Impeccable
Back

Halo Story

Pictures gather into a turning halo around your words, then open into two rows as you scroll. Use it on a launch or about page with 12 to 28 photos.

ScrollGalleryNo extra packagesLight + darkMobile
Jagged mountain peaks above a winding valley road
A wooden boat on a turquoise mountain lake
A sand dune glowing in warm evening light
  1. Every day, the web gets more screens,
  2. made faster than ever before.
  3. Pages pile up, one after another,
  4. but few of them feel alive.
  5. We make the parts that do.
  6. Let's make something for Humans once again.
npx shadcn@latest add https://impeccable-ui.com/r/halo-story.json
Scroll inside the box. Pictures join a halo around the words one by one, and it keeps turning clockwise as it fills. Keep going and the halo stretches into two rows, one above the words running right and one below running left, that fade to gray and leave, until three big pictures rise for the last line. Scroll back up to play it in reverse.

Run it in a project set up with shadcn. No other packages needed. Or open and copy the file into components/ui/halo-story.tsx.

Prompts

Paste one into Claude Code, Cursor or any AI coding tool. Install adds this exact story and asks only which page it goes on. Blend asks four short questions (the page, the pictures, the six lines and how long the story runs), then fits it to your product without changing how it moves.

# Halo Story

A 1-file React component from Impeccable. Add it to this project so it works and looks exactly like the source below, on the one page I choose, and change nothing else.

A short story told by scrolling, with pictures as the cast. One line of words sits in the middle of the screen while the pictures move around it in six scenes: pictures join a halo (a ring) around the first line one by one, always turning clockwise; the halo fills up, still turning; it stretches into two long rows, one above the words running right and one below running left, the same clockwise flow; the rows fade to gray and run off the sides; a quiet line on its own; then three big pictures rise from below in full color for the last line. Each line arrives word by word. The pictures follow the scroll softly, easing toward where you scrolled, so nothing ever snaps.

## Before you build: one question

Look through this project first: its pages with room for a story (landing page, about, a launch or case study page), where a full-screen moment would sit between existing sections, and the pictures it already has (product shots, team photos, work samples). Then ask me this in one message and wait for my answer:

- **Where should it go?** Suggest the 1–3 places in my code it fits best (the page, and between which two sections), and the 12 to 28 pictures you'd use from my project. If you found too few pictures, say so and I'll give you some.
  *Why: it is a whole-screen moment, so it needs a page people scroll through, and the pictures are what people will remember.*

Ask nothing else. If I say *skip*, use the best suggestion. Use the six lines from my project's own copy if they fit; otherwise use simple placeholder lines and tell me where to change them.

## Keep it as it is

The six scenes and their order, the soft follow, the halo that only ever turns clockwise, the conveyor of two rows (top runs right, bottom runs left) that fade to gray, the three big pictures rising for the finale, the word-by-word lines, the masked edges, and their timing and easing, are the design. Keep them exactly as in the source. If something doesn't fit my project, tell me instead of changing it.

- Add only the component file and place it once, in the spot I picked. Don't add packages, change other files, or restyle anything.
- Don't add the demo parts from the Impeccable website: the 28 demo photos and three finale photos, the six demo lines about Impeccable UI, the card around the preview and the home page's TV.
- Shrink every picture before use (about 420px on the long side for the ring, 760px for the three big ones, WebP if the project can), so the page stays fast.

## Fastest path

If this project has a `components.json` (shadcn), run `npx shadcn@latest add https://impeccable-ui.com/r/halo-story.json`.
If the command succeeds, only fix import paths to match this project and skip ahead. If it fails or there is no `components.json`, build it by hand as below.

## Build it

- Stack: React 18 or 19 with TypeScript. No other packages: one small loop reads the scroll and places every picture with transform and opacity only, and every word arrives with a CSS transition. Its styles sit in a `<style>` tag inside the file.
- JavaScript project? Name the file `halo-story.jsx` and remove the type annotations; nothing else changes.
- Create this file, in this project's usual place for components:
  - `components/ui/halo-story.tsx`
- Keep these exports and their names: `HaloStory`, `HaloStoryProps` and `HaloStoryImage`.
- Keep `"use client"` at the top in Next.js App Router projects. In other setups it is harmless.
- Keep the tuning values at the top exactly as written: `JOIN`, `JOIN_EACH`, `TURN_DEG`, `OPEN`, `OPEN_EACH`, `GRAY_AT`, `LEAVE`, `FINALE`, `LINE_AT`, `SOFTEN`, `SOFTEN_TOUCH`, `WORD_IN_MS`, `WORD_GAP_MS`, `WORD_WAIT_MS`, `WORD_OUT_MS`, `GRAY_IN_MS`, `GRAY_OUT_MS`, `FADE_MS`, `IN_EASE`, `OUT_EASE`, `SHAPES`, `GLIDE_DEG` and the `CSS` block. They are the design and its timing.
- Keep the fallbacks: with `prefers-reduced-motion: reduce` nothing travels: each scene fades in at its place in 0.22 seconds and the words only fade. The lines are also given to screen readers as a plain list; the moving words are hidden from them. Pictures can't be selected or dragged, and a picture that fails to load simply leaves its place.

## Use it

