@angular/cdk-experimental 21.0.0-next.8 → 21.0.0-rc.0

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.
@@ -1 +1 @@
1
- {"version":3,"file":"scrolling.mjs","sources":["../../../../../darwin_arm64-fastbuild-ST-199a4f3c4e20/bin/src/cdk-experimental/scrolling/auto-size-virtual-scroll.ts","../../../../../darwin_arm64-fastbuild-ST-199a4f3c4e20/bin/src/cdk-experimental/scrolling/scrolling-module.ts"],"sourcesContent":["/**\n * @license\n * Copyright Google LLC All Rights Reserved.\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://angular.dev/license\n */\n\nimport {coerceNumberProperty, NumberInput} from '@angular/cdk/coercion';\nimport {ListRange} from '@angular/cdk/collections';\nimport {\n CdkVirtualScrollViewport,\n VIRTUAL_SCROLL_STRATEGY,\n VirtualScrollStrategy,\n} from '@angular/cdk/scrolling';\nimport {Directive, forwardRef, Input, OnChanges} from '@angular/core';\nimport {Observable} from 'rxjs';\n\n/**\n * A class that tracks the size of items that have been seen and uses it to estimate the average\n * item size.\n */\nexport class ItemSizeAverager {\n /** The total amount of weight behind the current average. */\n private _totalWeight = 0;\n\n /** The current average item size. */\n private _averageItemSize: number;\n\n /** The default size to use for items when no data is available. */\n private _defaultItemSize: number;\n\n /** @param defaultItemSize The default size to use for items when no data is available. */\n constructor(defaultItemSize = 50) {\n this._defaultItemSize = defaultItemSize;\n this._averageItemSize = defaultItemSize;\n }\n\n /** Returns the average item size. */\n getAverageItemSize(): number {\n return this._averageItemSize;\n }\n\n /**\n * Adds a measurement sample for the estimator to consider.\n * @param range The measured range.\n * @param size The measured size of the given range in pixels.\n */\n addSample(range: ListRange, size: number) {\n const newTotalWeight = this._totalWeight + range.end - range.start;\n if (newTotalWeight) {\n const newAverageItemSize =\n (size + this._averageItemSize * this._totalWeight) / newTotalWeight;\n if (newAverageItemSize) {\n this._averageItemSize = newAverageItemSize;\n this._totalWeight = newTotalWeight;\n }\n }\n }\n\n /** Resets the averager. */\n reset() {\n this._averageItemSize = this._defaultItemSize;\n this._totalWeight = 0;\n }\n}\n\n/** Virtual scrolling strategy for lists with items of unknown or dynamic size. */\nexport class AutoSizeVirtualScrollStrategy implements VirtualScrollStrategy {\n /** @docs-private Implemented as part of VirtualScrollStrategy. */\n scrolledIndexChange = new Observable<number>(() => {\n // TODO(mmalerba): Implement.\n if (typeof ngDevMode === 'undefined' || ngDevMode) {\n throw Error(\n 'cdk-virtual-scroll: scrolledIndexChange is currently not supported for the' +\n ' autosize scroll strategy',\n );\n }\n });\n\n /** The attached viewport. */\n private _viewport: CdkVirtualScrollViewport | null = null;\n\n /** The minimum amount of buffer rendered beyond the viewport (in pixels). */\n private _minBufferPx: number;\n\n /** The number of buffer items to render beyond the edge of the viewport (in pixels). */\n private _maxBufferPx: number;\n\n /** The estimator used to estimate the size of unseen items. */\n private _averager: ItemSizeAverager;\n\n /** The last measured scroll offset of the viewport. */\n private _lastScrollOffset: number;\n\n /** The last measured size of the rendered content in the viewport. */\n private _lastRenderedContentSize: number;\n\n /** The last measured size of the rendered content in the viewport. */\n private _lastRenderedContentOffset: number;\n\n /**\n * The number of consecutive cycles where removing extra items has failed. Failure here means that\n * we estimated how many items we could safely remove, but our estimate turned out to be too much\n * and it wasn't safe to remove that many elements.\n */\n private _removalFailures = 0;\n\n /**\n * @param minBufferPx The minimum amount of buffer rendered beyond the viewport (in pixels).\n * If the amount of buffer dips below this number, more items will be rendered.\n * @param maxBufferPx The number of pixels worth of buffer to shoot for when rendering new items.\n * If the actual amount turns out to be less it will not necessarily trigger an additional\n * rendering cycle (as long as the amount of buffer is still greater than `minBufferPx`).\n * @param averager The averager used to estimate the size of unseen items.\n */\n constructor(minBufferPx: number, maxBufferPx: number, averager = new ItemSizeAverager()) {\n this._minBufferPx = minBufferPx;\n this._maxBufferPx = maxBufferPx;\n this._averager = averager;\n }\n\n /**\n * Attaches this scroll strategy to a viewport.\n * @param viewport The viewport to attach this strategy to.\n */\n attach(viewport: CdkVirtualScrollViewport) {\n this._averager.reset();\n this._viewport = viewport;\n this._renderContentForCurrentOffset();\n }\n\n /** Detaches this scroll strategy from the currently attached viewport. */\n detach() {\n this._viewport = null;\n }\n\n /** @docs-private Implemented as part of VirtualScrollStrategy. */\n onContentScrolled() {\n if (this._viewport) {\n this._updateRenderedContentAfterScroll();\n }\n }\n\n /** @docs-private Implemented as part of VirtualScrollStrategy. */\n onDataLengthChanged() {\n if (this._viewport) {\n this._renderContentForCurrentOffset();\n this._checkRenderedContentSize();\n }\n }\n\n /** @docs-private Implemented as part of VirtualScrollStrategy. */\n onContentRendered() {\n if (this._viewport) {\n this._checkRenderedContentSize();\n }\n }\n\n /** @docs-private Implemented as part of VirtualScrollStrategy. */\n onRenderedOffsetChanged() {\n if (this._viewport) {\n this._checkRenderedContentOffset();\n }\n }\n\n /** Scroll to the offset for the given index. */\n scrollToIndex(): void {\n if (typeof ngDevMode === 'undefined' || ngDevMode) {\n // TODO(mmalerba): Implement.\n throw Error(\n 'cdk-virtual-scroll: scrollToIndex is currently not supported for the autosize' +\n ' scroll strategy',\n );\n }\n }\n\n /**\n * Update the buffer parameters.\n * @param minBufferPx The minimum amount of buffer rendered beyond the viewport (in pixels).\n * @param maxBufferPx The number of buffer items to render beyond the edge of the viewport (in\n * pixels).\n */\n updateBufferSize(minBufferPx: number, maxBufferPx: number) {\n if (maxBufferPx < minBufferPx) {\n throw Error('CDK virtual scroll: maxBufferPx must be greater than or equal to minBufferPx');\n }\n this._minBufferPx = minBufferPx;\n this._maxBufferPx = maxBufferPx;\n }\n\n /** Update the rendered content after the user scrolls. */\n private _updateRenderedContentAfterScroll() {\n const viewport = this._viewport!;\n\n // The current scroll offset.\n const scrollOffset = viewport.measureScrollOffset();\n // The delta between the current scroll offset and the previously recorded scroll offset.\n let scrollDelta = scrollOffset - this._lastScrollOffset;\n // The magnitude of the scroll delta.\n let scrollMagnitude = Math.abs(scrollDelta);\n\n // The currently rendered range.\n const renderedRange = viewport.getRenderedRange();\n\n // If we're scrolling toward the top, we need to account for the fact that the predicted amount\n // of content and the actual amount of scrollable space may differ. We address this by slowly\n // correcting the difference on each scroll event.\n let offsetCorrection = 0;\n if (scrollDelta < 0) {\n // The content offset we would expect based on the average item size.\n const predictedOffset = renderedRange.start * this._averager.getAverageItemSize();\n // The difference between the predicted size of the un-rendered content at the beginning and\n // the actual available space to scroll over. We need to reduce this to zero by the time the\n // user scrolls to the top.\n // - 0 indicates that the predicted size and available space are the same.\n // - A negative number that the predicted size is smaller than the available space.\n // - A positive number indicates the predicted size is larger than the available space\n const offsetDifference = predictedOffset - this._lastRenderedContentOffset;\n // The amount of difference to correct during this scroll event. We calculate this as a\n // percentage of the total difference based on the percentage of the distance toward the top\n // that the user scrolled.\n offsetCorrection = Math.round(\n offsetDifference *\n Math.max(0, Math.min(1, scrollMagnitude / (scrollOffset + scrollMagnitude))),\n );\n\n // Based on the offset correction above, we pretend that the scroll delta was bigger or\n // smaller than it actually was, this way we can start to eliminate the difference.\n scrollDelta = scrollDelta - offsetCorrection;\n scrollMagnitude = Math.abs(scrollDelta);\n }\n\n // The current amount of buffer past the start of the viewport.\n const startBuffer = this._lastScrollOffset - this._lastRenderedContentOffset;\n // The current amount of buffer past the end of the viewport.\n const endBuffer =\n this._lastRenderedContentOffset +\n this._lastRenderedContentSize -\n (this._lastScrollOffset + viewport.getViewportSize());\n // The amount of unfilled space that should be filled on the side the user is scrolling toward\n // in order to safely absorb the scroll delta.\n const underscan =\n scrollMagnitude + this._minBufferPx - (scrollDelta < 0 ? startBuffer : endBuffer);\n\n // Check if there's unfilled space that we need to render new elements to fill.\n if (underscan > 0) {\n // Check if the scroll magnitude was larger than the viewport size. In this case the user\n // won't notice a discontinuity if we just jump to the new estimated position in the list.\n // However, if the scroll magnitude is smaller than the viewport the user might notice some\n // jitteriness if we just jump to the estimated position. Instead we make sure to scroll by\n // the same number of pixels as the scroll magnitude.\n if (scrollMagnitude >= viewport.getViewportSize()) {\n this._renderContentForCurrentOffset();\n } else {\n // The number of new items to render on the side the user is scrolling towards. Rather than\n // just filling the underscan space, we actually fill enough to have a buffer size of\n // `maxBufferPx`. This gives us a little wiggle room in case our item size estimate is off.\n const addItems = Math.max(\n 0,\n Math.ceil(\n (underscan - this._minBufferPx + this._maxBufferPx) /\n this._averager.getAverageItemSize(),\n ),\n );\n // The amount of filled space beyond what is necessary on the side the user is scrolling\n // away from.\n const overscan =\n (scrollDelta < 0 ? endBuffer : startBuffer) - this._minBufferPx + scrollMagnitude;\n // The number of currently rendered items to remove on the side the user is scrolling away\n // from. If removal has failed in recent cycles we are less aggressive in how much we try to\n // remove.\n const unboundedRemoveItems = Math.floor(\n overscan / this._averager.getAverageItemSize() / (this._removalFailures + 1),\n );\n const removeItems = Math.min(\n renderedRange.end - renderedRange.start,\n Math.max(0, unboundedRemoveItems),\n );\n\n // The new range we will tell the viewport to render. We first expand it to include the new\n // items we want rendered, we then contract the opposite side to remove items we no longer\n // want rendered.\n const range = this._expandRange(\n renderedRange,\n scrollDelta < 0 ? addItems : 0,\n scrollDelta > 0 ? addItems : 0,\n );\n if (scrollDelta < 0) {\n range.end = Math.max(range.start + 1, range.end - removeItems);\n } else {\n range.start = Math.min(range.end - 1, range.start + removeItems);\n }\n\n // The new offset we want to set on the rendered content. To determine this we measure the\n // number of pixels we removed and then adjust the offset to the start of the rendered\n // content or to the end of the rendered content accordingly (whichever one doesn't require\n // that the newly added items to be rendered to calculate.)\n let contentOffset: number;\n let contentOffsetTo: 'to-start' | 'to-end';\n if (scrollDelta < 0) {\n let removedSize = viewport.measureRangeSize({\n start: range.end,\n end: renderedRange.end,\n });\n // Check that we're not removing too much.\n if (removedSize <= overscan) {\n contentOffset =\n this._lastRenderedContentOffset + this._lastRenderedContentSize - removedSize;\n this._removalFailures = 0;\n } else {\n // If the removal is more than the overscan can absorb just undo it and record the fact\n // that the removal failed so we can be less aggressive next time.\n range.end = renderedRange.end;\n contentOffset = this._lastRenderedContentOffset + this._lastRenderedContentSize;\n this._removalFailures++;\n }\n contentOffsetTo = 'to-end';\n } else {\n const removedSize = viewport.measureRangeSize({\n start: renderedRange.start,\n end: range.start,\n });\n // Check that we're not removing too much.\n if (removedSize <= overscan) {\n contentOffset = this._lastRenderedContentOffset + removedSize;\n this._removalFailures = 0;\n } else {\n // If the removal is more than the overscan can absorb just undo it and record the fact\n // that the removal failed so we can be less aggressive next time.\n range.start = renderedRange.start;\n contentOffset = this._lastRenderedContentOffset;\n this._removalFailures++;\n }\n contentOffsetTo = 'to-start';\n }\n\n // Set the range and offset we calculated above.\n viewport.setRenderedRange(range);\n viewport.setRenderedContentOffset(contentOffset + offsetCorrection, contentOffsetTo);\n }\n } else if (offsetCorrection) {\n // Even if the rendered range didn't change, we may still need to adjust the content offset to\n // simulate scrolling slightly slower or faster than the user actually scrolled.\n viewport.setRenderedContentOffset(this._lastRenderedContentOffset + offsetCorrection);\n }\n\n // Save the scroll offset to be compared to the new value on the next scroll event.\n this._lastScrollOffset = scrollOffset;\n }\n\n /**\n * Checks the size of the currently rendered content and uses it to update the estimated item size\n * and estimated total content size.\n */\n private _checkRenderedContentSize() {\n const viewport = this._viewport!;\n this._lastRenderedContentSize = viewport.measureRenderedContentSize();\n this._averager.addSample(viewport.getRenderedRange(), this._lastRenderedContentSize);\n this._updateTotalContentSize(this._lastRenderedContentSize);\n }\n\n /** Checks the currently rendered content offset and saves the value for later use. */\n private _checkRenderedContentOffset() {\n const viewport = this._viewport!;\n this._lastRenderedContentOffset = viewport.getOffsetToRenderedContentStart()!;\n }\n\n /**\n * Recalculates the rendered content based on our estimate of what should be shown at the current\n * scroll offset.\n */\n private _renderContentForCurrentOffset() {\n const viewport = this._viewport!;\n const scrollOffset = viewport.measureScrollOffset();\n this._lastScrollOffset = scrollOffset;\n this._removalFailures = 0;\n\n const itemSize = this._averager.getAverageItemSize();\n const firstVisibleIndex = Math.min(\n viewport.getDataLength() - 1,\n Math.floor(scrollOffset / itemSize),\n );\n const bufferSize = Math.ceil(this._maxBufferPx / itemSize);\n const range = this._expandRange(\n this._getVisibleRangeForIndex(firstVisibleIndex),\n bufferSize,\n bufferSize,\n );\n\n viewport.setRenderedRange(range);\n viewport.setRenderedContentOffset(itemSize * range.start);\n }\n\n // TODO: maybe move to base class, can probably share with fixed size strategy.\n /**\n * Gets the visible range of data for the given start index. If the start index is too close to\n * the end of the list it may be backed up to ensure the estimated size of the range is enough to\n * fill the viewport.\n * Note: must not be called if `this._viewport` is null\n * @param startIndex The index to start the range at\n * @return a range estimated to be large enough to fill the viewport when rendered.\n */\n private _getVisibleRangeForIndex(startIndex: number): ListRange {\n const viewport = this._viewport!;\n const range: ListRange = {\n start: startIndex,\n end: startIndex + Math.ceil(viewport.getViewportSize() / this._averager.getAverageItemSize()),\n };\n const extra = range.end - viewport.getDataLength();\n if (extra > 0) {\n range.start = Math.max(0, range.start - extra);\n }\n return range;\n }\n\n // TODO: maybe move to base class, can probably share with fixed size strategy.\n /**\n * Expand the given range by the given amount in either direction.\n * Note: must not be called if `this._viewport` is null\n * @param range The range to expand\n * @param expandStart The number of items to expand the start of the range by.\n * @param expandEnd The number of items to expand the end of the range by.\n * @return The expanded range.\n */\n private _expandRange(range: ListRange, expandStart: number, expandEnd: number): ListRange {\n const viewport = this._viewport!;\n const start = Math.max(0, range.start - expandStart);\n const end = Math.min(viewport.getDataLength(), range.end + expandEnd);\n return {start, end};\n }\n\n /** Update the viewport's total content size. */\n private _updateTotalContentSize(renderedContentSize: number) {\n const viewport = this._viewport!;\n const renderedRange = viewport.getRenderedRange();\n const totalSize =\n renderedContentSize +\n (viewport.getDataLength() - (renderedRange.end - renderedRange.start)) *\n this._averager.getAverageItemSize();\n viewport.setTotalContentSize(totalSize);\n }\n}\n\n/**\n * Provider factory for `AutoSizeVirtualScrollStrategy` that simply extracts the already created\n * `AutoSizeVirtualScrollStrategy` from the given directive.\n * @param autoSizeDir The instance of `CdkAutoSizeVirtualScroll` to extract the\n * `AutoSizeVirtualScrollStrategy` from.\n */\nexport function _autoSizeVirtualScrollStrategyFactory(autoSizeDir: CdkAutoSizeVirtualScroll) {\n return autoSizeDir._scrollStrategy;\n}\n\n/** A virtual scroll strategy that supports unknown or dynamic size items. */\n@Directive({\n selector: 'cdk-virtual-scroll-viewport[autosize]',\n providers: [\n {\n provide: VIRTUAL_SCROLL_STRATEGY,\n useFactory: _autoSizeVirtualScrollStrategyFactory,\n deps: [forwardRef(() => CdkAutoSizeVirtualScroll)],\n },\n ],\n})\nexport class CdkAutoSizeVirtualScroll implements OnChanges {\n /**\n * The minimum amount of buffer rendered beyond the viewport (in pixels).\n * If the amount of buffer dips below this number, more items will be rendered. Defaults to 100px.\n */\n @Input()\n get minBufferPx(): number {\n return this._minBufferPx;\n }\n set minBufferPx(value: NumberInput) {\n this._minBufferPx = coerceNumberProperty(value);\n }\n _minBufferPx = 100;\n\n /**\n * The number of pixels worth of buffer to shoot for when rendering new items.\n * If the actual amount turns out to be less it will not necessarily trigger an additional\n * rendering cycle (as long as the amount of buffer is still greater than `minBufferPx`).\n * Defaults to 200px.\n */\n @Input()\n get maxBufferPx(): number {\n return this._maxBufferPx;\n }\n set maxBufferPx(value: NumberInput) {\n this._maxBufferPx = coerceNumberProperty(value);\n }\n _maxBufferPx = 200;\n\n /** The scroll strategy used by this directive. */\n _scrollStrategy = new AutoSizeVirtualScrollStrategy(this.minBufferPx, this.maxBufferPx);\n\n ngOnChanges() {\n this._scrollStrategy.updateBufferSize(this.minBufferPx, this.maxBufferPx);\n }\n}\n","/**\n * @license\n * Copyright Google LLC All Rights Reserved.\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://angular.dev/license\n */\n\nimport {NgModule} from '@angular/core';\nimport {CdkAutoSizeVirtualScroll} from './auto-size-virtual-scroll';\n\n@NgModule({\n imports: [CdkAutoSizeVirtualScroll],\n exports: [CdkAutoSizeVirtualScroll],\n})\nexport class ScrollingModule {}\n"],"names":[],"mappings":";;;;;;AAkBA;;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OAAO,EAAE,CAAC,wBAAwB,CAAC;oBACnC,OAAO,EAAE,CAAC,wBAAwB,CAAC;AACpC,iBAAA;;;;;"}
1
+ {"version":3,"file":"scrolling.mjs","sources":["../../../../../darwin_arm64-fastbuild-ST-199a4f3c4e20/bin/src/cdk-experimental/scrolling/auto-size-virtual-scroll.ts","../../../../../darwin_arm64-fastbuild-ST-199a4f3c4e20/bin/src/cdk-experimental/scrolling/scrolling-module.ts"],"sourcesContent":["/**\n * @license\n * Copyright Google LLC All Rights Reserved.\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://angular.dev/license\n */\n\nimport {coerceNumberProperty, NumberInput} from '@angular/cdk/coercion';\nimport {ListRange} from '@angular/cdk/collections';\nimport {\n CdkVirtualScrollViewport,\n VIRTUAL_SCROLL_STRATEGY,\n VirtualScrollStrategy,\n} from '@angular/cdk/scrolling';\nimport {Directive, forwardRef, Input, OnChanges} from '@angular/core';\nimport {Observable} from 'rxjs';\n\n/**\n * A class that tracks the size of items that have been seen and uses it to estimate the average\n * item size.\n */\nexport class ItemSizeAverager {\n /** The total amount of weight behind the current average. */\n private _totalWeight = 0;\n\n /** The current average item size. */\n private _averageItemSize: number;\n\n /** The default size to use for items when no data is available. */\n private _defaultItemSize: number;\n\n /** @param defaultItemSize The default size to use for items when no data is available. */\n constructor(defaultItemSize = 50) {\n this._defaultItemSize = defaultItemSize;\n this._averageItemSize = defaultItemSize;\n }\n\n /** Returns the average item size. */\n getAverageItemSize(): number {\n return this._averageItemSize;\n }\n\n /**\n * Adds a measurement sample for the estimator to consider.\n * @param range The measured range.\n * @param size The measured size of the given range in pixels.\n */\n addSample(range: ListRange, size: number) {\n const newTotalWeight = this._totalWeight + range.end - range.start;\n if (newTotalWeight) {\n const newAverageItemSize =\n (size + this._averageItemSize * this._totalWeight) / newTotalWeight;\n if (newAverageItemSize) {\n this._averageItemSize = newAverageItemSize;\n this._totalWeight = newTotalWeight;\n }\n }\n }\n\n /** Resets the averager. */\n reset() {\n this._averageItemSize = this._defaultItemSize;\n this._totalWeight = 0;\n }\n}\n\n/** Virtual scrolling strategy for lists with items of unknown or dynamic size. */\nexport class AutoSizeVirtualScrollStrategy implements VirtualScrollStrategy {\n /** @docs-private Implemented as part of VirtualScrollStrategy. */\n scrolledIndexChange = new Observable<number>(() => {\n // TODO(mmalerba): Implement.\n if (typeof ngDevMode === 'undefined' || ngDevMode) {\n throw Error(\n 'cdk-virtual-scroll: scrolledIndexChange is currently not supported for the' +\n ' autosize scroll strategy',\n );\n }\n });\n\n /** The attached viewport. */\n private _viewport: CdkVirtualScrollViewport | null = null;\n\n /** The minimum amount of buffer rendered beyond the viewport (in pixels). */\n private _minBufferPx: number;\n\n /** The number of buffer items to render beyond the edge of the viewport (in pixels). */\n private _maxBufferPx: number;\n\n /** The estimator used to estimate the size of unseen items. */\n private _averager: ItemSizeAverager;\n\n /** The last measured scroll offset of the viewport. */\n private _lastScrollOffset: number;\n\n /** The last measured size of the rendered content in the viewport. */\n private _lastRenderedContentSize: number;\n\n /** The last measured size of the rendered content in the viewport. */\n private _lastRenderedContentOffset: number;\n\n /**\n * The number of consecutive cycles where removing extra items has failed. Failure here means that\n * we estimated how many items we could safely remove, but our estimate turned out to be too much\n * and it wasn't safe to remove that many elements.\n */\n private _removalFailures = 0;\n\n /**\n * @param minBufferPx The minimum amount of buffer rendered beyond the viewport (in pixels).\n * If the amount of buffer dips below this number, more items will be rendered.\n * @param maxBufferPx The number of pixels worth of buffer to shoot for when rendering new items.\n * If the actual amount turns out to be less it will not necessarily trigger an additional\n * rendering cycle (as long as the amount of buffer is still greater than `minBufferPx`).\n * @param averager The averager used to estimate the size of unseen items.\n */\n constructor(minBufferPx: number, maxBufferPx: number, averager = new ItemSizeAverager()) {\n this._minBufferPx = minBufferPx;\n this._maxBufferPx = maxBufferPx;\n this._averager = averager;\n }\n\n /**\n * Attaches this scroll strategy to a viewport.\n * @param viewport The viewport to attach this strategy to.\n */\n attach(viewport: CdkVirtualScrollViewport) {\n this._averager.reset();\n this._viewport = viewport;\n this._renderContentForCurrentOffset();\n }\n\n /** Detaches this scroll strategy from the currently attached viewport. */\n detach() {\n this._viewport = null;\n }\n\n /** @docs-private Implemented as part of VirtualScrollStrategy. */\n onContentScrolled() {\n if (this._viewport) {\n this._updateRenderedContentAfterScroll();\n }\n }\n\n /** @docs-private Implemented as part of VirtualScrollStrategy. */\n onDataLengthChanged() {\n if (this._viewport) {\n this._renderContentForCurrentOffset();\n this._checkRenderedContentSize();\n }\n }\n\n /** @docs-private Implemented as part of VirtualScrollStrategy. */\n onContentRendered() {\n if (this._viewport) {\n this._checkRenderedContentSize();\n }\n }\n\n /** @docs-private Implemented as part of VirtualScrollStrategy. */\n onRenderedOffsetChanged() {\n if (this._viewport) {\n this._checkRenderedContentOffset();\n }\n }\n\n /** Scroll to the offset for the given index. */\n scrollToIndex(): void {\n if (typeof ngDevMode === 'undefined' || ngDevMode) {\n // TODO(mmalerba): Implement.\n throw Error(\n 'cdk-virtual-scroll: scrollToIndex is currently not supported for the autosize' +\n ' scroll strategy',\n );\n }\n }\n\n /**\n * Update the buffer parameters.\n * @param minBufferPx The minimum amount of buffer rendered beyond the viewport (in pixels).\n * @param maxBufferPx The number of buffer items to render beyond the edge of the viewport (in\n * pixels).\n */\n updateBufferSize(minBufferPx: number, maxBufferPx: number) {\n if (maxBufferPx < minBufferPx) {\n throw Error('CDK virtual scroll: maxBufferPx must be greater than or equal to minBufferPx');\n }\n this._minBufferPx = minBufferPx;\n this._maxBufferPx = maxBufferPx;\n }\n\n /** Update the rendered content after the user scrolls. */\n private _updateRenderedContentAfterScroll() {\n const viewport = this._viewport!;\n\n // The current scroll offset.\n const scrollOffset = viewport.measureScrollOffset();\n // The delta between the current scroll offset and the previously recorded scroll offset.\n let scrollDelta = scrollOffset - this._lastScrollOffset;\n // The magnitude of the scroll delta.\n let scrollMagnitude = Math.abs(scrollDelta);\n\n // The currently rendered range.\n const renderedRange = viewport.getRenderedRange();\n\n // If we're scrolling toward the top, we need to account for the fact that the predicted amount\n // of content and the actual amount of scrollable space may differ. We address this by slowly\n // correcting the difference on each scroll event.\n let offsetCorrection = 0;\n if (scrollDelta < 0) {\n // The content offset we would expect based on the average item size.\n const predictedOffset = renderedRange.start * this._averager.getAverageItemSize();\n // The difference between the predicted size of the un-rendered content at the beginning and\n // the actual available space to scroll over. We need to reduce this to zero by the time the\n // user scrolls to the top.\n // - 0 indicates that the predicted size and available space are the same.\n // - A negative number that the predicted size is smaller than the available space.\n // - A positive number indicates the predicted size is larger than the available space\n const offsetDifference = predictedOffset - this._lastRenderedContentOffset;\n // The amount of difference to correct during this scroll event. We calculate this as a\n // percentage of the total difference based on the percentage of the distance toward the top\n // that the user scrolled.\n offsetCorrection = Math.round(\n offsetDifference *\n Math.max(0, Math.min(1, scrollMagnitude / (scrollOffset + scrollMagnitude))),\n );\n\n // Based on the offset correction above, we pretend that the scroll delta was bigger or\n // smaller than it actually was, this way we can start to eliminate the difference.\n scrollDelta = scrollDelta - offsetCorrection;\n scrollMagnitude = Math.abs(scrollDelta);\n }\n\n // The current amount of buffer past the start of the viewport.\n const startBuffer = this._lastScrollOffset - this._lastRenderedContentOffset;\n // The current amount of buffer past the end of the viewport.\n const endBuffer =\n this._lastRenderedContentOffset +\n this._lastRenderedContentSize -\n (this._lastScrollOffset + viewport.getViewportSize());\n // The amount of unfilled space that should be filled on the side the user is scrolling toward\n // in order to safely absorb the scroll delta.\n const underscan =\n scrollMagnitude + this._minBufferPx - (scrollDelta < 0 ? startBuffer : endBuffer);\n\n // Check if there's unfilled space that we need to render new elements to fill.\n if (underscan > 0) {\n // Check if the scroll magnitude was larger than the viewport size. In this case the user\n // won't notice a discontinuity if we just jump to the new estimated position in the list.\n // However, if the scroll magnitude is smaller than the viewport the user might notice some\n // jitteriness if we just jump to the estimated position. Instead we make sure to scroll by\n // the same number of pixels as the scroll magnitude.\n if (scrollMagnitude >= viewport.getViewportSize()) {\n this._renderContentForCurrentOffset();\n } else {\n // The number of new items to render on the side the user is scrolling towards. Rather than\n // just filling the underscan space, we actually fill enough to have a buffer size of\n // `maxBufferPx`. This gives us a little wiggle room in case our item size estimate is off.\n const addItems = Math.max(\n 0,\n Math.ceil(\n (underscan - this._minBufferPx + this._maxBufferPx) /\n this._averager.getAverageItemSize(),\n ),\n );\n // The amount of filled space beyond what is necessary on the side the user is scrolling\n // away from.\n const overscan =\n (scrollDelta < 0 ? endBuffer : startBuffer) - this._minBufferPx + scrollMagnitude;\n // The number of currently rendered items to remove on the side the user is scrolling away\n // from. If removal has failed in recent cycles we are less aggressive in how much we try to\n // remove.\n const unboundedRemoveItems = Math.floor(\n overscan / this._averager.getAverageItemSize() / (this._removalFailures + 1),\n );\n const removeItems = Math.min(\n renderedRange.end - renderedRange.start,\n Math.max(0, unboundedRemoveItems),\n );\n\n // The new range we will tell the viewport to render. We first expand it to include the new\n // items we want rendered, we then contract the opposite side to remove items we no longer\n // want rendered.\n const range = this._expandRange(\n renderedRange,\n scrollDelta < 0 ? addItems : 0,\n scrollDelta > 0 ? addItems : 0,\n );\n if (scrollDelta < 0) {\n range.end = Math.max(range.start + 1, range.end - removeItems);\n } else {\n range.start = Math.min(range.end - 1, range.start + removeItems);\n }\n\n // The new offset we want to set on the rendered content. To determine this we measure the\n // number of pixels we removed and then adjust the offset to the start of the rendered\n // content or to the end of the rendered content accordingly (whichever one doesn't require\n // that the newly added items to be rendered to calculate.)\n let contentOffset: number;\n let contentOffsetTo: 'to-start' | 'to-end';\n if (scrollDelta < 0) {\n let removedSize = viewport.measureRangeSize({\n start: range.end,\n end: renderedRange.end,\n });\n // Check that we're not removing too much.\n if (removedSize <= overscan) {\n contentOffset =\n this._lastRenderedContentOffset + this._lastRenderedContentSize - removedSize;\n this._removalFailures = 0;\n } else {\n // If the removal is more than the overscan can absorb just undo it and record the fact\n // that the removal failed so we can be less aggressive next time.\n range.end = renderedRange.end;\n contentOffset = this._lastRenderedContentOffset + this._lastRenderedContentSize;\n this._removalFailures++;\n }\n contentOffsetTo = 'to-end';\n } else {\n const removedSize = viewport.measureRangeSize({\n start: renderedRange.start,\n end: range.start,\n });\n // Check that we're not removing too much.\n if (removedSize <= overscan) {\n contentOffset = this._lastRenderedContentOffset + removedSize;\n this._removalFailures = 0;\n } else {\n // If the removal is more than the overscan can absorb just undo it and record the fact\n // that the removal failed so we can be less aggressive next time.\n range.start = renderedRange.start;\n contentOffset = this._lastRenderedContentOffset;\n this._removalFailures++;\n }\n contentOffsetTo = 'to-start';\n }\n\n // Set the range and offset we calculated above.\n viewport.setRenderedRange(range);\n viewport.setRenderedContentOffset(contentOffset + offsetCorrection, contentOffsetTo);\n }\n } else if (offsetCorrection) {\n // Even if the rendered range didn't change, we may still need to adjust the content offset to\n // simulate scrolling slightly slower or faster than the user actually scrolled.\n viewport.setRenderedContentOffset(this._lastRenderedContentOffset + offsetCorrection);\n }\n\n // Save the scroll offset to be compared to the new value on the next scroll event.\n this._lastScrollOffset = scrollOffset;\n }\n\n /**\n * Checks the size of the currently rendered content and uses it to update the estimated item size\n * and estimated total content size.\n */\n private _checkRenderedContentSize() {\n const viewport = this._viewport!;\n this._lastRenderedContentSize = viewport.measureRenderedContentSize();\n this._averager.addSample(viewport.getRenderedRange(), this._lastRenderedContentSize);\n this._updateTotalContentSize(this._lastRenderedContentSize);\n }\n\n /** Checks the currently rendered content offset and saves the value for later use. */\n private _checkRenderedContentOffset() {\n const viewport = this._viewport!;\n this._lastRenderedContentOffset = viewport.getOffsetToRenderedContentStart()!;\n }\n\n /**\n * Recalculates the rendered content based on our estimate of what should be shown at the current\n * scroll offset.\n */\n private _renderContentForCurrentOffset() {\n const viewport = this._viewport!;\n const scrollOffset = viewport.measureScrollOffset();\n this._lastScrollOffset = scrollOffset;\n this._removalFailures = 0;\n\n const itemSize = this._averager.getAverageItemSize();\n const firstVisibleIndex = Math.min(\n viewport.getDataLength() - 1,\n Math.floor(scrollOffset / itemSize),\n );\n const bufferSize = Math.ceil(this._maxBufferPx / itemSize);\n const range = this._expandRange(\n this._getVisibleRangeForIndex(firstVisibleIndex),\n bufferSize,\n bufferSize,\n );\n\n viewport.setRenderedRange(range);\n viewport.setRenderedContentOffset(itemSize * range.start);\n }\n\n // TODO: maybe move to base class, can probably share with fixed size strategy.\n /**\n * Gets the visible range of data for the given start index. If the start index is too close to\n * the end of the list it may be backed up to ensure the estimated size of the range is enough to\n * fill the viewport.\n * Note: must not be called if `this._viewport` is null\n * @param startIndex The index to start the range at\n * @return a range estimated to be large enough to fill the viewport when rendered.\n */\n private _getVisibleRangeForIndex(startIndex: number): ListRange {\n const viewport = this._viewport!;\n const range: ListRange = {\n start: startIndex,\n end: startIndex + Math.ceil(viewport.getViewportSize() / this._averager.getAverageItemSize()),\n };\n const extra = range.end - viewport.getDataLength();\n if (extra > 0) {\n range.start = Math.max(0, range.start - extra);\n }\n return range;\n }\n\n // TODO: maybe move to base class, can probably share with fixed size strategy.\n /**\n * Expand the given range by the given amount in either direction.\n * Note: must not be called if `this._viewport` is null\n * @param range The range to expand\n * @param expandStart The number of items to expand the start of the range by.\n * @param expandEnd The number of items to expand the end of the range by.\n * @return The expanded range.\n */\n private _expandRange(range: ListRange, expandStart: number, expandEnd: number): ListRange {\n const viewport = this._viewport!;\n const start = Math.max(0, range.start - expandStart);\n const end = Math.min(viewport.getDataLength(), range.end + expandEnd);\n return {start, end};\n }\n\n /** Update the viewport's total content size. */\n private _updateTotalContentSize(renderedContentSize: number) {\n const viewport = this._viewport!;\n const renderedRange = viewport.getRenderedRange();\n const totalSize =\n renderedContentSize +\n (viewport.getDataLength() - (renderedRange.end - renderedRange.start)) *\n this._averager.getAverageItemSize();\n viewport.setTotalContentSize(totalSize);\n }\n}\n\n/**\n * Provider factory for `AutoSizeVirtualScrollStrategy` that simply extracts the already created\n * `AutoSizeVirtualScrollStrategy` from the given directive.\n * @param autoSizeDir The instance of `CdkAutoSizeVirtualScroll` to extract the\n * `AutoSizeVirtualScrollStrategy` from.\n */\nexport function _autoSizeVirtualScrollStrategyFactory(autoSizeDir: CdkAutoSizeVirtualScroll) {\n return autoSizeDir._scrollStrategy;\n}\n\n/** A virtual scroll strategy that supports unknown or dynamic size items. */\n@Directive({\n selector: 'cdk-virtual-scroll-viewport[autosize]',\n providers: [\n {\n provide: VIRTUAL_SCROLL_STRATEGY,\n useFactory: _autoSizeVirtualScrollStrategyFactory,\n deps: [forwardRef(() => CdkAutoSizeVirtualScroll)],\n },\n ],\n})\nexport class CdkAutoSizeVirtualScroll implements OnChanges {\n /**\n * The minimum amount of buffer rendered beyond the viewport (in pixels).\n * If the amount of buffer dips below this number, more items will be rendered. Defaults to 100px.\n */\n @Input()\n get minBufferPx(): number {\n return this._minBufferPx;\n }\n set minBufferPx(value: NumberInput) {\n this._minBufferPx = coerceNumberProperty(value);\n }\n _minBufferPx = 100;\n\n /**\n * The number of pixels worth of buffer to shoot for when rendering new items.\n * If the actual amount turns out to be less it will not necessarily trigger an additional\n * rendering cycle (as long as the amount of buffer is still greater than `minBufferPx`).\n * Defaults to 200px.\n */\n @Input()\n get maxBufferPx(): number {\n return this._maxBufferPx;\n }\n set maxBufferPx(value: NumberInput) {\n this._maxBufferPx = coerceNumberProperty(value);\n }\n _maxBufferPx = 200;\n\n /** The scroll strategy used by this directive. */\n _scrollStrategy = new AutoSizeVirtualScrollStrategy(this.minBufferPx, this.maxBufferPx);\n\n ngOnChanges() {\n this._scrollStrategy.updateBufferSize(this.minBufferPx, this.maxBufferPx);\n }\n}\n","/**\n * @license\n * Copyright Google LLC All Rights Reserved.\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://angular.dev/license\n */\n\nimport {NgModule} from '@angular/core';\nimport {CdkAutoSizeVirtualScroll} from './auto-size-virtual-scroll';\n\n@NgModule({\n imports: [CdkAutoSizeVirtualScroll],\n exports: [CdkAutoSizeVirtualScroll],\n})\nexport class ScrollingModule {}\n"],"names":["ItemSizeAverager","_defaultItemSize","defaultItemSize","getAverageItemSize","addSample","range","size","newTotalWeight","_totalWeight","Observable","Error","_lastScrollOffset","_lastRenderedContentSize","_lastRenderedContentOffset","_averager","reset","_viewport","onContentScrolled","_updateRenderedContentAfterScroll","_checkRenderedContentSize","onContentRendered","onRenderedOffsetChanged","ngDevMode","scrollOffset","viewport","measureScrollOffset","scrollMagnitude","Math","abs","scrollDelta","getRenderedRange","offsetCorrection","renderedRange","start","predictedOffset","getViewportSize","_minBufferPx","startBuffer","endBuffer","underscan","_renderContentForCurrentOffset","max","ceil","_maxBufferPx","floor","removeItems","min","end","unboundedRemoveItems","addItems","contentOffsetTo","removedSize","measureRangeSize","overscan","_removalFailures","contentOffset","setRenderedRange","setRenderedContentOffset","measureRenderedContentSize","_checkRenderedContentOffset","getOffsetToRenderedContentStart","firstVisibleIndex","getDataLength","itemSize","bufferSize","extra","_updateTotalContentSize","renderedContentSize","version","ngImport","i0","type","ScrollingModule","decorators"],"mappings":";;;;;;AA8BU,MAAAA,gBAAA,CAAgB;;;;;IAWxB,IAAAC,CAAAA,gBAAA,GAAAC,eAAA;;;AAOSC,EAAAA,kBAA+BA,GAAA;;AAGpC;WASJC,CAAAC,KAA2B,EAAAC,IAAA,EAAA;;AAGzB,IAAA,IAAAC,cAAA,EAAA;;;;QAKJ,IAAAC,CAAAA,YAAA,GAAAD,cAAA;;AAEE;;AAKQ,EAAA,KAAA,GAAA;AAEN,IAAA,IAAA,CAAA,gBAAA,GAAA,IAAA,CAAAN,gBAAA;AACA,IAAA,IAAA,CAAA,YAAA,GAAA,CAAA;;;mCAQsF,CAAA;AAGzB,EAAA,mBAAA,GAAA,IAAAQ,UAAA,CAAA,MAAA;;AAIvD,MAAA,MAAAC,KAAA,CAGA,4EAAA,GAAA,2BAAA,CAAA;AAE8D;AAC9D,GAAA,CAAA;;;;;EAgBLC,iBAAA;EAGDC,wBAAA;EAIFC,0BAAA;;;;;;;;QAkCE,CAAAC,SAAA,CAAAC,KAAA,EAAA;;;;;QAQF,CAAAC,SAAA,GAAA,IAAA;;mBAIEC,GAAA;;AA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