react-anchorlist 0.2.0 → 0.2.3

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