@rootnative/inertia 0.0.0-alpha.0 → 0.0.0-alpha.1
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 +6 -5
- package/dist/gestureLayer/index.d.ts +6 -5
- package/dist/gestureLayer/index.js +89 -27
- package/dist/gestureLayer/index.js.map +1 -1
- package/dist/gestureLayer/index.mjs +89 -27
- package/dist/gestureLayer/index.mjs.map +1 -1
- package/dist/index.d.mts +127 -16
- package/dist/index.d.ts +127 -16
- package/dist/index.js +177 -60
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +175 -61
- package/dist/index.mjs.map +1 -1
- package/dist/motion/Image.d.mts +1 -1
- package/dist/motion/Image.d.ts +1 -1
- package/dist/motion/Image.js +90 -48
- package/dist/motion/Image.js.map +1 -1
- package/dist/motion/Image.mjs +90 -48
- package/dist/motion/Image.mjs.map +1 -1
- package/dist/motion/Pressable.d.mts +1 -1
- package/dist/motion/Pressable.d.ts +1 -1
- package/dist/motion/Pressable.js +90 -48
- package/dist/motion/Pressable.js.map +1 -1
- package/dist/motion/Pressable.mjs +90 -48
- package/dist/motion/Pressable.mjs.map +1 -1
- package/dist/motion/ScrollView.d.mts +1 -1
- package/dist/motion/ScrollView.d.ts +1 -1
- package/dist/motion/ScrollView.js +90 -48
- package/dist/motion/ScrollView.js.map +1 -1
- package/dist/motion/ScrollView.mjs +90 -48
- package/dist/motion/ScrollView.mjs.map +1 -1
- package/dist/motion/Text.d.mts +1 -1
- package/dist/motion/Text.d.ts +1 -1
- package/dist/motion/Text.js +90 -48
- package/dist/motion/Text.js.map +1 -1
- package/dist/motion/Text.mjs +90 -48
- package/dist/motion/Text.mjs.map +1 -1
- package/dist/motion/View.d.mts +1 -1
- package/dist/motion/View.d.ts +1 -1
- package/dist/motion/View.js +90 -48
- package/dist/motion/View.js.map +1 -1
- package/dist/motion/View.mjs +90 -48
- package/dist/motion/View.mjs.map +1 -1
- package/dist/touch/index.d.mts +1 -1
- package/dist/touch/index.d.ts +1 -1
- 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 +8 -4
- package/package.json +1 -1
- package/src/__type-tests__/motion-value.test-d.ts +39 -0
- 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/useGestureLayer.ts +32 -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
|
@@ -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/ScrollView.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."
|