{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "newsletter",
  "title": "Newsletter",
  "author": "AlgorizeTech",
  "description": "Ask the user to pick one of 3 newsletter variants: https://avaraui.com/view/newsletter. This item holds 3 of them as looks of one component (portraits, spotlight, issues). Skip the question if the user already named one. A sign-up section in three layouts: readers' faces drifting around a centred form, a panel with a pointer glow and a ticker of who just joined, or the form beside a fanned stack of recent issues. The form becomes a thank-you when your promise resolves.",
  "dependencies": [
    "gsap",
    "lucide-react"
  ],
  "registryDependencies": [
    "https://avaraui.com/r/button.json",
    "https://avaraui.com/r/input.json",
    "https://avaraui.com/r/marquee.json",
    "https://avaraui.com/r/tilted-card.json",
    "utils"
  ],
  "files": [
    {
      "path": "src/components/custom/blocks/NewsletterBlock.tsx",
      "content": "\"use client\";\n\nimport React, {\n  createContext,\n  useContext,\n  useLayoutEffect,\n  useRef,\n  useState,\n  useSyncExternalStore,\n} from \"react\";\nimport gsap from \"gsap\";\nimport { ArrowRight } from \"lucide-react\";\nimport { cn } from \"@/lib/utils\";\nimport Button from \"./Button\";\nimport { InputBlock } from \"./InputBlock\";\nimport { MarqueeBlock } from \"./MarqueeBlock\";\nimport { TiltedCard } from \"./TiltedCardBlock\";\nimport { bezierEase, gsapTicker } from \"./gsap-motion\";\nimport { createSpringFollower, MOTION_EASE, springEase } from \"./motion-curves\";\n\n// ==========================================\n// NEWSLETTER\n// A sign-up section in three layouts. `portraits` puts four readers' faces\n// around a centred form on a soft panel and lets them drift with the pointer;\n// `spotlight` is the same form on a dark panel with a glow under the cursor\n// and a ticker of who just joined; `issues` puts the form beside a fanned\n// stack of recent issues. One reveal when the section first appears, a\n// form that turns into a thank-you when your promise resolves, and nothing\n// else moves unless the reader does.\n// ==========================================\n\nexport type NewsletterVariant = \"portraits\" | \"spotlight\" | \"issues\";\n\n/** One part of the section's staggered reveal. */\ninterface RevealChild {\n  el: HTMLElement;\n  /** Start its entrance; `delay` is its place in the stagger. */\n  play: (delay: number) => void;\n}\n\n/** The parts waiting for the reveal, played in document order. */\ninterface RevealRegistry {\n  children: Set<RevealChild>;\n  played: boolean;\n  register: (child: RevealChild) => () => void;\n  play: () => void;\n}\n\n/** Stagger between parts, and the pause before the first. */\nconst STAGGER = 0.11;\nconst DELAY_CHILDREN = 0.05;\n\nfunction createRevealRegistry(): RevealRegistry {\n  const registry: RevealRegistry = {\n    children: new Set(),\n    played: false,\n    register(child) {\n      registry.children.add(child);\n      // Mounted after the reveal: come in straight away.\n      if (registry.played) child.play(0);\n      return () => {\n        registry.children.delete(child);\n      };\n    },\n    play() {\n      if (registry.played) return;\n      registry.played = true;\n      Array.from(registry.children)\n        .sort((a, b) => (a.el.compareDocumentPosition(b.el) & 2 ? 1 : -1))\n        .forEach((child, i) => child.play(DELAY_CHILDREN + i * STAGGER));\n    },\n  };\n  return registry;\n}\n\ninterface NewsletterContextValue {\n  variant: NewsletterVariant;\n  reveal: \"in-view\" | \"immediate\";\n  reduced: boolean;\n  registry: RevealRegistry | null;\n}\n\nconst NewsletterContext = createContext<NewsletterContextValue>({\n  variant: \"portraits\",\n  reveal: \"in-view\",\n  reduced: false,\n  registry: null,\n});\n\nconst subscribeReducedMotion = (onChange: () => void) => {\n  const query = window.matchMedia(\"(prefers-reduced-motion: reduce)\");\n  query.addEventListener(\"change\", onChange);\n  return () => query.removeEventListener(\"change\", onChange);\n};\n\n/** `prefers-reduced-motion: reduce`, false on the server. */\nfunction usePrefersReducedMotion() {\n  return useSyncExternalStore(\n    subscribeReducedMotion,\n    () => window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches,\n    () => false,\n  );\n}\n\n/** The rise: 0.7s on cubic-bezier(0.16, 1, 0.3, 1). */\nconst RISE_EASE = bezierEase([0.16, 1, 0.3, 1]);\nconst RISE_HIDDEN: React.CSSProperties = { opacity: 0, transform: \"translateY(18px)\" };\n\n/** Form out: 0.2s on Motion's default `easeOut`. */\nconst EXIT_EASE = bezierEase(MOTION_EASE.easeOut);\n/** Thank-you in: 0.45s on cubic-bezier(0.16, 1, 0.3, 1); the tick draws on `easeOut`. */\nconst DONE_EASE = bezierEase([0.16, 1, 0.3, 1]);\nconst DONE_HIDDEN: React.CSSProperties = { opacity: 0, transform: \"scale(0.96)\" };\nconst CHECK_EASE = bezierEase(MOTION_EASE.easeOut);\n\n/** Animates as one child of the section's staggered reveal. */\nfunction Reveal({ className, children }: { className?: string; children: React.ReactNode }) {\n  const { reduced, registry } = useContext(NewsletterContext);\n  const ref = useRef<HTMLDivElement>(null);\n\n  useLayoutEffect(() => {\n    const el = ref.current;\n    if (reduced || !el || !registry) return;\n    const state = { opacity: 0, y: 18 };\n    let tween: gsap.core.Tween | null = null;\n    const unregister = registry.register({\n      el,\n      play: (delay) => {\n        tween = gsap.to(state, {\n          opacity: 1,\n          y: 0,\n          duration: 0.7,\n          ease: RISE_EASE,\n          delay,\n          onUpdate: () => {\n            el.style.opacity = String(state.opacity);\n            el.style.transform = state.y ? `translateY(${state.y}px)` : \"none\";\n          },\n        });\n      },\n    });\n    return () => {\n      unregister();\n      tween?.kill();\n    };\n  }, [reduced, registry]);\n\n  return (\n    <div ref={ref} className={className} style={reduced ? undefined : RISE_HIDDEN}>\n      {children}\n    </div>\n  );\n}\n\n// ------------------------------------------\n// Heading, Intro\n// ------------------------------------------\nfunction Heading({ className, children, ...props }: React.HTMLAttributes<HTMLHeadingElement>) {\n  const { variant } = useContext(NewsletterContext);\n  return (\n    <Reveal>\n      <h2\n        className={cn(\n          \"font-sans text-[2rem] font-semibold leading-[1.08] tracking-[-0.03em] sm:text-[2.6rem]\",\n          variant === \"issues\" ? \"text-left\" : \"text-center\",\n          className,\n        )}\n        {...props}\n      >\n        {children}\n      </h2>\n    </Reveal>\n  );\n}\n\nfunction Intro({ className, children, ...props }: React.HTMLAttributes<HTMLParagraphElement>) {\n  const { variant } = useContext(NewsletterContext);\n  return (\n    <Reveal>\n      <p\n        className={cn(\n          \"mt-4 max-w-md text-[15px] leading-[1.65] opacity-65\",\n          variant === \"issues\" ? \"text-left\" : \"mx-auto text-center\",\n          className,\n        )}\n        {...props}\n      >\n        {children}\n      </p>\n    </Reveal>\n  );\n}\n\n// ------------------------------------------\n// Form — a pill with the button inside, that becomes a thank-you\n// ------------------------------------------\nexport interface NewsletterFormProps extends Omit<React.FormHTMLAttributes<HTMLFormElement>, \"onSubmit\"> {\n  placeholder?: string;\n  /** Button label. */\n  action?: string;\n  /** Return a promise to keep the button busy; resolve to show the thank-you, throw to stay on the form. */\n  onSubscribe?: (email: string) => void | Promise<void>;\n  successTitle?: string;\n  successText?: string;\n}\n\nfunction Form({\n  placeholder = \"name@email.com\",\n  action = \"Subscribe now\",\n  onSubscribe,\n  successTitle = \"You're subscribed\",\n  successText = \"Look out for the next edition in your inbox.\",\n  className,\n  ...props\n}: NewsletterFormProps) {\n  const { variant, reduced } = useContext(NewsletterContext);\n  const [email, setEmail] = useState(\"\");\n  const [busy, setBusy] = useState(false);\n  const [done, setDone] = useState(false);\n  // What is on screen: the form keeps its place until its exit has played.\n  const [shown, setShown] = useState<\"form\" | \"done\">(\"form\");\n  const formRef = useRef<HTMLDivElement>(null);\n  const doneRef = useRef<HTMLDivElement>(null);\n  const checkRef = useRef<SVGPathElement>(null);\n\n  // Form out (0.2s), then the thank-you in.\n  useLayoutEffect(() => {\n    if (!done || shown !== \"form\") return;\n    const el = formRef.current;\n    if (reduced || !el) {\n      setShown(\"done\");\n      return;\n    }\n    const state = { opacity: 1, scale: 1 };\n    const tween = gsap.to(state, {\n      opacity: 0,\n      scale: 0.97,\n      duration: 0.2,\n      ease: EXIT_EASE,\n      onUpdate: () => {\n        el.style.opacity = String(state.opacity);\n        el.style.transform = `scale(${state.scale})`;\n      },\n      onComplete: () => setShown(\"done\"),\n    });\n    return () => {\n      tween.kill();\n    };\n  }, [done, shown, reduced]);\n\n  // The thank-you settles in and the tick draws itself.\n  useLayoutEffect(() => {\n    if (shown !== \"done\" || reduced) return;\n    const el = doneRef.current;\n    const check = checkRef.current;\n    if (!el || !check) return;\n    const state = { opacity: 0, scale: 0.96, length: 0 };\n    const tweens = [\n      gsap.to(state, {\n        opacity: 1,\n        scale: 1,\n        duration: 0.45,\n        ease: DONE_EASE,\n        onUpdate: () => {\n          el.style.opacity = String(state.opacity);\n          el.style.transform = state.scale !== 1 ? `scale(${state.scale})` : \"none\";\n        },\n      }),\n      gsap.to(state, {\n        length: 1,\n        duration: 0.5,\n        delay: 0.15,\n        ease: CHECK_EASE,\n        onUpdate: () => check.setAttribute(\"stroke-dasharray\", `${state.length}px 1px`),\n      }),\n    ];\n    return () => tweens.forEach((tween) => tween.kill());\n    // Plays once, when the thank-you mounts.\n    // eslint-disable-next-line react-hooks/exhaustive-deps\n  }, [shown]);\n\n  const submit = async (e: React.FormEvent<HTMLFormElement>) => {\n    e.preventDefault();\n    if (!email || busy) return;\n    setBusy(true);\n    try {\n      await onSubscribe?.(email);\n      setDone(true);\n    } catch {\n      // Stay on the form; the caller shows its own error.\n    } finally {\n      setBusy(false);\n    }\n  };\n\n  return (\n    <Reveal className={cn(\"mt-8 w-full max-w-[26rem]\", variant !== \"issues\" && \"mx-auto\")}>\n      {shown === \"done\" ? (\n        <div\n          key=\"done\"\n          ref={doneRef}\n          role=\"status\"\n          style={reduced ? undefined : DONE_HIDDEN}\n          className=\"flex items-center gap-3 rounded-full bg-card py-2 pl-2 pr-5 text-card-foreground shadow-[0_1px_2px_rgba(0,0,0,0.05),0_8px_24px_-12px_rgba(0,0,0,0.2)] dark:shadow-none dark:ring-1 dark:ring-border\"\n        >\n          <span className=\"grid h-10 w-10 shrink-0 place-items-center rounded-full bg-emerald-500 text-white\">\n            <svg viewBox=\"0 0 24 24\" className=\"h-5 w-5\" fill=\"none\" stroke=\"currentColor\" strokeWidth={2.5} strokeLinecap=\"round\" strokeLinejoin=\"round\">\n              <path\n                ref={checkRef}\n                d=\"M5 12.5l4.5 4.5L19 7.5\"\n                pathLength={1}\n                strokeDashoffset=\"0px\"\n                strokeDasharray={reduced ? \"1px 1px\" : \"0px 1px\"}\n              />\n            </svg>\n          </span>\n          <span className=\"min-w-0 text-left\">\n            <span className=\"block text-[14px] font-semibold leading-tight\">{successTitle}</span>\n            <span className=\"block text-[12px] leading-tight text-muted-foreground\">{successText}</span>\n          </span>\n        </div>\n      ) : (\n        <div key=\"form\" ref={formRef}>\n        <form\n          onSubmit={submit}\n          className={cn(\n            \"flex items-center gap-1 rounded-full p-1.5 transition-shadow duration-300\",\n            \"bg-card shadow-[0_1px_2px_rgba(0,0,0,0.05),0_8px_24px_-12px_rgba(0,0,0,0.2)] focus-within:shadow-[0_1px_2px_rgba(0,0,0,0.05),0_12px_32px_-12px_rgba(0,0,0,0.28)]\",\n            \"dark:shadow-none dark:ring-1 dark:ring-foreground/15 dark:backdrop-blur dark:focus-within:shadow-none dark:focus-within:ring-foreground/30\",\n            className,\n          )}\n          {...props}\n        >\n          {/* The library input, with its own box made invisible so the pill is the field. */}\n          <InputBlock\n            type=\"email\"\n            variant=\"filled\"\n            inputSize=\"md\"\n            required\n            value={email}\n            onChange={(e) => setEmail(e.target.value)}\n            placeholder={placeholder}\n            aria-label=\"Email address\"\n            autoComplete=\"email\"\n            className=\"min-w-0 flex-1 gap-0 [&>div>div]:h-10 [&>div>div]:rounded-full [&>div>div]:border-0 [&>div>div]:bg-transparent [&>div>div]:px-4 [&>div>div]:shadow-none [&>div>div]:focus-within:bg-transparent [&>div>div]:focus-within:ring-0 [&_input]:text-foreground [&_input]:placeholder:text-muted-foreground\"\n          />\n          <Button\n            type=\"submit\"\n            variant=\"default\"\n            size=\"sm\"\n            loading={busy}\n            iconRight={<ArrowRight size={14} />}\n            className=\"h-10 shrink-0 rounded-full px-4 text-[13px] shadow-none\"\n          >\n            {action}\n          </Button>\n        </form>\n        </div>\n      )}\n    </Reveal>\n  );\n}\n\n// ------------------------------------------\n// Proof — a stack of faces and a line\n// ------------------------------------------\nexport interface NewsletterProofProps extends React.HTMLAttributes<HTMLDivElement> {\n  avatars: string[];\n}\n\nfunction Proof({ avatars, className, children, ...props }: NewsletterProofProps) {\n  const { variant } = useContext(NewsletterContext);\n  return (\n    <Reveal>\n      <div\n        className={cn(\n          \"mt-7 flex items-center gap-3 text-[13px] font-medium text-foreground/65\",\n          variant !== \"issues\" && \"justify-center\",\n          className,\n        )}\n        {...props}\n      >\n        <span className=\"flex items-center\">\n          <span className=\"flex -space-x-2\">\n            {avatars.slice(0, 5).map((src, i) => (\n              <img\n                key={src + i}\n                src={src}\n                alt=\"\"\n                className=\"h-7 w-7 rounded-full object-cover ring-2 ring-background\"\n              />\n            ))}\n          </span>\n          <span\n            className=\"-ml-1 grid h-7 w-7 place-items-center rounded-full bg-foreground text-[11px] font-semibold text-background ring-2 ring-background\"\n            aria-hidden\n          >\n            +\n          </span>\n        </span>\n        <span>{children}</span>\n      </div>\n    </Reveal>\n  );\n}\n\n// ------------------------------------------\n// Ticker — who just joined (spotlight)\n// ------------------------------------------\nexport interface NewsletterTickerItem {\n  name: string;\n  avatar?: string;\n  when: string;\n}\n\nfunction Ticker({ items, className }: { items: NewsletterTickerItem[]; className?: string }) {\n  return (\n    <Reveal className={cn(\"mt-12 w-full\", className)}>\n      <MarqueeBlock direction=\"left\" speed=\"slow\" gap=\"0.75rem\" fade pauseOnHover className=\"w-full\">\n        {items.map((it, i) => (\n          <span\n            key={it.name + i}\n            className=\"inline-flex shrink-0 items-center gap-2 rounded-full bg-card py-1.5 pl-1.5 pr-3.5 text-[12px] text-foreground/75 shadow-[0_1px_2px_rgba(0,0,0,0.04),0_6px_16px_-10px_rgba(0,0,0,0.2)] ring-1 ring-foreground/[0.08] dark:shadow-none\"\n          >\n            {it.avatar ? (\n              <img src={it.avatar} alt=\"\" className=\"h-6 w-6 rounded-full object-cover\" />\n            ) : (\n              <span className=\"grid h-6 w-6 place-items-center rounded-full bg-foreground/10 text-[10px] font-semibold\">\n                {it.name.slice(0, 1)}\n              </span>\n            )}\n            <span className=\"font-semibold text-foreground\">{it.name}</span> joined\n            <span className=\"text-foreground/45\">· {it.when}</span>\n          </span>\n        ))}\n      </MarqueeBlock>\n    </Reveal>\n  );\n}\n\n// ------------------------------------------\n// Issues — a fanned stack of recent issues (issues layout)\n// ------------------------------------------\nexport interface NewsletterIssue {\n  title: string;\n  date: string;\n  excerpt: string;\n  /** A picture for the top card. */\n  cover?: string;\n  tag?: string;\n}\n\nfunction Issues({ items, className }: { items: NewsletterIssue[]; className?: string }) {\n  const [top, ...rest] = items;\n  if (!top) return null;\n  return (\n    <Reveal className={cn(\"relative mx-auto w-full max-w-[22rem] pt-8\", className)}>\n      {/* The two behind sit back, offset and turned; the stack spreads a little on hover. */}\n      <div className=\"group relative\">\n        {rest.slice(0, 2).map((issue, i) => (\n          <div\n            key={issue.title}\n            aria-hidden\n            className={cn(\n              \"absolute inset-x-0 top-0 rounded-2xl border border-border bg-card p-5 text-card-foreground shadow-[0_8px_24px_-14px_rgba(0,0,0,0.25)] transition-transform duration-500 ease-out\",\n              i === 0\n                ? \"-translate-y-4 scale-[0.94] rotate-[-4deg] group-hover:-translate-y-7 group-hover:rotate-[-7deg]\"\n                : \"-translate-y-8 scale-[0.88] rotate-[3deg] group-hover:-translate-y-12 group-hover:rotate-[6deg]\",\n            )}\n          >\n            <p className=\"text-[11px] font-medium opacity-50\">{issue.date}</p>\n            <p className=\"mt-1 truncate text-[15px] font-semibold\">{issue.title}</p>\n          </div>\n        ))}\n        <TiltedCard tiltIntensity={7} glareOpacity={0.1} scaleOnHover={1.02} className=\"h-auto\">\n          <article className=\"rounded-2xl border border-border bg-card p-5 text-left text-card-foreground\">\n            {top.cover && (\n              <div className=\"mb-4 h-32 overflow-hidden rounded-xl\">\n                <img src={top.cover} alt=\"\" className=\"h-full w-full object-cover\" />\n              </div>\n            )}\n            <div className=\"flex items-center justify-between gap-3 text-[11px] font-medium\">\n              <span className=\"opacity-50\">{top.date}</span>\n              {top.tag && <span className=\"rounded-full bg-primary/10 px-2 py-0.5 text-primary\">{top.tag}</span>}\n            </div>\n            <h3 className=\"mt-2 text-[17px] font-semibold leading-snug tracking-tight\">{top.title}</h3>\n            <p className=\"mt-2 text-[13px] leading-relaxed opacity-65\">{top.excerpt}</p>\n          </article>\n        </TiltedCard>\n      </div>\n    </Reveal>\n  );\n}\n\n// ------------------------------------------\n// Portraits — four faces that drift with the pointer\n// ------------------------------------------\nexport interface NewsletterPortrait {\n  src: string;\n  alt?: string;\n}\n\nconst CORNERS = [\n  { className: \"left-[7%] top-[13%] h-20 w-20 lg:h-[5.5rem] lg:w-[5.5rem]\", depth: 14 },\n  { className: \"right-[7%] top-[13%] h-16 w-16 lg:h-[4.5rem] lg:w-[4.5rem]\", depth: -10 },\n  { className: \"bottom-[13%] left-[8%] h-16 w-16 lg:h-[4.5rem] lg:w-[4.5rem]\", depth: -8 },\n  { className: \"bottom-[13%] right-[7%] h-20 w-20 lg:h-[5.5rem] lg:w-[5.5rem]\", depth: 12 },\n];\n\n/** Pointer position as -1..1 across the panel, smoothed; the portraits and the spotlight read it. */\ninterface DriftBus {\n  x: number;\n  y: number;\n  listeners: Set<() => void>;\n}\n\n/** Portrait entrance: a spring, after the portrait's own delay. */\nconst PORTRAIT_SPRING = springEase({ stiffness: 260, damping: 18 });\nconst PORTRAIT_HIDDEN: React.CSSProperties = { opacity: 0, transform: \"scale(0.6)\" };\n\nfunction Portrait({\n  portrait,\n  corner,\n  drift,\n  index,\n}: {\n  portrait: NewsletterPortrait;\n  corner: (typeof CORNERS)[number];\n  drift: DriftBus;\n  index: number;\n}) {\n  const { reduced, registry } = useContext(NewsletterContext);\n  const ref = useRef<HTMLDivElement>(null);\n\n  useLayoutEffect(() => {\n    const el = ref.current;\n    if (reduced || !el || !registry) return;\n    const pose = { x: 0, y: 0, scale: 0.6, opacity: 0 };\n    const render = () => {\n      let t = \"\";\n      if (pose.x) t += `translateX(${pose.x}px) `;\n      if (pose.y) t += `translateY(${pose.y}px) `;\n      if (pose.scale !== 1) t += `scale(${pose.scale}) `;\n      el.style.transform = t ? t.trim() : \"none\";\n      el.style.opacity = String(pose.opacity);\n    };\n    const follow = () => {\n      pose.x = drift.x * corner.depth;\n      pose.y = drift.y * corner.depth;\n      render();\n    };\n    drift.listeners.add(follow);\n    if (drift.x || drift.y) follow();\n\n    let tween: gsap.core.Tween | null = null;\n    const unregister = registry.register({\n      el,\n      // Its own delay, not its place in the stagger.\n      play: () => {\n        const progress = { value: 0 };\n        tween = gsap.to(progress, {\n          value: 1,\n          duration: PORTRAIT_SPRING.duration,\n          ease: PORTRAIT_SPRING.ease,\n          delay: 0.35 + index * 0.08,\n          onUpdate: () => {\n            pose.opacity = progress.value;\n            pose.scale = 0.6 + 0.4 * progress.value;\n            render();\n          },\n        });\n      },\n    });\n    return () => {\n      drift.listeners.delete(follow);\n      unregister();\n      tween?.kill();\n    };\n  }, [reduced, registry, drift, corner.depth, index]);\n\n  return (\n    <div\n      ref={ref}\n      className={cn(\"absolute hidden overflow-hidden rounded-full md:block\", corner.className)}\n      style={reduced ? undefined : PORTRAIT_HIDDEN}\n    >\n      <img src={portrait.src} alt={portrait.alt ?? \"\"} className=\"h-full w-full object-cover\" />\n    </div>\n  );\n}\n\n/** Spotlight: a soft disc of the accent that follows the pointer. */\nconst glowAt = (x: number, y: number) => {\n  const at = (v: number) => `${(Math.max(-1, Math.min(1, v)) + 1) * 50}%`;\n  return `radial-gradient(420px circle at ${at(x)} ${at(y)}, color-mix(in oklab, var(--primary) 22%, transparent), transparent 70%)`;\n};\nconst GLOW_STYLE: React.CSSProperties = { background: glowAt(0, 0) };\n\nfunction Glow({ drift }: { drift: DriftBus }) {\n  const ref = useRef<HTMLDivElement>(null);\n  useLayoutEffect(() => {\n    const el = ref.current;\n    if (!el) return;\n    const follow = () => {\n      el.style.background = glowAt(drift.x, drift.y);\n    };\n    drift.listeners.add(follow);\n    follow();\n    return () => {\n      drift.listeners.delete(follow);\n    };\n  }, [drift]);\n  return <div ref={ref} aria-hidden className=\"pointer-events-none absolute inset-0 -z-10\" style={GLOW_STYLE} />;\n}\n\n// ------------------------------------------\n// Root\n// ------------------------------------------\nexport interface NewsletterProps extends React.HTMLAttributes<HTMLElement> {\n  variant?: NewsletterVariant;\n  /** Up to four faces, for the `portraits` layout. */\n  portraits?: NewsletterPortrait[];\n  /** Accent for buttons, tags and the spotlight; defaults to the theme's primary. */\n  accent?: string;\n  reveal?: \"in-view\" | \"immediate\";\n  children: React.ReactNode;\n}\n\nconst isPart = (child: React.ReactNode, type: React.ElementType) =>\n  React.isValidElement(child) && child.type === type;\n\nexport function Newsletter({\n  variant = \"portraits\",\n  portraits = [],\n  accent,\n  reveal = \"in-view\",\n  className,\n  style,\n  children,\n  ...props\n}: NewsletterProps) {\n  const reduced = usePrefersReducedMotion();\n  const ref = useRef<HTMLElement>(null);\n  const revealRef = useRef<HTMLDivElement>(null);\n  const [registry] = useState(createRevealRegistry);\n\n  // Pointer position as -1..1 across the panel, smoothed; the portraits and\n  // the spotlight read it.\n  const [drift] = useState<DriftBus>(() => ({ x: 0, y: 0, listeners: new Set() }));\n  const pointer = useRef<{ x: (v: number) => void; y: (v: number) => void } | null>(null);\n\n  useLayoutEffect(() => {\n    const notify = () => drift.listeners.forEach((listener) => listener());\n    const options = { stiffness: 60, damping: 18, mass: 0.6, ticker: gsapTicker };\n    const sx = createSpringFollower(0, (v) => {\n      drift.x = v;\n      notify();\n    }, options);\n    const sy = createSpringFollower(0, (v) => {\n      drift.y = v;\n      notify();\n    }, options);\n    pointer.current = { x: sx.set, y: sy.set };\n    return () => {\n      sx.destroy();\n      sy.destroy();\n      pointer.current = null;\n    };\n  }, [drift]);\n\n  // One reveal: at once, or when 30% of the section is in view.\n  useLayoutEffect(() => {\n    const el = revealRef.current;\n    if (!el) return;\n    let observer: IntersectionObserver | null = null;\n    if (reveal === \"immediate\") {\n      registry.play();\n    } else {\n      observer = new IntersectionObserver(\n        (entries) => {\n          if (!entries.some((entry) => entry.isIntersecting)) return;\n          observer?.disconnect();\n          registry.play();\n        },\n        { threshold: 0.3 },\n      );\n      observer.observe(el);\n    }\n    return () => {\n      observer?.disconnect();\n      // A remount (Strict Mode) plays the reveal again from the top.\n      registry.played = false;\n    };\n  }, [reveal, registry]);\n\n  const onMove = (e: React.MouseEvent<HTMLElement>) => {\n    const r = e.currentTarget.getBoundingClientRect();\n    pointer.current?.x(((e.clientX - r.left) / r.width) * 2 - 1);\n    pointer.current?.y(((e.clientY - r.top) / r.height) * 2 - 1);\n  };\n  const onLeave = () => {\n    pointer.current?.x(0);\n    pointer.current?.y(0);\n  };\n\n  const all = React.Children.toArray(children);\n  const issues = all.filter((c) => isPart(c, Issues));\n  const ticker = all.filter((c) => isPart(c, Ticker));\n  const body = all.filter((c) => !isPart(c, Issues) && !isPart(c, Ticker));\n\n  const spotlight = variant === \"spotlight\";\n\n  return (\n    <NewsletterContext.Provider value={{ variant, reveal, reduced, registry }}>\n      <section\n        ref={ref}\n        onMouseMove={onMove}\n        onMouseLeave={onLeave}\n        className={cn(\n          \"relative isolate w-full overflow-hidden text-foreground\",\n          // Every layout follows the site's theme: a muted or plain ground by day, the page ground by night.\n          variant === \"issues\" ? \"bg-background\" : \"bg-muted dark:bg-background\",\n          className,\n        )}\n        style={accent ? ({ ...style, \"--primary\": accent } as React.CSSProperties) : style}\n        {...props}\n      >\n      <div ref={revealRef} className=\"relative\">\n        {/* Spotlight: a soft disc of the accent that follows the pointer. */}\n        {spotlight && !reduced && <Glow drift={drift} />}\n\n        {variant === \"portraits\" &&\n          portraits.slice(0, 4).map((p, i) => {\n            const corner = CORNERS[i];\n            return corner ? <Portrait key={p.src} portrait={p} corner={corner} drift={drift} index={i} /> : null;\n          })}\n\n        {variant === \"issues\" ? (\n          <div className=\"mx-auto grid max-w-5xl grid-cols-1 items-center gap-12 px-6 py-14 sm:px-10 sm:py-20 lg:grid-cols-[1.1fr_1fr] lg:gap-16\">\n            <div className=\"flex flex-col items-start\">{body}</div>\n            <div>{issues}</div>\n          </div>\n        ) : (\n          <div className=\"mx-auto flex max-w-xl flex-col items-center px-6 py-16 sm:py-24\">\n            {variant === \"portraits\" && portraits.length > 0 && (\n              <Reveal className=\"mb-6 flex -space-x-3 md:hidden\">\n                {portraits.slice(0, 4).map((p) => (\n                  <img key={p.src} src={p.src} alt={p.alt ?? \"\"} className=\"h-12 w-12 rounded-full object-cover ring-2 ring-muted dark:ring-background\" />\n                ))}\n              </Reveal>\n            )}\n            {body}\n            {ticker}\n          </div>\n        )}\n      </div>\n      </section>\n    </NewsletterContext.Provider>\n  );\n}\n\nNewsletter.Heading = Heading;\nNewsletter.Intro = Intro;\nNewsletter.Form = Form;\nNewsletter.Proof = Proof;\nNewsletter.Ticker = Ticker;\nNewsletter.Issues = Issues;\n\nexport default Newsletter;\n",
      "type": "registry:component",
      "target": "components/custom/blocks/NewsletterBlock.tsx"
    },
    {
      "path": "src/components/custom/blocks/gsap-motion.ts",
      "content": "import gsap from \"gsap\";\nimport { cubicBezier, type FrameTicker } from \"./motion-curves\";\n\n/**\n * GSAP-side glue for the GSAP builds of components that also ship a Motion\n * Motion twin. Kept apart from motion-curves.ts so the library-free curves\n * never pull GSAP into a CSS or Motion build.\n */\n\n/** `gsap.ticker` as a FrameTicker, so spring followers run on GSAP's loop. */\nexport const gsapTicker: FrameTicker = {\n  add(callback) {\n    const tick = (_time: number, deltaTime: number) => callback(deltaTime);\n    gsap.ticker.add(tick);\n    return () => gsap.ticker.remove(tick);\n  },\n};\n\n/** A Motion / CSS cubic-bezier array as a GSAP ease. */\nexport const bezierEase = (curve: readonly [number, number, number, number] | readonly number[]) =>\n  cubicBezier(curve[0], curve[1], curve[2], curve[3]);\n\n/** `(prefers-reduced-motion: reduce)` right now. */\nexport const prefersReducedMotion = () =>\n  typeof window !== \"undefined\" &&\n  window.matchMedia?.(\"(prefers-reduced-motion: reduce)\").matches === true;\n",
      "type": "registry:component",
      "target": "components/custom/blocks/gsap-motion.ts"
    },
    {
      "path": "src/components/custom/blocks/motion-curves.ts",
      "content": "/**\n * Motion curves with no animation library behind them.\n *\n * The components here ship as CSS, GSAP or Motion builds that must move\n * identically, so the curves are computed once, from the same numbers, and\n * handed to whichever engine runs them:\n *\n *   - `cubicBezier(x1, y1, x2, y2)` → an easing function (GSAP accepts any\n *     `(progress) => value` as `ease`), exact for Motion's `ease: [..]` arrays\n *     and for CSS `cubic-bezier()`.\n *   - `spring({ stiffness, damping, mass })` → the analytic solution Motion\n *     Motion uses, as an easing function plus the time it takes to settle, or\n *     as a CSS `linear()` string for a fixed start and end.\n *   - `createSpringFollower` → a value that chases a moving target through the\n *     same spring every frame, like Motion's `useSpring`, for pointer-driven\n *     motion that no fixed curve can describe.\n */\n\n// ---------------------------------------------------------------------------\n// Cubic bezier\n// ---------------------------------------------------------------------------\n\n/**\n * The CSS / Motion cubic-bezier as a function of progress. Newton-Raphson\n * with a bisection fallback, the same solver browsers use.\n */\nexport function cubicBezier(x1: number, y1: number, x2: number, y2: number) {\n  if (x1 === y1 && x2 === y2) return (t: number) => t;\n\n  const a = (p1: number, p2: number) => 1 - 3 * p2 + 3 * p1;\n  const b = (p1: number, p2: number) => 3 * p2 - 6 * p1;\n  const c = (p1: number) => 3 * p1;\n  const at = (t: number, p1: number, p2: number) =>\n    ((a(p1, p2) * t + b(p1, p2)) * t + c(p1)) * t;\n  const slope = (t: number, p1: number, p2: number) =>\n    3 * a(p1, p2) * t * t + 2 * b(p1, p2) * t + c(p1);\n\n  const solveX = (x: number) => {\n    let t = x;\n    for (let i = 0; i < 8; i++) {\n      const s = slope(t, x1, x2);\n      if (Math.abs(s) < 1e-6) break;\n      const err = at(t, x1, x2) - x;\n      if (Math.abs(err) < 1e-7) return t;\n      t -= err / s;\n    }\n    let lo = 0;\n    let hi = 1;\n    t = x;\n    for (let i = 0; i < 30 && hi - lo > 1e-7; i++) {\n      const value = at(t, x1, x2);\n      if (value < x) lo = t;\n      else hi = t;\n      t = (lo + hi) / 2;\n    }\n    return t;\n  };\n\n  return (x: number) => (x <= 0 ? 0 : x >= 1 ? 1 : at(solveX(x), y1, y2));\n}\n\n/** Motion's named eases, as the cubic-beziers they are. */\nexport const MOTION_EASE = {\n  linear: [0, 0, 1, 1],\n  easeIn: [0.42, 0, 1, 1],\n  easeOut: [0, 0, 0.58, 1],\n  easeInOut: [0.42, 0, 0.58, 1],\n  circIn: [0.55, 0, 1, 0.45],\n  circOut: [0.55, 0, 0.45, 1],\n  circInOut: [0.85, 0, 0.15, 1],\n  backIn: [0.31, 0.01, 0.66, -0.59],\n  backOut: [0.33, 1.53, 0.69, 0.99],\n  anticipate: [0.66, -0.56, 0.34, 1.35],\n} as const;\n\n/**\n * Motion's default layout transition (`layout` / `layoutId`):\n * `{ duration: 0.45, ease: [0.4, 0, 0.1, 1] }`.\n */\nexport const LAYOUT_TRANSITION = { duration: 0.45, ease: [0.4, 0, 0.1, 1] as const };\n\n// ---------------------------------------------------------------------------\n// Spring\n// ---------------------------------------------------------------------------\n\nexport interface SpringOptions {\n  /** Motion default 100. */\n  stiffness?: number;\n  /** Motion default 10. */\n  damping?: number;\n  /** Motion default 1. */\n  mass?: number;\n  /** Starting velocity, in units of the whole distance per second. */\n  velocity?: number;\n  /** How close to the end counts as settled, as a fraction of the distance. */\n  restDelta?: number;\n}\n\n/**\n * Normalised position (0 → 1) of a spring released from 0 towards 1, at time\n * `t` seconds. The closed-form solution Motion's `spring()` generator\n * uses for the under-, critically and over-damped cases.\n */\nexport function springAt(options: SpringOptions = {}) {\n  const { stiffness = 100, damping = 10, mass = 1, velocity = 0 } = options;\n  const zeta = damping / (2 * Math.sqrt(stiffness * mass));\n  const omega0 = Math.sqrt(stiffness / mass);\n  // Motion's convention: distance still to cover, velocity toward it negated.\n  const delta = 1;\n  const v0 = -velocity;\n\n  if (zeta < 1) {\n    const omegaD = omega0 * Math.sqrt(1 - zeta * zeta);\n    return (t: number) => {\n      const envelope = Math.exp(-zeta * omega0 * t);\n      return (\n        1 -\n        envelope *\n          (((v0 + zeta * omega0 * delta) / omegaD) * Math.sin(omegaD * t) +\n            delta * Math.cos(omegaD * t))\n      );\n    };\n  }\n  if (zeta === 1) {\n    return (t: number) => 1 - Math.exp(-omega0 * t) * (delta + (v0 + omega0 * delta) * t);\n  }\n  const omegaD = omega0 * Math.sqrt(zeta * zeta - 1);\n  return (t: number) => {\n    const envelope = Math.exp(-zeta * omega0 * t);\n    const freq = Math.min(omegaD * t, 300);\n    return (\n      1 -\n      (envelope *\n        ((v0 + zeta * omega0 * delta) * Math.sinh(freq) + omegaD * delta * Math.cosh(freq))) /\n        omegaD\n    );\n  };\n}\n\n/** Seconds until the spring stays within `restDelta` of its end. */\nexport function springDuration(options: SpringOptions = {}) {\n  const at = springAt(options);\n  const restDelta = options.restDelta ?? 0.001;\n  const step = 1 / 240;\n  let lastOutside = 0;\n  for (let t = 0; t <= 10; t += step) {\n    if (Math.abs(1 - at(t)) > restDelta) lastOutside = t;\n    else if (t - lastOutside > 0.1) break;\n  }\n  return Math.max(lastOutside + step, step);\n}\n\n/**\n * A spring as a duration and an easing function over it — what GSAP takes:\n *\n *   const { duration, ease } = springEase({ stiffness: 300, damping: 20 });\n *   gsap.to(el, { y: 0, duration, ease });\n *\n * Exact for a fixed start and end; a spring that has to react mid-flight to a\n * new target needs `createSpringFollower` instead.\n */\nexport function springEase(options: SpringOptions = {}) {\n  const duration = springDuration(options);\n  const at = springAt(options);\n  return {\n    duration,\n    ease: (progress: number) => (progress >= 1 ? 1 : at(progress * duration)),\n  };\n}\n\n/**\n * A spring as a CSS `linear()` easing and its duration in ms, for\n * `transition` / `animation` with a fixed start and end.\n *\n *   const { easing, duration } = springLinear({ stiffness: 400, damping: 30 });\n *   el.style.transition = `transform ${duration}ms ${easing}`;\n */\nexport function springLinear(options: SpringOptions = {}, pointsPerSecond = 60) {\n  const duration = springDuration(options);\n  const at = springAt(options);\n  const count = Math.max(Math.ceil(duration * pointsPerSecond), 8);\n  const points: string[] = [];\n  for (let i = 0; i <= count; i++) {\n    const t = (i / count) * duration;\n    points.push(String(Math.round((i === count ? 1 : at(t)) * 10000) / 10000));\n  }\n  return { easing: `linear(${points.join(\", \")})`, duration: Math.round(duration * 1000) };\n}\n\n// ---------------------------------------------------------------------------\n// Spring follower (useSpring equivalent)\n// ---------------------------------------------------------------------------\n\n/** Something that calls back once per frame with the time since the last, in ms. */\nexport interface FrameTicker {\n  add: (callback: (deltaMs: number) => void) => () => void;\n}\n\n/** requestAnimationFrame as a ticker — the library-free default. */\nexport const rafTicker: FrameTicker = {\n  add(callback) {\n    let last = performance.now();\n    let frame = requestAnimationFrame(function tick(now) {\n      callback(now - last);\n      last = now;\n      frame = requestAnimationFrame(tick);\n    });\n    return () => cancelAnimationFrame(frame);\n  },\n};\n\nexport interface SpringFollower {\n  /** Chase a new target from wherever the value is now, keeping its velocity. */\n  set: (target: number) => void;\n  /** Move to a value instantly, with no motion. */\n  jump: (value: number) => void;\n  get: () => number;\n  destroy: () => void;\n}\n\n/**\n * A value that follows its target through a spring, integrating the same\n * equation of motion Motion's `useSpring` solves — so a pointer-driven spring\n * reads the same in every build. Runs only while moving; `onUpdate` receives\n * each new value.\n */\nexport function createSpringFollower(\n  initial: number,\n  onUpdate: (value: number) => void,\n  options: SpringOptions & { restSpeed?: number; ticker?: FrameTicker } = {},\n): SpringFollower {\n  const { stiffness = 100, damping = 10, mass = 1, ticker = rafTicker } = options;\n  const restDelta = options.restDelta ?? 0.01;\n  const restSpeed = options.restSpeed ?? 0.01;\n  let value = initial;\n  let target = initial;\n  let velocity = 0;\n  let stop: (() => void) | null = null;\n\n  const step = (deltaMs: number) => {\n    // Fixed 1ms sub-steps keep the integration stable for stiff springs and\n    // independent of the frame rate.\n    const steps = Math.min(Math.max(Math.round(deltaMs), 1), 250);\n    for (let i = 0; i < steps; i++) {\n      const force = -stiffness * (value - target) - damping * velocity;\n      velocity += (force / mass) * 0.001;\n      value += velocity * 0.001;\n    }\n    if (Math.abs(target - value) < restDelta && Math.abs(velocity) < restSpeed) {\n      value = target;\n      velocity = 0;\n      stop?.();\n      stop = null;\n    }\n    onUpdate(value);\n  };\n\n  return {\n    set(next) {\n      target = next;\n      if (!stop && value !== target) stop = ticker.add(step);\n    },\n    jump(next) {\n      stop?.();\n      stop = null;\n      value = target = next;\n      velocity = 0;\n      onUpdate(value);\n    },\n    get: () => value,\n    destroy() {\n      stop?.();\n      stop = null;\n    },\n  };\n}\n",
      "type": "registry:component",
      "target": "components/custom/blocks/motion-curves.ts"
    }
  ],
  "docs": "Named export: Newsletter, with parts Heading, Intro, Form, Proof, Ticker and Issues. Composed from the input, button, marquee and tilted-card items, which install alongside it. `variant` is portraits | spotlight | issues, each styled for light and dark mode; `portraits` takes up to four faces; `Form` takes `onSubscribe(email)` (a promise holds the busy state), `action`, `successTitle`/`successText`; `accent` pins the glow and button colour; `reveal` is in-view or immediate.",
  "categories": [
    "marketing",
    "forms"
  ],
  "type": "registry:component"
}
