{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "keyboard",
  "title": "Keyboard",
  "author": "VenusUI",
  "description": "A compact Mac-style keyboard whose keys press down when clicked, light up as you type on your own keyboard, and can sound like a mechanical keyboard.",
  "dependencies": [
    "lucide-react"
  ],
  "files": [
    {
      "path": "registry/default/ui/keyboard.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport {\n  FastForward,\n  Globe,\n  LayoutGrid,\n  Mic,\n  Moon,\n  Play,\n  Rewind,\n  Search,\n  Sun,\n  SunDim,\n  Volume1,\n  Volume2,\n  VolumeX,\n  type LucideIcon,\n} from \"lucide-react\"\n\nimport { cn } from \"@/lib/utils\"\n\n/** What `onKeyPress` receives. */\nexport interface KeyboardKeyPress {\n  /** The `KeyboardEvent.code` of the key, e.g. `\"KeyA\"` or `\"MetaLeft\"`. */\n  code: string\n  /** Human-readable name, e.g. `\"A\"` or `\"Command\"`. */\n  name: string\n  /**\n   * `click`: an on-screen key was clicked, tapped, or activated with Enter or\n   * Space while focused. `keyboard`: the key was typed on a real keyboard.\n   */\n  source: \"click\" | \"keyboard\"\n}\n\ntype Legend =\n  | { kind: \"char\"; main: string }\n  | { kind: \"pair\"; shift: string; main: string }\n  | { kind: \"word\"; word: string; align: \"left\" | \"right\" }\n  | { kind: \"mod\"; symbol: string; word: string }\n  | { kind: \"fn\"; icon: LucideIcon; label: string }\n  | { kind: \"globe\" }\n  | { kind: \"touch\" }\n  | { kind: \"arrow\"; dir: \"up\" | \"down\" | \"left\" | \"right\" }\n  | { kind: \"blank\" }\n\ninterface KeyDef {\n  code: string\n  name: string\n  /** Width in key units (a letter key is 1). */\n  w?: number\n  legend: Legend\n}\n\nconst char = (code: string, main: string): KeyDef => ({ code, name: main, legend: { kind: \"char\", main } })\nconst pair = (code: string, shift: string, main: string, name = main): KeyDef => ({\n  code,\n  name,\n  legend: { kind: \"pair\", shift, main },\n})\nconst fnKey = (n: number, icon: LucideIcon): KeyDef => ({ code: `F${n}`, name: `F${n}`, legend: { kind: \"fn\", icon, label: `F${n}` } })\nconst mod = (code: string, name: string, symbol: string, w = 1): KeyDef => ({\n  code,\n  name,\n  w,\n  legend: { kind: \"mod\", symbol, word: name.toLowerCase() },\n})\n\n/** A compact Mac layout. Every row adds up to 14.5 key units. */\nconst ROWS: KeyDef[][] = [\n  [\n    { code: \"Escape\", name: \"Escape\", w: 1.5, legend: { kind: \"word\", word: \"esc\", align: \"left\" } },\n    fnKey(1, SunDim),\n    fnKey(2, Sun),\n    fnKey(3, LayoutGrid),\n    fnKey(4, Search),\n    fnKey(5, Mic),\n    fnKey(6, Moon),\n    fnKey(7, Rewind),\n    fnKey(8, Play),\n    fnKey(9, FastForward),\n    fnKey(10, VolumeX),\n    fnKey(11, Volume1),\n    fnKey(12, Volume2),\n    { code: \"TouchID\", name: \"Touch ID\", legend: { kind: \"touch\" } },\n  ],\n  [\n    pair(\"Backquote\", \"~\", \"`\", \"Backtick\"),\n    pair(\"Digit1\", \"!\", \"1\"),\n    pair(\"Digit2\", \"@\", \"2\"),\n    pair(\"Digit3\", \"#\", \"3\"),\n    pair(\"Digit4\", \"$\", \"4\"),\n    pair(\"Digit5\", \"%\", \"5\"),\n    pair(\"Digit6\", \"^\", \"6\"),\n    pair(\"Digit7\", \"&\", \"7\"),\n    pair(\"Digit8\", \"*\", \"8\"),\n    pair(\"Digit9\", \"(\", \"9\"),\n    pair(\"Digit0\", \")\", \"0\"),\n    pair(\"Minus\", \"_\", \"-\", \"Minus\"),\n    pair(\"Equal\", \"+\", \"=\", \"Equals\"),\n    { code: \"Backspace\", name: \"Delete\", w: 1.5, legend: { kind: \"word\", word: \"delete\", align: \"right\" } },\n  ],\n  [\n    { code: \"Tab\", name: \"Tab\", w: 1.5, legend: { kind: \"word\", word: \"tab\", align: \"left\" } },\n    ...\"QWERTYUIOP\".split(\"\").map((l) => char(`Key${l}`, l)),\n    pair(\"BracketLeft\", \"{\", \"[\", \"Left bracket\"),\n    pair(\"BracketRight\", \"}\", \"]\", \"Right bracket\"),\n    pair(\"Backslash\", \"|\", \"\\\\\", \"Backslash\"),\n  ],\n  [\n    { code: \"CapsLock\", name: \"Caps Lock\", w: 1.75, legend: { kind: \"word\", word: \"caps lock\", align: \"left\" } },\n    ...\"ASDFGHJKL\".split(\"\").map((l) => char(`Key${l}`, l)),\n    pair(\"Semicolon\", \":\", \";\", \"Semicolon\"),\n    pair(\"Quote\", '\"', \"'\", \"Quote\"),\n    { code: \"Enter\", name: \"Return\", w: 1.75, legend: { kind: \"word\", word: \"return\", align: \"right\" } },\n  ],\n  [\n    { code: \"ShiftLeft\", name: \"Shift\", w: 2.25, legend: { kind: \"word\", word: \"shift\", align: \"left\" } },\n    ...\"ZXCVBNM\".split(\"\").map((l) => char(`Key${l}`, l)),\n    pair(\"Comma\", \"<\", \",\", \"Comma\"),\n    pair(\"Period\", \">\", \".\", \"Period\"),\n    pair(\"Slash\", \"?\", \"/\", \"Slash\"),\n    { code: \"ShiftRight\", name: \"Right Shift\", w: 2.25, legend: { kind: \"word\", word: \"shift\", align: \"right\" } },\n  ],\n]\n\nconst BOTTOM_LEFT: KeyDef[] = [\n  { code: \"Fn\", name: \"Function\", legend: { kind: \"globe\" } },\n  mod(\"ControlLeft\", \"Control\", \"⌃\"),\n  mod(\"AltLeft\", \"Option\", \"⌥\"),\n  mod(\"MetaLeft\", \"Command\", \"⌘\", 1.25),\n  { code: \"Space\", name: \"Space\", w: 5, legend: { kind: \"blank\" } },\n  mod(\"MetaRight\", \"Command\", \"⌘\", 1.25),\n  mod(\"AltRight\", \"Option\", \"⌥\"),\n]\n\nconst ARROWS = {\n  left: { code: \"ArrowLeft\", name: \"Left arrow\", legend: { kind: \"arrow\", dir: \"left\" } },\n  up: { code: \"ArrowUp\", name: \"Up arrow\", legend: { kind: \"arrow\", dir: \"up\" } },\n  down: { code: \"ArrowDown\", name: \"Down arrow\", legend: { kind: \"arrow\", dir: \"down\" } },\n  right: { code: \"ArrowRight\", name: \"Right arrow\", legend: { kind: \"arrow\", dir: \"right\" } },\n} satisfies Record<string, KeyDef>\n\n/** Keys a real keyboard reports that this layout shows once. */\nconst ALIASES: Record<string, string> = { ControlRight: \"ControlLeft\", OSLeft: \"MetaLeft\", OSRight: \"MetaRight\" }\n\nconst SIZES = new Map<string, KeySize>(\n  [...ROWS.flat(), ...BOTTOM_LEFT].map((k) => [k.code, (k.w ?? 1) >= 5 ? \"space\" : (k.w ?? 1) >= 1.5 ? \"wide\" : \"normal\"])\n)\n\nconst NAMES = new Map([...ROWS.flat(), ...BOTTOM_LEFT, ...Object.values(ARROWS)].map((k) => [k.code, k.name]))\n\n/** Width of a key `w` units wide, including the gaps it spans. */\nconst width = (w = 1) => `calc(var(--u) * ${w} + var(--g) * ${w - 1})`\n\nfunction Triangle({ dir }: { dir: \"up\" | \"down\" | \"left\" | \"right\" }) {\n  const rotate = { up: 0, right: 90, down: 180, left: 270 }[dir]\n  return (\n    <svg viewBox=\"0 0 10 10\" aria-hidden=\"true\" className=\"size-[calc(var(--u)*0.2)]\" style={{ transform: `rotate(${rotate}deg)` }}>\n      <path d=\"M5 2 9 8H1Z\" fill=\"currentColor\" />\n    </svg>\n  )\n}\n\nfunction KeyLegend({ legend, capsOn }: { legend: Legend; capsOn: boolean }) {\n  const corner = \"absolute text-[calc(var(--u)*0.19)] leading-none\"\n  switch (legend.kind) {\n    case \"char\":\n      return <span className=\"m-auto text-[calc(var(--u)*0.25)] leading-none\">{legend.main}</span>\n    case \"pair\":\n      return (\n        <span className=\"m-auto flex flex-col items-center gap-[calc(var(--u)*0.08)] text-[calc(var(--u)*0.21)] leading-none\">\n          <span>{legend.shift}</span>\n          <span>{legend.main}</span>\n        </span>\n      )\n    case \"word\":\n      return (\n        <>\n          {legend.word === \"caps lock\" ? (\n            <span\n              aria-hidden=\"true\"\n              className={cn(\n                \"absolute top-[calc(var(--u)*0.14)] left-[calc(var(--u)*0.16)] size-[calc(var(--u)*0.09)] rounded-full transition-colors\",\n                capsOn ? \"bg-emerald-500 shadow-[0_0_6px_1px_rgb(16_185_129/0.7)]\" : \"bg-neutral-300 dark:bg-neutral-600\"\n              )}\n            />\n          ) : null}\n          <span\n            className={cn(\n              corner,\n              \"bottom-[calc(var(--u)*0.14)]\",\n              legend.align === \"left\" ? \"left-[calc(var(--u)*0.16)]\" : \"right-[calc(var(--u)*0.16)]\"\n            )}\n          >\n            {legend.word}\n          </span>\n        </>\n      )\n    case \"mod\":\n      return (\n        <>\n          <span className={cn(corner, \"top-[calc(var(--u)*0.14)] left-[calc(var(--u)*0.16)]\")}>{legend.symbol}</span>\n          <span className={cn(corner, \"bottom-[calc(var(--u)*0.14)] left-[calc(var(--u)*0.16)]\")}>{legend.word}</span>\n        </>\n      )\n    case \"fn\": {\n      const Icon = legend.icon\n      return (\n        <span className=\"m-auto flex flex-col items-center gap-[calc(var(--u)*0.07)] text-[calc(var(--u)*0.18)] leading-none\">\n          <Icon aria-hidden=\"true\" className=\"size-[calc(var(--u)*0.2)]\" strokeWidth={1.75} />\n          {legend.label}\n        </span>\n      )\n    }\n    case \"globe\":\n      return (\n        <>\n          <span className={cn(corner, \"top-[calc(var(--u)*0.14)] left-[calc(var(--u)*0.16)]\")}>fn</span>\n          <Globe\n            aria-hidden=\"true\"\n            strokeWidth={1.75}\n            className=\"absolute bottom-[calc(var(--u)*0.13)] left-[calc(var(--u)*0.15)] size-[calc(var(--u)*0.22)]\"\n          />\n        </>\n      )\n    case \"touch\":\n      return <span aria-hidden=\"true\" className=\"m-auto size-[calc(var(--u)*0.52)] rounded-full ring-1 ring-neutral-300 dark:ring-neutral-600\" />\n    case \"arrow\":\n      return (\n        <span className=\"m-auto\">\n          <Triangle dir={legend.dir} />\n        </span>\n      )\n    default:\n      return null\n  }\n}\n\n/** Switch sounds: `thock` is a deep, muted linear switch; `clicky` a bright, crisp click switch. */\nexport type KeyboardSound = \"thock\" | \"clicky\"\n\n/** Key sizes sound different: long keys are deeper, and the space bar's stabilizers rattle. */\ntype KeySize = \"normal\" | \"wide\" | \"space\"\n\ninterface Burst {\n  /** Seconds after the key event. */\n  at: number\n  /** Seconds until the burst fades out. */\n  length: number\n  filter: BiquadFilterType\n  frequency: number\n  q?: number\n  gain: number\n}\n\ninterface Thump {\n  at: number\n  length: number\n  /** Pitch sweeps down from `from` to `to` Hz, like a keycap bottoming out. */\n  from: number\n  to: number\n  gain: number\n}\n\ninterface SoundShape {\n  bursts: Burst[]\n  thumps: Thump[]\n}\n\n/**\n * Each sound is filtered noise bursts (the click and the plastic body) plus\n * short pitch-dropping tones (the bottom-out thump).\n */\nconst SHAPES: Record<KeyboardSound, Record<\"down\" | \"up\", (size: KeySize) => SoundShape>> = {\n  thock: {\n    down: (size) => ({\n      bursts: [\n        { at: 0, length: 0.006, filter: \"highpass\", frequency: 4200, gain: 0.07 },\n        {\n          at: 0.002,\n          length: size === \"space\" ? 0.08 : 0.05,\n          filter: \"bandpass\",\n          frequency: size === \"normal\" ? 650 : size === \"wide\" ? 480 : 360,\n          q: 1.3,\n          gain: 0.42,\n        },\n        ...(size === \"space\" ? [{ at: 0.018, length: 0.02, filter: \"bandpass\" as const, frequency: 2200, q: 3, gain: 0.035 }] : []),\n      ],\n      thumps: [\n        {\n          at: 0.001,\n          length: size === \"space\" ? 0.1 : 0.06,\n          from: size === \"normal\" ? 240 : size === \"wide\" ? 180 : 150,\n          to: size === \"normal\" ? 105 : size === \"wide\" ? 80 : 62,\n          gain: 0.55,\n        },\n      ],\n    }),\n    up: (size) => ({\n      bursts: [{ at: 0, length: 0.028, filter: \"bandpass\", frequency: size === \"normal\" ? 1400 : 1100, q: 1.4, gain: 0.13 }],\n      thumps: [{ at: 0, length: 0.03, from: 420, to: 260, gain: 0.08 }],\n    }),\n  },\n  clicky: {\n    down: (size) => ({\n      bursts: [\n        { at: 0, length: 0.011, filter: \"highpass\", frequency: 3400, gain: 0.5 },\n        { at: 0.006, length: 0.008, filter: \"bandpass\", frequency: 5200, q: 1.5, gain: 0.28 },\n        {\n          at: 0.012,\n          length: size === \"space\" ? 0.05 : 0.035,\n          filter: \"bandpass\",\n          frequency: size === \"normal\" ? 1900 : size === \"wide\" ? 1400 : 1100,\n          q: 1.1,\n          gain: 0.3,\n        },\n        ...(size === \"space\" ? [{ at: 0.026, length: 0.02, filter: \"bandpass\" as const, frequency: 2600, q: 3, gain: 0.04 }] : []),\n      ],\n      thumps: [{ at: 0.012, length: 0.04, from: size === \"normal\" ? 320 : size === \"wide\" ? 240 : 190, to: size === \"space\" ? 100 : 150, gain: 0.22 }],\n    }),\n    up: () => ({\n      bursts: [\n        { at: 0, length: 0.01, filter: \"highpass\", frequency: 3000, gain: 0.32 },\n        { at: 0.004, length: 0.025, filter: \"bandpass\", frequency: 2300, q: 1.2, gain: 0.14 },\n      ],\n      thumps: [],\n    }),\n  },\n}\n\n/**\n * One shared audio engine for every keyboard on the page, created on the\n * first sound (browsers only allow audio after the user interacts).\n */\nlet audio: { context: AudioContext; noise: AudioBuffer; output: AudioNode } | null = null\n\nfunction getAudio() {\n  if (!audio) {\n    const context = new AudioContext({ latencyHint: \"interactive\" })\n    // One second of white noise, reused from random offsets.\n    const noise = context.createBuffer(1, context.sampleRate, context.sampleRate)\n    const data = noise.getChannelData(0)\n    for (let i = 0; i < data.length; i++) data[i] = Math.random() * 2 - 1\n    // A compressor keeps fast typing from clipping.\n    const compressor = context.createDynamicsCompressor()\n    compressor.threshold.value = -14\n    compressor.ratio.value = 4\n    const master = context.createGain()\n    master.gain.value = 3\n    compressor.connect(master).connect(context.destination)\n    audio = { context, noise, output: compressor }\n  }\n  if (audio.context.state === \"suspended\") void audio.context.resume()\n  return audio\n}\n\nfunction playKeySound(sound: KeyboardSound, phase: \"down\" | \"up\", size: KeySize) {\n  const { context, noise, output } = getAudio()\n  // Every press sounds slightly different, like a real board.\n  const pitch = 0.92 + Math.random() * 0.16\n  const level = 0.85 + Math.random() * 0.3\n  const now = context.currentTime + 0.002\n  const shape = SHAPES[sound][phase](size)\n\n  for (const b of shape.bursts) {\n    const start = now + b.at\n    const source = context.createBufferSource()\n    source.buffer = noise\n    const filter = context.createBiquadFilter()\n    filter.type = b.filter\n    filter.frequency.value = b.frequency * pitch\n    filter.Q.value = b.q ?? 0.7\n    const gain = context.createGain()\n    gain.gain.setValueAtTime(0.0001, start)\n    gain.gain.linearRampToValueAtTime(b.gain * level, start + 0.0008)\n    gain.gain.exponentialRampToValueAtTime(0.0001, start + b.length)\n    source.connect(filter).connect(gain).connect(output)\n    source.start(start, Math.random() * 0.9, b.length + 0.02)\n  }\n\n  for (const t of shape.thumps) {\n    const start = now + t.at\n    const oscillator = context.createOscillator()\n    oscillator.frequency.setValueAtTime(t.from * pitch, start)\n    oscillator.frequency.exponentialRampToValueAtTime(t.to * pitch, start + t.length)\n    const gain = context.createGain()\n    gain.gain.setValueAtTime(0.0001, start)\n    gain.gain.linearRampToValueAtTime(t.gain * level, start + 0.002)\n    gain.gain.exponentialRampToValueAtTime(0.0001, start + t.length)\n    oscillator.connect(gain).connect(output)\n    oscillator.start(start)\n    oscillator.stop(start + t.length + 0.02)\n  }\n}\n\n/** The key next to `from` in an arrow-key direction, judged by on-screen position. */\nfunction neighbor(from: HTMLElement, key: string, keys: HTMLElement[]) {\n  const a = from.getBoundingClientRect()\n  const ax = a.left + a.width / 2\n  const ay = a.top + a.height / 2\n  let best: HTMLElement | undefined\n  let bestScore = Infinity\n  for (const el of keys) {\n    if (el === from) continue\n    const r = el.getBoundingClientRect()\n    const dx = r.left + r.width / 2 - ax\n    const dy = r.top + r.height / 2 - ay\n    const along = key === \"ArrowRight\" ? dx : key === \"ArrowLeft\" ? -dx : key === \"ArrowDown\" ? dy : -dy\n    if (along <= 1) continue\n    const across = key === \"ArrowRight\" || key === \"ArrowLeft\" ? Math.abs(dy) : Math.abs(dx)\n    const score = along + across * 3\n    if (score < bestScore) {\n      bestScore = score\n      best = el\n    }\n  }\n  return best\n}\n\nexport interface KeyboardProps extends Omit<React.ComponentProps<\"div\">, \"onKeyPress\"> {\n  /** Called for every key press, from a click or tap or from the user's real keyboard. */\n  onKeyPress?: (key: KeyboardKeyPress) => void\n  /** Light up keys as they are pressed on the user's real keyboard. */\n  listen?: boolean\n  /**\n   * Play a mechanical keyboard sound on each press and release: `\"thock\"`\n   * (deep, linear switches; also what `true` plays) or `\"clicky\"` (bright\n   * click switches). Off by default.\n   */\n  sound?: boolean | KeyboardSound\n}\n\n/**\n * A compact keyboard whose keys press down when clicked or tapped, and light\n * up as you type on your own keyboard. It scales to its container's width.\n * Keys are real buttons: Tab moves into the keyboard, the arrow keys move\n * between keys, and Enter or Space presses the focused key.\n */\nexport function Keyboard({ onKeyPress, listen = true, sound = false, className, style, ...props }: KeyboardProps) {\n  const [pressed, setPressed] = React.useState<ReadonlySet<string>>(() => new Set())\n  const [capsOn, setCapsOn] = React.useState(false)\n  const [focusCode, setFocusCode] = React.useState(\"Escape\")\n  const groupRef = React.useRef<HTMLDivElement>(null)\n  const profile: KeyboardSound | null = sound === true ? \"thock\" : sound || null\n  const playSound = React.useCallback(\n    (code: string, phase: \"down\" | \"up\") => {\n      if (profile) playKeySound(profile, phase, SIZES.get(code) ?? \"normal\")\n    },\n    [profile]\n  )\n  const onKeyPressRef = React.useRef(onKeyPress)\n\n  React.useEffect(() => {\n    onKeyPressRef.current = onKeyPress\n  }, [onKeyPress])\n\n  const press = React.useCallback((code: string) => setPressed((all) => new Set(all).add(code)), [])\n  const release = React.useCallback(\n    (code: string) =>\n      setPressed((all) => {\n        if (!all.has(code)) return all\n        const next = new Set(all)\n        next.delete(code)\n        return next\n      }),\n    []\n  )\n\n  // The user's real keyboard.\n  React.useEffect(() => {\n    if (!listen) return\n    // Presses inside the component are arrow navigation or activating a\n    // focused key; the key's own click handler reports those.\n    const inside = (event: KeyboardEvent) => event.target instanceof Node && Boolean(groupRef.current?.contains(event.target))\n    const onDown = (event: KeyboardEvent) => {\n      if (inside(event)) return\n      const code = ALIASES[event.code] ?? event.code\n      if (!NAMES.has(code)) return\n      if (!event.repeat) {\n        playSound(code, \"down\")\n        onKeyPressRef.current?.({ code, name: NAMES.get(code) ?? code, source: \"keyboard\" })\n      }\n      press(code)\n      setCapsOn(event.getModifierState?.(\"CapsLock\") ?? false)\n    }\n    const onUp = (event: KeyboardEvent) => {\n      const code = ALIASES[event.code] ?? event.code\n      if (!inside(event) && NAMES.has(code)) playSound(code, \"up\")\n      // While ⌘ is held, macOS doesn't send keyup for other keys: clear them all.\n      if (code === \"MetaLeft\" || code === \"MetaRight\") setPressed(new Set())\n      else release(code)\n      setCapsOn(event.getModifierState?.(\"CapsLock\") ?? false)\n    }\n    const clear = () => setPressed(new Set())\n    window.addEventListener(\"keydown\", onDown)\n    window.addEventListener(\"keyup\", onUp)\n    window.addEventListener(\"blur\", clear)\n    return () => {\n      window.removeEventListener(\"keydown\", onDown)\n      window.removeEventListener(\"keyup\", onUp)\n      window.removeEventListener(\"blur\", clear)\n    }\n  }, [listen, playSound, press, release])\n\n  const onArrowNavigate = (event: React.KeyboardEvent<HTMLDivElement>) => {\n    if (![\"ArrowLeft\", \"ArrowRight\", \"ArrowUp\", \"ArrowDown\"].includes(event.key)) return\n    const from = event.target\n    if (!(from instanceof HTMLElement) || !from.dataset.code) return\n    const keys = [...(groupRef.current?.querySelectorAll<HTMLElement>(\"[data-code]\") ?? [])]\n    const next = neighbor(from, event.key, keys)\n    if (!next) return\n    event.preventDefault()\n    next.focus()\n  }\n\n  const renderKey = (key: KeyDef, height = \"var(--u)\") => {\n    const isPressed = pressed.has(key.code)\n    return (\n      <button\n        key={key.code}\n        type=\"button\"\n        data-code={key.code}\n        data-pressed={isPressed || undefined}\n        aria-label={key.name}\n        aria-pressed={key.code === \"CapsLock\" ? capsOn : undefined}\n        tabIndex={focusCode === key.code ? 0 : -1}\n        onFocus={() => setFocusCode(key.code)}\n        onPointerDown={() => {\n          press(key.code)\n          playSound(key.code, \"down\")\n        }}\n        onPointerUp={() => {\n          if (pressed.has(key.code)) playSound(key.code, \"up\")\n          release(key.code)\n        }}\n        onPointerLeave={() => {\n          if (pressed.has(key.code)) playSound(key.code, \"up\")\n          release(key.code)\n        }}\n        onPointerCancel={() => release(key.code)}\n        onClick={(event) => {\n          if (key.code === \"CapsLock\") setCapsOn((on) => !on)\n          // Activated with Enter or Space while focused: show a brief press.\n          if (event.detail === 0) {\n            press(key.code)\n            playSound(key.code, \"down\")\n            setTimeout(() => {\n              release(key.code)\n              playSound(key.code, \"up\")\n            }, 110)\n          }\n          onKeyPress?.({ code: key.code, name: key.name, source: \"click\" })\n        }}\n        className={cn(\n          \"relative flex shrink-0 cursor-pointer rounded-[calc(var(--u)*0.15)] text-neutral-700 outline-none select-none\",\n          \"bg-linear-to-b from-white to-neutral-50 shadow-[0_0_0_1px_rgb(0_0_0/0.07),0_1.5px_0_rgb(0_0_0/0.13),0_3px_4px_-2px_rgb(0_0_0/0.2)]\",\n          \"transition-[translate,box-shadow,background-color] duration-75 hover:from-neutral-50 motion-reduce:transition-none\",\n          \"focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-1\",\n          \"data-pressed:translate-y-[1.5px] data-pressed:from-neutral-100 data-pressed:to-neutral-100 data-pressed:shadow-[0_0_0_1px_rgb(0_0_0/0.08),inset_0_1px_2px_rgb(0_0_0/0.14)]\",\n          \"dark:from-neutral-700 dark:to-neutral-800 dark:text-neutral-200 dark:shadow-[0_0_0_1px_rgb(255_255_255/0.06),0_1.5px_0_rgb(0_0_0/0.7),0_3px_5px_-2px_rgb(0_0_0/0.6)] dark:hover:from-neutral-600\",\n          \"dark:data-pressed:from-neutral-800 dark:data-pressed:to-neutral-800 dark:data-pressed:shadow-[0_0_0_1px_rgb(255_255_255/0.05),inset_0_1px_3px_rgb(0_0_0/0.6)]\"\n        )}\n        style={{ width: width(key.w), height }}\n      >\n        <KeyLegend legend={key.legend} capsOn={capsOn} />\n      </button>\n    )\n  }\n\n  const half = \"calc((var(--u) - var(--g)) / 2)\"\n\n  return (\n    <div data-slot=\"keyboard\" className={cn(\"@container w-full\", className)} style={style} {...props}>\n      <div\n        ref={groupRef}\n        role=\"group\"\n        aria-label=\"Keyboard\"\n        onKeyDown={onArrowNavigate}\n        className=\"mx-auto flex w-fit flex-col gap-(--g) rounded-[calc(var(--u)*0.45)] bg-neutral-200 p-(--p) shadow-[inset_0_1px_0_rgb(255_255_255/0.7),0_0_0_1px_rgb(0_0_0/0.06),0_24px_48px_-24px_rgb(0_0_0/0.35)] dark:bg-neutral-900 dark:shadow-[inset_0_1px_0_rgb(255_255_255/0.06),0_0_0_1px_rgb(255_255_255/0.08),0_24px_48px_-24px_rgb(0_0_0/0.8)]\"\n        style={\n          {\n            \"--u\": \"min(6.15cqw, 3.25rem)\",\n            \"--g\": \"calc(var(--u) * 0.09)\",\n            \"--p\": \"calc(var(--u) * 0.22)\",\n          } as React.CSSProperties\n        }\n      >\n        {ROWS.map((row, i) => (\n          <div key={i} className=\"flex gap-(--g)\">\n            {row.map((key) => renderKey(key, i === 0 ? \"calc(var(--u) * 0.82)\" : undefined))}\n          </div>\n        ))}\n        <div className=\"flex gap-(--g)\">\n          {BOTTOM_LEFT.map((key) => renderKey(key))}\n          <div className=\"flex items-end gap-(--g)\">\n            {renderKey(ARROWS.left)}\n            <div className=\"flex flex-col gap-(--g)\">\n              {renderKey(ARROWS.up, half)}\n              {renderKey(ARROWS.down, half)}\n            </div>\n            {renderKey(ARROWS.right)}\n          </div>\n        </div>\n      </div>\n    </div>\n  )\n}\n",
      "type": "registry:ui"
    }
  ],
  "meta": {
    "version": "0.2.0"
  },
  "categories": [
    "interactive",
    "data-display"
  ],
  "type": "registry:ui"
}