@rootnative/inertia 0.0.0-alpha.2 → 0.0.0-alpha.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.
@@ -1,52 +1,10 @@
1
1
  'use strict';
2
2
 
3
+ var chunkSFRNO6AW_js = require('../chunk-SFRNO6AW.js');
3
4
  var react = require('react');
4
5
  var reactNative = require('react-native');
5
6
  var reactNativeReanimated = require('react-native-reanimated');
6
7
 
7
- // src/touch/useTouchDrag.ts
8
-
9
- // src/transitions/spring.ts
10
- var DEFAULT_SPRING = {
11
- tension: 170,
12
- friction: 26,
13
- mass: 1
14
- };
15
- function springToReanimated(t) {
16
- "worklet";
17
- return {
18
- stiffness: t.tension ?? DEFAULT_SPRING.tension,
19
- damping: t.friction ?? DEFAULT_SPRING.friction,
20
- mass: t.mass ?? DEFAULT_SPRING.mass,
21
- velocity: t.velocity,
22
- restSpeedThreshold: t.restSpeedThreshold,
23
- restDisplacementThreshold: t.restDisplacementThreshold
24
- };
25
- }
26
- var DEFAULT_TIMING_DURATION = 250;
27
- function buildReleaseAnimation(transition, toValue) {
28
- "worklet";
29
- if (transition.type === "no-animation") return toValue;
30
- if (transition.type === "decay") {
31
- const cfg = { velocity: transition.velocity ?? 0 };
32
- if (transition.deceleration !== void 0) {
33
- cfg.deceleration = transition.deceleration;
34
- }
35
- if (transition.clamp !== void 0) cfg.clamp = transition.clamp;
36
- return reactNativeReanimated.withDecay(cfg);
37
- }
38
- if (transition.type === "timing") {
39
- const e = transition.easing;
40
- const easingFn = e && typeof e === "object" && "factory" in e ? e.factory() : e ?? reactNativeReanimated.Easing.inOut(reactNativeReanimated.Easing.ease);
41
- return reactNativeReanimated.withTiming(toValue, {
42
- duration: transition.duration ?? DEFAULT_TIMING_DURATION,
43
- easing: easingFn
44
- });
45
- }
46
- return reactNativeReanimated.withSpring(toValue, springToReanimated(transition));
47
- }
48
-
49
- // src/touch/useTouchDrag.ts
50
8
  function useTouchDrag(options = {}) {
51
9
  const { axis = "both", constraints, elastic = 0 } = options;
52
10
  const dragX = reactNativeReanimated.useSharedValue(0);
@@ -90,14 +48,14 @@ function useTouchDrag(options = {}) {
90
48
  if (result) {
91
49
  if (result.x && lockX) {
92
50
  const toX = "to" in result.x ? result.x.to : x;
93
- dragX.value = buildReleaseAnimation(
51
+ dragX.value = chunkSFRNO6AW_js.buildReleaseAnimation(
94
52
  result.x,
95
53
  toX
96
54
  );
97
55
  }
98
56
  if (result.y && lockY) {
99
57
  const toY = "to" in result.y ? result.y.to : y;
100
- dragY.value = buildReleaseAnimation(
58
+ dragY.value = chunkSFRNO6AW_js.buildReleaseAnimation(
101
59
  result.y,
102
60
  toY
103
61
  );
@@ -1,50 +1,8 @@
1
+ import { buildReleaseAnimation } from '../chunk-6FENLMCA.mjs';
1
2
  import { useMemo } from 'react';
2
3
  import { PanResponder } from 'react-native';
3
- import { useSharedValue, useAnimatedStyle, withDecay, Easing, withTiming, withSpring } from 'react-native-reanimated';
4
+ import { useSharedValue, useAnimatedStyle } from 'react-native-reanimated';
4
5
 
5
- // src/touch/useTouchDrag.ts
6
-
7
- // src/transitions/spring.ts
8
- var DEFAULT_SPRING = {
9
- tension: 170,
10
- friction: 26,
11
- mass: 1
12
- };
13
- function springToReanimated(t) {
14
- "worklet";
15
- return {
16
- stiffness: t.tension ?? DEFAULT_SPRING.tension,
17
- damping: t.friction ?? DEFAULT_SPRING.friction,
18
- mass: t.mass ?? DEFAULT_SPRING.mass,
19
- velocity: t.velocity,
20
- restSpeedThreshold: t.restSpeedThreshold,
21
- restDisplacementThreshold: t.restDisplacementThreshold
22
- };
23
- }
24
- var DEFAULT_TIMING_DURATION = 250;
25
- function buildReleaseAnimation(transition, toValue) {
26
- "worklet";
27
- if (transition.type === "no-animation") return toValue;
28
- if (transition.type === "decay") {
29
- const cfg = { velocity: transition.velocity ?? 0 };
30
- if (transition.deceleration !== void 0) {
31
- cfg.deceleration = transition.deceleration;
32
- }
33
- if (transition.clamp !== void 0) cfg.clamp = transition.clamp;
34
- return withDecay(cfg);
35
- }
36
- if (transition.type === "timing") {
37
- const e = transition.easing;
38
- const easingFn = e && typeof e === "object" && "factory" in e ? e.factory() : e ?? Easing.inOut(Easing.ease);
39
- return withTiming(toValue, {
40
- duration: transition.duration ?? DEFAULT_TIMING_DURATION,
41
- easing: easingFn
42
- });
43
- }
44
- return withSpring(toValue, springToReanimated(transition));
45
- }
46
-
47
- // src/touch/useTouchDrag.ts
48
6
  function useTouchDrag(options = {}) {
49
7
  const { axis = "both", constraints, elastic = 0 } = options;
50
8
  const dragX = useSharedValue(0);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rootnative/inertia",
3
- "version": "0.0.0-alpha.2",
3
+ "version": "0.0.0-alpha.4",
4
4
  "description": "Declarative animation primitives for React Native, built on react-native-reanimated.",
5
5
  "license": "MIT",
6
6
  "author": "RootNative",
@@ -12,10 +12,15 @@ import { Platform } from 'react-native'
12
12
  * arrives via D-pad, screen reader, or hardware keyboard, all of which are
13
13
  * keyboard-equivalent — so `isFocusVisible()` is unconditionally `true`.
14
14
  *
15
- * The web listeners attach lazily on first call (capture phase, so they run
16
- * before the focus event reaches the focused element) and stay installed for
17
- * the lifetime of the document. They are passive and idle-cheap; the cost is
18
- * one boolean read per `onFocus` dispatch.
15
+ * The web listeners attach eagerly at module import (capture phase, so they
16
+ * run before the focus event reaches the focused element) and stay installed
17
+ * for the lifetime of the document. Eager installation matters: the very
18
+ * first interaction with a page can be the mouse click that focuses a
19
+ * gesture-wired element, and if the listeners only attached during that
20
+ * focus dispatch the mousedown would already have passed unobserved —
21
+ * leaving the default `'keyboard'` modality and drawing a focus ring for a
22
+ * pointer interaction. They are passive and idle-cheap; the cost is one
23
+ * boolean read per `onFocus` dispatch.
19
24
  */
20
25
 
21
26
  type InputModality = 'keyboard' | 'pointer'
@@ -44,6 +49,12 @@ function ensureInstalled(): void {
44
49
  installed = true
45
50
  }
46
51
 
52
+ // Install at import time so the pointer event that precedes the first focus
53
+ // is observed (see module doc above). `ensureInstalled` stays in
54
+ // `isFocusVisible` as a safety net for environments where `document` appears
55
+ // after import.
56
+ ensureInstalled()
57
+
47
58
  /**
48
59
  * `true` if the next `onFocus` should be treated as "focus-visible" (keyboard
49
60
  * focus). On native, always `true`. On web, reflects the most recent user