{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "modal-video-chapters",
  "type": "registry:component",
  "title": "Chapter Video Modal",
  "description": "A video modal with a scrubber split into chapters, hover previews of each chapter, synced captions and speed control. Without a src it plays a styled preview timeline, so it works before the video exists.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "modals",
    "video",
    "player",
    "chapters",
    "captions",
    "tour",
    "modal"
  ],
  "docs": "https://hyperblur.dev/effects/modal-video-chapters",
  "files": [
    {
      "path": "registry/hyperblur/modal-video-chapters.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/modal-video-chapters.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface VideoChapter {\n  title: string;\n  start: number;\n  tint?: string;\n}\n\nexport interface VideoCaption {\n  start: number;\n  text: string;\n}\n\nexport interface ModalVideoChaptersProps extends Omit<React.HTMLAttributes<HTMLDivElement>, \"title\" | \"onProgress\"> {\n  open?: boolean;\n  defaultOpen?: boolean;\n  onOpenChange?: (open: boolean) => void;\n  embedded?: boolean;\n  trigger?: React.ReactNode;\n  title?: string;\n  src?: string;\n  duration?: number;\n  chapters?: VideoChapter[];\n  captions?: VideoCaption[];\n  autoPlay?: boolean;\n  onProgress?: (seconds: number) => void;\n  accent?: string;\n}\n\nconst defaultChapters: VideoChapter[] = [\n  { title: \"Welcome to Relay\", start: 0, tint: \"#6d5dfc\" },\n  { title: \"Planning a cycle\", start: 72, tint: \"#0ea5e9\" },\n  { title: \"Triage inbox\", start: 168, tint: \"#f97316\" },\n  { title: \"Roadmaps\", start: 254, tint: \"#10b981\" },\n  { title: \"Shortcuts\", start: 336, tint: \"#ec4899\" },\n];\n\nconst defaultCaptions: VideoCaption[] = [\n  { start: 0, text: \"Hi, I’m Dana. Let’s take a quick look around Relay.\" },\n  { start: 9, text: \"Everything your team ships starts in a single workspace.\" },\n  { start: 24, text: \"On the left you will find teams, projects and views.\" },\n  { start: 72, text: \"Cycles keep work moving in two week rhythms.\" },\n  { start: 96, text: \"Drag issues into the cycle and Relay balances the load.\" },\n  { start: 168, text: \"New requests land in triage before they reach the backlog.\" },\n  { start: 200, text: \"Accept, merge or snooze them with a single key.\" },\n  { start: 254, text: \"Roadmaps roll projects up into quarterly goals.\" },\n  { start: 336, text: \"Press Command K to do anything without the mouse.\" },\n  { start: 380, text: \"That’s the tour. Go build something great.\" },\n];\n\nconst css = `\n.hb-xe9 { --hb-xe9-accent: #ffffff; display: inline-block; box-sizing: border-box; color: #ededed; font-family: var(--font-sans, ui-sans-serif, system-ui, sans-serif); }\n.hb-xe9 *, .hb-xe9 *::before, .hb-xe9 *::after { box-sizing: border-box; }\n.hb-xe9[data-embedded] { container-type: size; position: relative; display: grid; place-items: center; width: 100%; height: 100%; min-height: 190px; border-radius: 16px; overflow: hidden; isolation: isolate; background: #0a0a0a; }\n.hb-xe9 button:focus-visible, .hb-xe9-scrub:focus-visible { outline: 2px solid var(--hb-xe9-accent); outline-offset: 2px; }\n.hb-xe9-card { position: relative; display: grid; align-content: end; width: 240px; aspect-ratio: 16 / 9; padding: 10px; overflow: hidden; border: 0; border-radius: 12px; background: radial-gradient(60% 80% at 20% 20%, #6d5dfc, transparent 60%), radial-gradient(60% 80% at 90% 90%, #0ea5e9, transparent 60%), #111; color: #fff; font: inherit; text-align: left; cursor: pointer; box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08), 0 16px 30px -16px rgba(0, 0, 0, 0.9); transition: transform 0.35s cubic-bezier(0.2, 0.9, 0.2, 1); }\n.hb-xe9-card:hover { transform: translateY(-2px); }\n.hb-xe9-card:hover .hb-xe9-cplay { transform: translate(-50%, -50%) scale(1.08); }\n.hb-xe9-cplay { position: absolute; top: 46%; left: 50%; display: grid; place-items: center; width: 42px; height: 42px; border-radius: 50%; background: rgba(255, 255, 255, 0.92); color: #0a0a0a; transform: translate(-50%, -50%); box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4); transition: transform 0.3s cubic-bezier(0.3, 0.7, 0.4, 1.4); }\n.hb-xe9-cplay svg { width: 15px; height: 15px; margin-left: 2px; }\n.hb-xe9-clabel { position: relative; font-size: 12.5px; font-weight: 600; text-shadow: 0 1px 8px rgba(0, 0, 0, 0.5); }\n.hb-xe9-cdur { position: absolute; top: 8px; right: 8px; padding: 2px 6px; border-radius: 5px; background: rgba(0, 0, 0, 0.55); font-family: var(--font-mono, ui-monospace, monospace); font-size: 10.5px; }\n.hb-xe9-layer { container-type: inline-size; position: fixed; inset: 0; z-index: 1000; height: 100dvh; display: grid; place-items: center; padding: 16px; }\n.hb-xe9[data-embedded] .hb-xe9-layer { position: absolute; height: auto; z-index: 2; padding: 8px; }\n.hb-xe9-scrim { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.82); animation: hb-xe9-fade 0.3s ease both; }\n.hb-xe9-layer[data-state=\"closed\"] .hb-xe9-scrim { animation: hb-xe9-fade-out 0.25s ease both; }\n.hb-xe9-panel { position: relative; width: min(960px, 100%, calc((100dvh - 32px) * 16 / 9)); outline: none; animation: hb-xe9-in 0.5s cubic-bezier(0.16, 1, 0.3, 1) both; }\n.hb-xe9[data-embedded] .hb-xe9-panel { width: min(100%, calc((100cqh - 16px) * 16 / 9)); }\n.hb-xe9-layer[data-state=\"closed\"] .hb-xe9-panel { animation: hb-xe9-out 0.25s ease both; }\n.hb-xe9-player { position: relative; aspect-ratio: 16 / 9; max-height: calc(100dvh - 32px); overflow: hidden; border-radius: 14px; background: #000; box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.08), 0 40px 100px -30px rgba(0, 0, 0, 1); }\n.hb-xe9[data-embedded] .hb-xe9-player { max-height: none; }\n.hb-xe9-video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }\n.hb-xe9-scene { position: absolute; inset: 0; display: grid; place-items: center; background: radial-gradient(50% 60% at 30% 30%, color-mix(in srgb, var(--hb-xe9-tint) 70%, transparent), transparent 70%), radial-gradient(60% 70% at 80% 80%, color-mix(in srgb, var(--hb-xe9-tint) 40%, #000), transparent 70%), #07070a; transition: background 0.6s ease; }\n.hb-xe9-scene::after { content: \"\"; position: absolute; inset: 0; background: repeating-linear-gradient(0deg, rgba(255, 255, 255, 0.025) 0 1px, transparent 1px 3px); }\n.hb-xe9-chap { position: relative; display: grid; justify-items: center; gap: 4px; text-align: center; animation: hb-xe9-kb 0.8s cubic-bezier(0.2, 0.9, 0.2, 1) both; }\n.hb-xe9-chap small { font-family: var(--font-mono, ui-monospace, monospace); font-size: clamp(9px, 1.6cqw, 12px); letter-spacing: 0.14em; text-transform: uppercase; color: rgba(255, 255, 255, 0.6); }\n.hb-xe9-chap b { font-family: var(--font-grotesk, inherit); font-size: clamp(16px, 5cqw, 44px); font-weight: 600; letter-spacing: -0.03em; }\n.hb-xe9-top { position: absolute; top: 0; left: 0; right: 0; display: flex; align-items: center; gap: 10px; padding: clamp(8px, 2cqw, 16px); background: linear-gradient(180deg, rgba(0, 0, 0, 0.6), transparent); }\n.hb-xe9-title { flex: 1; min-width: 0; margin: 0; font-size: clamp(11.5px, 1.7cqw, 14px); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }\n.hb-xe9-x { flex: none; display: grid; place-items: center; width: 30px; height: 30px; border: 0; border-radius: 50%; background: rgba(255, 255, 255, 0.12); color: #fff; cursor: pointer; -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px); transition: background-color 0.2s ease; }\n.hb-xe9-x:hover { background: rgba(255, 255, 255, 0.24); }\n.hb-xe9-x svg { width: 13px; height: 13px; }\n.hb-xe9-big { position: absolute; top: 50%; left: 50%; display: grid; place-items: center; width: clamp(44px, 10cqw, 76px); height: clamp(44px, 10cqw, 76px); border: 0; border-radius: 50%; background: rgba(255, 255, 255, 0.94); color: #0a0a0a; cursor: pointer; transform: translate(-50%, -50%); box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5); animation: hb-xe9-pop 0.35s cubic-bezier(0.3, 0.7, 0.4, 1.4) both; }\n.hb-xe9-big svg { width: 36%; height: 36%; margin-left: 6%; }\n.hb-xe9-cap { position: absolute; left: 50%; bottom: clamp(52px, 11cqw, 78px); max-width: 86%; padding: 4px 10px; border-radius: 6px; background: rgba(0, 0, 0, 0.72); color: #fff; font-size: clamp(10.5px, 1.9cqw, 16px); line-height: 1.4; text-align: center; transform: translateX(-50%); animation: hb-xe9-cap 0.25s ease both; }\n.hb-xe9-ctrl { position: absolute; left: 0; right: 0; bottom: 0; display: grid; gap: clamp(4px, 1cqw, 8px); padding: clamp(18px, 4cqw, 36px) clamp(8px, 2cqw, 16px) clamp(6px, 1.6cqw, 12px); background: linear-gradient(0deg, rgba(0, 0, 0, 0.78), transparent); transition: opacity 0.3s ease; }\n.hb-xe9-player[data-idle=\"true\"] .hb-xe9-ctrl, .hb-xe9-player[data-idle=\"true\"] .hb-xe9-top { opacity: 0; }\n.hb-xe9-scrub { position: relative; display: flex; gap: 3px; height: 14px; align-items: center; cursor: pointer; touch-action: none; border-radius: 4px; }\n.hb-xe9-seg { position: relative; flex: var(--hb-xe9-w) 1 0; height: 4px; border-radius: 3px; background: rgba(255, 255, 255, 0.22); overflow: hidden; transition: height 0.2s cubic-bezier(0.3, 0.7, 0.4, 1); }\n.hb-xe9-scrub:hover .hb-xe9-seg, .hb-xe9-scrub:focus-visible .hb-xe9-seg { height: 7px; }\n.hb-xe9-seg i { position: absolute; inset: 0; background: var(--hb-xe9-accent); transform-origin: left; transform: scaleX(var(--hb-xe9-p)); font-style: normal; }\n.hb-xe9-seg b { position: absolute; inset: 0; background: rgba(255, 255, 255, 0.35); transform-origin: left; transform: scaleX(var(--hb-xe9-h, 0)); }\n.hb-xe9-tip { position: absolute; bottom: 18px; padding: 4px 8px; border-radius: 6px; background: #fff; color: #0a0a0a; font-size: 11px; font-weight: 600; white-space: nowrap; transform: translateX(-50%); pointer-events: none; box-shadow: 0 6px 18px rgba(0, 0, 0, 0.4); }\n.hb-xe9-tip span { margin-left: 6px; font-family: var(--font-mono, ui-monospace, monospace); font-weight: 500; color: #555; }\n.hb-xe9-row { display: flex; align-items: center; gap: clamp(2px, 0.8cqw, 8px); }\n.hb-xe9-btn { display: grid; place-items: center; min-width: 30px; height: 30px; padding: 0 6px; border: 0; border-radius: 7px; background: transparent; color: #fff; font: inherit; font-size: 12px; font-weight: 600; cursor: pointer; transition: background-color 0.18s ease; }\n.hb-xe9-btn:hover { background: rgba(255, 255, 255, 0.14); }\n.hb-xe9-btn[aria-pressed=\"true\"] { background: rgba(255, 255, 255, 0.92); color: #0a0a0a; }\n.hb-xe9-btn svg { width: 16px; height: 16px; }\n.hb-xe9-time { font-family: var(--font-mono, ui-monospace, monospace); font-size: clamp(10.5px, 1.6cqw, 12px); font-variant-numeric: tabular-nums; color: rgba(255, 255, 255, 0.85); white-space: nowrap; }\n.hb-xe9-now { flex: 1; min-width: 0; color: rgba(255, 255, 255, 0.7); font-size: clamp(10.5px, 1.6cqw, 12.5px); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }\n@container (max-width: 420px) {\n  .hb-xe9-now, .hb-xe9-hide-sm { display: none; }\n  .hb-xe9-row { justify-content: space-between; }\n}\n@keyframes hb-xe9-fade { from { opacity: 0; } to { opacity: 1; } }\n@keyframes hb-xe9-fade-out { from { opacity: 1; } to { opacity: 0; } }\n@keyframes hb-xe9-in { from { opacity: 0; transform: translateY(24px) scale(0.94); } to { opacity: 1; transform: none; } }\n@keyframes hb-xe9-out { from { opacity: 1; } to { opacity: 0; transform: scale(0.96); } }\n@keyframes hb-xe9-kb { from { opacity: 0; transform: scale(1.06); filter: blur(6px); } to { opacity: 1; transform: none; filter: none; } }\n@keyframes hb-xe9-pop { from { opacity: 0; transform: translate(-50%, -50%) scale(0.7); } to { opacity: 1; transform: translate(-50%, -50%); } }\n@keyframes hb-xe9-cap { from { opacity: 0; transform: translate(-50%, 4px); } to { opacity: 1; transform: translateX(-50%); } }\n@media (prefers-reduced-motion: reduce) {\n  .hb-xe9-scrim, .hb-xe9-panel, .hb-xe9-chap, .hb-xe9-big, .hb-xe9-cap, .hb-xe9-layer[data-state=\"closed\"] .hb-xe9-panel, .hb-xe9-layer[data-state=\"closed\"] .hb-xe9-scrim { animation: none; }\n  .hb-xe9-layer[data-state=\"closed\"] { opacity: 0; }\n  .hb-xe9-scene, .hb-xe9-seg, .hb-xe9-ctrl, .hb-xe9-card, .hb-xe9-cplay, .hb-xe9-btn, .hb-xe9-x { transition: none; }\n}\n`;\n\nconst focusable =\n  'a[href],button:not(:disabled),input:not(:disabled),select:not(:disabled),textarea:not(:disabled),video[controls],[tabindex]:not([tabindex=\"-1\"])';\n\nfunction useLayer(\n  open: boolean,\n  embedded: boolean,\n  panel: React.RefObject<HTMLElement | null>,\n  onClose: () => void,\n  userOpened: React.RefObject<boolean>,\n) {\n  const closeRef = React.useRef(onClose);\n  React.useEffect(() => {\n    closeRef.current = onClose;\n  });\n  React.useEffect(() => {\n    if (!open) return;\n    const node = panel.current;\n    const steal = !embedded || userOpened.current;\n    const previous = document.activeElement as HTMLElement | null;\n    const html = document.documentElement;\n    const overflow = html.style.overflow;\n    if (!embedded) html.style.overflow = \"hidden\";\n    if (steal && node) {\n      const target = node.querySelector<HTMLElement>(\"[data-autofocus]\") ?? node.querySelector<HTMLElement>(focusable) ?? node;\n      target.focus({ preventScroll: true });\n    }\n    const onKey = (e: KeyboardEvent) => {\n      if (!node) return;\n      if (embedded && !node.contains(document.activeElement)) return;\n      if (e.key === \"Escape\") {\n        e.preventDefault();\n        closeRef.current();\n        return;\n      }\n      if (e.key !== \"Tab\") return;\n      const items = Array.from(node.querySelectorAll<HTMLElement>(focusable)).filter((el) => el.getClientRects().length > 0);\n      if (!items.length) {\n        e.preventDefault();\n        node.focus();\n        return;\n      }\n      const first = items[0];\n      const last = items[items.length - 1];\n      const active = document.activeElement;\n      if (!node.contains(active)) {\n        e.preventDefault();\n        first.focus();\n      } else if (e.shiftKey && (active === first || active === node)) {\n        e.preventDefault();\n        last.focus();\n      } else if (!e.shiftKey && active === last) {\n        e.preventDefault();\n        first.focus();\n      }\n    };\n    document.addEventListener(\"keydown\", onKey);\n    return () => {\n      document.removeEventListener(\"keydown\", onKey);\n      if (!embedded) html.style.overflow = overflow;\n      if (steal && previous && previous.isConnected && previous !== document.body) previous.focus({ preventScroll: true });\n    };\n  }, [open, embedded, panel, userOpened]);\n}\n\nfunction fmt(s: number) {\n  const v = Math.max(0, Math.floor(s));\n  return `${Math.floor(v / 60)}:${String(v % 60).padStart(2, \"0\")}`;\n}\n\nconst speeds = [1, 1.5, 2];\n\nexport function ModalVideoChapters({\n  open,\n  defaultOpen,\n  onOpenChange,\n  embedded = false,\n  trigger = \"Watch the tour\",\n  title = \"Inside Relay: a six minute tour\",\n  src,\n  duration = 400,\n  chapters = defaultChapters,\n  captions = defaultCaptions,\n  autoPlay = true,\n  onProgress,\n  accent = \"#ffffff\",\n  className = \"\",\n  style,\n  ...rest\n}: ModalVideoChaptersProps) {\n  const [inner, setInner] = React.useState(defaultOpen ?? embedded);\n  const isOpen = open ?? inner;\n  const [present, setPresent] = React.useState(isOpen);\n  const [time, setTime] = React.useState(embedded ? 84 : 0);\n  const [length, setLength] = React.useState(duration);\n  const [playing, setPlaying] = React.useState(false);\n  const [muted, setMuted] = React.useState(false);\n  const [cc, setCc] = React.useState(true);\n  const [speed, setSpeed] = React.useState(1);\n  const [hover, setHover] = React.useState<number | null>(null);\n  const [idle, setIdle] = React.useState(false);\n  const userOpened = React.useRef(false);\n  const panel = React.useRef<HTMLDivElement>(null);\n  const video = React.useRef<HTMLVideoElement>(null);\n  const bar = React.useRef<HTMLDivElement>(null);\n  const idleTimer = React.useRef(0);\n  const id = React.useId();\n\n  if (isOpen && !present) setPresent(true);\n\n  const setOpen = React.useCallback(\n    (next: boolean) => {\n      if (next) {\n        userOpened.current = true;\n        setPlaying(autoPlay);\n      } else {\n        setPlaying(false);\n        video.current?.pause();\n      }\n      if (open === undefined) setInner(next);\n      onOpenChange?.(next);\n    },\n    [open, onOpenChange, autoPlay],\n  );\n  const close = React.useCallback(() => setOpen(false), [setOpen]);\n\n  React.useEffect(() => {\n    if (isOpen || !present) return;\n    const t = setTimeout(() => setPresent(false), 260);\n    return () => clearTimeout(t);\n  }, [isOpen, present]);\n\n  React.useEffect(() => {\n    if (src || !playing || !isOpen) return;\n    const t = setInterval(() => {\n      setTime((v) => {\n        const n = v + 0.25 * speed;\n        if (n >= length) {\n          setPlaying(false);\n          return length;\n        }\n        return n;\n      });\n    }, 250);\n    return () => clearInterval(t);\n  }, [src, playing, isOpen, speed, length]);\n\n  React.useEffect(() => {\n    const v = video.current;\n    if (!v) return;\n    v.muted = muted;\n    v.playbackRate = speed;\n    if (playing && isOpen) v.play().catch(() => setPlaying(false));\n    else v.pause();\n  }, [playing, muted, speed, isOpen, present]);\n\n  const progressRef = React.useRef(onProgress);\n  React.useEffect(() => {\n    progressRef.current = onProgress;\n  });\n  const whole = Math.floor(time);\n  React.useEffect(() => {\n    progressRef.current?.(whole);\n  }, [whole]);\n\n  React.useEffect(() => () => clearTimeout(idleTimer.current), []);\n\n  useLayer(isOpen, embedded, panel, close, userOpened);\n\n  function seek(t: number) {\n    const n = Math.min(Math.max(t, 0), length);\n    setTime(n);\n    if (video.current) video.current.currentTime = n;\n  }\n\n  function wake() {\n    setIdle(false);\n    clearTimeout(idleTimer.current);\n    if (playing) idleTimer.current = window.setTimeout(() => setIdle(true), 2400);\n  }\n\n  function at(clientX: number) {\n    const el = bar.current;\n    if (!el) return 0;\n    const r = el.getBoundingClientRect();\n    return (Math.min(Math.max(clientX - r.left, 0), r.width) / r.width) * length;\n  }\n\n  function onKeyDown(e: React.KeyboardEvent<HTMLDivElement>) {\n    const t = e.target as HTMLElement;\n    if (t.getAttribute(\"role\") === \"slider\") return;\n    if (e.key === \" \" || e.key === \"k\") {\n      if (t.tagName === \"BUTTON\" && e.key === \" \") return;\n      e.preventDefault();\n      setPlaying((p) => !p);\n    } else if (e.key === \"ArrowRight\") {\n      e.preventDefault();\n      seek(time + 5);\n    } else if (e.key === \"ArrowLeft\") {\n      e.preventDefault();\n      seek(time - 5);\n    } else if (e.key === \"m\") {\n      setMuted((m) => !m);\n    } else if (e.key === \"c\") {\n      setCc((c) => !c);\n    }\n    wake();\n  }\n\n  function onSliderKey(e: React.KeyboardEvent<HTMLDivElement>) {\n    const map: Record<string, number> = { ArrowRight: 5, ArrowUp: 5, ArrowLeft: -5, ArrowDown: -5, PageUp: 30, PageDown: -30 };\n    if (e.key in map) {\n      e.preventDefault();\n      seek(time + map[e.key]);\n    } else if (e.key === \"Home\") {\n      e.preventDefault();\n      seek(0);\n    } else if (e.key === \"End\") {\n      e.preventDefault();\n      seek(length);\n    }\n  }\n\n  const ci = Math.max(0, chapters.reduce((acc, c, i) => (time >= c.start ? i : acc), 0));\n  const chapter = chapters[ci];\n  const caption = captions.reduce<VideoCaption | null>((acc, c) => (time >= c.start ? c : acc), null);\n  const hoverChapter = hover === null ? null : chapters.reduce((acc, c, i) => (hover >= c.start ? i : acc), 0);\n  const vars = { \"--hb-xe9-accent\": accent, \"--hb-xe9-tint\": chapter?.tint ?? \"#6d5dfc\", ...style } as React.CSSProperties;\n  const playIcon = <svg viewBox=\"0 0 16 16\" fill=\"currentColor\" aria-hidden=\"true\"><path d=\"M4.5 2.8v10.4a.6.6 0 0 0 .9.5l8.2-5.2a.6.6 0 0 0 0-1L5.4 2.3a.6.6 0 0 0-.9.5Z\" /></svg>;\n  const pauseIcon = <svg viewBox=\"0 0 16 16\" fill=\"currentColor\" aria-hidden=\"true\"><rect x=\"3.5\" y=\"2.5\" width=\"3.2\" height=\"11\" rx=\"1\" /><rect x=\"9.3\" y=\"2.5\" width=\"3.2\" height=\"11\" rx=\"1\" /></svg>;\n\n  return (\n    <div className={`hb-xe9 ${className}`} data-embedded={embedded || undefined} style={vars} {...rest}>\n      <style href=\"hb-xe9-css\" precedence=\"default\">{css}</style>\n      {trigger !== null && (\n        <button type=\"button\" className=\"hb-xe9-card\" aria-haspopup=\"dialog\" aria-expanded={isOpen} onClick={() => setOpen(true)}>\n          <span className=\"hb-xe9-cdur\">{fmt(length)}</span>\n          <span className=\"hb-xe9-cplay\" aria-hidden=\"true\">{playIcon}</span>\n          <span className=\"hb-xe9-clabel\">{trigger}</span>\n        </button>\n      )}\n      {present && (\n        <div className=\"hb-xe9-layer\" data-state={isOpen ? \"open\" : \"closed\"}>\n          <div className=\"hb-xe9-scrim\" onClick={close} aria-hidden=\"true\" />\n          <div\n            ref={panel}\n            role=\"dialog\"\n            aria-modal=\"true\"\n            aria-labelledby={`${id}-t`}\n            tabIndex={-1}\n            className=\"hb-xe9-panel\"\n            onKeyDown={onKeyDown}\n          >\n            <div className=\"hb-xe9-player\" data-idle={idle && playing ? \"true\" : undefined} onPointerMove={wake}>\n              {src ? (\n                <video\n                  ref={video}\n                  className=\"hb-xe9-video\"\n                  src={src}\n                  playsInline\n                  preload=\"metadata\"\n                  onTimeUpdate={(e) => setTime(e.currentTarget.currentTime)}\n                  onLoadedMetadata={(e) => setLength(e.currentTarget.duration || duration)}\n                  onEnded={() => setPlaying(false)}\n                  onClick={() => setPlaying((p) => !p)}\n                />\n              ) : (\n                <div className=\"hb-xe9-scene\" onClick={() => setPlaying((p) => !p)} aria-hidden=\"true\">\n                  <div key={ci} className=\"hb-xe9-chap\">\n                    <small>Chapter {String(ci + 1).padStart(2, \"0\")}</small>\n                    <b>{chapter?.title}</b>\n                  </div>\n                </div>\n              )}\n              <div className=\"hb-xe9-top\">\n                <h2 id={`${id}-t`} className=\"hb-xe9-title\">{title}</h2>\n                <button type=\"button\" className=\"hb-xe9-x\" aria-label=\"Close video\" onClick={close}>\n                  <svg viewBox=\"0 0 16 16\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2\" strokeLinecap=\"round\" aria-hidden=\"true\"><path d=\"m4 4 8 8m0-8-8 8\" /></svg>\n                </button>\n              </div>\n              {!playing && (\n                <button type=\"button\" className=\"hb-xe9-big\" aria-label=\"Play\" onClick={() => setPlaying(true)}>{playIcon}</button>\n              )}\n              {cc && caption && (\n                <p key={caption.start} className=\"hb-xe9-cap\" aria-live=\"polite\" style={{ margin: 0 }}>{caption.text}</p>\n              )}\n              <div className=\"hb-xe9-ctrl\">\n                <div\n                  ref={bar}\n                  className=\"hb-xe9-scrub\"\n                  role=\"slider\"\n                  tabIndex={0}\n                  aria-label=\"Seek\"\n                  aria-valuemin={0}\n                  aria-valuemax={Math.round(length)}\n                  aria-valuenow={Math.round(time)}\n                  aria-valuetext={`${fmt(time)} of ${fmt(length)}, ${chapter?.title ?? \"\"}`}\n                  onKeyDown={onSliderKey}\n                  onPointerDown={(e) => {\n                    e.currentTarget.setPointerCapture(e.pointerId);\n                    seek(at(e.clientX));\n                  }}\n                  onPointerMove={(e) => {\n                    const t = at(e.clientX);\n                    setHover(t);\n                    if (e.currentTarget.hasPointerCapture(e.pointerId)) seek(t);\n                  }}\n                  onPointerLeave={() => setHover(null)}\n                >\n                  {chapters.map((c, i) => {\n                    const end = chapters[i + 1]?.start ?? length;\n                    const span = Math.max(end - c.start, 1);\n                    const p = Math.min(Math.max((time - c.start) / span, 0), 1);\n                    const h = hover === null ? 0 : Math.min(Math.max((hover - c.start) / span, 0), 1);\n                    return (\n                      <span\n                        key={c.title}\n                        className=\"hb-xe9-seg\"\n                        style={{ \"--hb-xe9-w\": span.toFixed(0), \"--hb-xe9-p\": p.toFixed(4), \"--hb-xe9-h\": h.toFixed(4) } as React.CSSProperties}\n                      >\n                        <b />\n                        <i />\n                      </span>\n                    );\n                  })}\n                  {hover !== null && hoverChapter !== null && (\n                    <span className=\"hb-xe9-tip\" style={{ left: `${((hover / length) * 100).toFixed(2)}%` }}>\n                      {chapters[hoverChapter]?.title}\n                      <span>{fmt(hover)}</span>\n                    </span>\n                  )}\n                </div>\n                <div className=\"hb-xe9-row\">\n                  <button type=\"button\" className=\"hb-xe9-btn\" aria-label={playing ? \"Pause\" : \"Play\"} onClick={() => setPlaying((p) => !p)}>\n                    {playing ? pauseIcon : playIcon}\n                  </button>\n                  <button type=\"button\" className=\"hb-xe9-btn hb-xe9-hide-sm\" aria-label=\"Back 10 seconds\" onClick={() => seek(time - 10)}>\n                    <svg viewBox=\"0 0 16 16\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.6\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\"><path d=\"M3 8a5 5 0 1 0 1.5-3.6M3 2.5v2.5h2.5\" /></svg>\n                  </button>\n                  <span className=\"hb-xe9-time\">{fmt(time)} / {fmt(length)}</span>\n                  <span className=\"hb-xe9-now\">· {chapter?.title}</span>\n                  <button type=\"button\" className=\"hb-xe9-btn\" aria-label=\"Captions\" aria-pressed={cc} onClick={() => setCc((c) => !c)}>CC</button>\n                  <button\n                    type=\"button\"\n                    className=\"hb-xe9-btn\"\n                    aria-label={`Playback speed ${speed}x`}\n                    onClick={() => setSpeed((s) => speeds[(speeds.indexOf(s) + 1) % speeds.length])}\n                  >\n                    {speed}x\n                  </button>\n                  <button type=\"button\" className=\"hb-xe9-btn\" aria-label={muted ? \"Unmute\" : \"Mute\"} aria-pressed={muted} onClick={() => setMuted((m) => !m)}>\n                    <svg viewBox=\"0 0 16 16\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.6\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n                      <path d=\"M2.5 6v4h2.5L8.5 13V3L5 6Z\" fill=\"currentColor\" />\n                      {muted ? <path d=\"m11 6 3.5 4m0-4L11 10\" /> : <path d=\"M11 5.5a3.5 3.5 0 0 1 0 5M12.8 3.6a6 6 0 0 1 0 8.8\" />}\n                    </svg>\n                  </button>\n                </div>\n              </div>\n            </div>\n          </div>\n        </div>\n      )}\n    </div>\n  );\n}\n"
    }
  ]
}