@angular/material
Version:
Angular Material
1,289 lines (1,273 loc) • 85.3 kB
JavaScript
/**
* @license
* Copyright Google Inc. 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://angular.io/license
*/
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/common'), require('@angular/core'), require('@angular/cdk/platform'), require('@angular/animations'), require('@angular/cdk/coercion'), require('@angular/cdk/rxjs'), require('@angular/cdk/bidi'), require('rxjs/Subject'), require('@angular/platform-browser'), require('@angular/cdk/keycodes'), require('rxjs/observable/fromEvent')) :
typeof define === 'function' && define.amd ? define(['exports', '@angular/common', '@angular/core', '@angular/cdk/platform', '@angular/animations', '@angular/cdk/coercion', '@angular/cdk/rxjs', '@angular/cdk/bidi', 'rxjs/Subject', '@angular/platform-browser', '@angular/cdk/keycodes', 'rxjs/observable/fromEvent'], factory) :
(factory((global.ng = global.ng || {}, global.ng.material = global.ng.material || {}, global.ng.material['form-field'] = global.ng.material['form-field'] || {}),global.ng.common,global.ng.core,global.ng.cdk.platform,global.ng.animations,global.ng.cdk.coercion,global.ng.cdk.rxjs,global.ng.cdk.bidi,global.Rx,global.ng.platformBrowser,global.ng.cdk.keycodes,global.Rx.Observable));
}(this, (function (exports,_angular_common,_angular_core,_angular_cdk_platform,_angular_animations,_angular_cdk_coercion,_angular_cdk_rxjs,_angular_cdk_bidi,rxjs_Subject,_angular_platformBrowser,_angular_cdk_keycodes,rxjs_observable_fromEvent) { 'use strict';
/*! *****************************************************************************
Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at http://www.apache.org/licenses/LICENSE-2.0
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
MERCHANTABLITY OR NON-INFRINGEMENT.
See the Apache Version 2.0 License for specific language governing permissions
and limitations under the License.
***************************************************************************** */
/* global Reflect, Promise */
var extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
function __extends(d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
}
var MATERIAL_COMPATIBILITY_MODE = new _angular_core.InjectionToken('md-compatibility-mode');
/**
* Injection token that configures whether the Material sanity checks are enabled.
*/
var MATERIAL_SANITY_CHECKS = new _angular_core.InjectionToken('mat-sanity-checks');
/**
* Mixin to augment a directive with a `disabled` property.
* @template T
* @param {?} base
* @return {?}
*/
function mixinDisabled(base) {
return (function (_super) {
__extends(class_1, _super);
/**
* @param {...?} args
*/
function class_1() {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
var _this = _super.apply(this, args) || this;
_this._disabled = false;
return _this;
}
Object.defineProperty(class_1.prototype, "disabled", {
/**
* @return {?}
*/
get: function () { return this._disabled; },
/**
* @param {?} value
* @return {?}
*/
set: function (value) { this._disabled = _angular_cdk_coercion.coerceBooleanProperty(value); },
enumerable: true,
configurable: true
});
return class_1;
}(base));
}
/**
* InjectionToken for datepicker that can be used to override default locale code.
*/
var MAT_DATE_LOCALE = new _angular_core.InjectionToken('MAT_DATE_LOCALE');
/**
* Adapts type `D` to be usable as a date by cdk-based components that work with dates.
* @abstract
*/
var DateAdapter = (function () {
function DateAdapter() {
this._localeChanges = new rxjs_Subject.Subject();
}
Object.defineProperty(DateAdapter.prototype, "localeChanges", {
/**
* A stream that emits when the locale changes.
* @return {?}
*/
get: function () { return this._localeChanges; },
enumerable: true,
configurable: true
});
/**
* Gets the year component of the given date.
* @abstract
* @param {?} date The date to extract the year from.
* @return {?} The year component.
*/
DateAdapter.prototype.getYear = function (date) { };
/**
* Gets the month component of the given date.
* @abstract
* @param {?} date The date to extract the month from.
* @return {?} The month component (0-indexed, 0 = January).
*/
DateAdapter.prototype.getMonth = function (date) { };
/**
* Gets the date of the month component of the given date.
* @abstract
* @param {?} date The date to extract the date of the month from.
* @return {?} The month component (1-indexed, 1 = first of month).
*/
DateAdapter.prototype.getDate = function (date) { };
/**
* Gets the day of the week component of the given date.
* @abstract
* @param {?} date The date to extract the day of the week from.
* @return {?} The month component (0-indexed, 0 = Sunday).
*/
DateAdapter.prototype.getDayOfWeek = function (date) { };
/**
* Gets a list of names for the months.
* @abstract
* @param {?} style The naming style (e.g. long = 'January', short = 'Jan', narrow = 'J').
* @return {?} An ordered list of all month names, starting with January.
*/
DateAdapter.prototype.getMonthNames = function (style$$1) { };
/**
* Gets a list of names for the dates of the month.
* @abstract
* @return {?} An ordered list of all date of the month names, starting with '1'.
*/
DateAdapter.prototype.getDateNames = function () { };
/**
* Gets a list of names for the days of the week.
* @abstract
* @param {?} style The naming style (e.g. long = 'Sunday', short = 'Sun', narrow = 'S').
* @return {?} An ordered list of all weekday names, starting with Sunday.
*/
DateAdapter.prototype.getDayOfWeekNames = function (style$$1) { };
/**
* Gets the name for the year of the given date.
* @abstract
* @param {?} date The date to get the year name for.
* @return {?} The name of the given year (e.g. '2017').
*/
DateAdapter.prototype.getYearName = function (date) { };
/**
* Gets the first day of the week.
* @abstract
* @return {?} The first day of the week (0-indexed, 0 = Sunday).
*/
DateAdapter.prototype.getFirstDayOfWeek = function () { };
/**
* Gets the number of days in the month of the given date.
* @abstract
* @param {?} date The date whose month should be checked.
* @return {?} The number of days in the month of the given date.
*/
DateAdapter.prototype.getNumDaysInMonth = function (date) { };
/**
* Clones the given date.
* @abstract
* @param {?} date The date to clone
* @return {?} A new date equal to the given date.
*/
DateAdapter.prototype.clone = function (date) { };
/**
* Creates a date with the given year, month, and date. Does not allow over/under-flow of the
* month and date.
* @abstract
* @param {?} year The full year of the date. (e.g. 89 means the year 89, not the year 1989).
* @param {?} month The month of the date (0-indexed, 0 = January). Must be an integer 0 - 11.
* @param {?} date The date of month of the date. Must be an integer 1 - length of the given month.
* @return {?} The new date, or null if invalid.
*/
DateAdapter.prototype.createDate = function (year, month, date) { };
/**
* Gets today's date.
* @abstract
* @return {?} Today's date.
*/
DateAdapter.prototype.today = function () { };
/**
* Parses a date from a value.
* @abstract
* @param {?} value The value to parse.
* @param {?} parseFormat The expected format of the value being parsed
* (type is implementation-dependent).
* @return {?} The parsed date.
*/
DateAdapter.prototype.parse = function (value, parseFormat) { };
/**
* Formats a date as a string.
* @abstract
* @param {?} date The value to format.
* @param {?} displayFormat The format to use to display the date as a string.
* @return {?} The formatted date string.
*/
DateAdapter.prototype.format = function (date, displayFormat) { };
/**
* Adds the given number of years to the date. Years are counted as if flipping 12 pages on the
* calendar for each year and then finding the closest date in the new month. For example when
* adding 1 year to Feb 29, 2016, the resulting date will be Feb 28, 2017.
* @abstract
* @param {?} date The date to add years to.
* @param {?} years The number of years to add (may be negative).
* @return {?} A new date equal to the given one with the specified number of years added.
*/
DateAdapter.prototype.addCalendarYears = function (date, years) { };
/**
* Adds the given number of months to the date. Months are counted as if flipping a page on the
* calendar for each month and then finding the closest date in the new month. For example when
* adding 1 month to Jan 31, 2017, the resulting date will be Feb 28, 2017.
* @abstract
* @param {?} date The date to add months to.
* @param {?} months The number of months to add (may be negative).
* @return {?} A new date equal to the given one with the specified number of months added.
*/
DateAdapter.prototype.addCalendarMonths = function (date, months) { };
/**
* Adds the given number of days to the date. Days are counted as if moving one cell on the
* calendar for each day.
* @abstract
* @param {?} date The date to add days to.
* @param {?} days The number of days to add (may be negative).
* @return {?} A new date equal to the given one with the specified number of days added.
*/
DateAdapter.prototype.addCalendarDays = function (date, days) { };
/**
* Gets the RFC 3339 compatible string (https://tools.ietf.org/html/rfc3339) for the given date.
* @abstract
* @param {?} date The date to get the ISO date string for.
* @return {?} The ISO date string date string.
*/
DateAdapter.prototype.toIso8601 = function (date) { };
/**
* Creates a date from an RFC 3339 compatible string (https://tools.ietf.org/html/rfc3339).
* @abstract
* @param {?} iso8601String The ISO date string to create a date from
* @return {?} The date created from the ISO date string.
*/
DateAdapter.prototype.fromIso8601 = function (iso8601String) { };
/**
* Checks whether the given object is considered a date instance by this DateAdapter.
* @abstract
* @param {?} obj The object to check
* @return {?} Whether the object is a date instance.
*/
DateAdapter.prototype.isDateInstance = function (obj) { };
/**
* Checks whether the given date is valid.
* @abstract
* @param {?} date The date to check.
* @return {?} Whether the date is valid.
*/
DateAdapter.prototype.isValid = function (date) { };
/**
* Sets the locale used for all dates.
* @param {?} locale The new locale.
* @return {?}
*/
DateAdapter.prototype.setLocale = function (locale) {
this.locale = locale;
this._localeChanges.next();
};
/**
* Compares two dates.
* @param {?} first The first date to compare.
* @param {?} second The second date to compare.
* @return {?} 0 if the dates are equal, a number less than 0 if the first date is earlier,
* a number greater than 0 if the first date is later.
*/
DateAdapter.prototype.compareDate = function (first$$1, second) {
return this.getYear(first$$1) - this.getYear(second) ||
this.getMonth(first$$1) - this.getMonth(second) ||
this.getDate(first$$1) - this.getDate(second);
};
/**
* Checks if two dates are equal.
* @param {?} first The first date to check.
* @param {?} second The second date to check.
* Null dates are considered equal to other null dates.
* @return {?}
*/
DateAdapter.prototype.sameDate = function (first$$1, second) {
return first$$1 && second ? !this.compareDate(first$$1, second) : first$$1 == second;
};
/**
* Clamp the given date between min and max dates.
* @param {?} date The date to clamp.
* @param {?=} min The minimum value to allow. If null or omitted no min is enforced.
* @param {?=} max The maximum value to allow. If null or omitted no max is enforced.
* @return {?} `min` if `date` is less than `min`, `max` if date is greater than `max`,
* otherwise `date`.
*/
DateAdapter.prototype.clampDate = function (date, min, max) {
if (min && this.compareDate(date, min) < 0) {
return min;
}
if (max && this.compareDate(date, max) > 0) {
return max;
}
return date;
};
return DateAdapter;
}());
/**
* Extends an object with the *enumerable* and *own* properties of one or more source objects,
* similar to Object.assign.
*
* @param {?} dest The object which will have properties copied to it.
* @param {...?} sources The source objects from which properties will be copied.
* @return {?}
*/
function extendObject(dest) {
var sources = [];
for (var _i = 1; _i < arguments.length; _i++) {
sources[_i - 1] = arguments[_i];
}
if (dest == null) {
throw TypeError('Cannot convert undefined or null to object');
}
for (var _a = 0, sources_1 = sources; _a < sources_1.length; _a++) {
var source = sources_1[_a];
if (source != null) {
for (var /** @type {?} */ key in source) {
if (source.hasOwnProperty(key)) {
dest[key] = source[key];
}
}
}
}
return dest;
}
/**
* Whether the browser supports the Intl API.
*/
var SUPPORTS_INTL_API = typeof Intl != 'undefined';
/**
* The default month names to use if Intl API is not available.
*/
var DEFAULT_MONTH_NAMES = {
'long': [
'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September',
'October', 'November', 'December'
],
'short': ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
'narrow': ['J', 'F', 'M', 'A', 'M', 'J', 'J', 'A', 'S', 'O', 'N', 'D']
};
/**
* The default date names to use if Intl API is not available.
*/
var DEFAULT_DATE_NAMES = range(31, function (i) { return String(i + 1); });
/**
* The default day of the week names to use if Intl API is not available.
*/
var DEFAULT_DAY_OF_WEEK_NAMES = {
'long': ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],
'short': ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
'narrow': ['S', 'M', 'T', 'W', 'T', 'F', 'S']
};
/**
* Matches strings that have the form of a valid RFC 3339 string
* (https://tools.ietf.org/html/rfc3339). Note that the string may not actually be a valid date
* because the regex will match strings an with out of bounds month, date, etc.
*/
var ISO_8601_REGEX = /^\d{4}-\d{2}-\d{2}(?:T\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|(?:(?:\+|-)\d{2}:\d{2}))?)?$/;
/**
* Creates an array and fills it with values.
* @template T
* @param {?} length
* @param {?} valueFunction
* @return {?}
*/
function range(length, valueFunction) {
var /** @type {?} */ valuesArray = Array(length);
for (var /** @type {?} */ i = 0; i < length; i++) {
valuesArray[i] = valueFunction(i);
}
return valuesArray;
}
/**
* Adapts the native JS Date for use with cdk-based components that work with dates.
*/
var NativeDateAdapter = (function (_super) {
__extends(NativeDateAdapter, _super);
/**
* @param {?} matDateLocale
*/
function NativeDateAdapter(matDateLocale) {
var _this = _super.call(this) || this;
/**
* Whether to use `timeZone: 'utc'` with `Intl.DateTimeFormat` when formatting dates.
* Without this `Intl.DateTimeFormat` sometimes chooses the wrong timeZone, which can throw off
* the result. (e.g. in the en-US locale `new Date(1800, 7, 14).toLocaleDateString()`
* will produce `'8/13/1800'`.
*/
_this.useUtcForDisplay = true;
_super.prototype.setLocale.call(_this, matDateLocale);
return _this;
}
/**
* @param {?} date
* @return {?}
*/
NativeDateAdapter.prototype.getYear = function (date) {
return date.getFullYear();
};
/**
* @param {?} date
* @return {?}
*/
NativeDateAdapter.prototype.getMonth = function (date) {
return date.getMonth();
};
/**
* @param {?} date
* @return {?}
*/
NativeDateAdapter.prototype.getDate = function (date) {
return date.getDate();
};
/**
* @param {?} date
* @return {?}
*/
NativeDateAdapter.prototype.getDayOfWeek = function (date) {
return date.getDay();
};
/**
* @param {?} style
* @return {?}
*/
NativeDateAdapter.prototype.getMonthNames = function (style$$1) {
var _this = this;
if (SUPPORTS_INTL_API) {
var /** @type {?} */ dtf_1 = new Intl.DateTimeFormat(this.locale, { month: style$$1 });
return range(12, function (i) { return _this._stripDirectionalityCharacters(dtf_1.format(new Date(2017, i, 1))); });
}
return DEFAULT_MONTH_NAMES[style$$1];
};
/**
* @return {?}
*/
NativeDateAdapter.prototype.getDateNames = function () {
var _this = this;
if (SUPPORTS_INTL_API) {
var /** @type {?} */ dtf_2 = new Intl.DateTimeFormat(this.locale, { day: 'numeric' });
return range(31, function (i) { return _this._stripDirectionalityCharacters(dtf_2.format(new Date(2017, 0, i + 1))); });
}
return DEFAULT_DATE_NAMES;
};
/**
* @param {?} style
* @return {?}
*/
NativeDateAdapter.prototype.getDayOfWeekNames = function (style$$1) {
var _this = this;
if (SUPPORTS_INTL_API) {
var /** @type {?} */ dtf_3 = new Intl.DateTimeFormat(this.locale, { weekday: style$$1 });
return range(7, function (i) { return _this._stripDirectionalityCharacters(dtf_3.format(new Date(2017, 0, i + 1))); });
}
return DEFAULT_DAY_OF_WEEK_NAMES[style$$1];
};
/**
* @param {?} date
* @return {?}
*/
NativeDateAdapter.prototype.getYearName = function (date) {
if (SUPPORTS_INTL_API) {
var /** @type {?} */ dtf = new Intl.DateTimeFormat(this.locale, { year: 'numeric' });
return this._stripDirectionalityCharacters(dtf.format(date));
}
return String(this.getYear(date));
};
/**
* @return {?}
*/
NativeDateAdapter.prototype.getFirstDayOfWeek = function () {
// We can't tell using native JS Date what the first day of the week is, we default to Sunday.
return 0;
};
/**
* @param {?} date
* @return {?}
*/
NativeDateAdapter.prototype.getNumDaysInMonth = function (date) {
return this.getDate(this._createDateWithOverflow(this.getYear(date), this.getMonth(date) + 1, 0));
};
/**
* @param {?} date
* @return {?}
*/
NativeDateAdapter.prototype.clone = function (date) {
return this.createDate(this.getYear(date), this.getMonth(date), this.getDate(date));
};
/**
* @param {?} year
* @param {?} month
* @param {?} date
* @return {?}
*/
NativeDateAdapter.prototype.createDate = function (year, month, date) {
// Check for invalid month and date (except upper bound on date which we have to check after
// creating the Date).
if (month < 0 || month > 11) {
throw Error("Invalid month index \"" + month + "\". Month index has to be between 0 and 11.");
}
if (date < 1) {
throw Error("Invalid date \"" + date + "\". Date has to be greater than 0.");
}
var /** @type {?} */ result = this._createDateWithOverflow(year, month, date);
// Check that the date wasn't above the upper bound for the month, causing the month to overflow
if (result.getMonth() != month) {
throw Error("Invalid date \"" + date + "\" for month with index \"" + month + "\".");
}
return result;
};
/**
* @return {?}
*/
NativeDateAdapter.prototype.today = function () {
return new Date();
};
/**
* @param {?} value
* @return {?}
*/
NativeDateAdapter.prototype.parse = function (value) {
// We have no way using the native JS Date to set the parse format or locale, so we ignore these
// parameters.
if (typeof value == 'number') {
return new Date(value);
}
return value ? new Date(Date.parse(value)) : null;
};
/**
* @param {?} date
* @param {?} displayFormat
* @return {?}
*/
NativeDateAdapter.prototype.format = function (date, displayFormat) {
if (!this.isValid(date)) {
throw Error('NativeDateAdapter: Cannot format invalid date.');
}
if (SUPPORTS_INTL_API) {
if (this.useUtcForDisplay) {
date = new Date(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate(), date.getHours(), date.getMinutes(), date.getSeconds(), date.getMilliseconds()));
displayFormat = extendObject({}, displayFormat, { timeZone: 'utc' });
}
var /** @type {?} */ dtf = new Intl.DateTimeFormat(this.locale, displayFormat);
return this._stripDirectionalityCharacters(dtf.format(date));
}
return this._stripDirectionalityCharacters(date.toDateString());
};
/**
* @param {?} date
* @param {?} years
* @return {?}
*/
NativeDateAdapter.prototype.addCalendarYears = function (date, years) {
return this.addCalendarMonths(date, years * 12);
};
/**
* @param {?} date
* @param {?} months
* @return {?}
*/
NativeDateAdapter.prototype.addCalendarMonths = function (date, months) {
var /** @type {?} */ newDate = this._createDateWithOverflow(this.getYear(date), this.getMonth(date) + months, this.getDate(date));
// It's possible to wind up in the wrong month if the original month has more days than the new
// month. In this case we want to go to the last day of the desired month.
// Note: the additional + 12 % 12 ensures we end up with a positive number, since JS % doesn't
// guarantee this.
if (this.getMonth(newDate) != ((this.getMonth(date) + months) % 12 + 12) % 12) {
newDate = this._createDateWithOverflow(this.getYear(newDate), this.getMonth(newDate), 0);
}
return newDate;
};
/**
* @param {?} date
* @param {?} days
* @return {?}
*/
NativeDateAdapter.prototype.addCalendarDays = function (date, days) {
return this._createDateWithOverflow(this.getYear(date), this.getMonth(date), this.getDate(date) + days);
};
/**
* @param {?} date
* @return {?}
*/
NativeDateAdapter.prototype.toIso8601 = function (date) {
return [
date.getUTCFullYear(),
this._2digit(date.getUTCMonth() + 1),
this._2digit(date.getUTCDate())
].join('-');
};
/**
* @param {?} iso8601String
* @return {?}
*/
NativeDateAdapter.prototype.fromIso8601 = function (iso8601String) {
// The `Date` constructor accepts formats other than ISO 8601, so we need to make sure the
// string is the right format first.
if (ISO_8601_REGEX.test(iso8601String)) {
var /** @type {?} */ d = new Date(iso8601String);
if (this.isValid(d)) {
return d;
}
}
return null;
};
/**
* @param {?} obj
* @return {?}
*/
NativeDateAdapter.prototype.isDateInstance = function (obj) {
return obj instanceof Date;
};
/**
* @param {?} date
* @return {?}
*/
NativeDateAdapter.prototype.isValid = function (date) {
return !isNaN(date.getTime());
};
/**
* Creates a date but allows the month and date to overflow.
* @param {?} year
* @param {?} month
* @param {?} date
* @return {?}
*/
NativeDateAdapter.prototype._createDateWithOverflow = function (year, month, date) {
var /** @type {?} */ result = new Date(year, month, date);
// We need to correct for the fact that JS native Date treats years in range [0, 99] as
// abbreviations for 19xx.
if (year >= 0 && year < 100) {
result.setFullYear(this.getYear(result) - 1900);
}
return result;
};
/**
* Pads a number to make it two digits.
* @param {?} n The number to pad.
* @return {?} The padded number.
*/
NativeDateAdapter.prototype._2digit = function (n) {
return ('00' + n).slice(-2);
};
/**
* Strip out unicode LTR and RTL characters. Edge and IE insert these into formatted dates while
* other browsers do not. We remove them to make output consistent and because they interfere with
* date parsing.
* @param {?} str The string to strip direction characters from.
* @return {?} The stripped string.
*/
NativeDateAdapter.prototype._stripDirectionalityCharacters = function (str) {
return str.replace(/[\u200e\u200f]/g, '');
};
NativeDateAdapter.decorators = [
{ type: _angular_core.Injectable },
];
/**
* @nocollapse
*/
NativeDateAdapter.ctorParameters = function () { return [
{ type: undefined, decorators: [{ type: _angular_core.Optional }, { type: _angular_core.Inject, args: [MAT_DATE_LOCALE,] },] },
]; };
return NativeDateAdapter;
}(DateAdapter));
var MAT_DATE_FORMATS = new _angular_core.InjectionToken('mat-date-formats');
var GestureConfig = (function (_super) {
__extends(GestureConfig, _super);
function GestureConfig() {
var _this = _super.call(this) || this;
_this._hammer = typeof window !== 'undefined' ? ((window)).Hammer : null;
/* List of new event names to add to the gesture support list */
_this.events = _this._hammer ? [
'longpress',
'slide',
'slidestart',
'slideend',
'slideright',
'slideleft'
] : [];
if (!_this._hammer && _angular_core.isDevMode()) {
console.warn('Could not find HammerJS. Certain Angular Material ' +
'components may not work correctly.');
}
return _this;
}
/**
* Builds Hammer instance manually to add custom recognizers that match the Material Design spec.
*
* Our gesture names come from the Material Design gestures spec:
* https://www.google.com/design/spec/patterns/gestures.html#gestures-touch-mechanics
*
* More information on default recognizers can be found in Hammer docs:
* http://hammerjs.github.io/recognizer-pan/
* http://hammerjs.github.io/recognizer-press/
*
* @param {?} element Element to which to assign the new HammerJS gestures.
* @return {?} Newly-created HammerJS instance.
*/
GestureConfig.prototype.buildHammer = function (element) {
var /** @type {?} */ mc = new this._hammer(element);
// Default Hammer Recognizers.
var /** @type {?} */ pan = new this._hammer.Pan();
var /** @type {?} */ swipe = new this._hammer.Swipe();
var /** @type {?} */ press = new this._hammer.Press();
// Notice that a HammerJS recognizer can only depend on one other recognizer once.
// Otherwise the previous `recognizeWith` will be dropped.
// TODO: Confirm threshold numbers with Material Design UX Team
var /** @type {?} */ slide = this._createRecognizer(pan, { event: 'slide', threshold: 0 }, swipe);
var /** @type {?} */ longpress = this._createRecognizer(press, { event: 'longpress', time: 500 });
// Overwrite the default `pan` event to use the swipe event.
pan.recognizeWith(swipe);
// Add customized gestures to Hammer manager
mc.add([swipe, press, pan, slide, longpress]);
return (mc);
};
/**
* Creates a new recognizer, without affecting the default recognizers of HammerJS
* @param {?} base
* @param {?} options
* @param {...?} inheritances
* @return {?}
*/
GestureConfig.prototype._createRecognizer = function (base, options) {
var inheritances = [];
for (var _i = 2; _i < arguments.length; _i++) {
inheritances[_i - 2] = arguments[_i];
}
var /** @type {?} */ recognizer = new ((base.constructor))(options);
inheritances.push(base);
inheritances.forEach(function (item) { return recognizer.recognizeWith(item); });
return recognizer;
};
GestureConfig.decorators = [
{ type: _angular_core.Injectable },
];
/**
* @nocollapse
*/
GestureConfig.ctorParameters = function () { return []; };
return GestureConfig;
}(_angular_platformBrowser.HammerGestureConfig));
var RippleState = {};
RippleState.FADING_IN = 0;
RippleState.VISIBLE = 1;
RippleState.FADING_OUT = 2;
RippleState.HIDDEN = 3;
RippleState[RippleState.FADING_IN] = "FADING_IN";
RippleState[RippleState.VISIBLE] = "VISIBLE";
RippleState[RippleState.FADING_OUT] = "FADING_OUT";
RippleState[RippleState.HIDDEN] = "HIDDEN";
/**
* Reference to a previously launched ripple element.
*/
var RippleRef = (function () {
/**
* @param {?} _renderer
* @param {?} element
* @param {?} config
*/
function RippleRef(_renderer, element, config) {
this._renderer = _renderer;
this.element = element;
this.config = config;
/**
* Current state of the ripple reference.
*/
this.state = RippleState.HIDDEN;
}
/**
* Fades out the ripple element.
* @return {?}
*/
RippleRef.prototype.fadeOut = function () {
this._renderer.fadeOutRipple(this);
};
return RippleRef;
}());
/**
* Fade-in duration for the ripples. Can be modified with the speedFactor option.
*/
var RIPPLE_FADE_IN_DURATION = 450;
/**
* Fade-out duration for the ripples in milliseconds. This can't be modified by the speedFactor.
*/
var RIPPLE_FADE_OUT_DURATION = 400;
/**
* Helper service that performs DOM manipulations. Not intended to be used outside this module.
* The constructor takes a reference to the ripple directive's host element and a map of DOM
* event handlers to be installed on the element that triggers ripple animations.
* This will eventually become a custom renderer once Angular support exists.
* \@docs-private
*/
var RippleRenderer = (function () {
/**
* @param {?} elementRef
* @param {?} _ngZone
* @param {?} platform
*/
function RippleRenderer(elementRef, _ngZone, platform) {
this._ngZone = _ngZone;
/**
* Whether the pointer is currently being held on the trigger or not.
*/
this._isPointerDown = false;
/**
* Events to be registered on the trigger element.
*/
this._triggerEvents = new Map();
/**
* Set of currently active ripple references.
*/
this._activeRipples = new Set();
/**
* Ripple config for all ripples created by events.
*/
this.rippleConfig = {};
/**
* Whether mouse ripples should be created or not.
*/
this.rippleDisabled = false;
// Only do anything if we're on the browser.
if (platform.isBrowser) {
this._containerElement = elementRef.nativeElement;
// Specify events which need to be registered on the trigger.
this._triggerEvents.set('mousedown', this.onMousedown.bind(this));
this._triggerEvents.set('touchstart', this.onTouchstart.bind(this));
this._triggerEvents.set('mouseup', this.onPointerUp.bind(this));
this._triggerEvents.set('touchend', this.onPointerUp.bind(this));
this._triggerEvents.set('mouseleave', this.onPointerLeave.bind(this));
// By default use the host element as trigger element.
this.setTriggerElement(this._containerElement);
}
}
/**
* Fades in a ripple at the given coordinates.
* @param {?} x Coordinate within the element, along the X axis at which to start the ripple.
* @param {?} y
* @param {?=} config Extra ripple options.
* @return {?}
*/
RippleRenderer.prototype.fadeInRipple = function (x, y, config) {
var _this = this;
if (config === void 0) { config = {}; }
var /** @type {?} */ containerRect = this._containerElement.getBoundingClientRect();
if (config.centered) {
x = containerRect.left + containerRect.width / 2;
y = containerRect.top + containerRect.height / 2;
}
var /** @type {?} */ radius = config.radius || distanceToFurthestCorner(x, y, containerRect);
var /** @type {?} */ duration = RIPPLE_FADE_IN_DURATION * (1 / (config.speedFactor || 1));
var /** @type {?} */ offsetX = x - containerRect.left;
var /** @type {?} */ offsetY = y - containerRect.top;
var /** @type {?} */ ripple = document.createElement('div');
ripple.classList.add('mat-ripple-element');
ripple.style.left = offsetX - radius + "px";
ripple.style.top = offsetY - radius + "px";
ripple.style.height = radius * 2 + "px";
ripple.style.width = radius * 2 + "px";
// If the color is not set, the default CSS color will be used.
ripple.style.backgroundColor = config.color || null;
ripple.style.transitionDuration = duration + "ms";
this._containerElement.appendChild(ripple);
// By default the browser does not recalculate the styles of dynamically created
// ripple elements. This is critical because then the `scale` would not animate properly.
enforceStyleRecalculation(ripple);
ripple.style.transform = 'scale(1)';
// Exposed reference to the ripple that will be returned.
var /** @type {?} */ rippleRef = new RippleRef(this, ripple, config);
rippleRef.state = RippleState.FADING_IN;
// Add the ripple reference to the list of all active ripples.
this._activeRipples.add(rippleRef);
// Wait for the ripple element to be completely faded in.
// Once it's faded in, the ripple can be hidden immediately if the mouse is released.
this.runTimeoutOutsideZone(function () {
rippleRef.state = RippleState.VISIBLE;
if (!config.persistent && !_this._isPointerDown) {
rippleRef.fadeOut();
}
}, duration);
return rippleRef;
};
/**
* Fades out a ripple reference.
* @param {?} rippleRef
* @return {?}
*/
RippleRenderer.prototype.fadeOutRipple = function (rippleRef) {
// For ripples that are not active anymore, don't re-un the fade-out animation.
if (!this._activeRipples.delete(rippleRef)) {
return;
}
var /** @type {?} */ rippleEl = rippleRef.element;
rippleEl.style.transitionDuration = RIPPLE_FADE_OUT_DURATION + "ms";
rippleEl.style.opacity = '0';
rippleRef.state = RippleState.FADING_OUT;
// Once the ripple faded out, the ripple can be safely removed from the DOM.
this.runTimeoutOutsideZone(function () {
rippleRef.state = RippleState.HIDDEN; /** @type {?} */
((rippleEl.parentNode)).removeChild(rippleEl);
}, RIPPLE_FADE_OUT_DURATION);
};
/**
* Fades out all currently active ripples.
* @return {?}
*/
RippleRenderer.prototype.fadeOutAll = function () {
this._activeRipples.forEach(function (ripple) { return ripple.fadeOut(); });
};
/**
* Sets the trigger element and registers the mouse events.
* @param {?} element
* @return {?}
*/
RippleRenderer.prototype.setTriggerElement = function (element) {
var _this = this;
// Remove all previously register event listeners from the trigger element.
if (this._triggerElement) {
this._triggerEvents.forEach(function (fn, type) {
((_this._triggerElement)).removeEventListener(type, fn);
});
}
if (element) {
// If the element is not null, register all event listeners on the trigger element.
this._ngZone.runOutsideAngular(function () {
_this._triggerEvents.forEach(function (fn, type) { return element.addEventListener(type, fn); });
});
}
this._triggerElement = element;
};
/**
* Function being called whenever the trigger is being pressed.
* @param {?} event
* @return {?}
*/
RippleRenderer.prototype.onMousedown = function (event) {
if (!this.rippleDisabled) {
this._isPointerDown = true;
this.fadeInRipple(event.clientX, event.clientY, this.rippleConfig);
}
};
/**
* Function being called whenever the pointer is being released.
* @return {?}
*/
RippleRenderer.prototype.onPointerUp = function () {
this._isPointerDown = false;
// Fade-out all ripples that are completely visible and not persistent.
this._activeRipples.forEach(function (ripple) {
if (!ripple.config.persistent && ripple.state === RippleState.VISIBLE) {
ripple.fadeOut();
}
});
};
/**
* Function being called whenever the pointer leaves the trigger.
* @return {?}
*/
RippleRenderer.prototype.onPointerLeave = function () {
if (this._isPointerDown) {
this.onPointerUp();
}
};
/**
* Function being called whenever the trigger is being touched.
* @param {?} event
* @return {?}
*/
RippleRenderer.prototype.onTouchstart = function (event) {
if (!this.rippleDisabled) {
var _a = event.touches[0], clientX = _a.clientX, clientY = _a.clientY;
this._isPointerDown = true;
this.fadeInRipple(clientX, clientY, this.rippleConfig);
}
};
/**
* Runs a timeout outside of the Angular zone to avoid triggering the change detection.
* @param {?} fn
* @param {?=} delay
* @return {?}
*/
RippleRenderer.prototype.runTimeoutOutsideZone = function (fn, delay) {
if (delay === void 0) { delay = 0; }
this._ngZone.runOutsideAngular(function () { return setTimeout(fn, delay); });
};
return RippleRenderer;
}());
/**
* @param {?} element
* @return {?}
*/
function enforceStyleRecalculation(element) {
// Enforce a style recalculation by calling `getComputedStyle` and accessing any property.
// Calling `getPropertyValue` is important to let optimizers know that this is not a noop.
// See: https://gist.github.com/paulirish/5d52fb081b3570c81e3a
window.getComputedStyle(element).getPropertyValue('opacity');
}
/**
* Returns the distance from the point (x, y) to the furthest corner of a rectangle.
* @param {?} x
* @param {?} y
* @param {?} rect
* @return {?}
*/
function distanceToFurthestCorner(x, y, rect) {
var /** @type {?} */ distX = Math.max(Math.abs(x - rect.left), Math.abs(x - rect.right));
var /** @type {?} */ distY = Math.max(Math.abs(y - rect.top), Math.abs(y - rect.bottom));
return Math.sqrt(distX * distX + distY * distY);
}
/**
* Injection token that can be used to specify the global ripple options.
*/
var MAT_RIPPLE_GLOBAL_OPTIONS = new _angular_core.InjectionToken('mat-ripple-global-options');
var MatRipple = (function () {
/**
* @param {?} elementRef
* @param {?} ngZone
* @param {?} platform
* @param {?} globalOptions
*/
function MatRipple(elementRef, ngZone, platform, globalOptions) {
/**
* If set, the radius in pixels of foreground ripples when fully expanded. If unset, the radius
* will be the distance from the center of the ripple to the furthest corner of the host element's
* bounding rectangle.
*/
this.radius = 0;
/**
* If set, the normal duration of ripple animations is divided by this value. For example,
* setting it to 0.5 will cause the animations to take twice as long.
* A changed speedFactor will not modify the fade-out duration of the ripples.
*/
this.speedFactor = 1;
this._rippleRenderer = new RippleRenderer(elementRef, ngZone, platform);
this._globalOptions = globalOptions ? globalOptions : {};
this._updateRippleRenderer();
}
/**
* @param {?} changes
* @return {?}
*/
MatRipple.prototype.ngOnChanges = function (changes) {
if ((changes['trigger'] || changes['_matRippleTrigger']) && this.trigger) {
this._rippleRenderer.setTriggerElement(this.trigger);
}
this._updateRippleRenderer();
};
/**
* @return {?}
*/
MatRipple.prototype.ngOnDestroy = function () {
// Set the trigger element to null to cleanup all listeners.
this._rippleRenderer.setTriggerElement(null);
};
/**
* Launches a manual ripple at the specified position.
* @param {?} x
* @param {?} y
* @param {?=} config
* @return {?}
*/
MatRipple.prototype.launch = function (x, y, config) {
if (config === void 0) { config = this.rippleConfig; }
return this._rippleRenderer.fadeInRipple(x, y, config);
};
/**
* Fades out all currently showing ripple elements.
* @return {?}
*/
MatRipple.prototype.fadeOutAll = function () {
this._rippleRenderer.fadeOutAll();
};
Object.defineProperty(MatRipple.prototype, "rippleConfig", {
/**
* Ripple configuration from the directive's input values.
* @return {?}
*/
get: function () {
return {
centered: this.centered,
speedFactor: this.speedFactor * (this._globalOptions.baseSpeedFactor || 1),
radius: this.radius,
color: this.color
};
},
enumerable: true,
configurable: true
});
/**
* Updates the ripple renderer with the latest ripple configuration.
* @return {?}
*/
MatRipple.prototype._updateRippleRenderer = function () {
this._rippleRenderer.rippleDisabled = this._globalOptions.disabled || this.disabled;
this._rippleRenderer.rippleConfig = this.rippleConfig;
};
MatRipple.decorators = [
{ type: _angular_core.Directive, args: [{
selector: '[mat-ripple], [matRipple]',
exportAs: 'matRipple',
host: {
'class': 'mat-ripple',
'[class.mat-ripple-unbounded]': 'unbounded'
}
},] },
];
/**
* @nocollapse
*/
MatRipple.ctorParameters = function () { return [
{ type: _angular_core.ElementRef, },
{ type: _angular_core.NgZone, },
{ type: _angular_cdk_platform.Platform, },
{ type: undefined, decorators: [{ type: _angular_core.Optional }, { type: _angular_core.Inject, args: [MAT_RIPPLE_GLOBAL_OPTIONS,] },] },
]; };
MatRipple.propDecorators = {
'trigger': [{ type: _angular_core.Input, args: ['matRippleTrigger',] },],
'centered': [{ type: _angular_core.Input, args: ['matRippleCentered',] },],
'disabled': [{ type: _angular_core.Input, args: ['matRippleDisabled',] },],
'radius': [{ type: _angular_core.Input, args: ['matRippleRadius',] },],
'speedFactor': [{ type: _angular_core.Input, args: ['matRippleSpeedFactor',] },],
'color': [{ type: _angular_core.Input, args: ['matRippleColor',] },],
'unbounded': [{ type: _angular_core.Input, args: ['matRippleUnbounded',] },],
};
return MatRipple;
}());
/**
* \@docs-private
*/
var MatOptgroupBase = (function () {
function MatOptgroupBase() {
}
return MatOptgroupBase;
}());
var _MatOptgroupMixinBase = mixinDisabled(MatOptgroupBase);
// Counter for unique group ids.
var _uniqueOptgroupIdCounter = 0;
/**
* Component that is used to group instances of `mat-option`.
*/
var MatOptgroup = (function (_super) {
__extends(MatOptgroup, _super);
function MatOptgroup() {
var _this = _super !== null && _super.apply(this, arguments) || this;
/**
* Unique id for the underlying label.
*/
_this._labelId = "mat-optgroup-label-" + _uniqueOptgroupIdCounter++;
return _this;
}
MatOptgroup.decorators = [
{ type: _angular_core.Component, args: [{selector: 'mat-optgroup',
exportAs: 'matOptgroup',
template: "<label class=\"mat-optgroup-label\" [id]=\"_labelId\">{{ label }}</label><ng-content select=\"mat-option\"></ng-content>",
encapsulation: _angular_core.ViewEncapsulation.None,
preserveWhitespaces: false,
changeDetection: _angular_core.ChangeDetectionStrategy.OnPush,
inputs: ['disabled'],
host: {
'class': 'mat-optgroup',
'role': 'group',
'[class.mat-optgroup-disabled]': 'disabled',
'[attr.aria-disabled]': 'disabled.toString()',
'[attr.aria-labelledby]': '_labelId',
}
},] },
];
/**
* @nocollapse
*/
MatOptgroup.ctorParameters = function () { return []; };
MatOptgroup.propDecorators = {
'label': [{ type: _angular_core.Input },],
};
return MatOptgroup;
}(_MatOptgroupMixinBase));
/**
* Option IDs need to be unique across components, so this counter exists outside of
* the component definition.
*/
var _uniqueIdCounter = 0;
/**
* Event object emitted by MatOption when selected or deselected.
*/
var MatOptionSelectionChange = (function () {
/**
* @param {?} source
* @param {?=} isUserInput
*/
function MatOptionSelectionChange(source, isUserInput) {
if (isUserInput === void 0) { isUserInput = false; }
this.source = source;
this.isUserInput = isUserInput;
}
return MatOptionSelectionChange;
}());
/**
* Single option inside of a `<mat-select>` element.
*/
var MatOption = (function () {
/**
* @param {?} _element
* @param {?} _changeDetectorRef
* @param {?} group
*/
function MatOption(_element, _changeDetectorRef, group) {
this._element = _element;
this._changeDetectorRef = _changeDetectorRef;
this.group = group;
this._selected = false;
this._active = false;
this._multiple = false;
this._disableRipple = false;
/**
* Whether the option is disabled.
*/
this._disabled = false;
this._id = "mat-option-" + _uniqueIdCounter++;
/**
* Event emitted when the option is selected or deselected.
*/
this.onSelectionChange = new _angular_core.EventEmitter();
}
Object.defineProperty(MatOption.prototype, "multiple", {
/**
* Whether the wrapping component is in multiple selection mode.
* @return {?}
*/
get: function () { return this._multiple; },
/**
* @param {?} value
* @return {?}
*/
set: function (value) {
if (value !== this._multiple) {
this._multiple = value;
this._changeDetectorRef.markForCheck();
}
},
enumerable: true,
configurable: true
});
Object.defineProperty(MatOption.prototype, "id", {
/**
* The unique ID of the option.
* @return {?}
*/
get: function () { return this._id; },
enumerable: true,
configurable: true
});
Object.defineProperty(MatOption.prototype, "selected", {
/**
* Whether or not the option is currently selected.
* @return {?}
*/
get: function () { return this._selected; },
enumerable: true,
configurable: true
});
Object.defin