react-native-gtkx 0.2.0-alpha.2 → 0.3.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 (340) hide show
  1. package/README.md +5 -2
  2. package/dist/aliases/index.d.ts +84 -0
  3. package/dist/aliases/index.js +208 -0
  4. package/dist/aliases/index.js.map +1 -0
  5. package/dist/animated/index.d.ts +2 -0
  6. package/dist/animated/index.js +5 -0
  7. package/dist/animated/index.js.map +1 -1
  8. package/dist/animated/types.d.ts +1 -0
  9. package/dist/animated/types.js.map +1 -1
  10. package/dist/animated/value-animation.js +17 -4
  11. package/dist/animated/value-animation.js.map +1 -1
  12. package/dist/apis/host.gtkx.js +9 -12
  13. package/dist/apis/host.gtkx.js.map +1 -1
  14. package/dist/apis/index.d.ts +4 -2
  15. package/dist/apis/index.js +2 -0
  16. package/dist/apis/index.js.map +1 -1
  17. package/dist/apis/keyboard.d.ts +60 -0
  18. package/dist/apis/keyboard.js +63 -0
  19. package/dist/apis/keyboard.js.map +1 -0
  20. package/dist/apis/log-box.d.ts +15 -0
  21. package/dist/apis/log-box.js +46 -0
  22. package/dist/apis/log-box.js.map +1 -0
  23. package/dist/apis/platform.d.ts +18 -1
  24. package/dist/apis/platform.js.map +1 -1
  25. package/dist/common/index.d.ts +0 -1
  26. package/dist/common/index.js +24 -1
  27. package/dist/common/index.js.map +1 -1
  28. package/dist/components/animated.d.ts +70 -6
  29. package/dist/components/animated.js +559 -46
  30. package/dist/components/animated.js.map +1 -1
  31. package/dist/components/driven-size.d.ts +27 -0
  32. package/dist/components/driven-size.js +85 -0
  33. package/dist/components/driven-size.js.map +1 -0
  34. package/dist/components/find-node-handle.d.ts +11 -0
  35. package/dist/components/find-node-handle.js +53 -0
  36. package/dist/components/find-node-handle.js.map +1 -0
  37. package/dist/components/flat-list.d.ts +3 -2
  38. package/dist/components/flat-list.js.map +1 -1
  39. package/dist/components/frame-scheduler.d.ts +16 -0
  40. package/dist/components/frame-scheduler.js +37 -0
  41. package/dist/components/frame-scheduler.js.map +1 -0
  42. package/dist/components/image.d.ts +6 -1
  43. package/dist/components/image.js +15 -4
  44. package/dist/components/image.js.map +1 -1
  45. package/dist/components/index.d.ts +7 -5
  46. package/dist/components/index.js +5 -3
  47. package/dist/components/index.js.map +1 -1
  48. package/dist/components/measure.d.ts +51 -1
  49. package/dist/components/measure.js +101 -2
  50. package/dist/components/measure.js.map +1 -1
  51. package/dist/components/pressable.d.ts +61 -1
  52. package/dist/components/pressable.js +151 -4
  53. package/dist/components/pressable.js.map +1 -1
  54. package/dist/components/rect-store.d.ts +58 -0
  55. package/dist/components/rect-store.js +124 -3
  56. package/dist/components/rect-store.js.map +1 -1
  57. package/dist/components/root.js +6 -1
  58. package/dist/components/root.js.map +1 -1
  59. package/dist/components/scroll-phase.d.ts +35 -0
  60. package/dist/components/scroll-phase.js +26 -0
  61. package/dist/components/scroll-phase.js.map +1 -0
  62. package/dist/components/scroll-view.d.ts +39 -3
  63. package/dist/components/scroll-view.js +378 -43
  64. package/dist/components/scroll-view.js.map +1 -1
  65. package/dist/components/text-input.js +9 -25
  66. package/dist/components/text-input.js.map +1 -1
  67. package/dist/components/text.d.ts +6 -2
  68. package/dist/components/text.js +43 -8
  69. package/dist/components/text.js.map +1 -1
  70. package/dist/components/use-focus.d.ts +27 -0
  71. package/dist/components/use-focus.js +116 -0
  72. package/dist/components/use-focus.js.map +1 -0
  73. package/dist/components/use-layout-child.d.ts +13 -1
  74. package/dist/components/use-layout-child.js +188 -5
  75. package/dist/components/use-layout-child.js.map +1 -1
  76. package/dist/components/view.d.ts +5 -2
  77. package/dist/components/view.js +18 -13
  78. package/dist/components/view.js.map +1 -1
  79. package/dist/components/virtualized-list.d.ts +45 -5
  80. package/dist/components/virtualized-list.js +90 -24
  81. package/dist/components/virtualized-list.js.map +1 -1
  82. package/dist/components/wheel-scroll-session.d.ts +7 -0
  83. package/dist/components/wheel-scroll-session.js +53 -0
  84. package/dist/components/wheel-scroll-session.js.map +1 -0
  85. package/dist/components/widget-retention.d.ts +35 -0
  86. package/dist/components/widget-retention.js +169 -0
  87. package/dist/components/widget-retention.js.map +1 -0
  88. package/dist/contracts.d.ts +4 -0
  89. package/dist/contracts.js.map +1 -1
  90. package/dist/dnd/context.d.ts +69 -0
  91. package/dist/dnd/context.js +149 -0
  92. package/dist/dnd/context.js.map +1 -0
  93. package/dist/dnd/draggable.d.ts +59 -0
  94. package/dist/dnd/draggable.js +149 -0
  95. package/dist/dnd/draggable.js.map +1 -0
  96. package/dist/dnd/droppable.d.ts +24 -0
  97. package/dist/dnd/droppable.js +74 -0
  98. package/dist/dnd/droppable.js.map +1 -0
  99. package/dist/dnd/gtk-controllers.d.ts +39 -0
  100. package/dist/dnd/gtk-controllers.js +110 -0
  101. package/dist/dnd/gtk-controllers.js.map +1 -0
  102. package/dist/dnd/index.d.ts +6 -0
  103. package/dist/dnd/index.js +31 -0
  104. package/dist/dnd/index.js.map +1 -0
  105. package/dist/dnd/order.d.ts +7 -0
  106. package/dist/dnd/order.js +20 -0
  107. package/dist/dnd/order.js.map +1 -0
  108. package/dist/dnd/payload.d.ts +14 -0
  109. package/dist/dnd/payload.js +41 -0
  110. package/dist/dnd/payload.js.map +1 -0
  111. package/dist/dnd/sortable.d.ts +49 -0
  112. package/dist/dnd/sortable.js +307 -0
  113. package/dist/dnd/sortable.js.map +1 -0
  114. package/dist/dnd/types.d.ts +290 -0
  115. package/dist/dnd/types.js +25 -0
  116. package/dist/dnd/types.js.map +1 -0
  117. package/dist/gesture-handler-compat/builder.d.ts +251 -0
  118. package/dist/gesture-handler-compat/builder.js +513 -0
  119. package/dist/gesture-handler-compat/builder.js.map +1 -0
  120. package/dist/gesture-handler-compat/composition.d.ts +23 -0
  121. package/dist/gesture-handler-compat/composition.js +111 -0
  122. package/dist/gesture-handler-compat/composition.js.map +1 -0
  123. package/dist/gesture-handler-compat/deciders.d.ts +3 -0
  124. package/dist/gesture-handler-compat/deciders.js +47 -0
  125. package/dist/gesture-handler-compat/deciders.js.map +1 -0
  126. package/dist/gesture-handler-compat/detector-runtime.d.ts +44 -0
  127. package/dist/gesture-handler-compat/detector-runtime.js +374 -0
  128. package/dist/gesture-handler-compat/detector-runtime.js.map +1 -0
  129. package/dist/gesture-handler-compat/detector.d.ts +22 -0
  130. package/dist/gesture-handler-compat/detector.js +104 -0
  131. package/dist/gesture-handler-compat/detector.js.map +1 -0
  132. package/dist/gesture-handler-compat/fling.d.ts +24 -0
  133. package/dist/gesture-handler-compat/fling.js +123 -0
  134. package/dist/gesture-handler-compat/fling.js.map +1 -0
  135. package/dist/gesture-handler-compat/force-touch.d.ts +13 -0
  136. package/dist/gesture-handler-compat/force-touch.js +40 -0
  137. package/dist/gesture-handler-compat/force-touch.js.map +1 -0
  138. package/dist/gesture-handler-compat/hooks.d.ts +157 -0
  139. package/dist/gesture-handler-compat/hooks.js +268 -0
  140. package/dist/gesture-handler-compat/hooks.js.map +1 -0
  141. package/dist/gesture-handler-compat/hover.d.ts +2 -0
  142. package/dist/gesture-handler-compat/hover.js +22 -0
  143. package/dist/gesture-handler-compat/hover.js.map +1 -0
  144. package/dist/gesture-handler-compat/index.d.ts +98 -0
  145. package/dist/gesture-handler-compat/index.js +255 -0
  146. package/dist/gesture-handler-compat/index.js.map +1 -0
  147. package/dist/gesture-handler-compat/long-press.d.ts +6 -0
  148. package/dist/gesture-handler-compat/long-press.js +21 -0
  149. package/dist/gesture-handler-compat/long-press.js.map +1 -0
  150. package/dist/gesture-handler-compat/manual.d.ts +2 -0
  151. package/dist/gesture-handler-compat/manual.js +18 -0
  152. package/dist/gesture-handler-compat/manual.js.map +1 -0
  153. package/dist/gesture-handler-compat/native.d.ts +7 -0
  154. package/dist/gesture-handler-compat/native.js +34 -0
  155. package/dist/gesture-handler-compat/native.js.map +1 -0
  156. package/dist/gesture-handler-compat/orchestrator.d.ts +77 -0
  157. package/dist/gesture-handler-compat/orchestrator.js +284 -0
  158. package/dist/gesture-handler-compat/orchestrator.js.map +1 -0
  159. package/dist/gesture-handler-compat/pan.d.ts +23 -0
  160. package/dist/gesture-handler-compat/pan.js +116 -0
  161. package/dist/gesture-handler-compat/pan.js.map +1 -0
  162. package/dist/gesture-handler-compat/recognizer.d.ts +268 -0
  163. package/dist/gesture-handler-compat/recognizer.js +1056 -0
  164. package/dist/gesture-handler-compat/recognizer.js.map +1 -0
  165. package/dist/gesture-handler-compat/relations.d.ts +43 -0
  166. package/dist/gesture-handler-compat/relations.js +128 -0
  167. package/dist/gesture-handler-compat/relations.js.map +1 -0
  168. package/dist/gesture-handler-compat/tap.d.ts +6 -0
  169. package/dist/gesture-handler-compat/tap.js +29 -0
  170. package/dist/gesture-handler-compat/tap.js.map +1 -0
  171. package/dist/gesture-handler-compat/touchpad.d.ts +41 -0
  172. package/dist/gesture-handler-compat/touchpad.js +64 -0
  173. package/dist/gesture-handler-compat/touchpad.js.map +1 -0
  174. package/dist/gesture-handler-compat/types.d.ts +441 -0
  175. package/dist/gesture-handler-compat/types.js +167 -0
  176. package/dist/gesture-handler-compat/types.js.map +1 -0
  177. package/dist/gtk/controllers.d.ts +39 -0
  178. package/dist/gtk/controllers.js +92 -0
  179. package/dist/gtk/controllers.js.map +1 -0
  180. package/dist/gtk/index.d.ts +2 -1
  181. package/dist/gtk/index.js +7 -1
  182. package/dist/gtk/index.js.map +1 -1
  183. package/dist/gtkx/bridge/geometry.js +6 -4
  184. package/dist/gtkx/bridge/geometry.js.map +1 -1
  185. package/dist/gtkx/bridge/index.d.ts +5 -3
  186. package/dist/gtkx/bridge/index.js +6 -3
  187. package/dist/gtkx/bridge/index.js.map +1 -1
  188. package/dist/gtkx/bridge/slot-portal.js.map +1 -1
  189. package/dist/gtkx/bridge/use-signal.js +1 -1
  190. package/dist/gtkx/bridge/use-signal.js.map +1 -1
  191. package/dist/gtkx/bridge/view-box.d.ts +56 -0
  192. package/dist/gtkx/bridge/view-box.js +394 -9
  193. package/dist/gtkx/bridge/view-box.js.map +1 -1
  194. package/dist/gtkx/bridge/widget-css.d.ts +17 -0
  195. package/dist/gtkx/bridge/widget-css.js +72 -0
  196. package/dist/gtkx/bridge/widget-css.js.map +1 -0
  197. package/dist/index.d.ts +3 -3
  198. package/dist/index.js +2 -2
  199. package/dist/index.js.map +1 -1
  200. package/dist/layout/driven-size.d.ts +12 -0
  201. package/dist/layout/driven-size.js +70 -0
  202. package/dist/layout/driven-size.js.map +1 -0
  203. package/dist/layout/engine.d.ts +17 -1
  204. package/dist/layout/engine.js +3 -20
  205. package/dist/layout/engine.js.map +1 -1
  206. package/dist/layout/node.d.ts +13 -0
  207. package/dist/layout/node.js +14 -0
  208. package/dist/layout/node.js.map +1 -1
  209. package/dist/layout/yoga.d.ts +3 -2
  210. package/dist/layout/yoga.js +5 -2
  211. package/dist/layout/yoga.js.map +1 -1
  212. package/dist/mcp/data/generated.d.ts +257 -60
  213. package/dist/mcp/data/generated.js +306 -62
  214. package/dist/mcp/data/generated.js.map +1 -1
  215. package/dist/metro/index.d.ts +10 -0
  216. package/dist/metro/index.js +21 -12
  217. package/dist/metro/index.js.map +1 -1
  218. package/dist/navigation/sidebar.d.ts +16 -0
  219. package/dist/navigation/sidebar.js +65 -1
  220. package/dist/navigation/sidebar.js.map +1 -1
  221. package/dist/reanimated-compat/animated-ref.d.ts +32 -0
  222. package/dist/reanimated-compat/animated-ref.js +57 -0
  223. package/dist/reanimated-compat/animated-ref.js.map +1 -0
  224. package/dist/reanimated-compat/animation.d.ts +177 -0
  225. package/dist/reanimated-compat/animation.js +540 -0
  226. package/dist/reanimated-compat/animation.js.map +1 -0
  227. package/dist/reanimated-compat/color.d.ts +28 -0
  228. package/dist/reanimated-compat/color.js +249 -0
  229. package/dist/reanimated-compat/color.js.map +1 -0
  230. package/dist/reanimated-compat/decay.d.ts +39 -0
  231. package/dist/reanimated-compat/decay.js +96 -0
  232. package/dist/reanimated-compat/decay.js.map +1 -0
  233. package/dist/reanimated-compat/easing.d.ts +30 -0
  234. package/dist/reanimated-compat/easing.js +76 -0
  235. package/dist/reanimated-compat/easing.js.map +1 -0
  236. package/dist/reanimated-compat/hooks.d.ts +14 -0
  237. package/dist/reanimated-compat/hooks.js +217 -0
  238. package/dist/reanimated-compat/hooks.js.map +1 -0
  239. package/dist/reanimated-compat/index.d.ts +258 -0
  240. package/dist/reanimated-compat/index.js +464 -0
  241. package/dist/reanimated-compat/index.js.map +1 -0
  242. package/dist/reanimated-compat/interpolation.d.ts +18 -0
  243. package/dist/reanimated-compat/interpolation.js +122 -0
  244. package/dist/reanimated-compat/interpolation.js.map +1 -0
  245. package/dist/reanimated-compat/layout-animation-config.d.ts +43 -0
  246. package/dist/reanimated-compat/layout-animation-config.js +78 -0
  247. package/dist/reanimated-compat/layout-animation-config.js.map +1 -0
  248. package/dist/reanimated-compat/layout-animation-presets.d.ts +117 -0
  249. package/dist/reanimated-compat/layout-animation-presets.js +498 -0
  250. package/dist/reanimated-compat/layout-animation-presets.js.map +1 -0
  251. package/dist/reanimated-compat/layout-animation-runtime.d.ts +21 -0
  252. package/dist/reanimated-compat/layout-animation-runtime.js +311 -0
  253. package/dist/reanimated-compat/layout-animation-runtime.js.map +1 -0
  254. package/dist/reanimated-compat/layout-animation-view.d.ts +27 -0
  255. package/dist/reanimated-compat/layout-animation-view.js +266 -0
  256. package/dist/reanimated-compat/layout-animation-view.js.map +1 -0
  257. package/dist/reanimated-compat/layout-animation.d.ts +171 -0
  258. package/dist/reanimated-compat/layout-animation.js +469 -0
  259. package/dist/reanimated-compat/layout-animation.js.map +1 -0
  260. package/dist/reanimated-compat/layout-transitions.d.ts +83 -0
  261. package/dist/reanimated-compat/layout-transitions.js +350 -0
  262. package/dist/reanimated-compat/layout-transitions.js.map +1 -0
  263. package/dist/reanimated-compat/mutable.d.ts +29 -0
  264. package/dist/reanimated-compat/mutable.js +139 -0
  265. package/dist/reanimated-compat/mutable.js.map +1 -0
  266. package/dist/reanimated-compat/props.d.ts +18 -0
  267. package/dist/reanimated-compat/props.js +111 -0
  268. package/dist/reanimated-compat/props.js.map +1 -0
  269. package/dist/reanimated-compat/scroll-handler.d.ts +119 -0
  270. package/dist/reanimated-compat/scroll-handler.js +274 -0
  271. package/dist/reanimated-compat/scroll-handler.js.map +1 -0
  272. package/dist/reanimated-compat/scroll-offset.d.ts +12 -0
  273. package/dist/reanimated-compat/scroll-offset.js +104 -0
  274. package/dist/reanimated-compat/scroll-offset.js.map +1 -0
  275. package/dist/reanimated-compat/style.d.ts +90 -0
  276. package/dist/reanimated-compat/style.js +452 -0
  277. package/dist/reanimated-compat/style.js.map +1 -0
  278. package/dist/reanimated-compat/test-timers.d.ts +28 -0
  279. package/dist/reanimated-compat/test-timers.js +136 -0
  280. package/dist/reanimated-compat/test-timers.js.map +1 -0
  281. package/dist/reanimated-compat/threads.d.ts +13 -0
  282. package/dist/reanimated-compat/threads.js +41 -0
  283. package/dist/reanimated-compat/threads.js.map +1 -0
  284. package/dist/reanimated-compat/tracking.d.ts +41 -0
  285. package/dist/reanimated-compat/tracking.js +106 -0
  286. package/dist/reanimated-compat/tracking.js.map +1 -0
  287. package/dist/reanimated-compat/updater-animations.d.ts +36 -0
  288. package/dist/reanimated-compat/updater-animations.js +273 -0
  289. package/dist/reanimated-compat/updater-animations.js.map +1 -0
  290. package/dist/responder/system.d.ts +80 -7
  291. package/dist/responder/system.js +143 -23
  292. package/dist/responder/system.js.map +1 -1
  293. package/dist/responder/use-responder.d.ts +11 -0
  294. package/dist/responder/use-responder.js +225 -6
  295. package/dist/responder/use-responder.js.map +1 -1
  296. package/dist/runner/host-dev.js +1 -1
  297. package/dist/runner/host-dev.js.map +1 -1
  298. package/dist/runner/host.js +1 -1
  299. package/dist/runner/host.js.map +1 -1
  300. package/dist/runner/index.js +3 -3
  301. package/dist/runner/index.js.map +1 -1
  302. package/dist/sea/gtkx-config-module.js +1 -1
  303. package/dist/sea/gtkx-config-module.js.map +1 -1
  304. package/dist/style/absolute-insets.d.ts +26 -0
  305. package/dist/style/absolute-insets.js +113 -0
  306. package/dist/style/absolute-insets.js.map +1 -0
  307. package/dist/style/animated-size.d.ts +25 -0
  308. package/dist/style/animated-size.js +225 -0
  309. package/dist/style/animated-size.js.map +1 -0
  310. package/dist/style/colors.d.ts +17 -0
  311. package/dist/style/colors.js +25 -6
  312. package/dist/style/colors.js.map +1 -1
  313. package/dist/style/imperative-css.d.ts +21 -0
  314. package/dist/style/imperative-css.js +63 -0
  315. package/dist/style/imperative-css.js.map +1 -0
  316. package/dist/style/index.d.ts +2 -1
  317. package/dist/style/index.js +2 -1
  318. package/dist/style/index.js.map +1 -1
  319. package/dist/style/split-style.js +5 -0
  320. package/dist/style/split-style.js.map +1 -1
  321. package/dist/testing/index.js.map +1 -1
  322. package/dist/unsupported-export.d.ts +8 -0
  323. package/dist/unsupported-export.js +66 -0
  324. package/dist/unsupported-export.js.map +1 -0
  325. package/dist/vite/index.d.ts +21 -8
  326. package/dist/vite/index.js +127 -82
  327. package/dist/vite/index.js.map +1 -1
  328. package/dist/vitest/index.d.ts +2 -2
  329. package/dist/vitest/index.js.map +1 -1
  330. package/dist/worklets-compat/index.d.ts +4 -0
  331. package/dist/worklets-compat/index.js +28 -0
  332. package/dist/worklets-compat/index.js.map +1 -0
  333. package/dist/worklets-compat/surface.d.ts +110 -0
  334. package/dist/worklets-compat/surface.js +153 -0
  335. package/dist/worklets-compat/surface.js.map +1 -0
  336. package/package.json +25 -9
  337. package/types.d.ts +9 -0
  338. package/dist/common/list.d.ts +0 -82
  339. package/dist/common/list.js +0 -166
  340. package/dist/common/list.js.map +0 -1
