Introducing a new way to review your PRs.

Read the announcement

bas3line / ascii

Animated ascii art for web pages, in TypeScript: React, Next.js, Astro, or one HTML tag

View on GitHub

21 documents · Updated Oct 26, 2026

docs / framework-rendering-adapters

Framework rendering adapters

The framework rendering adapters connect React and Astro pages to ascii.rest's shared piece renderer. They let consumers play named or supplied pieces and draw text banners while preserving the same text, colour, motion, sizing, and accessibility model across both frameworks. See Public rendering API for the wider browser-facing API and Terminal and output rendering for non-framework output paths.

Adapter roles

React and Astro expose the same two product capabilities through framework-native components: <Ascii> for a reusable animation piece and <Banner> for generated block text. Both choose between text output and colour output, then hand playback to the shared browser renderer.

AdapterConsumer inputInitial resultLive result
ReactA piece object or piece nameAn empty <pre> or <canvas> during server renderingA mounted <pre> or <canvas> after hydration
AstroA piece nameA first text frame or a sized colour placeholder in the HTMLA live custom element after the browser script runs

The adapters do not define a second art format. A piece remains the shared unit of rendering, while the adapter supplies framework lifecycle behavior and passes options to the common mounting system.

References: src/react.tsx• L1-23 src/…/Ascii.astro• L1-16 src/mount.ts• L44-51

React components

The React adapter provides client components for React applications, including Next.js. <Ascii> accepts either an imported piece or a name that loads on demand; <Banner> first creates a piece from text and then uses the same <Ascii> path.

Piece playback

<Ascii> turns a piece into an accessible image-like element. Text art uses a <pre>, while colour art uses a <canvas> unless mono requests one-colour text. The component restarts playback when the piece, its option values, or its output mode changes.

Named pieces support deferred loading. Imported pieces are part of the page's code, while a name lets the component load the selected piece when it mounts. This gives React consumers a choice between immediate availability and a smaller initial page load.

References: src/react.tsx• L25-70 src/library.ts• L1-120

<Banner> converts supplied text and banner options into a piece before rendering it. This keeps banners subject to the same output choice, motion rules, labels, and lifecycle behavior as library pieces. Invalid banner input produces no component output and reports the reason to the browser console.

The component accepts the banner generator's options as props. A colour or shadow produces colour output; without those options, the banner remains text that follows the surrounding element's colour and size.

References: src/react.tsx• L72-106 src/banner.ts• L1-120

Client boundaries

The React adapter is a client component because playback needs browser APIs. A server component can still render it with serializable props such as a piece name or banner values. A piece object must cross through a client component of the consumer's own because executable piece code is not a server-component prop.

Server-rendered React output does not include a computed first frame by default. Consumers that need art in the initial HTML must provide their own stable first frame and then switch to the live component after mount.

References: src/react.tsx• L1-3 src/react.tsx• L38-69 site/…/react.md• L268-299 site/…/react.md• L342-391

Astro components

The Astro adapter provides server-rendered .astro components for named pieces and banners. It resolves the piece during page rendering, puts useful initial content into the HTML, and loads one browser script to replace that content with live playback.

Server-first playback

Astro renders a text piece's first frame in a <pre> before JavaScript runs. For colour art it renders a box with the correct aspect ratio and optional ground colour. This placeholder protects layout while the browser creates the canvas output; mono changes colour art back to a server-visible text frame.

The browser side uses the same named piece and options that the server used. The result is a progressive path: readers can see text art immediately, while animated or colour art becomes live when the script runs.

References: src/…/Ascii.astro• L18-55 src/…/Ascii.astro• L57-80 site/…/astro.md• L36-38 site/…/astro.md• L144-181

The Astro <Banner> component follows the same server-first rule as <Ascii>. It renders a stable banner frame when the output is text and reserves the banner's shape when colour output needs the browser canvas. Banner options are passed directly to the shared banner generator.

Astro's build-time validation makes bad piece names or unsupported banner input page errors instead of deferred browser failures. This gives static pages a clear failure at build or development time.

References: src/…/Banner.astro• L15-48 site/…/astro.md• L76-80 site/…/astro.md• L103-107

Shared output behavior

Both adapters rely on the same mount contract for frame timing and output selection. Playback advances only when the art is visible and the document is active. It stops for reduced-motion users unless the consumer explicitly enables motion for its own control, and it cleans up observers and animation work when the component is removed.

The output target also defines the visual contract:

  • A <pre> shows the frame as text in the element's colour.
  • A <canvas> uses the piece palette or current text colour and fills the available width.
  • mono gives coloured art a text-only path that works without canvas painting.
  • Labels provide the accessible name through role="img" and aria-label.

This shared behavior keeps framework choice separate from rendering policy. A consumer can move between React and Astro without changing what a piece means or how it respects motion and layout.

References: src/mount.ts• L5-14 src/mount.ts• L44-69 src/mount.ts• L181-221 src/react.tsx• L61-69 src/…/Ascii.astro• L43-49

The following flow shows how a framework component turns consumer input into initial page content and then live art.

flowchart LR
    Input[Piece name or banner text] --> Adapter[React or Astro adapter]
    Adapter --> Resolve[Resolve or create piece]
    Resolve --> Mode{Text or colour output?}
    Mode -->|Text| InitialText[Pre-render or mount a pre]
    Mode -->|Colour| InitialCanvas[Reserve or mount a canvas]
    InitialText --> Mount[Shared browser mount]
    InitialCanvas --> Mount
    Mount --> Playback[Visible, motion-aware playback]

Change checklist

When these files or sections are changed, remember to consider these:

  • Keep React's output-mode decision aligned with Astro's decision so palette-bearing pieces and banners reserve the same shape.
  • Keep the server placeholder shape aligned with the browser canvas aspect ratio to avoid layout shift during hydration or script startup.
  • Preserve the piece-name contract between the library loader and both adapter entry points; a name that is accepted by one must resolve to the same piece in the other.
  • Keep accessibility labels on both the server-rendered element and the live output when changing component markup.
  • Keep reduced-motion and visibility behavior in the shared mount path so both framework adapters retain the same playback policy.

Important failure modes

TriggerConsequenceGuard
A React consumer passes a new piece object during every renderPlayback restarts on each renderCreate the piece outside the component or memoize it
A named piece is not present in the libraryReact cannot load the requested art; Astro fails during page renderingUse a library piece name or a valid piece module
A colour canvas has no usable container widthThe art has no useful visible sizeGive the containing element width or a maximum width
A consumer expects colour art in server HTMLThe initial page shows only the reserved boxUse mono or a text banner when initial text is required
A page enables motion without its own controlReduced-motion users may see animation against their preferenceSet motion only when the page provides an explicit play control

Key files

FileWhy to read it
src/react.tsxDefines the React <Ascii> and <Banner> adapter contract.
src/astro/Ascii.astroShows Astro's server-first piece rendering and browser handoff.
src/astro/Banner.astroShows server-first banner rendering and banner-specific validation.
src/mount.tsDefines shared output modes, playback policy, and cleanup behavior.
src/library.tsDefines named piece loading and colour capability lookup used by adapters.
src/banner.tsDefines the banner-to-piece boundary used by both framework paths.
site/…/react.mdExplains React consumer behavior and server-component boundaries.
site/…/astro.mdExplains Astro's initial HTML, placeholders, and styling behavior.