hotkey-router 0.3.1 → 0.3.3

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.
@@ -1,21 +1,26 @@
1
- // hotkey-router v0.3.1 | SEE LICENSE IN LICENSE
1
+ // hotkey-router v0.3.3 | SEE LICENSE IN LICENSE
2
2
 
3
3
 
4
- // hotkey-router.js
5
- function on(target, type, fn, options) {
6
- target.addEventListener(type, fn, options);
7
- return () => target.removeEventListener(type, fn, options);
4
+ // platform.js
5
+ function fromPlatformString(s) {
6
+ if (!s) return null;
7
+ if (/Chrome ?OS|CrOS/i.test(s)) return "chromeos";
8
+ if (/Mac|iPhone|iPad|iPod/i.test(s)) return "mac";
9
+ if (/Win/i.test(s)) return "windows";
10
+ if (/Linux|X11/i.test(s)) return "linux";
11
+ return null;
8
12
  }
9
- var isMac = typeof navigator !== "undefined" && /Mac|iPhone|iPad|iPod/.test(navigator.platform);
10
- var modifierTokens = /* @__PURE__ */ new Set(["ctrl", "shift", "alt", "meta"]);
11
- var MODIFIER_KEY_TOKEN = Object.freeze({
12
- Alt: "alt",
13
- AltGraph: "alt",
14
- Control: "ctrl",
15
- Shift: "shift",
16
- Meta: "meta",
17
- OS: "meta"
18
- });
13
+ function detectPlatform(nav = typeof navigator !== "undefined" ? navigator : null, { chromeos = false } = {}) {
14
+ if (!nav) return null;
15
+ const ua = nav.userAgent || "";
16
+ const found = (/\bCrOS\b/.test(ua) ? "chromeos" : null) || fromPlatformString(nav.userAgentData?.platform) || fromPlatformString(nav.platform) || (/Mac OS X/i.test(ua) ? "mac" : /Windows/i.test(ua) ? "windows" : /Linux|X11/i.test(ua) ? "linux" : null);
17
+ if (found === "chromeos" && !chromeos) return "linux";
18
+ return found;
19
+ }
20
+
21
+ // parse.js
22
+ var DEFAULT_PLATFORM = detectPlatform();
23
+ var modifierTokens = /* @__PURE__ */ new Set(["ctrl", "shift", "alt", "meta", "mod"]);
19
24
  var ahkPrefixMap = /* @__PURE__ */ new Map([
20
25
  ["^", "ctrl"],
21
26
  // Ctrl
@@ -58,6 +63,7 @@ var keyAliases = Object.freeze({
58
63
  control: "ctrl",
59
64
  ctrl: "ctrl",
60
65
  option: "alt",
66
+ opt: "alt",
61
67
  alt: "alt",
62
68
  shift: "shift",
63
69
  // modifiers (symbols)
@@ -65,19 +71,11 @@ var keyAliases = Object.freeze({
65
71
  "\u2303": "ctrl",
66
72
  "\u2325": "alt",
67
73
  "\u21E7": "shift",
68
- // cross-platform "mod"
69
- mod: isMac ? "meta" : "ctrl",
74
+ // cross-platform "mod", resolved per platform while parsing
75
+ mod: "mod",
70
76
  // plus key ergonomics
71
77
  plus: "+"
72
78
  });
73
- var ignoreEditable = true;
74
- var defaultTarget = typeof window !== "undefined" ? window : null;
75
- var bindHooks = [];
76
- var registry = /* @__PURE__ */ new Map();
77
- var plugins = /* @__PURE__ */ new Map();
78
- var bindingIndex = /* @__PURE__ */ new Map();
79
- var paused = false;
80
- var nextId = 1;
81
79
  function normalizeKey(key) {
82
80
  const original = String(key ?? "");
83
81
  if (original === " ") return " ";
@@ -85,43 +83,16 @@ function normalizeKey(key) {
85
83
  const k = trimmed.toLowerCase();
86
84
  return keyAliases[k] ?? k;
87
85
  }
88
- function comboKeyFromParts({ ctrl, shift, alt, meta, key, code, bareModifier }) {
89
- if (bareModifier) return `__bare__:${bareModifier}`;
90
- let s = "";
91
- if (ctrl) s += "ctrl+";
92
- if (shift) s += "shift+";
93
- if (alt) s += "alt+";
94
- if (meta) s += "meta+";
95
- if (code) return s + "code:" + code;
96
- return s ? s + key : key;
97
- }
98
- function comboKeyFromEvent(e) {
99
- const bareMod = MODIFIER_KEY_TOKEN[e.key];
100
- if (bareMod) return `__bare__:${bareMod}`;
101
- return comboKeyFromParts({
102
- ctrl: e.ctrlKey,
103
- shift: e.shiftKey,
104
- alt: e.altKey,
105
- meta: e.metaKey,
106
- key: normalizeKey(e.key)
107
- });
108
- }
109
- function codeKeyFromEvent(e) {
110
- if (!e.code) return null;
111
- let s = "";
112
- if (e.ctrlKey) s += "ctrl+";
113
- if (e.shiftKey) s += "shift+";
114
- if (e.altKey) s += "alt+";
115
- if (e.metaKey) s += "meta+";
116
- return s + "code:" + e.code;
117
- }
118
86
  function isModifierToken(token) {
119
- const t = normalizeKey(token);
120
- return modifierTokens.has(t);
87
+ return modifierTokens.has(normalizeKey(token));
121
88
  }
122
89
  var CODE_TOKEN_RE = /(^|\+)code:([A-Za-z][A-Za-z0-9_]*)/;
123
- function parseHotkey(hotkeyStr) {
90
+ function readHotkey(hotkeyStr, { platform = DEFAULT_PLATFORM } = {}) {
124
91
  const raw = String(hotkeyStr || "").trim();
92
+ let error = null;
93
+ const fail = (msg) => {
94
+ error = error || `Invalid hotkey "${hotkeyStr}": ${msg}`;
95
+ };
125
96
  const isUp = /\s+up$/i.test(raw);
126
97
  const baseRaw = isUp ? raw.replace(/\s+up$/i, "").trim() : raw;
127
98
  const combo = {
@@ -133,25 +104,27 @@ function parseHotkey(hotkeyStr) {
133
104
  code: null,
134
105
  bareModifier: null
135
106
  };
107
+ const setMod = (mod) => {
108
+ if (mod === "mod") combo[platform === "mac" ? "meta" : "ctrl"] = true;
109
+ else combo[mod] = true;
110
+ };
136
111
  let stripped = baseRaw;
137
112
  while (stripped.length) {
138
113
  const mod = ahkPrefixMap.get(stripped[0]) ?? null;
139
114
  if (!mod) break;
140
- combo[mod] = true;
115
+ setMod(mod);
141
116
  stripped = stripped.slice(1).trimStart();
142
117
  }
143
118
  const codeMatches = stripped.match(/code:[A-Za-z][A-Za-z0-9_]*/g);
144
119
  if (codeMatches && codeMatches.length > 1) {
145
- throw new Error(
146
- `Invalid hotkey "${hotkeyStr}": multiple code: tokens not supported (got ${codeMatches.length}).`
147
- );
120
+ fail(`multiple code: tokens not supported (got ${codeMatches.length}).`);
148
121
  }
149
122
  let codeValue = null;
150
123
  const scrubbed = stripped.replace(CODE_TOKEN_RE, (_, sep, val) => {
151
124
  codeValue = val;
152
125
  return sep + "__code__";
153
126
  });
154
- let cleanStr = scrubbed.toLowerCase();
127
+ const cleanStr = scrubbed.toLowerCase();
155
128
  const rawParts = cleanStr.split("+").map((p) => p.trim());
156
129
  const parts = rawParts.filter(Boolean);
157
130
  const impliedPlusKey = rawParts.some((p) => p === "") && cleanStr.includes("++");
@@ -159,13 +132,9 @@ function parseHotkey(hotkeyStr) {
159
132
  let seenBase = false;
160
133
  for (const part of parts) {
161
134
  if (isModifierToken(part)) {
162
- if (seenBase) {
163
- throw new Error(
164
- `Invalid hotkey "${hotkeyStr}": modifiers must come before the base key (e.g. "ctrl+k", not "k+ctrl")`
165
- );
166
- }
135
+ if (seenBase) fail('modifiers must come before the base key (e.g. "ctrl+k", not "k+ctrl")');
167
136
  } else {
168
- if (!seenBase) seenBase = true;
137
+ seenBase = true;
169
138
  }
170
139
  }
171
140
  }
@@ -175,10 +144,7 @@ function parseHotkey(hotkeyStr) {
175
144
  continue;
176
145
  }
177
146
  const actual = keyAliases[part] ?? part;
178
- if (actual === "ctrl") combo.ctrl = true;
179
- else if (actual === "shift") combo.shift = true;
180
- else if (actual === "alt") combo.alt = true;
181
- else if (actual === "meta") combo.meta = true;
147
+ if (modifierTokens.has(actual)) setMod(actual);
182
148
  else combo.key = normalizeKey(actual);
183
149
  }
184
150
  if (!combo.key && !combo.code && impliedPlusKey) combo.key = "+";
@@ -187,17 +153,100 @@ function parseHotkey(hotkeyStr) {
187
153
  if (modCount === 1) {
188
154
  combo.bareModifier = combo.ctrl ? "ctrl" : combo.shift ? "shift" : combo.alt ? "alt" : "meta";
189
155
  } else if (modCount > 1) {
190
- throw new Error(
191
- `Invalid hotkey "${hotkeyStr}": multi-modifier bare bindings not supported. Add a base key (e.g. "ctrl+alt+x").`
192
- );
156
+ fail('multi-modifier bare bindings not supported. Add a base key (e.g. "ctrl+alt+x").');
193
157
  } else {
194
- throw new Error(`Invalid hotkey "${hotkeyStr}" (missing base key)`);
158
+ error = error || `Invalid hotkey "${hotkeyStr}" (missing base key)`;
195
159
  }
196
160
  }
197
- return { combo, type: isUp ? "keyup" : "keydown", raw: hotkeyStr };
161
+ return { combo, type: isUp ? "keyup" : "keydown", raw: hotkeyStr, error };
162
+ }
163
+ function parseHotkey(hotkeyStr, opts) {
164
+ const { combo, type, raw, error } = readHotkey(hotkeyStr, opts);
165
+ if (error) throw new Error(error);
166
+ return { combo, type, raw };
167
+ }
168
+ var SHIFTED_PUNCT = {
169
+ ",": ["<", "Comma"],
170
+ ".": [">", "Period"],
171
+ "/": ["?", "Slash"],
172
+ ";": [":", "Semicolon"],
173
+ "'": ['"', "Quote"],
174
+ "[": ["{", "BracketLeft"],
175
+ "]": ["}", "BracketRight"],
176
+ "\\": ["|", "Backslash"],
177
+ "-": ["_", "Minus"],
178
+ "=": ["+", "Equal"],
179
+ "`": ["~", "Backquote"]
180
+ };
181
+ function shiftedPunctuationHint(hotkeyStr) {
182
+ const { combo, type, error } = readHotkey(hotkeyStr);
183
+ if (error || !combo.shift || combo.code) return null;
184
+ const shifted = SHIFTED_PUNCT[combo.key];
185
+ if (!shifted) return null;
186
+ const [typed, code] = shifted;
187
+ const base = String(hotkeyStr).trim().replace(/\s+up$/i, "");
188
+ const suggestion = base.slice(0, -1) + "code:" + code + (type === "keyup" ? " up" : "");
189
+ return {
190
+ message: `"${hotkeyStr}" never fires on US layouts: Shift turns "${combo.key}" into "${typed}". Bind "${suggestion}" instead.`,
191
+ suggestion
192
+ };
193
+ }
194
+
195
+ // hotkey-router.js
196
+ function on(target, type, fn, options) {
197
+ target.addEventListener(type, fn, options);
198
+ return () => target.removeEventListener(type, fn, options);
199
+ }
200
+ var PLATFORM = detectPlatform();
201
+ var MODIFIER_KEY_TOKEN = Object.freeze({
202
+ Alt: "alt",
203
+ AltGraph: "alt",
204
+ Control: "ctrl",
205
+ Shift: "shift",
206
+ Meta: "meta",
207
+ OS: "meta"
208
+ });
209
+ var ignoreEditable = true;
210
+ var defaultTarget = typeof window !== "undefined" ? window : null;
211
+ var bindHooks = [];
212
+ var registry = /* @__PURE__ */ new Map();
213
+ var plugins = /* @__PURE__ */ new Map();
214
+ var bindingIndex = /* @__PURE__ */ new Map();
215
+ var paused = false;
216
+ var nextId = 1;
217
+ var warnedShifted = /* @__PURE__ */ new Set();
218
+ function comboKeyFromParts({ ctrl, shift, alt, meta, key, code, bareModifier }) {
219
+ if (bareModifier) return `__bare__:${bareModifier}`;
220
+ let s = "";
221
+ if (ctrl) s += "ctrl+";
222
+ if (shift) s += "shift+";
223
+ if (alt) s += "alt+";
224
+ if (meta) s += "meta+";
225
+ if (code) return s + "code:" + code;
226
+ return s ? s + key : key;
227
+ }
228
+ function comboKeyFromEvent(e) {
229
+ const bareMod = MODIFIER_KEY_TOKEN[e.key];
230
+ if (bareMod) return `__bare__:${bareMod}`;
231
+ return comboKeyFromParts({
232
+ ctrl: e.ctrlKey,
233
+ shift: e.shiftKey,
234
+ alt: e.altKey,
235
+ meta: e.metaKey,
236
+ key: normalizeKey(e.key)
237
+ });
238
+ }
239
+ function codeKeyFromEvent(e) {
240
+ if (!e.code) return null;
241
+ let s = "";
242
+ if (e.ctrlKey) s += "ctrl+";
243
+ if (e.shiftKey) s += "shift+";
244
+ if (e.altKey) s += "alt+";
245
+ if (e.metaKey) s += "meta+";
246
+ return s + "code:" + e.code;
198
247
  }
199
248
  function isFromInputTarget(e) {
200
- const t = e?.target;
249
+ const t = e?.composedPath?.()[0] ?? e?.target;
201
250
  if (!t) return false;
202
251
  const tag = String(t.tagName || "").toUpperCase();
203
252
  return t.isContentEditable || tag === "INPUT" || tag === "TEXTAREA" || tag === "SELECT" || t.getAttribute?.("role") === "textbox";
@@ -254,6 +303,14 @@ function bind(hotkeyStr, handler, plugin = null, options = {}) {
254
303
  };
255
304
  ensureSlot(comboStr, type).push(binding);
256
305
  bindingIndex.set(binding.id, { comboStr, type });
306
+ const warnKey = `${comboStr} ${type}`;
307
+ if (!warnedShifted.has(warnKey)) {
308
+ const hint = shiftedPunctuationHint(hotkeyStr);
309
+ if (hint) {
310
+ warnedShifted.add(warnKey);
311
+ console.warn(`[hotkey-router] ${hint.message}`);
312
+ }
313
+ }
257
314
  if (bindHooks.length) {
258
315
  for (const hook of bindHooks) {
259
316
  try {
@@ -300,8 +357,10 @@ function unbind(hotkeyStr, handler) {
300
357
  }
301
358
  function registerPlugin(name, hotkeyMap) {
302
359
  if (plugins.has(name)) throw new Error(`Plugin "${name}" already registered`);
360
+ const entries = Object.entries(hotkeyMap);
361
+ for (const [hotkeyStr] of entries) parseHotkey(hotkeyStr);
303
362
  const ids = [];
304
- for (const [hotkeyStr, fnOrTuple] of Object.entries(hotkeyMap)) {
363
+ for (const [hotkeyStr, fnOrTuple] of entries) {
305
364
  const [fn, options] = Array.isArray(fnOrTuple) ? fnOrTuple : [fnOrTuple, {}];
306
365
  const off = bind(hotkeyStr, fn, name, options);
307
366
  ids.push(off.id);
@@ -344,41 +403,71 @@ function isAltGraphCharacter(e) {
344
403
  function isComposingEvent(e) {
345
404
  return Boolean(e.isComposing || e.keyCode === 229);
346
405
  }
406
+ var NON_LATIN_LETTER = /^(?!\p{Script=Latin})\p{L}$/u;
407
+ function latinKeyFromEvent(e) {
408
+ if (!(e.ctrlKey || e.metaKey) || e.altKey) return null;
409
+ if (isComposingEvent(e)) return null;
410
+ if (typeof e.getModifierState === "function" && e.getModifierState("AltGraph")) return null;
411
+ const letter = /^Key([A-Z])$/.exec(e.code || "");
412
+ if (!letter || typeof e.key !== "string" || !NON_LATIN_LETTER.test(e.key)) return null;
413
+ return comboKeyFromParts({
414
+ ctrl: e.ctrlKey,
415
+ shift: e.shiftKey,
416
+ alt: false,
417
+ meta: e.metaKey,
418
+ key: letter[1].toLowerCase()
419
+ });
420
+ }
421
+ function eligibleBindings(e, type, phase) {
422
+ const guards = {
423
+ altGraphChar: isAltGraphCharacter(e),
424
+ composing: isComposingEvent(e),
425
+ fromInput: ignoreEditable && isFromInputTarget(e)
426
+ };
427
+ const candidates = [];
428
+ const seen = /* @__PURE__ */ new Set();
429
+ for (const lookupKey of [comboKeyFromEvent(e), codeKeyFromEvent(e)]) {
430
+ if (!lookupKey || seen.has(lookupKey)) continue;
431
+ seen.add(lookupKey);
432
+ collectEligible(candidates, lookupKey, e, type, phase, guards);
433
+ }
434
+ if (!candidates.length) {
435
+ const latinKey = latinKeyFromEvent(e);
436
+ if (latinKey && !seen.has(latinKey)) collectEligible(candidates, latinKey, e, type, phase, guards);
437
+ }
438
+ return candidates;
439
+ }
440
+ function collectEligible(candidates, lookupKey, e, type, phase, { altGraphChar, composing, fromInput }) {
441
+ const bindings = registry.get(lookupKey)?.get(type);
442
+ if (!bindings?.length) return;
443
+ for (const b of bindings) {
444
+ const o = b.options;
445
+ if (phase === "capture" && !o.capture) continue;
446
+ if (phase === "bubble" && o.capture) continue;
447
+ if (altGraphChar && !o.altGraph) continue;
448
+ if (composing && !o.composing) continue;
449
+ if (fromInput && !o.allowIn?.(e)) continue;
450
+ if (type === "keydown" && o.repeat === false && e.repeat) continue;
451
+ if (o.when && o.when(e) === false) continue;
452
+ candidates.push(b);
453
+ }
454
+ }
455
+ function fire(winner, e) {
456
+ const o = winner.options;
457
+ if (o.preventDefault) e.preventDefault();
458
+ if (o.stopImmediatePropagation) e.stopImmediatePropagation();
459
+ else if (o.stopPropagation) e.stopPropagation();
460
+ try {
461
+ winner.handler(e);
462
+ } finally {
463
+ if (o.once) removeById(winner.id);
464
+ }
465
+ }
347
466
  function handleEvent(type, phase = "all") {
348
467
  return (e) => {
349
468
  if (paused) return;
350
- const altGraphChar = isAltGraphCharacter(e);
351
- const composing = isComposingEvent(e);
352
- const fromInput = ignoreEditable && isFromInputTarget(e);
353
- const comboStr = comboKeyFromEvent(e);
354
- const codeStr = codeKeyFromEvent(e);
355
- const seen = /* @__PURE__ */ new Set();
356
- const candidates = [];
357
- for (const lookupKey of [comboStr, codeStr]) {
358
- if (!lookupKey || seen.has(lookupKey)) continue;
359
- seen.add(lookupKey);
360
- const bindings = registry.get(lookupKey)?.get(type);
361
- if (!bindings?.length) continue;
362
- for (const b of bindings) {
363
- const o2 = b.options;
364
- if (phase === "capture" && !o2.capture) continue;
365
- if (phase === "bubble" && o2.capture) continue;
366
- if (altGraphChar && !o2.altGraph) continue;
367
- if (composing && !o2.composing) continue;
368
- if (fromInput && !o2.allowIn?.(e)) continue;
369
- if (type === "keydown" && o2.repeat === false && e.repeat) continue;
370
- if (o2.when && o2.when(e) === false) continue;
371
- candidates.push(b);
372
- }
373
- }
374
- if (!candidates.length) return;
375
- const winner = pickWinner(candidates);
376
- const o = winner.options;
377
- if (o.preventDefault) e.preventDefault();
378
- if (o.stopImmediatePropagation) e.stopImmediatePropagation();
379
- else if (o.stopPropagation) e.stopPropagation();
380
- winner.handler(e);
381
- if (o.once) removeById(winner.id);
469
+ const candidates = eligibleBindings(e, type, phase);
470
+ if (candidates.length) fire(pickWinner(candidates), e);
382
471
  };
383
472
  }
384
473
  var stopDown = null;
@@ -417,13 +506,62 @@ var BARE_MOD_TO_KEY = {
417
506
  alt: "Alt",
418
507
  meta: "Meta"
419
508
  };
420
- function trigger(hotkeyStr, { type: forcedType } = {}) {
509
+ var CODE_TO_KEY = {
510
+ Period: ".",
511
+ Comma: ",",
512
+ Semicolon: ";",
513
+ Quote: "'",
514
+ Slash: "/",
515
+ Backslash: "\\",
516
+ BracketLeft: "[",
517
+ BracketRight: "]",
518
+ Minus: "-",
519
+ Equal: "=",
520
+ Backquote: "`",
521
+ Space: " ",
522
+ Enter: "Enter",
523
+ NumpadEnter: "Enter",
524
+ Tab: "Tab",
525
+ Escape: "Escape",
526
+ Backspace: "Backspace",
527
+ Delete: "Delete",
528
+ Insert: "Insert",
529
+ Home: "Home",
530
+ End: "End",
531
+ PageUp: "PageUp",
532
+ PageDown: "PageDown",
533
+ ArrowUp: "ArrowUp",
534
+ ArrowDown: "ArrowDown",
535
+ ArrowLeft: "ArrowLeft",
536
+ ArrowRight: "ArrowRight"
537
+ };
538
+ var KEY_TO_CODE = {};
539
+ var _a;
540
+ for (const [code, key] of Object.entries(CODE_TO_KEY)) {
541
+ KEY_TO_CODE[_a = normalizeKey(key)] ?? (KEY_TO_CODE[_a] = code);
542
+ }
543
+ function keyForCode(code) {
544
+ if (!code) return null;
545
+ const letter = /^Key([A-Z])$/.exec(code);
546
+ if (letter) return letter[1].toLowerCase();
547
+ const digit = /^(?:Digit|Numpad)(\d)$/.exec(code);
548
+ if (digit) return digit[1];
549
+ if (/^F\d{1,2}$/.test(code)) return code;
550
+ return CODE_TO_KEY[code] ?? null;
551
+ }
552
+ function codeForKey(key) {
553
+ if (!key) return null;
554
+ if (/^[a-z]$/.test(key)) return "Key" + key.toUpperCase();
555
+ if (/^\d$/.test(key)) return "Digit" + key;
556
+ if (/^f\d{1,2}$/.test(key)) return key.toUpperCase();
557
+ return KEY_TO_CODE[key] ?? null;
558
+ }
559
+ function trigger(hotkeyStr, { type: forcedType, target = null } = {}) {
421
560
  const { combo, type } = parseHotkey(hotkeyStr);
422
- const comboStr = comboKeyFromParts(combo);
423
561
  const actualType = forcedType || type;
424
- const bindings = registry.get(comboStr)?.get(actualType);
425
- if (!bindings?.length) return false;
426
- const eventKey = combo.bareModifier ? BARE_MOD_TO_KEY[combo.bareModifier] : combo.key;
562
+ if (paused) return false;
563
+ const eventKey = combo.bareModifier ? BARE_MOD_TO_KEY[combo.bareModifier] : combo.key ?? keyForCode(combo.code);
564
+ const eventCode = combo.bareModifier ? null : combo.code ?? codeForKey(combo.key);
427
565
  let altKey = !!combo.alt;
428
566
  let ctrlKey = !!combo.ctrl;
429
567
  let shiftKey = !!combo.shift;
@@ -437,32 +575,33 @@ function trigger(hotkeyStr, { type: forcedType } = {}) {
437
575
  const e = {
438
576
  type: actualType,
439
577
  key: eventKey,
440
- code: combo.code || null,
578
+ code: eventCode,
441
579
  ctrlKey,
442
580
  shiftKey,
443
581
  altKey,
444
582
  metaKey,
445
583
  repeat: false,
584
+ isComposing: false,
585
+ getModifierState() {
586
+ return false;
587
+ },
446
588
  preventDefault() {
447
589
  },
448
590
  stopPropagation() {
449
591
  },
450
592
  stopImmediatePropagation() {
451
593
  },
452
- target: null
594
+ target
453
595
  };
454
- const winner = pickWinner(
455
- bindings.filter((b) => b.options.when ? b.options.when(e) !== false : true)
456
- );
457
- if (!winner) return false;
458
- winner.handler(e);
459
- if (winner.options.once) removeById(winner.id);
596
+ const candidates = eligibleBindings(e, actualType, "all");
597
+ if (!candidates.length) return false;
598
+ fire(pickWinner(candidates), e);
460
599
  return true;
461
600
  }
462
- function comboFromEvent(e, { physical = true, useMod = false } = {}) {
601
+ function comboFromEvent(e, { physical = true, useMod = false, platform = PLATFORM } = {}) {
463
602
  if (!e || MODIFIER_KEY_TOKEN[e.key]) return null;
464
603
  const parts = [];
465
- const primaryIsMeta = isMac;
604
+ const primaryIsMeta = platform === "mac";
466
605
  if (useMod && (primaryIsMeta ? e.metaKey : e.ctrlKey)) parts.push("mod");
467
606
  if (e.ctrlKey && !(useMod && !primaryIsMeta)) parts.push("ctrl");
468
607
  if (e.metaKey && !(useMod && primaryIsMeta)) parts.push("meta");
@@ -497,11 +636,13 @@ var hotkey_router_default = {
497
636
  trigger,
498
637
  // helpers
499
638
  parseHotkey,
500
- comboFromEvent
639
+ comboFromEvent,
640
+ detectPlatform
501
641
  };
502
642
  export {
503
643
  comboFromEvent,
504
644
  hotkey_router_default as default,
645
+ detectPlatform,
505
646
  parseHotkey
506
647
  };
507
648
  //# sourceMappingURL=hotkey-router.js.map