UNPKG

@angular/material

Version:
1,157 lines (1,137 loc) 89.8 kB
import * as i0 from '@angular/core'; import { Version, InjectionToken, NgModule, Optional, Inject, inject, LOCALE_ID, Injectable, Directive, Input, Component, ViewEncapsulation, ChangeDetectionStrategy, EventEmitter, Output } from '@angular/core'; import * as i1 from '@angular/cdk/a11y'; import { isFakeMousedownFromScreenReader, isFakeTouchstartFromScreenReader } from '@angular/cdk/a11y'; import { BidiModule } from '@angular/cdk/bidi'; import { VERSION as VERSION$2 } from '@angular/cdk'; import * as i3 from '@angular/common'; import { DOCUMENT, CommonModule } from '@angular/common'; import * as i1$1 from '@angular/cdk/platform'; import { _isTestEnvironment, PlatformModule, normalizePassiveListenerOptions } from '@angular/cdk/platform'; import { coerceBooleanProperty, coerceNumberProperty, coerceElement } from '@angular/cdk/coercion'; import { Subject, Observable } from 'rxjs'; import { startWith } from 'rxjs/operators'; import { ANIMATION_MODULE_TYPE } from '@angular/platform-browser/animations'; import { ENTER, SPACE, hasModifierKey } from '@angular/cdk/keycodes'; /** * @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. */ const VERSION$1 = new Version('13.1.1'); /** * @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 */ class 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)'; /** @docs-private */ class AnimationDurations { } AnimationDurations.COMPLEX = '375ms'; AnimationDurations.ENTERING = '225ms'; AnimationDurations.EXITING = '195ms'; /** * @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 const VERSION = new Version('13.1.1'); /** @docs-private */ function MATERIAL_SANITY_CHECKS_FACTORY() { return true; } /** Injection token that configures whether the Material sanity checks are enabled. */ const MATERIAL_SANITY_CHECKS = new 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). */ class MatCommonModule { constructor(highContrastModeDetector, _sanityChecks, _document) { this._sanityChecks = _sanityChecks; this._document = _document; /** Whether we've done the global sanity checks (e.g. a theme is loaded, there is a doctype). */ this._hasDoneGlobalChecks = false; // While A11yModule also does this, we repeat it here to avoid importing A11yModule // in MatCommonModule. highContrastModeDetector._applyBodyHighContrastModeCssClasses(); if (!this._hasDoneGlobalChecks) { this._hasDoneGlobalChecks = true; if (typeof ngDevMode === 'undefined' || ngDevMode) { if (this._checkIsEnabled('doctype')) { _checkDoctypeIsDefined(this._document); } if (this._checkIsEnabled('theme')) { _checkThemeIsPresent(this._document); } if (this._checkIsEnabled('version')) { _checkCdkVersionMatch(); } } } } /** Gets whether a specific sanity check is enabled. */ _checkIsEnabled(name) { if (_isTestEnvironment()) { return false; } if (typeof this._sanityChecks === 'boolean') { return this._sanityChecks; } return !!this._sanityChecks[name]; } } MatCommonModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.1.0", ngImport: i0, type: MatCommonModule, deps: [{ token: i1.HighContrastModeDetector }, { token: MATERIAL_SANITY_CHECKS, optional: true }, { token: DOCUMENT }], target: i0.ɵɵFactoryTarget.NgModule }); MatCommonModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "13.1.0", ngImport: i0, type: MatCommonModule, imports: [BidiModule], exports: [BidiModule] }); MatCommonModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "13.1.0", ngImport: i0, type: MatCommonModule, imports: [[BidiModule], BidiModule] }); i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.1.0", ngImport: i0, type: MatCommonModule, decorators: [{ type: NgModule, args: [{ imports: [BidiModule], exports: [BidiModule], }] }], ctorParameters: function () { return [{ type: i1.HighContrastModeDetector }, { type: undefined, decorators: [{ type: Optional }, { type: Inject, args: [MATERIAL_SANITY_CHECKS] }] }, { type: Document, decorators: [{ type: Inject, args: [DOCUMENT] }] }]; } }); /** Checks that the page has a doctype. */ function _checkDoctypeIsDefined(doc) { if (!doc.doctype) { console.warn('Current document does not have a doctype. This may cause ' + 'some Angular Material components not to behave as expected.'); } } /** Checks that a theme has been included. */ function _checkThemeIsPresent(doc) { // 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`. if (!doc.body || typeof getComputedStyle !== 'function') { return; } const testElement = doc.createElement('div'); testElement.classList.add('mat-theme-loaded-marker'); doc.body.appendChild(testElement); const 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'); } testElement.remove(); } /** Checks whether the Material version matches the CDK version. */ function _checkCdkVersionMatch() { if (VERSION.full !== VERSION$2.full) { console.warn('The Angular Material version (' + VERSION.full + ') does not match ' + 'the Angular CDK version (' + VERSION$2.full + ').\n' + 'Please ensure the versions of these two packages exactly match.'); } } /** * @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 */ function mixinDisabled(base) { return class extends base { constructor(...args) { super(...args); this._disabled = false; } get disabled() { return this._disabled; } set disabled(value) { this._disabled = coerceBooleanProperty(value); } }; } /** * @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 */ function mixinColor(base, defaultColor) { return class extends base { constructor(...args) { super(...args); this.defaultColor = defaultColor; // Set the default color that can be specified from the mixin. this.color = defaultColor; } get color() { return this._color; } set color(value) { const colorPalette = value || this.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; } } }; } /** * @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 */ function mixinDisableRipple(base) { return class extends base { constructor(...args) { super(...args); this._disableRipple = false; } /** Whether the ripple effect is disabled or not. */ get disableRipple() { return this._disableRipple; } set disableRipple(value) { this._disableRipple = coerceBooleanProperty(value); } }; } /** * @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 */ function mixinTabIndex(base, defaultTabIndex = 0) { return class extends base { constructor(...args) { super(...args); this._tabIndex = defaultTabIndex; this.defaultTabIndex = defaultTabIndex; } get tabIndex() { return this.disabled ? -1 : this._tabIndex; } set tabIndex(value) { // If the specified tabIndex value is null or undefined, fall back to the default value. this._tabIndex = value != null ? coerceNumberProperty(value) : this.defaultTabIndex; } }; } /** * @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 */ function mixinErrorState(base) { return class extends base { constructor(...args) { super(...args); // This class member exists as an interop with `MatFormFieldControl` which expects // a public `stateChanges` observable to emit whenever the form field should be updated. // The description is not specifically mentioning the error state, as classes using this // mixin can/should emit an event in other cases too. /** Emits whenever the component state changes. */ this.stateChanges = new Subject(); /** Whether the component is in an error state. */ this.errorState = false; } /** Updates the error state based on the provided error state matcher. */ updateErrorState() { const oldState = this.errorState; const parent = this._parentFormGroup || this._parentForm; const matcher = this.errorStateMatcher || this._defaultErrorStateMatcher; const control = this.ngControl ? this.ngControl.control : null; const newState = matcher.isErrorState(control, parent); if (newState !== oldState) { this.errorState = newState; this.stateChanges.next(); } } }; } /** * @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 extends base { constructor(...args) { super(...args); /** 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 Observable(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); } }); } /** * Marks the state as initialized and notifies pending subscribers. Should be called at the end * of ngOnInit. * @docs-private */ _markInitialized() { if (this._isInitialized && (typeof ngDevMode === 'undefined' || ngDevMode)) { 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). */ _notifySubscriber(subscriber) { subscriber.next(); subscriber.complete(); } }; } /** * @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. */ const MAT_DATE_LOCALE = new InjectionToken('MAT_DATE_LOCALE', { providedIn: 'root', factory: MAT_DATE_LOCALE_FACTORY, }); /** @docs-private */ function MAT_DATE_LOCALE_FACTORY() { return inject(LOCALE_ID); } /** Adapts type `D` to be usable as a date by cdk-based components that work with dates. */ class DateAdapter { constructor() { this._localeChanges = new Subject(); /** A stream that emits when the locale changes. */ this.localeChanges = this._localeChanges; } /** * Given a potential date object, returns that same date object if it is * a valid date, or `null` if it's not a valid date. * @param obj The object to check. * @returns A date or `null`. */ getValidDateOrNull(obj) { return this.isDateInstance(obj) && this.isValid(obj) ? obj : null; } /** * 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. */ deserialize(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. */ setLocale(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. */ compareDate(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. */ sameDate(first, second) { if (first && second) { let firstValid = this.isValid(first); let 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`. */ clampDate(date, min, max) { if (min && this.compareDate(date, min) < 0) { return min; } if (max && this.compareDate(date, max) > 0) { return max; } return date; } } /** * @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 */ const MAT_DATE_FORMATS = new 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 */ /** * 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. */ const 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) { const valuesArray = Array(length); for (let 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. */ class NativeDateAdapter extends DateAdapter { constructor(matDateLocale, /** * @deprecated No longer being used. To be removed. * @breaking-change 14.0.0 */ _platform) { super(); /** * @deprecated No longer being used. To be removed. * @breaking-change 14.0.0 */ this.useUtcForDisplay = false; super.setLocale(matDateLocale); } getYear(date) { return date.getFullYear(); } getMonth(date) { return date.getMonth(); } getDate(date) { return date.getDate(); } getDayOfWeek(date) { return date.getDay(); } getMonthNames(style) { const dtf = new Intl.DateTimeFormat(this.locale, { month: style, timeZone: 'utc' }); return range(12, i => this._format(dtf, new Date(2017, i, 1))); } getDateNames() { const dtf = new Intl.DateTimeFormat(this.locale, { day: 'numeric', timeZone: 'utc' }); return range(31, i => this._format(dtf, new Date(2017, 0, i + 1))); } getDayOfWeekNames(style) { const dtf = new Intl.DateTimeFormat(this.locale, { weekday: style, timeZone: 'utc' }); return range(7, i => this._format(dtf, new Date(2017, 0, i + 1))); } getYearName(date) { const dtf = new Intl.DateTimeFormat(this.locale, { year: 'numeric', timeZone: 'utc' }); return this._format(dtf, date); } getFirstDayOfWeek() { // We can't tell using native JS Date what the first day of the week is, we default to Sunday. return 0; } getNumDaysInMonth(date) { return this.getDate(this._createDateWithOverflow(this.getYear(date), this.getMonth(date) + 1, 0)); } clone(date) { return new Date(date.getTime()); } createDate(year, month, date) { if (typeof ngDevMode === 'undefined' || ngDevMode) { // 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.`); } } let 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 && (typeof ngDevMode === 'undefined' || ngDevMode)) { throw Error(`Invalid date "${date}" for month with index "${month}".`); } return result; } today() { return new Date(); } parse(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; } format(date, displayFormat) { if (!this.isValid(date)) { throw Error('NativeDateAdapter: Cannot format invalid date.'); } const dtf = new Intl.DateTimeFormat(this.locale, { ...displayFormat, timeZone: 'utc' }); return this._format(dtf, date); } addCalendarYears(date, years) { return this.addCalendarMonths(date, years * 12); } addCalendarMonths(date, months) { let 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; } addCalendarDays(date, days) { return this._createDateWithOverflow(this.getYear(date), this.getMonth(date), this.getDate(date) + days); } toIso8601(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. */ deserialize(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)) { let date = new Date(value); if (this.isValid(date)) { return date; } } } return super.deserialize(value); } isDateInstance(obj) { return obj instanceof Date; } isValid(date) { return !isNaN(date.getTime()); } invalid() { return new Date(NaN); } /** Creates a date but allows the month and date to overflow. */ _createDateWithOverflow(year, month, date) { // Passing the year to the constructor causes year numbers <100 to be converted to 19xx. // To work around this we use `setFullYear` and `setHours` instead. const d = new Date(); d.setFullYear(year, month, date); d.setHours(0, 0, 0, 0); return d; } /** * Pads a number to make it two digits. * @param n The number to pad. * @returns The padded number. */ _2digit(n) { return ('00' + n).slice(-2); } /** * 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 */ _format(dtf, date) { // Passing the year to the constructor causes year numbers <100 to be converted to 19xx. // To work around this we use `setUTCFullYear` and `setUTCHours` instead. const d = new Date(); d.setUTCFullYear(date.getFullYear(), date.getMonth(), date.getDate()); d.setUTCHours(date.getHours(), date.getMinutes(), date.getSeconds(), date.getMilliseconds()); return dtf.format(d); } } NativeDateAdapter.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.1.0", ngImport: i0, type: NativeDateAdapter, deps: [{ token: MAT_DATE_LOCALE, optional: true }, { token: i1$1.Platform }], target: i0.ɵɵFactoryTarget.Injectable }); NativeDateAdapter.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.1.0", ngImport: i0, type: NativeDateAdapter }); i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.1.0", ngImport: i0, type: NativeDateAdapter, decorators: [{ type: Injectable }], ctorParameters: function () { return [{ type: undefined, decorators: [{ type: Optional }, { type: Inject, args: [MAT_DATE_LOCALE] }] }, { type: i1$1.Platform }]; } }); /** * @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 */ const 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/license */ class NativeDateModule { } NativeDateModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.1.0", ngImport: i0, type: NativeDateModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); NativeDateModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "13.1.0", ngImport: i0, type: NativeDateModule, imports: [PlatformModule] }); NativeDateModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "13.1.0", ngImport: i0, type: NativeDateModule, providers: [{ provide: DateAdapter, useClass: NativeDateAdapter }], imports: [[PlatformModule]] }); i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.1.0", ngImport: i0, type: NativeDateModule, decorators: [{ type: NgModule, args: [{ imports: [PlatformModule], providers: [{ provide: DateAdapter, useClass: NativeDateAdapter }], }] }] }); class MatNativeDateModule { } MatNativeDateModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.1.0", ngImport: i0, type: MatNativeDateModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); MatNativeDateModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "13.1.0", ngImport: i0, type: MatNativeDateModule, imports: [NativeDateModule] }); MatNativeDateModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "13.1.0", ngImport: i0, type: MatNativeDateModule, providers: [{ provide: MAT_DATE_FORMATS, useValue: MAT_NATIVE_DATE_FORMATS }], imports: [[NativeDateModule]] }); i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.1.0", ngImport: i0, type: MatNativeDateModule, decorators: [{ type: NgModule, args: [{ imports: [NativeDateModule], providers: [{ provide: MAT_DATE_FORMATS, useValue: MAT_NATIVE_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 */ /** Error state matcher that matches when a control is invalid and dirty. */ class ShowOnDirtyErrorStateMatcher { isErrorState(control, form) { return !!(control && control.invalid && (control.dirty || (form && form.submitted))); } } ShowOnDirtyErrorStateMatcher.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.1.0", ngImport: i0, type: ShowOnDirtyErrorStateMatcher, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); ShowOnDirtyErrorStateMatcher.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.1.0", ngImport: i0, type: ShowOnDirtyErrorStateMatcher }); i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.1.0", ngImport: i0, type: ShowOnDirtyErrorStateMatcher, decorators: [{ type: Injectable }] }); /** Provider that defines how form controls behave with regards to displaying error messages. */ class ErrorStateMatcher { isErrorState(control, form) { return !!(control && control.invalid && (control.touched || (form && form.submitted))); } } ErrorStateMatcher.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.1.0", ngImport: i0, type: ErrorStateMatcher, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); ErrorStateMatcher.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.1.0", ngImport: i0, type: ErrorStateMatcher, providedIn: 'root' }); i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.1.0", ngImport: i0, type: ErrorStateMatcher, decorators: [{ type: Injectable, args: [{ providedIn: 'root' }] }] }); /** * @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 */ /** * Shared directive to count lines inside a text area, such as a list item. * Line elements can be extracted with a @ContentChildren(MatLine) query, then * counted by checking the query list's length. */ class MatLine { } MatLine.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.1.0", ngImport: i0, type: MatLine, deps: [], target: i0.ɵɵFactoryTarget.Directive }); MatLine.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "13.1.0", type: MatLine, selector: "[mat-line], [matLine]", host: { classAttribute: "mat-line" }, ngImport: i0 }); i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.1.0", ngImport: i0, type: MatLine, decorators: [{ type: Directive, args: [{ selector: '[mat-line], [matLine]', host: { 'class': 'mat-line' }, }] }] }); /** * Helper that takes a query list of lines and sets the correct class on the host. * @docs-private */ function setLines(lines, element, prefix = 'mat') { // Note: doesn't need to unsubscribe, because `changes` // gets completed by Angular when the view is destroyed. lines.changes.pipe(startWith(lines)).subscribe(({ length }) => { setClass(element, `${prefix}-2-line`, false); setClass(element, `${prefix}-3-line`, false); setClass(element, `${prefix}-multi-line`, false); if (length === 2 || length === 3) { setClass(element, `${prefix}-${length}-line`, true); } else if (length > 3) { setClass(element, `${prefix}-multi-line`, true); } }); } /** Adds or removes a class from an element. */ function setClass(element, className, isAdd) { element.nativeElement.classList.toggle(className, isAdd); } class MatLineModule { } MatLineModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.1.0", ngImport: i0, type: MatLineModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); MatLineModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "13.1.0", ngImport: i0, type: MatLineModule, declarations: [MatLine], imports: [MatCommonModule], exports: [MatLine, MatCommonModule] }); MatLineModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "13.1.0", ngImport: i0, type: MatLineModule, imports: [[MatCommonModule], MatCommonModule] }); i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.1.0", ngImport: i0, type: MatLineModule, decorators: [{ type: NgModule, args: [{ imports: [MatCommonModule], exports: [MatLine, MatCommonModule], declarations: [MatLine], }] }] }); /** * @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 */ /** * Reference to a previously launched ripple element. */ class RippleRef { constructor(_renderer, /** Reference to the ripple HTML element. */ element, /** Ripple configuration used for the ripple. */ config) { this._renderer = _renderer; this.element = element; this.config = config; /** Current state of the ripple. */ this.state = 3 /* HIDDEN */; } /** Fades out the ripple element. */ fadeOut() { this._renderer.fadeOutRipple(this); } } // TODO: import these values from `@material/ripple` eventually. /** * Default ripple animation configuration for ripples without an explicit * animation config specified. */ const defaultRippleAnimationConfig = { enterDuration: 225, exitDuration: 150, }; /** * Timeout for ignoring mouse events. Mouse events will be temporary ignored after touch * events to avoid synthetic mouse events. */ const ignoreMouseEventsTimeout = 800; /** Options that apply to all the event listeners that are bound by the ripple renderer. */ const passiveEventOptions = normalizePassiveListenerOptions({ passive: true }); /** Events that signal that the pointer is down. */ const pointerDownEvents = ['mousedown', 'touchstart']; /** Events that signal that the pointer is up. */ const pointerUpEvents = ['mouseup', 'mouseleave', 'touchend', 'touchcancel']; /** * 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 */ class RippleRenderer { constructor(_target, _ngZone, elementOrElementRef, platform) { this._target = _target; this._ngZone = _ngZone; /** Whether the pointer is currently down or not. */ this._isPointerDown = false; /** Set of currently active ripple references. */ this._activeRipples = new Set(); /** Whether pointer-up event listeners have been registered. */ this._pointerUpEventsRegistered = false; // Only do anything if we're on the browser. if (platform.isBrowser) { this._containerElement = coerceElement(elementOrElementRef); } } /** * 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 Coordinate within the element, along the Y axis at which to start the ripple. * @param config Extra ripple options. */ fadeInRipple(x, y, config = {}) { const containerRect = (this._containerRect = this._containerRect || this._containerElement.getBoundingClientRect()); const animationConfig = { ...defaultRippleAnimationConfig, ...config.animation }; if (config.centered) { x = containerRect.left + containerRect.width / 2; y = containerRect.top + containerRect.height / 2; } const radius = config.radius || distanceToFurthestCorner(x, y, containerRect); const offsetX = x - containerRect.left; const offsetY = y - containerRect.top; const duration = animationConfig.enterDuration; const 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 a custom color has been specified, set it as inline style. If no color is // set, the default color will be applied through the ripple theme styles. if (config.color != null) { ripple.style.backgroundColor = config.color; } 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. const rippleRef = new RippleRef(this, ripple, config); rippleRef.state = 0 /* FADING_IN */; // Add the ripple reference to the list of all active ripples. this._activeRipples.add(rippleRef); if (!config.persistent) { this._mostRecentTransientRipple = 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(() => { const isMostRecentTransientRipple = rippleRef === this._mostRecentTransientRipple; rippleRef.state = 1 /* VISIBLE */; // When the timer runs out while the user has kept their pointer down, we want to // keep only the persistent ripples and the latest transient ripple. We do this, // because we don't want stacked transient ripples to appear after their enter // animation has finished. if (!config.persistent && (!isMostRecentTransientRipple || !this._isPointerDown)) { rippleRef.fadeOut(); } }, duration); return rippleRef; } /** Fades out a ripple reference. */ fadeOutRipple(rippleRef) { const wasActive = this._activeRipples.delete(rippleRef); if (rippleRef === this._mostRecentTransientRipple) { this._mostRecentTransientRipple = null; } // Clear out the cached bounding rect if we have no more ripples. if (!this._activeRipples.size) { this._containerRect = null; } // For ripples that are not active anymore, don't re-run the fade-out animation. if (!wasActive) { return; } const rippleEl = rippleRef.element; const animationConfig = { ...defaultRippleAnimationConfig, ...rippleRef.config.animation }; rippleEl.style.transitionDuration = `${animationConfig.exitDuration}ms`; rippleEl.style.opacity = '0'; rippleRef.state = 2 /* FADING_OUT */; // Once the ripple faded out, the ripple can be safely removed from the DOM. this._runTimeoutOutsideZone(() => { rippleRef.state = 3 /* HIDDEN */; rippleEl.remove(); }, animationConfig.exitDuration); } /** Fades out all currently active ripples. */ fadeOutAll() { this._activeRipples.forEach(ripple => ripple.fadeOut()); } /** Fades out all currently active non-persistent ripples. */ fadeOutAllNonPersistent() { this._activeRipples.forEach(ripple => { if (!ripple.config.persistent) { ripple.fadeOut(); } }); } /** Sets up the trigger event listeners */ setupTriggerEvents(elementOrElementRef) { const element = coerceElement(elementOrElementRef); if (!element || element === this._triggerElement) { return; } // Remove all previously registered event listeners from the trigger element. this._removeTriggerEvents(); this._triggerElement = element; this._registerEvents(pointerDownEvents); } /** * Handles all registered events. * @docs-private */ handleEvent(event) { if (event.type === 'mousedown') { this._onMousedown(event); } else if (event.type === 'touchstart') { this._onTouchStart(event); } else { this._onPointerUp(); } // If pointer-up events haven't been registered yet, do so now. // We do this on-demand in order to reduce the total number of event listeners // registered by the ripples, which speeds up the rendering time for large UIs. if (!this._pointerUpEventsRegistered) { this._registerEvents(pointerUpEvents); this._pointerUpEventsRegistered = true; } } /** Function being called whenever the trigger is being pressed using mouse. */ _onMousedown(event) { // Screen readers will fire fake mouse events for space/enter. Skip launching a // ripple in this case for consistency with the non-screen-reader experience. const isFakeMousedown = isFakeMousedownFromScreenReader(event); const isSyntheticEvent = this._lastTouchStartEvent && Date.now() < this._lastTouchStartEvent + ignoreMouseEventsTimeout; if (!this._target.rippleDisabled && !isFakeMousedown && !isSyntheticEvent) { this._isPointerDown = true; this.fadeInRipple(event.clientX, event.clientY, this._target.rippleConfig); } } /** Function being called whenever the trigger is being pressed using touch. */ _onTouchStart(event) { if (!this._target.rippleDisabled && !isFakeTouchstartFromScreenReader(event)) { // Some browsers fire mouse events after a `touchstart` event. Those synthetic mouse // events will launch a second ripple if we don't ignore mouse events for a specific // time after a touchstart event. this._lastTouchStartEvent = Date.now(); this._isPointerDown = true; // Use `changedTouches` so we skip any touches where the user put // their finger down, but used another finger to tap the element again. const touches = event.changedTouches; for (let i = 0; i < touches.length; i++) { this.fadeInRipple(touches[i].clientX, touches[i].clientY, this._target.rippleConfig); } } } /** Function being called whenever the trigger is being released. */ _onPointerUp() { if (!this._isPointerDown) { return; } this._isPointerDown = false; // Fade-out all ripples that are visible and not persistent. this._activeRipples.forEach(ripple => { // By default, only ripples that are completely visible will fade out on pointer release. // If the `terminateOnPointerUp` option is set, ripples that still fade in will also fade out. const isVisible = ripple.state === 1 /* VISIBLE */ || (ripple.config.terminateOnPointerUp && ripple.state === 0 /* FADING_IN */); if (!ripple.config.persistent && isVisible) { ripple.fadeOut(); } }); } /** Runs a timeout outside of the Angular zone to avoid triggering the change detection. */ _runTimeoutOutsideZone(fn, delay = 0) { this._ngZone.runOutsideAngular(() => setTimeout(fn, delay)); } /** Registers event listeners for a given list of events. */ _registerEvents(eventTypes) { this._ngZone.runOutsideAngular(() => { eventTypes.forEach(type => { this._triggerElement.addEventListener(type, this, passiveEventOptions); }); }); } /** Removes previously registered event listeners from the trigger element. */ _removeTriggerEvents() { if (this._triggerElement) { pointerDownEvents.forEach(type => { this._triggerElement.removeEventListener(type, this, passiveEventOptions); }); if (this._pointerUpEventsRegistered) { pointerUpEvents.forEach(type => { this._triggerElement.removeEventListener(type, this, passiveEventOptions); }); } } } } /** Enforces a style recalculation of a DOM element by computing its styles. */ 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. */ function distanceToFurthestCorner(x, y, rect) { const distX = Math.max(Math.abs(x - rect.left), Math.abs(x - rect.right)); const distY = Math.max(Math.abs(y - rect.top), Math.abs(y - rect.bottom)); return Math.sqrt(distX * distX + distY * distY); } /** * @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 */ /** Injection token that can be used to specify the global ripple options. */ const MAT_RIPPLE_GLOBAL_OPTIONS = new InjectionToken('mat-ripple-global-options'); class MatRipple { constructor(_elementRef, ngZone, platform, globalOptions, _animationMode) { this._elementRef = _elementRef; this._animationMode = _animationMode; /** * 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; this._disabled = false; /** Whether ripple directive is initialized and the input bindings are set. */ this._isInitialized = false; this._globalOptions = globalOptions || {}; this._rippleRenderer = new RippleRenderer(this, ngZone, _elementRef, platform); } /** * Whether click events will not trigger the ripple. Ripples can be still launched manually * by using the `launch()` method. */ get disabled() { return this._d