UNPKG

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