@af-utils/virtual-core
Advanced tools
Comparing version 0.0.15 to 0.0.16
@@ -1,4 +0,4 @@ | ||
export declare const raw = 7633; | ||
export declare const min = 4804; | ||
export declare const minGz = 2119; | ||
export declare const minBrotli = 1935; | ||
export declare const raw = 7482; | ||
export declare const min = 4803; | ||
export declare const minGz = 2105; | ||
export declare const minBrotli = 1928; |
@@ -1,4 +0,4 @@ | ||
export const raw = 7633; | ||
export const min = 4804; | ||
export const minGz = 2119; | ||
export const minBrotli = 1935; | ||
export const raw = 7482; | ||
export const min = 4803; | ||
export const minGz = 2105; | ||
export const minBrotli = 1928; |
@@ -98,8 +98,2 @@ /** | ||
/** | ||
* Unsubscribe from model events | ||
* @param callBack - callBack to unsubscribe | ||
* @param events - events to unsubscribe | ||
*/ | ||
private _off; | ||
/** | ||
* Subscribe to model events | ||
@@ -106,0 +100,0 @@ * @returns unsubscribe function |
154
lib/index.js
@@ -5,27 +5,22 @@ const t = { | ||
SIZES: 2 | ||
}, s = [ 0, 1, 2 ], i = Uint32Array, e = "test" === process.env.NODE_ENV ? class { | ||
constructor(t) {} | ||
observe() {} | ||
unobserve() {} | ||
disconnect() {} | ||
} : ResizeObserver, h = t => t(), r = (t, s) => { | ||
}, s = [ 0, 1, 2 ], i = Uint32Array, e = t => t(), h = (t, s) => { | ||
if (!t) throw Error(s); | ||
}, o = (t, s) => { | ||
}, r = (t, s) => { | ||
if (t instanceof HTMLElement) { | ||
const i = new e(s); | ||
const i = new ResizeObserver(s); | ||
return i.observe(t), () => i.disconnect(); | ||
} | ||
return s(), addEventListener("resize", s), () => removeEventListener("resize", s); | ||
}, n = (t, s, e) => { | ||
}, o = (t, s, e) => { | ||
const h = new i(s); | ||
return h.set(t), h.fill(e, t.length), h; | ||
}, l = (t, s) => { | ||
}, 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]); | ||
}, c = (t, s, i, e) => { | ||
}, l = (t, s, i, e) => { | ||
for (;e > s; s += s & -s) t[s] += i; | ||
}, a = (t, s, i) => { | ||
}, c = (t, s, i) => { | ||
for (;i > s; s += s & -s) ; | ||
return Math.min(s, t.length); | ||
}, f = (t, s) => t.getBoundingClientRect()[s], _ = (t, s, i, e) => s && t && t !== s ? t[i] + Math.round(f(s, e) - (t instanceof HTMLElement ? f(t, e) : 0)) : 0, u = new Set, m = { | ||
}, a = (t, s) => t.getBoundingClientRect()[s], f = (t, s, i, e) => s && t && t !== s ? t[i] + Math.round(a(s, e) - (t instanceof HTMLElement ? a(t, e) : 0)) : 0, _ = new Set, u = { | ||
t: 0, | ||
@@ -36,14 +31,14 @@ i() { | ||
h() { | ||
0 == --this.t && (u.forEach(h), u.clear()); | ||
0 == --this.t && (_.forEach(e), _.clear()); | ||
}, | ||
o: t => u.add(t) | ||
}, d = { | ||
o: t => _.add(t) | ||
}, m = { | ||
box: "border-box" | ||
}, S = 2147483647, v = new i(0), E = [ "offsetHeight", "offsetWidth", "innerHeight", "innerWidth" ], z = [ "scrollTop", "scrollLeft", "scrollY", "scrollX" ], T = [ "blockSize", "inlineSize" ], b = [ "top", "left" ], p = (t, s) => Math.round(t[0][s]); | ||
}, d = 2147483647, S = new i(0), v = [ "offsetHeight", "offsetWidth", "innerHeight", "innerWidth" ], E = [ "scrollTop", "scrollLeft", "scrollY", "scrollX" ], z = [ "blockSize", "inlineSize" ], T = [ "top", "left" ], b = (t, s) => Math.round(t[0][s]); | ||
class y { | ||
l=E[0]; | ||
_=z[0]; | ||
u=T[0]; | ||
m=b[0]; | ||
class p { | ||
l=v[0]; | ||
_=E[0]; | ||
u=z[0]; | ||
m=T[0]; | ||
S=0; | ||
@@ -54,11 +49,11 @@ v=0; | ||
M=0; | ||
O=0; | ||
I=0; | ||
O=0; | ||
k=0; | ||
L=6; | ||
R=40; | ||
R=0; | ||
k=6; | ||
L=40; | ||
C=null; | ||
H=null; | ||
F=v; | ||
K=v; | ||
F=S; | ||
K=S; | ||
P=0; | ||
@@ -74,3 +69,3 @@ horizontal=!1; | ||
Z=[ 0, 0 ]; | ||
q=new e((t => { | ||
q=new ResizeObserver((t => { | ||
let s = 0; | ||
@@ -80,3 +75,3 @@ for (const i of t) { | ||
if (-1 !== t) { | ||
const e = p(i.borderBoxSize, this.u) - this.Z[t]; | ||
const e = b(i.borderBoxSize, this.u) - this.Z[t]; | ||
this.Z[t] += e, s += e; | ||
@@ -87,14 +82,14 @@ } | ||
})); | ||
U=new e((t => { | ||
U=new ResizeObserver((t => { | ||
let s = 0, i = !1; | ||
const e = a(this.K, this.from + 1, this.to); | ||
const e = c(this.K, this.from + 1, this.to); | ||
for (const h of t) { | ||
const t = this.W.get(h.target); | ||
if (e > t) { | ||
const r = p(h.borderBoxSize, this.u) - this.F[t]; | ||
r && (i = !0, this.F[t] += r, s += r, c(this.K, t + 1, r, e)); | ||
const r = b(h.borderBoxSize, this.u) - this.F[t]; | ||
r && (i = !0, this.F[t] += r, s += r, l(this.K, t + 1, r, e)); | ||
} | ||
} | ||
i && (m.i(), 0 !== s && (c(this.K, e, s, this.K.length), this.scrollSize += s, this.X(1), | ||
0 > s && this.Y()), this.sizesHash = this.sizesHash + 1 & S, this.X(2), m.h()); | ||
i && (u.i(), 0 !== s && (l(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), u.h()); | ||
})); | ||
@@ -104,11 +99,11 @@ $=s.map((() => [])); | ||
const t = this.horizontal ? 1 : 0, s = t + 2 * (this.C instanceof HTMLElement ? 0 : 1); | ||
this.l = E[s], this._ = z[s], this.u = T[t], this.m = b[t]; | ||
this.l = v[s], this._ = E[s], this.u = z[t], this.m = T[t]; | ||
} | ||
B=() => { | ||
const t = (s = this.C, i = this.l, e = this.I, s[i] - e); | ||
const t = (s = this.C, i = this.l, e = this.O, s[i] - e); | ||
var s, i, e; | ||
t !== this.k && (this.k = t, this.updateScrollerOffset(), this.Y()); | ||
t !== this.R && (this.R = t, this.updateScrollerOffset(), this.Y()); | ||
}; | ||
N(t) { | ||
t && (this.I += t, this.k -= t, this.Y()); | ||
t && (this.O += t, this.R -= t, this.Y()); | ||
} | ||
@@ -118,18 +113,15 @@ D=() => {}; | ||
t && (this.horizontal = !!t.horizontal, this.M = t.estimatedScrollElementOffset || 0, | ||
this.k = t.estimatedWidgetSize ?? 200, this.set(t)); | ||
this.R = t.estimatedWidgetSize ?? 200, this.set(t)); | ||
} | ||
J(t, s) { | ||
s.forEach((s => this.$[s].splice(this.$[s].indexOf(t) >>> 0, 1))); | ||
} | ||
on(t, s) { | ||
return s.forEach((s => this.$[s].push(t))), () => this.J(t, s); | ||
return s.forEach((s => this.$[s].push(t))), () => s.forEach((s => this.$[s].splice(this.$[s].indexOf(t) >>> 0, 1))); | ||
} | ||
X(t) { | ||
this.$[t].forEach(0 === m.t ? h : m.o); | ||
this.$[t].forEach(0 === u.t ? e : u.o); | ||
} | ||
getIndex(t) { | ||
if (0 >= t) return 0; | ||
if (t >= this.scrollSize) return this.O - 1; | ||
if (t >= this.scrollSize) return this.I - 1; | ||
let s = 0; | ||
for (let i = this.P, e = 0; i > 0; i >>= 1) e = s + i, e <= this.O && t > this.K[e] && (s = e, | ||
for (let i = this.P, e = 0; i > 0; i >>= 1) e = s + i, e <= this.I && t > this.K[e] && (s = e, | ||
t -= this.K[e]); | ||
@@ -139,3 +131,3 @@ return s; | ||
getOffset(t) { | ||
"production" !== process.env.NODE_ENV && r(t <= this.O, "index must not be > itemCount"); | ||
"production" !== process.env.NODE_ENV && h(t <= this.I, "index must not be > itemCount"); | ||
let s = 0; | ||
@@ -146,21 +138,21 @@ for (;t > 0; t -= t & -t) s += this.K[t]; | ||
getSize(t) { | ||
return "production" !== process.env.NODE_ENV && r(t < this.F.length, "itemIndex must be < itemCount in getSize"), | ||
return "production" !== process.env.NODE_ENV && h(t < this.F.length, "itemIndex must be < itemCount in getSize"), | ||
this.F[t]; | ||
} | ||
get visibleFrom() { | ||
const t = this.V; | ||
const t = this.J; | ||
return t + (this.p - this.getOffset(t)) / this.F[t]; | ||
} | ||
tt() { | ||
V() { | ||
const t = this.p, s = Math.round(this.C[this._]) - this.M; | ||
s !== t && (this.p = s, s > t ? this.Y() : this.st()); | ||
s !== t && (this.p = s, s > t ? this.Y() : this.tt()); | ||
} | ||
it=t => { | ||
this.S = t.timeStamp, this.tt(); | ||
st=t => { | ||
this.S = t.timeStamp, this.V(); | ||
}; | ||
setScroller(t) { | ||
t !== this.C && (clearInterval(this.v), clearTimeout(this.T), this.D(), this.C?.removeEventListener("scroll", this.it), | ||
this.C = t, t && (this.j(), this.D = o(t, this.B), t.addEventListener("scroll", this.it, { | ||
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 = r(t, this.B), t.addEventListener("scroll", this.st, { | ||
passive: !0 | ||
}), this.updateScrollerOffset(), this.tt())); | ||
}), this.updateScrollerOffset(), this.V())); | ||
} | ||
@@ -173,4 +165,4 @@ setContainer(t) { | ||
if (this.C) { | ||
const t = _(this.C, this.H, this._, this.m), s = t - this.M; | ||
s && (this.M = t, this.p -= s, this.tt()); | ||
const t = f(this.C, this.H, this._, this.m), s = t - this.M; | ||
s && (this.M = t, this.p -= s, this.V()); | ||
} | ||
@@ -182,28 +174,28 @@ }), 256); | ||
i && (this.A.delete(t), this.W.delete(i), this.U.unobserve(i)), s && (this.W.set(s, t), | ||
this.A.set(t, s), this.U.observe(s, d)); | ||
this.A.set(t, s), this.U.observe(s, m)); | ||
} | ||
et(t, s) { | ||
it(t, s) { | ||
const i = this.G[t]; | ||
i && (this.q.unobserve(i), this.N(-this.Z[t]), this.G[t] = null, this.Z[t] = 0), | ||
s && (this.G[t] = s, this.q.observe(s, d)); | ||
s && (this.G[t] = s, this.q.observe(s, m)); | ||
} | ||
setStickyHeader(t) { | ||
this.et(0, t); | ||
this.it(0, t); | ||
} | ||
setStickyFooter(t) { | ||
this.et(1, t); | ||
this.it(1, t); | ||
} | ||
get V() { | ||
get J() { | ||
return this.getIndex(this.p); | ||
} | ||
get ht() { | ||
return this.O && 1 + this.getIndex(this.p + this.k); | ||
get et() { | ||
return this.I && 1 + this.getIndex(this.p + this.R); | ||
} | ||
Y() { | ||
const {ht: t} = this; | ||
t > this.to && (this.to = Math.min(this.O, t + this.L), this.from = this.V, this.X(0)); | ||
const {et: t} = this; | ||
t > this.to && (this.to = Math.min(this.I, t + this.k), this.from = this.J, this.X(0)); | ||
} | ||
st() { | ||
const {V: t} = this; | ||
t < this.from && (this.from = Math.max(0, t - this.L), this.to = this.ht, this.X(0)); | ||
tt() { | ||
const {J: t} = this; | ||
t < this.from && (this.from = Math.max(0, t - this.k), this.to = this.et, this.X(0)); | ||
} | ||
@@ -222,3 +214,3 @@ scrollToOffset(t, s) { | ||
--i || clearInterval(this.v); | ||
const e = Math.trunc(t), h = Math.min(this.scrollSize - this.k, this.getOffset(e) + Math.round(this.F[e] * (t - e))); | ||
const e = Math.trunc(t), h = Math.min(this.scrollSize - this.R, this.getOffset(e) + Math.round(this.F[e] * (t - e))); | ||
this.scrollToOffset(h, s); | ||
@@ -229,14 +221,14 @@ } | ||
setItemCount(t) { | ||
if (this.O !== t) { | ||
if (m.i(), r(S >= t, `itemCount must be <= 2147483647. Got: ${t}.`), this.O = t, | ||
if (this.I !== t) { | ||
if (u.i(), h(d >= t, `itemCount must be <= 2147483647. Got: ${t}.`), this.I = t, | ||
this.P = t && 1 << 31 - Math.clz32(t), t > this.F.length) { | ||
const s = Math.min(t + 32, S); | ||
this.F = n(this.F, s, this.R || 40), this.K = new i(s + 1), l(this.K, this.F); | ||
const s = Math.min(t + 32, d); | ||
this.F = o(this.F, s, this.L || 40), this.K = new i(s + 1), n(this.K, this.F); | ||
} | ||
this.scrollSize = this.getOffset(t), this.X(1), this.to > t && (this.to = -1), this.Y(), | ||
m.h(); | ||
u.h(); | ||
} | ||
} | ||
set(t) { | ||
t.estimatedItemSize && (this.R = t.estimatedItemSize), void 0 !== t.overscanCount && (this.L = t.overscanCount), | ||
t.estimatedItemSize && (this.L = t.estimatedItemSize), void 0 !== t.overscanCount && (this.k = t.overscanCount), | ||
void 0 !== t.itemCount && this.setItemCount(t.itemCount); | ||
@@ -246,3 +238,3 @@ } | ||
export { y as VirtualScroller, t as VirtualScrollerEvent }; | ||
export { p as VirtualScroller, t as VirtualScrollerEvent }; | ||
//# sourceMappingURL=index.js.map |
@@ -5,27 +5,22 @@ const t = { | ||
SIZES: 2 | ||
}, s = [ 0, 1, 2 ], i = Uint32Array, e = class { | ||
constructor(t) {} | ||
observe() {} | ||
unobserve() {} | ||
disconnect() {} | ||
}, h = t => t(), o = (t, s) => { | ||
}, s = [ 0, 1, 2 ], i = Uint32Array, e = t => t(), h = (t, s) => { | ||
if (!t) throw Error(s); | ||
}, r = (t, s) => { | ||
if (t instanceof HTMLElement) { | ||
const i = new e(s); | ||
const i = new ResizeObserver(s); | ||
return i.observe(t), () => i.disconnect(); | ||
} | ||
return s(), addEventListener("resize", s), () => removeEventListener("resize", s); | ||
}, n = (t, s, e) => { | ||
}, o = (t, s, e) => { | ||
const h = new i(s); | ||
return h.set(t), h.fill(e, t.length), h; | ||
}, l = (t, s) => { | ||
}, 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]); | ||
}, c = (t, s, i, e) => { | ||
}, l = (t, s, i, e) => { | ||
for (;e > s; s += s & -s) t[s] += i; | ||
}, a = (t, s, i) => { | ||
}, c = (t, s, i) => { | ||
for (;i > s; s += s & -s) ; | ||
return Math.min(s, t.length); | ||
}, f = (t, s) => t.getBoundingClientRect()[s], _ = (t, s, i, e) => s && t && t !== s ? t[i] + Math.round(f(s, e) - (t instanceof HTMLElement ? f(t, e) : 0)) : 0, u = new Set, m = { | ||
}, a = (t, s) => t.getBoundingClientRect()[s], f = (t, s, i, e) => s && t && t !== s ? t[i] + Math.round(a(s, e) - (t instanceof HTMLElement ? a(t, e) : 0)) : 0, _ = new Set, u = { | ||
t: 0, | ||
@@ -36,25 +31,25 @@ i() { | ||
h() { | ||
0 == --this.t && (u.forEach(h), u.clear()); | ||
0 == --this.t && (_.forEach(e), _.clear()); | ||
}, | ||
o: t => u.add(t) | ||
}, d = { | ||
o: t => _.add(t) | ||
}, m = { | ||
box: "border-box" | ||
}, S = 2147483647, v = new i(0), E = [ "offsetHeight", "offsetWidth", "innerHeight", "innerWidth" ], z = [ "scrollTop", "scrollLeft", "scrollY", "scrollX" ], T = [ "blockSize", "inlineSize" ], b = [ "top", "left" ], p = (t, s) => Math.round(t[0][s]); | ||
}, d = 2147483647, v = new i(0), S = [ "offsetHeight", "offsetWidth", "innerHeight", "innerWidth" ], E = [ "scrollTop", "scrollLeft", "scrollY", "scrollX" ], z = [ "blockSize", "inlineSize" ], b = [ "top", "left" ], T = (t, s) => Math.round(t[0][s]); | ||
class y { | ||
l=E[0]; | ||
_=z[0]; | ||
u=T[0]; | ||
class p { | ||
l=S[0]; | ||
_=E[0]; | ||
u=z[0]; | ||
m=b[0]; | ||
v=0; | ||
S=0; | ||
v=0; | ||
T=0; | ||
p=0; | ||
M=0; | ||
O=0; | ||
I=0; | ||
O=0; | ||
k=0; | ||
L=6; | ||
C=40; | ||
R=null; | ||
R=0; | ||
k=6; | ||
L=40; | ||
C=null; | ||
H=null; | ||
@@ -73,3 +68,3 @@ F=v; | ||
Z=[ 0, 0 ]; | ||
q=new e((t => { | ||
q=new ResizeObserver((t => { | ||
let s = 0; | ||
@@ -79,3 +74,3 @@ for (const i of t) { | ||
if (-1 !== t) { | ||
const e = p(i.borderBoxSize, this.u) - this.Z[t]; | ||
const e = T(i.borderBoxSize, this.u) - this.Z[t]; | ||
this.Z[t] += e, s += e; | ||
@@ -86,27 +81,27 @@ } | ||
})); | ||
U=new e((t => { | ||
U=new ResizeObserver((t => { | ||
let s = 0, i = !1; | ||
const e = a(this.K, this.from + 1, this.to); | ||
const e = c(this.K, this.from + 1, this.to); | ||
for (const h of t) { | ||
const t = this.W.get(h.target); | ||
if (e > t) { | ||
const o = p(h.borderBoxSize, this.u) - this.F[t]; | ||
o && (i = !0, this.F[t] += o, s += o, c(this.K, t + 1, o, e)); | ||
const r = T(h.borderBoxSize, this.u) - this.F[t]; | ||
r && (i = !0, this.F[t] += r, s += r, l(this.K, t + 1, r, e)); | ||
} | ||
} | ||
i && (m.i(), 0 !== s && (c(this.K, e, s, this.K.length), this.scrollSize += s, this.X(1), | ||
0 > s && this.Y()), this.sizesHash = this.sizesHash + 1 & S, this.X(2), m.h()); | ||
i && (u.i(), 0 !== s && (l(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), u.h()); | ||
})); | ||
$=s.map((() => [])); | ||
j() { | ||
const t = this.horizontal ? 1 : 0, s = t + 2 * (this.R instanceof HTMLElement ? 0 : 1); | ||
this.l = E[s], this._ = z[s], this.u = T[t], this.m = b[t]; | ||
const t = this.horizontal ? 1 : 0, s = t + 2 * (this.C instanceof HTMLElement ? 0 : 1); | ||
this.l = S[s], this._ = E[s], this.u = z[t], this.m = b[t]; | ||
} | ||
B=() => { | ||
const t = (s = this.R, i = this.l, e = this.I, s[i] - e); | ||
const t = (s = this.C, i = this.l, e = this.O, s[i] - e); | ||
var s, i, e; | ||
t !== this.k && (this.k = t, this.updateScrollerOffset(), this.Y()); | ||
t !== this.R && (this.R = t, this.updateScrollerOffset(), this.Y()); | ||
}; | ||
N(t) { | ||
t && (this.I += t, this.k -= t, this.Y()); | ||
t && (this.O += t, this.R -= t, this.Y()); | ||
} | ||
@@ -116,18 +111,15 @@ D=() => {}; | ||
t && (this.horizontal = !!t.horizontal, this.M = t.estimatedScrollElementOffset || 0, | ||
this.k = t.estimatedWidgetSize ?? 200, this.set(t)); | ||
this.R = t.estimatedWidgetSize ?? 200, this.set(t)); | ||
} | ||
J(t, s) { | ||
s.forEach((s => this.$[s].splice(this.$[s].indexOf(t) >>> 0, 1))); | ||
} | ||
on(t, s) { | ||
return s.forEach((s => this.$[s].push(t))), () => this.J(t, s); | ||
return s.forEach((s => this.$[s].push(t))), () => s.forEach((s => this.$[s].splice(this.$[s].indexOf(t) >>> 0, 1))); | ||
} | ||
X(t) { | ||
this.$[t].forEach(0 === m.t ? h : m.o); | ||
this.$[t].forEach(0 === u.t ? e : u.o); | ||
} | ||
getIndex(t) { | ||
if (0 >= t) return 0; | ||
if (t >= this.scrollSize) return this.O - 1; | ||
if (t >= this.scrollSize) return this.I - 1; | ||
let s = 0; | ||
for (let i = this.P, e = 0; i > 0; i >>= 1) e = s + i, e <= this.O && t > this.K[e] && (s = e, | ||
for (let i = this.P, e = 0; i > 0; i >>= 1) e = s + i, e <= this.I && t > this.K[e] && (s = e, | ||
t -= this.K[e]); | ||
@@ -137,3 +129,3 @@ return s; | ||
getOffset(t) { | ||
"production" !== process.env.NODE_ENV && o(t <= this.O, "index must not be > itemCount"); | ||
"production" !== process.env.NODE_ENV && h(t <= this.I, "index must not be > itemCount"); | ||
let s = 0; | ||
@@ -144,21 +136,21 @@ for (;t > 0; t -= t & -t) s += this.K[t]; | ||
getSize(t) { | ||
return "production" !== process.env.NODE_ENV && o(t < this.F.length, "itemIndex must be < itemCount in getSize"), | ||
return "production" !== process.env.NODE_ENV && h(t < this.F.length, "itemIndex must be < itemCount in getSize"), | ||
this.F[t]; | ||
} | ||
get visibleFrom() { | ||
const t = this.V; | ||
const t = this.J; | ||
return t + (this.p - this.getOffset(t)) / this.F[t]; | ||
} | ||
tt() { | ||
const t = this.p, s = Math.round(this.R[this._]) - this.M; | ||
s !== t && (this.p = s, s > t ? this.Y() : this.st()); | ||
V() { | ||
const t = this.p, s = Math.round(this.C[this._]) - this.M; | ||
s !== t && (this.p = s, s > t ? this.Y() : this.tt()); | ||
} | ||
it=t => { | ||
this.S = t.timeStamp, this.tt(); | ||
st=t => { | ||
this.v = t.timeStamp, this.V(); | ||
}; | ||
setScroller(t) { | ||
t !== this.R && (clearInterval(this.v), clearTimeout(this.T), this.D(), this.R?.removeEventListener("scroll", this.it), | ||
this.R = t, t && (this.j(), this.D = r(t, this.B), t.addEventListener("scroll", this.it, { | ||
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 = r(t, this.B), t.addEventListener("scroll", this.st, { | ||
passive: !0 | ||
}), this.updateScrollerOffset(), this.tt())); | ||
}), this.updateScrollerOffset(), this.V())); | ||
} | ||
@@ -170,5 +162,5 @@ setContainer(t) { | ||
clearTimeout(this.T), this.T = setTimeout((() => { | ||
if (this.R) { | ||
const t = _(this.R, this.H, this._, this.m), s = t - this.M; | ||
s && (this.M = t, this.p -= s, this.tt()); | ||
if (this.C) { | ||
const t = f(this.C, this.H, this._, this.m), s = t - this.M; | ||
s && (this.M = t, this.p -= s, this.V()); | ||
} | ||
@@ -180,31 +172,31 @@ }), 256); | ||
i && (this.A.delete(t), this.W.delete(i), this.U.unobserve(i)), s && (this.W.set(s, t), | ||
this.A.set(t, s), this.U.observe(s, d)); | ||
this.A.set(t, s), this.U.observe(s, m)); | ||
} | ||
et(t, s) { | ||
it(t, s) { | ||
const i = this.G[t]; | ||
i && (this.q.unobserve(i), this.N(-this.Z[t]), this.G[t] = null, this.Z[t] = 0), | ||
s && (this.G[t] = s, this.q.observe(s, d)); | ||
s && (this.G[t] = s, this.q.observe(s, m)); | ||
} | ||
setStickyHeader(t) { | ||
this.et(0, t); | ||
this.it(0, t); | ||
} | ||
setStickyFooter(t) { | ||
this.et(1, t); | ||
this.it(1, t); | ||
} | ||
get V() { | ||
get J() { | ||
return this.getIndex(this.p); | ||
} | ||
get ht() { | ||
return this.O && 1 + this.getIndex(this.p + this.k); | ||
get et() { | ||
return this.I && 1 + this.getIndex(this.p + this.R); | ||
} | ||
Y() { | ||
const {ht: t} = this; | ||
t > this.to && (this.to = Math.min(this.O, t + this.L), this.from = this.V, this.X(0)); | ||
const {et: t} = this; | ||
t > this.to && (this.to = Math.min(this.I, t + this.k), this.from = this.J, this.X(0)); | ||
} | ||
st() { | ||
const {V: t} = this; | ||
t < this.from && (this.from = Math.max(0, t - this.L), this.to = this.ht, this.X(0)); | ||
tt() { | ||
const {J: t} = this; | ||
t < this.from && (this.from = Math.max(0, t - this.k), this.to = this.et, this.X(0)); | ||
} | ||
scrollToOffset(t, s) { | ||
this.R?.scroll({ | ||
this.C?.scroll({ | ||
[this.m]: this.M + t, | ||
@@ -215,8 +207,8 @@ behavior: s ? "smooth" : "instant" | ||
scrollToIndex(t, s) { | ||
clearInterval(this.v); | ||
clearInterval(this.S); | ||
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.k, this.getOffset(e) + Math.round(this.F[e] * (t - e))); | ||
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.scrollToOffset(h, s); | ||
@@ -227,14 +219,14 @@ } | ||
setItemCount(t) { | ||
if (this.O !== t) { | ||
if (m.i(), o(S >= t, `itemCount must be <= 2147483647. Got: ${t}.`), this.O = t, | ||
if (this.I !== t) { | ||
if (u.i(), h(d >= t, `itemCount must be <= 2147483647. Got: ${t}.`), this.I = t, | ||
this.P = t && 1 << 31 - Math.clz32(t), t > this.F.length) { | ||
const s = Math.min(t + 32, S); | ||
this.F = n(this.F, s, this.C || 40), this.K = new i(s + 1), l(this.K, this.F); | ||
const s = Math.min(t + 32, d); | ||
this.F = o(this.F, s, this.L || 40), this.K = new i(s + 1), n(this.K, this.F); | ||
} | ||
this.scrollSize = this.getOffset(t), this.X(1), this.to > t && (this.to = -1), this.Y(), | ||
m.h(); | ||
u.h(); | ||
} | ||
} | ||
set(t) { | ||
t.estimatedItemSize && (this.C = t.estimatedItemSize), void 0 !== t.overscanCount && (this.L = t.overscanCount), | ||
t.estimatedItemSize && (this.L = t.estimatedItemSize), void 0 !== t.overscanCount && (this.k = t.overscanCount), | ||
void 0 !== t.itemCount && this.setItemCount(t.itemCount); | ||
@@ -244,2 +236,8 @@ } | ||
export { y as VirtualScroller, t as VirtualScrollerEvent }; | ||
global.ResizeObserver ||= class { | ||
observe() {} | ||
unobserve() {} | ||
disconnect() {} | ||
}; | ||
export { p as VirtualScroller, t as VirtualScrollerEvent }; |
{ | ||
"name": "@af-utils/virtual-core", | ||
"private": false, | ||
"version": "0.0.15", | ||
"version": "0.0.16", | ||
"description": "Model for rendering large scrollable data", | ||
@@ -35,3 +35,3 @@ "repository": "https://github.com/nowaalex/af-utils.git", | ||
"devDependencies": { | ||
"@rollup/plugin-replace": "^5.0.4", | ||
"@rollup/plugin-replace": "^5.0.5", | ||
"@rollup/plugin-terser": "^0.4.4", | ||
@@ -42,5 +42,2 @@ "@rollup/plugin-typescript": "^11.1.5", | ||
}, | ||
"dependencies": { | ||
"@af-utils/scrollend-polyfill": "0.0.9" | ||
}, | ||
"publishConfig": { | ||
@@ -47,0 +44,0 @@ "access": "public" |
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
0
74584
870
- Removed@af-utils/scrollend-polyfill@0.0.9
- Removed@af-utils/scrollend-polyfill@0.0.9(transitive)