Skip to content

Components Reference ​

registerComponents() ​

Register all web components. Call once at startup.

ts
function registerComponents(): void
js
import { registerComponents } from 'keybinds'
registerComponents()

CommandPalette ​

Custom element: <keybinds-command-palette>

Properties ​

PropertyTypeDescription
commandsCommand[]Commands to display and execute
inputsInputUI[]How bindings are shown: an item shows its first (default: keys only)
contextobjectContext for when evaluation
source(query: string) => Command[] | Promise<Command[]>Further commands for a typed query, merged with commands (same id keeps the one in commands); an answer for a query no longer typed is dropped
sourceDelaynumberMilliseconds of typing pause before source is asked (default 200)
openbooleanVisibility state

Attributes ​

AttributeTypeDescription
openbooleanWhen present, palette is visible
auto-triggerbooleanEnable $mod+K keyboard trigger
placeholderstringInput placeholder text (default: "Type a command...")

Events ​

EventDetailDescription
execute{ command: Command }Command was executed
close-Palette was dismissed

CSS Parts ​

PartElement
paletteRoot .palette div
backdropOverlay div
dialogMain dialog container
inputSearch input
listResults ul
itemResult li
item-activeSelected result
item-disabledInactive result
item-labelLabel span
item-descriptionDescription span
item-categoryCategory span
item-keyShortcut kbd
emptyNo results message

Keyboard Navigation ​

KeyAction
↑ / ↓Navigate results (wraps around)
Home / EndJump to first / last result
EnterExecute selected
EscapeClose palette

Keyboard and pointer input are tracked separately — moving the mouse won't hijack an in-progress keyboard selection until the pointer deliberately moves again.


KeybindCheatsheet ​

Custom element: <keybinds-cheatsheet>

Properties ​

PropertyTypeDescription
commandsCommand[]Commands to display
inputsInputUI[]Which bindings are shown (default: keys only)
contextobjectContext for when evaluation
openbooleanVisibility state

Attributes ​

AttributeTypeDescription
openbooleanWhen present, cheatsheet is visible
auto-triggerbooleanOpen while a modifier is held on its own
trigger-keystringThe modifier: $mod (default; Meta on Mac, Control elsewhere), Control, Alt, Shift or Meta
trigger-delaynumberHow long it's held before opening, in ms (default 200)

Events ​

EventDescription
closeCheatsheet was dismissed

CSS Parts ​

PartElement
cheatsheetRoot div
backdropOverlay div
dialogMain dialog container
groupCategory group div
group-titleCategory heading
listCommands ul
itemCommand li
item-disabledInactive command
item-labelLabel span
item-keysKeys container span
item-keyIndividual kbd

KeybindSettings ​

Custom element: <keybinds-settings>

Properties ​

PropertyTypeDescription
storeBindingsStoreReactive bindings store instance
inputsInputUI[]Which bindings are shown and can be recorded (default: keys only)
releases, holds, sequencesbooleanOffer recording release bindings (k:up), holds and taps (k:hold, k:tap), and steps (g i); the hub sets them from its options (default: false)
openbooleanVisibility state

Attributes ​

AttributeTypeDescription
openbooleanWhen present, settings panel is visible

Events ​

EventDetailDescription
close-Settings panel was dismissed
change{ commandId, keys?, mouse? }A binding was changed
reset{ commandId? }Bindings were reset (per-command or all)

CSS Parts ​

PartElement
settingsRoot .settings div
backdropOverlay div
dialogMain dialog container
headerHeader container
titleTitle text
reset-allReset All button
groupCategory group div
group-titleCategory heading
listCommands ul
itemCommand li
item-labelLabel span
item-bindingsBindings container span
item-resetPer-command reset button
bindingIndividual binding span
binding-recordingBinding in recording state
binding-keysKey display container
binding-keyIndividual kbd
binding-removeRemove (×) button
binding-releasePress/release switch on a binding (binding-release-on while it is a release)
item-addAdd binding container
add-<input>Add button for each of inputs: add-key, add-mouse, add-gamepad (shown while a gamepad is connected), add-axis
binding-invertAn axis source's Invert switch (binding-invert-on when inverted)
recording-overlayRecording prompt text
recording-releaseRelease toggle in the recording prompt (recording-release-on while on)
recording-hold, recording-tapHold and Tap toggles, with holds (-on while on)
recording-sequenceSteps toggle, with sequences: keys are recorded one after another until Done or a pause of a second
recording-doneEnds recording steps
conflictConflict warning
conflict-acceptReplace button
conflict-cancelCancel button

Keyboard Navigation ​

KeyAction
EscapeCancel recording, or close panel

ContextMenu ​

Custom element: <keybinds-basic-context-menu>

Properties ​

PropertyTypeDescription
commandsCommand[]Commands to display and execute
inputsInputUI[]How bindings are shown: an item shows its first (default: keys only)
contextobjectContext for when evaluation
menustringFilter to commands with matching menu tag
position{ x: number, y: number }Menu position in viewport coordinates
openbooleanVisibility state

