virtua 0.1.11 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +31 -4
- package/lib/core/scroller.d.ts +4 -7
- package/lib/core/store.d.ts +1 -0
- package/lib/index.d.ts +2 -2
- 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/lib/react/{List.d.ts → VList.d.ts} +39 -27
- package/lib/react/useRefWithUpdate.d.ts +2 -0
- package/package.json +10 -7
- package/lib/react/useEvent.d.ts +0 -1
package/README.md
CHANGED
|
@@ -4,6 +4,8 @@
|
|
|
4
4
|
|
|
5
5
|
A zero-config, fast and small (3kB) virtual list component for [React](https://github.com/facebook/react).
|
|
6
6
|
|
|
7
|
+
If you want to check the difference with the alternatives right away, [see comparison section](#comparison).
|
|
8
|
+
|
|
7
9
|
## Motivation
|
|
8
10
|
|
|
9
11
|
This project is a challenge to rethink virtualization. The goals are...
|
|
@@ -12,7 +14,7 @@ This project is a challenge to rethink virtualization. The goals are...
|
|
|
12
14
|
- **Fast:** Scrolling without frame drop needs optimization in many aspects (reduce CPU usage, reduce GC, [reduce layout recalculation](https://gist.github.com/paulirish/5d52fb081b3570c81e3a), optimize for frameworks, etc). We are trying to combine the best of them.
|
|
13
15
|
- **Small:** Its bundle size should be small as much as possible to be friendly with modern web development. Currently [about 3kB gzipped](https://bundlephobia.com/package/virtua).
|
|
14
16
|
- **Flexible:** Aiming to support many usecases - fixed size, dynamic size, horizontal scrolling, reverse scrolling, rtl direction, sticky, infinite scrolling, placeholder, scrollTo, dnd, table, and more. See [live demo](#demo).
|
|
15
|
-
- **Framework agnostic (WIP):** Currently only for React but we could support Vue, Svelte, Solid and more in the future.
|
|
17
|
+
- **Framework agnostic (WIP):** Currently only for React but we could support Vue, Svelte, Solid, Web Components and more in the future.
|
|
16
18
|
|
|
17
19
|
## Demo
|
|
18
20
|
|
|
@@ -33,11 +35,11 @@ If you use ESM and webpack 5, use react >= 18 to avoid [Can't resolve `react/jsx
|
|
|
33
35
|
## Usage
|
|
34
36
|
|
|
35
37
|
```tsx
|
|
36
|
-
import {
|
|
38
|
+
import { VList } from "virtua";
|
|
37
39
|
|
|
38
40
|
export const App = () => {
|
|
39
41
|
return (
|
|
40
|
-
<
|
|
42
|
+
<VList style={{ height: 800 }}>
|
|
41
43
|
{Array.from({ length: 1000 }).map((_, i) => (
|
|
42
44
|
<div
|
|
43
45
|
key={i}
|
|
@@ -50,7 +52,7 @@ export const App = () => {
|
|
|
50
52
|
{i}
|
|
51
53
|
</div>
|
|
52
54
|
))}
|
|
53
|
-
</
|
|
55
|
+
</VList>
|
|
54
56
|
);
|
|
55
57
|
};
|
|
56
58
|
```
|
|
@@ -61,6 +63,31 @@ And see [examples](./stories) for more usages.
|
|
|
61
63
|
|
|
62
64
|
- [API reference](./docs/API.md)
|
|
63
65
|
|
|
66
|
+
## Comparison
|
|
67
|
+
|
|
68
|
+
### Benchmarks
|
|
69
|
+
|
|
70
|
+
WIP
|
|
71
|
+
|
|
72
|
+
### Features
|
|
73
|
+
|
|
74
|
+
| | [virtua](https://github.com/inokawa/virtua) | [react-virtuoso](https://github.com/petyosi/react-virtuoso) | [react-virtualized](https://github.com/bvaughn/react-virtualized) | [react-window](https://github.com/bvaughn/react-window) | [react-virtual](https://github.com/TanStack/virtual) | [react-cool-virtual](https://github.com/wellyshen/react-cool-virtual) |
|
|
75
|
+
| :---------------- | :------------------------------------------------------- | :---------------------------------------------------------------- | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :------------------------------------------------------------------------------------------------- | :-------------------------------------------------------------- | :-------------------------------------------------------------------- |
|
|
76
|
+
| Bundle size | [3.1kB gzipped](https://bundlephobia.com/package/virtua) | [15.6kB gzipped](https://bundlephobia.com/package/react-virtuoso) | [27.4kB gzipped](https://bundlephobia.com/package/react-virtualized) | [6.4kB gzipped](https://bundlephobia.com/package/react-window) | [2.3kB gzipped](https://bundlephobia.com/package/react-virtual) | [3.1kB gzipped](https://bundlephobia.com/package/react-cool-virtual) |
|
|
77
|
+
| Vertical scroll | ✅ | ✅ | ✅ | ✅ | 🟠 (needs customization) | 🟠 (needs customization) |
|
|
78
|
+
| Horizontal scroll | ✅ | ✅ | ✅ | ✅ | 🟠 (needs customization) | 🟠 (needs customization) |
|
|
79
|
+
| Grid | ❌ | ✅ | ✅ | ✅ | 🟠 (needs customization) | 🟠 (needs customization) |
|
|
80
|
+
| Table | 🟠 (needs customization) | ✅ | ✅ | 🟠 (needs customization) | 🟠 (needs customization) | 🟠 (needs customization) |
|
|
81
|
+
| Dynamic list size | ✅ | ✅ | 🟠 (needs [AutoSizer](https://github.com/bvaughn/react-virtualized/blob/master/docs/AutoSizer.md)) | 🟠 (needs [AutoSizer](https://github.com/bvaughn/react-virtualized/blob/master/docs/AutoSizer.md)) | ✅ | ✅ |
|
|
82
|
+
| Dynamic item size | ✅ | ✅ | 🟠 (needs [CellMeasurer](https://github.com/bvaughn/react-virtualized/blob/master/docs/CellMeasurer.md) and has wrong destination when scrolling to item imperatively) | 🟠 (needs additional codes and has wrong destination when scrolling to item imperatively) | 🟠 (has wrong destination when scrolling to item imperatively) | 🟠 (has wrong destination when scrolling to item imperatively) |
|
|
83
|
+
| Reverse scroll | ✅ | ✅ | ❌ | ❌ | ❌ | ❌ |
|
|
84
|
+
| Infinite scroll | ✅ | ✅ | 🟠 (needs [InfiniteLoader](https://github.com/bvaughn/react-virtualized/blob/master/docs/InfiniteLoader.md)) | 🟠 (needs [react-window-infinite-loader](https://github.com/bvaughn/react-window-infinite-loader)) | ✅ | ✅ |
|
|
85
|
+
| RTL | ✅ | ❌ | ✅ | ✅ | ❌ | ❌ |
|
|
86
|
+
|
|
87
|
+
- ✅ - Built-in supported
|
|
88
|
+
- 🟠 - Supported but partial, limited or requires some user custom code
|
|
89
|
+
- ❌ - Not officially supported
|
|
90
|
+
|
|
64
91
|
## Contribute
|
|
65
92
|
|
|
66
93
|
All contributions are welcome.
|
package/lib/core/scroller.d.ts
CHANGED
|
@@ -1,17 +1,14 @@
|
|
|
1
|
-
import { VirtualStore } from "./store";
|
|
1
|
+
import { ScrollJump, VirtualStore } from "./store";
|
|
2
2
|
export declare const SCROLL_STOP = 0;
|
|
3
3
|
export declare const SCROLL_DOWN = 1;
|
|
4
4
|
export declare const SCROLL_UP = 2;
|
|
5
5
|
export declare const SCROLL_MANUAL = 3;
|
|
6
|
-
type ScrollDirection = typeof SCROLL_STOP | typeof SCROLL_DOWN | typeof SCROLL_UP | typeof SCROLL_MANUAL;
|
|
7
6
|
export type Scroller = {
|
|
8
7
|
_initRoot: (rootElement: HTMLElement) => () => void;
|
|
9
8
|
_initItem: (itemElement: HTMLElement, index: number) => () => void;
|
|
10
|
-
_getScrollPosition: () => number;
|
|
11
|
-
_getScrollDirection: () => ScrollDirection;
|
|
12
9
|
_getActualScrollSize: () => number;
|
|
13
|
-
|
|
14
|
-
|
|
10
|
+
_scrollTo: (offset: number) => void;
|
|
11
|
+
_scrollToIndex: (index: number, count: number) => void;
|
|
12
|
+
_fixScrollJump: (jump: ScrollJump, startIndex: number) => void;
|
|
15
13
|
};
|
|
16
14
|
export declare const createScroller: (store: VirtualStore, emitScrollOffsetChange: (offset: number) => void, emitScrollStateChange: (scrolling: boolean) => void) => Scroller;
|
|
17
|
-
export {};
|
package/lib/core/store.d.ts
CHANGED
|
@@ -17,6 +17,7 @@ export type VirtualStore = {
|
|
|
17
17
|
_isUnmeasuredItem(index: number): boolean;
|
|
18
18
|
_hasUnmeasuredItemsInRange(startIndex: number): boolean;
|
|
19
19
|
_getItemOffset(index: number): number;
|
|
20
|
+
_getScrollOffset(): number;
|
|
20
21
|
_getViewportSize(): number;
|
|
21
22
|
_getScrollSize(): number;
|
|
22
23
|
_getItemCount(): number;
|
package/lib/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export type {
|
|
1
|
+
export { VList } from "./react/VList";
|
|
2
|
+
export type { VListProps, VListHandle, CustomItemComponent, CustomItemComponentProps, CustomWindowComponent, CustomWindowComponentProps, WindowComponentAttributes, } from "./react/VList";
|
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,
|
|
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},_=(e,t)=>a(e,t),d=(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)=>d(e,r,t-n),h=d,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})})),I=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})}))),x=({_: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})},y=t.forwardRef((({children:r,itemSize:c=40,overscan:d=4,horizontal:y,rtl:b,element:T=I,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,d=[],m=g(e,t),w=[0,0];const S=new Set,p=()=>r?l:i;return{A(){const[e,t]=w,r=_(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=>_(m,e),D:()=>c,F:()=>p(),j:()=>(e=>a(e,e.l-1,!0))(m),J:()=>m.l,P:()=>d,R:()=>r,M:()=>o,U:e=>f(m,e,0,0),B:()=>(s&&s[1](),new Promise(((e,t)=>{s=[()=>{Promise.resolve().then((()=>{e(),s=void 0}))},t]}))),p:e=>(S.add(e),()=>{S.delete(e)}),H(e,r){(()=>{switch(e){case 0:return m.l!==r&&(m=g(r,t,m),!0);case 1:{const e=r.filter((([e,t])=>m.t[e]!==t));if(!e.length)return!1;const t=[];return e.forEach((([e,r])=>{t.push([e,r-u(m,e)]),((e,t,r)=>{e.t[t]=r,e.i=n(t,e.i)})(m,e,r)})),d=t,!0}case 2:return(l!==r.L||i!==r.V)&&(l=r.L,i=r.V,!0);case 3:{const e=c;return(c=r)!==e}}})()&&(S.forEach((e=>{e()})),s&&1===e&&s[0]())}}})(C,c,!!y,!!b))),[E,F]=w(D.p,D.A),J=w(D.p,D.P),P=t.useRef(null),U=v(M),B=v(O),[H,L]=t.useState(new Set),[V,W]=t.useState(!1),G=p((()=>((e,t,r)=>{let c,u,a,_=-1,d=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.H(2,{L:n.contentRect.width,V:n.contentRect.height});else{const e=w.get(n.target);i(e)&&r.push([e,n.contentRect[h?"width":"height"]])}r.length&&(e.H(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,d=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.H(3,n());try{await e.B()}catch(e){return}}while(e.C(t));v(n())}else{const t=n();v(t),e.H(3,t)}},I=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)),_!==r&&(0!==d&&f?f=!1:3!==d&&(d=_>r?2:1),e.H(3,_=r),t(r))},a=(()=>{let e;const t=()=>{i(e)&&clearTimeout(e)},n=()=>{t(),e=setTimeout((()=>{e=null,c(),d=0,r(!1)}),150)};return n.G=t,n})(),w=()=>{const e=0===d;c(),e&&r(!0),a()},p=(()=>{let t=l()-50;return(...r)=>{const n=l();t+50<n&&(t=n,(t=>{0!==d&&(t.ctrlKey||(h?t.deltaX:t.deltaY)&&_>0&&_<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.U(t),(()=>t))},X(t,r){t=o(n(t,r-1),0),z(t,(()=>e.v(t)))},Y:(t,r)=>{if(2===d){const e=I(t);e&&v(e,!0)}else if(3===d){const n=e.D();if(0===n);else{const o=I(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=>{U[S]&&U[S](e)}),(e=>{W(e),e||(L(new Set),B[S]&&B[S]())})))),K=n(C,D.J());m((()=>{D.H(0,C)}),[C]),m((()=>G.W(P[S])),[]),m((()=>{J.length&&G.Y(J,E)}),[J]),t.useEffect((()=>{k&&k({start:E,end:F,count:K})}),[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,K)},scrollTo:G.N,scrollBy(e){G.N(D.D()+e)}})),[K]);const N=o(E-d,0),Q=n(F+d,K-1),X=t.useMemo((()=>{const t=[];for(let e=N;e<=Q;e++)H.add(e);return H.forEach((r=>{const n=A[r];t.push(e.jsx(z,{h:G,g:D,m:r,S:R,_:n},(null==n?void 0:n.key)||r))})),t}),[A,H,N,Q]);return e.jsx(x,{O:P,g:D,S:T,k:V,_:X,q})}));exports.VList=y;
|
|
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/useEvent.ts","../src/src/react/List.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 { useCallback, useRef } from \"react\";\n\nimport { useIsomorphicLayoutEffect } from \"./useIsomorphicLayoutEffect\";\nimport { refKey } from \"./utils\";\n\nexport const useEvent = <T extends (...args: any[]) => void>(\n handler: T | undefined\n) => {\n const handlerRef = useRef<T | undefined>(handler);\n\n useIsomorphicLayoutEffect(() => {\n handlerRef[refKey] = handler;\n });\n\n return useCallback((...args: Parameters<T>): void => {\n handlerRef[refKey] && handlerRef[refKey](...args);\n }, []);\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} 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 {\n createScroller,\n Scroller,\n SCROLL_MANUAL,\n SCROLL_UP,\n} from \"../core/scroller\";\nimport { refKey } from \"./utils\";\nimport { useStatic } from \"./useStatic\";\nimport { useEvent } from \"./useEvent\";\n\nconst INITIAL_END_REACHED_INDEX = -1;\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 // willChange: \"transform\",\n };\n if (isHorizontal) {\n style.display = \"flex\";\n }\n if (hide) {\n style.visibility = \"hidden\";\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 interface CustomWindowComponentProps {\n children: ReactNode;\n style: CSSProperties;\n scrollSize: number;\n scrolling: boolean;\n horizontal: boolean;\n rtl: boolean;\n}\n\nconst DefaultWindow = forwardRef<any, CustomWindowComponentProps>(\n (\n { children, style, scrollSize, scrolling, horizontal, rtl },\n ref\n ): ReactElement => {\n return (\n <div ref={ref} style={style}>\n <div\n style={useMemo((): CSSProperties => {\n const width = horizontal ? scrollSize : \"100%\";\n const height = horizontal ? \"100%\" : scrollSize;\n return {\n position: \"absolute\",\n top: 0,\n [rtl ? \"right\" : \"left\"]: 0,\n width,\n height,\n minWidth: width,\n minHeight: height,\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 _style: style,\n}: {\n _children: ReactNode;\n _ref: RefObject<HTMLDivElement>;\n _store: VirtualStore;\n _element: CustomWindowComponent;\n _scrolling: boolean;\n _style: CSSProperties | undefined;\n}) => {\n const scrollSize = useSyncExternalStore(\n store._subscribe,\n store._getScrollSize\n );\n const viewportSize = useSyncExternalStore(\n store._subscribe,\n store._getViewportSize\n );\n const clampedScrollSize =\n scrollSize >= viewportSize ? scrollSize : viewportSize;\n\n const horizontal = store._isHorizontal();\n return (\n <Element\n ref={ref}\n scrollSize={clampedScrollSize}\n scrolling={scrolling}\n horizontal={horizontal}\n rtl={store._isRtl()}\n style={useMemo(\n (): CSSProperties => ({\n overflow: horizontal ? \"auto hidden\" : \"hidden auto\",\n position: \"relative\",\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 ...style,\n }),\n [style]\n )}\n >\n {children}\n </Element>\n );\n};\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 List}.\n */\nexport interface ListHandle {\n /**\n * Get current scrollTop or scrollLeft.\n */\n scrollOffset: number;\n /**\n * Get current scrollHeight or scrollWidth.\n */\n scrollSize: 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 item specified by offset.\n * @param offset offset from start\n */\n scrollToOffset(offset: number): void;\n}\n\n/**\n * Props of {@link List}.\n */\nexport interface ListProps {\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 * Number of items to be the margin from the end of the scroll. See also {@link onEndReached}.\n * @defaultValue 0\n */\n endThreshold?: number;\n /**\n * Inline style prop to override style of scrollable element.\n */\n style?: CSSProperties;\n /**\n * Customized element type for scrollable element.\n * @defaultValue {@link DefaultWindow}\n */\n element?: CustomWindowComponent;\n /**\n * Customized element type for item element.\n * @defaultValue \"div\"\n */\n itemElement?: CustomItemComponentOrElement;\n /**\n * Callback invoked when scrolling reached to the end. The margin from the end is specified by {@link endThreshold}.\n */\n onEndReached?: () => void;\n /**\n * Callback invoked whenever scroll offset changes.\n */\n onScroll?: (offset: number) => void;\n /**\n * Callback invoked when scrolling stops.\n */\n onScrollStop?: () => void;\n}\n\n/**\n * Virtualized list component. See {@link ListProps} and {@link ListHandle}.\n */\nexport const List = forwardRef<ListHandle, ListProps>(\n (\n {\n children,\n itemSize: itemSizeProp = 40,\n overscan = 4,\n horizontal: horizontalProp,\n rtl: rtlProp,\n endThreshold = 0,\n style: styleProp,\n element = DefaultWindow,\n itemElement = \"div\",\n onEndReached,\n onScroll: onScrollProp,\n onScrollStop: onScrollStopProp,\n },\n ref\n ): ReactElement => {\n // Memoize element array\n const elements = useMemo(() => {\n const arr: ReactNode[] = [];\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 onEndReachedCalledIndex = useRef<number>(INITIAL_END_REACHED_INDEX);\n const onScroll = useEvent(onScrollProp);\n const onScrollStop = useEvent(onScrollStopProp);\n\n const [mountedIndexes, reset] = useState<Set<number>>(new Set<number>());\n const [scrolling, setScrolling] = useState(false);\n const scroller = useStatic(() =>\n createScroller(store, onScroll, (isScrolling) => {\n setScrolling(isScrolling);\n if (!isScrolling) {\n reset(new Set());\n onScrollStop();\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 // Compensate scroll jump\n const scrollDirection = scroller._getScrollDirection();\n if (scrollDirection === SCROLL_UP) {\n const diff = jump.reduce((acc, [, j]) => acc + j, 0);\n if (diff) {\n scroller._updateScrollPosition(diff, true);\n }\n } else if (scrollDirection === SCROLL_MANUAL) {\n const isStartInView = startIndex === 0;\n const isEndInView = endIndex - (count - 1) === 0;\n const diff = jump.reduce((acc, [index, j]) => {\n if (index < startIndex) {\n // Keep start if scroll position is not stuck to the start\n if (!isStartInView) {\n acc += j;\n }\n } else {\n // Keep end if scroll position is stuck to the end\n if (!isStartInView && isEndInView) {\n acc += j;\n }\n }\n return acc;\n }, 0);\n if (diff) {\n scroller._updateScrollPosition(diff, true);\n }\n } else {\n // NOP\n }\n }, [jump]);\n\n useEffect(() => {\n if (!onEndReached) return;\n\n if (onEndReachedCalledIndex[refKey] > count) {\n // Probably items have been refreshed, so reset index\n onEndReachedCalledIndex[refKey] = INITIAL_END_REACHED_INDEX;\n }\n\n const endMargin = count - 1 - endIndex;\n if (\n endMargin <= endThreshold &&\n onEndReachedCalledIndex[refKey] < count\n ) {\n onEndReachedCalledIndex[refKey] = count;\n onEndReached();\n }\n }, [endIndex]);\n\n useImperativeHandle(\n ref,\n () => {\n return {\n get scrollOffset() {\n return scroller._getScrollPosition();\n },\n get scrollSize() {\n return scroller._getActualScrollSize();\n },\n scrollToIndex(index) {\n index = max(min(index, count - 1), 0);\n\n scroller._scrollTo(index, () => store._getItemOffset(index));\n },\n scrollToOffset(offset) {\n offset = max(offset, 0);\n\n scroller._scrollTo(\n store._getItemIndexForScrollTo(offset),\n () => offset\n );\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 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 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 _style={styleProp}\n _children={items}\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 _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 _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 VirtualStore,\n} from \"./store\";\nimport { abs, debounce, throttle, exists } 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 _getScrollPosition: () => number;\n _getScrollDirection: () => ScrollDirection;\n _getActualScrollSize: () => number;\n _updateScrollPosition: (offset: number, diff?: boolean) => void;\n _scrollTo: (index: number, getCurrentOffset: () => 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 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 _getScrollPosition() {\n if (!rootElement) return 0;\n return rootElement[scrollToKey];\n },\n _getScrollDirection() {\n return scrollDirection;\n },\n _getActualScrollSize: getActualScrollSize,\n _updateScrollPosition: updateScrollPosition,\n _scrollTo: scrollTo,\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","useEvent","handler","handlerRef","useCallback","args","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","display","visibility","DefaultWindow","forwardRef","scrollSize","scrolling","horizontal","rtl","jsx","width","height","minWidth","minHeight","pointerEvents","Window","_ref","_scrolling","_style","_getScrollSize","viewportSize","_getViewportSize","clampedScrollSize","overflow","contain","List","itemSizeProp","overscan","horizontalProp","rtlProp","endThreshold","styleProp","element","itemElement","onEndReached","onScroll","onScrollProp","onScrollStop","onScrollStopProp","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","computeTotalSize","_getItemCount","_getJump","_getItemIndexForScrollTo","_waitForScrollDestinationItemsMeasured","Promise","resolve","reject","then","undefined","add","delete","_update","type","payload","updated","filter","updatedJump","setItemSize","_width","_height","rootRef","onEndReachedCalledIndex","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","_initRoot","root","ro","syncViewportToScrollPosition","onScrollStopped","debounce","id","cancel","clearTimeout","debouncedFn","setTimeout","_cancel","isScrollStart","onWheel","throttle","time","n","ctrlKey","deltaX","deltaY","fn","observe","addEventListener","passive","disconnect","removeEventListener","el","set","unobserve","_getScrollPosition","_getScrollDirection","_getActualScrollSize","_updateScrollPosition","_scrollTo","async","getCurrentOffset","getOffset","isScrolling","count","reduce","acc","j","isStartInView","isEndInView","useImperativeHandle","scrollToIndex","scrollToOffset","startIndexWithMargin","endIndexWithMargin","items","res","key"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ErB6B,EAAS2K,EACPzK,EAAMwF,EAAyBvH,IAC/B,IAAMA,GAET,KAGL,CAAC6M,IAGH,MAAMS,EAAuBrP,EAAIgJ,EAAarC,EAAU,GAClD2I,EAAqBxP,EAAIoJ,EAAWvC,EAAUiI,EAAQ,GACtDW,EAAQ9K,EAAAA,SAAQ,KACpB,MAAM+K,EAAsB,GAC5B,IAAK,IAAI5O,EAAIyO,EAAsBzO,GAAK0O,EAAoB1O,IAE1D8J,EAAeb,IAAIjJ,GAerB,OAbA8J,EAAehD,SAAS9G,IACtB,MAAM+G,EAAIJ,EAAS3G,GACnB4O,EAAI3H,KACFtD,MAAChB,GAECI,EAAWC,EACXC,EAAQC,EACRC,EAAQnD,EACRoD,EAAUiD,EACVxD,EAAWkE,IALLA,aAAC,EAADA,EAAqC8H,MAAO7O,GAOrD,IAEI4O,CAAG,GACT,CAACjI,EAAUmD,EAAgB2E,EAAsBC,IAEpD,OACE/K,EAAAA,IAACwB,EAAM,CACLC,EAAMwE,EACN3G,EAAQC,EACRE,EAAUgD,EACVf,EAAYX,EACZY,EAAQa,EACRtD,EAAW8L,GACX"}
|
|
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 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 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,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A,IAACsB,EAAM,CACLC,EAAMwE,EACNzG,EAAQC,EACRE,EAAU0C,EACVX,EAAYT,EACZ7B,EAAW6L,EACXtJ,GACA"}
|
package/lib/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{jsx as e}from"react/jsx-runtime";import{useLayoutEffect as t,useEffect as r,useRef as n,
|
|
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,_=Math.max,d=Math.abs,h=Date.now,m=e=>null!=e,g=(e,t)=>Array.from({length:e},((e,r)=>t(r))),S=(e,t)=>{const r=e.t[t];return-1===r?e.o:r},p=(e,t,r)=>{if(!e.l)return 0;if(e.i>=t)return r?e.u[t]+S(e,t):e.u[t];let n=e.i,o=e.u[n];for(;n<=t&&(e.u[n]=o,n!==t||r);)o+=S(e,n),n++;return e.i=t,o},w=(e,t)=>p(e,t),v=(e,t,r)=>{let n=0;if(r>=0)for(;t<e.l-1;){const o=S(e,t++);if((n+=o)>=r){n-o/2>=r&&t--;break}}else for(;t>0;){const o=S(e,--t);if((n-=o)<=r){n+o/2<r&&t++;break}}return f(_(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,S:i})=>{const c=n(null),u=b(o.p,(()=>o.v(l))),a=b(o.p,(()=>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,S:o,k:l,j:i})=>{const c=b(n.p,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 P=s((()=>{const e=[];return i.forEach(t,(t=>{(e=>!m(e)||"boolean"==typeof e)(t)||e.push(t)})),e}),[t]),U=P.length,B=R((()=>((e,t,r,n)=>{let o,s=0,l=0,i=0,c=[],u=y(e,t),a=[0,0];const _=new Set,d=()=>r?s:l;return{C(){const[e,t]=a,r=w(u,e),n=z(u,i,e,r),o=x(u,n,d());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,d())),v:e=>w(u,e),F:()=>i,J:()=>d(),A:()=>(e=>p(e,e.l-1,!0))(u),P:()=>u.l,U:()=>c,R:()=>r,M:()=>n,B:e=>z(u,e,0,0),H:()=>(o&&o[1](),new Promise(((e,t)=>{o=[()=>{Promise.resolve().then((()=>{e(),o=void 0}))},t]}))),p:e=>(_.add(e),()=>{_.delete(e)}),L(e,r){(()=>{switch(e){case 0:return u.l!==r&&(u=y(r,t,u),!0);case 1:{const e=r.filter((([e,t])=>u.t[e]!==t));if(!e.length)return!1;const t=[];return e.forEach((([e,r])=>{t.push([e,r-S(u,e)]),((e,t,r)=>{e.t[t]=r,e.i=f(t,e.i)})(u,e,r)})),c=t,!0}case 2:return(s!==r.V||l!==r.W)&&(s=r.V,l=r.W,!0);case 3:{const e=i;return(i=r)!==e}}})()&&(_.forEach((e=>{e()})),o&&1===e&&o[0]())}}})(U,o,!!a,!!g))),[H,L]=b(B.p,B.C),V=b(B.p,B.U),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",S=new WeakMap,p=()=>s||(s=new ResizeObserver((t=>{const r=[];for(const n of t)if(n.target===o)e.L(2,{V:n.contentRect.width,W:n.contentRect.height});else{const e=S.get(n.target);m(e)&&r.push([e,n.contentRect[u?"width":"height"]])}r.length&&(e.L(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.L(3,n());try{await e.H()}catch(e){return}}while(e.D(t));v(n())}else{const t=n();v(t),e.L(3,t)}},x=e=>e.reduce(((e,[,t])=>e+t),0);return{q(n){o=n;const s=p(),f=()=>{let r=n[g];a&&(r=d(r)),l!==r&&(0!==i&&c?c=!1:3!==i&&(i=l>r?2:1),e.L(3,l=r),t(r))},_=(()=>{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})(),S=()=>{const e=0===i;f(),e&&r(!0),_()},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()&&_())})(...r))}})();return s.observe(n),n.addEventListener("scroll",S),n.addEventListener("wheel",w,{passive:!0}),()=>{s.disconnect(),n.removeEventListener("scroll",S),n.removeEventListener("wheel",w),_.G()}},T(e,t){const r=p();return S.set(e,t),r.observe(e),()=>{S.delete(e),r.unobserve(e)}},K:w,N(t){t=_(t,0),z(e.B(t),(()=>t))},X(t,r){t=_(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)}}}}}})(B,(e=>{q[T]&&q[T](e)}),(e=>{X(e),e||(N(new Set),G[T]&&G[T]())})))),Z=f(U,B.P());I((()=>{B.L(0,U)}),[U]),I((()=>Y.q(W[T])),[]),I((()=>{V.length&&Y.Y(V,H)}),[V]),r((()=>{D&&D({start:H,end:L,count:Z})}),[H,L]),u(J,(()=>({get scrollOffset(){return B.F()},get scrollSize(){return Y.K()},get viewportSize(){return B.J()},scrollToIndex(e){Y.X(e,Z)},scrollTo:Y.N,scrollBy(e){Y.N(B.F()+e)}})),[Z]);const $=_(H-l,0),ee=f(L+l,Z-1),te=s((()=>{const t=[];for(let e=$;e<=ee;e++)K.add(e);return K.forEach((r=>{const n=P[r];t.push(e(O,{h:Y,m:B,g:r,S:j,_:n},(null==n?void 0:n.key)||r))})),t}),[P,K,$,ee]);return e(E,{O:W,m:B,S:v,k:Q,_:te,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/useEvent.ts","../src/src/react/List.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 { useCallback, useRef } from \"react\";\n\nimport { useIsomorphicLayoutEffect } from \"./useIsomorphicLayoutEffect\";\nimport { refKey } from \"./utils\";\n\nexport const useEvent = <T extends (...args: any[]) => void>(\n handler: T | undefined\n) => {\n const handlerRef = useRef<T | undefined>(handler);\n\n useIsomorphicLayoutEffect(() => {\n handlerRef[refKey] = handler;\n });\n\n return useCallback((...args: Parameters<T>): void => {\n handlerRef[refKey] && handlerRef[refKey](...args);\n }, []);\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} 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 {\n createScroller,\n Scroller,\n SCROLL_MANUAL,\n SCROLL_UP,\n} from \"../core/scroller\";\nimport { refKey } from \"./utils\";\nimport { useStatic } from \"./useStatic\";\nimport { useEvent } from \"./useEvent\";\n\nconst INITIAL_END_REACHED_INDEX = -1;\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 // willChange: \"transform\",\n };\n if (isHorizontal) {\n style.display = \"flex\";\n }\n if (hide) {\n style.visibility = \"hidden\";\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 interface CustomWindowComponentProps {\n children: ReactNode;\n style: CSSProperties;\n scrollSize: number;\n scrolling: boolean;\n horizontal: boolean;\n rtl: boolean;\n}\n\nconst DefaultWindow = forwardRef<any, CustomWindowComponentProps>(\n (\n { children, style, scrollSize, scrolling, horizontal, rtl },\n ref\n ): ReactElement => {\n return (\n <div ref={ref} style={style}>\n <div\n style={useMemo((): CSSProperties => {\n const width = horizontal ? scrollSize : \"100%\";\n const height = horizontal ? \"100%\" : scrollSize;\n return {\n position: \"absolute\",\n top: 0,\n [rtl ? \"right\" : \"left\"]: 0,\n width,\n height,\n minWidth: width,\n minHeight: height,\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 _style: style,\n}: {\n _children: ReactNode;\n _ref: RefObject<HTMLDivElement>;\n _store: VirtualStore;\n _element: CustomWindowComponent;\n _scrolling: boolean;\n _style: CSSProperties | undefined;\n}) => {\n const scrollSize = useSyncExternalStore(\n store._subscribe,\n store._getScrollSize\n );\n const viewportSize = useSyncExternalStore(\n store._subscribe,\n store._getViewportSize\n );\n const clampedScrollSize =\n scrollSize >= viewportSize ? scrollSize : viewportSize;\n\n const horizontal = store._isHorizontal();\n return (\n <Element\n ref={ref}\n scrollSize={clampedScrollSize}\n scrolling={scrolling}\n horizontal={horizontal}\n rtl={store._isRtl()}\n style={useMemo(\n (): CSSProperties => ({\n overflow: horizontal ? \"auto hidden\" : \"hidden auto\",\n position: \"relative\",\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 ...style,\n }),\n [style]\n )}\n >\n {children}\n </Element>\n );\n};\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 List}.\n */\nexport interface ListHandle {\n /**\n * Get current scrollTop or scrollLeft.\n */\n scrollOffset: number;\n /**\n * Get current scrollHeight or scrollWidth.\n */\n scrollSize: 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 item specified by offset.\n * @param offset offset from start\n */\n scrollToOffset(offset: number): void;\n}\n\n/**\n * Props of {@link List}.\n */\nexport interface ListProps {\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 * Number of items to be the margin from the end of the scroll. See also {@link onEndReached}.\n * @defaultValue 0\n */\n endThreshold?: number;\n /**\n * Inline style prop to override style of scrollable element.\n */\n style?: CSSProperties;\n /**\n * Customized element type for scrollable element.\n * @defaultValue {@link DefaultWindow}\n */\n element?: CustomWindowComponent;\n /**\n * Customized element type for item element.\n * @defaultValue \"div\"\n */\n itemElement?: CustomItemComponentOrElement;\n /**\n * Callback invoked when scrolling reached to the end. The margin from the end is specified by {@link endThreshold}.\n */\n onEndReached?: () => void;\n /**\n * Callback invoked whenever scroll offset changes.\n */\n onScroll?: (offset: number) => void;\n /**\n * Callback invoked when scrolling stops.\n */\n onScrollStop?: () => void;\n}\n\n/**\n * Virtualized list component. See {@link ListProps} and {@link ListHandle}.\n */\nexport const List = forwardRef<ListHandle, ListProps>(\n (\n {\n children,\n itemSize: itemSizeProp = 40,\n overscan = 4,\n horizontal: horizontalProp,\n rtl: rtlProp,\n endThreshold = 0,\n style: styleProp,\n element = DefaultWindow,\n itemElement = \"div\",\n onEndReached,\n onScroll: onScrollProp,\n onScrollStop: onScrollStopProp,\n },\n ref\n ): ReactElement => {\n // Memoize element array\n const elements = useMemo(() => {\n const arr: ReactNode[] = [];\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 onEndReachedCalledIndex = useRef<number>(INITIAL_END_REACHED_INDEX);\n const onScroll = useEvent(onScrollProp);\n const onScrollStop = useEvent(onScrollStopProp);\n\n const [mountedIndexes, reset] = useState<Set<number>>(new Set<number>());\n const [scrolling, setScrolling] = useState(false);\n const scroller = useStatic(() =>\n createScroller(store, onScroll, (isScrolling) => {\n setScrolling(isScrolling);\n if (!isScrolling) {\n reset(new Set());\n onScrollStop();\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 // Compensate scroll jump\n const scrollDirection = scroller._getScrollDirection();\n if (scrollDirection === SCROLL_UP) {\n const diff = jump.reduce((acc, [, j]) => acc + j, 0);\n if (diff) {\n scroller._updateScrollPosition(diff, true);\n }\n } else if (scrollDirection === SCROLL_MANUAL) {\n const isStartInView = startIndex === 0;\n const isEndInView = endIndex - (count - 1) === 0;\n const diff = jump.reduce((acc, [index, j]) => {\n if (index < startIndex) {\n // Keep start if scroll position is not stuck to the start\n if (!isStartInView) {\n acc += j;\n }\n } else {\n // Keep end if scroll position is stuck to the end\n if (!isStartInView && isEndInView) {\n acc += j;\n }\n }\n return acc;\n }, 0);\n if (diff) {\n scroller._updateScrollPosition(diff, true);\n }\n } else {\n // NOP\n }\n }, [jump]);\n\n useEffect(() => {\n if (!onEndReached) return;\n\n if (onEndReachedCalledIndex[refKey] > count) {\n // Probably items have been refreshed, so reset index\n onEndReachedCalledIndex[refKey] = INITIAL_END_REACHED_INDEX;\n }\n\n const endMargin = count - 1 - endIndex;\n if (\n endMargin <= endThreshold &&\n onEndReachedCalledIndex[refKey] < count\n ) {\n onEndReachedCalledIndex[refKey] = count;\n onEndReached();\n }\n }, [endIndex]);\n\n useImperativeHandle(\n ref,\n () => {\n return {\n get scrollOffset() {\n return scroller._getScrollPosition();\n },\n get scrollSize() {\n return scroller._getActualScrollSize();\n },\n scrollToIndex(index) {\n index = max(min(index, count - 1), 0);\n\n scroller._scrollTo(index, () => store._getItemOffset(index));\n },\n scrollToOffset(offset) {\n offset = max(offset, 0);\n\n scroller._scrollTo(\n store._getItemIndexForScrollTo(offset),\n () => offset\n );\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 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 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 _style={styleProp}\n _children={items}\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 _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 _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 VirtualStore,\n} from \"./store\";\nimport { abs, debounce, throttle, exists } 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 _getScrollPosition: () => number;\n _getScrollDirection: () => ScrollDirection;\n _getActualScrollSize: () => number;\n _updateScrollPosition: (offset: number, diff?: boolean) => void;\n _scrollTo: (index: number, getCurrentOffset: () => 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 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 _getScrollPosition() {\n if (!rootElement) return 0;\n return rootElement[scrollToKey];\n },\n _getScrollDirection() {\n return scrollDirection;\n },\n _getActualScrollSize: getActualScrollSize,\n _updateScrollPosition: updateScrollPosition,\n _scrollTo: scrollTo,\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","useEvent","handler","handlerRef","useCallback","args","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","display","visibility","DefaultWindow","forwardRef","scrollSize","scrolling","horizontal","rtl","width","height","minWidth","minHeight","pointerEvents","Window","_ref","_scrolling","_style","_getScrollSize","viewportSize","_getViewportSize","clampedScrollSize","overflow","contain","List","itemSizeProp","overscan","horizontalProp","rtlProp","endThreshold","styleProp","element","itemElement","onEndReached","onScroll","onScrollProp","onScrollStop","onScrollStopProp","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","computeTotalSize","_getItemCount","_getJump","_getItemIndexForScrollTo","_waitForScrollDestinationItemsMeasured","Promise","resolve","reject","then","undefined","add","delete","_update","type","payload","updated","filter","updatedJump","setItemSize","_width","_height","rootRef","onEndReachedCalledIndex","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","_initRoot","root","ro","syncViewportToScrollPosition","onScrollStopped","debounce","id","cancel","clearTimeout","debouncedFn","setTimeout","_cancel","isScrollStart","onWheel","throttle","time","n","ctrlKey","deltaX","deltaY","fn","observe","addEventListener","passive","disconnect","removeEventListener","el","set","unobserve","_getScrollPosition","_getScrollDirection","_getActualScrollSize","_updateScrollPosition","_scrollTo","async","getCurrentOffset","getOffset","isScrolling","count","reduce","acc","j","isStartInView","isEndInView","useImperativeHandle","scrollToIndex","scrollToOffset","startIndexWithMargin","endIndexWithMargin","items","res","key"],"mappings":"qSAAO,MAA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GAAQ7K,GAAQ,KACpB,MAAM8K,EAAsB,GAC5B,IAAK,IAAI3O,EAAIwO,GAAsBxO,GAAKyO,GAAoBzO,IAE1D6J,EAAeb,IAAIhJ,GAerB,OAbA6J,EAAehD,SAAS7G,IACtB,MAAM8G,EAAIJ,EAAS1G,GACnB2O,EAAI3H,KACFrD,EAAChB,GAECI,EAAWC,EACXC,EAAQC,EACRC,EAAQnD,EACRoD,EAAUgD,EACVvD,EAAWiE,IALLA,aAAC,EAADA,EAAqC8H,MAAO5O,GAOrD,IAEI2O,CAAG,GACT,CAACjI,EAAUmD,EAAgB2E,GAAsBC,KAEpD,OACE9K,EAACuB,EAAM,CACLC,EAAMwE,EACN1G,EAAQC,EACRE,EAAU+C,EACVf,EAAYV,EACZW,EAAQa,EACRrD,EAAW6L,IACX"}
|
|
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 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 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,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,EAA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U,KACHqE,GAELA,EAAkB,CAChBwB,MAAOG,EACPF,IAAKI,EACL+F,SACA,GACD,CAACjG,EAAYE,IAEhBmG,EACE7L,GACA,KACS,CACD6E,mBACF,OAAOlE,EAAMgF,GACd,EACGzD,iBACF,OAAOzB,EAAS6K,GACjB,EACGnC,mBACF,OAAOxI,EAAMiF,GACd,EACDkG,cAAc/N,GACZ0C,EAAS+K,EAAezN,EAAO0N,EAChC,EACD1C,SAAUtI,EAAS8K,EACnBQ,SAAShN,GACP0B,EAAS8K,EAAU5K,EAAMgF,IAAqB5G,EAC/C,KAGL,CAAC0M,IAGH,MAAMO,EAAuBhP,EAAIwI,EAAatC,EAAU,GAClD+I,GAAqBnP,EAAI4I,EAAWxC,EAAUuI,EAAQ,GACtDS,GAAQ5K,GAAQ,KACpB,MAAM6K,EAAsB,GAC5B,IAAK,IAAIvO,EAAIoO,EAAsBpO,GAAKqO,GAAoBrO,IAE1DuJ,EAAeZ,IAAI3I,GAerB,OAbAuJ,EAAejD,SAAStG,IACtB,MAAMuG,EAAIJ,EAASnG,GACnBuO,EAAI9H,KACFjD,EAAChB,GAECI,EAAWC,EACXC,EAAQC,EACRC,EAAQhD,EACRiD,EAAU0C,EACVjD,EAAW6D,IALLA,aAAC,EAADA,EAAqCiI,MAAOxO,GAOrD,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,14 +1,20 @@
|
|
|
1
1
|
import { CSSProperties, ReactNode } from "react";
|
|
2
|
+
export type WindowComponentAttributes = Pick<React.HTMLAttributes<HTMLElement>, "className" | "style" | "id" | "role" | "tabIndex"> & React.AriaAttributes;
|
|
3
|
+
/**
|
|
4
|
+
* Props of customized scrollable component.
|
|
5
|
+
*/
|
|
2
6
|
export interface CustomWindowComponentProps {
|
|
3
7
|
children: ReactNode;
|
|
4
|
-
style: CSSProperties;
|
|
5
8
|
scrollSize: number;
|
|
6
9
|
scrolling: boolean;
|
|
7
10
|
horizontal: boolean;
|
|
8
|
-
|
|
11
|
+
attrs: WindowComponentAttributes;
|
|
9
12
|
}
|
|
10
13
|
declare const DefaultWindow: import("react").ForwardRefExoticComponent<CustomWindowComponentProps & import("react").RefAttributes<any>>;
|
|
11
14
|
export type CustomWindowComponent = typeof DefaultWindow;
|
|
15
|
+
/**
|
|
16
|
+
* Props of customized item component.
|
|
17
|
+
*/
|
|
12
18
|
export interface CustomItemComponentProps {
|
|
13
19
|
style: CSSProperties;
|
|
14
20
|
children: ReactNode;
|
|
@@ -16,32 +22,41 @@ export interface CustomItemComponentProps {
|
|
|
16
22
|
export type CustomItemComponent = React.ForwardRefExoticComponent<React.PropsWithoutRef<CustomItemComponentProps> & React.RefAttributes<any>>;
|
|
17
23
|
type CustomItemComponentOrElement = keyof JSX.IntrinsicElements | CustomItemComponent;
|
|
18
24
|
/**
|
|
19
|
-
* Methods of {@link
|
|
25
|
+
* Methods of {@link VList}.
|
|
20
26
|
*/
|
|
21
|
-
export interface
|
|
27
|
+
export interface VListHandle {
|
|
22
28
|
/**
|
|
23
29
|
* Get current scrollTop or scrollLeft.
|
|
24
30
|
*/
|
|
25
|
-
scrollOffset: number;
|
|
31
|
+
readonly scrollOffset: number;
|
|
26
32
|
/**
|
|
27
33
|
* Get current scrollHeight or scrollWidth.
|
|
28
34
|
*/
|
|
29
|
-
scrollSize: number;
|
|
35
|
+
readonly scrollSize: number;
|
|
36
|
+
/**
|
|
37
|
+
* Get current offsetHeight or offsetWidth.
|
|
38
|
+
*/
|
|
39
|
+
readonly viewportSize: number;
|
|
30
40
|
/**
|
|
31
41
|
* Scroll to the item specified by index.
|
|
32
42
|
* @param index index of item
|
|
33
43
|
*/
|
|
34
44
|
scrollToIndex(index: number): void;
|
|
35
45
|
/**
|
|
36
|
-
* Scroll to the
|
|
46
|
+
* Scroll to the given offset.
|
|
37
47
|
* @param offset offset from start
|
|
38
48
|
*/
|
|
39
|
-
|
|
49
|
+
scrollTo(offset: number): void;
|
|
50
|
+
/**
|
|
51
|
+
* Scroll by the given offset.
|
|
52
|
+
* @param offset offset from current position
|
|
53
|
+
*/
|
|
54
|
+
scrollBy(offset: number): void;
|
|
40
55
|
}
|
|
41
56
|
/**
|
|
42
|
-
* Props of {@link
|
|
57
|
+
* Props of {@link VList}.
|
|
43
58
|
*/
|
|
44
|
-
export interface
|
|
59
|
+
export interface VListProps extends WindowComponentAttributes {
|
|
45
60
|
/**
|
|
46
61
|
* Elements rendered by this component.
|
|
47
62
|
*/
|
|
@@ -65,39 +80,36 @@ export interface ListProps {
|
|
|
65
80
|
*/
|
|
66
81
|
rtl?: boolean;
|
|
67
82
|
/**
|
|
68
|
-
*
|
|
69
|
-
* @defaultValue 0
|
|
70
|
-
*/
|
|
71
|
-
endThreshold?: number;
|
|
72
|
-
/**
|
|
73
|
-
* Inline style prop to override style of scrollable element.
|
|
74
|
-
*/
|
|
75
|
-
style?: CSSProperties;
|
|
76
|
-
/**
|
|
77
|
-
* Customized element type for scrollable element.
|
|
83
|
+
* Customized element type for scrollable element. This element will get {@link CustomWindowComponentProps} as props.
|
|
78
84
|
* @defaultValue {@link DefaultWindow}
|
|
79
85
|
*/
|
|
80
86
|
element?: CustomWindowComponent;
|
|
81
87
|
/**
|
|
82
|
-
* Customized element type for item element.
|
|
88
|
+
* Customized element type for item element. This element will get {@link CustomItemComponentProps} as props.
|
|
83
89
|
* @defaultValue "div"
|
|
84
90
|
*/
|
|
85
91
|
itemElement?: CustomItemComponentOrElement;
|
|
86
|
-
/**
|
|
87
|
-
* Callback invoked when scrolling reached to the end. The margin from the end is specified by {@link endThreshold}.
|
|
88
|
-
*/
|
|
89
|
-
onEndReached?: () => void;
|
|
90
92
|
/**
|
|
91
93
|
* Callback invoked whenever scroll offset changes.
|
|
94
|
+
* @param offset Current scrollTop or scrollLeft.
|
|
92
95
|
*/
|
|
93
96
|
onScroll?: (offset: number) => void;
|
|
94
97
|
/**
|
|
95
98
|
* Callback invoked when scrolling stops.
|
|
96
99
|
*/
|
|
97
100
|
onScrollStop?: () => void;
|
|
101
|
+
/**
|
|
102
|
+
* Callback invoked when visible items range changes.
|
|
103
|
+
* @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.
|
|
104
|
+
*/
|
|
105
|
+
onRangeChange?: (payload: {
|
|
106
|
+
start: number;
|
|
107
|
+
end: number;
|
|
108
|
+
count: number;
|
|
109
|
+
}) => void;
|
|
98
110
|
}
|
|
99
111
|
/**
|
|
100
|
-
* Virtualized list component. See {@link
|
|
112
|
+
* Virtualized list component. See {@link VListProps} and {@link VListHandle}.
|
|
101
113
|
*/
|
|
102
|
-
export declare const
|
|
114
|
+
export declare const VList: import("react").ForwardRefExoticComponent<VListProps & import("react").RefAttributes<VListHandle>>;
|
|
103
115
|
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "virtua",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
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",
|
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
"storybook": "storybook dev -p 6006",
|
|
18
18
|
"storybook:build": "storybook build",
|
|
19
19
|
"storybook:test": "concurrently -k -s first -n \"SB,TEST\" -c \"magenta,blue\" \"npm run storybook -- --quiet --no-open\" \"wait-on tcp:6006 && test-storybook\"",
|
|
20
|
+
"e2e": "npx playwright test",
|
|
20
21
|
"typedoc": "typedoc",
|
|
21
22
|
"prepublishOnly": "npm run typedoc && rimraf lib && npm run build"
|
|
22
23
|
},
|
|
@@ -27,17 +28,18 @@
|
|
|
27
28
|
"@babel/plugin-transform-react-pure-annotations": "7.18.6",
|
|
28
29
|
"@dnd-kit/core": "6.0.8",
|
|
29
30
|
"@dnd-kit/sortable": "7.0.2",
|
|
30
|
-
"@emotion/react": "11.10.
|
|
31
|
-
"@emotion/styled": "11.10.
|
|
31
|
+
"@emotion/react": "11.10.8",
|
|
32
|
+
"@emotion/styled": "11.10.8",
|
|
32
33
|
"@faker-js/faker": "7.6.0",
|
|
33
34
|
"@mui/material": "5.11.15",
|
|
35
|
+
"@playwright/test": "^1.33.0",
|
|
34
36
|
"@rollup/plugin-babel": "6.0.3",
|
|
35
37
|
"@rollup/plugin-terser": "0.4.1",
|
|
36
38
|
"@rollup/plugin-typescript": "11.1.0",
|
|
37
39
|
"@storybook/addon-docs": "7.0.5",
|
|
38
40
|
"@storybook/react": "7.0.6",
|
|
39
41
|
"@storybook/react-vite": "^7.0.6",
|
|
40
|
-
"@storybook/test-runner": "0.10.0
|
|
42
|
+
"@storybook/test-runner": "0.10.0",
|
|
41
43
|
"@tanstack/react-virtual": "3.0.0-alpha.0",
|
|
42
44
|
"@testing-library/react": "14.0.0",
|
|
43
45
|
"@types/react": "18.0.32",
|
|
@@ -58,9 +60,9 @@
|
|
|
58
60
|
"react-is": "18.2.0",
|
|
59
61
|
"react-merge-refs": "2.0.1",
|
|
60
62
|
"react-select": "5.7.2",
|
|
61
|
-
"react-virtualized": "9.22.
|
|
63
|
+
"react-virtualized": "9.22.5",
|
|
62
64
|
"react-virtuoso": "4.2.0",
|
|
63
|
-
"react-window": "1.8.
|
|
65
|
+
"react-window": "1.8.9",
|
|
64
66
|
"rimraf": "3.0.2",
|
|
65
67
|
"rollup": "3.20.2",
|
|
66
68
|
"storybook": "^7.0.6",
|
|
@@ -68,7 +70,8 @@
|
|
|
68
70
|
"typedoc": "0.23.28",
|
|
69
71
|
"typedoc-plugin-markdown": "3.14.0",
|
|
70
72
|
"typescript": "5.0.4",
|
|
71
|
-
"
|
|
73
|
+
"virtua": "^0.1.12",
|
|
74
|
+
"vite": "4.3.3",
|
|
72
75
|
"wait-on": "6.0.1"
|
|
73
76
|
},
|
|
74
77
|
"peerDependencies": {
|
package/lib/react/useEvent.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const useEvent: <T extends (...args: any[]) => void>(handler: T | undefined) => (...args: Parameters<T>) => void;
|