# Rewind

Back to a checkpoint as time running backwards: later messages leave newest first.

Also called: rewind animation, restore checkpoint animation.

> chatcn Pro: needs a Pro license (https://chatcn.dev/pro). Install from the `@chatcn-pro` registry with your license token; setup at https://chatcn.dev/docs/chatcn-pro.

Example: Back to a checkpoint. Restore a checkpoint and the messages after it leave newest first, faster and faster, while the checkpoint's clock turns back. Preview: https://chatcn.dev/preview/rewind-demo

Press Restore on a checkpoint and the messages after it leave in reverse order, the newest first: each folds up and lifts away, the ones above follow faster and faster, and the checkpoint's clock turns back while it happens. Then the thread is exactly as it was.

## Installation

```bash
npx shadcn@latest add @chatcn-pro/rewind
```

## Usage

```tsx
import { Rewind } from "@/components/ui/chatcn/pro/rewind"

<Rewind messages={thread} rewindTo={target} onRestore={setTarget} onRewound={(id) => trimAfter(id)} />
```

## Props

| Prop | Type | Notes |
| --- | --- | --- |
| `messages` | `{ id, role, text, checkpoint? }[]` | A `checkpoint` label marks a restore point |
| `rewindTo` | `string | null` | Plays the rewind after this id |
| `onRestore` | `(id) => void` | Shows Restore on checkpoints |
| `onRewound` | `(id) => void` | Remove the later messages here |

## Accessibility

- Restore buttons are labelled; the removed messages leave the tree once the rewind has played.

## Motion

- Each message folds 280 ms; the gap between them shrinks from 170 to 60 ms. Reduced motion: they go at once.

Source: https://chatcn.dev/docs/components/rewind