@baleada/logic 0.23.3 → 0.23.4

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.
package/lib/index.cjs CHANGED
@@ -13,6 +13,202 @@ var dequal = require('dequal');
13
13
  var slugify = require('@sindresorhus/slugify');
14
14
  var clsx = require('clsx');
15
15
 
16
+ function fromComboToAliases(combo) {
17
+ const delimiter = "+";
18
+ return lazyCollections.pipe(
19
+ lazyCollections.unique(),
20
+ lazyCollections.map((name) => name === "" ? delimiter : name.toLowerCase()),
21
+ lazyCollections.toArray()
22
+ )(combo.split(delimiter));
23
+ }
24
+
25
+ function fromAliasToDownKeys(alias) {
26
+ if (alias in keysByAlias) {
27
+ return [{ key: keysByAlias[alias] }];
28
+ }
29
+ if (alias in keyStatusKeysByAlias)
30
+ return keyStatusKeysByAlias[alias];
31
+ return [{
32
+ code: (() => {
33
+ if (letterRE.test(alias))
34
+ return `Key${alias.toUpperCase()}`;
35
+ if (digitRE.test(alias))
36
+ return `Digit${alias}`;
37
+ if (functionRE.test(alias))
38
+ return alias.toUpperCase();
39
+ return "unsupported";
40
+ })()
41
+ }];
42
+ }
43
+ const digitRE = /^[0-9]$/;
44
+ const letterRE = /^[a-zA-Z]$/;
45
+ const functionRE = /^[fF][0-9]{1,2}$/;
46
+ const keyStatusKeysByAlias = {
47
+ "`": [{ code: "Backquote" }],
48
+ "~": [{ code: "Backquote" }, { key: "Shift" }],
49
+ "-": [{ code: "Minus" }],
50
+ _: [{ code: "Minus" }, { key: "Shift" }],
51
+ "=": [{ code: "Equal" }],
52
+ "+": [{ code: "Equal" }, { key: "Shift" }],
53
+ "[": [{ code: "BracketLeft" }],
54
+ "{": [{ code: "BracketLeft" }, { key: "Shift" }],
55
+ "]": [{ code: "BracketRight" }],
56
+ "}": [{ code: "BracketRight" }, { key: "Shift" }],
57
+ "\\": [{ code: "Backslash" }],
58
+ "|": [{ code: "Backslash" }, { key: "Shift" }],
59
+ ";": [{ code: "Semicolon" }],
60
+ ":": [{ code: "Semicolon" }, { key: "Shift" }],
61
+ "'": [{ code: "Quote" }],
62
+ '"': [{ code: "Quote" }, { key: "Shift" }],
63
+ ",": [{ code: "Comma" }],
64
+ "<": [{ code: "Comma" }, { key: "Shift" }],
65
+ ".": [{ code: "Period" }],
66
+ ">": [{ code: "Period" }, { key: "Shift" }],
67
+ "/": [{ code: "Slash" }],
68
+ "?": [{ code: "Slash" }, { key: "Shift" }],
69
+ "!": [{ code: "Digit1" }, { key: "Shift" }],
70
+ "@": [{ code: "Digit2" }, { key: "Shift" }],
71
+ "#": [{ code: "Digit3" }, { key: "Shift" }],
72
+ $: [{ code: "Digit4" }, { key: "Shift" }],
73
+ "%": [{ code: "Digit5" }, { key: "Shift" }],
74
+ "^": [{ code: "Digit6" }, { key: "Shift" }],
75
+ "&": [{ code: "Digit7" }, { key: "Shift" }],
76
+ "*": [{ code: "Digit8" }, { key: "Shift" }],
77
+ "(": [{ code: "Digit9" }, { key: "Shift" }],
78
+ ")": [{ code: "Digit0" }, { key: "Shift" }],
79
+ up: [{ code: "ArrowUp" }],
80
+ down: [{ code: "ArrowDown" }],
81
+ left: [{ code: "ArrowLeft" }],
82
+ right: [{ code: "ArrowRight" }],
83
+ enter: [{ code: "Enter" }],
84
+ space: [{ code: "Space" }],
85
+ tab: [{ code: "Tab" }],
86
+ esc: [{ code: "Escape" }],
87
+ backspace: [{ code: "Backspace" }],
88
+ delete: [{ code: "Delete" }],
89
+ home: [{ code: "Home" }],
90
+ end: [{ code: "End" }],
91
+ pagedown: [{ code: "PageDown" }],
92
+ pageup: [{ code: "PageUp" }],
93
+ capslock: [{ code: "CapsLock" }],
94
+ camera: [{ code: "Camera" }]
95
+ };
96
+ const keysByAlias = {
97
+ alt: "Alt",
98
+ opt: "Alt",
99
+ option: "Alt",
100
+ ctrl: "Control",
101
+ control: "Control",
102
+ meta: "Meta",
103
+ cmd: "Meta",
104
+ command: "Meta",
105
+ shift: "Shift"
106
+ };
107
+
108
+ const defaultOptions$m = {
109
+ toDownKeys: (alias) => fromAliasToDownKeys(alias)
110
+ };
111
+ const createPredicateKeycomboDown = (keycombo, options = {}) => {
112
+ const { toDownKeys } = { ...defaultOptions$m, ...options }, downKeys = lazyCollections.pipe(
113
+ fromComboToAliases,
114
+ lazyCollections.map(toDownKeys)
115
+ )(keycombo);
116
+ return (statuses) => {
117
+ const predicateAliasEntriesDown = lazyCollections.every(
118
+ (key) => statuses.toValue(key) === "down"
119
+ );
120
+ return lazyCollections.every(predicateAliasEntriesDown)(downKeys);
121
+ };
122
+ };
123
+
124
+ function fromEventToAliases(event) {
125
+ if (event.shiftKey && event.code in aliasesByShiftCode) {
126
+ return [aliasesByShiftCode[event.code]];
127
+ }
128
+ if (event.key in aliasListsByModifier) {
129
+ return aliasListsByModifier[event.key];
130
+ }
131
+ return event.code in aliasesByCode ? [aliasesByCode[event.code]] : [event.code.match(aliasCaptureRE)?.[1].toLowerCase() || "unsupported"];
132
+ }
133
+ const aliasCaptureRE = /^(?:Digit|Key)?(F[0-9]{1,2}|[0-9]|[A-Z])$/;
134
+ const aliasesByCode = {
135
+ Backquote: "`",
136
+ Minus: "-",
137
+ Equal: "=",
138
+ BracketLeft: "[",
139
+ BracketRight: "]",
140
+ Backslash: "\\",
141
+ Semicolon: ";",
142
+ Quote: "'",
143
+ Comma: ",",
144
+ Period: ".",
145
+ Slash: "/",
146
+ ArrowUp: "up",
147
+ ArrowDown: "down",
148
+ ArrowLeft: "left",
149
+ ArrowRight: "right",
150
+ Enter: "enter",
151
+ Space: "space",
152
+ Tab: "tab",
153
+ Escape: "esc",
154
+ Backspace: "backspace",
155
+ Delete: "delete",
156
+ Home: "home",
157
+ End: "end",
158
+ PageDown: "pagedown",
159
+ PageUp: "pageup",
160
+ CapsLock: "capslock",
161
+ Camera: "camera"
162
+ };
163
+ const aliasesByShiftCode = {
164
+ Backquote: "~",
165
+ Minus: "_",
166
+ Equal: "+",
167
+ BracketLeft: "{",
168
+ BracketRight: "}",
169
+ Backslash: "|",
170
+ Semicolon: ":",
171
+ Quote: '"',
172
+ Comma: "<",
173
+ Period: ">",
174
+ Slash: "?",
175
+ Digit1: "!",
176
+ Digit2: "@",
177
+ Digit3: "#",
178
+ Digit4: "$",
179
+ Digit5: "%",
180
+ Digit6: "^",
181
+ Digit7: "&",
182
+ Digit8: "*",
183
+ Digit9: "(",
184
+ Digit0: ")"
185
+ };
186
+ const aliasListsByModifier = {
187
+ Alt: ["alt", "option", "opt"],
188
+ Control: ["control", "ctrl"],
189
+ Meta: ["meta", "command", "cmd"],
190
+ Shift: ["shift"]
191
+ };
192
+
193
+ const defaultOptions$l = {
194
+ toDownKeys: (alias) => fromAliasToDownKeys(alias),
195
+ toAliases: (event) => fromEventToAliases(event)
196
+ };
197
+ const createPredicateKeycomboMatch$1 = (keycombo, options = {}) => {
198
+ const { toDownKeys, toAliases } = { ...defaultOptions$l, ...options }, aliases = fromComboToAliases(keycombo), downKeys = lazyCollections.map(toDownKeys)(aliases);
199
+ return (statuses) => {
200
+ const predicateAliasDown = lazyCollections.every(
201
+ (key) => statuses.toValue(key) === "down"
202
+ );
203
+ return lazyCollections.every(predicateAliasDown)(downKeys) && lazyCollections.every(
204
+ ([key, value]) => value === "up" || lazyCollections.pipe(
205
+ toAliases,
206
+ lazyCollections.some((alias) => lazyCollections.includes(alias)(aliases))
207
+ )(key)
208
+ )(statuses.toEntries());
209
+ };
210
+ };
211
+
16
212
  function createClone() {
17
213
  return (any) => {
18
214
  return klona.klona(any);
@@ -280,7 +476,7 @@ function createRename(from, to) {
280
476
  };
281
477
  }
282
478
 
283
- const defaultOptions$m = {
479
+ const defaultOptions$k = {
284
480
  elementIsCandidate: false,
285
481
  // Adapted from React Aria https://github.com/adobe/react-spectrum/blob/b6786da906973130a1746b2bee63215bba013ca4/packages/%40react-aria/focus/src/FocusScope.tsx#L256
286
482
  tabbableSelector: lazyCollections.join(':not([hidden]):not([tabindex="-1"]),')([
@@ -301,7 +497,7 @@ const defaultOptions$m = {
301
497
  ])
302
498
  };
303
499
  function createFocusable(order, options = {}) {
304
- const { elementIsCandidate, tabbableSelector } = { ...defaultOptions$m, ...options }, predicateFocusable = (element) => element.matches(tabbableSelector);
500
+ const { elementIsCandidate, tabbableSelector } = { ...defaultOptions$k, ...options }, predicateFocusable = (element) => element.matches(tabbableSelector);
305
501
  return (element) => {
306
502
  if (elementIsCandidate && predicateFocusable(element))
307
503
  return element;
@@ -736,12 +932,12 @@ function createList() {
736
932
  return (...classValues) => clsx(...classValues);
737
933
  }
738
934
 
739
- const defaultOptions$l = {
935
+ const defaultOptions$j = {
740
936
  toId: (node) => node.id,
741
937
  toChildren: (node) => node.children
742
938
  };
743
939
  function createToGraph(options = {}) {
744
- const { toId, toChildren } = { ...defaultOptions$l, ...options };
940
+ const { toId, toChildren } = { ...defaultOptions$j, ...options };
745
941
  return function* (tree) {
746
942
  const root = tree[0], rootId = toId(root);
747
943
  function* toPair(node, id) {
@@ -760,36 +956,56 @@ function createToGraph(options = {}) {
760
956
  };
761
957
  }
762
958
 
763
- const defaultOptions$k = {
764
- toKey: (alias) => fromAliasToKeyStatusKey(alias),
959
+ const defaultOptions$i = {
960
+ toDownKeys: (alias) => fromAliasToDownKeys(alias),
765
961
  toAliases: (event) => fromEventToAliases(event)
766
962
  };
767
- const createPredicateKeycomboMatch$1 = (keycombo, options = {}) => {
768
- const { toKey, toAliases } = { ...defaultOptions$k, ...options }, aliases = fromComboToAliases(keycombo), keys = lazyCollections.map(toKey)(aliases);
963
+ const createPredicateKeycomboMatch = (keycombo, options = {}) => {
964
+ const { toDownKeys, toAliases } = { ...defaultOptions$i, ...options }, aliases = fromComboToAliases(keycombo), downKeys = createMap(toDownKeys)(aliases), implicitModifierAliases = (() => {
965
+ const implicitModifierAliases2 = [];
966
+ for (const aliasDownKeys of downKeys) {
967
+ for (const { key } of aliasDownKeys) {
968
+ if (lazyCollections.includes(key)(modifiers))
969
+ implicitModifierAliases2.push(key.toLowerCase());
970
+ }
971
+ }
972
+ return implicitModifierAliases2;
973
+ })();
769
974
  return (event) => {
770
- const { toValue, set, toEntries } = createKeyStatuses();
771
- set(fromEventToKeyStatusKey(event), "down");
975
+ const statuses = createKeyStatuses(), predicateAliasDown = lazyCollections.every(
976
+ (key) => statuses.toValue(key) === "down"
977
+ );
978
+ statuses.set(fromEventToKeyStatusKey(event), "down");
772
979
  for (const modifier of modifiers) {
773
980
  if (event[`${modifier.toLowerCase()}Key`])
774
- set({ key: modifier }, "down");
775
- }
776
- return lazyCollections.every(lazyCollections.pipe(
777
- toValue,
778
- predicateDown
779
- ))(keys) && lazyCollections.every(
780
- ([key]) => lazyCollections.some(
781
- (alias) => lazyCollections.includes(alias)(aliases)
782
- )(toAliases(key))
783
- )(toEntries());
981
+ statuses.set({ key: modifier }, "down");
982
+ }
983
+ const events = createMap(
984
+ ([key]) => {
985
+ const e = { ...key };
986
+ for (const modifier of modifiers) {
987
+ e[`${modifier.toLowerCase()}Key`] = event[`${modifier.toLowerCase()}Key`];
988
+ }
989
+ return e;
990
+ }
991
+ )(statuses.toEntries());
992
+ return lazyCollections.every(predicateAliasDown)(downKeys) && lazyCollections.every(
993
+ (e) => lazyCollections.pipe(
994
+ toAliases,
995
+ lazyCollections.some(
996
+ (alias) => lazyCollections.includes(alias)(aliases) || lazyCollections.includes(alias)(implicitModifierAliases)
997
+ )
998
+ )(e)
999
+ )(events);
784
1000
  };
785
1001
  };
786
1002
 
787
- const defaultOptions$j = {
1003
+ const defaultOptions$h = {
788
1004
  initial: [],
789
1005
  createPredicateKey: (query) => (candidate) => query === candidate
790
1006
  };
791
1007
  function createAssociativeArray(options = {}) {
792
- const { initial, createPredicateKey } = { ...defaultOptions$j, ...options }, entries = [...initial];
1008
+ const { initial, createPredicateKey } = { ...defaultOptions$h, ...options }, entries = [...initial];
793
1009
  const toValue = (key) => {
794
1010
  const predicateKey = createPredicateKey(key);
795
1011
  return lazyCollections.find(
@@ -850,22 +1066,22 @@ function createAssociativeArray(options = {}) {
850
1066
  };
851
1067
  }
852
1068
 
853
- const defaultOptions$i = {
1069
+ const defaultOptions$g = {
854
1070
  minDuration: 0,
855
1071
  preventsDefaultUnlessDenied: true,
856
- toKey: (alias) => fromAliasToKeyStatusKey(alias),
1072
+ toDownKeys: (alias) => fromAliasToDownKeys(alias),
857
1073
  toAliases: (event) => fromEventToAliases(event)
858
1074
  };
859
1075
  function createKeypress(keycomboOrKeycombos, options = {}) {
860
1076
  const {
861
1077
  minDuration,
862
1078
  preventsDefaultUnlessDenied,
863
- toKey,
1079
+ toDownKeys,
864
1080
  toAliases,
865
1081
  onDown,
866
1082
  onUp,
867
1083
  onVisibilitychange
868
- } = { ...defaultOptions$i, ...options }, {
1084
+ } = { ...defaultOptions$g, ...options }, {
869
1085
  matchPredicatesByKeycombo,
870
1086
  getDownCombos,
871
1087
  predicateValid,
@@ -874,7 +1090,7 @@ function createKeypress(keycomboOrKeycombos, options = {}) {
874
1090
  } = createKeyState({
875
1091
  keycomboOrKeycombos,
876
1092
  unsupportedAliases: unsupportedAliases$2,
877
- toKey,
1093
+ toDownKeys,
878
1094
  toAliases,
879
1095
  getRequest: () => request
880
1096
  });
@@ -973,22 +1189,22 @@ function createKeypress(keycomboOrKeycombos, options = {}) {
973
1189
  const unsupportedAliases$2 = ["meta", "command", "cmd"];
974
1190
  const unsupportedKeys$2 = ["Meta"];
975
1191
 
976
- const defaultOptions$h = {
1192
+ const defaultOptions$f = {
977
1193
  minDuration: 0,
978
1194
  preventsDefaultUnlessDenied: true,
979
- toKey: (alias) => fromAliasToKeyStatusKey(alias),
1195
+ toDownKeys: (alias) => fromAliasToDownKeys(alias),
980
1196
  toAliases: (event) => fromEventToAliases(event)
981
1197
  };
982
1198
  function createKeyrelease(keycomboOrKeycombos, options = {}) {
983
1199
  const {
984
1200
  minDuration,
985
1201
  preventsDefaultUnlessDenied,
986
- toKey,
1202
+ toDownKeys,
987
1203
  toAliases,
988
1204
  onDown,
989
1205
  onUp,
990
1206
  onVisibilitychange
991
- } = { ...defaultOptions$h, ...options }, {
1207
+ } = { ...defaultOptions$f, ...options }, {
992
1208
  matchPredicatesByKeycombo,
993
1209
  getDownCombos,
994
1210
  predicateValid,
@@ -997,7 +1213,7 @@ function createKeyrelease(keycomboOrKeycombos, options = {}) {
997
1213
  } = createKeyState({
998
1214
  keycomboOrKeycombos,
999
1215
  unsupportedAliases: unsupportedAliases$1,
1000
- toKey,
1216
+ toDownKeys,
1001
1217
  toAliases,
1002
1218
  getRequest: () => request
1003
1219
  });
@@ -1099,12 +1315,12 @@ function createKeyrelease(keycomboOrKeycombos, options = {}) {
1099
1315
  const unsupportedAliases$1 = ["meta", "command", "cmd"];
1100
1316
  const unsupportedKeys$1 = ["Meta"];
1101
1317
 
1102
- const defaultOptions$g = {
1318
+ const defaultOptions$e = {
1103
1319
  minDuration: 0,
1104
1320
  maxInterval: 5e3,
1105
1321
  // VS Code default
1106
1322
  preventsDefaultUnlessDenied: true,
1107
- toKey: (alias) => fromAliasToKeyStatusKey(alias),
1323
+ toDownKeys: (alias) => fromAliasToDownKeys(alias),
1108
1324
  toAliases: (event) => fromEventToAliases(event)
1109
1325
  };
1110
1326
  function createKeychord(keychord, options = {}) {
@@ -1112,15 +1328,15 @@ function createKeychord(keychord, options = {}) {
1112
1328
  minDuration,
1113
1329
  maxInterval,
1114
1330
  preventsDefaultUnlessDenied,
1115
- toKey,
1331
+ toDownKeys,
1116
1332
  toAliases,
1117
1333
  onDown,
1118
1334
  onUp,
1119
1335
  onVisibilitychange
1120
- } = { ...defaultOptions$g, ...options }, narrowedKeychord = keychord.split(" "), keyStates = createMap((keycombo) => createKeyState({
1336
+ } = { ...defaultOptions$e, ...options }, narrowedKeychord = keychord.split(" "), keyStates = createMap((keycombo) => createKeyState({
1121
1337
  keycomboOrKeycombos: keycombo,
1122
1338
  unsupportedAliases,
1123
- toKey,
1339
+ toDownKeys,
1124
1340
  toAliases,
1125
1341
  getRequest: () => request
1126
1342
  }))(narrowedKeychord), localStatuses = createMap(
@@ -1265,7 +1481,7 @@ function createKonami(options = {}) {
1265
1481
  return createKeychord("up up down down left right left right b a enter", options);
1266
1482
  }
1267
1483
 
1268
- const defaultOptions$f = {
1484
+ const defaultOptions$d = {
1269
1485
  minDuration: 0,
1270
1486
  minDistance: 0,
1271
1487
  getMousemoveTarget: (event) => event.target
@@ -1279,7 +1495,7 @@ function createMousepress(options = {}) {
1279
1495
  onLeave,
1280
1496
  onMove,
1281
1497
  onUp
1282
- } = { ...defaultOptions$f, ...options }, cleanup = (event) => {
1498
+ } = { ...defaultOptions$d, ...options }, cleanup = (event) => {
1283
1499
  window.cancelAnimationFrame(request);
1284
1500
  getMousemoveTarget(event).removeEventListener("mousemove", mousemoveEffect);
1285
1501
  };
@@ -1339,7 +1555,7 @@ function createMousepress(options = {}) {
1339
1555
  };
1340
1556
  }
1341
1557
 
1342
- const defaultOptions$e = {
1558
+ const defaultOptions$c = {
1343
1559
  minDuration: 0,
1344
1560
  minDistance: 0,
1345
1561
  minVelocity: 0,
@@ -1355,7 +1571,7 @@ function createMouserelease(options = {}) {
1355
1571
  onLeave,
1356
1572
  onMove,
1357
1573
  onUp
1358
- } = { ...defaultOptions$e, ...options }, cleanup = (event) => {
1574
+ } = { ...defaultOptions$c, ...options }, cleanup = (event) => {
1359
1575
  window.cancelAnimationFrame(request);
1360
1576
  getMousemoveTarget(event).removeEventListener("mousemove", mousemoveEffect);
1361
1577
  };
@@ -1413,7 +1629,7 @@ function createMouserelease(options = {}) {
1413
1629
  };
1414
1630
  }
1415
1631
 
1416
- const defaultOptions$d = {
1632
+ const defaultOptions$b = {
1417
1633
  minDuration: 0,
1418
1634
  minDistance: 0
1419
1635
  };
@@ -1425,7 +1641,7 @@ function createTouchpress(options = {}) {
1425
1641
  onCancel,
1426
1642
  onMove,
1427
1643
  onEnd
1428
- } = { ...defaultOptions$d, ...options }, cleanup = () => {
1644
+ } = { ...defaultOptions$b, ...options }, cleanup = () => {
1429
1645
  window.cancelAnimationFrame(request);
1430
1646
  };
1431
1647
  let request;
@@ -1486,7 +1702,7 @@ function createTouchpress(options = {}) {
1486
1702
  };
1487
1703
  }
1488
1704
 
1489
- const defaultOptions$c = {
1705
+ const defaultOptions$a = {
1490
1706
  minDuration: 0,
1491
1707
  minDistance: 0,
1492
1708
  minVelocity: 0
@@ -1500,7 +1716,7 @@ function createTouchrelease(options = {}) {
1500
1716
  onCancel,
1501
1717
  onMove,
1502
1718
  onEnd
1503
- } = { ...defaultOptions$c, ...options }, cleanup = () => {
1719
+ } = { ...defaultOptions$a, ...options }, cleanup = () => {
1504
1720
  window.cancelAnimationFrame(request);
1505
1721
  };
1506
1722
  let request;
@@ -1567,12 +1783,12 @@ function createTouchrelease(options = {}) {
1567
1783
  };
1568
1784
  }
1569
1785
 
1570
- const defaultOptions$b = {
1786
+ const defaultOptions$9 = {
1571
1787
  initial: []
1572
1788
  };
1573
1789
  function createKeyStatuses(options = {}) {
1574
1790
  return createAssociativeArray({
1575
- ...defaultOptions$b,
1791
+ ...defaultOptions$9,
1576
1792
  ...options,
1577
1793
  createPredicateKey: (query) => (key) => {
1578
1794
  for (const prop in query) {
@@ -1584,214 +1800,14 @@ function createKeyStatuses(options = {}) {
1584
1800
  }
1585
1801
  });
1586
1802
  }
1587
- function predicateDown(status) {
1588
- return status === "down";
1589
- }
1590
1803
  function predicateSomeKeyDown(statuses) {
1591
1804
  return lazyCollections.includes("down")(statuses.toValues());
1592
1805
  }
1593
1806
 
1594
- function fromComboToAliases(combo) {
1595
- const delimiter = "+";
1596
- return lazyCollections.pipe(
1597
- lazyCollections.unique(),
1598
- lazyCollections.map((name) => name === "" ? delimiter : name.toLowerCase()),
1599
- lazyCollections.toArray()
1600
- )(combo.split(delimiter));
1601
- }
1602
-
1603
- function fromAliasToKeyStatusKey(alias) {
1604
- if (alias in keysByAlias) {
1605
- return { key: keysByAlias[alias] };
1606
- }
1607
- return {
1608
- code: (() => {
1609
- if (alias in codesByAlias)
1610
- return codesByAlias[alias];
1611
- if (letterRE.test(alias))
1612
- return `Key${alias.toUpperCase()}`;
1613
- if (digitRE.test(alias))
1614
- return `Digit${alias}`;
1615
- if (functionRE.test(alias))
1616
- return alias.toUpperCase();
1617
- return "unsupported";
1618
- })()
1619
- };
1620
- }
1621
- const digitRE = /^[0-9]$/;
1622
- const letterRE = /^[a-zA-Z]$/;
1623
- const functionRE = /^[fF][0-9]{1,2}$/;
1624
- const codesByAlias = {
1625
- "`": "Backquote",
1626
- "~": "Backquote",
1627
- "-": "Minus",
1628
- _: "Minus",
1629
- "=": "Equal",
1630
- "+": "Equal",
1631
- "[": "BracketLeft",
1632
- "{": "BracketLeft",
1633
- "]": "BracketRight",
1634
- "}": "BracketRight",
1635
- "\\": "Backslash",
1636
- "|": "Backslash",
1637
- ";": "Semicolon",
1638
- ":": "Semicolon",
1639
- "'": "Quote",
1640
- '"': "Quote",
1641
- ",": "Comma",
1642
- "<": "Comma",
1643
- ".": "Period",
1644
- ">": "Period",
1645
- "/": "Slash",
1646
- "?": "Slash",
1647
- "!": "Digit1",
1648
- "@": "Digit2",
1649
- "#": "Digit3",
1650
- $: "Digit4",
1651
- "%": "Digit5",
1652
- "^": "Digit6",
1653
- "&": "Digit7",
1654
- "*": "Digit8",
1655
- "(": "Digit9",
1656
- ")": "Digit0",
1657
- up: "ArrowUp",
1658
- down: "ArrowDown",
1659
- left: "ArrowLeft",
1660
- right: "ArrowRight",
1661
- enter: "Enter",
1662
- space: "Space",
1663
- tab: "Tab",
1664
- esc: "Escape",
1665
- backspace: "Backspace",
1666
- delete: "Delete",
1667
- home: "Home",
1668
- end: "End",
1669
- pagedown: "PageDown",
1670
- pageup: "PageUp",
1671
- capslock: "CapsLock",
1672
- camera: "Camera"
1673
- };
1674
- const keysByAlias = {
1675
- alt: "Alt",
1676
- opt: "Alt",
1677
- option: "Alt",
1678
- ctrl: "Control",
1679
- control: "Control",
1680
- meta: "Meta",
1681
- cmd: "Meta",
1682
- command: "Meta",
1683
- shift: "Shift"
1684
- };
1685
-
1686
- const defaultOptions$a = {
1687
- toKey: (alias) => fromAliasToKeyStatusKey(alias)
1688
- };
1689
- const createPredicateKeycomboDown = (keycombo, options = {}) => {
1690
- const { toKey } = { ...defaultOptions$a, ...options }, keys = lazyCollections.pipe(
1691
- fromComboToAliases,
1692
- lazyCollections.map(toKey)
1693
- )(keycombo);
1694
- return (statuses) => {
1695
- const { toValue } = statuses;
1696
- return lazyCollections.every(lazyCollections.pipe(
1697
- toValue,
1698
- predicateDown
1699
- ))(keys);
1700
- };
1701
- };
1702
-
1703
- function fromEventToAliases(event) {
1704
- if (event.shiftKey && event.code in aliasesByShiftCode) {
1705
- return [aliasesByShiftCode[event.code]];
1706
- }
1707
- if (event.key in aliasListsByModifier) {
1708
- return aliasListsByModifier[event.key];
1709
- }
1710
- return event.code in aliasesByCode ? [aliasesByCode[event.code]] : [event.code.match(aliasCaptureRE)?.[1].toLowerCase() || "unsupported"];
1711
- }
1712
- const aliasCaptureRE = /^(?:Digit|Key)?(F[0-9]{1,2}|[0-9]|[A-Z])$/;
1713
- const aliasesByCode = {
1714
- Backquote: "`",
1715
- Minus: "-",
1716
- Equal: "=",
1717
- BracketLeft: "[",
1718
- BracketRight: "]",
1719
- Backslash: "\\",
1720
- Semicolon: ";",
1721
- Quote: "'",
1722
- Comma: ",",
1723
- Period: ".",
1724
- Slash: "/",
1725
- ArrowUp: "up",
1726
- ArrowDown: "down",
1727
- ArrowLeft: "left",
1728
- ArrowRight: "right",
1729
- Enter: "enter",
1730
- Space: "space",
1731
- Tab: "tab",
1732
- Escape: "esc",
1733
- Backspace: "backspace",
1734
- Delete: "delete",
1735
- Home: "home",
1736
- End: "end",
1737
- PageDown: "pagedown",
1738
- PageUp: "pageup",
1739
- CapsLock: "capslock",
1740
- Camera: "camera"
1741
- };
1742
- const aliasesByShiftCode = {
1743
- Backquote: "~",
1744
- Minus: "_",
1745
- Equal: "+",
1746
- BracketLeft: "{",
1747
- BracketRight: "}",
1748
- Backslash: "|",
1749
- Semicolon: ":",
1750
- Quote: '"',
1751
- Comma: "<",
1752
- Period: ">",
1753
- Slash: "?",
1754
- Digit1: "!",
1755
- Digit2: "@",
1756
- Digit3: "#",
1757
- Digit4: "$",
1758
- Digit5: "%",
1759
- Digit6: "^",
1760
- Digit7: "&",
1761
- Digit8: "*",
1762
- Digit9: "(",
1763
- Digit0: ")"
1764
- };
1765
- const aliasListsByModifier = {
1766
- Alt: ["alt", "option", "opt"],
1767
- Control: ["control", "ctrl"],
1768
- Meta: ["meta", "command", "cmd"],
1769
- Shift: ["shift"]
1770
- };
1771
-
1772
- const defaultOptions$9 = {
1773
- toKey: (alias) => fromAliasToKeyStatusKey(alias),
1774
- toAliases: (event) => fromEventToAliases(event)
1775
- };
1776
- const createPredicateKeycomboMatch = (keycombo, options = {}) => {
1777
- const { toKey, toAliases } = { ...defaultOptions$9, ...options }, aliases = fromComboToAliases(keycombo), keys = lazyCollections.map(toKey)(aliases);
1778
- return (statuses) => {
1779
- const { toValue } = statuses;
1780
- return lazyCollections.every(lazyCollections.pipe(
1781
- toValue,
1782
- predicateDown
1783
- ))(keys) && lazyCollections.every(
1784
- ([key, value]) => value === "up" || lazyCollections.some(
1785
- (alias) => lazyCollections.includes(alias)(aliases)
1786
- )(toAliases(key))
1787
- )(statuses.toEntries());
1788
- };
1789
- };
1790
-
1791
1807
  function createKeyState({
1792
1808
  keycomboOrKeycombos,
1793
1809
  unsupportedAliases,
1794
- toKey,
1810
+ toDownKeys,
1795
1811
  toAliases,
1796
1812
  getRequest
1797
1813
  }) {
@@ -1799,7 +1815,7 @@ function createKeyState({
1799
1815
  (keycombo) => !lazyCollections.some(
1800
1816
  (alias) => lazyCollections.includes(alias)(unsupportedAliases)
1801
1817
  )(fromComboToAliases(keycombo))
1802
- )(Array.isArray(keycomboOrKeycombos) ? keycomboOrKeycombos : [keycomboOrKeycombos]), createPredicateKeycomboDownOptions = { toKey }, downPredicatesByKeycombo = (() => {
1818
+ )(Array.isArray(keycomboOrKeycombos) ? keycomboOrKeycombos : [keycomboOrKeycombos]), createPredicateKeycomboDownOptions = { toDownKeys }, downPredicatesByKeycombo = (() => {
1803
1819
  const predicates = [];
1804
1820
  for (const keycombo of narrowedKeycombos) {
1805
1821
  predicates.push([
@@ -1814,7 +1830,7 @@ function createKeyState({
1814
1830
  })(), createPredicateKeycomboMatchOptions = { ...createPredicateKeycomboDownOptions, toAliases }, matchPredicatesByKeycombo = (() => {
1815
1831
  const predicates = {};
1816
1832
  for (const keycombo of narrowedKeycombos) {
1817
- predicates[keycombo] = createPredicateKeycomboMatch(
1833
+ predicates[keycombo] = createPredicateKeycomboMatch$1(
1818
1834
  keycombo,
1819
1835
  createPredicateKeycomboMatchOptions
1820
1836
  );
@@ -5047,7 +5063,7 @@ exports.createMap = createMap;
5047
5063
  exports.createMapAsync = createMapAsync;
5048
5064
  exports.createMousepress = createMousepress;
5049
5065
  exports.createMouserelease = createMouserelease;
5050
- exports.createPredicateKeycomboMatch = createPredicateKeycomboMatch$1;
5066
+ exports.createPredicateKeycomboMatch = createPredicateKeycomboMatch;
5051
5067
  exports.createPredicateRoot = createPredicateRoot;
5052
5068
  exports.createReduce = createReduce;
5053
5069
  exports.createReduceAsync = createReduceAsync;