{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "hover-play-tiles",
  "type": "registry:component",
  "title": "Hover Play Tiles",
  "description": "Video-style preview tiles that start playing the moment the pointer lands on them, with a live timecode and progress bar, and pause where they left off when it leaves. Tap toggles playback on touch.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "hover",
    "video",
    "preview",
    "hover to play",
    "tiles",
    "timecode",
    "media"
  ],
  "docs": "https://hyperblur.dev/effects/hover-play-tiles",
  "files": [
    {
      "path": "registry/hyperblur/hover-play-tiles.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/hover-play-tiles.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport type HoverPlayTilesScene = \"tide\" | \"orbit\" | \"city\" | \"pulse\";\n\nexport interface HoverPlayTilesItem {\n  title: string;\n  duration: number;\n  scene: HoverPlayTilesScene;\n}\n\nexport interface HoverPlayTilesProps extends React.HTMLAttributes<HTMLDivElement> {\n  items?: HoverPlayTilesItem[];\n  columns?: number;\n  autoPlay?: boolean;\n  accent?: string;\n  onPlayChange?: (index: number, playing: boolean) => void;\n}\n\nconst defaults: HoverPlayTilesItem[] = [\n  { title: \"Swell report\", duration: 24, scene: \"tide\" },\n  { title: \"Moonrise\", duration: 18, scene: \"orbit\" },\n  { title: \"Night shift\", duration: 32, scene: \"city\" },\n  { title: \"Live set\", duration: 15, scene: \"pulse\" },\n];\n\nconst css = `\n.hb-wg10 { --hb-wg10-accent: #2f7bff; box-sizing: border-box; width: 100%; display: grid; grid-template-columns: repeat(var(--hb-wg10-cols), minmax(0, 1fr)); gap: 8px; font-family: inherit; color: #ededed; }\n.hb-wg10 *, .hb-wg10 *::before, .hb-wg10 *::after { box-sizing: border-box; }\n.hb-wg10-tile { appearance: none; border: 0; margin: 0; padding: 0; font: inherit; color: inherit; cursor: pointer; position: relative; aspect-ratio: 16 / 10; border-radius: 10px; overflow: hidden; background: #111; box-shadow: inset 0 0 0 1px rgba(255,255,255,.07), 0 12px 24px -16px rgba(0,0,0,.9); outline: none; text-align: left; transition: transform .45s cubic-bezier(.2,.9,.25,1), box-shadow .3s ease; -webkit-tap-highlight-color: transparent; }\n.hb-wg10-tile[data-playing=\"true\"] { transform: scale(1.03); box-shadow: inset 0 0 0 1px rgba(255,255,255,.16), 0 18px 30px -16px rgba(0,0,0,.95); z-index: 1; }\n.hb-wg10-tile:focus-visible { box-shadow: 0 0 0 2px #0a0a0a, 0 0 0 4px var(--hb-wg10-accent); }\n.hb-wg10-scene { position: absolute; inset: 0; overflow: hidden; }\n.hb-wg10-scene * { animation-play-state: paused !important; }\n.hb-wg10-tile[data-playing=\"true\"] .hb-wg10-scene * { animation-play-state: running !important; }\n.hb-wg10-tide { background: linear-gradient(180deg, #ffcf9a 0%, #ff8a6a 40%, #2a4f7a 41%, #0c2240 100%); }\n.hb-wg10-sun { position: absolute; left: 50%; top: 18%; width: 26%; aspect-ratio: 1; margin-left: -13%; border-radius: 50%; background: radial-gradient(circle, #fff3d1 0 45%, #ffbf7a 70%, transparent 72%); }\n.hb-wg10-wave { position: absolute; left: -50%; width: 200%; height: 22%; background: repeating-radial-gradient(ellipse 14px 7px at 50% 0%, rgba(255,255,255,.28) 0 1px, transparent 1.5px 7px); background-size: 28px 100%; animation: hb-wg10-slide 3.2s linear infinite; }\n.hb-wg10-wave:nth-child(2) { top: 46%; opacity: .7; }\n.hb-wg10-wave:nth-child(3) { top: 62%; animation-duration: 2.3s; animation-direction: reverse; }\n.hb-wg10-wave:nth-child(4) { top: 80%; animation-duration: 1.8s; opacity: .6; }\n.hb-wg10-orbit { background: radial-gradient(circle at 50% 50%, #1a1d3a 0%, #07080f 75%); }\n.hb-wg10-stars { position: absolute; inset: 0; background-image: radial-gradient(1px 1px at 12% 20%, #fff, transparent), radial-gradient(1px 1px at 80% 30%, #fff, transparent), radial-gradient(1px 1px at 30% 80%, #cfd8ff, transparent), radial-gradient(1px 1px at 66% 70%, #fff, transparent), radial-gradient(1px 1px at 90% 85%, #cfd8ff, transparent); animation: hb-wg10-twinkle 2.4s ease-in-out infinite alternate; }\n.hb-wg10-planet { position: absolute; left: 50%; top: 50%; width: 34%; aspect-ratio: 1; transform: translate(-50%, -50%); border-radius: 50%; background: radial-gradient(circle at 35% 30%, #a8c4ff 0%, #4c6fd8 45%, #1a2560 100%); box-shadow: inset -8px -6px 14px rgba(0,0,0,.55), 0 0 22px rgba(90,130,255,.35); }\n.hb-wg10-moon-path { position: absolute; left: 50%; top: 50%; width: 70%; aspect-ratio: 1; margin: -35% 0 0 -35%; animation: hb-wg10-spin 4.5s linear infinite; }\n.hb-wg10-moon { position: absolute; left: 0; top: 50%; width: 9%; aspect-ratio: 1; margin-top: -4.5%; border-radius: 50%; background: radial-gradient(circle at 35% 30%, #fff, #a0a0a8); }\n.hb-wg10-city { background: linear-gradient(180deg, #0f1430 0%, #3a1f4f 70%, #6a2f4f 100%); }\n.hb-wg10-sky { position: absolute; left: 0; bottom: 0; width: 200%; height: 70%; display: flex; align-items: flex-end; animation: hb-wg10-slide 7s linear infinite; }\n.hb-wg10-bld { flex: 0 0 auto; margin-right: 3px; background: #0a0c1a; background-image: repeating-linear-gradient(0deg, transparent 0 5px, rgba(255,206,110,.55) 5px 6.5px), repeating-linear-gradient(90deg, transparent 0 4px, #0a0c1a 4px 7px); box-shadow: inset 0 1px 0 rgba(255,255,255,.08); }\n.hb-wg10-pulse { background: radial-gradient(90% 70% at 50% 100%, #3b0f45 0%, #0b0610 70%); display: flex; align-items: flex-end; justify-content: center; gap: 4%; padding: 0 12% 18%; }\n.hb-wg10-eq { width: 7%; height: 70%; border-radius: 3px 3px 1px 1px; background: linear-gradient(180deg, #ff6ad5, #7a5cff); transform-origin: 50% 100%; animation: hb-wg10-eq .9s cubic-bezier(.4,0,.2,1) infinite alternate; }\n.hb-wg10-poster { position: absolute; inset: 0; display: grid; place-items: center; background: linear-gradient(180deg, rgba(0,0,0,.05), rgba(0,0,0,.45)); transition: opacity .35s ease; }\n.hb-wg10-tile[data-playing=\"true\"] .hb-wg10-poster { opacity: 0; }\n.hb-wg10-play { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; background: rgba(10,10,10,.55); box-shadow: 0 0 0 1px rgba(255,255,255,.22), inset 0 1px 0 rgba(255,255,255,.12); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); transition: transform .4s cubic-bezier(.3,1.5,.4,1); }\n.hb-wg10-play svg { width: 11px; height: 11px; margin-left: 2px; fill: #ededed; }\n.hb-wg10-tile:hover .hb-wg10-play { transform: scale(1.12); }\n.hb-wg10-info { position: absolute; left: 7px; right: 7px; bottom: 7px; display: flex; align-items: center; justify-content: space-between; gap: 6px; pointer-events: none; }\n.hb-wg10-name { font-size: 10.5px; font-weight: 600; text-shadow: 0 1px 6px rgba(0,0,0,.7); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }\n.hb-wg10-time { flex: none; padding: 1px 5px; border-radius: 4px; background: rgba(10,10,10,.7); font-family: var(--font-mono, ui-monospace, monospace); font-size: 9px; color: #ededed; font-variant-numeric: tabular-nums; }\n.hb-wg10-bar { position: absolute; left: 0; right: 0; bottom: 0; height: 2.5px; background: rgba(255,255,255,.14); }\n.hb-wg10-fill { display: block; height: 100%; width: 100%; background: var(--hb-wg10-accent); transform-origin: 0 50%; transform: scaleX(var(--hb-wg10-p, 0)); box-shadow: 0 0 8px var(--hb-wg10-accent); }\n.hb-wg10-live { position: absolute; left: 7px; top: 7px; display: inline-flex; align-items: center; gap: 4px; padding: 1px 5px; border-radius: 4px; background: rgba(10,10,10,.6); font-size: 8.5px; letter-spacing: .08em; text-transform: uppercase; opacity: 0; transform: translateY(-3px); transition: opacity .3s ease, transform .35s ease; }\n.hb-wg10-live::before { content: \"\"; width: 5px; height: 5px; border-radius: 50%; background: #ff4d4f; }\n.hb-wg10-tile[data-playing=\"true\"] .hb-wg10-live { opacity: 1; transform: none; }\n@keyframes hb-wg10-slide { to { transform: translateX(-50%); } }\n@keyframes hb-wg10-spin { to { transform: rotate(360deg); } }\n@keyframes hb-wg10-twinkle { to { opacity: .45; } }\n@keyframes hb-wg10-eq { 0% { transform: scaleY(.2); } 100% { transform: scaleY(1); } }\n@media (prefers-reduced-motion: reduce) {\n  .hb-wg10-scene * { animation: none !important; }\n  .hb-wg10-tile, .hb-wg10-poster, .hb-wg10-play, .hb-wg10-live { transition: none; }\n}\n`;\n\nfunction hash(n: number) {\n  let x = Math.imul((n | 0) ^ 0x2545f491, 0x9e3779b1) >>> 0;\n  x ^= x >>> 15;\n  x = Math.imul(x, 0x85ebca6b) >>> 0;\n  x ^= x >>> 13;\n  return (x >>> 0) / 4294967296;\n}\n\nfunction Scene({ scene }: { scene: HoverPlayTilesScene }) {\n  if (scene === \"tide\")\n    return (\n      <div className=\"hb-wg10-scene hb-wg10-tide\">\n        <span className=\"hb-wg10-sun\" />\n        <span className=\"hb-wg10-wave\" />\n        <span className=\"hb-wg10-wave\" />\n        <span className=\"hb-wg10-wave\" />\n      </div>\n    );\n  if (scene === \"orbit\")\n    return (\n      <div className=\"hb-wg10-scene hb-wg10-orbit\">\n        <span className=\"hb-wg10-stars\" />\n        <span className=\"hb-wg10-planet\" />\n        <span className=\"hb-wg10-moon-path\">\n          <span className=\"hb-wg10-moon\" />\n        </span>\n      </div>\n    );\n  if (scene === \"city\")\n    return (\n      <div className=\"hb-wg10-scene hb-wg10-city\">\n        <div className=\"hb-wg10-sky\">\n          {Array.from({ length: 28 }, (_, i) => (\n            <span\n              key={i}\n              className=\"hb-wg10-bld\"\n              style={{ width: `${(4 + hash(i % 14) * 5).toFixed(2)}%`, height: `${(30 + hash((i % 14) + 40) * 65).toFixed(1)}%` }}\n            />\n          ))}\n        </div>\n      </div>\n    );\n  return (\n    <div className=\"hb-wg10-scene hb-wg10-pulse\">\n      {Array.from({ length: 8 }, (_, i) => (\n        <span key={i} className=\"hb-wg10-eq\" style={{ animationDelay: `${(-hash(i + 3) * 0.9).toFixed(2)}s`, animationDuration: `${(0.5 + hash(i + 9) * 0.6).toFixed(2)}s` }} />\n      ))}\n    </div>\n  );\n}\n\nconst fmt = (s: number) => `${Math.floor(s / 60)}:${String(Math.floor(s % 60)).padStart(2, \"0\")}`;\n\nexport function HoverPlayTiles({\n  items = defaults,\n  columns = 2,\n  autoPlay = true,\n  accent = \"#2f7bff\",\n  onPlayChange,\n  className = \"\",\n  style,\n  ...rest\n}: HoverPlayTilesProps) {\n  const [playing, setPlaying] = React.useState(-1);\n  const [auto, setAuto] = React.useState(-1);\n  const [engaged, setEngaged] = React.useState(false);\n  const tileRefs = React.useRef<(HTMLButtonElement | null)[]>([]);\n  const timeRefs = React.useRef<(HTMLSpanElement | null)[]>([]);\n  const pos = React.useRef<number[]>([]);\n  const lastPointer = React.useRef(\"mouse\");\n  const n = items.length;\n  const active = engaged ? playing : playing >= 0 ? playing : auto;\n  const cb = React.useRef(onPlayChange);\n  React.useEffect(() => {\n    cb.current = onPlayChange;\n  }, [onPlayChange]);\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    const kick = window.setTimeout(() => setAuto(0), 600);\n    const id = window.setInterval(() => {\n      i = (i + 1) % n;\n      setAuto(i);\n    }, 2600);\n    return () => {\n      window.clearTimeout(kick);\n      window.clearInterval(id);\n    };\n  }, [autoPlay, engaged, n]);\n\n  React.useEffect(() => {\n    if (active < 0) return;\n    const reduce = window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n    const el = tileRefs.current[active];\n    const tm = timeRefs.current[active];\n    const item = items[active];\n    if (!el || !tm || !item) return;\n    cb.current?.(active, true);\n    let raf = 0;\n    let last = performance.now();\n    const tick = (now: number) => {\n      const dt = (now - last) / 1000;\n      last = now;\n      const cur = ((pos.current[active] ?? 0) + (reduce ? 0 : dt)) % item.duration;\n      pos.current[active] = cur;\n      el.style.setProperty(\"--hb-wg10-p\", (cur / item.duration).toFixed(4));\n      tm.textContent = `${fmt(cur)} / ${fmt(item.duration)}`;\n      raf = requestAnimationFrame(tick);\n    };\n    raf = requestAnimationFrame(tick);\n    return () => {\n      cancelAnimationFrame(raf);\n      tm.textContent = fmt(item.duration);\n      cb.current?.(active, false);\n    };\n  }, [active, items]);\n\n  return (\n    <div\n      className={`hb-wg10 ${className}`}\n      style={{ \"--hb-wg10-accent\": accent, \"--hb-wg10-cols\": Math.max(1, columns), ...style } as React.CSSProperties}\n      role=\"list\"\n      {...rest}\n    >\n      <style href=\"hb-hover-play-tiles\" precedence=\"default\">{css}</style>\n      {items.map((item, i) => (\n        <div role=\"listitem\" key={`${item.title}-${i}`} style={{ display: \"contents\" }}>\n          <button\n            ref={(el) => {\n              tileRefs.current[i] = el;\n            }}\n            type=\"button\"\n            className=\"hb-wg10-tile\"\n            data-playing={active === i ? \"true\" : \"false\"}\n            aria-pressed={active === i}\n            aria-label={`${item.title}, ${fmt(item.duration)}. ${active === i ? \"Pause\" : \"Play\"} preview`}\n            onPointerDown={(e) => {\n              lastPointer.current = e.pointerType;\n            }}\n            onPointerEnter={(e) => {\n              if (e.pointerType !== \"mouse\") return;\n              setEngaged(true);\n              setPlaying(i);\n            }}\n            onPointerLeave={(e) => {\n              if (e.pointerType !== \"mouse\") return;\n              setPlaying((p) => (p === i ? -1 : p));\n            }}\n            onFocus={() => {\n              setEngaged(true);\n              setPlaying(i);\n            }}\n            onBlur={() => setPlaying((p) => (p === i ? -1 : p))}\n            onClick={() => {\n              if (lastPointer.current === \"mouse\") return;\n              setEngaged(true);\n              setPlaying((p) => (p === i ? -1 : i));\n            }}\n            onKeyDown={(e) => {\n              if (e.key === \"Escape\") setPlaying(-1);\n              if (e.key === \"Enter\" || e.key === \" \") lastPointer.current = \"key\";\n            }}\n          >\n            <Scene scene={item.scene} />\n            <span className=\"hb-wg10-poster\" aria-hidden=\"true\">\n              <span className=\"hb-wg10-play\">\n                <svg viewBox=\"0 0 12 12\">\n                  <path d=\"M2.5 1.5v9l8-4.5z\" />\n                </svg>\n              </span>\n            </span>\n            <span className=\"hb-wg10-live\" aria-hidden=\"true\">Preview</span>\n            <span className=\"hb-wg10-info\" aria-hidden=\"true\">\n              <span className=\"hb-wg10-name\">{item.title}</span>\n              <span\n                ref={(el) => {\n                  timeRefs.current[i] = el;\n                }}\n                className=\"hb-wg10-time\"\n              >\n                {fmt(item.duration)}\n              </span>\n            </span>\n            <span className=\"hb-wg10-bar\" aria-hidden=\"true\">\n              <span className=\"hb-wg10-fill\" />\n            </span>\n          </button>\n        </div>\n      ))}\n    </div>\n  );\n}\n"
    }
  ]
}