New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@rwh/keystrokes

Package Overview
Dependencies
Maintainers
1
Versions
45
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@rwh/keystrokes - npm Package Compare versions

Comparing version 1.5.3 to 1.5.4

368

dist/keystrokes.js
var w = Object.defineProperty;
var A = (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) => (A(n, typeof e != "symbol" ? e + "" : e, t), t);
var A = (a, e, t) => e in a ? w(a, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : a[e] = t;
var r = (a, e, t) => (A(a, typeof e != "symbol" ? e + "" : e, t), t);
const R = {

@@ -10,7 +10,7 @@ /*

*/
addEventListener: (...n) => {
addEventListener: (...a) => {
},
removeEventListener: (...n) => {
removeEventListener: (...a) => {
},
dispatchEvent: (...n) => {
dispatchEvent: (...a) => {
}

@@ -24,26 +24,26 @@ /*

userAgent: ""
}, p = () => typeof document < "u" ? document : R, x = () => typeof navigator < "u" ? navigator : E, q = () => x().userAgent.toLowerCase().includes("mac");
}, K = () => typeof document < "u" ? document : R, x = () => typeof navigator < "u" ? navigator : E, q = () => x().userAgent.toLowerCase().includes("mac");
let C = !1;
const I = (n) => {
!q() || n.key !== "Meta" || (C = !0);
}, M = (n) => {
!C || n.key !== "Meta" || (C = !1, k());
}, b = /* @__PURE__ */ new Map(), B = (n) => {
b.set(n.key, n);
}, W = (n) => {
b.delete(n.key);
const I = (a) => {
!q() || a.key !== "Meta" || (C = !0);
}, M = (a) => {
!C || a.key !== "Meta" || (C = !1, k());
}, b = /* @__PURE__ */ new Map(), B = (a) => {
b.set(a.key, a);
}, W = (a) => {
b.delete(a.key);
}, k = () => {
for (const n of b.values()) {
for (const a of b.values()) {
const e = new KeyboardEvent("keyup", {
key: n.key,
code: n.code,
key: a.key,
code: a.code,
bubbles: !0,
cancelable: !0
});
p().dispatchEvent(e);
K().dispatchEvent(e);
}
b.clear();
}, L = (n) => {
}, L = (a) => {
try {
const e = () => n();
const e = () => a();
return addEventListener("focus", e), () => {

@@ -54,6 +54,6 @@ removeEventListener("focus", e);

}
}, O = (n) => {
}, O = (a) => {
try {
const e = () => {
k(), n();
k(), a();
};

@@ -63,6 +63,6 @@ return addEventListener("blur", e), () => removeEventListener("blur", e);

}
}, z = (n) => {
}, z = (a) => {
try {
const e = (t) => {
B(t), I(t), n({
B(t), I(t), a({
key: t.key,

@@ -75,9 +75,9 @@ aliases: [`@${t.code}`],

};
return p().addEventListener("keydown", e), () => p().removeEventListener("keydown", e);
return K().addEventListener("keydown", e), () => K().removeEventListener("keydown", e);
} catch {
}
}, T = (n) => {
}, T = (a) => {
try {
const e = (t) => {
W(t), M(t), n({
W(t), M(t), a({
key: t.key,

@@ -90,3 +90,3 @@ aliases: [`@${t.code}`],

};
return p().addEventListener("keyup", e), () => p().removeEventListener("keyup", e);
return K().addEventListener("keyup", e), () => K().removeEventListener("keyup", e);
} catch {

@@ -97,7 +97,7 @@ }

constructor(e) {
o(this, "_onPressed");
o(this, "_onPressedWithRepeat");
o(this, "_onReleased");
o(this, "_isPressed");
o(this, "_identity");
r(this, "_onPressed");
r(this, "_onPressedWithRepeat");
r(this, "_onReleased");
r(this, "_isPressed");
r(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);

@@ -112,4 +112,4 @@ }

executePressed(e) {
var t, i;
this._isPressed || (t = this._onPressed) == null || t.call(this, e), this._isPressed = !0, (i = this._onPressedWithRepeat) == null || i.call(this, e);
var t, s;
this._isPressed || (t = this._onPressed) == null || t.call(this, e), this._isPressed = !0, (s = this._onPressedWithRepeat) == null || s.call(this, e);
}

@@ -122,14 +122,14 @@ executeReleased(e) {

const h = class h {
constructor(e, t, i = {}) {
o(this, "_normalizedKeyCombo");
o(this, "_parsedKeyCombo");
o(this, "_handlerState");
o(this, "_keyComboEventMapper");
o(this, "_movingToNextSequenceAt");
o(this, "_sequenceIndex");
o(this, "_unitIndex");
o(this, "_lastActiveKeyPresses");
o(this, "_lastActiveKeyCount");
o(this, "_isPressedWithFinalUnit");
this._normalizedKeyCombo = h.normalizeKeyCombo(e), this._parsedKeyCombo = h.parseKeyCombo(e), this._handlerState = new S(i), this._keyComboEventMapper = t, this._movingToNextSequenceAt = 0, this._sequenceIndex = 0, this._unitIndex = 0, this._lastActiveKeyPresses = [], this._lastActiveKeyCount = 0, this._isPressedWithFinalUnit = null;
constructor(e, t, s = {}) {
r(this, "_normalizedKeyCombo");
r(this, "_parsedKeyCombo");
r(this, "_handlerState");
r(this, "_keyComboEventMapper");
r(this, "_movingToNextSequenceAt");
r(this, "_sequenceIndex");
r(this, "_unitIndex");
r(this, "_lastActiveKeyPresses");
r(this, "_lastActiveKeyCount");
r(this, "_isPressedWithFinalUnit");
this._normalizedKeyCombo = h.normalizeKeyCombo(e), this._parsedKeyCombo = h.parseKeyCombo(e), this._handlerState = new S(s), this._keyComboEventMapper = t, this._movingToNextSequenceAt = 0, this._sequenceIndex = 0, this._unitIndex = 0, this._lastActiveKeyPresses = [], this._lastActiveKeyCount = 0, this._isPressedWithFinalUnit = null;
}

@@ -140,19 +140,19 @@ static parseKeyCombo(e) {

const t = e.toLowerCase();
let i = "", s = [], a = [s], r = [a];
const K = [r];
let _ = !1;
let s = "", i = [], n = [i], o = [n];
const _ = [o];
let u = !1;
for (let c = 0; c < e.length; c += 1)
if (t[c] === "\\")
_ = !0;
else if ((t[c] === "+" || t[c] === ">" || t[c] === ",") && !_) {
if (i)
u = !0;
else if ((t[c] === "+" || t[c] === ">" || t[c] === ",") && !u) {
if (s)
throw new Error("cannot have two operators in a row");
i = t[c];
s = t[c];
} else
t[c].match(/[^\s]/) && (i && (i === "," ? (s = [], a = [s], r = [a], K.push(r)) : i === ">" ? (s = [], a = [s], r.push(a)) : i === "+" && (s = [], a.push(s)), i = ""), _ = !1, s.push(t[c]));
const d = K.map((c) => c.map((u) => u.map((f) => f.join(""))));
t[c].match(/[^\s]/) && (s && (s === "," ? (i = [], n = [i], o = [n], _.push(o)) : s === ">" ? (i = [], n = [i], o.push(n)) : s === "+" && (i = [], n.push(i)), s = ""), u = !1, i.push(t[c]));
const d = _.map((c) => c.map((m) => m.map((f) => f.join(""))));
return h._parseCache[e] = d, d;
}
static stringifyKeyCombo(e) {
return e.map((t) => t.map((i) => i.map((s) => s === "+" ? "\\+" : s === ">" ? "\\>" : s === "," ? "\\," : s).join("+")).join(">")).join(",");
return e.map((t) => t.map((s) => s.map((i) => i === "+" ? "\\+" : i === ">" ? "\\>" : i === "," ? "\\," : i).join("+")).join(">")).join(",");
}

@@ -175,6 +175,6 @@ static normalizeKeyCombo(e) {

executePressed(e) {
var t, i;
!((t = this._isPressedWithFinalUnit) != null && t.has(e.key)) && !((i = e.aliases) != null && i.some((s) => {
var a;
return (a = this._isPressedWithFinalUnit) == null ? void 0 : a.has(s);
var t, s;
!((t = this._isPressedWithFinalUnit) != null && t.has(e.key)) && !((s = e.aliases) != null && s.some((i) => {
var n;
return (n = this._isPressedWithFinalUnit) == null ? void 0 : n.has(i);
})) || this._handlerState.executePressed(this._wrapEvent(this._lastActiveKeyPresses, {

@@ -187,6 +187,6 @@ key: e.key,

executeReleased(e) {
var t, i;
!((t = this._isPressedWithFinalUnit) != null && t.has(e.key)) && !((i = e.aliases) != null && i.some((s) => {
var a;
return (a = this._isPressedWithFinalUnit) == null ? void 0 : a.has(s);
var t, s;
!((t = this._isPressedWithFinalUnit) != null && t.has(e.key)) && !((s = e.aliases) != null && s.some((i) => {
var n;
return (n = this._isPressedWithFinalUnit) == null ? void 0 : n.has(i);
})) || (this._handlerState.executeReleased(this._wrapEvent(this._lastActiveKeyPresses, {

@@ -199,12 +199,12 @@ key: e.key,

updateState(e, t) {
const i = e.length, s = i < this._lastActiveKeyCount;
this._lastActiveKeyCount = i;
const a = this._parsedKeyCombo[this._sequenceIndex], r = a.slice(0, this._unitIndex), K = a.slice(this._unitIndex), _ = () => {
const s = e.length, i = s < this._lastActiveKeyCount;
this._lastActiveKeyCount = s;
const n = this._parsedKeyCombo[this._sequenceIndex], o = n.slice(0, this._unitIndex), _ = n.slice(this._unitIndex), u = () => {
this._movingToNextSequenceAt = 0, this._sequenceIndex = 0, this._unitIndex = 0, this._lastActiveKeyPresses.length = 0, this._handlerState.isEmpty && (this._isPressedWithFinalUnit = null);
};
let d = 0;
if (s) {
if (i) {
if (this._movingToNextSequenceAt === 0)
return _();
if (this._movingToNextSequenceAt + t < Date.now() || i !== 0)
return u();
if (this._movingToNextSequenceAt + t < Date.now() || s !== 0)
return;

@@ -214,7 +214,7 @@ this._movingToNextSequenceAt = 0, this._sequenceIndex += 1, this._unitIndex = 0;

}
for (const c of r) {
for (const u of c) {
for (const c of o) {
for (const m of c) {
let f = !1;
for (let l = d; l < e.length && l < d + c.length; l += 1)
if (e[l].key === u || e[l].aliases.has(u)) {
if (e[l].key === m || e[l].aliases.has(m)) {
f = !0;

@@ -224,3 +224,3 @@ break;

if (!f)
return _();
return u();
}

@@ -230,7 +230,7 @@ d += c.length;

if (this._movingToNextSequenceAt === 0) {
for (const c of K) {
for (const u of c) {
for (const c of _) {
for (const m of c) {
let f = !1;
for (let l = d; l < e.length && l < d + c.length; l += 1)
if (e[l].key === u || e[l].aliases.has(u)) {
if (e[l].key === m || e[l].aliases.has(m)) {
f = !0;

@@ -244,4 +244,4 @@ break;

}
if (d < i - 1)
return _();
if (d < s - 1)
return u();
if (this._lastActiveKeyPresses[this._sequenceIndex] = e.slice(0), this._sequenceIndex < this._parsedKeyCombo.length - 1) {

@@ -251,3 +251,3 @@ this._movingToNextSequenceAt = Date.now();

}
this._isPressedWithFinalUnit = new Set(a[a.length - 1]);
this._isPressedWithFinalUnit = new Set(n[n.length - 1]);
}

@@ -259,3 +259,3 @@ }

keyCombo: this._normalizedKeyCombo,
keyEvents: e.flat().map((s) => s.event),
keyEvents: e.flat().map((i) => i.event),
finalKeyEvent: t.event

@@ -265,3 +265,3 @@ };

};
o(h, "_parseCache", {}), o(h, "_normalizationCache", {});
r(h, "_parseCache", {}), r(h, "_normalizationCache", {});
let y = h;

@@ -271,18 +271,18 @@ const U = 1e3;

constructor(e = {}) {
o(this, "sequenceTimeout");
o(this, "_isActive");
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, "_activeKeyMap");
o(this, "_watchedKeyComboStates");
r(this, "sequenceTimeout");
r(this, "_isActive");
r(this, "_unbinder");
r(this, "_onActiveBinder");
r(this, "_onInactiveBinder");
r(this, "_onKeyPressedBinder");
r(this, "_onKeyReleasedBinder");
r(this, "_keyComboEventMapper");
r(this, "_selfReleasingKeys");
r(this, "_keyRemap");
r(this, "_handlerStates");
r(this, "_keyComboStates");
r(this, "_keyComboStatesArray");
r(this, "_activeKeyPresses");
r(this, "_activeKeyMap");
r(this, "_watchedKeyComboStates");
this.sequenceTimeout = U, this._isActive = !0, this._onActiveBinder = () => {

@@ -298,56 +298,56 @@ }, this._onInactiveBinder = () => {

bindKey(e, t) {
var s;
var i;
if (typeof e == "object") {
for (const a of e)
this.bindKey(a, t);
for (const n of e)
this.bindKey(n, t);
return;
}
e = e.toLowerCase();
const i = new S(t);
(s = this._handlerStates)[e] ?? (s[e] = []), this._handlerStates[e].push(i);
const s = new S(t);
(i = this._handlerStates)[e] ?? (i[e] = []), this._handlerStates[e].push(s);
}
unbindKey(e, t) {
if (typeof e == "object") {
for (const s of e)
this.unbindKey(s, t);
for (const i of e)
this.unbindKey(i, t);
return;
}
e = e.toLowerCase();
const i = this._handlerStates[e];
if (i)
const s = this._handlerStates[e];
if (s)
if (t)
for (let s = 0; s < i.length; s += 1)
i[s].isOwnHandler(t) && (i.splice(s, 1), s -= 1);
for (let i = 0; i < s.length; i += 1)
s[i].isOwnHandler(t) && (s.splice(i, 1), i -= 1);
else
i.length = 0;
s.length = 0;
}
bindKeyCombo(e, t) {
var s;
var i;
if (typeof e == "object") {
for (const a of e)
this.bindKeyCombo(a, t);
for (const n of e)
this.bindKeyCombo(n, t);
return;
}
e = y.normalizeKeyCombo(e);
const i = new y(e, this._keyComboEventMapper, t);
(s = this._keyComboStates)[e] ?? (s[e] = []), this._keyComboStates[e].push(i), this._keyComboStatesArray.push(i);
const s = new y(e, this._keyComboEventMapper, t);
(i = this._keyComboStates)[e] ?? (i[e] = []), this._keyComboStates[e].push(s), this._keyComboStatesArray.push(s);
}
unbindKeyCombo(e, t) {
if (typeof e == "object") {
for (const s of e)
this.unbindKeyCombo(s, t);
for (const i of e)
this.unbindKeyCombo(i, t);
return;
}
e = y.normalizeKeyCombo(e);
const i = this._keyComboStates[e];
if (i)
const s = this._keyComboStates[e];
if (s)
if (t) {
for (let s = 0; s < i.length; s += 1)
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);
i.splice(s, 1), s -= 1;
for (let i = 0; i < s.length; i += 1)
if (s[i].isOwnHandler(t)) {
for (let n = 0; n < this._keyComboStatesArray.length; n += 1)
this._keyComboStatesArray[n] === s[i] && (this._keyComboStatesArray.splice(n, 1), n -= 1);
s.splice(i, 1), i -= 1;
}
} else
i.length = 0;
s.length = 0;
}

@@ -367,11 +367,11 @@ checkKey(e) {

this._isActive = !0;
}), i = this._onInactiveBinder(() => {
}), s = this._onInactiveBinder(() => {
this._isActive = !1;
}), s = this._onKeyPressedBinder((r) => {
this._handleKeyPress(r);
}), a = this._onKeyReleasedBinder((r) => {
this._handleKeyRelease(r);
}), i = this._onKeyPressedBinder((o) => {
this._handleKeyPress(o);
}), n = this._onKeyReleasedBinder((o) => {
this._handleKeyRelease(o);
});
this._unbinder = () => {
t == null || t(), i == null || i(), s == null || s(), a == null || a();
t == null || t(), s == null || s(), i == null || i(), n == null || n();
};

@@ -389,20 +389,25 @@ }

_handleKeyPress(e) {
var n;
if (!this._isActive)
return;
e = { ...e, key: e.key.toLowerCase() };
e = {
...e,
key: e.key.toLowerCase(),
aliases: ((n = e.aliases) == null ? void 0 : n.map((o) => o.toLowerCase())) ?? []
};
const t = this._keyRemap[e.key];
if (t && (e.key = t), e.aliases)
for (let a = 0; a < e.aliases.length; a += 1) {
const r = this._keyRemap[e.aliases[a]];
r && (e.aliases[a] = r);
for (let o = 0; o < e.aliases.length; o += 1) {
const _ = this._keyRemap[e.aliases[o]];
_ && (e.aliases[o] = _);
}
const i = this._handlerStates[e.key];
const s = this._handlerStates[e.key];
if (s)
for (const o of s)
o.executePressed(e);
const i = this._activeKeyMap.get(e.key);
if (i)
for (const a of i)
a.executePressed(e);
const s = this._activeKeyMap.get(e.key);
if (s)
s.event = e;
i.event = e;
else {
const a = {
const o = {
key: e.key,

@@ -412,25 +417,30 @@ aliases: new Set(e.aliases),

};
this._activeKeyMap.set(e.key, a), this._activeKeyPresses.push(a);
this._activeKeyMap.set(e.key, o), this._activeKeyPresses.push(o);
}
this._updateKeyComboStates();
for (const a of this._keyComboStatesArray)
a.executePressed(e);
for (const o of this._keyComboStatesArray)
o.executePressed(e);
}
_handleKeyRelease(e) {
e = { ...e, key: e.key.toLowerCase() };
var i;
e = {
...e,
key: e.key.toLowerCase(),
aliases: ((i = e.aliases) == null ? void 0 : i.map((n) => n.toLowerCase())) ?? []
};
const t = this._keyRemap[e.key];
if (t && (e.key = t), e.aliases)
for (let s = 0; s < e.aliases.length; s += 1) {
const a = this._keyRemap[e.aliases[s]];
a && (e.aliases[s] = a);
for (let n = 0; n < e.aliases.length; n += 1) {
const o = this._keyRemap[e.aliases[n]];
o && (e.aliases[n] = o);
}
const i = this._handlerStates[e.key];
if (i)
for (const s of i)
s.executeReleased(e);
const s = this._handlerStates[e.key];
if (s)
for (const n of s)
n.executeReleased(e);
if (this._activeKeyMap.has(e.key)) {
this._activeKeyMap.delete(e.key);
for (let s = 0; s < this._activeKeyPresses.length; s += 1)
if (this._activeKeyPresses[s].key === e.key) {
this._activeKeyPresses.splice(s, 1), s -= 1;
for (let n = 0; n < this._activeKeyPresses.length; n += 1)
if (this._activeKeyPresses[n].key === e.key) {
this._activeKeyPresses.splice(n, 1), n -= 1;
break;

@@ -440,4 +450,4 @@ }

this._tryReleaseSelfReleasingKeys(), this._updateKeyComboStates();
for (const s of this._keyComboStatesArray)
s.executeReleased(e);
for (const n of this._keyComboStatesArray)
n.executeReleased(e);
}

@@ -455,21 +465,21 @@ _updateKeyComboStates() {

let g, v;
const F = (n) => {
v = n ?? new P(g);
}, m = () => (v || F(), v), H = (n) => {
g = n;
}, N = (...n) => m().bindKey(...n), D = (...n) => m().unbindKey(...n), G = (...n) => m().bindKeyCombo(...n), $ = (...n) => m().unbindKeyCombo(...n), J = (...n) => m().checkKey(...n), Q = (...n) => m().checkKeyCombo(...n), V = y.normalizeKeyCombo, X = y.stringifyKeyCombo, Y = y.parseKeyCombo, Z = (n = {}) => {
let e, t, i, s;
const F = (a) => {
v = a ?? new P(g);
}, p = () => (v || F(), v), H = (a) => {
g = a;
}, N = (...a) => p().bindKey(...a), D = (...a) => p().unbindKey(...a), G = (...a) => p().bindKeyCombo(...a), $ = (...a) => p().unbindKeyCombo(...a), J = (...a) => p().checkKey(...a), Q = (...a) => p().checkKeyCombo(...a), V = y.normalizeKeyCombo, X = y.stringifyKeyCombo, Y = y.parseKeyCombo, Z = (a = {}) => {
let e, t, s, i;
return Object.assign(new P({
...n,
onActive(r) {
e = r;
...a,
onActive(o) {
e = o;
},
onInactive(r) {
t = r;
onInactive(o) {
t = o;
},
onKeyPressed(r) {
i = r;
onKeyPressed(o) {
s = o;
},
onKeyReleased(r) {
s = r;
onKeyReleased(o) {
i = o;
}

@@ -483,7 +493,7 @@ }), {

},
press(r) {
i({ composedPath: () => [], ...r });
press(o) {
s({ composedPath: () => [], ...o });
},
release(r) {
s({ composedPath: () => [], ...r });
release(o) {
i({ composedPath: () => [], ...o });
}

@@ -506,3 +516,3 @@ });

U as defaultSequenceTimeout,
m as getGlobalKeystrokes,
p as getGlobalKeystrokes,
V as normalizeKeyCombo,

@@ -509,0 +519,0 @@ Y as parseKeyCombo,

{
"name": "@rwh/keystrokes",
"version": "1.5.3",
"version": "1.5.4",
"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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc