UNPKG

@virtuoso.dev/message-list

Version:

Virtualized React component for rendering human/AI chatbot conversations.

1,887 lines (1,886 loc) 73.2 kB
import { Cell as c, Signal as y, map as d, filter as v, withLatestFrom as x, scan as ce, debounceTime as Ae, mapTo as K, throttleTime as ln, delayWithMicrotask as it, onNext as wn, Action as un, useCellValue as C, useRealm as _e, Realm as Oo, RealmContext as Bo, useCellValues as Do, usePublisher as No } from "@virtuoso.dev/gurx"; import h, { useEffect as $n, useLayoutEffect as Ho } from "react"; import { jsx as w, jsxs as Ln } from "react/jsx-runtime"; function Fe(e, t) { const n = c(e, (o) => { o.link(t(o), n); }); return n; } const Ke = { lvl: 0 }; function Rn(e, t, n, o = Ke, i = Ke) { return { k: e, l: o, lvl: n, r: i, v: t }; } function E(e) { return e === Ke; } function Pe() { return Ke; } function Ut(e, t) { if (E(e)) return Ke; const { k: n, l: o, r: i } = e; if (t === n) { if (E(o)) return i; if (E(i)) return o; const [s, r] = An(o); return vt(V(e, { k: s, l: Cn(o), v: r })); } return t < n ? vt(V(e, { l: Ut(o, t) })) : vt(V(e, { r: Ut(i, t) })); } function me(e, t, n = "k") { if (E(e)) return [Number.NEGATIVE_INFINITY, void 0]; if (e[n] === t) return [e.k, e.v]; if (e[n] < t) { const o = me(e.r, t, n); return o[0] === Number.NEGATIVE_INFINITY ? [e.k, e.v] : o; } return me(e.l, t, n); } function U(e, t, n) { return E(e) ? Rn(t, n, 1) : t === e.k ? V(e, { k: t, v: n }) : t < e.k ? Sn(V(e, { l: U(e.l, t, n) })) : Sn(V(e, { r: U(e.r, t, n) })); } function qt(e, t, n) { if (E(e)) return []; const { k: o, v: i, l: s, r } = e; let l = []; return o > t && (l = l.concat(qt(s, t, n))), o >= t && o <= n && l.push({ k: o, v: i }), o <= n && (l = l.concat(qt(r, t, n))), l; } function _o(e, t, n, o) { if (E(e)) return Ke; let i = Pe(); for (const { k: s, v: r } of be(e)) s > t && s <= n ? i = U(i, ...o(s, r)) : i = U(i, s, r); return i; } function Fo(e, t, n) { let o = Pe(), i = -1; for (const { start: s, end: r, value: l } of Po(e)) s < t ? (o = U(o, s, l), i = l) : s > t + n ? o = U(o, s - n, l) : r >= t + n && i !== l && (o = U(o, t, l)); return o; } function be(e) { return E(e) ? [] : [...be(e.l), { k: e.k, v: e.v }, ...be(e.r)]; } function An(e) { return E(e.r) ? [e.k, e.v] : An(e.r); } function Cn(e) { return E(e.r) ? e.l : vt(V(e, { r: Cn(e.r) })); } function V(e, t) { return Rn(t.k ?? e.k, t.v ?? e.v, t.lvl ?? e.lvl, t.l ?? e.l, t.r ?? e.r); } function Yt(e) { return E(e) || e.lvl > e.r.lvl; } function Sn(e) { return Gt(Bn(e)); } function vt(e) { const { l: t, r: n, lvl: o } = e; if (n.lvl >= o - 1 && t.lvl >= o - 1) return e; if (o > n.lvl + 1) { if (Yt(t)) return Bn(V(e, { lvl: o - 1 })); if (!E(t) && !E(t.r)) return V(t.r, { l: V(t, { r: t.r.l }), lvl: o, r: V(e, { l: t.r.r, lvl: o - 1 }) }); throw new Error("Unexpected empty nodes"); } if (Yt(e)) return Gt(V(e, { lvl: o - 1 })); if (!E(n) && !E(n.l)) { const i = n.l, s = Yt(i) ? n.lvl - 1 : n.lvl; return V(i, { l: V(e, { lvl: o - 1, r: i.l }), lvl: i.lvl + 1, r: Gt(V(n, { l: i.r, lvl: s })) }); } throw new Error("Unexpected empty nodes"); } function Po(e) { return On(be(e)); } function Mn(e, t, n) { if (E(e)) return []; const o = me(e, t)[0]; return On(qt(e, o, n)); } function Vn(e, t) { const n = e.length; if (n === 0) return []; let { index: o, value: i } = t(e[0]); const s = []; for (let r = 1; r < n; r++) { const { index: l, value: u } = t(e[r]); s.push({ end: l - 1, start: o, value: i }), o = l, i = u; } return s.push({ end: Number.POSITIVE_INFINITY, start: o, value: i }), s; } function On(e) { return Vn(e, ({ k: t, v: n }) => ({ index: t, value: n })); } function Gt(e) { const { r: t, lvl: n } = e; return !E(t) && !E(t.r) && t.lvl === n && t.r.lvl === n ? V(t, { l: V(e, { r: t.l }), lvl: n + 1 }) : e; } function Bn(e) { const { l: t } = e; return !E(t) && t.lvl === e.lvl ? V(t, { r: V(e, { l: t.r }) }) : e; } function Lt(e, t, n, o = 0) { let i = e.length - 1; for (; o <= i; ) { const s = Math.floor((o + i) / 2), r = e[s], l = n(r, t); if (l === 0) return s; if (l === -1) { if (i - o < 2) return s - 1; i = s - 1; } else { if (i === o) return s; o = s + 1; } } throw new Error(`Failed binary finding record in array - ${e.join(",")}, searched for ${t}`); } function Dn(e, t, n) { return e[Lt(e, t, n)]; } function Wo(e, t, n, o) { const i = Lt(e, t, o), s = Lt(e, n, o, i); return e.slice(i, s + 1); } function cn({ index: e }, t) { return t === e ? 0 : t < e ? -1 : 1; } function zo({ offset: e }, t) { return t === e ? 0 : t < e ? -1 : 1; } function Yo(e) { return { index: e.index, value: e }; } function Nn(e, t, n, o = 0) { return o > 0 && (t = Math.max(t, Dn(e, o, cn).offset)), t = Math.max(0, t), Vn(Wo(e, t, n, zo), Yo); } const Ue = [[], 0, 0, 0]; function jo(e, [t, n]) { let o = 0, i = 0, s = 0, r = 0; if (n !== 0) { r = Lt(e, n - 1, cn), s = e[r].offset; const u = me(t, n - 1); o = u[0], i = u[1], e.length && e[r].height === me(t, n)[1] && (r -= 1), e = e.slice(0, r + 1); } else e = []; for (const { start: l, value: u } of Mn(t, n, Number.POSITIVE_INFINITY)) { const a = (l - o) * i + s; e.push({ height: u, index: l, offset: a }), o = l, s = a, i = u; } return [e, i, s, o]; } function Ko(e) { const { size: t, startIndex: n, endIndex: o } = e; return (i) => i.start === n && (i.end === o || i.end === Number.POSITIVE_INFINITY) && i.value === t; } function Uo(e, t) { let n = E(e) ? 0 : Number.POSITIVE_INFINITY; for (const o of t) { const { size: i, startIndex: s, endIndex: r } = o; if (n = Math.min(n, s), E(e)) { e = U(e, 0, i); continue; } const l = Mn(e, s - 1, r + 1); if (l.some(Ko(o))) continue; let u = !1, a = !1; for (const { start: I, end: f, value: p } of l) u ? (r >= I || i === p) && (e = Ut(e, I)) : (a = p !== i, u = !0), f > r && r >= I && p !== i && (e = U(e, r + 1, p)); a && (e = U(e, s, i)); } return [e, n]; } const qe = [Pe(), 0]; function qo(e, [t, n]) { if (n.length > 0 && E(e) && t.length === 2) { const o = t[0].size, i = t[1].size; return [ n.reduce((s, r) => U(U(s, r, o), r + 1, i), Pe()), 0 ]; } return Uo(e, t); } const de = y(); c([]); c([]); c(0); c(null); c(Number.NaN); const Ce = c(!1), J = c(qe, (e) => { e.link( e.pipe( de, v((t) => t.length > 0), x(te), d(([t, n]) => qo(n, [t, []])) ), J ); }), te = c(qe[0], (e) => { e.link( e.pipe( J, d(([t]) => t) ), te ); }), Hn = c(qe[1], (e) => { e.link( e.pipe( J, d(([, t]) => t) ), Hn ); }), Me = c(Ue[1]), se = c(Ue[0]), tt = c(Ue, (e) => { e.link( e.pipe( te, x(Hn), ce(([t], [n, o]) => jo(t, [n, o]), Ue) ), tt ), e.link( e.pipe( tt, d(([, t]) => t) ), Me ), e.link( e.pipe( tt, d(([t]) => t) ), se ); }), _n = c(Ue[2], (e) => { e.link( e.pipe( tt, d(([, , t]) => t) ), _n ); }), Fn = c(Ue[3], (e) => { e.link( e.pipe( tt, d(([, , , t]) => t) ), Fn ); }), Xe = c(0, (e) => { e.link( e.pipe( e.combine(Se, Fn, _n, Me), d(([t, n, o, i]) => o + (t - n) * i) ), Xe ); }), Go = 3, Zo = 5; function Rt(e, t) { const n = Xo() ? Zo : Go; return Math.abs(e - t) <= n; } function Pn() { return typeof navigator > "u" ? !1 : /Macintosh/i.test(navigator.userAgent) && navigator.maxTouchPoints && navigator.maxTouchPoints > 1 || /iP(ad|od|hone)/i.test(navigator.userAgent) && /WebKit/i.test(navigator.userAgent); } function Xo() { return typeof navigator > "u" ? !1 : /Safari/i.test(navigator.userAgent) && /Apple Computer/i.test(navigator.vendor) && !/(Chrome|Chromium|CriOS|FxiOS|Edg|OPR|Opera|Android)/i.test(navigator.userAgent); } function Qo(e) { return !e; } function Jo(e) { return e === 1 ? 1 : 1 - 2 ** (-10 * e); } function Bt(e = 1) { return (t, n) => { const o = n.signalInstance(); return n.sub(t, (i) => { let s = e; function r() { s > 0 ? (s--, requestAnimationFrame(r)) : n.pub(o, i); } r(); }), o; }; } const Zt = "up", jt = "down", ei = "none", ti = { atBottom: !1, notAtBottomBecause: "NOT_SHOWING_LAST_ITEM", state: { offsetBottom: 0, scrollTop: 0, viewportHeight: 0, viewportWidth: 0, scrollHeight: 0 } }, ni = 0, oi = 4; function xn(e) { return (t, n) => { const o = n.signalInstance(); return n.sub(t, (i) => { e > 0 ? e-- : n.pub(o, i); }), o; }; } c(!1); const Wn = c(!0); y(); const ye = c(!1), ii = y((e) => { e.link(e.pipe(Wn, ln(50)), ii); }), zn = c(oi), si = c(ni, (e) => { e.link( e.pipe( e.combine(L, si), d(([t, n]) => t <= n) ), Wn ); }), st = c(!1, (e) => { e.link(e.pipe(L, xn(1), K(!0)), st), e.link(e.pipe(L, xn(1), K(!1), Ae(100)), st); }), Xt = c(!1, (e) => { e.link(e.pipe(ee, K(!0)), Xt), e.link(e.pipe(ee, K(!1), Ae(200)), Xt); }), an = c(!1), St = c( null, (e) => { e.link( e.pipe( e.combine( H, L, ne, wt, zn, Ot, Nt, te ), v(([, , , , , , , t]) => !E(t)), ce((t, [n, o, i, s, r, l]) => { const a = o + i - n + l > -r, I = { viewportWidth: s, viewportHeight: i, scrollTop: o, scrollHeight: n, listMarginTop: l }; if (a) { let p, b; return o > t.state.scrollTop ? (p = "SCROLLED_DOWN", b = t.state.scrollTop - o) : (p = n === i ? "LIST_TOO_SHORT" : "SIZE_DECREASED", b = t.state.scrollTop - o || t.scrollTopDelta), { atBottom: !0, state: I, atBottomBecause: p, scrollTopDelta: b }; } let f; return i < t.state.viewportHeight ? f = "VIEWPORT_HEIGHT_DECREASING" : s < t.state.viewportWidth ? f = "VIEWPORT_WIDTH_DECREASING" : o < t.state.scrollTop ? f = "SCROLLING_UPWARDS" : I.scrollHeight > t.state.scrollHeight || I.listMarginTop < t.state.listMarginTop ? t.atBottom ? f = "SIZE_INCREASED" : f = t.notAtBottomBecause : t.atBottom ? f = "NOT_FULLY_SCROLLED_TO_LAST_ITEM_BOTTOM" : f = t.notAtBottomBecause, { atBottom: !1, notAtBottomBecause: f, state: I }; }, ti) ), St ), e.link( e.pipe( St, ce( ({ prev: t }, n) => { const o = !!(t && n && t.atBottom && !n.atBottom && n.notAtBottomBecause === "SIZE_INCREASED"); return { prev: n, shouldScroll: o }; }, { prev: null, shouldScroll: !1 } ), d(({ shouldScroll: t }) => t) ), an ), e.sub( e.pipe( ne, x(St, dn, rt), v(([, , t, n]) => !t && !n), ce( (t, [n, o]) => { let i = 0; return t.viewportHeight > n && o && !o.atBottom && o.notAtBottomBecause === "VIEWPORT_HEIGHT_DECREASING" && (i = t.viewportHeight - n), { viewportHeight: n, delta: i }; }, { viewportHeight: 0, delta: 0 } ) ), (t) => { t.delta && e.pub(ee, t.delta); } ); }, (e, t) => !e || e.atBottom !== (t == null ? void 0 : t.atBottom) ? !1 : !e.atBottom && !t.atBottom ? e.notAtBottomBecause === t.notAtBottomBecause : !0 ), Yn = c(0, (e) => { e.link( e.pipe( e.combine(L, H, ne), ce( (t, [n, o, i]) => { if (!Rt(t.scrollHeight, o)) { const s = o - (n + i) < 1; return t.scrollTop !== n && s ? { scrollHeight: o, scrollTop: n, jump: t.scrollTop - n, changed: !0 } : { scrollHeight: o, scrollTop: n, jump: 0, changed: !0 }; } return { scrollTop: n, scrollHeight: o, jump: 0, changed: !1 }; }, { scrollHeight: 0, jump: 0, scrollTop: 0, changed: !1 } ), v((t) => t.changed), d((t) => t.jump) ), Yn ); }), At = c(jt, (e) => { e.link( e.pipe( L, ce( (t, n) => { if (n < 0) return { direction: Zt, prevScrollTop: 0 }; if (e.getValue(Xt)) return { direction: t.direction, prevScrollTop: n }; const i = n === t.prevScrollTop && n === 0; return { direction: n < t.prevScrollTop || i ? Zt : jt, prevScrollTop: n }; }, { direction: jt, prevScrollTop: 0 } ), d((t) => t.direction) ), At ), e.link(e.pipe(L, Ae(100), K(ei)), At); }), kn = c(0, (e) => { e.link(e.pipe(st, v(Qo), K(0)), kn), e.link( e.pipe( L, ln(100), x(st), v(([, t]) => !!t), ce(([, t], [n]) => [t, n], [0, 0]), d(([t, n]) => n - t) ), kn ); }), oe = c(!1), Ge = c(!1), xt = y((e) => { e.link( e.pipe( Ie, d((t) => t.deviationDelta), v((t) => t !== 0) ), xt ), Pn() ? (e.sub(e.pipe(xt, x(Q, L)), ([t, n]) => { e.pub(Q, n - t); }), e.sub( e.pipe(e.combine(L, Q, Ce, Ge)), ([t, n, o, i]) => { o || i || (n > 0 && t < n ? (e.pub(oe, !0), e.pub(Ne, { top: 0, behavior: "instant" }), setTimeout(() => { e.pubIn({ [oe]: !1, [Q]: 0 }); })) : n < 0 && t <= 0 && (e.pubIn({ [oe]: !0, [Q]: 0 }), setTimeout(() => { e.pub(Ne, { top: 0, behavior: "instant" }), e.pub(oe, !1); }))); } ), e.sub( e.pipe( e.combine(st, Q, oe, Ce, Ge), v( ([t, n, o, i, s]) => !t && n !== 0 && !o && !i && !s ), ln(100) ), ([, t]) => { e.pub(oe, !0), t < 0 ? requestAnimationFrame(() => { e.pub(ee, -t), e.pub(Q, 0), requestAnimationFrame(() => { e.pub(oe, !1); }); }) : requestAnimationFrame(() => { e.pub(ee, -t), e.pub(Q, 0), requestAnimationFrame(() => { e.pub(oe, !1); }); }); } )) : e.link(xt, ee); }); function jn(e, t) { if (t.length === 0) return [0, 0]; const { offset: n, index: o, height: i } = Dn(t, e, cn); return [i * (e - o) + n, i]; } function Ve(e, t) { return jn(e, t)[0]; } function fn(e, t) { if (typeof e == "number") return { index: e, offset: 0, behavior: "auto", align: "start-no-overflow" }; const n = { index: Number.NaN, align: e.align ?? "start-no-overflow", behavior: e.behavior ?? "auto", offset: e.offset ?? 0 }; return e.index === "LAST" ? n.index = t : e.index < 0 ? n.index = t + e.index : n.index = e.index, n; } function Kn({ location: e, sizeTree: t, offsetTree: n, totalHeight: o, totalCount: i, viewportHeight: s, headerHeight: r, stickyHeaderHeight: l, stickyFooterHeight: u }) { const { align: a, behavior: I, offset: f, index: p } = fn(e, i - 1); function b() { const k = me(t, p)[1]; if (k === void 0) throw new Error(`Item at index ${p} not found`); return k; } s -= l + u; let g = Ve(p, n) + r - l; a === "end" ? g = g - s + b() : a === "center" && (g = g - s / 2 + b() / 2), f && (g += f); let m = 0; return a === "start" && (m = Math.max(0, Math.min(g - (o - s)))), g = Math.max(0, g), { top: g, behavior: I, align: a, forceBottomSpace: m }; } const et = c(null), ri = c(!1), nt = c(!0), Qt = y((e) => { e.link( e.pipe( Qt, d(() => !0) ), nt ), e.link( e.pipe( Qt, d(() => null) ), et ); }), Un = y((e) => { e.link( e.pipe( Un, x(Se, se, He), d(([t, n, o, i]) => { let { align: s, behavior: r, offset: l, index: u } = fn(t, n - 1); const a = typeof t != "number" ? t.done : void 0, [I, f] = jn(u, o); return I < -i.listOffset ? ((typeof t == "number" || t.align === void 0) && (s = "start-no-overflow"), { index: u, align: s, behavior: r, offset: l, done: a }) : I + f > -i.listOffset + i.visibleListHeight ? ((typeof t == "number" || t.align === void 0) && (s = "end"), { index: u, align: s, behavior: r, offset: l, done: a }) : null; }), v((t) => t !== null) ), // @ts-expect-error contra variance ie ); }), ie = y((e) => { const t = e.pipe( ie, x( te, se, Se, ne, ft, Qe, at, Xe ), d( ([n, o, i, s, r, l, u, a, I]) => { try { return Kn({ location: n, totalHeight: I, sizeTree: o, offsetTree: i, totalCount: s, viewportHeight: r, headerHeight: l, stickyHeaderHeight: u, stickyFooterHeight: a }); } catch { return null; } } ), v((n) => n !== null) ); e.link(ie, et), e.link(t, Ne), e.link( e.pipe( ie, v((n) => typeof n != "number" && n.index === "LAST"), K(!0) ), ye ), e.link(e.pipe(t, K(!1)), nt), e.link(e.pipe(t, K(!1)), ri), e.link( e.pipe( te, // wait for the list to render with the specified sizeTree, so that enough space is available to scroll by Ae(0), x(nt, et), v(([, n, o]) => !n && o !== null), d(([, , n]) => n) ), ie ), e.sub(e.pipe(Re, Ae(10)), () => { const n = e.getValue(et); n !== null && typeof n != "number" && n.done !== void 0 && n.done(), e.pubIn({ [et]: null, [nt]: !0 }); }), e.link( e.pipe( $t, // wait for the list to render with the specified scrollOffset, so that enough space is available to scroll by it(), v((n) => n !== 0) ), ee ), e.link( e.pipe( $t, wn(L), d(() => 0) ), $t ); }), Le = c(null), Oe = c( null, (e) => { e.link( e.pipe( Oe, v((n) => n !== null) ), Le ); const t = e.pipe( e.combine(Oe, te), x(Le), v(([[n, o], i]) => n !== null && !E(o) && i !== null), d(([[n]]) => n) ); e.link(e.pipe(t, it()), ie), e.link( e.pipe( t, wn( e.pipe( nt, v((n) => n) ) ), K(null) // unset the location after the scroll completes ), Le ); }, !1 ); function li(e, t) { return [ { data: t == null ? void 0 : t[e], prevData: (t == null ? void 0 : t[e - 1]) ?? null, nextData: (t == null ? void 0 : t[e + 1]) ?? null, height: 0, index: e, offset: 0, type: "flat" } ]; } const ui = [], we = { items: ui, listBottom: 0, listTop: 0, offsetTree: [], paddingBottom: 0, paddingTop: 0, totalCount: 0, totalHeight: 0, deviationDelta: 0, visibleListHeight: 0, data: null }, Jt = c(!1), Ie = c(we, (e) => { e.link( e.pipe( e.combine( ai, Jn, te, se, Se, Xe, S, $t, Oe, Le, ct, Qe, at, Q, Jt, Ce, oe ), v((t) => { const n = t.at(-1), o = t.at(-2), i = t.at(-3); return !o && !n && !i; }), ce( (t, [ n, o, i, s, r, l, u, a, I, f, p, b, g, m ]) => { var xe; if ((u == null ? void 0 : u.length) === 0) return we; if (E(i)) { let re = 0; return I !== null && (re = fn(I, r - 1).index), { ...we, items: li(re, u), offsetTree: s, totalCount: r, data: u }; } let k = 0; f !== null && n === 0 && (k = Kn({ totalHeight: l, location: f, sizeTree: i, offsetTree: s, totalCount: r, viewportHeight: e.getValue(ne), headerHeight: e.getValue(ft), stickyHeaderHeight: b, stickyFooterHeight: g }).top ?? 0); let O = 0; e.getValue(L) !== 0 && !e.getValue(Dt) && e.getValue(At) === Zt && t.totalCount === r && t.items.length > 0 && (O = l - t.totalHeight, O !== 0 && (O += e.getValue(Yn))); const M = e.getValue(Zn), N = Math.min( Math.max( n + k + a - m - p + O - M, 0 ), l - o ), j = N + o + M * 2; if (t.offsetTree === s && t.totalCount === r && t.data === u && N >= t.listTop && j <= t.listBottom) return t; const _ = [], q = r - 1, G = 0, F = Nn(s, N, j, G); let B = 0, R = 0, X = !1; for (const re of F) { const { value: { offset: ke, height: Ee } } = re; let le = re.start; B = ke, ke < N && (le += Math.floor((N - ke) / Ee), B += (le - re.start) * Ee), le < G && (B += (G - le) * Ee, le = G); const Ft = Math.min(re.end, q); for (let fe = le; fe <= Ft && !(B >= j); fe++) { const pt = { data: u == null ? void 0 : u[fe], prevData: (u == null ? void 0 : u[fe - 1]) ?? null, nextData: (u == null ? void 0 : u[fe + 1]) ?? null, height: Ee, index: fe, offset: B, type: "flat" }; X || (X = !0, R = B), _.push(pt), B += Ee; } } _.length === 0 && (R = B = 0); const A = l - B, ae = ((xe = _[0]) == null ? void 0 : xe.offset) || 0; return { items: _, listBottom: B, listTop: R, offsetTree: s, paddingBottom: A, paddingTop: ae, totalCount: r, totalHeight: l, data: u, deviationDelta: O, visibleListHeight: o }; }, we ) ), Ie ); }), Ct = Fe([], (e) => e.pipe( e.combine(Ie, L), d(([t, n]) => { const o = t.items.slice(); for (; o.length > 0 && o[0].offset + o[0].height < n; ) o.shift(); return o.map((i) => i.data); }) )); function ci(e, t) { var r, l; const n = t.slice(); let o = 0; const i = []; for (const { k: u, v: a } of be(e)) { for (; n.length && n[0] < u; ) n.shift(), o++; const I = Math.max(0, u - o), f = ((r = i.at(-1)) == null ? void 0 : r.k) ?? -1; I === f ? (((l = i.at(-2)) == null ? void 0 : l.v) ?? -1) === a ? i.pop() : i[i.length - 1].v = a : i.push({ k: I, v: a }); } let s = Pe(); for (const { k: u, v: a } of i) s = U(s, u, a); return s; } const Se = c(0), Be = c(null), S = c(null, (e) => { e.link( e.pipe( S, v((t) => t !== null), d((t) => t.length) ), Se ); }), kt = c(null); function En(e, t, n) { function o() { e.pubIn({ [Q]: 0, [nn]: 0, [kt]: null, [Ge]: !1, [Jt]: !1, [yt]: null }); } e.pubIn({ [Jt]: !0, [ee]: t, [nn]: t }), n ? requestAnimationFrame(o) : o(); } const ue = y((e) => { e.link( e.pipe( ue, x(Me), d(([t, n]) => -(n * t.length)) ), Q ), e.link(e.pipe(ue, K(!0)), Ge), e.link(e.pipe(ue, it()), kt), e.sub( e.pipe( se, x(kt), v(([, t]) => t !== null), d(([t, n]) => { if (n === null) throw new Error("Unexpected null items"); return Ve(n.length, t); }) ), (t) => { En(e, t, !1); } ), e.sub( e.pipe( ue, Bt(2), x(se, kt), v(([, , t]) => t !== null), d(([t, n]) => Ve(t.length, n)) ), (t) => { En(e, t, !0); } ), e.changeWith(S, ue, (t, n) => t ? [...n, ...t] : n.slice()), e.link( e.pipe( ue, x(te, Me), d(([t, n, o]) => { const i = t.length, s = o; return be(n).reduce( (l, { k: u, v: a }) => ({ ranges: [...l.ranges, { startIndex: l.prevIndex, endIndex: u + i - 1, size: l.prevSize }], prevIndex: u + i, prevSize: a }), { ranges: [], prevIndex: 0, prevSize: s } ).ranges; }) ), de ); }), ut = y((e) => { const t = e.pipe( ut, x(He, $e, Be), d(([{ data: o, scrollToBottom: i, atBottom: s }, r, l, u]) => { if (i === !1 || i === void 0) return null; let a = "auto"; const I = s ?? r.isAtBottom; if (typeof i == "function") { const f = i({ data: o, scrollLocation: r, scrollInProgress: l, context: u, atBottom: I }); if (!f) return null; if (typeof f == "object") return f; if (typeof f == "number") return { index: f, align: "end", behavior: "auto" }; a = f; } else { if (!I) return null; a = i; } return a === !0 && (a = "auto"), { index: "LAST", align: "end", behavior: a }; }) ); e.link( e.pipe( t, v((o) => o !== null), d(() => !0) ), ye ), e.link( e.pipe( Re, x(ye), v(([o, i]) => i), d(() => !1) ), ye ); const n = e.pipe( gn, x(ye), v(([o, i]) => o === "up" && i) ); e.link( e.pipe( n, d(() => !1) ), ye ), e.link(e.pipe(n, K(!0)), Qt), e.link( e.pipe( t, x(te), v(([o, i]) => o !== null && E(i)), d(([o]) => o) ), Oe ), e.link( e.pipe( t, x(te), v(([o, i]) => o !== null && !E(i)), d(([o]) => o), Ae(20) ), ie ); }), Mt = y((e) => { e.changeWith(S, Mt, (t, n) => t ? [...t, ...n.data] : n.data.slice()), e.link(Mt, ut); }), Et = y((e) => { e.changeWith(S, Et, (t, n) => t ? [...t.slice(0, n.offset), ...n.data, ...t.slice(n.offset)] : n.data.slice()), e.changeWith(J, Et, ([t], n) => { const i = me(t, n.offset, "k")[0], s = n.data.length; return [_o(t, i, Number.POSITIVE_INFINITY, (l, u) => [l + s, u]), i]; }), e.link( e.pipe( Et, d(({ data: t, scrollToBottom: n }) => ({ data: t, scrollToBottom: n })) ), ut ); }), en = y((e) => { e.changeWith(S, en, (t, { offset: n, count: o }) => t ? t.slice(0, n).concat(t.slice(n + o)) : []), e.changeWith(J, en, ([t], { offset: n, count: o }) => [Fo(t, n, o), n]); }), Kt = c(null), je = y((e) => { e.sub( e.pipe( je, x(S), v( ([{ data: t, purgeItemSizes: n }, o]) => t.length === 0 || !!n || o === null || o.length === 0 ) ), ([t, n]) => { n === null || n.length === 0 ? e.pubIn({ ...t.initialLocation ? { [Oe]: t.initialLocation } : {}, [ot]: 0, ...t.data.length === 0 ? { [J]: qe, [Ie]: we } : {}, [S]: t.data.slice() }) : e.pubIn({ ...t.initialLocation ? { [Oe]: t.initialLocation } : {}, [ot]: 0, [J]: qe, [Ie]: we, [Kt]: t.data.slice() }); } ), e.sub( e.pipe( no, x(Kt), Bt(), v(([, t]) => t !== null) ), ([, t]) => { e.pubIn({ [S]: t, [Kt]: null }); } ), e.link( e.pipe( je, v(({ data: t, purgeItemSizes: n }) => t.length > 0 && !n), x(Me), v(([, t]) => t > 0), d(([{ data: t }, n]) => [ { size: n, startIndex: t.length, endIndex: Number.POSITIVE_INFINITY } ]) ), de ), e.sub( e.pipe( je, v(({ data: t, purgeItemSizes: n }) => t.length > 0 && !n) ), ({ data: t, initialLocation: n, suppressItemMeasure: o }) => { e.pub(ot, 0), requestAnimationFrame(() => { o || e.pub(to), requestAnimationFrame(() => { n && e.pubIn({ [ie]: n }); }); }), e.pubIn({ [S]: t.slice() }); } ); }), Tt = y((e) => { e.link( e.pipe( Tt, x(se), d(([t, n]) => -Ve(t, n)) ), ee ), e.changeWith(S, e.pipe(Tt, it()), (t, n) => t ? t.slice(n) : []), e.changeWith(J, e.pipe(Tt, it()), ([t], n) => [be(t).reduce((i, { k: s, v: r }) => U(i, Math.max(0, s - n), r), Pe()), 0]); }), Tn = y((e) => { e.changeWith(S, Tn, (t, n) => t ? t.slice(0, t.length - n) : []), e.link( e.pipe( Tn, x(Se, Me), d(([, t, n]) => [ { size: n, startIndex: t, endIndex: Number.POSITIVE_INFINITY } ]) ), de ); }), qn = y((e) => { const t = e.pipe( qn, x(S), d(([n, o]) => { if (!o) return []; const i = []; return o.forEach((s, r) => { n(s, r) && i.push(r); }), i; }) ); e.changeWith(S, t, (n, o) => n ? n.filter((i, s) => !o.includes(s)) : []), e.changeWith(J, t, ([n], o) => [ci(n, o), 0]); }), yt = c(null), Ye = y((e) => { e.changeWith(S, Ye, (t, { mapper: n }) => t ? t.map(n) : []), e.link( e.pipe( Ye, v(({ anchorItemIndex: t }) => t !== void 0), K(!0) ), Ge ), e.link( e.pipe( Ye, v(({ anchorItemIndex: t }) => t !== void 0), x(se), d(([{ anchorItemIndex: t }, n]) => { const o = t; return { oldOffset: Ve(o, n), index: o }; }) ), yt ), e.sub( e.pipe( se, x(yt), v(([, t]) => t !== null), d(([t, n]) => Ve(n.index, t) - n.oldOffset) ), (t) => { e.pubIn({ [Ge]: !1, [yt]: null, [ee]: t }); } ), e.link( e.pipe( Ye, Bt(3), x(an), v(([{ autoscrollToBottomBehavior: t }, n]) => n && !!t), d(([{ autoscrollToBottomBehavior: t }]) => typeof t == "object" ? t.location() : { index: "LAST", align: "end", behavior: t }), v((t) => !!t) ), ie ); }), Vt = y((e) => { e.changeWith(S, Vt, (t, { newData: n }) => n), e.link( e.pipe( Vt, Bt(3), x(an), v(([{ autoscrollToBottomBehavior: t }, n]) => n && !!t), d(([{ autoscrollToBottomBehavior: t }]) => typeof t == "object" ? t.location() : { index: "LAST", align: "end", behavior: t }), v((t) => !!t) ), ie ); }), Dt = y(), $e = c(!1), Re = y((e) => { e.link(e.pipe(Re, K(!1)), Dt); }, !1), L = c(0), ne = c(0), wt = c(0), H = c(0), ai = L, $t = c(0), Qe = c(0), ct = c(0), at = c(0), pn = c(0), De = c(null), Gn = un(), Zn = c(0), Xn = c(!1), fi = Jo, pi = 50, ft = Fe(0, (e) => e.pipe( e.combine(Qe, ct), d(([t, n]) => t + n) )), Qn = Fe(0, (e) => e.pipe( e.combine(at, pn), d(([t, n]) => t + n) )), hi = Fe(0, (e) => e.pipe( e.combine(Qe, ct, L), d(([t, n, o]) => t + Math.max(n - o, 0)) )), gi = Fe(0, (e) => e.pipe( e.combine(at, pn, L, ne, H), d(([t, n, o, i, s]) => { o = Math.min(o, s - i); const r = Math.max(n - (s - (o + i)), 0); return t + r; }) )), Jn = Fe(0, (e) => e.pipe( e.combine(ne, hi, gi), d(([t, n, o]) => Math.max(0, t - n - o)) )), Nt = c(0), ot = c(0, (e) => { e.link( e.pipe( e.combine(ot, Xe, ne, ft, Qe), d(([t, n, o, i, s]) => t === 0 ? 0 : Math.max(0, Math.min(t - (n + i + s - o)))) ), Nt ); }), Ne = y((e) => { e.link( e.pipe( Ne, d((t) => t.align === "start" ? t.top ?? 0 : 0) ), ot ), e.link( e.pipe( Ne, x(L), v(([t, n]) => t.top !== n), K(!0) ), Dt ); }), hn = y((e) => { e.link( e.pipe( Ne, x(lt), d(([t, n]) => ("top" in t && typeof t.top < "u" && (t = { ...t, top: t.top + n }), t)) ), hn ); }), He = Fe( { listOffset: 0, visibleListHeight: 0, scrollHeight: 0, bottomOffset: 0, isAtBottom: !1, lastVisibleItemIndex: 0, lastItemBottomOffset: 0 }, (e) => e.pipe( e.combine( L, ft, Qn, ct, Jn, H, Nt, Ce, Le, oe, ye ), v(([, , , , , , , t, n, o]) => !t && n === null && !o), d( ([ t, n, o, i, s, r, l, u, a, I, f ]) => { const p = e.getValue(zn), b = r - n - o, g = -t + i, m = b + Math.min(0, g) - s - l; let k = 0, O = 0; const M = e.getValue(se), N = e.getValue(Se); if (N > 0 && M.length > 0) { const j = t - i + s, _ = Nn(M, Math.max(0, j - 1), j); if (_.length > 0) { const q = _[_.length - 1], { offset: G, height: F } = q.value, B = Math.min(q.start + Math.floor((j - G) / F), q.end); k = Math.min(B, N - 1); const R = G + (B - q.start + 1) * F; O = j - R; } } return { scrollHeight: b, listOffset: g, visibleListHeight: s, bottomOffset: m, isAtBottom: f || m <= p, lastVisibleItemIndex: k, lastItemBottomOffset: O }; } ) ) ), tn = y((e) => { e.link( e.pipe( L, Ae(0), x(He, Le, Ce), v(([, t, n, o]) => t.scrollHeight > 0 && n == null && !o), d(([, t]) => t) ), tn ); }), ee = y(), Q = c(0), nn = c(0), Ot = c(0), eo = c(""), gn = y(), to = un(), no = un(), dn = c(!1), rt = c(null); c(0); const lt = c(0, (e) => { e.link( e.pipe( e.combine(Ze, ve, lt), d(([t, n, o]) => t - Math.max(0, o - n)) ), ne ); }), ve = c(0, (e) => { e.link( e.pipe( e.combine(ve, lt), d(([t, n]) => Math.max(0, t - n)) ), L ); }), Ze = c(0); function di(e, t, n) { if (n === !1 || n === void 0) return; const o = e.getValue(He), i = o.isAtBottom, s = e.getValue($e), r = e.getValue(Be); let l; if (typeof n == "function") l = n({ atBottom: i, context: r, data: t, scrollInProgress: s, scrollLocation: o }); else { if (!i) return; l = n; } if (l) return typeof l == "object" ? { location: () => l } : typeof l == "number" ? { location: () => ({ index: l, align: "end", behavior: "auto" }) } : l === !0 ? "auto" : l; } function oo(e) { return { data: { prepend: (t) => { e.pub(ue, t); }, append: (t, n) => { e.pub(Mt, { data: t, scrollToBottom: n }); }, replace: (t, n) => { e.pub(je, { ...n, data: t }); }, map: (t, n) => { e.pub(Ye, { mapper: t, autoscrollToBottomBehavior: n }); }, mapWithAnchor: (t, n) => { e.pub(Ye, { mapper: t, anchorItemIndex: n }); }, findAndDelete: (t) => { e.pub(qn, t); }, findIndex: (t) => e.getValue(S).findIndex(t), find: (t) => e.getValue(S).find(t), insert: (t, n, o) => { e.pub(Et, { data: t, offset: n, scrollToBottom: o }); }, deleteRange: (t, n) => { e.pub(en, { offset: t, count: n }); }, batch: (t, n) => { const o = e.getValue(S), i = ((o == null ? void 0 : o.length) ?? 0) === 0 || e.getValue(He).isAtBottom; e.pub(Ce, !0), t(), e.pub(Ce, !1), e.pub(ut, { data: [], scrollToBottom: n, atBottom: i }); }, get: () => e.getValue(S).slice(), getCurrentlyRendered: () => e.getValue(Ct), removeFromStart: (t) => { e.pub(Tt, t); } }, scrollToItem: (t) => { e.pub(ie, t); }, scrollIntoView: (t) => { e.pub(Un, t); }, scrollerElement: () => e.getValue(De), getScrollLocation() { return e.getValue(He); }, cancelSmoothScroll() { e.pub(Gn); }, notifyItemsChanged({ scrollToBottom: t }) { const n = e.getValue(S) ?? []; e.pub(Vt, { newData: n, autoscrollToBottomBehavior: di(e, n, t) }); }, height: (t) => { var i; const n = ((i = e.getValue(S)) == null ? void 0 : i.indexOf(t)) ?? -1; if (n === -1) return 0; const o = e.getValue(te); return me(o, n)[1] ?? 0; } }; } function Zi() { return C(He); } function Xi() { return C(Ct); } function Qi() { const e = _e(); return h.useMemo(() => oo(e), [e]); } const Ji = { prepend: "prepend", removeFromStart: "remove-from-start", removeFromEnd: "remove-from-end" }; function es({ atBottom: e, scrollInProgress: t }) { return e || t ? "smooth" : !1; } function ts({ atBottom: e, scrollInProgress: t }) { return { index: "LAST", align: "end", behavior: e || t ? "smooth" : "auto" }; } const io = c(null), so = c(null), ro = c(null), lo = c(null), uo = c(null), co = c("div"), mi = { position: "sticky", top: 0, zIndex: 1 }, bt = { overflowAnchor: "none" }, bi = { position: "sticky", bottom: 0 }, ao = h.forwardRef((e, t) => /* @__PURE__ */ w("div", { style: { zIndex: 1 }, ...e, ref: t })), fo = h.forwardRef((e, t) => /* @__PURE__ */ w("div", { ...e, ref: t })), po = h.forwardRef( ({ style: e, ...t }, n) => /* @__PURE__ */ w("div", { ...t, style: { ...mi, ...e }, ref: n }) ), ho = h.forwardRef( ({ style: e, ...t }, n) => /* @__PURE__ */ w("div", { ...t, style: { ...bi, ...e }, ref: n }) ), go = c(ao), mo = c(po), bo = c(fo), Io = c(ho), vo = ({ index: e }) => /* @__PURE__ */ Ln("div", { children: [ "Item ", e ] }), So = ({ index: e }) => e, on = c(vo), xo = c(So), ko = (e) => e, sn = c(ko), Eo = c( null, (e) => { e.sub( e.pipe(Eo, x(S, sn, se, J)), ([t, n, o, i, s]) => { if (t === void 0) return; if (!t || !t.data || !t.data.length) { e.pubIn({ [S]: [], [J]: qe, [Ie]: we }); return; } const r = t.data, l = t.scrollModifier; if (l === "prepend") { if (n === null || !n.length) { e.pub(S, r); return; } const u = n[0], a = r.findIndex((p) => o(p) === o(u)), I = a === -1 ? r : r.slice(0, a), f = a === -1 ? [] : r.slice(a); e.pubIn({ [S]: f }), e.pubIn({ [ue]: I }); return; } if (l === "remove-from-start") { const u = r[0], a = (n == null ? void 0 : n.findIndex((f) => o(f) === o(u))) ?? -1; if (a === -1) { e.pub(S, r); return; } const I = Ve(a, i); e.pub(ee, -I), queueMicrotask(() => { e.pub(S, r); const f = be(s[0]).reduce((p, { k: b, v: g }) => U(p, Math.max(0, b - a), g), Pe()); e.pub(J, [f, 0]); }); return; } if (l === "remove-from-end") { e.pub(S, r), e.pub(de, [ { size: e.getValue(Me), startIndex: r.length, endIndex: Number.POSITIVE_INFINITY } ]); return; } if ((l == null ? void 0 : l.type) === "item-location") { r !== n && e.pubIn({ [je]: { data: r, initialLocation: l.location, purgeItemSizes: l.purgeItemSizes } }); return; } if ((l == null ? void 0 : l.type) === "auto-scroll-to-bottom") { e.pubIn({ [S]: r, [ut]: { data: r, scrollToBottom: l.autoScroll } }); return; } if ((l == null ? void 0 : l.type) === "items-change") { e.pub(Vt, { newData: r, autoscrollToBottomBehavior: l.behavior }); return; } e.pub(S, r); } ); }, (e, t) => e ? e.data === (t == null ? void 0 : t.data) : !1 ), Ii = ({ item: e, ItemContent: t, mount: n, unmount: o }) => { const i = C(Be), s = h.useRef(null), r = h.useCallback( (l) => { l ? (s.current = l, n(l)) : s.current && (o(s.current), s.current = null); }, [n, o] ); return /* @__PURE__ */ w( "div", { ref: r, "data-index": e.index, "data-known-size": e.height, style: { overflowAnchor: "none", position: "absolute", width: "100%", top: e.offset }, children: /* @__PURE__ */ w(t, { index: e.index, prevData: e.prevData, nextData: e.nextData, data: e.data, context: i }) } ); }, vi = h.memo(Ii, (e, t) => { const n = e.item, o = t.item; return n.index === o.index && n.height === o.height && n.offset === o.offset && n.data === o.data && n.prevData === o.prevData && n.nextData === o.nextData && e.ItemContent === t.ItemContent; }), rn = c("top", (e) => { e.link( e.pipe( e.combine(rn, Xe, ne, ft, Qn), v(([t]) => t === "bottom" || t === "bottom-smooth"), d(([, t, n, o, i]) => Math.max(0, n - t - o - i)) ), Ot ), e.link( e.pipe( e.combine(Ot, rn), v(([, t]) => t === "bottom-smooth"), ce( (t, [n]) => [t[1], n], [0, 0] ), d(([t, n]) => t > 0 && n > 0 ? "margin-top 0.2s ease-out" : "") ), eo ); }); function It(e) { const t = h.useRef(null); return [h.useCallback( (o) => { o ? (t.current = o, e == null || e.observe(o, { box: "border-box" })) : t.current && (e == null || e.unobserve(t.current), t.current = null); }, [e] ), t]; } function Si(e, t, n, o, i) { const s = _e(), r = h.useRef(null), l = h.useRef(null), u = h.useCallback( (p = !1) => { r.current && (cancelAnimationFrame(r.current), r.current = null, l.current = null), o.current = !1, p && n.current !== null && (n.current = null, s.pub($e, !1)); }, [s, o, n] ); h.useEffect(() => s.sub(gn, (p) => { p !== l.current && u(!0); }), [s, u]), h.useEffect(() => s.sub(Gn, () => u(!0)), [s, u]); const a = h.useCallback( (p, b, g) => { var N; r.current && u(); const m = ((N = e.current) == null ? void 0 : N.scrollTop) ?? 0; l.current = m < p ? "down" : "up", o.current = !0; let k = 0, O = 0; function M() { var _, q; const j = m + (p - m) * b(k); (_ = e.current) == null || _.scrollTo({ top: j, behavior: "instant" }), k += 1 / g, O += 1, O < g ? (s.pub(i, j), r.current = requestAnimationFrame(M)) : ((q = e.current) == null || q.scrollTo({ top: p, behavior: "instant" }), r.current = null, l.current = null, o.current = !1, n.current = null, s.pub(i, p), s.pub($e, !1), s.pub(Re, p)); } M(); }, [e, u, o, n, s, i] ), I = h.useCallback( (p) => { const b = e.current; if (b === null || n.current !== p) return; const g = b.scrollHeight - b.clientHeight; Rt(b.scrollTop, Math.min(g, p)) && (n.current = null, s.pub(i, b.scrollTop), s.pub($e, !1), s.pub(Re, b.scrollTop)); }, [s, e, n, i] ); return h.useCallback( (p) => { var k, O; const b = e.current; if (!b || p.top === void 0) return; const g = b.scrollHeight - b.clientHeight, m = Math.max(0, Math.min(p.top, g)); if (Rt(m, b.scrollTop) || b.scrollHeight <= b.clientHeight) { requestAnimationFrame(() => { var M; s.pub(Re, (M = e.current) == null ? void 0 : M.scrollTop); }); return; } if (n.current = m, s.pub($e, !0), p.forceBottomSpace !== void 0 && t.current && (t.current.style.paddingBottom = `${p.forceBottomSpace}px`), p.behavior === "smooth") a(m ?? 0, fi, pi); else if (p.behavior === "auto" || p.behavior === "instant" || p.behavior === void 0) u(), (k = e.current) == null || k.scrollTo(p), requestAnimationFrame(() => I(m)); else { const { easing: M, animationFrameCount: N } = p.behavior(((O = e.current) == null ? void 0 : O.scrollTop) ?? 0, m ?? 0); a(m ?? 0, M, N); } }, [s, a, t, e, n, u, I] ); } function xi(e) { return ki(Ti(yi(Ei(e), 8 * e.length))).toLowerCase(); } function ki(e) { for (var t, n = "0123456789ABCDEF", o = "", i = 0; i < e.length; i++) t = e.charCodeAt(i), o += n.charAt(t >>> 4 & 15) + n.charAt(15 & t); return o; } function Ei(e) { for (var t = Array(e.length >> 2), n = 0; n < t.length; n++) t[n] = 0; for (n = 0; n < 8 * e.length; n += 8) t[n >> 5] |= (255 & e.charCodeAt(n / 8)) << n % 32; return t; } function Ti(e) { for (var t = "", n = 0; n < 32 * e.length; n += 8) t += String.fromCharCode(e[n >> 5] >>> n % 32 & 255); return t; } function yi(e, t) { e[t >> 5] |= 128 << t % 32, e[14 + (t + 64 >>> 9 << 4)] = t; for (var n = 1732584193, o = -271733879, i = -1732584194, s = 271733878, r = 0; r < e.length; r += 16) { const l = n, u = o, a = i, I = s; o = Y( o = Y( o = Y( o = Y( o = z( o = z( o = z( o = z( o = W( o = W( o = W( o = W( o = P( o = P( o = P( o = P( o, i = P( i, s = P(s, n = P(n, o, i, s, e[r + 0], 7, -680876936), o, i, e[r + 1], 12, -389564586), n, o, e[r + 2], 17, 606105819 ), s, n, e[r + 3], 22, -1044525330 ), i = P( i, s = P(s, n = P(n, o, i, s, e[r + 4], 7, -176418897), o, i, e[r + 5], 12, 1200080426), n, o, e[r + 6], 17, -1473231341 ), s, n, e[r + 7], 22, -45705983 ), i = P( i, s = P(s, n = P(n, o, i, s, e[r + 8], 7, 1770035416), o, i, e[r + 9], 12, -1958414417), n, o, e[r + 10], 17, -42063 ), s, n, e[r + 11], 22, -1990404162 ), i = P( i, s = P(s, n = P(n, o, i, s, e[r + 12], 7, 1804603682), o, i, e[r + 13], 12, -40341101), n, o, e[r + 14], 17, -1502002290 ), s, n, e[r + 15], 22, 1236535329 ), i = W( i, s = W(s, n = W(n, o, i, s, e[r + 1], 5, -165796510), o, i, e[r + 6], 9, -1069501632), n, o, e[r + 11], 14, 643717713 ), s, n, e[r + 0], 20, -373897302 ), i = W( i, s = W(s, n = W(n, o, i, s, e[r + 5], 5, -701558691), o, i, e[r + 10], 9, 38016083), n, o, e[r + 15], 14, -660478335 ), s, n, e[r + 4], 20, -405537848 ), i = W( i, s = W(s, n = W(n, o, i, s, e[r + 9], 5, 568446438), o, i, e[r + 14], 9, -1019803690), n, o, e[r + 3],