Skip to content

Commit 45e447b

Browse files
chenglouno1x0
andcommitted
Inline prepare() vs layout() tip in README
Co-Authored-By: no1x <no1ex.es@gmail.com>
1 parent 77dabd5 commit 45e447b

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ const prepared = prepare('AGI 春天到了. بدأت الرحلة 🚀', '16px I
2828
const { height, lineCount } = layout(prepared, textWidth, 20) // pure arithmetics. No DOM layout & reflow!
2929
```
3030

31-
`prepare()` does the one-time work: normalize whitespace, segment the text, apply glue rules, measure the segments with canvas, and return an opaque handle. `layout()` is the cheap hot path after that: pure arithmetic over cached widths.
31+
`prepare()` does the one-time work: normalize whitespace, segment the text, apply glue rules, measure the segments with canvas, and return an opaque handle. `layout()` is the cheap hot path after that: pure arithmetic over cached widths. Do not rerun `prepare()` for the same text and configs; that'd defeat its precomputation. For example, on resize, only rerun `layout()`.
3232

33-
If you want textarea-like text where ordinary spaces, `\t` tabs, and `\n` hard breaks stay visible, pass `{ whiteSpace: 'pre-wrap' }` to `prepare()` / `prepareWithSegments()`.
33+
If you want textarea-like text where ordinary spaces, `\t` tabs, and `\n` hard breaks stay visible, pass `{ whiteSpace: 'pre-wrap' }` to `prepare()`:
3434

3535
```ts
3636
const prepared = prepare(textareaValue, '16px Inter', { whiteSpace: 'pre-wrap' })

0 commit comments

Comments
 (0)