{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "kbd",
  "title": "Kbd",
  "description": "A keyboard key cap for showing shortcuts, with raised, flat and outline styles, 3 sizes, automatic Mac or Windows symbols, key combinations and a live press animation.",
  "dependencies": [
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "registry/new-york/kbd/kbd.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport { clsx, type ClassValue } from \"clsx\";\nimport { twMerge } from \"tailwind-merge\";\n\nfunction cn(...inputs: ClassValue[]) {\n  return twMerge(clsx(inputs));\n}\n\nexport type KbdVariant = \"raised\" | \"flat\" | \"outline\";\nexport type KbdSize = \"sm\" | \"md\" | \"lg\";\n\nexport interface KbdProps {\n  combo?: string;\n  children?: React.ReactNode;\n  variant?: KbdVariant;\n  size?: KbdSize;\n  theme?: \"dark\" | \"light\";\n  separator?: boolean;\n  listen?: boolean;\n  className?: string;\n}\n\nconst PALETTES = {\n  dark: {\n    raised: { bg: \"linear-gradient(180deg, #1C1C1C, #141414)\", border: \"rgba(255,255,255,0.12)\", shadow: \"0 2px 0 0 rgba(255,255,255,0.1), inset 0 1px 0 rgba(255,255,255,0.06)\", pressedShadow: \"0 0 0 0 rgba(255,255,255,0.1), inset 0 1px 0 rgba(255,255,255,0.04)\" },\n    flat: { bg: \"rgba(255,255,255,0.07)\", border: \"transparent\", shadow: \"none\", pressedShadow: \"none\" },\n    outline: { bg: \"transparent\", border: \"rgba(255,255,255,0.22)\", shadow: \"none\", pressedShadow: \"none\" },\n    text: \"#F5F4F1\",\n    muted: \"rgba(245,244,241,0.4)\",\n    pressedBg: \"rgba(255,255,255,0.16)\",\n  },\n  light: {\n    raised: { bg: \"linear-gradient(180deg, #FFFFFF, #F5F4F1)\", border: \"rgba(10,10,10,0.14)\", shadow: \"0 2px 0 0 rgba(10,10,10,0.14), inset 0 1px 0 rgba(255,255,255,0.9)\", pressedShadow: \"0 0 0 0 rgba(10,10,10,0.14), inset 0 1px 0 rgba(255,255,255,0.6)\" },\n    flat: { bg: \"rgba(10,10,10,0.06)\", border: \"transparent\", shadow: \"none\", pressedShadow: \"none\" },\n    outline: { bg: \"transparent\", border: \"rgba(10,10,10,0.25)\", shadow: \"none\", pressedShadow: \"none\" },\n    text: \"#0A0A0A\",\n    muted: \"rgba(10,10,10,0.4)\",\n    pressedBg: \"rgba(10,10,10,0.12)\",\n  },\n};\n\nconst SIZES: Record<KbdSize, { height: number; font: number; padX: number; radius: number }> = {\n  sm: { height: 22, font: 11, padX: 6, radius: 6 },\n  md: { height: 26, font: 12.5, padX: 8, radius: 7 },\n  lg: { height: 32, font: 14, padX: 10, radius: 9 },\n};\n\nconst SYMBOLS: Record<string, { mac?: string; other?: string; both?: string }> = {\n  mod: { mac: \"⌘\", other: \"Ctrl\" },\n  cmd: { both: \"⌘\" },\n  command: { both: \"⌘\" },\n  meta: { mac: \"⌘\", other: \"Win\" },\n  ctrl: { mac: \"⌃\", other: \"Ctrl\" },\n  control: { mac: \"⌃\", other: \"Ctrl\" },\n  shift: { both: \"⇧\" },\n  alt: { mac: \"⌥\", other: \"Alt\" },\n  option: { mac: \"⌥\", other: \"Alt\" },\n  enter: { both: \"↵\" },\n  return: { both: \"↵\" },\n  esc: { both: \"Esc\" },\n  escape: { both: \"Esc\" },\n  tab: { both: \"⇥\" },\n  backspace: { both: \"⌫\" },\n  delete: { both: \"Del\" },\n  space: { both: \"Space\" },\n  up: { both: \"↑\" },\n  down: { both: \"↓\" },\n  left: { both: \"←\" },\n  right: { both: \"→\" },\n};\n\nconst subscribe = () => () => {};\nconst getMac = () => typeof navigator !== \"undefined\" && /Mac|iPhone|iPad/i.test(navigator.platform || navigator.userAgent);\n\nfunction labelFor(token: string, mac: boolean) {\n  const entry = SYMBOLS[token.toLowerCase()];\n  if (entry) return entry.both ?? (mac ? entry.mac : entry.other) ?? token;\n  return token.length === 1 ? token.toUpperCase() : token;\n}\n\nfunction eventToken(e: KeyboardEvent): string {\n  const k = e.key;\n  if (k === \"Meta\") return \"cmd\";\n  if (k === \"Control\") return \"ctrl\";\n  if (k === \"Shift\") return \"shift\";\n  if (k === \"Alt\") return \"alt\";\n  if (k === \" \") return \"space\";\n  if (k === \"Escape\") return \"esc\";\n  if (k.startsWith(\"Arrow\")) return k.slice(5).toLowerCase();\n  return k.toLowerCase();\n}\n\nfunction normalizeToken(token: string, mac: boolean) {\n  const t = token.toLowerCase();\n  if (t === \"mod\") return mac ? \"cmd\" : \"ctrl\";\n  if (t === \"command\" || t === \"meta\") return \"cmd\";\n  if (t === \"control\") return \"ctrl\";\n  if (t === \"option\") return \"alt\";\n  if (t === \"escape\") return \"esc\";\n  if (t === \"return\") return \"enter\";\n  return t;\n}\n\nexport function Kbd({ combo, children, variant = \"raised\", size = \"md\", theme = \"dark\", separator = false, listen = false, className }: KbdProps) {\n  const mac = React.useSyncExternalStore(subscribe, getMac, () => false);\n  const p = PALETTES[theme];\n  const v = p[variant];\n  const s = SIZES[size];\n  const tokens = combo ? combo.split(\"+\").map((t) => t.trim()).filter(Boolean) : [];\n  const [pressed, setPressed] = React.useState<Set<string>>(() => new Set());\n\n  React.useEffect(() => {\n    if (!listen) return;\n    const down = (e: KeyboardEvent) => setPressed((prev) => new Set(prev).add(eventToken(e)));\n    const up = (e: KeyboardEvent) =>\n      setPressed((prev) => {\n        const next = new Set(prev);\n        next.delete(eventToken(e));\n        return next;\n      });\n    const clear = () => setPressed(new Set());\n    window.addEventListener(\"keydown\", down);\n    window.addEventListener(\"keyup\", up);\n    window.addEventListener(\"blur\", clear);\n    return () => {\n      window.removeEventListener(\"keydown\", down);\n      window.removeEventListener(\"keyup\", up);\n      window.removeEventListener(\"blur\", clear);\n    };\n  }, [listen]);\n\n  const cap = (label: React.ReactNode, isPressed: boolean, key: string) => (\n    <kbd\n      key={key}\n      className=\"inline-flex items-center justify-center font-semibold select-none\"\n      style={{\n        minWidth: s.height,\n        height: s.height,\n        padding: `0 ${s.padX}px`,\n        borderRadius: s.radius,\n        fontSize: s.font,\n        fontFamily: \"Inter, ui-sans-serif, system-ui, sans-serif\",\n        lineHeight: 1,\n        color: p.text,\n        background: isPressed ? p.pressedBg : v.bg,\n        border: `1px solid ${v.border}`,\n        boxShadow: isPressed ? v.pressedShadow : v.shadow,\n        transform: isPressed ? \"translateY(2px)\" : \"translateY(0)\",\n        transition: \"transform 0.08s ease, box-shadow 0.08s ease, background 0.08s ease\",\n      }}\n    >\n      {label}\n    </kbd>\n  );\n\n  if (tokens.length === 0) {\n    return <span className={cn(\"inline-flex\", className)}>{cap(children, false, \"single\")}</span>;\n  }\n\n  return (\n    <span className={cn(\"inline-flex items-center\", className)} style={{ gap: separator ? 6 : 4 }} aria-label={tokens.join(\" + \")}>\n      {tokens.map((token, i) => (\n        <React.Fragment key={`${token}-${i}`}>\n          {cap(labelFor(token, mac), listen && pressed.has(normalizeToken(token, mac)), `${token}-${i}`)}\n          {separator && i < tokens.length - 1 && (\n            <span aria-hidden=\"true\" style={{ color: p.muted, fontSize: s.font, fontFamily: \"Inter, sans-serif\" }}>\n              +\n            </span>\n          )}\n        </React.Fragment>\n      ))}\n    </span>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}