# Add the "Caustics Pool" block to this P1 project

Add a Puck component from P1 Blocks (https://p1-blocks.prolificdigital.io/blocks/caustics-pool) to this Pantheon Content Publisher (P1) Next.js project. Aquatic center hero with shimmering pool caustics over a tiled floor, today's hours and a CTA.

## Steps

1. Install the dependency: `pnpm add vgpu` (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/caustics-pool-block.tsx`, `components/puck/caustics-pool.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 { causticsPoolBlock } from "./components/puck/caustics-pool-block";`
4. Register it under `components` as `CausticsPoolBlock: causticsPoolBlock`.
5. Add `"CausticsPoolBlock"` to the best-fitting entry in `categories` (this block's library category is "GPU effects"). 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/caustics-pool-block.tsx`

```tsx
import type { ComponentConfig } from "@puckeditor/core";
import { CausticsCanvas } from "./caustics-pool.client";

/**
 * Caustics Pool — a hero for an aquatic center or swim program: shimmering pool caustics
 * over a tiled floor (vgpu / WebGPU), with today's hours on a solid card and a clear CTA.
 * Content is server-rendered. Needs `pnpm add vgpu` and caustics-pool.client.tsx.
 * Register: `CausticsPoolBlock: causticsPoolBlock` in puck.config.tsx.
 */

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

type Hours = { label: string; hours: string };

export type CausticsPoolProps = {
  eyebrow: string;
  heading: string;
  headingLevel: Heading;
  body: string;
  primaryLabel: string;
  primaryHref: string;
  secondaryLabel: string;
  secondaryHref: string;
  hoursTitle: string;
  hours: Hours[];
  hoursNote: string;
  deepColor: string;
  waterColor: string;
  lightColor: string;
  speed: "0.5" | "1" | "1.6";
  height: "medium" | "tall" | "screen";
};

const HEX = /^#?([0-9a-f]{3}|[0-9a-f]{6})$/i;
const hex = (value: string | undefined, fallback: string) => (HEX.test((value ?? "").trim()) ? `#${value!.trim().replace(/^#/, "")}` : fallback);

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

const colorHelp = "A hex color such as #1f9ad1.";

export const causticsPoolBlock: ComponentConfig<CausticsPoolProps> = {
  label: "Caustics Pool",
  fields: {
    eyebrow: { type: "text", label: "Eyebrow", metadata: { help: "Small line above the heading. Leave blank to hide it." } },
    heading: { type: "textarea", label: "Heading" },
    headingLevel: {
      type: "select",
      label: "Heading level",
      options: [
        { label: "H1 (page title)", value: "h1" },
        { label: "H2", value: "h2" },
        { label: "H3", value: "h3" },
        { label: "H4", value: "h4" },
      ],
      metadata: { help: "Use H1 when this hero is the top of the page. The look doesn't change." },
    },
    body: { type: "textarea", label: "Body" },
    primaryLabel: { type: "text", label: "Primary button text" },
    primaryHref: { type: "text", label: "Primary button link" },
    secondaryLabel: { type: "text", label: "Secondary link text", metadata: { help: "Leave blank to hide it." } },
    secondaryHref: { type: "text", label: "Secondary link" },
    hoursTitle: { type: "text", label: "Hours card title", metadata: { help: "Leave the title and every row blank to hide the card." } },
    hours: {
      type: "array",
      label: "Hours",
      min: 0,
      max: 7,
      getItemSummary: (item) => item?.label || "Session",
      defaultItemProps: { label: "Open swim", hours: "1–4 pm" },
      arrayFields: {
        label: { type: "text", label: "Session or day" },
        hours: { type: "text", label: "Hours" },
      },
    },
    hoursNote: { type: "textarea", label: "Hours note", metadata: { help: "Closures or fine print. Leave blank to hide it." } },
    deepColor: { type: "text", label: "Deep water color", metadata: { help: `${colorHelp} Also used for the lane stripes.` } },
    waterColor: { type: "text", label: "Tile color", metadata: { help: colorHelp } },
    lightColor: { type: "text", label: "Light color", metadata: { help: `${colorHelp} The shimmering caustics.` } },
    speed: {
      type: "radio",
      label: "Motion",
      options: [
        { label: "Still water", value: "0.5" },
        { label: "Gentle", value: "1" },
        { label: "Lively", value: "1.6" },
      ],
      metadata: { help: "Visitors who ask their device for reduced motion always see a still frame." },
    },
    height: {
      type: "select",
      label: "Height",
      options: [
        { label: "Medium", value: "medium" },
        { label: "Tall", value: "tall" },
        { label: "Full screen", value: "screen" },
      ],
    },
  },
  defaultProps: {
    eyebrow: "Riverside Aquatic Center",
    heading: "Fifty meters of open water, all year round",
    headingLevel: "h1",
    body: "Lap lanes before work, swim lessons for every age, and a warm-water therapy pool. City residents swim free with a library card.",
    primaryLabel: "Register for swim lessons",
    primaryHref: "/aquatics/lessons",
    secondaryLabel: "Full schedule",
    secondaryHref: "/aquatics/schedule",
    hoursTitle: "Today's pool hours",
    hours: [
      { label: "Lap swim", hours: "5:30–8:30 am" },
      { label: "Lessons", hours: "9 am–12 pm" },
      { label: "Open swim", hours: "1–5 pm" },
      { label: "Family swim", hours: "5–7:30 pm" },
    ],
    hoursNote: "Pool closes 15 minutes before posted end times. Lifeguards on duty at all sessions.",
    deepColor: "#08456f",
    waterColor: "#1f9ad1",
    lightColor: "#ecfbff",
    speed: "1",
    height: "tall",
  },
  render: ({ eyebrow, heading, headingLevel, body, primaryLabel, primaryHref, secondaryLabel, secondaryHref, hoursTitle, hours, hoursNote, deepColor, waterColor, lightColor, speed, height }) => {
    const H = headingLevel || "h1";
    const deep = hex(deepColor, "#08456f");
    const water = hex(waterColor, "#1f9ad1");
    const light = hex(lightColor, "#ecfbff");
    const rows = (hours ?? []).filter((r) => r?.label || r?.hours);
    const showCard = Boolean(hoursTitle || rows.length);
    // The CSS fallback approximates the shader: a tiled floor with a few soft glints of light.
    const fallback = {
      backgroundColor: water,
      backgroundImage: [
        `radial-gradient(30% 18% at 30% 70%, ${light}40, transparent 70%)`,
        `radial-gradient(25% 15% at 75% 30%, ${light}33, transparent 70%)`,
        "repeating-linear-gradient(0deg, rgba(0,0,0,0.12) 0 1px, transparent 1px 40px)",
        "repeating-linear-gradient(90deg, rgba(0,0,0,0.12) 0 1px, transparent 1px 40px)",
        `linear-gradient(to bottom, ${deep}, ${water})`,
      ].join(", "),
    };
    return (
      <section className={`relative isolate flex items-end overflow-hidden ${HEIGHTS[height] ?? HEIGHTS.tall}`} style={fallback}>
        <CausticsCanvas colors={{ deep, water, light }} speed={Number(speed) || 1} />
        <div aria-hidden="true" className="pointer-events-none absolute inset-0 bg-neutral-950/60 lg:bg-transparent lg:bg-gradient-to-r lg:from-neutral-950/80 lg:via-neutral-950/60 lg:to-neutral-950/10" />
        <div className="relative mx-auto grid w-full max-w-7xl grid-cols-1 items-end gap-10 px-4 pt-32 pb-16 sm:px-6 sm:pb-20 lg:grid-cols-12 lg:gap-8 lg:px-8 lg:pb-24">
          <div className="lg:col-span-7">
            {eyebrow ? (
              <p className="flex items-center gap-3 text-sm font-semibold tracking-[0.2em] text-white/85 uppercase">
                <svg aria-hidden="true" viewBox="0 0 24 8" fill="none" stroke="currentColor" strokeWidth="1.5" className="h-2 w-6">
                  <path d="M0 4c3 0 3-3 6-3s3 3 6 3 3-3 6-3 3 3 6 3" />
                </svg>
                {eyebrow}
              </p>
            ) : null}
            {heading ? <H className="mt-5 text-4xl font-semibold tracking-tight text-balance text-white sm:text-6xl lg:text-7xl">{heading}</H> : null}
            {body ? <p className="mt-6 max-w-xl text-lg leading-8 text-pretty text-white/90">{body}</p> : null}
            {primaryLabel || secondaryLabel ? (
              <div className="mt-10 flex flex-col gap-3 sm:flex-row sm:items-center sm:gap-6">
                {primaryLabel ? (
                  <a
                    href={primaryHref || "#"}
                    className="inline-flex min-h-11 items-center justify-center rounded-full bg-white px-6 py-3 text-base font-semibold text-neutral-950 shadow-sm transition hover:bg-white/90 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-white"
                  >
                    {primaryLabel}
                  </a>
                ) : null}
                {secondaryLabel ? (
                  <a
                    href={secondaryHref || "#"}
                    className="group inline-flex min-h-11 items-center justify-center gap-1.5 rounded-full px-1 text-base font-semibold text-white underline decoration-white/40 underline-offset-4 hover:decoration-white focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-white"
                  >
                    {secondaryLabel}
                  </a>
                ) : null}
              </div>
            ) : null}
          </div>
          {showCard ? (
            <div className="rounded-2xl bg-white p-6 shadow-2xl ring-1 ring-neutral-950/5 sm:p-8 lg:col-span-5 lg:col-start-8">
              {hoursTitle ? (
                <p className="flex items-center gap-2 text-sm font-semibold tracking-wide text-neutral-950 uppercase">
                  <svg aria-hidden="true" viewBox="0 0 20 20" fill="currentColor" className="size-5 text-indigo-600">
                    <path fillRule="evenodd" d="M10 18a8 8 0 1 0 0-16 8 8 0 0 0 0 16Zm.75-13a.75.75 0 0 0-1.5 0v5c0 .2.08.39.22.53l3 3a.75.75 0 1 0 1.06-1.06l-2.78-2.78V5Z" clipRule="evenodd" />
                  </svg>
                  {hoursTitle}
                </p>
              ) : null}
              {rows.length ? (
                <dl className="mt-4 divide-y divide-neutral-200">
                  {rows.map((r, i) => (
                    <div key={i} className="flex items-baseline justify-between gap-4 py-3">
                      <dt className="text-base text-neutral-700">{r.label}</dt>
                      <dd className="text-base font-semibold text-neutral-950 tabular-nums">{r.hours}</dd>
                    </div>
                  ))}
                </dl>
              ) : null}
              {hoursNote ? <p className="mt-4 text-sm leading-6 text-neutral-600">{hoursNote}</p> : null}
            </div>
          ) : null}
        </div>
      </section>
    );
  },
};
```

## File: `components/puck/caustics-pool.client.tsx`

```tsx
"use client";

import { useEffect, useRef, useState } from "react";
import { clock, effect, frame, frameLoop, init, surface } from "vgpu";
import type { FrameLoopHandle } from "vgpu";

/**
 * GPU half of the Caustics Pool: shimmering pool caustics dancing over a tiled floor with
 * lane stripes, gently refracted by the moving surface (vgpu / WebGPU). Decorative only.
 * The hero's content is server-rendered and the CSS fallback underneath is the final look
 * wherever WebGPU isn't available.
 */

const CAUSTICS_WGSL = /* wgsl */ `
struct Params {
  time: f32,
  aspect: f32,
  deep: vec3f,
  water: vec3f,
  light: vec3f,
}
@group(0) @binding(0) var<uniform> params: Params;

fn hash(p: vec2f) -> f32 {
  return fract(sin(dot(p, vec2f(127.1, 311.7))) * 43758.5453);
}

fn noise(p: vec2f) -> f32 {
  let i = floor(p);
  let f = fract(p);
  let u = f * f * (3.0 - 2.0 * f);
  return mix(
    mix(hash(i), hash(i + vec2f(1.0, 0.0)), u.x),
    mix(hash(i + vec2f(0.0, 1.0)), hash(i + vec2f(1.0, 1.0)), u.x),
    u.y,
  );
}

// Iterated interference caustic: light focused by a moving water surface.
fn caustic(q: vec2f, time: f32) -> f32 {
  let p = q - vec2f(250.0);
  var i = p;
  var c = 1.0;
  let inten = 0.005;
  for (var n = 0; n < 5; n++) {
    let t = time * (1.0 - 3.5 / f32(n + 1));
    i = p + vec2f(cos(t - i.x) + sin(t + i.y), sin(t - i.y) + cos(t + i.x));
    c += 1.0 / length(vec2f(p.x / (sin(i.x + t) / inten), p.y / (cos(i.y + t) / inten)));
  }
  c /= 5.0;
  c = 1.17 - pow(c, 1.4);
  return clamp(pow(abs(c), 8.0), 0.0, 1.5);
}

fn gridLine(v: f32, w: f32) -> f32 {
  let e = abs(fract(v + 0.5) - 0.5);
  let fw = fwidth(v);
  return 1.0 - smoothstep(w, w + fw * 1.5, e);
}

@fragment fn fs_main(@location(0) uv: vec2f) -> @location(0) vec4f {
  let t = params.time;
  let p = vec2f(uv.x * params.aspect, uv.y);

  // Refraction: the floor seen through moving water wobbles slightly.
  let wob = vec2f(noise(p * 3.0 + vec2f(t * 0.35, 0.0)), noise(p * 3.0 + vec2f(4.1, t * 0.3))) - 0.5;
  let floorP = p + wob * 0.025;

  // Pool floor: deeper toward the top, small square tiles with grout, and dark lane stripes.
  var col = mix(params.deep, params.water, smoothstep(-0.1, 1.0, uv.y));
  let tiles = max(gridLine(floorP.x * 16.0, 0.03), gridLine(floorP.y * 16.0, 0.03));
  col = mix(col, col * 0.8, tiles * 0.4);
  let tileTone = hash(floor(floorP * 16.0));
  col *= 0.96 + 0.06 * tileTone;
  let laneX = fract(floorP.x * 0.95 + 0.18) - 0.5;
  let lane = 1.0 - smoothstep(0.017, 0.024, abs(laneX));
  col = mix(col, params.deep * 0.55, lane * 0.75);

  // Two caustic octaves for richer, less repetitive webs; chromatic split at the edges.
  let cq = floorP * 4.2;
  let k = caustic(cq, t * 0.5) * 0.75 + caustic(cq * 1.6 + 9.0, t * 0.38 + 3.0) * 0.4;
  let kr = caustic(cq + vec2f(0.03, 0.0), t * 0.5);
  col += params.light * (smoothstep(0.12, 0.95, k) * 0.6 + k * 0.15);
  col += vec3f(0.6, 0.9, 1.0) * max(k - kr, 0.0) * 0.12;

  // Gentle surface sheen fading toward the top.
  col += params.light * 0.06 * (1.0 - uv.y);
  return vec4f(col, 1.0);
}
`;

type Vec3 = [number, number, number];

function hexToVec3(hex: string | undefined, fallback: Vec3): Vec3 {
  const m = /^#?([0-9a-f]{3}|[0-9a-f]{6})$/i.exec((hex ?? "").trim());
  if (!m) return fallback;
  const h = m[1].length === 3 ? m[1].replace(/./g, "$&$&") : m[1];
  return [0, 2, 4].map((i) => parseInt(h.slice(i, i + 2), 16) / 255) as Vec3;
}

type Colors = { deep: string; water: string; light: string };
type Fx = { set: (values: { params: Record<string, unknown> }) => void };

const colorUniforms = (c: Colors) => ({
  deep: hexToVec3(c.deep, [0.03, 0.27, 0.45]),
  water: hexToVec3(c.water, [0.12, 0.6, 0.82]),
  light: hexToVec3(c.light, [0.92, 0.99, 1.0]),
});

export function CausticsCanvas({ colors, speed }: { colors: Colors; speed: number }) {
  const canvasRef = useRef<HTMLCanvasElement>(null);
  const fxRef = useRef<Fx | null>(null);
  const redrawRef = useRef<(() => void) | null>(null);
  const live = useRef({ colors, speed });
  live.current = { colors, speed };
  const [ready, setReady] = useState(false);

  useEffect(() => {
    const canvas = canvasRef.current;
    if (!canvas || !("gpu" in navigator)) return;
    let disposed = false;
    let loop: FrameLoopHandle | undefined;
    let gpu: Awaited<ReturnType<typeof init>> | undefined;
    let observer: IntersectionObserver | undefined;
    let removeVisibility: (() => void) | undefined;
    const still = window.matchMedia("(prefers-reduced-motion: reduce)").matches;

    void (async () => {
      try {
        gpu = await init();
        if (disposed) return gpu.dispose();
        const target = surface(gpu, canvas, { dpr: [1, 2] });
        const aspect = () => (target.size[1] ? target.size[0] / target.size[1] : 1);
        const fx = effect(gpu, CAUSTICS_WGSL, {
          label: "caustics-pool",
          set: { params: { time: 20, aspect: aspect(), ...colorUniforms(live.current.colors) } },
        });
        fxRef.current = fx;
        const time = clock(gpu);
        const draw = () => gpu && !disposed && frame(gpu, (f) => f.pass(target, fx));
        redrawRef.current = still ? draw : null;
        target.onResize(() => {
          fx.set({ params: { aspect: aspect() } });
          if (still) queueMicrotask(draw);
        });

        const start = () => {
          if (loop || disposed || !gpu) return;
          loop = frameLoop(
            gpu,
            (f) => {
              fx.set({ params: { time: 20 + time.time * live.current.speed } });
              f.pass(target, fx);
            },
            { fps: 60 },
          );
        };
        const stop = () => {
          loop?.stop();
          loop = undefined;
        };

        if (still) {
          // Reduced motion: one settled frame, redrawn only when the editor changes a color.
          draw();
        } else {
          let onScreen = false;
          const sync = () => (onScreen && !document.hidden ? start() : stop());
          observer = new IntersectionObserver(([entry]) => {
            onScreen = Boolean(entry?.isIntersecting);
            sync();
          });
          observer.observe(canvas);
          document.addEventListener("visibilitychange", sync);
          removeVisibility = () => document.removeEventListener("visibilitychange", sync);
        }
        setReady(true);
      } catch {
        // No adapter, blocked, or lost device: the CSS fallback is the look.
      }
    })();

    return () => {
      disposed = true;
      observer?.disconnect();
      removeVisibility?.();
      loop?.stop();
      fxRef.current = null;
      redrawRef.current = null;
      gpu?.dispose();
    };
  }, []);

  // Live-update colors from the Puck sidebar without re-initializing.
  useEffect(() => {
    fxRef.current?.set({ params: colorUniforms(colors) });
    redrawRef.current?.();
  }, [colors.deep, colors.water, colors.light]); // eslint-disable-line react-hooks/exhaustive-deps

  return (
    <canvas
      ref={canvasRef}
      aria-hidden="true"
      className={`pointer-events-none absolute inset-0 size-full transition-opacity duration-1000 ${ready ? "opacity-100" : "opacity-0"}`}
    />
  );
}
```
