text: define(["exports", "../../../lit-element/lit-element.js"], function (_exports, _litElement) {
    "use strict";
  
    Object.defineProperty(_exports, "__esModule", {
      value: true
    });
    _exports.A11yMediaStateManager = void 0;
  
    function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
  
    function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { babelHelpers.defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
  
    function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = babelHelpers.getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = babelHelpers.getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return babelHelpers.possibleConstructorReturn(this, result); }; }
  
    function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
  
    // register globally so we can make sure there is only one
    window.A11yMediaStateManager = window.A11yMediaStateManager || {}; // request if this exists. This helps invoke the element existing in the dom
    // as well as that there is only one of them. That way we can ensure everything
    // is rendered through the same modal
  
    window.A11yMediaStateManager.requestAvailability = function () {
      if (!window.A11yMediaStateManager.instance) {
        window.A11yMediaStateManager.instance = document.createElement("a11y-media-state-manager");
        document.body.appendChild(window.A11yMediaStateManager.instance);
      }
  
      return window.A11yMediaStateManager.instance;
    };
    /**
     * `a11y-media-state-manager`
     * A utility that manages the state of multiple a11y-media-players on a single page.
     *
     */
  
  
    var A11yMediaStateManager = /*#__PURE__*/function (_LitElement) {
      babelHelpers.inherits(A11yMediaStateManager, _LitElement);
  
      var _super = _createSuper(A11yMediaStateManager);
  
      babelHelpers.createClass(A11yMediaStateManager, null, [{
        key: "tag",
  
        /**
         * Store the tag name to make it easier to obtain directly.
         */
        get: function get() {
          return "a11y-media-state-manager";
        } // properties available to the custom element for data binding
  
      }, {
        key: "properties",
        get: function get() {
          return _objectSpread(_objectSpread({}, babelHelpers.get(babelHelpers.getPrototypeOf(A11yMediaStateManager), "properties", this)), {}, {
            /**
             * Stores an array of all the players on the page.
             */
            players: {
              type: Array
            },
  
            /**
             * Manages which player is currently active.
             */
            activePlayer: {
              type: Object
            }
          });
        }
        /**
         * Makes sure there is a utility ready and listening for elements.
         */
  
      }]);
  
      function A11yMediaStateManager() {
        var _this;
  
        babelHelpers.classCallCheck(this, A11yMediaStateManager);
        _this = _super.call(this);
        _this.players = [];
  
        _this.__stickyManager = function (e) {
          return _this.setStickyPlayer(e.detail);
        };
  
        _this.__activeManager = function (e) {
          return _this.setActivePlayer(e.detail);
        };
  
        _this.__scrollChecker = function (e) {
          return _this._checkScroll(e);
        };
  
        _this.__playerLoader = function (e) {
          return _this.players.push(e.detail);
        }; // sets the instance to the current instance
  
  
        if (!window.A11yMediaStateManager.instance) {
          window.A11yMediaStateManager.instance = babelHelpers.assertThisInitialized(_this);
        }
  
        return _this;
      }
      /**
       * if a player disallows concurrent players, pauses other players
       */
  
  
      babelHelpers.createClass(A11yMediaStateManager, [{
        key: "checkConcurrentPlayers",
        value: function checkConcurrentPlayers() {
          var active = this.activePlayer;
          this.players.forEach(function (player) {
            if (player !== active) {
              player.toggleFullscreen(false);
              if (!player.allowConcurrent && !active.allowConcurrent || active.fullscreen) player.pause();
            }
          });
        }
        /**
         * sets the active player
         *
         * @param {object} the player to set stickiness
         */
  
      }, {
        key: "setActivePlayer",
        value: function setActivePlayer(player) {
          this.activePlayer = player;
          this.checkConcurrentPlayers();
        }
        /**
         * stops all other players on the page
         *
         * @param {object} the player to set stickiness
         */
  
      }, {
        key: "setStickyPlayer",
        value: function setStickyPlayer(player) {
          var parent = this._getParentNode(player);
  
          this.__playerTop = parent.offsetTop;
          this.__playerUpperMiddle = this.__playerTop + parent.offsetHeight * 0.9;
          this.__playerLowerMiddle = this.__playerTop + parent.offsetHeight * 0.1;
  
          if (player !== this.activePlayer && this.activePlayer !== undefined && this.activePlayer !== null) {
            this.activePlayer.toggleSticky(false);
          }
  
          parent.style.height = parent.offsetHeight + "px";
          this.setActivePlayer(player);
  
          this._checkScroll();
        }
        /**
         * checks the wondow's scroll position and compares it to active player to set sticky attribute
         */
  
      }, {
        key: "_checkScroll",
        value: function _checkScroll() {
          var wintop = window.pageYOffset,
              winbottom = wintop + window.innerHeight;
  
          if (this.activePlayer !== undefined && this.activePlayer !== null) {
            if (this.activePlayer.__playing && (this.__playerLowerMiddle > winbottom || this.__playerUpperMiddle < wintop)) {
              this.activePlayer.toggleSticky(true);
            } else {
              this.activePlayer.toggleSticky(false);
            }
          }
        }
        /**
         * gets parent node in light DOM
         *
         * @param {object} the node
         * @returns {object} the parent node
         */
  
      }, {
        key: "_getParentNode",
        value: function _getParentNode(node) {
          var parent = node.parentNode;
  
          if (parent !== undefined && parent !== null && parent.nodeType === Node.DOCUMENT_FRAGMENT_NODE) {
            parent = parent.host;
          }
  
          return parent;
        }
      }, {
        key: "connectedCallback",
        value: function connectedCallback() {
          babelHelpers.get(babelHelpers.getPrototypeOf(A11yMediaStateManager.prototype), "connectedCallback", this).call(this); // listen for a player that starts playing
  
          window.addEventListener("a11y-player-playing", this.__stickyManager); // listen for a player toggles fullscreen mode
  
          window.addEventListener("a11y-player-fullscreen", this.__activeManager); // listen for scrolling and find out if a player is off-screen
  
          window.addEventListener("scroll", this.__scrollChecker); // listen for a players added to the page
  
          window.addEventListener("a11y-player", this.__playerLoader);
        }
        /**
         * life cycle, element is removed from the DOM
         */
  
      }, {
        key: "disconnectedCallback",
        value: function disconnectedCallback() {
          var root = this;
          window.removeEventListener("a11y-player", root.__playerLoader);
          window.removeEventListener("a11y-player-playing", root.__stickyManager);
          window.removeEventListener("a11y-player-fullscreen", root.__activeManager);
          window.removeEventListener("scroll", root.__scrollChecker);
          babelHelpers.get(babelHelpers.getPrototypeOf(A11yMediaStateManager.prototype), "disconnectedCallback", this).call(this);
        }
      }]);
      return A11yMediaStateManager;
    }(_litElement.LitElement);
  
    _exports.A11yMediaStateManager = A11yMediaStateManager;
    window.customElements.define(A11yMediaStateManager.tag, A11yMediaStateManager);
  });