{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "components-keyboard-shortcuts",
  "type": "registry:component",
  "title": "Keyboard shortcuts",
  "description": "A cheat sheet of chords as platform keycaps",
  "author": "sudo-kw <https://github.com/sudo-kw>",
  "dependencies": [
    "@gpuix/native@0.11.0",
    "@gpuix/react@0.11.0",
    "effect@4.1.2",
    "react@^19.2.4"
  ],
  "registryDependencies": [
    "https://gpuixui.sudokw.com/gpuix-keyboard.json",
    "https://gpuixui.sudokw.com/gpuix-tokens.json",
    "https://gpuixui.sudokw.com/gpuix-tw.json"
  ],
  "files": [
    {
      "path": "packages/components/src/internal/parts.ts",
      "target": "@ui/gpuixui/components/internal/parts.ts",
      "type": "registry:lib",
      "content": "import * as Arr from \"effect/Array\";\nimport * as P from \"effect/Predicate\";\nimport {\n  Children,\n  Fragment,\n  isValidElement,\n  type ReactElement,\n  type ReactNode,\n} from \"react\";\n\nexport type PartComponent = (props: never) => ReactNode;\n\nexport type PartChildren =\n  | ReactElement<unknown>\n  | boolean\n  | null\n  | undefined\n  | ReadonlyArray<PartChildren>;\n\nexport interface PartsContract {\n  readonly parent: string;\n\n  readonly family: ReadonlyArray<PartComponent>;\n\n  readonly accepts: ReadonlyArray<PartComponent>;\n\n  readonly hint?: string;\n}\n\nconst componentName = (type: unknown): string =>\n  P.isString(type)\n    ? type\n    : P.isFunction(type)\n      ? type.name || \"anonymous\"\n      : \"element\";\n\nconst fragmentChildren = (element: ReactElement<unknown>): ReactNode =>\n  hasChildren(element.props) ? element.props.children : undefined;\n\nconst hasChildren = (\n  value: unknown,\n): value is { readonly children?: ReactNode } =>\n  P.isObject(value) && \"children\" in value;\n\nconst leaves = (children: ReactNode): ReadonlyArray<unknown> =>\n  Arr.flatMap(Children.toArray(children), (child) =>\n    isValidElement<unknown>(child) && child.type === Fragment\n      ? leaves(fragmentChildren(child))\n      : [child],\n  );\n\nexport const assertParts = (\n  contract: PartsContract,\n  children: ReactNode,\n): void => {\n  Arr.forEach(leaves(children), (leaf) => {\n    if (!isValidElement(leaf)) return;\n    if (Arr.some(contract.accepts, (part) => part === leaf.type)) return;\n    if (!Arr.some(contract.family, (part) => part === leaf.type)) return;\n\n    throw new Error(\n      `${componentName(leaf.type)} cannot be used inside ${contract.parent}.` +\n        (contract.hint === undefined ? \"\" : ` ${contract.hint}`),\n    );\n  });\n};\n"
    },
    {
      "path": "packages/components/src/internal/recipe.ts",
      "target": "@ui/gpuixui/components/internal/recipe.ts",
      "type": "registry:lib",
      "content": "import type { StyleDesc } from \"@gpuix/react\";\nimport { createRecipeCache } from \"../../tw/index.js\";\nimport type { Theme } from \"./theme.js\";\n\nexport const recipeStyle: (recipe: string, theme: Theme) => StyleDesc =\n  createRecipeCache(512);\n"
    },
    {
      "path": "packages/components/src/internal/theme.ts",
      "target": "@ui/gpuixui/components/internal/theme.ts",
      "type": "registry:lib",
      "content": "import type { StyleDesc } from \"@gpuix/react\";\nimport * as Schema from \"effect/Schema\";\nimport {\n  alpha,\n  avatarPixels,\n  avatarSize,\n  brandTextOn,\n  controlFocusRing,\n  controlHeight,\n  controlPaddingX,\n  currentPlatform,\n  darkTheme,\n  disabledAction,\n  disabledOpacity,\n  elevationShadow,\n  filledHover,\n  filledPressed,\n  findHighlight,\n  focusRing,\n  keyboardFocusRing,\n  lightTheme,\n  nativeTextTheme,\n  pointerWash,\n  selectionOn,\n  statusTone,\n  syntaxColors,\n  targetSize,\n  textStyle,\n  type BoxShadow,\n  type ElevationLevel,\n  type FindHighlightSource,\n  type NativeTextFill,\n  type PlatformName,\n  type PointerWashSurface,\n  type StatusTone,\n  type SyntaxColors,\n  type SyntaxRole,\n  type TextRole,\n  type Theme,\n  type ThemeColors,\n} from \"../../tokens/index.js\";\n\nexport {\n  alpha,\n  avatarPixels,\n  avatarSize,\n  controlFocusRing,\n  controlHeight,\n  controlPaddingX,\n  currentPlatform,\n  darkTheme,\n  disabledAction,\n  disabledOpacity,\n  elevationShadow,\n  filledHover,\n  filledPressed,\n  findHighlight,\n  focusRing,\n  keyboardFocusRing,\n  lightTheme,\n  nativeTextTheme,\n  statusTone,\n  syntaxColors,\n  targetSize,\n  textStyle,\n};\nexport type {\n  BoxShadow,\n  ElevationLevel,\n  FindHighlightSource,\n  NativeTextFill,\n  PlatformName,\n  StatusTone,\n  SyntaxColors,\n  SyntaxRole,\n  TextRole,\n  Theme,\n};\nexport { ThemeProvider, useTheme } from \"../../tokens/react.js\";\n\nexport const keyboardRing = (theme: Theme, invalid = false): StyleDesc =>\n  controlFocusRing(theme, { invalid }) ?? {};\n\nexport interface ControlRingState {\n  readonly disabled?: boolean;\n\n  readonly invalid?: boolean;\n}\n\nexport const controlRing = (\n  theme: Theme,\n  state: ControlRingState = {},\n): StyleDesc => controlFocusRing(theme, state) ?? {};\n\nexport const pressWash = (theme: Theme, replaced: PointerWashSurface): string =>\n  pointerWash(theme, \"active\", replaced) ?? theme.colors.active;\n\nexport const selectionWash = (theme: Theme): StyleDesc => ({\n  selectionColor: theme.colors.selection,\n});\n\nexport const keepContent: StyleDesc = { keyboardFocusDim: false };\n\nexport const disabledFade = (\n  disabled: boolean,\n): { readonly opacity: number } | undefined =>\n  disabled ? { opacity: disabledOpacity } : undefined;\n\nconst Tones = Schema.Literals([\"info\", \"success\", \"warning\", \"danger\"]);\n\nexport type Tone = typeof Tones.Type;\n\nexport const toneOf = (value: unknown): Tone =>\n  Schema.is(Tones)(value) ? value : \"info\";\n\nexport interface ToneStyle {\n  readonly fg: string;\n  readonly bg: string;\n  readonly border: string;\n}\n\nconst TOKEN_TONE: Readonly<Record<Tone, StatusTone>> = {\n  info: \"info\",\n  success: \"success\",\n  warning: \"warning\",\n  danger: \"destructive\",\n};\n\nexport const tone = (theme: Theme, value: Tone): ToneStyle => {\n  const { background, border, foreground } = statusTone(\n    theme,\n    TOKEN_TONE[value],\n  );\n  return { bg: background, border, fg: foreground };\n};\n\nconst softRoles: Readonly<Record<Tone, keyof ThemeColors>> = {\n  info: \"infoSoft\",\n  success: \"successSoft\",\n  warning: \"warningSoft\",\n  danger: \"destructiveSoft\",\n};\n\nexport const messageLink = (theme: Theme, value: Tone): string =>\n  brandTextOn(theme, softRoles[value]);\n\nexport const messageSelection = (theme: Theme, value: Tone): string =>\n  selectionOn(theme, softRoles[value]);\n\nexport const toneSurface = (theme: Theme, value: Tone): StyleDesc => {\n  const { bg, border, fg } = tone(theme, value);\n  return {\n    backgroundColor: bg,\n    color: fg,\n    borderWidth: theme.borderWidth.thin,\n    borderColor: border,\n  };\n};\n"
    },
    {
      "path": "packages/components/src/keyboard-shortcuts.tsx",
      "target": "@ui/gpuixui/components/keyboard-shortcuts.tsx",
      "type": "registry:component",
      "content": "/** @jsxImportSource @gpuix/react */\nimport type { Props } from \"@gpuix/react\";\nimport {\n  mergeStyles,\n  resolveStyle,\n  type StateStyle,\n} from \"@gpuix/react/floating\";\nimport { formatSymbols, type Platform } from \"../keyboard/index.js\";\nimport {\n  cn,\n  KEYBOARD_SHORTCUT,\n  KEYBOARD_SHORTCUT_KEYS,\n  KEYBOARD_SHORTCUT_LABEL,\n  KEYBOARD_SHORTCUTS_GROUP,\n  KEYBOARD_SHORTCUTS_HEADING,\n  KEYBOARD_SHORTCUTS_ROOT,\n  KEYBOARD_SHORTCUTS_ROW,\n  KEYBOARD_SHORTCUTS_SEPARATOR,\n  KEYCAP,\n  KEYCAP_TEXT,\n} from \"../tw/index.js\";\nimport { Children, isValidElement } from \"react\";\nimport {\n  assertParts,\n  type PartChildren,\n  type PartComponent,\n  type PartsContract,\n} from \"./internal/parts.js\";\nimport { recipeStyle } from \"./internal/recipe.js\";\nimport { currentPlatform, useTheme } from \"./internal/theme.js\";\n\nexport interface KeyboardShortcutsProps extends Omit<Props, \"children\"> {\n  readonly label?: string;\n\n  readonly className?: string;\n  readonly children?: PartChildren;\n}\n\nexport const KeyboardShortcuts = ({\n  label,\n  className,\n  children,\n  style,\n  ...rest\n}: KeyboardShortcutsProps) => {\n  const theme = useTheme();\n  assertParts(shortcutsRoot, children);\n\n  return (\n    <div\n      role=\"list\"\n      {...(label === undefined ? {} : { \"aria-label\": label })}\n      {...rest}\n      style={mergeStyles(\n        recipeStyle(cn(KEYBOARD_SHORTCUTS_ROOT, className), theme),\n        style,\n      )}\n    >\n      {children}\n    </div>\n  );\n};\n\nexport interface KeyboardShortcutsGroupProps extends Omit<Props, \"children\"> {\n  readonly label: string;\n\n  readonly className?: string;\n  readonly children?: PartChildren;\n}\n\nexport const KeyboardShortcutsGroup = ({\n  label,\n  className,\n  children,\n  style,\n  ...rest\n}: KeyboardShortcutsGroupProps) => {\n  const theme = useTheme();\n  assertParts(shortcutsGroup, children);\n\n  const rows = Children.toArray(children);\n  const lastShortcut = rows.reduce(\n    (last, child, index) =>\n      isValidElement(child) && child.type === KeyboardShortcut ? index : last,\n    -1,\n  );\n\n  return (\n    <div\n      role=\"group\"\n      aria-label={label}\n      {...rest}\n      style={mergeStyles(\n        recipeStyle(cn(KEYBOARD_SHORTCUTS_GROUP, className), theme),\n        style,\n      )}\n    >\n      <text\n        role=\"heading\"\n        aria-level={3}\n        style={recipeStyle(KEYBOARD_SHORTCUTS_HEADING, theme)}\n      >\n        {label}\n      </text>\n      {rows.map((row, index) => (\n        <div key={index} style={recipeStyle(KEYBOARD_SHORTCUTS_ROW, theme)}>\n          {row}\n          {isValidElement(row) &&\n          row.type === KeyboardShortcut &&\n          index !== lastShortcut ? (\n            <div style={recipeStyle(KEYBOARD_SHORTCUTS_SEPARATOR, theme)} />\n          ) : null}\n        </div>\n      ))}\n    </div>\n  );\n};\n\nexport interface KeycapProps extends Omit<Props, \"children\" | \"style\"> {\n  readonly children?: string;\n\n  readonly className?: string;\n  readonly style?: StateStyle<KeycapState>;\n}\n\nexport interface KeycapState {\n  readonly label: string;\n}\n\nexport const Keycap = ({\n  children,\n  className,\n  style,\n  ...rest\n}: KeycapProps) => {\n  const theme = useTheme();\n  const label = children ?? \"\";\n\n  return (\n    <div\n      {...rest}\n      style={mergeStyles(\n        mergeStyles(recipeStyle(cn(KEYCAP, className), theme), {\n          pointerEvents: \"none\",\n        }),\n        resolveStyle(style, { label }),\n      )}\n    >\n      <text style={recipeStyle(KEYCAP_TEXT, theme)}>{label}</text>\n    </div>\n  );\n};\n\nexport interface KeyboardShortcutProps extends Omit<\n  Props,\n  \"children\" | \"style\"\n> {\n  readonly label: string;\n\n  readonly accelerator: string;\n\n  readonly platform?: Platform;\n\n  readonly className?: string;\n\n  readonly style?: StateStyle<KeyboardShortcutState>;\n}\n\nexport interface KeyboardShortcutState {\n  readonly keys: ReadonlyArray<string>;\n}\n\nexport const KeyboardShortcut = ({\n  label,\n  accelerator,\n  platform,\n  className,\n  style,\n  ...rest\n}: KeyboardShortcutProps) => {\n  const theme = useTheme();\n  const keys = formatSymbols(accelerator, platform ?? currentPlatform);\n\n  return (\n    <div\n      role=\"listitem\"\n      {...rest}\n      style={mergeStyles(\n        recipeStyle(cn(KEYBOARD_SHORTCUT, className), theme),\n        resolveStyle(style, { keys }),\n      )}\n    >\n      <text style={recipeStyle(KEYBOARD_SHORTCUT_LABEL, theme)}>{label}</text>\n      <div style={recipeStyle(KEYBOARD_SHORTCUT_KEYS, theme)}>\n        {keys.map((key, index) => (\n          <Keycap key={index}>{key}</Keycap>\n        ))}\n      </div>\n    </div>\n  );\n};\n\nconst shortcutParts: ReadonlyArray<PartComponent> = [\n  KeyboardShortcuts,\n  KeyboardShortcutsGroup,\n  KeyboardShortcut,\n  Keycap,\n];\n\nconst shortcutsRoot: PartsContract = {\n  parent: \"KeyboardShortcuts\",\n  family: shortcutParts,\n  accepts: [KeyboardShortcutsGroup, KeyboardShortcut],\n  hint: \"Put KeyboardShortcutsGroup (or a KeyboardShortcut) inside KeyboardShortcuts.\",\n};\n\nconst shortcutsGroup: PartsContract = {\n  parent: \"KeyboardShortcutsGroup\",\n  family: shortcutParts,\n  accepts: [KeyboardShortcut],\n  hint: \"Put KeyboardShortcut rows directly inside KeyboardShortcutsGroup.\",\n};\n\nexport const keyboardShortcutsMeta = {\n  name: \"Keyboard shortcuts / keycap display\",\n  tier: 2,\n  status: \"done\",\n  gpuixSupport: \"yes\",\n  limitations: [\n    \"display-only: a row documents a chord, it does not register a handler\",\n    \"the chord grammar is @tanstack/hotkeys; an unknown token displays verbatim rather than failing\",\n    \"rows are separated by 1px elements because 0.11.0 has one border colour per element\",\n  ],\n  docs: \"docs/keyboard-shortcuts.mdx\",\n  example: \"examples/keyboard-shortcuts.example.tsx\",\n  testFile: \"src/behaviour/keyboard-shortcuts.test.tsx\",\n} as const;\n"
    }
  ],
  "docs": "[Keyboard shortcuts](https://gpuixui.sudokw.com/components/keyboard-shortcuts) — These are GPUix native components: the files render through GPUix's reconciler against `@gpuix/react`, not the DOM, and need the per-platform `@gpuix/native` binding. The CLI installs the `@gpuixui/*` runtime the components import as registry items, so the copied tree resolves on its own; wrap it in `ThemeProvider` before it renders.",
  "meta": {
    "url": "/components/keyboard-shortcuts",
    "kind": "component",
    "runtime": "gpuix",
    "registry": "gpuixui"
  }
}