# Add the "Sky Time Banner" block to this P1 project

Add a Puck component from P1 Blocks (https://p1-blocks.prolificdigital.io/blocks/sky-time-banner) to this Pantheon Content Publisher (P1) Next.js project. A park or city banner whose GPU sky follows the visitor's local time: dawn, day, dusk or night.

## 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/sky-time-banner-block.tsx`, `components/puck/sky-time-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 { skyTimeBannerBlock } from "./components/puck/sky-time-banner-block";`
4. Register it under `components` as `SkyTimeBannerBlock: skyTimeBannerBlock`.
5. Add `"SkyTimeBannerBlock"` 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/sky-time-banner-block.tsx`

```tsx
import type { ComponentConfig } from "@puckeditor/core";
import { SkyTimeCanvas } from "./sky-time-banner.client";

/**
 * Sky Time Banner — a "today at the park" banner whose GPU sky (vgpu / WebGPU) follows the
 * visitor's local time: dawn, day, dusk or night, with the sun or moon placed by the hour.
 * Copy is server-rendered; without WebGPU a daytime CSS sky stands in.
 * Needs `pnpm add vgpu` and sky-time-banner.client.tsx. Register: `SkyTimeBannerBlock: skyTimeBannerBlock`.
 */

type Heading = "h1" | "h2" | "h3" | "h4";
type SkyPreview = "live" | "dawn" | "noon" | "dusk" | "night";

export type SkyTimeBannerProps = {
  eyebrow: string;
  heading: string;
  headingLevel: Heading;
  body: string;
  hours: string;
  ctaLabel: string;
  ctaHref: string;
  cloudiness: "0.15" | "0.45" | "0.75";
  preview: SkyPreview;
};

// Neutral daytime sky with a ridgeline: the pre-hydration look and the non-WebGPU look.
const FALLBACK = {
  backgroundColor: "#7fb3e3",
  backgroundImage:
    "linear-gradient(to bottom, transparent 82%, #2c4a47 82%), radial-gradient(140% 30% at 50% 84%, #6d8f9a 50%, transparent 51%), linear-gradient(to bottom, #2a6dc9 0%, #5d9ee0 45%, #a6d0f2 82%)",
};

export const skyTimeBannerBlock: ComponentConfig<SkyTimeBannerProps> = {
  label: "Sky Time Banner",
  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", 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." },
    },
    body: { type: "textarea", label: "Body" },
    hours: { type: "text", label: "Hours", metadata: { help: "Today's hours or a short status line. Bind a data source with {{ }}. Leave blank to hide it." } },
    ctaLabel: { type: "text", label: "Button text", metadata: { help: "Leave blank to hide it." } },
    ctaHref: { type: "text", label: "Button link" },
    cloudiness: {
      type: "radio",
      label: "Clouds",
      options: [
        { label: "Clear", value: "0.15" },
        { label: "Scattered", value: "0.45" },
        { label: "Cloudy", value: "0.75" },
      ],
    },
    preview: {
      type: "select",
      label: "Sky time",
      options: [
        { label: "Live (visitor's local time)", value: "live" },
        { label: "Dawn", value: "dawn" },
        { label: "Noon", value: "noon" },
        { label: "Dusk", value: "dusk" },
        { label: "Night", value: "night" },
      ],
      metadata: { help: "Pin a time while you design, then set it back to Live before publishing. Pinned times show to every visitor." },
    },
  },
  defaultProps: {
    eyebrow: "Today at Riverside Park",
    heading: "Open from first light until the stars come out",
    headingLevel: "h2",
    body: "Trails, the boathouse and the nature center are open daily. Check today's hours before you head out, and catch the guided sunset walk from the overlook every Friday.",
    hours: "Grounds 6 a.m. – 10 p.m. · Nature center 9 a.m. – 5 p.m.",
    ctaLabel: "Plan your visit",
    ctaHref: "/visit",
    cloudiness: "0.45",
    preview: "live",
  },
  render: ({ eyebrow, heading, headingLevel, body, hours, ctaLabel, ctaHref, cloudiness, preview }) => {
    const H = headingLevel || "h2";
    return (
      <section className="relative isolate flex min-h-[30rem] items-end overflow-hidden px-4 py-16 sm:min-h-[34rem] sm:px-6 sm:py-20 lg:px-8 lg:py-24" style={FALLBACK}>
        <SkyTimeCanvas preview={preview || "live"} clouds={Number(cloudiness) || 0.45} />
        <div className="relative mx-auto w-full max-w-7xl">
          <div className="max-w-xl rounded-2xl bg-neutral-950/55 p-6 text-white ring-1 ring-white/15 backdrop-blur-md sm:p-8">
            {eyebrow ? <p className="text-sm font-semibold tracking-widest text-white/90 uppercase">{eyebrow}</p> : null}
            {heading ? <H className="mt-3 text-3xl font-semibold tracking-tight text-balance sm:text-4xl">{heading}</H> : null}
            {body ? <p className="mt-4 text-base leading-7 text-pretty text-white/90 sm:text-lg sm:leading-8">{body}</p> : null}
            {hours ? (
              <p className="mt-5 flex items-start gap-2 text-sm font-medium text-white">
                <svg aria-hidden="true" viewBox="0 0 20 20" fill="currentColor" className="mt-0.5 size-4 shrink-0">
                  <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>
                <span>{hours}</span>
              </p>
            ) : null}
            {ctaLabel ? (
              <a
                href={ctaHref || "#"}
                className="mt-7 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"
              >
                {ctaLabel}
              </a>
            ) : null}
          </div>
        </div>
      </section>
    );
  },
};
```

## File: `components/puck/sky-time-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 Sky Time Banner: a sky that follows the visitor's local time of day (dawn,
 * day, dusk, night) with a sun or moon placed by the hour, stars after dark, drifting clouds and
 * a distant ridgeline, drawn with vgpu (WebGPU). Decorative; the server renders a daytime
 * CSS gradient that stays the look wherever WebGPU isn't available.
 */

