# Link unfurl

> A sent invite link unfolded into a black video card, where a fox drawn in white scanlines peeks in and waves.

A message thread whose sent link has become a rich preview: a black video card where a fox engraved in horizontal white stripes leans in from the right edge, smiles, reaches out and waves on a 4.2 s loop, over a caption with the invite’s title and domain. The card opens like a link and lifts on hover; a button on the video pauses the loop. Type a link in the composer and send it, and a new card appears at once with a shimmer, then unfurls.

A React component by Bruno Delorence: https://brunodelorence.com/components/link-unfurl. MIT License, Copyright (c) 2026 Bruno Delorence.

Category: Media.

## Anatomy

1. **Thread**: The conversation, a fixed 312 px tall so sending doesn’t push the page; it scrolls to the newest message.
2. **Time**: When the conversation starts, centred: “Today” in semibold, then the time.
3. **Video**: The preview’s picture, 1.91 : 1, always black: the fox in white scanlines, playing on a 4.2 s loop.
4. **Play and pause**: A 30 px round button on the video; it shows on hover, on focus, while paused, and always on touch screens.
5. **Caption**: The card’s button: the page’s title in 15 px semibold, its domain in 13 px, a chevron. Its hit area covers the whole card.
6. **Receipt**: Under the newest message: Delivered, then Read with the time.
7. **Composer**: Add the invite link, the message field (a voice level, or Send once there is something to send) and add a wave.

## Properties

### Start (`defaultPaused`)

1. **Playing (default)**: The loop runs while the card is on screen.
2. **Paused**: The still frame until the reader presses play.

Let the newest preview play; start older ones, or any beside other motion, paused. Under reduced motion every preview starts paused anyway.

## When to use

- A link sent in a conversation that deserves more than its address: an invite, a release, a shared page with a picture of its own.
- Referral and invite links, where a moving preview in the thread is what gets the tap: the page’s `og:video` played as a short loop.
- Any chat or feed that unfurls links as they are sent: a shimmer while the preview loads, then the card.

## When not to use

- A link inside running text, a list of results or a table. Show the title as a plain link; a card per link drowns the words.
- Pages without a picture or a title of their own. Show the address alone rather than an empty card.
- Several moving previews on one screen. Let one play and keep the others on their still frame.
- Anything the reader must act on without opening it (a code to copy, a date to accept). Put that in the message itself.

### Unfurling

- **At once**: the card appears the moment the link is sent, with its domain, so the thread never jumps from a bare address to a card.
- **A shimmer, not a spinner**, where the picture will be, and a bar where the title will be. Here it unfurls after 1.1 s (`unfurlDelay`).
- **Words that aren’t a link** go as a plain bubble. A link to the invite’s own site unfurls into the fox; any other into its letter.

### The loop

- **Short and quiet**: 4.2 s, the fox leaning in by 7 units, reaching out from 1.05 to 1.5 s and waving until 3.2 s. The end meets the start, so it never jumps.
- **Only while it can be seen**: off screen, in a hidden tab or paused, the canvas stops drawing and holds its frame.
- **Reduced motion** starts it paused on the still frame; the play button still plays it on request.

## Do’s and don’ts

- **Do**: Keep the title to one line at 350 px: what it is and the one thing to know, “Join Hollowfox · Invite code: K7QD”.
- **Don’t**: Pour a whole pitch into the title. Past two lines it is cut off, and the code falls out of sight.
- **Do**: Let the newest preview play and send other links as they come: each unfurls, older ones keep their place.
- **Caution**: Two previews moving side by side pull at the eye. Pause the older one, or start it paused.

## Content

The words are the page’s title and domain, the time and the receipt, and the composer’s placeholder.

- **The title is the page’s own** (`og:title`), in sentence or title case as the site writes it. An invite says what to join and the code: `Join Hollowfox · Invite code: K7QD`.
- **The domain, not the address**: `invite.hollowfox.app`, without https:// or the path, so the reader sees where the link goes.
- **Receipts in two words**: `Delivered`, then `Read 11:01 AM`.
- **No full stops** in the caption or the receipt.

## Installation

Install it with the shadcn CLI, into components/link-unfurl of any React project:

```sh
npx shadcn@latest add https://brunodelorence.com/r/link-unfurl.json
```

Or add the registry to components.json once, as a namespace that coding agents and the shadcn MCP server search by name:

```json
{
  "registries": {
    "@brunodelorence": "https://brunodelorence.com/r/{name}.json"
  }
}
```

```sh
npx shadcn@latest add @brunodelorence/link-unfurl
```

Or copy all the source files below into one folder of your project. Either way it needs React 19.2 and a bundler with CSS Modules (Next.js, Vite).

It has a dark colour scheme. Its colours are CSS light-dark() pairs, kept inside @supports so that builds which rewrite light-dark() for older browsers leave them alone: it follows your page’s color-scheme (light unless the page sets one) or its colorScheme prop, with nothing to configure. Browsers without light-dark() show it light.

## Usage

```tsx
import { LinkUnfurl } from './link-unfurl';

export function InviteThread() {
  return (
    <LinkUnfurl
      app="Hollowfox"
      code="K7QD"
      domain="invite.hollowfox.app"
      onOpen={(href) => window.open(href, '_blank', 'noopener')}
      onSend={(text) => console.log('sent', text)}
      autoplay={false}
    />
  );
}
```

## States

- **Playing**: The default: the fox leans in, smiles, reaches out and waves, and leans back, on a loop.
- **Paused**: With `defaultPaused`, or after Pause: the still frame, mid-wave, and the play button showing.
- **Unfurling**: A link just sent: the domain is known at once, the picture shimmers and the title is a bar until the preview arrives.
- **Another site**: A link to a page the thread has no picture for: a shaded ball with the site’s letter, its highlight circling.
- **Typing**: Words in the field: the voice level turns into a round Send button.
- **Words**: What isn’t a link is sent as a blue bubble, with the same tail.
- **Dark**: With `colorScheme="dark"`: the chat turns near-black and the caption a dark grey; the video stays black.

## How it works

- The video is drawn, not played: the fox is painted in greys on a hidden canvas the size of the card, then redrawn on the visible one as white horizontal stripes 5.75 units apart, each as thick as the picture is light there, up to 64% of the spacing. Shading turns into thinner lines, and the eyes, nose and open mouth into gaps.
- A stripe starts where the picture passes about a quarter of full light, its edge smoothed over three samples, and each end is a half circle as tall as the stripe there, so the lines taper and round off like ink.
- The loop is timed on a 4.2 s reference: the fox leans in by 7 units in 0.25 s, opens its mouth by 0.6 s, swings an arm out from 1.05 to 1.5 s with a small overshoot, waves it until 3.2 s, blinks, and leans back out from 3.9 s, so the end meets the start.
- The canvas only draws while the card plays, is on screen (an IntersectionObserver) and the tab is visible; paused, it holds its frame and picks the loop up where it stopped. Under reduced motion it starts paused on a still frame, mid-wave.
- The card is 350 × 226 px, corners 18: the 1.91 : 1 video over a 43 px caption (title 15 px semibold, domain 13 px), with a tail curling out of its lower right corner. Hovering lifts it 2 px in 180 ms with a soft shadow; the caption is its button, stretched over the whole card.
- Sending a link adds its card at once, with the domain and a band of light crossing the black every 1.3 s; it unfurls 1.1 s later, the picture fading in over 350 ms. A link to the invite’s own site unfurls into the fox, any other into a shaded ball with the site’s letter cut out of it.
- While on screen and untouched, a demo pointer hovers the card, pauses and plays it, types a link, sends it and watches it unfurl, then clears the thread and starts over; any input from the reader stops it.
- Every colour is a token on the root, light-dark() where the two schemes differ: the chat follows the scheme, and the video stays black in both.

## API reference

- **app** (`string`, default `'Hollowfox'`): The app the invite is for: the card reads “Join <app> · Invite code: <code>”.
- **code** (`string`, default `'K7QD'`): The invite code on the card.
- **domain** (`string`, default `'invite.hollowfox.app'`): The invite’s domain, under the title. Links sent to this site unfurl into the fox.
- **onOpen** (`(href: string) => void`): Called with a card’s address when the reader opens it.
- **onSend** (`(text: string) => void`): Called with what the reader sends from the composer.
- **defaultPaused** (`boolean`, default `false`): Starts with the invite’s video paused on its still frame.
- **defaultDraft** (`string`, default `''`): Words already in the composer.
- **defaultSent** (`(string | { text: string; loading: true })[]`, default `[]`): Messages already sent after the invite: links become cards, other words bubbles; one with loading stays unfurling.
- **unfurlDelay** (`number`, default `1100`): How long a sent link shimmers before it unfurls, in ms.
- **autoplay** (`boolean`, default `true`): While on screen and untouched, a demo pointer plays with the card and sends a link; any input from the reader stops it.
- **colorScheme** (`'light' | 'dark' | 'system'`): Light or dark colours, or the reader’s; without it, the page’s color-scheme.
- **className** (`string`): A class for the thread’s frame.

