@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.
package/dist/index.js CHANGED
@@ -1,1388 +1,41 @@
1
1
  'use strict';
2
2
 
3
- var reactNative = require('react-native');
3
+ var chunkQ6ZTMLTI_js = require('./chunk-Q6ZTMLTI.js');
4
+ var chunkSCTX5Z7I_js = require('./chunk-SCTX5Z7I.js');
5
+ var chunkWZGMAXKC_js = require('./chunk-WZGMAXKC.js');
6
+ var chunkNDKVHL3N_js = require('./chunk-NDKVHL3N.js');
7
+ var chunkOM5FXU4I_js = require('./chunk-OM5FXU4I.js');
8
+ var chunk5I3G43XA_js = require('./chunk-5I3G43XA.js');
9
+ var chunk6UQ4KA6V_js = require('./chunk-6UQ4KA6V.js');
10
+ var chunk6EP3S2PN_js = require('./chunk-6EP3S2PN.js');
11
+ var chunkSFRNO6AW_js = require('./chunk-SFRNO6AW.js');
4
12
  var react = require('react');
5
- var Animated = require('react-native-reanimated');
6
- var jsxRuntime = require('react/jsx-runtime');
13
+ var reactNativeReanimated = require('react-native-reanimated');
7
14
  var reactNativeWorklets = require('react-native-worklets');
8
15
 
