{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "scene-strip",
  "type": "registry:ui",
  "title": "Scene Strip",
  "description": "A row of the scenes or chapters of a clip, each with a picture, a name and a length, that scrolls sideways, marks the one that is playing and goes to a scene when it is pressed.",
  "categories": [
    "ui"
  ],
  "dependencies": [
    "lucide-react"
  ],
  "registryDependencies": [
    "@rivier-ui/theme",
    "@rivier-ui/cn",
    "@rivier-ui/direction",
    "@rivier-ui/use-media"
  ],
  "files": [
    {
      "path": "registry/ui/scene-strip.tsx",
      "type": "registry:ui",
      "target": "components/ui/scene-strip.tsx",
      "content": "\"use client\";\n/**\n * @name scene-strip\n * @category ui\n * @description A row of the scenes or chapters of a clip, each with a picture, a name and a length, that scrolls sideways, marks the one that is playing and goes to a scene when it is pressed.\n * @when Under or beside a player whose clip has named parts: chapters of a lesson, scenes of a film, steps of a recipe. It reads the time from the player it is inside (wrap the player and the strip in VideoPlayerProvider, or put it inside AudioPlayer), or from `time` and `onSeek`. For marks on the time bar itself use the scrubber's `marks`; for the spoken lines use Transcript.\n * @example\n * <VideoPlayerProvider>\n *   <VideoPlayer aria-label=\"A day at the pottery\">…</VideoPlayer>\n *   <SceneStrip\n *     aria-label=\"Scenes\"\n *     scenes={[\n *       { start: 0, label: \"Wedging the clay\", picture: <img src=\"/scene-1.jpg\" alt=\"\" /> },\n *       { start: 42, label: \"On the wheel\", picture: <img src=\"/scene-2.jpg\" alt=\"\" /> },\n *     ]}\n *   />\n * </VideoPlayerProvider>\n */\nimport { Play } from \"lucide-react\";\nimport { useEffect, useRef, type ComponentProps, type KeyboardEvent, type ReactNode } from \"react\";\nimport { cn } from \"@/lib/cn\";\nimport { inlineStep } from \"@/lib/direction\";\nimport { formatMediaTime, useOptionalMediaContext } from \"@/lib/use-media\";\n\nexport type Scene = {\n  /** When it starts, in seconds. */\n  start: number;\n  /** When it ends. Left out: where the next scene starts, or the end of the clip. */\n  end?: number;\n  /** Its name. */\n  label: string;\n  /** Its picture: an element that fills the frame (an `<img alt=\"\">`: the name is beside it). */\n  picture?: ReactNode;\n};\n\nexport type SceneStripProps = Omit<ComponentProps<\"div\">, \"children\"> & {\n  scenes: readonly Scene[];\n  /** The current time in seconds. Left out, it is the player's. */\n  time?: number;\n  /** The length of the clip in seconds, for the last scene's length. Left out, it is the player's. */\n  duration?: number;\n  /** Called with a scene's start when it is pressed. Left out, the player seeks there. */\n  onSeek?: (time: number, scene: Scene) => void;\n  /** The language tag lengths are formatted for. Left out, it is the player's. */\n  locale?: string;\n  /** What is said after the name of the playing scene (\"playing\"). Translate it with the interface. */\n  currentLabel?: string;\n};\n\n/**\n * A toolbar of buttons with one Tab stop: Left and Right (the other way round in right-to-left pages, where\n * the strip itself runs from the right) move between scenes, Home and End go to the first and last, Enter\n * or Space goes to the scene. The playing scene carries `aria-current`, a mark on its picture and its name\n * in a heavier weight, and is kept in view as the clip plays, without ever scrolling the page. Name the\n * strip with `aria-label` (\"Scenes\").\n */\nexport function SceneStrip({ className, scenes, time, duration, onSeek, locale, currentLabel = \"playing\", onKeyDown, ...props }: SceneStripProps) {\n  const context = useOptionalMediaContext();\n  const now = time ?? context?.state.time ?? 0;\n  const length = duration ?? context?.state.duration ?? 0;\n  const where = locale ?? context?.locale;\n  const box = useRef<HTMLDivElement>(null);\n\n  const endOf = (index: number): number => scenes[index]?.end ?? scenes[index + 1]?.start ?? length;\n  const current = scenes.findIndex((scene, index) => scene.start <= now && (now < endOf(index) || index === scenes.length - 1));\n\n  // Keep the playing scene in view by scrolling the strip only (scrollIntoView would move the page too).\n  useEffect(() => {\n    const strip = box.current;\n    const item = strip?.querySelector<HTMLElement>('[aria-current=\"true\"]');\n    if (!strip || !item) return;\n    const outer = strip.getBoundingClientRect();\n    const inner = item.getBoundingClientRect();\n    const shift = inner.left < outer.left ? inner.left - outer.left - 4 : inner.right > outer.right ? inner.right - outer.right + 4 : 0;\n    if (shift === 0) return;\n    strip.scrollBy({ left: shift, behavior: window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches ? \"instant\" : \"smooth\" });\n  }, [current]);\n\n  const handleKeyDown = (event: KeyboardEvent<HTMLDivElement>): void => {\n    onKeyDown?.(event);\n    if (event.defaultPrevented) return;\n    const items = [...event.currentTarget.querySelectorAll<HTMLButtonElement>(\"[data-slot=scene-strip-item]\")];\n    const at = items.indexOf(document.activeElement as HTMLButtonElement);\n    const step = inlineStep(event.key, event.currentTarget);\n    const next = step !== 0 ? at + step : event.key === \"Home\" ? 0 : event.key === \"End\" ? items.length - 1 : -1;\n    if (at === -1 || next < 0 || next >= items.length) return;\n    event.preventDefault();\n    // The player's own Left and Right (seek) must not also run.\n    event.stopPropagation();\n    items[next]?.focus();\n  };\n\n  // One Tab stop: the playing scene, or the first when none is.\n  const stop = current === -1 ? 0 : current;\n\n  return (\n    <div\n      ref={box}\n      data-slot=\"scene-strip\"\n      role=\"toolbar\"\n      aria-orientation=\"horizontal\"\n      onKeyDown={handleKeyDown}\n      className={cn(\"flex w-full min-w-0 snap-x scroll-px-1 gap-2 overflow-x-auto overscroll-x-contain p-1\", className)}\n      {...props}\n    >\n      {scenes.map((scene, index) => {\n        const playing = index === current;\n        const span = endOf(index) - scene.start;\n        return (\n          <button\n            key={`${scene.start}-${scene.label}`}\n            type=\"button\"\n            data-slot=\"scene-strip-item\"\n            tabIndex={index === stop ? 0 : -1}\n            aria-current={playing ? \"true\" : undefined}\n            onClick={() => (onSeek ? onSeek(scene.start, scene) : context?.actions.seek(scene.start))}\n            onFocus={(event) => event.currentTarget.scrollIntoView({ block: \"nearest\", inline: \"nearest\" })}\n            // relative: the visually hidden text inside is positioned, and must stay within the item so the strip clips it.\n            className=\"group/scene relative flex w-28 shrink-0 snap-start flex-col gap-1.5 rounded-control p-1 text-start text-xs text-muted-foreground transition-colors duration-instant ease-out hover:bg-accent hover:text-foreground aria-[current=true]:text-foreground motion-reduce:transition-none sm:w-36\"\n          >\n            <span\n              data-slot=\"scene-strip-picture\"\n              className=\"relative block aspect-video w-full overflow-hidden rounded-control border border-border-strong bg-muted group-aria-[current=true]/scene:border-primary [&>img]:size-full [&>img]:object-cover\"\n            >\n              {scene.picture}\n              {playing ? (\n                <span aria-hidden=\"true\" className=\"absolute start-1 bottom-1 inline-flex size-5 items-center justify-center rounded-control bg-primary text-primary-foreground\">\n                  <Play strokeWidth={2} className=\"size-3\" />\n                </span>\n              ) : null}\n            </span>\n            <span className=\"flex min-w-0 items-baseline justify-between gap-2\">\n              <span data-slot=\"scene-strip-label\" className=\"min-w-0 truncate group-aria-[current=true]/scene:font-medium\">\n                {scene.label}\n                {playing ? <span className=\"sr-only\">, {currentLabel}</span> : null}\n              </span>\n              {span > 0 ? (\n                <span data-slot=\"scene-strip-length\" className=\"shrink-0 tabular-nums\">\n                  {formatMediaTime(span, where)}\n                </span>\n              ) : null}\n            </span>\n          </button>\n        );\n      })}\n    </div>\n  );\n}\n"
    }
  ],
  "meta": {
    "category": "ui",
    "when": "Under or beside a player whose clip has named parts: chapters of a lesson, scenes of a film, steps of a recipe. It reads the time from the player it is inside (wrap the player and the strip in VideoPlayerProvider, or put it inside AudioPlayer), or from `time` and `onSeek`. For marks on the time bar itself use the scrubber's `marks`; for the spoken lines use Transcript.",
    "example": "<VideoPlayerProvider>\n  <VideoPlayer aria-label=\"A day at the pottery\">…</VideoPlayer>\n  <SceneStrip\n    aria-label=\"Scenes\"\n    scenes={[\n      { start: 0, label: \"Wedging the clay\", picture: <img src=\"/scene-1.jpg\" alt=\"\" /> },\n      { start: 42, label: \"On the wheel\", picture: <img src=\"/scene-2.jpg\" alt=\"\" /> },\n    ]}\n  />\n</VideoPlayerProvider>",
    "client": true
  }
}
