{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"scrub-timeline-player","type":"registry:component","title":"Scrub Timeline Player","description":"A media scrubber with buffered range, hover timestamp and pointer-capture dragging.","dependencies":[],"registryDependencies":[],"files":[{"path":"components/viberdy/scrub-timeline-player.tsx","content":"\"use client\";\n\nimport { useRef, useState } from \"react\";\n\nfunction formatTime(seconds: number) {\n  const m = Math.floor(seconds / 60);\n  const s = Math.floor(seconds % 60);\n  return m + \":\" + String(s).padStart(2, \"0\");\n}\n\nexport function ScrubTimelinePlayer({\n  height = 5,\n  duration,\n  value,\n  buffered = 0,\n  showHoverTime = true,\n  onChange,\n}: {\n  height?: number;\n  /** Timestamp bubble above the pointer while hovering the track. */\n  showHoverTime?: boolean;\n  duration: number;\n  /** Current position, 0-100. */\n  value: number;\n  /** Buffered extent, 0-100. */\n  buffered?: number;\n  onChange: (next: number) => void;\n}) {\n  const trackRef = useRef<HTMLDivElement>(null);\n  const [scrubbing, setScrubbing] = useState(false);\n  const [hoverPct, setHoverPct] = useState<number | null>(null);\n\n  function pctFromEvent(clientX: number) {\n    const rect = trackRef.current?.getBoundingClientRect();\n    if (!rect) return 0;\n    return Math.max(0, Math.min(100, ((clientX - rect.left) / rect.width) * 100));\n  }\n\n  return (\n    <div\n      ref={trackRef}\n      /*\n       * A real slider, not a div with a click handler: role, the three value\n       * attributes, tabIndex and arrow keys are what make this operable\n       * without a pointer and announced correctly. aria-valuetext carries the\n       * formatted timestamp, since \"42\" is meaningless read aloud.\n       */\n      role=\"slider\"\n      tabIndex={0}\n      aria-label=\"Seek\"\n      aria-valuemin={0}\n      aria-valuemax={100}\n      aria-valuenow={Math.round(value)}\n      aria-valuetext={formatTime((value / 100) * duration)}\n      onKeyDown={(e) => {\n        if (e.key === \"ArrowRight\") onChange(Math.min(100, value + 2));\n        if (e.key === \"ArrowLeft\") onChange(Math.max(0, value - 2));\n      }}\n      /*\n       * POINTER events with setPointerCapture — not mousedown/mousemove.\n       * Capture routes every later pointer event to this element even when the\n       * pointer is outside its bounds, so the scrub survives dragging above or\n       * below the bar. The mouse-event version silently stops there, which is\n       * exactly what people do when scrubbing quickly.\n       */\n      onPointerDown={(e) => {\n        e.currentTarget.setPointerCapture(e.pointerId);\n        setScrubbing(true);\n        onChange(pctFromEvent(e.clientX));\n      }}\n      onPointerMove={(e) => {\n        setHoverPct(pctFromEvent(e.clientX));\n        if (scrubbing) onChange(pctFromEvent(e.clientX));\n      }}\n      onPointerUp={(e) => {\n        e.currentTarget.releasePointerCapture(e.pointerId);\n        setScrubbing(false);\n      }}\n      onPointerLeave={() => setHoverPct(null)}\n      className=\"group relative cursor-pointer py-3\"\n    >\n      <div\n        className=\"relative w-full overflow-hidden rounded-full bg-white/15 transition-[height] duration-150\"\n        style={{ height: scrubbing ? height + 3 : height }}\n      >\n        <div className=\"absolute inset-y-0 left-0 bg-white/20\" style={{ width: buffered + \"%\" }} />\n        <div className=\"absolute inset-y-0 left-0 bg-blue-500\" style={{ width: value + \"%\" }} />\n      </div>\n\n      <span\n        className=\"pointer-events-none absolute top-1/2 size-3 -translate-x-1/2 -translate-y-1/2 rounded-full bg-white shadow transition-transform duration-150 group-hover:scale-110\"\n        style={{ left: value + \"%\" }}\n      />\n\n      {showHoverTime && hoverPct !== null && (\n        <span\n          className=\"pointer-events-none absolute bottom-full -translate-x-1/2 rounded bg-neutral-800 px-1.5 py-0.5 font-mono text-[10px] tabular-nums text-white\"\n          style={{ left: hoverPct + \"%\" }}\n        >\n          {formatTime((hoverPct / 100) * duration)}\n        </span>\n      )}\n    </div>\n  );\n}\n","type":"registry:component","target":"components/viberdy/scrub-timeline-player.tsx"}],"meta":{"tier":"free","tags":["media","slider","scrub","player"],"href":"https://viberdy.dev/library/scrub-timeline-player","aiPrompt":"Create a React + Tailwind component named ScrubTimelinePlayer — a media scrubber with a buffered range, a draggable playhead and a hover timestamp.\n\nBehavior:\n- A track showing three layers: an empty rail, a buffered extent, and the played extent.\n- A circular playhead sits at the current position and scales up slightly on hover.\n- Hovering anywhere on the track shows a small monospace timestamp tooltip above that point.\n- The bar grows a few px taller while actively scrubbing.\n\nTwo requirements that are the whole point of the component:\n\n1. Use POINTER events with setPointerCapture, not mousedown/mousemove.\n   On pointerdown: e.currentTarget.setPointerCapture(e.pointerId), begin scrubbing, seek.\n   On pointerup: releasePointerCapture.\n   Capture routes every subsequent pointer event to this element even when the pointer is OUTSIDE its bounds, so the scrub keeps working when the user drags above or below the bar — which is exactly what people do when scrubbing fast. The mouse-event version silently stops there. It also removes the need for window-level listeners and their cleanup.\n\n2. Make it a real slider, not a div with a click handler:\n   role=\"slider\", tabIndex={0}, aria-label, aria-valuemin/max/now, and aria-valuetext carrying the FORMATTED timestamp (a bare \"42\" is meaningless read aloud). Handle ArrowLeft/ArrowRight to seek.\n\nProps: duration (seconds), value (0-100), buffered (0-100), onChange (callback).\n\nOutput a single self-contained \"use client\" component.","license":"https://viberdy.dev/license"}}