9
- function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
10
-
11
- var Animated__default = /*#__PURE__*/_interopDefault(Animated);
12
-
13
- // src/motion/Image.tsx
14
-
15
- // src/transitions/sig.ts
16
- function stableSig(value) {
17
- if (value === void 0) return "";
18
- try {
19
- return stableStringify(value);
20
- } catch {
21
- return String(value);
22
- }
23
- }
24
- function stableStringify(v) {
25
- if (v === null || typeof v !== "object") {
26
- if (typeof v === "function" || v === void 0) return "null";
27
- return JSON.stringify(v);
28
- }
29
- if (Array.isArray(v)) {
30
- return "[" + v.map(stableStringify).join(",") + "]";
31
- }
32
- const obj = v;
33
- const keys = Object.keys(obj).sort();
34
- return "{" + keys.map((k) => JSON.stringify(k) + ":" + stableStringify(obj[k])).join(",") + "}";
35
- }
36
- var DEFAULT_MOTION_CONFIG = {
37
- reducedMotion: "user",
38
- transitions: {}
39
- };
40
- var MotionConfigContext = react.createContext(
41
- DEFAULT_MOTION_CONFIG
42
- );
43
- function useMotionConfig() {
44
- return react.useContext(MotionConfigContext);
45
- }
46
- function useNamedTransitions() {
47
- return useMotionConfig().transitions;
48
- }
49
- function useShouldReduceMotion() {
50
- const { reducedMotion } = useMotionConfig();
51
- const osReduced = Animated.useReducedMotion();
52
- if (reducedMotion === "never") return false;
53
- if (reducedMotion === "always") return true;
54
- return osReduced;
55
- }
56
- function MotionConfig({
57
- reducedMotion,
58
- transitions,
59
- children
60
- }) {
61
- const parent = useMotionConfig();
62
- const transitionsSig = stableSig(transitions);
63
- const value = react.useMemo(
64
- () => ({
65
- reducedMotion: reducedMotion ?? parent.reducedMotion,
66
- transitions: transitions ? { ...parent.transitions, ...transitions } : parent.transitions
67
- }),
68
- // eslint-disable-next-line react-hooks/exhaustive-deps
69
- [reducedMotion, transitionsSig, parent]
70
- );
71
- return /* @__PURE__ */ jsxRuntime.jsx(MotionConfigContext.Provider, { value, children });
72
- }
73
-
74
- // src/transitions/keys.ts
75
- var TRANSITION_CONFIG_KEYS = /* @__PURE__ */ new Set([
76
- "type",
77
- "tension",
78
- "friction",
79
- "mass",
80
- "velocity",
81
- "restSpeedThreshold",
82
- "restDisplacementThreshold",
83
- "duration",
84
- "easing",
85
- "delay",
86
- "repeat",
87
- "deceleration",
88
- "clamp"
89
- ]);
90
- function isTopLevelTransition(t) {
91
- if (t === null || typeof t !== "object") return false;
92
- const keys = Object.keys(t);
93
- if (keys.length === 0) return false;
94
- return keys.every((k) => TRANSITION_CONFIG_KEYS.has(k));
95
- }
96
-
97
- // src/config/namedTransitions.ts
98
- var UNKNOWN_NAME_FALLBACK = { type: "spring" };
99
- function lookupNamedTransition(name, registry) {
100
- const cfg = registry[name];
101
- if (cfg) return cfg;
102
- if (__DEV__) {
103
- console.warn(
104
- `[inertia] Unknown transition name "${name}" \u2014 falling back to the default spring. Register it on a provider: <MotionConfig transitions={{ '${name}': { ... } }}>.`
105
- );
106
- }
107
- return UNKNOWN_NAME_FALLBACK;
108
- }
109
- function resolveNamedTransition(input, registry) {
110
- if (input === void 0) return void 0;
111
- if (typeof input === "string") return lookupNamedTransition(input, registry);
112
- return input;
113
- }
114
- function resolveNamedTransitionProp(transition, registry) {
115
- if (transition === void 0) return void 0;
116
- if (typeof transition === "string") {
117
- return lookupNamedTransition(transition, registry);
118
- }
119
- if (isTopLevelTransition(transition)) return transition;
120
- const map = transition;
121
- let out = null;
122
- for (const key in map) {
123
- const value = map[key];
124
- if (typeof value === "string") {
125
- if (out === null) out = { ...map };
126
- out[key] = lookupNamedTransition(value, registry);
127
- }
128
- }
129
- return out ?? transition;
130
- }
131
- var modality = "keyboard";
132
- var installed = false;
133
- function setKeyboard() {
134
- modality = "keyboard";
135
- }
136
- function setPointer() {
137
- modality = "pointer";
138
- }
139
- function ensureInstalled() {
140
- if (installed) return;
141
- if (reactNative.Platform.OS !== "web") return;
142
- if (typeof document === "undefined") return;
143
- document.addEventListener("keydown", setKeyboard, true);
144
- document.addEventListener("mousedown", setPointer, true);
145
- document.addEventListener("pointerdown", setPointer, true);
146
- document.addEventListener("touchstart", setPointer, true);
147
- installed = true;
148
- }
149
- function isFocusVisible() {
150
- if (reactNative.Platform.OS !== "web") return true;
151
- ensureInstalled();
152
- return modality === "keyboard";
153
- }
154
- function ensureWorkletEasing(easing) {
155
- if (!easing) return void 0;
156
- const fn = isEasingFactory(easing) ? easing.factory() : easing;
157
- if (reactNativeWorklets.isWorkletFunction(fn)) return fn;
158
- const wrapped = (t) => {
159
- "worklet";
160
- return fn(t);
161
- };
162
- return wrapped;
163
- }
164
- function isEasingFactory(value) {
165
- return typeof value === "object" && value !== null && "factory" in value && typeof value.factory === "function";
166
- }
167
-
168
- // src/transitions/spring.ts
169
- var DEFAULT_SPRING = {
170
- tension: 170,
171
- friction: 26,
172
- mass: 1
173
- };
174
- function springToReanimated(t) {
175
- "worklet";
176
- return {
177
- stiffness: t.tension ?? DEFAULT_SPRING.tension,
178
- damping: t.friction ?? DEFAULT_SPRING.friction,
179
- mass: t.mass ?? DEFAULT_SPRING.mass,
180
- velocity: t.velocity,
181
- restSpeedThreshold: t.restSpeedThreshold,
182
- restDisplacementThreshold: t.restDisplacementThreshold
183
- };
184
- }
185
-
186
- // src/layout/resolveLayout.ts
187
- function resolveLayoutTransition(layout) {
188
- if (!layout) return void 0;
189
- const cfg = layout === true ? { type: "spring" } : layout;
190
- if (cfg.type === "no-animation") return void 0;
191
- if (cfg.type === "timing") {
192
- let builder2 = Animated.LinearTransition.duration(cfg.duration ?? 300);
193
- const easing = ensureWorkletEasing(cfg.easing);
194
- if (easing) builder2 = builder2.easing(easing);
195
- if (cfg.delay) builder2 = builder2.delay(cfg.delay);
196
- return builder2;
197
- }
198
- const spring = cfg.type === "decay" ? { type: "spring" } : cfg;
199
- const { stiffness, damping, mass } = springToReanimated({
200
- ...DEFAULT_SPRING,
201
- ...spring
202
- });
203
- let builder = Animated.LinearTransition.springify().stiffness(stiffness).damping(damping).mass(mass);
204
- if ("delay" in spring && spring.delay) builder = builder.delay(spring.delay);
205
- return builder;
206
- }
207
-
208
- // src/layout/sharedRegistry.ts
209
- var REGISTRY = /* @__PURE__ */ new Map();
210
- var SHARED_LAYOUT_TTL_MS = 1e3;
211
- var now = () => Date.now();
212
- function registerLayout(id, rect) {
213
- REGISTRY.set(id, { rect, expiresAt: now() + SHARED_LAYOUT_TTL_MS });
214
- }
215
- function releaseLayout(id, rect) {
216
- REGISTRY.set(id, { rect, expiresAt: now() + SHARED_LAYOUT_TTL_MS });
217
- }
218
- function consumeLayout(id) {
219
- const entry = REGISTRY.get(id);
220
- if (!entry) return void 0;
221
- REGISTRY.delete(id);
222
- if (entry.expiresAt < now()) return void 0;
223
- return entry.rect;
224
- }
225
- function useSharedLayout(options) {
226
- const { layoutId, userRef, transition, shouldReduceMotion, userOnLayout } = options;
227
- const dx = Animated.useSharedValue(0);
228
- const dy = Animated.useSharedValue(0);
229
- const sx = Animated.useSharedValue(1);
230
- const sy = Animated.useSharedValue(1);
231
- const lastRectRef = react.useRef(null);
232
- const consumedRef = react.useRef(false);
233
- const transitionRef = react.useRef(transition);
234
- transitionRef.current = transition;
235
- const reducedMotionRef = react.useRef(shouldReduceMotion);
236
- reducedMotionRef.current = shouldReduceMotion;
237
- const setRef = react.useCallback(
238
- (node) => {
239
- if (typeof userRef === "function") userRef(node);
240
- else if (userRef) userRef.current = node;
241
- },
242
- [userRef]
243
- );
244
- const onLayout = react.useCallback(
245
- (event) => {
246
- userOnLayout?.(event);
247
- if (!layoutId) return;
248
- const { x, y, width, height } = event.nativeEvent.layout;
249
- const rect = { x, y, width, height };
250
- lastRectRef.current = rect;
251
- let source;
252
- if (!consumedRef.current) {
253
- consumedRef.current = true;
254
- source = consumeLayout(layoutId);
255
- }
256
- registerLayout(layoutId, rect);
257
- if (source) {
258
- applyFlip({
259
- source,
260
- target: rect,
261
- dx,
262
- dy,
263
- sx,
264
- sy,
265
- transition: transitionRef.current,
266
- shouldReduceMotion: reducedMotionRef.current
267
- });
268
- }
269
- },
270
- // dx/dy/sx/sy are stable refs from useSharedValue, but eslint's
271
- // exhaustive-deps would flag them — including them is harmless and
272
- // silences the warning.
273
- [layoutId, userOnLayout, dx, dy, sx, sy]
274
- );
275
- react.useEffect(() => {
276
- consumedRef.current = false;
277
- }, [layoutId]);
278
- react.useEffect(() => {
279
- return () => {
280
- if (!layoutId) return;
281
- const rect = lastRectRef.current;
282
- if (!rect) return;
283
- releaseLayout(layoutId, rect);
284
- };
285
- }, [layoutId]);
286
- return react.useMemo(
287
- () => ({
288
- flip: { dx, dy, sx, sy },
289
- setRef,
290
- onLayout
291
- }),
292
- [dx, dy, sx, sy, setRef, onLayout]
293
- );
294
- }
295
- function applyFlip(args) {
296
- const { source, target, dx, dy, sx, sy, transition, shouldReduceMotion } = args;
297
- const sourceCenterX = source.x + source.width / 2;
298
- const sourceCenterY = source.y + source.height / 2;
299
- const targetCenterX = target.x + target.width / 2;
300
- const targetCenterY = target.y + target.height / 2;
301
- const deltaX = sourceCenterX - targetCenterX;
302
- const deltaY = sourceCenterY - targetCenterY;
303
- const scaleX = target.width > 0 ? source.width / target.width : 1;
304
- const scaleY = target.height > 0 ? source.height / target.height : 1;
305
- if (shouldReduceMotion) {
306
- dx.value = 0;
307
- dy.value = 0;
308
- sx.value = 1;
309
- sy.value = 1;
310
- return;
311
- }
312
- if (transition?.type === "no-animation") {
313
- dx.value = 0;
314
- dy.value = 0;
315
- sx.value = 1;
316
- sy.value = 1;
317
- return;
318
- }
319
- if (transition?.type === "timing") {
320
- const duration = transition.duration ?? 300;
321
- dx.value = Animated.withSequence(
322
- Animated.withTiming(deltaX, { duration: 0 }),
323
- Animated.withTiming(0, { duration })
324
- );
325
- dy.value = Animated.withSequence(
326
- Animated.withTiming(deltaY, { duration: 0 }),
327
- Animated.withTiming(0, { duration })
328
- );
329
- sx.value = Animated.withSequence(
330
- Animated.withTiming(scaleX, { duration: 0 }),
331
- Animated.withTiming(1, { duration })
332
- );
333
- sy.value = Animated.withSequence(
334
- Animated.withTiming(scaleY, { duration: 0 }),
335
- Animated.withTiming(1, { duration })
336
- );
337
- return;
338
- }
339
- const springCfg = transition?.type === "spring" ? { ...DEFAULT_SPRING, ...transition } : { ...DEFAULT_SPRING };
340
- const springParams = springToReanimated(springCfg);
341
- dx.value = Animated.withSequence(
342
- Animated.withTiming(deltaX, { duration: 0 }),
343
- Animated.withSpring(0, springParams)
344
- );
345
- dy.value = Animated.withSequence(
346
- Animated.withTiming(deltaY, { duration: 0 }),
347
- Animated.withSpring(0, springParams)
348
- );
349
- sx.value = Animated.withSequence(
350
- Animated.withTiming(scaleX, { duration: 0 }),
351
- Animated.withSpring(1, springParams)
352
- );
353
- sy.value = Animated.withSequence(
354
- Animated.withTiming(scaleY, { duration: 0 }),
355
- Animated.withSpring(1, springParams)
356
- );
357
- }
358
- var PresenceContext = react.createContext(null);
359
- function usePresence() {
360
- return react.useContext(PresenceContext);
361
- }
362
- function Presence({ children }) {
363
- const incoming = react.useMemo(() => {
364
- const out = [];
365
- react.Children.forEach(children, (child) => {
366
- if (!react.isValidElement(child)) return;
367
- if (child.key === null) {
368
- if (__DEV__) {
369
- console.warn(
370
- "[inertia] <Presence> children must have a `key`. Skipping a keyless child."
371
- );
372
- }
373
- return;
374
- }
375
- out.push(child);
376
- });
377
- return out;
378
- }, [children]);
379
- const [exiting, setExiting] = react.useState(
380
- () => /* @__PURE__ */ new Map()
381
- );
382
- const prevIncomingRef = react.useRef(incoming);
383
- if (prevIncomingRef.current !== incoming) {
384
- const prev = prevIncomingRef.current;
385
- prevIncomingRef.current = incoming;
386
- const incomingKeys = new Set(incoming.map((el) => el.key));
387
- let next = null;
388
- const ensureMutable = () => {
389
- if (!next) next = new Map(exiting);
390
- return next;
391
- };
392
- for (const oldEl of prev) {
393
- const key = oldEl.key;
394
- if (!incomingKeys.has(key) && !exiting.has(key)) {
395
- ensureMutable().set(key, oldEl);
396
- }
397
- }
398
- for (const el of incoming) {
399
- const key = el.key;
400
- if (exiting.has(key)) {
401
- ensureMutable().delete(key);
402
- }
403
- }
404
- if (next) setExiting(next);
405
- }
406
- const handleRemove = react.useCallback((key) => {
407
- setExiting((prev) => {
408
- if (!prev.has(key)) return prev;
409
- const next = new Map(prev);
410
- next.delete(key);
411
- return next;
412
- });
413
- }, []);
414
- const renderList = [];
415
- for (const el of incoming) {
416
- renderList.push({
417
- key: el.key,
418
- element: el,
419
- isPresent: true
420
- });
421
- }
422
- for (const [key, el] of exiting) {
423
- if (!renderList.some((entry) => entry.key === key)) {
424
- renderList.push({ key, element: el, isPresent: false });
425
- }
426
- }
427
- return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: renderList.map(({ key, element, isPresent }) => /* @__PURE__ */ jsxRuntime.jsx(
428
- PresenceItem,
429
- {
430
- itemKey: key,
431
- isPresent,
432
- onRemove: handleRemove,
433
- children: element
434
- },
435
- key
436
- )) });
437
- }
438
- function PresenceItem({
439
- itemKey,
440
- isPresent,
441
- onRemove,
442
- children
443
- }) {
444
- const value = react.useMemo(
445
- () => ({
446
- isPresent,
447
- safeToRemove: () => onRemove(itemKey)
448
- }),
449
- [isPresent, itemKey, onRemove]
450
- );
451
- return /* @__PURE__ */ jsxRuntime.jsx(PresenceContext.Provider, { value, children });
452
- }
453
- var DEFAULT_TIMING_DURATION = 250;
454
- function buildSpring(cfg, toValue, cb) {
455
- return Animated.withSpring(toValue, springToReanimated(cfg), cb);
456
- }
457
- function buildTiming(cfg, toValue, cb) {
458
- return Animated.withTiming(
459
- toValue,
460
- {
461
- duration: cfg.duration ?? DEFAULT_TIMING_DURATION,
462
- easing: ensureWorkletEasing(cfg.easing) ?? Animated.Easing.inOut(Animated.Easing.ease)
463
- },
464
- cb
465
- );
466
- }
467
- function buildDecay(cfg, cb) {
468
- return Animated.withDecay(
469
- {
470
- velocity: cfg.velocity ?? 0,
471
- deceleration: cfg.deceleration,
472
- clamp: cfg.clamp
473
- },
474
- cb
475
- );
476
- }
477
- function buildOne(cfg, toValue, cb) {
478
- if (cfg.type === "no-animation") {
479
- if (cb) cb(true, toValue);
480
- return toValue;
481
- }
482
- if (cfg.type === "decay") return buildDecay(cfg, cb);
483
- if (cfg.type === "timing") return buildTiming(cfg, toValue, cb);
484
- return buildSpring(cfg, toValue, cb);
485
- }
486
- function applyRepeat(animation, repeat) {
487
- if (repeat === void 0) return animation;
488
- if (repeat === "infinite") {
489
- return Animated.withRepeat(animation, -1, true);
490
- }
491
- if (typeof repeat === "number") {
492
- return Animated.withRepeat(animation, repeat, true);
493
- }
494
- const count = repeat.count === "infinite" ? -1 : repeat.count;
495
- const alternate = repeat.alternate ?? true;
496
- return Animated.withRepeat(animation, count, alternate);
497
- }
498
- function applyDelay(animation, delay) {
499
- if (!delay || delay <= 0) return animation;
500
- return Animated.withDelay(delay, animation);
501
- }
502
- function resolveTransition(config, toValue, callback) {
503
- const cfg = config ?? { type: "spring" };
504
- const base = buildOne(cfg, toValue, callback);
505
- const repeated = applyRepeat(base, repeatOf(cfg));
506
- return applyDelay(repeated, delayOf(cfg));
507
- }
508
- function repeatOf(cfg) {
509
- if (cfg.type === "no-animation" || cfg.type === "decay") return void 0;
510
- return cfg.repeat;
511
- }
512
- function stripRepeat(cfg) {
513
- if (!cfg) return cfg;
514
- if (cfg.type === "no-animation" || cfg.type === "decay") return cfg;
515
- if (cfg.repeat === void 0) return cfg;
516
- const next = { ...cfg };
517
- delete next.repeat;
518
- return next;
519
- }
520
- function delayOf(cfg) {
521
- if (cfg.type === "no-animation") return void 0;
522
- return cfg.delay;
523
- }
524
- function isStepObject(v) {
525
- return typeof v === "object" && v !== null && !Array.isArray(v) && "to" in v;
526
- }
527
- function resolveAnimatableValue(value, base, factory) {
528
- if (Array.isArray(value)) {
529
- const steps = value;
530
- const stepBase = stripRepeat(base);
531
- const animations = steps.map(
532
- (step2, i) => resolveStep(step2, stepBase, factory?.("step", i))
533
- );
534
- const seq = Animated.withSequence(...animations);
535
- return applyRepeat(seq, base ? repeatOf(base) : void 0);
536
- }
537
- const step = value;
538
- const cb = factory?.("animation", void 0);
539
- if (isStepObject(step)) {
540
- return resolveStep(step, base, cb);
541
- }
542
- return resolveTransition(base, step, cb);
543
- }
544
- function resolveStep(step, base, cb) {
545
- if (isStepObject(step)) {
546
- const { to, ...override } = step;
547
- const merged = mergeTransition(base, override);
548
- return resolveTransition(merged, to, cb);
549
- }
550
- return resolveTransition(base, step, cb);
551
- }
552
- function mergeTransition(base, override) {
553
- if (override.type && base && override.type !== base.type) {
554
- return override;
555
- }
556
- return { ...base ?? { type: "spring" }, ...override };
557
- }
558
- var CSS_KEYWORDS = {
559
- ease: [0.25, 0.1, 0.25, 1],
560
- "ease-in": [0.42, 0, 1, 1],
561
- "ease-out": [0, 0, 0.58, 1],
562
- "ease-in-out": [0.42, 0, 0.58, 1]
563
- };
564
- var CSS_FUNCTION = /^cubic-bezier\((.*)\)$/;
565
- function cubicBezier(first, y1, x2, y2) {
566
- if (typeof first === "string") return fromCss(first);
567
- return bezier(first, y1, x2, y2, void 0);
568
- }
569
- function fromCss(input) {
570
- const token = input.trim().toLowerCase();
571
- if (token === "linear") return Animated.Easing.linear;
572
- const keyword = CSS_KEYWORDS[token];
573
- if (keyword) return bezier(...keyword, input);
574
- const match = CSS_FUNCTION.exec(token);
575
- if (!match) {
576
- throw new Error(
577
- `[inertia] cubicBezier: unsupported easing token ${JSON.stringify(input)}. Expected four numbers, a 'cubic-bezier(x1, y1, x2, y2)' string, or one of the CSS keywords 'linear' | 'ease' | 'ease-in' | 'ease-out' | 'ease-in-out'.`
578
- );
579
- }
580
- const parts = match[1].split(",").map((p) => Number(p.trim()));
581
- if (parts.length !== 4 || parts.some((n) => !Number.isFinite(n))) {
582
- throw new Error(
583
- `[inertia] cubicBezier: could not parse ${JSON.stringify(input)} \u2014 expected exactly four finite numbers inside cubic-bezier(...).`
584
- );
585
- }
586
- return bezier(parts[0], parts[1], parts[2], parts[3], input);
587
- }
588
- function bezier(x1, y1, x2, y2, source) {
589
- const describe = () => source !== void 0 ? JSON.stringify(source) : `cubicBezier(${x1}, ${y1}, ${x2}, ${y2})`;
590
- for (const n of [x1, y1, x2, y2]) {
591
- if (typeof n !== "number" || !Number.isFinite(n)) {
592
- throw new Error(
593
- `[inertia] cubicBezier: ${describe()} \u2014 every control point must be a finite number.`
594
- );
595
- }
596
- }
597
- if (x1 < 0 || x1 > 1 || x2 < 0 || x2 > 1) {
598
- throw new Error(
599
- `[inertia] cubicBezier: ${describe()} \u2014 x1 and x2 must be within [0, 1] (got x1=${x1}, x2=${x2}).`
600
- );
601
- }
602
- return Animated.Easing.bezier(x1, y1, x2, y2);
603
- }
604
- var DEFAULT_TIMING_DURATION2 = 250;
605
- function buildReleaseAnimation(transition, toValue) {
606
- "worklet";
607
- if (transition.type === "no-animation") return toValue;
608
- if (transition.type === "decay") {
609
- const cfg = { velocity: transition.velocity ?? 0 };
610
- if (transition.deceleration !== void 0) {
611
- cfg.deceleration = transition.deceleration;
612
- }
613
- if (transition.clamp !== void 0) cfg.clamp = transition.clamp;
614
- return Animated.withDecay(cfg);
615
- }
616
- if (transition.type === "timing") {
617
- const e = transition.easing;
618
- const easingFn = e && typeof e === "object" && "factory" in e ? e.factory() : e ?? Animated.Easing.inOut(Animated.Easing.ease);
619
- return Animated.withTiming(toValue, {
620
- duration: transition.duration ?? DEFAULT_TIMING_DURATION2,
621
- easing: easingFn
622
- });
623
- }
624
- return Animated.withSpring(toValue, springToReanimated(transition));
625
- }
626
- var alreadyChecked = false;
627
- function ensureReanimatedInstalled() {
628
- if (!__DEV__ || alreadyChecked) return;
629
- if (typeof process !== "undefined" && process.env?.NODE_ENV === "test") {
630
- return;
631
- }
632
- alreadyChecked = true;
633
- const version = Animated.reanimatedVersion;
634
- if (version) {
635
- const major = parseInt(version.split(".")[0] ?? "0", 10);
636
- if (major < 4) {
637
- console.error(
638
- `[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).`
639
- );
640
- return;
641
- }
642
- }
643
- const probe = function probe2() {
644
- "worklet";
645
- return 0;
646
- };
647
- if (typeof probe.__workletHash !== "number") {
648
- console.error(
649
- `[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\`.`
650
- );
651
- }
652
- }
653
- var TRANSFORM_KEYS = [
654
- "translateX",
655
- "translateY",
656
- "scale",
657
- "scaleX",
658
- "scaleY",
659
- "rotate",
660
- "rotateX",
661
- "rotateY"
662
- ];
663
- var ROTATION_KEYS = /* @__PURE__ */ new Set(["rotate", "rotateX", "rotateY"]);
664
- var NUMERIC_TOP_LEVEL_KEYS = [
665
- "opacity",
666
- "width",
667
- "height",
668
- "borderRadius",
669
- "shadowOpacity",
670
- "shadowRadius",
671
- "elevation"
672
- ];
673
- var COLOR_KEYS = [
674
- "backgroundColor",
675
- "borderColor",
676
- "color",
677
- "tintColor",
678
- "shadowColor"
679
- ];
680
- var SHADOW_OFFSET_KEYS = ["shadowOffsetWidth", "shadowOffsetHeight"];
681
- var ALL_KEYS = [
682
- ...TRANSFORM_KEYS,
683
- ...NUMERIC_TOP_LEVEL_KEYS,
684
- ...COLOR_KEYS,
685
- ...SHADOW_OFFSET_KEYS
686
- ];
687
- var TRANSFORM_KEY_SET = new Set(TRANSFORM_KEYS);
688
- var COLOR_KEY_SET = new Set(COLOR_KEYS);
689
- var SHADOW_OFFSET_KEY_SET = new Set(SHADOW_OFFSET_KEYS);
690
- var GESTURE_LAYER_NAMES = [
691
- "hovered",
692
- "focused",
693
- "focusVisible",
694
- "pressed"
695
- ];
696
- var GESTURE_LAYER_NAME_SET = new Set(GESTURE_LAYER_NAMES);
697
- var EXITING_POINTER_EVENTS_STYLE = { pointerEvents: "none" };
698
- var DEFAULT_RESTING = {
699
- translateX: 0,
700
- translateY: 0,
701
- scale: 1,
702
- scaleX: 1,
703
- scaleY: 1,
704
- rotate: 0,
705
- rotateX: 0,
706
- rotateY: 0,
707
- opacity: 1,
708
- width: 0,
709
- height: 0,
710
- borderRadius: 0,
711
- shadowOpacity: 0,
712
- shadowRadius: 0,
713
- elevation: 0,
714
- // 'transparent' is the only safe universal default for colors: it works as
715
- // an initial seed for any color animation (no jarring opaque flash on mount
716
- // when `initial` is omitted) and rgba(0,0,0,0) interpolates cleanly into
717
- // any opaque target via Reanimated's color util.
718
- backgroundColor: "transparent",
719
- borderColor: "transparent",
720
- color: "transparent",
721
- tintColor: "transparent",
722
- shadowColor: "transparent",
723
- shadowOffsetWidth: 0,
724
- shadowOffsetHeight: 0
725
- };
726
- function transitionFor(prop, transition) {
727
- if (!transition) return void 0;
728
- if (typeof transition === "string") return void 0;
729
- if (isTopLevelTransition(transition)) return transition;
730
- if (GESTURE_LAYER_NAME_SET.has(prop)) return void 0;
731
- return transition[prop];
732
- }
733
- function gestureLayerTransitionFor(layer, transition) {
734
- if (!transition) return void 0;
735
- if (typeof transition === "string") return void 0;
736
- if (isTopLevelTransition(transition)) return transition;
737
- return transition[layer];
738
- }
739
- function createMotionComponent(Component) {
740
- ensureReanimatedInstalled();
741
- const AnimatedComponent = Animated__default.default.createAnimatedComponent(
742
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
743
- Component
744
- );
745
- const Motion2 = react.forwardRef(function Motion3(props, ref) {
746
- const {
747
- initial,
748
- animate,
749
- exit,
750
- transition: transitionProp,
751
- variants,
752
- controller,
753
- gesture,
754
- layout: layoutProp,
755
- layoutId,
756
- onAnimationEnd,
757
- style,
758
- onLayout: userOnLayout,
759
- ...rest
760
- } = props;
761
- const namedTransitions = useNamedTransitions();
762
- const transition = resolveNamedTransitionProp(
763
- transitionProp,
764
- namedTransitions
765
- );
766
- const layout = typeof layoutProp === "string" ? lookupNamedTransition(layoutProp, namedTransitions) : layoutProp;
767
- if (__DEV__ && typeof style === "function") {
768
- throw new Error(
769
- "[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."
770
- );
771
- }
772
- const presence = usePresence();
773
- const isExiting = presence !== null && presence.isPresent === false;
774
- const shouldReduceMotion = useShouldReduceMotion();
775
- const onAnimationEndRef = react.useRef(onAnimationEnd);
776
- onAnimationEndRef.current = onAnimationEnd;
777
- const variantKey = useControllerKey(controller);
778
- const resolvedAnimate = resolveAnimateInput(
779
- animate,
780
- variants,
781
- variantKey
782
- );
783
- const animateRecord = resolvedAnimate ?? {};
784
- const initialRecord = initial && initial !== false ? initial : void 0;
785
- const exitRecord = exit ? exit : void 0;
786
- const [pressed, setPressed] = react.useState(false);
787
- const [focused, setFocused] = react.useState(false);
788
- const [focusVisible, setFocusVisible] = react.useState(false);
789
- const [hovered, setHovered] = react.useState(false);
790
- const touched = /* @__PURE__ */ new Set();
791
- collectTouchedKeys(touched, animateRecord);
792
- if (initialRecord) collectTouchedKeys(touched, initialRecord);
793
- if (variants) {
794
- for (const variant of Object.values(variants)) {
795
- if (!variant) continue;
796
- collectTouchedKeys(touched, variant);
797
- }
798
- }
799
- if (gesture) {
800
- for (const subState of [
801
- gesture.pressed,
802
- gesture.focused,
803
- gesture.focusVisible,
804
- gesture.hovered
805
- ]) {
806
- if (!subState) continue;
807
- collectTouchedKeys(touched, subState);
808
- }
809
- }
810
- if (exitRecord) collectTouchedKeys(touched, exitRecord);
811
- const activeKeysRef = react.useRef(null);
812
- const hasTransformRef = react.useRef(false);
813
- const hasShadowOffsetRef = react.useRef(false);
814
- const prevActive = activeKeysRef.current;
815
- let grew = prevActive === null;
816
- if (!grew && prevActive) {
817
- for (const k of touched) {
818
- if (!prevActive.includes(k)) {
819
- grew = true;
820
- break;
821
- }
822
- }
823
- }
824
- if (grew) {
825
- const merged = new Set(prevActive ?? []);
826
- for (const k of touched) merged.add(k);
827
- activeKeysRef.current = ALL_KEYS.filter((k) => merged.has(k));
828
- hasTransformRef.current = activeKeysRef.current.some(
829
- (k) => TRANSFORM_KEY_SET.has(k)
830
- );
831
- hasShadowOffsetRef.current = activeKeysRef.current.some(
832
- (k) => SHADOW_OFFSET_KEY_SET.has(k)
833
- );
834
- }
835
- const sharedValues = useAnimatableSharedValues((key) => {
836
- if (SHADOW_OFFSET_KEY_SET.has(key)) {
837
- const axis = shadowOffsetAxisFor(key);
838
- if (initial === false) {
839
- return shadowOffsetAxisValue(animateRecord.shadowOffset, axis) ?? DEFAULT_RESTING[key];
840
- }
841
- return shadowOffsetAxisValue(
842
- initialRecord?.shadowOffset,
843
- axis
844
- ) ?? shadowOffsetAxisValue(animateRecord.shadowOffset, axis) ?? DEFAULT_RESTING[key];
845
- }
846
- if (initial === false) {
847
- const a = animateRecord[key];
848
- return restValue(a) ?? DEFAULT_RESTING[key];
849
- }
850
- return initialRecord?.[key] ?? restValue(animateRecord[key]) ?? DEFAULT_RESTING[key];
851
- });
852
- const pressedProgress = Animated.useSharedValue(0);
853
- const focusedProgress = Animated.useSharedValue(0);
854
- const focusVisibleProgress = Animated.useSharedValue(0);
855
- const hoveredProgress = Animated.useSharedValue(0);
856
- const gestureSV = Animated.useSharedValue(
857
- resolveGestureLayers(gesture)
858
- );
859
- const gestureTargetsSig = stableSig(gesture);
860
- react.useEffect(() => {
861
- gestureSV.value = resolveGestureLayers(gesture);
862
- }, [gestureTargetsSig]);
863
- const baseRecord = isExiting && exitRecord ? { ...animateRecord, ...exitRecord } : animateRecord;
864
- const baseSig = stableSig(baseRecord) + (isExiting ? "|exit" : "") + (shouldReduceMotion ? "|rm" : "");
865
- const transitionSig = stableSig(transition);
866
- const safeToRemoveRef = react.useRef(void 0);
867
- safeToRemoveRef.current = presence?.safeToRemove;
868
- react.useEffect(() => {
869
- if (isExiting && (!exitRecord || Object.keys(exitRecord).length === 0)) {
870
- safeToRemoveRef.current?.();
871
- return;
872
- }
873
- let pending = 0;
874
- let done = false;
875
- const onSettle = () => {
876
- if (done) return;
877
- pending--;
878
- if (pending <= 0) {
879
- done = true;
880
- if (isExiting) safeToRemoveRef.current?.();
881
- }
882
- };
883
- let transformPending = 0;
884
- for (const k of ALL_KEYS) {
885
- if (TRANSFORM_KEY_SET.has(k) && baseRecord[k] !== void 0) {
886
- transformPending++;
887
- }
888
- }
889
- const transformGroup = transformPending > 0 ? { remaining: transformPending } : void 0;
890
- for (const key of ALL_KEYS) {
891
- const target = SHADOW_OFFSET_KEY_SET.has(key) ? shadowOffsetAxisValue(
892
- baseRecord.shadowOffset,
893
- shadowOffsetAxisFor(key)
894
- ) : baseRecord[key];
895
- if (target === void 0) continue;
896
- const cfg = shouldReduceMotion ? { type: "no-animation" } : transitionFor(
897
- SHADOW_OFFSET_KEY_SET.has(key) ? "shadowOffset" : key,
898
- transition
899
- );
900
- if (isExiting) pending++;
901
- const factory = makeKeyCallbackFactory(
902
- key,
903
- sharedValues[key],
904
- targetEndValue(target),
905
- onAnimationEndRef,
906
- {
907
- stepCount: stepCountOf(target),
908
- totalIterations: totalIterationsOf(cfg)
909
- },
910
- isExiting ? onSettle : void 0,
911
- TRANSFORM_KEY_SET.has(key) ? transformGroup : void 0
912
- );
913
- sharedValues[key].value = resolveAnimatableValue(
914
- target,
915
- cfg,
916
- factory
917
- );
918
- }
919
- if (isExiting && pending === 0) {
920
- safeToRemoveRef.current?.();
921
- }
922
- }, [baseSig, transitionSig]);
923
- useGestureLayerProgress(
924
- pressedProgress,
925
- pressed,
926
- gesture?.pressed != null,
927
- "pressed",
928
- transition,
929
- isExiting,
930
- shouldReduceMotion
931
- );
932
- useGestureLayerProgress(
933
- focusedProgress,
934
- focused,
935
- gesture?.focused != null,
936
- "focused",
937
- transition,
938
- isExiting,
939
- shouldReduceMotion
940
- );
941
- useGestureLayerProgress(
942
- focusVisibleProgress,
943
- focusVisible,
944
- gesture?.focusVisible != null,
945
- "focusVisible",
946
- transition,
947
- isExiting,
948
- shouldReduceMotion
949
- );
950
- useGestureLayerProgress(
951
- hoveredProgress,
952
- hovered,
953
- gesture?.hovered != null,
954
- "hovered",
955
- transition,
956
- isExiting,
957
- shouldReduceMotion
958
- );
959
- const sharedLayout = useSharedLayout({
960
- layoutId,
961
- userRef: ref,
962
- transition: isTopLevelTransition(transition) ? transition : void 0,
963
- shouldReduceMotion,
964
- userOnLayout
965
- });
966
- const flip = sharedLayout.flip;
967
- const hasLayoutId = layoutId !== void 0;
968
- const animatedStyle = Animated.useAnimatedStyle(() => {
969
- const activeKeys = activeKeysRef.current;
970
- const hasTransform = hasTransformRef.current;
971
- const hasShadowOffset = hasShadowOffsetRef.current;
972
- const out = {};
973
- const transform = [];
974
- let shadowOffsetW = 0;
975
- let shadowOffsetH = 0;
976
- const ph = hoveredProgress.value;
977
- const pf = focusedProgress.value;
978
- const pfv = focusVisibleProgress.value;
979
- const pp = pressedProgress.value;
980
- const layers = gestureSV.value;
981
- const hoveredLayer = layers ? layers.hovered : null;
982
- const focusedLayer = layers ? layers.focused : null;
983
- const focusVisibleLayer = layers ? layers.focusVisible : null;
984
- const pressedLayer = layers ? layers.pressed : null;
985
- for (const key of activeKeys) {
986
- let v = sharedValues[key].value;
987
- const isColor = COLOR_KEY_SET.has(key);
988
- if (hoveredLayer && ph > 0 && hoveredLayer[key] !== void 0) {
989
- const t = hoveredLayer[key];
990
- v = isColor ? Animated.interpolateColor(ph, [0, 1], [v, t]) : v + (t - v) * ph;
991
- }
992
- if (focusedLayer && pf > 0 && focusedLayer[key] !== void 0) {
993
- const t = focusedLayer[key];
994
- v = isColor ? Animated.interpolateColor(pf, [0, 1], [v, t]) : v + (t - v) * pf;
995
- }
996
- if (focusVisibleLayer && pfv > 0 && focusVisibleLayer[key] !== void 0) {
997
- const t = focusVisibleLayer[key];
998
- v = isColor ? Animated.interpolateColor(pfv, [0, 1], [v, t]) : v + (t - v) * pfv;
999
- }
1000
- if (pressedLayer && pp > 0 && pressedLayer[key] !== void 0) {
1001
- const t = pressedLayer[key];
1002
- v = isColor ? Animated.interpolateColor(pp, [0, 1], [v, t]) : v + (t - v) * pp;
1003
- }
1004
- if (TRANSFORM_KEY_SET.has(key)) {
1005
- transform.push(
1006
- ROTATION_KEYS.has(key) ? { [key]: `${v}deg` } : { [key]: v }
1007
- );
1008
- } else if (key === "shadowOffsetWidth") {
1009
- shadowOffsetW = v;
1010
- } else if (key === "shadowOffsetHeight") {
1011
- shadowOffsetH = v;
1012
- } else {
1013
- out[key] = v;
1014
- }
1015
- }
1016
- if (hasLayoutId) {
1017
- transform.push({ translateX: flip.dx.value });
1018
- transform.push({ translateY: flip.dy.value });
1019
- transform.push({ scaleX: flip.sx.value });
1020
- transform.push({ scaleY: flip.sy.value });
1021
- }
1022
- if (hasTransform || hasLayoutId) out.transform = transform;
1023
- if (hasShadowOffset) {
1024
- out.shadowOffset = { width: shadowOffsetW, height: shadowOffsetH };
1025
- }
1026
- return out;
1027
- });
1028
- const mergedStyle = react.useMemo(
1029
- () => isExiting ? [style, animatedStyle, EXITING_POINTER_EVENTS_STYLE] : [style, animatedStyle],
1030
- [style, animatedStyle, isExiting]
1031
- );
1032
- const gestureHandlers = useGestureHandlers(
1033
- gesture,
1034
- rest,
1035
- setPressed,
1036
- setFocused,
1037
- setFocusVisible,
1038
- setHovered
1039
- );
1040
- const layoutSig = stableSig(layout);
1041
- const layoutTransition = react.useMemo(
1042
- () => shouldReduceMotion ? void 0 : resolveLayoutTransition(layout),
1043
- // eslint-disable-next-line react-hooks/exhaustive-deps
1044
- [layoutSig, shouldReduceMotion]
1045
- );
1046
- return /* @__PURE__ */ jsxRuntime.jsx(
1047
- AnimatedComponent,
1048
- {
1049
- ref: sharedLayout.setRef,
1050
- ...rest,
1051
- ...gestureHandlers,
1052
- onLayout: sharedLayout.onLayout,
1053
- layout: layoutTransition,
1054
- style: mergedStyle
1055
- }
1056
- );
1057
- });
1058
- Motion2.displayName = `Motion(${Component.displayName ?? Component.name ?? "Component"})`;
1059
- return Motion2;
1060
- }
1061
- function useAnimatableSharedValues(init) {
1062
- const translateX = Animated.useSharedValue(init("translateX"));
1063
- const translateY = Animated.useSharedValue(init("translateY"));
1064
- const scale = Animated.useSharedValue(init("scale"));
1065
- const scaleX = Animated.useSharedValue(init("scaleX"));
1066
- const scaleY = Animated.useSharedValue(init("scaleY"));
1067
- const rotate = Animated.useSharedValue(init("rotate"));
1068
- const rotateX = Animated.useSharedValue(init("rotateX"));
1069
- const rotateY = Animated.useSharedValue(init("rotateY"));
1070
- const opacity = Animated.useSharedValue(init("opacity"));
1071
- const width = Animated.useSharedValue(init("width"));
1072
- const height = Animated.useSharedValue(init("height"));
1073
- const borderRadius = Animated.useSharedValue(init("borderRadius"));
1074
- const shadowOpacity = Animated.useSharedValue(init("shadowOpacity"));
1075
- const shadowRadius = Animated.useSharedValue(init("shadowRadius"));
1076
- const elevation = Animated.useSharedValue(init("elevation"));
1077
- const backgroundColor = Animated.useSharedValue(
1078
- init("backgroundColor")
1079
- );
1080
- const borderColor = Animated.useSharedValue(init("borderColor"));
1081
- const color = Animated.useSharedValue(init("color"));
1082
- const tintColor = Animated.useSharedValue(init("tintColor"));
1083
- const shadowColor = Animated.useSharedValue(init("shadowColor"));
1084
- const shadowOffsetWidth = Animated.useSharedValue(
1085
- init("shadowOffsetWidth")
1086
- );
1087
- const shadowOffsetHeight = Animated.useSharedValue(
1088
- init("shadowOffsetHeight")
1089
- );
1090
- const ref = react.useRef(null);
1091
- if (ref.current === null) {
1092
- ref.current = {
1093
- translateX,
1094
- translateY,
1095
- scale,
1096
- scaleX,
1097
- scaleY,
1098
- rotate,
1099
- rotateX,
1100
- rotateY,
1101
- opacity,
1102
- width,
1103
- height,
1104
- borderRadius,
1105
- shadowOpacity,
1106
- shadowRadius,
1107
- elevation,
1108
- backgroundColor,
1109
- borderColor,
1110
- color,
1111
- tintColor,
1112
- shadowColor,
1113
- shadowOffsetWidth,
1114
- shadowOffsetHeight
1115
- };
1116
- }
1117
- return ref.current;
1118
- }
1119
- function makeKeyCallbackFactory(key, sharedValue, target, onAnimationEndRef, meta, onSettle, transformGroup) {
1120
- if (!onAnimationEndRef.current && !onSettle) return void 0;
1121
- const state = { iteration: 0 };
1122
- const isTransformKey = TRANSFORM_KEY_SET.has(key);
1123
- const dispatch = (rawPhase, step, finished, value) => {
1124
- const isLastIteration = state.iteration >= meta.totalIterations - 1;
1125
- let phase;
1126
- let isTerminal = false;
1127
- if (rawPhase === "step") {
1128
- const isLastInPass = step !== void 0 && step === meta.stepCount - 1;
1129
- if (!isLastInPass) {
1130
- phase = "step";
1131
- } else if (isLastIteration) {
1132
- phase = "animation";
1133
- isTerminal = true;
1134
- } else {
1135
- phase = "sequence";
1136
- }
1137
- } else if (isLastIteration) {
1138
- phase = "animation";
1139
- isTerminal = true;
1140
- } else {
1141
- phase = "repeat";
1142
- }
1143
- const reportedIteration = state.iteration;
1144
- if (phase === "sequence" || phase === "repeat") state.iteration++;
1145
- const fn = onAnimationEndRef.current;
1146
- if (fn) {
1147
- if (isTransformKey && transformGroup && phase === "animation") {
1148
- transformGroup.remaining--;
1149
- if (transformGroup.remaining <= 0) {
1150
- fn({
1151
- key: "transform",
1152
- finished,
1153
- value,
1154
- target,
1155
- phase,
1156
- step,
1157
- iteration: reportedIteration
1158
- });
1159
- }
1160
- } else {
1161
- fn({
1162
- key,
1163
- finished,
1164
- value,
1165
- target,
1166
- phase,
1167
- step,
1168
- iteration: reportedIteration
1169
- });
1170
- }
1171
- }
1172
- if (onSettle && isTerminal) onSettle();
1173
- };
1174
- return (rawPhase, step) => {
1175
- const cb = (finished) => {
1176
- "worklet";
1177
- Animated.runOnJS(dispatch)(rawPhase, step, !!finished, sharedValue.value);
1178
- };
1179
- return cb;
1180
- };
1181
- }
1182
- function shadowOffsetAxisFor(key) {
1183
- return key === "shadowOffsetWidth" ? "width" : "height";
1184
- }
1185
- function shadowOffsetAxisValue(source, axis) {
1186
- return source?.[axis];
1187
- }
1188
- function collectTouchedKeys(touched, record) {
1189
- for (const k of ALL_KEYS) {
1190
- if (k in record) touched.add(k);
1191
- }
1192
- if ("shadowOffset" in record && record.shadowOffset) {
1193
- const so = record.shadowOffset;
1194
- if (so.width !== void 0) touched.add("shadowOffsetWidth");
1195
- if (so.height !== void 0) touched.add("shadowOffsetHeight");
1196
- }
1197
- }
1198
- function stepCountOf(v) {
1199
- if (Array.isArray(v)) return v.length;
1200
- return 1;
1201
- }
1202
- function totalIterationsOf(cfg) {
1203
- if (!cfg || cfg.type === "no-animation" || cfg.type === "decay") return 1;
1204
- const r = cfg.repeat;
1205
- if (r === void 0) return 1;
1206
- if (r === "infinite") return Number.POSITIVE_INFINITY;
1207
- if (typeof r === "number") return r;
1208
- if (r.count === "infinite") return Number.POSITIVE_INFINITY;
1209
- return r.count;
1210
- }
1211
- function targetEndValue(v) {
1212
- if (v === void 0) return void 0;
1213
- if (typeof v === "number" || typeof v === "string") return v;
1214
- if (Array.isArray(v)) {
1215
- return v.length > 0 ? targetEndValue(v[v.length - 1]) : void 0;
1216
- }
1217
- if (typeof v === "object" && v !== null && "to" in v) {
1218
- const to = v.to;
1219
- return typeof to === "number" || typeof to === "string" ? to : void 0;
1220
- }
1221
- return void 0;
1222
- }
1223
- function useControllerKey(controller) {
1224
- const [, setTick] = react.useState(0);
1225
- react.useEffect(() => {
1226
- if (!controller) return;
1227
- const unsub = controller.subscribe(() => setTick((n) => n + 1));
1228
- return unsub;
1229
- }, [controller]);
1230
- return controller?.current;
1231
- }
1232
- function resolveAnimateInput(animate, variants, controllerKey) {
1233
- if (controllerKey !== void 0 && variants && controllerKey in variants) {
1234
- return variants[controllerKey];
1235
- }
1236
- if (typeof animate === "string") {
1237
- if (variants && animate in variants) return variants[animate];
1238
- if (__DEV__) {
1239
- console.warn(
1240
- `[inertia] animate="${animate}" but no matching variant. Did you forget to pass \`variants\`?`
1241
- );
1242
- }
1243
- return void 0;
1244
- }
1245
- return animate;
1246
- }
1247
- function restValue(v) {
1248
- if (v === void 0) return void 0;
1249
- if (typeof v === "number" || typeof v === "string") return v;
1250
- if (Array.isArray(v)) {
1251
- return v.length > 0 ? restValue(v[0]) : void 0;
1252
- }
1253
- if (typeof v === "object" && v !== null && "to" in v) {
1254
- const to = v.to;
1255
- return typeof to === "number" || typeof to === "string" ? to : void 0;
1256
- }
1257
- return void 0;
1258
- }
1259
- function resolveGestureLayers(gesture) {
1260
- if (!gesture) return null;
1261
- const out = {};
1262
- for (const layer of GESTURE_LAYER_NAMES) {
1263
- const subState = gesture[layer];
1264
- if (!subState) continue;
1265
- const resolved = {};
1266
- for (const key of ALL_KEYS) {
1267
- if (SHADOW_OFFSET_KEY_SET.has(key)) {
1268
- const axis = shadowOffsetAxisFor(key);
1269
- const so = subState.shadowOffset;
1270
- const v = shadowOffsetAxisValue(so, axis);
1271
- if (v !== void 0) resolved[key] = v;
1272
- continue;
1273
- }
1274
- const raw = subState[key];
1275
- if (raw === void 0) continue;
1276
- const t = targetEndValue(raw);
1277
- if (t !== void 0) resolved[key] = t;
1278
- }
1279
- out[layer] = resolved;
1280
- }
1281
- return out;
1282
- }
1283
- function useGestureLayerProgress(progress, active, declared, layer, transition, isExiting, shouldReduceMotion) {
1284
- const layerCfgSig = stableSig(gestureLayerTransitionFor(layer, transition));
1285
- react.useEffect(() => {
1286
- if (!declared) return;
1287
- if (isExiting) {
1288
- progress.value = 0;
1289
- return;
1290
- }
1291
- const target = active ? 1 : 0;
1292
- const cfg = shouldReduceMotion ? { type: "no-animation" } : gestureLayerTransitionFor(layer, transition) ?? { type: "spring" };
1293
- progress.value = resolveTransition(cfg, target);
1294
- }, [active, declared, isExiting, shouldReduceMotion, layerCfgSig]);
1295
- }
1296
- function useGestureHandlers(gesture, rest, setPressed, setFocused, setFocusVisible, setHovered) {
1297
- const hasPressed = gesture?.pressed ? 1 : 0;
1298
- const hasFocused = gesture?.focused ? 1 : 0;
1299
- const hasFocusVisible = gesture?.focusVisible ? 1 : 0;
1300
- const hasHovered = gesture?.hovered ? 1 : 0;
1301
- return react.useMemo(() => {
1302
- if (!gesture) return {};
1303
- const handlers = {};
1304
- if (gesture.pressed) {
1305
- handlers.onTouchStart = compose(rest.onTouchStart, () => setPressed(true));
1306
- handlers.onTouchEnd = compose(rest.onTouchEnd, () => setPressed(false));
1307
- handlers.onTouchCancel = compose(
1308
- rest.onTouchCancel,
1309
- () => setPressed(false)
1310
- );
1311
- handlers.onPressIn = compose(rest.onPressIn, () => setPressed(true));
1312
- handlers.onPressOut = compose(rest.onPressOut, () => setPressed(false));
1313
- }
1314
- if (gesture.focused || gesture.focusVisible) {
1315
- handlers.onFocus = compose(rest.onFocus, () => {
1316
- if (gesture.focused) setFocused(true);
1317
- if (gesture.focusVisible && isFocusVisible()) setFocusVisible(true);
1318
- });
1319
- handlers.onBlur = compose(rest.onBlur, () => {
1320
- if (gesture.focused) setFocused(false);
1321
- if (gesture.focusVisible) setFocusVisible(false);
1322
- });
1323
- }
1324
- if (gesture.hovered) {
1325
- handlers.onMouseEnter = compose(rest.onMouseEnter, () => setHovered(true));
1326
- handlers.onMouseLeave = compose(
1327
- rest.onMouseLeave,
1328
- () => setHovered(false)
1329
- );
1330
- }
1331
- return handlers;
1332
- }, [
1333
- hasPressed,
1334
- hasFocused,
1335
- hasFocusVisible,
1336
- hasHovered,
1337
- rest.onTouchStart,
1338
- rest.onTouchEnd,
1339
- rest.onTouchCancel,
1340
- rest.onPressIn,
1341
- rest.onPressOut,
1342
- rest.onFocus,
1343
- rest.onBlur,
1344
- rest.onMouseEnter,
1345
- rest.onMouseLeave
1346
- ]);
1347
- }
1348
- function compose(user, ours) {
1349
- if (typeof user !== "function") return ours;
1350
- return (event) => {
1351
- user(event);
1352
- ours(event);
1353
- };
1354
- }
1355
-
1356
- // src/motion/Image.tsx
1357
- var MotionImage = createMotionComponent(reactNative.Image);
1358
- var MotionPressable = createMotionComponent(reactNative.Pressable);
1359
- var MotionScrollView = createMotionComponent(reactNative.ScrollView);
1360
- var MotionText = createMotionComponent(reactNative.Text);
1361
- var MotionView = createMotionComponent(reactNative.View);
1362
-
1363
16
  // src/motion/index.ts