Attributes ​

AttributeTypeDescription
openbooleanWhen present, menu is visible
auto-triggerbooleanListen for contextmenu on parent or target element
menustringFilter commands by menu tag
targetstringCSS selector for trigger element (defaults to parent)

Events ​

EventDetailDescription
execute{ command: Command }Command was executed
close-Menu was dismissed

CSS Parts ​

PartElement
context-menuRoot div
backdropOverlay div
listMenu ul
itemMenu item li
item-activeHighlighted item
item-disabledInactive item
separatorCategory separator
item-labelLabel span
item-keysKeys container span
item-keyIndividual kbd

Keyboard Navigation ​

KeyAction
↑ / ↓Navigate items (wraps around)
Home / EndJump to first / last item
EnterExecute selected
EscapeClose menu

Keyboard and pointer input are tracked separately — moving the mouse won't hijack an in-progress keyboard selection until the pointer deliberately moves again.


eventToBindingString(event) ​

Convert a KeyboardEvent to a canonical binding string.

ts
function eventToBindingString(event: KeyboardEvent): string | null

Returns null for bare modifier presses and unknown keys. Uses $mod for the platform modifier (Meta on Mac, Ctrl elsewhere).


eventToMouseBindingString(event) ​

Convert a MouseEvent to a canonical binding string.

ts
function eventToMouseBindingString(event: MouseEvent): string | null

Maps button numbers to canonical names (0=click, 1=middle, 2=right).


findConflict(schema, bindingStr, input, excludeId?) ​

Check if a binding string conflicts with any command in a schema.

ts
function findConflict(
  schema: Schema,
  bindingStr: string,
  input: Input,
  excludeId?: string
): { commandId: string, label: string } | null

Normalizes through parse → lookup for accurate cross-format comparison.


formatMouseParts(binding) ​

Format a mouse/scroll binding string into an array of display-ready parts.

ts
function formatMouseParts(binding: string): string[]
js
formatMouseParts('$mod+click')      // ["⌘", "Click"] on Mac, ["Ctrl", "Click"] elsewhere
formatMouseParts('scrollup')        // ["Scroll ↑"]
formatMouseParts('ctrl+scrolldown') // ["Ctrl", "Scroll ↓"] on Mac, ["Ctrl", "Scroll ↓"] elsewhere

formatGamepadParts(binding) ​

Format a gamepad binding string into display-ready parts.

ts
function formatGamepadParts(binding: string): string[]
js
formatGamepadParts('rt')     // ["RT"]
formatGamepadParts('south:up') // ["A", "Release"]
formatGamepadParts('up')     // ["D-pad ↑"]

formatAxisParts(binding) ​

js
formatAxisParts('mouse:x')  // ["Mouse ↔"]
formatAxisParts('-pad:ry')  // ["Right stick ↕", "Inverted"]
formatAxisParts('keys:a/d') // ["A", "/", "D"]

filterByMenu(commands, menu, context?) ​

Filter commands by their menu tag for context menu display.

ts
function filterByMenu(
  commands: Command[],
  menu: string,
  context?: Record<string, unknown>
): (Command & { active: boolean })[]

Returns commands whose menu property matches (string match or array includes). Each result includes an active boolean from when evaluation. Hidden commands are excluded.

js
const items = filterByMenu(commands, 'editor', { hasSelection: true })

onModifierHold(modifiers, callback, options?) ​

Utility for hold-to-show behavior.

ts
function onModifierHold(
  modifiers: string | string[],
  callback: (held: boolean) => void,
  options?: { delay?: number, target?: EventTarget }
): () => void

Parameters:

ParameterTypeDefaultDescription
modifiersstring | string[]-Modifier key(s): 'Control', 'Alt', 'Shift', 'Meta'
callback(held: boolean) => void-Called with true when held by itself for delay, false on release or when another key, a click or scrolling happens
options.delaynumber200Hold duration in ms
options.targetEventTargetwindowElement to listen on

Returns: Cleanup function.

js
const cleanup = onModifierHold('Control', (held) => {
  cheatsheet.open = held
})

// Multiple modifiers (either triggers)
onModifierHold(['Control', 'Meta'], callback)

// Custom delay
onModifierHold('Alt', callback, { delay: 300 })

onModifierTaps(modifiers, count, callback, options?) ​

Calls back when a modifier is tapped (pressed and released by itself) count times in a row.

ts
function onModifierTaps(
  modifiers: string | string[],
  count: number,
  callback: () => void,
  options?: { within?: number, target?: EventTarget }
): () => void
ParameterTypeDefaultDescription
modifiersstring | string[]-Modifier key(s): 'Control', 'Alt', 'Shift', 'Meta'
countnumber-Taps in a row
callback() => void-Called on the last tap's release
options.withinnumber400Most ms from one tap's press to the next tap's release
options.targetEventTargetwindowElement to listen on

Returns: Cleanup function.

js
onModifierTaps('Shift', 2, () => palette.open = true)