@tanstack/hotkeys 0.8.0 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (158) hide show
  1. package/README.md +15 -1
  2. package/dist/{manager.utils.js → _event-target.cjs} +5 -41
  3. package/dist/_event-target.cjs.map +1 -0
  4. package/dist/{manager.utils.cjs → _event-target.js} +3 -47
  5. package/dist/_event-target.js.map +1 -0
  6. package/dist/_keyboard-event.cjs +83 -0
  7. package/dist/_keyboard-event.cjs.map +1 -0
  8. package/dist/_keyboard-event.js +76 -0
  9. package/dist/_keyboard-event.js.map +1 -0
  10. package/dist/_match.cjs +49 -0
  11. package/dist/_match.cjs.map +1 -0
  12. package/dist/_match.js +49 -0
  13. package/dist/_match.js.map +1 -0
  14. package/dist/_named-keys.cjs +68 -0
  15. package/dist/_named-keys.cjs.map +1 -0
  16. package/dist/_named-keys.d.cts +8 -0
  17. package/dist/_named-keys.d.ts +8 -0
  18. package/dist/_named-keys.js +66 -0
  19. package/dist/_named-keys.js.map +1 -0
  20. package/dist/_recorder-chord.cjs +44 -0
  21. package/dist/_recorder-chord.cjs.map +1 -0
  22. package/dist/_recorder-chord.js +43 -0
  23. package/dist/_recorder-chord.js.map +1 -0
  24. package/dist/_recording-guard.cjs +59 -0
  25. package/dist/_recording-guard.cjs.map +1 -0
  26. package/dist/_recording-guard.js +56 -0
  27. package/dist/_recording-guard.js.map +1 -0
  28. package/dist/_registration.cjs +54 -0
  29. package/dist/_registration.cjs.map +1 -0
  30. package/dist/_registration.js +50 -0
  31. package/dist/_registration.js.map +1 -0
  32. package/dist/conflicts.cjs +55 -0
  33. package/dist/conflicts.cjs.map +1 -0
  34. package/dist/conflicts.d.cts +39 -0
  35. package/dist/conflicts.d.ts +39 -0
  36. package/dist/conflicts.js +55 -0
  37. package/dist/conflicts.js.map +1 -0
  38. package/dist/constants.cjs +46 -171
  39. package/dist/constants.cjs.map +1 -1
  40. package/dist/constants.d.cts +4 -129
  41. package/dist/constants.d.ts +4 -129
  42. package/dist/constants.js +48 -164
  43. package/dist/constants.js.map +1 -1
  44. package/dist/display-labels.cjs +119 -0
  45. package/dist/display-labels.cjs.map +1 -0
  46. package/dist/display-labels.d.cts +93 -0
  47. package/dist/display-labels.d.ts +93 -0
  48. package/dist/display-labels.js +113 -0
  49. package/dist/display-labels.js.map +1 -0
  50. package/dist/format.cjs +30 -36
  51. package/dist/format.cjs.map +1 -1
  52. package/dist/format.d.cts +46 -7
  53. package/dist/format.d.ts +46 -7
  54. package/dist/format.js +31 -37
  55. package/dist/format.js.map +1 -1
  56. package/dist/hint.cjs +24 -0
  57. package/dist/hint.cjs.map +1 -0
  58. package/dist/hint.d.cts +23 -0
  59. package/dist/hint.d.ts +23 -0
  60. package/dist/hint.js +24 -0
  61. package/dist/hint.js.map +1 -0
  62. package/dist/hotkey-manager.cjs +53 -22
  63. package/dist/hotkey-manager.cjs.map +1 -1
  64. package/dist/hotkey-manager.d.cts +6 -2
  65. package/dist/hotkey-manager.d.ts +6 -2
  66. package/dist/hotkey-manager.js +49 -18
  67. package/dist/hotkey-manager.js.map +1 -1
  68. package/dist/hotkey-recorder.cjs +66 -10
  69. package/dist/hotkey-recorder.cjs.map +1 -1
  70. package/dist/hotkey-recorder.d.cts +5 -2
  71. package/dist/hotkey-recorder.d.ts +5 -2
  72. package/dist/hotkey-recorder.js +65 -9
  73. package/dist/hotkey-recorder.js.map +1 -1
  74. package/dist/hotkey-sequence-recorder.cjs +85 -22
  75. package/dist/hotkey-sequence-recorder.cjs.map +1 -1
  76. package/dist/hotkey-sequence-recorder.d.cts +9 -2
  77. package/dist/hotkey-sequence-recorder.d.ts +9 -2
  78. package/dist/hotkey-sequence-recorder.js +84 -21
  79. package/dist/hotkey-sequence-recorder.js.map +1 -1
  80. package/dist/{hotkey.d.ts → hotkey.types.d.cts} +55 -120
  81. package/dist/{hotkey.d.cts → hotkey.types.d.ts} +55 -120
  82. package/dist/index.cjs +18 -10
  83. package/dist/index.d.cts +14 -9
  84. package/dist/index.d.ts +14 -9
  85. package/dist/index.js +10 -6
  86. package/dist/key-state-tracker.cjs +24 -24
  87. package/dist/key-state-tracker.cjs.map +1 -1
  88. package/dist/key-state-tracker.js +24 -24
  89. package/dist/key-state-tracker.js.map +1 -1
  90. package/dist/key.types.d.cts +82 -0
  91. package/dist/key.types.d.ts +82 -0
  92. package/dist/match.cjs +21 -30
  93. package/dist/match.cjs.map +1 -1
  94. package/dist/match.d.cts +19 -3
  95. package/dist/match.d.ts +19 -3
  96. package/dist/match.js +19 -29
  97. package/dist/match.js.map +1 -1
  98. package/dist/parse.cjs +43 -26
  99. package/dist/parse.cjs.map +1 -1
  100. package/dist/parse.d.cts +10 -4
  101. package/dist/parse.d.ts +10 -4
  102. package/dist/parse.js +35 -19
  103. package/dist/parse.js.map +1 -1
  104. package/dist/platform.cjs +55 -0
  105. package/dist/platform.cjs.map +1 -0
  106. package/dist/platform.d.cts +44 -0
  107. package/dist/platform.d.ts +44 -0
  108. package/dist/platform.js +53 -0
  109. package/dist/platform.js.map +1 -0
  110. package/dist/recorder-options.d.cts +34 -0
  111. package/dist/recorder-options.d.ts +34 -0
  112. package/dist/sequence-manager.cjs +54 -28
  113. package/dist/sequence-manager.cjs.map +1 -1
  114. package/dist/sequence-manager.d.cts +18 -3
  115. package/dist/sequence-manager.d.ts +18 -3
  116. package/dist/sequence-manager.js +49 -23
  117. package/dist/sequence-manager.js.map +1 -1
  118. package/dist/validate.cjs +6 -10
  119. package/dist/validate.cjs.map +1 -1
  120. package/dist/validate.d.cts +13 -2
  121. package/dist/validate.d.ts +13 -2
  122. package/dist/validate.js +7 -11
  123. package/dist/validate.js.map +1 -1
  124. package/package.json +1 -1
  125. package/src/{manager.utils.ts → _event-target.ts} +0 -74
  126. package/src/_keyboard-event.ts +101 -0
  127. package/src/_match.ts +96 -0
  128. package/src/_named-keys.ts +62 -0
  129. package/src/_recorder-chord.ts +76 -0
  130. package/src/_recording-guard.ts +63 -0
  131. package/src/_registration.ts +79 -0
  132. package/src/conflicts.ts +125 -0
  133. package/src/constants.ts +48 -196
  134. package/src/display-labels.ts +123 -0
  135. package/src/format.ts +111 -52
  136. package/src/hint.ts +42 -0
  137. package/src/hotkey-manager.ts +95 -40
  138. package/src/hotkey-recorder.ts +91 -15
  139. package/src/hotkey-sequence-recorder.ts +110 -28
  140. package/src/{hotkey.ts → hotkey.types.ts} +57 -224
  141. package/src/index.ts +11 -5
  142. package/src/key-state-tracker.ts +36 -24
  143. package/src/key.types.ts +268 -0
  144. package/src/match.ts +41 -90
  145. package/src/parse.ts +67 -26
  146. package/src/platform.ts +66 -0
  147. package/src/recorder-options.ts +34 -0
  148. package/src/sequence-manager.ts +77 -42
  149. package/src/validate.ts +29 -21
  150. package/dist/manager.utils.cjs.map +0 -1
  151. package/dist/manager.utils.d.cts +0 -13
  152. package/dist/manager.utils.d.ts +0 -13
  153. package/dist/manager.utils.js.map +0 -1
  154. package/dist/recorder-chord.cjs +0 -18
  155. package/dist/recorder-chord.cjs.map +0 -1
  156. package/dist/recorder-chord.js +0 -18
  157. package/dist/recorder-chord.js.map +0 -1
  158. package/src/recorder-chord.ts +0 -25