```tsx
"use client";
import { HaloStory } from "@/components/ui/halo-story";

const pictures = [
  { src: "/story/01.webp", alt: "Our first launch day" },
  { src: "/story/02.webp", alt: "The studio at night" },
  // ...12 to 28 pictures read best
];

export function Story() {
  return (
    <HaloStory
      images={pictures}
      lines={[
        "Every day, the web gets more screens,",
        "made faster than ever before.",
        "Pages pile up, one after another,",
        "but few of them feel alive.",
        "We make the parts that do.",
        "Let's make something for Humans once again.",
      ]}
    />
  );
}
```

- `images` are the pictures for the halo and the rows, each with a real `alt`. 12 to 28 read best; fewer are repeated to close the ring. Each is cropped to its card.
- `lines` has one line per scene, in order: the first pictures, the full halo, the rows, the gray rows, the quiet moment and the finale. Under 50 letters each reads best.
- `finale` is the three big pictures at the end (left, middle, right). Leave it out to use the first three images. Portrait pictures fit best.
- Leave out `height` on a page, so it pins to the screen while the page scrolls past it. Give it a `height` (like `600` or `"80vh"`) only to make it its own scroll box.
- `length` is how many screens of scroll the story takes (7). `radius` is the corner radius of the small pictures (10).
- It takes its colors from `--foreground` and `--background` (or `--fg` and `--bg`), so it follows light and dark mode.

## How the story works

Read this before you touch anything, so you know what the code does and why it must stay as it is.

1. **The stage.** A tall track (`length` screens of scroll, 7 by default) with a stage pinned to the screen inside it. Without `height` it pins to the browser window while the page scrolls past; with `height` it is its own scroll box. Scroll position becomes a number from 0 (start) to 1 (end), and every scene has its place on that line.
2. **Soft follow.** The pictures don't jump with each wheel step: the story eases toward where you scrolled (about 0.16 seconds behind on a wheel or trackpad, 0.07 on touch, which is already smooth). This is what keeps it from feeling jerky.
3. **One way only.** Every picture moves clockwise from the moment it appears until it leaves. Nothing ever turns back; this is the heart of the design.
4. **Halo (0.01 to 0.59).** Pictures join an oval ring around the words one at a time, spread evenly round it: a few at first, then more and more. Each grows in from small while gliding forward with the ring, with a long, soft landing. The ring turns clockwise the whole time, 150 degrees in all.
5. **Rows (0.43 to 0.78).** The ring stretches into one long loop, like a conveyor belt: the top half becomes a row above the words running right, the bottom half a row below running left, and the loop turns round off screen at both ends. Pictures at the top and bottom of the ring flatten in first, the ones at the sides follow, each heading further along the way it was already going. As the fourth line arrives (0.63) the rows fade to gray over 1.6 seconds (and back to color in 0.5 when you scroll up). Then they run off the sides the same way, quickly (0.71 to 0.78), fading at the edges with a mask, never a hard cut.
6. **Quiet, then finale (0.78 to 0.98).** A line on its own. Then three big pictures rise from below in full color: the middle one first, the side ones fanning out from behind it and turning toward you, while the words move up to make room. The bottom edge fades with a mask.
7. **Words.** Each scene has its line. A new line arrives word by word: each word rises, turns upright and comes into focus in 1.1 seconds, 55ms apart, after the old line has left in a quarter of a second. Arriving is slow and calm, leaving is quick.
8. **Sizes.** Card size, the ring, the rows and the finale are measured from the stage, so it works from a phone to a wide screen. On a phone there is nothing to hover; touch scrolling plays the same story.

## Check

- It type-checks and the page renders with no console errors.
- Scrolling down plays all six scenes in order: the halo filling up as it turns clockwise, the two rows (top runs right, bottom runs left), the gray rows running off, the quiet line, and the three big pictures. Scrolling up plays it back. Nothing jumps or snaps on a mouse wheel.
- Every line arrives word by word, and the old one leaves quickly first.
- Pictures leaving a side fade out; none is cut off with a hard edge.
- It looks right in light and dark mode (check both).
- It fits on a phone without scrolling sideways, the words stay inside the halo, and touch scrolling stays smooth.
- With `prefers-reduced-motion: reduce`, each scene only fades in at its place.
- Nothing else on the site looks or behaves differently.
- Finish with a short report: the files you added or changed, where it went, the pictures and lines you used, and every place where you had to do something differently from the source, and why.

## Source

The reference implementation. Copy it as-is, then apply only the changes listed above.

### `components/ui/halo-story.tsx`

