# Add the "Flow Field Banner" block to this P1 project

Add a Puck component from P1 Blocks (https://p1-blocks.prolificdigital.io/blocks/flow-field-banner) to this Pantheon Content Publisher (P1) Next.js project. A slim announcement band or section divider over flowing curl-noise light streaks in two brand colors.

## 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/flow-field-banner-block.tsx`, `components/puck/flow-field-banner.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 { flowFieldBannerBlock } from "./components/puck/flow-field-banner-block";`
4. Register it under `components` as `FlowFieldBannerBlock: flowFieldBannerBlock`.
5. Add `"FlowFieldBannerBlock"` 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/flow-field-banner-block.tsx`

```tsx
import type { ComponentConfig } from "@puckeditor/core";
import { FlowFieldCanvas } from "./flow-field-banner.client";

/**
 * Flow Field Banner — a slim, full-width announcement band (or section divider) over
 * GPU-drawn streaks flowing through a curl-noise current (vgpu / WebGPU). Text sits on a
 * dark frosted pill so it stays legible over any colors; browsers without WebGPU get a
 * CSS gradient. Needs `pnpm add vgpu` and the companion flow-field-banner.client.tsx file.
 * Register: `FlowFieldBannerBlock: flowFieldBannerBlock` in puck.config.tsx.
 */

export type FlowFieldBannerProps = {
  badge: string;
  message: string;
  linkLabel: string;
  linkHref: string;
  color1: string;
  color2: string;
  backgroundColor: string;
  height: "slim" | "medium" | "tall";
  speed: "0.5" | "1" | "1.6";
};

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<FlowFieldBannerProps["height"], string> = {
  slim: "min-h-24",
  medium: "min-h-40",
  tall: "min-h-64",
};

export const flowFieldBannerBlock: ComponentConfig<FlowFieldBannerProps> = {
  label: "Flow Field Banner",
  fields: {
    badge: { type: "text", label: "Badge", metadata: { help: "A word or two, such as \"Now open\". Leave blank to hide it." } },
    message: { type: "textarea", label: "Message", metadata: { help: "One sentence reads best." } },
    linkLabel: { type: "text", label: "Link text", metadata: { help: "Leave blank to hide the link." } },
    linkHref: { type: "text", label: "Link" },
    color1: { type: "text", label: "Streak color 1", metadata: { help: "A hex color such as #2dd4bf." } },
    color2: { type: "text", label: "Streak color 2", metadata: { help: "A hex color such as #fbbf24. The streaks drift between the two." } },
    backgroundColor: { type: "text", label: "Background color", metadata: { help: "A hex color such as #08121f. Darker backgrounds make the streaks glow." } },
    height: {
      type: "select",
      label: "Height",
      options: [
        { label: "Slim (announcement)", value: "slim" },
        { label: "Medium", value: "medium" },
        { label: "Tall (section divider)", value: "tall" },
      ],
    },
    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." },
    },
  },
  defaultProps: {
    badge: "Now open",
    message: "The Riverwalk extension opens Saturday, June 6: 4.2 new miles of paved trail from downtown to Harbor Park.",
    linkLabel: "See the route",
    linkHref: "/parks/riverwalk",
    color1: "#2dd4bf",
    color2: "#fbbf24",
    backgroundColor: "#08121f",
    height: "slim",
    speed: "1",
  },
  render: ({ badge, message, linkLabel, linkHref, color1, color2, backgroundColor, height, speed }) => {
    const c1 = hex(color1, "#2dd4bf");
    const c2 = hex(color2, "#fbbf24");
    const bg = hex(backgroundColor, "#08121f");
    if (!message && !linkLabel && !badge) return <></>;
    // The CSS fallback approximates the shader: a dark field with two soft currents of color.
    const fallback = {
      backgroundColor: bg,
      backgroundImage: `radial-gradient(60% 140% at 15% 50%, ${c1}40, transparent 70%), radial-gradient(50% 140% at 85% 40%, ${c2}33, transparent 70%), repeating-linear-gradient(170deg, transparent 0 9px, ${c1}14 9px 10px)`,
    };
    return (
      <section className={`relative isolate flex items-center overflow-hidden px-4 py-5 sm:px-6 lg:px-8 ${HEIGHTS[height] ?? HEIGHTS.slim}`} style={fallback}>
        <FlowFieldCanvas colors={{ c1, c2, bg }} speed={Number(speed) || 1} />
        <div className="relative mx-auto flex w-full max-w-7xl justify-center">
          <div className="flex max-w-3xl flex-col items-start gap-3 rounded-2xl bg-neutral-950/70 px-5 py-3 text-white shadow-lg ring-1 shadow-black/20 ring-white/15 backdrop-blur-md sm:flex-row sm:items-center sm:gap-4 sm:rounded-full sm:py-2 sm:pr-2 sm:pl-3">
            {badge ? (
              <span className="inline-flex shrink-0 items-center gap-1.5 rounded-full bg-white px-2.5 py-1 text-xs font-semibold tracking-wide text-neutral-950 uppercase">
                <span aria-hidden="true" className="size-1.5 rounded-full" style={{ backgroundColor: c1 }} />
                {badge}
              </span>
            ) : null}
            {message ? <p className="text-sm leading-6 text-pretty text-white sm:text-base">{message}</p> : null}
            {linkLabel ? (
              <a
                href={linkHref || "#"}
                className="group inline-flex min-h-11 shrink-0 items-center gap-1.5 rounded-full px-3 text-sm font-semibold text-white underline decoration-white/40 underline-offset-4 transition hover:bg-white/10 hover:decoration-white focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-white sm:text-base"
              >
                {linkLabel}
                <svg aria-hidden="true" viewBox="0 0 20 20" fill="currentColor" className="size-4 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>
        </div>
      </section>
    );
  },
};
```

## File: `components/puck/flow-field-banner.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 Flow Field Banner: streaklines traced backwards through a slowly evolving
 * curl-noise field, fragment-only (line integral convolution, vgpu / WebGPU). Decorative only;
 * the banner's text is server-rendered and the CSS gradient underneath is the fallback look.
 */

const FLOW_WGSL = /* wgsl */ `
struct Params {
  time: f32,
  aspect: f32,
  c1: vec3f,
  c2: vec3f,
  bg: 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 potential(p: vec2f, t: f32) -> f32 {
  return noise(p * 1.1 + vec2f(t * 0.04, -t * 0.03)) + 0.5 * noise(p * 2.3 + vec2f(5.2, t * 0.05));
}

// Divergence-free velocity: the 2D curl of a scalar noise potential.
fn curl(p: vec2f, t: f32) -> vec2f {
  let e = 0.01;
  let dx = potential(p + vec2f(e, 0.0), t) - potential(p - vec2f(e, 0.0), t);
  let dy = potential(p + vec2f(0.0, e), t) - potential(p - vec2f(0.0, e), t);
  // A steady eastward current keeps the streaks reading as a horizontal band.
  return vec2f(dy, -dx) / (2.0 * e) + vec2f(1.6, 0.0);
}

// Sparse seeds: bright specks that smear into streaks along the flow.
fn seed(p: vec2f) -> f32 {
  // Rotated lattice so value-noise cells never line up with the streak direction.
  let r = mat2x2f(0.83, -0.56, 0.56, 0.83) * p;
  return smoothstep(0.78, 0.98, noise(r * 62.0));
}

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

  var q = p;
  var acc = 0.0;
  var norm = 0.0;
  let steps = 48;
  for (var i = 0; i < steps; i++) {
    let fi = f32(i) / f32(steps);
    // Head of each streak is brightest; its tail fades back upstream.
    let w = (1.0 - fi) * (1.0 - fi);
    acc += seed(q - drift) * w;
    norm += w;
    q -= normalize(curl(q, t)) * 0.0042;
  }
  let streak = clamp(acc / norm * 5.0, 0.0, 1.0);

  // Color shifts across the field on a slow, broad noise; a soft glow lifts the base.
  let tint = smoothstep(0.25, 0.75, noise(p * 0.8 + vec2f(-t * 0.02, 1.3)));
  let ink = mix(params.c1, params.c2, tint);
  let glow = noise(p * 1.2 + vec2f(t * 0.03, 7.7));
  var col = params.bg + ink * glow * 0.12;
  col = mix(col, ink, streak * 0.9);
  return vec4f(clamp(col, vec3f(0.0), vec3f(1.0)), 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 = { c1: string; c2: string; bg: string };
type Fx = { set: (values: { params: Record<string, unknown> }) => void };

const uniforms = (c: Colors) => ({
  c1: hexToVec3(c.c1, [0.18, 0.83, 0.75]),
  c2: hexToVec3(c.c2, [0.98, 0.75, 0.14]),
  bg: hexToVec3(c.bg, [0.03, 0.07, 0.13]),
});

export function FlowFieldCanvas({ 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);

  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 cleanupVisibility: (() => 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, FLOW_WGSL, {
          label: "flow-field",
          set: { params: { time: 6, 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: 6 + time.time * live.current.speed } });
              frame.pass(target, fx);
              if (still) stop();
            },
            { fps: 60 },
          );
        };
        const stop = () => {
          loop?.stop();
          loop = undefined;
        };

        let visible = false;
        const onVisibility = () => (document.hidden ? stop() : visible && start());
        observer = new IntersectionObserver(([entry]) => {
          visible = !!entry?.isIntersecting;
          if (visible && !document.hidden) start();
          else if (!still) stop();
        });
        observer.observe(canvas);
        if (!still) document.addEventListener("visibilitychange", onVisibility);
        cleanupVisibility = () => document.removeEventListener("visibilitychange", onVisibility);
        setReady(true);
      } catch {
        // No adapter, blocked, or lost device: the CSS fallback is the look.
      }
    })();

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

  useEffect(() => {
    fxRef.current?.set({ params: uniforms(colors) });
  }, [colors.c1, colors.c2, colors.bg]); // 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"}`}
    />
  );
}
```
