// The masonry grid is a CSS grid with very small implicit rows: one row is // 1/ROWS_PER_COLUMN_WIDTH of the column width, so a photo's height in rows // follows from its aspect ratio alone, at any screen width. No measuring in // the browser, so nothing shifts while photos load. export const ROWS_PER_COLUMN_WIDTH = 40; // Vertical space between two photos, in rows (about 5% of the column width) export const GAP_ROWS = 2; // How many implicit rows a photo spans: its height at the column width, in // rows, plus the gap below it. Rounding crops at most half a row. export function masonryRowSpan( image: { width: number; height: number }, rowsPerColumnWidth: number = ROWS_PER_COLUMN_WIDTH, gapRows: number = GAP_ROWS, ): number { const photoRows = Math.max( 1, Math.round((rowsPerColumnWidth * image.height) / image.width), ); return photoRows + gapRows; }