@rowsncolumns/utils 9.2.38 → 9.2.39

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -21,4 +21,5 @@ export * from "./conditional-format";
21
21
  export * from "./data-validation";
22
22
  export * from "./content-hash";
23
23
  export * from "./shared-string-canonical";
24
+ export * from "./keyboard";
24
25
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,QAAQ,CAAC;AACvB,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC;AACxB,cAAc,OAAO,CAAC;AACtB,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC;AACvB,cAAc,OAAO,CAAC;AACtB,cAAc,SAAS,CAAC;AACxB,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,qBAAqB,CAAC;AACpC,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC;AACzB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,QAAQ,CAAC;AACvB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,sBAAsB,CAAC;AACrC,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,2BAA2B,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,QAAQ,CAAC;AACvB,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC;AACxB,cAAc,OAAO,CAAC;AACtB,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC;AACvB,cAAc,OAAO,CAAC;AACtB,cAAc,SAAS,CAAC;AACxB,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,qBAAqB,CAAC;AACpC,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC;AACzB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,QAAQ,CAAC;AACvB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,sBAAsB,CAAC;AACrC,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,2BAA2B,CAAC;AAC1C,cAAc,YAAY,CAAC"}
package/dist/cjs/index.js CHANGED
@@ -24,3 +24,4 @@ tslib_1.__exportStar(require("./conditional-format"), exports);
24
24
  tslib_1.__exportStar(require("./data-validation"), exports);
25
25
  tslib_1.__exportStar(require("./content-hash"), exports);
26
26
  tslib_1.__exportStar(require("./shared-string-canonical"), exports);
