{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "dialog",
  "type": "registry:ui",
  "title": "Dialog",
  "description": "A modal that tips into view from its edge while the page blurs behind it.",
  "dependencies": [
    "motion",
    "lucide-react"
  ],
  "files": [
    {
      "path": "components/prequelui/motion.tsx",
      "type": "registry:lib",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport {\n  MotionConfig,\n  useInView as useMotionInView,\n  type Transition,\n} from \"motion/react\";\nimport { useHydratedReducedMotion } from \"@/lib/use-reduced-motion\";\nimport { cn } from \"@/lib/utils\";\n\nconst TempoContext = React.createContext(1);\n\nexport function PrequelMotionProvider({\n  tempo = 1,\n  children,\n}: {\n  tempo?: number;\n  children: React.ReactNode;\n}) {\n  const value = React.useMemo(() => Math.max(0.4, tempo), [tempo]);\n  return (\n    <TempoContext.Provider value={value}>\n      <MotionConfig reducedMotion=\"user\">{children}</MotionConfig>\n    </TempoContext.Provider>\n  );\n}\n\nexport function useTempo() {\n  return React.useContext(TempoContext);\n}\n\nconst TIME_KEYS = [\n  \"duration\",\n  \"visualDuration\",\n  \"delay\",\n  \"repeatDelay\",\n  \"delayChildren\",\n] as const;\n\nfunction scaleValue(transition: Transition, tempo: number): Transition {\n  if (tempo === 1 || !transition || typeof transition !== \"object\") {\n    return transition;\n  }\n  const next: Record<string, unknown> = {};\n  for (const [key, value] of Object.entries(transition)) {\n    if (typeof value === \"number\" && (TIME_KEYS as readonly string[]).includes(key)) {\n      next[key] = value * tempo;\n    } else if (typeof value === \"number\" && key === \"stiffness\") {\n      next[key] = value / (tempo * tempo);\n    } else if (typeof value === \"number\" && key === \"damping\") {\n      next[key] = value / tempo;\n    } else if (value && typeof value === \"object\" && !Array.isArray(value)) {\n      next[key] = scaleValue(value as Transition, tempo);\n    } else {\n      next[key] = value;\n    }\n  }\n  return next as Transition;\n}\n\nexport function useTempoTransition(transition: Transition) {\n  const tempo = useTempo();\n  return React.useMemo(\n    () => scaleValue(transition, tempo),\n    [tempo, JSON.stringify(transition)],\n  );\n}\n\nexport function useReduceMotion() {\n  return useHydratedReducedMotion();\n}\n\nexport function usePageVisible() {\n  const [visible, setVisible] = React.useState(true);\n  React.useEffect(() => {\n    const update = () => setVisible(!document.hidden);\n    update();\n    document.addEventListener(\"visibilitychange\", update);\n    return () => document.removeEventListener(\"visibilitychange\", update);\n  }, []);\n  return visible;\n}\n\nexport function useMounted() {\n  return React.useSyncExternalStore(\n    () => () => {},\n    () => true,\n    () => false,\n  );\n}\n\nexport function useSeen(\n  ref: React.RefObject<Element | null>,\n  enabled = true,\n  once = true,\n) {\n  const inView = useMotionInView(ref, { once, amount: 0.35 });\n  return enabled ? inView : true;\n}\n\ntype SlotProps = React.HTMLAttributes<HTMLElement> & {\n  children?: React.ReactNode;\n  ref?: React.Ref<HTMLElement>;\n};\n\nexport function Slot({ children, ...props }: SlotProps) {\n  if (!React.isValidElement<Record<string, unknown>>(children)) {\n    return null;\n  }\n  const child = children as React.ReactElement<Record<string, unknown>>;\n  const childProps = child.props;\n  return React.cloneElement(child, {\n    ...props,\n    ...childProps,\n    className: cn(\n      String(props.className ?? \"\"),\n      String(childProps.className ?? \"\"),\n    ),\n    style: {\n      ...((props.style as React.CSSProperties) ?? {}),\n      ...((childProps.style as React.CSSProperties) ?? {}),\n    },\n  } as Record<string, unknown>);\n}\n\nexport function srOnlyStyle(): React.CSSProperties {\n  return {\n    position: \"absolute\",\n    width: 1,\n    height: 1,\n    padding: 0,\n    margin: -1,\n    overflow: \"hidden\",\n    clip: \"rect(0, 0, 0, 0)\",\n    whiteSpace: \"nowrap\",\n    borderWidth: 0,\n  };\n}\n\nlet segmenter: Intl.Segmenter | null | undefined;\n\nexport function splitGraphemes(text: string): string[] {\n  if (segmenter === undefined) {\n    segmenter =\n      typeof Intl !== \"undefined\" && typeof Intl.Segmenter === \"function\"\n        ? new Intl.Segmenter(undefined, { granularity: \"grapheme\" })\n        : null;\n  }\n  if (!segmenter) return Array.from(text);\n  return Array.from(segmenter.segment(text), (entry) => entry.segment);\n}\n\nexport const easeOut = [0.23, 1, 0.32, 1] as const;\nexport const easeSoft = [0.215, 0.61, 0.355, 1] as const;\nexport const easeInOut = [0.77, 0, 0.175, 1] as const;\nexport const easeEnter = [0.25, 0.1, 0.35, 1] as const;\nexport const easeLeave = [0, 0, 0.58, 1] as const;\nexport const easeResize = [0.4, 0, 0.1, 1] as const;\nexport const easeAway = [0.33, 0.17, 0.67, 0.5] as const;\n\nexport const pressSpring: Transition = {\n  type: \"spring\",\n  stiffness: 550,\n  damping: 30,\n  restSpeed: 10,\n};\n\nexport const selectionSpring: Transition = {\n  type: \"spring\",\n  stiffness: 300,\n  damping: 30,\n};\n\nexport const highlightSpring: Transition = {\n  type: \"spring\",\n  stiffness: 500,\n  damping: 40,\n};\n\nexport const popSpring: Transition = {\n  type: \"spring\",\n  stiffness: 400,\n  damping: 29,\n};\n\nexport const tooltipSpring: Transition = {\n  type: \"spring\",\n  stiffness: 400,\n  damping: 31,\n};\n\nexport const dialogSpring: Transition = {\n  type: \"spring\",\n  stiffness: 150,\n  damping: 25,\n};\n\nexport const toastSpring: Transition = {\n  type: \"spring\",\n  stiffness: 280,\n  damping: 24,\n};\n\nexport const heightSpring: Transition = {\n  type: \"spring\",\n  stiffness: 300,\n  damping: 30,\n  bounce: 0,\n  restDelta: 0.01,\n};\n\nexport const progressSpring: Transition = {\n  type: \"spring\",\n  stiffness: 300,\n  damping: 35,\n  restDelta: 0.01,\n  restSpeed: 0.1,\n};\n\nexport const scrollSpring: Transition = {\n  type: \"spring\",\n  stiffness: 250,\n  damping: 40,\n  bounce: 0,\n};\n\nexport const avatarSpring: Transition = {\n  type: \"spring\",\n  stiffness: 300,\n  damping: 17,\n};\n\nexport const pinnedSpring: Transition = {\n  type: \"spring\",\n  stiffness: 320,\n  damping: 25,\n  mass: 0.8,\n};\n\nexport const thumbSpring: Transition = {\n  type: \"spring\",\n  stiffness: 300,\n  damping: 25,\n};\n\nexport const checkSpring: Transition = {\n  type: \"spring\",\n  stiffness: 500,\n  damping: 24,\n};\n\nexport const cursorEntry: Transition = {\n  type: \"spring\",\n  stiffness: 550,\n  damping: 30,\n  restSpeed: 10,\n};\n\nexport const cursorExit: Transition = {\n  type: \"spring\",\n  stiffness: 550,\n  damping: 46.9,\n  restSpeed: 10,\n};\n\nexport const cursorLabel: Transition = {\n  type: \"spring\",\n  stiffness: 500,\n  damping: 50,\n  bounce: 0,\n};\n\nexport const swapTween: Transition = {\n  duration: 0.15,\n  ease: easeOut,\n};\n\nexport const overlayTween: Transition = {\n  duration: 0.4,\n  ease: easeSoft,\n};\n\nexport const disclosureTween: Transition = {\n  duration: 0.35,\n  ease: easeSoft,\n};\n\nexport const menuTween: Transition = {\n  duration: 0.22,\n  ease: easeSoft,\n};\n\nexport const panelOutTween: Transition = {\n  duration: 0.15,\n  ease: easeLeave,\n};\n\nexport const panelInTween: Transition = {\n  duration: 0.3,\n  ease: easeEnter,\n};\n\nexport const panelHeightTween: Transition = {\n  duration: 0.45,\n  ease: easeResize,\n};\n\nexport const exitTween: Transition = {\n  duration: 0.2,\n  ease: easeAway,\n};\n\nexport const faceSpring: Transition = {\n  type: \"spring\",\n  stiffness: 280,\n  damping: 20,\n};\n\nexport const blurIcon = \"blur(2px)\";\n\nexport function flipTransform(side: \"top\" | \"bottom\" | \"left\" | \"right\") {\n  const rotate =\n    side === \"top\"\n      ? \"rotateX(-20deg)\"\n      : side === \"bottom\"\n        ? \"rotateX(20deg)\"\n        : side === \"left\"\n          ? \"rotateY(20deg)\"\n          : \"rotateY(-20deg)\";\n  return `perspective(500px) ${rotate} scale(0.8)`;\n}\n\nexport function uprightTransform(side: \"top\" | \"bottom\" | \"left\" | \"right\") {\n  const rotate = side === \"left\" || side === \"right\" ? \"rotateY(0deg)\" : \"rotateX(0deg)\";\n  return `perspective(500px) ${rotate} scale(1)`;\n}\n",
      "target": "components/prequelui/motion.tsx"
    },
    {
      "path": "components/prequelui/dialog.tsx",
      "type": "registry:ui",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport { createPortal } from \"react-dom\";\nimport { AnimatePresence, motion, type Transition } from \"motion/react\";\nimport { X } from \"lucide-react\";\nimport { cn } from \"@/lib/utils\";\nimport {\n  Slot,\n  dialogSpring,\n  exitTween,\n  flipTransform,\n  overlayTween,\n  uprightTransform,\n  useMounted,\n  useReduceMotion,\n  useTempoTransition,\n} from \"./motion\";\n\ntype Side = \"top\" | \"bottom\" | \"left\" | \"right\";\n\ntype DialogContextValue = {\n  open: boolean;\n  setOpen: (open: boolean) => void;\n  side: Side;\n};\n\nconst DialogContext = React.createContext<DialogContextValue | null>(null);\n\nfunction useDialog(component: string) {\n  const context = React.useContext(DialogContext);\n  if (!context) throw new Error(`${component} must be used inside <Dialog>.`);\n  return context;\n}\n\nexport type DialogProps = {\n  open?: boolean;\n  defaultOpen?: boolean;\n  onOpenChange?: (open: boolean) => void;\n  modal?: boolean;\n  side?: Side;\n  children?: React.ReactNode;\n};\n\nexport function Dialog({\n  open: openProp,\n  defaultOpen = false,\n  onOpenChange,\n  modal = true,\n  side = \"top\",\n  children,\n}: DialogProps) {\n  const [internal, setInternal] = React.useState(defaultOpen);\n  const controlled = openProp !== undefined;\n  const open = controlled ? openProp : internal;\n  const setOpen = React.useCallback(\n    (next: boolean) => {\n      if (!controlled) setInternal(next);\n      onOpenChange?.(next);\n    },\n    [controlled, onOpenChange],\n  );\n  return (\n    <DialogContext.Provider value={{ open, setOpen, side }}>\n      <div data-slot=\"dialog\" data-modal={modal ? \"\" : undefined}>\n        {children}\n      </div>\n    </DialogContext.Provider>\n  );\n}\n\nexport type DialogTriggerProps = React.ButtonHTMLAttributes<HTMLButtonElement> & {\n  asChild?: boolean;\n};\n\nexport function DialogTrigger({ asChild = false, children, onClick, ...props }: DialogTriggerProps) {\n  const dialog = useDialog(\"DialogTrigger\");\n  const handle = (event: React.MouseEvent<HTMLButtonElement>) => {\n    onClick?.(event);\n    if (!event.defaultPrevented) dialog.setOpen(true);\n  };\n  if (asChild) {\n    return (\n      <Slot onClick={handle} aria-haspopup=\"dialog\" aria-expanded={dialog.open}>\n        {children}\n      </Slot>\n    );\n  }\n  return (\n    <button\n      type=\"button\"\n      data-slot=\"dialog-trigger\"\n      aria-haspopup=\"dialog\"\n      aria-expanded={dialog.open}\n      onClick={handle}\n      {...props}\n    >\n      {children}\n    </button>\n  );\n}\n\nexport type DialogContentProps = React.HTMLAttributes<HTMLDivElement> & {\n  side?: Side;\n  showClose?: boolean;\n  hideOverlay?: boolean;\n  transition?: Transition;\n  exitTransition?: Transition;\n  onEscapeKeyDown?: (event: KeyboardEvent) => void;\n};\n\nexport function DialogContent({\n  side,\n  showClose = true,\n  hideOverlay = false,\n  transition,\n  exitTransition,\n  onEscapeKeyDown,\n  className,\n  children,\n  ...props\n}: DialogContentProps) {\n  const dialog = useDialog(\"DialogContent\");\n  const { open, setOpen } = dialog;\n  const reduce = useReduceMotion();\n  const mounted = useMounted();\n  const ref = React.useRef<HTMLDivElement>(null);\n  const edge = side ?? dialog.side;\n  const enter = useTempoTransition(transition ?? dialogSpring);\n  const leave = useTempoTransition(exitTransition ?? exitTween);\n\n  React.useEffect(() => {\n    if (!open || !mounted) return;\n    const previous = document.activeElement as HTMLElement | null;\n    const previousOverflow = document.body.style.overflow;\n    document.body.style.overflow = \"hidden\";\n    const focusTimer = window.setTimeout(() => ref.current?.focus(), 20);\n\n    const onKey = (event: KeyboardEvent) => {\n      if (event.key === \"Escape\") {\n        onEscapeKeyDown?.(event);\n        if (!event.defaultPrevented) setOpen(false);\n      }\n    };\n    document.addEventListener(\"keydown\", onKey);\n    return () => {\n      window.clearTimeout(focusTimer);\n      document.removeEventListener(\"keydown\", onKey);\n      document.body.style.overflow = previousOverflow;\n      previous?.focus?.();\n    };\n  }, [open, setOpen, mounted, onEscapeKeyDown]);\n\n  if (!mounted) return null;\n\n  const transform = flipTransform(edge);\n\n  return createPortal(\n    <AnimatePresence>\n      {dialog.open && (\n        <div className=\"fixed inset-0 z-[90] flex items-center justify-center p-4\">\n          {hideOverlay ? null : (\n            <motion.button\n              type=\"button\"\n              aria-label=\"Close dialog\"\n              initial={{ backgroundColor: \"rgba(0,0,0,0)\", backdropFilter: \"blur(0px)\" }}\n              animate={{ backgroundColor: \"rgba(0,0,0,0.14)\", backdropFilter: \"blur(4px)\" }}\n              exit={{ backgroundColor: \"rgba(0,0,0,0)\", backdropFilter: \"blur(0px)\" }}\n              transition={overlayTween}\n              onClick={() => dialog.setOpen(false)}\n              className=\"absolute inset-0\"\n            />\n          )}\n          <motion.div\n            ref={ref}\n            role=\"dialog\"\n            aria-modal=\"true\"\n            tabIndex={-1}\n            data-slot=\"dialog-content\"\n            initial={\n              reduce\n                ? { opacity: 0 }\n                : { opacity: 0, filter: \"blur(4px)\", transform }\n            }\n            animate={\n              reduce\n                ? { opacity: 1 }\n                : { opacity: 1, filter: \"blur(0px)\", transform: uprightTransform(edge) }\n            }\n            exit={\n              reduce\n                ? { opacity: 0, transition: leave }\n                : { opacity: 0, filter: \"blur(4px)\", transition: leave }\n            }\n            transition={reduce ? { duration: 0.2 } : enter}\n            className={cn(\n              \"relative z-10 w-full max-w-[400px] rounded-xl border bg-popover p-5 text-popover-foreground shadow-2xl outline-none\",\n              className,\n            )}\n            {...(props as Record<string, unknown>)}\n          >\n            {showClose ? (\n              <button\n                type=\"button\"\n                aria-label=\"Close dialog\"\n                onClick={() => dialog.setOpen(false)}\n                className=\"absolute right-3 top-3 flex size-7 items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-accent hover:text-foreground\"\n              >\n                <X className=\"size-3.5\" />\n              </button>\n            ) : null}\n            {children}\n          </motion.div>\n        </div>\n      )}\n    </AnimatePresence>,\n    document.body,\n  );\n}\n\nexport function DialogClose({\n  asChild = false,\n  children,\n  onClick,\n  ...props\n}: React.ButtonHTMLAttributes<HTMLButtonElement> & { asChild?: boolean }) {\n  const dialog = useDialog(\"DialogClose\");\n  const handle = (event: React.MouseEvent<HTMLButtonElement>) => {\n    onClick?.(event);\n    if (!event.defaultPrevented) dialog.setOpen(false);\n  };\n  if (asChild) {\n    return <Slot onClick={handle}>{children}</Slot>;\n  }\n  return (\n    <button type=\"button\" onClick={handle} {...props}>\n      {children}\n    </button>\n  );\n}\n\nexport function DialogTitle({ className, ...props }: React.HTMLAttributes<HTMLHeadingElement>) {\n  return <h2 className={cn(\"pr-6 text-[15px] font-medium\", className)} {...props} />;\n}\n\nexport function DialogDescription({ className, ...props }: React.HTMLAttributes<HTMLParagraphElement>) {\n  return (\n    <p\n      className={cn(\"mt-2 text-[13px] leading-6 text-muted-foreground\", className)}\n      {...props}\n    />\n  );\n}\n\nexport function DialogFooter({ className, ...props }: React.HTMLAttributes<HTMLDivElement>) {\n  return <div className={cn(\"mt-5 flex justify-end gap-2\", className)} {...props} />;\n}\n",
      "target": "components/prequelui/dialog.tsx"
    },
    {
      "path": "lib/use-reduced-motion.ts",
      "target": "lib/use-reduced-motion.ts",
      "type": "registry:lib",
      "content": "\"use client\";\n\nimport { useReducedMotion } from \"motion/react\";\nimport { useSyncExternalStore } from \"react\";\n\nconst subscribe = () => () => {};\n\nexport function useHydratedReducedMotion() {\n  const reduce = useReducedMotion() ?? false;\n  const mounted = useSyncExternalStore(\n    subscribe,\n    () => true,\n    () => false,\n  );\n  return mounted ? reduce : false;\n}\n"
    }
  ]
}
