react-anchorlist 0.1.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.
Files changed (37) hide show
  1. package/dist/components/ChatVirtualList.d.ts +6 -0
  2. package/dist/components/ChatVirtualList.d.ts.map +1 -0
  3. package/dist/components/VirtualItem.d.ts +15 -0
  4. package/dist/components/VirtualItem.d.ts.map +1 -0
  5. package/dist/components/VirtualList.d.ts +5 -0
  6. package/dist/components/VirtualList.d.ts.map +1 -0
  7. package/dist/components/VirtualScroller.d.ts +12 -0
  8. package/dist/components/VirtualScroller.d.ts.map +1 -0
  9. package/dist/core/binarySearch.d.ts +5 -0
  10. package/dist/core/binarySearch.d.ts.map +1 -0
  11. package/dist/core/itemSizeCache.d.ts +18 -0
  12. package/dist/core/itemSizeCache.d.ts.map +1 -0
  13. package/dist/core/offsetMap.d.ts +19 -0
  14. package/dist/core/offsetMap.d.ts.map +1 -0
  15. package/dist/core/rangeCalc.d.ts +12 -0
  16. package/dist/core/rangeCalc.d.ts.map +1 -0
  17. package/dist/hooks/useAtBottom.d.ts +3 -0
  18. package/dist/hooks/useAtBottom.d.ts.map +1 -0
  19. package/dist/hooks/useChatVirtualizer.d.ts +23 -0
  20. package/dist/hooks/useChatVirtualizer.d.ts.map +1 -0
  21. package/dist/hooks/useFollowOutput.d.ts +14 -0
  22. package/dist/hooks/useFollowOutput.d.ts.map +1 -0
  23. package/dist/hooks/usePagination.d.ts +9 -0
  24. package/dist/hooks/usePagination.d.ts.map +1 -0
  25. package/dist/hooks/useScrollAnchor.d.ts +9 -0
  26. package/dist/hooks/useScrollAnchor.d.ts.map +1 -0
  27. package/dist/hooks/useScrollToIndex.d.ts +6 -0
  28. package/dist/hooks/useScrollToIndex.d.ts.map +1 -0
  29. package/dist/hooks/useVirtualEngine.d.ts +10 -0
  30. package/dist/hooks/useVirtualEngine.d.ts.map +1 -0
  31. package/dist/index.cjs +1 -0
  32. package/dist/index.d.ts +6 -0
  33. package/dist/index.d.ts.map +1 -0
  34. package/dist/index.js +592 -0
  35. package/dist/types.d.ts +120 -0
  36. package/dist/types.d.ts.map +1 -0
  37. package/package.json +43 -0
