UNPKG

@material/banner

Version:
1,165 lines (1,119 loc) • 49.8 kB
/** * @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/banner", [], factory); else if(typeof exports === 'object') exports["banner"] = factory(); else root["mdc"] = root["mdc"] || {}, root["mdc"]["banner"] = 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-banner/index.ts"); /******/ }) /************************************************************************/ /******/ ({ /***/ "./packages/mdc-banner/adapter.ts": /*!****************************************!*\ !*** ./packages/mdc-banner/adapter.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 }); /***/ }), /***/ "./packages/mdc-banner/component.ts": /*!******************************************!*\ !*** ./packages/mdc-banner/component.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. */ var __extends = this && this.__extends || function () { var _extendStatics = function extendStatics(d, b) { _extendStatics = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; } || function (d, b) { for (var p in b) { if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; } }; return _extendStatics(d, b); }; return function (d, b) { if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); _extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; }(); Object.defineProperty(exports, "__esModule", { value: true }); exports.MDCBanner = void 0; var component_1 = __webpack_require__(/*! @material/base/component */ "./packages/mdc-base/component.ts"); var focus_trap_1 = __webpack_require__(/*! @material/dom/focus-trap */ "./packages/mdc-dom/focus-trap.ts"); var ponyfill_1 = __webpack_require__(/*! @material/dom/ponyfill */ "./packages/mdc-dom/ponyfill.ts"); var constants_1 = __webpack_require__(/*! ./constants */ "./packages/mdc-banner/constants.ts"); var foundation_1 = __webpack_require__(/*! ./foundation */ "./packages/mdc-banner/foundation.ts"); /** Vanilla JS implementation of banner component. */ var MDCBanner = /** @class */function (_super) { __extends(MDCBanner, _super); function MDCBanner() { return _super !== null && _super.apply(this, arguments) || this; } MDCBanner.attachTo = function (root) { return new MDCBanner(root); }; MDCBanner.prototype.initialize = function (focusTrapFactory) { var _this = this; if (focusTrapFactory === void 0) { focusTrapFactory = function focusTrapFactory(el, focusOptions) { return new focus_trap_1.FocusTrap(el, focusOptions); }; } this.contentEl = this.root.querySelector(constants_1.selectors.CONTENT); this.textEl = this.root.querySelector(constants_1.selectors.TEXT); this.primaryActionEl = this.root.querySelector(constants_1.selectors.PRIMARY_ACTION); this.secondaryActionEl = this.root.querySelector(constants_1.selectors.SECONDARY_ACTION); this.focusTrapFactory = focusTrapFactory; this.handleContentClick = function (evt) { var target = evt.target; if (ponyfill_1.closest(target, constants_1.selectors.PRIMARY_ACTION)) { _this.foundation.handlePrimaryActionClick(); } else if (ponyfill_1.closest(target, constants_1.selectors.SECONDARY_ACTION)) { _this.foundation.handleSecondaryActionClick(); } }; }; MDCBanner.prototype.initialSyncWithDOM = function () { this.registerContentClickHandler(this.handleContentClick); this.focusTrap = this.focusTrapFactory(this.root, { initialFocusEl: this.primaryActionEl }); }; MDCBanner.prototype.destroy = function () { _super.prototype.destroy.call(this); this.deregisterContentClickHandler(this.handleContentClick); }; MDCBanner.prototype.layout = function () { this.foundation.layout(); }; /** * Opens the banner and fires events.OPENING to indicate the beginning of its * opening animation and then events.OPENED once the animation finishes. */ MDCBanner.prototype.open = function () { this.foundation.open(); }; /** * Closes the banner and fires events.CLOSING to indicate the beginning of its * closing animation and then events.CLOSED once the animation finishes. * @param reason Why the banner was closed. Value will be passed to * events.CLOSING and events.CLOSED via the `event.detail.reason` * property. Standard values are CloseReason.PRIMARY and * CloseReason.SECONDARY, but CloseReason.UNSPECIFIED is provided for * custom handling of programmatic closing of the banner. */ MDCBanner.prototype.close = function (reason) { this.foundation.close(reason); }; MDCBanner.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 = { addClass: function addClass(className) { _this.root.classList.add(className); }, getContentHeight: function getContentHeight() { return _this.contentEl.offsetHeight; }, notifyClosed: function notifyClosed(reason) { _this.emit(constants_1.events.CLOSED, { reason: reason }); }, notifyClosing: function notifyClosing(reason) { _this.emit(constants_1.events.CLOSING, { reason: reason }); }, notifyOpened: function notifyOpened() { _this.emit(constants_1.events.OPENED, {}); }, notifyOpening: function notifyOpening() { _this.emit(constants_1.events.OPENING, {}); }, notifyActionClicked: function notifyActionClicked(action) { _this.emit(constants_1.events.ACTION_CLICKED, { action: action }); }, releaseFocus: function releaseFocus() { _this.focusTrap.releaseFocus(); }, removeClass: function removeClass(className) { _this.root.classList.remove(className); }, setStyleProperty: function setStyleProperty(propertyName, value) { _this.root.style.setProperty(propertyName, value); }, trapFocus: function trapFocus() { _this.focusTrap.trapFocus(); } }; return new foundation_1.MDCBannerFoundation(adapter); }; Object.defineProperty(MDCBanner.prototype, "isOpen", { get: function get() { return this.foundation.isOpen(); }, enumerable: false, configurable: true }); MDCBanner.prototype.getText = function () { return this.textEl.textContent || ''; }; MDCBanner.prototype.setText = function (text) { this.textEl.textContent = text; }; MDCBanner.prototype.getPrimaryActionText = function () { return this.primaryActionEl.textContent || ''; }; MDCBanner.prototype.setPrimaryActionText = function (actionButtonText) { this.primaryActionEl.textContent = actionButtonText; }; /** Returns null if the banner has no secondary action. */ MDCBanner.prototype.getSecondaryActionText = function () { return this.secondaryActionEl ? this.secondaryActionEl.textContent || '' : null; }; MDCBanner.prototype.setSecondaryActionText = function (actionButtonText) { if (this.secondaryActionEl) { this.secondaryActionEl.textContent = actionButtonText; } }; MDCBanner.prototype.registerContentClickHandler = function (handler) { this.contentEl.addEventListener('click', handler); }; MDCBanner.prototype.deregisterContentClickHandler = function (handler) { this.contentEl.removeEventListener('click', handler); }; return MDCBanner; }(component_1.MDCComponent); exports.MDCBanner = MDCBanner; /***/ }), /***/ "./packages/mdc-banner/constants.ts": /*!******************************************!*\ !*** ./packages/mdc-banner/constants.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.Action = exports.CloseReason = exports.selectors = exports.events = exports.numbers = exports.cssClasses = void 0; /** Banner element classes. */ exports.cssClasses = { CLOSING: 'mdc-banner--closing', OPEN: 'mdc-banner--open', OPENING: 'mdc-banner--opening' }; /** Banner numbers. */ exports.numbers = { BANNER_ANIMATION_CLOSE_TIME_MS: 250, BANNER_ANIMATION_OPEN_TIME_MS: 300 }; /** Banner events. */ exports.events = { CLOSED: 'MDCBanner:closed', CLOSING: 'MDCBanner:closing', OPENED: 'MDCBanner:opened', OPENING: 'MDCBanner:opening', ACTION_CLICKED: 'MDCBanner:actionClicked' }; /** Banner selectors. */ exports.selectors = { CONTENT: '.mdc-banner__content', PRIMARY_ACTION: '.mdc-banner__primary-action', SECONDARY_ACTION: '.mdc-banner__secondary-action', TEXT: '.mdc-banner__text' }; /** Reason as to why the banner was closed. */ var CloseReason; (function (CloseReason) { // Indicates the banner was closed via primary action button. CloseReason[CloseReason["PRIMARY"] = 0] = "PRIMARY"; // Indicates the banner was closed via secondary action button. CloseReason[CloseReason["SECONDARY"] = 1] = "SECONDARY"; // Will never be used by the component. Provided for custom handling of // programmatic closing of the banner. CloseReason[CloseReason["UNSPECIFIED"] = 2] = "UNSPECIFIED"; })(CloseReason = exports.CloseReason || (exports.CloseReason = {})); /** * Payload of actionClicked events to signify which action emitted the event. */ var Action; (function (Action) { Action[Action["PRIMARY"] = 0] = "PRIMARY"; Action[Action["SECONDARY"] = 1] = "SECONDARY"; Action[Action["UNKNOWN"] = 2] = "UNKNOWN"; })(Action = exports.Action || (exports.Action = {})); /***/ }), /***/ "./packages/mdc-banner/foundation.ts": /*!*******************************************!*\ !*** ./packages/mdc-banner/foundation.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. */ var __extends = this && this.__extends || function () { var _extendStatics = function extendStatics(d, b) { _extendStatics = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; } || function (d, b) { for (var p in b) { if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; } }; return _extendStatics(d, b); }; return function (d, b) { if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); _extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; }(); var __assign = this && this.__assign || function () { __assign = Object.assign || function (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); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.MDCBannerFoundation = void 0; var foundation_1 = __webpack_require__(/*! @material/base/foundation */ "./packages/mdc-base/foundation.ts"); var constants_1 = __webpack_require__(/*! ./constants */ "./packages/mdc-banner/constants.ts"); var OPENING = constants_1.cssClasses.OPENING, OPEN = constants_1.cssClasses.OPEN, CLOSING = constants_1.cssClasses.CLOSING; /** * Foundation class for banner. Responsibilities include opening and closing the * banner. */ var MDCBannerFoundation = /** @class */function (_super) { __extends(MDCBannerFoundation, _super); function MDCBannerFoundation(adapter) { var _this = _super.call(this, __assign(__assign({}, MDCBannerFoundation.defaultAdapter), adapter)) || this; _this.isOpened = false; // Request id for open animation, used to cancel the refresh callback // request on close() and destroy(). _this.animationFrame = 0; // Timer id for close and open animation, used to cancel the timer on // close() and destroy(). _this.animationTimer = 0; return _this; } Object.defineProperty(MDCBannerFoundation, "defaultAdapter", { get: function get() { return { addClass: function addClass() { return undefined; }, getContentHeight: function getContentHeight() { return 0; }, notifyClosed: function notifyClosed() { return undefined; }, notifyClosing: function notifyClosing() { return undefined; }, notifyOpened: function notifyOpened() { return undefined; }, notifyOpening: function notifyOpening() { return undefined; }, notifyActionClicked: function notifyActionClicked() { return undefined; }, releaseFocus: function releaseFocus() { return undefined; }, removeClass: function removeClass() { return undefined; }, setStyleProperty: function setStyleProperty() { return undefined; }, trapFocus: function trapFocus() { return undefined; } }; }, enumerable: false, configurable: true }); MDCBannerFoundation.prototype.destroy = function () { cancelAnimationFrame(this.animationFrame); this.animationFrame = 0; clearTimeout(this.animationTimer); this.animationTimer = 0; }; MDCBannerFoundation.prototype.open = function () { var _this = this; this.isOpened = true; this.adapter.notifyOpening(); this.adapter.removeClass(CLOSING); this.adapter.addClass(OPENING); var contentHeight = this.adapter.getContentHeight(); this.animationFrame = requestAnimationFrame(function () { _this.adapter.addClass(OPEN); _this.adapter.setStyleProperty('height', contentHeight + "px"); _this.animationTimer = setTimeout(function () { _this.handleAnimationTimerEnd(); _this.adapter.trapFocus(); _this.adapter.notifyOpened(); }, constants_1.numbers.BANNER_ANIMATION_OPEN_TIME_MS); }); }; /** * @param reason Why the banner was closed. Value will be passed to * events.CLOSING and events.CLOSED via the `event.detail.reason` * property. Standard values are CloseReason.PRIMARY and * CloseReason.SECONDARY, but CloseReason.UNSPECIFIED is provided for * custom handling of programmatic closing of the banner. */ MDCBannerFoundation.prototype.close = function (reason) { var _this = this; if (!this.isOpened) { // Avoid redundant close calls (and events), e.g. repeated interactions as // the banner is animating closed return; } cancelAnimationFrame(this.animationFrame); this.animationFrame = 0; this.isOpened = false; this.adapter.notifyClosing(reason); this.adapter.addClass(CLOSING); this.adapter.setStyleProperty('height', '0'); this.adapter.removeClass(OPEN); this.adapter.removeClass(OPENING); clearTimeout(this.animationTimer); this.animationTimer = setTimeout(function () { _this.adapter.releaseFocus(); _this.handleAnimationTimerEnd(); _this.adapter.notifyClosed(reason); }, constants_1.numbers.BANNER_ANIMATION_CLOSE_TIME_MS); }; MDCBannerFoundation.prototype.isOpen = function () { return this.isOpened; }; MDCBannerFoundation.prototype.handlePrimaryActionClick = function (disableAutoClose) { if (disableAutoClose === void 0) { disableAutoClose = false; } if (disableAutoClose) { this.adapter.notifyActionClicked(0 /* PRIMARY */); } else { this.close(constants_1.CloseReason.PRIMARY); } }; MDCBannerFoundation.prototype.handleSecondaryActionClick = function (disableAutoClose) { if (disableAutoClose === void 0) { disableAutoClose = false; } if (disableAutoClose) { this.adapter.notifyActionClicked(1 /* SECONDARY */); } else { this.close(constants_1.CloseReason.SECONDARY); } }; MDCBannerFoundation.prototype.layout = function () { var contentHeight = this.adapter.getContentHeight(); this.adapter.setStyleProperty('height', contentHeight + "px"); }; MDCBannerFoundation.prototype.handleAnimationTimerEnd = function () { this.animationTimer = 0; this.adapter.removeClass(OPENING); this.adapter.removeClass(CLOSING); }; return MDCBannerFoundation; }(foundation_1.MDCFoundation); exports.MDCBannerFoundation = MDCBannerFoundation; /***/ }), /***/ "./packages/mdc-banner/index.ts": /*!**************************************!*\ !*** ./packages/mdc-banner/index.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. */ 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 __exportStar = this && this.__exportStar || function (m, exports) { for (var p in m) { if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); } }; Object.defineProperty(exports, "__esModule", { value: true }); __exportStar(__webpack_require__(/*! ./adapter */ "./packages/mdc-banner/adapter.ts"), exports); __exportStar(__webpack_require__(/*! ./component */ "./packages/mdc-banner/component.ts"), exports); __exportStar(__webpack_require__(/*! ./constants */ "./packages/mdc-banner/constants.ts"), exports); __exportStar(__webpack_require__(/*! ./foundation */ "./packages/mdc-banner/foundation.ts"), exports); /***/ }), /***/ "./packages/mdc-base/component.ts": /*!****************************************!*\ !*** ./packages/mdc-base/component.ts ***! \****************************************/ /*! no static exports found */ /***/ (function(module, exports, __webpack_require__) { "use strict"; /** * @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 __read = this && this.__read || function (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; }; var __spreadArray = this && this.__spreadArray || function (to, from) { for (var i = 0, il = from.length, j = to.length; i < il; i++, j++) { to[j] = from[i]; }return to; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.MDCComponent = void 0; var foundation_1 = __webpack_require__(/*! ./foundation */ "./packages/mdc-base/foundation.ts"); 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, __spreadArray([], __read(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 foundation_1.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; }(); exports.MDCComponent = MDCComponent; // tslint:disable-next-line:no-default-export Needed for backward compatibility with MDC Web v0.44.0 and earlier. exports.default = MDCComponent; /***/ }), /***/ "./packages/mdc-base/foundation.ts": /*!*****************************************!*\ !*** ./packages/mdc-base/foundation.ts ***! \*****************************************/ /*! no static exports found */ /***/ (function(module, exports, __webpack_require__) { "use strict"; /** * @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. */ Object.defineProperty(exports, "__esModule", { value: true }); exports.MDCFoundation = void 0; var MDCFoundation = /** @class */function () { function MDCFoundation(adapter) { if (adapter === void 0) { adapter = {}; } this.adapter = adapter; } Object.defineProperty(MDCFoundation, "cssClasses", { get: function get() { // 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: false, configurable: true }); Object.defineProperty(MDCFoundation, "strings", { get: function get() { // 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: false, configurable: true }); Object.defineProperty(MDCFoundation, "numbers", { get: function get() { // 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: false, configurable: true }); Object.defineProperty(MDCFoundation, "defaultAdapter", { get: function get() { // 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: false, 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; }(); exports.MDCFoundation = MDCFoundation; // tslint:disable-next-line:no-default-export Needed for backward compatibility with MDC Web v0.44.0 and earlier. exports.default = MDCFoundation; /***/ }), /***/ "./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/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.banner.js.map