(text: string, chars: number)
| 220 | * a `min-height` box grow, an image cannot. |
| 221 | */ |
| 222 | export function wrapText(text: string, chars: number): string[] { |
| 223 | const words = text.split(/\s+/).filter(Boolean); |
| 224 | if (words.length === 0) return ['']; |
| 225 | const lines: string[] = []; |
| 226 | let line = ''; |
| 227 | for (const word of words) { |
| 228 | if (line.length === 0) line = word; |
| 229 | else if (line.length + 1 + word.length <= chars) line = `${line} ${word}`; |
| 230 | else { |
| 231 | lines.push(line); |
| 232 | line = word; |
| 233 | } |
| 234 | } |
| 235 | lines.push(line); |
| 236 | return lines; |
| 237 | } |
| 238 | |
| 239 | /* ------------------------------------------------------------- the frame -- */ |
| 240 |
no test coverage detected