{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "launcher-dock",
  "title": "Launcher Dock",
  "description": "Centred floating launcher bar at the bottom of the screen that opens the app's command palette.",
  "dependencies": [
    "@vllnt/ui@^0.4.0",
    "lucide-react"
  ],
  "registryDependencies": [],
  "files": [
    {
      "path": "registry/default/launcher-dock/launcher-dock.tsx",
      "content": "\"use client\";\n\nimport { useCallback, useEffect, useRef, useState } from \"react\";\n\nimport { Search } from \"lucide-react\";\nimport type { ComponentPropsWithoutRef, ReactNode, RefObject } from \"react\";\n\nimport type { Material, MaterialProps } from \"@vllnt/ui\";\nimport { assignRef } from \"@vllnt/ui\";\nimport { useMounted } from \"@vllnt/ui\";\nimport { cn } from \"@vllnt/ui\";\n\n/**\n * Where {@link LauncherDock} shows. `\"below-desktop\"` hides it (and its\n * spacer) at 1024 px and wider, with a media query in `@vllnt/ui/styles.css`.\n *\n * @public\n */\nexport type LauncherDockPlacement = \"all\" | \"below-desktop\";\n\n/**\n * Props for {@link LauncherDock}.\n *\n * @public\n */\nexport type LauncherDockProps = Omit<\n  ComponentPropsWithoutRef<\"div\">,\n  \"children\"\n> &\n  Omit<MaterialProps, \"material\"> & {\n    /** Hide on scroll down of the window, show again on scroll up or at the top. Other scroll containers are not watched. Defaults to `true`. */\n    hideOnScroll?: boolean;\n    /** Hide while a text field or contenteditable outside the dock and outside any dialog has focus (the on-screen keyboard is up). CSS `:has()` does it; without `:has()` support the dock stays shown. Defaults to `true`. */\n    hideWhileEditing?: boolean;\n    /** Text of the launcher button, and its accessible name. */\n    label: string;\n    /** Content before the launcher button inside the bar, such as an icon button. */\n    leading?: ReactNode;\n    /** Surface material. Defaults to `\"solid\"` (flat); `\"glass\"` opts in to glass. */\n    material?: Material;\n    /** Runs when the user presses the launcher button. Open the palette here. */\n    onOpen: () => void;\n    /** Where the dock shows. Defaults to `\"all\"`. */\n    placement?: LauncherDockPlacement;\n    /** Keyboard hint shown after mount: ⌘K on Apple platforms, Ctrl K elsewhere. The app binds the key. */\n    shortcut?: \"mod+k\";\n    /** Content after the launcher button inside the bar, such as an icon button. */\n    trailing?: ReactNode;\n  };\n\ntype ShortcutPlatform = \"apple\" | \"other\";\n\nconst APPLE_PLATFORM = /Mac|iPhone|iPad|iPod/;\n\nconst SCROLL_THRESHOLD = 8;\n\nconst SHORTCUT_HINT = { apple: \"⌘K\", other: \"Ctrl K\" } as const;\n\nconst SHORTCUT_KEYS = { apple: \"Meta+K\", other: \"Control+K\" } as const;\n\nfunction readShortcutPlatform(): ShortcutPlatform {\n  return APPLE_PLATFORM.test(navigator.userAgent) ? \"apple\" : \"other\";\n}\n\nfunction useScrolledAway(\n  enabled: boolean,\n  rootRef: RefObject<HTMLDivElement | null>,\n): boolean {\n  const [scrolledAway, setScrolledAway] = useState(false);\n  useEffect(() => {\n    if (!enabled) return;\n    const readY = (): number =>\n      Math.min(\n        Math.max(window.scrollY, 0),\n        Math.max(document.documentElement.scrollHeight - window.innerHeight, 0),\n      );\n    let lastY = readY();\n    const handleScroll = (): void => {\n      const y = readY();\n      const delta = y - lastY;\n      if (Math.abs(delta) < SCROLL_THRESHOLD && y > 0) return;\n      lastY = y;\n      if (delta > 0 && rootRef.current?.querySelector(\":focus-visible\")) {\n        return;\n      }\n      setScrolledAway(delta > 0 && y > 0);\n    };\n    window.addEventListener(\"scroll\", handleScroll, { passive: true });\n    return () => {\n      window.removeEventListener(\"scroll\", handleScroll);\n    };\n  }, [enabled, rootRef]);\n  return enabled && scrolledAway;\n}\n\nfunction useDockVisibility(\n  hideOnScroll: boolean,\n  ref: React.Ref<HTMLDivElement> | undefined,\n): { hidden: boolean; setRoot: (node: HTMLDivElement | null) => void } {\n  const rootRef = useRef<HTMLDivElement | null>(null);\n  const hidden = useScrolledAway(hideOnScroll, rootRef);\n  const setRoot = useCallback(\n    (node: HTMLDivElement | null): void => {\n      rootRef.current = node;\n      assignRef(ref, node);\n    },\n    [ref],\n  );\n  return { hidden, setRoot };\n}\n\nfunction useShortcutPlatform(\n  shortcut: LauncherDockProps[\"shortcut\"],\n): null | ShortcutPlatform {\n  const mounted = useMounted();\n  return mounted && shortcut !== undefined ? readShortcutPlatform() : null;\n}\n\nfunction LauncherButton(props: {\n  label: string;\n  onOpen: () => void;\n  shortcut: LauncherDockProps[\"shortcut\"];\n}): React.ReactElement {\n  const { label, onOpen, shortcut } = props;\n  const platform = useShortcutPlatform(shortcut);\n  const handleOpen = (): void => {\n    onOpen();\n  };\n  return (\n    <button\n      aria-keyshortcuts={platform ? SHORTCUT_KEYS[platform] : undefined}\n      className=\"flex min-h-11 min-w-0 flex-1 items-center gap-2 rounded-full px-3 text-left text-sm text-muted-foreground transition-colors hover:bg-secondary/60 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring\"\n      data-slot=\"launcher-dock-button\"\n      onClick={handleOpen}\n      type=\"button\"\n    >\n      <Search aria-hidden=\"true\" className=\"size-4 shrink-0\" />\n      <span className=\"min-w-0 flex-1 truncate\">{label}</span>\n      {platform ? (\n        <kbd\n          aria-hidden=\"true\"\n          className=\"shrink-0 rounded border px-1.5 py-0.5 font-mono text-xs [@media(pointer:coarse)]:hidden\"\n          data-slot=\"launcher-dock-shortcut\"\n        >\n          {SHORTCUT_HINT[platform]}\n        </kbd>\n      ) : null}\n    </button>\n  );\n}\n\n/**\n * Centred floating launcher bar at the bottom of the viewport, such as\n * \"Search… ⌘K\". Pressing it calls `onOpen`; the app opens its own palette.\n * It hides on scroll down of the window and while a text field outside a\n * dialog has focus, clears the\n * bottom safe area, and renders a spacer in its place in the page flow, so\n * the dock never covers the end of the page. Flat by default;\n * `material=\"glass\"` opts in to glass.\n *\n * @example\n * ```tsx\n * <LauncherDock label=\"Search…\" shortcut=\"mod+k\" onOpen={() => setOpen(true)} />\n * ```\n *\n * @public\n */\nexport const LauncherDock = /* @__PURE__ */ named(\n  \"LauncherDock\",\n  ({\n    className,\n    hideOnScroll = true,\n    hideWhileEditing = true,\n    label,\n    leading,\n    material = \"solid\",\n    onOpen,\n    placement = \"all\",\n    ref,\n    shortcut,\n    trailing,\n    ...props\n  }: LauncherDockProps & { ref?: React.Ref<HTMLDivElement> }) => {\n    const { hidden, setRoot } = useDockVisibility(hideOnScroll, ref);\n    return (\n      <>\n        <div\n          aria-hidden=\"true\"\n          className=\"h-[calc(5rem+env(safe-area-inset-bottom,0px))] shrink-0\"\n          data-placement={placement}\n          data-slot=\"launcher-dock-spacer\"\n        />\n        <div\n          className={cn(\n            \"pointer-events-none fixed inset-x-0 bottom-0 z-40 flex justify-center px-4 pb-[calc(0.75rem+env(safe-area-inset-bottom,0px))] transition-[transform,opacity] duration-200 ease-out motion-reduce:transition-none data-[hidden]:translate-y-full data-[hidden]:opacity-0\",\n            className,\n          )}\n          data-hidden={hidden ? \"\" : undefined}\n          data-hide-while-editing={hideWhileEditing ? \"\" : undefined}\n          data-placement={placement}\n          data-slot=\"launcher-dock\"\n          inert={hidden}\n          ref={setRoot}\n          {...props}\n        >\n          <div\n            className=\"vllnt-glass-floating vllnt-glass-dense pointer-events-auto flex w-full max-w-md items-center gap-1 rounded-full border p-1 text-foreground\"\n            data-glass={material === \"glass\" ? \"on\" : undefined}\n            data-material={material}\n          >\n            {leading}\n            <LauncherButton label={label} onOpen={onOpen} shortcut={shortcut} />\n            {trailing}\n          </div>\n        </div>\n      </>\n    );\n  },\n);\n\nfunction named<TComponent extends object>(\n  displayName: string,\n  component: TComponent,\n): TComponent & { displayName: string };\nfunction named<TComponent extends object, TStatics extends object>(\n  displayName: string,\n  component: TComponent,\n  statics: () => TStatics,\n): TComponent & TStatics & { displayName: string };\nfunction named(\n  displayName: string,\n  component: object,\n  statics?: () => object,\n): object {\n  return Object.assign(component, statics?.(), { displayName });\n}\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component",
  "version": "0.4.0",
  "stability": "stable",
  "platforms": [
    "web"
  ]
}
