mdc.dom.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620
  1. /**
  2. * @license
  3. * Copyright Google LLC All Rights Reserved.
  4. *
  5. * Use of this source code is governed by an MIT-style license that can be
  6. * found in the LICENSE file at https://github.com/material-components/material-components-web/blob/master/LICENSE
  7. */
  8. (function webpackUniversalModuleDefinition(root, factory) {
  9. if(typeof exports === 'object' && typeof module === 'object')
  10. module.exports = factory();
  11. else if(typeof define === 'function' && define.amd)
  12. define("@material/dom", [], factory);
  13. else if(typeof exports === 'object')
  14. exports["dom"] = factory();
  15. else
  16. root["mdc"] = root["mdc"] || {}, root["mdc"]["dom"] = factory();
  17. })(this, function() {
  18. return /******/ (function(modules) { // webpackBootstrap
  19. /******/ // The module cache
  20. /******/ var installedModules = {};
  21. /******/
  22. /******/ // The require function
  23. /******/ function __webpack_require__(moduleId) {
  24. /******/
  25. /******/ // Check if module is in cache
  26. /******/ if(installedModules[moduleId]) {
  27. /******/ return installedModules[moduleId].exports;
  28. /******/ }
  29. /******/ // Create a new module (and put it into the cache)
  30. /******/ var module = installedModules[moduleId] = {
  31. /******/ i: moduleId,
  32. /******/ l: false,
  33. /******/ exports: {}
  34. /******/ };
  35. /******/
  36. /******/ // Execute the module function
  37. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  38. /******/
  39. /******/ // Flag the module as loaded
  40. /******/ module.l = true;
  41. /******/
  42. /******/ // Return the exports of the module
  43. /******/ return module.exports;
  44. /******/ }
  45. /******/
  46. /******/
  47. /******/ // expose the modules object (__webpack_modules__)
  48. /******/ __webpack_require__.m = modules;
  49. /******/
  50. /******/ // expose the module cache
  51. /******/ __webpack_require__.c = installedModules;
  52. /******/
  53. /******/ // define getter function for harmony exports
  54. /******/ __webpack_require__.d = function(exports, name, getter) {
  55. /******/ if(!__webpack_require__.o(exports, name)) {
  56. /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
  57. /******/ }
  58. /******/ };
  59. /******/
  60. /******/ // define __esModule on exports
  61. /******/ __webpack_require__.r = function(exports) {
  62. /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
  63. /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
  64. /******/ }
  65. /******/ Object.defineProperty(exports, '__esModule', { value: true });
  66. /******/ };
  67. /******/
  68. /******/ // create a fake namespace object
  69. /******/ // mode & 1: value is a module id, require it
  70. /******/ // mode & 2: merge all properties of value into the ns
  71. /******/ // mode & 4: return value when already ns object
  72. /******/ // mode & 8|1: behave like require
  73. /******/ __webpack_require__.t = function(value, mode) {
  74. /******/ if(mode & 1) value = __webpack_require__(value);
  75. /******/ if(mode & 8) return value;
  76. /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
  77. /******/ var ns = Object.create(null);
  78. /******/ __webpack_require__.r(ns);
  79. /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
  80. /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
  81. /******/ return ns;
  82. /******/ };
  83. /******/
  84. /******/ // getDefaultExport function for compatibility with non-harmony modules
  85. /******/ __webpack_require__.n = function(module) {
  86. /******/ var getter = module && module.__esModule ?
  87. /******/ function getDefault() { return module['default']; } :
  88. /******/ function getModuleExports() { return module; };
  89. /******/ __webpack_require__.d(getter, 'a', getter);
  90. /******/ return getter;
  91. /******/ };
  92. /******/
  93. /******/ // Object.prototype.hasOwnProperty.call
  94. /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  95. /******/
  96. /******/ // __webpack_public_path__
  97. /******/ __webpack_require__.p = "";
  98. /******/
  99. /******/
  100. /******/ // Load entry module and return exports
  101. /******/ return __webpack_require__(__webpack_require__.s = "./packages/mdc-dom/index.ts");
  102. /******/ })
  103. /************************************************************************/
  104. /******/ ({
  105. /***/ "./packages/mdc-dom/events.ts":
  106. /*!************************************!*\
  107. !*** ./packages/mdc-dom/events.ts ***!
  108. \************************************/
  109. /*! no static exports found */
  110. /***/ (function(module, exports, __webpack_require__) {
  111. "use strict";
  112. /**
  113. * @license
  114. * Copyright 2019 Google Inc.
  115. *
  116. * Permission is hereby granted, free of charge, to any person obtaining a copy
  117. * of this software and associated documentation files (the "Software"), to deal
  118. * in the Software without restriction, including without limitation the rights
  119. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  120. * copies of the Software, and to permit persons to whom the Software is
  121. * furnished to do so, subject to the following conditions:
  122. *
  123. * The above copyright notice and this permission notice shall be included in
  124. * all copies or substantial portions of the Software.
  125. *
  126. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  127. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  128. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  129. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  130. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  131. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  132. * THE SOFTWARE.
  133. */
  134. Object.defineProperty(exports, "__esModule", { value: true });
  135. exports.applyPassive = void 0;
  136. /**
  137. * Determine whether the current browser supports passive event listeners, and
  138. * if so, use them.
  139. */
  140. function applyPassive(globalObj) {
  141. if (globalObj === void 0) {
  142. globalObj = window;
  143. }
  144. return supportsPassiveOption(globalObj) ? { passive: true } : false;
  145. }
  146. exports.applyPassive = applyPassive;
  147. function supportsPassiveOption(globalObj) {
  148. if (globalObj === void 0) {
  149. globalObj = window;
  150. }
  151. // See
  152. // https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener
  153. var passiveSupported = false;
  154. try {
  155. var options = {
  156. // This function will be called when the browser
  157. // attempts to access the passive property.
  158. get passive() {
  159. passiveSupported = true;
  160. return false;
  161. }
  162. };
  163. var handler = function handler() {};
  164. globalObj.document.addEventListener('test', handler, options);
  165. globalObj.document.removeEventListener('test', handler, options);
  166. } catch (err) {
  167. passiveSupported = false;
  168. }
  169. return passiveSupported;
  170. }
  171. /***/ }),
  172. /***/ "./packages/mdc-dom/focus-trap.ts":
  173. /*!****************************************!*\
  174. !*** ./packages/mdc-dom/focus-trap.ts ***!
  175. \****************************************/
  176. /*! no static exports found */
  177. /***/ (function(module, exports, __webpack_require__) {
  178. "use strict";
  179. /**
  180. * @license
  181. * Copyright 2020 Google Inc.
  182. *
  183. * Permission is hereby granted, free of charge, to any person obtaining a copy
  184. * of this software and associated documentation files (the "Software"), to deal
  185. * in the Software without restriction, including without limitation the rights
  186. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  187. * copies of the Software, and to permit persons to whom the Software is
  188. * furnished to do so, subject to the following conditions:
  189. *
  190. * The above copyright notice and this permission notice shall be included in
  191. * all copies or substantial portions of the Software.
  192. *
  193. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  194. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  195. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  196. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  197. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  198. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  199. * THE SOFTWARE.
  200. */
  201. Object.defineProperty(exports, "__esModule", { value: true });
  202. exports.FocusTrap = void 0;
  203. var FOCUS_SENTINEL_CLASS = 'mdc-dom-focus-sentinel';
  204. /**
  205. * Utility to trap focus in a given root element, e.g. for modal components such
  206. * as dialogs. The root should have at least one focusable child element,
  207. * for setting initial focus when trapping focus.
  208. * Also tracks the previously focused element, and restores focus to that
  209. * element when releasing focus.
  210. */
  211. var FocusTrap = /** @class */function () {
  212. function FocusTrap(root, options) {
  213. if (options === void 0) {
  214. options = {};
  215. }
  216. this.root = root;
  217. this.options = options;
  218. // Previously focused element before trapping focus.
  219. this.elFocusedBeforeTrapFocus = null;
  220. }
  221. /**
  222. * Traps focus in `root`. Also focuses on either `initialFocusEl` if set;
  223. * otherwises sets initial focus to the first focusable child element.
  224. */
  225. FocusTrap.prototype.trapFocus = function () {
  226. var focusableEls = this.getFocusableElements(this.root);
  227. if (focusableEls.length === 0) {
  228. throw new Error('FocusTrap: Element must have at least one focusable child.');
  229. }
  230. this.elFocusedBeforeTrapFocus = document.activeElement instanceof HTMLElement ? document.activeElement : null;
  231. this.wrapTabFocus(this.root);
  232. if (!this.options.skipInitialFocus) {
  233. this.focusInitialElement(focusableEls, this.options.initialFocusEl);
  234. }
  235. };
  236. /**
  237. * Releases focus from `root`. Also restores focus to the previously focused
  238. * element.
  239. */
  240. FocusTrap.prototype.releaseFocus = function () {
  241. Array.from(this.root.querySelectorAll("." + FOCUS_SENTINEL_CLASS)).forEach(function (sentinelEl) {
  242. sentinelEl.parentElement.removeChild(sentinelEl);
  243. });
  244. if (!this.options.skipRestoreFocus && this.elFocusedBeforeTrapFocus) {
  245. this.elFocusedBeforeTrapFocus.focus();
  246. }
  247. };
  248. /**
  249. * Wraps tab focus within `el` by adding two hidden sentinel divs which are
  250. * used to mark the beginning and the end of the tabbable region. When
  251. * focused, these sentinel elements redirect focus to the first/last
  252. * children elements of the tabbable region, ensuring that focus is trapped
  253. * within that region.
  254. */
  255. FocusTrap.prototype.wrapTabFocus = function (el) {
  256. var _this = this;
  257. var sentinelStart = this.createSentinel();
  258. var sentinelEnd = this.createSentinel();
  259. sentinelStart.addEventListener('focus', function () {
  260. var focusableEls = _this.getFocusableElements(el);
  261. if (focusableEls.length > 0) {
  262. focusableEls[focusableEls.length - 1].focus();
  263. }
  264. });
  265. sentinelEnd.addEventListener('focus', function () {
  266. var focusableEls = _this.getFocusableElements(el);
  267. if (focusableEls.length > 0) {
  268. focusableEls[0].focus();
  269. }
  270. });
  271. el.insertBefore(sentinelStart, el.children[0]);
  272. el.appendChild(sentinelEnd);
  273. };
  274. /**
  275. * Focuses on `initialFocusEl` if defined and a child of the root element.
  276. * Otherwise, focuses on the first focusable child element of the root.
  277. */
  278. FocusTrap.prototype.focusInitialElement = function (focusableEls, initialFocusEl) {
  279. var focusIndex = 0;
  280. if (initialFocusEl) {
  281. focusIndex = Math.max(focusableEls.indexOf(initialFocusEl), 0);
  282. }
  283. focusableEls[focusIndex].focus();
  284. };
  285. FocusTrap.prototype.getFocusableElements = function (root) {
  286. var focusableEls = Array.from(root.querySelectorAll('[autofocus], [tabindex], a, input, textarea, select, button'));
  287. return focusableEls.filter(function (el) {
  288. var isDisabledOrHidden = el.getAttribute('aria-disabled') === 'true' || el.getAttribute('disabled') != null || el.getAttribute('hidden') != null || el.getAttribute('aria-hidden') === 'true';
  289. var isTabbableAndVisible = el.tabIndex >= 0 && el.getBoundingClientRect().width > 0 && !el.classList.contains(FOCUS_SENTINEL_CLASS) && !isDisabledOrHidden;
  290. var isProgrammaticallyHidden = false;
  291. if (isTabbableAndVisible) {
  292. var style = getComputedStyle(el);
  293. isProgrammaticallyHidden = style.display === 'none' || style.visibility === 'hidden';
  294. }
  295. return isTabbableAndVisible && !isProgrammaticallyHidden;
  296. });
  297. };
  298. FocusTrap.prototype.createSentinel = function () {
  299. var sentinel = document.createElement('div');
  300. sentinel.setAttribute('tabindex', '0');
  301. // Don't announce in screen readers.
  302. sentinel.setAttribute('aria-hidden', 'true');
  303. sentinel.classList.add(FOCUS_SENTINEL_CLASS);
  304. return sentinel;
  305. };
  306. return FocusTrap;
  307. }();
  308. exports.FocusTrap = FocusTrap;
  309. /***/ }),
  310. /***/ "./packages/mdc-dom/index.ts":
  311. /*!***********************************!*\
  312. !*** ./packages/mdc-dom/index.ts ***!
  313. \***********************************/
  314. /*! no static exports found */
  315. /***/ (function(module, exports, __webpack_require__) {
  316. "use strict";
  317. /**
  318. * @license
  319. * Copyright 2018 Google Inc.
  320. *
  321. * Permission is hereby granted, free of charge, to any person obtaining a copy
  322. * of this software and associated documentation files (the "Software"), to deal
  323. * in the Software without restriction, including without limitation the rights
  324. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  325. * copies of the Software, and to permit persons to whom the Software is
  326. * furnished to do so, subject to the following conditions:
  327. *
  328. * The above copyright notice and this permission notice shall be included in
  329. * all copies or substantial portions of the Software.
  330. *
  331. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  332. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  333. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  334. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  335. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  336. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  337. * THE SOFTWARE.
  338. */
  339. var __createBinding = this && this.__createBinding || (Object.create ? function (o, m, k, k2) {
  340. if (k2 === undefined) k2 = k;
  341. Object.defineProperty(o, k2, { enumerable: true, get: function get() {
  342. return m[k];
  343. } });
  344. } : function (o, m, k, k2) {
  345. if (k2 === undefined) k2 = k;
  346. o[k2] = m[k];
  347. });
  348. var __setModuleDefault = this && this.__setModuleDefault || (Object.create ? function (o, v) {
  349. Object.defineProperty(o, "default", { enumerable: true, value: v });
  350. } : function (o, v) {
  351. o["default"] = v;
  352. });
  353. var __importStar = this && this.__importStar || function (mod) {
  354. if (mod && mod.__esModule) return mod;
  355. var result = {};
  356. if (mod != null) for (var k in mod) {
  357. if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
  358. }__setModuleDefault(result, mod);
  359. return result;
  360. };
  361. Object.defineProperty(exports, "__esModule", { value: true });
  362. exports.ponyfill = exports.keyboard = exports.focusTrap = exports.events = void 0;
  363. var events = __importStar(__webpack_require__(/*! ./events */ "./packages/mdc-dom/events.ts"));
  364. exports.events = events;
  365. var focusTrap = __importStar(__webpack_require__(/*! ./focus-trap */ "./packages/mdc-dom/focus-trap.ts"));
  366. exports.focusTrap = focusTrap;
  367. var keyboard = __importStar(__webpack_require__(/*! ./keyboard */ "./packages/mdc-dom/keyboard.ts"));
  368. exports.keyboard = keyboard;
  369. var ponyfill = __importStar(__webpack_require__(/*! ./ponyfill */ "./packages/mdc-dom/ponyfill.ts"));
  370. exports.ponyfill = ponyfill;
  371. /***/ }),
  372. /***/ "./packages/mdc-dom/keyboard.ts":
  373. /*!**************************************!*\
  374. !*** ./packages/mdc-dom/keyboard.ts ***!
  375. \**************************************/
  376. /*! no static exports found */
  377. /***/ (function(module, exports, __webpack_require__) {
  378. "use strict";
  379. /**
  380. * @license
  381. * Copyright 2020 Google Inc.
  382. *
  383. * Permission is hereby granted, free of charge, to any person obtaining a copy
  384. * of this software and associated documentation files (the "Software"), to deal
  385. * in the Software without restriction, including without limitation the rights
  386. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  387. * copies of the Software, and to permit persons to whom the Software is
  388. * furnished to do so, subject to the following conditions:
  389. *
  390. * The above copyright notice and this permission notice shall be included in
  391. * all copies or substantial portions of the Software.
  392. *
  393. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  394. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  395. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  396. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  397. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  398. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  399. * THE SOFTWARE.
  400. */
  401. Object.defineProperty(exports, "__esModule", { value: true });
  402. exports.isNavigationEvent = exports.normalizeKey = exports.KEY = void 0;
  403. /**
  404. * KEY provides normalized string values for keys.
  405. */
  406. exports.KEY = {
  407. UNKNOWN: 'Unknown',
  408. BACKSPACE: 'Backspace',
  409. ENTER: 'Enter',
  410. SPACEBAR: 'Spacebar',
  411. PAGE_UP: 'PageUp',
  412. PAGE_DOWN: 'PageDown',
  413. END: 'End',
  414. HOME: 'Home',
  415. ARROW_LEFT: 'ArrowLeft',
  416. ARROW_UP: 'ArrowUp',
  417. ARROW_RIGHT: 'ArrowRight',
  418. ARROW_DOWN: 'ArrowDown',
  419. DELETE: 'Delete',
  420. ESCAPE: 'Escape',
  421. TAB: 'Tab'
  422. };
  423. var normalizedKeys = new Set();
  424. // IE11 has no support for new Map with iterable so we need to initialize this
  425. // by hand.
  426. normalizedKeys.add(exports.KEY.BACKSPACE);
  427. normalizedKeys.add(exports.KEY.ENTER);
  428. normalizedKeys.add(exports.KEY.SPACEBAR);
  429. normalizedKeys.add(exports.KEY.PAGE_UP);
  430. normalizedKeys.add(exports.KEY.PAGE_DOWN);
  431. normalizedKeys.add(exports.KEY.END);
  432. normalizedKeys.add(exports.KEY.HOME);
  433. normalizedKeys.add(exports.KEY.ARROW_LEFT);
  434. normalizedKeys.add(exports.KEY.ARROW_UP);
  435. normalizedKeys.add(exports.KEY.ARROW_RIGHT);
  436. normalizedKeys.add(exports.KEY.ARROW_DOWN);
  437. normalizedKeys.add(exports.KEY.DELETE);
  438. normalizedKeys.add(exports.KEY.ESCAPE);
  439. normalizedKeys.add(exports.KEY.TAB);
  440. var KEY_CODE = {
  441. BACKSPACE: 8,
  442. ENTER: 13,
  443. SPACEBAR: 32,
  444. PAGE_UP: 33,
  445. PAGE_DOWN: 34,
  446. END: 35,
  447. HOME: 36,
  448. ARROW_LEFT: 37,
  449. ARROW_UP: 38,
  450. ARROW_RIGHT: 39,
  451. ARROW_DOWN: 40,
  452. DELETE: 46,
  453. ESCAPE: 27,
  454. TAB: 9
  455. };
  456. var mappedKeyCodes = new Map();
  457. // IE11 has no support for new Map with iterable so we need to initialize this
  458. // by hand.
  459. mappedKeyCodes.set(KEY_CODE.BACKSPACE, exports.KEY.BACKSPACE);
  460. mappedKeyCodes.set(KEY_CODE.ENTER, exports.KEY.ENTER);
  461. mappedKeyCodes.set(KEY_CODE.SPACEBAR, exports.KEY.SPACEBAR);
  462. mappedKeyCodes.set(KEY_CODE.PAGE_UP, exports.KEY.PAGE_UP);
  463. mappedKeyCodes.set(KEY_CODE.PAGE_DOWN, exports.KEY.PAGE_DOWN);
  464. mappedKeyCodes.set(KEY_CODE.END, exports.KEY.END);
  465. mappedKeyCodes.set(KEY_CODE.HOME, exports.KEY.HOME);
  466. mappedKeyCodes.set(KEY_CODE.ARROW_LEFT, exports.KEY.ARROW_LEFT);
  467. mappedKeyCodes.set(KEY_CODE.ARROW_UP, exports.KEY.ARROW_UP);
  468. mappedKeyCodes.set(KEY_CODE.ARROW_RIGHT, exports.KEY.ARROW_RIGHT);
  469. mappedKeyCodes.set(KEY_CODE.ARROW_DOWN, exports.KEY.ARROW_DOWN);
  470. mappedKeyCodes.set(KEY_CODE.DELETE, exports.KEY.DELETE);
  471. mappedKeyCodes.set(KEY_CODE.ESCAPE, exports.KEY.ESCAPE);
  472. mappedKeyCodes.set(KEY_CODE.TAB, exports.KEY.TAB);
  473. var navigationKeys = new Set();
  474. // IE11 has no support for new Set with iterable so we need to initialize this
  475. // by hand.
  476. navigationKeys.add(exports.KEY.PAGE_UP);
  477. navigationKeys.add(exports.KEY.PAGE_DOWN);
  478. navigationKeys.add(exports.KEY.END);
  479. navigationKeys.add(exports.KEY.HOME);
  480. navigationKeys.add(exports.KEY.ARROW_LEFT);
  481. navigationKeys.add(exports.KEY.ARROW_UP);
  482. navigationKeys.add(exports.KEY.ARROW_RIGHT);
  483. navigationKeys.add(exports.KEY.ARROW_DOWN);
  484. /**
  485. * normalizeKey returns the normalized string for a navigational action.
  486. */
  487. function normalizeKey(evt) {
  488. var key = evt.key;
  489. // If the event already has a normalized key, return it
  490. if (normalizedKeys.has(key)) {
  491. return key;
  492. }
  493. // tslint:disable-next-line:deprecation
  494. var mappedKey = mappedKeyCodes.get(evt.keyCode);
  495. if (mappedKey) {
  496. return mappedKey;
  497. }
  498. return exports.KEY.UNKNOWN;
  499. }
  500. exports.normalizeKey = normalizeKey;
  501. /**
  502. * isNavigationEvent returns whether the event is a navigation event
  503. */
  504. function isNavigationEvent(evt) {
  505. return navigationKeys.has(normalizeKey(evt));
  506. }
  507. exports.isNavigationEvent = isNavigationEvent;
  508. /***/ }),
  509. /***/ "./packages/mdc-dom/ponyfill.ts":
  510. /*!**************************************!*\
  511. !*** ./packages/mdc-dom/ponyfill.ts ***!
  512. \**************************************/
  513. /*! no static exports found */
  514. /***/ (function(module, exports, __webpack_require__) {
  515. "use strict";
  516. /**
  517. * @license
  518. * Copyright 2018 Google Inc.
  519. *
  520. * Permission is hereby granted, free of charge, to any person obtaining a copy
  521. * of this software and associated documentation files (the "Software"), to deal
  522. * in the Software without restriction, including without limitation the rights
  523. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  524. * copies of the Software, and to permit persons to whom the Software is
  525. * furnished to do so, subject to the following conditions:
  526. *
  527. * The above copyright notice and this permission notice shall be included in
  528. * all copies or substantial portions of the Software.
  529. *
  530. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  531. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  532. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  533. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  534. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  535. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  536. * THE SOFTWARE.
  537. */
  538. Object.defineProperty(exports, "__esModule", { value: true });
  539. exports.estimateScrollWidth = exports.matches = exports.closest = void 0;
  540. /**
  541. * @fileoverview A "ponyfill" is a polyfill that doesn't modify the global
  542. * prototype chain. This makes ponyfills safer than traditional polyfills,
  543. * especially for libraries like MDC.
  544. */
  545. function closest(element, selector) {
  546. if (element.closest) {
  547. return element.closest(selector);
  548. }
  549. var el = element;
  550. while (el) {
  551. if (matches(el, selector)) {
  552. return el;
  553. }
  554. el = el.parentElement;
  555. }
  556. return null;
  557. }
  558. exports.closest = closest;
  559. /** Element.matches with support for webkit and IE. */
  560. function matches(element, selector) {
  561. var nativeMatches = element.matches || element.webkitMatchesSelector || element.msMatchesSelector;
  562. return nativeMatches.call(element, selector);
  563. }
  564. exports.matches = matches;
  565. /**
  566. * Used to compute the estimated scroll width of elements. When an element is
  567. * hidden due to display: none; being applied to a parent element, the width is
  568. * returned as 0. However, the element will have a true width once no longer
  569. * inside a display: none context. This method computes an estimated width when
  570. * the element is hidden or returns the true width when the element is visble.
  571. * @param {Element} element the element whose width to estimate
  572. */
  573. function estimateScrollWidth(element) {
  574. // Check the offsetParent. If the element inherits display: none from any
  575. // parent, the offsetParent property will be null (see
  576. // https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/offsetParent).
  577. // This check ensures we only clone the node when necessary.
  578. var htmlEl = element;
  579. if (htmlEl.offsetParent !== null) {
  580. return htmlEl.scrollWidth;
  581. }
  582. var clone = htmlEl.cloneNode(true);
  583. clone.style.setProperty('position', 'absolute');
  584. clone.style.setProperty('transform', 'translate(-9999px, -9999px)');
  585. document.documentElement.appendChild(clone);
  586. var scrollWidth = clone.scrollWidth;
  587. document.documentElement.removeChild(clone);
  588. return scrollWidth;
  589. }
  590. exports.estimateScrollWidth = estimateScrollWidth;
  591. /***/ })
  592. /******/ });
  593. });
  594. //# sourceMappingURL=mdc.dom.js.map