618 lines
24 KiB
JavaScript
618 lines
24 KiB
JavaScript
|
/**
|
||
|
* @license
|
||
|
* Copyright Google LLC All Rights Reserved.
|
||
|
*
|
||
|
* Use of this source code is governed by an MIT-style license that can be
|
||
|
* found in the LICENSE file at https://github.com/material-components/material-components-web/blob/master/LICENSE
|
||
|
*/
|
||
|
(function webpackUniversalModuleDefinition(root, factory) {
|
||
|
if(typeof exports === 'object' && typeof module === 'object')
|
||
|
module.exports = factory();
|
||
|
else if(typeof define === 'function' && define.amd)
|
||
|
define("@material/dom", [], factory);
|
||
|
else if(typeof exports === 'object')
|
||
|
exports["dom"] = factory();
|
||
|
else
|
||
|
root["mdc"] = root["mdc"] || {}, root["mdc"]["dom"] = factory();
|
||
|
})(this, function() {
|
||
|
return /******/ (function(modules) { // webpackBootstrap
|
||
|
/******/ // The module cache
|
||
|
/******/ var installedModules = {};
|
||
|
/******/
|
||
|
/******/ // The require function
|
||
|
/******/ function __webpack_require__(moduleId) {
|
||
|
/******/
|
||
|
/******/ // Check if module is in cache
|
||
|
/******/ if(installedModules[moduleId]) {
|
||
|
/******/ return installedModules[moduleId].exports;
|
||
|
/******/ }
|
||
|
/******/ // Create a new module (and put it into the cache)
|
||
|
/******/ var module = installedModules[moduleId] = {
|
||
|
/******/ i: moduleId,
|
||
|
/******/ l: false,
|
||
|
/******/ exports: {}
|
||
|
/******/ };
|
||
|
/******/
|
||
|
/******/ // Execute the module function
|
||
|
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
|
||
|
/******/
|
||
|
/******/ // Flag the module as loaded
|
||
|
/******/ module.l = true;
|
||
|
/******/
|
||
|
/******/ // Return the exports of the module
|
||
|
/******/ return module.exports;
|
||
|
/******/ }
|
||
|
/******/
|
||
|
/******/
|
||
|
/******/ // expose the modules object (__webpack_modules__)
|
||
|
/******/ __webpack_require__.m = modules;
|
||
|
/******/
|
||
|
/******/ // expose the module cache
|
||
|
/******/ __webpack_require__.c = installedModules;
|
||
|
/******/
|
||
|
/******/ // define getter function for harmony exports
|
||
|
/******/ __webpack_require__.d = function(exports, name, getter) {
|
||
|
/******/ if(!__webpack_require__.o(exports, name)) {
|
||
|
/******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
|
||
|
/******/ }
|
||
|
/******/ };
|
||
|
/******/
|
||
|
/******/ // define __esModule on exports
|
||
|
/******/ __webpack_require__.r = function(exports) {
|
||
|
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
|
||
|
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
||
|
/******/ }
|
||
|
/******/ Object.defineProperty(exports, '__esModule', { value: true });
|
||
|
/******/ };
|
||
|
/******/
|
||
|
/******/ // create a fake namespace object
|
||
|
/******/ // mode & 1: value is a module id, require it
|
||
|
/******/ // mode & 2: merge all properties of value into the ns
|
||
|
/******/ // mode & 4: return value when already ns object
|
||
|
/******/ // mode & 8|1: behave like require
|
||
|
/******/ __webpack_require__.t = function(value, mode) {
|
||
|
/******/ if(mode & 1) value = __webpack_require__(value);
|
||
|
/******/ if(mode & 8) return value;
|
||
|
/******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
|
||
|
/******/ var ns = Object.create(null);
|
||
|
/******/ __webpack_require__.r(ns);
|
||
|
/******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
|
||
|
/******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
|
||
|
/******/ return ns;
|
||
|
/******/ };
|
||
|
/******/
|
||
|
/******/ // getDefaultExport function for compatibility with non-harmony modules
|
||
|
/******/ __webpack_require__.n = function(module) {
|
||
|
/******/ var getter = module && module.__esModule ?
|
||
|
/******/ function getDefault() { return module['default']; } :
|
||
|
/******/ function getModuleExports() { return module; };
|
||
|
/******/ __webpack_require__.d(getter, 'a', getter);
|
||
|
/******/ return getter;
|
||
|
/******/ };
|
||
|
/******/
|
||
|
/******/ // Object.prototype.hasOwnProperty.call
|
||
|
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
|
||
|
/******/
|
||
|
/******/ // __webpack_public_path__
|
||
|
/******/ __webpack_require__.p = "";
|
||
|
/******/
|
||
|
/******/
|
||
|
/******/ // Load entry module and return exports
|
||
|
/******/ return __webpack_require__(__webpack_require__.s = "./packages/mdc-dom/index.ts");
|
||
|
/******/ })
|
||
|
/************************************************************************/
|
||
|
/******/ ({
|
||
|
|
||
|
/***/ "./packages/mdc-dom/events.ts":
|
||
|
/*!************************************!*\
|
||
|
!*** ./packages/mdc-dom/events.ts ***!
|
||
|
\************************************/
|
||
|
/*! no static exports found */
|
||
|
/***/ (function(module, exports, __webpack_require__) {
|
||
|
|
||
|
"use strict";
|
||
|
|
||
|
/**
|
||
|
* @license
|
||
|
* Copyright 2019 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.
|
||
|
*/
|
||
|
|
||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||
|
exports.applyPassive = void 0;
|
||
|
/**
|
||
|
* Determine whether the current browser supports passive event listeners, and
|
||
|
* if so, use them.
|
||
|
*/
|
||
|
function applyPassive(globalObj) {
|
||
|
if (globalObj === void 0) {
|
||
|
globalObj = window;
|
||
|
}
|
||
|
return supportsPassiveOption(globalObj) ? { passive: true } : false;
|
||
|
}
|
||
|
exports.applyPassive = applyPassive;
|
||
|
function supportsPassiveOption(globalObj) {
|
||
|
if (globalObj === void 0) {
|
||
|
globalObj = window;
|
||
|
}
|
||
|
// See
|
||
|
// https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener
|
||
|
var passiveSupported = false;
|
||
|
try {
|
||
|
var options = {
|
||
|
// This function will be called when the browser
|
||
|
// attempts to access the passive property.
|
||
|
get passive() {
|
||
|
passiveSupported = true;
|
||
|
return false;
|
||
|
}
|
||
|
};
|
||
|
var handler = function handler() {};
|
||
|
globalObj.document.addEventListener('test', handler, options);
|
||
|
globalObj.document.removeEventListener('test', handler, options);
|
||
|
} catch (err) {
|
||
|
passiveSupported = false;
|
||
|
}
|
||
|
return passiveSupported;
|
||
|
}
|
||
|
|
||
|
/***/ }),
|
||
|
|
||
|
/***/ "./packages/mdc-dom/focus-trap.ts":
|
||
|
/*!****************************************!*\
|
||
|
!*** ./packages/mdc-dom/focus-trap.ts ***!
|
||
|
\****************************************/
|
||
|
/*! no static exports found */
|
||
|
/***/ (function(module, exports, __webpack_require__) {
|
||
|
|
||
|
"use strict";
|
||
|
|
||
|
/**
|
||
|
* @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.
|
||
|
*/
|
||
|
|
||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||
|
exports.FocusTrap = void 0;
|
||
|
var FOCUS_SENTINEL_CLASS = 'mdc-dom-focus-sentinel';
|
||
|
/**
|
||
|
* Utility to trap focus in a given root element, e.g. for modal components such
|
||
|
* as dialogs. The root should have at least one focusable child element,
|
||
|
* for setting initial focus when trapping focus.
|
||
|
* Also tracks the previously focused element, and restores focus to that
|
||
|
* element when releasing focus.
|
||
|
*/
|
||
|
var FocusTrap = /** @class */function () {
|
||
|
function FocusTrap(root, options) {
|
||
|
if (options === void 0) {
|
||
|
options = {};
|
||
|
}
|
||
|
this.root = root;
|
||
|
this.options = options;
|
||
|
// Previously focused element before trapping focus.
|
||
|
this.elFocusedBeforeTrapFocus = null;
|
||
|
}
|
||
|
/**
|
||
|
* Traps focus in `root`. Also focuses on either `initialFocusEl` if set;
|
||
|
* otherwises sets initial focus to the first focusable child element.
|
||
|
*/
|
||
|
FocusTrap.prototype.trapFocus = function () {
|
||
|
var focusableEls = this.getFocusableElements(this.root);
|
||
|
if (focusableEls.length === 0) {
|
||
|
throw new Error('FocusTrap: Element must have at least one focusable child.');
|
||
|
}
|
||
|
this.elFocusedBeforeTrapFocus = document.activeElement instanceof HTMLElement ? document.activeElement : null;
|
||
|
this.wrapTabFocus(this.root);
|
||
|
if (!this.options.skipInitialFocus) {
|
||
|
this.focusInitialElement(focusableEls, this.options.initialFocusEl);
|
||
|
}
|
||
|
};
|
||
|
/**
|
||
|
* Releases focus from `root`. Also restores focus to the previously focused
|
||
|
* element.
|
||
|
*/
|
||
|
FocusTrap.prototype.releaseFocus = function () {
|
||
|
[].slice.call(this.root.querySelectorAll("." + FOCUS_SENTINEL_CLASS)).forEach(function (sentinelEl) {
|
||
|
sentinelEl.parentElement.removeChild(sentinelEl);
|
||
|
});
|
||
|
if (!this.options.skipRestoreFocus && this.elFocusedBeforeTrapFocus) {
|
||
|
this.elFocusedBeforeTrapFocus.focus();
|
||
|
}
|
||
|
};
|
||
|
/**
|
||
|
* Wraps tab focus within `el` by adding two hidden sentinel divs which are
|
||
|
* used to mark the beginning and the end of the tabbable region. When
|
||
|
* focused, these sentinel elements redirect focus to the first/last
|
||
|
* children elements of the tabbable region, ensuring that focus is trapped
|
||
|
* within that region.
|
||
|
*/
|
||
|
FocusTrap.prototype.wrapTabFocus = function (el) {
|
||
|
var _this = this;
|
||
|
var sentinelStart = this.createSentinel();
|
||
|
var sentinelEnd = this.createSentinel();
|
||
|
sentinelStart.addEventListener('focus', function () {
|
||
|
var focusableEls = _this.getFocusableElements(el);
|
||
|
if (focusableEls.length > 0) {
|
||
|
focusableEls[focusableEls.length - 1].focus();
|
||
|
}
|
||
|
});
|
||
|
sentinelEnd.addEventListener('focus', function () {
|
||
|
var focusableEls = _this.getFocusableElements(el);
|
||
|
if (focusableEls.length > 0) {
|
||
|
focusableEls[0].focus();
|
||
|
}
|
||
|
});
|
||
|
el.insertBefore(sentinelStart, el.children[0]);
|
||
|
el.appendChild(sentinelEnd);
|
||
|
};
|
||
|
/**
|
||
|
* Focuses on `initialFocusEl` if defined and a child of the root element.
|
||
|
* Otherwise, focuses on the first focusable child element of the root.
|
||
|
*/
|
||
|
FocusTrap.prototype.focusInitialElement = function (focusableEls, initialFocusEl) {
|
||
|
var focusIndex = 0;
|
||
|
if (initialFocusEl) {
|
||
|
focusIndex = Math.max(focusableEls.indexOf(initialFocusEl), 0);
|
||
|
}
|
||
|
focusableEls[focusIndex].focus();
|
||
|
};
|
||
|
FocusTrap.prototype.getFocusableElements = function (root) {
|
||
|
var focusableEls = [].slice.call(root.querySelectorAll('[autofocus], [tabindex], a, input, textarea, select, button'));
|
||
|
return focusableEls.filter(function (el) {
|
||
|
var isDisabledOrHidden = el.getAttribute('aria-disabled') === 'true' || el.getAttribute('disabled') != null || el.getAttribute('hidden') != null || el.getAttribute('aria-hidden') === 'true';
|
||
|
var isTabbableAndVisible = el.tabIndex >= 0 && el.getBoundingClientRect().width > 0 && !el.classList.contains(FOCUS_SENTINEL_CLASS) && !isDisabledOrHidden;
|
||
|
var isProgrammaticallyHidden = false;
|
||
|
if (isTabbableAndVisible) {
|
||
|
var style = getComputedStyle(el);
|
||
|
isProgrammaticallyHidden = style.display === 'none' || style.visibility === 'hidden';
|
||
|
}
|
||
|
return isTabbableAndVisible && !isProgrammaticallyHidden;
|
||
|
});
|
||
|
};
|
||
|
FocusTrap.prototype.createSentinel = function () {
|
||
|
var sentinel = document.createElement('div');
|
||
|
sentinel.setAttribute('tabindex', '0');
|
||
|
// Don't announce in screen readers.
|
||
|
sentinel.setAttribute('aria-hidden', 'true');
|
||
|
sentinel.classList.add(FOCUS_SENTINEL_CLASS);
|
||
|
return sentinel;
|
||
|
};
|
||
|
return FocusTrap;
|
||
|
}();
|
||
|
exports.FocusTrap = FocusTrap;
|
||
|
|
||
|
/***/ }),
|
||
|
|
||
|
/***/ "./packages/mdc-dom/index.ts":
|
||
|
/*!***********************************!*\
|
||
|
!*** ./packages/mdc-dom/index.ts ***!
|
||
|
\***********************************/
|
||
|
/*! no static exports found */
|
||
|
/***/ (function(module, exports, __webpack_require__) {
|
||
|
|
||
|
"use strict";
|
||
|
|
||
|
/**
|
||
|
* @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 __createBinding = this && this.__createBinding || (Object.create ? function (o, m, k, k2) {
|
||
|
if (k2 === undefined) k2 = k;
|
||
|
Object.defineProperty(o, k2, { enumerable: true, get: function get() {
|
||
|
return m[k];
|
||
|
} });
|
||
|
} : function (o, m, k, k2) {
|
||
|
if (k2 === undefined) k2 = k;
|
||
|
o[k2] = m[k];
|
||
|
});
|
||
|
var __setModuleDefault = this && this.__setModuleDefault || (Object.create ? function (o, v) {
|
||
|
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||
|
} : function (o, v) {
|
||
|
o["default"] = v;
|
||
|
});
|
||
|
var __importStar = this && this.__importStar || function (mod) {
|
||
|
if (mod && mod.__esModule) return mod;
|
||
|
var result = {};
|
||
|
if (mod != null) for (var k in mod) {
|
||
|
if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
||
|
}__setModuleDefault(result, mod);
|
||
|
return result;
|
||
|
};
|
||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||
|
exports.ponyfill = exports.keyboard = exports.focusTrap = exports.events = void 0;
|
||
|
var events = __importStar(__webpack_require__(/*! ./events */ "./packages/mdc-dom/events.ts"));
|
||
|
exports.events = events;
|
||
|
var focusTrap = __importStar(__webpack_require__(/*! ./focus-trap */ "./packages/mdc-dom/focus-trap.ts"));
|
||
|
exports.focusTrap = focusTrap;
|
||
|
var keyboard = __importStar(__webpack_require__(/*! ./keyboard */ "./packages/mdc-dom/keyboard.ts"));
|
||
|
exports.keyboard = keyboard;
|
||
|
var ponyfill = __importStar(__webpack_require__(/*! ./ponyfill */ "./packages/mdc-dom/ponyfill.ts"));
|
||
|
exports.ponyfill = ponyfill;
|
||
|
|
||
|
/***/ }),
|
||
|
|
||
|
/***/ "./packages/mdc-dom/keyboard.ts":
|
||
|
/*!**************************************!*\
|
||
|
!*** ./packages/mdc-dom/keyboard.ts ***!
|
||
|
\**************************************/
|
||
|
/*! no static exports found */
|
||
|
/***/ (function(module, exports, __webpack_require__) {
|
||
|
|
||
|
"use strict";
|
||
|
|
||
|
/**
|
||
|
* @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.
|
||
|
*/
|
||
|
|
||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||
|
exports.isNavigationEvent = exports.normalizeKey = exports.KEY = void 0;
|
||
|
/**
|
||
|
* KEY provides normalized string values for keys.
|
||
|
*/
|
||
|
exports.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',
|
||
|
TAB: 'Tab'
|
||
|
};
|
||
|
var normalizedKeys = new Set();
|
||
|
// IE11 has no support for new Map with iterable so we need to initialize this
|
||
|
// by hand.
|
||
|
normalizedKeys.add(exports.KEY.BACKSPACE);
|
||
|
normalizedKeys.add(exports.KEY.ENTER);
|
||
|
normalizedKeys.add(exports.KEY.SPACEBAR);
|
||
|
normalizedKeys.add(exports.KEY.PAGE_UP);
|
||
|
normalizedKeys.add(exports.KEY.PAGE_DOWN);
|
||
|
normalizedKeys.add(exports.KEY.END);
|
||
|
normalizedKeys.add(exports.KEY.HOME);
|
||
|
normalizedKeys.add(exports.KEY.ARROW_LEFT);
|
||
|
normalizedKeys.add(exports.KEY.ARROW_UP);
|
||
|
normalizedKeys.add(exports.KEY.ARROW_RIGHT);
|
||
|
normalizedKeys.add(exports.KEY.ARROW_DOWN);
|
||
|
normalizedKeys.add(exports.KEY.DELETE);
|
||
|
normalizedKeys.add(exports.KEY.ESCAPE);
|
||
|
normalizedKeys.add(exports.KEY.TAB);
|
||
|
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,
|
||
|
TAB: 9
|
||
|
};
|
||
|
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, exports.KEY.BACKSPACE);
|
||
|
mappedKeyCodes.set(KEY_CODE.ENTER, exports.KEY.ENTER);
|
||
|
mappedKeyCodes.set(KEY_CODE.SPACEBAR, exports.KEY.SPACEBAR);
|
||
|
mappedKeyCodes.set(KEY_CODE.PAGE_UP, exports.KEY.PAGE_UP);
|
||
|
mappedKeyCodes.set(KEY_CODE.PAGE_DOWN, exports.KEY.PAGE_DOWN);
|
||
|
mappedKeyCodes.set(KEY_CODE.END, exports.KEY.END);
|
||
|
mappedKeyCodes.set(KEY_CODE.HOME, exports.KEY.HOME);
|
||
|
mappedKeyCodes.set(KEY_CODE.ARROW_LEFT, exports.KEY.ARROW_LEFT);
|
||
|
mappedKeyCodes.set(KEY_CODE.ARROW_UP, exports.KEY.ARROW_UP);
|
||
|
mappedKeyCodes.set(KEY_CODE.ARROW_RIGHT, exports.KEY.ARROW_RIGHT);
|
||
|
mappedKeyCodes.set(KEY_CODE.ARROW_DOWN, exports.KEY.ARROW_DOWN);
|
||
|
mappedKeyCodes.set(KEY_CODE.DELETE, exports.KEY.DELETE);
|
||
|
mappedKeyCodes.set(KEY_CODE.ESCAPE, exports.KEY.ESCAPE);
|
||
|
mappedKeyCodes.set(KEY_CODE.TAB, exports.KEY.TAB);
|
||
|
var navigationKeys = new Set();
|
||
|
// IE11 has no support for new Set with iterable so we need to initialize this
|
||
|
// by hand.
|
||
|
navigationKeys.add(exports.KEY.PAGE_UP);
|
||
|
navigationKeys.add(exports.KEY.PAGE_DOWN);
|
||
|
navigationKeys.add(exports.KEY.END);
|
||
|
navigationKeys.add(exports.KEY.HOME);
|
||
|
navigationKeys.add(exports.KEY.ARROW_LEFT);
|
||
|
navigationKeys.add(exports.KEY.ARROW_UP);
|
||
|
navigationKeys.add(exports.KEY.ARROW_RIGHT);
|
||
|
navigationKeys.add(exports.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 exports.KEY.UNKNOWN;
|
||
|
}
|
||
|
exports.normalizeKey = normalizeKey;
|
||
|
/**
|
||
|
* isNavigationEvent returns whether the event is a navigation event
|
||
|
*/
|
||
|
function isNavigationEvent(evt) {
|
||
|
return navigationKeys.has(normalizeKey(evt));
|
||
|
}
|
||
|
exports.isNavigationEvent = isNavigationEvent;
|
||
|
|
||
|
/***/ }),
|
||
|
|
||
|
/***/ "./packages/mdc-dom/ponyfill.ts":
|
||
|
/*!**************************************!*\
|
||
|
!*** ./packages/mdc-dom/ponyfill.ts ***!
|
||
|
\**************************************/
|
||
|
/*! no static exports found */
|
||
|
/***/ (function(module, exports, __webpack_require__) {
|
||
|
|
||
|
"use strict";
|
||
|
|
||
|
/**
|
||
|
* @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.
|
||
|
*/
|
||
|
|
||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||
|
exports.estimateScrollWidth = exports.matches = exports.closest = void 0;
|
||
|
/**
|
||
|
* @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;
|
||
|
}
|
||
|
exports.closest = closest;
|
||
|
function matches(element, selector) {
|
||
|
var nativeMatches = element.matches || element.webkitMatchesSelector || element.msMatchesSelector;
|
||
|
return nativeMatches.call(element, selector);
|
||
|
}
|
||
|
exports.matches = matches;
|
||
|
/**
|
||
|
* Used to compute the estimated scroll width of elements. When an element is
|
||
|
* hidden due to display: none; being applied to a parent element, the width is
|
||
|
* returned as 0. However, the element will have a true width once no longer
|
||
|
* inside a display: none context. This method computes an estimated width when
|
||
|
* the element is hidden or returns the true width when the element is visble.
|
||
|
* @param {Element} element the element whose width to estimate
|
||
|
*/
|
||
|
function estimateScrollWidth(element) {
|
||
|
// Check the offsetParent. If the element inherits display: none from any
|
||
|
// parent, the offsetParent property will be null (see
|
||
|
// https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/offsetParent).
|
||
|
// This check ensures we only clone the node when necessary.
|
||
|
var htmlEl = element;
|
||
|
if (htmlEl.offsetParent !== null) {
|
||
|
return htmlEl.scrollWidth;
|
||
|
}
|
||
|
var clone = htmlEl.cloneNode(true);
|
||
|
clone.style.setProperty('position', 'absolute');
|
||
|
clone.style.setProperty('transform', 'translate(-9999px, -9999px)');
|
||
|
document.documentElement.appendChild(clone);
|
||
|
var scrollWidth = clone.scrollWidth;
|
||
|
document.documentElement.removeChild(clone);
|
||
|
return scrollWidth;
|
||
|
}
|
||
|
exports.estimateScrollWidth = estimateScrollWidth;
|
||
|
|
||
|
/***/ })
|
||
|
|
||
|
/******/ });
|
||
|
});
|
||
|
//# sourceMappingURL=mdc.dom.js.map
|