@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.
Files changed (69) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/README.md +2 -0
  3. package/dist/gestureLayer/index.d.mts +6 -5
  4. package/dist/gestureLayer/index.d.ts +6 -5
  5. package/dist/gestureLayer/index.js +89 -27
  6. package/dist/gestureLayer/index.js.map +1 -1
  7. package/dist/gestureLayer/index.mjs +89 -27
  8. package/dist/gestureLayer/index.mjs.map +1 -1
  9. package/dist/index.d.mts +127 -16
  10. package/dist/index.d.ts +127 -16
  11. package/dist/index.js +177 -60
  12. package/dist/index.js.map +1 -1
  13. package/dist/index.mjs +175 -61
  14. package/dist/index.mjs.map +1 -1
  15. package/dist/motion/Image.d.mts +1 -1
  16. package/dist/motion/Image.d.ts +1 -1
  17. package/dist/motion/Image.js +90 -48
  18. package/dist/motion/Image.js.map +1 -1
  19. package/dist/motion/Image.mjs +90 -48
  20. package/dist/motion/Image.mjs.map +1 -1
  21. package/dist/motion/Pressable.d.mts +1 -1
  22. package/dist/motion/Pressable.d.ts +1 -1
  23. package/dist/motion/Pressable.js +90 -48
  24. package/dist/motion/Pressable.js.map +1 -1
  25. package/dist/motion/Pressable.mjs +90 -48
  26. package/dist/motion/Pressable.mjs.map +1 -1
  27. package/dist/motion/ScrollView.d.mts +1 -1
  28. package/dist/motion/ScrollView.d.ts +1 -1
  29. package/dist/motion/ScrollView.js +90 -48
  30. package/dist/motion/ScrollView.js.map +1 -1
  31. package/dist/motion/ScrollView.mjs +90 -48
  32. package/dist/motion/ScrollView.mjs.map +1 -1
  33. package/dist/motion/Text.d.mts +1 -1
  34. package/dist/motion/Text.d.ts +1 -1
  35. package/dist/motion/Text.js +90 -48
  36. package/dist/motion/Text.js.map +1 -1
  37. package/dist/motion/Text.mjs +90 -48
  38. package/dist/motion/Text.mjs.map +1 -1
  39. package/dist/motion/View.d.mts +1 -1
  40. package/dist/motion/View.d.ts +1 -1
  41. package/dist/motion/View.js +90 -48
  42. package/dist/motion/View.js.map +1 -1
  43. package/dist/motion/View.mjs +90 -48
  44. package/dist/motion/View.mjs.map +1 -1
  45. package/dist/touch/index.d.mts +1 -1
  46. package/dist/touch/index.d.ts +1 -1
  47. package/dist/{types-cU43dEmH.d.mts → types-BzEgiUdJ.d.mts} +58 -9
  48. package/dist/{types-cU43dEmH.d.ts → types-BzEgiUdJ.d.ts} +58 -9
  49. package/dist/{useGesture-BnY65PlQ.d.ts → useGesture-BRLgiNOC.d.ts} +6 -4
  50. package/dist/{useGesture-DxtXdz-K.d.mts → useGesture-C0GBS7d2.d.mts} +6 -4
  51. package/llms.txt +8 -4
  52. package/package.json +1 -1
  53. package/src/__type-tests__/motion-value.test-d.ts +39 -0
  54. package/src/config/MotionConfig.tsx +55 -9
  55. package/src/config/MotionConfigContext.ts +21 -1
  56. package/src/config/index.ts +7 -1
  57. package/src/config/namedTransitions.ts +80 -0
  58. package/src/gestureLayer/useGestureLayer.ts +32 -8
  59. package/src/index.ts +20 -2
  60. package/src/motion/createMotionComponent.tsx +36 -6
  61. package/src/transitions/cubicBezier.ts +126 -0
  62. package/src/transitions/index.ts +1 -0
  63. package/src/types.ts +63 -8
  64. package/src/values/useAnimation.ts +12 -6
  65. package/src/values/useBooleanSpring.ts +5 -3
  66. package/src/values/useGesture.ts +25 -7
  67. package/src/values/useMotionValue.ts +11 -0
  68. package/src/values/useScroll.ts +8 -1
  69. package/src/values/useSpring.ts +46 -9
@@ -1,5 +1,5 @@
1
1
  import { Image } from 'react-native';
2
- import { M as MotionComponent } from '../types-cU43dEmH.mjs';
2
+ import { M as MotionComponent } from '../types-BzEgiUdJ.mjs';
3
3
  import 'react';
4
4
 
5
5
  /**
@@ -1,5 +1,5 @@
1
1
  import { Image } from 'react-native';
2
- import { M as MotionComponent } from '../types-cU43dEmH.js';
2
+ import { M as MotionComponent } from '../types-BzEgiUdJ.js';
3
3
  import 'react';
4
4
 
5
5
  /**
@@ -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."