react-anchorlist 0.3.2 → 0.3.4

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