@baleada/logic 0.23.1 → 0.23.3
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 +26 -14
- package/lib/index.d.ts +2 -0
- package/lib/index.js +26 -14
- package/package.json +1 -1
package/lib/index.cjs
CHANGED
|
@@ -761,15 +761,13 @@ function createToGraph(options = {}) {
|
|
|
761
761
|
}
|
|
762
762
|
|
|
763
763
|
const defaultOptions$k = {
|
|
764
|
-
toKey: (alias) => fromAliasToKeyStatusKey(alias)
|
|
764
|
+
toKey: (alias) => fromAliasToKeyStatusKey(alias),
|
|
765
|
+
toAliases: (event) => fromEventToAliases(event)
|
|
765
766
|
};
|
|
766
767
|
const createPredicateKeycomboMatch$1 = (keycombo, options = {}) => {
|
|
767
|
-
const { toKey } = { ...defaultOptions$k, ...options }, keys = lazyCollections.
|
|
768
|
-
fromComboToAliases,
|
|
769
|
-
lazyCollections.map(toKey)
|
|
770
|
-
)(keycombo);
|
|
768
|
+
const { toKey, toAliases } = { ...defaultOptions$k, ...options }, aliases = fromComboToAliases(keycombo), keys = lazyCollections.map(toKey)(aliases);
|
|
771
769
|
return (event) => {
|
|
772
|
-
const { toValue, set } = createKeyStatuses();
|
|
770
|
+
const { toValue, set, toEntries } = createKeyStatuses();
|
|
773
771
|
set(fromEventToKeyStatusKey(event), "down");
|
|
774
772
|
for (const modifier of modifiers) {
|
|
775
773
|
if (event[`${modifier.toLowerCase()}Key`])
|
|
@@ -778,7 +776,11 @@ const createPredicateKeycomboMatch$1 = (keycombo, options = {}) => {
|
|
|
778
776
|
return lazyCollections.every(lazyCollections.pipe(
|
|
779
777
|
toValue,
|
|
780
778
|
predicateDown
|
|
781
|
-
))(keys)
|
|
779
|
+
))(keys) && lazyCollections.every(
|
|
780
|
+
([key]) => lazyCollections.some(
|
|
781
|
+
(alias) => lazyCollections.includes(alias)(aliases)
|
|
782
|
+
)(toAliases(key))
|
|
783
|
+
)(toEntries());
|
|
782
784
|
};
|
|
783
785
|
};
|
|
784
786
|
|
|
@@ -1300,6 +1302,8 @@ function createMousepress(options = {}) {
|
|
|
1300
1302
|
onDown?.(toHookApi(api));
|
|
1301
1303
|
};
|
|
1302
1304
|
const mousemove = (event, api) => {
|
|
1305
|
+
const { pushSequence } = api;
|
|
1306
|
+
pushSequence(event);
|
|
1303
1307
|
storePointerMoveMetadata(event, api);
|
|
1304
1308
|
recognize(event, api);
|
|
1305
1309
|
onMove?.(toHookApi(api));
|
|
@@ -2070,7 +2074,7 @@ const initialMetadata = {
|
|
|
2070
2074
|
velocity: 0
|
|
2071
2075
|
};
|
|
2072
2076
|
function storePointerTimeMetadata(event, api, getShouldStore, setRequest, recognize) {
|
|
2073
|
-
const { getMetadata, getStatus, onRecognized } = api, metadata = getMetadata();
|
|
2077
|
+
const { getSequence, getMetadata, getStatus, onRecognized } = api, metadata = getMetadata();
|
|
2074
2078
|
if (!metadata.times) {
|
|
2075
2079
|
metadata.times = createClone()(initialMetadata.times);
|
|
2076
2080
|
}
|
|
@@ -2085,9 +2089,10 @@ function storePointerTimeMetadata(event, api, getShouldStore, setRequest, recogn
|
|
|
2085
2089
|
metadata.duration = Math.max(0, metadata.times.end - metadata.times.start);
|
|
2086
2090
|
const durationFromPrevious = Math.max(0, metadata.times.end - previousTime);
|
|
2087
2091
|
metadata.velocity = metadata.distance.straight.fromPrevious / durationFromPrevious;
|
|
2088
|
-
|
|
2092
|
+
const event2 = getSequence().at(-1);
|
|
2093
|
+
recognize?.(event2, api);
|
|
2089
2094
|
if (getStatus() === "recognized")
|
|
2090
|
-
onRecognized(
|
|
2095
|
+
onRecognized(event2);
|
|
2091
2096
|
storeDuration();
|
|
2092
2097
|
}
|
|
2093
2098
|
});
|
|
@@ -2265,11 +2270,18 @@ class Recognizeable {
|
|
|
2265
2270
|
}
|
|
2266
2271
|
recognize(sequenceItem, { onRecognized } = {}) {
|
|
2267
2272
|
this.recognizing();
|
|
2268
|
-
const type = this.toType(sequenceItem),
|
|
2269
|
-
|
|
2270
|
-
|
|
2271
|
-
|
|
2273
|
+
const type = this.toType(sequenceItem), pushSequence = (sequenceItem2) => {
|
|
2274
|
+
newSequence.push(sequenceItem2);
|
|
2275
|
+
if (this.maxSequenceLength !== true && newSequence.length > this.maxSequenceLength) {
|
|
2276
|
+
newSequence.shift();
|
|
2277
|
+
}
|
|
2278
|
+
}, newSequence = [];
|
|
2279
|
+
for (const sequenceItem2 of this.sequence) {
|
|
2280
|
+
pushSequence(sequenceItem2);
|
|
2281
|
+
}
|
|
2282
|
+
pushSequence(sequenceItem);
|
|
2272
2283
|
this.effectApi.getSequence = () => newSequence;
|
|
2284
|
+
this.effectApi.pushSequence = pushSequence;
|
|
2273
2285
|
this.effectApi.onRecognized = onRecognized || (() => {
|
|
2274
2286
|
});
|
|
2275
2287
|
this.effects[type]?.(sequenceItem, { ...this.effectApi });
|
package/lib/index.d.ts
CHANGED
|
@@ -160,6 +160,7 @@ type RecognizeableEffectApi<Type extends ListenableSupportedType, Metadata exten
|
|
|
160
160
|
recognized: () => void;
|
|
161
161
|
denied: () => void;
|
|
162
162
|
getSequence: () => ListenEffectParam<Type>[];
|
|
163
|
+
pushSequence: (sequenceItem: ListenEffectParam<Type>) => void;
|
|
163
164
|
onRecognized: (sequenceItem: ListenEffectParam<Type>) => any;
|
|
164
165
|
};
|
|
165
166
|
type RecognizeableStatus = 'recognized' | 'recognizing' | 'denied' | 'ready';
|
|
@@ -1244,6 +1245,7 @@ declare function createToGraph<TreeNode>(options?: CreateToGraphOptions<TreeNode
|
|
|
1244
1245
|
type KeyboardEventFn<Returned> = (keyboardEvent: KeyboardEvent) => Returned;
|
|
1245
1246
|
type CreatePredicateKeycomboMatchOptions = {
|
|
1246
1247
|
toKey?: (alias: string) => KeyStatusKey;
|
|
1248
|
+
toAliases?: (event: KeyboardEvent) => string[];
|
|
1247
1249
|
};
|
|
1248
1250
|
declare const createPredicateKeycomboMatch: (keycombo: string, options?: CreatePredicateKeycomboMatchOptions) => KeyboardEventFn<boolean>;
|
|
1249
1251
|
|
package/lib/index.js
CHANGED
|
@@ -759,15 +759,13 @@ function createToGraph(options = {}) {
|
|
|
759
759
|
}
|
|
760
760
|
|
|
761
761
|
const defaultOptions$k = {
|
|
762
|
-
toKey: (alias) => fromAliasToKeyStatusKey(alias)
|
|
762
|
+
toKey: (alias) => fromAliasToKeyStatusKey(alias),
|
|
763
|
+
toAliases: (event) => fromEventToAliases(event)
|
|
763
764
|
};
|
|
764
765
|
const createPredicateKeycomboMatch$1 = (keycombo, options = {}) => {
|
|
765
|
-
const { toKey } = { ...defaultOptions$k, ...options }, keys =
|
|
766
|
-
fromComboToAliases,
|
|
767
|
-
map(toKey)
|
|
768
|
-
)(keycombo);
|
|
766
|
+
const { toKey, toAliases } = { ...defaultOptions$k, ...options }, aliases = fromComboToAliases(keycombo), keys = map(toKey)(aliases);
|
|
769
767
|
return (event) => {
|
|
770
|
-
const { toValue, set } = createKeyStatuses();
|
|
768
|
+
const { toValue, set, toEntries } = createKeyStatuses();
|
|
771
769
|
set(fromEventToKeyStatusKey(event), "down");
|
|
772
770
|
for (const modifier of modifiers) {
|
|
773
771
|
if (event[`${modifier.toLowerCase()}Key`])
|
|
@@ -776,7 +774,11 @@ const createPredicateKeycomboMatch$1 = (keycombo, options = {}) => {
|
|
|
776
774
|
return every(pipe(
|
|
777
775
|
toValue,
|
|
778
776
|
predicateDown
|
|
779
|
-
))(keys)
|
|
777
|
+
))(keys) && every(
|
|
778
|
+
([key]) => some(
|
|
779
|
+
(alias) => includes(alias)(aliases)
|
|
780
|
+
)(toAliases(key))
|
|
781
|
+
)(toEntries());
|
|
780
782
|
};
|
|
781
783
|
};
|
|
782
784
|
|
|
@@ -1298,6 +1300,8 @@ function createMousepress(options = {}) {
|
|
|
1298
1300
|
onDown?.(toHookApi(api));
|
|
1299
1301
|
};
|
|
1300
1302
|
const mousemove = (event, api) => {
|
|
1303
|
+
const { pushSequence } = api;
|
|
1304
|
+
pushSequence(event);
|
|
1301
1305
|
storePointerMoveMetadata(event, api);
|
|
1302
1306
|
recognize(event, api);
|
|
1303
1307
|
onMove?.(toHookApi(api));
|
|
@@ -2068,7 +2072,7 @@ const initialMetadata = {
|
|
|
2068
2072
|
velocity: 0
|
|
2069
2073
|
};
|
|
2070
2074
|
function storePointerTimeMetadata(event, api, getShouldStore, setRequest, recognize) {
|
|
2071
|
-
const { getMetadata, getStatus, onRecognized } = api, metadata = getMetadata();
|
|
2075
|
+
const { getSequence, getMetadata, getStatus, onRecognized } = api, metadata = getMetadata();
|
|
2072
2076
|
if (!metadata.times) {
|
|
2073
2077
|
metadata.times = createClone()(initialMetadata.times);
|
|
2074
2078
|
}
|
|
@@ -2083,9 +2087,10 @@ function storePointerTimeMetadata(event, api, getShouldStore, setRequest, recogn
|
|
|
2083
2087
|
metadata.duration = Math.max(0, metadata.times.end - metadata.times.start);
|
|
2084
2088
|
const durationFromPrevious = Math.max(0, metadata.times.end - previousTime);
|
|
2085
2089
|
metadata.velocity = metadata.distance.straight.fromPrevious / durationFromPrevious;
|
|
2086
|
-
|
|
2090
|
+
const event2 = getSequence().at(-1);
|
|
2091
|
+
recognize?.(event2, api);
|
|
2087
2092
|
if (getStatus() === "recognized")
|
|
2088
|
-
onRecognized(
|
|
2093
|
+
onRecognized(event2);
|
|
2089
2094
|
storeDuration();
|
|
2090
2095
|
}
|
|
2091
2096
|
});
|
|
@@ -2263,11 +2268,18 @@ class Recognizeable {
|
|
|
2263
2268
|
}
|
|
2264
2269
|
recognize(sequenceItem, { onRecognized } = {}) {
|
|
2265
2270
|
this.recognizing();
|
|
2266
|
-
const type = this.toType(sequenceItem),
|
|
2267
|
-
|
|
2268
|
-
|
|
2269
|
-
|
|
2271
|
+
const type = this.toType(sequenceItem), pushSequence = (sequenceItem2) => {
|
|
2272
|
+
newSequence.push(sequenceItem2);
|
|
2273
|
+
if (this.maxSequenceLength !== true && newSequence.length > this.maxSequenceLength) {
|
|
2274
|
+
newSequence.shift();
|
|
2275
|
+
}
|
|
2276
|
+
}, newSequence = [];
|
|
2277
|
+
for (const sequenceItem2 of this.sequence) {
|
|
2278
|
+
pushSequence(sequenceItem2);
|
|
2279
|
+
}
|
|
2280
|
+
pushSequence(sequenceItem);
|
|
2270
2281
|
this.effectApi.getSequence = () => newSequence;
|
|
2282
|
+
this.effectApi.pushSequence = pushSequence;
|
|
2271
2283
|
this.effectApi.onRecognized = onRecognized || (() => {
|
|
2272
2284
|
});
|
|
2273
2285
|
this.effects[type]?.(sequenceItem, { ...this.effectApi });
|