{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "file-drop",
  "type": "registry:ui",
  "title": "File Drop",
  "description": "A drop zone that breathes on drag, fills a spring bar and draws its own check.",
  "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/file-drop.tsx",
      "type": "registry:ui",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport { motion } from \"motion/react\";\nimport { cn } from \"@/lib/utils\";\nimport { useReduceMotion } from \"./motion\";\n\nexport type FileDropStatus = \"idle\" | \"uploading\" | \"done\" | \"error\";\n\nexport type FileDropProps = Omit<\n  React.ComponentProps<\"div\">,\n  \"onDrop\" | \"onChange\"\n> & {\n  onFiles?: (files: File[]) => void;\n  onError?: (message: string) => void;\n  accept?: string;\n  multiple?: boolean;\n  maxSize?: number;\n  disabled?: boolean;\n  progress?: number;\n  status?: FileDropStatus;\n  fileName?: string;\n  title?: string;\n  hint?: string;\n  icon?: React.ReactNode;\n};\n\nfunction formatSize(bytes: number) {\n  if (bytes < 1024) return `${bytes} B`;\n  if (bytes < 1024 * 1024) return `${Math.round(bytes / 102.4) / 10} KB`;\n  return `${Math.round(bytes / 104857.6) / 10} MB`;\n}\n\nfunction UploadIcon() {\n  return (\n    <svg viewBox=\"0 0 24 24\" fill=\"none\" aria-hidden=\"true\" className=\"size-5\">\n      <path\n        d=\"M12 16V5m0 0L8 9m4-4 4 4\"\n        stroke=\"currentColor\"\n        strokeWidth=\"1.7\"\n        strokeLinecap=\"round\"\n        strokeLinejoin=\"round\"\n      />\n      <path\n        d=\"M4.5 15.5v2A2.5 2.5 0 0 0 7 20h10a2.5 2.5 0 0 0 2.5-2.5v-2\"\n        stroke=\"currentColor\"\n        strokeWidth=\"1.7\"\n        strokeLinecap=\"round\"\n      />\n    </svg>\n  );\n}\n\nfunction FileIcon() {\n  return (\n    <svg viewBox=\"0 0 20 20\" fill=\"none\" aria-hidden=\"true\" className=\"size-4 shrink-0\">\n      <path\n        d=\"M6 2.8h5.2L15 6.6v10.6H6z\"\n        stroke=\"currentColor\"\n        strokeWidth=\"1.4\"\n        strokeLinejoin=\"round\"\n      />\n      <path d=\"M11 2.8v4h4\" stroke=\"currentColor\" strokeWidth=\"1.4\" strokeLinejoin=\"round\" />\n    </svg>\n  );\n}\n\nfunction CheckIcon() {\n  return (\n    <svg viewBox=\"0 0 20 20\" fill=\"none\" aria-hidden=\"true\" className=\"size-4\">\n      <motion.path\n        d=\"M4.5 10.4 8 14l7.5-8\"\n        stroke=\"currentColor\"\n        strokeWidth=\"1.8\"\n        strokeLinecap=\"round\"\n        strokeLinejoin=\"round\"\n        initial={{ pathLength: 0 }}\n        animate={{ pathLength: 1 }}\n        transition={{ duration: 0.32, ease: [0.23, 1, 0.32, 1] }}\n      />\n    </svg>\n  );\n}\n\nexport function FileDrop({\n  onFiles,\n  onError,\n  accept,\n  multiple = false,\n  maxSize,\n  disabled = false,\n  progress,\n  status,\n  fileName,\n  title = \"Drop a file or browse\",\n  hint = \"SVG, PNG or JPG\",\n  icon,\n  className,\n  children,\n  onClick,\n  ...props\n}: FileDropProps) {\n  const reduce = useReduceMotion();\n  const inputRef = React.useRef<HTMLInputElement>(null);\n  const [dragging, setDragging] = React.useState(false);\n  const [selected, setSelected] = React.useState<File[]>([]);\n  const [error, setError] = React.useState<string | null>(null);\n  const resolvedStatus: FileDropStatus = status ?? (error ? \"error\" : \"idle\");\n  const shownName = fileName ?? selected[0]?.name;\n  const shownSize = selected[0] ? formatSize(selected[0].size) : null;\n  const safeProgress =\n    typeof progress === \"number\" ? Math.min(100, Math.max(0, progress)) : null;\n\n  const acceptFiles = React.useCallback(\n    (list: FileList | null) => {\n      if (!list || disabled) return;\n      const files = Array.from(list);\n      if (!files.length) return;\n      if (!multiple && files.length > 1) files.splice(1);\n      if (maxSize !== undefined) {\n        const oversized = files.find((file) => file.size > maxSize);\n        if (oversized) {\n          const message = `${oversized.name} is larger than ${formatSize(maxSize)}.`;\n          setError(message);\n          onError?.(message);\n          return;\n        }\n      }\n      setError(null);\n      setSelected(files);\n      onFiles?.(files);\n    },\n    [disabled, maxSize, multiple, onError, onFiles],\n  );\n\n  const open = () => {\n    if (disabled) return;\n    inputRef.current?.click();\n  };\n\n  const stateBorder =\n    resolvedStatus === \"error\"\n      ? \"border-destructive/60 bg-destructive/5\"\n      : dragging\n        ? \"border-primary/70 bg-accent/60\"\n        : resolvedStatus === \"done\"\n          ? \"border-emerald-500/40 bg-emerald-500/5\"\n          : \"border-border bg-muted/20 hover:border-border/80 hover:bg-accent/40\";\n\n  return (\n    <div\n      data-slot=\"file-drop\"\n      role=\"button\"\n      tabIndex={disabled ? -1 : 0}\n      aria-disabled={disabled || undefined}\n      aria-label={title}\n      onClick={(event) => {\n        onClick?.(event);\n        open();\n      }}\n      onKeyDown={(event) => {\n        if (disabled) return;\n        if (event.key === \"Enter\" || event.key === \" \") {\n          event.preventDefault();\n          open();\n        }\n      }}\n      onDragEnter={(event) => {\n        event.preventDefault();\n        if (!disabled) setDragging(true);\n      }}\n      onDragOver={(event) => {\n        event.preventDefault();\n        if (!disabled) setDragging(true);\n      }}\n      onDragLeave={(event) => {\n        if (event.currentTarget.contains(event.relatedTarget as Node)) return;\n        setDragging(false);\n      }}\n      onDrop={(event) => {\n        event.preventDefault();\n        setDragging(false);\n        acceptFiles(event.dataTransfer.files);\n      }}\n      className={cn(\n        \"group relative flex w-full max-w-[360px] cursor-pointer flex-col items-center justify-center gap-3 rounded-xl border border-dashed px-6 py-7 text-center transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/50\",\n        stateBorder,\n        disabled && \"pointer-events-none opacity-50\",\n        className,\n      )}\n      {...props}\n    >\n      <input\n        ref={inputRef}\n        type=\"file\"\n        accept={accept}\n        multiple={multiple}\n        disabled={disabled}\n        className=\"sr-only\"\n        onChange={(event) => {\n          acceptFiles(event.target.files);\n          event.target.value = \"\";\n        }}\n      />\n      {children ?? (\n        <>\n          <motion.span\n            className=\"flex size-10 items-center justify-center rounded-lg border bg-background text-muted-foreground shadow-sm\"\n            initial={false}\n            animate={\n              dragging && !reduce\n                ? { y: -3, scale: 1.04 }\n                : { y: 0, scale: 1 }\n            }\n            transition={{ type: \"spring\", stiffness: 380, damping: 24 }}\n          >\n            {icon ?? <UploadIcon />}\n          </motion.span>\n          <span className=\"flex flex-col gap-1\">\n            <span className=\"text-[13px] font-medium text-foreground\">{title}</span>\n            <span className=\"text-[13px] leading-4 text-muted-foreground\">{hint}</span>\n          </span>\n\n          {shownName ? (\n            <span className=\"flex w-full flex-col gap-2 rounded-lg border bg-background px-2.5 py-2 text-left\">\n              <span className=\"flex items-center gap-2 text-[13px] text-foreground\">\n                <FileIcon />\n                <span className=\"min-w-0 flex-1 truncate\">{shownName}</span>\n                {shownSize ? (\n                  <span className=\"shrink-0 tabular-nums text-muted-foreground\">\n                    {shownSize}\n                  </span>\n                ) : null}\n                {resolvedStatus === \"done\" ? (\n                  <span className=\"flex size-5 shrink-0 items-center justify-center rounded-full bg-emerald-500/15 text-emerald-600 dark:text-emerald-400\">\n                    <CheckIcon />\n                  </span>\n                ) : null}\n              </span>\n              {safeProgress !== null ? (\n                <span className=\"block h-1 overflow-hidden rounded-full bg-border\">\n                  <motion.span\n                    className=\"block h-full rounded-full bg-primary\"\n                    initial={false}\n                    animate={{ width: `${safeProgress}%` }}\n                    transition={\n                      reduce\n                        ? { duration: 0 }\n                        : { type: \"spring\", stiffness: 220, damping: 26 }\n                    }\n                  />\n                </span>\n              ) : null}\n            </span>\n          ) : null}\n\n          {error ? (\n            <span className=\"text-[13px] leading-4 text-destructive\">{error}</span>\n          ) : null}\n        </>\n      )}\n    </div>\n  );\n}\n",
      "target": "components/prequelui/file-drop.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"
    }
  ]
}
