Join our webinar on Wednesday, June 26, at 1pm EDTHow Chia Mitigates Risk in the Crypto Industry.Register
Socket
Socket
Sign inDemoInstall

@github/hotkey

Package Overview
Dependencies
206
Maintainers
15
Versions
40
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.3.1 to 3.0.1

dist/macos-uppercase-layer.d.ts

4

dist/hotkey.d.ts

@@ -1,4 +0,4 @@

import { NormalizedSequenceString } from './sequence';
import { NormalizedSequenceString } from './sequence.js';
declare const normalizedHotkeyBrand: unique symbol;
export declare type NormalizedHotkeyString = NormalizedSequenceString & {
export type NormalizedHotkeyString = NormalizedSequenceString & {
[normalizedHotkeyBrand]: true;

@@ -5,0 +5,0 @@ };

@@ -1,2 +0,3 @@

import { macosSymbolLayerKeys } from './macos-symbol-layer';
import { macosSymbolLayerKeys } from './macos-symbol-layer.js';
import { macosUppercaseLayerKeys } from './macos-uppercase-layer.js';
const normalizedHotkeyBrand = Symbol('normalizedHotkey');

@@ -8,6 +9,6 @@ const syntheticKeyNames = {

export function eventToHotkeyString(event, platform = navigator.platform) {
var _a, _b;
const { ctrlKey, altKey, metaKey, key } = event;
var _a, _b, _c;
const { ctrlKey, altKey, metaKey, shiftKey, key } = event;
const hotkeyString = [];
const modifiers = [ctrlKey, altKey, metaKey, showShift(event)];
const modifiers = [ctrlKey, altKey, metaKey, shiftKey];
for (const [i, mod] of modifiers.entries()) {

@@ -18,4 +19,7 @@ if (mod)

if (!modifierKeyNames.includes(key)) {
const nonOptionPlaneKey = hotkeyString.includes('Alt') && matchApplePlatform.test(platform) ? (_a = macosSymbolLayerKeys[key]) !== null && _a !== void 0 ? _a : key : key;
const syntheticKey = (_b = syntheticKeyNames[nonOptionPlaneKey]) !== null && _b !== void 0 ? _b : nonOptionPlaneKey;
const altNormalizedKey = hotkeyString.includes('Alt') && matchApplePlatform.test(platform) ? (_a = macosSymbolLayerKeys[key]) !== null && _a !== void 0 ? _a : key : key;
const shiftNormalizedKey = hotkeyString.includes('Shift') && matchApplePlatform.test(platform)
? (_b = macosUppercaseLayerKeys[altNormalizedKey]) !== null && _b !== void 0 ? _b : altNormalizedKey
: altNormalizedKey;
const syntheticKey = (_c = syntheticKeyNames[shiftNormalizedKey]) !== null && _c !== void 0 ? _c : shiftNormalizedKey;
hotkeyString.push(syntheticKey);

@@ -26,6 +30,2 @@ }

const modifierKeyNames = ['Control', 'Alt', 'Meta', 'Shift'];
function showShift(event) {
const { shiftKey, code, key } = event;
return shiftKey && !(code.startsWith('Key') && key.toUpperCase() === key);
}
export function normalizeHotkey(hotkey, platform) {

@@ -50,4 +50,5 @@ let result;

}
modifiers.push(key);
if (key)
modifiers.push(key);
return modifiers.join('+');
}

@@ -1,5 +0,5 @@

export { eventToHotkeyString, normalizeHotkey, NormalizedHotkeyString } from './hotkey';
export { SequenceTracker, normalizeSequence, NormalizedSequenceString } from './sequence';
export { RadixTrie, Leaf } from './radix-trie';
export { eventToHotkeyString, normalizeHotkey, NormalizedHotkeyString } from './hotkey.js';
export { SequenceTracker, normalizeSequence, NormalizedSequenceString } from './sequence.js';
export { RadixTrie, Leaf } from './radix-trie.js';
export declare function install(element: HTMLElement, hotkey?: string): void;
export declare function uninstall(element: HTMLElement): void;

@@ -164,2 +164,52 @@ class Leaf {

const macosUppercaseLayerKeys = {
['`']: '~',
['1']: '!',
['2']: '@',
['3']: '#',
['4']: '$',
['5']: '%',
['6']: '^',
['7']: '&',
['8']: '*',
['9']: '(',
['0']: ')',
['-']: '_',
['=']: '+',
['[']: '{',
[']']: '}',
['\\']: '|',
[';']: ':',
["'"]: '"',
[',']: '<',
['.']: '>',
['/']: '?',
['q']: 'Q',
['w']: 'W',
['e']: 'E',
['r']: 'R',
['t']: 'T',
['y']: 'Y',
['u']: 'U',
['i']: 'I',
['o']: 'O',
['p']: 'P',
['a']: 'A',
['s']: 'S',
['d']: 'D',
['f']: 'F',
['g']: 'G',
['h']: 'H',
['j']: 'J',
['k']: 'K',
['l']: 'L',
['z']: 'Z',
['x']: 'X',
['c']: 'C',
['v']: 'V',
['b']: 'B',
['n']: 'N',
['m']: 'M'
};
const syntheticKeyNames = {

@@ -170,6 +220,6 @@ ' ': 'Space',

function eventToHotkeyString(event, platform = navigator.platform) {
var _a, _b;
const { ctrlKey, altKey, metaKey, key } = event;
var _a, _b, _c;
const { ctrlKey, altKey, metaKey, shiftKey, key } = event;
const hotkeyString = [];
const modifiers = [ctrlKey, altKey, metaKey, showShift(event)];
const modifiers = [ctrlKey, altKey, metaKey, shiftKey];
for (const [i, mod] of modifiers.entries()) {

@@ -180,4 +230,7 @@ if (mod)

if (!modifierKeyNames.includes(key)) {
const nonOptionPlaneKey = hotkeyString.includes('Alt') && matchApplePlatform.test(platform) ? (_a = macosSymbolLayerKeys[key]) !== null && _a !== void 0 ? _a : key : key;
const syntheticKey = (_b = syntheticKeyNames[nonOptionPlaneKey]) !== null && _b !== void 0 ? _b : nonOptionPlaneKey;
const altNormalizedKey = hotkeyString.includes('Alt') && matchApplePlatform.test(platform) ? (_a = macosSymbolLayerKeys[key]) !== null && _a !== void 0 ? _a : key : key;
const shiftNormalizedKey = hotkeyString.includes('Shift') && matchApplePlatform.test(platform)
? (_b = macosUppercaseLayerKeys[altNormalizedKey]) !== null && _b !== void 0 ? _b : altNormalizedKey
: altNormalizedKey;
const syntheticKey = (_c = syntheticKeyNames[shiftNormalizedKey]) !== null && _c !== void 0 ? _c : shiftNormalizedKey;
hotkeyString.push(syntheticKey);

@@ -188,6 +241,2 @@ }

const modifierKeyNames = ['Control', 'Alt', 'Meta', 'Shift'];
function showShift(event) {
const { shiftKey, code, key } = event;
return shiftKey && !(code.startsWith('Key') && key.toUpperCase() === key);
}
function normalizeHotkey(hotkey, platform) {

@@ -212,3 +261,4 @@ let result;

}
modifiers.push(key);
if (key)
modifiers.push(key);
return modifiers.join('+');

@@ -215,0 +265,0 @@ }

@@ -1,2 +0,2 @@

import { NormalizedHotkeyString } from './hotkey';
import { NormalizedHotkeyString } from './hotkey.js';
interface SequenceTrackerOptions {

@@ -7,3 +7,3 @@ onReset?: () => void;

declare const sequenceBrand: unique symbol;
export declare type NormalizedSequenceString = string & {
export type NormalizedSequenceString = string & {
[sequenceBrand]: true;

@@ -10,0 +10,0 @@ };

@@ -1,2 +0,2 @@

import { eventToHotkeyString, normalizeHotkey } from './hotkey';
import { eventToHotkeyString, normalizeHotkey } from './hotkey.js';
export const SEQUENCE_DELIMITER = ' ';

@@ -3,0 +3,0 @@ const sequenceBrand = Symbol('sequence');

@@ -1,4 +0,4 @@

import { NormalizedHotkeyString } from './hotkey';
import { NormalizedHotkeyString } from './hotkey.js';
export declare function isFormField(element: Node): boolean;
export declare function fireDeterminedAction(el: HTMLElement, path: readonly NormalizedHotkeyString[]): void;
export declare function expandHotkeyToEdges(hotkey: string): NormalizedHotkeyString[][];

@@ -1,3 +0,3 @@

import { normalizeHotkey } from './hotkey';
import { SEQUENCE_DELIMITER } from './sequence';
import { normalizeHotkey } from './hotkey.js';
import { SEQUENCE_DELIMITER } from './sequence.js';
export function isFormField(element) {

@@ -4,0 +4,0 @@ if (!(element instanceof HTMLElement)) {

{
"name": "@github/hotkey",
"version": "2.3.1",
"version": "3.0.1",
"description": "",

@@ -15,5 +15,5 @@ "main": "dist/index.js",

"clean": "rm -rf dist",
"prebuild": "npm run clean && npm run lint && mkdir dist",
"pretest": "npm run build",
"prepublishOnly": "npm run build",
"prebuild": "npm run clean && mkdir dist",
"pretest": "npm run build && npm run lint",
"prepublishOnly": "npm run test",
"buildSite": "npm run build && mkdir -p pages/hotkey && cp -r dist/* pages/hotkey"

@@ -30,18 +30,21 @@ },

"@github/prettier-config": "0.0.4",
"chai": "^4.2.0",
"chai": "^4.3.10",
"chromium": "^3.0.3",
"eslint": "^7.22.0",
"eslint-plugin-github": "^4.0.0",
"karma": "^6.2.0",
"eslint": "^8.52.0",
"eslint-plugin-github": "^4.10.1",
"karma": "^6.4.2",
"karma-chai": "^0.1.0",
"karma-chrome-launcher": "^3.1.0",
"karma-chrome-launcher": "^3.2.0",
"karma-mocha": "^2.0.1",
"karma-mocha-reporter": "^2.2.3",
"karma-mocha-reporter": "^2.2.5",
"mocha": "^10.2.0",
"rollup": "^2.4.0",
"typescript": "^4.2.3"
"rollup": "^4.1.4",
"typescript": "^5.2.2"
},
"eslintIgnore": [
"dist/"
]
],
"dependencies": {
"eslint-import-resolver-typescript": "^3.6.1"
}
}

@@ -111,5 +111,6 @@ # Hotkey Behavior

2. Neither the `Control` or `Meta` modifiers should appear in a hotkey string with `Mod`.
3. Due to the inconsistent lowercasing of `event.key` on Mac and iOS when `Meta` is pressed along with `Shift`, it is recommended to avoid hotkey strings containing both `Mod` and `Shift`.
7. `"Plus"` and `"Space"` are special key names to represent the `+` and ` ` keys respectively, because these symbols cannot be represented in the normal hotkey string syntax.
8. You can use the comma key `,` as a hotkey, e.g. `a,,` would activate if the user typed `a` or `,`. `Control+,,x` would activate for `Control+,` or `x`.
9. `"Shift"` should be included if it would be held and the key is uppercase: ie, `Shift+A` not `A`
1. MacOS outputs lowercase key names when `Meta+Shift` is held (ie, `Meta+Shift+a`). In an attempt to normalize this, `hotkey` will automatically map these key names to uppercase, so the uppercase keys should still be used (ie, `"Meta+Shift+A"` or `"Mod+Shift+A"`). **However**, this normalization only works on US keyboard layouts.

@@ -122,3 +123,2 @@ ### Example

'a b,Control+Alt+/'
```

@@ -125,0 +125,0 @@

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc