ng-virtual-list 16.4.2 → 16.4.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/README.md +35 -2
  2. package/esm2020/lib/components/ng-virtual-list-item.component.mjs +131 -0
  3. package/esm2020/lib/const/index.mjs +44 -0
  4. package/esm2020/lib/enums/direction.mjs +2 -0
  5. package/esm2020/lib/enums/directions.mjs +18 -0
  6. package/esm2020/lib/enums/index.mjs +4 -0
  7. package/esm2020/lib/enums/snapping-method.mjs +2 -0
  8. package/esm2020/lib/enums/snapping-methods.mjs +18 -0
  9. package/esm2020/lib/models/base-virtual-list-item-component.mjs +9 -0
  10. package/esm2020/lib/models/collection.model.mjs +3 -0
  11. package/esm2020/lib/models/component.model.mjs +2 -0
  12. package/esm2020/lib/models/index.mjs +2 -0
  13. package/esm2020/lib/models/item.model.mjs +2 -0
  14. package/esm2020/lib/models/render-collection.model.mjs +3 -0
  15. package/esm2020/lib/models/render-item-config.model.mjs +2 -0
  16. package/esm2020/lib/models/render-item.model.mjs +3 -0
  17. package/esm2020/lib/models/scroll-direction.model.mjs +2 -0
  18. package/esm2020/lib/models/scroll-event.model.mjs +2 -0
  19. package/esm2020/lib/models/sticky-map.model.mjs +2 -0
  20. package/esm2020/lib/ng-virtual-list.component.mjs +675 -0
  21. package/esm2020/lib/ng-virtual-list.module.mjs +20 -0
  22. package/esm2020/lib/types/id.mjs +2 -0
  23. package/esm2020/lib/types/index.mjs +2 -0
  24. package/esm2020/lib/types/rect.mjs +2 -0
  25. package/esm2020/lib/types/size.mjs +2 -0
  26. package/esm2020/lib/utils/browser.mjs +3 -0
  27. package/esm2020/lib/utils/buffer-interpolation.mjs +27 -0
  28. package/esm2020/lib/utils/cacheMap.mjs +167 -0
  29. package/esm2020/lib/utils/debounce.mjs +31 -0
  30. package/esm2020/lib/utils/disposableComponent.mjs +29 -0
  31. package/esm2020/lib/utils/eventEmitter.mjs +106 -0
  32. package/esm2020/lib/utils/index.mjs +5 -0
  33. package/esm2020/lib/utils/isDirection.mjs +15 -0
  34. package/esm2020/lib/utils/scrollEvent.mjs +42 -0
  35. package/esm2020/lib/utils/snapping-method.mjs +9 -0
  36. package/esm2020/lib/utils/toggleClassName.mjs +15 -0
  37. package/esm2020/lib/utils/trackBox.mjs +756 -0
  38. package/esm2020/lib/utils/tracker.mjs +134 -0
  39. package/esm2020/ng-virtual-list.mjs +5 -0
  40. package/esm2020/public-api.mjs +10 -0
  41. package/fesm2015/ng-virtual-list.mjs +2224 -0
  42. package/fesm2015/ng-virtual-list.mjs.map +1 -0
  43. package/fesm2020/ng-virtual-list.mjs +2229 -0
  44. package/fesm2020/ng-virtual-list.mjs.map +1 -0
  45. package/lib/utils/disposableComponent.d.ts +15 -0
  46. package/package.json +1 -1
