{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "bento-hero",
  "title": "Bento Hero",
  "description": "A hero built as a hairline bento grid: the headline shares the first screen with live cells, from counting totals and a period switch to uptime bars and rotating activity.",
  "dependencies": [
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "registry/new-york/bento-hero/bento-hero.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport { clsx, type ClassValue } from \"clsx\";\nimport { twMerge } from \"tailwind-merge\";\n\nfunction cn(...inputs: ClassValue[]) {\n  return twMerge(clsx(inputs));\n}\n\nexport type BentoHeroTheme = \"dark\" | \"light\";\n\nexport interface BentoStat {\n  value: number;\n  suffix?: string;\n  label: string;\n}\n\nexport interface BentoHeroProps extends Omit<\n  React.ComponentPropsWithoutRef<\"section\">,\n  \"title\"\n> {\n  theme?: BentoHeroTheme;\n  /** The serif headline on the centre tile. */\n  title?: string;\n  eyebrow?: string;\n  description?: string;\n  action?: { label: string; href?: string; onClick?: () => void } | null;\n  /** Photo in the centre tile, the one that grows to fill the hero. */\n  image?: string;\n  alt?: string;\n  /** Plays in the centre tile instead of the photo. */\n  video?: string;\n  /** The two photo tiles at the sides. */\n  sideImages?: [string, string];\n  /** Shown once the centre tile has filled the hero. */\n  revealHeading?: string;\n  revealDescription?: string;\n  /** The first two also get tiles of their own. */\n  stats?: BentoStat[];\n  /** Soft light that follows the pointer. */\n  showGlow?: boolean;\n  /** How far people scroll to open the centre tile, in hero heights. */\n  scrollDistance?: number;\n  /** Height from tablet width up, in px. */\n  minHeight?: number;\n}\n\nconst PALETTES = {\n  dark: {\n    bg: \"#0A0A0A\",\n    tile: \"#121212\",\n    border: \"rgba(255,255,255,0.09)\",\n    text: \"#FFFFFF\",\n    sub: \"rgba(255,255,255,0.62)\",\n    faint: \"rgba(255,255,255,0.42)\",\n    pill: \"rgba(255,255,255,0.08)\",\n    pillHover: \"rgba(255,255,255,0.18)\",\n    pillBorder: \"rgba(255,255,255,0.35)\",\n    glow: \"rgba(255,255,255,0.1)\",\n  },\n  light: {\n    bg: \"#EFEDE8\",\n    tile: \"#F8F7F3\",\n    border: \"rgba(10,10,10,0.1)\",\n    text: \"#0A0A0A\",\n    sub: \"rgba(10,10,10,0.62)\",\n    faint: \"rgba(10,10,10,0.44)\",\n    pill: \"rgba(10,10,10,0.04)\",\n    pillHover: \"rgba(10,10,10,0.1)\",\n    pillBorder: \"rgba(10,10,10,0.3)\",\n    glow: \"rgba(255,255,255,0.7)\",\n  },\n};\n\nconst DEFAULT_STATS: BentoStat[] = [\n  { value: 42, label: \"Routes\" },\n  { value: 18, suffix: \"k\", label: \"Members\" },\n  { value: 96, suffix: \"%\", label: \"Come back\" },\n];\n\n/** Where the centre tile starts, as insets in percent: top, right, bottom, left. */\nconst WIDE_START = [3, 29.4, 34, 29.4];\nconst NARROW_START = [2.5, 4, 44, 4];\n\nconst START_RADIUS = 24;\nconst MEDIA_ZOOM = 1.3;\n\nconst clamp = (v: number, a: number, b: number) => Math.min(b, Math.max(a, v));\nconst smoothstep = (a: number, b: number, x: number) => {\n  const t = clamp((x - a) / (b - a), 0, 1);\n  return t * t * (3 - 2 * t);\n};\n\nconst label = \"text-[11px] font-medium tracking-[0.16em] uppercase\";\n\nfunction useReducedMotion() {\n  return React.useSyncExternalStore(\n    (callback) => {\n      const query = window.matchMedia(\"(prefers-reduced-motion: reduce)\");\n      query.addEventListener(\"change\", callback);\n      return () => query.removeEventListener(\"change\", callback);\n    },\n    () => window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches,\n    () => false,\n  );\n}\n\nfunction Pill({\n  action,\n  color,\n  fill,\n  fillHover,\n  border,\n}: {\n  action: { label: string; href?: string; onClick?: () => void };\n  color: string;\n  fill: string;\n  fillHover: string;\n  border: string;\n}) {\n  const cls = cn(\n    label,\n    \"inline-flex cursor-pointer items-center justify-center rounded-full border bg-[var(--pill)] px-[22px] py-2.5 no-underline backdrop-blur-[8px] transition-[transform,background] duration-200 hover:scale-[1.04] hover:bg-[var(--pill-hover)]\",\n  );\n  const style = {\n    \"--pill\": fill,\n    \"--pill-hover\": fillHover,\n    borderColor: border,\n    color,\n  } as React.CSSProperties;\n  return action.href ? (\n    <a href={action.href} className={cls} style={style}>\n      {action.label}\n    </a>\n  ) : (\n    <button\n      type=\"button\"\n      onClick={action.onClick}\n      className={cls}\n      style={style}\n    >\n      {action.label}\n    </button>\n  );\n}\n\nexport function BentoHero({\n  theme = \"dark\",\n  title = \"Keep Moving\",\n  eyebrow = \"Field notes, volume nine\",\n  description = \"Gear, routes and training plans from people who go out in every weather.\",\n  action = { label: \"See the collection\" },\n  image = \"/demo/26.webp\",\n  alt = \"A rider and horse at full gallop, blurred with speed\",\n  video,\n  sideImages = [\"/demo/23.webp\", \"/demo/34.webp\"],\n  revealHeading = \"Built for the long way round.\",\n  revealDescription = \"Every route is walked, ridden and rewritten by the people who publish it.\",\n  stats = DEFAULT_STATS,\n  showGlow = true,\n  scrollDistance = 1.2,\n  minHeight = 720,\n  className,\n  style,\n  ...props\n}: BentoHeroProps) {\n  const pal = PALETTES[theme];\n  const reduce = useReducedMotion();\n  const scrollerRef = React.useRef<HTMLDivElement>(null);\n  const frameRef = React.useRef<HTMLDivElement>(null);\n  const mediaRef = React.useRef<HTMLDivElement>(null);\n  const titleRef = React.useRef<HTMLDivElement>(null);\n  const cueRef = React.useRef<HTMLDivElement>(null);\n  const dotRef = React.useRef<SVGCircleElement>(null);\n  const scrimRef = React.useRef<HTMLDivElement>(null);\n  const revealRef = React.useRef<HTMLDivElement>(null);\n  const dividerRef = React.useRef<HTMLDivElement>(null);\n  const glowRef = React.useRef<HTMLDivElement>(null);\n  const tileRefs = React.useRef<(HTMLDivElement | null)[]>([]);\n  const countRefs = React.useRef<(HTMLSpanElement | null)[]>([]);\n  // The extra quarter holds the finished state for a moment before the hero scrolls away.\n  const travel = Math.max(0.2, scrollDistance);\n  const track = 1 + travel * 1.25;\n\n  // Everything is scrubbed by one eased progress value and written straight to the elements.\n  React.useEffect(() => {\n    const scroller = scrollerRef.current;\n    const frame = frameRef.current;\n    const media = mediaRef.current;\n    if (!scroller || !frame || !media) return;\n    let raf = 0;\n    let prev = 0;\n    let current = -1;\n\n    const apply = (p: number) => {\n      const e = smoothstep(0, 1, p);\n      const start = scroller.clientWidth >= 640 ? WIDE_START : NARROW_START;\n      const [t, r, b, l] = start.map((v) => (v * (1 - e)).toFixed(3));\n      frame.style.clipPath = `inset(${t}% ${r}% ${b}% ${l}% round ${(START_RADIUS * (1 - e)).toFixed(2)}px)`;\n      media.style.transform = `scale(${(MEDIA_ZOOM + (1 - MEDIA_ZOOM) * e).toFixed(4)})`;\n      if (scrimRef.current) {\n        scrimRef.current.style.opacity = `${(0.2 + 0.5 * e).toFixed(3)}`;\n      }\n\n      const out = smoothstep(0.3, 0.5, p);\n      if (titleRef.current) {\n        titleRef.current.style.opacity = `${1 - out}`;\n        titleRef.current.style.transform = `translate3d(0, ${(-30 * out).toFixed(1)}px, 0) scale(${(1 + 0.06 * out).toFixed(3)})`;\n      }\n      if (cueRef.current) {\n        cueRef.current.style.opacity = `${1 - smoothstep(0, 0.1, p)}`;\n      }\n\n      // Each tile leaves through its own edge as the centre tile needs the room.\n      const leave = smoothstep(0, 0.7, p);\n      tileRefs.current.forEach((tile) => {\n        if (!tile) return;\n        const dx = Number(tile.dataset.dx);\n        const dy = Number(tile.dataset.dy);\n        tile.style.transform = `translate3d(${(dx * 140 * leave).toFixed(1)}px, ${(dy * 140 * leave).toFixed(1)}px, 0) scale(${(1 - 0.06 * leave).toFixed(3)})`;\n        tile.style.opacity = `${1 - smoothstep(0.1, 0.62, p)}`;\n        tile.style.visibility = p > 0.62 ? \"hidden\" : \"visible\";\n      });\n\n      const inn = smoothstep(0.55, 0.74, p);\n      if (revealRef.current) {\n        revealRef.current.style.opacity = `${inn}`;\n        revealRef.current.style.transform = `translate3d(0, ${(18 * (1 - inn)).toFixed(1)}px, 0)`;\n        revealRef.current.style.visibility = p > 0.5 ? \"visible\" : \"hidden\";\n      }\n      if (dividerRef.current) {\n        dividerRef.current.style.transform = `scaleX(${smoothstep(0.58, 0.76, p).toFixed(3)})`;\n      }\n      const count = smoothstep(0.62, 0.9, p);\n      countRefs.current.forEach((el, i) => {\n        const stat = stats[i];\n        if (el && stat) {\n          el.textContent = `${Math.round(stat.value * count)}${stat.suffix ?? \"\"}`;\n        }\n      });\n    };\n\n    const progress = () => {\n      const distance = scroller.clientHeight * travel;\n      return distance > 0 ? clamp(scroller.scrollTop / distance, 0, 1) : 0;\n    };\n\n    const frameLoop = (now: number) => {\n      const dt = Math.min(0.05, prev ? (now - prev) / 1000 : 1 / 60);\n      prev = now;\n      const target = progress();\n      const next = current + (target - current) * (1 - Math.exp(-dt * 7));\n      const settled = Math.abs(target - next) < 0.0006;\n      current = settled ? target : next;\n      apply(current);\n      if (settled) {\n        raf = 0;\n        prev = 0;\n      } else raf = requestAnimationFrame(frameLoop);\n    };\n\n    const onScroll = () => {\n      if (reduce) {\n        current = progress();\n        apply(current);\n      } else if (!raf) raf = requestAnimationFrame(frameLoop);\n    };\n\n    current = progress();\n    apply(current);\n    scroller.addEventListener(\"scroll\", onScroll, { passive: true });\n    const ro = new ResizeObserver(() => apply(current));\n    ro.observe(scroller);\n    return () => {\n      cancelAnimationFrame(raf);\n      scroller.removeEventListener(\"scroll\", onScroll);\n      ro.disconnect();\n    };\n  }, [reduce, travel, stats]);\n\n  // The little scroll cue nods until people start scrolling.\n  React.useEffect(() => {\n    const dot = dotRef.current;\n    if (!dot || reduce) return;\n    const nod = dot.animate(\n      [\n        { transform: \"translateY(0)\", opacity: 1 },\n        { transform: \"translateY(9px)\", opacity: 0.2 },\n      ],\n      { duration: 1400, iterations: Infinity, easing: \"ease-in-out\" },\n    );\n    return () => nod.cancel();\n  }, [reduce]);\n\n  const moveGlow = (e: React.PointerEvent<HTMLDivElement>) => {\n    const glow = glowRef.current;\n    if (!glow || e.pointerType !== \"mouse\") return;\n    const r = e.currentTarget.getBoundingClientRect();\n    glow.style.opacity = \"1\";\n    glow.style.transform = `translate3d(${(e.clientX - r.left - 190).toFixed(0)}px, ${(e.clientY - r.top - 190).toFixed(0)}px, 0)`;\n  };\n\n  const tile = \"absolute overflow-hidden rounded-[24px] will-change-transform\";\n  const photo = \"absolute inset-0 size-full object-cover grayscale select-none\";\n  const pair = stats.slice(0, 2);\n\n  return (\n    <section\n      className={cn(\"@container w-full\", className)}\n      style={\n        {\n          \"--h\": `${minHeight}px`,\n          background: pal.bg,\n          color: pal.text,\n          fontFamily: \"Inter, -apple-system, BlinkMacSystemFont, sans-serif\",\n          ...style,\n        } as React.CSSProperties\n      }\n      {...props}\n    >\n      <div\n        ref={scrollerRef}\n        role=\"region\"\n        aria-label={title}\n        tabIndex={0}\n        className=\"relative h-[640px] overflow-x-hidden overflow-y-auto outline-none @[640px]:h-[var(--h)]\"\n        style={{ scrollbarWidth: \"none\" }}\n      >\n        <div className=\"relative w-full\" style={{ height: `${track * 100}%` }}>\n          <div\n            onPointerMove={showGlow ? moveGlow : undefined}\n            onPointerLeave={() => {\n              if (glowRef.current) glowRef.current.style.opacity = \"0\";\n            }}\n            className=\"sticky top-0 w-full overflow-hidden\"\n            style={{ height: `${100 / track}%`, background: pal.bg }}\n          >\n            <div\n              data-dx={-1}\n              data-dy={-0.3}\n              ref={(el) => {\n                tileRefs.current[0] = el;\n              }}\n              className={cn(\n                tile,\n                \"top-[57.5%] left-[4%] h-[20%] w-[45%] @[640px]:top-[3%] @[640px]:left-[2%] @[640px]:h-[61%] @[640px]:w-[26%]\",\n              )}\n            >\n              {/* eslint-disable-next-line @next/next/no-img-element */}\n              <img\n                src={sideImages[0]}\n                alt=\"\"\n                draggable={false}\n                className={photo}\n              />\n            </div>\n\n            {pair[0] && (\n              <div\n                data-dx={-1}\n                data-dy={0.5}\n                ref={(el) => {\n                  tileRefs.current[1] = el;\n                }}\n                className={cn(\n                  tile,\n                  \"top-[57.5%] left-[51%] flex h-[20%] w-[45%] flex-col justify-between p-5 @[640px]:top-[65.5%] @[640px]:left-[2%] @[640px]:h-[31.5%] @[640px]:w-[26%] @[640px]:p-6\",\n                )}\n                style={{\n                  background: pal.tile,\n                  boxShadow: `inset 0 0 0 1px ${pal.border}`,\n                }}\n              >\n                <p className={cn(label, \"m-0\")} style={{ color: pal.faint }}>\n                  {pair[0].label}\n                </p>\n                <p className=\"m-0 font-serif text-[44px] leading-none font-normal tracking-[-0.02em] @[640px]:text-[64px]\">\n                  {pair[0].value}\n                  {pair[0].suffix}\n                </p>\n              </div>\n            )}\n\n            <div\n              data-dx={0}\n              data-dy={1}\n              ref={(el) => {\n                tileRefs.current[2] = el;\n              }}\n              className={cn(\n                tile,\n                \"top-[79%] right-[4%] left-[4%] flex h-[19%] flex-col justify-between gap-2 p-5 @[640px]:top-[67.5%] @[640px]:right-[29.4%] @[640px]:left-[29.4%] @[640px]:h-[29.5%] @[640px]:p-6\",\n              )}\n              style={{\n                background: pal.tile,\n                boxShadow: `inset 0 0 0 1px ${pal.border}`,\n              }}\n            >\n              <div>\n                <p className={cn(label, \"m-0\")} style={{ color: pal.faint }}>\n                  {eyebrow}\n                </p>\n                <p\n                  className=\"m-0 mt-2 hidden text-[14px] leading-[1.5] @[640px]:block\"\n                  style={{ color: pal.sub }}\n                >\n                  {description}\n                </p>\n              </div>\n              {action && (\n                <div>\n                  <Pill\n                    action={action}\n                    color={pal.text}\n                    fill={pal.pill}\n                    fillHover={pal.pillHover}\n                    border={pal.pillBorder}\n                  />\n                </div>\n              )}\n            </div>\n\n            {pair[1] && (\n              <div\n                data-dx={1}\n                data-dy={-0.5}\n                ref={(el) => {\n                  tileRefs.current[3] = el;\n                }}\n                className={cn(\n                  tile,\n                  \"hidden flex-col justify-between p-6 @[640px]:top-[3%] @[640px]:right-[2%] @[640px]:flex @[640px]:h-[31.5%] @[640px]:w-[26%]\",\n                )}\n                style={{\n                  background: pal.tile,\n                  boxShadow: `inset 0 0 0 1px ${pal.border}`,\n                }}\n              >\n                <p className={cn(label, \"m-0\")} style={{ color: pal.faint }}>\n                  {pair[1].label}\n                </p>\n                <p className=\"m-0 font-serif text-[64px] leading-none font-normal tracking-[-0.02em]\">\n                  {pair[1].value}\n                  {pair[1].suffix}\n                </p>\n              </div>\n            )}\n\n            <div\n              data-dx={1}\n              data-dy={0.3}\n              ref={(el) => {\n                tileRefs.current[4] = el;\n              }}\n              className={cn(\n                tile,\n                \"hidden @[640px]:top-[36%] @[640px]:right-[2%] @[640px]:block @[640px]:h-[61%] @[640px]:w-[26%]\",\n              )}\n            >\n              {/* eslint-disable-next-line @next/next/no-img-element */}\n              <img\n                src={sideImages[1]}\n                alt=\"\"\n                draggable={false}\n                className={photo}\n              />\n            </div>\n\n            {/* The centre tile is the full hero, clipped down, so growing it never moves the picture. */}\n            <div\n              ref={frameRef}\n              className=\"absolute inset-0 [clip-path:inset(2.5%_4%_44%_4%_round_24px)] will-change-[clip-path] @[640px]:[clip-path:inset(3%_29.4%_34%_29.4%_round_24px)]\"\n            >\n              <div\n                ref={mediaRef}\n                className=\"absolute inset-0 origin-[50%_34%] will-change-transform\"\n                style={{ transform: `scale(${MEDIA_ZOOM})` }}\n              >\n                {video ? (\n                  <video\n                    src={video}\n                    muted\n                    loop\n                    autoPlay={!reduce}\n                    playsInline\n                    aria-hidden=\"true\"\n                    className={photo}\n                  />\n                ) : (\n                  // eslint-disable-next-line @next/next/no-img-element\n                  <img\n                    src={image}\n                    alt={alt}\n                    draggable={false}\n                    className={photo}\n                  />\n                )}\n              </div>\n              <div\n                ref={scrimRef}\n                aria-hidden=\"true\"\n                className=\"pointer-events-none absolute inset-0\"\n                style={{\n                  opacity: 0.2,\n                  background:\n                    \"linear-gradient(to top, rgba(0,0,0,0.9) 0%, rgba(0,0,0,0.6) 45%, rgba(0,0,0,0.7) 100%)\",\n                }}\n              />\n              <div\n                ref={revealRef}\n                className=\"invisible absolute inset-0 flex flex-col items-center justify-center px-[8%] text-center text-white opacity-0\"\n              >\n                <h2 className=\"m-0 mb-3 font-serif text-[32px] leading-[1.15] font-normal tracking-[-0.02em] @[640px]:text-[44px]\">\n                  {revealHeading}\n                </h2>\n                <div\n                  ref={dividerRef}\n                  aria-hidden=\"true\"\n                  className=\"mb-3.5 h-px w-16 bg-white\"\n                  style={{ transform: \"scaleX(0)\" }}\n                />\n                <p className=\"m-0 max-w-[420px] text-[14px] leading-[1.6] text-white/70\">\n                  {revealDescription}\n                </p>\n                {stats.length > 0 && (\n                  <dl className=\"m-0 mt-6 flex gap-8\">\n                    {stats.map((stat, i) => (\n                      <div\n                        key={stat.label}\n                        className=\"flex flex-col-reverse items-center gap-1\"\n                      >\n                        <dt className={cn(label, \"text-[10px] text-white/50\")}>\n                          {stat.label}\n                        </dt>\n                        <dd className=\"m-0 font-serif text-[28px] text-white tabular-nums\">\n                          <span\n                            ref={(el) => {\n                              countRefs.current[i] = el;\n                            }}\n                          >\n                            0{stat.suffix ?? \"\"}\n                          </span>\n                        </dd>\n                      </div>\n                    ))}\n                  </dl>\n                )}\n                {action && (\n                  <div className=\"mt-6\">\n                    <Pill\n                      action={action}\n                      color=\"rgba(255,255,255,0.85)\"\n                      fill=\"rgba(255,255,255,0.08)\"\n                      fillHover=\"rgba(255,255,255,0.18)\"\n                      border=\"rgba(255,255,255,0.35)\"\n                    />\n                  </div>\n                )}\n              </div>\n            </div>\n\n            <div className=\"pointer-events-none absolute inset-x-[4%] top-[2.5%] h-[53.5%] @[640px]:inset-x-[29.4%] @[640px]:top-[3%] @[640px]:h-[63%]\">\n              <div\n                ref={titleRef}\n                className=\"absolute inset-0 flex items-center justify-center px-4\"\n              >\n                <h1\n                  className=\"m-0 text-center font-serif text-[54px] leading-[1.06] font-normal tracking-[-0.02em] text-white @[640px]:text-[6.8cqw]\"\n                  style={{ textShadow: \"0 2px 28px rgba(0,0,0,0.5)\" }}\n                >\n                  {title}\n                </h1>\n              </div>\n              <div\n                ref={cueRef}\n                aria-hidden=\"true\"\n                className=\"absolute inset-x-0 bottom-4 flex flex-col items-center gap-1.5 text-white/80\"\n              >\n                <svg width=\"22\" height=\"36\" viewBox=\"0 0 22 36\" fill=\"none\">\n                  <rect\n                    x=\"1.5\"\n                    y=\"1.5\"\n                    width=\"19\"\n                    height=\"33\"\n                    rx=\"9.5\"\n                    stroke=\"currentColor\"\n                    strokeWidth=\"1.6\"\n                  />\n                  <circle\n                    ref={dotRef}\n                    cx=\"11\"\n                    cy=\"10\"\n                    r=\"2.2\"\n                    fill=\"currentColor\"\n                  />\n                </svg>\n              </div>\n            </div>\n\n            {showGlow && (\n              <div\n                ref={glowRef}\n                aria-hidden=\"true\"\n                className=\"pointer-events-none absolute top-0 left-0 size-[380px] rounded-full opacity-0 transition-opacity duration-300\"\n                style={{\n                  background: `radial-gradient(circle, ${pal.glow} 0%, transparent 70%)`,\n                }}\n              />\n            )}\n          </div>\n        </div>\n      </div>\n    </section>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}