UNPKG

@material/checkbox

Version:
1,154 lines (1,114 loc) • 99.7 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/checkbox", [], factory); else if(typeof exports === 'object') exports["checkbox"] = factory(); else root["mdc"] = root["mdc"] || {}, root["mdc"]["checkbox"] = 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-checkbox/index.ts"); /******/ }) /************************************************************************/ /******/ ({ /***/ "./packages/mdc-animation/util.ts": /*!****************************************!*\ !*** ./packages/mdc-animation/util.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.getCorrectEventName = exports.getCorrectPropertyName = void 0; var cssPropertyNameMap = { animation: { prefixed: '-webkit-animation', standard: 'animation' }, transform: { prefixed: '-webkit-transform', standard: 'transform' }, transition: { prefixed: '-webkit-transition', standard: 'transition' } }; var jsEventTypeMap = { animationend: { cssProperty: 'animation', prefixed: 'webkitAnimationEnd', standard: 'animationend' }, animationiteration: { cssProperty: 'animation', prefixed: 'webkitAnimationIteration', standard: 'animationiteration' }, animationstart: { cssProperty: 'animation', prefixed: 'webkitAnimationStart', standard: 'animationstart' }, transitionend: { cssProperty: 'transition', prefixed: 'webkitTransitionEnd', standard: 'transitionend' } }; function isWindow(windowObj) { return Boolean(windowObj.document) && typeof windowObj.document.createElement === 'function'; } function getCorrectPropertyName(windowObj, cssProperty) { if (isWindow(windowObj) && cssProperty in cssPropertyNameMap) { var el = windowObj.document.createElement('div'); var _a = cssPropertyNameMap[cssProperty], standard = _a.standard, prefixed = _a.prefixed; var isStandard = standard in el.style; return isStandard ? standard : prefixed; } return cssProperty; } exports.getCorrectPropertyName = getCorrectPropertyName; function getCorrectEventName(windowObj, eventType) { if (isWindow(windowObj) && eventType in jsEventTypeMap) { var el = windowObj.document.createElement('div'); var _a = jsEventTypeMap[eventType], standard = _a.standard, prefixed = _a.prefixed, cssProperty = _a.cssProperty; var isStandard = cssProperty in el.style; return isStandard ? standard : prefixed; } return eventType; } exports.getCorrectEventName = getCorrectEventName; /***/ }), /***/ "./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-checkbox/adapter.ts": /*!******************************************!*\ !*** ./packages/mdc-checkbox/adapter.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 }); /***/ }), /***/ "./packages/mdc-checkbox/component.ts": /*!********************************************!*\ !*** ./packages/mdc-checkbox/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 _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; 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); }; var __values = this && this.__values || function (o) { var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0; if (m) return m.call(o); if (o && typeof o.length === "number") return { next: function next() { if (o && i >= o.length) o = void 0; return { value: o && o[i++], done: !o }; } }; throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined."); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.MDCCheckbox = void 0; var util_1 = __webpack_require__(/*! @material/animation/util */ "./packages/mdc-animation/util.ts"); var component_1 = __webpack_require__(/*! @material/base/component */ "./packages/mdc-base/component.ts"); var events_1 = __webpack_require__(/*! @material/dom/events */ "./packages/mdc-dom/events.ts"); var ponyfill_1 = __webpack_require__(/*! @material/dom/ponyfill */ "./packages/mdc-dom/ponyfill.ts"); var component_2 = __webpack_require__(/*! @material/ripple/component */ "./packages/mdc-ripple/component.ts"); var foundation_1 = __webpack_require__(/*! @material/ripple/foundation */ "./packages/mdc-ripple/foundation.ts"); var constants_1 = __webpack_require__(/*! ./constants */ "./packages/mdc-checkbox/constants.ts"); var foundation_2 = __webpack_require__(/*! ./foundation */ "./packages/mdc-checkbox/foundation.ts"); var CB_PROTO_PROPS = ['checked', 'indeterminate']; var MDCCheckbox = /** @class */function (_super) { __extends(MDCCheckbox, _super); function MDCCheckbox() { var _this = _super !== null && _super.apply(this, arguments) || this; _this.rippleSurface = _this.createRipple(); return _this; } MDCCheckbox.attachTo = function (root) { return new MDCCheckbox(root); }; Object.defineProperty(MDCCheckbox.prototype, "ripple", { get: function get() { return this.rippleSurface; }, enumerable: false, configurable: true }); Object.defineProperty(MDCCheckbox.prototype, "checked", { get: function get() { return this.getNativeControl().checked; }, set: function set(checked) { this.getNativeControl().checked = checked; }, enumerable: false, configurable: true }); Object.defineProperty(MDCCheckbox.prototype, "indeterminate", { get: function get() { return this.getNativeControl().indeterminate; }, set: function set(indeterminate) { this.getNativeControl().indeterminate = indeterminate; }, enumerable: false, configurable: true }); Object.defineProperty(MDCCheckbox.prototype, "disabled", { get: function get() { return this.getNativeControl().disabled; }, set: function set(disabled) { this.foundation.setDisabled(disabled); }, enumerable: false, configurable: true }); Object.defineProperty(MDCCheckbox.prototype, "value", { get: function get() { return this.getNativeControl().value; }, set: function set(value) { this.getNativeControl().value = value; }, enumerable: false, configurable: true }); MDCCheckbox.prototype.initialize = function () { var DATA_INDETERMINATE_ATTR = constants_1.strings.DATA_INDETERMINATE_ATTR; this.getNativeControl().indeterminate = this.getNativeControl().getAttribute(DATA_INDETERMINATE_ATTR) === 'true'; this.getNativeControl().removeAttribute(DATA_INDETERMINATE_ATTR); }; MDCCheckbox.prototype.initialSyncWithDOM = function () { var _this = this; this.handleChange = function () { _this.foundation.handleChange(); }; this.handleAnimationEnd = function () { _this.foundation.handleAnimationEnd(); }; this.getNativeControl().addEventListener('change', this.handleChange); this.listen(util_1.getCorrectEventName(window, 'animationend'), this.handleAnimationEnd); this.installPropertyChangeHooks(); }; MDCCheckbox.prototype.destroy = function () { this.rippleSurface.destroy(); this.getNativeControl().removeEventListener('change', this.handleChange); this.unlisten(util_1.getCorrectEventName(window, 'animationend'), this.handleAnimationEnd); this.uninstallPropertyChangeHooks(); _super.prototype.destroy.call(this); }; MDCCheckbox.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) { return _this.root.classList.add(className); }, forceLayout: function forceLayout() { return _this.root.offsetWidth; }, hasNativeControl: function hasNativeControl() { return !!_this.getNativeControl(); }, isAttachedToDOM: function isAttachedToDOM() { return Boolean(_this.root.parentNode); }, isChecked: function isChecked() { return _this.checked; }, isIndeterminate: function isIndeterminate() { return _this.indeterminate; }, removeClass: function removeClass(className) { _this.root.classList.remove(className); }, removeNativeControlAttr: function removeNativeControlAttr(attr) { _this.getNativeControl().removeAttribute(attr); }, setNativeControlAttr: function setNativeControlAttr(attr, value) { _this.getNativeControl().setAttribute(attr, value); }, setNativeControlDisabled: function setNativeControlDisabled(disabled) { _this.getNativeControl().disabled = disabled; } }; return new foundation_2.MDCCheckboxFoundation(adapter); }; MDCCheckbox.prototype.createRipple = 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 = __assign(__assign({}, component_2.MDCRipple.createAdapter(this)), { deregisterInteractionHandler: function deregisterInteractionHandler(evtType, handler) { _this.getNativeControl().removeEventListener(evtType, handler, events_1.applyPassive()); }, isSurfaceActive: function isSurfaceActive() { return ponyfill_1.matches(_this.getNativeControl(), ':active'); }, isUnbounded: function isUnbounded() { return true; }, registerInteractionHandler: function registerInteractionHandler(evtType, handler) { _this.getNativeControl().addEventListener(evtType, handler, events_1.applyPassive()); } }); return new component_2.MDCRipple(this.root, new foundation_1.MDCRippleFoundation(adapter)); }; MDCCheckbox.prototype.installPropertyChangeHooks = function () { var e_1, _a; var _this = this; var nativeCb = this.getNativeControl(); var cbProto = Object.getPrototypeOf(nativeCb); var _loop_1 = function _loop_1(controlState) { var desc = Object.getOwnPropertyDescriptor(cbProto, controlState); // We have to check for this descriptor, since some browsers (Safari) don't support its return. // See: https://bugs.webkit.org/show_bug.cgi?id=49739 if (!validDescriptor(desc)) { return { value: void 0 }; } // Type cast is needed for compatibility with Closure Compiler. var nativeGetter = desc.get; var nativeCbDesc = { configurable: desc.configurable, enumerable: desc.enumerable, get: nativeGetter, set: function set(state) { desc.set.call(nativeCb, state); _this.foundation.handleChange(); } }; Object.defineProperty(nativeCb, controlState, nativeCbDesc); }; try { for (var CB_PROTO_PROPS_1 = __values(CB_PROTO_PROPS), CB_PROTO_PROPS_1_1 = CB_PROTO_PROPS_1.next(); !CB_PROTO_PROPS_1_1.done; CB_PROTO_PROPS_1_1 = CB_PROTO_PROPS_1.next()) { var controlState = CB_PROTO_PROPS_1_1.value; var state_1 = _loop_1(controlState); if ((typeof state_1 === "undefined" ? "undefined" : _typeof(state_1)) === "object") return state_1.value; } } catch (e_1_1) { e_1 = { error: e_1_1 }; } finally { try { if (CB_PROTO_PROPS_1_1 && !CB_PROTO_PROPS_1_1.done && (_a = CB_PROTO_PROPS_1.return)) _a.call(CB_PROTO_PROPS_1); } finally { if (e_1) throw e_1.error; } } }; MDCCheckbox.prototype.uninstallPropertyChangeHooks = function () { var e_2, _a; var nativeCb = this.getNativeControl(); var cbProto = Object.getPrototypeOf(nativeCb); try { for (var CB_PROTO_PROPS_2 = __values(CB_PROTO_PROPS), CB_PROTO_PROPS_2_1 = CB_PROTO_PROPS_2.next(); !CB_PROTO_PROPS_2_1.done; CB_PROTO_PROPS_2_1 = CB_PROTO_PROPS_2.next()) { var controlState = CB_PROTO_PROPS_2_1.value; var desc = Object.getOwnPropertyDescriptor(cbProto, controlState); if (!validDescriptor(desc)) { return; } Object.defineProperty(nativeCb, controlState, desc); } } catch (e_2_1) { e_2 = { error: e_2_1 }; } finally { try { if (CB_PROTO_PROPS_2_1 && !CB_PROTO_PROPS_2_1.done && (_a = CB_PROTO_PROPS_2.return)) _a.call(CB_PROTO_PROPS_2); } finally { if (e_2) throw e_2.error; } } }; MDCCheckbox.prototype.getNativeControl = function () { var NATIVE_CONTROL_SELECTOR = constants_1.strings.NATIVE_CONTROL_SELECTOR; var el = this.root.querySelector(NATIVE_CONTROL_SELECTOR); if (!el) { throw new Error("Checkbox component requires a " + NATIVE_CONTROL_SELECTOR + " element"); } return el; }; return MDCCheckbox; }(component_1.MDCComponent); exports.MDCCheckbox = MDCCheckbox; function validDescriptor(inputPropDesc) { return !!inputPropDesc && typeof inputPropDesc.set === 'function'; } /***/ }), /***/ "./packages/mdc-checkbox/constants.ts": /*!********************************************!*\ !*** ./packages/mdc-checkbox/constants.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.numbers = exports.strings = exports.cssClasses = void 0; exports.cssClasses = { ANIM_CHECKED_INDETERMINATE: 'mdc-checkbox--anim-checked-indeterminate', ANIM_CHECKED_UNCHECKED: 'mdc-checkbox--anim-checked-unchecked', ANIM_INDETERMINATE_CHECKED: 'mdc-checkbox--anim-indeterminate-checked', ANIM_INDETERMINATE_UNCHECKED: 'mdc-checkbox--anim-indeterminate-unchecked', ANIM_UNCHECKED_CHECKED: 'mdc-checkbox--anim-unchecked-checked', ANIM_UNCHECKED_INDETERMINATE: 'mdc-checkbox--anim-unchecked-indeterminate', BACKGROUND: 'mdc-checkbox__background', CHECKED: 'mdc-checkbox--checked', CHECKMARK: 'mdc-checkbox__checkmark', CHECKMARK_PATH: 'mdc-checkbox__checkmark-path', DISABLED: 'mdc-checkbox--disabled', INDETERMINATE: 'mdc-checkbox--indeterminate', MIXEDMARK: 'mdc-checkbox__mixedmark', NATIVE_CONTROL: 'mdc-checkbox__native-control', ROOT: 'mdc-checkbox', SELECTED: 'mdc-checkbox--selected', UPGRADED: 'mdc-checkbox--upgraded' }; exports.strings = { ARIA_CHECKED_ATTR: 'aria-checked', ARIA_CHECKED_INDETERMINATE_VALUE: 'mixed', DATA_INDETERMINATE_ATTR: 'data-indeterminate', NATIVE_CONTROL_SELECTOR: '.mdc-checkbox__native-control', TRANSITION_STATE_CHECKED: 'checked', TRANSITION_STATE_INDETERMINATE: 'indeterminate', TRANSITION_STATE_INIT: 'init', TRANSITION_STATE_UNCHECKED: 'unchecked' }; exports.numbers = { ANIM_END_LATCH_MS: 250 }; /***/ }), /***/ "./packages/mdc-checkbox/foundation.ts": /*!*********************************************!*\ !*** ./packages/mdc-checkbox/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. */ 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.MDCCheckboxFoundation = void 0; var foundation_1 = __webpack_require__(/*! @material/base/foundation */ "./packages/mdc-base/foundation.ts"); var constants_1 = __webpack_require__(/*! ./constants */ "./packages/mdc-checkbox/constants.ts"); var MDCCheckboxFoundation = /** @class */function (_super) { __extends(MDCCheckboxFoundation, _super); function MDCCheckboxFoundation(adapter) { var _this = _super.call(this, __assign(__assign({}, MDCCheckboxFoundation.defaultAdapter), adapter)) || this; _this.currentCheckState = constants_1.strings.TRANSITION_STATE_INIT; _this.currentAnimationClass = ''; _this.animEndLatchTimer = 0; _this.enableAnimationEndHandler = false; return _this; } Object.defineProperty(MDCCheckboxFoundation, "cssClasses", { get: function get() { return constants_1.cssClasses; }, enumerable: false, configurable: true }); Object.defineProperty(MDCCheckboxFoundation, "strings", { get: function get() { return constants_1.strings; }, enumerable: false, configurable: true }); Object.defineProperty(MDCCheckboxFoundation, "numbers", { get: function get() { return constants_1.numbers; }, enumerable: false, configurable: true }); Object.defineProperty(MDCCheckboxFoundation, "defaultAdapter", { get: function get() { return { addClass: function addClass() { return undefined; }, forceLayout: function forceLayout() { return undefined; }, hasNativeControl: function hasNativeControl() { return false; }, isAttachedToDOM: function isAttachedToDOM() { return false; }, isChecked: function isChecked() { return false; }, isIndeterminate: function isIndeterminate() { return false; }, removeClass: function removeClass() { return undefined; }, removeNativeControlAttr: function removeNativeControlAttr() { return undefined; }, setNativeControlAttr: function setNativeControlAttr() { return undefined; }, setNativeControlDisabled: function setNativeControlDisabled() { return undefined; } }; }, enumerable: false, configurable: true }); MDCCheckboxFoundation.prototype.init = function () { this.currentCheckState = this.determineCheckState(); this.updateAriaChecked(); this.adapter.addClass(constants_1.cssClasses.UPGRADED); }; MDCCheckboxFoundation.prototype.destroy = function () { clearTimeout(this.animEndLatchTimer); }; MDCCheckboxFoundation.prototype.setDisabled = function (disabled) { this.adapter.setNativeControlDisabled(disabled); if (disabled) { this.adapter.addClass(constants_1.cssClasses.DISABLED); } else { this.adapter.removeClass(constants_1.cssClasses.DISABLED); } }; /** * Handles the animationend event for the checkbox */ MDCCheckboxFoundation.prototype.handleAnimationEnd = function () { var _this = this; if (!this.enableAnimationEndHandler) { return; } clearTimeout(this.animEndLatchTimer); this.animEndLatchTimer = setTimeout(function () { _this.adapter.removeClass(_this.currentAnimationClass); _this.enableAnimationEndHandler = false; }, constants_1.numbers.ANIM_END_LATCH_MS); }; /** * Handles the change event for the checkbox */ MDCCheckboxFoundation.prototype.handleChange = function () { this.transitionCheckState(); }; MDCCheckboxFoundation.prototype.transitionCheckState = function () { if (!this.adapter.hasNativeControl()) { return; } var oldState = this.currentCheckState; var newState = this.determineCheckState(); if (oldState === newState) { return; } this.updateAriaChecked(); var TRANSITION_STATE_UNCHECKED = constants_1.strings.TRANSITION_STATE_UNCHECKED; var SELECTED = constants_1.cssClasses.SELECTED; if (newState === TRANSITION_STATE_UNCHECKED) { this.adapter.removeClass(SELECTED); } else { this.adapter.addClass(SELECTED); } // Check to ensure that there isn't a previously existing animation class, in case for example // the user interacted with the checkbox before the animation was finished. if (this.currentAnimationClass.length > 0) { clearTimeout(this.animEndLatchTimer); this.adapter.forceLayout(); this.adapter.removeClass(this.currentAnimationClass); } this.currentAnimationClass = this.getTransitionAnimationClass(oldState, newState); this.currentCheckState = newState; // Check for parentNode so that animations are only run when the element is attached // to the DOM. if (this.adapter.isAttachedToDOM() && this.currentAnimationClass.length > 0) { this.adapter.addClass(this.currentAnimationClass); this.enableAnimationEndHandler = true; } }; MDCCheckboxFoundation.prototype.determineCheckState = function () { var TRANSITION_STATE_INDETERMINATE = constants_1.strings.TRANSITION_STATE_INDETERMINATE, TRANSITION_STATE_CHECKED = constants_1.strings.TRANSITION_STATE_CHECKED, TRANSITION_STATE_UNCHECKED = constants_1.strings.TRANSITION_STATE_UNCHECKED; if (this.adapter.isIndeterminate()) { return TRANSITION_STATE_INDETERMINATE; } return this.adapter.isChecked() ? TRANSITION_STATE_CHECKED : TRANSITION_STATE_UNCHECKED; }; MDCCheckboxFoundation.prototype.getTransitionAnimationClass = function (oldState, newState) { var TRANSITION_STATE_INIT = constants_1.strings.TRANSITION_STATE_INIT, TRANSITION_STATE_CHECKED = constants_1.strings.TRANSITION_STATE_CHECKED, TRANSITION_STATE_UNCHECKED = constants_1.strings.TRANSITION_STATE_UNCHECKED; var _a = MDCCheckboxFoundation.cssClasses, ANIM_UNCHECKED_CHECKED = _a.ANIM_UNCHECKED_CHECKED, ANIM_UNCHECKED_INDETERMINATE = _a.ANIM_UNCHECKED_INDETERMINATE, ANIM_CHECKED_UNCHECKED = _a.ANIM_CHECKED_UNCHECKED, ANIM_CHECKED_INDETERMINATE = _a.ANIM_CHECKED_INDETERMINATE, ANIM_INDETERMINATE_CHECKED = _a.ANIM_INDETERMINATE_CHECKED, ANIM_INDETERMINATE_UNCHECKED = _a.ANIM_INDETERMINATE_UNCHECKED; switch (oldState) { case TRANSITION_STATE_INIT: if (newState === TRANSITION_STATE_UNCHECKED) { return ''; } return newState === TRANSITION_STATE_CHECKED ? ANIM_INDETERMINATE_CHECKED : ANIM_INDETERMINATE_UNCHECKED; case TRANSITION_STATE_UNCHECKED: return newState === TRANSITION_STATE_CHECKED ? ANIM_UNCHECKED_CHECKED : ANIM_UNCHECKED_INDETERMINATE; case TRANSITION_STATE_CHECKED: return newState === TRANSITION_STATE_UNCHECKED ? ANIM_CHECKED_UNCHECKED : ANIM_CHECKED_INDETERMINATE; default: // TRANSITION_STATE_INDETERMINATE return newState === TRANSITION_STATE_CHECKED ? ANIM_INDETERMINATE_CHECKED : ANIM_INDETERMINATE_UNCHECKED; } }; MDCCheckboxFoundation.prototype.updateAriaChecked = function () { // Ensure aria-checked is set to mixed if checkbox is in indeterminate state. if (this.adapter.isIndeterminate()) { this.adapter.setNativeControlAttr(constants_1.strings.ARIA_CHECKED_ATTR, constants_1.strings.ARIA_CHECKED_INDETERMINATE_VALUE); } else { // The on/off state does not need to keep track of aria-checked, since // the screenreader uses the checked property on the checkbox element. this.adapter.removeNativeControlAttr(constants_1.strings.ARIA_CHECKED_ATTR); } }; return MDCCheckboxFoundation; }(foundation_1.MDCFoundation); exports.MDCCheckboxFoundation = MDCCheckboxFoundation; // tslint:disable-next-line:no-default-export Needed for backward compatibility with MDC Web v0.44.0 and earlier. exports.default = MDCCheckboxFoundation; /***/ }), /***/ "./packages/mdc-checkbox/index.ts": /*!****************************************!*\ !*** ./packages/mdc-checkbox/index.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. */ 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 !==