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 🙏

© 2026 – Pkg Stats / Ryan Hefner

fetta

v1.2.1

Published

Text splitting library with kerning compensation for animations

Readme

Fetta

A text-splitting library with kerning compensation for smooth, natural text animations.

Split text into characters, words, and lines while preserving the original typography. Works with any animation library.

Features

  • Kerning Compensation — Measures kerning between character pairs, applies margin adjustments to maintain original spacing
  • Nested Elements — Preserves inline HTML elements (<a>, <em>, <strong>, etc.) with all attributes intact
  • Line Detection — Detects lines based on Y-position clustering, works with any container width
  • Dash Handling — Allows text to wrap naturally after em-dashes, en-dashes, and hyphens
  • Auto Re-split — Automatically re-splits on container resize with debouncing
  • Auto-Revert — Restore original HTML after animations
  • Masking — Wrap elements in clip containers for reveal animations
  • Emoji Support — Properly handles compound emojis and complex Unicode characters
  • Accessible — Automatic screen reader support, even when splitting text with nested links or emphasis
  • TypeScript — Full type definitions included
  • React Component — Declarative wrapper for React projects
  • Built-in InView — Viewport detection for scroll-triggered animations in React
  • Library Agnostic — Works with Motion, GSAP, or any animation library

Installation

npm install fetta

Quick Start

Vanilla JavaScript

import { splitText } from 'fetta';
import { animate, stagger } from 'motion';

const { chars, words, lines, revert } = splitText(
  document.querySelector('h1'),
  { type: 'chars,words,lines' }
);

animate(chars, { opacity: [0, 1], y: [20, 0] }, { delay: stagger(0.02) });

React

import { SplitText } from 'fetta/react';
import { animate, stagger } from 'motion';

function Hero() {
  return (
    <SplitText
      onSplit={({ words }) => {
        animate(words, { opacity: [0, 1], y: [20, 0] }, { delay: stagger(0.05) });
      }}
    >
      <h1>Hello World</h1>
    </SplitText>
  );
}

API

splitText(element, options?)

Splits text content into characters, words, and/or lines.

const result = splitText(element, options);

Options

| Option | Type | Default | Description | |--------|------|---------|-------------| | type | string | "chars,words,lines" | What to split: "chars", "words", "lines", or combinations | | charClass | string | "split-char" | CSS class for character elements | | wordClass | string | "split-word" | CSS class for word elements | | lineClass | string | "split-line" | CSS class for line elements | | mask | "lines" \| "words" \| "chars" | — | Wraps elements in overflow: clip container for reveal animations | | autoSplit | boolean | false | Re-split on container resize | | onResize | function | — | Callback after resize re-split | | onSplit | function | — | Callback after initial split | | revertOnComplete | boolean | false | Auto-revert when animation completes | | propIndex | boolean | false | Add CSS custom properties: --char-index, --word-index, --line-index |

Return Value

{
  chars: HTMLSpanElement[];   // Character elements
  words: HTMLSpanElement[];   // Word elements
  lines: HTMLSpanElement[];   // Line elements
  revert: () => void;         // Restore original HTML and cleanup
}

<SplitText> (React)

import { SplitText } from 'fetta/react';

Props

| Prop | Type | Default | Description | |------|------|---------|-------------| | children | ReactElement | — | Single element to split | | onSplit | function | — | Called after text is split | | onResize | function | — | Called on autoSplit re-split | | options | object | — | Split options (type, classes, mask, propIndex) | | autoSplit | boolean | false | Re-split on container resize | | revertOnComplete | boolean | false | Revert after animation completes | | inView | boolean \| InViewOptions | false | Enable viewport detection | | onInView | function | — | Called when element enters viewport | | onLeaveView | function | — | Called when element leaves viewport |

InView Options

{
  amount?: number;   // How much must be visible (0-1), default: 0
  margin?: string;   // Root margin, default: "0px"
  once?: boolean;    // Only trigger once, default: false
}

Examples

Masked Line Reveal

<SplitText
  options={{ type: 'lines', mask: 'lines' }}
  onSplit={({ lines }) => {
    animate(lines, { y: ['100%', 0] }, { delay: stagger(0.1) });
  }}
>
  <p>Each line reveals from below</p>
</SplitText>

Scroll-Triggered Animation

<SplitText
  onSplit={({ words }) => {
    words.forEach(w => (w.style.opacity = '0'));
  }}
  inView={{ amount: 0.5, once: true }}
  onInView={({ words }) => {
    animate(words, { opacity: 1, y: [20, 0] }, { delay: stagger(0.03) });
  }}
>
  <p>Animates when scrolled into view</p>
</SplitText>

Auto-Revert After Animation

<SplitText
  revertOnComplete
  onSplit={({ chars }) => {
    return animate(chars, { opacity: [0, 1] }, { delay: stagger(0.02) });
  }}
>
  <h1>Reverts to original HTML after animation</h1>
</SplitText>

Responsive Re-split

<SplitText
  autoSplit
  onSplit={({ lines }) => animateLines(lines)}
  onResize={({ lines }) => animateLines(lines)}
>
  <p>Re-animates when container resizes</p>
</SplitText>

CSS-Only Animation with Index Props

<SplitText options={{ type: 'chars', propIndex: true }}>
  <h1 className="stagger-fade">Hello</h1>
</SplitText>
.stagger-fade .split-char {
  opacity: 0;
  animation: fade-in 0.5s forwards;
  animation-delay: calc(var(--char-index) * 0.03s);
}

@keyframes fade-in {
  to { opacity: 1; }
}

With GSAP

import { SplitText } from 'fetta/react';
import gsap from 'gsap';

<SplitText
  revertOnComplete
  onSplit={({ words }) => {
    return gsap.from(words, {
      opacity: 0,
      y: 20,
      stagger: 0.05,
      duration: 0.6,
    });
  }}
>
  <h1>Works with GSAP</h1>
</SplitText>

Nested HTML Elements

Fetta preserves inline elements like links, emphasis, and other formatting. Attributes (href, class, id, data-*, etc.) are maintained.

<SplitText
  onSplit={({ chars }) => {
    animate(chars, { opacity: [0, 1] }, { delay: stagger(0.02) });
  }}
>
  <p>Click <a href="/signup">here</a> to <em>get started</em></p>
</SplitText>

CSS Classes

Default classes applied to split elements:

| Class | Element | Notes | |-------|---------|-------| | .split-char | Characters | Inline positioning | | .split-word | Words | Inline positioning | | .split-line | Lines | Block display |

Each element also receives a data-index attribute with its position.

Notes

  • Fonts must be loaded before splitting. The React component waits for document.fonts.ready automatically.
  • Ligatures are disabled (font-variant-ligatures: none) because ligatures cannot span multiple elements.
  • Accessibility: Automatic screen reader support for both simple text and text with nested elements like links.

Browser Support

All modern browsers: Chrome, Firefox, Safari, Edge.

Requires:

  • ResizeObserver
  • IntersectionObserver
  • Intl.Segmenter

License

MIT