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

Add a Puck component from P1 Blocks (https://p1-blocks.prolificdigital.io/blocks/aurora-hero) to this Pantheon Content Publisher (P1) Next.js project. A hero over slow, GPU-rendered aurora curtains in your brand colors, with a matching CSS fallback.

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

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

/**
 * Aurora Hero — a hero over slow, GPU-rendered aurora ribbons in your brand colors
 * (vgpu / WebGPU). Content is server-rendered; browsers without WebGPU get a matching
 * CSS gradient. Needs `pnpm add vgpu` and the companion aurora-hero.client.tsx file.
 * Register: `AuroraHeroBlock: auroraHeroBlock` in puck.config.tsx.
 */

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

export type AuroraHeroProps = {
  eyebrow: string;
  heading: string;
  headingLevel: Heading;
  body: string;
  primaryLabel: string;
  primaryHref: string;
  secondaryLabel: string;
  secondaryHref: string;
  baseColor: string;
  color1: string;
  color2: string;
  color3: 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<AuroraHeroProps["height"], string> = {
  medium: "min-h-[32rem]",
  tall: "min-h-[40rem]",
  screen: "min-h-svh",
};

const colorHelp = "A hex color such as #2dd4bf.";

export const auroraHeroBlock: ComponentConfig<AuroraHeroProps> = {
  label: "Aurora Hero",
  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" },
    baseColor: { type: "text", label: "Sky color", metadata: { help: `${colorHelp} Keep it dark: the text is white.` } },
    color1: { type: "text", label: "Ribbon color 1", metadata: { help: colorHelp } },
    color2: { type: "text", label: "Ribbon color 2", metadata: { help: colorHelp } },
    color3: { type: "text", label: "Ribbon color 3", metadata: { help: colorHelp } },
    speed: {
      type: "radio",
      label: "Motion",
      options: [
        { label: "Drifting", 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: "Dark Sky Preserve · Open nightly",
    heading: "See the night the way it was meant to look",
    headingLevel: "h1",
    body: "Twelve thousand acres with no streetlights, guided stargazing every clear Friday, and a sky so dark you can see your shadow by the Milky Way.",
    primaryLabel: "Plan a night visit",
    primaryHref: "/visit",
    secondaryLabel: "Tonight's sky forecast",
    secondaryHref: "/forecast",
    baseColor: "#070b1f",
    color1: "#2dd4bf",
    color2: "#6366f1",
    color3: "#c084fc",
    speed: "1",
    height: "tall",
  },
  render: ({ eyebrow, heading, headingLevel, body, primaryLabel, primaryHref, secondaryLabel, secondaryHref, baseColor, color1, color2, color3, speed, height }) => {
    const H = headingLevel || "h1";
    const base = hex(baseColor, "#070b1f");
    const c1 = hex(color1, "#2dd4bf");
    const c2 = hex(color2, "#6366f1");
    const c3 = hex(color3, "#c084fc");
    // The CSS fallback approximates the shader, and is all non-WebGPU browsers ever see.
    const fallback = {
      backgroundColor: base,
      backgroundImage: `radial-gradient(120% 60% at 20% 10%, ${c1}55, transparent 60%), radial-gradient(100% 50% at 70% 20%, ${c2}66, transparent 60%), radial-gradient(90% 45% at 50% 0%, ${c3}44, transparent 65%)`,
    };
    return (
      <section className={`relative isolate flex items-end overflow-hidden ${HEIGHTS[height] ?? HEIGHTS.tall}`} style={fallback}>
        <AuroraCanvas colors={{ base, c1, c2, c3 }} speed={Number(speed) || 1} />
        <div aria-hidden="true" className="pointer-events-none absolute inset-x-0 bottom-0 h-2/3 bg-gradient-to-t from-black/50 to-transparent" />
        <div className="relative mx-auto w-full max-w-7xl px-4 pt-32 pb-16 sm:px-6 sm:pb-20 lg:px-8 lg:pb-24">
          <div className="max-w-3xl">
            {eyebrow ? (
              <p className="inline-flex items-center gap-2 rounded-full bg-white/10 px-3 py-1 text-sm font-medium text-white ring-1 ring-white/20 backdrop-blur-sm ring-inset">
                <span aria-hidden="true" className="size-1.5 rounded-full bg-white" />
                {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-2xl text-lg leading-8 text-pretty text-white/85">{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-lg bg-white px-5 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-lg px-1 text-base font-semibold text-white focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-white"
                  >
                    {secondaryLabel}
                    <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>
                ) : null}
              </div>
            ) : null}
          </div>
        </div>
      </section>
    );
  },
};
```

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

```tsx
"use client";

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

/**
 * GPU half of the Aurora Hero: slow, domain-warped light ribbons drawn with 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 AURORA_WGSL = /* wgsl */ `
struct Params {
  time: f32,
  aspect: f32,
  base: vec3f,
  c1: vec3f,
  c2: vec3f,
  c3: 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,
  );
}

fn fbm(p0: vec2f) -> f32 {
  var p = p0;
  var amp = 0.5;
  var sum = 0.0;
  for (var i = 0; i < 5; i++) {
    sum += amp * noise(p);
    p = p * 2.02 + vec2f(1.7, 9.2);
    amp *= 0.5;
  }
  return sum;
}

@fragment fn fs_main(@location(0) uv: vec2f) -> @location(0) vec4f {
  let t = params.time;
  let p = vec2f(uv.x * params.aspect, uv.y);
  let warp = fbm(p * 1.4 + vec2f(t * 0.04, t * 0.025));
  var col = params.base;

  for (var k = 0; k < 3; k++) {
    let fk = f32(k);
    let center = 0.22 + 0.11 * fk + 0.07 * sin(p.x * 1.2 + t * 0.18 + fk * 2.1) + 0.16 * (warp - 0.5);
    let d = uv.y - center;
    let width = 90.0 / (1.0 + fk * 0.7);
    // Ribbons fall off sharply below and trail upward, like real aurora curtains.
    let falloff = select(exp(-d * d * width * 4.0), exp(-d * d * width * 0.35), d < 0.0);
    let shimmer = 0.5 + 0.5 * fbm(vec2f(p.x * 3.0 - t * 0.12, fk * 4.0 + t * 0.05));
    // Vertical rays: high-frequency streaks along x, bent by the same warp as the ribbon.
    let rays = 0.45 + 0.55 * noise(vec2f(p.x * 34.0 + warp * 7.0 + fk * 13.0, t * 0.35));
    var c = params.c1;
    if (k == 1) { c = params.c2; }
    if (k == 2) { c = params.c3; }
    col = mix(col, c, clamp(falloff * shimmer * rays * 1.35, 0.0, 1.0) * 0.85);
  }

  // Settle back to the base color toward the bottom, where the copy sits.
  col = mix(col, params.base, smoothstep(0.45, 0.95, uv.y) * 0.85);
  col += (hash(uv * vec2f(1931.0, 1093.0) + fract(t)) - 0.5) * 0.025;
  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 = { base: string; c1: string; c2: string; c3: string };
type Fx = { set: (values: { params: Record<string, unknown> }) => void };

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

  const uniforms = (c: Colors) => ({
    base: hexToVec3(c.base, [0.03, 0.05, 0.13]),
    c1: hexToVec3(c.c1, [0.25, 0.85, 0.75]),
    c2: hexToVec3(c.c2, [0.35, 0.4, 0.95]),
    c3: hexToVec3(c.c3, [0.75, 0.35, 0.9]),
  });

  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, AURORA_WGSL, {
          label: "aurora",
          set: { params: { time: 8, aspect: aspect(), ...uniforms(live.current.colors) } },
        });
        fxRef.current = fx;
        target.onResize(() => fx.set({ params: { aspect: aspect() } }));
        const time = clock(gpu);

        const start = () => {
          if (loop || disposed || !gpu) return;
          loop = frameLoop(
            gpu,
            (frame) => {
              fx.set({ params: { time: 8 + time.time * live.current.speed } });
              frame.pass(target, fx);
              // Reduced motion: one settled frame, then stop.
              if (still) stop();
            },
            { fps: 60 },
          );
        };
        const stop = () => {
          loop?.stop();
          loop = undefined;
        };

        // Run only while on screen and the tab is visible; a still frame needs neither.
        let onScreen = false;
        const sync = () => (onScreen && !document.hidden ? start() : still ? undefined : 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;
      gpu?.dispose();
    };
  }, []);

  // Live-update colors (e.g. while an editor types in the Puck sidebar) without re-initializing.
  useEffect(() => {
    fxRef.current?.set({ params: uniforms(colors) });
  }, [colors.base, colors.c1, colors.c2, colors.c3]); // eslint-disable-line react-hooks/exhaustive-deps

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