scrolling.es5.js 93 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409
  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 { InjectionToken, Directive, forwardRef, Input, Injectable, NgZone, Optional, SkipSelf, ElementRef, NgModule, IterableDiffers, TemplateRef, ViewContainerRef, ChangeDetectionStrategy, ChangeDetectorRef, Component, Inject, Output, ViewChild, ViewEncapsulation, ɵɵdefineInjectable, ɵɵinject } from '@angular/core';
  9. import { coerceNumberProperty } from '@angular/cdk/coercion';
  10. import { Subject, fromEvent, of, Observable, animationFrameScheduler, asapScheduler, merge } from 'rxjs';
  11. import { distinctUntilChanged, auditTime, filter, takeUntil, startWith, pairwise, shareReplay, switchMap } from 'rxjs/operators';
  12. import { Platform, getRtlScrollAxisType, RtlScrollAxisType, supportsScrollBehavior, PlatformModule } from '@angular/cdk/platform';
  13. import { Directionality, BidiModule } from '@angular/cdk/bidi';
  14. import { __extends } from 'tslib';
  15. import { ArrayDataSource, isDataSource } from '@angular/cdk/collections';
  16. /**
  17. * @fileoverview added by tsickle
  18. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  19. */
  20. /**
  21. * The injection token used to specify the virtual scrolling strategy.
  22. * @type {?}
  23. */
  24. var VIRTUAL_SCROLL_STRATEGY = new InjectionToken('VIRTUAL_SCROLL_STRATEGY');
  25. /**
  26. * @fileoverview added by tsickle
  27. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  28. */
  29. /**
  30. * Virtual scrolling strategy for lists with items of known fixed size.
  31. */
  32. var /**
  33. * Virtual scrolling strategy for lists with items of known fixed size.
  34. */
  35. FixedSizeVirtualScrollStrategy = /** @class */ (function () {
  36. /**
  37. * @param itemSize The size of the items in the virtually scrolling list.
  38. * @param minBufferPx The minimum amount of buffer (in pixels) before needing to render more
  39. * @param maxBufferPx The amount of buffer (in pixels) to render when rendering more.
  40. */
  41. function FixedSizeVirtualScrollStrategy(itemSize, minBufferPx, maxBufferPx) {
  42. this._scrolledIndexChange = new Subject();
  43. /**
  44. * \@docs-private Implemented as part of VirtualScrollStrategy.
  45. */
  46. this.scrolledIndexChange = this._scrolledIndexChange.pipe(distinctUntilChanged());
  47. /**
  48. * The attached viewport.
  49. */
  50. this._viewport = null;
  51. this._itemSize = itemSize;
  52. this._minBufferPx = minBufferPx;
  53. this._maxBufferPx = maxBufferPx;
  54. }
  55. /**
  56. * Attaches this scroll strategy to a viewport.
  57. * @param viewport The viewport to attach this strategy to.
  58. */
  59. /**
  60. * Attaches this scroll strategy to a viewport.
  61. * @param {?} viewport The viewport to attach this strategy to.
  62. * @return {?}
  63. */
  64. FixedSizeVirtualScrollStrategy.prototype.attach = /**
  65. * Attaches this scroll strategy to a viewport.
  66. * @param {?} viewport The viewport to attach this strategy to.
  67. * @return {?}
  68. */
  69. function (viewport) {
  70. this._viewport = viewport;
  71. this._updateTotalContentSize();
  72. this._updateRenderedRange();
  73. };
  74. /** Detaches this scroll strategy from the currently attached viewport. */
  75. /**
  76. * Detaches this scroll strategy from the currently attached viewport.
  77. * @return {?}
  78. */
  79. FixedSizeVirtualScrollStrategy.prototype.detach = /**
  80. * Detaches this scroll strategy from the currently attached viewport.
  81. * @return {?}
  82. */
  83. function () {
  84. this._scrolledIndexChange.complete();
  85. this._viewport = null;
  86. };
  87. /**
  88. * Update the item size and buffer size.
  89. * @param itemSize The size of the items in the virtually scrolling list.
  90. * @param minBufferPx The minimum amount of buffer (in pixels) before needing to render more
  91. * @param maxBufferPx The amount of buffer (in pixels) to render when rendering more.
  92. */
  93. /**
  94. * Update the item size and buffer size.
  95. * @param {?} itemSize The size of the items in the virtually scrolling list.
  96. * @param {?} minBufferPx The minimum amount of buffer (in pixels) before needing to render more
  97. * @param {?} maxBufferPx The amount of buffer (in pixels) to render when rendering more.
  98. * @return {?}
  99. */
  100. FixedSizeVirtualScrollStrategy.prototype.updateItemAndBufferSize = /**
  101. * Update the item size and buffer size.
  102. * @param {?} itemSize The size of the items in the virtually scrolling list.
  103. * @param {?} minBufferPx The minimum amount of buffer (in pixels) before needing to render more
  104. * @param {?} maxBufferPx The amount of buffer (in pixels) to render when rendering more.
  105. * @return {?}
  106. */
  107. function (itemSize, minBufferPx, maxBufferPx) {
  108. if (maxBufferPx < minBufferPx) {
  109. throw Error('CDK virtual scroll: maxBufferPx must be greater than or equal to minBufferPx');
  110. }
  111. this._itemSize = itemSize;
  112. this._minBufferPx = minBufferPx;
  113. this._maxBufferPx = maxBufferPx;
  114. this._updateTotalContentSize();
  115. this._updateRenderedRange();
  116. };
  117. /** @docs-private Implemented as part of VirtualScrollStrategy. */
  118. /**
  119. * \@docs-private Implemented as part of VirtualScrollStrategy.
  120. * @return {?}
  121. */
  122. FixedSizeVirtualScrollStrategy.prototype.onContentScrolled = /**
  123. * \@docs-private Implemented as part of VirtualScrollStrategy.
  124. * @return {?}
  125. */
  126. function () {
  127. this._updateRenderedRange();
  128. };
  129. /** @docs-private Implemented as part of VirtualScrollStrategy. */
  130. /**
  131. * \@docs-private Implemented as part of VirtualScrollStrategy.
  132. * @return {?}
  133. */
  134. FixedSizeVirtualScrollStrategy.prototype.onDataLengthChanged = /**
  135. * \@docs-private Implemented as part of VirtualScrollStrategy.
  136. * @return {?}
  137. */
  138. function () {
  139. this._updateTotalContentSize();
  140. this._updateRenderedRange();
  141. };
  142. /** @docs-private Implemented as part of VirtualScrollStrategy. */
  143. /**
  144. * \@docs-private Implemented as part of VirtualScrollStrategy.
  145. * @return {?}
  146. */
  147. FixedSizeVirtualScrollStrategy.prototype.onContentRendered = /**
  148. * \@docs-private Implemented as part of VirtualScrollStrategy.
  149. * @return {?}
  150. */
  151. function () { };
  152. /** @docs-private Implemented as part of VirtualScrollStrategy. */
  153. /**
  154. * \@docs-private Implemented as part of VirtualScrollStrategy.
  155. * @return {?}
  156. */
  157. FixedSizeVirtualScrollStrategy.prototype.onRenderedOffsetChanged = /**
  158. * \@docs-private Implemented as part of VirtualScrollStrategy.
  159. * @return {?}
  160. */
  161. function () { };
  162. /**
  163. * Scroll to the offset for the given index.
  164. * @param index The index of the element to scroll to.
  165. * @param behavior The ScrollBehavior to use when scrolling.
  166. */
  167. /**
  168. * Scroll to the offset for the given index.
  169. * @param {?} index The index of the element to scroll to.
  170. * @param {?} behavior The ScrollBehavior to use when scrolling.
  171. * @return {?}
  172. */
  173. FixedSizeVirtualScrollStrategy.prototype.scrollToIndex = /**
  174. * Scroll to the offset for the given index.
  175. * @param {?} index The index of the element to scroll to.
  176. * @param {?} behavior The ScrollBehavior to use when scrolling.
  177. * @return {?}
  178. */
  179. function (index, behavior) {
  180. if (this._viewport) {
  181. this._viewport.scrollToOffset(index * this._itemSize, behavior);
  182. }
  183. };
  184. /** Update the viewport's total content size. */
  185. /**
  186. * Update the viewport's total content size.
  187. * @private
  188. * @return {?}
  189. */
  190. FixedSizeVirtualScrollStrategy.prototype._updateTotalContentSize = /**
  191. * Update the viewport's total content size.
  192. * @private
  193. * @return {?}
  194. */
  195. function () {
  196. if (!this._viewport) {
  197. return;
  198. }
  199. this._viewport.setTotalContentSize(this._viewport.getDataLength() * this._itemSize);
  200. };
  201. /** Update the viewport's rendered range. */
  202. /**
  203. * Update the viewport's rendered range.
  204. * @private
  205. * @return {?}
  206. */
  207. FixedSizeVirtualScrollStrategy.prototype._updateRenderedRange = /**
  208. * Update the viewport's rendered range.
  209. * @private
  210. * @return {?}
  211. */
  212. function () {
  213. if (!this._viewport) {
  214. return;
  215. }
  216. /** @type {?} */
  217. var scrollOffset = this._viewport.measureScrollOffset();
  218. /** @type {?} */
  219. var firstVisibleIndex = scrollOffset / this._itemSize;
  220. /** @type {?} */
  221. var renderedRange = this._viewport.getRenderedRange();
  222. /** @type {?} */
  223. var newRange = { start: renderedRange.start, end: renderedRange.end };
  224. /** @type {?} */
  225. var viewportSize = this._viewport.getViewportSize();
  226. /** @type {?} */
  227. var dataLength = this._viewport.getDataLength();
  228. /** @type {?} */
  229. var startBuffer = scrollOffset - newRange.start * this._itemSize;
  230. if (startBuffer < this._minBufferPx && newRange.start != 0) {
  231. /** @type {?} */
  232. var expandStart = Math.ceil((this._maxBufferPx - startBuffer) / this._itemSize);
  233. newRange.start = Math.max(0, newRange.start - expandStart);
  234. newRange.end = Math.min(dataLength, Math.ceil(firstVisibleIndex + (viewportSize + this._minBufferPx) / this._itemSize));
  235. }
  236. else {
  237. /** @type {?} */
  238. var endBuffer = newRange.end * this._itemSize - (scrollOffset + viewportSize);
  239. if (endBuffer < this._minBufferPx && newRange.end != dataLength) {
  240. /** @type {?} */
  241. var expandEnd = Math.ceil((this._maxBufferPx - endBuffer) / this._itemSize);
  242. if (expandEnd > 0) {
  243. newRange.end = Math.min(dataLength, newRange.end + expandEnd);
  244. newRange.start = Math.max(0, Math.floor(firstVisibleIndex - this._minBufferPx / this._itemSize));
  245. }
  246. }
  247. }
  248. this._viewport.setRenderedRange(newRange);
  249. this._viewport.setRenderedContentOffset(this._itemSize * newRange.start);
  250. this._scrolledIndexChange.next(Math.floor(firstVisibleIndex));
  251. };
  252. return FixedSizeVirtualScrollStrategy;
  253. }());
  254. /**
  255. * Provider factory for `FixedSizeVirtualScrollStrategy` that simply extracts the already created
  256. * `FixedSizeVirtualScrollStrategy` from the given directive.
  257. * @param {?} fixedSizeDir The instance of `CdkFixedSizeVirtualScroll` to extract the
  258. * `FixedSizeVirtualScrollStrategy` from.
  259. * @return {?}
  260. */
  261. function _fixedSizeVirtualScrollStrategyFactory(fixedSizeDir) {
  262. return fixedSizeDir._scrollStrategy;
  263. }
  264. /**
  265. * A virtual scroll strategy that supports fixed-size items.
  266. */
  267. var CdkFixedSizeVirtualScroll = /** @class */ (function () {
  268. function CdkFixedSizeVirtualScroll() {
  269. this._itemSize = 20;
  270. this._minBufferPx = 100;
  271. this._maxBufferPx = 200;
  272. /**
  273. * The scroll strategy used by this directive.
  274. */
  275. this._scrollStrategy = new FixedSizeVirtualScrollStrategy(this.itemSize, this.minBufferPx, this.maxBufferPx);
  276. }
  277. Object.defineProperty(CdkFixedSizeVirtualScroll.prototype, "itemSize", {
  278. /** The size of the items in the list (in pixels). */
  279. get: /**
  280. * The size of the items in the list (in pixels).
  281. * @return {?}
  282. */
  283. function () { return this._itemSize; },
  284. set: /**
  285. * @param {?} value
  286. * @return {?}
  287. */
  288. function (value) { this._itemSize = coerceNumberProperty(value); },
  289. enumerable: true,
  290. configurable: true
  291. });
  292. Object.defineProperty(CdkFixedSizeVirtualScroll.prototype, "minBufferPx", {
  293. /**
  294. * The minimum amount of buffer rendered beyond the viewport (in pixels).
  295. * If the amount of buffer dips below this number, more items will be rendered. Defaults to 100px.
  296. */
  297. get: /**
  298. * The minimum amount of buffer rendered beyond the viewport (in pixels).
  299. * If the amount of buffer dips below this number, more items will be rendered. Defaults to 100px.
  300. * @return {?}
  301. */
  302. function () { return this._minBufferPx; },
  303. set: /**
  304. * @param {?} value
  305. * @return {?}
  306. */
  307. function (value) { this._minBufferPx = coerceNumberProperty(value); },
  308. enumerable: true,
  309. configurable: true
  310. });
  311. Object.defineProperty(CdkFixedSizeVirtualScroll.prototype, "maxBufferPx", {
  312. /**
  313. * The number of pixels worth of buffer to render for when rendering new items. Defaults to 200px.
  314. */
  315. get: /**
  316. * The number of pixels worth of buffer to render for when rendering new items. Defaults to 200px.
  317. * @return {?}
  318. */
  319. function () { return this._maxBufferPx; },
  320. set: /**
  321. * @param {?} value
  322. * @return {?}
  323. */
  324. function (value) { this._maxBufferPx = coerceNumberProperty(value); },
  325. enumerable: true,
  326. configurable: true
  327. });
  328. /**
  329. * @return {?}
  330. */
  331. CdkFixedSizeVirtualScroll.prototype.ngOnChanges = /**
  332. * @return {?}
  333. */
  334. function () {
  335. this._scrollStrategy.updateItemAndBufferSize(this.itemSize, this.minBufferPx, this.maxBufferPx);
  336. };
  337. CdkFixedSizeVirtualScroll.decorators = [
  338. { type: Directive, args: [{
  339. selector: 'cdk-virtual-scroll-viewport[itemSize]',
  340. providers: [{
  341. provide: VIRTUAL_SCROLL_STRATEGY,
  342. useFactory: _fixedSizeVirtualScrollStrategyFactory,
  343. deps: [forwardRef((/**
  344. * @return {?}
  345. */
  346. function () { return CdkFixedSizeVirtualScroll; }))],
  347. }],
  348. },] },
  349. ];
  350. CdkFixedSizeVirtualScroll.propDecorators = {
  351. itemSize: [{ type: Input }],
  352. minBufferPx: [{ type: Input }],
  353. maxBufferPx: [{ type: Input }]
  354. };
  355. return CdkFixedSizeVirtualScroll;
  356. }());
  357. /**
  358. * @fileoverview added by tsickle
  359. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  360. */
  361. /**
  362. * Time in ms to throttle the scrolling events by default.
  363. * @type {?}
  364. */
  365. var DEFAULT_SCROLL_TIME = 20;
  366. /**
  367. * Service contained all registered Scrollable references and emits an event when any one of the
  368. * Scrollable references emit a scrolled event.
  369. */
  370. var ScrollDispatcher = /** @class */ (function () {
  371. function ScrollDispatcher(_ngZone, _platform) {
  372. this._ngZone = _ngZone;
  373. this._platform = _platform;
  374. /**
  375. * Subject for notifying that a registered scrollable reference element has been scrolled.
  376. */
  377. this._scrolled = new Subject();
  378. /**
  379. * Keeps track of the global `scroll` and `resize` subscriptions.
  380. */
  381. this._globalSubscription = null;
  382. /**
  383. * Keeps track of the amount of subscriptions to `scrolled`. Used for cleaning up afterwards.
  384. */
  385. this._scrolledCount = 0;
  386. /**
  387. * Map of all the scrollable references that are registered with the service and their
  388. * scroll event subscriptions.
  389. */
  390. this.scrollContainers = new Map();
  391. }
  392. /**
  393. * Registers a scrollable instance with the service and listens for its scrolled events. When the
  394. * scrollable is scrolled, the service emits the event to its scrolled observable.
  395. * @param scrollable Scrollable instance to be registered.
  396. */
  397. /**
  398. * Registers a scrollable instance with the service and listens for its scrolled events. When the
  399. * scrollable is scrolled, the service emits the event to its scrolled observable.
  400. * @param {?} scrollable Scrollable instance to be registered.
  401. * @return {?}
  402. */
  403. ScrollDispatcher.prototype.register = /**
  404. * Registers a scrollable instance with the service and listens for its scrolled events. When the
  405. * scrollable is scrolled, the service emits the event to its scrolled observable.
  406. * @param {?} scrollable Scrollable instance to be registered.
  407. * @return {?}
  408. */
  409. function (scrollable) {
  410. var _this = this;
  411. if (!this.scrollContainers.has(scrollable)) {
  412. this.scrollContainers.set(scrollable, scrollable.elementScrolled()
  413. .subscribe((/**
  414. * @return {?}
  415. */
  416. function () { return _this._scrolled.next(scrollable); })));
  417. }
  418. };
  419. /**
  420. * Deregisters a Scrollable reference and unsubscribes from its scroll event observable.
  421. * @param scrollable Scrollable instance to be deregistered.
  422. */
  423. /**
  424. * Deregisters a Scrollable reference and unsubscribes from its scroll event observable.
  425. * @param {?} scrollable Scrollable instance to be deregistered.
  426. * @return {?}
  427. */
  428. ScrollDispatcher.prototype.deregister = /**
  429. * Deregisters a Scrollable reference and unsubscribes from its scroll event observable.
  430. * @param {?} scrollable Scrollable instance to be deregistered.
  431. * @return {?}
  432. */
  433. function (scrollable) {
  434. /** @type {?} */
  435. var scrollableReference = this.scrollContainers.get(scrollable);
  436. if (scrollableReference) {
  437. scrollableReference.unsubscribe();
  438. this.scrollContainers.delete(scrollable);
  439. }
  440. };
  441. /**
  442. * Returns an observable that emits an event whenever any of the registered Scrollable
  443. * references (or window, document, or body) fire a scrolled event. Can provide a time in ms
  444. * to override the default "throttle" time.
  445. *
  446. * **Note:** in order to avoid hitting change detection for every scroll event,
  447. * all of the events emitted from this stream will be run outside the Angular zone.
  448. * If you need to update any data bindings as a result of a scroll event, you have
  449. * to run the callback using `NgZone.run`.
  450. */
  451. /**
  452. * Returns an observable that emits an event whenever any of the registered Scrollable
  453. * references (or window, document, or body) fire a scrolled event. Can provide a time in ms
  454. * to override the default "throttle" time.
  455. *
  456. * **Note:** in order to avoid hitting change detection for every scroll event,
  457. * all of the events emitted from this stream will be run outside the Angular zone.
  458. * If you need to update any data bindings as a result of a scroll event, you have
  459. * to run the callback using `NgZone.run`.
  460. * @param {?=} auditTimeInMs
  461. * @return {?}
  462. */
  463. ScrollDispatcher.prototype.scrolled = /**
  464. * Returns an observable that emits an event whenever any of the registered Scrollable
  465. * references (or window, document, or body) fire a scrolled event. Can provide a time in ms
  466. * to override the default "throttle" time.
  467. *
  468. * **Note:** in order to avoid hitting change detection for every scroll event,
  469. * all of the events emitted from this stream will be run outside the Angular zone.
  470. * If you need to update any data bindings as a result of a scroll event, you have
  471. * to run the callback using `NgZone.run`.
  472. * @param {?=} auditTimeInMs
  473. * @return {?}
  474. */
  475. function (auditTimeInMs) {
  476. var _this = this;
  477. if (auditTimeInMs === void 0) { auditTimeInMs = DEFAULT_SCROLL_TIME; }
  478. if (!this._platform.isBrowser) {
  479. return of();
  480. }
  481. return new Observable((/**
  482. * @param {?} observer
  483. * @return {?}
  484. */
  485. function (observer) {
  486. if (!_this._globalSubscription) {
  487. _this._addGlobalListener();
  488. }
  489. // In the case of a 0ms delay, use an observable without auditTime
  490. // since it does add a perceptible delay in processing overhead.
  491. /** @type {?} */
  492. var subscription = auditTimeInMs > 0 ?
  493. _this._scrolled.pipe(auditTime(auditTimeInMs)).subscribe(observer) :
  494. _this._scrolled.subscribe(observer);
  495. _this._scrolledCount++;
  496. return (/**
  497. * @return {?}
  498. */
  499. function () {
  500. subscription.unsubscribe();
  501. _this._scrolledCount--;
  502. if (!_this._scrolledCount) {
  503. _this._removeGlobalListener();
  504. }
  505. });
  506. }));
  507. };
  508. /**
  509. * @return {?}
  510. */
  511. ScrollDispatcher.prototype.ngOnDestroy = /**
  512. * @return {?}
  513. */
  514. function () {
  515. var _this = this;
  516. this._removeGlobalListener();
  517. this.scrollContainers.forEach((/**
  518. * @param {?} _
  519. * @param {?} container
  520. * @return {?}
  521. */
  522. function (_, container) { return _this.deregister(container); }));
  523. this._scrolled.complete();
  524. };
  525. /**
  526. * Returns an observable that emits whenever any of the
  527. * scrollable ancestors of an element are scrolled.
  528. * @param elementRef Element whose ancestors to listen for.
  529. * @param auditTimeInMs Time to throttle the scroll events.
  530. */
  531. /**
  532. * Returns an observable that emits whenever any of the
  533. * scrollable ancestors of an element are scrolled.
  534. * @param {?} elementRef Element whose ancestors to listen for.
  535. * @param {?=} auditTimeInMs Time to throttle the scroll events.
  536. * @return {?}
  537. */
  538. ScrollDispatcher.prototype.ancestorScrolled = /**
  539. * Returns an observable that emits whenever any of the
  540. * scrollable ancestors of an element are scrolled.
  541. * @param {?} elementRef Element whose ancestors to listen for.
  542. * @param {?=} auditTimeInMs Time to throttle the scroll events.
  543. * @return {?}
  544. */
  545. function (elementRef, auditTimeInMs) {
  546. /** @type {?} */
  547. var ancestors = this.getAncestorScrollContainers(elementRef);
  548. return this.scrolled(auditTimeInMs).pipe(filter((/**
  549. * @param {?} target
  550. * @return {?}
  551. */
  552. function (target) {
  553. return !target || ancestors.indexOf(target) > -1;
  554. })));
  555. };
  556. /** Returns all registered Scrollables that contain the provided element. */
  557. /**
  558. * Returns all registered Scrollables that contain the provided element.
  559. * @param {?} elementRef
  560. * @return {?}
  561. */
  562. ScrollDispatcher.prototype.getAncestorScrollContainers = /**
  563. * Returns all registered Scrollables that contain the provided element.
  564. * @param {?} elementRef
  565. * @return {?}
  566. */
  567. function (elementRef) {
  568. var _this = this;
  569. /** @type {?} */
  570. var scrollingContainers = [];
  571. this.scrollContainers.forEach((/**
  572. * @param {?} _subscription
  573. * @param {?} scrollable
  574. * @return {?}
  575. */
  576. function (_subscription, scrollable) {
  577. if (_this._scrollableContainsElement(scrollable, elementRef)) {
  578. scrollingContainers.push(scrollable);
  579. }
  580. }));
  581. return scrollingContainers;
  582. };
  583. /** Returns true if the element is contained within the provided Scrollable. */
  584. /**
  585. * Returns true if the element is contained within the provided Scrollable.
  586. * @private
  587. * @param {?} scrollable
  588. * @param {?} elementRef
  589. * @return {?}
  590. */
  591. ScrollDispatcher.prototype._scrollableContainsElement = /**
  592. * Returns true if the element is contained within the provided Scrollable.
  593. * @private
  594. * @param {?} scrollable
  595. * @param {?} elementRef
  596. * @return {?}
  597. */
  598. function (scrollable, elementRef) {
  599. /** @type {?} */
  600. var element = elementRef.nativeElement;
  601. /** @type {?} */
  602. var scrollableElement = scrollable.getElementRef().nativeElement;
  603. // Traverse through the element parents until we reach null, checking if any of the elements
  604. // are the scrollable's element.
  605. do {
  606. if (element == scrollableElement) {
  607. return true;
  608. }
  609. } while (element = (/** @type {?} */ (element)).parentElement);
  610. return false;
  611. };
  612. /** Sets up the global scroll listeners. */
  613. /**
  614. * Sets up the global scroll listeners.
  615. * @private
  616. * @return {?}
  617. */
  618. ScrollDispatcher.prototype._addGlobalListener = /**
  619. * Sets up the global scroll listeners.
  620. * @private
  621. * @return {?}
  622. */
  623. function () {
  624. var _this = this;
  625. this._globalSubscription = this._ngZone.runOutsideAngular((/**
  626. * @return {?}
  627. */
  628. function () {
  629. return fromEvent(window.document, 'scroll').subscribe((/**
  630. * @return {?}
  631. */
  632. function () { return _this._scrolled.next(); }));
  633. }));
  634. };
  635. /** Cleans up the global scroll listener. */
  636. /**
  637. * Cleans up the global scroll listener.
  638. * @private
  639. * @return {?}
  640. */
  641. ScrollDispatcher.prototype._removeGlobalListener = /**
  642. * Cleans up the global scroll listener.
  643. * @private
  644. * @return {?}
  645. */
  646. function () {
  647. if (this._globalSubscription) {
  648. this._globalSubscription.unsubscribe();
  649. this._globalSubscription = null;
  650. }
  651. };
  652. ScrollDispatcher.decorators = [
  653. { type: Injectable, args: [{ providedIn: 'root' },] },
  654. ];
  655. /** @nocollapse */
  656. ScrollDispatcher.ctorParameters = function () { return [
  657. { type: NgZone },
  658. { type: Platform }
  659. ]; };
  660. /** @nocollapse */ ScrollDispatcher.ngInjectableDef = ɵɵdefineInjectable({ factory: function ScrollDispatcher_Factory() { return new ScrollDispatcher(ɵɵinject(NgZone), ɵɵinject(Platform)); }, token: ScrollDispatcher, providedIn: "root" });
  661. return ScrollDispatcher;
  662. }());
  663. /**
  664. * \@docs-private \@deprecated \@breaking-change 8.0.0
  665. * @param {?} parentDispatcher
  666. * @param {?} ngZone
  667. * @param {?} platform
  668. * @return {?}
  669. */
  670. function SCROLL_DISPATCHER_PROVIDER_FACTORY(parentDispatcher, ngZone, platform) {
  671. return parentDispatcher || new ScrollDispatcher(ngZone, platform);
  672. }
  673. /**
  674. * \@docs-private \@deprecated \@breaking-change 8.0.0
  675. * @type {?}
  676. */
  677. var SCROLL_DISPATCHER_PROVIDER = {
  678. // If there is already a ScrollDispatcher available, use that. Otherwise, provide a new one.
  679. provide: ScrollDispatcher,
  680. deps: [[new Optional(), new SkipSelf(), ScrollDispatcher], NgZone, Platform],
  681. useFactory: SCROLL_DISPATCHER_PROVIDER_FACTORY
  682. };
  683. /**
  684. * @fileoverview added by tsickle
  685. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  686. */
  687. /**
  688. * Sends an event when the directive's element is scrolled. Registers itself with the
  689. * ScrollDispatcher service to include itself as part of its collection of scrolling events that it
  690. * can be listened to through the service.
  691. */
  692. var CdkScrollable = /** @class */ (function () {
  693. function CdkScrollable(elementRef, scrollDispatcher, ngZone, dir) {
  694. var _this = this;
  695. this.elementRef = elementRef;
  696. this.scrollDispatcher = scrollDispatcher;
  697. this.ngZone = ngZone;
  698. this.dir = dir;
  699. this._destroyed = new Subject();
  700. this._elementScrolled = new Observable((/**
  701. * @param {?} observer
  702. * @return {?}
  703. */
  704. function (observer) {
  705. return _this.ngZone.runOutsideAngular((/**
  706. * @return {?}
  707. */
  708. function () {
  709. return fromEvent(_this.elementRef.nativeElement, 'scroll').pipe(takeUntil(_this._destroyed))
  710. .subscribe(observer);
  711. }));
  712. }));
  713. }
  714. /**
  715. * @return {?}
  716. */
  717. CdkScrollable.prototype.ngOnInit = /**
  718. * @return {?}
  719. */
  720. function () {
  721. this.scrollDispatcher.register(this);
  722. };
  723. /**
  724. * @return {?}
  725. */
  726. CdkScrollable.prototype.ngOnDestroy = /**
  727. * @return {?}
  728. */
  729. function () {
  730. this.scrollDispatcher.deregister(this);
  731. this._destroyed.next();
  732. this._destroyed.complete();
  733. };
  734. /** Returns observable that emits when a scroll event is fired on the host element. */
  735. /**
  736. * Returns observable that emits when a scroll event is fired on the host element.
  737. * @return {?}
  738. */
  739. CdkScrollable.prototype.elementScrolled = /**
  740. * Returns observable that emits when a scroll event is fired on the host element.
  741. * @return {?}
  742. */
  743. function () {
  744. return this._elementScrolled;
  745. };
  746. /** Gets the ElementRef for the viewport. */
  747. /**
  748. * Gets the ElementRef for the viewport.
  749. * @return {?}
  750. */
  751. CdkScrollable.prototype.getElementRef = /**
  752. * Gets the ElementRef for the viewport.
  753. * @return {?}
  754. */
  755. function () {
  756. return this.elementRef;
  757. };
  758. /**
  759. * Scrolls to the specified offsets. This is a normalized version of the browser's native scrollTo
  760. * method, since browsers are not consistent about what scrollLeft means in RTL. For this method
  761. * left and right always refer to the left and right side of the scrolling container irrespective
  762. * of the layout direction. start and end refer to left and right in an LTR context and vice-versa
  763. * in an RTL context.
  764. * @param options specified the offsets to scroll to.
  765. */
  766. /**
  767. * Scrolls to the specified offsets. This is a normalized version of the browser's native scrollTo
  768. * method, since browsers are not consistent about what scrollLeft means in RTL. For this method
  769. * left and right always refer to the left and right side of the scrolling container irrespective
  770. * of the layout direction. start and end refer to left and right in an LTR context and vice-versa
  771. * in an RTL context.
  772. * @param {?} options specified the offsets to scroll to.
  773. * @return {?}
  774. */
  775. CdkScrollable.prototype.scrollTo = /**
  776. * Scrolls to the specified offsets. This is a normalized version of the browser's native scrollTo
  777. * method, since browsers are not consistent about what scrollLeft means in RTL. For this method
  778. * left and right always refer to the left and right side of the scrolling container irrespective
  779. * of the layout direction. start and end refer to left and right in an LTR context and vice-versa
  780. * in an RTL context.
  781. * @param {?} options specified the offsets to scroll to.
  782. * @return {?}
  783. */
  784. function (options) {
  785. /** @type {?} */
  786. var el = this.elementRef.nativeElement;
  787. /** @type {?} */
  788. var isRtl = this.dir && this.dir.value == 'rtl';
  789. // Rewrite start & end offsets as right or left offsets.
  790. options.left = options.left == null ? (isRtl ? options.end : options.start) : options.left;
  791. options.right = options.right == null ? (isRtl ? options.start : options.end) : options.right;
  792. // Rewrite the bottom offset as a top offset.
  793. if (options.bottom != null) {
  794. ((/** @type {?} */ (options))).top =
  795. el.scrollHeight - el.clientHeight - options.bottom;
  796. }
  797. // Rewrite the right offset as a left offset.
  798. if (isRtl && getRtlScrollAxisType() != RtlScrollAxisType.NORMAL) {
  799. if (options.left != null) {
  800. ((/** @type {?} */ (options))).right =
  801. el.scrollWidth - el.clientWidth - options.left;
  802. }
  803. if (getRtlScrollAxisType() == RtlScrollAxisType.INVERTED) {
  804. options.left = options.right;
  805. }
  806. else if (getRtlScrollAxisType() == RtlScrollAxisType.NEGATED) {
  807. options.left = options.right ? -options.right : options.right;
  808. }
  809. }
  810. else {
  811. if (options.right != null) {
  812. ((/** @type {?} */ (options))).left =
  813. el.scrollWidth - el.clientWidth - options.right;
  814. }
  815. }
  816. this._applyScrollToOptions(options);
  817. };
  818. /**
  819. * @private
  820. * @param {?} options
  821. * @return {?}
  822. */
  823. CdkScrollable.prototype._applyScrollToOptions = /**
  824. * @private
  825. * @param {?} options
  826. * @return {?}
  827. */
  828. function (options) {
  829. /** @type {?} */
  830. var el = this.elementRef.nativeElement;
  831. if (supportsScrollBehavior()) {
  832. el.scrollTo(options);
  833. }
  834. else {
  835. if (options.top != null) {
  836. el.scrollTop = options.top;
  837. }
  838. if (options.left != null) {
  839. el.scrollLeft = options.left;
  840. }
  841. }
  842. };
  843. /**
  844. * Measures the scroll offset relative to the specified edge of the viewport. This method can be
  845. * used instead of directly checking scrollLeft or scrollTop, since browsers are not consistent
  846. * about what scrollLeft means in RTL. The values returned by this method are normalized such that
  847. * left and right always refer to the left and right side of the scrolling container irrespective
  848. * of the layout direction. start and end refer to left and right in an LTR context and vice-versa
  849. * in an RTL context.
  850. * @param from The edge to measure from.
  851. */
  852. /**
  853. * Measures the scroll offset relative to the specified edge of the viewport. This method can be
  854. * used instead of directly checking scrollLeft or scrollTop, since browsers are not consistent
  855. * about what scrollLeft means in RTL. The values returned by this method are normalized such that
  856. * left and right always refer to the left and right side of the scrolling container irrespective
  857. * of the layout direction. start and end refer to left and right in an LTR context and vice-versa
  858. * in an RTL context.
  859. * @param {?} from The edge to measure from.
  860. * @return {?}
  861. */
  862. CdkScrollable.prototype.measureScrollOffset = /**
  863. * Measures the scroll offset relative to the specified edge of the viewport. This method can be
  864. * used instead of directly checking scrollLeft or scrollTop, since browsers are not consistent
  865. * about what scrollLeft means in RTL. The values returned by this method are normalized such that
  866. * left and right always refer to the left and right side of the scrolling container irrespective
  867. * of the layout direction. start and end refer to left and right in an LTR context and vice-versa
  868. * in an RTL context.
  869. * @param {?} from The edge to measure from.
  870. * @return {?}
  871. */
  872. function (from) {
  873. /** @type {?} */
  874. var LEFT = 'left';
  875. /** @type {?} */
  876. var RIGHT = 'right';
  877. /** @type {?} */
  878. var el = this.elementRef.nativeElement;
  879. if (from == 'top') {
  880. return el.scrollTop;
  881. }
  882. if (from == 'bottom') {
  883. return el.scrollHeight - el.clientHeight - el.scrollTop;
  884. }
  885. // Rewrite start & end as left or right offsets.
  886. /** @type {?} */
  887. var isRtl = this.dir && this.dir.value == 'rtl';
  888. if (from == 'start') {
  889. from = isRtl ? RIGHT : LEFT;
  890. }
  891. else if (from == 'end') {
  892. from = isRtl ? LEFT : RIGHT;
  893. }
  894. if (isRtl && getRtlScrollAxisType() == RtlScrollAxisType.INVERTED) {
  895. // For INVERTED, scrollLeft is (scrollWidth - clientWidth) when scrolled all the way left and
  896. // 0 when scrolled all the way right.
  897. if (from == LEFT) {
  898. return el.scrollWidth - el.clientWidth - el.scrollLeft;
  899. }
  900. else {
  901. return el.scrollLeft;
  902. }
  903. }
  904. else if (isRtl && getRtlScrollAxisType() == RtlScrollAxisType.NEGATED) {
  905. // For NEGATED, scrollLeft is -(scrollWidth - clientWidth) when scrolled all the way left and
  906. // 0 when scrolled all the way right.
  907. if (from == LEFT) {
  908. return el.scrollLeft + el.scrollWidth - el.clientWidth;
  909. }
  910. else {
  911. return -el.scrollLeft;
  912. }
  913. }
  914. else {
  915. // For NORMAL, as well as non-RTL contexts, scrollLeft is 0 when scrolled all the way left and
  916. // (scrollWidth - clientWidth) when scrolled all the way right.
  917. if (from == LEFT) {
  918. return el.scrollLeft;
  919. }
  920. else {
  921. return el.scrollWidth - el.clientWidth - el.scrollLeft;
  922. }
  923. }
  924. };
  925. CdkScrollable.decorators = [
  926. { type: Directive, args: [{
  927. selector: '[cdk-scrollable], [cdkScrollable]'
  928. },] },
  929. ];
  930. /** @nocollapse */
  931. CdkScrollable.ctorParameters = function () { return [
  932. { type: ElementRef },
  933. { type: ScrollDispatcher },
  934. { type: NgZone },
  935. { type: Directionality, decorators: [{ type: Optional }] }
  936. ]; };
  937. return CdkScrollable;
  938. }());
  939. /**
  940. * @fileoverview added by tsickle
  941. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  942. */
  943. /**
  944. * Checks if the given ranges are equal.
  945. * @param {?} r1
  946. * @param {?} r2
  947. * @return {?}
  948. */
  949. function rangesEqual(r1, r2) {
  950. return r1.start == r2.start && r1.end == r2.end;
  951. }
  952. /**
  953. * Scheduler to be used for scroll events. Needs to fall back to
  954. * something that doesn't rely on requestAnimationFrame on environments
  955. * that don't support it (e.g. server-side rendering).
  956. * @type {?}
  957. */
  958. var SCROLL_SCHEDULER = typeof requestAnimationFrame !== 'undefined' ? animationFrameScheduler : asapScheduler;
  959. /**
  960. * A viewport that virtualizes its scrolling with the help of `CdkVirtualForOf`.
  961. */
  962. var CdkVirtualScrollViewport = /** @class */ (function (_super) {
  963. __extends(CdkVirtualScrollViewport, _super);
  964. function CdkVirtualScrollViewport(elementRef, _changeDetectorRef, ngZone, _scrollStrategy, dir, scrollDispatcher) {
  965. var _this = _super.call(this, elementRef, scrollDispatcher, ngZone, dir) || this;
  966. _this.elementRef = elementRef;
  967. _this._changeDetectorRef = _changeDetectorRef;
  968. _this._scrollStrategy = _scrollStrategy;
  969. /**
  970. * Emits when the viewport is detached from a CdkVirtualForOf.
  971. */
  972. _this._detachedSubject = new Subject();
  973. /**
  974. * Emits when the rendered range changes.
  975. */
  976. _this._renderedRangeSubject = new Subject();
  977. _this._orientation = 'vertical';
  978. // Note: we don't use the typical EventEmitter here because we need to subscribe to the scroll
  979. // strategy lazily (i.e. only if the user is actually listening to the events). We do this because
  980. // depending on how the strategy calculates the scrolled index, it may come at a cost to
  981. // performance.
  982. /**
  983. * Emits when the index of the first element visible in the viewport changes.
  984. */
  985. _this.scrolledIndexChange = new Observable((/**
  986. * @param {?} observer
  987. * @return {?}
  988. */
  989. function (observer) {
  990. return _this._scrollStrategy.scrolledIndexChange.subscribe((/**
  991. * @param {?} index
  992. * @return {?}
  993. */
  994. function (index) {
  995. return Promise.resolve().then((/**
  996. * @return {?}
  997. */
  998. function () { return _this.ngZone.run((/**
  999. * @return {?}
  1000. */
  1001. function () { return observer.next(index); })); }));
  1002. }));
  1003. }));
  1004. /**
  1005. * A stream that emits whenever the rendered range changes.
  1006. */
  1007. _this.renderedRangeStream = _this._renderedRangeSubject.asObservable();
  1008. /**
  1009. * The total size of all content (in pixels), including content that is not currently rendered.
  1010. */
  1011. _this._totalContentSize = 0;
  1012. /**
  1013. * A string representing the `style.width` property value to be used for the spacer element.
  1014. */
  1015. _this._totalContentWidth = '';
  1016. /**
  1017. * A string representing the `style.height` property value to be used for the spacer element.
  1018. */
  1019. _this._totalContentHeight = '';
  1020. /**
  1021. * The currently rendered range of indices.
  1022. */
  1023. _this._renderedRange = { start: 0, end: 0 };
  1024. /**
  1025. * The length of the data bound to this viewport (in number of items).
  1026. */
  1027. _this._dataLength = 0;
  1028. /**
  1029. * The size of the viewport (in pixels).
  1030. */
  1031. _this._viewportSize = 0;
  1032. /**
  1033. * The last rendered content offset that was set.
  1034. */
  1035. _this._renderedContentOffset = 0;
  1036. /**
  1037. * Whether the last rendered content offset was to the end of the content (and therefore needs to
  1038. * be rewritten as an offset to the start of the content).
  1039. */
  1040. _this._renderedContentOffsetNeedsRewrite = false;
  1041. /**
  1042. * Whether there is a pending change detection cycle.
  1043. */
  1044. _this._isChangeDetectionPending = false;
  1045. /**
  1046. * A list of functions to run after the next change detection cycle.
  1047. */
  1048. _this._runAfterChangeDetection = [];
  1049. if (!_scrollStrategy) {
  1050. throw Error('Error: cdk-virtual-scroll-viewport requires the "itemSize" property to be set.');
  1051. }
  1052. return _this;
  1053. }
  1054. Object.defineProperty(CdkVirtualScrollViewport.prototype, "orientation", {
  1055. /** The direction the viewport scrolls. */
  1056. get: /**
  1057. * The direction the viewport scrolls.
  1058. * @return {?}
  1059. */
  1060. function () {
  1061. return this._orientation;
  1062. },
  1063. set: /**
  1064. * @param {?} orientation
  1065. * @return {?}
  1066. */
  1067. function (orientation) {
  1068. if (this._orientation !== orientation) {
  1069. this._orientation = orientation;
  1070. this._calculateSpacerSize();
  1071. }
  1072. },
  1073. enumerable: true,
  1074. configurable: true
  1075. });
  1076. /**
  1077. * @return {?}
  1078. */
  1079. CdkVirtualScrollViewport.prototype.ngOnInit = /**
  1080. * @return {?}
  1081. */
  1082. function () {
  1083. var _this = this;
  1084. _super.prototype.ngOnInit.call(this);
  1085. // It's still too early to measure the viewport at this point. Deferring with a promise allows
  1086. // the Viewport to be rendered with the correct size before we measure. We run this outside the
  1087. // zone to avoid causing more change detection cycles. We handle the change detection loop
  1088. // ourselves instead.
  1089. this.ngZone.runOutsideAngular((/**
  1090. * @return {?}
  1091. */
  1092. function () { return Promise.resolve().then((/**
  1093. * @return {?}
  1094. */
  1095. function () {
  1096. _this._measureViewportSize();
  1097. _this._scrollStrategy.attach(_this);
  1098. _this.elementScrolled()
  1099. .pipe(
  1100. // Start off with a fake scroll event so we properly detect our initial position.
  1101. startWith((/** @type {?} */ (null))),
  1102. // Collect multiple events into one until the next animation frame. This way if
  1103. // there are multiple scroll events in the same frame we only need to recheck
  1104. // our layout once.
  1105. auditTime(0, SCROLL_SCHEDULER))
  1106. .subscribe((/**
  1107. * @return {?}
  1108. */
  1109. function () { return _this._scrollStrategy.onContentScrolled(); }));
  1110. _this._markChangeDetectionNeeded();
  1111. })); }));
  1112. };
  1113. /**
  1114. * @return {?}
  1115. */
  1116. CdkVirtualScrollViewport.prototype.ngOnDestroy = /**
  1117. * @return {?}
  1118. */
  1119. function () {
  1120. this.detach();
  1121. this._scrollStrategy.detach();
  1122. // Complete all subjects
  1123. this._renderedRangeSubject.complete();
  1124. this._detachedSubject.complete();
  1125. _super.prototype.ngOnDestroy.call(this);
  1126. };
  1127. /** Attaches a `CdkVirtualForOf` to this viewport. */
  1128. /**
  1129. * Attaches a `CdkVirtualForOf` to this viewport.
  1130. * @param {?} forOf
  1131. * @return {?}
  1132. */
  1133. CdkVirtualScrollViewport.prototype.attach = /**
  1134. * Attaches a `CdkVirtualForOf` to this viewport.
  1135. * @param {?} forOf
  1136. * @return {?}
  1137. */
  1138. function (forOf) {
  1139. var _this = this;
  1140. if (this._forOf) {
  1141. throw Error('CdkVirtualScrollViewport is already attached.');
  1142. }
  1143. // Subscribe to the data stream of the CdkVirtualForOf to keep track of when the data length
  1144. // changes. Run outside the zone to avoid triggering change detection, since we're managing the
  1145. // change detection loop ourselves.
  1146. this.ngZone.runOutsideAngular((/**
  1147. * @return {?}
  1148. */
  1149. function () {
  1150. _this._forOf = forOf;
  1151. _this._forOf.dataStream.pipe(takeUntil(_this._detachedSubject)).subscribe((/**
  1152. * @param {?} data
  1153. * @return {?}
  1154. */
  1155. function (data) {
  1156. /** @type {?} */
  1157. var newLength = data.length;
  1158. if (newLength !== _this._dataLength) {
  1159. _this._dataLength = newLength;
  1160. _this._scrollStrategy.onDataLengthChanged();
  1161. }
  1162. _this._doChangeDetection();
  1163. }));
  1164. }));
  1165. };
  1166. /** Detaches the current `CdkVirtualForOf`. */
  1167. /**
  1168. * Detaches the current `CdkVirtualForOf`.
  1169. * @return {?}
  1170. */
  1171. CdkVirtualScrollViewport.prototype.detach = /**
  1172. * Detaches the current `CdkVirtualForOf`.
  1173. * @return {?}
  1174. */
  1175. function () {
  1176. this._forOf = null;
  1177. this._detachedSubject.next();
  1178. };
  1179. /** Gets the length of the data bound to this viewport (in number of items). */
  1180. /**
  1181. * Gets the length of the data bound to this viewport (in number of items).
  1182. * @return {?}
  1183. */
  1184. CdkVirtualScrollViewport.prototype.getDataLength = /**
  1185. * Gets the length of the data bound to this viewport (in number of items).
  1186. * @return {?}
  1187. */
  1188. function () {
  1189. return this._dataLength;
  1190. };
  1191. /** Gets the size of the viewport (in pixels). */
  1192. /**
  1193. * Gets the size of the viewport (in pixels).
  1194. * @return {?}
  1195. */
  1196. CdkVirtualScrollViewport.prototype.getViewportSize = /**
  1197. * Gets the size of the viewport (in pixels).
  1198. * @return {?}
  1199. */
  1200. function () {
  1201. return this._viewportSize;
  1202. };
  1203. // TODO(mmalerba): This is technically out of sync with what's really rendered until a render
  1204. // cycle happens. I'm being careful to only call it after the render cycle is complete and before
  1205. // setting it to something else, but its error prone and should probably be split into
  1206. // `pendingRange` and `renderedRange`, the latter reflecting whats actually in the DOM.
  1207. /** Get the current rendered range of items. */
  1208. // TODO(mmalerba): This is technically out of sync with what's really rendered until a render
  1209. // cycle happens. I'm being careful to only call it after the render cycle is complete and before
  1210. // setting it to something else, but its error prone and should probably be split into
  1211. // `pendingRange` and `renderedRange`, the latter reflecting whats actually in the DOM.
  1212. /**
  1213. * Get the current rendered range of items.
  1214. * @return {?}
  1215. */
  1216. CdkVirtualScrollViewport.prototype.getRenderedRange =
  1217. // TODO(mmalerba): This is technically out of sync with what's really rendered until a render
  1218. // cycle happens. I'm being careful to only call it after the render cycle is complete and before
  1219. // setting it to something else, but its error prone and should probably be split into
  1220. // `pendingRange` and `renderedRange`, the latter reflecting whats actually in the DOM.
  1221. /**
  1222. * Get the current rendered range of items.
  1223. * @return {?}
  1224. */
  1225. function () {
  1226. return this._renderedRange;
  1227. };
  1228. /**
  1229. * Sets the total size of all content (in pixels), including content that is not currently
  1230. * rendered.
  1231. */
  1232. /**
  1233. * Sets the total size of all content (in pixels), including content that is not currently
  1234. * rendered.
  1235. * @param {?} size
  1236. * @return {?}
  1237. */
  1238. CdkVirtualScrollViewport.prototype.setTotalContentSize = /**
  1239. * Sets the total size of all content (in pixels), including content that is not currently
  1240. * rendered.
  1241. * @param {?} size
  1242. * @return {?}
  1243. */
  1244. function (size) {
  1245. if (this._totalContentSize !== size) {
  1246. this._totalContentSize = size;
  1247. this._calculateSpacerSize();
  1248. this._markChangeDetectionNeeded();
  1249. }
  1250. };
  1251. /** Sets the currently rendered range of indices. */
  1252. /**
  1253. * Sets the currently rendered range of indices.
  1254. * @param {?} range
  1255. * @return {?}
  1256. */
  1257. CdkVirtualScrollViewport.prototype.setRenderedRange = /**
  1258. * Sets the currently rendered range of indices.
  1259. * @param {?} range
  1260. * @return {?}
  1261. */
  1262. function (range) {
  1263. var _this = this;
  1264. if (!rangesEqual(this._renderedRange, range)) {
  1265. this._renderedRangeSubject.next(this._renderedRange = range);
  1266. this._markChangeDetectionNeeded((/**
  1267. * @return {?}
  1268. */
  1269. function () { return _this._scrollStrategy.onContentRendered(); }));
  1270. }
  1271. };
  1272. /**
  1273. * Gets the offset from the start of the viewport to the start of the rendered data (in pixels).
  1274. */
  1275. /**
  1276. * Gets the offset from the start of the viewport to the start of the rendered data (in pixels).
  1277. * @return {?}
  1278. */
  1279. CdkVirtualScrollViewport.prototype.getOffsetToRenderedContentStart = /**
  1280. * Gets the offset from the start of the viewport to the start of the rendered data (in pixels).
  1281. * @return {?}
  1282. */
  1283. function () {
  1284. return this._renderedContentOffsetNeedsRewrite ? null : this._renderedContentOffset;
  1285. };
  1286. /**
  1287. * Sets the offset from the start of the viewport to either the start or end of the rendered data
  1288. * (in pixels).
  1289. */
  1290. /**
  1291. * Sets the offset from the start of the viewport to either the start or end of the rendered data
  1292. * (in pixels).
  1293. * @param {?} offset
  1294. * @param {?=} to
  1295. * @return {?}
  1296. */
  1297. CdkVirtualScrollViewport.prototype.setRenderedContentOffset = /**
  1298. * Sets the offset from the start of the viewport to either the start or end of the rendered data
  1299. * (in pixels).
  1300. * @param {?} offset
  1301. * @param {?=} to
  1302. * @return {?}
  1303. */
  1304. function (offset, to) {
  1305. var _this = this;
  1306. if (to === void 0) { to = 'to-start'; }
  1307. // For a horizontal viewport in a right-to-left language we need to translate along the x-axis
  1308. // in the negative direction.
  1309. /** @type {?} */
  1310. var isRtl = this.dir && this.dir.value == 'rtl';
  1311. /** @type {?} */
  1312. var isHorizontal = this.orientation == 'horizontal';
  1313. /** @type {?} */
  1314. var axis = isHorizontal ? 'X' : 'Y';
  1315. /** @type {?} */
  1316. var axisDirection = isHorizontal && isRtl ? -1 : 1;
  1317. /** @type {?} */
  1318. var transform = "translate" + axis + "(" + Number(axisDirection * offset) + "px)";
  1319. this._renderedContentOffset = offset;
  1320. if (to === 'to-end') {
  1321. transform += " translate" + axis + "(-100%)";
  1322. // The viewport should rewrite this as a `to-start` offset on the next render cycle. Otherwise
  1323. // elements will appear to expand in the wrong direction (e.g. `mat-expansion-panel` would
  1324. // expand upward).
  1325. this._renderedContentOffsetNeedsRewrite = true;
  1326. }
  1327. if (this._renderedContentTransform != transform) {
  1328. // We know this value is safe because we parse `offset` with `Number()` before passing it
  1329. // into the string.
  1330. this._renderedContentTransform = transform;
  1331. this._markChangeDetectionNeeded((/**
  1332. * @return {?}
  1333. */
  1334. function () {
  1335. if (_this._renderedContentOffsetNeedsRewrite) {
  1336. _this._renderedContentOffset -= _this.measureRenderedContentSize();
  1337. _this._renderedContentOffsetNeedsRewrite = false;
  1338. _this.setRenderedContentOffset(_this._renderedContentOffset);
  1339. }
  1340. else {
  1341. _this._scrollStrategy.onRenderedOffsetChanged();
  1342. }
  1343. }));
  1344. }
  1345. };
  1346. /**
  1347. * Scrolls to the given offset from the start of the viewport. Please note that this is not always
  1348. * the same as setting `scrollTop` or `scrollLeft`. In a horizontal viewport with right-to-left
  1349. * direction, this would be the equivalent of setting a fictional `scrollRight` property.
  1350. * @param offset The offset to scroll to.
  1351. * @param behavior The ScrollBehavior to use when scrolling. Default is behavior is `auto`.
  1352. */
  1353. /**
  1354. * Scrolls to the given offset from the start of the viewport. Please note that this is not always
  1355. * the same as setting `scrollTop` or `scrollLeft`. In a horizontal viewport with right-to-left
  1356. * direction, this would be the equivalent of setting a fictional `scrollRight` property.
  1357. * @param {?} offset The offset to scroll to.
  1358. * @param {?=} behavior The ScrollBehavior to use when scrolling. Default is behavior is `auto`.
  1359. * @return {?}
  1360. */
  1361. CdkVirtualScrollViewport.prototype.scrollToOffset = /**
  1362. * Scrolls to the given offset from the start of the viewport. Please note that this is not always
  1363. * the same as setting `scrollTop` or `scrollLeft`. In a horizontal viewport with right-to-left
  1364. * direction, this would be the equivalent of setting a fictional `scrollRight` property.
  1365. * @param {?} offset The offset to scroll to.
  1366. * @param {?=} behavior The ScrollBehavior to use when scrolling. Default is behavior is `auto`.
  1367. * @return {?}
  1368. */
  1369. function (offset, behavior) {
  1370. if (behavior === void 0) { behavior = 'auto'; }
  1371. /** @type {?} */
  1372. var options = { behavior: behavior };
  1373. if (this.orientation === 'horizontal') {
  1374. options.start = offset;
  1375. }
  1376. else {
  1377. options.top = offset;
  1378. }
  1379. this.scrollTo(options);
  1380. };
  1381. /**
  1382. * Scrolls to the offset for the given index.
  1383. * @param index The index of the element to scroll to.
  1384. * @param behavior The ScrollBehavior to use when scrolling. Default is behavior is `auto`.
  1385. */
  1386. /**
  1387. * Scrolls to the offset for the given index.
  1388. * @param {?} index The index of the element to scroll to.
  1389. * @param {?=} behavior The ScrollBehavior to use when scrolling. Default is behavior is `auto`.
  1390. * @return {?}
  1391. */
  1392. CdkVirtualScrollViewport.prototype.scrollToIndex = /**
  1393. * Scrolls to the offset for the given index.
  1394. * @param {?} index The index of the element to scroll to.
  1395. * @param {?=} behavior The ScrollBehavior to use when scrolling. Default is behavior is `auto`.
  1396. * @return {?}
  1397. */
  1398. function (index, behavior) {
  1399. if (behavior === void 0) { behavior = 'auto'; }
  1400. this._scrollStrategy.scrollToIndex(index, behavior);
  1401. };
  1402. /**
  1403. * Gets the current scroll offset from the start of the viewport (in pixels).
  1404. * @param from The edge to measure the offset from. Defaults to 'top' in vertical mode and 'start'
  1405. * in horizontal mode.
  1406. */
  1407. /**
  1408. * Gets the current scroll offset from the start of the viewport (in pixels).
  1409. * @param {?=} from The edge to measure the offset from. Defaults to 'top' in vertical mode and 'start'
  1410. * in horizontal mode.
  1411. * @return {?}
  1412. */
  1413. CdkVirtualScrollViewport.prototype.measureScrollOffset = /**
  1414. * Gets the current scroll offset from the start of the viewport (in pixels).
  1415. * @param {?=} from The edge to measure the offset from. Defaults to 'top' in vertical mode and 'start'
  1416. * in horizontal mode.
  1417. * @return {?}
  1418. */
  1419. function (from) {
  1420. return _super.prototype.measureScrollOffset.call(this, from ? from : this.orientation === 'horizontal' ? 'start' : 'top');
  1421. };
  1422. /** Measure the combined size of all of the rendered items. */
  1423. /**
  1424. * Measure the combined size of all of the rendered items.
  1425. * @return {?}
  1426. */
  1427. CdkVirtualScrollViewport.prototype.measureRenderedContentSize = /**
  1428. * Measure the combined size of all of the rendered items.
  1429. * @return {?}
  1430. */
  1431. function () {
  1432. /** @type {?} */
  1433. var contentEl = this._contentWrapper.nativeElement;
  1434. return this.orientation === 'horizontal' ? contentEl.offsetWidth : contentEl.offsetHeight;
  1435. };
  1436. /**
  1437. * Measure the total combined size of the given range. Throws if the range includes items that are
  1438. * not rendered.
  1439. */
  1440. /**
  1441. * Measure the total combined size of the given range. Throws if the range includes items that are
  1442. * not rendered.
  1443. * @param {?} range
  1444. * @return {?}
  1445. */
  1446. CdkVirtualScrollViewport.prototype.measureRangeSize = /**
  1447. * Measure the total combined size of the given range. Throws if the range includes items that are
  1448. * not rendered.
  1449. * @param {?} range
  1450. * @return {?}
  1451. */
  1452. function (range) {
  1453. if (!this._forOf) {
  1454. return 0;
  1455. }
  1456. return this._forOf.measureRangeSize(range, this.orientation);
  1457. };
  1458. /** Update the viewport dimensions and re-render. */
  1459. /**
  1460. * Update the viewport dimensions and re-render.
  1461. * @return {?}
  1462. */
  1463. CdkVirtualScrollViewport.prototype.checkViewportSize = /**
  1464. * Update the viewport dimensions and re-render.
  1465. * @return {?}
  1466. */
  1467. function () {
  1468. // TODO: Cleanup later when add logic for handling content resize
  1469. this._measureViewportSize();
  1470. this._scrollStrategy.onDataLengthChanged();
  1471. };
  1472. /** Measure the viewport size. */
  1473. /**
  1474. * Measure the viewport size.
  1475. * @private
  1476. * @return {?}
  1477. */
  1478. CdkVirtualScrollViewport.prototype._measureViewportSize = /**
  1479. * Measure the viewport size.
  1480. * @private
  1481. * @return {?}
  1482. */
  1483. function () {
  1484. /** @type {?} */
  1485. var viewportEl = this.elementRef.nativeElement;
  1486. this._viewportSize = this.orientation === 'horizontal' ?
  1487. viewportEl.clientWidth : viewportEl.clientHeight;
  1488. };
  1489. /** Queue up change detection to run. */
  1490. /**
  1491. * Queue up change detection to run.
  1492. * @private
  1493. * @param {?=} runAfter
  1494. * @return {?}
  1495. */
  1496. CdkVirtualScrollViewport.prototype._markChangeDetectionNeeded = /**
  1497. * Queue up change detection to run.
  1498. * @private
  1499. * @param {?=} runAfter
  1500. * @return {?}
  1501. */
  1502. function (runAfter) {
  1503. var _this = this;
  1504. if (runAfter) {
  1505. this._runAfterChangeDetection.push(runAfter);
  1506. }
  1507. // Use a Promise to batch together calls to `_doChangeDetection`. This way if we set a bunch of
  1508. // properties sequentially we only have to run `_doChangeDetection` once at the end.
  1509. if (!this._isChangeDetectionPending) {
  1510. this._isChangeDetectionPending = true;
  1511. this.ngZone.runOutsideAngular((/**
  1512. * @return {?}
  1513. */
  1514. function () { return Promise.resolve().then((/**
  1515. * @return {?}
  1516. */
  1517. function () {
  1518. _this._doChangeDetection();
  1519. })); }));
  1520. }
  1521. };
  1522. /** Run change detection. */
  1523. /**
  1524. * Run change detection.
  1525. * @private
  1526. * @return {?}
  1527. */
  1528. CdkVirtualScrollViewport.prototype._doChangeDetection = /**
  1529. * Run change detection.
  1530. * @private
  1531. * @return {?}
  1532. */
  1533. function () {
  1534. var _this = this;
  1535. this._isChangeDetectionPending = false;
  1536. // Apply changes to Angular bindings. Note: We must call `markForCheck` to run change detection
  1537. // from the root, since the repeated items are content projected in. Calling `detectChanges`
  1538. // instead does not properly check the projected content.
  1539. this.ngZone.run((/**
  1540. * @return {?}
  1541. */
  1542. function () { return _this._changeDetectorRef.markForCheck(); }));
  1543. // Apply the content transform. The transform can't be set via an Angular binding because
  1544. // bypassSecurityTrustStyle is banned in Google. However the value is safe, it's composed of
  1545. // string literals, a variable that can only be 'X' or 'Y', and user input that is run through
  1546. // the `Number` function first to coerce it to a numeric value.
  1547. this._contentWrapper.nativeElement.style.transform = this._renderedContentTransform;
  1548. /** @type {?} */
  1549. var runAfterChangeDetection = this._runAfterChangeDetection;
  1550. this._runAfterChangeDetection = [];
  1551. for (var _i = 0, runAfterChangeDetection_1 = runAfterChangeDetection; _i < runAfterChangeDetection_1.length; _i++) {
  1552. var fn = runAfterChangeDetection_1[_i];
  1553. fn();
  1554. }
  1555. };
  1556. /** Calculates the `style.width` and `style.height` for the spacer element. */
  1557. /**
  1558. * Calculates the `style.width` and `style.height` for the spacer element.
  1559. * @private
  1560. * @return {?}
  1561. */
  1562. CdkVirtualScrollViewport.prototype._calculateSpacerSize = /**
  1563. * Calculates the `style.width` and `style.height` for the spacer element.
  1564. * @private
  1565. * @return {?}
  1566. */
  1567. function () {
  1568. this._totalContentHeight =
  1569. this.orientation === 'horizontal' ? '' : this._totalContentSize + "px";
  1570. this._totalContentWidth =
  1571. this.orientation === 'horizontal' ? this._totalContentSize + "px" : '';
  1572. };
  1573. CdkVirtualScrollViewport.decorators = [
  1574. { type: Component, args: [{selector: 'cdk-virtual-scroll-viewport',
  1575. template: "<div #contentWrapper class=\"cdk-virtual-scroll-content-wrapper\"><ng-content></ng-content></div><div class=\"cdk-virtual-scroll-spacer\" [style.width]=\"_totalContentWidth\" [style.height]=\"_totalContentHeight\"></div>",
  1576. styles: ["cdk-virtual-scroll-viewport{display:block;position:relative;overflow:auto;contain:strict;transform:translateZ(0);will-change:scroll-position;-webkit-overflow-scrolling:touch}.cdk-virtual-scroll-content-wrapper{position:absolute;top:0;left:0;contain:content}[dir=rtl] .cdk-virtual-scroll-content-wrapper{right:0;left:auto}.cdk-virtual-scroll-orientation-horizontal .cdk-virtual-scroll-content-wrapper{min-height:100%}.cdk-virtual-scroll-orientation-horizontal .cdk-virtual-scroll-content-wrapper>dl:not([cdkVirtualFor]),.cdk-virtual-scroll-orientation-horizontal .cdk-virtual-scroll-content-wrapper>ol:not([cdkVirtualFor]),.cdk-virtual-scroll-orientation-horizontal .cdk-virtual-scroll-content-wrapper>table:not([cdkVirtualFor]),.cdk-virtual-scroll-orientation-horizontal .cdk-virtual-scroll-content-wrapper>ul:not([cdkVirtualFor]){padding-left:0;padding-right:0;margin-left:0;margin-right:0;border-left-width:0;border-right-width:0;outline:0}.cdk-virtual-scroll-orientation-vertical .cdk-virtual-scroll-content-wrapper{min-width:100%}.cdk-virtual-scroll-orientation-vertical .cdk-virtual-scroll-content-wrapper>dl:not([cdkVirtualFor]),.cdk-virtual-scroll-orientation-vertical .cdk-virtual-scroll-content-wrapper>ol:not([cdkVirtualFor]),.cdk-virtual-scroll-orientation-vertical .cdk-virtual-scroll-content-wrapper>table:not([cdkVirtualFor]),.cdk-virtual-scroll-orientation-vertical .cdk-virtual-scroll-content-wrapper>ul:not([cdkVirtualFor]){padding-top:0;padding-bottom:0;margin-top:0;margin-bottom:0;border-top-width:0;border-bottom-width:0;outline:0}.cdk-virtual-scroll-spacer{position:absolute;top:0;left:0;height:1px;width:1px;transform-origin:0 0}[dir=rtl] .cdk-virtual-scroll-spacer{right:0;left:auto;transform-origin:100% 0}"],
  1577. host: {
  1578. 'class': 'cdk-virtual-scroll-viewport',
  1579. '[class.cdk-virtual-scroll-orientation-horizontal]': 'orientation === "horizontal"',
  1580. '[class.cdk-virtual-scroll-orientation-vertical]': 'orientation !== "horizontal"',
  1581. },
  1582. encapsulation: ViewEncapsulation.None,
  1583. changeDetection: ChangeDetectionStrategy.OnPush,
  1584. providers: [{
  1585. provide: CdkScrollable,
  1586. useExisting: CdkVirtualScrollViewport,
  1587. }]
  1588. },] },
  1589. ];
  1590. /** @nocollapse */
  1591. CdkVirtualScrollViewport.ctorParameters = function () { return [
  1592. { type: ElementRef },
  1593. { type: ChangeDetectorRef },
  1594. { type: NgZone },
  1595. { type: undefined, decorators: [{ type: Optional }, { type: Inject, args: [VIRTUAL_SCROLL_STRATEGY,] }] },
  1596. { type: Directionality, decorators: [{ type: Optional }] },
  1597. { type: ScrollDispatcher }
  1598. ]; };
  1599. CdkVirtualScrollViewport.propDecorators = {
  1600. orientation: [{ type: Input }],
  1601. scrolledIndexChange: [{ type: Output }],
  1602. _contentWrapper: [{ type: ViewChild, args: ['contentWrapper', { static: true },] }]
  1603. };
  1604. return CdkVirtualScrollViewport;
  1605. }(CdkScrollable));
  1606. /**
  1607. * @fileoverview added by tsickle
  1608. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  1609. */
  1610. /**
  1611. * Helper to extract size from a DOM Node.
  1612. * @param {?} orientation
  1613. * @param {?} node
  1614. * @return {?}
  1615. */
  1616. function getSize(orientation, node) {
  1617. /** @type {?} */
  1618. var el = (/** @type {?} */ (node));
  1619. if (!el.getBoundingClientRect) {
  1620. return 0;
  1621. }
  1622. /** @type {?} */
  1623. var rect = el.getBoundingClientRect();
  1624. return orientation == 'horizontal' ? rect.width : rect.height;
  1625. }
  1626. /**
  1627. * A directive similar to `ngForOf` to be used for rendering data inside a virtual scrolling
  1628. * container.
  1629. * @template T
  1630. */
  1631. var CdkVirtualForOf = /** @class */ (function () {
  1632. function CdkVirtualForOf(_viewContainerRef, _template, _differs, _viewport, ngZone) {
  1633. var _this = this;
  1634. this._viewContainerRef = _viewContainerRef;
  1635. this._template = _template;
  1636. this._differs = _differs;
  1637. this._viewport = _viewport;
  1638. /**
  1639. * Emits when the rendered view of the data changes.
  1640. */
  1641. this.viewChange = new Subject();
  1642. /**
  1643. * Subject that emits when a new DataSource instance is given.
  1644. */
  1645. this._dataSourceChanges = new Subject();
  1646. /**
  1647. * The size of the cache used to store templates that are not being used for re-use later.
  1648. * Setting the cache size to `0` will disable caching. Defaults to 20 templates.
  1649. */
  1650. this.cdkVirtualForTemplateCacheSize = 20;
  1651. /**
  1652. * Emits whenever the data in the current DataSource changes.
  1653. */
  1654. this.dataStream = this._dataSourceChanges
  1655. .pipe(
  1656. // Start off with null `DataSource`.
  1657. startWith((/** @type {?} */ (null))),
  1658. // Bundle up the previous and current data sources so we can work with both.
  1659. pairwise(),
  1660. // Use `_changeDataSource` to disconnect from the previous data source and connect to the
  1661. // new one, passing back a stream of data changes which we run through `switchMap` to give
  1662. // us a data stream that emits the latest data from whatever the current `DataSource` is.
  1663. switchMap((/**
  1664. * @param {?} __0
  1665. * @return {?}
  1666. */
  1667. function (_a) {
  1668. var prev = _a[0], cur = _a[1];
  1669. return _this._changeDataSource(prev, cur);
  1670. })),
  1671. // Replay the last emitted data when someone subscribes.
  1672. shareReplay(1));
  1673. /**
  1674. * The differ used to calculate changes to the data.
  1675. */
  1676. this._differ = null;
  1677. /**
  1678. * The template cache used to hold on ot template instancess that have been stamped out, but don't
  1679. * currently need to be rendered. These instances will be reused in the future rather than
  1680. * stamping out brand new ones.
  1681. */
  1682. this._templateCache = [];
  1683. /**
  1684. * Whether the rendered data should be updated during the next ngDoCheck cycle.
  1685. */
  1686. this._needsUpdate = false;
  1687. this._destroyed = new Subject();
  1688. this.dataStream.subscribe((/**
  1689. * @param {?} data
  1690. * @return {?}
  1691. */
  1692. function (data) {
  1693. _this._data = data;
  1694. _this._onRenderedDataChange();
  1695. }));
  1696. this._viewport.renderedRangeStream.pipe(takeUntil(this._destroyed)).subscribe((/**
  1697. * @param {?} range
  1698. * @return {?}
  1699. */
  1700. function (range) {
  1701. _this._renderedRange = range;
  1702. ngZone.run((/**
  1703. * @return {?}
  1704. */
  1705. function () { return _this.viewChange.next(_this._renderedRange); }));
  1706. _this._onRenderedDataChange();
  1707. }));
  1708. this._viewport.attach(this);
  1709. }
  1710. Object.defineProperty(CdkVirtualForOf.prototype, "cdkVirtualForOf", {
  1711. /** The DataSource to display. */
  1712. get: /**
  1713. * The DataSource to display.
  1714. * @return {?}
  1715. */
  1716. function () {
  1717. return this._cdkVirtualForOf;
  1718. },
  1719. set: /**
  1720. * @param {?} value
  1721. * @return {?}
  1722. */
  1723. function (value) {
  1724. this._cdkVirtualForOf = value;
  1725. /** @type {?} */
  1726. var ds = isDataSource(value) ? value :
  1727. // Slice the value if its an NgIterable to ensure we're working with an array.
  1728. new ArrayDataSource(value instanceof Observable ? value : Array.prototype.slice.call(value || []));
  1729. this._dataSourceChanges.next(ds);
  1730. },
  1731. enumerable: true,
  1732. configurable: true
  1733. });
  1734. Object.defineProperty(CdkVirtualForOf.prototype, "cdkVirtualForTrackBy", {
  1735. /**
  1736. * The `TrackByFunction` to use for tracking changes. The `TrackByFunction` takes the index and
  1737. * the item and produces a value to be used as the item's identity when tracking changes.
  1738. */
  1739. get: /**
  1740. * The `TrackByFunction` to use for tracking changes. The `TrackByFunction` takes the index and
  1741. * the item and produces a value to be used as the item's identity when tracking changes.
  1742. * @return {?}
  1743. */
  1744. function () {
  1745. return this._cdkVirtualForTrackBy;
  1746. },
  1747. set: /**
  1748. * @param {?} fn
  1749. * @return {?}
  1750. */
  1751. function (fn) {
  1752. var _this = this;
  1753. this._needsUpdate = true;
  1754. this._cdkVirtualForTrackBy = fn ?
  1755. (/**
  1756. * @param {?} index
  1757. * @param {?} item
  1758. * @return {?}
  1759. */
  1760. function (index, item) { return fn(index + (_this._renderedRange ? _this._renderedRange.start : 0), item); }) :
  1761. undefined;
  1762. },
  1763. enumerable: true,
  1764. configurable: true
  1765. });
  1766. Object.defineProperty(CdkVirtualForOf.prototype, "cdkVirtualForTemplate", {
  1767. /** The template used to stamp out new elements. */
  1768. set: /**
  1769. * The template used to stamp out new elements.
  1770. * @param {?} value
  1771. * @return {?}
  1772. */
  1773. function (value) {
  1774. if (value) {
  1775. this._needsUpdate = true;
  1776. this._template = value;
  1777. }
  1778. },
  1779. enumerable: true,
  1780. configurable: true
  1781. });
  1782. /**
  1783. * Measures the combined size (width for horizontal orientation, height for vertical) of all items
  1784. * in the specified range. Throws an error if the range includes items that are not currently
  1785. * rendered.
  1786. */
  1787. /**
  1788. * Measures the combined size (width for horizontal orientation, height for vertical) of all items
  1789. * in the specified range. Throws an error if the range includes items that are not currently
  1790. * rendered.
  1791. * @param {?} range
  1792. * @param {?} orientation
  1793. * @return {?}
  1794. */
  1795. CdkVirtualForOf.prototype.measureRangeSize = /**
  1796. * Measures the combined size (width for horizontal orientation, height for vertical) of all items
  1797. * in the specified range. Throws an error if the range includes items that are not currently
  1798. * rendered.
  1799. * @param {?} range
  1800. * @param {?} orientation
  1801. * @return {?}
  1802. */
  1803. function (range, orientation) {
  1804. if (range.start >= range.end) {
  1805. return 0;
  1806. }
  1807. if (range.start < this._renderedRange.start || range.end > this._renderedRange.end) {
  1808. throw Error("Error: attempted to measure an item that isn't rendered.");
  1809. }
  1810. // The index into the list of rendered views for the first item in the range.
  1811. /** @type {?} */
  1812. var renderedStartIndex = range.start - this._renderedRange.start;
  1813. // The length of the range we're measuring.
  1814. /** @type {?} */
  1815. var rangeLen = range.end - range.start;
  1816. // Loop over all root nodes for all items in the range and sum up their size.
  1817. /** @type {?} */
  1818. var totalSize = 0;
  1819. /** @type {?} */
  1820. var i = rangeLen;
  1821. while (i--) {
  1822. /** @type {?} */
  1823. var view = (/** @type {?} */ (this._viewContainerRef.get(i + renderedStartIndex)));
  1824. /** @type {?} */
  1825. var j = view ? view.rootNodes.length : 0;
  1826. while (j--) {
  1827. totalSize += getSize(orientation, (/** @type {?} */ (view)).rootNodes[j]);
  1828. }
  1829. }
  1830. return totalSize;
  1831. };
  1832. /**
  1833. * @return {?}
  1834. */
  1835. CdkVirtualForOf.prototype.ngDoCheck = /**
  1836. * @return {?}
  1837. */
  1838. function () {
  1839. if (this._differ && this._needsUpdate) {
  1840. // TODO(mmalerba): We should differentiate needs update due to scrolling and a new portion of
  1841. // this list being rendered (can use simpler algorithm) vs needs update due to data actually
  1842. // changing (need to do this diff).
  1843. /** @type {?} */
  1844. var changes = this._differ.diff(this._renderedItems);
  1845. if (!changes) {
  1846. this._updateContext();
  1847. }
  1848. else {
  1849. this._applyChanges(changes);
  1850. }
  1851. this._needsUpdate = false;
  1852. }
  1853. };
  1854. /**
  1855. * @return {?}
  1856. */
  1857. CdkVirtualForOf.prototype.ngOnDestroy = /**
  1858. * @return {?}
  1859. */
  1860. function () {
  1861. this._viewport.detach();
  1862. this._dataSourceChanges.next();
  1863. this._dataSourceChanges.complete();
  1864. this.viewChange.complete();
  1865. this._destroyed.next();
  1866. this._destroyed.complete();
  1867. for (var _i = 0, _a = this._templateCache; _i < _a.length; _i++) {
  1868. var view = _a[_i];
  1869. view.destroy();
  1870. }
  1871. };
  1872. /** React to scroll state changes in the viewport. */
  1873. /**
  1874. * React to scroll state changes in the viewport.
  1875. * @private
  1876. * @return {?}
  1877. */
  1878. CdkVirtualForOf.prototype._onRenderedDataChange = /**
  1879. * React to scroll state changes in the viewport.
  1880. * @private
  1881. * @return {?}
  1882. */
  1883. function () {
  1884. if (!this._renderedRange) {
  1885. return;
  1886. }
  1887. this._renderedItems = this._data.slice(this._renderedRange.start, this._renderedRange.end);
  1888. if (!this._differ) {
  1889. this._differ = this._differs.find(this._renderedItems).create(this.cdkVirtualForTrackBy);
  1890. }
  1891. this._needsUpdate = true;
  1892. };
  1893. /** Swap out one `DataSource` for another. */
  1894. /**
  1895. * Swap out one `DataSource` for another.
  1896. * @private
  1897. * @param {?} oldDs
  1898. * @param {?} newDs
  1899. * @return {?}
  1900. */
  1901. CdkVirtualForOf.prototype._changeDataSource = /**
  1902. * Swap out one `DataSource` for another.
  1903. * @private
  1904. * @param {?} oldDs
  1905. * @param {?} newDs
  1906. * @return {?}
  1907. */
  1908. function (oldDs, newDs) {
  1909. if (oldDs) {
  1910. oldDs.disconnect(this);
  1911. }
  1912. this._needsUpdate = true;
  1913. return newDs ? newDs.connect(this) : of();
  1914. };
  1915. /** Update the `CdkVirtualForOfContext` for all views. */
  1916. /**
  1917. * Update the `CdkVirtualForOfContext` for all views.
  1918. * @private
  1919. * @return {?}
  1920. */
  1921. CdkVirtualForOf.prototype._updateContext = /**
  1922. * Update the `CdkVirtualForOfContext` for all views.
  1923. * @private
  1924. * @return {?}
  1925. */
  1926. function () {
  1927. /** @type {?} */
  1928. var count = this._data.length;
  1929. /** @type {?} */
  1930. var i = this._viewContainerRef.length;
  1931. while (i--) {
  1932. /** @type {?} */
  1933. var view = (/** @type {?} */ (this._viewContainerRef.get(i)));
  1934. view.context.index = this._renderedRange.start + i;
  1935. view.context.count = count;
  1936. this._updateComputedContextProperties(view.context);
  1937. view.detectChanges();
  1938. }
  1939. };
  1940. /** Apply changes to the DOM. */
  1941. /**
  1942. * Apply changes to the DOM.
  1943. * @private
  1944. * @param {?} changes
  1945. * @return {?}
  1946. */
  1947. CdkVirtualForOf.prototype._applyChanges = /**
  1948. * Apply changes to the DOM.
  1949. * @private
  1950. * @param {?} changes
  1951. * @return {?}
  1952. */
  1953. function (changes) {
  1954. var _this = this;
  1955. // Rearrange the views to put them in the right location.
  1956. changes.forEachOperation((/**
  1957. * @param {?} record
  1958. * @param {?} adjustedPreviousIndex
  1959. * @param {?} currentIndex
  1960. * @return {?}
  1961. */
  1962. function (record, adjustedPreviousIndex, currentIndex) {
  1963. if (record.previousIndex == null) { // Item added.
  1964. // Item added.
  1965. /** @type {?} */
  1966. var view = _this._insertViewForNewItem((/** @type {?} */ (currentIndex)));
  1967. view.context.$implicit = record.item;
  1968. }
  1969. else if (currentIndex == null) { // Item removed.
  1970. _this._cacheView(_this._detachView((/** @type {?} */ (adjustedPreviousIndex))));
  1971. }
  1972. else { // Item moved.
  1973. // Item moved.
  1974. /** @type {?} */
  1975. var view = (/** @type {?} */ (_this._viewContainerRef.get((/** @type {?} */ (adjustedPreviousIndex)))));
  1976. _this._viewContainerRef.move(view, currentIndex);
  1977. view.context.$implicit = record.item;
  1978. }
  1979. }));
  1980. // Update $implicit for any items that had an identity change.
  1981. changes.forEachIdentityChange((/**
  1982. * @param {?} record
  1983. * @return {?}
  1984. */
  1985. function (record) {
  1986. /** @type {?} */
  1987. var view = (/** @type {?} */ (_this._viewContainerRef.get((/** @type {?} */ (record.currentIndex)))));
  1988. view.context.$implicit = record.item;
  1989. }));
  1990. // Update the context variables on all items.
  1991. /** @type {?} */
  1992. var count = this._data.length;
  1993. /** @type {?} */
  1994. var i = this._viewContainerRef.length;
  1995. while (i--) {
  1996. /** @type {?} */
  1997. var view = (/** @type {?} */ (this._viewContainerRef.get(i)));
  1998. view.context.index = this._renderedRange.start + i;
  1999. view.context.count = count;
  2000. this._updateComputedContextProperties(view.context);
  2001. }
  2002. };
  2003. /** Cache the given detached view. */
  2004. /**
  2005. * Cache the given detached view.
  2006. * @private
  2007. * @param {?} view
  2008. * @return {?}
  2009. */
  2010. CdkVirtualForOf.prototype._cacheView = /**
  2011. * Cache the given detached view.
  2012. * @private
  2013. * @param {?} view
  2014. * @return {?}
  2015. */
  2016. function (view) {
  2017. if (this._templateCache.length < this.cdkVirtualForTemplateCacheSize) {
  2018. this._templateCache.push(view);
  2019. }
  2020. else {
  2021. /** @type {?} */
  2022. var index = this._viewContainerRef.indexOf(view);
  2023. // It's very unlikely that the index will ever be -1, but just in case,
  2024. // destroy the view on its own, otherwise destroy it through the
  2025. // container to ensure that all the references are removed.
  2026. if (index === -1) {
  2027. view.destroy();
  2028. }
  2029. else {
  2030. this._viewContainerRef.remove(index);
  2031. }
  2032. }
  2033. };
  2034. /** Inserts a view for a new item, either from the cache or by creating a new one. */
  2035. /**
  2036. * Inserts a view for a new item, either from the cache or by creating a new one.
  2037. * @private
  2038. * @param {?} index
  2039. * @return {?}
  2040. */
  2041. CdkVirtualForOf.prototype._insertViewForNewItem = /**
  2042. * Inserts a view for a new item, either from the cache or by creating a new one.
  2043. * @private
  2044. * @param {?} index
  2045. * @return {?}
  2046. */
  2047. function (index) {
  2048. return this._insertViewFromCache(index) || this._createEmbeddedViewAt(index);
  2049. };
  2050. /** Update the computed properties on the `CdkVirtualForOfContext`. */
  2051. /**
  2052. * Update the computed properties on the `CdkVirtualForOfContext`.
  2053. * @private
  2054. * @param {?} context
  2055. * @return {?}
  2056. */
  2057. CdkVirtualForOf.prototype._updateComputedContextProperties = /**
  2058. * Update the computed properties on the `CdkVirtualForOfContext`.
  2059. * @private
  2060. * @param {?} context
  2061. * @return {?}
  2062. */
  2063. function (context) {
  2064. context.first = context.index === 0;
  2065. context.last = context.index === context.count - 1;
  2066. context.even = context.index % 2 === 0;
  2067. context.odd = !context.even;
  2068. };
  2069. /** Creates a new embedded view and moves it to the given index */
  2070. /**
  2071. * Creates a new embedded view and moves it to the given index
  2072. * @private
  2073. * @param {?} index
  2074. * @return {?}
  2075. */
  2076. CdkVirtualForOf.prototype._createEmbeddedViewAt = /**
  2077. * Creates a new embedded view and moves it to the given index
  2078. * @private
  2079. * @param {?} index
  2080. * @return {?}
  2081. */
  2082. function (index) {
  2083. // Note that it's important that we insert the item directly at the proper index,
  2084. // rather than inserting it and the moving it in place, because if there's a directive
  2085. // on the same node that injects the `ViewContainerRef`, Angular will insert another
  2086. // comment node which can throw off the move when it's being repeated for all items.
  2087. return this._viewContainerRef.createEmbeddedView(this._template, {
  2088. $implicit: (/** @type {?} */ (null)),
  2089. cdkVirtualForOf: this._cdkVirtualForOf,
  2090. index: -1,
  2091. count: -1,
  2092. first: false,
  2093. last: false,
  2094. odd: false,
  2095. even: false
  2096. }, index);
  2097. };
  2098. /** Inserts a recycled view from the cache at the given index. */
  2099. /**
  2100. * Inserts a recycled view from the cache at the given index.
  2101. * @private
  2102. * @param {?} index
  2103. * @return {?}
  2104. */
  2105. CdkVirtualForOf.prototype._insertViewFromCache = /**
  2106. * Inserts a recycled view from the cache at the given index.
  2107. * @private
  2108. * @param {?} index
  2109. * @return {?}
  2110. */
  2111. function (index) {
  2112. /** @type {?} */
  2113. var cachedView = this._templateCache.pop();
  2114. if (cachedView) {
  2115. this._viewContainerRef.insert(cachedView, index);
  2116. }
  2117. return cachedView || null;
  2118. };
  2119. /** Detaches the embedded view at the given index. */
  2120. /**
  2121. * Detaches the embedded view at the given index.
  2122. * @private
  2123. * @param {?} index
  2124. * @return {?}
  2125. */
  2126. CdkVirtualForOf.prototype._detachView = /**
  2127. * Detaches the embedded view at the given index.
  2128. * @private
  2129. * @param {?} index
  2130. * @return {?}
  2131. */
  2132. function (index) {
  2133. return (/** @type {?} */ (this._viewContainerRef.detach(index)));
  2134. };
  2135. CdkVirtualForOf.decorators = [
  2136. { type: Directive, args: [{
  2137. selector: '[cdkVirtualFor][cdkVirtualForOf]',
  2138. },] },
  2139. ];
  2140. /** @nocollapse */
  2141. CdkVirtualForOf.ctorParameters = function () { return [
  2142. { type: ViewContainerRef },
  2143. { type: TemplateRef },
  2144. { type: IterableDiffers },
  2145. { type: CdkVirtualScrollViewport, decorators: [{ type: SkipSelf }] },
  2146. { type: NgZone }
  2147. ]; };
  2148. CdkVirtualForOf.propDecorators = {
  2149. cdkVirtualForOf: [{ type: Input }],
  2150. cdkVirtualForTrackBy: [{ type: Input }],
  2151. cdkVirtualForTemplate: [{ type: Input }],
  2152. cdkVirtualForTemplateCacheSize: [{ type: Input }]
  2153. };
  2154. return CdkVirtualForOf;
  2155. }());
  2156. /**
  2157. * @fileoverview added by tsickle
  2158. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  2159. */
  2160. var ScrollingModule = /** @class */ (function () {
  2161. function ScrollingModule() {
  2162. }
  2163. ScrollingModule.decorators = [
  2164. { type: NgModule, args: [{
  2165. imports: [BidiModule, PlatformModule],
  2166. exports: [
  2167. BidiModule,
  2168. CdkFixedSizeVirtualScroll,
  2169. CdkScrollable,
  2170. CdkVirtualForOf,
  2171. CdkVirtualScrollViewport,
  2172. ],
  2173. declarations: [
  2174. CdkFixedSizeVirtualScroll,
  2175. CdkScrollable,
  2176. CdkVirtualForOf,
  2177. CdkVirtualScrollViewport,
  2178. ],
  2179. },] },
  2180. ];
  2181. return ScrollingModule;
  2182. }());
  2183. /**
  2184. * @deprecated ScrollDispatchModule has been renamed to ScrollingModule.
  2185. * \@breaking-change 8.0.0 delete this alias
  2186. */
  2187. var ScrollDispatchModule = /** @class */ (function () {
  2188. function ScrollDispatchModule() {
  2189. }
  2190. ScrollDispatchModule.decorators = [
  2191. { type: NgModule, args: [{
  2192. imports: [ScrollingModule],
  2193. exports: [ScrollingModule],
  2194. },] },
  2195. ];
  2196. return ScrollDispatchModule;
  2197. }());
  2198. /**
  2199. * @fileoverview added by tsickle
  2200. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  2201. */
  2202. /**
  2203. * Time in ms to throttle the resize events by default.
  2204. * @type {?}
  2205. */
  2206. var DEFAULT_RESIZE_TIME = 20;
  2207. /**
  2208. * Simple utility for getting the bounds of the browser viewport.
  2209. * \@docs-private
  2210. */
  2211. var ViewportRuler = /** @class */ (function () {
  2212. function ViewportRuler(_platform, ngZone) {
  2213. var _this = this;
  2214. this._platform = _platform;
  2215. ngZone.runOutsideAngular((/**
  2216. * @return {?}
  2217. */
  2218. function () {
  2219. _this._change = _platform.isBrowser ?
  2220. merge(fromEvent(window, 'resize'), fromEvent(window, 'orientationchange')) :
  2221. of();
  2222. // Note that we need to do the subscription inside `runOutsideAngular`
  2223. // since subscribing is what causes the event listener to be added.
  2224. _this._invalidateCache = _this.change().subscribe((/**
  2225. * @return {?}
  2226. */
  2227. function () { return _this._updateViewportSize(); }));
  2228. }));
  2229. }
  2230. /**
  2231. * @return {?}
  2232. */
  2233. ViewportRuler.prototype.ngOnDestroy = /**
  2234. * @return {?}
  2235. */
  2236. function () {
  2237. this._invalidateCache.unsubscribe();
  2238. };
  2239. /** Returns the viewport's width and height. */
  2240. /**
  2241. * Returns the viewport's width and height.
  2242. * @return {?}
  2243. */
  2244. ViewportRuler.prototype.getViewportSize = /**
  2245. * Returns the viewport's width and height.
  2246. * @return {?}
  2247. */
  2248. function () {
  2249. if (!this._viewportSize) {
  2250. this._updateViewportSize();
  2251. }
  2252. /** @type {?} */
  2253. var output = { width: this._viewportSize.width, height: this._viewportSize.height };
  2254. // If we're not on a browser, don't cache the size since it'll be mocked out anyway.
  2255. if (!this._platform.isBrowser) {
  2256. this._viewportSize = (/** @type {?} */ (null));
  2257. }
  2258. return output;
  2259. };
  2260. /** Gets a ClientRect for the viewport's bounds. */
  2261. /**
  2262. * Gets a ClientRect for the viewport's bounds.
  2263. * @return {?}
  2264. */
  2265. ViewportRuler.prototype.getViewportRect = /**
  2266. * Gets a ClientRect for the viewport's bounds.
  2267. * @return {?}
  2268. */
  2269. function () {
  2270. // Use the document element's bounding rect rather than the window scroll properties
  2271. // (e.g. pageYOffset, scrollY) due to in issue in Chrome and IE where window scroll
  2272. // properties and client coordinates (boundingClientRect, clientX/Y, etc.) are in different
  2273. // conceptual viewports. Under most circumstances these viewports are equivalent, but they
  2274. // can disagree when the page is pinch-zoomed (on devices that support touch).
  2275. // See https://bugs.chromium.org/p/chromium/issues/detail?id=489206#c4
  2276. // We use the documentElement instead of the body because, by default (without a css reset)
  2277. // browsers typically give the document body an 8px margin, which is not included in
  2278. // getBoundingClientRect().
  2279. /** @type {?} */
  2280. var scrollPosition = this.getViewportScrollPosition();
  2281. var _a = this.getViewportSize(), width = _a.width, height = _a.height;
  2282. return {
  2283. top: scrollPosition.top,
  2284. left: scrollPosition.left,
  2285. bottom: scrollPosition.top + height,
  2286. right: scrollPosition.left + width,
  2287. height: height,
  2288. width: width,
  2289. };
  2290. };
  2291. /** Gets the (top, left) scroll position of the viewport. */
  2292. /**
  2293. * Gets the (top, left) scroll position of the viewport.
  2294. * @return {?}
  2295. */
  2296. ViewportRuler.prototype.getViewportScrollPosition = /**
  2297. * Gets the (top, left) scroll position of the viewport.
  2298. * @return {?}
  2299. */
  2300. function () {
  2301. // While we can get a reference to the fake document
  2302. // during SSR, it doesn't have getBoundingClientRect.
  2303. if (!this._platform.isBrowser) {
  2304. return { top: 0, left: 0 };
  2305. }
  2306. // The top-left-corner of the viewport is determined by the scroll position of the document
  2307. // body, normally just (scrollLeft, scrollTop). However, Chrome and Firefox disagree about
  2308. // whether `document.body` or `document.documentElement` is the scrolled element, so reading
  2309. // `scrollTop` and `scrollLeft` is inconsistent. However, using the bounding rect of
  2310. // `document.documentElement` works consistently, where the `top` and `left` values will
  2311. // equal negative the scroll position.
  2312. /** @type {?} */
  2313. var documentElement = (/** @type {?} */ (document.documentElement));
  2314. /** @type {?} */
  2315. var documentRect = documentElement.getBoundingClientRect();
  2316. /** @type {?} */
  2317. var top = -documentRect.top || document.body.scrollTop || window.scrollY ||
  2318. documentElement.scrollTop || 0;
  2319. /** @type {?} */
  2320. var left = -documentRect.left || document.body.scrollLeft || window.scrollX ||
  2321. documentElement.scrollLeft || 0;
  2322. return { top: top, left: left };
  2323. };
  2324. /**
  2325. * Returns a stream that emits whenever the size of the viewport changes.
  2326. * @param throttleTime Time in milliseconds to throttle the stream.
  2327. */
  2328. /**
  2329. * Returns a stream that emits whenever the size of the viewport changes.
  2330. * @param {?=} throttleTime Time in milliseconds to throttle the stream.
  2331. * @return {?}
  2332. */
  2333. ViewportRuler.prototype.change = /**
  2334. * Returns a stream that emits whenever the size of the viewport changes.
  2335. * @param {?=} throttleTime Time in milliseconds to throttle the stream.
  2336. * @return {?}
  2337. */
  2338. function (throttleTime) {
  2339. if (throttleTime === void 0) { throttleTime = DEFAULT_RESIZE_TIME; }
  2340. return throttleTime > 0 ? this._change.pipe(auditTime(throttleTime)) : this._change;
  2341. };
  2342. /** Updates the cached viewport size. */
  2343. /**
  2344. * Updates the cached viewport size.
  2345. * @private
  2346. * @return {?}
  2347. */
  2348. ViewportRuler.prototype._updateViewportSize = /**
  2349. * Updates the cached viewport size.
  2350. * @private
  2351. * @return {?}
  2352. */
  2353. function () {
  2354. this._viewportSize = this._platform.isBrowser ?
  2355. { width: window.innerWidth, height: window.innerHeight } :
  2356. { width: 0, height: 0 };
  2357. };
  2358. ViewportRuler.decorators = [
  2359. { type: Injectable, args: [{ providedIn: 'root' },] },
  2360. ];
  2361. /** @nocollapse */
  2362. ViewportRuler.ctorParameters = function () { return [
  2363. { type: Platform },
  2364. { type: NgZone }
  2365. ]; };
  2366. /** @nocollapse */ ViewportRuler.ngInjectableDef = ɵɵdefineInjectable({ factory: function ViewportRuler_Factory() { return new ViewportRuler(ɵɵinject(Platform), ɵɵinject(NgZone)); }, token: ViewportRuler, providedIn: "root" });
  2367. return ViewportRuler;
  2368. }());
  2369. /**
  2370. * \@docs-private \@deprecated \@breaking-change 8.0.0
  2371. * @param {?} parentRuler
  2372. * @param {?} platform
  2373. * @param {?} ngZone
  2374. * @return {?}
  2375. */
  2376. function VIEWPORT_RULER_PROVIDER_FACTORY(parentRuler, platform, ngZone) {
  2377. return parentRuler || new ViewportRuler(platform, ngZone);
  2378. }
  2379. /**
  2380. * \@docs-private \@deprecated \@breaking-change 8.0.0
  2381. * @type {?}
  2382. */
  2383. var VIEWPORT_RULER_PROVIDER = {
  2384. // If there is already a ViewportRuler available, use that. Otherwise, provide a new one.
  2385. provide: ViewportRuler,
  2386. deps: [[new Optional(), new SkipSelf(), ViewportRuler], Platform, NgZone],
  2387. useFactory: VIEWPORT_RULER_PROVIDER_FACTORY
  2388. };
  2389. /**
  2390. * @fileoverview added by tsickle
  2391. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  2392. */
  2393. /**
  2394. * @fileoverview added by tsickle
  2395. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  2396. */
  2397. export { _fixedSizeVirtualScrollStrategyFactory, FixedSizeVirtualScrollStrategy, CdkFixedSizeVirtualScroll, SCROLL_DISPATCHER_PROVIDER_FACTORY, DEFAULT_SCROLL_TIME, ScrollDispatcher, SCROLL_DISPATCHER_PROVIDER, CdkScrollable, ScrollingModule, ScrollDispatchModule, VIEWPORT_RULER_PROVIDER_FACTORY, DEFAULT_RESIZE_TIME, ViewportRuler, VIEWPORT_RULER_PROVIDER, CdkVirtualForOf, VIRTUAL_SCROLL_STRATEGY, CdkVirtualScrollViewport };
  2398. //# sourceMappingURL=scrolling.es5.js.map