@lynx-js/react 0.129.2 → 0.129.4

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 (420) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/components/tsconfig.tsbuildinfo +1 -1
  3. package/package.json +2 -2
  4. package/refresh/.turbo/turbo-build.log +3 -3
  5. package/refresh/dist/index.js +113 -20
  6. package/refresh/rslib.config.ts +13 -3
  7. package/refresh/src/index.ts +100 -0
  8. package/refresh/src/self.ts +38 -0
  9. package/runtime/__test__/{snapshot → core}/attribute-name.test.ts +1 -1
  10. package/runtime/__test__/core/background-function.test.ts +37 -0
  11. package/runtime/__test__/{shared → core}/component-stack.test.ts +4 -4
  12. package/runtime/__test__/core/ref.test.ts +218 -1
  13. package/runtime/__test__/core/sync-effect-flush.test.ts +58 -0
  14. package/runtime/__test__/element-template/debug/alog.test.ts +20 -12
  15. package/runtime/__test__/element-template/fixtures/background/hydrate/_shared.tsx +15 -34
  16. package/runtime/__test__/element-template/fixtures/background/hydrate/children.creates-missing-nodes-recursively/output.txt +2 -0
  17. package/runtime/__test__/element-template/fixtures/background/hydrate/children.iterates-existing-slots/output.txt +1 -0
  18. package/runtime/__test__/element-template/fixtures/background/hydrate/children.missing-attrs-element/output.txt +6 -1
  19. package/runtime/__test__/element-template/fixtures/background/hydrate/children.missing-slot-record-on-main/output.txt +1 -0
  20. package/runtime/__test__/element-template/fixtures/background/hydrate/{coverage.move-before-child → children.reconciles-raw-text-slots}/case.tsx +1 -1
  21. package/runtime/__test__/element-template/fixtures/background/hydrate/coverage.emit-create-raw-text/output.txt +1 -0
  22. package/runtime/__test__/element-template/fixtures/background/hydrate/coverage.emit-create-raw-text-non-text/output.txt +1 -0
  23. package/runtime/__test__/element-template/fixtures/background/hydrate/root-key-mismatch-reconciles/output.txt +1 -0
  24. package/runtime/__test__/element-template/fixtures/background/hydrate-compiled/children.creates-and-inserts-new/output.txt +1 -0
  25. package/runtime/__test__/element-template/fixtures/background/hydrate-compiled/children.inserts-before-existing-sibling/output.txt +1 -0
  26. package/runtime/__test__/element-template/fixtures/background/hydrate-compiled/children.mixed-operations/output.txt +1 -0
  27. package/runtime/__test__/element-template/fixtures/background/hydrate-compiled/children.non-string-raw-text-key-on-main/output.txt +1 -0
  28. package/runtime/__test__/element-template/fixtures/background/hydrate-compiled/complex-trees.deeply-nested-dynamic-content/output.txt +1 -0
  29. package/runtime/__test__/element-template/fixtures/background/instance/ops/emits-bundle-url-in-create-template/output.txt +1 -0
  30. package/runtime/__test__/element-template/fixtures/list/mts/index.tsx +185 -0
  31. package/runtime/__test__/element-template/fixtures/page/render-page/native-log.txt +1 -0
  32. package/runtime/__test__/element-template/fixtures/patch/detaches-node-when-moving-between-slots/case.tsx +2 -0
  33. package/runtime/__test__/element-template/fixtures/patch-compiled/applies-insert-before-with-reference/ops.txt +1 -0
  34. package/runtime/__test__/element-template/fixtures/patch-compiled/apply-hydration-ops/ops.txt +1 -0
  35. package/runtime/__test__/element-template/fixtures/render/child-siblings/papi.txt +10 -5
  36. package/runtime/__test__/element-template/fixtures/render/component/papi.txt +6 -3
  37. package/runtime/__test__/element-template/fixtures/render/component-slot-content/papi.txt +6 -3
  38. package/runtime/__test__/element-template/fixtures/render/css-scope-dynamic-bundle-url/papi.txt +2 -1
  39. package/runtime/__test__/element-template/fixtures/render/direct-native/appends-root-text-via-append-element/native-log.txt +1 -0
  40. package/runtime/__test__/element-template/fixtures/render/direct-native/creates-template-from-attrs-and-slot-text/native-log.txt +2 -0
  41. package/runtime/__test__/element-template/fixtures/render/direct-native/handles-multiple-template-children-in-the-same-slot/native-log.txt +3 -0
  42. package/runtime/__test__/element-template/fixtures/render/direct-native/handles-multiple-text-nodes-in-the-same-slot/native-log.txt +3 -0
  43. package/runtime/__test__/element-template/fixtures/render/direct-native/inserts-nested-templates-into-parent-slots/native-log.txt +3 -0
  44. package/runtime/__test__/element-template/fixtures/render/direct-native/keeps-slot-children-separated-and-ordered/native-log.txt +3 -0
  45. package/runtime/__test__/element-template/fixtures/render/direct-native/passes-bundle-url-to-native-create/native-log.txt +1 -0
  46. package/runtime/__test__/element-template/fixtures/render/mapped-view-children/papi.txt +14 -7
  47. package/runtime/__test__/element-template/fixtures/render/mixed-children/papi.txt +8 -4
  48. package/runtime/__test__/element-template/fixtures/render/multiple-text/papi.txt +38 -19
  49. package/runtime/__test__/element-template/fixtures/render/nested-templates/papi.txt +6 -3
  50. package/runtime/__test__/element-template/fixtures/render/react-example/papi.txt +6 -3
  51. package/runtime/__test__/element-template/fixtures/render/sparse-element-slot/papi.txt +6 -3
  52. package/runtime/__test__/element-template/fixtures/render/template-dedupe/papi.txt +10 -5
  53. package/runtime/__test__/element-template/lynx/performance.test.ts +1 -0
  54. package/runtime/__test__/element-template/native/callDestroyLifetimeFun.test.ts +1 -0
  55. package/runtime/__test__/element-template/native/mts-destroy.test.ts +10 -15
  56. package/runtime/__test__/element-template/native/reload.test.ts +4 -7
  57. package/runtime/__test__/element-template/runtime/background/adapter/background-adapter.et.test.tsx +0 -32
  58. package/runtime/__test__/element-template/runtime/background/commit-context.test.ts +0 -14
  59. package/runtime/__test__/element-template/runtime/background/commit-hook.test.ts +10 -0
  60. package/runtime/__test__/element-template/runtime/background/event/compiled-fixtures.test.tsx +22 -0
  61. package/runtime/__test__/element-template/runtime/background/hydrate.test.ts +197 -252
  62. package/runtime/__test__/element-template/runtime/background/instance.test.ts +277 -126
  63. package/runtime/__test__/element-template/runtime/background/passive-update-depth.test.tsx +496 -0
  64. package/runtime/__test__/element-template/runtime/background/render/preact.test.tsx +16 -22
  65. package/runtime/__test__/element-template/runtime/background/root-render.test.tsx +5 -3
  66. package/runtime/__test__/element-template/runtime/background/suspense.test.tsx +2 -0
  67. package/runtime/__test__/element-template/runtime/background/update/compiled-fixtures.test.tsx +1 -0
  68. package/runtime/__test__/element-template/runtime/background/update-timing.test.ts +1 -0
  69. package/runtime/__test__/element-template/runtime/hydration/hydration-listener.test.ts +3 -4
  70. package/runtime/__test__/element-template/runtime/list/list-mts-compiled.test.ts +525 -0
  71. package/runtime/__test__/element-template/runtime/page/compiled-fixtures.test.tsx +2 -0
  72. package/runtime/__test__/element-template/runtime/page/root-instance.test.ts +2 -14
  73. package/runtime/__test__/element-template/runtime/patch/element-template-patch.test.tsx +425 -1032
  74. package/runtime/__test__/element-template/runtime/patch/patch-listener-alog.test.ts +1 -0
  75. package/runtime/__test__/element-template/runtime/patch/update-timing.test.ts +1 -0
  76. package/runtime/__test__/element-template/runtime/prop-adapters/event.test.ts +0 -20
  77. package/runtime/__test__/element-template/runtime/prop-adapters/gesture.test.ts +2 -1
  78. package/runtime/__test__/element-template/runtime/prop-adapters/hydrate.test.ts +1 -0
  79. package/runtime/__test__/element-template/runtime/prop-adapters/ref.test.ts +65 -0
  80. package/runtime/__test__/element-template/runtime/prop-adapters/spread-mts-compiled.test.ts +12 -4
  81. package/runtime/__test__/element-template/runtime/render/render-components.test.jsx +2 -5
  82. package/runtime/__test__/element-template/runtime/render/render-direct-native.test.tsx +56 -121
  83. package/runtime/__test__/element-template/runtime/render/render-direct-suspense.test.ts +18 -17
  84. package/runtime/__test__/element-template/runtime/render/render-direct.test.ts +5 -4
  85. package/runtime/__test__/element-template/runtime/render/render-main-thread.contract.test.ts +2 -0
  86. package/runtime/__test__/element-template/runtime/render/render-main-thread.test.ts +1 -60
  87. package/runtime/__test__/element-template/runtime/render/render-transform.contract.test.ts +32 -89
  88. package/runtime/__test__/element-template/runtime/template/element-template-handle.test.ts +8 -6
  89. package/runtime/__test__/element-template/runtime/template/main-thread-dynamic-attr-state.test.ts +34 -6
  90. package/runtime/__test__/element-template/test-utils/debug/updateRunner.test.tsx +20 -12
  91. package/runtime/__test__/element-template/test-utils/debug/updateRunner.ts +2 -28
  92. package/runtime/__test__/element-template/test-utils/mock/mockNativePapi/templateTree.test.ts +14 -5
  93. package/runtime/__test__/element-template/test-utils/mock/mockNativePapi/templateTree.ts +1 -57
  94. package/runtime/__test__/element-template/test-utils/mock/mockNativePapi.ts +29 -13
  95. package/runtime/__test__/element-template/vitest.config.ts +1 -0
  96. package/runtime/__test__/guardrails/snapshot-containment.test.ts +98 -77
  97. package/runtime/__test__/snapshot/compat/export.test.jsx +8 -2
  98. package/runtime/__test__/snapshot/debug/passive-update-depth.test.jsx +549 -0
  99. package/runtime/__test__/snapshot/debug/react-hooks-profile.test.jsx +3 -3
  100. package/runtime/__test__/snapshot/lifecycle/reload-background-function.test.jsx +138 -1
  101. package/runtime/__test__/snapshot/lifecycle/reload-delayed-background.test.jsx +1 -1
  102. package/runtime/__test__/snapshot/lifecycle/transfer.mts.test.jsx +194 -0
  103. package/runtime/__test__/snapshot/lifecycle/transfer.test.jsx +210 -0
  104. package/runtime/__test__/snapshot/list.test.jsx +109 -0
  105. package/runtime/__test__/snapshot/lynxQueueMicrotask.test.jsx +2 -2
  106. package/runtime/__test__/snapshot/ref.test.jsx +124 -1
  107. package/runtime/__test__/snapshot/utils/envManager.ts +5 -0
  108. package/runtime/__test__/snapshot/utils/globals.js +1 -0
  109. package/runtime/__test__/worklet-runtime/delayWorkletEvent.test.js +22 -11
  110. package/runtime/__test__/worklet-runtime/hydrate.test.js +1 -0
  111. package/runtime/__test__/worklet-runtime/initEntry.test.js +12 -0
  112. package/runtime/__test__/worklet-runtime/jsFunctionLifecycle.test.js +24 -16
  113. package/runtime/__test__/worklet-runtime/runOnBackground.test.js +188 -0
  114. package/runtime/__test__/worklet-runtime/workletRef.test.js +16 -0
  115. package/runtime/__test__/worklet-runtime/workletRuntime.test.js +53 -1
  116. package/runtime/compat/index.d.ts +17 -1
  117. package/runtime/compat/index.js +3 -2
  118. package/runtime/lazy/compat.js +1 -0
  119. package/runtime/lazy/internal.js +1 -0
  120. package/runtime/lib/core/attribute-name.js.map +1 -0
  121. package/runtime/lib/core/background-function/run-on-background.js +7 -7
  122. package/runtime/lib/core/background-function/run-on-background.js.map +1 -1
  123. package/runtime/lib/{shared → core}/component-stack.js +1 -1
  124. package/runtime/lib/core/component-stack.js.map +1 -0
  125. package/runtime/lib/core/deep-equal.d.ts +1 -0
  126. package/runtime/lib/core/deep-equal.js +31 -0
  127. package/runtime/lib/core/deep-equal.js.map +1 -0
  128. package/runtime/lib/core/hooks/mainThreadImpl.js +1 -1
  129. package/runtime/lib/core/hooks/mainThreadImpl.js.map +1 -1
  130. package/runtime/lib/core/lynx-page-data.js +1 -1
  131. package/runtime/lib/core/lynx-page-data.js.map +1 -1
  132. package/runtime/lib/core/mts-capability.js +1 -1
  133. package/runtime/lib/core/mts-capability.js.map +1 -1
  134. package/runtime/lib/core/performance.js +2 -1
  135. package/runtime/lib/core/performance.js.map +1 -1
  136. package/runtime/lib/core/ref.d.ts +1 -2
  137. package/runtime/lib/core/ref.js +60 -9
  138. package/runtime/lib/core/ref.js.map +1 -1
  139. package/runtime/lib/core/sync-effect-flush.d.ts +9 -0
  140. package/runtime/lib/core/sync-effect-flush.js +31 -0
  141. package/runtime/lib/core/sync-effect-flush.js.map +1 -0
  142. package/runtime/lib/core/thread-function-call/main-thread.js +1 -1
  143. package/runtime/lib/core/thread-function-call/main-thread.js.map +1 -1
  144. package/runtime/lib/element-template/background/attr-slots.d.ts +1 -0
  145. package/runtime/lib/element-template/background/attr-slots.js.map +1 -1
  146. package/runtime/lib/element-template/background/commit-hook.js +1 -1
  147. package/runtime/lib/element-template/background/commit-hook.js.map +1 -1
  148. package/runtime/lib/element-template/background/destroy.js +1 -1
  149. package/runtime/lib/element-template/background/destroy.js.map +1 -1
  150. package/runtime/lib/element-template/background/hydrate.js +173 -85
  151. package/runtime/lib/element-template/background/hydrate.js.map +1 -1
  152. package/runtime/lib/element-template/background/instance.d.ts +7 -10
  153. package/runtime/lib/element-template/background/instance.js +65 -58
  154. package/runtime/lib/element-template/background/instance.js.map +1 -1
  155. package/runtime/lib/element-template/background/render-scope.js +2 -1
  156. package/runtime/lib/element-template/background/render-scope.js.map +1 -1
  157. package/runtime/lib/element-template/debug/alog.d.ts +1 -10
  158. package/runtime/lib/element-template/debug/alog.js +1 -16
  159. package/runtime/lib/element-template/debug/alog.js.map +1 -1
  160. package/runtime/lib/element-template/debug/profile.js +1 -1
  161. package/runtime/lib/element-template/debug/profile.js.map +1 -1
  162. package/runtime/lib/element-template/native/index.js +2 -2
  163. package/runtime/lib/element-template/native/index.js.map +1 -1
  164. package/runtime/lib/element-template/native/patch-listener.js +4 -8
  165. package/runtime/lib/element-template/native/patch-listener.js.map +1 -1
  166. package/runtime/lib/element-template/native/reload-main-thread.js +0 -4
  167. package/runtime/lib/element-template/native/reload-main-thread.js.map +1 -1
  168. package/runtime/lib/element-template/prop-adapters/ref.d.ts +2 -1
  169. package/runtime/lib/element-template/prop-adapters/ref.js +4 -4
  170. package/runtime/lib/element-template/prop-adapters/ref.js.map +1 -1
  171. package/runtime/lib/element-template/prop-adapters/spread.js +1 -1
  172. package/runtime/lib/element-template/prop-adapters/spread.js.map +1 -1
  173. package/runtime/lib/element-template/protocol/opcodes.d.ts +0 -2
  174. package/runtime/lib/element-template/protocol/opcodes.js +0 -2
  175. package/runtime/lib/element-template/protocol/opcodes.js.map +1 -1
  176. package/runtime/lib/element-template/protocol/types.d.ts +8 -30
  177. package/runtime/lib/element-template/protocol/types.js.map +1 -1
  178. package/runtime/lib/element-template/runtime/list/list.d.ts +14 -54
  179. package/runtime/lib/element-template/runtime/list/list.js +82 -546
  180. package/runtime/lib/element-template/runtime/list/list.js.map +1 -1
  181. package/runtime/lib/element-template/runtime/list/platform-info.d.ts +2 -0
  182. package/runtime/lib/element-template/runtime/list/platform-info.js +26 -0
  183. package/runtime/lib/element-template/runtime/list/platform-info.js.map +1 -0
  184. package/runtime/lib/element-template/runtime/patch.js +42 -119
  185. package/runtime/lib/element-template/runtime/patch.js.map +1 -1
  186. package/runtime/lib/element-template/runtime/render/create-rendered-host.d.ts +1 -1
  187. package/runtime/lib/element-template/runtime/render/create-rendered-host.js +24 -21
  188. package/runtime/lib/element-template/runtime/render/create-rendered-host.js.map +1 -1
  189. package/runtime/lib/element-template/runtime/render/render-components.d.ts +1 -1
  190. package/runtime/lib/element-template/runtime/render/render-components.js +3 -6
  191. package/runtime/lib/element-template/runtime/render/render-components.js.map +1 -1
  192. package/runtime/lib/element-template/runtime/render/render-direct.js +21 -20
  193. package/runtime/lib/element-template/runtime/render/render-direct.js.map +1 -1
  194. package/runtime/lib/element-template/runtime/render/render-main-thread.js +0 -13
  195. package/runtime/lib/element-template/runtime/render/render-main-thread.js.map +1 -1
  196. package/runtime/lib/element-template/runtime/template/attr-slot-plan.js +8 -0
  197. package/runtime/lib/element-template/runtime/template/attr-slot-plan.js.map +1 -1
  198. package/runtime/lib/element-template/runtime/template/handle.d.ts +3 -3
  199. package/runtime/lib/element-template/runtime/template/handle.js +2 -2
  200. package/runtime/lib/element-template/runtime/template/handle.js.map +1 -1
  201. package/runtime/lib/element-template/runtime/template/main-thread-background-function.js +1 -6
  202. package/runtime/lib/element-template/runtime/template/main-thread-background-function.js.map +1 -1
  203. package/runtime/lib/element-template/runtime/template/main-thread-dynamic-attr-state.d.ts +2 -1
  204. package/runtime/lib/element-template/runtime/template/main-thread-dynamic-attr-state.js +44 -28
  205. package/runtime/lib/element-template/runtime/template/main-thread-dynamic-attr-state.js.map +1 -1
  206. package/runtime/lib/element-template/runtime/template/typed-attributes.d.ts +2 -0
  207. package/runtime/lib/element-template/runtime/template/typed-attributes.js +8 -1
  208. package/runtime/lib/element-template/runtime/template/typed-attributes.js.map +1 -1
  209. package/runtime/lib/internal.d.ts +1 -0
  210. package/runtime/lib/internal.js +1 -0
  211. package/runtime/lib/internal.js.map +1 -1
  212. package/runtime/lib/lynx-api.js +6 -1
  213. package/runtime/lib/lynx-api.js.map +1 -1
  214. package/runtime/lib/lynx.js +4 -4
  215. package/runtime/lib/lynx.js.map +1 -1
  216. package/runtime/lib/root.d.ts +5 -1
  217. package/runtime/lib/root.js +12 -1
  218. package/runtime/lib/root.js.map +1 -1
  219. package/runtime/lib/shared/microtask.d.ts +1 -0
  220. package/runtime/lib/shared/microtask.js +28 -0
  221. package/runtime/lib/shared/microtask.js.map +1 -0
  222. package/runtime/lib/shared/utils.d.ts +8 -0
  223. package/runtime/lib/shared/utils.js +27 -0
  224. package/runtime/lib/shared/utils.js.map +1 -0
  225. package/runtime/lib/{worklet-runtime/utils → shared}/version.d.ts +1 -0
  226. package/runtime/lib/shared/version.js +15 -0
  227. package/runtime/lib/shared/version.js.map +1 -0
  228. package/runtime/lib/snapshot/alog/render.js +1 -1
  229. package/runtime/lib/snapshot/alog/render.js.map +1 -1
  230. package/runtime/lib/snapshot/debug/profileHooks.js +1 -1
  231. package/runtime/lib/snapshot/debug/profileHooks.js.map +1 -1
  232. package/runtime/lib/snapshot/lifecycle/destroy.js +2 -2
  233. package/runtime/lib/snapshot/lifecycle/destroy.js.map +1 -1
  234. package/runtime/lib/snapshot/lifecycle/isRendering.js +2 -1
  235. package/runtime/lib/snapshot/lifecycle/isRendering.js.map +1 -1
  236. package/runtime/lib/snapshot/lifecycle/patch/commit.d.ts +7 -2
  237. package/runtime/lib/snapshot/lifecycle/patch/commit.js +11 -6
  238. package/runtime/lib/snapshot/lifecycle/patch/commit.js.map +1 -1
  239. package/runtime/lib/snapshot/lifecycle/patch/updateMainThread.d.ts +5 -0
  240. package/runtime/lib/snapshot/lifecycle/patch/updateMainThread.js +1 -1
  241. package/runtime/lib/snapshot/lifecycle/patch/updateMainThread.js.map +1 -1
  242. package/runtime/lib/snapshot/lifecycle/ref/delay.d.ts +1 -1
  243. package/runtime/lib/snapshot/lifecycle/ref/delay.js +2 -2
  244. package/runtime/lib/snapshot/lifecycle/ref/delay.js.map +1 -1
  245. package/runtime/lib/snapshot/lifecycle/reload.js +1 -1
  246. package/runtime/lib/snapshot/lifecycle/reload.js.map +1 -1
  247. package/runtime/lib/snapshot/list/list.js +12 -3
  248. package/runtime/lib/snapshot/list/list.js.map +1 -1
  249. package/runtime/lib/snapshot/lynx/tt.d.ts +3 -1
  250. package/runtime/lib/snapshot/lynx/tt.js +7 -3
  251. package/runtime/lib/snapshot/lynx/tt.js.map +1 -1
  252. package/runtime/lib/snapshot/renderToOpcodes/hydrate.js +1 -1
  253. package/runtime/lib/snapshot/renderToOpcodes/hydrate.js.map +1 -1
  254. package/runtime/lib/snapshot/snapshot/backgroundSnapshot.js +1 -1
  255. package/runtime/lib/snapshot/snapshot/backgroundSnapshot.js.map +1 -1
  256. package/runtime/lib/snapshot/snapshot/platformInfo.js +1 -1
  257. package/runtime/lib/snapshot/snapshot/platformInfo.js.map +1 -1
  258. package/runtime/lib/snapshot/snapshot/ref.d.ts +1 -0
  259. package/runtime/lib/snapshot/snapshot/ref.js +2 -2
  260. package/runtime/lib/snapshot/snapshot/ref.js.map +1 -1
  261. package/runtime/lib/snapshot/snapshot/snapshot.js +1 -1
  262. package/runtime/lib/snapshot/snapshot/snapshot.js.map +1 -1
  263. package/runtime/lib/snapshot/snapshot/spread.js +3 -2
  264. package/runtime/lib/snapshot/snapshot/spread.js.map +1 -1
  265. package/runtime/lib/snapshot/transfer.d.ts +15 -0
  266. package/runtime/lib/snapshot/transfer.js +343 -0
  267. package/runtime/lib/snapshot/transfer.js.map +1 -0
  268. package/runtime/lib/snapshot/worklet/functionality.js +1 -1
  269. package/runtime/lib/snapshot/worklet/functionality.js.map +1 -1
  270. package/runtime/lib/tsconfig.tsbuildinfo +1 -1
  271. package/runtime/lib/worklet-runtime/api/element.js +1 -1
  272. package/runtime/lib/worklet-runtime/api/element.js.map +1 -1
  273. package/runtime/lib/worklet-runtime/api/lynxApi.js +1 -1
  274. package/runtime/lib/worklet-runtime/api/lynxApi.js.map +1 -1
  275. package/runtime/lib/worklet-runtime/bindings/bindings.d.ts +3 -2
  276. package/runtime/lib/worklet-runtime/bindings/bindings.js +11 -1
  277. package/runtime/lib/worklet-runtime/bindings/bindings.js.map +1 -1
  278. package/runtime/lib/worklet-runtime/bindings/observers.js +9 -1
  279. package/runtime/lib/worklet-runtime/bindings/observers.js.map +1 -1
  280. package/runtime/lib/worklet-runtime/bindings/types.d.ts +1 -0
  281. package/runtime/lib/worklet-runtime/bindings/types.js.map +1 -1
  282. package/runtime/lib/worklet-runtime/delayWorkletEvent.d.ts +2 -4
  283. package/runtime/lib/worklet-runtime/delayWorkletEvent.js +42 -44
  284. package/runtime/lib/worklet-runtime/delayWorkletEvent.js.map +1 -1
  285. package/runtime/lib/worklet-runtime/global.d.ts +1 -2
  286. package/runtime/lib/worklet-runtime/global.js.map +1 -1
  287. package/runtime/lib/worklet-runtime/hydrate.js +2 -32
  288. package/runtime/lib/worklet-runtime/hydrate.js.map +1 -1
  289. package/runtime/lib/worklet-runtime/run-on-background/index.d.ts +28 -0
  290. package/runtime/lib/worklet-runtime/run-on-background/index.js +103 -0
  291. package/runtime/lib/worklet-runtime/run-on-background/index.js.map +1 -0
  292. package/runtime/lib/worklet-runtime/{jsFunctionLifecycle.d.ts → run-on-background/lifecycle.d.ts} +2 -2
  293. package/runtime/lib/worklet-runtime/{jsFunctionLifecycle.js → run-on-background/lifecycle.js} +12 -9
  294. package/runtime/lib/worklet-runtime/run-on-background/lifecycle.js.map +1 -0
  295. package/runtime/lib/worklet-runtime/workletRef.js +51 -54
  296. package/runtime/lib/worklet-runtime/workletRef.js.map +1 -1
  297. package/runtime/lib/worklet-runtime/workletRuntime.js +5 -6
  298. package/runtime/lib/worklet-runtime/workletRuntime.js.map +1 -1
  299. package/runtime/src/core/background-function/run-on-background.ts +7 -7
  300. package/runtime/src/{shared → core}/component-stack.ts +1 -1
  301. package/runtime/src/core/deep-equal.ts +33 -0
  302. package/runtime/src/core/hooks/mainThreadImpl.ts +1 -1
  303. package/runtime/src/core/lynx-page-data.ts +1 -1
  304. package/runtime/src/core/mts-capability.ts +1 -1
  305. package/runtime/src/core/performance.ts +2 -1
  306. package/runtime/src/core/ref.ts +92 -15
  307. package/runtime/src/core/sync-effect-flush.ts +30 -0
  308. package/runtime/src/core/thread-function-call/main-thread.ts +1 -1
  309. package/runtime/src/element-template/background/attr-slots.ts +2 -2
  310. package/runtime/src/element-template/background/commit-hook.ts +1 -1
  311. package/runtime/src/element-template/background/destroy.ts +1 -1
  312. package/runtime/src/element-template/background/hydrate.ts +229 -119
  313. package/runtime/src/element-template/background/instance.ts +82 -82
  314. package/runtime/src/element-template/background/render-scope.ts +2 -1
  315. package/runtime/src/element-template/debug/alog.ts +2 -30
  316. package/runtime/src/element-template/debug/profile.ts +1 -1
  317. package/runtime/src/element-template/native/index.ts +2 -2
  318. package/runtime/src/element-template/native/patch-listener.ts +6 -7
  319. package/runtime/src/element-template/native/reload-main-thread.ts +0 -4
  320. package/runtime/src/element-template/prop-adapters/ref.ts +12 -5
  321. package/runtime/src/element-template/prop-adapters/spread.ts +1 -1
  322. package/runtime/src/element-template/protocol/opcodes.ts +0 -2
  323. package/runtime/src/element-template/protocol/types.ts +10 -38
  324. package/runtime/src/element-template/runtime/list/list.ts +115 -744
  325. package/runtime/src/element-template/runtime/list/platform-info.ts +31 -0
  326. package/runtime/src/element-template/runtime/patch.ts +59 -163
  327. package/runtime/src/element-template/runtime/render/create-rendered-host.ts +27 -31
  328. package/runtime/src/element-template/runtime/render/render-components.ts +2 -5
  329. package/runtime/src/element-template/runtime/render/render-direct.ts +19 -18
  330. package/runtime/src/element-template/runtime/render/render-main-thread.ts +0 -14
  331. package/runtime/src/element-template/runtime/template/attr-slot-plan.ts +9 -0
  332. package/runtime/src/element-template/runtime/template/handle.ts +3 -2
  333. package/runtime/src/element-template/runtime/template/main-thread-background-function.ts +1 -6
  334. package/runtime/src/element-template/runtime/template/main-thread-dynamic-attr-state.ts +44 -30
  335. package/runtime/src/element-template/runtime/template/typed-attributes.ts +17 -1
  336. package/runtime/src/element-template/types.d.ts +6 -22
  337. package/runtime/src/internal.ts +2 -0
  338. package/runtime/src/lynx-api.ts +6 -1
  339. package/runtime/src/lynx.ts +4 -4
  340. package/runtime/src/root.ts +17 -1
  341. package/runtime/src/shared/microtask.ts +26 -0
  342. package/runtime/src/shared/utils.ts +37 -0
  343. package/runtime/src/shared/version.ts +16 -0
  344. package/runtime/src/snapshot/alog/render.ts +1 -1
  345. package/runtime/src/snapshot/debug/profileHooks.ts +1 -1
  346. package/runtime/src/snapshot/lifecycle/destroy.ts +2 -2
  347. package/runtime/src/snapshot/lifecycle/isRendering.ts +2 -1
  348. package/runtime/src/snapshot/lifecycle/patch/commit.ts +28 -7
  349. package/runtime/src/snapshot/lifecycle/patch/updateMainThread.ts +1 -1
  350. package/runtime/src/snapshot/lifecycle/ref/delay.ts +5 -2
  351. package/runtime/src/snapshot/lifecycle/reload.ts +1 -1
  352. package/runtime/src/snapshot/list/list.ts +12 -3
  353. package/runtime/src/snapshot/lynx/tt.ts +8 -3
  354. package/runtime/src/snapshot/renderToOpcodes/hydrate.ts +1 -1
  355. package/runtime/src/snapshot/snapshot/backgroundSnapshot.ts +1 -1
  356. package/runtime/src/snapshot/snapshot/platformInfo.ts +1 -1
  357. package/runtime/src/snapshot/snapshot/ref.ts +7 -4
  358. package/runtime/src/snapshot/snapshot/snapshot.ts +1 -1
  359. package/runtime/src/snapshot/snapshot/spread.ts +3 -2
  360. package/runtime/src/snapshot/transfer.ts +379 -0
  361. package/runtime/src/snapshot/worklet/functionality.ts +1 -1
  362. package/runtime/src/worklet-runtime/api/element.ts +1 -1
  363. package/runtime/src/worklet-runtime/api/lynxApi.ts +1 -1
  364. package/runtime/src/worklet-runtime/bindings/bindings.ts +12 -0
  365. package/runtime/src/worklet-runtime/bindings/observers.ts +9 -1
  366. package/runtime/src/worklet-runtime/bindings/types.ts +1 -0
  367. package/runtime/src/worklet-runtime/delayWorkletEvent.ts +49 -54
  368. package/runtime/src/worklet-runtime/global.ts +1 -2
  369. package/runtime/src/worklet-runtime/hydrate.ts +2 -35
  370. package/runtime/src/worklet-runtime/run-on-background/index.ts +145 -0
  371. package/runtime/src/worklet-runtime/{jsFunctionLifecycle.ts → run-on-background/lifecycle.ts} +11 -9
  372. package/runtime/src/worklet-runtime/workletRef.ts +63 -62
  373. package/runtime/src/worklet-runtime/workletRuntime.ts +10 -10
  374. package/testing-library/.turbo/turbo-build.log +10 -10
  375. package/testing-library/dist/pure.js +7 -4
  376. package/testing-library/dist/setupFiles/common/runtime-setup.js +3 -1
  377. package/testing-library/dist/setupFiles/inner/rstest.js +1 -1
  378. package/testing-library/dist/setupFiles/inner/vitest.js +1 -1
  379. package/testing-library/src/__tests__/list.test.jsx +52 -0
  380. package/testing-library/src/__tests__/worklet.test.jsx +81 -0
  381. package/testing-library/src/pure.jsx +5 -2
  382. package/testing-library/src/setupFiles/common/runtime-setup.js +2 -0
  383. package/transform/.turbo/turbo-build$colon$wasm.log +88 -201
  384. package/transform/crates/swc_plugin_element_template/tests/element_template.rs +19 -45
  385. package/transform/crates/swc_plugin_element_template/tests/element_template_contract.rs +0 -19
  386. package/transform/rspack-napi/tsconfig.tsbuildinfo +1 -1
  387. package/transform/swc-plugin-reactlynx/.turbo/turbo-build.log +129 -156
  388. package/transform/swc-plugin-reactlynx-compat/.turbo/turbo-build.log +282 -149
  389. package/runtime/__test__/element-template/fixtures/background/hydrate/coverage.move-before-child/output.txt +0 -10
  390. package/runtime/__test__/element-template/fixtures/background/hydrate/coverage.raw-text-key-branches/case.tsx +0 -5
  391. package/runtime/__test__/element-template/fixtures/background/instance/ops/supports-silent-insert-before/case.ts +0 -11
  392. package/runtime/__test__/element-template/fixtures/background/instance/ops/supports-silent-insert-before/output.txt +0 -1
  393. package/runtime/__test__/element-template/fixtures/background/instance/ops/treats-nullish-attrs-as-empty-object/case.ts +0 -23
  394. package/runtime/__test__/element-template/fixtures/background/instance/ops/treats-nullish-attrs-as-empty-object/output.txt +0 -6
  395. package/runtime/__test__/element-template/runtime/page/authored-page.test.ts +0 -35
  396. package/runtime/__test__/element-template/runtime/patch/update-fixture-helper.test.tsx +0 -40
  397. package/runtime/__test__/snapshot/lynx-data-processors.test.ts +0 -3
  398. package/runtime/lib/shared/attribute-name.js.map +0 -1
  399. package/runtime/lib/shared/component-stack.js.map +0 -1
  400. package/runtime/lib/snapshot/alog/index.d.ts +0 -1
  401. package/runtime/lib/snapshot/alog/index.js +0 -8
  402. package/runtime/lib/snapshot/alog/index.js.map +0 -1
  403. package/runtime/lib/utils.d.ts +0 -19
  404. package/runtime/lib/utils.js +0 -119
  405. package/runtime/lib/utils.js.map +0 -1
  406. package/runtime/lib/worklet-runtime/delayRunOnBackground.d.ts +0 -13
  407. package/runtime/lib/worklet-runtime/delayRunOnBackground.js +0 -29
  408. package/runtime/lib/worklet-runtime/delayRunOnBackground.js.map +0 -1
  409. package/runtime/lib/worklet-runtime/jsFunctionLifecycle.js.map +0 -1
  410. package/runtime/lib/worklet-runtime/utils/version.js +0 -10
  411. package/runtime/lib/worklet-runtime/utils/version.js.map +0 -1
  412. package/runtime/src/snapshot/alog/index.ts +0 -8
  413. package/runtime/src/utils.ts +0 -134
  414. package/runtime/src/worklet-runtime/delayRunOnBackground.ts +0 -53
  415. package/runtime/src/worklet-runtime/utils/version.ts +0 -11
  416. /package/runtime/__test__/element-template/fixtures/background/hydrate/{coverage.raw-text-key-branches → children.reconciles-raw-text-slots}/output.txt +0 -0
  417. /package/runtime/lib/{shared → core}/attribute-name.d.ts +0 -0
  418. /package/runtime/lib/{shared → core}/attribute-name.js +0 -0
  419. /package/runtime/lib/{shared → core}/component-stack.d.ts +0 -0
  420. /package/runtime/src/{shared → core}/attribute-name.ts +0 -0
