@onlynative/inertia 0.0.1-alpha.4 → 0.0.1-alpha.6

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 (48) hide show
  1. package/dist/index.d.mts +30 -4
  2. package/dist/index.d.ts +30 -4
  3. package/dist/index.js +123 -24
  4. package/dist/index.js.map +1 -1
  5. package/dist/index.mjs +123 -25
  6. package/dist/index.mjs.map +1 -1
  7. package/dist/motion/Image.d.mts +1 -1
  8. package/dist/motion/Image.d.ts +1 -1
  9. package/dist/motion/Image.js +100 -24
  10. package/dist/motion/Image.js.map +1 -1
  11. package/dist/motion/Image.mjs +100 -24
  12. package/dist/motion/Image.mjs.map +1 -1
  13. package/dist/motion/Pressable.d.mts +1 -1
  14. package/dist/motion/Pressable.d.ts +1 -1
  15. package/dist/motion/Pressable.js +100 -24
  16. package/dist/motion/Pressable.js.map +1 -1
  17. package/dist/motion/Pressable.mjs +100 -24
  18. package/dist/motion/Pressable.mjs.map +1 -1
  19. package/dist/motion/ScrollView.d.mts +1 -1
  20. package/dist/motion/ScrollView.d.ts +1 -1
  21. package/dist/motion/ScrollView.js +100 -24
  22. package/dist/motion/ScrollView.js.map +1 -1
  23. package/dist/motion/ScrollView.mjs +100 -24
  24. package/dist/motion/ScrollView.mjs.map +1 -1
  25. package/dist/motion/Text.d.mts +1 -1
  26. package/dist/motion/Text.d.ts +1 -1
  27. package/dist/motion/Text.js +100 -24
  28. package/dist/motion/Text.js.map +1 -1
  29. package/dist/motion/Text.mjs +100 -24
  30. package/dist/motion/Text.mjs.map +1 -1
  31. package/dist/motion/View.d.mts +1 -1
  32. package/dist/motion/View.d.ts +1 -1
  33. package/dist/motion/View.js +100 -24
  34. package/dist/motion/View.js.map +1 -1
  35. package/dist/motion/View.mjs +100 -24
  36. package/dist/motion/View.mjs.map +1 -1
  37. package/dist/{types-CjztO3RW.d.mts → types-NmNeJjo1.d.mts} +23 -2
  38. package/dist/{types-CjztO3RW.d.ts → types-NmNeJjo1.d.ts} +23 -2
  39. package/jest-preset.js +33 -0
  40. package/jest-setup.js +209 -0
  41. package/package.json +5 -1
  42. package/src/index.ts +1 -0
  43. package/src/motion/createMotionComponent.tsx +172 -26
  44. package/src/transitions/easing.ts +25 -3
  45. package/src/transitions/index.ts +1 -0
  46. package/src/transitions/runtime.ts +63 -0
  47. package/src/transitions/spring.ts +1 -0
  48. package/src/types.ts +23 -1
