Primitives / foldkit-primitives/state
masonry
function · packages/primitives/src/state/virtual.ts:466
function masonry(
keys: ReadonlyArray<string>,
heights: Readonly<Record<string, number>>,
options: {
readonly columns: number
readonly columnWidth: number
readonly gap: number
readonly estimatedHeight: number
},
): {
readonly placements: ReadonlyArray<MasonryPlacement>
readonly totalHeight: number
}Masonry layout as a pure function: fixed column count and width, each item packed into the currently shortest column. Unmeasured items use the estimate; poisoned heights fall back the same way. This is layout only, not windowing — every placed item renders, so it fits hundreds of images, not hundred-thousands. Needing a windowed grid is a different algorithm.