{"slug":"project-folder","name":"Project Folder","description":"An interactive project folder that opens its file fan on hover or focus, expands into a focus-managed overlay, then retraces the complete path when closed.","category":"blocks","source_url":"https://beui.dev/r/project-folder/raw","detail_url":"https://beui.dev/r/project-folder","raw_url":"https://beui.dev/r/project-folder/raw","page_url":"https://beui.dev/components/blocks/project-folder","markdown_url":"https://beui.dev/components/blocks/project-folder.md","published_at":"2026-08-15","updated_at":"2026-11-24","dependencies":["clsx","lucide-react","motion","react","react-dom","tailwind-merge"],"internal":["@/components/motion/project-folder","@/lib/ease","@/lib/focusable","@/lib/hooks/use-focus-trap","@/lib/hooks/use-hover-capable","@/lib/i18n","@/lib/layers","@/lib/scroll-lock","@/lib/utils"],"install_slugs":["project-folder"],"requires_theme":false,"props":[{"displayName":"ProjectFolder","props":[{"name":"title","type":"string","required":true,"defaultValue":null,"description":"Folder name shown on the front and in the overlay header."},{"name":"description","type":"string","required":false,"defaultValue":null,"description":"Secondary text beside the count. Default: \"Updated recently\""},{"name":"previews","type":"ProjectFolderPreview[]","required":false,"defaultValue":"[]","description":"Cards that fan out of the folder and fill the overlay. Only the first 5 show."},{"name":"count","type":"number","required":false,"defaultValue":"previews.length","description":"Number shown in the count text. Default: the number of previews"},{"name":"itemLabel","type":"string","required":false,"defaultValue":null,"description":"Singular noun for the count, e.g. `\"file\"`. Pluralized the English way by\nappending `s` (`3 files`), so only pass it for English copy. Leave it\nunset to use the localizable `countOne`/`countOther` messages."},{"name":"open","type":"boolean","required":false,"defaultValue":null,"description":"Whether the lid tilts and previews fan out, for controlled use."},{"name":"defaultOpen","type":"boolean","required":false,"defaultValue":"false","description":"Whether the folder starts open when uncontrolled. Default: false"},{"name":"onOpenChange","type":"((open: boolean) => void)","required":false,"defaultValue":null,"description":"Called with the new open state on hover, focus, click or close."},{"name":"expanded","type":"boolean","required":false,"defaultValue":null,"description":"Whether the full-screen previews overlay is shown, for controlled use."},{"name":"defaultExpanded","type":"boolean","required":false,"defaultValue":"false","description":"Whether the overlay starts shown when uncontrolled. Default: false"},{"name":"onExpandedChange","type":"((expanded: boolean) => void)","required":false,"defaultValue":null,"description":"Called with the new state when the overlay opens or closes."},{"name":"onClick","type":"(() => void)","required":false,"defaultValue":null,"description":"Called when the folder is clicked, after it starts opening."},{"name":"disabled","type":"boolean","required":false,"defaultValue":"false","description":"Blocks hover, click and the overlay, and dims the folder. Default: false"},{"name":"ariaLabel","type":"string","required":false,"defaultValue":null,"description":"Accessible name for the folder button."},{"name":"labels","type":"Partial<{ description: string; countOne: string; countOther: string; closeOverlay: string; close: string; }>","required":false,"defaultValue":null,"description":"Override any built-in string. `{count}` fills `countOne`/`countOther`; `{title}` fills `close`."},{"name":"className","type":"string","required":false,"defaultValue":null,"description":"Classes merged onto the folder button."}]}],"types":[{"name":"ProjectFolderPreview","file":"components/motion/project-folder.tsx","fields":[{"name":"id","type":"string","required":true,"description":"Unique key for the card, which links it between the folder and the overlay."},{"name":"content","type":"ReactNode","required":true,"description":"What the card shows, such as an image or file thumbnail."}]}],"files":[{"path":"components/motion/project-folder.tsx","type":"component","content":"\"use client\";\n// beui.dev/components/blocks/project-folder\n\nimport { X } from \"lucide-react\";\nimport {\n  AnimatePresence,\n  LayoutGroup,\n  motion,\n  type Transition,\n  useReducedMotion,\n} from \"motion/react\";\nimport {\n  type ReactNode,\n  useCallback,\n  useEffect,\n  useId,\n  useRef,\n  useState,\n} from \"react\";\nimport { createPortal } from \"react-dom\";\nimport { SPRING_LAYOUT, SPRING_PRESS } from \"@/lib/ease\";\nimport { useFocusTrap } from \"@/lib/hooks/use-focus-trap\";\nimport { useHoverCapable } from \"@/lib/hooks/use-hover-capable\";\nimport { useMessages } from \"@/lib/i18n\";\nimport { useScrollLock } from \"@/lib/scroll-lock\";\nimport { cn } from \"@/lib/utils\";\n\nexport type ProjectFolderPreview = {\n  /** Unique key for the card, which links it between the folder and the overlay. */\n  id: string;\n  /** What the card shows, such as an image or file thumbnail. */\n  content: ReactNode;\n};\n\n/** English defaults. Override per instance with `labels`, or app-wide with `LocaleProvider`. */\nexport const projectFolderMessages = {\n  description: \"Updated recently\",\n  countOne: \"{count} file\",\n  countOther: \"{count} files\",\n  closeOverlay: \"Close file overlay\",\n  close: \"Close {title}\",\n};\n\nexport type ProjectFolderMessages = typeof projectFolderMessages;\n\nexport interface ProjectFolderProps {\n  /** Folder name shown on the front and in the overlay header. */\n  title: string;\n  /** Secondary text beside the count. Default: \"Updated recently\" */\n  description?: string;\n  /** Cards that fan out of the folder and fill the overlay. Only the first 5 show. */\n  previews?: ProjectFolderPreview[];\n  /** Number shown in the count text. Default: the number of previews */\n  count?: number;\n  /**\n   * Singular noun for the count, e.g. `\"file\"`. Pluralized the English way by\n   * appending `s` (`3 files`), so only pass it for English copy. Leave it\n   * unset to use the localizable `countOne`/`countOther` messages.\n   */\n  itemLabel?: string;\n  /** Whether the lid tilts and previews fan out, for controlled use. */\n  open?: boolean;\n  /** Whether the folder starts open when uncontrolled. Default: false */\n  defaultOpen?: boolean;\n  /** Called with the new open state on hover, focus, click or close. */\n  onOpenChange?: (open: boolean) => void;\n  /** Whether the full-screen previews overlay is shown, for controlled use. */\n  expanded?: boolean;\n  /** Whether the overlay starts shown when uncontrolled. Default: false */\n  defaultExpanded?: boolean;\n  /** Called with the new state when the overlay opens or closes. */\n  onExpandedChange?: (expanded: boolean) => void;\n  /** Called when the folder is clicked, after it starts opening. */\n  onClick?: () => void;\n  /** Blocks hover, click and the overlay, and dims the folder. Default: false */\n  disabled?: boolean;\n  /** Accessible name for the folder button. */\n  ariaLabel?: string;\n  /** Override any built-in string. `{count}` fills `countOne`/`countOther`; `{title}` fills `close`. */\n  labels?: Partial<ProjectFolderMessages>;\n  /** Classes merged onto the folder button. */\n  className?: string;\n}\n\nconst MAX_PREVIEWS = 5;\n\nfunction getPreviewTransform(index: number, count: number) {\n  const offset = index - (count - 1) / 2;\n  const distance = Math.abs(offset);\n  const centerLift = Math.max(0, 2 - distance) * 8;\n\n  return {\n    x: offset * 44,\n    y: 8 - centerLift,\n    rotate: offset * 6,\n    scale: distance === 0 ? 1.04 : distance === 1 ? 0.95 : 0.88,\n    opacity: distance === 0 ? 1 : distance === 1 ? 0.78 : 0.58,\n    zIndex: 10 - distance,\n  };\n}\n\nexport function ProjectFolder({\n  title,\n  description: descriptionProp,\n  previews = [],\n  count = previews.length,\n  itemLabel,\n  open,\n  defaultOpen = false,\n  onOpenChange,\n  expanded,\n  defaultExpanded = false,\n  onExpandedChange,\n  onClick,\n  disabled = false,\n  ariaLabel,\n  labels,\n  className,\n}: ProjectFolderProps) {\n  const t = useMessages(\"projectFolder\", projectFolderMessages, labels);\n  const description = descriptionProp ?? t(\"description\");\n  const reduce = useReducedMotion();\n  const canHover = useHoverCapable();\n  const layoutGroupId = useId();\n  const dialogTitleId = `${layoutGroupId}-title`;\n  const hoveredRef = useRef(false);\n  const focusedRef = useRef(false);\n  const restoringFocusRef = useRef(false);\n  const folderButtonRef = useRef<HTMLButtonElement>(null);\n  const closeButtonRef = useRef<HTMLButtonElement>(null);\n  const dialogRef = useRef<HTMLDivElement>(null);\n  const [mounted, setMounted] = useState(false);\n  const [internalOpen, setInternalOpen] = useState(defaultOpen);\n  const [internalExpanded, setInternalExpanded] = useState(defaultExpanded);\n  const [isClosing, setIsClosing] = useState(false);\n  const openControlled = open !== undefined;\n  const expandedControlled = expanded !== undefined;\n  const isExpanded = expanded ?? internalExpanded;\n  const isOpen = (open ?? internalOpen) || isExpanded;\n  const previewItems = previews.slice(0, MAX_PREVIEWS);\n  const transition: Transition = reduce ? { duration: 0 } : SPRING_LAYOUT;\n  // `itemLabel` keeps its English suffix plural; without it the count comes from messages.\n  const countText =\n    itemLabel !== undefined\n      ? `${count} ${itemLabel}${count === 1 ? \"\" : \"s\"}`\n      : t(count === 1 ? \"countOne\" : \"countOther\", { count });\n\n  const setOpen = useCallback(\n    (next: boolean) => {\n      if (disabled) return;\n      if (!openControlled) setInternalOpen(next);\n      onOpenChange?.(next);\n    },\n    [disabled, onOpenChange, openControlled],\n  );\n\n  const setExpanded = useCallback(\n    (next: boolean) => {\n      if (disabled || previewItems.length === 0) return;\n      if (!expandedControlled) setInternalExpanded(next);\n      onExpandedChange?.(next);\n    },\n    [disabled, expandedControlled, onExpandedChange, previewItems.length],\n  );\n\n  const finishClose = useCallback(() => {\n    setIsClosing(false);\n    restoringFocusRef.current = true;\n    requestAnimationFrame(() => folderButtonRef.current?.focus());\n  }, []);\n\n  const closeOverlay = useCallback(() => {\n    setIsClosing(true);\n    setOpen(false);\n    setExpanded(false);\n  }, [setExpanded, setOpen]);\n\n  useEffect(() => setMounted(true), []);\n\n  useEffect(() => {\n    if (reduce && isClosing) finishClose();\n  }, [finishClose, isClosing, reduce]);\n\n  useFocusTrap(isExpanded && mounted, dialogRef, { onEscape: closeOverlay });\n  useScrollLock(isExpanded);\n  useEffect(() => {\n    if (!isExpanded) return;\n    const focusFrame = requestAnimationFrame(() => closeButtonRef.current?.focus());\n    return () => cancelAnimationFrame(focusFrame);\n  }, [isExpanded]);\n\n  const handleFolderClick = () => {\n    setIsClosing(false);\n    setExpanded(true);\n    setOpen(true);\n    onClick?.();\n  };\n\n  // The chrome is two siblings: a backdrop spanning the viewport edges that\n  // paints the scrim, and a transparent dialog inset off every edge that lays\n  // out and scrolls the panel. The backdrop cannot nest inside that scroll box -\n  // WebKit resolves a `position: fixed` descendant of an accelerated overflow\n  // scroller against the scroller, not the viewport, so the insets would go\n  // unscrimmed on a phone. The scroll box takes no pointer events and the panel\n  // takes them back, so gutter presses still close the overlay. Accepted: the\n  // 2rem inset sits outside the scroll box, so it stays put rather than\n  // scrolling away with the content.\n  const overlay = isExpanded || isClosing ? (\n    <>\n      <AnimatePresence initial={false}>\n        {isExpanded ? (\n          <motion.button\n            key=\"project-files-backdrop\"\n            type=\"button\"\n            tabIndex={-1}\n            aria-label={t(\"closeOverlay\")}\n            onClick={closeOverlay}\n            initial={{ opacity: 0 }}\n            animate={{ opacity: 1 }}\n            exit={{ opacity: 0 }}\n            transition={reduce ? { duration: 0 } : { duration: 0.18 }}\n            className={cn(\n              \"fixed inset-0 z-50 cursor-default bg-background/80 backdrop-blur-xl\",\n              isClosing && \"pointer-events-none\",\n            )}\n          />\n        ) : null}\n      </AnimatePresence>\n\n      <div\n        ref={dialogRef}\n        role=\"dialog\"\n        aria-modal=\"true\"\n        aria-labelledby={dialogTitleId}\n        aria-hidden={isExpanded ? undefined : \"true\"}\n        className=\"pointer-events-none fixed inset-x-6 inset-y-8 z-50 flex items-start justify-center overflow-y-auto sm:items-center\"\n      >\n        {/* 61rem, not `max-w-5xl`: the cap is on a padding-free box, so it has to\n            be the 64rem border box less the 3rem the gutters take. */}\n        <div\n          className={cn(\n            \"pointer-events-auto relative z-10 w-full max-w-[61rem]\",\n            isClosing && \"pointer-events-none\",\n          )}\n        >\n          <AnimatePresence initial={false}>\n            {isExpanded ? (\n              <motion.div\n                key=\"project-files-header\"\n                initial={{ opacity: 0, y: reduce ? 0 : 8 }}\n                animate={{ opacity: 1, y: 0 }}\n                exit={{ opacity: 0, y: reduce ? 0 : -8 }}\n                transition={reduce ? { duration: 0 } : { duration: 0.18 }}\n                className=\"mb-6 flex items-center justify-between gap-4\"\n              >\n                <div>\n                  <h2\n                    id={dialogTitleId}\n                    className=\"text-xl font-medium text-foreground\"\n                  >\n                    {title}\n                  </h2>\n                  <p className=\"mt-1 text-sm text-muted-foreground\">{countText}</p>\n                </div>\n                <button\n                  ref={closeButtonRef}\n                  type=\"button\"\n                  onClick={closeOverlay}\n                  aria-label={t(\"close\", { title })}\n                  className=\"flex size-10 items-center justify-center rounded-full border border-foreground/10 bg-background/50 text-muted-foreground backdrop-blur-xl transition-colors hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring\"\n                >\n                  <X className=\"size-4\" aria-hidden=\"true\" />\n                </button>\n              </motion.div>\n            ) : null}\n          </AnimatePresence>\n\n          <div className=\"grid grid-cols-2 place-items-center gap-3 sm:grid-cols-3 lg:grid-cols-5\">\n            {isExpanded\n              ? previewItems.map((preview) => (\n                  <motion.div\n                    key={preview.id}\n                    layoutId={`file-${preview.id}`}\n                    transition={transition}\n                    className=\"aspect-[3/4] w-full max-w-40 overflow-hidden rounded-xl border border-foreground/10 bg-background/50 backdrop-blur-xl\"\n                  >\n                    {preview.content}\n                  </motion.div>\n                ))\n              : null}\n          </div>\n        </div>\n      </div>\n    </>\n  ) : null;\n\n  return (\n    <LayoutGroup id={layoutGroupId}>\n      <motion.button\n        ref={folderButtonRef}\n        type=\"button\"\n        disabled={disabled}\n        aria-label={ariaLabel}\n        aria-haspopup=\"dialog\"\n        aria-expanded={isExpanded}\n        data-open={isOpen ? \"true\" : \"false\"}\n        data-expanded={isExpanded ? \"true\" : \"false\"}\n        tabIndex={isExpanded ? -1 : undefined}\n        onPointerEnter={() => {\n          if (!canHover) return;\n          hoveredRef.current = true;\n          setOpen(true);\n        }}\n        onPointerLeave={() => {\n          if (!canHover) return;\n          hoveredRef.current = false;\n          if (!isExpanded && !isClosing) setOpen(focusedRef.current);\n        }}\n        onFocus={() => {\n          if (restoringFocusRef.current) {\n            restoringFocusRef.current = false;\n            focusedRef.current = false;\n            return;\n          }\n          focusedRef.current = true;\n          setOpen(true);\n        }}\n        onBlur={() => {\n          focusedRef.current = false;\n          if (!isExpanded && !isClosing) setOpen(hoveredRef.current);\n        }}\n        onClick={handleFolderClick}\n        whileTap={reduce || disabled ? undefined : { scale: 0.98 }}\n        transition={reduce ? { duration: 0 } : SPRING_PRESS}\n        className={cn(\n          \"relative block h-56 w-72 select-none rounded-2xl text-left outline-none [perspective:1200px] focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-4 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50\",\n          className,\n        )}\n      >\n        <motion.span\n          aria-hidden=\"true\"\n          animate={{ rotateX: isOpen && !reduce ? 15 : 0 }}\n          transition={transition}\n          className=\"absolute inset-0 rounded-2xl border border-foreground/10 bg-background/25 backdrop-blur-xl [transform-origin:center_bottom]\"\n        />\n\n        <span\n          aria-hidden=\"true\"\n          className=\"pointer-events-none absolute inset-0\"\n        >\n          <span className=\"absolute left-1/2 top-0 block h-0 w-0\">\n            <AnimatePresence initial={false}>\n              {!isExpanded\n                  ? previewItems.map((preview, index) => {\n                    const opened = getPreviewTransform(\n                      index,\n                      previewItems.length,\n                    );\n                    return (\n                      <motion.span\n                        key={preview.id}\n                        layoutId={`file-${preview.id}`}\n                        initial={false}\n                        animate={\n                          isOpen && !reduce\n                            ? {\n                                x: opened.x * 1.4,\n                                y: opened.y - 8,\n                                rotate: opened.rotate * 1.3,\n                                scale: opened.scale * 1.02,\n                                opacity: Math.min(1, opened.opacity + 0.18),\n                              }\n                            : {\n                                x: opened.x,\n                                y: opened.y,\n                                rotate: opened.rotate,\n                                scale: opened.scale,\n                                opacity: opened.opacity,\n                              }\n                        }\n                        transition={transition}\n                        onLayoutAnimationComplete={() => {\n                          if (isClosing && index === 0) finishClose();\n                        }}\n                        className=\"absolute left-0 top-0 -ml-12 block h-40 w-24 overflow-hidden rounded-lg border border-foreground/10 bg-background/45 backdrop-blur-lg\"\n                        style={{ zIndex: opened.zIndex }}\n                      >\n                        {preview.content}\n                      </motion.span>\n                    );\n                  })\n                : null}\n            </AnimatePresence>\n          </span>\n        </span>\n\n        <motion.span\n          initial={false}\n          animate={{ rotateX: isOpen && !reduce ? -25 : 0 }}\n          transition={transition}\n          className=\"absolute inset-x-0 bottom-0 z-20 overflow-hidden rounded-2xl border border-foreground/10 bg-background/60 backdrop-blur-2xl [backface-visibility:hidden] [transform-origin:center_bottom]\"\n        >\n          <span className=\"flex h-16 items-center px-4\">\n            <span className=\"line-clamp-2 text-xl font-medium leading-tight text-foreground\">\n              {title}\n            </span>\n          </span>\n          <span className=\"flex h-12 items-center justify-between gap-3 border-t border-foreground/10 px-4\">\n            <span className=\"shrink-0 text-sm font-medium text-foreground/70\">\n              {countText}\n            </span>\n            <span className=\"truncate text-sm text-muted-foreground\">\n              {description}\n            </span>\n          </span>\n        </motion.span>\n      </motion.button>\n\n      {mounted ? createPortal(overlay, document.body) : null}\n    </LayoutGroup>\n  );\n}\n"},{"path":"lib/ease.ts","type":"util","content":"// Shared motion tokens. Easing curves mirror the CSS custom properties in\n// globals.css; springs are the canonical physics used across components.\n// Strong custom variants - defaults like `ease-in`/`ease-out` feel weak.\n\nexport const EASE_OUT = [0.16, 1, 0.3, 1] as const;\n/** Accelerating curve for things that fall (a dropped ball, a toppled block). Not for UI entrances. */\nexport const EASE_IN = [0.55, 0, 1, 0.45] as const;\nexport const EASE_IN_OUT = [0.77, 0, 0.175, 1] as const;\nexport const EASE_DRAWER = [0.32, 0.72, 0, 1] as const;\n\n/** CSS string form of EASE_OUT for inline style transitions. */\nexport const EASE_OUT_CSS = \"cubic-bezier(0.16, 1, 0.3, 1)\";\n\n/** Press feedback on buttons and other tappable surfaces. */\nexport const SPRING_PRESS = {\n  type: \"spring\",\n  stiffness: 500,\n  damping: 30,\n  mass: 0.6,\n} as const;\n\n/** Content swaps - label/icon slots trading places inside a control. */\nexport const SPRING_SWAP = {\n  type: \"spring\",\n  stiffness: 460,\n  damping: 30,\n  mass: 0.55,\n} as const;\n\n/** Overlay panel entrances - modals and sheets summoned by pointer. */\nexport const SPRING_PANEL = {\n  type: \"spring\",\n  stiffness: 420,\n  damping: 40,\n  mass: 0.5,\n} as const;\n\n/** Shared-layout glides - pills, indicators and panels morphing between positions. */\nexport const SPRING_LAYOUT = {\n  type: \"spring\",\n  stiffness: 360,\n  damping: 32,\n  mass: 0.6,\n} as const;\n\n/** Cursor-follow physics for decorative mouse tracking (magnetic, tilt, dock). */\nexport const SPRING_MOUSE = {\n  stiffness: 200,\n  damping: 15,\n  mass: 0.3,\n} as const;\n\n/** Dragged handles and fills (sliders) - critically damped `useSpring` config,\n * so the value follows the pointer butterily and never rebounds off an end. */\nexport const SPRING_GLIDE = {\n  stiffness: 700,\n  damping: 50,\n  mass: 0.5,\n} as const;\n\n/** Shared-surface morphs: a trigger growing into its panel and back on one\n * weighted spring, so opening and closing travel the same path. */\nexport const SPRING_MORPH = {\n  type: \"spring\",\n  duration: 0.5,\n  bounce: 0.22,\n} as const;\n"},{"path":"lib/hooks/use-focus-trap.ts","type":"util","content":"\"use client\";\n\nimport { type RefObject, useEffect, useLayoutEffect, useRef } from \"react\";\nimport { cycleTab, focusFirstIn } from \"@/lib/focusable\";\nimport { inLayerAbove, type Layer, openLayer, ownsEscape, trapAbove } from \"@/lib/layers\";\n\nexport interface FocusTrapOptions {\n  /** Called on Escape while this is the innermost open layer. */\n  onEscape?: () => void;\n}\n\n/**\n * Moves focus into `panel` when `open` turns true, keeps Tab cycling inside it,\n * pulls focus back if it lands outside, and returns focus to whatever held it\n * before opening once `open` turns false.\n *\n * Layers opened on top (a menu portaled out of a drawer, a sheet opened from\n * it) keep focus and Escape until they close: see `lib/layers.ts`.\n *\n * For overlays rendered in place, where `useModalScope` cannot inert the rest\n * of the page. Pass `open` rather than presence: an exiting panel is already\n * inert through `PresenceGate`, so the trap releases with the same commit.\n * Give the panel `tabIndex={-1}` so it can take focus when it holds nothing\n * focusable.\n */\nexport function useFocusTrap(\n  open: boolean,\n  panel: RefObject<HTMLElement | null>,\n  { onEscape }: FocusTrapOptions = {},\n) {\n  const escapeRef = useRef(onEscape);\n  useLayoutEffect(() => {\n    escapeRef.current = onEscape;\n  });\n\n  useEffect(() => {\n    if (!open || !panel.current) return;\n    const layer: Layer = {\n      contains: (target) => Boolean(panel.current?.contains(target)),\n      traps: true,\n      get escape() {\n        return Boolean(escapeRef.current);\n      },\n    };\n    const closeLayer = openLayer(layer);\n    const returnFocus =\n      document.activeElement instanceof HTMLElement\n        ? document.activeElement\n        : null;\n    if (!panel.current.contains(document.activeElement)) focusFirstIn(panel.current);\n\n    const onFocus = (event: FocusEvent) => {\n      const target = event.target;\n      if (!(target instanceof Node) || !panel.current) return;\n      if (panel.current.closest(\"[inert]\") || panel.current.contains(target)) return;\n      if (inLayerAbove(layer, target) || trapAbove(layer)) return;\n      focusFirstIn(panel.current);\n    };\n    const onKey = (event: KeyboardEvent) => {\n      if (event.key === \"Escape\") {\n        if (!escapeRef.current || !ownsEscape(layer, event)) return;\n        event.preventDefault();\n        escapeRef.current();\n        return;\n      }\n      const active = document.activeElement;\n      if (event.defaultPrevented || (active && inLayerAbove(layer, active))) return;\n      cycleTab(event, panel.current);\n    };\n    document.addEventListener(\"focusin\", onFocus);\n    document.addEventListener(\"keydown\", onKey);\n    return () => {\n      document.removeEventListener(\"focusin\", onFocus);\n      document.removeEventListener(\"keydown\", onKey);\n      closeLayer();\n      if (returnFocus?.isConnected && !returnFocus.closest(\"[inert]\"))\n        returnFocus.focus({ preventScroll: true });\n    };\n  }, [open, panel]);\n}\n"},{"path":"lib/hooks/use-hover-capable.ts","type":"util","content":"\"use client\";\n\nimport { useEffect, useState } from \"react\";\n\n/**\n * Returns true only on devices that have a true hover (mouse / trackpad).\n * Touch devices fire phantom `:hover` on tap that sticks until tap-elsewhere\n * - gate hover-only effects (scale lifts, magnetic pulls) behind this.\n */\nexport function useHoverCapable() {\n  const [canHover, setCanHover] = useState(false);\n\n  useEffect(() => {\n    if (typeof window === \"undefined\" || !window.matchMedia) return;\n    const mq = window.matchMedia(\"(hover: hover) and (pointer: fine)\");\n    const update = () => setCanHover(mq.matches);\n    update();\n    mq.addEventListener?.(\"change\", update);\n    return () => mq.removeEventListener?.(\"change\", update);\n  }, []);\n\n  return canHover;\n}\n"},{"path":"lib/i18n.tsx","type":"util","content":"\"use client\";\n\nimport {\n  createContext,\n  type ReactNode,\n  useCallback,\n  useContext,\n  useMemo,\n} from \"react\";\n\n/**\n * A component's messages. Plain strings with `{name}` placeholders, so a\n * dictionary stays JSON-serializable and can be passed from a server layout.\n * There are no plural forms: write messages that read correctly for any count.\n */\nexport type Messages = Record<string, string>;\n\n/** A language file: component namespace → any subset of that component's messages. */\nexport type LocaleMessages = Record<string, Partial<Messages>>;\n\ntype LocaleContextValue = {\n  locale?: string;\n  messages: LocaleMessages;\n};\n\nconst NO_MESSAGES: LocaleMessages = {};\n\nconst LocaleContext = createContext<LocaleContextValue>({ messages: NO_MESSAGES });\n\n/** Without a locale, digits stay plain so server and client render the same text. */\nexport function formatNumber(value: number, locale?: string) {\n  return locale ? new Intl.NumberFormat(locale).format(value) : String(value);\n}\n\nexport interface LocaleProviderProps {\n  /** BCP 47 tag, e.g. `de`, `pt-BR`. Drives `Intl` number formatting. */\n  locale: string;\n  /**\n   * Component namespace → translated strings. Missing keys fall back to English.\n   * Pass a stable object (a module constant, imported JSON or a memoized value):\n   * a new object each render gives every translated component a new `t`.\n   */\n  messages?: LocaleMessages;\n  children: ReactNode;\n}\n\nexport function LocaleProvider({ locale, messages = NO_MESSAGES, children }: LocaleProviderProps) {\n  const value = useMemo(() => ({ locale, messages }), [locale, messages]);\n  return <LocaleContext.Provider value={value}>{children}</LocaleContext.Provider>;\n}\n\nexport function useLocale(): { locale?: string } {\n  return { locale: useContext(LocaleContext).locale };\n}\n\n/**\n * Resolves a component's strings: `labels` prop, then the provider's\n * messages for `namespace`, then the component's English `defaults`.\n * Numbers passed as values are formatted for the provider's locale.\n */\nexport function useMessages<T extends Messages>(\n  namespace: string,\n  defaults: T,\n  labels?: Partial<T>,\n) {\n  const { locale, messages } = useContext(LocaleContext);\n  const provided = messages[namespace];\n  // Inline `labels={{ … }}` is a new object every render. Keying it by content\n  // keeps `t` one identity until a label changes, so effects and memos that\n  // depend on `t` don't re-run per render, and render-time reads never lag.\n  const labelsKey = labels ? JSON.stringify(labels) : \"\";\n  const stableLabels = useMemo(\n    () => (labelsKey ? (JSON.parse(labelsKey) as Partial<T>) : undefined),\n    [labelsKey],\n  );\n\n  return useCallback(\n    (key: keyof T & string, values?: Record<string, string | number>) => {\n      const template = stableLabels?.[key] ?? provided?.[key] ?? defaults[key];\n      if (!values) return template;\n      return template.replace(/\\{(\\w+)\\}/g, (match, name: string) => {\n        const value = values[name];\n        if (value === undefined) return match;\n        return typeof value === \"number\" ? formatNumber(value, locale) : value;\n      });\n    },\n    [defaults, stableLabels, locale, provided],\n  );\n}\n"},{"path":"lib/scroll-lock.ts","type":"util","content":"\"use client\";\n\nimport { useEffect } from \"react\";\n\nexport interface ScrollLockOptions {\n  /**\n   * Pin the body with `position: fixed` and restore the scroll offset on\n   * release. iOS Safari still scrolls an `overflow: hidden` body under a\n   * touch drag, so full-screen sheets that take touch gestures need this.\n   */\n  fixed?: boolean;\n}\n\n// Reference-counted, so overlays that close out of order never unlock the\n// page under one that is still open. The first lock picks the technique.\nlet owners = 0;\nlet restore: (() => void) | null = null;\n\nfunction apply({ fixed = false }: ScrollLockOptions) {\n  const root = document.documentElement;\n  const body = document.body;\n  const scrollY = window.scrollY;\n  const previous = {\n    rootOverflow: root.style.overflow,\n    overflow: body.style.overflow,\n    position: body.style.position,\n    top: body.style.top,\n    left: body.style.left,\n    right: body.style.right,\n  };\n  root.style.overflow = \"hidden\";\n  body.style.overflow = \"hidden\";\n  if (fixed) {\n    body.style.position = \"fixed\";\n    body.style.top = `-${scrollY}px`;\n    body.style.left = \"0\";\n    body.style.right = \"0\";\n  }\n  return () => {\n    root.style.overflow = previous.rootOverflow;\n    body.style.overflow = previous.overflow;\n    if (!fixed) return;\n    body.style.position = previous.position;\n    body.style.top = previous.top;\n    body.style.left = previous.left;\n    body.style.right = previous.right;\n    window.scrollTo(0, scrollY);\n  };\n}\n\n/** Locks page scroll. Call the returned function to release this lock. */\nexport function lockScroll(options: ScrollLockOptions = {}) {\n  if (owners++ === 0) restore = apply(options);\n  let released = false;\n  return () => {\n    if (released) return;\n    released = true;\n    if (--owners === 0) {\n      restore?.();\n      restore = null;\n    }\n  };\n}\n\n/** Locks page scroll while `locked` is true. */\nexport function useScrollLock(locked: boolean, { fixed = false }: ScrollLockOptions = {}) {\n  useEffect(() => {\n    if (!locked) return;\n    return lockScroll({ fixed });\n  }, [locked, fixed]);\n}\n"},{"path":"lib/utils.ts","type":"util","content":"import { clsx, type ClassValue } from \"clsx\"\nimport { twMerge } from \"tailwind-merge\"\n\nexport function cn(...inputs: ClassValue[]) {\n  return twMerge(clsx(inputs))\n}\n"},{"path":"lib/focusable.ts","type":"util","content":"/**\n * Elements that can usually take keyboard focus. The selector cannot see\n * everything focus() checks (an element under `display: none`, say), so a\n * caller that needs certainty tries focus() and checks where it landed.\n */\nexport const FOCUSABLE_SELECTOR = [\n  \"a[href]\",\n  \"button:not(:disabled)\",\n  \"input:not(:disabled):not([type='hidden'])\",\n  \"select:not(:disabled)\",\n  \"textarea:not(:disabled)\",\n  \"[tabindex]:not([tabindex='-1'])\",\n].join(\",\");\n\n/** Elements inside `container` that Tab can reach, in DOM order. */\nexport function focusablesIn(container: Element | null | undefined) {\n  return Array.from(\n    container?.querySelectorAll<HTMLElement>(FOCUSABLE_SELECTOR) ?? [],\n  ).filter((element) => element.tabIndex >= 0 && !element.closest(\"[inert]\"));\n}\n\n/** Focuses the first tabbable element in `panel`, or the panel itself. */\nexport function focusFirstIn(panel: HTMLElement | null | undefined) {\n  (focusablesIn(panel)[0] ?? panel)?.focus({ preventScroll: true });\n}\n\n/**\n * Keeps a Tab keypress inside `panel`, wrapping from the last tabbable element\n * to the first and back. Give the panel `tabIndex={-1}` so it can hold focus\n * when it has nothing tabbable.\n */\nexport function cycleTab(event: KeyboardEvent, panel: HTMLElement | null) {\n  if (event.key !== \"Tab\" || !panel) return;\n  const elements = focusablesIn(panel);\n  const first = elements[0];\n  const last = elements[elements.length - 1];\n  const active = document.activeElement;\n  if (!first || !last) {\n    event.preventDefault();\n    panel.focus({ preventScroll: true });\n  } else if (event.shiftKey && (active === first || active === panel)) {\n    event.preventDefault();\n    last.focus();\n  } else if (!event.shiftKey && active === last) {\n    event.preventDefault();\n    first.focus();\n  }\n}\n"},{"path":"lib/layers.ts","type":"util","content":"/**\n * Every open overlay on the page, innermost last: focus traps, modal scopes\n * and dismissable menus all register here. Overlays have no shared z-order to\n * consult, and a menu inside a drawer portals out of it, so this stack is how\n * they agree on who answers Escape and where focus may go.\n */\n\nexport interface Layer {\n  /** Whether `target` belongs to this layer (its panel, portals, trigger). */\n  contains: (target: Node) => boolean;\n  /** True for focus traps and modal scopes, which pull stray focus back. */\n  traps?: boolean;\n  /** False for a layer that ignores Escape, so the key reaches the one below. */\n  escape?: boolean;\n}\n\nconst stack: Layer[] = [];\n// The innermost layer when each Escape began, read before any handler runs,\n// so a layer that closes itself mid-event can't hand the key to the one below.\nconst escapeOwners = new WeakMap<Event, Layer | undefined>();\nlet listening = false;\n\nfunction innermostEscapeLayer() {\n  for (let index = stack.length - 1; index >= 0; index--) {\n    if (stack[index].escape !== false) return stack[index];\n  }\n  return undefined;\n}\n\nfunction recordEscapeOwner(event: KeyboardEvent) {\n  if (event.key === \"Escape\") escapeOwners.set(event, innermostEscapeLayer());\n}\n\n/** Registers an open layer. Call the returned function when it closes. */\nexport function openLayer(layer: Layer) {\n  if (!listening) {\n    document.addEventListener(\"keydown\", recordEscapeOwner, true);\n    listening = true;\n  }\n  stack.push(layer);\n  return () => {\n    const index = stack.indexOf(layer);\n    if (index !== -1) stack.splice(index, 1);\n  };\n}\n\n/** Whether this Escape is `layer`'s to answer: it was innermost when the key went down. */\nexport function ownsEscape(layer: Layer, event: KeyboardEvent) {\n  if (event.defaultPrevented) return false;\n  const owner = escapeOwners.has(event)\n    ? escapeOwners.get(event)\n    : innermostEscapeLayer();\n  return owner === layer;\n}\n\n/** Whether `target` sits in a layer opened on top of `layer`. */\nexport function inLayerAbove(layer: Layer, target: Node) {\n  const index = stack.indexOf(layer);\n  return stack.slice(index + 1).some((above) => above.contains(target));\n}\n\n/** Whether a focus trap is open on top of `layer`; stray focus is that one's to pull back. */\nexport function trapAbove(layer: Layer) {\n  const index = stack.indexOf(layer);\n  return stack.slice(index + 1).some((above) => above.traps);\n}\n\n/**\n * Whether `target` belongs to any open layer other than `layer`. Pass\n * `traps: false` to count only dismissable overlays, not the traps under them.\n */\nexport function inOtherLayer(layer: Layer, target: Node, { traps = true } = {}) {\n  return stack.some(\n    (other) => other !== layer && (traps || !other.traps) && other.contains(target),\n  );\n}\n"},{"path":"components/previews/blocks/project-folder.preview.tsx","type":"preview","content":"\"use client\";\n\nimport { ProjectFolder } from \"@/components/motion/project-folder\";\n\nconst previews = [\n  { id: \"moss\", color: \"bg-emerald-200\", mark: \"A\" },\n  { id: \"clay\", color: \"bg-orange-200\", mark: \"B\" },\n  { id: \"sky\", color: \"bg-sky-200\", mark: \"C\" },\n  { id: \"rose\", color: \"bg-rose-200\", mark: \"D\" },\n  { id: \"sand\", color: \"bg-amber-100\", mark: \"E\" },\n].map((preview) => ({\n  id: preview.id,\n  content: (\n    <span className={cn(\"relative block h-full w-full\", preview.color)}>\n      <span className=\"absolute left-3 top-3 h-2 w-8 rounded-full bg-black/15\" />\n      <span className=\"absolute inset-x-3 top-8 h-px bg-black/10\" />\n      <span className=\"absolute inset-x-3 top-11 h-px bg-black/10\" />\n      <span className=\"absolute bottom-3 right-3 text-sm font-medium text-black/50\">\n        {preview.mark}\n      </span>\n    </span>\n  ),\n}));\n\nfunction cn(...classes: string[]) {\n  return classes.filter(Boolean).join(\" \");\n}\n\nexport function ProjectFolderPreview() {\n  return (\n    <div className=\"flex min-h-80 w-full items-center justify-center px-6 py-10\">\n      <ProjectFolder\n        title=\"Brand direction\"\n        description=\"Updated recently\"\n        count={5}\n        previews={previews}\n        onClick={() => {}}\n      />\n    </div>\n  );\n}\n"}]}