How ephibbs/flowtoken works
Project type and purpose
• FlowToken is a front-end React component library (published as an npm package) whose sole purpose is to animate streaming text (and other inline content) from Large Language Models (LLMs). It provides a set of highly customizable, performant, CSS-based animations for words, characters, code blocks, images, and even user-supplied custom components.
File structure
• Top level:
• package.json, tsconfig.json, tailwind.config.js, postcss.config.js, eslint/ignore files → build, lint & distribution configuration
• .storybook/ → Storybook integration for live component preview & docs
• stories/ → sample/demo code for each component in Storybook
• src/
• src/index.ts → library entry point (exports)
• src/components/ → the actual React components:
– AnimatedMarkdown.tsx
– AnimatedText.tsx
– AnimatedImage.tsx
– CodeRenderer.tsx & DefaultCode.tsx
– SplitText.tsx
• src/utils/animations.ts → centralized definitions of CSS keyframes and utility helpers
• src/styles.css → base CSS (animation class names, utility classes)
• This is purely a UI-centric, component-based codebase—no backend, no database, no external microservices.
README for additional insights
• Confirms React + optional Tailwind usage
• Emphasizes streaming of LLM content, markdown support, custom component injection
• Lists all built-in animation types (fadeIn, dropIn, typewriter, etc.)
Main components & their relationships
• AnimatedMarkdown
• Parses markdown → splits into inline tokens → delegates rendering to SplitText, CodeRenderer, and/or customComponents
• SplitText
• Receives plain text or markdown node → splits by word/char based on “sep” prop → wraps each chunk in AnimatedText
• AnimatedText
• Applies a given CSS animation class (e.g. “fadeIn”) with duration & timing props → renders a span per chunk
• CodeRenderer & DefaultCode
• Syntax-highlight code blocks (using a highlighter library) and animate appearance
• AnimatedImage
• Renders images with entry animations
• utils/animations.ts
• Central registry of @keyframes and helper functions → imported by components or included in styles
• src/index.ts
• Exposes all components & CSS entrypoint (styles.css) as the package API
Important architectural patterns & principles
• Component composition & single responsibility: each component wraps one concern (markdown → split → animate)
• Strategy pattern via customComponents prop: consumers can inject their own renderers at parse-time
• CSS-first animations: leverages pure CSS @keyframes for smooth GPU-accelerated effects
• Configuration & theming via props + tailwind integration
• Orange for “Consumer App” and “Storybook”