{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "kbd",
  "title": "Kbd",
  "description": "A keyboard shortcut, in the reader's platform's notation: `keys={[\"mod\", \"k\"]}` shows ⌘K on a Mac, iPhone or iPad and Ctrl+K elsewhere.",
  "registryDependencies": [
    "@ouro/lib-class-name-check",
    "@ouro/lib-cn",
    "@ouro/lib-env",
    "@ouro/lib-platform",
    "@ouro/lib-use-dev-messages",
    "@ouro/lib-use-platform"
  ],
  "files": [
    {
      "path": "registry/ouro/components/ouro/kbd/kbd.tsx",
      "content": "\"use client\";\n\nimport { Fragment } from \"react\";\nimport type { HTMLAttributes, JSX, Ref } from \"react\";\nimport { useAppearanceClassNameCheck } from \"@/registry/ouro/lib/ouro/class-name-check\";\nimport { cn } from \"@/registry/ouro/lib/ouro/cn\";\nimport type { Platform } from \"@/registry/ouro/lib/ouro/platform\";\nimport { useDevWarnings } from \"@/registry/ouro/lib/ouro/use-dev-messages\";\nimport { usePlatform } from \"@/registry/ouro/lib/ouro/use-platform\";\n\n/** The props Kbd adds to the `<kbd>` attributes it passes through. */\nexport interface KbdOwnProps {\n  /**\n   * The keys to press together, by name: `[\"mod\", \"k\"]`. `mod` is ⌘ on Apple platforms\n   * and Ctrl elsewhere, the portable choice for an app shortcut. Modifier names: `mod`,\n   * `cmd` (`meta`: ⌘ on Apple, Win on Windows, Ctrl on Linux and ChromeOS), `ctrl`, `alt`\n   * (`option`), `shift`. Modifiers show in the platform's order (⌃⌥⇧⌘ on Apple, Win+Ctrl+Alt+Shift\n   * elsewhere), then the other keys as given. Other names: `enter`, `escape`,\n   * `tab`, `backspace`, `delete`, `space`, `up`, `down`, `left`, `right`. Any other\n   * string shows as written, a single letter in capitals.\n   */\n  keys: readonly string[] | (string & { 'Use an array: keys={[\"mod\", \"k\"]}': never });\n  /** Layout only: margins (`ms-2`). Appearance classes warn in development; Kbd sizes itself to the surrounding text. */\n  className?: string | undefined;\n  ref?: Ref<HTMLElement> | undefined;\n\n  /**\n   * Not a prop. Kbd takes `keys`, so each platform gets the right glyphs: `<Kbd keys={[\"mod\", \"k\"]} />`.\n   *\n   * @claim \"Kbd takes `keys`, so each platform\" registry/ouro/components/ouro/kbd/kbd.test.tsx verify:testExists(registry/ouro/components/ouro/kbd/kbd.test.tsx::Kbd > names Apple glyphs for screen readers)\n   * @claim \"Kbd takes `keys`, so each platform\" registry/ouro/components/ouro/kbd/kbd.test.tsx verify:testExists(registry/ouro/components/ouro/kbd/kbd.test.tsx::Kbd)\n   * @claim \"Kbd takes `keys`, so each platform\" registry/ouro/components/ouro/kbd/kbd.test.tsx verify:testExists(registry/ouro/components/ouro/kbd/kbd.test.tsx::Kbd > puts other modifiers in Win, Ctrl, Alt, Shift order, before the key)\n   */\n  children?: { 'Use <Kbd keys={[\"mod\", \"k\"]} />': never };\n  /** Not a prop. Ouro UI uses `keys`, an array: `<Kbd keys={[\"mod\", \"k\"]} />`. */\n  shortcut?: { 'Use <Kbd keys={[\"mod\", \"k\"]} />': never };\n}\n\n/** Props for {@link Kbd}: its own props and the `<kbd>` attributes it passes through. */\nexport type KbdProps = Omit<HTMLAttributes<HTMLElement>, keyof KbdOwnProps> & KbdOwnProps;\n\n/**\n * Each named key as `[Apple glyph, Apple name, other label, other name]`. A name is\n * given where the visible label is a symbol, for screen readers.\n * @claim \"Each named key as `[Apple glyph\" registry/ouro/components/ouro/kbd/kbd.test.tsx verify:testExists(registry/ouro/components/ouro/kbd/kbd.test.tsx::Kbd > names Apple glyphs for screen readers)\n * @claim \"Each named key as `[Apple glyph\" registry/ouro/components/ouro/kbd/kbd.test.tsx verify:testExists(registry/ouro/components/ouro/kbd/kbd.test.tsx::Kbd > puts Apple modifiers in Apple's order, Control, Option, Shift, Command, before the key)\n * @claim \"Each named key as `[Apple glyph\" registry/ouro/components/ouro/kbd/kbd.test.tsx verify:testExists(registry/ouro/components/ouro/kbd/kbd.test.tsx::Kbd > puts other modifiers in Win, Ctrl, Alt, Shift order, before the key)\n */\nconst named: Readonly<Record<string, readonly [string, string, string, string?]>> = {\n  mod: [\"⌘\", \"Command\", \"Ctrl\"],\n  cmd: [\"⌘\", \"Command\", \"Win\"],\n  ctrl: [\"⌃\", \"Control\", \"Ctrl\"],\n  alt: [\"⌥\", \"Option\", \"Alt\"],\n  shift: [\"⇧\", \"Shift\", \"Shift\"],\n  enter: [\"↩\", \"Return\", \"Enter\"],\n  escape: [\"Esc\", \"\", \"Esc\"],\n  tab: [\"⇥\", \"Tab\", \"Tab\"],\n  backspace: [\"⌫\", \"Delete\", \"Backspace\"],\n  delete: [\"⌦\", \"Forward delete\", \"Del\"],\n  space: [\"Space\", \"\", \"Space\"],\n  up: [\"↑\", \"Up arrow\", \"↑\", \"Up arrow\"],\n  down: [\"↓\", \"Down arrow\", \"↓\", \"Down arrow\"],\n  left: [\"←\", \"Left arrow\", \"←\", \"Left arrow\"],\n  right: [\"→\", \"Right arrow\", \"→\", \"Right arrow\"],\n};\n\nconst aliases: Readonly<Record<string, string>> = {\n  meta: \"cmd\",\n  command: \"cmd\",\n  control: \"ctrl\",\n  option: \"alt\",\n  return: \"enter\",\n  esc: \"escape\",\n  arrowup: \"up\",\n  arrowdown: \"down\",\n  arrowleft: \"left\",\n  arrowright: \"right\",\n};\n\n/**\n * Where each modifier goes, so a shortcut reads as the platform writes it: Apple's menus\n * use Control, Option, Shift, Command (⌃⌥⇧⌘); elsewhere it is Win, Ctrl, Alt, Shift. Other\n * keys follow the modifiers in the order given.\n * @claim \"Where each modifier goes, so a\" registry/ouro/components/ouro/kbd/kbd.test.tsx verify:testExists(registry/ouro/components/ouro/kbd/kbd.test.tsx::Kbd > puts Apple modifiers in Apple's order, Control, Option, Shift, Command, before the key)\n * @claim \"Where each modifier goes, so a\" registry/ouro/components/ouro/kbd/kbd.test.tsx verify:testExists(registry/ouro/components/ouro/kbd/kbd.test.tsx::Kbd > puts other modifiers in Win, Ctrl, Alt, Shift order, before the key)\n */\nconst appleOrder: Readonly<Record<string, number>> = { ctrl: 0, alt: 1, shift: 2, mod: 3, cmd: 3 };\nconst otherOrder: Readonly<Record<string, number>> = { cmd: 0, mod: 1, ctrl: 1, alt: 2, shift: 3 };\n\n/** The canonical name of a key: an alias such as `option` becomes `alt`. */\nfunction keyId(key: string): string {\n  const lower = key.toLowerCase();\n  return Object.hasOwn(aliases, lower) ? aliases[lower]! : lower;\n}\n\n/**\n * A one-character key that is also an emoji, such as ↩, followed by U+FE0E so it draws as text in\n * the key's colour, never as a colour emoji (macOS draws ↩ as one).\n * @claim \"A one-character key that is also\" registry/ouro/components/ouro/kbd/kbd.test.tsx verify:testExists(registry/ouro/components/ouro/kbd/kbd.test.tsx::Kbd > draws a key that is also an emoji as text)\n */\nfunction asText(text: string): string {\n  return /^(?!\\p{ASCII})\\p{Emoji}$/u.test(text) ? `${text}\\uFE0E` : text;\n}\n\n/** One key: its visible label, and a screen-reader name when the label is a symbol. */\nfunction label(key: string, platform: Platform): { text: string; name: string | undefined } {\n  const id = keyId(key);\n  // Only Windows has a Win key; on Linux and ChromeOS the app's command key is Ctrl.\n  if (id === \"cmd\" && platform !== \"apple\") return { text: platform === \"windows\" ? \"Win\" : \"Ctrl\", name: undefined };\n  if (!Object.hasOwn(named, id)) return { text: asText(key.length === 1 ? key.toUpperCase() : key), name: undefined };\n  const [glyph, glyphName, text, textName] = named[id]!;\n  return platform === \"apple\" ? { text: asText(glyph), name: glyphName || undefined } : { text, name: textName };\n}\n\n/**\n * A keyboard shortcut, in the reader's platform's notation: `keys={[\"mod\", \"k\"]}` shows\n * ⌘K on a Mac, iPhone or iPad and Ctrl+K elsewhere. Symbols carry their spoken name for\n * screen readers, and draw as text even where they are also emoji (↩). It sizes itself to the surrounding text, so it fits in a Menu item, a\n * Tooltip or a sentence.\n *\n * The server can't know the platform, so server HTML shows the key names (Ctrl+K) and\n * Apple devices switch to the glyphs after hydration.\n *\n * Use plain `Text` instead for a key named in prose that isn't a shortcut to press.\n *\n * @group Text\n * @see https://ui.ouroboros.bot/docs/kbd\n * @claim \"and draw as text even where\" registry/ouro/components/ouro/kbd/kbd.test.tsx verify:testExists(registry/ouro/components/ouro/kbd/kbd.test.tsx::Kbd > draws a key that is also an emoji as text)\n *\n * @example\n * <Kbd keys={[\"mod\", \"k\"]} />\n * <Text>Press <Kbd keys={[\"shift\", \"enter\"]} /> for a new line.</Text>\n */\nexport function Kbd(props: KbdProps): JSX.Element {\n  const {\n    keys: keysProp,\n    className,\n    // Guard props (hint types), dropped here so they never reach the DOM.\n    children,\n    shortcut,\n    ...rest\n  } = props;\n  const platform = usePlatform();\n  // A string of keys (a type error) is split on \"+\", as the agent meant it.\n  const keys: readonly string[] = typeof keysProp === \"string\" ? keysProp.split(\"+\") : (keysProp ?? []);\n  useAppearanceClassNameCheck(\n    \"Kbd\",\n    className,\n    process.env.NODE_ENV !== \"production\"\n      ? (token: string) =>\n          /^text-(xs|sm|base|lg|xl|\\dxl)$/.test(token)\n            ? `remove \"${token}\"; Kbd sizes itself to the surrounding text`\n            : `remove \"${token}\"; Kbd matches the theme`\n      : /* istanbul ignore next @preserve -- production only */ \"\",\n  );\n  useDevWarnings(\n    \"Kbd\",\n    process.env.NODE_ENV !== \"production\"\n      ? () => [\n          typeof keysProp === \"string\" && [`keys=\"${keysProp}\" is a string; keys takes an array`, '<Kbd keys={[\"mod\", \"k\"]} />'],\n          children !== undefined && [\"Kbd takes keys, not children\", '<Kbd keys={[\"mod\", \"k\"]} />'],\n          Array.isArray(keysProp) && keysProp.length === 0 && [\"keys is empty\", '<Kbd keys={[\"mod\", \"k\"]} />'],\n          shortcut !== undefined && [\"shortcut is not a prop\", '<Kbd keys={[\"mod\", \"k\"]} />'],\n        ]\n      : /* istanbul ignore next @preserve -- production only */ undefined,\n  );\n  const apple = platform === \"apple\";\n  const order = apple ? appleOrder : otherOrder;\n  const rank = (key: string) => order[keyId(key)] ?? 4;\n  const ordered = [...keys].sort((a, b) => rank(a) - rank(b));\n  return (\n    <kbd\n      {...rest}\n      data-ouro=\"kbd\"\n      data-platform={apple ? \"apple\" : platform === \"unknown\" ? \"unknown\" : \"other\"}\n      className={cn(\n        \"box-border inline-flex h-[1.6em] min-w-[1.6em] items-center justify-center gap-[0.15em] align-[0.1em] \" +\n          \"rounded-ouro-sm border border-solid border-border bg-muted px-[0.35em] [font-family:inherit] text-[0.85em]/none font-medium \" +\n          \"text-foreground whitespace-nowrap select-none\",\n        className,\n      )}\n    >\n      {ordered.map((key, index) => {\n        const { text, name } = label(key, platform);\n        return (\n          <Fragment key={index}>\n            {!apple && index > 0 && \"+\"}\n            <kbd className=\"m-0 [font:inherit]\">\n              {name ? (\n                <>\n                  <span aria-hidden=\"true\" data-glyph=\"\">\n                    {text}\n                  </span>\n                  <span className=\"sr-only\">{name}</span>\n                </>\n              ) : (\n                text\n              )}\n            </kbd>\n          </Fragment>\n        );\n      })}\n    </kbd>\n  );\n}\n",
      "type": "registry:ui",
      "target": "@components/ouro/kbd/kbd.tsx"
    }
  ],
  "docs": "A keyboard shortcut, in the reader's platform's notation: `keys={[\"mod\", \"k\"]}` shows ⌘K on a Mac, iPhone or iPad and Ctrl+K elsewhere. Import: import { Kbd } from \"@/components/ouro/kbd/kbd\", with @/components replaced by your components alias (aliases.components in components.json, such as ~/components). Also installed: the helpers it imports in lib/ouro. Needs ouro-base in your stylesheet: add that item once per app, from the same place as this one, if you have not. Docs: https://ui.ouroboros.bot/docs/kbd.md Ouro UI v1.3.257.",
  "type": "registry:ui"
}