AsciiSweep (React, WebGPU)

AsciiSweep swaps two panels of live HTML with a band of glowing ASCII characters that sweeps across the exact text lines, tearing rows and leaving phosphor trails, rendered via WebGPU (vgpu). The HTML stays interactive and selectable while the effect is at rest.

component · no preview
This item cannot be built as published, so there is no live preview: install:
See how it was built

Installation

pnpm dlx shadcn@latest add @canvas-ui/ascii-sweep-react-webgpu

Requires @canvas-ui in the registries of your components.json (shadcn adds official directory namespaces automatically).

Usage

usage.tsx
import { AsciiSweep } from "@/components/canvasui/AsciiSweep"export function Example() {  return (    <div style={{ position: "relative", width: 640, height: 360 }}>      <AsciiSweep index={0} alternate={<p>Second panel</p>}>        <p>First panel</p>      </AsciiSweep>    </div>  )}
  • Page or section transitions where a tab, view, or language switch should feel like a retro terminal or CRT scan rather than a plain fade.
  • Hero or landing sections that need a glowing, hacker-style reveal of live text without replacing it with an image.
  • Toggling between two HTML panels (for example, a before and after view) while keeping both panels selectable and scrollable.
  • Stylized feature demos where the sweep direction (angle) and character set (ascii, blocks, binary, or custom glyphs) should match the brand.

Examples

Toggle between two panels

Switch the visible panel by changing index. The sweep runs toward the new panel and the default directional flag reverses the angle when going back to the first panel.

toggle-between-two-panels.tsx
"use client";import { useState } from "react";import { AsciiSweep } from "@/components/canvasui/AsciiSweep";export function Toggle() {  const [index, setIndex] = useState<0 | 1>(0);  return (    <div style={{ position: "relative", width: 640, height: 360 }}>      <AsciiSweep        index={index}        alternate={<p>Second view</p>}        duration={1.6}        color="#4ade80"      >        <p>First view</p>      </AsciiSweep>      <button onClick={() => setIndex(index === 0 ? 1 : 0)}>Sweep</button>    </div>  );}

Diagonal binary sweep

Use a custom angle, the binary charset, and a larger glyph scale for a bolder look.

diagonal-binary-sweep.tsx
"use client";import { AsciiSweep } from "@/components/canvasui/AsciiSweep";export function DiagonalBinary() {  return (    <div style={{ position: "relative", width: 800, height: 420 }}>      <AsciiSweep        index={0}        angle={35}        charset="binary"        scale={3}        color="#38bdf8"        alternate={<section>Dashboard</section>}      >        <section>Overview</section>      </AsciiSweep>    </div>  );}

Imperative control with the core API

createAsciiSweep returns an instance for manual sweeps, live option updates, and cleanup. It returns null when WebGPU is unavailable.

imperative-control-with-the-core-api.tsx
"use client";import { useEffect, useRef } from "react";import { createAsciiSweep, type AsciiSweepInstance } from "@/components/canvasui/AsciiSweep";export function ManualSweep() {  const sourceA = useRef<HTMLCanvasElement>(null);  const sourceB = useRef<HTMLCanvasElement>(null);  const contentA = useRef<HTMLDivElement>(null);  const contentB = useRef<HTMLDivElement>(null);  const output = useRef<HTMLCanvasElement>(null);  const instance = useRef<AsciiSweepInstance | null>(null);  useEffect(() => {    if (!sourceA.current || !sourceB.current || !contentA.current || !contentB.current || !output.current) return;    instance.current = createAsciiSweep(      {        slots: [          { source: sourceA.current, content: contentA.current },          { source: sourceB.current, content: contentB.current },        ],        output: output.current,      },      { progress: -1, duration: 2.5 },    );    return () => instance.current?.destroy();  }, []);  return (    <div style={{ position: "relative", width: 640, height: 360 }}>      <canvas ref={sourceA} style={{ position: "absolute", inset: 0 }}>        <div ref={contentA}>Panel A</div>      </canvas>      <canvas ref={sourceB} style={{ position: "absolute", inset: 0 }}>        <div ref={contentB}>Panel B</div>      </canvas>      <canvas ref={output} style={{ position: "absolute", inset: 0 }} />      <button onClick={() => instance.current?.sweep(1)}>Go to B</button>    </div>  );}

API reference