package/dist/index.mjs CHANGED
@@ -1455,13 +1455,17 @@ if (globalThis._ALWAYS_FALSE) {
1455
1455
  // src/transitions/easing.ts
1456
1456
  function ensureWorkletEasing(easing) {
1457
1457
  if (!easing) return void 0;
1458
- if (isWorkletFunction(easing)) return easing;
1458
+ const fn = isEasingFactory(easing) ? easing.factory() : easing;
1459
+ if (isWorkletFunction(fn)) return fn;
1459
1460
  const wrapped = (t) => {
1460
1461
  "worklet";
1461
- return easing(t);
1462
+ return fn(t);
1462
1463
  };
1463
1464
  return wrapped;
1464
1465
  }
1466
+ function isEasingFactory(value) {
1467
+ return typeof value === "object" && value !== null && "factory" in value && typeof value.factory === "function";
1468
+ }
1465
1469
 
1466
1470
  // src/transitions/spring.ts
1467
1471
  var DEFAULT_SPRING = {
@@ -1470,6 +1474,7 @@ var DEFAULT_SPRING = {
1470
1474
  mass: 1
1471
1475
  };
1472
1476
  function springToReanimated(t) {
1477
+ "worklet";
1473
1478
  return {
1474
1479
  stiffness: t.tension ?? DEFAULT_SPRING.tension,
1475
1480
  damping: t.friction ?? DEFAULT_SPRING.friction,
@@ -1724,6 +1729,28 @@ function isTopLevelTransition(t) {
1724
1729
  if (keys.length === 0) return false;
1725
1730
  return keys.every((k) => TRANSITION_CONFIG_KEYS.has(k));
1726
1731
  }
1732
+ var DEFAULT_TIMING_DURATION2 = 250;
1733
+ function buildReleaseAnimation(transition, toValue) {
1734
+ "worklet";
1735
+ if (transition.type === "no-animation") return toValue;
1736
+ if (transition.type === "decay") {
1737
+ const cfg = { velocity: transition.velocity ?? 0 };
1738
+ if (transition.deceleration !== void 0) {
1739
+ cfg.deceleration = transition.deceleration;
1740
+ }
1741
+ if (transition.clamp !== void 0) cfg.clamp = transition.clamp;
1742
+ return withDecay(cfg);
1743
+ }
1744
+ if (transition.type === "timing") {
1745
+ const e = transition.easing;
1746
+ const easingFn = e && typeof e === "object" && "factory" in e ? e.factory() : e ?? Easing.inOut(Easing.ease);
1747
+ return withTiming(toValue, {
1748
+ duration: transition.duration ?? DEFAULT_TIMING_DURATION2,
1749
+ easing: easingFn
1750
+ });
1751
+ }
1752
+ return withSpring(toValue, springToReanimated(transition));
1753
+ }
1727
1754
 
1728
1755
  // src/transitions/sig.ts
1729
1756
  function stableSig(value) {
@@ -1795,21 +1822,28 @@ var NUMERIC_TOP_LEVEL_KEYS = [
1795
1822
  "opacity",
1796
1823
  "width",
1797
1824
  "height",
1798
- "borderRadius"
1825
+ "borderRadius",
1826
+ "shadowOpacity",
1827
+ "shadowRadius",
1828
+ "elevation"
1799
1829
  ];
1800
1830
  var COLOR_KEYS = [
1801
1831
  "backgroundColor",
1802
1832
  "borderColor",
1803
1833
  "color",
1804
- "tintColor"
1834
+ "tintColor",
1835
+ "shadowColor"
1805
1836
  ];
1837
+ var SHADOW_OFFSET_KEYS = ["shadowOffsetWidth", "shadowOffsetHeight"];
1806
1838
  var ALL_KEYS = [
1807
1839
  ...TRANSFORM_KEYS,
1808
1840
  ...NUMERIC_TOP_LEVEL_KEYS,
1809
- ...COLOR_KEYS
1841
+ ...COLOR_KEYS,
1842
+ ...SHADOW_OFFSET_KEYS
1810
1843
  ];
1811
1844
  var TRANSFORM_KEY_SET = new Set(TRANSFORM_KEYS);
1812
1845
  var COLOR_KEY_SET = new Set(COLOR_KEYS);
1846
+ var SHADOW_OFFSET_KEY_SET = new Set(SHADOW_OFFSET_KEYS);
1813
1847
  var GESTURE_LAYER_NAMES = [
1814
1848
  "hovered",
1815
1849
  "focused",
@@ -1831,6 +1865,9 @@ var DEFAULT_RESTING = {
1831
1865
  width: 0,
1832
1866
  height: 0,
1833
1867
  borderRadius: 0,
1868
+ shadowOpacity: 0,
1869
+ shadowRadius: 0,
1870
+ elevation: 0,
1834
1871
  // 'transparent' is the only safe universal default for colors: it works as
1835
1872
  // an initial seed for any color animation (no jarring opaque flash on mount
1836
1873
  // when `initial` is omitted) and rgba(0,0,0,0) interpolates cleanly into
@@ -1838,7 +1875,10 @@ var DEFAULT_RESTING = {
1838
1875
  backgroundColor: "transparent",
1839
1876
  borderColor: "transparent",
1840
1877
  color: "transparent",
1841
- tintColor: "transparent"
1878
+ tintColor: "transparent",
1879
+ shadowColor: "transparent",
1880
+ shadowOffsetWidth: 0,
1881
+ shadowOffsetHeight: 0
1842
1882
  };
1843
1883
  function transitionFor(prop, transition) {
1844
1884
  if (!transition) return void 0;
@@ -1892,16 +1932,12 @@ function createMotionComponent(Component) {
1892
1932
  const activeKeysRef = useRef(null);
1893
1933
  if (activeKeysRef.current === null) {
1894
1934
  const touched = /* @__PURE__ */ new Set();
1895
- for (const k of ALL_KEYS) {
1896
- if (k in animateRecord) touched.add(k);
1897
- if (initialRecord && k in initialRecord) touched.add(k);
1898
- }
1935
+ collectTouchedKeys(touched, animateRecord);
1936
+ if (initialRecord) collectTouchedKeys(touched, initialRecord);
1899
1937
  if (variants) {
1900
1938
  for (const variant of Object.values(variants)) {
1901
1939
  if (!variant) continue;
1902
- for (const k of ALL_KEYS) {
1903
- if (k in variant) touched.add(k);
1904
- }
1940
+ collectTouchedKeys(touched, variant);
1905
1941
  }
1906
1942
  }
1907
1943
  if (gesture) {
@@ -1912,22 +1948,29 @@ function createMotionComponent(Component) {
1912
1948
  gesture.hovered
1913
1949
  ]) {
1914
1950
  if (!subState) continue;
1915
- for (const k of ALL_KEYS) {
1916
- if (k in subState) touched.add(k);
1917
- }
1918
- }
1919
- }
1920
- if (exitRecord) {
1921
- for (const k of ALL_KEYS) {
1922
- if (k in exitRecord) touched.add(k);
1951
+ collectTouchedKeys(touched, subState);
1923
1952
  }
1924
1953
  }
1954
+ if (exitRecord) collectTouchedKeys(touched, exitRecord);
1925
1955
  activeKeysRef.current = ALL_KEYS.filter((k) => touched.has(k));
1926
1956
  }
1927
1957
  const hasTransformRef = useRef(
1928
1958
  activeKeysRef.current.some((k) => TRANSFORM_KEY_SET.has(k))
1929
1959
  );
1960
+ const hasShadowOffsetRef = useRef(
1961
+ activeKeysRef.current.some((k) => SHADOW_OFFSET_KEY_SET.has(k))
1962
+ );
1930
1963
  const sharedValues = useAnimatableSharedValues((key) => {
1964
+ if (SHADOW_OFFSET_KEY_SET.has(key)) {
1965
+ const axis = shadowOffsetAxisFor(key);
1966
+ if (initial === false) {
1967
+ return shadowOffsetAxisValue(animateRecord.shadowOffset, axis) ?? DEFAULT_RESTING[key];
1968
+ }
1969
+ return shadowOffsetAxisValue(
1970
+ initialRecord?.shadowOffset,
1971
+ axis
1972
+ ) ?? shadowOffsetAxisValue(animateRecord.shadowOffset, axis) ?? DEFAULT_RESTING[key];
1973
+ }
1931
1974
  if (initial === false) {
1932
1975
  const a = animateRecord[key];
1933
1976
  return restValue(a) ?? DEFAULT_RESTING[key];
@@ -1973,9 +2016,15 @@ function createMotionComponent(Component) {
1973
2016
  }
1974
2017
  const transformGroup = transformPending > 0 ? { remaining: transformPending } : void 0;
1975
2018
  for (const key of ALL_KEYS) {
1976
- const target = baseRecord[key];
2019
+ const target = SHADOW_OFFSET_KEY_SET.has(key) ? shadowOffsetAxisValue(
2020
+ baseRecord.shadowOffset,
2021
+ shadowOffsetAxisFor(key)
2022
+ ) : baseRecord[key];
1977
2023
  if (target === void 0) continue;
1978
- const cfg = shouldReduceMotion ? { type: "no-animation" } : transitionFor(key, transition);
2024
+ const cfg = shouldReduceMotion ? { type: "no-animation" } : transitionFor(
2025
+ SHADOW_OFFSET_KEY_SET.has(key) ? "shadowOffset" : key,
2026
+ transition
2027
+ );
1979
2028
  if (isExiting) pending++;
1980
2029
  const factory = makeKeyCallbackFactory(
1981
2030
  key,
@@ -2038,8 +2087,11 @@ function createMotionComponent(Component) {
2038
2087
  const animatedStyle = useAnimatedStyle(() => {
2039
2088
  const activeKeys = activeKeysRef.current;
2040
2089
  const hasTransform = hasTransformRef.current;
2090
+ const hasShadowOffset = hasShadowOffsetRef.current;
2041
2091
  const out = {};
2042
2092
  const transform = [];
2093
+ let shadowOffsetW = 0;
2094
+ let shadowOffsetH = 0;
2043
2095
  const ph = hoveredProgress.value;
2044
2096
  const pf = focusedProgress.value;
2045
2097
  const pfv = focusVisibleProgress.value;
@@ -2072,11 +2124,18 @@ function createMotionComponent(Component) {
2072
2124
  transform.push(
2073
2125
  ROTATION_KEYS.has(key) ? { [key]: `${v}deg` } : { [key]: v }
2074
2126
  );
2127
+ } else if (key === "shadowOffsetWidth") {
2128
+ shadowOffsetW = v;
2129
+ } else if (key === "shadowOffsetHeight") {
2130
+ shadowOffsetH = v;
2075
2131
  } else {
2076
2132
  out[key] = v;
2077
2133
  }
2078
2134
  }
2079
2135
  if (hasTransform) out.transform = transform;
2136
+ if (hasShadowOffset) {
2137
+ out.shadowOffset = { width: shadowOffsetW, height: shadowOffsetH };
2138
+ }
2080
2139
  return out;
2081
2140
  });
2082
2141
  const mergedStyle = useMemo(
@@ -2124,12 +2183,22 @@ function useAnimatableSharedValues(init2) {
2124
2183
  const width = useSharedValue(init2("width"));
2125
2184
  const height = useSharedValue(init2("height"));
2126
2185
  const borderRadius = useSharedValue(init2("borderRadius"));
2186
+ const shadowOpacity = useSharedValue(init2("shadowOpacity"));
2187
+ const shadowRadius = useSharedValue(init2("shadowRadius"));
2188
+ const elevation = useSharedValue(init2("elevation"));
2127
2189
  const backgroundColor = useSharedValue(
2128
2190
  init2("backgroundColor")
2129
2191
  );
2130
2192
  const borderColor = useSharedValue(init2("borderColor"));
2131
2193
  const color = useSharedValue(init2("color"));
2132
2194
  const tintColor = useSharedValue(init2("tintColor"));
2195
+ const shadowColor = useSharedValue(init2("shadowColor"));
2196
+ const shadowOffsetWidth = useSharedValue(
2197
+ init2("shadowOffsetWidth")
2198
+ );
2199
+ const shadowOffsetHeight = useSharedValue(
2200
+ init2("shadowOffsetHeight")
2201
+ );
2133
2202
  const ref = useRef(null);
2134
2203
  if (ref.current === null) {
2135
2204
  ref.current = {
@@ -2145,10 +2214,16 @@ function useAnimatableSharedValues(init2) {
2145
2214
  width,
2146
2215
  height,
2147
2216
  borderRadius,
2217
+ shadowOpacity,
2218
+ shadowRadius,
2219
+ elevation,
2148
2220
  backgroundColor,
2149
2221
  borderColor,
2150
2222
  color,
2151
- tintColor
2223
+ tintColor,
2224
+ shadowColor,
2225
+ shadowOffsetWidth,
2226
+ shadowOffsetHeight
2152
2227
  };
2153
2228
  }
2154
2229
  return ref.current;
@@ -2216,6 +2291,22 @@ function makeKeyCallbackFactory(key, sharedValue, target, onAnimationEndRef, met
2216
2291
  return cb;
2217
2292
  };
2218
2293
  }
2294
+ function shadowOffsetAxisFor(key) {
2295
+ return key === "shadowOffsetWidth" ? "width" : "height";
2296
+ }
2297
+ function shadowOffsetAxisValue(source, axis) {
2298
+ return source?.[axis];
2299
+ }
2300
+ function collectTouchedKeys(touched, record) {
2301
+ for (const k of ALL_KEYS) {
2302
+ if (k in record) touched.add(k);
2303
+ }
2304
+ if ("shadowOffset" in record && record.shadowOffset) {
2305
+ const so = record.shadowOffset;
2306
+ if (so.width !== void 0) touched.add("shadowOffsetWidth");
2307
+ if (so.height !== void 0) touched.add("shadowOffsetHeight");
2308
+ }
2309
+ }
2219
2310
  function stepCountOf(v) {
2220
2311
  if (Array.isArray(v)) return v.length;
2221
2312
  return 1;
@@ -2285,6 +2376,13 @@ function resolveGestureLayers(gesture) {
2285
2376
  if (!subState) continue;
2286
2377
  const resolved = {};
2287
2378
  for (const key of ALL_KEYS) {
2379
+ if (SHADOW_OFFSET_KEY_SET.has(key)) {
2380
+ const axis = shadowOffsetAxisFor(key);
2381
+ const so = subState.shadowOffset;
2382
+ const v = shadowOffsetAxisValue(so, axis);
2383
+ if (v !== void 0) resolved[key] = v;
2384
+ continue;
2385
+ }
2288
2386
  const raw = subState[key];
2289
2387
  if (raw === void 0) continue;
2290
2388
  const t = targetEndValue(raw);
@@ -2564,6 +2662,6 @@ function useVariants(variants, initial) {
2564
2662
  }, []);
2565
2663
  }
2566
2664
 
2567
- export { Motion, MotionConfig, MotionImage, MotionPressable, MotionScrollView, MotionText, MotionView, Presence, createMotionComponent, ensureWorkletEasing, resolveAnimatableValue, resolveTransition, useAnimation, useGesture, useMotionConfig, useMotionValue, usePresence, useScroll, useShouldReduceMotion, useSpring, useTransform, useVariants };
2665
+ export { Motion, MotionConfig, MotionImage, MotionPressable, MotionScrollView, MotionText, MotionView, Presence, buildReleaseAnimation, createMotionComponent, ensureWorkletEasing, resolveAnimatableValue, resolveTransition, useAnimation, useGesture, useMotionConfig, useMotionValue, usePresence, useScroll, useShouldReduceMotion, useSpring, useTransform, useVariants };
2568
2666
  //# sourceMappingURL=index.mjs.map
2569
2667
  //# sourceMappingURL=index.mjs.map