Installation
Usage
import { AsciiField } from "@/components/ascii-field"
export function Hero() {
return (
<AsciiField text="Hello, world." y={0.42} className="flex min-h-[32rem] flex-col items-center justify-end px-6 pb-12 text-center">
<p className="text-muted-foreground">Move your pointer, or press to send a wave.</p>
</AsciiField>
)
}Props
| Prop | Type | Default | Description |
|---|---|---|---|
| text | string | "Signal." | The headline in the picture, in your page's font. Also real text on the page, for screen readers and search engines. |
| src | string | — | A photo to draw in characters instead of the headline (same origin or served with CORS). |
| colors | [string, string] | ["var(--background)", "var(--primary)"] | The ground, then the glow near the pointer. Any CSS colour. |
| charset | string | " .:-=+*#%@" | The characters from darkest to brightest. |
| cell | number | 12 | Height of one character, 8–28 CSS pixels; smaller when the headline needs it to stay readable. |
| tinted | boolean | true | Characters keep the picture's own colours, or use one ink. |
| size | number | 1 | Reach of the ripple around the pointer, 0.5–1.6. |
| y | number | 0.45 | Where the headline sits, from 0 (top) to 1 (bottom). |
| autoplay | boolean | true | When nobody is near, the ripple wanders slowly over the picture. |
| interactive | boolean | true | The ripple follows the pointer; pressing sends a wave out. |
| moment | number | — | Holds the ripple still where it wanders to at this moment, in seconds. |
| captureRef | Ref<AsciiFieldHandle> | — | capture(width, height) resolves a PNG at any size. |
| ...props | HTMLAttributes<HTMLDivElement> | — | Children sit above the picture and stay interactive. |
Accessibility
- The headline is real text in the page (visually hidden), so screen readers and search engines read it; the canvas and its still are decorative and hidden from assistive technology.
- With prefers-reduced-motion the characters stay still and the pointer is ignored.
- It pauses off-screen and in hidden tabs, and frees its GPU memory when removed.
- Without WebGL2, on a software renderer, or on a device that can't hold a smooth frame rate, it shows the picture without the effect.
Changelog
- v1.0.0Latest
First release.