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