/* ═══════════════════════════════════════════════════════════════ TEXT Shared helpers for showing a short piece of longer text. preview() is for anywhere a paragraph is cut to fit a row title, a list cell or a card: it collapses whitespace and, when it has to cut, stops at the last whole word and ends with an ellipsis, so a shortened line always reads as shortened. Text that already fits comes back unchanged, with no ellipsis. ═══════════════════════════════════════════════════════════════ */ export function preview(text: string | null | undefined, max: number): string { const flat = (text ?? '').replace(/\s+/g, ' ').trim() if (flat.length <= max) return flat const cut = flat.slice(0, max) const lastSpace = cut.lastIndexOf(' ') // Break on a word if one ends in the back half; otherwise a single // long word would leave almost nothing. const clean = lastSpace > max / 2 ? cut.slice(0, lastSpace) : cut return `${clean.replace(/[\s.,;:!?]+$/, '')}…` } export const capitalize = (word: string) => word ? word.charAt(0).toUpperCase() + word.slice(1) : ''