Renderers
TypingFlow operates on "nodes" to build a typing snapshot. Renderer is a function that should render a snapshot after processing each command. The package has several ready-made renderers.
Types
type TypingSnapshot = {
content: Array<string>;
cursorPosition: number;
};
type RendererType = (
typingSnapshot: TypingSnapshot
) => void;Simple Browser Renderer
Will display each character by wrapping it in a span with the specified classes. TypingFlow does not provide any styles. You can customize the display as you like.
import { simpleBrowserRenderer } from "typing-flow/renderers";
type BrowserRendererConfig = {
selector: string;
baseNodeClasses?: string[]; // default: typing-node
nodeWithCursorClasses?: string[]; // default: typing-node_with-cursor
};
const myBrowserRenderer = simpleBrowserRenderer({
selector: ".example",
baseNodeClasses: ["typing-node"],
nodeWithCursorClasses: ["typing-node_with-cursor"],
});Attribute Renderer
Translates the current state of the animation into the specified container attributes.
HTML Renderer
You can use HTML syntax in text command when using this renderer.
Custom Renderer
Renderer is a function like this:
If you want to parametrize the renderer, you can do it like this:
Last updated