## Accessibility

### Keyboard

- Tab reaches each card’s button (Enter or Space opens it), then its play button, then the composer’s buttons and field.
- Enter in the field sends; Send appears in the tab order only when there is something to send.
- Every control shows a focus ring; the card’s goes round the whole card.

### Screen readers

- The thread is a `log` named Messages, so new messages are read as they arrive.
- The card’s button is named by the title and the domain (“Join Hollowfox · Invite code: K7QD, invite.hollowfox.app”); while it loads, “Loading preview” and the domain.
- The play button says what it will do (“Pause preview”, “Play preview”), and a polite live region confirms it and “Opening …”. The canvas and the icons are hidden.

### Motion

The loop is under 5 s, can be paused at any time (WCAG 2.2.2), stops off screen, and starts paused under reduced motion. The shimmer and the lift are dropped too.

### Colour and contrast

The caption’s white title and grey domain are at least 6 : 1 on its dark grey in both schemes; the time and the receipt are over 4.5 : 1 on the chat’s background.

### In this build

- The thread is a log named Messages, so new messages are read as they arrive.
- Each card is a button named by its title and domain, with its hit area over the whole card and a focus ring round it; while it loads it says “Loading preview” and the domain.
- The play button on the video says what it will do (Pause preview, Play preview); a polite live region confirms it, and “Opening …” when a card is opened.
- The loop is under 5 s, can be paused at any time, stops off screen and starts paused under reduced motion, which also drops the shimmer, the lift and the rise of new messages.
- The composer’s buttons are named (Add the invite link, Add a wave, Send); Enter in the field sends. The canvas, the icons and the demo pointer are hidden from screen readers.

## Source

### link-unfurl/link-unfurl.tsx