1364
17
  var Motion = {
1365
- View: MotionView,
1366
- Text: MotionText,
1367
- Image: MotionImage,
1368
- Pressable: MotionPressable,
1369
- ScrollView: MotionScrollView
18
+ View: chunkSCTX5Z7I_js.MotionView,
19
+ Text: chunkWZGMAXKC_js.MotionText,
20
+ Image: chunkNDKVHL3N_js.MotionImage,
21
+ Pressable: chunkOM5FXU4I_js.MotionPressable,
22
+ ScrollView: chunk5I3G43XA_js.MotionScrollView
1370
23
  };
1371
24
  function useAnimation(target, transition) {
1372
- const output = Animated.useSharedValue(target);
1373
- const shouldReduceMotion = useShouldReduceMotion();
1374
- const resolved = resolveNamedTransition(transition, useNamedTransitions());
1375
- const cfgSig = stableSig(resolved);
25
+ const output = reactNativeReanimated.useSharedValue(target);
26
+ const shouldReduceMotion = chunk6EP3S2PN_js.useShouldReduceMotion();
27
+ const resolved = chunk6EP3S2PN_js.resolveNamedTransition(transition, chunk6EP3S2PN_js.useNamedTransitions());
28
+ const cfgSig = chunkSFRNO6AW_js.stableSig(resolved);
1376
29
  react.useEffect(() => {
1377
30
  const cfg = shouldReduceMotion ? { type: "no-animation" } : resolved ?? { type: "spring" };
1378
- output.value = resolveTransition(cfg, target);
31
+ output.value = chunkSFRNO6AW_js.resolveTransition(cfg, target);
1379
32
  }, [target, cfgSig, shouldReduceMotion]);
1380
33
  return output;
1381
34
  }
