@af-utils/virtual-core
Advanced tools
Comparing version 0.0.20 to 0.0.21
@@ -1,4 +0,4 @@ | ||
export declare const raw = 7561; | ||
export declare const min = 4781; | ||
export declare const minGz = 2104; | ||
export declare const minBrotli = 1907; | ||
export declare const raw = 7434; | ||
export declare const min = 4668; | ||
export declare const minGz = 2051; | ||
export declare const minBrotli = 1862; |
@@ -1,4 +0,4 @@ | ||
export const raw = 7561; | ||
export const min = 4781; | ||
export const minGz = 2104; | ||
export const minBrotli = 1907; | ||
export const raw = 7434; | ||
export const min = 4668; | ||
export const minGz = 2051; | ||
export const minBrotli = 1862; |
@@ -234,3 +234,3 @@ /** | ||
*/ | ||
private get _exactFrom(); | ||
private _getExactFrom; | ||
/** | ||
@@ -240,3 +240,3 @@ * Get last visible item index (without overscan) | ||
*/ | ||
private get _exactTo(); | ||
private _getExactTo; | ||
/** | ||
@@ -243,0 +243,0 @@ * Used to update current visible items range when scrolling down/right; |
255
lib/index.js
@@ -5,54 +5,45 @@ const t = { | ||
SIZES: 2 | ||
}, s = [ 0, 1, 2 ], i = t => t(), e = (t, s) => { | ||
}, s = t => t(), i = (t, s) => { | ||
if (!t) throw Error(s); | ||
}, h = (t, s) => { | ||
if (t instanceof HTMLElement) { | ||
const i = new ResizeObserver(s); | ||
return i.observe(t), () => i.disconnect(); | ||
} | ||
return s(), addEventListener("resize", s), () => removeEventListener("resize", s); | ||
}, r = (t, s, i) => { | ||
}, e = (t, s, i) => { | ||
const e = new Uint32Array(s); | ||
return e.set(t), e.fill(i, t.length), e; | ||
}, n = (t, s) => { | ||
}, h = t => t instanceof HTMLElement, r = (t, s) => t.getBoundingClientRect()[s], o = (t, s, i, e) => s && t && t !== s ? t[i] + Math.round(r(s, e) - (h(t) ? r(t, e) : 0)) : 0, n = (t, s) => { | ||
t.set(s, 1); | ||
for (let s, i = 1, e = t.length; e > i; i++) s = i + (i & -i), e > s && (t[s] += t[i]); | ||
}, o = (t, s, i, e) => { | ||
}, l = (t, s, i, e) => { | ||
for (;e > s; s += s & -s) t[s] += i; | ||
}, l = (t, s, i) => { | ||
}, c = (t, s, i) => { | ||
for (;i > s; s += s & -s) ; | ||
return Math.min(s, t.length); | ||
}, c = (t, s) => t.getBoundingClientRect()[s], a = (t, s, i, e) => s && t && t !== s ? t[i] + Math.round(c(s, e) - (t instanceof HTMLElement ? c(t, e) : 0)) : 0, f = new Set, _ = { | ||
t: 0, | ||
i() { | ||
this.t++; | ||
}, | ||
h() { | ||
0 == --this.t && (f.forEach(i), f.clear()); | ||
}, | ||
o: t => f.add(t) | ||
}, u = { | ||
}, a = new Set; | ||
let f = 0; | ||
const _ = () => { | ||
--f || (a.forEach(s), a.clear()); | ||
}, u = t => a.add(t), m = { | ||
box: "border-box" | ||
}, m = new Uint32Array(0), d = 2147483647, S = [ "offsetHeight", "offsetWidth", "innerHeight", "innerWidth" ], v = [ "scrollTop", "scrollLeft", "scrollY", "scrollX" ], E = [ "blockSize", "inlineSize" ], z = [ "top", "left" ], T = (t, s) => Math.round(t.borderBoxSize[0][s]); | ||
}, d = new Uint32Array(0), S = 2147483647, v = [ "offsetHeight", "offsetWidth", "innerHeight", "innerWidth" ], E = [ "scrollTop", "scrollLeft", "scrollY", "scrollX" ], z = [ "blockSize", "inlineSize" ], b = [ "top", "left" ], y = (t, s) => Math.round(t.borderBoxSize[0][s]); | ||
class b { | ||
l=S[0]; | ||
_=v[0]; | ||
u=E[0]; | ||
m=z[0]; | ||
class p { | ||
t=v[0]; | ||
i=E[0]; | ||
h=z[0]; | ||
o=b[0]; | ||
l=0; | ||
_=0; | ||
u=0; | ||
m=0; | ||
S=0; | ||
v=0; | ||
p=0; | ||
T=0; | ||
p=0; | ||
M=0; | ||
O=0; | ||
I=0; | ||
R=0; | ||
k=6; | ||
L=40; | ||
C=null; | ||
H=null; | ||
F=m; | ||
K=m; | ||
A=0; | ||
M=6; | ||
O=40; | ||
I=null; | ||
R=null; | ||
k=d; | ||
C=d; | ||
L=0; | ||
horizontal=!1; | ||
@@ -63,97 +54,103 @@ scrollSize=0; | ||
sizesHash=0; | ||
P=new Map; | ||
U=new Map; | ||
W=[ null, null ]; | ||
G=[ 0, 0 ]; | ||
Z=new ResizeObserver((t => { | ||
F=new Map; | ||
H=new Map; | ||
K=[ null, null ]; | ||
A=[ 0, 0 ]; | ||
P=new ResizeObserver((t => { | ||
let s = 0; | ||
for (const i of t) { | ||
const t = this.W.indexOf(i.target); | ||
const t = this.K.indexOf(i.target); | ||
if (-1 !== t) { | ||
const e = T(i, this.u) - this.G[t]; | ||
this.G[t] += e, s += e; | ||
const e = y(i, this.h) - this.A[t]; | ||
this.A[t] += e, s += e; | ||
} | ||
} | ||
this.q(s); | ||
this.U(s); | ||
})); | ||
N=new ResizeObserver((t => { | ||
W=new ResizeObserver((t => { | ||
let s = 0, i = !1; | ||
const e = /*#__NOINLINE__*/ l(this.K, this.from + 1, this.to); | ||
const e = /*#__NOINLINE__*/ c(this.C, this.from + 1, this.to); | ||
for (const h of t) { | ||
const t = this.P.get(h.target); | ||
const t = this.F.get(h.target); | ||
if (e > t) { | ||
const r = T(h, this.u) - this.F[t]; | ||
r && (i = !0, this.F[t] += r, s += r, o(this.K, t + 1, r, e)); | ||
const r = y(h, this.h) - this.k[t]; | ||
r && (i = !0, this.k[t] += r, s += r, l(this.C, t + 1, r, e)); | ||
} | ||
} | ||
i && (_.i(), 0 !== s && (o(this.K, e, s, this.K.length), this.scrollSize += s, this.X(1), | ||
0 > s && this.Y()), this.sizesHash = this.sizesHash + 1 & d, this.X(2), _.h()); | ||
i && (++f, 0 !== s && (l(this.C, e, s, this.C.length), this.scrollSize += s, this.Z(1), | ||
0 > s && this.G()), this.sizesHash = this.sizesHash + 1 & S, this.Z(2), _()); | ||
})); | ||
$=s.map((() => [])); | ||
j() { | ||
const t = this.horizontal ? 1 : 0, s = t + 2 * (this.C instanceof HTMLElement ? 0 : 1); | ||
this.l = S[s], this._ = v[s], this.u = E[t], this.m = z[t]; | ||
N=[ [], [], [] ]; | ||
X() { | ||
const t = this.horizontal ? 1 : 0, s = t + 2 * (h(this.I) ? 0 : 1); | ||
this.t = v[s], this.i = E[s], this.h = z[t], this.o = b[t]; | ||
} | ||
B=() => { | ||
const t = this.C[this.l] - this.O; | ||
t !== this.R && (this.R = t, this.updateScrollerOffset(), this.Y()); | ||
Y=() => { | ||
const t = this.I[this.t] - this.v; | ||
t !== this.T && (this.T = t, this.updateScrollerOffset(), this.G()); | ||
}; | ||
q(t) { | ||
t && (this.O += t, this.R -= t, this.Y()); | ||
U(t) { | ||
t && (this.v += t, this.T -= t, this.G()); | ||
} | ||
D=() => {}; | ||
j=() => {}; | ||
constructor(t) { | ||
t && (this.horizontal = !!t.horizontal, this.M = t.estimatedScrollElementOffset || 0, | ||
this.R = t.estimatedWidgetSize ?? 200, this.set(t)); | ||
t && (this.horizontal = !!t.horizontal, this.S = t.estimatedScrollElementOffset || 0, | ||
this.T = t.estimatedWidgetSize ?? 200, this.set(t)); | ||
} | ||
on(t, s) { | ||
return s.forEach((s => this.$[s].push(t))), () => s.forEach((s => this.$[s].splice(this.$[s].indexOf(t) >>> 0, 1))); | ||
return s.forEach((s => this.N[s].push(t))), () => s.forEach((s => this.N[s].splice(this.N[s].indexOf(t) >>> 0, 1))); | ||
} | ||
X(t) { | ||
this.$[t].forEach(0 === _.t ? i : _.o); | ||
Z(t) { | ||
this.N[t].forEach(f ? u : s); | ||
} | ||
getIndex(t) { | ||
if (0 >= t) return 0; | ||
if (t >= this.scrollSize) return this.I - 1; | ||
if (t >= this.scrollSize) return this.p - 1; | ||
let s = 0; | ||
for (let i = this.A, e = 0; i > 0; i >>= 1) e = s + i, e <= this.I && t > this.K[e] && (s = e, | ||
t -= this.K[e]); | ||
for (let i = this.L, e = 0; i > 0; i >>= 1) e = s + i, e <= this.p && t > this.C[e] && (s = e, | ||
t -= this.C[e]); | ||
return s; | ||
} | ||
getOffset(t) { | ||
"production" !== process.env.NODE_ENV && e(t <= this.I, "index must not be > itemCount"); | ||
"production" !== process.env.NODE_ENV && i(t <= this.p, "index must not be > itemCount"); | ||
let s = 0; | ||
for (;t > 0; t -= t & -t) s += this.K[t]; | ||
for (;t > 0; t -= t & -t) s += this.C[t]; | ||
return s; | ||
} | ||
getSize(t) { | ||
return "production" !== process.env.NODE_ENV && e(t < this.F.length, "itemIndex must be < itemCount in getSize"), | ||
this.F[t]; | ||
return "production" !== process.env.NODE_ENV && i(t < this.k.length, "itemIndex must be < itemCount in getSize"), | ||
this.k[t]; | ||
} | ||
get visibleFrom() { | ||
const t = this.J; | ||
return t + (this.p - this.getOffset(t)) / this.F[t]; | ||
const t = this.q(); | ||
return t + (this.m - this.getOffset(t)) / this.k[t]; | ||
} | ||
V() { | ||
const t = this.p, s = Math.round(this.C[this._]) - this.M; | ||
s !== t && (this.p = s, s > t ? this.Y() : this.tt()); | ||
B() { | ||
const t = this.m, s = Math.round(this.I[this.i]) - this.S; | ||
s !== t && (this.m = s, s > t ? this.G() : this.D()); | ||
} | ||
st=t => { | ||
this.S = t.timeStamp, this.V(); | ||
J=t => { | ||
this.l = t.timeStamp, this.B(); | ||
}; | ||
setScroller(t) { | ||
t !== this.C && (clearInterval(this.v), clearTimeout(this.T), this.D(), this.C?.removeEventListener("scroll", this.st), | ||
this.C = t, t && (this.j(), this.D = /*#__NOINLINE__*/ h(t, this.B), t.addEventListener("scroll", this.st, { | ||
passive: !0 | ||
}), this.updateScrollerOffset(), this.V())); | ||
if (this.I && (clearInterval(this._), clearTimeout(this.u), this.j(), this.I.removeEventListener("scroll", this.J)), | ||
this.I = t, t) { | ||
if (this.X(), h(t)) { | ||
const s = new ResizeObserver(this.Y); | ||
s.observe(t), this.j = () => s.disconnect(); | ||
} else this.Y(), addEventListener("resize", this.Y), this.j = () => removeEventListener("resize", this.Y); | ||
t.addEventListener("scroll", this.J, { | ||
passive: !0 | ||
}), this.updateScrollerOffset(), this.B(); | ||
} | ||
} | ||
setContainer(t) { | ||
t !== this.H && (this.H = t, this.updateScrollerOffset()); | ||
t !== this.R && (this.R = t, this.updateScrollerOffset()); | ||
} | ||
updateScrollerOffset() { | ||
clearTimeout(this.T), this.T = setTimeout((() => { | ||
if (this.C) { | ||
clearTimeout(this.u), this.u = setTimeout((() => { | ||
if (this.I) { | ||
const t = | ||
/*#__NOINLINE__*/ a(this.C, this.H, this._, this.m), s = t - this.M; | ||
s && (this.M = t, this.p -= s, this.V()); | ||
/*#__NOINLINE__*/ o(this.I, this.R, this.i, this.o), s = t - this.S; | ||
s && (this.S = t, this.m -= s, this.B()); | ||
} | ||
@@ -163,34 +160,34 @@ }), 256); | ||
el(t, s) { | ||
const i = this.U.get(t); | ||
i && (this.U.delete(t), this.P.delete(i), this.N.unobserve(i)), s && (this.P.set(s, t), | ||
this.U.set(t, s), this.N.observe(s, u)); | ||
const i = this.H.get(t); | ||
i && (this.H.delete(t), this.F.delete(i), this.W.unobserve(i)), s && (this.F.set(s, t), | ||
this.H.set(t, s), this.W.observe(s, m)); | ||
} | ||
it(t, s) { | ||
const i = this.W[t]; | ||
i && (this.Z.unobserve(i), this.q(-this.G[t]), this.W[t] = null, this.G[t] = 0), | ||
s && (this.W[t] = s, this.Z.observe(s, u)); | ||
V(t, s) { | ||
const i = this.K[t]; | ||
i && (this.P.unobserve(i), this.U(-this.A[t]), this.K[t] = null, this.A[t] = 0), | ||
s && (this.K[t] = s, this.P.observe(s, m)); | ||
} | ||
setStickyHeader(t) { | ||
this.it(0, t); | ||
this.V(0, t); | ||
} | ||
setStickyFooter(t) { | ||
this.it(1, t); | ||
this.V(1, t); | ||
} | ||
get J() { | ||
return this.getIndex(this.p); | ||
q() { | ||
return this.getIndex(this.m); | ||
} | ||
get et() { | ||
return this.I && 1 + this.getIndex(this.p + this.R); | ||
$() { | ||
return this.p && 1 + this.getIndex(this.m + this.T); | ||
} | ||
Y() { | ||
const {et: t} = this; | ||
t > this.to && (this.to = Math.min(this.I, t + this.k), this.from = this.J, this.X(0)); | ||
G() { | ||
const t = this.$(); | ||
t > this.to && (this.to = Math.min(this.p, t + this.M), this.from = this.q(), this.Z(0)); | ||
} | ||
tt() { | ||
const {J: t} = this; | ||
t < this.from && (this.from = Math.max(0, t - this.k), this.to = this.et, this.X(0)); | ||
D() { | ||
const t = this.q(); | ||
t < this.from && (this.from = Math.max(0, t - this.M), this.to = this.$(), this.Z(0)); | ||
} | ||
scrollToOffset(t, s) { | ||
this.C?.scroll({ | ||
[this.m]: this.M + t, | ||
this.I?.scroll({ | ||
[this.o]: this.S + t, | ||
behavior: s ? "smooth" : "instant" | ||
@@ -200,8 +197,8 @@ }); | ||
scrollToIndex(t, s) { | ||
clearInterval(this.v); | ||
clearInterval(this._); | ||
let i = 5; | ||
this.v = setInterval((() => { | ||
if (!s || performance.now() - this.S > 128) { | ||
--i || clearInterval(this.v); | ||
const e = Math.trunc(t), h = Math.min(this.scrollSize - this.R, this.getOffset(e) + Math.round(this.F[e] * (t - e))); | ||
this._ = setInterval((() => { | ||
if (!s || performance.now() - this.l > 128) { | ||
--i || clearInterval(this._); | ||
const e = Math.trunc(t), h = Math.min(this.scrollSize - this.T, this.getOffset(e) + Math.round(this.k[e] * (t - e))); | ||
this.scrollToOffset(h, s); | ||
@@ -212,15 +209,15 @@ } | ||
setItemCount(t) { | ||
if (this.I !== t) { | ||
if (_.i(), e(d >= t, `itemCount must be <= 2147483647. Got: ${t}.`), this.I = t, | ||
this.A = t && 1 << 31 - Math.clz32(t), t > this.F.length) { | ||
const s = Math.min(t + 32, d); | ||
this.F = /*#__NOINLINE__*/ r(this.F, s, this.L || 40), this.K = new Uint32Array(s + 1), | ||
/*#__NOINLINE__*/ n(this.K, this.F); | ||
if (this.p !== t) { | ||
if (++f, i(S >= t, "itemCount must be <= " + S), this.p = t, this.L = t && 1 << 31 - Math.clz32(t), | ||
t > this.k.length) { | ||
const s = Math.min(t + 32, S); | ||
this.k = /*#__NOINLINE__*/ e(this.k, s, this.O || 40), this.C = new Uint32Array(s + 1), | ||
/*#__NOINLINE__*/ n(this.C, this.k); | ||
} | ||
this.scrollSize = this.getOffset(t), this.X(1), this.to > t && (this.to = -1), this.Y(), | ||
_.h(); | ||
this.scrollSize = this.getOffset(t), this.Z(1), this.to > t && (this.to = -1), this.G(), | ||
_(); | ||
} | ||
} | ||
set(t) { | ||
t.estimatedItemSize && (this.L = t.estimatedItemSize), void 0 !== t.overscanCount && (this.k = t.overscanCount), | ||
t.estimatedItemSize && (this.O = t.estimatedItemSize), void 0 !== t.overscanCount && (this.M = t.overscanCount), | ||
void 0 !== t.itemCount && this.setItemCount(t.itemCount); | ||
@@ -230,3 +227,3 @@ } | ||
export { b as VirtualScroller, t as VirtualScrollerEvent }; | ||
export { p as VirtualScroller, t as VirtualScrollerEvent }; | ||
//# sourceMappingURL=index.js.map |
@@ -11,58 +11,45 @@ global.ResizeObserver ||= class { | ||
SIZES: 2 | ||
}, s = [ 0, 1, 2 ], i = t => t(), e = (t, s) => { | ||
}, s = t => t(), i = (t, s) => { | ||
if (!t) throw Error(s); | ||
}, h = (t, s) => { | ||
if (t instanceof HTMLElement) { | ||
const i = new ResizeObserver(s); | ||
return i.observe(t), () => i.disconnect(); | ||
} | ||
return s(), addEventListener("resize", s), () => removeEventListener("resize", s); | ||
}, r = (t, s, i) => { | ||
}, e = (t, s, i) => { | ||
const e = new Uint32Array(s); | ||
return e.set(t), e.fill(i, t.length), e; | ||
}, o = (t, s) => { | ||
}, h = t => t instanceof HTMLElement, r = (t, s) => t.getBoundingClientRect()[s], o = (t, s, i, e) => s && t && t !== s ? t[i] + Math.round(r(s, e) - (h(t) ? r(t, e) : 0)) : 0, n = (t, s) => { | ||
t.set(s, 1); | ||
for (let s, i = 1, e = t.length; e > i; i++) s = i + (i & -i), e > s && (t[s] += t[i]); | ||
}, n = (t, s, i, e) => { | ||
}, l = (t, s, i, e) => { | ||
for (;e > s; s += s & -s) t[s] += i; | ||
}, l = (t, s, i) => { | ||
}, c = (t, s, i) => { | ||
for (;i > s; s += s & -s) ; | ||
return Math.min(s, t.length); | ||
}, c = (t, s) => t.getBoundingClientRect()[s], a = (t, s, i, e) => s && t && t !== s ? t[i] + Math.round(c(s, e) - (t instanceof HTMLElement ? c(t, e) : 0)) : 0, f = new Set; | ||
}, a = new Set; | ||
var _ = { | ||
t: 0, | ||
i() { | ||
this.t++; | ||
}, | ||
h() { | ||
0 == --this.t && (f.forEach(i), f.clear()); | ||
}, | ||
o: t => f.add(t) | ||
}; | ||
let f = 0; | ||
const u = { | ||
const u = () => { | ||
--f || (a.forEach(s), a.clear()); | ||
}, _ = t => a.add(t), m = { | ||
box: "border-box" | ||
}, m = new Uint32Array(0), d = 2147483647, v = [ "offsetHeight", "offsetWidth", "innerHeight", "innerWidth" ], S = [ "scrollTop", "scrollLeft", "scrollY", "scrollX" ], E = [ "blockSize", "inlineSize" ], z = [ "top", "left" ], b = (t, s) => Math.round(t.borderBoxSize[0][s]); | ||
}, d = new Uint32Array(0), S = 2147483647, v = [ "offsetHeight", "offsetWidth", "innerHeight", "innerWidth" ], E = [ "scrollTop", "scrollLeft", "scrollY", "scrollX" ], z = [ "blockSize", "inlineSize" ], b = [ "top", "left" ], y = (t, s) => Math.round(t.borderBoxSize[0][s]); | ||
class T { | ||
l=v[0]; | ||
_=S[0]; | ||
u=E[0]; | ||
m=z[0]; | ||
class p { | ||
t=v[0]; | ||
i=E[0]; | ||
h=z[0]; | ||
o=b[0]; | ||
l=0; | ||
u=0; | ||
_=0; | ||
m=0; | ||
S=0; | ||
v=0; | ||
S=0; | ||
p=0; | ||
T=0; | ||
p=0; | ||
M=0; | ||
O=0; | ||
I=0; | ||
R=0; | ||
k=6; | ||
L=40; | ||
C=null; | ||
H=null; | ||
F=m; | ||
K=m; | ||
A=0; | ||
M=6; | ||
O=40; | ||
I=null; | ||
R=null; | ||
k=d; | ||
C=d; | ||
L=0; | ||
horizontal=!1; | ||
@@ -73,97 +60,103 @@ scrollSize=0; | ||
sizesHash=0; | ||
P=new Map; | ||
U=new Map; | ||
W=[ null, null ]; | ||
G=[ 0, 0 ]; | ||
Z=new ResizeObserver((t => { | ||
F=new Map; | ||
H=new Map; | ||
K=[ null, null ]; | ||
A=[ 0, 0 ]; | ||
P=new ResizeObserver((t => { | ||
let s = 0; | ||
for (const i of t) { | ||
const t = this.W.indexOf(i.target); | ||
const t = this.K.indexOf(i.target); | ||
if (-1 !== t) { | ||
const e = b(i, this.u) - this.G[t]; | ||
this.G[t] += e, s += e; | ||
const e = y(i, this.h) - this.A[t]; | ||
this.A[t] += e, s += e; | ||
} | ||
} | ||
this.q(s); | ||
this.U(s); | ||
})); | ||
N=new ResizeObserver((t => { | ||
W=new ResizeObserver((t => { | ||
let s = 0, i = !1; | ||
const e = /*#__NOINLINE__*/ l(this.K, this.from + 1, this.to); | ||
const e = /*#__NOINLINE__*/ c(this.C, this.from + 1, this.to); | ||
for (const h of t) { | ||
const t = this.P.get(h.target); | ||
const t = this.F.get(h.target); | ||
if (e > t) { | ||
const r = b(h, this.u) - this.F[t]; | ||
r && (i = !0, this.F[t] += r, s += r, n(this.K, t + 1, r, e)); | ||
const r = y(h, this.h) - this.k[t]; | ||
r && (i = !0, this.k[t] += r, s += r, l(this.C, t + 1, r, e)); | ||
} | ||
} | ||
i && (_.i(), 0 !== s && (n(this.K, e, s, this.K.length), this.scrollSize += s, this.X(1), | ||
0 > s && this.Y()), this.sizesHash = this.sizesHash + 1 & d, this.X(2), _.h()); | ||
i && (++f, 0 !== s && (l(this.C, e, s, this.C.length), this.scrollSize += s, this.Z(1), | ||
0 > s && this.G()), this.sizesHash = this.sizesHash + 1 & S, this.Z(2), u()); | ||
})); | ||
$=s.map((() => [])); | ||
j() { | ||
const t = this.horizontal ? 1 : 0, s = t + 2 * (this.C instanceof HTMLElement ? 0 : 1); | ||
this.l = v[s], this._ = S[s], this.u = E[t], this.m = z[t]; | ||
N=[ [], [], [] ]; | ||
X() { | ||
const t = this.horizontal ? 1 : 0, s = t + 2 * (h(this.I) ? 0 : 1); | ||
this.t = v[s], this.i = E[s], this.h = z[t], this.o = b[t]; | ||
} | ||
B=() => { | ||
const t = this.C[this.l] - this.O; | ||
t !== this.R && (this.R = t, this.updateScrollerOffset(), this.Y()); | ||
Y=() => { | ||
const t = this.I[this.t] - this.v; | ||
t !== this.T && (this.T = t, this.updateScrollerOffset(), this.G()); | ||
}; | ||
q(t) { | ||
t && (this.O += t, this.R -= t, this.Y()); | ||
U(t) { | ||
t && (this.v += t, this.T -= t, this.G()); | ||
} | ||
D=() => {}; | ||
j=() => {}; | ||
constructor(t) { | ||
t && (this.horizontal = !!t.horizontal, this.M = t.estimatedScrollElementOffset || 0, | ||
this.R = t.estimatedWidgetSize ?? 200, this.set(t)); | ||
t && (this.horizontal = !!t.horizontal, this.S = t.estimatedScrollElementOffset || 0, | ||
this.T = t.estimatedWidgetSize ?? 200, this.set(t)); | ||
} | ||
on(t, s) { | ||
return s.forEach((s => this.$[s].push(t))), () => s.forEach((s => this.$[s].splice(this.$[s].indexOf(t) >>> 0, 1))); | ||
return s.forEach((s => this.N[s].push(t))), () => s.forEach((s => this.N[s].splice(this.N[s].indexOf(t) >>> 0, 1))); | ||
} | ||
X(t) { | ||
this.$[t].forEach(0 === _.t ? i : _.o); | ||
Z(t) { | ||
this.N[t].forEach(f ? _ : s); | ||
} | ||
getIndex(t) { | ||
if (0 >= t) return 0; | ||
if (t >= this.scrollSize) return this.I - 1; | ||
if (t >= this.scrollSize) return this.p - 1; | ||
let s = 0; | ||
for (let i = this.A, e = 0; i > 0; i >>= 1) e = s + i, e <= this.I && t > this.K[e] && (s = e, | ||
t -= this.K[e]); | ||
for (let i = this.L, e = 0; i > 0; i >>= 1) e = s + i, e <= this.p && t > this.C[e] && (s = e, | ||
t -= this.C[e]); | ||
return s; | ||
} | ||
getOffset(t) { | ||
"production" !== process.env.NODE_ENV && e(t <= this.I, "index must not be > itemCount"); | ||
"production" !== process.env.NODE_ENV && i(t <= this.p, "index must not be > itemCount"); | ||
let s = 0; | ||
for (;t > 0; t -= t & -t) s += this.K[t]; | ||
for (;t > 0; t -= t & -t) s += this.C[t]; | ||
return s; | ||
} | ||
getSize(t) { | ||
return "production" !== process.env.NODE_ENV && e(t < this.F.length, "itemIndex must be < itemCount in getSize"), | ||
this.F[t]; | ||
return "production" !== process.env.NODE_ENV && i(t < this.k.length, "itemIndex must be < itemCount in getSize"), | ||
this.k[t]; | ||
} | ||
get visibleFrom() { | ||
const t = this.J; | ||
return t + (this.p - this.getOffset(t)) / this.F[t]; | ||
const t = this.q(); | ||
return t + (this.m - this.getOffset(t)) / this.k[t]; | ||
} | ||
V() { | ||
const t = this.p, s = Math.round(this.C[this._]) - this.M; | ||
s !== t && (this.p = s, s > t ? this.Y() : this.tt()); | ||
B() { | ||
const t = this.m, s = Math.round(this.I[this.i]) - this.S; | ||
s !== t && (this.m = s, s > t ? this.G() : this.D()); | ||
} | ||
st=t => { | ||
this.v = t.timeStamp, this.V(); | ||
J=t => { | ||
this.l = t.timeStamp, this.B(); | ||
}; | ||
setScroller(t) { | ||
t !== this.C && (clearInterval(this.S), clearTimeout(this.T), this.D(), this.C?.removeEventListener("scroll", this.st), | ||
this.C = t, t && (this.j(), this.D = /*#__NOINLINE__*/ h(t, this.B), t.addEventListener("scroll", this.st, { | ||
passive: !0 | ||
}), this.updateScrollerOffset(), this.V())); | ||
if (this.I && (clearInterval(this.u), clearTimeout(this._), this.j(), this.I.removeEventListener("scroll", this.J)), | ||
this.I = t, t) { | ||
if (this.X(), h(t)) { | ||
const s = new ResizeObserver(this.Y); | ||
s.observe(t), this.j = () => s.disconnect(); | ||
} else this.Y(), addEventListener("resize", this.Y), this.j = () => removeEventListener("resize", this.Y); | ||
t.addEventListener("scroll", this.J, { | ||
passive: !0 | ||
}), this.updateScrollerOffset(), this.B(); | ||
} | ||
} | ||
setContainer(t) { | ||
t !== this.H && (this.H = t, this.updateScrollerOffset()); | ||
t !== this.R && (this.R = t, this.updateScrollerOffset()); | ||
} | ||
updateScrollerOffset() { | ||
clearTimeout(this.T), this.T = setTimeout((() => { | ||
if (this.C) { | ||
clearTimeout(this._), this._ = setTimeout((() => { | ||
if (this.I) { | ||
const t = | ||
/*#__NOINLINE__*/ a(this.C, this.H, this._, this.m), s = t - this.M; | ||
s && (this.M = t, this.p -= s, this.V()); | ||
/*#__NOINLINE__*/ o(this.I, this.R, this.i, this.o), s = t - this.S; | ||
s && (this.S = t, this.m -= s, this.B()); | ||
} | ||
@@ -173,34 +166,34 @@ }), 256); | ||
el(t, s) { | ||
const i = this.U.get(t); | ||
i && (this.U.delete(t), this.P.delete(i), this.N.unobserve(i)), s && (this.P.set(s, t), | ||
this.U.set(t, s), this.N.observe(s, u)); | ||
const i = this.H.get(t); | ||
i && (this.H.delete(t), this.F.delete(i), this.W.unobserve(i)), s && (this.F.set(s, t), | ||
this.H.set(t, s), this.W.observe(s, m)); | ||
} | ||
it(t, s) { | ||
const i = this.W[t]; | ||
i && (this.Z.unobserve(i), this.q(-this.G[t]), this.W[t] = null, this.G[t] = 0), | ||
s && (this.W[t] = s, this.Z.observe(s, u)); | ||
V(t, s) { | ||
const i = this.K[t]; | ||
i && (this.P.unobserve(i), this.U(-this.A[t]), this.K[t] = null, this.A[t] = 0), | ||
s && (this.K[t] = s, this.P.observe(s, m)); | ||
} | ||
setStickyHeader(t) { | ||
this.it(0, t); | ||
this.V(0, t); | ||
} | ||
setStickyFooter(t) { | ||
this.it(1, t); | ||
this.V(1, t); | ||
} | ||
get J() { | ||
return this.getIndex(this.p); | ||
q() { | ||
return this.getIndex(this.m); | ||
} | ||
get et() { | ||
return this.I && 1 + this.getIndex(this.p + this.R); | ||
$() { | ||
return this.p && 1 + this.getIndex(this.m + this.T); | ||
} | ||
Y() { | ||
const {et: t} = this; | ||
t > this.to && (this.to = Math.min(this.I, t + this.k), this.from = this.J, this.X(0)); | ||
G() { | ||
const t = this.$(); | ||
t > this.to && (this.to = Math.min(this.p, t + this.M), this.from = this.q(), this.Z(0)); | ||
} | ||
tt() { | ||
const {J: t} = this; | ||
t < this.from && (this.from = Math.max(0, t - this.k), this.to = this.et, this.X(0)); | ||
D() { | ||
const t = this.q(); | ||
t < this.from && (this.from = Math.max(0, t - this.M), this.to = this.$(), this.Z(0)); | ||
} | ||
scrollToOffset(t, s) { | ||
this.C?.scroll({ | ||
[this.m]: this.M + t, | ||
this.I?.scroll({ | ||
[this.o]: this.S + t, | ||
behavior: s ? "smooth" : "instant" | ||
@@ -210,8 +203,8 @@ }); | ||
scrollToIndex(t, s) { | ||
clearInterval(this.S); | ||
clearInterval(this.u); | ||
let i = 5; | ||
this.S = setInterval((() => { | ||
if (!s || performance.now() - this.v > 128) { | ||
--i || clearInterval(this.S); | ||
const e = Math.trunc(t), h = Math.min(this.scrollSize - this.R, this.getOffset(e) + Math.round(this.F[e] * (t - e))); | ||
this.u = setInterval((() => { | ||
if (!s || performance.now() - this.l > 128) { | ||
--i || clearInterval(this.u); | ||
const e = Math.trunc(t), h = Math.min(this.scrollSize - this.T, this.getOffset(e) + Math.round(this.k[e] * (t - e))); | ||
this.scrollToOffset(h, s); | ||
@@ -222,15 +215,15 @@ } | ||
setItemCount(t) { | ||
if (this.I !== t) { | ||
if (_.i(), e(d >= t, `itemCount must be <= 2147483647. Got: ${t}.`), this.I = t, | ||
this.A = t && 1 << 31 - Math.clz32(t), t > this.F.length) { | ||
const s = Math.min(t + 32, d); | ||
this.F = /*#__NOINLINE__*/ r(this.F, s, this.L || 40), this.K = new Uint32Array(s + 1), | ||
/*#__NOINLINE__*/ o(this.K, this.F); | ||
if (this.p !== t) { | ||
if (++f, i(S >= t, "itemCount must be <= " + S), this.p = t, this.L = t && 1 << 31 - Math.clz32(t), | ||
t > this.k.length) { | ||
const s = Math.min(t + 32, S); | ||
this.k = /*#__NOINLINE__*/ e(this.k, s, this.O || 40), this.C = new Uint32Array(s + 1), | ||
/*#__NOINLINE__*/ n(this.C, this.k); | ||
} | ||
this.scrollSize = this.getOffset(t), this.X(1), this.to > t && (this.to = -1), this.Y(), | ||
_.h(); | ||
this.scrollSize = this.getOffset(t), this.Z(1), this.to > t && (this.to = -1), this.G(), | ||
u(); | ||
} | ||
} | ||
set(t) { | ||
t.estimatedItemSize && (this.L = t.estimatedItemSize), void 0 !== t.overscanCount && (this.k = t.overscanCount), | ||
t.estimatedItemSize && (this.O = t.estimatedItemSize), void 0 !== t.overscanCount && (this.M = t.overscanCount), | ||
void 0 !== t.itemCount && this.setItemCount(t.itemCount); | ||
@@ -240,2 +233,2 @@ } | ||
export { T as VirtualScroller, t as VirtualScrollerEvent }; | ||
export { p as VirtualScroller, t as VirtualScrollerEvent }; |
{ | ||
"name": "@af-utils/virtual-core", | ||
"private": false, | ||
"version": "0.0.20", | ||
"version": "0.0.21", | ||
"description": "Model for rendering large scrollable data", | ||
"repository": "https://github.com/nowaalex/af-utils.git", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/nowaalex/af-utils.git", | ||
"directory": "packages/virtual/core" | ||
}, | ||
"homepage": "https://af-utils.vercel.app/virtual", | ||
"bugs": "https://github.com/nowaalex/af-utils/issues", | ||
"homepage": "https://af-utils.vercel.app/", | ||
"author": "Alex Fomin <nowaalex@gmail.com> (https://github.com/nowaalex/)", | ||
@@ -27,3 +31,3 @@ "license": "MIT", | ||
"engines": { | ||
"node": ">=13.2" | ||
"node": ">20.0.0" | ||
}, | ||
@@ -48,3 +52,3 @@ "keywords": [ | ||
"@rollup/plugin-typescript": "^11.1.6", | ||
"rollup": "^4.9.6", | ||
"rollup": "^4.12.1", | ||
"ts-jest": "^29.1.2", | ||
@@ -58,5 +62,5 @@ "@af-utils/rollup-plugin-export-bundle-size": "0.0.5" | ||
"dev": "rollup -w -c rollup.config.ts --configPlugin typescript & tsc-alias -w", | ||
"build": "rollup -c rollup.config.ts --configPlugin typescript && tsc-alias && api-extractor run -v && rm -r lib/types", | ||
"build": "rollup -c rollup.config.ts --configPlugin typescript && tsc-alias && api-extractor run && rm -r lib/types", | ||
"test": "jest" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
0
73690
862