llm-message-react 0.1.3 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +28 -8
- package/dist/highlighters/shiki.d.cts +1 -1
- package/dist/highlighters/shiki.d.ts +1 -1
- package/dist/highlighters/shikiWeb.d.cts +1 -1
- package/dist/highlighters/shikiWeb.d.ts +1 -1
- package/dist/index.cjs +837 -314
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +29 -3
- package/dist/index.d.ts +29 -3
- package/dist/index.js +843 -320
- package/dist/index.js.map +1 -1
- package/dist/styles.css +39 -0
- package/dist/{types-Dz7GupgB.d.cts → types-DETvxTAd.d.cts} +1 -0
- package/dist/{types-Dz7GupgB.d.ts → types-DETvxTAd.d.ts} +1 -0
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -154,15 +154,32 @@ This convenience has a cost: it runs a synchronous KaTeX parse on every streamed
|
|
|
154
154
|
<LLMMessage showUnfinishedLatexBlocks={false}>{content}</LLMMessage>
|
|
155
155
|
```
|
|
156
156
|
|
|
157
|
-
|
|
157
|
+
### Smooth reveal
|
|
158
158
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
159
|
+
By default new text pops in as each chunk arrives. Set `smoothReveal` to fade it in instead — character by character for prose, and as a single unit for complex blocks (code, tables, images, rules). Box decorations (a blockquote's border, list bullets, an inline-code background) fade in together with the content they belong to. Block math (`$$ … $$`, `\[ … \]`) is the one exception: KaTeX only produces output once the whole formula has streamed in, so a fade would just be a flash — instead the block appears instantly the moment the wave reaches it:
|
|
160
|
+
|
|
161
|
+
```tsx
|
|
162
|
+
<LLMMessage smoothReveal>{content}</LLMMessage>
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
The reveal is purely visual: text is always in the DOM the moment it streams in, it just eases up from transparent as a single travelling wave. The wave is sized so it sweeps through the not-yet-revealed text within a short window (`smoothRevealDuration`, default `300` ms). When a new chunk arrives while the previous one is still fading, the leftover (not-yet-revealed) characters and the new ones reveal together over one fresh window, so the animation stays a single coherent wave that keeps pace with the stream instead of many overlapping fades.
|
|
166
|
+
|
|
167
|
+
```tsx
|
|
168
|
+
<LLMMessage smoothReveal smoothRevealDuration={200}>
|
|
169
|
+
{content}
|
|
170
|
+
</LLMMessage>
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
Opacity is computed purely from each character's position relative to the reveal point, so it only ever increases (no flicker) regardless of how the stream re-renders, and it is disabled automatically for users who prefer reduced motion.
|
|
174
|
+
|
|
175
|
+
### Block memoization
|
|
176
|
+
|
|
177
|
+
While a long message streams in, each new chunk would otherwise re-parse and re-render the entire message — re-running KaTeX and code highlighting over text that has not changed. By default `LLMMessage` splits the message into top-level markdown blocks (paragraphs, headings, code fences, math blocks, lists, tables, …) and memoizes each one, so only the last (currently growing) block re-renders on each chunk. Earlier blocks stay mounted and untouched, which keeps streaming smooth regardless of message length.
|
|
178
|
+
|
|
179
|
+
This is on by default and needs no configuration. The one trade-off is that constructs which resolve across blocks — footnotes and link reference definitions — cannot be split (a definition in one block could not be seen by a reference in another). Those are detected automatically and kept in a single block, but if you render content that relies on them and want to be certain, disable splitting:
|
|
180
|
+
|
|
181
|
+
```tsx
|
|
182
|
+
<LLMMessage blockMemoization={false}>{content}</LLMMessage>
|
|
166
183
|
```
|
|
167
184
|
|
|
168
185
|
## Theming
|
|
@@ -239,6 +256,9 @@ import { MyCheckbox, MyCodeBlock, MyLink } from "./ui";
|
|
|
239
256
|
- `highlighter?: CodeHighlighter` — opt-in syntax highlighter for fenced code blocks (see [Syntax highlighting](#syntax-highlighting)). Omitted by default, so no highlighter bundle is pulled in.
|
|
240
257
|
- `completePartialTokens?: boolean` — repair partially-streamed markdown/LaTeX. Defaults to `true`.
|
|
241
258
|
- `showUnfinishedLatexBlocks?: boolean` — progressively render unterminated block math while it streams (costs a synchronous KaTeX parse per chunk); set to `false` to hide unfinished blocks until they close and skip that work. Defaults to `true`. Only relevant while `completePartialTokens` is enabled.
|
|
259
|
+
- `smoothReveal?: boolean` — fade newly-streamed text in (per character for prose, whole-unit for code/tables/images; block math snaps in instantly since it can't fade progressively) instead of popping it in. Purely visual and respects `prefers-reduced-motion`. Defaults to `false`.
|
|
260
|
+
- `smoothRevealDuration?: number` — reveal window in milliseconds for each freshly-arrived chunk. Defaults to `300`. Only relevant while `smoothReveal` is enabled.
|
|
261
|
+
- `blockMemoization?: boolean` — split the message into top-level blocks and memoize each so a streaming chunk only re-renders the last block (see [Block memoization](#block-memoization)). Defaults to `true`.
|
|
242
262
|
- All other `div` props are spread onto the root element.
|
|
243
263
|
|
|
244
264
|
> Pass stable references for `classNames`, `components`, and `highlighter` (define them outside render or memoize them). They are dependencies of an internal `useMemo`, so new object/identity on every render defeats it.
|