cdk-scrolling.umd.js 95 KB

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