@af-utils/virtual-core
Advanced tools
Comparing version 0.0.18 to 0.0.19
@@ -1,4 +0,4 @@ | ||
export declare const raw = 7548; | ||
export declare const min = 4765; | ||
export declare const minGz = 2089; | ||
export declare const raw = 7561; | ||
export declare const min = 4781; | ||
export declare const minGz = 2104; | ||
export declare const minBrotli = 1907; |
@@ -1,4 +0,4 @@ | ||
export const raw = 7548; | ||
export const min = 4765; | ||
export const minGz = 2089; | ||
export const raw = 7561; | ||
export const min = 4781; | ||
export const minGz = 2104; | ||
export const minBrotli = 1907; |
110
lib/index.js
@@ -5,5 +5,5 @@ const t = { | ||
SIZES: 2 | ||
}, s = [ 0, 1, 2 ], i = Uint32Array, e = t => t(), h = (t, s) => { | ||
}, s = [ 0, 1, 2 ], i = t => t(), e = (t, s) => { | ||
if (!t) throw Error(s); | ||
}, r = (t, s) => { | ||
}, h = (t, s) => { | ||
if (t instanceof HTMLElement) { | ||
@@ -14,14 +14,14 @@ const i = new ResizeObserver(s); | ||
return s(), addEventListener("resize", s), () => removeEventListener("resize", s); | ||
}, o = (t, s, e) => { | ||
const h = new i(s); | ||
return h.set(t), h.fill(e, t.length), h; | ||
}, r = (t, s, i) => { | ||
const e = new Uint32Array(s); | ||
return e.set(t), e.fill(i, t.length), e; | ||
}, 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]); | ||
}, l = (t, s, i, e) => { | ||
}, o = (t, s, i, e) => { | ||
for (;e > s; s += s & -s) t[s] += i; | ||
}, c = (t, s, i) => { | ||
}, l = (t, s, i) => { | ||
for (;i > s; s += s & -s) ; | ||
return Math.min(s, t.length); | ||
}, 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 = { | ||
}, 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, | ||
@@ -32,14 +32,14 @@ i() { | ||
h() { | ||
0 == --this.t && (_.forEach(e), _.clear()); | ||
0 == --this.t && (f.forEach(i), f.clear()); | ||
}, | ||
o: t => _.add(t) | ||
}, m = { | ||
o: t => f.add(t) | ||
}, u = { | ||
box: "border-box" | ||
}, 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.borderBoxSize[0][s]); | ||
}, 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]); | ||
class p { | ||
l=v[0]; | ||
_=E[0]; | ||
u=z[0]; | ||
m=T[0]; | ||
class b { | ||
l=S[0]; | ||
_=v[0]; | ||
u=E[0]; | ||
m=z[0]; | ||
S=0; | ||
@@ -57,5 +57,5 @@ v=0; | ||
H=null; | ||
F=S; | ||
K=S; | ||
P=0; | ||
F=m; | ||
K=m; | ||
A=0; | ||
horizontal=!1; | ||
@@ -66,29 +66,29 @@ scrollSize=0; | ||
sizesHash=0; | ||
W=new Map; | ||
A=new Map; | ||
G=[ null, null ]; | ||
Z=[ 0, 0 ]; | ||
q=new ResizeObserver((t => { | ||
P=new Map; | ||
U=new Map; | ||
W=[ null, null ]; | ||
G=[ 0, 0 ]; | ||
Z=new ResizeObserver((t => { | ||
let s = 0; | ||
for (const i of t) { | ||
const t = this.G.indexOf(i.target); | ||
const t = this.W.indexOf(i.target); | ||
if (-1 !== t) { | ||
const e = b(i, this.u) - this.Z[t]; | ||
this.Z[t] += e, s += e; | ||
const e = T(i, this.u) - this.G[t]; | ||
this.G[t] += e, s += e; | ||
} | ||
} | ||
this.N(s); | ||
this.q(s); | ||
})); | ||
U=new ResizeObserver((t => { | ||
N=new ResizeObserver((t => { | ||
let s = 0, i = !1; | ||
const e = /*#__NOINLINE__*/ c(this.K, this.from + 1, this.to); | ||
const e = /*#__NOINLINE__*/ l(this.K, this.from + 1, this.to); | ||
for (const h of t) { | ||
const t = this.W.get(h.target); | ||
const t = this.P.get(h.target); | ||
if (e > t) { | ||
const r = b(h, this.u) - this.F[t]; | ||
r && (i = !0, this.F[t] += r, s += r, l(this.K, t + 1, r, e)); | ||
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)); | ||
} | ||
} | ||
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()); | ||
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()); | ||
})); | ||
@@ -98,3 +98,3 @@ $=s.map((() => [])); | ||
const t = this.horizontal ? 1 : 0, s = t + 2 * (this.C instanceof HTMLElement ? 0 : 1); | ||
this.l = v[s], this._ = E[s], this.u = z[t], this.m = T[t]; | ||
this.l = S[s], this._ = v[s], this.u = E[t], this.m = z[t]; | ||
} | ||
@@ -105,3 +105,3 @@ B=() => { | ||
}; | ||
N(t) { | ||
q(t) { | ||
t && (this.O += t, this.R -= t, this.Y()); | ||
@@ -118,3 +118,3 @@ } | ||
X(t) { | ||
this.$[t].forEach(0 === u.t ? e : u.o); | ||
this.$[t].forEach(0 === _.t ? i : _.o); | ||
} | ||
@@ -125,3 +125,3 @@ getIndex(t) { | ||
let s = 0; | ||
for (let i = this.P, e = 0; i > 0; i >>= 1) e = s + i, e <= this.I && t > this.K[e] && (s = e, | ||
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]); | ||
@@ -131,3 +131,3 @@ return s; | ||
getOffset(t) { | ||
"production" !== process.env.NODE_ENV && h(t <= this.I, "index must not be > itemCount"); | ||
"production" !== process.env.NODE_ENV && e(t <= this.I, "index must not be > itemCount"); | ||
let s = 0; | ||
@@ -138,3 +138,3 @@ for (;t > 0; t -= t & -t) s += this.K[t]; | ||
getSize(t) { | ||
return "production" !== process.env.NODE_ENV && h(t < this.F.length, "itemIndex must be < itemCount in getSize"), | ||
return "production" !== process.env.NODE_ENV && e(t < this.F.length, "itemIndex must be < itemCount in getSize"), | ||
this.F[t]; | ||
@@ -155,3 +155,3 @@ } | ||
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__*/ r(t, this.B), t.addEventListener("scroll", this.st, { | ||
this.C = t, t && (this.j(), this.D = /*#__NOINLINE__*/ h(t, this.B), t.addEventListener("scroll", this.st, { | ||
passive: !0 | ||
@@ -167,3 +167,3 @@ }), this.updateScrollerOffset(), this.V())); | ||
const t = | ||
/*#__NOINLINE__*/ f(this.C, this.H, this._, this.m), s = t - this.M; | ||
/*#__NOINLINE__*/ a(this.C, this.H, this._, this.m), s = t - this.M; | ||
s && (this.M = t, this.p -= s, this.V()); | ||
@@ -174,10 +174,10 @@ } | ||
el(t, s) { | ||
const i = this.A.get(t); | ||
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, m)); | ||
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)); | ||
} | ||
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, m)); | ||
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)); | ||
} | ||
@@ -223,10 +223,10 @@ setStickyHeader(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) { | ||
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__*/ o(this.F, s, this.L || 40), this.K = new i(s + 1), | ||
this.F = /*#__NOINLINE__*/ r(this.F, s, this.L || 40), this.K = new Uint32Array(s + 1), | ||
/*#__NOINLINE__*/ n(this.K, this.F); | ||
} | ||
this.scrollSize = this.getOffset(t), this.X(1), this.to > t && (this.to = -1), this.Y(), | ||
u.h(); | ||
_.h(); | ||
} | ||
@@ -240,3 +240,3 @@ } | ||
export { p as VirtualScroller, t as VirtualScrollerEvent }; | ||
export { b as VirtualScroller, t as VirtualScrollerEvent }; | ||
//# sourceMappingURL=index.js.map |
@@ -11,9 +11,5 @@ global.ResizeObserver ||= class { | ||
SIZES: 2 | ||
}, s = [ 0, 1, 2 ]; | ||
var i = Uint32Array; | ||
const e = t => t(), h = (t, s) => { | ||
}, s = [ 0, 1, 2 ], i = t => t(), e = (t, s) => { | ||
if (!t) throw Error(s); | ||
}, r = (t, s) => { | ||
}, h = (t, s) => { | ||
if (t instanceof HTMLElement) { | ||
@@ -24,16 +20,16 @@ const i = new ResizeObserver(s); | ||
return s(), addEventListener("resize", s), () => removeEventListener("resize", s); | ||
}, o = (t, s, e) => { | ||
const h = new i(s); | ||
return h.set(t), h.fill(e, t.length), h; | ||
}, n = (t, s) => { | ||
}, r = (t, s, i) => { | ||
const e = new Uint32Array(s); | ||
return e.set(t), e.fill(i, t.length), e; | ||
}, o = (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]); | ||
}, l = (t, s, i, e) => { | ||
}, n = (t, s, i, e) => { | ||
for (;e > s; s += s & -s) t[s] += i; | ||
}, c = (t, s, i) => { | ||
}, l = (t, s, i) => { | ||
for (;i > s; s += s & -s) ; | ||
return Math.min(s, t.length); | ||
}, 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; | ||
}, 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; | ||
var u = { | ||
var _ = { | ||
t: 0, | ||
@@ -44,16 +40,16 @@ i() { | ||
h() { | ||
0 == --this.t && (_.forEach(e), _.clear()); | ||
0 == --this.t && (f.forEach(i), f.clear()); | ||
}, | ||
o: t => _.add(t) | ||
o: t => f.add(t) | ||
}; | ||
const m = { | ||
const u = { | ||
box: "border-box" | ||
}, 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.borderBoxSize[0][s]); | ||
}, 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]); | ||
class p { | ||
l=S[0]; | ||
_=E[0]; | ||
u=z[0]; | ||
m=b[0]; | ||
class T { | ||
l=v[0]; | ||
_=S[0]; | ||
u=E[0]; | ||
m=z[0]; | ||
v=0; | ||
@@ -71,5 +67,5 @@ S=0; | ||
H=null; | ||
F=v; | ||
K=v; | ||
P=0; | ||
F=m; | ||
K=m; | ||
A=0; | ||
horizontal=!1; | ||
@@ -80,29 +76,29 @@ scrollSize=0; | ||
sizesHash=0; | ||
W=new Map; | ||
A=new Map; | ||
G=[ null, null ]; | ||
Z=[ 0, 0 ]; | ||
q=new ResizeObserver((t => { | ||
P=new Map; | ||
U=new Map; | ||
W=[ null, null ]; | ||
G=[ 0, 0 ]; | ||
Z=new ResizeObserver((t => { | ||
let s = 0; | ||
for (const i of t) { | ||
const t = this.G.indexOf(i.target); | ||
const t = this.W.indexOf(i.target); | ||
if (-1 !== t) { | ||
const e = T(i, this.u) - this.Z[t]; | ||
this.Z[t] += e, s += e; | ||
const e = b(i, this.u) - this.G[t]; | ||
this.G[t] += e, s += e; | ||
} | ||
} | ||
this.N(s); | ||
this.q(s); | ||
})); | ||
U=new ResizeObserver((t => { | ||
N=new ResizeObserver((t => { | ||
let s = 0, i = !1; | ||
const e = /*#__NOINLINE__*/ c(this.K, this.from + 1, this.to); | ||
const e = /*#__NOINLINE__*/ l(this.K, this.from + 1, this.to); | ||
for (const h of t) { | ||
const t = this.W.get(h.target); | ||
const t = this.P.get(h.target); | ||
if (e > t) { | ||
const r = T(h, this.u) - this.F[t]; | ||
r && (i = !0, this.F[t] += r, s += r, l(this.K, t + 1, r, e)); | ||
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)); | ||
} | ||
} | ||
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()); | ||
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()); | ||
})); | ||
@@ -112,3 +108,3 @@ $=s.map((() => [])); | ||
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]; | ||
this.l = v[s], this._ = S[s], this.u = E[t], this.m = z[t]; | ||
} | ||
@@ -119,3 +115,3 @@ B=() => { | ||
}; | ||
N(t) { | ||
q(t) { | ||
t && (this.O += t, this.R -= t, this.Y()); | ||
@@ -132,3 +128,3 @@ } | ||
X(t) { | ||
this.$[t].forEach(0 === u.t ? e : u.o); | ||
this.$[t].forEach(0 === _.t ? i : _.o); | ||
} | ||
@@ -139,3 +135,3 @@ getIndex(t) { | ||
let s = 0; | ||
for (let i = this.P, e = 0; i > 0; i >>= 1) e = s + i, e <= this.I && t > this.K[e] && (s = e, | ||
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]); | ||
@@ -145,3 +141,3 @@ return s; | ||
getOffset(t) { | ||
"production" !== process.env.NODE_ENV && h(t <= this.I, "index must not be > itemCount"); | ||
"production" !== process.env.NODE_ENV && e(t <= this.I, "index must not be > itemCount"); | ||
let s = 0; | ||
@@ -152,3 +148,3 @@ for (;t > 0; t -= t & -t) s += this.K[t]; | ||
getSize(t) { | ||
return "production" !== process.env.NODE_ENV && h(t < this.F.length, "itemIndex must be < itemCount in getSize"), | ||
return "production" !== process.env.NODE_ENV && e(t < this.F.length, "itemIndex must be < itemCount in getSize"), | ||
this.F[t]; | ||
@@ -169,3 +165,3 @@ } | ||
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__*/ r(t, this.B), t.addEventListener("scroll", this.st, { | ||
this.C = t, t && (this.j(), this.D = /*#__NOINLINE__*/ h(t, this.B), t.addEventListener("scroll", this.st, { | ||
passive: !0 | ||
@@ -181,3 +177,3 @@ }), this.updateScrollerOffset(), this.V())); | ||
const t = | ||
/*#__NOINLINE__*/ f(this.C, this.H, this._, this.m), s = t - this.M; | ||
/*#__NOINLINE__*/ a(this.C, this.H, this._, this.m), s = t - this.M; | ||
s && (this.M = t, this.p -= s, this.V()); | ||
@@ -188,10 +184,10 @@ } | ||
el(t, s) { | ||
const i = this.A.get(t); | ||
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, m)); | ||
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)); | ||
} | ||
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, m)); | ||
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)); | ||
} | ||
@@ -237,10 +233,10 @@ setStickyHeader(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) { | ||
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__*/ o(this.F, s, this.L || 40), this.K = new i(s + 1), | ||
/*#__NOINLINE__*/ n(this.K, this.F); | ||
this.F = /*#__NOINLINE__*/ r(this.F, s, this.L || 40), this.K = new Uint32Array(s + 1), | ||
/*#__NOINLINE__*/ o(this.K, this.F); | ||
} | ||
this.scrollSize = this.getOffset(t), this.X(1), this.to > t && (this.to = -1), this.Y(), | ||
u.h(); | ||
_.h(); | ||
} | ||
@@ -254,2 +250,2 @@ } | ||
export { p as VirtualScroller, t as VirtualScrollerEvent }; | ||
export { T as VirtualScroller, t as VirtualScrollerEvent }; |
{ | ||
"name": "@af-utils/virtual-core", | ||
"private": false, | ||
"version": "0.0.18", | ||
"version": "0.0.19", | ||
"description": "Model for rendering large scrollable data", | ||
@@ -46,5 +46,6 @@ "repository": "https://github.com/nowaalex/af-utils.git", | ||
"@rollup/plugin-terser": "^0.4.4", | ||
"@rollup/plugin-typescript": "^11.1.5", | ||
"ts-jest": "^29.1.1", | ||
"@af-utils/rollup-plugin-export-bundle-size": "0.0.4" | ||
"@rollup/plugin-typescript": "^11.1.6", | ||
"rollup": "^4.9.6", | ||
"ts-jest": "^29.1.2", | ||
"@af-utils/rollup-plugin-export-bundle-size": "0.0.5" | ||
}, | ||
@@ -51,0 +52,0 @@ "publishConfig": { |
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
74294
5
874