Skip to main content

Scramble Text

Decodes random glyphs with blur settling left-to-right into target text without horizontal layout jitter.

Verified · access granted

Customize

Blur (px)6
Step (ms)40
Settle (ms)340

Installation

Add Scramble Text with the registry command:

npx shadcn@latest add @kinetic/scramble-text

Usage

Import ScrambleText and pass the target text:

import { ScrambleText } from "@/components/kinetic/ui/scramble-text";

export function StatusHeading() {
  return <ScrambleText text="SYSTEM READY" as="h2" className="text-2xl font-semibold" />;
}

Charset and timing

Customize the scrambled charset, glyph flip cadence (stepMs), per-character settle duration (settleMs), and blurPx (clamped to a maximum of 8 px). Each grapheme cell locks its width in monospace so characters never jitter horizontally, and Vietnamese diacritics stay intact.

<ScrambleText
  text="Tiếng Việt rõ nét"
  charset="ABCDEF0123456789#%&*"
  blurPx={6}
  stepMs={40}
  settleMs={340}
/>

Imperative control

Set trigger="manual" and attach a ref typed with ScrambleTextHandle to call play() or reverse() on demand:

import { useRef } from "react";
import { ScrambleText, type ScrambleTextHandle } from "@/components/kinetic/ui/scramble-text";

interface ManualDecodeProps {
  readonly label: string;
}

export function ManualDecode({ label }: ManualDecodeProps) {
  const ref = useRef<ScrambleTextHandle>(null);

  return (
    <div className="flex items-center gap-3">
      <ScrambleText ref={ref} text={label} trigger="manual" />
      <button type="button" onClick={() => ref.current?.play()}>
        Decode
      </button>
      <button type="button" onClick={() => ref.current?.reverse()}>
        Scramble out
      </button>
    </div>
  );
}

Motion preferences

When reduced motion is active via the browser preference or data-reduced-motion="true", ScrambleText renders the final text immediately with no blur or animation loop and invokes onComplete. Otherwise, timing scales with the Kinetic tempo and speed prop.

API Reference

ScrambleText

Monospace-locked glyph decoder driven by direct ref mutations in requestAnimationFrame.

PropTypeDefaultDescription
textstring-Target string to decode.
charsetstring"ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789#%&*+=<>/"Glyph pool used while scrambling.
blurPxnumber6Maximum blur while decoding (max 8px).
stepMsnumber40Delay between consecutive characters.
settleMsnumber340Time each character takes to lock in.