text: /**
   * @license
   * Copyright 2018 Google Inc.
   *
   * Permission is hereby granted, free of charge, to any person obtaining a copy
   * of this software and associated documentation files (the "Software"), to deal
   * in the Software without restriction, including without limitation the rights
   * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
   * copies of the Software, and to permit persons to whom the Software is
   * furnished to do so, subject to the following conditions:
   *
   * The above copyright notice and this permission notice shall be included in
   * all copies or substantial portions of the Software.
   *
   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
   * THE SOFTWARE.
   */
  import * as tslib_1 from "tslib";
  import { MDCComponent } from '@material/base/component';
  import { MDCList, MDCListFoundation } from '@material/list/index';
  import { MDCMenuSurfaceFoundation } from '@material/menu-surface/foundation';
  import { MDCMenuSurface } from '@material/menu-surface/index';
  import { cssClasses, strings } from './constants';
  import { MDCMenuFoundation } from './foundation';
  var MDCMenu = /** @class */ (function (_super) {
      tslib_1.__extends(MDCMenu, _super);
      function MDCMenu() {
          return _super !== null && _super.apply(this, arguments) || this;
      }
      MDCMenu.attachTo = function (root) {
          return new MDCMenu(root);
      };
      MDCMenu.prototype.initialize = function (menuSurfaceFactory, listFactory) {
          if (menuSurfaceFactory === void 0) { menuSurfaceFactory = function (el) { return new MDCMenuSurface(el); }; }
          if (listFactory === void 0) { listFactory = function (el) { return new MDCList(el); }; }
          this.menuSurfaceFactory_ = menuSurfaceFactory;
          this.listFactory_ = listFactory;
      };
      MDCMenu.prototype.initialSyncWithDOM = function () {
          var _this = this;
          this.menuSurface_ = this.menuSurfaceFactory_(this.root_);
          var list = this.root_.querySelector(strings.LIST_SELECTOR);
          if (list) {
              this.list_ = this.listFactory_(list);
              this.list_.wrapFocus = true;
          }
          else {
              this.list_ = null;
          }
          this.handleKeydown_ = function (evt) { return _this.foundation_.handleKeydown(evt); };
          this.handleItemAction_ = function (evt) { return _this.foundation_.handleItemAction(_this.items[evt.detail.index]); };
          this.afterOpenedCallback_ = function () { return _this.handleAfterOpened_(); };
          this.menuSurface_.listen(MDCMenuSurfaceFoundation.strings.OPENED_EVENT, this.afterOpenedCallback_);
          this.listen('keydown', this.handleKeydown_);
          this.listen(MDCListFoundation.strings.ACTION_EVENT, this.handleItemAction_);
      };
      MDCMenu.prototype.destroy = function () {
          if (this.list_) {
              this.list_.destroy();
          }
          this.menuSurface_.destroy();
          this.menuSurface_.unlisten(MDCMenuSurfaceFoundation.strings.OPENED_EVENT, this.afterOpenedCallback_);
          this.unlisten('keydown', this.handleKeydown_);
          this.unlisten(MDCListFoundation.strings.ACTION_EVENT, this.handleItemAction_);
          _super.prototype.destroy.call(this);
      };
      Object.defineProperty(MDCMenu.prototype, "open", {
          get: function () {
              return this.menuSurface_.open;
          },
          set: function (value) {
              this.menuSurface_.open = value;
          },
          enumerable: true,
          configurable: true
      });
      Object.defineProperty(MDCMenu.prototype, "wrapFocus", {
          get: function () {
              return this.list_ ? this.list_.wrapFocus : false;
          },
          set: function (value) {
              if (this.list_) {
                  this.list_.wrapFocus = value;
              }
          },
          enumerable: true,
          configurable: true
      });
      Object.defineProperty(MDCMenu.prototype, "items", {
          /**
           * Return the items within the menu. Note that this only contains the set of elements within
           * the items container that are proper list items, and not supplemental / presentational DOM
           * elements.
           */
          get: function () {
              return this.list_ ? this.list_.listElements : [];
          },
          enumerable: true,
          configurable: true
      });
      Object.defineProperty(MDCMenu.prototype, "quickOpen", {
          set: function (quickOpen) {
              this.menuSurface_.quickOpen = quickOpen;
          },
          enumerable: true,
          configurable: true
      });
      /**
       * @param corner Default anchor corner alignment of top-left menu corner.
       */
      MDCMenu.prototype.setAnchorCorner = function (corner) {
          this.menuSurface_.setAnchorCorner(corner);
      };
      MDCMenu.prototype.setAnchorMargin = function (margin) {
          this.menuSurface_.setAnchorMargin(margin);
      };
      /**
       * @return The item within the menu at the index specified.
       */
      MDCMenu.prototype.getOptionByIndex = function (index) {
          var items = this.items;
          if (index < items.length) {
              return this.items[index];
          }
          else {
              return null;
          }
      };
      MDCMenu.prototype.setFixedPosition = function (isFixed) {
          this.menuSurface_.setFixedPosition(isFixed);
      };
      MDCMenu.prototype.hoistMenuToBody = function () {
          this.menuSurface_.hoistMenuToBody();
      };
      MDCMenu.prototype.setIsHoisted = function (isHoisted) {
          this.menuSurface_.setIsHoisted(isHoisted);
      };
      MDCMenu.prototype.setAbsolutePosition = function (x, y) {
          this.menuSurface_.setAbsolutePosition(x, y);
      };
      /**
       * Sets the element that the menu-surface is anchored to.
       */
      MDCMenu.prototype.setAnchorElement = function (element) {
          this.menuSurface_.anchorElement = element;
      };
      MDCMenu.prototype.getDefaultFoundation = function () {
          var _this = this;
          // DO NOT INLINE this variable. For backward compatibility, foundations take a Partial<MDCFooAdapter>.
          // To ensure we don't accidentally omit any methods, we need a separate, strongly typed adapter variable.
          // tslint:disable:object-literal-sort-keys Methods should be in the same order as the adapter interface.
          var adapter = {
              addClassToElementAtIndex: function (index, className) {
                  var list = _this.items;
                  list[index].classList.add(className);
              },
              removeClassFromElementAtIndex: function (index, className) {
                  var list = _this.items;
                  list[index].classList.remove(className);
              },
              addAttributeToElementAtIndex: function (index, attr, value) {
                  var list = _this.items;
                  list[index].setAttribute(attr, value);
              },
              removeAttributeFromElementAtIndex: function (index, attr) {
                  var list = _this.items;
                  list[index].removeAttribute(attr);
              },
              elementContainsClass: function (element, className) { return element.classList.contains(className); },
              closeSurface: function () { return _this.open = false; },
              getElementIndex: function (element) { return _this.items.indexOf(element); },
              getParentElement: function (element) { return element.parentElement; },
              getSelectedElementIndex: function (selectionGroup) {
                  var selectedListItem = selectionGroup.querySelector("." + cssClasses.MENU_SELECTED_LIST_ITEM);
                  return selectedListItem ? _this.items.indexOf(selectedListItem) : -1;
              },
              notifySelected: function (evtData) { return _this.emit(strings.SELECTED_EVENT, {
                  index: evtData.index,
                  item: _this.items[evtData.index],
              }); },
          };
          // tslint:enable:object-literal-sort-keys
          return new MDCMenuFoundation(adapter);
      };
      MDCMenu.prototype.handleAfterOpened_ = function () {
          var list = this.items;
          if (list.length > 0) {
              list[0].focus();
          }
      };
      return MDCMenu;
  }(MDCComponent));
  export { MDCMenu };
  //# sourceMappingURL=component.js.map