@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,262 @@
1
+ 'use strict';
2
+
3
+ import { bundleValueUnpacker } from './bundleUnpacker';
4
+ import { setupCallGuard } from './callGuard';
5
+ import { registerReportFatalRemoteError } from './errors';
6
+ import { IS_JEST, SHOULD_BE_USE_WEB } from './PlatformChecker';
7
+ import { setupSetImmediate } from './runLoop/common/setImmediatePolyfill';
8
+ import { setupSetInterval } from './runLoop/common/setIntervalPolyfill';
9
+ import { mockedRequestAnimationFrame } from './runLoop/uiRuntime/mockedRequestAnimationFrame';
10
+ import { setupRequestAnimationFrame } from './runLoop/uiRuntime/requestAnimationFrame';
11
+ import { setupSetTimeout } from './runLoop/uiRuntime/setTimeoutPolyfill';
12
+ import { RuntimeKind } from './runtimeKind';
13
+ import { __installUnpacker as installSynchronizableUnpacker } from './synchronizableUnpacker';
14
+ import { executeOnUIRuntimeSync, runOnJS, setupMicrotasks } from './threads';
15
+ import { isWorkletFunction } from './workletFunction';
16
+ import { registerWorkletsError, WorkletsError } from './WorkletsError';
17
+ import { WorkletsModule } from './WorkletsModule';
18
+ import type { ValueUnpacker } from './workletTypes';
19
+
20
+ let capturableConsole: typeof console;
21
+
22
+ /**
23
+ * Currently there seems to be a bug in the JSI layer which causes a crash when
24
+ * we try to copy some of the console methods, i.e. `clear` or `dirxml`.
25
+ *
26
+ * The crash happens only in React Native 0.75. It's not reproducible in neither
27
+ * 0.76 nor 0.74. It also happens only in the configuration of a debug app and
28
+ * production bundle.
29
+ *
30
+ * I haven't yet discovered what exactly causes the crash. It's tied to the
31
+ * console methods sometimes being `HostFunction`s. Therefore, as a workaround
32
+ * we don't copy the methods as they are in the original console object, we copy
33
+ * JavaScript wrappers instead.
34
+ */
35
+ export function getMemorySafeCapturableConsole(): typeof console {
36
+ if (capturableConsole) {
37
+ return capturableConsole;
38
+ }
39
+
40
+ const consoleCopy = Object.fromEntries(
41
+ Object.entries(console).map(([methodName, method]) => {
42
+ const methodWrapper = function methodWrapper(...args: unknown[]) {
43
+ return method(...args);
44
+ };
45
+ if (method.name) {
46
+ /**
47
+ * Set the original method name as the wrapper name if available.
48
+ *
49
+ * It might be unnecessary but if we want to fully mimic the console
50
+ * object we should take into the account the fact some code might rely
51
+ * on the method name.
52
+ */
53
+ Object.defineProperty(methodWrapper, 'name', {
54
+ value: method.name,
55
+ writable: false,
56
+ });
57
+ }
58
+ return [methodName, methodWrapper];
59
+ })
60
+ );
61
+
62
+ capturableConsole = consoleCopy as unknown as typeof console;
63
+
64
+ return consoleCopy as unknown as typeof console;
65
+ }
66
+
67
+ export function setupConsole(boundCapturableConsole: typeof console) {
68
+ 'worklet';
69
+ // @ts-ignore TypeScript doesn't like that there are missing methods in console object, but we don't provide all the methods for the UI runtime console version
70
+ globalThis.console = {
71
+ assert: runOnJS(boundCapturableConsole.assert),
72
+ debug: runOnJS(boundCapturableConsole.debug),
73
+ log: runOnJS(boundCapturableConsole.log),
74
+ warn: runOnJS(boundCapturableConsole.warn),
75
+ error: runOnJS(boundCapturableConsole.error),
76
+ info: runOnJS(boundCapturableConsole.info),
77
+ };
78
+ }
79
+
80
+ let initialized = false;
81
+
82
+ export function init() {
83
+ if (initialized) {
84
+ return;
85
+ }
86
+ initialized = true;
87
+
88
+ if (globalThis.__RUNTIME_KIND === undefined) {
89
+ // The only runtime that doesn't have `__RUNTIME_KIND` preconfigured
90
+ // is the RN Runtime. We must set it as soon as possible.
91
+ globalThis.__RUNTIME_KIND = RuntimeKind.ReactNative;
92
+ }
93
+
94
+ initializeRuntime();
95
+
96
+ if (SHOULD_BE_USE_WEB) {
97
+ initializeRuntimeOnWeb();
98
+ }
99
+
100
+ if (globalThis.__RUNTIME_KIND !== RuntimeKind.ReactNative) {
101
+ initializeWorkletRuntime();
102
+ } else {
103
+ initializeRNRuntime();
104
+ if (!SHOULD_BE_USE_WEB) {
105
+ installRNBindingsOnUIRuntime();
106
+ }
107
+ }
108
+ }
109
+
110
+ /** A function that should be run on any kind of runtime. */
111
+ function initializeRuntime() {
112
+ if (globalThis._WORKLETS_BUNDLE_MODE) {
113
+ globalThis.__valueUnpacker = bundleValueUnpacker as ValueUnpacker;
114
+ }
115
+ installSynchronizableUnpacker();
116
+ }
117
+
118
+ /** A function that should be run only on React Native runtime. */
119
+ function initializeRNRuntime() {
120
+ if (__DEV__) {
121
+ const testWorklet = () => {
122
+ 'worklet';
123
+ };
124
+ if (!isWorkletFunction(testWorklet)) {
125
+ throw new WorkletsError(
126
+ `Failed to create a worklet. See https://docs.swmansion.com/react-native-reanimated/docs/guides/troubleshooting#failed-to-create-a-worklet for more details.`
127
+ );
128
+ }
129
+ }
130
+
131
+ registerReportFatalRemoteError();
132
+ }
133
+
134
+ /** A function that should be run only on Worklet runtimes. */
135
+ function initializeWorkletRuntime() {
136
+ if (globalThis._WORKLETS_BUNDLE_MODE) {
137
+ setupCallGuard();
138
+
139
+ if (__DEV__) {
140
+ /*
141
+ * Temporary workaround for Metro bundler. We must implement a dummy
142
+ * Refresh module to prevent Metro from throwing irrelevant errors.
143
+ */
144
+ const Refresh = new Proxy(
145
+ {},
146
+ {
147
+ get() {
148
+ return () => {};
149
+ },
150
+ }
151
+ );
152
+
153
+ globalThis.__r.Refresh = Refresh;
154
+
155
+ /* Gracefully handle unwanted imports from React Native. */
156
+ // @ts-expect-error type not exposed by Metro
157
+ const modules = require.getModules();
158
+ // @ts-expect-error type not exposed by Metro
159
+ const ReactNativeModuleId = require.resolveWeak('react-native');
160
+
161
+ const factory = function (
162
+ _global: unknown,
163
+ _require: unknown,
164
+ _importDefault: unknown,
165
+ _importAll: unknown,
166
+ module: Record<string, unknown>,
167
+ _exports: unknown,
168
+ _dependencyMap: unknown
169
+ ) {
170
+ module.exports = new Proxy(
171
+ {},
172
+ {
173
+ get: function get(_target, prop) {
174
+ globalThis.console.warn(
175
+ `You tried to import '${String(prop)}' from 'react-native' module on a Worklet Runtime. Using 'react-native' module on a Worklet Runtime is not allowed.`
176
+ );
177
+ return {
178
+ get() {
179
+ return undefined;
180
+ },
181
+ };
182
+ },
183
+ }
184
+ );
185
+ };
186
+
187
+ const mod = {
188
+ dependencyMap: [],
189
+ factory,
190
+ hasError: false,
191
+ importedAll: {},
192
+ importedDefault: {},
193
+ isInitialized: false,
194
+ publicModule: {
195
+ exports: {},
196
+ },
197
+ };
198
+
199
+ modules.set(ReactNativeModuleId, mod);
200
+ }
201
+ }
202
+ }
203
+
204
+ /** A function that should be run only on RN Runtime in web implementation. */
205
+ function initializeRuntimeOnWeb() {
206
+ globalThis._WORKLET = false;
207
+ globalThis._log = console.log;
208
+ globalThis._getAnimationTimestamp = () => performance.now();
209
+ if (IS_JEST) {
210
+ // requestAnimationFrame react-native jest's setup is incorrect as it polyfills
211
+ // the method directly using setTimeout, therefore the callback doesn't get the
212
+ // expected timestamp as the only argument: https://github.com/facebook/react-native/blob/main/packages/react-native/jest/setup.js#L28
213
+ // We override this setup here to make sure that callbacks get the proper timestamps
214
+ // when executed. For non-jest environments we define requestAnimationFrame in setupRequestAnimationFrame
215
+ // @ts-ignore TypeScript uses Node definition for rAF, setTimeout, etc which returns a Timeout object rather than a number
216
+ globalThis.requestAnimationFrame = mockedRequestAnimationFrame;
217
+ }
218
+ }
219
+
220
+ /**
221
+ * A function that should be run on the RN Runtime to configure the UI Runtime
222
+ * with callback bindings.
223
+ */
224
+ function installRNBindingsOnUIRuntime() {
225
+ if (!WorkletsModule) {
226
+ throw new WorkletsError(
227
+ 'Worklets are trying to initialize the UI runtime without a valid WorkletsModule'
228
+ );
229
+ }
230
+
231
+ const runtimeBoundCapturableConsole = getMemorySafeCapturableConsole();
232
+
233
+ if (!globalThis._WORKLETS_BUNDLE_MODE) {
234
+ /** In bundle mode Runtimes setup their callGuard themselves. */
235
+ executeOnUIRuntimeSync(setupCallGuard)();
236
+
237
+ /**
238
+ * Register WorkletsError in the UI runtime global scope. (we are using
239
+ * `executeOnUIRuntimeSync` here to make sure that the changes are applied
240
+ * before any async operations are executed on the UI runtime).
241
+ *
242
+ * There's no need to register the error in bundle mode.
243
+ */
244
+ executeOnUIRuntimeSync(registerWorkletsError)();
245
+ }
246
+
247
+ executeOnUIRuntimeSync(() => {
248
+ 'worklet';
249
+
250
+ setupConsole(runtimeBoundCapturableConsole);
251
+ /**
252
+ * TODO: Move `setupMicrotasks` and `setupRequestAnimationFrame` to a
253
+ * separate function once we have a better way to distinguish between
254
+ * Worklet Runtimes.
255
+ */
256
+ setupMicrotasks();
257
+ setupRequestAnimationFrame();
258
+ setupSetTimeout();
259
+ setupSetImmediate();
260
+ setupSetInterval();
261
+ })();
262
+ }
@@ -0,0 +1,13 @@
1
+ 'use strict';
2
+ import type { Synchronizable } from './synchronizable';
3
+
4
+ export function isSynchronizable<TValue>(
5
+ value: unknown
6
+ ): value is Synchronizable<TValue> {
7
+ return (
8
+ typeof value === 'object' &&
9
+ value !== null &&
10
+ '__synchronizableRef' in value &&
11
+ value.__synchronizableRef === true
12
+ );
13
+ }
package/src/logger.ts ADDED
@@ -0,0 +1,16 @@
1
+ 'use strict';
2
+
3
+ const PREFIX = '[Worklets]';
4
+
5
+ function formatMessage(message: string) {
6
+ return `${PREFIX} ${message}`;
7
+ }
8
+
9
+ export const logger = {
10
+ warn(message: string) {
11
+ console.warn(formatMessage(message));
12
+ },
13
+ error(message: string) {
14
+ console.error(formatMessage(message));
15
+ },
16
+ };
@@ -0,0 +1,79 @@
1
+ /* eslint-disable reanimated/use-global-this */
2
+ 'use strict';
3
+
4
+ // This file works by accident - currently Builder Bob doesn't move `.d.ts` files to output types.
5
+ // If it ever breaks, we should address it so we'd not pollute the user's global namespace.
6
+ import type { callGuardDEV } from './callGuard';
7
+ import type { reportFatalRemoteError } from './errors';
8
+ import type { Queue } from './runLoop/workletRuntime/taskQueue';
9
+ import type { SynchronizableUnpacker } from './synchronizableUnpacker';
10
+ import type { IWorkletsErrorConstructor } from './WorkletsError';
11
+ import type { WorkletsModuleProxy } from './WorkletsModule';
12
+ import type { ValueUnpacker } from './workletTypes';
13
+
14
+ declare global {
15
+ /** The only runtime-available require method is `__r` defined by Metro. */
16
+ var __r: ((moduleId: number) => Record<string, unknown>) &
17
+ Record<string, unknown>;
18
+
19
+ var _toString: (value: unknown) => string;
20
+ var __workletsModuleProxy: WorkletsModuleProxy | undefined;
21
+ var _WORKLETS_BUNDLE_MODE: boolean | undefined;
22
+ var _WORKLETS_VERSION_CPP: string | undefined;
23
+ var _WORKLETS_VERSION_JS: string | undefined;
24
+ var _createSerializable: <T>(
25
+ value: T,
26
+ nativeStateSource?: object
27
+ ) => FlatSerializableRef<T>;
28
+ var _createSerializableString: (value: string) => FlatSerializableRef<string>;
29
+ var _createSerializableNumber: (value: number) => FlatSerializableRef<number>;
30
+ var _createSerializableBoolean: (
31
+ value: boolean
32
+ ) => FlatSerializableRef<boolean>;
33
+ var _createSerializableBigInt: (value: bigint) => FlatSerializableRef<bigint>;
34
+ var _createSerializableUndefined: () => FlatSerializableRef<undefined>;
35
+ var _createSerializableNull: () => FlatSerializableRef<null>;
36
+ var _createSerializableObject: <T extends object>(
37
+ value: T,
38
+ shouldRetainRemote: boolean,
39
+ nativeStateSource?: object
40
+ ) => FlatSerializableRef<T>;
41
+ var _createSerializableHostObject: <T extends object>(
42
+ value: T
43
+ ) => FlatSerializableRef<T>;
44
+ var _createSerializableWorklet: (
45
+ value: object,
46
+ shouldPersistRemote: boolean
47
+ ) => FlatSerializableRef<object>;
48
+ var _createSerializableArray: (
49
+ value: unknown[]
50
+ ) => FlatSerializableRef<unknown[]>;
51
+ var _createSerializableInitializer: (
52
+ value: object
53
+ ) => FlatSerializableRef<object>;
54
+ var _createSerializableSynchronizable: (
55
+ value: object
56
+ ) => FlatShareableRef<object>;
57
+ var __callMicrotasks: () => void;
58
+ var _scheduleHostFunctionOnJS: (fun: (...args: A) => R, args?: A) => void;
59
+ var _scheduleRemoteFunctionOnJS: (fun: (...args: A) => R, args?: A) => void;
60
+ /** Available only on RN Runtime */
61
+ var __reportFatalRemoteError: typeof reportFatalRemoteError | undefined;
62
+ var __valueUnpacker: ValueUnpacker;
63
+ var __synchronizableUnpacker: SynchronizableUnpacker;
64
+ var __callGuardDEV: typeof callGuardDEV | undefined;
65
+ var __flushAnimationFrame: (timestamp: number) => void;
66
+ var __frameTimestamp: number | undefined;
67
+ var _log: (value: unknown) => void;
68
+ var _getAnimationTimestamp: () => number;
69
+ var _scheduleOnRuntime: (
70
+ runtime: WorkletRuntime,
71
+ worklet: SerializableRef<() => void>
72
+ ) => void;
73
+ var _microtaskQueueFinalizers: (() => void)[];
74
+ var WorkletsError: IWorkletsErrorConstructor;
75
+ var _scheduleTimeoutCallback: (delay: number, handlerId: number) => void;
76
+ var __runTimeoutCallback: (handlerId: number) => void;
77
+ var __flushMicrotasks: () => void;
78
+ var _taskQueue: Queue;
79
+ }
@@ -0,0 +1,39 @@
1
+ 'use strict';
2
+ /* eslint-disable reanimated/use-global-this */
3
+ import type { RuntimeKind } from './runtimeKind';
4
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
5
+ import { getRuntimeKind } from './runtimeKind';
6
+
7
+ export {};
8
+
9
+ declare global {
10
+ /**
11
+ * @deprecated Use {@link __RUNTIME_KIND} instead.
12
+ *
13
+ * This global variable is a diagnostic/development tool.
14
+ *
15
+ * It's `true` on Worklet Runtimes and `false` on React Native Runtime.
16
+ */
17
+ var _WORKLET: boolean | undefined;
18
+
19
+ /**
20
+ * This ArrayBuffer contains the memory address of `jsi::Runtime` which is the
21
+ * Reanimated UI runtime.
22
+ */
23
+ var _WORKLET_RUNTIME: ArrayBuffer;
24
+
25
+ /** @deprecated Don't use. */
26
+ var _IS_FABRIC: boolean | undefined;
27
+
28
+ /**
29
+ * This global variable is used to determine the kind of the current runtime.
30
+ * You can use it directly to differentiate between runtimes. However, the
31
+ * recommended way for differentiating is to use the {@link getRuntimeKind}
32
+ * function.
33
+ *
34
+ * - Value _1_: React Native Runtime
35
+ * - Value _2_: UI Worklet Runtime
36
+ * - Value _3_: Worker Worklet Runtime
37
+ */
38
+ var __RUNTIME_KIND: RuntimeKind | 1 | 2 | 3;
39
+ }
@@ -0,0 +1,20 @@
1
+ 'use strict';
2
+
3
+ export function setupSetImmediate() {
4
+ 'worklet';
5
+
6
+ const setImmediatePolyfill = (
7
+ callback: (...args: unknown[]) => void,
8
+ ...args: unknown[]
9
+ ) => {
10
+ return setTimeout(callback, 0, ...args);
11
+ };
12
+
13
+ const clearImmediatePolyfill = (immediateHandle: number) => {
14
+ clearTimeout(immediateHandle);
15
+ };
16
+
17
+ globalThis.setImmediate =
18
+ setImmediatePolyfill as unknown as typeof setImmediate;
19
+ globalThis.clearImmediate = clearImmediatePolyfill as typeof clearImmediate;
20
+ }
@@ -0,0 +1,38 @@
1
+ 'use strict';
2
+
3
+ export function setupSetInterval() {
4
+ 'worklet';
5
+
6
+ const intervalHandleToTimeoutHandle: Map<number, number> = new Map();
7
+
8
+ const setIntervalPolyfill = (
9
+ callback: (...args: unknown[]) => void,
10
+ delay: number = 0,
11
+ ...args: unknown[]
12
+ ) => {
13
+ let intervalHandle = 0;
14
+
15
+ const repeatingCallback = () => {
16
+ const timeoutHandle = setTimeout(
17
+ repeatingCallback,
18
+ delay
19
+ ) as unknown as number;
20
+ intervalHandleToTimeoutHandle.set(intervalHandle, timeoutHandle);
21
+ callback(...args);
22
+ };
23
+
24
+ intervalHandle = setTimeout(repeatingCallback, delay) as unknown as number;
25
+ intervalHandleToTimeoutHandle.set(intervalHandle, intervalHandle);
26
+
27
+ return intervalHandle;
28
+ };
29
+
30
+ const clearIntervalPolyfill = (intervalHandle: number) => {
31
+ const timeoutHandle = intervalHandleToTimeoutHandle.get(intervalHandle);
32
+ clearTimeout(timeoutHandle);
33
+ intervalHandleToTimeoutHandle.delete(intervalHandle);
34
+ };
35
+
36
+ globalThis.setInterval = setIntervalPolyfill as typeof setInterval;
37
+ globalThis.clearInterval = clearIntervalPolyfill as typeof clearInterval;
38
+ }
@@ -0,0 +1,11 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * This is Jest implementation of `requestAnimationFrame` that is required by
5
+ * React Native for test purposes.
6
+ */
7
+ export function mockedRequestAnimationFrame(
8
+ callback: (timestamp: number) => void
9
+ ): ReturnType<typeof setTimeout> {
10
+ return setTimeout(() => callback(performance.now()), 0);
11
+ }
@@ -0,0 +1,66 @@
1
+ 'use strict';
2
+
3
+ import { callMicrotasks } from '../../threads';
4
+
5
+ export function setupRequestAnimationFrame() {
6
+ 'worklet';
7
+ const nativeRequestAnimationFrame = globalThis.requestAnimationFrame;
8
+
9
+ let queuedCallbacks: ((timestamp: number) => void)[] = [];
10
+ let queuedCallbacksBegin = 0;
11
+ let queuedCallbacksEnd = 0;
12
+
13
+ let flushedCallbacks = queuedCallbacks;
14
+ let flushedCallbacksBegin = 0;
15
+ let flushedCallbacksEnd = 0;
16
+
17
+ let flushRequested = false;
18
+
19
+ globalThis.__flushAnimationFrame = (timestamp: number) => {
20
+ flushedCallbacks = queuedCallbacks;
21
+ queuedCallbacks = [];
22
+
23
+ flushedCallbacksBegin = queuedCallbacksBegin;
24
+ flushedCallbacksEnd = queuedCallbacksEnd;
25
+ queuedCallbacksBegin = queuedCallbacksEnd;
26
+
27
+ for (const callback of flushedCallbacks) {
28
+ callback(timestamp);
29
+ }
30
+
31
+ flushedCallbacksBegin = flushedCallbacksEnd;
32
+
33
+ callMicrotasks();
34
+ };
35
+
36
+ globalThis.requestAnimationFrame = (
37
+ callback: (timestamp: number) => void
38
+ ): number => {
39
+ const handle = queuedCallbacksEnd++;
40
+
41
+ queuedCallbacks.push(callback);
42
+ if (!flushRequested) {
43
+ flushRequested = true;
44
+
45
+ nativeRequestAnimationFrame((timestamp) => {
46
+ flushRequested = false;
47
+ globalThis.__frameTimestamp = timestamp;
48
+ globalThis.__flushAnimationFrame(timestamp);
49
+ globalThis.__frameTimestamp = undefined;
50
+ });
51
+ }
52
+ return handle;
53
+ };
54
+
55
+ globalThis.cancelAnimationFrame = (handle: number) => {
56
+ if (handle < flushedCallbacksBegin || handle >= queuedCallbacksEnd) {
57
+ return;
58
+ }
59
+
60
+ if (handle < flushedCallbacksEnd) {
61
+ flushedCallbacks[handle - flushedCallbacksBegin] = () => {};
62
+ } else {
63
+ queuedCallbacks[handle - queuedCallbacksBegin] = () => {};
64
+ }
65
+ };
66
+ }
@@ -0,0 +1,40 @@
1
+ 'use strict';
2
+
3
+ export function setupSetTimeout() {
4
+ 'worklet';
5
+
6
+ const timeoutHandleToRafHandle: Map<number, number> = new Map();
7
+
8
+ const setTimeoutPolyfill = (
9
+ callback: (...args: unknown[]) => void,
10
+ delay: number = 0,
11
+ ...args: unknown[]
12
+ ) => {
13
+ const start = performance.now();
14
+ let timeoutHandle = 0;
15
+
16
+ const rafCallback = () => {
17
+ const now = performance.now();
18
+ if (now - start >= delay) {
19
+ callback(...args);
20
+ timeoutHandleToRafHandle.delete(timeoutHandle);
21
+ } else {
22
+ const rafHandle = requestAnimationFrame(rafCallback);
23
+ timeoutHandleToRafHandle.set(timeoutHandle, rafHandle);
24
+ }
25
+ };
26
+
27
+ timeoutHandle = requestAnimationFrame(rafCallback);
28
+ timeoutHandleToRafHandle.set(timeoutHandle, timeoutHandle);
29
+ return timeoutHandle;
30
+ };
31
+
32
+ const clearTimeoutPolyfill = (timeoutHandle: number) => {
33
+ const rafHandle = timeoutHandleToRafHandle.get(timeoutHandle);
34
+ timeoutHandleToRafHandle.delete(timeoutHandle);
35
+ cancelAnimationFrame(rafHandle!);
36
+ };
37
+
38
+ globalThis.setTimeout = setTimeoutPolyfill as typeof setTimeout;
39
+ globalThis.clearTimeout = clearTimeoutPolyfill as typeof clearTimeout;
40
+ }
@@ -0,0 +1,18 @@
1
+ 'use strict';
2
+
3
+ import { setupSetImmediate } from '../common/setImmediatePolyfill';
4
+ import { setupSetInterval } from '../common/setIntervalPolyfill';
5
+ import { setupQueueMicrotask } from './queueMicrotask';
6
+ import { setupRequestAnimationFrame } from './requestAnimationFramePolyfill';
7
+ import { setupSetTimeout } from './setTimeout';
8
+ import { setupTaskQueue } from './taskQueue';
9
+
10
+ export function setupRunLoop(animationQueuePollingRate: number) {
11
+ 'worklet';
12
+ setupTaskQueue();
13
+ setupQueueMicrotask();
14
+ setupSetTimeout();
15
+ setupRequestAnimationFrame(animationQueuePollingRate);
16
+ setupSetImmediate();
17
+ setupSetInterval();
18
+ }
@@ -0,0 +1,13 @@
1
+ 'use strict';
2
+
3
+ import { pushMicrotask } from './taskQueue';
4
+
5
+ export function setupQueueMicrotask() {
6
+ 'worklet';
7
+ globalThis.queueMicrotask = function (
8
+ callback: (...args: unknown[]) => void,
9
+ ...args: unknown[]
10
+ ) {
11
+ pushMicrotask(() => callback(...args));
12
+ } as typeof queueMicrotask;
13
+ }
@@ -0,0 +1,61 @@
1
+ 'use strict';
2
+
3
+ export function setupRequestAnimationFrame(animationQueuePollingRate: number) {
4
+ 'worklet';
5
+ const timeoutInterval = animationQueuePollingRate;
6
+
7
+ let queuedCallbacks: ((timestamp: number) => void)[] = [];
8
+ let queuedCallbacksBegin = 0;
9
+ let queuedCallbacksEnd = 0;
10
+
11
+ let flushedCallbacks = queuedCallbacks;
12
+ let flushedCallbacksBegin = 0;
13
+ let flushedCallbacksEnd = 0;
14
+
15
+ let flushRequested = false;
16
+
17
+ function flushAnimationFrame() {
18
+ flushRequested = false;
19
+ const timestamp = performance.now();
20
+
21
+ flushedCallbacks = queuedCallbacks;
22
+ queuedCallbacks = [];
23
+
24
+ flushedCallbacksBegin = queuedCallbacksBegin;
25
+ flushedCallbacksEnd = queuedCallbacksEnd;
26
+ queuedCallbacksBegin = queuedCallbacksEnd;
27
+
28
+ for (const callback of flushedCallbacks) {
29
+ callback(timestamp);
30
+ globalThis.__flushMicrotasks();
31
+ }
32
+
33
+ flushedCallbacksBegin = flushedCallbacksEnd;
34
+ }
35
+
36
+ globalThis.requestAnimationFrame = (
37
+ callback: (timestamp: number) => void
38
+ ): number => {
39
+ const handle = queuedCallbacksEnd++;
40
+
41
+ queuedCallbacks.push(callback);
42
+ if (!flushRequested) {
43
+ flushRequested = true;
44
+
45
+ setTimeout(flushAnimationFrame, timeoutInterval);
46
+ }
47
+ return handle;
48
+ };
49
+
50
+ globalThis.cancelAnimationFrame = (handle: number) => {
51
+ if (handle < flushedCallbacksBegin || handle >= queuedCallbacksEnd) {
52
+ return;
53
+ }
54
+
55
+ if (handle < flushedCallbacksEnd) {
56
+ flushedCallbacks[handle - flushedCallbacksBegin] = () => {};
57
+ } else {
58
+ queuedCallbacks[handle - queuedCallbacksBegin] = () => {};
59
+ }
60
+ };
61
+ }