{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "review-16",
  "title": "Checkpoint rewind",
  "description": "A timeline of checkpoints where picking one previews the files a rewind would revert, then the Now marker glides back, what came after dims, and Redo brings it back.",
  "dependencies": [
    "motion"
  ],
  "registryDependencies": [
    "https://ui.ndekocode.dev/r/animated-size.json",
    "https://ui.ndekocode.dev/r/button.json",
    "https://ui.ndekocode.dev/r/chip.json",
    "https://ui.ndekocode.dev/r/demonstration.json",
    "https://ui.ndekocode.dev/r/icons.json",
    "https://ui.ndekocode.dev/r/live-region.json",
    "https://ui.ndekocode.dev/r/motion-number.json",
    "https://ui.ndekocode.dev/r/motion-presets.json",
    "https://ui.ndekocode.dev/r/segments.json",
    "https://ui.ndekocode.dev/r/theme.json",
    "https://ui.ndekocode.dev/r/use-autoplay.json",
    "https://ui.ndekocode.dev/r/use-kept-height.json",
    "https://ui.ndekocode.dev/r/use-prefers-reduced-motion.json",
    "https://ui.ndekocode.dev/r/utils.json",
    "https://ui.ndekocode.dev/r/words.json"
  ],
  "files": [
    {
      "path": "registry/ndeko/components/review/review-16.tsx",
      "content": "'use client';\n\nimport { AnimatePresence, motion } from 'motion/react';\nimport { useId, useImperativeHandle, useRef, useState } from 'react';\n\nimport { MotionNumber } from '@/components/core/motion-number';\nimport {\n  useAutoplay,\n  type AutoplayStep,\n} from '@/registry/ndeko/hooks/use-autoplay';\nimport { useKeptHeight } from '@/registry/ndeko/hooks/use-kept-height';\nimport { usePrefersReducedMotion } from '@/registry/ndeko/hooks/use-prefers-reduced-motion';\nimport {\n  hold,\n  PRESS_LEAD_MS,\n  pressedSolidOf,\n  spokenUnless,\n  usePress,\n} from '@/registry/ndeko/lib/demonstration';\nimport {\n  HistoryIcon,\n  RedoIcon,\n  RotateCcwIcon,\n} from '@/registry/ndeko/lib/icons';\nimport {\n  fadePresence,\n  rowPresenceOf,\n} from '@/registry/ndeko/lib/motion-presets';\nimport { cn } from '@/registry/ndeko/lib/utils';\nimport { countOf, nounOf } from '@/registry/ndeko/lib/words';\nimport { AnimatedSize } from '@/registry/ndeko/ui/animated-size';\nimport { Button } from '@/registry/ndeko/ui/button';\nimport { Chip } from '@/registry/ndeko/ui/chip';\nimport { LiveRegion } from '@/registry/ndeko/ui/live-region';\nimport { Segments, type Segment } from '@/registry/ndeko/ui/segments';\n\nimport { pathPartsOf } from './_parts/path-parts';\nimport { useFocusHandOff } from './_parts/use-focus-hand-off';\n\nexport type FileChange = {\n  path: string;\n  added: number;\n  removed: number;\n};\n\nexport type Checkpoint = {\n  id: string;\n  /** The turn that made the checkpoint, as the person asked it. */\n  turn: string;\n  time: string;\n  /** The files that turn changed. */\n  changes: FileChange[];\n};\n\nexport type RewindMode = 'code' | 'both';\n\nexport type RewindState = {\n  selectedId: string | null;\n  nowId: string;\n  /** Where Now was before the first rewind, so Redo can go back there. */\n  redoId: string | null;\n  mode: RewindMode;\n  /** The mode the last rewind used. */\n  appliedMode: RewindMode;\n};\n\n/** The control a demonstration holds down: a row by its id, Rewind or Redo. */\nexport type CheckpointRewindPress = 'rewind' | 'redo' | `row-${string}`;\n\nexport type CheckpointRewindHandle = {\n  select: (checkpointId: string) => void;\n  setMode: (mode: RewindMode) => void;\n  rewind: () => void;\n  redo: () => void;\n};\n\nconst ROW_PX = 48;\n\nconst MAX_FILES = 5;\n\nconst MODES: Segment<RewindMode>[] = [\n  { value: 'code', label: 'Code only' },\n  { value: 'both', label: 'Code and conversation' },\n];\n\nconst MODE_WORDS: Record<RewindMode, string> = {\n  code: 'code only',\n  both: 'code and conversation',\n};\n\nconst UNDONE_WORDS: Record<RewindMode, string> = {\n  code: 'Code reverted',\n  both: 'Removed',\n};\n\nconst ROW_PRESSED = 'scale-[0.985] bg-foreground/[0.06]';\n\nfunction rowPressedOf(isPressed: boolean) {\n  if (isPressed) {\n    return ROW_PRESSED;\n  }\n  return undefined;\n}\n\nexport function startStateOf(checkpoints: Checkpoint[]): RewindState {\n  const last = checkpoints[checkpoints.length - 1];\n  return {\n    selectedId: null,\n    nowId: last?.id ?? '',\n    redoId: null,\n    mode: 'code',\n    appliedMode: 'code',\n  };\n}\n\nfunction indexOfId(checkpoints: Checkpoint[], id: string | null) {\n  return checkpoints.findIndex((entry) => entry.id === id);\n}\n\nfunction revertOf(\n  checkpoints: Checkpoint[],\n  nowIndex: number,\n  targetIndex: number\n) {\n  const merged = new Map<string, FileChange>();\n  for (let index = targetIndex + 1; index <= nowIndex; index += 1) {\n    for (const change of checkpoints[index].changes) {\n      const existing = merged.get(change.path);\n      if (!existing) {\n        merged.set(change.path, change);\n        continue;\n      }\n      merged.set(change.path, {\n        path: change.path,\n        added: existing.added + change.added,\n        removed: existing.removed + change.removed,\n      });\n    }\n  }\n  return Array.from(merged.values());\n}\n\nfunction linesOf(files: FileChange[]) {\n  let lines = 0;\n  for (const file of files) {\n    lines += file.added + file.removed;\n  }\n  return lines;\n}\n\nfunction panelKeyOf(\n  isEmpty: boolean,\n  isPreviewing: boolean,\n  isRewound: boolean\n) {\n  if (isEmpty) {\n    return 'empty';\n  }\n  if (isPreviewing) {\n    return 'preview';\n  }\n  if (isRewound) {\n    return 'rewound';\n  }\n  return 'hint';\n}\n\nfunction dotToneOf(isMarked: boolean, isUndone: boolean) {\n  if (isMarked) {\n    return 'bg-primary';\n  }\n  if (isUndone) {\n    return 'bg-foreground/15';\n  }\n  return 'bg-foreground/35';\n}\n\nfunction selectedToneOf(isSelected: boolean) {\n  if (isSelected) {\n    return 'bg-foreground/[0.05]';\n  }\n  return undefined;\n}\n\nfunction undoneToneOf(isUndone: boolean) {\n  if (isUndone) {\n    return 'opacity-50';\n  }\n  return undefined;\n}\n\nfunction handOffOf(isNow: boolean) {\n  if (isNow) {\n    return '';\n  }\n  return undefined;\n}\n\ntype CheckpointRowProps = {\n  checkpoint: Checkpoint;\n  name: string;\n  isSelected: boolean;\n  isNow: boolean;\n  isUndone: boolean;\n  undoneWord: string;\n  isPressed: boolean;\n  onSelect: (checkpointId: string) => void;\n};\n\nfunction CheckpointRow({\n  checkpoint,\n  name,\n  isSelected,\n  isNow,\n  isUndone,\n  undoneWord,\n  isPressed,\n  onSelect,\n}: CheckpointRowProps) {\n  const fileCount = countOf(checkpoint.changes.length, 'file');\n  const isMarked = isSelected || isNow;\n\n  return (\n    <div className='relative'>\n      <label\n        className={cn(\n          'hover:bg-foreground/[0.03] has-[:focus-visible]:ring-ring/25 flex h-12 cursor-pointer items-center gap-2 rounded-lg ps-2 pe-24 transition-[background-color,opacity,scale] duration-150 ease-(--ease-out-strong) has-[:disabled]:cursor-default has-[:focus-visible]:ring-[3px] has-[:focus-visible]:ring-inset',\n          selectedToneOf(isSelected),\n          undoneToneOf(isUndone),\n          rowPressedOf(isPressed)\n        )}\n      >\n        <input\n          type='radio'\n          name={name}\n          checked={isSelected}\n          disabled={isUndone}\n          data-hand-off={handOffOf(isNow)}\n          onChange={() => onSelect(checkpoint.id)}\n          className='sr-only'\n        />\n        <span aria-hidden='true' className='flex w-4 shrink-0 justify-center'>\n          <span\n            className={cn(\n              'ring-card size-2 rounded-full ring-4 transition-colors duration-150',\n              dotToneOf(isMarked, isUndone)\n            )}\n          />\n        </span>\n        <span className='flex min-w-0 flex-1 flex-col'>\n          <span className='truncate text-[13px] font-medium'>\n            {isNow && <span className='sr-only'>Now, </span>}\n            {checkpoint.turn}\n          </span>\n          <span className='text-muted-foreground truncate text-xs tabular-nums'>\n            {checkpoint.time}, {fileCount}\n          </span>\n        </span>\n        {isUndone && (\n          <span className='text-muted-foreground absolute end-2 text-xs'>\n            {undoneWord}\n          </span>\n        )}\n      </label>\n    </div>\n  );\n}\n\nfunction FileLine({ file }: { file: FileChange }) {\n  const { folder, name } = pathPartsOf(file.path);\n  const total = file.added + file.removed;\n  const label = `${file.added} lines added, ${file.removed} removed`;\n\n  return (\n    <div className='flex items-center gap-3 py-1 text-xs'>\n      <span className='min-w-0 flex-1 truncate font-mono'>\n        <span className='text-muted-foreground'>{folder}</span>\n        {name}\n      </span>\n      <span className='tabular-nums' aria-label={label}>\n        <span className='text-success-foreground'>+{file.added}</span>{' '}\n        <span className='text-destructive-ink'>-{file.removed}</span>\n      </span>\n      <span\n        aria-hidden='true'\n        className='bg-foreground/[0.06] flex h-1.5 w-12 shrink-0 overflow-hidden rounded-full'\n      >\n        <span\n          className='bg-success/70 h-full'\n          style={{ flexGrow: file.added, flexBasis: 0 }}\n        />\n        <span\n          className='bg-destructive/70 h-full'\n          style={{ flexGrow: file.removed, flexBasis: 0 }}\n        />\n        <span className='sr-only'>{total}</span>\n      </span>\n    </div>\n  );\n}\n\ntype PreviewPanelProps = {\n  target: Checkpoint;\n  files: FileChange[];\n  mode: RewindMode;\n  isRewindPressed: boolean;\n  onModeChange: (mode: RewindMode) => void;\n  onRewind: () => void;\n};\n\nfunction PreviewPanel({\n  target,\n  files,\n  mode,\n  isRewindPressed,\n  onModeChange,\n  onRewind,\n}: PreviewPanelProps) {\n  const shouldReduceMotion = usePrefersReducedMotion();\n  const rowPresence = rowPresenceOf(shouldReduceMotion);\n  const shown = files.slice(0, MAX_FILES);\n  const hidden = files.length - shown.length;\n  const lines = linesOf(files);\n  const fileNoun = nounOf(files.length, 'file');\n  const lineNoun = nounOf(lines, 'line');\n\n  return (\n    <div className='bg-foreground/[0.04] flex flex-col gap-3 rounded-lg p-3'>\n      <p className='text-xs leading-5'>\n        Rewinding to <span className='font-medium'>{target.turn}</span> undoes{' '}\n        <MotionNumber value={files.length} className='font-medium' /> {fileNoun}\n        , <MotionNumber value={lines} className='font-medium' /> {lineNoun}{' '}\n        changed.\n      </p>\n      <div className='flex flex-col'>\n        <AnimatePresence initial={false}>\n          {shown.map((file) => (\n            <motion.div\n              key={file.path}\n              className='overflow-hidden'\n              {...rowPresence}\n            >\n              <FileLine file={file} />\n            </motion.div>\n          ))}\n        </AnimatePresence>\n        {hidden > 0 && (\n          <p className='text-muted-foreground py-1 text-xs'>\n            and {countOf(hidden, 'more file')}\n          </p>\n        )}\n      </div>\n      <Segments\n        value={mode}\n        segments={MODES}\n        onValueChange={onModeChange}\n        label='What to rewind'\n        className='w-full @sm:w-fit'\n      />\n      <div className='flex items-center gap-3'>\n        <Button\n          type='button'\n          size='sm'\n          onClick={onRewind}\n          className={pressedSolidOf(isRewindPressed)}\n        >\n          <RotateCcwIcon />\n          Rewind\n        </Button>\n        <p className='text-muted-foreground text-xs'>\n          Nothing is lost, Redo brings it back\n        </p>\n      </div>\n    </div>\n  );\n}\n\ntype RewoundPanelProps = {\n  target: Checkpoint;\n  mode: RewindMode;\n  isRedoPressed: boolean;\n  onRedo: () => void;\n};\n\nfunction RewoundPanel({\n  target,\n  mode,\n  isRedoPressed,\n  onRedo,\n}: RewoundPanelProps) {\n  return (\n    <div className='bg-foreground/[0.04] flex items-center gap-3 rounded-lg p-3'>\n      <p className='min-w-0 flex-1 text-xs leading-5'>\n        Rewound to <span className='font-medium'>{target.turn}</span>,{' '}\n        {MODE_WORDS[mode]}.\n      </p>\n      <Button\n        type='button'\n        size='sm'\n        variant='outline'\n        onClick={onRedo}\n        className={pressedSolidOf(isRedoPressed)}\n      >\n        <RedoIcon />\n        Redo\n      </Button>\n    </div>\n  );\n}\n\nexport type CheckpointRewindProps = {\n  checkpoints: Checkpoint[];\n  /** The state the card first shows. Rewinding and redoing are kept in it. */\n  initialState?: RewindState;\n  /** Something new happened after a rewind: the turns that came after Now are gone and Redo with them. */\n  hasNewActivity?: boolean;\n  onRewind?: (checkpointId: string, mode: RewindMode) => void;\n  onRedo?: () => void;\n  /** Putting the card back to its first state: change this number. */\n  resetToken?: number;\n  handleRef?: React.Ref<CheckpointRewindHandle>;\n  pressed?: CheckpointRewindPress | null;\n  /** A demonstration is not read aloud. */\n  isDemonstrating?: boolean;\n  className?: string;\n};\n\nexport function CheckpointRewind({\n  checkpoints,\n  initialState,\n  hasNewActivity = false,\n  onRewind,\n  onRedo,\n  resetToken = 0,\n  handleRef,\n  pressed = null,\n  isDemonstrating = false,\n  className,\n}: CheckpointRewindProps) {\n  const first = initialState ?? startStateOf(checkpoints);\n  const [state, setState] = useState(first);\n  const [notice, setNotice] = useState('');\n  const [seenToken, setSeenToken] = useState(resetToken);\n  const groupName = useId();\n  const fade = fadePresence();\n  const shouldReduceMotion = usePrefersReducedMotion();\n  const rowPresence = rowPresenceOf(shouldReduceMotion);\n  const { rootRef, markIfFocusInside } = useFocusHandOff(String(state.nowId));\n  const nowIndex = indexOfId(checkpoints, state.nowId);\n  const selectedIndex = indexOfId(checkpoints, state.selectedId);\n  const lastIndex = checkpoints.length - 1;\n  const isRewound = nowIndex < lastIndex;\n  const isPreviewing = selectedIndex >= 0 && selectedIndex < nowIndex;\n  const canRedo = isRewound && !hasNewActivity && state.redoId !== null;\n  const showsRewound = isRewound && !isPreviewing;\n  const isEmpty = checkpoints.length === 0;\n  const panelKey = panelKeyOf(isEmpty, isPreviewing, showsRewound);\n  const target = checkpoints[selectedIndex];\n  const nowCheckpoint = checkpoints[nowIndex];\n  const files = revertOf(checkpoints, nowIndex, selectedIndex);\n  const visibleCount = visibleCountOf(\n    checkpoints.length,\n    nowIndex,\n    hasNewActivity\n  );\n  const visible = checkpoints.slice(0, visibleCount);\n  const undoneWord = UNDONE_WORDS[state.appliedMode];\n\n  if (seenToken !== resetToken) {\n    setSeenToken(resetToken);\n    setState(first);\n  }\n\n  function select(checkpointId: string) {\n    const index = indexOfId(checkpoints, checkpointId);\n    const isUndone = index > nowIndex;\n    if (isUndone) {\n      return;\n    }\n    setState((current) => ({ ...current, selectedId: checkpointId }));\n    if (index === nowIndex) {\n      setNotice('You are here');\n      return;\n    }\n    const undone = revertOf(checkpoints, nowIndex, index);\n    const turn = checkpoints[index].turn;\n    setNotice(`Rewinding to ${turn} undoes ${countOf(undone.length, 'file')}`);\n  }\n\n  function setMode(mode: RewindMode) {\n    setState((current) => ({ ...current, mode }));\n  }\n\n  function rewind() {\n    if (!isPreviewing) {\n      return;\n    }\n    markIfFocusInside();\n    const redoId = state.redoId ?? state.nowId;\n    setState((current) => ({\n      ...current,\n      nowId: target.id,\n      selectedId: null,\n      redoId,\n      appliedMode: current.mode,\n    }));\n    setNotice(`Rewound to ${target.turn}, ${MODE_WORDS[state.mode]}`);\n    onRewind?.(target.id, state.mode);\n  }\n\n  function redo() {\n    if (!canRedo || state.redoId === null) {\n      return;\n    }\n    markIfFocusInside();\n    const backTo = state.redoId;\n    setState((current) => ({\n      ...current,\n      nowId: backTo,\n      selectedId: null,\n      redoId: null,\n    }));\n    setNotice('Redone, back at the latest checkpoint');\n    onRedo?.();\n  }\n\n  useImperativeHandle(handleRef, () => ({ select, setMode, rewind, redo }));\n\n  function handleKeys(event: React.KeyboardEvent<HTMLDivElement>) {\n    const isEscape = event.key === 'Escape';\n    const isEnter = event.key === 'Enter';\n    const isOnRadio = event.target instanceof HTMLInputElement;\n    if (isEscape && state.selectedId !== null) {\n      event.preventDefault();\n      setState((current) => ({ ...current, selectedId: null }));\n      return;\n    }\n    const canRewind = isEnter && isOnRadio && isPreviewing;\n    if (canRewind) {\n      event.preventDefault();\n      rewind();\n    }\n  }\n\n  return (\n    <div\n      ref={rootRef}\n      onKeyDown={handleKeys}\n      className={cn(\n        'surface-raised @container flex flex-col gap-3 rounded-xl p-4',\n        className\n      )}\n    >\n      <div className='flex items-center justify-between gap-3'>\n        <h3 className='flex items-center gap-2 text-sm font-medium'>\n          <HistoryIcon className='text-muted-foreground size-4' />\n          Checkpoints\n        </h3>\n        <p className='text-muted-foreground text-xs tabular-nums'>\n          {countOf(visible.length, 'turn')}\n        </p>\n      </div>\n      <fieldset className='relative min-w-0'>\n        <legend className='sr-only'>Pick a checkpoint to rewind to</legend>\n        <span\n          aria-hidden='true'\n          className='bg-border absolute start-4 top-6 w-(--hairline)'\n          style={{ height: Math.max(0, visible.length - 1) * ROW_PX }}\n        />\n        {!isEmpty && (\n          <span\n            aria-hidden='true'\n            style={{ transform: `translateY(${nowIndex * ROW_PX}px)` }}\n            className='bg-primary/[0.05] hairline-ring ring-primary/40 absolute inset-x-0 top-0 h-12 rounded-lg transition-transform duration-500 ease-(--ease-in-out-strong)'\n          >\n            <Chip\n              color='var(--primary)'\n              className='absolute end-2 top-1/2 -translate-y-1/2'\n            >\n              Now\n            </Chip>\n          </span>\n        )}\n        <ul className='relative flex flex-col'>\n          <AnimatePresence initial={false}>\n            {visible.map((checkpoint, index) => (\n              <motion.li\n                key={checkpoint.id}\n                className='relative z-10 overflow-hidden'\n                {...rowPresence}\n              >\n                <CheckpointRow\n                  checkpoint={checkpoint}\n                  name={groupName}\n                  isSelected={checkpoint.id === state.selectedId}\n                  isNow={index === nowIndex}\n                  isUndone={index > nowIndex}\n                  undoneWord={undoneWord}\n                  isPressed={pressed === `row-${checkpoint.id}`}\n                  onSelect={select}\n                />\n              </motion.li>\n            ))}\n          </AnimatePresence>\n        </ul>\n      </fieldset>\n      <AnimatedSize>\n        <AnimatePresence initial={false} mode='popLayout'>\n          <motion.div key={panelKey} {...fade}>\n            {panelKey === 'preview' && (\n              <PreviewPanel\n                target={target}\n                files={files}\n                mode={state.mode}\n                isRewindPressed={pressed === 'rewind'}\n                onModeChange={setMode}\n                onRewind={rewind}\n              />\n            )}\n            {panelKey === 'rewound' && (\n              <RewoundPanel\n                target={nowCheckpoint}\n                mode={state.appliedMode}\n                isRedoPressed={pressed === 'redo'}\n                onRedo={redo}\n              />\n            )}\n            {panelKey === 'empty' && (\n              <p className='text-muted-foreground px-1 py-3 text-xs leading-5'>\n                No checkpoints yet. One is saved at the start of every turn.\n              </p>\n            )}\n            {panelKey === 'hint' && (\n              <p className='text-muted-foreground px-1 py-3 text-xs leading-5'>\n                Pick a checkpoint to see what rewinding to it would undo\n              </p>\n            )}\n          </motion.div>\n        </AnimatePresence>\n      </AnimatedSize>\n      <LiveRegion message={spokenUnless(isDemonstrating, notice)} />\n    </div>\n  );\n}\n\nfunction visibleCountOf(\n  total: number,\n  nowIndex: number,\n  hasNewActivity: boolean\n) {\n  if (hasNewActivity) {\n    return nowIndex + 1;\n  }\n  return total;\n}\n\nconst CHECKPOINTS: Checkpoint[] = [\n  {\n    id: 'scaffold',\n    turn: 'Scaffold the invoice page',\n    time: '11:02',\n    changes: [\n      { path: 'src/app/invoice/page.tsx', added: 64, removed: 0 },\n      { path: 'src/lib/invoice.ts', added: 38, removed: 0 },\n    ],\n  },\n  {\n    id: 'table',\n    turn: 'Add the line items table',\n    time: '11:09',\n    changes: [\n      { path: 'components/line-items.tsx', added: 72, removed: 0 },\n      { path: 'src/app/invoice/page.tsx', added: 18, removed: 6 },\n    ],\n  },\n  {\n    id: 'rounding',\n    turn: 'Round totals to cents',\n    time: '11:21',\n    changes: [\n      { path: 'src/lib/invoice.ts', added: 21, removed: 9 },\n      { path: 'tests/invoice.test.ts', added: 34, removed: 0 },\n    ],\n  },\n  {\n    id: 'tax',\n    turn: 'Add the Kinshasa tax rule',\n    time: '11:34',\n    changes: [\n      { path: 'src/lib/tax.ts', added: 46, removed: 3 },\n      { path: 'src/lib/invoice.ts', added: 12, removed: 2 },\n      { path: 'tests/tax.test.ts', added: 40, removed: 0 },\n    ],\n  },\n  {\n    id: 'rename',\n    turn: 'Rename the totals component',\n    time: '11:48',\n    changes: [\n      { path: 'components/totals.tsx', added: 8, removed: 8 },\n      { path: 'src/lib/tax.ts', added: 2, removed: 2 },\n    ],\n  },\n];\n\nconst RESTING_STATE: RewindState = {\n  selectedId: null,\n  nowId: 'rounding',\n  redoId: 'rename',\n  mode: 'both',\n  appliedMode: 'both',\n};\n\nfunction initialStateOf(isResting: boolean) {\n  if (isResting) {\n    return RESTING_STATE;\n  }\n  return startStateOf(CHECKPOINTS);\n}\n\nfunction RewindDemo({ isResting }: { isResting: boolean }) {\n  const [round, setRound] = useState(0);\n  const card = useRef<CheckpointRewindHandle>(null);\n  const { pressed, press } = usePress<CheckpointRewindPress>();\n\n  function resetDemo() {\n    setRound((current) => current + 1);\n  }\n\n  const steps: AutoplayStep[] = [\n    { after: 1500, run: () => press('row-rounding') },\n    { after: PRESS_LEAD_MS, run: () => card.current?.select('rounding') },\n    { after: 2000, run: () => card.current?.setMode('both') },\n    { after: 1600, run: () => press('rewind') },\n    { after: PRESS_LEAD_MS, run: () => card.current?.rewind() },\n    { after: 2800, run: () => press('redo') },\n    { after: PRESS_LEAD_MS, run: () => card.current?.redo() },\n    { after: 2400, run: hold },\n  ];\n  const { ref, isAutoplaying } = useAutoplay(steps, {\n    loopAfter: 1800,\n    onReset: resetDemo,\n  });\n\n  useKeptHeight(ref);\n\n  return (\n    <div\n      ref={ref}\n      className='flex min-h-[39rem] w-full max-w-[30rem] flex-col gap-2'\n    >\n      <CheckpointRewind\n        checkpoints={CHECKPOINTS}\n        initialState={initialStateOf(isResting)}\n        resetToken={round}\n        handleRef={card}\n        pressed={pressed}\n        isDemonstrating={isAutoplaying}\n      />\n      <p className='text-muted-foreground px-1 text-xs'>\n        Illustrative session, no file was touched\n      </p>\n    </div>\n  );\n}\n\nexport default function Review16() {\n  const shouldReduceMotion = usePrefersReducedMotion();\n  const restKey = String(shouldReduceMotion);\n\n  return <RewindDemo key={restKey} isResting={shouldReduceMotion} />;\n}\n",
      "type": "registry:component",
      "target": "components/review/review-16.tsx"
    },
    {
      "path": "registry/ndeko/components/review/_parts/path-parts.ts",
      "content": "export function pathPartsOf(path: string) {\n  const slash = path.lastIndexOf('/');\n  if (slash < 0) {\n    return { folder: '', name: path };\n  }\n  const nameStart = slash + 1;\n  const folder = path.slice(0, nameStart);\n  const name = path.slice(nameStart);\n  return { folder, name };\n}\n",
      "type": "registry:component",
      "target": "components/review/_parts/path-parts.ts"
    },
    {
      "path": "registry/ndeko/components/review/_parts/use-focus-hand-off.ts",
      "content": "'use client';\n\nimport { useCallback, useEffect, useRef } from 'react';\n\n/**\n * When a card turns into another view, the control a person just used is gone and focus would fall\n * to the page. If focus was inside the card, it goes to the last element marked `data-hand-off`\n * once the new view is in place; a demonstration never had focus there, so it never moves it.\n */\nexport function useFocusHandOff(phase: string) {\n  const rootRef = useRef<HTMLDivElement>(null);\n  const isPending = useRef(false);\n\n  const markIfFocusInside = useCallback(() => {\n    const root = rootRef.current;\n    if (!root) {\n      return;\n    }\n    isPending.current = root.contains(document.activeElement);\n  }, []);\n\n  useEffect(() => {\n    if (!isPending.current) {\n      return;\n    }\n    isPending.current = false;\n    const root = rootRef.current;\n    if (!root) {\n      return;\n    }\n    const targets = root.querySelectorAll<HTMLElement>('[data-hand-off]');\n    const target = targets[targets.length - 1];\n    target?.focus();\n  }, [phase]);\n\n  return { rootRef, markIfFocusInside };\n}\n",
      "type": "registry:component",
      "target": "components/review/_parts/use-focus-hand-off.ts"
    }
  ],
  "categories": [
    "components",
    "review"
  ],
  "type": "registry:component"
}