```tsx
// Copyright (c) 2026 Bruno Delorence. MIT License.

'use client';

import { useEffect, useEffectEvent, useRef, useState, type FormEvent } from 'react';
import { DemoPointer, runDemo, type Point } from './demo-pointer';
import { Chevron, Pause, Play, Plus, Send, Smile, Tail, Voice } from './glyphs';
import { ScanlineVideo } from './scanline-video';
import type { Scene } from './scanline';
import { useAutoplay } from './use-autoplay';
import styles from './link-unfurl.module.css';

/*
 * Link unfurl: a message thread whose sent link has unfolded into a rich preview, a black video
 * card where a fox drawn in white scanlines peeks in from the right edge and waves, on a loop,
 * over a caption bar with the page's title and domain.
 *
 * - The card is one control: a button that opens the link, with its hit area stretched over the
 *   whole card. Hovering lifts it 2 px; its focus ring goes round the card. A play/pause button
 *   sits on the video, over that hit area.
 * - The video is drawn on a canvas (scanline.ts), so it plays only while it should: on screen,
 *   the tab visible, not paused. Under reduced motion it starts paused on a still frame, and the
 *   play button still plays it on request.
 * - Type a link in the composer and send it: a card appears at once with a shimmer where the
 *   picture will be, the domain already shown, and unfurls 1.1 s later. A link to the invite's
 *   own site unfurls into the fox; any other into its first letter with light sweeping across.
 *   Words that aren't a link are sent as a plain bubble.
 * - While on screen and untouched, a demo pointer hovers the card, pauses and plays it, types a
 *   link and sends it, then clears the thread and starts over. The reader's first input stops it.
 */

/** A message the thread starts with after the invite: a link or words; `loading` holds its card. */
export type Sent = string | { text: string; loading: true };

type Message =
  | {
      id: number;
      kind: 'link';
      href: string;
      host: string;
      title: string;
      scene: Scene;
      loading: boolean;
    }
  | { id: number; kind: 'text'; text: string };

const FOX: Scene = { kind: 'fox' };
/** What the demo types. */
const DEMO_LINK = 'lark.studio/notes';
/** The thread's clock: the invite was read at 11:00, anything sent here at 11:01. */
const READ_AT = '11:00 AM';
const NOW = '11:01 AM';

const LINK = /^(https?:\/\/)?((?:[a-z0-9-]+\.)+[a-z]{2,})(\/\S*)?$/i;
const capital = (word: string) => word.charAt(0).toUpperCase() + word.slice(1);

/** A link's parts, or null when the words aren't one. */
function parseLink(text: string) {
  const match = LINK.exec(text.trim());
  if (!match) return null;
  const host = match[2].toLowerCase().replace(/^www\./, '');
  const path = (match[3] ?? '').replace(/[?#].*$/, '').replace(/\/+$/, '');
  return { host, path, href: `${match[1] ? match[1].toLowerCase() : 'https://'}${host}${path}` };
}

export function LinkUnfurl({
  app = 'Hollowfox',
  code = 'K7QD',
  domain = 'invite.hollowfox.app',
  onOpen,
  onSend,
  defaultPaused = false,
  defaultDraft = '',
  defaultSent = [],
  unfurlDelay = 1100,
  autoplay = true,
  colorScheme,
  className = '',
}: {
  /** The app the invite is for: the card reads "Join <app> · Invite code: <code>". */
  app?: string;
  /** The invite code on the card. */
  code?: string;
  /** The invite's domain, under the title; links to it unfurl into the fox. */
  domain?: string;
  /** Called with a card's address when the reader opens it. */
  onOpen?: (href: string) => void;
  /** Called with what the reader sends from the composer. */
  onSend?: (text: string) => void;
  /** Starts with the invite's video paused on its still frame. */
  defaultPaused?: boolean;
  /** Words already in the composer, as a still for docs. */
  defaultDraft?: string;
  /** Messages already sent after the invite. */
  defaultSent?: Sent[];
  /** How long a sent link shimmers before it unfurls, in ms. */
  unfurlDelay?: number;
  /** While on screen and untouched, a demo pointer plays with the card and sends a link. */
  autoplay?: boolean;
  /** Light or dark colours, or the reader's ('system'); without it, the page's color-scheme. */
  colorScheme?: 'light' | 'dark' | 'system';
  className?: string;
}) {
  const { ref: root, playing: demoing, take } = useAutoplay<HTMLDivElement>();
  const invite = `https://${domain}/${code}`;
  const site = domain.split('.').slice(-2).join('.');

  /** A message for `text`, a card when it's a link. */
  const toMessage = (text: string, id: number, loading: boolean): Message => {
    const link = parseLink(text);
    if (!link) return { id, kind: 'text', text: text.trim() };
    const ours = link.host === site || link.host.endsWith(`.${site}`);
    const label = link.host.split('.')[0];
    const page = link.path.split('/').filter(Boolean).at(-1);
    return {
      id,
      kind: 'link',
      href: link.href,
      host: link.host,
      title: ours
        ? `Join ${app} · Invite code: ${code}`
        : page
          ? `${capital(page.replace(/[-_]+/g, ' '))} · ${capital(label)}`
          : capital(label),
      scene: ours ? FOX : { kind: 'letter', letter: label.charAt(0).toUpperCase() },
      loading,
    };
  };

  const first = (): Message[] => [
    toMessage(invite, 0, false),
    ...defaultSent.map((sent, index) =>
      typeof sent === 'string'
        ? toMessage(sent, index + 1, false)
        : toMessage(sent.text, index + 1, true),
    ),
  ];
  const [messages, setMessages] = useState<Message[]>(first);
  const [draft, setDraft] = useState(defaultDraft);
  const [receipt, setReceipt] = useState<{ read: boolean; at: string }>(() => ({
    read: true,
    at: defaultSent.length ? NOW : READ_AT,
  }));
  /** Each card's play state, once the reader (or the demo) has chosen one. */
  const [chosen, setChosen] = useState<Record<number, boolean>>({});
  /** Unknown (null) until read in the browser: nothing plays before then, so a reader who
   *  prefers reduced motion never sees the loop start. */
  const [reduced, setReduced] = useState<boolean | null>(null);
  const [opening, setOpening] = useState<number | null>(null);
  /** The card the demo pointer rests on, shown as hovered. */
  const [demoHover, setDemoHover] = useState<number | null>(null);
  const [message, setMessage] = useState('');

  const thread = useRef<HTMLDivElement>(null);
  const field = useRef<HTMLInputElement>(null);
  const pointer = useRef<HTMLSpanElement>(null);
  const nextId = useRef(defaultSent.length + 1);
  const timers = useRef(new Set<number>());
  const count = useRef(messages.length);

  const later = (ms: number, run: () => void) => {
    const timer = window.setTimeout(() => {
      timers.current.delete(timer);
      run();
    }, ms);
    timers.current.add(timer);
  };
  useEffect(() => {
    const pending = timers.current;
    return () => pending.forEach((timer) => window.clearTimeout(timer));
  }, []);

  useEffect(() => {
    const motion = window.matchMedia('(prefers-reduced-motion: reduce)');
    const read = () => setReduced(motion.matches);
    read();
    motion.addEventListener('change', read);
    return () => motion.removeEventListener('change', read);
  }, []);

  // The thread opens on its newest message, as a conversation does.
  useEffect(() => {
    const box = thread.current;
    if (box) box.scrollTop = box.scrollHeight;
  }, []);

  // A new message scrolls the thread to its end; clearing the thread goes back to the top.
  useEffect(() => {
    const box = thread.current;
    if (!box || messages.length === count.current) return;
    const grew = messages.length > count.current;
    count.current = messages.length;
    box.scrollTo({
      top: grew ? box.scrollHeight : 0,
      behavior: reduced === false ? 'smooth' : 'auto',
    });
  }, [messages.length, reduced]);

  /** Repeats are made to differ, so screen readers announce them again. */
  const announce = (text: string) => setMessage((now) => (now === text ? `${text} ` : text));

  const isPlaying = (id: number) =>
    chosen[id] ?? (reduced === false && !(id === 0 && defaultPaused));

  const toggle = (id: number) => {
    const next = !isPlaying(id);
    setChosen((now) => ({ ...now, [id]: next }));
    announce(next ? 'Preview playing' : 'Preview paused');
  };

  const open = (item: Extract<Message, { kind: 'link' }>) => {
    if (item.loading) return;
    onOpen?.(item.href);
    setOpening(item.id);
    announce(`Opening ${item.host}`);
    later(1400, () => setOpening((now) => (now === item.id ? null : now)));
  };

  const send = (text: string, from: 'reader' | 'demo') => {
    const words = text.trim();
    if (!words) return;
    const id = nextId.current++;
    const item = toMessage(words, id, true);
    setMessages((now) => [...now, item]);
    setDraft('');
    setReceipt({ read: false, at: NOW });
    if (from === 'reader') onSend?.(words);
    if (item.kind === 'link') {
      later(unfurlDelay, () =>
        setMessages((now) =>
          now.map((each) =>
            each.id === id && each.kind === 'link' ? { ...each, loading: false } : each,
          ),
        ),
      );
    }
    later(1500, () => setReceipt((now) => (now.at === NOW ? { read: true, at: NOW } : now)));
  };

  const onSubmit = (event: FormEvent) => {
    event.preventDefault();
    send(draft, 'reader');
  };

  // The demo: hover the card, pause and play it, type a link, send it; clear the thread, again.
  const demoAct = useEffectEvent(
    (
      act:
        | { hover: number | null }
        | { toggle: number }
        | { draft: string }
        | { send: true }
        | { reset: true }
        | { stop: true },
    ) => {
      if ('hover' in act) setDemoHover(act.hover);
      else if ('toggle' in act)
        setChosen((now) => ({ ...now, [act.toggle]: !isPlaying(act.toggle) }));
      else if ('draft' in act) setDraft(act.draft);
      else if ('send' in act) send(draft, 'demo');
      else if ('reset' in act) {
        setMessages((now) => now.filter((each) => each.id === 0));
        setReceipt({ read: true, at: READ_AT });
        setChosen({});
      } else {
        setDemoHover(null);
        // Leave the reader's own words alone; the demo's half-typed link goes.
        setDraft((now) => (DEMO_LINK.startsWith(now) ? '' : now));
        setChosen((now) => {
          const rest = { ...now };
          delete rest[0];
          return rest;
        });
      }
    },
  );
  const demo = autoplay && demoing;
  useEffect(() => {
    const stage = root.current;
    const arrow = pointer.current;
    if (!demo || !stage || !arrow) return;
    const stop = runDemo(stage, arrow, async ({ wait, glide, glyph }) => {
      /** The point at shares (fx, fy) of the first element matching `part`, in the stage's px. */
      const at = (part: string, fx = 0.5, fy = 0.5): Point => {
        const frame = stage.getBoundingClientRect();
        const scale = frame.width / stage.offsetWidth || 1;
        const rect = stage.querySelector(`[data-part="${part}"]`)?.getBoundingClientRect();
        if (!rect) return { x: stage.offsetWidth / 2, y: stage.offsetHeight / 2 };
        return {
          x: (rect.left + rect.width * fx - frame.left) / scale,
          y: (rect.top + rect.height * fy - frame.top) / scale,
        };
      };
      for (;;) {
        await wait(900);
        await glide(at('video', 0.42, 0.55), 900);
        glyph('hand');
        demoAct({ hover: 0 });
        await wait(1500);
        await glide(at('play'), 520);
        await wait(240);
        demoAct({ toggle: 0 });
        await wait(1100);
        demoAct({ toggle: 0 });
        await wait(500);
        demoAct({ hover: null });
        glyph('arrow');
        await glide(at('field', 0.3, 0.55), 820);
        await wait(300);
        for (let i = 1; i <= DEMO_LINK.length; i += 1) {
          demoAct({ draft: DEMO_LINK.slice(0, i) });
          await wait(i === 5 ? 180 : 62);
        }
        await wait(380);
        await glide(at('send'), 520);
        glyph('hand');
        await wait(200);
        demoAct({ send: true });
        await wait(300);
        glyph('arrow');
        await glide(at('thread', 0.3, 0.45), 900);
        await wait(3600);
        demoAct({ reset: true });
        await wait(600);
      }
    });
    return () => {
      stop();
      demoAct({ stop: true });
    };
  }, [demo, root]);

  const last = messages.at(-1)?.id;

  return (
    <div
      ref={root}
      className={`${styles.root} ${className}`}
      data-part="stage"
      data-color-scheme={colorScheme}
      onPointerDownCapture={take}
      onKeyDownCapture={take}
      onPointerMove={(event) => {
        if (event.pointerType !== 'touch') take();
      }}
    >
      <div
        ref={thread}
        className={styles.thread}
        data-part="thread"
        role="log"
        aria-label="Messages"
      >
        <p className={styles.time} data-part="time">
          <strong>Today</strong> {READ_AT}
        </p>
        {messages.map((item) => (
          <div
            key={item.id}
            className={styles.message}
            data-kind={item.kind}
            data-last={item.id === last}
          >
            {item.kind === 'link' ? (
              <div
                className={styles.card}
                data-part="card"
                data-loading={item.loading}
                data-paused={!isPlaying(item.id)}
                data-hover={demoHover === item.id}
              >
                <div className={styles.bubble}>
                  <div className={styles.video} data-part="video">
                    <span className={styles.shimmer} aria-hidden="true" />
                    {!item.loading && (
                      <ScanlineVideo
                        scene={item.scene}
                        playing={isPlaying(item.id)}
                        className={styles.canvas}
                      />
                    )}
                  </div>
                  <button
                    type="button"
                    className={styles.open}
                    data-part="caption"
                    aria-label={
                      item.loading ? `Loading preview, ${item.host}` : `${item.title}, ${item.host}`
                    }
                    aria-disabled={item.loading || undefined}
                    onClick={() => open(item)}
                  >
                    <span className={styles.title}>
                      {item.loading ? <span className={styles.skeleton} /> : item.title}
                    </span>
                    <span className={styles.domain}>
                      {opening === item.id ? 'Opening…' : item.host}
                    </span>
                    <Chevron className={styles.chevron} />
                  </button>
                  {!item.loading && (
                    <button
                      type="button"
                      className={styles.play}
                      data-part="play"
                      aria-label={isPlaying(item.id) ? 'Pause preview' : 'Play preview'}
                      onClick={() => toggle(item.id)}
                    >
                      {isPlaying(item.id) ? (
                        <Pause className={styles.playGlyph} />
                      ) : (
                        <Play className={styles.playGlyph} />
                      )}
                    </button>
                  )}
                </div>
                <Tail className={styles.tail} />
              </div>
            ) : (
              <div className={styles.text} data-part="text">
                {item.text}
                <Tail className={styles.tail} />
              </div>
            )}
            {item.id === last && (
              <p className={styles.receipt} data-part="receipt">
                {receipt.read ? (
                  <>
                    <strong>Read</strong> {receipt.at}
                  </>
                ) : (
                  <strong>Delivered</strong>
                )}
              </p>
            )}
          </div>
        ))}
      </div>

      <form className={styles.composer} data-part="composer" onSubmit={onSubmit}>
        <button
          type="button"
          className={styles.round}
          data-part="add"
          aria-label="Add the invite link"
          onClick={() => {
            setDraft(invite);
            field.current?.focus();
          }}
        >
          <Plus className={styles.glyph} />
        </button>
        <div className={styles.field} data-part="field">
          <input
            ref={field}
            className={styles.input}
            type="text"
            inputMode="url"
            enterKeyHint="send"
            autoComplete="off"
            spellCheck={false}
            placeholder="Message"
            aria-label="Message"
            value={draft}
            onChange={(event) => setDraft(event.target.value)}
          />
          {draft.trim() ? (
            <button type="submit" className={styles.send} data-part="send" aria-label="Send">
              <Send className={styles.sendGlyph} />
            </button>
          ) : (
            <Voice className={styles.voice} />
          )}
        </div>
        <button
          type="button"
          className={styles.round}
          data-part="emoji"
          aria-label="Add a wave"
          onClick={() => {
            setDraft((now) => `${now}${now && !now.endsWith(' ') ? ' ' : ''}👋`);
            field.current?.focus();
          }}
        >
          <Smile className={styles.glyph} />
        </button>
      </form>

      <p className={styles.hidden} aria-live="polite">
        {message}
      </p>
      <div className={styles.pointerLayer} aria-hidden="true">
        <DemoPointer
          ref={pointer}
          className={styles.pointer}
          arrowClass={styles.arrow}
          handClass={styles.hand}
        />
      </div>
    </div>
  );
}
```

### link-unfurl/link-unfurl.module.css

```css
/* Link unfurl (link-unfurl.tsx): a message thread, a sent link unfolded into a rich preview, and
   the composer under it.

   Sizes are the reference's, in css px: the card is 350 wide (or the thread's width, less its
   gutters, when narrower), its video 350 × 183 (1.91 : 1, a link preview's image) over a 43 px
   caption bar, corners 18. The caption's title is 15 px semibold, the domain 13 px; the time
   and the receipt 11 px. The composer's round buttons and its field are 32 px tall.

   Colours are the tokens below, light-dark(light, dark) where the two differ: the chat follows
   the color-scheme it inherits from the page, or the one its colorScheme prop sets. The video is
   black in both, as a video is. */

