@rwh/keystrokes
Advanced tools
Comparing version 1.4.0 to 1.5.0
@@ -1,5 +0,5 @@ | ||
var A = Object.defineProperty; | ||
var w = (i, e, t) => e in i ? A(i, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[e] = t; | ||
var o = (i, e, t) => (w(i, typeof e != "symbol" ? e + "" : e, t), t); | ||
const E = { | ||
var E = Object.defineProperty; | ||
var A = (i, e, t) => e in i ? E(i, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[e] = t; | ||
var o = (i, e, t) => (A(i, typeof e != "symbol" ? e + "" : e, t), t); | ||
const w = { | ||
/* | ||
@@ -23,3 +23,3 @@ eslint-disable | ||
userAgent: "" | ||
}, p = () => typeof document < "u" ? document : E, x = () => typeof navigator < "u" ? navigator : R, q = () => x().userAgent.toLocaleLowerCase().includes("mac"); | ||
}, m = () => typeof document < "u" ? document : w, x = () => typeof navigator < "u" ? navigator : R, q = () => x().userAgent.toLowerCase().includes("mac"); | ||
let v = !1; | ||
@@ -32,3 +32,3 @@ const I = (i) => { | ||
b.set(i.key, i); | ||
}, L = (i) => { | ||
}, W = (i) => { | ||
b.delete(i.key); | ||
@@ -43,6 +43,6 @@ }, k = () => { | ||
}); | ||
p().dispatchEvent(e); | ||
m().dispatchEvent(e); | ||
} | ||
b.clear(); | ||
}, W = (i) => { | ||
}, L = (i) => { | ||
try { | ||
@@ -65,9 +65,16 @@ const e = () => i(); | ||
try { | ||
const e = (t) => (B(t), I(t), i({ | ||
key: t.key, | ||
originalEvent: t, | ||
composedPath: () => t.composedPath(), | ||
preventDefault: () => t.preventDefault() | ||
})); | ||
return p().addEventListener("keydown", e), () => p().removeEventListener("keydown", e); | ||
const e = (t) => { | ||
B(t), I(t), i({ | ||
key: t.key, | ||
originalEvent: t, | ||
composedPath: () => t.composedPath(), | ||
preventDefault: () => t.preventDefault() | ||
}), t.code && i({ | ||
key: `@${t.code}`, | ||
originalEvent: t, | ||
composedPath: () => t.composedPath(), | ||
preventDefault: () => t.preventDefault() | ||
}); | ||
}; | ||
return m().addEventListener("keydown", e), () => m().removeEventListener("keydown", e); | ||
} catch { | ||
@@ -77,9 +84,16 @@ } | ||
try { | ||
const e = (t) => (L(t), M(t), i({ | ||
key: t.key, | ||
originalEvent: t, | ||
composedPath: () => t.composedPath(), | ||
preventDefault: () => t.preventDefault() | ||
})); | ||
return p().addEventListener("keyup", e), () => p().removeEventListener("keyup", e); | ||
const e = (t) => { | ||
W(t), M(t), i({ | ||
key: t.key, | ||
originalEvent: t, | ||
composedPath: () => t.composedPath(), | ||
preventDefault: () => t.preventDefault() | ||
}), t.code && i({ | ||
key: `@${t.code}`, | ||
originalEvent: t, | ||
composedPath: () => t.composedPath(), | ||
preventDefault: () => t.preventDefault() | ||
}); | ||
}; | ||
return m().addEventListener("keyup", e), () => m().removeEventListener("keyup", e); | ||
} catch { | ||
@@ -142,3 +156,3 @@ } | ||
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("")))); | ||
const d = K.map((c) => c.map((p) => p.map((u) => u.join("")))); | ||
return h._parseCache[e] = d, d; | ||
@@ -188,6 +202,6 @@ } | ||
for (const c of a) { | ||
for (const m of c) { | ||
for (const p of c) { | ||
let u = !1; | ||
for (let l = d; l < e.length && l < d + c.length; l += 1) | ||
if (e[l].key === m) { | ||
if (e[l].key === p) { | ||
u = !0; | ||
@@ -203,6 +217,6 @@ break; | ||
for (const c of K) { | ||
for (const m of c) { | ||
for (const p of c) { | ||
let u = !1; | ||
for (let l = d; l < e.length && l < d + c.length; l += 1) | ||
if (e[l].key === m) { | ||
if (e[l].key === p) { | ||
u = !0; | ||
@@ -330,3 +344,3 @@ break; | ||
bindEnvironment(e = {}) { | ||
this.unbindEnvironment(), this._onActiveBinder = e.onActive ?? W, this._onInactiveBinder = e.onInactive ?? O, this._onKeyPressedBinder = e.onKeyPressed ?? z, this._onKeyReleasedBinder = e.onKeyReleased ?? T, this._keyComboEventMapper = e.mapKeyComboEvent ?? (() => ({})), this._selfReleasingKeys = e.selfReleasingKeys ?? [], this._keyRemap = e.keyRemap ?? {}; | ||
this.unbindEnvironment(), this._onActiveBinder = e.onActive ?? L, this._onInactiveBinder = e.onInactive ?? O, this._onKeyPressedBinder = e.onKeyPressed ?? z, this._onKeyReleasedBinder = e.onKeyReleased ?? T, this._keyComboEventMapper = e.mapKeyComboEvent ?? (() => ({})), this._selfReleasingKeys = e.selfReleasingKeys ?? [], this._keyRemap = e.keyRemap ?? {}; | ||
const t = this._onActiveBinder(() => { | ||
@@ -409,7 +423,7 @@ this._isActive = !0; | ||
let g, C; | ||
const F = (i) => { | ||
const D = (i) => { | ||
C = i ?? new S(g); | ||
}, f = () => (C || F(), C), H = (i) => { | ||
}, f = () => (C || D(), C), j = (i) => { | ||
g = 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 = {}) => { | ||
}, H = (...i) => f().bindKey(...i), N = (...i) => f().unbindKey(...i), G = (...i) => f().bindKeyCombo(...i), $ = (...i) => f().unbindKeyCombo(...i), J = (...i) => f().checkKey(...i), Q = (...i) => f().checkKeyCombo(...i), V = y.normalizeKeyCombo, X = y.stringifyKeyCombo, Y = y.parseKeyCombo, Z = (i = {}) => { | ||
let e, t, n, s; | ||
@@ -449,20 +463,20 @@ return Object.assign(new S({ | ||
S as Keystrokes, | ||
N as bindKey, | ||
H as bindKey, | ||
G as bindKeyCombo, | ||
W as browserOnActiveBinder, | ||
L as browserOnActiveBinder, | ||
O as browserOnInactiveBinder, | ||
z as browserOnKeyPressedBinder, | ||
T as browserOnKeyReleasedBinder, | ||
Q as checkKey, | ||
V as checkKeyCombo, | ||
$ as createTestKeystrokes, | ||
J as checkKey, | ||
Q as checkKeyCombo, | ||
Z as createTestKeystrokes, | ||
U as defaultSequenceTimeout, | ||
f as getGlobalKeystrokes, | ||
X as normalizeKeyCombo, | ||
Z as parseKeyCombo, | ||
F as setGlobalKeystrokes, | ||
H as setGlobalKeystrokesOptions, | ||
Y as stringifyKeyCombo, | ||
D as unbindKey, | ||
J as unbindKeyCombo | ||
V as normalizeKeyCombo, | ||
Y as parseKeyCombo, | ||
D as setGlobalKeystrokes, | ||
j as setGlobalKeystrokesOptions, | ||
X as stringifyKeyCombo, | ||
N as unbindKey, | ||
$ as unbindKeyCombo | ||
}; |
{ | ||
"name": "@rwh/keystrokes", | ||
"version": "1.4.0", | ||
"version": "1.5.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.", | ||
@@ -48,3 +48,3 @@ "type": "module", | ||
"typescript": "^5.1.6", | ||
"vite": "^4.4.8", | ||
"vite": "^4.4.12", | ||
"vitest": "^0.34.1" | ||
@@ -51,0 +51,0 @@ }, |
@@ -77,2 +77,13 @@ <h1 align="center"> | ||
It is also possible to use [KeyboardEvent.code][code] should you care more | ||
about the key's location on the keyboard than it's value. To use code instead | ||
of key, prepend the key name with `@`. For example `@KeyW` binds the | ||
physical key labeled `W` on a QWERTY keyboard, `Z` on a AZERTY keyboard, and | ||
`<` on a Dvorak keyboard - the same physical key by position on all of these | ||
keyboards. | ||
To see what code names can be used in your bindings see MDN's | ||
[table of code values][code-names]. Don't forget to prepend code names with `@` | ||
when using them in bindings. | ||
Note that if you need to bind a combo containing a key name like `+` which is | ||
@@ -96,2 +107,3 @@ used as a combo operator, you will need to escape the character using backslash. | ||
### Combo Unit | ||
A combo unit is a grouping of key names separated by the `+` operator. Keys in | ||
@@ -515,3 +527,5 @@ a unit can be pressed in any order. One or more units make up a sequence, and | ||
[key]: https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key | ||
[code]: https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/code | ||
[code-names]: https://developer.mozilla.org/en-US/docs/Web/API/UI_Events/Keyboard_event_code_values | ||
[bug-report]: https://github.com/RobertWHurst/Keystrokes/issues/new?template=bug_report.md | ||
[feature-request]: https://github.com/RobertWHurst/Keystrokes/issues/new?template=feature_request.md |
Sorry, the diff of this file is not supported yet
57148
681
529