{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "cinema-subtitles",
  "type": "registry:component",
  "title": "Cinema Subtitles",
  "description": "A night drive scene with streetlights sweeping through the cabin and subtitles synced to a timeline, with speaker labels, sound cues and a scrubber that marks every line. Play, pause, seek and toggle captions.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "cinematic",
    "cinematic",
    "subtitles",
    "captions",
    "player",
    "timeline",
    "dialogue"
  ],
  "docs": "https://hyperblur.dev/effects/cinema-subtitles",
  "files": [
    {
      "path": "registry/hyperblur/cinema-subtitles.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/cinema-subtitles.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface CinemaSubtitleCue {\n  start: number;\n  end: number;\n  text: string;\n  speaker?: string;\n}\n\nexport interface CinemaSubtitlesProps extends Omit<React.HTMLAttributes<HTMLElement>, \"title\"> {\n  title?: string;\n  episode?: string;\n  cues?: CinemaSubtitleCue[];\n  duration?: number;\n  autoPlay?: boolean;\n  loop?: boolean;\n  defaultCaptions?: boolean;\n  accent?: string;\n  onCueChange?: (cue: CinemaSubtitleCue | null) => void;\n  headingAs?: \"h1\" | \"h2\";\n}\n\nconst defaultCues: CinemaSubtitleCue[] = [\n  { start: 0.6, end: 3.2, speaker: \"Mara\", text: \"You missed the turn again.\" },\n  { start: 3.6, end: 6.4, speaker: \"Elias\", text: \"I didn't miss it. I'm avoiding it.\" },\n  { start: 7.0, end: 9.6, speaker: \"Mara\", text: \"Avoiding what? It's a gas station.\" },\n  { start: 10.2, end: 12.8, speaker: \"Elias\", text: \"The radio. Listen. Right... there.\" },\n  { start: 13.2, end: 15.0, text: \"[ static rises, then a voice under it ]\" },\n  { start: 15.4, end: 18.8, speaker: \"Mara\", text: \"That's not static. Someone is counting.\" },\n];\n\nconst css = `\n.hb-vc10 {\n  --hb-vc10-accent: #ffd34d;\n  position: relative;\n  box-sizing: border-box;\n  display: block;\n  width: 100%;\n  height: 580px;\n  overflow: hidden;\n  isolation: isolate;\n  container-type: inline-size;\n  background: #020305;\n  color: #fff;\n  font-family: inherit;\n  -webkit-font-smoothing: antialiased;\n}\n.hb-vc10 *, .hb-vc10 *::before, .hb-vc10 *::after { box-sizing: border-box; }\n.hb-vc10-scene { position: absolute; inset: 0; }\n.hb-vc10-scene svg { display: block; width: 100%; height: 100%; }\n.hb-vc10-sweep {\n  position: absolute;\n  inset: -20% -60%;\n  background: linear-gradient(105deg, transparent 40%, rgba(255, 196, 120, .16) 48%, rgba(255, 220, 170, .26) 50%, rgba(255, 196, 120, .14) 52%, transparent 60%);\n  mix-blend-mode: screen;\n  animation: hb-vc10-sweep 2.6s cubic-bezier(.5, 0, .5, 1) infinite;\n}\n.hb-vc10[data-playing=\"false\"] .hb-vc10-sweep,\n.hb-vc10[data-playing=\"false\"] .hb-vc10-lamp,\n.hb-vc10[data-playing=\"false\"] .hb-vc10-dash { animation-play-state: paused; }\n@keyframes hb-vc10-sweep {\n  from { transform: translate3d(-40%, 0, 0); }\n  to { transform: translate3d(40%, 0, 0); }\n}\n.hb-vc10-lamp { animation: hb-vc10-lamp 2.6s cubic-bezier(.6, 0, .9, .4) infinite; transform-box: view-box; }\n@keyframes hb-vc10-lamp {\n  from { transform: translate(0, 0) scale(.2); opacity: 0; }\n  20% { opacity: 1; }\n  to { transform: translate(-560px, -120px) scale(2.4); opacity: 0; }\n}\n.hb-vc10-dash { animation: hb-vc10-dash .7s linear infinite; }\n@keyframes hb-vc10-dash {\n  from { stroke-dashoffset: 0; }\n  to { stroke-dashoffset: -60; }\n}\n.hb-vc10-top {\n  position: absolute;\n  top: 18px;\n  left: clamp(16px, 3cqi, 30px);\n  right: clamp(16px, 3cqi, 30px);\n  z-index: 3;\n  display: flex;\n  align-items: baseline;\n  justify-content: space-between;\n  gap: 12px;\n}\n.hb-vc10-title {\n  margin: 0;\n  font-family: var(--font-grotesk, var(--font-sans, ui-sans-serif, system-ui, sans-serif));\n  font-size: clamp(18px, 2.6cqi, 26px);\n  font-weight: 600;\n  letter-spacing: -.01em;\n}\n.hb-vc10-ep {\n  color: rgba(255, 255, 255, .55);\n  font-family: var(--font-mono, ui-monospace, monospace);\n  font-size: 10.5px;\n  letter-spacing: .16em;\n  text-transform: uppercase;\n  white-space: nowrap;\n}\n.hb-vc10-subs {\n  position: absolute;\n  left: 50%;\n  bottom: 96px;\n  z-index: 3;\n  display: grid;\n  place-items: center;\n  width: min(92%, 760px);\n  min-height: 64px;\n  transform: translateX(-50%);\n  text-align: center;\n}\n.hb-vc10-line {\n  display: inline;\n  margin: 0;\n  padding: .12em .5em;\n  border-radius: 4px;\n  background: rgba(0, 0, 0, .55);\n  -webkit-box-decoration-break: clone;\n  box-decoration-break: clone;\n  color: #fff;\n  font-size: clamp(16px, 2.6cqi, 26px);\n  font-weight: 500;\n  line-height: 1.5;\n  letter-spacing: .005em;\n  text-shadow: 0 1px 2px rgba(0, 0, 0, .8);\n  animation: hb-vc10-in .32s cubic-bezier(.2, .8, .2, 1) both;\n}\n.hb-vc10-line[data-sfx] { color: rgba(255, 255, 255, .78); font-size: clamp(14px, 2.1cqi, 21px); letter-spacing: .04em; }\n.hb-vc10-speaker {\n  margin-right: .45em;\n  color: var(--hb-vc10-accent);\n  font-size: .62em;\n  font-weight: 700;\n  letter-spacing: .16em;\n  text-transform: uppercase;\n  vertical-align: .18em;\n}\n@keyframes hb-vc10-in {\n  from { opacity: 0; transform: translate3d(0, 6px, 0); }\n  to { opacity: 1; transform: none; }\n}\n.hb-vc10-bar {\n  position: absolute;\n  left: clamp(12px, 3cqi, 28px);\n  right: clamp(12px, 3cqi, 28px);\n  bottom: 18px;\n  z-index: 4;\n  display: flex;\n  align-items: center;\n  gap: 14px;\n  height: 52px;\n  padding: 0 14px 0 8px;\n  border: 1px solid rgba(255, 255, 255, .1);\n  border-radius: 14px;\n  background: linear-gradient(180deg, rgba(28, 28, 32, .78), rgba(14, 14, 16, .86));\n  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .06), 0 20px 40px -20px rgba(0, 0, 0, .8);\n  backdrop-filter: blur(14px);\n}\n.hb-vc10-ib {\n  display: grid;\n  flex: none;\n  place-items: center;\n  width: 36px;\n  height: 36px;\n  border: 0;\n  border-radius: 10px;\n  background: transparent;\n  color: #fff;\n  cursor: pointer;\n  transition: background .2s ease, color .2s ease;\n}\n.hb-vc10-ib:hover { background: rgba(255, 255, 255, .08); }\n.hb-vc10-ib:focus-visible, .hb-vc10-range:focus-visible { outline: 2px solid var(--hb-vc10-accent); outline-offset: 2px; }\n.hb-vc10-ib[aria-pressed=\"false\"] { color: rgba(255, 255, 255, .45); }\n.hb-vc10-cc {\n  padding: 2px 4px;\n  border: 1.5px solid currentColor;\n  border-radius: 4px;\n  font-size: 9.5px;\n  font-weight: 800;\n  letter-spacing: .04em;\n  line-height: 1;\n}\n.hb-vc10-tc {\n  flex: none;\n  min-width: 92px;\n  color: rgba(255, 255, 255, .72);\n  font-family: var(--font-mono, ui-monospace, monospace);\n  font-size: 11.5px;\n  font-variant-numeric: tabular-nums;\n}\n.hb-vc10-track { position: relative; flex: 1; min-width: 0; height: 36px; }\n.hb-vc10-rail {\n  position: absolute;\n  left: 0;\n  right: 0;\n  top: 50%;\n  height: 4px;\n  border-radius: 4px;\n  background: rgba(255, 255, 255, .12);\n  transform: translateY(-50%);\n  overflow: hidden;\n}\n.hb-vc10-fill { position: absolute; inset: 0 auto 0 0; background: #fff; border-radius: 4px; }\n.hb-vc10-cue {\n  position: absolute;\n  top: 50%;\n  height: 4px;\n  border-radius: 2px;\n  background: color-mix(in srgb, var(--hb-vc10-accent) 55%, transparent);\n  transform: translateY(-50%);\n  pointer-events: none;\n}\n.hb-vc10-cue[data-on=\"true\"] { background: var(--hb-vc10-accent); box-shadow: 0 0 10px var(--hb-vc10-accent); }\n.hb-vc10-range {\n  position: absolute;\n  inset: 0;\n  width: 100%;\n  height: 100%;\n  margin: 0;\n  background: transparent;\n  cursor: pointer;\n  -webkit-appearance: none;\n  appearance: none;\n}\n.hb-vc10-range::-webkit-slider-runnable-track { height: 36px; background: transparent; }\n.hb-vc10-range::-moz-range-track { height: 36px; background: transparent; }\n.hb-vc10-range::-webkit-slider-thumb {\n  width: 14px;\n  height: 14px;\n  margin-top: 11px;\n  border: 0;\n  border-radius: 50%;\n  background: #fff;\n  box-shadow: 0 0 0 4px rgba(255, 255, 255, .16);\n  -webkit-appearance: none;\n  appearance: none;\n}\n.hb-vc10-range::-moz-range-thumb { width: 14px; height: 14px; border: 0; border-radius: 50%; background: #fff; box-shadow: 0 0 0 4px rgba(255, 255, 255, .16); }\n@container (max-width: 520px) {\n  .hb-vc10-tc { display: none; }\n  .hb-vc10-subs { bottom: 86px; }\n}\n@media (prefers-reduced-motion: reduce) {\n  .hb-vc10-sweep, .hb-vc10-lamp, .hb-vc10-dash, .hb-vc10-line { animation: none; }\n}\n`;\n\nfunction fmt(t: number) {\n  const s = Math.floor(t);\n  const f = Math.floor((t - s) * 24);\n  return `00:${String(Math.floor(s / 60)).padStart(2, \"0\")}:${String(s % 60).padStart(2, \"0\")}:${String(f).padStart(2, \"0\")}`;\n}\n\nexport function CinemaSubtitles({\n  title = \"Static, Episode 1\",\n  episode = \"S1 · E1 · The Counting Station\",\n  cues = defaultCues,\n  duration = 20,\n  autoPlay = true,\n  loop = true,\n  defaultCaptions = true,\n  accent = \"#ffd34d\",\n  onCueChange,\n  headingAs = \"h2\",\n  className,\n  style,\n  ...rest\n}: CinemaSubtitlesProps) {\n  const Heading = headingAs;\n  const [t, setT] = React.useState(0);\n  const [playing, setPlaying] = React.useState(autoPlay);\n  const [captions, setCaptions] = React.useState(defaultCaptions);\n  const tRef = React.useRef(0);\n  const cueRef = React.useRef(onCueChange);\n  const uid = React.useId();\n\n  React.useEffect(() => {\n    cueRef.current = onCueChange;\n  }, [onCueChange]);\n\n  React.useEffect(() => {\n    if (!playing) return;\n    let raf = 0;\n    let last = 0;\n    const step = (now: number) => {\n      if (last) {\n        let next = tRef.current + (now - last) / 1000;\n        if (next >= duration) {\n          if (loop) next = next % duration;\n          else {\n            next = duration;\n            tRef.current = next;\n            setT(next);\n            setPlaying(false);\n            return;\n          }\n        }\n        tRef.current = next;\n        setT(next);\n      }\n      last = now;\n      raf = requestAnimationFrame(step);\n    };\n    raf = requestAnimationFrame(step);\n    return () => cancelAnimationFrame(raf);\n  }, [playing, duration, loop]);\n\n  const activeIndex = cues.findIndex((c) => t >= c.start && t < c.end);\n  const active = activeIndex >= 0 ? cues[activeIndex] : null;\n\n  React.useEffect(() => {\n    cueRef.current?.(activeIndex >= 0 ? cues[activeIndex] : null);\n  }, [activeIndex, cues]);\n\n  const seek = (v: number) => {\n    const next = Math.max(0, Math.min(duration, v));\n    tRef.current = next;\n    setT(next);\n  };\n\n  const toggle = () => {\n    if (!playing && tRef.current >= duration) seek(0);\n    setPlaying((p) => !p);\n  };\n\n  const vars = { \"--hb-vc10-accent\": accent, ...style } as React.CSSProperties;\n\n  return (\n    <section\n      className={[\"hb-vc10\", className].filter(Boolean).join(\" \")}\n      style={vars}\n      data-playing={playing ? \"true\" : \"false\"}\n      {...rest}\n    >\n      <style href=\"hb-cinema-subtitles\" precedence=\"default\">{css}</style>\n      <div className=\"hb-vc10-scene\" aria-hidden=\"true\">\n        <svg viewBox=\"0 0 1600 900\" preserveAspectRatio=\"xMidYMid slice\">\n          <rect width=\"1600\" height=\"900\" fill=\"#03050a\" />\n          <path d=\"M250 120 C600 60 1000 60 1350 120 L1480 560 L120 560Z\" fill=\"#0a1220\" />\n          <path d=\"M250 120 C600 60 1000 60 1350 120 L1480 560 L120 560Z\" fill=\"none\" stroke=\"#101826\" strokeWidth=\"18\" />\n          <path d=\"M120 560 L760 330 L840 330 L1480 560Z\" fill=\"#05080e\" />\n          <path d=\"M800 334 L800 560\" stroke=\"#c9a35a\" strokeWidth=\"5\" strokeDasharray=\"26 34\" className=\"hb-vc10-dash\" opacity=\".7\" />\n          {[0, 1].map((i) => (\n            <g key={i} className=\"hb-vc10-lamp\" style={{ transformOrigin: \"760px 320px\", animationDelay: `${-i * 1.3}s` }}>\n              <circle cx=\"760\" cy=\"300\" r=\"4\" fill=\"#ffd9a0\" />\n              <circle cx=\"760\" cy=\"300\" r=\"14\" fill=\"#ffc070\" opacity=\".25\" />\n            </g>\n          ))}\n          <circle cx=\"840\" cy=\"340\" r=\"3\" fill=\"#ff4a3a\" opacity=\".85\" />\n          <circle cx=\"852\" cy=\"340\" r=\"3\" fill=\"#ff4a3a\" opacity=\".85\" />\n          <path d=\"M0 520 L1600 520 L1600 900 L0 900Z\" fill=\"#020305\" />\n          <path d=\"M0 560 C300 520 520 520 700 548 L700 900 L0 900Z\" fill=\"#06080c\" />\n          <path d=\"M900 548 C1080 520 1300 520 1600 560 L1600 900 L900 900Z\" fill=\"#06080c\" />\n          <ellipse cx=\"480\" cy=\"560\" rx=\"96\" ry=\"112\" fill=\"#010203\" />\n          <path d=\"M300 900 C310 720 380 660 480 660 C580 660 650 720 660 900Z\" fill=\"#010203\" />\n          <ellipse cx=\"1110\" cy=\"584\" rx=\"88\" ry=\"104\" fill=\"#010203\" />\n          <path d=\"M940 900 C950 740 1020 690 1110 690 C1200 690 1270 740 1280 900Z\" fill=\"#010203\" />\n          <rect x=\"740\" y=\"600\" width=\"120\" height=\"44\" rx=\"8\" fill=\"#0b0f16\" />\n          <rect x=\"752\" y=\"612\" width=\"96\" height=\"20\" rx=\"3\" fill=\"#0e3a2e\" />\n          <text x=\"800\" y=\"627\" fill=\"#4dffb0\" fontSize=\"13\" fontFamily=\"monospace\" textAnchor=\"middle\">88.4 FM</text>\n          <path d=\"M300 104 L380 94 L380 136 L300 146Z\" fill=\"#06090f\" />\n        </svg>\n        <span className=\"hb-vc10-sweep\" />\n      </div>\n      <div className=\"hb-vc10-top\">\n        <Heading className=\"hb-vc10-title\">{title}</Heading>\n        {episode ? <span className=\"hb-vc10-ep\">{episode}</span> : null}\n      </div>\n      <div className=\"hb-vc10-subs\" aria-live=\"polite\">\n        {captions && active ? (\n          <p className=\"hb-vc10-line\" key={activeIndex} data-sfx={active.speaker ? undefined : \"\"}>\n            {active.speaker ? <span className=\"hb-vc10-speaker\">{active.speaker}</span> : null}\n            {active.text}\n          </p>\n        ) : null}\n      </div>\n      <div className=\"hb-vc10-bar\">\n        <button type=\"button\" className=\"hb-vc10-ib\" onClick={toggle} aria-label={playing ? \"Pause\" : \"Play\"}>\n          {playing ? (\n            <svg width=\"14\" height=\"14\" viewBox=\"0 0 14 14\" aria-hidden=\"true\"><path d=\"M2.5 1.5h3v11h-3zM8.5 1.5h3v11h-3z\" fill=\"currentColor\" /></svg>\n          ) : (\n            <svg width=\"14\" height=\"14\" viewBox=\"0 0 14 14\" aria-hidden=\"true\"><path d=\"M3 1.2 L12.5 7 L3 12.8Z\" fill=\"currentColor\" /></svg>\n          )}\n        </button>\n        <span className=\"hb-vc10-tc\" aria-hidden=\"true\">{fmt(t)}</span>\n        <div className=\"hb-vc10-track\">\n          <div className=\"hb-vc10-rail\">\n            <span className=\"hb-vc10-fill\" style={{ width: `${((t / duration) * 100).toFixed(2)}%` }} />\n          </div>\n          {cues.map((c, i) => (\n            <span\n              key={i}\n              className=\"hb-vc10-cue\"\n              data-on={i === activeIndex ? \"true\" : \"false\"}\n              style={{ left: `${((c.start / duration) * 100).toFixed(2)}%`, width: `${(((c.end - c.start) / duration) * 100).toFixed(2)}%` }}\n            />\n          ))}\n          <input\n            className=\"hb-vc10-range\"\n            type=\"range\"\n            min={0}\n            max={duration}\n            step={0.1}\n            value={t}\n            aria-label=\"Seek\"\n            aria-valuetext={fmt(t)}\n            aria-describedby={`${uid}-tc`}\n            onChange={(e) => seek(Number(e.target.value))}\n          />\n          <span id={`${uid}-tc`} hidden>{active ? active.text : \"No dialogue\"}</span>\n        </div>\n        <button\n          type=\"button\"\n          className=\"hb-vc10-ib\"\n          onClick={() => setCaptions((c) => !c)}\n          aria-pressed={captions}\n          aria-label=\"Subtitles\"\n        >\n          <span className=\"hb-vc10-cc\">CC</span>\n        </button>\n      </div>\n    </section>\n  );\n}\n"
    }
  ]
}