@rwh/keystrokes
Advanced tools
Comparing version 1.2.3 to 1.3.0
@@ -41,6 +41,6 @@ import { MaybeBrowserKeyComboEventProps, MaybeBrowserKeyEventProps } from './browser-bindings'; | ||
get pressedKeys(): string[]; | ||
bindKey(key: string, handler: Handler<KeyEvent<OriginalEvent, KeyEventProps>>): void; | ||
unbindKey(key: string, handler?: Handler<KeyEvent<OriginalEvent, KeyEventProps>>): void; | ||
bindKeyCombo(keyCombo: string, handler: Handler<KeyComboEvent<OriginalEvent, KeyEventProps, KeyComboEventProps>>): void; | ||
unbindKeyCombo(keyCombo: string, handler?: Handler<KeyComboEvent<OriginalEvent, KeyEventProps, KeyComboEventProps>>): void; | ||
bindKey(key: string | string[], handler: Handler<KeyEvent<OriginalEvent, KeyEventProps>>): void; | ||
unbindKey(key: string | string[], handler?: Handler<KeyEvent<OriginalEvent, KeyEventProps>>): void; | ||
bindKeyCombo(keyCombo: string | string[], handler: Handler<KeyComboEvent<OriginalEvent, KeyEventProps, KeyComboEventProps>>): void; | ||
unbindKeyCombo(keyCombo: string | string[], handler?: Handler<KeyComboEvent<OriginalEvent, KeyEventProps, KeyComboEventProps>>): void; | ||
checkKey(key: string): boolean; | ||
@@ -47,0 +47,0 @@ checkKeyCombo(keyCombo: string): boolean; |
@@ -47,3 +47,3 @@ var A = Object.defineProperty; | ||
let n = "", s = [], r = [s], a = [r]; | ||
const f = [a]; | ||
const K = [a]; | ||
let _ = !1; | ||
@@ -58,4 +58,4 @@ for (let c = 0; c < e.length; c += 1) | ||
} else | ||
t[c].match(/[^\s]/) && (n && (n === "," ? (s = [], r = [s], a = [r], f.push(a)) : n === ">" ? (s = [], r = [s], a.push(r)) : n === "+" && (s = [], r.push(s)), n = ""), _ = !1, s.push(t[c])); | ||
const d = f.map((c) => c.map((p) => p.map((u) => u.join("")))); | ||
t[c].match(/[^\s]/) && (n && (n === "," ? (s = [], r = [s], a = [r], K.push(a)) : n === ">" ? (s = [], r = [s], a.push(r)) : n === "+" && (s = [], r.push(s)), n = ""), _ = !1, s.push(t[c])); | ||
const d = K.map((c) => c.map((m) => m.map((u) => u.join("")))); | ||
return h._parseCache[e] = d, d; | ||
@@ -92,3 +92,3 @@ } | ||
this._lastActiveKeyCount = n; | ||
const r = this._parsedKeyCombo[this._sequenceIndex], a = r.slice(0, this._unitIndex), f = r.slice(this._unitIndex), _ = () => { | ||
const r = this._parsedKeyCombo[this._sequenceIndex], a = r.slice(0, this._unitIndex), K = r.slice(this._unitIndex), _ = () => { | ||
this._movingToNextSequenceAt = 0, this._sequenceIndex = 0, this._unitIndex = 0, this._lastActiveKeyPresses.length = 0, this._handlerState.isEmpty && (this._isPressedWithFinalUnit = null); | ||
@@ -106,6 +106,6 @@ }; | ||
for (const c of a) { | ||
for (const p of c) { | ||
for (const m of c) { | ||
let u = !1; | ||
for (let l = d; l < e.length && l < d + c.length; l += 1) | ||
if (e[l].key === p) { | ||
if (e[l].key === m) { | ||
u = !0; | ||
@@ -120,7 +120,7 @@ break; | ||
if (this._movingToNextSequenceAt === 0) { | ||
for (const c of f) { | ||
for (const p of c) { | ||
for (const c of K) { | ||
for (const m of c) { | ||
let u = !1; | ||
for (let l = d; l < e.length && l < d + c.length; l += 1) | ||
if (e[l].key === p) { | ||
if (e[l].key === m) { | ||
u = !0; | ||
@@ -173,3 +173,3 @@ break; | ||
userAgent: "" | ||
}, K = () => typeof document < "u" ? document : E, x = () => typeof navigator < "u" ? navigator : R, q = () => x().userAgent.toLocaleLowerCase().includes("mac"); | ||
}, p = () => typeof document < "u" ? document : E, x = () => typeof navigator < "u" ? navigator : R, q = () => x().userAgent.toLocaleLowerCase().includes("mac"); | ||
let v = !1; | ||
@@ -192,3 +192,3 @@ const I = (i) => { | ||
}); | ||
K().dispatchEvent(e); | ||
p().dispatchEvent(e); | ||
} | ||
@@ -220,3 +220,3 @@ b.clear(); | ||
})); | ||
return K().addEventListener("keydown", e), () => K().removeEventListener("keydown", e); | ||
return p().addEventListener("keydown", e), () => p().removeEventListener("keydown", e); | ||
} catch { | ||
@@ -232,3 +232,3 @@ } | ||
})); | ||
return K().addEventListener("keyup", e), () => K().removeEventListener("keyup", e); | ||
return p().addEventListener("keyup", e), () => p().removeEventListener("keyup", e); | ||
} catch { | ||
@@ -266,2 +266,7 @@ } | ||
var s; | ||
if (typeof e == "object") { | ||
for (const r of e) | ||
this.bindKey(r, t); | ||
return; | ||
} | ||
e = e.toLowerCase(); | ||
@@ -272,2 +277,7 @@ const n = new k(t); | ||
unbindKey(e, t) { | ||
if (typeof e == "object") { | ||
for (const s of e) | ||
this.unbindKey(s, t); | ||
return; | ||
} | ||
e = e.toLowerCase(); | ||
@@ -284,2 +294,7 @@ const n = this._handlerStates[e]; | ||
var s; | ||
if (typeof e == "object") { | ||
for (const r of e) | ||
this.bindKeyCombo(r, t); | ||
return; | ||
} | ||
e = y.normalizeKeyCombo(e); | ||
@@ -290,2 +305,7 @@ const n = new y(e, this._keyComboEventMapper, t); | ||
unbindKeyCombo(e, t) { | ||
if (typeof e == "object") { | ||
for (const s of e) | ||
this.unbindKeyCombo(s, t); | ||
return; | ||
} | ||
e = y.normalizeKeyCombo(e); | ||
@@ -394,5 +414,5 @@ const n = this._keyComboStates[e]; | ||
C = i ?? new S(g); | ||
}, m = () => (C || F(), C), N = (i) => { | ||
}, f = () => (C || F(), C), H = (i) => { | ||
g = i; | ||
}, D = (...i) => m().bindKey(...i), j = (...i) => m().unbindKey(...i), G = (...i) => m().bindKeyCombo(...i), J = (...i) => m().unbindKeyCombo(...i), Q = (...i) => m().checkKey(...i), V = (...i) => m().checkKeyCombo(...i), X = y.normalizeKeyCombo, Y = y.stringifyKeyCombo, Z = y.parseKeyCombo, $ = (i = {}) => { | ||
}, N = (...i) => f().bindKey(...i), D = (...i) => f().unbindKey(...i), G = (...i) => f().bindKeyCombo(...i), J = (...i) => f().unbindKeyCombo(...i), Q = (...i) => f().checkKey(...i), V = (...i) => f().checkKeyCombo(...i), X = y.normalizeKeyCombo, Y = y.stringifyKeyCombo, Z = y.parseKeyCombo, $ = (i = {}) => { | ||
let e, t, n, s; | ||
@@ -429,3 +449,3 @@ return Object.assign(new S({ | ||
export { | ||
D as bindKey, | ||
N as bindKey, | ||
G as bindKeyCombo, | ||
@@ -435,10 +455,10 @@ Q as checkKey, | ||
$ as createTestKeystrokes, | ||
m as getGlobalKeystrokes, | ||
f as getGlobalKeystrokes, | ||
X as normalizeKeyCombo, | ||
Z as parseKeyCombo, | ||
F as setGlobalKeystrokes, | ||
N as setGlobalKeystrokesOptions, | ||
H as setGlobalKeystrokesOptions, | ||
Y as stringifyKeyCombo, | ||
j as unbindKey, | ||
D as unbindKey, | ||
J as unbindKeyCombo | ||
}; |
{ | ||
"name": "@rwh/keystrokes", | ||
"version": "1.2.3", | ||
"version": "1.3.0", | ||
"description": "Keystrokes is an easy to use library for binding functions to keys and key combos. It can be used with any TypeScript or JavaScript project, even in non-browser environments.", | ||
@@ -5,0 +5,0 @@ "type": "module", |
Sorry, the diff of this file is not supported yet
52845
651