export interface PositionCacheConfig { totalItemsFn: () => number; sizeFn: (index: number) => number; defaultSizeFn: () => number; isUniformFn?: () => boolean; sparseExceptionsFn?: () => Record | null; onBuildFn?: () => void; } /** * Axis position cache: answers "what pixel offset does item N start at" (and the inverse) for row * heights and column widths without a per-question walk over the items. * * The class itself owns only the LIFECYCLE — when to (re)build, whether the built data is still * current, and invalidation. Every lookup is delegated to one of three interchangeable * strategies, chosen per build from the configured providers (`./strategy` has the contract): * * - {@link UniformPositionStrategy} — all items share one size; pure arithmetic, O(1) build. * Chosen when `isUniformFn` reports uniform sizes. * - {@link SparsePositionStrategy} — a uniform base plus few per-index overrides (e.g. measured * oversized rows); O(exceptions) build. Chosen when `sparseExceptionsFn` returns the overrides. * - {@link PrefixSumPositionStrategy} — fully heterogeneous sizes; O(totalItems) build, the * general fallback. * * @class PositionCache */ export declare class PositionCache { #private; /** * The total number of items (rows or columns) read at build time. * * @type {number} */ totalItems: number; /** * Increments on every {@link PositionCache#build}, in any mode. * * A caller that must not be served a build taken while its own inputs were incomplete can * snapshot this and compare afterwards. `isCurrent()` cannot answer that: an invalidate followed * by a rebuild leaves it `true` both before and after. * * @type {number} */ buildSeq: number; /** * @param {object} config The configuration object. * @param {Function} config.totalItemsFn A function that returns the total number of items (rows or columns). * @param {Function} config.sizeFn A function that returns the size for a given index. * @param {Function} config.defaultSizeFn A function that returns the default size for items * that return NaN/undefined. * @param {Function} [config.isUniformFn] Optional predicate; when `true`, all items share one size. * @param {Function} [config.sparseExceptionsFn] Optional provider of per-index size overrides * on top of a uniform base. * @param {Function} [config.onBuildFn] Optional callback invoked on every (re)build. */ constructor({ totalItemsFn, sizeFn, defaultSizeFn, isUniformFn, sparseExceptionsFn, onBuildFn, }: PositionCacheConfig); /** * The prefix sum array when the current strategy holds one (prefix-sum mode); `null` in the * uniform and sparse modes and while the cache is not built. Kept for the `isBuilt()` type * guard and its consumers. * * @type {Float64Array|null} */ get prefixSum(): Float64Array | null; /** * Builds the lookup strategy by reading the current total items, size function, and default * size from the configured providers: uniform when the uniform predicate holds, sparse when * the exceptions provider returns overrides, and the full prefix-sum walk otherwise. */ build(): void; /** * Returns the cumulative size at an index (sum of items 0..index-1). * * @param {number} index The item index. * @returns {number} The cumulative size before this index, or `0` when the cache is not built. */ getOffset(index: number): number; /** * Finds the item index at a given pixel offset. * * @param {number} offset The pixel offset. * @returns {number} The index whose cumulative start position is at or just before the offset. * Returns `0` when there are no items or the cache is not built. */ findIndexAtOffset(offset: number): number; /** * Returns the size of a single item at the given index. * * @param {number} index The item index. * @returns {number} The size of the item, or `0` outside the item range or when not built. */ getSizeAt(index: number): number; /** * Returns the total size of all items. * * @returns {number} */ getTotalSize(): number; /** * Builds the lookup strategy only when the cache is not yet built or the item count has * changed. */ ensureBuilt(): void; /** * Invalidates the cache so it will be rebuilt on the next * {@link PositionCache#ensureBuilt} call. */ invalidate(): void; /** * Returns whether the cache holds a prefix-sum array (heterogeneous mode). The uniform and * sparse strategies keep `prefixSum` as `null`, so this is `false` there; use it only as the * prefix-sum type guard. * * @returns {boolean} */ isBuilt(): this is PositionCache & { prefixSum: Float64Array; }; /** * Returns whether the cache currently holds valid built data for the current item count, in any * mode. Unlike {@link PositionCache#isBuilt} (a prefix-sum-mode type guard that is always `false` * in the uniform and sparse modes), this reflects the real build/invalidate state: * {@link PositionCache#build} sets it regardless of mode, {@link PositionCache#invalidate} clears * it, and a changed item count makes it stale (mirroring {@link PositionCache#ensureBuilt}). It is * the signal for "the sizes the pre-render calculators read are still current" — e.g. * `markOversizedRows` invalidates the row cache here when it finds a genuinely oversized row. * * @returns {boolean} */ isCurrent(): boolean; }