const SKY_WGSL = /* wgsl */ `
struct Params {
  time: f32,
  aspect: f32,
  tod: f32,
  clouds: f32,
}
@group(0) @binding(0) var<uniform> params: Params;

const TAU = 6.2831853;

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.03 + vec2f(3.1, 1.7);
    amp *= 0.5;
  }
  return sum;
}

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

  // Sun elevation: rises at 0.25 (6 a.m.), peaks at 0.5, sets at 0.75. The moon runs opposite.
  let elev = sin((tod - 0.25) * TAU);
  let dayF = smoothstep(-0.12, 0.32, elev);
  let twF = exp(-pow(elev / 0.2, 2.0));
  let nightF = smoothstep(-0.05, -0.3, elev);

  let horizonY = 0.86;
  let sunProg = fract(tod - 0.25) * 2.0;
  let sunP = vec2f((0.1 + 0.8 * sunProg) * asp, horizonY - 0.72 * elev);
  let moonProg = fract(tod + 0.25) * 2.0;
  let moonP = vec2f((0.1 + 0.8 * moonProg) * asp, horizonY - 0.72 * -elev);

  // Sky gradient: zenith to horizon, blended across night, twilight and day.
  var zen = mix(vec3f(0.015, 0.03, 0.09), vec3f(0.14, 0.42, 0.82), dayF);
  var hor = mix(vec3f(0.06, 0.09, 0.2), vec3f(0.6, 0.8, 0.95), dayF);
  zen = mix(zen, vec3f(0.18, 0.2, 0.45), twF * 0.55);
  hor = mix(hor, vec3f(0.98, 0.56, 0.34), twF * 0.85);
  let vt = pow(smoothstep(0.0, horizonY, uv.y), 1.6);
  var col = mix(zen, hor, vt);
  // A rose band above the horizon at twilight, and warm glow on the sun's side.
  col = mix(col, vec3f(0.86, 0.46, 0.56), twF * 0.35 * exp(-pow((uv.y - 0.62) * 5.0, 2.0)));
  let sideGlow = exp(-pow((p.x - sunP.x) / (0.7 * asp), 2.0)) * smoothstep(0.2, horizonY, uv.y);
  col += vec3f(0.6, 0.3, 0.1) * twF * sideGlow * 0.45;

  // Stars, fading in after dusk and thinning toward the horizon.
  let sp = p * 64.0;
  let cell = floor(sp);
  let h = hash(cell);
  if (h > 0.97) {
    let off = vec2f(hash(cell + 3.7), hash(cell + 9.1)) * 0.6 + 0.2;
    let sd = length(fract(sp) - off);
    let tw = 0.6 + 0.4 * sin(t * (1.5 + h * 3.0) + h * 40.0);
    let star = smoothstep(0.2, 0.0, sd) * tw * (0.5 + (h - 0.97) * 50.0);
    col += vec3f(0.9, 0.93, 1.0) * star * nightF * (1.0 - smoothstep(0.4, horizonY, uv.y));
  }

  // Sun: disc plus layered glow, warmer as it nears the horizon.
  let sunVis = smoothstep(-0.08, 0.02, elev);
  let sd = length(p - sunP);
  let sunCol = mix(vec3f(1.0, 0.52, 0.26), vec3f(1.0, 0.97, 0.88), smoothstep(0.0, 0.35, elev));
  col += sunCol * (exp(-sd * 5.0) * 0.35 + exp(-sd * 18.0) * 0.5) * sunVis;
  col = mix(col, sunCol, smoothstep(0.052, 0.046, sd) * sunVis);

  // Moon: a cool disc with faint maria, and a soft halo.
  let moonVis = smoothstep(-0.02, 0.08, -elev) * (1.0 - dayF * 0.8);
  let md = length(p - moonP);
  let maria = fbm((p - moonP) * 40.0 + 4.0);
  let moonCol = vec3f(0.92, 0.93, 0.97) * (0.82 + 0.25 * maria);
  col += vec3f(0.55, 0.62, 0.8) * exp(-md * 9.0) * 0.22 * moonVis;
  col = mix(col, moonCol, smoothstep(0.038, 0.033, md) * moonVis);

  // Clouds: warped fbm drifting east, lit by the hour.
  let cp = vec2f(p.x * 1.3 + t * 0.012, uv.y * 3.2);
  let warp = fbm(cp * 0.8 + vec2f(t * 0.004, 0.0));
  let n = fbm(cp + warp * 0.9);
  let thr = mix(0.6, 0.34, params.clouds);
  let band = smoothstep(0.0, 0.15, uv.y) * (1.0 - smoothstep(0.6, 0.82, uv.y));
  let cover = smoothstep(thr, thr + 0.2, n) * band;
  var cloudCol = mix(vec3f(0.11, 0.13, 0.22), vec3f(1.0, 1.0, 1.0), dayF);
  cloudCol = mix(cloudCol, vec3f(1.0, 0.7, 0.58), twF * 0.7);
  let underside = fbm(cp + warp * 0.9 + vec2f(0.0, 0.18));
  cloudCol *= 0.8 + 0.25 * smoothstep(0.3, 0.7, n - underside + 0.5);
  col = mix(col, cloudCol, cover * 0.88);

  // Distant ridges: a hazy far line and a darker near line.
  let nearCol0 = mix(vec3f(0.02, 0.03, 0.07), vec3f(0.17, 0.29, 0.28), dayF);
  let nearCol = mix(nearCol0, vec3f(0.22, 0.14, 0.22), twF * 0.6);
  let farY = horizonY - 0.05 + 0.035 * sin(p.x * 2.2 + 1.0) + 0.02 * sin(p.x * 5.1 + 0.4) + 0.01 * (noise(p * vec2f(14.0, 1.0)) - 0.5);
  col = mix(col, mix(nearCol, hor, 0.55), smoothstep(farY - 0.002, farY + 0.002, uv.y));
  let nearY = horizonY + 0.025 + 0.025 * sin(p.x * 1.4 + 2.6) + 0.012 * sin(p.x * 4.3) + 0.008 * (noise(p * vec2f(30.0, 1.0)) - 0.5);
  col = mix(col, nearCol, smoothstep(nearY - 0.002, nearY + 0.002, uv.y));

  col += (hash(uv * vec2f(1931.0, 1093.0) + fract(t)) - 0.5) * 0.02;
  return vec4f(col, 1.0);
}
`;

