@baleada/logic 0.24.5 → 0.24.7
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 +44 -36
- package/lib/index.d.ts +3 -3
- package/lib/index.js +44 -36
- package/package.json +1 -1
package/lib/index.cjs
CHANGED
|
@@ -1800,6 +1800,7 @@ function createLayers$1(options = {}) {
|
|
|
1800
1800
|
yield layers[depth - 1];
|
|
1801
1801
|
(layers[depth] || (layers[depth] = [])).push(node);
|
|
1802
1802
|
}
|
|
1803
|
+
yield layers.at(-1);
|
|
1803
1804
|
};
|
|
1804
1805
|
}
|
|
1805
1806
|
function createTree$2(options = {}) {
|
|
@@ -2220,22 +2221,23 @@ const createKeycomboMatch$1 = (keycombo, options = {}) => {
|
|
|
2220
2221
|
}
|
|
2221
2222
|
return implicitModifierAliases2;
|
|
2222
2223
|
})();
|
|
2223
|
-
return (
|
|
2224
|
+
return (descriptor) => {
|
|
2224
2225
|
const statuses = [];
|
|
2225
|
-
|
|
2226
|
+
if (descriptor.code)
|
|
2227
|
+
createSet(fromEventToKeyStatusCode(descriptor), "down")(statuses);
|
|
2226
2228
|
for (const modifier of modifiers) {
|
|
2227
2229
|
const prefix = modifier === "Control" ? "ctrl" : modifier.toLowerCase();
|
|
2228
|
-
if (
|
|
2230
|
+
if (descriptor[`${prefix}Key`])
|
|
2229
2231
|
createSet(modifier, "down")(statuses);
|
|
2230
2232
|
}
|
|
2231
|
-
const
|
|
2233
|
+
const descriptors = createMap(
|
|
2232
2234
|
([code]) => {
|
|
2233
|
-
const
|
|
2235
|
+
const newDescriptor = { code };
|
|
2234
2236
|
for (const modifier of modifiers) {
|
|
2235
2237
|
const prefix = modifier === "Control" ? "ctrl" : modifier.toLowerCase();
|
|
2236
|
-
|
|
2238
|
+
newDescriptor[`${prefix}Key`] = descriptor[`${prefix}Key`];
|
|
2237
2239
|
}
|
|
2238
|
-
return
|
|
2240
|
+
return newDescriptor;
|
|
2239
2241
|
}
|
|
2240
2242
|
)(statuses);
|
|
2241
2243
|
return lazyCollections.every(
|
|
@@ -2244,7 +2246,7 @@ const createKeycomboMatch$1 = (keycombo, options = {}) => {
|
|
|
2244
2246
|
{ predicateKey: createCode(code) }
|
|
2245
2247
|
)(statuses) === "down"
|
|
2246
2248
|
)(codes) && lazyCollections.every(
|
|
2247
|
-
(
|
|
2249
|
+
(d) => lazyCollections.pipe(
|
|
2248
2250
|
fromDescriptorToAliases,
|
|
2249
2251
|
lazyCollections.map(fromComboToAliases),
|
|
2250
2252
|
lazyCollections.some(
|
|
@@ -2252,8 +2254,8 @@ const createKeycomboMatch$1 = (keycombo, options = {}) => {
|
|
|
2252
2254
|
(longhandAlias) => lazyCollections.includes(longhandAlias)(aliases) || lazyCollections.includes(longhandAlias)(implicitModifierAliases)
|
|
2253
2255
|
)(longhandAliases)
|
|
2254
2256
|
)
|
|
2255
|
-
)(
|
|
2256
|
-
)(
|
|
2257
|
+
)(d)
|
|
2258
|
+
)(descriptors);
|
|
2257
2259
|
};
|
|
2258
2260
|
};
|
|
2259
2261
|
|
|
@@ -2485,13 +2487,13 @@ const createKeycomboDown = (keycombo, options = {}) => {
|
|
|
2485
2487
|
)(codes);
|
|
2486
2488
|
};
|
|
2487
2489
|
|
|
2488
|
-
function fromKeyboardEventDescriptorToAliases(
|
|
2489
|
-
if (
|
|
2490
|
-
return [aliasesByShiftCode[
|
|
2491
|
-
const withoutModifierSide = toWithoutModifierSide(
|
|
2490
|
+
function fromKeyboardEventDescriptorToAliases(descriptor) {
|
|
2491
|
+
if (descriptor.shiftKey && descriptor.code in aliasesByShiftCode)
|
|
2492
|
+
return [aliasesByShiftCode[descriptor.code]];
|
|
2493
|
+
const withoutModifierSide = toWithoutModifierSide(descriptor.code);
|
|
2492
2494
|
if (withoutModifierSide in aliasListsByModifier)
|
|
2493
2495
|
return aliasListsByModifier[withoutModifierSide];
|
|
2494
|
-
return
|
|
2496
|
+
return descriptor.code in aliasesByCode ? [aliasesByCode[descriptor.code]] : [descriptor.code.match(aliasCaptureRE)?.[1].toLowerCase() || "unsupported"];
|
|
2495
2497
|
}
|
|
2496
2498
|
const toWithoutModifierSide = createClip(/(?:Left|Right)$/);
|
|
2497
2499
|
const aliasCaptureRE = /^(?:Digit|Key)?(F[0-9]{1,2}|[0-9]|[A-Z])$/;
|
|
@@ -2753,21 +2755,24 @@ function storeKeyboardTimeMetadata({
|
|
|
2753
2755
|
timeMetadata.times = createClone()(initialMetadata$3.times);
|
|
2754
2756
|
timeMetadata.times.start = Math.round(event.timeStamp);
|
|
2755
2757
|
timeMetadata.times.end = Math.round(event.timeStamp);
|
|
2756
|
-
const
|
|
2758
|
+
const frameEffect = (timestamp) => {
|
|
2759
|
+
timeMetadata.times.end = Math.round(timestamp);
|
|
2760
|
+
timeMetadata.duration = Math.max(0, timeMetadata.times.end - timeMetadata.times.start);
|
|
2761
|
+
if (recognize) {
|
|
2762
|
+
recognize(event, api);
|
|
2763
|
+
if (getStatus() === "recognized")
|
|
2764
|
+
effect(event);
|
|
2765
|
+
}
|
|
2766
|
+
}, storeDuration = () => {
|
|
2757
2767
|
const request = requestAnimationFrame((timestamp) => {
|
|
2758
2768
|
if (!getShouldStore())
|
|
2759
2769
|
return;
|
|
2760
|
-
|
|
2761
|
-
timeMetadata.duration = Math.max(0, timeMetadata.times.end - timeMetadata.times.start);
|
|
2762
|
-
if (recognize) {
|
|
2763
|
-
recognize(event, api);
|
|
2764
|
-
if (getStatus() === "recognized")
|
|
2765
|
-
effect(event);
|
|
2766
|
-
}
|
|
2770
|
+
frameEffect(timestamp);
|
|
2767
2771
|
storeDuration();
|
|
2768
2772
|
});
|
|
2769
2773
|
setRequest(request);
|
|
2770
2774
|
};
|
|
2775
|
+
frameEffect(performance.now());
|
|
2771
2776
|
storeDuration();
|
|
2772
2777
|
}
|
|
2773
2778
|
|
|
@@ -2867,23 +2872,26 @@ function storePointerTimeMetadata(event, api, getShouldStore, setRequest, recogn
|
|
|
2867
2872
|
metadata.times.start = Math.round(event.timeStamp);
|
|
2868
2873
|
metadata.times.end = Math.round(event.timeStamp);
|
|
2869
2874
|
let previousTime = metadata.times.start;
|
|
2870
|
-
const
|
|
2875
|
+
const frameEffect = (timestamp) => {
|
|
2876
|
+
previousTime = metadata.times.end;
|
|
2877
|
+
metadata.times.end = Math.round(timestamp);
|
|
2878
|
+
metadata.duration = Math.max(0, metadata.times.end - metadata.times.start);
|
|
2879
|
+
const durationFromPrevious = Math.max(0, metadata.times.end - previousTime);
|
|
2880
|
+
metadata.velocity = metadata.distance.straight.fromPrevious / durationFromPrevious || 0;
|
|
2881
|
+
const event2 = getSequence().at(-1);
|
|
2882
|
+
recognize?.(event2, api);
|
|
2883
|
+
if (getStatus() === "recognized")
|
|
2884
|
+
effect(event2);
|
|
2885
|
+
}, storeDuration = () => {
|
|
2871
2886
|
const request = requestAnimationFrame((timestamp) => {
|
|
2872
|
-
if (getShouldStore())
|
|
2873
|
-
|
|
2874
|
-
|
|
2875
|
-
|
|
2876
|
-
const durationFromPrevious = Math.max(0, metadata.times.end - previousTime);
|
|
2877
|
-
metadata.velocity = metadata.distance.straight.fromPrevious / durationFromPrevious;
|
|
2878
|
-
const event2 = getSequence().at(-1);
|
|
2879
|
-
recognize?.(event2, api);
|
|
2880
|
-
if (getStatus() === "recognized")
|
|
2881
|
-
effect(event2);
|
|
2882
|
-
storeDuration();
|
|
2883
|
-
}
|
|
2887
|
+
if (!getShouldStore())
|
|
2888
|
+
return;
|
|
2889
|
+
frameEffect(timestamp);
|
|
2890
|
+
storeDuration();
|
|
2884
2891
|
});
|
|
2885
2892
|
setRequest(request);
|
|
2886
2893
|
};
|
|
2894
|
+
frameEffect(performance.now());
|
|
2887
2895
|
storeDuration();
|
|
2888
2896
|
}
|
|
2889
2897
|
|
package/lib/index.d.ts
CHANGED
|
@@ -134,7 +134,7 @@ type CreateKeycomboMatchOptions$1 = CreateKeycomboDownOptions & {
|
|
|
134
134
|
};
|
|
135
135
|
|
|
136
136
|
type KeyboardEventDescriptor = {
|
|
137
|
-
code
|
|
137
|
+
code?: string;
|
|
138
138
|
shiftKey?: boolean;
|
|
139
139
|
altKey?: boolean;
|
|
140
140
|
ctrlKey?: boolean;
|
|
@@ -638,14 +638,14 @@ type GraphTreeTransform<Id extends string, Transformed> = (tree: GraphTree<Id>)
|
|
|
638
638
|
*/
|
|
639
639
|
declare function createFind<Id extends string>(node: GraphNode<Id>): GraphTreeTransform<Id, GraphTreeNode<Id>>;
|
|
640
640
|
|
|
641
|
-
type
|
|
641
|
+
type KeyboardEventDescriptorTransform<Transformed> = (descriptor: KeyboardEventDescriptor) => Transformed;
|
|
642
642
|
type CreateKeycomboMatchOptions = Omit<CreateKeycomboMatchOptions$1, 'toAliases'> & {
|
|
643
643
|
toAliases?: (descriptor: KeyboardEventDescriptor) => string[];
|
|
644
644
|
};
|
|
645
645
|
/**
|
|
646
646
|
* [Docs](https://baleada.dev/docs/logic/pipes/keycombo-match)
|
|
647
647
|
*/
|
|
648
|
-
declare const createKeycomboMatch: (keycombo: string, options?: CreateKeycomboMatchOptions) =>
|
|
648
|
+
declare const createKeycomboMatch: (keycombo: string, options?: CreateKeycomboMatchOptions) => KeyboardEventDescriptorTransform<boolean>;
|
|
649
649
|
|
|
650
650
|
type NumberTransform<Transformed> = (number: number) => Transformed;
|
|
651
651
|
/**
|
package/lib/index.js
CHANGED
|
@@ -1798,6 +1798,7 @@ function createLayers$1(options = {}) {
|
|
|
1798
1798
|
yield layers[depth - 1];
|
|
1799
1799
|
(layers[depth] || (layers[depth] = [])).push(node);
|
|
1800
1800
|
}
|
|
1801
|
+
yield layers.at(-1);
|
|
1801
1802
|
};
|
|
1802
1803
|
}
|
|
1803
1804
|
function createTree$2(options = {}) {
|
|
@@ -2218,22 +2219,23 @@ const createKeycomboMatch$1 = (keycombo, options = {}) => {
|
|
|
2218
2219
|
}
|
|
2219
2220
|
return implicitModifierAliases2;
|
|
2220
2221
|
})();
|
|
2221
|
-
return (
|
|
2222
|
+
return (descriptor) => {
|
|
2222
2223
|
const statuses = [];
|
|
2223
|
-
|
|
2224
|
+
if (descriptor.code)
|
|
2225
|
+
createSet(fromEventToKeyStatusCode(descriptor), "down")(statuses);
|
|
2224
2226
|
for (const modifier of modifiers) {
|
|
2225
2227
|
const prefix = modifier === "Control" ? "ctrl" : modifier.toLowerCase();
|
|
2226
|
-
if (
|
|
2228
|
+
if (descriptor[`${prefix}Key`])
|
|
2227
2229
|
createSet(modifier, "down")(statuses);
|
|
2228
2230
|
}
|
|
2229
|
-
const
|
|
2231
|
+
const descriptors = createMap(
|
|
2230
2232
|
([code]) => {
|
|
2231
|
-
const
|
|
2233
|
+
const newDescriptor = { code };
|
|
2232
2234
|
for (const modifier of modifiers) {
|
|
2233
2235
|
const prefix = modifier === "Control" ? "ctrl" : modifier.toLowerCase();
|
|
2234
|
-
|
|
2236
|
+
newDescriptor[`${prefix}Key`] = descriptor[`${prefix}Key`];
|
|
2235
2237
|
}
|
|
2236
|
-
return
|
|
2238
|
+
return newDescriptor;
|
|
2237
2239
|
}
|
|
2238
2240
|
)(statuses);
|
|
2239
2241
|
return every(
|
|
@@ -2242,7 +2244,7 @@ const createKeycomboMatch$1 = (keycombo, options = {}) => {
|
|
|
2242
2244
|
{ predicateKey: createCode(code) }
|
|
2243
2245
|
)(statuses) === "down"
|
|
2244
2246
|
)(codes) && every(
|
|
2245
|
-
(
|
|
2247
|
+
(d) => pipe(
|
|
2246
2248
|
fromDescriptorToAliases,
|
|
2247
2249
|
map(fromComboToAliases),
|
|
2248
2250
|
some(
|
|
@@ -2250,8 +2252,8 @@ const createKeycomboMatch$1 = (keycombo, options = {}) => {
|
|
|
2250
2252
|
(longhandAlias) => includes(longhandAlias)(aliases) || includes(longhandAlias)(implicitModifierAliases)
|
|
2251
2253
|
)(longhandAliases)
|
|
2252
2254
|
)
|
|
2253
|
-
)(
|
|
2254
|
-
)(
|
|
2255
|
+
)(d)
|
|
2256
|
+
)(descriptors);
|
|
2255
2257
|
};
|
|
2256
2258
|
};
|
|
2257
2259
|
|
|
@@ -2483,13 +2485,13 @@ const createKeycomboDown = (keycombo, options = {}) => {
|
|
|
2483
2485
|
)(codes);
|
|
2484
2486
|
};
|
|
2485
2487
|
|
|
2486
|
-
function fromKeyboardEventDescriptorToAliases(
|
|
2487
|
-
if (
|
|
2488
|
-
return [aliasesByShiftCode[
|
|
2489
|
-
const withoutModifierSide = toWithoutModifierSide(
|
|
2488
|
+
function fromKeyboardEventDescriptorToAliases(descriptor) {
|
|
2489
|
+
if (descriptor.shiftKey && descriptor.code in aliasesByShiftCode)
|
|
2490
|
+
return [aliasesByShiftCode[descriptor.code]];
|
|
2491
|
+
const withoutModifierSide = toWithoutModifierSide(descriptor.code);
|
|
2490
2492
|
if (withoutModifierSide in aliasListsByModifier)
|
|
2491
2493
|
return aliasListsByModifier[withoutModifierSide];
|
|
2492
|
-
return
|
|
2494
|
+
return descriptor.code in aliasesByCode ? [aliasesByCode[descriptor.code]] : [descriptor.code.match(aliasCaptureRE)?.[1].toLowerCase() || "unsupported"];
|
|
2493
2495
|
}
|
|
2494
2496
|
const toWithoutModifierSide = createClip(/(?:Left|Right)$/);
|
|
2495
2497
|
const aliasCaptureRE = /^(?:Digit|Key)?(F[0-9]{1,2}|[0-9]|[A-Z])$/;
|
|
@@ -2751,21 +2753,24 @@ function storeKeyboardTimeMetadata({
|
|
|
2751
2753
|
timeMetadata.times = createClone()(initialMetadata$3.times);
|
|
2752
2754
|
timeMetadata.times.start = Math.round(event.timeStamp);
|
|
2753
2755
|
timeMetadata.times.end = Math.round(event.timeStamp);
|
|
2754
|
-
const
|
|
2756
|
+
const frameEffect = (timestamp) => {
|
|
2757
|
+
timeMetadata.times.end = Math.round(timestamp);
|
|
2758
|
+
timeMetadata.duration = Math.max(0, timeMetadata.times.end - timeMetadata.times.start);
|
|
2759
|
+
if (recognize) {
|
|
2760
|
+
recognize(event, api);
|
|
2761
|
+
if (getStatus() === "recognized")
|
|
2762
|
+
effect(event);
|
|
2763
|
+
}
|
|
2764
|
+
}, storeDuration = () => {
|
|
2755
2765
|
const request = requestAnimationFrame((timestamp) => {
|
|
2756
2766
|
if (!getShouldStore())
|
|
2757
2767
|
return;
|
|
2758
|
-
|
|
2759
|
-
timeMetadata.duration = Math.max(0, timeMetadata.times.end - timeMetadata.times.start);
|
|
2760
|
-
if (recognize) {
|
|
2761
|
-
recognize(event, api);
|
|
2762
|
-
if (getStatus() === "recognized")
|
|
2763
|
-
effect(event);
|
|
2764
|
-
}
|
|
2768
|
+
frameEffect(timestamp);
|
|
2765
2769
|
storeDuration();
|
|
2766
2770
|
});
|
|
2767
2771
|
setRequest(request);
|
|
2768
2772
|
};
|
|
2773
|
+
frameEffect(performance.now());
|
|
2769
2774
|
storeDuration();
|
|
2770
2775
|
}
|
|
2771
2776
|
|
|
@@ -2865,23 +2870,26 @@ function storePointerTimeMetadata(event, api, getShouldStore, setRequest, recogn
|
|
|
2865
2870
|
metadata.times.start = Math.round(event.timeStamp);
|
|
2866
2871
|
metadata.times.end = Math.round(event.timeStamp);
|
|
2867
2872
|
let previousTime = metadata.times.start;
|
|
2868
|
-
const
|
|
2873
|
+
const frameEffect = (timestamp) => {
|
|
2874
|
+
previousTime = metadata.times.end;
|
|
2875
|
+
metadata.times.end = Math.round(timestamp);
|
|
2876
|
+
metadata.duration = Math.max(0, metadata.times.end - metadata.times.start);
|
|
2877
|
+
const durationFromPrevious = Math.max(0, metadata.times.end - previousTime);
|
|
2878
|
+
metadata.velocity = metadata.distance.straight.fromPrevious / durationFromPrevious || 0;
|
|
2879
|
+
const event2 = getSequence().at(-1);
|
|
2880
|
+
recognize?.(event2, api);
|
|
2881
|
+
if (getStatus() === "recognized")
|
|
2882
|
+
effect(event2);
|
|
2883
|
+
}, storeDuration = () => {
|
|
2869
2884
|
const request = requestAnimationFrame((timestamp) => {
|
|
2870
|
-
if (getShouldStore())
|
|
2871
|
-
|
|
2872
|
-
|
|
2873
|
-
|
|
2874
|
-
const durationFromPrevious = Math.max(0, metadata.times.end - previousTime);
|
|
2875
|
-
metadata.velocity = metadata.distance.straight.fromPrevious / durationFromPrevious;
|
|
2876
|
-
const event2 = getSequence().at(-1);
|
|
2877
|
-
recognize?.(event2, api);
|
|
2878
|
-
if (getStatus() === "recognized")
|
|
2879
|
-
effect(event2);
|
|
2880
|
-
storeDuration();
|
|
2881
|
-
}
|
|
2885
|
+
if (!getShouldStore())
|
|
2886
|
+
return;
|
|
2887
|
+
frameEffect(timestamp);
|
|
2888
|
+
storeDuration();
|
|
2882
2889
|
});
|
|
2883
2890
|
setRequest(request);
|
|
2884
2891
|
};
|
|
2892
|
+
frameEffect(performance.now());
|
|
2885
2893
|
storeDuration();
|
|
2886
2894
|
}
|
|
2887
2895
|
|