@rootnative/inertia 0.0.0-alpha.0

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 (113) hide show
  1. package/CHANGELOG.md +33 -0
  2. package/LICENSE +21 -0
  3. package/README.md +131 -0
  4. package/dist/gestureLayer/index.d.mts +119 -0
  5. package/dist/gestureLayer/index.d.ts +119 -0
  6. package/dist/gestureLayer/index.js +346 -0
  7. package/dist/gestureLayer/index.js.map +1 -0
  8. package/dist/gestureLayer/index.mjs +344 -0
  9. package/dist/gestureLayer/index.mjs.map +1 -0
  10. package/dist/index.d.mts +507 -0
  11. package/dist/index.d.ts +507 -0
  12. package/dist/index.js +1546 -0
  13. package/dist/index.js.map +1 -0
  14. package/dist/index.mjs +1515 -0
  15. package/dist/index.mjs.map +1 -0
  16. package/dist/motion/Image.d.mts +12 -0
  17. package/dist/motion/Image.d.ts +12 -0
  18. package/dist/motion/Image.js +1138 -0
  19. package/dist/motion/Image.js.map +1 -0
  20. package/dist/motion/Image.mjs +1132 -0
  21. package/dist/motion/Image.mjs.map +1 -0
  22. package/dist/motion/Pressable.d.mts +15 -0
  23. package/dist/motion/Pressable.d.ts +15 -0
  24. package/dist/motion/Pressable.js +1138 -0
  25. package/dist/motion/Pressable.js.map +1 -0
  26. package/dist/motion/Pressable.mjs +1132 -0
  27. package/dist/motion/Pressable.mjs.map +1 -0
  28. package/dist/motion/ScrollView.d.mts +12 -0
  29. package/dist/motion/ScrollView.d.ts +12 -0
  30. package/dist/motion/ScrollView.js +1138 -0
  31. package/dist/motion/ScrollView.js.map +1 -0
  32. package/dist/motion/ScrollView.mjs +1132 -0
  33. package/dist/motion/ScrollView.mjs.map +1 -0
  34. package/dist/motion/Text.d.mts +11 -0
  35. package/dist/motion/Text.d.ts +11 -0
  36. package/dist/motion/Text.js +1138 -0
  37. package/dist/motion/Text.js.map +1 -0
  38. package/dist/motion/Text.mjs +1132 -0
  39. package/dist/motion/Text.mjs.map +1 -0
  40. package/dist/motion/View.d.mts +11 -0
  41. package/dist/motion/View.d.ts +11 -0
  42. package/dist/motion/View.js +1138 -0
  43. package/dist/motion/View.js.map +1 -0
  44. package/dist/motion/View.mjs +1132 -0
  45. package/dist/motion/View.mjs.map +1 -0
  46. package/dist/testing/index.d.mts +57 -0
  47. package/dist/testing/index.d.ts +57 -0
  48. package/dist/testing/index.js +19 -0
  49. package/dist/testing/index.js.map +1 -0
  50. package/dist/testing/index.mjs +16 -0
  51. package/dist/testing/index.mjs.map +1 -0
  52. package/dist/touch/index.d.mts +146 -0
  53. package/dist/touch/index.d.ts +146 -0
  54. package/dist/touch/index.js +166 -0
  55. package/dist/touch/index.js.map +1 -0
  56. package/dist/touch/index.mjs +164 -0
  57. package/dist/touch/index.mjs.map +1 -0
  58. package/dist/types-cU43dEmH.d.mts +339 -0
  59. package/dist/types-cU43dEmH.d.ts +339 -0
  60. package/dist/useGesture-BnY65PlQ.d.ts +84 -0
  61. package/dist/useGesture-DxtXdz-K.d.mts +84 -0
  62. package/jest-preset.js +33 -0
  63. package/jest-setup.js +213 -0
  64. package/llms.txt +142 -0
  65. package/package.json +151 -0
  66. package/src/__type-tests__/animate.test-d.tsx +88 -0
  67. package/src/__type-tests__/variants.test-d.tsx +67 -0
  68. package/src/config/MotionConfig.tsx +30 -0
  69. package/src/config/MotionConfigContext.ts +53 -0
  70. package/src/config/index.ts +9 -0
  71. package/src/gestureLayer/index.ts +21 -0
  72. package/src/gestureLayer/useGestureLayer.ts +285 -0
  73. package/src/gestures/focusVisibility.ts +61 -0
  74. package/src/gestures/index.ts +1 -0
  75. package/src/index.ts +72 -0
  76. package/src/layout/index.ts +16 -0
  77. package/src/layout/resolveLayout.ts +54 -0
  78. package/src/layout/sharedRegistry.ts +111 -0
  79. package/src/layout/useSharedLayout.ts +289 -0
  80. package/src/motion/Image.tsx +9 -0
  81. package/src/motion/Pressable.tsx +12 -0
  82. package/src/motion/ScrollView.tsx +9 -0
  83. package/src/motion/Text.tsx +8 -0
  84. package/src/motion/View.tsx +8 -0
  85. package/src/motion/createMotionComponent.tsx +1306 -0
  86. package/src/motion/index.ts +26 -0
  87. package/src/motion/installCheck.ts +65 -0
  88. package/src/presence/Presence.tsx +165 -0
  89. package/src/presence/PresenceContext.ts +28 -0
  90. package/src/presence/index.ts +6 -0
  91. package/src/testing/index.ts +78 -0
  92. package/src/touch/index.ts +18 -0
  93. package/src/touch/useTouchDrag.ts +289 -0
  94. package/src/transitions/easing.ts +53 -0
  95. package/src/transitions/index.ts +7 -0
  96. package/src/transitions/keys.ts +32 -0
  97. package/src/transitions/resolve.ts +169 -0
  98. package/src/transitions/resolveSequence.ts +87 -0
  99. package/src/transitions/runtime.ts +63 -0
  100. package/src/transitions/sig.ts +40 -0
  101. package/src/transitions/spring.ts +42 -0
  102. package/src/types.ts +383 -0
  103. package/src/values/index.ts +26 -0
  104. package/src/values/useAnimation.ts +69 -0
  105. package/src/values/useBooleanSpring.ts +33 -0
  106. package/src/values/useColorTransition.ts +72 -0
  107. package/src/values/useGesture.ts +144 -0
  108. package/src/values/useMotionValue.ts +33 -0
  109. package/src/values/useScroll.ts +72 -0
  110. package/src/values/useShadow.ts +116 -0
  111. package/src/values/useSpring.ts +98 -0
  112. package/src/values/useTransform.ts +132 -0
  113. package/src/values/useVariants.ts +60 -0
