{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"shortcut-sheet","type":"registry:component","title":"Shortcut sheet","description":"A searchable keyboard shortcuts reference and modal with live physical keycap lighting, chord and sequence matching and OS-aware glyphs.","author":"Hairline UI","dependencies":["lucide-react"],"registryDependencies":["https://hairlineui.com/r/text-morph.json?as=dependency","https://hairlineui.com/r/number-roll.json?as=dependency"],"files":[{"path":"registry/shortcut-sheet.tsx","type":"registry:component","content":"// Hairline UI · shortcut-sheet · MIT License\n// Copyright (c) 2026 Hairline UI · https://hairlineui.com/license#components\n\n\"use client\";\n\nimport * as React from \"react\";\nimport { Check, Keyboard, Search, X } from \"lucide-react\";\nimport {\n  INTERACTION_FOCUS,\n  INTERACTION_PRESS,\n  useInteractionReducedMotion,\n} from \"./ui-interaction-motion\";\nimport { NumberRoll } from \"./number-roll\";\nimport { TextMorph } from \"./text-morph\";\nimport { playSound } from \"./ui-sounds\";\n\n/* ─────────────────────────────────────────────────────────\n * SHORTCUT SHEET: searchable keyboard map & live key trainer\n *\n *   live      while the sheet is open or active, pressing real\n *             keys on your keyboard physically depresses and\n *             illuminates matching <kbd> keycaps across the grid;\n *             completing a chord or two-key sequence (e.g. G then I)\n *             highlights that exact command row in real time\n *\n *   format    shares ShortcutRecorder's canonical syntax (\"mod+k\",\n *             \"mod+shift+p\", \"g then i\", \"/\") with automatic macOS\n *             (⌘ ⌥ ⇧ ⌃) vs Windows/Linux (Ctrl Alt Shift) glyphs\n *\n *   modes     renders either inline inside Settings/Help screens\n *             or as a hairline modal overlay toggled by global \"?\"\n * ───────────────────────────────────────────────────────── */\n\nexport type ShortcutSheetPlatform = \"auto\" | \"mac\" | \"other\";\n\nexport interface ShortcutEntry {\n  /** Stable identifier for the command (e.g. \"open-command-menu\"). */\n  id: string;\n  /** Human-readable command label (e.g. \"Open command menu\"). */\n  label: string;\n  /** Canonical shortcut string: chord (\"mod+k\", \"mod+shift+p\") or sequence (\"g then i\", \"g then p\"). */\n  keys: string;\n  /** Optional subtle secondary note or category hint. */\n  description?: string;\n  /** Optional custom search keywords. */\n  keywords?: string[];\n}\n\nexport interface ShortcutGroup {\n  /** Section heading (e.g. \"Navigation\", \"Editor\", \"Actions\"). */\n  title: string;\n  /** Shortcuts inside this section. */\n  items: ShortcutEntry[];\n}\n\nexport interface ShortcutSheetProps extends Omit<React.HTMLAttributes<HTMLDivElement>, \"onSelect\"> {\n  /** Grouped keyboard shortcuts to display. */\n  groups: ShortcutGroup[];\n  /** Presentation mode: embedded hairline card or global-hotkey dialog overlay. */\n  variant?: \"inline\" | \"dialog\";\n  /** Controlled open state (dialog variant only). */\n  open?: boolean;\n  /** Initial uncontrolled open state (dialog variant, default false). */\n  defaultOpen?: boolean;\n  /** Called when dialog opens or closes. */\n  onOpenChange?: (open: boolean) => void;\n  /** Global single key that toggles the dialog when not typing in an input (default \"?\"; pass null to disable). */\n  hotkey?: string | null;\n  /** Enable real-time physical keyboard keycap lighting & chord matching (default true). */\n  liveKeys?: boolean;\n  /** Called when a user clicks a shortcut row or completes its chord in liveKeys mode. */\n  onTrigger?: (entry: ShortcutEntry) => void;\n  /** OS glyph rendering mode (default \"auto\"). */\n  platform?: ShortcutSheetPlatform;\n  /** Show quick search bar (default true). */\n  searchable?: boolean;\n  /** Sheet title (default \"Keyboard shortcuts\"). */\n  title?: string;\n  /** Opt-in quiet Web Audio ticks when live keys match (from ui-sounds.ts). */\n  sound?: boolean;\n}\n\nconst noopSubscribe = () => () => {};\nfunction useDetectedPlatform(): \"mac\" | \"other\" {\n  return React.useSyncExternalStore(\n    noopSubscribe,\n    () => {\n      if (typeof navigator === \"undefined\") return \"mac\";\n      const nav = navigator as Navigator & { userAgentData?: { platform?: string } };\n      const plat = (nav.userAgentData?.platform ?? navigator.platform ?? navigator.userAgent ?? \"\").toLowerCase();\n      return plat.includes(\"mac\") || plat.includes(\"iphone\") || plat.includes(\"ipad\") ? \"mac\" : \"other\";\n    },\n    () => \"mac\",\n  );\n}\n\ninterface ParsedStep {\n  /** Normalized tokens like [\"mod\", \"shift\", \"p\"] or [\"g\"]. */\n  tokens: string[];\n}\n\n/** Parse \"mod+shift+p\" or \"g then i\" into steps of normalized lowercase tokens. */\nexport function parseShortcutSpec(spec: string): ParsedStep[] {\n  return spec\n    .trim()\n    .toLowerCase()\n    .split(/\\s+then\\s+/i)\n    .map((step) => ({\n      tokens: step\n        .split(\"+\")\n        .map((t) => normalizeToken(t.trim()))\n        .filter(Boolean),\n    }))\n    .filter((s) => s.tokens.length > 0);\n}\n\nfunction normalizeToken(raw: string): string {\n  switch (raw) {\n    case \"cmd\":\n    case \"command\":\n    case \"meta\":\n    case \"cmdorctrl\":\n    case \"commandorcontrol\":\n      return \"mod\";\n    case \"control\":\n      return \"ctrl\";\n    case \"option\":\n    case \"opt\":\n      return \"alt\";\n    case \"escape\":\n      return \"esc\";\n    case \"return\":\n      return \"enter\";\n    case \"arrowup\":\n    case \"up\":\n      return \"up\";\n    case \"arrowdown\":\n    case \"down\":\n      return \"down\";\n    case \"arrowleft\":\n    case \"left\":\n      return \"left\";\n    case \"arrowright\":\n    case \"right\":\n      return \"right\";\n    case \" \":\n      return \"space\";\n    default:\n      return raw;\n  }\n}\n\nfunction eventToPrimaryToken(e: KeyboardEvent): string | null {\n  const k = e.key.toLowerCase();\n  if (k === \"meta\" || k === \"control\" || k === \"alt\" || k === \"shift\") return null;\n  if (k === \" \") return \"space\";\n  if (k === \"escape\") return \"esc\";\n  if (k === \"enter\") return \"enter\";\n  if (k === \"backspace\") return \"backspace\";\n  if (k === \"tab\") return \"tab\";\n  if (k === \"arrowup\") return \"up\";\n  if (k === \"arrowdown\") return \"down\";\n  if (k === \"arrowleft\") return \"left\";\n  if (k === \"arrowright\") return \"right\";\n  if (k.length === 1) return k;\n  return k;\n}\n\nfunction formatKeyToken(token: string, resolvedPlatform: \"mac\" | \"other\"): string {\n  const isMac = resolvedPlatform === \"mac\";\n  switch (token) {\n    case \"mod\":\n      return isMac ? \"⌘\" : \"Ctrl\";\n    case \"ctrl\":\n      return isMac ? \"⌃\" : \"Ctrl\";\n    case \"alt\":\n      return isMac ? \"⌥\" : \"Alt\";\n    case \"shift\":\n      return isMac ? \"⇧\" : \"Shift\";\n    case \"enter\":\n      return \"↵\";\n    case \"esc\":\n      return \"Esc\";\n    case \"space\":\n      return \"Space\";\n    case \"backspace\":\n      return \"⌫\";\n    case \"tab\":\n      return \"⇥\";\n    case \"up\":\n      return \"↑\";\n    case \"down\":\n      return \"↓\";\n    case \"left\":\n      return \"←\";\n    case \"right\":\n      return \"→\";\n    default:\n      return token.length === 1 ? token.toUpperCase() : token[0].toUpperCase() + token.slice(1);\n  }\n}\n\nfunction isEditableElement(target: EventTarget | null): boolean {\n  if (!(target instanceof HTMLElement)) return false;\n  const tag = target.tagName;\n  if (tag === \"INPUT\" || tag === \"TEXTAREA\" || tag === \"SELECT\") return true;\n  return target.isContentEditable;\n}\n\nfunction Keycap({\n  label,\n  pressed,\n  matched,\n  reduced,\n}: {\n  label: string;\n  pressed: boolean;\n  matched: boolean;\n  reduced: boolean;\n}) {\n  return (\n    <kbd\n      data-pressed={pressed ? \"true\" : \"false\"}\n      className={`inline-flex h-6 min-w-[24px] select-none items-center justify-center rounded-[6px] border px-1.5 font-mono text-[11px] font-medium leading-none ${\n        reduced ? \"\" : \"transition-[transform,background-color,border-color,color,box-shadow] duration-100\"\n      } ${\n        matched\n          ? \"translate-y-[1px] border-emerald-500/50 bg-emerald-500/15 text-emerald-700 shadow-none dark:text-emerald-300\"\n          : pressed\n            ? \"translate-y-[1px] border-foreground/45 bg-foreground text-background shadow-none\"\n            : \"border-border bg-background text-foreground shadow-[0_1.5px_0_var(--border),inset_0_0.5px_0_rgb(255_255_255/0.75)] dark:shadow-[0_1.5px_0_rgb(0_0_0/0.65),inset_0_0.5px_0_rgb(255_255_255/0.07)]\"\n      }`}\n    >\n      {label}\n    </kbd>\n  );\n}\n\ninterface SheetContentProps {\n  groups: ShortcutGroup[];\n  title: string;\n  searchable: boolean;\n  liveKeys: boolean;\n  resolvedPlatform: \"mac\" | \"other\";\n  reduced: boolean;\n  isDialog: boolean;\n  sound: boolean;\n  onClose?: () => void;\n  onTrigger?: (entry: ShortcutEntry) => void;\n}\n\nfunction SheetSurface({\n  groups,\n  title,\n  searchable,\n  liveKeys,\n  resolvedPlatform,\n  reduced,\n  isDialog,\n  sound,\n  onClose,\n  onTrigger,\n}: SheetContentProps) {\n  const [query, setQuery] = React.useState(\"\");\n  const [pressedTokens, setPressedTokens] = React.useState<Set<string>>(() => new Set());\n  const [matchedId, setMatchedId] = React.useState<string | null>(null);\n  const [liveStatus, setLiveStatus] = React.useState(\"\");\n\n  const searchRef = React.useRef<HTMLInputElement | null>(null);\n  const seqPrefixRef = React.useRef<{ token: string; ts: number } | null>(null);\n  const matchTimerRef = React.useRef(0);\n\n  React.useEffect(\n    () => () => {\n      window.clearTimeout(matchTimerRef.current);\n    },\n    [],\n  );\n\n  // Pre-parse every shortcut spec once per groups update\n  const parsedGroups = React.useMemo(\n    () =>\n      groups.map((g) => ({\n        ...g,\n        entries: g.items.map((item) => ({\n          item,\n          steps: parseShortcutSpec(item.keys),\n        })),\n      })),\n    [groups],\n  );\n\n  const flatEntries = React.useMemo(() => parsedGroups.flatMap((g) => g.entries), [parsedGroups]);\n\n  const filteredGroups = React.useMemo(() => {\n    const q = query.trim().toLowerCase();\n    if (!q) return parsedGroups;\n    return parsedGroups\n      .map((g) => ({\n        ...g,\n        entries: g.entries.filter(({ item }) => {\n          const hay = [g.title, item.label, item.description ?? \"\", item.keys, ...(item.keywords ?? [])]\n            .join(\" \")\n            .toLowerCase();\n          return hay.includes(q);\n        }),\n      }))\n      .filter((g) => g.entries.length > 0);\n  }, [parsedGroups, query]);\n\n  const fireMatch = React.useCallback(\n    (entry: ShortcutEntry) => {\n      setMatchedId(entry.id);\n      setLiveStatus(`Matched shortcut: ${entry.label}`);\n      if (sound) playSound(\"tick\", 0.3);\n      onTrigger?.(entry);\n      window.clearTimeout(matchTimerRef.current);\n      matchTimerRef.current = window.setTimeout(() => setMatchedId(null), 1100);\n    },\n    [onTrigger, sound],\n  );\n\n  // Real-time physical keycap lighting & chord / sequence matching\n  React.useEffect(() => {\n    if (!liveKeys) return;\n\n    const getActiveMods = (e: KeyboardEvent) => {\n      const next = new Set<string>();\n      const modDown = resolvedPlatform === \"mac\" ? e.metaKey : e.ctrlKey;\n      if (modDown) next.add(\"mod\");\n      if (resolvedPlatform === \"mac\" && e.ctrlKey) next.add(\"ctrl\");\n      if (e.altKey) next.add(\"alt\");\n      if (e.shiftKey) next.add(\"shift\");\n      return next;\n    };\n\n    const onKeyDown = (e: KeyboardEvent) => {\n      if (isDialog && e.key === \"Escape\") {\n        e.preventDefault();\n        onClose?.();\n        return;\n      }\n\n      // Skip live keycap lighting while typing inside the search input (except Escape clearing search)\n      if (isEditableElement(e.target)) {\n        if (e.key === \"Escape\" && query) {\n          setQuery(\"\");\n        }\n        return;\n      }\n\n      const active = getActiveMods(e);\n      const primary = eventToPrimaryToken(e);\n      if (primary) active.add(primary);\n      setPressedTokens(active);\n\n      if (!primary) return;\n\n      const now = Date.now();\n      const hasMods = active.has(\"mod\") || active.has(\"ctrl\") || active.has(\"alt\") || active.has(\"shift\");\n\n      // Check two-key sequence match first (e.g. \"g then i\")\n      const prev = seqPrefixRef.current;\n      if (!hasMods && prev && now - prev.ts < 900) {\n        const seqHit = flatEntries.find(\n          ({ steps }) =>\n            steps.length === 2 &&\n            steps[0].tokens.length === 1 &&\n            steps[0].tokens[0] === prev.token &&\n            steps[1].tokens.length === 1 &&\n            steps[1].tokens[0] === primary,\n        );\n        if (seqHit) {\n          e.preventDefault();\n          seqPrefixRef.current = null;\n          fireMatch(seqHit.item);\n          return;\n        }\n      }\n\n      // Check single-step chord match (e.g. \"mod+k\", \"mod+shift+p\", \"/\", \"c\")\n      const chordHit = flatEntries.find(({ steps }) => {\n        if (steps.length !== 1) return false;\n        const req = steps[0].tokens;\n        if (req.length !== active.size) return false;\n        return req.every((t) => active.has(t));\n      });\n\n      if (chordHit) {\n        // Prevent browser hijacking chords like Cmd+K when practicing in the sheet\n        if (hasMods || primary === \"/\") e.preventDefault();\n        seqPrefixRef.current = null;\n        fireMatch(chordHit.item);\n        return;\n      }\n\n      // Record potential sequence prefix (e.g. pressing \"g\")\n      if (!hasMods) {\n        const isPrefix = flatEntries.some(\n          ({ steps }) => steps.length === 2 && steps[0].tokens.length === 1 && steps[0].tokens[0] === primary,\n        );\n        seqPrefixRef.current = isPrefix ? { token: primary, ts: now } : null;\n      } else {\n        seqPrefixRef.current = null;\n      }\n    };\n\n    const onKeyUp = (e: KeyboardEvent) => {\n      if (isEditableElement(e.target)) return;\n      setPressedTokens(getActiveMods(e));\n    };\n\n    const onBlur = () => setPressedTokens(new Set());\n\n    window.addEventListener(\"keydown\", onKeyDown);\n    window.addEventListener(\"keyup\", onKeyUp);\n    window.addEventListener(\"blur\", onBlur);\n    return () => {\n      window.removeEventListener(\"keydown\", onKeyDown);\n      window.removeEventListener(\"keyup\", onKeyUp);\n      window.removeEventListener(\"blur\", onBlur);\n    };\n  }, [liveKeys, isDialog, onClose, resolvedPlatform, flatEntries, fireMatch, query]);\n\n  const visibleCount = filteredGroups.reduce((acc, g) => acc + g.entries.length, 0);\n  const liveKeyText =\n    pressedTokens.size > 0\n      ? Array.from(pressedTokens)\n          .map((t) => formatKeyToken(t, resolvedPlatform))\n          .join(\" + \")\n      : \"Press any key to test\";\n\n  return (\n    <div\n      role=\"region\"\n      aria-label={title}\n      data-live-keys={liveKeys ? \"true\" : \"false\"}\n      data-matched-id={matchedId ?? \"\"}\n      className=\"@container flex w-full flex-col overflow-hidden rounded-[16px] border border-border bg-card text-card-foreground shadow-[inset_0_0.5px_0_rgb(255_255_255/0.75)] dark:shadow-[inset_0_0.5px_0_rgb(255_255_255/0.06)]\"\n    >\n      {/* Header */}\n      <div className=\"flex flex-wrap items-center justify-between gap-2 border-b border-border/80 bg-muted/20 px-4 py-3\">\n        <div className=\"flex items-center gap-2\">\n          <Keyboard className=\"size-4 text-muted-foreground\" strokeWidth={1.9} />\n          <span className=\"text-[13px] font-medium tracking-[-0.01em] text-foreground\">{title}</span>\n          <span className=\"font-mono text-[11px] tabular-nums text-muted-foreground\">\n            <NumberRoll value={visibleCount} duration={420} />\n          </span>\n        </div>\n\n        <div className=\"flex items-center gap-2\">\n          {liveKeys && (\n            <span className=\"hidden items-center gap-1.5 rounded-full border border-border/80 bg-background px-2 py-0.5 text-[10.5px] text-muted-foreground @[440px]:inline-flex\">\n              <span\n                className={`size-1.5 rounded-full transition-colors ${\n                  pressedTokens.size > 0 || matchedId ? \"bg-emerald-500\" : \"bg-muted-foreground/45\"\n                }`}\n              />\n              <TextMorph duration={320}>{liveKeyText}</TextMorph>\n            </span>\n          )}\n          {isDialog && onClose && (\n            <button\n              type=\"button\"\n              aria-label=\"Close shortcuts\"\n              onClick={onClose}\n              className={`inline-flex size-7 cursor-pointer items-center justify-center rounded-[8px] text-muted-foreground hover:bg-accent hover:text-foreground ${INTERACTION_PRESS} ${INTERACTION_FOCUS}`}\n            >\n              <X className=\"size-4\" strokeWidth={2} />\n            </button>\n          )}\n        </div>\n      </div>\n\n      {/* Optional live search filter */}\n      {searchable && (\n        <div className=\"flex items-center gap-2 border-b border-border/80 px-3.5 py-2\">\n          <Search className=\"size-3.5 shrink-0 text-muted-foreground\" strokeWidth={2} />\n          <input\n            ref={searchRef}\n            type=\"text\"\n            aria-label=\"Filter keyboard shortcuts\"\n            placeholder=\"Filter commands or keys…\"\n            value={query}\n            onChange={(e) => setQuery(e.currentTarget.value)}\n            className=\"h-6 min-w-0 flex-1 bg-transparent text-[12.5px] text-foreground placeholder:text-muted-foreground/55 focus:outline-none\"\n          />\n          {query && (\n            <button\n              type=\"button\"\n              aria-label=\"Clear filter\"\n              onClick={() => {\n                setQuery(\"\");\n                searchRef.current?.focus();\n              }}\n              className=\"inline-flex size-5 cursor-pointer items-center justify-center rounded-[5px] text-muted-foreground hover:bg-accent hover:text-foreground\"\n            >\n              <X className=\"size-3\" strokeWidth={2} />\n            </button>\n          )}\n        </div>\n      )}\n\n      {/* Two-column grouped hairline shortcut grid */}\n      <div className=\"max-h-[420px] overflow-y-auto p-4\">\n        {filteredGroups.length === 0 ? (\n          <div className=\"py-8 text-center text-[12.5px] text-muted-foreground\">\n            No shortcuts matching &ldquo;{query}&rdquo;\n          </div>\n        ) : (\n          <div className=\"grid grid-cols-1 gap-x-5 gap-y-5 md:grid-cols-2\">\n            {filteredGroups.map((group) => (\n              <div key={group.title} className=\"flex flex-col gap-1.5\">\n                <h3 className=\"px-2 text-[11px] font-medium uppercase tracking-[0.06em] text-muted-foreground\">\n                  {group.title}\n                </h3>\n                <div className=\"flex flex-col divide-y divide-border/50 rounded-[12px] border border-border/80 bg-background/50\">\n                  {group.entries.map(({ item, steps }) => {\n                    const isMatched = matchedId === item.id;\n                    return (\n                      <button\n                        key={item.id}\n                        type=\"button\"\n                        data-shortcut-row={item.id}\n                        data-matched={isMatched ? \"true\" : \"false\"}\n                        onClick={() => fireMatch(item)}\n                        className={`flex w-full cursor-pointer items-center justify-between gap-3 px-2.5 py-2 text-left transition-colors first:rounded-t-[11px] last:rounded-b-[11px] ${\n                          isMatched\n                            ? \"bg-emerald-500/[0.09]\"\n                            : \"hover:bg-accent/55\"\n                        } ${INTERACTION_FOCUS}`}\n                      >\n                        <span className=\"min-w-0\">\n                          <span className=\"flex items-center gap-1.5 text-[12.5px] text-foreground\">\n                            <span className=\"truncate\">{item.label}</span>\n                            {isMatched && (\n                              <span className=\"inline-flex shrink-0 items-center gap-0.5 rounded-full bg-emerald-500/15 px-1.5 py-0 text-[10px] font-medium text-emerald-700 dark:text-emerald-300\">\n                                <Check className=\"size-2.5\" strokeWidth={2.5} />\n                                Ready\n                              </span>\n                            )}\n                          </span>\n                          {item.description && (\n                            <span className=\"block truncate text-[11px] text-muted-foreground\">{item.description}</span>\n                          )}\n                        </span>\n\n                        <span className=\"flex shrink-0 items-center gap-1\">\n                          {steps.map((step, sIdx) => (\n                            <React.Fragment key={sIdx}>\n                              {sIdx > 0 && (\n                                <span className=\"px-0.5 text-[10px] text-muted-foreground/70\">then</span>\n                              )}\n                              <span className=\"flex items-center gap-0.5\">\n                                {step.tokens.map((tok, tIdx) => (\n                                  <Keycap\n                                    key={`${tok}-${tIdx}`}\n                                    label={formatKeyToken(tok, resolvedPlatform)}\n                                    pressed={pressedTokens.has(tok)}\n                                    matched={isMatched}\n                                    reduced={reduced}\n                                  />\n                                ))}\n                              </span>\n                            </React.Fragment>\n                          ))}\n                        </span>\n                      </button>\n                    );\n                  })}\n                </div>\n              </div>\n            ))}\n          </div>\n        )}\n      </div>\n\n      {/* Subtle footer hint */}\n      <div className=\"flex items-center justify-between border-t border-border/80 bg-muted/15 px-4 py-2 text-[11px] text-muted-foreground\">\n        <span>\n          Showing {resolvedPlatform === \"mac\" ? \"macOS\" : \"Windows / Linux\"} glyphs\n        </span>\n        {isDialog && <span>Press Esc to close</span>}\n      </div>\n\n      <span className=\"sr-only\" role=\"status\" aria-live=\"polite\">\n        {liveStatus}\n      </span>\n    </div>\n  );\n}\n\nexport function ShortcutSheet({\n  groups,\n  variant = \"inline\",\n  open: controlledOpen,\n  defaultOpen = false,\n  onOpenChange,\n  hotkey = \"?\",\n  liveKeys = true,\n  onTrigger,\n  platform = \"auto\",\n  searchable = true,\n  title = \"Keyboard shortcuts\",\n  sound = false,\n  className = \"\",\n  ...props\n}: ShortcutSheetProps) {\n  const reduced = useInteractionReducedMotion();\n  const detected = useDetectedPlatform();\n  const resolvedPlatform: \"mac\" | \"other\" = platform === \"auto\" ? detected : platform;\n\n  const [ownOpen, setOwnOpen] = React.useState(defaultOpen);\n  const isOpen = controlledOpen !== undefined ? controlledOpen : ownOpen;\n\n  const setOpen = React.useCallback(\n    (next: boolean) => {\n      if (controlledOpen === undefined) setOwnOpen(next);\n      onOpenChange?.(next);\n    },\n    [controlledOpen, onOpenChange],\n  );\n\n  // Global `?` toggle for dialog variant\n  React.useEffect(() => {\n    if (variant !== \"dialog\" || !hotkey) return;\n    const onKey = (e: KeyboardEvent) => {\n      if (isEditableElement(e.target)) return;\n      if (e.metaKey || e.ctrlKey || e.altKey) return;\n      if (e.key === hotkey) {\n        e.preventDefault();\n        setOpen(!isOpen);\n      }\n    };\n    window.addEventListener(\"keydown\", onKey);\n    return () => window.removeEventListener(\"keydown\", onKey);\n  }, [variant, hotkey, isOpen, setOpen]);\n\n  if (variant === \"inline\") {\n    return (\n      <div className={`w-full max-w-[720px] ${className}`} {...props}>\n        <SheetSurface\n          groups={groups}\n          title={title}\n          searchable={searchable}\n          liveKeys={liveKeys}\n          resolvedPlatform={resolvedPlatform}\n          reduced={reduced}\n          isDialog={false}\n          sound={sound}\n          onTrigger={onTrigger}\n        />\n      </div>\n    );\n  }\n\n  if (!isOpen) return null;\n\n  return (\n    <div\n      role=\"dialog\"\n      aria-modal=\"true\"\n      aria-label={title}\n      className=\"fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4 backdrop-blur-[2px]\"\n      onMouseDown={(e) => {\n        if (e.target === e.currentTarget) setOpen(false);\n      }}\n    >\n      <div className={`w-full max-w-[720px] ${className}`} {...props}>\n        <SheetSurface\n          groups={groups}\n          title={title}\n          searchable={searchable}\n          liveKeys={liveKeys}\n          resolvedPlatform={resolvedPlatform}\n          reduced={reduced}\n          isDialog\n          sound={sound}\n          onClose={() => setOpen(false)}\n          onTrigger={onTrigger}\n        />\n      </div>\n    </div>\n  );\n}\n\nexport default ShortcutSheet;\n"},{"path":"registry/ui-interaction-motion.ts","type":"registry:component","content":"// Hairline UI · shortcut-sheet · MIT License\n// Copyright (c) 2026 Hairline UI · https://hairlineui.com/license#components\n\n'use client';\n\nimport * as React from 'react';\n\nexport const EASE_OUT = 'cubic-bezier(0.16, 1, 0.3, 1)';\nexport const EASE_SETTLE = 'cubic-bezier(0.22, 1.18, 0.36, 1)';\n/** Thrown things (indicators, thumbs): a slight overshoot on transform only. */\nexport const EASE_THROW = 'cubic-bezier(0.34, 1.36, 0.64, 1)';\n/**\n * The press every button primitive shares: a 3% give that eases in and settles back.\n * Tailwind v4's scale-* writes the `scale` property, so `scale` has to be in the list\n * or the press snaps.\n */\nexport const INTERACTION_PRESS =\n  'transition-[background-color,color,box-shadow,opacity,scale] duration-200 ease-[cubic-bezier(0.16,1,0.3,1)] active:scale-[0.97] motion-reduce:transition-none motion-reduce:active:scale-100';\nexport const INTERACTION_FOCUS ='focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/50 focus-visible:ring-offset-2 focus-visible:ring-offset-background';\n\nconst query = '(prefers-reduced-motion: reduce)';\nconst subscribe = (notify: () => void) => {\n  const media = window.matchMedia(query);\n  media.addEventListener('change', notify);\n  return () => media.removeEventListener('change', notify);\n};\nexport const useInteractionReducedMotion = () => React.useSyncExternalStore(subscribe, () => window.matchMedia(query).matches, () => false);\n\nexport function useInteractionActivity<T extends Element>() {\n  const ref = React.useRef<T>(null);\n  const [visible, setVisible] = React.useState(false);\n  const [hidden, setHidden] = React.useState(false);\n  React.useEffect(() => {\n    const el = ref.current;\n    if (!el) return;\n    const observer = new IntersectionObserver(([entry]) => setVisible(entry.isIntersecting));\n    observer.observe(el);\n    const visibility = () => setHidden(document.hidden);\n    visibility(); document.addEventListener('visibilitychange', visibility);\n    return () => { observer.disconnect(); document.removeEventListener('visibilitychange', visibility); };\n  }, []);\n  return { ref, active: visible && !hidden };\n}\n\nexport function interactionIcon(on: boolean, reduced: boolean): React.CSSProperties {\n  return { opacity: on ? 1 : 0, transform: on ? 'none' : 'scale(0.6)', filter: on ? 'blur(0px)' : 'blur(3px)', transition: reduced ? 'none' : `opacity 220ms ${EASE_OUT}, transform 380ms ${EASE_OUT}, filter 220ms ${EASE_OUT}` };\n}\n\n/** A raised object: one tight contact shadow, one short ambient, a hairline of light on its top edge. */\nexport const MATERIAL_LIFT =\n  'shadow-[0_1px_1.5px_rgb(0_0_0/0.07),0_3px_8px_-2px_rgb(0_0_0/0.1),inset_0_0.5px_0_rgb(255_255_255/0.8)] dark:shadow-[0_1px_2px_rgb(0_0_0/0.5),0_4px_10px_-2px_rgb(0_0_0/0.35),inset_0_0.5px_0_rgb(255_255_255/0.1)]';\n/** A trough something sits in, shaded from above, lit along its bottom edge. */\nexport const MATERIAL_RECESS =\n  'shadow-[inset_0_1px_2.5px_rgb(0_0_0/0.09),inset_0_-0.5px_0_rgb(255_255_255/0.7)] dark:shadow-[inset_0_1px_3px_rgb(0_0_0/0.45),inset_0_-0.5px_0_rgb(255_255_255/0.07)]';\n\nexport type SpringConfig = { stiffness: number; damping: number; mass?: number };\nexport interface Spring {\n  get(): number;\n  getVelocity(): number;\n  getTarget(): number;\n  /** Aim somewhere new from wherever it is now, keeping its speed. */\n  set(target: number): void;\n  /** Add speed (units per second), on top of what it already has. */\n  push(velocity: number): void;\n  /** Be there now, at rest. */\n  jump(value: number): void;\n  configure(config: SpringConfig): void;\n  stop(): void;\n}\n\n// Every moving spring on the page shares one frame loop, which sleeps when the last one rests. Each spring's onFrame runs\n// once per frame after all of them have stepped, so several springs that draw one shape paint it once.\nconst SPRING_STEP = 1 / 240;\ntype Running = { step: () => void };\nconst runningSprings = new Set<Running>();\nconst springPainters = new Set<() => void>();\nlet springFrame = 0;\nlet springLast = 0;\nlet springSpare = 0;\n\nfunction springTick(now: number) {\n  // A hidden tab stops the frames, so the first one back must not count the whole gap as time passed.\n  springSpare += Math.min((now - springLast) / 1000, 0.05);\n  springLast = now;\n  while (springSpare >= SPRING_STEP) {\n    runningSprings.forEach((spring) => spring.step());\n    springSpare -= SPRING_STEP;\n  }\n  const painters = [...springPainters];\n  springPainters.clear();\n  painters.forEach((paint) => paint());\n  springFrame = runningSprings.size ? requestAnimationFrame(springTick) : 0;\n}\n\nfunction wakeSprings(spring: Running) {\n  runningSprings.add(spring);\n  if (springFrame) return;\n  springSpare = 0;\n  springFrame = requestAnimationFrame((now) => {\n    springLast = now - 1000 / 60;\n    springTick(now);\n  });\n}\n\n/**\n * A spring that carries its speed: re-aim it mid-flight and it curves on from where it is, push it while it swings and the\n * push adds to the swing. Use it for anything that can be interrupted; a curve restarts from a standstill every time.\n * `onFrame` should write straight to the DOM. `precision` is how close counts as there, in the value's own units.\n */\nexport function createSpring(initial: number, config: SpringConfig, onFrame: () => void, precision = 0.01): Spring {\n  let value = initial;\n  let velocity = 0;\n  let target = initial;\n  let { stiffness, damping, mass = 1 } = config;\n  const running: Running = {\n    step() {\n      velocity += ((-stiffness * (value - target) - damping * velocity) / mass) * SPRING_STEP;\n      value += velocity * SPRING_STEP;\n      if (Math.abs(value - target) < precision && Math.abs(velocity) < precision * 10) {\n        value = target;\n        velocity = 0;\n        runningSprings.delete(running);\n      }\n      springPainters.add(onFrame);\n    },\n  };\n  return {\n    get: () => value,\n    getVelocity: () => velocity,\n    getTarget: () => target,\n    set(next) {\n      if (next === target && !runningSprings.has(running)) return;\n      target = next;\n      wakeSprings(running);\n    },\n    push(speed) {\n      velocity += speed;\n      wakeSprings(running);\n    },\n    jump(next) {\n      value = next;\n      target = next;\n      velocity = 0;\n      runningSprings.delete(running);\n      onFrame();\n    },\n    configure(next) {\n      ({ stiffness, damping, mass = 1 } = next);\n    },\n    stop() {\n      runningSprings.delete(running);\n    },\n  };\n}\n\n/** Sample recent movement rather than averaging a long drag and losing its release velocity. */\nexport type PointerSample = { x: number; time: number };\nexport function samplePointer(samples: PointerSample[], x: number, time: number) {\n  samples.push({ x, time });\n  while (samples.length > 2 && time - samples[0].time > 100) samples.shift();\n}\nexport function releaseVelocity(samples: PointerSample[], now: number) {\n  if (samples.length < 2 || now - samples[samples.length - 1].time > 100) return 0;\n  const first = samples[0], last = samples[samples.length - 1];\n  return (last.x - first.x) / Math.max(1, last.time - first.time);\n}\n\n/** Smooth Apple/rational rubber-band curve: continuous exponential-like resistance without linear kinks. */\nexport function rubberBand(overshoot: number, dimension = 320, constant = 0.55): number {\n  const d = dimension || 320;\n  const abs = Math.abs(overshoot);\n  return Math.sign(overshoot) * (1 - 1 / ((abs * constant) / d + 1)) * d;\n}\n\n/** Projects resting travel from release velocity (velocity in px/ms; time in seconds). */\nexport function projectInertia(distance: number, velocity: number, time = 0.12): number {\n  return distance + velocity * 1000 * time;\n}\n\n/** Smooths incoming release velocity toward a boundary so springs don't slam or clip into walls. */\nexport function softenVelocity(velocity: number, distanceToTarget: number, factor = 10): number {\n  const maxAllowed = Math.abs(distanceToTarget) * factor;\n  return Math.sign(velocity) * Math.min(Math.abs(velocity), maxAllowed);\n}\n\n/** A damped spring sampled by WAAPI: tuned for organic lightness with a hint of life (3% breath). */\nexport function springFrames(\n  from: number,\n  to: number,\n  velocity = 0,\n  duration = 480,\n  config: { omega?: number; damping?: number; steps?: number } = {},\n) {\n  const { omega = 16, damping = 0.74, steps = 36 } = config;\n  const damped = omega * Math.sqrt(Math.max(0.001, 1 - damping * damping));\n  const displacement = from - to;\n  const coefficient = (velocity * 1000 + damping * omega * displacement) / damped;\n  return Array.from({ length: steps + 1 }, (_, i) => {\n    const t = (i / steps) * (duration / 1000);\n    const value = to + Math.exp(-damping * omega * t) * (displacement * Math.cos(damped * t) + coefficient * Math.sin(damped * t));\n    return { value: i === steps ? to : value, offset: i / steps };\n  });\n}\n\n"},{"path":"registry/ui-sounds.ts","type":"registry:component","content":"// Hairline UI · shortcut-sheet · MIT License\n// Copyright (c) 2026 Hairline UI · https://hairlineui.com/license#components\n\n/* ─────────────────────────────────────────────────────────\n * UI SOUNDS: small interface sounds, made in code\n *\n * No files and nothing to license: every sound is built from a\n * tone or a burst of noise with the Web Audio API the moment it\n * plays. They're short and quiet, made to sit under an interface,\n * and components only play them when you pass `sound`.\n *\n *   fold     paper creasing: two short crisp bursts\n *   unfold   paper opening: a soft rising sweep\n *   drop     something small landing: a low, soft knock\n *   tick     a light click\n *   pop      a quick bright blip\n *   success  two soft rising notes\n *   error    two low falling notes\n *\n * Browsers only start audio after the visitor has pressed\n * something on the page, so a sound before that stays silent.\n * ───────────────────────────────────────────────────────── */\n\nexport type UiSound = \"fold\" | \"unfold\" | \"drop\" | \"tick\" | \"pop\" | \"success\" | \"error\";\n\nlet context: AudioContext | null = null;\nlet noise: AudioBuffer | null = null;\n\nfunction audio() {\n  if (typeof window === \"undefined\") return null;\n  if (!context) {\n    const Ctx = window.AudioContext ?? (window as unknown as { webkitAudioContext?: typeof AudioContext }).webkitAudioContext;\n    if (!Ctx) return null;\n    context = new Ctx();\n  }\n  if (context.state === \"suspended\") void context.resume().catch(() => {});\n  return context;\n}\n\nfunction noiseBuffer(ctx: AudioContext) {\n  if (noise && noise.sampleRate === ctx.sampleRate) return noise;\n  noise = ctx.createBuffer(1, Math.floor(ctx.sampleRate * 0.5), ctx.sampleRate);\n  const data = noise.getChannelData(0);\n  for (let i = 0; i < data.length; i++) data[i] = Math.random() * 2 - 1;\n  return noise;\n}\n\n/** A burst of filtered noise. */\nfunction burst(ctx: AudioContext, out: AudioNode, at: number, length: number, { type = \"bandpass\", from = 2000, to = from, q = 0.9, level = 0.5 }: { type?: BiquadFilterType; from?: number; to?: number; q?: number; level?: number }) {\n  const src = ctx.createBufferSource();\n  src.buffer = noiseBuffer(ctx);\n  const filter = ctx.createBiquadFilter();\n  filter.type = type;\n  filter.Q.value = q;\n  filter.frequency.setValueAtTime(from, at);\n  filter.frequency.exponentialRampToValueAtTime(Math.max(40, to), at + length);\n  const gain = ctx.createGain();\n  gain.gain.setValueAtTime(0.0001, at);\n  gain.gain.exponentialRampToValueAtTime(level, at + Math.min(0.012, length / 3));\n  gain.gain.exponentialRampToValueAtTime(0.0001, at + length);\n  src.connect(filter).connect(gain).connect(out);\n  src.start(at, Math.random() * 0.3, length + 0.02);\n}\n\n/** A tone that glides from one pitch to another. */\nfunction tone(ctx: AudioContext, out: AudioNode, at: number, length: number, { type = \"sine\", from, to = from, level = 0.4 }: { type?: OscillatorType; from: number; to?: number; level?: number }) {\n  const osc = ctx.createOscillator();\n  osc.type = type;\n  osc.frequency.setValueAtTime(from, at);\n  osc.frequency.exponentialRampToValueAtTime(Math.max(20, to), at + length);\n  const gain = ctx.createGain();\n  gain.gain.setValueAtTime(0.0001, at);\n  gain.gain.exponentialRampToValueAtTime(level, at + 0.006);\n  gain.gain.exponentialRampToValueAtTime(0.0001, at + length);\n  osc.connect(gain).connect(out);\n  osc.start(at);\n  osc.stop(at + length + 0.02);\n}\n\n/** Plays one sound. `volume` is 0 to 1; the default sits quietly under an interface. */\nexport function playSound(name: UiSound, volume = 0.5) {\n  const ctx = audio();\n  if (!ctx) return;\n  const out = ctx.createGain();\n  out.gain.value = Math.max(0, Math.min(1, volume)) * 0.5;\n  out.connect(ctx.destination);\n  const t = ctx.currentTime + 0.005;\n  switch (name) {\n    case \"fold\":\n      burst(ctx, out, t, 0.05, { type: \"highpass\", from: 2600, q: 0.7, level: 0.45 });\n      burst(ctx, out, t + 0.07, 0.07, { type: \"bandpass\", from: 3200, to: 1800, q: 1.2, level: 0.35 });\n      break;\n    case \"unfold\":\n      burst(ctx, out, t, 0.16, { type: \"bandpass\", from: 900, to: 2800, q: 0.8, level: 0.3 });\n      break;\n    case \"drop\":\n      tone(ctx, out, t, 0.12, { from: 180, to: 70, level: 0.55 });\n      burst(ctx, out, t, 0.03, { type: \"lowpass\", from: 1200, q: 0.5, level: 0.2 });\n      break;\n    case \"tick\":\n      tone(ctx, out, t, 0.025, { type: \"triangle\", from: 1900, to: 1500, level: 0.25 });\n      break;\n    case \"pop\":\n      tone(ctx, out, t, 0.06, { from: 620, to: 980, level: 0.3 });\n      break;\n    case \"success\":\n      tone(ctx, out, t, 0.11, { from: 660, level: 0.22 });\n      tone(ctx, out, t + 0.09, 0.16, { from: 990, level: 0.22 });\n      break;\n    case \"error\":\n      tone(ctx, out, t, 0.12, { type: \"triangle\", from: 330, level: 0.25 });\n      tone(ctx, out, t + 0.1, 0.18, { type: \"triangle\", from: 247, level: 0.25 });\n      break;\n  }\n  window.setTimeout(() => out.disconnect(), 600);\n}\n"}],"css":{},"docs":"Docs and live preview: https://hairlineui.com/ui/shortcut-sheet. MIT licensed: https://hairlineui.com/license#components","meta":{"license":"MIT"}}