27
+ tslib_1.__exportStar(require("./keyboard"), exports);
@@ -0,0 +1,28 @@
1
+ type HotkeyEventLike = {
2
+ key: string;
3
+ code?: string;
4
+ };
5
+ /**
6
+ * Map a physical key code (`KeyboardEvent.code`) to the character that key
7
+ * produces on a US layout: `KeyB` → `b`, `Digit1` → `1`, `Semicolon` → `;`.
8
+ * Returns undefined for codes that are not a letter, digit or punctuation key.
9
+ * @param code
10
+ * @returns
11
+ */
12
+ export declare const hotkeyKeyFromCode: (code: string | undefined) => string | undefined;
13
+ /**
14
+ * Layout-independent key to match keyboard shortcuts against.
15
+ *
16
+ * - A printable ASCII `event.key` wins, lowercased, so Dvorak/AZERTY users
17
+ * keep the shortcut printed on their keys (Excel / Google Sheets parity)
18
+ * and Shift no longer changes the letter (`Ctrl+Shift+X` → `x`).
19
+ * - When the layout produces a non-ASCII character (Cyrillic `и`, Greek `β`,
20
+ * Hebrew, or a macOS Option dead character such as `†`), the character is
21
+ * derived from the physical key instead: `event.code` `KeyB` → `b`.
22
+ * - Named keys (`Enter`, `Escape`, `F4`, `ArrowUp`, …) are returned as-is.
23
+ * @param event
24
+ * @returns
25
+ */
26
+ export declare const getHotkeyKey: (event: HotkeyEventLike) => string;
27
+ export {};
28
+ //# sourceMappingURL=keyboard.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"keyboard.d.ts","sourceRoot":"","sources":["../../keyboard.ts"],"names":[],"mappings":"AAAA,KAAK,eAAe,GAAG;IACrB,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,CAAC;AAqBF;;;;;;GAMG;AACH,eAAO,MAAM,iBAAiB,GAAI,MAAM,MAAM,GAAG,SAAS,uBAWzD,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,YAAY,GAAI,OAAO,eAAe,WAYlD,CAAC"}
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getHotkeyKey = exports.hotkeyKeyFromCode = void 0;
4
+ var PUNCTUATION_BY_CODE = {
5
+ Backquote: "`",
6
+ Backslash: "\\",
7
+ BracketLeft: "[",
8
+ BracketRight: "]",
9
+ Comma: ",",
10
+ Equal: "=",
11
+ Minus: "-",
12
+ Period: ".",
13
+ Quote: "'",
14
+ Semicolon: ";",
15
+ Slash: "/",
16
+ };
17
+ var isPrintableAscii = function (key) {
18
+ var charCode = key.charCodeAt(0);
19
+ return charCode >= 0x20 && charCode <= 0x7e;
20
+ };
21
+ /**
22
+ * Map a physical key code (`KeyboardEvent.code`) to the character that key
23
+ * produces on a US layout: `KeyB` → `b`, `Digit1` → `1`, `Semicolon` → `;`.
24
+ * Returns undefined for codes that are not a letter, digit or punctuation key.
25
+ * @param code
26
+ * @returns
27
+ */
28
+ var hotkeyKeyFromCode = function (code) {
29
+ if (!code) {
30
+ return undefined;
31
+ }
32
+ if (/^Key[A-Z]$/.test(code)) {
33
+ return code.charAt(3).toLowerCase();
34
+ }
35
+ if (/^Digit[0-9]$/.test(code)) {
36
+ return code.charAt(5);
37
+ }
38
+ return PUNCTUATION_BY_CODE[code];
39
+ };
40
+ exports.hotkeyKeyFromCode = hotkeyKeyFromCode;
41
+ /**
42
+ * Layout-independent key to match keyboard shortcuts against.
43
+ *
44
+ * - A printable ASCII `event.key` wins, lowercased, so Dvorak/AZERTY users
45
+ * keep the shortcut printed on their keys (Excel / Google Sheets parity)
46
+ * and Shift no longer changes the letter (`Ctrl+Shift+X` → `x`).
47
+ * - When the layout produces a non-ASCII character (Cyrillic `и`, Greek `β`,
48
+ * Hebrew, or a macOS Option dead character such as `†`), the character is
49
+ * derived from the physical key instead: `event.code` `KeyB` → `b`.
50
+ * - Named keys (`Enter`, `Escape`, `F4`, `ArrowUp`, …) are returned as-is.
51
+ * @param event
52
+ * @returns
53
+ */
54
+ var getHotkeyKey = function (event) {
55
+ var key = event.key, code = event.code;
56
+ if (key.length === 1) {
57
+ if (isPrintableAscii(key)) {
58
+ return key.toLowerCase();
59
+ }
60
+ var keyFromCode = (0, exports.hotkeyKeyFromCode)(code);
61
+ if (keyFromCode !== undefined) {
62
+ return keyFromCode;
63
+ }
64
+ }
65
+ return key;
66
+ };
67
+ exports.getHotkeyKey = getHotkeyKey;
@@ -1 +1 @@
1
- {"root":["../../array.ts","../../cell-data-helpers.ts","../../color.ts","../../colors.ts","../../conditional-format.ts","../../content-hash.ts","../../data-validation.ts","../../date.ts","../../dom.ts","../../formatter.ts","../../formula-refs.ts","../../formula.ts","../../index.ts","../../locale.ts","../../log.ts","../../memoize.ts","../../numbers.ts","../../selection.ts","../../shared-string-canonical.ts","../../sort.ts","../../string.ts","../../table-styles.ts","../../typeguards.ts","../../uuid.ts","../../vitest.config.ts"],"version":"5.8.3"}
1
+ {"root":["../../array.ts","../../cell-data-helpers.ts","../../color.ts","../../colors.ts","../../conditional-format.ts","../../content-hash.ts","../../data-validation.ts","../../date.ts","../../dom.ts","../../formatter.ts","../../formula-refs.ts","../../formula.ts","../../index.ts","../../keyboard.ts","../../locale.ts","../../log.ts","../../memoize.ts","../../numbers.ts","../../selection.ts","../../shared-string-canonical.ts","../../sort.ts","../../string.ts","../../table-styles.ts","../../typeguards.ts","../../uuid.ts","../../vitest.config.ts"],"version":"5.8.3"}
@@ -21,4 +21,5 @@ export * from "./conditional-format";
21
21
  export * from "./data-validation";
