# Add the "Coverflow Carousel" block to this P1 project

Add a Puck component from P1 Blocks (https://p1-blocks.prolificdigital.io/blocks/coverflow-carousel) to this Pantheon Content Publisher (P1) Next.js project. Image cards fanned out in 3D around a spotlit center card with its caption. Drag, throw, buttons or arrow keys.

## Steps

1. Install the dependency: `pnpm add gsap` (use the project's package manager if it isn't pnpm).
2. Create these files with the exact contents below, in the same folder: `components/puck/coverflow-carousel-block.tsx`, `components/puck/coverflow-carousel.client.tsx`. If `components/puck/` doesn't exist, use the folder where this project keeps its Puck components (look at the imports in `puck.config.tsx`).
3. In `puck.config.tsx`, import it: `import { coverflowCarouselBlock } from "./components/puck/coverflow-carousel-block";`
4. Register it under `components` as `CoverflowCarouselBlock: coverflowCarouselBlock`.
5. Add `"CoverflowCarouselBlock"` to the best-fitting entry in `categories` (this block's library category is "Carousels"). Create a category only if none fits.
6. Run the project's type check (usually `pnpm typecheck`) and resolve anything project-specific.
7. If `package.json` has a `sync:registry` script, tell the user it must run (or that CI will run it) before the new component appears in the P1 editor.

## Rules

- The block is two files: a server-safe Puck config and a `"use client"` island it imports by relative path. Keep both files in the same folder and keep the island's file name unchanged.
- WebGPU effects are progressive enhancement: content is server-rendered and a CSS fallback shows wherever WebGPU is unavailable. Don't move content into the client file.
- Keep the files as-is unless the user asks for changes. The accent color is `indigo-*`; if the project has brand colors, offer to swap them with a find-and-replace on `indigo-`.
- Images are plain `imageUrl` + `imageAlt` text fields. If this project defines a P1 media-library field (search for `"p1-media"`), offer to switch to it.
- Don't change prop names in `defaultProps`. Content editors' saved pages depend on them.

## File: `components/puck/coverflow-carousel-block.tsx`

```tsx
import type { ComponentConfig } from "@puckeditor/core";
import { CoverflowStage } from "./coverflow-carousel.client";

/**
 * Coverflow Carousel — image cards fanned out in 3D around a spotlit center card, with the
 * centered card's caption beneath. Drag, buttons or arrow keys; a plain swipeable strip
 * without JavaScript or with reduced motion. Needs `pnpm add gsap` and coverflow-carousel.client.tsx.
 * Register: `CoverflowCarouselBlock: coverflowCarouselBlock` in puck.config.tsx.
 */

type Heading = "h1" | "h2" | "h3" | "h4";

type Item = {
  imageUrl: string;
  imageAlt: string;
  title: string;
  caption: string;
};

export type CoverflowCarouselProps = {
  eyebrow: string;
  heading: string;
  headingLevel: Heading;
  intro: string;
  label: string;
  items: Item[];
};

export const coverflowCarouselBlock: ComponentConfig<CoverflowCarouselProps> = {
  label: "Coverflow Carousel",
  fields: {
    eyebrow: { type: "text", label: "Eyebrow", metadata: { help: "Small line above the heading. Leave blank to hide it." } },
    heading: { type: "text", label: "Heading" },
    headingLevel: {
      type: "select",
      label: "Heading level",
      options: [
        { label: "H1", value: "h1" },
        { label: "H2", value: "h2" },
        { label: "H3", value: "h3" },
        { label: "H4", value: "h4" },
      ],
      metadata: { help: "Sets the page outline for screen readers and search. The look doesn't change." },
    },
    intro: { type: "textarea", label: "Intro" },
    label: {
      type: "text",
      label: "Carousel name",
      metadata: { help: "Read aloud by screen readers, e.g. \"Works in the exhibition\". Not shown on the page." },
    },
    items: {
      type: "array",
      label: "Cards",
      min: 1,
      max: 15,
      getItemSummary: (item) => item?.title || "Card",
      defaultItemProps: {
        imageUrl: "https://picsum.photos/seed/canvas/720/960",
        imageAlt: "",
        title: "Untitled work",
        caption: "Artist name, year. Medium.",
      },
      arrayFields: {
        imageUrl: { type: "text", label: "Image URL", metadata: { help: "A portrait image (3:4) works best, at least 720px wide." } },
        imageAlt: { type: "text", label: "Image description", metadata: { help: "Describe the image for people who can't see it." } },
        title: { type: "text", label: "Title" },
        caption: { type: "textarea", label: "Caption", metadata: { help: "Shown under the card while it's in the center." } },
      },
    },
  },
  defaultProps: {
    eyebrow: "2026 Community Open",
    heading: "Forty neighbors, one wall",
    headingLevel: "h2",
    intro: "Every piece in this year's open call was made by someone who lives within ten miles of the gallery. Drag through a few of the works now on view, free, through December.",
    label: "Works in the exhibition",
    items: [
      { imageUrl: "https://picsum.photos/seed/ohiomorning/720/960", imageAlt: "Soft-focus landscape of mist over a slow river at dawn", title: "Morning on the Ohio", caption: "Dana Whitfield, 2026. Oil on linen." },
      { imageUrl: "https://picsum.photos/seed/fieldstudy/720/960", imageAlt: "Close study of dry grasses and seed heads against a pale sky", title: "Field Study No. 4", caption: "Marcus Oyelaran, 2025. Cyanotype." },
      { imageUrl: "https://picsum.photos/seed/porchlight/720/960", imageAlt: "A lit porch on a dark street, seen from across the road", title: "Porch Light, Germantown", caption: "Lena Ruiz, 2026. Archival pigment print." },
      { imageUrl: "https://picsum.photos/seed/quilthands/720/960", imageAlt: "Hands stitching a patchwork quilt in deep blues and rust", title: "What We Kept", caption: "The Tuesday Quilters, 2026. Cotton, thread, forty years of fabric." },
      { imageUrl: "https://picsum.photos/seed/busstop/720/960", imageAlt: "A bus shelter at dusk with streaks of passing headlights", title: "Route 23, 6:40 pm", caption: "Theo Grant, age 15, 2026. Long-exposure photograph." },
      { imageUrl: "https://picsum.photos/seed/claybowls/720/960", imageAlt: "A stack of hand-thrown clay bowls with uneven glazes", title: "Twelve Bowls for the Pantry", caption: "Ruth Adeyemi, 2025. Stoneware, ash glaze." },
      { imageUrl: "https://picsum.photos/seed/rivermap/720/960", imageAlt: "A hand-drawn map of creeks and streets layered in ink", title: "Where the Creek Went", caption: "Sam Holloway, 2026. Ink and watercolor on found survey maps." },
    ],
  },
  render: ({ id, eyebrow, heading, headingLevel, intro, label, items }) => {
    const H = headingLevel || "h2";
    const cards = (items ?? []).filter((it) => it && (it.imageUrl || it.title));
    const headingId = `${id}-heading`;
    const many = cards.length > 1;
    return (
      <section aria-labelledby={heading ? headingId : undefined} className="relative isolate overflow-hidden bg-neutral-950 px-4 py-16 sm:px-6 sm:py-20 lg:px-8 lg:py-24">
        <div aria-hidden="true" className="pointer-events-none absolute inset-x-0 top-1/3 -z-10 mx-auto h-96 max-w-3xl rounded-full bg-indigo-500/20 blur-3xl" />
        <div className="mx-auto max-w-7xl">
          {eyebrow || heading || intro ? (
            <div className="grid grid-cols-1 gap-6 lg:grid-cols-12 lg:items-end lg:gap-12">
              <div className="lg:col-span-7">
                {eyebrow ? <p className="text-xs font-semibold tracking-widest text-indigo-300 uppercase sm:text-sm">{eyebrow}</p> : null}
                {heading ? (
                  <H id={headingId} className="mt-3 text-4xl font-semibold tracking-tight text-balance text-white sm:text-5xl">
                    {heading}
                  </H>
                ) : null}
              </div>
              {intro ? <p className="text-base leading-7 text-pretty text-neutral-300 lg:col-span-5 lg:text-lg lg:leading-8">{intro}</p> : null}
            </div>
          ) : null}
          {cards.length ? (
            <div className="mt-12 sm:mt-16">
              <CoverflowStage count={cards.length} label={label || heading || "Image carousel"}>
                {cards.map((card, i) => (
                  <figure
                    key={i}
                    data-slide=""
                    role={many ? "group" : undefined}
                    aria-roledescription={many ? "slide" : undefined}
                    aria-label={many ? `${i + 1} of ${cards.length}` : undefined}
                    className="w-60 shrink-0 snap-center sm:w-72 lg:w-80"
                  >
                    <div className="relative aspect-3/4 overflow-hidden rounded-2xl bg-neutral-800 shadow-2xl shadow-black/60 ring-1 ring-white/10">
                      {card.imageUrl ? <img src={card.imageUrl} alt={card.imageAlt || ""} draggable={false} className="size-full object-cover" /> : null}
                      <div data-shade="" aria-hidden="true" className="absolute inset-0 bg-neutral-950 opacity-0" />
                      <div aria-hidden="true" className="absolute inset-0 rounded-2xl bg-gradient-to-tr from-transparent via-transparent to-white/10" />
                    </div>
                    {card.title || card.caption ? (
                      <figcaption data-caption="" className="mt-6 px-1 text-center">
                        {card.title ? (
                          <p data-title="" className="text-base font-semibold text-white">
                            {card.title}
                          </p>
                        ) : null}
                        {card.caption ? <p className="mt-1 text-sm leading-6 text-pretty text-neutral-400">{card.caption}</p> : null}
                      </figcaption>
                    ) : null}
                  </figure>
                ))}
              </CoverflowStage>
            </div>
          ) : null}
        </div>
      </section>
    );
  },
};
```

## File: `components/puck/coverflow-carousel.client.tsx`

```tsx
"use client";

import { useEffect, useLayoutEffect, useRef, useState } from "react";
import type { KeyboardEvent, ReactNode } from "react";
import { gsap } from "gsap";
import { Draggable } from "gsap/Draggable";
import { InertiaPlugin } from "gsap/InertiaPlugin";

/**
 * Motion half of the Coverflow Carousel. The cards arrive server-rendered as a scroll-snap
 * strip; this lifts them into a 3D fan driven by one continuous position value, so drag,
 * throw, buttons and keys all share the same motion. Reduced motion keeps the flat strip.
 */

if (typeof window !== "undefined") gsap.registerPlugin(Draggable, InertiaPlugin);

const useIsoLayoutEffect = typeof window === "undefined" ? useEffect : useLayoutEffect;

type Api = { go: (index: number) => void; step: (delta: number) => void };

type CoverflowStageProps = {
  count: number;
  label: string;
  children: ReactNode;
};

const pad = (n: number) => String(n).padStart(2, "0");
const clamp = (min: number, max: number, v: number) => Math.min(max, Math.max(min, v));

export function CoverflowStage({ count, label, children }: CoverflowStageProps) {
  const rootRef = useRef<HTMLDivElement>(null);
  const trackRef = useRef<HTMLDivElement>(null);
  const api = useRef<Api | null>(null);
  const [ready, setReady] = useState(false);
  const [index, setIndex] = useState(0);
  const [message, setMessage] = useState("");
  const many = count > 1;

  useIsoLayoutEffect(() => {
    const root = rootRef.current;
    const track = trackRef.current;
    if (!root || !track || !many) return;
    const slides = Array.from(track.children).filter((el): el is HTMLElement => el instanceof HTMLElement && el.hasAttribute("data-slide"));
    const n = slides.length;
    if (n < 2) return;

    const reduced = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
    const title = (s: HTMLElement) => s.querySelector("[data-title]")?.textContent?.trim();
    let active = -1;
    const commit = (i: number, flat: boolean) => {
      if (i === active) return;
      const first = active === -1;
      active = i;
      if (!flat) slides.forEach((s, k) => (s.inert = k !== i));
      setIndex(i);
      if (!first) {
        const t = title(slides[i]);
        setMessage(`${t ? `${t}, ` : ""}${i + 1} of ${n}`);
      }
    };

    // Reduced motion: keep the native strip, just center cards and track which one is in view.
    if (reduced) {
      let raf = 0;
      const center = (s: HTMLElement) => s.offsetLeft + s.offsetWidth / 2;
      const closest = () => {
        const mid = track.scrollLeft + track.clientWidth / 2;
        let best = 0;
        slides.forEach((s, k) => {
          if (Math.abs(center(s) - mid) < Math.abs(center(slides[best]) - mid)) best = k;
        });
        return best;
      };
      const ctx = gsap.context(() => {
        gsap.set(track, { paddingInline: `calc(50% - ${slides[0].offsetWidth / 2}px)` });
      }, root);
      const onScroll = () => {
        cancelAnimationFrame(raf);
        raf = requestAnimationFrame(() => commit(closest(), true));
      };
      track.addEventListener("scroll", onScroll, { passive: true });
      const go = (i: number) => {
        const to = clamp(0, n - 1, i);
        track.scrollTo({ left: center(slides[to]) - track.clientWidth / 2, behavior: "auto" });
        commit(to, true);
      };
      api.current = { go, step: (d) => go(active + d) };
      commit(closest(), true);
      setReady(true);
      return () => {
        cancelAnimationFrame(raf);
        track.removeEventListener("scroll", onScroll);
        api.current = null;
        ctx.revert();
        setReady(false);
      };
    }

    const state = { pos: 0 };
    let w = 0;
    let step = 0;
    let drag: Draggable | undefined;
    const proxy = document.createElement("div");

    const measure = () => {
      w = slides[0].offsetWidth;
      step = w * 0.62;
      return Math.max(...slides.map((s) => s.offsetHeight));
    };

    const layout = () => {
      slides.forEach((s, k) => {
        const o = k - state.pos;
        const a = Math.abs(o);
        const x = Math.sign(o) * (Math.min(a, 1) * 0.62 + Math.max(a - 1, 0) * 0.3) * w;
        gsap.set(s, {
          x,
          z: -Math.min(a, 4) * 150,
          rotationY: -clamp(-1, 1, o) * 50,
          zIndex: 100 - Math.round(a * 10),
          autoAlpha: clamp(0, 1, 3.6 - a),
        });
        const shade = s.querySelector("[data-shade]");
        const caption = s.querySelector("[data-caption]");
        if (shade) gsap.set(shade, { opacity: clamp(0, 0.62, a * 0.32) });
        if (caption) gsap.set(caption, { autoAlpha: clamp(0, 1, 1 - a * 2.2) });
      });
      commit(clamp(0, n - 1, Math.round(state.pos)), false);
    };

    const fromDrag = () => {
      if (!drag || !step) return;
      state.pos = -drag.x / step;
      layout();
    };

    const ctx = gsap.context(() => {
      const height = measure();
      gsap.set(track, { position: "relative", display: "block", overflow: "visible", scrollSnapType: "none", height, perspective: 1600 });
      gsap.set(slides, { position: "absolute", top: 0, left: "50%", xPercent: -50, force3D: true });
      layout();
      drag = Draggable.create(proxy, {
        type: "x",
        trigger: track,
        inertia: true,
        edgeResistance: 0.8,
        bounds: { minX: -(n - 1) * step, maxX: 0 },
        snap: (v: number) => -Math.round(clamp(0, n - 1, -v / step)) * step,
        onPress: () => {
          gsap.killTweensOf(state);
          gsap.set(proxy, { x: -state.pos * step });
          drag?.update();
        },
        onDrag: fromDrag,
        onThrowUpdate: fromDrag,
        onClick: (e: PointerEvent) => {
          const hit = (e.target as Element | null)?.closest?.("[data-slide]");
          const k = hit ? slides.indexOf(hit as HTMLElement) : -1;
          if (k >= 0 && k !== active) go(k);
        },
      })[0];
    }, root);

    const go = (i: number) => {
      const to = clamp(0, n - 1, i);
      ctx.add(() => {
        gsap.to(state, {
          pos: to,
          duration: 0.95,
          ease: "expo.out",
          overwrite: true,
          onUpdate: layout,
        });
      });
    };

    const onResize = () => {
      gsap.set(track, { height: measure() });
      drag?.applyBounds({ minX: -(n - 1) * step, maxX: 0 });
      layout();
    };
    window.addEventListener("resize", onResize);

    api.current = { go, step: (d) => go(Math.round(state.pos) + d) };
    setReady(true);

    return () => {
      window.removeEventListener("resize", onResize);
      api.current = null;
      drag?.kill();
      ctx.revert();
      slides.forEach((s) => (s.inert = false));
      setReady(false);
    };
  }, [count, many]);

  const onKeyDown = (e: KeyboardEvent<HTMLDivElement>) => {
    const keys: Record<string, () => void> = {
      ArrowRight: () => api.current?.step(1),
      ArrowLeft: () => api.current?.step(-1),
      Home: () => api.current?.go(0),
      End: () => api.current?.go(count - 1),
    };
    const run = keys[e.key];
    if (!run || !api.current) return;
    e.preventDefault();
    run();
  };

  const btn =
    "group inline-flex size-11 items-center justify-center rounded-full bg-white/10 text-white ring-1 ring-white/20 transition ring-inset hover:bg-white hover:text-neutral-950 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-300 aria-disabled:pointer-events-none aria-disabled:opacity-35";

  return (
    <div ref={rootRef} role="region" aria-roledescription="carousel" aria-label={label} onKeyDown={onKeyDown} className="relative">
      <div
        ref={trackRef}
        tabIndex={many ? 0 : undefined}
        className={`relative flex snap-x snap-mandatory gap-6 overflow-x-auto overscroll-x-contain pb-4 focus-visible:rounded-2xl focus-visible:outline-2 focus-visible:outline-offset-8 focus-visible:outline-indigo-300 ${many ? "" : "justify-center"}`}
      >
        {children}
      </div>
      {many ? (
        <div hidden={!ready} className="mt-10 sm:mt-12">
          <div className="flex items-center justify-center gap-6">
            <button type="button" onClick={() => api.current?.step(-1)} aria-label="Previous card" aria-disabled={index === 0 ? "true" : undefined} className={btn}>
              <svg aria-hidden="true" viewBox="0 0 20 20" fill="currentColor" className="size-5 transition group-hover:-translate-x-0.5">
                <path fillRule="evenodd" d="M11.78 5.22a.75.75 0 0 1 0 1.06L8.06 10l3.72 3.72a.75.75 0 1 1-1.06 1.06l-4.25-4.25a.75.75 0 0 1 0-1.06l4.25-4.25a.75.75 0 0 1 1.06 0Z" clipRule="evenodd" />
              </svg>
            </button>
            <p aria-hidden="true" className="w-20 text-center text-sm text-neutral-400 tabular-nums">
              <span className="text-base font-semibold text-white">{pad(index + 1)}</span> / {pad(count)}
            </p>
            <button type="button" onClick={() => api.current?.step(1)} aria-label="Next card" aria-disabled={index === count - 1 ? "true" : undefined} className={btn}>
              <svg aria-hidden="true" viewBox="0 0 20 20" fill="currentColor" className="size-5 transition group-hover:translate-x-0.5">
                <path fillRule="evenodd" d="M8.22 5.22a.75.75 0 0 1 1.06 0l4.25 4.25a.75.75 0 0 1 0 1.06l-4.25 4.25a.75.75 0 0 1-1.06-1.06L11.94 10 8.22 6.28a.75.75 0 0 1 0-1.06Z" clipRule="evenodd" />
              </svg>
            </button>
          </div>
          <p className="mt-4 hidden text-center text-xs tracking-widest text-neutral-400 uppercase sm:block">Drag, swipe or use the arrow keys</p>
          <p className="sr-only" aria-live="polite" aria-atomic="true">
            {message}
          </p>
        </div>
      ) : null}
    </div>
  );
}
```