.root {
  --chat: #fafafa;
  --ink: #1c1c1e;
  --muted: #6c6c70;
  --edge: #e3e3e6;
  --field: #f6f6f7;
  --button: #fff;
  --caption: #1e1e1e;
  --caption-ink: #f3f3f3;
  --caption-muted: #a3a3a8;
  --skeleton: #3b3b3e;
  --lift: rgb(0 0 0 / 0.16);
  --sent: #1f74e8;
  --sent-ink: #fff;
  --focus: #2f7cf6;
  --pointer: #1c1c1e;
  --pointer-edge: #fff;
  --pointer-shadow: rgb(0 0 0 / 0.25);

  position: relative;
  display: flex;
  flex-direction: column;
  width: 100%;
  overflow: hidden;
  container-type: inline-size;
  border-radius: 16px;
  background: var(--chat);
  box-shadow: inset 0 0 0 1px var(--edge);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Inter, Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
@supports (color: light-dark(#fff, #000)) {
  .root {
    --chat: light-dark(#fafafa, #1c1c1e);
    --ink: light-dark(#1c1c1e, #f2f2f7);
    --muted: light-dark(#6c6c70, #9a9aa1);
    --edge: light-dark(#e3e3e6, #38383b);
    --field: light-dark(#f6f6f7, #242426);
    --button: light-dark(#fff, #2c2c2e);
    --caption: light-dark(#1e1e1e, #2a2a2c);
    --caption-muted: light-dark(#a3a3a8, #a8a8ae);
    --skeleton: light-dark(#3b3b3e, #464649);
    --lift: light-dark(rgb(0 0 0 / 0.16), rgb(0 0 0 / 0.5));
    --sent: light-dark(#1f74e8, #2b7ff0);
    --focus: light-dark(#2f7cf6, #5b9bff);
    --pointer: light-dark(#1c1c1e, #fff);
    --pointer-edge: light-dark(#fff, #1c1c1e);
  }
}
.root[data-color-scheme='light'] {
  color-scheme: light;
}
.root[data-color-scheme='dark'] {
  color-scheme: dark;
}
.root[data-color-scheme='system'] {
  color-scheme: light dark;
}

/* The thread: a fixed height, so sending doesn't push the page; it scrolls to the newest. */
.thread {
  display: flex;
  flex-direction: column;
  height: 312px;
  padding: 10px 16px 6px;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
}
.time {
  flex: none;
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 11px;
  line-height: 14px;
  text-align: center;
}
.time strong,
.receipt strong {
  font-weight: 600;
}

/* A sent message, on the right; the receipt under the newest one. */
.message {
  display: flex;
  flex: none;
  flex-direction: column;
  align-items: flex-end;
  margin-top: 4px;
  /* Room for the tail, which curls 6 px past the bubble. */
  padding-right: 6px;
}
.receipt {
  margin: 4px 10px 0 0;
  color: var(--muted);
  font-size: 11px;
  line-height: 14px;
}

/* The card. The wrapper lifts on hover and carries the tail with it. */
.card {
  position: relative;
  width: min(350px, 100cqi - 38px);
  transition: transform 0.18s cubic-bezier(0.3, 0.7, 0.4, 1);
}
.bubble {
  position: relative;
  overflow: hidden;
  border-radius: 18px;
  background: var(--caption);
  transition: box-shadow 0.18s ease;
}
@media (hover: hover) {
  .card:not([data-loading='true']):hover {
    transform: translateY(-2px);
  }
  .card:not([data-loading='true']):hover .bubble {
    box-shadow: 0 8px 20px -6px var(--lift);
  }
}
.card[data-hover='true'] {
  transform: translateY(-2px);
}
.card[data-hover='true'] .bubble {
  box-shadow: 0 8px 20px -6px var(--lift);
}
.card:not([data-loading='true']):has(.open:active) {
  transform: scale(0.985);
  transition-duration: 0.08s;
}
.card:has(.open:focus-visible) .bubble {
  outline: 2px solid var(--focus);
  outline-offset: 3px;
}

/* The video: black, 1.91 : 1; a shimmer under it until the card unfurls. */
.video {
  position: relative;
  aspect-ratio: 350 / 183;
  background: #000;
}
.canvas {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  animation: unfurl 0.35s ease-out;
}
@keyframes unfurl {
  from {
    opacity: 0;
  }
}
.shimmer {
  position: absolute;
  inset: 0;
  background: linear-gradient(100deg, #0c0c0c 35%, #232325 50%, #0c0c0c 65%) 0 0 / 250% 100%;
  opacity: 0;
  transition: opacity 0.3s ease;
}
.card[data-loading='true'] .shimmer {
  opacity: 1;
  animation: shimmer 1.3s linear infinite;
}
@keyframes shimmer {
  from {
    background-position: 100% 0;
  }
  to {
    background-position: -50% 0;
  }
}

/* The caption is the card's button: its hit area stretches over the whole card. */
.open {
  position: static;
  display: block;
  width: 100%;
  margin: 0;
  padding: 4px 36px 5px 10px;
  border: 0;
  background: none;
  color: var(--caption-ink);
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.open::after {
  content: '';
  position: absolute;
  inset: 0;
}
.open:focus-visible {
  outline: none;
}
.open[aria-disabled='true'] {
  cursor: progress;
}
/* The title takes two lines at most (one at 350 px for a title of the right length). */
.title {
  display: -webkit-box;
  min-height: 18px;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  font-size: 15px;
  font-weight: 600;
  line-height: 18px;
  letter-spacing: -0.01em;
}
.domain {
  display: block;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  color: var(--caption-muted);
  font-size: 13px;
  line-height: 16px;
}
.skeleton {
  display: block;
  width: 62%;
  height: 10px;
  margin-top: 4px;
  border-radius: 5px;
  background: var(--skeleton);
}
.chevron {
  position: absolute;
  right: 11px;
  bottom: 13px;
  width: 16px;
  height: 16px;
  color: var(--caption-muted);
  transition: transform 0.18s ease;
}
.card:hover .chevron,
.card[data-hover='true'] .chevron {
  transform: translateX(2px);
}

/* Play and pause, on the video above the card's hit area: shown on hover, on focus, while
   paused, and always where nothing hovers. */
.play {
  position: absolute;
  z-index: 1;
  top: 8px;
  left: 8px;
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: rgb(255 255 255 / 0.16);
  color: #fff;
  opacity: 0;
  cursor: pointer;
  transition:
    opacity 0.2s ease,
    background-color 0.15s ease;
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}
.play:hover {
  background: rgb(255 255 255 / 0.26);
}
.card:hover .play,
.card[data-hover='true'] .play,
.card[data-paused='true'] .play,
.play:focus-visible {
  opacity: 1;
}
@media (hover: none) {
  .play {
    opacity: 1;
  }
}
.play:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 2px;
}
.playGlyph {
  width: 14px;
  height: 14px;
}

/* The tail, in the bubble's own colour, curling out of its lower right corner. */
.tail {
  position: absolute;
  right: -6px;
  bottom: 0;
  width: 22px;
  height: 20px;
  fill: var(--caption);
  pointer-events: none;
}
/* Only the last message of the run has a tail, as in a conversation. */
.message[data-last='false'] .tail {
  display: none;
}

/* Words sent as words: a blue bubble with the same tail. */
.text {
  position: relative;
  max-width: min(75%, 320px);
  padding: 7px 12px 8px;
  border-radius: 18px;
  background: var(--sent);
  color: var(--sent-ink);
  font-size: 15px;
  line-height: 20px;
  overflow-wrap: anywhere;
}
.text .tail {
  fill: var(--sent);
}

/* The composer: add, the field (voice, or send once there's something to send), emoji. */
.composer {
  display: flex;
  flex: none;
  gap: 9px;
  align-items: center;
  padding: 8px 10px 12px;
}
.round {
  display: grid;
  flex: none;
  place-items: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--button);
  box-shadow:
    inset 0 0 0 1px var(--edge),
    0 1px 2px rgb(0 0 0 / 0.05);
  color: var(--ink);
  cursor: pointer;
}
.round:hover {
  background: var(--field);
}
.round:focus-visible,
.send:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}
.glyph {
  width: 20px;
  height: 20px;
}
.field {
  display: flex;
  flex: 1;
  align-items: center;
  min-width: 0;
  height: 32px;
  padding: 0 3px 0 12px;
  border-radius: 16px;
  background: var(--field);
  box-shadow: inset 0 0 0 1px var(--edge);
}
.field:has(.input:focus-visible) {
  outline: 2px solid var(--focus);
  outline-offset: 1px;
}
.input {
  flex: 1;
  min-width: 0;
  height: 100%;
  padding: 0;
  border: 0;
  background: none;
  color: var(--ink);
  font: inherit;
  font-size: 15px;
  caret-color: var(--focus);
}
.input::placeholder {
  color: var(--muted);
  opacity: 1;
}
.input:focus {
  outline: none;
}
.voice {
  flex: none;
  width: 18px;
  height: 18px;
  margin-right: 6px;
  color: var(--muted);
}
.send {
  display: grid;
  flex: none;
  place-items: center;
  width: 26px;
  height: 26px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--sent);
  color: #fff;
  cursor: pointer;
  animation: pop 0.2s cubic-bezier(0.3, 1.4, 0.5, 1);
}
@keyframes pop {
  from {
    transform: scale(0.4);
    opacity: 0;
  }
}
.sendGlyph {
  width: 16px;
  height: 16px;
}

/* A new message rises into place. */
.message:not(:first-of-type) {
  animation: rise 0.3s cubic-bezier(0.2, 0.8, 0.3, 1);
}
@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.97);
  }
}

/* The demo pointer, over everything; one of its glyphs shows at a time. */
.pointerLayer {
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
}
.pointer {
  width: 22px;
  height: 22px;
}
.hand {
  visibility: hidden;
}
.pointer[data-glyph='hand'] .arrow {
  visibility: hidden;
}
.pointer[data-glyph='hand'] .hand {
  visibility: visible;
}

.hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

@media (prefers-reduced-motion: reduce) {
  .card,
  .chevron {
    transition: none;
  }
  .card[data-hover='true'],
  .card:not([data-loading='true']):hover,
  .card:not([data-loading='true']):has(.open:active) {
    transform: none;
  }
  .card[data-loading='true'] .shimmer,
  .canvas,
  .send,
  .message:not(:first-of-type) {
    animation: none;
  }
}
```

### link-unfurl/scanline.ts

```tsx
// Copyright (c) 2026 Bruno Delorence. MIT License.

/*
 * The preview's "video": a picture drawn in greys on a hidden canvas, then redrawn on the visible
 * one as white horizontal stripes on black, like a 1-bit engraving. Each stripe runs along one
 * row of the grey picture; how thick it is at each point is how light the picture is there, so
 * shading turns into thinner lines and the darkest parts (eyes, nose, the mouth) into gaps.
 *
 * - The design space is the reference's card: 350 × 183 units (the 1.91 : 1 of a link preview's
 *   image), scaled to the canvas's width. Stripes are 5.75 units apart and at most 64% of that
 *   thick, as measured on the reference.
 * - A stripe starts where the picture is lighter than about a quarter, and each end is a half
 *   circle as tall as the stripe there, so the lines taper and round off like ink.
 * - Two scenes: the fox, peeking in from the right edge and waving on a 4.2 s loop, and a shaded
 *   ball with a letter cut out of it, for links the thread knows nothing about.
 */

export type Scene = { kind: 'fox' } | { kind: 'letter'; letter: string };

/** One loop of the scene, in ms (the reference clip is 4.2 s). */
export const LOOP = 4200;
/** Where a still frame stands in the loop, in s: the arm up, mid-wave, the mouth open. */
export const STILL = 2.05;

/** The design space, in units. */
const W = 350;
const H = 183;
/** Stripe spacing, and the share of it a stripe fills at full light. */
const PITCH = 5.75;
const FILL = 0.64;
/** Below this share of full thickness, there is no stripe. */
const CUT = 0.26;

const clamp = (v: number, lo = 0, hi = 1) => Math.min(hi, Math.max(lo, v));
const lerp = (a: number, b: number, t: number) => a + (b - a) * t;
/** 0 to 1 across [from, to]. */
const span = (t: number, from: number, to: number) => clamp((t - from) / (to - from));
const easeOut = (t: number) => 1 - (1 - t) ** 3;
const easeInOut = (t: number) => (t < 0.5 ? 4 * t * t * t : 1 - (-2 * t + 2) ** 3 / 2);
/** Out with a small overshoot, for the arm swinging up. */
const easeOutBack = (t: number) => 1 + 2.2 * (t - 1) ** 3 + 1.2 * (t - 1) ** 2;
const grey = (l: number) => {
  const v = Math.round(clamp(l) * 255);
  return `rgb(${v} ${v} ${v})`;
};
const rad = (deg: number) => (deg * Math.PI) / 180;

type Pose = {
  /** How far the fox has drawn back to the right, in units. */
  peek: number;
  /** Up and down, in units. */
  bob: number;
  /** 0 closed to 1 open. */
  mouth: number;
  /** 0 hanging out of frame to 1 raised. */
  arm: number;
  /** The forearm's swing, -1 to 1. */
  wave: number;
  /** 0 open to 1 shut. */
  blink: number;
};

/*
 * The loop, in s, timed on the reference: it leans in during the first 0.25 s, opens its mouth by
 * 0.6 s, swings an arm up from 1.05 to 1.5 s and waves it until 3.2 s, then lowers it, blinks
 * and closes its mouth, and leans back out from 3.9 s, so the end meets the start.
 */
function pose(t: number): Pose {
  const leanIn = easeOut(span(t, 0, 0.25));
  const leanOut = easeInOut(span(t, 3.9, 4.2));
  const up = easeOutBack(span(t, 1.05, 1.5));
  const down = easeInOut(span(t, 3.2, 3.55));
  const waving = span(t, 1.4, 1.6) * (1 - span(t, 3.05, 3.25));
  const blinkAt = (at: number) => 1 - clamp(Math.abs(t - at) / 0.07);
  return {
    peek: 7 * (1 - leanIn) + 7 * leanOut,
    bob: Math.sin((t / 2.1) * Math.PI * 2) * 1.3,
    mouth: easeOut(span(t, 0.25, 0.6)) * (1 - easeInOut(span(t, 3.45, 3.75))),
    arm: up * (1 - down),
    wave: Math.sin(((t - 1.5) / 0.57) * Math.PI * 2) * waving,
    blink: Math.max(blinkAt(0.95), blinkAt(3.62)),
  };
}

/** The fox, in greys, with its right side cut off by the frame. */
function drawFox(ctx: CanvasRenderingContext2D, p: Pose) {
  const x0 = p.peek;
  const y0 = p.bob;
  // Drawn at 1.28 times its units, from the frame's lower right corner, so the head fills the
  // right quarter of the card as on the reference and the ear tips touch the top edge.
  ctx.save();
  ctx.translate(W, H);
  ctx.scale(1.28, 1.28);
  ctx.translate(-W - 7, -H + 36);

  // The body: shoulders down to the bottom edge, darker toward its left side, a white bib.
  ctx.save();
  ctx.translate(x0, y0 * 0.4);
  const body = new Path2D();
  body.moveTo(302, 92);
  body.quadraticCurveTo(270, 118, 264, 190);
  body.lineTo(352, 190);
  body.lineTo(352, 88);
  body.closePath();
  const side = ctx.createLinearGradient(264, 0, 350, 0);
  side.addColorStop(0, grey(0.62));
  side.addColorStop(1, grey(0.94));
  ctx.fillStyle = side;
  ctx.fill(body);
  ctx.save();
  ctx.clip(body);
  ctx.fillStyle = grey(1);
  ctx.beginPath();
  ctx.ellipse(322, 146, 21, 36, 0, 0, Math.PI * 2);
  ctx.fill();
  ctx.restore();
  ctx.restore();

  // The arm: from the shoulder, the upper arm swings from hanging to level, the forearm rises
  // and waves; out of frame below while it hangs.
  const a = p.arm;
  const shoulder = { x: 296 + x0, y: 128 + y0 + (1 - clamp(a)) * 74 };
  const upper = rad(lerp(98, 188, a));
  const fore = upper + rad(a * (20 + p.wave * 20));
  const elbow = {
    x: shoulder.x + Math.cos(upper) * 33,
    y: shoulder.y + Math.sin(upper) * 33,
  };
  const paw = { x: elbow.x + Math.cos(fore) * 31, y: elbow.y + Math.sin(fore) * 31 };
  const wrist = { x: lerp(elbow.x, paw.x, 0.45), y: lerp(elbow.y, paw.y, 0.45) };
  ctx.lineCap = 'round';
  ctx.lineJoin = 'round';
  ctx.lineWidth = 17;
  // A dark outline first, so the arm stays apart from the body it crosses.
  ctx.lineWidth = 21;
  ctx.strokeStyle = grey(0);
  ctx.beginPath();
  ctx.moveTo(shoulder.x, shoulder.y);
  ctx.lineTo(elbow.x, elbow.y);
  ctx.lineTo(paw.x, paw.y);
  ctx.stroke();
  ctx.lineWidth = 17;
  ctx.strokeStyle = grey(0.86);
  ctx.beginPath();
  ctx.moveTo(shoulder.x, shoulder.y);
  ctx.lineTo(elbow.x, elbow.y);
  ctx.lineTo(wrist.x, wrist.y);
  ctx.stroke();
  // A dark sock, so the paw reads as thinner lines against the lighter arm.
  ctx.strokeStyle = grey(0.44);
  ctx.beginPath();
  ctx.moveTo(wrist.x, wrist.y);
  ctx.lineTo(paw.x, paw.y);
  ctx.stroke();
  ctx.fillStyle = grey(0.5);
  ctx.beginPath();
  ctx.arc(paw.x, paw.y, 10.5, 0, Math.PI * 2);
  ctx.fill();
  // Three toes, as gaps across the end of the paw.
  ctx.strokeStyle = grey(0);
  ctx.lineWidth = 1.6;
  for (const k of [-1, 0, 1]) {
    const angle = fore + k * 0.55;
    ctx.beginPath();
    ctx.moveTo(paw.x + Math.cos(angle) * 5, paw.y + Math.sin(angle) * 5);
    ctx.lineTo(paw.x + Math.cos(angle) * 11, paw.y + Math.sin(angle) * 11);
    ctx.stroke();
  }

  // The head, facing out, its right ear past the frame.
  ctx.save();
  ctx.translate(318 + x0, 66 + y0);
  ctx.rotate(-0.05 * clamp(a));
  const head = new Path2D();
  head.moveTo(-26, -26);
  head.lineTo(-41, -60);
  head.quadraticCurveTo(-24, -45, -8, -34);
  head.quadraticCurveTo(4, -37, 14, -34);
  head.quadraticCurveTo(27, -47, 37, -62);
  head.quadraticCurveTo(45, -34, 42, -14);
  head.quadraticCurveTo(48, 12, 36, 28);
  head.quadraticCurveTo(18, 40, 0, 40);
  head.quadraticCurveTo(-22, 38, -36, 30);
  head.lineTo(-57, 30);
  head.quadraticCurveTo(-46, 22, -44, 10);
  head.quadraticCurveTo(-46, -12, -26, -26);
  head.closePath();
  const light = ctx.createRadialGradient(-16, -18, 4, -6, -6, 66);
  light.addColorStop(0, grey(0.97));
  light.addColorStop(1, grey(0.64));
  ctx.fillStyle = light;
  ctx.fill(head);
  ctx.strokeStyle = grey(0);
  ctx.lineWidth = 2.6;
  ctx.stroke(head);

  ctx.fillStyle = grey(0.2);
  ctx.beginPath();
  ctx.moveTo(-35, -50);
  ctx.lineTo(-26, -31);
  ctx.lineTo(-13, -34);
  ctx.closePath();
  ctx.moveTo(31, -53);
  ctx.lineTo(20, -34);
  ctx.lineTo(35, -27);
  ctx.closePath();
  ctx.fill();

  // The white muzzle and cheeks.
  ctx.save();
  ctx.clip(head);
  ctx.fillStyle = grey(1);
  ctx.beginPath();
  ctx.moveTo(-58, 30);
  ctx.quadraticCurveTo(-32, 6, -14, 12);
  ctx.quadraticCurveTo(0, 20, 14, 12);
  ctx.quadraticCurveTo(32, 6, 44, 24);
  ctx.quadraticCurveTo(22, 46, 0, 46);
  ctx.quadraticCurveTo(-30, 44, -58, 30);
  ctx.fill();
  ctx.restore();

  // Eyes, with a highlight while open.
  const lid = 1 - p.blink * 0.88;
  for (const ex of [-18, 16]) {
    ctx.fillStyle = grey(0);
    ctx.beginPath();
    ctx.ellipse(ex, -4, 7.5, 8.5 * lid, 0, 0, Math.PI * 2);
    ctx.fill();
    if (p.blink < 0.5) {
      ctx.fillStyle = grey(1);
      ctx.beginPath();
      ctx.arc(ex + 2.2, -7, 2.3, 0, Math.PI * 2);
      ctx.fill();
    }
  }

  // Nose, and the mouth: a small line closed, an open smile with a tongue.
  ctx.fillStyle = grey(0);
  ctx.beginPath();
  ctx.moveTo(-8, 11);
  ctx.quadraticCurveTo(-1, 7.5, 6, 11);
  ctx.quadraticCurveTo(4, 18.5, -1, 20);
  ctx.quadraticCurveTo(-6, 18.5, -8, 11);
  ctx.fill();
  ctx.strokeStyle = grey(0);
  ctx.lineWidth = 2.2;
  ctx.beginPath();
  ctx.moveTo(-1, 19);
  ctx.lineTo(-1, 23);
  ctx.moveTo(-10, 25);
  ctx.quadraticCurveTo(-5, 28, -1, 23);
  ctx.quadraticCurveTo(3, 28, 8, 25);
  ctx.stroke();
  if (p.mouth > 0.02) {
    const m = p.mouth;
    ctx.fillStyle = grey(0);
    ctx.beginPath();
    ctx.ellipse(-1, 26 + m * 2, 3 + m * 6, m * 7, 0, 0, Math.PI * 2);
    ctx.fill();
    ctx.fillStyle = grey(0.58);
    ctx.beginPath();
    ctx.ellipse(-1, 29 + m * 2.4, m * 4, m * 3, 0, 0, Math.PI * 2);
    ctx.fill();
  }
  ctx.restore();
  ctx.restore();
}

/**
 * A shaded ball with the site's letter cut out of it, its highlight circling once a loop: an
 * engraved badge for a link whose own picture the thread doesn't have.
 */
function drawLetter(ctx: CanvasRenderingContext2D, letter: string, t: number) {
  const turn = ((t * 1000) / LOOP) * Math.PI * 2;
  const cx = W / 2;
  const cy = H / 2;
  const r = 74;
  const lx = cx + Math.cos(turn) * 34;
  const ly = cy - 22 + Math.sin(turn) * 16;
  const ball = ctx.createRadialGradient(lx, ly, 6, cx, cy, r);
  ball.addColorStop(0, grey(1));
  ball.addColorStop(0.75, grey(0.62));
  ball.addColorStop(1, grey(0.4));
  ctx.fillStyle = ball;
  ctx.beginPath();
  ctx.arc(cx, cy, r, 0, Math.PI * 2);
  ctx.fill();
  ctx.fillStyle = grey(0);
  ctx.font = '800 96px -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif';
  ctx.textAlign = 'center';
  ctx.textBaseline = 'middle';
  ctx.fillText(letter, cx, cy + 5);
}

/** Draws scenes on `canvas` as stripes; size it with resize() first. */
export function createRenderer(canvas: HTMLCanvasElement) {
  const source = document.createElement('canvas');
  const art = source.getContext('2d', { willReadFrequently: true });
  const out = canvas.getContext('2d');
  let width = 0;
  let height = 0;
  let ratio = 1;
  let half = new Float32Array(0);

  return {
    /** The canvas's size in css px, and the device pixel ratio. */
    resize(w: number, h: number, dpr: number) {
      width = Math.max(1, Math.round(w));
      height = Math.max(1, Math.round(h));
      ratio = dpr;
      canvas.width = Math.round(width * dpr);
      canvas.height = Math.round(height * dpr);
      // The grey picture needs no more than one sample per css px.
      source.width = width;
      source.height = height;
      half = new Float32Array(width);
    },
    /** Draws `scene` at `t` s into its loop. */
    draw(scene: Scene, t: number) {
      if (!art || !out || width < 2) return;
      const s = width / W;
      art.setTransform(1, 0, 0, 1, 0, 0);
      art.fillStyle = '#000';
      art.fillRect(0, 0, width, height);
      art.setTransform(s, 0, 0, s, 0, 0);
      if (scene.kind === 'fox') drawFox(art, pose(t));
      else drawLetter(art, scene.letter, t);
      const data = art.getImageData(0, 0, width, height).data;

      out.setTransform(ratio, 0, 0, ratio, 0, 0);
      out.fillStyle = '#000';
      out.fillRect(0, 0, width, height);
      out.fillStyle = '#fff';
      out.beginPath();
      const pitch = PITCH * s;
      const most = (pitch * FILL) / 2;
      const least = most * CUT;
      for (let yc = pitch / 2; yc < height; yc += pitch) {
        const row = Math.min(height - 1, Math.round(yc)) * width;
        // Three samples across, for a smoother edge than the picture's own pixels.
        for (let x = 0; x < width; x += 1) {
          const l = data[(row + Math.max(0, x - 1)) * 4];
          const c = data[(row + x) * 4];
          const r = data[(row + Math.min(width - 1, x + 1)) * 4];
          half[x] = ((l + 2 * c + r) / 1020) * most;
        }
        let x = 0;
        while (x < width) {
          if (half[x] < least) {
            x += 1;
            continue;
          }
          const a = x;
          while (x < width && half[x] >= least) x += 1;
          const b = x - 1;
          const ax = a + 0.5;
          const bx = b + 0.5;
          out.moveTo(ax, yc - half[a]);
          for (let i = a + 1; i <= b; i += 1) out.lineTo(i + 0.5, yc - half[i]);
          out.arc(bx, yc, half[b], -Math.PI / 2, Math.PI / 2);
          for (let i = b - 1; i >= a; i -= 1) out.lineTo(i + 0.5, yc + half[i]);
          out.arc(ax, yc, half[a], Math.PI / 2, (Math.PI * 3) / 2);
          out.closePath();
        }
      }
      out.fill();
    },
  };
}
```

### link-unfurl/scanline-video.tsx

```tsx
// Copyright (c) 2026 Bruno Delorence. MIT License.

'use client';

import { useEffect, useRef } from 'react';
import { createRenderer, LOOP, STILL, type Scene } from './scanline';

/*
 * The preview's moving picture, drawn frame by frame on a canvas (scanline.ts). It only runs
 * while it should play, is on screen and the tab is visible; otherwise it holds its frame, and
 * picks up the loop where it stopped. Never playing at all (reduced motion, or paused from the
 * start), it shows the still frame: the fox mid-wave.
 */
export function ScanlineVideo({
  scene,
  playing,
  className,
}: {
  scene: Scene;
  playing: boolean;
  className?: string;
}) {
  const canvas = useRef<HTMLCanvasElement>(null);
  /** ms into the loop, kept across pauses. */
  const elapsed = useRef(STILL * 1000);
  const started = useRef(false);
  const renderer = useRef<ReturnType<typeof createRenderer> | null>(null);
  const sceneRef = useRef(scene);
  const visible = useRef(false);
  const kick = useRef<() => void>(() => {});

  useEffect(() => {
    sceneRef.current = scene;
    renderer.current?.draw(scene, elapsed.current / 1000);
  }, [scene]);

  // Size the canvas to its box (and redraw at once), and watch whether it's on screen.
  useEffect(() => {
    const element = canvas.current;
    if (!element) return;
    const draw = createRenderer(element);
    renderer.current = draw;
    const resize = new ResizeObserver(() => {
      const box = element.getBoundingClientRect();
      draw.resize(
        element.clientWidth || box.width,
        element.clientHeight || box.height,
        Math.min(window.devicePixelRatio || 1, 2),
      );
      draw.draw(sceneRef.current, elapsed.current / 1000);
    });
    resize.observe(element);
    const seen = new IntersectionObserver(([entry]) => {
      visible.current = entry.isIntersecting;
      kick.current();
    });
    seen.observe(element);
    const onVisibility = () => kick.current();
    document.addEventListener('visibilitychange', onVisibility);
    return () => {
      resize.disconnect();
      seen.disconnect();
      document.removeEventListener('visibilitychange', onVisibility);
      renderer.current = null;
    };
  }, []);

  // The loop itself.
  useEffect(() => {
    let frame = 0;
    let last = 0;
    const tick = (now: number) => {
      if (last) elapsed.current = (elapsed.current + now - last) % LOOP;
      last = now;
      renderer.current?.draw(sceneRef.current, elapsed.current / 1000);
      frame = requestAnimationFrame(tick);
    };
    const update = () => {
      const run = playing && visible.current && !document.hidden;
      if (run && !frame) {
        // The first time it plays, the loop starts from its beginning, not from the still.
        if (!started.current) {
          started.current = true;
          elapsed.current = 0;
        }
        last = 0;
        frame = requestAnimationFrame(tick);
      } else if (!run && frame) {
        cancelAnimationFrame(frame);
        frame = 0;
      }
    };
    kick.current = update;
    update();
    return () => {
      cancelAnimationFrame(frame);
      kick.current = () => {};
    };
  }, [playing]);

  return <canvas ref={canvas} className={className} aria-hidden="true" />;
}
```

### link-unfurl/glyphs.tsx

```tsx
// Copyright (c) 2026 Bruno Delorence. MIT License.

/*
 * The thread's icons, drawn on a 24-unit grid in currentColor, all hidden from screen readers:
 * the buttons that hold them carry the names.
 */

type GlyphProps = { className?: string };

const svg = {
  viewBox: '0 0 24 24',
  'aria-hidden': true,
  focusable: false,
} as const;

export function Plus({ className }: GlyphProps) {
  return (
    <svg {...svg} className={className}>
      <path d="M12 4.5v15M4.5 12h15" stroke="currentColor" strokeWidth="2" strokeLinecap="round" />
    </svg>
  );
}

/** Five bars of a voice level, as the composer shows while it's empty. */
export function Voice({ className }: GlyphProps) {
  return (
    <svg {...svg} className={className}>
      <path
        d="M4 10.5v3M8 7.5v9M12 4.5v15M16 7.5v9M20 10.5v3"
        stroke="currentColor"
        strokeWidth="1.8"
        strokeLinecap="round"
      />
    </svg>
  );
}

export function Smile({ className }: GlyphProps) {
  return (
    <svg {...svg} className={className}>
      <circle cx="12" cy="12" r="9" fill="none" stroke="currentColor" strokeWidth="1.8" />
      <circle cx="9" cy="10" r="1.3" fill="currentColor" />
      <circle cx="15" cy="10" r="1.3" fill="currentColor" />
      <path
        d="M7.6 13.6c1 2 2.6 3 4.4 3s3.4-1 4.4-3z"
        fill="currentColor"
        stroke="currentColor"
        strokeWidth="1.2"
        strokeLinejoin="round"
      />
    </svg>
  );
}

export function Chevron({ className }: GlyphProps) {
  return (
    <svg {...svg} className={className}>
      <path
        d="M9 5.5l6.5 6.5L9 18.5"
        fill="none"
        stroke="currentColor"
        strokeWidth="1.8"
        strokeLinecap="round"
        strokeLinejoin="round"
      />
    </svg>
  );
}

export function Play({ className }: GlyphProps) {
  return (
    <svg {...svg} className={className}>
      <path
        d="M8 5.8v12.4c0 .8.9 1.3 1.6.8l9.4-6.2c.6-.4.6-1.2 0-1.6L9.6 5c-.7-.5-1.6 0-1.6.8z"
        fill="currentColor"
      />
    </svg>
  );
}

export function Pause({ className }: GlyphProps) {
  return (
    <svg {...svg} className={className}>
      <rect x="6.5" y="5" width="4" height="14" rx="1.2" fill="currentColor" />
      <rect x="13.5" y="5" width="4" height="14" rx="1.2" fill="currentColor" />
    </svg>
  );
}

/** The send button's arrow, pointing up. */
export function Send({ className }: GlyphProps) {
  return (
    <svg {...svg} className={className}>
      <path
        d="M12 19V5.5M6 11l6-6 6 6"
        fill="none"
        stroke="currentColor"
        strokeWidth="2.4"
        strokeLinecap="round"
        strokeLinejoin="round"
      />
    </svg>
  );
}

/** The bubble's tail, curling out of its lower right corner. */
export function Tail({ className }: GlyphProps) {
  return (
    <svg viewBox="0 0 22 20" aria-hidden="true" focusable="false" className={className}>
      <path d="M0 0H16C16 9 17 15 22 19.5 17 20.5 12 19.2 8.5 17 6 18.7 3 20 0 20Z" />
    </svg>
  );
}
```

### link-unfurl/demo-pointer.tsx

```tsx
// Copyright (c) 2026 Bruno Delorence. MIT License.

'use client';

import type { CSSProperties, Ref } from 'react';

/*
 * The demo's pointer, and the steps that move it. A demo is a script of awaited steps: wait, or
 * glide the pointer somewhere. Stopping the demo (the reader takes over, or it scrolls away) ends
 * the step in progress at once: its promise rejects, which ends the script right there, and the
 * pointer fades out.
 *
 * Each glide is a curved flight played by the Web Animations API, so nothing runs frame by frame.
 * The points of the flight are handed to whoever wants to move along with it (nothing here uses
 * them yet). The arrow and the hand are HTML boxes
 * that swap by their visibility: a change of style inside an SVG would lay the SVG out again.
 */

export type Point = { x: number; y: number };

/** A glide's path and timing, for an animation that plays along with it. */
export type Flight = { points: Point[]; timing: KeyframeAnimationOptions };

export type Demo = {
  /** Resolves after `ms`. */
  wait: (ms: number) => Promise<void>;
  /** Glides the pointer to `to`, in the stage's own px, in `ms`; `along` gets the flight. */
  glide: (to: Point, ms: number, along?: (flight: Flight) => void) => Promise<void>;
  /** Shows the arrow, or the hand a link shows. */
  glyph: (name: 'arrow' | 'hand') => void;
};

/** What a stopped demo's pending step rejects with. */
class Stopped extends Error {}

/** Where the arrow's tip is, as shares of its box: the point the pointer stands on. */
const TIP: Point = { x: 0.15, y: 0.1 };

/** How many points a flight is drawn through. */
const SAMPLES = 24;

/** Plays `script` with the pointer over `stage`; returns the function that stops it. */
export function runDemo(
  stage: HTMLElement,
  pointer: HTMLElement,
  script: (demo: Demo) => Promise<void>,
): () => void {
  let alive = true;
  let flight: Animation | null = null;
  // The stylesheet sizes the pointer from the stage's width; its tip is where it stands.
  const tip = { x: pointer.offsetWidth * TIP.x, y: pointer.offsetHeight * TIP.y };
  const place = ({ x, y }: Point) => `translate(${x - tip.x}px, ${y - tip.y}px)`;
  const timers = new Set<number>();
  const pending = new Set<() => void>();
  // The pointer comes in from the lower right.
  let at: Point = { x: stage.offsetWidth * 0.8, y: stage.offsetHeight * 0.9 };

  /** Settles like `promise`, or rejects as soon as the demo stops. */
  const step = (promise: Promise<unknown>) =>
    new Promise<void>((resolve, reject) => {
      if (!alive) return reject(new Stopped());
      const cancel = () => reject(new Stopped());
      pending.add(cancel);
      promise.then(
        () => {
          pending.delete(cancel);
          if (alive) resolve();
        },
        () => {
          pending.delete(cancel);
          reject(new Stopped());
        },
      );
    });

  const wait = (ms: number) =>
    step(
      new Promise<void>((resolve) => {
        const timer = window.setTimeout(() => {
          timers.delete(timer);
          resolve();
        }, ms);
        timers.add(timer);
      }),
    );

  const glide: Demo['glide'] = (to, ms, along) => {
    const from = at;
    at = to;
    const dx = to.x - from.x;
    const dy = to.y - from.y;
    // A gentle curve, as a hand moves: the control point sits off the straight line.
    const bend = { x: (from.x + to.x) / 2 - dy * 0.18, y: (from.y + to.y) / 2 + dx * 0.18 };
    const points: Point[] = [];
    for (let i = 0; i <= SAMPLES; i += 1) {
      const t = i / SAMPLES;
      const u = 1 - t;
      points.push({
        x: u * u * from.x + 2 * u * t * bend.x + t * t * to.x,
        y: u * u * from.y + 2 * u * t * bend.y + t * t * to.y,
      });
    }
    const timing: KeyframeAnimationOptions = {
      duration: ms,
      easing: 'cubic-bezier(0.45, 0, 0.25, 1)',
    };
    flight?.cancel();
    // Where it rests once the flight is over.
    pointer.style.transform = place(to);
    flight = pointer.animate(
      points.map((point) => ({ transform: place(point) })),
      timing,
    );
    along?.({ points, timing });
    return step(flight.finished);
  };

  const glyph: Demo['glyph'] = (name) => {
    pointer.dataset.glyph = name;
  };

  pointer.dataset.glyph = 'arrow';
  pointer.style.transform = place(at);
  pointer.style.opacity = '1';
  script({ wait, glide, glyph }).catch((error: unknown) => {
    if (!(error instanceof Stopped)) throw error;
  });

  return () => {
    if (!alive) return;
    alive = false;
    timers.forEach((timer) => window.clearTimeout(timer));
    flight?.cancel();
    pending.forEach((cancel) => cancel());
    pointer.style.opacity = '0';
  };
}

/**
 * The pointer's box: it moves, on a layer of its own. Its size comes from its class, its colours
 * from the stage’s tokens (link-unfurl.module.css).
 */
const POINTER: CSSProperties = {
  position: 'absolute',
  top: 0,
  left: 0,
  zIndex: 2,
  display: 'block',
  pointerEvents: 'none',
  opacity: 0,
  transition: 'opacity 0.3s ease',
  filter: 'drop-shadow(0 1px 1.5px var(--pointer-shadow))',
  willChange: 'transform',
};

/** One glyph over the other, each filling the box. */
const GLYPH: CSSProperties = { position: 'absolute', inset: 0, display: 'block' };
const DRAWING: CSSProperties = {
  display: 'block',
  width: '100%',
  height: '100%',
  overflow: 'visible',
};
/** The arrow is dark on a white edge, the hand white on a dark one, as the system draws them. */
const ARROW: CSSProperties = { fill: 'var(--pointer)', stroke: 'var(--pointer-edge)' };
const HAND: CSSProperties = { fill: 'var(--pointer-edge)', stroke: 'var(--pointer)' };

/**
 * The pointer the demo moves around: an arrow, or a pointing hand over a control. It is
 * decorative: what it does shows on the control itself. The stylesheet shows one glyph at a time,
 * from the box's data-glyph.
 */
export function DemoPointer({
  ref,
  className,
  arrowClass,
  handClass,
}: {
  ref: Ref<HTMLSpanElement>;
  className?: string;
  arrowClass?: string;
  handClass?: string;
}) {
  return (
    <span ref={ref} className={className} style={POINTER} aria-hidden="true">
      <span className={arrowClass} style={GLYPH}>
        <svg viewBox="0 0 20 20" style={DRAWING}>
          <path
            d="M3 2v14.5l3.6-3.3 2.6 5.6 2.4-1.1-2.6-5.5h5.2z"
            style={ARROW}
            strokeWidth="1.3"
            strokeLinejoin="round"
          />
        </svg>
      </span>
      <span className={handClass} style={GLYPH}>
        <svg viewBox="0 0 20 20" style={DRAWING}>
          {/* The tip of the finger sits where the arrow's tip is. */}
          <path
            d="M6.4 3.3c0-.8.6-1.4 1.3-1.4S9 2.5 9 3.3v5.5c.2-.5.6-.8 1.2-.8.7 0 1.2.5 1.2 1.2v.5c.2-.5.6-.8 1.2-.8.7 0 1.2.5 1.2 1.2v.7c.2-.4.6-.7 1.1-.7.7 0 1.2.5 1.2 1.2v3.5c0 2.8-1.9 4.9-4.6 4.9h-1.2c-1.8 0-3.1-.8-4.1-2.3l-2.6-3.9c-.4-.6-.2-1.3.4-1.7.6-.3 1.3-.2 1.7.4l.6.9z"
            style={HAND}
            strokeWidth="1.1"
            strokeLinejoin="round"
            transform="translate(-4.7 0.1)"
          />
        </svg>
      </span>
    </span>
  );
}
```

### link-unfurl/use-autoplay.ts

```tsx
// Copyright (c) 2026 Bruno Delorence. MIT License.

'use client';

import { useCallback, useEffect, useRef, useState } from 'react';

/*
 * When a demo may play on its own: while part of it is on screen and the tab is visible, never
 * under reduced motion, and never again once the reader has used it: `take()` hands it to the
 * reader for good (until the component mounts again), so it can't come back on its own.
 */
export function useAutoplay<T extends HTMLElement>() {
  const ref = useRef<T>(null);
  const [visible, setVisible] = useState(false);
  const [reduced, setReduced] = useState(true);
  const [taken, setTaken] = useState(false);

  useEffect(() => {
    const element = ref.current;
    if (!element) return;
    let onScreen = false;
    const update = () => setVisible(onScreen && !document.hidden);
    const observer = new IntersectionObserver(
      ([entry]) => {
        onScreen = entry.isIntersecting;
        update();
      },
      { threshold: 0.3 },
    );
    observer.observe(element);
    document.addEventListener('visibilitychange', update);
    const motion = window.matchMedia('(prefers-reduced-motion: reduce)');
    const readMotion = () => setReduced(motion.matches);
    readMotion();
    motion.addEventListener('change', readMotion);
    return () => {
      observer.disconnect();
      document.removeEventListener('visibilitychange', update);
      motion.removeEventListener('change', readMotion);
    };
  }, []);

  const take = useCallback(() => setTaken(true), []);

  return { ref, take, playing: visible && !reduced && !taken };
}
```