@@ -0,0 +1,34 @@
1
+ import type { Hotkey, ParsedHotkey } from './hotkey.types'
2
+ import type { HotkeyConflict, HotkeyConflictOptions } from './conflicts'
3
+
4
+ /** Event property used to record a binding. Physical codes are the default. */
5
+ export type RecorderKeyMode = 'code' | 'key'
6
+
7
+ export interface RecorderRejection {
8
+ reason: 'missing-code' | 'alt-graph' | 'invalid' | 'conflict' | 'validation'
9
+ message: string
10
+ hotkey?: Hotkey
11
+ sequence?: Array<Hotkey>
12
+ conflicts?: Array<HotkeyConflict>
13
+ }
14
+
15
+ export interface RecorderOptions {
16
+ /** Physical code recording is the default. Choose key to record logical characters. */
17
+ recordBy?: RecorderKeyMode
18
+ /** Platform used for Mod and AltGraph handling. Defaults to platform detection. */
19
+ platform?: 'mac' | 'windows' | 'linux'
20
+ /** Opt in to live-registry conflicts, including sequence prefixes. Default: false. */
21
+ detectConflicts?: boolean | HotkeyConflictOptions
22
+ /** Rejected candidates leave recording active. */
23
+ onReject?: (rejection: RecorderRejection) => void
24
+ }
25
+
26
+ export interface HotkeyRecorderValidationContext {
27
+ event: KeyboardEvent
28
+ parsedHotkey: ParsedHotkey
29
+ }
30
+
31
+ export interface HotkeySequenceRecorderValidationContext {
32
+ events: ReadonlyArray<KeyboardEvent>
33
+ parsedSequence: ReadonlyArray<ParsedHotkey>
34
+ }
@@ -1,24 +1,28 @@
1
1
  import { Store } from '@tanstack/store'
2
+ import { isRecordingEvent } from './_recording-guard'
2
3
  import { formatHotkeySequence } from './format'
3
- import { detectPlatform, normalizeKeyName } from './constants'
4
+ import { detectPlatform } from './platform'
5
+ import { normalizeKeyName } from './constants'
4
6
  import { isModifierKey, parseHotkey } from './parse'
5
- import { matchesKeyboardEvent } from './match'
7
+ import { areHotkeysEqual, matchesKeyboardEvent } from './match'
8
+ import { matchKeyboardEvent } from './_match'
9
+ import { normalizeKeyboardEvent } from './_keyboard-event'
6
10
  import {
7
11
  defaultHotkeyOptions,
8
12
  getDefaultIgnoreInputs,
9
13
  handleConflict,
10
- isEventForTarget,
11
- shouldIgnoreInputEvent,
12
- } from './manager.utils'
14
+ optionsEqual,
15
+ } from './_registration'
16
+ import { isEventForTarget, shouldIgnoreInputEvent } from './_event-target'
13
17
  import type { HotkeyOptions } from './hotkey-manager'
14
18
  import type {
15
19
  Hotkey,
16
20
  HotkeyCallback,
17
21
  HotkeyCallbackContext,
18
22
  ParsedHotkey,
19
- } from './hotkey'
23
+ } from './hotkey.types'
20
24
 
21
- type Target = HTMLElement | Document | Window
25
+ export type Target = HTMLElement | Document | Window
22
26
 
23
27
  /**
24
28
  * Options for hotkey sequence matching.
@@ -35,7 +39,7 @@ export interface SequenceOptions extends Omit<HotkeyOptions, 'requireReset'> {
35
39
  * Each element is one step (a `Hotkey` string). Steps may include modifiers;
36
40
  * the same modifier can appear on consecutive steps (e.g. `Shift+R` then
37
41
  * `Shift+T`). Modifier-only key events do not advance or reset matching—see
38
- * `SequenceManager`.
42
+ * `SequenceManager`. Automatic keydown repeats and IME composition are also ignored.
39
43
  *
40
44
  * @example
41
45
  * ```ts
@@ -62,13 +66,6 @@ function generateSequenceId(): string {
62
66
  return `sequence_${++sequenceIdCounter}`
63
67
  }
64
68
 
65
- /**
66
- * Returns a canonical string for sequence conflict comparison.
67
- */
68
- function sequenceKey(sequence: HotkeySequence): string {
69
- return sequence.join('|')
70
- }
71
-
72
69
  /**
73
70
  * View of a sequence registration for devtools display.
74
71
  * Progress fields reflect an in-progress match (between first key and completion or timeout).
@@ -90,7 +87,7 @@ export interface SequenceRegistrationView {
90
87
  /**
91
88
  * Internal representation of a sequence registration.
92
89
  */
