@baleada/logic 0.24.5 → 0.24.6

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.
Files changed (3) hide show
  1. package/lib/index.cjs +27 -21
  2. package/lib/index.js +27 -21
  3. package/package.json +1 -1
package/lib/index.cjs CHANGED
@@ -2753,21 +2753,24 @@ function storeKeyboardTimeMetadata({
2753
2753
  timeMetadata.times = createClone()(initialMetadata$3.times);
2754
2754
  timeMetadata.times.start = Math.round(event.timeStamp);
2755
2755
  timeMetadata.times.end = Math.round(event.timeStamp);
2756
- const storeDuration = () => {
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 = () => {
2757
2765
  const request = requestAnimationFrame((timestamp) => {
2758
2766
  if (!getShouldStore())
2759
2767
  return;
2760
- timeMetadata.times.end = Math.round(timestamp);
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
- }
2768
+ frameEffect(timestamp);
2767
2769
  storeDuration();
2768
2770
  });
2769
2771
  setRequest(request);
2770
2772
  };
2773
+ frameEffect(performance.now());
2771
2774
  storeDuration();
2772
2775
  }
2773
2776
 
@@ -2867,23 +2870,26 @@ function storePointerTimeMetadata(event, api, getShouldStore, setRequest, recogn
2867
2870
  metadata.times.start = Math.round(event.timeStamp);
2868
2871
  metadata.times.end = Math.round(event.timeStamp);
2869
2872
  let previousTime = metadata.times.start;
2870
- const storeDuration = () => {
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 = () => {
2871
2884
  const request = requestAnimationFrame((timestamp) => {
2872
- if (getShouldStore()) {
2873
- previousTime = metadata.times.end;
2874
- metadata.times.end = Math.round(timestamp);
2875
- metadata.duration = Math.max(0, metadata.times.end - metadata.times.start);
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
- }
2885
+ if (!getShouldStore())
2886
+ return;
2887
+ frameEffect(timestamp);
2888
+ storeDuration();
2884
2889
  });
2885
2890
  setRequest(request);
2886
2891
  };
2892
+ frameEffect(performance.now());
2887
2893
  storeDuration();
2888
2894
  }
2889
2895
 
package/lib/index.js CHANGED
@@ -2751,21 +2751,24 @@ function storeKeyboardTimeMetadata({
2751
2751
  timeMetadata.times = createClone()(initialMetadata$3.times);
2752
2752
  timeMetadata.times.start = Math.round(event.timeStamp);
2753
2753
  timeMetadata.times.end = Math.round(event.timeStamp);
2754
- const storeDuration = () => {
2754
+ const frameEffect = (timestamp) => {
2755
+ timeMetadata.times.end = Math.round(timestamp);
2756
+ timeMetadata.duration = Math.max(0, timeMetadata.times.end - timeMetadata.times.start);
2757
+ if (recognize) {
2758
+ recognize(event, api);
2759
+ if (getStatus() === "recognized")
2760
+ effect(event);
2761
+ }
2762
+ }, storeDuration = () => {
2755
2763
  const request = requestAnimationFrame((timestamp) => {
2756
2764
  if (!getShouldStore())
2757
2765
  return;
2758
- timeMetadata.times.end = Math.round(timestamp);
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
- }
2766
+ frameEffect(timestamp);
2765
2767
  storeDuration();
2766
2768
  });
2767
2769
  setRequest(request);
2768
2770
  };
2771
+ frameEffect(performance.now());
2769
2772
  storeDuration();
2770
2773
  }
2771
2774
 
@@ -2865,23 +2868,26 @@ function storePointerTimeMetadata(event, api, getShouldStore, setRequest, recogn
2865
2868
  metadata.times.start = Math.round(event.timeStamp);
2866
2869
  metadata.times.end = Math.round(event.timeStamp);
2867
2870
  let previousTime = metadata.times.start;
2868
- const storeDuration = () => {
2871
+ const frameEffect = (timestamp) => {
2872
+ previousTime = metadata.times.end;
2873
+ metadata.times.end = Math.round(timestamp);
2874
+ metadata.duration = Math.max(0, metadata.times.end - metadata.times.start);
2875
+ const durationFromPrevious = Math.max(0, metadata.times.end - previousTime);
2876
+ metadata.velocity = metadata.distance.straight.fromPrevious / durationFromPrevious || 0;
2877
+ const event2 = getSequence().at(-1);
2878
+ recognize?.(event2, api);
2879
+ if (getStatus() === "recognized")
2880
+ effect(event2);
2881
+ }, storeDuration = () => {
2869
2882
  const request = requestAnimationFrame((timestamp) => {
2870
- if (getShouldStore()) {
2871
- previousTime = metadata.times.end;
2872
- metadata.times.end = Math.round(timestamp);
2873
- metadata.duration = Math.max(0, metadata.times.end - metadata.times.start);
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
- }
2883
+ if (!getShouldStore())
2884
+ return;
2885
+ frameEffect(timestamp);
2886
+ storeDuration();
2882
2887
  });
2883
2888
  setRequest(request);
2884
2889
  };
2890
+ frameEffect(performance.now());
2885
2891
  storeDuration();
2886
2892
  }
2887
2893
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@baleada/logic",
3
- "version": "0.24.5",
3
+ "version": "0.24.6",
4
4
  "description": "UI logic for the Baleada toolkit",
5
5
  "main": "lib/index.cjs",
6
6
  "module": "lib/index.js",