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,4 +1,4 @@
1
- // hotkey-router v0.3.1 | SEE LICENSE IN LICENSE
1
+ // hotkey-router v0.3.3 | SEE LICENSE IN LICENSE
2
2
 
3
3
  var __defProp = Object.defineProperty;
4
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -23,23 +23,31 @@ var hotkey_router_exports = {};
23
23
  __export(hotkey_router_exports, {
24
24
  comboFromEvent: () => comboFromEvent,
25
25
  default: () => hotkey_router_default,
26
+ detectPlatform: () => detectPlatform,
26
27
  parseHotkey: () => parseHotkey
27
28
  });
28
29
  module.exports = __toCommonJS(hotkey_router_exports);
29
- function on(target, type, fn, options) {
30
- target.addEventListener(type, fn, options);
31
- return () => target.removeEventListener(type, fn, options);
30
+
31
+ // platform.js
32
+ function fromPlatformString(s) {
33
+ if (!s) return null;
34
+ if (/Chrome ?OS|CrOS/i.test(s)) return "chromeos";
35
+ if (/Mac|iPhone|iPad|iPod/i.test(s)) return "mac";
36
+ if (/Win/i.test(s)) return "windows";
37
+ if (/Linux|X11/i.test(s)) return "linux";
38
+ return null;
32
39
  }
33
- var isMac = typeof navigator !== "undefined" && /Mac|iPhone|iPad|iPod/.test(navigator.platform);
34
- var modifierTokens = /* @__PURE__ */ new Set(["ctrl", "shift", "alt", "meta"]);
35
- var MODIFIER_KEY_TOKEN = Object.freeze({
36
- Alt: "alt",
37
- AltGraph: "alt",
38
- Control: "ctrl",
39
- Shift: "shift",
40
- Meta: "meta",
41
- OS: "meta"
42
- });
40
+ function detectPlatform(nav = typeof navigator !== "undefined" ? navigator : null, { chromeos = false } = {}) {
41
+ if (!nav) return null;
42
+ const ua = nav.userAgent || "";
43
+ 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);
44
+ if (found === "chromeos" && !chromeos) return "linux";
45
+ return found;
46
+ }
47
+
48
+ // parse.js
49
+ var DEFAULT_PLATFORM = detectPlatform();
50
+ var modifierTokens = /* @__PURE__ */ new Set(["ctrl", "shift", "alt", "meta", "mod"]);
43
51
  var ahkPrefixMap = /* @__PURE__ */ new Map([
44
52
  ["^", "ctrl"],
45
53
  // Ctrl
@@ -82,6 +90,7 @@ var keyAliases = Object.freeze({
82
90
  control: "ctrl",
83
91
  ctrl: "ctrl",
84
92
  option: "alt",
93
+ opt: "alt",
85
94
  alt: "alt",
86
95
  shift: "shift",
87
96
  // modifiers (symbols)
@@ -89,19 +98,11 @@ var keyAliases = Object.freeze({
89
98
  "\u2303": "ctrl",
90
99
  "\u2325": "alt",
91
100
  "\u21E7": "shift",
92
- // cross-platform "mod"
93
- mod: isMac ? "meta" : "ctrl",
101
+ // cross-platform "mod", resolved per platform while parsing
102
+ mod: "mod",
94
103
  // plus key ergonomics
95
104
  plus: "+"
96
105
  });
97
- var ignoreEditable = true;
98
- var defaultTarget = typeof window !== "undefined" ? window : null;
99
- var bindHooks = [];
100
- var registry = /* @__PURE__ */ new Map();
101
- var plugins = /* @__PURE__ */ new Map();
102
- var bindingIndex = /* @__PURE__ */ new Map();
103
- var paused = false;
104
- var nextId = 1;
105
106
  function normalizeKey(key) {
106
107
  const original = String(key ?? "");
107
108
  if (original === " ") return " ";
@@ -109,43 +110,16 @@ function normalizeKey(key) {
109
110
  const k = trimmed.toLowerCase();
110
111
  return keyAliases[k] ?? k;
111
112
  }
112
- function comboKeyFromParts({ ctrl, shift, alt, meta, key, code, bareModifier }) {
113
- if (bareModifier) return `__bare__:${bareModifier}`;
114
- let s = "";
115
- if (ctrl) s += "ctrl+";
116
- if (shift) s += "shift+";
117
- if (alt) s += "alt+";
118
- if (meta) s += "meta+";
119
- if (code) return s + "code:" + code;
120
- return s ? s + key : key;
121
- }
122
- function comboKeyFromEvent(e) {
123
- const bareMod = MODIFIER_KEY_TOKEN[e.key];
124
- if (bareMod) return `__bare__:${bareMod}`;
125
- return comboKeyFromParts({
126
- ctrl: e.ctrlKey,
127
- shift: e.shiftKey,
128
- alt: e.altKey,
129
- meta: e.metaKey,
130
- key: normalizeKey(e.key)
131
- });
132
- }
133
- function codeKeyFromEvent(e) {
134
- if (!e.code) return null;
135
- let s = "";
136
- if (e.ctrlKey) s += "ctrl+";
137
- if (e.shiftKey) s += "shift+";
138
- if (e.altKey) s += "alt+";
139
- if (e.metaKey) s += "meta+";
140
- return s + "code:" + e.code;
141
- }
142
113
  function isModifierToken(token) {
143
- const t = normalizeKey(token);
144
- return modifierTokens.has(t);
114
+ return modifierTokens.has(normalizeKey(token));
145
115
  }
146
116
  var CODE_TOKEN_RE = /(^|\+)code:([A-Za-z][A-Za-z0-9_]*)/;
147
- function parseHotkey(hotkeyStr) {
117
+ function readHotkey(hotkeyStr, { platform = DEFAULT_PLATFORM } = {}) {
148
118
  const raw = String(hotkeyStr || "").trim();
119
+ let error = null;
120
+ const fail = (msg) => {
121
+ error = error || `Invalid hotkey "${hotkeyStr}": ${msg}`;
122
+ };
149
123
  const isUp = /\s+up$/i.test(raw);
150
124
  const baseRaw = isUp ? raw.replace(/\s+up$/i, "").trim() : raw;
151
125
  const combo = {
@@ -157,25 +131,27 @@ function parseHotkey(hotkeyStr) {
157
131
  code: null,
158
132
  bareModifier: null
159
133
  };
134
+ const setMod = (mod) => {
135
+ if (mod === "mod") combo[platform === "mac" ? "meta" : "ctrl"] = true;
136
+ else combo[mod] = true;
137
+ };
160
138
  let stripped = baseRaw;
161
139
  while (stripped.length) {
162
140
  const mod = ahkPrefixMap.get(stripped[0]) ?? null;
163
141
  if (!mod) break;
164
- combo[mod] = true;
142
+ setMod(mod);
165
143
  stripped = stripped.slice(1).trimStart();
166
144
  }
167
145
  const codeMatches = stripped.match(/code:[A-Za-z][A-Za-z0-9_]*/g);
168
146
  if (codeMatches && codeMatches.length > 1) {
169
- throw new Error(
170
- `Invalid hotkey "${hotkeyStr}": multiple code: tokens not supported (got ${codeMatches.length}).`
171
- );
147
+ fail(`multiple code: tokens not supported (got ${codeMatches.length}).`);
172
148
  }
173
149
  let codeValue = null;
174
150
  const scrubbed = stripped.replace(CODE_TOKEN_RE, (_, sep, val) => {
175
151
  codeValue = val;
176
152
  return sep + "__code__";
177
153
  });
178
- let cleanStr = scrubbed.toLowerCase();
154
+ const cleanStr = scrubbed.toLowerCase();
179
155
  const rawParts = cleanStr.split("+").map((p) => p.trim());
180
156
  const parts = rawParts.filter(Boolean);
181
157
  const impliedPlusKey = rawParts.some((p) => p === "") && cleanStr.includes("++");
@@ -183,13 +159,9 @@ function parseHotkey(hotkeyStr) {
183
159
  let seenBase = false;
184
160
  for (const part of parts) {
185
161
  if (isModifierToken(part)) {
186
- if (seenBase) {
187
- throw new Error(
188
- `Invalid hotkey "${hotkeyStr}": modifiers must come before the base key (e.g. "ctrl+k", not "k+ctrl")`
189
- );
190
- }
162
+ if (seenBase) fail('modifiers must come before the base key (e.g. "ctrl+k", not "k+ctrl")');
191
163
  } else {
192
- if (!seenBase) seenBase = true;
164
+ seenBase = true;
193
165
  }
194
166
  }
195
167
  }
@@ -199,10 +171,7 @@ function parseHotkey(hotkeyStr) {
199
171
  continue;
200
172
  }
201
173
  const actual = keyAliases[part] ?? part;
202
- if (actual === "ctrl") combo.ctrl = true;
203
- else if (actual === "shift") combo.shift = true;
204
- else if (actual === "alt") combo.alt = true;
205
- else if (actual === "meta") combo.meta = true;
174
+ if (modifierTokens.has(actual)) setMod(actual);
206
175
  else combo.key = normalizeKey(actual);
207
176
  }
208
177
  if (!combo.key && !combo.code && impliedPlusKey) combo.key = "+";
@@ -211,17 +180,100 @@ function parseHotkey(hotkeyStr) {
211
180
  if (modCount === 1) {
212
181
  combo.bareModifier = combo.ctrl ? "ctrl" : combo.shift ? "shift" : combo.alt ? "alt" : "meta";
213
182
  } else if (modCount > 1) {
214
- throw new Error(
215
- `Invalid hotkey "${hotkeyStr}": multi-modifier bare bindings not supported. Add a base key (e.g. "ctrl+alt+x").`
216
- );
183
+ fail('multi-modifier bare bindings not supported. Add a base key (e.g. "ctrl+alt+x").');
217
184
  } else {
218
- throw new Error(`Invalid hotkey "${hotkeyStr}" (missing base key)`);
185
+ error = error || `Invalid hotkey "${hotkeyStr}" (missing base key)`;
219
186
  }
220
187
  }
221
- return { combo, type: isUp ? "keyup" : "keydown", raw: hotkeyStr };
188
+ return { combo, type: isUp ? "keyup" : "keydown", raw: hotkeyStr, error };
189
+ }
190
+ function parseHotkey(hotkeyStr, opts) {
191
+ const { combo, type, raw, error } = readHotkey(hotkeyStr, opts);
192
+ if (error) throw new Error(error);
193
+ return { combo, type, raw };
194
+ }
195
+ var SHIFTED_PUNCT = {
196
+ ",": ["<", "Comma"],
197
+ ".": [">", "Period"],
198
+ "/": ["?", "Slash"],
199
+ ";": [":", "Semicolon"],
200
+ "'": ['"', "Quote"],
201
+ "[": ["{", "BracketLeft"],
202
+ "]": ["}", "BracketRight"],
203
+ "\\": ["|", "Backslash"],
204
+ "-": ["_", "Minus"],
205
+ "=": ["+", "Equal"],
206
+ "`": ["~", "Backquote"]
207
+ };
208
+ function shiftedPunctuationHint(hotkeyStr) {
209
+ const { combo, type, error } = readHotkey(hotkeyStr);
210
+ if (error || !combo.shift || combo.code) return null;
211
+ const shifted = SHIFTED_PUNCT[combo.key];
212
+ if (!shifted) return null;
213
+ const [typed, code] = shifted;
214
+ const base = String(hotkeyStr).trim().replace(/\s+up$/i, "");
215
+ const suggestion = base.slice(0, -1) + "code:" + code + (type === "keyup" ? " up" : "");
216
+ return {
217
+ message: `"${hotkeyStr}" never fires on US layouts: Shift turns "${combo.key}" into "${typed}". Bind "${suggestion}" instead.`,
218
+ suggestion
219
+ };
220
+ }
221
+
222
+ // hotkey-router.js
223
+ function on(target, type, fn, options) {
224
+ target.addEventListener(type, fn, options);
225
+ return () => target.removeEventListener(type, fn, options);
226
+ }
227
+ var PLATFORM = detectPlatform();
228
+ var MODIFIER_KEY_TOKEN = Object.freeze({
229
+ Alt: "alt",
230
+ AltGraph: "alt",
231
+ Control: "ctrl",
232
+ Shift: "shift",
233
+ Meta: "meta",
234
+ OS: "meta"
235
+ });
236
+ var ignoreEditable = true;
237
+ var defaultTarget = typeof window !== "undefined" ? window : null;
238
+ var bindHooks = [];
239
+ var registry = /* @__PURE__ */ new Map();
240
+ var plugins = /* @__PURE__ */ new Map();
241
+ var bindingIndex = /* @__PURE__ */ new Map();
242
+ var paused = false;
243
+ var nextId = 1;
244
+ var warnedShifted = /* @__PURE__ */ new Set();
245
+ function comboKeyFromParts({ ctrl, shift, alt, meta, key, code, bareModifier }) {
246
+ if (bareModifier) return `__bare__:${bareModifier}`;
247
+ let s = "";
248
+ if (ctrl) s += "ctrl+";
249
+ if (shift) s += "shift+";
250
+ if (alt) s += "alt+";
251
+ if (meta) s += "meta+";
252
+ if (code) return s + "code:" + code;
253
+ return s ? s + key : key;
254
+ }
255
+ function comboKeyFromEvent(e) {
256
+ const bareMod = MODIFIER_KEY_TOKEN[e.key];
257
+ if (bareMod) return `__bare__:${bareMod}`;
258
+ return comboKeyFromParts({
259
+ ctrl: e.ctrlKey,
260
+ shift: e.shiftKey,
261
+ alt: e.altKey,
262
+ meta: e.metaKey,
263
+ key: normalizeKey(e.key)
264
+ });
265
+ }
266
+ function codeKeyFromEvent(e) {
267
+ if (!e.code) return null;
268
+ let s = "";
269
+ if (e.ctrlKey) s += "ctrl+";
270
+ if (e.shiftKey) s += "shift+";
271
+ if (e.altKey) s += "alt+";
272
+ if (e.metaKey) s += "meta+";
273
+ return s + "code:" + e.code;
222
274
  }
223
275
  function isFromInputTarget(e) {
224
- const t = e?.target;
276
+ const t = e?.composedPath?.()[0] ?? e?.target;
225
277
  if (!t) return false;
226
278
  const tag = String(t.tagName || "").toUpperCase();
227
279
  return t.isContentEditable || tag === "INPUT" || tag === "TEXTAREA" || tag === "SELECT" || t.getAttribute?.("role") === "textbox";
@@ -278,6 +330,14 @@ function bind(hotkeyStr, handler, plugin = null, options = {}) {
278
330
  };
279
331
  ensureSlot(comboStr, type).push(binding);
280
332
  bindingIndex.set(binding.id, { comboStr, type });
333
+ const warnKey = `${comboStr} ${type}`;
334
+ if (!warnedShifted.has(warnKey)) {
335
+ const hint = shiftedPunctuationHint(hotkeyStr);
336
+ if (hint) {
337
+ warnedShifted.add(warnKey);
338
+ console.warn(`[hotkey-router] ${hint.message}`);
339
+ }
340
+ }
281
341
  if (bindHooks.length) {
282
342
  for (const hook of bindHooks) {
283
343
  try {
@@ -324,8 +384,10 @@ function unbind(hotkeyStr, handler) {
324
384
  }
325
385
  function registerPlugin(name, hotkeyMap) {
326
386
  if (plugins.has(name)) throw new Error(`Plugin "${name}" already registered`);
387
+ const entries = Object.entries(hotkeyMap);
388
+ for (const [hotkeyStr] of entries) parseHotkey(hotkeyStr);
327
389
  const ids = [];
328
- for (const [hotkeyStr, fnOrTuple] of Object.entries(hotkeyMap)) {
390
+ for (const [hotkeyStr, fnOrTuple] of entries) {
329
391
  const [fn, options] = Array.isArray(fnOrTuple) ? fnOrTuple : [fnOrTuple, {}];
330
392
  const off = bind(hotkeyStr, fn, name, options);
331
393
  ids.push(off.id);
@@ -368,41 +430,71 @@ function isAltGraphCharacter(e) {
368
430
  function isComposingEvent(e) {
369
431
  return Boolean(e.isComposing || e.keyCode === 229);
370
432
  }
433
+ var NON_LATIN_LETTER = /^(?!\p{Script=Latin})\p{L}$/u;
434
+ function latinKeyFromEvent(e) {
435
+ if (!(e.ctrlKey || e.metaKey) || e.altKey) return null;
436
+ if (isComposingEvent(e)) return null;
437
+ if (typeof e.getModifierState === "function" && e.getModifierState("AltGraph")) return null;
438
+ const letter = /^Key([A-Z])$/.exec(e.code || "");
439
+ if (!letter || typeof e.key !== "string" || !NON_LATIN_LETTER.test(e.key)) return null;
440
+ return comboKeyFromParts({
441
+ ctrl: e.ctrlKey,
442
+ shift: e.shiftKey,
443
+ alt: false,
444
+ meta: e.metaKey,
445
+ key: letter[1].toLowerCase()
446
+ });
447
+ }
448
+ function eligibleBindings(e, type, phase) {
449
+ const guards = {
450
+ altGraphChar: isAltGraphCharacter(e),
451
+ composing: isComposingEvent(e),
452
+ fromInput: ignoreEditable && isFromInputTarget(e)
453
+ };
454
+ const candidates = [];
455
+ const seen = /* @__PURE__ */ new Set();
456
+ for (const lookupKey of [comboKeyFromEvent(e), codeKeyFromEvent(e)]) {
457
+ if (!lookupKey || seen.has(lookupKey)) continue;
458
+ seen.add(lookupKey);
459
+ collectEligible(candidates, lookupKey, e, type, phase, guards);
460
+ }
461
+ if (!candidates.length) {
462
+ const latinKey = latinKeyFromEvent(e);
463
+ if (latinKey && !seen.has(latinKey)) collectEligible(candidates, latinKey, e, type, phase, guards);
464
+ }
465
+ return candidates;
466
+ }
467
+ function collectEligible(candidates, lookupKey, e, type, phase, { altGraphChar, composing, fromInput }) {
468
+ const bindings = registry.get(lookupKey)?.get(type);
469
+ if (!bindings?.length) return;
470
+ for (const b of bindings) {
471
+ const o = b.options;
472
+ if (phase === "capture" && !o.capture) continue;
473
+ if (phase === "bubble" && o.capture) continue;
474
+ if (altGraphChar && !o.altGraph) continue;
475
+ if (composing && !o.composing) continue;
476
+ if (fromInput && !o.allowIn?.(e)) continue;
477
+ if (type === "keydown" && o.repeat === false && e.repeat) continue;
478
+ if (o.when && o.when(e) === false) continue;
479
+ candidates.push(b);
480
+ }
481
+ }
482
+ function fire(winner, e) {
483
+ const o = winner.options;
484
+ if (o.preventDefault) e.preventDefault();
485
+ if (o.stopImmediatePropagation) e.stopImmediatePropagation();
486
+ else if (o.stopPropagation) e.stopPropagation();
487
+ try {
488
+ winner.handler(e);
489
+ } finally {
490
+ if (o.once) removeById(winner.id);
491
+ }
492
+ }
371
493
  function handleEvent(type, phase = "all") {
372
494
  return (e) => {
373
495
  if (paused) return;
374
- const altGraphChar = isAltGraphCharacter(e);
375
- const composing = isComposingEvent(e);
376
- const fromInput = ignoreEditable && isFromInputTarget(e);
377
- const comboStr = comboKeyFromEvent(e);
378
- const codeStr = codeKeyFromEvent(e);
379
- const seen = /* @__PURE__ */ new Set();
380
- const candidates = [];
381
- for (const lookupKey of [comboStr, codeStr]) {
382
- if (!lookupKey || seen.has(lookupKey)) continue;
383
- seen.add(lookupKey);
384
- const bindings = registry.get(lookupKey)?.get(type);
385
- if (!bindings?.length) continue;
386
- for (const b of bindings) {
387
- const o2 = b.options;
388
- if (phase === "capture" && !o2.capture) continue;
389
- if (phase === "bubble" && o2.capture) continue;
390
- if (altGraphChar && !o2.altGraph) continue;
391
- if (composing && !o2.composing) continue;
392
- if (fromInput && !o2.allowIn?.(e)) continue;
393
- if (type === "keydown" && o2.repeat === false && e.repeat) continue;
394
- if (o2.when && o2.when(e) === false) continue;
395
- candidates.push(b);
396
- }
397
- }
398
- if (!candidates.length) return;
399
- const winner = pickWinner(candidates);
400
- const o = winner.options;
401
- if (o.preventDefault) e.preventDefault();
402
- if (o.stopImmediatePropagation) e.stopImmediatePropagation();
403
- else if (o.stopPropagation) e.stopPropagation();
404
- winner.handler(e);
405
- if (o.once) removeById(winner.id);
496
+ const candidates = eligibleBindings(e, type, phase);
497
+ if (candidates.length) fire(pickWinner(candidates), e);
406
498
  };
407
499
  }
408
500
  var stopDown = null;
@@ -441,13 +533,62 @@ var BARE_MOD_TO_KEY = {
441
533
  alt: "Alt",
442
534
  meta: "Meta"
443
535
  };
444
- function trigger(hotkeyStr, { type: forcedType } = {}) {
536
+ var CODE_TO_KEY = {
537
+ Period: ".",
538
+ Comma: ",",
539
+ Semicolon: ";",
540
+ Quote: "'",
541
+ Slash: "/",
542
+ Backslash: "\\",
543
+ BracketLeft: "[",
544
+ BracketRight: "]",
545
+ Minus: "-",
546
+ Equal: "=",
547
+ Backquote: "`",
548
+ Space: " ",
549
+ Enter: "Enter",
550
+ NumpadEnter: "Enter",
551
+ Tab: "Tab",
552
+ Escape: "Escape",
553
+ Backspace: "Backspace",
554
+ Delete: "Delete",
555
+ Insert: "Insert",
556
+ Home: "Home",
557
+ End: "End",
558
+ PageUp: "PageUp",
559
+ PageDown: "PageDown",
560
+ ArrowUp: "ArrowUp",
561
+ ArrowDown: "ArrowDown",
562
+ ArrowLeft: "ArrowLeft",
563
+ ArrowRight: "ArrowRight"
564
+ };
565
+ var KEY_TO_CODE = {};
566
+ var _a;
567
+ for (const [code, key] of Object.entries(CODE_TO_KEY)) {
568
+ KEY_TO_CODE[_a = normalizeKey(key)] ?? (KEY_TO_CODE[_a] = code);
569
+ }
570
+ function keyForCode(code) {
571
+ if (!code) return null;
572
+ const letter = /^Key([A-Z])$/.exec(code);
573
+ if (letter) return letter[1].toLowerCase();
574
+ const digit = /^(?:Digit|Numpad)(\d)$/.exec(code);
575
+ if (digit) return digit[1];
576
+ if (/^F\d{1,2}$/.test(code)) return code;
577
+ return CODE_TO_KEY[code] ?? null;
578
+ }
579
+ function codeForKey(key) {
580
+ if (!key) return null;
581
+ if (/^[a-z]$/.test(key)) return "Key" + key.toUpperCase();
582
+ if (/^\d$/.test(key)) return "Digit" + key;
583
+ if (/^f\d{1,2}$/.test(key)) return key.toUpperCase();
584
+ return KEY_TO_CODE[key] ?? null;
585
+ }
586
+ function trigger(hotkeyStr, { type: forcedType, target = null } = {}) {
445
587
  const { combo, type } = parseHotkey(hotkeyStr);
446
- const comboStr = comboKeyFromParts(combo);
447
588
  const actualType = forcedType || type;
448
- const bindings = registry.get(comboStr)?.get(actualType);
449
- if (!bindings?.length) return false;
450
- const eventKey = combo.bareModifier ? BARE_MOD_TO_KEY[combo.bareModifier] : combo.key;
589
+ if (paused) return false;
590
+ const eventKey = combo.bareModifier ? BARE_MOD_TO_KEY[combo.bareModifier] : combo.key ?? keyForCode(combo.code);
591
+ const eventCode = combo.bareModifier ? null : combo.code ?? codeForKey(combo.key);
451
592
  let altKey = !!combo.alt;
452
593
  let ctrlKey = !!combo.ctrl;
453
594
  let shiftKey = !!combo.shift;
@@ -461,32 +602,33 @@ function trigger(hotkeyStr, { type: forcedType } = {}) {
461
602
  const e = {
462
603
  type: actualType,
463
604
  key: eventKey,
464
- code: combo.code || null,
605
+ code: eventCode,
465
606
  ctrlKey,
466
607
  shiftKey,
467
608
  altKey,
468
609
  metaKey,
469
610
  repeat: false,
611
+ isComposing: false,
612
+ getModifierState() {
613
+ return false;
614
+ },
470
615
  preventDefault() {
471
616
  },
472
617
  stopPropagation() {
473
618
  },
474
619
  stopImmediatePropagation() {
475
620
  },
476
- target: null
621
+ target
477
622
  };
478
- const winner = pickWinner(
479
- bindings.filter((b) => b.options.when ? b.options.when(e) !== false : true)
480
- );
481
- if (!winner) return false;
482
- winner.handler(e);
483
- if (winner.options.once) removeById(winner.id);
623
+ const candidates = eligibleBindings(e, actualType, "all");
624
+ if (!candidates.length) return false;
625
+ fire(pickWinner(candidates), e);
484
626
  return true;
485
627
  }
486
- function comboFromEvent(e, { physical = true, useMod = false } = {}) {
628
+ function comboFromEvent(e, { physical = true, useMod = false, platform = PLATFORM } = {}) {
487
629
  if (!e || MODIFIER_KEY_TOKEN[e.key]) return null;
488
630
  const parts = [];
489
- const primaryIsMeta = isMac;
631
+ const primaryIsMeta = platform === "mac";
490
632
  if (useMod && (primaryIsMeta ? e.metaKey : e.ctrlKey)) parts.push("mod");
491
633
  if (e.ctrlKey && !(useMod && !primaryIsMeta)) parts.push("ctrl");
492
634
  if (e.metaKey && !(useMod && primaryIsMeta)) parts.push("meta");
@@ -521,6 +663,7 @@ var hotkey_router_default = {
521
663
  trigger,
522
664
  // helpers
523
665
  parseHotkey,
524
- comboFromEvent
666
+ comboFromEvent,
667
+ detectPlatform
525
668
  };
526
669
  //# sourceMappingURL=hotkey-router.cjs.map