@rootnative/inertia 0.0.0-alpha.1 → 0.0.0-alpha.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.
Files changed (64) hide show
  1. package/CHANGELOG.md +15 -1
  2. package/dist/chunk-5RCMIJGZ.js +8 -0
  3. package/dist/chunk-6FENLMCA.mjs +257 -0
  4. package/dist/chunk-E4MDU4YV.mjs +6 -0
  5. package/dist/chunk-FSPQVLBF.mjs +6 -0
  6. package/dist/chunk-GJD4VVAS.mjs +103 -0
  7. package/dist/chunk-JWHKMNYA.js +112 -0
  8. package/dist/chunk-K7ICHCTZ.js +54 -0
  9. package/dist/chunk-KARV7QKF.mjs +6 -0
  10. package/dist/chunk-KVSJWO5X.js +1011 -0
  11. package/dist/chunk-NJYRN3WG.js +8 -0
  12. package/dist/chunk-R3ODWDTI.js +8 -0
  13. package/dist/chunk-RJNR7CFN.mjs +6 -0
  14. package/dist/chunk-S4AEU72O.js +8 -0
  15. package/dist/chunk-SFRNO6AW.js +267 -0
  16. package/dist/chunk-UM3WVSKQ.mjs +6 -0
  17. package/dist/chunk-UMFBAFZP.js +8 -0
  18. package/dist/chunk-UXK4YCT6.mjs +1003 -0
  19. package/dist/chunk-W6IS4HAK.mjs +52 -0
  20. package/dist/gestureLayer/index.d.mts +42 -2
  21. package/dist/gestureLayer/index.d.ts +42 -2
  22. package/dist/gestureLayer/index.js +28 -275
  23. package/dist/gestureLayer/index.mjs +23 -270
  24. package/dist/index.js +122 -1459
  25. package/dist/index.mjs +19 -1402
  26. package/dist/motion/Image.js +8 -1175
  27. package/dist/motion/Image.mjs +4 -1174
  28. package/dist/motion/Pressable.js +8 -1175
  29. package/dist/motion/Pressable.mjs +4 -1174
  30. package/dist/motion/ScrollView.js +8 -1175
  31. package/dist/motion/ScrollView.mjs +4 -1174
  32. package/dist/motion/Text.js +8 -1175
  33. package/dist/motion/Text.mjs +4 -1174
  34. package/dist/motion/View.js +8 -1175
  35. package/dist/motion/View.mjs +4 -1174
  36. package/dist/testing/index.js +0 -2
  37. package/dist/testing/index.mjs +0 -2
  38. package/dist/touch/index.js +3 -47
  39. package/dist/touch/index.mjs +2 -46
  40. package/llms.txt +2 -2
  41. package/package.json +2 -1
  42. package/src/gestureLayer/index.ts +1 -0
  43. package/src/gestureLayer/useGestureLayer.ts +60 -0
  44. package/dist/gestureLayer/index.js.map +0 -1
  45. package/dist/gestureLayer/index.mjs.map +0 -1
  46. package/dist/index.js.map +0 -1
  47. package/dist/index.mjs.map +0 -1
  48. package/dist/motion/Image.js.map +0 -1
  49. package/dist/motion/Image.mjs.map +0 -1
  50. package/dist/motion/Pressable.js.map +0 -1
  51. package/dist/motion/Pressable.mjs.map +0 -1
  52. package/dist/motion/ScrollView.js.map +0 -1
  53. package/dist/motion/ScrollView.mjs.map +0 -1
  54. package/dist/motion/Text.js.map +0 -1
  55. package/dist/motion/Text.mjs.map +0 -1
  56. package/dist/motion/View.js.map +0 -1
  57. package/dist/motion/View.mjs.map +0 -1
  58. package/dist/testing/index.js.map +0 -1
  59. package/dist/testing/index.mjs.map +0 -1
  60. package/dist/touch/index.js.map +0 -1
  61. package/dist/touch/index.mjs.map +0 -1
  62. package/src/__type-tests__/animate.test-d.tsx +0 -88
  63. package/src/__type-tests__/motion-value.test-d.ts +0 -39
  64. package/src/__type-tests__/variants.test-d.tsx +0 -67