export type SkyPreview = "live" | "dawn" | "noon" | "dusk" | "night";

const PRESETS: Record<Exclude<SkyPreview, "live">, number> = { dawn: 0.272, noon: 0.5, dusk: 0.735, night: 0.02 };

const timeOfDay = (preview: SkyPreview) => {
  if (preview !== "live" && preview in PRESETS) return PRESETS[preview];
  const now = new Date();
  return (now.getHours() * 60 + now.getMinutes() + now.getSeconds() / 60) / 1440;
};

type SkyTimeCanvasProps = { preview: SkyPreview; clouds: number };

export function SkyTimeCanvas({ preview, clouds }: SkyTimeCanvasProps) {
  const canvasRef = useRef<HTMLCanvasElement>(null);
  const redrawRef = useRef<(() => void) | null>(null);
  const live = useRef({ preview, clouds });
  live.current = { preview, clouds };
  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 tick: ReturnType<typeof setInterval> | 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, SKY_WGSL, {
          label: "sky-time",
          set: { params: { time: 20, aspect: aspect(), tod: timeOfDay(live.current.preview), clouds: live.current.clouds } },
        });
        target.onResize(() => fx.set({ params: { aspect: aspect() } }));
        const time = clock(gpu);
        let visible = false;

        const start = () => {
          if (loop || disposed || !gpu) return;
          loop = frameLoop(
            gpu,
            (frame) => {
              fx.set({ params: { time: 20 + time.time, tod: timeOfDay(live.current.preview), clouds: live.current.clouds } });
              frame.pass(target, fx);
              if (still) stop();
            },
            { fps: 60 },
          );
        };
        const stop = () => {
          loop?.stop();
          loop = undefined;
        };
        // Props changed (editor) or the minute rolled over: a reduced-motion visitor gets a fresh still.
        redrawRef.current = () => {
          if (still && visible) start();
        };
        tick = setInterval(() => redrawRef.current?.(), 60_000);

        observer = new IntersectionObserver(([entry]) => {
          visible = !!entry?.isIntersecting;
          if (visible) start();
          else if (!still) stop();
        });
        observer.observe(canvas);
        setReady(true);
      } catch {
        // No adapter, blocked, or lost device: the CSS sky is the look.
      }
    })();

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

  useEffect(() => {
    redrawRef.current?.();
  }, [preview, clouds]);

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