@@ -3,8 +3,8 @@
3
3
  // LICENSE file in the root directory of this source tree.
4
4
  import { Animation } from './animation/animation.js';
5
5
  import { KeyframeEffect } from './animation/effect.js';
6
+ import { isSdkVersionGt } from '../../shared/version.js';
6
7
  import { mainThreadFlushLoopMark, mainThreadFlushLoopOnFlushMicrotask, mainThreadFlushLoopReport, } from '../utils/mainThreadFlushLoopGuard.js';
7
- import { isSdkVersionGt } from '../utils/version.js';
8
8
  let willFlush = false;
9
9
  let shouldFlush = true;
10
10
  export function setShouldFlush(value) {
@@ -1 +1 @@
1
- {"version":3,"file":"element.js","sourceRoot":"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IAAI,CAAC;QACjB,KAAK,OAAO,CAAC,OAAO,EAAE,CAAC,IAAI,CAAC,GAAG,EAAE;YAC/B,SAAS,GAAG,KAAK,CAAC;YAClB,IAAI,OAAO,EAAE,CAAC;gBACZ,uBAAuB,CAAC,QAAQ,CAAC,CAAC;gBAClC,MAAM,KAAK,GAAG,mCAAmC,EAAE,CAAC;gBACpD,IAAI,KAAK,EAAE,CAAC;oBACV,+DAA+D;oBAC/D,iEAAiE;oBACjE,WAAW,GAAG,KAAK,CAAC;oBACpB,yBAAyB,CAAC,KAAK,CAAC,CAAC;oBACjC,OAAO;gBACT,CAAC;YACH,CAAC;YACD,kBAAkB,EAAE,CAAC;QACvB,CAAC,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["// Copyright 2024 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\nimport { Animation } from './animation/animation.js';\nimport { KeyframeEffect } from './animation/effect.js';\nimport {\n mainThreadFlushLoopMark,\n mainThreadFlushLoopOnFlushMicrotask,\n mainThreadFlushLoopReport,\n} from '../utils/mainThreadFlushLoopGuard.js';\nimport { isSdkVersionGt } from '../utils/version.js';\n\nlet willFlush = false;\nlet shouldFlush = true;\n\nexport function setShouldFlush(value: boolean): void {\n shouldFlush = value;\n}\n\nexport class Element {\n // @ts-expect-error set in constructor\n private readonly element: ElementNode;\n\n constructor(element: ElementNode) {\n // In Lynx versions prior to and including 2.15,\n // a crash occurs when printing or transferring refCounted across threads.\n // Bypass this problem by hiding the element object.\n Object.defineProperty(this, 'element', {\n get() {\n return element;\n },\n });\n }\n\n public setAttribute(name: string, value: unknown): void {\n /* v8 ignore next 3 */\n if (__DEV__) {\n mainThreadFlushLoopMark(`element:setAttribute ${name}`);\n }\n __SetAttribute(this.element, name, value);\n this.flushElementTree();\n }\n\n public setStyleProperty(name: string, value: string): void {\n /* v8 ignore next 3 */\n if (__DEV__) {\n mainThreadFlushLoopMark(`element:setStyleProperty ${name}`);\n }\n __AddInlineStyle(this.element, name, value);\n this.flushElementTree();\n }\n\n public setStyleProperties(styles: Record<string, string>): void {\n /* v8 ignore next 5 */\n if (__DEV__) {\n mainThreadFlushLoopMark(\n `element:setStyleProperties keys=${Object.keys(styles).length}`,\n );\n }\n for (const key in styles) {\n __AddInlineStyle(this.element, key, styles[key]!);\n }\n this.flushElementTree();\n }\n\n public getAttribute(attributeName: string): unknown {\n return __GetAttributeByName(this.element, attributeName);\n }\n\n public getAttributeNames(): string[] {\n return __GetAttributeNames(this.element);\n }\n\n public querySelector(selector: string): Element | null {\n const ref = __QuerySelector(this.element, selector, {});\n return ref ? new Element(ref) : null;\n }\n\n public querySelectorAll(selector: string): Element[] {\n return __QuerySelectorAll(this.element, selector, {}).map((element) => {\n return new Element(element);\n });\n }\n\n public getComputedStyleProperty(key: string): string {\n if (!isSdkVersionGt(3, 4)) {\n throw new Error(\n 'getComputedStyleProperty requires Lynx sdk version 3.5',\n );\n }\n\n if (!key) {\n throw new Error('getComputedStyleProperty: key is required');\n }\n return __GetComputedStyleByKey(this.element, key);\n }\n\n public animate(\n keyframes: Record<string, number | string>[],\n options?: number | Record<string, number | string>,\n ): Animation {\n const normalizedOptions = typeof options === 'number' ? { duration: options } : options ?? {};\n return new Animation(new KeyframeEffect(this, keyframes, normalizedOptions));\n }\n\n public invoke(\n methodName: string,\n params?: Record<string, unknown>,\n ): Promise<unknown> {\n /* v8 ignore next 3 */\n if (__DEV__) {\n mainThreadFlushLoopMark(`element:invoke ${methodName}`);\n }\n return new Promise((resolve, reject) => {\n __InvokeUIMethod(\n this.element,\n methodName,\n params ?? {},\n (res: { code: number; data: unknown }) => {\n if (res.code === 0) {\n resolve(res.data);\n } else {\n reject(new Error('UI method invoke: ' + JSON.stringify(res)));\n }\n },\n );\n this.flushElementTree();\n });\n }\n\n private flushElementTree() {\n if (willFlush || !shouldFlush) {\n return;\n }\n willFlush = true;\n void Promise.resolve().then(() => {\n willFlush = false;\n if (__DEV__) {\n mainThreadFlushLoopMark('render');\n const error = mainThreadFlushLoopOnFlushMicrotask();\n if (error) {\n // Stop scheduling further flushes so we can surface the error.\n // This is DEV-only behavior guarded internally by the dev guard.\n shouldFlush = false;\n mainThreadFlushLoopReport(error);\n return;\n }\n }\n __FlushElementTree();\n });\n }\n}\n"]}
1
+ {"version":3,"file":"element.js","sourceRoot":"","sources":["../../../src/worklet-runtime/api/element.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAC1D,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AACrD,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AACzD,OAAO,EACL,uBAAuB,EACvB,mCAAmC,EACnC,yBAAyB,GAC1B,MAAM,sCAAsC,CAAC;AAE9C,IAAI,SAAS,GAAG,KAAK,CAAC;AACtB,IAAI,WAAW,GAAG,IAAI,CAAC;AAEvB,MAAM,UAAU,cAAc,CAAC,KAAc;IAC3C,WAAW,GAAG,KAAK,CAAC;AACtB,CAAC;AAED,MAAM,OAAO,OAAO;IAClB,sCAAsC;IACrB,OAAO,CAAc;IAEtC,YAAY,OAAoB;QAC9B,gDAAgD;QAChD,0EAA0E;QAC1E,oDAAoD;QACpD,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,SAAS,EAAE;YACrC,GAAG;gBACD,OAAO,OAAO,CAAC;YACjB,CAAC;SACF,CAAC,CAAC;IACL,CAAC;IAEM,YAAY,CAAC,IAAY,EAAE,KAAc;QAC9C,sBAAsB;QACtB,IAAI,OAAO,EAAE,CAAC;YACZ,uBAAuB,CAAC,wBAAwB,IAAI,EAAE,CAAC,CAAC;QAC1D,CAAC;QACD,cAAc,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC;QAC1C,IAAI,CAAC,gBAAgB,EAAE,CAAC;IAC1B,CAAC;IA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CAAC,CAAC,CAAC;gBAChE,CAAC;YACH,CAAC,CACF,CAAC;YACF,IAAI,CAAC,gBAAgB,EAAE,CAAC;QAC1B,CAAC,CAAC,CAAC;IACL,CAAC;IAEO,gBAAgB;QACtB,IAAI,SAAS,IAAI,CAAC,WAAW,EAAE,CAAC;YAC9B,OAAO;QACT,CAAC;QACD,SAAS,GAAG,IAAI,CAAC;QACjB,KAAK,OAAO,CAAC,OAAO,EAAE,CAAC,IAAI,CAAC,GAAG,EAAE;YAC/B,SAAS,GAAG,KAAK,CAAC;YAClB,IAAI,OAAO,EAAE,CAAC;gBACZ,uBAAuB,CAAC,QAAQ,CAAC,CAAC;gBAClC,MAAM,KAAK,GAAG,mCAAmC,EAAE,CAAC;gBACpD,IAAI,KAAK,EAAE,CAAC;oBACV,+DAA+D;oBAC/D,iEAAiE;oBACjE,WAAW,GAAG,KAAK,CAAC;oBACpB,yBAAyB,CAAC,KAAK,CAAC,CAAC;oBACjC,OAAO;gBACT,CAAC;YACH,CAAC;YACD,kBAAkB,EAAE,CAAC;QACvB,CAAC,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["// Copyright 2024 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\nimport { Animation } from './animation/animation.js';\nimport { KeyframeEffect } from './animation/effect.js';\nimport { isSdkVersionGt } from '../../shared/version.js';\nimport {\n mainThreadFlushLoopMark,\n mainThreadFlushLoopOnFlushMicrotask,\n mainThreadFlushLoopReport,\n} from '../utils/mainThreadFlushLoopGuard.js';\n\nlet willFlush = false;\nlet shouldFlush = true;\n\nexport function setShouldFlush(value: boolean): void {\n shouldFlush = value;\n}\n\nexport class Element {\n // @ts-expect-error set in constructor\n private readonly element: ElementNode;\n\n constructor(element: ElementNode) {\n // In Lynx versions prior to and including 2.15,\n // a crash occurs when printing or transferring refCounted across threads.\n // Bypass this problem by hiding the element object.\n Object.defineProperty(this, 'element', {\n get() {\n return element;\n },\n });\n }\n\n public setAttribute(name: string, value: unknown): void {\n /* v8 ignore next 3 */\n if (__DEV__) {\n mainThreadFlushLoopMark(`element:setAttribute ${name}`);\n }\n __SetAttribute(this.element, name, value);\n this.flushElementTree();\n }\n\n public setStyleProperty(name: string, value: string): void {\n /* v8 ignore next 3 */\n if (__DEV__) {\n mainThreadFlushLoopMark(`element:setStyleProperty ${name}`);\n }\n __AddInlineStyle(this.element, name, value);\n this.flushElementTree();\n }\n\n public setStyleProperties(styles: Record<string, string>): void {\n /* v8 ignore next 5 */\n if (__DEV__) {\n mainThreadFlushLoopMark(\n `element:setStyleProperties keys=${Object.keys(styles).length}`,\n );\n }\n for (const key in styles) {\n __AddInlineStyle(this.element, key, styles[key]!);\n }\n this.flushElementTree();\n }\n\n public getAttribute(attributeName: string): unknown {\n return __GetAttributeByName(this.element, attributeName);\n }\n\n public getAttributeNames(): string[] {\n return __GetAttributeNames(this.element);\n }\n\n public querySelector(selector: string): Element | null {\n const ref = __QuerySelector(this.element, selector, {});\n return ref ? new Element(ref) : null;\n }\n\n public querySelectorAll(selector: string): Element[] {\n return __QuerySelectorAll(this.element, selector, {}).map((element) => {\n return new Element(element);\n });\n }\n\n public getComputedStyleProperty(key: string): string {\n if (!isSdkVersionGt(3, 4)) {\n throw new Error(\n 'getComputedStyleProperty requires Lynx sdk version 3.5',\n );\n }\n\n if (!key) {\n throw new Error('getComputedStyleProperty: key is required');\n }\n return __GetComputedStyleByKey(this.element, key);\n }\n\n public animate(\n keyframes: Record<string, number | string>[],\n options?: number | Record<string, number | string>,\n ): Animation {\n const normalizedOptions = typeof options === 'number' ? { duration: options } : options ?? {};\n return new Animation(new KeyframeEffect(this, keyframes, normalizedOptions));\n }\n\n public invoke(\n methodName: string,\n params?: Record<string, unknown>,\n ): Promise<unknown> {\n /* v8 ignore next 3 */\n if (__DEV__) {\n mainThreadFlushLoopMark(`element:invoke ${methodName}`);\n }\n return new Promise((resolve, reject) => {\n __InvokeUIMethod(\n this.element,\n methodName,\n params ?? {},\n (res: { code: number; data: unknown }) => {\n if (res.code === 0) {\n resolve(res.data);\n } else {\n reject(new Error('UI method invoke: ' + JSON.stringify(res)));\n }\n },\n );\n this.flushElementTree();\n });\n }\n\n private flushElementTree() {\n if (willFlush || !shouldFlush) {\n return;\n }\n willFlush = true;\n void Promise.resolve().then(() => {\n willFlush = false;\n if (__DEV__) {\n mainThreadFlushLoopMark('render');\n const error = mainThreadFlushLoopOnFlushMicrotask();\n if (error) {\n // Stop scheduling further flushes so we can surface the error.\n // This is DEV-only behavior guarded internally by the dev guard.\n shouldFlush = false;\n mainThreadFlushLoopReport(error);\n return;\n }\n }\n __FlushElementTree();\n });\n }\n}\n"]}
@@ -2,7 +2,7 @@
2
2
  // Licensed under the Apache License Version 2.0 that can be found in the
3
3
  // LICENSE file in the root directory of this source tree.
4
4
  import { querySelector, querySelectorAll } from './lepusQuerySelector.js';
5
- import { isSdkVersionGt } from '../utils/version.js';
5
+ import { isSdkVersionGt } from '../../shared/version.js';
6
6
  function initApiEnv() {
7
7
  // @ts-expect-error type
8
8
  lynx.querySelector = querySelector;
@@ -1 +1 @@
1
- {"version":3,"file":"lynxApi.js","sourceRoot":"","sources":["../../../src/worklet-runtime/api/lynxApi.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAC1D,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC1E,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAErD,SAAS,UAAU;IACjB,wBAAwB;IACxB,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;IACnC,wBAAwB;IACxB,IAAI,CAAC,gBAAgB,GAAG,gBAAgB,CAAC;IACzC,wBAAwB;IACxB,UAAU,CAAC,UAAU,GAAG,IAAI,CAAC,UAAyD,CAAC;IACvF,wBAAwB;IACxB,UAAU,CAAC,WAAW,GAAG,IAAI,CAAC,WAA0D,CAAC;IACzF,wBAAwB;IACxB,UAAU,CAAC,YAAY,GAAG,IAAI,CAAC,YAAyC,CAAC;IACzE,yGAAyG;IACzG,wBAAwB;IACxB,UAAU,CAAC,aAAa,GAAG,CAAC,IAAI,CAAC,aAAa,IAAI,IAAI,CAAC,iBAAiB,CAA8B,CAAC;IAEvG,CAAC;QACC,wBAAwB;QACxB,MAAM,qBAAqB,GAAG,IAAI,CAAC,qBAAyD,CAAC;QAC7F,wBAAwB;QACxB,IAAI,CAAC,qBAAqB,GAAG,UAAU,CAAC,qBAAqB,GAAG,CAC9D,QAAoB,EACpB,EAAE;YACF,IAAI,CAAC,cAAc,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC;gBAC3B,MAAM,IAAI,KAAK,CACb,4EAA4E,CAC7E,CAAC;YACJ,CAAC;YACD,OAAO,qBAAqB,CAAC,QAAQ,CAAC,CAAC;QACzC,CAAC,CAAC;IACJ,CAAC;IAED,wBAAwB;IACxB,UAAU,CAAC,oBAAoB,GAAG,IAAI,CAAC,oBAAmD,CAAC;AAC7F,CAAC;AAED,OAAO,EAAE,UAAU,EAAE,CAAC","sourcesContent":["// Copyright 2024 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\nimport { querySelector, querySelectorAll } from './lepusQuerySelector.js';\nimport { isSdkVersionGt } from '../utils/version.js';\n\nfunction initApiEnv(): void {\n // @ts-expect-error type\n lynx.querySelector = querySelector;\n // @ts-expect-error type\n lynx.querySelectorAll = querySelectorAll;\n // @ts-expect-error type\n globalThis.setTimeout = lynx.setTimeout as (cb: () => void, timeout: number) => number;\n // @ts-expect-error type\n globalThis.setInterval = lynx.setInterval as (cb: () => void, timeout: number) => number;\n // @ts-expect-error type\n globalThis.clearTimeout = lynx.clearTimeout as (timeout: number) => void;\n // In lynx 2.14 `clearInterval` is mistakenly spelled as `clearTimeInterval`. This is fixed in lynx 2.15.\n // @ts-expect-error type\n globalThis.clearInterval = (lynx.clearInterval ?? lynx.clearTimeInterval) as (timeout: number) => void;\n\n {\n // @ts-expect-error type\n const requestAnimationFrame = lynx.requestAnimationFrame as (callback: () => void) => number;\n // @ts-expect-error type\n lynx.requestAnimationFrame = globalThis.requestAnimationFrame = (\n callback: () => void,\n ) => {\n if (!isSdkVersionGt(2, 15)) {\n throw new Error(\n 'requestAnimationFrame in main thread script requires Lynx sdk version 2.16',\n );\n }\n return requestAnimationFrame(callback);\n };\n }\n\n // @ts-expect-error type\n globalThis.cancelAnimationFrame = lynx.cancelAnimationFrame as (requestId: number) => void;\n}\n\nexport { initApiEnv };\n"]}
1
+ {"version":3,"file":"lynxApi.js","sourceRoot":"","sources":["../../../src/worklet-runtime/api/lynxApi.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAC1D,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC1E,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAEzD,SAAS,UAAU;IACjB,wBAAwB;IACxB,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;IACnC,wBAAwB;IACxB,IAAI,CAAC,gBAAgB,GAAG,gBAAgB,CAAC;IACzC,wBAAwB;IACxB,UAAU,CAAC,UAAU,GAAG,IAAI,CAAC,UAAyD,CAAC;IACvF,wBAAwB;IACxB,UAAU,CAAC,WAAW,GAAG,IAAI,CAAC,WAA0D,CAAC;IACzF,wBAAwB;IACxB,UAAU,CAAC,YAAY,GAAG,IAAI,CAAC,YAAyC,CAAC;IACzE,yGAAyG;IACzG,wBAAwB;IACxB,UAAU,CAAC,aAAa,GAAG,CAAC,IAAI,CAAC,aAAa,IAAI,IAAI,CAAC,iBAAiB,CAA8B,CAAC;IAEvG,CAAC;QACC,wBAAwB;QACxB,MAAM,qBAAqB,GAAG,IAAI,CAAC,qBAAyD,CAAC;QAC7F,wBAAwB;QACxB,IAAI,CAAC,qBAAqB,GAAG,UAAU,CAAC,qBAAqB,GAAG,CAC9D,QAAoB,EACpB,EAAE;YACF,IAAI,CAAC,cAAc,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC;gBAC3B,MAAM,IAAI,KAAK,CACb,4EAA4E,CAC7E,CAAC;YACJ,CAAC;YACD,OAAO,qBAAqB,CAAC,QAAQ,CAAC,CAAC;QACzC,CAAC,CAAC;IACJ,CAAC;IAED,wBAAwB;IACxB,UAAU,CAAC,oBAAoB,GAAG,IAAI,CAAC,oBAAmD,CAAC;AAC7F,CAAC;AAED,OAAO,EAAE,UAAU,EAAE,CAAC","sourcesContent":["// Copyright 2024 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\nimport { querySelector, querySelectorAll } from './lepusQuerySelector.js';\nimport { isSdkVersionGt } from '../../shared/version.js';\n\nfunction initApiEnv(): void {\n // @ts-expect-error type\n lynx.querySelector = querySelector;\n // @ts-expect-error type\n lynx.querySelectorAll = querySelectorAll;\n // @ts-expect-error type\n globalThis.setTimeout = lynx.setTimeout as (cb: () => void, timeout: number) => number;\n // @ts-expect-error type\n globalThis.setInterval = lynx.setInterval as (cb: () => void, timeout: number) => number;\n // @ts-expect-error type\n globalThis.clearTimeout = lynx.clearTimeout as (timeout: number) => void;\n // In lynx 2.14 `clearInterval` is mistakenly spelled as `clearTimeInterval`. This is fixed in lynx 2.15.\n // @ts-expect-error type\n globalThis.clearInterval = (lynx.clearInterval ?? lynx.clearTimeInterval) as (timeout: number) => void;\n\n {\n // @ts-expect-error type\n const requestAnimationFrame = lynx.requestAnimationFrame as (callback: () => void) => number;\n // @ts-expect-error type\n lynx.requestAnimationFrame = globalThis.requestAnimationFrame = (\n callback: () => void,\n ) => {\n if (!isSdkVersionGt(2, 15)) {\n throw new Error(\n 'requestAnimationFrame in main thread script requires Lynx sdk version 2.16',\n );\n }\n return requestAnimationFrame(callback);\n };\n }\n\n // @ts-expect-error type\n globalThis.cancelAnimationFrame = lynx.cancelAnimationFrame as (requestId: number) => void;\n}\n\nexport { initApiEnv };\n"]}
@@ -1,4 +1,4 @@
1
- import type { ClosureValueType, MainThreadRefInitValuePatch, Worklet } from './types.js';
1
+ import type { ClosureValueType, JsFnHandle, MainThreadRefInitValuePatch, Worklet } from './types.js';
2
2
  /**
3
3
  * Executes the worklet ctx.
4
4
  * @param worklet - The Worklet ctx to run.
@@ -15,4 +15,5 @@ declare function updateWorkletRefInitValueChanges(patch?: MainThreadRefInitValue
15
15
  * Releases the temporary negative-ID MainThreadRefs after hydration handoff.
16
16
  */
17
17
  declare function clearFirstScreenMainThreadRefs(): void;
18
- export { runWorkletCtx, updateWorkletRef, updateWorkletRefInitValueChanges, clearFirstScreenMainThreadRefs, registerMainThreadObjectType, registerWorklet, delayRunOnBackground, setEomShouldFlushElementTree, runRunOnMainThreadTask, };
18
+ declare function shouldDelayRunOnBackground(fnObj: JsFnHandle): boolean;
19
+ export { runWorkletCtx, updateWorkletRef, updateWorkletRefInitValueChanges, clearFirstScreenMainThreadRefs, registerMainThreadObjectType, registerWorklet, shouldDelayRunOnBackground, delayRunOnBackground, setEomShouldFlushElementTree, runRunOnMainThreadTask, };
@@ -51,6 +51,16 @@ function clearFirstScreenMainThreadRefs() {
51
51
  function registerWorklet(type, id, worklet) {
52
52
  globalThis.registerWorklet(type, id, worklet);
53
53
  }
54
+ function shouldDelayRunOnBackground(fnObj) {
55
+ if (fnObj._isFirstScreen) {
56
+ return true;
57
+ }
58
+ if (fnObj._hydratedEpoch === undefined) {
59
+ return false;
60
+ }
61
+ const delayImpl = globalThis.lynxWorkletImpl?._runOnBackgroundDelayImpl;
62
+ return Boolean(delayImpl && !delayImpl.hasHydrated && fnObj._hydratedEpoch !== delayImpl.epoch);
63
+ }
54
64
  /**
55
65
  * Delay a runOnBackground after hydration.
56
66
  *
@@ -75,5 +85,5 @@ function setEomShouldFlushElementTree(value) {
75
85
  function runRunOnMainThreadTask(task, params, resolveId) {
76
86
  globalThis.lynxWorkletImpl?._runRunOnMainThreadTask(task, params, resolveId);
77
87
  }
78
- export { runWorkletCtx, updateWorkletRef, updateWorkletRefInitValueChanges, clearFirstScreenMainThreadRefs, registerMainThreadObjectType, registerWorklet, delayRunOnBackground, setEomShouldFlushElementTree, runRunOnMainThreadTask, };
88
+ export { runWorkletCtx, updateWorkletRef, updateWorkletRefInitValueChanges, clearFirstScreenMainThreadRefs, registerMainThreadObjectType, registerWorklet, shouldDelayRunOnBackground, delayRunOnBackground, setEomShouldFlushElementTree, runRunOnMainThreadTask, };
79
89
  //# sourceMappingURL=bindings.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"bindings.js","sourceRoot":"","sources":["../../../src/worklet-runtime/bindings/bindings.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAK1D;;;;GAIG;AACH,SAAS,aAAa,CAAC,OAAgB,EAAE,MAA0B;IACjE,OAAO,UAAU,CAAC,UAAU,EAAE,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;AAClD,CAAC;AAED;;;;;;GAMG;AACH,SAAS,gBAAgB,CAAC,UAAmC,EAAE,OAA2B;IACxF,UAAU,CAAC,eAAe,EAAE,QAAQ,CAAC,gBAAgB,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;AAC7E,CAAC;AAED;;;;GAIG;AACH,SAAS,gCAAgC,CACvC,KAAmC;IAEnC,IAAI,KAAK,EAAE,CAAC;QACV,UAAU,CAAC,eAAe,EAAE,QAAQ,CAAC,gCAAgC,CAAC,KAAK,CAAC,CAAC;IAC/E,CAAC;AACH,CAAC;AAED;;;;GAIG;AACH,SAAS,4BAA4B,CACnC,IAAY,EACZ,MAAqD;IAErD,UAAU,CAAC,eAAe,CAAC,QAAQ,CAAC,4BAA4B,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;AACjF,CAAC;AAED;;GAEG;AACH,SAAS,8BAA8B;IACrC,UAAU,CAAC,eAAe,EAAE,QAAQ,CAAC,6BAA6B,EAAE,CAAC;AACvE,CAAC;AAED;;;;GAIG;AACH,SAAS,eAAe,CAAC,IAAY,EAAE,EAAU,EAAE,OAAwC;IACzF,UAAU,CAAC,eAAe,CAAC,IAAI,EAAE,EAAE,EAAE,OAAO,CAAC,CAAC;AAChD,CAAC;AAED;;;;GAIG;AACH,SAAS,oBAAoB,CAAC,KAAiB,EAAE,EAA0C;IACzF,UAAU,CAAC,eAAe,EAAE,yBAAyB,CAAC,oBAAoB,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;AACxF,CAAC;AAED;;;;GAIG;AACH,SAAS,4BAA4B,CAAC,KAAc;IAClD,UAAU,CAAC,eAAe,EAAE,QAAQ,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;AAC7D,CAAC;AAED;;;;GAIG;AACH,SAAS,sBAAsB,CAAC,IAAa,EAAE,MAA0B,EAAE,SAAiB;IAC1F,UAAU,CAAC,eAAe,EAAE,uBAAuB,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,CAAC,CAAC;AAC/E,CAAC;AAED,OAAO,EACL,aAAa,EACb,gBAAgB,EAChB,gCAAgC,EAChC,8BAA8B,EAC9B,4BAA4B,EAC5B,eAAe,EACf,oBAAoB,EACpB,4BAA4B,EAC5B,sBAAsB,GACvB,CAAC","sourcesContent":["// Copyright 2024 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\nimport type { ClosureValueType, JsFnHandle, MainThreadRefInitValuePatch, Worklet, WorkletRefImpl } from './types.js';\nimport type { Element } from '../api/element.js';\n\n/**\n * Executes the worklet ctx.\n * @param worklet - The Worklet ctx to run.\n * @param params - An array as parameters of the worklet run.\n */\nfunction runWorkletCtx(worklet: Worklet, params: ClosureValueType[]): unknown {\n return globalThis.runWorklet?.(worklet, params);\n}\n\n/**\n * Save an element to a `WorkletRef`.\n *\n * @param workletRef - The `WorkletRef` to be updated.\n * @param element - The element.\n * @internal\n */\nfunction updateWorkletRef(workletRef: WorkletRefImpl<Element>, element: ElementNode | null): void {\n globalThis.lynxWorkletImpl?._refImpl.updateWorkletRef(workletRef, element);\n}\n\n/**\n * Update the initial value of the `WorkletRef`.\n *\n * @param patch - An array containing the index and new value of the worklet value.\n */\nfunction updateWorkletRefInitValueChanges(\n patch?: MainThreadRefInitValuePatch,\n): void {\n if (patch) {\n globalThis.lynxWorkletImpl?._refImpl.updateWorkletRefInitValueChanges(patch);\n }\n}\n\n/**\n * Register a definition for an opaque main-thread object type.\n *\n * @internal\n */\nfunction registerMainThreadObjectType(\n type: string,\n create: ((initialValue: unknown) => object) | Worklet,\n): void {\n globalThis.lynxWorkletImpl._refImpl.registerMainThreadObjectType(type, create);\n}\n\n/**\n * Releases the temporary negative-ID MainThreadRefs after hydration handoff.\n */\nfunction clearFirstScreenMainThreadRefs(): void {\n globalThis.lynxWorkletImpl?._refImpl.clearFirstScreenWorkletRefMap();\n}\n\n/**\n * Register a worklet.\n *\n * @internal\n */\nfunction registerWorklet(type: string, id: string, worklet: (...args: unknown[]) => unknown): void {\n globalThis.registerWorklet(type, id, worklet);\n}\n\n/**\n * Delay a runOnBackground after hydration.\n *\n * @internal\n */\nfunction delayRunOnBackground(fnObj: JsFnHandle, fn: (fnId: number, execId: number) => void): void {\n globalThis.lynxWorkletImpl?._runOnBackgroundDelayImpl.delayRunOnBackground(fnObj, fn);\n}\n\n/**\n * Set whether EOM operations should flush the element tree.\n *\n * @internal\n */\nfunction setEomShouldFlushElementTree(value: boolean) {\n globalThis.lynxWorkletImpl?._eomImpl.setShouldFlush(value);\n}\n\n/**\n * Runs a task on the main thread.\n *\n * @internal\n */\nfunction runRunOnMainThreadTask(task: Worklet, params: ClosureValueType[], resolveId: number): void {\n globalThis.lynxWorkletImpl?._runRunOnMainThreadTask(task, params, resolveId);\n}\n\nexport {\n runWorkletCtx,\n updateWorkletRef,\n updateWorkletRefInitValueChanges,\n clearFirstScreenMainThreadRefs,\n registerMainThreadObjectType,\n registerWorklet,\n delayRunOnBackground,\n setEomShouldFlushElementTree,\n runRunOnMainThreadTask,\n};\n"]}
1
+ {"version":3,"file":"bindings.js","sourceRoot":"","sources":["../../../src/worklet-runtime/bindings/bindings.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAK1D;;;;GAIG;AACH,SAAS,aAAa,CAAC,OAAgB,EAAE,MAA0B;IACjE,OAAO,UAAU,CAAC,UAAU,EAAE,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;AAClD,CAAC;AAED;;;;;;GAMG;AACH,SAAS,gBAAgB,CAAC,UAAmC,EAAE,OAA2B;IACxF,UAAU,CAAC,eAAe,EAAE,QAAQ,CAAC,gBAAgB,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;AAC7E,CAAC;AAED;;;;GAIG;AACH,SAAS,gCAAgC,CACvC,KAAmC;IAEnC,IAAI,KAAK,EAAE,CAAC;QACV,UAAU,CAAC,eAAe,EAAE,QAAQ,CAAC,gCAAgC,CAAC,KAAK,CAAC,CAAC;IAC/E,CAAC;AACH,CAAC;AAED;;;;GAIG;AACH,SAAS,4BAA4B,CACnC,IAAY,EACZ,MAAqD;IAErD,UAAU,CAAC,eAAe,CAAC,QAAQ,CAAC,4BAA4B,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;AACjF,CAAC;AAED;;GAEG;AACH,SAAS,8BAA8B;IACrC,UAAU,CAAC,eAAe,EAAE,QAAQ,CAAC,6BAA6B,EAAE,CAAC;AACvE,CAAC;AAED;;;;GAIG;AACH,SAAS,eAAe,CAAC,IAAY,EAAE,EAAU,EAAE,OAAwC;IACzF,UAAU,CAAC,eAAe,CAAC,IAAI,EAAE,EAAE,EAAE,OAAO,CAAC,CAAC;AAChD,CAAC;AAED,SAAS,0BAA0B,CAAC,KAAiB;IACnD,IAAI,KAAK,CAAC,cAAc,EAAE,CAAC;QACzB,OAAO,IAAI,CAAC;IACd,CAAC;IACD,IAAI,KAAK,CAAC,cAAc,KAAK,SAAS,EAAE,CAAC;QACvC,OAAO,KAAK,CAAC;IACf,CAAC;IACD,MAAM,SAAS,GAAG,UAAU,CAAC,eAAe,EAAE,yBAAyB,CAAC;IACxE,OAAO,OAAO,CAAC,SAAS,IAAI,CAAC,SAAS,CAAC,WAAW,IAAI,KAAK,CAAC,cAAc,KAAK,SAAS,CAAC,KAAK,CAAC,CAAC;AAClG,CAAC;AAED;;;;GAIG;AACH,SAAS,oBAAoB,CAAC,KAAiB,EAAE,EAA0C;IACzF,UAAU,CAAC,eAAe,EAAE,yBAAyB,CAAC,oBAAoB,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;AACxF,CAAC;AAED;;;;GAIG;AACH,SAAS,4BAA4B,CAAC,KAAc;IAClD,UAAU,CAAC,eAAe,EAAE,QAAQ,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;AAC7D,CAAC;AAED;;;;GAIG;AACH,SAAS,sBAAsB,CAAC,IAAa,EAAE,MAA0B,EAAE,SAAiB;IAC1F,UAAU,CAAC,eAAe,EAAE,uBAAuB,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,CAAC,CAAC;AAC/E,CAAC;AAED,OAAO,EACL,aAAa,EACb,gBAAgB,EAChB,gCAAgC,EAChC,8BAA8B,EAC9B,4BAA4B,EAC5B,eAAe,EACf,0BAA0B,EAC1B,oBAAoB,EACpB,4BAA4B,EAC5B,sBAAsB,GACvB,CAAC","sourcesContent":["// Copyright 2024 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\nimport type { ClosureValueType, JsFnHandle, MainThreadRefInitValuePatch, Worklet, WorkletRefImpl } from './types.js';\nimport type { Element } from '../api/element.js';\n\n/**\n * Executes the worklet ctx.\n * @param worklet - The Worklet ctx to run.\n * @param params - An array as parameters of the worklet run.\n */\nfunction runWorkletCtx(worklet: Worklet, params: ClosureValueType[]): unknown {\n return globalThis.runWorklet?.(worklet, params);\n}\n\n/**\n * Save an element to a `WorkletRef`.\n *\n * @param workletRef - The `WorkletRef` to be updated.\n * @param element - The element.\n * @internal\n */\nfunction updateWorkletRef(workletRef: WorkletRefImpl<Element>, element: ElementNode | null): void {\n globalThis.lynxWorkletImpl?._refImpl.updateWorkletRef(workletRef, element);\n}\n\n/**\n * Update the initial value of the `WorkletRef`.\n *\n * @param patch - An array containing the index and new value of the worklet value.\n */\nfunction updateWorkletRefInitValueChanges(\n patch?: MainThreadRefInitValuePatch,\n): void {\n if (patch) {\n globalThis.lynxWorkletImpl?._refImpl.updateWorkletRefInitValueChanges(patch);\n }\n}\n\n/**\n * Register a definition for an opaque main-thread object type.\n *\n * @internal\n */\nfunction registerMainThreadObjectType(\n type: string,\n create: ((initialValue: unknown) => object) | Worklet,\n): void {\n globalThis.lynxWorkletImpl._refImpl.registerMainThreadObjectType(type, create);\n}\n\n/**\n * Releases the temporary negative-ID MainThreadRefs after hydration handoff.\n */\nfunction clearFirstScreenMainThreadRefs(): void {\n globalThis.lynxWorkletImpl?._refImpl.clearFirstScreenWorkletRefMap();\n}\n\n/**\n * Register a worklet.\n *\n * @internal\n */\nfunction registerWorklet(type: string, id: string, worklet: (...args: unknown[]) => unknown): void {\n globalThis.registerWorklet(type, id, worklet);\n}\n\nfunction shouldDelayRunOnBackground(fnObj: JsFnHandle): boolean {\n if (fnObj._isFirstScreen) {\n return true;\n }\n if (fnObj._hydratedEpoch === undefined) {\n return false;\n }\n const delayImpl = globalThis.lynxWorkletImpl?._runOnBackgroundDelayImpl;\n return Boolean(delayImpl && !delayImpl.hasHydrated && fnObj._hydratedEpoch !== delayImpl.epoch);\n}\n\n/**\n * Delay a runOnBackground after hydration.\n *\n * @internal\n */\nfunction delayRunOnBackground(fnObj: JsFnHandle, fn: (fnId: number, execId: number) => void): void {\n globalThis.lynxWorkletImpl?._runOnBackgroundDelayImpl.delayRunOnBackground(fnObj, fn);\n}\n\n/**\n * Set whether EOM operations should flush the element tree.\n *\n * @internal\n */\nfunction setEomShouldFlushElementTree(value: boolean) {\n globalThis.lynxWorkletImpl?._eomImpl.setShouldFlush(value);\n}\n\n/**\n * Runs a task on the main thread.\n *\n * @internal\n */\nfunction runRunOnMainThreadTask(task: Worklet, params: ClosureValueType[], resolveId: number): void {\n globalThis.lynxWorkletImpl?._runRunOnMainThreadTask(task, params, resolveId);\n}\n\nexport {\n runWorkletCtx,\n updateWorkletRef,\n updateWorkletRefInitValueChanges,\n clearFirstScreenMainThreadRefs,\n registerMainThreadObjectType,\n registerWorklet,\n shouldDelayRunOnBackground,\n delayRunOnBackground,\n setEomShouldFlushElementTree,\n runRunOnMainThreadTask,\n};\n"]}
@@ -35,7 +35,15 @@ export function flushDelayedRunOnBackgroundFunctions() {
35
35
  globalThis.lynxWorkletImpl?._runOnBackgroundDelayImpl?.runDelayedBackgroundFunctions?.();
36
36
  }
37
37
  export function clearDelayedRunOnBackgroundFunctions() {
38
- globalThis.lynxWorkletImpl?._runOnBackgroundDelayImpl?.clearDelayedBackgroundFunctions?.();
38
+ const impl = globalThis.lynxWorkletImpl;
39
+ if (!impl) {
40
+ return;
41
+ }
42
+ const manager = impl._jsFunctionLifecycleManager;
43
+ if (manager?.recreate) {
44
+ impl._jsFunctionLifecycleManager = manager.recreate();
45
+ }
46
+ impl._runOnBackgroundDelayImpl?.clearDelayedBackgroundFunctions?.();
39
47
  }
40
48
  /**
41
49
  * This must be called when the hydration is finished.
@@ -1 +1 @@
1
- {"version":3,"file":"observers.js","sourceRoot":"","sources":["../../../src/worklet-runtime/bindings/observers.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D,OAAO,EAAE,8BAA8B,EAAE,MAAM,eAAe,CAAC;AAG/D;;;GAGG;AACH,MAAM,UAAU,iBAAiB,CAAC,OAAgB,EAAE,UAAmB;IACrE,UAAU,CAAC,eAAe,EAAE,WAAW,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC;AAC/D,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,kBAAkB,CAChC,OAAgB,EAChB,UAAsC,EACtC,aAAsB,EACtB,OAAoB;IAEpB,IAAI,aAAa,IAAI,UAAU,EAAE,CAAC;QAChC,iBAAiB,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC;IACzC,CAAC;IACD,mDAAmD;IACnD,IAAI,aAAa,EAAE,CAAC;QAClB,UAAU,CAAC,eAAe,EAAE,eAAe,CAAC,iBAAiB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IAClF,CAAC;AACH,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,OAAgB;IAC/C,IAAI,OAAO,CAAC,OAAO,KAAK,SAAS,EAAE,CAAC;QAClC,UAAU,CAAC,eAAe,EAAE,2BAA2B,EAAE,MAAM,CAAC,OAAO,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IAC5F,CAAC;AACH,CAAC;AAED,MAAM,UAAU,oCAAoC;IAClD,UAAU,CAAC,eAAe,EAAE,yBAAyB,EAAE,6BAA6B,EAAE,EAAE,CAAC;AAC3F,CAAC;AAED,MAAM,UAAU,oCAAoC;IAClD,UAAU,CAAC,eAAe,EAAE,yBAAyB,EAAE,+BAA+B,EAAE,EAAE,CAAC;AAC7F,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,mBAAmB;IACjC,UAAU,CAAC,eAAe,EAAE,yBAAyB,CAAC,6BAA6B,EAAE,CAAC;IACtF,8BAA8B,EAAE,CAAC;IACjC,mDAAmD;IACnD,UAAU,CAAC,eAAe,EAAE,eAAe,CAAC,oBAAoB,EAAE,CAAC;AACrE,CAAC","sourcesContent":["// Copyright 2025 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\nimport { clearFirstScreenMainThreadRefs } from './bindings.js';\nimport type { Worklet } from './types.js';\n\n/**\n * Hydrates a new worklet ctx from the first-screen ctx without requiring a\n * native Element. Backends compose their own replay semantics around this.\n */\nexport function hydrateWorkletCtx(worklet: Worklet, oldWorklet: Worklet): void {\n globalThis.lynxWorkletImpl?._hydrateCtx(worklet, oldWorklet);\n}\n\n/**\n * This function must be called when a worklet context is updated.\n *\n * @param worklet - The worklet to be updated\n * @param oldWorklet - The old worklet context\n * @param isFirstScreen - Whether it is before the hydration is finished\n * @param element - The element\n */\nexport function onWorkletCtxUpdate(\n worklet: Worklet,\n oldWorklet: Worklet | null | undefined,\n isFirstScreen: boolean,\n element: ElementNode,\n): void {\n if (isFirstScreen && oldWorklet) {\n hydrateWorkletCtx(worklet, oldWorklet);\n }\n // For old version dynamic component compatibility.\n if (isFirstScreen) {\n globalThis.lynxWorkletImpl?._eventDelayImpl.runDelayedWorklet(worklet, element);\n }\n}\n\nexport function retainWorkletCtx(worklet: Worklet): void {\n if (worklet._execId !== undefined) {\n globalThis.lynxWorkletImpl?._jsFunctionLifecycleManager?.addRef(worklet._execId, worklet);\n }\n}\n\nexport function flushDelayedRunOnBackgroundFunctions(): void {\n globalThis.lynxWorkletImpl?._runOnBackgroundDelayImpl?.runDelayedBackgroundFunctions?.();\n}\n\nexport function clearDelayedRunOnBackgroundFunctions(): void {\n globalThis.lynxWorkletImpl?._runOnBackgroundDelayImpl?.clearDelayedBackgroundFunctions?.();\n}\n\n/**\n * This must be called when the hydration is finished.\n */\nexport function onHydrationFinished(): void {\n globalThis.lynxWorkletImpl?._runOnBackgroundDelayImpl.runDelayedBackgroundFunctions();\n clearFirstScreenMainThreadRefs();\n // For old version dynamic component compatibility.\n globalThis.lynxWorkletImpl?._eventDelayImpl.clearDelayedWorklets();\n}\n"]}
1
+ {"version":3,"file":"observers.js","sourceRoot":"","sources":["../../../src/worklet-runtime/bindings/observers.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D,OAAO,EAAE,8BAA8B,EAAE,MAAM,eAAe,CAAC;AAG/D;;;GAGG;AACH,MAAM,UAAU,iBAAiB,CAAC,OAAgB,EAAE,UAAmB;IACrE,UAAU,C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BAA8B,EAAE,CAAC;IACjC,mDAAmD;IACnD,UAAU,CAAC,eAAe,EAAE,eAAe,CAAC,oBAAoB,EAAE,CAAC;AACrE,CAAC","sourcesContent":["// Copyright 2025 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\nimport { clearFirstScreenMainThreadRefs } from './bindings.js';\nimport type { Worklet } from './types.js';\n\n/**\n * Hydrates a new worklet ctx from the first-screen ctx without requiring a\n * native Element. Backends compose their own replay semantics around this.\n */\nexport function hydrateWorkletCtx(worklet: Worklet, oldWorklet: Worklet): void {\n globalThis.lynxWorkletImpl?._hydrateCtx(worklet, oldWorklet);\n}\n\n/**\n * This function must be called when a worklet context is updated.\n *\n * @param worklet - The worklet to be updated\n * @param oldWorklet - The old worklet context\n * @param isFirstScreen - Whether it is before the hydration is finished\n * @param element - The element\n */\nexport function onWorkletCtxUpdate(\n worklet: Worklet,\n oldWorklet: Worklet | null | undefined,\n isFirstScreen: boolean,\n element: ElementNode,\n): void {\n if (isFirstScreen && oldWorklet) {\n hydrateWorkletCtx(worklet, oldWorklet);\n }\n // For old version dynamic component compatibility.\n if (isFirstScreen) {\n globalThis.lynxWorkletImpl?._eventDelayImpl.runDelayedWorklet(worklet, element);\n }\n}\n\nexport function retainWorkletCtx(worklet: Worklet): void {\n if (worklet._execId !== undefined) {\n globalThis.lynxWorkletImpl?._jsFunctionLifecycleManager?.addRef(worklet._execId, worklet);\n }\n}\n\nexport function flushDelayedRunOnBackgroundFunctions(): void {\n globalThis.lynxWorkletImpl?._runOnBackgroundDelayImpl?.runDelayedBackgroundFunctions?.();\n}\n\nexport function clearDelayedRunOnBackgroundFunctions(): void {\n const impl = globalThis.lynxWorkletImpl;\n if (!impl) {\n return;\n }\n const manager = impl._jsFunctionLifecycleManager;\n if (manager?.recreate) {\n impl._jsFunctionLifecycleManager = manager.recreate();\n }\n impl._runOnBackgroundDelayImpl?.clearDelayedBackgroundFunctions?.();\n}\n\n/**\n * This must be called when the hydration is finished.\n */\nexport function onHydrationFinished(): void {\n globalThis.lynxWorkletImpl?._runOnBackgroundDelayImpl.runDelayedBackgroundFunctions();\n clearFirstScreenMainThreadRefs();\n // For old version dynamic component compatibility.\n globalThis.lynxWorkletImpl?._eventDelayImpl.clearDelayedWorklets();\n}\n"]}
@@ -34,6 +34,7 @@ export interface JsFnHandle {
34
34
  _execId?: number;
35
35
  _error?: string;
36
36
  _isFirstScreen?: boolean;
37
+ _hydratedEpoch?: number;
37
38
  /**
38
39
  * Stores an array of indexes of runOnBackground tasks that should be processed with a delay.
39
40
  * This is used before hydration.
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/worklet-runtime/bindings/types.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAqE1D,MAAM,CAAN,IAAY,gBAIX;AAJD,WAAY,gBAAgB;IAC1B,uDAAQ,CAAA;IACR,yDAAS,CAAA;IACT,6DAAW,CAAA;AACb,CAAC,EAJW,gBAAgB,KAAhB,gBAAgB,QAI3B","sourcesContent":["// Copyright 2024 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\nimport type { Element } from '../api/element.js';\n\nexport type { Element };\n\nexport type WorkletRefId = number;\n\nexport interface WorkletRefImpl<T> {\n _wvid: WorkletRefId;\n _initValue: T;\n _type?: string;\n _lifecycleObserver?: unknown;\n current?: T;\n}\n\nexport interface WorkletRef<T> {\n _wvid: WorkletRefId;\n current: T;\n\n [key: string]: unknown;\n}\n\nexport type ClosureValueType =\n | null\n | undefined\n | string\n | boolean\n | number\n | object;\n\nexport type MainThreadRefInitValuePatch = (\n | [id: number, value: unknown]\n | [id: number, value: unknown, type: string]\n)[];\n\nexport interface Worklet {\n _wkltId: string;\n _workletType?: string;\n _c?: Record<string, ClosureValueType>;\n _execId?: number;\n _jsFn?: Record<string, string>;\n _unmount?: () => void;\n [key: string]: ClosureValueType;\n\n // for pre-0.99 compatibility\n _lepusWorkletHash?: string;\n}\n\n/**\n * @public\n */\nexport interface JsFnHandle {\n _jsFnId?: number;\n _fn?: (...args: unknown[]) => unknown;\n _execId?: number;\n _error?: string;\n _isFirstScreen?: boolean;\n /**\n * Stores an array of indexes of runOnBackground tasks that should be processed with a delay.\n * This is used before hydration.\n */\n _delayIndices?: number[];\n}\n\nexport interface EventCtx {\n _eventReturnResult?: number;\n}\n\nexport enum RunWorkletSource {\n NONE = 0,\n EVENT = 1,\n GESTURE = 2,\n}\n\nexport interface RunWorkletOptions {\n source: RunWorkletSource;\n}\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/worklet-runtime/bindings/types.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAsE1D,MAAM,CAAN,IAAY,gBAIX;AAJD,WAAY,gBAAgB;IAC1B,uDAAQ,CAAA;IACR,yDAAS,CAAA;IACT,6DAAW,CAAA;AACb,CAAC,EAJW,gBAAgB,KAAhB,gBAAgB,QAI3B","sourcesContent":["// Copyright 2024 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\nimport type { Element } from '../api/element.js';\n\nexport type { Element };\n\nexport type WorkletRefId = number;\n\nexport interface WorkletRefImpl<T> {\n _wvid: WorkletRefId;\n _initValue: T;\n _type?: string;\n _lifecycleObserver?: unknown;\n current?: T;\n}\n\nexport interface WorkletRef<T> {\n _wvid: WorkletRefId;\n current: T;\n\n [key: string]: unknown;\n}\n\nexport type ClosureValueType =\n | null\n | undefined\n | string\n | boolean\n | number\n | object;\n\nexport type MainThreadRefInitValuePatch = (\n | [id: number, value: unknown]\n | [id: number, value: unknown, type: string]\n)[];\n\nexport interface Worklet {\n _wkltId: string;\n _workletType?: string;\n _c?: Record<string, ClosureValueType>;\n _execId?: number;\n _jsFn?: Record<string, string>;\n _unmount?: () => void;\n [key: string]: ClosureValueType;\n\n // for pre-0.99 compatibility\n _lepusWorkletHash?: string;\n}\n\n/**\n * @public\n */\nexport interface JsFnHandle {\n _jsFnId?: number;\n _fn?: (...args: unknown[]) => unknown;\n _execId?: number;\n _error?: string;\n _isFirstScreen?: boolean;\n _hydratedEpoch?: number;\n /**\n * Stores an array of indexes of runOnBackground tasks that should be processed with a delay.\n * This is used before hydration.\n */\n _delayIndices?: number[];\n}\n\nexport interface EventCtx {\n _eventReturnResult?: number;\n}\n\nexport enum RunWorkletSource {\n NONE = 0,\n EVENT = 1,\n GESTURE = 2,\n}\n\nexport interface RunWorkletOptions {\n source: RunWorkletSource;\n}\n"]}
@@ -1,11 +1,9 @@
1
1
  import type { ClosureValueType, Worklet } from './bindings/types.js';
2
2
  interface EventDelayImpl {
3
3
  _delayedWorkletParamsMap: Map<string, ClosureValueType[][]>;
4
+ delayExecUntilJsReady(hash: string, params: ClosureValueType[]): void;
4
5
  runDelayedWorklet(worklet: Worklet, element: ElementNode): void;
5
6
  clearDelayedWorklets(): void;
6
7
  }
7
8
  declare function initEventDelay(): EventDelayImpl;
8
- declare function delayExecUntilJsReady(hash: string, params: ClosureValueType[]): void;
9
- declare function runDelayedWorklet(worklet: Worklet, element: ElementNode): void;
10
- declare function clearDelayedWorklets(): void;
11
- export { type EventDelayImpl, initEventDelay, delayExecUntilJsReady, runDelayedWorklet, clearDelayedWorklets };
9
+ export { type EventDelayImpl, initEventDelay };
@@ -1,49 +1,47 @@
1
1
  import { profile } from './utils/profile.js';
2
- let impl;
3
2
  function initEventDelay() {
4
- return (impl = {
3
+ const instance = {
5
4
  _delayedWorkletParamsMap: new Map(),
6
- runDelayedWorklet,
7
- clearDelayedWorklets,
8
- });
5
+ delayExecUntilJsReady(hash, params) {
6
+ profile('delayExecUntilJsReady: ' + hash, () => {
7
+ const map = instance._delayedWorkletParamsMap;
8
+ const paramVec = map.get(hash);
9
+ if (paramVec) {
10
+ paramVec.push(params);
11
+ }
12
+ else {
13
+ map.set(hash, [params]);
14
+ }
15
+ });
16
+ },
17
+ runDelayedWorklet(worklet, element) {
18
+ profile('commitDelayedWorklet', () => {
19
+ const paramsVec = instance._delayedWorkletParamsMap.get(worklet._wkltId);
20
+ if (paramsVec === undefined) {
21
+ return;
22
+ }
23
+ const leftParamsVec = [];
24
+ paramsVec.forEach((params) => {
25
+ const firstParam = params[0];
26
+ if (firstParam?.currentTarget?.elementRefptr === element) {
27
+ setTimeout(() => {
28
+ profile('runDelayedWorklet', () => {
29
+ runWorklet(worklet, params);
30
+ });
31
+ }, 0);
32
+ }
33
+ else {
34
+ leftParamsVec.push(params);
35
+ }
36
+ });
37
+ instance._delayedWorkletParamsMap.set(worklet._wkltId, leftParamsVec);
38
+ });
39
+ },
40
+ clearDelayedWorklets() {
41
+ instance._delayedWorkletParamsMap.clear();
42
+ },
43
+ };
44
+ return instance;
9
45
  }
10
- function delayExecUntilJsReady(hash, params) {
11
- profile('delayExecUntilJsReady: ' + hash, () => {
12
- const map = impl._delayedWorkletParamsMap;
13
- const paramVec = map.get(hash);
14
- if (paramVec) {
15
- paramVec.push(params);
16
- }
17
- else {
18
- map.set(hash, [params]);
19
- }
20
- });
21
- }
22
- function runDelayedWorklet(worklet, element) {
23
- profile('commitDelayedWorklet', () => {
24
- const paramsVec = impl._delayedWorkletParamsMap.get(worklet._wkltId);
25
- if (paramsVec === undefined) {
26
- return;
27
- }
28
- const leftParamsVec = [];
29
- paramsVec.forEach((params) => {
30
- const firstParam = params[0];
31
- if (firstParam?.currentTarget?.elementRefptr === element) {
32
- setTimeout(() => {
33
- profile('runDelayedWorklet', () => {
34
- runWorklet(worklet, params);
35
- });
36
- }, 0);
37
- }
38
- else {
39
- leftParamsVec.push(params);
40
- }
41
- });
42
- impl._delayedWorkletParamsMap.set(worklet._wkltId, leftParamsVec);
43
- });
44
- }
45
- function clearDelayedWorklets() {
46
- impl._delayedWorkletParamsMap.clear();
47
- }
48
- export { initEventDelay, delayExecUntilJsReady, runDelayedWorklet, clearDelayedWorklets };
46
+ export { initEventDelay };
49
47
  //# sourceMappingURL=delayWorkletEvent.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"delayWorkletEvent.js","sourceRoot":"","sources":["../../src/worklet-runtime/delayWorkletEvent.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAQ7C,IAAI,IAAgC,CAAC;AAErC,SAAS,cAAc;IACrB,OAAO,CAAC,IAAI,GAAG;QACb,wBAAwB,EAAE,IAAI,GAAG,EAAE;QACnC,iBAAiB;QACjB,oBAAoB;KACrB,CAAC,CAAC;AACL,CAAC;AAED,SAAS,qBAAqB,CAC5B,IAAY,EACZ,MAA0B;IAE1B,OAAO,CAAC,yBAAyB,GAAG,IAAI,EAAE,GAAG,EAAE;QAC7C,MAAM,GAAG,GAAG,IAAK,CAAC,wBAAwB,CAAC;QAC3C,MAAM,QAAQ,GAAG,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAC/B,IAAI,QAAQ,EAAE,CAAC;YACb,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACxB,CAAC;aAAM,CAAC;YACN,GAAG,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC;QAC1B,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC;AAED,SAAS,iBAAiB,CAAC,OAAgB,EAAE,OAAoB;IAC/D,OAAO,CAAC,sBAAsB,EAAE,GAAG,EAAE;QACnC,MAAM,SAAS,GAAG,IAAK,CAAC,wBAAwB,CAAC,GAAG,CAClD,OAAO,CAAC,OAAO,CAChB,CAAC;QACF,IAAI,SAAS,KAAK,SAAS,EAAE,CAAC;YAC5B,OAAO;QACT,CAAC;QACD,MAAM,aAAa,GAAyB,EAAE,CAAC;QAC/C,SAAS,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,EAAE;YAC3B,MAAM,UAAU,GAAG,MAAM,CAAC,CAAC,CAAoE,CAAC;YAChG,IAAI,UAAU,EAAE,aAAa,EAAE,aAAa,KAAK,OAAO,EAAE,CAAC;gBACzD,UAAU,CAAC,GAAG,EAAE;oBACd,OAAO,CAAC,mBAAmB,EAAE,GAAG,EAAE;wBAChC,UAAU,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;oBAC9B,CAAC,CAAC,CAAC;gBACL,CAAC,EAAE,CAAC,CAAC,CAAC;YACR,CAAC;iBAAM,CAAC;gBACN,aAAa,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;YAC7B,CAAC;QACH,CAAC,CAAC,CAAC;QACH,IAAK,CAAC,wBAAwB,CAAC,GAAG,CAChC,OAAO,CAAC,OAAO,EACf,aAAa,CACd,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC;AAED,SAAS,oBAAoB;IAC3B,IAAK,CAAC,wBAAwB,CAAC,KAAK,EAAE,CAAC;AACzC,CAAC;AAED,OAAO,EAAuB,cAAc,EAAE,qBAAqB,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,CAAC","sourcesContent":["// Copyright 2024 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\nimport type { ClosureValueType, Worklet } from './bindings/types.js';\nimport { profile } from './utils/profile.js';\n\ninterface EventDelayImpl {\n _delayedWorkletParamsMap: Map<string, ClosureValueType[][]>;\n runDelayedWorklet(worklet: Worklet, element: ElementNode): void;\n clearDelayedWorklets(): void;\n}\n\nlet impl: EventDelayImpl | undefined;\n\nfunction initEventDelay(): EventDelayImpl {\n return (impl = {\n _delayedWorkletParamsMap: new Map(),\n runDelayedWorklet,\n clearDelayedWorklets,\n });\n}\n\nfunction delayExecUntilJsReady(\n hash: string,\n params: ClosureValueType[],\n): void {\n profile('delayExecUntilJsReady: ' + hash, () => {\n const map = impl!._delayedWorkletParamsMap;\n const paramVec = map.get(hash);\n if (paramVec) {\n paramVec.push(params);\n } else {\n map.set(hash, [params]);\n }\n });\n}\n\nfunction runDelayedWorklet(worklet: Worklet, element: ElementNode): void {\n profile('commitDelayedWorklet', () => {\n const paramsVec = impl!._delayedWorkletParamsMap.get(\n worklet._wkltId,\n );\n if (paramsVec === undefined) {\n return;\n }\n const leftParamsVec: ClosureValueType[][] = [];\n paramsVec.forEach((params) => {\n const firstParam = params[0] as { currentTarget?: { elementRefptr?: ElementNode } } | undefined;\n if (firstParam?.currentTarget?.elementRefptr === element) {\n setTimeout(() => {\n profile('runDelayedWorklet', () => {\n runWorklet(worklet, params);\n });\n }, 0);\n } else {\n leftParamsVec.push(params);\n }\n });\n impl!._delayedWorkletParamsMap.set(\n worklet._wkltId,\n leftParamsVec,\n );\n });\n}\n\nfunction clearDelayedWorklets(): void {\n impl!._delayedWorkletParamsMap.clear();\n}\n\nexport { type EventDelayImpl, initEventDelay, delayExecUntilJsReady, runDelayedWorklet, clearDelayedWorklets };\n"]}
1
+ {"version":3,"file":"delayWorkletEvent.js","sourceRoot":"","sources":["../../src/worklet-runtime/delayWorkletEvent.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAS7C,SAAS,cAAc;IACrB,MAAM,QAAQ,GAAmB;QAC/B,wBAAwB,EAAE,IAAI,GAAG,EAAE;QACnC,qBAAqB,CACnB,IAAY,EACZ,MAA0B;YAE1B,OAAO,CAAC,yBAAyB,GAAG,IAAI,EAAE,GAAG,EAAE;gBAC7C,MAAM,GAAG,GAAG,QAAQ,CAAC,wBAAwB,CAAC;gBAC9C,MAAM,QAAQ,GAAG,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;gBAC/B,IAAI,QAAQ,EAAE,CAAC;oBACb,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;gBACxB,CAAC;qBAAM,CAAC;oBACN,GAAG,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC;gBAC1B,CAAC;YACH,CAAC,CAAC,CAAC;QACL,CAAC;QACD,iBAAiB,CAAC,OAAgB,EAAE,OAAoB;YACtD,OAAO,CAAC,sBAAsB,EAAE,GAAG,EAAE;gBACnC,MAAM,SAAS,GAAG,QAAQ,CAAC,wBAAwB,CAAC,GAAG,CACrD,OAAO,CAAC,OAAO,CAChB,CAAC;gBACF,IAAI,SAAS,KAAK,SAAS,EAAE,CAAC;oBAC5B,OAAO;gBACT,CAAC;gBACD,MAAM,aAAa,GAAyB,EAAE,CAAC;gBAC/C,SAAS,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,EAAE;oBAC3B,MAAM,UAAU,GAAG,MAAM,CAAC,CAAC,CAAoE,CAAC;oBAChG,IAAI,UAAU,EAAE,aAAa,EAAE,aAAa,KAAK,OAAO,EAAE,CAAC;wBACzD,UAAU,CAAC,GAAG,EAAE;4BACd,OAAO,CAAC,mBAAmB,EAAE,GAAG,EAAE;gCAChC,UAAU,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;4BAC9B,CAAC,CAAC,CAAC;wBACL,CAAC,EAAE,CAAC,CAAC,CAAC;oBACR,CAAC;yBAAM,CAAC;wBACN,aAAa,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;oBAC7B,CAAC;gBACH,CAAC,CAAC,CAAC;gBACH,QAAQ,CAAC,wBAAwB,CAAC,GAAG,CACnC,OAAO,CAAC,OAAO,EACf,aAAa,CACd,CAAC;YACJ,CAAC,CAAC,CAAC;QACL,CAAC;QACD,oBAAoB;YAClB,QAAQ,CAAC,wBAAwB,CAAC,KAAK,EAAE,CAAC;QAC5C,CAAC;KACF,CAAC;IACF,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED,OAAO,EAAuB,cAAc,EAAE,CAAC","sourcesContent":["// Copyright 2024 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\nimport type { ClosureValueType, Worklet } from './bindings/types.js';\nimport { profile } from './utils/profile.js';\n\ninterface EventDelayImpl {\n _delayedWorkletParamsMap: Map<string, ClosureValueType[][]>;\n delayExecUntilJsReady(hash: string, params: ClosureValueType[]): void;\n runDelayedWorklet(worklet: Worklet, element: ElementNode): void;\n clearDelayedWorklets(): void;\n}\n\nfunction initEventDelay(): EventDelayImpl {\n const instance: EventDelayImpl = {\n _delayedWorkletParamsMap: new Map(),\n delayExecUntilJsReady(\n hash: string,\n params: ClosureValueType[],\n ): void {\n profile('delayExecUntilJsReady: ' + hash, () => {\n const map = instance._delayedWorkletParamsMap;\n const paramVec = map.get(hash);\n if (paramVec) {\n paramVec.push(params);\n } else {\n map.set(hash, [params]);\n }\n });\n },\n runDelayedWorklet(worklet: Worklet, element: ElementNode): void {\n profile('commitDelayedWorklet', () => {\n const paramsVec = instance._delayedWorkletParamsMap.get(\n worklet._wkltId,\n );\n if (paramsVec === undefined) {\n return;\n }\n const leftParamsVec: ClosureValueType[][] = [];\n paramsVec.forEach((params) => {\n const firstParam = params[0] as { currentTarget?: { elementRefptr?: ElementNode } } | undefined;\n if (firstParam?.currentTarget?.elementRefptr === element) {\n setTimeout(() => {\n profile('runDelayedWorklet', () => {\n runWorklet(worklet, params);\n });\n }, 0);\n } else {\n leftParamsVec.push(params);\n }\n });\n instance._delayedWorkletParamsMap.set(\n worklet._wkltId,\n leftParamsVec,\n );\n });\n },\n clearDelayedWorklets(): void {\n instance._delayedWorkletParamsMap.clear();\n },\n };\n return instance;\n}\n\nexport { type EventDelayImpl, initEventDelay };\n"]}
@@ -1,8 +1,7 @@
1
1
  import type { ClosureValueType, Worklet } from './bindings/types.js';
2
- import type { RunOnBackgroundDelayImpl } from './delayRunOnBackground.js';
3
2
  import type { EventDelayImpl } from './delayWorkletEvent.js';
4
3
  import type { EomImpl } from './eomImpl.js';
5
- import type { JsFunctionLifecycleManager } from './jsFunctionLifecycle.js';
4
+ import type { JsFunctionLifecycleManager, RunOnBackgroundDelayImpl } from './run-on-background/index.js';
6
5
  import type { RefImpl } from './workletRef.js';
7
6
  declare global {
8
7
  var lynxWorkletImpl: {
@@ -1 +1 @@
1
- {"version":3,"file":"global.js","sourceRoot":"","sources":["../../src/worklet-runtime/global.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright 2024 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\nimport type { ClosureValueType, Worklet } from './bindings/types.js';\nimport type { RunOnBackgroundDelayImpl } from './delayRunOnBackground.js';\nimport type { EventDelayImpl } from './delayWorkletEvent.js';\nimport type { EomImpl } from './eomImpl.js';\nimport type { JsFunctionLifecycleManager } from './jsFunctionLifecycle.js';\nimport type { RefImpl } from './workletRef.js';\n\ndeclare global {\n var lynxWorkletImpl: {\n _workletMap: Record<string, (...args: unknown[]) => unknown>;\n _jsFunctionLifecycleManager?: JsFunctionLifecycleManager;\n // for pre-0.99 compatibility\n _eventDelayImpl: EventDelayImpl;\n _refImpl: RefImpl;\n _runOnBackgroundDelayImpl: RunOnBackgroundDelayImpl;\n _hydrateCtx: (worklet: Worklet, firstScreenWorklet: Worklet) => void;\n _eomImpl: EomImpl;\n _runRunOnMainThreadTask: (task: Worklet, params: ClosureValueType[], resolveId: number) => void;\n };\n\n function runWorklet(ctx: Worklet, params: ClosureValueType[]): unknown;\n\n function registerWorklet(type: string, id: string, worklet: (...args: unknown[]) => unknown): void;\n function registerWorkletInternal(type: string, id: string, worklet: (...args: unknown[]) => unknown): void;\n}\n"]}
1
+ {"version":3,"file":"global.js","sourceRoot":"","sources":["../../src/worklet-runtime/global.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright 2024 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\nimport type { ClosureValueType, Worklet } from './bindings/types.js';\nimport type { EventDelayImpl } from './delayWorkletEvent.js';\nimport type { EomImpl } from './eomImpl.js';\nimport type { JsFunctionLifecycleManager, RunOnBackgroundDelayImpl } from './run-on-background/index.js';\nimport type { RefImpl } from './workletRef.js';\n\ndeclare global {\n var lynxWorkletImpl: {\n _workletMap: Record<string, (...args: unknown[]) => unknown>;\n _jsFunctionLifecycleManager?: JsFunctionLifecycleManager;\n // for pre-0.99 compatibility\n _eventDelayImpl: EventDelayImpl;\n _refImpl: RefImpl;\n _runOnBackgroundDelayImpl: RunOnBackgroundDelayImpl;\n _hydrateCtx: (worklet: Worklet, firstScreenWorklet: Worklet) => void;\n _eomImpl: EomImpl;\n _runRunOnMainThreadTask: (task: Worklet, params: ClosureValueType[], resolveId: number) => void;\n };\n\n function runWorklet(ctx: Worklet, params: ClosureValueType[]): unknown;\n\n function registerWorklet(type: string, id: string, worklet: (...args: unknown[]) => unknown): void;\n function registerWorkletInternal(type: string, id: string, worklet: (...args: unknown[]) => unknown): void;\n}\n"]}
@@ -1,6 +1,7 @@
1
1
  // Copyright 2024 The Lynx Authors. All rights reserved.
2
2
  // Licensed under the Apache License Version 2.0 that can be found in the
3
3
  // LICENSE file in the root directory of this source tree.
4
+ import { hydrateJsFnHandles } from './run-on-background/index.js';
4
5
  import { profile } from './utils/profile.js';
5
6
  import { hydrateWorkletValue, isHydratedWorkletValue } from './workletRef.js';
6
7
  /**
@@ -38,7 +39,7 @@ function hydrateCtxImpl(ctx, firstScreenCtx, execId) {
38
39
  hydrateMainThreadRef(ctxObj[key], firstScreenCtxObj);
39
40
  }
40
41
  else if (key === '_jsFn') {
41
- hydrateDelayRunOnBackgroundTasks(ctxObj[key], firstScreenCtxObj[key], execId);
42
+ hydrateJsFnHandles(ctxObj[key], firstScreenCtxObj[key], execId);
42
43
  }
43
44
  else {
44
45
  const firstScreenValue = typeof firstScreenCtxObj[key] === 'function'
@@ -75,35 +76,4 @@ function hydrateWorkletValueHandle(handle, value) {
75
76
  }
76
77
  hydrateWorkletValue(handle, value);
77
78
  }
78
- /**
79
- * Hydrates delayed `runOnBackground` tasks.
80
- * This function ensures that any `runOnBackground` calls that were delayed
81
- * during the first-screen rendering are correctly associated with their
82
- * respective JavaScript function handles in the hydrated Worklet context.
83
- */
84
- function hydrateDelayRunOnBackgroundTasks(fnObjs, // example: {"_jsFn1":{"_jsFnId":1}}
85
- firstScreenFnObjs, // example: {"_jsFn1":{"_isFirstScreen":true,"_delayIndices":[0]}}
86
- execId) {
87
- for (const fnName in fnObjs) {
88
- const fnObj = fnObjs[fnName];
89
- const firstScreenFnObj = firstScreenFnObjs[fnName];
90
- if (!firstScreenFnObj?._delayIndices) {
91
- if (firstScreenFnObj) {
92
- firstScreenFnObj._isFirstScreen = false;
93
- firstScreenFnObj._execId = execId;
94
- Object.assign(firstScreenFnObj, fnObj);
95
- }
96
- continue;
97
- }
98
- for (const index of firstScreenFnObj._delayIndices) {
99
- const details = lynxWorkletImpl._runOnBackgroundDelayImpl
100
- .delayedBackgroundFunctionArray[index];
101
- if (!details) {
102
- continue;
103
- }
104
- fnObj._execId = execId;
105
- details.jsFnHandle = fnObj;
106
- }
107
- }
108
- }
109
79
  //# sourceMappingURL=hydrate.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"hydrate.js","sourceRoot":"","sources":["../../src/worklet-runtime/hydrate.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAU1D,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC7C,OAAO,EAAE,mBAAmB,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AAE9E;;;;;;;;GAQG;AACH,MAAM,UAAU,UAAU,CAAC,GAAY,EAAE,cAAuB;IAC9D,OAAO,CAAC,YAAY,EAAE,GAAG,EAAE;QACzB,cAAc,CAAC,GAAG,EAAE,cAAc,EAAE,GAAG,CAAC,OAAQ,CAAC,CAAC;IACpD,CAAC,CAAC,CAAC;AACL,CAAC;AAED,SAAS,cAAc,CACrB,GAAqB,EACrB,cAAgC,EAChC,MAAc;IAEd,IACE,CAAC,GAAG,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,CAAC,cAAc;WAC/C,OAAO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,OAAO,CAAC,UAAU,GAAG,KAAK,CAAC;QAC7B,CAAC;IACH,CAAC;AACH,CAAC","sourcesContent":["// Copyright 2024 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\nimport type {\n ClosureValueType,\n JsFnHandle,\n Worklet,\n WorkletRef,\n WorkletRefId,\n WorkletRefImpl,\n} from './bindings/index.js';\nimport { profile } from './utils/profile.js';\nimport { hydrateWorkletValue, isHydratedWorkletValue } from './workletRef.js';\n\n/**\n * Hydrates a Worklet context with data from a first-screen Worklet context.\n * This process is typically used to run all delayed `runOnBackground` functions\n * and initialize `WorkletRef` values modified before hydration.\n *\n * @param ctx The target Worklet context to be hydrated.\n * @param firstScreenCtx The Worklet context from the first screen rendering,\n * containing the data to hydrate with.\n */\nexport function hydrateCtx(ctx: Worklet, firstScreenCtx: Worklet): void {\n profile('hydrateCtx', () => {\n hydrateCtxImpl(ctx, firstScreenCtx, ctx._execId!);\n });\n}\n\nfunction hydrateCtxImpl(\n ctx: ClosureValueType,\n firstScreenCtx: ClosureValueType,\n execId: number,\n): void {\n if (\n !ctx || typeof ctx !== 'object' || !firstScreenCtx\n || typeof firstScreenCtx !== 'object'\n ) return;\n\n const ctxObj = ctx as Record<string, ClosureValueType>;\n const firstScreenCtxObj = firstScreenCtx as Record<string, ClosureValueType>;\n\n if (ctxObj['_wkltId'] && ctxObj['_wkltId'] !== firstScreenCtxObj['_wkltId']) {\n return;\n }\n\n // Typed handles (including `_type: 'main-thread'` mutable cells) hydrate\n // atomically without walking their initialization payload. Untyped legacy\n // refs continue through the existing `_wvid` path below.\n if (isTypedWorkletRefDescriptor(ctxObj)) {\n hydrateWorkletValueHandle(ctxObj, firstScreenCtxObj);\n return;\n }\n for (const key in ctx) {\n if (key === '_wvid') {\n hydrateMainThreadRef(\n ctxObj[key] as WorkletRefId,\n firstScreenCtxObj as unknown as WorkletRefImpl<unknown>,\n );\n } else if (key === '_jsFn') {\n hydrateDelayRunOnBackgroundTasks(\n ctxObj[key] as Record<string, JsFnHandle>,\n firstScreenCtxObj[key] as Record<string, JsFnHandle>,\n execId,\n );\n } else {\n const firstScreenValue = typeof firstScreenCtxObj[key] === 'function'\n ? (firstScreenCtxObj[key] as { boundCtx?: object }).boundCtx as ClosureValueType\n : firstScreenCtxObj[key];\n hydrateCtxImpl(ctxObj[key], firstScreenValue, execId);\n }\n }\n}\n\nfunction isTypedWorkletRefDescriptor(\n value: object,\n): value is WorkletRefImpl<unknown> {\n const descriptor = value as Partial<WorkletRefImpl<unknown>>;\n return typeof descriptor._wvid === 'number'\n && typeof descriptor._type === 'string';\n}\n\n/**\n * Hydrates a WorkletRef on the main thread.\n * This maps the positive-ID background handle to the target realized during\n * first-screen rendering, while leaving an unused first-screen handle alone.\n */\nfunction hydrateMainThreadRef(\n refId: WorkletRefId,\n value: WorkletRefImpl<unknown>,\n): void {\n if ('_initValue' in value) {\n return;\n }\n lynxWorkletImpl!._refImpl._workletRefMap[refId] = value as WorkletRef<unknown>;\n}\n\n/**\n * Hydrates a typed worklet handle on the main thread.\n * The target is the object or mutable cell realized from the matching first-screen handle.\n */\nfunction hydrateWorkletValueHandle(\n handle: WorkletRefImpl<unknown>,\n value: ClosureValueType,\n): void {\n if (!isHydratedWorkletValue(value)) {\n // The handle was not accessed during first-screen rendering.\n return;\n }\n hydrateWorkletValue(handle, value);\n}\n\n/**\n * Hydrates delayed `runOnBackground` tasks.\n * This function ensures that any `runOnBackground` calls that were delayed\n * during the first-screen rendering are correctly associated with their\n * respective JavaScript function handles in the hydrated Worklet context.\n */\nfunction hydrateDelayRunOnBackgroundTasks(\n fnObjs: Record<string, JsFnHandle>, // example: {\"_jsFn1\":{\"_jsFnId\":1}}\n firstScreenFnObjs: Record<string, JsFnHandle>, // example: {\"_jsFn1\":{\"_isFirstScreen\":true,\"_delayIndices\":[0]}}\n execId: number,\n) {\n for (const fnName in fnObjs) {\n const fnObj = fnObjs[fnName]!;\n const firstScreenFnObj: JsFnHandle | undefined = firstScreenFnObjs[fnName];\n if (!firstScreenFnObj?._delayIndices) {\n if (firstScreenFnObj) {\n firstScreenFnObj._isFirstScreen = false;\n firstScreenFnObj._execId = execId;\n Object.assign(firstScreenFnObj, fnObj);\n }\n continue;\n }\n for (const index of firstScreenFnObj._delayIndices) {\n const details = lynxWorkletImpl!._runOnBackgroundDelayImpl\n .delayedBackgroundFunctionArray[index];\n if (!details) {\n continue;\n }\n fnObj._execId = execId;\n details.jsFnHandle = fnObj;\n }\n }\n}\n"]}
1
+ {"version":3,"file":"hydrate.js","sourceRoot":"","sources":["../../src/worklet-runtime/hydrate.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAU1D,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAClE,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC7C,OAAO,EAAE,mBAAmB,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AAE9E;;;;;;;;GAQG;AACH,MAAM,UAAU,UAAU,CAAC,GAAY,EAAE,cAAuB;IAC9D,OAAO,CAAC,YAAY,EAAE,GAAG,EAAE;QACzB,cAAc,CAAC,GAAG,EAAE,cAAc,EAAE,GAAG,CAAC,OAAQ,CAAC,CAAC;IACpD,CAAC,CAAC,CAAC;AACL,CAAC;AAED,SAAS,cAAc,CACrB,GAAqB,EACrB,cAAgC,EAChC,MAAc;IAEd,IACE,CAAC,GAAG,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,CAAC,cAAc;WAC/C,OAAO,cAAc,KAAK,QAAQ;QACrC,OAAO;IAET,MAAM,MAAM,GAAG,GAAuC,CAAC;IACvD,MAAM,iBAAiB,GAAG,cAAkD,CAAC;IAE7E,IAAI,MAAM,CAAC,SAAS,CAAC,IAAI,MAAM,CAAC,SAAS,CAAC,KAAK,iBAAiB,CAAC,SAAS,CAAC,EAAE,CAAC;QAC5E,OAAO;IACT,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SAAS,yBAAyB,CAChC,MAA+B,EAC/B,KAAuB;IAEvB,IAAI,CAAC,sBAAsB,CAAC,KAAK,CAAC,EAAE,CAAC;QACnC,6DAA6D;QAC7D,OAAO;IACT,CAAC;IACD,mBAAmB,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;AACrC,CAAC","sourcesContent":["// Copyright 2024 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\nimport type {\n ClosureValueType,\n JsFnHandle,\n Worklet,\n WorkletRef,\n WorkletRefId,\n WorkletRefImpl,\n} from './bindings/index.js';\nimport { hydrateJsFnHandles } from './run-on-background/index.js';\nimport { profile } from './utils/profile.js';\nimport { hydrateWorkletValue, isHydratedWorkletValue } from './workletRef.js';\n\n/**\n * Hydrates a Worklet context with data from a first-screen Worklet context.\n * This process is typically used to run all delayed `runOnBackground` functions\n * and initialize `WorkletRef` values modified before hydration.\n *\n * @param ctx The target Worklet context to be hydrated.\n * @param firstScreenCtx The Worklet context from the first screen rendering,\n * containing the data to hydrate with.\n */\nexport function hydrateCtx(ctx: Worklet, firstScreenCtx: Worklet): void {\n profile('hydrateCtx', () => {\n hydrateCtxImpl(ctx, firstScreenCtx, ctx._execId!);\n });\n}\n\nfunction hydrateCtxImpl(\n ctx: ClosureValueType,\n firstScreenCtx: ClosureValueType,\n execId: number,\n): void {\n if (\n !ctx || typeof ctx !== 'object' || !firstScreenCtx\n || typeof firstScreenCtx !== 'object'\n ) return;\n\n const ctxObj = ctx as Record<string, ClosureValueType>;\n const firstScreenCtxObj = firstScreenCtx as Record<string, ClosureValueType>;\n\n if (ctxObj['_wkltId'] && ctxObj['_wkltId'] !== firstScreenCtxObj['_wkltId']) {\n return;\n }\n\n // Typed handles (including `_type: 'main-thread'` mutable cells) hydrate\n // atomically without walking their initialization payload. Untyped legacy\n // refs continue through the existing `_wvid` path below.\n if (isTypedWorkletRefDescriptor(ctxObj)) {\n hydrateWorkletValueHandle(ctxObj, firstScreenCtxObj);\n return;\n }\n for (const key in ctx) {\n if (key === '_wvid') {\n hydrateMainThreadRef(\n ctxObj[key] as WorkletRefId,\n firstScreenCtxObj as unknown as WorkletRefImpl<unknown>,\n );\n } else if (key === '_jsFn') {\n hydrateJsFnHandles(\n ctxObj[key] as Record<string, JsFnHandle>,\n firstScreenCtxObj[key] as Record<string, JsFnHandle>,\n execId,\n );\n } else {\n const firstScreenValue = typeof firstScreenCtxObj[key] === 'function'\n ? (firstScreenCtxObj[key] as { boundCtx?: object }).boundCtx as ClosureValueType\n : firstScreenCtxObj[key];\n hydrateCtxImpl(ctxObj[key], firstScreenValue, execId);\n }\n }\n}\n\nfunction isTypedWorkletRefDescriptor(\n value: object,\n): value is WorkletRefImpl<unknown> {\n const descriptor = value as Partial<WorkletRefImpl<unknown>>;\n return typeof descriptor._wvid === 'number'\n && typeof descriptor._type === 'string';\n}\n\n/**\n * Hydrates a WorkletRef on the main thread.\n * This maps the positive-ID background handle to the target realized during\n * first-screen rendering, while leaving an unused first-screen handle alone.\n */\nfunction hydrateMainThreadRef(\n refId: WorkletRefId,\n value: WorkletRefImpl<unknown>,\n): void {\n if ('_initValue' in value) {\n return;\n }\n lynxWorkletImpl!._refImpl._workletRefMap[refId] = value as WorkletRef<unknown>;\n}\n\n/**\n * Hydrates a typed worklet handle on the main thread.\n * The target is the object or mutable cell realized from the matching first-screen handle.\n */\nfunction hydrateWorkletValueHandle(\n handle: WorkletRefImpl<unknown>,\n value: ClosureValueType,\n): void {\n if (!isHydratedWorkletValue(value)) {\n // The handle was not accessed during first-screen rendering.\n return;\n }\n hydrateWorkletValue(handle, value);\n}\n"]}
@@ -0,0 +1,28 @@
1
+ import { JsFunctionLifecycleManager } from './lifecycle.js';
2
+ import type { JsFnHandle, Worklet } from '../bindings/types.js';
3
+ interface Details {
4
+ task: (fnId: number, execId: number) => void;
5
+ jsFnHandle?: JsFnHandle;
6
+ }
7
+ interface RunOnBackgroundDelayImpl {
8
+ delayedBackgroundFunctionArray: Array<Details | undefined>;
9
+ epoch: number;
10
+ hasHydrated: boolean;
11
+ clearDelayedBackgroundFunctions(): void;
12
+ delayRunOnBackground(fnObj: JsFnHandle, fn: (fnId: number, execId: number) => void): void;
13
+ runDelayedBackgroundFunctions(): void;
14
+ }
15
+ declare function initRunOnBackgroundDelay(): RunOnBackgroundDelayImpl;
16
+ /**
17
+ * Hydrates first-screen `JsFnHandle` placeholders and associates any queued
18
+ * pre-hydration `runOnBackground` tasks with their hydrated handles.
19
+ */
20
+ declare function hydrateJsFnHandles(fnObjs: Record<string, JsFnHandle>, // example: {"_jsFn1":{"_jsFnId":1}}
21
+ firstScreenFnObjs: Record<string, JsFnHandle>, // example: {"_jsFn1":{"_isFirstScreen":true,"_delayIndices":[0]}}
22
+ execId: number): void;
23
+ /**
24
+ * Binds and retains a captured `JsFnHandle` during worklet context transformation,
25
+ * skipping handles from retired reload epochs and preserving prebound `_execId`s.
26
+ */
27
+ declare function bindCapturedJsFnHandle(handle: JsFnHandle, rootCtx: Worklet): void;
28
+ export { type RunOnBackgroundDelayImpl, JsFunctionLifecycleManager, initRunOnBackgroundDelay, hydrateJsFnHandles, bindCapturedJsFnHandle, };
@@ -0,0 +1,103 @@
1
+ // Copyright 2024 The Lynx Authors. All rights reserved.
2
+ // Licensed under the Apache License Version 2.0 that can be found in the
3
+ // LICENSE file in the root directory of this source tree.
4
+ import { JsFunctionLifecycleManager } from './lifecycle.js';
5
+ function isStaleHydratedEpoch(handle, currentEpoch) {
6
+ return handle._hydratedEpoch !== undefined
7
+ && handle._hydratedEpoch !== (currentEpoch ?? lynxWorkletImpl._runOnBackgroundDelayImpl.epoch);
8
+ }
9
+ function initRunOnBackgroundDelay() {
10
+ const pendingHandles = new Set();
11
+ function clearPendingDelayIndices() {
12
+ for (const handle of pendingHandles) {
13
+ delete handle._delayIndices;
14
+ }
15
+ pendingHandles.clear();
16
+ }
17
+ const instance = {
18
+ delayedBackgroundFunctionArray: [],
19
+ epoch: 0,
20
+ hasHydrated: false,
21
+ clearDelayedBackgroundFunctions() {
22
+ instance.epoch++;
23
+ instance.hasHydrated = false;
24
+ clearPendingDelayIndices();
25
+ // PrimJS can keep truncated array storage alive; drop the consumed queue so
26
+ // its tasks and hydrated handles stop retaining their background executions.
27
+ instance.delayedBackgroundFunctionArray = [];
28
+ },
29
+ delayRunOnBackground(fnObj, task) {
30
+ if (instance.hasHydrated) {
31
+ return;
32
+ }
33
+ pendingHandles.add(fnObj);
34
+ instance.delayedBackgroundFunctionArray.push({ task });
35
+ const delayIndices = fnObj._delayIndices ??= [];
36
+ delayIndices.push(instance.delayedBackgroundFunctionArray.length - 1);
37
+ },
38
+ runDelayedBackgroundFunctions() {
39
+ const queue = instance.delayedBackgroundFunctionArray;
40
+ instance.delayedBackgroundFunctionArray = [];
41
+ instance.hasHydrated = true;
42
+ clearPendingDelayIndices();
43
+ for (const details of queue) {
44
+ if (details?.jsFnHandle) {
45
+ details.task(details.jsFnHandle._jsFnId, details.jsFnHandle._execId);
46
+ }
47
+ }
48
+ },
49
+ };
50
+ return instance;
51
+ }
52
+ /**
53
+ * Hydrates first-screen `JsFnHandle` placeholders and associates any queued
54
+ * pre-hydration `runOnBackground` tasks with their hydrated handles.
55
+ */
56
+ function hydrateJsFnHandles(fnObjs, // example: {"_jsFn1":{"_jsFnId":1}}
57
+ firstScreenFnObjs, // example: {"_jsFn1":{"_isFirstScreen":true,"_delayIndices":[0]}}
58
+ execId) {
59
+ const delayImpl = lynxWorkletImpl._runOnBackgroundDelayImpl;
60
+ const currentEpoch = delayImpl.epoch;
61
+ for (const fnName in fnObjs) {
62
+ const fnObj = fnObjs[fnName];
63
+ fnObj._execId = execId;
64
+ const firstScreenFnObj = firstScreenFnObjs[fnName];
65
+ if (!firstScreenFnObj) {
66
+ continue;
67
+ }
68
+ if (firstScreenFnObj._isFirstScreen || isStaleHydratedEpoch(firstScreenFnObj, currentEpoch)) {
69
+ Object.assign(firstScreenFnObj, fnObj);
70
+ firstScreenFnObj._isFirstScreen = false;
71
+ firstScreenFnObj._hydratedEpoch = currentEpoch;
72
+ lynxWorkletImpl._jsFunctionLifecycleManager?.addRef(execId, firstScreenFnObj);
73
+ }
74
+ const delayIndices = firstScreenFnObj._delayIndices;
75
+ if (!delayIndices) {
76
+ continue;
77
+ }
78
+ delete firstScreenFnObj._delayIndices;
79
+ for (const index of delayIndices) {
80
+ const details = delayImpl.delayedBackgroundFunctionArray[index];
81
+ if (!details) {
82
+ continue;
83
+ }
84
+ details.jsFnHandle = firstScreenFnObj;
85
+ }
86
+ }
87
+ }
88
+ /**
89
+ * Binds and retains a captured `JsFnHandle` during worklet context transformation,
90
+ * skipping handles from retired reload epochs and preserving prebound `_execId`s.
91
+ */
92
+ function bindCapturedJsFnHandle(handle, rootCtx) {
93
+ if (isStaleHydratedEpoch(handle)) {
94
+ return;
95
+ }
96
+ const targetExecId = handle._execId ?? rootCtx._execId;
97
+ if (targetExecId !== undefined) {
98
+ handle._execId = targetExecId;
99
+ lynxWorkletImpl._jsFunctionLifecycleManager?.addRef(targetExecId, handle);
100
+ }
101
+ }
102
+ export { JsFunctionLifecycleManager, initRunOnBackgroundDelay, hydrateJsFnHandles, bindCapturedJsFnHandle, };
103
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/worklet-runtime/run-on-background/index.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAC1D,OAAO,EAAE,0BAA0B,EAAE,MAAM,gBAAgB,CAAC;AAoB5D,SAAS,oBAAoB,CAC3B,MAAkB,EAClB,YAAqB;IAErB,OAAO,MAAM,CAAC,cAAc,KAAK,SAAS;WACrC,MAAM,CAAC,cAAc,KAAK,CAAC,YAAY,IAAI,eAAe,CAAC,yBAAyB,CAAC,KAAK,CAAC,CAAC;AACnG,CAAC;AAED,SAAS,wBAAwB;IAC/B,MAAM,cAAc,GAAG,IAAI,GAAG,EA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AAS;YACX,CAAC;YACD,OAAO,CAAC,UAAU,GAAG,gBAAgB,CAAC;QACxC,CAAC;IACH,CAAC;AACH,CAAC;AAED;;;GAGG;AACH,SAAS,sBAAsB,CAC7B,MAAkB,EAClB,OAAgB;IAEhB,IAAI,oBAAoB,CAAC,MAAM,CAAC,EAAE,CAAC;QACjC,OAAO;IACT,CAAC;IACD,MAAM,YAAY,GAAG,MAAM,CAAC,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC;IACvD,IAAI,YAAY,KAAK,SAAS,EAAE,CAAC;QAC/B,MAAM,CAAC,OAAO,GAAG,YAAY,CAAC;QAC9B,eAAe,CAAC,2BAA2B,EAAE,MAAM,CACjD,YAAY,EACZ,MAAM,CACP,CAAC;IACJ,CAAC;AACH,CAAC;AAED,OAAO,EAEL,0BAA0B,EAC1B,wBAAwB,EACxB,kBAAkB,EAClB,sBAAsB,GACvB,CAAC","sourcesContent":["// Copyright 2024 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\nimport { JsFunctionLifecycleManager } from './lifecycle.js';\nimport type { JsFnHandle, Worklet } from '../bindings/types.js';\n\ninterface Details {\n task: (fnId: number, execId: number) => void;\n\n // This comes from the background thread, inserted here during ctx hydration.\n jsFnHandle?: JsFnHandle;\n}\n\ninterface RunOnBackgroundDelayImpl {\n // Elements should keep the order being called by the user.\n delayedBackgroundFunctionArray: Array<Details | undefined>;\n epoch: number;\n hasHydrated: boolean;\n clearDelayedBackgroundFunctions(): void;\n delayRunOnBackground(fnObj: JsFnHandle, fn: (fnId: number, execId: number) => void): void;\n runDelayedBackgroundFunctions(): void;\n}\n\nfunction isStaleHydratedEpoch(\n handle: JsFnHandle,\n currentEpoch?: number,\n): boolean {\n return handle._hydratedEpoch !== undefined\n && handle._hydratedEpoch !== (currentEpoch ?? lynxWorkletImpl._runOnBackgroundDelayImpl.epoch);\n}\n\nfunction initRunOnBackgroundDelay(): RunOnBackgroundDelayImpl {\n const pendingHandles = new Set<JsFnHandle>();\n function clearPendingDelayIndices(): void {\n for (const handle of pendingHandles) {\n delete handle._delayIndices;\n }\n pendingHandles.clear();\n }\n const instance: RunOnBackgroundDelayImpl = {\n delayedBackgroundFunctionArray: [],\n epoch: 0,\n hasHydrated: false,\n clearDelayedBackgroundFunctions(): void {\n instance.epoch++;\n instance.hasHydrated = false;\n clearPendingDelayIndices();\n // PrimJS can keep truncated array storage alive; drop the consumed queue so\n // its tasks and hydrated handles stop retaining their background executions.\n instance.delayedBackgroundFunctionArray = [];\n },\n delayRunOnBackground(fnObj: JsFnHandle, task: (fnId: number, execId: number) => void): void {\n if (instance.hasHydrated) {\n return;\n }\n pendingHandles.add(fnObj);\n instance.delayedBackgroundFunctionArray.push({ task });\n const delayIndices = fnObj._delayIndices ??= [];\n delayIndices.push(instance.delayedBackgroundFunctionArray.length - 1);\n },\n runDelayedBackgroundFunctions(): void {\n const queue = instance.delayedBackgroundFunctionArray;\n instance.delayedBackgroundFunctionArray = [];\n instance.hasHydrated = true;\n clearPendingDelayIndices();\n for (const details of queue) {\n if (details?.jsFnHandle) {\n details.task(details.jsFnHandle._jsFnId!, details.jsFnHandle._execId!);\n }\n }\n },\n };\n return instance;\n}\n\n/**\n * Hydrates first-screen `JsFnHandle` placeholders and associates any queued\n * pre-hydration `runOnBackground` tasks with their hydrated handles.\n */\nfunction hydrateJsFnHandles(\n fnObjs: Record<string, JsFnHandle>, // example: {\"_jsFn1\":{\"_jsFnId\":1}}\n firstScreenFnObjs: Record<string, JsFnHandle>, // example: {\"_jsFn1\":{\"_isFirstScreen\":true,\"_delayIndices\":[0]}}\n execId: number,\n): void {\n const delayImpl = lynxWorkletImpl!._runOnBackgroundDelayImpl;\n const currentEpoch = delayImpl.epoch;\n for (const fnName in fnObjs) {\n const fnObj = fnObjs[fnName]!;\n fnObj._execId = execId;\n const firstScreenFnObj: JsFnHandle | undefined = firstScreenFnObjs[fnName];\n if (!firstScreenFnObj) {\n continue;\n }\n if (firstScreenFnObj._isFirstScreen || isStaleHydratedEpoch(firstScreenFnObj, currentEpoch)) {\n Object.assign(firstScreenFnObj, fnObj);\n firstScreenFnObj._isFirstScreen = false;\n firstScreenFnObj._hydratedEpoch = currentEpoch;\n lynxWorkletImpl!._jsFunctionLifecycleManager?.addRef(\n execId,\n firstScreenFnObj,\n );\n }\n const delayIndices = firstScreenFnObj._delayIndices;\n if (!delayIndices) {\n continue;\n }\n delete firstScreenFnObj._delayIndices;\n for (const index of delayIndices) {\n const details = delayImpl.delayedBackgroundFunctionArray[index];\n if (!details) {\n continue;\n }\n details.jsFnHandle = firstScreenFnObj;\n }\n }\n}\n\n/**\n * Binds and retains a captured `JsFnHandle` during worklet context transformation,\n * skipping handles from retired reload epochs and preserving prebound `_execId`s.\n */\nfunction bindCapturedJsFnHandle(\n handle: JsFnHandle,\n rootCtx: Worklet,\n): void {\n if (isStaleHydratedEpoch(handle)) {\n return;\n }\n const targetExecId = handle._execId ?? rootCtx._execId;\n if (targetExecId !== undefined) {\n handle._execId = targetExecId;\n lynxWorkletImpl._jsFunctionLifecycleManager?.addRef(\n targetExecId,\n handle,\n );\n }\n}\n\nexport {\n type RunOnBackgroundDelayImpl,\n JsFunctionLifecycleManager,\n initRunOnBackgroundDelay,\n hydrateJsFnHandles,\n bindCapturedJsFnHandle,\n};\n"]}
@@ -15,7 +15,7 @@ declare class JsFunctionLifecycleManager {
15
15
  addRef(execId: number, objToRef: object): void;
16
16
  removeRef(execId: number): void;
17
17
  dispose(): void;
18
+ recreate(): JsFunctionLifecycleManager;
18
19
  fire(): void;
19
20
  }
20
- declare function isRunOnBackgroundEnabled(): boolean;
21
- export { JsFunctionLifecycleManager, isRunOnBackgroundEnabled };
21
+ export { JsFunctionLifecycleManager };