93
- interface SequenceRegistration {
90
+ export interface SequenceRegistration {
94
91
  id: string
95
92
  sequence: HotkeySequence
96
93
  parsedSequence: Array<ParsedHotkey>
@@ -253,7 +250,7 @@ export class SequenceManager {
253
250
 
254
251
  // Check for existing registrations with the same sequence and target
255
252
  const conflictingRegistration = this.#findConflictingSequence(
256
- sequence,
253
+ parsedSequence,
257
254
  target,
258
255
  )
259
256
 
@@ -325,7 +322,10 @@ export class SequenceManager {
325
322
  },
326
323
  setOptions: (newOptions: Partial<SequenceOptions>) => {
327
324
  const reg = manager.#registrations.get(id)
328
- if (reg) {
325
+ if (
326
+ reg &&
327
+ !optionsEqual(reg.options, { ...reg.options, ...newOptions })
328
+ ) {
329
329
  reg.options = { ...reg.options, ...newOptions }
330
330
  manager.registrations.setState((prev) =>
331
331
  new Map(prev).set(id, toRegistrationView(reg)),
@@ -438,6 +438,22 @@ export class SequenceManager {
438
438
  target: Target,
439
439
  eventType: 'keydown' | 'keyup',
440
440
  ): void {
441
+ if (isRecordingEvent(event)) {
442
+ for (const id of this.#targetRegistrations.get(target) ?? []) {
443
+ const registration = this.#registrations.get(id)
444
+ if (registration && registration.currentIndex > 0) {
445
+ registration.currentIndex = 0
446
+ this.#syncRegistrationView(registration)
447
+ }
448
+ }
449
+ return
450
+ }
451
+ if (
452
+ (event.type === 'keydown' && event.repeat) ||
453
+ normalizeKeyboardEvent(event).isComposing
454
+ ) {
455
+ return
456
+ }
441
457
  // Skip modifier-only events so pressing e.g. Shift before Shift+C does not reset the sequence.
442
458
  if (isModifierKey(normalizeKeyName(event.key))) {
443
459
  return
@@ -449,6 +465,9 @@ export class SequenceManager {
449
465
  }
450
466
 
451
467
  const now = Date.now()
468
+ // Score eligible next steps (or restarts) before advancing any sequence.
469
+ const candidates = new Map<string, { score: number; nextIndex: number }>()
470
+ let bestScore = 0
452
471
 
453
472
  registrationIds: for (const id of targetRegs) {
454
473
  const registration = this.#registrations.get(id)
@@ -493,15 +512,30 @@ export class SequenceManager {
493
512
  continue
494
513
  }
495
514
 
496
- if (
497
- matchesKeyboardEvent(
515
+ let match = matchKeyboardEvent(
516
+ event,
517
+ expectedHotkey,
518
+ registration.options.platform,
519
+ )
520
+ let nextIndex = registration.currentIndex + 1
521
+ if (!match.matched && registration.currentIndex > 0) {
522
+ match = matchKeyboardEvent(
498
523
  event,
499
- expectedHotkey,
524
+ registration.parsedSequence[0]!,
500
525
  registration.options.platform,
501
526
  )
502
- ) {
527
+ nextIndex = 1
528
+ }
529
+ candidates.set(id, { score: match.score, nextIndex })
530
+ bestScore = Math.max(bestScore, match.score)
531
+ }
532
+
533
+ for (const [id, candidate] of candidates) {
534
+ const registration = this.#registrations.get(id)
535
+ if (!registration || !registration.options.enabled) continue
536
+ if (candidate.score > 0 && candidate.score === bestScore) {
503
537
  registration.lastKeyTime = now
504
- registration.currentIndex++
538
+ registration.currentIndex = candidate.nextIndex
505
539
 
506
540
  if (registration.currentIndex >= registration.parsedSequence.length) {
507
541
  if (registration.options.preventDefault) {
@@ -530,36 +564,27 @@ export class SequenceManager {
530
564
  this.#syncRegistrationView(registration)
531
565
  }
532
566
  } else if (registration.currentIndex > 0) {
533
- const firstHotkey = registration.parsedSequence[0]!
534
- if (
535
- matchesKeyboardEvent(
536
- event,
537
- firstHotkey,
538
- registration.options.platform,
539
- )
540
- ) {
541
- registration.currentIndex = 1
542
- registration.lastKeyTime = now
543
- } else {
544
- registration.currentIndex = 0
545
- }
567
+ // A mismatched or weaker candidate cannot carry stale progress forward.
568
+ registration.currentIndex = 0
546
569
  this.#syncRegistrationView(registration)
547
570
  }
548
571
  }
549
572
  }
550
573
 
551
574
  /**
552
- * Finds an existing registration with the same sequence and target.
575
+ * Compares resolved step identities without changing the supplied sequence strings.
553
576
  */
554
577
  #findConflictingSequence(
555
- sequence: HotkeySequence,
578
+ parsedSequence: Array<ParsedHotkey>,
556
579
  target: Target,
557
580
  ): SequenceRegistration | null {
558
- const key = sequenceKey(sequence)
559
581
  for (const registration of this.#registrations.values()) {
560
582
  if (
561
- sequenceKey(registration.sequence) === key &&
562
- registration.target === target
583
+ registration.target === target &&
584
+ registration.parsedSequence.length === parsedSequence.length &&
585
+ parsedSequence.every((step, index) =>
586
+ areHotkeysEqual(step, registration.parsedSequence[index]!),
587
+ )
563
588
  ) {
564
589
  return registration
565
590
  }
@@ -600,7 +625,9 @@ export class SequenceManager {
600
625
  const syntheticEvent = new KeyboardEvent(
601
626
  registration.options.eventType ?? 'keydown',
602
627
  {
603
- key: lastParsed.key,
628
+ ...(lastParsed.code !== undefined
629
+ ? { code: lastParsed.code }
630
+ : { key: lastParsed.key }),
604
631
  ctrlKey: lastParsed.ctrl,
605
632
  shiftKey: lastParsed.shift,
606
633
  altKey: lastParsed.alt,
@@ -691,6 +718,14 @@ export function createSequenceMatcher(
691
718
 
692
719
  return {
693
720
  match(event: KeyboardEvent): boolean {
721
+ // These events are not sequence steps and must not refresh the timeout.
722
+ if (
723
+ (event.type === 'keydown' && event.repeat) ||
724
+ normalizeKeyboardEvent(event, platform).isComposing ||
725
+ isModifierKey(normalizeKeyName(event.key))
726
+ ) {
727
+ return false
728
+ }
694
729
  const now = Date.now()
695
730
 
696
731
  if (currentIndex > 0 && now - lastKeyTime > timeout) {
package/src/validate.ts CHANGED
@@ -1,5 +1,6 @@
1
- import { ALL_KEYS, MODIFIER_ALIASES } from './constants'
2
- import type { Hotkey, ValidationResult } from './hotkey'
1
+ import { ALL_KEYS, MODIFIER_ALIASES, normalizeKeyName } from './constants'
2
+ import { splitHotkeyParts } from './_keyboard-event'
3
+ import type { Hotkey } from './hotkey.types'
3
4
 
4
5
  /**
5
6
  * Validates a hotkey string and returns any warnings or errors.
@@ -36,7 +37,7 @@ export function validateHotkey(
36
37
  }
37
38
  }
38
39
 
39
- const parts = hotkey.split('+').map((p) => p.trim())
40
+ const parts = splitHotkeyParts(hotkey).map((p) => p.trim())
40
41
 
41
42
  // Must have at least one part (the key)
42
43
  if (parts.length === 0 || parts.some((p) => p === '')) {
@@ -60,8 +61,18 @@ export function validateHotkey(
60
61
  }
61
62
  }
62
63
 
64
+ if (
65
+ keyPart.length > 1 &&
66
+ (keyPart.startsWith('[') || keyPart.endsWith(']')) &&
67
+ !/^\[[A-Za-z][A-Za-z0-9]*\]$/.test(keyPart)
68
+ ) {
69
+ errors.push(
70
+ 'Invalid physical key: use a bracketed KeyboardEvent.code, such as [KeyS]',
71
+ )
72
+ }
73
+
63
74
  // Check if key is known
64
- const normalizedKey = normalizeKeyForValidation(keyPart)
75
+ const normalizedKey = normalizeKeyName(keyPart)
65
76
  if (!isKnownKey(normalizedKey) && !isKnownKey(keyPart)) {
66
77
  warnings.push(
67
78
  `Unknown key: '${keyPart}'. This may still work but won't have type-safe autocomplete.`,
@@ -75,27 +86,12 @@ export function validateHotkey(
75
86
  }
76
87
  }
77
88
 
78
- /**
79
- * Normalizes a key for validation checking.
80
- */
81
- function normalizeKeyForValidation(key: string): string {
82
- // Single letter to uppercase
83
- if (key.length === 1 && /^[a-zA-Z]$/.test(key)) {
84
- return key.toUpperCase()
85
- }
86
-
87
- // Function keys to uppercase
88
- if (/^f([1-9]|1[0-2])$/i.test(key)) {
89
- return key.toUpperCase()
90
- }
91
-
92
- return key
93
- }
94
-
95
89
  /**
96
90
  * Checks if a key is in the known keys set.
97
91
  */
98
92
  function isKnownKey(key: string): boolean {
93
+ if (/^\[[A-Za-z][A-Za-z0-9]*\]$/.test(key)) return true
94
+ if (Array.from(key).length === 1) return true
99
95
  // Check direct match
100
96
  if (ALL_KEYS.has(key as any)) {
101
97
  return true
@@ -169,3 +165,15 @@ export function checkHotkey(hotkey: Hotkey | (string & {})): boolean {
169
165
 
170
166
  return result.valid
171
167
  }
168
+
169
+ /**
170
+ * Result of validating a hotkey string.
171
+ */
172
+ export interface ValidationResult {
173
+ /** Whether the hotkey is valid (can still have warnings) */
174
+ valid: boolean
175
+ /** Warning messages about potential issues */
176
+ warnings: Array<string>
177
+ /** Error messages about invalid syntax */
178
+ errors: Array<string>
179
+ }
@@ -1 +0,0 @@
1
- {"version":3,"file":"manager.utils.cjs","names":[],"sources":["../src/manager.utils.ts"],"sourcesContent":["import type { ParsedHotkey } from './hotkey'\n\n/**\n * Behavior when registering a hotkey/sequence that conflicts with an existing registration.\n *\n * - `'warn'` - Log a warning to the console but allow both registrations (default)\n * - `'error'` - Throw an error and prevent the new registration\n * - `'replace'` - Unregister the existing registration and register the new one\n * - `'allow'` - Allow multiple registrations without warning\n */\nexport type ConflictBehavior = 'warn' | 'error' | 'replace' | 'allow'\n\n/**\n * Default options for hotkey/sequence registration.\n * Omitted: platform, target (resolved at registration), requireReset (HotkeyManager only).\n */\nexport const defaultHotkeyOptions = {\n preventDefault: true,\n stopPropagation: true,\n eventType: 'keydown' as const,\n enabled: true,\n ignoreInputs: true,\n conflictBehavior: 'warn' as ConflictBehavior,\n}\n\n/**\n * Computes the default ignoreInputs value based on the hotkey.\n * Ctrl/Meta shortcuts and Escape fire in inputs; single keys and Shift/Alt combos are ignored.\n */\nexport function getDefaultIgnoreInputs(parsedHotkey: ParsedHotkey): boolean {\n if (parsedHotkey.ctrl || parsedHotkey.meta) return false // Mod+S, Ctrl+C, etc.\n if (parsedHotkey.key === 'Escape') return false // Close modal, etc.\n return true // Single keys, Shift+key, Alt+key\n}\n\n/**\n * Checks if an element is an input-like element that should be ignored for hotkeys.\n *\n * This includes:\n * - HTMLInputElement (all input types except button, submit, reset)\n * - HTMLTextAreaElement\n * - HTMLSelectElement\n * - Elements with contentEditable enabled\n *\n * Button-type inputs (button, submit, reset) are excluded so hotkeys like\n * Mod+S and Escape fire when the user has tabbed to a form button.\n */\nexport function isInputElement(element: EventTarget | null): boolean {\n if (!element) {\n return false\n }\n\n if (element instanceof HTMLInputElement) {\n const type = element.type.toLowerCase()\n if (type === 'button' || type === 'submit' || type === 'reset') {\n return false\n }\n return true\n }\n\n if (\n element instanceof HTMLTextAreaElement ||\n element instanceof HTMLSelectElement\n ) {\n return true\n }\n\n // Check for contenteditable elements (includes \"true\", \"\", \"plaintext-only\",\n // and inherited contenteditable from ancestor elements)\n if (element instanceof HTMLElement && element.isContentEditable) {\n return true\n }\n\n return false\n}\n\n/**\n * Returns the focused element for the document associated with where hotkey\n * listeners are attached (listener root). Use this instead of the global\n * `document.activeElement` so registrations scoped to an iframe (or another\n * document) read focus from the correct tree.\n */\nexport function getActiveElementForListenerTarget(\n target: HTMLElement | Document | Window,\n): Element | null {\n if (typeof document === 'undefined') {\n return null\n }\n\n // Document first (nodeType covers environments where `document instanceof Document` is false)\n if (\n (typeof Document !== 'undefined' && target instanceof Document) ||\n (typeof Node !== 'undefined' &&\n (target as Node).nodeType === Node.DOCUMENT_NODE)\n ) {\n return (target as Document).activeElement\n }\n\n if (typeof HTMLElement !== 'undefined' && target instanceof HTMLElement) {\n return target.ownerDocument.activeElement ?? null\n }\n\n // Window (global or iframe): avoid relying on `instanceof Window` alone (test DOM quirks)\n return (target as Window).document.activeElement ?? null\n}\n\n/**\n * Returns whether an event should be ignored because it originated from an\n * input-like element other than the registration target.\n *\n * This checks:\n * - the currently focused element for the listener target\n * - the event's composed path (for shadow DOM)\n * - the event target as a final fallback\n */\nexport function shouldIgnoreInputEvent(\n event: KeyboardEvent,\n listenerTarget: HTMLElement | Document | Window,\n registrationTarget: HTMLElement | Document | Window,\n): boolean {\n const focused = getActiveElementForListenerTarget(listenerTarget)\n if (focused && isInputElement(focused) && focused !== registrationTarget) {\n return true\n }\n\n if (\n event\n .composedPath()\n .some(\n (element) => isInputElement(element) && element !== registrationTarget,\n )\n ) {\n return true\n }\n\n return isInputElement(event.target) && event.target !== registrationTarget\n}\n\n/**\n * Checks if an event is for the given target (originated from or bubbled to it).\n *\n * For document/window targets, also accepts document.documentElement as currentTarget\n * to handle Brave and other browsers where currentTarget may be documentElement\n * instead of document when listeners are attached to document.\n */\nexport function isEventForTarget(\n event: KeyboardEvent,\n target: HTMLElement | Document | Window,\n): boolean {\n // For Document and Window, verify that our handler was indeed called for this target.\n //\n // Browser compatibility note:\n // Per the DOM spec, event.currentTarget should equal the element the listener was\n // attached to. However, some Chromium-based browsers (notably Brave) exhibit\n // non-standard behavior where event.currentTarget is set to document.documentElement\n // (<html>) instead of document when a listener is attached to document.\n // This may be related to privacy/fingerprinting protections.\n //\n // To ensure cross-browser compatibility, we accept both the expected target\n // and document.documentElement as valid currentTarget values.\n // See: https://dom.spec.whatwg.org/#dom-event-currenttarget\n if (target === document || target === window) {\n return (\n event.currentTarget === target ||\n event.currentTarget === document.documentElement\n )\n }\n\n // For Window, accept window, document, or document.documentElement (browser quirks)\n if (target === window) {\n return (\n event.currentTarget === window ||\n event.currentTarget === document ||\n event.currentTarget === document.documentElement\n )\n }\n\n // For HTMLElement, check if event originated from or bubbled to the element\n if (target instanceof HTMLElement) {\n // Check if the event's currentTarget is the target (capturing/bubbling)\n if (event.currentTarget === target) {\n return true\n }\n\n // Check if the event's target is a descendant of our target\n if (event.target instanceof Node && target.contains(event.target)) {\n return true\n }\n }\n\n return false\n}\n\n/**\n * Handles conflicts between registrations based on conflict behavior.\n *\n * @param conflictingId - The ID of the conflicting registration\n * @param keyDisplay - Display string for the conflicting key/sequence (for error messages)\n * @param conflictBehavior - How to handle the conflict\n * @param unregister - Function to unregister by ID\n */\nexport function handleConflict(\n conflictingId: string,\n keyDisplay: string,\n conflictBehavior: ConflictBehavior,\n unregister: (id: string) => void,\n): void {\n if (conflictBehavior === 'allow') {\n return\n }\n\n if (conflictBehavior === 'warn') {\n console.warn(\n `'${keyDisplay}' is already registered. Multiple handlers will be triggered. ` +\n `Use conflictBehavior: 'replace' to replace the existing handler, ` +\n `or conflictBehavior: 'allow' to suppress this warning.`,\n )\n return\n }\n\n if (conflictBehavior === 'error') {\n throw new Error(\n `'${keyDisplay}' is already registered. ` +\n `Use conflictBehavior: 'replace' to replace the existing handler, ` +\n `or conflictBehavior: 'allow' to allow multiple registrations.`,\n )\n }\n\n // At this point, conflictBehavior must be 'replace'\n unregister(conflictingId)\n}\n"],"mappings":";;;;;;AAgBA,MAAa,uBAAuB;CAClC,gBAAgB;CAChB,iBAAiB;CACjB,WAAW;CACX,SAAS;CACT,cAAc;CACd,kBAAkB;CACnB;;;;;AAMD,SAAgB,uBAAuB,cAAqC;AAC1E,KAAI,aAAa,QAAQ,aAAa,KAAM,QAAO;AACnD,KAAI,aAAa,QAAQ,SAAU,QAAO;AAC1C,QAAO;;;;;;;;;;;;;;AAeT,SAAgB,eAAe,SAAsC;AACnE,KAAI,CAAC,QACH,QAAO;AAGT,KAAI,mBAAmB,kBAAkB;EACvC,MAAM,OAAO,QAAQ,KAAK,aAAa;AACvC,MAAI,SAAS,YAAY,SAAS,YAAY,SAAS,QACrD,QAAO;AAET,SAAO;;AAGT,KACE,mBAAmB,uBACnB,mBAAmB,kBAEnB,QAAO;AAKT,KAAI,mBAAmB,eAAe,QAAQ,kBAC5C,QAAO;AAGT,QAAO;;;;;;;;AAST,SAAgB,kCACd,QACgB;AAChB,KAAI,OAAO,aAAa,YACtB,QAAO;AAIT,KACG,OAAO,aAAa,eAAe,kBAAkB,YACrD,OAAO,SAAS,eACd,OAAgB,aAAa,KAAK,cAErC,QAAQ,OAAoB;AAG9B,KAAI,OAAO,gBAAgB,eAAe,kBAAkB,YAC1D,QAAO,OAAO,cAAc,iBAAiB;AAI/C,QAAQ,OAAkB,SAAS,iBAAiB;;;;;;;;;;;AAYtD,SAAgB,uBACd,OACA,gBACA,oBACS;CACT,MAAM,UAAU,kCAAkC,eAAe;AACjE,KAAI,WAAW,eAAe,QAAQ,IAAI,YAAY,mBACpD,QAAO;AAGT,KACE,MACG,cAAc,CACd,MACE,YAAY,eAAe,QAAQ,IAAI,YAAY,mBACrD,CAEH,QAAO;AAGT,QAAO,eAAe,MAAM,OAAO,IAAI,MAAM,WAAW;;;;;;;;;AAU1D,SAAgB,iBACd,OACA,QACS;AAaT,KAAI,WAAW,YAAY,WAAW,OACpC,QACE,MAAM,kBAAkB,UACxB,MAAM,kBAAkB,SAAS;AAKrC,KAAI,WAAW,OACb,QACE,MAAM,kBAAkB,UACxB,MAAM,kBAAkB,YACxB,MAAM,kBAAkB,SAAS;AAKrC,KAAI,kBAAkB,aAAa;AAEjC,MAAI,MAAM,kBAAkB,OAC1B,QAAO;AAIT,MAAI,MAAM,kBAAkB,QAAQ,OAAO,SAAS,MAAM,OAAO,CAC/D,QAAO;;AAIX,QAAO;;;;;;;;;;AAWT,SAAgB,eACd,eACA,YACA,kBACA,YACM;AACN,KAAI,qBAAqB,QACvB;AAGF,KAAI,qBAAqB,QAAQ;AAC/B,UAAQ,KACN,IAAI,WAAW,uLAGhB;AACD;;AAGF,KAAI,qBAAqB,QACvB,OAAM,IAAI,MACR,IAAI,WAAW,yJAGhB;AAIH,YAAW,cAAc"}
@@ -1,13 +0,0 @@
1
- //#region src/manager.utils.d.ts
2
- /**
3
- * Behavior when registering a hotkey/sequence that conflicts with an existing registration.
4
- *
5
- * - `'warn'` - Log a warning to the console but allow both registrations (default)
6
- * - `'error'` - Throw an error and prevent the new registration
7
- * - `'replace'` - Unregister the existing registration and register the new one
8
- * - `'allow'` - Allow multiple registrations without warning
9
- */
10
- type ConflictBehavior = 'warn' | 'error' | 'replace' | 'allow';
11
- //#endregion
12
- export { ConflictBehavior };
13
- //# sourceMappingURL=manager.utils.d.cts.map
@@ -1,13 +0,0 @@
1
- //#region src/manager.utils.d.ts
2
- /**
3
- * Behavior when registering a hotkey/sequence that conflicts with an existing registration.
4
- *
5
- * - `'warn'` - Log a warning to the console but allow both registrations (default)
6
- * - `'error'` - Throw an error and prevent the new registration
7
- * - `'replace'` - Unregister the existing registration and register the new one
8
- * - `'allow'` - Allow multiple registrations without warning
9
- */
10
- type ConflictBehavior = 'warn' | 'error' | 'replace' | 'allow';
11
- //#endregion
12
- export { ConflictBehavior };
13
- //# sourceMappingURL=manager.utils.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"manager.utils.js","names":[],"sources":["../src/manager.utils.ts"],"sourcesContent":["import type { ParsedHotkey } from './hotkey'\n\n/**\n * Behavior when registering a hotkey/sequence that conflicts with an existing registration.\n *\n * - `'warn'` - Log a warning to the console but allow both registrations (default)\n * - `'error'` - Throw an error and prevent the new registration\n * - `'replace'` - Unregister the existing registration and register the new one\n * - `'allow'` - Allow multiple registrations without warning\n */\nexport type ConflictBehavior = 'warn' | 'error' | 'replace' | 'allow'\n\n/**\n * Default options for hotkey/sequence registration.\n * Omitted: platform, target (resolved at registration), requireReset (HotkeyManager only).\n */\nexport const defaultHotkeyOptions = {\n preventDefault: true,\n stopPropagation: true,\n eventType: 'keydown' as const,\n enabled: true,\n ignoreInputs: true,\n conflictBehavior: 'warn' as ConflictBehavior,\n}\n\n/**\n * Computes the default ignoreInputs value based on the hotkey.\n * Ctrl/Meta shortcuts and Escape fire in inputs; single keys and Shift/Alt combos are ignored.\n */\nexport function getDefaultIgnoreInputs(parsedHotkey: ParsedHotkey): boolean {\n if (parsedHotkey.ctrl || parsedHotkey.meta) return false // Mod+S, Ctrl+C, etc.\n if (parsedHotkey.key === 'Escape') return false // Close modal, etc.\n return true // Single keys, Shift+key, Alt+key\n}\n\n/**\n * Checks if an element is an input-like element that should be ignored for hotkeys.\n *\n * This includes:\n * - HTMLInputElement (all input types except button, submit, reset)\n * - HTMLTextAreaElement\n * - HTMLSelectElement\n * - Elements with contentEditable enabled\n *\n * Button-type inputs (button, submit, reset) are excluded so hotkeys like\n * Mod+S and Escape fire when the user has tabbed to a form button.\n */\nexport function isInputElement(element: EventTarget | null): boolean {\n if (!element) {\n return false\n }\n\n if (element instanceof HTMLInputElement) {\n const type = element.type.toLowerCase()\n if (type === 'button' || type === 'submit' || type === 'reset') {\n return false\n }\n return true\n }\n\n if (\n element instanceof HTMLTextAreaElement ||\n element instanceof HTMLSelectElement\n ) {\n return true\n }\n\n // Check for contenteditable elements (includes \"true\", \"\", \"plaintext-only\",\n // and inherited contenteditable from ancestor elements)\n if (element instanceof HTMLElement && element.isContentEditable) {\n return true\n }\n\n return false\n}\n\n/**\n * Returns the focused element for the document associated with where hotkey\n * listeners are attached (listener root). Use this instead of the global\n * `document.activeElement` so registrations scoped to an iframe (or another\n * document) read focus from the correct tree.\n */\nexport function getActiveElementForListenerTarget(\n target: HTMLElement | Document | Window,\n): Element | null {\n if (typeof document === 'undefined') {\n return null\n }\n\n // Document first (nodeType covers environments where `document instanceof Document` is false)\n if (\n (typeof Document !== 'undefined' && target instanceof Document) ||\n (typeof Node !== 'undefined' &&\n (target as Node).nodeType === Node.DOCUMENT_NODE)\n ) {\n return (target as Document).activeElement\n }\n\n if (typeof HTMLElement !== 'undefined' && target instanceof HTMLElement) {\n return target.ownerDocument.activeElement ?? null\n }\n\n // Window (global or iframe): avoid relying on `instanceof Window` alone (test DOM quirks)\n return (target as Window).document.activeElement ?? null\n}\n\n/**\n * Returns whether an event should be ignored because it originated from an\n * input-like element other than the registration target.\n *\n * This checks:\n * - the currently focused element for the listener target\n * - the event's composed path (for shadow DOM)\n * - the event target as a final fallback\n */\nexport function shouldIgnoreInputEvent(\n event: KeyboardEvent,\n listenerTarget: HTMLElement | Document | Window,\n registrationTarget: HTMLElement | Document | Window,\n): boolean {\n const focused = getActiveElementForListenerTarget(listenerTarget)\n if (focused && isInputElement(focused) && focused !== registrationTarget) {\n return true\n }\n\n if (\n event\n .composedPath()\n .some(\n (element) => isInputElement(element) && element !== registrationTarget,\n )\n ) {\n return true\n }\n\n return isInputElement(event.target) && event.target !== registrationTarget\n}\n\n/**\n * Checks if an event is for the given target (originated from or bubbled to it).\n *\n * For document/window targets, also accepts document.documentElement as currentTarget\n * to handle Brave and other browsers where currentTarget may be documentElement\n * instead of document when listeners are attached to document.\n */\nexport function isEventForTarget(\n event: KeyboardEvent,\n target: HTMLElement | Document | Window,\n): boolean {\n // For Document and Window, verify that our handler was indeed called for this target.\n //\n // Browser compatibility note:\n // Per the DOM spec, event.currentTarget should equal the element the listener was\n // attached to. However, some Chromium-based browsers (notably Brave) exhibit\n // non-standard behavior where event.currentTarget is set to document.documentElement\n // (<html>) instead of document when a listener is attached to document.\n // This may be related to privacy/fingerprinting protections.\n //\n // To ensure cross-browser compatibility, we accept both the expected target\n // and document.documentElement as valid currentTarget values.\n // See: https://dom.spec.whatwg.org/#dom-event-currenttarget\n if (target === document || target === window) {\n return (\n event.currentTarget === target ||\n event.currentTarget === document.documentElement\n )\n }\n\n // For Window, accept window, document, or document.documentElement (browser quirks)\n if (target === window) {\n return (\n event.currentTarget === window ||\n event.currentTarget === document ||\n event.currentTarget === document.documentElement\n )\n }\n\n // For HTMLElement, check if event originated from or bubbled to the element\n if (target instanceof HTMLElement) {\n // Check if the event's currentTarget is the target (capturing/bubbling)\n if (event.currentTarget === target) {\n return true\n }\n\n // Check if the event's target is a descendant of our target\n if (event.target instanceof Node && target.contains(event.target)) {\n return true\n }\n }\n\n return false\n}\n\n/**\n * Handles conflicts between registrations based on conflict behavior.\n *\n * @param conflictingId - The ID of the conflicting registration\n * @param keyDisplay - Display string for the conflicting key/sequence (for error messages)\n * @param conflictBehavior - How to handle the conflict\n * @param unregister - Function to unregister by ID\n */\nexport function handleConflict(\n conflictingId: string,\n keyDisplay: string,\n conflictBehavior: ConflictBehavior,\n unregister: (id: string) => void,\n): void {\n if (conflictBehavior === 'allow') {\n return\n }\n\n if (conflictBehavior === 'warn') {\n console.warn(\n `'${keyDisplay}' is already registered. Multiple handlers will be triggered. ` +\n `Use conflictBehavior: 'replace' to replace the existing handler, ` +\n `or conflictBehavior: 'allow' to suppress this warning.`,\n )\n return\n }\n\n if (conflictBehavior === 'error') {\n throw new Error(\n `'${keyDisplay}' is already registered. ` +\n `Use conflictBehavior: 'replace' to replace the existing handler, ` +\n `or conflictBehavior: 'allow' to allow multiple registrations.`,\n )\n }\n\n // At this point, conflictBehavior must be 'replace'\n unregister(conflictingId)\n}\n"],"mappings":";;;;;AAgBA,MAAa,uBAAuB;CAClC,gBAAgB;CAChB,iBAAiB;CACjB,WAAW;CACX,SAAS;CACT,cAAc;CACd,kBAAkB;CACnB;;;;;AAMD,SAAgB,uBAAuB,cAAqC;AAC1E,KAAI,aAAa,QAAQ,aAAa,KAAM,QAAO;AACnD,KAAI,aAAa,QAAQ,SAAU,QAAO;AAC1C,QAAO;;;;;;;;;;;;;;AAeT,SAAgB,eAAe,SAAsC;AACnE,KAAI,CAAC,QACH,QAAO;AAGT,KAAI,mBAAmB,kBAAkB;EACvC,MAAM,OAAO,QAAQ,KAAK,aAAa;AACvC,MAAI,SAAS,YAAY,SAAS,YAAY,SAAS,QACrD,QAAO;AAET,SAAO;;AAGT,KACE,mBAAmB,uBACnB,mBAAmB,kBAEnB,QAAO;AAKT,KAAI,mBAAmB,eAAe,QAAQ,kBAC5C,QAAO;AAGT,QAAO;;;;;;;;AAST,SAAgB,kCACd,QACgB;AAChB,KAAI,OAAO,aAAa,YACtB,QAAO;AAIT,KACG,OAAO,aAAa,eAAe,kBAAkB,YACrD,OAAO,SAAS,eACd,OAAgB,aAAa,KAAK,cAErC,QAAQ,OAAoB;AAG9B,KAAI,OAAO,gBAAgB,eAAe,kBAAkB,YAC1D,QAAO,OAAO,cAAc,iBAAiB;AAI/C,QAAQ,OAAkB,SAAS,iBAAiB;;;;;;;;;;;AAYtD,SAAgB,uBACd,OACA,gBACA,oBACS;CACT,MAAM,UAAU,kCAAkC,eAAe;AACjE,KAAI,WAAW,eAAe,QAAQ,IAAI,YAAY,mBACpD,QAAO;AAGT,KACE,MACG,cAAc,CACd,MACE,YAAY,eAAe,QAAQ,IAAI,YAAY,mBACrD,CAEH,QAAO;AAGT,QAAO,eAAe,MAAM,OAAO,IAAI,MAAM,WAAW;;;;;;;;;AAU1D,SAAgB,iBACd,OACA,QACS;AAaT,KAAI,WAAW,YAAY,WAAW,OACpC,QACE,MAAM,kBAAkB,UACxB,MAAM,kBAAkB,SAAS;AAKrC,KAAI,WAAW,OACb,QACE,MAAM,kBAAkB,UACxB,MAAM,kBAAkB,YACxB,MAAM,kBAAkB,SAAS;AAKrC,KAAI,kBAAkB,aAAa;AAEjC,MAAI,MAAM,kBAAkB,OAC1B,QAAO;AAIT,MAAI,MAAM,kBAAkB,QAAQ,OAAO,SAAS,MAAM,OAAO,CAC/D,QAAO;;AAIX,QAAO;;;;;;;;;;AAWT,SAAgB,eACd,eACA,YACA,kBACA,YACM;AACN,KAAI,qBAAqB,QACvB;AAGF,KAAI,qBAAqB,QAAQ;AAC/B,UAAQ,KACN,IAAI,WAAW,uLAGhB;AACD;;AAGF,KAAI,qBAAqB,QACvB,OAAM,IAAI,MACR,IAAI,WAAW,yJAGhB;AAIH,YAAW,cAAc"}
@@ -1,18 +0,0 @@
1
- const require_constants = require('./constants.cjs');
2
- const require_parse = require('./parse.cjs');
3
-
4
- //#region src/recorder-chord.ts
5
- /**
6
- * Parses a keydown event into a single normalized hotkey chord, or null if
7
- * the event should be ignored (modifier-only or invalid).
8
- */
9
- function hotkeyChordFromKeydown(event, platform) {
10
- if (require_parse.isModifierKey(require_constants.normalizeKeyName(event.key))) return null;
11
- const finalHotkey = require_parse.normalizeHotkeyFromEvent(event, platform);
12
- if (!require_parse.hasNonModifierKey(finalHotkey, platform)) return null;
13
- return finalHotkey;
14
- }
15
-
16
- //#endregion
17
- exports.hotkeyChordFromKeydown = hotkeyChordFromKeydown;
18
- //# sourceMappingURL=recorder-chord.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"recorder-chord.cjs","names":["isModifierKey","normalizeKeyName","normalizeHotkeyFromEvent","hasNonModifierKey"],"sources":["../src/recorder-chord.ts"],"sourcesContent":["import { normalizeKeyName } from './constants'\nimport {\n hasNonModifierKey,\n isModifierKey,\n normalizeHotkeyFromEvent,\n} from './parse'\nimport type { Hotkey } from './hotkey'\n\n/**\n * Parses a keydown event into a single normalized hotkey chord, or null if\n * the event should be ignored (modifier-only or invalid).\n */\nexport function hotkeyChordFromKeydown(\n event: KeyboardEvent,\n platform: 'mac' | 'windows' | 'linux',\n): Hotkey | null {\n if (isModifierKey(normalizeKeyName(event.key))) {\n return null\n }\n const finalHotkey = normalizeHotkeyFromEvent(event, platform)\n if (!hasNonModifierKey(finalHotkey, platform)) {\n return null\n }\n return finalHotkey\n}\n"],"mappings":";;;;;;;;AAYA,SAAgB,uBACd,OACA,UACe;AACf,KAAIA,4BAAcC,mCAAiB,MAAM,IAAI,CAAC,CAC5C,QAAO;CAET,MAAM,cAAcC,uCAAyB,OAAO,SAAS;AAC7D,KAAI,CAACC,gCAAkB,aAAa,SAAS,CAC3C,QAAO;AAET,QAAO"}
@@ -1,18 +0,0 @@
1
- import { normalizeKeyName } from "./constants.js";
2
- import { hasNonModifierKey, isModifierKey, normalizeHotkeyFromEvent } from "./parse.js";
3
-
4
- //#region src/recorder-chord.ts
5
- /**
6
- * Parses a keydown event into a single normalized hotkey chord, or null if
7
- * the event should be ignored (modifier-only or invalid).
8
- */
9
- function hotkeyChordFromKeydown(event, platform) {
10
- if (isModifierKey(normalizeKeyName(event.key))) return null;
11
- const finalHotkey = normalizeHotkeyFromEvent(event, platform);
12
- if (!hasNonModifierKey(finalHotkey, platform)) return null;
13
- return finalHotkey;
14
- }
15
-
16
- //#endregion
17
- export { hotkeyChordFromKeydown };
18
- //# sourceMappingURL=recorder-chord.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"recorder-chord.js","names":[],"sources":["../src/recorder-chord.ts"],"sourcesContent":["import { normalizeKeyName } from './constants'\nimport {\n hasNonModifierKey,\n isModifierKey,\n normalizeHotkeyFromEvent,\n} from './parse'\nimport type { Hotkey } from './hotkey'\n\n/**\n * Parses a keydown event into a single normalized hotkey chord, or null if\n * the event should be ignored (modifier-only or invalid).\n */\nexport function hotkeyChordFromKeydown(\n event: KeyboardEvent,\n platform: 'mac' | 'windows' | 'linux',\n): Hotkey | null {\n if (isModifierKey(normalizeKeyName(event.key))) {\n return null\n }\n const finalHotkey = normalizeHotkeyFromEvent(event, platform)\n if (!hasNonModifierKey(finalHotkey, platform)) {\n return null\n }\n return finalHotkey\n}\n"],"mappings":";;;;;;;;AAYA,SAAgB,uBACd,OACA,UACe;AACf,KAAI,cAAc,iBAAiB,MAAM,IAAI,CAAC,CAC5C,QAAO;CAET,MAAM,cAAc,yBAAyB,OAAO,SAAS;AAC7D,KAAI,CAAC,kBAAkB,aAAa,SAAS,CAC3C,QAAO;AAET,QAAO"}
@@ -1,25 +0,0 @@
1
- import { normalizeKeyName } from './constants'
2
- import {
3
- hasNonModifierKey,
4
- isModifierKey,
5
- normalizeHotkeyFromEvent,
6
- } from './parse'
7
- import type { Hotkey } from './hotkey'
8
-
9
- /**
10
- * Parses a keydown event into a single normalized hotkey chord, or null if
11
- * the event should be ignored (modifier-only or invalid).
12
- */
13
- export function hotkeyChordFromKeydown(
14
- event: KeyboardEvent,
15
- platform: 'mac' | 'windows' | 'linux',
16
- ): Hotkey | null {
17
- if (isModifierKey(normalizeKeyName(event.key))) {
18
- return null
19
- }
20
- const finalHotkey = normalizeHotkeyFromEvent(event, platform)
21
- if (!hasNonModifierKey(finalHotkey, platform)) {
22
- return null
23
- }
24
- return finalHotkey
25
- }