react-anchorlist 0.2.5 → 0.3.1

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/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
- import { jsx as B, jsxs as Q } from "react/jsx-runtime";
2
- import * as X from "react";
3
- import { useCallback as M, useRef as T, useState as _, useEffect as j, useLayoutEffect as $, forwardRef as te, useImperativeHandle as re } from "react";
4
- class ne {
1
+ import { jsx as W, jsxs as le } from "react/jsx-runtime";
2
+ import * as te from "react";
3
+ import { useRef as g, useCallback as C, useState as U, useEffect as X, useLayoutEffect as Q, forwardRef as me, useImperativeHandle as de } from "react";
4
+ class ge {
5
5
  constructor(e, t) {
6
6
  this.defaultSize = t, this.sizes = e > 0 ? Array(e).fill(t) : [], this.offsets = e > 0 ? Array(e).fill(0) : [], e > 0 && this._recalcFrom(0);
7
7
  }
@@ -25,7 +25,7 @@ class ne {
25
25
  }
26
26
  append(e) {
27
27
  const t = this.sizes.length;
28
- for (let s = 0; s < e; s++)
28
+ for (let n = 0; n < e; n++)
29
29
  this.sizes.push(this.defaultSize), this.offsets.push(0);
30
30
  this._recalcFrom(t);
31
31
  }
@@ -48,7 +48,7 @@ class ne {
48
48
  return this.sizes;
49
49
  }
50
50
  }
51
- class se {
51
+ class pe {
52
52
  constructor() {
53
53
  this.cache = /* @__PURE__ */ new Map();
54
54
  }
@@ -69,334 +69,452 @@ class se {
69
69
  }
70
70
  /** Re-applies all cached sizes to the OffsetMap using a key→index map */
71
71
  applyToOffsetMap(e, t) {
72
- for (const [s, o] of this.cache) {
73
- const c = t.get(s);
74
- c !== void 0 && e.setSize(c, o);
72
+ for (const [n, c] of this.cache) {
73
+ const o = t.get(n);
74
+ o !== void 0 && e.setSize(o, c);
75
75
  }
76
76
  }
77
77
  }
78
78
  function ce(a, e) {
79
79
  if (a.length === 0) return 0;
80
- let t = 0, s = a.length - 1;
81
- for (; t < s; ) {
82
- const o = t + s >> 1;
83
- (a[o] ?? 0) < e ? t = o + 1 : s = o;
80
+ let t = 0, n = a.length - 1;
81
+ for (; t < n; ) {
82
+ const c = t + n >> 1;
83
+ (a[c] ?? 0) < e ? t = c + 1 : n = c;
84
84
  }
85
85
  return Math.max(0, t > 0 && (a[t] ?? 0) > e ? t - 1 : t);
86
86
  }
87
- function oe(a, e, t) {
87
+ function ve(a, e, t) {
88
88
  if (a.length === 0) return 0;
89
- for (let s = a.length - 1; s >= 0; s--)
90
- if ((a[s] ?? 0) < t) return s;
91
- return 0;
89
+ let n = 0, c = a.length - 1, o = 0;
90
+ for (; n <= c; ) {
91
+ const r = n + c >> 1;
92
+ (a[r] ?? 0) < t ? (o = r, n = r + 1) : c = r - 1;
93
+ }
94
+ return o;
92
95
  }
93
- function ie(a) {
94
- const { firstVisible: e, lastVisible: t, itemCount: s, overscan: o } = a;
95
- return s === 0 ? { start: 0, end: -1 } : {
96
- start: Math.max(0, e - o),
97
- end: Math.min(s - 1, t + o)
96
+ function Te(a) {
97
+ const { firstVisible: e, lastVisible: t, itemCount: n, overscan: c } = a;
98
+ return n === 0 ? { start: 0, end: -1 } : {
99
+ start: Math.max(0, e - c),
100
+ end: Math.min(n - 1, t + c)
98
101
  };
99
102
  }
100
- function le(a, e, t) {
101
- return M(
102
- (s, o) => {
103
- var E;
104
- const c = a.current, r = e.current;
105
- if (!c || !r) return;
106
- let m, u;
107
- if (typeof s == "object" && s !== null ? (m = s.index, u = {
108
- align: s.align,
109
- behavior: s.behavior,
110
- offset: s.offset
111
- }) : (m = s, u = o), !Number.isFinite(m)) return;
112
- const h = Math.max(0, Math.min(Math.floor(m), r.count - 1)), d = ((E = t == null ? void 0 : t.current) == null ? void 0 : E.offsetTop) ?? 0, y = r.getOffset(h), S = r.getSize(h), x = (u == null ? void 0 : u.align) ?? "start", f = (u == null ? void 0 : u.behavior) ?? "auto", F = (u == null ? void 0 : u.offset) ?? 0;
113
- let z;
114
- x === "start" ? z = d + y + F : x === "center" ? z = d + y - c.clientHeight / 2 + S / 2 + F : z = d + y - c.clientHeight + S + F, c.scrollTo({ top: Math.max(0, z), behavior: f });
103
+ function ye(a, e, t, n) {
104
+ const c = n == null ? void 0 : n.reconcile, o = g(null);
105
+ return C(
106
+ (r, S) => {
107
+ const l = a.current, f = e.current;
108
+ if (!l || !f) return;
109
+ o.current !== null && (cancelAnimationFrame(o.current), o.current = null);
110
+ let y, u;
111
+ if (typeof r == "object" && r !== null ? (y = r.index, u = {
112
+ align: r.align,
113
+ behavior: r.behavior,
114
+ offset: r.offset
115
+ }) : (y = r, u = S), !Number.isFinite(y)) return;
116
+ const m = Math.max(0, Math.min(Math.floor(y), f.count - 1));
117
+ f.getOffset(m), f.getSize(m);
118
+ const b = (u == null ? void 0 : u.align) ?? "start", A = (u == null ? void 0 : u.behavior) ?? "auto", K = (u == null ? void 0 : u.offset) ?? 0, h = () => {
119
+ var p;
120
+ const H = e.current, i = a.current;
121
+ if (!H || !i) return 0;
122
+ const d = ((p = t == null ? void 0 : t.current) == null ? void 0 : p.offsetTop) ?? 0, R = H.getOffset(m), w = H.getSize(m);
123
+ return b === "start" ? d + R + K : b === "center" ? d + R - i.clientHeight / 2 + w / 2 + K : d + R - i.clientHeight + w + K;
124
+ }, E = h();
125
+ ((H, i) => {
126
+ typeof l.scrollTo == "function" ? l.scrollTo({ top: H, behavior: i }) : l.scrollTop = H;
127
+ })(Math.max(0, E), A);
128
+ const M = performance.now();
129
+ let z = 0;
130
+ const L = 12, q = 300, V = 1, k = () => {
131
+ o.current = null;
132
+ const H = a.current;
133
+ if (!H) return;
134
+ const i = Math.max(0, h()), d = Math.abs(H.scrollTop - i), R = performance.now() - M >= q, w = z >= L;
135
+ d <= V || R || w || (typeof H.scrollTo == "function" ? H.scrollTo({ top: i, behavior: "auto" }) : H.scrollTop = i, z += 1, o.current = requestAnimationFrame(k));
136
+ };
137
+ o.current = requestAnimationFrame(k);
115
138
  },
116
- [a, e, t]
139
+ [a, e, t, c]
117
140
  );
118
141
  }
119
- function W(a) {
120
- var Y;
121
- const { items: e, getKey: t, estimatedItemSize: s, overscan: o, initialAlignment: c } = a, r = T(null), m = T(null), u = T(null), h = T(new se()), d = T([]), y = T(!1), S = T(0), x = T(0), f = T(null), F = T(!1), z = T(null), [, E] = _(0), p = M(() => E((n) => n + 1), []);
122
- u.current || (u.current = new ne(e.length, s));
123
- const w = T(e.length);
124
- if (e.length !== w.current || e.some((n, v) => {
125
- const I = t(n, v);
126
- return d.current[v] !== I;
127
- })) {
128
- const n = u.current, v = e.map((U, O) => t(U, O)), I = d.current, R = I.length, K = v.length;
129
- K === 0 ? n.resize(0) : R === 0 ? n.resize(K) : K > R ? I.length > 0 && v[K - R] === I[0] ? n.prepend(K - R) : n.resize(K) : K < R && n.resize(K);
130
- const P = /* @__PURE__ */ new Map();
131
- v.forEach((U, O) => P.set(U, O)), h.current.applyToOffsetMap(n, P), d.current = v, w.current = e.length;
142
+ function ie(a) {
143
+ var se;
144
+ const { items: e, getKey: t, estimatedItemSize: n, overscan: c, initialAlignment: o } = a, r = g(null), S = g(null), l = g(null), f = g(new pe()), y = g([]), u = g(/* @__PURE__ */ new Map()), m = g(e.length), b = g(null), A = g(null), K = g(!1), h = g(0), E = g(0), T = g(null), M = g(!1), z = g(null), L = g(0), q = g(0), V = g(0), k = g(null), H = g(!1), [, i] = U(0), d = C(() => i((s) => s + 1), []);
145
+ l.current || (l.current = new ge(e.length, n));
146
+ const R = e.length > 0 ? t(e[0], 0) : null, w = e.length > 0 ? t(e[e.length - 1], e.length - 1) : null;
147
+ if (e.length !== m.current || R !== b.current || w !== A.current) {
148
+ const s = l.current, v = e.map((j, _) => t(j, _)), x = y.current, I = x.length, P = v.length;
149
+ if (P === 0)
150
+ s.resize(0);
151
+ else if (I === 0)
152
+ s.resize(P);
153
+ else if (P > I) {
154
+ const j = P - I;
155
+ x.length > 0 && j >= 0 && v[j] === x[0] ? s.prepend(j) : s.resize(P);
156
+ } else P < I, s.resize(P);
157
+ const F = /* @__PURE__ */ new Map();
158
+ v.forEach((j, _) => F.set(j, _)), u.current = F, f.current.applyToOffsetMap(s, F), y.current = v, m.current = e.length, b.current = R, A.current = w;
132
159
  }
133
- j(() => {
134
- const n = r.current;
135
- if (!n) return;
160
+ const B = C(() => {
161
+ k.current === null && (k.current = requestAnimationFrame(() => {
162
+ k.current = null;
163
+ const s = r.current;
164
+ if (!s) return;
165
+ const v = L.current;
166
+ Math.abs(v) < 0.01 || (L.current = 0, q.current += v, V.current += v, s.scrollTop += v, h.current = s.scrollTop, H.current = !0, d());
167
+ }));
168
+ }, [d]);
169
+ X(() => {
170
+ const s = r.current;
171
+ if (!s) return;
136
172
  const v = () => {
137
- f.current === null && (f.current = requestAnimationFrame(() => {
138
- f.current = null, S.current = n.scrollTop, x.current = n.clientHeight, p();
173
+ T.current === null && (T.current = requestAnimationFrame(() => {
174
+ T.current = null, h.current = s.scrollTop, E.current = s.clientHeight, H.current && (H.current = !1, q.current = 0, V.current = 0), d();
139
175
  }));
140
176
  };
141
- return n.addEventListener("scroll", v, { passive: !0 }), () => {
142
- n.removeEventListener("scroll", v), f.current !== null && (cancelAnimationFrame(f.current), f.current = null);
177
+ return s.addEventListener("scroll", v, { passive: !0 }), () => {
178
+ s.removeEventListener("scroll", v), T.current !== null && (cancelAnimationFrame(T.current), T.current = null), k.current !== null && (cancelAnimationFrame(k.current), k.current = null);
143
179
  };
144
- }, [p]), j(() => {
145
- const n = r.current;
146
- if (!n) return;
147
- x.current = n.clientHeight, S.current = n.scrollTop;
148
- const v = new ResizeObserver(([I]) => {
149
- I && (x.current = I.contentRect.height, p());
180
+ }, [d]), X(() => {
181
+ const s = r.current;
182
+ if (!s) return;
183
+ E.current = s.clientHeight, h.current = s.scrollTop;
184
+ const v = new ResizeObserver(([x]) => {
185
+ x && (E.current = x.contentRect.height, d());
150
186
  });
151
- return v.observe(n), () => v.disconnect();
152
- }, [p]), $(() => {
153
- if (y.current || e.length === 0) return;
154
- const n = r.current;
155
- if (n) {
156
- if (c === "bottom") {
157
- n.scrollTop = n.scrollHeight, S.current = n.scrollTop, x.current = n.clientHeight, F.current = !0, z.current !== null && cancelAnimationFrame(z.current);
158
- let v = 0;
159
- const I = 30, R = () => {
160
- if (!F.current || v >= I) {
161
- F.current = !1, z.current = null;
187
+ return v.observe(s), () => v.disconnect();
188
+ }, [d]), Q(() => {
189
+ if (K.current || e.length === 0) return;
190
+ const s = r.current;
191
+ if (s) {
192
+ if (o === "bottom") {
193
+ s.scrollTop = s.scrollHeight, h.current = s.scrollTop, E.current = s.clientHeight, M.current = !0, z.current !== null && cancelAnimationFrame(z.current);
194
+ const v = performance.now();
195
+ let x = 0, I = s.scrollHeight;
196
+ const P = () => {
197
+ if (!M.current) {
198
+ z.current = null;
199
+ return;
200
+ }
201
+ const F = s.scrollHeight, j = Math.abs(F - I);
202
+ I = F, j < 1 ? x += 1 : x = 0, s.scrollTop = s.scrollHeight, h.current = s.scrollTop;
203
+ const _ = performance.now() - v;
204
+ if (x >= 3 || _ >= 500) {
205
+ M.current = !1, z.current = null;
162
206
  return;
163
207
  }
164
- v++, n.scrollTop = n.scrollHeight, S.current = n.scrollTop, z.current = requestAnimationFrame(R);
208
+ z.current = requestAnimationFrame(P);
165
209
  };
166
- z.current = requestAnimationFrame(R);
210
+ z.current = requestAnimationFrame(P);
167
211
  }
168
- y.current = !0;
212
+ K.current = !0;
169
213
  }
170
- }, [c, e.length]), j(() => {
171
- e.length === 0 && (y.current = !1, F.current = !1, z.current !== null && (cancelAnimationFrame(z.current), z.current = null));
214
+ }, [o, e.length]), X(() => {
215
+ e.length === 0 && (K.current = !1, M.current = !1, z.current !== null && (cancelAnimationFrame(z.current), z.current = null));
172
216
  }, [e.length]);
173
- const C = M((n, v) => {
174
- var O;
175
- const I = u.current;
176
- if (!I || h.current.get(n) === v) return;
177
- h.current.set(n, v);
178
- const K = d.current.indexOf(n);
179
- if (K === -1) return;
180
- const P = r.current;
181
- if (P && !F.current) {
182
- const G = I.getSize(K), J = v - G, ee = I.getOffset(K) + G + (((O = m.current) == null ? void 0 : O.offsetTop) ?? 0);
183
- J !== 0 && ee < P.scrollTop && (P.scrollTop += J, S.current = P.scrollTop);
184
- }
185
- I.setSize(K, v) && p();
186
- }, [p]), V = M(
187
- (n, v = "auto") => {
188
- var I;
189
- (I = r.current) == null || I.scrollTo({ top: n, behavior: v });
217
+ const N = C((s, v) => {
218
+ var oe;
219
+ const x = l.current;
220
+ if (!x || f.current.get(s) === v) return;
221
+ f.current.set(s, v);
222
+ const P = u.current.get(s);
223
+ if (P === void 0) return;
224
+ const F = x.getSize(P), j = v - F, _ = r.current;
225
+ _ && !M.current && j !== 0 && x.getOffset(P) + F + (((oe = S.current) == null ? void 0 : oe.offsetTop) ?? 0) < _.scrollTop && (L.current += j, B()), x.setSize(P, v) && d();
226
+ }, [B, d]), D = C(
227
+ (s, v = "auto") => {
228
+ var x;
229
+ (x = r.current) == null || x.scrollTo({ top: s, behavior: v });
230
+ },
231
+ []
232
+ ), $ = ye(r, l, S, {
233
+ reconcile: !0
234
+ }), G = C(() => {
235
+ var _;
236
+ const s = r.current, v = l.current;
237
+ if (!s || !v || v.count === 0) return null;
238
+ const x = ((_ = S.current) == null ? void 0 : _.offsetTop) ?? 0, I = Math.max(0, s.scrollTop - x), P = v.getOffsets(), F = ce(P, I);
239
+ return {
240
+ key: y.current[F] ?? null,
241
+ offsetWithinItem: I - v.getOffset(F),
242
+ scrollTop: s.scrollTop,
243
+ scrollHeight: s.scrollHeight
244
+ };
245
+ }, []), J = C(
246
+ (s, v) => {
247
+ var F;
248
+ const x = l.current;
249
+ if (!x) return null;
250
+ const I = u.current.get(s);
251
+ return I === void 0 ? null : (((F = S.current) == null ? void 0 : F.offsetTop) ?? 0) + x.getOffset(I) + v;
190
252
  },
191
253
  []
192
- ), N = le(r, u, m), H = u.current, q = H ? H.totalSize() : 0, l = r.current, i = (l == null ? void 0 : l.scrollTop) ?? S.current, g = (l == null ? void 0 : l.clientHeight) ?? x.current, A = ((Y = m.current) == null ? void 0 : Y.offsetTop) ?? 0, L = Math.max(0, i - A);
193
- let k = [];
194
- if (H && H.count > 0 && g > 0) {
195
- const n = H.getOffsets(), v = H.getSizes(), I = ce(n, L), R = oe(
196
- n,
254
+ ), O = l.current, ae = O ? O.totalSize() : 0, Y = r.current, Z = (Y == null ? void 0 : Y.scrollTop) ?? h.current, re = (Y == null ? void 0 : Y.clientHeight) ?? E.current, fe = ((se = S.current) == null ? void 0 : se.offsetTop) ?? 0, ne = Math.max(0, Z - fe), ee = [];
255
+ if (O && O.count > 0 && re > 0) {
256
+ const s = O.getOffsets(), v = O.getSizes(), x = ce(s, ne), I = ve(
257
+ s,
197
258
  v,
198
- L + g
199
- ), K = ie({
200
- firstVisible: I,
201
- lastVisible: R,
202
- itemCount: H.count,
203
- overscan: o
259
+ ne + re
260
+ ), P = Te({
261
+ firstVisible: x,
262
+ lastVisible: I,
263
+ itemCount: O.count,
264
+ overscan: c
204
265
  });
205
- for (let P = K.start; P <= K.end && P < e.length; P++)
206
- k.push({
207
- key: d.current[P] ?? t(e[P], P),
208
- index: P,
209
- start: H.getOffset(P),
210
- size: H.getSize(P),
211
- data: e[P]
266
+ for (let F = P.start; F <= P.end && F < e.length; F++)
267
+ ee.push({
268
+ key: y.current[F] ?? t(e[F], F),
269
+ index: F,
270
+ start: O.getOffset(F),
271
+ size: O.getSize(F),
272
+ data: e[F]
212
273
  });
213
- } else if (H && H.count > 0) {
214
- const n = Math.min(e.length, o * 2 + 1), v = c === "bottom" ? Math.max(0, e.length - n) : 0, I = v + n - 1;
215
- for (let R = v; R <= I; R++)
216
- k.push({
217
- key: d.current[R] ?? t(e[R], R),
218
- index: R,
219
- start: H.getOffset(R),
220
- size: H.getSize(R),
221
- data: e[R]
274
+ } else if (O && O.count > 0) {
275
+ const s = Math.min(e.length, c * 2 + 1), v = o === "bottom" ? Math.max(0, e.length - s) : 0, x = v + s - 1;
276
+ for (let I = v; I <= x; I++)
277
+ ee.push({
278
+ key: y.current[I] ?? t(e[I], I),
279
+ index: I,
280
+ start: O.getOffset(I),
281
+ size: O.getSize(I),
282
+ data: e[I]
222
283
  });
223
284
  }
224
- const D = l ? l.scrollHeight - l.scrollTop - l.clientHeight : 1 / 0;
285
+ const he = Y ? Y.scrollHeight - Y.scrollTop - Y.clientHeight : 1 / 0;
225
286
  return {
226
287
  scrollerRef: r,
227
- innerRef: m,
228
- virtualItems: k,
229
- totalSize: q,
230
- measureItem: C,
231
- scrollToIndex: N,
232
- scrollToOffset: V,
233
- isAtTop: i <= 1,
234
- isAtBottom: D <= 1,
235
- scrollTop: i
288
+ innerRef: S,
289
+ virtualItems: ee,
290
+ totalSize: ae,
291
+ measureItem: N,
292
+ scrollToIndex: $,
293
+ scrollToOffset: D,
294
+ captureAnchorSnapshot: G,
295
+ resolveAnchorTop: J,
296
+ isAtTop: Z <= 1,
297
+ isAtBottom: he <= 1,
298
+ scrollTop: Z
236
299
  };
237
300
  }
238
- function ae(a, e, t) {
239
- const s = T(0), o = T(0), c = T(!1), r = T({
301
+ function ze(a) {
302
+ const {
303
+ scrollerRef: e,
304
+ itemCount: t,
305
+ captureAnchorSnapshot: n,
306
+ resolveAnchorTop: c,
307
+ onRestored: o
308
+ } = a, r = g(null), S = g(!1), l = g({
240
309
  first: null,
241
310
  second: null,
242
311
  timeout: null
243
- }), m = M(() => {
244
- const { first: h, second: d, timeout: y } = r.current;
245
- h && cancelAnimationFrame(h), d && cancelAnimationFrame(d), y && clearTimeout(y), r.current = { first: null, second: null, timeout: null };
246
- }, []), u = M(() => {
247
- const h = a.current;
248
- h && (s.current = h.scrollTop, o.current = h.scrollHeight, c.current = !0);
249
- }, [a]);
250
- return $(() => {
251
- if (!c.current) return;
252
- const h = a.current;
253
- if (!h) return;
254
- c.current = !1;
255
- const d = () => {
256
- const y = s.current + (h.scrollHeight - o.current);
257
- Number.isFinite(y) && Math.abs(h.scrollTop - y) > 1 && (h.scrollTop = y);
312
+ }), f = C(() => {
313
+ const { first: u, second: m, timeout: b } = l.current;
314
+ u && cancelAnimationFrame(u), m && cancelAnimationFrame(m), b && clearTimeout(b), l.current = { first: null, second: null, timeout: null };
315
+ }, []), y = C(() => {
316
+ const u = e.current;
317
+ if (!u) return;
318
+ const m = n();
319
+ r.current = m ?? {
320
+ key: null,
321
+ offsetWithinItem: 0,
322
+ scrollTop: u.scrollTop,
323
+ scrollHeight: u.scrollHeight
324
+ }, S.current = !0;
325
+ }, [e, n]);
326
+ return Q(() => {
327
+ if (!S.current) return;
328
+ const u = e.current, m = r.current;
329
+ if (!u || !m) return;
330
+ S.current = !1;
331
+ const b = () => {
332
+ let A = null;
333
+ m.key !== null && (A = c(m.key, m.offsetWithinItem)), A === null && (A = m.scrollTop + (u.scrollHeight - m.scrollHeight)), Number.isFinite(A) && Math.abs(u.scrollTop - A) > 1 && (u.scrollTop = A);
258
334
  };
259
- return m(), d(), t == null || t(), r.current.first = requestAnimationFrame(() => {
260
- r.current.first = null, d(), r.current.second = requestAnimationFrame(() => {
261
- r.current.second = null, d();
335
+ return f(), b(), o == null || o(), l.current.first = requestAnimationFrame(() => {
336
+ l.current.first = null, b(), l.current.second = requestAnimationFrame(() => {
337
+ l.current.second = null, b();
262
338
  });
263
- }), r.current.timeout = setTimeout(() => {
264
- r.current.timeout = null, d();
265
- }, 90), () => m();
266
- }, [e, a, m, t]), { prepareAnchor: u };
339
+ }), l.current.timeout = setTimeout(() => {
340
+ l.current.timeout = null, b();
341
+ }, 90), () => f();
342
+ }, [t, e, c, f, o]), { prepareAnchor: y };
267
343
  }
268
- function ue(a, e) {
269
- const [t, s] = _(!0), o = T(null);
270
- return j(() => {
271
- const c = a.current;
272
- if (!c) return;
273
- const r = () => {
274
- const u = c.scrollHeight - c.scrollTop - c.clientHeight;
275
- s(u <= e);
276
- }, m = () => {
277
- o.current !== null && cancelAnimationFrame(o.current), o.current = requestAnimationFrame(r);
344
+ function Se(a) {
345
+ const { previous: e, distanceFromBottom: t, threshold: n, hysteresis: c } = a;
346
+ if (!c) return t <= n;
347
+ const o = Math.max(0, c.enter), r = Math.max(o, c.leave);
348
+ return e ? t <= r : t <= o;
349
+ }
350
+ function Ae(a, e) {
351
+ const t = typeof e == "number" ? e : e.threshold ?? 200, n = typeof e == "number" ? void 0 : e.hysteresis, [c, o] = U(!0), r = g(null), S = g(!0);
352
+ return X(() => {
353
+ const l = a.current;
354
+ if (!l) return;
355
+ const f = () => {
356
+ const u = l.scrollHeight - l.scrollTop - l.clientHeight, m = Se({
357
+ previous: S.current,
358
+ distanceFromBottom: u,
359
+ threshold: t,
360
+ hysteresis: n
361
+ });
362
+ S.current = m, o(m);
363
+ }, y = () => {
364
+ r.current !== null && cancelAnimationFrame(r.current), r.current = requestAnimationFrame(f);
278
365
  };
279
- return c.addEventListener("scroll", m, { passive: !0 }), r(), () => {
280
- c.removeEventListener("scroll", m), o.current !== null && cancelAnimationFrame(o.current);
366
+ return l.addEventListener("scroll", y, { passive: !0 }), f(), () => {
367
+ l.removeEventListener("scroll", y), r.current !== null && cancelAnimationFrame(r.current);
281
368
  };
282
- }, [a, e]), t;
369
+ }, [a, t, n == null ? void 0 : n.enter, n == null ? void 0 : n.leave]), c;
283
370
  }
284
- function fe(a) {
285
- const { itemCount: e, firstKey: t, lastKey: s, isAtBottom: o, scrollToIndex: c, mode: r } = a, m = T(e), u = T(t), h = T(s);
286
- $(() => {
371
+ function Re(a) {
372
+ const { itemCount: e, firstKey: t, lastKey: n, isAtBottom: c, scrollToIndex: o, mode: r } = a, S = g(e), l = g(t), f = g(n);
373
+ Q(() => {
287
374
  if (!r) {
288
- m.current = e, u.current = t, h.current = s;
375
+ S.current = e, l.current = t, f.current = n;
289
376
  return;
290
377
  }
291
- const d = m.current, y = u.current, S = h.current;
292
- e > d && t === y && s !== S && o && e > 0 && c(e - 1, {
378
+ const y = S.current, u = l.current, m = f.current;
379
+ e > y && t === u && n !== m && c && e > 0 && o(e - 1, {
293
380
  align: "end",
294
381
  behavior: r === "smooth" ? "smooth" : "auto"
295
- }), m.current = e, u.current = t, h.current = s;
296
- }, [e, t, s, o, c, r]);
382
+ }), S.current = e, l.current = t, f.current = n;
383
+ }, [e, t, n, c, o, r]);
297
384
  }
298
- function he(a) {
385
+ function xe(a) {
299
386
  const {
300
387
  items: e,
301
388
  getKey: t,
302
- estimatedItemSize: s = 80,
303
- overscan: o = 20,
304
- atBottomThreshold: c = 200,
305
- followOutput: r = "auto",
306
- initialAlignment: m = "bottom",
307
- onStartReached: u,
308
- onEndReached: h,
309
- startReachedThreshold: d = 300,
310
- endReachedThreshold: y = 300,
311
- scrollToMessageKey: S,
312
- onScrollToMessageComplete: x
313
- } = a, f = W({
389
+ estimatedItemSize: n = 80,
390
+ overscan: c = 20,
391
+ atBottomThreshold: o = 200,
392
+ atBottomHysteresis: r,
393
+ followOutput: S = "auto",
394
+ initialAlignment: l = "bottom",
395
+ scrollModifier: f = null,
396
+ onStartReached: y,
397
+ onEndReached: u,
398
+ startReachedThreshold: m = 300,
399
+ endReachedThreshold: b = 300,
400
+ scrollToMessageKey: A,
401
+ onScrollToMessageComplete: K
402
+ } = a, h = ie({
314
403
  items: e,
315
404
  getKey: t,
316
- estimatedItemSize: s,
317
- overscan: o,
318
- initialAlignment: m
319
- }), F = ue(f.scrollerRef, c), [, z] = _(0), E = M(() => z((i) => i + 1), []), { prepareAnchor: p } = ae(f.scrollerRef, e.length, E), w = e.length > 0 ? t(e[0], 0) : null, b = e.length > 0 ? t(e[e.length - 1], e.length - 1) : null;
320
- fe({
405
+ estimatedItemSize: n,
406
+ overscan: c,
407
+ initialAlignment: l
408
+ }), E = Ae(h.scrollerRef, {
409
+ threshold: o,
410
+ hysteresis: r ?? { enter: 80, leave: 160 }
411
+ }), [, T] = U(0), M = C(() => T((p) => p + 1), []), { prepareAnchor: z } = ze({
412
+ scrollerRef: h.scrollerRef,
321
413
  itemCount: e.length,
322
- firstKey: w,
323
- lastKey: b,
324
- isAtBottom: F,
325
- scrollToIndex: f.scrollToIndex,
326
- mode: r ?? !1
414
+ captureAnchorSnapshot: h.captureAnchorSnapshot,
415
+ resolveAnchorTop: h.resolveAnchorTop,
416
+ onRestored: M
417
+ }), L = e.length > 0 ? t(e[0], 0) : null, q = e.length > 0 ? t(e[e.length - 1], e.length - 1) : null;
418
+ Re({
419
+ itemCount: e.length,
420
+ firstKey: L,
421
+ lastKey: q,
422
+ isAtBottom: E,
423
+ scrollToIndex: h.scrollToIndex,
424
+ mode: S ?? !1
327
425
  });
328
- const C = T(!1), V = T(m === "top");
329
- j(() => {
330
- const i = f.scrollerRef.current;
331
- if (!i || !u) return;
332
- const g = () => {
333
- const A = i.scrollTop;
334
- !V.current && A > d && (V.current = !0), V.current && A <= d && !C.current && (C.current = !0, Promise.resolve(u()).finally(() => {
335
- C.current = !1;
426
+ const V = C(
427
+ (p = "auto") => {
428
+ e.length !== 0 && h.scrollToIndex(e.length - 1, { align: "end", behavior: p });
429
+ },
430
+ [e.length, h]
431
+ ), k = C(
432
+ (p, B) => {
433
+ const N = e.findIndex((D, $) => t(D, $) === p);
434
+ N !== -1 && h.scrollToIndex(N, B);
435
+ },
436
+ [e, t, h]
437
+ ), H = g(null);
438
+ Q(() => {
439
+ if (f && H.current !== f.id) {
440
+ if (H.current = f.id, f.type === "prepend") {
441
+ z();
442
+ return;
443
+ }
444
+ if (f.type === "append") {
445
+ if (f.ifAtBottomOnly && !E) return;
446
+ V(f.behavior ?? "auto");
447
+ return;
448
+ }
449
+ if (f.type === "items-change") {
450
+ E && V("auto");
451
+ return;
452
+ }
453
+ k(f.key, {
454
+ align: f.align ?? "center",
455
+ behavior: f.behavior ?? "auto"
456
+ });
457
+ }
458
+ }, [f, E, z, V, k]);
459
+ const i = g(!1), d = g(l === "top");
460
+ X(() => {
461
+ const p = h.scrollerRef.current;
462
+ if (!p || !y) return;
463
+ const B = () => {
464
+ const N = p.scrollTop;
465
+ d.current || (p.scrollHeight <= p.clientHeight + m || N > m) && (d.current = !0), d.current && N <= m && !i.current && (i.current = !0, Promise.resolve(y()).finally(() => {
466
+ i.current = !1;
336
467
  }));
337
468
  };
338
- return i.addEventListener("scroll", g, { passive: !0 }), () => i.removeEventListener("scroll", g);
339
- }, [f.scrollerRef, u, d, m]);
340
- const N = T(!1);
341
- j(() => {
342
- const i = f.scrollerRef.current;
343
- if (!i || !h) return;
344
- const g = () => {
345
- i.scrollHeight - i.scrollTop - i.clientHeight <= y && !N.current && (N.current = !0, Promise.resolve(h()).finally(() => {
346
- N.current = !1;
469
+ return p.addEventListener("scroll", B, { passive: !0 }), B(), () => p.removeEventListener("scroll", B);
470
+ }, [h.scrollerRef, y, m, l]);
471
+ const R = g(!1);
472
+ X(() => {
473
+ const p = h.scrollerRef.current;
474
+ if (!p || !u) return;
475
+ const B = () => {
476
+ p.scrollHeight - p.scrollTop - p.clientHeight <= b && !R.current && (R.current = !0, Promise.resolve(u()).finally(() => {
477
+ R.current = !1;
347
478
  }));
348
479
  };
349
- return i.addEventListener("scroll", g, { passive: !0 }), () => i.removeEventListener("scroll", g);
350
- }, [f.scrollerRef, h, y]);
351
- const H = T(null);
352
- j(() => {
353
- if (!S || H.current === S) return;
354
- const i = e.findIndex((g, A) => t(g, A) === S);
355
- i !== -1 && (H.current = S, f.scrollToIndex(i, { align: "center", behavior: "smooth" }), x == null || x());
356
- }, [S, e, t, f, x]);
357
- const q = M(
358
- (i = "auto") => {
359
- e.length !== 0 && f.scrollToIndex(e.length - 1, { align: "end", behavior: i });
360
- },
361
- [e.length, f]
362
- ), l = M(
363
- (i, g) => {
364
- const A = e.findIndex((L, k) => t(L, k) === i);
365
- A !== -1 && f.scrollToIndex(A, g);
366
- },
367
- [e, t, f]
368
- );
369
- return {
370
- scrollerRef: f.scrollerRef,
371
- innerRef: f.innerRef,
372
- virtualItems: f.virtualItems,
373
- totalSize: f.totalSize,
374
- measureItem: f.measureItem,
375
- scrollToIndex: f.scrollToIndex,
376
- scrollToBottom: q,
377
- scrollToKey: l,
378
- isAtBottom: F,
379
- prepareAnchor: p
480
+ return p.addEventListener("scroll", B, { passive: !0 }), () => p.removeEventListener("scroll", B);
481
+ }, [h.scrollerRef, u, b]);
482
+ const w = g(null);
483
+ return X(() => {
484
+ if (!A || w.current === A) return;
485
+ const p = e.findIndex((B, N) => t(B, N) === A);
486
+ p !== -1 && (w.current = A, h.scrollToIndex(p, { align: "center", behavior: "auto" }), K == null || K());
487
+ }, [A, e, t, h, K]), {
488
+ scrollerRef: h.scrollerRef,
489
+ innerRef: h.innerRef,
490
+ virtualItems: h.virtualItems,
491
+ totalSize: h.totalSize,
492
+ measureItem: h.measureItem,
493
+ scrollToIndex: h.scrollToIndex,
494
+ scrollToBottom: V,
495
+ scrollToKey: k,
496
+ isAtBottom: E,
497
+ prepareAnchor: z
380
498
  };
381
499
  }
382
- function Z({
500
+ function ue({
383
501
  virtualItem: a,
384
502
  measureItem: e,
385
503
  children: t
386
504
  }) {
387
- const s = T(null), o = T(!1);
388
- return j(() => {
389
- const c = s.current;
390
- if (!c) return;
391
- o.current = !1;
392
- const r = new ResizeObserver(([m]) => {
393
- m && (o.current = !0, e(a.key, m.contentRect.height));
505
+ const n = g(null), c = g(!1);
506
+ return X(() => {
507
+ const o = n.current;
508
+ if (!o) return;
509
+ c.current = !1;
510
+ const r = new ResizeObserver(([S]) => {
511
+ S && (c.current = !0, e(a.key, S.contentRect.height));
394
512
  });
395
- return r.observe(c), () => r.disconnect();
396
- }, [a.key, e]), /* @__PURE__ */ B(
513
+ return r.observe(o), () => r.disconnect();
514
+ }, [a.key, e]), /* @__PURE__ */ W(
397
515
  "div",
398
516
  {
399
- ref: s,
517
+ ref: n,
400
518
  style: {
401
519
  position: "absolute",
402
520
  top: 0,
@@ -408,243 +526,247 @@ function Z({
408
526
  // ResizeObserver can accurately report the real size.
409
527
  // Without this, items can never be smaller than estimatedItemSize,
410
528
  // which distorts offsets and total height.
411
- minHeight: o.current ? void 0 : a.size
529
+ minHeight: c.current ? void 0 : a.size
412
530
  },
413
531
  children: t
414
532
  }
415
533
  );
416
534
  }
417
- function de(a, e) {
535
+ function Ie(a, e) {
418
536
  const {
419
537
  data: t,
420
- itemContent: s,
421
- computeItemKey: o,
422
- estimatedItemSize: c = 80,
538
+ itemContent: n,
539
+ computeItemKey: c,
540
+ estimatedItemSize: o = 80,
423
541
  overscan: r = 20,
424
- followOutput: m = "auto",
425
- atBottomThreshold: u = 200,
426
- initialAlignment: h = "bottom",
427
- onStartReached: d,
428
- onEndReached: y,
429
- startReachedThreshold: S = 300,
430
- endReachedThreshold: x = 300,
431
- scrollToMessageKey: f,
432
- onScrollToMessageComplete: F,
433
- onAtBottomChange: z,
434
- components: E = {},
435
- className: p,
436
- style: w
542
+ followOutput: S = "auto",
543
+ atBottomThreshold: l = 200,
544
+ atBottomHysteresis: f,
545
+ initialAlignment: y = "bottom",
546
+ scrollModifier: u,
547
+ onStartReached: m,
548
+ onEndReached: b,
549
+ startReachedThreshold: A = 300,
550
+ endReachedThreshold: K = 300,
551
+ scrollToMessageKey: h,
552
+ onScrollToMessageComplete: E,
553
+ onAtBottomChange: T,
554
+ components: M = {},
555
+ className: z,
556
+ style: L
437
557
  } = a, {
438
- scrollerRef: b,
439
- innerRef: C,
440
- virtualItems: V,
441
- totalSize: N,
442
- measureItem: H,
443
- scrollToIndex: q,
444
- scrollToBottom: l,
445
- scrollToKey: i,
446
- isAtBottom: g,
447
- prepareAnchor: A
448
- } = he({
558
+ scrollerRef: q,
559
+ innerRef: V,
560
+ virtualItems: k,
561
+ totalSize: H,
562
+ measureItem: i,
563
+ scrollToIndex: d,
564
+ scrollToBottom: R,
565
+ scrollToKey: w,
566
+ isAtBottom: p,
567
+ prepareAnchor: B
568
+ } = xe({
449
569
  items: t,
450
- getKey: (n, v) => o(v, n),
451
- estimatedItemSize: c,
570
+ getKey: (J, O) => c(O, J),
571
+ estimatedItemSize: o,
452
572
  overscan: r,
453
- atBottomThreshold: u,
454
- followOutput: m,
455
- initialAlignment: h,
456
- onStartReached: d,
457
- onEndReached: y,
458
- startReachedThreshold: S,
459
- endReachedThreshold: x,
460
- scrollToMessageKey: f,
461
- onScrollToMessageComplete: F
462
- }), L = X.useRef(g);
463
- X.useEffect(() => {
464
- L.current !== g && (L.current = g, z == null || z(g));
465
- }, [g, z]), re(
573
+ atBottomThreshold: l,
574
+ atBottomHysteresis: f,
575
+ followOutput: S,
576
+ initialAlignment: y,
577
+ scrollModifier: u,
578
+ onStartReached: m,
579
+ onEndReached: b,
580
+ startReachedThreshold: A,
581
+ endReachedThreshold: K,
582
+ scrollToMessageKey: h,
583
+ onScrollToMessageComplete: E
584
+ }), N = te.useRef(p);
585
+ te.useEffect(() => {
586
+ N.current !== p && (N.current = p, T == null || T(p));
587
+ }, [p, T]), de(
466
588
  e,
467
589
  () => ({
468
- scrollToBottom: l,
469
- scrollToIndex: q,
470
- scrollToKey: i,
590
+ scrollToBottom: R,
591
+ scrollToIndex: d,
592
+ scrollToKey: w,
471
593
  getScrollTop: () => {
472
- var n;
473
- return ((n = b.current) == null ? void 0 : n.scrollTop) ?? 0;
594
+ var J;
595
+ return ((J = q.current) == null ? void 0 : J.scrollTop) ?? 0;
474
596
  },
475
- isAtBottom: () => g,
476
- prepareAnchor: A
597
+ isAtBottom: () => p,
598
+ prepareAnchor: B
477
599
  }),
478
- [l, q, i, b, g, A]
600
+ [R, d, w, q, p, B]
479
601
  );
480
- const { Header: k, Footer: D, EmptyPlaceholder: Y } = E;
481
- return t.length === 0 && Y ? /* @__PURE__ */ B(Y, {}) : /* @__PURE__ */ Q(
602
+ const { Header: D, Footer: $, EmptyPlaceholder: G } = M;
603
+ return t.length === 0 && G ? /* @__PURE__ */ W(G, {}) : /* @__PURE__ */ le(
482
604
  "div",
483
605
  {
484
- ref: b,
485
- className: p,
606
+ ref: q,
607
+ className: z,
486
608
  style: {
487
609
  overflow: "auto",
488
610
  height: "100%",
489
611
  position: "relative",
490
612
  overscrollBehaviorY: "contain",
491
- ...w
613
+ ...L
492
614
  },
493
615
  children: [
494
- k && /* @__PURE__ */ B(k, {}),
495
- /* @__PURE__ */ B("div", { ref: C, style: { height: N, position: "relative", width: "100%" }, children: V.map((n) => /* @__PURE__ */ B(
496
- Z,
616
+ D && /* @__PURE__ */ W(D, {}),
617
+ /* @__PURE__ */ W("div", { ref: V, style: { height: H, position: "relative", width: "100%" }, children: k.map((J) => /* @__PURE__ */ W(
618
+ ue,
497
619
  {
498
- virtualItem: n,
499
- measureItem: H,
500
- children: s(n.index, n.data)
620
+ virtualItem: J,
621
+ measureItem: i,
622
+ children: n(J.index, J.data)
501
623
  },
502
- n.key
624
+ J.key
503
625
  )) }),
504
- D && /* @__PURE__ */ B(D, {})
626
+ $ && /* @__PURE__ */ W($, {})
505
627
  ]
506
628
  }
507
629
  );
508
630
  }
509
- const pe = te(de);
510
- function ve({
631
+ const we = me(Ie);
632
+ function Pe({
511
633
  data: a,
512
634
  itemContent: e,
513
635
  computeItemKey: t,
514
- estimatedItemSize: s = 60,
515
- overscan: o = 20,
516
- onEndReached: c,
636
+ estimatedItemSize: n = 60,
637
+ overscan: c = 20,
638
+ onEndReached: o,
517
639
  endReachedThreshold: r = 300,
518
- components: m = {},
519
- className: u,
520
- style: h
640
+ components: S = {},
641
+ className: l,
642
+ style: f
521
643
  }) {
522
- const { scrollerRef: d, innerRef: y, virtualItems: S, totalSize: x, measureItem: f } = W({
644
+ const { scrollerRef: y, innerRef: u, virtualItems: m, totalSize: b, measureItem: A } = ie({
523
645
  items: a,
524
- getKey: (p, w) => t(w, p),
525
- estimatedItemSize: s,
526
- overscan: o,
646
+ getKey: (T, M) => t(M, T),
647
+ estimatedItemSize: n,
648
+ overscan: c,
527
649
  initialAlignment: "top"
528
650
  });
529
- X.useEffect(() => {
530
- const p = d.current;
531
- if (!p || !c) return;
532
- let w = !1;
533
- const b = () => {
534
- p.scrollHeight - p.scrollTop - p.clientHeight <= r && !w && (w = !0, Promise.resolve(c()).finally(() => {
535
- w = !1;
651
+ te.useEffect(() => {
652
+ const T = y.current;
653
+ if (!T || !o) return;
654
+ let M = !1;
655
+ const z = () => {
656
+ T.scrollHeight - T.scrollTop - T.clientHeight <= r && !M && (M = !0, Promise.resolve(o()).finally(() => {
657
+ M = !1;
536
658
  }));
537
659
  };
538
- return p.addEventListener("scroll", b, { passive: !0 }), () => p.removeEventListener("scroll", b);
539
- }, [d, c, r]);
540
- const { Header: F, Footer: z, EmptyPlaceholder: E } = m;
541
- return a.length === 0 && E ? /* @__PURE__ */ B(E, {}) : /* @__PURE__ */ Q(
660
+ return T.addEventListener("scroll", z, { passive: !0 }), () => T.removeEventListener("scroll", z);
661
+ }, [y, o, r]);
662
+ const { Header: K, Footer: h, EmptyPlaceholder: E } = S;
663
+ return a.length === 0 && E ? /* @__PURE__ */ W(E, {}) : /* @__PURE__ */ le(
542
664
  "div",
543
665
  {
544
- ref: d,
545
- className: u,
666
+ ref: y,
667
+ className: l,
546
668
  style: {
547
669
  overflow: "auto",
548
670
  height: "100%",
549
671
  position: "relative",
550
672
  overscrollBehaviorY: "contain",
551
- ...h
673
+ ...f
552
674
  },
553
675
  children: [
554
- F && /* @__PURE__ */ B(F, {}),
555
- /* @__PURE__ */ B("div", { ref: y, style: { height: x, position: "relative", width: "100%" }, children: S.map((p) => /* @__PURE__ */ B(
556
- Z,
676
+ K && /* @__PURE__ */ W(K, {}),
677
+ /* @__PURE__ */ W("div", { ref: u, style: { height: b, position: "relative", width: "100%" }, children: m.map((T) => /* @__PURE__ */ W(
678
+ ue,
557
679
  {
558
- virtualItem: p,
559
- measureItem: f,
560
- children: e(p.index, p.data)
680
+ virtualItem: T,
681
+ measureItem: A,
682
+ children: e(T.index, T.data)
561
683
  },
562
- p.key
684
+ T.key
563
685
  )) }),
564
- z && /* @__PURE__ */ B(z, {})
686
+ h && /* @__PURE__ */ W(h, {})
565
687
  ]
566
688
  }
567
689
  );
568
690
  }
569
- function ze(a) {
691
+ function Ke(a) {
570
692
  const {
571
693
  fetcher: e,
572
694
  initialPage: t = 1,
573
- direction: s = "append",
574
- getKey: o,
575
- onPageLoaded: c,
695
+ direction: n = "append",
696
+ getKey: c,
697
+ onPageLoaded: o,
576
698
  onError: r
577
- } = a, [m, u] = _([]), [h, d] = _(t), [y, S] = _(!0), [x, f] = _(!1), [F, z] = _(!1), [E, p] = _(!1), w = T(/* @__PURE__ */ new Set()), b = T(!1), C = M(
578
- (l) => o ? l.filter((i) => {
579
- const g = o(i);
580
- return w.current.has(g) ? !1 : (w.current.add(g), !0);
581
- }) : l,
582
- [o]
583
- ), V = M(async () => {
584
- if (!(b.current || !y)) {
585
- b.current = !0, p(!0);
699
+ } = a, [S, l] = U([]), [f, y] = U(t), [u, m] = U(!0), [b, A] = U(!1), [K, h] = U(!1), [E, T] = U(!1), M = g(/* @__PURE__ */ new Set()), z = g(!1), L = C(
700
+ (i) => c ? i.filter((d) => {
701
+ const R = c(d);
702
+ return M.current.has(R) ? !1 : (M.current.add(R), !0);
703
+ }) : i,
704
+ [c]
705
+ ), q = C(async () => {
706
+ if (!(z.current || !u)) {
707
+ z.current = !0, T(!0);
586
708
  try {
587
- const l = h + 1, i = await e(l), g = C(i.data);
588
- u(
589
- (A) => s === "prepend" ? [...g, ...A] : [...A, ...g]
590
- ), d(l), S(i.hasNextPage), f(i.hasPrevPage), c == null || c(l, g);
591
- } catch (l) {
592
- r == null || r(l instanceof Error ? l : new Error(String(l)));
709
+ const i = f + 1, d = await e(i), R = L(d.data);
710
+ l(
711
+ (w) => n === "prepend" ? [...R, ...w] : [...w, ...R]
712
+ ), y(i), m(d.hasNextPage), A(d.hasPrevPage), o == null || o(i, R);
713
+ } catch (i) {
714
+ r == null || r(i instanceof Error ? i : new Error(String(i)));
593
715
  } finally {
594
- p(!1), b.current = !1;
716
+ T(!1), z.current = !1;
595
717
  }
596
718
  }
597
- }, [h, y, e, C, s, c, r]), N = M(async () => {
598
- if (!(b.current || !x)) {
599
- b.current = !0, p(!0);
719
+ }, [f, u, e, L, n, o, r]), V = C(async () => {
720
+ if (!(z.current || !b)) {
721
+ z.current = !0, T(!0);
600
722
  try {
601
- const l = h - 1, i = await e(l), g = C(i.data);
602
- u((A) => [...g, ...A]), d(l), f(i.hasPrevPage), S(i.hasNextPage), c == null || c(l, g);
603
- } catch (l) {
604
- r == null || r(l instanceof Error ? l : new Error(String(l)));
723
+ const i = f - 1, d = await e(i), R = L(d.data);
724
+ l((w) => [...R, ...w]), y(i), A(d.hasPrevPage), m(d.hasNextPage), o == null || o(i, R);
725
+ } catch (i) {
726
+ r == null || r(i instanceof Error ? i : new Error(String(i)));
605
727
  } finally {
606
- p(!1), b.current = !1;
728
+ T(!1), z.current = !1;
607
729
  }
608
730
  }
609
- }, [h, x, e, C, c, r]), H = M(async () => {
610
- if (!b.current) {
611
- b.current = !0, z(!0);
731
+ }, [f, b, e, L, o, r]), k = C(async () => {
732
+ if (!z.current) {
733
+ z.current = !0, h(!0);
612
734
  try {
613
- const l = await e(t), i = l.data;
614
- if (o) {
615
- const g = new Set(i.map(o));
616
- i.forEach((A) => w.current.add(o(A))), u((A) => {
617
- const L = A.filter((k) => !g.has(o(k)));
618
- return s === "prepend" ? [...i, ...L] : [...L, ...i];
735
+ const i = await e(t), d = i.data;
736
+ if (c) {
737
+ const R = new Set(d.map(c));
738
+ d.forEach((w) => M.current.add(c(w))), l((w) => {
739
+ const p = w.filter((B) => !R.has(c(B)));
740
+ return n === "prepend" ? [...d, ...p] : [...p, ...d];
619
741
  });
620
742
  } else
621
- u(i);
622
- d(t), S(l.hasNextPage), f(l.hasPrevPage), c == null || c(t, i);
623
- } catch (l) {
624
- r == null || r(l instanceof Error ? l : new Error(String(l)));
743
+ l(d);
744
+ y(t), m(i.hasNextPage), A(i.hasPrevPage), o == null || o(t, d);
745
+ } catch (i) {
746
+ r == null || r(i instanceof Error ? i : new Error(String(i)));
625
747
  } finally {
626
- z(!1), b.current = !1;
748
+ h(!1), z.current = !1;
627
749
  }
628
750
  }
629
- }, [e, t, o, s, c, r]), q = M(() => {
630
- u([]), d(t), S(!0), f(!1), z(!1), p(!1), w.current.clear(), b.current = !1;
751
+ }, [e, t, c, n, o, r]), H = C(() => {
752
+ l([]), y(t), m(!0), A(!1), h(!1), T(!1), M.current.clear(), z.current = !1;
631
753
  }, [t]);
632
754
  return {
633
- items: m,
634
- loadNextPage: V,
635
- loadPrevPage: N,
636
- hasNextPage: y,
637
- hasPrevPage: x,
638
- loading: F,
755
+ items: S,
756
+ loadNextPage: q,
757
+ loadPrevPage: V,
758
+ hasNextPage: u,
759
+ hasPrevPage: b,
760
+ loading: K,
639
761
  loadingMore: E,
640
- refresh: H,
641
- reset: q,
642
- currentPage: h
762
+ refresh: k,
763
+ reset: H,
764
+ currentPage: f
643
765
  };
644
766
  }
645
767
  export {
646
- pe as ChatVirtualList,
647
- ve as VirtualList,
648
- he as useChatVirtualizer,
649
- ze as usePagination
768
+ we as ChatVirtualList,
769
+ Pe as VirtualList,
770
+ xe as useChatVirtualizer,
771
+ Ke as usePagination
650
772
  };