Something went wrong. Try again.
A social knowledge tool for research trails, built on ATProto semble.so
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263import { 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<number, Placement[]> = { 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 = ( <div style={{ display: 'flex', flexDirection: 'column', flex: 1, justifyContent: 'center', paddingTop: padV, paddingBottom: padV, paddingLeft: padH, paddingRight: hasThumb ? gap : padH, gap: 5, }} > <p style={{ fontSize: large ? 17 : 13, color: '#868e96', margin: 0, maxWidth: textWidth, whiteSpace: 'nowrap', overflow: 'hidden', }} > {truncateText(tile.domain, 30)} </p> {tile.title && ( <p style={{ fontSize: large ? 22 : 17, lineHeight: 1.2, color: '#343a40', margin: 0, maxWidth: textWidth, whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis', }} > {truncateText(tile.title, 44)} </p> )} </div> );
let thumbBlock = null; if (tile.kind === 'image') { thumbBlock = ( <div style={{ display: 'flex', alignItems: 'center', paddingRight: padH }} > <img src={tile.dataUri} alt="" width={thumb} height={thumb} style={{ width: thumb, height: thumb, objectFit: 'cover', borderRadius: 8, border: THUMB_BORDER, }} /> </div> ); } else if (tile.kind === 'favicon') { thumbBlock = ( <div style={{ display: 'flex', alignItems: 'center', paddingRight: padH }} > <div style={{ display: 'flex', width: thumb, height: thumb, alignItems: 'center', justifyContent: 'center', backgroundColor: '#f1f3f5', borderRadius: 8, border: THUMB_BORDER, }} > <img src={tile.dataUri} alt="" width={Math.round(thumb * 0.5)} height={Math.round(thumb * 0.5)} /> </div> </div> ); }
return ( <div style={frame}> {textBlock} {thumbBlock} </div> );}
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 ( <div style={{ position: 'relative', display: 'flex', width: BOX_WIDTH, height: BOX_HEIGHT, }} > {tiles.map((tile, i) => ( <div key={i} style={{ position: 'absolute', top: layout[i].top, left: layout[i].left, display: 'flex', transform: `rotate(${layout[i].rotate}deg)`, }} > {renderTile(tile, layout[i].width, layout[i].height)} </div> ))} {extraCount > 0 && ( <div style={{ position: 'absolute', top: lastPlacement.top + lastPlacement.height - 16, right: 16, display: 'flex', alignItems: 'center', padding: '9px 16px', borderRadius: 999, backgroundColor: '#ffffff', boxShadow: '0 0 0 1px rgba(15, 23, 42, 0.08), 0 10px 28px rgba(15, 23, 42, 0.28)', }} > <p style={{ fontSize: 20, lineHeight: 1, color: '#495057', margin: 0, }} > +{abbreviateNumber(extraCount)} more </p> </div> )} </div> );}