# Add the "Hero Slideshow" block to this P1 project

Add a Puck component from P1 Blocks (https://p1-blocks.prolificdigital.io/blocks/hero-slideshow) to this Pantheon Content Publisher (P1) Next.js project. Full-bleed photo slides that crossfade with a slow Ken Burns push, staggered copy, a counter and optional pausable rotation.

## 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/hero-slideshow-block.tsx`, `components/puck/hero-slideshow.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 { heroSlideshowBlock } from "./components/puck/hero-slideshow-block";`
4. Register it under `components` as `HeroSlideshowBlock: heroSlideshowBlock`.
5. Add `"HeroSlideshowBlock"` 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/hero-slideshow-block.tsx`

```tsx
import type { ComponentConfig } from "@puckeditor/core";
import { HeroSlideshowStage } from "./hero-slideshow.client";

/**
 * Hero Slideshow — full-bleed photo slides that crossfade with a slow Ken Burns push and
 * staggered copy. Swipeable without JavaScript; GSAP adds the transitions, counter and
 * optional rotation. Needs `pnpm add gsap` and the companion hero-slideshow.client.tsx.
 * Register: `HeroSlideshowBlock: heroSlideshowBlock` in puck.config.tsx.
 */

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

type Slide = {
  imageUrl: string;
  imageAlt: string;
  eyebrow: string;
  heading: string;
  body: string;
  ctaLabel: string;
  ctaHref: string;
};

export type HeroSlideshowProps = {
  label: string;
  slides: Slide[];
  headingLevel: Heading;
  autoplay: "off" | "on";
  interval: "5" | "7" | "10";
  height: "tall" | "screen";
};

const HEIGHTS: Record<HeroSlideshowProps["height"], string> = {
  tall: "min-h-[36rem] sm:min-h-[40rem]",
  screen: "min-h-svh",
};

export const heroSlideshowBlock: ComponentConfig<HeroSlideshowProps> = {
  label: "Hero Slideshow",
  fields: {
    label: {
      type: "text",
      label: "Slideshow name",
      metadata: { help: "Read aloud by screen readers, e.g. \"Featured stories\". Not shown on the page." },
    },
    slides: {
      type: "array",
      label: "Slides",
      min: 1,
      max: 8,
      getItemSummary: (item) => item?.heading || "Slide",
      defaultItemProps: {
        imageUrl: "https://picsum.photos/seed/meadow/1920/1080",
        imageAlt: "",
        eyebrow: "New this season",
        heading: "A headline that earns the scroll",
        body: "One or two sentences that tell people why this matters and what to do next.",
        ctaLabel: "Learn more",
        ctaHref: "#",
      },
      arrayFields: {
        imageUrl: { type: "text", label: "Image URL", metadata: { help: "A wide photo, at least 1920px across. The bottom of it sits behind the text." } },
        imageAlt: { type: "text", label: "Image description", metadata: { help: "Describe the photo for people who can't see it. Leave blank if it's purely decorative." } },
        eyebrow: { type: "text", label: "Eyebrow", metadata: { help: "Small line above the heading. Leave blank to hide it." } },
        heading: { type: "textarea", label: "Heading" },
        body: { type: "textarea", label: "Body" },
        ctaLabel: { type: "text", label: "Button text", metadata: { help: "Leave blank to hide the button." } },
        ctaHref: { type: "text", label: "Button link" },
      },
    },
    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." },
    },
    autoplay: {
      type: "radio",
      label: "Advance on its own",
      options: [
        { label: "Off", value: "off" },
        { label: "On", value: "on" },
      ],
      metadata: { help: "When on, visitors get a pause button, and it stops while they hover or tab into it. Never rotates for people who ask their device for reduced motion." },
    },
    interval: {
      type: "select",
      label: "Time per slide",
      options: [
        { label: "5 seconds", value: "5" },
        { label: "7 seconds", value: "7" },
        { label: "10 seconds", value: "10" },
      ],
      metadata: { help: "Only used when the slideshow advances on its own. Longer is kinder to slow readers." },
    },
    height: {
      type: "select",
      label: "Height",
      options: [
        { label: "Tall", value: "tall" },
        { label: "Full screen", value: "screen" },
      ],
    },
  },
  defaultProps: {
    label: "Featured stories",
    headingLevel: "h2",
    autoplay: "off",
    interval: "7",
    height: "tall",
    slides: [
      {
        imageUrl: "https://picsum.photos/seed/riverbank/1920/1080",
        imageAlt: "Volunteers planting saplings along a muddy riverbank in early spring",
        eyebrow: "Spring Restoration Days",
        heading: "Twelve miles of river, replanted by hand",
        body: "Every Saturday in April, neighbors trade a morning for a stronger shoreline. Bring gloves; we bring the trees, the tools and the coffee.",
        ctaLabel: "Volunteer this spring",
        ctaHref: "/volunteer",
      },
      {
        imageUrl: "https://picsum.photos/seed/fieldschool/1920/1080",
        imageAlt: "A group of students kneeling at the water's edge with sampling nets",
        eyebrow: "Youth Field School",
        heading: "Teaching the next generation to read a watershed",
        body: "Six weeks outdoors for middle schoolers, with scholarships for every family that needs one. Applications close May 15.",
        ctaLabel: "Enroll a student",
        ctaHref: "/field-school",
      },
      {
        imageUrl: "https://picsum.photos/seed/opentrail/1920/1080",
        imageAlt: "A gravel trail winding through tall grass toward a stand of sycamores",
        eyebrow: "Open Lands",
        heading: "Trails that belong to everyone, every day",
        body: "No gates, no fees, no reservations. Find a loop that fits your afternoon, from a twenty-minute stroll to a full-day ridge walk.",
        ctaLabel: "Find a trail",
        ctaHref: "/trails",
      },
      {
        imageUrl: "https://picsum.photos/seed/shoreline/1920/1080",
        imageAlt: "Morning fog lifting off a quiet bend in the river",
        eyebrow: "Annual Appeal",
        heading: "Keep the river wild for the next hundred years",
        body: "Gifts from people like you protect land that can't be bought back once it's gone. Give monthly and your support goes to work right away.",
        ctaLabel: "Give to the river",
        ctaHref: "/give",
      },
    ],
  },
  render: ({ label, slides, headingLevel, autoplay, interval, height }) => {
    const H = headingLevel || "h2";
    const items = (slides ?? []).filter((s) => s && (s.heading || s.imageUrl || s.body));
    if (!items.length) return <></>;
    const minH = HEIGHTS[height] ?? HEIGHTS.tall;
    const many = items.length > 1;
    return (
      <section className="relative isolate bg-neutral-950">
        <HeroSlideshowStage count={items.length} label={label || "Featured stories"} autoplay={autoplay === "on"} interval={Number(interval) || 7}>
          {items.map((slide, i) => (
            <div
              key={i}
              data-slide=""
              role={many ? "group" : undefined}
              aria-roledescription={many ? "slide" : undefined}
              aria-label={many ? `${i + 1} of ${items.length}` : undefined}
              className={`relative isolate flex w-full shrink-0 snap-start items-end overflow-hidden bg-neutral-900 ${minH}`}
            >
              {slide.imageUrl ? (
                <img data-media="" src={slide.imageUrl} alt={slide.imageAlt || ""} draggable={false} className="absolute inset-0 -z-10 size-full object-cover" />
              ) : null}
              <div aria-hidden="true" className="absolute inset-0 -z-10 bg-gradient-to-t from-neutral-950/95 via-neutral-950/50 to-neutral-950/10" />
              <div aria-hidden="true" className="absolute inset-0 -z-10 bg-gradient-to-r from-neutral-950/60 via-neutral-950/20 to-transparent" />
              <div className={`mx-auto w-full max-w-7xl px-4 pt-32 sm:px-6 lg:px-8 ${many ? "pb-32 sm:pb-36" : "pb-16 sm:pb-20 lg:pb-24"}`}>
                <div className="max-w-3xl">
                  {slide.eyebrow ? (
                    <p data-reveal="" className="flex items-center gap-3 text-xs font-semibold tracking-widest text-indigo-200 uppercase sm:text-sm">
                      <span aria-hidden="true" className="h-px w-8 bg-indigo-300" />
                      {slide.eyebrow}
                    </p>
                  ) : null}
                  {slide.heading ? (
                    <H data-reveal="" data-title="" className="mt-5 text-4xl leading-none font-semibold tracking-tight text-balance text-white sm:text-6xl lg:text-7xl">
                      {slide.heading}
                    </H>
                  ) : null}
                  {slide.body ? (
                    <p data-reveal="" className="mt-6 max-w-xl text-base leading-7 text-pretty text-white/85 sm:text-lg sm:leading-8">
                      {slide.body}
                    </p>
                  ) : null}
                  {slide.ctaLabel ? (
                    <div data-reveal="" className="mt-9">
                      <a
                        href={slide.ctaHref || "#"}
                        className="group inline-flex min-h-11 items-center gap-2 rounded-full bg-white py-3 pr-4 pl-6 text-base font-semibold text-neutral-950 shadow-sm transition hover:bg-indigo-50 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-white"
                      >
                        {slide.ctaLabel}
                        <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="M3 10a.75.75 0 0 1 .75-.75h10.64l-3.22-3.22a.75.75 0 1 1 1.06-1.06l4.5 4.5a.75.75 0 0 1 0 1.06l-4.5 4.5a.75.75 0 1 1-1.06-1.06l3.22-3.22H3.75A.75.75 0 0 1 3 10Z" clipRule="evenodd" />
                        </svg>
                      </a>
                    </div>
                  ) : null}
                </div>
              </div>
            </div>
          ))}
        </HeroSlideshowStage>
      </section>
    );
  },
};
```

## File: `components/puck/hero-slideshow.client.tsx`

```tsx
"use client";

