@rootnative/inertia 0.0.0-alpha.0 → 0.0.0-alpha.2
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/CHANGELOG.md +10 -0
- package/README.md +2 -0
- package/dist/gestureLayer/index.d.mts +48 -7
- package/dist/gestureLayer/index.d.ts +48 -7
- package/dist/gestureLayer/index.js +107 -30
- package/dist/gestureLayer/index.mjs +107 -30
- package/dist/index.d.mts +127 -16
- package/dist/index.d.ts +127 -16
- package/dist/index.js +177 -62
- package/dist/index.mjs +175 -63
- package/dist/motion/Image.d.mts +1 -1
- package/dist/motion/Image.d.ts +1 -1
- package/dist/motion/Image.js +90 -50
- package/dist/motion/Image.mjs +90 -50
- package/dist/motion/Pressable.d.mts +1 -1
- package/dist/motion/Pressable.d.ts +1 -1
- package/dist/motion/Pressable.js +90 -50
- package/dist/motion/Pressable.mjs +90 -50
- package/dist/motion/ScrollView.d.mts +1 -1
- package/dist/motion/ScrollView.d.ts +1 -1
- package/dist/motion/ScrollView.js +90 -50
- package/dist/motion/ScrollView.mjs +90 -50
- package/dist/motion/Text.d.mts +1 -1
- package/dist/motion/Text.d.ts +1 -1
- package/dist/motion/Text.js +90 -50
- package/dist/motion/Text.mjs +90 -50
- package/dist/motion/View.d.mts +1 -1
- package/dist/motion/View.d.ts +1 -1
- package/dist/motion/View.js +90 -50
- package/dist/motion/View.mjs +90 -50
- package/dist/testing/index.js +0 -2
- package/dist/testing/index.mjs +0 -2
- package/dist/touch/index.d.mts +1 -1
- package/dist/touch/index.d.ts +1 -1
- package/dist/touch/index.js +0 -2
- package/dist/touch/index.mjs +0 -2
- package/dist/{types-cU43dEmH.d.mts → types-BzEgiUdJ.d.mts} +58 -9
- package/dist/{types-cU43dEmH.d.ts → types-BzEgiUdJ.d.ts} +58 -9
- package/dist/{useGesture-BnY65PlQ.d.ts → useGesture-BRLgiNOC.d.ts} +6 -4
- package/dist/{useGesture-DxtXdz-K.d.mts → useGesture-C0GBS7d2.d.mts} +6 -4
- package/llms.txt +9 -5
- package/package.json +2 -1
- package/src/config/MotionConfig.tsx +55 -9
- package/src/config/MotionConfigContext.ts +21 -1
- package/src/config/index.ts +7 -1
- package/src/config/namedTransitions.ts +80 -0
- package/src/gestureLayer/index.ts +1 -0
- package/src/gestureLayer/useGestureLayer.ts +92 -8
- package/src/index.ts +20 -2
- package/src/motion/createMotionComponent.tsx +36 -6
- package/src/transitions/cubicBezier.ts +126 -0
- package/src/transitions/index.ts +1 -0
- package/src/types.ts +63 -8
- package/src/values/useAnimation.ts +12 -6
- package/src/values/useBooleanSpring.ts +5 -3
- package/src/values/useGesture.ts +25 -7
- package/src/values/useMotionValue.ts +11 -0
- package/src/values/useScroll.ts +8 -1
- package/src/values/useSpring.ts +46 -9
- package/dist/gestureLayer/index.js.map +0 -1
- package/dist/gestureLayer/index.mjs.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/index.mjs.map +0 -1
- package/dist/motion/Image.js.map +0 -1
- package/dist/motion/Image.mjs.map +0 -1
- package/dist/motion/Pressable.js.map +0 -1
- package/dist/motion/Pressable.mjs.map +0 -1
- package/dist/motion/ScrollView.js.map +0 -1
- package/dist/motion/ScrollView.mjs.map +0 -1
- package/dist/motion/Text.js.map +0 -1
- package/dist/motion/Text.mjs.map +0 -1
- package/dist/motion/View.js.map +0 -1
- package/dist/motion/View.mjs.map +0 -1
- package/dist/testing/index.js.map +0 -1
- package/dist/testing/index.mjs.map +0 -1
- package/dist/touch/index.js.map +0 -1
- package/dist/touch/index.mjs.map +0 -1
- package/src/__type-tests__/animate.test-d.tsx +0 -88
- package/src/__type-tests__/variants.test-d.tsx +0 -67
package/dist/index.mjs
CHANGED
|
@@ -5,8 +5,31 @@ import { jsx, Fragment } from 'react/jsx-runtime';
|
|
|
5
5
|
import { isWorkletFunction } from 'react-native-worklets';
|
|
6
6
|
|
|
7
7
|
// src/motion/Image.tsx
|
|
8
|
+
|
|
9
|
+
// src/transitions/sig.ts
|
|
10
|
+
function stableSig(value) {
|
|
11
|
+
if (value === void 0) return "";
|
|
12
|
+
try {
|
|
13
|
+
return stableStringify(value);
|
|
14
|
+
} catch {
|
|
15
|
+
return String(value);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
function stableStringify(v) {
|
|
19
|
+
if (v === null || typeof v !== "object") {
|
|
20
|
+
if (typeof v === "function" || v === void 0) return "null";
|
|
21
|
+
return JSON.stringify(v);
|
|
22
|
+
}
|
|
23
|
+
if (Array.isArray(v)) {
|
|
24
|
+
return "[" + v.map(stableStringify).join(",") + "]";
|
|
25
|
+
}
|
|
26
|
+
const obj = v;
|
|
27
|
+
const keys = Object.keys(obj).sort();
|
|
28
|
+
return "{" + keys.map((k) => JSON.stringify(k) + ":" + stableStringify(obj[k])).join(",") + "}";
|
|
29
|
+
}
|
|
8
30
|
var DEFAULT_MOTION_CONFIG = {
|
|
9
|
-
reducedMotion: "user"
|
|
31
|
+
reducedMotion: "user",
|
|
32
|
+
transitions: {}
|
|
10
33
|
};
|
|
11
34
|
var MotionConfigContext = createContext(
|
|
12
35
|
DEFAULT_MOTION_CONFIG
|
|
@@ -14,6 +37,9 @@ var MotionConfigContext = createContext(
|
|
|
14
37
|
function useMotionConfig() {
|
|
15
38
|
return useContext(MotionConfigContext);
|
|
16
39
|
}
|
|
40
|
+
function useNamedTransitions() {
|
|
41
|
+
return useMotionConfig().transitions;
|
|
42
|
+
}
|
|
17
43
|
function useShouldReduceMotion() {
|
|
18
44
|
const { reducedMotion } = useMotionConfig();
|
|
19
45
|
const osReduced = useReducedMotion();
|
|
@@ -22,15 +48,80 @@ function useShouldReduceMotion() {
|
|
|
22
48
|
return osReduced;
|
|
23
49
|
}
|
|
24
50
|
function MotionConfig({
|
|
25
|
-
reducedMotion
|
|
51
|
+
reducedMotion,
|
|
52
|
+
transitions,
|
|
26
53
|
children
|
|
27
54
|
}) {
|
|
55
|
+
const parent = useMotionConfig();
|
|
56
|
+
const transitionsSig = stableSig(transitions);
|
|
28
57
|
const value = useMemo(
|
|
29
|
-
() => ({
|
|
30
|
-
|
|
58
|
+
() => ({
|
|
59
|
+
reducedMotion: reducedMotion ?? parent.reducedMotion,
|
|
60
|
+
transitions: transitions ? { ...parent.transitions, ...transitions } : parent.transitions
|
|
61
|
+
}),
|
|
62
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
63
|
+
[reducedMotion, transitionsSig, parent]
|
|
31
64
|
);
|
|
32
65
|
return /* @__PURE__ */ jsx(MotionConfigContext.Provider, { value, children });
|
|
33
66
|
}
|
|
67
|
+
|
|
68
|
+
// src/transitions/keys.ts
|
|
69
|
+
var TRANSITION_CONFIG_KEYS = /* @__PURE__ */ new Set([
|
|
70
|
+
"type",
|
|
71
|
+
"tension",
|
|
72
|
+
"friction",
|
|
73
|
+
"mass",
|
|
74
|
+
"velocity",
|
|
75
|
+
"restSpeedThreshold",
|
|
76
|
+
"restDisplacementThreshold",
|
|
77
|
+
"duration",
|
|
78
|
+
"easing",
|
|
79
|
+
"delay",
|
|
80
|
+
"repeat",
|
|
81
|
+
"deceleration",
|
|
82
|
+
"clamp"
|
|
83
|
+
]);
|
|
84
|
+
function isTopLevelTransition(t) {
|
|
85
|
+
if (t === null || typeof t !== "object") return false;
|
|
86
|
+
const keys = Object.keys(t);
|
|
87
|
+
if (keys.length === 0) return false;
|
|
88
|
+
return keys.every((k) => TRANSITION_CONFIG_KEYS.has(k));
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// src/config/namedTransitions.ts
|
|
92
|
+
var UNKNOWN_NAME_FALLBACK = { type: "spring" };
|
|
93
|
+
function lookupNamedTransition(name, registry) {
|
|
94
|
+
const cfg = registry[name];
|
|
95
|
+
if (cfg) return cfg;
|
|
96
|
+
if (__DEV__) {
|
|
97
|
+
console.warn(
|
|
98
|
+
`[inertia] Unknown transition name "${name}" \u2014 falling back to the default spring. Register it on a provider: <MotionConfig transitions={{ '${name}': { ... } }}>.`
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
return UNKNOWN_NAME_FALLBACK;
|
|
102
|
+
}
|
|
103
|
+
function resolveNamedTransition(input, registry) {
|
|
104
|
+
if (input === void 0) return void 0;
|
|
105
|
+
if (typeof input === "string") return lookupNamedTransition(input, registry);
|
|
106
|
+
return input;
|
|
107
|
+
}
|
|
108
|
+
function resolveNamedTransitionProp(transition, registry) {
|
|
109
|
+
if (transition === void 0) return void 0;
|
|
110
|
+
if (typeof transition === "string") {
|
|
111
|
+
return lookupNamedTransition(transition, registry);
|
|
112
|
+
}
|
|
113
|
+
if (isTopLevelTransition(transition)) return transition;
|
|
114
|
+
const map = transition;
|
|
115
|
+
let out = null;
|
|
116
|
+
for (const key in map) {
|
|
117
|
+
const value = map[key];
|
|
118
|
+
if (typeof value === "string") {
|
|
119
|
+
if (out === null) out = { ...map };
|
|
120
|
+
out[key] = lookupNamedTransition(value, registry);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
return out ?? transition;
|
|
124
|
+
}
|
|
34
125
|
var modality = "keyboard";
|
|
35
126
|
var installed = false;
|
|
36
127
|
function setKeyboard() {
|
|
@@ -458,28 +549,51 @@ function mergeTransition(base, override) {
|
|
|
458
549
|
}
|
|
459
550
|
return { ...base ?? { type: "spring" }, ...override };
|
|
460
551
|
}
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
"
|
|
465
|
-
"
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
"
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
"
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
552
|
+
var CSS_KEYWORDS = {
|
|
553
|
+
ease: [0.25, 0.1, 0.25, 1],
|
|
554
|
+
"ease-in": [0.42, 0, 1, 1],
|
|
555
|
+
"ease-out": [0, 0, 0.58, 1],
|
|
556
|
+
"ease-in-out": [0.42, 0, 0.58, 1]
|
|
557
|
+
};
|
|
558
|
+
var CSS_FUNCTION = /^cubic-bezier\((.*)\)$/;
|
|
559
|
+
function cubicBezier(first, y1, x2, y2) {
|
|
560
|
+
if (typeof first === "string") return fromCss(first);
|
|
561
|
+
return bezier(first, y1, x2, y2, void 0);
|
|
562
|
+
}
|
|
563
|
+
function fromCss(input) {
|
|
564
|
+
const token = input.trim().toLowerCase();
|
|
565
|
+
if (token === "linear") return Easing.linear;
|
|
566
|
+
const keyword = CSS_KEYWORDS[token];
|
|
567
|
+
if (keyword) return bezier(...keyword, input);
|
|
568
|
+
const match = CSS_FUNCTION.exec(token);
|
|
569
|
+
if (!match) {
|
|
570
|
+
throw new Error(
|
|
571
|
+
`[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'.`
|
|
572
|
+
);
|
|
573
|
+
}
|
|
574
|
+
const parts = match[1].split(",").map((p) => Number(p.trim()));
|
|
575
|
+
if (parts.length !== 4 || parts.some((n) => !Number.isFinite(n))) {
|
|
576
|
+
throw new Error(
|
|
577
|
+
`[inertia] cubicBezier: could not parse ${JSON.stringify(input)} \u2014 expected exactly four finite numbers inside cubic-bezier(...).`
|
|
578
|
+
);
|
|
579
|
+
}
|
|
580
|
+
return bezier(parts[0], parts[1], parts[2], parts[3], input);
|
|
581
|
+
}
|
|
582
|
+
function bezier(x1, y1, x2, y2, source) {
|
|
583
|
+
const describe = () => source !== void 0 ? JSON.stringify(source) : `cubicBezier(${x1}, ${y1}, ${x2}, ${y2})`;
|
|
584
|
+
for (const n of [x1, y1, x2, y2]) {
|
|
585
|
+
if (typeof n !== "number" || !Number.isFinite(n)) {
|
|
586
|
+
throw new Error(
|
|
587
|
+
`[inertia] cubicBezier: ${describe()} \u2014 every control point must be a finite number.`
|
|
588
|
+
);
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
if (x1 < 0 || x1 > 1 || x2 < 0 || x2 > 1) {
|
|
592
|
+
throw new Error(
|
|
593
|
+
`[inertia] cubicBezier: ${describe()} \u2014 x1 and x2 must be within [0, 1] (got x1=${x1}, x2=${x2}).`
|
|
594
|
+
);
|
|
595
|
+
}
|
|
596
|
+
return Easing.bezier(x1, y1, x2, y2);
|
|
483
597
|
}
|
|
484
598
|
var DEFAULT_TIMING_DURATION2 = 250;
|
|
485
599
|
function buildReleaseAnimation(transition, toValue) {
|
|
@@ -503,28 +617,6 @@ function buildReleaseAnimation(transition, toValue) {
|
|
|
503
617
|
}
|
|
504
618
|
return withSpring(toValue, springToReanimated(transition));
|
|
505
619
|
}
|
|
506
|
-
|
|
507
|
-
// src/transitions/sig.ts
|
|
508
|
-
function stableSig(value) {
|
|
509
|
-
if (value === void 0) return "";
|
|
510
|
-
try {
|
|
511
|
-
return stableStringify(value);
|
|
512
|
-
} catch {
|
|
513
|
-
return String(value);
|
|
514
|
-
}
|
|
515
|
-
}
|
|
516
|
-
function stableStringify(v) {
|
|
517
|
-
if (v === null || typeof v !== "object") {
|
|
518
|
-
if (typeof v === "function" || v === void 0) return "null";
|
|
519
|
-
return JSON.stringify(v);
|
|
520
|
-
}
|
|
521
|
-
if (Array.isArray(v)) {
|
|
522
|
-
return "[" + v.map(stableStringify).join(",") + "]";
|
|
523
|
-
}
|
|
524
|
-
const obj = v;
|
|
525
|
-
const keys = Object.keys(obj).sort();
|
|
526
|
-
return "{" + keys.map((k) => JSON.stringify(k) + ":" + stableStringify(obj[k])).join(",") + "}";
|
|
527
|
-
}
|
|
528
620
|
var alreadyChecked = false;
|
|
529
621
|
function ensureReanimatedInstalled() {
|
|
530
622
|
if (!__DEV__ || alreadyChecked) return;
|
|
@@ -627,12 +719,14 @@ var DEFAULT_RESTING = {
|
|
|
627
719
|
};
|
|
628
720
|
function transitionFor(prop, transition) {
|
|
629
721
|
if (!transition) return void 0;
|
|
722
|
+
if (typeof transition === "string") return void 0;
|
|
630
723
|
if (isTopLevelTransition(transition)) return transition;
|
|
631
724
|
if (GESTURE_LAYER_NAME_SET.has(prop)) return void 0;
|
|
632
725
|
return transition[prop];
|
|
633
726
|
}
|
|
634
727
|
function gestureLayerTransitionFor(layer, transition) {
|
|
635
728
|
if (!transition) return void 0;
|
|
729
|
+
if (typeof transition === "string") return void 0;
|
|
636
730
|
if (isTopLevelTransition(transition)) return transition;
|
|
637
731
|
return transition[layer];
|
|
638
732
|
}
|
|
@@ -647,17 +741,23 @@ function createMotionComponent(Component) {
|
|
|
647
741
|
initial,
|
|
648
742
|
animate,
|
|
649
743
|
exit,
|
|
650
|
-
transition,
|
|
744
|
+
transition: transitionProp,
|
|
651
745
|
variants,
|
|
652
746
|
controller,
|
|
653
747
|
gesture,
|
|
654
|
-
layout,
|
|
748
|
+
layout: layoutProp,
|
|
655
749
|
layoutId,
|
|
656
750
|
onAnimationEnd,
|
|
657
751
|
style,
|
|
658
752
|
onLayout: userOnLayout,
|
|
659
753
|
...rest
|
|
660
754
|
} = props;
|
|
755
|
+
const namedTransitions = useNamedTransitions();
|
|
756
|
+
const transition = resolveNamedTransitionProp(
|
|
757
|
+
transitionProp,
|
|
758
|
+
namedTransitions
|
|
759
|
+
);
|
|
760
|
+
const layout = typeof layoutProp === "string" ? lookupNamedTransition(layoutProp, namedTransitions) : layoutProp;
|
|
661
761
|
if (__DEV__ && typeof style === "function") {
|
|
662
762
|
throw new Error(
|
|
663
763
|
"[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."
|
|
@@ -1265,28 +1365,30 @@ var Motion = {
|
|
|
1265
1365
|
function useAnimation(target, transition) {
|
|
1266
1366
|
const output = useSharedValue(target);
|
|
1267
1367
|
const shouldReduceMotion = useShouldReduceMotion();
|
|
1268
|
-
const
|
|
1368
|
+
const resolved = resolveNamedTransition(transition, useNamedTransitions());
|
|
1369
|
+
const cfgSig = stableSig(resolved);
|
|
1269
1370
|
useEffect(() => {
|
|
1270
|
-
const cfg = shouldReduceMotion ? { type: "no-animation" } :
|
|
1371
|
+
const cfg = shouldReduceMotion ? { type: "no-animation" } : resolved ?? { type: "spring" };
|
|
1271
1372
|
output.value = resolveTransition(cfg, target);
|
|
1272
1373
|
}, [target, cfgSig, shouldReduceMotion]);
|
|
1273
1374
|
return output;
|
|
1274
1375
|
}
|
|
1275
1376
|
function useSpring(target, config) {
|
|
1377
|
+
const spring = resolveSpringInput(config, useNamedTransitions());
|
|
1276
1378
|
const reanimConfig = useMemo(
|
|
1277
|
-
() => springToReanimated(
|
|
1379
|
+
() => springToReanimated(spring ?? {}),
|
|
1278
1380
|
// Keyed on the resolved primitive fields rather than the `config` object
|
|
1279
1381
|
// identity: callers routinely pass a fresh object literal each render, so
|
|
1280
1382
|
// depending on `config` itself would rebuild the Reanimated config on
|
|
1281
1383
|
// every render and defeat the memo.
|
|
1282
1384
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
1283
1385
|
[
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1386
|
+
spring?.tension,
|
|
1387
|
+
spring?.friction,
|
|
1388
|
+
spring?.mass,
|
|
1389
|
+
spring?.velocity,
|
|
1390
|
+
spring?.restSpeedThreshold,
|
|
1391
|
+
spring?.restDisplacementThreshold
|
|
1290
1392
|
]
|
|
1291
1393
|
);
|
|
1292
1394
|
const isSharedTarget = isSharedValue(target);
|
|
@@ -1311,6 +1413,17 @@ function useSpring(target, config) {
|
|
|
1311
1413
|
);
|
|
1312
1414
|
return output;
|
|
1313
1415
|
}
|
|
1416
|
+
function resolveSpringInput(config, registry) {
|
|
1417
|
+
if (typeof config !== "string") return config;
|
|
1418
|
+
const cfg = lookupNamedTransition(config, registry);
|
|
1419
|
+
if (cfg.type === void 0 || cfg.type === "spring") return cfg;
|
|
1420
|
+
if (__DEV__) {
|
|
1421
|
+
console.warn(
|
|
1422
|
+
`[inertia] Named transition "${config}" resolves to type '${cfg.type}', but useSpring / useBooleanSpring are spring-only \u2014 falling back to the default spring. Use useAnimation to honor non-spring named transitions.`
|
|
1423
|
+
);
|
|
1424
|
+
}
|
|
1425
|
+
return void 0;
|
|
1426
|
+
}
|
|
1314
1427
|
function isSharedValue(v) {
|
|
1315
1428
|
return typeof v === "object" && v !== null && "value" in v;
|
|
1316
1429
|
}
|
|
@@ -1334,9 +1447,10 @@ function useGesture(transition) {
|
|
|
1334
1447
|
const focusVisible = useSharedValue(0);
|
|
1335
1448
|
const hovered = useSharedValue(0);
|
|
1336
1449
|
const shouldReduceMotion = useShouldReduceMotion();
|
|
1450
|
+
const resolved = resolveNamedTransitionProp(transition, useNamedTransitions());
|
|
1337
1451
|
const setLayer = useCallback(
|
|
1338
1452
|
(sv, layer, target) => {
|
|
1339
|
-
const cfg = shouldReduceMotion ? { type: "no-animation" } : layerTransition(layer,
|
|
1453
|
+
const cfg = shouldReduceMotion ? { type: "no-animation" } : layerTransition(layer, resolved) ?? { type: "spring" };
|
|
1340
1454
|
sv.value = resolveTransition(cfg, target);
|
|
1341
1455
|
},
|
|
1342
1456
|
// The transition is intentionally read on every call rather than cooked
|
|
@@ -1510,6 +1624,4 @@ function useVariants(variants, initial) {
|
|
|
1510
1624
|
}, []);
|
|
1511
1625
|
}
|
|
1512
1626
|
|
|
1513
|
-
export { Motion, MotionConfig, MotionImage, MotionPressable, MotionScrollView, MotionText, MotionView, Presence, buildReleaseAnimation, createMotionComponent, ensureWorkletEasing, resolveAnimatableValue, resolveTransition, useAnimation, useBooleanSpring, useColorTransition, useGesture, useMotionConfig, useMotionValue, usePresence, useScroll, useShadow, useShouldReduceMotion, useSpring, useTransform, useVariants };
|
|
1514
|
-
//# sourceMappingURL=index.mjs.map
|
|
1515
|
-
//# sourceMappingURL=index.mjs.map
|
|
1627
|
+
export { Motion, MotionConfig, MotionImage, MotionPressable, MotionScrollView, MotionText, MotionView, Presence, buildReleaseAnimation, createMotionComponent, cubicBezier, ensureWorkletEasing, resolveAnimatableValue, resolveNamedTransition, resolveTransition, useAnimation, useBooleanSpring, useColorTransition, useGesture, useMotionConfig, useMotionValue, useNamedTransitions, usePresence, useScroll, useShadow, useShouldReduceMotion, useSpring, useTransform, useVariants };
|
package/dist/motion/Image.d.mts
CHANGED
package/dist/motion/Image.d.ts
CHANGED
package/dist/motion/Image.js
CHANGED
|
@@ -11,8 +11,31 @@ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
|
11
11
|
var Animated__default = /*#__PURE__*/_interopDefault(Animated);
|
|
12
12
|
|
|
13
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
|
+
}
|
|
14
36
|
var DEFAULT_MOTION_CONFIG = {
|
|
15
|
-
reducedMotion: "user"
|
|
37
|
+
reducedMotion: "user",
|
|
38
|
+
transitions: {}
|
|
16
39
|
};
|
|
17
40
|
var MotionConfigContext = react.createContext(
|
|
18
41
|
DEFAULT_MOTION_CONFIG
|
|
@@ -20,6 +43,9 @@ var MotionConfigContext = react.createContext(
|
|
|
20
43
|
function useMotionConfig() {
|
|
21
44
|
return react.useContext(MotionConfigContext);
|
|
22
45
|
}
|
|
46
|
+
function useNamedTransitions() {
|
|
47
|
+
return useMotionConfig().transitions;
|
|
48
|
+
}
|
|
23
49
|
function useShouldReduceMotion() {
|
|
24
50
|
const { reducedMotion } = useMotionConfig();
|
|
25
51
|
const osReduced = Animated.useReducedMotion();
|
|
@@ -27,6 +53,59 @@ function useShouldReduceMotion() {
|
|
|
27
53
|
if (reducedMotion === "always") return true;
|
|
28
54
|
return osReduced;
|
|
29
55
|
}
|
|
56
|
+
|
|
57
|
+
// src/transitions/keys.ts
|
|
58
|
+
var TRANSITION_CONFIG_KEYS = /* @__PURE__ */ new Set([
|
|
59
|
+
"type",
|
|
60
|
+
"tension",
|
|
61
|
+
"friction",
|
|
62
|
+
"mass",
|
|
63
|
+
"velocity",
|
|
64
|
+
"restSpeedThreshold",
|
|
65
|
+
"restDisplacementThreshold",
|
|
66
|
+
"duration",
|
|
67
|
+
"easing",
|
|
68
|
+
"delay",
|
|
69
|
+
"repeat",
|
|
70
|
+
"deceleration",
|
|
71
|
+
"clamp"
|
|
72
|
+
]);
|
|
73
|
+
function isTopLevelTransition(t) {
|
|
74
|
+
if (t === null || typeof t !== "object") return false;
|
|
75
|
+
const keys = Object.keys(t);
|
|
76
|
+
if (keys.length === 0) return false;
|
|
77
|
+
return keys.every((k) => TRANSITION_CONFIG_KEYS.has(k));
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// src/config/namedTransitions.ts
|
|
81
|
+
var UNKNOWN_NAME_FALLBACK = { type: "spring" };
|
|
82
|
+
function lookupNamedTransition(name, registry) {
|
|
83
|
+
const cfg = registry[name];
|
|
84
|
+
if (cfg) return cfg;
|
|
85
|
+
if (__DEV__) {
|
|
86
|
+
console.warn(
|
|
87
|
+
`[inertia] Unknown transition name "${name}" \u2014 falling back to the default spring. Register it on a provider: <MotionConfig transitions={{ '${name}': { ... } }}>.`
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
return UNKNOWN_NAME_FALLBACK;
|
|
91
|
+
}
|
|
92
|
+
function resolveNamedTransitionProp(transition, registry) {
|
|
93
|
+
if (transition === void 0) return void 0;
|
|
94
|
+
if (typeof transition === "string") {
|
|
95
|
+
return lookupNamedTransition(transition, registry);
|
|
96
|
+
}
|
|
97
|
+
if (isTopLevelTransition(transition)) return transition;
|
|
98
|
+
const map = transition;
|
|
99
|
+
let out = null;
|
|
100
|
+
for (const key in map) {
|
|
101
|
+
const value = map[key];
|
|
102
|
+
if (typeof value === "string") {
|
|
103
|
+
if (out === null) out = { ...map };
|
|
104
|
+
out[key] = lookupNamedTransition(value, registry);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return out ?? transition;
|
|
108
|
+
}
|
|
30
109
|
var modality = "keyboard";
|
|
31
110
|
var installed = false;
|
|
32
111
|
function setKeyboard() {
|
|
@@ -363,51 +442,6 @@ function mergeTransition(base, override) {
|
|
|
363
442
|
}
|
|
364
443
|
return { ...base ?? { type: "spring" }, ...override };
|
|
365
444
|
}
|
|
366
|
-
|
|
367
|
-
// src/transitions/keys.ts
|
|
368
|
-
var TRANSITION_CONFIG_KEYS = /* @__PURE__ */ new Set([
|
|
369
|
-
"type",
|
|
370
|
-
"tension",
|
|
371
|
-
"friction",
|
|
372
|
-
"mass",
|
|
373
|
-
"velocity",
|
|
374
|
-
"restSpeedThreshold",
|
|
375
|
-
"restDisplacementThreshold",
|
|
376
|
-
"duration",
|
|
377
|
-
"easing",
|
|
378
|
-
"delay",
|
|
379
|
-
"repeat",
|
|
380
|
-
"deceleration",
|
|
381
|
-
"clamp"
|
|
382
|
-
]);
|
|
383
|
-
function isTopLevelTransition(t) {
|
|
384
|
-
if (t === null || typeof t !== "object") return false;
|
|
385
|
-
const keys = Object.keys(t);
|
|
386
|
-
if (keys.length === 0) return false;
|
|
387
|
-
return keys.every((k) => TRANSITION_CONFIG_KEYS.has(k));
|
|
388
|
-
}
|
|
389
|
-
|
|
390
|
-
// src/transitions/sig.ts
|
|
391
|
-
function stableSig(value) {
|
|
392
|
-
if (value === void 0) return "";
|
|
393
|
-
try {
|
|
394
|
-
return stableStringify(value);
|
|
395
|
-
} catch {
|
|
396
|
-
return String(value);
|
|
397
|
-
}
|
|
398
|
-
}
|
|
399
|
-
function stableStringify(v) {
|
|
400
|
-
if (v === null || typeof v !== "object") {
|
|
401
|
-
if (typeof v === "function" || v === void 0) return "null";
|
|
402
|
-
return JSON.stringify(v);
|
|
403
|
-
}
|
|
404
|
-
if (Array.isArray(v)) {
|
|
405
|
-
return "[" + v.map(stableStringify).join(",") + "]";
|
|
406
|
-
}
|
|
407
|
-
const obj = v;
|
|
408
|
-
const keys = Object.keys(obj).sort();
|
|
409
|
-
return "{" + keys.map((k) => JSON.stringify(k) + ":" + stableStringify(obj[k])).join(",") + "}";
|
|
410
|
-
}
|
|
411
445
|
var alreadyChecked = false;
|
|
412
446
|
function ensureReanimatedInstalled() {
|
|
413
447
|
if (!__DEV__ || alreadyChecked) return;
|
|
@@ -510,12 +544,14 @@ var DEFAULT_RESTING = {
|
|
|
510
544
|
};
|
|
511
545
|
function transitionFor(prop, transition) {
|
|
512
546
|
if (!transition) return void 0;
|
|
547
|
+
if (typeof transition === "string") return void 0;
|
|
513
548
|
if (isTopLevelTransition(transition)) return transition;
|
|
514
549
|
if (GESTURE_LAYER_NAME_SET.has(prop)) return void 0;
|
|
515
550
|
return transition[prop];
|
|
516
551
|
}
|
|
517
552
|
function gestureLayerTransitionFor(layer, transition) {
|
|
518
553
|
if (!transition) return void 0;
|
|
554
|
+
if (typeof transition === "string") return void 0;
|
|
519
555
|
if (isTopLevelTransition(transition)) return transition;
|
|
520
556
|
return transition[layer];
|
|
521
557
|
}
|
|
@@ -530,17 +566,23 @@ function createMotionComponent(Component) {
|
|
|
530
566
|
initial,
|
|
531
567
|
animate,
|
|
532
568
|
exit,
|
|
533
|
-
transition,
|
|
569
|
+
transition: transitionProp,
|
|
534
570
|
variants,
|
|
535
571
|
controller,
|
|
536
572
|
gesture,
|
|
537
|
-
layout,
|
|
573
|
+
layout: layoutProp,
|
|
538
574
|
layoutId,
|
|
539
575
|
onAnimationEnd,
|
|
540
576
|
style,
|
|
541
577
|
onLayout: userOnLayout,
|
|
542
578
|
...rest
|
|
543
579
|
} = props;
|
|
580
|
+
const namedTransitions = useNamedTransitions();
|
|
581
|
+
const transition = resolveNamedTransitionProp(
|
|
582
|
+
transitionProp,
|
|
583
|
+
namedTransitions
|
|
584
|
+
);
|
|
585
|
+
const layout = typeof layoutProp === "string" ? lookupNamedTransition(layoutProp, namedTransitions) : layoutProp;
|
|
544
586
|
if (__DEV__ && typeof style === "function") {
|
|
545
587
|
throw new Error(
|
|
546
588
|
"[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."
|
|
@@ -1134,5 +1176,3 @@ function compose(user, ours) {
|
|
|
1134
1176
|
var MotionImage = createMotionComponent(reactNative.Image);
|
|
1135
1177
|
|
|
1136
1178
|
exports.MotionImage = MotionImage;
|
|
1137
|
-
//# sourceMappingURL=Image.js.map
|
|
1138
|
-
//# sourceMappingURL=Image.js.map
|