primeng
Version:
PrimeNG is a premium UI library for Angular featuring a rich set of 90+ components, a theme designer, various theme alternatives such as Material, Bootstrap, Tailwind, premium templates and professional support. In addition, it integrates with PrimeBlock,
1 lines • 96.8 kB
Source Map (JSON)
{"version":3,"file":"primeng-scroller.mjs","sources":["../../src/scroller/style/scrollerstyle.ts","../../src/scroller/scroller.ts","../../src/scroller/primeng-scroller.ts"],"sourcesContent":["import { Injectable } from '@angular/core';\nimport { BaseStyle } from 'primeng/base';\n\nconst css = /*css*/ `\n.p-virtualscroller {\n position: relative;\n overflow: auto;\n contain: strict;\n transform: translateZ(0);\n will-change: scroll-position;\n outline: 0 none;\n}\n\n.p-virtualscroller-content {\n position: absolute;\n top: 0;\n left: 0;\n min-height: 100%;\n min-width: 100%;\n will-change: transform;\n}\n\n.p-virtualscroller-spacer {\n position: absolute;\n top: 0;\n left: 0;\n height: 1px;\n width: 1px;\n transform-origin: 0 0;\n pointer-events: none;\n}\n\n.p-virtualscroller-loader {\n position: sticky;\n top: 0;\n left: 0;\n width: 100%;\n height: 100%;\n background: dt('virtualscroller.loader.mask.background');\n color: dt('virtualscroller.loader.mask.color');\n}\n\n.p-virtualscroller-loader-mask {\n display: flex;\n align-items: center;\n justify-content: center;\n}\n\n.p-virtualscroller-loading-icon {\n font-size: dt('virtualscroller.loader.icon.size');\n width: dt('virtualscroller.loader.icon.size');\n height: dt('virtualscroller.loader.icon.size');\n}\n\n.p-virtualscroller-horizontal > .p-virtualscroller-content {\n display: flex;\n}\n\n.p-virtualscroller-inline .p-virtualscroller-content {\n position: static;\n}\n`;\n\nconst classes = {\n root: ({ instance }) => [\n 'p-virtualscroller',\n {\n 'p-virtualscroller-inline': instance.inline(),\n 'p-virtualscroller-both p-both-scroll': instance.both(),\n 'p-virtualscroller-horizontal p-horizontal-scroll': instance.horizontal()\n }\n ],\n content: 'p-virtualscroller-content',\n spacer: 'p-virtualscroller-spacer',\n loader: ({ instance }) => [\n 'p-virtualscroller-loader',\n {\n 'p-virtualscroller-loader-mask': !instance.loaderTemplate()\n }\n ],\n loadingIcon: 'p-virtualscroller-loading-icon'\n};\n\n@Injectable()\nexport class ScrollerStyle extends BaseStyle {\n name = 'virtualscroller';\n\n css = css;\n\n classes = classes;\n}\n\n/**\n *\n * VirtualScroller is a performant approach to handle huge data efficiently.\n *\n * [Live Demo](https://www.primeng.org/scroller/)\n *\n * @module scrollerstyle\n *\n */\nexport enum ScrollerClasses {\n /**\n * Class name of the root element\n */\n root = 'p-virtualscroller',\n /**\n * Class name of the content element\n */\n content = 'p-virtualscroller-content',\n /**\n * Class name of the spacer element\n */\n spacer = 'p-virtualscroller-spacer',\n /**\n * Class name of the loader element\n */\n loader = 'p-virtualscroller-loader',\n /**\n * Class name of the loading icon element\n */\n loadingIcon = 'p-virtualscroller-loading-icon'\n}\n\nexport interface ScrollerStyle extends BaseStyle {}\n","import { isPlatformBrowser, NgTemplateOutlet } from '@angular/common';\nimport { ChangeDetectionStrategy, Component, computed, contentChild, effect, ElementRef, inject, InjectionToken, input, NgModule, output, signal, TemplateRef, untracked, viewChild, ViewEncapsulation } from '@angular/core';\nimport { findSingle, getHeight, getWidth, isTouchDevice, isVisible } from '@primeuix/utils';\nimport { ScrollerOptions } from 'primeng/api';\nimport { BaseComponent, PARENT_INSTANCE } from 'primeng/basecomponent';\nimport { Bind } from 'primeng/bind';\nimport { Spinner as SpinnerIcon } from '@primeicons/angular/spinner';\nimport { VoidListener } from 'primeng/ts-helpers';\nimport {\n ScrollerContentTemplateContext,\n ScrollerItemTemplateContext,\n ScrollerLazyLoadEvent,\n ScrollerLoaderIconTemplateContext,\n ScrollerLoaderTemplateContext,\n ScrollerScrollEvent,\n ScrollerScrollIndexChangeEvent,\n ScrollerToType,\n VirtualScrollerPassThrough\n} from 'primeng/types/scroller';\nimport { ScrollerStyle } from './style/scrollerstyle';\nimport { CSSProperties } from 'primeng/types/shared';\n\nconst SCROLLER_INSTANCE = new InjectionToken<Scroller>('SCROLLER_INSTANCE');\n\n/**\n * Scroller is a performance-approach to handle huge data efficiently.\n * @group Components\n */\n@Component({\n selector: 'p-scroller, p-virtualscroller, p-virtual-scroller',\n imports: [NgTemplateOutlet, SpinnerIcon, Bind],\n standalone: true,\n template: `\n @if (!_disabled()) {\n <div #element [attr.id]=\"_id()\" [attr.tabindex]=\"_tabindex()\" [style]=\"_style()\" [class]=\"cn(cx('root'), _styleClass())\" (scroll)=\"onContainerScroll($event)\" [pBind]=\"ptm('root')\">\n @if (contentTemplate()) {\n <ng-container *ngTemplateOutlet=\"contentTemplate(); context: getContentTemplateContext()\"></ng-container>\n } @else {\n <div #content [class]=\"cn(cx('content'), contentStyleClass())\" [style]=\"contentStyle\" [pBind]=\"ptm('content')\">\n @for (item of loadedItems; track _trackBy() ? _trackBy()($index, item) : $index; let index = $index) {\n <ng-container *ngTemplateOutlet=\"itemTemplate(); context: getItemTemplateContext(item, index)\"></ng-container>\n }\n </div>\n }\n @if (_showSpacer()) {\n <div [class]=\"cx('spacer')\" [style]=\"spacerStyle\" [pBind]=\"ptm('spacer')\"></div>\n }\n @if (!_loaderDisabled() && _showLoader() && d_loading) {\n <div [class]=\"cx('loader')\" [pBind]=\"ptm('loader')\">\n @if (loaderTemplate()) {\n @for (item of loaderArr; track $index; let index = $index) {\n <ng-container *ngTemplateOutlet=\"loaderTemplate(); context: getLoaderTemplateContext(index)\"></ng-container>\n }\n } @else {\n @if (loaderIconTemplate()) {\n <ng-container *ngTemplateOutlet=\"loaderIconTemplate(); context: loaderIconContext\"></ng-container>\n } @else {\n <svg data-p-icon=\"spinner\" [class]=\"cx('loadingIcon')\" [spin]=\"true\" [pBind]=\"ptm('loadingIcon')\" />\n }\n }\n </div>\n }\n </div>\n } @else {\n <ng-content />\n @if (contentTemplate()) {\n <ng-container *ngTemplateOutlet=\"contentTemplate(); context: getDisabledContentTemplateContext()\"></ng-container>\n }\n }\n `,\n changeDetection: ChangeDetectionStrategy.Default,\n encapsulation: ViewEncapsulation.None,\n providers: [ScrollerStyle, { provide: SCROLLER_INSTANCE, useExisting: Scroller }, { provide: PARENT_INSTANCE, useExisting: Scroller }],\n hostDirectives: [Bind],\n host: {\n '[style.height]': 'hostHeight()'\n }\n})\nexport class Scroller extends BaseComponent<VirtualScrollerPassThrough> {\n componentName = 'VirtualScroller';\n\n bindDirectiveInstance = inject(Bind, { self: true });\n\n $pcScroller: Scroller | undefined = inject(SCROLLER_INSTANCE, { optional: true, skipSelf: true }) ?? undefined;\n\n hostName = input('');\n /**\n * Unique identifier of the element.\n * @group Props\n */\n id = input<string | undefined>();\n /**\n * Inline style of the component.\n * @group Props\n */\n style = input<any>();\n /**\n * Style class of the element.\n * @group Props\n */\n styleClass = input<string | undefined>();\n /**\n * Index of the element in tabbing order.\n * @group Props\n */\n tabindex = input(0);\n /**\n * An array of objects to display.\n * @group Props\n */\n items = input<any[] | undefined | null>();\n /**\n * The height/width of item according to orientation.\n * @group Props\n */\n itemSize = input<number | number[]>(0);\n /**\n * Height of the scroll viewport.\n * @group Props\n */\n scrollHeight = input<string | undefined>();\n /**\n * Width of the scroll viewport.\n * @group Props\n */\n scrollWidth = input<string | undefined>();\n /**\n * The orientation of scrollbar.\n * @group Props\n */\n orientation = input<'vertical' | 'horizontal' | 'both'>('vertical');\n /**\n * Used to specify how many items to load in each load method in lazy mode.\n * @group Props\n */\n step = input(0);\n /**\n * Delay in scroll before new data is loaded.\n * @group Props\n */\n delay = input(0);\n /**\n * Delay after window's resize finishes.\n * @group Props\n */\n resizeDelay = input(10);\n /**\n * Used to append each loaded item to top without removing any items from the DOM. Using very large data may cause the browser to crash.\n * @group Props\n */\n appendOnly = input(false);\n /**\n * Specifies whether the scroller should be displayed inline or not.\n * @group Props\n */\n inline = input(false);\n /**\n * Defines if data is loaded and interacted with in lazy manner.\n * @group Props\n */\n lazy = input(false);\n /**\n * If disabled, the scroller feature is eliminated and the content is displayed directly.\n * @group Props\n */\n disabled = input(false);\n /**\n * Used to implement a custom loader instead of using the loader feature in the scroller.\n * @group Props\n */\n loaderDisabled = input(false);\n /**\n * Columns to display.\n * @group Props\n */\n columns = input<any[] | undefined | null>();\n /**\n * Used to implement a custom spacer instead of using the spacer feature in the scroller.\n * @group Props\n */\n showSpacer = input(true);\n /**\n * Defines whether to show loader.\n * @group Props\n */\n showLoader = input(false);\n /**\n * Determines how many additional elements to add to the DOM outside of the view. According to the scrolls made up and down, extra items are added in a certain algorithm in the form of multiples of this number. Default value is half the number of items shown in the view.\n * @group Props\n */\n numToleratedItems = input<any>();\n /**\n * Defines whether the data is loaded.\n * @group Props\n */\n loading = input<boolean | undefined>();\n /**\n * Defines whether to dynamically change the height or width of scrollable container.\n * @group Props\n */\n autoSize = input(false);\n /**\n * Function to optimize the dom operations by delegating to ngForTrackBy, default algoritm checks for object identity.\n * @group Props\n */\n trackBy = input<Function>();\n /**\n * Defines whether to use the scroller feature. The properties of scroller component can be used like an object in it.\n * @group Props\n */\n options = input<ScrollerOptions | undefined>();\n\n // Computed: Options merge with individual inputs\n _id = computed(() => this.options()?.id ?? this.id());\n _style = computed(() => this.options()?.style ?? this.style());\n _styleClass = computed(() => this.options()?.styleClass ?? this.styleClass());\n _tabindex = computed(() => this.options()?.tabindex ?? this.tabindex());\n _items = computed(() => this.options()?.items ?? this.items());\n _itemSize = computed(() => this.options()?.itemSize ?? this.itemSize());\n _scrollHeight = computed(() => this.options()?.scrollHeight ?? this.scrollHeight());\n _scrollWidth = computed(() => this.options()?.scrollWidth ?? this.scrollWidth());\n _orientation = computed(() => this.options()?.orientation ?? this.orientation());\n _step = computed(() => this.options()?.step ?? this.step());\n _delay = computed(() => this.options()?.delay ?? this.delay());\n _resizeDelay = computed(() => this.options()?.resizeDelay ?? this.resizeDelay());\n _appendOnly = computed(() => this.options()?.appendOnly ?? this.appendOnly());\n _inline = computed(() => this.options()?.inline ?? this.inline());\n _lazy = computed(() => this.options()?.lazy ?? this.lazy());\n _disabled = computed(() => this.options()?.disabled ?? this.disabled());\n _loaderDisabled = computed(() => this.options()?.loaderDisabled ?? this.loaderDisabled());\n _columns = computed(() => this.options()?.columns ?? this.columns());\n _showSpacer = computed(() => this.options()?.showSpacer ?? this.showSpacer());\n _showLoader = computed(() => this.options()?.showLoader ?? this.showLoader());\n _numToleratedItems = computed(() => this.options()?.numToleratedItems ?? this.numToleratedItems());\n _loading = computed(() => this.options()?.loading ?? this.loading());\n _autoSize = computed(() => this.options()?.autoSize ?? this.autoSize());\n _trackBy = computed(() => this.options()?.trackBy ?? this.trackBy());\n\n contentStyleClass = computed(() => this.options()?.contentStyleClass);\n\n /**\n * Callback to invoke in lazy mode to load new data.\n * @param {ScrollerLazyLoadEvent} event - Custom lazy load event.\n * @group Emits\n */\n onLazyLoad = output<ScrollerLazyLoadEvent>();\n /**\n * Callback to invoke when scroll position changes.\n * @param {ScrollerScrollEvent} event - Custom scroll event.\n * @group Emits\n */\n onScroll = output<ScrollerScrollEvent>();\n /**\n * Callback to invoke when scroll position and item's range in view changes.\n * @param {ScrollerScrollEvent} event - Custom scroll index change event.\n * @group Emits\n */\n onScrollIndexChange = output<ScrollerScrollIndexChangeEvent>();\n\n elementViewChild = viewChild<ElementRef>('element');\n\n contentViewChild = viewChild<ElementRef>('content');\n\n hostHeight = signal<string | undefined>(undefined);\n\n /**\n * Content template of the component.\n * @param {ScrollerContentTemplateContext} context - content context.\n * @see {@link ScrollerContentTemplateContext}\n * @group Templates\n */\n contentTemplate = contentChild<TemplateRef<ScrollerContentTemplateContext>>('content', { descendants: false });\n\n /**\n * Item template of the component.\n * @param {ScrollerItemTemplateContext} context - item context.\n * @see {@link ScrollerItemTemplateContext}\n * @group Templates\n */\n itemTemplate = contentChild<TemplateRef<ScrollerItemTemplateContext>>('item', { descendants: false });\n\n /**\n * Loader template of the component.\n * @param {ScrollerLoaderTemplateContext} context - loader context.\n * @see {@link ScrollerLoaderTemplateContext}\n * @group Templates\n */\n loaderTemplate = contentChild<TemplateRef<ScrollerLoaderTemplateContext>>('loader', { descendants: false });\n\n /**\n * Loader icon template of the component.\n * @param {ScrollerLoaderIconTemplateContext} context - loader icon context.\n * @see {@link ScrollerLoaderIconTemplateContext}\n * @group Templates\n */\n loaderIconTemplate = contentChild<TemplateRef<ScrollerLoaderIconTemplateContext>>('loadericon', { descendants: false });\n\n d_loading: boolean = false;\n\n d_numToleratedItems: any;\n\n contentEl: any;\n\n vertical = computed(() => this._orientation() === 'vertical');\n\n horizontal = computed(() => this._orientation() === 'horizontal');\n\n both = computed(() => this._orientation() === 'both');\n\n get loadedItems() {\n const items = this._items();\n if (items && !this.d_loading) {\n if (this.both()) {\n return items.slice(this._appendOnly() ? 0 : this.first.rows, this.last.rows).map((item) => {\n if (this._columns()) {\n return item;\n } else if (Array.isArray(item)) {\n return item.slice(this._appendOnly() ? 0 : this.first.cols, this.last.cols);\n } else {\n return item;\n }\n });\n } else if (this.horizontal() && this._columns()) return items;\n else return items.slice(this._appendOnly() ? 0 : this.first, this.last);\n }\n\n return [];\n }\n\n get loadedRows() {\n return this.d_loading ? (this._loaderDisabled() ? this.loaderArr : []) : this.loadedItems;\n }\n\n get loadedColumns() {\n const columns = this._columns();\n if (columns && (this.both() || this.horizontal())) {\n return this.d_loading && this._loaderDisabled() ? (this.both() ? this.loaderArr[0] : this.loaderArr) : columns.slice(this.both() ? this.first.cols : this.first, this.both() ? this.last.cols : this.last);\n }\n\n return columns;\n }\n\n first: any = 0;\n\n last: any = 0;\n\n page: number = 0;\n\n isRangeChanged: boolean = false;\n\n numItemsInViewport: any = 0;\n\n lastScrollPos: any = 0;\n\n lazyLoadState: any = {};\n\n loaderArr: any[] = [];\n\n spacerStyle: CSSProperties;\n\n contentStyle: CSSProperties;\n\n scrollTimeout: any;\n\n resizeTimeout: any;\n\n private _destroyed = false;\n\n initialized: boolean = false;\n\n windowResizeListener: VoidListener;\n\n defaultWidth: number | undefined;\n\n defaultHeight: number | undefined;\n\n defaultContentWidth: number | undefined;\n\n defaultContentHeight: number | undefined;\n\n _componentStyle = inject(ScrollerStyle);\n\n constructor() {\n super();\n\n // hostHeight\n effect(() => {\n if (this._scrollHeight() === '100%') {\n this.hostHeight.set('100%');\n }\n });\n\n // loading sync\n effect(() => {\n const loading = this._loading();\n untracked(() => {\n if (this._lazy() && loading !== undefined && loading !== this.d_loading) {\n this.d_loading = loading;\n }\n });\n });\n\n // orientation reset\n effect(() => {\n this._orientation();\n untracked(() => {\n this.lastScrollPos = this.both() ? { top: 0, left: 0 } : 0;\n });\n });\n\n // numToleratedItems sync\n effect(() => {\n const numT = this._numToleratedItems();\n untracked(() => {\n if (numT !== undefined && numT !== this.d_numToleratedItems) {\n this.d_numToleratedItems = numT;\n }\n });\n });\n\n // reinit on size/scroll changes\n effect(() => {\n this._itemSize();\n this._scrollHeight();\n this._scrollWidth();\n untracked(() => {\n if (this.initialized) {\n this.init();\n this.calculateAutoSize();\n }\n });\n });\n\n // items change\n effect(() => {\n this._items();\n untracked(() => {\n if (this.initialized && !this._lazy()) {\n this.init();\n }\n });\n });\n\n // contentStyle sync from options\n effect(() => {\n const opts = this.options();\n untracked(() => {\n if (opts?.contentStyle !== undefined) {\n this.contentStyle = opts.contentStyle;\n }\n });\n });\n }\n\n onInit() {\n this.setInitialState();\n }\n\n onAfterViewInit() {\n Promise.resolve().then(() => {\n this.viewInit();\n });\n }\n\n onAfterViewChecked() {\n this.bindDirectiveInstance.setAttrs(this.ptm('host'));\n if (!this.initialized) {\n this.viewInit();\n }\n }\n\n onDestroy() {\n this._destroyed = true;\n this.unbindResizeListener();\n\n // Cancel pending scroll/resize debounce timers so handleEvents can't emit after destroy.\n if (this.scrollTimeout) {\n clearTimeout(this.scrollTimeout);\n }\n if (this.resizeTimeout) {\n clearTimeout(this.resizeTimeout);\n }\n\n this.contentEl = null;\n this.initialized = false;\n }\n\n viewInit() {\n if (isPlatformBrowser(this.platformId) && !this.initialized) {\n if (isVisible(this.elementViewChild()?.nativeElement)) {\n this.setInitialState();\n this.setContentEl(this.contentEl);\n this.init();\n\n this.defaultWidth = getWidth(this.elementViewChild()?.nativeElement);\n this.defaultHeight = getHeight(this.elementViewChild()?.nativeElement);\n this.defaultContentWidth = getWidth(this.contentEl);\n this.defaultContentHeight = getHeight(this.contentEl);\n this.initialized = true;\n }\n }\n }\n\n init() {\n if (!this._disabled()) {\n this.bindResizeListener();\n\n // wait for the next tick\n setTimeout(() => {\n this.setSpacerSize();\n this.setSize();\n this.calculateOptions();\n this.calculateAutoSize();\n this.cd.detectChanges();\n }, 1);\n }\n }\n\n setContentEl(el?: HTMLElement) {\n this.contentEl = el || this.contentViewChild()?.nativeElement || findSingle(this.elementViewChild()?.nativeElement, '.p-virtualscroller-content');\n }\n setInitialState() {\n this.first = this.both() ? { rows: 0, cols: 0 } : 0;\n this.last = this.both() ? { rows: 0, cols: 0 } : 0;\n this.numItemsInViewport = this.both() ? { rows: 0, cols: 0 } : 0;\n this.lastScrollPos = this.both() ? { top: 0, left: 0 } : 0;\n if (this.d_loading === undefined || this.d_loading === false) {\n this.d_loading = this._loading() || false;\n }\n this.d_numToleratedItems = this._numToleratedItems();\n this.loaderArr = this.loaderArr.length > 0 ? this.loaderArr : [];\n }\n\n getElementRef() {\n return this.elementViewChild();\n }\n\n getPageByFirst(first?: any) {\n return Math.floor(((first ?? this.first) + this.d_numToleratedItems * 4) / (this._step() || 1));\n }\n\n isPageChanged(first?: any) {\n return this._step() ? this.page !== this.getPageByFirst(first ?? this.first) : true;\n }\n\n scrollTo(options: ScrollToOptions) {\n this.elementViewChild()?.nativeElement?.scrollTo(options);\n }\n\n scrollToIndex(index: number | number[], behavior: ScrollBehavior = 'auto') {\n const valid = this.both() ? (index as number[]).every((i) => i > -1) : (index as number) > -1;\n\n if (valid) {\n const first = this.first;\n const { scrollTop = 0, scrollLeft = 0 } = this.elementViewChild()?.nativeElement;\n const { numToleratedItems } = this.calculateNumItems();\n const contentPos = this.getContentPosition();\n const itemSize = this._itemSize();\n const calculateFirst = (_index = 0, _numT: number) => (_index <= _numT ? 0 : _index);\n const calculateCoord = (_first: number, _size: number, _cpos: number) => _first * _size + _cpos;\n const scrollTo = (left = 0, top = 0) => this.scrollTo({ left, top, behavior });\n let newFirst = this.both() ? { rows: 0, cols: 0 } : 0;\n let isRangeChanged = false,\n isScrollChanged = false;\n\n if (this.both()) {\n newFirst = {\n rows: calculateFirst(index[0], numToleratedItems[0]),\n cols: calculateFirst(index[1], numToleratedItems[1])\n };\n scrollTo(calculateCoord(newFirst.cols, itemSize[1], contentPos.left), calculateCoord(newFirst.rows, itemSize[0], contentPos.top));\n isScrollChanged = this.lastScrollPos.top !== scrollTop || this.lastScrollPos.left !== scrollLeft;\n isRangeChanged = newFirst.rows !== first.rows || newFirst.cols !== first.cols;\n } else {\n newFirst = calculateFirst(index as number, numToleratedItems);\n this.horizontal() ? scrollTo(calculateCoord(newFirst, itemSize, contentPos.left), scrollTop) : scrollTo(scrollLeft, calculateCoord(newFirst, itemSize, contentPos.top));\n isScrollChanged = this.lastScrollPos !== (this.horizontal() ? scrollLeft : scrollTop);\n isRangeChanged = newFirst !== first;\n }\n\n this.isRangeChanged = isRangeChanged;\n isScrollChanged && (this.first = newFirst);\n }\n }\n\n scrollInView(index: number, to: ScrollerToType, behavior: ScrollBehavior = 'auto') {\n if (to) {\n const { first, viewport } = this.getRenderedRange();\n const scrollTo = (left = 0, top = 0) => this.scrollTo({ left, top, behavior });\n const isToStart = to === 'to-start';\n const isToEnd = to === 'to-end';\n\n if (isToStart) {\n if (this.both()) {\n if (viewport.first.rows - first.rows > (<any>index)[0]) {\n scrollTo(viewport.first.cols * (<number[]>this._itemSize())[1], (viewport.first.rows - 1) * (<number[]>this._itemSize())[0]);\n } else if (viewport.first.cols - first.cols > (<any>index)[1]) {\n scrollTo((viewport.first.cols - 1) * (<number[]>this._itemSize())[1], viewport.first.rows * (<number[]>this._itemSize())[0]);\n }\n } else {\n if (viewport.first - first > index) {\n const pos = (viewport.first - 1) * <number>this._itemSize();\n this.horizontal() ? scrollTo(pos, 0) : scrollTo(0, pos);\n }\n }\n } else if (isToEnd) {\n if (this.both()) {\n if (viewport.last.rows - first.rows <= (<any>index)[0] + 1) {\n scrollTo(viewport.first.cols * (<number[]>this._itemSize())[1], (viewport.first.rows + 1) * (<number[]>this._itemSize())[0]);\n } else if (viewport.last.cols - first.cols <= (<any>index)[1] + 1) {\n scrollTo((viewport.first.cols + 1) * (<number[]>this._itemSize())[1], viewport.first.rows * (<number[]>this._itemSize())[0]);\n }\n } else {\n if (viewport.last - first <= index + 1) {\n const pos = (viewport.first + 1) * <number>this._itemSize();\n this.horizontal() ? scrollTo(pos, 0) : scrollTo(0, pos);\n }\n }\n }\n } else {\n this.scrollToIndex(index, behavior);\n }\n }\n\n getRenderedRange() {\n const calculateFirstInViewport = (_pos: number, _size: number) => (_size || _pos ? Math.floor(_pos / (_size || _pos)) : 0);\n\n let firstInViewport = this.first;\n let lastInViewport: any = 0;\n const el = this.elementViewChild()?.nativeElement;\n\n if (el) {\n const { scrollTop, scrollLeft } = el;\n\n if (this.both()) {\n firstInViewport = {\n rows: calculateFirstInViewport(scrollTop, (<number[]>this._itemSize())[0]),\n cols: calculateFirstInViewport(scrollLeft, (<number[]>this._itemSize())[1])\n };\n lastInViewport = {\n rows: firstInViewport.rows + this.numItemsInViewport.rows,\n cols: firstInViewport.cols + this.numItemsInViewport.cols\n };\n } else {\n const scrollPos = this.horizontal() ? scrollLeft : scrollTop;\n firstInViewport = calculateFirstInViewport(scrollPos, <number>this._itemSize());\n lastInViewport = firstInViewport + this.numItemsInViewport;\n }\n }\n\n return {\n first: this.first,\n last: this.last,\n viewport: {\n first: firstInViewport,\n last: lastInViewport\n }\n };\n }\n\n calculateNumItems() {\n const contentPos = this.getContentPosition();\n const el = this.elementViewChild()?.nativeElement;\n const contentWidth = (el ? el.offsetWidth - contentPos.left : 0) || 0;\n const contentHeight = (el ? el.offsetHeight - contentPos.top : 0) || 0;\n const calculateNumItemsInViewport = (_contentSize: number, _itemSize: number) => (_itemSize || _contentSize ? Math.ceil(_contentSize / (_itemSize || _contentSize)) : 0);\n const calculateNumToleratedItems = (_numItems: number) => Math.ceil(_numItems / 2);\n const numItemsInViewport: any = this.both()\n ? {\n rows: calculateNumItemsInViewport(contentHeight, (<number[]>this._itemSize())[0]),\n cols: calculateNumItemsInViewport(contentWidth, (<number[]>this._itemSize())[1])\n }\n : calculateNumItemsInViewport(this.horizontal() ? contentWidth : contentHeight, <number>this._itemSize());\n\n const numToleratedItems = this.d_numToleratedItems || (this.both() ? [calculateNumToleratedItems(numItemsInViewport.rows), calculateNumToleratedItems(numItemsInViewport.cols)] : calculateNumToleratedItems(numItemsInViewport));\n\n return { numItemsInViewport, numToleratedItems };\n }\n\n calculateOptions() {\n const { numItemsInViewport, numToleratedItems } = this.calculateNumItems();\n const calculateLast = (_first: number, _num: number, _numT: number, _isCols: boolean = false) => this.getLast(_first + _num + (_first < _numT ? 2 : 3) * _numT, _isCols);\n const first = this.first;\n const last = this.both()\n ? {\n rows: calculateLast(this.first.rows, numItemsInViewport.rows, numToleratedItems[0]),\n cols: calculateLast(this.first.cols, numItemsInViewport.cols, numToleratedItems[1], true)\n }\n : calculateLast(this.first, numItemsInViewport, numToleratedItems);\n\n this.last = last;\n this.numItemsInViewport = numItemsInViewport;\n this.d_numToleratedItems = numToleratedItems;\n\n if (this._showLoader()) {\n this.loaderArr = this.both() ? Array.from({ length: numItemsInViewport.rows }).map(() => Array.from({ length: numItemsInViewport.cols })) : Array.from({ length: numItemsInViewport });\n }\n\n if (this._lazy()) {\n Promise.resolve().then(() => {\n this.lazyLoadState = {\n first: this._step() ? (this.both() ? { rows: 0, cols: first.cols } : 0) : first,\n last: Math.min(this._step() ? this._step() : this.last, (<any[]>this._items()).length)\n };\n\n this.handleEvents('onLazyLoad', this.lazyLoadState);\n });\n }\n }\n\n calculateAutoSize() {\n if (this._autoSize() && !this.d_loading) {\n Promise.resolve().then(() => {\n if (this.contentEl) {\n this.contentEl.style.minHeight = this.contentEl.style.minWidth = 'auto';\n this.contentEl.style.position = 'relative';\n (<ElementRef>this.elementViewChild()).nativeElement.style.contain = 'none';\n\n const [contentWidth, contentHeight] = [getWidth(this.contentEl), getHeight(this.contentEl)];\n contentWidth !== this.defaultContentWidth && ((<ElementRef>this.elementViewChild()).nativeElement.style.width = '');\n contentHeight !== this.defaultContentHeight && ((<ElementRef>this.elementViewChild()).nativeElement.style.height = '');\n\n const [width, height] = [getWidth((<ElementRef>this.elementViewChild()).nativeElement), getHeight((<ElementRef>this.elementViewChild()).nativeElement)];\n (this.both() || this.horizontal()) && ((<ElementRef>this.elementViewChild()).nativeElement.style.width = width < <number>this.defaultWidth ? width + 'px' : this._scrollWidth() || this.defaultWidth + 'px');\n (this.both() || this.vertical()) && ((<ElementRef>this.elementViewChild()).nativeElement.style.height = height < <number>this.defaultHeight ? height + 'px' : this._scrollHeight() || this.defaultHeight + 'px');\n\n this.contentEl.style.minHeight = this.contentEl.style.minWidth = '';\n this.contentEl.style.position = '';\n (<ElementRef>this.elementViewChild()).nativeElement.style.contain = '';\n }\n });\n }\n }\n\n getLast(last = 0, isCols = false) {\n const items = this._items();\n const columns = this._columns();\n return items ? Math.min(isCols ? (columns || items[0]).length : items.length, last) : 0;\n }\n\n getContentPosition() {\n if (this.contentEl) {\n const style = getComputedStyle(this.contentEl);\n const left = parseFloat(style.paddingLeft) + Math.max(parseFloat(style.left) || 0, 0);\n const right = parseFloat(style.paddingRight) + Math.max(parseFloat(style.right) || 0, 0);\n const top = parseFloat(style.paddingTop) + Math.max(parseFloat(style.top) || 0, 0);\n const bottom = parseFloat(style.paddingBottom) + Math.max(parseFloat(style.bottom) || 0, 0);\n\n return { left, right, top, bottom, x: left + right, y: top + bottom };\n }\n\n return { left: 0, right: 0, top: 0, bottom: 0, x: 0, y: 0 };\n }\n\n setSize() {\n const nativeElement = this.elementViewChild()?.nativeElement;\n if (nativeElement) {\n const parentElement = nativeElement.parentElement?.parentElement;\n\n const elementWidth = nativeElement.offsetWidth;\n const parentWidth = parentElement?.offsetWidth || 0;\n const width = this._scrollWidth() || `${elementWidth || parentWidth}px`;\n\n const elementHeight = nativeElement.offsetHeight;\n const parentHeight = parentElement?.offsetHeight || 0;\n const height = this._scrollHeight() || `${elementHeight || parentHeight}px`;\n\n const setProp = (_name: string, _value: any) => (nativeElement.style[_name] = _value);\n\n if (this.both() || this.horizontal()) {\n setProp('height', height);\n setProp('width', width);\n } else {\n setProp('height', height);\n }\n }\n }\n\n setSpacerSize() {\n const items = this._items();\n if (items) {\n const contentPos = this.getContentPosition();\n const setProp = (_name: string, _value: any, _size: number, _cpos: number = 0) =>\n (this.spacerStyle = {\n ...this.spacerStyle,\n ...{ [`${_name}`]: (_value || []).length * _size + _cpos + 'px' }\n });\n\n if (this.both()) {\n setProp('height', items, (<number[]>this._itemSize())[0], contentPos.y);\n setProp('width', this._columns() || items[1], (<number[]>this._itemSize())[1], contentPos.x);\n } else {\n this.horizontal() ? setProp('width', this._columns() || items, <number>this._itemSize(), contentPos.x) : setProp('height', items, <number>this._itemSize(), contentPos.y);\n }\n }\n }\n\n setContentPosition(pos: any) {\n if (this.contentEl && !this._appendOnly()) {\n const first = pos ? pos.first : this.first;\n const calculateTranslateVal = (_first: number, _size: number) => _first * _size;\n const setTransform = (_x = 0, _y = 0) => (this.contentStyle = { ...this.contentStyle, ...{ transform: `translate3d(${_x}px, ${_y}px, 0)` } });\n\n if (this.both()) {\n setTransform(calculateTranslateVal(first.cols, (<number[]>this._itemSize())[1]), calculateTranslateVal(first.rows, (<number[]>this._itemSize())[0]));\n } else {\n const translateVal = calculateTranslateVal(first, <number>this._itemSize());\n this.horizontal() ? setTransform(translateVal, 0) : setTransform(0, translateVal);\n }\n }\n }\n\n onScrollPositionChange(event: Event) {\n const target = event.target;\n if (!target) {\n throw new Error('Event target is null');\n }\n const contentPos = this.getContentPosition();\n const calculateScrollPos = (_pos: number, _cpos: number) => (_pos ? (_pos > _cpos ? _pos - _cpos : _pos) : 0);\n const calculateCurrentIndex = (_pos: number, _size: number) => (_size || _pos ? Math.floor(_pos / (_size || _pos)) : 0);\n const calculateTriggerIndex = (_currentIndex: number, _first: number, _last: number, _num: number, _numT: number, _isScrollDownOrRight: any) => {\n return _currentIndex <= _numT ? _numT : _isScrollDownOrRight ? _last - _num - _numT : _first + _numT - 1;\n };\n const calculateFirst = (_currentIndex: number, _triggerIndex: number, _first: number, _last: number, _num: number, _numT: number, _isScrollDownOrRight: any) => {\n if (_currentIndex <= _numT) return 0;\n else return Math.max(0, _isScrollDownOrRight ? (_currentIndex < _triggerIndex ? _first : _currentIndex - _numT) : _currentIndex > _triggerIndex ? _first : _currentIndex - 2 * _numT);\n };\n const calculateLast = (_currentIndex: number, _first: number, _last: number, _num: number, _numT: number, _isCols = false) => {\n let lastValue = _first + _num + 2 * _numT;\n\n if (_currentIndex >= _numT) {\n lastValue += _numT + 1;\n }\n\n return this.getLast(lastValue, _isCols);\n };\n\n const scrollTop = calculateScrollPos((<HTMLElement>target).scrollTop, contentPos.top);\n const scrollLeft = calculateScrollPos((<HTMLElement>target).scrollLeft, contentPos.left);\n\n let newFirst = this.both() ? { rows: 0, cols: 0 } : 0;\n let newLast = this.last;\n let isRangeChanged = false;\n let newScrollPos = this.lastScrollPos;\n\n if (this.both()) {\n const isScrollDown = this.lastScrollPos.top <= scrollTop;\n const isScrollRight = this.lastScrollPos.left <= scrollLeft;\n\n if (!this._appendOnly() || (this._appendOnly() && (isScrollDown || isScrollRight))) {\n const currentIndex = {\n rows: calculateCurrentIndex(scrollTop, (<number[]>this._itemSize())[0]),\n cols: calculateCurrentIndex(scrollLeft, (<number[]>this._itemSize())[1])\n };\n const triggerIndex = {\n rows: calculateTriggerIndex(currentIndex.rows, this.first.rows, this.last.rows, this.numItemsInViewport.rows, this.d_numToleratedItems[0], isScrollDown),\n cols: calculateTriggerIndex(currentIndex.cols, this.first.cols, this.last.cols, this.numItemsInViewport.cols, this.d_numToleratedItems[1], isScrollRight)\n };\n\n newFirst = {\n rows: calculateFirst(currentIndex.rows, triggerIndex.rows, this.first.rows, this.last.rows, this.numItemsInViewport.rows, this.d_numToleratedItems[0], isScrollDown),\n cols: calculateFirst(currentIndex.cols, triggerIndex.cols, this.first.cols, this.last.cols, this.numItemsInViewport.cols, this.d_numToleratedItems[1], isScrollRight)\n };\n newLast = {\n rows: calculateLast(currentIndex.rows, newFirst.rows, this.last.rows, this.numItemsInViewport.rows, this.d_numToleratedItems[0]),\n cols: calculateLast(currentIndex.cols, newFirst.cols, this.last.cols, this.numItemsInViewport.cols, this.d_numToleratedItems[1], true)\n };\n\n isRangeChanged = newFirst.rows !== this.first.rows || newLast.rows !== this.last.rows || newFirst.cols !== this.first.cols || newLast.cols !== this.last.cols || this.isRangeChanged;\n newScrollPos = { top: scrollTop, left: scrollLeft };\n }\n } else {\n const scrollPos = this.horizontal() ? scrollLeft : scrollTop;\n const isScrollDownOrRight = this.lastScrollPos <= scrollPos;\n\n if (!this._appendOnly() || (this._appendOnly() && isScrollDownOrRight)) {\n const currentIndex = calculateCurrentIndex(scrollPos, <number>this._itemSize());\n const triggerIndex = calculateTriggerIndex(currentIndex, this.first, this.last, this.numItemsInViewport, this.d_numToleratedItems, isScrollDownOrRight);\n\n newFirst = calculateFirst(currentIndex, triggerIndex, this.first, this.last, this.numItemsInViewport, this.d_numToleratedItems, isScrollDownOrRight);\n newLast = calculateLast(currentIndex, newFirst, this.last, this.numItemsInViewport, this.d_numToleratedItems);\n isRangeChanged = newFirst !== this.first || newLast !== this.last || this.isRangeChanged;\n newScrollPos = scrollPos;\n }\n }\n\n return {\n first: newFirst,\n last: newLast,\n isRangeChanged,\n scrollPos: newScrollPos\n };\n }\n\n onScrollChange(event: Event) {\n const { first, last, isRangeChanged, scrollPos } = this.onScrollPositionChange(event);\n\n if (isRangeChanged) {\n const newState = { first, last };\n\n this.setContentPosition(newState);\n\n this.first = first;\n this.last = last;\n this.lastScrollPos = scrollPos;\n\n this.handleEvents('onScrollIndexChange', newState);\n\n if (this._lazy() && this.isPageChanged(first)) {\n const lazyLoadState = {\n first: this._step() ? Math.min(this.getPageByFirst(first) * this._step(), (<any[]>this._items()).length - this._step()) : first,\n last: Math.min(this._step() ? (this.getPageByFirst(first) + 1) * this._step() : last, (<any[]>this._items()).length)\n };\n const isLazyStateChanged = this.lazyLoadState.first !== lazyLoadState.first || this.lazyLoadState.last !== lazyLoadState.last;\n\n isLazyStateChanged && this.handleEvents('onLazyLoad', lazyLoadState);\n this.lazyLoadState = lazyLoadState;\n }\n }\n }\n\n onContainerScroll(event: Event) {\n this.handleEvents('onScroll', { originalEvent: event });\n\n if (this._delay()) {\n if (this.scrollTimeout) {\n clearTimeout(this.scrollTimeout);\n }\n\n if (!this.d_loading && this._showLoader()) {\n const { isRangeChanged } = this.onScrollPositionChange(event);\n const changed = isRangeChanged || (this._step() ? this.isPageChanged() : false);\n\n if (changed) {\n this.d_loading = true;\n\n this.cd.detectChanges();\n }\n }\n\n this.scrollTimeout = setTimeout(() => {\n this.onScrollChange(event);\n\n if (this.d_loading && this._showLoader() && (!this._lazy() || this._loading() === undefined)) {\n this.d_loading = false;\n this.page = this.getPageByFirst();\n }\n this.cd.detectChanges();\n }, this._delay());\n } else {\n !this.d_loading && this.onScrollChange(event);\n }\n }\n\n bindResizeListener() {\n if (isPlatformBrowser(this.platformId)) {\n if (!this.windowResizeListener) {\n const window = this.document.defaultView as Window;\n const event = isTouchDevice() ? 'orientationchange' : 'resize';\n this.windowResizeListener = this.renderer.listen(window, event, this.onWindowResize.bind(this));\n }\n }\n }\n\n unbindResizeListener() {\n if (this.windowResizeListener) {\n this.windowResizeListener();\n this.windowResizeListener = null;\n }\n }\n\n onWindowResize() {\n if (this.resizeTimeout) {\n clearTimeout(this.resizeTimeout);\n }\n\n this.resizeTimeout = setTimeout(() => {\n if (isVisible(this.elementViewChild()?.nativeElement)) {\n const [width, height] = [getWidth(this.elementViewChild()?.nativeElement), getHeight(this.elementViewChild()?.nativeElement)];\n const [isDiffWidth, isDiffHeight] = [width !== this.defaultWidth, height !== this.defaultHeight];\n const reinit = this.both() ? isDiffWidth || isDiffHeight : this.horizontal() ? isDiffWidth : this.vertical() ? isDiffHeight : false;\n\n if (reinit) {\n this.d_numToleratedItems = this._numToleratedItems();\n this.defaultWidth = width;\n this.defaultHeight = height;\n this.defaultContentWidth = getWidth(this.contentEl);\n this.defaultContentHeight = getHeight(this.contentEl);\n\n this.init();\n }\n }\n }, this._resizeDelay());\n }\n\n handleEvents(name: string, params: any) {\n // Pending timers / promise microtasks (e.g. the lazy-load Promise.resolve callback) can\n // reach this after destroy; bail so we don't emit on a destroyed OutputRef.\n if (this._destroyed) return;\n const opts = this.options();\n return opts && (opts as any)[name] ? (opts as any)[name](params) : this[name].emit(params);\n }\n\n readonly loaderIconContext = { options: { styleClass: 'p-virtualscroller-loading-icon' } };\n\n getContentTemplateContext() {\n return {\n $implicit: this.loadedItems,\n options: this.getContentOptions()\n };\n }\n\n getItemTemplateContext(item: any, index: number) {\n return {\n $implicit: item,\n options: this.getOptions(index)\n };\n }\n\n getLoaderTemplateContext(index: number) {\n return {\n options: this.getLoaderOptions(index, this.both() && { numCols: this.numItemsInViewport.cols })\n };\n }\n\n getDisabledContentTemplateContext() {\n return {\n $implicit: this.items(),\n options: { rows: this._items(), columns: this.loadedColumns }\n };\n }\n\n getContentOptions() {\n return {\n contentStyleClass: `p-virtualscroller-content ${this.d_loading ? 'p-virtualscroller-loading' : ''}`,\n items: this.loadedItems,\n getItemOptions: (index: number) => this.getOptions(index),\n loading: this.d_loading,\n getLoaderOptions: (index: number, options?: any) => this.getLoaderOptions(index, options),\n itemSize: this._itemSize(),\n rows: this.loadedRows,\n columns: this.loadedColumns,\n spacerStyle: this.spacerStyle,\n contentStyle: this.contentStyle,\n vertical: this.vertical(),\n horizontal: this.horizontal(),\n both: this.both(),\n scrollTo: this.scrollTo.bind(this),\n scrollToIndex: this.scrollToIndex.bind(this),\n orientation: this._orientation(),\n scrollableElement: this.elementViewChild()?.nativeElement\n };\n }\n\n getOptions(renderedIndex: number) {\n const count = (this._items() || []).length;\n const index = this.both() ? this.first.rows + renderedIndex : this.first + renderedIndex;\n\n return {\n index,\n count,\n first: index === 0,\n last: index === count - 1,\n even: index % 2 === 0,\n odd: index % 2 !== 0\n };\n }\n\n getLoaderOptions(index: number, extOptions: any) {\n const count = this.loaderArr.length;\n\n return {\n index,\n count,\n first: index === 0,\n last: index === count - 1,\n even: index % 2 === 0,\n odd: index % 2 !== 0,\n loading: this.d_loading,\n ...extOptions\n };\n }\n}\n\n@NgModule({\n imports: [Scroller],\n exports: [Scroller]\n})\nexport class ScrollerModule {}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public_api';\n"],"names":["SpinnerIcon"],"mappings":";;;;;;;;;;;AAGA,MAAM,GAAG,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA0DnB;AAED,MAAM,OAAO,GAAG;AACZ,IAAA,IAAI,EAAE,CAAC,EAAE,QAAQ,EAAE,KAAK;QACpB,mBAAmB;AACnB,QAAA;AACI,YAAA,0BAA0B,EAAE,QAAQ,CAAC,MAAM,EAAE;AAC7C,YAAA,sCAAsC,EAAE,QAAQ,CAAC,IAAI,EAAE;AACvD,YAAA,kDAAkD,EAAE,QAAQ,CAAC,UAAU;AAC1E;AACJ,KAAA;AACD,IAAA,OAAO,EAAE,2BAA2B;AACpC,IAAA,MAAM,EAAE,0BAA0B;AAClC,IAAA,MAAM,EAAE,CAAC,EAAE,QAAQ,EAAE,KAAK;QACtB,0BAA0B;AAC1B,QAAA;AACI,YAAA,+BAA+B,EAAE,CAAC,QAAQ,CAAC,cAAc;AAC5D;AACJ,KAAA;AACD,IAAA,WAA