```tsx
"use client";

/**
 * Halo Story, from Impeccable.
 *
 * A short story told by scrolling, with your pictures as the cast. One line of
 * words sits in the middle of the screen while the pictures move around it:
 *
 *   1. Pictures appear one by one on a ring (a halo) around the first line.
 *      The ring always turns clockwise, and more pictures join as you scroll.
 *   2. The halo fills up, still turning clockwise.
 *   3. It splits smoothly into two rows, one above the words and one below,
 *      that keep the same clockwise flow: the top row runs right, the bottom
 *      row runs left.
 *   4. The rows lose their color, then run off the sides the same way.
 *   5. A quiet moment: just the words.
 *   6. Three big pictures rise from below for the last line, back in full color.
 *
 * Each scene has its own line, and every line arrives word by word.
 *
 * The pictures follow your scroll, but softly: the story eases toward where
 * you scrolled instead of jumping with every wheel step, so nothing ever snaps.
 * Things arrive slowly with a long, soft landing and leave quickly. Pictures
 * moving off a side fade out with a mask, never a hard cut.
 *
 * Give it a height to make it its own scroll box, or leave the height out and
 * it pins to the screen while the page scrolls past it.
 *
 * Phones get the same story with touch scrolling; there is nothing to hover.
 * Reduced motion: no travel at all. Each scene fades in at its place and the
 * words simply fade.
 *
 * Colors come from your theme: the words from --foreground (else --fg), the
 * page from --background (else --bg), so it follows light and dark mode.
 * One file, React only, no packages.
 */

import { Fragment, useEffect, useMemo, useRef, useState, type CSSProperties, type SyntheticEvent } from "react";

export type HaloStoryImage = {
  /** The picture. It is cropped to fit its card. */
  src: string;
  /** Read by screen readers. */
  alt: string;
};

export type HaloStoryProps = {
  /** The pictures for the halo and the rows. 12 to 28 reads best; fewer are repeated to close the ring. */
  images: HaloStoryImage[];
  /** The three big pictures at the end, left, middle, right. Default: the first three images. */
  finale?: HaloStoryImage[];
  /**
   * One line per scene, in order: the first pictures, the full halo, the rows, the gray rows,
   * the quiet moment and the finale. Short lines (under 50 letters) read best.
   */
  lines?: string[];
  /** Makes it its own scroll box this tall: 600 (px) or any CSS length like "80vh". Leave out to pin to the screen while the page scrolls. */
  height?: number | string;
  /** How long the story is, in screens of scrolling. Default: 7. */
  length?: number;
  /** Corner radius of the small pictures, in px. The big ones get a little more. Default: 10. */
  radius?: number;
  /** Name of the story for screen readers. Default: "Picture story". */
  "aria-label"?: string;
  className?: string;
  style?: CSSProperties;
};

/* ---------- the design: keep as written ---------- */

// Where each scene sits on the scroll, from 0 (start) to 1 (end).
// Everything turns one way only: clockwise, from the first picture to the last row leaving.
const JOIN = [0.01, 0.4]; // pictures join the halo one by one: a few at first, then more and more
const JOIN_EACH = 0.075; // how long one picture takes to glide in (clockwise) and settle in its place
const TURN_DEG = 150; // how far the halo turns clockwise from the start until it has split into rows
const OPEN = [0.43, 0.59]; // the halo splits into two rows, above and below the words
const GRAY_AT = 0.63; // the rows lose their color here
const LEAVE = [0.71, 0.775]; // the rows run off the sides: short, so leaving is quick
const FINALE = [0.845, 0.975]; // three big pictures rise from below
const LINE_AT = [0, 0.2, 0.47, 0.63, 0.78, 0.855]; // where each scene's line takes over

const SOFTEN = 0.16; // s: how softly the story follows a wheel or trackpad (higher = softer)
const SOFTEN_TOUCH = 0.07; // s: touch scrolling is already smooth, so it follows closer
const WORD_IN_MS = 1100; // each word rising into place: slow, with a long soft landing
const WORD_GAP_MS = 55; // between words, left to right
const WORD_WAIT_MS = 160; // the new line waits for the old one to leave first
const WORD_OUT_MS = 260; // a line leaving: quick
const GRAY_IN_MS = 1600; // the rows fading to gray, slowly
const GRAY_OUT_MS = 500; // and back to color, quicker
const FADE_MS = 220; // reduced motion: each scene fades out and back in at its place
const IN_EASE = "cubic-bezier(.22,1,.36,1)"; // gentle start, long soft landing
const OUT_EASE = "cubic-bezier(.4,0,1,1)"; // speeds up as it goes

// Card shapes, width to height, used in turn so the halo has a natural mix.
const SHAPES = [0.8, 1.25, 1, 0.75, 1.33, 0.9, 1.15, 1.5, 0.8, 1.1];
const GLIDE_DEG = 32; // a joining picture starts this far behind its place and glides forward, clockwise
const OPEN_EACH = 0.7; // how much of the split each picture takes: the top and bottom go first, the sides follow

const CSS = `
.hs{--hs-fg:var(--foreground,var(--fg,CanvasText));--hs-bg:var(--background,var(--bg,Canvas));position:relative;background:var(--hs-bg);color:var(--hs-fg);--hs-v:100vh;--hs-v:100svh}
.hs[data-own]{height:var(--hs-h);--hs-v:var(--hs-h);overflow-y:auto;scrollbar-width:none}
.hs[data-own]::-webkit-scrollbar{display:none}
.hs[data-own]:focus-visible{outline:2px solid color-mix(in srgb,var(--hs-fg) 45%,transparent);outline-offset:-2px}
.hs-track{position:relative;height:calc(var(--hs-v) * var(--hs-len))}
.hs-stage{position:sticky;top:0;height:var(--hs-v);overflow:hidden;container-type:size;user-select:none;-webkit-user-select:none}
.hs-cards,.hs-fin{position:absolute;inset:0;pointer-events:none}
.hs-cards{-webkit-mask-image:linear-gradient(to right,transparent,#000 7%,#000 93%,transparent);mask-image:linear-gradient(to right,transparent,#000 7%,#000 93%,transparent);transition:filter ${GRAY_OUT_MS}ms ${OUT_EASE},opacity ${FADE_MS}ms ${IN_EASE}}
.hs-cards[data-gray]{filter:grayscale(1) brightness(.94);transition:filter ${GRAY_IN_MS}ms ${IN_EASE},opacity ${FADE_MS}ms ${IN_EASE}}
.hs-fin{-webkit-mask-image:linear-gradient(to bottom,#000 78%,transparent 99%);mask-image:linear-gradient(to bottom,#000 78%,transparent 99%);perspective:1400px;transition:opacity ${FADE_MS}ms ${IN_EASE}}
.hs-stage[data-hide] .hs-cards,.hs-stage[data-hide] .hs-fin{opacity:0;transition:opacity ${FADE_MS}ms ${OUT_EASE}}
.hs-c,.hs-f{position:absolute;left:50%;top:50%;overflow:hidden;opacity:0;will-change:transform,opacity;border-radius:var(--hs-r);background:color-mix(in srgb,var(--hs-fg) 6%,var(--hs-bg));box-shadow:0 0 0 1px color-mix(in srgb,var(--hs-fg) 8%,transparent)}
.hs-f{border-radius:calc(var(--hs-r) * 1.6);box-shadow:0 0 0 1px color-mix(in srgb,var(--hs-fg) 8%,transparent),0 30px 60px -30px rgba(0,0,0,.45)}
.hs-c[data-broken],.hs-f[data-broken]{display:none}
.hs-c img,.hs-f img{display:block;width:100%;height:100%;max-width:none;object-fit:cover;pointer-events:none;user-select:none;-webkit-user-select:none;-webkit-user-drag:none;-webkit-touch-callout:none}
.hs-text{position:absolute;left:50%;top:50%;width:var(--hs-tw,min(58cqw,760px));translate:-50% -50%;display:grid;place-items:center;text-align:center;pointer-events:none;will-change:transform}
.hs-line{grid-area:1/1;margin:0;font-size:var(--hs-text,clamp(13px,3.6cqw + 8px,46px));line-height:1.18;font-weight:500;letter-spacing:-.015em;text-wrap:balance;perspective:600px}
.hs-w{display:inline-block;max-width:100%;overflow-wrap:anywhere;opacity:0;transform-origin:50% 100%;transform:translateY(.55em) rotateX(-55deg);filter:blur(6px);transition:transform ${WORD_OUT_MS}ms ${OUT_EASE},opacity ${WORD_OUT_MS}ms ${OUT_EASE},filter ${WORD_OUT_MS}ms ${OUT_EASE}}
.hs-line[data-s=past] .hs-w{transform:translateY(-.45em);filter:blur(4px)}
.hs-line[data-s=now] .hs-w{opacity:1;transform:none;filter:blur(0);transition:transform ${WORD_IN_MS}ms ${IN_EASE} var(--d),opacity ${Math.round(WORD_IN_MS * 0.8)}ms ${IN_EASE} var(--d),filter ${Math.round(WORD_IN_MS * 0.8)}ms ${IN_EASE} var(--d)}
@media (prefers-reduced-motion:reduce){.hs-w,.hs-line[data-s] .hs-w{transform:none;filter:none;transition:opacity ${FADE_MS}ms linear}.hs-cards[data-gray],.hs-cards{transition-duration:${FADE_MS}ms}}
.hs-sr{position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0,0,0,0);white-space:nowrap;border:0}
`;

/* ---------- small helpers ---------- */

const clamp = (v: number, a = 0, b = 1) => Math.min(b, Math.max(a, v));
const span = (p: number, [a, b]: number[]) => clamp((p - a) / (b - a));
const mix = (a: number, b: number, t: number) => a + (b - a) * t;
const outQuart = (t: number) => 1 - (1 - t) ** 4; // arrives slowly, long soft landing
const outCubic = (t: number) => 1 - (1 - t) ** 3;
const inOutCubic = (t: number) => (t < 0.5 ? 4 * t * t * t : 1 - (-2 * t + 2) ** 3 / 2); // travels, then settles
const inCubic = (t: number) => t * t * t; // leaves quickly
const RAD = Math.PI / 180;
/** How far the halo has turned clockwise at p: steady with the scroll, then it stops once the rows have formed. */
const turnAt = (p: number) => (clamp(p, 0, OPEN[1]) / OPEN[1]) * TURN_DEG * RAD;
const cssLength = (h: number | string) => (typeof h === "number" ? `${h}px` : h);

type Geo = {
  W: number;
  H: number;
  n: number; // cards in the halo and rows
  u: number; // card size (square root of its area), px
  rx: number; // halo, half width
  ry: number; // halo, half height
  rowH: number; // card height in the rows
};

function measure(W: number, H: number, count: number): Geo {
  const u = clamp(Math.min(W, H * 1.5) * 0.115, 18, 132);
  const edge = Math.max(10, W * 0.02);
  const rx = Math.max(u, W / 2 - u * 0.8 - edge);
  const ry = Math.max(u, H / 2 - u * 0.8 - edge);
  // Ramanujan's length of an ellipse: how many cards fit round it, a little overlapped.
  const around = Math.PI * (3 * (rx + ry) - Math.sqrt((3 * rx + ry) * (rx + 3 * ry)));
  const n = Math.round(clamp(around / (u * 0.95), 10, Math.max(10, Math.min(32, Math.max(count, 12)))));
  const rowH = clamp(H * 0.19, 34, 230);
  return { W, H, n, u, rx, ry, rowH };
}

/** Each card's fixed size, plus the parts of its path that don't change while you scroll. */
type Plan = {
  w: number;
  h: number;
  base: number; // its angle on the halo before turning
  join: number; // when it starts to join the halo, on the 0..1 scroll
  belt: number; // its place on the loop once the rows have formed (distance along the loop, px)
  open: number; // when it starts to leave the halo for its row, on the 0..1 scroll
  rowS: number; // its scale in the row
};

/** The rows are one long loop, like a conveyor belt: the top row runs right, round the far end
 *  (off screen), back along the bottom running left, and round again. Clockwise, the same way the halo turns. */
type Belt = { L: number; R: number; P: number };

/** The point at distance s along the loop, starting top middle and going clockwise. */
function beltAt(s: number, { L, R, P }: Belt): [number, number] {
  s = ((s % P) + P) % P;
  const cap = Math.PI * R;
  if (s < L) return [s, -R];
  if (s < L + cap) {
    const a = (s - L) / R - Math.PI / 2;
    return [L + R * Math.cos(a), R * Math.sin(a)];
  }
  if (s < 3 * L + cap) return [L - (s - L - cap), R];
  if (s < 3 * L + 2 * cap) {
    const a = (s - 3 * L - cap) / R + Math.PI / 2;
    return [-L + R * Math.cos(a), R * Math.sin(a)];
  }
  return [s - P, -R];
}

function plan(g: Geo): { cards: Plan[]; belt: Belt } {
  const { n, u, W, H, rx } = g;
  // Row size: on a wide screen the rows grow a little (up to a third), so they stay full instead of gappy.
  const shapes = Array.from({ length: n }, (_, i) => SHAPES[i % SHAPES.length]);
  const across = shapes.reduce((s, a) => s + a, 0); // the rows' length in card heights
  const widest = Math.max(...shapes);
  const fits = (h: number) => across * h * 1.08 >= 4 * (W / 2 + widest * h) + 2 * Math.PI * rowsAt(h);
  const rowsAt = (h: number) => Math.min(H * 0.27, H / 2 - h / 2 - Math.max(H * 0.06, 12));
  let rowH = g.rowH;
  while (!fits(rowH) && rowH < g.rowH * 1.33) rowH *= 1.04;
  const R = rowsAt(rowH); // rows sit this far above and below the middle
  const turned = turnAt(OPEN[1]);
  // The order pictures join in: spread evenly round the ring (golden ratio steps), so the
  // first few sit far apart and the gaps fill in. Early ones come slowly, later ones closer together.
  const order = Array.from({ length: n }, (_, i) => i).sort((a, b) => ((a * 0.618034) % 1) - ((b * 0.618034) % 1));
  const rank = new Array<number>(n);
  order.forEach((i, r) => (rank[i] = r));
  const cards: Plan[] = Array.from({ length: n }, (_, i) => {
    const a = SHAPES[i % SHAPES.length];
    const base = -Math.PI / 2 + (i / n) * Math.PI * 2;
    const h = u / Math.sqrt(a);
    // Pictures at the top and bottom of the halo flatten into the rows first, the ones at the sides last.
    const side = Math.abs(Math.cos(base + turned));
    return {
      w: u * Math.sqrt(a),
      h,
      base,
      join: JOIN[0] + (1 - (1 - rank[i] / Math.max(1, n - 1)) ** 2) * (JOIN[1] - JOIN[0] - JOIN_EACH),
      belt: 0,
      open: OPEN[0] + side * (OPEN[1] - OPEN[0]) * (1 - OPEN_EACH),
      rowS: rowH / h,
    };
  });
  // Lay the pictures along the loop in the same order they sit on the halo, so nobody overtakes.
  const widths = cards.map((c) => c.w * c.rowS);
  const sum = widths.reduce((s, w) => s + w, 0);
  const cap = 2 * Math.PI * R;
  // Each straight must reach past the screen's edge, so the loop's ends always turn off screen.
  const need = 4 * (W / 2 + Math.max(...widths)) + cap;
  const gap = Math.max(rowH * 0.08, (need - sum) / n);
  const P = sum + gap * n;
  const belt: Belt = { L: (P - cap) / 4, R, P };
  // Start the loop from the picture about to climb the halo's left side: it lands at the left of the top row,
  // and every picture after it lands further along. So each one only ever moves forward, clockwise.
  let first = 0;
  let best = Infinity;
  cards.forEach((c, i) => {
    const behind = (((Math.PI - (c.base + turned)) % (2 * Math.PI)) + 2 * Math.PI) % (2 * Math.PI);
    if (behind < best) [best, first] = [behind, i];
  });
  let at = P - rx * 0.9;
  for (let k = 0; k < n; k++) {
    const i = (first + k) % n;
    cards[i].belt = at; // the middle of the picture
    at += widths[i] / 2 + gap + widths[(i + 1) % n] / 2;
  }
  return { cards, belt };
}

export function HaloStory({
  images,
  finale,
  lines = [],
  height,
  length = 7,
  radius = 10,
  "aria-label": ariaLabel = "Picture story",
  className,
  style,
}: HaloStoryProps) {
  const own = height !== undefined;
  const rootRef = useRef<HTMLDivElement>(null);
  const trackRef = useRef<HTMLDivElement>(null);
  const stageRef = useRef<HTMLDivElement>(null);
  const cardsRef = useRef<HTMLDivElement>(null);
  const textRef = useRef<HTMLDivElement>(null);
  const [geo, setGeo] = useState<Geo | null>(null);
  const [line, setLine] = useState(-1);
  const [gray, setGray] = useState(false);

  const pics = images.length ? images : [];
  const big = (finale && finale.length ? finale : pics).slice(0, 3);
  const layout = useMemo(() => (geo ? plan(geo) : null), [geo]);
  const words = useMemo(() => lines.map((l) => l.split(/\s+/).filter(Boolean)), [lines]);

  // Measure the stage, and again whenever it changes size.
  useEffect(() => {
    const stage = stageRef.current;
    const root = rootRef.current;
    if (!stage || !root) return;
    const ro = new ResizeObserver(() => {
      // An own scroll box can be sized in % or any unit: one screen is its measured height.
      if (own && root.clientHeight) root.style.setProperty("--hs-v", `${root.clientHeight}px`);
      const W = stage.clientWidth;
      const H = stage.clientHeight;
      if (!W || !H) return;
      setGeo((g) => (g && g.W === W && g.H === H ? g : measure(W, H, pics.length)));
    });
    ro.observe(stage);
    if (own) ro.observe(root);
    return () => ro.disconnect();
  }, [pics.length, own]);

  // The scroll loop: read where you scrolled, ease toward it, place every card.
  useEffect(() => {
    const root = rootRef.current;
    const track = trackRef.current;
    const stage = stageRef.current;
    const layer = cardsRef.current;
    const text = textRef.current;
    if (!root || !track || !stage || !layer || !text || !geo || !layout) return;
    const cardEls = Array.from(layer.children) as HTMLElement[];
    const finEls = Array.from(stage.querySelectorAll<HTMLElement>(".hs-f"));
    const reduce = matchMedia("(prefers-reduced-motion: reduce)");
    const coarse = matchMedia("(pointer: coarse)");
    const { W, H, rx, ry } = geo;
    const { cards, belt } = layout;
    // The rows carry on at the speed the top of the halo was moving.
    const speed = rx * ((TURN_DEG * RAD) / OPEN[1]);

    const read = () => {
      if (own) {
        const max = root.scrollHeight - root.clientHeight;
        return max > 0 ? clamp(root.scrollTop / max) : 0;
      }
      const r = track.getBoundingClientRect();
      const run = r.height - innerHeight;
      return run > 0 ? clamp(-r.top / run) : 0;
    };
    const inView = () => {
      const r = (own ? root : track).getBoundingClientRect();
      return r.top < innerHeight * 0.65 && r.bottom > innerHeight * 0.35;
    };

    const place = (p: number) => {
      const turn = turnAt(p);
      const ran = speed * (p - OPEN[1]); // how far the loop has run since the rows formed
      const leave = inCubic(span(p, LEAVE)) * W * 0.95;
      const gone = 1 - clamp((span(p, LEAVE) - 0.35) / 0.65);
      for (let i = 0; i < cards.length; i++) {
        const c = cards[i];
        const el = cardEls[i];
        if (!el) continue;
        // Joining: it starts a little behind its place and glides forward, clockwise, with the turning halo.
        const t = outCubic(span(p, [c.join, c.join + JOIN_EACH]));
        const ang = c.base + turn - (1 - t) * GLIDE_DEG * RAD;
        const near = mix(0.9, 1, t);
        let x = rx * near * Math.cos(ang);
        let y = ry * near * Math.sin(ang);
        let s = mix(0.4, 1, t);
        let o = clamp(t * 2.2);
        let r = 0;
        // Splitting: the halo stretches out into the loop. Each picture heads for its place further along,
        // so the top half becomes the row above the words (running right), the bottom half the row below (running left).
        const m = inOutCubic(span(p, [c.open, c.open + (OPEN[1] - OPEN[0]) * OPEN_EACH]));
        if (m > 0) {
          const [bx, by] = beltAt(c.belt + ran, belt);
          x = mix(x, bx - (by / belt.R) * leave, m); // leaving: the top row runs off right, the bottom off left
          y = mix(y, by, m);
          s = mix(s, c.rowS, m);
          r = Math.sin(Math.PI * m) * 2.5; // a slight clockwise lean while it travels
          o *= gone;
        }
        el.style.opacity = o < 0.002 ? "0" : o.toFixed(3);
        el.style.visibility = o < 0.002 ? "hidden" : "";
        el.style.transform = `translate3d(${(x - c.w / 2).toFixed(2)}px,${(y - c.h / 2).toFixed(2)}px,0) rotate(${r.toFixed(2)}deg) scale(${s.toFixed(4)})`;
      }
      // The finale: the middle picture rises first, the side ones fan out from behind it.
      const fw = clamp(Math.min(W * 0.34, H * 0.42), 60, 420);
      const fh = fw * 1.3;
      finEls.forEach((el, j) => {
        const side = j === 0 ? -1 : j === 2 ? 1 : 0;
        const start = FINALE[0] + (side ? 0.022 : 0);
        const t = span(p, [start, start + (FINALE[1] - FINALE[0]) * 0.8]);
        const rise = outQuart(t);
        const fan = inOutCubic(clamp((t - 0.12) / 0.88));
        const x = side * fw * 1.06 * fan;
        const y = H * (side ? 0.27 : 0.22) + (1 - rise) * H * 0.55;
        const rotY = -side * 22 * fan;
        const tilt = (1 - rise) * 18;
        el.style.width = `${fw}px`;
        el.style.height = `${fh}px`;
        el.style.zIndex = side ? "0" : "1";
        el.style.opacity = rise < 0.002 ? "0" : clamp(rise * 1.6).toFixed(3);
        el.style.visibility = rise < 0.002 ? "hidden" : "";
        el.style.transform = `translate3d(${(x - fw / 2).toFixed(2)}px,${(y - fh / 2).toFixed(2)}px,0) rotateX(${tilt.toFixed(2)}deg) rotateY(${rotY.toFixed(2)}deg) rotate(${(side * 2 * fan).toFixed(2)}deg)`;
      });
      // The words make room for the finale.
      text.style.transform = `translateY(${(-H * 0.25 * inOutCubic(span(p, [FINALE[0] - 0.01, FINALE[0] + 0.07]))).toFixed(2)}px)`;
    };

    // Reduced motion: no travel. Each scene shows at rest and fades in at its place.
    const SCENES = [0.12, 0.42, 0.62, 0.79, 1];
    const sceneOf = (p: number) => (p < 0.28 ? 0 : p < 0.5 ? 1 : p < 0.74 ? 2 : p < 0.84 ? 3 : 4);
    let shown = -1;
    let fadeTimer = 0;

    let cur = read();
    let lineNow = -1;
    let grayNow = false;
    let raf = 0;
    let last = 0;
    let seen = false;

    const words = (p: number) => {
      if (!seen) seen = inView();
      let next = -1;
      if (seen) for (let i = 0; i < LINE_AT.length; i++) if (p >= LINE_AT[i] - (i <= lineNow ? 0.006 : 0)) next = i;
      if (next !== lineNow) {
        lineNow = next;
        setLine(next);
      }
      const g = p >= GRAY_AT && p < FINALE[0];
      if (g !== grayNow) {
        grayNow = g;
        setGray(g);
      }
    };

    const frame = (now: number) => {
      raf = 0;
      const dt = last ? Math.min(0.1, (now - last) / 1000) : 1 / 60;
      last = now;
      const target = read();
      if (reduce.matches) {
        cur = target;
        const sc = sceneOf(cur);
        if (sc !== shown) {
          if (shown < 0) {
            shown = sc;
            place(SCENES[sc]);
          } else {
            stage.setAttribute("data-hide", "");
            clearTimeout(fadeTimer);
            fadeTimer = window.setTimeout(() => {
              shown = sceneOf(cur);
              place(SCENES[shown]);
              stage.removeAttribute("data-hide");
            }, FADE_MS);
          }
        }
        words(cur);
        last = 0;
        return;
      }
      const soft = coarse.matches ? SOFTEN_TOUCH : SOFTEN;
      cur += (target - cur) * (1 - Math.exp(-dt / soft));
      if (Math.abs(target - cur) < 0.00004) cur = target;
      place(cur);
      words(cur);
      if (cur !== target) raf = requestAnimationFrame(frame);
      else last = 0;
    };
    const kick = () => {
      if (!raf) raf = requestAnimationFrame(frame);
    };

    if (reduce.matches) {
      shown = sceneOf(cur);
      place(SCENES[shown]);
    } else place(cur);
    words(cur);
    kick();

    const scroller: HTMLElement | Window = own ? root : window;
    scroller.addEventListener("scroll", kick, { passive: true });
    if (!own) addEventListener("resize", kick);
    // Not seen yet: wake up when it comes into view, so the first line plays as you arrive.
    const io = new IntersectionObserver(kick, { threshold: [0, 0.35, 0.65] });
    io.observe(own ? root : track);
    return () => {
      cancelAnimationFrame(raf);
      clearTimeout(fadeTimer);
      io.disconnect();
      scroller.removeEventListener("scroll", kick);
      if (!own) removeEventListener("resize", kick);
      stage.removeAttribute("data-hide");
    };
  }, [geo, layout, own]);

  const broken = (e: SyntheticEvent<HTMLImageElement>) => e.currentTarget.parentElement?.setAttribute("data-broken", "");

  const rootStyle = {
    ...style,
    "--hs-len": (Number.isFinite(length) ? Math.max(2, length) : 7) + 1,
    "--hs-r": `${radius}px`,
    ...(own ? { "--hs-h": cssLength(height!) } : null),
  } as CSSProperties;

  return (
    <div
      ref={rootRef}
      className={`hs${className ? ` ${className}` : ""}`}
      data-own={own ? "" : undefined}
      style={rootStyle}
      tabIndex={own ? 0 : undefined}
      role={own ? "region" : undefined}
      aria-label={own ? ariaLabel : undefined}
    >
      <style>{CSS}</style>
      <div ref={trackRef} className="hs-track">
        <div ref={stageRef} className="hs-stage">
          <div ref={cardsRef} className="hs-cards" data-gray={gray ? "" : undefined}>
            {layout?.cards.map((c, i) => {
              const pic = pics[i % Math.max(1, pics.length)];
              if (!pic) return null;
              const first = i < pics.length;
              return (
                <div key={i} className="hs-c" style={{ width: c.w, height: c.h, opacity: 0 }}>
                  <img src={pic.src} alt={first ? pic.alt : ""} aria-hidden={first ? undefined : true} loading="lazy" decoding="async" draggable={false} onError={broken} />
                </div>
              );
            })}
          </div>
          <div className="hs-fin">
            {big.map((pic, j) => (
              <div key={j} className="hs-f" style={{ opacity: 0 }}>
                <img src={pic.src} alt={pic.alt} loading="lazy" decoding="async" draggable={false} onError={broken} />
              </div>
            ))}
          </div>
          <div ref={textRef} className="hs-text" aria-hidden="true">
            {words.map((ws, i) => (
              <p key={i} className="hs-line" dir="auto" data-s={i === line ? "now" : i < line ? "past" : "next"}>
                {ws.map((w, k) => (
                  <Fragment key={k}>
                    {k > 0 && " "}
                    <span className="hs-w" style={{ "--d": `${WORD_WAIT_MS + k * WORD_GAP_MS}ms` } as CSSProperties}>
                      {w}
                    </span>
                  </Fragment>
                ))}
              </p>
            ))}
          </div>
        </div>
      </div>
      {lines.length > 0 && (
        <ol className="hs-sr">
          {lines.map((l, i) => (
            <li key={i}>{l}</li>
          ))}
        </ol>
      )}
    </div>
  );
}
```

Usage

Pass your pictures to images and one short line per scene to lines. Leave out height on a page, so it pins to the screen while the page scrolls past it.

"use client";
import { HaloStory } from "@/components/ui/halo-story";

// Your pictures, and one line for each of the six scenes.
const pictures = [
  { src: "/story/01.webp", alt: "Our team at the first launch" },
  { src: "/story/02.webp", alt: "The studio at night" },
  // ...12 to 28 pictures read best
];

export function Story() {
  return (
    <HaloStory
      images={pictures}
      lines={[
        "Every day, the web gets more screens,",
        "made faster than ever before.",
        "Pages pile up, one after another,",
        "but few of them feel alive.",
        "We make the parts that do.",
        "Let's make something for Humans once again.",
      ]}
    />
  );
}

// Or give it a height to make it its own scroll box.
// <HaloStory images={pictures} lines={lines} height={600} />

How it moves

Six scenes, one line each. The pictures follow your scroll, but softly: the story eases toward where you scrolled instead of jumping with every wheel step, so nothing ever snaps.

Everything turns one way only: clockwise. Pictures join a halo around the words one at a time, a few at first and then more and more, each one growing in from small while it glides forward with the turning ring, with a long, soft landing. The halo keeps turning clockwise as it fills, about 150 degrees in all. Then it stretches out into one long loop, like a conveyor belt: the top half becomes a row above the words running right, the bottom half a row below running left, and the loop turns round off screen at both ends. Every picture heads further along the way it was already going, so nothing ever turns back. As the fourth line arrives, the rows fade to gray over 1.6 seconds, then run off the sides the same way, quickly, fading at the edges. After a quiet line on its own, three big pictures rise from below in full color: the middle one first, the side ones fanning out from behind it and turning toward you, while the words move up to make room. Each line arrives word by word, every word rising and coming into focus in 1.1 seconds, 55ms apart; the line before it leaves in a quarter of a second. With reduced motion nothing travels: each scene fades in at its place in 0.22 seconds.

Props

PropDefaultWhat it does
images—The pictures for the halo and the rows: { src, alt }. 12 to 28 read best; fewer are repeated to close the ring. Each is cropped to its card.
lines[]One line per scene, in order: the first pictures, the full halo, the rows, the gray rows, the quiet moment and the finale. Short lines read best.
finalefirst 3 imagesThe three big pictures at the end: left, middle, right. Portrait pictures fit best.
height—Makes it its own scroll box this tall: 600 (px) or any CSS length like "80vh". Leave it out to pin it to the screen while the page scrolls.
length7How long the story is, in screens of scrolling. Fewer feels quicker, more feels calmer.
radius10Corner radius of the small pictures, in px. The big ones get 1.6 times as much.
aria-label"Picture story"Name of the scroll box for screen readers, only with a height. The lines are also read out as a list.
className / style—On the outer box. Colors come from --foreground and --background (or --fg and --bg), so it follows your theme. Set --hs-text to fix the size of the words.