@amazon-devices/react-native-worklets 1.0.0-rn-83

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 (348) hide show
  1. package/Common/cpp/worklets/AnimationFrameQueue/AnimationFrameBatchinator.cpp +71 -0
  2. package/Common/cpp/worklets/AnimationFrameQueue/AnimationFrameBatchinator.h +38 -0
  3. package/Common/cpp/worklets/NativeModules/JSIWorkletsModuleProxy.cpp +712 -0
  4. package/Common/cpp/worklets/NativeModules/JSIWorkletsModuleProxy.h +88 -0
  5. package/Common/cpp/worklets/NativeModules/WorkletsModuleProxy.cpp +89 -0
  6. package/Common/cpp/worklets/NativeModules/WorkletsModuleProxy.h +80 -0
  7. package/Common/cpp/worklets/Public/AsyncQueue.h +14 -0
  8. package/Common/cpp/worklets/Registries/EventHandlerRegistry.cpp +94 -0
  9. package/Common/cpp/worklets/Registries/EventHandlerRegistry.h +51 -0
  10. package/Common/cpp/worklets/Registries/WorkletRuntimeRegistry.cpp +8 -0
  11. package/Common/cpp/worklets/Registries/WorkletRuntimeRegistry.h +40 -0
  12. package/Common/cpp/worklets/Resources/SynchronizableUnpacker.cpp +49 -0
  13. package/Common/cpp/worklets/Resources/Unpackers.h +6 -0
  14. package/Common/cpp/worklets/Resources/ValueUnpacker.cpp +53 -0
  15. package/Common/cpp/worklets/RunLoop/AsyncQueueImpl.cpp +62 -0
  16. package/Common/cpp/worklets/RunLoop/AsyncQueueImpl.h +46 -0
  17. package/Common/cpp/worklets/RunLoop/EventLoop.cpp +112 -0
  18. package/Common/cpp/worklets/RunLoop/EventLoop.h +52 -0
  19. package/Common/cpp/worklets/SharedItems/Serializable.cpp +545 -0
  20. package/Common/cpp/worklets/SharedItems/Serializable.h +473 -0
  21. package/Common/cpp/worklets/SharedItems/Synchronizable.cpp +67 -0
  22. package/Common/cpp/worklets/SharedItems/Synchronizable.h +59 -0
  23. package/Common/cpp/worklets/SharedItems/SynchronizableAccess.cpp +81 -0
  24. package/Common/cpp/worklets/SharedItems/SynchronizableAccess.h +45 -0
  25. package/Common/cpp/worklets/Tools/Defs.h +10 -0
  26. package/Common/cpp/worklets/Tools/FeatureFlags.cpp +15 -0
  27. package/Common/cpp/worklets/Tools/FeatureFlags.h +44 -0
  28. package/Common/cpp/worklets/Tools/JSISerializer.cpp +342 -0
  29. package/Common/cpp/worklets/Tools/JSISerializer.h +51 -0
  30. package/Common/cpp/worklets/Tools/JSLogger.cpp +68 -0
  31. package/Common/cpp/worklets/Tools/JSLogger.h +37 -0
  32. package/Common/cpp/worklets/Tools/JSScheduler.cpp +24 -0
  33. package/Common/cpp/worklets/Tools/JSScheduler.h +39 -0
  34. package/Common/cpp/worklets/Tools/PlatformLogger.h +16 -0
  35. package/Common/cpp/worklets/Tools/SingleInstanceChecker.h +82 -0
  36. package/Common/cpp/worklets/Tools/ThreadSafeQueue.h +49 -0
  37. package/Common/cpp/worklets/Tools/UIScheduler.cpp +19 -0
  38. package/Common/cpp/worklets/Tools/UIScheduler.h +26 -0
  39. package/Common/cpp/worklets/Tools/VersionUtils.cpp +75 -0
  40. package/Common/cpp/worklets/Tools/VersionUtils.h +28 -0
  41. package/Common/cpp/worklets/Tools/WorkletEventHandler.cpp +29 -0
  42. package/Common/cpp/worklets/Tools/WorkletEventHandler.h +41 -0
  43. package/Common/cpp/worklets/Tools/WorkletsJSIUtils.cpp +46 -0
  44. package/Common/cpp/worklets/Tools/WorkletsJSIUtils.h +208 -0
  45. package/Common/cpp/worklets/Tools/WorkletsSystraceSection.h +161 -0
  46. package/Common/cpp/worklets/Tools/WorkletsVersion.cpp +54 -0
  47. package/Common/cpp/worklets/Tools/WorkletsVersion.h +20 -0
  48. package/Common/cpp/worklets/WorkletRuntime/RNRuntimeWorkletDecorator.cpp +38 -0
  49. package/Common/cpp/worklets/WorkletRuntime/RNRuntimeWorkletDecorator.h +21 -0
  50. package/Common/cpp/worklets/WorkletRuntime/RuntimeData.cpp +3 -0
  51. package/Common/cpp/worklets/WorkletRuntime/RuntimeData.h +12 -0
  52. package/Common/cpp/worklets/WorkletRuntime/RuntimeInitialization.md +191 -0
  53. package/Common/cpp/worklets/WorkletRuntime/RuntimeKind.h +16 -0
  54. package/Common/cpp/worklets/WorkletRuntime/RuntimeManager.cpp +105 -0
  55. package/Common/cpp/worklets/WorkletRuntime/RuntimeManager.h +63 -0
  56. package/Common/cpp/worklets/WorkletRuntime/UIRuntimeDecorator.cpp +23 -0
  57. package/Common/cpp/worklets/WorkletRuntime/UIRuntimeDecorator.h +16 -0
  58. package/Common/cpp/worklets/WorkletRuntime/WorkletHermesRuntime.cpp +119 -0
  59. package/Common/cpp/worklets/WorkletRuntime/WorkletHermesRuntime.h +134 -0
  60. package/Common/cpp/worklets/WorkletRuntime/WorkletRuntime.cpp +244 -0
  61. package/Common/cpp/worklets/WorkletRuntime/WorkletRuntime.h +102 -0
  62. package/Common/cpp/worklets/WorkletRuntime/WorkletRuntimeCollector.h +36 -0
  63. package/Common/cpp/worklets/WorkletRuntime/WorkletRuntimeDecorator.cpp +308 -0
  64. package/Common/cpp/worklets/WorkletRuntime/WorkletRuntimeDecorator.h +26 -0
  65. package/LICENSE +7 -0
  66. package/README.md +31 -0
  67. package/RNWorklets.podspec +94 -0
  68. package/SystemBundles/cc12deac6e91c435b76698c8445aed85612f2f88e733218d14f88a35d06fb0f4.bundle +10512 -0
  69. package/SystemBundles/cc12deac6e91c435b76698c8445aed85612f2f88e733218d14f88a35d06fb0f4.map +3771 -0
  70. package/SystemModules/amzn__react-native-worklets-1.modules.txt +39 -0
  71. package/SystemModules/amzn__react-native-worklets-1.private.modules.txt +61 -0
  72. package/SystemModules/keplerscript-system-bundle-config.json +7 -0
  73. package/android/CMakeLists.txt +124 -0
  74. package/android/build.gradle +350 -0
  75. package/android/gradle.properties +5 -0
  76. package/android/proguard-rules.pro +3 -0
  77. package/android/spotless.gradle +9 -0
  78. package/android/src/experimentalBundling/com/swmansion/worklets/WorkletsModule.java +149 -0
  79. package/android/src/legacyBundling/com/swmansion/worklets/WorkletsModule.java +122 -0
  80. package/android/src/main/AndroidManifest.xml +2 -0
  81. package/android/src/main/cpp/worklets/android/AndroidUIScheduler.cpp +63 -0
  82. package/android/src/main/cpp/worklets/android/AndroidUIScheduler.h +43 -0
  83. package/android/src/main/cpp/worklets/android/AnimationFrameCallback.h +34 -0
  84. package/android/src/main/cpp/worklets/android/PlatformLogger.cpp +29 -0
  85. package/android/src/main/cpp/worklets/android/WorkletsModule.cpp +115 -0
  86. package/android/src/main/cpp/worklets/android/WorkletsModule.h +78 -0
  87. package/android/src/main/cpp/worklets/android/WorkletsOnLoad.cpp +13 -0
  88. package/android/src/main/java/com/swmansion/worklets/AndroidUIScheduler.java +60 -0
  89. package/android/src/main/java/com/swmansion/worklets/JSCallInvokerResolver.java +27 -0
  90. package/android/src/main/java/com/swmansion/worklets/WorkletsMessageQueueThread.java +16 -0
  91. package/android/src/main/java/com/swmansion/worklets/WorkletsMessageQueueThreadBase.java +73 -0
  92. package/android/src/main/java/com/swmansion/worklets/WorkletsPackage.java +48 -0
  93. package/android/src/main/java/com/swmansion/worklets/runloop/AnimationFrameCallback.java +19 -0
  94. package/android/src/main/java/com/swmansion/worklets/runloop/AnimationFrameQueue.java +113 -0
  95. package/apple/worklets/apple/AnimationFrameQueue.h +15 -0
  96. package/apple/worklets/apple/AnimationFrameQueue.mm +135 -0
  97. package/apple/worklets/apple/AssertJavaScriptQueue.h +14 -0
  98. package/apple/worklets/apple/AssertTurboModuleManagerQueue.h +16 -0
  99. package/apple/worklets/apple/IOSUIScheduler.h +15 -0
  100. package/apple/worklets/apple/IOSUIScheduler.mm +29 -0
  101. package/apple/worklets/apple/PlatformLogger.mm +31 -0
  102. package/apple/worklets/apple/SlowAnimations.h +8 -0
  103. package/apple/worklets/apple/SlowAnimations.mm +45 -0
  104. package/apple/worklets/apple/WorkletsDisplayLink.h +21 -0
  105. package/apple/worklets/apple/WorkletsMessageThread.h +16 -0
  106. package/apple/worklets/apple/WorkletsMessageThread.mm +31 -0
  107. package/apple/worklets/apple/WorkletsModule.h +28 -0
  108. package/apple/worklets/apple/WorkletsModule.mm +121 -0
  109. package/bundleMode/index.d.ts +3 -0
  110. package/bundleMode/index.js +59 -0
  111. package/compatibility.json +11 -0
  112. package/kepler-compatibility.json +5 -0
  113. package/kepler-transformed-package-info.json +3 -0
  114. package/lib/module/PlatformChecker/PlatformChecker.js +8 -0
  115. package/lib/module/PlatformChecker/PlatformChecker.js.map +1 -0
  116. package/lib/module/PlatformChecker/index.js +18 -0
  117. package/lib/module/PlatformChecker/index.js.map +1 -0
  118. package/lib/module/WorkletsError.js +29 -0
  119. package/lib/module/WorkletsError.js.map +1 -0
  120. package/lib/module/WorkletsModule/JSWorklets.js +111 -0
  121. package/lib/module/WorkletsModule/JSWorklets.js.map +1 -0
  122. package/lib/module/WorkletsModule/NativeWorklets.js +126 -0
  123. package/lib/module/WorkletsModule/NativeWorklets.js.map +1 -0
  124. package/lib/module/WorkletsModule/index.js +4 -0
  125. package/lib/module/WorkletsModule/index.js.map +1 -0
  126. package/lib/module/WorkletsModule/workletsModuleInstance.js +7 -0
  127. package/lib/module/WorkletsModule/workletsModuleInstance.js.map +1 -0
  128. package/lib/module/WorkletsModule/workletsModuleInstance.web.js +5 -0
  129. package/lib/module/WorkletsModule/workletsModuleInstance.web.js.map +1 -0
  130. package/lib/module/WorkletsModule/workletsModuleProxy.js +4 -0
  131. package/lib/module/WorkletsModule/workletsModuleProxy.js.map +1 -0
  132. package/lib/module/bundleUnpacker.js +47 -0
  133. package/lib/module/bundleUnpacker.js.map +1 -0
  134. package/lib/module/callGuard.js +30 -0
  135. package/lib/module/callGuard.js.map +1 -0
  136. package/lib/module/deprecated.js +20 -0
  137. package/lib/module/deprecated.js.map +1 -0
  138. package/lib/module/errors.js +69 -0
  139. package/lib/module/errors.js.map +1 -0
  140. package/lib/module/featureFlags/index.js +48 -0
  141. package/lib/module/featureFlags/index.js.map +1 -0
  142. package/lib/module/featureFlags/staticFlags.json +4 -0
  143. package/lib/module/index.js +26 -0
  144. package/lib/module/index.js.map +1 -0
  145. package/lib/module/initializers.js +221 -0
  146. package/lib/module/initializers.js.map +1 -0
  147. package/lib/module/isSynchronizable.js +6 -0
  148. package/lib/module/isSynchronizable.js.map +1 -0
  149. package/lib/module/logger.js +15 -0
  150. package/lib/module/logger.js.map +1 -0
  151. package/lib/module/privateGlobals.d.js +7 -0
  152. package/lib/module/privateGlobals.d.js.map +1 -0
  153. package/lib/module/publicGlobals.js +6 -0
  154. package/lib/module/publicGlobals.js.map +1 -0
  155. package/lib/module/runLoop/common/setImmediatePolyfill.js +15 -0
  156. package/lib/module/runLoop/common/setImmediatePolyfill.js.map +1 -0
  157. package/lib/module/runLoop/common/setIntervalPolyfill.js +26 -0
  158. package/lib/module/runLoop/common/setIntervalPolyfill.js.map +1 -0
  159. package/lib/module/runLoop/uiRuntime/mockedRequestAnimationFrame.js +10 -0
  160. package/lib/module/runLoop/uiRuntime/mockedRequestAnimationFrame.js.map +1 -0
  161. package/lib/module/runLoop/uiRuntime/requestAnimationFrame.js +52 -0
  162. package/lib/module/runLoop/uiRuntime/requestAnimationFrame.js.map +1 -0
  163. package/lib/module/runLoop/uiRuntime/setTimeoutPolyfill.js +32 -0
  164. package/lib/module/runLoop/uiRuntime/setTimeoutPolyfill.js.map +1 -0
  165. package/lib/module/runLoop/workletRuntime/index.js +19 -0
  166. package/lib/module/runLoop/workletRuntime/index.js.map +1 -0
  167. package/lib/module/runLoop/workletRuntime/queueMicrotask.js +11 -0
  168. package/lib/module/runLoop/workletRuntime/queueMicrotask.js.map +1 -0
  169. package/lib/module/runLoop/workletRuntime/requestAnimationFramePolyfill.js +48 -0
  170. package/lib/module/runLoop/workletRuntime/requestAnimationFramePolyfill.js.map +1 -0
  171. package/lib/module/runLoop/workletRuntime/setTimeout.js +28 -0
  172. package/lib/module/runLoop/workletRuntime/setTimeout.js.map +1 -0
  173. package/lib/module/runLoop/workletRuntime/taskQueue.js +37 -0
  174. package/lib/module/runLoop/workletRuntime/taskQueue.js.map +1 -0
  175. package/lib/module/runtimeKind.js +39 -0
  176. package/lib/module/runtimeKind.js.map +1 -0
  177. package/lib/module/runtimes.js +100 -0
  178. package/lib/module/runtimes.js.map +1 -0
  179. package/lib/module/serializable.js +568 -0
  180. package/lib/module/serializable.js.map +1 -0
  181. package/lib/module/serializableMappingCache.js +37 -0
  182. package/lib/module/serializableMappingCache.js.map +1 -0
  183. package/lib/module/specs/NativeWorkletsModule.js +5 -0
  184. package/lib/module/specs/NativeWorkletsModule.js.map +1 -0
  185. package/lib/module/specs/NativeWorkletsModule.kepler.js +7 -0
  186. package/lib/module/specs/NativeWorkletsModule.kepler.js.map +1 -0
  187. package/lib/module/specs/index.js +10 -0
  188. package/lib/module/specs/index.js.map +1 -0
  189. package/lib/module/synchronizable.js +9 -0
  190. package/lib/module/synchronizable.js.map +1 -0
  191. package/lib/module/synchronizableUnpacker.js +42 -0
  192. package/lib/module/synchronizableUnpacker.js.map +1 -0
  193. package/lib/module/threads.js +347 -0
  194. package/lib/module/threads.js.map +1 -0
  195. package/lib/module/utils/checkCppVersion.js +30 -0
  196. package/lib/module/utils/checkCppVersion.js.map +1 -0
  197. package/lib/module/utils/jsVersion.js +9 -0
  198. package/lib/module/utils/jsVersion.js.map +1 -0
  199. package/lib/module/valueUnpacker.js +60 -0
  200. package/lib/module/valueUnpacker.js.map +1 -0
  201. package/lib/module/workletFunction.js +37 -0
  202. package/lib/module/workletFunction.js.map +1 -0
  203. package/lib/module/workletRuntimeEntry.js +32 -0
  204. package/lib/module/workletRuntimeEntry.js.map +1 -0
  205. package/lib/module/workletTypes.js +12 -0
  206. package/lib/module/workletTypes.js.map +1 -0
  207. package/lib/typescript/PlatformChecker/PlatformChecker.d.ts +5 -0
  208. package/lib/typescript/PlatformChecker/PlatformChecker.d.ts.map +1 -0
  209. package/lib/typescript/PlatformChecker/index.d.ts +10 -0
  210. package/lib/typescript/PlatformChecker/index.d.ts.map +1 -0
  211. package/lib/typescript/WorkletsError.d.ts +15 -0
  212. package/lib/typescript/WorkletsError.d.ts.map +1 -0
  213. package/lib/typescript/WorkletsModule/JSWorklets.d.ts +3 -0
  214. package/lib/typescript/WorkletsModule/JSWorklets.d.ts.map +1 -0
  215. package/lib/typescript/WorkletsModule/NativeWorklets.d.ts +3 -0
  216. package/lib/typescript/WorkletsModule/NativeWorklets.d.ts.map +1 -0
  217. package/lib/typescript/WorkletsModule/index.d.ts +3 -0
  218. package/lib/typescript/WorkletsModule/index.d.ts.map +1 -0
  219. package/lib/typescript/WorkletsModule/workletsModuleInstance.d.ts +2 -0
  220. package/lib/typescript/WorkletsModule/workletsModuleInstance.d.ts.map +1 -0
  221. package/lib/typescript/WorkletsModule/workletsModuleInstance.web.d.ts +2 -0
  222. package/lib/typescript/WorkletsModule/workletsModuleInstance.web.d.ts.map +1 -0
  223. package/lib/typescript/WorkletsModule/workletsModuleProxy.d.ts +37 -0
  224. package/lib/typescript/WorkletsModule/workletsModuleProxy.d.ts.map +1 -0
  225. package/lib/typescript/bundleUnpacker.d.ts +7 -0
  226. package/lib/typescript/bundleUnpacker.d.ts.map +1 -0
  227. package/lib/typescript/callGuard.d.ts +4 -0
  228. package/lib/typescript/callGuard.d.ts.map +1 -0
  229. package/lib/typescript/deprecated.d.ts +20 -0
  230. package/lib/typescript/deprecated.d.ts.map +1 -0
  231. package/lib/typescript/errors.d.ts +16 -0
  232. package/lib/typescript/errors.d.ts.map +1 -0
  233. package/lib/typescript/featureFlags/index.d.ts +23 -0
  234. package/lib/typescript/featureFlags/index.d.ts.map +1 -0
  235. package/lib/typescript/index.d.ts +17 -0
  236. package/lib/typescript/index.d.ts.map +1 -0
  237. package/lib/typescript/initializers.d.ts +17 -0
  238. package/lib/typescript/initializers.d.ts.map +1 -0
  239. package/lib/typescript/isSynchronizable.d.ts +3 -0
  240. package/lib/typescript/isSynchronizable.d.ts.map +1 -0
  241. package/lib/typescript/logger.d.ts +5 -0
  242. package/lib/typescript/logger.d.ts.map +1 -0
  243. package/lib/typescript/publicGlobals.d.ts +31 -0
  244. package/lib/typescript/publicGlobals.d.ts.map +1 -0
  245. package/lib/typescript/runLoop/common/setImmediatePolyfill.d.ts +2 -0
  246. package/lib/typescript/runLoop/common/setImmediatePolyfill.d.ts.map +1 -0
  247. package/lib/typescript/runLoop/common/setIntervalPolyfill.d.ts +2 -0
  248. package/lib/typescript/runLoop/common/setIntervalPolyfill.d.ts.map +1 -0
  249. package/lib/typescript/runLoop/uiRuntime/mockedRequestAnimationFrame.d.ts +6 -0
  250. package/lib/typescript/runLoop/uiRuntime/mockedRequestAnimationFrame.d.ts.map +1 -0
  251. package/lib/typescript/runLoop/uiRuntime/requestAnimationFrame.d.ts +2 -0
  252. package/lib/typescript/runLoop/uiRuntime/requestAnimationFrame.d.ts.map +1 -0
  253. package/lib/typescript/runLoop/uiRuntime/setTimeoutPolyfill.d.ts +2 -0
  254. package/lib/typescript/runLoop/uiRuntime/setTimeoutPolyfill.d.ts.map +1 -0
  255. package/lib/typescript/runLoop/workletRuntime/index.d.ts +2 -0
  256. package/lib/typescript/runLoop/workletRuntime/index.d.ts.map +1 -0
  257. package/lib/typescript/runLoop/workletRuntime/queueMicrotask.d.ts +2 -0
  258. package/lib/typescript/runLoop/workletRuntime/queueMicrotask.d.ts.map +1 -0
  259. package/lib/typescript/runLoop/workletRuntime/requestAnimationFramePolyfill.d.ts +2 -0
  260. package/lib/typescript/runLoop/workletRuntime/requestAnimationFramePolyfill.d.ts.map +1 -0
  261. package/lib/typescript/runLoop/workletRuntime/setTimeout.d.ts +2 -0
  262. package/lib/typescript/runLoop/workletRuntime/setTimeout.d.ts.map +1 -0
  263. package/lib/typescript/runLoop/workletRuntime/taskQueue.d.ts +10 -0
  264. package/lib/typescript/runLoop/workletRuntime/taskQueue.d.ts.map +1 -0
  265. package/lib/typescript/runtimeKind.d.ts +25 -0
  266. package/lib/typescript/runtimeKind.d.ts.map +1 -0
  267. package/lib/typescript/runtimes.d.ts +77 -0
  268. package/lib/typescript/runtimes.d.ts.map +1 -0
  269. package/lib/typescript/serializable.d.ts +20 -0
  270. package/lib/typescript/serializable.d.ts.map +1 -0
  271. package/lib/typescript/serializableMappingCache.d.ts +16 -0
  272. package/lib/typescript/serializableMappingCache.d.ts.map +1 -0
  273. package/lib/typescript/specs/NativeWorkletsModule.d.ts +7 -0
  274. package/lib/typescript/specs/NativeWorkletsModule.d.ts.map +1 -0
  275. package/lib/typescript/specs/NativeWorkletsModule.kepler.d.ts +7 -0
  276. package/lib/typescript/specs/NativeWorkletsModule.kepler.d.ts.map +1 -0
  277. package/lib/typescript/specs/index.d.ts +3 -0
  278. package/lib/typescript/specs/index.d.ts.map +1 -0
  279. package/lib/typescript/synchronizable.d.ts +15 -0
  280. package/lib/typescript/synchronizable.d.ts.map +1 -0
  281. package/lib/typescript/synchronizableUnpacker.d.ts +4 -0
  282. package/lib/typescript/synchronizableUnpacker.d.ts.map +1 -0
  283. package/lib/typescript/threads.d.ts +138 -0
  284. package/lib/typescript/threads.d.ts.map +1 -0
  285. package/lib/typescript/utils/checkCppVersion.d.ts +3 -0
  286. package/lib/typescript/utils/checkCppVersion.d.ts.map +1 -0
  287. package/lib/typescript/utils/jsVersion.d.ts +7 -0
  288. package/lib/typescript/utils/jsVersion.d.ts.map +1 -0
  289. package/lib/typescript/valueUnpacker.d.ts +6 -0
  290. package/lib/typescript/valueUnpacker.d.ts.map +1 -0
  291. package/lib/typescript/workletFunction.d.ts +27 -0
  292. package/lib/typescript/workletFunction.d.ts.map +1 -0
  293. package/lib/typescript/workletRuntimeEntry.d.ts +14 -0
  294. package/lib/typescript/workletRuntimeEntry.d.ts.map +1 -0
  295. package/lib/typescript/workletTypes.d.ts +61 -0
  296. package/lib/typescript/workletTypes.d.ts.map +1 -0
  297. package/package.json +153 -0
  298. package/plugin/index.js +1761 -0
  299. package/react-native.config.js +21 -0
  300. package/scripts/validate-react-native-version.js +43 -0
  301. package/scripts/worklets_utils.rb +94 -0
  302. package/src/PlatformChecker/PlatformChecker.ts +7 -0
  303. package/src/PlatformChecker/index.ts +30 -0
  304. package/src/WorkletsError.ts +36 -0
  305. package/src/WorkletsModule/JSWorklets.ts +200 -0
  306. package/src/WorkletsModule/NativeWorklets.ts +256 -0
  307. package/src/WorkletsModule/index.ts +7 -0
  308. package/src/WorkletsModule/workletsModuleInstance.ts +9 -0
  309. package/src/WorkletsModule/workletsModuleInstance.web.ts +5 -0
  310. package/src/WorkletsModule/workletsModuleProxy.ts +126 -0
  311. package/src/bundleUnpacker.ts +75 -0
  312. package/src/callGuard.ts +33 -0
  313. package/src/deprecated.ts +32 -0
  314. package/src/errors.ts +80 -0
  315. package/src/featureFlags/index.ts +72 -0
  316. package/src/featureFlags/staticFlags.json +4 -0
  317. package/src/index.ts +53 -0
  318. package/src/initializers.ts +262 -0
  319. package/src/isSynchronizable.ts +13 -0
  320. package/src/logger.ts +16 -0
  321. package/src/privateGlobals.d.ts +79 -0
  322. package/src/publicGlobals.ts +39 -0
  323. package/src/runLoop/common/setImmediatePolyfill.ts +20 -0
  324. package/src/runLoop/common/setIntervalPolyfill.ts +38 -0
  325. package/src/runLoop/uiRuntime/mockedRequestAnimationFrame.ts +11 -0
  326. package/src/runLoop/uiRuntime/requestAnimationFrame.ts +66 -0
  327. package/src/runLoop/uiRuntime/setTimeoutPolyfill.ts +40 -0
  328. package/src/runLoop/workletRuntime/index.ts +18 -0
  329. package/src/runLoop/workletRuntime/queueMicrotask.ts +13 -0
  330. package/src/runLoop/workletRuntime/requestAnimationFramePolyfill.ts +61 -0
  331. package/src/runLoop/workletRuntime/setTimeout.ts +37 -0
  332. package/src/runLoop/workletRuntime/taskQueue.ts +44 -0
  333. package/src/runtimeKind.ts +37 -0
  334. package/src/runtimes.ts +193 -0
  335. package/src/serializable.ts +801 -0
  336. package/src/serializableMappingCache.ts +42 -0
  337. package/src/specs/NativeWorkletsModule.kepler.ts +11 -0
  338. package/src/specs/NativeWorkletsModule.ts +9 -0
  339. package/src/specs/index.ts +13 -0
  340. package/src/synchronizable.ts +32 -0
  341. package/src/synchronizableUnpacker.ts +67 -0
  342. package/src/threads.ts +452 -0
  343. package/src/utils/checkCppVersion.ts +34 -0
  344. package/src/utils/jsVersion.ts +7 -0
  345. package/src/valueUnpacker.ts +90 -0
  346. package/src/workletFunction.ts +42 -0
  347. package/src/workletRuntimeEntry.ts +35 -0
  348. package/src/workletTypes.ts +81 -0
