How github/hotkey works
@github/hotkey is a browser-side hotkey library. Callers install it on elements (usually those declared with data-hotkey); the library registers a document keydown handler, matches normalized keys and sequences, applies scope rules, then emits a cancellable event and defaults to focusing form fields or clicking other elements. The README also documents aliases, modifier and platform normalization, and unregistering. The graph follows sampled runtime imports and calls; broader documented usage is represented without assuming unsampled implementation details.
Main entry points: index.ts Install / uninstall · hotkey.ts Event serialization · radix-trie.ts Hotkey trie · utils.ts Alias expansion
Components 13
Registration API
- Install / uninstall
src/index.ts - Keydown handler
src/index.ts
Key Matching
- Hotkey trie
src/radix-trie.ts - Sequence tracker
src/sequence.ts - Alias expansion
src/utils.ts
Dispatch and Actions
- Action dispatch
src/utils.ts
Key Normalization
- Event serialization
src/hotkey.ts - Hotkey normalization
src/hotkey.ts - Mac symbol map
src/macos-symbol-layer.ts - Mac uppercase map
src/macos-uppercase-layer.ts
Other components
- Integrating page
- Target element
- Browser DOM
Connections 15
- Integrating page → Install / uninstall: registers elements
- Install / uninstall → Alias expansion: expands hotkeys
- Alias expansion → Hotkey normalization: normalizes keys
- Install / uninstall → Hotkey trie: inserts mappings
- Install / uninstall → Browser DOM: adds listener
- Browser DOM → Keydown handler: delivers keydown
- Keydown handler → Event serialization: serializes event
- Event serialization → Mac symbol map: maps symbols
- Event serialization → Mac uppercase map: maps uppercase
- Keydown handler → Hotkey trie: looks up key
- Keydown handler → Sequence tracker: records keypress
- Keydown handler → Action dispatch: dispatches match
- Action dispatch → Target element: fires event; focuses or clicks
- Install / uninstall → Hotkey trie: removes mappings
- Install / uninstall → Browser DOM: removes listener