import { useEffect, useLayoutEffect, useRef, useState } from "react";
import type { FocusEvent, KeyboardEvent, PointerEvent, ReactNode } from "react";
import { gsap } from "gsap";

/**
 * Motion half of the Hero Slideshow. The slides arrive server-rendered as a CSS scroll-snap
 * strip; once mounted this stacks them, crossfades with a slow Ken Burns push, staggers each
 * slide's copy in, and adds the counter, progress segments and optional rotation.
 */

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

type Api = {
  go: (index: number, dir?: number) => void;
  step: (delta: number) => void;
  toggle: () => void;
  hold: (reason: "hover" | "focus", on: boolean) => void;
};

type HeroSlideshowStageProps = {
  count: number;
  label: string;
  autoplay: boolean;
  interval: number;
  children: ReactNode;
};

const pad = (n: number) => String(n).padStart(2, "0");

export function HeroSlideshowStage({ count, label, autoplay, interval, children }: HeroSlideshowStageProps) {
  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 [canRotate, setCanRotate] = useState(false);
  const [playing, setPlaying] = useState(false);
  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 rotates = autoplay && !reduced;
    const seconds = Math.max(3, interval || 7);
    const media = (s: HTMLElement) => s.querySelector<HTMLElement>("[data-media]");
    const reveals = (s: HTMLElement) => Array.from(s.querySelectorAll<HTMLElement>("[data-reveal]"));
    const fills = () => Array.from(root.querySelectorAll<HTMLElement>("[data-fill]"));
    const title = (s: HTMLElement) => s.querySelector("[data-title]")?.textContent?.trim();

    // Honor wherever someone had already swiped to before hydration.
    let current = Math.min(n - 1, Math.max(0, Math.round(track.scrollLeft / Math.max(1, track.clientWidth))));
    let rotating = rotates;
    let hover = false;
    let focus = false;
    let timer: gsap.core.Tween | null = null;

    const ctx = gsap.context(() => {
      gsap.set(track, { display: "grid", gridTemplateColumns: "minmax(0, 1fr)", overflow: "hidden", scrollSnapType: "none" });
      slides.forEach((s, k) => gsap.set(s, { gridArea: "1 / 1", zIndex: k === current ? 2 : 0, autoAlpha: k === current ? 1 : 0 }));
      const m = media(slides[current]);
      if (m && !reduced) gsap.to(m, { scale: 1.08, xPercent: -1, duration: seconds + 8, ease: "sine.out" });
    }, root);
    slides.forEach((s, k) => (s.inert = k !== current));
    track.scrollLeft = 0;

    const held = () => hover || focus;

    // The active progress segment doubles as the rotation timer.
    const arm = () =>
      ctx.add(() => {
        timer?.kill();
        timer = null;
        fills().forEach((f, k) => {
          gsap.killTweensOf(f);
          gsap.set(f, { scaleX: k === current && !rotating ? 1 : 0, transformOrigin: "0% 50%" });
        });
        const fill = fills()[current];
        if (!rotating || !fill) return;
        timer = gsap.to(fill, { scaleX: 1, duration: seconds, ease: "none", paused: held(), onComplete: () => go(current + 1, 1) });
      });

    const go = (target: number, dir?: number) => {
      const to = ((target % n) + n) % n;
      if (to === current) return;
      const from = current;
      const d = dir ?? (to > from ? 1 : -1);
      current = to;
      const incoming = slides[to];
      const outgoing = slides[from];

      ctx.add(() => {
        slides.forEach((s, k) => {
          s.inert = k !== to;
          if (k === to || k === from) return;
          gsap.killTweensOf(s);
          gsap.set(s, { autoAlpha: 0, zIndex: 0 });
        });
        gsap.killTweensOf([incoming, outgoing]);
        gsap.set(outgoing, { zIndex: 1 });
        gsap.set(incoming, { zIndex: 2 });
        const inText = reveals(incoming);
        const inMedia = media(incoming);

        if (reduced) {
          gsap.set(inText, { autoAlpha: 1, y: 0, filter: "none" });
          gsap.fromTo(incoming, { autoAlpha: 0 }, { autoAlpha: 1, duration: 0.3, ease: "none", onComplete: () => gsap.set(outgoing, { autoAlpha: 0, zIndex: 0 }) });
          return;
        }

        gsap.fromTo(
          incoming,
          { autoAlpha: 0 },
          { autoAlpha: 1, duration: 1.2, ease: "power2.inOut", onComplete: () => gsap.set(outgoing, { autoAlpha: 0, zIndex: 0 }) },
        );
        if (inMedia) {
          gsap.fromTo(
            inMedia,
            { scale: 1.02, xPercent: d * 1.5 },
            { scale: 1.1, xPercent: -d * 1, duration: seconds + 8, ease: "sine.out", overwrite: true },
          );
        }
        gsap.to(reveals(outgoing), { autoAlpha: 0, y: -14, duration: 0.45, ease: "power2.in", stagger: 0.04, overwrite: true });
        gsap.fromTo(
          inText,
          { autoAlpha: 0, y: 32, filter: "blur(10px)" },
          { autoAlpha: 1, y: 0, filter: "blur(0px)", duration: 1.15, ease: "power3.out", stagger: 0.14, delay: 0.4, overwrite: true },
        );
      });

      arm();
      setIndex(to);
      const t = title(incoming);
      setMessage(`Slide ${to + 1} of ${n}${t ? `: ${t}` : ""}`);
    };

    api.current = {
      go,
      step: (delta) => go(current + delta, delta),
      toggle: () => {
        if (!rotates) return;
        rotating = !rotating;
        setPlaying(rotating);
        arm();
      },
      hold: (reason, on) => {
        if (reason === "hover") hover = on;
        else focus = on;
        if (!timer) return;
        if (held()) timer.pause();
        else timer.resume();
      },
    };

    arm();
    setIndex(current);
    setCanRotate(rotates);
    setPlaying(rotates);
    setReady(true);

    return () => {
      timer = null;
      api.current = null;
      ctx.revert();
      slides.forEach((s) => (s.inert = false));
      setReady(false);
    };
  }, [count, autoplay, interval, many]);

  const onKeyDown = (e: KeyboardEvent<HTMLDivElement>) => {
    // Leave arrow keys alone inside a slide, so focus never lands in a slide that's fading out.
    if ((e.target as HTMLElement).closest("[data-slide]")) return;
    if (e.key === "ArrowRight") api.current?.step(1);
    else if (e.key === "ArrowLeft") api.current?.step(-1);
    else return;
    e.preventDefault();
  };
  const onPointer = (on: boolean) => (e: PointerEvent<HTMLDivElement>) => {
    if (e.pointerType === "mouse") api.current?.hold("hover", on);
  };
  const onFocus = (e: FocusEvent<HTMLDivElement>) => {
    if ((e.target as HTMLElement).matches(":focus-visible")) api.current?.hold("focus", true);
  };
  const onBlur = (e: FocusEvent<HTMLDivElement>) => {
    if (!e.currentTarget.contains(e.relatedTarget as Node | null)) api.current?.hold("focus", false);
  };

  const btn =
    "inline-flex size-11 shrink-0 items-center justify-center rounded-full text-white ring-1 ring-white/40 backdrop-blur-sm transition ring-inset hover:bg-white hover:text-neutral-950 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-white";

  return (
    <div
      ref={rootRef}
      role="region"
      aria-roledescription="carousel"
      aria-label={label}
      onKeyDown={onKeyDown}
      onPointerEnter={onPointer(true)}
      onPointerLeave={onPointer(false)}
      onFocus={onFocus}
      onBlur={onBlur}
      className="relative isolate overflow-hidden"
    >
      {many ? (
        <div hidden={!ready} className="pointer-events-none absolute inset-x-0 bottom-0 z-10">
          <div className="pointer-events-auto mx-auto flex max-w-7xl items-center gap-3 px-4 pb-6 sm:gap-5 sm:px-6 sm:pb-8 lg:px-8">
            {canRotate ? (
              <button type="button" onClick={() => api.current?.toggle()} aria-label={playing ? "Pause slideshow" : "Play slideshow"} className={btn}>
                {playing ? (
                  <svg aria-hidden="true" viewBox="0 0 20 20" fill="currentColor" className="size-4">
                    <path d="M5.75 3a.75.75 0 0 0-.75.75v12.5c0 .41.34.75.75.75h1.5a.75.75 0 0 0 .75-.75V3.75A.75.75 0 0 0 7.25 3h-1.5ZM12.75 3a.75.75 0 0 0-.75.75v12.5c0 .41.34.75.75.75h1.5a.75.75 0 0 0 .75-.75V3.75a.75.75 0 0 0-.75-.75h-1.5Z" />
                  </svg>
                ) : (
                  <svg aria-hidden="true" viewBox="0 0 20 20" fill="currentColor" className="size-4 translate-x-px">
                    <path d="M6.3 2.84A1.5 1.5 0 0 0 4 4.11v11.78a1.5 1.5 0 0 0 2.3 1.27l9.34-5.89a1.5 1.5 0 0 0 0-2.54L6.3 2.84Z" />
                  </svg>
                )}
              </button>
            ) : null}
            <p aria-hidden="true" className="shrink-0 text-sm font-medium text-white tabular-nums">
              <span className="text-lg font-semibold">{pad(index + 1)}</span>
              <span className="text-white/70"> / {pad(count)}</span>
            </p>
            <div className="hidden min-w-0 flex-1 items-center gap-1.5 sm:flex">
              {Array.from({ length: count }, (_, k) => (
                <button
                  key={k}
                  type="button"
                  onClick={() => api.current?.go(k)}
                  aria-label={`Show slide ${k + 1}`}
                  aria-current={k === index ? "true" : undefined}
                  className="group flex h-11 min-w-6 flex-1 items-center focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-white"
                >
                  <span className="relative h-0.5 w-full overflow-hidden rounded-full bg-white/30 transition-all group-hover:h-1">
                    <span data-fill="" className="absolute inset-0 bg-white" />
                  </span>
                </button>
              ))}
            </div>
            <div className="flex-1 sm:hidden" />
            <div className="flex shrink-0 gap-2">
              <button type="button" onClick={() => api.current?.step(-1)} aria-label="Previous slide" className={`group ${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>
              <button type="button" onClick={() => api.current?.step(1)} aria-label="Next slide" className={`group ${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>
          </div>
        </div>
      ) : null}
      <div
        ref={trackRef}
        tabIndex={many ? 0 : undefined}
        className="flex snap-x snap-mandatory relative overflow-x-auto overscroll-x-contain focus-visible:outline-2 focus-visible:-outline-offset-4 focus-visible:outline-white"
      >
        {children}
      </div>
      {many ? (
        <p className="sr-only" aria-live={canRotate && playing ? "off" : "polite"} aria-atomic="true">
          {message}
        </p>
      ) : null}
    </div>
  );
}
```
