@rwh/keystrokes
Advanced tools
Comparing version 1.1.1 to 1.1.2
@@ -1,11 +0,11 @@ | ||
var w = Object.defineProperty; | ||
var E = (n, e, t) => e in n ? w(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t; | ||
var o = (n, e, t) => (E(n, typeof e != "symbol" ? e + "" : e, t), t); | ||
var R = Object.defineProperty; | ||
var w = (n, e, t) => e in n ? R(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t; | ||
var a = (n, e, t) => (w(n, typeof e != "symbol" ? e + "" : e, t), t); | ||
class C { | ||
constructor(e) { | ||
o(this, "_onPressed"); | ||
o(this, "_onPressedWithRepeat"); | ||
o(this, "_onReleased"); | ||
o(this, "_isPressed"); | ||
o(this, "_identity"); | ||
a(this, "_onPressed"); | ||
a(this, "_onPressedWithRepeat"); | ||
a(this, "_onReleased"); | ||
a(this, "_isPressed"); | ||
a(this, "_identity"); | ||
this._isPressed = !1, this._identity = e, typeof e == "function" ? this._onPressedWithRepeat = e : (this._onPressed = e.onPressed, this._onPressedWithRepeat = e.onPressedWithRepeat, this._onReleased = e.onReleased); | ||
@@ -30,9 +30,9 @@ } | ||
constructor(e, t, i = {}) { | ||
o(this, "_normalizedKeyCombo"); | ||
o(this, "_parsedKeyCombo"); | ||
o(this, "_handlerState"); | ||
o(this, "_lastActiveKeyPresses"); | ||
o(this, "_isPressedWithFinalKey"); | ||
o(this, "_sequenceIndex"); | ||
o(this, "_keyComboEventMapper"); | ||
a(this, "_normalizedKeyCombo"); | ||
a(this, "_parsedKeyCombo"); | ||
a(this, "_handlerState"); | ||
a(this, "_lastActiveKeyPresses"); | ||
a(this, "_isPressedWithFinalKey"); | ||
a(this, "_sequenceIndex"); | ||
a(this, "_keyComboEventMapper"); | ||
this._normalizedKeyCombo = c.normalizeKeyCombo(e), this._parsedKeyCombo = c.parseKeyCombo(e), this._handlerState = new C(i), this._keyComboEventMapper = t, this._lastActiveKeyPresses = [], this._isPressedWithFinalKey = null, this._sequenceIndex = 0; | ||
@@ -44,9 +44,9 @@ } | ||
const t = e.toLowerCase(); | ||
let i = "", s = [], a = [s], r = [a]; | ||
let i = "", s = [], o = [s], r = [o]; | ||
const l = [r]; | ||
let y = !1; | ||
for (let h = 0; h < e.length; h += 1) | ||
t[h] === "\\" ? y = !0 : (t[h] === "+" || t[h] === ">" || t[h] === ",") && !y ? i = t[h] : t[h].match(/[^\s]/) && (i && (i === "," ? (s = [], a = [s], r = [a], l.push(r)) : i === ">" ? (s = [], a = [s], r.push(a)) : i === "+" && (s = [], a.push(s)), i = ""), y = !1, s.push(t[h])); | ||
const K = l.map((h) => h.map((k) => k.map((g) => g.join("")))); | ||
return c._parseCache[e] = K, K; | ||
t[h] === "\\" ? y = !0 : (t[h] === "+" || t[h] === ">" || t[h] === ",") && !y ? i = t[h] : t[h].match(/[^\s]/) && (i && (i === "," ? (s = [], o = [s], r = [o], l.push(r)) : i === ">" ? (s = [], o = [s], r.push(o)) : i === "+" && (s = [], o.push(s)), i = ""), y = !1, s.push(t[h])); | ||
const m = l.map((h) => h.map((S) => S.map((g) => g.join("")))); | ||
return c._parseCache[e] = m, m; | ||
} | ||
@@ -83,9 +83,9 @@ static stringifyKeyCombo(e) { | ||
for (const s of t) { | ||
let a = i; | ||
let o = i; | ||
for (const r of s) { | ||
let l = !1; | ||
for (let y = i; y < e.length; y += 1) { | ||
const K = e[y]; | ||
if (r === K.key) { | ||
y > a && (a = y), l = !0; | ||
const m = e[y]; | ||
if (r === m.key) { | ||
y > o && (o = y), l = !0; | ||
break; | ||
@@ -99,13 +99,13 @@ } | ||
} | ||
i = a; | ||
i = o; | ||
} | ||
for (const s of e) { | ||
let a = !1; | ||
let o = !1; | ||
for (const r of t) | ||
for (const l of r) | ||
if (s.key === l) { | ||
a = !0; | ||
o = !0; | ||
break; | ||
} | ||
if (!a) { | ||
if (!o) { | ||
this._lastActiveKeyPresses.length = 0, this._sequenceIndex = 0; | ||
@@ -130,5 +130,5 @@ return; | ||
}; | ||
o(c, "_parseCache", {}), o(c, "_normalizationCache", {}); | ||
a(c, "_parseCache", {}), a(c, "_normalizationCache", {}); | ||
let d = c; | ||
const R = { | ||
const E = { | ||
/* | ||
@@ -152,16 +152,16 @@ eslint-disable | ||
userAgent: "" | ||
}, u = () => typeof document < "u" ? document : R, x = () => typeof navigator < "u" ? navigator : A, f = x().userAgent.toLocaleLowerCase().includes("mac"); | ||
let m = ""; | ||
}, u = () => typeof document < "u" ? document : E, x = () => typeof navigator < "u" ? navigator : A, f = x().userAgent.toLocaleLowerCase().includes("mac"); | ||
let K = ""; | ||
const B = (n) => { | ||
!f || n.key !== "Meta" || (m = n.code); | ||
!f || n.key !== "Meta" || (K = n.code); | ||
}, I = (n) => !(!f || n.key !== "Meta"), P = () => { | ||
if (!f || !m) | ||
if (!f || !K) | ||
return; | ||
const n = new KeyboardEvent("keyup", { | ||
key: "Meta", | ||
code: m, | ||
code: K, | ||
bubbles: !0, | ||
cancelable: !0 | ||
}); | ||
m = "", u().dispatchEvent(n); | ||
K = "", u().dispatchEvent(n); | ||
}, W = (n) => { | ||
@@ -215,20 +215,20 @@ try { | ||
}, z = typeof requestAnimationFrame == "function" ? (n) => requestAnimationFrame(n) : (n) => setTimeout(n, 0), b = () => new Promise((n) => z(n)); | ||
class v { | ||
class k { | ||
constructor(e = {}) { | ||
o(this, "_isActive"); | ||
o(this, "_isUpdatingKeyComboState"); | ||
o(this, "_unbinder"); | ||
o(this, "_onActiveBinder"); | ||
o(this, "_onInactiveBinder"); | ||
o(this, "_onKeyPressedBinder"); | ||
o(this, "_onKeyReleasedBinder"); | ||
o(this, "_keyComboEventMapper"); | ||
o(this, "_selfReleasingKeys"); | ||
o(this, "_keyRemap"); | ||
o(this, "_handlerStates"); | ||
o(this, "_keyComboStates"); | ||
o(this, "_keyComboStatesArray"); | ||
o(this, "_activeKeyPresses"); | ||
o(this, "_activeKeySet"); | ||
o(this, "_watchedKeyComboStates"); | ||
a(this, "_isActive"); | ||
a(this, "_isUpdatingKeyComboState"); | ||
a(this, "_unbinder"); | ||
a(this, "_onActiveBinder"); | ||
a(this, "_onInactiveBinder"); | ||
a(this, "_onKeyPressedBinder"); | ||
a(this, "_onKeyReleasedBinder"); | ||
a(this, "_keyComboEventMapper"); | ||
a(this, "_selfReleasingKeys"); | ||
a(this, "_keyRemap"); | ||
a(this, "_handlerStates"); | ||
a(this, "_keyComboStates"); | ||
a(this, "_keyComboStatesArray"); | ||
a(this, "_activeKeyPresses"); | ||
a(this, "_activeKeySet"); | ||
a(this, "_watchedKeyComboStates"); | ||
this._isActive = !0, this._isUpdatingKeyComboState = !1, this._onActiveBinder = () => { | ||
@@ -272,4 +272,4 @@ }, this._onInactiveBinder = () => { | ||
if (i[s].isOwnHandler(t)) { | ||
for (let a = 0; a < this._keyComboStatesArray.length; a += 1) | ||
this._keyComboStatesArray[a] === i[s] && (this._keyComboStatesArray.splice(a, 1), a -= 1); | ||
for (let o = 0; o < this._keyComboStatesArray.length; o += 1) | ||
this._keyComboStatesArray[o] === i[s] && (this._keyComboStatesArray.splice(o, 1), o -= 1); | ||
i.splice(s, 1), s -= 1; | ||
@@ -290,3 +290,3 @@ } | ||
bindEnvironment(e = {}) { | ||
this.unbindEnvironment(), this._onActiveBinder = e.onActive ?? W, this._onInactiveBinder = e.onInactive ?? L, this._onKeyPressedBinder = e.onKeyPressed ?? O, this._onKeyReleasedBinder = e.onKeyReleased ?? q, this._keyComboEventMapper = e.mapKeyComboEvent ?? (() => ({})), this._selfReleasingKeys = e.selfReleasingKeys ?? []; | ||
this.unbindEnvironment(), this._onActiveBinder = e.onActive ?? W, this._onInactiveBinder = e.onInactive ?? L, this._onKeyPressedBinder = e.onKeyPressed ?? O, this._onKeyReleasedBinder = e.onKeyReleased ?? q, this._keyComboEventMapper = e.mapKeyComboEvent ?? (() => ({})), this._selfReleasingKeys = e.selfReleasingKeys ?? [], this._keyRemap = e.keyRemap ?? {}; | ||
const t = this._onActiveBinder(() => { | ||
@@ -298,7 +298,7 @@ this._isActive = !0; | ||
this._handleKeyPress(r); | ||
}), a = this._onKeyReleasedBinder((r) => { | ||
}), o = this._onKeyReleasedBinder((r) => { | ||
this._handleKeyRelease(r); | ||
}); | ||
this._unbinder = () => { | ||
t == null || t(), i == null || i(), s == null || s(), a == null || a(); | ||
t == null || t(), i == null || i(), s == null || s(), o == null || o(); | ||
}; | ||
@@ -374,10 +374,10 @@ } | ||
} | ||
let S, p; | ||
let v, p; | ||
const M = (n) => { | ||
p = n ?? new v(S); | ||
p = n ?? new k(v); | ||
}, _ = () => (p || M(), p), H = (n) => { | ||
S = n; | ||
v = n; | ||
}, U = (...n) => _().bindKey(...n), j = (...n) => _().unbindKey(...n), T = (...n) => _().bindKeyCombo(...n), D = (...n) => _().unbindKeyCombo(...n), G = (...n) => _().checkKey(...n), N = (...n) => _().checkKeyCombo(...n), J = d.normalizeKeyCombo, Q = d.stringifyKeyCombo, V = d.parseKeyCombo, X = (n = {}) => { | ||
let e, t, i, s; | ||
return Object.assign(new v({ | ||
return Object.assign(new k({ | ||
...n, | ||
@@ -412,3 +412,3 @@ onActive(r) { | ||
export { | ||
v as Keystrokes, | ||
k as Keystrokes, | ||
U as bindKey, | ||
@@ -415,0 +415,0 @@ T as bindKeyCombo, |
{ | ||
"name": "@rwh/keystrokes", | ||
"version": "1.1.1", | ||
"version": "1.1.2", | ||
"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.", | ||
@@ -47,5 +47,3 @@ "type": "module", | ||
"eslint-plugin-prettier": "^5.0.0", | ||
"node-static": "^0.7.11", | ||
"prettier": "^3.0.0", | ||
"ts-node": "^10.9.1", | ||
"typescript": "^5.1.6", | ||
@@ -52,0 +50,0 @@ "vite": "^4.4.6", |
Sorry, the diff of this file is not supported yet
50713
11