@@ -0,0 +1,6 @@
1
+ import { ChatVirtualListHandle, ChatVirtualListProps } from '../types';
2
+ import * as React from "react";
3
+ export declare const ChatVirtualList: <T>(props: ChatVirtualListProps<T> & {
4
+ ref?: React.Ref<ChatVirtualListHandle>;
5
+ }) => React.ReactElement;
6
+ //# sourceMappingURL=ChatVirtualList.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ChatVirtualList.d.ts","sourceRoot":"","sources":["../../src/components/ChatVirtualList.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAK9B,OAAO,KAAK,EAAE,qBAAqB,EAAE,oBAAoB,EAAe,MAAM,UAAU,CAAA;AA6FxF,eAAO,MAAM,eAAe,EAAuC,CAAC,CAAC,EACnE,KAAK,EAAE,oBAAoB,CAAC,CAAC,CAAC,GAAG;IAAE,GAAG,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,qBAAqB,CAAC,CAAA;CAAE,KACxE,KAAK,CAAC,YAAY,CAAA"}
@@ -0,0 +1,15 @@
1
+ import { VirtualItem } from '../types';
2
+
3
+ interface VirtualItemProps {
4
+ virtualItem: VirtualItem<unknown>;
5
+ measureItem: (key: string | number, size: number) => void;
6
+ children: React.ReactNode;
7
+ }
8
+ /**
9
+ * Wrapper for a single virtualized item.
10
+ * - Positioned with CSS transform (GPU compositor — no layout reflow)
11
+ * - ResizeObserver measures real height and reports back to the engine
12
+ */
13
+ export declare function VirtualItemComponent({ virtualItem, measureItem, children, }: VirtualItemProps): import("react/jsx-runtime").JSX.Element;
14
+ export {};
15
+ //# sourceMappingURL=VirtualItem.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"VirtualItem.d.ts","sourceRoot":"","sources":["../../src/components/VirtualItem.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA;AAE3C,UAAU,gBAAgB;IACxB,WAAW,EAAE,WAAW,CAAC,OAAO,CAAC,CAAA;IACjC,WAAW,EAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,IAAI,EAAE,MAAM,KAAK,IAAI,CAAA;IACzD,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;CAC1B;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,EACnC,WAAW,EACX,WAAW,EACX,QAAQ,GACT,EAAE,gBAAgB,2CA6BlB"}
@@ -0,0 +1,5 @@
1
+ import { VirtualListProps } from '../types';
2
+
3
+ /** Simple virtualized list — no chat-specific features. Good for ticket lists, selects, etc. */
4
+ export declare function VirtualList<T>({ data, itemContent, computeItemKey, estimatedItemSize, overscan, onEndReached, endReachedThreshold, components, className, style, }: VirtualListProps<T>): import("react/jsx-runtime").JSX.Element;
5
+ //# sourceMappingURL=VirtualList.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"VirtualList.d.ts","sourceRoot":"","sources":["../../src/components/VirtualList.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAe,gBAAgB,EAAE,MAAM,UAAU,CAAA;AAE7D,gGAAgG;AAChG,wBAAgB,WAAW,CAAC,CAAC,EAAE,EAC7B,IAAI,EACJ,WAAW,EACX,cAAc,EACd,iBAAsB,EACtB,QAAY,EACZ,YAAY,EACZ,mBAAyB,EACzB,UAAe,EACf,SAAS,EACT,KAAK,GACN,EAAE,gBAAgB,CAAC,CAAC,CAAC,2CAoDrB"}
@@ -0,0 +1,12 @@
1
+ import type * as React from "react";
2
+ interface VirtualScrollerProps {
3
+ scrollerRef: React.RefObject<HTMLDivElement>;
4
+ totalSize: number;
5
+ children: React.ReactNode;
6
+ className?: string;
7
+ style?: React.CSSProperties;
8
+ }
9
+ /** Scrollable container. Inner div has the virtual total height. */
10
+ export declare function VirtualScroller({ scrollerRef, totalSize, children, className, style, }: VirtualScrollerProps): import("react/jsx-runtime").JSX.Element;
11
+ export {};
12
+ //# sourceMappingURL=VirtualScroller.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"VirtualScroller.d.ts","sourceRoot":"","sources":["../../src/components/VirtualScroller.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,KAAK,MAAM,OAAO,CAAA;AAEnC,UAAU,oBAAoB;IAC5B,WAAW,EAAE,KAAK,CAAC,SAAS,CAAC,cAAc,CAAC,CAAA;IAC5C,SAAS,EAAE,MAAM,CAAA;IACjB,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;IACzB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,KAAK,CAAC,EAAE,KAAK,CAAC,aAAa,CAAA;CAC5B;AAED,oEAAoE;AACpE,wBAAgB,eAAe,CAAC,EAC9B,WAAW,EACX,SAAS,EACT,QAAQ,EACR,SAAS,EACT,KAAK,GACN,EAAE,oBAAoB,2CAYtB"}
@@ -0,0 +1,5 @@
1
+ /** O(log n) — finds index of first item whose top edge is >= scrollTop */
2
+ export declare function findFirstVisibleIndex(offsets: number[], scrollTop: number): number;
3
+ /** Linear scan from end — finds the last item whose top edge is within scrollBottom */
4
+ export declare function findLastVisibleIndex(offsets: number[], _sizes: number[], scrollBottom: number): number;
5
+ //# sourceMappingURL=binarySearch.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"binarySearch.d.ts","sourceRoot":"","sources":["../../src/core/binarySearch.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,CAWlF;AAED,uFAAuF;AACvF,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,MAAM,EAAE,EACjB,MAAM,EAAE,MAAM,EAAE,EAChB,YAAY,EAAE,MAAM,GACnB,MAAM,CAMR"}
@@ -0,0 +1,18 @@
1
+ import { OffsetMap } from './offsetMap';
2
+
3
+ /**
4
+ * Persists measured item heights by key.
5
+ * Survives re-renders and item reordering — heights are re-applied whenever
6
+ * the OffsetMap is rebuilt.
7
+ */
8
+ export declare class ItemSizeCache {
9
+ private cache;
10
+ get(key: string | number): number | undefined;
11
+ set(key: string | number, size: number): void;
12
+ has(key: string | number): boolean;
13
+ delete(key: string | number): void;
14
+ clear(): void;
15
+ /** Re-applies all cached sizes to the OffsetMap using a key→index map */
16
+ applyToOffsetMap(offsetMap: OffsetMap, keyToIndex: Map<string | number, number>): void;
17
+ }
18
+ //# sourceMappingURL=itemSizeCache.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"itemSizeCache.d.ts","sourceRoot":"","sources":["../../src/core/itemSizeCache.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAE5C;;;;GAIG;AACH,qBAAa,aAAa;IACxB,OAAO,CAAC,KAAK,CAA0C;IAEvD,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,SAAS;IAI7C,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI;IAI7C,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO;IAIlC,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;IAIlC,KAAK,IAAI,IAAI;IAIb,yEAAyE;IACzE,gBAAgB,CACd,SAAS,EAAE,SAAS,EACpB,UAAU,EAAE,GAAG,CAAC,MAAM,GAAG,MAAM,EAAE,MAAM,CAAC,GACvC,IAAI;CAQR"}
@@ -0,0 +1,19 @@
1
+ export declare class OffsetMap {
2
+ private offsets;
3
+ private sizes;
4
+ private defaultSize;
5
+ constructor(count: number, defaultSize: number);
6
+ private _recalcFrom;
7
+ getOffset(index: number): number;
8
+ getSize(index: number): number;
9
+ /** Returns true if the value changed */
10
+ setSize(index: number, size: number): boolean;
11
+ prepend(count: number): void;
12
+ append(count: number): void;
13
+ resize(newCount: number): void;
14
+ totalSize(): number;
15
+ get count(): number;
16
+ getOffsets(): number[];
17
+ getSizes(): number[];
18
+ }
19
+ //# sourceMappingURL=offsetMap.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"offsetMap.d.ts","sourceRoot":"","sources":["../../src/core/offsetMap.ts"],"names":[],"mappings":"AAAA,qBAAa,SAAS;IACpB,OAAO,CAAC,OAAO,CAAU;IACzB,OAAO,CAAC,KAAK,CAAU;IACvB,OAAO,CAAC,WAAW,CAAQ;gBAEf,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM;IAO9C,OAAO,CAAC,WAAW;IASnB,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM;IAIhC,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM;IAI9B,wCAAwC;IACxC,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO;IAO7C,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAO5B,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAS3B,MAAM,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI;IAU9B,SAAS,IAAI,MAAM;IAMnB,IAAI,KAAK,IAAI,MAAM,CAElB;IAED,UAAU,IAAI,MAAM,EAAE;IAItB,QAAQ,IAAI,MAAM,EAAE;CAGrB"}
@@ -0,0 +1,12 @@
1
+ export interface RenderRange {
2
+ start: number;
3
+ end: number;
4
+ }
5
+ /** Applies overscan buffer to the visible range, clamped to [0, itemCount-1] */
6
+ export declare function calcRenderRange(params: {
7
+ firstVisible: number;
8
+ lastVisible: number;
9
+ itemCount: number;
10
+ overscan: number;
11
+ }): RenderRange;
12
+ //# sourceMappingURL=rangeCalc.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rangeCalc.d.ts","sourceRoot":"","sources":["../../src/core/rangeCalc.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,WAAW;IAC1B,KAAK,EAAE,MAAM,CAAA;IACb,GAAG,EAAE,MAAM,CAAA;CACZ;AAED,gFAAgF;AAChF,wBAAgB,eAAe,CAAC,MAAM,EAAE;IACtC,YAAY,EAAE,MAAM,CAAA;IACpB,WAAW,EAAE,MAAM,CAAA;IACnB,SAAS,EAAE,MAAM,CAAA;IACjB,QAAQ,EAAE,MAAM,CAAA;CACjB,GAAG,WAAW,CAOd"}
@@ -0,0 +1,3 @@
1
+ /** Returns true when the scroll container is within `threshold` px of the bottom */
2
+ export declare function useAtBottom(scrollerRef: React.RefObject<HTMLDivElement>, threshold: number): boolean;
3
+ //# sourceMappingURL=useAtBottom.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useAtBottom.d.ts","sourceRoot":"","sources":["../../src/hooks/useAtBottom.ts"],"names":[],"mappings":"AAEA,oFAAoF;AACpF,wBAAgB,WAAW,CACzB,WAAW,EAAE,KAAK,CAAC,SAAS,CAAC,cAAc,CAAC,EAC5C,SAAS,EAAE,MAAM,GAChB,OAAO,CA4BT"}
@@ -0,0 +1,23 @@
1
+ import { UseChatVirtualizerReturn } from '../types';
2
+
3
+ /**
4
+ * Composites all virtual engine hooks into a single chat-optimized hook.
5
+ * Handles: virtualization, scroll anchor (no-flicker prepend), stick-to-bottom,
6
+ * start/end reached callbacks, and programmatic scroll-to-key.
7
+ */
8
+ export declare function useChatVirtualizer<T>(options: {
9
+ items: T[];
10
+ getKey: (item: T, index: number) => string | number;
11
+ estimatedItemSize?: number;
12
+ overscan?: number;
13
+ atBottomThreshold?: number;
14
+ followOutput?: "auto" | "smooth" | false;
15
+ initialAlignment?: "top" | "bottom";
16
+ onStartReached?: () => void | Promise<void>;
17
+ onEndReached?: () => void | Promise<void>;
18
+ startReachedThreshold?: number;
19
+ endReachedThreshold?: number;
20
+ scrollToMessageKey?: string | number | null;
21
+ onScrollToMessageComplete?: () => void;
22
+ }): UseChatVirtualizerReturn<T>;
23
+ //# sourceMappingURL=useChatVirtualizer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useChatVirtualizer.d.ts","sourceRoot":"","sources":["../../src/hooks/useChatVirtualizer.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAqB,wBAAwB,EAAE,MAAM,UAAU,CAAA;AAE3E;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,CAAC,EAAE,OAAO,EAAE;IAC7C,KAAK,EAAE,CAAC,EAAE,CAAA;IACV,MAAM,EAAE,CAAC,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,KAAK,MAAM,GAAG,MAAM,CAAA;IACnD,iBAAiB,CAAC,EAAE,MAAM,CAAA;IAC1B,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,iBAAiB,CAAC,EAAE,MAAM,CAAA;IAC1B,YAAY,CAAC,EAAE,MAAM,GAAG,QAAQ,GAAG,KAAK,CAAA;IACxC,gBAAgB,CAAC,EAAE,KAAK,GAAG,QAAQ,CAAA;IACnC,cAAc,CAAC,EAAE,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IAC3C,YAAY,CAAC,EAAE,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IACzC,qBAAqB,CAAC,EAAE,MAAM,CAAA;IAC9B,mBAAmB,CAAC,EAAE,MAAM,CAAA;IAC5B,kBAAkB,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAA;IAC3C,yBAAyB,CAAC,EAAE,MAAM,IAAI,CAAA;CACvC,GAAG,wBAAwB,CAAC,CAAC,CAAC,CA6G9B"}
@@ -0,0 +1,14 @@
1
+ import { ScrollToIndexOpts } from '../types';
2
+
3
+ /**
4
+ * Automatically scrolls to the last item when new items are appended
5
+ * and the user is already at the bottom.
6
+ * Uses useLayoutEffect to run before paint — zero visual lag.
7
+ */
8
+ export declare function useFollowOutput(params: {
9
+ itemCount: number;
10
+ isAtBottom: boolean;
11
+ scrollToIndex: (index: number, opts?: ScrollToIndexOpts) => void;
12
+ mode: "auto" | "smooth" | false;
13
+ }): void;
14
+ //# sourceMappingURL=useFollowOutput.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useFollowOutput.d.ts","sourceRoot":"","sources":["../../src/hooks/useFollowOutput.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAA;AAEjD;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE;IACtC,SAAS,EAAE,MAAM,CAAA;IACjB,UAAU,EAAE,OAAO,CAAA;IACnB,aAAa,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,iBAAiB,KAAK,IAAI,CAAA;IAChE,IAAI,EAAE,MAAM,GAAG,QAAQ,GAAG,KAAK,CAAA;CAChC,GAAG,IAAI,CAcP"}
@@ -0,0 +1,9 @@
1
+ import { UsePaginationOptions, UsePaginationReturn } from '../types';
2
+
3
+ /**
4
+ * Manages paginated data with deduplication.
5
+ * Supports append, prepend, and bidirectional loading.
6
+ * Compatible with any fetcher (SWR, TanStack, raw fetch, etc.).
7
+ */
8
+ export declare function usePagination<T>(options: UsePaginationOptions<T>): UsePaginationReturn<T>;
9
+ //# sourceMappingURL=usePagination.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"usePagination.d.ts","sourceRoot":"","sources":["../../src/hooks/usePagination.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAA;AAEzE;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAAE,OAAO,EAAE,oBAAoB,CAAC,CAAC,CAAC,GAAG,mBAAmB,CAAC,CAAC,CAAC,CAsIzF"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Prevents scroll jump when items are prepended.
3
+ * Call prepareAnchor() BEFORE adding items to the top.
4
+ * useLayoutEffect adjusts scrollTop synchronously before the browser paints.
5
+ */
6
+ export declare function useScrollAnchor(scrollerRef: React.RefObject<HTMLDivElement>, itemCount: number): {
7
+ prepareAnchor: () => void;
8
+ };
9
+ //# sourceMappingURL=useScrollAnchor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useScrollAnchor.d.ts","sourceRoot":"","sources":["../../src/hooks/useScrollAnchor.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,wBAAgB,eAAe,CAC7B,WAAW,EAAE,KAAK,CAAC,SAAS,CAAC,cAAc,CAAC,EAC5C,SAAS,EAAE,MAAM,GAChB;IAAE,aAAa,EAAE,MAAM,IAAI,CAAA;CAAE,CA0B/B"}
@@ -0,0 +1,6 @@
1
+ import { OffsetMap } from '../core/offsetMap';
2
+ import { ScrollToIndexOpts } from '../types';
3
+
4
+ /** Programmatic scroll to a given item index with alignment support */
5
+ export declare function useScrollToIndex(scrollerRef: React.RefObject<HTMLDivElement>, offsetMapRef: React.MutableRefObject<OffsetMap | null>): (index: number, opts?: ScrollToIndexOpts) => void;
6
+ //# sourceMappingURL=useScrollToIndex.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useScrollToIndex.d.ts","sourceRoot":"","sources":["../../src/hooks/useScrollToIndex.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA;AAClD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAA;AAEjD,uEAAuE;AACvE,wBAAgB,gBAAgB,CAC9B,WAAW,EAAE,KAAK,CAAC,SAAS,CAAC,cAAc,CAAC,EAC5C,YAAY,EAAE,KAAK,CAAC,gBAAgB,CAAC,SAAS,GAAG,IAAI,CAAC,GACrD,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,iBAAiB,KAAK,IAAI,CA2BnD"}
@@ -0,0 +1,10 @@
1
+ import { UseVirtualEngineReturn } from '../types';
2
+
3
+ export declare function useVirtualEngine<T>(options: {
4
+ items: T[];
5
+ getKey: (item: T, index: number) => string | number;
6
+ estimatedItemSize: number;
7
+ overscan: number;
8
+ initialAlignment: "top" | "bottom";
9
+ }): UseVirtualEngineReturn<T>;
10
+ //# sourceMappingURL=useVirtualEngine.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useVirtualEngine.d.ts","sourceRoot":"","sources":["../../src/hooks/useVirtualEngine.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,sBAAsB,EAAe,MAAM,UAAU,CAAA;AA6BnE,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,OAAO,EAAE;IAC3C,KAAK,EAAE,CAAC,EAAE,CAAA;IACV,MAAM,EAAE,CAAC,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,KAAK,MAAM,GAAG,MAAM,CAAA;IACnD,iBAAiB,EAAE,MAAM,CAAA;IACzB,QAAQ,EAAE,MAAM,CAAA;IAChB,gBAAgB,EAAE,KAAK,GAAG,QAAQ,CAAA;CACnC,GAAG,sBAAsB,CAAC,CAAC,CAAC,CA2K5B"}
package/dist/index.cjs ADDED
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const A=require("react/jsx-runtime"),l=require("react");function _(s){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(s){for(const t in s)if(t!=="default"){const r=Object.getOwnPropertyDescriptor(s,t);Object.defineProperty(e,t,r.get?r:{enumerable:!0,get:()=>s[t]})}}return e.default=s,Object.freeze(e)}const D=_(l);class q{constructor(e,t){this.defaultSize=t,this.sizes=e>0?Array(e).fill(t):[],this.offsets=e>0?Array(e).fill(0):[],e>0&&this._recalcFrom(0)}_recalcFrom(e){for(let t=e;t<this.sizes.length;t++)this.offsets[t]=t===0?0:(this.offsets[t-1]??0)+(this.sizes[t-1]??this.defaultSize)}getOffset(e){return this.offsets[e]??0}getSize(e){return this.sizes[e]??this.defaultSize}setSize(e,t){return this.sizes[e]===t?!1:(this.sizes[e]=t,this._recalcFrom(e+1),!0)}prepend(e){const t=Array(e).fill(this.defaultSize);this.sizes=[...t,...this.sizes],this.offsets=Array(this.sizes.length).fill(0),this._recalcFrom(0)}append(e){const t=this.sizes.length;for(let r=0;r<e;r++)this.sizes.push(this.defaultSize),this.offsets.push(0);this._recalcFrom(t)}resize(e){const t=this.sizes.length;e>t?this.append(e-t):e<t&&(this.sizes=this.sizes.slice(0,e),this.offsets=this.offsets.slice(0,e))}totalSize(){if(this.sizes.length===0)return 0;const e=this.sizes.length-1;return(this.offsets[e]??0)+(this.sizes[e]??this.defaultSize)}get count(){return this.sizes.length}getOffsets(){return this.offsets}getSizes(){return this.sizes}}class G{constructor(){this.cache=new Map}get(e){return this.cache.get(e)}set(e,t){this.cache.set(e,t)}has(e){return this.cache.has(e)}delete(e){this.cache.delete(e)}clear(){this.cache.clear()}applyToOffsetMap(e,t){for(const[r,i]of this.cache){const a=t.get(r);a!==void 0&&e.setSize(a,i)}}}function U(s,e){if(s.length===0)return 0;let t=0,r=s.length-1;for(;t<r;){const i=t+r>>1;(s[i]??0)<e?t=i+1:r=i}return Math.max(0,t>0&&(s[t]??0)>e?t-1:t)}function Z(s,e,t){if(s.length===0)return 0;for(let r=s.length-1;r>=0;r--)if((s[r]??0)<t)return r;return 0}function Y(s){const{firstVisible:e,lastVisible:t,itemCount:r,overscan:i}=s;return r===0?{start:0,end:-1}:{start:Math.max(0,e-i),end:Math.min(r-1,t+i)}}function $(s,e){return l.useCallback((t,r)=>{const i=s.current,a=e.current;if(!i||!a)return;const c=a.getOffset(t),d=a.getSize(t),S=(r==null?void 0:r.align)??"start",y=(r==null?void 0:r.behavior)??"auto",v=(r==null?void 0:r.offset)??0;let T;S==="start"?T=c+v:S==="center"?T=c-i.clientHeight/2+d/2+v:T=c-i.clientHeight+d+v,i.scrollTo({top:Math.max(0,T),behavior:y})},[s,e])}function J(s,e){switch(e.type){case"SCROLL":return{...s,scrollTop:e.scrollTop,totalSize:e.totalSize,renderRange:e.renderRange};case"RESIZE_CONTAINER":return{...s,containerHeight:e.height,totalSize:e.totalSize,renderRange:e.renderRange};case"MEASURE":return{...s,totalSize:e.totalSize};case"ITEMS_CHANGED":return{...s,renderRange:e.renderRange,totalSize:e.totalSize}}}function F(s){const{items:e,getKey:t,estimatedItemSize:r,overscan:i,initialAlignment:a}=s,c=l.useRef(null),d=l.useRef(null),S=l.useRef(new G),y=l.useRef([]),v=l.useRef(!1),T=l.useRef(i);T.current=i,d.current||(d.current=new q(e.length,r));const z=l.useCallback((o,m)=>{const n=d.current;if(!n||n.count===0)return{start:0,end:-1};const u=n.getOffsets(),h=n.getSizes(),x=U(u,o),P=Z(u,h,o+m);return Y({firstVisible:x,lastVisible:P,itemCount:n.count,overscan:T.current})},[]),[b,f]=l.useReducer(J,{renderRange:{start:0,end:Math.min(e.length-1,i*2)},scrollTop:0,containerHeight:0,totalSize:d.current.totalSize()});l.useEffect(()=>{const o=d.current,m=e.map((k,L)=>t(k,L)),n=y.current,u=n.length,h=m.length;h===0?o.resize(0):u===0?o.resize(h):h>u?n.length>0&&m[h-u]===n[0]?o.prepend(h-u):o.resize(h):h<u&&o.resize(h);const x=new Map;m.forEach((k,L)=>x.set(k,L)),S.current.applyToOffsetMap(o,x),y.current=m;const P=c.current,H=(P==null?void 0:P.scrollTop)??0,M=(P==null?void 0:P.clientHeight)??0,B=z(H,M);f({type:"ITEMS_CHANGED",renderRange:B,totalSize:o.totalSize()})},[e,t,z]),l.useEffect(()=>{const o=c.current;if(!o)return;const m=()=>{const n=d.current,u=o.scrollTop,h=o.clientHeight,x=z(u,h);f({type:"SCROLL",scrollTop:u,totalSize:n.totalSize(),renderRange:x})};return o.addEventListener("scroll",m,{passive:!0}),()=>o.removeEventListener("scroll",m)},[z]),l.useEffect(()=>{const o=c.current;if(!o)return;const m=new ResizeObserver(([n])=>{if(!n)return;const u=n.contentRect.height,h=d.current,x=o.scrollTop,P=z(x,u);f({type:"RESIZE_CONTAINER",height:u,totalSize:h.totalSize(),renderRange:P})});return m.observe(o),()=>m.disconnect()},[z]),l.useEffect(()=>{if(v.current||e.length===0)return;const o=c.current;o&&(a==="bottom"&&(o.scrollTop=o.scrollHeight),v.current=!0)},[a,e.length]);const w=l.useCallback((o,m)=>{const n=d.current;if(!n)return;S.current.set(o,m);const u=y.current.indexOf(o);if(u===-1)return;n.setSize(u,m)&&f({type:"MEASURE",totalSize:n.totalSize()})},[]),O=l.useCallback((o,m="auto")=>{var n;(n=c.current)==null||n.scrollTo({top:o,behavior:m})},[]),p=$(c,d),R=d.current,{start:I,end:E}=b.renderRange,j=[];if(R&&E>=I)for(let o=I;o<=E&&o<e.length;o++)j.push({key:y.current[o]??t(e[o],o),index:o,start:R.getOffset(o),size:R.getSize(o),data:e[o]});const g=c.current,C=g?g.scrollHeight-g.scrollTop-g.clientHeight:1/0;return{scrollerRef:c,virtualItems:j,totalSize:b.totalSize,measureItem:w,scrollToIndex:p,scrollToOffset:O,isAtTop:b.scrollTop<=0,isAtBottom:C<=0,scrollTop:b.scrollTop}}function Q(s,e){const t=l.useRef(0),r=l.useRef(0),i=l.useRef(!1),a=l.useCallback(()=>{const c=s.current;c&&(t.current=c.scrollTop,r.current=c.scrollHeight,i.current=!0)},[s]);return l.useLayoutEffect(()=>{if(!i.current)return;const c=s.current;if(!c)return;const d=c.scrollHeight-r.current;d>0&&(c.scrollTop=t.current+d),i.current=!1},[e,s]),{prepareAnchor:a}}function W(s,e){const[t,r]=l.useState(!0),i=l.useRef(null);return l.useEffect(()=>{const a=s.current;if(!a)return;const c=()=>{const S=a.scrollHeight-a.scrollTop-a.clientHeight;r(S<=e)},d=()=>{i.current!==null&&cancelAnimationFrame(i.current),i.current=requestAnimationFrame(c)};return a.addEventListener("scroll",d,{passive:!0}),c(),()=>{a.removeEventListener("scroll",d),i.current!==null&&cancelAnimationFrame(i.current)}},[s,e]),t}function X(s){const{itemCount:e,isAtBottom:t,scrollToIndex:r,mode:i}=s,a=l.useRef(e);l.useLayoutEffect(()=>{i&&(e>a.current&&t&&e>0&&r(e-1,{align:"end",behavior:i==="smooth"?"smooth":"auto"}),a.current=e)},[e,t,r,i])}function K(s){const{items:e,getKey:t,estimatedItemSize:r=80,overscan:i=5,atBottomThreshold:a=200,followOutput:c="auto",initialAlignment:d="bottom",onStartReached:S,onEndReached:y,startReachedThreshold:v=300,endReachedThreshold:T=300,scrollToMessageKey:z,onScrollToMessageComplete:b}=s,f=F({items:e,getKey:t,estimatedItemSize:r,overscan:i,initialAlignment:d}),w=W(f.scrollerRef,a),{prepareAnchor:O}=Q(f.scrollerRef,e.length);X({itemCount:e.length,isAtBottom:w,scrollToIndex:f.scrollToIndex,mode:c??!1});const p=l.useRef(!1);l.useEffect(()=>{const g=f.scrollerRef.current;if(!g||!S)return;const C=()=>{g.scrollTop<=v&&!p.current&&(p.current=!0,Promise.resolve(S()).finally(()=>{p.current=!1}))};return g.addEventListener("scroll",C,{passive:!0}),()=>g.removeEventListener("scroll",C)},[f.scrollerRef,S,v]);const R=l.useRef(!1);l.useEffect(()=>{const g=f.scrollerRef.current;if(!g||!y)return;const C=()=>{g.scrollHeight-g.scrollTop-g.clientHeight<=T&&!R.current&&(R.current=!0,Promise.resolve(y()).finally(()=>{R.current=!1}))};return g.addEventListener("scroll",C,{passive:!0}),()=>g.removeEventListener("scroll",C)},[f.scrollerRef,y,T]);const I=l.useRef(null);l.useEffect(()=>{if(!z||I.current===z)return;const g=e.findIndex((C,o)=>t(C,o)===z);g!==-1&&(I.current=z,f.scrollToIndex(g,{align:"center",behavior:"smooth"}),b==null||b())},[z,e,t,f,b]);const E=l.useCallback((g="auto")=>{e.length!==0&&f.scrollToIndex(e.length-1,{align:"end",behavior:g})},[e.length,f]),j=l.useCallback((g,C)=>{const o=e.findIndex((m,n)=>t(m,n)===g);o!==-1&&f.scrollToIndex(o,C)},[e,t,f]);return{scrollerRef:f.scrollerRef,virtualItems:f.virtualItems,totalSize:f.totalSize,measureItem:f.measureItem,scrollToIndex:f.scrollToIndex,scrollToBottom:E,scrollToKey:j,isAtBottom:w,prepareAnchor:O}}function N({scrollerRef:s,totalSize:e,children:t,className:r,style:i}){return A.jsx("div",{ref:s,className:r,style:{overflow:"auto",height:"100%",position:"relative",...i},children:A.jsx("div",{style:{height:e,position:"relative",width:"100%"},children:t})})}function V({virtualItem:s,measureItem:e,children:t}){const r=l.useRef(null);return l.useEffect(()=>{const i=r.current;if(!i)return;const a=new ResizeObserver(([c])=>{c&&e(s.key,c.contentRect.height)});return a.observe(i),()=>a.disconnect()},[s.key,e]),A.jsx("div",{ref:r,style:{position:"absolute",top:0,transform:`translateY(${s.start}px)`,width:"100%",minHeight:s.size},children:t})}function ee(s,e){const{data:t,itemContent:r,computeItemKey:i,estimatedItemSize:a=80,overscan:c=5,followOutput:d="auto",atBottomThreshold:S=200,initialAlignment:y="bottom",onStartReached:v,onEndReached:T,startReachedThreshold:z=300,endReachedThreshold:b=300,scrollToMessageKey:f,onScrollToMessageComplete:w,components:O={},className:p,style:R}=s,{scrollerRef:I,virtualItems:E,totalSize:j,measureItem:g,scrollToIndex:C,scrollToBottom:o,scrollToKey:m,isAtBottom:n,prepareAnchor:u}=K({items:t,getKey:(H,M)=>i(M,H),estimatedItemSize:a,overscan:c,atBottomThreshold:S,followOutput:d,initialAlignment:y,onStartReached:v,onEndReached:T,startReachedThreshold:z,endReachedThreshold:b,scrollToMessageKey:f,onScrollToMessageComplete:w});l.useImperativeHandle(e,()=>({scrollToBottom:o,scrollToIndex:C,scrollToKey:m,getScrollTop:()=>{var H;return((H=I.current)==null?void 0:H.scrollTop)??0},isAtBottom:()=>n,prepareAnchor:u}),[o,C,m,I,n,u]);const{Header:h,Footer:x,EmptyPlaceholder:P}=O;return t.length===0&&P?A.jsx(P,{}):A.jsxs("div",{style:{display:"flex",flexDirection:"column",height:"100%"},children:[h&&A.jsx(h,{}),A.jsx(N,{scrollerRef:I,totalSize:j,className:p,style:{flex:1,minHeight:0,...R},children:E.map(H=>A.jsx(V,{virtualItem:H,measureItem:g,children:r(H.index,H.data)},H.key))}),x&&A.jsx(x,{})]})}const te=l.forwardRef(ee);function re({data:s,itemContent:e,computeItemKey:t,estimatedItemSize:r=80,overscan:i=5,onEndReached:a,endReachedThreshold:c=300,components:d={},className:S,style:y}){const{scrollerRef:v,virtualItems:T,totalSize:z,measureItem:b}=F({items:s,getKey:(p,R)=>t(R,p),estimatedItemSize:r,overscan:i,initialAlignment:"top"});D.useEffect(()=>{const p=v.current;if(!p||!a)return;let R=!1;const I=()=>{p.scrollHeight-p.scrollTop-p.clientHeight<=c&&!R&&(R=!0,Promise.resolve(a()).finally(()=>{R=!1}))};return p.addEventListener("scroll",I,{passive:!0}),()=>p.removeEventListener("scroll",I)},[v,a,c]);const{Header:f,Footer:w,EmptyPlaceholder:O}=d;return s.length===0&&O?A.jsx(O,{}):A.jsxs("div",{style:{display:"flex",flexDirection:"column",height:"100%"},children:[f&&A.jsx(f,{}),A.jsx(N,{scrollerRef:v,totalSize:z,className:S,style:{flex:1,minHeight:0,...y},children:T.map(p=>A.jsx(V,{virtualItem:p,measureItem:b,children:e(p.index,p.data)},p.key))}),w&&A.jsx(w,{})]})}function se(s){const{fetcher:e,initialPage:t=1,direction:r="append",getKey:i,onPageLoaded:a,onError:c}=s,[d,S]=l.useState([]),[y,v]=l.useState(t),[T,z]=l.useState(!0),[b,f]=l.useState(!1),[w,O]=l.useState(!1),[p,R]=l.useState(!1),I=l.useRef(new Set),E=l.useRef(!1),j=l.useCallback(n=>i?n.filter(u=>{const h=i(u);return I.current.has(h)?!1:(I.current.add(h),!0)}):n,[i]),g=l.useCallback(async()=>{if(!(E.current||!T)){E.current=!0,R(!0);try{const n=y+1,u=await e(n),h=j(u.data);S(x=>r==="prepend"?[...h,...x]:[...x,...h]),v(n),z(u.hasNextPage),f(u.hasPrevPage),a==null||a(n,h)}catch(n){c==null||c(n instanceof Error?n:new Error(String(n)))}finally{R(!1),E.current=!1}}},[y,T,e,j,r,a,c]),C=l.useCallback(async()=>{if(!(E.current||!b)){E.current=!0,R(!0);try{const n=y-1,u=await e(n),h=j(u.data);S(x=>[...h,...x]),v(n),f(u.hasPrevPage),z(u.hasNextPage),a==null||a(n,h)}catch(n){c==null||c(n instanceof Error?n:new Error(String(n)))}finally{R(!1),E.current=!1}}},[y,b,e,j,a,c]),o=l.useCallback(async()=>{if(!E.current){E.current=!0,O(!0);try{const n=await e(t),u=n.data;if(i){const h=new Set(u.map(i));u.forEach(x=>I.current.add(i(x))),S(x=>{const P=x.filter(H=>!h.has(i(H)));return r==="prepend"?[...u,...P]:[...P,...u]})}else S(u);v(t),z(n.hasNextPage),f(n.hasPrevPage),a==null||a(t,u)}catch(n){c==null||c(n instanceof Error?n:new Error(String(n)))}finally{O(!1),E.current=!1}}},[e,t,i,r,a,c]),m=l.useCallback(()=>{S([]),v(t),z(!0),f(!1),O(!1),R(!1),I.current.clear(),E.current=!1},[t]);return{items:d,loadNextPage:g,loadPrevPage:C,hasNextPage:T,hasPrevPage:b,loading:w,loadingMore:p,refresh:o,reset:m,currentPage:y}}exports.ChatVirtualList=te;exports.VirtualList=re;exports.useChatVirtualizer=K;exports.usePagination=se;
@@ -0,0 +1,6 @@
1
+ export { ChatVirtualList } from './components/ChatVirtualList';
2
+ export { VirtualList } from './components/VirtualList';
3
+ export { useChatVirtualizer } from './hooks/useChatVirtualizer';
4
+ export { usePagination } from './hooks/usePagination';
5
+ export type { ChatVirtualListProps, ChatVirtualListHandle, VirtualListProps, VirtualItem, ScrollToIndexOpts, VirtualListComponents, UsePaginationOptions, UsePaginationReturn, UseChatVirtualizerReturn, } from './types';
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAA;AAC9D,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAA;AACtD,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAA;AAC/D,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAA;AACrD,YAAY,EACV,oBAAoB,EACpB,qBAAqB,EACrB,gBAAgB,EAChB,WAAW,EACX,iBAAiB,EACjB,qBAAqB,EACrB,oBAAoB,EACpB,mBAAmB,EACnB,wBAAwB,GACzB,MAAM,SAAS,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,592 @@
1
+ import { jsx as b, jsxs as _ } from "react/jsx-runtime";
2
+ import * as Z from "react";
3
+ import { useCallback as C, useRef as A, useReducer as q, useEffect as K, useLayoutEffect as k, useState as L, forwardRef as Y, useImperativeHandle as $ } from "react";
4
+ class J {
5
+ constructor(e, t) {
6
+ this.defaultSize = t, this.sizes = e > 0 ? Array(e).fill(t) : [], this.offsets = e > 0 ? Array(e).fill(0) : [], e > 0 && this._recalcFrom(0);
7
+ }
8
+ _recalcFrom(e) {
9
+ for (let t = e; t < this.sizes.length; t++)
10
+ this.offsets[t] = t === 0 ? 0 : (this.offsets[t - 1] ?? 0) + (this.sizes[t - 1] ?? this.defaultSize);
11
+ }
12
+ getOffset(e) {
13
+ return this.offsets[e] ?? 0;
14
+ }
15
+ getSize(e) {
16
+ return this.sizes[e] ?? this.defaultSize;
17
+ }
18
+ /** Returns true if the value changed */
19
+ setSize(e, t) {
20
+ return this.sizes[e] === t ? !1 : (this.sizes[e] = t, this._recalcFrom(e + 1), !0);
21
+ }
22
+ prepend(e) {
23
+ const t = Array(e).fill(this.defaultSize);
24
+ this.sizes = [...t, ...this.sizes], this.offsets = Array(this.sizes.length).fill(0), this._recalcFrom(0);
25
+ }
26
+ append(e) {
27
+ const t = this.sizes.length;
28
+ for (let n = 0; n < e; n++)
29
+ this.sizes.push(this.defaultSize), this.offsets.push(0);
30
+ this._recalcFrom(t);
31
+ }
32
+ resize(e) {
33
+ const t = this.sizes.length;
34
+ e > t ? this.append(e - t) : e < t && (this.sizes = this.sizes.slice(0, e), this.offsets = this.offsets.slice(0, e));
35
+ }
36
+ totalSize() {
37
+ if (this.sizes.length === 0) return 0;
38
+ const e = this.sizes.length - 1;
39
+ return (this.offsets[e] ?? 0) + (this.sizes[e] ?? this.defaultSize);
40
+ }
41
+ get count() {
42
+ return this.sizes.length;
43
+ }
44
+ getOffsets() {
45
+ return this.offsets;
46
+ }
47
+ getSizes() {
48
+ return this.sizes;
49
+ }
50
+ }
51
+ class Q {
52
+ constructor() {
53
+ this.cache = /* @__PURE__ */ new Map();
54
+ }
55
+ get(e) {
56
+ return this.cache.get(e);
57
+ }
58
+ set(e, t) {
59
+ this.cache.set(e, t);
60
+ }
61
+ has(e) {
62
+ return this.cache.has(e);
63
+ }
64
+ delete(e) {
65
+ this.cache.delete(e);
66
+ }
67
+ clear() {
68
+ this.cache.clear();
69
+ }
70
+ /** Re-applies all cached sizes to the OffsetMap using a key→index map */
71
+ applyToOffsetMap(e, t) {
72
+ for (const [n, s] of this.cache) {
73
+ const c = t.get(n);
74
+ c !== void 0 && e.setSize(c, s);
75
+ }
76
+ }
77
+ }
78
+ function W(o, e) {
79
+ if (o.length === 0) return 0;
80
+ let t = 0, n = o.length - 1;
81
+ for (; t < n; ) {
82
+ const s = t + n >> 1;
83
+ (o[s] ?? 0) < e ? t = s + 1 : n = s;
84
+ }
85
+ return Math.max(0, t > 0 && (o[t] ?? 0) > e ? t - 1 : t);
86
+ }
87
+ function X(o, e, t) {
88
+ if (o.length === 0) return 0;
89
+ for (let n = o.length - 1; n >= 0; n--)
90
+ if ((o[n] ?? 0) < t) return n;
91
+ return 0;
92
+ }
93
+ function ee(o) {
94
+ const { firstVisible: e, lastVisible: t, itemCount: n, overscan: s } = o;
95
+ return n === 0 ? { start: 0, end: -1 } : {
96
+ start: Math.max(0, e - s),
97
+ end: Math.min(n - 1, t + s)
98
+ };
99
+ }
100
+ function te(o, e) {
101
+ return C(
102
+ (t, n) => {
103
+ const s = o.current, c = e.current;
104
+ if (!s || !c) return;
105
+ const l = c.getOffset(t), h = c.getSize(t), p = (n == null ? void 0 : n.align) ?? "start", v = (n == null ? void 0 : n.behavior) ?? "auto", y = (n == null ? void 0 : n.offset) ?? 0;
106
+ let R;
107
+ p === "start" ? R = l + y : p === "center" ? R = l - s.clientHeight / 2 + h / 2 + y : R = l - s.clientHeight + h + y, s.scrollTo({ top: Math.max(0, R), behavior: v });
108
+ },
109
+ [o, e]
110
+ );
111
+ }
112
+ function re(o, e) {
113
+ switch (e.type) {
114
+ case "SCROLL":
115
+ return { ...o, scrollTop: e.scrollTop, totalSize: e.totalSize, renderRange: e.renderRange };
116
+ case "RESIZE_CONTAINER":
117
+ return { ...o, containerHeight: e.height, totalSize: e.totalSize, renderRange: e.renderRange };
118
+ case "MEASURE":
119
+ return { ...o, totalSize: e.totalSize };
120
+ case "ITEMS_CHANGED":
121
+ return { ...o, renderRange: e.renderRange, totalSize: e.totalSize };
122
+ }
123
+ }
124
+ function D(o) {
125
+ const { items: e, getKey: t, estimatedItemSize: n, overscan: s, initialAlignment: c } = o, l = A(null), h = A(null), p = A(new Q()), v = A([]), y = A(!1), R = A(s);
126
+ R.current = s, h.current || (h.current = new J(e.length, n));
127
+ const z = C((i, g) => {
128
+ const r = h.current;
129
+ if (!r || r.count === 0) return { start: 0, end: -1 };
130
+ const a = r.getOffsets(), f = r.getSizes(), T = W(a, i), P = X(a, f, i + g);
131
+ return ee({
132
+ firstVisible: T,
133
+ lastVisible: P,
134
+ itemCount: r.count,
135
+ overscan: R.current
136
+ });
137
+ }, []), [I, u] = q(re, {
138
+ renderRange: { start: 0, end: Math.min(e.length - 1, s * 2) },
139
+ scrollTop: 0,
140
+ containerHeight: 0,
141
+ totalSize: h.current.totalSize()
142
+ });
143
+ K(() => {
144
+ const i = h.current, g = e.map((N, V) => t(N, V)), r = v.current, a = r.length, f = g.length;
145
+ f === 0 ? i.resize(0) : a === 0 ? i.resize(f) : f > a ? r.length > 0 && g[f - a] === r[0] ? i.prepend(f - a) : i.resize(f) : f < a && i.resize(f);
146
+ const T = /* @__PURE__ */ new Map();
147
+ g.forEach((N, V) => T.set(N, V)), p.current.applyToOffsetMap(i, T), v.current = g;
148
+ const P = l.current, w = (P == null ? void 0 : P.scrollTop) ?? 0, B = (P == null ? void 0 : P.clientHeight) ?? 0, U = z(w, B);
149
+ u({ type: "ITEMS_CHANGED", renderRange: U, totalSize: i.totalSize() });
150
+ }, [e, t, z]), K(() => {
151
+ const i = l.current;
152
+ if (!i) return;
153
+ const g = () => {
154
+ const r = h.current, a = i.scrollTop, f = i.clientHeight, T = z(a, f);
155
+ u({ type: "SCROLL", scrollTop: a, totalSize: r.totalSize(), renderRange: T });
156
+ };
157
+ return i.addEventListener("scroll", g, { passive: !0 }), () => i.removeEventListener("scroll", g);
158
+ }, [z]), K(() => {
159
+ const i = l.current;
160
+ if (!i) return;
161
+ const g = new ResizeObserver(([r]) => {
162
+ if (!r) return;
163
+ const a = r.contentRect.height, f = h.current, T = i.scrollTop, P = z(T, a);
164
+ u({ type: "RESIZE_CONTAINER", height: a, totalSize: f.totalSize(), renderRange: P });
165
+ });
166
+ return g.observe(i), () => g.disconnect();
167
+ }, [z]), K(() => {
168
+ if (y.current || e.length === 0) return;
169
+ const i = l.current;
170
+ i && (c === "bottom" && (i.scrollTop = i.scrollHeight), y.current = !0);
171
+ }, [c, e.length]);
172
+ const M = C((i, g) => {
173
+ const r = h.current;
174
+ if (!r) return;
175
+ p.current.set(i, g);
176
+ const a = v.current.indexOf(i);
177
+ if (a === -1) return;
178
+ r.setSize(a, g) && u({ type: "MEASURE", totalSize: r.totalSize() });
179
+ }, []), O = C(
180
+ (i, g = "auto") => {
181
+ var r;
182
+ (r = l.current) == null || r.scrollTo({ top: i, behavior: g });
183
+ },
184
+ []
185
+ ), m = te(l, h), S = h.current, { start: E, end: x } = I.renderRange, F = [];
186
+ if (S && x >= E)
187
+ for (let i = E; i <= x && i < e.length; i++)
188
+ F.push({
189
+ key: v.current[i] ?? t(e[i], i),
190
+ index: i,
191
+ start: S.getOffset(i),
192
+ size: S.getSize(i),
193
+ data: e[i]
194
+ });
195
+ const d = l.current, H = d ? d.scrollHeight - d.scrollTop - d.clientHeight : 1 / 0;
196
+ return {
197
+ scrollerRef: l,
198
+ virtualItems: F,
199
+ totalSize: I.totalSize,
200
+ measureItem: M,
201
+ scrollToIndex: m,
202
+ scrollToOffset: O,
203
+ isAtTop: I.scrollTop <= 0,
204
+ isAtBottom: H <= 0,
205
+ scrollTop: I.scrollTop
206
+ };
207
+ }
208
+ function ne(o, e) {
209
+ const t = A(0), n = A(0), s = A(!1), c = C(() => {
210
+ const l = o.current;
211
+ l && (t.current = l.scrollTop, n.current = l.scrollHeight, s.current = !0);
212
+ }, [o]);
213
+ return k(() => {
214
+ if (!s.current) return;
215
+ const l = o.current;
216
+ if (!l) return;
217
+ const h = l.scrollHeight - n.current;
218
+ h > 0 && (l.scrollTop = t.current + h), s.current = !1;
219
+ }, [e, o]), { prepareAnchor: c };
220
+ }
221
+ function se(o, e) {
222
+ const [t, n] = L(!0), s = A(null);
223
+ return K(() => {
224
+ const c = o.current;
225
+ if (!c) return;
226
+ const l = () => {
227
+ const p = c.scrollHeight - c.scrollTop - c.clientHeight;
228
+ n(p <= e);
229
+ }, h = () => {
230
+ s.current !== null && cancelAnimationFrame(s.current), s.current = requestAnimationFrame(l);
231
+ };
232
+ return c.addEventListener("scroll", h, { passive: !0 }), l(), () => {
233
+ c.removeEventListener("scroll", h), s.current !== null && cancelAnimationFrame(s.current);
234
+ };
235
+ }, [o, e]), t;
236
+ }
237
+ function ie(o) {
238
+ const { itemCount: e, isAtBottom: t, scrollToIndex: n, mode: s } = o, c = A(e);
239
+ k(() => {
240
+ s && (e > c.current && t && e > 0 && n(e - 1, {
241
+ align: "end",
242
+ behavior: s === "smooth" ? "smooth" : "auto"
243
+ }), c.current = e);
244
+ }, [e, t, n, s]);
245
+ }
246
+ function oe(o) {
247
+ const {
248
+ items: e,
249
+ getKey: t,
250
+ estimatedItemSize: n = 80,
251
+ overscan: s = 5,
252
+ atBottomThreshold: c = 200,
253
+ followOutput: l = "auto",
254
+ initialAlignment: h = "bottom",
255
+ onStartReached: p,
256
+ onEndReached: v,
257
+ startReachedThreshold: y = 300,
258
+ endReachedThreshold: R = 300,
259
+ scrollToMessageKey: z,
260
+ onScrollToMessageComplete: I
261
+ } = o, u = D({
262
+ items: e,
263
+ getKey: t,
264
+ estimatedItemSize: n,
265
+ overscan: s,
266
+ initialAlignment: h
267
+ }), M = se(u.scrollerRef, c), { prepareAnchor: O } = ne(u.scrollerRef, e.length);
268
+ ie({
269
+ itemCount: e.length,
270
+ isAtBottom: M,
271
+ scrollToIndex: u.scrollToIndex,
272
+ mode: l ?? !1
273
+ });
274
+ const m = A(!1);
275
+ K(() => {
276
+ const d = u.scrollerRef.current;
277
+ if (!d || !p) return;
278
+ const H = () => {
279
+ d.scrollTop <= y && !m.current && (m.current = !0, Promise.resolve(p()).finally(() => {
280
+ m.current = !1;
281
+ }));
282
+ };
283
+ return d.addEventListener("scroll", H, { passive: !0 }), () => d.removeEventListener("scroll", H);
284
+ }, [u.scrollerRef, p, y]);
285
+ const S = A(!1);
286
+ K(() => {
287
+ const d = u.scrollerRef.current;
288
+ if (!d || !v) return;
289
+ const H = () => {
290
+ d.scrollHeight - d.scrollTop - d.clientHeight <= R && !S.current && (S.current = !0, Promise.resolve(v()).finally(() => {
291
+ S.current = !1;
292
+ }));
293
+ };
294
+ return d.addEventListener("scroll", H, { passive: !0 }), () => d.removeEventListener("scroll", H);
295
+ }, [u.scrollerRef, v, R]);
296
+ const E = A(null);
297
+ K(() => {
298
+ if (!z || E.current === z) return;
299
+ const d = e.findIndex((H, i) => t(H, i) === z);
300
+ d !== -1 && (E.current = z, u.scrollToIndex(d, { align: "center", behavior: "smooth" }), I == null || I());
301
+ }, [z, e, t, u, I]);
302
+ const x = C(
303
+ (d = "auto") => {
304
+ e.length !== 0 && u.scrollToIndex(e.length - 1, { align: "end", behavior: d });
305
+ },
306
+ [e.length, u]
307
+ ), F = C(
308
+ (d, H) => {
309
+ const i = e.findIndex((g, r) => t(g, r) === d);
310
+ i !== -1 && u.scrollToIndex(i, H);
311
+ },
312
+ [e, t, u]
313
+ );
314
+ return {
315
+ scrollerRef: u.scrollerRef,
316
+ virtualItems: u.virtualItems,
317
+ totalSize: u.totalSize,
318
+ measureItem: u.measureItem,
319
+ scrollToIndex: u.scrollToIndex,
320
+ scrollToBottom: x,
321
+ scrollToKey: F,
322
+ isAtBottom: M,
323
+ prepareAnchor: O
324
+ };
325
+ }
326
+ function j({
327
+ scrollerRef: o,
328
+ totalSize: e,
329
+ children: t,
330
+ className: n,
331
+ style: s
332
+ }) {
333
+ return /* @__PURE__ */ b(
334
+ "div",
335
+ {
336
+ ref: o,
337
+ className: n,
338
+ style: { overflow: "auto", height: "100%", position: "relative", ...s },
339
+ children: /* @__PURE__ */ b("div", { style: { height: e, position: "relative", width: "100%" }, children: t })
340
+ }
341
+ );
342
+ }
343
+ function G({
344
+ virtualItem: o,
345
+ measureItem: e,
346
+ children: t
347
+ }) {
348
+ const n = A(null);
349
+ return K(() => {
350
+ const s = n.current;
351
+ if (!s) return;
352
+ const c = new ResizeObserver(([l]) => {
353
+ l && e(o.key, l.contentRect.height);
354
+ });
355
+ return c.observe(s), () => c.disconnect();
356
+ }, [o.key, e]), /* @__PURE__ */ b(
357
+ "div",
358
+ {
359
+ ref: n,
360
+ style: {
361
+ position: "absolute",
362
+ top: 0,
363
+ // transform instead of top: avoids reflow, uses GPU compositor layer
364
+ transform: `translateY(${o.start}px)`,
365
+ width: "100%",
366
+ // Reserve estimated height to prevent layout collapse before first measure
367
+ minHeight: o.size
368
+ },
369
+ children: t
370
+ }
371
+ );
372
+ }
373
+ function le(o, e) {
374
+ const {
375
+ data: t,
376
+ itemContent: n,
377
+ computeItemKey: s,
378
+ estimatedItemSize: c = 80,
379
+ overscan: l = 5,
380
+ followOutput: h = "auto",
381
+ atBottomThreshold: p = 200,
382
+ initialAlignment: v = "bottom",
383
+ onStartReached: y,
384
+ onEndReached: R,
385
+ startReachedThreshold: z = 300,
386
+ endReachedThreshold: I = 300,
387
+ scrollToMessageKey: u,
388
+ onScrollToMessageComplete: M,
389
+ components: O = {},
390
+ className: m,
391
+ style: S
392
+ } = o, {
393
+ scrollerRef: E,
394
+ virtualItems: x,
395
+ totalSize: F,
396
+ measureItem: d,
397
+ scrollToIndex: H,
398
+ scrollToBottom: i,
399
+ scrollToKey: g,
400
+ isAtBottom: r,
401
+ prepareAnchor: a
402
+ } = oe({
403
+ items: t,
404
+ getKey: (w, B) => s(B, w),
405
+ estimatedItemSize: c,
406
+ overscan: l,
407
+ atBottomThreshold: p,
408
+ followOutput: h,
409
+ initialAlignment: v,
410
+ onStartReached: y,
411
+ onEndReached: R,
412
+ startReachedThreshold: z,
413
+ endReachedThreshold: I,
414
+ scrollToMessageKey: u,
415
+ onScrollToMessageComplete: M
416
+ });
417
+ $(
418
+ e,
419
+ () => ({
420
+ scrollToBottom: i,
421
+ scrollToIndex: H,
422
+ scrollToKey: g,
423
+ getScrollTop: () => {
424
+ var w;
425
+ return ((w = E.current) == null ? void 0 : w.scrollTop) ?? 0;
426
+ },
427
+ isAtBottom: () => r,
428
+ prepareAnchor: a
429
+ }),
430
+ [i, H, g, E, r, a]
431
+ );
432
+ const { Header: f, Footer: T, EmptyPlaceholder: P } = O;
433
+ return t.length === 0 && P ? /* @__PURE__ */ b(P, {}) : /* @__PURE__ */ _("div", { style: { display: "flex", flexDirection: "column", height: "100%" }, children: [
434
+ f && /* @__PURE__ */ b(f, {}),
435
+ /* @__PURE__ */ b(
436
+ j,
437
+ {
438
+ scrollerRef: E,
439
+ totalSize: F,
440
+ className: m,
441
+ style: { flex: 1, minHeight: 0, ...S },
442
+ children: x.map((w) => /* @__PURE__ */ b(
443
+ G,
444
+ {
445
+ virtualItem: w,
446
+ measureItem: d,
447
+ children: n(w.index, w.data)
448
+ },
449
+ w.key
450
+ ))
451
+ }
452
+ ),
453
+ T && /* @__PURE__ */ b(T, {})
454
+ ] });
455
+ }
456
+ const ue = Y(le);
457
+ function fe({
458
+ data: o,
459
+ itemContent: e,
460
+ computeItemKey: t,
461
+ estimatedItemSize: n = 80,
462
+ overscan: s = 5,
463
+ onEndReached: c,
464
+ endReachedThreshold: l = 300,
465
+ components: h = {},
466
+ className: p,
467
+ style: v
468
+ }) {
469
+ const { scrollerRef: y, virtualItems: R, totalSize: z, measureItem: I } = D({
470
+ items: o,
471
+ getKey: (m, S) => t(S, m),
472
+ estimatedItemSize: n,
473
+ overscan: s,
474
+ initialAlignment: "top"
475
+ });
476
+ Z.useEffect(() => {
477
+ const m = y.current;
478
+ if (!m || !c) return;
479
+ let S = !1;
480
+ const E = () => {
481
+ m.scrollHeight - m.scrollTop - m.clientHeight <= l && !S && (S = !0, Promise.resolve(c()).finally(() => {
482
+ S = !1;
483
+ }));
484
+ };
485
+ return m.addEventListener("scroll", E, { passive: !0 }), () => m.removeEventListener("scroll", E);
486
+ }, [y, c, l]);
487
+ const { Header: u, Footer: M, EmptyPlaceholder: O } = h;
488
+ return o.length === 0 && O ? /* @__PURE__ */ b(O, {}) : /* @__PURE__ */ _("div", { style: { display: "flex", flexDirection: "column", height: "100%" }, children: [
489
+ u && /* @__PURE__ */ b(u, {}),
490
+ /* @__PURE__ */ b(
491
+ j,
492
+ {
493
+ scrollerRef: y,
494
+ totalSize: z,
495
+ className: p,
496
+ style: { flex: 1, minHeight: 0, ...v },
497
+ children: R.map((m) => /* @__PURE__ */ b(
498
+ G,
499
+ {
500
+ virtualItem: m,
501
+ measureItem: I,
502
+ children: e(m.index, m.data)
503
+ },
504
+ m.key
505
+ ))
506
+ }
507
+ ),
508
+ M && /* @__PURE__ */ b(M, {})
509
+ ] });
510
+ }
511
+ function he(o) {
512
+ const {
513
+ fetcher: e,
514
+ initialPage: t = 1,
515
+ direction: n = "append",
516
+ getKey: s,
517
+ onPageLoaded: c,
518
+ onError: l
519
+ } = o, [h, p] = L([]), [v, y] = L(t), [R, z] = L(!0), [I, u] = L(!1), [M, O] = L(!1), [m, S] = L(!1), E = A(/* @__PURE__ */ new Set()), x = A(!1), F = C(
520
+ (r) => s ? r.filter((a) => {
521
+ const f = s(a);
522
+ return E.current.has(f) ? !1 : (E.current.add(f), !0);
523
+ }) : r,
524
+ [s]
525
+ ), d = C(async () => {
526
+ if (!(x.current || !R)) {
527
+ x.current = !0, S(!0);
528
+ try {
529
+ const r = v + 1, a = await e(r), f = F(a.data);
530
+ p(
531
+ (T) => n === "prepend" ? [...f, ...T] : [...T, ...f]
532
+ ), y(r), z(a.hasNextPage), u(a.hasPrevPage), c == null || c(r, f);
533
+ } catch (r) {
534
+ l == null || l(r instanceof Error ? r : new Error(String(r)));
535
+ } finally {
536
+ S(!1), x.current = !1;
537
+ }
538
+ }
539
+ }, [v, R, e, F, n, c, l]), H = C(async () => {
540
+ if (!(x.current || !I)) {
541
+ x.current = !0, S(!0);
542
+ try {
543
+ const r = v - 1, a = await e(r), f = F(a.data);
544
+ p((T) => [...f, ...T]), y(r), u(a.hasPrevPage), z(a.hasNextPage), c == null || c(r, f);
545
+ } catch (r) {
546
+ l == null || l(r instanceof Error ? r : new Error(String(r)));
547
+ } finally {
548
+ S(!1), x.current = !1;
549
+ }
550
+ }
551
+ }, [v, I, e, F, c, l]), i = C(async () => {
552
+ if (!x.current) {
553
+ x.current = !0, O(!0);
554
+ try {
555
+ const r = await e(t), a = r.data;
556
+ if (s) {
557
+ const f = new Set(a.map(s));
558
+ a.forEach((T) => E.current.add(s(T))), p((T) => {
559
+ const P = T.filter((w) => !f.has(s(w)));
560
+ return n === "prepend" ? [...a, ...P] : [...P, ...a];
561
+ });
562
+ } else
563
+ p(a);
564
+ y(t), z(r.hasNextPage), u(r.hasPrevPage), c == null || c(t, a);
565
+ } catch (r) {
566
+ l == null || l(r instanceof Error ? r : new Error(String(r)));
567
+ } finally {
568
+ O(!1), x.current = !1;
569
+ }
570
+ }
571
+ }, [e, t, s, n, c, l]), g = C(() => {
572
+ p([]), y(t), z(!0), u(!1), O(!1), S(!1), E.current.clear(), x.current = !1;
573
+ }, [t]);
574
+ return {
575
+ items: h,
576
+ loadNextPage: d,
577
+ loadPrevPage: H,
578
+ hasNextPage: R,
579
+ hasPrevPage: I,
580
+ loading: M,
581
+ loadingMore: m,
582
+ refresh: i,
583
+ reset: g,
584
+ currentPage: v
585
+ };
586
+ }
587
+ export {
588
+ ue as ChatVirtualList,
589
+ fe as VirtualList,
590
+ oe as useChatVirtualizer,
591
+ he as usePagination
592
+ };
@@ -0,0 +1,120 @@
1
+ import type * as React from "react";
2
+ export interface VirtualItem<T = unknown> {
3
+ key: string | number;
4
+ index: number;
5
+ /** Y position (top) in pixels */
6
+ start: number;
7
+ /** Current height — estimated until measured */
8
+ size: number;
9
+ data: T;
10
+ }
11
+ export interface ScrollToIndexOpts {
12
+ align?: "start" | "center" | "end";
13
+ behavior?: ScrollBehavior;
14
+ /** Additional pixel offset after alignment */
15
+ offset?: number;
16
+ }
17
+ export interface VirtualListComponents<T = unknown> {
18
+ Header?: React.ComponentType;
19
+ Footer?: React.ComponentType;
20
+ EmptyPlaceholder?: React.ComponentType;
21
+ ScrollSeekPlaceholder?: React.ComponentType<{
22
+ index: number;
23
+ data: T;
24
+ }>;
25
+ }
26
+ export interface PaginationResult<T> {
27
+ data: T[];
28
+ hasNextPage: boolean;
29
+ hasPrevPage: boolean;
30
+ currentPage: number;
31
+ totalPages?: number;
32
+ }
33
+ export interface UsePaginationOptions<T> {
34
+ fetcher: (page: number) => Promise<PaginationResult<T>>;
35
+ initialPage?: number;
36
+ pageSize?: number;
37
+ direction?: "append" | "prepend" | "bidirectional";
38
+ getKey?: (item: T) => string | number;
39
+ onPageLoaded?: (page: number, items: T[]) => void;
40
+ onError?: (error: Error) => void;
41
+ }
42
+ export interface UsePaginationReturn<T> {
43
+ items: T[];
44
+ loadNextPage: () => Promise<void>;
45
+ loadPrevPage: () => Promise<void>;
46
+ hasNextPage: boolean;
47
+ hasPrevPage: boolean;
48
+ loading: boolean;
49
+ loadingMore: boolean;
50
+ refresh: () => Promise<void>;
51
+ reset: () => void;
52
+ currentPage: number;
53
+ }
54
+ export interface ChatVirtualListHandle {
55
+ scrollToBottom: (behavior?: ScrollBehavior) => void;
56
+ scrollToIndex: (index: number, opts?: ScrollToIndexOpts) => void;
57
+ scrollToKey: (key: string | number, opts?: ScrollToIndexOpts) => void;
58
+ getScrollTop: () => number;
59
+ isAtBottom: () => boolean;
60
+ prepareAnchor: () => void;
61
+ }
62
+ export interface ChatVirtualListProps<T> {
63
+ data: T[];
64
+ itemContent: (index: number, item: T) => React.ReactNode;
65
+ computeItemKey: (index: number, item: T) => string | number;
66
+ estimatedItemSize?: number;
67
+ overscan?: number;
68
+ followOutput?: "auto" | "smooth" | false;
69
+ atBottomThreshold?: number;
70
+ initialAlignment?: "top" | "bottom";
71
+ onStartReached?: () => void | Promise<void>;
72
+ onEndReached?: () => void | Promise<void>;
73
+ startReachedThreshold?: number;
74
+ endReachedThreshold?: number;
75
+ scrollToMessageKey?: string | number | null;
76
+ onScrollToMessageComplete?: () => void;
77
+ components?: VirtualListComponents<T>;
78
+ className?: string;
79
+ style?: React.CSSProperties;
80
+ context?: unknown;
81
+ }
82
+ export interface VirtualListProps<T> {
83
+ data: T[];
84
+ itemContent: (index: number, item: T) => React.ReactNode;
85
+ computeItemKey: (index: number, item: T) => string | number;
86
+ estimatedItemSize?: number;
87
+ overscan?: number;
88
+ onEndReached?: () => void | Promise<void>;
89
+ endReachedThreshold?: number;
90
+ components?: VirtualListComponents<T>;
91
+ className?: string;
92
+ style?: React.CSSProperties;
93
+ }
94
+ export interface UseVirtualEngineReturn<T> {
95
+ scrollerRef: React.RefObject<HTMLDivElement>;
96
+ virtualItems: VirtualItem<T>[];
97
+ totalSize: number;
98
+ measureItem: (key: string | number, size: number) => void;
99
+ scrollToIndex: (index: number, opts?: ScrollToIndexOpts) => void;
100
+ scrollToOffset: (offset: number, behavior?: ScrollBehavior) => void;
101
+ isAtTop: boolean;
102
+ isAtBottom: boolean;
103
+ scrollTop: number;
104
+ }
105
+ export interface RenderRange {
106
+ start: number;
107
+ end: number;
108
+ }
109
+ export interface UseChatVirtualizerReturn<T> {
110
+ scrollerRef: React.RefObject<HTMLDivElement>;
111
+ virtualItems: VirtualItem<T>[];
112
+ totalSize: number;
113
+ measureItem: (key: string | number, size: number) => void;
114
+ scrollToIndex: (index: number, opts?: ScrollToIndexOpts) => void;
115
+ scrollToBottom: (behavior?: ScrollBehavior) => void;
116
+ scrollToKey: (key: string | number, opts?: ScrollToIndexOpts) => void;
117
+ isAtBottom: boolean;
118
+ prepareAnchor: () => void;
119
+ }
120
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"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"}
package/package.json ADDED
@@ -0,0 +1,43 @@
1
+ {
2
+ "name": "react-anchorlist",
3
+ "version": "0.1.0",
4
+ "description": "High-performance chat virtualizer for React — no flicker, no hacks",
5
+ "type": "module",
6
+ "main": "./dist/index.cjs",
7
+ "module": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "import": "./dist/index.js",
12
+ "require": "./dist/index.cjs",
13
+ "types": "./dist/index.d.ts"
14
+ }
15
+ },
16
+ "files": ["dist"],
17
+ "sideEffects": false,
18
+ "scripts": {
19
+ "dev": "vite build --watch",
20
+ "build": "vite build",
21
+ "test": "vitest run",
22
+ "test:watch": "vitest",
23
+ "typecheck": "tsc --noEmit"
24
+ },
25
+ "peerDependencies": {
26
+ "react": ">=18.0.0",
27
+ "react-dom": ">=18.0.0"
28
+ },
29
+ "devDependencies": {
30
+ "@testing-library/jest-dom": "^6.4.2",
31
+ "@testing-library/react": "^14.3.1",
32
+ "@types/react": "^18.3.3",
33
+ "@types/react-dom": "^18.3.0",
34
+ "@vitejs/plugin-react": "^4.3.0",
35
+ "jsdom": "^24.1.0",
36
+ "react": "^18.3.1",
37
+ "react-dom": "^18.3.1",
38
+ "typescript": "^5.4.5",
39
+ "vite": "^5.2.11",
40
+ "vite-plugin-dts": "^3.9.1",
41
+ "vitest": "^1.6.0"
42
+ }
43
+ }