{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "spiral-launch-countdown",
  "title": "Spiral Launch Countdown",
  "description": "A launch event countdown over a turning spiral, with add-to-calendar links and a live state.",
  "dependencies": [
    "@paper-design/shaders-react",
    "lucide-react"
  ],
  "registryDependencies": [
    "button"
  ],
  "files": [
    {
      "path": "registry/shaders/spiral-launch-countdown/spiral-launch-countdown.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport { Spiral } from \"@paper-design/shaders-react\"\nimport { ArrowRightIcon, CalendarPlusIcon } from \"lucide-react\"\n\nimport { cn } from \"@/lib/utils\"\nimport { buttonVariants } from \"@/components/ui/button\"\n\ntype SpiralLaunchCountdownProps = React.ComponentProps<\"section\"> & {\n  /** When the launch starts. A date string or a Date. */\n  launchAt: string | Date\n  /** Name of the launch, used in calendar invites. */\n  event?: string\n  eyebrow?: string\n  title?: string\n  description?: string\n  /** Where people watch the launch, e.g. a livestream. Also added to calendar invites. */\n  liveAction?: { label: string; href: string }\n  /** Replace the title and description once the launch has started. */\n  liveTitle?: string\n  liveDescription?: string\n  /** Length of the launch event in calendar invites, in minutes. */\n  duration?: number\n  colorBack?: string\n  colorFront?: string\n  speed?: number\n}\n\nfunction SpiralLaunchCountdown({\n  launchAt,\n  event = \"Acme 3.0 launch keynote\",\n  eyebrow = \"Live keynote\",\n  title = \"Acme 3.0 goes live in\",\n  description = \"Join us for the first look at everything new. Add it to your calendar so you don't miss the start.\",\n  liveAction = { label: \"Watch the keynote\", href: \"#\" },\n  liveTitle = \"We're live\",\n  liveDescription = \"The keynote has started. Grab a seat, we're streaming now.\",\n  duration = 60,\n  colorBack = \"#05030f\",\n  colorFront = \"#7c6cff\",\n  speed = 0.4,\n  className,\n  style,\n  ...props\n}: SpiralLaunchCountdownProps) {\n  const start = new Date(launchAt)\n  const now = useNow()\n  const live = now !== null && now >= start.getTime()\n  const calendar = { event, start, duration, url: liveAction.href }\n\n  return (\n    <section\n      data-slot=\"spiral-launch-countdown\"\n      className={cn(\n        \"dark relative isolate flex min-h-[720px] w-full flex-col items-center justify-center overflow-hidden px-6 py-24 text-center text-white\",\n        className\n      )}\n      style={{ backgroundColor: colorBack, ...style }}\n      {...props}\n    >\n      <Spiral\n        aria-hidden\n        className=\"absolute inset-0 -z-10 size-full opacity-70\"\n        colorBack={colorBack}\n        colorFront={colorFront}\n        density={1}\n        distortion={0}\n        strokeWidth={0.15}\n        strokeTaper={0}\n        strokeCap={0}\n        noise={0.15}\n        noiseFrequency={0.3}\n        softness={0.02}\n        scale={1}\n        // Spins faster once the launch is live.\n        speed={live ? speed * 3 : speed}\n      />\n      {/* Darkens the middle of the spiral so the countdown stays readable. */}\n      <div\n        aria-hidden\n        className=\"absolute inset-0 -z-10\"\n        style={{\n          background: `radial-gradient(closest-side, ${colorBack} 35%, transparent)`,\n        }}\n      />\n      <div className=\"flex w-full max-w-3xl flex-col items-center gap-8\">\n        <span className=\"flex items-center gap-2 border border-white/20 bg-white/5 px-3 py-1 font-mono text-[11px] tracking-widest text-white/80 uppercase backdrop-blur\">\n          {live && (\n            <span className=\"size-1.5 animate-pulse rounded-full bg-red-500\" />\n          )}\n          {live ? \"Live now\" : eyebrow}\n        </span>\n        <h2 className=\"font-heading text-3xl leading-tight tracking-tight text-balance sm:text-5xl\">\n          {live ? liveTitle : title}\n        </h2>\n        {!live && <Countdown to={start} now={now} />}\n        <p className=\"max-w-md text-base text-pretty text-white/70\">\n          {/* In the visitor's own time zone, known once mounted. */}\n          {!live && now !== null && (\n            <span className=\"block font-medium text-white\">\n              {launchDateFormat.format(start)}.\n            </span>\n          )}\n          {live ? liveDescription : description}\n        </p>\n        {live ? (\n          <a\n            href={liveAction.href}\n            className={cn(\n              buttonVariants({ size: \"lg\" }),\n              \"h-11 bg-white px-5 text-black hover:bg-white/80\"\n            )}\n          >\n            {liveAction.label}\n            <ArrowRightIcon />\n          </a>\n        ) : (\n          <div className=\"flex flex-wrap items-center justify-center gap-3\">\n            <a\n              href={getGoogleCalendarUrl(calendar)}\n              target=\"_blank\"\n              rel=\"noreferrer\"\n              className={cn(\n                buttonVariants({ size: \"lg\" }),\n                \"h-11 bg-white px-5 text-black hover:bg-white/80\"\n              )}\n            >\n              <CalendarPlusIcon />\n              Add to Google Calendar\n            </a>\n            <a\n              href={`data:text/calendar;charset=utf-8,${encodeURIComponent(getIcs(calendar))}`}\n              download=\"launch.ics\"\n              className={cn(\n                buttonVariants({ variant: \"outline\", size: \"lg\" }),\n                \"h-11 border-white/20 bg-white/5 px-5 backdrop-blur hover:bg-white/10\"\n              )}\n            >\n              Apple / Outlook (.ics)\n            </a>\n          </div>\n        )}\n      </div>\n    </section>\n  )\n}\n\n/** The current time, ticking every second. Null until mounted, so the server and the first client render match. */\nfunction useNow() {\n  const [now, setNow] = React.useState<number | null>(null)\n\n  React.useEffect(() => {\n    const tick = () => setNow(Date.now())\n    tick()\n    const interval = setInterval(tick, 1000)\n    return () => clearInterval(interval)\n  }, [])\n\n  return now\n}\n\nconst launchDateFormat = new Intl.DateTimeFormat(undefined, {\n  dateStyle: \"full\",\n  timeStyle: \"short\",\n})\n\nconst UNITS = [\n  [\"Days\", 86_400_000],\n  [\"Hours\", 3_600_000],\n  [\"Minutes\", 60_000],\n  [\"Seconds\", 1_000],\n] as const\n\nfunction Countdown({ to, now }: { to: Date; now: number | null }) {\n  const remaining = now === null ? 0 : to.getTime() - now\n  // Each unit only counts what the larger units above it don't, e.g. 0–23 hours.\n  const parts = UNITS.map(([label, ms], i) => ({\n    label,\n    value: Math.floor((i ? remaining % UNITS[i - 1][1] : remaining) / ms),\n  }))\n\n  return (\n    <time\n      dateTime={to.toISOString()}\n      className=\"flex justify-center gap-4 sm:gap-8\"\n    >\n      {parts.map(({ label, value }) => (\n        <span key={label} className=\"flex flex-col items-center gap-2\">\n          <span className=\"min-w-[2ch] font-heading text-5xl leading-none tracking-tight tabular-nums sm:text-8xl\">\n            {now === null ? \"--\" : String(value).padStart(2, \"0\")}\n          </span>\n          <span className=\"font-mono text-[10px] tracking-widest text-white/50 uppercase\">\n            {label}\n          </span>\n        </span>\n      ))}\n    </time>\n  )\n}\n\ntype CalendarEvent = {\n  event: string\n  start: Date\n  duration: number\n  url: string\n}\n\n// Calendar dates in UTC, like 20270601T090000Z.\nfunction formatCalendarDate(date: Date) {\n  return date\n    .toISOString()\n    .replace(/[-:]/g, \"\")\n    .replace(/\\.\\d{3}/, \"\")\n}\n\nfunction getGoogleCalendarUrl({ event, start, duration, url }: CalendarEvent) {\n  const end = new Date(start.getTime() + duration * 60_000)\n  const params = new URLSearchParams({\n    action: \"TEMPLATE\",\n    text: event,\n    dates: `${formatCalendarDate(start)}/${formatCalendarDate(end)}`,\n    details: url,\n  })\n  return `https://calendar.google.com/calendar/render?${params}`\n}\n\n// A single-event iCalendar file, which Apple Calendar and Outlook can open.\nfunction getIcs({ event, start, duration, url }: CalendarEvent) {\n  const end = new Date(start.getTime() + duration * 60_000)\n  const escape = (text: string) => text.replace(/([\\\\;,])/g, \"\\\\$1\")\n  return [\n    \"BEGIN:VCALENDAR\",\n    \"VERSION:2.0\",\n    \"PRODID:-//shaderscn//launch countdown//EN\",\n    \"BEGIN:VEVENT\",\n    `UID:${formatCalendarDate(start)}-${encodeURIComponent(event)}`,\n    `DTSTAMP:${formatCalendarDate(start)}`,\n    `DTSTART:${formatCalendarDate(start)}`,\n    `DTEND:${formatCalendarDate(end)}`,\n    `SUMMARY:${escape(event)}`,\n    `URL:${url}`,\n    `DESCRIPTION:${escape(url)}`,\n    \"END:VEVENT\",\n    \"END:VCALENDAR\",\n  ].join(\"\\r\\n\")\n}\n\nexport { SpiralLaunchCountdown }\n",
      "type": "registry:component"
    }
  ],
  "categories": [
    "sections",
    "launch"
  ],
  "type": "registry:block"
}