{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "hover-direction-caption",
  "type": "registry:component",
  "title": "Direction-Aware Caption",
  "description": "Project cards whose caption panel slides in from the edge the pointer entered and leaves through the edge it exits, with the text lines rising in a stagger and the image drifting the other way.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "hover",
    "direction aware",
    "caption",
    "cards",
    "portfolio",
    "overlay",
    "hover"
  ],
  "docs": "https://hyperblur.dev/effects/hover-direction-caption",
  "files": [
    {
      "path": "registry/hyperblur/hover-direction-caption.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/hover-direction-caption.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface HoverDirectionCaptionItem {\n  title: string;\n  kicker: string;\n  detail: string;\n  background: string;\n  href?: string;\n}\n\nexport interface HoverDirectionCaptionProps extends React.HTMLAttributes<HTMLDivElement> {\n  items?: HoverDirectionCaptionItem[];\n  columns?: number;\n  ratio?: number;\n  tint?: string;\n  accent?: string;\n  autoPlay?: boolean;\n}\n\ntype Edge = \"top\" | \"right\" | \"bottom\" | \"left\";\n\nconst defaults: HoverDirectionCaptionItem[] = [\n  { title: \"Tidewater House\", kicker: \"Residential\", detail: \"Lisbon · 2025\", background: \"linear-gradient(180deg, transparent 62%, #20303a 62%), linear-gradient(90deg, transparent 18%, #e9e3d6 18% 58%, transparent 58%), linear-gradient(180deg, #9ec3d8 0%, #d8e6ee 100%)\" },\n  { title: \"Copper Pavilion\", kicker: \"Cultural\", detail: \"Oslo · 2024\", background: \"radial-gradient(70% 50% at 50% 100%, #3b1d12 0%, transparent 70%), linear-gradient(160deg, transparent 50%, #b8673a 50% 72%, transparent 72%), linear-gradient(180deg, #f2c79a 0%, #d98a5a 100%)\" },\n  { title: \"Fernhall Studio\", kicker: \"Workplace\", detail: \"Kyoto · 2023\", background: \"repeating-linear-gradient(90deg, rgba(20,40,25,.5) 0 3px, transparent 3px 18px), radial-gradient(circle at 70% 30%, #d9f2c2 0 12%, transparent 13%), linear-gradient(180deg, #6f9a62 0%, #1d3522 100%)\" },\n];\n\nconst css = `\n.hb-wg11 { --hb-wg11-accent: #2f7bff; --hb-wg11-tint: rgba(10,10,10,.72); box-sizing: border-box; width: 100%; display: grid; grid-template-columns: repeat(var(--hb-wg11-cols), minmax(0, 1fr)); gap: 8px; font-family: inherit; color: #ededed; }\n.hb-wg11 *, .hb-wg11 *::before, .hb-wg11 *::after { box-sizing: border-box; }\n.hb-wg11-card { position: relative; display: block; aspect-ratio: var(--hb-wg11-ratio); border-radius: 12px; overflow: hidden; color: inherit; text-decoration: none; outline: none; box-shadow: inset 0 0 0 1px rgba(255,255,255,.07), 0 14px 26px -18px rgba(0,0,0,.95); -webkit-tap-highlight-color: transparent; cursor: pointer; }\n.hb-wg11-card:focus-visible { box-shadow: 0 0 0 2px #0a0a0a, 0 0 0 4px var(--hb-wg11-accent); }\n.hb-wg11-img { position: absolute; inset: -6%; background: var(--hb-wg11-bg); background-size: cover; transition: transform .8s cubic-bezier(.16,1,.3,1); }\n.hb-wg11-card[data-open=\"true\"] .hb-wg11-img { transform: scale(1.06) translate(var(--hb-wg11-ix, 0px), var(--hb-wg11-iy, 0px)); }\n.hb-wg11-over { position: absolute; inset: 0; display: flex; flex-direction: column; justify-content: flex-end; gap: 3px; padding: 10px; background: linear-gradient(180deg, color-mix(in srgb, var(--hb-wg11-tint) 55%, transparent), var(--hb-wg11-tint)); backdrop-filter: blur(3px) saturate(1.2); -webkit-backdrop-filter: blur(3px) saturate(1.2); transform: translate(0, 101%); will-change: transform; }\n.hb-wg11-line { display: block; overflow: hidden; }\n.hb-wg11-line > span { display: block; transform: translateY(110%); transition: transform .5s cubic-bezier(.2,.9,.25,1); }\n.hb-wg11-card[data-open=\"true\"] .hb-wg11-line > span { transform: none; }\n.hb-wg11-card[data-open=\"true\"] .hb-wg11-line:nth-child(2) > span { transition-delay: .06s; }\n.hb-wg11-card[data-open=\"true\"] .hb-wg11-line:nth-child(3) > span { transition-delay: .12s; }\n.hb-wg11-kicker { font-size: 8.5px; letter-spacing: .12em; text-transform: uppercase; color: color-mix(in srgb, var(--hb-wg11-accent) 55%, #fff); }\n.hb-wg11-title { font-size: 12.5px; font-weight: 650; letter-spacing: -.01em; line-height: 1.15; }\n.hb-wg11-detail { display: flex; align-items: center; justify-content: space-between; font-size: 9.5px; color: rgba(237,237,237,.7); }\n.hb-wg11-arrow { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }\n@media (prefers-reduced-motion: reduce) {\n  .hb-wg11-img, .hb-wg11-line > span { transition: none; }\n}\n`;\n\nconst offset: Record<Edge, string> = {\n  top: \"translate(0, -101%)\",\n  right: \"translate(101%, 0)\",\n  bottom: \"translate(0, 101%)\",\n  left: \"translate(-101%, 0)\",\n};\n\nfunction edgeOf(el: HTMLElement, cx: number, cy: number): Edge {\n  const r = el.getBoundingClientRect();\n  const x = (cx - r.left) / (r.width || 1) - 0.5;\n  const y = (cy - r.top) / (r.height || 1) - 0.5;\n  const ratio = (r.width || 1) / (r.height || 1);\n  if (Math.abs(x) * ratio > Math.abs(y)) return x > 0 ? \"right\" : \"left\";\n  return y > 0 ? \"bottom\" : \"top\";\n}\n\nexport function HoverDirectionCaption({\n  items = defaults,\n  columns = 3,\n  ratio = 0.78,\n  tint = \"rgba(10,10,10,.72)\",\n  accent = \"#2f7bff\",\n  autoPlay = true,\n  className = \"\",\n  style,\n  ...rest\n}: HoverDirectionCaptionProps) {\n  const overRefs = React.useRef<(HTMLSpanElement | null)[]>([]);\n  const cardRefs = React.useRef<(HTMLAnchorElement | null)[]>([]);\n  const anims = React.useRef<(Animation | null)[]>([]);\n  const [open, setOpen] = React.useState<boolean[]>(() => items.map(() => false));\n  const [engaged, setEngaged] = React.useState(false);\n  const lastPointer = React.useRef(\"mouse\");\n  const n = items.length;\n\n  const move = React.useCallback((i: number, from: string, to: string, into: boolean) => {\n    const el = overRefs.current[i];\n    const card = cardRefs.current[i];\n    if (!el || !card) return;\n    const reduce = window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n    anims.current[i]?.cancel();\n    const shift = into ? from : to;\n    const m = /translate\\((-?[\\d.]+)%, (-?[\\d.]+)%\\)/.exec(shift);\n    const ix = m ? -parseFloat(m[1]) * 0.04 : 0;\n    const iy = m ? -parseFloat(m[2]) * 0.04 : 0;\n    card.style.setProperty(\"--hb-wg11-ix\", `${ix.toFixed(2)}px`);\n    card.style.setProperty(\"--hb-wg11-iy\", `${iy.toFixed(2)}px`);\n    anims.current[i] = el.animate([{ transform: from }, { transform: to }], {\n      duration: reduce ? 0 : into ? 520 : 420,\n      easing: into ? \"cubic-bezier(.2,.9,.25,1)\" : \"cubic-bezier(.5,0,.75,0)\",\n      fill: \"forwards\",\n    });\n  }, []);\n\n  const set = React.useCallback((i: number, v: boolean) => {\n    setOpen((prev) => {\n      if (prev[i] === v) return prev;\n      const next = prev.slice();\n      next[i] = v;\n      return next;\n    });\n  }, []);\n\n  const enter = React.useCallback(\n    (i: number, edge: Edge) => {\n      move(i, offset[edge], \"translate(0, 0)\", true);\n      set(i, true);\n    },\n    [move, set],\n  );\n  const leave = React.useCallback(\n    (i: number, edge: Edge) => {\n      move(i, \"translate(0, 0)\", offset[edge], false);\n      set(i, false);\n    },\n    [move, set],\n  );\n\n  React.useEffect(() => {\n    if (!autoPlay || engaged || n === 0) return;\n    if (window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches) return;\n    let i = 0;\n    let shown = -1;\n    const id = window.setInterval(() => {\n      if (shown >= 0) leave(shown, \"right\");\n      shown = i;\n      enter(i, \"left\");\n      i = (i + 1) % n;\n    }, 1300);\n    return () => {\n      window.clearInterval(id);\n    };\n  }, [autoPlay, engaged, n, enter, leave]);\n\n  React.useEffect(() => {\n    const list = anims.current;\n    return () => list.forEach((a) => a?.cancel());\n  }, []);\n\n  return (\n    <div\n      className={`hb-wg11 ${className}`}\n      style={{ \"--hb-wg11-accent\": accent, \"--hb-wg11-tint\": tint, \"--hb-wg11-cols\": Math.max(1, columns), \"--hb-wg11-ratio\": String(ratio), ...style } as React.CSSProperties}\n      role=\"list\"\n      {...rest}\n    >\n      <style href=\"hb-hover-direction-caption\" precedence=\"default\">{css}</style>\n      {items.map((item, i) => (\n        <div role=\"listitem\" key={`${item.title}-${i}`} style={{ display: \"contents\" }}>\n          <a\n            ref={(el) => {\n              cardRefs.current[i] = el;\n            }}\n            href={item.href ?? \"#\"}\n            className=\"hb-wg11-card\"\n            data-open={open[i] ? \"true\" : \"false\"}\n            aria-label={`${item.title}, ${item.kicker}, ${item.detail}`}\n            style={{ \"--hb-wg11-bg\": item.background } as React.CSSProperties}\n            onPointerDown={(e) => {\n              lastPointer.current = e.pointerType;\n            }}\n            onPointerEnter={(e) => {\n              if (e.pointerType !== \"mouse\") return;\n              if (!engaged) {\n                setEngaged(true);\n                items.forEach((_, j) => {\n                  if (j !== i && open[j]) leave(j, \"bottom\");\n                });\n              }\n              enter(i, edgeOf(e.currentTarget, e.clientX, e.clientY));\n            }}\n            onPointerLeave={(e) => {\n              if (e.pointerType !== \"mouse\") return;\n              leave(i, edgeOf(e.currentTarget, e.clientX, e.clientY));\n            }}\n            onFocus={() => {\n              if (!engaged) setEngaged(true);\n              if (!open[i]) enter(i, \"bottom\");\n            }}\n            onBlur={() => {\n              if (lastPointer.current !== \"mouse\") return;\n              if (open[i] && !(cardRefs.current[i]?.matches(\":hover\") ?? false)) leave(i, \"bottom\");\n            }}\n            onClick={(e) => {\n              if (lastPointer.current === \"mouse\") {\n                if (!item.href) e.preventDefault();\n                return;\n              }\n              if (!open[i]) {\n                e.preventDefault();\n                setEngaged(true);\n                items.forEach((_, j) => {\n                  if (j !== i && open[j]) leave(j, \"bottom\");\n                });\n                enter(i, \"bottom\");\n              } else if (!item.href) e.preventDefault();\n            }}\n          >\n            <span className=\"hb-wg11-img\" aria-hidden=\"true\" />\n            <span\n              ref={(el) => {\n                overRefs.current[i] = el;\n              }}\n              className=\"hb-wg11-over\"\n              aria-hidden=\"true\"\n            >\n              <span className=\"hb-wg11-line\">\n                <span className=\"hb-wg11-kicker\">{item.kicker}</span>\n              </span>\n              <span className=\"hb-wg11-line\">\n                <span className=\"hb-wg11-title\">{item.title}</span>\n              </span>\n              <span className=\"hb-wg11-line\">\n                <span className=\"hb-wg11-detail\">\n                  {item.detail}\n                  <svg className=\"hb-wg11-arrow\" viewBox=\"0 0 14 14\">\n                    <path d=\"M3.5 10.5l7-7M5 3.5h5.5V9\" />\n                  </svg>\n                </span>\n              </span>\n            </span>\n          </a>\n        </div>\n      ))}\n    </div>\n  );\n}\n"
    }
  ]
}