react-anchorlist 0.3.4 → 0.3.5

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