@@ -0,0 +1,2229 @@
1
+ import * as i0 from '@angular/core';
2
+ import { Component, ChangeDetectionStrategy, EventEmitter as EventEmitter$1, ViewContainerRef, ElementRef, ViewEncapsulation, ViewChild, Output, Input, NgModule, NO_ERRORS_SCHEMA } from '@angular/core';
3
+ import * as i1 from '@angular/common';
4
+ import { CommonModule } from '@angular/common';
5
+ import { Subject, BehaviorSubject, takeUntil, tap, filter, map, combineLatest, distinctUntilChanged, switchMap, of } from 'rxjs';
6
+
7
+ /**
8
+ * Axis of the arrangement of virtual list elements.
9
+ * @link https://github.com/DjonnyX/ng-virtual-list/blob/15.x/projects/ng-virtual-list/src/lib/enums/directions.ts
10
+ * @author Evgenii Grebennikov
11
+ * @email djonnyx@gmail.com
12
+ */
13
+ var Directions;
14
+ (function (Directions) {
15
+ /**
16
+ * Horizontal axis.
17
+ */
18
+ Directions["HORIZONTAL"] = "horizontal";
19
+ /**
20
+ * Vertical axis.
21
+ */
22
+ Directions["VERTICAL"] = "vertical";
23
+ })(Directions || (Directions = {}));
24
+
25
+ /**
26
+ * Snapping method.
27
+ * @link https://github.com/DjonnyX/ng-virtual-list/blob/15.x/projects/ng-virtual-list/src/lib/enums/snapping-method.ts
28
+ * @author Evgenii Grebennikov
29
+ * @email djonnyx@gmail.com
30
+ */
31
+ var SnappingMethods;
32
+ (function (SnappingMethods) {
33
+ /**
34
+ * Normal group rendering.
35
+ */
36
+ SnappingMethods["NORMAL"] = "normal";
37
+ /**
38
+ * The group is rendered on a transparent background. List items below the group are not rendered.
39
+ */
40
+ SnappingMethods["ADVANCED"] = "advanced";
41
+ })(SnappingMethods || (SnappingMethods = {}));
42
+
43
+ const DEFAULT_ITEM_SIZE = 24;
44
+ const DEFAULT_BUFFER_SIZE = 2;
45
+ const DEFAULT_MAX_BUFFER_SIZE = 100;
46
+ const DEFAULT_LIST_SIZE = 400;
47
+ const DEFAULT_SNAP = false;
48
+ const DEFAULT_ENABLED_BUFFER_OPTIMIZATION = false;
49
+ const DEFAULT_DYNAMIC_SIZE = false;
50
+ const TRACK_BY_PROPERTY_NAME = 'id';
51
+ const DEFAULT_DIRECTION = Directions.VERTICAL;
52
+ const DISPLAY_OBJECTS_LENGTH_MESUREMENT_ERROR = 1;
53
+ const MAX_SCROLL_TO_ITERATIONS = 5;
54
+ const DEFAULT_SNAPPING_METHOD = SnappingMethods.NORMAL;
55
+ // presets
56
+ const BEHAVIOR_AUTO = 'auto';
57
+ const BEHAVIOR_INSTANT = 'instant';
58
+ const BEHAVIOR_SMOOTH = 'smooth';
59
+ const DISPLAY_BLOCK = 'block';
60
+ const DISPLAY_NONE = 'none';
61
+ const OPACITY_0 = '0';
62
+ const OPACITY_100 = '100';
63
+ const VISIBILITY_VISIBLE = 'visible';
64
+ const VISIBILITY_HIDDEN = 'hidden';
65
+ const SIZE_100_PERSENT = '100%';
66
+ const SIZE_AUTO = 'auto';
67
+ const POSITION_ABSOLUTE = 'absolute';
68
+ const POSITION_STICKY = 'sticky';
69
+ const TRANSLATE_3D = 'translate3d';
70
+ const ZEROS_TRANSLATE_3D = `${TRANSLATE_3D}(0,0,0)`;
71
+ const HIDDEN_ZINDEX = '-1';
72
+ const DEFAULT_ZINDEX = '0';
73
+ const TOP_PROP_NAME = 'top';
74
+ const LEFT_PROP_NAME = 'left';
75
+ const X_PROP_NAME = 'x';
76
+ const Y_PROP_NAME = 'y';
77
+ const WIDTH_PROP_NAME = 'width';
78
+ const HEIGHT_PROP_NAME = 'height';
79
+ const PX = 'px';
80
+ const SCROLL = 'scroll';
81
+ const SCROLL_END = 'scrollend';
82
+ const CLASS_LIST_VERTICAL = 'vertical';
83
+ const CLASS_LIST_HORIZONTAL = 'horizontal';
84
+
85
+ /**
86
+ * Virtual List Item Interface
87
+ * @link https://github.com/DjonnyX/ng-virtual-list/blob/15.x/projects/ng-virtual-list/src/lib/models/base-virtual-list-item-component.ts
88
+ * @author Evgenii Grebennikov
89
+ * @email djonnyx@gmail.com
90
+ */
91
+ class BaseVirtualListItemComponent {
92
+ }
93
+
94
+ /**
95
+ * Virtual list item component
96
+ * @link https://github.com/DjonnyX/ng-virtual-list/blob/15.x/projects/ng-virtual-list/src/lib/components/ng-virtual-list-item.component.ts
97
+ * @author Evgenii Grebennikov
98
+ * @email djonnyx@gmail.com
99
+ */
100
+ class NgVirtualListItemComponent extends BaseVirtualListItemComponent {
101
+ get id() {
102
+ return this._id;
103
+ }
104
+ set item(v) {
105
+ if (this.data === v) {
106
+ return;
107
+ }
108
+ this.data = v;
109
+ this.update();
110
+ this._cdr.detectChanges();
111
+ }
112
+ set regularLength(v) {
113
+ if (this._regularLength === v) {
114
+ return;
115
+ }
116
+ this._regularLength = v;
117
+ this.update();
118
+ this._cdr.detectChanges();
119
+ }
120
+ get item() {
121
+ return this.data;
122
+ }
123
+ get itemId() {
124
+ return this.data?.id;
125
+ }
126
+ set renderer(v) {
127
+ if (this.itemRenderer === v) {
128
+ return;
129
+ }
130
+ this.itemRenderer = v;
131
+ this._cdr.markForCheck();
132
+ }
133
+ get element() {
134
+ return this._elementRef.nativeElement;
135
+ }
136
+ constructor(_cdr, _elementRef) {
137
+ super();
138
+ this._cdr = _cdr;
139
+ this._elementRef = _elementRef;
140
+ this.regular = false;
141
+ this._regularLength = SIZE_100_PERSENT;
142
+ this._id = NgVirtualListItemComponent.__nextId = NgVirtualListItemComponent.__nextId === Number.MAX_SAFE_INTEGER
143
+ ? 0 : NgVirtualListItemComponent.__nextId + 1;
144
+ }
145
+ update() {
146
+ const data = this.data, regular = this.regular, length = this._regularLength;
147
+ if (data) {
148
+ const styles = this._elementRef.nativeElement.style;
149
+ styles.zIndex = data.config.zIndex;
150
+ if (data.config.snapped) {
151
+ styles.transform = data.config.sticky === 1 ? ZEROS_TRANSLATE_3D : `${TRANSLATE_3D}(${data.config.isVertical ? 0 : data.measures.x}${PX}, ${data.config.isVertical ? data.measures.y : 0}${PX} , 0)`;
152
+ ;
153
+ if (!data.config.isSnappingMethodAdvanced) {
154
+ styles.position = POSITION_STICKY;
155
+ }
156
+ }
157
+ else {
158
+ styles.position = POSITION_ABSOLUTE;
159
+ if (regular) {
160
+ styles.transform = `${TRANSLATE_3D}(${data.config.isVertical ? 0 : data.measures.delta}${PX}, ${data.config.isVertical ? data.measures.delta : 0}${PX} , 0)`;
161
+ }
162
+ else {
163
+ styles.transform = `${TRANSLATE_3D}(${data.config.isVertical ? 0 : data.measures.x}${PX}, ${data.config.isVertical ? data.measures.y : 0}${PX} , 0)`;
164
+ }
165
+ }
166
+ styles.height = data.config.isVertical ? data.config.dynamic ? SIZE_AUTO : `${data.measures.height}${PX}` : regular ? length : SIZE_100_PERSENT;
167
+ styles.width = data.config.isVertical ? regular ? length : SIZE_100_PERSENT : data.config.dynamic ? SIZE_AUTO : `${data.measures.width}${PX}`;
168
+ }
169
+ this._cdr.markForCheck();
170
+ }
171
+ getBounds() {
172
+ const el = this._elementRef.nativeElement, { width, height } = el.getBoundingClientRect();
173
+ return { width, height };
174
+ }
175
+ show() {
176
+ const styles = this._elementRef.nativeElement.style;
177
+ if (this.regular) {
178
+ if (styles.display === DISPLAY_BLOCK) {
179
+ return;
180
+ }
181
+ styles.display = DISPLAY_BLOCK;
182
+ }
183
+ else {
184
+ if (styles.visibility === VISIBILITY_VISIBLE) {
185
+ return;
186
+ }
187
+ styles.visibility = VISIBILITY_VISIBLE;
188
+ }
189
+ styles.zIndex = this.data?.config?.zIndex ?? DEFAULT_ZINDEX;
190
+ }
191
+ hide() {
192
+ const styles = this._elementRef.nativeElement.style;
193
+ if (this.regular) {
194
+ if (styles.display === DISPLAY_NONE) {
195
+ return;
196
+ }
197
+ styles.display = DISPLAY_NONE;
198
+ }
199
+ else {
200
+ if (styles.visibility === VISIBILITY_HIDDEN) {
201
+ return;
202
+ }
203
+ styles.visibility = VISIBILITY_HIDDEN;
204
+ }
205
+ styles.position = POSITION_ABSOLUTE;
206
+ styles.transform = ZEROS_TRANSLATE_3D;
207
+ styles.zIndex = HIDDEN_ZINDEX;
208
+ }
209
+ }
210
+ NgVirtualListItemComponent.__nextId = 0;
211
+ NgVirtualListItemComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: NgVirtualListItemComponent, deps: [{ token: i0.ChangeDetectorRef }, { token: i0.ElementRef }], target: i0.ɵɵFactoryTarget.Component });
212
+ NgVirtualListItemComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "15.2.10", type: NgVirtualListItemComponent, selector: "ng-virtual-list-item", host: { classAttribute: "ngvl__item" }, usesInheritance: true, ngImport: i0, template: "<ng-container *ngIf=\"data\">\r\n <li #listItem part=\"item\" class=\"ngvl-item__container\" [ngClass]=\"{'snapped': data.config.snapped,\r\n 'snapped-out': data.config.snappedOut}\">\r\n <ng-container *ngIf=\"itemRenderer\">\r\n <ng-container [ngTemplateOutlet]=\"itemRenderer\"\r\n [ngTemplateOutletContext]=\"{data: data.data || {}, config: data.config}\" />\r\n </ng-container>\r\n </li>\r\n</ng-container>", styles: [":host{display:block;position:absolute;left:0;top:0;box-sizing:border-box;overflow:hidden}.ngvl-item__container{margin:0;padding:0;overflow:hidden;background-color:#fff;width:inherit;height:inherit}\n"], dependencies: [{ kind: "directive", type: i1.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { kind: "directive", type: i1.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "directive", type: i1.NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet", "ngTemplateOutletInjector"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
213
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: NgVirtualListItemComponent, decorators: [{
214
+ type: Component,
215
+ args: [{ selector: 'ng-virtual-list-item', host: {
216
+ 'class': 'ngvl__item',
217
+ }, changeDetection: ChangeDetectionStrategy.OnPush, template: "<ng-container *ngIf=\"data\">\r\n <li #listItem part=\"item\" class=\"ngvl-item__container\" [ngClass]=\"{'snapped': data.config.snapped,\r\n 'snapped-out': data.config.snappedOut}\">\r\n <ng-container *ngIf=\"itemRenderer\">\r\n <ng-container [ngTemplateOutlet]=\"itemRenderer\"\r\n [ngTemplateOutletContext]=\"{data: data.data || {}, config: data.config}\" />\r\n </ng-container>\r\n </li>\r\n</ng-container>", styles: [":host{display:block;position:absolute;left:0;top:0;box-sizing:border-box;overflow:hidden}.ngvl-item__container{margin:0;padding:0;overflow:hidden;background-color:#fff;width:inherit;height:inherit}\n"] }]
218
+ }], ctorParameters: function () { return [{ type: i0.ChangeDetectorRef }, { type: i0.ElementRef }]; } });
219
+
220
+ /**
221
+ * Simple debounce function.
222
+ * @link https://github.com/DjonnyX/ng-virtual-list/blob/15.x/projects/ng-virtual-list/src/lib/utils/debounce.ts
223
+ * @author Evgenii Grebennikov
224
+ * @email djonnyx@gmail.com
225
+ */
226
+ const debounce = (cb, debounceTime = 0) => {
227
+ let timeout;
228
+ const dispose = () => {
229
+ if (timeout !== undefined) {
230
+ clearTimeout(timeout);
231
+ }
232
+ };
233
+ const execute = (...args) => {
234
+ dispose();
235
+ timeout = setTimeout(() => {
236
+ cb(...args);
237
+ }, debounceTime);
238
+ };
239
+ return {
240
+ /**
241
+ * Call handling method
242
+ */
243
+ execute,
244
+ /**
245
+ * Method of destroying handlers
246
+ */
247
+ dispose,
248
+ };
249
+ };
250
+
251
+ /**
252
+ * Switch css classes
253
+ * @link https://github.com/DjonnyX/ng-virtual-list/blob/15.x/projects/ng-virtual-list/src/lib/utils/toggleClassName.ts
254
+ * @author Evgenii Grebennikov
255
+ * @email djonnyx@gmail.com
256
+ */
257
+ const toggleClassName = (el, className, removeClassName) => {
258
+ if (!el.classList.contains(className)) {
259
+ el.classList.add(className);
260
+ }
261
+ if (removeClassName) {
262
+ el.classList.remove(removeClassName);
263
+ }
264
+ };
265
+
266
+ /**
267
+ * Scroll event.
268
+ * @link https://github.com/DjonnyX/ng-virtual-list/blob/15.x/projects/ng-virtual-list/src/lib/utils/scrollEvent.ts
269
+ * @author Evgenii Grebennikov
270
+ * @email djonnyx@gmail.com
271
+ */
272
+ class ScrollEvent {
273
+ get direction() { return this._direction; }
274
+ get scrollSize() { return this._scrollSize; }
275
+ get scrollWeight() { return this._scrollWeight; }
276
+ get isVertical() { return this._isVertical; }
277
+ get listSize() { return this._listSize; }
278
+ get size() { return this._size; }
279
+ get isStart() { return this._isStart; }
280
+ get isEnd() { return this._isEnd; }
281
+ get delta() { return this._delta; }
282
+ get scrollDelta() { return this._scrollDelta; }
283
+ constructor(params) {
284
+ this._direction = 1;
285
+ this._scrollSize = 0;
286
+ this._scrollWeight = 0;
287
+ this._isVertical = true;
288
+ this._listSize = 0;
289
+ this._size = 0;
290
+ this._isStart = true;
291
+ this._isEnd = false;
292
+ this._delta = 0;
293
+ this._scrollDelta = 0;
294
+ const { direction, isVertical, container, list, delta, scrollDelta } = params;
295
+ this._direction = direction;
296
+ this._isVertical = isVertical;
297
+ this._scrollSize = isVertical ? container.scrollTop : container.scrollLeft;
298
+ this._scrollWeight = isVertical ? container.scrollHeight : container.scrollWidth;
299
+ this._listSize = isVertical ? list.offsetHeight : list.offsetWidth;
300
+ this._size = isVertical ? container.offsetHeight : container.offsetWidth;
301
+ this._isEnd = (this._scrollSize + this._size) === this._scrollWeight;
302
+ this._delta = delta;
303
+ this._scrollDelta = scrollDelta;
304
+ this._isStart = this._scrollSize === 0;
305
+ }
306
+ }
307
+
308
+ /**
309
+ * Simple event emitter
310
+ * @link https://github.com/DjonnyX/ng-virtual-list/blob/15.x/projects/ng-virtual-list/src/lib/utils/eventEmitter.ts
311
+ * @author Evgenii Grebennikov
312
+ * @email djonnyx@gmail.com
313
+ */
314
+ class EventEmitter {
315
+ constructor() {
316
+ this._listeners = {};
317
+ this._disposed = false;
318
+ }
319
+ /**
320
+ * Emits the event
321
+ */
322
+ dispatch(event, ...args) {
323
+ const ctx = this;
324
+ const listeners = this._listeners[event];
325
+ if (Array.isArray(listeners)) {
326
+ for (let i = 0, l = listeners.length; i < l; i++) {
327
+ const listener = listeners[i];
328
+ if (listener) {
329
+ listener.apply(ctx, args);
330
+ }
331
+ }
332
+ }
333
+ }
334
+ /**
335
+ * Emits the event async
336
+ */
337
+ dispatchAsync(event, ...args) {
338
+ queueMicrotask(() => {
339
+ if (this._disposed) {
340
+ return;
341
+ }
342
+ this.dispatch(event, ...args);
343
+ });
344
+ }
345
+ /**
346
+ * Returns true if the event listener is already subscribed.
347
+ */
348
+ hasEventListener(eventName, handler) {
349
+ const event = eventName;
350
+ if (this._listeners.hasOwnProperty(event)) {
351
+ const listeners = this._listeners[event];
352
+ const index = listeners.findIndex(v => v === handler);
353
+ if (index > -1) {
354
+ return true;
355
+ }
356
+ }
357
+ return false;
358
+ }
359
+ /**
360
+ * Add event listener
361
+ */
362
+ addEventListener(eventName, handler) {
363
+ const event = eventName;
364
+ if (!this._listeners.hasOwnProperty(event)) {
365
+ this._listeners[event] = [];
366
+ }
367
+ this._listeners[event].push(handler);
368
+ }
369
+ /**
370
+ * Remove event listener
371
+ */
372
+ removeEventListener(eventName, handler) {
373
+ const event = eventName;
374
+ if (!this._listeners.hasOwnProperty(event)) {
375
+ return;
376
+ }
377
+ const listeners = this._listeners[event], index = listeners.findIndex(v => v === handler);
378
+ if (index > -1) {
379
+ listeners.splice(index, 1);
380
+ if (listeners.length === 0) {
381
+ delete this._listeners[event];
382
+ }
383
+ }
384
+ }
385
+ /**
386
+ * Remove all listeners
387
+ */
388
+ removeAllListeners() {
389
+ const events = Object.keys(this._listeners);
390
+ while (events.length > 0) {
391
+ const event = events.pop();
392
+ if (event) {
393
+ const listeners = this._listeners[event];
394
+ if (Array.isArray(listeners)) {
395
+ while (listeners.length > 0) {
396
+ const listener = listeners.pop();
397
+ if (listener) {
398
+ this.removeEventListener(event, listener);
399
+ }
400
+ }
401
+ }
402
+ }
403
+ }
404
+ }
405
+ /**
406
+ * Method of destroying handlers
407
+ */
408
+ dispose() {
409
+ this._disposed = true;
410
+ this.removeAllListeners();
411
+ }
412
+ }
413
+
414
+ class CMap {
415
+ constructor(dict) {
416
+ this._dict = {};
417
+ if (dict) {
418
+ this._dict = { ...dict._dict };
419
+ }
420
+ }
421
+ get(key) {
422
+ const k = String(key);
423
+ return this._dict[k];
424
+ }
425
+ set(key, value) {
426
+ const k = String(key);
427
+ this._dict[k] = value;
428
+ return this;
429
+ }
430
+ has(key) {
431
+ return this._dict.hasOwnProperty(String(key));
432
+ }
433
+ delete(key) {
434
+ const k = String(key);
435
+ delete this._dict[k];
436
+ }
437
+ clear() {
438
+ this._dict = {};
439
+ }
440
+ }
441
+ const CACHE_BOX_CHANGE_EVENT_NAME = 'change';
442
+ const MAX_SCROLL_DIRECTION_POOL = 50, CLEAR_SCROLL_DIRECTION_TO = 10, DIR_BACK = '-1', DIR_NONE = '0', DIR_FORWARD = '1';
443
+ /**
444
+ * Cache map.
445
+ * Emits a change event on each mutation.
446
+ * @link https://github.com/DjonnyX/ng-virtual-list/blob/15.x/projects/ng-virtual-list/src/lib/utils/cacheMap.ts
447
+ * @author Evgenii Grebennikov
448
+ * @email djonnyx@gmail.com
449
+ */
450
+ class CacheMap extends EventEmitter {
451
+ get delta() {
452
+ return this._delta;
453
+ }
454
+ set deltaDirection(v) {
455
+ this._deltaDirection = v;
456
+ this._scrollDirection = this.calcScrollDirection(v);
457
+ }
458
+ get deltaDirection() {
459
+ return this._deltaDirection;
460
+ }
461
+ get scrollDirection() {
462
+ return this._scrollDirection;
463
+ }
464
+ get version() {
465
+ return this._version;
466
+ }
467
+ constructor() {
468
+ super();
469
+ this._map = new CMap();
470
+ this._snapshot = new CMap();
471
+ this._version = 0;
472
+ this._previousVersion = this._version;
473
+ this._delta = 0;
474
+ this._deltaDirection = 0;
475
+ this._scrollDirectionCache = [];
476
+ this._scrollDirection = 0;
477
+ this._clearScrollDirectionDebounce = debounce(() => {
478
+ while (this._scrollDirectionCache.length > CLEAR_SCROLL_DIRECTION_TO) {
479
+ this._scrollDirectionCache.shift();
480
+ }
481
+ }, 10);
482
+ this.lifeCircle();
483
+ }
484
+ changesDetected() {
485
+ return this._version !== this._previousVersion;
486
+ }
487
+ stopLifeCircle() {
488
+ clearTimeout(this._lifeCircleTimeout);
489
+ }
490
+ nextTick(cb) {
491
+ if (this._disposed) {
492
+ return;
493
+ }
494
+ this._lifeCircleTimeout = setTimeout(() => {
495
+ cb();
496
+ });
497
+ return this._lifeCircleTimeout;
498
+ }
499
+ lifeCircle() {
500
+ this.fireChangeIfNeed();
501
+ this.lifeCircleDo();
502
+ }
503
+ lifeCircleDo() {
504
+ this._previousVersion = this._version;
505
+ this.nextTick(() => {
506
+ this.lifeCircle();
507
+ });
508
+ }
509
+ clearScrollDirectionCache() {
510
+ this._clearScrollDirectionDebounce.execute();
511
+ }
512
+ calcScrollDirection(v) {
513
+ while (this._scrollDirectionCache.length >= MAX_SCROLL_DIRECTION_POOL) {
514
+ this._scrollDirectionCache.shift();
515
+ }
516
+ this._scrollDirectionCache.push(v);
517
+ const dict = { [DIR_BACK]: 0, [DIR_NONE]: 0, [DIR_FORWARD]: 0 };
518
+ for (let i = 0, l = this._scrollDirectionCache.length, li = l - 1; i < l; i++) {
519
+ const dir = String(this._scrollDirectionCache[i]);
520
+ dict[dir] += 1;
521
+ if (i === li) {
522
+ for (let d in dict) {
523
+ if (d === String(v)) {
524
+ continue;
525
+ }
526
+ dict[d] -= 1;
527
+ }
528
+ }
529
+ }
530
+ if (dict[DIR_BACK] > dict[DIR_NONE] && dict[DIR_BACK] > dict[DIR_FORWARD]) {
531
+ return -1;
532
+ }
533
+ else if (dict[DIR_FORWARD] > dict[DIR_BACK] && dict[DIR_FORWARD] > dict[DIR_NONE]) {
534
+ return 1;
535
+ }
536
+ return 0;
537
+ }
538
+ bumpVersion() {
539
+ if (this.changesDetected()) {
540
+ return;
541
+ }
542
+ const v = this._version === Number.MAX_SAFE_INTEGER ? 0 : this._version + 1;
543
+ this._version = v;
544
+ }
545
+ fireChangeIfNeed() {
546
+ if (this.changesDetected()) {
547
+ this.dispatch(CACHE_BOX_CHANGE_EVENT_NAME, this.version);
548
+ }
549
+ }
550
+ set(id, bounds) {
551
+ if (this._map.has(id)) {
552
+ const b = this._map.get(id), bb = bounds;
553
+ if (b.width === bb.width && b.height === bb.height) {
554
+ return this._map;
555
+ }
556
+ return this._map;
557
+ }
558
+ const v = this._map.set(id, bounds);
559
+ this.bumpVersion();
560
+ return v;
561
+ }
562
+ has(id) {
563
+ return this._map.has(id);
564
+ }
565
+ get(id) {
566
+ return this._map.get(id);
567
+ }
568
+ snapshot() {
569
+ this._snapshot = new CMap(this._map);
570
+ }
571
+ dispose() {
572
+ super.dispose();
573
+ this.stopLifeCircle();
574
+ this._snapshot.clear();
575
+ this._map.clear();
576
+ }
577
+ }
578
+
579
+ /**
580
+ * Tracks display items by property
581
+ * @link https://github.com/DjonnyX/ng-virtual-list/blob/15.x/projects/ng-virtual-list/src/lib/utils/tracker.ts
582
+ * @author Evgenii Grebennikov
583
+ * @email djonnyx@gmail.com
584
+ */
585
+ class Tracker {
586
+ set displayObjectIndexMapById(v) {
587
+ if (this._displayObjectIndexMapById === v) {
588
+ return;
589
+ }
590
+ this._displayObjectIndexMapById = v;
591
+ }
592
+ get displayObjectIndexMapById() {
593
+ return this._displayObjectIndexMapById;
594
+ }
595
+ get trackMap() {
596
+ return this._trackMap;
597
+ }
598
+ set trackingPropertyName(v) {
599
+ this._trackingPropertyName = v;
600
+ }
601
+ constructor(trackingPropertyName) {
602
+ /**
603
+ * display objects dictionary of indexes by id
604
+ */
605
+ this._displayObjectIndexMapById = {};
606
+ /**
607
+ * Dictionary displayItems propertyNameId by items propertyNameId
608
+ */
609
+ this._trackMap = {};
610
+ this._trackingPropertyName = trackingPropertyName;
611
+ }
612
+ /**
613
+ * tracking by propName
614
+ */
615
+ track(items, components, snapedComponent, direction) {
616
+ if (!items) {
617
+ return;
618
+ }
619
+ const idPropName = this._trackingPropertyName, untrackedItems = [...components], isDown = direction === 0 || direction === 1;
620
+ let isRegularSnapped = false;
621
+ for (let i = isDown ? 0 : items.length - 1, l = isDown ? items.length : 0; isDown ? i < l : i >= l; isDown ? i++ : i--) {
622
+ const item = items[i], itemTrackingProperty = item[idPropName];
623
+ if (this._trackMap) {
624
+ if (this._trackMap.hasOwnProperty(itemTrackingProperty)) {
625
+ const diId = this._trackMap[itemTrackingProperty], compIndex = this._displayObjectIndexMapById[diId], comp = components[compIndex];
626
+ const compId = comp?.instance?.id;
627
+ if (comp !== undefined && compId === diId) {
628
+ const indexByUntrackedItems = untrackedItems.findIndex(v => {
629
+ return v.instance.id === compId;
630
+ });
631
+ if (indexByUntrackedItems > -1) {
632
+ if (snapedComponent) {
633
+ if (item['config']['snapped'] || item['config']['snappedOut']) {
634
+ isRegularSnapped = true;
635
+ snapedComponent.instance.item = item;
636
+ snapedComponent.instance.show();
637
+ }
638
+ }
639
+ comp.instance.item = item;
640
+ if (snapedComponent) {
641
+ if (item['config']['snapped'] || item['config']['snappedOut']) {
642
+ comp.instance.hide();
643
+ }
644
+ else {
645
+ comp.instance.show();
646
+ }
647
+ }
648
+ else {
649
+ comp.instance.show();
650
+ }
651
+ untrackedItems.splice(indexByUntrackedItems, 1);
652
+ continue;
653
+ }
654
+ }
655
+ delete this._trackMap[itemTrackingProperty];
656
+ }
657
+ }
658
+ if (untrackedItems.length > 0) {
659
+ const comp = untrackedItems.shift(), item = items[i];
660
+ if (comp) {
661
+ if (snapedComponent) {
662
+ if (item['config']['snapped'] || item['config']['snappedOut']) {
663
+ isRegularSnapped = true;
664
+ snapedComponent.instance.item = item;
665
+ snapedComponent.instance.show();
666
+ }
667
+ }
668
+ comp.instance.item = item;
669
+ if (snapedComponent) {
670
+ if (item['config']['snapped'] || item['config']['snappedOut']) {
671
+ comp.instance.hide();
672
+ }
673
+ else {
674
+ comp.instance.show();
675
+ }
676
+ }
677
+ else {
678
+ comp.instance.show();
679
+ }
680
+ if (this._trackMap) {
681
+ this._trackMap[itemTrackingProperty] = comp.instance.id;
682
+ }
683
+ }
684
+ }
685
+ }
686
+ if (untrackedItems.length) {
687
+ for (let i = 0, l = untrackedItems.length; i < l; i++) {
688
+ const comp = untrackedItems[i];
689
+ comp.instance.hide();
690
+ }
691
+ }
692
+ if (!isRegularSnapped) {
693
+ if (snapedComponent) {
694
+ snapedComponent.instance.item = null;
695
+ snapedComponent.instance.hide();
696
+ }
697
+ }
698
+ }
699
+ untrackComponentByIdProperty(component) {
700
+ if (!component) {
701
+ return;
702
+ }
703
+ const propertyIdName = this._trackingPropertyName;
704
+ if (this._trackMap && component[propertyIdName] !== undefined) {
705
+ delete this._trackMap[propertyIdName];
706
+ }
707
+ }
708
+ dispose() {
709
+ this._trackMap = null;
710
+ }
711
+ }
712
+
713
+ const DEFAULT_EXTRA = {
714
+ extremumThreshold: 2,
715
+ bufferSize: 10,
716
+ };
717
+ const bufferInterpolation = (currentBufferValue, array, value, extra) => {
718
+ const { extremumThreshold = DEFAULT_EXTRA.extremumThreshold, bufferSize = DEFAULT_EXTRA.bufferSize, } = extra ?? DEFAULT_EXTRA;
719
+ if (currentBufferValue < value) {
720
+ let i = 0;
721
+ while (i < extremumThreshold) {
722
+ array.push(value);
723
+ i++;
724
+ }
725
+ }
726
+ else {
727
+ array.push(value);
728
+ }
729
+ while (array.length >= bufferSize) {
730
+ array.shift();
731
+ }
732
+ const l = array.length;
733
+ let buffer = 0;
734
+ for (let i = 0; i < l; i++) {
735
+ buffer += array[i];
736
+ }
737
+ return Math.ceil(buffer / l);
738
+ };
739
+
740
+ const TRACK_BOX_CHANGE_EVENT_NAME = 'change';
741
+ var ItemDisplayMethods;
742
+ (function (ItemDisplayMethods) {
743
+ ItemDisplayMethods[ItemDisplayMethods["CREATE"] = 0] = "CREATE";
744
+ ItemDisplayMethods[ItemDisplayMethods["UPDATE"] = 1] = "UPDATE";
745
+ ItemDisplayMethods[ItemDisplayMethods["DELETE"] = 2] = "DELETE";
746
+ ItemDisplayMethods[ItemDisplayMethods["NOT_CHANGED"] = 3] = "NOT_CHANGED";
747
+ })(ItemDisplayMethods || (ItemDisplayMethods = {}));
748
+ const DEFAULT_BUFFER_EXTREMUM_THRESHOLD = 15, DEFAULT_MAX_BUFFER_SEQUENCE_LENGTH = 30, DEFAULT_RESET_BUFFER_SIZE_TIMEOUT = 10000;
749
+ /**
750
+ * An object that performs tracking, calculations and caching.
751
+ * @link https://github.com/DjonnyX/ng-virtual-list/blob/15.x/projects/ng-virtual-list/src/lib/utils/trackBox.ts
752
+ * @author Evgenii Grebennikov
753
+ * @email djonnyx@gmail.com
754
+ */
755
+ class TrackBox extends CacheMap {
756
+ set items(v) {
757
+ if (this._items === v) {
758
+ return;
759
+ }
760
+ this._items = v;
761
+ }
762
+ set displayComponents(v) {
763
+ if (this._displayComponents === v) {
764
+ return;
765
+ }
766
+ this._displayComponents = v;
767
+ }
768
+ set snapedDisplayComponent(v) {
769
+ if (this._snapedDisplayComponent === v) {
770
+ return;
771
+ }
772
+ this._snapedDisplayComponent = v;
773
+ }
774
+ set isSnappingMethodAdvanced(v) {
775
+ if (this._isSnappingMethodAdvanced === v) {
776
+ return;
777
+ }
778
+ this._isSnappingMethodAdvanced = v;
779
+ }
780
+ /**
781
+ * Set the trackBy property
782
+ */
783
+ set trackingPropertyName(v) {
784
+ this._trackingPropertyName = this._tracker.trackingPropertyName = v;
785
+ }
786
+ constructor(trackingPropertyName) {
787
+ super();
788
+ this._isSnappingMethodAdvanced = false;
789
+ this._trackingPropertyName = TRACK_BY_PROPERTY_NAME;
790
+ this._deletedItemsMap = {};
791
+ this._crudDetected = false;
792
+ this._previousTotalSize = 0;
793
+ this._scrollDelta = 0;
794
+ this.isAdaptiveBuffer = true;
795
+ this._bufferSequenceExtraThreshold = DEFAULT_BUFFER_EXTREMUM_THRESHOLD;
796
+ this._maxBufferSequenceLength = DEFAULT_MAX_BUFFER_SEQUENCE_LENGTH;
797
+ this._bufferSizeSequence = [];
798
+ this._bufferSize = 0;
799
+ this._defaultBufferSize = 0;
800
+ this._maxBufferSize = this._defaultBufferSize;
801
+ this._resetBufferSizeTimeout = DEFAULT_RESET_BUFFER_SIZE_TIMEOUT;
802
+ this._previousScrollSize = 0;
803
+ this._trackingPropertyName = trackingPropertyName;
804
+ this.initialize();
805
+ }
806
+ initialize() {
807
+ this._tracker = new Tracker(this._trackingPropertyName);
808
+ }
809
+ set(id, bounds) {
810
+ if (this._map.has(id)) {
811
+ const b = this._map.get(id);
812
+ if (b?.width === bounds.width && b.height === bounds.height) {
813
+ return this._map;
814
+ }
815
+ }
816
+ const v = this._map.set(id, bounds);
817
+ this.bumpVersion();
818
+ return v;
819
+ }
820
+ get crudDetected() { return this._crudDetected; }
821
+ fireChangeIfNeed() {
822
+ if (this.changesDetected()) {
823
+ this.dispatch(TRACK_BOX_CHANGE_EVENT_NAME, this._version);
824
+ }
825
+ }
826
+ get scrollDelta() { return this._scrollDelta; }
827
+ get bufferSize() { return this._bufferSize; }
828
+ lifeCircle() {
829
+ this.fireChangeIfNeed();
830
+ this.lifeCircleDo();
831
+ }
832
+ /**
833
+ * Scans the collection for deleted items and flushes the deleted item cache.
834
+ */
835
+ resetCollection(currentCollection, itemSize) {
836
+ if (currentCollection !== undefined && currentCollection !== null && currentCollection === this._previousCollection) {
837
+ console.warn('Attention! The collection must be immutable.');
838
+ return;
839
+ }
840
+ this.updateCache(this._previousCollection, currentCollection, itemSize);
841
+ this._previousCollection = currentCollection;
842
+ }
843
+ /**
844
+ * Update the cache of items from the list
845
+ */
846
+ updateCache(previousCollection, currentCollection, itemSize) {
847
+ let crudDetected = false;
848
+ if (!currentCollection || currentCollection.length === 0) {
849
+ if (previousCollection) {
850
+ // deleted
851
+ for (let i = 0, l = previousCollection.length; i < l; i++) {
852
+ const item = previousCollection[i], id = item.id;
853
+ crudDetected = true;
854
+ if (this._map.has(id)) {
855
+ this._map.delete(id);
856
+ }
857
+ }
858
+ }
859
+ return;
860
+ }
861
+ if (!previousCollection || previousCollection.length === 0) {
862
+ if (currentCollection) {
863
+ // added
864
+ for (let i = 0, l = currentCollection.length; i < l; i++) {
865
+ crudDetected = true;
866
+ const item = currentCollection[i], id = item.id;
867
+ this._map.set(id, { width: itemSize, height: itemSize, method: ItemDisplayMethods.CREATE });
868
+ }
869
+ }
870
+ return;
871
+ }
872
+ const collectionDict = {};
873
+ for (let i = 0, l = currentCollection.length; i < l; i++) {
874
+ const item = currentCollection[i];
875
+ if (item) {
876
+ collectionDict[item.id] = item;
877
+ }
878
+ }
879
+ const notChangedMap = {}, deletedMap = {}, deletedItemsMap = {}, updatedMap = {};
880
+ for (let i = 0, l = previousCollection.length; i < l; i++) {
881
+ const item = previousCollection[i], id = item.id;
882
+ if (item) {
883
+ if (collectionDict.hasOwnProperty(id)) {
884
+ if (item === collectionDict[id]) {
885
+ // not changed
886
+ notChangedMap[item.id] = item;
887
+ this._map.set(id, { ...(this._map.get(id) || { width: itemSize, height: itemSize }), method: ItemDisplayMethods.NOT_CHANGED });
888
+ continue;
889
+ }
890
+ else {
891
+ // updated
892
+ crudDetected = true;
893
+ updatedMap[item.id] = item;
894
+ this._map.set(id, { ...(this._map.get(id) || { width: itemSize, height: itemSize }), method: ItemDisplayMethods.UPDATE });
895
+ continue;
896
+ }
897
+ }
898
+ // deleted
899
+ crudDetected = true;
900
+ deletedMap[item.id] = item;
901
+ deletedItemsMap[i] = this._map.get(item.id);
902
+ this._map.delete(id);
903
+ }
904
+ }
905
+ for (let i = 0, l = currentCollection.length; i < l; i++) {
906
+ const item = currentCollection[i], id = item.id;
907
+ if (item && !deletedMap.hasOwnProperty(id) && !updatedMap.hasOwnProperty(id) && !notChangedMap.hasOwnProperty(id)) {
908
+ // added
909
+ crudDetected = true;
910
+ this._map.set(id, { width: itemSize, height: itemSize, method: ItemDisplayMethods.CREATE });
911
+ }
912
+ }
913
+ this._crudDetected = crudDetected;
914
+ this._deletedItemsMap = deletedItemsMap;
915
+ }
916
+ /**
917
+ * Finds the position of a collection element by the given Id
918
+ */
919
+ getItemPosition(id, stickyMap, options) {
920
+ const opt = { fromItemId: id, stickyMap, ...options };
921
+ this._defaultBufferSize = opt.bufferSize;
922
+ this._maxBufferSize = opt.maxBufferSize;
923
+ const { scrollSize, isFromItemIdFound } = this.recalculateMetrics({
924
+ ...opt,
925
+ dynamicSize: this._crudDetected || opt.dynamicSize,
926
+ previousTotalSize: this._previousTotalSize,
927
+ crudDetected: this._crudDetected,
928
+ deletedItemsMap: this._deletedItemsMap,
929
+ });
930
+ return isFromItemIdFound ? scrollSize : -1;
931
+ }
932
+ /**
933
+ * Updates the collection of display objects
934
+ */
935
+ updateCollection(items, stickyMap, options) {
936
+ const opt = { stickyMap, ...options }, crudDetected = this._crudDetected, deletedItemsMap = this._deletedItemsMap;
937
+ if (opt.dynamicSize) {
938
+ this.cacheElements();
939
+ }
940
+ this._defaultBufferSize = opt.bufferSize;
941
+ this._maxBufferSize = opt.maxBufferSize;
942
+ const metrics = this.recalculateMetrics({
943
+ ...opt,
944
+ collection: items,
945
+ previousTotalSize: this._previousTotalSize,
946
+ crudDetected: this._crudDetected,
947
+ deletedItemsMap,
948
+ });
949
+ this._delta += metrics.delta;
950
+ this.updateAdaptiveBufferParams(metrics, items.length);
951
+ this._previousTotalSize = metrics.totalSize;
952
+ this._deletedItemsMap = {};
953
+ this._crudDetected = false;
954
+ if (opt.dynamicSize) {
955
+ this.snapshot();
956
+ }
957
+ const displayItems = this.generateDisplayCollection(items, stickyMap, { ...metrics, });
958
+ return { displayItems, totalSize: metrics.totalSize, delta: metrics.delta, crudDetected };
959
+ }
960
+ /**
961
+ * Finds the closest element in the collection by scrollSize
962
+ */
963
+ getNearestItem(scrollSize, items, itemSize, isVertical) {
964
+ return this.getElementFromStart(scrollSize, items, this._map, itemSize, isVertical);
965
+ }
966
+ updateAdaptiveBufferParams(metrics, totalItemsLength) {
967
+ this.disposeClearBufferSizeTimer();
968
+ const scrollSize = metrics.scrollSize + this._delta, delta = Math.abs(this._previousScrollSize - scrollSize);
969
+ this._previousScrollSize = scrollSize;
970
+ const bufferRawSize = Math.min(Math.floor(delta / metrics.typicalItemSize) * 5, totalItemsLength), minBufferSize = bufferRawSize < this._defaultBufferSize ? this._defaultBufferSize : bufferRawSize, bufferValue = minBufferSize > this._maxBufferSize ? this._maxBufferSize : minBufferSize;
971
+ this._bufferSize = bufferInterpolation(this._bufferSize, this._bufferSizeSequence, bufferValue, {
972
+ extremumThreshold: this._bufferSequenceExtraThreshold,
973
+ bufferSize: this._maxBufferSequenceLength,
974
+ });
975
+ this.startResetBufferSizeTimer();
976
+ }
977
+ startResetBufferSizeTimer() {
978
+ this._resetBufferSizeTimer = setTimeout(() => {
979
+ this._bufferSize = this._defaultBufferSize;
980
+ this._bufferSizeSequence = [];
981
+ }, this._resetBufferSizeTimeout);
982
+ }
983
+ disposeClearBufferSizeTimer() {
984
+ clearTimeout(this._resetBufferSizeTimer);
985
+ }
986
+ /**
987
+ * Calculates the position of an element based on the given scrollSize
988
+ */
989
+ getElementFromStart(scrollSize, collection, map, typicalItemSize, isVertical) {
990
+ const sizeProperty = isVertical ? HEIGHT_PROP_NAME : WIDTH_PROP_NAME;
991
+ let offset = 0;
992
+ for (let i = 0, l = collection.length; i < l; i++) {
993
+ const item = collection[i];
994
+ let itemSize = 0;
995
+ if (map.has(item.id)) {
996
+ const bounds = map.get(item.id);
997
+ itemSize = bounds ? bounds[sizeProperty] : typicalItemSize;
998
+ }
999
+ else {
1000
+ itemSize = typicalItemSize;
1001
+ }
1002
+ if (offset > scrollSize) {
1003
+ return item;
1004
+ }
1005
+ offset += itemSize;
1006
+ }
1007
+ return undefined;
1008
+ }
1009
+ /**
1010
+ * Calculates the entry into the overscroll area and returns the number of overscroll elements
1011
+ */
1012
+ getElementNumToEnd(i, collection, map, typicalItemSize, size, isVertical, indexOffset = 0) {
1013
+ const sizeProperty = isVertical ? HEIGHT_PROP_NAME : WIDTH_PROP_NAME;
1014
+ let offset = 0, num = 0;
1015
+ for (let j = collection.length - indexOffset - 1; j >= i; j--) {
1016
+ const item = collection[j];
1017
+ let itemSize = 0;
1018
+ if (map.has(item.id)) {
1019
+ const bounds = map.get(item.id);
1020
+ itemSize = bounds ? bounds[sizeProperty] : typicalItemSize;
1021
+ }
1022
+ else {
1023
+ itemSize = typicalItemSize;
1024
+ }
1025
+ offset += itemSize;
1026
+ num++;
1027
+ if (offset > size) {
1028
+ return { num: 0, offset };
1029
+ }
1030
+ }
1031
+ return { num, offset };
1032
+ }
1033
+ /**
1034
+ * Calculates list metrics
1035
+ */
1036
+ recalculateMetrics(options) {
1037
+ const { fromItemId, bounds, collection, dynamicSize, isVertical, itemSize, bufferSize: minBufferSize, scrollSize, snap, stickyMap, enabledBufferOptimization, previousTotalSize, crudDetected, deletedItemsMap } = options;
1038
+ const bufferSize = Math.max(minBufferSize, this._bufferSize), { width, height } = bounds, sizeProperty = isVertical ? HEIGHT_PROP_NAME : WIDTH_PROP_NAME, size = isVertical ? height : width, totalLength = collection.length, typicalItemSize = itemSize, w = isVertical ? width : typicalItemSize, h = isVertical ? typicalItemSize : height, map = this._map, snapshot = this._snapshot, checkOverscrollItemsLimit = Math.ceil(size / typicalItemSize), snippedPos = Math.floor(scrollSize), leftItemsWeights = [], isFromId = fromItemId !== undefined && (typeof fromItemId === 'number' && fromItemId > -1)
1039
+ || (typeof fromItemId === 'string' && fromItemId > '-1');
1040
+ let leftItemsOffset = 0, rightItemsOffset = 0;
1041
+ if (enabledBufferOptimization) {
1042
+ switch (this.scrollDirection) {
1043
+ case 1: {
1044
+ leftItemsOffset = 0;
1045
+ rightItemsOffset = bufferSize;
1046
+ break;
1047
+ }
1048
+ case -1: {
1049
+ leftItemsOffset = bufferSize;
1050
+ rightItemsOffset = 0;
1051
+ break;
1052
+ }
1053
+ case 0:
1054
+ default: {
1055
+ leftItemsOffset = rightItemsOffset = bufferSize;
1056
+ }
1057
+ }
1058
+ }
1059
+ else {
1060
+ leftItemsOffset = rightItemsOffset = bufferSize;
1061
+ }
1062
+ let itemsFromStartToScrollEnd = -1, itemsFromDisplayEndToOffsetEnd = 0, itemsFromStartToDisplayEnd = -1, leftItemLength = 0, rightItemLength = 0, leftItemsWeight = 0, rightItemsWeight = 0, leftHiddenItemsWeight = 0, totalItemsToDisplayEndWeight = 0, leftSizeOfAddedItems = 0, leftSizeOfUpdatedItems = 0, leftSizeOfDeletedItems = 0, itemById = undefined, itemByIdPos = 0, targetDisplayItemIndex = -1, isTargetInOverscroll = false, actualScrollSize = itemByIdPos, totalSize = 0, startIndex, isFromItemIdFound = false;
1063
+ // If the list is dynamic or there are new elements in the collection, then it switches to the long algorithm.
1064
+ if (dynamicSize) {
1065
+ let y = 0, stickyCollectionItem = undefined, stickyComponentSize = 0;
1066
+ for (let i = 0, l = collection.length; i < l; i++) {
1067
+ const ii = i + 1, collectionItem = collection[i], id = collectionItem.id;
1068
+ let componentSize = 0, componentSizeDelta = 0, itemDisplayMethod = ItemDisplayMethods.NOT_CHANGED;
1069
+ if (map.has(id)) {
1070
+ const bounds = map.get(id) || { width: typicalItemSize, height: typicalItemSize };
1071
+ componentSize = bounds[sizeProperty];
1072
+ itemDisplayMethod = bounds?.method ?? ItemDisplayMethods.UPDATE;
1073
+ switch (itemDisplayMethod) {
1074
+ case ItemDisplayMethods.UPDATE: {
1075
+ const snapshotBounds = snapshot.get(id);
1076
+ const componentSnapshotSize = componentSize - (snapshotBounds ? snapshotBounds[sizeProperty] : typicalItemSize);
1077
+ componentSizeDelta = componentSnapshotSize;
1078
+ map.set(id, { ...bounds, method: ItemDisplayMethods.NOT_CHANGED });
1079
+ break;
1080
+ }
1081
+ case ItemDisplayMethods.CREATE: {
1082
+ componentSizeDelta = typicalItemSize;
1083
+ map.set(id, { ...bounds, method: ItemDisplayMethods.NOT_CHANGED });
1084
+ break;
1085
+ }
1086
+ }
1087
+ }
1088
+ if (deletedItemsMap.hasOwnProperty(i)) {
1089
+ const bounds = deletedItemsMap[i], size = bounds?.[sizeProperty] ?? typicalItemSize;
1090
+ if (y < scrollSize - size) {
1091
+ leftSizeOfDeletedItems += size;
1092
+ }
1093
+ }
1094
+ totalSize += componentSize;
1095
+ if (isFromId) {
1096
+ if (itemById === undefined) {
1097
+ if (id !== fromItemId && stickyMap && stickyMap[id] === 1) {
1098
+ stickyComponentSize = componentSize;
1099
+ stickyCollectionItem = collectionItem;
1100
+ }
1101
+ if (id === fromItemId) {
1102
+ isFromItemIdFound = true;
1103
+ targetDisplayItemIndex = i;
1104
+ if (stickyCollectionItem && stickyMap) {
1105
+ const { num } = this.getElementNumToEnd(i, collection, map, typicalItemSize, size, isVertical);
1106
+ if (num > 0) {
1107
+ isTargetInOverscroll = true;
1108
+ y -= size - componentSize;
1109
+ }
1110
+ else {
1111
+ if (stickyMap && !stickyMap[collectionItem.id] && y >= scrollSize && y < scrollSize + stickyComponentSize) {
1112
+ const snappedY = scrollSize - stickyComponentSize;
1113
+ leftHiddenItemsWeight -= (snappedY - y);
1114
+ y = snappedY;
1115
+ }
1116
+ else {
1117
+ y -= stickyComponentSize;
1118
+ leftHiddenItemsWeight -= stickyComponentSize;
1119
+ }
1120
+ }
1121
+ }
1122
+ itemById = collectionItem;
1123
+ itemByIdPos = y;
1124
+ }
1125
+ else {
1126
+ leftItemsWeights.push(componentSize);
1127
+ leftHiddenItemsWeight += componentSize;
1128
+ itemsFromStartToScrollEnd = ii;
1129
+ }
1130
+ }
1131
+ }
1132
+ else if (y <= scrollSize - componentSize) {
1133
+ leftItemsWeights.push(componentSize);
1134
+ leftHiddenItemsWeight += componentSize;
1135
+ itemsFromStartToScrollEnd = ii;
1136
+ }
1137
+ if (isFromId) {
1138
+ if (itemById === undefined || y < itemByIdPos + size + componentSize) {
1139
+ itemsFromStartToDisplayEnd = ii;
1140
+ totalItemsToDisplayEndWeight += componentSize;
1141
+ itemsFromDisplayEndToOffsetEnd = itemsFromStartToDisplayEnd + rightItemsOffset;
1142
+ }
1143
+ }
1144
+ else if (y <= scrollSize + size + componentSize) {
1145
+ itemsFromStartToDisplayEnd = ii;
1146
+ totalItemsToDisplayEndWeight += componentSize;
1147
+ itemsFromDisplayEndToOffsetEnd = itemsFromStartToDisplayEnd + rightItemsOffset;
1148
+ if (y <= scrollSize - componentSize) {
1149
+ switch (itemDisplayMethod) {
1150
+ case ItemDisplayMethods.CREATE: {
1151
+ leftSizeOfAddedItems += componentSizeDelta;
1152
+ break;
1153
+ }
1154
+ case ItemDisplayMethods.UPDATE: {
1155
+ leftSizeOfUpdatedItems += componentSizeDelta;
1156
+ break;
1157
+ }
1158
+ case ItemDisplayMethods.DELETE: {
1159
+ leftSizeOfDeletedItems += componentSizeDelta;
1160
+ break;
1161
+ }
1162
+ }
1163
+ }
1164
+ }
1165
+ else {
1166
+ if (i < itemsFromDisplayEndToOffsetEnd) {
1167
+ rightItemsWeight += componentSize;
1168
+ }
1169
+ }
1170
+ y += componentSize;
1171
+ }
1172
+ if (isTargetInOverscroll) {
1173
+ const { num } = this.getElementNumToEnd(collection.length - (checkOverscrollItemsLimit < 0 ? 0 : collection.length - checkOverscrollItemsLimit), collection, map, typicalItemSize, size, isVertical, collection.length - (collection.length - (targetDisplayItemIndex + 1)));
1174
+ if (num > 0) {
1175
+ itemsFromStartToScrollEnd -= num;
1176
+ }
1177
+ }
1178
+ if (itemsFromStartToScrollEnd <= -1) {
1179
+ itemsFromStartToScrollEnd = 0;
1180
+ }
1181
+ if (itemsFromStartToDisplayEnd <= -1) {
1182
+ itemsFromStartToDisplayEnd = 0;
1183
+ }
1184
+ actualScrollSize = isFromId ? itemByIdPos : scrollSize;
1185
+ leftItemsWeights.splice(0, leftItemsWeights.length - leftItemsOffset);
1186
+ leftItemsWeights.forEach(v => {
1187
+ leftItemsWeight += v;
1188
+ });
1189
+ leftItemLength = Math.min(itemsFromStartToScrollEnd, leftItemsOffset);
1190
+ rightItemLength = itemsFromStartToDisplayEnd + rightItemsOffset > totalLength
1191
+ ? totalLength - itemsFromStartToDisplayEnd : rightItemsOffset;
1192
+ }
1193
+ else
1194
+ // Buffer optimization does not work on fast linear algorithm
1195
+ {
1196
+ if (crudDetected) {
1197
+ let y = 0;
1198
+ for (let i = 0, l = collection.length; i < l; i++) {
1199
+ const collectionItem = collection[i], id = collectionItem.id;
1200
+ let componentSize = typicalItemSize, itemDisplayMethod = ItemDisplayMethods.NOT_CHANGED;
1201
+ if (map.has(id)) {
1202
+ const bounds = map.get(id);
1203
+ itemDisplayMethod = bounds?.method ?? ItemDisplayMethods.UPDATE;
1204
+ if (itemDisplayMethod === ItemDisplayMethods.CREATE) {
1205
+ map.set(id, { ...bounds, method: ItemDisplayMethods.NOT_CHANGED });
1206
+ }
1207
+ }
1208
+ if (deletedItemsMap.hasOwnProperty(i)) {
1209
+ const bounds = deletedItemsMap[i], size = bounds?.[sizeProperty] ?? typicalItemSize;
1210
+ if (y < scrollSize - size) {
1211
+ leftSizeOfDeletedItems += size;
1212
+ }
1213
+ }
1214
+ if (y < scrollSize - componentSize) {
1215
+ switch (itemDisplayMethod) {
1216
+ case ItemDisplayMethods.CREATE: {
1217
+ leftSizeOfUpdatedItems += componentSize;
1218
+ break;
1219
+ }
1220
+ case ItemDisplayMethods.UPDATE: {
1221
+ leftSizeOfUpdatedItems += componentSize;
1222
+ break;
1223
+ }
1224
+ case ItemDisplayMethods.DELETE: {
1225
+ leftSizeOfDeletedItems += componentSize;
1226
+ break;
1227
+ }
1228
+ }
1229
+ }
1230
+ y += componentSize;
1231
+ }
1232
+ }
1233
+ itemsFromStartToScrollEnd = Math.floor(scrollSize / typicalItemSize);
1234
+ itemsFromStartToDisplayEnd = Math.ceil((scrollSize + size) / typicalItemSize);
1235
+ leftItemLength = Math.min(itemsFromStartToScrollEnd, bufferSize);
1236
+ rightItemLength = itemsFromStartToDisplayEnd + bufferSize > totalLength
1237
+ ? totalLength - itemsFromStartToDisplayEnd : bufferSize;
1238
+ leftItemsWeight = leftItemLength * typicalItemSize;
1239
+ rightItemsWeight = rightItemLength * typicalItemSize;
1240
+ leftHiddenItemsWeight = itemsFromStartToScrollEnd * typicalItemSize;
1241
+ totalItemsToDisplayEndWeight = itemsFromStartToDisplayEnd * typicalItemSize;
1242
+ totalSize = totalLength * typicalItemSize;
1243
+ const k = totalSize !== 0 ? previousTotalSize / totalSize : 0;
1244
+ actualScrollSize = scrollSize * k;
1245
+ }
1246
+ startIndex = Math.min(itemsFromStartToScrollEnd - leftItemLength, totalLength > 0 ? totalLength - 1 : 0);
1247
+ const itemsOnDisplayWeight = totalItemsToDisplayEndWeight - leftItemsWeight, itemsOnDisplayLength = itemsFromStartToDisplayEnd - itemsFromStartToScrollEnd, startPosition = leftHiddenItemsWeight - leftItemsWeight, renderItems = itemsOnDisplayLength + leftItemLength + rightItemLength, delta = leftSizeOfUpdatedItems + leftSizeOfAddedItems - leftSizeOfDeletedItems;
1248
+ const metrics = {
1249
+ delta,
1250
+ normalizedItemWidth: w,
1251
+ normalizedItemHeight: h,
1252
+ width,
1253
+ height,
1254
+ dynamicSize,
1255
+ itemSize,
1256
+ itemsFromStartToScrollEnd,
1257
+ itemsFromStartToDisplayEnd,
1258
+ itemsOnDisplayWeight,
1259
+ itemsOnDisplayLength,
1260
+ isVertical,
1261
+ leftHiddenItemsWeight,
1262
+ leftItemLength,
1263
+ leftItemsWeight,
1264
+ renderItems,
1265
+ rightItemLength,
1266
+ rightItemsWeight,
1267
+ scrollSize: actualScrollSize,
1268
+ leftSizeOfAddedItems,
1269
+ sizeProperty,
1270
+ snap,
1271
+ snippedPos,
1272
+ startIndex,
1273
+ startPosition,
1274
+ totalItemsToDisplayEndWeight,
1275
+ totalLength,
1276
+ totalSize,
1277
+ typicalItemSize,
1278
+ isFromItemIdFound,
1279
+ };
1280
+ return metrics;
1281
+ }
1282
+ clearDeltaDirection() {
1283
+ this.clearScrollDirectionCache();
1284
+ }
1285
+ clearDelta(clearDirectionDetector = false) {
1286
+ this._delta = 0;
1287
+ if (clearDirectionDetector) {
1288
+ this.clearScrollDirectionCache();
1289
+ }
1290
+ }
1291
+ changes() {
1292
+ this.bumpVersion();
1293
+ }
1294
+ generateDisplayCollection(items, stickyMap, metrics) {
1295
+ const { width, height, normalizedItemWidth, normalizedItemHeight, dynamicSize, itemsOnDisplayLength, itemsFromStartToScrollEnd, isVertical, renderItems: renderItemsLength, scrollSize, sizeProperty, snap, snippedPos, startPosition, totalLength, startIndex, typicalItemSize, } = metrics, displayItems = [];
1296
+ if (items.length) {
1297
+ const actualSnippedPosition = snippedPos, isSnappingMethodAdvanced = this.isSnappingMethodAdvanced, boundsSize = isVertical ? height : width, actualEndSnippedPosition = boundsSize;
1298
+ let pos = startPosition, renderItems = renderItemsLength, stickyItem, nextSticky, stickyItemIndex = -1, stickyItemSize = 0, endStickyItem, nextEndSticky, endStickyItemIndex = -1, endStickyItemSize = 0;
1299
+ if (snap) {
1300
+ for (let i = Math.min(itemsFromStartToScrollEnd > 0 ? itemsFromStartToScrollEnd : 0, totalLength - 1); i >= 0; i--) {
1301
+ if (!items[i]) {
1302
+ continue;
1303
+ }
1304
+ const id = items[i].id, sticky = stickyMap[id], size = dynamicSize ? this.get(id)?.[sizeProperty] || typicalItemSize : typicalItemSize;
1305
+ if (sticky === 1) {
1306
+ const measures = {
1307
+ x: isVertical ? 0 : actualSnippedPosition,
1308
+ y: isVertical ? actualSnippedPosition : 0,
1309
+ width: isVertical ? normalizedItemWidth : size,
1310
+ height: isVertical ? size : normalizedItemHeight,
1311
+ delta: 0,
1312
+ }, config = {
1313
+ isVertical,
1314
+ sticky,
1315
+ snap,
1316
+ snapped: true,
1317
+ snappedOut: false,
1318
+ dynamic: dynamicSize,
1319
+ isSnappingMethodAdvanced,
1320
+ zIndex: '1',
1321
+ };
1322
+ const itemData = items[i];
1323
+ stickyItem = { id, measures, data: itemData, config };
1324
+ stickyItemIndex = i;
1325
+ stickyItemSize = size;
1326
+ displayItems.push(stickyItem);
1327
+ break;
1328
+ }
1329
+ }
1330
+ }
1331
+ if (snap) {
1332
+ const startIndex = itemsFromStartToScrollEnd + itemsOnDisplayLength - 1;
1333
+ for (let i = Math.min(startIndex, totalLength > 0 ? totalLength - 1 : 0), l = totalLength; i < l; i++) {
1334
+ if (!items[i]) {
1335
+ continue;
1336
+ }
1337
+ const id = items[i].id, sticky = stickyMap[id], size = dynamicSize
1338
+ ? this.get(id)?.[sizeProperty] || typicalItemSize
1339
+ : typicalItemSize;
1340
+ if (sticky === 2) {
1341
+ const w = isVertical ? normalizedItemWidth : size, h = isVertical ? size : normalizedItemHeight, measures = {
1342
+ x: isVertical ? 0 : actualEndSnippedPosition - w,
1343
+ y: isVertical ? actualEndSnippedPosition - h : 0,
1344
+ width: w,
1345
+ height: h,
1346
+ delta: 0,
1347
+ }, config = {
1348
+ isVertical,
1349
+ sticky,
1350
+ snap,
1351
+ snapped: true,
1352
+ snappedOut: false,
1353
+ dynamic: dynamicSize,
1354
+ isSnappingMethodAdvanced,
1355
+ zIndex: '1',
1356
+ };
1357
+ const itemData = items[i];
1358
+ endStickyItem = { id, measures, data: itemData, config };
1359
+ endStickyItemIndex = i;
1360
+ endStickyItemSize = size;
1361
+ displayItems.push(endStickyItem);
1362
+ break;
1363
+ }
1364
+ }
1365
+ }
1366
+ let i = startIndex;
1367
+ while (renderItems > 0) {
1368
+ if (i >= totalLength) {
1369
+ break;
1370
+ }
1371
+ if (!items[i]) {
1372
+ continue;
1373
+ }
1374
+ const id = items[i].id, size = dynamicSize ? this.get(id)?.[sizeProperty] || typicalItemSize : typicalItemSize;
1375
+ if (id !== stickyItem?.id && id !== endStickyItem?.id) {
1376
+ const snapped = snap && (stickyMap[id] === 1 && pos <= scrollSize || stickyMap[id] === 2 && pos >= scrollSize + boundsSize - size), measures = {
1377
+ x: isVertical ? stickyMap[id] === 1 ? 0 : boundsSize - size : pos,
1378
+ y: isVertical ? pos : stickyMap[id] === 2 ? boundsSize - size : 0,
1379
+ width: isVertical ? normalizedItemWidth : size,
1380
+ height: isVertical ? size : normalizedItemHeight,
1381
+ delta: 0,
1382
+ }, config = {
1383
+ isVertical,
1384
+ sticky: stickyMap[id],
1385
+ snap,
1386
+ snapped: false,
1387
+ snappedOut: false,
1388
+ dynamic: dynamicSize,
1389
+ isSnappingMethodAdvanced,
1390
+ zIndex: '0',
1391
+ };
1392
+ if (snapped) {
1393
+ config.zIndex = '2';
1394
+ }
1395
+ const itemData = items[i];
1396
+ const item = { id, measures, data: itemData, config };
1397
+ if (!nextSticky && stickyItemIndex < i && stickyMap[id] === 1 && (pos <= scrollSize + size + stickyItemSize)) {
1398
+ item.measures.x = isVertical ? 0 : snapped ? actualSnippedPosition : pos;
1399
+ item.measures.y = isVertical ? snapped ? actualSnippedPosition : pos : 0;
1400
+ nextSticky = item;
1401
+ nextSticky.config.snapped = snapped;
1402
+ nextSticky.measures.delta = isVertical ? (item.measures.y - scrollSize) : (item.measures.x - scrollSize);
1403
+ nextSticky.config.zIndex = '3';
1404
+ }
1405
+ else if (!nextEndSticky && endStickyItemIndex > i && stickyMap[id] === 2 && (pos >= scrollSize + boundsSize - size - endStickyItemSize)) {
1406
+ item.measures.x = isVertical ? 0 : snapped ? actualEndSnippedPosition - size : pos;
1407
+ item.measures.y = isVertical ? snapped ? actualEndSnippedPosition - size : pos : 0;
1408
+ nextEndSticky = item;
1409
+ nextEndSticky.config.zIndex = '3';
1410
+ nextEndSticky.config.snapped = snapped;
1411
+ nextEndSticky.measures.delta = isVertical ? (item.measures.y - scrollSize) : (item.measures.x - scrollSize);
1412
+ }
1413
+ displayItems.push(item);
1414
+ }
1415
+ renderItems -= 1;
1416
+ pos += size;
1417
+ i++;
1418
+ }
1419
+ const axis = isVertical ? Y_PROP_NAME : X_PROP_NAME;
1420
+ if (nextSticky && stickyItem && nextSticky.measures[axis] <= scrollSize + stickyItemSize) {
1421
+ if (nextSticky.measures[axis] > scrollSize) {
1422
+ stickyItem.measures[axis] = nextSticky.measures[axis] - stickyItemSize;
1423
+ stickyItem.config.snapped = nextSticky.config.snapped = false;
1424
+ stickyItem.config.snappedOut = true;
1425
+ stickyItem.config.sticky = 1;
1426
+ stickyItem.measures.delta = isVertical ? stickyItem.measures.y - scrollSize : stickyItem.measures.x - scrollSize;
1427
+ }
1428
+ else {
1429
+ nextSticky.config.snapped = true;
1430
+ nextSticky.measures.delta = isVertical ? nextSticky.measures.y - scrollSize : nextSticky.measures.x - scrollSize;
1431
+ }
1432
+ }
1433
+ if (nextEndSticky && endStickyItem && nextEndSticky.measures[axis] >= scrollSize + boundsSize - endStickyItemSize - nextEndSticky.measures[sizeProperty]) {
1434
+ if (nextEndSticky.measures[axis] < scrollSize + boundsSize - endStickyItemSize) {
1435
+ endStickyItem.measures[axis] = nextEndSticky.measures[axis] + nextEndSticky.measures[sizeProperty];
1436
+ endStickyItem.config.snapped = nextEndSticky.config.snapped = false;
1437
+ endStickyItem.config.snappedOut = true;
1438
+ endStickyItem.config.sticky = 2;
1439
+ endStickyItem.measures.delta = isVertical ? endStickyItem.measures.y - scrollSize : endStickyItem.measures.x - scrollSize;
1440
+ }
1441
+ else {
1442
+ nextEndSticky.config.snapped = true;
1443
+ nextEndSticky.measures.delta = isVertical ? nextEndSticky.measures.y - scrollSize : nextEndSticky.measures.x - scrollSize;
1444
+ }
1445
+ }
1446
+ }
1447
+ return displayItems;
1448
+ }
1449
+ /**
1450
+ * tracking by propName
1451
+ */
1452
+ track() {
1453
+ if (!this._items || !this._displayComponents) {
1454
+ return;
1455
+ }
1456
+ this._tracker.track(this._items, this._displayComponents, this._snapedDisplayComponent, this.scrollDirection);
1457
+ }
1458
+ setDisplayObjectIndexMapById(v) {
1459
+ this._tracker.displayObjectIndexMapById = v;
1460
+ }
1461
+ untrackComponentByIdProperty(component) {
1462
+ this._tracker.untrackComponentByIdProperty(component);
1463
+ }
1464
+ getItemBounds(id) {
1465
+ if (this.has(id)) {
1466
+ return this.get(id);
1467
+ }
1468
+ return undefined;
1469
+ }
1470
+ cacheElements() {
1471
+ if (!this._displayComponents) {
1472
+ return;
1473
+ }
1474
+ for (let i = 0, l = this._displayComponents.length; i < l; i++) {
1475
+ const component = this._displayComponents[i], itemId = component.instance.itemId;
1476
+ if (itemId === undefined) {
1477
+ continue;
1478
+ }
1479
+ const bounds = component.instance.getBounds();
1480
+ this.set(itemId, bounds);
1481
+ }
1482
+ }
1483
+ dispose() {
1484
+ super.dispose();
1485
+ this.disposeClearBufferSizeTimer();
1486
+ if (this._tracker) {
1487
+ this._tracker.dispose();
1488
+ }
1489
+ }
1490
+ }
1491
+
1492
+ /**
1493
+ * Base disposable component
1494
+ * @link https://github.com/DjonnyX/ng-virtual-list/blob/15.x/projects/ng-virtual-list/src/lib/utils/disposableComponent.ts
1495
+ * @author Evgenii Grebennikov
1496
+ * @email djonnyx@gmail.com
1497
+ */
1498
+ class DisposableComponent {
1499
+ constructor() {
1500
+ this._$unsubscribe = new Subject();
1501
+ }
1502
+ ngOnDestroy() {
1503
+ if (this._$unsubscribe) {
1504
+ this._$unsubscribe.next();
1505
+ this._$unsubscribe.complete();
1506
+ }
1507
+ }
1508
+ }
1509
+ DisposableComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: DisposableComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
1510
+ DisposableComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "15.2.10", type: DisposableComponent, selector: "ng-component", ngImport: i0, template: ``, isInline: true });
1511
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: DisposableComponent, decorators: [{
1512
+ type: Component,
1513
+ args: [{
1514
+ template: ``,
1515
+ }]
1516
+ }] });
1517
+
1518
+ const ADVANCED_PATTERNS = [SnappingMethods.ADVANCED, 'advanced'], DEFAULT_PATTERN = [SnappingMethods.NORMAL, 'normal'];
1519
+ const isSnappingMethodAdvenced = (method) => {
1520
+ return ADVANCED_PATTERNS.includes(method);
1521
+ };
1522
+ const isSnappingMethodDefault = (method) => {
1523
+ return DEFAULT_PATTERN.includes(method);
1524
+ };
1525
+
1526
+ const IS_FIREFOX = navigator.userAgent.toLowerCase().includes('firefox');
1527
+ const FIREFOX_SCROLLBAR_OVERLAP_SIZE = 12;
1528
+
1529
+ const HORIZONTAL_ALIASES = [Directions.HORIZONTAL, 'horizontal'], VERTICAL_ALIASES = [Directions.VERTICAL, 'vertical'];
1530
+ /**
1531
+ * Determines the axis membership of a virtual list
1532
+ * @link https://github.com/DjonnyX/ng-virtual-list/blob/15.x/projects/ng-virtual-list/src/lib/utils/isDirection.ts
1533
+ * @author Evgenii Grebennikov
1534
+ * @email djonnyx@gmail.com
1535
+ */
1536
+ const isDirection = (src, expected) => {
1537
+ if (HORIZONTAL_ALIASES.includes(expected)) {
1538
+ return HORIZONTAL_ALIASES.includes(src);
1539
+ }
1540
+ return VERTICAL_ALIASES.includes(src);
1541
+ };
1542
+
1543
+ /**
1544
+ * Virtual list component.
1545
+ * Maximum performance for extremely large lists.
1546
+ * It is based on algorithms for virtualization of screen objects.
1547
+ * @link https://github.com/DjonnyX/ng-virtual-list/blob/15.x/projects/ng-virtual-list/src/lib/ng-virtual-list.component.ts
1548
+ * @author Evgenii Grebennikov
1549
+ * @email djonnyx@gmail.com
1550
+ */
1551
+ class NgVirtualListComponent extends DisposableComponent {
1552
+ /**
1553
+ * Readonly. Returns the unique identifier of the component.
1554
+ */
1555
+ get id() { return this._id; }
1556
+ /**
1557
+ * Collection of list items.
1558
+ */
1559
+ set items(v) {
1560
+ if (this._$items.getValue() === v) {
1561
+ return;
1562
+ }
1563
+ const transformedValue = this._itemsTransform(v);
1564
+ this._$items.next(transformedValue);
1565
+ this._cdr.markForCheck();
1566
+ }
1567
+ ;
1568
+ get items() { return this._$items.getValue(); }
1569
+ /**
1570
+ * Determines whether elements will snap. Default value is "true".
1571
+ */
1572
+ set snap(v) {
1573
+ if (this._$snap.getValue() === v) {
1574
+ return;
1575
+ }
1576
+ this._$snap.next(v);
1577
+ this._cdr.markForCheck();
1578
+ }
1579
+ ;
1580
+ get snap() { return this._$snap.getValue(); }
1581
+ /**
1582
+ * Experimental!
1583
+ * Enables buffer optimization.
1584
+ * Can only be used if items in the collection are not added or updated. Otherwise, artifacts in the form of twitching of the scroll area are possible.
1585
+ * Works only if the property dynamic = true
1586
+ */
1587
+ set enabledBufferOptimization(v) {
1588
+ if (this._$enabledBufferOptimization.getValue() === v) {
1589
+ return;
1590
+ }
1591
+ this._$enabledBufferOptimization.next(v);
1592
+ this._cdr.markForCheck();
1593
+ }
1594
+ ;
1595
+ get enabledBufferOptimization() { return this._$enabledBufferOptimization.getValue(); }
1596
+ /**
1597
+ * Rendering element template.
1598
+ */
1599
+ set itemRenderer(v) {
1600
+ if (this._$itemRenderer.getValue() === v) {
1601
+ return;
1602
+ }
1603
+ this._$itemRenderer.next(v);
1604
+ this._cdr.markForCheck();
1605
+ }
1606
+ ;
1607
+ get itemRenderer() { return this._$itemRenderer.getValue(); }
1608
+ /**
1609
+ * Dictionary zIndex by id of the list element. If the value is not set or equal to 0,
1610
+ * then a simple element is displayed, if the value is greater than 0, then the sticky position mode is enabled for the element.
1611
+ */
1612
+ set stickyMap(v) {
1613
+ if (this._$stickyMap.getValue() === v) {
1614
+ return;
1615
+ }
1616
+ this._$stickyMap.next(v);
1617
+ this._cdr.markForCheck();
1618
+ }
1619
+ ;
1620
+ get stickyMap() { return this._$stickyMap.getValue(); }
1621
+ /**
1622
+ * If direction = 'vertical', then the height of a typical element. If direction = 'horizontal', then the width of a typical element.
1623
+ * Ignored if the dynamicSize property is true.
1624
+ */
1625
+ set itemSize(v) {
1626
+ if (this._$itemSize.getValue() === v) {
1627
+ return;
1628
+ }
1629
+ this._$itemSize.next(this._itemSizeOptions(v));
1630
+ this._cdr.markForCheck();
1631
+ }
1632
+ ;
1633
+ get itemSize() { return this._$itemSize.getValue(); }
1634
+ /**
1635
+ * If true then the items in the list can have different sizes and the itemSize property is ignored.
1636
+ * If false then the items in the list have a fixed size specified by the itemSize property. The default value is false.
1637
+ */
1638
+ set dynamicSize(v) {
1639
+ if (this._$dynamicSize.getValue() === v) {
1640
+ return;
1641
+ }
1642
+ this._$dynamicSize.next(v);
1643
+ this._cdr.markForCheck();
1644
+ }
1645
+ ;
1646
+ get dynamicSize() { return this._$dynamicSize.getValue(); }
1647
+ /**
1648
+ * Determines the direction in which elements are placed. Default value is "vertical".
1649
+ */
1650
+ set direction(v) {
1651
+ if (this._$direction.getValue() === v) {
1652
+ return;
1653
+ }
1654
+ this._$direction.next(v);
1655
+ this._cdr.markForCheck();
1656
+ }
1657
+ ;
1658
+ get direction() { return this._$direction.getValue(); }
1659
+ /**
1660
+ * @deprecated "itemOffset" parameter is deprecated. Use "bufferSize" and "maxBufferSize".
1661
+ */
1662
+ set itemsOffset(v) {
1663
+ throw Error('"itemOffset" parameter is deprecated. Use "bufferSize" and "maxBufferSize".');
1664
+ }
1665
+ ;
1666
+ /**
1667
+ * Number of elements outside the scope of visibility. Default value is 2.
1668
+ */
1669
+ set bufferSize(v) {
1670
+ if (this._$bufferSize.getValue() === v) {
1671
+ return;
1672
+ }
1673
+ this._$bufferSize.next(v);
1674
+ }
1675
+ ;
1676
+ get bufferSize() { return this._$bufferSize.getValue(); }
1677
+ /**
1678
+ * Maximum number of elements outside the scope of visibility. Default value is 100.
1679
+ * If maxBufferSize is set to be greater than bufferSize, then adaptive buffer mode is enabled.
1680
+ * The greater the scroll size, the more elements are allocated for rendering.
1681
+ */
1682
+ set maxBufferSize(v) {
1683
+ const val = this._maxBufferSizeTransform(v);
1684
+ if (this._$maxBufferSize.getValue() === val) {
1685
+ return;
1686
+ }
1687
+ this._$maxBufferSize.next(val);
1688
+ }
1689
+ ;
1690
+ get maxBufferSize() { return this._$maxBufferSize.getValue(); }
1691
+ /**
1692
+ * The name of the property by which tracking is performed
1693
+ */
1694
+ set trackBy(v) {
1695
+ if (this._$trackBy.getValue() === v) {
1696
+ return;
1697
+ }
1698
+ this._$trackBy.next(v);
1699
+ }
1700
+ ;
1701
+ get trackBy() { return this._$trackBy.getValue(); }
1702
+ /**
1703
+ * Snapping method.
1704
+ * 'default' - Normal group rendering.
1705
+ * 'advanced' - The group is rendered on a transparent background. List items below the group are not rendered.
1706
+ */
1707
+ set snappingMethod(v) {
1708
+ if (this._$snappingMethod.getValue() === v) {
1709
+ return;
1710
+ }
1711
+ this._$snappingMethod.next(v);
1712
+ }
1713
+ ;
1714
+ get snappingMethod() { return this._$snappingMethod.getValue(); }
1715
+ get isSnappingMethodAdvanced() { return this._isSnappingMethodAdvanced; }
1716
+ get $cacheVersion() { return this._$cacheVersion.asObservable(); }
1717
+ constructor(_cdr, _elementRef) {
1718
+ super();
1719
+ this._cdr = _cdr;
1720
+ this._elementRef = _elementRef;
1721
+ this._id = NgVirtualListComponent.__nextId;
1722
+ /**
1723
+ * Fires when the list has been scrolled.
1724
+ */
1725
+ this.onScroll = new EventEmitter$1();
1726
+ /**
1727
+ * Fires when the list has completed scrolling.
1728
+ */
1729
+ this.onScrollEnd = new EventEmitter$1();
1730
+ this._$items = new BehaviorSubject(undefined);
1731
+ this.$items = this._$items.asObservable();
1732
+ this._itemsTransform = (v) => {
1733
+ this._trackBox.resetCollection(v, this._$itemSize.getValue());
1734
+ return v;
1735
+ };
1736
+ this._$snap = new BehaviorSubject(DEFAULT_SNAP);
1737
+ this.$snap = this._$snap.asObservable();
1738
+ this._$enabledBufferOptimization = new BehaviorSubject(DEFAULT_ENABLED_BUFFER_OPTIMIZATION);
1739
+ this.$enabledBufferOptimization = this._$enabledBufferOptimization.asObservable();
1740
+ this._$itemRenderer = new BehaviorSubject(undefined);
1741
+ this.$itemRenderer = this._$itemRenderer.asObservable();
1742
+ this._$renderer = new BehaviorSubject(undefined);
1743
+ this._$stickyMap = new BehaviorSubject({});
1744
+ this.$stickyMap = this._$stickyMap.asObservable();
1745
+ this._itemSizeOptions = (v) => {
1746
+ if (v === undefined) {
1747
+ return DEFAULT_ITEM_SIZE;
1748
+ }
1749
+ const val = Number(v);
1750
+ return Number.isNaN(val) || val <= 0 ? DEFAULT_ITEM_SIZE : val;
1751
+ };
1752
+ this._$itemSize = new BehaviorSubject(DEFAULT_ITEM_SIZE);
1753
+ this.$itemSize = this._$itemSize.asObservable();
1754
+ this._$dynamicSize = new BehaviorSubject(DEFAULT_DYNAMIC_SIZE);
1755
+ this.$dynamicSize = this._$dynamicSize.asObservable();
1756
+ this._$direction = new BehaviorSubject(DEFAULT_DIRECTION);
1757
+ this.$direction = this._$direction.asObservable();
1758
+ this._$bufferSize = new BehaviorSubject(DEFAULT_BUFFER_SIZE);
1759
+ this.$bufferSize = this._$bufferSize.asObservable();
1760
+ this._maxBufferSizeTransform = (v) => {
1761
+ const bufferSize = this._$bufferSize.getValue();
1762
+ if (v === undefined || v <= bufferSize) {
1763
+ return bufferSize;
1764
+ }
1765
+ return v;
1766
+ };
1767
+ this._$maxBufferSize = new BehaviorSubject(DEFAULT_MAX_BUFFER_SIZE);
1768
+ this.$maxBufferSize = this._$maxBufferSize.asObservable();
1769
+ this._$trackBy = new BehaviorSubject(TRACK_BY_PROPERTY_NAME);
1770
+ this.$trackBy = this._$trackBy.asObservable();
1771
+ this._isVertical = this.getIsVertical();
1772
+ this._$snappingMethod = new BehaviorSubject(DEFAULT_SNAPPING_METHOD);
1773
+ this.$snappingMethod = this._$snappingMethod.asObservable();
1774
+ this._isSnappingMethodAdvanced = this.getIsSnappingMethodAdvanced();
1775
+ this._displayComponents = [];
1776
+ this._$bounds = new BehaviorSubject(null);
1777
+ this._$scrollSize = new BehaviorSubject(0);
1778
+ this._resizeObserver = null;
1779
+ this._resizeSnappedComponentHandler = () => {
1780
+ const list = this._list, container = this._container, snappedComponent = this._snapedDisplayComponent?.instance;
1781
+ if (list && container && snappedComponent) {
1782
+ const isVertical = this._isVertical, listBounds = list.nativeElement.getBoundingClientRect(), listElement = list?.nativeElement, { width: lWidth, height: lHeight } = listElement?.getBoundingClientRect() ?? { width: 0, height: 0 }, { width, height } = this._$bounds.getValue() ?? { width: 0, height: 0 }, isScrollable = isVertical ? container.nativeElement.scrollHeight > 0 : container.nativeElement.scrollWidth > 0;
1783
+ let scrollBarSize = isVertical ? width - lWidth : height - lHeight, isScrollBarOverlap = true, overlapScrollBarSize = 0;
1784
+ if (scrollBarSize === 0 && isScrollable) {
1785
+ isScrollBarOverlap = true;
1786
+ }
1787
+ if (isScrollBarOverlap && IS_FIREFOX) {
1788
+ scrollBarSize = overlapScrollBarSize = FIREFOX_SCROLLBAR_OVERLAP_SIZE;
1789
+ }
1790
+ const { width: sWidth, height: sHeight } = snappedComponent.getBounds() ?? { width: 0, height: 0 };
1791
+ snappedComponent.element.style.clipPath = `path("M 0 0 L 0 ${sHeight} L ${sWidth - overlapScrollBarSize} ${sHeight} L ${sWidth - overlapScrollBarSize} 0 Z")`;
1792
+ snappedComponent.regularLength = `${isVertical ? listBounds.width : listBounds.height}${PX}`;
1793
+ const containerElement = container.nativeElement, delta = snappedComponent.item?.measures.delta ?? 0;
1794
+ let left, right, top, bottom;
1795
+ if (isVertical) {
1796
+ left = 0;
1797
+ right = width - scrollBarSize;
1798
+ top = sHeight;
1799
+ bottom = height;
1800
+ containerElement.style.clipPath = `path("M 0 ${top + delta} L 0 ${height} L ${width} ${height} L ${width} 0 L ${right} 0 L ${right} ${top + delta} Z")`;
1801
+ }
1802
+ else {
1803
+ left = sWidth;
1804
+ right = width;
1805
+ top = 0;
1806
+ bottom = height - scrollBarSize;
1807
+ containerElement.style.clipPath = `path("M ${left + delta} 0 L ${left + delta} ${bottom} L 0 ${bottom} L 0 ${height} L ${width} ${height} L ${width} 0 Z")`;
1808
+ }
1809
+ }
1810
+ };
1811
+ this._resizeSnappedObserver = null;
1812
+ this._onResizeHandler = () => {
1813
+ const bounds = this._container?.nativeElement?.getBoundingClientRect();
1814
+ if (bounds) {
1815
+ this._$bounds.next({ width: bounds.width, height: bounds.height });
1816
+ }
1817
+ else {
1818
+ this._$bounds.next({ width: DEFAULT_LIST_SIZE, height: DEFAULT_LIST_SIZE });
1819
+ }
1820
+ if (this._isSnappingMethodAdvanced) {
1821
+ this.updateRegularRenderer();
1822
+ }
1823
+ };
1824
+ this._onScrollHandler = (e) => {
1825
+ this.clearScrollToRepeatExecutionTimeout();
1826
+ const container = this._container?.nativeElement;
1827
+ if (container) {
1828
+ const scrollSize = (this._isVertical ? container.scrollTop : container.scrollLeft);
1829
+ this._$scrollSize.next(scrollSize);
1830
+ }
1831
+ };
1832
+ this._$initialized = new BehaviorSubject(false);
1833
+ /**
1834
+ * Base class of the element component
1835
+ */
1836
+ this._itemComponentClass = NgVirtualListItemComponent;
1837
+ /**
1838
+ * Base class trackBox
1839
+ */
1840
+ this._trackBoxClass = TrackBox;
1841
+ /**
1842
+ * Dictionary of element sizes by their id
1843
+ */
1844
+ this._trackBox = new this._trackBoxClass(this.trackBy);
1845
+ this._onTrackBoxChangeHandler = (v) => {
1846
+ this._$cacheVersion.next(v);
1847
+ };
1848
+ this._$cacheVersion = new BehaviorSubject(-1);
1849
+ this._componentsResizeObserver = new ResizeObserver(() => {
1850
+ this._trackBox.changes();
1851
+ });
1852
+ this._onContainerScrollHandler = (e) => {
1853
+ const containerEl = this._container;
1854
+ if (containerEl) {
1855
+ const scrollSize = (this._isVertical ? containerEl.nativeElement.scrollTop : containerEl.nativeElement.scrollLeft);
1856
+ this._trackBox.deltaDirection = this._$scrollSize.getValue() > scrollSize ? -1 : this._$scrollSize.getValue() < scrollSize ? 1 : 0;
1857
+ const event = new ScrollEvent({
1858
+ direction: this._trackBox.scrollDirection, container: containerEl.nativeElement,
1859
+ list: this._list.nativeElement, delta: this._trackBox.delta,
1860
+ scrollDelta: this._trackBox.scrollDelta, isVertical: this._isVertical,
1861
+ });
1862
+ this.onScroll.emit(event);
1863
+ }
1864
+ };
1865
+ this._onContainerScrollEndHandler = (e) => {
1866
+ const containerEl = this._container;
1867
+ if (containerEl) {
1868
+ const scrollSize = (this._isVertical ? containerEl.nativeElement.scrollTop : containerEl.nativeElement.scrollLeft);
1869
+ this._trackBox.deltaDirection = this._$scrollSize.getValue() > scrollSize ? -1 : 0;
1870
+ const event = new ScrollEvent({
1871
+ direction: this._trackBox.scrollDirection, container: containerEl.nativeElement,
1872
+ list: this._list.nativeElement, delta: this._trackBox.delta,
1873
+ scrollDelta: this._trackBox.scrollDelta, isVertical: this._isVertical,
1874
+ });
1875
+ this.onScrollEnd.emit(event);
1876
+ }
1877
+ };
1878
+ NgVirtualListComponent.__nextId = NgVirtualListComponent.__nextId + 1 === Number.MAX_SAFE_INTEGER
1879
+ ? 0 : NgVirtualListComponent.__nextId + 1;
1880
+ this._id = NgVirtualListComponent.__nextId;
1881
+ this._$initialized = new BehaviorSubject(false);
1882
+ this.$initialized = this._$initialized.asObservable();
1883
+ this._trackBox.displayComponents = this._displayComponents;
1884
+ const $trackBy = this.$trackBy;
1885
+ $trackBy.pipe(takeUntil(this._$unsubscribe), tap(v => {
1886
+ this._trackBox.trackingPropertyName = v;
1887
+ })).subscribe();
1888
+ const $bounds = this._$bounds.asObservable().pipe(filter(b => !!b)), $items = this.$items.pipe(map(i => !i ? [] : i)), $scrollSize = this._$scrollSize.asObservable(), $itemSize = this.$itemSize.pipe(map(v => v <= 0 ? DEFAULT_ITEM_SIZE : v)), $bufferSize = this.$bufferSize.pipe(map(v => v < 0 ? DEFAULT_BUFFER_SIZE : v)), $maxBufferSize = this.$maxBufferSize.pipe(map(v => v < 0 ? DEFAULT_MAX_BUFFER_SIZE : v)), $stickyMap = this.$stickyMap.pipe(map(v => !v ? {} : v)), $snap = this.$snap, $isVertical = this.$direction.pipe(map(v => this.getIsVertical(v || DEFAULT_DIRECTION))), $dynamicSize = this.$dynamicSize, $enabledBufferOptimization = this.$enabledBufferOptimization, $snappingMethod = this.$snappingMethod.pipe(map(v => this.getIsSnappingMethodAdvanced(v || DEFAULT_SNAPPING_METHOD))), $cacheVersion = this.$cacheVersion;
1889
+ $isVertical.pipe(takeUntil(this._$unsubscribe), tap(v => {
1890
+ this._isVertical = v;
1891
+ const el = this._elementRef.nativeElement;
1892
+ toggleClassName(el, v ? CLASS_LIST_VERTICAL : CLASS_LIST_HORIZONTAL, v ? CLASS_LIST_HORIZONTAL : CLASS_LIST_VERTICAL);
1893
+ })).subscribe();
1894
+ $snappingMethod.pipe(takeUntil(this._$unsubscribe), tap(v => {
1895
+ this._isSnappingMethodAdvanced = this._trackBox.isSnappingMethodAdvanced = v;
1896
+ })).subscribe();
1897
+ $dynamicSize.pipe(takeUntil(this._$unsubscribe), tap(dynamicSize => {
1898
+ this.listenCacheChangesIfNeed(dynamicSize);
1899
+ })).subscribe();
1900
+ combineLatest([this.$initialized, $bounds, $items, $stickyMap, $scrollSize, $itemSize,
1901
+ $bufferSize, $maxBufferSize, $snap, $isVertical, $dynamicSize, $enabledBufferOptimization, $cacheVersion,
1902
+ ]).pipe(takeUntil(this._$unsubscribe), distinctUntilChanged(), filter(([initialized]) => !!initialized), switchMap(([, bounds, items, stickyMap, scrollSize, itemSize, bufferSize, maxBufferSize, snap, isVertical, dynamicSize, enabledBufferOptimization, cacheVersion,]) => {
1903
+ let actualScrollSize = (this._isVertical ? this._container?.nativeElement.scrollTop ?? 0 : this._container?.nativeElement.scrollLeft) ?? 0;
1904
+ const { width, height } = bounds, opts = {
1905
+ bounds: { width, height }, dynamicSize, isVertical, itemSize,
1906
+ bufferSize, maxBufferSize, scrollSize: actualScrollSize, snap, enabledBufferOptimization,
1907
+ }, { displayItems, totalSize } = this._trackBox.updateCollection(items, stickyMap, opts);
1908
+ this.resetBoundsSize(isVertical, totalSize);
1909
+ this.createDisplayComponentsIfNeed(displayItems);
1910
+ this.tracking();
1911
+ if (this._isSnappingMethodAdvanced) {
1912
+ this.updateRegularRenderer();
1913
+ }
1914
+ const container = this._container;
1915
+ if (container) {
1916
+ const delta = this._trackBox.delta;
1917
+ actualScrollSize = actualScrollSize + delta;
1918
+ this._trackBox.clearDelta();
1919
+ if (scrollSize !== actualScrollSize) {
1920
+ const params = {
1921
+ [this._isVertical ? TOP_PROP_NAME : LEFT_PROP_NAME]: actualScrollSize,
1922
+ behavior: BEHAVIOR_INSTANT
1923
+ };
1924
+ container.nativeElement.scrollTo(params);
1925
+ }
1926
+ }
1927
+ return of(displayItems);
1928
+ })).subscribe();
1929
+ const $itemRenderer = this.$itemRenderer;
1930
+ $itemRenderer.pipe(takeUntil(this._$unsubscribe), distinctUntilChanged(), filter(v => !!v), tap(v => {
1931
+ this._$renderer.next(v);
1932
+ })).subscribe();
1933
+ }
1934
+ /** @internal */
1935
+ ngOnInit() {
1936
+ this.onInit();
1937
+ }
1938
+ onInit() {
1939
+ this._$initialized.next(true);
1940
+ }
1941
+ listenCacheChangesIfNeed(value) {
1942
+ if (value) {
1943
+ if (!this._trackBox.hasEventListener(TRACK_BOX_CHANGE_EVENT_NAME, this._onTrackBoxChangeHandler)) {
1944
+ this._trackBox.addEventListener(TRACK_BOX_CHANGE_EVENT_NAME, this._onTrackBoxChangeHandler);
1945
+ }
1946
+ }
1947
+ else {
1948
+ if (this._trackBox.hasEventListener(TRACK_BOX_CHANGE_EVENT_NAME, this._onTrackBoxChangeHandler)) {
1949
+ this._trackBox.removeEventListener(TRACK_BOX_CHANGE_EVENT_NAME, this._onTrackBoxChangeHandler);
1950
+ }
1951
+ }
1952
+ }
1953
+ getIsSnappingMethodAdvanced(m) {
1954
+ const method = m || this._$snappingMethod.getValue();
1955
+ return isSnappingMethodAdvenced(method);
1956
+ }
1957
+ getIsVertical(d) {
1958
+ const dir = d || this.direction;
1959
+ return isDirection(dir, Directions.VERTICAL);
1960
+ }
1961
+ createDisplayComponentsIfNeed(displayItems) {
1962
+ if (!displayItems || !this._listContainerRef) {
1963
+ this._trackBox.setDisplayObjectIndexMapById({});
1964
+ return;
1965
+ }
1966
+ if (this._isSnappingMethodAdvanced && this.snap) {
1967
+ if (!this._snapedDisplayComponent && this._snapContainerRef) {
1968
+ const comp = this._snapContainerRef.createComponent(this._itemComponentClass);
1969
+ comp.instance.regular = true;
1970
+ this._snapedDisplayComponent = comp;
1971
+ this._trackBox.snapedDisplayComponent = this._snapedDisplayComponent;
1972
+ this._resizeSnappedObserver = new ResizeObserver(this._resizeSnappedComponentHandler);
1973
+ this._resizeSnappedObserver.observe(comp.instance.element);
1974
+ }
1975
+ }
1976
+ this._trackBox.items = displayItems;
1977
+ const _listContainerRef = this._listContainerRef;
1978
+ const maxLength = displayItems.length, components = this._displayComponents;
1979
+ while (components.length < maxLength) {
1980
+ if (_listContainerRef) {
1981
+ const comp = _listContainerRef.createComponent(this._itemComponentClass);
1982
+ components.push(comp);
1983
+ this._componentsResizeObserver.observe(comp.instance.element);
1984
+ }
1985
+ }
1986
+ this.resetRenderers();
1987
+ }
1988
+ updateRegularRenderer() {
1989
+ this._resizeSnappedComponentHandler();
1990
+ }
1991
+ resetRenderers(itemRenderer) {
1992
+ const doMap = {};
1993
+ for (let i = 0, l = this._displayComponents.length; i < l; i++) {
1994
+ const item = this._displayComponents[i];
1995
+ item.instance.renderer = itemRenderer || this.itemRenderer;
1996
+ doMap[item.instance.id] = i;
1997
+ }
1998
+ if (this._isSnappingMethodAdvanced && this.snap && this._snapedDisplayComponent && this._snapContainerRef) {
1999
+ const comp = this._snapedDisplayComponent;
2000
+ comp.instance.renderer = itemRenderer || this.itemRenderer;
2001
+ }
2002
+ this._trackBox.setDisplayObjectIndexMapById(doMap);
2003
+ }
2004
+ /**
2005
+ * Tracking by id
2006
+ */
2007
+ tracking() {
2008
+ this._trackBox.track();
2009
+ }
2010
+ resetBoundsSize(isVertical, totalSize) {
2011
+ const l = this._list;
2012
+ if (l) {
2013
+ l.nativeElement.style[isVertical ? HEIGHT_PROP_NAME : WIDTH_PROP_NAME] = `${totalSize}${PX}`;
2014
+ }
2015
+ }
2016
+ /**
2017
+ * Returns the bounds of an element with a given id
2018
+ */
2019
+ getItemBounds(id) {
2020
+ return this._trackBox.getItemBounds(id);
2021
+ }
2022
+ /**
2023
+ * The method scrolls the list to the element with the given id and returns the value of the scrolled area.
2024
+ * Behavior accepts the values ​​"auto", "instant" and "smooth".
2025
+ */
2026
+ scrollTo(id, behavior = BEHAVIOR_AUTO) {
2027
+ this.scrollToExecutor(id, behavior);
2028
+ }
2029
+ clearScrollToRepeatExecutionTimeout() {
2030
+ clearTimeout(this._scrollToRepeatExecutionTimeout);
2031
+ }
2032
+ scrollToExecutor(id, behavior, iteration = 0, isLastIteration = false) {
2033
+ const items = this.items;
2034
+ if (!items || !items.length) {
2035
+ return;
2036
+ }
2037
+ const dynamicSize = this.dynamicSize, container = this._container, itemSize = this.itemSize;
2038
+ if (container) {
2039
+ this.clearScrollToRepeatExecutionTimeout();
2040
+ if (dynamicSize) {
2041
+ if (container) {
2042
+ container.nativeElement.removeEventListener(SCROLL, this._onScrollHandler);
2043
+ }
2044
+ const { width, height } = this._$bounds.getValue() || { width: 0, height: 0 }, stickyMap = this.stickyMap, items = this.items, isVertical = this._isVertical, delta = this._trackBox.delta, opts = {
2045
+ bounds: { width, height }, collection: items, dynamicSize, isVertical: this._isVertical, itemSize,
2046
+ bufferSize: this.bufferSize, maxBufferSize: this.maxBufferSize, scrollSize: (isVertical ? container.nativeElement.scrollTop : container.nativeElement.scrollLeft) + delta,
2047
+ snap: this.snap, fromItemId: id, enabledBufferOptimization: this.enabledBufferOptimization,
2048
+ }, scrollSize = this._trackBox.getItemPosition(id, stickyMap, opts), params = { [isVertical ? TOP_PROP_NAME : LEFT_PROP_NAME]: scrollSize, behavior };
2049
+ if (scrollSize === -1) {
2050
+ container.nativeElement.addEventListener(SCROLL, this._onScrollHandler);
2051
+ return;
2052
+ }
2053
+ this._trackBox.clearDelta();
2054
+ if (container) {
2055
+ const { displayItems, totalSize } = this._trackBox.updateCollection(items, stickyMap, {
2056
+ ...opts, scrollSize, fromItemId: isLastIteration ? undefined : id,
2057
+ }), delta = this._trackBox.delta;
2058
+ this._trackBox.clearDelta();
2059
+ let actualScrollSize = scrollSize + delta;
2060
+ this.resetBoundsSize(isVertical, totalSize);
2061
+ this.createDisplayComponentsIfNeed(displayItems);
2062
+ this.tracking();
2063
+ const _scrollSize = this._trackBox.getItemPosition(id, stickyMap, { ...opts, scrollSize: actualScrollSize, fromItemId: id });
2064
+ if (_scrollSize === -1) {
2065
+ container.nativeElement.addEventListener(SCROLL, this._onScrollHandler);
2066
+ return;
2067
+ }
2068
+ const notChanged = actualScrollSize === _scrollSize;
2069
+ if (!notChanged || iteration < MAX_SCROLL_TO_ITERATIONS) {
2070
+ this.clearScrollToRepeatExecutionTimeout();
2071
+ this._scrollToRepeatExecutionTimeout = setTimeout(() => {
2072
+ this.scrollToExecutor(id, BEHAVIOR_INSTANT, iteration + 1, notChanged);
2073
+ });
2074
+ }
2075
+ else {
2076
+ this._$scrollSize.next(actualScrollSize);
2077
+ container.nativeElement.addEventListener(SCROLL, this._onScrollHandler);
2078
+ }
2079
+ }
2080
+ container.nativeElement.scrollTo(params);
2081
+ this._$scrollSize.next(scrollSize);
2082
+ }
2083
+ else {
2084
+ const index = items.findIndex(item => item.id === id);
2085
+ if (index > -1) {
2086
+ const scrollSize = index * this.itemSize;
2087
+ const params = { [this._isVertical ? TOP_PROP_NAME : LEFT_PROP_NAME]: scrollSize, behavior };
2088
+ container.nativeElement.scrollTo(params);
2089
+ }
2090
+ }
2091
+ }
2092
+ }
2093
+ /**
2094
+ * Scrolls the scroll area to the desired element with the specified ID.
2095
+ */
2096
+ scrollToEnd(behavior = BEHAVIOR_INSTANT) {
2097
+ const items = this.items, latItem = items[items.length > 0 ? items.length - 1 : 0];
2098
+ this.scrollTo(latItem.id, behavior);
2099
+ }
2100
+ /** @internal */
2101
+ ngAfterViewInit() {
2102
+ this.afterViewInit();
2103
+ }
2104
+ afterViewInit() {
2105
+ const containerEl = this._container;
2106
+ if (containerEl) {
2107
+ // for direction calculation
2108
+ containerEl.nativeElement.addEventListener(SCROLL, this._onContainerScrollHandler);
2109
+ containerEl.nativeElement.addEventListener(SCROLL_END, this._onContainerScrollEndHandler);
2110
+ containerEl.nativeElement.addEventListener(SCROLL, this._onScrollHandler);
2111
+ this._resizeObserver = new ResizeObserver(this._onResizeHandler);
2112
+ this._resizeObserver.observe(containerEl.nativeElement);
2113
+ this._onResizeHandler();
2114
+ }
2115
+ }
2116
+ /** @internal */
2117
+ ngOnDestroy() {
2118
+ super.ngOnDestroy();
2119
+ this.dispose();
2120
+ }
2121
+ dispose() {
2122
+ this.clearScrollToRepeatExecutionTimeout();
2123
+ if (this._trackBox) {
2124
+ this._trackBox.dispose();
2125
+ }
2126
+ if (this._componentsResizeObserver) {
2127
+ this._componentsResizeObserver.disconnect();
2128
+ }
2129
+ if (this._resizeObserver) {
2130
+ this._resizeObserver.disconnect();
2131
+ }
2132
+ if (this._resizeSnappedObserver) {
2133
+ this._resizeSnappedObserver.disconnect();
2134
+ }
2135
+ const containerEl = this._container;
2136
+ if (containerEl) {
2137
+ containerEl.nativeElement.removeEventListener(SCROLL, this._onScrollHandler);
2138
+ containerEl.nativeElement.removeEventListener(SCROLL, this._onContainerScrollHandler);
2139
+ containerEl.nativeElement.removeEventListener(SCROLL_END, this._onContainerScrollEndHandler);
2140
+ }
2141
+ if (this._snapedDisplayComponent) {
2142
+ this._snapedDisplayComponent.destroy();
2143
+ }
2144
+ if (this._displayComponents) {
2145
+ while (this._displayComponents.length > 0) {
2146
+ const comp = this._displayComponents.pop();
2147
+ comp?.destroy();
2148
+ }
2149
+ }
2150
+ }
2151
+ }
2152
+ NgVirtualListComponent.__nextId = 0;
2153
+ NgVirtualListComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: NgVirtualListComponent, deps: [{ token: i0.ChangeDetectorRef }, { token: i0.ElementRef }], target: i0.ɵɵFactoryTarget.Component });
2154
+ NgVirtualListComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "15.2.10", type: NgVirtualListComponent, selector: "ng-virtual-list", inputs: { items: "items", snap: "snap", enabledBufferOptimization: "enabledBufferOptimization", itemRenderer: "itemRenderer", stickyMap: "stickyMap", itemSize: "itemSize", dynamicSize: "dynamicSize", direction: "direction", itemsOffset: "itemsOffset", bufferSize: "bufferSize", maxBufferSize: "maxBufferSize", trackBy: "trackBy", snappingMethod: "snappingMethod" }, outputs: { onScroll: "onScroll", onScrollEnd: "onScrollEnd" }, viewQueries: [{ propertyName: "_listContainerRef", first: true, predicate: ["renderersContainer"], descendants: true, read: ViewContainerRef }, { propertyName: "_container", first: true, predicate: ["container"], descendants: true, read: (ElementRef) }, { propertyName: "_list", first: true, predicate: ["list"], descendants: true, read: (ElementRef) }, { propertyName: "_snapContainerRef", first: true, predicate: ["snapRendererContainer"], descendants: true, read: ViewContainerRef }, { propertyName: "_snappedContainer", first: true, predicate: ["snapped"], descendants: true, read: ViewContainerRef }], usesInheritance: true, ngImport: i0, template: "<div *ngIf=\"snap\" #snapped part=\"snapped-item\" class=\"ngvl__list-snapper\">\r\n <ng-container #snapRendererContainer></ng-container>\r\n</div>\r\n<div #container part=\"scroller\" class=\"ngvl__scroller\">\r\n <ul #list part=\"list\" class=\"ngvl__list\">\r\n <ng-container #renderersContainer></ng-container>\r\n </ul>\r\n</div>", styles: [":host{position:relative;display:block;width:400px;overflow:hidden}:host(.horizontal){height:48px}:host(.horizontal) .ngvl__list{display:inline-flex}:host(.horizontal) .ngvl__scroller{overflow:auto hidden}:host(.vertical) .ngvl__scroller{overflow:hidden auto}:host(.vertical){height:320px}.ngvl__scroller{overflow:auto;width:100%;height:100%}.ngvl__list-snapper{pointer-events:none;position:absolute;list-style:none;left:0;top:0;z-index:1}.ngvl__list{position:relative;list-style:none;padding:0;margin:0;width:100%;height:100%}\n"], dependencies: [{ kind: "directive", type: i1.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.ShadowDom });
2155
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: NgVirtualListComponent, decorators: [{
2156
+ type: Component,
2157
+ args: [{ selector: 'ng-virtual-list', changeDetection: ChangeDetectionStrategy.OnPush, encapsulation: ViewEncapsulation.ShadowDom, template: "<div *ngIf=\"snap\" #snapped part=\"snapped-item\" class=\"ngvl__list-snapper\">\r\n <ng-container #snapRendererContainer></ng-container>\r\n</div>\r\n<div #container part=\"scroller\" class=\"ngvl__scroller\">\r\n <ul #list part=\"list\" class=\"ngvl__list\">\r\n <ng-container #renderersContainer></ng-container>\r\n </ul>\r\n</div>", styles: [":host{position:relative;display:block;width:400px;overflow:hidden}:host(.horizontal){height:48px}:host(.horizontal) .ngvl__list{display:inline-flex}:host(.horizontal) .ngvl__scroller{overflow:auto hidden}:host(.vertical) .ngvl__scroller{overflow:hidden auto}:host(.vertical){height:320px}.ngvl__scroller{overflow:auto;width:100%;height:100%}.ngvl__list-snapper{pointer-events:none;position:absolute;list-style:none;left:0;top:0;z-index:1}.ngvl__list{position:relative;list-style:none;padding:0;margin:0;width:100%;height:100%}\n"] }]
2158
+ }], ctorParameters: function () { return [{ type: i0.ChangeDetectorRef }, { type: i0.ElementRef }]; }, propDecorators: { _listContainerRef: [{
2159
+ type: ViewChild,
2160
+ args: ['renderersContainer', { read: ViewContainerRef }]
2161
+ }], _container: [{
2162
+ type: ViewChild,
2163
+ args: ['container', { read: (ElementRef) }]
2164
+ }], _list: [{
2165
+ type: ViewChild,
2166
+ args: ['list', { read: (ElementRef) }]
2167
+ }], _snapContainerRef: [{
2168
+ type: ViewChild,
2169
+ args: ['snapRendererContainer', { read: ViewContainerRef }]
2170
+ }], _snappedContainer: [{
2171
+ type: ViewChild,
2172
+ args: ['snapped', { read: ViewContainerRef }]
2173
+ }], onScroll: [{
2174
+ type: Output
2175
+ }], onScrollEnd: [{
2176
+ type: Output
2177
+ }], items: [{
2178
+ type: Input
2179
+ }], snap: [{
2180
+ type: Input
2181
+ }], enabledBufferOptimization: [{
2182
+ type: Input
2183
+ }], itemRenderer: [{
2184
+ type: Input
2185
+ }], stickyMap: [{
2186
+ type: Input
2187
+ }], itemSize: [{
2188
+ type: Input
2189
+ }], dynamicSize: [{
2190
+ type: Input
2191
+ }], direction: [{
2192
+ type: Input
2193
+ }], itemsOffset: [{
2194
+ type: Input
2195
+ }], bufferSize: [{
2196
+ type: Input
2197
+ }], maxBufferSize: [{
2198
+ type: Input
2199
+ }], trackBy: [{
2200
+ type: Input
2201
+ }], snappingMethod: [{
2202
+ type: Input
2203
+ }] } });
2204
+
2205
+ class NgVirtualListModule {
2206
+ }
2207
+ NgVirtualListModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: NgVirtualListModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
2208
+ NgVirtualListModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.2.10", ngImport: i0, type: NgVirtualListModule, declarations: [NgVirtualListComponent, NgVirtualListItemComponent], imports: [CommonModule], exports: [NgVirtualListComponent] });
2209
+ NgVirtualListModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: NgVirtualListModule, imports: [CommonModule] });
2210
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: NgVirtualListModule, decorators: [{
2211
+ type: NgModule,
2212
+ args: [{
2213
+ declarations: [NgVirtualListComponent, NgVirtualListItemComponent],
2214
+ exports: [NgVirtualListComponent],
2215
+ imports: [CommonModule],
2216
+ schemas: [NO_ERRORS_SCHEMA],
2217
+ }]
2218
+ }] });
2219
+
2220
+ /*
2221
+ * Public API Surface of ng-virtual-list
2222
+ */
2223
+
2224
+ /**
2225
+ * Generated bundle index. Do not edit.
2226
+ */
2227
+
2228
+ export { Directions, NgVirtualListComponent, NgVirtualListItemComponent, NgVirtualListModule, SnappingMethods };
2229
+ //# sourceMappingURL=ng-virtual-list.mjs.map