virtua 0.2.1 → 0.2.2
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.
- package/lib/core/store.d.ts +2 -3
- package/lib/index.js +1 -1
- package/lib/index.js.map +1 -1
- package/lib/index.mjs +1 -1
- package/lib/index.mjs.map +1 -1
- package/package.json +2 -2
package/lib/core/store.d.ts
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
export type ScrollJump = Readonly<[index: number, sizeDiff: number][]>;
|
|
2
2
|
export type ItemResize = [index: number, size: number];
|
|
3
3
|
type ItemsRange = [startIndex: number, endIndex: number];
|
|
4
|
-
export declare const ACTION_UPDATE_CACHE_LENGTH = 0;
|
|
5
4
|
export declare const ACTION_UPDATE_ITEM_SIZES = 1;
|
|
6
5
|
export declare const ACTION_UPDATE_VIEWPORT = 2;
|
|
7
6
|
export declare const ACTION_HANDLE_SCROLL = 3;
|
|
8
|
-
type Actions = [type: typeof
|
|
7
|
+
type Actions = [type: typeof ACTION_UPDATE_ITEM_SIZES, entries: ItemResize[]] | [
|
|
9
8
|
type: typeof ACTION_UPDATE_VIEWPORT,
|
|
10
9
|
rect: {
|
|
11
10
|
_width: number;
|
|
@@ -20,7 +19,6 @@ export type VirtualStore = {
|
|
|
20
19
|
_getScrollOffset(): number;
|
|
21
20
|
_getViewportSize(): number;
|
|
22
21
|
_getScrollSize(): number;
|
|
23
|
-
_getItemCount(): number;
|
|
24
22
|
_getJump(): ScrollJump;
|
|
25
23
|
_isHorizontal(): boolean;
|
|
26
24
|
_isRtl(): boolean;
|
|
@@ -28,6 +26,7 @@ export type VirtualStore = {
|
|
|
28
26
|
_waitForScrollDestinationItemsMeasured(): Promise<void>;
|
|
29
27
|
_subscribe(cb: () => void): () => void;
|
|
30
28
|
_update(...action: Actions): void;
|
|
29
|
+
_updateCacheLength(length: number): void;
|
|
31
30
|
};
|
|
32
31
|
export declare const createVirtualStore: (itemCount: number, itemSize: number, isHorizontal: boolean, isRtl: boolean) => VirtualStore;
|
|
33
32
|
export {};
|
package/lib/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var e=require("react/jsx-runtime"),t=require("react"),r=require("use-sync-external-store/shim/index.js");const n=Math.min,o=Math.max,s=Math.abs,l=Date.now,i=e=>null!=e,c=(e,t)=>Array.from({length:e},((e,r)=>t(r))),u=(e,t)=>{const r=e.t[t];return-1===r?e.o:r},a=(e,t,r)=>{if(!e.l)return 0;if(e.i>=t)return r?e.u[t]+u(e,t):e.u[t];let n=e.i,o=e.u[n];for(;n<=t&&(e.u[n]=o,n!==t||r);)o+=u(e,n),n++;return e.i=t,o},
|
|
1
|
+
var e=require("react/jsx-runtime"),t=require("react"),r=require("use-sync-external-store/shim/index.js");const n=Math.min,o=Math.max,s=Math.abs,l=Date.now,i=e=>null!=e,c=(e,t)=>Array.from({length:e},((e,r)=>t(r))),u=(e,t)=>{const r=e.t[t];return-1===r?e.o:r},a=(e,t,r)=>{if(!e.l)return 0;if(e.i>=t)return r?e.u[t]+u(e,t):e.u[t];let n=e.i,o=e.u[n];for(;n<=t&&(e.u[n]=o,n!==t||r);)o+=u(e,n),n++;return e.i=t,o},d=(e,t)=>a(e,t),_=(e,t,r)=>{let s=0;if(r>=0)for(;t<e.l-1;){const n=u(e,t++);if((s+=n)>=r){s-n/2>=r&&t--;break}}else for(;t>0;){const n=u(e,--t);if((s-=n)<=r){s+n/2<r&&t++;break}}return n(o(t,0),e.l-1)},f=(e,t,r,n)=>_(e,r,t-n),h=_,g=(e,t,r)=>({o:t,l:e,i:r?n(r.i,e-1):0,t:c(e,(e=>{const t=r&&r.t[e];return i(t)?t:-1})),u:c(e,(e=>{if(0===e)return 0;const t=r&&r.u[e];return i(t)?t:-1}))}),m="undefined"!=typeof window?t.useLayoutEffect:t.useEffect,w=(e,t)=>r.useSyncExternalStore(e,t,t),S="current",p=e=>{const r=t.useRef();return r[S]||(r[S]=e())},v=e=>{const r=t.useRef(e);return m((()=>{r[S]=e}),[e]),r},z=t.memo((({_:r,h:n,g:o,m:s,S:l})=>{const i=t.useRef(null),c=w(o.p,(()=>o.v(s))),u=w(o.p,(()=>o.I(s)));return m((()=>n.T(i[S],s)),[s]),e.jsx(l,{ref:i,style:t.useMemo((()=>{const e=o.R(),t=o.M()?"right":"left",r={margin:0,padding:0,position:"absolute",[e?"height":"width"]:"100%",[e?"top":t]:0,[e?t:"top"]:c,visibility:u?"hidden":"visible"};return e&&(r.display="flex"),r}),[c,u]),children:r})})),x=t.forwardRef((({children:r,scrollSize:n,scrolling:o,horizontal:s,attrs:l},i)=>e.jsx("div",{ref:i,...l,children:e.jsx("div",{style:t.useMemo((()=>({position:"relative",visibility:"hidden",width:s?n:"100%",height:s?"100%":n,pointerEvents:o?"none":"auto"})),[n,o]),children:r})}))),y=({_:r,O:n,g:o,S:s,k:l,q:i})=>{const c=w(o.p,o.j),u=o.R();return e.jsx(s,{ref:n,scrollSize:c,scrolling:l,horizontal:u,attrs:t.useMemo((()=>({...i,style:{overflow:u?"auto hidden":"hidden auto",contain:"strict",width:"100%",height:"100%",padding:0,margin:0,...i.style}})),[i]),children:r})},I=t.forwardRef((({children:r,itemSize:c=40,overscan:_=4,horizontal:I,rtl:b,element:T=x,itemElement:R="div",onScroll:M,onScrollStop:O,onRangeChange:k,...q},j)=>{const A=t.useMemo((()=>{const e=[];return t.Children.forEach(r,(t=>{(e=>!i(e)||"boolean"==typeof e)(t)||e.push(t)})),e}),[r]),C=A.length,D=p((()=>((e,t,r,o)=>{let s,l=0,i=0,c=0,_=[],m=g(e,t),w=[0,0];const S=new Set,p=()=>r?l:i;return{A(){const[e,t]=w,r=d(m,e),n=f(m,c,e,r),o=h(m,n,p());return e===n&&t===o?w:w=[n,o]},I:e=>-1===m.t[e],C:e=>((e,t,r)=>{for(let n=t;n<=r;n++)if(-1===e.t[n])return!0;return!1})(m,e,h(m,e,p())),v:e=>d(m,e),D:()=>c,F:()=>p(),j:()=>(e=>a(e,e.l-1,!0))(m),J:()=>_,R:()=>r,M:()=>o,L:e=>f(m,e,0,0),P:()=>(s&&s[1](),new Promise(((e,t)=>{s=[()=>{Promise.resolve().then((()=>{e(),s=void 0}))},t]}))),p:e=>(S.add(e),()=>{S.delete(e)}),U(e,t){const r=(()=>{switch(e){case 1:{const e=t.filter((([e,t])=>m.t[e]!==t));if(!e.length)return!1;const r=[];return e.forEach((([e,t])=>{r.push([e,t-u(m,e)]),((e,t,r)=>{e.t[t]=r,e.i=n(t,e.i)})(m,e,t)})),_=r,!0}case 2:return(l!==t.B||i!==t.H)&&(l=t.B,i=t.H,!0);case 3:{const e=c;return(c=t)!==e}}})();r&&(S.forEach((e=>{e()})),s&&1===e&&s[0]())},V(e){m.l!==e&&(m=g(e,t,m))}}})(C,c,!!I,!!b)));D.V(C);const[E,F]=w(D.p,D.A),J=w(D.p,D.J),L=t.useRef(null),P=v(M),U=v(O),[B,H]=t.useState(new Set),[V,W]=t.useState(!1),G=p((()=>((e,t,r)=>{let c,u,a,d=-1,_=0,f=!1;const h=e.R(),g=e.M(),m=h?"scrollLeft":"scrollTop",w=new WeakMap,S=()=>a||(a=new ResizeObserver((t=>{const r=[];for(const n of t)if(n.target===u)e.U(2,{B:n.contentRect.width,H:n.contentRect.height});else{const e=w.get(n.target);i(e)&&r.push([e,n.contentRect[h?"width":"height"]])}r.length&&(e.U(1,r),f=!0)}))),p=()=>u?e.R()?u.scrollWidth:u.scrollHeight:0,v=(e,t)=>{if(u){if(g){if(!i(c)){const e=u[m];u[m]=1,c=0===u[m],u[m]=e}c&&(e*=-1)}t?u[m]+=e:(u[m]=e,_=3)}},z=async(t,r)=>{const n=()=>{let t=r();const n=p(),o=e.F();return n-(t+o)<=0&&(t=n-o),t};if(e.C(t)){do{e.U(3,n());try{await e.P()}catch(e){return}}while(e.C(t));v(n())}else{const t=n();v(t),e.U(3,t)}},x=e=>e.reduce(((e,[,t])=>e+t),0);return{W(n){u=n;const o=S(),c=()=>{let r=n[m];g&&(r=s(r)),d!==r&&(0!==_&&f?f=!1:3!==_&&(_=d>r?2:1),e.U(3,d=r),t(r))},a=(()=>{let e;const t=()=>{i(e)&&clearTimeout(e)},n=()=>{t(),e=setTimeout((()=>{e=null,c(),_=0,r(!1)}),150)};return n.G=t,n})(),w=()=>{const e=0===_;c(),e&&r(!0),a()},p=(()=>{let t=l()-50;return(...r)=>{const n=l();t+50<n&&(t=n,(t=>{0!==_&&(t.ctrlKey||(h?t.deltaX:t.deltaY)&&d>0&&d<e.j()-e.F()&&a())})(...r))}})();return o.observe(n),n.addEventListener("scroll",w),n.addEventListener("wheel",p,{passive:!0}),()=>{o.disconnect(),n.removeEventListener("scroll",w),n.removeEventListener("wheel",p),a.G()}},T(e,t){const r=S();return w.set(e,t),r.observe(e),()=>{w.delete(e),r.unobserve(e)}},K:p,N(t){t=o(t,0),z(e.L(t),(()=>t))},X(t,r){t=o(n(t,r-1),0),z(t,(()=>e.v(t)))},Y:(t,r)=>{if(2===_){const e=x(t);e&&v(e,!0)}else if(3===_){const n=e.D();if(0===n);else{const o=x(t);if(e.j()-(n+e.F()+o)<=0)o&&v(n+o);else{const e=t.reduce(((e,[t,n])=>(t<r&&(e+=n),e)),0);e&&v(e,!0)}}}}}})(D,(e=>{P[S]&&P[S](e)}),(e=>{W(e),e||(H(new Set),U[S]&&U[S]())}))));m((()=>G.W(L[S])),[]),m((()=>{J.length&&G.Y(J,E)}),[J]),t.useEffect((()=>{k&&k({start:E,end:F,count:C})}),[E,F]),t.useImperativeHandle(j,(()=>({get scrollOffset(){return D.D()},get scrollSize(){return G.K()},get viewportSize(){return D.F()},scrollToIndex(e){G.X(e,C)},scrollTo:G.N,scrollBy(e){G.N(D.D()+e)}})),[C]);const K=o(E-_,0),N=n(F+_,C-1),Q=t.useMemo((()=>{const t=[];for(let e=K;e<=N;e++)B.add(e);return B.forEach((r=>{const n=A[r];i(n)&&t.push(e.jsx(z,{h:G,g:D,m:r,S:R,_:n},(null==n?void 0:n.key)||r))})),t}),[A,B,K,N]);return e.jsx(y,{O:L,g:D,S:T,k:V,_:Q,q})}));exports.VList=I;
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../src/src/core/utils.ts","../src/src/core/cache.ts","../src/src/react/useIsomorphicLayoutEffect.ts","../src/src/react/useSyncExternalStore.ts","../src/src/react/utils.ts","../src/src/react/useStatic.ts","../src/src/react/useRefWithUpdate.ts","../src/src/react/VList.tsx","../src/src/core/store.ts","../src/src/core/scroller.ts"],"sourcesContent":["export const min = Math.min;\nexport const max = Math.max;\nexport const abs = Math.abs;\nexport const now = Date.now;\n\nexport const exists = <T>(v: T): v is Exclude<T, null | undefined> => v != null;\n\nexport const range = <T>(length: number, cb: (i: number) => T): T[] =>\n Array.from({ length }, (_, i) => cb(i));\n\nexport const debounce = <T extends (...args: any[]) => void>(\n fn: T,\n ms: number\n) => {\n let id: NodeJS.Timeout | undefined | null;\n\n const cancel = () => {\n if (exists(id)) {\n clearTimeout(id);\n }\n };\n const debouncedFn = () => {\n cancel();\n id = setTimeout(() => {\n id = null;\n fn();\n }, ms);\n };\n debouncedFn._cancel = cancel;\n return debouncedFn;\n};\n\nexport const throttle = <T extends (...args: any[]) => void>(\n fn: T,\n ms: number\n) => {\n let time = now() - ms;\n return (...args: Parameters<T>) => {\n const n = now();\n if (time + ms < n) {\n time = n;\n fn(...args);\n }\n };\n};\n","import type { DeepReadonly, Writeable } from \"./types\";\nimport { exists, max, min, range } from \"./utils\";\n\nexport const UNCACHED = -1;\n\nexport type Cache = DeepReadonly<{\n _defaultItemSize: number;\n _length: number;\n _sizes: number[];\n _measuredOffsetIndex: number;\n _offsets: number[];\n}>;\n\nexport const getItemSize = (cache: Cache, index: number): number => {\n const size = cache._sizes[index]!;\n return size === UNCACHED ? cache._defaultItemSize : size;\n};\n\nexport const setItemSize = (\n cache: Writeable<Cache>,\n index: number,\n size: number\n) => {\n cache._sizes[index] = size;\n // mark as dirty\n cache._measuredOffsetIndex = min(index, cache._measuredOffsetIndex);\n};\n\nconst computeOffset = (\n cache: Writeable<Cache>,\n index: number,\n isTotal?: boolean\n): number => {\n if (!cache._length) return 0;\n if (cache._measuredOffsetIndex >= index) {\n if (isTotal) {\n return cache._offsets[index]! + getItemSize(cache, index);\n } else {\n return cache._offsets[index]!;\n }\n }\n\n let i = cache._measuredOffsetIndex;\n let top = cache._offsets[i]!;\n while (i <= index) {\n cache._offsets[i] = top;\n if (i === index && !isTotal) {\n break;\n }\n top += getItemSize(cache, i);\n i++;\n }\n // mark as measured\n cache._measuredOffsetIndex = index;\n return top;\n};\n\nexport const computeTotalSize = (cache: Writeable<Cache>): number => {\n return computeOffset(cache, cache._length - 1, true);\n};\n\nexport const computeStartOffset = (\n cache: Writeable<Cache>,\n index: number\n): number => {\n return computeOffset(cache, index);\n};\n\nconst findIndex = (cache: Cache, i: number, distance: number): number => {\n let sum = 0;\n if (distance >= 0) {\n // search forward\n while (i < cache._length - 1) {\n const h = getItemSize(cache, i++);\n if ((sum += h) >= distance) {\n if (sum - h / 2 >= distance) {\n i--;\n }\n break;\n }\n }\n } else {\n // search backward\n while (i > 0) {\n const h = getItemSize(cache, --i);\n if ((sum -= h) <= distance) {\n if (sum + h / 2 < distance) {\n i++;\n }\n break;\n }\n }\n }\n\n return min(max(i, 0), cache._length - 1);\n};\n\nexport const findStartIndexWithOffset = (\n cache: Cache,\n offset: number,\n prevStartIndex: number,\n prevOffset: number\n): number => {\n return findIndex(cache, prevStartIndex, offset - prevOffset);\n};\n\nexport const findEndIndex = findIndex;\n\nexport const hasUnmeasuredItemsInRange = (\n cache: Cache,\n startIndex: number,\n endIndex: number\n): boolean => {\n for (let i = startIndex; i <= endIndex; i++) {\n if (cache._sizes[i] === UNCACHED) {\n return true;\n }\n }\n return false;\n};\n\nexport const resetCache = (\n length: number,\n itemSize: number,\n cache?: Cache\n): Cache => {\n return {\n _defaultItemSize: itemSize,\n _length: length,\n _measuredOffsetIndex: cache\n ? min(cache._measuredOffsetIndex, length - 1)\n : 0,\n _sizes: range(length, (i) => {\n const size = cache && cache._sizes[i];\n if (exists(size)) {\n return size;\n }\n return UNCACHED;\n }),\n _offsets: range(length, (i) => {\n if (i === 0) {\n // first offset must be 0\n return 0;\n }\n const offset = cache && cache._offsets[i];\n if (exists(offset)) {\n return offset;\n }\n return UNCACHED;\n }),\n };\n};\n","import { useEffect, useLayoutEffect } from \"react\";\n\n// https://gist.github.com/gaearon/e7d97cdf38a2907924ea12e4ebdf3c85\nexport const useIsomorphicLayoutEffect =\n typeof window !== \"undefined\" ? useLayoutEffect : useEffect;\n","import { useSyncExternalStore as _useSyncExternalStore } from \"use-sync-external-store/shim/index.js\";\n\nexport const useSyncExternalStore = <T>(\n subscibe: (onStoreChange: () => void) => () => void,\n getSnapShot: () => T\n): T => {\n return _useSyncExternalStore(subscibe, getSnapShot, getSnapShot);\n};\n","export const refKey = \"current\";\n","import { useRef } from \"react\";\nimport { refKey } from \"./utils\";\n\nexport const useStatic = <T>(init: () => T): T => {\n const ref = useRef<T>();\n return ref[refKey] || (ref[refKey] = init());\n};\n","import { useRef } from \"react\";\nimport { useIsomorphicLayoutEffect } from \"./useIsomorphicLayoutEffect\";\nimport { refKey } from \"./utils\";\n\nexport const useRefWithUpdate = <T>(value: T) => {\n const ref = useRef<T>(value);\n\n useIsomorphicLayoutEffect(() => {\n ref[refKey] = value;\n }, [value]);\n\n return ref;\n};\n","import {\n Children,\n memo,\n useRef,\n useMemo,\n CSSProperties,\n ReactElement,\n forwardRef,\n useImperativeHandle,\n ReactNode,\n useEffect,\n RefObject,\n useState,\n ReactFragment,\n} from \"react\";\nimport {\n ACTION_UPDATE_CACHE_LENGTH,\n VirtualStore,\n createVirtualStore,\n} from \"../core/store\";\nimport { useIsomorphicLayoutEffect } from \"./useIsomorphicLayoutEffect\";\nimport { useSyncExternalStore } from \"./useSyncExternalStore\";\nimport { exists, max, min } from \"../core/utils\";\nimport { createScroller, Scroller } from \"../core/scroller\";\nimport { refKey } from \"./utils\";\nimport { useStatic } from \"./useStatic\";\nimport { useRefWithUpdate } from \"./useRefWithUpdate\";\n\ntype ItemProps = {\n _children: ReactNode;\n _scroller: Scroller;\n _store: VirtualStore;\n _index: number;\n _element: \"div\";\n};\n\nconst Item = memo(\n ({\n _children: children,\n _scroller: scroller,\n _store: store,\n _index: index,\n _element: Element,\n }: ItemProps): ReactElement => {\n const ref = useRef<HTMLDivElement>(null);\n\n const offset = useSyncExternalStore(store._subscribe, () =>\n store._getItemOffset(index)\n );\n const hide = useSyncExternalStore(store._subscribe, () =>\n store._isUnmeasuredItem(index)\n );\n\n // The index may be changed if elements are inserted to or removed from the start of props.children\n useIsomorphicLayoutEffect(\n () => scroller._initItem(ref[refKey]!, index),\n [index]\n );\n\n return (\n <Element\n ref={ref}\n style={useMemo((): CSSProperties => {\n const isHorizontal = store._isHorizontal();\n const leftOrRightKey = store._isRtl() ? \"right\" : \"left\";\n const style: CSSProperties = {\n margin: 0,\n padding: 0,\n position: \"absolute\",\n [isHorizontal ? \"height\" : \"width\"]: \"100%\",\n [isHorizontal ? \"top\" : leftOrRightKey]: 0,\n [isHorizontal ? leftOrRightKey : \"top\"]: offset,\n visibility: hide ? \"hidden\" : \"visible\",\n // willChange: \"transform\",\n };\n if (isHorizontal) {\n style.display = \"flex\";\n }\n return style;\n }, [offset, hide])}\n >\n {children}\n </Element>\n );\n }\n);\n\nconst isInvalidElement = <T extends ReactNode>(\n e: T\n): e is Extract<T, null | undefined | boolean> =>\n !exists(e) || typeof e === \"boolean\";\n\nexport type WindowComponentAttributes = Pick<\n React.HTMLAttributes<HTMLElement>,\n \"className\" | \"style\" | \"id\" | \"role\" | \"tabIndex\"\n> &\n React.AriaAttributes;\n\n/**\n * Props of customized scrollable component.\n */\nexport interface CustomWindowComponentProps {\n children: ReactNode;\n scrollSize: number;\n scrolling: boolean;\n horizontal: boolean;\n attrs: WindowComponentAttributes;\n}\n\nconst DefaultWindow = forwardRef<any, CustomWindowComponentProps>(\n (\n { children, scrollSize, scrolling, horizontal, attrs },\n ref\n ): ReactElement => {\n return (\n <div ref={ref} {...attrs}>\n <div\n style={useMemo((): CSSProperties => {\n return {\n position: \"relative\",\n visibility: \"hidden\",\n width: horizontal ? scrollSize : \"100%\",\n height: horizontal ? \"100%\" : scrollSize,\n pointerEvents: scrolling ? \"none\" : \"auto\",\n };\n }, [scrollSize, scrolling])}\n >\n {children}\n </div>\n </div>\n );\n }\n);\n\nexport type CustomWindowComponent = typeof DefaultWindow;\n\nconst Window = ({\n _children: children,\n _ref: ref,\n _store: store,\n _element: Element,\n _scrolling: scrolling,\n _attrs: attrs,\n}: {\n _children: ReactNode;\n _ref: RefObject<HTMLDivElement>;\n _store: VirtualStore;\n _element: CustomWindowComponent;\n _scrolling: boolean;\n _attrs: WindowComponentAttributes;\n}) => {\n const scrollSize = useSyncExternalStore(\n store._subscribe,\n store._getScrollSize\n );\n\n const horizontal = store._isHorizontal();\n\n return (\n <Element\n ref={ref}\n scrollSize={scrollSize}\n scrolling={scrolling}\n horizontal={horizontal}\n attrs={useMemo(\n () => ({\n ...attrs,\n style: {\n overflow: horizontal ? \"auto hidden\" : \"hidden auto\",\n contain: \"strict\",\n // transform: \"translate3d(0px, 0px, 0px)\",\n // willChange: \"scroll-position\",\n // backfaceVisibility: \"hidden\",\n width: \"100%\",\n height: \"100%\",\n padding: 0,\n margin: 0,\n ...attrs.style,\n },\n }),\n [attrs]\n )}\n >\n {children}\n </Element>\n );\n};\n\n/**\n * Props of customized item component.\n */\nexport interface CustomItemComponentProps {\n style: CSSProperties;\n children: ReactNode;\n}\n\nexport type CustomItemComponent = React.ForwardRefExoticComponent<\n React.PropsWithoutRef<CustomItemComponentProps> & React.RefAttributes<any>\n>;\n\ntype CustomItemComponentOrElement =\n | keyof JSX.IntrinsicElements\n | CustomItemComponent;\n\n/**\n * Methods of {@link VList}.\n */\nexport interface VListHandle {\n /**\n * Get current scrollTop or scrollLeft.\n */\n readonly scrollOffset: number;\n /**\n * Get current scrollHeight or scrollWidth.\n */\n readonly scrollSize: number;\n /**\n * Get current offsetHeight or offsetWidth.\n */\n readonly viewportSize: number;\n /**\n * Scroll to the item specified by index.\n * @param index index of item\n */\n scrollToIndex(index: number): void;\n /**\n * Scroll to the given offset.\n * @param offset offset from start\n */\n scrollTo(offset: number): void;\n /**\n * Scroll by the given offset.\n * @param offset offset from current position\n */\n scrollBy(offset: number): void;\n}\n\n/**\n * Props of {@link VList}.\n */\nexport interface VListProps extends WindowComponentAttributes {\n /**\n * Elements rendered by this component.\n */\n children: ReactNode;\n /**\n * Item size hint for unmeasured items. It's recommended to specify this prop if item sizes are fixed and known, or much larger than the defaultValue. It will help to reduce scroll jump when items are measured.\n * @defaultValue 40\n */\n itemSize?: number;\n /**\n * Number of items to render above/below the visible bounds of the list. You can increase to avoid showing blank items in fast scrolling.\n * @defaultValue 4\n */\n overscan?: number;\n /**\n * If true, rendered as a horizontally scrollable list. Otherwise rendered as a vertically scrollable list.\n */\n horizontal?: boolean;\n /**\n * You have to set true if you use this component under `direction: rtl` style.\n */\n rtl?: boolean;\n /**\n * Customized element type for scrollable element. This element will get {@link CustomWindowComponentProps} as props.\n * @defaultValue {@link DefaultWindow}\n */\n element?: CustomWindowComponent;\n /**\n * Customized element type for item element. This element will get {@link CustomItemComponentProps} as props.\n * @defaultValue \"div\"\n */\n itemElement?: CustomItemComponentOrElement;\n /**\n * Callback invoked whenever scroll offset changes.\n * @param offset Current scrollTop or scrollLeft.\n */\n onScroll?: (offset: number) => void;\n /**\n * Callback invoked when scrolling stops.\n */\n onScrollStop?: () => void;\n /**\n * Callback invoked when visible items range changes.\n * @param payload `start` is the start index of viewable items. `end` is the end index of viewable items. `count` is the total count of items.\n */\n onRangeChange?: (payload: {\n start: number;\n end: number;\n count: number;\n }) => void;\n}\n\n/**\n * Virtualized list component. See {@link VListProps} and {@link VListHandle}.\n */\nexport const VList = forwardRef<VListHandle, VListProps>(\n (\n {\n children,\n itemSize: itemSizeProp = 40,\n overscan = 4,\n horizontal: horizontalProp,\n rtl: rtlProp,\n element = DefaultWindow,\n itemElement = \"div\",\n onScroll: onScrollProp,\n onScrollStop: onScrollStopProp,\n onRangeChange: onRangeChangeProp,\n ...windowAttrs\n },\n ref\n ): ReactElement => {\n // Memoize element array\n const elements = useMemo(() => {\n const arr: (ReactElement | ReactFragment | string | number)[] = [];\n Children.forEach(children, (e) => {\n if (isInvalidElement(e)) {\n return;\n }\n arr.push(e);\n });\n return arr;\n }, [children]);\n const elementsCount = elements.length;\n\n // https://github.com/facebook/react/issues/25191#issuecomment-1237456448\n const store = useStatic(() =>\n createVirtualStore(\n elementsCount,\n itemSizeProp,\n !!horizontalProp,\n !!rtlProp\n )\n );\n const [startIndex, endIndex] = useSyncExternalStore(\n store._subscribe,\n store._getRange\n );\n const jump = useSyncExternalStore(store._subscribe, store._getJump);\n const rootRef = useRef<HTMLDivElement>(null);\n\n const onScroll = useRefWithUpdate(onScrollProp);\n const onScrollStop = useRefWithUpdate(onScrollStopProp);\n\n const [mountedIndexes, reset] = useState<Set<number>>(new Set<number>());\n const [scrolling, setScrolling] = useState(false);\n const scroller = useStatic(() =>\n createScroller(\n store,\n (offset) => {\n onScroll[refKey] && onScroll[refKey](offset);\n },\n (isScrolling) => {\n setScrolling(isScrolling);\n if (!isScrolling) {\n reset(new Set());\n onScrollStop[refKey] && onScrollStop[refKey]();\n }\n }\n )\n );\n\n // The elements length and cached items length are different just after element is added/removed.\n const count = min(elementsCount, store._getItemCount());\n\n // So update cache length. Updating state in render will cause warn so use useEffect for now.\n useIsomorphicLayoutEffect(() => {\n store._update(ACTION_UPDATE_CACHE_LENGTH, elementsCount);\n }, [elementsCount]);\n\n useIsomorphicLayoutEffect(() => scroller._initRoot(rootRef[refKey]!), []);\n\n useIsomorphicLayoutEffect(() => {\n if (!jump.length) return;\n\n scroller._fixScrollJump(jump, startIndex);\n }, [jump]);\n\n useEffect(() => {\n if (!onRangeChangeProp) return;\n\n onRangeChangeProp({\n start: startIndex,\n end: endIndex,\n count,\n });\n }, [startIndex, endIndex]);\n\n useImperativeHandle(\n ref,\n () => {\n return {\n get scrollOffset() {\n return store._getScrollOffset();\n },\n get scrollSize() {\n return scroller._getActualScrollSize();\n },\n get viewportSize() {\n return store._getViewportSize();\n },\n scrollToIndex(index) {\n scroller._scrollToIndex(index, count);\n },\n scrollTo: scroller._scrollTo,\n scrollBy(offset) {\n scroller._scrollTo(store._getScrollOffset() + offset);\n },\n };\n },\n [count]\n );\n\n const startIndexWithMargin = max(startIndex - overscan, 0);\n const endIndexWithMargin = min(endIndex + overscan, count - 1);\n const items = useMemo(() => {\n const res: ReactElement[] = [];\n for (let i = startIndexWithMargin; i <= endIndexWithMargin; i++) {\n // https://github.com/sergi/virtual-list/commit/8e7e06dc63568334c1ab809ea83c1be36572e9ed\n mountedIndexes.add(i);\n }\n mountedIndexes.forEach((i) => {\n const e = elements[i];\n // This can be undefined when items are removed\n if (exists(e)) {\n res.push(\n <Item\n key={(e as { key?: ReactElement[\"key\"] })?.key || i}\n _scroller={scroller}\n _store={store}\n _index={i}\n _element={itemElement as \"div\"}\n _children={e}\n />\n );\n }\n });\n return res;\n }, [elements, mountedIndexes, startIndexWithMargin, endIndexWithMargin]);\n\n return (\n <Window\n _ref={rootRef}\n _store={store}\n _element={element}\n _scrolling={scrolling}\n _children={items}\n _attrs={windowAttrs}\n />\n );\n }\n);\n","import {\n findStartIndexWithOffset,\n resetCache,\n getItemSize,\n computeTotalSize,\n findEndIndex,\n computeStartOffset,\n Cache,\n UNCACHED,\n setItemSize,\n hasUnmeasuredItemsInRange,\n} from \"./cache\";\nimport type { Writeable } from \"./types\";\n\nexport type ScrollJump = Readonly<[index: number, sizeDiff: number][]>;\nexport type ItemResize = [index: number, size: number];\ntype ItemsRange = [startIndex: number, endIndex: number];\n\nexport const ACTION_UPDATE_CACHE_LENGTH = 0;\nexport const ACTION_UPDATE_ITEM_SIZES = 1;\nexport const ACTION_UPDATE_VIEWPORT = 2;\nexport const ACTION_HANDLE_SCROLL = 3;\n\ntype Actions =\n | [type: typeof ACTION_UPDATE_CACHE_LENGTH, length: number]\n | [type: typeof ACTION_UPDATE_ITEM_SIZES, entries: ItemResize[]]\n | [\n type: typeof ACTION_UPDATE_VIEWPORT,\n rect: { _width: number; _height: number }\n ]\n | [type: typeof ACTION_HANDLE_SCROLL, offset: number];\n\nexport type VirtualStore = {\n _getRange(): ItemsRange;\n _isUnmeasuredItem(index: number): boolean;\n _hasUnmeasuredItemsInRange(startIndex: number): boolean;\n _getItemOffset(index: number): number;\n _getScrollOffset(): number;\n _getViewportSize(): number;\n _getScrollSize(): number;\n _getItemCount(): number;\n _getJump(): ScrollJump;\n _isHorizontal(): boolean;\n _isRtl(): boolean;\n _getItemIndexForScrollTo(offset: number): number;\n _waitForScrollDestinationItemsMeasured(): Promise<void>;\n _subscribe(cb: () => void): () => void;\n _update(...action: Actions): void;\n};\n\nexport const createVirtualStore = (\n itemCount: number,\n itemSize: number,\n isHorizontal: boolean,\n isRtl: boolean\n): VirtualStore => {\n let viewportWidth = 0;\n let viewportHeight = 0;\n let scrollOffset = 0;\n let jump: ScrollJump = [];\n let cache = resetCache(itemCount, itemSize);\n let _prevRange: ItemsRange = [0, 0];\n let _scrollToQueue: [() => void, () => void] | undefined;\n\n const subscribers = new Set<() => void>();\n const getViewportSize = (): number =>\n isHorizontal ? viewportWidth : viewportHeight;\n\n return {\n _getRange() {\n const [prevStartIndex, prevEndIndex] = _prevRange;\n const prevOffset = computeStartOffset(\n cache as Writeable<Cache>,\n prevStartIndex\n );\n const start = findStartIndexWithOffset(\n cache,\n scrollOffset,\n prevStartIndex,\n prevOffset\n );\n const end = findEndIndex(cache, start, getViewportSize());\n if (prevStartIndex === start && prevEndIndex === end) {\n return _prevRange;\n }\n return (_prevRange = [start, end]);\n },\n _isUnmeasuredItem(index) {\n return cache._sizes[index] === UNCACHED;\n },\n _hasUnmeasuredItemsInRange(startIndex) {\n return hasUnmeasuredItemsInRange(\n cache,\n startIndex,\n findEndIndex(cache, startIndex, getViewportSize())\n );\n },\n _getItemOffset(index) {\n return computeStartOffset(cache as Writeable<Cache>, index);\n },\n _getScrollOffset() {\n return scrollOffset;\n },\n _getViewportSize() {\n return getViewportSize();\n },\n _getScrollSize() {\n return computeTotalSize(cache as Writeable<Cache>);\n },\n _getItemCount() {\n return cache._length;\n },\n _getJump() {\n return jump;\n },\n _isHorizontal() {\n return isHorizontal;\n },\n _isRtl() {\n return isRtl;\n },\n _getItemIndexForScrollTo(offset) {\n return findStartIndexWithOffset(cache, offset, 0, 0);\n },\n _waitForScrollDestinationItemsMeasured() {\n if (_scrollToQueue) {\n // Cancel waiting scrollTo\n _scrollToQueue[1]();\n }\n // The measurement will be done asynchronously and the timing is not predictable so we use promise.\n // For example, ResizeObserver may not fire when window is not visible.\n return new Promise((resolve, reject) => {\n _scrollToQueue = [\n () => {\n // HACK: It should be resolved in the next microtask that is after React's render\n Promise.resolve().then(() => {\n resolve();\n _scrollToQueue = undefined;\n });\n },\n reject,\n ];\n });\n },\n _subscribe(cb) {\n subscribers.add(cb);\n return () => {\n subscribers.delete(cb);\n };\n },\n _update(type, payload) {\n const mutated = ((): boolean => {\n switch (type) {\n case ACTION_UPDATE_CACHE_LENGTH: {\n if (cache._length === payload) return false;\n cache = resetCache(payload, itemSize, cache);\n return true;\n }\n case ACTION_UPDATE_ITEM_SIZES: {\n const updated = payload.filter(\n ([index, size]) => cache._sizes[index] !== size\n );\n // Skip if all items are cached and not updated\n if (!updated.length) {\n return false;\n }\n\n const updatedJump: [index: number, sizeDiff: number][] = [];\n updated.forEach(([index, size]) => {\n updatedJump.push([index, size - getItemSize(cache, index)]);\n setItemSize(cache as Writeable<Cache>, index, size);\n });\n jump = updatedJump;\n return true;\n }\n case ACTION_UPDATE_VIEWPORT: {\n if (\n viewportWidth === payload._width &&\n viewportHeight === payload._height\n ) {\n return false;\n }\n viewportWidth = payload._width;\n viewportHeight = payload._height;\n return true;\n }\n case ACTION_HANDLE_SCROLL: {\n const prevOffset = scrollOffset;\n return (scrollOffset = payload) !== prevOffset;\n }\n }\n })();\n\n if (mutated) {\n subscribers.forEach((cb) => {\n cb();\n });\n if (_scrollToQueue && type === ACTION_UPDATE_ITEM_SIZES) {\n _scrollToQueue[0]();\n }\n }\n },\n };\n};\n","import {\n ACTION_HANDLE_SCROLL,\n ACTION_UPDATE_ITEM_SIZES,\n ACTION_UPDATE_VIEWPORT,\n ItemResize,\n ScrollJump,\n VirtualStore,\n} from \"./store\";\nimport { abs, debounce, throttle, exists, max, min } from \"./utils\";\n\nexport const SCROLL_STOP = 0;\nexport const SCROLL_DOWN = 1;\nexport const SCROLL_UP = 2;\nexport const SCROLL_MANUAL = 3;\ntype ScrollDirection =\n | typeof SCROLL_STOP\n | typeof SCROLL_DOWN\n | typeof SCROLL_UP\n | typeof SCROLL_MANUAL;\n\nexport type Scroller = {\n _initRoot: (rootElement: HTMLElement) => () => void;\n _initItem: (itemElement: HTMLElement, index: number) => () => void;\n _getActualScrollSize: () => number;\n _scrollTo: (offset: number) => void;\n _scrollToIndex: (index: number, count: number) => void;\n _fixScrollJump: (jump: ScrollJump, startIndex: number) => void;\n};\n\nexport const createScroller = (\n store: VirtualStore,\n emitScrollOffsetChange: (offset: number) => void,\n emitScrollStateChange: (scrolling: boolean) => void\n): Scroller => {\n let prevOffset = -1;\n let scrollDirection: ScrollDirection = SCROLL_STOP;\n let resized = false;\n let isNegativeOffset: boolean | undefined;\n let rootElement: HTMLElement | undefined;\n let _ro: ResizeObserver | undefined;\n const isHorizontal = store._isHorizontal();\n const isRtl = store._isRtl();\n const scrollToKey = isHorizontal ? \"scrollLeft\" : \"scrollTop\";\n const mountedIndexes = new WeakMap<Element, number>();\n const getResizeObserver = (): ResizeObserver => {\n // Initialize ResizeObserver lazily for SSR\n return (\n _ro ||\n (_ro = new ResizeObserver((entries) => {\n // https://www.w3.org/TR/resize-observer/#intro\n const resizes: ItemResize[] = [];\n for (const entry of entries) {\n if (entry.target === rootElement) {\n store._update(ACTION_UPDATE_VIEWPORT, {\n _width: entry.contentRect.width,\n _height: entry.contentRect.height,\n });\n } else {\n const index = mountedIndexes.get(entry.target);\n if (exists(index)) {\n resizes.push([\n index,\n entry.contentRect[isHorizontal ? \"width\" : \"height\"],\n ]);\n }\n }\n }\n\n if (resizes.length) {\n store._update(ACTION_UPDATE_ITEM_SIZES, resizes);\n resized = true;\n }\n }))\n );\n };\n const getActualScrollSize = (): number => {\n if (!rootElement) return 0;\n // Use element's scrollHeight/scrollWidth instead of stored scrollSize.\n // This is because stored size may differ from the actual size, for example when a new item is added and not yet measured.\n return store._isHorizontal()\n ? rootElement.scrollWidth\n : rootElement.scrollHeight;\n };\n const updateScrollPosition = (offset: number, diff?: boolean) => {\n if (!rootElement) return;\n if (isRtl) {\n if (!exists(isNegativeOffset)) {\n // Assume offset type in rtl direction.\n // The scroll position is negative in spec however its not in some browsers, for example Chrome earlier than v85.\n // https://github.com/othree/jquery.rtl-scroll-type\n const prev = rootElement[scrollToKey];\n rootElement[scrollToKey] = 1;\n isNegativeOffset = rootElement[scrollToKey] === 0;\n rootElement[scrollToKey] = prev;\n }\n if (isNegativeOffset) {\n offset *= -1;\n }\n }\n if (diff) {\n rootElement[scrollToKey] += offset;\n } else {\n rootElement[scrollToKey] = offset;\n scrollDirection = SCROLL_MANUAL;\n }\n };\n const scrollTo = async (index: number, getCurrentOffset: () => number) => {\n const getOffset = (): number => {\n let offset = getCurrentOffset();\n const scrollSize = getActualScrollSize();\n const viewportSize = store._getViewportSize();\n if (scrollSize - (offset + viewportSize) <= 0) {\n // Adjust if the offset is over the end, to get correct startIndex.\n offset = scrollSize - viewportSize;\n }\n return offset;\n };\n\n if (store._hasUnmeasuredItemsInRange(index)) {\n do {\n // In order to scroll to the correct position, mount the items and measure their sizes before scrolling.\n store._update(ACTION_HANDLE_SCROLL, getOffset());\n try {\n // Wait for the scroll destination items to be measured.\n await store._waitForScrollDestinationItemsMeasured();\n } catch (e) {\n // canceled\n return;\n }\n } while (store._hasUnmeasuredItemsInRange(index));\n\n // Scroll with the updated value\n updateScrollPosition(getOffset());\n } else {\n const offset = getOffset();\n updateScrollPosition(offset);\n // Sync viewport to scroll destination\n store._update(ACTION_HANDLE_SCROLL, offset);\n }\n };\n\n const calcTotalJump = (jump: ScrollJump): number =>\n jump.reduce((acc, [, j]) => acc + j, 0);\n\n return {\n _initRoot(root) {\n rootElement = root;\n const ro = getResizeObserver();\n\n const syncViewportToScrollPosition = () => {\n let offset = root[scrollToKey];\n if (isRtl) {\n // The scroll position may be negative value in rtl direction.\n // https://github.com/othree/jquery.rtl-scroll-type\n offset = abs(offset);\n }\n if (prevOffset === offset) {\n return;\n }\n // Skip scroll direction detection just after resizing because it may result in the opposite direction.\n // Scroll events are dispatched enough so it's ok to skip some of them.\n if (scrollDirection === SCROLL_STOP || !resized) {\n // Ignore until manual scrolling\n if (scrollDirection !== SCROLL_MANUAL) {\n scrollDirection = prevOffset > offset ? SCROLL_UP : SCROLL_DOWN;\n }\n } else {\n resized = false;\n }\n store._update(ACTION_HANDLE_SCROLL, (prevOffset = offset));\n emitScrollOffsetChange(offset);\n };\n\n const onScrollStopped = debounce(() => {\n // Check scroll position once just after scrolling stopped\n syncViewportToScrollPosition();\n scrollDirection = SCROLL_STOP;\n emitScrollStateChange(false);\n }, 150);\n\n const onScroll = () => {\n const isScrollStart = scrollDirection === SCROLL_STOP;\n syncViewportToScrollPosition();\n if (isScrollStart) {\n emitScrollStateChange(true);\n }\n onScrollStopped();\n };\n\n // Infer scroll state also from wheel events\n // Sometimes scroll events do not fire when frame dropped even if the visual have been already scrolled\n const onWheel = throttle((e: WheelEvent) => {\n if (scrollDirection === SCROLL_STOP) {\n // Scroll start should be detected with scroll event\n return;\n }\n if (e.ctrlKey) {\n // Probably a pinch-to-zoom gesture\n return;\n }\n // Get delta before checking deltaMode for firefox behavior\n // https://github.com/w3c/uievents/issues/181#issuecomment-392648065\n // https://bugzilla.mozilla.org/show_bug.cgi?id=1392460#c34\n if (isHorizontal ? e.deltaX : e.deltaY) {\n if (\n prevOffset > 0 &&\n prevOffset < store._getScrollSize() - store._getViewportSize()\n ) {\n onScrollStopped();\n }\n }\n }, 50);\n\n ro.observe(root);\n root.addEventListener(\"scroll\", onScroll);\n root.addEventListener(\"wheel\", onWheel, { passive: true });\n\n return () => {\n ro.disconnect();\n root.removeEventListener(\"scroll\", onScroll);\n root.removeEventListener(\"wheel\", onWheel);\n onScrollStopped._cancel();\n };\n },\n _initItem(el, i) {\n const ro = getResizeObserver();\n mountedIndexes.set(el, i);\n ro.observe(el);\n return () => {\n mountedIndexes.delete(el);\n ro.unobserve(el);\n };\n },\n _getActualScrollSize: getActualScrollSize,\n _scrollTo(offset) {\n offset = max(offset, 0);\n\n scrollTo(store._getItemIndexForScrollTo(offset), () => offset);\n },\n _scrollToIndex(index, count) {\n index = max(min(index, count - 1), 0);\n\n scrollTo(index, () => store._getItemOffset(index));\n },\n _fixScrollJump: (jump, startIndex) => {\n // Compensate scroll jump\n if (scrollDirection === SCROLL_UP) {\n const diff = calcTotalJump(jump);\n if (diff) {\n updateScrollPosition(diff, true);\n }\n } else if (scrollDirection === SCROLL_MANUAL) {\n const offset = store._getScrollOffset();\n if (offset === 0) {\n // Do nothing to stick to the start\n } else {\n const allDiff = calcTotalJump(jump);\n if (\n store._getScrollSize() -\n (offset + store._getViewportSize() + allDiff) <=\n 0\n ) {\n // Keep end to stick to the end\n if (allDiff) {\n updateScrollPosition(offset + allDiff);\n }\n } else {\n // Keep start at mid\n const diff = jump.reduce((acc, [index, j]) => {\n if (index < startIndex) {\n acc += j;\n }\n return acc;\n }, 0);\n if (diff) {\n updateScrollPosition(diff, true);\n }\n }\n }\n } else {\n // NOP\n }\n },\n };\n};\n"],"names":["min","Math","max","abs","now","Date","exists","v","range","length","cb","Array","from","_","i","getItemSize","cache","index","size","_sizes","_defaultItemSize","computeOffset","isTotal","_length","_measuredOffsetIndex","_offsets","top","computeStartOffset","findIndex","distance","sum","h","findStartIndexWithOffset","offset","prevStartIndex","prevOffset","findEndIndex","resetCache","itemSize","useIsomorphicLayoutEffect","window","useLayoutEffect","useEffect","useSyncExternalStore","subscibe","getSnapShot","_useSyncExternalStore","refKey","useStatic","init","ref","useRef","useRefWithUpdate","value","Item","memo","_children","children","_scroller","scroller","_store","store","_index","_element","Element","_subscribe","_getItemOffset","hide","_isUnmeasuredItem","_initItem","_jsx","style","useMemo","isHorizontal","_isHorizontal","leftOrRightKey","_isRtl","margin","padding","position","visibility","display","DefaultWindow","forwardRef","scrollSize","scrolling","horizontal","attrs","jsx","width","height","pointerEvents","Window","_ref","_scrolling","_attrs","_getScrollSize","overflow","contain","VList","itemSizeProp","overscan","horizontalProp","rtl","rtlProp","element","itemElement","onScroll","onScrollProp","onScrollStop","onScrollStopProp","onRangeChange","onRangeChangeProp","windowAttrs","elements","arr","Children","forEach","e","isInvalidElement","push","elementsCount","createVirtualStore","itemCount","isRtl","_scrollToQueue","viewportWidth","viewportHeight","scrollOffset","jump","_prevRange","subscribers","Set","getViewportSize","_getRange","prevEndIndex","start","end","_hasUnmeasuredItemsInRange","startIndex","hasUnmeasuredItemsInRange","endIndex","_getScrollOffset","_getViewportSize","computeTotalSize","_getItemCount","_getJump","_getItemIndexForScrollTo","_waitForScrollDestinationItemsMeasured","Promise","resolve","reject","then","undefined","add","delete","_update","type","payload","updated","filter","updatedJump","setItemSize","_width","_height","rootRef","mountedIndexes","reset","useState","setScrolling","createScroller","emitScrollOffsetChange","emitScrollStateChange","isNegativeOffset","rootElement","_ro","scrollDirection","resized","scrollToKey","WeakMap","getResizeObserver","ResizeObserver","entries","resizes","entry","target","contentRect","get","getActualScrollSize","scrollWidth","scrollHeight","updateScrollPosition","diff","prev","scrollTo","async","getCurrentOffset","getOffset","viewportSize","calcTotalJump","reduce","acc","j","_initRoot","root","ro","syncViewportToScrollPosition","onScrollStopped","debounce","id","cancel","clearTimeout","debouncedFn","setTimeout","_cancel","isScrollStart","onWheel","throttle","time","args","n","ctrlKey","deltaX","deltaY","fn","observe","addEventListener","passive","disconnect","removeEventListener","el","set","unobserve","_getActualScrollSize","_scrollTo","_scrollToIndex","count","_fixScrollJump","allDiff","isScrolling","useImperativeHandle","scrollToIndex","scrollBy","startIndexWithMargin","endIndexWithMargin","items","res","key"],"mappings":"yGAAO,MAAMA,EAAMC,KAAKD,IACXE,EAAMD,KAAKC,IACXC,EAAMF,KAAKE,IACXC,EAAMC,KAAKD,IAEXE,EAAaC,GAAiD,MAALA,EAEzDC,EAAQA,CAAIC,EAAgBC,IACvCC,MAAMC,KAAK,CAAEH,WAAU,CAACI,EAAGC,IAAMJ,EAAGI,KCKzBC,EAAcA,CAACC,EAAcC,KACxC,MAAMC,EAAOF,EAAMG,EAAOF,GAC1B,OAZsB,IAYfC,EAAoBF,EAAMI,EAAmBF,CAAI,EAapDG,EAAgBA,CACpBL,EACAC,EACAK,KAEA,IAAKN,EAAMO,EAAS,OAAO,EAC3B,GAAIP,EAAMQ,GAAwBP,EAChC,OAAIK,EACKN,EAAMS,EAASR,GAAUF,EAAYC,EAAOC,GAE5CD,EAAMS,EAASR,GAI1B,IAAIH,EAAIE,EAAMQ,EACVE,EAAMV,EAAMS,EAASX,GACzB,KAAOA,GAAKG,IACVD,EAAMS,EAASX,GAAKY,EAChBZ,IAAMG,GAAUK,IAGpBI,GAAOX,EAAYC,EAAOF,GAC1BA,IAIF,OADAE,EAAMQ,EAAuBP,EACtBS,CAAG,EAOCC,EAAqBA,CAChCX,EACAC,IAEOI,EAAcL,EAAOC,GAGxBW,EAAYA,CAACZ,EAAcF,EAAWe,KAC1C,IAAIC,EAAM,EACV,GAAID,GAAY,EAEd,KAAOf,EAAIE,EAAMO,EAAU,GAAG,CAC5B,MAAMQ,EAAIhB,EAAYC,EAAOF,KAC7B,IAAKgB,GAAOC,IAAMF,EAAU,CACtBC,EAAMC,EAAI,GAAKF,GACjBf,IAEF,KACD,CACF,MAGD,KAAOA,EAAI,GAAG,CAC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GnC,mBACF,OAAOzI,EAAMkF,GACd,EACDkG,cAAchO,GACZ0C,EAASgL,EAAe1N,EAAO2N,EAChC,EACD1C,SAAUvI,EAAS+K,EACnBQ,SAASjN,GACP0B,EAAS+K,EAAU7K,EAAMiF,IAAqB7G,EAC/C,KAGL,CAAC2M,IAGH,MAAMO,EAAuBjP,EAAIyI,EAAatC,EAAU,GAClD+I,EAAqBpP,EAAI6I,EAAWxC,EAAUuI,EAAQ,GACtDS,EAAQ7K,EAAAA,SAAQ,KACpB,MAAM8K,EAAsB,GAC5B,IAAK,IAAIxO,EAAIqO,EAAsBrO,GAAKsO,EAAoBtO,IAE1DwJ,EAAeZ,IAAI5I,GAkBrB,OAhBAwJ,EAAejD,SAASvG,IACtB,MAAMwG,EAAIJ,EAASpG,GAEfR,EAAOgH,IACTgI,EAAI9H,KACFlD,MAAChB,GAECI,EAAWC,EACXC,EAAQC,EACRC,EAAQhD,EACRiD,EAAU2C,EACVlD,EAAW8D,IALLA,aAAC,EAADA,EAAqCiI,MAAOzO,GAQvD,IAEIwO,CAAG,GACT,CAACpI,EAAUoD,EAAgB6E,EAAsBC,IAEpD,OACE9K,EAAAA,IAACsB,EAAM,CACLC,EAAMwE,EACNzG,EAAQC,EACRE,EAAU0C,EACVX,EAAYT,EACZ7B,EAAW6L,EACXtJ,GACA"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/src/core/utils.ts","../src/src/core/cache.ts","../src/src/react/useIsomorphicLayoutEffect.ts","../src/src/react/useSyncExternalStore.ts","../src/src/react/utils.ts","../src/src/react/useStatic.ts","../src/src/react/useRefWithUpdate.ts","../src/src/react/VList.tsx","../src/src/core/store.ts","../src/src/core/scroller.ts"],"sourcesContent":["export const min = Math.min;\nexport const max = Math.max;\nexport const abs = Math.abs;\nexport const now = Date.now;\n\nexport const exists = <T>(v: T): v is Exclude<T, null | undefined> => v != null;\n\nexport const range = <T>(length: number, cb: (i: number) => T): T[] =>\n Array.from({ length }, (_, i) => cb(i));\n\nexport const debounce = <T extends (...args: any[]) => void>(\n fn: T,\n ms: number\n) => {\n let id: NodeJS.Timeout | undefined | null;\n\n const cancel = () => {\n if (exists(id)) {\n clearTimeout(id);\n }\n };\n const debouncedFn = () => {\n cancel();\n id = setTimeout(() => {\n id = null;\n fn();\n }, ms);\n };\n debouncedFn._cancel = cancel;\n return debouncedFn;\n};\n\nexport const throttle = <T extends (...args: any[]) => void>(\n fn: T,\n ms: number\n) => {\n let time = now() - ms;\n return (...args: Parameters<T>) => {\n const n = now();\n if (time + ms < n) {\n time = n;\n fn(...args);\n }\n };\n};\n","import type { DeepReadonly, Writeable } from \"./types\";\nimport { exists, max, min, range } from \"./utils\";\n\nexport const UNCACHED = -1;\n\nexport type Cache = DeepReadonly<{\n _defaultItemSize: number;\n _length: number;\n _sizes: number[];\n _measuredOffsetIndex: number;\n _offsets: number[];\n}>;\n\nexport const getItemSize = (cache: Cache, index: number): number => {\n const size = cache._sizes[index]!;\n return size === UNCACHED ? cache._defaultItemSize : size;\n};\n\nexport const setItemSize = (\n cache: Writeable<Cache>,\n index: number,\n size: number\n) => {\n cache._sizes[index] = size;\n // mark as dirty\n cache._measuredOffsetIndex = min(index, cache._measuredOffsetIndex);\n};\n\nconst computeOffset = (\n cache: Writeable<Cache>,\n index: number,\n isTotal?: boolean\n): number => {\n if (!cache._length) return 0;\n if (cache._measuredOffsetIndex >= index) {\n if (isTotal) {\n return cache._offsets[index]! + getItemSize(cache, index);\n } else {\n return cache._offsets[index]!;\n }\n }\n\n let i = cache._measuredOffsetIndex;\n let top = cache._offsets[i]!;\n while (i <= index) {\n cache._offsets[i] = top;\n if (i === index && !isTotal) {\n break;\n }\n top += getItemSize(cache, i);\n i++;\n }\n // mark as measured\n cache._measuredOffsetIndex = index;\n return top;\n};\n\nexport const computeTotalSize = (cache: Writeable<Cache>): number => {\n return computeOffset(cache, cache._length - 1, true);\n};\n\nexport const computeStartOffset = (\n cache: Writeable<Cache>,\n index: number\n): number => {\n return computeOffset(cache, index);\n};\n\nconst findIndex = (cache: Cache, i: number, distance: number): number => {\n let sum = 0;\n if (distance >= 0) {\n // search forward\n while (i < cache._length - 1) {\n const h = getItemSize(cache, i++);\n if ((sum += h) >= distance) {\n if (sum - h / 2 >= distance) {\n i--;\n }\n break;\n }\n }\n } else {\n // search backward\n while (i > 0) {\n const h = getItemSize(cache, --i);\n if ((sum -= h) <= distance) {\n if (sum + h / 2 < distance) {\n i++;\n }\n break;\n }\n }\n }\n\n return min(max(i, 0), cache._length - 1);\n};\n\nexport const findStartIndexWithOffset = (\n cache: Cache,\n offset: number,\n prevStartIndex: number,\n prevOffset: number\n): number => {\n return findIndex(cache, prevStartIndex, offset - prevOffset);\n};\n\nexport const findEndIndex = findIndex;\n\nexport const hasUnmeasuredItemsInRange = (\n cache: Cache,\n startIndex: number,\n endIndex: number\n): boolean => {\n for (let i = startIndex; i <= endIndex; i++) {\n if (cache._sizes[i] === UNCACHED) {\n return true;\n }\n }\n return false;\n};\n\nexport const resetCache = (\n length: number,\n itemSize: number,\n cache?: Cache\n): Cache => {\n return {\n _defaultItemSize: itemSize,\n _length: length,\n _measuredOffsetIndex: cache\n ? min(cache._measuredOffsetIndex, length - 1)\n : 0,\n _sizes: range(length, (i) => {\n const size = cache && cache._sizes[i];\n if (exists(size)) {\n return size;\n }\n return UNCACHED;\n }),\n _offsets: range(length, (i) => {\n if (i === 0) {\n // first offset must be 0\n return 0;\n }\n const offset = cache && cache._offsets[i];\n if (exists(offset)) {\n return offset;\n }\n return UNCACHED;\n }),\n };\n};\n","import { useEffect, useLayoutEffect } from \"react\";\n\n// https://gist.github.com/gaearon/e7d97cdf38a2907924ea12e4ebdf3c85\nexport const useIsomorphicLayoutEffect =\n typeof window !== \"undefined\" ? useLayoutEffect : useEffect;\n","import { useSyncExternalStore as _useSyncExternalStore } from \"use-sync-external-store/shim/index.js\";\n\nexport const useSyncExternalStore = <T>(\n subscibe: (onStoreChange: () => void) => () => void,\n getSnapShot: () => T\n): T => {\n return _useSyncExternalStore(subscibe, getSnapShot, getSnapShot);\n};\n","export const refKey = \"current\";\n","import { useRef } from \"react\";\nimport { refKey } from \"./utils\";\n\nexport const useStatic = <T>(init: () => T): T => {\n const ref = useRef<T>();\n return ref[refKey] || (ref[refKey] = init());\n};\n","import { useRef } from \"react\";\nimport { useIsomorphicLayoutEffect } from \"./useIsomorphicLayoutEffect\";\nimport { refKey } from \"./utils\";\n\nexport const useRefWithUpdate = <T>(value: T) => {\n const ref = useRef<T>(value);\n\n useIsomorphicLayoutEffect(() => {\n ref[refKey] = value;\n }, [value]);\n\n return ref;\n};\n","import {\n Children,\n memo,\n useRef,\n useMemo,\n CSSProperties,\n ReactElement,\n forwardRef,\n useImperativeHandle,\n ReactNode,\n useEffect,\n RefObject,\n useState,\n ReactFragment,\n} from \"react\";\nimport { VirtualStore, createVirtualStore } from \"../core/store\";\nimport { useIsomorphicLayoutEffect } from \"./useIsomorphicLayoutEffect\";\nimport { useSyncExternalStore } from \"./useSyncExternalStore\";\nimport { exists, max, min } from \"../core/utils\";\nimport { createScroller, Scroller } from \"../core/scroller\";\nimport { refKey } from \"./utils\";\nimport { useStatic } from \"./useStatic\";\nimport { useRefWithUpdate } from \"./useRefWithUpdate\";\n\ntype ItemProps = {\n _children: ReactNode;\n _scroller: Scroller;\n _store: VirtualStore;\n _index: number;\n _element: \"div\";\n};\n\nconst Item = memo(\n ({\n _children: children,\n _scroller: scroller,\n _store: store,\n _index: index,\n _element: Element,\n }: ItemProps): ReactElement => {\n const ref = useRef<HTMLDivElement>(null);\n\n const offset = useSyncExternalStore(store._subscribe, () =>\n store._getItemOffset(index)\n );\n const hide = useSyncExternalStore(store._subscribe, () =>\n store._isUnmeasuredItem(index)\n );\n\n // The index may be changed if elements are inserted to or removed from the start of props.children\n useIsomorphicLayoutEffect(\n () => scroller._initItem(ref[refKey]!, index),\n [index]\n );\n\n return (\n <Element\n ref={ref}\n style={useMemo((): CSSProperties => {\n const isHorizontal = store._isHorizontal();\n const leftOrRightKey = store._isRtl() ? \"right\" : \"left\";\n const style: CSSProperties = {\n margin: 0,\n padding: 0,\n position: \"absolute\",\n [isHorizontal ? \"height\" : \"width\"]: \"100%\",\n [isHorizontal ? \"top\" : leftOrRightKey]: 0,\n [isHorizontal ? leftOrRightKey : \"top\"]: offset,\n visibility: hide ? \"hidden\" : \"visible\",\n // willChange: \"transform\",\n };\n if (isHorizontal) {\n style.display = \"flex\";\n }\n return style;\n }, [offset, hide])}\n >\n {children}\n </Element>\n );\n }\n);\n\nconst isInvalidElement = <T extends ReactNode>(\n e: T\n): e is Extract<T, null | undefined | boolean> =>\n !exists(e) || typeof e === \"boolean\";\n\nexport type WindowComponentAttributes = Pick<\n React.HTMLAttributes<HTMLElement>,\n \"className\" | \"style\" | \"id\" | \"role\" | \"tabIndex\"\n> &\n React.AriaAttributes;\n\n/**\n * Props of customized scrollable component.\n */\nexport interface CustomWindowComponentProps {\n children: ReactNode;\n scrollSize: number;\n scrolling: boolean;\n horizontal: boolean;\n attrs: WindowComponentAttributes;\n}\n\nconst DefaultWindow = forwardRef<any, CustomWindowComponentProps>(\n (\n { children, scrollSize, scrolling, horizontal, attrs },\n ref\n ): ReactElement => {\n return (\n <div ref={ref} {...attrs}>\n <div\n style={useMemo((): CSSProperties => {\n return {\n position: \"relative\",\n visibility: \"hidden\",\n width: horizontal ? scrollSize : \"100%\",\n height: horizontal ? \"100%\" : scrollSize,\n pointerEvents: scrolling ? \"none\" : \"auto\",\n };\n }, [scrollSize, scrolling])}\n >\n {children}\n </div>\n </div>\n );\n }\n);\n\nexport type CustomWindowComponent = typeof DefaultWindow;\n\nconst Window = ({\n _children: children,\n _ref: ref,\n _store: store,\n _element: Element,\n _scrolling: scrolling,\n _attrs: attrs,\n}: {\n _children: ReactNode;\n _ref: RefObject<HTMLDivElement>;\n _store: VirtualStore;\n _element: CustomWindowComponent;\n _scrolling: boolean;\n _attrs: WindowComponentAttributes;\n}) => {\n const scrollSize = useSyncExternalStore(\n store._subscribe,\n store._getScrollSize\n );\n\n const horizontal = store._isHorizontal();\n\n return (\n <Element\n ref={ref}\n scrollSize={scrollSize}\n scrolling={scrolling}\n horizontal={horizontal}\n attrs={useMemo(\n () => ({\n ...attrs,\n style: {\n overflow: horizontal ? \"auto hidden\" : \"hidden auto\",\n contain: \"strict\",\n // transform: \"translate3d(0px, 0px, 0px)\",\n // willChange: \"scroll-position\",\n // backfaceVisibility: \"hidden\",\n width: \"100%\",\n height: \"100%\",\n padding: 0,\n margin: 0,\n ...attrs.style,\n },\n }),\n [attrs]\n )}\n >\n {children}\n </Element>\n );\n};\n\n/**\n * Props of customized item component.\n */\nexport interface CustomItemComponentProps {\n style: CSSProperties;\n children: ReactNode;\n}\n\nexport type CustomItemComponent = React.ForwardRefExoticComponent<\n React.PropsWithoutRef<CustomItemComponentProps> & React.RefAttributes<any>\n>;\n\ntype CustomItemComponentOrElement =\n | keyof JSX.IntrinsicElements\n | CustomItemComponent;\n\n/**\n * Methods of {@link VList}.\n */\nexport interface VListHandle {\n /**\n * Get current scrollTop or scrollLeft.\n */\n readonly scrollOffset: number;\n /**\n * Get current scrollHeight or scrollWidth.\n */\n readonly scrollSize: number;\n /**\n * Get current offsetHeight or offsetWidth.\n */\n readonly viewportSize: number;\n /**\n * Scroll to the item specified by index.\n * @param index index of item\n */\n scrollToIndex(index: number): void;\n /**\n * Scroll to the given offset.\n * @param offset offset from start\n */\n scrollTo(offset: number): void;\n /**\n * Scroll by the given offset.\n * @param offset offset from current position\n */\n scrollBy(offset: number): void;\n}\n\n/**\n * Props of {@link VList}.\n */\nexport interface VListProps extends WindowComponentAttributes {\n /**\n * Elements rendered by this component.\n */\n children: ReactNode;\n /**\n * Item size hint for unmeasured items. It's recommended to specify this prop if item sizes are fixed and known, or much larger than the defaultValue. It will help to reduce scroll jump when items are measured.\n * @defaultValue 40\n */\n itemSize?: number;\n /**\n * Number of items to render above/below the visible bounds of the list. You can increase to avoid showing blank items in fast scrolling.\n * @defaultValue 4\n */\n overscan?: number;\n /**\n * If true, rendered as a horizontally scrollable list. Otherwise rendered as a vertically scrollable list.\n */\n horizontal?: boolean;\n /**\n * You have to set true if you use this component under `direction: rtl` style.\n */\n rtl?: boolean;\n /**\n * Customized element type for scrollable element. This element will get {@link CustomWindowComponentProps} as props.\n * @defaultValue {@link DefaultWindow}\n */\n element?: CustomWindowComponent;\n /**\n * Customized element type for item element. This element will get {@link CustomItemComponentProps} as props.\n * @defaultValue \"div\"\n */\n itemElement?: CustomItemComponentOrElement;\n /**\n * Callback invoked whenever scroll offset changes.\n * @param offset Current scrollTop or scrollLeft.\n */\n onScroll?: (offset: number) => void;\n /**\n * Callback invoked when scrolling stops.\n */\n onScrollStop?: () => void;\n /**\n * Callback invoked when visible items range changes.\n * @param payload `start` is the start index of viewable items. `end` is the end index of viewable items. `count` is the total count of items.\n */\n onRangeChange?: (payload: {\n start: number;\n end: number;\n count: number;\n }) => void;\n}\n\n/**\n * Virtualized list component. See {@link VListProps} and {@link VListHandle}.\n */\nexport const VList = forwardRef<VListHandle, VListProps>(\n (\n {\n children,\n itemSize: itemSizeProp = 40,\n overscan = 4,\n horizontal: horizontalProp,\n rtl: rtlProp,\n element = DefaultWindow,\n itemElement = \"div\",\n onScroll: onScrollProp,\n onScrollStop: onScrollStopProp,\n onRangeChange: onRangeChangeProp,\n ...windowAttrs\n },\n ref\n ): ReactElement => {\n // Memoize element array\n const elements = useMemo(() => {\n const arr: (ReactElement | ReactFragment | string | number)[] = [];\n Children.forEach(children, (e) => {\n if (isInvalidElement(e)) {\n return;\n }\n arr.push(e);\n });\n return arr;\n }, [children]);\n const count = elements.length;\n\n // https://github.com/facebook/react/issues/25191#issuecomment-1237456448\n const store = useStatic(() =>\n createVirtualStore(count, itemSizeProp, !!horizontalProp, !!rtlProp)\n );\n // The elements length and cached items length are different just after element is added/removed.\n store._updateCacheLength(count);\n\n const [startIndex, endIndex] = useSyncExternalStore(\n store._subscribe,\n store._getRange\n );\n const jump = useSyncExternalStore(store._subscribe, store._getJump);\n const rootRef = useRef<HTMLDivElement>(null);\n\n const onScroll = useRefWithUpdate(onScrollProp);\n const onScrollStop = useRefWithUpdate(onScrollStopProp);\n\n const [mountedIndexes, reset] = useState<Set<number>>(new Set<number>());\n const [scrolling, setScrolling] = useState(false);\n const scroller = useStatic(() =>\n createScroller(\n store,\n (offset) => {\n onScroll[refKey] && onScroll[refKey](offset);\n },\n (isScrolling) => {\n setScrolling(isScrolling);\n if (!isScrolling) {\n reset(new Set());\n onScrollStop[refKey] && onScrollStop[refKey]();\n }\n }\n )\n );\n\n useIsomorphicLayoutEffect(() => scroller._initRoot(rootRef[refKey]!), []);\n\n useIsomorphicLayoutEffect(() => {\n if (!jump.length) return;\n\n scroller._fixScrollJump(jump, startIndex);\n }, [jump]);\n\n useEffect(() => {\n if (!onRangeChangeProp) return;\n\n onRangeChangeProp({\n start: startIndex,\n end: endIndex,\n count,\n });\n }, [startIndex, endIndex]);\n\n useImperativeHandle(\n ref,\n () => {\n return {\n get scrollOffset() {\n return store._getScrollOffset();\n },\n get scrollSize() {\n return scroller._getActualScrollSize();\n },\n get viewportSize() {\n return store._getViewportSize();\n },\n scrollToIndex(index) {\n scroller._scrollToIndex(index, count);\n },\n scrollTo: scroller._scrollTo,\n scrollBy(offset) {\n scroller._scrollTo(store._getScrollOffset() + offset);\n },\n };\n },\n [count]\n );\n\n const startIndexWithMargin = max(startIndex - overscan, 0);\n const endIndexWithMargin = min(endIndex + overscan, count - 1);\n const items = useMemo(() => {\n const res: ReactElement[] = [];\n for (let i = startIndexWithMargin; i <= endIndexWithMargin; i++) {\n // https://github.com/sergi/virtual-list/commit/8e7e06dc63568334c1ab809ea83c1be36572e9ed\n mountedIndexes.add(i);\n }\n mountedIndexes.forEach((i) => {\n const e = elements[i];\n // This can be undefined when items are removed\n if (exists(e)) {\n res.push(\n <Item\n key={(e as { key?: ReactElement[\"key\"] })?.key || i}\n _scroller={scroller}\n _store={store}\n _index={i}\n _element={itemElement as \"div\"}\n _children={e}\n />\n );\n }\n });\n return res;\n }, [elements, mountedIndexes, startIndexWithMargin, endIndexWithMargin]);\n\n return (\n <Window\n _ref={rootRef}\n _store={store}\n _element={element}\n _scrolling={scrolling}\n _children={items}\n _attrs={windowAttrs}\n />\n );\n }\n);\n","import {\n findStartIndexWithOffset,\n resetCache,\n getItemSize,\n computeTotalSize,\n findEndIndex,\n computeStartOffset,\n Cache,\n UNCACHED,\n setItemSize,\n hasUnmeasuredItemsInRange,\n} from \"./cache\";\nimport type { Writeable } from \"./types\";\n\nexport type ScrollJump = Readonly<[index: number, sizeDiff: number][]>;\nexport type ItemResize = [index: number, size: number];\ntype ItemsRange = [startIndex: number, endIndex: number];\n\nexport const ACTION_UPDATE_ITEM_SIZES = 1;\nexport const ACTION_UPDATE_VIEWPORT = 2;\nexport const ACTION_HANDLE_SCROLL = 3;\n\ntype Actions =\n | [type: typeof ACTION_UPDATE_ITEM_SIZES, entries: ItemResize[]]\n | [\n type: typeof ACTION_UPDATE_VIEWPORT,\n rect: { _width: number; _height: number }\n ]\n | [type: typeof ACTION_HANDLE_SCROLL, offset: number];\n\nexport type VirtualStore = {\n _getRange(): ItemsRange;\n _isUnmeasuredItem(index: number): boolean;\n _hasUnmeasuredItemsInRange(startIndex: number): boolean;\n _getItemOffset(index: number): number;\n _getScrollOffset(): number;\n _getViewportSize(): number;\n _getScrollSize(): number;\n _getJump(): ScrollJump;\n _isHorizontal(): boolean;\n _isRtl(): boolean;\n _getItemIndexForScrollTo(offset: number): number;\n _waitForScrollDestinationItemsMeasured(): Promise<void>;\n _subscribe(cb: () => void): () => void;\n _update(...action: Actions): void;\n _updateCacheLength(length: number): void;\n};\n\nexport const createVirtualStore = (\n itemCount: number,\n itemSize: number,\n isHorizontal: boolean,\n isRtl: boolean\n): VirtualStore => {\n let viewportWidth = 0;\n let viewportHeight = 0;\n let scrollOffset = 0;\n let jump: ScrollJump = [];\n let cache = resetCache(itemCount, itemSize);\n let _prevRange: ItemsRange = [0, 0];\n let _scrollToQueue: [() => void, () => void] | undefined;\n\n const subscribers = new Set<() => void>();\n const getViewportSize = (): number =>\n isHorizontal ? viewportWidth : viewportHeight;\n\n return {\n _getRange() {\n const [prevStartIndex, prevEndIndex] = _prevRange;\n const prevOffset = computeStartOffset(\n cache as Writeable<Cache>,\n prevStartIndex\n );\n const start = findStartIndexWithOffset(\n cache,\n scrollOffset,\n prevStartIndex,\n prevOffset\n );\n const end = findEndIndex(cache, start, getViewportSize());\n if (prevStartIndex === start && prevEndIndex === end) {\n return _prevRange;\n }\n return (_prevRange = [start, end]);\n },\n _isUnmeasuredItem(index) {\n return cache._sizes[index] === UNCACHED;\n },\n _hasUnmeasuredItemsInRange(startIndex) {\n return hasUnmeasuredItemsInRange(\n cache,\n startIndex,\n findEndIndex(cache, startIndex, getViewportSize())\n );\n },\n _getItemOffset(index) {\n return computeStartOffset(cache as Writeable<Cache>, index);\n },\n _getScrollOffset() {\n return scrollOffset;\n },\n _getViewportSize() {\n return getViewportSize();\n },\n _getScrollSize() {\n return computeTotalSize(cache as Writeable<Cache>);\n },\n _getJump() {\n return jump;\n },\n _isHorizontal() {\n return isHorizontal;\n },\n _isRtl() {\n return isRtl;\n },\n _getItemIndexForScrollTo(offset) {\n return findStartIndexWithOffset(cache, offset, 0, 0);\n },\n _waitForScrollDestinationItemsMeasured() {\n if (_scrollToQueue) {\n // Cancel waiting scrollTo\n _scrollToQueue[1]();\n }\n // The measurement will be done asynchronously and the timing is not predictable so we use promise.\n // For example, ResizeObserver may not fire when window is not visible.\n return new Promise((resolve, reject) => {\n _scrollToQueue = [\n () => {\n // HACK: It should be resolved in the next microtask that is after React's render\n Promise.resolve().then(() => {\n resolve();\n _scrollToQueue = undefined;\n });\n },\n reject,\n ];\n });\n },\n _subscribe(cb) {\n subscribers.add(cb);\n return () => {\n subscribers.delete(cb);\n };\n },\n _update(type, payload) {\n const mutated = ((): boolean => {\n switch (type) {\n case ACTION_UPDATE_ITEM_SIZES: {\n const updated = payload.filter(\n ([index, size]) => cache._sizes[index] !== size\n );\n // Skip if all items are cached and not updated\n if (!updated.length) {\n return false;\n }\n\n const updatedJump: [index: number, sizeDiff: number][] = [];\n updated.forEach(([index, size]) => {\n updatedJump.push([index, size - getItemSize(cache, index)]);\n setItemSize(cache as Writeable<Cache>, index, size);\n });\n jump = updatedJump;\n return true;\n }\n case ACTION_UPDATE_VIEWPORT: {\n if (\n viewportWidth === payload._width &&\n viewportHeight === payload._height\n ) {\n return false;\n }\n viewportWidth = payload._width;\n viewportHeight = payload._height;\n return true;\n }\n case ACTION_HANDLE_SCROLL: {\n const prevOffset = scrollOffset;\n return (scrollOffset = payload) !== prevOffset;\n }\n }\n })();\n\n if (mutated) {\n subscribers.forEach((cb) => {\n cb();\n });\n if (_scrollToQueue && type === ACTION_UPDATE_ITEM_SIZES) {\n _scrollToQueue[0]();\n }\n }\n },\n _updateCacheLength(length) {\n // It's ok to be updated in render because states should be calculated consistently regardless cache length\n if (cache._length === length) return;\n cache = resetCache(length, itemSize, cache);\n },\n };\n};\n","import {\n ACTION_HANDLE_SCROLL,\n ACTION_UPDATE_ITEM_SIZES,\n ACTION_UPDATE_VIEWPORT,\n ItemResize,\n ScrollJump,\n VirtualStore,\n} from \"./store\";\nimport { abs, debounce, throttle, exists, max, min } from \"./utils\";\n\nexport const SCROLL_STOP = 0;\nexport const SCROLL_DOWN = 1;\nexport const SCROLL_UP = 2;\nexport const SCROLL_MANUAL = 3;\ntype ScrollDirection =\n | typeof SCROLL_STOP\n | typeof SCROLL_DOWN\n | typeof SCROLL_UP\n | typeof SCROLL_MANUAL;\n\nexport type Scroller = {\n _initRoot: (rootElement: HTMLElement) => () => void;\n _initItem: (itemElement: HTMLElement, index: number) => () => void;\n _getActualScrollSize: () => number;\n _scrollTo: (offset: number) => void;\n _scrollToIndex: (index: number, count: number) => void;\n _fixScrollJump: (jump: ScrollJump, startIndex: number) => void;\n};\n\nexport const createScroller = (\n store: VirtualStore,\n emitScrollOffsetChange: (offset: number) => void,\n emitScrollStateChange: (scrolling: boolean) => void\n): Scroller => {\n let prevOffset = -1;\n let scrollDirection: ScrollDirection = SCROLL_STOP;\n let resized = false;\n let isNegativeOffset: boolean | undefined;\n let rootElement: HTMLElement | undefined;\n let _ro: ResizeObserver | undefined;\n const isHorizontal = store._isHorizontal();\n const isRtl = store._isRtl();\n const scrollToKey = isHorizontal ? \"scrollLeft\" : \"scrollTop\";\n const mountedIndexes = new WeakMap<Element, number>();\n const getResizeObserver = (): ResizeObserver => {\n // Initialize ResizeObserver lazily for SSR\n return (\n _ro ||\n (_ro = new ResizeObserver((entries) => {\n // https://www.w3.org/TR/resize-observer/#intro\n const resizes: ItemResize[] = [];\n for (const entry of entries) {\n if (entry.target === rootElement) {\n store._update(ACTION_UPDATE_VIEWPORT, {\n _width: entry.contentRect.width,\n _height: entry.contentRect.height,\n });\n } else {\n const index = mountedIndexes.get(entry.target);\n if (exists(index)) {\n resizes.push([\n index,\n entry.contentRect[isHorizontal ? \"width\" : \"height\"],\n ]);\n }\n }\n }\n\n if (resizes.length) {\n store._update(ACTION_UPDATE_ITEM_SIZES, resizes);\n resized = true;\n }\n }))\n );\n };\n const getActualScrollSize = (): number => {\n if (!rootElement) return 0;\n // Use element's scrollHeight/scrollWidth instead of stored scrollSize.\n // This is because stored size may differ from the actual size, for example when a new item is added and not yet measured.\n return store._isHorizontal()\n ? rootElement.scrollWidth\n : rootElement.scrollHeight;\n };\n const updateScrollPosition = (offset: number, diff?: boolean) => {\n if (!rootElement) return;\n if (isRtl) {\n if (!exists(isNegativeOffset)) {\n // Assume offset type in rtl direction.\n // The scroll position is negative in spec however its not in some browsers, for example Chrome earlier than v85.\n // https://github.com/othree/jquery.rtl-scroll-type\n const prev = rootElement[scrollToKey];\n rootElement[scrollToKey] = 1;\n isNegativeOffset = rootElement[scrollToKey] === 0;\n rootElement[scrollToKey] = prev;\n }\n if (isNegativeOffset) {\n offset *= -1;\n }\n }\n if (diff) {\n rootElement[scrollToKey] += offset;\n } else {\n rootElement[scrollToKey] = offset;\n scrollDirection = SCROLL_MANUAL;\n }\n };\n const scrollTo = async (index: number, getCurrentOffset: () => number) => {\n const getOffset = (): number => {\n let offset = getCurrentOffset();\n const scrollSize = getActualScrollSize();\n const viewportSize = store._getViewportSize();\n if (scrollSize - (offset + viewportSize) <= 0) {\n // Adjust if the offset is over the end, to get correct startIndex.\n offset = scrollSize - viewportSize;\n }\n return offset;\n };\n\n if (store._hasUnmeasuredItemsInRange(index)) {\n do {\n // In order to scroll to the correct position, mount the items and measure their sizes before scrolling.\n store._update(ACTION_HANDLE_SCROLL, getOffset());\n try {\n // Wait for the scroll destination items to be measured.\n await store._waitForScrollDestinationItemsMeasured();\n } catch (e) {\n // canceled\n return;\n }\n } while (store._hasUnmeasuredItemsInRange(index));\n\n // Scroll with the updated value\n updateScrollPosition(getOffset());\n } else {\n const offset = getOffset();\n updateScrollPosition(offset);\n // Sync viewport to scroll destination\n store._update(ACTION_HANDLE_SCROLL, offset);\n }\n };\n\n const calcTotalJump = (jump: ScrollJump): number =>\n jump.reduce((acc, [, j]) => acc + j, 0);\n\n return {\n _initRoot(root) {\n rootElement = root;\n const ro = getResizeObserver();\n\n const syncViewportToScrollPosition = () => {\n let offset = root[scrollToKey];\n if (isRtl) {\n // The scroll position may be negative value in rtl direction.\n // https://github.com/othree/jquery.rtl-scroll-type\n offset = abs(offset);\n }\n if (prevOffset === offset) {\n return;\n }\n // Skip scroll direction detection just after resizing because it may result in the opposite direction.\n // Scroll events are dispatched enough so it's ok to skip some of them.\n if (scrollDirection === SCROLL_STOP || !resized) {\n // Ignore until manual scrolling\n if (scrollDirection !== SCROLL_MANUAL) {\n scrollDirection = prevOffset > offset ? SCROLL_UP : SCROLL_DOWN;\n }\n } else {\n resized = false;\n }\n store._update(ACTION_HANDLE_SCROLL, (prevOffset = offset));\n emitScrollOffsetChange(offset);\n };\n\n const onScrollStopped = debounce(() => {\n // Check scroll position once just after scrolling stopped\n syncViewportToScrollPosition();\n scrollDirection = SCROLL_STOP;\n emitScrollStateChange(false);\n }, 150);\n\n const onScroll = () => {\n const isScrollStart = scrollDirection === SCROLL_STOP;\n syncViewportToScrollPosition();\n if (isScrollStart) {\n emitScrollStateChange(true);\n }\n onScrollStopped();\n };\n\n // Infer scroll state also from wheel events\n // Sometimes scroll events do not fire when frame dropped even if the visual have been already scrolled\n const onWheel = throttle((e: WheelEvent) => {\n if (scrollDirection === SCROLL_STOP) {\n // Scroll start should be detected with scroll event\n return;\n }\n if (e.ctrlKey) {\n // Probably a pinch-to-zoom gesture\n return;\n }\n // Get delta before checking deltaMode for firefox behavior\n // https://github.com/w3c/uievents/issues/181#issuecomment-392648065\n // https://bugzilla.mozilla.org/show_bug.cgi?id=1392460#c34\n if (isHorizontal ? e.deltaX : e.deltaY) {\n if (\n prevOffset > 0 &&\n prevOffset < store._getScrollSize() - store._getViewportSize()\n ) {\n onScrollStopped();\n }\n }\n }, 50);\n\n ro.observe(root);\n root.addEventListener(\"scroll\", onScroll);\n root.addEventListener(\"wheel\", onWheel, { passive: true });\n\n return () => {\n ro.disconnect();\n root.removeEventListener(\"scroll\", onScroll);\n root.removeEventListener(\"wheel\", onWheel);\n onScrollStopped._cancel();\n };\n },\n _initItem(el, i) {\n const ro = getResizeObserver();\n mountedIndexes.set(el, i);\n ro.observe(el);\n return () => {\n mountedIndexes.delete(el);\n ro.unobserve(el);\n };\n },\n _getActualScrollSize: getActualScrollSize,\n _scrollTo(offset) {\n offset = max(offset, 0);\n\n scrollTo(store._getItemIndexForScrollTo(offset), () => offset);\n },\n _scrollToIndex(index, count) {\n index = max(min(index, count - 1), 0);\n\n scrollTo(index, () => store._getItemOffset(index));\n },\n _fixScrollJump: (jump, startIndex) => {\n // Compensate scroll jump\n if (scrollDirection === SCROLL_UP) {\n const diff = calcTotalJump(jump);\n if (diff) {\n updateScrollPosition(diff, true);\n }\n } else if (scrollDirection === SCROLL_MANUAL) {\n const offset = store._getScrollOffset();\n if (offset === 0) {\n // Do nothing to stick to the start\n } else {\n const allDiff = calcTotalJump(jump);\n if (\n store._getScrollSize() -\n (offset + store._getViewportSize() + allDiff) <=\n 0\n ) {\n // Keep end to stick to the end\n if (allDiff) {\n updateScrollPosition(offset + allDiff);\n }\n } else {\n // Keep start at mid\n const diff = jump.reduce((acc, [index, j]) => {\n if (index < startIndex) {\n acc += j;\n }\n return acc;\n }, 0);\n if (diff) {\n updateScrollPosition(diff, true);\n }\n }\n }\n } else {\n // NOP\n }\n },\n };\n};\n"],"names":["min","Math","max","abs","now","Date","exists","v","range","length","cb","Array","from","_","i","getItemSize","cache","index","size","_sizes","_defaultItemSize","computeOffset","isTotal","_length","_measuredOffsetIndex","_offsets","top","computeStartOffset","findIndex","distance","sum","h","findStartIndexWithOffset","offset","prevStartIndex","prevOffset","findEndIndex","resetCache","itemSize","useIsomorphicLayoutEffect","window","useLayoutEffect","useEffect","useSyncExternalStore","subscibe","getSnapShot","_useSyncExternalStore","refKey","useStatic","init","ref","useRef","useRefWithUpdate","value","Item","memo","_children","children","_scroller","scroller","_store","store","_index","_element","Element","_subscribe","_getItemOffset","hide","_isUnmeasuredItem","_initItem","_jsx","style","useMemo","isHorizontal","_isHorizontal","leftOrRightKey","_isRtl","margin","padding","position","visibility","display","DefaultWindow","forwardRef","scrollSize","scrolling","horizontal","attrs","jsx","width","height","pointerEvents","Window","_ref","_scrolling","_attrs","_getScrollSize","overflow","contain","VList","itemSizeProp","overscan","horizontalProp","rtl","rtlProp","element","itemElement","onScroll","onScrollProp","onScrollStop","onScrollStopProp","onRangeChange","onRangeChangeProp","windowAttrs","elements","arr","Children","forEach","e","isInvalidElement","push","count","createVirtualStore","itemCount","isRtl","_scrollToQueue","viewportWidth","viewportHeight","scrollOffset","jump","_prevRange","subscribers","Set","getViewportSize","_getRange","prevEndIndex","start","end","_hasUnmeasuredItemsInRange","startIndex","hasUnmeasuredItemsInRange","endIndex","_getScrollOffset","_getViewportSize","computeTotalSize","_getJump","_getItemIndexForScrollTo","_waitForScrollDestinationItemsMeasured","Promise","resolve","reject","then","undefined","add","delete","_update","type","payload","mutated","updated","filter","updatedJump","setItemSize","_width","_height","_updateCacheLength","rootRef","mountedIndexes","reset","useState","setScrolling","createScroller","emitScrollOffsetChange","emitScrollStateChange","isNegativeOffset","rootElement","_ro","scrollDirection","resized","scrollToKey","WeakMap","getResizeObserver","ResizeObserver","entries","resizes","entry","target","contentRect","get","getActualScrollSize","scrollWidth","scrollHeight","updateScrollPosition","diff","prev","scrollTo","async","getCurrentOffset","getOffset","viewportSize","calcTotalJump","reduce","acc","j","_initRoot","root","ro","syncViewportToScrollPosition","onScrollStopped","debounce","id","cancel","clearTimeout","debouncedFn","setTimeout","_cancel","isScrollStart","onWheel","throttle","time","args","n","ctrlKey","deltaX","deltaY","fn","observe","addEventListener","passive","disconnect","removeEventListener","el","set","unobserve","_getActualScrollSize","_scrollTo","_scrollToIndex","_fixScrollJump","allDiff","isScrolling","useImperativeHandle","scrollToIndex","scrollBy","startIndexWithMargin","endIndexWithMargin","items","res","key"],"mappings":"yGAAO,MAAMA,EAAMC,KAAKD,IACXE,EAAMD,KAAKC,IACXC,EAAMF,KAAKE,IACXC,EAAMC,KAAKD,IAEXE,EAAaC,GAAiD,MAALA,EAEzDC,EAAQA,CAAIC,EAAgBC,IACvCC,MAAMC,KAAK,CAAEH,WAAU,CAACI,EAAGC,IAAMJ,EAAGI,KCKzBC,EAAcA,CAACC,EAAcC,KACxC,MAAMC,EAAOF,EAAMG,EAAOF,GAC1B,OAZsB,IAYfC,EAAoBF,EAAMI,EAAmBF,CAAI,EAapDG,EAAgBA,CACpBL,EACAC,EACAK,KAEA,IAAKN,EAAMO,EAAS,OAAO,EAC3B,GAAIP,EAAMQ,GAAwBP,EAChC,OAAIK,EACKN,EAAMS,EAASR,GAAUF,EAAYC,EAAOC,GAE5CD,EAAMS,EAASR,GAI1B,IAAIH,EAAIE,EAAMQ,EACVE,EAAMV,EAAMS,EAASX,GACzB,KAAOA,GAAKG,IACVD,EAAMS,EAASX,GAAKY,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sx as e}from"react/jsx-runtime";import{useLayoutEffect as t,useEffect as r,useRef as n,memo as o,useMemo as s,forwardRef as l,Children as i,useState as c,useImperativeHandle as u}from"react";import{useSyncExternalStore as a}from"use-sync-external-store/shim/index.js";const f=Math.min,
|
|
1
|
+
import{jsx as e}from"react/jsx-runtime";import{useLayoutEffect as t,useEffect as r,useRef as n,memo as o,useMemo as s,forwardRef as l,Children as i,useState as c,useImperativeHandle as u}from"react";import{useSyncExternalStore as a}from"use-sync-external-store/shim/index.js";const f=Math.min,d=Math.max,_=Math.abs,h=Date.now,m=e=>null!=e,g=(e,t)=>Array.from({length:e},((e,r)=>t(r))),p=(e,t)=>{const r=e.t[t];return-1===r?e.o:r},S=(e,t,r)=>{if(!e.l)return 0;if(e.i>=t)return r?e.u[t]+p(e,t):e.u[t];let n=e.i,o=e.u[n];for(;n<=t&&(e.u[n]=o,n!==t||r);)o+=p(e,n),n++;return e.i=t,o},w=(e,t)=>S(e,t),v=(e,t,r)=>{let n=0;if(r>=0)for(;t<e.l-1;){const o=p(e,t++);if((n+=o)>=r){n-o/2>=r&&t--;break}}else for(;t>0;){const o=p(e,--t);if((n-=o)<=r){n+o/2<r&&t++;break}}return f(d(t,0),e.l-1)},z=(e,t,r,n)=>v(e,r,t-n),x=v,y=(e,t,r)=>({o:t,l:e,i:r?f(r.i,e-1):0,t:g(e,(e=>{const t=r&&r.t[e];return m(t)?t:-1})),u:g(e,(e=>{if(0===e)return 0;const t=r&&r.u[e];return m(t)?t:-1}))}),I="undefined"!=typeof window?t:r,b=(e,t)=>a(e,t,t),T="current",R=e=>{const t=n();return t[T]||(t[T]=e())},M=e=>{const t=n(e);return I((()=>{t[T]=e}),[e]),t},O=/*#__PURE__*/o((({_:t,h:r,m:o,g:l,p:i})=>{const c=n(null),u=b(o.S,(()=>o.v(l))),a=b(o.S,(()=>o.I(l)));return I((()=>r.T(c[T],l)),[l]),e(i,{ref:c,style:s((()=>{const e=o.R(),t=o.M()?"right":"left",r={margin:0,padding:0,position:"absolute",[e?"height":"width"]:"100%",[e?"top":t]:0,[e?t:"top"]:u,visibility:a?"hidden":"visible"};return e&&(r.display="flex"),r}),[u,a]),children:t})})),k=/*#__PURE__*/l((({children:t,scrollSize:r,scrolling:n,horizontal:o,attrs:l},i)=>e("div",{ref:i,...l,children:e("div",{style:s((()=>({position:"relative",visibility:"hidden",width:o?r:"100%",height:o?"100%":r,pointerEvents:n?"none":"auto"})),[r,n]),children:t})}))),E=({_:t,O:r,m:n,p:o,k:l,j:i})=>{const c=b(n.S,n.A),u=n.R();return e(o,{ref:r,scrollSize:c,scrolling:l,horizontal:u,attrs:s((()=>({...i,style:{overflow:u?"auto hidden":"hidden auto",contain:"strict",width:"100%",height:"100%",padding:0,margin:0,...i.style}})),[i]),children:t})},j=/*#__PURE__*/l((({children:t,itemSize:o=40,overscan:l=4,horizontal:a,rtl:g,element:v=k,itemElement:j="div",onScroll:A,onScrollStop:C,onRangeChange:D,...F},J)=>{const L=s((()=>{const e=[];return i.forEach(t,(t=>{(e=>!m(e)||"boolean"==typeof e)(t)||e.push(t)})),e}),[t]),P=L.length,U=R((()=>((e,t,r,n)=>{let o,s=0,l=0,i=0,c=[],u=y(e,t),a=[0,0];const d=new Set,_=()=>r?s:l;return{C(){const[e,t]=a,r=w(u,e),n=z(u,i,e,r),o=x(u,n,_());return e===n&&t===o?a:a=[n,o]},I:e=>-1===u.t[e],D:e=>((e,t,r)=>{for(let n=t;n<=r;n++)if(-1===e.t[n])return!0;return!1})(u,e,x(u,e,_())),v:e=>w(u,e),F:()=>i,J:()=>_(),A:()=>(e=>S(e,e.l-1,!0))(u),L:()=>c,R:()=>r,M:()=>n,P:e=>z(u,e,0,0),U:()=>(o&&o[1](),new Promise(((e,t)=>{o=[()=>{Promise.resolve().then((()=>{e(),o=void 0}))},t]}))),S:e=>(d.add(e),()=>{d.delete(e)}),B(e,t){const r=(()=>{switch(e){case 1:{const e=t.filter((([e,t])=>u.t[e]!==t));if(!e.length)return!1;const r=[];return e.forEach((([e,t])=>{r.push([e,t-p(u,e)]),((e,t,r)=>{e.t[t]=r,e.i=f(t,e.i)})(u,e,t)})),c=r,!0}case 2:return(s!==t.H||l!==t.V)&&(s=t.H,l=t.V,!0);case 3:{const e=i;return(i=t)!==e}}})();r&&(d.forEach((e=>{e()})),o&&1===e&&o[0]())},W(e){u.l!==e&&(u=y(e,t,u))}}})(P,o,!!a,!!g)));U.W(P);const[B,H]=b(U.S,U.C),V=b(U.S,U.L),W=n(null),q=M(A),G=M(C),[K,N]=c(new Set),[Q,X]=c(!1),Y=R((()=>((e,t,r)=>{let n,o,s,l=-1,i=0,c=!1;const u=e.R(),a=e.M(),g=u?"scrollLeft":"scrollTop",p=new WeakMap,S=()=>s||(s=new ResizeObserver((t=>{const r=[];for(const n of t)if(n.target===o)e.B(2,{H:n.contentRect.width,V:n.contentRect.height});else{const e=p.get(n.target);m(e)&&r.push([e,n.contentRect[u?"width":"height"]])}r.length&&(e.B(1,r),c=!0)}))),w=()=>o?e.R()?o.scrollWidth:o.scrollHeight:0,v=(e,t)=>{if(o){if(a){if(!m(n)){const e=o[g];o[g]=1,n=0===o[g],o[g]=e}n&&(e*=-1)}t?o[g]+=e:(o[g]=e,i=3)}},z=async(t,r)=>{const n=()=>{let t=r();const n=w(),o=e.J();return n-(t+o)<=0&&(t=n-o),t};if(e.D(t)){do{e.B(3,n());try{await e.U()}catch(e){return}}while(e.D(t));v(n())}else{const t=n();v(t),e.B(3,t)}},x=e=>e.reduce(((e,[,t])=>e+t),0);return{q(n){o=n;const s=S(),f=()=>{let r=n[g];a&&(r=_(r)),l!==r&&(0!==i&&c?c=!1:3!==i&&(i=l>r?2:1),e.B(3,l=r),t(r))},d=(()=>{let e;const t=()=>{m(e)&&clearTimeout(e)},n=()=>{t(),e=setTimeout((()=>{e=null,f(),i=0,r(!1)}),150)};return n.G=t,n})(),p=()=>{const e=0===i;f(),e&&r(!0),d()},w=(()=>{let t=h()-50;return(...r)=>{const n=h();t+50<n&&(t=n,(t=>{0!==i&&(t.ctrlKey||(u?t.deltaX:t.deltaY)&&l>0&&l<e.A()-e.J()&&d())})(...r))}})();return s.observe(n),n.addEventListener("scroll",p),n.addEventListener("wheel",w,{passive:!0}),()=>{s.disconnect(),n.removeEventListener("scroll",p),n.removeEventListener("wheel",w),d.G()}},T(e,t){const r=S();return p.set(e,t),r.observe(e),()=>{p.delete(e),r.unobserve(e)}},K:w,N(t){t=d(t,0),z(e.P(t),(()=>t))},X(t,r){t=d(f(t,r-1),0),z(t,(()=>e.v(t)))},Y:(t,r)=>{if(2===i){const e=x(t);e&&v(e,!0)}else if(3===i){const n=e.F();if(0===n);else{const o=x(t);if(e.A()-(n+e.J()+o)<=0)o&&v(n+o);else{const e=t.reduce(((e,[t,n])=>(t<r&&(e+=n),e)),0);e&&v(e,!0)}}}}}})(U,(e=>{q[T]&&q[T](e)}),(e=>{X(e),e||(N(new Set),G[T]&&G[T]())}))));I((()=>Y.q(W[T])),[]),I((()=>{V.length&&Y.Y(V,B)}),[V]),r((()=>{D&&D({start:B,end:H,count:P})}),[B,H]),u(J,(()=>({get scrollOffset(){return U.F()},get scrollSize(){return Y.K()},get viewportSize(){return U.J()},scrollToIndex(e){Y.X(e,P)},scrollTo:Y.N,scrollBy(e){Y.N(U.F()+e)}})),[P]);const Z=d(B-l,0),$=f(H+l,P-1),ee=s((()=>{const t=[];for(let e=Z;e<=$;e++)K.add(e);return K.forEach((r=>{const n=L[r];m(n)&&t.push(e(O,{h:Y,m:U,g:r,p:j,_:n},(null==n?void 0:n.key)||r))})),t}),[L,K,Z,$]);return e(E,{O:W,m:U,p:v,k:Q,_:ee,j:F})}));export{j as VList};
|
|
2
2
|
//# sourceMappingURL=index.mjs.map
|
package/lib/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":["../src/src/core/utils.ts","../src/src/core/cache.ts","../src/src/react/useIsomorphicLayoutEffect.ts","../src/src/react/useSyncExternalStore.ts","../src/src/react/utils.ts","../src/src/react/useStatic.ts","../src/src/react/useRefWithUpdate.ts","../src/src/react/VList.tsx","../src/src/core/store.ts","../src/src/core/scroller.ts"],"sourcesContent":["export const min = Math.min;\nexport const max = Math.max;\nexport const abs = Math.abs;\nexport const now = Date.now;\n\nexport const exists = <T>(v: T): v is Exclude<T, null | undefined> => v != null;\n\nexport const range = <T>(length: number, cb: (i: number) => T): T[] =>\n Array.from({ length }, (_, i) => cb(i));\n\nexport const debounce = <T extends (...args: any[]) => void>(\n fn: T,\n ms: number\n) => {\n let id: NodeJS.Timeout | undefined | null;\n\n const cancel = () => {\n if (exists(id)) {\n clearTimeout(id);\n }\n };\n const debouncedFn = () => {\n cancel();\n id = setTimeout(() => {\n id = null;\n fn();\n }, ms);\n };\n debouncedFn._cancel = cancel;\n return debouncedFn;\n};\n\nexport const throttle = <T extends (...args: any[]) => void>(\n fn: T,\n ms: number\n) => {\n let time = now() - ms;\n return (...args: Parameters<T>) => {\n const n = now();\n if (time + ms < n) {\n time = n;\n fn(...args);\n }\n };\n};\n","import type { DeepReadonly, Writeable } from \"./types\";\nimport { exists, max, min, range } from \"./utils\";\n\nexport const UNCACHED = -1;\n\nexport type Cache = DeepReadonly<{\n _defaultItemSize: number;\n _length: number;\n _sizes: number[];\n _measuredOffsetIndex: number;\n _offsets: number[];\n}>;\n\nexport const getItemSize = (cache: Cache, index: number): number => {\n const size = cache._sizes[index]!;\n return size === UNCACHED ? cache._defaultItemSize : size;\n};\n\nexport const setItemSize = (\n cache: Writeable<Cache>,\n index: number,\n size: number\n) => {\n cache._sizes[index] = size;\n // mark as dirty\n cache._measuredOffsetIndex = min(index, cache._measuredOffsetIndex);\n};\n\nconst computeOffset = (\n cache: Writeable<Cache>,\n index: number,\n isTotal?: boolean\n): number => {\n if (!cache._length) return 0;\n if (cache._measuredOffsetIndex >= index) {\n if (isTotal) {\n return cache._offsets[index]! + getItemSize(cache, index);\n } else {\n return cache._offsets[index]!;\n }\n }\n\n let i = cache._measuredOffsetIndex;\n let top = cache._offsets[i]!;\n while (i <= index) {\n cache._offsets[i] = top;\n if (i === index && !isTotal) {\n break;\n }\n top += getItemSize(cache, i);\n i++;\n }\n // mark as measured\n cache._measuredOffsetIndex = index;\n return top;\n};\n\nexport const computeTotalSize = (cache: Writeable<Cache>): number => {\n return computeOffset(cache, cache._length - 1, true);\n};\n\nexport const computeStartOffset = (\n cache: Writeable<Cache>,\n index: number\n): number => {\n return computeOffset(cache, index);\n};\n\nconst findIndex = (cache: Cache, i: number, distance: number): number => {\n let sum = 0;\n if (distance >= 0) {\n // search forward\n while (i < cache._length - 1) {\n const h = getItemSize(cache, i++);\n if ((sum += h) >= distance) {\n if (sum - h / 2 >= distance) {\n i--;\n }\n break;\n }\n }\n } else {\n // search backward\n while (i > 0) {\n const h = getItemSize(cache, --i);\n if ((sum -= h) <= distance) {\n if (sum + h / 2 < distance) {\n i++;\n }\n break;\n }\n }\n }\n\n return min(max(i, 0), cache._length - 1);\n};\n\nexport const findStartIndexWithOffset = (\n cache: Cache,\n offset: number,\n prevStartIndex: number,\n prevOffset: number\n): number => {\n return findIndex(cache, prevStartIndex, offset - prevOffset);\n};\n\nexport const findEndIndex = findIndex;\n\nexport const hasUnmeasuredItemsInRange = (\n cache: Cache,\n startIndex: number,\n endIndex: number\n): boolean => {\n for (let i = startIndex; i <= endIndex; i++) {\n if (cache._sizes[i] === UNCACHED) {\n return true;\n }\n }\n return false;\n};\n\nexport const resetCache = (\n length: number,\n itemSize: number,\n cache?: Cache\n): Cache => {\n return {\n _defaultItemSize: itemSize,\n _length: length,\n _measuredOffsetIndex: cache\n ? min(cache._measuredOffsetIndex, length - 1)\n : 0,\n _sizes: range(length, (i) => {\n const size = cache && cache._sizes[i];\n if (exists(size)) {\n return size;\n }\n return UNCACHED;\n }),\n _offsets: range(length, (i) => {\n if (i === 0) {\n // first offset must be 0\n return 0;\n }\n const offset = cache && cache._offsets[i];\n if (exists(offset)) {\n return offset;\n }\n return UNCACHED;\n }),\n };\n};\n","import { useEffect, useLayoutEffect } from \"react\";\n\n// https://gist.github.com/gaearon/e7d97cdf38a2907924ea12e4ebdf3c85\nexport const useIsomorphicLayoutEffect =\n typeof window !== \"undefined\" ? useLayoutEffect : useEffect;\n","import { useSyncExternalStore as _useSyncExternalStore } from \"use-sync-external-store/shim/index.js\";\n\nexport const useSyncExternalStore = <T>(\n subscibe: (onStoreChange: () => void) => () => void,\n getSnapShot: () => T\n): T => {\n return _useSyncExternalStore(subscibe, getSnapShot, getSnapShot);\n};\n","export const refKey = \"current\";\n","import { useRef } from \"react\";\nimport { refKey } from \"./utils\";\n\nexport const useStatic = <T>(init: () => T): T => {\n const ref = useRef<T>();\n return ref[refKey] || (ref[refKey] = init());\n};\n","import { useRef } from \"react\";\nimport { useIsomorphicLayoutEffect } from \"./useIsomorphicLayoutEffect\";\nimport { refKey } from \"./utils\";\n\nexport const useRefWithUpdate = <T>(value: T) => {\n const ref = useRef<T>(value);\n\n useIsomorphicLayoutEffect(() => {\n ref[refKey] = value;\n }, [value]);\n\n return ref;\n};\n","import {\n Children,\n memo,\n useRef,\n useMemo,\n CSSProperties,\n ReactElement,\n forwardRef,\n useImperativeHandle,\n ReactNode,\n useEffect,\n RefObject,\n useState,\n ReactFragment,\n} from \"react\";\nimport {\n ACTION_UPDATE_CACHE_LENGTH,\n VirtualStore,\n createVirtualStore,\n} from \"../core/store\";\nimport { useIsomorphicLayoutEffect } from \"./useIsomorphicLayoutEffect\";\nimport { useSyncExternalStore } from \"./useSyncExternalStore\";\nimport { exists, max, min } from \"../core/utils\";\nimport { createScroller, Scroller } from \"../core/scroller\";\nimport { refKey } from \"./utils\";\nimport { useStatic } from \"./useStatic\";\nimport { useRefWithUpdate } from \"./useRefWithUpdate\";\n\ntype ItemProps = {\n _children: ReactNode;\n _scroller: Scroller;\n _store: VirtualStore;\n _index: number;\n _element: \"div\";\n};\n\nconst Item = memo(\n ({\n _children: children,\n _scroller: scroller,\n _store: store,\n _index: index,\n _element: Element,\n }: ItemProps): ReactElement => {\n const ref = useRef<HTMLDivElement>(null);\n\n const offset = useSyncExternalStore(store._subscribe, () =>\n store._getItemOffset(index)\n );\n const hide = useSyncExternalStore(store._subscribe, () =>\n store._isUnmeasuredItem(index)\n );\n\n // The index may be changed if elements are inserted to or removed from the start of props.children\n useIsomorphicLayoutEffect(\n () => scroller._initItem(ref[refKey]!, index),\n [index]\n );\n\n return (\n <Element\n ref={ref}\n style={useMemo((): CSSProperties => {\n const isHorizontal = store._isHorizontal();\n const leftOrRightKey = store._isRtl() ? \"right\" : \"left\";\n const style: CSSProperties = {\n margin: 0,\n padding: 0,\n position: \"absolute\",\n [isHorizontal ? \"height\" : \"width\"]: \"100%\",\n [isHorizontal ? \"top\" : leftOrRightKey]: 0,\n [isHorizontal ? leftOrRightKey : \"top\"]: offset,\n visibility: hide ? \"hidden\" : \"visible\",\n // willChange: \"transform\",\n };\n if (isHorizontal) {\n style.display = \"flex\";\n }\n return style;\n }, [offset, hide])}\n >\n {children}\n </Element>\n );\n }\n);\n\nconst isInvalidElement = <T extends ReactNode>(\n e: T\n): e is Extract<T, null | undefined | boolean> =>\n !exists(e) || typeof e === \"boolean\";\n\nexport type WindowComponentAttributes = Pick<\n React.HTMLAttributes<HTMLElement>,\n \"className\" | \"style\" | \"id\" | \"role\" | \"tabIndex\"\n> &\n React.AriaAttributes;\n\n/**\n * Props of customized scrollable component.\n */\nexport interface CustomWindowComponentProps {\n children: ReactNode;\n scrollSize: number;\n scrolling: boolean;\n horizontal: boolean;\n attrs: WindowComponentAttributes;\n}\n\nconst DefaultWindow = forwardRef<any, CustomWindowComponentProps>(\n (\n { children, scrollSize, scrolling, horizontal, attrs },\n ref\n ): ReactElement => {\n return (\n <div ref={ref} {...attrs}>\n <div\n style={useMemo((): CSSProperties => {\n return {\n position: \"relative\",\n visibility: \"hidden\",\n width: horizontal ? scrollSize : \"100%\",\n height: horizontal ? \"100%\" : scrollSize,\n pointerEvents: scrolling ? \"none\" : \"auto\",\n };\n }, [scrollSize, scrolling])}\n >\n {children}\n </div>\n </div>\n );\n }\n);\n\nexport type CustomWindowComponent = typeof DefaultWindow;\n\nconst Window = ({\n _children: children,\n _ref: ref,\n _store: store,\n _element: Element,\n _scrolling: scrolling,\n _attrs: attrs,\n}: {\n _children: ReactNode;\n _ref: RefObject<HTMLDivElement>;\n _store: VirtualStore;\n _element: CustomWindowComponent;\n _scrolling: boolean;\n _attrs: WindowComponentAttributes;\n}) => {\n const scrollSize = useSyncExternalStore(\n store._subscribe,\n store._getScrollSize\n );\n\n const horizontal = store._isHorizontal();\n\n return (\n <Element\n ref={ref}\n scrollSize={scrollSize}\n scrolling={scrolling}\n horizontal={horizontal}\n attrs={useMemo(\n () => ({\n ...attrs,\n style: {\n overflow: horizontal ? \"auto hidden\" : \"hidden auto\",\n contain: \"strict\",\n // transform: \"translate3d(0px, 0px, 0px)\",\n // willChange: \"scroll-position\",\n // backfaceVisibility: \"hidden\",\n width: \"100%\",\n height: \"100%\",\n padding: 0,\n margin: 0,\n ...attrs.style,\n },\n }),\n [attrs]\n )}\n >\n {children}\n </Element>\n );\n};\n\n/**\n * Props of customized item component.\n */\nexport interface CustomItemComponentProps {\n style: CSSProperties;\n children: ReactNode;\n}\n\nexport type CustomItemComponent = React.ForwardRefExoticComponent<\n React.PropsWithoutRef<CustomItemComponentProps> & React.RefAttributes<any>\n>;\n\ntype CustomItemComponentOrElement =\n | keyof JSX.IntrinsicElements\n | CustomItemComponent;\n\n/**\n * Methods of {@link VList}.\n */\nexport interface VListHandle {\n /**\n * Get current scrollTop or scrollLeft.\n */\n readonly scrollOffset: number;\n /**\n * Get current scrollHeight or scrollWidth.\n */\n readonly scrollSize: number;\n /**\n * Get current offsetHeight or offsetWidth.\n */\n readonly viewportSize: number;\n /**\n * Scroll to the item specified by index.\n * @param index index of item\n */\n scrollToIndex(index: number): void;\n /**\n * Scroll to the given offset.\n * @param offset offset from start\n */\n scrollTo(offset: number): void;\n /**\n * Scroll by the given offset.\n * @param offset offset from current position\n */\n scrollBy(offset: number): void;\n}\n\n/**\n * Props of {@link VList}.\n */\nexport interface VListProps extends WindowComponentAttributes {\n /**\n * Elements rendered by this component.\n */\n children: ReactNode;\n /**\n * Item size hint for unmeasured items. It's recommended to specify this prop if item sizes are fixed and known, or much larger than the defaultValue. It will help to reduce scroll jump when items are measured.\n * @defaultValue 40\n */\n itemSize?: number;\n /**\n * Number of items to render above/below the visible bounds of the list. You can increase to avoid showing blank items in fast scrolling.\n * @defaultValue 4\n */\n overscan?: number;\n /**\n * If true, rendered as a horizontally scrollable list. Otherwise rendered as a vertically scrollable list.\n */\n horizontal?: boolean;\n /**\n * You have to set true if you use this component under `direction: rtl` style.\n */\n rtl?: boolean;\n /**\n * Customized element type for scrollable element. This element will get {@link CustomWindowComponentProps} as props.\n * @defaultValue {@link DefaultWindow}\n */\n element?: CustomWindowComponent;\n /**\n * Customized element type for item element. This element will get {@link CustomItemComponentProps} as props.\n * @defaultValue \"div\"\n */\n itemElement?: CustomItemComponentOrElement;\n /**\n * Callback invoked whenever scroll offset changes.\n * @param offset Current scrollTop or scrollLeft.\n */\n onScroll?: (offset: number) => void;\n /**\n * Callback invoked when scrolling stops.\n */\n onScrollStop?: () => void;\n /**\n * Callback invoked when visible items range changes.\n * @param payload `start` is the start index of viewable items. `end` is the end index of viewable items. `count` is the total count of items.\n */\n onRangeChange?: (payload: {\n start: number;\n end: number;\n count: number;\n }) => void;\n}\n\n/**\n * Virtualized list component. See {@link VListProps} and {@link VListHandle}.\n */\nexport const VList = forwardRef<VListHandle, VListProps>(\n (\n {\n children,\n itemSize: itemSizeProp = 40,\n overscan = 4,\n horizontal: horizontalProp,\n rtl: rtlProp,\n element = DefaultWindow,\n itemElement = \"div\",\n onScroll: onScrollProp,\n onScrollStop: onScrollStopProp,\n onRangeChange: onRangeChangeProp,\n ...windowAttrs\n },\n ref\n ): ReactElement => {\n // Memoize element array\n const elements = useMemo(() => {\n const arr: (ReactElement | ReactFragment | string | number)[] = [];\n Children.forEach(children, (e) => {\n if (isInvalidElement(e)) {\n return;\n }\n arr.push(e);\n });\n return arr;\n }, [children]);\n const elementsCount = elements.length;\n\n // https://github.com/facebook/react/issues/25191#issuecomment-1237456448\n const store = useStatic(() =>\n createVirtualStore(\n elementsCount,\n itemSizeProp,\n !!horizontalProp,\n !!rtlProp\n )\n );\n const [startIndex, endIndex] = useSyncExternalStore(\n store._subscribe,\n store._getRange\n );\n const jump = useSyncExternalStore(store._subscribe, store._getJump);\n const rootRef = useRef<HTMLDivElement>(null);\n\n const onScroll = useRefWithUpdate(onScrollProp);\n const onScrollStop = useRefWithUpdate(onScrollStopProp);\n\n const [mountedIndexes, reset] = useState<Set<number>>(new Set<number>());\n const [scrolling, setScrolling] = useState(false);\n const scroller = useStatic(() =>\n createScroller(\n store,\n (offset) => {\n onScroll[refKey] && onScroll[refKey](offset);\n },\n (isScrolling) => {\n setScrolling(isScrolling);\n if (!isScrolling) {\n reset(new Set());\n onScrollStop[refKey] && onScrollStop[refKey]();\n }\n }\n )\n );\n\n // The elements length and cached items length are different just after element is added/removed.\n const count = min(elementsCount, store._getItemCount());\n\n // So update cache length. Updating state in render will cause warn so use useEffect for now.\n useIsomorphicLayoutEffect(() => {\n store._update(ACTION_UPDATE_CACHE_LENGTH, elementsCount);\n }, [elementsCount]);\n\n useIsomorphicLayoutEffect(() => scroller._initRoot(rootRef[refKey]!), []);\n\n useIsomorphicLayoutEffect(() => {\n if (!jump.length) return;\n\n scroller._fixScrollJump(jump, startIndex);\n }, [jump]);\n\n useEffect(() => {\n if (!onRangeChangeProp) return;\n\n onRangeChangeProp({\n start: startIndex,\n end: endIndex,\n count,\n });\n }, [startIndex, endIndex]);\n\n useImperativeHandle(\n ref,\n () => {\n return {\n get scrollOffset() {\n return store._getScrollOffset();\n },\n get scrollSize() {\n return scroller._getActualScrollSize();\n },\n get viewportSize() {\n return store._getViewportSize();\n },\n scrollToIndex(index) {\n scroller._scrollToIndex(index, count);\n },\n scrollTo: scroller._scrollTo,\n scrollBy(offset) {\n scroller._scrollTo(store._getScrollOffset() + offset);\n },\n };\n },\n [count]\n );\n\n const startIndexWithMargin = max(startIndex - overscan, 0);\n const endIndexWithMargin = min(endIndex + overscan, count - 1);\n const items = useMemo(() => {\n const res: ReactElement[] = [];\n for (let i = startIndexWithMargin; i <= endIndexWithMargin; i++) {\n // https://github.com/sergi/virtual-list/commit/8e7e06dc63568334c1ab809ea83c1be36572e9ed\n mountedIndexes.add(i);\n }\n mountedIndexes.forEach((i) => {\n const e = elements[i];\n // This can be undefined when items are removed\n if (exists(e)) {\n res.push(\n <Item\n key={(e as { key?: ReactElement[\"key\"] })?.key || i}\n _scroller={scroller}\n _store={store}\n _index={i}\n _element={itemElement as \"div\"}\n _children={e}\n />\n );\n }\n });\n return res;\n }, [elements, mountedIndexes, startIndexWithMargin, endIndexWithMargin]);\n\n return (\n <Window\n _ref={rootRef}\n _store={store}\n _element={element}\n _scrolling={scrolling}\n _children={items}\n _attrs={windowAttrs}\n />\n );\n }\n);\n","import {\n findStartIndexWithOffset,\n resetCache,\n getItemSize,\n computeTotalSize,\n findEndIndex,\n computeStartOffset,\n Cache,\n UNCACHED,\n setItemSize,\n hasUnmeasuredItemsInRange,\n} from \"./cache\";\nimport type { Writeable } from \"./types\";\n\nexport type ScrollJump = Readonly<[index: number, sizeDiff: number][]>;\nexport type ItemResize = [index: number, size: number];\ntype ItemsRange = [startIndex: number, endIndex: number];\n\nexport const ACTION_UPDATE_CACHE_LENGTH = 0;\nexport const ACTION_UPDATE_ITEM_SIZES = 1;\nexport const ACTION_UPDATE_VIEWPORT = 2;\nexport const ACTION_HANDLE_SCROLL = 3;\n\ntype Actions =\n | [type: typeof ACTION_UPDATE_CACHE_LENGTH, length: number]\n | [type: typeof ACTION_UPDATE_ITEM_SIZES, entries: ItemResize[]]\n | [\n type: typeof ACTION_UPDATE_VIEWPORT,\n rect: { _width: number; _height: number }\n ]\n | [type: typeof ACTION_HANDLE_SCROLL, offset: number];\n\nexport type VirtualStore = {\n _getRange(): ItemsRange;\n _isUnmeasuredItem(index: number): boolean;\n _hasUnmeasuredItemsInRange(startIndex: number): boolean;\n _getItemOffset(index: number): number;\n _getScrollOffset(): number;\n _getViewportSize(): number;\n _getScrollSize(): number;\n _getItemCount(): number;\n _getJump(): ScrollJump;\n _isHorizontal(): boolean;\n _isRtl(): boolean;\n _getItemIndexForScrollTo(offset: number): number;\n _waitForScrollDestinationItemsMeasured(): Promise<void>;\n _subscribe(cb: () => void): () => void;\n _update(...action: Actions): void;\n};\n\nexport const createVirtualStore = (\n itemCount: number,\n itemSize: number,\n isHorizontal: boolean,\n isRtl: boolean\n): VirtualStore => {\n let viewportWidth = 0;\n let viewportHeight = 0;\n let scrollOffset = 0;\n let jump: ScrollJump = [];\n let cache = resetCache(itemCount, itemSize);\n let _prevRange: ItemsRange = [0, 0];\n let _scrollToQueue: [() => void, () => void] | undefined;\n\n const subscribers = new Set<() => void>();\n const getViewportSize = (): number =>\n isHorizontal ? viewportWidth : viewportHeight;\n\n return {\n _getRange() {\n const [prevStartIndex, prevEndIndex] = _prevRange;\n const prevOffset = computeStartOffset(\n cache as Writeable<Cache>,\n prevStartIndex\n );\n const start = findStartIndexWithOffset(\n cache,\n scrollOffset,\n prevStartIndex,\n prevOffset\n );\n const end = findEndIndex(cache, start, getViewportSize());\n if (prevStartIndex === start && prevEndIndex === end) {\n return _prevRange;\n }\n return (_prevRange = [start, end]);\n },\n _isUnmeasuredItem(index) {\n return cache._sizes[index] === UNCACHED;\n },\n _hasUnmeasuredItemsInRange(startIndex) {\n return hasUnmeasuredItemsInRange(\n cache,\n startIndex,\n findEndIndex(cache, startIndex, getViewportSize())\n );\n },\n _getItemOffset(index) {\n return computeStartOffset(cache as Writeable<Cache>, index);\n },\n _getScrollOffset() {\n return scrollOffset;\n },\n _getViewportSize() {\n return getViewportSize();\n },\n _getScrollSize() {\n return computeTotalSize(cache as Writeable<Cache>);\n },\n _getItemCount() {\n return cache._length;\n },\n _getJump() {\n return jump;\n },\n _isHorizontal() {\n return isHorizontal;\n },\n _isRtl() {\n return isRtl;\n },\n _getItemIndexForScrollTo(offset) {\n return findStartIndexWithOffset(cache, offset, 0, 0);\n },\n _waitForScrollDestinationItemsMeasured() {\n if (_scrollToQueue) {\n // Cancel waiting scrollTo\n _scrollToQueue[1]();\n }\n // The measurement will be done asynchronously and the timing is not predictable so we use promise.\n // For example, ResizeObserver may not fire when window is not visible.\n return new Promise((resolve, reject) => {\n _scrollToQueue = [\n () => {\n // HACK: It should be resolved in the next microtask that is after React's render\n Promise.resolve().then(() => {\n resolve();\n _scrollToQueue = undefined;\n });\n },\n reject,\n ];\n });\n },\n _subscribe(cb) {\n subscribers.add(cb);\n return () => {\n subscribers.delete(cb);\n };\n },\n _update(type, payload) {\n const mutated = ((): boolean => {\n switch (type) {\n case ACTION_UPDATE_CACHE_LENGTH: {\n if (cache._length === payload) return false;\n cache = resetCache(payload, itemSize, cache);\n return true;\n }\n case ACTION_UPDATE_ITEM_SIZES: {\n const updated = payload.filter(\n ([index, size]) => cache._sizes[index] !== size\n );\n // Skip if all items are cached and not updated\n if (!updated.length) {\n return false;\n }\n\n const updatedJump: [index: number, sizeDiff: number][] = [];\n updated.forEach(([index, size]) => {\n updatedJump.push([index, size - getItemSize(cache, index)]);\n setItemSize(cache as Writeable<Cache>, index, size);\n });\n jump = updatedJump;\n return true;\n }\n case ACTION_UPDATE_VIEWPORT: {\n if (\n viewportWidth === payload._width &&\n viewportHeight === payload._height\n ) {\n return false;\n }\n viewportWidth = payload._width;\n viewportHeight = payload._height;\n return true;\n }\n case ACTION_HANDLE_SCROLL: {\n const prevOffset = scrollOffset;\n return (scrollOffset = payload) !== prevOffset;\n }\n }\n })();\n\n if (mutated) {\n subscribers.forEach((cb) => {\n cb();\n });\n if (_scrollToQueue && type === ACTION_UPDATE_ITEM_SIZES) {\n _scrollToQueue[0]();\n }\n }\n },\n };\n};\n","import {\n ACTION_HANDLE_SCROLL,\n ACTION_UPDATE_ITEM_SIZES,\n ACTION_UPDATE_VIEWPORT,\n ItemResize,\n ScrollJump,\n VirtualStore,\n} from \"./store\";\nimport { abs, debounce, throttle, exists, max, min } from \"./utils\";\n\nexport const SCROLL_STOP = 0;\nexport const SCROLL_DOWN = 1;\nexport const SCROLL_UP = 2;\nexport const SCROLL_MANUAL = 3;\ntype ScrollDirection =\n | typeof SCROLL_STOP\n | typeof SCROLL_DOWN\n | typeof SCROLL_UP\n | typeof SCROLL_MANUAL;\n\nexport type Scroller = {\n _initRoot: (rootElement: HTMLElement) => () => void;\n _initItem: (itemElement: HTMLElement, index: number) => () => void;\n _getActualScrollSize: () => number;\n _scrollTo: (offset: number) => void;\n _scrollToIndex: (index: number, count: number) => void;\n _fixScrollJump: (jump: ScrollJump, startIndex: number) => void;\n};\n\nexport const createScroller = (\n store: VirtualStore,\n emitScrollOffsetChange: (offset: number) => void,\n emitScrollStateChange: (scrolling: boolean) => void\n): Scroller => {\n let prevOffset = -1;\n let scrollDirection: ScrollDirection = SCROLL_STOP;\n let resized = false;\n let isNegativeOffset: boolean | undefined;\n let rootElement: HTMLElement | undefined;\n let _ro: ResizeObserver | undefined;\n const isHorizontal = store._isHorizontal();\n const isRtl = store._isRtl();\n const scrollToKey = isHorizontal ? \"scrollLeft\" : \"scrollTop\";\n const mountedIndexes = new WeakMap<Element, number>();\n const getResizeObserver = (): ResizeObserver => {\n // Initialize ResizeObserver lazily for SSR\n return (\n _ro ||\n (_ro = new ResizeObserver((entries) => {\n // https://www.w3.org/TR/resize-observer/#intro\n const resizes: ItemResize[] = [];\n for (const entry of entries) {\n if (entry.target === rootElement) {\n store._update(ACTION_UPDATE_VIEWPORT, {\n _width: entry.contentRect.width,\n _height: entry.contentRect.height,\n });\n } else {\n const index = mountedIndexes.get(entry.target);\n if (exists(index)) {\n resizes.push([\n index,\n entry.contentRect[isHorizontal ? \"width\" : \"height\"],\n ]);\n }\n }\n }\n\n if (resizes.length) {\n store._update(ACTION_UPDATE_ITEM_SIZES, resizes);\n resized = true;\n }\n }))\n );\n };\n const getActualScrollSize = (): number => {\n if (!rootElement) return 0;\n // Use element's scrollHeight/scrollWidth instead of stored scrollSize.\n // This is because stored size may differ from the actual size, for example when a new item is added and not yet measured.\n return store._isHorizontal()\n ? rootElement.scrollWidth\n : rootElement.scrollHeight;\n };\n const updateScrollPosition = (offset: number, diff?: boolean) => {\n if (!rootElement) return;\n if (isRtl) {\n if (!exists(isNegativeOffset)) {\n // Assume offset type in rtl direction.\n // The scroll position is negative in spec however its not in some browsers, for example Chrome earlier than v85.\n // https://github.com/othree/jquery.rtl-scroll-type\n const prev = rootElement[scrollToKey];\n rootElement[scrollToKey] = 1;\n isNegativeOffset = rootElement[scrollToKey] === 0;\n rootElement[scrollToKey] = prev;\n }\n if (isNegativeOffset) {\n offset *= -1;\n }\n }\n if (diff) {\n rootElement[scrollToKey] += offset;\n } else {\n rootElement[scrollToKey] = offset;\n scrollDirection = SCROLL_MANUAL;\n }\n };\n const scrollTo = async (index: number, getCurrentOffset: () => number) => {\n const getOffset = (): number => {\n let offset = getCurrentOffset();\n const scrollSize = getActualScrollSize();\n const viewportSize = store._getViewportSize();\n if (scrollSize - (offset + viewportSize) <= 0) {\n // Adjust if the offset is over the end, to get correct startIndex.\n offset = scrollSize - viewportSize;\n }\n return offset;\n };\n\n if (store._hasUnmeasuredItemsInRange(index)) {\n do {\n // In order to scroll to the correct position, mount the items and measure their sizes before scrolling.\n store._update(ACTION_HANDLE_SCROLL, getOffset());\n try {\n // Wait for the scroll destination items to be measured.\n await store._waitForScrollDestinationItemsMeasured();\n } catch (e) {\n // canceled\n return;\n }\n } while (store._hasUnmeasuredItemsInRange(index));\n\n // Scroll with the updated value\n updateScrollPosition(getOffset());\n } else {\n const offset = getOffset();\n updateScrollPosition(offset);\n // Sync viewport to scroll destination\n store._update(ACTION_HANDLE_SCROLL, offset);\n }\n };\n\n const calcTotalJump = (jump: ScrollJump): number =>\n jump.reduce((acc, [, j]) => acc + j, 0);\n\n return {\n _initRoot(root) {\n rootElement = root;\n const ro = getResizeObserver();\n\n const syncViewportToScrollPosition = () => {\n let offset = root[scrollToKey];\n if (isRtl) {\n // The scroll position may be negative value in rtl direction.\n // https://github.com/othree/jquery.rtl-scroll-type\n offset = abs(offset);\n }\n if (prevOffset === offset) {\n return;\n }\n // Skip scroll direction detection just after resizing because it may result in the opposite direction.\n // Scroll events are dispatched enough so it's ok to skip some of them.\n if (scrollDirection === SCROLL_STOP || !resized) {\n // Ignore until manual scrolling\n if (scrollDirection !== SCROLL_MANUAL) {\n scrollDirection = prevOffset > offset ? SCROLL_UP : SCROLL_DOWN;\n }\n } else {\n resized = false;\n }\n store._update(ACTION_HANDLE_SCROLL, (prevOffset = offset));\n emitScrollOffsetChange(offset);\n };\n\n const onScrollStopped = debounce(() => {\n // Check scroll position once just after scrolling stopped\n syncViewportToScrollPosition();\n scrollDirection = SCROLL_STOP;\n emitScrollStateChange(false);\n }, 150);\n\n const onScroll = () => {\n const isScrollStart = scrollDirection === SCROLL_STOP;\n syncViewportToScrollPosition();\n if (isScrollStart) {\n emitScrollStateChange(true);\n }\n onScrollStopped();\n };\n\n // Infer scroll state also from wheel events\n // Sometimes scroll events do not fire when frame dropped even if the visual have been already scrolled\n const onWheel = throttle((e: WheelEvent) => {\n if (scrollDirection === SCROLL_STOP) {\n // Scroll start should be detected with scroll event\n return;\n }\n if (e.ctrlKey) {\n // Probably a pinch-to-zoom gesture\n return;\n }\n // Get delta before checking deltaMode for firefox behavior\n // https://github.com/w3c/uievents/issues/181#issuecomment-392648065\n // https://bugzilla.mozilla.org/show_bug.cgi?id=1392460#c34\n if (isHorizontal ? e.deltaX : e.deltaY) {\n if (\n prevOffset > 0 &&\n prevOffset < store._getScrollSize() - store._getViewportSize()\n ) {\n onScrollStopped();\n }\n }\n }, 50);\n\n ro.observe(root);\n root.addEventListener(\"scroll\", onScroll);\n root.addEventListener(\"wheel\", onWheel, { passive: true });\n\n return () => {\n ro.disconnect();\n root.removeEventListener(\"scroll\", onScroll);\n root.removeEventListener(\"wheel\", onWheel);\n onScrollStopped._cancel();\n };\n },\n _initItem(el, i) {\n const ro = getResizeObserver();\n mountedIndexes.set(el, i);\n ro.observe(el);\n return () => {\n mountedIndexes.delete(el);\n ro.unobserve(el);\n };\n },\n _getActualScrollSize: getActualScrollSize,\n _scrollTo(offset) {\n offset = max(offset, 0);\n\n scrollTo(store._getItemIndexForScrollTo(offset), () => offset);\n },\n _scrollToIndex(index, count) {\n index = max(min(index, count - 1), 0);\n\n scrollTo(index, () => store._getItemOffset(index));\n },\n _fixScrollJump: (jump, startIndex) => {\n // Compensate scroll jump\n if (scrollDirection === SCROLL_UP) {\n const diff = calcTotalJump(jump);\n if (diff) {\n updateScrollPosition(diff, true);\n }\n } else if (scrollDirection === SCROLL_MANUAL) {\n const offset = store._getScrollOffset();\n if (offset === 0) {\n // Do nothing to stick to the start\n } else {\n const allDiff = calcTotalJump(jump);\n if (\n store._getScrollSize() -\n (offset + store._getViewportSize() + allDiff) <=\n 0\n ) {\n // Keep end to stick to the end\n if (allDiff) {\n updateScrollPosition(offset + allDiff);\n }\n } else {\n // Keep start at mid\n const diff = jump.reduce((acc, [index, j]) => {\n if (index < startIndex) {\n acc += j;\n }\n return acc;\n }, 0);\n if (diff) {\n updateScrollPosition(diff, true);\n }\n }\n }\n } else {\n // NOP\n }\n },\n };\n};\n"],"names":["min","Math","max","abs","now","Date","exists","v","range","length","cb","Array","from","_","i","getItemSize","cache","index","size","_sizes","_defaultItemSize","computeOffset","isTotal","_length","_measuredOffsetIndex","_offsets","top","computeStartOffset","findIndex","distance","sum","h","findStartIndexWithOffset","offset","prevStartIndex","prevOffset","findEndIndex","resetCache","itemSize","useIsomorphicLayoutEffect","window","useLayoutEffect","useEffect","useSyncExternalStore","subscibe","getSnapShot","_useSyncExternalStore","refKey","useStatic","init","ref","useRef","useRefWithUpdate","value","Item","memo","_children","children","_scroller","scroller","_store","store","_index","_element","Element","_subscribe","_getItemOffset","hide","_isUnmeasuredItem","_initItem","_jsx","style","useMemo","isHorizontal","_isHorizontal","leftOrRightKey","_isRtl","margin","padding","position","visibility","display","DefaultWindow","forwardRef","scrollSize","scrolling","horizontal","attrs","width","height","pointerEvents","Window","_ref","_scrolling","_attrs","_getScrollSize","overflow","contain","VList","itemSizeProp","overscan","horizontalProp","rtl","rtlProp","element","itemElement","onScroll","onScrollProp","onScrollStop","onScrollStopProp","onRangeChange","onRangeChangeProp","windowAttrs","elements","arr","Children","forEach","e","isInvalidElement","push","elementsCount","createVirtualStore","itemCount","isRtl","_scrollToQueue","viewportWidth","viewportHeight","scrollOffset","jump","_prevRange","subscribers","Set","getViewportSize","_getRange","prevEndIndex","start","end","_hasUnmeasuredItemsInRange","startIndex","hasUnmeasuredItemsInRange","endIndex","_getScrollOffset","_getViewportSize","computeTotalSize","_getItemCount","_getJump","_getItemIndexForScrollTo","_waitForScrollDestinationItemsMeasured","Promise","resolve","reject","then","undefined","add","delete","_update","type","payload","updated","filter","updatedJump","setItemSize","_width","_height","rootRef","mountedIndexes","reset","useState","setScrolling","createScroller","emitScrollOffsetChange","emitScrollStateChange","isNegativeOffset","rootElement","_ro","scrollDirection","resized","scrollToKey","WeakMap","getResizeObserver","ResizeObserver","entries","resizes","entry","target","contentRect","get","getActualScrollSize","scrollWidth","scrollHeight","updateScrollPosition","diff","prev","scrollTo","async","getCurrentOffset","getOffset","viewportSize","calcTotalJump","reduce","acc","j","_initRoot","root","ro","syncViewportToScrollPosition","onScrollStopped","debounce","id","cancel","clearTimeout","debouncedFn","setTimeout","_cancel","isScrollStart","onWheel","throttle","time","args","n","ctrlKey","deltaX","deltaY","fn","observe","addEventListener","passive","disconnect","removeEventListener","el","set","unobserve","_getActualScrollSize","_scrollTo","_scrollToIndex","count","_fixScrollJump","allDiff","isScrolling","useImperativeHandle","scrollToIndex","scrollBy","startIndexWithMargin","endIndexWithMargin","items","res","key"],"mappings":"oRAAO,MAAMA,EAAMC,KAAKD,IACXE,EAAMD,KAAKC,IAC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AI3I,GAkBrB,OAhBAuJ,EAAejD,SAAStG,IACtB,MAAMuG,EAAIJ,EAASnG,GAEfR,EAAO+G,IACTgI,EAAI9H,KACFjD,EAAChB,GAECI,EAAWC,EACXC,EAAQC,EACRC,EAAQhD,EACRiD,EAAU0C,EACVjD,EAAW6D,IALLA,aAAC,EAADA,EAAqCiI,MAAOxO,GAQvD,IAEIuO,CAAG,GACT,CAACpI,EAAUoD,EAAgB6E,EAAsBC,KAEpD,OACE7K,EAACqB,EAAM,CACLC,EAAMwE,EACNxG,EAAQC,EACRE,EAAUyC,EACVX,EAAYR,EACZ7B,EAAW4L,GACXtJ,EAAQkB,GACR"}
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../src/src/core/utils.ts","../src/src/core/cache.ts","../src/src/react/useIsomorphicLayoutEffect.ts","../src/src/react/useSyncExternalStore.ts","../src/src/react/utils.ts","../src/src/react/useStatic.ts","../src/src/react/useRefWithUpdate.ts","../src/src/react/VList.tsx","../src/src/core/store.ts","../src/src/core/scroller.ts"],"sourcesContent":["export const min = Math.min;\nexport const max = Math.max;\nexport const abs = Math.abs;\nexport const now = Date.now;\n\nexport const exists = <T>(v: T): v is Exclude<T, null | undefined> => v != null;\n\nexport const range = <T>(length: number, cb: (i: number) => T): T[] =>\n Array.from({ length }, (_, i) => cb(i));\n\nexport const debounce = <T extends (...args: any[]) => void>(\n fn: T,\n ms: number\n) => {\n let id: NodeJS.Timeout | undefined | null;\n\n const cancel = () => {\n if (exists(id)) {\n clearTimeout(id);\n }\n };\n const debouncedFn = () => {\n cancel();\n id = setTimeout(() => {\n id = null;\n fn();\n }, ms);\n };\n debouncedFn._cancel = cancel;\n return debouncedFn;\n};\n\nexport const throttle = <T extends (...args: any[]) => void>(\n fn: T,\n ms: number\n) => {\n let time = now() - ms;\n return (...args: Parameters<T>) => {\n const n = now();\n if (time + ms < n) {\n time = n;\n fn(...args);\n }\n };\n};\n","import type { DeepReadonly, Writeable } from \"./types\";\nimport { exists, max, min, range } from \"./utils\";\n\nexport const UNCACHED = -1;\n\nexport type Cache = DeepReadonly<{\n _defaultItemSize: number;\n _length: number;\n _sizes: number[];\n _measuredOffsetIndex: number;\n _offsets: number[];\n}>;\n\nexport const getItemSize = (cache: Cache, index: number): number => {\n const size = cache._sizes[index]!;\n return size === UNCACHED ? cache._defaultItemSize : size;\n};\n\nexport const setItemSize = (\n cache: Writeable<Cache>,\n index: number,\n size: number\n) => {\n cache._sizes[index] = size;\n // mark as dirty\n cache._measuredOffsetIndex = min(index, cache._measuredOffsetIndex);\n};\n\nconst computeOffset = (\n cache: Writeable<Cache>,\n index: number,\n isTotal?: boolean\n): number => {\n if (!cache._length) return 0;\n if (cache._measuredOffsetIndex >= index) {\n if (isTotal) {\n return cache._offsets[index]! + getItemSize(cache, index);\n } else {\n return cache._offsets[index]!;\n }\n }\n\n let i = cache._measuredOffsetIndex;\n let top = cache._offsets[i]!;\n while (i <= index) {\n cache._offsets[i] = top;\n if (i === index && !isTotal) {\n break;\n }\n top += getItemSize(cache, i);\n i++;\n }\n // mark as measured\n cache._measuredOffsetIndex = index;\n return top;\n};\n\nexport const computeTotalSize = (cache: Writeable<Cache>): number => {\n return computeOffset(cache, cache._length - 1, true);\n};\n\nexport const computeStartOffset = (\n cache: Writeable<Cache>,\n index: number\n): number => {\n return computeOffset(cache, index);\n};\n\nconst findIndex = (cache: Cache, i: number, distance: number): number => {\n let sum = 0;\n if (distance >= 0) {\n // search forward\n while (i < cache._length - 1) {\n const h = getItemSize(cache, i++);\n if ((sum += h) >= distance) {\n if (sum - h / 2 >= distance) {\n i--;\n }\n break;\n }\n }\n } else {\n // search backward\n while (i > 0) {\n const h = getItemSize(cache, --i);\n if ((sum -= h) <= distance) {\n if (sum + h / 2 < distance) {\n i++;\n }\n break;\n }\n }\n }\n\n return min(max(i, 0), cache._length - 1);\n};\n\nexport const findStartIndexWithOffset = (\n cache: Cache,\n offset: number,\n prevStartIndex: number,\n prevOffset: number\n): number => {\n return findIndex(cache, prevStartIndex, offset - prevOffset);\n};\n\nexport const findEndIndex = findIndex;\n\nexport const hasUnmeasuredItemsInRange = (\n cache: Cache,\n startIndex: number,\n endIndex: number\n): boolean => {\n for (let i = startIndex; i <= endIndex; i++) {\n if (cache._sizes[i] === UNCACHED) {\n return true;\n }\n }\n return false;\n};\n\nexport const resetCache = (\n length: number,\n itemSize: number,\n cache?: Cache\n): Cache => {\n return {\n _defaultItemSize: itemSize,\n _length: length,\n _measuredOffsetIndex: cache\n ? min(cache._measuredOffsetIndex, length - 1)\n : 0,\n _sizes: range(length, (i) => {\n const size = cache && cache._sizes[i];\n if (exists(size)) {\n return size;\n }\n return UNCACHED;\n }),\n _offsets: range(length, (i) => {\n if (i === 0) {\n // first offset must be 0\n return 0;\n }\n const offset = cache && cache._offsets[i];\n if (exists(offset)) {\n return offset;\n }\n return UNCACHED;\n }),\n };\n};\n","import { useEffect, useLayoutEffect } from \"react\";\n\n// https://gist.github.com/gaearon/e7d97cdf38a2907924ea12e4ebdf3c85\nexport const useIsomorphicLayoutEffect =\n typeof window !== \"undefined\" ? useLayoutEffect : useEffect;\n","import { useSyncExternalStore as _useSyncExternalStore } from \"use-sync-external-store/shim/index.js\";\n\nexport const useSyncExternalStore = <T>(\n subscibe: (onStoreChange: () => void) => () => void,\n getSnapShot: () => T\n): T => {\n return _useSyncExternalStore(subscibe, getSnapShot, getSnapShot);\n};\n","export const refKey = \"current\";\n","import { useRef } from \"react\";\nimport { refKey } from \"./utils\";\n\nexport const useStatic = <T>(init: () => T): T => {\n const ref = useRef<T>();\n return ref[refKey] || (ref[refKey] = init());\n};\n","import { useRef } from \"react\";\nimport { useIsomorphicLayoutEffect } from \"./useIsomorphicLayoutEffect\";\nimport { refKey } from \"./utils\";\n\nexport const useRefWithUpdate = <T>(value: T) => {\n const ref = useRef<T>(value);\n\n useIsomorphicLayoutEffect(() => {\n ref[refKey] = value;\n }, [value]);\n\n return ref;\n};\n","import {\n Children,\n memo,\n useRef,\n useMemo,\n CSSProperties,\n ReactElement,\n forwardRef,\n useImperativeHandle,\n ReactNode,\n useEffect,\n RefObject,\n useState,\n ReactFragment,\n} from \"react\";\nimport { VirtualStore, createVirtualStore } from \"../core/store\";\nimport { useIsomorphicLayoutEffect } from \"./useIsomorphicLayoutEffect\";\nimport { useSyncExternalStore } from \"./useSyncExternalStore\";\nimport { exists, max, min } from \"../core/utils\";\nimport { createScroller, Scroller } from \"../core/scroller\";\nimport { refKey } from \"./utils\";\nimport { useStatic } from \"./useStatic\";\nimport { useRefWithUpdate } from \"./useRefWithUpdate\";\n\ntype ItemProps = {\n _children: ReactNode;\n _scroller: Scroller;\n _store: VirtualStore;\n _index: number;\n _element: \"div\";\n};\n\nconst Item = memo(\n ({\n _children: children,\n _scroller: scroller,\n _store: store,\n _index: index,\n _element: Element,\n }: ItemProps): ReactElement => {\n const ref = useRef<HTMLDivElement>(null);\n\n const offset = useSyncExternalStore(store._subscribe, () =>\n store._getItemOffset(index)\n );\n const hide = useSyncExternalStore(store._subscribe, () =>\n store._isUnmeasuredItem(index)\n );\n\n // The index may be changed if elements are inserted to or removed from the start of props.children\n useIsomorphicLayoutEffect(\n () => scroller._initItem(ref[refKey]!, index),\n [index]\n );\n\n return (\n <Element\n ref={ref}\n style={useMemo((): CSSProperties => {\n const isHorizontal = store._isHorizontal();\n const leftOrRightKey = store._isRtl() ? \"right\" : \"left\";\n const style: CSSProperties = {\n margin: 0,\n padding: 0,\n position: \"absolute\",\n [isHorizontal ? \"height\" : \"width\"]: \"100%\",\n [isHorizontal ? \"top\" : leftOrRightKey]: 0,\n [isHorizontal ? leftOrRightKey : \"top\"]: offset,\n visibility: hide ? \"hidden\" : \"visible\",\n // willChange: \"transform\",\n };\n if (isHorizontal) {\n style.display = \"flex\";\n }\n return style;\n }, [offset, hide])}\n >\n {children}\n </Element>\n );\n }\n);\n\nconst isInvalidElement = <T extends ReactNode>(\n e: T\n): e is Extract<T, null | undefined | boolean> =>\n !exists(e) || typeof e === \"boolean\";\n\nexport type WindowComponentAttributes = Pick<\n React.HTMLAttributes<HTMLElement>,\n \"className\" | \"style\" | \"id\" | \"role\" | \"tabIndex\"\n> &\n React.AriaAttributes;\n\n/**\n * Props of customized scrollable component.\n */\nexport interface CustomWindowComponentProps {\n children: ReactNode;\n scrollSize: number;\n scrolling: boolean;\n horizontal: boolean;\n attrs: WindowComponentAttributes;\n}\n\nconst DefaultWindow = forwardRef<any, CustomWindowComponentProps>(\n (\n { children, scrollSize, scrolling, horizontal, attrs },\n ref\n ): ReactElement => {\n return (\n <div ref={ref} {...attrs}>\n <div\n style={useMemo((): CSSProperties => {\n return {\n position: \"relative\",\n visibility: \"hidden\",\n width: horizontal ? scrollSize : \"100%\",\n height: horizontal ? \"100%\" : scrollSize,\n pointerEvents: scrolling ? \"none\" : \"auto\",\n };\n }, [scrollSize, scrolling])}\n >\n {children}\n </div>\n </div>\n );\n }\n);\n\nexport type CustomWindowComponent = typeof DefaultWindow;\n\nconst Window = ({\n _children: children,\n _ref: ref,\n _store: store,\n _element: Element,\n _scrolling: scrolling,\n _attrs: attrs,\n}: {\n _children: ReactNode;\n _ref: RefObject<HTMLDivElement>;\n _store: VirtualStore;\n _element: CustomWindowComponent;\n _scrolling: boolean;\n _attrs: WindowComponentAttributes;\n}) => {\n const scrollSize = useSyncExternalStore(\n store._subscribe,\n store._getScrollSize\n );\n\n const horizontal = store._isHorizontal();\n\n return (\n <Element\n ref={ref}\n scrollSize={scrollSize}\n scrolling={scrolling}\n horizontal={horizontal}\n attrs={useMemo(\n () => ({\n ...attrs,\n style: {\n overflow: horizontal ? \"auto hidden\" : \"hidden auto\",\n contain: \"strict\",\n // transform: \"translate3d(0px, 0px, 0px)\",\n // willChange: \"scroll-position\",\n // backfaceVisibility: \"hidden\",\n width: \"100%\",\n height: \"100%\",\n padding: 0,\n margin: 0,\n ...attrs.style,\n },\n }),\n [attrs]\n )}\n >\n {children}\n </Element>\n );\n};\n\n/**\n * Props of customized item component.\n */\nexport interface CustomItemComponentProps {\n style: CSSProperties;\n children: ReactNode;\n}\n\nexport type CustomItemComponent = React.ForwardRefExoticComponent<\n React.PropsWithoutRef<CustomItemComponentProps> & React.RefAttributes<any>\n>;\n\ntype CustomItemComponentOrElement =\n | keyof JSX.IntrinsicElements\n | CustomItemComponent;\n\n/**\n * Methods of {@link VList}.\n */\nexport interface VListHandle {\n /**\n * Get current scrollTop or scrollLeft.\n */\n readonly scrollOffset: number;\n /**\n * Get current scrollHeight or scrollWidth.\n */\n readonly scrollSize: number;\n /**\n * Get current offsetHeight or offsetWidth.\n */\n readonly viewportSize: number;\n /**\n * Scroll to the item specified by index.\n * @param index index of item\n */\n scrollToIndex(index: number): void;\n /**\n * Scroll to the given offset.\n * @param offset offset from start\n */\n scrollTo(offset: number): void;\n /**\n * Scroll by the given offset.\n * @param offset offset from current position\n */\n scrollBy(offset: number): void;\n}\n\n/**\n * Props of {@link VList}.\n */\nexport interface VListProps extends WindowComponentAttributes {\n /**\n * Elements rendered by this component.\n */\n children: ReactNode;\n /**\n * Item size hint for unmeasured items. It's recommended to specify this prop if item sizes are fixed and known, or much larger than the defaultValue. It will help to reduce scroll jump when items are measured.\n * @defaultValue 40\n */\n itemSize?: number;\n /**\n * Number of items to render above/below the visible bounds of the list. You can increase to avoid showing blank items in fast scrolling.\n * @defaultValue 4\n */\n overscan?: number;\n /**\n * If true, rendered as a horizontally scrollable list. Otherwise rendered as a vertically scrollable list.\n */\n horizontal?: boolean;\n /**\n * You have to set true if you use this component under `direction: rtl` style.\n */\n rtl?: boolean;\n /**\n * Customized element type for scrollable element. This element will get {@link CustomWindowComponentProps} as props.\n * @defaultValue {@link DefaultWindow}\n */\n element?: CustomWindowComponent;\n /**\n * Customized element type for item element. This element will get {@link CustomItemComponentProps} as props.\n * @defaultValue \"div\"\n */\n itemElement?: CustomItemComponentOrElement;\n /**\n * Callback invoked whenever scroll offset changes.\n * @param offset Current scrollTop or scrollLeft.\n */\n onScroll?: (offset: number) => void;\n /**\n * Callback invoked when scrolling stops.\n */\n onScrollStop?: () => void;\n /**\n * Callback invoked when visible items range changes.\n * @param payload `start` is the start index of viewable items. `end` is the end index of viewable items. `count` is the total count of items.\n */\n onRangeChange?: (payload: {\n start: number;\n end: number;\n count: number;\n }) => void;\n}\n\n/**\n * Virtualized list component. See {@link VListProps} and {@link VListHandle}.\n */\nexport const VList = forwardRef<VListHandle, VListProps>(\n (\n {\n children,\n itemSize: itemSizeProp = 40,\n overscan = 4,\n horizontal: horizontalProp,\n rtl: rtlProp,\n element = DefaultWindow,\n itemElement = \"div\",\n onScroll: onScrollProp,\n onScrollStop: onScrollStopProp,\n onRangeChange: onRangeChangeProp,\n ...windowAttrs\n },\n ref\n ): ReactElement => {\n // Memoize element array\n const elements = useMemo(() => {\n const arr: (ReactElement | ReactFragment | string | number)[] = [];\n Children.forEach(children, (e) => {\n if (isInvalidElement(e)) {\n return;\n }\n arr.push(e);\n });\n return arr;\n }, [children]);\n const count = elements.length;\n\n // https://github.com/facebook/react/issues/25191#issuecomment-1237456448\n const store = useStatic(() =>\n createVirtualStore(count, itemSizeProp, !!horizontalProp, !!rtlProp)\n );\n // The elements length and cached items length are different just after element is added/removed.\n store._updateCacheLength(count);\n\n const [startIndex, endIndex] = useSyncExternalStore(\n store._subscribe,\n store._getRange\n );\n const jump = useSyncExternalStore(store._subscribe, store._getJump);\n const rootRef = useRef<HTMLDivElement>(null);\n\n const onScroll = useRefWithUpdate(onScrollProp);\n const onScrollStop = useRefWithUpdate(onScrollStopProp);\n\n const [mountedIndexes, reset] = useState<Set<number>>(new Set<number>());\n const [scrolling, setScrolling] = useState(false);\n const scroller = useStatic(() =>\n createScroller(\n store,\n (offset) => {\n onScroll[refKey] && onScroll[refKey](offset);\n },\n (isScrolling) => {\n setScrolling(isScrolling);\n if (!isScrolling) {\n reset(new Set());\n onScrollStop[refKey] && onScrollStop[refKey]();\n }\n }\n )\n );\n\n useIsomorphicLayoutEffect(() => scroller._initRoot(rootRef[refKey]!), []);\n\n useIsomorphicLayoutEffect(() => {\n if (!jump.length) return;\n\n scroller._fixScrollJump(jump, startIndex);\n }, [jump]);\n\n useEffect(() => {\n if (!onRangeChangeProp) return;\n\n onRangeChangeProp({\n start: startIndex,\n end: endIndex,\n count,\n });\n }, [startIndex, endIndex]);\n\n useImperativeHandle(\n ref,\n () => {\n return {\n get scrollOffset() {\n return store._getScrollOffset();\n },\n get scrollSize() {\n return scroller._getActualScrollSize();\n },\n get viewportSize() {\n return store._getViewportSize();\n },\n scrollToIndex(index) {\n scroller._scrollToIndex(index, count);\n },\n scrollTo: scroller._scrollTo,\n scrollBy(offset) {\n scroller._scrollTo(store._getScrollOffset() + offset);\n },\n };\n },\n [count]\n );\n\n const startIndexWithMargin = max(startIndex - overscan, 0);\n const endIndexWithMargin = min(endIndex + overscan, count - 1);\n const items = useMemo(() => {\n const res: ReactElement[] = [];\n for (let i = startIndexWithMargin; i <= endIndexWithMargin; i++) {\n // https://github.com/sergi/virtual-list/commit/8e7e06dc63568334c1ab809ea83c1be36572e9ed\n mountedIndexes.add(i);\n }\n mountedIndexes.forEach((i) => {\n const e = elements[i];\n // This can be undefined when items are removed\n if (exists(e)) {\n res.push(\n <Item\n key={(e as { key?: ReactElement[\"key\"] })?.key || i}\n _scroller={scroller}\n _store={store}\n _index={i}\n _element={itemElement as \"div\"}\n _children={e}\n />\n );\n }\n });\n return res;\n }, [elements, mountedIndexes, startIndexWithMargin, endIndexWithMargin]);\n\n return (\n <Window\n _ref={rootRef}\n _store={store}\n _element={element}\n _scrolling={scrolling}\n _children={items}\n _attrs={windowAttrs}\n />\n );\n }\n);\n","import {\n findStartIndexWithOffset,\n resetCache,\n getItemSize,\n computeTotalSize,\n findEndIndex,\n computeStartOffset,\n Cache,\n UNCACHED,\n setItemSize,\n hasUnmeasuredItemsInRange,\n} from \"./cache\";\nimport type { Writeable } from \"./types\";\n\nexport type ScrollJump = Readonly<[index: number, sizeDiff: number][]>;\nexport type ItemResize = [index: number, size: number];\ntype ItemsRange = [startIndex: number, endIndex: number];\n\nexport const ACTION_UPDATE_ITEM_SIZES = 1;\nexport const ACTION_UPDATE_VIEWPORT = 2;\nexport const ACTION_HANDLE_SCROLL = 3;\n\ntype Actions =\n | [type: typeof ACTION_UPDATE_ITEM_SIZES, entries: ItemResize[]]\n | [\n type: typeof ACTION_UPDATE_VIEWPORT,\n rect: { _width: number; _height: number }\n ]\n | [type: typeof ACTION_HANDLE_SCROLL, offset: number];\n\nexport type VirtualStore = {\n _getRange(): ItemsRange;\n _isUnmeasuredItem(index: number): boolean;\n _hasUnmeasuredItemsInRange(startIndex: number): boolean;\n _getItemOffset(index: number): number;\n _getScrollOffset(): number;\n _getViewportSize(): number;\n _getScrollSize(): number;\n _getJump(): ScrollJump;\n _isHorizontal(): boolean;\n _isRtl(): boolean;\n _getItemIndexForScrollTo(offset: number): number;\n _waitForScrollDestinationItemsMeasured(): Promise<void>;\n _subscribe(cb: () => void): () => void;\n _update(...action: Actions): void;\n _updateCacheLength(length: number): void;\n};\n\nexport const createVirtualStore = (\n itemCount: number,\n itemSize: number,\n isHorizontal: boolean,\n isRtl: boolean\n): VirtualStore => {\n let viewportWidth = 0;\n let viewportHeight = 0;\n let scrollOffset = 0;\n let jump: ScrollJump = [];\n let cache = resetCache(itemCount, itemSize);\n let _prevRange: ItemsRange = [0, 0];\n let _scrollToQueue: [() => void, () => void] | undefined;\n\n const subscribers = new Set<() => void>();\n const getViewportSize = (): number =>\n isHorizontal ? viewportWidth : viewportHeight;\n\n return {\n _getRange() {\n const [prevStartIndex, prevEndIndex] = _prevRange;\n const prevOffset = computeStartOffset(\n cache as Writeable<Cache>,\n prevStartIndex\n );\n const start = findStartIndexWithOffset(\n cache,\n scrollOffset,\n prevStartIndex,\n prevOffset\n );\n const end = findEndIndex(cache, start, getViewportSize());\n if (prevStartIndex === start && prevEndIndex === end) {\n return _prevRange;\n }\n return (_prevRange = [start, end]);\n },\n _isUnmeasuredItem(index) {\n return cache._sizes[index] === UNCACHED;\n },\n _hasUnmeasuredItemsInRange(startIndex) {\n return hasUnmeasuredItemsInRange(\n cache,\n startIndex,\n findEndIndex(cache, startIndex, getViewportSize())\n );\n },\n _getItemOffset(index) {\n return computeStartOffset(cache as Writeable<Cache>, index);\n },\n _getScrollOffset() {\n return scrollOffset;\n },\n _getViewportSize() {\n return getViewportSize();\n },\n _getScrollSize() {\n return computeTotalSize(cache as Writeable<Cache>);\n },\n _getJump() {\n return jump;\n },\n _isHorizontal() {\n return isHorizontal;\n },\n _isRtl() {\n return isRtl;\n },\n _getItemIndexForScrollTo(offset) {\n return findStartIndexWithOffset(cache, offset, 0, 0);\n },\n _waitForScrollDestinationItemsMeasured() {\n if (_scrollToQueue) {\n // Cancel waiting scrollTo\n _scrollToQueue[1]();\n }\n // The measurement will be done asynchronously and the timing is not predictable so we use promise.\n // For example, ResizeObserver may not fire when window is not visible.\n return new Promise((resolve, reject) => {\n _scrollToQueue = [\n () => {\n // HACK: It should be resolved in the next microtask that is after React's render\n Promise.resolve().then(() => {\n resolve();\n _scrollToQueue = undefined;\n });\n },\n reject,\n ];\n });\n },\n _subscribe(cb) {\n subscribers.add(cb);\n return () => {\n subscribers.delete(cb);\n };\n },\n _update(type, payload) {\n const mutated = ((): boolean => {\n switch (type) {\n case ACTION_UPDATE_ITEM_SIZES: {\n const updated = payload.filter(\n ([index, size]) => cache._sizes[index] !== size\n );\n // Skip if all items are cached and not updated\n if (!updated.length) {\n return false;\n }\n\n const updatedJump: [index: number, sizeDiff: number][] = [];\n updated.forEach(([index, size]) => {\n updatedJump.push([index, size - getItemSize(cache, index)]);\n setItemSize(cache as Writeable<Cache>, index, size);\n });\n jump = updatedJump;\n return true;\n }\n case ACTION_UPDATE_VIEWPORT: {\n if (\n viewportWidth === payload._width &&\n viewportHeight === payload._height\n ) {\n return false;\n }\n viewportWidth = payload._width;\n viewportHeight = payload._height;\n return true;\n }\n case ACTION_HANDLE_SCROLL: {\n const prevOffset = scrollOffset;\n return (scrollOffset = payload) !== prevOffset;\n }\n }\n })();\n\n if (mutated) {\n subscribers.forEach((cb) => {\n cb();\n });\n if (_scrollToQueue && type === ACTION_UPDATE_ITEM_SIZES) {\n _scrollToQueue[0]();\n }\n }\n },\n _updateCacheLength(length) {\n // It's ok to be updated in render because states should be calculated consistently regardless cache length\n if (cache._length === length) return;\n cache = resetCache(length, itemSize, cache);\n },\n };\n};\n","import {\n ACTION_HANDLE_SCROLL,\n ACTION_UPDATE_ITEM_SIZES,\n ACTION_UPDATE_VIEWPORT,\n ItemResize,\n ScrollJump,\n VirtualStore,\n} from \"./store\";\nimport { abs, debounce, throttle, exists, max, min } from \"./utils\";\n\nexport const SCROLL_STOP = 0;\nexport const SCROLL_DOWN = 1;\nexport const SCROLL_UP = 2;\nexport const SCROLL_MANUAL = 3;\ntype ScrollDirection =\n | typeof SCROLL_STOP\n | typeof SCROLL_DOWN\n | typeof SCROLL_UP\n | typeof SCROLL_MANUAL;\n\nexport type Scroller = {\n _initRoot: (rootElement: HTMLElement) => () => void;\n _initItem: (itemElement: HTMLElement, index: number) => () => void;\n _getActualScrollSize: () => number;\n _scrollTo: (offset: number) => void;\n _scrollToIndex: (index: number, count: number) => void;\n _fixScrollJump: (jump: ScrollJump, startIndex: number) => void;\n};\n\nexport const createScroller = (\n store: VirtualStore,\n emitScrollOffsetChange: (offset: number) => void,\n emitScrollStateChange: (scrolling: boolean) => void\n): Scroller => {\n let prevOffset = -1;\n let scrollDirection: ScrollDirection = SCROLL_STOP;\n let resized = false;\n let isNegativeOffset: boolean | undefined;\n let rootElement: HTMLElement | undefined;\n let _ro: ResizeObserver | undefined;\n const isHorizontal = store._isHorizontal();\n const isRtl = store._isRtl();\n const scrollToKey = isHorizontal ? \"scrollLeft\" : \"scrollTop\";\n const mountedIndexes = new WeakMap<Element, number>();\n const getResizeObserver = (): ResizeObserver => {\n // Initialize ResizeObserver lazily for SSR\n return (\n _ro ||\n (_ro = new ResizeObserver((entries) => {\n // https://www.w3.org/TR/resize-observer/#intro\n const resizes: ItemResize[] = [];\n for (const entry of entries) {\n if (entry.target === rootElement) {\n store._update(ACTION_UPDATE_VIEWPORT, {\n _width: entry.contentRect.width,\n _height: entry.contentRect.height,\n });\n } else {\n const index = mountedIndexes.get(entry.target);\n if (exists(index)) {\n resizes.push([\n index,\n entry.contentRect[isHorizontal ? \"width\" : \"height\"],\n ]);\n }\n }\n }\n\n if (resizes.length) {\n store._update(ACTION_UPDATE_ITEM_SIZES, resizes);\n resized = true;\n }\n }))\n );\n };\n const getActualScrollSize = (): number => {\n if (!rootElement) return 0;\n // Use element's scrollHeight/scrollWidth instead of stored scrollSize.\n // This is because stored size may differ from the actual size, for example when a new item is added and not yet measured.\n return store._isHorizontal()\n ? rootElement.scrollWidth\n : rootElement.scrollHeight;\n };\n const updateScrollPosition = (offset: number, diff?: boolean) => {\n if (!rootElement) return;\n if (isRtl) {\n if (!exists(isNegativeOffset)) {\n // Assume offset type in rtl direction.\n // The scroll position is negative in spec however its not in some browsers, for example Chrome earlier than v85.\n // https://github.com/othree/jquery.rtl-scroll-type\n const prev = rootElement[scrollToKey];\n rootElement[scrollToKey] = 1;\n isNegativeOffset = rootElement[scrollToKey] === 0;\n rootElement[scrollToKey] = prev;\n }\n if (isNegativeOffset) {\n offset *= -1;\n }\n }\n if (diff) {\n rootElement[scrollToKey] += offset;\n } else {\n rootElement[scrollToKey] = offset;\n scrollDirection = SCROLL_MANUAL;\n }\n };\n const scrollTo = async (index: number, getCurrentOffset: () => number) => {\n const getOffset = (): number => {\n let offset = getCurrentOffset();\n const scrollSize = getActualScrollSize();\n const viewportSize = store._getViewportSize();\n if (scrollSize - (offset + viewportSize) <= 0) {\n // Adjust if the offset is over the end, to get correct startIndex.\n offset = scrollSize - viewportSize;\n }\n return offset;\n };\n\n if (store._hasUnmeasuredItemsInRange(index)) {\n do {\n // In order to scroll to the correct position, mount the items and measure their sizes before scrolling.\n store._update(ACTION_HANDLE_SCROLL, getOffset());\n try {\n // Wait for the scroll destination items to be measured.\n await store._waitForScrollDestinationItemsMeasured();\n } catch (e) {\n // canceled\n return;\n }\n } while (store._hasUnmeasuredItemsInRange(index));\n\n // Scroll with the updated value\n updateScrollPosition(getOffset());\n } else {\n const offset = getOffset();\n updateScrollPosition(offset);\n // Sync viewport to scroll destination\n store._update(ACTION_HANDLE_SCROLL, offset);\n }\n };\n\n const calcTotalJump = (jump: ScrollJump): number =>\n jump.reduce((acc, [, j]) => acc + j, 0);\n\n return {\n _initRoot(root) {\n rootElement = root;\n const ro = getResizeObserver();\n\n const syncViewportToScrollPosition = () => {\n let offset = root[scrollToKey];\n if (isRtl) {\n // The scroll position may be negative value in rtl direction.\n // https://github.com/othree/jquery.rtl-scroll-type\n offset = abs(offset);\n }\n if (prevOffset === offset) {\n return;\n }\n // Skip scroll direction detection just after resizing because it may result in the opposite direction.\n // Scroll events are dispatched enough so it's ok to skip some of them.\n if (scrollDirection === SCROLL_STOP || !resized) {\n // Ignore until manual scrolling\n if (scrollDirection !== SCROLL_MANUAL) {\n scrollDirection = prevOffset > offset ? SCROLL_UP : SCROLL_DOWN;\n }\n } else {\n resized = false;\n }\n store._update(ACTION_HANDLE_SCROLL, (prevOffset = offset));\n emitScrollOffsetChange(offset);\n };\n\n const onScrollStopped = debounce(() => {\n // Check scroll position once just after scrolling stopped\n syncViewportToScrollPosition();\n scrollDirection = SCROLL_STOP;\n emitScrollStateChange(false);\n }, 150);\n\n const onScroll = () => {\n const isScrollStart = scrollDirection === SCROLL_STOP;\n syncViewportToScrollPosition();\n if (isScrollStart) {\n emitScrollStateChange(true);\n }\n onScrollStopped();\n };\n\n // Infer scroll state also from wheel events\n // Sometimes scroll events do not fire when frame dropped even if the visual have been already scrolled\n const onWheel = throttle((e: WheelEvent) => {\n if (scrollDirection === SCROLL_STOP) {\n // Scroll start should be detected with scroll event\n return;\n }\n if (e.ctrlKey) {\n // Probably a pinch-to-zoom gesture\n return;\n }\n // Get delta before checking deltaMode for firefox behavior\n // https://github.com/w3c/uievents/issues/181#issuecomment-392648065\n // https://bugzilla.mozilla.org/show_bug.cgi?id=1392460#c34\n if (isHorizontal ? e.deltaX : e.deltaY) {\n if (\n prevOffset > 0 &&\n prevOffset < store._getScrollSize() - store._getViewportSize()\n ) {\n onScrollStopped();\n }\n }\n }, 50);\n\n ro.observe(root);\n root.addEventListener(\"scroll\", onScroll);\n root.addEventListener(\"wheel\", onWheel, { passive: true });\n\n return () => {\n ro.disconnect();\n root.removeEventListener(\"scroll\", onScroll);\n root.removeEventListener(\"wheel\", onWheel);\n onScrollStopped._cancel();\n };\n },\n _initItem(el, i) {\n const ro = getResizeObserver();\n mountedIndexes.set(el, i);\n ro.observe(el);\n return () => {\n mountedIndexes.delete(el);\n ro.unobserve(el);\n };\n },\n _getActualScrollSize: getActualScrollSize,\n _scrollTo(offset) {\n offset = max(offset, 0);\n\n scrollTo(store._getItemIndexForScrollTo(offset), () => offset);\n },\n _scrollToIndex(index, count) {\n index = max(min(index, count - 1), 0);\n\n scrollTo(index, () => store._getItemOffset(index));\n },\n _fixScrollJump: (jump, startIndex) => {\n // Compensate scroll jump\n if (scrollDirection === SCROLL_UP) {\n const diff = calcTotalJump(jump);\n if (diff) {\n updateScrollPosition(diff, true);\n }\n } else if (scrollDirection === SCROLL_MANUAL) {\n const offset = store._getScrollOffset();\n if (offset === 0) {\n // Do nothing to stick to the start\n } else {\n const allDiff = calcTotalJump(jump);\n if (\n store._getScrollSize() -\n (offset + store._getViewportSize() + allDiff) <=\n 0\n ) {\n // Keep end to stick to the end\n if (allDiff) {\n updateScrollPosition(offset + allDiff);\n }\n } else {\n // Keep start at mid\n const diff = jump.reduce((acc, [index, j]) => {\n if (index < startIndex) {\n acc += j;\n }\n return acc;\n }, 0);\n if (diff) {\n updateScrollPosition(diff, true);\n }\n }\n }\n } else {\n // NOP\n }\n },\n };\n};\n"],"names":["min","Math","max","abs","now","Date","exists","v","range","length","cb","Array","from","_","i","getItemSize","cache","index","size","_sizes","_defaultItemSize","computeOffset","isTotal","_length","_measuredOffsetIndex","_offsets","top","computeStartOffset","findIndex","distance","sum","h","findStartIndexWithOffset","offset","prevStartIndex","prevOffset","findEndIndex","resetCache","itemSize","useIsomorphicLayoutEffect","window","useLayoutEffect","useEffect","useSyncExternalStore","subscibe","getSnapShot","_useSyncExternalStore","refKey","useStatic","init","ref","useRef","useRefWithUpdate","value","Item","memo","_children","children","_scroller","scroller","_store","store","_index","_element","Element","_subscribe","_getItemOffset","hide","_isUnmeasuredItem","_initItem","_jsx","style","useMemo","isHorizontal","_isHorizontal","leftOrRightKey","_isRtl","margin","padding","position","visibility","display","DefaultWindow","forwardRef","scrollSize","scrolling","horizontal","attrs","width","height","pointerEvents","Window","_ref","_scrolling","_attrs","_getScrollSize","overflow","contain","VList","itemSizeProp","overscan","horizontalProp","rtl","rtlProp","element","itemElement","onScroll","onScrollProp","onScrollStop","onScrollStopProp","onRangeChange","onRangeChangeProp","windowAttrs","elements","arr","Children","forEach","e","isInvalidElement","push","count","createVirtualStore","itemCount","isRtl","_scrollToQueue","viewportWidth","viewportHeight","scrollOffset","jump","_prevRange","subscribers","Set","getViewportSize","_getRange","prevEndIndex","start","end","_hasUnmeasuredItemsInRange","startIndex","hasUnmeasuredItemsInRange","endIndex","_getScrollOffset","_getViewportSize","computeTotalSize","_getJump","_getItemIndexForScrollTo","_waitForScrollDestinationItemsMeasured","Promise","resolve","reject","then","undefined","add","delete","_update","type","payload","mutated","updated","filter","updatedJump","setItemSize","_width","_height","_updateCacheLength","rootRef","mountedIndexes","reset","useState","setScrolling","createScroller","emitScrollOffsetChange","emitScrollStateChange","isNegativeOffset","rootElement","_ro","scrollDirection","resized","scrollToKey","WeakMap","getResizeObserver","ResizeObserver","entries","resizes","entry","target","contentRect","get","getActualScrollSize","scrollWidth","scrollHeight","updateScrollPosition","diff","prev","scrollTo","async","getCurrentOffset","getOffset","viewportSize","calcTotalJump","reduce","acc","j","_initRoot","root","ro","syncViewportToScrollPosition","onScrollStopped","debounce","id","cancel","clearTimeout","debouncedFn","setTimeout","_cancel","isScrollStart","onWheel","throttle","time","args","n","ctrlKey","deltaX","deltaY","fn","observe","addEventListener","passive","disconnect","removeEventListener","el","set","unobserve","_getActualScrollSize","_scrollTo","_scrollToIndex","_fixScrollJump","allDiff","isScrolling","useImperativeHandle","scrollToIndex","scrollBy","startIndexWithMargin","endIndexWithMargin","items","res","key"],"mappings":"oRAAO,MAAMA,EAAMC,KAAKD,IACXE,EAAMD,KAAKC,IACXC,EAAMF,KAAKE,IACXC,EAAMC,KAAKD,IAEXE,EAAaC,GAAiD,MAALA,EAEzDC,EAAQA,CAAIC,EAAgBC,IACvCC,MAAMC,KAAK,CAAEH,WAAU,CAACI,EAAGC,IAAMJ,EAAGI,KCKzBC,EAAcA,CAACC,EAAcC,KACxC,MAAMC,EAAOF,EAAMG,EAAOF,GAC1B,OAZsB,IAYfC,EAAoBF,EAAMI,EAAmBF,CAAI,EAapDG,EAAgBA,CACpBL,EACAC,EACAK,KAEA,IAAKN,EAAMO,EAAS,OAAO,EAC3B,GAAIP,EAAMQ,GAAwBP,EAChC,OAAIK,EACKN,EAAMS,EAASR,GAAUF,EAAYC,EAAOC,GAE5CD,EAAMS,EAASR,GAI1B,IAAIH,EAAIE,EAAMQ,EACVE,EAAMV,EAAMS,EAASX,GACzB,KAAOA,GAAKG,IACVD,EAAMS,EAASX,GAAKY,EAChBZ,IAAMG,GAAUK,IAGpBI,GAAOX,EAAYC,EAAOF,GAC1BA,IAIF,OADAE,EAAMQ,EAAuBP,EACtBS,CAAG,EAOCC,EAAqBA,CAChCX,EACAC,IAEOI,EAAcL,EAAOC,GAGxBW,EAAYA,CAACZ,EAAcF,EAAWe,KAC1C,IAAIC,EAAM,EACV,GAAID,GAAY,EAEd,KAAOf,EAAIE,EAAMO,EAAU,GAAG,CAC5B,MAAMQ,EAAIhB,EAAYC,EAAOF,KAC7B,IAAKgB,GAAOC,IAAMF,EAAU,CACtBC,EAAMC,EAAI,GAAKF,GACjBf,IAEF,KACD,CACF,MAGD,KAAOA,EAAI,GAAG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EAAU,GAClD+I,EAAqBnP,EAAI4I,EAAWxC,EAAUoB,EAAQ,GACtD4H,GAAQ5K,GAAQ,KACpB,MAAM6K,EAAsB,GAC5B,IAAK,IAAIvO,EAAIoO,EAAsBpO,GAAKqO,EAAoBrO,IAE1DwJ,EAAed,IAAI1I,GAkBrB,OAhBAwJ,EAAelD,SAAStG,IACtB,MAAMuG,EAAIJ,EAASnG,GAEfR,EAAO+G,IACTgI,EAAI9H,KACFjD,EAAChB,GAECI,EAAWC,EACXC,EAAQC,EACRC,EAAQhD,EACRiD,EAAU0C,EACVjD,EAAW6D,IALLA,aAAC,EAADA,EAAqCiI,MAAOxO,GAQvD,IAEIuO,CAAG,GACT,CAACpI,EAAUqD,EAAgB4E,EAAsBC,IAEpD,OACE7K,EAACqB,EAAM,CACLC,EAAMyE,EACNzG,EAAQC,EACRE,EAAUyC,EACVX,EAAYR,EACZ7B,EAAW4L,GACXtJ,EAAQkB,GACR"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "virtua",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "A zero-config, fast and small (3kB) virtual list component for React.",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"module": "lib/index.mjs",
|
|
@@ -67,7 +67,7 @@
|
|
|
67
67
|
"rollup": "3.21.5",
|
|
68
68
|
"storybook": "^7.0.8",
|
|
69
69
|
"ts-jest": "29.1.0",
|
|
70
|
-
"typedoc": "0.24.
|
|
70
|
+
"typedoc": "0.24.4",
|
|
71
71
|
"typedoc-plugin-markdown": "3.15.3",
|
|
72
72
|
"typescript": "5.0.4",
|
|
73
73
|
"virtua": "^0.2.0",
|