streaming/reveal_spans library

Applying a character reveal to spans that are already built.

The alternative — re-slicing the Markdown source every frame and rendering the prefix — reparses the tail on every tick, and can only ever produce a hard cut: by the time there are spans the character boundaries are gone, so the only softening left is a gradient over whatever pixels happen to be at the bottom of the box.

Working on the span tree instead means the document is rendered once per text change rather than once per frame, and a frame's whole job is restyling the handful of characters still arriving. It also has nothing to say about which parser produced the spans, so one implementation serves both pipelines.

Classes

RevealableSpan
A widget span that lets the reveal reach the text inside it.

Functions

applyReveal({required List<InlineSpan> spans, required int revealed, required GptMarkdownAnimation effect, required double progressFor(int index), required Color defaultColor, int window = 64}) List<InlineSpan>
Rebuilds spans showing only the first revealed characters, with the ones still arriving styled by effect.
countRevealCharacters(List<InlineSpan> spans) int
Total characters in spans, counting a placeholder as one.

Typedefs

SpanTransform = List<InlineSpan> Function(List<InlineSpan> spans)
Transforms a run of spans — the reveal, handed to a RevealableSpan so it can be applied to content the span builds for itself.