UNPKG

@angular/material

Version:
1,032 lines (993 loc) 109 kB
(function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@angular/cdk/a11y'), require('@angular/cdk/bidi'), require('@angular/cdk'), require('@angular/cdk/coercion'), require('rxjs'), require('@angular/cdk/platform'), require('@angular/platform-browser'), require('rxjs/operators'), require('@angular/common'), require('@angular/platform-browser/animations'), require('@angular/cdk/keycodes')) : typeof define === 'function' && define.amd ? define('@angular/material/core', ['exports', '@angular/core', '@angular/cdk/a11y', '@angular/cdk/bidi', '@angular/cdk', '@angular/cdk/coercion', 'rxjs', '@angular/cdk/platform', '@angular/platform-browser', 'rxjs/operators', '@angular/common', '@angular/platform-browser/animations', '@angular/cdk/keycodes'], factory) : (global = global || self, factory((global.ng = global.ng || {}, global.ng.material = global.ng.material || {}, global.ng.material.core = {}), global.ng.core, global.ng.cdk.a11y, global.ng.cdk.bidi, global.ng.cdk, global.ng.cdk.coercion, global.rxjs, global.ng.cdk.platform, global.ng.platformBrowser, global.rxjs.operators, global.ng.common, global.ng.platformBrowser.animations, global.ng.cdk.keycodes)); }(this, (function (exports, i0, a11y, bidi, cdk, coercion, rxjs, platform, platformBrowser, operators, common, animations, keycodes) { 'use strict'; /** * @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://angular.io/license */ /** Current version of Angular Material. */ var VERSION = new i0.Version('9.1.2'); /** * @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://angular.io/license */ /** @docs-private */ var AnimationCurves = /** @class */ (function () { function AnimationCurves() { } AnimationCurves.STANDARD_CURVE = 'cubic-bezier(0.4,0.0,0.2,1)'; AnimationCurves.DECELERATION_CURVE = 'cubic-bezier(0.0,0.0,0.2,1)'; AnimationCurves.ACCELERATION_CURVE = 'cubic-bezier(0.4,0.0,1,1)'; AnimationCurves.SHARP_CURVE = 'cubic-bezier(0.4,0.0,0.6,1)'; return AnimationCurves; }()); /** @docs-private */ var AnimationDurations = /** @class */ (function () { function AnimationDurations() { } AnimationDurations.COMPLEX = '375ms'; AnimationDurations.ENTERING = '225ms'; AnimationDurations.EXITING = '195ms'; return AnimationDurations; }()); /** * @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://angular.io/license */ // Private version constant to circumvent test/build issues, // i.e. avoid core to depend on the @angular/material primary entry-point // Can be removed once the Material primary entry-point no longer // re-exports all secondary entry-points var VERSION$1 = new i0.Version('9.1.2'); /** @docs-private */ function MATERIAL_SANITY_CHECKS_FACTORY() { return true; } /** Injection token that configures whether the Material sanity checks are enabled. */ var MATERIAL_SANITY_CHECKS = new i0.InjectionToken('mat-sanity-checks', { providedIn: 'root', factory: MATERIAL_SANITY_CHECKS_FACTORY, }); /** * Module that captures anything that should be loaded and/or run for *all* Angular Material * components. This includes Bidi, etc. * * This module should be imported to each top-level component module (e.g., MatTabsModule). */ var MatCommonModule = /** @class */ (function () { function MatCommonModule(highContrastModeDetector, sanityChecks) { /** Whether we've done the global sanity checks (e.g. a theme is loaded, there is a doctype). */ this._hasDoneGlobalChecks = false; /** Reference to the global `document` object. */ this._document = typeof document === 'object' && document ? document : null; /** Reference to the global 'window' object. */ this._window = typeof window === 'object' && window ? window : null; // While A11yModule also does this, we repeat it here to avoid importing A11yModule // in MatCommonModule. highContrastModeDetector._applyBodyHighContrastModeCssClasses(); // Note that `_sanityChecks` is typed to `any`, because AoT // throws an error if we use the `SanityChecks` type directly. this._sanityChecks = sanityChecks; if (!this._hasDoneGlobalChecks) { this._checkDoctypeIsDefined(); this._checkThemeIsPresent(); this._checkCdkVersionMatch(); this._hasDoneGlobalChecks = true; } } /** Whether any sanity checks are enabled. */ MatCommonModule.prototype._checksAreEnabled = function () { return i0.isDevMode() && !this._isTestEnv(); }; /** Whether the code is running in tests. */ MatCommonModule.prototype._isTestEnv = function () { var window = this._window; return window && (window.__karma__ || window.jasmine); }; MatCommonModule.prototype._checkDoctypeIsDefined = function () { var isEnabled = this._checksAreEnabled() && (this._sanityChecks === true || this._sanityChecks.doctype); if (isEnabled && this._document && !this._document.doctype) { console.warn('Current document does not have a doctype. This may cause ' + 'some Angular Material components not to behave as expected.'); } }; MatCommonModule.prototype._checkThemeIsPresent = function () { // We need to assert that the `body` is defined, because these checks run very early // and the `body` won't be defined if the consumer put their scripts in the `head`. var isDisabled = !this._checksAreEnabled() || (this._sanityChecks === false || !this._sanityChecks.theme); if (isDisabled || !this._document || !this._document.body || typeof getComputedStyle !== 'function') { return; } var testElement = this._document.createElement('div'); testElement.classList.add('mat-theme-loaded-marker'); this._document.body.appendChild(testElement); var computedStyle = getComputedStyle(testElement); // In some situations the computed style of the test element can be null. For example in // Firefox, the computed style is null if an application is running inside of a hidden iframe. // See: https://bugzilla.mozilla.org/show_bug.cgi?id=548397 if (computedStyle && computedStyle.display !== 'none') { console.warn('Could not find Angular Material core theme. Most Material ' + 'components may not work as expected. For more info refer ' + 'to the theming guide: https://material.angular.io/guide/theming'); } this._document.body.removeChild(testElement); }; /** Checks whether the material version matches the cdk version */ MatCommonModule.prototype._checkCdkVersionMatch = function () { var isEnabled = this._checksAreEnabled() && (this._sanityChecks === true || this._sanityChecks.version); if (isEnabled && VERSION$1.full !== cdk.VERSION.full) { console.warn('The Angular Material version (' + VERSION$1.full + ') does not match ' + 'the Angular CDK version (' + cdk.VERSION.full + ').\n' + 'Please ensure the versions of these two packages exactly match.'); } }; MatCommonModule.decorators = [ { type: i0.NgModule, args: [{ imports: [bidi.BidiModule], exports: [bidi.BidiModule], },] } ]; /** @nocollapse */ MatCommonModule.ctorParameters = function () { return [ { type: a11y.HighContrastModeDetector }, { type: undefined, decorators: [{ type: i0.Optional }, { type: i0.Inject, args: [MATERIAL_SANITY_CHECKS,] }] } ]; }; return MatCommonModule; }()); /*! ***************************************************************************** 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 = function(d, b) { 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]; }; return extendStatics(d, b); }; function __extends(d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); } var __assign = function() { __assign = Object.assign || function __assign(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); }; function __rest(s, e) { var t = {}; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]]; } return t; } function __decorate(decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; } function __param(paramIndex, decorator) { return function (target, key) { decorator(target, key, paramIndex); } } function __metadata(metadataKey, metadataValue) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue); } function __awaiter(thisArg, _arguments, P, generator) { return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); } function __generator(thisArg, body) { var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; function verb(n) { return function (v) { return step([n, v]); }; } function step(op) { if (f) throw new TypeError("Generator is already executing."); while (_) try { if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; if (y = 0, t) op = [op[0] & 2, t.value]; switch (op[0]) { case 0: case 1: t = op; break; case 4: _.label++; return { value: op[1], done: false }; case 5: _.label++; y = op[1]; op = [0]; continue; case 7: op = _.ops.pop(); _.trys.pop(); continue; default: if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } if (t[2]) _.ops.pop(); _.trys.pop(); continue; } op = body.call(thisArg, _); } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; } } function __exportStar(m, exports) { for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; } function __values(o) { var m = typeof Symbol === "function" && o[Symbol.iterator], i = 0; if (m) return m.call(o); return { next: function () { if (o && i >= o.length) o = void 0; return { value: o && o[i++], done: !o }; } }; } function __read(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; } function __spread() { for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i])); return ar; } function __spreadArrays() { for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length; for (var r = Array(s), k = 0, i = 0; i < il; i++) for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) r[k] = a[j]; return r; }; function __await(v) { return this instanceof __await ? (this.v = v, this) : new __await(v); } function __asyncGenerator(thisArg, _arguments, generator) { if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined."); var g = generator.apply(thisArg, _arguments || []), i, q = []; return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i; function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; } function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } } function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); } function fulfill(value) { resume("next", value); } function reject(value) { resume("throw", value); } function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); } } function __asyncDelegator(o) { var i, p; return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i; function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v; } : f; } } function __asyncValues(o) { if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined."); var m = o[Symbol.asyncIterator], i; return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i); function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; } function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); } } function __makeTemplateObject(cooked, raw) { if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; } return cooked; }; function __importStar(mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; result.default = mod; return result; } function __importDefault(mod) { return (mod && mod.__esModule) ? mod : { default: mod }; } /** * @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://angular.io/license */ /** Mixin to augment a directive with a `disabled` property. */ function mixinDisabled(base) { return /** @class */ (function (_super) { __extends(class_1, _super); function class_1() { var args = []; for (var _i = 0; _i < arguments.length; _i++) { args[_i] = arguments[_i]; } var _this = _super.apply(this, __spread(args)) || this; _this._disabled = false; return _this; } Object.defineProperty(class_1.prototype, "disabled", { get: function () { return this._disabled; }, set: function (value) { this._disabled = coercion.coerceBooleanProperty(value); }, enumerable: true, configurable: true }); return class_1; }(base)); } /** * @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://angular.io/license */ /** Mixin to augment a directive with a `color` property. */ function mixinColor(base, defaultColor) { return /** @class */ (function (_super) { __extends(class_1, _super); function class_1() { var args = []; for (var _i = 0; _i < arguments.length; _i++) { args[_i] = arguments[_i]; } var _this = _super.apply(this, __spread(args)) || this; // Set the default color that can be specified from the mixin. _this.color = defaultColor; return _this; } Object.defineProperty(class_1.prototype, "color", { get: function () { return this._color; }, set: function (value) { var colorPalette = value || defaultColor; if (colorPalette !== this._color) { if (this._color) { this._elementRef.nativeElement.classList.remove("mat-" + this._color); } if (colorPalette) { this._elementRef.nativeElement.classList.add("mat-" + colorPalette); } this._color = colorPalette; } }, enumerable: true, configurable: true }); return class_1; }(base)); } /** * @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://angular.io/license */ /** Mixin to augment a directive with a `disableRipple` property. */ function mixinDisableRipple(base) { return /** @class */ (function (_super) { __extends(class_1, _super); function class_1() { var args = []; for (var _i = 0; _i < arguments.length; _i++) { args[_i] = arguments[_i]; } var _this = _super.apply(this, __spread(args)) || this; _this._disableRipple = false; return _this; } Object.defineProperty(class_1.prototype, "disableRipple", { /** Whether the ripple effect is disabled or not. */ get: function () { return this._disableRipple; }, set: function (value) { this._disableRipple = coercion.coerceBooleanProperty(value); }, enumerable: true, configurable: true }); return class_1; }(base)); } /** * @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://angular.io/license */ /** Mixin to augment a directive with a `tabIndex` property. */ function mixinTabIndex(base, defaultTabIndex) { if (defaultTabIndex === void 0) { defaultTabIndex = 0; } return /** @class */ (function (_super) { __extends(class_1, _super); function class_1() { var args = []; for (var _i = 0; _i < arguments.length; _i++) { args[_i] = arguments[_i]; } var _this = _super.apply(this, __spread(args)) || this; _this._tabIndex = defaultTabIndex; return _this; } Object.defineProperty(class_1.prototype, "tabIndex", { get: function () { return this.disabled ? -1 : this._tabIndex; }, set: function (value) { // If the specified tabIndex value is null or undefined, fall back to the default value. this._tabIndex = value != null ? value : defaultTabIndex; }, enumerable: true, configurable: true }); return class_1; }(base)); } /** * @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://angular.io/license */ /** * Mixin to augment a directive with updateErrorState method. * For component with `errorState` and need to update `errorState`. */ function mixinErrorState(base) { return /** @class */ (function (_super) { __extends(class_1, _super); function class_1() { var args = []; for (var _i = 0; _i < arguments.length; _i++) { args[_i] = arguments[_i]; } var _this = _super.apply(this, __spread(args)) || this; /** Whether the component is in an error state. */ _this.errorState = false; /** * Stream that emits whenever the state of the input changes such that the wrapping * `MatFormField` needs to run change detection. */ _this.stateChanges = new rxjs.Subject(); return _this; } class_1.prototype.updateErrorState = function () { var oldState = this.errorState; var parent = this._parentFormGroup || this._parentForm; var matcher = this.errorStateMatcher || this._defaultErrorStateMatcher; var control = this.ngControl ? this.ngControl.control : null; var newState = matcher.isErrorState(control, parent); if (newState !== oldState) { this.errorState = newState; this.stateChanges.next(); } }; return class_1; }(base)); } /** * @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://angular.io/license */ /** Mixin to augment a directive with an initialized property that will emits when ngOnInit ends. */ function mixinInitialized(base) { return /** @class */ (function (_super) { __extends(class_1, _super); function class_1() { var args = []; for (var _i = 0; _i < arguments.length; _i++) { args[_i] = arguments[_i]; } var _this = _super.apply(this, __spread(args)) || this; /** Whether this directive has been marked as initialized. */ _this._isInitialized = false; /** * List of subscribers that subscribed before the directive was initialized. Should be notified * during _markInitialized. Set to null after pending subscribers are notified, and should * not expect to be populated after. */ _this._pendingSubscribers = []; /** * Observable stream that emits when the directive initializes. If already initialized, the * subscriber is stored to be notified once _markInitialized is called. */ _this.initialized = new rxjs.Observable(function (subscriber) { // If initialized, immediately notify the subscriber. Otherwise store the subscriber to notify // when _markInitialized is called. if (_this._isInitialized) { _this._notifySubscriber(subscriber); } else { _this._pendingSubscribers.push(subscriber); } }); return _this; } /** * Marks the state as initialized and notifies pending subscribers. Should be called at the end * of ngOnInit. * @docs-private */ class_1.prototype._markInitialized = function () { if (this._isInitialized) { throw Error('This directive has already been marked as initialized and ' + 'should not be called twice.'); } this._isInitialized = true; this._pendingSubscribers.forEach(this._notifySubscriber); this._pendingSubscribers = null; }; /** Emits and completes the subscriber stream (should only emit once). */ class_1.prototype._notifySubscriber = function (subscriber) { subscriber.next(); subscriber.complete(); }; return class_1; }(base)); } /** * @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://angular.io/license */ /** * @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://angular.io/license */ /** InjectionToken for datepicker that can be used to override default locale code. */ var MAT_DATE_LOCALE = new i0.InjectionToken('MAT_DATE_LOCALE', { providedIn: 'root', factory: MAT_DATE_LOCALE_FACTORY, }); /** @docs-private */ function MAT_DATE_LOCALE_FACTORY() { return i0.inject(i0.LOCALE_ID); } /** * No longer needed since MAT_DATE_LOCALE has been changed to a scoped injectable. * If you are importing and providing this in your code you can simply remove it. * @deprecated * @breaking-change 8.0.0 */ var MAT_DATE_LOCALE_PROVIDER = { provide: MAT_DATE_LOCALE, useExisting: i0.LOCALE_ID }; /** Adapts type `D` to be usable as a date by cdk-based components that work with dates. */ var DateAdapter = /** @class */ (function () { function DateAdapter() { this._localeChanges = new rxjs.Subject(); } Object.defineProperty(DateAdapter.prototype, "localeChanges", { /** A stream that emits when the locale changes. */ get: function () { return this._localeChanges; }, enumerable: true, configurable: true }); /** * Attempts to deserialize a value to a valid date object. This is different from parsing in that * deserialize should only accept non-ambiguous, locale-independent formats (e.g. a ISO 8601 * string). The default implementation does not allow any deserialization, it simply checks that * the given value is already a valid date object or null. The `<mat-datepicker>` will call this * method on all of its `@Input()` properties that accept dates. It is therefore possible to * support passing values from your backend directly to these properties by overriding this method * to also deserialize the format used by your backend. * @param value The value to be deserialized into a date object. * @returns The deserialized date object, either a valid date, null if the value can be * deserialized into a null date (e.g. the empty string), or an invalid date. */ DateAdapter.prototype.deserialize = function (value) { if (value == null || this.isDateInstance(value) && this.isValid(value)) { return value; } return this.invalid(); }; /** * Sets the locale used for all dates. * @param locale The new locale. */ 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. * @returns 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, second) { return this.getYear(first) - this.getYear(second) || this.getMonth(first) - this.getMonth(second) || this.getDate(first) - this.getDate(second); }; /** * Checks if two dates are equal. * @param first The first date to check. * @param second The second date to check. * @returns Whether the two dates are equal. * Null dates are considered equal to other null dates. */ DateAdapter.prototype.sameDate = function (first, second) { if (first && second) { var firstValid = this.isValid(first); var secondValid = this.isValid(second); if (firstValid && secondValid) { return !this.compareDate(first, second); } return firstValid == secondValid; } return first == 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. * @returns `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; }()); /** * @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://angular.io/license */ var MAT_DATE_FORMATS = new i0.InjectionToken('mat-date-formats'); /** * @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://angular.io/license */ // TODO(mmalerba): Remove when we no longer support safari 9. /** Whether the browser supports the Intl API. */ var SUPPORTS_INTL_API; // We need a try/catch around the reference to `Intl`, because accessing it in some cases can // cause IE to throw. These cases are tied to particular versions of Windows and can happen if // the consumer is providing a polyfilled `Map`. See: // https://github.com/Microsoft/ChakraCore/issues/3189 // https://github.com/angular/components/issues/15687 try { SUPPORTS_INTL_API = typeof Intl != 'undefined'; } catch (_a) { SUPPORTS_INTL_API = false; } /** 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'] }; var ɵ0 = function (i) { return String(i + 1); }; /** The default date names to use if Intl API is not available. */ var DEFAULT_DATE_NAMES = range(31, ɵ0); /** 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. */ function range(length, valueFunction) { var valuesArray = Array(length); for (var 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 = /** @class */ (function (_super) { __extends(NativeDateAdapter, _super); function NativeDateAdapter(matDateLocale, platform) { 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'`. * * TODO(mmalerba): drop this variable. It's not being used in the code right now. We're now * getting the string representation of a Date object from its utc representation. We're keeping * it here for sometime, just for precaution, in case we decide to revert some of these changes * though. */ _this.useUtcForDisplay = true; _super.prototype.setLocale.call(_this, matDateLocale); // IE does its own time zone correction, so we disable this on IE. _this.useUtcForDisplay = !platform.TRIDENT; _this._clampDate = platform.TRIDENT || platform.EDGE; return _this; } NativeDateAdapter.prototype.getYear = function (date) { return date.getFullYear(); }; NativeDateAdapter.prototype.getMonth = function (date) { return date.getMonth(); }; NativeDateAdapter.prototype.getDate = function (date) { return date.getDate(); }; NativeDateAdapter.prototype.getDayOfWeek = function (date) { return date.getDay(); }; NativeDateAdapter.prototype.getMonthNames = function (style) { var _this = this; if (SUPPORTS_INTL_API) { var dtf_1 = new Intl.DateTimeFormat(this.locale, { month: style, timeZone: 'utc' }); return range(12, function (i) { return _this._stripDirectionalityCharacters(_this._format(dtf_1, new Date(2017, i, 1))); }); } return DEFAULT_MONTH_NAMES[style]; }; NativeDateAdapter.prototype.getDateNames = function () { var _this = this; if (SUPPORTS_INTL_API) { var dtf_2 = new Intl.DateTimeFormat(this.locale, { day: 'numeric', timeZone: 'utc' }); return range(31, function (i) { return _this._stripDirectionalityCharacters(_this._format(dtf_2, new Date(2017, 0, i + 1))); }); } return DEFAULT_DATE_NAMES; }; NativeDateAdapter.prototype.getDayOfWeekNames = function (style) { var _this = this; if (SUPPORTS_INTL_API) { var dtf_3 = new Intl.DateTimeFormat(this.locale, { weekday: style, timeZone: 'utc' }); return range(7, function (i) { return _this._stripDirectionalityCharacters(_this._format(dtf_3, new Date(2017, 0, i + 1))); }); } return DEFAULT_DAY_OF_WEEK_NAMES[style]; }; NativeDateAdapter.prototype.getYearName = function (date) { if (SUPPORTS_INTL_API) { var dtf = new Intl.DateTimeFormat(this.locale, { year: 'numeric', timeZone: 'utc' }); return this._stripDirectionalityCharacters(this._format(dtf, date)); } return String(this.getYear(date)); }; 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; }; NativeDateAdapter.prototype.getNumDaysInMonth = function (date) { return this.getDate(this._createDateWithOverflow(this.getYear(date), this.getMonth(date) + 1, 0)); }; NativeDateAdapter.prototype.clone = function (date) { return new Date(date.getTime()); }; 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 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; }; NativeDateAdapter.prototype.today = function () { return new Date(); }; 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; }; NativeDateAdapter.prototype.format = function (date, displayFormat) { if (!this.isValid(date)) { throw Error('NativeDateAdapter: Cannot format invalid date.'); } if (SUPPORTS_INTL_API) { // On IE and Edge the i18n API will throw a hard error that can crash the entire app // if we attempt to format a date whose year is less than 1 or greater than 9999. if (this._clampDate && (date.getFullYear() < 1 || date.getFullYear() > 9999)) { date = this.clone(date); date.setFullYear(Math.max(1, Math.min(9999, date.getFullYear()))); } displayFormat = __assign(__assign({}, displayFormat), { timeZone: 'utc' }); var dtf = new Intl.DateTimeFormat(this.locale, displayFormat); return this._stripDirectionalityCharacters(this._format(dtf, date)); } return this._stripDirectionalityCharacters(date.toDateString()); }; NativeDateAdapter.prototype.addCalendarYears = function (date, years) { return this.addCalendarMonths(date, years * 12); }; NativeDateAdapter.prototype.addCalendarMonths = function (date, months) { var 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; }; NativeDateAdapter.prototype.addCalendarDays = function (date, days) { return this._createDateWithOverflow(this.getYear(date), this.getMonth(date), this.getDate(date) + days); }; NativeDateAdapter.prototype.toIso8601 = function (date) { return [ date.getUTCFullYear(), this._2digit(date.getUTCMonth() + 1), this._2digit(date.getUTCDate()) ].join('-'); }; /** * Returns the given value if given a valid Date or null. Deserializes valid ISO 8601 strings * (https://www.ietf.org/rfc/rfc3339.txt) into valid Dates and empty string into null. Returns an * invalid date for all other values. */ NativeDateAdapter.prototype.deserialize = function (value) { if (typeof value === 'string') { if (!value) { return null; } // 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(value)) { var date = new Date(value); if (this.isValid(date)) { return date; } } } return _super.prototype.deserialize.call(this, value); }; NativeDateAdapter.prototype.isDateInstance = function (obj) { return obj instanceof Date; }; NativeDateAdapter.prototype.isValid = function (date) { return !isNaN(date.getTime()); }; NativeDateAdapter.prototype.invalid = function () { return new Date(NaN); }; /** Creates a date but allows the month and date to overflow. */ NativeDateAdapter.prototype._createDateWithOverflow = function (year, month, date) { var 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. * @returns 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. * @returns The stripped string. */ NativeDateAdapter.prototype._stripDirectionalityCharacters = function (str) { return str.replace(/[\u200e\u200f]/g, ''); }; /** * When converting Date object to string, javascript built-in functions may return wrong * results because it applies its internal DST rules. The DST rules around the world change * very frequently, and the current valid rule is not always valid in previous years though. * We work around this problem building a new Date object which has its internal UTC * representation with the local date and time. * @param dtf Intl.DateTimeFormat object, containg the desired string format. It must have * timeZone set to 'utc' to work fine. * @param date Date from which we want to get the string representation according to dtf * @returns A Date object with its UTC representation based on the passed in date info */ NativeDateAdapter.prototype._format = function (dtf, date) { var d = new Date(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate(), date.getHours(), date.getMinutes(), date.getSeconds(), date.getMilliseconds())); return dtf.format(d); }; NativeDateAdapter.decorators = [ { type: i0.Injectable } ]; /** @nocollapse */ NativeDateAdapter.ctorParameters = function () { return [ { type: String, decorators: [{ type: i0.Optional }, { type: i0.Inject, args: [MAT_DATE_LOCALE,] }] }, { type: platform.Platform } ]; }; return NativeDateAdapter; }(DateAdapter)); /** * @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://angular.io/license */ var MAT_NATIVE_DATE_FORMATS = { parse: { dateInput: null, }, display: { dateInput: { year: 'numeric', month: 'numeric', day: 'numeric' }, monthYearLabel: { year: 'numeric', month: 'short' }, dateA11yLabel: { year: 'numeric', month: 'long', day: 'numeric' }, monthYearA11yLabel: { year: 'numeric', month: 'long' }, } }; /** * @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://angular.io/licens