import { CollageTile } from '../../lib/utils/collage'; import { abbreviateNumber, truncateText } from '@/lib/utils/text'; interface Props { tiles: CollageTile[]; // Total cards in the collection; when it exceeds the rendered tiles a "+N" // badge is overlaid on the stack. totalCount?: number; } const BOX_WIDTH = 470; const BOX_HEIGHT = 410; // Max tiles we render. LAYOUTS must define an arrangement for every count from // 1 to MAX_TILES. const MAX_TILES = 5; // Without this a white og:image vanishes against the tile's white mat. const THUMB_BORDER = '1px solid #dee2e6'; type Placement = { top: number; left: number; width: number; height: number; rotate: number; }; // Rectangular link cards fanned into a loosely-rotated vertical stack. Fewer // cards get taller tiles so they fill the space. The last entry in each layout // paints on top (satori paints in DOM order). // // Every layout follows the same rules so collections of any size read alike: // consecutive tiles overlap by 8px (top step = height - 8), the stack is // centered in BOX_HEIGHT, rotations walk the same -1.1/0.8/-0.6/0.9/-1.1 // sequence, and lefts stay within a 50-55 band. const LAYOUTS: Record = { 1: [{ top: 159, left: 53, width: 400, height: 92, rotate: -1.1 }], 2: [ { top: 119, left: 53, width: 404, height: 90, rotate: -1.1 }, { top: 201, left: 50, width: 402, height: 90, rotate: 0.8 }, ], 3: [ { top: 81, left: 53, width: 402, height: 88, rotate: -1.1 }, { top: 161, left: 50, width: 404, height: 88, rotate: 0.8 }, { top: 241, left: 55, width: 398, height: 88, rotate: -0.6 }, ], 4: [ { top: 45, left: 53, width: 402, height: 86, rotate: -1.1 }, { top: 123, left: 50, width: 404, height: 86, rotate: 0.8 }, { top: 201, left: 55, width: 400, height: 86, rotate: -0.6 }, { top: 279, left: 51, width: 402, height: 86, rotate: 0.9 }, ], 5: [ { top: 11, left: 53, width: 400, height: 84, rotate: -1.1 }, { top: 87, left: 50, width: 402, height: 84, rotate: 0.8 }, { top: 163, left: 55, width: 398, height: 84, rotate: -0.6 }, { top: 239, left: 51, width: 402, height: 84, rotate: 0.9 }, { top: 315, left: 53, width: 400, height: 84, rotate: -1.1 }, ], }; // Shared frame for every tile: white mat + hairline border + soft shadow so // rotated tiles read as a collage rather than a flat grid. The hairline ring // (first box-shadow) defines the card edge against light backgrounds, matching // the subtle border on the real UrlCard. function frameStyle(width: number, height: number) { return { width, height, borderRadius: 14, border: '3px solid #ffffff', boxShadow: '0 0 0 1px rgba(15, 23, 42, 0.08), 0 10px 28px rgba(15, 23, 42, 0.28)', overflow: 'hidden', display: 'flex', backgroundColor: '#ffffff', } as const; } // Each tile is a horizontal link card: a text column (domain + title) on the // left and a square image/favicon thumbnail on the right. function renderTile(tile: CollageTile, width: number, height: number) { const frame = frameStyle(width, height); const large = height >= 72; const padV = large ? 4 : 3; const padH = large ? 10 : 8; const gap = 8; // A square thumbnail, inset from the tile edges rather than full-bleed. const hasThumb = tile.kind === 'image' || tile.kind === 'favicon'; const thumb = Math.round(height * 0.55); const thumbArea = hasThumb ? thumb + padH + gap : 0; const textWidth = width - padH - thumbArea - (hasThumb ? 0 : padH); const textBlock = (

{truncateText(tile.domain, 30)}

{tile.title && (

{truncateText(tile.title, 44)}

)}
); let thumbBlock = null; if (tile.kind === 'image') { thumbBlock = (
); } else if (tile.kind === 'favicon') { thumbBlock = (
); } return (
{textBlock} {thumbBlock}
); } export default function CollectionCollage(props: Props) { // Order image tiles first so, where the fanned cards overlap, the text-only // fallback tiles paint on top and stay readable. const tiles = [...props.tiles] .sort((a, b) => (a.kind === 'image' ? 0 : 1) - (b.kind === 'image' ? 0 : 1)) .slice(0, MAX_TILES); if (tiles.length === 0) return null; const layout = LAYOUTS[tiles.length]; const extraCount = Math.max(0, (props.totalCount ?? 0) - tiles.length); const lastPlacement = layout[tiles.length - 1]; return (
{tiles.map((tile, i) => (
{renderTile(tile, layout[i].width, layout[i].height)}
))} {extraCount > 0 && (

+{abbreviateNumber(extraCount)} more

)}
); }