{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "tour",
  "title": "Tour",
  "description": "A step-by-step product tour with a spotlight cut-out, anchored to a selector or a ref. It manages focus, scrolls targets into view, follows them on resize and skips the ones that are missing.",
  "dependencies": [
    "lucide-react",
    "motion",
    "radix-ui"
  ],
  "registryDependencies": [
    "utils",
    "https://miseui.junsu4621.workers.dev/r/motion.json",
    "https://miseui.junsu4621.workers.dev/r/button.json"
  ],
  "files": [
    {
      "path": "registry/miseui/ui/tour.tsx",
      "content": "import type * as React from \"react\"\nimport { useEffect, useLayoutEffect, useRef, useState } from \"react\"\nimport { Dialog as DialogPrimitive } from \"radix-ui\"\nimport { motion, useReducedMotion } from \"motion/react\"\nimport { SPRING_DEFAULT } from \"@/registry/miseui/lib/motion\"\nimport { placePopover, type TourPlacement, type TourSize } from \"@/registry/miseui/ui/tour-math\"\nimport { StepCopy, StepFooter, TourChecklist, TourHighlight, type TourLabels } from \"@/registry/miseui/ui/tour-parts\"\nimport { useTour, type TourStep } from \"@/registry/miseui/ui/tour-state\"\nimport { cn } from \"@/registry/miseui/lib/utils\"\n\ntype TourVariant = \"spotlight\" | \"popover\" | \"banner\" | \"checklist\"\ntype TourEffect = \"spring\"\n\nconst INSTANT = { duration: 0 } as const\nconst DEFAULT_LABELS: TourLabels = { next: \"Next\", back: \"Back\", finish: \"Done\", close: \"Close tour\" }\n\nconst SURFACE_CLASS = \"z-50 grid gap-3 rounded-xl border bg-popover p-4 text-popover-foreground shadow-lg outline-none\"\nconst LAYOUT_CLASS: Record<TourVariant, string> = {\n  spotlight: \"fixed top-0 left-0 w-[min(20rem,calc(100vw-1rem))]\",\n  popover: \"fixed top-0 left-0 w-[min(20rem,calc(100vw-1rem))]\",\n  banner: \"fixed inset-x-0 bottom-4 mx-auto w-[min(36rem,calc(100vw-2rem))]\",\n  checklist: \"fixed right-4 bottom-4 max-h-[calc(100dvh-2rem)] w-[min(20rem,calc(100vw-2rem))] overflow-y-auto\",\n}\n\ntype TourProps = {\n  steps: readonly TourStep[]\n  open?: boolean\n  defaultOpen?: boolean\n  onOpenChange?: (open: boolean) => void\n  /** Where to begin. Steps whose target is missing are skipped. */\n  defaultStep?: number\n  onStepChange?: (index: number) => void\n  /** The last step was completed, as opposed to the tour being closed early. */\n  onFinish?: () => void\n  /** `spotlight` dims all but the target, `popover` points without dimming, `banner` a bar along the bottom, `checklist` a corner card of all the steps. */\n  variant?: TourVariant\n  /** `spring` carries the highlight and the card to each new target. */\n  effect?: TourEffect\n  /** Air around the target, in px. */\n  padding?: number\n  /** Title of `checklist`. */\n  title?: React.ReactNode\n  labels?: Partial<TourLabels>\n  className?: string\n}\n\n/** Takes the element itself, not a ref: the portal mounts the card after the first layout effect has already run. */\nfunction useElementSize(element: HTMLElement | null): TourSize {\n  const [size, setSize] = useState<TourSize>({ width: 0, height: 0 })\n  useLayoutEffect(() => {\n    if (!element) return undefined\n    const measure = () => setSize({ width: element.offsetWidth, height: element.offsetHeight })\n    measure()\n    if (typeof ResizeObserver === \"undefined\") return undefined\n    const observer = new ResizeObserver(measure)\n    observer.observe(element)\n    return () => observer.disconnect()\n  }, [element])\n  return size\n}\n\n/** True from the second frame. A card still finding its size must appear in place, not slide there. */\nfunction useSettled() {\n  const [settled, setSettled] = useState(false)\n  useEffect(() => {\n    const frame = requestAnimationFrame(() => setSettled(true))\n    return () => cancelAnimationFrame(frame)\n  }, [])\n  return settled\n}\n\n/** Radix returns focus to a trigger, and a tour has none: it starts from anything, so it remembers for itself. */\nfunction useReturnFocus(primaryRef: React.RefObject<HTMLButtonElement | null>) {\n  const returnTo = useRef<HTMLElement | null>(null)\n  return {\n    onOpenAutoFocus: (event: Event) => {\n      returnTo.current = document.activeElement as HTMLElement | null\n      event.preventDefault()\n      primaryRef.current?.focus({ preventScroll: true })\n    },\n    onCloseAutoFocus: (event: Event) => {\n      event.preventDefault()\n      returnTo.current?.focus({ preventScroll: true })\n    },\n  }\n}\n\nfunction arrowKeys(goNext: () => void, goBack: () => void) {\n  return (event: React.KeyboardEvent) => {\n    if (event.key !== \"ArrowRight\" && event.key !== \"ArrowLeft\") return\n    event.preventDefault()\n    if (event.key === \"ArrowRight\") goNext()\n    else goBack()\n  }\n}\n\nfunction useCardMotion(\n  card: HTMLElement | null,\n  geometry: ReturnType<typeof useTour>[\"geometry\"],\n  placement: TourPlacement | undefined,\n  effect: TourEffect | undefined,\n) {\n  const reduceMotion = useReducedMotion() ?? false\n  const settled = useSettled()\n  const popover = useElementSize(card)\n  return {\n    spot: placePopover({ target: geometry.rect, popover, viewport: geometry.viewport, placement }),\n    transition: effect === \"spring\" && !reduceMotion && settled && geometry.moving ? SPRING_DEFAULT : INSTANT,\n  }\n}\n\ninterface SessionProps extends Required<Pick<TourProps, \"steps\" | \"variant\" | \"padding\">>, Pick<TourProps, \"effect\" | \"title\" | \"onStepChange\" | \"onFinish\" | \"className\"> {\n  initialStep: number\n  labels: TourLabels\n  onClose: () => void\n}\n\nfunction TourSession({ steps, variant, padding, effect, title, initialStep, labels, onStepChange, onFinish, className, onClose }: SessionProps) {\n  const { step, index, position, shown, geometry, isLast, hasPrevious, done, goNext, goBack, goTo } = useTour({ steps, initialStep, padding, onStepChange, onFinish, onClose })\n  const [card, setCard] = useState<HTMLDivElement | null>(null)\n  const primaryRef = useRef<HTMLButtonElement>(null)\n  const focus = useReturnFocus(primaryRef)\n  const { spot, transition } = useCardMotion(card, geometry, step?.placement, effect)\n  const anchored = variant === \"spotlight\" || variant === \"popover\"\n\n  // Stays on the main action, since Back disappears on the first step and would otherwise drop focus to the page.\n  useEffect(() => {\n    primaryRef.current?.focus({ preventScroll: true })\n  }, [index])\n\n  if (!step) return null\n  const footer = { position, total: shown.length, isLast, labels, primaryRef, onBack: goBack, onNext: goNext }\n  return (\n    <DialogPrimitive.Portal>\n      <TourHighlight rect={geometry.rect} dim={variant === \"spotlight\"} transition={transition} />\n      <DialogPrimitive.Content\n        asChild\n        // Without a body there is no description element, and the default id would point at nothing.\n        {...(step.body ? {} : { \"aria-describedby\": undefined })}\n        {...focus}\n        // A tour is left on purpose, with Close or Escape. A stray click on the page must not lose someone's place.\n        onInteractOutside={(event) => event.preventDefault()}\n        onKeyDown={arrowKeys(goNext, goBack)}\n      >\n        <motion.div\n          ref={setCard}\n          data-slot=\"tour\"\n          data-variant={variant}\n          data-effect={effect}\n          data-side={anchored ? spot.side ?? undefined : undefined}\n          initial={false}\n          animate={anchored ? { x: spot.x, y: spot.y } : undefined}\n          transition={transition}\n          className={cn(SURFACE_CLASS, LAYOUT_CLASS[variant], className)}\n        >\n          {variant === \"checklist\" ? (\n            <TourChecklist {...footer} title={title} steps={steps} shown={shown} index={index} done={done} onJump={goTo} />\n          ) : (\n            <>\n              <StepCopy step={step} closeLabel={labels.close} />\n              <StepFooter {...footer} hasPrevious={hasPrevious} />\n            </>\n          )}\n          <span role=\"status\" className=\"sr-only\">{`Step ${position} of ${shown.length}`}</span>\n        </motion.div>\n      </DialogPrimitive.Content>\n    </DialogPrimitive.Portal>\n  )\n}\n\nfunction Tour({ open: openProp, defaultOpen = false, onOpenChange, defaultStep = 0, variant = \"spotlight\", padding = 8, title = \"Getting started\", labels, ...rest }: TourProps) {\n  const [uncontrolled, setUncontrolled] = useState(defaultOpen)\n  const open = openProp ?? uncontrolled\n  const setOpen = (next: boolean) => {\n    setUncontrolled(next)\n    onOpenChange?.(next)\n  }\n  return (\n    // Only the spotlight is modal: the others explain the page while leaving it usable.\n    <DialogPrimitive.Root open={open} onOpenChange={setOpen} modal={variant === \"spotlight\"}>\n      {open ? <TourSession {...rest} {...{ variant, padding, title }} initialStep={defaultStep} labels={{ ...DEFAULT_LABELS, ...labels }} onClose={() => setOpen(false)} /> : null}\n    </DialogPrimitive.Root>\n  )\n}\n\nexport { Tour, type TourProps, type TourStep, type TourVariant, type TourEffect, type TourLabels, type TourPlacement }\n",
      "type": "registry:ui"
    },
    {
      "path": "registry/miseui/ui/tour-math.ts",
      "content": "interface TourRect {\n  x: number\n  y: number\n  width: number\n  height: number\n}\n\ninterface TourSize {\n  width: number\n  height: number\n}\n\ntype TourSide = \"top\" | \"bottom\" | \"left\" | \"right\"\ntype TourPlacement = TourSide | \"auto\"\n\ninterface PlaceOptions {\n  /** The target, or null for a step about the whole page. */\n  target: TourRect | null\n  popover: TourSize\n  viewport: TourSize\n  placement?: TourPlacement\n  gap?: number\n  margin?: number\n}\n\nconst AUTO_ORDER: readonly TourSide[] = [\"bottom\", \"top\", \"right\", \"left\"]\nconst DEFAULT_GAP = 12\nconst DEFAULT_MARGIN = 8\n\nfunction clamp(value: number, min: number, max: number) {\n  // A popover wider than the viewport pins to the leading edge, so its start stays readable.\n  return max < min ? min : Math.min(max, Math.max(min, value))\n}\n\nfunction roomOn(side: TourSide, target: TourRect, viewport: TourSize) {\n  const room: Record<TourSide, number> = {\n    top: target.y,\n    bottom: viewport.height - target.y - target.height,\n    left: target.x,\n    right: viewport.width - target.x - target.width,\n  }\n  return room[side]\n}\n\nfunction needed(side: TourSide, popover: TourSize, gap: number, margin: number) {\n  const main = side === \"top\" || side === \"bottom\" ? popover.height : popover.width\n  return main + gap + margin\n}\n\n/** The first side that fits, or the one that misses by least. A requested side is honoured only while it fits. */\nfunction chooseSide(target: TourRect, { popover, viewport, placement = \"auto\", gap = DEFAULT_GAP, margin = DEFAULT_MARGIN }: PlaceOptions) {\n  const order = placement === \"auto\" ? AUTO_ORDER : [placement, ...AUTO_ORDER.filter((side) => side !== placement)]\n  const spare = (side: TourSide) => roomOn(side, target, viewport) - needed(side, popover, gap, margin)\n  return order.find((side) => spare(side) >= 0) ?? order.reduce((best, side) => (spare(side) > spare(best) ? side : best))\n}\n\n/** Where the popover goes, in viewport pixels: beside the target, centred on it, and never off screen. */\nfunction placePopover(options: PlaceOptions) {\n  const { target, popover, viewport, gap = DEFAULT_GAP, margin = DEFAULT_MARGIN } = options\n  const maxX = viewport.width - popover.width - margin\n  const maxY = viewport.height - popover.height - margin\n  if (!target) {\n    return {\n      x: clamp((viewport.width - popover.width) / 2, margin, maxX),\n      y: clamp((viewport.height - popover.height) / 2, margin, maxY),\n      side: null,\n    }\n  }\n  const side = chooseSide(target, options)\n  const centredX = target.x + (target.width - popover.width) / 2\n  const centredY = target.y + (target.height - popover.height) / 2\n  const raw: Record<TourSide, { x: number; y: number }> = {\n    top: { x: centredX, y: target.y - popover.height - gap },\n    bottom: { x: centredX, y: target.y + target.height + gap },\n    left: { x: target.x - popover.width - gap, y: centredY },\n    right: { x: target.x + target.width + gap, y: centredY },\n  }\n  return { x: clamp(raw[side].x, margin, maxX), y: clamp(raw[side].y, margin, maxY), side }\n}\n\n/** Grows the target by the padding, so the highlight has air around what it points at. */\nfunction padRect(rect: TourRect, padding: number): TourRect {\n  return { x: rect.x - padding, y: rect.y - padding, width: rect.width + padding * 2, height: rect.height + padding * 2 }\n}\n\nfunction isInViewport(rect: TourRect, viewport: TourSize) {\n  return rect.x >= 0 && rect.y >= 0 && rect.x + rect.width <= viewport.width && rect.y + rect.height <= viewport.height\n}\n\n/** The next step in that direction that passes the test, starting at `from` itself, or -1 when there is none. */\nfunction findStep<T>(steps: readonly T[], from: number, direction: 1 | -1, available: (step: T) => boolean) {\n  for (let index = from; index >= 0 && index < steps.length; index += direction) {\n    if (available(steps[index])) return index\n  }\n  return -1\n}\n\nexport { findStep, isInViewport, padRect, placePopover, type TourPlacement, type TourRect, type TourSide, type TourSize }\n",
      "type": "registry:ui"
    },
    {
      "path": "registry/miseui/ui/tour-parts.tsx",
      "content": "import type * as React from \"react\"\nimport { Dialog as DialogPrimitive } from \"radix-ui\"\nimport { Check, X } from \"lucide-react\"\nimport { motion } from \"motion/react\"\nimport { Button } from \"@/registry/miseui/ui/button\"\nimport type { TourRect } from \"@/registry/miseui/ui/tour-math\"\nimport type { TourStep } from \"@/registry/miseui/ui/tour-state\"\nimport { cn } from \"@/registry/miseui/lib/utils\"\n\ntype MotionTransition = React.ComponentProps<typeof motion.div>[\"transition\"]\n\ninterface TourLabels {\n  next: string\n  back: string\n  finish: string\n  close: string\n}\n\nconst CUTOUT_RADIUS_PX = 8\n/** Big enough to cover any screen from a spot anywhere on it. Black in both themes: a dim is a dim. */\nconst DIM_SHADOW = \"0 0 0 1px rgb(255 255 255 / 0.2), 0 0 0 200vmax rgb(0 0 0 / 0.55)\"\nconst BUTTON_SIZE_CLASS = \"pointer-coarse:h-10\"\nconst CLOSE_CLASS = [\n  \"inline-flex size-8 shrink-0 items-center justify-center rounded-md text-muted-foreground outline-none pointer-coarse:size-10\",\n  \"transition-colors duration-(--duration-fast) ease-(--ease-mise) hover:bg-accent hover:text-foreground focus-visible:ring-[3px] focus-visible:ring-ring/50\",\n]\n\ninterface HighlightProps {\n  rect: TourRect | null\n  dim: boolean\n  transition: MotionTransition\n}\n\n/** One box does the whole job: its shadow is the dim, so the hole in it is simply the box itself. */\nfunction TourHighlight({ rect, dim, transition }: HighlightProps) {\n  if (!rect && !dim) return null\n  const box = rect ?? { x: window.innerWidth / 2, y: window.innerHeight / 2, width: 0, height: 0 }\n  return (\n    <motion.div\n      aria-hidden=\"true\"\n      data-slot=\"tour-highlight\"\n      data-dim={dim ? \"true\" : undefined}\n      data-rect={`${box.x},${box.y},${box.width},${box.height}`}\n      initial={false}\n      animate={{ x: box.x, y: box.y, width: box.width, height: box.height }}\n      transition={transition}\n      className={cn(\"pointer-events-none fixed top-0 left-0 z-50\", !dim && \"ring-2 ring-mise ring-offset-2 ring-offset-background\")}\n      style={{ borderRadius: CUTOUT_RADIUS_PX, boxShadow: dim ? DIM_SHADOW : undefined }}\n    />\n  )\n}\n\ninterface StepFooterProps {\n  position: number\n  total: number\n  hasPrevious: boolean\n  isLast: boolean\n  labels: TourLabels\n  primaryRef: React.Ref<HTMLButtonElement>\n  onBack: () => void\n  onNext: () => void\n}\n\nfunction StepFooter({ position, total, hasPrevious, isLast, labels, primaryRef, onBack, onNext }: StepFooterProps) {\n  return (\n    <div className=\"flex flex-wrap items-center gap-2\">\n      <span data-slot=\"tour-count\" className=\"mr-auto text-[13px] text-muted-foreground tabular-nums\">\n        {position} of {total}\n      </span>\n      {hasPrevious ? (\n        <Button variant=\"ghost\" size=\"sm\" className={BUTTON_SIZE_CLASS} onClick={onBack}>\n          {labels.back}\n        </Button>\n      ) : null}\n      <Button ref={primaryRef} variant=\"mise\" size=\"sm\" className={BUTTON_SIZE_CLASS} onClick={onNext}>\n        {isLast ? labels.finish : labels.next}\n      </Button>\n    </div>\n  )\n}\n\nfunction CloseButton({ label }: { label: string }) {\n  return (\n    <DialogPrimitive.Close aria-label={label} className={cn(CLOSE_CLASS)}>\n      <X aria-hidden=\"true\" className=\"size-4\" />\n    </DialogPrimitive.Close>\n  )\n}\n\ninterface StepCopyProps {\n  step: TourStep\n  closeLabel: string\n}\n\nfunction StepCopy({ step, closeLabel }: StepCopyProps) {\n  return (\n    <>\n      <div className=\"flex items-start justify-between gap-2\">\n        <DialogPrimitive.Title className=\"min-w-0 pt-1 text-[15px] leading-6 font-medium\">{step.title}</DialogPrimitive.Title>\n        <CloseButton label={closeLabel} />\n      </div>\n      {step.body ? <DialogPrimitive.Description className=\"text-sm leading-5 text-muted-foreground\">{step.body}</DialogPrimitive.Description> : null}\n    </>\n  )\n}\n\ninterface ChecklistProps extends Omit<StepFooterProps, \"hasPrevious\"> {\n  title: React.ReactNode\n  steps: readonly TourStep[]\n  shown: readonly number[]\n  index: number\n  done: ReadonlySet<number>\n  onJump: (index: number) => void\n}\n\nfunction ChecklistMark({ state }: { state: \"done\" | \"current\" | \"upcoming\" }) {\n  // Done is a result, so it takes the fixed hue: the accent may itself be any colour.\n  if (state === \"done\") return <Check aria-hidden=\"true\" className=\"size-4 shrink-0 text-emerald-600 dark:text-emerald-400\" />\n  return (\n    <span\n      aria-hidden=\"true\"\n      className={cn(\"mx-0.5 size-3 shrink-0 rounded-full border-2\", state === \"current\" ? \"border-foreground\" : \"border-border\")}\n    />\n  )\n}\n\nfunction TourChecklist({ title, steps, shown, index, done, position, total, isLast, labels, primaryRef, onJump, onBack, onNext }: ChecklistProps) {\n  const current = steps[index]\n  return (\n    <>\n      <div className=\"flex items-center justify-between gap-2\">\n        <DialogPrimitive.Title className=\"min-w-0 text-[15px] leading-6 font-medium\">{title}</DialogPrimitive.Title>\n        <CloseButton label={labels.close} />\n      </div>\n      <ol data-slot=\"tour-checklist\" className=\"grid gap-1\">\n        {shown.map((stepIndex) => {\n          const isCurrent = stepIndex === index\n          const state = isCurrent ? \"current\" : done.has(stepIndex) ? \"done\" : \"upcoming\"\n          return (\n            <li key={stepIndex}>\n              <button\n                type=\"button\"\n                aria-current={isCurrent ? \"step\" : undefined}\n                onClick={() => onJump(stepIndex)}\n                className={cn(\n                  \"flex min-h-8 w-full items-center gap-2 rounded-md px-2 text-left text-sm outline-none pointer-coarse:min-h-10\",\n                  \"transition-colors duration-(--duration-fast) ease-(--ease-mise) hover:bg-accent focus-visible:ring-[3px] focus-visible:ring-ring/50\",\n                  isCurrent ? \"font-medium\" : \"text-muted-foreground\",\n                )}\n              >\n                <ChecklistMark state={state} />\n                <span className=\"min-w-0\">{steps[stepIndex].title}</span>\n              </button>\n            </li>\n          )\n        })}\n      </ol>\n      {current?.body ? <DialogPrimitive.Description className=\"text-sm leading-5 text-muted-foreground\">{current.body}</DialogPrimitive.Description> : null}\n      <StepFooter {...{ position, total, isLast, labels, primaryRef, onBack, onNext }} hasPrevious={position > 1} />\n    </>\n  )\n}\n\nexport { StepCopy, StepFooter, TourChecklist, TourHighlight, type TourLabels }\n",
      "type": "registry:ui"
    },
    {
      "path": "registry/miseui/ui/tour-state.ts",
      "content": "import type * as React from \"react\"\nimport { useCallback, useEffect, useLayoutEffect, useRef, useState } from \"react\"\nimport { useReducedMotion } from \"motion/react\"\nimport { findStep, isInViewport, padRect, type TourPlacement, type TourRect, type TourSize } from \"@/registry/miseui/ui/tour-math\"\n\ntype TourTarget = string | React.RefObject<HTMLElement | null>\n\ninterface TourStep {\n  /** A CSS selector or a ref. Leave it out for a step about the whole page. */\n  target?: TourTarget\n  title: React.ReactNode\n  body?: React.ReactNode\n  placement?: TourPlacement\n}\n\ninterface UseTourOptions {\n  steps: readonly TourStep[]\n  initialStep: number\n  padding: number\n  onStepChange?: (index: number) => void\n  onFinish?: () => void\n  onClose: () => void\n}\n\n/**\n * Long enough for a smooth scroll to land. Geometry reported within it is part of moving to the step and may\n * spring; after it, the only way a target moves is the person scrolling, and the highlight must stick to it.\n */\nconst MOVE_WINDOW_MS = 700\nconst UNRESOLVED = -2\n\nfunction resolveTarget(target: TourTarget | undefined): HTMLElement | null {\n  if (!target) return null\n  if (typeof target !== \"string\") return target.current\n  try {\n    return document.querySelector<HTMLElement>(target)\n  } catch {\n    // A selector the browser refuses is the same as a target that is not there.\n    return null\n  }\n}\n\nfunction isAvailable(step: TourStep) {\n  return !step.target || resolveTarget(step.target) !== null\n}\n\nfunction viewportSize(): TourSize {\n  return { width: window.innerWidth, height: window.innerHeight }\n}\n\nfunction elementRect(element: HTMLElement): TourRect {\n  const { left, top, width, height } = element.getBoundingClientRect()\n  return { x: left, y: top, width, height }\n}\n\nfunction bringIntoView(element: HTMLElement | null, smooth: boolean) {\n  if (!element || isInViewport(elementRect(element), viewportSize())) return\n  element.scrollIntoView({ block: \"center\", inline: \"nearest\", behavior: smooth ? \"smooth\" : \"auto\" })\n}\n\n/** Keyed on the target, not the step: a steps array written inline is new on every render, and its strings are not. */\nfunction useTourPosition(target: TourTarget | undefined, index: number, padding: number) {\n  const reduceMotion = useReducedMotion() ?? false\n  const [geometry, setGeometry] = useState<{ rect: TourRect | null; viewport: TourSize; moving: boolean }>({\n    rect: null,\n    viewport: { width: 0, height: 0 },\n    moving: false,\n  })\n  const movingUntil = useRef(0)\n  const frame = useRef(0)\n\n  const measure = useCallback(() => {\n    const element = resolveTarget(target)\n    setGeometry({\n      rect: element ? padRect(elementRect(element), padding) : null,\n      viewport: viewportSize(),\n      moving: performance.now() < movingUntil.current,\n    })\n  }, [target, padding])\n\n  useLayoutEffect(() => {\n    movingUntil.current = performance.now() + MOVE_WINDOW_MS\n    bringIntoView(resolveTarget(target), !reduceMotion)\n    measure()\n  }, [index, target, reduceMotion, measure])\n\n  useEffect(() => {\n    const schedule = () => {\n      cancelAnimationFrame(frame.current)\n      frame.current = requestAnimationFrame(measure)\n    }\n    const element = resolveTarget(target)\n    const observer = typeof ResizeObserver === \"undefined\" ? null : new ResizeObserver(schedule)\n    if (element) observer?.observe(element)\n    window.addEventListener(\"resize\", schedule)\n    // Capture, because scroll does not bubble and the target may sit in any scroller.\n    window.addEventListener(\"scroll\", schedule, true)\n    return () => {\n      cancelAnimationFrame(frame.current)\n      observer?.disconnect()\n      window.removeEventListener(\"resize\", schedule)\n      window.removeEventListener(\"scroll\", schedule, true)\n    }\n  }, [target, measure])\n\n  return geometry\n}\n\n/**\n * Finds the first step once, after mount: a tour open from the start commits together with its targets,\n * so they cannot be found during render. A page with none of them ends the tour instead of opening it empty.\n */\nfunction useFirstStep(options: Pick<UseTourOptions, \"steps\" | \"initialStep\" | \"onClose\">) {\n  const [index, setIndex] = useState(UNRESOLVED)\n  const [available, setAvailable] = useState<readonly boolean[]>([])\n  const first = useRef(options)\n  const resolve = useCallback(() => {\n    const { steps, initialStep, onClose } = first.current\n    const start = findStep(steps, initialStep, 1, isAvailable)\n    setAvailable(steps.map(isAvailable))\n    setIndex(start)\n    if (start === -1) onClose()\n  }, [])\n  useLayoutEffect(resolve, [resolve])\n  return { index, setIndex, available, setAvailable }\n}\n\nfunction useTour({ steps, initialStep, padding, onStepChange, onFinish, onClose }: UseTourOptions) {\n  const { index, setIndex, available, setAvailable } = useFirstStep({ steps, initialStep, onClose })\n  const [done, setDone] = useState<ReadonlySet<number>>(() => new Set())\n  const step = steps[index]\n  const geometry = useTourPosition(step?.target, index, padding)\n  const shown = steps.flatMap((_, position) => (available[position] ? [position] : []))\n\n  const goTo = (next: number) => {\n    // Checked again on every move: the steps before this one may have changed what is on the page.\n    setAvailable(steps.map(isAvailable))\n    setIndex(next)\n    onStepChange?.(next)\n  }\n\n  const goNext = () => {\n    const next = findStep(steps, index + 1, 1, isAvailable)\n    setDone((current) => new Set([...current, index]))\n    if (next !== -1) {\n      goTo(next)\n      return\n    }\n    onFinish?.()\n    onClose()\n  }\n\n  const goBack = () => {\n    const previous = findStep(steps, index - 1, -1, isAvailable)\n    if (previous !== -1) goTo(previous)\n  }\n\n  const position = shown.indexOf(index) + 1\n  const isLast = shown[shown.length - 1] === index\n  return { index, step, done, shown, position, isLast, hasPrevious: position > 1, geometry, goTo, goNext, goBack }\n}\n\nexport { useTour, type TourStep, type TourTarget }\n",
      "type": "registry:ui"
    }
  ],
  "categories": [
    "overlays"
  ],
  "type": "registry:ui"
}