@@ -0,0 +1,10 @@
1
+ 'use strict';
2
+
3
+ import { RuntimeKind } from '../runtimeKind';
4
+ import RNWorkletsTurboModule from './NativeWorkletsModule';
5
+ export const WorkletsTurboModule = globalThis.__RUNTIME_KIND === RuntimeKind.ReactNative ? RNWorkletsTurboModule :
6
+ // In Bundle Mode, on Worklet Runtimes `RNWorkletsTurboModule` isn't
7
+ // available and shouldn't be accessed. We return null here
8
+ // to keep the same codebase for the Bundle Mode and legacy behavior.
9
+ null;
10
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["RuntimeKind","RNWorkletsTurboModule","WorkletsTurboModule","globalThis","__RUNTIME_KIND","ReactNative"],"sourceRoot":"../../../src","sources":["specs/index.ts"],"mappings":"AAAA,YAAY;;AAEZ,SAASA,WAAW,QAAQ,gBAAgB;AAE5C,OAAOC,qBAAqB,MAAM,wBAAwB;AAE1D,OAAO,MAAMC,mBAAgC,GAC3CC,UAAU,CAACC,cAAc,KAAKJ,WAAW,CAACK,WAAW,GACjDJ,qBAAqB;AACrB;AACA;AACA;AACA,IAAI","ignoreList":[]}
@@ -0,0 +1,9 @@
1
+ 'use strict';
2
+
3
+ import { createSerializable } from './serializable';
4
+ import { WorkletsModule } from './WorkletsModule';
5
+ export function createSynchronizable(initialValue) {
6
+ const synchronizableRef = WorkletsModule.createSynchronizable(createSerializable(initialValue));
7
+ return globalThis.__synchronizableUnpacker(synchronizableRef);
8
+ }
9
+ //# sourceMappingURL=synchronizable.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["createSerializable","WorkletsModule","createSynchronizable","initialValue","synchronizableRef","globalThis","__synchronizableUnpacker"],"sourceRoot":"../../src","sources":["synchronizable.ts"],"mappings":"AAAA,YAAY;;AAEZ,SAASA,kBAAkB,QAAQ,gBAAgB;AACnD,SAASC,cAAc,QAAQ,kBAAkB;AAGjD,OAAO,SAASC,oBAAoBA,CAClCC,YAAoB,EACI;EACxB,MAAMC,iBAAiB,GAAGH,cAAc,CAACC,oBAAoB,CAC3DF,kBAAkB,CAACG,YAAY,CACjC,CAAC;EAED,OAAOE,UAAU,CAACC,wBAAwB,CACxCF,iBACF,CAAC;AACH","ignoreList":[]}
@@ -0,0 +1,42 @@
1
+ 'use strict';
2
+
3
+ import { createSerializable } from './serializable';
4
+ export function __installUnpacker() {
5
+ // TODO: Add cache for synchronizables.
6
+ const serializer = !globalThis._WORKLET || globalThis._WORKLETS_BUNDLE_MODE ? (value, _) => createSerializable(value) : globalThis._createSerializable;
7
+ function synchronizableUnpacker(synchronizableRef) {
8
+ const synchronizable = synchronizableRef;
9
+ const proxy = globalThis.__workletsModuleProxy;
10
+ synchronizable.__synchronizableRef = true;
11
+ synchronizable.getDirty = () => {
12
+ return proxy.synchronizableGetDirty(synchronizable);
13
+ };
14
+ synchronizable.getBlocking = () => {
15
+ return proxy.synchronizableGetBlocking(synchronizable);
16
+ };
17
+ synchronizable.setBlocking = valueOrFunction => {
18
+ let newValue;
19
+ if (typeof valueOrFunction === 'function') {
20
+ const func = valueOrFunction;
21
+ synchronizable.lock();
22
+ const prev = synchronizable.getBlocking();
23
+ newValue = func(prev);
24
+ proxy.synchronizableSetBlocking(synchronizable, serializer(newValue, undefined));
25
+ synchronizable.unlock();
26
+ } else {
27
+ const value = valueOrFunction;
28
+ newValue = value;
29
+ proxy.synchronizableSetBlocking(synchronizable, serializer(newValue, undefined));
30
+ }
31
+ };
32
+ synchronizable.lock = () => {
33
+ proxy.synchronizableLock(synchronizable);
34
+ };
35
+ synchronizable.unlock = () => {
36
+ proxy.synchronizableUnlock(synchronizable);
37
+ };
38
+ return synchronizable;
39
+ }
40
+ globalThis.__synchronizableUnpacker = synchronizableUnpacker;
41
+ }
42
+ //# sourceMappingURL=synchronizableUnpacker.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["createSerializable","__installUnpacker","serializer","globalThis","_WORKLET","_WORKLETS_BUNDLE_MODE","value","_","_createSerializable","synchronizableUnpacker","synchronizableRef","synchronizable","proxy","__workletsModuleProxy","__synchronizableRef","getDirty","synchronizableGetDirty","getBlocking","synchronizableGetBlocking","setBlocking","valueOrFunction","newValue","func","lock","prev","synchronizableSetBlocking","undefined","unlock","synchronizableLock","synchronizableUnlock","__synchronizableUnpacker"],"sourceRoot":"../../src","sources":["synchronizableUnpacker.ts"],"mappings":"AAAA,YAAY;;AAEZ,SAASA,kBAAkB,QAAQ,gBAAgB;AAGnD,OAAO,SAASC,iBAAiBA,CAAA,EAAG;EAClC;EACA,MAAMC,UAAU,GACd,CAACC,UAAU,CAACC,QAAQ,IAAID,UAAU,CAACE,qBAAqB,GACpD,CAACC,KAAc,EAAEC,CAAU,KAAKP,kBAAkB,CAACM,KAAK,CAAC,GACzDH,UAAU,CAACK,mBAAmB;EAEpC,SAASC,sBAAsBA,CAC7BC,iBAA4C,EACpB;IACxB,MAAMC,cAAc,GAClBD,iBAAsD;IACxD,MAAME,KAAK,GAAGT,UAAU,CAACU,qBAAsB;IAE/CF,cAAc,CAACG,mBAAmB,GAAG,IAAI;IACzCH,cAAc,CAACI,QAAQ,GAAG,MAAM;MAC9B,OAAOH,KAAK,CAACI,sBAAsB,CAACL,cAAc,CAAC;IACrD,CAAC;IACDA,cAAc,CAACM,WAAW,GAAG,MAAM;MACjC,OAAOL,KAAK,CAACM,yBAAyB,CAACP,cAAc,CAAC;IACxD,CAAC;IACDA,cAAc,CAACQ,WAAW,GACxBC,eAAoD,IACjD;MACH,IAAIC,QAAgB;MACpB,IAAI,OAAOD,eAAe,KAAK,UAAU,EAAE;QACzC,MAAME,IAAI,GAAGF,eAA2C;QACxDT,cAAc,CAACY,IAAI,CAAC,CAAC;QACrB,MAAMC,IAAI,GAAGb,cAAc,CAACM,WAAW,CAAC,CAAC;QACzCI,QAAQ,GAAGC,IAAI,CAACE,IAAI,CAAC;QAErBZ,KAAK,CAACa,yBAAyB,CAC7Bd,cAAc,EACdT,UAAU,CAACmB,QAAQ,EAAEK,SAAS,CAChC,CAAC;QAEDf,cAAc,CAACgB,MAAM,CAAC,CAAC;MACzB,CAAC,MAAM;QACL,MAAMrB,KAAK,GAAGc,eAAe;QAC7BC,QAAQ,GAAGf,KAAK;QAChBM,KAAK,CAACa,yBAAyB,CAC7Bd,cAAc,EACdT,UAAU,CAACmB,QAAQ,EAAEK,SAAS,CAChC,CAAC;MACH;IACF,CAAC;IACDf,cAAc,CAACY,IAAI,GAAG,MAAM;MAC1BX,KAAK,CAACgB,kBAAkB,CAACjB,cAAc,CAAC;IAC1C,CAAC;IACDA,cAAc,CAACgB,MAAM,GAAG,MAAM;MAC5Bf,KAAK,CAACiB,oBAAoB,CAAClB,cAAc,CAAC;IAC5C,CAAC;IAED,OAAOA,cAAc;EACvB;EAEAR,UAAU,CAAC2B,wBAAwB,GAAGrB,sBAAsB;AAC9D","ignoreList":[]}
@@ -0,0 +1,347 @@
1
+ 'use strict';
2
+
3
+ import { IS_JEST, SHOULD_BE_USE_WEB } from './PlatformChecker';
4
+ import { RuntimeKind } from './runtimeKind';
5
+ import { createSerializable, makeShareableCloneOnUIRecursive } from './serializable';
6
+ import { serializableMappingCache } from './serializableMappingCache';
7
+ import { isWorkletFunction } from './workletFunction';
8
+ import { WorkletsError } from './WorkletsError';
9
+ import { WorkletsModule } from './WorkletsModule';
10
+ let runOnUIQueue = [];
11
+ export function setupMicrotasks() {
12
+ 'worklet';
13
+
14
+ let microtasksQueue = [];
15
+ let isExecutingMicrotasksQueue = false;
16
+ global.queueMicrotask = callback => {
17
+ microtasksQueue.push(callback);
18
+ };
19
+ global._microtaskQueueFinalizers = [];
20
+ global.__callMicrotasks = () => {
21
+ if (isExecutingMicrotasksQueue) {
22
+ return;
23
+ }
24
+ try {
25
+ isExecutingMicrotasksQueue = true;
26
+ for (let index = 0; index < microtasksQueue.length; index += 1) {
27
+ // we use classic 'for' loop because the size of the currentTasks array may change while executing some of the callbacks due to queueMicrotask calls
28
+ microtasksQueue[index]();
29
+ }
30
+ microtasksQueue = [];
31
+ global._microtaskQueueFinalizers.forEach(finalizer => finalizer());
32
+ } finally {
33
+ isExecutingMicrotasksQueue = false;
34
+ }
35
+ };
36
+ }
37
+ function callMicrotasksOnUIThread() {
38
+ 'worklet';
39
+
40
+ global.__callMicrotasks();
41
+ }
42
+ export const callMicrotasks = SHOULD_BE_USE_WEB ? () => {
43
+ // on web flushing is a noop as immediates are handled by the browser
44
+ } : callMicrotasksOnUIThread;
45
+
46
+ /**
47
+ * Lets you schedule a function to be executed on the [UI
48
+ * Runtime](https://docs.swmansion.com/react-native-worklets/docs/fundamentals/glossary#ui-runtime).
49
+ *
50
+ * - The callback executes asynchronously and doesn't return a value.
51
+ * - Passed function and args are automatically
52
+ * [workletized](https://docs.swmansion.com/react-native-worklets/docs/fundamentals/glossary#to-workletize)
53
+ * and serialized.
54
+ * - This function cannot be called from the [UI
55
+ * Runtime](https://docs.swmansion.com/react-native-worklets/docs/fundamentals/glossary#ui-runtime)
56
+ * or [Worker
57
+ * Runtime](https://docs.swmansion.com/react-native-worklets/docs/fundamentals/glossary#worker-worklet-runtime---worker-runtime),
58
+ * unless you have the [Bundle Mode](/docs/experimental/bundleMode) enabled.
59
+ *
60
+ * @param fun - A reference to a function you want to schedule on the [UI
61
+ * Runtime](https://docs.swmansion.com/react-native-worklets/docs/fundamentals/glossary#ui-runtime).
62
+ * @param args - Arguments to pass to the function.
63
+ * @see https://docs.swmansion.com/react-native-worklets/docs/threading/scheduleOnUI
64
+ */
65
+ export function scheduleOnUI(worklet, ...args) {
66
+ runOnUI(worklet)(...args);
67
+ }
68
+
69
+ /**
70
+ * Lets you asynchronously run
71
+ * [workletized](https://docs.swmansion.com/react-native-worklets/docs/fundamentals/glossary#to-workletize)
72
+ * functions on the [UI
73
+ * thread](https://docs.swmansion.com/react-native-worklets/docs/threading/runOnUI/).
74
+ *
75
+ * This method does not schedule the work immediately but instead waits for
76
+ * other worklets to be scheduled within the same JS loop. It uses
77
+ * queueMicrotask to schedule all the worklets at once making sure they will run
78
+ * within the same frame boundaries on the UI thread.
79
+ *
80
+ * @param fun - A reference to a function you want to execute on the [UI
81
+ * thread](https://docs.swmansion.com/react-native-worklets/docs/threading/runOnUI/)
82
+ * from the [JavaScript
83
+ * thread](https://docs.swmansion.com/react-native-worklets/docs/threading/runOnUI/).
84
+ * @returns A function that accepts arguments for the function passed as the
85
+ * first argument.
86
+ * @see https://docs.swmansion.com/react-native-worklets/docs/threading/runOnUI @deprecated Use `scheduleOnUI` instead.
87
+ */
88
+ // @ts-expect-error This overload is correct since it's what user sees in his code
89
+ // before it's transformed by Reanimated Babel plugin.
90
+
91
+ export function runOnUI(worklet) {
92
+ if (__DEV__ && !SHOULD_BE_USE_WEB && !isWorkletFunction(worklet) && !worklet.__bundleData) {
93
+ throw new WorkletsError('`runOnUI` can only be used with worklets.');
94
+ }
95
+ return (...args) => {
96
+ if (IS_JEST) {
97
+ // Mocking time in Jest is tricky as both requestAnimationFrame and queueMicrotask
98
+ // callbacks run on the same queue and can be interleaved. There is no way
99
+ // to flush particular queue in Jest and the only control over mocked timers
100
+ // is by using jest.advanceTimersByTime() method which advances all types
101
+ // of timers including immediate and animation callbacks. Ideally we'd like
102
+ // to have some way here to schedule work along with React updates, but
103
+ // that's not possible, and hence in Jest environment instead of using scheduling
104
+ // mechanism we just schedule the work ommiting the queue. This is ok for the
105
+ // uses that we currently have but may not be ok for future tests that we write.
106
+ WorkletsModule.scheduleOnUI(createSerializable(() => {
107
+ 'worklet';
108
+
109
+ worklet(...args);
110
+ }));
111
+ return;
112
+ }
113
+ if (__DEV__) {
114
+ // in DEV mode we call serializable conversion here because in case the object
115
+ // can't be converted, we will get a meaningful stack-trace as opposed to the
116
+ // situation when conversion is only done via microtask queue. This does not
117
+ // make the app particularily less efficient as converted objects are cached
118
+ // and for a given worklet the conversion only happens once.
119
+ createSerializable(worklet);
120
+ createSerializable(args);
121
+ }
122
+ enqueueUI(worklet, args);
123
+ };
124
+ }
125
+ if (__DEV__) {
126
+ function runOnUIWorklet() {
127
+ 'worklet';
128
+
129
+ throw new WorkletsError('`runOnUI` cannot be called on the UI runtime. Please call the function synchronously or use `queueMicrotask` or `requestAnimationFrame` instead.');
130
+ }
131
+ const serializableRunOnUIWorklet = createSerializable(runOnUIWorklet);
132
+ serializableMappingCache.set(runOnUI, serializableRunOnUIWorklet);
133
+ }
134
+
135
+ /**
136
+ * Lets you run a function synchronously on the [UI
137
+ * Runtime](https://docs.swmansion.com/react-native-worklets/docs/fundamentals/glossary#ui-runtime)
138
+ * from the [RN
139
+ * Runtime](https://docs.swmansion.com/react-native-worklets/docs/fundamentals/glossary#react-native-runtime-rn-runtime).
140
+ * Passed function and args are automatically
141
+ * [workletized](https://docs.swmansion.com/react-native-worklets/docs/fundamentals/glossary#to-workletize)
142
+ * and serialized.
143
+ *
144
+ * - This function cannot be called from the [UI
145
+ * Runtime](https://docs.swmansion.com/react-native-worklets/docs/fundamentals/glossary#ui-runtime).
146
+ * - This function cannot be called from a [Worker
147
+ * Runtime](https://docs.swmansion.com/react-native-worklets/docs/fundamentals/glossary#worker-worklet-runtime---worker-runtime).
148
+ *
149
+ * @param fun - A reference to a function you want to execute on the [UI
150
+ * Runtime](https://docs.swmansion.com/react-native-worklets/docs/fundamentals/glossary#ui-runtime).
151
+ * @param args - Arguments to pass to the function.
152
+ * @returns The return value of the function passed as the first argument.
153
+ * @see https://docs.swmansion.com/react-native-worklets/docs/threading/runOnUISync
154
+ */
155
+ export function runOnUISync(worklet, ...args) {
156
+ return executeOnUIRuntimeSync(worklet)(...args);
157
+ }
158
+
159
+ // @ts-expect-error Check `executeOnUIRuntimeSync` overload above.
160
+
161
+ export function executeOnUIRuntimeSync(worklet) {
162
+ return (...args) => {
163
+ return WorkletsModule.executeOnUIRuntimeSync(createSerializable(() => {
164
+ 'worklet';
165
+
166
+ const result = worklet(...args);
167
+ return makeShareableCloneOnUIRecursive(result);
168
+ }));
169
+ };
170
+ }
171
+ function runWorkletOnJS(worklet, ...args) {
172
+ // remote function that calls a worklet synchronously on the JS runtime
173
+ worklet(...args);
174
+ }
175
+
176
+ /**
177
+ * Lets you asynchronously run
178
+ * non-[workletized](https://docs.swmansion.com/react-native-worklets/docs/fundamentals/glossary#to-workletize)
179
+ * functions that couldn't otherwise run on the [UI
180
+ * thread](https://docs.swmansion.com/react-native-worklets/docs/fundamentals/glossary#ui-thread).
181
+ * This applies to most external libraries as they don't have their functions
182
+ * marked with "worklet"; directive.
183
+ *
184
+ * @param fun - A reference to a function you want to execute on the JavaScript
185
+ * thread from the UI thread.
186
+ * @returns A function that accepts arguments for the function passed as the
187
+ * first argument.
188
+ * @see https://docs.swmansion.com/react-native-worklets/docs/threading/runOnJS
189
+ */
190
+ /** @deprecated Use `scheduleOnRN` instead. */
191
+ export function runOnJS(fun) {
192
+ 'worklet';
193
+
194
+ if (SHOULD_BE_USE_WEB || globalThis.__RUNTIME_KIND === RuntimeKind.ReactNative) {
195
+ // if we are already on the JS thread, we just schedule the worklet on the JS queue
196
+ return (...args) => queueMicrotask(args.length ? () => fun(...args) : fun);
197
+ }
198
+ if (isWorkletFunction(fun)) {
199
+ // If `fun` is a worklet, we schedule a call of a remote function `runWorkletOnJS`
200
+ // and pass the worklet as a first argument followed by original arguments.
201
+
202
+ return (...args) => runOnJS(runWorkletOnJS)(fun, ...args);
203
+ }
204
+ if (fun.__remoteFunction) {
205
+ // In development mode the function provided as `fun` throws an error message
206
+ // such that when someone accidentally calls it directly on the UI runtime, they
207
+ // see that they should use `runOnJS` instead. To facilitate that we put the
208
+ // reference to the original remote function in the `__remoteFunction` property.
209
+ fun = fun.__remoteFunction;
210
+ }
211
+ const scheduleOnJS = typeof fun === 'function' ? global._scheduleHostFunctionOnJS : global._scheduleRemoteFunctionOnJS;
212
+ return (...args) => {
213
+ scheduleOnJS(fun, args.length > 0 ? makeShareableCloneOnUIRecursive(args) : undefined);
214
+ };
215
+ }
216
+
217
+ /**
218
+ * Lets you schedule a function to be executed on the RN runtime from any
219
+ * runtime. Check
220
+ * {@link https://docs.swmansion.com/react-native-worklets/docs/fundamentals/runtimeKinds}
221
+ * for more information about the different runtime kinds.
222
+ *
223
+ * Scheduling function from the RN Runtime (we are already on RN Runtime) simply
224
+ * uses `queueMicrotask`.
225
+ *
226
+ * When functions need to be scheduled from the UI Runtime, first function and
227
+ * args are serialized and then the system passes the scheduling responsibility
228
+ * to the JSScheduler. The JSScheduler then uses the RN CallInvoker to schedule
229
+ * the function asynchronously on the JavaScript thread by calling
230
+ * `jsCallInvoker_->invokeAsync()`.
231
+ *
232
+ * When called from a Worker Runtime, it uses the same JSScheduler mechanism.
233
+ *
234
+ * @param fun - A function you want to schedule on the RN runtime. A function
235
+ * can be a worklet, a remote function or a regular function.
236
+ * @param args - Arguments to pass to the function.
237
+ * @see https://docs.swmansion.com/react-native-worklets/docs/threading/scheduleOnRN
238
+ */
239
+ export function scheduleOnRN(fun, ...args) {
240
+ 'worklet';
241
+
242
+ runOnJS(fun)(...args);
243
+ }
244
+
245
+ /**
246
+ * Lets you asynchronously run
247
+ * [workletized](https://docs.swmansion.com/react-native-worklets/docs/fundamentals/glossary#to-workletize)
248
+ * functions on the [UI
249
+ * Runtime](https://docs.swmansion.com/react-native-worklets/docs/fundamentals/glossary#ui-runtime).
250
+ *
251
+ * This method does not schedule the work immediately but instead waits for
252
+ * other worklets to be scheduled within the same JS loop. It uses
253
+ * queueMicrotask to schedule all the worklets at once making sure they will run
254
+ * within the same frame boundaries on the UI thread.
255
+ *
256
+ * @param fun - A reference to a function you want to execute on the [UI
257
+ * Runtime](https://docs.swmansion.com/react-native-worklets/docs/fundamentals/glossary#ui-runtime).
258
+ * from the [JavaScript
259
+ * Runtime](https://docs.swmansion.com/react-native-worklets/docs/fundamentals/glossary#javascript-runtime).
260
+ * @returns A promise that resolves to the return value of the function passed
261
+ * as the first argument.
262
+ * @see https://docs.swmansion.com/react-native-worklets/docs/threading/runOnUIAsync
263
+ */
264
+ export function runOnUIAsync(worklet) {
265
+ if (__DEV__ && !SHOULD_BE_USE_WEB && !isWorkletFunction(worklet)) {
266
+ throw new WorkletsError('`runOnUIAsync` can only be used with worklets.');
267
+ }
268
+ return (...args) => {
269
+ return new Promise(resolve => {
270
+ if (IS_JEST) {
271
+ // Mocking time in Jest is tricky as both requestAnimationFrame and queueMicrotask
272
+ // callbacks run on the same queue and can be interleaved. There is no way
273
+ // to flush particular queue in Jest and the only control over mocked timers
274
+ // is by using jest.advanceTimersByTime() method which advances all types
275
+ // of timers including immediate and animation callbacks. Ideally we'd like
276
+ // to have some way here to schedule work along with React updates, but
277
+ // that's not possible, and hence in Jest environment instead of using scheduling
278
+ // mechanism we just schedule the work ommiting the queue. This is ok for the
279
+ // uses that we currently have but may not be ok for future tests that we write.
280
+ WorkletsModule.scheduleOnUI(createSerializable(() => {
281
+ 'worklet';
282
+
283
+ worklet(...args);
284
+ }));
285
+ return;
286
+ }
287
+ if (__DEV__) {
288
+ // in DEV mode we call serializable conversion here because in case the object
289
+ // can't be converted, we will get a meaningful stack-trace as opposed to the
290
+ // situation when conversion is only done via microtask queue. This does not
291
+ // make the app particularily less efficient as converted objects are cached
292
+ // and for a given worklet the conversion only happens once.
293
+ createSerializable(worklet);
294
+ createSerializable(args);
295
+ }
296
+ enqueueUI(worklet, args, resolve);
297
+ });
298
+ };
299
+ }
300
+ if (__DEV__) {
301
+ function runOnUIAsyncWorklet() {
302
+ 'worklet';
303
+
304
+ throw new WorkletsError('`runOnUIAsync` cannot be called on the UI runtime. Please call the function synchronously or use `queueMicrotask` or `requestAnimationFrame` instead.');
305
+ }
306
+ const serializableRunOnUIAsyncWorklet = createSerializable(runOnUIAsyncWorklet);
307
+ serializableMappingCache.set(runOnUIAsync, serializableRunOnUIAsyncWorklet);
308
+ }
309
+ function enqueueUI(worklet, args, resolve) {
310
+ const job = [worklet, args, resolve];
311
+ runOnUIQueue.push(job);
312
+ if (runOnUIQueue.length === 1) {
313
+ flushUIQueue();
314
+ }
315
+ }
316
+ function flushUIQueue() {
317
+ queueMicrotask(() => {
318
+ const queue = runOnUIQueue;
319
+ runOnUIQueue = [];
320
+ WorkletsModule.scheduleOnUI(createSerializable(() => {
321
+ 'worklet';
322
+
323
+ queue.forEach(([workletFunction, workletArgs, jobResolve]) => {
324
+ const result = workletFunction(...workletArgs);
325
+ if (jobResolve) {
326
+ runOnJS(jobResolve)(result);
327
+ }
328
+ });
329
+ callMicrotasks();
330
+ }));
331
+ });
332
+ }
333
+
334
+ /**
335
+ * Added temporarily for integration with `react-native-audio-api`. Don't depend
336
+ * on this API as it may change without notice.
337
+ */
338
+ // eslint-disable-next-line camelcase
339
+ export function unstable_eventLoopTask(worklet) {
340
+ return (...args) => {
341
+ 'worklet';
342
+
343
+ worklet(...args);
344
+ callMicrotasks();
345
+ };
346
+ }
347
+ //# sourceMappingURL=threads.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["IS_JEST","SHOULD_BE_USE_WEB","RuntimeKind","createSerializable","makeShareableCloneOnUIRecursive","serializableMappingCache","isWorkletFunction","WorkletsError","WorkletsModule","runOnUIQueue","setupMicrotasks","microtasksQueue","isExecutingMicrotasksQueue","global","queueMicrotask","callback","push","_microtaskQueueFinalizers","__callMicrotasks","index","length","forEach","finalizer","callMicrotasksOnUIThread","callMicrotasks","scheduleOnUI","worklet","args","runOnUI","__DEV__","__bundleData","enqueueUI","runOnUIWorklet","serializableRunOnUIWorklet","set","runOnUISync","executeOnUIRuntimeSync","result","runWorkletOnJS","runOnJS","fun","globalThis","__RUNTIME_KIND","ReactNative","__remoteFunction","scheduleOnJS","_scheduleHostFunctionOnJS","_scheduleRemoteFunctionOnJS","undefined","scheduleOnRN","runOnUIAsync","Promise","resolve","runOnUIAsyncWorklet","serializableRunOnUIAsyncWorklet","job","flushUIQueue","queue","workletFunction","workletArgs","jobResolve","unstable_eventLoopTask"],"sourceRoot":"../../src","sources":["threads.ts"],"mappings":"AAAA,YAAY;;AACZ,SAASA,OAAO,EAAEC,iBAAiB,QAAQ,mBAAmB;AAC9D,SAASC,WAAW,QAAQ,eAAe;AAC3C,SACEC,kBAAkB,EAClBC,+BAA+B,QAC1B,gBAAgB;AACvB,SAASC,wBAAwB,QAAQ,4BAA4B;AACrE,SAASC,iBAAiB,QAAQ,mBAAmB;AACrD,SAASC,aAAa,QAAQ,iBAAiB;AAC/C,SAASC,cAAc,QAAQ,kBAAkB;AASjD,IAAIC,YAAqB,GAAG,EAAE;AAE9B,OAAO,SAASC,eAAeA,CAAA,EAAG;EAChC,SAAS;;EAET,IAAIC,eAAkC,GAAG,EAAE;EAC3C,IAAIC,0BAA0B,GAAG,KAAK;EACtCC,MAAM,CAACC,cAAc,GAAIC,QAAoB,IAAK;IAChDJ,eAAe,CAACK,IAAI,CAACD,QAAQ,CAAC;EAChC,CAAC;EACDF,MAAM,CAACI,yBAAyB,GAAG,EAAE;EAErCJ,MAAM,CAACK,gBAAgB,GAAG,MAAM;IAC9B,IAAIN,0BAA0B,EAAE;MAC9B;IACF;IACA,IAAI;MACFA,0BAA0B,GAAG,IAAI;MACjC,KAAK,IAAIO,KAAK,GAAG,CAAC,EAAEA,KAAK,GAAGR,eAAe,CAACS,MAAM,EAAED,KAAK,IAAI,CAAC,EAAE;QAC9D;QACAR,eAAe,CAACQ,KAAK,CAAC,CAAC,CAAC;MAC1B;MACAR,eAAe,GAAG,EAAE;MACpBE,MAAM,CAACI,yBAAyB,CAACI,OAAO,CAAEC,SAAS,IAAKA,SAAS,CAAC,CAAC,CAAC;IACtE,CAAC,SAAS;MACRV,0BAA0B,GAAG,KAAK;IACpC;EACF,CAAC;AACH;AAEA,SAASW,wBAAwBA,CAAA,EAAG;EAClC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AM,CAAC;QAC7B;MACF,CAAC,CAAC;MACFb,cAAc,CAAC,CAAC;IAClB,CAAC,CACH,CAAC;EACH,CAAC,CAAC;AACJ;;AAEA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASqC,sBAAsBA,CACpCnC,OAAiC,EACjC;EACA,OAAO,CAAC,GAAGC,IAAW,KAAK;IACzB,SAAS;;IACTD,OAAO,CAAC,GAAGC,IAAI,CAAC;IAChBH,cAAc,CAAC,CAAC;EAClB,CAAC;AACH","ignoreList":[]}
@@ -0,0 +1,30 @@
1
+ 'use strict';
2
+
3
+ import { logger } from '../logger';
4
+ import { WorkletsError } from '../WorkletsError';
5
+ import { jsVersion } from './jsVersion';
6
+ export function checkCppVersion() {
7
+ const cppVersion = global._WORKLETS_VERSION_CPP;
8
+ if (cppVersion === undefined) {
9
+ logger.warn(`Couldn't determine the version of the native part of Worklets.
10
+ See \`https://docs.swmansion.com/react-native-worklets/docs/guides/troubleshooting#couldnt-determine-the-version-of-the-native-part-of-worklets\` for more details.`);
11
+ return;
12
+ }
13
+ const ok = matchVersion(jsVersion, cppVersion);
14
+ if (!ok) {
15
+ throw new WorkletsError(`Mismatch between JavaScript part and native part of Worklets (${jsVersion} vs ${cppVersion}).
16
+ See \`https://docs.swmansion.com/react-native-worklets/docs/guides/troubleshooting#mismatch-between-javascript-part-and-native-part-of-worklets\` for more details.`);
17
+ }
18
+ }
19
+ export function matchVersion(version1, version2) {
20
+ if (version1.match(/^\d+\.\d+\.\d+$/) && version2.match(/^\d+\.\d+\.\d+$/)) {
21
+ // x.y.z, compare only major and minor, skip patch
22
+ const [major1, minor1] = version1.split('.');
23
+ const [major2, minor2] = version2.split('.');
24
+ return major1 === major2 && minor1 === minor2;
25
+ } else {
26
+ // alpha, beta or rc, compare everything
27
+ return version1 === version2;
28
+ }
29
+ }
30
+ //# sourceMappingURL=checkCppVersion.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["logger","WorkletsError","jsVersion","checkCppVersion","cppVersion","global","_WORKLETS_VERSION_CPP","undefined","warn","ok","matchVersion","version1","version2","match","major1","minor1","split","major2","minor2"],"sourceRoot":"../../../src","sources":["utils/checkCppVersion.ts"],"mappings":"AAAA,YAAY;;AACZ,SAASA,MAAM,QAAQ,WAAW;AAClC,SAASC,aAAa,QAAQ,kBAAkB;AAChD,SAASC,SAAS,QAAQ,aAAa;AAEvC,OAAO,SAASC,eAAeA,CAAA,EAAG;EAChC,MAAMC,UAAU,GAAGC,MAAM,CAACC,qBAAqB;EAC/C,IAAIF,UAAU,KAAKG,SAAS,EAAE;IAC5BP,MAAM,CAACQ,IAAI,CACT;AACN,wKACI,CAAC;IACD;EACF;EACA,MAAMC,EAAE,GAAGC,YAAY,CAACR,SAAS,EAAEE,UAAU,CAAC;EAC9C,IAAI,CAACK,EAAE,EAAE;IACP,MAAM,IAAIR,aAAa,CACrB,iEAAiEC,SAAS,OAAOE,UAAU;AACjG,wKACI,CAAC;EACH;AACF;AAEA,OAAO,SAASM,YAAYA,CAACC,QAAgB,EAAEC,QAAgB,EAAE;EAC/D,IAAID,QAAQ,CAACE,KAAK,CAAC,iBAAiB,CAAC,IAAID,QAAQ,CAACC,KAAK,CAAC,iBAAiB,CAAC,EAAE;IAC1E;IACA,MAAM,CAACC,MAAM,EAAEC,MAAM,CAAC,GAAGJ,QAAQ,CAACK,KAAK,CAAC,GAAG,CAAC;IAC5C,MAAM,CAACC,MAAM,EAAEC,MAAM,CAAC,GAAGN,QAAQ,CAACI,KAAK,CAAC,GAAG,CAAC;IAC5C,OAAOF,MAAM,KAAKG,MAAM,IAAIF,MAAM,KAAKG,MAAM;EAC/C,CAAC,MAAM;IACL;IACA,OAAOP,QAAQ,KAAKC,QAAQ;EAC9B;AACF","ignoreList":[]}
@@ -0,0 +1,9 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * We hardcode the version of Worklets here in order to compare it with the
5
+ * version used to build the native part of the library in runtime. Remember to
6
+ * keep this in sync with the version declared in `package.json`
7
+ */
8
+ export const jsVersion = '1.0.0+0.6.0';
9
+ //# sourceMappingURL=jsVersion.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["jsVersion"],"sourceRoot":"../../../src","sources":["utils/jsVersion.ts"],"mappings":"AAAA,YAAY;;AACZ;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMA,SAAS,GAAG,aAAa","ignoreList":[]}
@@ -0,0 +1,60 @@
1
+ 'use strict';
2
+
3
+ function __installUnpacker() {
4
+ const workletsCache = new Map();
5
+ const handleCache = new WeakMap();
6
+ function valueUnpacker(objectToUnpack, category, remoteFunctionName) {
7
+ 'use strict';
8
+
9
+ const workletHash = objectToUnpack.__workletHash;
10
+ if (workletHash !== undefined) {
11
+ let workletFun = workletsCache.get(workletHash);
12
+ if (workletFun === undefined) {
13
+ const initData = objectToUnpack.__initData;
14
+ if (globalThis.evalWithSourceMap) {
15
+ // if the runtime (hermes only for now) supports loading source maps
16
+ // we want to use the proper filename for the location as it guarantees
17
+ // that debugger understands and loads the source code of the file where
18
+ // the worklet is defined.
19
+ workletFun = globalThis.evalWithSourceMap('(' + initData.code + '\n)', initData.location, initData.sourceMap);
20
+ } else if (globalThis.evalWithSourceUrl) {
21
+ // if the runtime doesn't support loading source maps, in dev mode we
22
+ // can pass source url when evaluating the worklet. Now, instead of using
23
+ // the actual file location we use worklet hash, as it the allows us to
24
+ // properly symbolicate traces (see errors.ts for details)
25
+ workletFun = globalThis.evalWithSourceUrl('(' + initData.code + '\n)', `worklet_${workletHash}`);
26
+ } else {
27
+ // in release we use the regular eval to save on JSI calls
28
+ // eslint-disable-next-line no-eval
29
+ workletFun = eval('(' + initData.code + '\n)');
30
+ }
31
+ workletsCache.set(workletHash, workletFun);
32
+ }
33
+ const functionInstance = workletFun.bind(objectToUnpack);
34
+ objectToUnpack._recur = functionInstance;
35
+ return functionInstance;
36
+ } else if (objectToUnpack.__init !== undefined) {
37
+ let value = handleCache.get(objectToUnpack);
38
+ if (value === undefined) {
39
+ value = objectToUnpack.__init();
40
+ handleCache.set(objectToUnpack, value);
41
+ }
42
+ return value;
43
+ } else if (category === 'RemoteFunction') {
44
+ const fun = () => {
45
+ const label = remoteFunctionName ? `function \`${remoteFunctionName}\`` : 'anonymous function';
46
+ // eslint-disable-next-line reanimated/use-worklets-error
47
+ throw new Error(`[Worklets] Tried to synchronously call a non-worklet ${label} on the UI thread.
48
+ See https://docs.swmansion.com/react-native-reanimated/docs/guides/troubleshooting#tried-to-synchronously-call-a-non-worklet-function-on-the-ui-thread for more details.`);
49
+ };
50
+ fun.__remoteFunction = objectToUnpack;
51
+ return fun;
52
+ } else {
53
+ // eslint-disable-next-line reanimated/use-worklets-error
54
+ throw new Error(`[Worklets] Data type in category "${category}" not recognized by value unpacker: "${globalThis._toString(objectToUnpack)}".`);
55
+ }
56
+ }
57
+ globalThis.__valueUnpacker = valueUnpacker;
58
+ }
59
+ export {};
60
+ //# sourceMappingURL=valueUnpacker.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["__installUnpacker","workletsCache","Map","handleCache","WeakMap","valueUnpacker","objectToUnpack","category","remoteFunctionName","workletHash","__workletHash","undefined","workletFun","get","initData","__initData","globalThis","evalWithSourceMap","code","location","sourceMap","evalWithSourceUrl","eval","set","functionInstance","bind","_recur","__init","value","fun","label","Error","__remoteFunction","_toString","__valueUnpacker"],"sourceRoot":"../../src","sources":["valueUnpacker.ts"],"mappings":"AAAA,YAAY;;AAYZ,SAASA,iBAAiBA,CAAA,EAAG;EAC3B,MAAMC,aAAa,GAAG,IAAIC,GAAG,CAAwB,CAAC;EACtD,MAAMC,WAAW,GAAG,IAAIC,OAAO,CAAkB,CAAC;EAElD,SAASC,aAAaA,CACpBC,cAA8B,EAC9BC,QAAiB,EACjBC,kBAA2B,EAClB;IACT,YAAY;;IACZ,MAAMC,WAAW,GAAGH,cAAc,CAACI,aAAa;IAChD,IAAID,WAAW,KAAKE,SAAS,EAAE;MAC7B,IAAIC,UAAU,GAAGX,aAAa,CAACY,GAAG,CAACJ,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QAChB,MAAMC,KAAK,GAAGtB,kBAAkB,GAC5B,cAAcA,kBAAkB,IAAI,GACpC,oBAAoB;QACxB;QACA,MAAM,IAAIuB,KAAK,CAAC,wDAAwDD,KAAK;AACrF,yKAAyK,CAAC;MACpK,CAAC;MACDD,GAAG,CAACG,gBAAgB,GAAG1B,cAAc;MACrC,OAAOuB,GAAG;IACZ,CAAC,MAAM;MACL;MACA,MAAM,IAAIE,KAAK,CACb,qCAAqCxB,QAAQ,wCAAwCS,UAAU,CAACiB,SAAS,CACvG3B,cACF,CAAC,IACH,CAAC;IACH;EACF;EAEAU,UAAU,CAACkB,eAAe,GAAG7B,aAA8B;AAC7D;AAAC","ignoreList":[]}
@@ -0,0 +1,37 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * This function allows you to determine if a given function is a worklet. It
5
+ * only works with Reanimated Babel plugin enabled. Unless you are doing
6
+ * something with internals of Reanimated you shouldn't need to use this
7
+ * function.
8
+ *
9
+ * ### Note
10
+ *
11
+ * Do not call it before the worklet is declared, as it will always return false
12
+ * then. E.g.:
13
+ *
14
+ * ```ts
15
+ * isWorkletFunction(myWorklet); // Will always return false.
16
+ *
17
+ * function myWorklet() {
18
+ * 'worklet';
19
+ * }
20
+ * ```
21
+ *
22
+ * ### Maintainer note
23
+ *
24
+ * This function is supposed to be used only in the React Runtime. It always
25
+ * returns `false` in Worklet Runtimes.
26
+ */
27
+ export function isWorkletFunction(value) {
28
+ 'worklet';
29
+
30
+ // Since host objects always return true for `in` operator, we have to use dot notation to check if the property exists.
31
+ // See https://github.com/facebook/hermes/blob/340726ef8cf666a7cce75bc60b02fa56b3e54560/lib/VM/JSObject.cpp#L1276.
32
+ return (
33
+ // `__workletHash` isn't extracted in Worklet Runtimes.
34
+ typeof value === 'function' && !!value.__workletHash
35
+ );
36
+ }
37
+ //# sourceMappingURL=workletFunction.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["isWorkletFunction","value","__workletHash"],"sourceRoot":"../../src","sources":["workletFunction.ts"],"mappings":"AAAA,YAAY;;AAIZ;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASA,iBAAiBA,CAG/BC,KAAc,EAA+C;EAC7D,SAAS;;EACT;EACA;EAEA;IACE;IACA,OAAOA,KAAK,KAAK,UAAU,IAC3B,CAAC,CAAEA,KAAK,CAAwCC;EAAa;AAEjE","ignoreList":[]}
@@ -0,0 +1,32 @@
1
+ 'use strict';
2
+
3
+ import { init } from './initializers';
4
+ import { SHOULD_BE_USE_WEB } from './PlatformChecker';
5
+ import { RuntimeKind } from './runtimeKind';
6
+ import { WorkletsError } from './WorkletsError';
7
+
8
+ /**
9
+ * This function is an entry point for Worklet Runtimes. We can use it to setup
10
+ * necessary tools, like the ValueUnpacker.
11
+ *
12
+ * We must throw an error at the end of this function to prevent the bundle to
13
+ * continue executing. This is because the next module to be ran would be the
14
+ * React Native one, and it would break the Worklet Runtime if initialized. The
15
+ * error is caught in C++ code.
16
+ *
17
+ * This function has no effect on the RN Runtime beside setting the
18
+ * `_WORKLETS_BUNDLE_MODE` flag.
19
+ */
20
+ export function bundleModeInit() {
21
+ globalThis._WORKLETS_BUNDLE_MODE = true;
22
+ if (!SHOULD_BE_USE_WEB && globalThis.__RUNTIME_KIND !== RuntimeKind.ReactNative) {
23
+ /**
24
+ * We shouldn't call `init()` on RN Runtime here, as it would initialize our
25
+ * module before React Native has configured the RN Runtime.
26
+ */
27
+ init();
28
+ throw new WorkletsError('Worklets initialized successfully');
29
+ }
30
+ }
31
+ bundleModeInit();
32
+ //# sourceMappingURL=workletRuntimeEntry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["init","SHOULD_BE_USE_WEB","RuntimeKind","WorkletsError","bundleModeInit","globalThis","_WORKLETS_BUNDLE_MODE","__RUNTIME_KIND","ReactNative"],"sourceRoot":"../../src","sources":["workletRuntimeEntry.ts"],"mappings":"AAAA,YAAY;;AAEZ,SAASA,IAAI,QAAQ,gBAAgB;AACrC,SAASC,iBAAiB,QAAQ,mBAAmB;AACrD,SAASC,WAAW,QAAQ,eAAe;AAC3C,SAASC,aAAa,QAAQ,iBAAiB;;AAE/C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,cAAcA,CAAA,EAAG;EAC/BC,UAAU,CAACC,qBAAqB,GAAG,IAAI;EACvC,IACE,CAACL,iBAAiB,IAClBI,UAAU,CAACE,cAAc,KAAKL,WAAW,CAACM,WAAW,EACrD;IACA;AACJ;AACA;AACA;IACIR,IAAI,CAAC,CAAC;IACN,MAAM,IAAIG,aAAa,CAAC,mCAAmC,CAAC;EAC9D;AACF;AAEAC,cAAc,CAAC,CAAC","ignoreList":[]}
@@ -0,0 +1,12 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * The below type is used for HostObjects returned by the JSI API that don't
5
+ * have any accessible fields or methods but can carry data that is accessed
6
+ * from the c++ side. We add a field to the type to make it possible for
7
+ * typescript to recognize which JSI methods accept those types as arguments and
8
+ * to be able to correctly type check other methods that may use them. However,
9
+ * this field is not actually defined nor should be used for anything else as
10
+ * assigning any data to those objects will throw an error.
11
+ */
12
+ //# sourceMappingURL=workletTypes.js.map