🎩 You're Invited:Meet the Socket team at Black Hat in Las Vegas, August 3-6.RSVP
Sign In

@virtuoso.dev/masonry

Package Overview
Dependencies
Maintainers
2
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@virtuoso.dev/masonry - npm Package Compare versions

Comparing version
1.3.1
to
1.3.2
+6
-44
CHANGELOG.md

@@ -1,49 +0,11 @@

## [1.3.1](https://github.com/virtuoso-dev/masonry/compare/v1.3.0...v1.3.1) (2025-01-01)
# Change Log - @virtuoso.dev/masonry
This log was last generated on Fri, 10 Jan 2025 08:23:07 GMT and should not be manually modified.
### Bug Fixes
## 1.3.2
Fri, 10 Jan 2025 08:23:07 GMT
* euristics for missing items ([6ae5db7](https://github.com/virtuoso-dev/masonry/commit/6ae5db7bef6342f8a6f8e968bd09ef0e432d85a7))
### Patches
# [1.3.0](https://github.com/virtuoso-dev/masonry/compare/v1.2.0...v1.3.0) (2024-12-31)
- Switch to @virtuoso.dev/gurx
### Features
* scroll parent ref prop ([2a29d6d](https://github.com/virtuoso-dev/masonry/commit/2a29d6dfb95abffada91e328f9574840c3fb1e86))
# [1.2.0](https://github.com/virtuoso-dev/masonry/compare/v1.1.0...v1.2.0) (2024-12-08)
### Features
* dynamic columns ([407021d](https://github.com/virtuoso-dev/masonry/commit/407021d1a99b69ede6d03876e6a5b8b88fd4a35d))
* dynamic columns ([e080d56](https://github.com/virtuoso-dev/masonry/commit/e080d561ade20642cd45c4e6e3d1d4b20f34fcd3))
# [1.1.0](https://github.com/virtuoso-dev/masonry/compare/v1.0.1...v1.1.0) (2024-12-01)
### Features
* SSR ([e5945ea](https://github.com/virtuoso-dev/masonry/commit/e5945eadccbfae843c322fb8e97c3835dd6cdf8d))
* useWindowScroll ([7d052d0](https://github.com/virtuoso-dev/masonry/commit/7d052d010e306ce0d4324b833b4116820625bb59))
## [1.0.1](https://github.com/virtuoso-dev/masonry/compare/v1.0.0...v1.0.1) (2024-11-30)
### Bug Fixes
* remove obsolete files ([54af3ee](https://github.com/virtuoso-dev/masonry/commit/54af3ee796ce2ba1d5d2aec827172d2852579928))
* use latest gurx ([2280065](https://github.com/virtuoso-dev/masonry/commit/2280065469d44389cdf3d610a4ac4e1760ac7590))
# 1.0.0 (2024-11-24)
### Bug Fixes
* disable playwright ([6c33b02](https://github.com/virtuoso-dev/masonry/commit/6c33b0252295425c3b77cb6360f4337f7a276936))
### Features
* initial commit ([3b2afb3](https://github.com/virtuoso-dev/masonry/commit/3b2afb3a78b69fd0e7f7bfef7ea16c050ed5a959))

@@ -1,4 +0,1 @@

import { MutableRefObject } from 'react';
import { RefObject } from 'react';
/* Excluded from this release type: ComputeItemKey */

@@ -44,4 +41,2 @@

declare type ScrollParentRef = null | RefObject<HTMLElement | null> | MutableRefObject<HTMLElement | null>;
/* Excluded from this release type: SizeRange */

@@ -63,5 +58,4 @@

useWindowScroll?: boolean;
scrollParentRef?: ScrollParentRef;
}
export { }
+324
-384

@@ -1,44 +0,44 @@

import { jsxs as Jt, jsx as V, Fragment as Qt } from "react/jsx-runtime";
import { Cell as p, link as St, pipe as b, filter as vt, map as y, DerivedCell as N, combine as $t, Signal as Ot, changeWith as Tt, withLatestFrom as Nt, scan as At, sub as Xt, pub as Zt, Realm as te, RealmContext as ee, useRealm as ne, useCellValues as re, useCellValue as oe } from "@mdxeditor/gurx";
import { forwardRef as se, useMemo as le, useImperativeHandle as ie, useEffect as xt, useState as ce, useCallback as j, useRef as It } from "react";
const Pt = ({ index: t }) => /* @__PURE__ */ Jt("div", { children: [
import { jsxs as jt, jsx as C, Fragment as Dt } from "react/jsx-runtime";
import { Cell as g, link as xt, pipe as b, filter as $t, map as w, DerivedCell as $, combine as gt, Signal as Rt, changeWith as Nt, withLatestFrom as It, scan as Ct, sub as Gt, pub as Ut, Realm as qt, RealmContext as Kt, useRealm as Jt, useCellValues as Qt, useCellValue as Xt } from "@virtuoso.dev/gurx";
import { forwardRef as Zt, useMemo as te, useImperativeHandle as ee, useEffect as Et, useState as ne, useCallback as F, useRef as ut } from "react";
const Mt = ({ index: t }) => /* @__PURE__ */ jt("div", { children: [
"Item ",
t
] }), kt = p(Pt), X = p(0), bt = p(null), st = p(null, () => {
St(
] }), Vt = g(Mt), Y = g(0), ft = g(null), Z = g(null, () => {
xt(
b(
st,
vt((t) => t !== null),
y((t) => t.length)
Z,
$t((t) => t !== null),
w((t) => t.length)
),
X
Y
);
}), k = p(0), D = p(0), dt = p(0), P = p(0), ue = k, J = p(0), Z = p(!1), fe = N(0, () => b(
$t(D, Z, J),
y(([t, e, n]) => e ? t - Math.max(n, 0) : t)
)), lt = p(null), tt = { lvl: 0 };
function Bt(t, e, n, r = tt, o = tt) {
}), Q = g(0), at = g(0), re = g(0), J = g(0), oe = Q, tt = g(0), j = g(!1), se = $(0, () => b(
gt(at, j, tt),
w(([t, e, n]) => e ? t - Math.max(n, 0) : t)
)), D = { lvl: 0 };
function Ht(t, e, n, r = D, o = D) {
return { k: t, l: r, lvl: n, r: o, v: e };
}
function h(t) {
return t === tt;
function a(t) {
return t === D;
}
function it() {
return tt;
function et() {
return D;
}
function wt(t, e) {
if (h(t)) return tt;
function ht(t, e) {
if (a(t)) return D;
const { k: n, l: r, r: o } = t;
if (e === n) {
if (h(r))
if (a(r))
return o;
if (h(o))
if (a(o))
return r;
const [s, l] = zt(r);
return ot(d(t, { k: s, l: Ft(r), v: l }));
const [s, l] = Ot(r);
return X(m(t, { k: s, l: kt(r), v: l }));
}
return e < n ? ot(d(t, { l: wt(r, e) })) : ot(d(t, { r: wt(o, e) }));
return e < n ? X(m(t, { l: ht(r, e) })) : X(m(t, { r: ht(o, e) }));
}
function et(t, e, n = "k") {
if (h(t))
function G(t, e, n = "k") {
if (a(t))
return [Number.NEGATIVE_INFINITY, void 0];

@@ -48,33 +48,36 @@ if (t[n] === e)

if (t[n] < e) {
const r = et(t.r, e, n);
const r = G(t.r, e, n);
return r[0] === Number.NEGATIVE_INFINITY ? [t.k, t.v] : r;
}
return et(t.l, e, n);
return G(t.l, e, n);
}
function B(t, e, n) {
return h(t) ? Bt(e, n, 1) : e === t.k ? d(t, { k: e, v: n }) : e < t.k ? Ht(d(t, { l: B(t.l, e, n) })) : Ht(d(t, { r: B(t.r, e, n) }));
function O(t, e, n) {
return a(t) ? Ht(e, n, 1) : e === t.k ? m(t, { k: e, v: n }) : e < t.k ? St(m(t, { l: O(t.l, e, n) })) : St(m(t, { r: O(t.r, e, n) }));
}
function Rt(t, e, n) {
if (h(t))
function mt(t, e, n) {
if (a(t))
return [];
const { k: r, v: o, l: s, r: l } = t;
let i = [];
return r > e && (i = i.concat(Rt(s, e, n))), r >= e && r <= n && i.push({ k: r, v: o }), r <= n && (i = i.concat(Rt(l, e, n))), i;
return r > e && (i = i.concat(mt(s, e, n))), r >= e && r <= n && i.push({ k: r, v: o }), r <= n && (i = i.concat(mt(l, e, n))), i;
}
function zt(t) {
return h(t.r) ? [t.k, t.v] : zt(t.r);
function dt(t) {
return a(t) ? [] : [...dt(t.l), { k: t.k, v: t.v }, ...dt(t.r)];
}
function Ft(t) {
return h(t.r) ? t.l : ot(d(t, { r: Ft(t.r) }));
function Ot(t) {
return a(t.r) ? [t.k, t.v] : Ot(t.r);
}
function d(t, e) {
return Bt(e.k ?? t.k, e.v ?? t.v, e.lvl ?? t.lvl, e.l ?? t.l, e.r ?? t.r);
function kt(t) {
return a(t.r) ? t.l : X(m(t, { r: kt(t.r) }));
}
function gt(t) {
return h(t) || t.lvl > t.r.lvl;
function m(t, e) {
return Ht(e.k ?? t.k, e.v ?? t.v, e.lvl ?? t.lvl, e.l ?? t.l, e.r ?? t.r);
}
function Ht(t) {
return yt(_t(t));
function ct(t) {
return a(t) || t.lvl > t.r.lvl;
}
function ot(t) {
function St(t) {
return vt(Pt(t));
}
function X(t) {
const { l: e, r: n, lvl: r } = t;

@@ -84,9 +87,9 @@ if (n.lvl >= r - 1 && e.lvl >= r - 1)

if (r > n.lvl + 1) {
if (gt(e))
return _t(d(t, { lvl: r - 1 }));
if (!h(e) && !h(e.r))
return d(e.r, {
l: d(e, { r: e.r.l }),
if (ct(e))
return Pt(m(t, { lvl: r - 1 }));
if (!a(e) && !a(e.r))
return m(e.r, {
l: m(e, { r: e.r.l }),
lvl: r,
r: d(t, {
r: m(t, {
l: e.r.r,

@@ -98,8 +101,8 @@ lvl: r - 1

}
if (gt(t))
return yt(d(t, { lvl: r - 1 }));
if (!h(n) && !h(n.l)) {
const o = n.l, s = gt(o) ? n.lvl - 1 : n.lvl;
return d(o, {
l: d(t, {
if (ct(t))
return vt(m(t, { lvl: r - 1 }));
if (!a(n) && !a(n.l)) {
const o = n.l, s = ct(o) ? n.lvl - 1 : n.lvl;
return m(o, {
l: m(t, {
lvl: r - 1,

@@ -109,3 +112,3 @@ r: o.l

lvl: o.lvl + 1,
r: yt(d(n, { l: o.r, lvl: s }))
r: vt(m(n, { l: o.r, lvl: s }))
});

@@ -115,9 +118,9 @@ }

}
function Lt(t, e, n) {
if (h(t))
function At(t, e, n) {
if (a(t))
return [];
const r = et(t, e)[0];
return ae(Rt(t, r, n));
const r = G(t, e)[0];
return le(mt(t, r, n));
}
function Wt(t, e) {
function Tt(t, e) {
const n = t.length;

@@ -134,36 +137,36 @@ if (n === 0)

}
function ae(t) {
return Wt(t, ({ k: e, v: n }) => ({ index: e, value: n }));
function le(t) {
return Tt(t, ({ k: e, v: n }) => ({ index: e, value: n }));
}
function yt(t) {
function vt(t) {
const { r: e, lvl: n } = t;
return !h(e) && !h(e.r) && e.lvl === n && e.r.lvl === n ? d(e, { l: d(t, { r: e.l }), lvl: n + 1 }) : t;
return !a(e) && !a(e.r) && e.lvl === n && e.r.lvl === n ? m(e, { l: m(t, { r: e.l }), lvl: n + 1 }) : t;
}
function _t(t) {
function Pt(t) {
const { l: e } = t;
return !h(e) && e.lvl === t.lvl ? d(e, { r: d(t, { l: e.r }) }) : t;
return !a(e) && e.lvl === t.lvl ? m(e, { r: m(t, { l: e.r }) }) : t;
}
function he(t) {
function ie(t) {
const { size: e, startIndex: n, endIndex: r } = t;
return (o) => o.start === n && (o.end === r || o.end === Number.POSITIVE_INFINITY) && o.value === e;
}
function Yt(t, e) {
let n = h(t) ? 0 : Number.POSITIVE_INFINITY;
function zt(t, e) {
let n = a(t) ? 0 : Number.POSITIVE_INFINITY;
for (const r of e) {
const { size: o, startIndex: s, endIndex: l } = r;
if (n = Math.min(n, s), h(t)) {
t = B(t, 0, o);
if (n = Math.min(n, s), a(t)) {
t = O(t, 0, o);
continue;
}
const i = Lt(t, s - 1, l + 1);
if (i.some(he(r)))
const i = At(t, s - 1, l + 1);
if (i.some(ie(r)))
continue;
let u = !1, f = !1;
for (const { start: a, end: H, value: S } of i)
u ? (l >= a || o === S) && (t = wt(t, a)) : (f = S !== o, u = !0), H > l && l >= a && S !== o && (t = B(t, l + 1, S));
f && (t = B(t, s, o));
let u = !1, c = !1;
for (const { start: h, end: E, value: y } of i)
u ? (l >= h || o === y) && (t = ht(t, h)) : (c = y !== o, u = !0), E > l && l >= h && y !== o && (t = O(t, l + 1, y));
c && (t = O(t, s, o));
}
return [t, n];
}
function ct(t, e, n, r = 0) {
function nt(t, e, n, r = 0) {
let o = t.length - 1;

@@ -186,55 +189,49 @@ for (; r <= o; ) {

}
function jt(t, e, n) {
return t[ct(t, e, n)];
function ce(t, e, n) {
return t[nt(t, e, n)];
}
function me(t, e, n, r) {
const o = ct(t, e, r), s = ct(t, n, r, o);
function ue(t, e, n, r) {
const o = nt(t, e, r), s = nt(t, n, r, o);
return t.slice(o, s + 1);
}
function Ct({ index: t }, e) {
function Ft({ index: t }, e) {
return e === t ? 0 : e < t ? -1 : 1;
}
function de({ offset: t }, e) {
function fe({ offset: t }, e) {
return e === t ? 0 : e < t ? -1 : 1;
}
function ge(t) {
function ae(t) {
return { index: t.index, value: t };
}
function pe(t, e, n, r = 0) {
return r > 0 && (e = Math.max(e, jt(t, r, Ct).offset)), e = Math.max(0, e), Wt(me(t, e, n, de), ge);
function he(t, e, n, r = 0) {
return r > 0 && (e = Math.max(e, ce(t, r, Ft).offset)), e = Math.max(0, e), Tt(ue(t, e, n, fe), ae);
}
function ve(t, e) {
const n = jt(t, e, Ct);
if (!n)
throw new Error(`No offset for index ${e}`);
return n.offset + (e - n.index + 1) * n.height;
}
function xe(t, [e, n]) {
function me(t, [e, n]) {
let r = 0, o = 0, s = 0, l = 0;
if (n !== 0) {
l = ct(t, n - 1, Ct), s = t[l].offset;
const u = et(e, n - 1);
l = nt(t, n - 1, Ft), s = t[l].offset;
const u = G(e, n - 1);
if (u[1] === void 0)
throw new Error("Invariant violation");
r = u[0], o = u[1], t.length && t[l].height === et(e, n)[1] && (l -= 1), t = t.slice(0, l + 1);
r = u[0], o = u[1], t.length && t[l].height === G(e, n)[1] && (l -= 1), t = t.slice(0, l + 1);
} else
t = [];
for (const { start: i, value: u } of Lt(e, n, Number.POSITIVE_INFINITY)) {
const f = (i - r) * o + s;
t.push({ height: u, index: i, offset: f }), r = i, s = f, o = u;
for (const { start: i, value: u } of At(e, n, Number.POSITIVE_INFINITY)) {
const c = (i - r) * o + s;
t.push({ height: u, index: i, offset: c }), r = i, s = c, o = u;
}
return [t, o, s, r];
}
function Ie(t, [e, n]) {
if (n.length > 0 && h(t) && e.length === 2) {
function de(t, [e, n]) {
if (n.length > 0 && a(t) && e.length === 2) {
const r = e[0].size, o = e[1].size;
return [
n.reduce((s, l) => B(B(s, l, r), l + 1, o), it()),
n.reduce((s, l) => O(O(s, l, r), l + 1, o), et()),
0
];
}
return Yt(t, e);
return zt(t, e);
}
const Dt = Ot(), qt = Ot(), at = p([], () => {
Tt(at, qt, (t, e) => {
const Bt = Rt(), Wt = Rt(), st = g([], () => {
Nt(st, Wt, (t, e) => {
const n = t.slice();

@@ -244,12 +241,14 @@ for (const [r, o] of Object.entries(e))

for (let r = 0; r < n.length; r++)
n[r] === void 0 && (n[r] = n[r - 1]);
if (n[r] === void 0)
return t;
return n;
});
}), z = p(0), Et = p(0), ut = p([], () => {
St(
}), k = g(0), pt = g(0), rt = g([], () => {
xt(
b(
z,
Nt(at),
y(([t, e]) => {
const n = Array.from({ length: t }, () => [it(), 0]);
k,
It(st),
w(([t, e]) => {
console.log("knownSizes", e);
const n = Array.from({ length: t }, () => [et(), 0]);
if (e.length > 0) {

@@ -259,6 +258,8 @@ const r = Array.from({ length: t }, () => 0), o = Array.from({ length: t }, () => 0);

const l = e[s], i = r.indexOf(Math.min(...r)), u = o[i];
o[i]++, r[i] += l, n[i] = Yt(n[i][0], [
o[i]++, r[i] += l, n[i] = zt(n[i][0], [
{ size: l, startIndex: u, endIndex: u }
]);
}
for (const [s] of n)
console.log(dt(s));
}

@@ -268,7 +269,7 @@ return n.map(([r]) => [r, 0]);

),
ut
), Tt(ut, Dt, (t, e) => {
rt
), Nt(rt, Bt, (t, e) => {
const n = t.map(([o]) => o), r = [];
for (let o = 0; o < e.length; o++) {
const s = n[o] ?? it();
const s = n[o] ?? et();
if (e[o].length === 0) {

@@ -278,58 +279,58 @@ r.push([s, 0]);

}
r.push(Ie(s, [e[o], []]));
r.push(de(s, [e[o], []]));
}
return r;
});
}), Gt = N([], () => b(
ut,
y((t) => t.map(([e]) => e))
)), be = N([], (t) => t.pipe(
ut,
y((e) => e.map(([, n]) => n))
)), ht = N([], () => b(
Gt,
Nt(be),
At((t, [e, n]) => {
}), _t = $([], () => b(
rt,
w((t) => t.map(([e]) => e))
)), ve = $([], (t) => t.pipe(
rt,
w((e) => e.map(([, n]) => n))
)), lt = $([], () => b(
_t,
It(ve),
Ct((t, [e, n]) => {
const r = [];
for (let o = 0; o < e.length; o++) {
const s = t[o] ?? [[]];
r.push(xe(s[0], [e[o], n[o]]));
r.push(me(s[0], [e[o], n[o]]));
}
return r;
}, [])
)), we = N(
)), xe = $(
[],
() => b(
ht,
y((t) => t.map(([e]) => e))
lt,
w((t) => t.map(([e]) => e))
)
), Re = N(
), ge = $(
[],
() => b(
ht,
y((t) => t.map(([, e]) => e))
lt,
w((t) => t.map(([, e]) => e))
)
), ye = N(
), Ie = $(
[],
() => b(
ht,
y((t) => t.map(([, , e]) => e))
lt,
w((t) => t.map(([, , e]) => e))
)
), Se = N(
), pe = $(
[],
(t) => t.pipe(
ht,
y((e) => e.map(([, , , n]) => n))
lt,
w((e) => e.map(([, , , n]) => n))
)
), Q = N([], () => b(
z,
Nt(X, Et, at),
y(([t, e, n, r]) => {
), L = $([], () => b(
k,
It(Y, pt, st),
w(([t, e, n, r]) => {
if (r.length > 0) {
const l = Array.from({ length: t }, () => 0), i = Array.from({ length: t }, () => []);
for (let u = 0; u < r.length; u++) {
const f = r[u], a = l.indexOf(Math.min(...l));
i[a].push(u), l[a] += f;
const c = r[u], h = l.indexOf(Math.min(...l));
i[h].push(u), l[h] += c;
}
return i;
return console.log({ columnHeights: l }), i;
}

@@ -339,40 +340,37 @@ const o = n === 0 ? Math.min(t, e) : n;

const u = [];
for (let f = i; f < o; f += t)
u.push(f);
for (let c = i; c < o; c += t)
u.push(c);
return u;
});
})
)), $e = N(
)), be = $(
[],
() => b(
$t(z, X, Se, ye, Re, Q),
y(([t, e, n, r, o, s]) => {
const l = s.reduce((f, a) => f + a.length, 0), i = Math.ceil((e - l) / t);
return Array.from({ length: t }, (f, a) => {
const S = s[a].length + i - n[a];
return r[a] + S * o[a];
gt(k, Y, pe, Ie, ge, L),
w(([t, e, n, r, o, s]) => {
const l = s.reduce((c, h) => c + h.length, 0), i = Math.ceil((e - l) / t);
return Array.from({ length: t }, (c, h) => {
const y = s[h].length + i - n[h];
return r[h] + y * o[h];
});
})
)
), pt = p(!1), ft = p({ columns: [], totalCount: -1, data: [], indexesInColumns: [] }, (t) => {
St(
), ot = g({ columns: [], totalCount: -1, data: [], indexesInColumns: [] }, (t) => {
xt(
b(
$t(
z,
ue,
fe,
Gt,
we,
X,
$e,
st,
Q,
Et,
J,
gt(
k,
oe,
se,
_t,
xe,
Y,
be,
Z,
lt,
pt
L,
pt,
tt,
j
),
vt(([, , , , , , , , , , , , , e]) => !e),
At(
Ct(
(e, [

@@ -386,33 +384,32 @@ n,

u,
f,
a,
H,
S,
q,
O
c,
h,
E,
y,
B
]) => {
const Mt = q || O !== null ? S + r : 0, c = Math.min(Math.max(r - Mt, 0), Math.max(...u) - o), m = c + o, I = H === 0 ? Math.min(n, i) : H;
const bt = B ? y + r : 0, f = Math.min(Math.max(r - bt, 0), Math.max(...u) - o), d = f + o, R = E === 0 ? Math.min(n, i) : E;
return {
columns: Array.from(
{ length: n },
(L, g) => {
const C = e.columns[g], v = s[g] ?? it(), w = l[g] ?? [], W = u[g] ?? 0, x = a[g] ?? [];
if (h(v) || x.length === 0) {
const A = [];
let U = 0;
for (let $ = g; $ < I; $ += n)
A.push({
data: f == null ? void 0 : f[$],
(U, I) => {
const v = e.columns[I], M = s[I] ?? et(), N = l[I] ?? [], p = u[I] ?? 0, V = h[I] ?? [];
if (a(M) || V.length === 0) {
const H = [];
let _ = 0;
for (let S = I; S < R; S += n)
H.push({
data: c == null ? void 0 : c[S],
height: 0,
columnIndex: g,
indexInColumn: U++,
index: $,
columnIndex: I,
indexInColumn: _++,
index: S,
offset: 0
});
return {
index: g,
items: A,
index: I,
items: H,
listBottom: 0,
listTop: 0,
offsetTree: w,
offsetTree: N,
totalHeight: 0,

@@ -424,34 +421,34 @@ viewportBottom: 0

// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
C && C.offsetTree === w && e.totalCount === i && e.data === f && e.indexesInColumns === a && c >= C.listTop && m <= C.listBottom
v && v.offsetTree === N && e.totalCount === i && e.data === c && e.indexesInColumns === h && f >= v.listTop && d <= v.listBottom
)
return C;
const _ = [], nt = x.length - 1, E = 0, mt = ve(w, nt), G = Math.min(c, mt - 1), M = pe(w, G, m, E);
let R = 0, T = 0, K = !1;
for (const A of M) {
return v;
const q = [], T = V.length - 1, P = 0, it = he(N, f, d, P);
let x = 0, W = 0, wt = !1;
for (const H of it) {
const {
value: { offset: U, height: $ }
} = A;
let Y = A.start;
R = U, U < G && (Y += Math.floor((G - U) / $), R += (Y - A.start) * $), Y < E && (R += (E - Y) * $, Y = E);
const Kt = Math.min(A.end, nt);
for (let rt = Y; rt <= Kt && !(R >= m); rt++) {
const Vt = x[rt], Ut = {
data: f == null ? void 0 : f[Vt],
height: $,
columnIndex: g,
indexInColumn: rt,
index: Vt,
offset: R
value: { offset: _, height: S }
} = H;
let z = H.start;
x = _, _ < f && (z += Math.floor((f - _) / S), x += (z - H.start) * S), z < P && (x += (P - z) * S, z = P);
const Lt = Math.min(H.end, T);
for (let K = z; K <= Lt && !(x >= d); K++) {
const yt = V[K], Yt = {
data: c == null ? void 0 : c[yt],
height: S,
columnIndex: I,
indexInColumn: K,
index: yt,
offset: x
};
K || (K = !0, T = R), _.push(Ut), R += $;
wt || (wt = !0, W = x), q.push(Yt), x += S;
}
}
return {
items: _,
viewportBottom: m,
listBottom: R,
listTop: T,
offsetTree: w,
totalHeight: W,
index: g
items: q,
viewportBottom: d,
listBottom: x,
listTop: W,
offsetTree: N,
totalHeight: p,
index: I
};

@@ -461,4 +458,4 @@ }

totalCount: i,
data: f,
indexesInColumns: a
data: c,
indexesInColumns: h
};

@@ -474,52 +471,40 @@ },

),
ft
), Xt(
ot
), Gt(
b(
ft,
vt((e) => e.columns.some((n) => n.listBottom < n.viewportBottom))
ot,
$t((e) => e.columns.some((n) => n.listBottom < n.viewportBottom))
),
(e) => {
const n = e.columns.slice().sort((s, l) => s.listBottom - l.listBottom)[0], r = t.getValue(Q), o = Math.max(...r.flat()) + 1;
o >= t.getValue(X) || (Zt(pt, !0), requestAnimationFrame(() => {
t.pubIn({
[pt]: !1,
[Q]: r.map((s, l) => l === n.index ? [...s, o] : s)
});
}));
const n = e.columns.slice().sort((s, l) => s.listBottom - l.listBottom)[0], r = t.getValue(L), o = Math.max(...r.flat()) + 1;
o >= t.getValue(Y) || Ut(
L,
r.map((s, l) => l === n.index ? [...s, o] : s)
);
}
);
}), Ne = se(
({
scrollParentRef: t,
initialItemCount: e = 0,
data: n,
context: r,
columnCount: o,
useWindowScroll: s = !1,
ItemContent: l = Pt,
...i
}, u) => {
const f = le(() => {
const a = new te();
return a.register(Q), a.register(ft), a.register(at), a.pubIn({
[st]: n.slice(),
[bt]: r,
[z]: o,
[kt]: l,
[Et]: e,
[Z]: s,
[lt]: t ?? null
}), a;
}), we = Zt(
({ initialItemCount: t = 0, data: e, context: n, columnCount: r, useWindowScroll: o = !1, ItemContent: s = Mt, ...l }, i) => {
const u = te(() => {
const c = new qt();
return c.register(L), c.register(ot), c.register(st), c.pubIn({
[Z]: e.slice(),
[ft]: n,
[k]: r,
[Vt]: s,
[pt]: t,
[j]: o
}), c;
}, []);
return ie(u, () => ({}), []), xt(() => {
f.pubIn({
[st]: n.slice(),
[bt]: r,
[z]: o
return ee(i, () => ({}), []), Et(() => {
u.pubIn({
[Z]: e.slice(),
[ft]: n,
[k]: r
});
}), /* @__PURE__ */ V(ee.Provider, { value: f, children: /* @__PURE__ */ V(Ee, { ...i }) });
}), /* @__PURE__ */ C(Kt.Provider, { value: u, children: /* @__PURE__ */ C(Se, { ...l }) });
}
);
Ne.displayName = "VirtuosoMasonry";
const Ce = {
we.displayName = "VirtuosoMasonry";
const ye = {
observe: () => {

@@ -529,145 +514,100 @@ },

}
}, Ee = ({ style: t, ...e }) => {
const n = ne(), [r] = ce(() => {
}, Se = ({ style: t, ...e }) => {
const n = Jt(), [r] = ne(() => {
if (typeof ResizeObserver > "u") {
if (typeof window < "u")
throw new Error("ResizeObserver not found. Please ensure that you have a polyfill installed.");
return Ce;
return ye;
}
return new ResizeObserver((c) => {
const m = c.length, I = n.getValue(z), F = n.getValue(Z), L = n.getValue(lt), g = Array.from({ length: I }, () => []), C = {};
return new ResizeObserver((f) => {
const d = f.length, R = n.getValue(k), A = n.getValue(j), U = Array.from({ length: R }, () => []), I = {};
let v = {};
for (let w = 0; w < m; w++) {
const W = c[w], x = W.target;
if (x === l.current) {
if (F)
v = {
...v,
[k]: window.scrollY,
[P]: document.documentElement.scrollHeight,
[D]: window.innerHeight,
[dt]: window.innerWidth
};
else if (L !== null) {
const T = L.current;
if (T) {
const K = T.getBoundingClientRect();
v = {
...v,
[k]: T.scrollTop,
[P]: T.scrollHeight,
[D]: K.height,
[dt]: K.width
};
}
} else
v = {
...v,
[k]: x.scrollTop,
[P]: x.scrollHeight,
[D]: W.contentRect.height,
[dt]: x.clientWidth,
[P]: x.scrollHeight,
[J]: W.contentRect.top
};
for (let M = 0; M < d; M++) {
const N = f[M], p = N.target;
if (p === l.current) {
v = {
...v,
[Q]: A ? window.scrollY : p.scrollTop,
[J]: A ? document.documentElement.scrollHeight : p.scrollHeight,
[at]: A ? window.innerHeight : N.contentRect.height,
[re]: A ? window.innerWidth : p.clientWidth,
...A ? {} : { [J]: p.scrollHeight, [tt]: N.contentRect.top }
};
continue;
}
if (x.dataset.role === "column") {
if (p.dataset.role === "column") {
l.current && (v = {
...v,
[P]: l.current.scrollHeight
[J]: l.current.scrollHeight
});
continue;
}
if (x.dataset.index === void 0)
if (p.dataset.index === void 0)
continue;
const _ = Number.parseInt(x.dataset.index), nt = Number.parseFloat(x.dataset.knownSize ?? ""), E = W.contentRect.height, mt = Number.parseInt(x.dataset.columnIndex ?? "0"), G = Number.parseInt(x.dataset.absoluteIndex ?? "0");
if (C[G] = E, E === nt)
const V = Number.parseInt(p.dataset.index), q = Number.parseFloat(p.dataset.knownSize ?? ""), T = N.contentRect.height, P = Number.parseInt(p.dataset.columnIndex ?? "0"), it = Number.parseInt(p.dataset.absoluteIndex ?? "0");
if (I[it] = T, T === q)
continue;
const M = g[mt], R = M[M.length - 1];
M.length === 0 || R.size !== E || R.endIndex !== _ - 1 ? M.push({ endIndex: _, size: E, startIndex: _ }) : M[M.length - 1].endIndex++;
const x = U[P], W = x[x.length - 1];
x.length === 0 || W.size !== T || W.endIndex !== V - 1 ? x.push({ endIndex: V, size: T, startIndex: V }) : x[x.length - 1].endIndex++;
}
g.some((w) => w.length > 0) && (v = {
U.some((M) => M.length > 0) && (v = {
...v,
[Dt]: g
}), Object.keys(C).length > 0 && (v = {
[Bt]: U
}), Object.keys(I).length > 0 && (v = {
...v,
[qt]: C
[Wt]: I
}), n.pubIn(v);
});
}), o = j(
(c) => {
r.observe(c);
}), o = F(
(f) => {
r.observe(f);
},
[r]
), s = j(
(c) => {
r.unobserve(c);
), s = F(
(f) => {
r.unobserve(f);
},
[r]
), l = It(null), i = It([]), u = j(
(c) => (m) => {
if (m)
i.current[c] = m, r.observe(m, { box: "border-box" });
), l = ut(null), i = ut([]), u = F(
(f) => (d) => {
if (d)
i.current[f] = d, r.observe(d, { box: "border-box" });
else {
const I = i.current[c];
I != null && (r.unobserve(I), i.current[c] = null);
const R = i.current[f];
R != null && (r.unobserve(R), i.current[f] = null);
}
},
[r]
), f = j(() => {
const c = l.current;
c !== null && n.pub(k, c.scrollTop);
}, [n]), a = j(
(c) => {
c ? (l.current = c, c.addEventListener("scroll", f), r.observe(c, { box: "border-box" })) : l.current && (l.current.removeEventListener("scroll", f), r.unobserve(l.current), l.current = null);
), c = F(() => {
const f = l.current;
f !== null && n.pub(Q, f.scrollTop);
}, [n]), h = F(
(f) => {
f ? (l.current = f, f.addEventListener("scroll", c), r.observe(f, { box: "border-box" })) : l.current && (l.current.removeEventListener("scroll", c), r.unobserve(l.current), l.current = null);
},
[r, f]
), [H, S, q, O] = re(
ft,
kt,
Z,
lt
);
return xt(() => {
var c;
if (O) {
const m = (I) => {
var g;
const F = I.target, L = F.getBoundingClientRect();
[r, c]
), [E, y, B] = Qt(ot, Vt, j);
return Et(() => {
if (B) {
const f = () => {
var d;
n.pubIn({
[k]: F.scrollTop,
[P]: F.scrollHeight,
[D]: L.height,
[J]: (((g = l.current) == null ? void 0 : g.getBoundingClientRect().top) ?? 0) - L.top
[Q]: window.scrollY,
[J]: document.documentElement.scrollHeight,
[at]: window.innerHeight,
[tt]: ((d = l.current) == null ? void 0 : d.getBoundingClientRect().top) ?? 0
});
};
return (c = O.current) == null || c.addEventListener("scroll", m), () => {
var I;
(I = O.current) == null || I.removeEventListener("scroll", m);
return window.addEventListener("scroll", f), f(), () => {
window.removeEventListener("scroll", f);
};
}
}, [n, O]), xt(() => {
if (q) {
const c = () => {
var m;
n.pubIn({
[k]: window.scrollY,
[P]: document.documentElement.scrollHeight,
[D]: window.innerHeight,
[J]: ((m = l.current) == null ? void 0 : m.getBoundingClientRect().top) ?? 0
});
};
return window.addEventListener("scroll", c), c(), () => {
window.removeEventListener("scroll", c);
};
}
}, [q, n]), /* @__PURE__ */ V(Qt, { children: /* @__PURE__ */ V(
}, [B, n]), /* @__PURE__ */ C(Dt, { children: /* @__PURE__ */ C(
"div",
{
...e,
ref: a,
ref: h,
"data-testid": "virtuoso-scroller",
style: {
...q || O !== null ? {
...B ? {
boxSizing: "border-box",

@@ -684,6 +624,6 @@ display: "flex",

},
children: H.columns.map((c, m) => /* @__PURE__ */ V(
children: E.columns.map((f, d) => /* @__PURE__ */ C(
"div",
{
ref: u(m),
ref: u(d),
"data-testid": "virtuoso-list",

@@ -693,15 +633,15 @@ style: {

boxSizing: "content-box",
height: c.totalHeight,
height: f.totalHeight,
overflowAnchor: "none",
position: "relative"
},
children: c.items.map((I) => /* @__PURE__ */ V(Me, { ItemContent: S, item: I, mount: o, unmount: s }, I.index))
children: f.items.map((R) => /* @__PURE__ */ C($e, { ItemContent: y, item: R, mount: o, unmount: s }, R.index))
},
`column-${// biome-ignore lint/suspicious/noArrayIndexKey: <explanation>
m}`
d}`
))
}
) });
}, Me = ({ item: t, mount: e, unmount: n, ItemContent: r }) => {
const o = oe(bt), s = It(null), l = j(
}, $e = ({ item: t, mount: e, unmount: n, ItemContent: r }) => {
const o = Xt(ft), s = ut(null), l = F(
(i) => {

@@ -712,3 +652,3 @@ i ? (s.current = i, e(i)) : s.current && (n(s.current), s.current = null);

);
return /* @__PURE__ */ V(
return /* @__PURE__ */ C(
"div",

@@ -728,3 +668,3 @@ {

},
children: /* @__PURE__ */ V(r, { data: t.data, index: t.index, context: o })
children: /* @__PURE__ */ C(r, { data: t.data, index: t.index, context: o })
}

@@ -734,3 +674,3 @@ );

export {
Ne as VirtuosoMasonry
we as VirtuosoMasonry
};

@@ -21,3 +21,3 @@ {

},
"version": "1.3.1",
"version": "1.3.2",
"type": "module",

@@ -31,51 +31,4 @@ "module": "dist/index.js",

},
"scripts": {
"build": "tsc && vite build",
"dev": "ladle serve",
"test": "vitest",
"e2e": "echo 'No e2e tests'",
"typecheck": "tsc --noEmit",
"docs:build": "npx typedoc --plugin typedoc-plugin-no-inherit --watch --excludeInternal --excludePrivate --out docs --name 'Virtuoso Masonry' src/index.ts",
"docs:serve": "npx serve docs",
"lint": "biome check",
"ci-lint": "biome ci",
"knip": "knip"
},
"release": {
"branches": [
"+([0-9])?(.{+([0-9]),x}).x",
"main",
"next",
"next-major",
{
"name": "beta",
"prerelease": true
},
{
"name": "alpha",
"prerelease": true
}
],
"plugins": [
"@semantic-release/commit-analyzer",
"@semantic-release/release-notes-generator",
[
"@semantic-release/changelog",
{
"changelogFile": "CHANGELOG.md"
}
],
"@semantic-release/npm",
[
"@semantic-release/git",
{
"assets": [
"CHANGELOG.md"
]
}
]
]
},
"dependencies": {
"@mdxeditor/gurx": "^1.2.3"
"@virtuoso.dev/gurx": "1.0.0"
},

@@ -89,8 +42,2 @@ "peerDependencies": {

"@ladle/react": "^4.1.2",
"@ngneat/falso": "^7.2.0",
"@playwright/test": "^1.49.0",
"@semantic-release/changelog": "^6.0.3",
"@semantic-release/git": "^10.0.1",
"@testing-library/jest-dom": "^6.6.3",
"@testing-library/react": "^16.0.1",
"@types/node": "^22.10.1",

@@ -100,3 +47,3 @@ "@types/react": "^18.3.12",

"@vitejs/plugin-react-swc": "^3.7.2",
"@vitest/browser": "^2.1.6",
"@vitest/browser": "^3.0.0-beta.3",
"globals": "^15.12.0",

@@ -114,3 +61,5 @@ "jsdom": "^25.0.1",

"vite-plugin-dts": "^4.3.0",
"vitest": "^2.1.6"
"vitest": "3.0.0-beta.3",
"react": "18",
"react-dom": "18"
},

@@ -123,3 +72,15 @@ "engines": {

"CHANGELOG.md"
]
}
],
"scripts": {
"build": "tsc && vite build",
"dev": "ladle serve",
"test": "vitest",
"e2e": "echo 'No e2e tests'",
"typecheck": "tsc --noEmit",
"docs:build": "npx typedoc --plugin typedoc-plugin-no-inherit --watch --excludeInternal --excludePrivate --out docs --name 'Virtuoso Masonry' src/index.ts",
"docs:serve": "npx serve docs",
"lint": "biome check",
"ci-lint": "biome ci",
"knip": "knip"
}
}