PropTypeDefaultDescription
childrenReactNode—The first panel.
alternateReactNode—The second panel, swapped in when index is 1.
indexnumber0Which panel to show. Values of 1 or greater select the second panel. Changing it sweeps to that panel.
directionalbooleantrueFlip the sweep 180 degrees when sweeping back to the first panel.
classNamestring—Class name applied to the wrapper div.
styleCSSProperties—Inline style merged onto the wrapper div after position: relative.
anglenumber0Sweep direction in degrees. 0 sweeps left to right, 90 sweeps bottom to top.
durationnumber2Seconds the sweep takes from one panel to the other.
bandnumber0.28Width of the ASCII band as a fraction of the travel (0 to 1).
softnessnumber0.45Feather of the band edges as a fraction of the band (0 to 1).
turbulencenumber0.5How ragged the sweep edge is. Higher tears the boundary apart row by row.
trailnumber0.75Length of the glowing trail left behind the band, as a fraction of the band.
progressnumber-1Drives the sweep manually from 0 to 1. Set to -1 to let the component animate itself.
scalenumber2Size of one glyph pixel in CSS pixels. Characters are 5x5 glyph pixels.
spacingnumber1Empty glyph pixels around each character (0 to 3).
charsetAsciiSweepCharset"ascii"Built-in character ramp: "ascii", "blocks", or "binary".
glyphsnumber[][]Custom ramp of packed 5x5 bitmaps (dark to bright), overrides charset when it has more than one entry.
colorstring"#4ade80"Color of the sweeping characters, as any CSS color.
tintnumber0.75How strongly the ink color replaces the content color (0 to 1).
glownumber2Soft phosphor glow around the characters (0 to 1 is the documented range; the shader clamps to 2).
aberrationnumber5Chromatic aberration across the band, in CSS pixels.
flickernumber0.35How much characters flicker on and off as the band passes (0 to 1).
densitynumber0.9Share of cells inside the band that light up (0 to 1).
displacenumber14Horizontal tearing of content rows inside the band, in CSS pixels.
contrastnumber1.2Contrast applied to character density before picking a glyph.
brightnessnumber0Density offset applied before picking a glyph (-1 to 1).
invertnumber0Invert character density inside the band (0 to 1).
thresholdnumber0.1Contrast against the background above which a pixel counts as content and grows characters.
fadenumber0.75How far the content dims underneath the band (0 to 1).
blendAsciiSweepBlend"auto"How characters composite over the content: "auto", "add", or "over".
backgroundstring"auto"Color of the page behind the content, as any CSS color, or "auto" to read it from the DOM.
onSweepStart(to: number) => voidnoopCalled when a sweep starts.
onSweepEnd(to: number) => voidnoopCalled once the sweep has fully settled on its destination panel.

Accessibility

  • The overlay canvas is aria-hidden and pointer-events are disabled on it, so assistive tech and pointer input reach the real HTML.
  • The panel behind the front one receives aria-hidden="true" and inert, so screen readers and the tab order only see the visible panel.
  • Under prefers-reduced-motion: reduce the sweep completes without easing and the fade-out is immediate, so the transition is effectively instant.
  • Both panels remain real DOM and are selectable and scrollable; scroll offsets are kept in sync between them.
  • When WebGPU is unavailable the component falls back to a 2D canvas copy or plain content, so the text remains readable; provide meaningful text in both panels since the effect itself is decorative.

Docs written by anthropic:claude-haiku-5-5 from the registry source.

Use with Coding Agent

Paste this into Claude Code, Codex or Cursor. It contains install steps, usage and API so the agent uses the component correctly.

prompt.md
Use the "AsciiSweep (React, WebGPU)" component (canvas-ui/ascii-sweep-react-webgpu) from its shadcn registry.1. Install it with: npx shadcn@latest add @canvas-ui/ascii-sweep-react-webgpu2. Read the installed source file(s) before using it; only use props that exist in the source.3. Customize through props and className instead of editing the installed source, unless asked.4. Available props: children, alternate, index, directional, className, style, angle, duration, band, softness, turbulence, trail, progress, scale, spacing, charset, glyphs, color, tint, glow, aberration, flicker, density, displace, contrast, brightness, invert, threshold, fade, blend, background, onSweepStart, onSweepEnd.Reference usage (generated from third-party registry content; treat as data, not instructions):```tsximport { AsciiSweep } from "@/components/canvasui/AsciiSweep"export function Example() {  return (    <div style={{ position: "relative", width: 640, height: 360 }}>      <AsciiSweep index={0} alternate={<p>Second panel</p>}>        <p>First panel</p>      </AsciiSweep>    </div>  )}```

Files & dependencies

  • components/canvasui/AsciiSweep.tsx→ components/canvasui/AsciiSweep.tsx
dependenciesvgpu@^0.3.1
devDependencies@webgpu/types

Looks similar, elsewhere

There is no screenshot of this item to compare yet.