@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
@@ -5,8 +5,31 @@ import { isWorkletFunction } from 'react-native-worklets';
5
5
  import { jsx } from 'react/jsx-runtime';
6
6
 
7
7
  // src/motion/Text.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();
@@ -21,6 +47,59 @@ function useShouldReduceMotion() {
21
47
  if (reducedMotion === "always") return true;
22
48
  return osReduced;
23
49
  }
50
+
51
+ // src/transitions/keys.ts
52
+ var TRANSITION_CONFIG_KEYS = /* @__PURE__ */ new Set([
53
+ "type",
54
+ "tension",
55
+ "friction",
56
+ "mass",
57
+ "velocity",
58
+ "restSpeedThreshold",
59
+ "restDisplacementThreshold",
60
+ "duration",
61
+ "easing",
62
+ "delay",
63
+ "repeat",
64
+ "deceleration",
65
+ "clamp"
66
+ ]);
67
+ function isTopLevelTransition(t) {
68
+ if (t === null || typeof t !== "object") return false;
69
+ const keys = Object.keys(t);
70
+ if (keys.length === 0) return false;
71
+ return keys.every((k) => TRANSITION_CONFIG_KEYS.has(k));
72
+ }
73
+
74
+ // src/config/namedTransitions.ts
75
+ var UNKNOWN_NAME_FALLBACK = { type: "spring" };
76
+ function lookupNamedTransition(name, registry) {
77
+ const cfg = registry[name];
78
+ if (cfg) return cfg;
79
+ if (__DEV__) {
80
+ console.warn(
81
+ `[inertia] Unknown transition name "${name}" \u2014 falling back to the default spring. Register it on a provider: <MotionConfig transitions={{ '${name}': { ... } }}>.`
82
+ );
83
+ }
84
+ return UNKNOWN_NAME_FALLBACK;
85
+ }
86
+ function resolveNamedTransitionProp(transition, registry) {
87
+ if (transition === void 0) return void 0;
88
+ if (typeof transition === "string") {
89
+ return lookupNamedTransition(transition, registry);
90
+ }
91
+ if (isTopLevelTransition(transition)) return transition;
92
+ const map = transition;
93
+ let out = null;
94
+ for (const key in map) {
95
+ const value = map[key];
96
+ if (typeof value === "string") {
97
+ if (out === null) out = { ...map };
98
+ out[key] = lookupNamedTransition(value, registry);
99
+ }
100
+ }
101
+ return out ?? transition;
102
+ }
24
103
  var modality = "keyboard";
25
104
  var installed = false;
26
105
  function setKeyboard() {
@@ -357,51 +436,6 @@ function mergeTransition(base, override) {
357
436
  }
358
437
  return { ...base ?? { type: "spring" }, ...override };
359
438
  }
360
-
361
- // src/transitions/keys.ts
362
- var TRANSITION_CONFIG_KEYS = /* @__PURE__ */ new Set([
363
- "type",
364
- "tension",
365
- "friction",
366
- "mass",
367
- "velocity",
368
- "restSpeedThreshold",
369
- "restDisplacementThreshold",
370
- "duration",
371
- "easing",
372
- "delay",
373
- "repeat",
374
- "deceleration",
375
- "clamp"
376
- ]);
377
- function isTopLevelTransition(t) {
378
- if (t === null || typeof t !== "object") return false;
379
- const keys = Object.keys(t);
380
- if (keys.length === 0) return false;
381
- return keys.every((k) => TRANSITION_CONFIG_KEYS.has(k));
382
- }
383
-
384
- // src/transitions/sig.ts
385
- function stableSig(value) {
386
- if (value === void 0) return "";
387
- try {
388
- return stableStringify(value);
389
- } catch {
390
- return String(value);
391
- }
392
- }
393
- function stableStringify(v) {
394
- if (v === null || typeof v !== "object") {
395
- if (typeof v === "function" || v === void 0) return "null";
396
- return JSON.stringify(v);
397
- }
398
- if (Array.isArray(v)) {
399
- return "[" + v.map(stableStringify).join(",") + "]";
400
- }
401
- const obj = v;
402
- const keys = Object.keys(obj).sort();
403
- return "{" + keys.map((k) => JSON.stringify(k) + ":" + stableStringify(obj[k])).join(",") + "}";
404
- }
405
439
  var alreadyChecked = false;
406
440
  function ensureReanimatedInstalled() {
407
441
  if (!__DEV__ || alreadyChecked) return;
@@ -504,12 +538,14 @@ var DEFAULT_RESTING = {
504
538
  };
505
539
  function transitionFor(prop, transition) {
506
540
  if (!transition) return void 0;
541
+ if (typeof transition === "string") return void 0;
507
542
  if (isTopLevelTransition(transition)) return transition;
508
543
  if (GESTURE_LAYER_NAME_SET.has(prop)) return void 0;
509
544
  return transition[prop];
510
545
  }
511
546
  function gestureLayerTransitionFor(layer, transition) {
512
547
  if (!transition) return void 0;
548
+ if (typeof transition === "string") return void 0;
513
549
  if (isTopLevelTransition(transition)) return transition;
514
550
  return transition[layer];
515
551
  }
@@ -524,17 +560,23 @@ function createMotionComponent(Component) {
524
560
  initial,
525
561
  animate,
526
562
  exit,
527
- transition,
563
+ transition: transitionProp,
528
564
  variants,
529
565
  controller,
530
566
  gesture,
531
- layout,
567
+ layout: layoutProp,
532
568
  layoutId,
533
569
  onAnimationEnd,
534
570
  style,
535
571
  onLayout: userOnLayout,
536
572
  ...rest
537
573
  } = props;
574
+ const namedTransitions = useNamedTransitions();
575
+ const transition = resolveNamedTransitionProp(
576
+ transitionProp,
577
+ namedTransitions
578
+ );
579
+ const layout = typeof layoutProp === "string" ? lookupNamedTransition(layoutProp, namedTransitions) : layoutProp;
538
580
  if (__DEV__ && typeof style === "function") {
539
581
  throw new Error(
540
582
  "[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."