22
22
  export * from "./content-hash";
23
23
  export * from "./shared-string-canonical";
24
+ export * from "./keyboard";
24
25
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,QAAQ,CAAC;AACvB,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC;AACxB,cAAc,OAAO,CAAC;AACtB,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC;AACvB,cAAc,OAAO,CAAC;AACtB,cAAc,SAAS,CAAC;AACxB,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,qBAAqB,CAAC;AACpC,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC;AACzB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,QAAQ,CAAC;AACvB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,sBAAsB,CAAC;AACrC,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,2BAA2B,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,QAAQ,CAAC;AACvB,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC;AACxB,cAAc,OAAO,CAAC;AACtB,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC;AACvB,cAAc,OAAO,CAAC;AACtB,cAAc,SAAS,CAAC;AACxB,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,qBAAqB,CAAC;AACpC,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC;AACzB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,QAAQ,CAAC;AACvB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,sBAAsB,CAAC;AACrC,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,2BAA2B,CAAC;AAC1C,cAAc,YAAY,CAAC"}
package/dist/esm/index.js CHANGED
@@ -21,3 +21,4 @@ export * from "./conditional-format";
21
21
  export * from "./data-validation";
22
22
  export * from "./content-hash";
23
23
  export * from "./shared-string-canonical";
24
+ export * from "./keyboard";
@@ -0,0 +1,28 @@
1
+ type HotkeyEventLike = {
2
+ key: string;
3
+ code?: string;
4
+ };
5
+ /**
6
+ * Map a physical key code (`KeyboardEvent.code`) to the character that key
7
+ * produces on a US layout: `KeyB` → `b`, `Digit1` → `1`, `Semicolon` → `;`.
8
+ * Returns undefined for codes that are not a letter, digit or punctuation key.
9
+ * @param code
10
+ * @returns
11
+ */
12
+ export declare const hotkeyKeyFromCode: (code: string | undefined) => string | undefined;
13
+ /**
14
+ * Layout-independent key to match keyboard shortcuts against.
15
+ *
16
+ * - A printable ASCII `event.key` wins, lowercased, so Dvorak/AZERTY users
17
+ * keep the shortcut printed on their keys (Excel / Google Sheets parity)
18
+ * and Shift no longer changes the letter (`Ctrl+Shift+X` → `x`).
19
+ * - When the layout produces a non-ASCII character (Cyrillic `и`, Greek `β`,
20
+ * Hebrew, or a macOS Option dead character such as `†`), the character is
21
+ * derived from the physical key instead: `event.code` `KeyB` → `b`.
22
+ * - Named keys (`Enter`, `Escape`, `F4`, `ArrowUp`, …) are returned as-is.
23
+ * @param event
24
+ * @returns
25
+ */
26
+ export declare const getHotkeyKey: (event: HotkeyEventLike) => string;
27
+ export {};
28
+ //# sourceMappingURL=keyboard.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"keyboard.d.ts","sourceRoot":"","sources":["../../keyboard.ts"],"names":[],"mappings":"AAAA,KAAK,eAAe,GAAG;IACrB,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,CAAC;AAqBF;;;;;;GAMG;AACH,eAAO,MAAM,iBAAiB,GAAI,MAAM,MAAM,GAAG,SAAS,uBAWzD,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,YAAY,GAAI,OAAO,eAAe,WAYlD,CAAC"}
@@ -0,0 +1,62 @@
1
+ const PUNCTUATION_BY_CODE = {
2
+ Backquote: "`",
3
+ Backslash: "\\",
4
+ BracketLeft: "[",
5
+ BracketRight: "]",
6
+ Comma: ",",
7
+ Equal: "=",
8
+ Minus: "-",
9
+ Period: ".",
10
+ Quote: "'",
11
+ Semicolon: ";",
12
+ Slash: "/",
13
+ };
14
+ const isPrintableAscii = (key) => {
15
+ const charCode = key.charCodeAt(0);
16
+ return charCode >= 0x20 && charCode <= 0x7e;
17
+ };
18
+ /**
19
+ * Map a physical key code (`KeyboardEvent.code`) to the character that key
20
+ * produces on a US layout: `KeyB` → `b`, `Digit1` → `1`, `Semicolon` → `;`.
21
+ * Returns undefined for codes that are not a letter, digit or punctuation key.
22
+ * @param code
23
+ * @returns
24
+ */
25
+ export const hotkeyKeyFromCode = (code) => {
26
+ if (!code) {
27
+ return undefined;
28
+ }
29
+ if (/^Key[A-Z]$/.test(code)) {
30
+ return code.charAt(3).toLowerCase();
31
+ }
32
+ if (/^Digit[0-9]$/.test(code)) {
33
+ return code.charAt(5);
34
+ }
35
+ return PUNCTUATION_BY_CODE[code];
36
+ };
37
+ /**
38
+ * Layout-independent key to match keyboard shortcuts against.
39
+ *
40
+ * - A printable ASCII `event.key` wins, lowercased, so Dvorak/AZERTY users
41
+ * keep the shortcut printed on their keys (Excel / Google Sheets parity)
42
+ * and Shift no longer changes the letter (`Ctrl+Shift+X` → `x`).
43
+ * - When the layout produces a non-ASCII character (Cyrillic `и`, Greek `β`,
44
+ * Hebrew, or a macOS Option dead character such as `†`), the character is
45
+ * derived from the physical key instead: `event.code` `KeyB` → `b`.
46
+ * - Named keys (`Enter`, `Escape`, `F4`, `ArrowUp`, …) are returned as-is.
47
+ * @param event
48
+ * @returns
49
+ */
50
+ export const getHotkeyKey = (event) => {
51
+ const { key, code } = event;
52
+ if (key.length === 1) {
53
+ if (isPrintableAscii(key)) {
54
+ return key.toLowerCase();
55
+ }
56
+ const keyFromCode = hotkeyKeyFromCode(code);
57
+ if (keyFromCode !== undefined) {
58
+ return keyFromCode;
59
+ }
60
+ }
61
+ return key;
62
+ };
@@ -1 +1 @@
1
- {"root":["../../array.ts","../../cell-data-helpers.ts","../../color.ts","../../colors.ts","../../conditional-format.ts","../../content-hash.ts","../../data-validation.ts","../../date.ts","../../dom.ts","../../formatter.ts","../../formula-refs.ts","../../formula.ts","../../index.ts","../../locale.ts","../../log.ts","../../memoize.ts","../../numbers.ts","../../selection.ts","../../shared-string-canonical.ts","../../sort.ts","../../string.ts","../../table-styles.ts","../../typeguards.ts","../../uuid.ts","../../vitest.config.ts"],"version":"5.8.3"}
1
+ {"root":["../../array.ts","../../cell-data-helpers.ts","../../color.ts","../../colors.ts","../../conditional-format.ts","../../content-hash.ts","../../data-validation.ts","../../date.ts","../../dom.ts","../../formatter.ts","../../formula-refs.ts","../../formula.ts","../../index.ts","../../keyboard.ts","../../locale.ts","../../log.ts","../../memoize.ts","../../numbers.ts","../../selection.ts","../../shared-string-canonical.ts","../../sort.ts","../../string.ts","../../table-styles.ts","../../typeguards.ts","../../uuid.ts","../../vitest.config.ts"],"version":"5.8.3"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rowsncolumns/utils",
3
- "version": "9.2.38",
3
+ "version": "9.2.39",
4
4
  "author": "Vinay M",
5
5
  "license": "SEE LICENSE IN LICENSE.md",
6
6
  "main": "./dist/cjs/index.js",