@@ -0,0 +1,1132 @@
1
+ import { ScrollView, Platform } from 'react-native';
2
+ import { createContext, forwardRef, useRef, useState, useEffect, useMemo, useContext, useCallback } from 'react';
3
+ import Animated, { useSharedValue, useAnimatedStyle, interpolateColor, reanimatedVersion, useReducedMotion, withSequence, LinearTransition, runOnJS, withRepeat, withTiming, withSpring, withDelay, withDecay, Easing } from 'react-native-reanimated';
4
+ import { isWorkletFunction } from 'react-native-worklets';
5
+ import { jsx } from 'react/jsx-runtime';
6
+
7
+ // src/motion/ScrollView.tsx
8
+ var DEFAULT_MOTION_CONFIG = {
9
+ reducedMotion: "user"
10
+ };
11
+ var MotionConfigContext = createContext(
12
+ DEFAULT_MOTION_CONFIG
13
+ );
14
+ function useMotionConfig() {
15
+ return useContext(MotionConfigContext);
16
+ }
17
+ function useShouldReduceMotion() {
18
+ const { reducedMotion } = useMotionConfig();
19
+ const osReduced = useReducedMotion();
20
+ if (reducedMotion === "never") return false;
21
+ if (reducedMotion === "always") return true;
22
+ return osReduced;
23
+ }
24
+ var modality = "keyboard";
25
+ var installed = false;
26
+ function setKeyboard() {
27
+ modality = "keyboard";
28
+ }
29
+ function setPointer() {
30
+ modality = "pointer";
31
+ }
32
+ function ensureInstalled() {
33
+ if (installed) return;
34
+ if (Platform.OS !== "web") return;
35
+ if (typeof document === "undefined") return;
36
+ document.addEventListener("keydown", setKeyboard, true);
37
+ document.addEventListener("mousedown", setPointer, true);
38
+ document.addEventListener("pointerdown", setPointer, true);
39
+ document.addEventListener("touchstart", setPointer, true);
40
+ installed = true;
41
+ }
42
+ function isFocusVisible() {
43
+ if (Platform.OS !== "web") return true;
44
+ ensureInstalled();
45
+ return modality === "keyboard";
46
+ }
47
+ function ensureWorkletEasing(easing) {
48
+ if (!easing) return void 0;
49
+ const fn = isEasingFactory(easing) ? easing.factory() : easing;
50
+ if (isWorkletFunction(fn)) return fn;
51
+ const wrapped = (t) => {
52
+ "worklet";
53
+ return fn(t);
54
+ };
55
+ return wrapped;
56
+ }
57
+ function isEasingFactory(value) {
58
+ return typeof value === "object" && value !== null && "factory" in value && typeof value.factory === "function";
59
+ }
60
+
61
+ // src/transitions/spring.ts
62
+ var DEFAULT_SPRING = {
63
+ tension: 170,
64
+ friction: 26,
65
+ mass: 1
66
+ };
67
+ function springToReanimated(t) {
68
+ "worklet";
69
+ return {
70
+ stiffness: t.tension ?? DEFAULT_SPRING.tension,
71
+ damping: t.friction ?? DEFAULT_SPRING.friction,
72
+ mass: t.mass ?? DEFAULT_SPRING.mass,
73
+ velocity: t.velocity,
74
+ restSpeedThreshold: t.restSpeedThreshold,
75
+ restDisplacementThreshold: t.restDisplacementThreshold
76
+ };
77
+ }
78
+
79
+ // src/layout/resolveLayout.ts
80
+ function resolveLayoutTransition(layout) {
81
+ if (!layout) return void 0;
82
+ const cfg = layout === true ? { type: "spring" } : layout;
83
+ if (cfg.type === "no-animation") return void 0;
84
+ if (cfg.type === "timing") {
85
+ let builder2 = LinearTransition.duration(cfg.duration ?? 300);
86
+ const easing = ensureWorkletEasing(cfg.easing);
87
+ if (easing) builder2 = builder2.easing(easing);
88
+ if (cfg.delay) builder2 = builder2.delay(cfg.delay);
89
+ return builder2;
90
+ }
91
+ const spring = cfg.type === "decay" ? { type: "spring" } : cfg;
92
+ const { stiffness, damping, mass } = springToReanimated({
93
+ ...DEFAULT_SPRING,
94
+ ...spring
95
+ });
96
+ let builder = LinearTransition.springify().stiffness(stiffness).damping(damping).mass(mass);
97
+ if ("delay" in spring && spring.delay) builder = builder.delay(spring.delay);
98
+ return builder;
99
+ }
100
+
101
+ // src/layout/sharedRegistry.ts
102
+ var REGISTRY = /* @__PURE__ */ new Map();
103
+ var SHARED_LAYOUT_TTL_MS = 1e3;
104
+ var now = () => Date.now();
105
+ function registerLayout(id, rect) {
106
+ REGISTRY.set(id, { rect, expiresAt: now() + SHARED_LAYOUT_TTL_MS });
107
+ }
108
+ function releaseLayout(id, rect) {
109
+ REGISTRY.set(id, { rect, expiresAt: now() + SHARED_LAYOUT_TTL_MS });
110
+ }
111
+ function consumeLayout(id) {
112
+ const entry = REGISTRY.get(id);
113
+ if (!entry) return void 0;
114
+ REGISTRY.delete(id);
115
+ if (entry.expiresAt < now()) return void 0;
116
+ return entry.rect;
117
+ }
118
+ function useSharedLayout(options) {
119
+ const { layoutId, userRef, transition, shouldReduceMotion, userOnLayout } = options;
120
+ const dx = useSharedValue(0);
121
+ const dy = useSharedValue(0);
122
+ const sx = useSharedValue(1);
123
+ const sy = useSharedValue(1);
124
+ const lastRectRef = useRef(null);
125
+ const consumedRef = useRef(false);
126
+ const transitionRef = useRef(transition);
127
+ transitionRef.current = transition;
128
+ const reducedMotionRef = useRef(shouldReduceMotion);
129
+ reducedMotionRef.current = shouldReduceMotion;
130
+ const setRef = useCallback(
131
+ (node) => {
132
+ if (typeof userRef === "function") userRef(node);
133
+ else if (userRef) userRef.current = node;
134
+ },
135
+ [userRef]
136
+ );
137
+ const onLayout = useCallback(
138
+ (event) => {
139
+ userOnLayout?.(event);
140
+ if (!layoutId) return;
141
+ const { x, y, width, height } = event.nativeEvent.layout;
142
+ const rect = { x, y, width, height };
143
+ lastRectRef.current = rect;
144
+ let source;
145
+ if (!consumedRef.current) {
146
+ consumedRef.current = true;
147
+ source = consumeLayout(layoutId);
148
+ }
149
+ registerLayout(layoutId, rect);
150
+ if (source) {
151
+ applyFlip({
152
+ source,
153
+ target: rect,
154
+ dx,
155
+ dy,
156
+ sx,
157
+ sy,
158
+ transition: transitionRef.current,
159
+ shouldReduceMotion: reducedMotionRef.current
160
+ });
161
+ }
162
+ },
163
+ // dx/dy/sx/sy are stable refs from useSharedValue, but eslint's
164
+ // exhaustive-deps would flag them — including them is harmless and
165
+ // silences the warning.
166
+ [layoutId, userOnLayout, dx, dy, sx, sy]
167
+ );
168
+ useEffect(() => {
169
+ consumedRef.current = false;
170
+ }, [layoutId]);
171
+ useEffect(() => {
172
+ return () => {
173
+ if (!layoutId) return;
174
+ const rect = lastRectRef.current;
175
+ if (!rect) return;
176
+ releaseLayout(layoutId, rect);
177
+ };
178
+ }, [layoutId]);
179
+ return useMemo(
180
+ () => ({
181
+ flip: { dx, dy, sx, sy },
182
+ setRef,
183
+ onLayout
184
+ }),
185
+ [dx, dy, sx, sy, setRef, onLayout]
186
+ );
187
+ }
188
+ function applyFlip(args) {
189
+ const { source, target, dx, dy, sx, sy, transition, shouldReduceMotion } = args;
190
+ const sourceCenterX = source.x + source.width / 2;
191
+ const sourceCenterY = source.y + source.height / 2;
192
+ const targetCenterX = target.x + target.width / 2;
193
+ const targetCenterY = target.y + target.height / 2;
194
+ const deltaX = sourceCenterX - targetCenterX;
195
+ const deltaY = sourceCenterY - targetCenterY;
196
+ const scaleX = target.width > 0 ? source.width / target.width : 1;
197
+ const scaleY = target.height > 0 ? source.height / target.height : 1;
198
+ if (shouldReduceMotion) {
199
+ dx.value = 0;
200
+ dy.value = 0;
201
+ sx.value = 1;
202
+ sy.value = 1;
203
+ return;
204
+ }
205
+ if (transition?.type === "no-animation") {
206
+ dx.value = 0;
207
+ dy.value = 0;
208
+ sx.value = 1;
209
+ sy.value = 1;
210
+ return;
211
+ }
212
+ if (transition?.type === "timing") {
213
+ const duration = transition.duration ?? 300;
214
+ dx.value = withSequence(
215
+ withTiming(deltaX, { duration: 0 }),
216
+ withTiming(0, { duration })
217
+ );
218
+ dy.value = withSequence(
219
+ withTiming(deltaY, { duration: 0 }),
220
+ withTiming(0, { duration })
221
+ );
222
+ sx.value = withSequence(
223
+ withTiming(scaleX, { duration: 0 }),
224
+ withTiming(1, { duration })
225
+ );
226
+ sy.value = withSequence(
227
+ withTiming(scaleY, { duration: 0 }),
228
+ withTiming(1, { duration })
229
+ );
230
+ return;
231
+ }
232
+ const springCfg = transition?.type === "spring" ? { ...DEFAULT_SPRING, ...transition } : { ...DEFAULT_SPRING };
233
+ const springParams = springToReanimated(springCfg);
234
+ dx.value = withSequence(
235
+ withTiming(deltaX, { duration: 0 }),
236
+ withSpring(0, springParams)
237
+ );
238
+ dy.value = withSequence(
239
+ withTiming(deltaY, { duration: 0 }),
240
+ withSpring(0, springParams)
241
+ );
242
+ sx.value = withSequence(
243
+ withTiming(scaleX, { duration: 0 }),
244
+ withSpring(1, springParams)
245
+ );
246
+ sy.value = withSequence(
247
+ withTiming(scaleY, { duration: 0 }),
248
+ withSpring(1, springParams)
249
+ );
250
+ }
251
+ var PresenceContext = createContext(null);
252
+ function usePresence() {
253
+ return useContext(PresenceContext);
254
+ }
255
+ var DEFAULT_TIMING_DURATION = 250;
256
+ function buildSpring(cfg, toValue, cb) {
257
+ return withSpring(toValue, springToReanimated(cfg), cb);
258
+ }
259
+ function buildTiming(cfg, toValue, cb) {
260
+ return withTiming(
261
+ toValue,
262
+ {
263
+ duration: cfg.duration ?? DEFAULT_TIMING_DURATION,
264
+ easing: ensureWorkletEasing(cfg.easing) ?? Easing.inOut(Easing.ease)
265
+ },
266
+ cb
267
+ );
268
+ }
269
+ function buildDecay(cfg, cb) {
270
+ return withDecay(
271
+ {
272
+ velocity: cfg.velocity ?? 0,
273
+ deceleration: cfg.deceleration,
274
+ clamp: cfg.clamp
275
+ },
276
+ cb
277
+ );
278
+ }
279
+ function buildOne(cfg, toValue, cb) {
280
+ if (cfg.type === "no-animation") {
281
+ if (cb) cb(true, toValue);
282
+ return toValue;
283
+ }
284
+ if (cfg.type === "decay") return buildDecay(cfg, cb);
285
+ if (cfg.type === "timing") return buildTiming(cfg, toValue, cb);
286
+ return buildSpring(cfg, toValue, cb);
287
+ }
288
+ function applyRepeat(animation, repeat) {
289
+ if (repeat === void 0) return animation;
290
+ if (repeat === "infinite") {
291
+ return withRepeat(animation, -1, true);
292
+ }
293
+ if (typeof repeat === "number") {
294
+ return withRepeat(animation, repeat, true);
295
+ }
296
+ const count = repeat.count === "infinite" ? -1 : repeat.count;
297
+ const alternate = repeat.alternate ?? true;
298
+ return withRepeat(animation, count, alternate);
299
+ }
300
+ function applyDelay(animation, delay) {
301
+ if (!delay || delay <= 0) return animation;
302
+ return withDelay(delay, animation);
303
+ }
304
+ function resolveTransition(config, toValue, callback) {
305
+ const cfg = config ?? { type: "spring" };
306
+ const base = buildOne(cfg, toValue, callback);
307
+ const repeated = applyRepeat(base, repeatOf(cfg));
308
+ return applyDelay(repeated, delayOf(cfg));
309
+ }
310
+ function repeatOf(cfg) {
311
+ if (cfg.type === "no-animation" || cfg.type === "decay") return void 0;
312
+ return cfg.repeat;
313
+ }
314
+ function stripRepeat(cfg) {
315
+ if (!cfg) return cfg;
316
+ if (cfg.type === "no-animation" || cfg.type === "decay") return cfg;
317
+ if (cfg.repeat === void 0) return cfg;
318
+ const next = { ...cfg };
319
+ delete next.repeat;
320
+ return next;
321
+ }
322
+ function delayOf(cfg) {
323
+ if (cfg.type === "no-animation") return void 0;
324
+ return cfg.delay;
325
+ }
326
+ function isStepObject(v) {
327
+ return typeof v === "object" && v !== null && !Array.isArray(v) && "to" in v;
328
+ }
329
+ function resolveAnimatableValue(value, base, factory) {
330
+ if (Array.isArray(value)) {
331
+ const steps = value;
332
+ const stepBase = stripRepeat(base);
333
+ const animations = steps.map(
334
+ (step2, i) => resolveStep(step2, stepBase, factory?.("step", i))
335
+ );
336
+ const seq = withSequence(...animations);
337
+ return applyRepeat(seq, base ? repeatOf(base) : void 0);
338
+ }
339
+ const step = value;
340
+ const cb = factory?.("animation", void 0);
341
+ if (isStepObject(step)) {
342
+ return resolveStep(step, base, cb);
343
+ }
344
+ return resolveTransition(base, step, cb);
345
+ }
346
+ function resolveStep(step, base, cb) {
347
+ if (isStepObject(step)) {
348
+ const { to, ...override } = step;
349
+ const merged = mergeTransition(base, override);
350
+ return resolveTransition(merged, to, cb);
351
+ }
352
+ return resolveTransition(base, step, cb);
353
+ }
354
+ function mergeTransition(base, override) {
355
+ if (override.type && base && override.type !== base.type) {
356
+ return override;
357
+ }
358
+ return { ...base ?? { type: "spring" }, ...override };
359
+ }
360
+
361
+ // src/transitions/keys.ts
362
+ var TRANSITION_CONFIG_KEYS = /* @__PURE__ */ new Set([
363
+ "type",
364
+ "tension",
365
+ "friction",
366
+ "mass",
367
+ "velocity",
368
+ "restSpeedThreshold",
369
+ "restDisplacementThreshold",
370
+ "duration",
371
+ "easing",
372
+ "delay",
373
+ "repeat",
374
+ "deceleration",
375
+ "clamp"
376
+ ]);
377
+ function isTopLevelTransition(t) {
378
+ if (t === null || typeof t !== "object") return false;
379
+ const keys = Object.keys(t);
380
+ if (keys.length === 0) return false;
381
+ return keys.every((k) => TRANSITION_CONFIG_KEYS.has(k));
382
+ }
383
+
384
+ // src/transitions/sig.ts
385
+ function stableSig(value) {
386
+ if (value === void 0) return "";
387
+ try {
388
+ return stableStringify(value);
389
+ } catch {
390
+ return String(value);
391
+ }
392
+ }
393
+ function stableStringify(v) {
394
+ if (v === null || typeof v !== "object") {
395
+ if (typeof v === "function" || v === void 0) return "null";
396
+ return JSON.stringify(v);
397
+ }
398
+ if (Array.isArray(v)) {
399
+ return "[" + v.map(stableStringify).join(",") + "]";
400
+ }
401
+ const obj = v;
402
+ const keys = Object.keys(obj).sort();
403
+ return "{" + keys.map((k) => JSON.stringify(k) + ":" + stableStringify(obj[k])).join(",") + "}";
404
+ }
405
+ var alreadyChecked = false;
406
+ function ensureReanimatedInstalled() {
407
+ if (!__DEV__ || alreadyChecked) return;
408
+ if (typeof process !== "undefined" && process.env?.NODE_ENV === "test") {
409
+ return;
410
+ }
411
+ alreadyChecked = true;
412
+ const version = reanimatedVersion;
413
+ if (version) {
414
+ const major = parseInt(version.split(".")[0] ?? "0", 10);
415
+ if (major < 4) {
416
+ console.error(
417
+ `[inertia] react-native-reanimated v${version} is installed, but @rootnative/inertia requires v4.0.0 or later. Upgrade with \`pnpm add react-native-reanimated@^4\` (or your package manager's equivalent).`
418
+ );
419
+ return;
420
+ }
421
+ }
422
+ const probe = function probe2() {
423
+ "worklet";
424
+ return 0;
425
+ };
426
+ if (typeof probe.__workletHash !== "number") {
427
+ console.error(
428
+ `[inertia] The Reanimated worklets babel plugin is not configured. Add \`'react-native-worklets/plugin'\` as the LAST entry in the \`plugins\` array of your \`babel.config.js\`, then restart Metro with a fresh cache: \`npx expo start -c\` or \`npx react-native start --reset-cache\`.`
429
+ );
430
+ }
431
+ }
432
+ var TRANSFORM_KEYS = [
433
+ "translateX",
434
+ "translateY",
435
+ "scale",
436
+ "scaleX",
437
+ "scaleY",
438
+ "rotate",
439
+ "rotateX",
440
+ "rotateY"
441
+ ];
442
+ var ROTATION_KEYS = /* @__PURE__ */ new Set(["rotate", "rotateX", "rotateY"]);
443
+ var NUMERIC_TOP_LEVEL_KEYS = [
444
+ "opacity",
445
+ "width",
446
+ "height",
447
+ "borderRadius",
448
+ "shadowOpacity",
449
+ "shadowRadius",
450
+ "elevation"
451
+ ];
452
+ var COLOR_KEYS = [
453
+ "backgroundColor",
454
+ "borderColor",
455
+ "color",
456
+ "tintColor",
457
+ "shadowColor"
458
+ ];
459
+ var SHADOW_OFFSET_KEYS = ["shadowOffsetWidth", "shadowOffsetHeight"];
460
+ var ALL_KEYS = [
461
+ ...TRANSFORM_KEYS,
462
+ ...NUMERIC_TOP_LEVEL_KEYS,
463
+ ...COLOR_KEYS,
464
+ ...SHADOW_OFFSET_KEYS
465
+ ];
466
+ var TRANSFORM_KEY_SET = new Set(TRANSFORM_KEYS);
467
+ var COLOR_KEY_SET = new Set(COLOR_KEYS);
468
+ var SHADOW_OFFSET_KEY_SET = new Set(SHADOW_OFFSET_KEYS);
469
+ var GESTURE_LAYER_NAMES = [
470
+ "hovered",
471
+ "focused",
472
+ "focusVisible",
473
+ "pressed"
474
+ ];
475
+ var GESTURE_LAYER_NAME_SET = new Set(GESTURE_LAYER_NAMES);
476
+ var EXITING_POINTER_EVENTS_STYLE = { pointerEvents: "none" };
477
+ var DEFAULT_RESTING = {
478
+ translateX: 0,
479
+ translateY: 0,
480
+ scale: 1,
481
+ scaleX: 1,
482
+ scaleY: 1,
483
+ rotate: 0,
484
+ rotateX: 0,
485
+ rotateY: 0,
486
+ opacity: 1,
487
+ width: 0,
488
+ height: 0,
489
+ borderRadius: 0,
490
+ shadowOpacity: 0,
491
+ shadowRadius: 0,
492
+ elevation: 0,
493
+ // 'transparent' is the only safe universal default for colors: it works as
494
+ // an initial seed for any color animation (no jarring opaque flash on mount
495
+ // when `initial` is omitted) and rgba(0,0,0,0) interpolates cleanly into
496
+ // any opaque target via Reanimated's color util.
497
+ backgroundColor: "transparent",
498
+ borderColor: "transparent",
499
+ color: "transparent",
500
+ tintColor: "transparent",
501
+ shadowColor: "transparent",
502
+ shadowOffsetWidth: 0,
503
+ shadowOffsetHeight: 0
504
+ };
505
+ function transitionFor(prop, transition) {
506
+ if (!transition) return void 0;
507
+ if (isTopLevelTransition(transition)) return transition;
508
+ if (GESTURE_LAYER_NAME_SET.has(prop)) return void 0;
509
+ return transition[prop];
510
+ }
511
+ function gestureLayerTransitionFor(layer, transition) {
512
+ if (!transition) return void 0;
513
+ if (isTopLevelTransition(transition)) return transition;
514
+ return transition[layer];
515
+ }
516
+ function createMotionComponent(Component) {
517
+ ensureReanimatedInstalled();
518
+ const AnimatedComponent = Animated.createAnimatedComponent(
519
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
520
+ Component
521
+ );
522
+ const Motion = forwardRef(function Motion2(props, ref) {
523
+ const {
524
+ initial,
525
+ animate,
526
+ exit,
527
+ transition,
528
+ variants,
529
+ controller,
530
+ gesture,
531
+ layout,
532
+ layoutId,
533
+ onAnimationEnd,
534
+ style,
535
+ onLayout: userOnLayout,
536
+ ...rest
537
+ } = props;
538
+ if (__DEV__ && typeof style === "function") {
539
+ throw new Error(
540
+ "[inertia] `style` must be a style object or array of style objects, not a function. The function-form `style={(state) => ...}` Pressable API is not supported \u2014 use `gesture.pressed` (or `gesture.focused`, etc.) to drive state-dependent styling instead."
541
+ );
542
+ }
543
+ const presence = usePresence();
544
+ const isExiting = presence !== null && presence.isPresent === false;
545
+ const shouldReduceMotion = useShouldReduceMotion();
546
+ const onAnimationEndRef = useRef(onAnimationEnd);
547
+ onAnimationEndRef.current = onAnimationEnd;
548
+ const variantKey = useControllerKey(controller);
549
+ const resolvedAnimate = resolveAnimateInput(
550
+ animate,
551
+ variants,
552
+ variantKey
553
+ );
554
+ const animateRecord = resolvedAnimate ?? {};
555
+ const initialRecord = initial && initial !== false ? initial : void 0;
556
+ const exitRecord = exit ? exit : void 0;
557
+ const [pressed, setPressed] = useState(false);
558
+ const [focused, setFocused] = useState(false);
559
+ const [focusVisible, setFocusVisible] = useState(false);
560
+ const [hovered, setHovered] = useState(false);
561
+ const touched = /* @__PURE__ */ new Set();
562
+ collectTouchedKeys(touched, animateRecord);
563
+ if (initialRecord) collectTouchedKeys(touched, initialRecord);
564
+ if (variants) {
565
+ for (const variant of Object.values(variants)) {
566
+ if (!variant) continue;
567
+ collectTouchedKeys(touched, variant);
568
+ }
569
+ }
570
+ if (gesture) {
571
+ for (const subState of [
572
+ gesture.pressed,
573
+ gesture.focused,
574
+ gesture.focusVisible,
575
+ gesture.hovered
576
+ ]) {
577
+ if (!subState) continue;
578
+ collectTouchedKeys(touched, subState);
579
+ }
580
+ }
581
+ if (exitRecord) collectTouchedKeys(touched, exitRecord);
582
+ const activeKeysRef = useRef(null);
583
+ const hasTransformRef = useRef(false);
584
+ const hasShadowOffsetRef = useRef(false);
585
+ const prevActive = activeKeysRef.current;
586
+ let grew = prevActive === null;
587
+ if (!grew && prevActive) {
588
+ for (const k of touched) {
589
+ if (!prevActive.includes(k)) {
590
+ grew = true;
591
+ break;
592
+ }
593
+ }
594
+ }
595
+ if (grew) {
596
+ const merged = new Set(prevActive ?? []);
597
+ for (const k of touched) merged.add(k);
598
+ activeKeysRef.current = ALL_KEYS.filter((k) => merged.has(k));
599
+ hasTransformRef.current = activeKeysRef.current.some(
600
+ (k) => TRANSFORM_KEY_SET.has(k)
601
+ );
602
+ hasShadowOffsetRef.current = activeKeysRef.current.some(
603
+ (k) => SHADOW_OFFSET_KEY_SET.has(k)
604
+ );
605
+ }
606
+ const sharedValues = useAnimatableSharedValues((key) => {
607
+ if (SHADOW_OFFSET_KEY_SET.has(key)) {
608
+ const axis = shadowOffsetAxisFor(key);
609
+ if (initial === false) {
610
+ return shadowOffsetAxisValue(animateRecord.shadowOffset, axis) ?? DEFAULT_RESTING[key];
611
+ }
612
+ return shadowOffsetAxisValue(
613
+ initialRecord?.shadowOffset,
614
+ axis
615
+ ) ?? shadowOffsetAxisValue(animateRecord.shadowOffset, axis) ?? DEFAULT_RESTING[key];
616
+ }
617
+ if (initial === false) {
618
+ const a = animateRecord[key];
619
+ return restValue(a) ?? DEFAULT_RESTING[key];
620
+ }
621
+ return initialRecord?.[key] ?? restValue(animateRecord[key]) ?? DEFAULT_RESTING[key];
622
+ });
623
+ const pressedProgress = useSharedValue(0);
624
+ const focusedProgress = useSharedValue(0);
625
+ const focusVisibleProgress = useSharedValue(0);
626
+ const hoveredProgress = useSharedValue(0);
627
+ const gestureSV = useSharedValue(
628
+ resolveGestureLayers(gesture)
629
+ );
630
+ const gestureTargetsSig = stableSig(gesture);
631
+ useEffect(() => {
632
+ gestureSV.value = resolveGestureLayers(gesture);
633
+ }, [gestureTargetsSig]);
634
+ const baseRecord = isExiting && exitRecord ? { ...animateRecord, ...exitRecord } : animateRecord;
635
+ const baseSig = stableSig(baseRecord) + (isExiting ? "|exit" : "") + (shouldReduceMotion ? "|rm" : "");
636
+ const transitionSig = stableSig(transition);
637
+ const safeToRemoveRef = useRef(void 0);
638
+ safeToRemoveRef.current = presence?.safeToRemove;
639
+ useEffect(() => {
640
+ if (isExiting && (!exitRecord || Object.keys(exitRecord).length === 0)) {
641
+ safeToRemoveRef.current?.();
642
+ return;
643
+ }
644
+ let pending = 0;
645
+ let done = false;
646
+ const onSettle = () => {
647
+ if (done) return;
648
+ pending--;
649
+ if (pending <= 0) {
650
+ done = true;
651
+ if (isExiting) safeToRemoveRef.current?.();
652
+ }
653
+ };
654
+ let transformPending = 0;
655
+ for (const k of ALL_KEYS) {
656
+ if (TRANSFORM_KEY_SET.has(k) && baseRecord[k] !== void 0) {
657
+ transformPending++;
658
+ }
659
+ }
660
+ const transformGroup = transformPending > 0 ? { remaining: transformPending } : void 0;
661
+ for (const key of ALL_KEYS) {
662
+ const target = SHADOW_OFFSET_KEY_SET.has(key) ? shadowOffsetAxisValue(
663
+ baseRecord.shadowOffset,
664
+ shadowOffsetAxisFor(key)
665
+ ) : baseRecord[key];
666
+ if (target === void 0) continue;
667
+ const cfg = shouldReduceMotion ? { type: "no-animation" } : transitionFor(
668
+ SHADOW_OFFSET_KEY_SET.has(key) ? "shadowOffset" : key,
669
+ transition
670
+ );
671
+ if (isExiting) pending++;
672
+ const factory = makeKeyCallbackFactory(
673
+ key,
674
+ sharedValues[key],
675
+ targetEndValue(target),
676
+ onAnimationEndRef,
677
+ {
678
+ stepCount: stepCountOf(target),
679
+ totalIterations: totalIterationsOf(cfg)
680
+ },
681
+ isExiting ? onSettle : void 0,
682
+ TRANSFORM_KEY_SET.has(key) ? transformGroup : void 0
683
+ );
684
+ sharedValues[key].value = resolveAnimatableValue(
685
+ target,
686
+ cfg,
687
+ factory
688
+ );
689
+ }
690
+ if (isExiting && pending === 0) {
691
+ safeToRemoveRef.current?.();
692
+ }
693
+ }, [baseSig, transitionSig]);
694
+ useGestureLayerProgress(
695
+ pressedProgress,
696
+ pressed,
697
+ gesture?.pressed != null,
698
+ "pressed",
699
+ transition,
700
+ isExiting,
701
+ shouldReduceMotion
702
+ );
703
+ useGestureLayerProgress(
704
+ focusedProgress,
705
+ focused,
706
+ gesture?.focused != null,
707
+ "focused",
708
+ transition,
709
+ isExiting,
710
+ shouldReduceMotion
711
+ );
712
+ useGestureLayerProgress(
713
+ focusVisibleProgress,
714
+ focusVisible,
715
+ gesture?.focusVisible != null,
716
+ "focusVisible",
717
+ transition,
718
+ isExiting,
719
+ shouldReduceMotion
720
+ );
721
+ useGestureLayerProgress(
722
+ hoveredProgress,
723
+ hovered,
724
+ gesture?.hovered != null,
725
+ "hovered",
726
+ transition,
727
+ isExiting,
728
+ shouldReduceMotion
729
+ );
730
+ const sharedLayout = useSharedLayout({
731
+ layoutId,
732
+ userRef: ref,
733
+ transition: isTopLevelTransition(transition) ? transition : void 0,
734
+ shouldReduceMotion,
735
+ userOnLayout
736
+ });
737
+ const flip = sharedLayout.flip;
738
+ const hasLayoutId = layoutId !== void 0;
739
+ const animatedStyle = useAnimatedStyle(() => {
740
+ const activeKeys = activeKeysRef.current;
741
+ const hasTransform = hasTransformRef.current;
742
+ const hasShadowOffset = hasShadowOffsetRef.current;
743
+ const out = {};
744
+ const transform = [];
745
+ let shadowOffsetW = 0;
746
+ let shadowOffsetH = 0;
747
+ const ph = hoveredProgress.value;
748
+ const pf = focusedProgress.value;
749
+ const pfv = focusVisibleProgress.value;
750
+ const pp = pressedProgress.value;
751
+ const layers = gestureSV.value;
752
+ const hoveredLayer = layers ? layers.hovered : null;
753
+ const focusedLayer = layers ? layers.focused : null;
754
+ const focusVisibleLayer = layers ? layers.focusVisible : null;
755
+ const pressedLayer = layers ? layers.pressed : null;
756
+ for (const key of activeKeys) {
757
+ let v = sharedValues[key].value;
758
+ const isColor = COLOR_KEY_SET.has(key);
759
+ if (hoveredLayer && ph > 0 && hoveredLayer[key] !== void 0) {
760
+ const t = hoveredLayer[key];
761
+ v = isColor ? interpolateColor(ph, [0, 1], [v, t]) : v + (t - v) * ph;
762
+ }
763
+ if (focusedLayer && pf > 0 && focusedLayer[key] !== void 0) {
764
+ const t = focusedLayer[key];
765
+ v = isColor ? interpolateColor(pf, [0, 1], [v, t]) : v + (t - v) * pf;
766
+ }
767
+ if (focusVisibleLayer && pfv > 0 && focusVisibleLayer[key] !== void 0) {
768
+ const t = focusVisibleLayer[key];
769
+ v = isColor ? interpolateColor(pfv, [0, 1], [v, t]) : v + (t - v) * pfv;
770
+ }
771
+ if (pressedLayer && pp > 0 && pressedLayer[key] !== void 0) {
772
+ const t = pressedLayer[key];
773
+ v = isColor ? interpolateColor(pp, [0, 1], [v, t]) : v + (t - v) * pp;
774
+ }
775
+ if (TRANSFORM_KEY_SET.has(key)) {
776
+ transform.push(
777
+ ROTATION_KEYS.has(key) ? { [key]: `${v}deg` } : { [key]: v }
778
+ );
779
+ } else if (key === "shadowOffsetWidth") {
780
+ shadowOffsetW = v;
781
+ } else if (key === "shadowOffsetHeight") {
782
+ shadowOffsetH = v;
783
+ } else {
784
+ out[key] = v;
785
+ }
786
+ }
787
+ if (hasLayoutId) {
788
+ transform.push({ translateX: flip.dx.value });
789
+ transform.push({ translateY: flip.dy.value });
790
+ transform.push({ scaleX: flip.sx.value });
791
+ transform.push({ scaleY: flip.sy.value });
792
+ }
793
+ if (hasTransform || hasLayoutId) out.transform = transform;
794
+ if (hasShadowOffset) {
795
+ out.shadowOffset = { width: shadowOffsetW, height: shadowOffsetH };
796
+ }
797
+ return out;
798
+ });
799
+ const mergedStyle = useMemo(
800
+ () => isExiting ? [style, animatedStyle, EXITING_POINTER_EVENTS_STYLE] : [style, animatedStyle],
801
+ [style, animatedStyle, isExiting]
802
+ );
803
+ const gestureHandlers = useGestureHandlers(
804
+ gesture,
805
+ rest,
806
+ setPressed,
807
+ setFocused,
808
+ setFocusVisible,
809
+ setHovered
810
+ );
811
+ const layoutSig = stableSig(layout);
812
+ const layoutTransition = useMemo(
813
+ () => shouldReduceMotion ? void 0 : resolveLayoutTransition(layout),
814
+ // eslint-disable-next-line react-hooks/exhaustive-deps
815
+ [layoutSig, shouldReduceMotion]
816
+ );
817
+ return /* @__PURE__ */ jsx(
818
+ AnimatedComponent,
819
+ {
820
+ ref: sharedLayout.setRef,
821
+ ...rest,
822
+ ...gestureHandlers,
823
+ onLayout: sharedLayout.onLayout,
824
+ layout: layoutTransition,
825
+ style: mergedStyle
826
+ }
827
+ );
828
+ });
829
+ Motion.displayName = `Motion(${Component.displayName ?? Component.name ?? "Component"})`;
830
+ return Motion;
831
+ }
832
+ function useAnimatableSharedValues(init) {
833
+ const translateX = useSharedValue(init("translateX"));
834
+ const translateY = useSharedValue(init("translateY"));
835
+ const scale = useSharedValue(init("scale"));
836
+ const scaleX = useSharedValue(init("scaleX"));
837
+ const scaleY = useSharedValue(init("scaleY"));
838
+ const rotate = useSharedValue(init("rotate"));
839
+ const rotateX = useSharedValue(init("rotateX"));
840
+ const rotateY = useSharedValue(init("rotateY"));
841
+ const opacity = useSharedValue(init("opacity"));
842
+ const width = useSharedValue(init("width"));
843
+ const height = useSharedValue(init("height"));
844
+ const borderRadius = useSharedValue(init("borderRadius"));
845
+ const shadowOpacity = useSharedValue(init("shadowOpacity"));
846
+ const shadowRadius = useSharedValue(init("shadowRadius"));
847
+ const elevation = useSharedValue(init("elevation"));
848
+ const backgroundColor = useSharedValue(
849
+ init("backgroundColor")
850
+ );
851
+ const borderColor = useSharedValue(init("borderColor"));
852
+ const color = useSharedValue(init("color"));
853
+ const tintColor = useSharedValue(init("tintColor"));
854
+ const shadowColor = useSharedValue(init("shadowColor"));
855
+ const shadowOffsetWidth = useSharedValue(
856
+ init("shadowOffsetWidth")
857
+ );
858
+ const shadowOffsetHeight = useSharedValue(
859
+ init("shadowOffsetHeight")
860
+ );
861
+ const ref = useRef(null);
862
+ if (ref.current === null) {
863
+ ref.current = {
864
+ translateX,
865
+ translateY,
866
+ scale,
867
+ scaleX,
868
+ scaleY,
869
+ rotate,
870
+ rotateX,
871
+ rotateY,
872
+ opacity,
873
+ width,
874
+ height,
875
+ borderRadius,
876
+ shadowOpacity,
877
+ shadowRadius,
878
+ elevation,
879
+ backgroundColor,
880
+ borderColor,
881
+ color,
882
+ tintColor,
883
+ shadowColor,
884
+ shadowOffsetWidth,
885
+ shadowOffsetHeight
886
+ };
887
+ }
888
+ return ref.current;
889
+ }
890
+ function makeKeyCallbackFactory(key, sharedValue, target, onAnimationEndRef, meta, onSettle, transformGroup) {
891
+ if (!onAnimationEndRef.current && !onSettle) return void 0;
892
+ const state = { iteration: 0 };
893
+ const isTransformKey = TRANSFORM_KEY_SET.has(key);
894
+ const dispatch = (rawPhase, step, finished, value) => {
895
+ const isLastIteration = state.iteration >= meta.totalIterations - 1;
896
+ let phase;
897
+ let isTerminal = false;
898
+ if (rawPhase === "step") {
899
+ const isLastInPass = step !== void 0 && step === meta.stepCount - 1;
900
+ if (!isLastInPass) {
901
+ phase = "step";
902
+ } else if (isLastIteration) {
903
+ phase = "animation";
904
+ isTerminal = true;
905
+ } else {
906
+ phase = "sequence";
907
+ }
908
+ } else if (isLastIteration) {
909
+ phase = "animation";
910
+ isTerminal = true;
911
+ } else {
912
+ phase = "repeat";
913
+ }
914
+ const reportedIteration = state.iteration;
915
+ if (phase === "sequence" || phase === "repeat") state.iteration++;
916
+ const fn = onAnimationEndRef.current;
917
+ if (fn) {
918
+ if (isTransformKey && transformGroup && phase === "animation") {
919
+ transformGroup.remaining--;
920
+ if (transformGroup.remaining <= 0) {
921
+ fn({
922
+ key: "transform",
923
+ finished,
924
+ value,
925
+ target,
926
+ phase,
927
+ step,
928
+ iteration: reportedIteration
929
+ });
930
+ }
931
+ } else {
932
+ fn({
933
+ key,
934
+ finished,
935
+ value,
936
+ target,
937
+ phase,
938
+ step,
939
+ iteration: reportedIteration
940
+ });
941
+ }
942
+ }
943
+ if (onSettle && isTerminal) onSettle();
944
+ };
945
+ return (rawPhase, step) => {
946
+ const cb = (finished) => {
947
+ "worklet";
948
+ runOnJS(dispatch)(rawPhase, step, !!finished, sharedValue.value);
949
+ };
950
+ return cb;
951
+ };
952
+ }
953
+ function shadowOffsetAxisFor(key) {
954
+ return key === "shadowOffsetWidth" ? "width" : "height";
955
+ }
956
+ function shadowOffsetAxisValue(source, axis) {
957
+ return source?.[axis];
958
+ }
959
+ function collectTouchedKeys(touched, record) {
960
+ for (const k of ALL_KEYS) {
961
+ if (k in record) touched.add(k);
962
+ }
963
+ if ("shadowOffset" in record && record.shadowOffset) {
964
+ const so = record.shadowOffset;
965
+ if (so.width !== void 0) touched.add("shadowOffsetWidth");
966
+ if (so.height !== void 0) touched.add("shadowOffsetHeight");
967
+ }
968
+ }
969
+ function stepCountOf(v) {
970
+ if (Array.isArray(v)) return v.length;
971
+ return 1;
972
+ }
973
+ function totalIterationsOf(cfg) {
974
+ if (!cfg || cfg.type === "no-animation" || cfg.type === "decay") return 1;
975
+ const r = cfg.repeat;
976
+ if (r === void 0) return 1;
977
+ if (r === "infinite") return Number.POSITIVE_INFINITY;
978
+ if (typeof r === "number") return r;
979
+ if (r.count === "infinite") return Number.POSITIVE_INFINITY;
980
+ return r.count;
981
+ }
982
+ function targetEndValue(v) {
983
+ if (v === void 0) return void 0;
984
+ if (typeof v === "number" || typeof v === "string") return v;
985
+ if (Array.isArray(v)) {
986
+ return v.length > 0 ? targetEndValue(v[v.length - 1]) : void 0;
987
+ }
988
+ if (typeof v === "object" && v !== null && "to" in v) {
989
+ const to = v.to;
990
+ return typeof to === "number" || typeof to === "string" ? to : void 0;
991
+ }
992
+ return void 0;
993
+ }
994
+ function useControllerKey(controller) {
995
+ const [, setTick] = useState(0);
996
+ useEffect(() => {
997
+ if (!controller) return;
998
+ const unsub = controller.subscribe(() => setTick((n) => n + 1));
999
+ return unsub;
1000
+ }, [controller]);
1001
+ return controller?.current;
1002
+ }
1003
+ function resolveAnimateInput(animate, variants, controllerKey) {
1004
+ if (controllerKey !== void 0 && variants && controllerKey in variants) {
1005
+ return variants[controllerKey];
1006
+ }
1007
+ if (typeof animate === "string") {
1008
+ if (variants && animate in variants) return variants[animate];
1009
+ if (__DEV__) {
1010
+ console.warn(
1011
+ `[inertia] animate="${animate}" but no matching variant. Did you forget to pass \`variants\`?`
1012
+ );
1013
+ }
1014
+ return void 0;
1015
+ }
1016
+ return animate;
1017
+ }
1018
+ function restValue(v) {
1019
+ if (v === void 0) return void 0;
1020
+ if (typeof v === "number" || typeof v === "string") return v;
1021
+ if (Array.isArray(v)) {
1022
+ return v.length > 0 ? restValue(v[0]) : void 0;
1023
+ }
1024
+ if (typeof v === "object" && v !== null && "to" in v) {
1025
+ const to = v.to;
1026
+ return typeof to === "number" || typeof to === "string" ? to : void 0;
1027
+ }
1028
+ return void 0;
1029
+ }
1030
+ function resolveGestureLayers(gesture) {
1031
+ if (!gesture) return null;
1032
+ const out = {};
1033
+ for (const layer of GESTURE_LAYER_NAMES) {
1034
+ const subState = gesture[layer];
1035
+ if (!subState) continue;
1036
+ const resolved = {};
1037
+ for (const key of ALL_KEYS) {
1038
+ if (SHADOW_OFFSET_KEY_SET.has(key)) {
1039
+ const axis = shadowOffsetAxisFor(key);
1040
+ const so = subState.shadowOffset;
1041
+ const v = shadowOffsetAxisValue(so, axis);
1042
+ if (v !== void 0) resolved[key] = v;
1043
+ continue;
1044
+ }
1045
+ const raw = subState[key];
1046
+ if (raw === void 0) continue;
1047
+ const t = targetEndValue(raw);
1048
+ if (t !== void 0) resolved[key] = t;
1049
+ }
1050
+ out[layer] = resolved;
1051
+ }
1052
+ return out;
1053
+ }
1054
+ function useGestureLayerProgress(progress, active, declared, layer, transition, isExiting, shouldReduceMotion) {
1055
+ const layerCfgSig = stableSig(gestureLayerTransitionFor(layer, transition));
1056
+ useEffect(() => {
1057
+ if (!declared) return;
1058
+ if (isExiting) {
1059
+ progress.value = 0;
1060
+ return;
1061
+ }
1062
+ const target = active ? 1 : 0;
1063
+ const cfg = shouldReduceMotion ? { type: "no-animation" } : gestureLayerTransitionFor(layer, transition) ?? { type: "spring" };
1064
+ progress.value = resolveTransition(cfg, target);
1065
+ }, [active, declared, isExiting, shouldReduceMotion, layerCfgSig]);
1066
+ }
1067
+ function useGestureHandlers(gesture, rest, setPressed, setFocused, setFocusVisible, setHovered) {
1068
+ const hasPressed = gesture?.pressed ? 1 : 0;
1069
+ const hasFocused = gesture?.focused ? 1 : 0;
1070
+ const hasFocusVisible = gesture?.focusVisible ? 1 : 0;
1071
+ const hasHovered = gesture?.hovered ? 1 : 0;
1072
+ return useMemo(() => {
1073
+ if (!gesture) return {};
1074
+ const handlers = {};
1075
+ if (gesture.pressed) {
1076
+ handlers.onTouchStart = compose(rest.onTouchStart, () => setPressed(true));
1077
+ handlers.onTouchEnd = compose(rest.onTouchEnd, () => setPressed(false));
1078
+ handlers.onTouchCancel = compose(
1079
+ rest.onTouchCancel,
1080
+ () => setPressed(false)
1081
+ );
1082
+ handlers.onPressIn = compose(rest.onPressIn, () => setPressed(true));
1083
+ handlers.onPressOut = compose(rest.onPressOut, () => setPressed(false));
1084
+ }
1085
+ if (gesture.focused || gesture.focusVisible) {
1086
+ handlers.onFocus = compose(rest.onFocus, () => {
1087
+ if (gesture.focused) setFocused(true);
1088
+ if (gesture.focusVisible && isFocusVisible()) setFocusVisible(true);
1089
+ });
1090
+ handlers.onBlur = compose(rest.onBlur, () => {
1091
+ if (gesture.focused) setFocused(false);
1092
+ if (gesture.focusVisible) setFocusVisible(false);
1093
+ });
1094
+ }
1095
+ if (gesture.hovered) {
1096
+ handlers.onMouseEnter = compose(rest.onMouseEnter, () => setHovered(true));
1097
+ handlers.onMouseLeave = compose(
1098
+ rest.onMouseLeave,
1099
+ () => setHovered(false)
1100
+ );
1101
+ }
1102
+ return handlers;
1103
+ }, [
1104
+ hasPressed,
1105
+ hasFocused,
1106
+ hasFocusVisible,
1107
+ hasHovered,
1108
+ rest.onTouchStart,
1109
+ rest.onTouchEnd,
1110
+ rest.onTouchCancel,
1111
+ rest.onPressIn,
1112
+ rest.onPressOut,
1113
+ rest.onFocus,
1114
+ rest.onBlur,
1115
+ rest.onMouseEnter,
1116
+ rest.onMouseLeave
1117
+ ]);
1118
+ }
1119
+ function compose(user, ours) {
1120
+ if (typeof user !== "function") return ours;
1121
+ return (event) => {
1122
+ user(event);
1123
+ ours(event);
1124
+ };
1125
+ }
1126
+
1127
+ // src/motion/ScrollView.tsx
1128
+ var MotionScrollView = createMotionComponent(ScrollView);
1129
+
1130
+ export { MotionScrollView };
1131
+ //# sourceMappingURL=ScrollView.mjs.map
1132
+ //# sourceMappingURL=ScrollView.mjs.map