var mainScript = (() => {
  var __create = Object.create;
  var __defProp = Object.defineProperty;
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
  var __getOwnPropNames = Object.getOwnPropertyNames;
  var __getProtoOf = Object.getPrototypeOf;
  var __hasOwnProp = Object.prototype.hasOwnProperty;
  var __commonJS = (cb, mod) => function __require() {
    return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
  };
  var __export = (target, all) => {
    for (var name in all)
      __defProp(target, name, { get: all[name], enumerable: true });
  };
  var __copyProps = (to, from, except, desc) => {
    if (from && typeof from === "object" || typeof from === "function") {
      for (let key of __getOwnPropNames(from))
        if (!__hasOwnProp.call(to, key) && key !== except)
          __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
    }
    return to;
  };
  var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
    // If the importer is in node compatibility mode or this is not an ESM
    // file that has been converted to a CommonJS file using a Babel-
    // compatible transform (i.e. "__esModule" has not been set), then set
    // "default" to the CommonJS "module.exports" for node compatibility.
    isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
    mod
  ));
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

  // ../node_modules/howler/dist/howler.js
  var require_howler = __commonJS({
    "../node_modules/howler/dist/howler.js"(exports) {
      (function() {
        "use strict";
        var HowlerGlobal2 = function() {
          this.init();
        };
        HowlerGlobal2.prototype = {
          /**
           * Initialize the global Howler object.
           * @return {Howler}
           */
          init: function() {
            var self = this || Howler2;
            self._counter = 1e3;
            self._html5AudioPool = [];
            self.html5PoolSize = 10;
            self._codecs = {};
            self._howls = [];
            self._muted = false;
            self._volume = 1;
            self._canPlayEvent = "canplaythrough";
            self._navigator = typeof window !== "undefined" && window.navigator ? window.navigator : null;
            self.masterGain = null;
            self.noAudio = false;
            self.usingWebAudio = true;
            self.autoSuspend = true;
            self.ctx = null;
            self.autoUnlock = true;
            self._setup();
            return self;
          },
          /**
           * Get/set the global volume for all sounds.
           * @param  {Float} vol Volume from 0.0 to 1.0.
           * @return {Howler/Float}     Returns self or current volume.
           */
          volume: function(vol) {
            var self = this || Howler2;
            vol = parseFloat(vol);
            if (!self.ctx) {
              setupAudioContext();
            }
            if (typeof vol !== "undefined" && vol >= 0 && vol <= 1) {
              self._volume = vol;
              if (self._muted) {
                return self;
              }
              if (self.usingWebAudio) {
                self.masterGain.gain.setValueAtTime(vol, Howler2.ctx.currentTime);
              }
              for (var i = 0; i < self._howls.length; i++) {
                if (!self._howls[i]._webAudio) {
                  var ids = self._howls[i]._getSoundIds();
                  for (var j = 0; j < ids.length; j++) {
                    var sound = self._howls[i]._soundById(ids[j]);
                    if (sound && sound._node) {
                      sound._node.volume = sound._volume * vol;
                    }
                  }
                }
              }
              return self;
            }
            return self._volume;
          },
          /**
           * Handle muting and unmuting globally.
           * @param  {Boolean} muted Is muted or not.
           */
          mute: function(muted) {
            var self = this || Howler2;
            if (!self.ctx) {
              setupAudioContext();
            }
            self._muted = muted;
            if (self.usingWebAudio) {
              self.masterGain.gain.setValueAtTime(muted ? 0 : self._volume, Howler2.ctx.currentTime);
            }
            for (var i = 0; i < self._howls.length; i++) {
              if (!self._howls[i]._webAudio) {
                var ids = self._howls[i]._getSoundIds();
                for (var j = 0; j < ids.length; j++) {
                  var sound = self._howls[i]._soundById(ids[j]);
                  if (sound && sound._node) {
                    sound._node.muted = muted ? true : sound._muted;
                  }
                }
              }
            }
            return self;
          },
          /**
           * Handle stopping all sounds globally.
           */
          stop: function() {
            var self = this || Howler2;
            for (var i = 0; i < self._howls.length; i++) {
              self._howls[i].stop();
            }
            return self;
          },
          /**
           * Unload and destroy all currently loaded Howl objects.
           * @return {Howler}
           */
          unload: function() {
            var self = this || Howler2;
            for (var i = self._howls.length - 1; i >= 0; i--) {
              self._howls[i].unload();
            }
            if (self.usingWebAudio && self.ctx && typeof self.ctx.close !== "undefined") {
              self.ctx.close();
              self.ctx = null;
              setupAudioContext();
            }
            return self;
          },
          /**
           * Check for codec support of specific extension.
           * @param  {String} ext Audio file extention.
           * @return {Boolean}
           */
          codecs: function(ext) {
            return (this || Howler2)._codecs[ext.replace(/^x-/, "")];
          },
          /**
           * Setup various state values for global tracking.
           * @return {Howler}
           */
          _setup: function() {
            var self = this || Howler2;
            self.state = self.ctx ? self.ctx.state || "suspended" : "suspended";
            self._autoSuspend();
            if (!self.usingWebAudio) {
              if (typeof Audio !== "undefined") {
                try {
                  var test = new Audio();
                  if (typeof test.oncanplaythrough === "undefined") {
                    self._canPlayEvent = "canplay";
                  }
                } catch (e) {
                  self.noAudio = true;
                }
              } else {
                self.noAudio = true;
              }
            }
            try {
              var test = new Audio();
              if (test.muted) {
                self.noAudio = true;
              }
            } catch (e) {
            }
            if (!self.noAudio) {
              self._setupCodecs();
            }
            return self;
          },
          /**
           * Check for browser support for various codecs and cache the results.
           * @return {Howler}
           */
          _setupCodecs: function() {
            var self = this || Howler2;
            var audioTest = null;
            try {
              audioTest = typeof Audio !== "undefined" ? new Audio() : null;
            } catch (err) {
              return self;
            }
            if (!audioTest || typeof audioTest.canPlayType !== "function") {
              return self;
            }
            var mpegTest = audioTest.canPlayType("audio/mpeg;").replace(/^no$/, "");
            var ua = self._navigator ? self._navigator.userAgent : "";
            var checkOpera = ua.match(/OPR\/(\d+)/g);
            var isOldOpera = checkOpera && parseInt(checkOpera[0].split("/")[1], 10) < 33;
            var checkSafari = ua.indexOf("Safari") !== -1 && ua.indexOf("Chrome") === -1;
            var safariVersion = ua.match(/Version\/(.*?) /);
            var isOldSafari = checkSafari && safariVersion && parseInt(safariVersion[1], 10) < 15;
            self._codecs = {
              mp3: !!(!isOldOpera && (mpegTest || audioTest.canPlayType("audio/mp3;").replace(/^no$/, ""))),
              mpeg: !!mpegTest,
              opus: !!audioTest.canPlayType('audio/ogg; codecs="opus"').replace(/^no$/, ""),
              ogg: !!audioTest.canPlayType('audio/ogg; codecs="vorbis"').replace(/^no$/, ""),
              oga: !!audioTest.canPlayType('audio/ogg; codecs="vorbis"').replace(/^no$/, ""),
              wav: !!(audioTest.canPlayType('audio/wav; codecs="1"') || audioTest.canPlayType("audio/wav")).replace(/^no$/, ""),
              aac: !!audioTest.canPlayType("audio/aac;").replace(/^no$/, ""),
              caf: !!audioTest.canPlayType("audio/x-caf;").replace(/^no$/, ""),
              m4a: !!(audioTest.canPlayType("audio/x-m4a;") || audioTest.canPlayType("audio/m4a;") || audioTest.canPlayType("audio/aac;")).replace(/^no$/, ""),
              m4b: !!(audioTest.canPlayType("audio/x-m4b;") || audioTest.canPlayType("audio/m4b;") || audioTest.canPlayType("audio/aac;")).replace(/^no$/, ""),
              mp4: !!(audioTest.canPlayType("audio/x-mp4;") || audioTest.canPlayType("audio/mp4;") || audioTest.canPlayType("audio/aac;")).replace(/^no$/, ""),
              weba: !!(!isOldSafari && audioTest.canPlayType('audio/webm; codecs="vorbis"').replace(/^no$/, "")),
              webm: !!(!isOldSafari && audioTest.canPlayType('audio/webm; codecs="vorbis"').replace(/^no$/, "")),
              dolby: !!audioTest.canPlayType('audio/mp4; codecs="ec-3"').replace(/^no$/, ""),
              flac: !!(audioTest.canPlayType("audio/x-flac;") || audioTest.canPlayType("audio/flac;")).replace(/^no$/, "")
            };
            return self;
          },
          /**
           * Some browsers/devices will only allow audio to be played after a user interaction.
           * Attempt to automatically unlock audio on the first user interaction.
           * Concept from: http://paulbakaus.com/tutorials/html5/web-audio-on-ios/
           * @return {Howler}
           */
          _unlockAudio: function() {
            var self = this || Howler2;
            if (self._audioUnlocked || !self.ctx) {
              return;
            }
            self._audioUnlocked = false;
            self.autoUnlock = false;
            if (!self._mobileUnloaded && self.ctx.sampleRate !== 44100) {
              self._mobileUnloaded = true;
              self.unload();
            }
            self._scratchBuffer = self.ctx.createBuffer(1, 1, 22050);
            var unlock = function(e) {
              while (self._html5AudioPool.length < self.html5PoolSize) {
                try {
                  var audioNode = new Audio();
                  audioNode._unlocked = true;
                  self._releaseHtml5Audio(audioNode);
                } catch (e2) {
                  self.noAudio = true;
                  break;
                }
              }
              for (var i = 0; i < self._howls.length; i++) {
                if (!self._howls[i]._webAudio) {
                  var ids = self._howls[i]._getSoundIds();
                  for (var j = 0; j < ids.length; j++) {
                    var sound = self._howls[i]._soundById(ids[j]);
                    if (sound && sound._node && !sound._node._unlocked) {
                      sound._node._unlocked = true;
                      sound._node.load();
                    }
                  }
                }
              }
              self._autoResume();
              var source = self.ctx.createBufferSource();
              source.buffer = self._scratchBuffer;
              source.connect(self.ctx.destination);
              if (typeof source.start === "undefined") {
                source.noteOn(0);
              } else {
                source.start(0);
              }
              if (typeof self.ctx.resume === "function") {
                self.ctx.resume();
              }
              source.onended = function() {
                source.disconnect(0);
                self._audioUnlocked = true;
                document.removeEventListener("touchstart", unlock, true);
                document.removeEventListener("touchend", unlock, true);
                document.removeEventListener("click", unlock, true);
                document.removeEventListener("keydown", unlock, true);
                for (var i2 = 0; i2 < self._howls.length; i2++) {
                  self._howls[i2]._emit("unlock");
                }
              };
            };
            document.addEventListener("touchstart", unlock, true);
            document.addEventListener("touchend", unlock, true);
            document.addEventListener("click", unlock, true);
            document.addEventListener("keydown", unlock, true);
            return self;
          },
          /**
           * Get an unlocked HTML5 Audio object from the pool. If none are left,
           * return a new Audio object and throw a warning.
           * @return {Audio} HTML5 Audio object.
           */
          _obtainHtml5Audio: function() {
            var self = this || Howler2;
            if (self._html5AudioPool.length) {
              return self._html5AudioPool.pop();
            }
            var testPlay = new Audio().play();
            if (testPlay && typeof Promise !== "undefined" && (testPlay instanceof Promise || typeof testPlay.then === "function")) {
              testPlay.catch(function() {
                console.warn("HTML5 Audio pool exhausted, returning potentially locked audio object.");
              });
            }
            return new Audio();
          },
          /**
           * Return an activated HTML5 Audio object to the pool.
           * @return {Howler}
           */
          _releaseHtml5Audio: function(audio) {
            var self = this || Howler2;
            if (audio._unlocked) {
              self._html5AudioPool.push(audio);
            }
            return self;
          },
          /**
           * Automatically suspend the Web Audio AudioContext after no sound has played for 30 seconds.
           * This saves processing/energy and fixes various browser-specific bugs with audio getting stuck.
           * @return {Howler}
           */
          _autoSuspend: function() {
            var self = this;
            if (!self.autoSuspend || !self.ctx || typeof self.ctx.suspend === "undefined" || !Howler2.usingWebAudio) {
              return;
            }
            for (var i = 0; i < self._howls.length; i++) {
              if (self._howls[i]._webAudio) {
                for (var j = 0; j < self._howls[i]._sounds.length; j++) {
                  if (!self._howls[i]._sounds[j]._paused) {
                    return self;
                  }
                }
              }
            }
            if (self._suspendTimer) {
              clearTimeout(self._suspendTimer);
            }
            self._suspendTimer = setTimeout(function() {
              if (!self.autoSuspend) {
                return;
              }
              self._suspendTimer = null;
              self.state = "suspending";
              var handleSuspension = function() {
                self.state = "suspended";
                if (self._resumeAfterSuspend) {
                  delete self._resumeAfterSuspend;
                  self._autoResume();
                }
              };
              self.ctx.suspend().then(handleSuspension, handleSuspension);
            }, 3e4);
            return self;
          },
          /**
           * Automatically resume the Web Audio AudioContext when a new sound is played.
           * @return {Howler}
           */
          _autoResume: function() {
            var self = this;
            if (!self.ctx || typeof self.ctx.resume === "undefined" || !Howler2.usingWebAudio) {
              return;
            }
            if (self.state === "running" && self.ctx.state !== "interrupted" && self._suspendTimer) {
              clearTimeout(self._suspendTimer);
              self._suspendTimer = null;
            } else if (self.state === "suspended" || self.state === "running" && self.ctx.state === "interrupted") {
              self.ctx.resume().then(function() {
                self.state = "running";
                for (var i = 0; i < self._howls.length; i++) {
                  self._howls[i]._emit("resume");
                }
              });
              if (self._suspendTimer) {
                clearTimeout(self._suspendTimer);
                self._suspendTimer = null;
              }
            } else if (self.state === "suspending") {
              self._resumeAfterSuspend = true;
            }
            return self;
          }
        };
        var Howler2 = new HowlerGlobal2();
        var Howl3 = function(o) {
          var self = this;
          if (!o.src || o.src.length === 0) {
            console.error("An array of source files must be passed with any new Howl.");
            return;
          }
          self.init(o);
        };
        Howl3.prototype = {
          /**
           * Initialize a new Howl group object.
           * @param  {Object} o Passed in properties for this group.
           * @return {Howl}
           */
          init: function(o) {
            var self = this;
            if (!Howler2.ctx) {
              setupAudioContext();
            }
            self._autoplay = o.autoplay || false;
            self._format = typeof o.format !== "string" ? o.format : [o.format];
            self._html5 = o.html5 || false;
            self._muted = o.mute || false;
            self._loop = o.loop || false;
            self._pool = o.pool || 5;
            self._preload = typeof o.preload === "boolean" || o.preload === "metadata" ? o.preload : true;
            self._rate = o.rate || 1;
            self._sprite = o.sprite || {};
            self._src = typeof o.src !== "string" ? o.src : [o.src];
            self._volume = o.volume !== void 0 ? o.volume : 1;
            self._xhr = {
              method: o.xhr && o.xhr.method ? o.xhr.method : "GET",
              headers: o.xhr && o.xhr.headers ? o.xhr.headers : null,
              withCredentials: o.xhr && o.xhr.withCredentials ? o.xhr.withCredentials : false
            };
            self._duration = 0;
            self._state = "unloaded";
            self._sounds = [];
            self._endTimers = {};
            self._queue = [];
            self._playLock = false;
            self._onend = o.onend ? [{ fn: o.onend }] : [];
            self._onfade = o.onfade ? [{ fn: o.onfade }] : [];
            self._onload = o.onload ? [{ fn: o.onload }] : [];
            self._onloaderror = o.onloaderror ? [{ fn: o.onloaderror }] : [];
            self._onplayerror = o.onplayerror ? [{ fn: o.onplayerror }] : [];
            self._onpause = o.onpause ? [{ fn: o.onpause }] : [];
            self._onplay = o.onplay ? [{ fn: o.onplay }] : [];
            self._onstop = o.onstop ? [{ fn: o.onstop }] : [];
            self._onmute = o.onmute ? [{ fn: o.onmute }] : [];
            self._onvolume = o.onvolume ? [{ fn: o.onvolume }] : [];
            self._onrate = o.onrate ? [{ fn: o.onrate }] : [];
            self._onseek = o.onseek ? [{ fn: o.onseek }] : [];
            self._onunlock = o.onunlock ? [{ fn: o.onunlock }] : [];
            self._onresume = [];
            self._webAudio = Howler2.usingWebAudio && !self._html5;
            if (typeof Howler2.ctx !== "undefined" && Howler2.ctx && Howler2.autoUnlock) {
              Howler2._unlockAudio();
            }
            Howler2._howls.push(self);
            if (self._autoplay) {
              self._queue.push({
                event: "play",
                action: function() {
                  self.play();
                }
              });
            }
            if (self._preload && self._preload !== "none") {
              self.load();
            }
            return self;
          },
          /**
           * Load the audio file.
           * @return {Howler}
           */
          load: function() {
            var self = this;
            var url = null;
            if (Howler2.noAudio) {
              self._emit("loaderror", null, "No audio support.");
              return;
            }
            if (typeof self._src === "string") {
              self._src = [self._src];
            }
            for (var i = 0; i < self._src.length; i++) {
              var ext, str;
              if (self._format && self._format[i]) {
                ext = self._format[i];
              } else {
                str = self._src[i];
                if (typeof str !== "string") {
                  self._emit("loaderror", null, "Non-string found in selected audio sources - ignoring.");
                  continue;
                }
                ext = /^data:audio\/([^;,]+);/i.exec(str);
                if (!ext) {
                  ext = /\.([^.]+)$/.exec(str.split("?", 1)[0]);
                }
                if (ext) {
                  ext = ext[1].toLowerCase();
                }
              }
              if (!ext) {
                console.warn('No file extension was found. Consider using the "format" property or specify an extension.');
              }
              if (ext && Howler2.codecs(ext)) {
                url = self._src[i];
                break;
              }
            }
            if (!url) {
              self._emit("loaderror", null, "No codec support for selected audio sources.");
              return;
            }
            self._src = url;
            self._state = "loading";
            if (window.location.protocol === "https:" && url.slice(0, 5) === "http:") {
              self._html5 = true;
              self._webAudio = false;
            }
            new Sound2(self);
            if (self._webAudio) {
              loadBuffer(self);
            }
            return self;
          },
          /**
           * Play a sound or resume previous playback.
           * @param  {String/Number} sprite   Sprite name for sprite playback or sound id to continue previous.
           * @param  {Boolean} internal Internal Use: true prevents event firing.
           * @return {Number}          Sound ID.
           */
          play: function(sprite, internal) {
            var self = this;
            var id = null;
            if (typeof sprite === "number") {
              id = sprite;
              sprite = null;
            } else if (typeof sprite === "string" && self._state === "loaded" && !self._sprite[sprite]) {
              return null;
            } else if (typeof sprite === "undefined") {
              sprite = "__default";
              if (!self._playLock) {
                var num = 0;
                for (var i = 0; i < self._sounds.length; i++) {
                  if (self._sounds[i]._paused && !self._sounds[i]._ended) {
                    num++;
                    id = self._sounds[i]._id;
                  }
                }
                if (num === 1) {
                  sprite = null;
                } else {
                  id = null;
                }
              }
            }
            var sound = id ? self._soundById(id) : self._inactiveSound();
            if (!sound) {
              return null;
            }
            if (id && !sprite) {
              sprite = sound._sprite || "__default";
            }
            if (self._state !== "loaded") {
              sound._sprite = sprite;
              sound._ended = false;
              var soundId = sound._id;
              self._queue.push({
                event: "play",
                action: function() {
                  self.play(soundId);
                }
              });
              return soundId;
            }
            if (id && !sound._paused) {
              if (!internal) {
                self._loadQueue("play");
              }
              return sound._id;
            }
            if (self._webAudio) {
              Howler2._autoResume();
            }
            var seek = Math.max(0, sound._seek > 0 ? sound._seek : self._sprite[sprite][0] / 1e3);
            var duration = Math.max(0, (self._sprite[sprite][0] + self._sprite[sprite][1]) / 1e3 - seek);
            var timeout = duration * 1e3 / Math.abs(sound._rate);
            var start = self._sprite[sprite][0] / 1e3;
            var stop = (self._sprite[sprite][0] + self._sprite[sprite][1]) / 1e3;
            sound._sprite = sprite;
            sound._ended = false;
            var setParams = function() {
              sound._paused = false;
              sound._seek = seek;
              sound._start = start;
              sound._stop = stop;
              sound._loop = !!(sound._loop || self._sprite[sprite][2]);
            };
            if (seek >= stop) {
              self._ended(sound);
              return;
            }
            var node = sound._node;
            if (self._webAudio) {
              var playWebAudio = function() {
                self._playLock = false;
                setParams();
                self._refreshBuffer(sound);
                var vol = sound._muted || self._muted ? 0 : sound._volume;
                node.gain.setValueAtTime(vol, Howler2.ctx.currentTime);
                sound._playStart = Howler2.ctx.currentTime;
                if (typeof node.bufferSource.start === "undefined") {
                  sound._loop ? node.bufferSource.noteGrainOn(0, seek, 86400) : node.bufferSource.noteGrainOn(0, seek, duration);
                } else {
                  sound._loop ? node.bufferSource.start(0, seek, 86400) : node.bufferSource.start(0, seek, duration);
                }
                if (timeout !== Infinity) {
                  self._endTimers[sound._id] = setTimeout(self._ended.bind(self, sound), timeout);
                }
                if (!internal) {
                  setTimeout(function() {
                    self._emit("play", sound._id);
                    self._loadQueue();
                  }, 0);
                }
              };
              if (Howler2.state === "running" && Howler2.ctx.state !== "interrupted") {
                playWebAudio();
              } else {
                self._playLock = true;
                self.once("resume", playWebAudio);
                self._clearTimer(sound._id);
              }
            } else {
              var playHtml5 = function() {
                node.currentTime = seek;
                node.muted = sound._muted || self._muted || Howler2._muted || node.muted;
                node.volume = sound._volume * Howler2.volume();
                node.playbackRate = sound._rate;
                try {
                  var play = node.play();
                  if (play && typeof Promise !== "undefined" && (play instanceof Promise || typeof play.then === "function")) {
                    self._playLock = true;
                    setParams();
                    play.then(function() {
                      self._playLock = false;
                      node._unlocked = true;
                      if (!internal) {
                        self._emit("play", sound._id);
                      } else {
                        self._loadQueue();
                      }
                    }).catch(function() {
                      self._playLock = false;
                      self._emit("playerror", sound._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.");
                      sound._ended = true;
                      sound._paused = true;
                    });
                  } else if (!internal) {
                    self._playLock = false;
                    setParams();
                    self._emit("play", sound._id);
                  }
                  node.playbackRate = sound._rate;
                  if (node.paused) {
                    self._emit("playerror", sound._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 (sprite !== "__default" || sound._loop) {
                    self._endTimers[sound._id] = setTimeout(self._ended.bind(self, sound), timeout);
                  } else {
                    self._endTimers[sound._id] = function() {
                      self._ended(sound);
                      node.removeEventListener("ended", self._endTimers[sound._id], false);
                    };
                    node.addEventListener("ended", self._endTimers[sound._id], false);
                  }
                } catch (err) {
                  self._emit("playerror", sound._id, err);
                }
              };
              if (node.src === "data:audio/wav;base64,UklGRigAAABXQVZFZm10IBIAAAABAAEARKwAAIhYAQACABAAAABkYXRhAgAAAAEA") {
                node.src = self._src;
                node.load();
              }
              var loadedNoReadyState = window && window.ejecta || !node.readyState && Howler2._navigator.isCocoonJS;
              if (node.readyState >= 3 || loadedNoReadyState) {
                playHtml5();
              } else {
                self._playLock = true;
                self._state = "loading";
                var listener = function() {
                  self._state = "loaded";
                  playHtml5();
                  node.removeEventListener(Howler2._canPlayEvent, listener, false);
                };
                node.addEventListener(Howler2._canPlayEvent, listener, false);
                self._clearTimer(sound._id);
              }
            }
            return sound._id;
          },
          /**
           * Pause playback and save current position.
           * @param  {Number} id The sound ID (empty to pause all in group).
           * @return {Howl}
           */
          pause: function(id) {
            var self = this;
            if (self._state !== "loaded" || self._playLock) {
              self._queue.push({
                event: "pause",
                action: function() {
                  self.pause(id);
                }
              });
              return self;
            }
            var ids = self._getSoundIds(id);
            for (var i = 0; i < ids.length; i++) {
              self._clearTimer(ids[i]);
              var sound = self._soundById(ids[i]);
              if (sound && !sound._paused) {
                sound._seek = self.seek(ids[i]);
                sound._rateSeek = 0;
                sound._paused = true;
                self._stopFade(ids[i]);
                if (sound._node) {
                  if (self._webAudio) {
                    if (!sound._node.bufferSource) {
                      continue;
                    }
                    if (typeof sound._node.bufferSource.stop === "undefined") {
                      sound._node.bufferSource.noteOff(0);
                    } else {
                      sound._node.bufferSource.stop(0);
                    }
                    self._cleanBuffer(sound._node);
                  } else if (!isNaN(sound._node.duration) || sound._node.duration === Infinity) {
                    sound._node.pause();
                  }
                }
              }
              if (!arguments[1]) {
                self._emit("pause", sound ? sound._id : null);
              }
            }
            return self;
          },
          /**
           * Stop playback and reset to start.
           * @param  {Number} id The sound ID (empty to stop all in group).
           * @param  {Boolean} internal Internal Use: true prevents event firing.
           * @return {Howl}
           */
          stop: function(id, internal) {
            var self = this;
            if (self._state !== "loaded" || self._playLock) {
              self._queue.push({
                event: "stop",
                action: function() {
                  self.stop(id);
                }
              });
              return self;
            }
            var ids = self._getSoundIds(id);
            for (var i = 0; i < ids.length; i++) {
              self._clearTimer(ids[i]);
              var sound = self._soundById(ids[i]);
              if (sound) {
                sound._seek = sound._start || 0;
                sound._rateSeek = 0;
                sound._paused = true;
                sound._ended = true;
                self._stopFade(ids[i]);
                if (sound._node) {
                  if (self._webAudio) {
                    if (sound._node.bufferSource) {
                      if (typeof sound._node.bufferSource.stop === "undefined") {
                        sound._node.bufferSource.noteOff(0);
                      } else {
                        sound._node.bufferSource.stop(0);
                      }
                      self._cleanBuffer(sound._node);
                    }
                  } else if (!isNaN(sound._node.duration) || sound._node.duration === Infinity) {
                    sound._node.currentTime = sound._start || 0;
                    sound._node.pause();
                    if (sound._node.duration === Infinity) {
                      self._clearSound(sound._node);
                    }
                  }
                }
                if (!internal) {
                  self._emit("stop", sound._id);
                }
              }
            }
            return self;
          },
          /**
           * Mute/unmute a single sound or all sounds in this Howl group.
           * @param  {Boolean} muted Set to true to mute and false to unmute.
           * @param  {Number} id    The sound ID to update (omit to mute/unmute all).
           * @return {Howl}
           */
          mute: function(muted, id) {
            var self = this;
            if (self._state !== "loaded" || self._playLock) {
              self._queue.push({
                event: "mute",
                action: function() {
                  self.mute(muted, id);
                }
              });
              return self;
            }
            if (typeof id === "undefined") {
              if (typeof muted === "boolean") {
                self._muted = muted;
              } else {
                return self._muted;
              }
            }
            var ids = self._getSoundIds(id);
            for (var i = 0; i < ids.length; i++) {
              var sound = self._soundById(ids[i]);
              if (sound) {
                sound._muted = muted;
                if (sound._interval) {
                  self._stopFade(sound._id);
                }
                if (self._webAudio && sound._node) {
                  sound._node.gain.setValueAtTime(muted ? 0 : sound._volume, Howler2.ctx.currentTime);
                } else if (sound._node) {
                  sound._node.muted = Howler2._muted ? true : muted;
                }
                self._emit("mute", sound._id);
              }
            }
            return self;
          },
          /**
           * Get/set the volume of this sound or of the Howl group. This method can optionally take 0, 1 or 2 arguments.
           *   volume() -> Returns the group's volume value.
           *   volume(id) -> Returns the sound id's current volume.
           *   volume(vol) -> Sets the volume of all sounds in this Howl group.
           *   volume(vol, id) -> Sets the volume of passed sound id.
           * @return {Howl/Number} Returns self or current volume.
           */
          volume: function() {
            var self = this;
            var args = arguments;
            var vol, id;
            if (args.length === 0) {
              return self._volume;
            } else if (args.length === 1 || args.length === 2 && typeof args[1] === "undefined") {
              var ids = self._getSoundIds();
              var index = ids.indexOf(args[0]);
              if (index >= 0) {
                id = parseInt(args[0], 10);
              } else {
                vol = parseFloat(args[0]);
              }
            } else if (args.length >= 2) {
              vol = parseFloat(args[0]);
              id = parseInt(args[1], 10);
            }
            var sound;
            if (typeof vol !== "undefined" && vol >= 0 && vol <= 1) {
              if (self._state !== "loaded" || self._playLock) {
                self._queue.push({
                  event: "volume",
                  action: function() {
                    self.volume.apply(self, args);
                  }
                });
                return self;
              }
              if (typeof id === "undefined") {
                self._volume = vol;
              }
              id = self._getSoundIds(id);
              for (var i = 0; i < id.length; i++) {
                sound = self._soundById(id[i]);
                if (sound) {
                  sound._volume = vol;
                  if (!args[2]) {
                    self._stopFade(id[i]);
                  }
                  if (self._webAudio && sound._node && !sound._muted) {
                    sound._node.gain.setValueAtTime(vol, Howler2.ctx.currentTime);
                  } else if (sound._node && !sound._muted) {
                    sound._node.volume = vol * Howler2.volume();
                  }
                  self._emit("volume", sound._id);
                }
              }
            } else {
              sound = id ? self._soundById(id) : self._sounds[0];
              return sound ? sound._volume : 0;
            }
            return self;
          },
          /**
           * Fade a currently playing sound between two volumes (if no id is passed, all sounds will fade).
           * @param  {Number} from The value to fade from (0.0 to 1.0).
           * @param  {Number} to   The volume to fade to (0.0 to 1.0).
           * @param  {Number} len  Time in milliseconds to fade.
           * @param  {Number} id   The sound id (omit to fade all sounds).
           * @return {Howl}
           */
          fade: function(from, to, len, id) {
            var self = this;
            if (self._state !== "loaded" || self._playLock) {
              self._queue.push({
                event: "fade",
                action: function() {
                  self.fade(from, to, len, id);
                }
              });
              return self;
            }
            from = Math.min(Math.max(0, parseFloat(from)), 1);
            to = Math.min(Math.max(0, parseFloat(to)), 1);
            len = parseFloat(len);
            self.volume(from, id);
            var ids = self._getSoundIds(id);
            for (var i = 0; i < ids.length; i++) {
              var sound = self._soundById(ids[i]);
              if (sound) {
                if (!id) {
                  self._stopFade(ids[i]);
                }
                if (self._webAudio && !sound._muted) {
                  var currentTime = Howler2.ctx.currentTime;
                  var end = currentTime + len / 1e3;
                  sound._volume = from;
                  sound._node.gain.setValueAtTime(from, currentTime);
                  sound._node.gain.linearRampToValueAtTime(to, end);
                }
                self._startFadeInterval(sound, from, to, len, ids[i], typeof id === "undefined");
              }
            }
            return self;
          },
          /**
           * Starts the internal interval to fade a sound.
           * @param  {Object} sound Reference to sound to fade.
           * @param  {Number} from The value to fade from (0.0 to 1.0).
           * @param  {Number} to   The volume to fade to (0.0 to 1.0).
           * @param  {Number} len  Time in milliseconds to fade.
           * @param  {Number} id   The sound id to fade.
           * @param  {Boolean} isGroup   If true, set the volume on the group.
           */
          _startFadeInterval: function(sound, from, to, len, id, isGroup) {
            var self = this;
            var vol = from;
            var diff = to - from;
            var steps = Math.abs(diff / 0.01);
            var stepLen = Math.max(4, steps > 0 ? len / steps : len);
            var lastTick = Date.now();
            sound._fadeTo = to;
            sound._interval = setInterval(function() {
              var tick = (Date.now() - lastTick) / len;
              lastTick = Date.now();
              vol += diff * tick;
              vol = Math.round(vol * 100) / 100;
              if (diff < 0) {
                vol = Math.max(to, vol);
              } else {
                vol = Math.min(to, vol);
              }
              if (self._webAudio) {
                sound._volume = vol;
              } else {
                self.volume(vol, sound._id, true);
              }
              if (isGroup) {
                self._volume = vol;
              }
              if (to < from && vol <= to || to > from && vol >= to) {
                clearInterval(sound._interval);
                sound._interval = null;
                sound._fadeTo = null;
                self.volume(to, sound._id);
                self._emit("fade", sound._id);
              }
            }, stepLen);
          },
          /**
           * Internal method that stops the currently playing fade when
           * a new fade starts, volume is changed or the sound is stopped.
           * @param  {Number} id The sound id.
           * @return {Howl}
           */
          _stopFade: function(id) {
            var self = this;
            var sound = self._soundById(id);
            if (sound && sound._interval) {
              if (self._webAudio) {
                sound._node.gain.cancelScheduledValues(Howler2.ctx.currentTime);
              }
              clearInterval(sound._interval);
              sound._interval = null;
              self.volume(sound._fadeTo, id);
              sound._fadeTo = null;
              self._emit("fade", id);
            }
            return self;
          },
          /**
           * Get/set the loop parameter on a sound. This method can optionally take 0, 1 or 2 arguments.
           *   loop() -> Returns the group's loop value.
           *   loop(id) -> Returns the sound id's loop value.
           *   loop(loop) -> Sets the loop value for all sounds in this Howl group.
           *   loop(loop, id) -> Sets the loop value of passed sound id.
           * @return {Howl/Boolean} Returns self or current loop value.
           */
          loop: function() {
            var self = this;
            var args = arguments;
            var loop, id, sound;
            if (args.length === 0) {
              return self._loop;
            } else if (args.length === 1) {
              if (typeof args[0] === "boolean") {
                loop = args[0];
                self._loop = loop;
              } else {
                sound = self._soundById(parseInt(args[0], 10));
                return sound ? sound._loop : false;
              }
            } else if (args.length === 2) {
              loop = args[0];
              id = parseInt(args[1], 10);
            }
            var ids = self._getSoundIds(id);
            for (var i = 0; i < ids.length; i++) {
              sound = self._soundById(ids[i]);
              if (sound) {
                sound._loop = loop;
                if (self._webAudio && sound._node && sound._node.bufferSource) {
                  sound._node.bufferSource.loop = loop;
                  if (loop) {
                    sound._node.bufferSource.loopStart = sound._start || 0;
                    sound._node.bufferSource.loopEnd = sound._stop;
                    if (self.playing(ids[i])) {
                      self.pause(ids[i], true);
                      self.play(ids[i], true);
                    }
                  }
                }
              }
            }
            return self;
          },
          /**
           * Get/set the playback rate of a sound. This method can optionally take 0, 1 or 2 arguments.
           *   rate() -> Returns the first sound node's current playback rate.
           *   rate(id) -> Returns the sound id's current playback rate.
           *   rate(rate) -> Sets the playback rate of all sounds in this Howl group.
           *   rate(rate, id) -> Sets the playback rate of passed sound id.
           * @return {Howl/Number} Returns self or the current playback rate.
           */
          rate: function() {
            var self = this;
            var args = arguments;
            var rate, id;
            if (args.length === 0) {
              id = self._sounds[0]._id;
            } else if (args.length === 1) {
              var ids = self._getSoundIds();
              var index = ids.indexOf(args[0]);
              if (index >= 0) {
                id = parseInt(args[0], 10);
              } else {
                rate = parseFloat(args[0]);
              }
            } else if (args.length === 2) {
              rate = parseFloat(args[0]);
              id = parseInt(args[1], 10);
            }
            var sound;
            if (typeof rate === "number") {
              if (self._state !== "loaded" || self._playLock) {
                self._queue.push({
                  event: "rate",
                  action: function() {
                    self.rate.apply(self, args);
                  }
                });
                return self;
              }
              if (typeof id === "undefined") {
                self._rate = rate;
              }
              id = self._getSoundIds(id);
              for (var i = 0; i < id.length; i++) {
                sound = self._soundById(id[i]);
                if (sound) {
                  if (self.playing(id[i])) {
                    sound._rateSeek = self.seek(id[i]);
                    sound._playStart = self._webAudio ? Howler2.ctx.currentTime : sound._playStart;
                  }
                  sound._rate = rate;
                  if (self._webAudio && sound._node && sound._node.bufferSource) {
                    sound._node.bufferSource.playbackRate.setValueAtTime(rate, Howler2.ctx.currentTime);
                  } else if (sound._node) {
                    sound._node.playbackRate = rate;
                  }
                  var seek = self.seek(id[i]);
                  var duration = (self._sprite[sound._sprite][0] + self._sprite[sound._sprite][1]) / 1e3 - seek;
                  var timeout = duration * 1e3 / Math.abs(sound._rate);
                  if (self._endTimers[id[i]] || !sound._paused) {
                    self._clearTimer(id[i]);
                    self._endTimers[id[i]] = setTimeout(self._ended.bind(self, sound), timeout);
                  }
                  self._emit("rate", sound._id);
                }
              }
            } else {
              sound = self._soundById(id);
              return sound ? sound._rate : self._rate;
            }
            return self;
          },
          /**
           * Get/set the seek position of a sound. This method can optionally take 0, 1 or 2 arguments.
           *   seek() -> Returns the first sound node's current seek position.
           *   seek(id) -> Returns the sound id's current seek position.
           *   seek(seek) -> Sets the seek position of the first sound node.
           *   seek(seek, id) -> Sets the seek position of passed sound id.
           * @return {Howl/Number} Returns self or the current seek position.
           */
          seek: function() {
            var self = this;
            var args = arguments;
            var seek, id;
            if (args.length === 0) {
              if (self._sounds.length) {
                id = self._sounds[0]._id;
              }
            } else if (args.length === 1) {
              var ids = self._getSoundIds();
              var index = ids.indexOf(args[0]);
              if (index >= 0) {
                id = parseInt(args[0], 10);
              } else if (self._sounds.length) {
                id = self._sounds[0]._id;
                seek = parseFloat(args[0]);
              }
            } else if (args.length === 2) {
              seek = parseFloat(args[0]);
              id = parseInt(args[1], 10);
            }
            if (typeof id === "undefined") {
              return 0;
            }
            if (typeof seek === "number" && (self._state !== "loaded" || self._playLock)) {
              self._queue.push({
                event: "seek",
                action: function() {
                  self.seek.apply(self, args);
                }
              });
              return self;
            }
            var sound = self._soundById(id);
            if (sound) {
              if (typeof seek === "number" && seek >= 0) {
                var playing = self.playing(id);
                if (playing) {
                  self.pause(id, true);
                }
                sound._seek = seek;
                sound._ended = false;
                self._clearTimer(id);
                if (!self._webAudio && sound._node && !isNaN(sound._node.duration)) {
                  sound._node.currentTime = seek;
                }
                var seekAndEmit = function() {
                  if (playing) {
                    self.play(id, true);
                  }
                  self._emit("seek", id);
                };
                if (playing && !self._webAudio) {
                  var emitSeek = function() {
                    if (!self._playLock) {
                      seekAndEmit();
                    } else {
                      setTimeout(emitSeek, 0);
                    }
                  };
                  setTimeout(emitSeek, 0);
                } else {
                  seekAndEmit();
                }
              } else {
                if (self._webAudio) {
                  var realTime = self.playing(id) ? Howler2.ctx.currentTime - sound._playStart : 0;
                  var rateSeek = sound._rateSeek ? sound._rateSeek - sound._seek : 0;
                  return sound._seek + (rateSeek + realTime * Math.abs(sound._rate));
                } else {
                  return sound._node.currentTime;
                }
              }
            }
            return self;
          },
          /**
           * Check if a specific sound is currently playing or not (if id is provided), or check if at least one of the sounds in the group is playing or not.
           * @param  {Number}  id The sound id to check. If none is passed, the whole sound group is checked.
           * @return {Boolean} True if playing and false if not.
           */
          playing: function(id) {
            var self = this;
            if (typeof id === "number") {
              var sound = self._soundById(id);
              return sound ? !sound._paused : false;
            }
            for (var i = 0; i < self._sounds.length; i++) {
              if (!self._sounds[i]._paused) {
                return true;
              }
            }
            return false;
          },
          /**
           * Get the duration of this sound. Passing a sound id will return the sprite duration.
           * @param  {Number} id The sound id to check. If none is passed, return full source duration.
           * @return {Number} Audio duration in seconds.
           */
          duration: function(id) {
            var self = this;
            var duration = self._duration;
            var sound = self._soundById(id);
            if (sound) {
              duration = self._sprite[sound._sprite][1] / 1e3;
            }
            return duration;
          },
          /**
           * Returns the current loaded state of this Howl.
           * @return {String} 'unloaded', 'loading', 'loaded'
           */
          state: function() {
            return this._state;
          },
          /**
           * Unload and destroy the current Howl object.
           * This will immediately stop all sound instances attached to this group.
           */
          unload: function() {
            var self = this;
            var sounds = self._sounds;
            for (var i = 0; i < sounds.length; i++) {
              if (!sounds[i]._paused) {
                self.stop(sounds[i]._id);
              }
              if (!self._webAudio) {
                self._clearSound(sounds[i]._node);
                sounds[i]._node.removeEventListener("error", sounds[i]._errorFn, false);
                sounds[i]._node.removeEventListener(Howler2._canPlayEvent, sounds[i]._loadFn, false);
                sounds[i]._node.removeEventListener("ended", sounds[i]._endFn, false);
                Howler2._releaseHtml5Audio(sounds[i]._node);
              }
              delete sounds[i]._node;
              self._clearTimer(sounds[i]._id);
            }
            var index = Howler2._howls.indexOf(self);
            if (index >= 0) {
              Howler2._howls.splice(index, 1);
            }
            var remCache = true;
            for (i = 0; i < Howler2._howls.length; i++) {
              if (Howler2._howls[i]._src === self._src || self._src.indexOf(Howler2._howls[i]._src) >= 0) {
                remCache = false;
                break;
              }
            }
            if (cache && remCache) {
              delete cache[self._src];
            }
            Howler2.noAudio = false;
            self._state = "unloaded";
            self._sounds = [];
            self = null;
            return null;
          },
          /**
           * Listen to a custom event.
           * @param  {String}   event Event name.
           * @param  {Function} fn    Listener to call.
           * @param  {Number}   id    (optional) Only listen to events for this sound.
           * @param  {Number}   once  (INTERNAL) Marks event to fire only once.
           * @return {Howl}
           */
          on: function(event, fn, id, once) {
            var self = this;
            var events = self["_on" + event];
            if (typeof fn === "function") {
              events.push(once ? { id, fn, once } : { id, fn });
            }
            return self;
          },
          /**
           * Remove a custom event. Call without parameters to remove all events.
           * @param  {String}   event Event name.
           * @param  {Function} fn    Listener to remove. Leave empty to remove all.
           * @param  {Number}   id    (optional) Only remove events for this sound.
           * @return {Howl}
           */
          off: function(event, fn, id) {
            var self = this;
            var events = self["_on" + event];
            var i = 0;
            if (typeof fn === "number") {
              id = fn;
              fn = null;
            }
            if (fn || id) {
              for (i = 0; i < events.length; i++) {
                var isId = id === events[i].id;
                if (fn === events[i].fn && isId || !fn && isId) {
                  events.splice(i, 1);
                  break;
                }
              }
            } else if (event) {
              self["_on" + event] = [];
            } else {
              var keys = Object.keys(self);
              for (i = 0; i < keys.length; i++) {
                if (keys[i].indexOf("_on") === 0 && Array.isArray(self[keys[i]])) {
                  self[keys[i]] = [];
                }
              }
            }
            return self;
          },
          /**
           * Listen to a custom event and remove it once fired.
           * @param  {String}   event Event name.
           * @param  {Function} fn    Listener to call.
           * @param  {Number}   id    (optional) Only listen to events for this sound.
           * @return {Howl}
           */
          once: function(event, fn, id) {
            var self = this;
            self.on(event, fn, id, 1);
            return self;
          },
          /**
           * Emit all events of a specific type and pass the sound id.
           * @param  {String} event Event name.
           * @param  {Number} id    Sound ID.
           * @param  {Number} msg   Message to go with event.
           * @return {Howl}
           */
          _emit: function(event, id, msg) {
            var self = this;
            var events = self["_on" + event];
            for (var i = events.length - 1; i >= 0; i--) {
              if (!events[i].id || events[i].id === id || event === "load") {
                setTimeout(function(fn) {
                  fn.call(this, id, msg);
                }.bind(self, events[i].fn), 0);
                if (events[i].once) {
                  self.off(event, events[i].fn, events[i].id);
                }
              }
            }
            self._loadQueue(event);
            return self;
          },
          /**
           * Queue of actions initiated before the sound has loaded.
           * These will be called in sequence, with the next only firing
           * after the previous has finished executing (even if async like play).
           * @return {Howl}
           */
          _loadQueue: function(event) {
            var self = this;
            if (self._queue.length > 0) {
              var task = self._queue[0];
              if (task.event === event) {
                self._queue.shift();
                self._loadQueue();
              }
              if (!event) {
                task.action();
              }
            }
            return self;
          },
          /**
           * Fired when playback ends at the end of the duration.
           * @param  {Sound} sound The sound object to work with.
           * @return {Howl}
           */
          _ended: function(sound) {
            var self = this;
            var sprite = sound._sprite;
            if (!self._webAudio && sound._node && !sound._node.paused && !sound._node.ended && sound._node.currentTime < sound._stop) {
              setTimeout(self._ended.bind(self, sound), 100);
              return self;
            }
            var loop = !!(sound._loop || self._sprite[sprite][2]);
            self._emit("end", sound._id);
            if (!self._webAudio && loop) {
              self.stop(sound._id, true).play(sound._id);
            }
            if (self._webAudio && loop) {
              self._emit("play", sound._id);
              sound._seek = sound._start || 0;
              sound._rateSeek = 0;
              sound._playStart = Howler2.ctx.currentTime;
              var timeout = (sound._stop - sound._start) * 1e3 / Math.abs(sound._rate);
              self._endTimers[sound._id] = setTimeout(self._ended.bind(self, sound), timeout);
            }
            if (self._webAudio && !loop) {
              sound._paused = true;
              sound._ended = true;
              sound._seek = sound._start || 0;
              sound._rateSeek = 0;
              self._clearTimer(sound._id);
              self._cleanBuffer(sound._node);
              Howler2._autoSuspend();
            }
            if (!self._webAudio && !loop) {
              self.stop(sound._id, true);
            }
            return self;
          },
          /**
           * Clear the end timer for a sound playback.
           * @param  {Number} id The sound ID.
           * @return {Howl}
           */
          _clearTimer: function(id) {
            var self = this;
            if (self._endTimers[id]) {
              if (typeof self._endTimers[id] !== "function") {
                clearTimeout(self._endTimers[id]);
              } else {
                var sound = self._soundById(id);
                if (sound && sound._node) {
                  sound._node.removeEventListener("ended", self._endTimers[id], false);
                }
              }
              delete self._endTimers[id];
            }
            return self;
          },
          /**
           * Return the sound identified by this ID, or return null.
           * @param  {Number} id Sound ID
           * @return {Object}    Sound object or null.
           */
          _soundById: function(id) {
            var self = this;
            for (var i = 0; i < self._sounds.length; i++) {
              if (id === self._sounds[i]._id) {
                return self._sounds[i];
              }
            }
            return null;
          },
          /**
           * Return an inactive sound from the pool or create a new one.
           * @return {Sound} Sound playback object.
           */
          _inactiveSound: function() {
            var self = this;
            self._drain();
            for (var i = 0; i < self._sounds.length; i++) {
              if (self._sounds[i]._ended) {
                return self._sounds[i].reset();
              }
            }
            return new Sound2(self);
          },
          /**
           * Drain excess inactive sounds from the pool.
           */
          _drain: function() {
            var self = this;
            var limit = self._pool;
            var cnt = 0;
            var i = 0;
            if (self._sounds.length < limit) {
              return;
            }
            for (i = 0; i < self._sounds.length; i++) {
              if (self._sounds[i]._ended) {
                cnt++;
              }
            }
            for (i = self._sounds.length - 1; i >= 0; i--) {
              if (cnt <= limit) {
                return;
              }
              if (self._sounds[i]._ended) {
                if (self._webAudio && self._sounds[i]._node) {
                  self._sounds[i]._node.disconnect(0);
                }
                self._sounds.splice(i, 1);
                cnt--;
              }
            }
          },
          /**
           * Get all ID's from the sounds pool.
           * @param  {Number} id Only return one ID if one is passed.
           * @return {Array}    Array of IDs.
           */
          _getSoundIds: function(id) {
            var self = this;
            if (typeof id === "undefined") {
              var ids = [];
              for (var i = 0; i < self._sounds.length; i++) {
                ids.push(self._sounds[i]._id);
              }
              return ids;
            } else {
              return [id];
            }
          },
          /**
           * Load the sound back into the buffer source.
           * @param  {Sound} sound The sound object to work with.
           * @return {Howl}
           */
          _refreshBuffer: function(sound) {
            var self = this;
            sound._node.bufferSource = Howler2.ctx.createBufferSource();
            sound._node.bufferSource.buffer = cache[self._src];
            if (sound._panner) {
              sound._node.bufferSource.connect(sound._panner);
            } else {
              sound._node.bufferSource.connect(sound._node);
            }
            sound._node.bufferSource.loop = sound._loop;
            if (sound._loop) {
              sound._node.bufferSource.loopStart = sound._start || 0;
              sound._node.bufferSource.loopEnd = sound._stop || 0;
            }
            sound._node.bufferSource.playbackRate.setValueAtTime(sound._rate, Howler2.ctx.currentTime);
            return self;
          },
          /**
           * Prevent memory leaks by cleaning up the buffer source after playback.
           * @param  {Object} node Sound's audio node containing the buffer source.
           * @return {Howl}
           */
          _cleanBuffer: function(node) {
            var self = this;
            var isIOS = Howler2._navigator && Howler2._navigator.vendor.indexOf("Apple") >= 0;
            if (!node.bufferSource) {
              return self;
            }
            if (Howler2._scratchBuffer && node.bufferSource) {
              node.bufferSource.onended = null;
              node.bufferSource.disconnect(0);
              if (isIOS) {
                try {
                  node.bufferSource.buffer = Howler2._scratchBuffer;
                } catch (e) {
                }
              }
            }
            node.bufferSource = null;
            return self;
          },
          /**
           * Set the source to a 0-second silence to stop any downloading (except in IE).
           * @param  {Object} node Audio node to clear.
           */
          _clearSound: function(node) {
            var checkIE = /MSIE |Trident\//.test(Howler2._navigator && Howler2._navigator.userAgent);
            if (!checkIE) {
              node.src = "data:audio/wav;base64,UklGRigAAABXQVZFZm10IBIAAAABAAEARKwAAIhYAQACABAAAABkYXRhAgAAAAEA";
            }
          }
        };
        var Sound2 = function(howl) {
          this._parent = howl;
          this.init();
        };
        Sound2.prototype = {
          /**
           * Initialize a new Sound object.
           * @return {Sound}
           */
          init: function() {
            var self = this;
            var parent = self._parent;
            self._muted = parent._muted;
            self._loop = parent._loop;
            self._volume = parent._volume;
            self._rate = parent._rate;
            self._seek = 0;
            self._paused = true;
            self._ended = true;
            self._sprite = "__default";
            self._id = ++Howler2._counter;
            parent._sounds.push(self);
            self.create();
            return self;
          },
          /**
           * Create and setup a new sound object, whether HTML5 Audio or Web Audio.
           * @return {Sound}
           */
          create: function() {
            var self = this;
            var parent = self._parent;
            var volume = Howler2._muted || self._muted || self._parent._muted ? 0 : self._volume;
            if (parent._webAudio) {
              self._node = typeof Howler2.ctx.createGain === "undefined" ? Howler2.ctx.createGainNode() : Howler2.ctx.createGain();
              self._node.gain.setValueAtTime(volume, Howler2.ctx.currentTime);
              self._node.paused = true;
              self._node.connect(Howler2.masterGain);
            } else if (!Howler2.noAudio) {
              self._node = Howler2._obtainHtml5Audio();
              self._errorFn = self._errorListener.bind(self);
              self._node.addEventListener("error", self._errorFn, false);
              self._loadFn = self._loadListener.bind(self);
              self._node.addEventListener(Howler2._canPlayEvent, self._loadFn, false);
              self._endFn = self._endListener.bind(self);
              self._node.addEventListener("ended", self._endFn, false);
              self._node.src = parent._src;
              self._node.preload = parent._preload === true ? "auto" : parent._preload;
              self._node.volume = volume * Howler2.volume();
              self._node.load();
            }
            return self;
          },
          /**
           * Reset the parameters of this sound to the original state (for recycle).
           * @return {Sound}
           */
          reset: function() {
            var self = this;
            var parent = self._parent;
            self._muted = parent._muted;
            self._loop = parent._loop;
            self._volume = parent._volume;
            self._rate = parent._rate;
            self._seek = 0;
            self._rateSeek = 0;
            self._paused = true;
            self._ended = true;
            self._sprite = "__default";
            self._id = ++Howler2._counter;
            return self;
          },
          /**
           * HTML5 Audio error listener callback.
           */
          _errorListener: function() {
            var self = this;
            self._parent._emit("loaderror", self._id, self._node.error ? self._node.error.code : 0);
            self._node.removeEventListener("error", self._errorFn, false);
          },
          /**
           * HTML5 Audio canplaythrough listener callback.
           */
          _loadListener: function() {
            var self = this;
            var parent = self._parent;
            parent._duration = Math.ceil(self._node.duration * 10) / 10;
            if (Object.keys(parent._sprite).length === 0) {
              parent._sprite = { __default: [0, parent._duration * 1e3] };
            }
            if (parent._state !== "loaded") {
              parent._state = "loaded";
              parent._emit("load");
              parent._loadQueue();
            }
            self._node.removeEventListener(Howler2._canPlayEvent, self._loadFn, false);
          },
          /**
           * HTML5 Audio ended listener callback.
           */
          _endListener: function() {
            var self = this;
            var parent = self._parent;
            if (parent._duration === Infinity) {
              parent._duration = Math.ceil(self._node.duration * 10) / 10;
              if (parent._sprite.__default[1] === Infinity) {
                parent._sprite.__default[1] = parent._duration * 1e3;
              }
              parent._ended(self);
            }
            self._node.removeEventListener("ended", self._endFn, false);
          }
        };
        var cache = {};
        var loadBuffer = function(self) {
          var url = self._src;
          if (cache[url]) {
            self._duration = cache[url].duration;
            loadSound(self);
            return;
          }
          if (/^data:[^;]+;base64,/.test(url)) {
            var data = atob(url.split(",")[1]);
            var dataView = new Uint8Array(data.length);
            for (var i = 0; i < data.length; ++i) {
              dataView[i] = data.charCodeAt(i);
            }
            decodeAudioData(dataView.buffer, self);
          } else {
            var xhr = new XMLHttpRequest();
            xhr.open(self._xhr.method, url, true);
            xhr.withCredentials = self._xhr.withCredentials;
            xhr.responseType = "arraybuffer";
            if (self._xhr.headers) {
              Object.keys(self._xhr.headers).forEach(function(key) {
                xhr.setRequestHeader(key, self._xhr.headers[key]);
              });
            }
            xhr.onload = function() {
              var code = (xhr.status + "")[0];
              if (code !== "0" && code !== "2" && code !== "3") {
                self._emit("loaderror", null, "Failed loading audio file with status: " + xhr.status + ".");
                return;
              }
              decodeAudioData(xhr.response, self);
            };
            xhr.onerror = function() {
              if (self._webAudio) {
                self._html5 = true;
                self._webAudio = false;
                self._sounds = [];
                delete cache[url];
                self.load();
              }
            };
            safeXhrSend(xhr);
          }
        };
        var safeXhrSend = function(xhr) {
          try {
            xhr.send();
          } catch (e) {
            xhr.onerror();
          }
        };
        var decodeAudioData = function(arraybuffer, self) {
          var error = function() {
            self._emit("loaderror", null, "Decoding audio data failed.");
          };
          var success = function(buffer) {
            if (buffer && self._sounds.length > 0) {
              cache[self._src] = buffer;
              loadSound(self, buffer);
            } else {
              error();
            }
          };
          if (typeof Promise !== "undefined" && Howler2.ctx.decodeAudioData.length === 1) {
            Howler2.ctx.decodeAudioData(arraybuffer).then(success).catch(error);
          } else {
            Howler2.ctx.decodeAudioData(arraybuffer, success, error);
          }
        };
        var loadSound = function(self, buffer) {
          if (buffer && !self._duration) {
            self._duration = buffer.duration;
          }
          if (Object.keys(self._sprite).length === 0) {
            self._sprite = { __default: [0, self._duration * 1e3] };
          }
          if (self._state !== "loaded") {
            self._state = "loaded";
            self._emit("load");
            self._loadQueue();
          }
        };
        var setupAudioContext = function() {
          if (!Howler2.usingWebAudio) {
            return;
          }
          try {
            if (typeof AudioContext !== "undefined") {
              Howler2.ctx = new AudioContext();
            } else if (typeof webkitAudioContext !== "undefined") {
              Howler2.ctx = new webkitAudioContext();
            } else {
              Howler2.usingWebAudio = false;
            }
          } catch (e) {
            Howler2.usingWebAudio = false;
          }
          if (!Howler2.ctx) {
            Howler2.usingWebAudio = false;
          }
          var iOS = /iP(hone|od|ad)/.test(Howler2._navigator && Howler2._navigator.platform);
          var appVersion = Howler2._navigator && Howler2._navigator.appVersion.match(/OS (\d+)_(\d+)_?(\d+)?/);
          var version = appVersion ? parseInt(appVersion[1], 10) : null;
          if (iOS && version && version < 9) {
            var safari = /safari/.test(Howler2._navigator && Howler2._navigator.userAgent.toLowerCase());
            if (Howler2._navigator && !safari) {
              Howler2.usingWebAudio = false;
            }
          }
          if (Howler2.usingWebAudio) {
            Howler2.masterGain = typeof Howler2.ctx.createGain === "undefined" ? Howler2.ctx.createGainNode() : Howler2.ctx.createGain();
            Howler2.masterGain.gain.setValueAtTime(Howler2._muted ? 0 : Howler2._volume, Howler2.ctx.currentTime);
            Howler2.masterGain.connect(Howler2.ctx.destination);
          }
          Howler2._setup();
        };
        if (typeof define === "function" && define.amd) {
          define([], function() {
            return {
              Howler: Howler2,
              Howl: Howl3
            };
          });
        }
        if (typeof exports !== "undefined") {
          exports.Howler = Howler2;
          exports.Howl = Howl3;
        }
        if (typeof global !== "undefined") {
          global.HowlerGlobal = HowlerGlobal2;
          global.Howler = Howler2;
          global.Howl = Howl3;
          global.Sound = Sound2;
        } else if (typeof window !== "undefined") {
          window.HowlerGlobal = HowlerGlobal2;
          window.Howler = Howler2;
          window.Howl = Howl3;
          window.Sound = Sound2;
        }
      })();
      (function() {
        "use strict";
        HowlerGlobal.prototype._pos = [0, 0, 0];
        HowlerGlobal.prototype._orientation = [0, 0, -1, 0, 1, 0];
        HowlerGlobal.prototype.stereo = function(pan) {
          var self = this;
          if (!self.ctx || !self.ctx.listener) {
            return self;
          }
          for (var i = self._howls.length - 1; i >= 0; i--) {
            self._howls[i].stereo(pan);
          }
          return self;
        };
        HowlerGlobal.prototype.pos = function(x, y, z) {
          var self = this;
          if (!self.ctx || !self.ctx.listener) {
            return self;
          }
          y = typeof y !== "number" ? self._pos[1] : y;
          z = typeof z !== "number" ? self._pos[2] : z;
          if (typeof x === "number") {
            self._pos = [x, y, z];
            if (typeof self.ctx.listener.positionX !== "undefined") {
              self.ctx.listener.positionX.setTargetAtTime(self._pos[0], Howler.ctx.currentTime, 0.1);
              self.ctx.listener.positionY.setTargetAtTime(self._pos[1], Howler.ctx.currentTime, 0.1);
              self.ctx.listener.positionZ.setTargetAtTime(self._pos[2], Howler.ctx.currentTime, 0.1);
            } else {
              self.ctx.listener.setPosition(self._pos[0], self._pos[1], self._pos[2]);
            }
          } else {
            return self._pos;
          }
          return self;
        };
        HowlerGlobal.prototype.orientation = function(x, y, z, xUp, yUp, zUp) {
          var self = this;
          if (!self.ctx || !self.ctx.listener) {
            return self;
          }
          var or = self._orientation;
          y = typeof y !== "number" ? or[1] : y;
          z = typeof z !== "number" ? or[2] : z;
          xUp = typeof xUp !== "number" ? or[3] : xUp;
          yUp = typeof yUp !== "number" ? or[4] : yUp;
          zUp = typeof zUp !== "number" ? or[5] : zUp;
          if (typeof x === "number") {
            self._orientation = [x, y, z, xUp, yUp, zUp];
            if (typeof self.ctx.listener.forwardX !== "undefined") {
              self.ctx.listener.forwardX.setTargetAtTime(x, Howler.ctx.currentTime, 0.1);
              self.ctx.listener.forwardY.setTargetAtTime(y, Howler.ctx.currentTime, 0.1);
              self.ctx.listener.forwardZ.setTargetAtTime(z, Howler.ctx.currentTime, 0.1);
              self.ctx.listener.upX.setTargetAtTime(xUp, Howler.ctx.currentTime, 0.1);
              self.ctx.listener.upY.setTargetAtTime(yUp, Howler.ctx.currentTime, 0.1);
              self.ctx.listener.upZ.setTargetAtTime(zUp, Howler.ctx.currentTime, 0.1);
            } else {
              self.ctx.listener.setOrientation(x, y, z, xUp, yUp, zUp);
            }
          } else {
            return or;
          }
          return self;
        };
        Howl.prototype.init = /* @__PURE__ */ function(_super) {
          return function(o) {
            var self = this;
            self._orientation = o.orientation || [1, 0, 0];
            self._stereo = o.stereo || null;
            self._pos = o.pos || null;
            self._pannerAttr = {
              coneInnerAngle: typeof o.coneInnerAngle !== "undefined" ? o.coneInnerAngle : 360,
              coneOuterAngle: typeof o.coneOuterAngle !== "undefined" ? o.coneOuterAngle : 360,
              coneOuterGain: typeof o.coneOuterGain !== "undefined" ? o.coneOuterGain : 0,
              distanceModel: typeof o.distanceModel !== "undefined" ? o.distanceModel : "inverse",
              maxDistance: typeof o.maxDistance !== "undefined" ? o.maxDistance : 1e4,
              panningModel: typeof o.panningModel !== "undefined" ? o.panningModel : "HRTF",
              refDistance: typeof o.refDistance !== "undefined" ? o.refDistance : 1,
              rolloffFactor: typeof o.rolloffFactor !== "undefined" ? o.rolloffFactor : 1
            };
            self._onstereo = o.onstereo ? [{ fn: o.onstereo }] : [];
            self._onpos = o.onpos ? [{ fn: o.onpos }] : [];
            self._onorientation = o.onorientation ? [{ fn: o.onorientation }] : [];
            return _super.call(this, o);
          };
        }(Howl.prototype.init);
        Howl.prototype.stereo = function(pan, id) {
          var self = this;
          if (!self._webAudio) {
            return self;
          }
          if (self._state !== "loaded") {
            self._queue.push({
              event: "stereo",
              action: function() {
                self.stereo(pan, id);
              }
            });
            return self;
          }
          var pannerType = typeof Howler.ctx.createStereoPanner === "undefined" ? "spatial" : "stereo";
          if (typeof id === "undefined") {
            if (typeof pan === "number") {
              self._stereo = pan;
              self._pos = [pan, 0, 0];
            } else {
              return self._stereo;
            }
          }
          var ids = self._getSoundIds(id);
          for (var i = 0; i < ids.length; i++) {
            var sound = self._soundById(ids[i]);
            if (sound) {
              if (typeof pan === "number") {
                sound._stereo = pan;
                sound._pos = [pan, 0, 0];
                if (sound._node) {
                  sound._pannerAttr.panningModel = "equalpower";
                  if (!sound._panner || !sound._panner.pan) {
                    setupPanner(sound, pannerType);
                  }
                  if (pannerType === "spatial") {
                    if (typeof sound._panner.positionX !== "undefined") {
                      sound._panner.positionX.setValueAtTime(pan, Howler.ctx.currentTime);
                      sound._panner.positionY.setValueAtTime(0, Howler.ctx.currentTime);
                      sound._panner.positionZ.setValueAtTime(0, Howler.ctx.currentTime);
                    } else {
                      sound._panner.setPosition(pan, 0, 0);
                    }
                  } else {
                    sound._panner.pan.setValueAtTime(pan, Howler.ctx.currentTime);
                  }
                }
                self._emit("stereo", sound._id);
              } else {
                return sound._stereo;
              }
            }
          }
          return self;
        };
        Howl.prototype.pos = function(x, y, z, id) {
          var self = this;
          if (!self._webAudio) {
            return self;
          }
          if (self._state !== "loaded") {
            self._queue.push({
              event: "pos",
              action: function() {
                self.pos(x, y, z, id);
              }
            });
            return self;
          }
          y = typeof y !== "number" ? 0 : y;
          z = typeof z !== "number" ? -0.5 : z;
          if (typeof id === "undefined") {
            if (typeof x === "number") {
              self._pos = [x, y, z];
            } else {
              return self._pos;
            }
          }
          var ids = self._getSoundIds(id);
          for (var i = 0; i < ids.length; i++) {
            var sound = self._soundById(ids[i]);
            if (sound) {
              if (typeof x === "number") {
                sound._pos = [x, y, z];
                if (sound._node) {
                  if (!sound._panner || sound._panner.pan) {
                    setupPanner(sound, "spatial");
                  }
                  if (typeof sound._panner.positionX !== "undefined") {
                    sound._panner.positionX.setValueAtTime(x, Howler.ctx.currentTime);
                    sound._panner.positionY.setValueAtTime(y, Howler.ctx.currentTime);
                    sound._panner.positionZ.setValueAtTime(z, Howler.ctx.currentTime);
                  } else {
                    sound._panner.setPosition(x, y, z);
                  }
                }
                self._emit("pos", sound._id);
              } else {
                return sound._pos;
              }
            }
          }
          return self;
        };
        Howl.prototype.orientation = function(x, y, z, id) {
          var self = this;
          if (!self._webAudio) {
            return self;
          }
          if (self._state !== "loaded") {
            self._queue.push({
              event: "orientation",
              action: function() {
                self.orientation(x, y, z, id);
              }
            });
            return self;
          }
          y = typeof y !== "number" ? self._orientation[1] : y;
          z = typeof z !== "number" ? self._orientation[2] : z;
          if (typeof id === "undefined") {
            if (typeof x === "number") {
              self._orientation = [x, y, z];
            } else {
              return self._orientation;
            }
          }
          var ids = self._getSoundIds(id);
          for (var i = 0; i < ids.length; i++) {
            var sound = self._soundById(ids[i]);
            if (sound) {
              if (typeof x === "number") {
                sound._orientation = [x, y, z];
                if (sound._node) {
                  if (!sound._panner) {
                    if (!sound._pos) {
                      sound._pos = self._pos || [0, 0, -0.5];
                    }
                    setupPanner(sound, "spatial");
                  }
                  if (typeof sound._panner.orientationX !== "undefined") {
                    sound._panner.orientationX.setValueAtTime(x, Howler.ctx.currentTime);
                    sound._panner.orientationY.setValueAtTime(y, Howler.ctx.currentTime);
                    sound._panner.orientationZ.setValueAtTime(z, Howler.ctx.currentTime);
                  } else {
                    sound._panner.setOrientation(x, y, z);
                  }
                }
                self._emit("orientation", sound._id);
              } else {
                return sound._orientation;
              }
            }
          }
          return self;
        };
        Howl.prototype.pannerAttr = function() {
          var self = this;
          var args = arguments;
          var o, id, sound;
          if (!self._webAudio) {
            return self;
          }
          if (args.length === 0) {
            return self._pannerAttr;
          } else if (args.length === 1) {
            if (typeof args[0] === "object") {
              o = args[0];
              if (typeof id === "undefined") {
                if (!o.pannerAttr) {
                  o.pannerAttr = {
                    coneInnerAngle: o.coneInnerAngle,
                    coneOuterAngle: o.coneOuterAngle,
                    coneOuterGain: o.coneOuterGain,
                    distanceModel: o.distanceModel,
                    maxDistance: o.maxDistance,
                    refDistance: o.refDistance,
                    rolloffFactor: o.rolloffFactor,
                    panningModel: o.panningModel
                  };
                }
                self._pannerAttr = {
                  coneInnerAngle: typeof o.pannerAttr.coneInnerAngle !== "undefined" ? o.pannerAttr.coneInnerAngle : self._coneInnerAngle,
                  coneOuterAngle: typeof o.pannerAttr.coneOuterAngle !== "undefined" ? o.pannerAttr.coneOuterAngle : self._coneOuterAngle,
                  coneOuterGain: typeof o.pannerAttr.coneOuterGain !== "undefined" ? o.pannerAttr.coneOuterGain : self._coneOuterGain,
                  distanceModel: typeof o.pannerAttr.distanceModel !== "undefined" ? o.pannerAttr.distanceModel : self._distanceModel,
                  maxDistance: typeof o.pannerAttr.maxDistance !== "undefined" ? o.pannerAttr.maxDistance : self._maxDistance,
                  refDistance: typeof o.pannerAttr.refDistance !== "undefined" ? o.pannerAttr.refDistance : self._refDistance,
                  rolloffFactor: typeof o.pannerAttr.rolloffFactor !== "undefined" ? o.pannerAttr.rolloffFactor : self._rolloffFactor,
                  panningModel: typeof o.pannerAttr.panningModel !== "undefined" ? o.pannerAttr.panningModel : self._panningModel
                };
              }
            } else {
              sound = self._soundById(parseInt(args[0], 10));
              return sound ? sound._pannerAttr : self._pannerAttr;
            }
          } else if (args.length === 2) {
            o = args[0];
            id = parseInt(args[1], 10);
          }
          var ids = self._getSoundIds(id);
          for (var i = 0; i < ids.length; i++) {
            sound = self._soundById(ids[i]);
            if (sound) {
              var pa = sound._pannerAttr;
              pa = {
                coneInnerAngle: typeof o.coneInnerAngle !== "undefined" ? o.coneInnerAngle : pa.coneInnerAngle,
                coneOuterAngle: typeof o.coneOuterAngle !== "undefined" ? o.coneOuterAngle : pa.coneOuterAngle,
                coneOuterGain: typeof o.coneOuterGain !== "undefined" ? o.coneOuterGain : pa.coneOuterGain,
                distanceModel: typeof o.distanceModel !== "undefined" ? o.distanceModel : pa.distanceModel,
                maxDistance: typeof o.maxDistance !== "undefined" ? o.maxDistance : pa.maxDistance,
                refDistance: typeof o.refDistance !== "undefined" ? o.refDistance : pa.refDistance,
                rolloffFactor: typeof o.rolloffFactor !== "undefined" ? o.rolloffFactor : pa.rolloffFactor,
                panningModel: typeof o.panningModel !== "undefined" ? o.panningModel : pa.panningModel
              };
              var panner = sound._panner;
              if (!panner) {
                if (!sound._pos) {
                  sound._pos = self._pos || [0, 0, -0.5];
                }
                setupPanner(sound, "spatial");
                panner = sound._panner;
              }
              panner.coneInnerAngle = pa.coneInnerAngle;
              panner.coneOuterAngle = pa.coneOuterAngle;
              panner.coneOuterGain = pa.coneOuterGain;
              panner.distanceModel = pa.distanceModel;
              panner.maxDistance = pa.maxDistance;
              panner.refDistance = pa.refDistance;
              panner.rolloffFactor = pa.rolloffFactor;
              panner.panningModel = pa.panningModel;
            }
          }
          return self;
        };
        Sound.prototype.init = /* @__PURE__ */ function(_super) {
          return function() {
            var self = this;
            var parent = self._parent;
            self._orientation = parent._orientation;
            self._stereo = parent._stereo;
            self._pos = parent._pos;
            self._pannerAttr = parent._pannerAttr;
            _super.call(this);
            if (self._stereo) {
              parent.stereo(self._stereo);
            } else if (self._pos) {
              parent.pos(self._pos[0], self._pos[1], self._pos[2], self._id);
            }
          };
        }(Sound.prototype.init);
        Sound.prototype.reset = /* @__PURE__ */ function(_super) {
          return function() {
            var self = this;
            var parent = self._parent;
            self._orientation = parent._orientation;
            self._stereo = parent._stereo;
            self._pos = parent._pos;
            self._pannerAttr = parent._pannerAttr;
            if (self._stereo) {
              parent.stereo(self._stereo);
            } else if (self._pos) {
              parent.pos(self._pos[0], self._pos[1], self._pos[2], self._id);
            } else if (self._panner) {
              self._panner.disconnect(0);
              self._panner = void 0;
              parent._refreshBuffer(self);
            }
            return _super.call(this);
          };
        }(Sound.prototype.reset);
        var setupPanner = function(sound, type) {
          type = type || "spatial";
          if (type === "spatial") {
            sound._panner = Howler.ctx.createPanner();
            sound._panner.coneInnerAngle = sound._pannerAttr.coneInnerAngle;
            sound._panner.coneOuterAngle = sound._pannerAttr.coneOuterAngle;
            sound._panner.coneOuterGain = sound._pannerAttr.coneOuterGain;
            sound._panner.distanceModel = sound._pannerAttr.distanceModel;
            sound._panner.maxDistance = sound._pannerAttr.maxDistance;
            sound._panner.refDistance = sound._pannerAttr.refDistance;
            sound._panner.rolloffFactor = sound._pannerAttr.rolloffFactor;
            sound._panner.panningModel = sound._pannerAttr.panningModel;
            if (typeof sound._panner.positionX !== "undefined") {
              sound._panner.positionX.setValueAtTime(sound._pos[0], Howler.ctx.currentTime);
              sound._panner.positionY.setValueAtTime(sound._pos[1], Howler.ctx.currentTime);
              sound._panner.positionZ.setValueAtTime(sound._pos[2], Howler.ctx.currentTime);
            } else {
              sound._panner.setPosition(sound._pos[0], sound._pos[1], sound._pos[2]);
            }
            if (typeof sound._panner.orientationX !== "undefined") {
              sound._panner.orientationX.setValueAtTime(sound._orientation[0], Howler.ctx.currentTime);
              sound._panner.orientationY.setValueAtTime(sound._orientation[1], Howler.ctx.currentTime);
              sound._panner.orientationZ.setValueAtTime(sound._orientation[2], Howler.ctx.currentTime);
            } else {
              sound._panner.setOrientation(sound._orientation[0], sound._orientation[1], sound._orientation[2]);
            }
          } else {
            sound._panner = Howler.ctx.createStereoPanner();
            sound._panner.pan.setValueAtTime(sound._stereo, Howler.ctx.currentTime);
          }
          sound._panner.connect(sound._node);
          if (!sound._paused) {
            sound._parent.pause(sound._id, true).play(sound._id, true);
          }
        };
      })();
    }
  });

  // index.js
  var script_files_exports = {};
  __export(script_files_exports, {
    Diary: () => Diary,
    DiaryMenu: () => DiaryMenu,
    Inventory: () => Inventory,
    addArrow: () => addArrow,
    addInteractable: () => addInteractable,
    addInventory: () => addInventory,
    addMenuPanels: () => addMenuPanels,
    addNpc: () => addNpc,
    addReplaceLink: () => addReplaceLink,
    addWrapperHtml: () => addWrapperHtml,
    closePanel: () => closePanel,
    dialogue: () => dialogue,
    globalScript: () => globalScript,
    musicManager: () => musicManager,
    numpad: () => numpad,
    openMenuPanel: () => openMenuPanel,
    playCutsceneComplex: () => playCutsceneComplex,
    preload: () => preload,
    showDialogue: () => showDialogue
  });

  // ../node_modules/svg-tag-names/index.js
  var svgTagNames = [
    "a",
    "altGlyph",
    "altGlyphDef",
    "altGlyphItem",
    "animate",
    "animateColor",
    "animateMotion",
    "animateTransform",
    "animation",
    "audio",
    "canvas",
    "circle",
    "clipPath",
    "color-profile",
    "cursor",
    "defs",
    "desc",
    "discard",
    "ellipse",
    "feBlend",
    "feColorMatrix",
    "feComponentTransfer",
    "feComposite",
    "feConvolveMatrix",
    "feDiffuseLighting",
    "feDisplacementMap",
    "feDistantLight",
    "feDropShadow",
    "feFlood",
    "feFuncA",
    "feFuncB",
    "feFuncG",
    "feFuncR",
    "feGaussianBlur",
    "feImage",
    "feMerge",
    "feMergeNode",
    "feMorphology",
    "feOffset",
    "fePointLight",
    "feSpecularLighting",
    "feSpotLight",
    "feTile",
    "feTurbulence",
    "filter",
    "font",
    "font-face",
    "font-face-format",
    "font-face-name",
    "font-face-src",
    "font-face-uri",
    "foreignObject",
    "g",
    "glyph",
    "glyphRef",
    "handler",
    "hkern",
    "iframe",
    "image",
    "line",
    "linearGradient",
    "listener",
    "marker",
    "mask",
    "metadata",
    "missing-glyph",
    "mpath",
    "path",
    "pattern",
    "polygon",
    "polyline",
    "prefetch",
    "radialGradient",
    "rect",
    "script",
    "set",
    "solidColor",
    "stop",
    "style",
    "svg",
    "switch",
    "symbol",
    "tbreak",
    "text",
    "textArea",
    "textPath",
    "title",
    "tref",
    "tspan",
    "unknown",
    "use",
    "video",
    "view",
    "vkern"
  ];

  // ../node_modules/dom-chef/index.js
  var svgTags = new Set(svgTagNames);
  svgTags.delete("a");
  svgTags.delete("audio");
  svgTags.delete("canvas");
  svgTags.delete("iframe");
  svgTags.delete("script");
  svgTags.delete("video");
  var IS_NON_DIMENSIONAL = /acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i;
  var isFragment = (type) => type === DocumentFragment;
  var setCSSProps = (element, style) => {
    for (const [name, value] of Object.entries(style)) {
      if (name.startsWith("-")) {
        element.style.setProperty(name, value);
      } else if (typeof value === "number" && !IS_NON_DIMENSIONAL.test(name)) {
        element.style[name] = `${value}px`;
      } else {
        element.style[name] = value;
      }
    }
  };
  var create = (type) => {
    if (typeof type === "string") {
      if (svgTags.has(type)) {
        return document.createElementNS("http://www.w3.org/2000/svg", type);
      }
      return document.createElement(type);
    }
    if (isFragment(type)) {
      return document.createDocumentFragment();
    }
    return type(type.defaultProps);
  };
  var setAttribute = (element, name, value) => {
    if (value === void 0 || value === null) {
      return;
    }
    if (/^xlink[AHRST]/.test(name)) {
      element.setAttributeNS("http://www.w3.org/1999/xlink", name.replace("xlink", "xlink:").toLowerCase(), value);
    } else {
      element.setAttribute(name, value);
    }
  };
  var addChildren = (parent, children) => {
    for (const child of children) {
      if (child instanceof Node) {
        parent.appendChild(child);
      } else if (Array.isArray(child)) {
        addChildren(parent, child);
      } else if (typeof child !== "boolean" && typeof child !== "undefined" && child !== null) {
        parent.appendChild(document.createTextNode(child));
      }
    }
  };
  var booleanishAttributes = /* @__PURE__ */ new Set([
    // These attributes allow "false" as a valid value
    "contentEditable",
    "draggable",
    "spellCheck",
    "value",
    // SVG-specific
    "autoReverse",
    "externalResourcesRequired",
    "focusable",
    "preserveAlpha"
  ]);
  var h = (type, attributes, ...children) => {
    var _a;
    const element = create(type);
    addChildren(element, children);
    if (element instanceof DocumentFragment || !attributes) {
      return element;
    }
    for (let [name, value] of Object.entries(attributes)) {
      if (name === "htmlFor") {
        name = "for";
      }
      if (name === "class" || name === "className") {
        const existingClassname = (_a = element.getAttribute("class")) !== null && _a !== void 0 ? _a : "";
        setAttribute(element, "class", (existingClassname + " " + String(value)).trim());
      } else if (name === "style") {
        setCSSProps(element, value);
      } else if (name.startsWith("on")) {
        const eventName = name.slice(2).toLowerCase().replace(/^-/, "");
        element.addEventListener(eventName, value);
      } else if (name === "dangerouslySetInnerHTML" && "__html" in value) {
        element.innerHTML = value.__html;
      } else if (name !== "key" && (booleanishAttributes.has(name) || value !== false)) {
        setAttribute(element, name, value === true ? "" : value);
      }
    }
    return element;
  };

  // addWrapperHtml.tsx
  function addWrapperHtml() {
    if (document.getElementById("contents") === null) {
      const iffSnippet = document.querySelector("tw-passage");
      if (iffSnippet === null) {
        console.error("tw-passage is null");
        return;
      }
      iffSnippet.remove();
      const contents = /* @__PURE__ */ h("div", { id: "contents" }, /* @__PURE__ */ h("div", { id: "bg", className: "fullscreenBg" }), /* @__PURE__ */ h("div", { id: "passagesFake" }, /* @__PURE__ */ h("div", { id: "screenContents", className: "absoluteAlign" }, iffSnippet), /* @__PURE__ */ h("div", { id: "screenCover", className: "fullscreenBg" })));
      document.querySelector("tw-story")?.appendChild(contents);
    }
  }

  // addReplaceLink.ts
  function clickReplaceLink(event) {
    const identifier = event.target.getAttribute("identifier");
    const replacers = document.querySelectorAll(".linkReplacer[identifier='" + identifier + "']");
    if (replacers.length === 0) {
      console.error("Replacelink without replacer! Identifier " + identifier);
      console.error(event.target);
      return;
    }
    replacers.forEach((r) => {
      if (!r.classList.contains("hidden")) {
        return;
      }
      r.classList.remove("hidden");
    });
    const removed = document.querySelectorAll(".removedOnClick[identifier='" + identifier + "']");
    removed.forEach((r) => {
      r.classList.add("hidden");
    });
  }
  function clickHideText(event) {
    const identifier = event.target.getAttribute("identifier");
    const replacers = document.querySelectorAll(".linkReplacer[identifier='" + identifier + "']");
    if (replacers.length === 0) {
      console.error("Replacelink without replacer! Identifier " + identifier);
      console.error(event.target);
      return;
    }
    replacers.forEach((r) => {
      if (r.classList.contains("hidden")) {
        return;
      }
      r.classList.add("hidden");
    });
    const removed = document.querySelectorAll(".removedOnClick[identifier='" + identifier + "']");
    removed.forEach((r) => {
      r.classList.remove("hidden");
    });
  }
  function addReplaceLink() {
    Array.from(document.getElementsByClassName("linkReplaced")).forEach((e) => {
      e.addEventListener("click", clickReplaceLink);
    });
    Array.from(document.getElementsByClassName("linkHider")).forEach((e) => {
      e.addEventListener("click", clickHideText);
    });
  }

  // addMenuPanels.tsx
  function clickOpener(event) {
    if (event.target === null) {
      return;
    }
    const identifier = event.target.getAttribute("identifier");
    if (identifier === null) {
      console.error("Panel opener without identifier!");
      console.error(event.target);
      return;
    }
    const replacer = document.querySelector(".panelFull[identifier='" + identifier + "']");
    if (replacer === null) {
      console.error("Panel opener without panel!");
      console.error(event.target);
      return;
    }
    openMenuPanel(replacer);
  }
  function openMenuPanel(menuPanel) {
    const screenCover = document.getElementById("screenCover");
    screenCover.style.display = "block";
    menuPanel.classList.remove("hidden");
  }
  function editMenuPanel(menuPanel) {
    if (menuPanel.querySelector(".closeButton") !== null) {
      return;
    }
    const closeButton = /* @__PURE__ */ h("button", { type: "button", className: "closeButton" }, "X");
    closeButton.addEventListener("click", () => {
      closePanel(menuPanel);
    });
    menuPanel.prepend(closeButton);
  }
  function closePanel(menuPanel) {
    menuPanel.classList.add("hidden");
    const screenCover = document.getElementById("screenCover");
    screenCover.style.display = "none";
  }
  function addMenuPanels() {
    Array.from(document.getElementsByClassName("panelOpener")).forEach((e) => {
      e.addEventListener("click", clickOpener);
    });
    Array.from(document.getElementsByClassName("panelFull")).forEach((e) => {
      editMenuPanel(e);
    });
  }

  // utility.ts
  function getPassageTags(pass) {
    if (pass === void 0) {
      pass = window.passage.name;
    }
    var passage = document.querySelector('tw-storydata tw-passagedata[name="' + pass + '"]');
    return (passage.getAttribute("tags") || "").trim().split(/\s+/).filter((n) => n);
  }
  function addTagsToStory(pass) {
    const tags = getPassageTags(pass);
    const tw_story = document.querySelector("tw-story");
    tw_story.removeAttribute("class");
    for (const tag of tags) {
      tw_story.classList.add(tag);
    }
  }

  // musicSetup.ts
  var import_howler = __toESM(require_howler(), 1);
  function addMaxVolume(howl, maxVolume) {
    howl["maxVolume"] = maxVolume;
    return howl;
  }
  var menuMusic = [
    addMaxVolume(
      new import_howler.Howl({
        src: [
          "assets/sound/gusts_of_wind_through_birch_trees.ogg",
          "assets/sound/gusts_of_wind_through_birch_trees.mp3"
        ],
        loop: true,
        autoplay: false,
        volume: 0,
        html5: true,
        preload: "metadata"
      }),
      0.3
    ),
    addMaxVolume(
      new import_howler.Howl({
        src: ["assets/sound/iNeedYourHelp.ogg", "assets/sound/iNeedYourHelp.mp3"],
        loop: true,
        autoplay: false,
        volume: 0,
        html5: true,
        preload: "metadata"
      }),
      1
    )
  ];
  var bedroomAwake = [
    addMaxVolume(
      new import_howler.Howl({
        src: ["assets/sound/room_tone.ogg", "assets/sound/room_tone.mp3"],
        loop: true,
        autoplay: false,
        volume: 0,
        html5: true,
        preload: "metadata"
      }),
      0.7
    ),
    addMaxVolume(
      new import_howler.Howl({
        src: [
          "assets/sound/airConditioner.ogg",
          "assets/sound/airConditioner.mp3"
        ],
        loop: true,
        autoplay: false,
        volume: 0,
        html5: true,
        preload: "metadata"
      }),
      1
    )
  ];
  var bedroomAsleep = [
    addMaxVolume(
      new import_howler.Howl({
        src: ["assets/sound/room_tone.ogg", "assets/sound/room_tone.mp3"],
        loop: true,
        autoplay: false,
        volume: 0,
        html5: true,
        preload: "metadata"
      }),
      1
    ),
    addMaxVolume(
      new import_howler.Howl({
        src: ["assets/sound/beamOfLight.ogg", "assets/sound/beamOfLight.mp3"],
        loop: true,
        autoplay: false,
        volume: 0,
        html5: true,
        preload: "metadata"
      }),
      0.8
    )
  ];
  var mines = [
    addMaxVolume(
      new import_howler.Howl({
        src: ["assets/sound/cave.ogg", "assets/sound/cave.mp3"],
        loop: true,
        autoplay: false,
        volume: 0,
        html5: true,
        preload: "metadata"
      }),
      1.2
    ),
    addMaxVolume(
      new import_howler.Howl({
        src: ["assets/sound/poisonFlowers.ogg", "assets/sound/poisonFlowers.mp3"],
        loop: true,
        autoplay: false,
        volume: 0,
        html5: true,
        preload: "metadata"
      }),
      0.7
    )
  ];
  var minesPit = [
    addMaxVolume(
      new import_howler.Howl({
        src: ["assets/sound/cave.ogg", "assets/sound/cave.mp3"],
        loop: true,
        autoplay: false,
        volume: 0,
        html5: true,
        preload: "metadata"
      }),
      1.5
    )
  ];
  var factory = [
    addMaxVolume(
      new import_howler.Howl({
        src: ["assets/sound/bus.ogg", "assets/sound/bus.mp3"],
        loop: true,
        autoplay: false,
        volume: 0,
        html5: true,
        preload: "metadata"
      }),
      0.3
    ),
    addMaxVolume(
      new import_howler.Howl({
        src: [
          "assets/sound/feelingTimeDisappear.ogg",
          "assets/sound/feelingTimeDisappear.mp3"
        ],
        loop: true,
        autoplay: false,
        volume: 0,
        html5: true,
        preload: "metadata"
      }),
      0.7
    )
  ];
  var office1 = [
    addMaxVolume(
      new import_howler.Howl({
        src: ["assets/sound/room_tone.ogg", "assets/sound/room_tone.mp3"],
        loop: true,
        autoplay: false,
        volume: 0,
        html5: true,
        preload: "metadata"
      }),
      0.3
    ),
    addMaxVolume(
      new import_howler.Howl({
        src: ["assets/sound/buzzing_light.ogg", "assets/sound/buzzing_light.mp3"],
        loop: true,
        autoplay: false,
        volume: 0,
        html5: true,
        preload: "metadata"
      }),
      0.2
    ),
    addMaxVolume(
      new import_howler.Howl({
        src: ["assets/sound/typing.ogg", "assets/sound/typing.mp3"],
        loop: true,
        autoplay: false,
        volume: 0,
        html5: true,
        preload: "metadata"
      }),
      1
    ),
    addMaxVolume(
      new import_howler.Howl({
        src: ["assets/sound/iCantDoThis.ogg", "assets/sound/iCantDoThis.mp3"],
        loop: true,
        autoplay: false,
        volume: 0,
        html5: true,
        preload: "metadata"
      }),
      1
    )
  ];
  var office2 = [
    addMaxVolume(
      new import_howler.Howl({
        src: ["assets/sound/room_tone.ogg", "assets/sound/room_tone.mp3"],
        loop: true,
        autoplay: false,
        volume: 0,
        html5: true,
        preload: "metadata"
      }),
      0.3
    ),
    addMaxVolume(
      new import_howler.Howl({
        src: ["assets/sound/buzzing_light.ogg", "assets/sound/buzzing_light.mp3"],
        loop: true,
        autoplay: false,
        volume: 0,
        html5: true,
        preload: "metadata"
      }),
      0.2
    ),
    addMaxVolume(
      new import_howler.Howl({
        src: ["assets/sound/typing.ogg", "assets/sound/typing.mp3"],
        loop: true,
        autoplay: false,
        volume: 0,
        html5: true,
        preload: "metadata"
      }),
      1
    ),
    addMaxVolume(
      new import_howler.Howl({
        src: [
          "assets/sound/anhedoniaOnset.ogg",
          "assets/sound/anhedoniaOnset.mp3"
        ],
        loop: true,
        autoplay: false,
        volume: 0,
        html5: true,
        preload: "metadata"
      }),
      1
    )
  ];
  var smoke = [
    addMaxVolume(
      new import_howler.Howl({
        src: ["assets/sound/intoVoid.ogg", "assets/sound/intoVoid.mp3"],
        loop: true,
        autoplay: false,
        volume: 0,
        html5: true,
        preload: "metadata"
      }),
      1
    ),
    addMaxVolume(
      new import_howler.Howl({
        src: ["assets/sound/windHowl.ogg", "assets/sound/windHowl.mp3"],
        loop: true,
        autoplay: false,
        volume: 0,
        html5: true,
        preload: "metadata"
      }),
      1
    )
  ];
  var beach = [
    addMaxVolume(
      new import_howler.Howl({
        src: ["assets/sound/waves1.ogg", "assets/sound/waves1.mp3"],
        loop: true,
        autoplay: false,
        volume: 0,
        html5: true,
        preload: "metadata"
      }),
      1.1
    ),
    addMaxVolume(
      new import_howler.Howl({
        src: ["assets/sound/waves2.ogg", "assets/sound/waves2.mp3"],
        loop: true,
        autoplay: false,
        volume: 0,
        html5: true,
        preload: "metadata"
      }),
      1
    )
  ];
  var end1 = [
    addMaxVolume(
      new import_howler.Howl({
        src: ["assets/sound/avancons.ogg", "assets/sound/avancons.mp3"],
        loop: true,
        autoplay: false,
        volume: 0,
        html5: true,
        preload: "metadata"
      }),
      1.1
    )
  ];
  var pool = [
    addMaxVolume(
      new import_howler.Howl({
        src: ["assets/sound/pool.ogg", "assets/sound/pool.mp3"],
        loop: true,
        autoplay: false,
        volume: 0,
        html5: true,
        preload: "metadata"
      }),
      1
    )
  ];
  var noise = [
    addMaxVolume(
      new import_howler.Howl({
        src: ["assets/sound/noise.ogg", "assets/sound/noise.mp3"],
        loop: true,
        autoplay: false,
        volume: 0,
        html5: true,
        preload: "metadata"
      }),
      1
    ),
    addMaxVolume(
      new import_howler.Howl({
        src: ["assets/sound/windHowl.ogg", "assets/sound/windHowl.mp3"],
        loop: true,
        autoplay: false,
        volume: 0,
        html5: true,
        preload: "metadata"
      }),
      1
    )
  ];
  var windowsError = new import_howler.Howl({
    src: ["assets/sound/windowsError.ogg", "assets/sound/windowsError.mp3"],
    loop: false,
    volume: 1,
    autoplay: false,
    html5: true,
    preload: "metadata"
  });
  var jingle1 = new import_howler.Howl({
    src: ["assets/sound/jingle2.ogg", "assets/sound/jingle2.mp3"],
    loop: false,
    volume: 0.6,
    autoplay: false,
    html5: true,
    preload: "metadata"
  });
  var jingle2 = new import_howler.Howl({
    src: ["assets/sound/jingle1.ogg", "assets/sound/jingle1.mp3"],
    loop: false,
    volume: 0.6,
    autoplay: false,
    html5: true,
    preload: "metadata"
  });
  var pageFlip = new import_howler.Howl({
    src: ["assets/sound/pageFlip.ogg", "assets/sound/pageFlip.mp3"],
    loop: false,
    volume: 1,
    autoplay: false,
    html5: true,
    preload: "metadata"
  });
  var sheriff = new import_howler.Howl({
    src: ["assets/sound/sheriff2.ogg", "assets/sound/sheriff2.mp3"],
    loop: false,
    volume: 1,
    autoplay: false,
    html5: true,
    preload: "metadata"
  });
  var knock = new import_howler.Howl({
    src: ["assets/sound/knocking.ogg", "assets/sound/knocking.mp3"],
    loop: true,
    volume: 1,
    autoplay: false,
    html5: true,
    preload: "metadata"
  });
  var door = new import_howler.Howl({
    src: ["assets/sound/door.ogg", "assets/sound/door.mp3"],
    loop: false,
    volume: 0.4,
    autoplay: false,
    html5: true,
    preload: "metadata"
  });
  var knife = new import_howler.Howl({
    src: ["assets/sound/knife.ogg", "assets/sound/knife.mp3"],
    loop: false,
    volume: 1,
    autoplay: false,
    html5: true,
    preload: "metadata"
  });
  var screech = new import_howler.Howl({
    src: ["assets/sound/screech.ogg", "assets/sound/screech.mp3"],
    loop: false,
    volume: 1,
    autoplay: false,
    html5: true,
    preload: "metadata"
  });

  // music.ts
  var musicManager = {
    activeSoundtrack: null,
    soundtracks: [
      { area: "menuMusic", soundtrack: menuMusic },
      { area: "bedroomAwakeMusic", soundtrack: bedroomAwake },
      { area: "bedroomAsleepMusic", soundtrack: bedroomAsleep },
      { area: "minesMusic", soundtrack: mines },
      { area: "minesPitMusic", soundtrack: minesPit },
      { area: "factoryMusic", soundtrack: factory },
      { area: "smokeMusic", soundtrack: smoke },
      { area: "officeMusic1", soundtrack: office1 },
      { area: "officeMusic2", soundtrack: office2 },
      { area: "beach", soundtrack: beach },
      { area: "pool", soundtrack: pool },
      { area: "noise", soundtrack: noise },
      { area: "end1Music", soundtrack: end1 }
    ],
    soundEffects: [
      { name: "windowsError", sound: windowsError },
      { name: "jingle1", sound: jingle1 },
      { name: "jingle2", sound: jingle2 },
      { name: "pageFlip", sound: pageFlip },
      { name: "sheriff", sound: sheriff },
      { name: "knock", sound: knock },
      { name: "door", sound: door },
      { name: "knife", sound: knife },
      { name: "screech", sound: screech }
    ],
    // from https://stackoverflow.com/a/11381730 because volume change doesn't work on mobile and you can't detect possibility of volume change directly (https://stackoverflow.com/questions/59417075/javascript-detect-if-volume-can-be-set)
    // but it keeps returning true even though I'm not on mobile? even though the actual site itself works?
    // not using for now
    mobileCheck() {
      let check = false;
      function regex_check(a) {
        if (/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(
          a
        ) || /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(
          a.substr(0, 4)
        )) {
          check = true;
        }
      }
      regex_check(navigator.userAgent || navigator.vendor || window.opera);
      return check;
    },
    playHowl: function(howl) {
      if (howl.state() === "unloaded") {
        howl.load();
      }
      howl.play();
    },
    activateSoundtrackMusic: function(newSoundtrack) {
      for (const howl of newSoundtrack.soundtrack) {
        let maxVolume = howl["maxVolume"];
        if (maxVolume === void 0) {
          maxVolume = 1;
        }
        if (!howl.playing()) {
          this.playHowl(howl);
        }
        setTimeout(() => {
          if (this.activeSoundtrack !== null && newSoundtrack.area === this.activeSoundtrack.area) {
            howl.fade(0, maxVolume, 4e3);
          }
        }, 10);
      }
    },
    playSoundtrack: function(snippetTags) {
      let newSoundtrack = this.soundtracks.find(
        (i) => snippetTags.includes(i.area)
      );
      if (newSoundtrack === void 0) {
        newSoundtrack = null;
      } else if (this.activeSoundtrack !== null && newSoundtrack.area === this.activeSoundtrack.area) {
        return;
      }
      const oldSoundtrack = this.activeSoundtrack;
      this.activeSoundtrack = newSoundtrack;
      if (oldSoundtrack !== null) {
        oldSoundtrack.soundtrack.forEach((howl) => {
          if (this.mobileCheck()) {
            howl.stop();
          } else {
            howl.fade(howl.volume(), 0, 2e3);
          }
        });
      }
      if (newSoundtrack !== null) {
        setTimeout(() => {
          this.activateSoundtrackMusic(newSoundtrack);
        }, 1e3);
      }
    },
    playSoundEffect(effectName) {
      let soundEffect = this.soundEffects.find(
        (i) => i.name === effectName
      );
      if (soundEffect === null) {
        console.error("Trying to play nonexistent sound effect: " + effectName);
      }
      this.playHowl(soundEffect.sound);
    },
    getSoundEffect(effectName) {
      return this.soundEffects.find(
        (i) => i.name === effectName
      ).sound;
    }
  };

  // specific/utility.tsx
  function addCloseButton(element) {
    const closeButton = /* @__PURE__ */ h("button", { type: "button", className: "closeButton" }, "X");
    closeButton.addEventListener("click", () => {
      element.remove();
    });
    element.prepend(closeButton);
    return closeButton;
  }
  function addArrow(direction, destination, top = void 0, left = void 0, angle = void 0) {
    const container = document.querySelector(".passage");
    const arrow = /* @__PURE__ */ h("img", { className: "arrow", src: "assets/arrow.gif", alt: "arrow" });
    switch (direction) {
      case "up":
        arrow.style.transform = "rotate(270deg)";
        arrow.style.top = "2%";
        arrow.style.left = "48%";
        arrow.classList.add("up");
        break;
      case "down":
        arrow.style.transform = "rotate(90deg)";
        arrow.style.top = "95%";
        arrow.style.left = "48%";
        arrow.classList.add("down");
        break;
      case "left":
        arrow.style.transform = "rotate(180deg)";
        arrow.style.top = "45%";
        arrow.style.left = "1%";
        arrow.classList.add("left");
        break;
      case "right":
        arrow.style.top = "45%";
        arrow.style.left = "95%";
        arrow.classList.add("right");
        break;
      case "upleft":
        arrow.style.transform = "rotate(225deg)";
        arrow.style.top = "2%";
        arrow.style.left = "1%";
        arrow.classList.add("upleft");
        break;
      case "upright":
        arrow.style.transform = "rotate(315deg)";
        arrow.style.top = "2%";
        arrow.style.left = "95%";
        arrow.classList.add("upright");
        break;
      case "downleft":
        arrow.style.transform = "rotate(135deg)";
        arrow.style.top = "95%";
        arrow.style.left = "1%";
        arrow.classList.add("downleft");
        break;
      case "downright":
        arrow.style.transform = "rotate(45deg)";
        arrow.style.top = "95%";
        arrow.style.left = "95%";
        arrow.classList.add("downright");
        break;
      default:
        console.error("Trying to create arrow with invalid direction: " + direction);
        return;
    }
    if (top !== void 0) {
      arrow.style.top = top + "%";
    }
    if (left !== void 0) {
      arrow.style.left = left + "%";
    }
    if (angle !== void 0) {
      arrow.style.transform = "rotate(" + angle + "deg)";
    }
    arrow.addEventListener("click", () => {
      window.story.show(destination);
    });
    container.append(arrow);
  }
  function playCutsceneComplex(imgSrcList, millisecondList, big = false, callbackAfterDone = null) {
    if (imgSrcList.length !== millisecondList.length) {
      console.error("playCutsceneComplex: arrays not same length");
      console.error(imgSrcList);
      console.error(millisecondList);
      return;
    }
    const cutsceneDiv = /* @__PURE__ */ h("div", { className: "absoluteAlign blackBg cutscenePanel" });
    if (big) {
      cutsceneDiv.classList.add("bigCutscenePanel");
    }
    const screenCover = document.getElementById("screenCover");
    screenCover.style.display = "block";
    const container = document.querySelector("#screenContents");
    container.append(cutsceneDiv);
    const timeoutFunctionList = [];
    function generateShowCutsceneFunction(i) {
      return () => {
        cutsceneDiv.innerHTML = "";
        const image1 = /* @__PURE__ */ h("img", { src: imgSrcList[i] });
        cutsceneDiv.append(image1);
        setTimeout(() => {
          if (i < imgSrcList.length - 1) {
            const next = /* @__PURE__ */ h("button", { type: "button", className: "nextButton" }, "\u2B95");
            next.addEventListener("click", () => {
              timeoutFunctionList[i + 1]();
            });
            cutsceneDiv.append(next);
          } else {
            const closeButton = addCloseButton(cutsceneDiv);
            closeButton.addEventListener("click", () => {
              screenCover.style.display = "none";
              if (callbackAfterDone !== null) {
                callbackAfterDone();
              }
            });
          }
        }, millisecondList[i]);
      };
    }
    for (let i = 0; i < imgSrcList.length; i++) {
      timeoutFunctionList.push(generateShowCutsceneFunction(i));
    }
    timeoutFunctionList[0]();
  }
  function preload(imageList) {
    if (!window.hasOwnProperty("_ImageCache")) {
      window._ImageCache = [];
      window.preloadedImages = [];
    }
    window.numberLoadedImages = 0;
    imageList.map(function(url) {
      if (!window.preloadedImages.includes(url)) {
        const image = document.createElement("img");
        image.onload = () => {
          window.numberLoadedImages++;
          console.log("image ", window.numberLoadedImages, " ", url);
        };
        image.src = url;
        window._ImageCache.push(image);
        window.preloadedImages.push(url);
      }
    });
  }

  // specific/npcs.tsx
  var NEXT_STRING = "\u2B62";
  var END_STRING = "\u2BA0";
  function addNpc(src, top, left, width, name, dialogueList) {
    const container = document.querySelector(".passage");
    let npc;
    if (name !== null && name !== "") {
      npc = /* @__PURE__ */ h("img", { className: "npc", src, id: name, alt: name });
    } else {
      npc = /* @__PURE__ */ h("img", { className: "npc", src, id: src });
    }
    npc.style.top = top + "%";
    npc.style.left = left + "%";
    npc.style.width = width + "%";
    npc.addEventListener("click", () => {
      showDialogue(name, dialogueList);
    });
    container.append(npc);
  }
  function addInteractable(top, left, bottom, right, dialogueList) {
    const container = document.querySelector(".passage");
    let npc = /* @__PURE__ */ h("div", { className: "interactable" });
    npc.style.top = top + "%";
    npc.style.left = left + "%";
    npc.style.bottom = bottom + "%";
    npc.style.right = right + "%";
    npc.addEventListener("click", () => {
      showDialogue(null, dialogueList);
    });
    container.append(npc);
  }
  function showDialogue(name, dialogueList, index = 0) {
    showCover();
    const dialogue2 = dialogueList[index];
    const dialoguePanel = getDialoguePanel();
    dialoguePanel.innerHTML = "";
    const dialogueText = document.createElement("p");
    dialogueText.innerHTML = dialogue2.text;
    dialoguePanel.append(dialogueText);
    if (name !== null) {
      const namePanel = getNamePanel();
      namePanel.innerHTML = name;
    }
    if (dialogue2.playerOptions !== void 0) {
      for (let i = 0; i < dialogue2.playerOptions.length; i++) {
        const option = dialogue2.playerOptions[i];
        const optionHtml = /* @__PURE__ */ h("a", null, option.text);
        if (option.nextPassage !== null) {
          optionHtml.addEventListener("click", () => {
            showDialogue(name, dialogueList, option.nextPassage);
          });
        } else {
          optionHtml.addEventListener("click", () => {
            closeDialoguePanel(dialoguePanel);
          });
        }
        if (option.callback !== void 0) {
          optionHtml.addEventListener("click", () => {
            option.callback();
          });
        }
        dialoguePanel.append(optionHtml);
        if (i < dialogue2.playerOptions.length - 1) {
          dialoguePanel.append(/* @__PURE__ */ h("span", null, "\xA0|\xA0"));
        }
      }
    } else {
      let optionHtml;
      if (index < dialogueList.length - 1) {
        optionHtml = /* @__PURE__ */ h("a", null, NEXT_STRING);
        optionHtml.addEventListener("click", () => {
          showDialogue(name, dialogueList, index + 1);
        });
      } else {
        optionHtml = /* @__PURE__ */ h("a", null, END_STRING);
        optionHtml.addEventListener("click", () => {
          closeDialoguePanel(dialoguePanel);
        });
      }
      dialoguePanel.append(optionHtml);
    }
  }
  function closeDialoguePanel(dialoguePanel) {
    hideCover();
    dialoguePanel.remove();
    document.getElementById("namePanel")?.remove();
  }
  function showCover() {
    const screenCover = document.getElementById("screenCover");
    screenCover.style.display = "block";
  }
  function hideCover() {
    const screenCover = document.getElementById("screenCover");
    screenCover.style.display = "none";
  }
  function getDialoguePanel() {
    let dialoguePanel = document.querySelector("#dialoguePanel");
    if (dialoguePanel === null) {
      dialoguePanel = createDialoguePanel();
    }
    return dialoguePanel;
  }
  function createDialoguePanel() {
    const dialoguePanel = /* @__PURE__ */ h("div", { id: "dialoguePanel", className: "absoluteAlign bottomHalf blackBg dialoguePanel" });
    const iffSnippet = document.querySelector(".passage");
    iffSnippet.append(dialoguePanel);
    return dialoguePanel;
  }
  function getNamePanel() {
    let namePanel = document.querySelector("#namePanel");
    if (namePanel === null) {
      namePanel = createNamePanel();
    }
    return namePanel;
  }
  function createNamePanel() {
    const namePanel = /* @__PURE__ */ h("div", { id: "namePanel", className: "absoluteAlign bottomHalf blackBg" });
    const iffSnippet = document.querySelector(".passage");
    iffSnippet.append(namePanel);
    return namePanel;
  }

  // specific/dialogue.tsx
  var dialogue = {
    bossDialogue: [
      {
        text: "SO A NEW DREAMER ARRIVES."
      },
      {
        text: "THE OTHER DREAMERS ARE IRRITANTS."
      },
      {
        text: "INTRUDERS. HIDING OUT IN THE FACTORY."
      },
      {
        text: "PERFORM NO WORK."
      },
      {
        text: "BUT PERHAPS WE CAN MAKE GOOD USE OF YOU."
      },
      {
        text: "GO PROVE YOURSELF VALUABLE.",
        playerOptions: [
          {
            text: NEXT_STRING,
            nextPassage: null,
            callback: () => {
              window.story.state.myInventory.addItem(
                {
                  name: "Dream Extractor",
                  iconSrc: "assets/knife.gif",
                  acquiredText: "For humans like you."
                }
              );
            }
          }
        ]
      }
    ],
    bossDialogue2: [
      {
        text: "YOUR PERFORMANCE IS UNSATISFACTORY."
      },
      {
        text: "CONTINUE WORK."
      }
    ],
    bossDialogueEnd: [
      {
        text: "WE ACKNOWLEDGE YOUR TASK COMPLETION."
      },
      {
        text: "NOW YOU ARE ONE OF US."
      },
      {
        text: "NORTH OF THE ENTRANCE IS YOUR REWARD."
      },
      {
        text: "CLIMB UP AND SEE THE BENEFITS."
      },
      {
        text: "DO NOT FLEE."
      }
    ]
  };

  // specific/keypad.ts
  var numpad = {
    // (A) PROPERTIES
    // (A1) HTML ELEMENTS
    hDisplay: null,
    // number display
    maxDig: 4,
    maxDec: 0,
    disabled: false,
    correctCode: null,
    successCallback: null,
    // (B) INIT - CREATE NUMPAD HTML
    init: (correctCode, successCallback) => {
      numpad.correctCode = correctCode;
      numpad.successCallback = successCallback;
      numpad.hDisplay = document.getElementById("numDisplay");
      let hbWrap = document.getElementById("numBWrap"), buttonator = (txt, css, fn) => {
        let button = document.createElement("div");
        button.innerHTML = txt;
        button.classList.add(css);
        button.onclick = fn;
        hbWrap.appendChild(button);
      };
      for (let i = 7; i <= 9; i++) {
        buttonator(i, "num", () => numpad.digit(i));
      }
      buttonator("&#10502;", "del", numpad.delete);
      for (let i = 4; i <= 6; i++) {
        buttonator(i, "num", () => numpad.digit(i));
      }
      buttonator("C", "clr", numpad.reset);
      for (let i = 1; i <= 3; i++) {
        buttonator(i, "num", () => numpad.digit(i));
      }
      buttonator(0, "zero", () => numpad.digit(0));
      buttonator("&#10004;", "ok", numpad.select);
    },
    // (C) BUTTON ACTIONS
    // (C1) NUMBER (0 TO 9)
    digit: (num) => {
      if (!numpad.disabled) {
        let v = numpad.hDisplay.value;
        if (v.indexOf(".") == -1) {
          if (v.length < numpad.maxDig) {
            if (v == "0") {
              numpad.hDisplay.value = num;
            } else {
              numpad.hDisplay.value += num;
            }
          }
        } else {
          if (v.split(".")[1].length < numpad.maxDec) {
            numpad.hDisplay.value += num;
          }
        }
      }
    },
    // (C3) BACKSPACE
    delete: () => {
      if (!numpad.disabled) {
        var length = numpad.hDisplay.value.length;
        if (length == 1) {
          numpad.hDisplay.value = 0;
        } else {
          numpad.hDisplay.value = numpad.hDisplay.value.substring(0, length - 1);
        }
      }
    },
    // (C4) CLEAR ALL
    reset: () => {
      if (!numpad.disabled) {
        numpad.hDisplay.value = "0";
      }
    },
    // (C5) OK - SET VALUE
    select: () => {
      if ("" + numpad.hDisplay.value === "" + numpad.correctCode) {
        numpad.hDisplay.style.borderColor = "green";
        numpad.disabled = true;
        numpad.successCallback();
      } else {
        numpad.hDisplay.style.borderColor = "red";
      }
    }
  };

  // specific/inventory.tsx
  var Inventory = class {
    items;
    constructor() {
      this.items = [];
    }
    addItem(item) {
      this.items.push(item);
      this.addItemNotif(item);
    }
    addItemNotif(item) {
      const panel = /* @__PURE__ */ h("div", { className: "panelFull panelSmall absoluteAlign hidden" }, /* @__PURE__ */ h("p", null, /* @__PURE__ */ h("span", { className: "itemName" }, "Acquired: ", item.name), " "), /* @__PURE__ */ h("img", { className: "itemIcon", src: item.iconSrc }));
      if (item.acquiredText !== void 0) {
        const description = /* @__PURE__ */ h("p", null, item.acquiredText);
        panel.append(description);
      }
      editMenuPanel(panel);
      document.querySelector("#passagesFake").append(panel);
      openMenuPanel(panel);
      musicManager.playSoundEffect("jingle1");
    }
    removeItem(name) {
      for (let i = 0; i < this.items.length; i++) {
        if (this.items[i].name === name) {
          this.items.splice(i, 1);
        }
      }
    }
    clear() {
      this.items = [];
    }
    checkHasItem(name) {
      for (const item of this.items) {
        if (item.name === name) {
          return true;
        }
      }
      return false;
    }
  };

  // specific/diary.tsx
  var Diary = class {
    pages;
    foundPages;
    constructor() {
      this.pages = [
        { name: "old", imagePath: "assets/diary/pageOld.png" },
        { name: "bird1040", imagePath: "assets/diary/pageBird1040.png" },
        { name: "churn", imagePath: "assets/diary/pageChurn.png" },
        { name: "cioran", imagePath: "assets/diary/pageCioran.png" },
        { name: "harvest", imagePath: "assets/diary/pageHarvest.png" },
        { name: "meatPlastic", imagePath: "assets/diary/pageMeatPlastic.png" },
        { name: "memo", imagePath: "assets/diary/pageMemo.png" },
        { name: "rain", imagePath: "assets/diary/pageRain.png" },
        { name: "room", imagePath: "assets/diary/pageRoom.png" },
        { name: "scribble", imagePath: "assets/diary/pageScribble.png" },
        { name: "workerSteps", imagePath: "assets/diary/pageWorkerSteps.png" }
      ];
      this.foundPages = [];
    }
    getPage(name) {
      const result = this.pages.find((item) => item.name === name);
      if (result === void 0) {
        console.error("getPage for name: " + name + " returns null!");
      }
      return result;
    }
    checkPageFound(name) {
      return this.foundPages.includes(name);
    }
    nextPage(currentPageName) {
      const index = this.foundPages.indexOf(currentPageName);
      if (index === -1) {
        console.error("Running nextPage on unfound page.");
        return null;
      }
      if (index === this.foundPages.length - 1) {
        return null;
      } else {
        return this.getPage(this.foundPages[index + 1]);
      }
    }
    prevPage(currentPageName) {
      const index = this.foundPages.indexOf(currentPageName);
      if (index === -1) {
        console.error("Running prevPage on unfound page.");
        return null;
      }
      if (index === 0) {
        return null;
      } else {
        return this.getPage(this.foundPages[index - 1]);
      }
    }
    addPageNotif(page) {
      const panel = /* @__PURE__ */ h("div", { id: "pageAcquired", className: "panelFull panelSmall absoluteAlign hidden" }, /* @__PURE__ */ h("p", null, /* @__PURE__ */ h("span", { className: "itemName" }, this.foundPages.length, "/", this.pages.length), " "), /* @__PURE__ */ h("img", { src: page.imagePath }));
      editMenuPanel(panel);
      document.querySelector("#passagesFake").append(panel);
      openMenuPanel(panel);
      musicManager.playSoundEffect("jingle1");
    }
    findPage(pageName) {
      this.addPage(pageName);
      const pageObject = this.getPage(pageName);
      this.addPageNotif(pageObject);
      musicManager.playSoundEffect("jingle1");
    }
    addPage(pageName) {
      if (this.checkPageFound(pageName)) {
        console.error("Running findPage on page already obtained.");
        return;
      }
      this.foundPages.push(pageName);
    }
    addPageItem(pageName, top, left, width) {
      if (!this.checkPageFound(pageName)) {
        const container = document.querySelector(".passage");
        const page = /* @__PURE__ */ h("img", { className: "page interactable", src: "assets/diary/icon.gif" });
        page.style.top = top + "%";
        page.style.left = left + "%";
        page.style.width = width + "%";
        page.addEventListener("click", () => {
          this.findPage(pageName);
          page.remove();
        });
        container.append(page);
      }
    }
    /* DEBUG ONLY */
    getAllPages() {
      this.foundPages = [];
      console.log(this.pages);
      this.pages.forEach((p) => {
        this.foundPages.push(p.name);
      });
      this.foundPages.splice(this.foundPages.indexOf("churn"), 1);
    }
  };

  // specific/diaryMenu.tsx
  var DiaryMenu = class {
    diary;
    currentPage;
    constructor(diary, startingPageName) {
      this.diary = diary;
      this.currentPage = this.diary.getPage(startingPageName);
    }
    refreshDiary(panel) {
      panel.querySelector("#page").src = this.currentPage.imagePath;
      panel.querySelector("#diaryRight")?.remove();
      const nextPage = this.diary.nextPage(this.currentPage.name);
      if (nextPage !== null) {
        const arrowRight = /* @__PURE__ */ h("a", { id: "diaryRight", className: "diaryArrow" }, "\u21D2");
        arrowRight.addEventListener("click", () => {
          musicManager.playSoundEffect("pageFlip");
          this.currentPage = nextPage;
          this.refreshDiary(panel);
        });
        panel.append(arrowRight);
      }
      panel.querySelector("#diaryLeft")?.remove();
      const prevPage = this.diary.prevPage(this.currentPage.name);
      if (prevPage !== null) {
        const arrowLeft = /* @__PURE__ */ h("a", { id: "diaryLeft", className: "diaryArrow" }, "\u21D0");
        arrowLeft.addEventListener("click", () => {
          musicManager.playSoundEffect("pageFlip");
          this.currentPage = prevPage;
          this.refreshDiary(panel);
        });
        panel.append(arrowLeft);
      }
    }
    openDiary() {
      const screenCover = document.getElementById("screenCover");
      screenCover.style.display = "block";
      const panel = this.getDiary();
      this.refreshDiary(panel);
      panel.classList.remove("hidden");
    }
    getDiary() {
      const diary = document.getElementById("diaryPanel");
      if (diary === null) {
        return this.createDiary();
      }
      return diary;
    }
    createDiary() {
      const panel = /* @__PURE__ */ h("div", { id: "diaryPanel", className: "panelFull absoluteAlign hidden" }, /* @__PURE__ */ h("img", { id: "diaryBg", src: "assets/diary/diaryBg.png" }), /* @__PURE__ */ h("img", { id: "page" }));
      editMenuPanel(panel);
      document.querySelector("tw-passage").append(panel);
      return panel;
    }
  };

  // specific/inventoryMenu.tsx
  function refreshInventory(panel) {
    const inventoryDiv = panel.querySelector("#items");
    inventoryDiv.innerHTML = "";
    for (const item of window.story.state.myInventory.items) {
      const newItem = /* @__PURE__ */ h("img", { className: "itemIcon", src: item.iconSrc });
      newItem.addEventListener("mouseenter", () => {
        document.querySelector("#label").innerHTML = item.name;
      });
      newItem.addEventListener("mouseleave", () => {
        document.querySelector("#label").innerHTML = "";
      });
      inventoryDiv.append(newItem);
    }
  }
  function openInventory() {
    const screenCover = document.getElementById("screenCover");
    screenCover.style.display = "block";
    const panel = getInventory();
    refreshInventory(panel);
    panel.classList.remove("hidden");
  }
  function getInventory() {
    const inventory = document.getElementById("inventoryPanel");
    if (inventory === null) {
      return createInventory();
    }
    return inventory;
  }
  function createInventory() {
    const panel = /* @__PURE__ */ h("div", { id: "inventoryPanel", className: "panelFull absoluteAlign hidden" }, /* @__PURE__ */ h("div", { id: "label", className: "itemName" }), /* @__PURE__ */ h("div", { id: "items" }));
    editMenuPanel(panel);
    const wakeUp = /* @__PURE__ */ h("button", { type: "button", className: "wakeUp" }, "Wake Up");
    wakeUp.addEventListener("click", () => {
      closePanel(panel);
      document.querySelector("#inventoryOpener").remove();
      window.story.show("transition1");
    });
    panel.append(wakeUp);
    return panel;
  }
  function addInventory() {
    if (!getPassageTags().includes("dream")) {
      document.getElementById("inventoryOpener")?.remove();
      return;
    }
    if (document.querySelector("#inventoryOpener") !== null) {
      return;
    }
    const opener = /* @__PURE__ */ h("a", { id: "inventoryOpener" }, "\u2749");
    opener.addEventListener("click", () => {
      openInventory();
    });
    const panel = getInventory();
    document.querySelector("#passagesFake").append(opener, panel);
  }

  // index.js
  function globalScript() {
    addWrapperHtml();
    addReplaceLink();
    addInventory();
    addMenuPanels();
    addTagsToStory(window.passage.name);
    musicManager.playSoundtrack(getPassageTags());
  }
  return __toCommonJS(script_files_exports);
})();
/*! Bundled license information:

howler/dist/howler.js:
  (*!
   *  howler.js v2.2.4
   *  howlerjs.com
   *
   *  (c) 2013-2020, James Simpson of GoldFire Studios
   *  goldfirestudios.com
   *
   *  MIT License
   *)
  (*!
   *  Spatial Plugin - Adds support for stereo and 3D audio where Web Audio is supported.
   *  
   *  howler.js v2.2.4
   *  howlerjs.com
   *
   *  (c) 2013-2020, James Simpson of GoldFire Studios
   *  goldfirestudios.com
   *
   *  MIT License
   *)
*/
window.mainScript = mainScript;