@@ -0,0 +1,249 @@
1
+ // `interpolateColor` and the colour helpers, ported from upstream's
2
+ // `src/interpolateColor.ts` and `src/Colors.ts` — the gamma correction, the
3
+ // HSV hue-wrap fix and the `transparent` handling included, because each of
4
+ // them is visible in the output and an app that looks right on iOS has to
5
+ // look right here.
6
+ //
7
+ // THE PARSER IS THE PLATFORM'S, NOT RN's. Upstream vendors a copy of React
8
+ // Native's `normalizeColor` and packs every colour into an AARRGGBB integer,
9
+ // because that integer is what crosses to native. Nothing crosses here:
10
+ // a colour's destination is a GTK stylesheet, which takes a string, and
11
+ // `src/style/colors.ts` already parses every syntax RN accepts on its way
12
+ // there. Reusing it means one parser, one set of accepted syntaxes, and no
13
+ // possibility of `interpolateColor` accepting a colour the stylesheet would
14
+ // then reject — or the reverse. The packed integer is not reproduced at all;
15
+ // it has no consumer on this platform, which is also why `processColor`
16
+ // stays refused rather than returning a number nothing here can use.
17
+ //
18
+ // The one thing the platform's parser accepts and this file cannot is a
19
+ // theme colour — `PlatformColor("accent-bg-color")`, i.e. `var(--…)` or
20
+ // `@named`. Those have no value until GTK resolves them against the live
21
+ // theme, so they can be handed to a stylesheet but not blended with a second
22
+ // colour. That fails loudly here rather than producing `rgba(NaN, …)`.
23
+ import { parseColorToRgba } from "../style/colors";
24
+ import { Extrapolation, interpolate } from "./interpolation";
25
+ const THEME_COLOR = /^(var\(|@)/i;
26
+ const parse = (color) => {
27
+ if (typeof color !== "string") {
28
+ throw new Error(`react-native-reanimated: interpolateColor() takes colour STRINGS, got ${typeof color} (${String(color)}). ` +
29
+ "React Native's packed colour integers do not exist on this platform — a colour's destination here is a " +
30
+ "GTK stylesheet, which is why `processColor` is not implemented either. See docs/api.md.");
31
+ }
32
+ const parsed = parseColorToRgba(color);
33
+ if (parsed !== null) {
34
+ return parsed;
35
+ }
36
+ if (THEME_COLOR.test(color.trim())) {
37
+ throw new Error(`react-native-reanimated: cannot interpolate the theme colour ${JSON.stringify(color)}. ` +
38
+ "PlatformColor values are resolved by GTK against the live theme, so they have no numeric value to " +
39
+ "blend with. Interpolate between literal colours, or swap the theme colour on a shared value instead.");
40
+ }
41
+ throw new Error(`react-native-reanimated: ${JSON.stringify(color)} is not a colour this platform understands. ` +
42
+ "Accepted: #rgb/#rgba/#rrggbb/#rrggbbaa, rgb()/rgba(), hsl()/hsla(), the CSS colour names, and `transparent`.");
43
+ };
44
+ // Upstream rounds alpha to three decimals; the value goes into a string, so
45
+ // the difference is observable.
46
+ const rgbaColor = (r, g, b, alpha = 1) => `rgba(${r}, ${g}, ${b}, ${Math.round(alpha * 1000) / 1000})`;
47
+ /** True for a string this platform can turn into a colour. Upstream's contract: numbers are not colours. */
48
+ export const isColor = (value) => typeof value === "string" && parseColorToRgba(value) !== null;
49
+ /**
50
+ * A colour as four 0-1 channels. Alpha is quantised to eighths-of-a-percent
51
+ * (n/255) exactly as upstream's is, because upstream reads it back out of an
52
+ * 8-bit packed integer and callers compare against those values.
53
+ */
54
+ export const convertToRGBA = (color) => {
55
+ const { r, g, b, a } = parse(color);
56
+ return [r / 255, g / 255, b / 255, Math.round(a * 255) / 255];
57
+ };
58
+ /** The inverse of {@link convertToRGBA}, in upstream's output format. */
59
+ export const rgbaArrayToRGBAColor = (rgba) => {
60
+ const alpha = rgba[3] < 0.001 ? 0 : rgba[3];
61
+ return `rgba(${Math.round(rgba[0] * 255)}, ${Math.round(rgba[1] * 255)}, ${Math.round(rgba[2] * 255)}, ${alpha})`;
62
+ };
63
+ // h in 0-1, s/v in 0-1, from 0-255 channels — upstream's exact arithmetic.
64
+ const rgbToHsv = (r, g, b) => {
65
+ const max = Math.max(r, g, b);
66
+ const min = Math.min(r, g, b);
67
+ const d = max - min;
68
+ const s = max === 0 ? 0 : d / max;
69
+ const v = max / 255;
70
+ let h = 0;
71
+ if (max !== min) {
72
+ if (max === r) {
73
+ h = (g - b + d * (g < b ? 6 : 0)) / (6 * d);
74
+ }
75
+ else if (max === g) {
76
+ h = (b - r + d * 2) / (6 * d);
77
+ }
78
+ else {
79
+ h = (r - g + d * 4) / (6 * d);
80
+ }
81
+ }
82
+ return { h, s, v };
83
+ };
84
+ const hsvToRgb = (h, s, v) => {
85
+ const i = Math.floor(h * 6);
86
+ const f = h * 6 - i;
87
+ const p = v * (1 - s);
88
+ const q = v * (1 - f * s);
89
+ const t = v * (1 - (1 - f) * s);
90
+ let triple;
91
+ switch (i % 6) {
92
+ case 0:
93
+ triple = [v, t, p];
94
+ break;
95
+ case 1:
96
+ triple = [q, v, p];
97
+ break;
98
+ case 2:
99
+ triple = [p, v, t];
100
+ break;
101
+ case 3:
102
+ triple = [p, q, v];
103
+ break;
104
+ case 4:
105
+ triple = [t, p, v];
106
+ break;
107
+ default:
108
+ triple = [v, p, q];
109
+ }
110
+ return {
111
+ r: Math.round(triple[0] * 255),
112
+ g: Math.round(triple[1] * 255),
113
+ b: Math.round(triple[2] * 255),
114
+ };
115
+ };
116
+ const toLinearSpace = (channels, gamma) => channels.map((value) => Math.pow(value / 255, gamma));
117
+ const toGammaSpace = (value, gamma) => Math.round(Math.pow(value, 1 / gamma) * 255);
118
+ /**
119
+ * `transparent` carries no hue, so interpolating THROUGH it the naive way
120
+ * fades to black and back. Upstream's fix, reproduced: a transparent stop
121
+ * borrows the RGB of the colour next to it and contributes only its alpha —
122
+ * which means the stop list grows by one entry at each transparent boundary.
123
+ */
124
+ const processColorRanges = (inputRange, outputRange) => {
125
+ const stops = [];
126
+ const colors = [];
127
+ let previousWasTransparent = false;
128
+ for (let index = 0; index < inputRange.length; index += 1) {
129
+ const color = outputRange[index];
130
+ const isTransparent = typeof color === "string" && color.trim().toLowerCase() === "transparent";
131
+ if (!isTransparent) {
132
+ const parsed = parse(color);
133
+ if (previousWasTransparent) {
134
+ // Coming OUT of transparent: start from this colour's own RGB at
135
+ // alpha 0, so the fade is of opacity and not of hue.
136
+ stops.push(inputRange[index - 1]);
137
+ colors.push({ ...parsed, a: 0 });
138
+ }
139
+ stops.push(inputRange[index]);
140
+ colors.push(parsed);
141
+ }
142
+ else if (!previousWasTransparent) {
143
+ if (index > 0) {
144
+ const last = colors[colors.length - 1];
145
+ stops.push(inputRange[index]);
146
+ colors.push({ ...last, a: 0 });
147
+ }
148
+ }
149
+ else if (index === inputRange.length - 1 && colors.length === 0) {
150
+ // Every stop was transparent: two stops of nothing is the whole range.
151
+ stops.push(inputRange[0], inputRange[inputRange.length - 1]);
152
+ colors.push({ r: 0, g: 0, b: 0, a: 0 }, { r: 0, g: 0, b: 0, a: 0 });
153
+ }
154
+ previousWasTransparent = isTransparent;
155
+ }
156
+ return { stops, colors };
157
+ };
158
+ const interpolateRgb = (value, stops, colors, gamma) => {
159
+ let outputR = colors.map((color) => color.r);
160
+ let outputG = colors.map((color) => color.g);
161
+ let outputB = colors.map((color) => color.b);
162
+ const outputA = colors.map((color) => color.a);
163
+ if (gamma !== 1) {
164
+ outputR = toLinearSpace(outputR, gamma);
165
+ outputG = toLinearSpace(outputG, gamma);
166
+ outputB = toLinearSpace(outputB, gamma);
167
+ }
168
+ const r = interpolate(value, stops, outputR, Extrapolation.CLAMP);
169
+ const g = interpolate(value, stops, outputG, Extrapolation.CLAMP);
170
+ const b = interpolate(value, stops, outputB, Extrapolation.CLAMP);
171
+ const a = interpolate(value, stops, outputA, Extrapolation.CLAMP);
172
+ if (gamma === 1) {
173
+ return rgbaColor(r, g, b, a);
174
+ }
175
+ return rgbaColor(toGammaSpace(r, gamma), toGammaSpace(g, gamma), toGammaSpace(b, gamma), a);
176
+ };
177
+ const interpolateHsv = (value, stops, colors, corrected) => {
178
+ const hsv = colors.map((color) => rgbToHsv(color.r, color.g, color.b));
179
+ const originalH = hsv.map((entry) => entry.h);
180
+ let h;
181
+ if (corrected) {
182
+ // A hue jump wider than half the circle means the short way round is the
183
+ // other way: shift the far end past the wrap point and re-enter the range
184
+ // an epsilon later at the original hue, so the following segment is
185
+ // unaffected.
186
+ const correctedStops = [stops[0]];
187
+ const correctedH = [originalH[0]];
188
+ for (let index = 1; index < originalH.length; index += 1) {
189
+ const current = originalH[index];
190
+ const previous = originalH[index - 1];
191
+ const delta = current - previous;
192
+ if (current > previous && delta > 0.5) {
193
+ correctedStops.push(stops[index], stops[index] + 0.00001);
194
+ correctedH.push(current - 1, current);
195
+ }
196
+ else if (current < previous && delta < -0.5) {
197
+ correctedStops.push(stops[index], stops[index] + 0.00001);
198
+ correctedH.push(current + 1, current);
199
+ }
200
+ else {
201
+ correctedStops.push(stops[index]);
202
+ correctedH.push(current);
203
+ }
204
+ }
205
+ h =
206
+ (interpolate(value, correctedStops, correctedH, Extrapolation.CLAMP) +
207
+ 1) %
208
+ 1;
209
+ }
210
+ else {
211
+ h = interpolate(value, stops, originalH, Extrapolation.CLAMP);
212
+ }
213
+ const s = interpolate(value, stops, hsv.map((entry) => entry.s), Extrapolation.CLAMP);
214
+ const v = interpolate(value, stops, hsv.map((entry) => entry.v), Extrapolation.CLAMP);
215
+ const a = interpolate(value, stops, colors.map((color) => color.a), Extrapolation.CLAMP);
216
+ const rgb = hsvToRgb(h, s, v);
217
+ return rgbaColor(rgb.r, rgb.g, rgb.b, a);
218
+ };
219
+ /**
220
+ * Maps `value` from `inputRange` onto a range of colours, returning
221
+ * `rgba(r, g, b, a)`.
222
+ *
223
+ * Outside `inputRange` the result is clamped to the nearest end, as upstream
224
+ * does — colour has no meaningful extrapolation.
225
+ */
226
+ export const interpolateColor = (value, inputRange, outputRange, colorSpace = "RGB", options = {}) => {
227
+ if (inputRange.length !== outputRange.length) {
228
+ throw new Error("react-native-reanimated: interpolateColor() input and output ranges must be the same length " +
229
+ `(got ${inputRange.length} and ${outputRange.length})`);
230
+ }
231
+ const { stops, colors } = processColorRanges(inputRange, outputRange);
232
+ if (stops.length < 2) {
233
+ throw new Error("react-native-reanimated: interpolateColor() input and output ranges must contain at least two values");
234
+ }
235
+ if (colorSpace === "RGB") {
236
+ return interpolateRgb(value, stops, colors, options.gamma ?? 2.2);
237
+ }
238
+ if (colorSpace === "HSV") {
239
+ return interpolateHsv(value, stops, colors, options.useCorrectedHSVInterpolation ?? true);
240
+ }
241
+ // Upstream also takes 'LAB' (Oklab, through a vendored slice of culori).
242
+ // Not reproduced: it is the only colour space that needs a second
243
+ // dependency, and upstream feeds it 0-255 channels where culori documents
244
+ // 0-1, so matching it would mean matching a scaling bug. Refused by name
245
+ // rather than silently treated as RGB.
246
+ throw new Error(`react-native-reanimated: unsupported colour space "${String(colorSpace)}" for interpolateColor(). ` +
247
+ "Supported here: 'RGB', 'HSV'. ('LAB' is upstream-only — see docs/api.md.)");
248
+ };
249
+ //# sourceMappingURL=color.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"color.js","sourceRoot":"","sources":["../../src/reanimated-compat/color.ts"],"names":[],"mappings":"AAAA,oEAAoE;AACpE,4EAA4E;AAC5E,4EAA4E;AAC5E,0EAA0E;AAC1E,mBAAmB;AACnB,EAAE;AACF,2EAA2E;AAC3E,6EAA6E;AAC7E,wEAAwE;AACxE,wEAAwE;AACxE,0EAA0E;AAC1E,2EAA2E;AAC3E,4EAA4E;AAC5E,6EAA6E;AAC7E,wEAAwE;AACxE,qEAAqE;AACrE,EAAE;AACF,wEAAwE;AACxE,wEAAwE;AACxE,yEAAyE;AACzE,6EAA6E;AAC7E,uEAAuE;AAEvE,OAAO,EAAE,gBAAgB,EAAa,MAAM,iBAAiB,CAAA;AAC7D,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA;AAe5D,MAAM,WAAW,GAAG,aAAa,CAAA;AAEjC,MAAM,KAAK,GAAG,CAAC,KAAc,EAAQ,EAAE;IACrC,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,MAAM,IAAI,KAAK,CACb,yEAAyE,OAAO,KAAK,KAAK,MAAM,CAAC,KAAK,CAAC,KAAK;YAC1G,yGAAyG;YACzG,yFAAyF,CAC5F,CAAA;IACH,CAAC;IACD,MAAM,MAAM,GAAG,gBAAgB,CAAC,KAAK,CAAC,CAAA;IACtC,IAAI,MAAM,KAAK,IAAI,EAAE,CAAC;QACpB,OAAO,MAAM,CAAA;IACf,CAAC;IACD,IAAI,WAAW,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,EAAE,CAAC;QACnC,MAAM,IAAI,KAAK,CACb,gEAAgE,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI;YACvF,oGAAoG;YACpG,sGAAsG,CACzG,CAAA;IACH,CAAC;IACD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C7C,CAAA;IACH,CAAC;IACD,yEAAyE;IACzE,kEAAkE;IAClE,0EAA0E;IAC1E,yEAAyE;IACzE,uCAAuC;IACvC,MAAM,IAAI,KAAK,CACb,sDAAsD,MAAM,CAAC,UAAU,CAAC,4BAA4B;QAClG,2EAA2E,CAC9E,CAAA;AACH,CAAC,CAAA","sourcesContent":["// `interpolateColor` and the colour helpers, ported from upstream's\n// `src/interpolateColor.ts` and `src/Colors.ts` — the gamma correction, the\n// HSV hue-wrap fix and the `transparent` handling included, because each of\n// them is visible in the output and an app that looks right on iOS has to\n// look right here.\n//\n// THE PARSER IS THE PLATFORM'S, NOT RN's. Upstream vendors a copy of React\n// Native's `normalizeColor` and packs every colour into an AARRGGBB integer,\n// because that integer is what crosses to native. Nothing crosses here:\n// a colour's destination is a GTK stylesheet, which takes a string, and\n// `src/style/colors.ts` already parses every syntax RN accepts on its way\n// there. Reusing it means one parser, one set of accepted syntaxes, and no\n// possibility of `interpolateColor` accepting a colour the stylesheet would\n// then reject — or the reverse. The packed integer is not reproduced at all;\n// it has no consumer on this platform, which is also why `processColor`\n// stays refused rather than returning a number nothing here can use.\n//\n// The one thing the platform's parser accepts and this file cannot is a\n// theme colour — `PlatformColor(\"accent-bg-color\")`, i.e. `var(--…)` or\n// `@named`. Those have no value until GTK resolves them against the live\n// theme, so they can be handed to a stylesheet but not blended with a second\n// colour. That fails loudly here rather than producing `rgba(NaN, …)`.\n\nimport { parseColorToRgba, type Rgba } from \"../style/colors\"\nimport { Extrapolation, interpolate } from \"./interpolation\"\n\n/** Upstream's shape: red, green, blue and alpha, each normalised to 0-1. */\nexport type ParsedColorArray = [number, number, number, number]\n\n/** Upstream's `InterpolationOptions`, with upstream's defaults. */\nexport type ColorInterpolationOptions = {\n /** Gamma used for the RGB colour space. Defaults to `2.2`. */\n gamma?: number\n /** Wrap hues the short way round. Defaults to `true`. */\n useCorrectedHSVInterpolation?: boolean\n}\n\nexport type ColorSpace = \"RGB\" | \"HSV\"\n\nconst THEME_COLOR = /^(var\\(|@)/i\n\nconst parse = (color: unknown): Rgba => {\n if (typeof color !== \"string\") {\n throw new Error(\n `react-native-reanimated: interpolateColor() takes colour STRINGS, got ${typeof color} (${String(color)}). ` +\n \"React Native's packed colour integers do not exist on this platform — a colour's destination here is a \" +\n \"GTK stylesheet, which is why `processColor` is not implemented either. See docs/api.md.\",\n )\n }\n const parsed = parseColorToRgba(color)\n if (parsed !== null) {\n return parsed\n }\n if (THEME_COLOR.test(color.trim())) {\n throw new Error(\n `react-native-reanimated: cannot interpolate the theme colour ${JSON.stringify(color)}. ` +\n \"PlatformColor values are resolved by GTK against the live theme, so they have no numeric value to \" +\n \"blend with. Interpolate between literal colours, or swap the theme colour on a shared value instead.\",\n )\n }\n throw new Error(\n `react-native-reanimated: ${JSON.stringify(color)} is not a colour this platform understands. ` +\n \"Accepted: #rgb/#rgba/#rrggbb/#rrggbbaa, rgb()/rgba(), hsl()/hsla(), the CSS colour names, and `transparent`.\",\n )\n}\n\n// Upstream rounds alpha to three decimals; the value goes into a string, so\n// the difference is observable.\nconst rgbaColor = (r: number, g: number, b: number, alpha = 1): string =>\n `rgba(${r}, ${g}, ${b}, ${Math.round(alpha * 1000) / 1000})`\n\n/** True for a string this platform can turn into a colour. Upstream's contract: numbers are not colours. */\nexport const isColor = (value: unknown): value is string =>\n typeof value === \"string\" && parseColorToRgba(value) !== null\n\n/**\n * A colour as four 0-1 channels. Alpha is quantised to eighths-of-a-percent\n * (n/255) exactly as upstream's is, because upstream reads it back out of an\n * 8-bit packed integer and callers compare against those values.\n */\nexport const convertToRGBA = (color: unknown): ParsedColorArray => {\n const { r, g, b, a } = parse(color)\n return [r / 255, g / 255, b / 255, Math.round(a * 255) / 255]\n}\n\n/** The inverse of {@link convertToRGBA}, in upstream's output format. */\nexport const rgbaArrayToRGBAColor = (rgba: ParsedColorArray): string => {\n const alpha = rgba[3] < 0.001 ? 0 : rgba[3]\n return `rgba(${Math.round(rgba[0] * 255)}, ${Math.round(rgba[1] * 255)}, ${Math.round(rgba[2] * 255)}, ${alpha})`\n}\n\n// h in 0-1, s/v in 0-1, from 0-255 channels — upstream's exact arithmetic.\nconst rgbToHsv = (\n r: number,\n g: number,\n b: number,\n): { h: number; s: number; v: number } => {\n const max = Math.max(r, g, b)\n const min = Math.min(r, g, b)\n const d = max - min\n const s = max === 0 ? 0 : d / max\n const v = max / 255\n let h = 0\n if (max !== min) {\n if (max === r) {\n h = (g - b + d * (g < b ? 6 : 0)) / (6 * d)\n } else if (max === g) {\n h = (b - r + d * 2) / (6 * d)\n } else {\n h = (r - g + d * 4) / (6 * d)\n }\n }\n return { h, s, v }\n}\n\nconst hsvToRgb = (\n h: number,\n s: number,\n v: number,\n): { r: number; g: number; b: number } => {\n const i = Math.floor(h * 6)\n const f = h * 6 - i\n const p = v * (1 - s)\n const q = v * (1 - f * s)\n const t = v * (1 - (1 - f) * s)\n let triple: [number, number, number]\n switch (i % 6) {\n case 0:\n triple = [v, t, p]\n break\n case 1:\n triple = [q, v, p]\n break\n case 2:\n triple = [p, v, t]\n break\n case 3:\n triple = [p, q, v]\n break\n case 4:\n triple = [t, p, v]\n break\n default:\n triple = [v, p, q]\n }\n return {\n r: Math.round(triple[0] * 255),\n g: Math.round(triple[1] * 255),\n b: Math.round(triple[2] * 255),\n }\n}\n\nconst toLinearSpace = (channels: number[], gamma: number): number[] =>\n channels.map((value) => Math.pow(value / 255, gamma))\n\nconst toGammaSpace = (value: number, gamma: number): number =>\n Math.round(Math.pow(value, 1 / gamma) * 255)\n\n/**\n * `transparent` carries no hue, so interpolating THROUGH it the naive way\n * fades to black and back. Upstream's fix, reproduced: a transparent stop\n * borrows the RGB of the colour next to it and contributes only its alpha —\n * which means the stop list grows by one entry at each transparent boundary.\n */\nconst processColorRanges = (\n inputRange: readonly number[],\n outputRange: readonly unknown[],\n): { stops: number[]; colors: Rgba[] } => {\n const stops: number[] = []\n const colors: Rgba[] = []\n let previousWasTransparent = false\n\n for (let index = 0; index < inputRange.length; index += 1) {\n const color = outputRange[index]\n const isTransparent =\n typeof color === \"string\" && color.trim().toLowerCase() === \"transparent\"\n\n if (!isTransparent) {\n const parsed = parse(color)\n if (previousWasTransparent) {\n // Coming OUT of transparent: start from this colour's own RGB at\n // alpha 0, so the fade is of opacity and not of hue.\n stops.push(inputRange[index - 1]!)\n colors.push({ ...parsed, a: 0 })\n }\n stops.push(inputRange[index]!)\n colors.push(parsed)\n } else if (!previousWasTransparent) {\n if (index > 0) {\n const last = colors[colors.length - 1]!\n stops.push(inputRange[index]!)\n colors.push({ ...last, a: 0 })\n }\n } else if (index === inputRange.length - 1 && colors.length === 0) {\n // Every stop was transparent: two stops of nothing is the whole range.\n stops.push(inputRange[0]!, inputRange[inputRange.length - 1]!)\n colors.push({ r: 0, g: 0, b: 0, a: 0 }, { r: 0, g: 0, b: 0, a: 0 })\n }\n\n previousWasTransparent = isTransparent\n }\n\n return { stops, colors }\n}\n\nconst interpolateRgb = (\n value: number,\n stops: number[],\n colors: Rgba[],\n gamma: number,\n): string => {\n let outputR = colors.map((color) => color.r)\n let outputG = colors.map((color) => color.g)\n let outputB = colors.map((color) => color.b)\n const outputA = colors.map((color) => color.a)\n if (gamma !== 1) {\n outputR = toLinearSpace(outputR, gamma)\n outputG = toLinearSpace(outputG, gamma)\n outputB = toLinearSpace(outputB, gamma)\n }\n const r = interpolate(value, stops, outputR, Extrapolation.CLAMP)\n const g = interpolate(value, stops, outputG, Extrapolation.CLAMP)\n const b = interpolate(value, stops, outputB, Extrapolation.CLAMP)\n const a = interpolate(value, stops, outputA, Extrapolation.CLAMP)\n if (gamma === 1) {\n return rgbaColor(r, g, b, a)\n }\n return rgbaColor(\n toGammaSpace(r, gamma),\n toGammaSpace(g, gamma),\n toGammaSpace(b, gamma),\n a,\n )\n}\n\nconst interpolateHsv = (\n value: number,\n stops: number[],\n colors: Rgba[],\n corrected: boolean,\n): string => {\n const hsv = colors.map((color) => rgbToHsv(color.r, color.g, color.b))\n const originalH = hsv.map((entry) => entry.h)\n let h: number\n\n if (corrected) {\n // A hue jump wider than half the circle means the short way round is the\n // other way: shift the far end past the wrap point and re-enter the range\n // an epsilon later at the original hue, so the following segment is\n // unaffected.\n const correctedStops: number[] = [stops[0]!]\n const correctedH: number[] = [originalH[0]!]\n for (let index = 1; index < originalH.length; index += 1) {\n const current = originalH[index]!\n const previous = originalH[index - 1]!\n const delta = current - previous\n if (current > previous && delta > 0.5) {\n correctedStops.push(stops[index]!, stops[index]! + 0.00001)\n correctedH.push(current - 1, current)\n } else if (current < previous && delta < -0.5) {\n correctedStops.push(stops[index]!, stops[index]! + 0.00001)\n correctedH.push(current + 1, current)\n } else {\n correctedStops.push(stops[index]!)\n correctedH.push(current)\n }\n }\n h =\n (interpolate(value, correctedStops, correctedH, Extrapolation.CLAMP) +\n 1) %\n 1\n } else {\n h = interpolate(value, stops, originalH, Extrapolation.CLAMP)\n }\n\n const s = interpolate(\n value,\n stops,\n hsv.map((entry) => entry.s),\n Extrapolation.CLAMP,\n )\n const v = interpolate(\n value,\n stops,\n hsv.map((entry) => entry.v),\n Extrapolation.CLAMP,\n )\n const a = interpolate(\n value,\n stops,\n colors.map((color) => color.a),\n Extrapolation.CLAMP,\n )\n const rgb = hsvToRgb(h, s, v)\n return rgbaColor(rgb.r, rgb.g, rgb.b, a)\n}\n\n/**\n * Maps `value` from `inputRange` onto a range of colours, returning\n * `rgba(r, g, b, a)`.\n *\n * Outside `inputRange` the result is clamped to the nearest end, as upstream\n * does — colour has no meaningful extrapolation.\n */\nexport const interpolateColor = (\n value: number,\n inputRange: readonly number[],\n outputRange: readonly string[],\n colorSpace: ColorSpace = \"RGB\",\n options: ColorInterpolationOptions = {},\n): string => {\n if (inputRange.length !== outputRange.length) {\n throw new Error(\n \"react-native-reanimated: interpolateColor() input and output ranges must be the same length \" +\n `(got ${inputRange.length} and ${outputRange.length})`,\n )\n }\n const { stops, colors } = processColorRanges(inputRange, outputRange)\n if (stops.length < 2) {\n throw new Error(\n \"react-native-reanimated: interpolateColor() input and output ranges must contain at least two values\",\n )\n }\n if (colorSpace === \"RGB\") {\n return interpolateRgb(value, stops, colors, options.gamma ?? 2.2)\n }\n if (colorSpace === \"HSV\") {\n return interpolateHsv(\n value,\n stops,\n colors,\n options.useCorrectedHSVInterpolation ?? true,\n )\n }\n // Upstream also takes 'LAB' (Oklab, through a vendored slice of culori).\n // Not reproduced: it is the only colour space that needs a second\n // dependency, and upstream feeds it 0-255 channels where culori documents\n // 0-1, so matching it would mean matching a scaling bug. Refused by name\n // rather than silently treated as RGB.\n throw new Error(\n `react-native-reanimated: unsupported colour space \"${String(colorSpace)}\" for interpolateColor(). ` +\n \"Supported here: 'RGB', 'HSV'. ('LAB' is upstream-only — see docs/api.md.)\",\n )\n}\n"]}
@@ -0,0 +1,39 @@
1
+ import type { MakeStep } from "../animated/index";
2
+ /**
3
+ * Upstream's config, unchanged. `clamp` is a `[min, max]` pair rather than the
4
+ * `{ min, max }` object `withSpring` takes — that asymmetry is upstream's and
5
+ * copying it is what lets source move over untouched.
6
+ */
7
+ export type WithDecayConfig = {
8
+ /** Initial velocity, in units per second. Defaults to 0. */
9
+ velocity?: number;
10
+ /** How fast the velocity decays, 0-1. Defaults to 0.998. */
11
+ deceleration?: number;
12
+ /** Multiplier applied to the velocity every frame. Defaults to 1. */
13
+ velocityFactor?: number;
14
+ /** Range the value is confined to. */
15
+ clamp?: [min: number, max: number];
16
+ /** Bounce past `clamp` and settle back onto it. Requires `clamp`. */
17
+ rubberBandEffect?: boolean;
18
+ /** Strength of that bounce. Defaults to 0.6. */
19
+ rubberBandFactor?: number;
20
+ };
21
+ type ResolvedDecayConfig = Required<Omit<WithDecayConfig, "clamp">> & {
22
+ clamp?: [min: number, max: number];
23
+ };
24
+ /**
25
+ * Fills in upstream's defaults and applies upstream's own validation — which
26
+ * runs here at the `withDecay()` call rather than on the animation's first
27
+ * frame, so a bad config throws at the line that wrote it.
28
+ */
29
+ export declare const resolveDecayConfig: (config?: WithDecayConfig) => ResolvedDecayConfig;
30
+ /**
31
+ * The per-frame step, in the shape the platform's value animation takes:
32
+ * elapsed milliseconds since the animation's first frame in, the next position
33
+ * and whether it has settled out. All of upstream's cross-frame state —
34
+ * current position, current velocity, the previous timestamp, and whether the
35
+ * rubber band has engaged — lives in this closure, which is rebuilt on every
36
+ * `start()`, so a restart picks up from wherever the value is now.
37
+ */
38
+ export declare const decayStep: (config: ResolvedDecayConfig) => MakeStep;
39
+ export {};
@@ -0,0 +1,96 @@
1
+ const SLOPE_FACTOR = 0.1;
2
+ const VELOCITY_EPS = 1;
3
+ const DERIVATIVE_EPS = 0.1;
4
+ /** Upstream's cap on a single frame's contribution: a stalled frame cannot fling. */
5
+ const MAX_FRAME_MS = 64;
6
+ const DEFAULTS = {
7
+ velocity: 0,
8
+ deceleration: 0.998,
9
+ velocityFactor: 1,
10
+ rubberBandEffect: false,
11
+ rubberBandFactor: 0.6,
12
+ };
13
+ /**
14
+ * Fills in upstream's defaults and applies upstream's own validation — which
15
+ * runs here at the `withDecay()` call rather than on the animation's first
16
+ * frame, so a bad config throws at the line that wrote it.
17
+ */
18
+ export const resolveDecayConfig = (config = {}) => {
19
+ const resolved = { ...DEFAULTS, ...config };
20
+ if (config.clamp !== undefined) {
21
+ if (!Array.isArray(config.clamp)) {
22
+ throw new Error(`react-native-reanimated: withDecay()'s \`clamp\` must be an array but is ${typeof config.clamp}.`);
23
+ }
24
+ if (config.clamp.length !== 2) {
25
+ throw new Error(`react-native-reanimated: withDecay()'s \`clamp\` must contain 2 items but has ${config.clamp.length}.`);
26
+ }
27
+ }
28
+ if (resolved.velocityFactor <= 0) {
29
+ throw new Error(`react-native-reanimated: withDecay()'s \`velocityFactor\` must be greater than 0 but is ${resolved.velocityFactor}.`);
30
+ }
31
+ if (resolved.rubberBandEffect && !resolved.clamp) {
32
+ throw new Error("react-native-reanimated: withDecay() needs a `clamp` range when `rubberBandEffect` is set.");
33
+ }
34
+ return resolved;
35
+ };
36
+ const usesRubberBand = (config) => config.rubberBandEffect && Array.isArray(config.clamp);
37
+ /**
38
+ * The per-frame step, in the shape the platform's value animation takes:
39
+ * elapsed milliseconds since the animation's first frame in, the next position
40
+ * and whether it has settled out. All of upstream's cross-frame state —
41
+ * current position, current velocity, the previous timestamp, and whether the
42
+ * rubber band has engaged — lives in this closure, which is rebuilt on every
43
+ * `start()`, so a restart picks up from wherever the value is now.
44
+ */
45
+ export const decayStep = (config) => (startValue) => {
46
+ const initialVelocity = config.velocity;
47
+ const rubberBand = usesRubberBand(config);
48
+ let current = startValue;
49
+ let velocity = initialVelocity;
50
+ let lastTimestamp = 0;
51
+ let springActive = false;
52
+ return (elapsedMs) => {
53
+ const deltaTime = Math.min(Math.max(elapsedMs - lastTimestamp, 0), MAX_FRAME_MS);
54
+ const envelope = Math.exp(-(1 - config.deceleration) * elapsedMs * SLOPE_FACTOR);
55
+ if (rubberBand) {
56
+ const clamp = config.clamp;
57
+ // The nearer bound is the one the band pulls back to.
58
+ const bound = Math.abs(current - clamp[0]) < Math.abs(current - clamp[1])
59
+ ? clamp[0]
60
+ : clamp[1];
61
+ const overshoot = current < clamp[0] || current > clamp[1] ? current - bound : 0;
62
+ const nextVelocity = velocity * envelope - overshoot * config.rubberBandFactor;
63
+ if (Math.abs(overshoot) > DERIVATIVE_EPS) {
64
+ springActive = true;
65
+ }
66
+ else if (springActive) {
67
+ // It went past the bound and has come back: land exactly on it.
68
+ return { position: bound, done: true };
69
+ }
70
+ else if (Math.abs(nextVelocity) < VELOCITY_EPS) {
71
+ return { position: current, done: true };
72
+ }
73
+ current += (nextVelocity * config.velocityFactor * deltaTime) / 1000;
74
+ velocity = nextVelocity;
75
+ lastTimestamp = elapsedMs;
76
+ return { position: current, done: false };
77
+ }
78
+ const nextVelocity = velocity * envelope;
79
+ current += (nextVelocity * config.velocityFactor * deltaTime) / 1000;
80
+ velocity = nextVelocity;
81
+ lastTimestamp = elapsedMs;
82
+ if (config.clamp) {
83
+ // Which bound stops it is decided by the INITIAL direction, not the
84
+ // current one: upstream's own rule, and the reason a fling that starts
85
+ // inside the range and reverses is not stopped by the far edge.
86
+ if (initialVelocity < 0 && current <= config.clamp[0]) {
87
+ return { position: config.clamp[0], done: true };
88
+ }
89
+ if (initialVelocity > 0 && current >= config.clamp[1]) {
90
+ return { position: config.clamp[1], done: true };
91
+ }
92
+ }
93
+ return { position: current, done: Math.abs(nextVelocity) < VELOCITY_EPS };
94
+ };
95
+ };
96
+ //# sourceMappingURL=decay.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"decay.js","sourceRoot":"","sources":["../../src/reanimated-compat/decay.ts"],"names":[],"mappings":"AA0BA,MAAM,YAAY,GAAG,GAAG,CAAA;AACxB,MAAM,YAAY,GAAG,CAAC,CAAA;AACtB,MAAM,cAAc,GAAG,GAAG,CAAA;AAC1B,qFAAqF;AACrF,MAAM,YAAY,GAAG,EAAE,CAAA;AA0BvB,MAAM,QAAQ,GAAG;IACf,QAAQ,EAAE,CAAC;IACX,YAAY,EAAE,KAAK;IACnB,cAAc,EAAE,CAAC;IACjB,gBAAgB,EAAE,KAAK;IACvB,gBAAgB,EAAE,GAAG;CACb,CAAA;AAEV;;;;GAIG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAChC,SAA0B,EAAE,EACP,EAAE;IACvB,MAAM,QAAQ,GAAwB,EAAE,GAAG,QAAQ,EAAE,GAAG,MAAM,EAAE,CAAA;IAChE,IAAI,MAAM,CAAC,KAAK,KAAK,SAAS,EAAE,CAAC;QAC/B,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;YACjC,MAAM,IAAI,KAAK,CACb,4EAA4E,OAAO,MAAM,CAAC,KAAK,GAAG,CACnG,CAAA;QACH,CAAC;QACD,IAAI,MAAM,CAAC,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC9B,MAAM,IAAI,KAAK,CACb,iFAAiF,MAAM,CAAC,KAAK,CAAC,MAAM,GAAG,CACxG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YAAY,GAAG,MAAM,CAAC,cAAc,GAAG,SAAS,CAAC,GAAG,IAAI,CAAA;QACpE,QAAQ,GAAG,YAAY,CAAA;QACvB,aAAa,GAAG,SAAS,CAAA;QAEzB,IAAI,MAAM,CAAC,KAAK,EAAE,CAAC;YACjB,oEAAoE;YACpE,uEAAuE;YACvE,gEAAgE;YAChE,IAAI,eAAe,GAAG,CAAC,IAAI,OAAO,IAAI,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;gBACtD,OAAO,EAAE,QAAQ,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,CAAA;YAClD,CAAC;YACD,IAAI,eAAe,GAAG,CAAC,IAAI,OAAO,IAAI,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;gBACtD,OAAO,EAAE,QAAQ,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,CAAA;YAClD,CAAC;QACH,CAAC;QACD,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC,YAAY,CAAC,GAAG,YAAY,EAAE,CAAA;IAC3E,CAAC,CAAA;AACH,CAAC,CAAA","sourcesContent":["// `withDecay` — the release-and-coast half of every fling.\n//\n// This is the one animation whose maths belongs to Reanimated rather than to\n// React Native: `Animated.decay` exists upstream in RN too, but it is a\n// different curve with a different parameterisation (velocity in px/ms, a\n// single closed-form exponential, a 0.1px rest test), and neither `clamp` nor\n// the rubber band exists there at all. So the step function below is ported\n// from react-native-reanimated 4.5.3's own\n// `src/animation/decay/{rigidDecay,rubberBandDecay}.ts` line for line, and\n// runs on the platform's frame loop like every other animation in this layer —\n// no second clock, no new engine, just a different per-frame step.\n//\n// PORTED AS-IS INCLUDES THE ODD PART, deliberately. Upstream multiplies the\n// ALREADY-DECAYED velocity by `exp(-k * totalElapsed)` on every frame rather\n// than the initial velocity, so the decay compounds into a Gaussian rather\n// than the exponential the `deceleration` name suggests. That is what shipped\n// apps are tuned against — a fling that travels the \"correct\" exponential\n// distance here would overshoot every list those apps calibrated on mobile —\n// so it is reproduced rather than corrected.\n//\n// The one value that is a CHOICE: `VELOCITY_EPS`, upstream's stop threshold,\n// is `IS_WEB ? 1/20 : 1`. This platform is not the web — pixels are device\n// pixels and velocities arrive in px/s exactly as on a phone — so it takes\n// the native branch, which is also the one react-native-windows takes.\nimport type { MakeStep } from \"../animated/index\"\n\nconst SLOPE_FACTOR = 0.1\nconst VELOCITY_EPS = 1\nconst DERIVATIVE_EPS = 0.1\n/** Upstream's cap on a single frame's contribution: a stalled frame cannot fling. */\nconst MAX_FRAME_MS = 64\n\n/**\n * Upstream's config, unchanged. `clamp` is a `[min, max]` pair rather than the\n * `{ min, max }` object `withSpring` takes — that asymmetry is upstream's and\n * copying it is what lets source move over untouched.\n */\nexport type WithDecayConfig = {\n /** Initial velocity, in units per second. Defaults to 0. */\n velocity?: number\n /** How fast the velocity decays, 0-1. Defaults to 0.998. */\n deceleration?: number\n /** Multiplier applied to the velocity every frame. Defaults to 1. */\n velocityFactor?: number\n /** Range the value is confined to. */\n clamp?: [min: number, max: number]\n /** Bounce past `clamp` and settle back onto it. Requires `clamp`. */\n rubberBandEffect?: boolean\n /** Strength of that bounce. Defaults to 0.6. */\n rubberBandFactor?: number\n}\n\ntype ResolvedDecayConfig = Required<Omit<WithDecayConfig, \"clamp\">> & {\n clamp?: [min: number, max: number]\n}\n\nconst DEFAULTS = {\n velocity: 0,\n deceleration: 0.998,\n velocityFactor: 1,\n rubberBandEffect: false,\n rubberBandFactor: 0.6,\n} as const\n\n/**\n * Fills in upstream's defaults and applies upstream's own validation — which\n * runs here at the `withDecay()` call rather than on the animation's first\n * frame, so a bad config throws at the line that wrote it.\n */\nexport const resolveDecayConfig = (\n config: WithDecayConfig = {},\n): ResolvedDecayConfig => {\n const resolved: ResolvedDecayConfig = { ...DEFAULTS, ...config }\n if (config.clamp !== undefined) {\n if (!Array.isArray(config.clamp)) {\n throw new Error(\n `react-native-reanimated: withDecay()'s \\`clamp\\` must be an array but is ${typeof config.clamp}.`,\n )\n }\n if (config.clamp.length !== 2) {\n throw new Error(\n `react-native-reanimated: withDecay()'s \\`clamp\\` must contain 2 items but has ${config.clamp.length}.`,\n )\n }\n }\n if (resolved.velocityFactor <= 0) {\n throw new Error(\n `react-native-reanimated: withDecay()'s \\`velocityFactor\\` must be greater than 0 but is ${resolved.velocityFactor}.`,\n )\n }\n if (resolved.rubberBandEffect && !resolved.clamp) {\n throw new Error(\n \"react-native-reanimated: withDecay() needs a `clamp` range when `rubberBandEffect` is set.\",\n )\n }\n return resolved\n}\n\nconst usesRubberBand = (\n config: ResolvedDecayConfig,\n): config is ResolvedDecayConfig & { clamp: [number, number] } =>\n config.rubberBandEffect && Array.isArray(config.clamp)\n\n/**\n * The per-frame step, in the shape the platform's value animation takes:\n * elapsed milliseconds since the animation's first frame in, the next position\n * and whether it has settled out. All of upstream's cross-frame state —\n * current position, current velocity, the previous timestamp, and whether the\n * rubber band has engaged — lives in this closure, which is rebuilt on every\n * `start()`, so a restart picks up from wherever the value is now.\n */\nexport const decayStep =\n (config: ResolvedDecayConfig): MakeStep =>\n (startValue) => {\n const initialVelocity = config.velocity\n const rubberBand = usesRubberBand(config)\n let current = startValue\n let velocity = initialVelocity\n let lastTimestamp = 0\n let springActive = false\n\n return (elapsedMs) => {\n const deltaTime = Math.min(\n Math.max(elapsedMs - lastTimestamp, 0),\n MAX_FRAME_MS,\n )\n const envelope = Math.exp(\n -(1 - config.deceleration) * elapsedMs * SLOPE_FACTOR,\n )\n\n if (rubberBand) {\n const clamp = config.clamp\n // The nearer bound is the one the band pulls back to.\n const bound =\n Math.abs(current - clamp[0]) < Math.abs(current - clamp[1])\n ? clamp[0]\n : clamp[1]\n const overshoot =\n current < clamp[0] || current > clamp[1] ? current - bound : 0\n const nextVelocity =\n velocity * envelope - overshoot * config.rubberBandFactor\n\n if (Math.abs(overshoot) > DERIVATIVE_EPS) {\n springActive = true\n } else if (springActive) {\n // It went past the bound and has come back: land exactly on it.\n return { position: bound, done: true }\n } else if (Math.abs(nextVelocity) < VELOCITY_EPS) {\n return { position: current, done: true }\n }\n\n current += (nextVelocity * config.velocityFactor * deltaTime) / 1000\n velocity = nextVelocity\n lastTimestamp = elapsedMs\n return { position: current, done: false }\n }\n\n const nextVelocity = velocity * envelope\n current += (nextVelocity * config.velocityFactor * deltaTime) / 1000\n velocity = nextVelocity\n lastTimestamp = elapsedMs\n\n if (config.clamp) {\n // Which bound stops it is decided by the INITIAL direction, not the\n // current one: upstream's own rule, and the reason a fling that starts\n // inside the range and reverses is not stopped by the far edge.\n if (initialVelocity < 0 && current <= config.clamp[0]) {\n return { position: config.clamp[0], done: true }\n }\n if (initialVelocity > 0 && current >= config.clamp[1]) {\n return { position: config.clamp[1], done: true }\n }\n }\n return { position: current, done: Math.abs(nextVelocity) < VELOCITY_EPS }\n }\n }\n"]}
@@ -0,0 +1,30 @@
1
+ export type EasingFunction = (t: number) => number;
2
+ /**
3
+ * Reanimated wraps bezier curves in a factory so the (comparatively
4
+ * expensive) sample table is built when the animation starts rather than when
5
+ * the config object is written. `withTiming` accepts either shape.
6
+ */
7
+ export type EasingFunctionFactory = {
8
+ factory: () => EasingFunction;
9
+ };
10
+ export declare const Easing: {
11
+ linear: EasingFunction;
12
+ ease: EasingFunction;
13
+ quad: EasingFunction;
14
+ cubic: EasingFunction;
15
+ poly: (n: number) => EasingFunction;
16
+ sin: EasingFunction;
17
+ circle: EasingFunction;
18
+ exp: EasingFunction;
19
+ elastic: (bounciness?: number) => EasingFunction;
20
+ back: (s?: number) => EasingFunction;
21
+ bounce: EasingFunction;
22
+ bezier: (x1: number, y1: number, x2: number, y2: number) => EasingFunctionFactory;
23
+ bezierFn: (x1: number, y1: number, x2: number, y2: number) => EasingFunction;
24
+ steps: (n?: number, roundToNextStep?: boolean) => EasingFunction;
25
+ in: (easing: EasingFunction) => EasingFunction;
26
+ out: (easing: EasingFunction) => EasingFunction;
27
+ inOut: (easing: EasingFunction) => EasingFunction;
28
+ };
29
+ /** Accepts either shape `withTiming`'s `easing` config takes. */
30
+ export declare const resolveEasing: (easing: EasingFunction | EasingFunctionFactory) => EasingFunction;
@@ -0,0 +1,76 @@
1
+ // Reanimated's Easing, which is NOT React Native's Easing and cannot be
2
+ // re-exported from `src/animated/easing.ts`:
3
+ //
4
+ // - `Easing.bezier(...)` returns `{ factory }` here, a plain function in RN.
5
+ // `withTiming` unwraps the factory; `Easing.bezierFn` is the RN-shaped
6
+ // escape hatch. Re-exporting the platform's would make
7
+ // `easing: Easing.bezier(.25,.1,.25,1)` a silently wrong easing rather
8
+ // than an error.
9
+ // - Reanimated ships `poly`, `sin`, `circle`, `exp`, `elastic`, `back`,
10
+ // `bounce` and `steps`, none of which the platform's RN-faithful subset
11
+ // has.
12
+ //
13
+ // The curve solver itself is shared: `Easing.bezier` in `src/animated` is the
14
+ // same sampled-Newton bezier the `bezier-easing` package implements and that
15
+ // both libraries embed, so this module borrows it rather than carrying a
16
+ // second copy.
17
+ import { Easing as PlatformEasing } from "../animated/index";
18
+ const bezierSolver = PlatformEasing.bezier;
19
+ const linear = (t) => t;
20
+ const ease = bezierSolver(0.42, 0, 1, 1);
21
+ const quad = (t) => t * t;
22
+ const cubic = (t) => t * t * t;
23
+ const poly = (n) => (t) => Math.pow(t, n);
24
+ const sin = (t) => 1 - Math.cos((t * Math.PI) / 2);
25
+ const circle = (t) => 1 - Math.sqrt(1 - t * t);
26
+ const exp = (t) => Math.pow(2, 10 * (t - 1));
27
+ const elastic = (bounciness = 1) => {
28
+ const p = bounciness * Math.PI;
29
+ return (t) => 1 - Math.pow(Math.cos((t * Math.PI) / 2), 3) * Math.cos(t * p);
30
+ };
31
+ const back = (s = 1.70158) => (t) => t * t * ((s + 1) * t - s);
32
+ const bounce = (t) => {
33
+ if (t < 1 / 2.75) {
34
+ return 7.5625 * t * t;
35
+ }
36
+ if (t < 2 / 2.75) {
37
+ const shifted = t - 1.5 / 2.75;
38
+ return 7.5625 * shifted * shifted + 0.75;
39
+ }
40
+ if (t < 2.5 / 2.75) {
41
+ const shifted = t - 2.25 / 2.75;
42
+ return 7.5625 * shifted * shifted + 0.9375;
43
+ }
44
+ const shifted = t - 2.625 / 2.75;
45
+ return 7.5625 * shifted * shifted + 0.984375;
46
+ };
47
+ const bezier = (x1, y1, x2, y2) => ({
48
+ factory: () => bezierSolver(x1, y1, x2, y2),
49
+ });
50
+ const bezierFn = (x1, y1, x2, y2) => bezierSolver(x1, y1, x2, y2);
51
+ const steps = (n = 10, roundToNextStep = true) => (t) => {
52
+ const value = Math.min(Math.max(t, 0), 1) * n;
53
+ return roundToNextStep ? Math.ceil(value) / n : Math.floor(value) / n;
54
+ };
55
+ export const Easing = {
56
+ linear,
57
+ ease,
58
+ quad,
59
+ cubic,
60
+ poly,
61
+ sin,
62
+ circle,
63
+ exp,
64
+ elastic,
65
+ back,
66
+ bounce,
67
+ bezier,
68
+ bezierFn,
69
+ steps,
70
+ in: (easing) => easing,
71
+ out: (easing) => (t) => 1 - easing(1 - t),
72
+ inOut: (easing) => (t) => t < 0.5 ? easing(t * 2) / 2 : 1 - easing((1 - t) * 2) / 2,
73
+ };
74
+ /** Accepts either shape `withTiming`'s `easing` config takes. */
75
+ export const resolveEasing = (easing) => (typeof easing === "function" ? easing : easing.factory());
76
+ //# sourceMappingURL=easing.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"easing.js","sourceRoot":"","sources":["../../src/reanimated-compat/easing.ts"],"names":[],"mappings":"AAAA,wEAAwE;AACxE,6CAA6C;AAC7C,EAAE;AACF,+EAA+E;AAC/E,2EAA2E;AAC3E,2DAA2D;AAC3D,2EAA2E;AAC3E,qBAAqB;AACrB,0EAA0E;AAC1E,4EAA4E;AAC5E,WAAW;AACX,EAAE;AACF,8EAA8E;AAC9E,6EAA6E;AAC7E,yEAAyE;AACzE,eAAe;AACf,OAAO,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C9D,CAAA;AAED,iEAAiE;AACjE,MAAM,CAAC,MAAM,aAAa,GAAG,CAC3B,MAA8C,EAC9B,EAAE,CAAC,CAAC,OAAO,MAAM,KAAK,UAAU,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC,CAAA","sourcesContent":["// Reanimated's Easing, which is NOT React Native's Easing and cannot be\n// re-exported from `src/animated/easing.ts`:\n//\n// - `Easing.bezier(...)` returns `{ factory }` here, a plain function in RN.\n// `withTiming` unwraps the factory; `Easing.bezierFn` is the RN-shaped\n// escape hatch. Re-exporting the platform's would make\n// `easing: Easing.bezier(.25,.1,.25,1)` a silently wrong easing rather\n// than an error.\n// - Reanimated ships `poly`, `sin`, `circle`, `exp`, `elastic`, `back`,\n// `bounce` and `steps`, none of which the platform's RN-faithful subset\n// has.\n//\n// The curve solver itself is shared: `Easing.bezier` in `src/animated` is the\n// same sampled-Newton bezier the `bezier-easing` package implements and that\n// both libraries embed, so this module borrows it rather than carrying a\n// second copy.\nimport { Easing as PlatformEasing } from \"../animated/index\"\n\nexport type EasingFunction = (t: number) => number\n\n/**\n * Reanimated wraps bezier curves in a factory so the (comparatively\n * expensive) sample table is built when the animation starts rather than when\n * the config object is written. `withTiming` accepts either shape.\n */\nexport type EasingFunctionFactory = { factory: () => EasingFunction }\n\nconst bezierSolver = PlatformEasing.bezier\n\nconst linear: EasingFunction = (t) => t\n\nconst ease: EasingFunction = bezierSolver(0.42, 0, 1, 1)\n\nconst quad: EasingFunction = (t) => t * t\n\nconst cubic: EasingFunction = (t) => t * t * t\n\nconst poly =\n (n: number): EasingFunction =>\n (t) =>\n Math.pow(t, n)\n\nconst sin: EasingFunction = (t) => 1 - Math.cos((t * Math.PI) / 2)\n\nconst circle: EasingFunction = (t) => 1 - Math.sqrt(1 - t * t)\n\nconst exp: EasingFunction = (t) => Math.pow(2, 10 * (t - 1))\n\nconst elastic = (bounciness = 1): EasingFunction => {\n const p = bounciness * Math.PI\n return (t) => 1 - Math.pow(Math.cos((t * Math.PI) / 2), 3) * Math.cos(t * p)\n}\n\nconst back =\n (s = 1.70158): EasingFunction =>\n (t) =>\n t * t * ((s + 1) * t - s)\n\nconst bounce: EasingFunction = (t) => {\n if (t < 1 / 2.75) {\n return 7.5625 * t * t\n }\n if (t < 2 / 2.75) {\n const shifted = t - 1.5 / 2.75\n return 7.5625 * shifted * shifted + 0.75\n }\n if (t < 2.5 / 2.75) {\n const shifted = t - 2.25 / 2.75\n return 7.5625 * shifted * shifted + 0.9375\n }\n const shifted = t - 2.625 / 2.75\n return 7.5625 * shifted * shifted + 0.984375\n}\n\nconst bezier = (\n x1: number,\n y1: number,\n x2: number,\n y2: number,\n): EasingFunctionFactory => ({\n factory: () => bezierSolver(x1, y1, x2, y2),\n})\n\nconst bezierFn = (\n x1: number,\n y1: number,\n x2: number,\n y2: number,\n): EasingFunction => bezierSolver(x1, y1, x2, y2)\n\nconst steps =\n (n = 10, roundToNextStep = true): EasingFunction =>\n (t) => {\n const value = Math.min(Math.max(t, 0), 1) * n\n return roundToNextStep ? Math.ceil(value) / n : Math.floor(value) / n\n }\n\nexport const Easing = {\n linear,\n ease,\n quad,\n cubic,\n poly,\n sin,\n circle,\n exp,\n elastic,\n back,\n bounce,\n bezier,\n bezierFn,\n steps,\n in: (easing: EasingFunction): EasingFunction => easing,\n out:\n (easing: EasingFunction): EasingFunction =>\n (t) =>\n 1 - easing(1 - t),\n inOut:\n (easing: EasingFunction): EasingFunction =>\n (t) =>\n t < 0.5 ? easing(t * 2) / 2 : 1 - easing((1 - t) * 2) / 2,\n}\n\n/** Accepts either shape `withTiming`'s `easing` config takes. */\nexport const resolveEasing = (\n easing: EasingFunction | EasingFunctionFactory,\n): EasingFunction => (typeof easing === \"function\" ? easing : easing.factory())\n"]}
@@ -0,0 +1,14 @@
1
+ import { type AnimationEngine } from "./animation";
2
+ import type { SharedValue } from "./mutable";
3
+ import { type PropsObject } from "./props";
4
+ import { type StyleObject } from "./style";
5
+ export type DependencyList = readonly unknown[];
6
+ type MakeMutable = <T>(initial: T) => SharedValue<T>;
7
+ export declare const createHooks: (makeMutable: MakeMutable, engine: AnimationEngine) => {
8
+ useSharedValue: <T>(initialValue: T | (() => T)) => SharedValue<T>;
9
+ useDerivedValue: <T>(updater: () => T, dependencies?: DependencyList) => SharedValue<T>;
10
+ useAnimatedReaction: <T>(prepare: () => T, react: (current: T, previous: T | null) => void, dependencies?: DependencyList) => void;
11
+ useAnimatedStyle: (updater: () => StyleObject, dependencies?: DependencyList) => StyleObject;
12
+ useAnimatedProps: (updater: () => PropsObject, dependencies?: DependencyList) => PropsObject;
13
+ };
14
+ export {};