text: /*! *****************************************************************************
  Copyright (c) Microsoft Corporation.
  
  Permission to use, copy, modify, and/or distribute this software for any
  purpose with or without fee is hereby granted.
  
  THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
  REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
  INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
  OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  PERFORMANCE OF THIS SOFTWARE.
  ***************************************************************************** */
  /* global Reflect, Promise */
  
  var extendStatics = function(d, b) {
      extendStatics = Object.setPrototypeOf ||
          ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
          function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
      return extendStatics(d, b);
  };
  
  function __extends(d, b) {
      extendStatics(d, b);
      function __() { this.constructor = d; }
      d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  }
  
  var __assign = function() {
      __assign = Object.assign || function __assign(t) {
          for (var s, i = 1, n = arguments.length; i < n; i++) {
              s = arguments[i];
              for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
          }
          return t;
      };
      return __assign.apply(this, arguments);
  };
  
  function __read(o, n) {
      var m = typeof Symbol === "function" && o[Symbol.iterator];
      if (!m) return o;
      var i = m.call(o), r, ar = [], e;
      try {
          while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
      }
      catch (error) { e = { error: error }; }
      finally {
          try {
              if (r && !r.done && (m = i["return"])) m.call(i);
          }
          finally { if (e) throw e.error; }
      }
      return ar;
  }
  
  function __spread() {
      for (var ar = [], i = 0; i < arguments.length; i++)
          ar = ar.concat(__read(arguments[i]));
      return ar;
  }
  
  /**
   * @license
   * Copyright 2016 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.
   */
  var MDCFoundation = /** @class */ (function () {
      function MDCFoundation(adapter) {
          if (adapter === void 0) { adapter = {}; }
          this.adapter = adapter;
      }
      Object.defineProperty(MDCFoundation, "cssClasses", {
          get: function () {
              // Classes extending MDCFoundation should implement this method to return an object which exports every
              // CSS class the foundation class needs as a property. e.g. {ACTIVE: 'mdc-component--active'}
              return {};
          },
          enumerable: true,
          configurable: true
      });
      Object.defineProperty(MDCFoundation, "strings", {
          get: function () {
              // Classes extending MDCFoundation should implement this method to return an object which exports all
              // semantic strings as constants. e.g. {ARIA_ROLE: 'tablist'}
              return {};
          },
          enumerable: true,
          configurable: true
      });
      Object.defineProperty(MDCFoundation, "numbers", {
          get: function () {
              // Classes extending MDCFoundation should implement this method to return an object which exports all
              // of its semantic numbers as constants. e.g. {ANIMATION_DELAY_MS: 350}
              return {};
          },
          enumerable: true,
          configurable: true
      });
      Object.defineProperty(MDCFoundation, "defaultAdapter", {
          get: function () {
              // Classes extending MDCFoundation may choose to implement this getter in order to provide a convenient
              // way of viewing the necessary methods of an adapter. In the future, this could also be used for adapter
              // validation.
              return {};
          },
          enumerable: true,
          configurable: true
      });
      MDCFoundation.prototype.init = function () {
          // Subclasses should override this method to perform initialization routines (registering events, etc.)
      };
      MDCFoundation.prototype.destroy = function () {
          // Subclasses should override this method to perform de-initialization routines (de-registering events, etc.)
      };
      return MDCFoundation;
  }());
  
  /**
   * @license
   * Copyright 2016 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.
   */
  var MDCComponent = /** @class */ (function () {
      function MDCComponent(root, foundation) {
          var args = [];
          for (var _i = 2; _i < arguments.length; _i++) {
              args[_i - 2] = arguments[_i];
          }
          this.root = root;
          this.initialize.apply(this, __spread(args));
          // Note that we initialize foundation here and not within the constructor's default param so that
          // this.root_ is defined and can be used within the foundation class.
          this.foundation =
              foundation === undefined ? this.getDefaultFoundation() : foundation;
          this.foundation.init();
          this.initialSyncWithDOM();
      }
      MDCComponent.attachTo = function (root) {
          // Subclasses which extend MDCBase should provide an attachTo() method that takes a root element and
          // returns an instantiated component with its root set to that element. Also note that in the cases of
          // subclasses, an explicit foundation class will not have to be passed in; it will simply be initialized
          // from getDefaultFoundation().
          return new MDCComponent(root, new MDCFoundation({}));
      };
      /* istanbul ignore next: method param only exists for typing purposes; it does not need to be unit tested */
      MDCComponent.prototype.initialize = function () {
          var _args = [];
          for (var _i = 0; _i < arguments.length; _i++) {
              _args[_i] = arguments[_i];
          }
          // Subclasses can override this to do any additional setup work that would be considered part of a
          // "constructor". Essentially, it is a hook into the parent constructor before the foundation is
          // initialized. Any additional arguments besides root and foundation will be passed in here.
      };
      MDCComponent.prototype.getDefaultFoundation = function () {
          // Subclasses must override this method to return a properly configured foundation class for the
          // component.
          throw new Error('Subclasses must override getDefaultFoundation to return a properly configured ' +
              'foundation class');
      };
      MDCComponent.prototype.initialSyncWithDOM = function () {
          // Subclasses should override this method if they need to perform work to synchronize with a host DOM
          // object. An example of this would be a form control wrapper that needs to synchronize its internal state
          // to some property or attribute of the host DOM. Please note: this is *not* the place to perform DOM
          // reads/writes that would cause layout / paint, as this is called synchronously from within the constructor.
      };
      MDCComponent.prototype.destroy = function () {
          // Subclasses may implement this method to release any resources / deregister any listeners they have
          // attached. An example of this might be deregistering a resize event from the window object.
          this.foundation.destroy();
      };
      MDCComponent.prototype.listen = function (evtType, handler, options) {
          this.root.addEventListener(evtType, handler, options);
      };
      MDCComponent.prototype.unlisten = function (evtType, handler, options) {
          this.root.removeEventListener(evtType, handler, options);
      };
      /**
       * Fires a cross-browser-compatible custom event from the component root of the given type, with the given data.
       */
      MDCComponent.prototype.emit = function (evtType, evtData, shouldBubble) {
          if (shouldBubble === void 0) { shouldBubble = false; }
          var evt;
          if (typeof CustomEvent === 'function') {
              evt = new CustomEvent(evtType, {
                  bubbles: shouldBubble,
                  detail: evtData,
              });
          }
          else {
              evt = document.createEvent('CustomEvent');
              evt.initCustomEvent(evtType, shouldBubble, false, evtData);
          }
          this.root.dispatchEvent(evt);
      };
      return MDCComponent;
  }());
  
  /**
   * @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.
   */
  /**
   * @fileoverview A "ponyfill" is a polyfill that doesn't modify the global prototype chain.
   * This makes ponyfills safer than traditional polyfills, especially for libraries like MDC.
   */
  function closest(element, selector) {
      if (element.closest) {
          return element.closest(selector);
      }
      var el = element;
      while (el) {
          if (matches(el, selector)) {
              return el;
          }
          el = el.parentElement;
      }
      return null;
  }
  function matches(element, selector) {
      var nativeMatches = element.matches
          || element.webkitMatchesSelector
          || element.msMatchesSelector;
      return nativeMatches.call(element, selector);
  }
  
  /**
   * @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.
   */
  var cssClasses = {
      LIST_ITEM_ACTIVATED_CLASS: 'mdc-list-item--activated',
      LIST_ITEM_CLASS: 'mdc-list-item',
      LIST_ITEM_DISABLED_CLASS: 'mdc-list-item--disabled',
      LIST_ITEM_SELECTED_CLASS: 'mdc-list-item--selected',
      LIST_ITEM_TEXT_CLASS: 'mdc-list-item__text',
      LIST_ITEM_PRIMARY_TEXT_CLASS: 'mdc-list-item__primary-text',
      ROOT: 'mdc-list',
  };
  var strings = {
      ACTION_EVENT: 'MDCList:action',
      ARIA_CHECKED: 'aria-checked',
      ARIA_CHECKED_CHECKBOX_SELECTOR: '[role="checkbox"][aria-checked="true"]',
      ARIA_CHECKED_RADIO_SELECTOR: '[role="radio"][aria-checked="true"]',
      ARIA_CURRENT: 'aria-current',
      ARIA_DISABLED: 'aria-disabled',
      ARIA_ORIENTATION: 'aria-orientation',
      ARIA_ORIENTATION_HORIZONTAL: 'horizontal',
      ARIA_ROLE_CHECKBOX_SELECTOR: '[role="checkbox"]',
      ARIA_SELECTED: 'aria-selected',
      CHECKBOX_RADIO_SELECTOR: 'input[type="checkbox"], input[type="radio"]',
      CHECKBOX_SELECTOR: 'input[type="checkbox"]',
      CHILD_ELEMENTS_TO_TOGGLE_TABINDEX: "\n    ." + cssClasses.LIST_ITEM_CLASS + " button:not(:disabled),\n    ." + cssClasses.LIST_ITEM_CLASS + " a\n  ",
      FOCUSABLE_CHILD_ELEMENTS: "\n    ." + cssClasses.LIST_ITEM_CLASS + " button:not(:disabled),\n    ." + cssClasses.LIST_ITEM_CLASS + " a,\n    ." + cssClasses.LIST_ITEM_CLASS + " input[type=\"radio\"]:not(:disabled),\n    ." + cssClasses.LIST_ITEM_CLASS + " input[type=\"checkbox\"]:not(:disabled)\n  ",
      RADIO_SELECTOR: 'input[type="radio"]',
  };
  var numbers = {
      UNSET_INDEX: -1,
      TYPEAHEAD_BUFFER_CLEAR_TIMEOUT_MS: 300
  };
  
  /**
   * @license
   * Copyright 2020 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.
   */
  /**
   * KEY provides normalized string values for keys.
   */
  var KEY = {
      UNKNOWN: 'Unknown',
      BACKSPACE: 'Backspace',
      ENTER: 'Enter',
      SPACEBAR: 'Spacebar',
      PAGE_UP: 'PageUp',
      PAGE_DOWN: 'PageDown',
      END: 'End',
      HOME: 'Home',
      ARROW_LEFT: 'ArrowLeft',
      ARROW_UP: 'ArrowUp',
      ARROW_RIGHT: 'ArrowRight',
      ARROW_DOWN: 'ArrowDown',
      DELETE: 'Delete',
      ESCAPE: 'Escape',
  };
  var normalizedKeys = new Set();
  // IE11 has no support for new Map with iterable so we need to initialize this
  // by hand.
  normalizedKeys.add(KEY.BACKSPACE);
  normalizedKeys.add(KEY.ENTER);
  normalizedKeys.add(KEY.SPACEBAR);
  normalizedKeys.add(KEY.PAGE_UP);
  normalizedKeys.add(KEY.PAGE_DOWN);
  normalizedKeys.add(KEY.END);
  normalizedKeys.add(KEY.HOME);
  normalizedKeys.add(KEY.ARROW_LEFT);
  normalizedKeys.add(KEY.ARROW_UP);
  normalizedKeys.add(KEY.ARROW_RIGHT);
  normalizedKeys.add(KEY.ARROW_DOWN);
  normalizedKeys.add(KEY.DELETE);
  normalizedKeys.add(KEY.ESCAPE);
  var KEY_CODE = {
      BACKSPACE: 8,
      ENTER: 13,
      SPACEBAR: 32,
      PAGE_UP: 33,
      PAGE_DOWN: 34,
      END: 35,
      HOME: 36,
      ARROW_LEFT: 37,
      ARROW_UP: 38,
      ARROW_RIGHT: 39,
      ARROW_DOWN: 40,
      DELETE: 46,
      ESCAPE: 27,
  };
  var mappedKeyCodes = new Map();
  // IE11 has no support for new Map with iterable so we need to initialize this
  // by hand.
  mappedKeyCodes.set(KEY_CODE.BACKSPACE, KEY.BACKSPACE);
  mappedKeyCodes.set(KEY_CODE.ENTER, KEY.ENTER);
  mappedKeyCodes.set(KEY_CODE.SPACEBAR, KEY.SPACEBAR);
  mappedKeyCodes.set(KEY_CODE.PAGE_UP, KEY.PAGE_UP);
  mappedKeyCodes.set(KEY_CODE.PAGE_DOWN, KEY.PAGE_DOWN);
  mappedKeyCodes.set(KEY_CODE.END, KEY.END);
  mappedKeyCodes.set(KEY_CODE.HOME, KEY.HOME);
  mappedKeyCodes.set(KEY_CODE.ARROW_LEFT, KEY.ARROW_LEFT);
  mappedKeyCodes.set(KEY_CODE.ARROW_UP, KEY.ARROW_UP);
  mappedKeyCodes.set(KEY_CODE.ARROW_RIGHT, KEY.ARROW_RIGHT);
  mappedKeyCodes.set(KEY_CODE.ARROW_DOWN, KEY.ARROW_DOWN);
  mappedKeyCodes.set(KEY_CODE.DELETE, KEY.DELETE);
  mappedKeyCodes.set(KEY_CODE.ESCAPE, KEY.ESCAPE);
  var navigationKeys = new Set();
  // IE11 has no support for new Set with iterable so we need to initialize this
  // by hand.
  navigationKeys.add(KEY.PAGE_UP);
  navigationKeys.add(KEY.PAGE_DOWN);
  navigationKeys.add(KEY.END);
  navigationKeys.add(KEY.HOME);
  navigationKeys.add(KEY.ARROW_LEFT);
  navigationKeys.add(KEY.ARROW_UP);
  navigationKeys.add(KEY.ARROW_RIGHT);
  navigationKeys.add(KEY.ARROW_DOWN);
  /**
   * normalizeKey returns the normalized string for a navigational action.
   */
  function normalizeKey(evt) {
      var key = evt.key;
      // If the event already has a normalized key, return it
      if (normalizedKeys.has(key)) {
          return key;
      }
      // tslint:disable-next-line:deprecation
      var mappedKey = mappedKeyCodes.get(evt.keyCode);
      if (mappedKey) {
          return mappedKey;
      }
      return KEY.UNKNOWN;
  }
  
  /**
   * @license
   * Copyright 2020 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.
   */
  var ELEMENTS_KEY_ALLOWED_IN = ['input', 'button', 'textarea', 'select'];
  /**
   * Ensures that preventDefault is only called if the containing element
   * doesn't consume the event, and it will cause an unintended scroll.
   *
   * @param evt keyboard event to be prevented.
   */
  var preventDefaultEvent = function (evt) {
      var target = evt.target;
      if (!target) {
          return;
      }
      var tagName = ("" + target.tagName).toLowerCase();
      if (ELEMENTS_KEY_ALLOWED_IN.indexOf(tagName) === -1) {
          evt.preventDefault();
      }
  };
  
  /**
   * @license
   * Copyright 2020 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.
   */
  /**
   * Initializes a state object for typeahead. Use the same reference for calls to
   * typeahead functions.
   *
   * @return The current state of the typeahead process. Each state reference
   *     represents a typeahead instance as the reference is typically mutated
   *     in-place.
   */
  function initState() {
      var state = {
          bufferClearTimeout: 0,
          currentFirstChar: '',
          sortedIndexCursor: 0,
          typeaheadBuffer: '',
      };
      return state;
  }
  /**
   * Initializes typeahead state by indexing the current list items by primary
   * text into the sortedIndexByFirstChar data structure.
   *
   * @param listItemCount numer of items in the list
   * @param getPrimaryTextByItemIndex function that returns the primary text at a
   *     given index
   *
   * @return Map that maps the first character of the primary text to the full
   *     list text and it's index
   */
  function initSortedIndex(listItemCount, getPrimaryTextByItemIndex) {
      var sortedIndexByFirstChar = new Map();
      // Aggregate item text to index mapping
      for (var i = 0; i < listItemCount; i++) {
          var primaryText = getPrimaryTextByItemIndex(i).trim();
          if (!primaryText) {
              continue;
          }
          var firstChar = primaryText[0].toLowerCase();
          if (!sortedIndexByFirstChar.has(firstChar)) {
              sortedIndexByFirstChar.set(firstChar, []);
          }
          sortedIndexByFirstChar.get(firstChar).push({ text: primaryText.toLowerCase(), index: i });
      }
      // Sort the mapping
      // TODO(b/157162694): Investigate replacing forEach with Map.values()
      sortedIndexByFirstChar.forEach(function (values) {
          values.sort(function (first, second) {
              return first.index - second.index;
          });
      });
      return sortedIndexByFirstChar;
  }
  /**
   * Given the next desired character from the user, it attempts to find the next
   * list option matching the buffer. Wraps around if at the end of options.
   *
   * @param opts Options and accessors
   *   - nextChar - the next character to match against items
   *   - sortedIndexByFirstChar - output of `initSortedIndex(...)`
   *   - focusedItemIndex - the index of the currently focused item
   *   - focusItemAtIndex - function that focuses a list item at given index
   *   - skipFocus - whether or not to focus the matched item
   *   - isItemAtIndexDisabled - function that determines whether an item at a
   *        given index is disabled
   * @param state The typeahead state instance. See `initState`.
   *
   * @return The index of the matched item, or -1 if no match.
   */
  function matchItem(opts, state) {
      var nextChar = opts.nextChar, focusItemAtIndex = opts.focusItemAtIndex, sortedIndexByFirstChar = opts.sortedIndexByFirstChar, focusedItemIndex = opts.focusedItemIndex, skipFocus = opts.skipFocus, isItemAtIndexDisabled = opts.isItemAtIndexDisabled;
      clearTimeout(state.bufferClearTimeout);
      state.bufferClearTimeout = setTimeout(function () {
          clearBuffer(state);
      }, numbers.TYPEAHEAD_BUFFER_CLEAR_TIMEOUT_MS);
      state.typeaheadBuffer = state.typeaheadBuffer + nextChar;
      var index;
      if (state.typeaheadBuffer.length === 1) {
          index = matchFirstChar(sortedIndexByFirstChar, focusedItemIndex, isItemAtIndexDisabled, state);
      }
      else {
          index = matchAllChars(sortedIndexByFirstChar, isItemAtIndexDisabled, state);
      }
      if (index !== -1 && !skipFocus) {
          focusItemAtIndex(index);
      }
      return index;
  }
  /**
   * Matches the user's single input character in the buffer to the
   * next option that begins with such character. Wraps around if at
   * end of options. Returns -1 if no match is found.
   */
  function matchFirstChar(sortedIndexByFirstChar, focusedItemIndex, isItemAtIndexDisabled, state) {
      var firstChar = state.typeaheadBuffer[0];
      var itemsMatchingFirstChar = sortedIndexByFirstChar.get(firstChar);
      if (!itemsMatchingFirstChar) {
          return -1;
      }
      // Has the same firstChar been recently matched?
      // Also, did starting index remain the same between key presses?
      // If both hold true, simply increment index.
      if (firstChar === state.currentFirstChar &&
          itemsMatchingFirstChar[state.sortedIndexCursor].index ===
              focusedItemIndex) {
          state.sortedIndexCursor =
              (state.sortedIndexCursor + 1) % itemsMatchingFirstChar.length;
          var newIndex = itemsMatchingFirstChar[state.sortedIndexCursor].index;
          if (!isItemAtIndexDisabled(newIndex)) {
              return newIndex;
          }
      }
      // If we're here, it means one of the following happened:
      // - either firstChar or startingIndex has changed, invalidating the
      // cursor.
      // - The next item of typeahead is disabled, so we have to look further.
      state.currentFirstChar = firstChar;
      var newCursorPosition = -1;
      var cursorPosition;
      // Find the first non-disabled item as a fallback.
      for (cursorPosition = 0; cursorPosition < itemsMatchingFirstChar.length; cursorPosition++) {
          if (!isItemAtIndexDisabled(itemsMatchingFirstChar[cursorPosition].index)) {
              newCursorPosition = cursorPosition;
              break;
          }
      }
      // Advance cursor to first item matching the firstChar that is positioned
      // after starting item. Cursor is unchanged from fallback if there's no
      // such item.
      for (; cursorPosition < itemsMatchingFirstChar.length; cursorPosition++) {
          if (itemsMatchingFirstChar[cursorPosition].index > focusedItemIndex &&
              !isItemAtIndexDisabled(itemsMatchingFirstChar[cursorPosition].index)) {
              newCursorPosition = cursorPosition;
              break;
          }
      }
      if (newCursorPosition !== -1) {
          state.sortedIndexCursor = newCursorPosition;
          return itemsMatchingFirstChar[state.sortedIndexCursor].index;
      }
      return -1;
  }
  /**
   * Attempts to find the next item that matches all of the typeahead buffer.
   * Wraps around if at end of options. Returns -1 if no match is found.
   */
  function matchAllChars(sortedIndexByFirstChar, isItemAtIndexDisabled, state) {
      var firstChar = state.typeaheadBuffer[0];
      var itemsMatchingFirstChar = sortedIndexByFirstChar.get(firstChar);
      if (!itemsMatchingFirstChar) {
          return -1;
      }
      // Do nothing if text already matches
      var startingItem = itemsMatchingFirstChar[state.sortedIndexCursor];
      if (startingItem.text.lastIndexOf(state.typeaheadBuffer, 0) === 0 &&
          !isItemAtIndexDisabled(startingItem.index)) {
          return startingItem.index;
      }
      // Find next item that matches completely; if no match, we'll eventually
      // loop around to same position
      var cursorPosition = (state.sortedIndexCursor + 1) % itemsMatchingFirstChar.length;
      var nextCursorPosition = -1;
      while (cursorPosition !== state.sortedIndexCursor) {
          var currentItem = itemsMatchingFirstChar[cursorPosition];
          var matches = currentItem.text.lastIndexOf(state.typeaheadBuffer, 0) === 0;
          var isEnabled = !isItemAtIndexDisabled(currentItem.index);
          if (matches && isEnabled) {
              nextCursorPosition = cursorPosition;
              break;
          }
          cursorPosition = (cursorPosition + 1) % itemsMatchingFirstChar.length;
      }
      if (nextCursorPosition !== -1) {
          state.sortedIndexCursor = nextCursorPosition;
          return itemsMatchingFirstChar[state.sortedIndexCursor].index;
      }
      return -1;
  }
  /**
   * Whether or not the given typeahead instaance state is currently typing.
   *
   * @param state The typeahead state instance. See `initState`.
   */
  function isTypingInProgress(state) {
      return state.typeaheadBuffer.length > 0;
  }
  /**
   * Clears the typeahaed buffer so that it resets item matching to the first
   * character.
   *
   * @param state The typeahead state instance. See `initState`.
   */
  function clearBuffer(state) {
      state.typeaheadBuffer = '';
  }
  /**
   * Given a keydown event, it calculates whether or not to automatically focus a
   * list item depending on what was typed mimicing the typeahead functionality of
   * a standard <select> element that is open.
   *
   * @param opts Options and accessors
   *   - event - the KeyboardEvent to handle and parse
   *   - sortedIndexByFirstChar - output of `initSortedIndex(...)`
   *   - focusedItemIndex - the index of the currently focused item
   *   - focusItemAtIndex - function that focuses a list item at given index
   *   - isItemAtFocusedIndexDisabled - whether or not the currently focused item
   *      is disabled
   *   - isTargetListItem - whether or not the event target is a list item
   * @param state The typeahead state instance. See `initState`.
   *
   * @returns index of the item matched by the keydown. -1 if not matched.
   */
  function handleKeydown(opts, state) {
      var event = opts.event, isTargetListItem = opts.isTargetListItem, focusedItemIndex = opts.focusedItemIndex, focusItemAtIndex = opts.focusItemAtIndex, sortedIndexByFirstChar = opts.sortedIndexByFirstChar, isItemAtIndexDisabled = opts.isItemAtIndexDisabled;
      var isArrowLeft = normalizeKey(event) === 'ArrowLeft';
      var isArrowUp = normalizeKey(event) === 'ArrowUp';
      var isArrowRight = normalizeKey(event) === 'ArrowRight';
      var isArrowDown = normalizeKey(event) === 'ArrowDown';
      var isHome = normalizeKey(event) === 'Home';
      var isEnd = normalizeKey(event) === 'End';
      var isEnter = normalizeKey(event) === 'Enter';
      var isSpace = normalizeKey(event) === 'Spacebar';
      if (isArrowLeft || isArrowUp || isArrowRight || isArrowDown || isHome ||
          isEnd || isEnter) {
          return -1;
      }
      var isCharacterKey = !isSpace && event.key.length === 1;
      if (isCharacterKey) {
          preventDefaultEvent(event);
          var matchItemOpts = {
              focusItemAtIndex: focusItemAtIndex,
              focusedItemIndex: focusedItemIndex,
              nextChar: event.key.toLowerCase(),
              sortedIndexByFirstChar: sortedIndexByFirstChar,
              skipFocus: false,
              isItemAtIndexDisabled: isItemAtIndexDisabled,
          };
          return matchItem(matchItemOpts, state);
      }
      if (!isSpace) {
          return -1;
      }
      if (isTargetListItem) {
          preventDefaultEvent(event);
      }
      var typeaheadOnListItem = isTargetListItem && isTypingInProgress(state);
      if (typeaheadOnListItem) {
          var matchItemOpts = {
              focusItemAtIndex: focusItemAtIndex,
              focusedItemIndex: focusedItemIndex,
              nextChar: ' ',
              sortedIndexByFirstChar: sortedIndexByFirstChar,
              skipFocus: false,
              isItemAtIndexDisabled: isItemAtIndexDisabled,
          };
          // space participates in typeahead matching if in rapid typing mode
          return matchItem(matchItemOpts, state);
      }
      return -1;
  }
  
  /**
   * @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.
   */
  function isNumberArray(selectedIndex) {
      return selectedIndex instanceof Array;
  }
  var MDCListFoundation = /** @class */ (function (_super) {
      __extends(MDCListFoundation, _super);
      function MDCListFoundation(adapter) {
          var _this = _super.call(this, __assign(__assign({}, MDCListFoundation.defaultAdapter), adapter)) || this;
          _this.wrapFocus_ = false;
          _this.isVertical_ = true;
          _this.isSingleSelectionList_ = false;
          _this.selectedIndex_ = numbers.UNSET_INDEX;
          _this.focusedItemIndex = numbers.UNSET_INDEX;
          _this.useActivatedClass_ = false;
          _this.ariaCurrentAttrValue_ = null;
          _this.isCheckboxList_ = false;
          _this.isRadioList_ = false;
          _this.hasTypeahead = false;
          // Transiently holds current typeahead prefix from user.
          _this.typeaheadState = initState();
          _this.sortedIndexByFirstChar = new Map();
          return _this;
      }
      Object.defineProperty(MDCListFoundation, "strings", {
          get: function () {
              return strings;
          },
          enumerable: true,
          configurable: true
      });
      Object.defineProperty(MDCListFoundation, "cssClasses", {
          get: function () {
              return cssClasses;
          },
          enumerable: true,
          configurable: true
      });
      Object.defineProperty(MDCListFoundation, "numbers", {
          get: function () {
              return numbers;
          },
          enumerable: true,
          configurable: true
      });
      Object.defineProperty(MDCListFoundation, "defaultAdapter", {
          get: function () {
              return {
                  addClassForElementIndex: function () { return undefined; },
                  focusItemAtIndex: function () { return undefined; },
                  getAttributeForElementIndex: function () { return null; },
                  getFocusedElementIndex: function () { return 0; },
                  getListItemCount: function () { return 0; },
                  hasCheckboxAtIndex: function () { return false; },
                  hasRadioAtIndex: function () { return false; },
                  isCheckboxCheckedAtIndex: function () { return false; },
                  isFocusInsideList: function () { return false; },
                  isRootFocused: function () { return false; },
                  listItemAtIndexHasClass: function () { return false; },
                  notifyAction: function () { return undefined; },
                  removeClassForElementIndex: function () { return undefined; },
                  setAttributeForElementIndex: function () { return undefined; },
                  setCheckedCheckboxOrRadioAtIndex: function () { return undefined; },
                  setTabIndexForListItemChildren: function () { return undefined; },
                  getPrimaryTextAtIndex: function () { return ''; },
              };
          },
          enumerable: true,
          configurable: true
      });
      MDCListFoundation.prototype.layout = function () {
          if (this.adapter.getListItemCount() === 0) {
              return;
          }
          if (this.adapter.hasCheckboxAtIndex(0)) {
              this.isCheckboxList_ = true;
          }
          else if (this.adapter.hasRadioAtIndex(0)) {
              this.isRadioList_ = true;
          }
          if (this.hasTypeahead) {
              this.sortedIndexByFirstChar = this.typeaheadInitSortedIndex();
          }
      };
      /**
       * Sets the private wrapFocus_ variable.
       */
      MDCListFoundation.prototype.setWrapFocus = function (value) {
          this.wrapFocus_ = value;
      };
      /**
       * Sets the isVertical_ private variable.
       */
      MDCListFoundation.prototype.setVerticalOrientation = function (value) {
          this.isVertical_ = value;
      };
      /**
       * Sets the isSingleSelectionList_ private variable.
       */
      MDCListFoundation.prototype.setSingleSelection = function (value) {
          this.isSingleSelectionList_ = value;
      };
      /**
       * Sets whether typeahead is enabled on the list.
       * @param hasTypeahead Whether typeahead is enabled.
       */
      MDCListFoundation.prototype.setHasTypeahead = function (hasTypeahead) {
          this.hasTypeahead = hasTypeahead;
          if (hasTypeahead) {
              this.sortedIndexByFirstChar = this.typeaheadInitSortedIndex();
          }
      };
      /**
       * @return Whether typeahead is currently matching a user-specified prefix.
       */
      MDCListFoundation.prototype.isTypeaheadInProgress = function () {
          return this.hasTypeahead &&
              isTypingInProgress(this.typeaheadState);
      };
      /**
       * Sets the useActivatedClass_ private variable.
       */
      MDCListFoundation.prototype.setUseActivatedClass = function (useActivated) {
          this.useActivatedClass_ = useActivated;
      };
      MDCListFoundation.prototype.getSelectedIndex = function () {
          return this.selectedIndex_;
      };
      MDCListFoundation.prototype.setSelectedIndex = function (index) {
          if (!this.isIndexValid_(index)) {
              return;
          }
          if (this.isCheckboxList_) {
              this.setCheckboxAtIndex_(index);
          }
          else if (this.isRadioList_) {
              this.setRadioAtIndex_(index);
          }
          else {
              this.setSingleSelectionAtIndex_(index);
          }
      };
      /**
       * Focus in handler for the list items.
       */
      MDCListFoundation.prototype.handleFocusIn = function (_, listItemIndex) {
          if (listItemIndex >= 0) {
              this.focusedItemIndex = listItemIndex;
              this.adapter.setTabIndexForListItemChildren(listItemIndex, '0');
          }
      };
      /**
       * Focus out handler for the list items.
       */
      MDCListFoundation.prototype.handleFocusOut = function (_, listItemIndex) {
          var _this = this;
          if (listItemIndex >= 0) {
              this.adapter.setTabIndexForListItemChildren(listItemIndex, '-1');
          }
          /**
           * Between Focusout & Focusin some browsers do not have focus on any element. Setting a delay to wait till the focus
           * is moved to next element.
           */
          setTimeout(function () {
              if (!_this.adapter.isFocusInsideList()) {
                  _this.setTabindexToFirstSelectedItem_();
              }
          }, 0);
      };
      /**
       * Key handler for the list.
       */
      MDCListFoundation.prototype.handleKeydown = function (event, isRootListItem, listItemIndex) {
          var _this = this;
          var isArrowLeft = normalizeKey(event) === 'ArrowLeft';
          var isArrowUp = normalizeKey(event) === 'ArrowUp';
          var isArrowRight = normalizeKey(event) === 'ArrowRight';
          var isArrowDown = normalizeKey(event) === 'ArrowDown';
          var isHome = normalizeKey(event) === 'Home';
          var isEnd = normalizeKey(event) === 'End';
          var isEnter = normalizeKey(event) === 'Enter';
          var isSpace = normalizeKey(event) === 'Spacebar';
          if (this.adapter.isRootFocused()) {
              if (isArrowUp || isEnd) {
                  event.preventDefault();
                  this.focusLastElement();
              }
              else if (isArrowDown || isHome) {
                  event.preventDefault();
                  this.focusFirstElement();
              }
              if (this.hasTypeahead) {
                  var handleKeydownOpts = {
                      event: event,
                      focusItemAtIndex: function (index) {
                          _this.focusItemAtIndex(index);
                      },
                      focusedItemIndex: -1,
                      isTargetListItem: isRootListItem,
                      sortedIndexByFirstChar: this.sortedIndexByFirstChar,
                      isItemAtIndexDisabled: function (index) {
                          return _this.adapter.listItemAtIndexHasClass(index, cssClasses.LIST_ITEM_DISABLED_CLASS);
                      },
                  };
                  handleKeydown(handleKeydownOpts, this.typeaheadState);
              }
              return;
          }
          var currentIndex = this.adapter.getFocusedElementIndex();
          if (currentIndex === -1) {
              currentIndex = listItemIndex;
              if (currentIndex < 0) {
                  // If this event doesn't have a mdc-list-item ancestor from the
                  // current list (not from a sublist), return early.
                  return;
              }
          }
          if ((this.isVertical_ && isArrowDown) || (!this.isVertical_ && isArrowRight)) {
              preventDefaultEvent(event);
              this.focusNextElement(currentIndex);
          }
          else if ((this.isVertical_ && isArrowUp) || (!this.isVertical_ && isArrowLeft)) {
              preventDefaultEvent(event);
              this.focusPrevElement(currentIndex);
          }
          else if (isHome) {
              preventDefaultEvent(event);
              this.focusFirstElement();
          }
          else if (isEnd) {
              preventDefaultEvent(event);
              this.focusLastElement();
          }
          else if (isEnter || isSpace) {
              if (isRootListItem) {
                  // Return early if enter key is pressed on anchor element which triggers synthetic MouseEvent event.
                  var target = event.target;
                  if (target && target.tagName === 'A' && isEnter) {
                      return;
                  }
                  preventDefaultEvent(event);
                  if (this.adapter.listItemAtIndexHasClass(currentIndex, cssClasses.LIST_ITEM_DISABLED_CLASS)) {
                      return;
                  }
                  if (!this.isTypeaheadInProgress()) {
                      if (this.isSelectableList_()) {
                          this.setSelectedIndexOnAction_(currentIndex);
                      }
                      this.adapter.notifyAction(currentIndex);
                  }
              }
          }
          if (this.hasTypeahead) {
              var handleKeydownOpts = {
                  event: event,
                  focusItemAtIndex: function (index) {
                      _this.focusItemAtIndex(index);
                  },
                  focusedItemIndex: this.focusedItemIndex,
                  isTargetListItem: isRootListItem,
                  sortedIndexByFirstChar: this.sortedIndexByFirstChar,
                  isItemAtIndexDisabled: function (index) { return _this.adapter.listItemAtIndexHasClass(index, cssClasses.LIST_ITEM_DISABLED_CLASS); },
              };
              handleKeydown(handleKeydownOpts, this.typeaheadState);
          }
      };
      /**
       * Click handler for the list.
       */
      MDCListFoundation.prototype.handleClick = function (index, toggleCheckbox) {
          if (index === numbers.UNSET_INDEX) {
              return;
          }
          this.setTabindexAtIndex_(index);
          this.focusedItemIndex = index;
          if (this.adapter.listItemAtIndexHasClass(index, cssClasses.LIST_ITEM_DISABLED_CLASS)) {
              return;
          }
          if (this.isSelectableList_()) {
              this.setSelectedIndexOnAction_(index, toggleCheckbox);
          }
          this.adapter.notifyAction(index);
      };
      /**
       * Focuses the next element on the list.
       */
      MDCListFoundation.prototype.focusNextElement = function (index) {
          var count = this.adapter.getListItemCount();
          var nextIndex = index + 1;
          if (nextIndex >= count) {
              if (this.wrapFocus_) {
                  nextIndex = 0;
              }
              else {
                  // Return early because last item is already focused.
                  return index;
              }
          }
          this.focusItemAtIndex(nextIndex);
          return nextIndex;
      };
      /**
       * Focuses the previous element on the list.
       */
      MDCListFoundation.prototype.focusPrevElement = function (index) {
          var prevIndex = index - 1;
          if (prevIndex < 0) {
              if (this.wrapFocus_) {
                  prevIndex = this.adapter.getListItemCount() - 1;
              }
              else {
                  // Return early because first item is already focused.
                  return index;
              }
          }
          this.focusItemAtIndex(prevIndex);
          return prevIndex;
      };
      MDCListFoundation.prototype.focusFirstElement = function () {
          this.focusItemAtIndex(0);
          return 0;
      };
      MDCListFoundation.prototype.focusLastElement = function () {
          var lastIndex = this.adapter.getListItemCount() - 1;
          this.focusItemAtIndex(lastIndex);
          return lastIndex;
      };
      /**
       * @param itemIndex Index of the list item
       * @param isEnabled Sets the list item to enabled or disabled.
       */
      MDCListFoundation.prototype.setEnabled = function (itemIndex, isEnabled) {
          if (!this.isIndexValid_(itemIndex)) {
              return;
          }
          if (isEnabled) {
              this.adapter.removeClassForElementIndex(itemIndex, cssClasses.LIST_ITEM_DISABLED_CLASS);
              this.adapter.setAttributeForElementIndex(itemIndex, strings.ARIA_DISABLED, 'false');
          }
          else {
              this.adapter.addClassForElementIndex(itemIndex, cssClasses.LIST_ITEM_DISABLED_CLASS);
              this.adapter.setAttributeForElementIndex(itemIndex, strings.ARIA_DISABLED, 'true');
          }
      };
      MDCListFoundation.prototype.setSingleSelectionAtIndex_ = function (index) {
          if (this.selectedIndex_ === index) {
              return;
          }
          var selectedClassName = cssClasses.LIST_ITEM_SELECTED_CLASS;
          if (this.useActivatedClass_) {
              selectedClassName = cssClasses.LIST_ITEM_ACTIVATED_CLASS;
          }
          if (this.selectedIndex_ !== numbers.UNSET_INDEX) {
              this.adapter.removeClassForElementIndex(this.selectedIndex_, selectedClassName);
          }
          this.adapter.addClassForElementIndex(index, selectedClassName);
          this.setAriaForSingleSelectionAtIndex_(index);
          this.selectedIndex_ = index;
      };
      /**
       * Sets aria attribute for single selection at given index.
       */
      MDCListFoundation.prototype.setAriaForSingleSelectionAtIndex_ = function (index) {
          // Detect the presence of aria-current and get the value only during list initialization when it is in unset state.
          if (this.selectedIndex_ === numbers.UNSET_INDEX) {
              this.ariaCurrentAttrValue_ =
                  this.adapter.getAttributeForElementIndex(index, strings.ARIA_CURRENT);
          }
          var isAriaCurrent = this.ariaCurrentAttrValue_ !== null;
          var ariaAttribute = isAriaCurrent ? strings.ARIA_CURRENT : strings.ARIA_SELECTED;
          if (this.selectedIndex_ !== numbers.UNSET_INDEX) {
              this.adapter.setAttributeForElementIndex(this.selectedIndex_, ariaAttribute, 'false');
          }
          var ariaAttributeValue = isAriaCurrent ? this.ariaCurrentAttrValue_ : 'true';
          this.adapter.setAttributeForElementIndex(index, ariaAttribute, ariaAttributeValue);
      };
      /**
       * Toggles radio at give index. Radio doesn't change the checked state if it is already checked.
       */
      MDCListFoundation.prototype.setRadioAtIndex_ = function (index) {
          this.adapter.setCheckedCheckboxOrRadioAtIndex(index, true);
          if (this.selectedIndex_ !== numbers.UNSET_INDEX) {
              this.adapter.setAttributeForElementIndex(this.selectedIndex_, strings.ARIA_CHECKED, 'false');
          }
          this.adapter.setAttributeForElementIndex(index, strings.ARIA_CHECKED, 'true');
          this.selectedIndex_ = index;
      };
      MDCListFoundation.prototype.setCheckboxAtIndex_ = function (index) {
          for (var i = 0; i < this.adapter.getListItemCount(); i++) {
              var isChecked = false;
              if (index.indexOf(i) >= 0) {
                  isChecked = true;
              }
              this.adapter.setCheckedCheckboxOrRadioAtIndex(i, isChecked);
              this.adapter.setAttributeForElementIndex(i, strings.ARIA_CHECKED, isChecked ? 'true' : 'false');
          }
          this.selectedIndex_ = index;
      };
      MDCListFoundation.prototype.setTabindexAtIndex_ = function (index) {
          if (this.focusedItemIndex === numbers.UNSET_INDEX && index !== 0) {
              // If no list item was selected set first list item's tabindex to -1.
              // Generally, tabindex is set to 0 on first list item of list that has no preselected items.
              this.adapter.setAttributeForElementIndex(0, 'tabindex', '-1');
          }
          else if (this.focusedItemIndex >= 0 && this.focusedItemIndex !== index) {
              this.adapter.setAttributeForElementIndex(this.focusedItemIndex, 'tabindex', '-1');
          }
          this.adapter.setAttributeForElementIndex(index, 'tabindex', '0');
      };
      /**
       * @return Return true if it is single selectin list, checkbox list or radio list.
       */
      MDCListFoundation.prototype.isSelectableList_ = function () {
          return this.isSingleSelectionList_ || this.isCheckboxList_ || this.isRadioList_;
      };
      MDCListFoundation.prototype.setTabindexToFirstSelectedItem_ = function () {
          var targetIndex = 0;
          if (this.isSelectableList_()) {
              if (typeof this.selectedIndex_ === 'number' && this.selectedIndex_ !== numbers.UNSET_INDEX) {
                  targetIndex = this.selectedIndex_;
              }
              else if (isNumberArray(this.selectedIndex_) && this.selectedIndex_.length > 0) {
                  targetIndex = this.selectedIndex_.reduce(function (currentIndex, minIndex) { return Math.min(currentIndex, minIndex); });
              }
          }
          this.setTabindexAtIndex_(targetIndex);
      };
      MDCListFoundation.prototype.isIndexValid_ = function (index) {
          var _this = this;
          if (index instanceof Array) {
              if (!this.isCheckboxList_) {
                  throw new Error('MDCListFoundation: Array of index is only supported for checkbox based list');
              }
              if (index.length === 0) {
                  return true;
              }
              else {
                  return index.some(function (i) { return _this.isIndexInRange_(i); });
              }
          }
          else if (typeof index === 'number') {
              if (this.isCheckboxList_) {
                  throw new Error('MDCListFoundation: Expected array of index for checkbox based list but got number: ' + index);
              }
              return this.isIndexInRange_(index);
          }
          else {
              return false;
          }
      };
      MDCListFoundation.prototype.isIndexInRange_ = function (index) {
          var listSize = this.adapter.getListItemCount();
          return index >= 0 && index < listSize;
      };
      /**
       * Sets selected index on user action, toggles checkbox / radio based on toggleCheckbox value.
       * User interaction should not toggle list item(s) when disabled.
       */
      MDCListFoundation.prototype.setSelectedIndexOnAction_ = function (index, toggleCheckbox) {
          if (toggleCheckbox === void 0) { toggleCheckbox = true; }
          if (this.isCheckboxList_) {
              this.toggleCheckboxAtIndex_(index, toggleCheckbox);
          }
          else {
              this.setSelectedIndex(index);
          }
      };
      MDCListFoundation.prototype.toggleCheckboxAtIndex_ = function (index, toggleCheckbox) {
          var isChecked = this.adapter.isCheckboxCheckedAtIndex(index);
          if (toggleCheckbox) {
              isChecked = !isChecked;
              this.adapter.setCheckedCheckboxOrRadioAtIndex(index, isChecked);
          }
          this.adapter.setAttributeForElementIndex(index, strings.ARIA_CHECKED, isChecked ? 'true' : 'false');
          // If none of the checkbox items are selected and selectedIndex is not initialized then provide a default value.
          var selectedIndexes = this.selectedIndex_ === numbers.UNSET_INDEX ? [] : this.selectedIndex_.slice();
          if (isChecked) {
              selectedIndexes.push(index);
          }
          else {
              selectedIndexes = selectedIndexes.filter(function (i) { return i !== index; });
          }
          this.selectedIndex_ = selectedIndexes;
      };
      MDCListFoundation.prototype.focusItemAtIndex = function (index) {
          this.setTabindexAtIndex_(index);
          this.adapter.focusItemAtIndex(index);
          this.focusedItemIndex = index;
      };
      /**
       * Given the next desired character from the user, adds it to the typeahead
       * buffer. Then, attempts to find the next option matching the buffer. Wraps
       * around if at the end of options.
       *
       * @param nextChar The next character to add to the prefix buffer.
       * @param startingIndex The index from which to start matching. Only relevant
       *     when starting a new match sequence. To start a new match sequence,
       *     clear the buffer using `clearTypeaheadBuffer`, or wait for the buffer
       *     to clear after a set interval defined in list foundation. Defaults to
       *     the currently focused index.
       * @return The index of the matched item, or -1 if no match.
       */
      MDCListFoundation.prototype.typeaheadMatchItem = function (nextChar, startingIndex, skipFocus) {
          var _this = this;
          if (skipFocus === void 0) { skipFocus = false; }
          var opts = {
              focusItemAtIndex: function (index) {
                  _this.focusItemAtIndex(index);
              },
              focusedItemIndex: startingIndex ? startingIndex : this.focusedItemIndex,
              nextChar: nextChar,
              sortedIndexByFirstChar: this.sortedIndexByFirstChar,
              skipFocus: skipFocus,
              isItemAtIndexDisabled: function (index) { return _this.adapter.listItemAtIndexHasClass(index, cssClasses.LIST_ITEM_DISABLED_CLASS); }
          };
          return matchItem(opts, this.typeaheadState);
      };
      /**
       * Initializes the MDCListTextAndIndex data structure by indexing the current
       * list items by primary text.
       *
       * @return The primary texts of all the list items sorted by first character.
       */
      MDCListFoundation.prototype.typeaheadInitSortedIndex = function () {
          return initSortedIndex(this.adapter.getListItemCount(), this.adapter.getPrimaryTextAtIndex);
      };
      /**
       * Clears the typeahead buffer.
       */
      MDCListFoundation.prototype.clearTypeaheadBuffer = function () {
          clearBuffer(this.typeaheadState);
      };
      return MDCListFoundation;
  }(MDCFoundation));
  
  /**
   * @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.
   */
  var MDCList = /** @class */ (function (_super) {
      __extends(MDCList, _super);
      function MDCList() {
          return _super !== null && _super.apply(this, arguments) || this;
      }
      Object.defineProperty(MDCList.prototype, "vertical", {
          set: function (value) {
              this.foundation.setVerticalOrientation(value);
          },
          enumerable: true,
          configurable: true
      });
      Object.defineProperty(MDCList.prototype, "listElements", {
          get: function () {
              return [].slice.call(this.root.querySelectorAll("." + cssClasses.LIST_ITEM_CLASS));
          },
          enumerable: true,
          configurable: true
      });
      Object.defineProperty(MDCList.prototype, "wrapFocus", {
          set: function (value) {
              this.foundation.setWrapFocus(value);
          },
          enumerable: true,
          configurable: true
      });
      Object.defineProperty(MDCList.prototype, "typeaheadInProgress", {
          /**
           * @return Whether typeahead is currently matching a user-specified prefix.
           */
          get: function () {
              return this.foundation.isTypeaheadInProgress();
          },
          enumerable: true,
          configurable: true
      });
      Object.defineProperty(MDCList.prototype, "hasTypeahead", {
          /**
           * Sets whether typeahead functionality is enabled on the list.
           * @param hasTypeahead Whether typeahead is enabled.
           */
          set: function (hasTypeahead) {
              this.foundation.setHasTypeahead(hasTypeahead);
          },
          enumerable: true,
          configurable: true
      });
      Object.defineProperty(MDCList.prototype, "singleSelection", {
          set: function (isSingleSelectionList) {
              this.foundation.setSingleSelection(isSingleSelectionList);
          },
          enumerable: true,
          configurable: true
      });
      Object.defineProperty(MDCList.prototype, "selectedIndex", {
          get: function () {
              return this.foundation.getSelectedIndex();
          },
          set: function (index) {
              this.foundation.setSelectedIndex(index);
          },
          enumerable: true,
          configurable: true
      });
      MDCList.attachTo = function (root) {
          return new MDCList(root);
      };
      MDCList.prototype.initialSyncWithDOM = function () {
          this.handleClick_ = this.handleClickEvent_.bind(this);
          this.handleKeydown_ = this.handleKeydownEvent_.bind(this);
          this.focusInEventListener_ = this.handleFocusInEvent_.bind(this);
          this.focusOutEventListener_ = this.handleFocusOutEvent_.bind(this);
          this.listen('keydown', this.handleKeydown_);
          this.listen('click', this.handleClick_);
          this.listen('focusin', this.focusInEventListener_);
          this.listen('focusout', this.focusOutEventListener_);
          this.layout();
          this.initializeListType();
      };
      MDCList.prototype.destroy = function () {
          this.unlisten('keydown', this.handleKeydown_);
          this.unlisten('click', this.handleClick_);
          this.unlisten('focusin', this.focusInEventListener_);
          this.unlisten('focusout', this.focusOutEventListener_);
      };
      MDCList.prototype.layout = function () {
          var direction = this.root.getAttribute(strings.ARIA_ORIENTATION);
          this.vertical = direction !== strings.ARIA_ORIENTATION_HORIZONTAL;
          // List items need to have at least tabindex=-1 to be focusable.
          [].slice.call(this.root.querySelectorAll('.mdc-list-item:not([tabindex])'))
              .forEach(function (el) {
              el.setAttribute('tabindex', '-1');
          });
          // Child button/a elements are not tabbable until the list item is focused.
          [].slice.call(this.root.querySelectorAll(strings.FOCUSABLE_CHILD_ELEMENTS))
              .forEach(function (el) { return el.setAttribute('tabindex', '-1'); });
          this.foundation.layout();
      };
      /**
       * Extracts the primary text from a list item.
       * @param item The list item element.
       * @return The primary text in the element.
       */
      MDCList.prototype.getPrimaryText = function (item) {
          var primaryText = item.querySelector("." + cssClasses.LIST_ITEM_PRIMARY_TEXT_CLASS);
          if (primaryText) {
              return primaryText.textContent || '';
          }
          var singleLineText = item.querySelector("." + cssClasses.LIST_ITEM_TEXT_CLASS);
          return (singleLineText && singleLineText.textContent) || '';
      };
      /**
       * Initialize selectedIndex value based on pre-selected checkbox list items, single selection or radio.
       */
      MDCList.prototype.initializeListType = function () {
          var _this = this;
          var checkboxListItems = this.root.querySelectorAll(strings.ARIA_ROLE_CHECKBOX_SELECTOR);
          var singleSelectedListItem = this.root.querySelector("\n      ." + cssClasses.LIST_ITEM_ACTIVATED_CLASS + ",\n      ." + cssClasses.LIST_ITEM_SELECTED_CLASS + "\n    ");
          var radioSelectedListItem = this.root.querySelector(strings.ARIA_CHECKED_RADIO_SELECTOR);
          if (checkboxListItems.length) {
              var preselectedItems = this.root.querySelectorAll(strings.ARIA_CHECKED_CHECKBOX_SELECTOR);
              this.selectedIndex =
                  [].map.call(preselectedItems, function (listItem) { return _this.listElements.indexOf(listItem); });
          }
          else if (singleSelectedListItem) {
              if (singleSelectedListItem.classList.contains(cssClasses.LIST_ITEM_ACTIVATED_CLASS)) {
                  this.foundation.setUseActivatedClass(true);
              }
              this.singleSelection = true;
              this.selectedIndex = this.listElements.indexOf(singleSelectedListItem);
          }
          else if (radioSelectedListItem) {
              this.selectedIndex = this.listElements.indexOf(radioSelectedListItem);
          }
      };
      /**
       * Updates the list item at itemIndex to the desired isEnabled state.
       * @param itemIndex Index of the list item
       * @param isEnabled Sets the list item to enabled or disabled.
       */
      MDCList.prototype.setEnabled = function (itemIndex, isEnabled) {
          this.foundation.setEnabled(itemIndex, isEnabled);
      };
      /**
       * Given the next desired character from the user, adds it to the typeahead
       * buffer. Then, attempts to find the next option matching the buffer. Wraps
       * around if at the end of options.
       *
       * @param nextChar The next character to add to the prefix buffer.
       * @param startingIndex The index from which to start matching. Defaults to
       *     the currently focused index.
       * @return The index of the matched item.
       */
      MDCList.prototype.typeaheadMatchItem = function (nextChar, startingIndex) {
          return this.foundation.typeaheadMatchItem(nextChar, startingIndex, /** skipFocus */ true);
      };
      MDCList.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.
          var adapter = {
              addClassForElementIndex: function (index, className) {
                  var element = _this.listElements[index];
                  if (element) {
                      element.classList.add(className);
                  }
              },
              focusItemAtIndex: function (index) {
                  var element = _this.listElements[index];
                  if (element) {
                      element.focus();
                  }
              },
              getAttributeForElementIndex: function (index, attr) {
                  return _this.listElements[index].getAttribute(attr);
              },
              getFocusedElementIndex: function () {
                  return _this.listElements.indexOf(document.activeElement);
              },
              getListItemCount: function () { return _this.listElements.length; },
              getPrimaryTextAtIndex: function (index) {
                  return _this.getPrimaryText(_this.listElements[index]);
              },
              hasCheckboxAtIndex: function (index) {
                  var listItem = _this.listElements[index];
                  return !!listItem.querySelector(strings.CHECKBOX_SELECTOR);
              },
              hasRadioAtIndex: function (index) {
                  var listItem = _this.listElements[index];
                  return !!listItem.querySelector(strings.RADIO_SELECTOR);
              },
              isCheckboxCheckedAtIndex: function (index) {
                  var listItem = _this.listElements[index];
                  var toggleEl = listItem.querySelector(strings.CHECKBOX_SELECTOR);
                  return toggleEl.checked;
              },
              isFocusInsideList: function () {
                  return _this.root.contains(document.activeElement);
              },
              isRootFocused: function () { return document.activeElement === _this.root; },
              listItemAtIndexHasClass: function (index, className) {
                  return _this.listElements[index].classList.contains(className);
              },
              notifyAction: function (index) {
                  _this.emit(strings.ACTION_EVENT, { index: index }, /** shouldBubble */ true);
              },
              removeClassForElementIndex: function (index, className) {
                  var element = _this.listElements[index];
                  if (element) {
                      element.classList.remove(className);
                  }
              },
              setAttributeForElementIndex: function (index, attr, value) {
                  var element = _this.listElements[index];
                  if (element) {
                      element.setAttribute(attr, value);
                  }
              },
              setCheckedCheckboxOrRadioAtIndex: function (index, isChecked) {
                  var listItem = _this.listElements[index];
                  var toggleEl = listItem.querySelector(strings.CHECKBOX_RADIO_SELECTOR);
                  toggleEl.checked = isChecked;
                  var event = document.createEvent('Event');
                  event.initEvent('change', true, true);
                  toggleEl.dispatchEvent(event);
              },
              setTabIndexForListItemChildren: function (listItemIndex, tabIndexValue) {
                  var element = _this.listElements[listItemIndex];
                  var listItemChildren = [].slice.call(element.querySelectorAll(strings.CHILD_ELEMENTS_TO_TOGGLE_TABINDEX));
                  listItemChildren.forEach(function (el) { return el.setAttribute('tabindex', tabIndexValue); });
              },
          };
          return new MDCListFoundation(adapter);
      };
      /**
       * Used to figure out which list item this event is targetting. Or returns -1 if
       * there is no list item
       */
      MDCList.prototype.getListItemIndex_ = function (evt) {
          var eventTarget = evt.target;
          var nearestParent = closest(eventTarget, "." + cssClasses.LIST_ITEM_CLASS + ", ." + cssClasses.ROOT);
          // Get the index of the element if it is a list item.
          if (nearestParent && matches(nearestParent, "." + cssClasses.LIST_ITEM_CLASS)) {
              return this.listElements.indexOf(nearestParent);
          }
          return -1;
      };
      /**
       * Used to figure out which element was clicked before sending the event to the foundation.
       */
      MDCList.prototype.handleFocusInEvent_ = function (evt) {
          var index = this.getListItemIndex_(evt);
          this.foundation.handleFocusIn(evt, index);
      };
      /**
       * Used to figure out which element was clicked before sending the event to the foundation.
       */
      MDCList.prototype.handleFocusOutEvent_ = function (evt) {
          var index = this.getListItemIndex_(evt);
          this.foundation.handleFocusOut(evt, index);
      };
      /**
       * Used to figure out which element was focused when keydown event occurred before sending the event to the
       * foundation.
       */
      MDCList.prototype.handleKeydownEvent_ = function (evt) {
          var index = this.getListItemIndex_(evt);
          var target = evt.target;
          this.foundation.handleKeydown(evt, target.classList.contains(cssClasses.LIST_ITEM_CLASS), index);
      };
      /**
       * Used to figure out which element was clicked before sending the event to the foundation.
       */
      MDCList.prototype.handleClickEvent_ = function (evt) {
          var index = this.getListItemIndex_(evt);
          var target = evt.target;
          // Toggle the checkbox only if it's not the target of the event, or the checkbox will have 2 change events.
          var toggleCheckbox = !matches(target, strings.CHECKBOX_RADIO_SELECTOR);
          this.foundation.handleClick(index, toggleCheckbox);
      };
      return MDCList;
  }(MDCComponent));
  
  export { MDCList, MDCListFoundation, cssClasses, numbers, strings };
  