@baleada/logic 0.23.2 → 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,34 +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),
961
+ toAliases: (event) => fromEventToAliases(event)
765
962
  };
766
- const createPredicateKeycomboMatch$1 = (keycombo, options = {}) => {
767
- const { toKey } = { ...defaultOptions$k, ...options }, keys = lazyCollections.pipe(
768
- fromComboToAliases,
769
- lazyCollections.map(toKey)
770
- )(keycombo);
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
+ })();
771
974
  return (event) => {
772
- const { toValue, set } = createKeyStatuses();
773
- set(fromEventToKeyStatusKey(event), "down");
975
+ const statuses = createKeyStatuses(), predicateAliasDown = lazyCollections.every(
976
+ (key) => statuses.toValue(key) === "down"
977
+ );
978
+ statuses.set(fromEventToKeyStatusKey(event), "down");
774
979
  for (const modifier of modifiers) {
775
980
  if (event[`${modifier.toLowerCase()}Key`])
776
- set({ key: modifier }, "down");
981
+ statuses.set({ key: modifier }, "down");
777
982
  }
778
- return lazyCollections.every(lazyCollections.pipe(
779
- toValue,
780
- predicateDown
781
- ))(keys);
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);
782
1000
  };
783
1001
  };
784
1002
 
785
- const defaultOptions$j = {
1003
+ const defaultOptions$h = {
786
1004
  initial: [],
787
1005
  createPredicateKey: (query) => (candidate) => query === candidate
788
1006
  };
789
1007
  function createAssociativeArray(options = {}) {
790
- const { initial, createPredicateKey } = { ...defaultOptions$j, ...options }, entries = [...initial];
1008
+ const { initial, createPredicateKey } = { ...defaultOptions$h, ...options }, entries = [...initial];
791
1009
  const toValue = (key) => {
792
1010
  const predicateKey = createPredicateKey(key);
793
1011
  return lazyCollections.find(
@@ -848,22 +1066,22 @@ function createAssociativeArray(options = {}) {
848
1066
  };
849
1067
  }
850
1068
 
851
- const defaultOptions$i = {
1069
+ const defaultOptions$g = {
852
1070
  minDuration: 0,
853
1071
  preventsDefaultUnlessDenied: true,
854
- toKey: (alias) => fromAliasToKeyStatusKey(alias),
1072
+ toDownKeys: (alias) => fromAliasToDownKeys(alias),
855
1073
  toAliases: (event) => fromEventToAliases(event)
856
1074
  };
857
1075
  function createKeypress(keycomboOrKeycombos, options = {}) {
858
1076
  const {
859
1077
  minDuration,
860
1078
  preventsDefaultUnlessDenied,
861
- toKey,
1079
+ toDownKeys,
862
1080
  toAliases,
863
1081
  onDown,
864
1082
  onUp,
865
1083
  onVisibilitychange
866
- } = { ...defaultOptions$i, ...options }, {
1084
+ } = { ...defaultOptions$g, ...options }, {
867
1085
  matchPredicatesByKeycombo,
868
1086
  getDownCombos,
869
1087
  predicateValid,
@@ -872,7 +1090,7 @@ function createKeypress(keycomboOrKeycombos, options = {}) {
872
1090
  } = createKeyState({
873
1091
  keycomboOrKeycombos,
874
1092
  unsupportedAliases: unsupportedAliases$2,
875
- toKey,
1093
+ toDownKeys,
876
1094
  toAliases,
877
1095
  getRequest: () => request
878
1096
  });
@@ -971,22 +1189,22 @@ function createKeypress(keycomboOrKeycombos, options = {}) {
971
1189
  const unsupportedAliases$2 = ["meta", "command", "cmd"];
972
1190
  const unsupportedKeys$2 = ["Meta"];
973
1191
 
974
- const defaultOptions$h = {
1192
+ const defaultOptions$f = {
975
1193
  minDuration: 0,
976
1194
  preventsDefaultUnlessDenied: true,
977
- toKey: (alias) => fromAliasToKeyStatusKey(alias),
1195
+ toDownKeys: (alias) => fromAliasToDownKeys(alias),
978
1196
  toAliases: (event) => fromEventToAliases(event)
979
1197
  };
980
1198
  function createKeyrelease(keycomboOrKeycombos, options = {}) {
981
1199
  const {
982
1200
  minDuration,
983
1201
  preventsDefaultUnlessDenied,
984
- toKey,
1202
+ toDownKeys,
985
1203
  toAliases,
986
1204
  onDown,
987
1205
  onUp,
988
1206
  onVisibilitychange
989
- } = { ...defaultOptions$h, ...options }, {
1207
+ } = { ...defaultOptions$f, ...options }, {
990
1208
  matchPredicatesByKeycombo,
991
1209
  getDownCombos,
992
1210
  predicateValid,
@@ -995,7 +1213,7 @@ function createKeyrelease(keycomboOrKeycombos, options = {}) {
995
1213
  } = createKeyState({
996
1214
  keycomboOrKeycombos,
997
1215
  unsupportedAliases: unsupportedAliases$1,
998
- toKey,
1216
+ toDownKeys,
999
1217
  toAliases,
1000
1218
  getRequest: () => request
1001
1219
  });
@@ -1097,12 +1315,12 @@ function createKeyrelease(keycomboOrKeycombos, options = {}) {
1097
1315
  const unsupportedAliases$1 = ["meta", "command", "cmd"];
1098
1316
  const unsupportedKeys$1 = ["Meta"];
1099
1317
 
1100
- const defaultOptions$g = {
1318
+ const defaultOptions$e = {
1101
1319
  minDuration: 0,
1102
1320
  maxInterval: 5e3,
1103
1321
  // VS Code default
1104
1322
  preventsDefaultUnlessDenied: true,
1105
- toKey: (alias) => fromAliasToKeyStatusKey(alias),
1323
+ toDownKeys: (alias) => fromAliasToDownKeys(alias),
1106
1324
  toAliases: (event) => fromEventToAliases(event)
1107
1325
  };
1108
1326
  function createKeychord(keychord, options = {}) {
@@ -1110,15 +1328,15 @@ function createKeychord(keychord, options = {}) {
1110
1328
  minDuration,
1111
1329
  maxInterval,
1112
1330
  preventsDefaultUnlessDenied,
1113
- toKey,
1331
+ toDownKeys,
1114
1332
  toAliases,
1115
1333
  onDown,
1116
1334
  onUp,
1117
1335
  onVisibilitychange
1118
- } = { ...defaultOptions$g, ...options }, narrowedKeychord = keychord.split(" "), keyStates = createMap((keycombo) => createKeyState({
1336
+ } = { ...defaultOptions$e, ...options }, narrowedKeychord = keychord.split(" "), keyStates = createMap((keycombo) => createKeyState({
1119
1337
  keycomboOrKeycombos: keycombo,
1120
1338
  unsupportedAliases,
1121
- toKey,
1339
+ toDownKeys,
1122
1340
  toAliases,
1123
1341
  getRequest: () => request
1124
1342
  }))(narrowedKeychord), localStatuses = createMap(
@@ -1263,7 +1481,7 @@ function createKonami(options = {}) {
1263
1481
  return createKeychord("up up down down left right left right b a enter", options);
1264
1482
  }
1265
1483
 
1266
- const defaultOptions$f = {
1484
+ const defaultOptions$d = {
1267
1485
  minDuration: 0,
1268
1486
  minDistance: 0,
1269
1487
  getMousemoveTarget: (event) => event.target
@@ -1277,7 +1495,7 @@ function createMousepress(options = {}) {
1277
1495
  onLeave,
1278
1496
  onMove,
1279
1497
  onUp
1280
- } = { ...defaultOptions$f, ...options }, cleanup = (event) => {
1498
+ } = { ...defaultOptions$d, ...options }, cleanup = (event) => {
1281
1499
  window.cancelAnimationFrame(request);
1282
1500
  getMousemoveTarget(event).removeEventListener("mousemove", mousemoveEffect);
1283
1501
  };
@@ -1337,7 +1555,7 @@ function createMousepress(options = {}) {
1337
1555
  };
1338
1556
  }
1339
1557
 
1340
- const defaultOptions$e = {
1558
+ const defaultOptions$c = {
1341
1559
  minDuration: 0,
1342
1560
  minDistance: 0,
1343
1561
  minVelocity: 0,
@@ -1353,7 +1571,7 @@ function createMouserelease(options = {}) {
1353
1571
  onLeave,
1354
1572
  onMove,
1355
1573
  onUp
1356
- } = { ...defaultOptions$e, ...options }, cleanup = (event) => {
1574
+ } = { ...defaultOptions$c, ...options }, cleanup = (event) => {
1357
1575
  window.cancelAnimationFrame(request);
1358
1576
  getMousemoveTarget(event).removeEventListener("mousemove", mousemoveEffect);
1359
1577
  };
@@ -1411,7 +1629,7 @@ function createMouserelease(options = {}) {
1411
1629
  };
1412
1630
  }
1413
1631
 
1414
- const defaultOptions$d = {
1632
+ const defaultOptions$b = {
1415
1633
  minDuration: 0,
1416
1634
  minDistance: 0
1417
1635
  };
@@ -1423,7 +1641,7 @@ function createTouchpress(options = {}) {
1423
1641
  onCancel,
1424
1642
  onMove,
1425
1643
  onEnd
1426
- } = { ...defaultOptions$d, ...options }, cleanup = () => {
1644
+ } = { ...defaultOptions$b, ...options }, cleanup = () => {
1427
1645
  window.cancelAnimationFrame(request);
1428
1646
  };
1429
1647
  let request;
@@ -1484,7 +1702,7 @@ function createTouchpress(options = {}) {
1484
1702
  };
1485
1703
  }
1486
1704
 
1487
- const defaultOptions$c = {
1705
+ const defaultOptions$a = {
1488
1706
  minDuration: 0,
1489
1707
  minDistance: 0,
1490
1708
  minVelocity: 0
@@ -1498,7 +1716,7 @@ function createTouchrelease(options = {}) {
1498
1716
  onCancel,
1499
1717
  onMove,
1500
1718
  onEnd
1501
- } = { ...defaultOptions$c, ...options }, cleanup = () => {
1719
+ } = { ...defaultOptions$a, ...options }, cleanup = () => {
1502
1720
  window.cancelAnimationFrame(request);
1503
1721
  };
1504
1722
  let request;
@@ -1565,12 +1783,12 @@ function createTouchrelease(options = {}) {
1565
1783
  };
1566
1784
  }
1567
1785
 
1568
- const defaultOptions$b = {
1786
+ const defaultOptions$9 = {
1569
1787
  initial: []
1570
1788
  };
1571
1789
  function createKeyStatuses(options = {}) {
1572
1790
  return createAssociativeArray({
1573
- ...defaultOptions$b,
1791
+ ...defaultOptions$9,
1574
1792
  ...options,
1575
1793
  createPredicateKey: (query) => (key) => {
1576
1794
  for (const prop in query) {
@@ -1582,214 +1800,14 @@ function createKeyStatuses(options = {}) {
1582
1800
  }
1583
1801
  });
1584
1802
  }
1585
- function predicateDown(status) {
1586
- return status === "down";
1587
- }
1588
1803
  function predicateSomeKeyDown(statuses) {
1589
1804
  return lazyCollections.includes("down")(statuses.toValues());
1590
1805
  }
1591
1806
 
1592
- function fromComboToAliases(combo) {
1593
- const delimiter = "+";
1594
- return lazyCollections.pipe(
1595
- lazyCollections.unique(),
1596
- lazyCollections.map((name) => name === "" ? delimiter : name.toLowerCase()),
1597
- lazyCollections.toArray()
1598
- )(combo.split(delimiter));
1599
- }
1600
-
1601
- function fromAliasToKeyStatusKey(alias) {
1602
- if (alias in keysByAlias) {
1603
- return { key: keysByAlias[alias] };
1604
- }
1605
- return {
1606
- code: (() => {
1607
- if (alias in codesByAlias)
1608
- return codesByAlias[alias];
1609
- if (letterRE.test(alias))
1610
- return `Key${alias.toUpperCase()}`;
1611
- if (digitRE.test(alias))
1612
- return `Digit${alias}`;
1613
- if (functionRE.test(alias))
1614
- return alias.toUpperCase();
1615
- return "unsupported";
1616
- })()
1617
- };
1618
- }
1619
- const digitRE = /^[0-9]$/;
1620
- const letterRE = /^[a-zA-Z]$/;
1621
- const functionRE = /^[fF][0-9]{1,2}$/;
1622
- const codesByAlias = {
1623
- "`": "Backquote",
1624
- "~": "Backquote",
1625
- "-": "Minus",
1626
- _: "Minus",
1627
- "=": "Equal",
1628
- "+": "Equal",
1629
- "[": "BracketLeft",
1630
- "{": "BracketLeft",
1631
- "]": "BracketRight",
1632
- "}": "BracketRight",
1633
- "\\": "Backslash",
1634
- "|": "Backslash",
1635
- ";": "Semicolon",
1636
- ":": "Semicolon",
1637
- "'": "Quote",
1638
- '"': "Quote",
1639
- ",": "Comma",
1640
- "<": "Comma",
1641
- ".": "Period",
1642
- ">": "Period",
1643
- "/": "Slash",
1644
- "?": "Slash",
1645
- "!": "Digit1",
1646
- "@": "Digit2",
1647
- "#": "Digit3",
1648
- $: "Digit4",
1649
- "%": "Digit5",
1650
- "^": "Digit6",
1651
- "&": "Digit7",
1652
- "*": "Digit8",
1653
- "(": "Digit9",
1654
- ")": "Digit0",
1655
- up: "ArrowUp",
1656
- down: "ArrowDown",
1657
- left: "ArrowLeft",
1658
- right: "ArrowRight",
1659
- enter: "Enter",
1660
- space: "Space",
1661
- tab: "Tab",
1662
- esc: "Escape",
1663
- backspace: "Backspace",
1664
- delete: "Delete",
1665
- home: "Home",
1666
- end: "End",
1667
- pagedown: "PageDown",
1668
- pageup: "PageUp",
1669
- capslock: "CapsLock",
1670
- camera: "Camera"
1671
- };
1672
- const keysByAlias = {
1673
- alt: "Alt",
1674
- opt: "Alt",
1675
- option: "Alt",
1676
- ctrl: "Control",
1677
- control: "Control",
1678
- meta: "Meta",
1679
- cmd: "Meta",
1680
- command: "Meta",
1681
- shift: "Shift"
1682
- };
1683
-
1684
- const defaultOptions$a = {
1685
- toKey: (alias) => fromAliasToKeyStatusKey(alias)
1686
- };
1687
- const createPredicateKeycomboDown = (keycombo, options = {}) => {
1688
- const { toKey } = { ...defaultOptions$a, ...options }, keys = lazyCollections.pipe(
1689
- fromComboToAliases,
1690
- lazyCollections.map(toKey)
1691
- )(keycombo);
1692
- return (statuses) => {
1693
- const { toValue } = statuses;
1694
- return lazyCollections.every(lazyCollections.pipe(
1695
- toValue,
1696
- predicateDown
1697
- ))(keys);
1698
- };
1699
- };
1700
-
1701
- function fromEventToAliases(event) {
1702
- if (event.shiftKey && event.code in aliasesByShiftCode) {
1703
- return [aliasesByShiftCode[event.code]];
1704
- }
1705
- if (event.key in aliasListsByModifier) {
1706
- return aliasListsByModifier[event.key];
1707
- }
1708
- return event.code in aliasesByCode ? [aliasesByCode[event.code]] : [event.code.match(aliasCaptureRE)?.[1].toLowerCase() || "unsupported"];
1709
- }
1710
- const aliasCaptureRE = /^(?:Digit|Key)?(F[0-9]{1,2}|[0-9]|[A-Z])$/;
1711
- const aliasesByCode = {
1712
- Backquote: "`",
1713
- Minus: "-",
1714
- Equal: "=",
1715
- BracketLeft: "[",
1716
- BracketRight: "]",
1717
- Backslash: "\\",
1718
- Semicolon: ";",
1719
- Quote: "'",
1720
- Comma: ",",
1721
- Period: ".",
1722
- Slash: "/",
1723
- ArrowUp: "up",
1724
- ArrowDown: "down",
1725
- ArrowLeft: "left",
1726
- ArrowRight: "right",
1727
- Enter: "enter",
1728
- Space: "space",
1729
- Tab: "tab",
1730
- Escape: "esc",
1731
- Backspace: "backspace",
1732
- Delete: "delete",
1733
- Home: "home",
1734
- End: "end",
1735
- PageDown: "pagedown",
1736
- PageUp: "pageup",
1737
- CapsLock: "capslock",
1738
- Camera: "camera"
1739
- };
1740
- const aliasesByShiftCode = {
1741
- Backquote: "~",
1742
- Minus: "_",
1743
- Equal: "+",
1744
- BracketLeft: "{",
1745
- BracketRight: "}",
1746
- Backslash: "|",
1747
- Semicolon: ":",
1748
- Quote: '"',
1749
- Comma: "<",
1750
- Period: ">",
1751
- Slash: "?",
1752
- Digit1: "!",
1753
- Digit2: "@",
1754
- Digit3: "#",
1755
- Digit4: "$",
1756
- Digit5: "%",
1757
- Digit6: "^",
1758
- Digit7: "&",
1759
- Digit8: "*",
1760
- Digit9: "(",
1761
- Digit0: ")"
1762
- };
1763
- const aliasListsByModifier = {
1764
- Alt: ["alt", "option", "opt"],
1765
- Control: ["control", "ctrl"],
1766
- Meta: ["meta", "command", "cmd"],
1767
- Shift: ["shift"]
1768
- };
1769
-
1770
- const defaultOptions$9 = {
1771
- toKey: (alias) => fromAliasToKeyStatusKey(alias),
1772
- toAliases: (event) => fromEventToAliases(event)
1773
- };
1774
- const createPredicateKeycomboMatch = (keycombo, options = {}) => {
1775
- const { toKey, toAliases } = { ...defaultOptions$9, ...options }, aliases = fromComboToAliases(keycombo), keys = lazyCollections.map(toKey)(aliases);
1776
- return (statuses) => {
1777
- const { toValue } = statuses;
1778
- return lazyCollections.every(lazyCollections.pipe(
1779
- toValue,
1780
- predicateDown
1781
- ))(keys) && lazyCollections.every(
1782
- ([key, value]) => value === "up" || lazyCollections.some(
1783
- (alias) => lazyCollections.includes(alias)(aliases)
1784
- )(toAliases(key))
1785
- )(statuses.toEntries());
1786
- };
1787
- };
1788
-
1789
1807
  function createKeyState({
1790
1808
  keycomboOrKeycombos,
1791
1809
  unsupportedAliases,
1792
- toKey,
1810
+ toDownKeys,
1793
1811
  toAliases,
1794
1812
  getRequest
1795
1813
  }) {
@@ -1797,7 +1815,7 @@ function createKeyState({
1797
1815
  (keycombo) => !lazyCollections.some(
1798
1816
  (alias) => lazyCollections.includes(alias)(unsupportedAliases)
1799
1817
  )(fromComboToAliases(keycombo))
1800
- )(Array.isArray(keycomboOrKeycombos) ? keycomboOrKeycombos : [keycomboOrKeycombos]), createPredicateKeycomboDownOptions = { toKey }, downPredicatesByKeycombo = (() => {
1818
+ )(Array.isArray(keycomboOrKeycombos) ? keycomboOrKeycombos : [keycomboOrKeycombos]), createPredicateKeycomboDownOptions = { toDownKeys }, downPredicatesByKeycombo = (() => {
1801
1819
  const predicates = [];
1802
1820
  for (const keycombo of narrowedKeycombos) {
1803
1821
  predicates.push([
@@ -1812,7 +1830,7 @@ function createKeyState({
1812
1830
  })(), createPredicateKeycomboMatchOptions = { ...createPredicateKeycomboDownOptions, toAliases }, matchPredicatesByKeycombo = (() => {
1813
1831
  const predicates = {};
1814
1832
  for (const keycombo of narrowedKeycombos) {
1815
- predicates[keycombo] = createPredicateKeycomboMatch(
1833
+ predicates[keycombo] = createPredicateKeycomboMatch$1(
1816
1834
  keycombo,
1817
1835
  createPredicateKeycomboMatchOptions
1818
1836
  );
@@ -5045,7 +5063,7 @@ exports.createMap = createMap;
5045
5063
  exports.createMapAsync = createMapAsync;
5046
5064
  exports.createMousepress = createMousepress;
5047
5065
  exports.createMouserelease = createMouserelease;
5048
- exports.createPredicateKeycomboMatch = createPredicateKeycomboMatch$1;
5066
+ exports.createPredicateKeycomboMatch = createPredicateKeycomboMatch;
5049
5067
  exports.createPredicateRoot = createPredicateRoot;
5050
5068
  exports.createReduce = createReduce;
5051
5069
  exports.createReduceAsync = createReduceAsync;