@@ -1,271 +1,9 @@
1
- import { createContext, useEffect, useMemo, useCallback, useContext } from 'react';
2
- import { useSharedValue, useAnimatedStyle, interpolateColor, useReducedMotion, withRepeat, withDelay, withDecay, withTiming, Easing, withSpring } from 'react-native-reanimated';
3
- import { isWorkletFunction } from 'react-native-worklets';
4
- import { Platform } from 'react-native';
1
+ import { useGesture } from '../chunk-W6IS4HAK.mjs';
2
+ import { useShouldReduceMotion, resolveNamedTransitionProp, useNamedTransitions } from '../chunk-GJD4VVAS.mjs';
3
+ import { stableSig, resolveTransition, isTopLevelTransition } from '../chunk-6FENLMCA.mjs';
4
+ import { useEffect, useMemo } from 'react';
5
+ import { useSharedValue, useAnimatedStyle, interpolateColor } from 'react-native-reanimated';
5
6
 
6
- // src/gestureLayer/useGestureLayer.ts
7
-
8
- // src/transitions/sig.ts
9
- function stableSig(value) {
10
- if (value === void 0) return "";
11
- try {
12
- return stableStringify(value);
13
- } catch {
14
- return String(value);
15
- }
16
- }
17
- function stableStringify(v) {
18
- if (v === null || typeof v !== "object") {
19
- if (typeof v === "function" || v === void 0) return "null";
20
- return JSON.stringify(v);
21
- }
22
- if (Array.isArray(v)) {
23
- return "[" + v.map(stableStringify).join(",") + "]";
24
- }
25
- const obj = v;
26
- const keys = Object.keys(obj).sort();
27
- return "{" + keys.map((k) => JSON.stringify(k) + ":" + stableStringify(obj[k])).join(",") + "}";
28
- }
29
- var DEFAULT_MOTION_CONFIG = {
30
- reducedMotion: "user",
31
- transitions: {}
32
- };
33
- var MotionConfigContext = createContext(
34
- DEFAULT_MOTION_CONFIG
35
- );
36
- function useMotionConfig() {
37
- return useContext(MotionConfigContext);
38
- }
39
- function useNamedTransitions() {
40
- return useMotionConfig().transitions;
41
- }
42
- function useShouldReduceMotion() {
43
- const { reducedMotion } = useMotionConfig();
44
- const osReduced = useReducedMotion();
45
- if (reducedMotion === "never") return false;
46
- if (reducedMotion === "always") return true;
47
- return osReduced;
48
- }
49
-
50
- // src/transitions/keys.ts
51
- var TRANSITION_CONFIG_KEYS = /* @__PURE__ */ new Set([
52
- "type",
53
- "tension",
54
- "friction",
55
- "mass",
56
- "velocity",
57
- "restSpeedThreshold",
58
- "restDisplacementThreshold",
59
- "duration",
60
- "easing",
61
- "delay",
62
- "repeat",
63
- "deceleration",
64
- "clamp"
65
- ]);
66
- function isTopLevelTransition(t) {
67
- if (t === null || typeof t !== "object") return false;
68
- const keys = Object.keys(t);
69
- if (keys.length === 0) return false;
70
- return keys.every((k) => TRANSITION_CONFIG_KEYS.has(k));
71
- }
72
-
73
- // src/config/namedTransitions.ts
74
- var UNKNOWN_NAME_FALLBACK = { type: "spring" };
75
- function lookupNamedTransition(name, registry) {
76
- const cfg = registry[name];
77
- if (cfg) return cfg;
78
- if (__DEV__) {
79
- console.warn(
80
- `[inertia] Unknown transition name "${name}" \u2014 falling back to the default spring. Register it on a provider: <MotionConfig transitions={{ '${name}': { ... } }}>.`
81
- );
82
- }
83
- return UNKNOWN_NAME_FALLBACK;
84
- }
85
- function resolveNamedTransitionProp(transition, registry) {
86
- if (transition === void 0) return void 0;
87
- if (typeof transition === "string") {
88
- return lookupNamedTransition(transition, registry);
89
- }
90
- if (isTopLevelTransition(transition)) return transition;
91
- const map = transition;
92
- let out = null;
93
- for (const key in map) {
94
- const value = map[key];
95
- if (typeof value === "string") {
96
- if (out === null) out = { ...map };
97
- out[key] = lookupNamedTransition(value, registry);
98
- }
99
- }
100
- return out ?? transition;
101
- }
102
- function ensureWorkletEasing(easing) {
103
- if (!easing) return void 0;
104
- const fn = isEasingFactory(easing) ? easing.factory() : easing;
105
- if (isWorkletFunction(fn)) return fn;
106
- const wrapped = (t) => {
107
- "worklet";
108
- return fn(t);
109
- };
110
- return wrapped;
111
- }
112
- function isEasingFactory(value) {
113
- return typeof value === "object" && value !== null && "factory" in value && typeof value.factory === "function";
114
- }
115
-
116
- // src/transitions/spring.ts
117
- var DEFAULT_SPRING = {
118
- tension: 170,
119
- friction: 26,
120
- mass: 1
121
- };
122
- function springToReanimated(t) {
123
- "worklet";
124
- return {
125
- stiffness: t.tension ?? DEFAULT_SPRING.tension,
126
- damping: t.friction ?? DEFAULT_SPRING.friction,
127
- mass: t.mass ?? DEFAULT_SPRING.mass,
128
- velocity: t.velocity,
129
- restSpeedThreshold: t.restSpeedThreshold,
130
- restDisplacementThreshold: t.restDisplacementThreshold
131
- };
132
- }
133
-
134
- // src/transitions/resolve.ts
135
- var DEFAULT_TIMING_DURATION = 250;
136
- function buildSpring(cfg, toValue, cb) {
137
- return withSpring(toValue, springToReanimated(cfg), cb);
138
- }
139
- function buildTiming(cfg, toValue, cb) {
140
- return withTiming(
141
- toValue,
142
- {
143
- duration: cfg.duration ?? DEFAULT_TIMING_DURATION,
144
- easing: ensureWorkletEasing(cfg.easing) ?? Easing.inOut(Easing.ease)
145
- },
146
- cb
147
- );
148
- }
149
- function buildDecay(cfg, cb) {
150
- return withDecay(
151
- {
152
- velocity: cfg.velocity ?? 0,
153
- deceleration: cfg.deceleration,
154
- clamp: cfg.clamp
155
- },
156
- cb
157
- );
158
- }
159
- function buildOne(cfg, toValue, cb) {
160
- if (cfg.type === "no-animation") {
161
- return toValue;
162
- }
163
- if (cfg.type === "decay") return buildDecay(cfg, cb);
164
- if (cfg.type === "timing") return buildTiming(cfg, toValue, cb);
165
- return buildSpring(cfg, toValue, cb);
166
- }
167
- function applyRepeat(animation, repeat) {
168
- if (repeat === void 0) return animation;
169
- if (repeat === "infinite") {
170
- return withRepeat(animation, -1, true);
171
- }
172
- if (typeof repeat === "number") {
173
- return withRepeat(animation, repeat, true);
174
- }
175
- const count = repeat.count === "infinite" ? -1 : repeat.count;
176
- const alternate = repeat.alternate ?? true;
177
- return withRepeat(animation, count, alternate);
178
- }
179
- function applyDelay(animation, delay) {
180
- if (!delay || delay <= 0) return animation;
181
- return withDelay(delay, animation);
182
- }
183
- function resolveTransition(config, toValue, callback) {
184
- const cfg = config ?? { type: "spring" };
185
- const base = buildOne(cfg, toValue, callback);
186
- const repeated = applyRepeat(base, repeatOf(cfg));
187
- return applyDelay(repeated, delayOf(cfg));
188
- }
189
- function repeatOf(cfg) {
190
- if (cfg.type === "no-animation" || cfg.type === "decay") return void 0;
191
- return cfg.repeat;
192
- }
193
- function delayOf(cfg) {
194
- if (cfg.type === "no-animation") return void 0;
195
- return cfg.delay;
196
- }
197
- var modality = "keyboard";
198
- var installed = false;
199
- function setKeyboard() {
200
- modality = "keyboard";
201
- }
202
- function setPointer() {
203
- modality = "pointer";
204
- }
205
- function ensureInstalled() {
206
- if (installed) return;
207
- if (Platform.OS !== "web") return;
208
- if (typeof document === "undefined") return;
209
- document.addEventListener("keydown", setKeyboard, true);
210
- document.addEventListener("mousedown", setPointer, true);
211
- document.addEventListener("pointerdown", setPointer, true);
212
- document.addEventListener("touchstart", setPointer, true);
213
- installed = true;
214
- }
215
- function isFocusVisible() {
216
- if (Platform.OS !== "web") return true;
217
- ensureInstalled();
218
- return modality === "keyboard";
219
- }
220
-
221
- // src/values/useGesture.ts
222
- function useGesture(transition) {
223
- const pressed = useSharedValue(0);
224
- const focused = useSharedValue(0);
225
- const focusVisible = useSharedValue(0);
226
- const hovered = useSharedValue(0);
227
- const shouldReduceMotion = useShouldReduceMotion();
228
- const resolved = resolveNamedTransitionProp(transition, useNamedTransitions());
229
- const setLayer = useCallback(
230
- (sv, layer, target) => {
231
- const cfg = shouldReduceMotion ? { type: "no-animation" } : layerTransition(layer, resolved) ?? { type: "spring" };
232
- sv.value = resolveTransition(cfg, target);
233
- },
234
- // The transition is intentionally read on every call rather than cooked
235
- // into the dep array — a fresh literal each render would otherwise
236
- // rebuild the handler bag and break composing consumers that key off
237
- // handler identity. `transition` is read inside the callback closure;
238
- // shared values are stable so the only dep that matters is the reduce-
239
- // motion flag.
240
- // eslint-disable-next-line react-hooks/exhaustive-deps
241
- [shouldReduceMotion]
242
- );
243
- const handlers = useMemo(
244
- () => ({
245
- onPressIn: () => setLayer(pressed, "pressed", 1),
246
- onPressOut: () => setLayer(pressed, "pressed", 0),
247
- onHoverIn: () => setLayer(hovered, "hovered", 1),
248
- onHoverOut: () => setLayer(hovered, "hovered", 0),
249
- onFocus: () => {
250
- setLayer(focused, "focused", 1);
251
- if (isFocusVisible()) setLayer(focusVisible, "focusVisible", 1);
252
- },
253
- onBlur: () => {
254
- setLayer(focused, "focused", 0);
255
- setLayer(focusVisible, "focusVisible", 0);
256
- }
257
- }),
258
- [setLayer, pressed, focused, focusVisible, hovered]
259
- );
260
- return { pressed, focused, focusVisible, hovered, handlers };
261
- }
262
- function layerTransition(layer, transition) {
263
- if (!transition) return void 0;
264
- if (isTopLevelTransition(transition)) return transition;
265
- return transition[layer];
266
- }
267
-
268
- // src/gestureLayer/useGestureLayer.ts
269
7
  function useGestureLayer(states, options = {}) {
270
8
  const { disabled: isDisabled = false, transition: transitionInput } = options;
271
9
  const shouldReduceMotion = useShouldReduceMotion();
@@ -390,9 +128,26 @@ function useGestureLayer(states, options = {}) {
390
128
  }
391
129
  return out;
392
130
  });
131
+ const progress = useMemo(
132
+ () => ({
133
+ hovered: gesture.hovered,
134
+ focused: gesture.focused,
135
+ focusVisible: gesture.focusVisible,
136
+ pressed: gesture.pressed,
137
+ disabled: disabledProgress
138
+ }),
139
+ [
140
+ gesture.hovered,
141
+ gesture.focused,
142
+ gesture.focusVisible,
143
+ gesture.pressed,
144
+ disabledProgress
145
+ ]
146
+ );
393
147
  return {
394
148
  style,
395
- handlers: gesture.handlers
149
+ handlers: gesture.handlers,
150
+ states: progress
396
151
  };
397
152
  }
398
153
  function disabledTransition(transition) {
@@ -402,5 +157,3 @@ function disabledTransition(transition) {
402
157
  }
403
158
 
404
159
  export { useGestureLayer };
405
- //# sourceMappingURL=index.mjs.map
406
- //# sourceMappingURL=index.mjs.map