# Add the "Logo Marquee" block to this P1 project

Add a Puck component from P1 Blocks (https://p1-blocks.prolificdigital.io/blocks/logo-marquee) to this Pantheon Content Publisher (P1) Next.js project. An endless, slow-drifting row of partner logos that eases to a stop on hover, focus or its Pause button.

## 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/logo-marquee-block.tsx`, `components/puck/logo-marquee.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 { logoMarqueeBlock } from "./components/puck/logo-marquee-block";`
4. Register it under `components` as `LogoMarqueeBlock: logoMarqueeBlock`.
5. Add `"LogoMarqueeBlock"` 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/logo-marquee-block.tsx`

```tsx
import type { ComponentConfig } from "@puckeditor/core";
import { LogoMarqueeTrack } from "./logo-marquee.client";

/**
 * Logo Marquee — an endless, slow-drifting row of funder and partner logos (GSAP), with a
 * visible Pause button and a stop on hover or focus. Reduced-motion visitors and no-JS
 * visitors get a still, wrapped or swipeable list. Needs `pnpm add gsap` and the companion
 * logo-marquee.client.tsx file. Register: `LogoMarqueeBlock: logoMarqueeBlock` in puck.config.tsx.
 */

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

export type LogoMarqueeProps = {
  heading: string;
  headingLevel: Heading;
  intro: string;
  partners: { name: string; logoUrl: string; href: string }[];
  speed: "slow" | "medium" | "fast";
  direction: "left" | "right";
};

const SPEEDS: Record<LogoMarqueeProps["speed"], number> = { slow: 28, medium: 44, fast: 68 };

// Typeset wordmarks with a small glyph each, so the row looks finished before artwork arrives.
const wordmarkStyles = [
  "font-serif text-xl font-medium italic tracking-tight",
  "text-sm font-bold tracking-widest uppercase",
  "text-lg font-semibold tracking-tight",
  "font-serif text-base font-semibold tracking-wider uppercase",
  "text-lg font-light tracking-wide",
  "text-base font-black tracking-tight uppercase",
];

const glyphs = [
  <circle key="c" cx="8" cy="8" r="6" />,
  <path key="d" d="M8 1 15 8 8 15 1 8Z" />,
  <path key="t" d="M8 2 15 14H1Z" />,
  <path key="l" d="M2 14C2 7 7 2 14 2c0 7-5 12-12 12Z" />,
  <path key="s" d="M3 3h10v10H3Z" />,
  <path key="w" d="M1 11c2.3-3 4.7-3 7 0s4.7 3 7 0V6c-2.3 3-4.7 3-7 0S3.3 3 1 6Z" />,
];

export const logoMarqueeBlock: ComponentConfig<LogoMarqueeProps> = {
  label: "Logo Marquee",
  fields: {
    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", metadata: { help: "Optional sentence under the heading. Leave blank to hide it." } },
    partners: {
      type: "array",
      label: "Partners",
      min: 1,
      max: 24,
      getItemSummary: (item) => item?.name?.slice(0, 48) || "Partner",
      defaultItemProps: { name: "Partner name", logoUrl: "", href: "" },
      arrayFields: {
        name: { type: "text", label: "Name", metadata: { help: "Used as the logo's alt text, or shown as a wordmark when there's no logo." } },
        logoUrl: { type: "text", label: "Logo URL", metadata: { help: "A wide logo (SVG or transparent PNG) works best. Leave blank to show the name as text." } },
        href: { type: "text", label: "Link", metadata: { help: "Optional partner website. Leave blank for no link." } },
      },
    },
    speed: {
      type: "radio",
      label: "Speed",
      options: [
        { label: "Slow", value: "slow" },
        { label: "Medium", value: "medium" },
        { label: "Fast", value: "fast" },
      ],
      metadata: { help: "Visitors who ask their device for reduced motion always see a still list." },
    },
    direction: {
      type: "radio",
      label: "Direction",
      options: [
        { label: "Right to left", value: "left" },
        { label: "Left to right", value: "right" },
      ],
    },
  },
  defaultProps: {
    heading: "Made possible by our partners",
    headingLevel: "h2",
    intro: "Foundations, businesses and public agencies that fund our year-round programs.",
    partners: [
      { name: "Riverbend Community Foundation", logoUrl: "", href: "" },
      { name: "Hollis Family Trust", logoUrl: "", href: "" },
      { name: "Northfield Arts Council", logoUrl: "", href: "" },
      { name: "Greenway Fund", logoUrl: "", href: "" },
      { name: "Marlow & Vance", logoUrl: "", href: "" },
      { name: "Cedar Valley Credit Union", logoUrl: "", href: "" },
      { name: "Office of Neighborhoods", logoUrl: "", href: "" },
      { name: "Lantern Health", logoUrl: "", href: "" },
    ],
    speed: "slow",
    direction: "left",
  },
  render: ({ id, heading, headingLevel, intro, partners, speed, direction }) => {
    const H = headingLevel || "h2";
    const list = (partners ?? []).filter((p) => p?.name || p?.logoUrl);
    const headingId = `${id}-heading`;
    const hasHeader = Boolean(heading || intro);

    const items = (
      <ul
        role="list"
        className="flex shrink-0 items-center gap-x-12 pr-12 sm:gap-x-16 sm:pr-16 motion-reduce:w-full motion-reduce:shrink motion-reduce:flex-wrap motion-reduce:justify-center motion-reduce:gap-y-6 motion-reduce:pr-0"
      >
        {list.map((partner, i) => {
          const style = i % wordmarkStyles.length;
          const mark = partner.logoUrl ? (
            <img
              src={partner.logoUrl}
              alt={partner.name || ""}
              draggable={false}
              className="h-8 w-auto max-w-36 object-contain opacity-70 grayscale transition group-hover:opacity-100 group-hover:grayscale-0 sm:h-9"
            />
          ) : (
            <span className={`inline-flex items-center gap-2.5 whitespace-nowrap text-neutral-500 transition-colors group-hover:text-neutral-950 ${wordmarkStyles[style]}`}>
              <svg aria-hidden="true" viewBox="0 0 16 16" fill="currentColor" className="size-4 shrink-0">
                {glyphs[i % glyphs.length]}
              </svg>
              {partner.name}
            </span>
          );
          return (
            <li key={`${partner.name}-${i}`} className="flex shrink-0 snap-start">
              {partner.href ? (
                <a
                  href={partner.href}
                  className="group inline-flex min-h-11 items-center rounded-md px-1 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600"
                >
                  {mark}
                </a>
              ) : (
                <span className="group inline-flex min-h-11 items-center px-1">{mark}</span>
              )}
            </li>
          );
        })}
      </ul>
    );

    return (
      <section aria-labelledby={heading ? headingId : undefined} className="overflow-hidden bg-white px-4 py-16 sm:px-6 sm:py-20 lg:px-8 lg:py-24">
        <div className="mx-auto max-w-7xl">
          {hasHeader ? (
            <div className="mx-auto max-w-2xl text-center">
              {heading ? (
                <H id={headingId} className="text-base font-semibold tracking-widest text-balance text-neutral-950 uppercase sm:text-lg">
                  {heading}
                </H>
              ) : null}
              {intro ? <p className="mt-3 text-base leading-7 text-pretty text-neutral-600">{intro}</p> : null}
            </div>
          ) : null}
          {list.length > 0 ? (
            <div className={hasHeader ? "mt-8 sm:mt-10" : ""}>
              <LogoMarqueeTrack count={list.length} pxPerSecond={SPEEDS[speed] ?? SPEEDS.slow} direction={direction === "right" ? "right" : "left"}>
                {items}
              </LogoMarqueeTrack>
            </div>
          ) : null}
        </div>
      </section>
    );
  },
};
```

## File: `components/puck/logo-marquee.client.tsx`

```tsx
"use client";

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

/**
 * Motion half of the Logo Marquee. The partner list arrives server-rendered as children; this
 * island repeats it (aria-hidden, inert) enough times to loop seamlessly and drifts the row
 * with a linear GSAP tween that eases to a stop on hover, focus, or the Pause button.
 * Reduced motion never mounts any of it: the CSS wraps the list into a still grid.
 */

export type LogoMarqueeTrackProps = {
  children: ReactNode;
  count: number;
  pxPerSecond: number;
  direction: "left" | "right";
};

export function LogoMarqueeTrack({ children, count, pxPerSecond, direction }: LogoMarqueeTrackProps) {
  const rootRef = useRef<HTMLDivElement>(null);
  const viewportRef = useRef<HTMLDivElement>(null);
  const trackRef = useRef<HTMLDivElement>(null);
  const userPausedRef = useRef(false);
  const applyRef = useRef<(() => void) | null>(null);
  const [enhanced, setEnhanced] = useState(false);
  const [copies, setCopies] = useState(2);
  const [userPaused, setUserPaused] = useState(false);

  useEffect(() => {
    // A single logo has nothing to loop; leave it still.
    setEnhanced(count > 1 && !window.matchMedia("(prefers-reduced-motion: reduce)").matches);
  }, [count]);

  useLayoutEffect(() => {
    const root = rootRef.current;
    const viewport = viewportRef.current;
    const track = trackRef.current;
    const set = track?.firstElementChild as HTMLElement | null | undefined;
    if (!enhanced || !root || !viewport || !track || !set) return;

    let hovered = false;
    let focused = false;
    let onScreen = true;
    let tween: gsap.core.Tween | undefined;

    const ctx = gsap.context(() => {}, root);

    const build = ctx.add("build", () => {
      const width = set.offsetWidth;
      if (!width) return;
      // Enough copies that the row never shows a gap, even on an ultrawide screen.
      const needed = Math.ceil(viewport.clientWidth / width) + 1;
      if (needed !== copies) {
        setCopies(needed);
        return;
      }
      const progress = tween?.progress() ?? 0;
      tween?.kill();
      const from = direction === "right" ? -width : 0;
      tween = gsap.fromTo(
        track,
        { x: from },
        { x: from === 0 ? -width : 0, duration: width / Math.max(pxPerSecond, 1), ease: "none", repeat: -1 },
      );
      tween.progress(progress);
      apply(true);
    }) as () => void;

    // Glide to a stop and back up to speed rather than freezing mid-frame.
    const apply = ctx.add("apply", (instant = false) => {
      if (!tween) return;
      const moving = !userPausedRef.current && !hovered && !focused;
      tween.paused(!onScreen);
      gsap.to(tween, { timeScale: moving ? 1 : 0, duration: instant ? 0 : moving ? 0.9 : 0.6, ease: moving ? "power2.in" : "power2.out", overwrite: true });
    }) as (instant?: boolean) => void;

    applyRef.current = () => apply();
    build();

    const onEnter = () => ((hovered = true), apply());
    const onLeave = () => ((hovered = false), apply());
    const onFocusIn = () => ((focused = true), apply());
    const onFocusOut = (e: FocusEvent) => {
      if (viewport.contains(e.relatedTarget as Node | null)) return;
      focused = false;
      apply();
    };
    viewport.addEventListener("pointerenter", onEnter);
    viewport.addEventListener("pointerleave", onLeave);
    viewport.addEventListener("focusin", onFocusIn);
    viewport.addEventListener("focusout", onFocusOut);

    const io = new IntersectionObserver(([entry]) => {
      onScreen = Boolean(entry?.isIntersecting) && !document.hidden;
      apply(true);
    });
    io.observe(viewport);
    const onVisibility = () => {
      onScreen = !document.hidden;
      apply(true);
    };
    document.addEventListener("visibilitychange", onVisibility);

    let lastWidth = viewport.clientWidth;
    const ro = new ResizeObserver(() => {
      if (Math.abs(viewport.clientWidth - lastWidth) < 1) return;
      lastWidth = viewport.clientWidth;
      build();
    });
    ro.observe(viewport);

    return () => {
      ro.disconnect();
      io.disconnect();
      document.removeEventListener("visibilitychange", onVisibility);
      viewport.removeEventListener("pointerenter", onEnter);
      viewport.removeEventListener("pointerleave", onLeave);
      viewport.removeEventListener("focusin", onFocusIn);
      viewport.removeEventListener("focusout", onFocusOut);
      applyRef.current = null;
      ctx.revert();
    };
  }, [enhanced, copies, pxPerSecond, direction]);

  const toggle = () => {
    userPausedRef.current = !userPausedRef.current;
    setUserPaused(userPausedRef.current);
    applyRef.current?.();
  };

  return (
    <div ref={rootRef}>
      {enhanced ? (
        <div className="mb-4 flex justify-end">
          <button
            type="button"
            onClick={toggle}
            className="inline-flex min-h-11 items-center gap-2 rounded-full px-4 text-sm font-medium text-neutral-700 ring-1 ring-neutral-300 transition-colors ring-inset hover:bg-neutral-100 hover:text-neutral-950 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600"
          >
            {userPaused ? (
              <svg aria-hidden="true" viewBox="0 0 16 16" fill="currentColor" className="size-3.5">
                <path d="M4.5 2.8v10.4a.6.6 0 0 0 .9.5l8.3-5.2a.6.6 0 0 0 0-1L5.4 2.3a.6.6 0 0 0-.9.5Z" />
              </svg>
            ) : (
              <svg aria-hidden="true" viewBox="0 0 16 16" fill="currentColor" className="size-3.5">
                <rect x="3.5" y="2.5" width="3" height="11" rx="0.75" />
                <rect x="9.5" y="2.5" width="3" height="11" rx="0.75" />
              </svg>
            )}
            {userPaused ? "Play" : "Pause"}
            <span className="sr-only"> scrolling logos</span>
          </button>
        </div>
      ) : null}
      <div className="relative">
        <div
          ref={viewportRef}
          className={
            enhanced
              ? "overflow-hidden py-2"
              : "snap-x snap-mandatory relative overflow-x-auto overscroll-x-contain py-2 motion-reduce:overflow-visible"
          }
        >
          <div ref={trackRef} className={enhanced ? "flex w-max will-change-transform" : "flex"}>
            {children}
            {enhanced
              ? Array.from({ length: copies - 1 }, (_, i) => (
                  <div key={i} aria-hidden="true" inert className="flex shrink-0">
                    {children}
                  </div>
                ))
              : null}
          </div>
        </div>
        {enhanced ? (
          <>
            <div aria-hidden="true" className="pointer-events-none absolute inset-y-0 left-0 w-12 bg-linear-to-r from-white to-transparent sm:w-32" />
            <div aria-hidden="true" className="pointer-events-none absolute inset-y-0 right-0 w-12 bg-linear-to-l from-white to-transparent sm:w-32" />
          </>
        ) : null}
      </div>
    </div>
  );
}
```
