core.js 85 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406
  1. /**
  2. * @license
  3. * Copyright Google LLC All Rights Reserved.
  4. *
  5. * Use of this source code is governed by an MIT-style license that can be
  6. * found in the LICENSE file at https://angular.io/license
  7. */
  8. import { Version, NgModule, InjectionToken, Optional, Inject, isDevMode, inject, LOCALE_ID, Injectable, Directive, ElementRef, Input, NgZone, Component, ViewEncapsulation, ChangeDetectionStrategy, ChangeDetectorRef, EventEmitter, Output, ɵɵdefineInjectable } from '@angular/core';
  9. import { HAMMER_LOADER, HammerGestureConfig } from '@angular/platform-browser';
  10. import { BidiModule } from '@angular/cdk/bidi';
  11. import { VERSION } from '@angular/cdk';
  12. import { coerceBooleanProperty } from '@angular/cdk/coercion';
  13. import { Subject, Observable } from 'rxjs';
  14. import { Platform, PlatformModule, normalizePassiveListenerOptions } from '@angular/cdk/platform';
  15. import { startWith } from 'rxjs/operators';
  16. import { isFakeMousedownFromScreenReader } from '@angular/cdk/a11y';
  17. import { ANIMATION_MODULE_TYPE } from '@angular/platform-browser/animations';
  18. import { ENTER, SPACE, hasModifierKey } from '@angular/cdk/keycodes';
  19. import { CommonModule } from '@angular/common';
  20. /**
  21. * @fileoverview added by tsickle
  22. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  23. */
  24. /**
  25. * Current version of Angular Material.
  26. * @type {?}
  27. */
  28. const VERSION$1 = new Version('8.1.4');
  29. /**
  30. * @fileoverview added by tsickle
  31. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  32. */
  33. /**
  34. * \@docs-private
  35. */
  36. class AnimationCurves {
  37. }
  38. AnimationCurves.STANDARD_CURVE = 'cubic-bezier(0.4,0.0,0.2,1)';
  39. AnimationCurves.DECELERATION_CURVE = 'cubic-bezier(0.0,0.0,0.2,1)';
  40. AnimationCurves.ACCELERATION_CURVE = 'cubic-bezier(0.4,0.0,1,1)';
  41. AnimationCurves.SHARP_CURVE = 'cubic-bezier(0.4,0.0,0.6,1)';
  42. /**
  43. * \@docs-private
  44. */
  45. class AnimationDurations {
  46. }
  47. AnimationDurations.COMPLEX = '375ms';
  48. AnimationDurations.ENTERING = '225ms';
  49. AnimationDurations.EXITING = '195ms';
  50. /**
  51. * @fileoverview added by tsickle
  52. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  53. */
  54. // Private version constant to circumvent test/build issues,
  55. // i.e. avoid core to depend on the @angular/material primary entry-point
  56. // Can be removed once the Material primary entry-point no longer
  57. // re-exports all secondary entry-points
  58. /** @type {?} */
  59. const VERSION$2 = new Version('8.1.4');
  60. /**
  61. * Injection token that configures whether the Material sanity checks are enabled.
  62. * @type {?}
  63. */
  64. const MATERIAL_SANITY_CHECKS = new InjectionToken('mat-sanity-checks', {
  65. providedIn: 'root',
  66. factory: MATERIAL_SANITY_CHECKS_FACTORY,
  67. });
  68. /**
  69. * \@docs-private
  70. * @return {?}
  71. */
  72. function MATERIAL_SANITY_CHECKS_FACTORY() {
  73. return true;
  74. }
  75. /**
  76. * Module that captures anything that should be loaded and/or run for *all* Angular Material
  77. * components. This includes Bidi, etc.
  78. *
  79. * This module should be imported to each top-level component module (e.g., MatTabsModule).
  80. */
  81. class MatCommonModule {
  82. /**
  83. * @param {?} _sanityChecksEnabled
  84. * @param {?=} _hammerLoader
  85. */
  86. constructor(_sanityChecksEnabled, _hammerLoader) {
  87. this._sanityChecksEnabled = _sanityChecksEnabled;
  88. this._hammerLoader = _hammerLoader;
  89. /**
  90. * Whether we've done the global sanity checks (e.g. a theme is loaded, there is a doctype).
  91. */
  92. this._hasDoneGlobalChecks = false;
  93. /**
  94. * Whether we've already checked for HammerJs availability.
  95. */
  96. this._hasCheckedHammer = false;
  97. /**
  98. * Reference to the global `document` object.
  99. */
  100. this._document = typeof document === 'object' && document ? document : null;
  101. /**
  102. * Reference to the global 'window' object.
  103. */
  104. this._window = typeof window === 'object' && window ? window : null;
  105. if (this._areChecksEnabled() && !this._hasDoneGlobalChecks) {
  106. this._checkDoctypeIsDefined();
  107. this._checkThemeIsPresent();
  108. this._checkCdkVersionMatch();
  109. this._hasDoneGlobalChecks = true;
  110. }
  111. }
  112. /**
  113. * Whether any sanity checks are enabled
  114. * @private
  115. * @return {?}
  116. */
  117. _areChecksEnabled() {
  118. return this._sanityChecksEnabled && isDevMode() && !this._isTestEnv();
  119. }
  120. /**
  121. * Whether the code is running in tests.
  122. * @private
  123. * @return {?}
  124. */
  125. _isTestEnv() {
  126. /** @type {?} */
  127. const window = (/** @type {?} */ (this._window));
  128. return window && (window.__karma__ || window.jasmine);
  129. }
  130. /**
  131. * @private
  132. * @return {?}
  133. */
  134. _checkDoctypeIsDefined() {
  135. if (this._document && !this._document.doctype) {
  136. console.warn('Current document does not have a doctype. This may cause ' +
  137. 'some Angular Material components not to behave as expected.');
  138. }
  139. }
  140. /**
  141. * @private
  142. * @return {?}
  143. */
  144. _checkThemeIsPresent() {
  145. // We need to assert that the `body` is defined, because these checks run very early
  146. // and the `body` won't be defined if the consumer put their scripts in the `head`.
  147. if (!this._document || !this._document.body || typeof getComputedStyle !== 'function') {
  148. return;
  149. }
  150. /** @type {?} */
  151. const testElement = this._document.createElement('div');
  152. testElement.classList.add('mat-theme-loaded-marker');
  153. this._document.body.appendChild(testElement);
  154. /** @type {?} */
  155. const computedStyle = getComputedStyle(testElement);
  156. // In some situations the computed style of the test element can be null. For example in
  157. // Firefox, the computed style is null if an application is running inside of a hidden iframe.
  158. // See: https://bugzilla.mozilla.org/show_bug.cgi?id=548397
  159. if (computedStyle && computedStyle.display !== 'none') {
  160. console.warn('Could not find Angular Material core theme. Most Material ' +
  161. 'components may not work as expected. For more info refer ' +
  162. 'to the theming guide: https://material.angular.io/guide/theming');
  163. }
  164. this._document.body.removeChild(testElement);
  165. }
  166. /**
  167. * Checks whether the material version matches the cdk version
  168. * @private
  169. * @return {?}
  170. */
  171. _checkCdkVersionMatch() {
  172. if (VERSION$2.full !== VERSION.full) {
  173. console.warn('The Angular Material version (' + VERSION$2.full + ') does not match ' +
  174. 'the Angular CDK version (' + VERSION.full + ').\n' +
  175. 'Please ensure the versions of these two packages exactly match.');
  176. }
  177. }
  178. /**
  179. * Checks whether HammerJS is available.
  180. * @return {?}
  181. */
  182. _checkHammerIsAvailable() {
  183. if (this._hasCheckedHammer || !this._window) {
  184. return;
  185. }
  186. if (this._areChecksEnabled() && !((/** @type {?} */ (this._window)))['Hammer'] && !this._hammerLoader) {
  187. console.warn('Could not find HammerJS. Certain Angular Material components may not work correctly.');
  188. }
  189. this._hasCheckedHammer = true;
  190. }
  191. }
  192. MatCommonModule.decorators = [
  193. { type: NgModule, args: [{
  194. imports: [BidiModule],
  195. exports: [BidiModule],
  196. },] },
  197. ];
  198. /** @nocollapse */
  199. MatCommonModule.ctorParameters = () => [
  200. { type: Boolean, decorators: [{ type: Optional }, { type: Inject, args: [MATERIAL_SANITY_CHECKS,] }] },
  201. { type: undefined, decorators: [{ type: Optional }, { type: Inject, args: [HAMMER_LOADER,] }] }
  202. ];
  203. /**
  204. * @fileoverview added by tsickle
  205. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  206. */
  207. /**
  208. * Mixin to augment a directive with a `disabled` property.
  209. * @template T
  210. * @param {?} base
  211. * @return {?}
  212. */
  213. function mixinDisabled(base) {
  214. return class extends base {
  215. /**
  216. * @param {...?} args
  217. */
  218. constructor(...args) {
  219. super(...args);
  220. this._disabled = false;
  221. }
  222. /**
  223. * @return {?}
  224. */
  225. get disabled() { return this._disabled; }
  226. /**
  227. * @param {?} value
  228. * @return {?}
  229. */
  230. set disabled(value) { this._disabled = coerceBooleanProperty(value); }
  231. };
  232. }
  233. /**
  234. * @fileoverview added by tsickle
  235. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  236. */
  237. /**
  238. * Mixin to augment a directive with a `color` property.
  239. * @template T
  240. * @param {?} base
  241. * @param {?=} defaultColor
  242. * @return {?}
  243. */
  244. function mixinColor(base, defaultColor) {
  245. return class extends base {
  246. /**
  247. * @return {?}
  248. */
  249. get color() { return this._color; }
  250. /**
  251. * @param {?} value
  252. * @return {?}
  253. */
  254. set color(value) {
  255. /** @type {?} */
  256. const colorPalette = value || defaultColor;
  257. if (colorPalette !== this._color) {
  258. if (this._color) {
  259. this._elementRef.nativeElement.classList.remove(`mat-${this._color}`);
  260. }
  261. if (colorPalette) {
  262. this._elementRef.nativeElement.classList.add(`mat-${colorPalette}`);
  263. }
  264. this._color = colorPalette;
  265. }
  266. }
  267. /**
  268. * @param {...?} args
  269. */
  270. constructor(...args) {
  271. super(...args);
  272. // Set the default color that can be specified from the mixin.
  273. this.color = defaultColor;
  274. }
  275. };
  276. }
  277. /**
  278. * @fileoverview added by tsickle
  279. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  280. */
  281. /**
  282. * Mixin to augment a directive with a `disableRipple` property.
  283. * @template T
  284. * @param {?} base
  285. * @return {?}
  286. */
  287. function mixinDisableRipple(base) {
  288. return class extends base {
  289. /**
  290. * @param {...?} args
  291. */
  292. constructor(...args) {
  293. super(...args);
  294. this._disableRipple = false;
  295. }
  296. /**
  297. * Whether the ripple effect is disabled or not.
  298. * @return {?}
  299. */
  300. get disableRipple() { return this._disableRipple; }
  301. /**
  302. * @param {?} value
  303. * @return {?}
  304. */
  305. set disableRipple(value) { this._disableRipple = coerceBooleanProperty(value); }
  306. };
  307. }
  308. /**
  309. * @fileoverview added by tsickle
  310. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  311. */
  312. /**
  313. * Mixin to augment a directive with a `tabIndex` property.
  314. * @template T
  315. * @param {?} base
  316. * @param {?=} defaultTabIndex
  317. * @return {?}
  318. */
  319. function mixinTabIndex(base, defaultTabIndex = 0) {
  320. return class extends base {
  321. /**
  322. * @param {...?} args
  323. */
  324. constructor(...args) {
  325. super(...args);
  326. this._tabIndex = defaultTabIndex;
  327. }
  328. /**
  329. * @return {?}
  330. */
  331. get tabIndex() { return this.disabled ? -1 : this._tabIndex; }
  332. /**
  333. * @param {?} value
  334. * @return {?}
  335. */
  336. set tabIndex(value) {
  337. // If the specified tabIndex value is null or undefined, fall back to the default value.
  338. this._tabIndex = value != null ? value : defaultTabIndex;
  339. }
  340. };
  341. }
  342. /**
  343. * @fileoverview added by tsickle
  344. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  345. */
  346. /**
  347. * Mixin to augment a directive with updateErrorState method.
  348. * For component with `errorState` and need to update `errorState`.
  349. * @template T
  350. * @param {?} base
  351. * @return {?}
  352. */
  353. function mixinErrorState(base) {
  354. return class extends base {
  355. /**
  356. * @param {...?} args
  357. */
  358. constructor(...args) {
  359. super(...args);
  360. /**
  361. * Whether the component is in an error state.
  362. */
  363. this.errorState = false;
  364. /**
  365. * Stream that emits whenever the state of the input changes such that the wrapping
  366. * `MatFormField` needs to run change detection.
  367. */
  368. this.stateChanges = new Subject();
  369. }
  370. /**
  371. * @return {?}
  372. */
  373. updateErrorState() {
  374. /** @type {?} */
  375. const oldState = this.errorState;
  376. /** @type {?} */
  377. const parent = this._parentFormGroup || this._parentForm;
  378. /** @type {?} */
  379. const matcher = this.errorStateMatcher || this._defaultErrorStateMatcher;
  380. /** @type {?} */
  381. const control = this.ngControl ? (/** @type {?} */ (this.ngControl.control)) : null;
  382. /** @type {?} */
  383. const newState = matcher.isErrorState(control, parent);
  384. if (newState !== oldState) {
  385. this.errorState = newState;
  386. this.stateChanges.next();
  387. }
  388. }
  389. };
  390. }
  391. /**
  392. * @fileoverview added by tsickle
  393. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  394. */
  395. /**
  396. * Mixin to augment a directive with an initialized property that will emits when ngOnInit ends.
  397. * @template T
  398. * @param {?} base
  399. * @return {?}
  400. */
  401. function mixinInitialized(base) {
  402. return class extends base {
  403. /**
  404. * @param {...?} args
  405. */
  406. constructor(...args) {
  407. super(...args);
  408. /**
  409. * Whether this directive has been marked as initialized.
  410. */
  411. this._isInitialized = false;
  412. /**
  413. * List of subscribers that subscribed before the directive was initialized. Should be notified
  414. * during _markInitialized. Set to null after pending subscribers are notified, and should
  415. * not expect to be populated after.
  416. */
  417. this._pendingSubscribers = [];
  418. /**
  419. * Observable stream that emits when the directive initializes. If already initialized, the
  420. * subscriber is stored to be notified once _markInitialized is called.
  421. */
  422. this.initialized = new Observable((/**
  423. * @param {?} subscriber
  424. * @return {?}
  425. */
  426. subscriber => {
  427. // If initialized, immediately notify the subscriber. Otherwise store the subscriber to notify
  428. // when _markInitialized is called.
  429. if (this._isInitialized) {
  430. this._notifySubscriber(subscriber);
  431. }
  432. else {
  433. (/** @type {?} */ (this._pendingSubscribers)).push(subscriber);
  434. }
  435. }));
  436. }
  437. /**
  438. * Marks the state as initialized and notifies pending subscribers. Should be called at the end
  439. * of ngOnInit.
  440. * \@docs-private
  441. * @return {?}
  442. */
  443. _markInitialized() {
  444. if (this._isInitialized) {
  445. throw Error('This directive has already been marked as initialized and ' +
  446. 'should not be called twice.');
  447. }
  448. this._isInitialized = true;
  449. (/** @type {?} */ (this._pendingSubscribers)).forEach(this._notifySubscriber);
  450. this._pendingSubscribers = null;
  451. }
  452. /**
  453. * Emits and completes the subscriber stream (should only emit once).
  454. * @param {?} subscriber
  455. * @return {?}
  456. */
  457. _notifySubscriber(subscriber) {
  458. subscriber.next();
  459. subscriber.complete();
  460. }
  461. };
  462. }
  463. /**
  464. * @fileoverview added by tsickle
  465. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  466. */
  467. /**
  468. * @fileoverview added by tsickle
  469. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  470. */
  471. /**
  472. * InjectionToken for datepicker that can be used to override default locale code.
  473. * @type {?}
  474. */
  475. const MAT_DATE_LOCALE = new InjectionToken('MAT_DATE_LOCALE', {
  476. providedIn: 'root',
  477. factory: MAT_DATE_LOCALE_FACTORY,
  478. });
  479. /**
  480. * \@docs-private
  481. * @return {?}
  482. */
  483. function MAT_DATE_LOCALE_FACTORY() {
  484. return inject(LOCALE_ID);
  485. }
  486. /**
  487. * No longer needed since MAT_DATE_LOCALE has been changed to a scoped injectable.
  488. * If you are importing and providing this in your code you can simply remove it.
  489. * @deprecated
  490. * \@breaking-change 8.0.0
  491. * @type {?}
  492. */
  493. const MAT_DATE_LOCALE_PROVIDER = { provide: MAT_DATE_LOCALE, useExisting: LOCALE_ID };
  494. /**
  495. * Adapts type `D` to be usable as a date by cdk-based components that work with dates.
  496. * @abstract
  497. * @template D
  498. */
  499. class DateAdapter {
  500. constructor() {
  501. this._localeChanges = new Subject();
  502. }
  503. /**
  504. * A stream that emits when the locale changes.
  505. * @return {?}
  506. */
  507. get localeChanges() { return this._localeChanges; }
  508. /**
  509. * Attempts to deserialize a value to a valid date object. This is different from parsing in that
  510. * deserialize should only accept non-ambiguous, locale-independent formats (e.g. a ISO 8601
  511. * string). The default implementation does not allow any deserialization, it simply checks that
  512. * the given value is already a valid date object or null. The `<mat-datepicker>` will call this
  513. * method on all of it's `\@Input()` properties that accept dates. It is therefore possible to
  514. * support passing values from your backend directly to these properties by overriding this method
  515. * to also deserialize the format used by your backend.
  516. * @param {?} value The value to be deserialized into a date object.
  517. * @return {?} The deserialized date object, either a valid date, null if the value can be
  518. * deserialized into a null date (e.g. the empty string), or an invalid date.
  519. */
  520. deserialize(value) {
  521. if (value == null || this.isDateInstance(value) && this.isValid(value)) {
  522. return value;
  523. }
  524. return this.invalid();
  525. }
  526. /**
  527. * Sets the locale used for all dates.
  528. * @param {?} locale The new locale.
  529. * @return {?}
  530. */
  531. setLocale(locale) {
  532. this.locale = locale;
  533. this._localeChanges.next();
  534. }
  535. /**
  536. * Compares two dates.
  537. * @param {?} first The first date to compare.
  538. * @param {?} second The second date to compare.
  539. * @return {?} 0 if the dates are equal, a number less than 0 if the first date is earlier,
  540. * a number greater than 0 if the first date is later.
  541. */
  542. compareDate(first, second) {
  543. return this.getYear(first) - this.getYear(second) ||
  544. this.getMonth(first) - this.getMonth(second) ||
  545. this.getDate(first) - this.getDate(second);
  546. }
  547. /**
  548. * Checks if two dates are equal.
  549. * @param {?} first The first date to check.
  550. * @param {?} second The second date to check.
  551. * @return {?} Whether the two dates are equal.
  552. * Null dates are considered equal to other null dates.
  553. */
  554. sameDate(first, second) {
  555. if (first && second) {
  556. /** @type {?} */
  557. let firstValid = this.isValid(first);
  558. /** @type {?} */
  559. let secondValid = this.isValid(second);
  560. if (firstValid && secondValid) {
  561. return !this.compareDate(first, second);
  562. }
  563. return firstValid == secondValid;
  564. }
  565. return first == second;
  566. }
  567. /**
  568. * Clamp the given date between min and max dates.
  569. * @param {?} date The date to clamp.
  570. * @param {?=} min The minimum value to allow. If null or omitted no min is enforced.
  571. * @param {?=} max The maximum value to allow. If null or omitted no max is enforced.
  572. * @return {?} `min` if `date` is less than `min`, `max` if date is greater than `max`,
  573. * otherwise `date`.
  574. */
  575. clampDate(date, min, max) {
  576. if (min && this.compareDate(date, min) < 0) {
  577. return min;
  578. }
  579. if (max && this.compareDate(date, max) > 0) {
  580. return max;
  581. }
  582. return date;
  583. }
  584. }
  585. /**
  586. * @fileoverview added by tsickle
  587. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  588. */
  589. /** @type {?} */
  590. const MAT_DATE_FORMATS = new InjectionToken('mat-date-formats');
  591. /**
  592. * @fileoverview added by tsickle
  593. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  594. */
  595. // TODO(mmalerba): Remove when we no longer support safari 9.
  596. /**
  597. * Whether the browser supports the Intl API.
  598. * @type {?}
  599. */
  600. let SUPPORTS_INTL_API;
  601. // We need a try/catch around the reference to `Intl`, because accessing it in some cases can
  602. // cause IE to throw. These cases are tied to particular versions of Windows and can happen if
  603. // the consumer is providing a polyfilled `Map`. See:
  604. // https://github.com/Microsoft/ChakraCore/issues/3189
  605. // https://github.com/angular/components/issues/15687
  606. try {
  607. SUPPORTS_INTL_API = typeof Intl != 'undefined';
  608. }
  609. catch (_a) {
  610. SUPPORTS_INTL_API = false;
  611. }
  612. /**
  613. * The default month names to use if Intl API is not available.
  614. * @type {?}
  615. */
  616. const DEFAULT_MONTH_NAMES = {
  617. 'long': [
  618. 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September',
  619. 'October', 'November', 'December'
  620. ],
  621. 'short': ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
  622. 'narrow': ['J', 'F', 'M', 'A', 'M', 'J', 'J', 'A', 'S', 'O', 'N', 'D']
  623. };
  624. const ɵ0 = /**
  625. * @param {?} i
  626. * @return {?}
  627. */
  628. i => String(i + 1);
  629. /**
  630. * The default date names to use if Intl API is not available.
  631. * @type {?}
  632. */
  633. const DEFAULT_DATE_NAMES = range(31, (ɵ0));
  634. /**
  635. * The default day of the week names to use if Intl API is not available.
  636. * @type {?}
  637. */
  638. const DEFAULT_DAY_OF_WEEK_NAMES = {
  639. 'long': ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],
  640. 'short': ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
  641. 'narrow': ['S', 'M', 'T', 'W', 'T', 'F', 'S']
  642. };
  643. /**
  644. * Matches strings that have the form of a valid RFC 3339 string
  645. * (https://tools.ietf.org/html/rfc3339). Note that the string may not actually be a valid date
  646. * because the regex will match strings an with out of bounds month, date, etc.
  647. * @type {?}
  648. */
  649. const ISO_8601_REGEX = /^\d{4}-\d{2}-\d{2}(?:T\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|(?:(?:\+|-)\d{2}:\d{2}))?)?$/;
  650. /**
  651. * Creates an array and fills it with values.
  652. * @template T
  653. * @param {?} length
  654. * @param {?} valueFunction
  655. * @return {?}
  656. */
  657. function range(length, valueFunction) {
  658. /** @type {?} */
  659. const valuesArray = Array(length);
  660. for (let i = 0; i < length; i++) {
  661. valuesArray[i] = valueFunction(i);
  662. }
  663. return valuesArray;
  664. }
  665. /**
  666. * Adapts the native JS Date for use with cdk-based components that work with dates.
  667. */
  668. class NativeDateAdapter extends DateAdapter {
  669. /**
  670. * @param {?} matDateLocale
  671. * @param {?} platform
  672. */
  673. constructor(matDateLocale, platform) {
  674. super();
  675. /**
  676. * Whether to use `timeZone: 'utc'` with `Intl.DateTimeFormat` when formatting dates.
  677. * Without this `Intl.DateTimeFormat` sometimes chooses the wrong timeZone, which can throw off
  678. * the result. (e.g. in the en-US locale `new Date(1800, 7, 14).toLocaleDateString()`
  679. * will produce `'8/13/1800'`.
  680. *
  681. * TODO(mmalerba): drop this variable. It's not being used in the code right now. We're now
  682. * getting the string representation of a Date object from it's utc representation. We're keeping
  683. * it here for sometime, just for precaution, in case we decide to revert some of these changes
  684. * though.
  685. */
  686. this.useUtcForDisplay = true;
  687. super.setLocale(matDateLocale);
  688. // IE does its own time zone correction, so we disable this on IE.
  689. this.useUtcForDisplay = !platform.TRIDENT;
  690. this._clampDate = platform.TRIDENT || platform.EDGE;
  691. }
  692. /**
  693. * @param {?} date
  694. * @return {?}
  695. */
  696. getYear(date) {
  697. return date.getFullYear();
  698. }
  699. /**
  700. * @param {?} date
  701. * @return {?}
  702. */
  703. getMonth(date) {
  704. return date.getMonth();
  705. }
  706. /**
  707. * @param {?} date
  708. * @return {?}
  709. */
  710. getDate(date) {
  711. return date.getDate();
  712. }
  713. /**
  714. * @param {?} date
  715. * @return {?}
  716. */
  717. getDayOfWeek(date) {
  718. return date.getDay();
  719. }
  720. /**
  721. * @param {?} style
  722. * @return {?}
  723. */
  724. getMonthNames(style) {
  725. if (SUPPORTS_INTL_API) {
  726. /** @type {?} */
  727. const dtf = new Intl.DateTimeFormat(this.locale, { month: style, timeZone: 'utc' });
  728. return range(12, (/**
  729. * @param {?} i
  730. * @return {?}
  731. */
  732. i => this._stripDirectionalityCharacters(this._format(dtf, new Date(2017, i, 1)))));
  733. }
  734. return DEFAULT_MONTH_NAMES[style];
  735. }
  736. /**
  737. * @return {?}
  738. */
  739. getDateNames() {
  740. if (SUPPORTS_INTL_API) {
  741. /** @type {?} */
  742. const dtf = new Intl.DateTimeFormat(this.locale, { day: 'numeric', timeZone: 'utc' });
  743. return range(31, (/**
  744. * @param {?} i
  745. * @return {?}
  746. */
  747. i => this._stripDirectionalityCharacters(this._format(dtf, new Date(2017, 0, i + 1)))));
  748. }
  749. return DEFAULT_DATE_NAMES;
  750. }
  751. /**
  752. * @param {?} style
  753. * @return {?}
  754. */
  755. getDayOfWeekNames(style) {
  756. if (SUPPORTS_INTL_API) {
  757. /** @type {?} */
  758. const dtf = new Intl.DateTimeFormat(this.locale, { weekday: style, timeZone: 'utc' });
  759. return range(7, (/**
  760. * @param {?} i
  761. * @return {?}
  762. */
  763. i => this._stripDirectionalityCharacters(this._format(dtf, new Date(2017, 0, i + 1)))));
  764. }
  765. return DEFAULT_DAY_OF_WEEK_NAMES[style];
  766. }
  767. /**
  768. * @param {?} date
  769. * @return {?}
  770. */
  771. getYearName(date) {
  772. if (SUPPORTS_INTL_API) {
  773. /** @type {?} */
  774. const dtf = new Intl.DateTimeFormat(this.locale, { year: 'numeric', timeZone: 'utc' });
  775. return this._stripDirectionalityCharacters(this._format(dtf, date));
  776. }
  777. return String(this.getYear(date));
  778. }
  779. /**
  780. * @return {?}
  781. */
  782. getFirstDayOfWeek() {
  783. // We can't tell using native JS Date what the first day of the week is, we default to Sunday.
  784. return 0;
  785. }
  786. /**
  787. * @param {?} date
  788. * @return {?}
  789. */
  790. getNumDaysInMonth(date) {
  791. return this.getDate(this._createDateWithOverflow(this.getYear(date), this.getMonth(date) + 1, 0));
  792. }
  793. /**
  794. * @param {?} date
  795. * @return {?}
  796. */
  797. clone(date) {
  798. return new Date(date.getTime());
  799. }
  800. /**
  801. * @param {?} year
  802. * @param {?} month
  803. * @param {?} date
  804. * @return {?}
  805. */
  806. createDate(year, month, date) {
  807. // Check for invalid month and date (except upper bound on date which we have to check after
  808. // creating the Date).
  809. if (month < 0 || month > 11) {
  810. throw Error(`Invalid month index "${month}". Month index has to be between 0 and 11.`);
  811. }
  812. if (date < 1) {
  813. throw Error(`Invalid date "${date}". Date has to be greater than 0.`);
  814. }
  815. /** @type {?} */
  816. let result = this._createDateWithOverflow(year, month, date);
  817. // Check that the date wasn't above the upper bound for the month, causing the month to overflow
  818. if (result.getMonth() != month) {
  819. throw Error(`Invalid date "${date}" for month with index "${month}".`);
  820. }
  821. return result;
  822. }
  823. /**
  824. * @return {?}
  825. */
  826. today() {
  827. return new Date();
  828. }
  829. /**
  830. * @param {?} value
  831. * @return {?}
  832. */
  833. parse(value) {
  834. // We have no way using the native JS Date to set the parse format or locale, so we ignore these
  835. // parameters.
  836. if (typeof value == 'number') {
  837. return new Date(value);
  838. }
  839. return value ? new Date(Date.parse(value)) : null;
  840. }
  841. /**
  842. * @param {?} date
  843. * @param {?} displayFormat
  844. * @return {?}
  845. */
  846. format(date, displayFormat) {
  847. if (!this.isValid(date)) {
  848. throw Error('NativeDateAdapter: Cannot format invalid date.');
  849. }
  850. if (SUPPORTS_INTL_API) {
  851. // On IE and Edge the i18n API will throw a hard error that can crash the entire app
  852. // if we attempt to format a date whose year is less than 1 or greater than 9999.
  853. if (this._clampDate && (date.getFullYear() < 1 || date.getFullYear() > 9999)) {
  854. date = this.clone(date);
  855. date.setFullYear(Math.max(1, Math.min(9999, date.getFullYear())));
  856. }
  857. displayFormat = Object.assign({}, displayFormat, { timeZone: 'utc' });
  858. /** @type {?} */
  859. const dtf = new Intl.DateTimeFormat(this.locale, displayFormat);
  860. return this._stripDirectionalityCharacters(this._format(dtf, date));
  861. }
  862. return this._stripDirectionalityCharacters(date.toDateString());
  863. }
  864. /**
  865. * @param {?} date
  866. * @param {?} years
  867. * @return {?}
  868. */
  869. addCalendarYears(date, years) {
  870. return this.addCalendarMonths(date, years * 12);
  871. }
  872. /**
  873. * @param {?} date
  874. * @param {?} months
  875. * @return {?}
  876. */
  877. addCalendarMonths(date, months) {
  878. /** @type {?} */
  879. let newDate = this._createDateWithOverflow(this.getYear(date), this.getMonth(date) + months, this.getDate(date));
  880. // It's possible to wind up in the wrong month if the original month has more days than the new
  881. // month. In this case we want to go to the last day of the desired month.
  882. // Note: the additional + 12 % 12 ensures we end up with a positive number, since JS % doesn't
  883. // guarantee this.
  884. if (this.getMonth(newDate) != ((this.getMonth(date) + months) % 12 + 12) % 12) {
  885. newDate = this._createDateWithOverflow(this.getYear(newDate), this.getMonth(newDate), 0);
  886. }
  887. return newDate;
  888. }
  889. /**
  890. * @param {?} date
  891. * @param {?} days
  892. * @return {?}
  893. */
  894. addCalendarDays(date, days) {
  895. return this._createDateWithOverflow(this.getYear(date), this.getMonth(date), this.getDate(date) + days);
  896. }
  897. /**
  898. * @param {?} date
  899. * @return {?}
  900. */
  901. toIso8601(date) {
  902. return [
  903. date.getUTCFullYear(),
  904. this._2digit(date.getUTCMonth() + 1),
  905. this._2digit(date.getUTCDate())
  906. ].join('-');
  907. }
  908. /**
  909. * Returns the given value if given a valid Date or null. Deserializes valid ISO 8601 strings
  910. * (https://www.ietf.org/rfc/rfc3339.txt) into valid Dates and empty string into null. Returns an
  911. * invalid date for all other values.
  912. * @param {?} value
  913. * @return {?}
  914. */
  915. deserialize(value) {
  916. if (typeof value === 'string') {
  917. if (!value) {
  918. return null;
  919. }
  920. // The `Date` constructor accepts formats other than ISO 8601, so we need to make sure the
  921. // string is the right format first.
  922. if (ISO_8601_REGEX.test(value)) {
  923. /** @type {?} */
  924. let date = new Date(value);
  925. if (this.isValid(date)) {
  926. return date;
  927. }
  928. }
  929. }
  930. return super.deserialize(value);
  931. }
  932. /**
  933. * @param {?} obj
  934. * @return {?}
  935. */
  936. isDateInstance(obj) {
  937. return obj instanceof Date;
  938. }
  939. /**
  940. * @param {?} date
  941. * @return {?}
  942. */
  943. isValid(date) {
  944. return !isNaN(date.getTime());
  945. }
  946. /**
  947. * @return {?}
  948. */
  949. invalid() {
  950. return new Date(NaN);
  951. }
  952. /**
  953. * Creates a date but allows the month and date to overflow.
  954. * @private
  955. * @param {?} year
  956. * @param {?} month
  957. * @param {?} date
  958. * @return {?}
  959. */
  960. _createDateWithOverflow(year, month, date) {
  961. /** @type {?} */
  962. const result = new Date(year, month, date);
  963. // We need to correct for the fact that JS native Date treats years in range [0, 99] as
  964. // abbreviations for 19xx.
  965. if (year >= 0 && year < 100) {
  966. result.setFullYear(this.getYear(result) - 1900);
  967. }
  968. return result;
  969. }
  970. /**
  971. * Pads a number to make it two digits.
  972. * @private
  973. * @param {?} n The number to pad.
  974. * @return {?} The padded number.
  975. */
  976. _2digit(n) {
  977. return ('00' + n).slice(-2);
  978. }
  979. /**
  980. * Strip out unicode LTR and RTL characters. Edge and IE insert these into formatted dates while
  981. * other browsers do not. We remove them to make output consistent and because they interfere with
  982. * date parsing.
  983. * @private
  984. * @param {?} str The string to strip direction characters from.
  985. * @return {?} The stripped string.
  986. */
  987. _stripDirectionalityCharacters(str) {
  988. return str.replace(/[\u200e\u200f]/g, '');
  989. }
  990. /**
  991. * When converting Date object to string, javascript built-in functions may return wrong
  992. * results because it applies its internal DST rules. The DST rules around the world change
  993. * very frequently, and the current valid rule is not always valid in previous years though.
  994. * We work around this problem building a new Date object which has its internal UTC
  995. * representation with the local date and time.
  996. * @private
  997. * @param {?} dtf Intl.DateTimeFormat object, containg the desired string format. It must have
  998. * timeZone set to 'utc' to work fine.
  999. * @param {?} date Date from which we want to get the string representation according to dtf
  1000. * @return {?} A Date object with its UTC representation based on the passed in date info
  1001. */
  1002. _format(dtf, date) {
  1003. /** @type {?} */
  1004. const d = new Date(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate(), date.getHours(), date.getMinutes(), date.getSeconds(), date.getMilliseconds()));
  1005. return dtf.format(d);
  1006. }
  1007. }
  1008. NativeDateAdapter.decorators = [
  1009. { type: Injectable },
  1010. ];
  1011. /** @nocollapse */
  1012. NativeDateAdapter.ctorParameters = () => [
  1013. { type: String, decorators: [{ type: Optional }, { type: Inject, args: [MAT_DATE_LOCALE,] }] },
  1014. { type: Platform }
  1015. ];
  1016. /**
  1017. * @fileoverview added by tsickle
  1018. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  1019. */
  1020. /** @type {?} */
  1021. const MAT_NATIVE_DATE_FORMATS = {
  1022. parse: {
  1023. dateInput: null,
  1024. },
  1025. display: {
  1026. dateInput: { year: 'numeric', month: 'numeric', day: 'numeric' },
  1027. monthYearLabel: { year: 'numeric', month: 'short' },
  1028. dateA11yLabel: { year: 'numeric', month: 'long', day: 'numeric' },
  1029. monthYearA11yLabel: { year: 'numeric', month: 'long' },
  1030. }
  1031. };
  1032. /**
  1033. * @fileoverview added by tsickle
  1034. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  1035. */
  1036. class NativeDateModule {
  1037. }
  1038. NativeDateModule.decorators = [
  1039. { type: NgModule, args: [{
  1040. imports: [PlatformModule],
  1041. providers: [
  1042. { provide: DateAdapter, useClass: NativeDateAdapter },
  1043. ],
  1044. },] },
  1045. ];
  1046. const ɵ0$1 = MAT_NATIVE_DATE_FORMATS;
  1047. class MatNativeDateModule {
  1048. }
  1049. MatNativeDateModule.decorators = [
  1050. { type: NgModule, args: [{
  1051. imports: [NativeDateModule],
  1052. providers: [{ provide: MAT_DATE_FORMATS, useValue: ɵ0$1 }],
  1053. },] },
  1054. ];
  1055. /**
  1056. * @fileoverview added by tsickle
  1057. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  1058. */
  1059. /**
  1060. * Error state matcher that matches when a control is invalid and dirty.
  1061. */
  1062. class ShowOnDirtyErrorStateMatcher {
  1063. /**
  1064. * @param {?} control
  1065. * @param {?} form
  1066. * @return {?}
  1067. */
  1068. isErrorState(control, form) {
  1069. return !!(control && control.invalid && (control.dirty || (form && form.submitted)));
  1070. }
  1071. }
  1072. ShowOnDirtyErrorStateMatcher.decorators = [
  1073. { type: Injectable },
  1074. ];
  1075. /**
  1076. * Provider that defines how form controls behave with regards to displaying error messages.
  1077. */
  1078. class ErrorStateMatcher {
  1079. /**
  1080. * @param {?} control
  1081. * @param {?} form
  1082. * @return {?}
  1083. */
  1084. isErrorState(control, form) {
  1085. return !!(control && control.invalid && (control.touched || (form && form.submitted)));
  1086. }
  1087. }
  1088. ErrorStateMatcher.decorators = [
  1089. { type: Injectable, args: [{ providedIn: 'root' },] },
  1090. ];
  1091. /** @nocollapse */ ErrorStateMatcher.ngInjectableDef = ɵɵdefineInjectable({ factory: function ErrorStateMatcher_Factory() { return new ErrorStateMatcher(); }, token: ErrorStateMatcher, providedIn: "root" });
  1092. /**
  1093. * @fileoverview added by tsickle
  1094. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  1095. */
  1096. /**
  1097. * @fileoverview added by tsickle
  1098. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  1099. */
  1100. /**
  1101. * Injection token that can be used to provide options to the Hammerjs instance.
  1102. * More info at http://hammerjs.github.io/api/.
  1103. * @type {?}
  1104. */
  1105. const MAT_HAMMER_OPTIONS = new InjectionToken('MAT_HAMMER_OPTIONS');
  1106. /** @type {?} */
  1107. const ANGULAR_MATERIAL_SUPPORTED_HAMMER_GESTURES = [
  1108. 'longpress',
  1109. 'slide',
  1110. 'slidestart',
  1111. 'slideend',
  1112. 'slideright',
  1113. 'slideleft'
  1114. ];
  1115. const ɵ0$2 = /**
  1116. * @return {?}
  1117. */
  1118. () => { }, ɵ1 = /**
  1119. * @return {?}
  1120. */
  1121. () => { };
  1122. /**
  1123. * Fake HammerInstance that is used when a Hammer instance is requested when HammerJS has not
  1124. * been loaded on the page.
  1125. * @type {?}
  1126. */
  1127. const noopHammerInstance = {
  1128. on: (ɵ0$2),
  1129. off: (ɵ1),
  1130. };
  1131. /**
  1132. * Adjusts configuration of our gesture library, Hammer.
  1133. */
  1134. class GestureConfig extends HammerGestureConfig {
  1135. /**
  1136. * @param {?=} _hammerOptions
  1137. * @param {?=} commonModule
  1138. */
  1139. constructor(_hammerOptions, commonModule) {
  1140. super();
  1141. this._hammerOptions = _hammerOptions;
  1142. /**
  1143. * List of new event names to add to the gesture support list
  1144. */
  1145. this.events = ANGULAR_MATERIAL_SUPPORTED_HAMMER_GESTURES;
  1146. if (commonModule) {
  1147. commonModule._checkHammerIsAvailable();
  1148. }
  1149. }
  1150. /**
  1151. * Builds Hammer instance manually to add custom recognizers that match the Material Design spec.
  1152. *
  1153. * Our gesture names come from the Material Design gestures spec:
  1154. * https://material.io/design/#gestures-touch-mechanics
  1155. *
  1156. * More information on default recognizers can be found in Hammer docs:
  1157. * http://hammerjs.github.io/recognizer-pan/
  1158. * http://hammerjs.github.io/recognizer-press/
  1159. *
  1160. * @param {?} element Element to which to assign the new HammerJS gestures.
  1161. * @return {?} Newly-created HammerJS instance.
  1162. */
  1163. buildHammer(element) {
  1164. /** @type {?} */
  1165. const hammer = typeof window !== 'undefined' ? ((/** @type {?} */ (window))).Hammer : null;
  1166. if (!hammer) {
  1167. // If HammerJS is not loaded here, return the noop HammerInstance. This is necessary to
  1168. // ensure that omitting HammerJS completely will not cause any errors while *also* supporting
  1169. // the lazy-loading of HammerJS via the HAMMER_LOADER token introduced in Angular 6.1.
  1170. // Because we can't depend on HAMMER_LOADER's existance until 7.0, we have to always set
  1171. // `this.events` to the set we support, instead of conditionally setting it to `[]` if
  1172. // `HAMMER_LOADER` is present (and then throwing an Error here if `window.Hammer` is
  1173. // undefined).
  1174. // @breaking-change 8.0.0
  1175. return noopHammerInstance;
  1176. }
  1177. /** @type {?} */
  1178. const mc = new hammer(element, this._hammerOptions || undefined);
  1179. // Default Hammer Recognizers.
  1180. /** @type {?} */
  1181. const pan = new hammer.Pan();
  1182. /** @type {?} */
  1183. const swipe = new hammer.Swipe();
  1184. /** @type {?} */
  1185. const press = new hammer.Press();
  1186. // Notice that a HammerJS recognizer can only depend on one other recognizer once.
  1187. // Otherwise the previous `recognizeWith` will be dropped.
  1188. // TODO: Confirm threshold numbers with Material Design UX Team
  1189. /** @type {?} */
  1190. const slide = this._createRecognizer(pan, { event: 'slide', threshold: 0 }, swipe);
  1191. /** @type {?} */
  1192. const longpress = this._createRecognizer(press, { event: 'longpress', time: 500 });
  1193. // Overwrite the default `pan` event to use the swipe event.
  1194. pan.recognizeWith(swipe);
  1195. // Since the slide event threshold is set to zero, the slide recognizer can fire and
  1196. // accidentally reset the longpress recognizer. In order to make sure that the two
  1197. // recognizers can run simultaneously but don't affect each other, we allow the slide
  1198. // recognizer to recognize while a longpress is being processed.
  1199. // See: https://github.com/hammerjs/hammer.js/blob/master/src/manager.js#L123-L124
  1200. longpress.recognizeWith(slide);
  1201. // Add customized gestures to Hammer manager
  1202. mc.add([swipe, press, pan, slide, longpress]);
  1203. return (/** @type {?} */ (mc));
  1204. }
  1205. /**
  1206. * Creates a new recognizer, without affecting the default recognizers of HammerJS
  1207. * @private
  1208. * @param {?} base
  1209. * @param {?} options
  1210. * @param {...?} inheritances
  1211. * @return {?}
  1212. */
  1213. _createRecognizer(base, options, ...inheritances) {
  1214. /** @type {?} */
  1215. let recognizer = new ((/** @type {?} */ (base.constructor)))(options);
  1216. inheritances.push(base);
  1217. inheritances.forEach((/**
  1218. * @param {?} item
  1219. * @return {?}
  1220. */
  1221. item => recognizer.recognizeWith(item)));
  1222. return recognizer;
  1223. }
  1224. }
  1225. GestureConfig.decorators = [
  1226. { type: Injectable },
  1227. ];
  1228. /** @nocollapse */
  1229. GestureConfig.ctorParameters = () => [
  1230. { type: undefined, decorators: [{ type: Optional }, { type: Inject, args: [MAT_HAMMER_OPTIONS,] }] },
  1231. { type: MatCommonModule, decorators: [{ type: Optional }] }
  1232. ];
  1233. /**
  1234. * @fileoverview added by tsickle
  1235. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  1236. */
  1237. /**
  1238. * Shared directive to count lines inside a text area, such as a list item.
  1239. * Line elements can be extracted with a \@ContentChildren(MatLine) query, then
  1240. * counted by checking the query list's length.
  1241. */
  1242. class MatLine {
  1243. }
  1244. MatLine.decorators = [
  1245. { type: Directive, args: [{
  1246. selector: '[mat-line], [matLine]',
  1247. host: { 'class': 'mat-line' }
  1248. },] },
  1249. ];
  1250. /**
  1251. * Helper that takes a query list of lines and sets the correct class on the host.
  1252. * \@docs-private
  1253. * @param {?} lines
  1254. * @param {?} element
  1255. * @return {?}
  1256. */
  1257. function setLines(lines, element) {
  1258. // Note: doesn't need to unsubscribe, because `changes`
  1259. // gets completed by Angular when the view is destroyed.
  1260. lines.changes.pipe(startWith(lines)).subscribe((/**
  1261. * @param {?} __0
  1262. * @return {?}
  1263. */
  1264. ({ length }) => {
  1265. setClass(element, 'mat-2-line', false);
  1266. setClass(element, 'mat-3-line', false);
  1267. setClass(element, 'mat-multi-line', false);
  1268. if (length === 2 || length === 3) {
  1269. setClass(element, `mat-${length}-line`, true);
  1270. }
  1271. else if (length > 3) {
  1272. setClass(element, `mat-multi-line`, true);
  1273. }
  1274. }));
  1275. }
  1276. /**
  1277. * Adds or removes a class from an element.
  1278. * @param {?} element
  1279. * @param {?} className
  1280. * @param {?} isAdd
  1281. * @return {?}
  1282. */
  1283. function setClass(element, className, isAdd) {
  1284. /** @type {?} */
  1285. const classList = element.nativeElement.classList;
  1286. isAdd ? classList.add(className) : classList.remove(className);
  1287. }
  1288. /**
  1289. * Helper that takes a query list of lines and sets the correct class on the host.
  1290. * \@docs-private
  1291. * @deprecated Use `setLines` instead.
  1292. * \@breaking-change 8.0.0
  1293. */
  1294. class MatLineSetter {
  1295. /**
  1296. * @param {?} lines
  1297. * @param {?} element
  1298. */
  1299. constructor(lines, element) {
  1300. setLines(lines, element);
  1301. }
  1302. }
  1303. class MatLineModule {
  1304. }
  1305. MatLineModule.decorators = [
  1306. { type: NgModule, args: [{
  1307. imports: [MatCommonModule],
  1308. exports: [MatLine, MatCommonModule],
  1309. declarations: [MatLine],
  1310. },] },
  1311. ];
  1312. /**
  1313. * @fileoverview added by tsickle
  1314. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  1315. */
  1316. /** @enum {number} */
  1317. const RippleState = {
  1318. FADING_IN: 0, VISIBLE: 1, FADING_OUT: 2, HIDDEN: 3,
  1319. };
  1320. RippleState[RippleState.FADING_IN] = 'FADING_IN';
  1321. RippleState[RippleState.VISIBLE] = 'VISIBLE';
  1322. RippleState[RippleState.FADING_OUT] = 'FADING_OUT';
  1323. RippleState[RippleState.HIDDEN] = 'HIDDEN';
  1324. /**
  1325. * Reference to a previously launched ripple element.
  1326. */
  1327. class RippleRef {
  1328. /**
  1329. * @param {?} _renderer
  1330. * @param {?} element
  1331. * @param {?} config
  1332. */
  1333. constructor(_renderer, element, config) {
  1334. this._renderer = _renderer;
  1335. this.element = element;
  1336. this.config = config;
  1337. /**
  1338. * Current state of the ripple.
  1339. */
  1340. this.state = RippleState.HIDDEN;
  1341. }
  1342. /**
  1343. * Fades out the ripple element.
  1344. * @return {?}
  1345. */
  1346. fadeOut() {
  1347. this._renderer.fadeOutRipple(this);
  1348. }
  1349. }
  1350. /**
  1351. * @fileoverview added by tsickle
  1352. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  1353. */
  1354. /**
  1355. * Default ripple animation configuration for ripples without an explicit
  1356. * animation config specified.
  1357. * @type {?}
  1358. */
  1359. const defaultRippleAnimationConfig = {
  1360. enterDuration: 450,
  1361. exitDuration: 400
  1362. };
  1363. /**
  1364. * Timeout for ignoring mouse events. Mouse events will be temporary ignored after touch
  1365. * events to avoid synthetic mouse events.
  1366. * @type {?}
  1367. */
  1368. const ignoreMouseEventsTimeout = 800;
  1369. /**
  1370. * Options that apply to all the event listeners that are bound by the ripple renderer.
  1371. * @type {?}
  1372. */
  1373. const passiveEventOptions = normalizePassiveListenerOptions({ passive: true });
  1374. /**
  1375. * Helper service that performs DOM manipulations. Not intended to be used outside this module.
  1376. * The constructor takes a reference to the ripple directive's host element and a map of DOM
  1377. * event handlers to be installed on the element that triggers ripple animations.
  1378. * This will eventually become a custom renderer once Angular support exists.
  1379. * \@docs-private
  1380. */
  1381. class RippleRenderer {
  1382. /**
  1383. * @param {?} _target
  1384. * @param {?} _ngZone
  1385. * @param {?} elementRef
  1386. * @param {?} platform
  1387. */
  1388. constructor(_target, _ngZone, elementRef, platform) {
  1389. this._target = _target;
  1390. this._ngZone = _ngZone;
  1391. /**
  1392. * Whether the pointer is currently down or not.
  1393. */
  1394. this._isPointerDown = false;
  1395. /**
  1396. * Events to be registered on the trigger element.
  1397. */
  1398. this._triggerEvents = new Map();
  1399. /**
  1400. * Set of currently active ripple references.
  1401. */
  1402. this._activeRipples = new Set();
  1403. /**
  1404. * Function being called whenever the trigger is being pressed using mouse.
  1405. */
  1406. this._onMousedown = (/**
  1407. * @param {?} event
  1408. * @return {?}
  1409. */
  1410. (event) => {
  1411. // Screen readers will fire fake mouse events for space/enter. Skip launching a
  1412. // ripple in this case for consistency with the non-screen-reader experience.
  1413. /** @type {?} */
  1414. const isFakeMousedown = isFakeMousedownFromScreenReader(event);
  1415. /** @type {?} */
  1416. const isSyntheticEvent = this._lastTouchStartEvent &&
  1417. Date.now() < this._lastTouchStartEvent + ignoreMouseEventsTimeout;
  1418. if (!this._target.rippleDisabled && !isFakeMousedown && !isSyntheticEvent) {
  1419. this._isPointerDown = true;
  1420. this.fadeInRipple(event.clientX, event.clientY, this._target.rippleConfig);
  1421. }
  1422. });
  1423. /**
  1424. * Function being called whenever the trigger is being pressed using touch.
  1425. */
  1426. this._onTouchStart = (/**
  1427. * @param {?} event
  1428. * @return {?}
  1429. */
  1430. (event) => {
  1431. if (!this._target.rippleDisabled) {
  1432. // Some browsers fire mouse events after a `touchstart` event. Those synthetic mouse
  1433. // events will launch a second ripple if we don't ignore mouse events for a specific
  1434. // time after a touchstart event.
  1435. this._lastTouchStartEvent = Date.now();
  1436. this._isPointerDown = true;
  1437. // Use `changedTouches` so we skip any touches where the user put
  1438. // their finger down, but used another finger to tap the element again.
  1439. /** @type {?} */
  1440. const touches = event.changedTouches;
  1441. for (let i = 0; i < touches.length; i++) {
  1442. this.fadeInRipple(touches[i].clientX, touches[i].clientY, this._target.rippleConfig);
  1443. }
  1444. }
  1445. });
  1446. /**
  1447. * Function being called whenever the trigger is being released.
  1448. */
  1449. this._onPointerUp = (/**
  1450. * @return {?}
  1451. */
  1452. () => {
  1453. if (!this._isPointerDown) {
  1454. return;
  1455. }
  1456. this._isPointerDown = false;
  1457. // Fade-out all ripples that are visible and not persistent.
  1458. this._activeRipples.forEach((/**
  1459. * @param {?} ripple
  1460. * @return {?}
  1461. */
  1462. ripple => {
  1463. // By default, only ripples that are completely visible will fade out on pointer release.
  1464. // If the `terminateOnPointerUp` option is set, ripples that still fade in will also fade out.
  1465. /** @type {?} */
  1466. const isVisible = ripple.state === RippleState.VISIBLE ||
  1467. ripple.config.terminateOnPointerUp && ripple.state === RippleState.FADING_IN;
  1468. if (!ripple.config.persistent && isVisible) {
  1469. ripple.fadeOut();
  1470. }
  1471. }));
  1472. });
  1473. // Only do anything if we're on the browser.
  1474. if (platform.isBrowser) {
  1475. this._containerElement = elementRef.nativeElement;
  1476. // Specify events which need to be registered on the trigger.
  1477. this._triggerEvents
  1478. .set('mousedown', this._onMousedown)
  1479. .set('mouseup', this._onPointerUp)
  1480. .set('mouseleave', this._onPointerUp)
  1481. .set('touchstart', this._onTouchStart)
  1482. .set('touchend', this._onPointerUp)
  1483. .set('touchcancel', this._onPointerUp);
  1484. }
  1485. }
  1486. /**
  1487. * Fades in a ripple at the given coordinates.
  1488. * @param {?} x Coordinate within the element, along the X axis at which to start the ripple.
  1489. * @param {?} y Coordinate within the element, along the Y axis at which to start the ripple.
  1490. * @param {?=} config Extra ripple options.
  1491. * @return {?}
  1492. */
  1493. fadeInRipple(x, y, config = {}) {
  1494. /** @type {?} */
  1495. const containerRect = this._containerRect =
  1496. this._containerRect || this._containerElement.getBoundingClientRect();
  1497. /** @type {?} */
  1498. const animationConfig = Object.assign({}, defaultRippleAnimationConfig, config.animation);
  1499. if (config.centered) {
  1500. x = containerRect.left + containerRect.width / 2;
  1501. y = containerRect.top + containerRect.height / 2;
  1502. }
  1503. /** @type {?} */
  1504. const radius = config.radius || distanceToFurthestCorner(x, y, containerRect);
  1505. /** @type {?} */
  1506. const offsetX = x - containerRect.left;
  1507. /** @type {?} */
  1508. const offsetY = y - containerRect.top;
  1509. /** @type {?} */
  1510. const duration = animationConfig.enterDuration;
  1511. /** @type {?} */
  1512. const ripple = document.createElement('div');
  1513. ripple.classList.add('mat-ripple-element');
  1514. ripple.style.left = `${offsetX - radius}px`;
  1515. ripple.style.top = `${offsetY - radius}px`;
  1516. ripple.style.height = `${radius * 2}px`;
  1517. ripple.style.width = `${radius * 2}px`;
  1518. // If the color is not set, the default CSS color will be used.
  1519. ripple.style.backgroundColor = config.color || null;
  1520. ripple.style.transitionDuration = `${duration}ms`;
  1521. this._containerElement.appendChild(ripple);
  1522. // By default the browser does not recalculate the styles of dynamically created
  1523. // ripple elements. This is critical because then the `scale` would not animate properly.
  1524. enforceStyleRecalculation(ripple);
  1525. ripple.style.transform = 'scale(1)';
  1526. // Exposed reference to the ripple that will be returned.
  1527. /** @type {?} */
  1528. const rippleRef = new RippleRef(this, ripple, config);
  1529. rippleRef.state = RippleState.FADING_IN;
  1530. // Add the ripple reference to the list of all active ripples.
  1531. this._activeRipples.add(rippleRef);
  1532. if (!config.persistent) {
  1533. this._mostRecentTransientRipple = rippleRef;
  1534. }
  1535. // Wait for the ripple element to be completely faded in.
  1536. // Once it's faded in, the ripple can be hidden immediately if the mouse is released.
  1537. this._runTimeoutOutsideZone((/**
  1538. * @return {?}
  1539. */
  1540. () => {
  1541. /** @type {?} */
  1542. const isMostRecentTransientRipple = rippleRef === this._mostRecentTransientRipple;
  1543. rippleRef.state = RippleState.VISIBLE;
  1544. // When the timer runs out while the user has kept their pointer down, we want to
  1545. // keep only the persistent ripples and the latest transient ripple. We do this,
  1546. // because we don't want stacked transient ripples to appear after their enter
  1547. // animation has finished.
  1548. if (!config.persistent && (!isMostRecentTransientRipple || !this._isPointerDown)) {
  1549. rippleRef.fadeOut();
  1550. }
  1551. }), duration);
  1552. return rippleRef;
  1553. }
  1554. /**
  1555. * Fades out a ripple reference.
  1556. * @param {?} rippleRef
  1557. * @return {?}
  1558. */
  1559. fadeOutRipple(rippleRef) {
  1560. /** @type {?} */
  1561. const wasActive = this._activeRipples.delete(rippleRef);
  1562. if (rippleRef === this._mostRecentTransientRipple) {
  1563. this._mostRecentTransientRipple = null;
  1564. }
  1565. // Clear out the cached bounding rect if we have no more ripples.
  1566. if (!this._activeRipples.size) {
  1567. this._containerRect = null;
  1568. }
  1569. // For ripples that are not active anymore, don't re-run the fade-out animation.
  1570. if (!wasActive) {
  1571. return;
  1572. }
  1573. /** @type {?} */
  1574. const rippleEl = rippleRef.element;
  1575. /** @type {?} */
  1576. const animationConfig = Object.assign({}, defaultRippleAnimationConfig, rippleRef.config.animation);
  1577. rippleEl.style.transitionDuration = `${animationConfig.exitDuration}ms`;
  1578. rippleEl.style.opacity = '0';
  1579. rippleRef.state = RippleState.FADING_OUT;
  1580. // Once the ripple faded out, the ripple can be safely removed from the DOM.
  1581. this._runTimeoutOutsideZone((/**
  1582. * @return {?}
  1583. */
  1584. () => {
  1585. rippleRef.state = RippleState.HIDDEN;
  1586. (/** @type {?} */ (rippleEl.parentNode)).removeChild(rippleEl);
  1587. }), animationConfig.exitDuration);
  1588. }
  1589. /**
  1590. * Fades out all currently active ripples.
  1591. * @return {?}
  1592. */
  1593. fadeOutAll() {
  1594. this._activeRipples.forEach((/**
  1595. * @param {?} ripple
  1596. * @return {?}
  1597. */
  1598. ripple => ripple.fadeOut()));
  1599. }
  1600. /**
  1601. * Sets up the trigger event listeners
  1602. * @param {?} element
  1603. * @return {?}
  1604. */
  1605. setupTriggerEvents(element) {
  1606. if (!element || element === this._triggerElement) {
  1607. return;
  1608. }
  1609. // Remove all previously registered event listeners from the trigger element.
  1610. this._removeTriggerEvents();
  1611. this._ngZone.runOutsideAngular((/**
  1612. * @return {?}
  1613. */
  1614. () => {
  1615. this._triggerEvents.forEach((/**
  1616. * @param {?} fn
  1617. * @param {?} type
  1618. * @return {?}
  1619. */
  1620. (fn, type) => {
  1621. element.addEventListener(type, fn, passiveEventOptions);
  1622. }));
  1623. }));
  1624. this._triggerElement = element;
  1625. }
  1626. /**
  1627. * Runs a timeout outside of the Angular zone to avoid triggering the change detection.
  1628. * @private
  1629. * @param {?} fn
  1630. * @param {?=} delay
  1631. * @return {?}
  1632. */
  1633. _runTimeoutOutsideZone(fn, delay = 0) {
  1634. this._ngZone.runOutsideAngular((/**
  1635. * @return {?}
  1636. */
  1637. () => setTimeout(fn, delay)));
  1638. }
  1639. /**
  1640. * Removes previously registered event listeners from the trigger element.
  1641. * @return {?}
  1642. */
  1643. _removeTriggerEvents() {
  1644. if (this._triggerElement) {
  1645. this._triggerEvents.forEach((/**
  1646. * @param {?} fn
  1647. * @param {?} type
  1648. * @return {?}
  1649. */
  1650. (fn, type) => {
  1651. (/** @type {?} */ (this._triggerElement)).removeEventListener(type, fn, passiveEventOptions);
  1652. }));
  1653. }
  1654. }
  1655. }
  1656. /**
  1657. * Enforces a style recalculation of a DOM element by computing its styles.
  1658. * @param {?} element
  1659. * @return {?}
  1660. */
  1661. function enforceStyleRecalculation(element) {
  1662. // Enforce a style recalculation by calling `getComputedStyle` and accessing any property.
  1663. // Calling `getPropertyValue` is important to let optimizers know that this is not a noop.
  1664. // See: https://gist.github.com/paulirish/5d52fb081b3570c81e3a
  1665. window.getComputedStyle(element).getPropertyValue('opacity');
  1666. }
  1667. /**
  1668. * Returns the distance from the point (x, y) to the furthest corner of a rectangle.
  1669. * @param {?} x
  1670. * @param {?} y
  1671. * @param {?} rect
  1672. * @return {?}
  1673. */
  1674. function distanceToFurthestCorner(x, y, rect) {
  1675. /** @type {?} */
  1676. const distX = Math.max(Math.abs(x - rect.left), Math.abs(x - rect.right));
  1677. /** @type {?} */
  1678. const distY = Math.max(Math.abs(y - rect.top), Math.abs(y - rect.bottom));
  1679. return Math.sqrt(distX * distX + distY * distY);
  1680. }
  1681. /**
  1682. * @fileoverview added by tsickle
  1683. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  1684. */
  1685. /**
  1686. * Injection token that can be used to specify the global ripple options.
  1687. * @type {?}
  1688. */
  1689. const MAT_RIPPLE_GLOBAL_OPTIONS = new InjectionToken('mat-ripple-global-options');
  1690. class MatRipple {
  1691. /**
  1692. * @param {?} _elementRef
  1693. * @param {?} ngZone
  1694. * @param {?} platform
  1695. * @param {?=} globalOptions
  1696. * @param {?=} animationMode
  1697. */
  1698. constructor(_elementRef, ngZone, platform, globalOptions, animationMode) {
  1699. this._elementRef = _elementRef;
  1700. /**
  1701. * If set, the radius in pixels of foreground ripples when fully expanded. If unset, the radius
  1702. * will be the distance from the center of the ripple to the furthest corner of the host element's
  1703. * bounding rectangle.
  1704. */
  1705. this.radius = 0;
  1706. this._disabled = false;
  1707. /**
  1708. * Whether ripple directive is initialized and the input bindings are set.
  1709. */
  1710. this._isInitialized = false;
  1711. this._globalOptions = globalOptions || {};
  1712. this._rippleRenderer = new RippleRenderer(this, ngZone, _elementRef, platform);
  1713. if (animationMode === 'NoopAnimations') {
  1714. this._globalOptions.animation = { enterDuration: 0, exitDuration: 0 };
  1715. }
  1716. }
  1717. /**
  1718. * Whether click events will not trigger the ripple. Ripples can be still launched manually
  1719. * by using the `launch()` method.
  1720. * @return {?}
  1721. */
  1722. get disabled() { return this._disabled; }
  1723. /**
  1724. * @param {?} value
  1725. * @return {?}
  1726. */
  1727. set disabled(value) {
  1728. this._disabled = value;
  1729. this._setupTriggerEventsIfEnabled();
  1730. }
  1731. /**
  1732. * The element that triggers the ripple when click events are received.
  1733. * Defaults to the directive's host element.
  1734. * @return {?}
  1735. */
  1736. get trigger() { return this._trigger || this._elementRef.nativeElement; }
  1737. /**
  1738. * @param {?} trigger
  1739. * @return {?}
  1740. */
  1741. set trigger(trigger) {
  1742. this._trigger = trigger;
  1743. this._setupTriggerEventsIfEnabled();
  1744. }
  1745. /**
  1746. * @return {?}
  1747. */
  1748. ngOnInit() {
  1749. this._isInitialized = true;
  1750. this._setupTriggerEventsIfEnabled();
  1751. }
  1752. /**
  1753. * @return {?}
  1754. */
  1755. ngOnDestroy() {
  1756. this._rippleRenderer._removeTriggerEvents();
  1757. }
  1758. /**
  1759. * Fades out all currently showing ripple elements.
  1760. * @return {?}
  1761. */
  1762. fadeOutAll() {
  1763. this._rippleRenderer.fadeOutAll();
  1764. }
  1765. /**
  1766. * Ripple configuration from the directive's input values.
  1767. * \@docs-private Implemented as part of RippleTarget
  1768. * @return {?}
  1769. */
  1770. get rippleConfig() {
  1771. return {
  1772. centered: this.centered,
  1773. radius: this.radius,
  1774. color: this.color,
  1775. animation: Object.assign({}, this._globalOptions.animation, this.animation),
  1776. terminateOnPointerUp: this._globalOptions.terminateOnPointerUp,
  1777. };
  1778. }
  1779. /**
  1780. * Whether ripples on pointer-down are disabled or not.
  1781. * \@docs-private Implemented as part of RippleTarget
  1782. * @return {?}
  1783. */
  1784. get rippleDisabled() {
  1785. return this.disabled || !!this._globalOptions.disabled;
  1786. }
  1787. /**
  1788. * Sets up the trigger event listeners if ripples are enabled.
  1789. * @private
  1790. * @return {?}
  1791. */
  1792. _setupTriggerEventsIfEnabled() {
  1793. if (!this.disabled && this._isInitialized) {
  1794. this._rippleRenderer.setupTriggerEvents(this.trigger);
  1795. }
  1796. }
  1797. /**
  1798. * Launches a manual ripple at the specified coordinated or just by the ripple config.
  1799. * @param {?} configOrX
  1800. * @param {?=} y
  1801. * @param {?=} config
  1802. * @return {?}
  1803. */
  1804. launch(configOrX, y = 0, config) {
  1805. if (typeof configOrX === 'number') {
  1806. return this._rippleRenderer.fadeInRipple(configOrX, y, Object.assign({}, this.rippleConfig, config));
  1807. }
  1808. else {
  1809. return this._rippleRenderer.fadeInRipple(0, 0, Object.assign({}, this.rippleConfig, configOrX));
  1810. }
  1811. }
  1812. }
  1813. MatRipple.decorators = [
  1814. { type: Directive, args: [{
  1815. selector: '[mat-ripple], [matRipple]',
  1816. exportAs: 'matRipple',
  1817. host: {
  1818. 'class': 'mat-ripple',
  1819. '[class.mat-ripple-unbounded]': 'unbounded'
  1820. }
  1821. },] },
  1822. ];
  1823. /** @nocollapse */
  1824. MatRipple.ctorParameters = () => [
  1825. { type: ElementRef },
  1826. { type: NgZone },
  1827. { type: Platform },
  1828. { type: undefined, decorators: [{ type: Optional }, { type: Inject, args: [MAT_RIPPLE_GLOBAL_OPTIONS,] }] },
  1829. { type: String, decorators: [{ type: Optional }, { type: Inject, args: [ANIMATION_MODULE_TYPE,] }] }
  1830. ];
  1831. MatRipple.propDecorators = {
  1832. color: [{ type: Input, args: ['matRippleColor',] }],
  1833. unbounded: [{ type: Input, args: ['matRippleUnbounded',] }],
  1834. centered: [{ type: Input, args: ['matRippleCentered',] }],
  1835. radius: [{ type: Input, args: ['matRippleRadius',] }],
  1836. animation: [{ type: Input, args: ['matRippleAnimation',] }],
  1837. disabled: [{ type: Input, args: ['matRippleDisabled',] }],
  1838. trigger: [{ type: Input, args: ['matRippleTrigger',] }]
  1839. };
  1840. /**
  1841. * @fileoverview added by tsickle
  1842. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  1843. */
  1844. class MatRippleModule {
  1845. }
  1846. MatRippleModule.decorators = [
  1847. { type: NgModule, args: [{
  1848. imports: [MatCommonModule, PlatformModule],
  1849. exports: [MatRipple, MatCommonModule],
  1850. declarations: [MatRipple],
  1851. },] },
  1852. ];
  1853. /**
  1854. * @fileoverview added by tsickle
  1855. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  1856. */
  1857. /**
  1858. * Component that shows a simplified checkbox without including any kind of "real" checkbox.
  1859. * Meant to be used when the checkbox is purely decorative and a large number of them will be
  1860. * included, such as for the options in a multi-select. Uses no SVGs or complex animations.
  1861. * Note that theming is meant to be handled by the parent element, e.g.
  1862. * `mat-primary .mat-pseudo-checkbox`.
  1863. *
  1864. * Note that this component will be completely invisible to screen-reader users. This is *not*
  1865. * interchangeable with `<mat-checkbox>` and should *not* be used if the user would directly
  1866. * interact with the checkbox. The pseudo-checkbox should only be used as an implementation detail
  1867. * of more complex components that appropriately handle selected / checked state.
  1868. * \@docs-private
  1869. */
  1870. class MatPseudoCheckbox {
  1871. /**
  1872. * @param {?=} _animationMode
  1873. */
  1874. constructor(_animationMode) {
  1875. this._animationMode = _animationMode;
  1876. /**
  1877. * Display state of the checkbox.
  1878. */
  1879. this.state = 'unchecked';
  1880. /**
  1881. * Whether the checkbox is disabled.
  1882. */
  1883. this.disabled = false;
  1884. }
  1885. }
  1886. MatPseudoCheckbox.decorators = [
  1887. { type: Component, args: [{encapsulation: ViewEncapsulation.None,
  1888. changeDetection: ChangeDetectionStrategy.OnPush,
  1889. selector: 'mat-pseudo-checkbox',
  1890. styles: [".mat-pseudo-checkbox{width:16px;height:16px;border:2px solid;border-radius:2px;cursor:pointer;display:inline-block;vertical-align:middle;box-sizing:border-box;position:relative;flex-shrink:0;transition:border-color 90ms cubic-bezier(0,0,.2,.1),background-color 90ms cubic-bezier(0,0,.2,.1)}.mat-pseudo-checkbox::after{position:absolute;opacity:0;content:'';border-bottom:2px solid currentColor;transition:opacity 90ms cubic-bezier(0,0,.2,.1)}.mat-pseudo-checkbox.mat-pseudo-checkbox-checked,.mat-pseudo-checkbox.mat-pseudo-checkbox-indeterminate{border-color:transparent}._mat-animation-noopable.mat-pseudo-checkbox{transition:none;animation:none}._mat-animation-noopable.mat-pseudo-checkbox::after{transition:none}.mat-pseudo-checkbox-disabled{cursor:default}.mat-pseudo-checkbox-indeterminate::after{top:5px;left:1px;width:10px;opacity:1;border-radius:2px}.mat-pseudo-checkbox-checked::after{top:2.4px;left:1px;width:8px;height:3px;border-left:2px solid currentColor;transform:rotate(-45deg);opacity:1;box-sizing:content-box}"],
  1891. template: '',
  1892. host: {
  1893. 'class': 'mat-pseudo-checkbox',
  1894. '[class.mat-pseudo-checkbox-indeterminate]': 'state === "indeterminate"',
  1895. '[class.mat-pseudo-checkbox-checked]': 'state === "checked"',
  1896. '[class.mat-pseudo-checkbox-disabled]': 'disabled',
  1897. '[class._mat-animation-noopable]': '_animationMode === "NoopAnimations"',
  1898. },
  1899. },] },
  1900. ];
  1901. /** @nocollapse */
  1902. MatPseudoCheckbox.ctorParameters = () => [
  1903. { type: String, decorators: [{ type: Optional }, { type: Inject, args: [ANIMATION_MODULE_TYPE,] }] }
  1904. ];
  1905. MatPseudoCheckbox.propDecorators = {
  1906. state: [{ type: Input }],
  1907. disabled: [{ type: Input }]
  1908. };
  1909. /**
  1910. * @fileoverview added by tsickle
  1911. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  1912. */
  1913. class MatPseudoCheckboxModule {
  1914. }
  1915. MatPseudoCheckboxModule.decorators = [
  1916. { type: NgModule, args: [{
  1917. exports: [MatPseudoCheckbox],
  1918. declarations: [MatPseudoCheckbox]
  1919. },] },
  1920. ];
  1921. /**
  1922. * @fileoverview added by tsickle
  1923. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  1924. */
  1925. // Boilerplate for applying mixins to MatOptgroup.
  1926. /**
  1927. * \@docs-private
  1928. */
  1929. class MatOptgroupBase {
  1930. }
  1931. /** @type {?} */
  1932. const _MatOptgroupMixinBase = mixinDisabled(MatOptgroupBase);
  1933. // Counter for unique group ids.
  1934. /** @type {?} */
  1935. let _uniqueOptgroupIdCounter = 0;
  1936. /**
  1937. * Component that is used to group instances of `mat-option`.
  1938. */
  1939. class MatOptgroup extends _MatOptgroupMixinBase {
  1940. constructor() {
  1941. super(...arguments);
  1942. /**
  1943. * Unique id for the underlying label.
  1944. */
  1945. this._labelId = `mat-optgroup-label-${_uniqueOptgroupIdCounter++}`;
  1946. }
  1947. }
  1948. MatOptgroup.decorators = [
  1949. { type: Component, args: [{selector: 'mat-optgroup',
  1950. exportAs: 'matOptgroup',
  1951. template: "<label class=\"mat-optgroup-label\" [id]=\"_labelId\">{{ label }}<ng-content></ng-content></label><ng-content select=\"mat-option, ng-container\"></ng-content>",
  1952. encapsulation: ViewEncapsulation.None,
  1953. changeDetection: ChangeDetectionStrategy.OnPush,
  1954. inputs: ['disabled'],
  1955. styles: [".mat-optgroup-label{white-space:nowrap;overflow:hidden;text-overflow:ellipsis;display:block;line-height:48px;height:48px;padding:0 16px;text-align:left;text-decoration:none;max-width:100%;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;cursor:default}.mat-optgroup-label[disabled]{cursor:default}[dir=rtl] .mat-optgroup-label{text-align:right}.mat-optgroup-label .mat-icon{margin-right:16px;vertical-align:middle}.mat-optgroup-label .mat-icon svg{vertical-align:top}[dir=rtl] .mat-optgroup-label .mat-icon{margin-left:16px;margin-right:0}"],
  1956. host: {
  1957. 'class': 'mat-optgroup',
  1958. 'role': 'group',
  1959. '[class.mat-optgroup-disabled]': 'disabled',
  1960. '[attr.aria-disabled]': 'disabled.toString()',
  1961. '[attr.aria-labelledby]': '_labelId',
  1962. }
  1963. },] },
  1964. ];
  1965. MatOptgroup.propDecorators = {
  1966. label: [{ type: Input }]
  1967. };
  1968. /**
  1969. * @fileoverview added by tsickle
  1970. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  1971. */
  1972. /**
  1973. * Option IDs need to be unique across components, so this counter exists outside of
  1974. * the component definition.
  1975. * @type {?}
  1976. */
  1977. let _uniqueIdCounter = 0;
  1978. /**
  1979. * Event object emitted by MatOption when selected or deselected.
  1980. */
  1981. class MatOptionSelectionChange {
  1982. /**
  1983. * @param {?} source
  1984. * @param {?=} isUserInput
  1985. */
  1986. constructor(source, isUserInput = false) {
  1987. this.source = source;
  1988. this.isUserInput = isUserInput;
  1989. }
  1990. }
  1991. /**
  1992. * Injection token used to provide the parent component to options.
  1993. * @type {?}
  1994. */
  1995. const MAT_OPTION_PARENT_COMPONENT = new InjectionToken('MAT_OPTION_PARENT_COMPONENT');
  1996. /**
  1997. * Single option inside of a `<mat-select>` element.
  1998. */
  1999. class MatOption {
  2000. /**
  2001. * @param {?} _element
  2002. * @param {?} _changeDetectorRef
  2003. * @param {?} _parent
  2004. * @param {?} group
  2005. */
  2006. constructor(_element, _changeDetectorRef, _parent, group) {
  2007. this._element = _element;
  2008. this._changeDetectorRef = _changeDetectorRef;
  2009. this._parent = _parent;
  2010. this.group = group;
  2011. this._selected = false;
  2012. this._active = false;
  2013. this._disabled = false;
  2014. this._mostRecentViewValue = '';
  2015. /**
  2016. * The unique ID of the option.
  2017. */
  2018. this.id = `mat-option-${_uniqueIdCounter++}`;
  2019. /**
  2020. * Event emitted when the option is selected or deselected.
  2021. */
  2022. // tslint:disable-next-line:no-output-on-prefix
  2023. this.onSelectionChange = new EventEmitter();
  2024. /**
  2025. * Emits when the state of the option changes and any parents have to be notified.
  2026. */
  2027. this._stateChanges = new Subject();
  2028. }
  2029. /**
  2030. * Whether the wrapping component is in multiple selection mode.
  2031. * @return {?}
  2032. */
  2033. get multiple() { return this._parent && this._parent.multiple; }
  2034. /**
  2035. * Whether or not the option is currently selected.
  2036. * @return {?}
  2037. */
  2038. get selected() { return this._selected; }
  2039. /**
  2040. * Whether the option is disabled.
  2041. * @return {?}
  2042. */
  2043. get disabled() { return (this.group && this.group.disabled) || this._disabled; }
  2044. /**
  2045. * @param {?} value
  2046. * @return {?}
  2047. */
  2048. set disabled(value) { this._disabled = coerceBooleanProperty(value); }
  2049. /**
  2050. * Whether ripples for the option are disabled.
  2051. * @return {?}
  2052. */
  2053. get disableRipple() { return this._parent && this._parent.disableRipple; }
  2054. /**
  2055. * Whether or not the option is currently active and ready to be selected.
  2056. * An active option displays styles as if it is focused, but the
  2057. * focus is actually retained somewhere else. This comes in handy
  2058. * for components like autocomplete where focus must remain on the input.
  2059. * @return {?}
  2060. */
  2061. get active() {
  2062. return this._active;
  2063. }
  2064. /**
  2065. * The displayed value of the option. It is necessary to show the selected option in the
  2066. * select's trigger.
  2067. * @return {?}
  2068. */
  2069. get viewValue() {
  2070. // TODO(kara): Add input property alternative for node envs.
  2071. return (this._getHostElement().textContent || '').trim();
  2072. }
  2073. /**
  2074. * Selects the option.
  2075. * @return {?}
  2076. */
  2077. select() {
  2078. if (!this._selected) {
  2079. this._selected = true;
  2080. this._changeDetectorRef.markForCheck();
  2081. this._emitSelectionChangeEvent();
  2082. }
  2083. }
  2084. /**
  2085. * Deselects the option.
  2086. * @return {?}
  2087. */
  2088. deselect() {
  2089. if (this._selected) {
  2090. this._selected = false;
  2091. this._changeDetectorRef.markForCheck();
  2092. this._emitSelectionChangeEvent();
  2093. }
  2094. }
  2095. /**
  2096. * Sets focus onto this option.
  2097. * @param {?=} _origin
  2098. * @param {?=} options
  2099. * @return {?}
  2100. */
  2101. focus(_origin, options) {
  2102. // Note that we aren't using `_origin`, but we need to keep it because some internal consumers
  2103. // use `MatOption` in a `FocusKeyManager` and we need it to match `FocusableOption`.
  2104. /** @type {?} */
  2105. const element = this._getHostElement();
  2106. if (typeof element.focus === 'function') {
  2107. element.focus(options);
  2108. }
  2109. }
  2110. /**
  2111. * This method sets display styles on the option to make it appear
  2112. * active. This is used by the ActiveDescendantKeyManager so key
  2113. * events will display the proper options as active on arrow key events.
  2114. * @return {?}
  2115. */
  2116. setActiveStyles() {
  2117. if (!this._active) {
  2118. this._active = true;
  2119. this._changeDetectorRef.markForCheck();
  2120. }
  2121. }
  2122. /**
  2123. * This method removes display styles on the option that made it appear
  2124. * active. This is used by the ActiveDescendantKeyManager so key
  2125. * events will display the proper options as active on arrow key events.
  2126. * @return {?}
  2127. */
  2128. setInactiveStyles() {
  2129. if (this._active) {
  2130. this._active = false;
  2131. this._changeDetectorRef.markForCheck();
  2132. }
  2133. }
  2134. /**
  2135. * Gets the label to be used when determining whether the option should be focused.
  2136. * @return {?}
  2137. */
  2138. getLabel() {
  2139. return this.viewValue;
  2140. }
  2141. /**
  2142. * Ensures the option is selected when activated from the keyboard.
  2143. * @param {?} event
  2144. * @return {?}
  2145. */
  2146. _handleKeydown(event) {
  2147. if ((event.keyCode === ENTER || event.keyCode === SPACE) && !hasModifierKey(event)) {
  2148. this._selectViaInteraction();
  2149. // Prevent the page from scrolling down and form submits.
  2150. event.preventDefault();
  2151. }
  2152. }
  2153. /**
  2154. * `Selects the option while indicating the selection came from the user. Used to
  2155. * determine if the select's view -> model callback should be invoked.`
  2156. * @return {?}
  2157. */
  2158. _selectViaInteraction() {
  2159. if (!this.disabled) {
  2160. this._selected = this.multiple ? !this._selected : true;
  2161. this._changeDetectorRef.markForCheck();
  2162. this._emitSelectionChangeEvent(true);
  2163. }
  2164. }
  2165. /**
  2166. * Gets the `aria-selected` value for the option. We explicitly omit the `aria-selected`
  2167. * attribute from single-selection, unselected options. Including the `aria-selected="false"`
  2168. * attributes adds a significant amount of noise to screen-reader users without providing useful
  2169. * information.
  2170. * @return {?}
  2171. */
  2172. _getAriaSelected() {
  2173. return this.selected || (this.multiple ? false : null);
  2174. }
  2175. /**
  2176. * Returns the correct tabindex for the option depending on disabled state.
  2177. * @return {?}
  2178. */
  2179. _getTabIndex() {
  2180. return this.disabled ? '-1' : '0';
  2181. }
  2182. /**
  2183. * Gets the host DOM element.
  2184. * @return {?}
  2185. */
  2186. _getHostElement() {
  2187. return this._element.nativeElement;
  2188. }
  2189. /**
  2190. * @return {?}
  2191. */
  2192. ngAfterViewChecked() {
  2193. // Since parent components could be using the option's label to display the selected values
  2194. // (e.g. `mat-select`) and they don't have a way of knowing if the option's label has changed
  2195. // we have to check for changes in the DOM ourselves and dispatch an event. These checks are
  2196. // relatively cheap, however we still limit them only to selected options in order to avoid
  2197. // hitting the DOM too often.
  2198. if (this._selected) {
  2199. /** @type {?} */
  2200. const viewValue = this.viewValue;
  2201. if (viewValue !== this._mostRecentViewValue) {
  2202. this._mostRecentViewValue = viewValue;
  2203. this._stateChanges.next();
  2204. }
  2205. }
  2206. }
  2207. /**
  2208. * @return {?}
  2209. */
  2210. ngOnDestroy() {
  2211. this._stateChanges.complete();
  2212. }
  2213. /**
  2214. * Emits the selection change event.
  2215. * @private
  2216. * @param {?=} isUserInput
  2217. * @return {?}
  2218. */
  2219. _emitSelectionChangeEvent(isUserInput = false) {
  2220. this.onSelectionChange.emit(new MatOptionSelectionChange(this, isUserInput));
  2221. }
  2222. }
  2223. MatOption.decorators = [
  2224. { type: Component, args: [{selector: 'mat-option',
  2225. exportAs: 'matOption',
  2226. host: {
  2227. 'role': 'option',
  2228. '[attr.tabindex]': '_getTabIndex()',
  2229. '[class.mat-selected]': 'selected',
  2230. '[class.mat-option-multiple]': 'multiple',
  2231. '[class.mat-active]': 'active',
  2232. '[id]': 'id',
  2233. '[attr.aria-selected]': '_getAriaSelected()',
  2234. '[attr.aria-disabled]': 'disabled.toString()',
  2235. '[class.mat-option-disabled]': 'disabled',
  2236. '(click)': '_selectViaInteraction()',
  2237. '(keydown)': '_handleKeydown($event)',
  2238. 'class': 'mat-option',
  2239. },
  2240. styles: [".mat-option{white-space:nowrap;overflow:hidden;text-overflow:ellipsis;display:block;line-height:48px;height:48px;padding:0 16px;text-align:left;text-decoration:none;max-width:100%;position:relative;cursor:pointer;outline:0;display:flex;flex-direction:row;max-width:100%;box-sizing:border-box;align-items:center;-webkit-tap-highlight-color:transparent}.mat-option[disabled]{cursor:default}[dir=rtl] .mat-option{text-align:right}.mat-option .mat-icon{margin-right:16px;vertical-align:middle}.mat-option .mat-icon svg{vertical-align:top}[dir=rtl] .mat-option .mat-icon{margin-left:16px;margin-right:0}.mat-option[aria-disabled=true]{-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;cursor:default}.mat-optgroup .mat-option:not(.mat-option-multiple){padding-left:32px}[dir=rtl] .mat-optgroup .mat-option:not(.mat-option-multiple){padding-left:16px;padding-right:32px}@media (-ms-high-contrast:active){.mat-option{margin:0 1px}.mat-option.mat-active{border:solid 1px currentColor;margin:0}}.mat-option-text{display:inline-block;flex-grow:1;overflow:hidden;text-overflow:ellipsis}.mat-option .mat-option-ripple{top:0;left:0;right:0;bottom:0;position:absolute;pointer-events:none}@media (-ms-high-contrast:active){.mat-option .mat-option-ripple{opacity:.5}}.mat-option-pseudo-checkbox{margin-right:8px}[dir=rtl] .mat-option-pseudo-checkbox{margin-left:8px;margin-right:0}"],
  2241. template: "<mat-pseudo-checkbox *ngIf=\"multiple\" class=\"mat-option-pseudo-checkbox\" [state]=\"selected ? 'checked' : ''\" [disabled]=\"disabled\"></mat-pseudo-checkbox><span class=\"mat-option-text\"><ng-content></ng-content></span><div class=\"mat-option-ripple\" mat-ripple [matRippleTrigger]=\"_getHostElement()\" [matRippleDisabled]=\"disabled || disableRipple\"></div>",
  2242. encapsulation: ViewEncapsulation.None,
  2243. changeDetection: ChangeDetectionStrategy.OnPush,
  2244. },] },
  2245. ];
  2246. /** @nocollapse */
  2247. MatOption.ctorParameters = () => [
  2248. { type: ElementRef },
  2249. { type: ChangeDetectorRef },
  2250. { type: undefined, decorators: [{ type: Optional }, { type: Inject, args: [MAT_OPTION_PARENT_COMPONENT,] }] },
  2251. { type: MatOptgroup, decorators: [{ type: Optional }] }
  2252. ];
  2253. MatOption.propDecorators = {
  2254. value: [{ type: Input }],
  2255. id: [{ type: Input }],
  2256. disabled: [{ type: Input }],
  2257. onSelectionChange: [{ type: Output }]
  2258. };
  2259. /**
  2260. * Counts the amount of option group labels that precede the specified option.
  2261. * \@docs-private
  2262. * @param {?} optionIndex Index of the option at which to start counting.
  2263. * @param {?} options Flat list of all of the options.
  2264. * @param {?} optionGroups Flat list of all of the option groups.
  2265. * @return {?}
  2266. */
  2267. function _countGroupLabelsBeforeOption(optionIndex, options, optionGroups) {
  2268. if (optionGroups.length) {
  2269. /** @type {?} */
  2270. let optionsArray = options.toArray();
  2271. /** @type {?} */
  2272. let groups = optionGroups.toArray();
  2273. /** @type {?} */
  2274. let groupCounter = 0;
  2275. for (let i = 0; i < optionIndex + 1; i++) {
  2276. if (optionsArray[i].group && optionsArray[i].group === groups[groupCounter]) {
  2277. groupCounter++;
  2278. }
  2279. }
  2280. return groupCounter;
  2281. }
  2282. return 0;
  2283. }
  2284. /**
  2285. * Determines the position to which to scroll a panel in order for an option to be into view.
  2286. * \@docs-private
  2287. * @param {?} optionIndex Index of the option to be scrolled into the view.
  2288. * @param {?} optionHeight Height of the options.
  2289. * @param {?} currentScrollPosition Current scroll position of the panel.
  2290. * @param {?} panelHeight Height of the panel.
  2291. * @return {?}
  2292. */
  2293. function _getOptionScrollPosition(optionIndex, optionHeight, currentScrollPosition, panelHeight) {
  2294. /** @type {?} */
  2295. const optionOffset = optionIndex * optionHeight;
  2296. if (optionOffset < currentScrollPosition) {
  2297. return optionOffset;
  2298. }
  2299. if (optionOffset + optionHeight > currentScrollPosition + panelHeight) {
  2300. return Math.max(0, optionOffset - panelHeight + optionHeight);
  2301. }
  2302. return currentScrollPosition;
  2303. }
  2304. /**
  2305. * @fileoverview added by tsickle
  2306. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  2307. */
  2308. class MatOptionModule {
  2309. }
  2310. MatOptionModule.decorators = [
  2311. { type: NgModule, args: [{
  2312. imports: [MatRippleModule, CommonModule, MatPseudoCheckboxModule],
  2313. exports: [MatOption, MatOptgroup],
  2314. declarations: [MatOption, MatOptgroup]
  2315. },] },
  2316. ];
  2317. /**
  2318. * @fileoverview added by tsickle
  2319. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  2320. */
  2321. /**
  2322. * InjectionToken that can be used to specify the global label options.
  2323. * @type {?}
  2324. */
  2325. const MAT_LABEL_GLOBAL_OPTIONS = new InjectionToken('mat-label-global-options');
  2326. /**
  2327. * @fileoverview added by tsickle
  2328. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  2329. */
  2330. /**
  2331. * When constructing a Date, the month is zero-based. This can be confusing, since people are
  2332. * used to seeing them one-based. So we create these aliases to make writing the tests easier.
  2333. * \@docs-private
  2334. * \@breaking-change 8.0.0 Remove this with V8 since it was only targeted for testing.
  2335. * @type {?}
  2336. */
  2337. const JAN = 0;
  2338. /** @type {?} */
  2339. const FEB = 1;
  2340. /** @type {?} */
  2341. const MAR = 2;
  2342. /** @type {?} */
  2343. const APR = 3;
  2344. /** @type {?} */
  2345. const MAY = 4;
  2346. /** @type {?} */
  2347. const JUN = 5;
  2348. /** @type {?} */
  2349. const JUL = 6;
  2350. /** @type {?} */
  2351. const AUG = 7;
  2352. /** @type {?} */
  2353. const SEP = 8;
  2354. /** @type {?} */
  2355. const OCT = 9;
  2356. /** @type {?} */
  2357. const NOV = 10;
  2358. /** @type {?} */
  2359. const DEC = 11;
  2360. /**
  2361. * @fileoverview added by tsickle
  2362. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  2363. */
  2364. /**
  2365. * @fileoverview added by tsickle
  2366. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  2367. */
  2368. export { VERSION$1 as VERSION, AnimationCurves, AnimationDurations, MatCommonModule, MATERIAL_SANITY_CHECKS, mixinDisabled, mixinColor, mixinDisableRipple, mixinTabIndex, mixinErrorState, mixinInitialized, NativeDateModule, MatNativeDateModule, MAT_DATE_LOCALE_FACTORY, MAT_DATE_LOCALE, MAT_DATE_LOCALE_PROVIDER, DateAdapter, MAT_DATE_FORMATS, NativeDateAdapter, MAT_NATIVE_DATE_FORMATS, ShowOnDirtyErrorStateMatcher, ErrorStateMatcher, MAT_HAMMER_OPTIONS, GestureConfig, setLines, MatLine, MatLineSetter, MatLineModule, MatOptionModule, _countGroupLabelsBeforeOption, _getOptionScrollPosition, MatOptionSelectionChange, MAT_OPTION_PARENT_COMPONENT, MatOption, MatOptgroup, MAT_LABEL_GLOBAL_OPTIONS, MatRippleModule, MAT_RIPPLE_GLOBAL_OPTIONS, MatRipple, RippleState, RippleRef, defaultRippleAnimationConfig, RippleRenderer, MatPseudoCheckboxModule, MatPseudoCheckbox, JAN, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP, OCT, NOV, DEC, MATERIAL_SANITY_CHECKS_FACTORY as ɵa1 };
  2369. //# sourceMappingURL=core.js.map