npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

flowtoken

v1.0.17

Published

![flow token demo](https://nextjs-omega-five-46.vercel.app/demo.gif)

Downloads

293

Readme

FlowToken - Smooth Animation Library for LLM Text Streaming

flow token demo

FlowToken is a React component library designed to enhance the visual presentation of text streaming from large language models (LLMs). This library offers a variety of animations that make the text appear smoothly and dynamically, providing an engaging user experience.

Demo

Try the demo here: Demo link

Features

FlowToken includes several key features:

  • Customizable Animations: A range of animations such as fade, blur-in, drop-in, slide from the left, typewriter effect, word pull-up, flip text, gradual spacing, and more.
  • Smooth Text Streaming: Options to control the speed and manner of text appearance to handle the variability in text generation speed.
  • Responsive and Lightweight: Optimized for performance and compatibility across all modern browsers.

Installation

Install FlowToken using npm:

npm install flowtoken

Or using yarn:

yarn add flowtoken

Usage

Markdown Support

To use markdown, import the AnimatedMarkdown component.

import React from 'react';
import { AnimatedMarkdown } from 'flowtoken';

const App = () => {
  return (
    <AnimatedMarkdown
      incomingText="## Hello, world!"
      sep="word"
      animation="fadeIn"
      animationDuration="0.5s"
      animationTimingFunction="ease-in-out"
    />
  );
};

export default App;

Real World with Vercel AI SDK

'use client'

import { useChat } from 'ai/react'
import { StreamText } from 'flowtoken';

export default function Chat() {
  const { messages, input, handleInputChange, handleSubmit } = useChat()

  return (
    <div>
      {messages.map(m => (
        <div key={m.id}>
          {m.role}: <AnimatedMarkdown content={m.content}
            sep="word"
            animation={index === messages.length - 1 && m.role === "assistant" ? "fadeIn" : null}
            animationDuration="0.5s"
            animationTimingFunction="ease-in-out"
            />
        </div>
      ))}

      <form onSubmit={handleSubmit}>
        <label>
          Say something...
          <input
            value={input}
            onChange={handleInputChange}
          />
        </label>
      </form>
    </div>
  )
}

AnimatedMarkdown Props

  • incomingText: The text to be displayed.
  • sep: word or char (word recommended).
  • animation: Name of the CSS animation to apply. See below for options.
  • animationDuration: CSS Duration of the animation. Ex. 0.6s
  • animationTimingFunction: CSS Timing function of the animation. Ex. ease, ease-in-out, etc
  • codeStyle: The highlighter js style object to use.

Animations

FlowToken supports various CSS animations:

  • fadeIn
  • blurIn
  • typewriter
  • slideInFromLeft
  • fadeAndScale
  • rotateIn
  • bounceIn
  • elastic
  • highlight
  • blurAndSharpen
  • dropIn
  • slideUp
  • wave

For custom animations, define your keyframes in CSS and pass the animation name to the animation prop.

Notes

To lower the memory footprint, disable animations by setting the animation parameter to null on any completed messages.

If using tailwind with generated markdown, be sure to setup tailwind typography: https://github.com/tailwindlabs/tailwindcss-typography

and add prose lg:prose-md prose-pre:p-0 prose-pre:m-0 prose-pre:bg-transparent to your flowtoken markdown container.

StreamText

Here is a simple example of how to use the StreamText component from FlowToken, which does not render markdown:

import React from 'react';
import { StreamText } from 'flowtoken';

const App = () => {
  return (
    <StreamText
      incomingText="Hello, world!"
      windowSize={5}
      delayMultiplier={1.1}
      sep="word"
      animation="fadeIn"
      animationDuration="0.5s"
      animationTimingFunction="ease-in-out"
    />
  );
};

export default App;

StreamText Props

  • incomingText: The text to be displayed.
  • windowSize: Number of tokens to consider for smoothing animations.
  • delayMultiplier: Multiplier to adjust the delay for each token or character's appearance.
  • sep: word or char (word recommended).
  • animation: Name of the CSS animation to apply.
  • animationDuration: Duration of the animation.
  • animationTimingFunction: Timing function of the animation.

Contributing

Contributions are welcome! Please feel free to submit pull requests or open issues to suggest features or report bugs.

License

FlowToken is MIT licensed.