1382
35
  function useSpring(target, config) {
1383
- const spring = resolveSpringInput(config, useNamedTransitions());
36
+ const spring = resolveSpringInput(config, chunk6EP3S2PN_js.useNamedTransitions());
1384
37
  const reanimConfig = react.useMemo(
1385
- () => springToReanimated(spring ?? {}),
38
+ () => chunkSFRNO6AW_js.springToReanimated(spring ?? {}),
1386
39
  // Keyed on the resolved primitive fields rather than the `config` object
1387
40
  // identity: callers routinely pass a fresh object literal each render, so
1388
41
  // depending on `config` itself would rebuild the Reanimated config on
@@ -1399,12 +52,12 @@ function useSpring(target, config) {
1399
52
  );
1400
53
  const isSharedTarget = isSharedValue(target);
1401
54
  const initial = isSharedTarget ? target.value : target;
1402
- const output = Animated.useSharedValue(initial);
55
+ const output = reactNativeReanimated.useSharedValue(initial);
1403
56
  react.useEffect(() => {
1404
57
  if (isSharedTarget) return;
1405
- output.value = Animated.withSpring(target, reanimConfig);
58
+ output.value = reactNativeReanimated.withSpring(target, reanimConfig);
1406
59
  }, [isSharedTarget, target, reanimConfig]);
1407
- Animated.useAnimatedReaction(
60
+ reactNativeReanimated.useAnimatedReaction(
1408
61
  () => {
1409
62
  "worklet";
1410
63
  if (!isSharedTarget) return null;
@@ -1413,7 +66,7 @@ function useSpring(target, config) {
1413
66
  (next, prev) => {
1414
67
  "worklet";
1415
68
  if (next === null || next === prev) return;
1416
- output.value = Animated.withSpring(next, reanimConfig);
69
+ output.value = reactNativeReanimated.withSpring(next, reanimConfig);
1417
70
  },
1418
71
  [isSharedTarget, reanimConfig]
1419
72
  );
@@ -1421,7 +74,7 @@ function useSpring(target, config) {
1421
74
  }
1422
75
  function resolveSpringInput(config, registry) {
1423
76
  if (typeof config !== "string") return config;
1424
- const cfg = lookupNamedTransition(config, registry);
77
+ const cfg = chunk6EP3S2PN_js.lookupNamedTransition(config, registry);
1425
78
  if (cfg.type === void 0 || cfg.type === "spring") return cfg;
1426
79
  if (__DEV__) {
1427
80
  console.warn(
@@ -1442,58 +95,13 @@ function useColorTransition(progress, range, options) {
1442
95
  const key = options?.key ?? "backgroundColor";
1443
96
  const from = range[0];
1444
97
  const to = range[1];
1445
- return Animated.useAnimatedStyle(() => {
98
+ return reactNativeReanimated.useAnimatedStyle(() => {
1446
99
  "worklet";
1447
- return { [key]: Animated.interpolateColor(progress.value, [0, 1], [from, to]) };
100
+ return { [key]: reactNativeReanimated.interpolateColor(progress.value, [0, 1], [from, to]) };
1448
101
  });
1449
102
  }
1450
- function useGesture(transition) {
1451
- const pressed = Animated.useSharedValue(0);
1452
- const focused = Animated.useSharedValue(0);
1453
- const focusVisible = Animated.useSharedValue(0);
1454
- const hovered = Animated.useSharedValue(0);
1455
- const shouldReduceMotion = useShouldReduceMotion();
1456
- const resolved = resolveNamedTransitionProp(transition, useNamedTransitions());
1457
- const setLayer = react.useCallback(
1458
- (sv, layer, target) => {
1459
- const cfg = shouldReduceMotion ? { type: "no-animation" } : layerTransition(layer, resolved) ?? { type: "spring" };
1460
- sv.value = resolveTransition(cfg, target);
1461
- },
1462
- // The transition is intentionally read on every call rather than cooked
1463
- // into the dep array — a fresh literal each render would otherwise
1464
- // rebuild the handler bag and break composing consumers that key off
1465
- // handler identity. `transition` is read inside the callback closure;
1466
- // shared values are stable so the only dep that matters is the reduce-
1467
- // motion flag.
1468
- // eslint-disable-next-line react-hooks/exhaustive-deps
1469
- [shouldReduceMotion]
1470
- );
1471
- const handlers = react.useMemo(
1472
- () => ({
1473
- onPressIn: () => setLayer(pressed, "pressed", 1),
1474
- onPressOut: () => setLayer(pressed, "pressed", 0),
1475
- onHoverIn: () => setLayer(hovered, "hovered", 1),
1476
- onHoverOut: () => setLayer(hovered, "hovered", 0),
1477
- onFocus: () => {
1478
- setLayer(focused, "focused", 1);
1479
- if (isFocusVisible()) setLayer(focusVisible, "focusVisible", 1);
1480
- },
1481
- onBlur: () => {
1482
- setLayer(focused, "focused", 0);
1483
- setLayer(focusVisible, "focusVisible", 0);
1484
- }
1485
- }),
1486
- [setLayer, pressed, focused, focusVisible, hovered]
1487
- );
1488
- return { pressed, focused, focusVisible, hovered, handlers };
1489
- }
1490
- function layerTransition(layer, transition) {
1491
- if (!transition) return void 0;
1492
- if (isTopLevelTransition(transition)) return transition;
1493
- return transition[layer];
1494
- }
1495
103
  function useMotionValue(initial) {
1496
- return Animated.useSharedValue(initial);
104
+ return reactNativeReanimated.useSharedValue(initial);
1497
105
  }
1498
106
  function useTransform(arg1, inputRange, outputRange, options) {
1499
107
  let producer;
@@ -1512,14 +120,14 @@ function useTransform(arg1, inputRange, outputRange, options) {
1512
120
  const extrapolateRight = mapExtrapolation(options?.extrapolateRight);
1513
121
  producer = isColor ? () => {
1514
122
  "worklet";
1515
- return Animated.interpolateColor(
123
+ return reactNativeReanimated.interpolateColor(
1516
124
  source.value,
1517
125
  input,
1518
126
  output
1519
127
  );
1520
128
  } : () => {
1521
129
  "worklet";
1522
- return Animated.interpolate(
130
+ return reactNativeReanimated.interpolate(
1523
131
  source.value,
1524
132
  input,
1525
133
  output,
@@ -1527,17 +135,17 @@ function useTransform(arg1, inputRange, outputRange, options) {
1527
135
  );
1528
136
  };
1529
137
  }
1530
- return Animated.useDerivedValue(producer);
138
+ return reactNativeReanimated.useDerivedValue(producer);
1531
139
  }
1532
140
  function mapExtrapolation(mode) {
1533
- if (mode === "identity") return Animated.Extrapolation.IDENTITY;
1534
- if (mode === "extend") return Animated.Extrapolation.EXTEND;
1535
- return Animated.Extrapolation.CLAMP;
141
+ if (mode === "identity") return reactNativeReanimated.Extrapolation.IDENTITY;
142
+ if (mode === "extend") return reactNativeReanimated.Extrapolation.EXTEND;
143
+ return reactNativeReanimated.Extrapolation.CLAMP;
1536
144
  }
1537
145
  function useScroll() {
1538
- const scrollX = Animated.useSharedValue(0);
1539
- const scrollY = Animated.useSharedValue(0);
1540
- const handler = Animated.useAnimatedScrollHandler({
146
+ const scrollX = reactNativeReanimated.useSharedValue(0);
147
+ const scrollY = reactNativeReanimated.useSharedValue(0);
148
+ const handler = reactNativeReanimated.useAnimatedScrollHandler({
1541
149
  onScroll: (event) => {
1542
150
  "worklet";
1543
151
  scrollX.value = event.contentOffset.x;
@@ -1572,26 +180,26 @@ function useShadow({
1572
180
  const offsetWTo = to.shadowOffset?.width ?? 0;
1573
181
  const offsetHFrom = from.shadowOffset?.height ?? 0;
1574
182
  const offsetHTo = to.shadowOffset?.height ?? 0;
1575
- return Animated.useAnimatedStyle(() => {
183
+ return reactNativeReanimated.useAnimatedStyle(() => {
1576
184
  "worklet";
1577
185
  const t = progress.value;
1578
186
  const out = {};
1579
187
  if (hasOpacity) {
1580
- out.shadowOpacity = Animated.interpolate(t, [0, 1], [opacityFrom, opacityTo]);
188
+ out.shadowOpacity = reactNativeReanimated.interpolate(t, [0, 1], [opacityFrom, opacityTo]);
1581
189
  }
1582
190
  if (hasRadius) {
1583
- out.shadowRadius = Animated.interpolate(t, [0, 1], [radiusFrom, radiusTo]);
191
+ out.shadowRadius = reactNativeReanimated.interpolate(t, [0, 1], [radiusFrom, radiusTo]);
1584
192
  }
1585
193
  if (hasElevation) {
1586
- out.elevation = Animated.interpolate(t, [0, 1], [elevationFrom, elevationTo]);
194
+ out.elevation = reactNativeReanimated.interpolate(t, [0, 1], [elevationFrom, elevationTo]);
1587
195
  }
1588
196
  if (hasColor) {
1589
- out.shadowColor = Animated.interpolateColor(t, [0, 1], [colorFrom, colorTo]);
197
+ out.shadowColor = reactNativeReanimated.interpolateColor(t, [0, 1], [colorFrom, colorTo]);
1590
198
  }
1591
199
  if (hasOffset) {
1592
200
  out.shadowOffset = {
1593
- width: Animated.interpolate(t, [0, 1], [offsetWFrom, offsetWTo]),
1594
- height: Animated.interpolate(t, [0, 1], [offsetHFrom, offsetHTo])
201
+ width: reactNativeReanimated.interpolate(t, [0, 1], [offsetWFrom, offsetWTo]),
202
+ height: reactNativeReanimated.interpolate(t, [0, 1], [offsetHFrom, offsetHTo])
1595
203
  };
1596
204
  }
1597
205
  return out;
@@ -1630,32 +238,89 @@ function useVariants(variants, initial) {
1630
238
  }, []);
1631
239
  }
1632
240
 
241
+ Object.defineProperty(exports, "useGesture", {
242
+ enumerable: true,
243
+ get: function () { return chunkQ6ZTMLTI_js.useGesture; }
244
+ });
245
+ Object.defineProperty(exports, "MotionView", {
246
+ enumerable: true,
247
+ get: function () { return chunkSCTX5Z7I_js.MotionView; }
248
+ });
249
+ Object.defineProperty(exports, "MotionText", {
250
+ enumerable: true,
251
+ get: function () { return chunkWZGMAXKC_js.MotionText; }
252
+ });
253
+ Object.defineProperty(exports, "MotionImage", {
254
+ enumerable: true,
255
+ get: function () { return chunkNDKVHL3N_js.MotionImage; }
256
+ });
257
+ Object.defineProperty(exports, "MotionPressable", {
258
+ enumerable: true,
259
+ get: function () { return chunkOM5FXU4I_js.MotionPressable; }
260
+ });
261
+ Object.defineProperty(exports, "MotionScrollView", {
262
+ enumerable: true,
263
+ get: function () { return chunk5I3G43XA_js.MotionScrollView; }
264
+ });
265
+ Object.defineProperty(exports, "Presence", {
266
+ enumerable: true,
267
+ get: function () { return chunk6UQ4KA6V_js.Presence; }
268
+ });
269
+ Object.defineProperty(exports, "createMotionComponent", {
270
+ enumerable: true,
271
+ get: function () { return chunk6UQ4KA6V_js.createMotionComponent; }
272
+ });
273
+ Object.defineProperty(exports, "usePresence", {
274
+ enumerable: true,
275
+ get: function () { return chunk6UQ4KA6V_js.usePresence; }
276
+ });
277
+ Object.defineProperty(exports, "MotionConfig", {
278
+ enumerable: true,
279
+ get: function () { return chunk6EP3S2PN_js.MotionConfig; }
280
+ });
281
+ Object.defineProperty(exports, "resolveNamedTransition", {
282
+ enumerable: true,
283
+ get: function () { return chunk6EP3S2PN_js.resolveNamedTransition; }
284
+ });
285
+ Object.defineProperty(exports, "useMotionConfig", {
286
+ enumerable: true,
287
+ get: function () { return chunk6EP3S2PN_js.useMotionConfig; }
288
+ });
289
+ Object.defineProperty(exports, "useNamedTransitions", {
290
+ enumerable: true,
291
+ get: function () { return chunk6EP3S2PN_js.useNamedTransitions; }
292
+ });
293
+ Object.defineProperty(exports, "useShouldReduceMotion", {
294
+ enumerable: true,
295
+ get: function () { return chunk6EP3S2PN_js.useShouldReduceMotion; }
296
+ });
297
+ Object.defineProperty(exports, "buildReleaseAnimation", {
298
+ enumerable: true,
299
+ get: function () { return chunkSFRNO6AW_js.buildReleaseAnimation; }
300
+ });
301
+ Object.defineProperty(exports, "cubicBezier", {
302
+ enumerable: true,
303
+ get: function () { return chunkSFRNO6AW_js.cubicBezier; }
304
+ });
305
+ Object.defineProperty(exports, "ensureWorkletEasing", {
306
+ enumerable: true,
307
+ get: function () { return chunkSFRNO6AW_js.ensureWorkletEasing; }
308
+ });
309
+ Object.defineProperty(exports, "resolveAnimatableValue", {
310
+ enumerable: true,
311
+ get: function () { return chunkSFRNO6AW_js.resolveAnimatableValue; }
312
+ });
313
+ Object.defineProperty(exports, "resolveTransition", {
314
+ enumerable: true,
315
+ get: function () { return chunkSFRNO6AW_js.resolveTransition; }
316
+ });
1633
317
  exports.Motion = Motion;
1634
- exports.MotionConfig = MotionConfig;
1635
- exports.MotionImage = MotionImage;
1636
- exports.MotionPressable = MotionPressable;
1637
- exports.MotionScrollView = MotionScrollView;
1638
- exports.MotionText = MotionText;
1639
- exports.MotionView = MotionView;
1640
- exports.Presence = Presence;
1641
- exports.buildReleaseAnimation = buildReleaseAnimation;
1642
- exports.createMotionComponent = createMotionComponent;
1643
- exports.cubicBezier = cubicBezier;
1644
- exports.ensureWorkletEasing = ensureWorkletEasing;
1645
- exports.resolveAnimatableValue = resolveAnimatableValue;
1646
- exports.resolveNamedTransition = resolveNamedTransition;
1647
- exports.resolveTransition = resolveTransition;
1648
318
  exports.useAnimation = useAnimation;
1649
319
  exports.useBooleanSpring = useBooleanSpring;
1650
320
  exports.useColorTransition = useColorTransition;
1651
- exports.useGesture = useGesture;
1652
- exports.useMotionConfig = useMotionConfig;
1653
321
  exports.useMotionValue = useMotionValue;
1654
- exports.useNamedTransitions = useNamedTransitions;
1655
- exports.usePresence = usePresence;
1656
322
  exports.useScroll = useScroll;
1657
323
  exports.useShadow = useShadow;
1658
- exports.useShouldReduceMotion = useShouldReduceMotion;
1659
324
  exports.useSpring = useSpring;
1660
325
  exports.useTransform = useTransform;
1661
326
  exports.useVariants = useVariants;