@lynx-js/react 0.126.2 → 0.128.0

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 (425) hide show
  1. package/CHANGELOG.md +36 -0
  2. package/components/tsconfig.tsbuildinfo +1 -1
  3. package/docs/directives.md +90 -0
  4. package/docs/global-events.md +50 -0
  5. package/docs/import-attributes.md +43 -0
  6. package/docs/macros.md +285 -0
  7. package/package.json +7 -14
  8. package/refresh/.turbo/turbo-build.log +2 -2
  9. package/refresh/dist/index.js +26 -6
  10. package/refresh/package.json +1 -1
  11. package/runtime/__test__/core/main-thread-object.test.js +149 -0
  12. package/runtime/__test__/element-template/fixtures/background/main-thread-function/run-on-main-thread/index.tsx +26 -3
  13. package/runtime/__test__/element-template/imports/main-thread-object-api.test.ts +10 -0
  14. package/runtime/__test__/element-template/internal/legacy-internal-guardrail.test.ts +4 -1
  15. package/runtime/__test__/element-template/runtime/background/event/compiled-fixtures.test.tsx +39 -48
  16. package/runtime/__test__/element-template/runtime/background/main-thread-function/compiled-fixtures.test.tsx +11 -9
  17. package/runtime/__test__/element-template/runtime/render/render-transform.contract.test.ts +6 -3
  18. package/runtime/__test__/element-template/test-utils/mock/globals.js +6 -0
  19. package/runtime/__test__/element-template/vitest.config.ts +4 -0
  20. package/runtime/__test__/snapshot/ctxNotFound.test.ts +271 -0
  21. package/runtime/__test__/snapshot/event.test.jsx +7 -7
  22. package/runtime/__test__/snapshot/lazy.test.js +73 -1
  23. package/runtime/__test__/snapshot/lynx/portals.test.jsx +75 -37
  24. package/runtime/__test__/snapshot/snapshotPatch.test.jsx +59 -47
  25. package/runtime/__test__/snapshot/spread.test.jsx +10 -10
  26. package/runtime/__test__/snapshot/worklet/main-thread-object.test.jsx +306 -0
  27. package/runtime/__test__/snapshot/worklet/workletRef.test.jsx +1 -0
  28. package/runtime/__test__/worklet-runtime/initEntry.test.js +109 -0
  29. package/runtime/__test__/worklet-runtime/mainThreadObject.test.js +182 -0
  30. package/runtime/__test__/worklet-runtime/object-methods.test.js +59 -0
  31. package/runtime/__test__/worklet-runtime/workletRef.test.js +362 -2
  32. package/runtime/__test__/worklet-runtime/workletRuntime.test.js +246 -1
  33. package/runtime/lazy/compat.js +2 -0
  34. package/runtime/lazy/element-template-internal.js +1 -1
  35. package/runtime/lazy/element-template.js +2 -0
  36. package/runtime/lazy/internal.js +2 -1
  37. package/runtime/lazy/react.js +2 -0
  38. package/runtime/lib/core/background-function/exec-map.js.map +1 -1
  39. package/runtime/lib/core/background-function/handle.js.map +1 -1
  40. package/runtime/lib/core/background-function/run-on-background.d.ts +16 -0
  41. package/runtime/lib/core/background-function/run-on-background.js +16 -0
  42. package/runtime/lib/core/background-function/run-on-background.js.map +1 -1
  43. package/runtime/lib/core/capture-main-thread-object.d.ts +1 -0
  44. package/runtime/lib/core/capture-main-thread-object.js +16 -0
  45. package/runtime/lib/core/capture-main-thread-object.js.map +1 -0
  46. package/runtime/lib/core/commit-context.js.map +1 -1
  47. package/runtime/lib/core/compat/legacy-react-runtime.js.map +1 -1
  48. package/runtime/lib/core/compat/lynxComponent.js.map +1 -1
  49. package/runtime/lib/core/component.js.map +1 -1
  50. package/runtime/lib/core/forceRootRender.js.map +1 -1
  51. package/runtime/lib/core/globalProps.d.ts +2 -0
  52. package/runtime/lib/core/globalProps.js.map +1 -1
  53. package/runtime/lib/core/hooks/mainThread.js.map +1 -1
  54. package/runtime/lib/core/hooks/mainThreadImpl.js.map +1 -1
  55. package/runtime/lib/core/hooks/react.d.ts +4 -0
  56. package/runtime/lib/core/hooks/react.js +4 -0
  57. package/runtime/lib/core/hooks/react.js.map +1 -1
  58. package/runtime/lib/core/hooks/useLynxGlobalEventListener.d.ts +2 -0
  59. package/runtime/lib/core/hooks/useLynxGlobalEventListener.js +2 -0
  60. package/runtime/lib/core/hooks/useLynxGlobalEventListener.js.map +1 -1
  61. package/runtime/lib/core/initData.d.ts +2 -0
  62. package/runtime/lib/core/initData.js +2 -0
  63. package/runtime/lib/core/initData.js.map +1 -1
  64. package/runtime/lib/core/lynx/dynamic-import.js.map +1 -1
  65. package/runtime/lib/core/lynx/lazy-bundle.js.map +1 -1
  66. package/runtime/lib/core/lynx/runtime-backend.js.map +1 -1
  67. package/runtime/lib/core/lynx/runtime-version.js.map +1 -1
  68. package/runtime/lib/core/lynx-data-processors.js.map +1 -1
  69. package/runtime/lib/core/lynx-page-data.js.map +1 -1
  70. package/runtime/lib/core/lynx-update-data.js.map +1 -1
  71. package/runtime/lib/core/main-thread-function.js.map +1 -1
  72. package/runtime/lib/core/main-thread-object-handle-registry.d.ts +3 -0
  73. package/runtime/lib/core/main-thread-object-handle-registry.js +17 -0
  74. package/runtime/lib/core/main-thread-object-handle-registry.js.map +1 -0
  75. package/runtime/lib/core/main-thread-object.d.ts +77 -0
  76. package/runtime/lib/core/main-thread-object.js +258 -0
  77. package/runtime/lib/core/main-thread-object.js.map +1 -0
  78. package/runtime/lib/core/main-thread-ref-id.d.ts +1 -0
  79. package/runtime/lib/core/main-thread-ref-id.js +14 -0
  80. package/runtime/lib/core/main-thread-ref-id.js.map +1 -0
  81. package/runtime/lib/core/main-thread-ref-init-value.d.ts +1 -1
  82. package/runtime/lib/core/main-thread-ref-init-value.js +4 -2
  83. package/runtime/lib/core/main-thread-ref-init-value.js.map +1 -1
  84. package/runtime/lib/core/main-thread-ref.d.ts +4 -0
  85. package/runtime/lib/core/main-thread-ref.js +5 -8
  86. package/runtime/lib/core/main-thread-ref.js.map +1 -1
  87. package/runtime/lib/core/mts-capability.js.map +1 -1
  88. package/runtime/lib/core/performance.js.map +1 -1
  89. package/runtime/lib/core/ref.js.map +1 -1
  90. package/runtime/lib/core/reload-version.js.map +1 -1
  91. package/runtime/lib/core/runtime-destroy.js.map +1 -1
  92. package/runtime/lib/core/thread-function-call/main-thread.js.map +1 -1
  93. package/runtime/lib/core/thread-function-call/return-value.js.map +1 -1
  94. package/runtime/lib/document.js.map +1 -1
  95. package/runtime/lib/element-template/background/attr-slots.js.map +1 -1
  96. package/runtime/lib/element-template/background/commit-context.js.map +1 -1
  97. package/runtime/lib/element-template/background/commit-hook.js.map +1 -1
  98. package/runtime/lib/element-template/background/destroy.js.map +1 -1
  99. package/runtime/lib/element-template/background/document.js.map +1 -1
  100. package/runtime/lib/element-template/background/hydrate.js.map +1 -1
  101. package/runtime/lib/element-template/background/hydration-listener.js.map +1 -1
  102. package/runtime/lib/element-template/background/instance.js.map +1 -1
  103. package/runtime/lib/element-template/background/manager.js.map +1 -1
  104. package/runtime/lib/element-template/background/page-root-hydrate.js.map +1 -1
  105. package/runtime/lib/element-template/background/render-scope.js.map +1 -1
  106. package/runtime/lib/element-template/client/root.js.map +1 -1
  107. package/runtime/lib/element-template/debug/alog.js.map +1 -1
  108. package/runtime/lib/element-template/debug/elementPAPICall.js.map +1 -1
  109. package/runtime/lib/element-template/debug/profile.js.map +1 -1
  110. package/runtime/lib/element-template/hydration-map.js.map +1 -1
  111. package/runtime/lib/element-template/index.d.ts +2 -0
  112. package/runtime/lib/element-template/index.js +1 -0
  113. package/runtime/lib/element-template/index.js.map +1 -1
  114. package/runtime/lib/element-template/internal.d.ts +1 -1
  115. package/runtime/lib/element-template/internal.js +1 -1
  116. package/runtime/lib/element-template/internal.js.map +1 -1
  117. package/runtime/lib/element-template/jsx-dev-runtime/index.js.map +1 -1
  118. package/runtime/lib/element-template/jsx-runtime/index.js.map +1 -1
  119. package/runtime/lib/element-template/lynx/env.js.map +1 -1
  120. package/runtime/lib/element-template/lynx/performance.js.map +1 -1
  121. package/runtime/lib/element-template/native/callDestroyLifetimeFun.js.map +1 -1
  122. package/runtime/lib/element-template/native/index.js.map +1 -1
  123. package/runtime/lib/element-template/native/main-thread-api.js.map +1 -1
  124. package/runtime/lib/element-template/native/mts-destroy.js.map +1 -1
  125. package/runtime/lib/element-template/native/patch-listener.js.map +1 -1
  126. package/runtime/lib/element-template/native/reload-background.js.map +1 -1
  127. package/runtime/lib/element-template/native/reload-main-thread.js.map +1 -1
  128. package/runtime/lib/element-template/prop-adapters/event-value.js.map +1 -1
  129. package/runtime/lib/element-template/prop-adapters/event.js.map +1 -1
  130. package/runtime/lib/element-template/prop-adapters/ref.js.map +1 -1
  131. package/runtime/lib/element-template/prop-adapters/spread.js.map +1 -1
  132. package/runtime/lib/element-template/protocol/lifecycle-constant.js.map +1 -1
  133. package/runtime/lib/element-template/protocol/opcodes.js.map +1 -1
  134. package/runtime/lib/element-template/protocol/page.js.map +1 -1
  135. package/runtime/lib/element-template/protocol/template-type.js.map +1 -1
  136. package/runtime/lib/element-template/protocol/types.d.ts +1 -1
  137. package/runtime/lib/element-template/protocol/types.js.map +1 -1
  138. package/runtime/lib/element-template/protocol/update-event.js.map +1 -1
  139. package/runtime/lib/element-template/runtime/list/list.js.map +1 -1
  140. package/runtime/lib/element-template/runtime/page/authored-page.js.map +1 -1
  141. package/runtime/lib/element-template/runtime/page/page.js.map +1 -1
  142. package/runtime/lib/element-template/runtime/page/root-instance.js.map +1 -1
  143. package/runtime/lib/element-template/runtime/patch.js.map +1 -1
  144. package/runtime/lib/element-template/runtime/render/create-rendered-host.js.map +1 -1
  145. package/runtime/lib/element-template/runtime/render/host.js.map +1 -1
  146. package/runtime/lib/element-template/runtime/render/render-components.js.map +1 -1
  147. package/runtime/lib/element-template/runtime/render/render-direct.js.map +1 -1
  148. package/runtime/lib/element-template/runtime/render/render-main-thread.js.map +1 -1
  149. package/runtime/lib/element-template/runtime/template/attr-slot-plan.js.map +1 -1
  150. package/runtime/lib/element-template/runtime/template/handle.js.map +1 -1
  151. package/runtime/lib/element-template/runtime/template/main-thread-background-function.js.map +1 -1
  152. package/runtime/lib/element-template/runtime/template/main-thread-dynamic-attr-state.js.map +1 -1
  153. package/runtime/lib/element-template/runtime/template/main-thread-event-ctx.js.map +1 -1
  154. package/runtime/lib/element-template/runtime/template/main-thread-function.js.map +1 -1
  155. package/runtime/lib/element-template/runtime/template/main-thread-ref-ctx.js.map +1 -1
  156. package/runtime/lib/element-template/runtime/template/registry.js.map +1 -1
  157. package/runtime/lib/element-template/runtime/template/typed-attributes.js.map +1 -1
  158. package/runtime/lib/element-template/runtime-marker.js.map +1 -1
  159. package/runtime/lib/index.js.map +1 -1
  160. package/runtime/lib/internal.d.ts +1 -1
  161. package/runtime/lib/internal.js +1 -1
  162. package/runtime/lib/internal.js.map +1 -1
  163. package/runtime/lib/lynx-api.d.ts +34 -0
  164. package/runtime/lib/lynx-api.js +21 -0
  165. package/runtime/lib/lynx-api.js.map +1 -1
  166. package/runtime/lib/lynx.js +4 -1
  167. package/runtime/lib/lynx.js.map +1 -1
  168. package/runtime/lib/root.js.map +1 -1
  169. package/runtime/lib/runtime-marker.js.map +1 -1
  170. package/runtime/lib/shared/attribute-name.js.map +1 -1
  171. package/runtime/lib/shared/component-stack.js.map +1 -1
  172. package/runtime/lib/shared/index-map.js.map +1 -1
  173. package/runtime/lib/shared/profile.js.map +1 -1
  174. package/runtime/lib/shared/render-constants.js.map +1 -1
  175. package/runtime/lib/snapshot/alog/elementPAPICall.js.map +1 -1
  176. package/runtime/lib/snapshot/alog/index.js.map +1 -1
  177. package/runtime/lib/snapshot/alog/render.js.map +1 -1
  178. package/runtime/lib/snapshot/compat/componentIs.js.map +1 -1
  179. package/runtime/lib/snapshot/debug/debug.js.map +1 -1
  180. package/runtime/lib/snapshot/debug/describeInvalidValue.js.map +1 -1
  181. package/runtime/lib/snapshot/debug/formatPatch.js.map +1 -1
  182. package/runtime/lib/snapshot/debug/printSnapshot.js.map +1 -1
  183. package/runtime/lib/snapshot/debug/profileHooks.js.map +1 -1
  184. package/runtime/lib/snapshot/debug/vnodeSource.js.map +1 -1
  185. package/runtime/lib/snapshot/gesture/processGesture.js.map +1 -1
  186. package/runtime/lib/snapshot/gesture/processGestureBagkround.js.map +1 -1
  187. package/runtime/lib/snapshot/gesture/types.js.map +1 -1
  188. package/runtime/lib/snapshot/index.js.map +1 -1
  189. package/runtime/lib/snapshot/lifecycle/constant.js.map +1 -1
  190. package/runtime/lib/snapshot/lifecycle/destroy.js.map +1 -1
  191. package/runtime/lib/snapshot/lifecycle/event/delayEvents.js.map +1 -1
  192. package/runtime/lib/snapshot/lifecycle/event/delayLifecycleEvents.js.map +1 -1
  193. package/runtime/lib/snapshot/lifecycle/event/firstScreenSync.js.map +1 -1
  194. package/runtime/lib/snapshot/lifecycle/isRendering.js.map +1 -1
  195. package/runtime/lib/snapshot/lifecycle/patch/commit.js.map +1 -1
  196. package/runtime/lib/snapshot/lifecycle/patch/error.d.ts +11 -1
  197. package/runtime/lib/snapshot/lifecycle/patch/error.js +24 -16
  198. package/runtime/lib/snapshot/lifecycle/patch/error.js.map +1 -1
  199. package/runtime/lib/snapshot/lifecycle/patch/globalState.js.map +1 -1
  200. package/runtime/lib/snapshot/lifecycle/patch/isMainThreadHydrating.js.map +1 -1
  201. package/runtime/lib/snapshot/lifecycle/patch/nodesRefApply.js.map +1 -1
  202. package/runtime/lib/snapshot/lifecycle/patch/snapshotPatch.js.map +1 -1
  203. package/runtime/lib/snapshot/lifecycle/patch/snapshotPatchApply.d.ts +1 -1
  204. package/runtime/lib/snapshot/lifecycle/patch/snapshotPatchApply.js +29 -7
  205. package/runtime/lib/snapshot/lifecycle/patch/snapshotPatchApply.js.map +1 -1
  206. package/runtime/lib/snapshot/lifecycle/patch/updateMainThread.js +2 -2
  207. package/runtime/lib/snapshot/lifecycle/patch/updateMainThread.js.map +1 -1
  208. package/runtime/lib/snapshot/lifecycle/ref/delay.js.map +1 -1
  209. package/runtime/lib/snapshot/lifecycle/reload.js.map +1 -1
  210. package/runtime/lib/snapshot/lifecycle/render.js.map +1 -1
  211. package/runtime/lib/snapshot/list/list.js.map +1 -1
  212. package/runtime/lib/snapshot/list/listUpdateInfo.js.map +1 -1
  213. package/runtime/lib/snapshot/list/pendingListUpdates.js.map +1 -1
  214. package/runtime/lib/snapshot/lynx/calledByNative.js.map +1 -1
  215. package/runtime/lib/snapshot/lynx/children.d.ts +2 -0
  216. package/runtime/lib/snapshot/lynx/children.js.map +1 -1
  217. package/runtime/lib/snapshot/lynx/element.d.ts +8 -0
  218. package/runtime/lib/snapshot/lynx/element.js +4 -0
  219. package/runtime/lib/snapshot/lynx/element.js.map +1 -1
  220. package/runtime/lib/snapshot/lynx/env.js.map +1 -1
  221. package/runtime/lib/snapshot/lynx/injectLepusMethods.js.map +1 -1
  222. package/runtime/lib/snapshot/lynx/lazyBundleConstants.js.map +1 -1
  223. package/runtime/lib/snapshot/lynx/nodesRef.js.map +1 -1
  224. package/runtime/lib/snapshot/lynx/performance.js.map +1 -1
  225. package/runtime/lib/snapshot/lynx/portals.js.map +1 -1
  226. package/runtime/lib/snapshot/lynx/portalsPending.js.map +1 -1
  227. package/runtime/lib/snapshot/lynx/prepareLazyBundleMTS.js.map +1 -1
  228. package/runtime/lib/snapshot/lynx/runWithForce.js.map +1 -1
  229. package/runtime/lib/snapshot/lynx/suspense.js.map +1 -1
  230. package/runtime/lib/snapshot/lynx/tt.js.map +1 -1
  231. package/runtime/lib/snapshot/renderToOpcodes/hydrate.js.map +1 -1
  232. package/runtime/lib/snapshot/renderToOpcodes/index.js.map +1 -1
  233. package/runtime/lib/snapshot/renderToOpcodes/opcodes.js.map +1 -1
  234. package/runtime/lib/snapshot/snapshot/backgroundSnapshot.js.map +1 -1
  235. package/runtime/lib/snapshot/snapshot/constants.js.map +1 -1
  236. package/runtime/lib/snapshot/snapshot/definition.js.map +1 -1
  237. package/runtime/lib/snapshot/snapshot/dynamicPartType.js.map +1 -1
  238. package/runtime/lib/snapshot/snapshot/event.js.map +1 -1
  239. package/runtime/lib/snapshot/snapshot/gesture.js.map +1 -1
  240. package/runtime/lib/snapshot/snapshot/index.js.map +1 -1
  241. package/runtime/lib/snapshot/snapshot/list.js.map +1 -1
  242. package/runtime/lib/snapshot/snapshot/platformInfo.js.map +1 -1
  243. package/runtime/lib/snapshot/snapshot/reconstructInstanceTree.js.map +1 -1
  244. package/runtime/lib/snapshot/snapshot/ref.js.map +1 -1
  245. package/runtime/lib/snapshot/snapshot/snapshot.js.map +1 -1
  246. package/runtime/lib/snapshot/snapshot/snapshotCreatorMap.js.map +1 -1
  247. package/runtime/lib/snapshot/snapshot/snapshotInstanceHydrationMap.js.map +1 -1
  248. package/runtime/lib/snapshot/snapshot/snapshotInstanceManager.js.map +1 -1
  249. package/runtime/lib/snapshot/snapshot/spread.js.map +1 -1
  250. package/runtime/lib/snapshot/snapshot/types.js.map +1 -1
  251. package/runtime/lib/snapshot/snapshot/utils.js.map +1 -1
  252. package/runtime/lib/snapshot/snapshot/workletEvent.js.map +1 -1
  253. package/runtime/lib/snapshot/snapshot/workletRef.js.map +1 -1
  254. package/runtime/lib/snapshot/worklet/call/runOnMainThread.d.ts +2 -0
  255. package/runtime/lib/snapshot/worklet/call/runOnMainThread.js +2 -0
  256. package/runtime/lib/snapshot/worklet/call/runOnMainThread.js.map +1 -1
  257. package/runtime/lib/snapshot/worklet/ctx.js.map +1 -1
  258. package/runtime/lib/snapshot/worklet/destroy.js.map +1 -1
  259. package/runtime/lib/snapshot/worklet/functionality.js.map +1 -1
  260. package/runtime/lib/snapshot/worklet/hmr.js.map +1 -1
  261. package/runtime/lib/snapshot/worklet/ref/updateInitValue.js.map +1 -1
  262. package/runtime/lib/tsconfig.tsbuildinfo +1 -1
  263. package/runtime/lib/utils.js.map +1 -1
  264. package/runtime/lib/worklet-runtime/api/animation/animation.js.map +1 -1
  265. package/runtime/lib/worklet-runtime/api/animation/effect.js.map +1 -1
  266. package/runtime/lib/worklet-runtime/api/element.js.map +1 -1
  267. package/runtime/lib/worklet-runtime/api/lepusQuerySelector.js.map +1 -1
  268. package/runtime/lib/worklet-runtime/api/lynxApi.js.map +1 -1
  269. package/runtime/lib/worklet-runtime/bindings/bindings.d.ts +3 -3
  270. package/runtime/lib/worklet-runtime/bindings/bindings.js +9 -1
  271. package/runtime/lib/worklet-runtime/bindings/bindings.js.map +1 -1
  272. package/runtime/lib/worklet-runtime/bindings/events.js.map +1 -1
  273. package/runtime/lib/worklet-runtime/bindings/index.d.ts +0 -1
  274. package/runtime/lib/worklet-runtime/bindings/index.js +0 -1
  275. package/runtime/lib/worklet-runtime/bindings/index.js.map +1 -1
  276. package/runtime/lib/worklet-runtime/bindings/observers.js.map +1 -1
  277. package/runtime/lib/worklet-runtime/bindings/types.d.ts +3 -6
  278. package/runtime/lib/worklet-runtime/bindings/types.js.map +1 -1
  279. package/runtime/lib/worklet-runtime/delayRunOnBackground.js.map +1 -1
  280. package/runtime/lib/worklet-runtime/delayWorkletEvent.js.map +1 -1
  281. package/runtime/lib/worklet-runtime/eomImpl.js.map +1 -1
  282. package/runtime/lib/worklet-runtime/eventPropagation.js.map +1 -1
  283. package/runtime/lib/worklet-runtime/global.js.map +1 -1
  284. package/runtime/lib/worklet-runtime/hydrate.js +26 -7
  285. package/runtime/lib/worklet-runtime/hydrate.js.map +1 -1
  286. package/runtime/lib/worklet-runtime/index.js +6 -0
  287. package/runtime/lib/worklet-runtime/index.js.map +1 -1
  288. package/runtime/lib/worklet-runtime/jsFunctionLifecycle.js.map +1 -1
  289. package/runtime/lib/worklet-runtime/listeners.js.map +1 -1
  290. package/runtime/lib/worklet-runtime/mainThreadObject.d.ts +8 -0
  291. package/runtime/lib/worklet-runtime/mainThreadObject.js +67 -0
  292. package/runtime/lib/worklet-runtime/mainThreadObject.js.map +1 -0
  293. package/runtime/lib/worklet-runtime/runOnMainThread.js.map +1 -1
  294. package/runtime/lib/worklet-runtime/utils/mainThreadFlushLoopGuard.js.map +1 -1
  295. package/runtime/lib/worklet-runtime/utils/profile.js.map +1 -1
  296. package/runtime/lib/worklet-runtime/utils/version.js.map +1 -1
  297. package/runtime/lib/worklet-runtime/workletRef.d.ts +11 -7
  298. package/runtime/lib/worklet-runtime/workletRef.js +72 -9
  299. package/runtime/lib/worklet-runtime/workletRef.js.map +1 -1
  300. package/runtime/lib/worklet-runtime/workletRuntime.js +68 -9
  301. package/runtime/lib/worklet-runtime/workletRuntime.js.map +1 -1
  302. package/runtime/package.json +2 -3
  303. package/runtime/src/core/background-function/run-on-background.ts +16 -0
  304. package/runtime/src/core/capture-main-thread-object.ts +17 -0
  305. package/runtime/src/core/globalProps.ts +2 -0
  306. package/runtime/src/core/hooks/react.ts +4 -0
  307. package/runtime/src/core/hooks/useLynxGlobalEventListener.ts +2 -0
  308. package/runtime/src/core/initData.ts +2 -0
  309. package/runtime/src/core/main-thread-object-handle-registry.ts +25 -0
  310. package/runtime/src/core/main-thread-object.ts +380 -0
  311. package/runtime/src/core/main-thread-ref-id.ts +16 -0
  312. package/runtime/src/core/main-thread-ref-init-value.ts +12 -4
  313. package/runtime/src/core/main-thread-ref.ts +7 -8
  314. package/runtime/src/element-template/background/commit-hook.ts +1 -1
  315. package/runtime/src/element-template/index.ts +6 -0
  316. package/runtime/src/element-template/internal.ts +2 -1
  317. package/runtime/src/element-template/protocol/types.ts +1 -1
  318. package/runtime/src/internal.ts +1 -1
  319. package/runtime/src/lynx-api.ts +38 -0
  320. package/runtime/src/lynx.ts +5 -1
  321. package/runtime/src/snapshot/lifecycle/patch/error.ts +36 -19
  322. package/runtime/src/snapshot/lifecycle/patch/snapshotPatchApply.ts +29 -7
  323. package/runtime/src/snapshot/lifecycle/patch/updateMainThread.ts +2 -2
  324. package/runtime/src/snapshot/lynx/children.ts +2 -0
  325. package/runtime/src/snapshot/lynx/element.ts +8 -0
  326. package/runtime/src/snapshot/worklet/call/runOnMainThread.ts +2 -0
  327. package/runtime/src/snapshot/worklet/ref/updateInitValue.ts +1 -1
  328. package/runtime/src/worklet-runtime/bindings/bindings.ts +17 -2
  329. package/runtime/src/worklet-runtime/bindings/index.ts +0 -1
  330. package/runtime/src/worklet-runtime/bindings/types.ts +7 -11
  331. package/runtime/src/worklet-runtime/hydrate.ts +43 -10
  332. package/runtime/src/worklet-runtime/index.ts +7 -0
  333. package/runtime/src/worklet-runtime/mainThreadObject.ts +117 -0
  334. package/runtime/src/worklet-runtime/workletRef.ts +120 -19
  335. package/runtime/src/worklet-runtime/workletRuntime.ts +83 -11
  336. package/runtime/tsconfig.json +2 -0
  337. package/runtime/vitest.config.ts +4 -0
  338. package/testing-library/.turbo/turbo-build.log +11 -11
  339. package/testing-library/dist/env/index.js +3 -15
  340. package/testing-library/dist/index.d.ts +165 -2
  341. package/testing-library/dist/plugins/index.js +10 -0
  342. package/testing-library/dist/rstest-config.js +15 -0
  343. package/testing-library/dist/setupFiles/common/worklet-runtime-init.js +11 -0
  344. package/testing-library/package.json +2 -1
  345. package/testing-library/rstest.config.ts +3 -0
  346. package/testing-library/src/__tests__/lynx.test.jsx +1 -1
  347. package/testing-library/src/__tests__/rstest-config.test.js +34 -1
  348. package/testing-library/src/__tests__/worklet.test.jsx +87 -33
  349. package/testing-library/src/plugins/vitest.ts +5 -1
  350. package/testing-library/src/rstest-config.ts +17 -1
  351. package/testing-library/src/setupFiles/common/worklet-runtime-init.js +22 -0
  352. package/testing-library/tsconfig.docs.json +9 -0
  353. package/testing-library/typedoc.json +22 -0
  354. package/transform/.turbo/turbo-build$colon$wasm.log +135 -73
  355. package/transform/__test__/defines.spec.js +80 -12
  356. package/transform/__test__/fixture.spec.js +231 -71
  357. package/transform/__test__/object-methods.spec.js +82 -0
  358. package/transform/crates/swc_plugin_worklet/decl_collect.rs +10 -0
  359. package/transform/crates/swc_plugin_worklet/extract_ident.rs +14 -0
  360. package/transform/crates/swc_plugin_worklet/gen_stmt.rs +228 -13
  361. package/transform/crates/swc_plugin_worklet/lib.rs +599 -150
  362. package/transform/crates/swc_plugin_worklet/napi.rs +10 -1
  363. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_capture_env_js.js +8 -1
  364. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_capture_env_lepus.js +12 -7
  365. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_expose_object_method_capture_channels_js.js +27 -0
  366. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_expose_object_method_capture_channels_lepus.js +43 -0
  367. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_ident_from_this_lepus.js +2 -4
  368. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_2_js.js +16 -14
  369. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_2_lepus.js +18 -18
  370. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_3_lepus.js +3 -5
  371. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_4_lepus.js +2 -4
  372. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_js.js +7 -5
  373. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_lepus.js +9 -9
  374. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_not_capture_computed_object_method_key_lepus.js +22 -0
  375. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_not_capture_globals.js +2 -4
  376. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_not_capture_object_method_local_decls_lepus.js +14 -0
  377. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_not_capture_type_annotations.js +2 -4
  378. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_not_destructure_from_closure.js +2 -4
  379. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_not_extract_catch_clause_params.js +2 -4
  380. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_not_extract_idents_inside_of_ctx.js +2 -4
  381. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_not_transform_recursively.js +2 -4
  382. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_preserve_main_thread_objects_in_class_js.js +42 -0
  383. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_preserve_main_thread_objects_in_class_lepus.js +58 -0
  384. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_skip_shared_identifiers_lepus.js +2 -4
  385. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_arrow_function.js +2 -4
  386. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_fn_decl_lepus.js +2 -4
  387. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_function_expr.js +2 -4
  388. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_in_class_lepus.js +2 -4
  389. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_in_class_property_lepus.js +2 -4
  390. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_in_class_static_lepus.js +2 -4
  391. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_in_class_static_property_lepus.js +2 -4
  392. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_js.js +3 -1
  393. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_js_fn_in_run_on_js_lepus.js +2 -4
  394. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_lepus.js +5 -5
  395. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_lepus_alias.js +2 -4
  396. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_lepus_general.js +2 -4
  397. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_lepus_general_mixed.js +2 -4
  398. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_multiple_worklets.js +3 -5
  399. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_multiple_worklets_in_func.js +3 -5
  400. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_object_methods_js.js +9 -0
  401. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_object_methods_lepus.js +14 -0
  402. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_ui_worklet_lepus.js +2 -4
  403. package/transform/dist/wasm.cjs +1 -1
  404. package/transform/index.d.ts +25 -1
  405. package/transform/rspack-napi/tsconfig.tsbuildinfo +1 -1
  406. package/transform/src/lib.rs +193 -23
  407. package/transform/swc-plugin-reactlynx/.turbo/turbo-build.log +63 -467
  408. package/transform/swc-plugin-reactlynx/swc_plugin_reactlynx.wasm +0 -0
  409. package/transform/swc-plugin-reactlynx-compat/.turbo/turbo-build.log +340 -28
  410. package/transform/swc-plugin-reactlynx-compat/swc_plugin_reactlynx_compat.wasm +0 -0
  411. package/transform/vitest.config.ts +5 -1
  412. package/types/react.docs.d.ts +130 -11
  413. package/runtime/lib/worklet-runtime/bindings/loadRuntime.d.ts +0 -8
  414. package/runtime/lib/worklet-runtime/bindings/loadRuntime.js +0 -23
  415. package/runtime/lib/worklet-runtime/bindings/loadRuntime.js.map +0 -1
  416. package/runtime/src/worklet-runtime/bindings/loadRuntime.ts +0 -25
  417. package/runtime/worklet-runtime/dev.js +0 -638
  418. package/runtime/worklet-runtime/main.js +0 -1
  419. package/testing-library/node_modules/.bin/rsbuild +0 -68
  420. package/testing-library/node_modules/.bin/rspeedy +0 -68
  421. package/testing-library/node_modules/.bin/rstest +0 -68
  422. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_add_worklet_runtime_ident_with_inner_ident.js +0 -13
  423. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_add_worklet_runtime_ident_with_outer_ident.js +0 -13
  424. package/transform/node_modules/.bin/esbuild +0 -59
  425. package/transform/node_modules/.bin/napi +0 -68
@@ -1 +1 @@
1
- {"version":3,"file":"runtime-version.js","sourceRoot":"","sources":["../../../src/core/lynx/runtime-version.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D,MAAM,CAAC,MAAM,eAAe,GAAW,MAAM,CAAC,GAAG,CAAC,gCAAgC,CAAC,CAAC;AAEpF,SAAS,SAAS;IAChB,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,IAAI,CAAgD,CAAC;AACxF,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,sBAAsB,CAAC,OAA2B;IAChE,4EAA4E;IAC5E,8BAA8B;IAC9B,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,OAAO;IACT,CAAC;IAED,MAAM,MAAM,GAAG,SAAS,EAAE,CAAC;IAC3B,MAAM,cAAc,GAAG,MAAM,CAAC,eAAe,CAAuB,CAAC;IAErE,0EAA0E;IAC1E,uEAAuE;IACvE,uCAAuC;IACvC,6EAA6E;IAC7E,IAAI,MAAM,EAAE,CAAC;QACX,OAAO,CAAC,IAAI,EAAE,CACZ,oCAAoC,OAAO,GACzC,cAAc,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,sBAAsB,cAAc,EAC1E,EAAE,CACH,CAAC;IACJ,CAAC;IAED,2EAA2E;IAC3E,mEAAmE;IACnE,IAAI,cAAc,KAAK,SAAS,EAAE,CAAC;QACjC,OAAO;IACT,CAAC;IAED,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,eAAe,EAAE;QAC7C,KAAK,EAAE,OAAO;QACd,UAAU,EAAE,KAAK;QACjB,QAAQ,EAAE,KAAK;QACf,YAAY,EAAE,IAAI;KACnB,CAAC,CAAC;AACL,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,iBAAiB;IAC/B,OAAO,SAAS,EAAE,CAAC,eAAe,CAAuB,CAAC;AAC5D,CAAC"}
1
+ {"version":3,"file":"runtime-version.js","sourceRoot":"","sources":["../../../src/core/lynx/runtime-version.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D,MAAM,CAAC,MAAM,eAAe,GAAW,MAAM,CAAC,GAAG,CAAC,gCAAgC,CAAC,CAAC;AAEpF,SAAS,SAAS;IAChB,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,IAAI,CAAgD,CAAC;AACxF,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,sBAAsB,CAAC,OAA2B;IAChE,4EAA4E;IAC5E,8BAA8B;IAC9B,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,OAAO;IACT,CAAC;IAED,MAAM,MAAM,GAAG,SAAS,EAAE,CAAC;IAC3B,MAAM,cAAc,GAAG,MAAM,CAAC,eAAe,CAAuB,CAAC;IAErE,0EAA0E;IAC1E,uEAAuE;IACvE,uCAAuC;IACvC,6EAA6E;IAC7E,IAAI,MAAM,EAAE,CAAC;QACX,OAAO,CAAC,IAAI,EAAE,CACZ,oCAAoC,OAAO,GACzC,cAAc,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,sBAAsB,cAAc,EAC1E,EAAE,CACH,CAAC;IACJ,CAAC;IAED,2EAA2E;IAC3E,mEAAmE;IACnE,IAAI,cAAc,KAAK,SAAS,EAAE,CAAC;QACjC,OAAO;IACT,CAAC;IAED,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,eAAe,EAAE;QAC7C,KAAK,EAAE,OAAO;QACd,UAAU,EAAE,KAAK;QACjB,QAAQ,EAAE,KAAK;QACf,YAAY,EAAE,IAAI;KACnB,CAAC,CAAC;AACL,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,iBAAiB;IAC/B,OAAO,SAAS,EAAE,CAAC,eAAe,CAAuB,CAAC;AAC5D,CAAC","sourcesContent":["// Copyright 2026 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\nexport const sRuntimeVersion: symbol = Symbol.for('__REACT_LYNX_RUNTIME_VERSION__');\n\nfunction getTarget(): typeof globalThis & Record<symbol, unknown> {\n return (__LEPUS__ ? globalThis : lynx) as typeof globalThis & Record<symbol, unknown>;\n}\n\n/**\n * Record the `@lynx-js/react` runtime version compiled into this bundle.\n *\n * Every lazy bundle bundles its own copy of the `@lynx-js/react` runtime. The\n * host template is loaded first, so the first registration wins and the\n * recorded value reflects the host's runtime version. This function only\n * records the version so it is available for later inspection; it does not\n * compare versions or throw.\n */\nexport function registerRuntimeVersion(version: string | undefined): void {\n // Older versions of the build plugin do not stamp `__RUNTIME_VERSION__`, so\n // there is nothing to record.\n if (!version) {\n return;\n }\n\n const target = getTarget();\n const currentVersion = target[sRuntimeVersion] as string | undefined;\n\n // Log host and bundle versions so online reports can diagnose mismatches.\n // Only emit on the background thread — the main-thread copy would be a\n // duplicate report of the same values.\n // TODO: on repeated registration, compare and surface a compatibility check.\n if (__JS__) {\n console.alog?.(\n `[ReactLynx] new runtime version: ${version}${\n currentVersion === undefined ? '' : `, current version: ${currentVersion}`\n }`,\n );\n }\n\n // The host registers first; keep its version and let later lazy bundles be\n // no-ops so the recorded value always represents the host runtime.\n if (currentVersion !== undefined) {\n return;\n }\n\n Object.defineProperty(target, sRuntimeVersion, {\n value: version,\n enumerable: false,\n writable: false,\n configurable: true,\n });\n}\n\n/**\n * Read the `@lynx-js/react` runtime version recorded by the host template, or\n * `undefined` when the host was built by a plugin that does not stamp it.\n */\nexport function getRuntimeVersion(): string | undefined {\n return getTarget()[sRuntimeVersion] as string | undefined;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"lynx-data-processors.js","sourceRoot":"","sources":["../../src/core/lynx-data-processors.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAEhE,qFAAqF;AACrF,sFA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A+B,GAAG,IAAI,CAAC;QACzC,CAAC;QAED,OAAO,MAAM,CAAC;IAChB,CAAC,CAAC;AACJ,CAAC;AAED,SAAS,sBAAsB,CAAC,MAA8B;IAC5D,iDAAiD;IACjD,MAAM,uBAAuB,GAAY,UAAU,CAAC,6BAA6B,CAAC;IAClF,IAAI,uBAAuB,EAAE,CAAC;QAC5B,MAAM,GAAG;YACP,GAAG,MAAM;YACT,6BAA6B,EAAE,uBAAuB;SACvD,CAAC;IACJ,CAAC;IAED,sDAAsD;IACtD,IAAI,eAAe,EAAE,CAAC;QACpB,sDAAsD;QACtD,MAAM,mBAAmB,GAAY,0BAA0B,CAAC;QAChE,MAAM,GAAG;YACP,GAAG,MAAM;YACT,YAAY,EAAE,mBAAmB;SAClC,CAAC;IACJ,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
1
+ {"version":3,"file":"lynx-data-processors.js","sourceRoot":"","sources":["../../src/core/lynx-data-processors.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAEhE,qFAAqF;AACrF,sFAAsF;AACtF,qFAAqF;AACrF,mFAAmF;AACnF,oFAAoF;AACpF,2DAA2D;AAC3D,IAAI,qBAAqB,GAAG,KAAK,CAAC;AAElC,MAAM,UAAU,uBAAuB;IACrC,OAAO,qBAAqB,CAAC;AAC/B,CAAC;AAED,MAAM,UAAU,iBAAiB,CAC/B,uBAAiD;IAEjD,IAAI,+BAA+B,GAAG,KAAK,CAAC;IAE5C,OAAO,CAAC,IAAI,EAAE,aAAa,EAAE,EAAE;QAC7B,IAAI,OAAO,WAAW,KAAK,WAAW,IAAI,WAAW,EAAE,CAAC;YACtD,YAAY,CAAC,aAAa,CAAC,CAAC;QAC9B,CAAC;QAED,IAAI,MAA8B,CAAC;QACnC,IAAI,CAAC;YACH,IAAI,aAAa,EAAE,CAAC;gBAClB,MAAM,GAAG,uBAAuB,EAAE,cAAc,EAAE,CAAC,a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ent":["// 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 { DataProcessorDefinition, InitData, InitDataRaw } from '../lynx-api.js';\nimport { profileEnd, profileStart } from '../shared/profile.js';\n\n// `true` only while the default data processor is running. `defaultDataProcessor` is\n// invoked by the native side as a separate call *before* `renderPage` / `updatePage`,\n// so a `markFirstScreenSyncReady()` made inside it must not sync the *previous* tree\n// (still latched ready) — a re-render of the data being processed is imminent. The\n// first-screen sync backend reads this to defer such a mark. Lives here (not in the\n// backend) so `core` does not depend on a runtime backend.\nlet processingDefaultData = false;\n\nexport function isProcessingDefaultData(): boolean {\n return processingDefaultData;\n}\n\nexport function createProcessData(\n dataProcessorDefinition?: DataProcessorDefinition,\n): (data: InitDataRaw, processorName?: string) => InitData | InitDataRaw {\n let hasDefaultDataProcessorExecuted = false;\n\n return (data, processorName) => {\n if (typeof __PROFILE__ !== 'undefined' && __PROFILE__) {\n profileStart('processData');\n }\n\n let result: InitData | InitDataRaw;\n try {\n if (processorName) {\n result = dataProcessorDefinition?.dataProcessors?.[processorName]?.(data) as InitData ?? data;\n } else {\n // a `markFirstScreenSyncReady()` made inside `defaultDataProcessor` must be\n // deferred until the data being processed renders (see `processingDefaultData`)\n processingDefaultData = true;\n try {\n result = dataProcessorDefinition?.defaultDataProcessor?.(data) ?? data;\n } finally {\n processingDefaultData = false;\n }\n }\n } catch (error: unknown) {\n lynx.reportError(error as Error);\n result = {};\n }\n\n if (typeof __PROFILE__ !== 'undefined' && __PROFILE__) {\n profileEnd();\n }\n\n if (!hasDefaultDataProcessorExecuted) {\n result = appendInitDataMetadata(result);\n }\n\n if (!processorName) {\n hasDefaultDataProcessorExecuted = true;\n }\n\n return result;\n };\n}\n\nfunction appendInitDataMetadata(result: InitData | InitDataRaw): InitData | InitDataRaw {\n // @ts-expect-error todo: add types to i18n logic\n const i18nResourceTranslation: unknown = globalThis.__I18N_RESOURCE_TRANSLATION__;\n if (i18nResourceTranslation) {\n result = {\n ...result,\n __I18N_RESOURCE_TRANSLATION__: i18nResourceTranslation,\n };\n }\n\n // @ts-expect-error todo: add types to __EXTRACT_STR__\n if (__EXTRACT_STR__) {\n // @ts-expect-error todo: add types to __EXTRACT_STR__\n const extractStrIdentFlag: unknown = __EXTRACT_STR_IDENT_FLAG__;\n result = {\n ...result,\n _EXTRACT_STR: extractStrIdentFlag,\n };\n }\n\n return result;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"lynx-page-data.js","sourceRoot":"","sources":["../../src/core/lynx-page-data.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAC1D,OAAO,EAAE,mCAAmC,EAAE,2BAA2B,EAAE,MAAM,eAAe,CAAC;AACjG,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C,IAAI,mCAAmC,GAAG,KAAK,CAAC;AAEhD,MAAM,UAAU,mBAAmB,CAAC,IAAa,EAAE,OAAiD;IAClG,IAAI,OAAO,EAAE,aAAa,EAAE,CAAC;QAC3B,IAAI,OAAO,IAAI,CAAC,mCAAmC,IAAI,2BAA2B,EAAE,EAAE,CAAC;YACrF,mCAAmC,GAAG,IAAI,CAAC;YAC3C,IAAI,CAAC,WAAW,CAAC,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAC,CAAC;QACnE,CAAC;QACD,IAAI,CAAC,UAAU,GAAG,EAAE,CAAC;IACvB,CAAC;IAED,IAAI,OAAO,IAAI,IAAI,QAAQ,IAAI,IAAI,KAAK,IAAI,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,EAAE,CAAC;QACrE,IAAI,CAAC,UAAU,KAAK,EAAE,CAAC;QACvB,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;IACvC,CAAC;AACH,CAAC"}
1
+ {"version":3,"file":"lynx-page-data.js","sourceRoot":"","sources":["../../src/core/lynx-page-data.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAC1D,OAAO,EAAE,mCAAmC,EAAE,2BAA2B,EAAE,MAAM,eAAe,CAAC;AACjG,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C,IAAI,mCAAmC,GAAG,KAAK,CAAC;AAEhD,MAAM,UAAU,mBAAmB,CAAC,IAAa,EAAE,OAAiD;IAClG,IAAI,OAAO,EAAE,aAAa,EAAE,CAAC;QAC3B,IAAI,OAAO,IAAI,CAAC,mCAAmC,IAAI,2BAA2B,EAAE,EAAE,CAAC;YACrF,mCAAmC,GAAG,IAAI,CAAC;YAC3C,IAAI,CAAC,WAAW,CAAC,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAC,CAAC;QACnE,CAAC;QACD,IAAI,CAAC,UAAU,GAAG,EAAE,CAAC;IACvB,CAAC;IAED,IAAI,OAAO,IAAI,IAAI,QAAQ,IAAI,IAAI,KAAK,IAAI,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,EAAE,CAAC;QACrE,IAAI,CAAC,UAAU,KAAK,EAAE,CAAC;QACvB,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;IACvC,CAAC;AACH,CAAC","sourcesContent":["// Copyright 2026 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 { RESET_WITH_INIT_DATA_IN_STATE_ERROR, hasWithInitDataInStateUsage } from './initData.js';\nimport { isEmptyObject } from '../utils.js';\n\nlet hasReportedResetWithInitDataInState = false;\n\nexport function applyUpdatePageData(data: unknown, options?: Pick<UpdatePageOption, 'resetPageData'>): void {\n if (options?.resetPageData) {\n if (__DEV__ && !hasReportedResetWithInitDataInState && hasWithInitDataInStateUsage()) {\n hasReportedResetWithInitDataInState = true;\n lynx.reportError(new Error(RESET_WITH_INIT_DATA_IN_STATE_ERROR));\n }\n lynx.__initData = {};\n }\n\n if (typeof data == 'object' && data !== null && !isEmptyObject(data)) {\n lynx.__initData ??= {};\n Object.assign(lynx.__initData, data);\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"lynx-update-data.js","sourceRoot":"","sources":["../../src/core/lynx-update-data.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAC1D,OAAO,EAAE,mCAAmC,EAAE,2BAA2B,EAAE,MAAM,eAAe,CAAC;AAEjG,IAAI,mCAAmC,GAAG,KAAK,CAAC;AAEhD,MAAM,CAAC,MAAM,oBAAoB,GAAG;IAClC,MAAM,EAAE,CAAC;IACT,KAAK,EAAE,CAAC;CACA,CAAC;AAUX,MAAM,UAAU,cAAc,CAC5B,OAAsB,EACtB,OAAiC;IAEjC,MAAM,EAAE,CAAC,oBAAoB,CAAC,EAAE,qBAAqB,EAAE,GAAG,WAAW,EAAE,GAAG,OAAO,CAAC;IAClF,IAAI,qBAAqB,EAAE,CAAC;QAC1B,IAAI,CAAC,WAAW,CACd,IAAI,KAAK,CACP,uEAAuE,qBAAqB,gCAAgC,CAC7H,CACF,CAAC;IACJ,CAAC;IAED,MAAM,EAAE,IAAI,GAAG,oBAAoB,CAAC,MAAM,EAAE,GAAG,OAAO,IAAI,EAAE,CAAC;IAC7D,IAAI,IAAI,IAAI,oBAAoB,CAAC,KAAK,EAAE,CAAC;QACvC,IAAI,OAAO,IAAI,CAAC,mCAAmC,IAAI,2BAA2B,EAAE,EAAE,CAAC;YACrF,mCAAmC,GAAG,IAAI,CAAC;YAC3C,IAAI,CAAC,WAAW,CAAC,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAC,CAAC;QACnE,CAAC;QACD,IAAI,CAAC,UAAU,GAAG,EAAE,CAAC;IACvB,CAAC;IAED,iFAAiF;IACjF,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,IAAI,CAAC,UAAU,EAAE,WAAW,CAAC,CAA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C,CAAC;IAElE,IAAI,CAAC,WAAW,CAAC,oBAAoB,CAAC,CAAC,IAAI,CAAC,eAAe,EAAE,CAAC,WAAW,CAAC,CAAC,CAAC;AAC9E,CAAC","sourcesContent":["// Copyright 2026 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 { RESET_WITH_INIT_DATA_IN_STATE_ERROR, hasWithInitDataInStateUsage } from './initData.js';\n\nlet hasReportedResetWithInitDataInState = false;\n\nexport const NativeUpdateDataType = {\n UPDATE: 0,\n RESET: 1,\n} as const;\n\nexport type NativeUpdateDataType = (typeof NativeUpdateDataType)[keyof typeof NativeUpdateDataType];\n\nexport interface NativeUpdateDataOptions {\n type?: NativeUpdateDataType | undefined;\n}\n\ntype InitDataPatch = Record<string, any>;\n\nexport function updateCardData(\n newData: InitDataPatch,\n options?: NativeUpdateDataOptions,\n): void {\n const { ['__lynx_timing_flag']: performanceTimingFlag, ...restNewData } = newData;\n if (performanceTimingFlag) {\n lynx.reportError(\n new Error(\n `Received unsupported updateData with \\`__lynx_timing_flag\\` (value \"${performanceTimingFlag}\"), the timing flag is ignored`,\n ),\n );\n }\n\n const { type = NativeUpdateDataType.UPDATE } = options ?? {};\n if (type == NativeUpdateDataType.RESET) {\n if (__DEV__ && !hasReportedResetWithInitDataInState && hasWithInitDataInStateUsage()) {\n hasReportedResetWithInitDataInState = true;\n lynx.reportError(new Error(RESET_WITH_INIT_DATA_IN_STATE_ERROR));\n }\n lynx.__initData = {};\n }\n\n // COW keeps provider/consumer readers aligned with Snapshot updateData behavior.\n lynx.__initData = Object.assign({}, lynx.__initData, restNewData);\n\n lynx.getJSModule('GlobalEventEmitter').emit('onDataChanged', [restNewData]);\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"main-thread-function.js","sourceRoot":"","sources":["../../src/core/main-thread-function.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAI1D,MAAM,UAAU,oBAAoB,CAAC,KAAc;IACjD,OAAO,KAAK,IAAI,IAAI;WACf,OAAO,KAAK,KAAK,QAAQ;WACzB,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;WACrB,OAAQ,KAA+B,CAAC,OAAO,KAAK,QAAQ,CAAC;AACpE,CAAC"}
1
+ {"version":3,"file":"main-thread-function.js","sourceRoot":"","sources":["../../src/core/main-thread-function.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAI1D,MAAM,UAAU,oBAAoB,CAAC,KAAc;IACjD,OAAO,KAAK,IAAI,IAAI;WACf,OAAO,KAAK,KAAK,QAAQ;WACzB,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;WACrB,OAAQ,KAA+B,CAAC,OAAO,KAAK,QAAQ,CAAC;AACpE,CAAC","sourcesContent":["// Copyright 2026 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 { Worklet } from '../worklet-runtime/bindings/types.js';\n\nexport function isMainThreadFunction(value: unknown): value is Worklet {\n return value != null\n && typeof value === 'object'\n && !Array.isArray(value)\n && typeof (value as { _wkltId?: unknown })._wkltId === 'string';\n}\n"]}
@@ -0,0 +1,3 @@
1
+ export declare function registerMainThreadObjectHandle(handle: object, type: string): void;
2
+ export declare function isMainThreadObjectHandle(value: unknown): value is object;
3
+ export declare function getMainThreadObjectHandleType(value: unknown): string | undefined;
@@ -0,0 +1,17 @@
1
+ // Copyright 2026 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
+ let mainThreadObjectHandleTypes;
5
+ export function registerMainThreadObjectHandle(handle, type) {
6
+ (mainThreadObjectHandleTypes ??= new WeakMap()).set(handle, type);
7
+ }
8
+ export function isMainThreadObjectHandle(value) {
9
+ return typeof value === 'object' && value !== null
10
+ && mainThreadObjectHandleTypes?.has(value) === true;
11
+ }
12
+ export function getMainThreadObjectHandleType(value) {
13
+ return typeof value === 'object' && value !== null
14
+ ? mainThreadObjectHandleTypes?.get(value)
15
+ : undefined;
16
+ }
17
+ //# sourceMappingURL=main-thread-object-handle-registry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"main-thread-object-handle-registry.js","sourceRoot":"","sources":["../../src/core/main-thread-object-handle-registry.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D,IAAI,2BAAgE,CAAC;AAErE,MAAM,UAAU,8BAA8B,CAC5C,MAAc,EACd,IAAY;IAEZ,CAAC,2BAA2B,KAAK,IAAI,OAAO,EAAE,CAAC,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;AACpE,CAAC;AAED,MAAM,UAAU,wBAAwB,CAAC,KAAc;IACrD,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI;WAC7C,2BAA2B,EAAE,GAAG,CAAC,KAAK,CAAC,KAAK,IAAI,CAAC;AACxD,CAAC;AAED,MAAM,UAAU,6BAA6B,CAC3C,KAAc;IAEd,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI;QAChD,CAAC,CAAC,2BAA2B,EAAE,GAAG,CAAC,KAAK,CAAC;QACzC,CAAC,CAAC,SAAS,CAAC;AAChB,CAAC","sourcesContent":["// Copyright 2026 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\nlet mainThreadObjectHandleTypes: WeakMap<object, string> | undefined;\n\nexport function registerMainThreadObjectHandle(\n handle: object,\n type: string,\n): void {\n (mainThreadObjectHandleTypes ??= new WeakMap()).set(handle, type);\n}\n\nexport function isMainThreadObjectHandle(value: unknown): value is object {\n return typeof value === 'object' && value !== null\n && mainThreadObjectHandleTypes?.has(value) === true;\n}\n\nexport function getMainThreadObjectHandleType(\n value: unknown,\n): string | undefined {\n return typeof value === 'object' && value !== null\n ? mainThreadObjectHandleTypes?.get(value)\n : undefined;\n}\n"]}
@@ -0,0 +1,77 @@
1
+ /**
2
+ * Describes how a serializable initialization payload becomes a stable object
3
+ * in the main-thread runtime.
4
+ *
5
+ * @public
6
+ */
7
+ export interface MainThreadObjectTypeDefinition<I, O extends object> {
8
+ /** A globally unique and stable type key. */
9
+ readonly type: string;
10
+ /**
11
+ * Create the realized main-thread object.
12
+ *
13
+ * This must be a capture-free Main Thread Function. Imports used by the
14
+ * function must come from shared-runtime modules.
15
+ */
16
+ readonly create: (initialValue: I) => O;
17
+ }
18
+ /**
19
+ * An immutable MainThreadObject type token with source-handle inspection.
20
+ *
21
+ * The factory function belongs to the input definition and is not exposed
22
+ * by the returned token. In the background runtime they compile to opaque
23
+ * Main Thread Function descriptors rather than bundling their implementation.
24
+ *
25
+ * @public
26
+ */
27
+ export interface MainThreadObjectType<I, O extends object> {
28
+ /** A globally unique and stable type key. */
29
+ readonly type: string;
30
+ /**
31
+ * Narrow a value to a source-runtime handle of this exact type.
32
+ *
33
+ * This does not create or access the realized main-thread object.
34
+ */
35
+ readonly downcast: (value: unknown) => MainThreadObjectHandle<I, O> | undefined;
36
+ }
37
+ /**
38
+ * An opaque source-runtime handle for an object realized on the main thread.
39
+ *
40
+ * A handle has logical identity and is serializable, but it is not the target
41
+ * object or an RPC stub. Capturing it in a main-thread function resolves it to
42
+ * the corresponding local target object. Development builds may wrap the
43
+ * background handle in a throwing guard solely to diagnose invalid access;
44
+ * that guard never forwards operations between runtimes.
45
+ *
46
+ * @public
47
+ */
48
+ export declare abstract class MainThreadObjectHandle<I, O extends object> {
49
+ /**
50
+ * The payload used to create the realized object.
51
+ *
52
+ * Readonly is a TypeScript contract; the value is not frozen at runtime.
53
+ */
54
+ get creationPayload(): Readonly<I>;
55
+ }
56
+ /**
57
+ * Define a main-thread object type for use by a library-provided hook.
58
+ *
59
+ * @param definition - Stable type key and target-object factory function.
60
+ * @returns An immutable object type definition.
61
+ * @public
62
+ */
63
+ export declare function defineMainThreadObjectType<I, O extends object>(definition: MainThreadObjectTypeDefinition<I, O>): MainThreadObjectType<I, O>;
64
+ /**
65
+ * Create a stable handle that resolves to an object of the supplied type in
66
+ * main-thread functions.
67
+ *
68
+ * This primitive is intended for library hooks. The returned target type is
69
+ * only callable in a main-thread function; it must not be used from the
70
+ * background runtime.
71
+ *
72
+ * @param objectType - Definition used to realize the target object.
73
+ * @param initialValue - JSON-serializable initialization payload.
74
+ * @returns The main-thread-only target type.
75
+ * @public
76
+ */
77
+ export declare function useMainThreadObject<I, O extends object>(objectType: MainThreadObjectType<I, O>, initialValue: I): O;
@@ -0,0 +1,258 @@
1
+ // Copyright 2026 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 { WorkletEvents, registerMainThreadObjectType } from '@lynx-js/react/worklet-runtime/bindings';
5
+ import { useMemo } from './hooks/react.js';
6
+ import { getMainThreadObjectHandleType, registerMainThreadObjectHandle } from './main-thread-object-handle-registry.js';
7
+ import { allocateMainThreadRefId } from './main-thread-ref-id.js';
8
+ import { addMainThreadRefInitValue } from './main-thread-ref-init-value.js';
9
+ const mainThreadObjectTypeDefinitions = new WeakMap();
10
+ /**
11
+ * An opaque source-runtime handle for an object realized on the main thread.
12
+ *
13
+ * A handle has logical identity and is serializable, but it is not the target
14
+ * object or an RPC stub. Capturing it in a main-thread function resolves it to
15
+ * the corresponding local target object. Development builds may wrap the
16
+ * background handle in a throwing guard solely to diagnose invalid access;
17
+ * that guard never forwards operations between runtimes.
18
+ *
19
+ * @public
20
+ */
21
+ export class MainThreadObjectHandle {
22
+ /** @internal */
23
+ _wvid;
24
+ /** @internal */
25
+ _initValue;
26
+ /** @internal */
27
+ _type;
28
+ /** @internal */
29
+ _releaseObserver;
30
+ /** @internal */
31
+ constructor(initialValue, type) {
32
+ if (__DEV__ && __JS__) {
33
+ assertSerializableMainThreadObjectPayload(initialValue, type);
34
+ }
35
+ this._wvid = allocateMainThreadRefId();
36
+ this._initValue = initialValue;
37
+ this._type = type;
38
+ registerMainThreadObjectHandle(this, type);
39
+ if (__JS__) {
40
+ addMainThreadRefInitValue(this._wvid, initialValue, type);
41
+ const id = this._wvid;
42
+ this._releaseObserver = lynx.getNativeApp().createJSObjectDestructionObserver?.(() => {
43
+ lynx.getCoreContext?.().dispatchEvent({
44
+ type: WorkletEvents.releaseWorkletRef,
45
+ data: { id },
46
+ });
47
+ });
48
+ }
49
+ }
50
+ /**
51
+ * The payload used to create the realized object.
52
+ *
53
+ * Readonly is a TypeScript contract; the value is not frozen at runtime.
54
+ */
55
+ get creationPayload() {
56
+ return this._initValue;
57
+ }
58
+ /** @internal */
59
+ toJSON() {
60
+ return {
61
+ _wvid: this._wvid,
62
+ _initValue: this._initValue,
63
+ _type: this._type,
64
+ };
65
+ }
66
+ }
67
+ class MainThreadObjectHandleImpl extends MainThreadObjectHandle {
68
+ constructor(initialValue, type) {
69
+ super(initialValue, type);
70
+ }
71
+ }
72
+ /**
73
+ * Define a main-thread object type for use by a library-provided hook.
74
+ *
75
+ * @param definition - Stable type key and target-object factory function.
76
+ * @returns An immutable object type definition.
77
+ * @public
78
+ */
79
+ export function defineMainThreadObjectType(definition) {
80
+ // Read accessor-backed fields once so validation and deferred registration
81
+ // operate on the same definition values.
82
+ const { type, create } = definition;
83
+ if (typeof type !== 'string' || type.length === 0) {
84
+ throw new Error('MainThreadObject type must be a non-empty string.');
85
+ }
86
+ if (type === 'main-thread') {
87
+ throw new Error('MainThreadObject type "main-thread" is reserved for MainThreadRef.');
88
+ }
89
+ if (!isMainThreadLifecycleFunction(create)) {
90
+ throw new Error(`MainThreadObject type "${type}" must provide a create Main Thread Function.`);
91
+ }
92
+ if (__DEV__) {
93
+ assertCaptureFreeLifecycleFunction(type, 'create', create);
94
+ }
95
+ // Keep the validated fields independent from the caller-owned definition.
96
+ // Registration may be deferred until the first main-thread hook use, so a
97
+ // later mutation of `definition` must not change the type or factory that is
98
+ // registered for this token.
99
+ const validatedDefinition = Object.freeze({
100
+ type,
101
+ create,
102
+ });
103
+ const objectType = Object.freeze({
104
+ type,
105
+ downcast(value) {
106
+ return getMainThreadObjectHandleType(value) === type
107
+ ? value
108
+ : undefined;
109
+ },
110
+ });
111
+ mainThreadObjectTypeDefinitions.set(objectType, validatedDefinition);
112
+ registerMainThreadObjectDefinition(validatedDefinition);
113
+ return objectType;
114
+ }
115
+ /**
116
+ * Create a stable handle that resolves to an object of the supplied type in
117
+ * main-thread functions.
118
+ *
119
+ * This primitive is intended for library hooks. The returned target type is
120
+ * only callable in a main-thread function; it must not be used from the
121
+ * background runtime.
122
+ *
123
+ * @param objectType - Definition used to realize the target object.
124
+ * @param initialValue - JSON-serializable initialization payload.
125
+ * @returns The main-thread-only target type.
126
+ * @public
127
+ */
128
+ export function useMainThreadObject(objectType, initialValue) {
129
+ return useMemo(() => {
130
+ const definition = mainThreadObjectTypeDefinitions.get(objectType);
131
+ if (definition === undefined) {
132
+ throw new Error(`Invalid MainThreadObject type token for "${objectType.type}". Create it with defineMainThreadObjectType().`);
133
+ }
134
+ // A library module normally registers its type while the MTS bundle is
135
+ // evaluated. Register again at the first hook use so runtimes that retain
136
+ // the module but reset their per-page worklet registry remain correct.
137
+ // The registry treats an equivalent duplicate as an idempotent lookup.
138
+ registerMainThreadObjectDefinition(definition);
139
+ const handle = new MainThreadObjectHandleImpl(initialValue, objectType.type);
140
+ return guardBackgroundMainThreadObjectAccess(handle, objectType.type);
141
+ }, []);
142
+ }
143
+ function registerMainThreadObjectDefinition(definition) {
144
+ if (__JS__) {
145
+ return;
146
+ }
147
+ registerMainThreadObjectType(definition.type, definition.create);
148
+ }
149
+ function isMainThreadLifecycleFunction(value) {
150
+ return typeof value === 'function'
151
+ || (typeof value === 'object' && value !== null
152
+ && typeof value._wkltId === 'string');
153
+ }
154
+ function assertCaptureFreeLifecycleFunction(type, name, value) {
155
+ if (typeof value === 'function') {
156
+ return;
157
+ }
158
+ const descriptors = Object.getOwnPropertyDescriptors(value);
159
+ const hasCaptures = Reflect.ownKeys(descriptors).some(key => {
160
+ if (typeof key !== 'string') {
161
+ return true;
162
+ }
163
+ if (key === '_wkltId' || key === '_workletType' || key === '_lepusWorkletHash') {
164
+ return false;
165
+ }
166
+ if (key === '_c') {
167
+ const descriptor = descriptors[key];
168
+ const closure = 'value' in descriptor ? descriptor.value : undefined;
169
+ return !('value' in descriptor)
170
+ || (closure !== undefined
171
+ && (typeof closure !== 'object' || closure === null
172
+ || Reflect.ownKeys(closure).length !== 0));
173
+ }
174
+ return true;
175
+ });
176
+ if (hasCaptures) {
177
+ throw new Error(`MainThreadObject ${name} function for "${type}" must not capture values. Import dependencies from a shared-runtime module instead.`);
178
+ }
179
+ }
180
+ function guardBackgroundMainThreadObjectAccess(handle, type) {
181
+ if (!__DEV__ || !__JS__) {
182
+ return handle;
183
+ }
184
+ // This development-only guard never forwards a call to the main thread. It
185
+ // only turns an otherwise opaque "method is not a function" failure into a
186
+ // diagnostic. Production handles remain plain serializable objects.
187
+ const guardedHandle = new Proxy(handle, {
188
+ get(target, property, receiver) {
189
+ if (property in target) {
190
+ return Reflect.get(target, property, receiver);
191
+ }
192
+ if (typeof property === 'symbol'
193
+ || property === 'then'
194
+ || property === '$$typeof') {
195
+ return undefined;
196
+ }
197
+ throw new Error(`MainThreadObject handle for "${type}" cannot access "${String(property)}" in the background runtime. Use the object only inside a main-thread function.`);
198
+ },
199
+ set(target, property, value, receiver) {
200
+ if (property in target) {
201
+ return Reflect.set(target, property, value, receiver);
202
+ }
203
+ throw new Error(`MainThreadObject handle for "${type}" cannot set "${String(property)}" in the background runtime. Use the object only inside a main-thread function.`);
204
+ },
205
+ });
206
+ registerMainThreadObjectHandle(guardedHandle, type);
207
+ return guardedHandle;
208
+ }
209
+ function assertSerializableMainThreadObjectPayload(value, type) {
210
+ const invalidPath = findNonSerializablePath(value, '$', new Set());
211
+ if (invalidPath !== undefined) {
212
+ throw new Error(`MainThreadObject initial value for "${type}" must be JSON-serializable; invalid value at ${invalidPath}.`);
213
+ }
214
+ }
215
+ function findNonSerializablePath(value, path, ancestors) {
216
+ if (value === undefined
217
+ || typeof value === 'function'
218
+ || typeof value === 'symbol'
219
+ || typeof value === 'bigint'
220
+ || (typeof value === 'number' && !Number.isFinite(value))) {
221
+ return path;
222
+ }
223
+ if (value === null || typeof value !== 'object') {
224
+ return undefined;
225
+ }
226
+ if (ancestors.has(value)) {
227
+ return path;
228
+ }
229
+ const prototype = Object.getPrototypeOf(value);
230
+ if (!Array.isArray(value) && prototype !== Object.prototype && prototype !== null) {
231
+ return path;
232
+ }
233
+ ancestors.add(value);
234
+ if (Array.isArray(value)) {
235
+ for (let index = 0; index < value.length; index++) {
236
+ if (!Object.prototype.hasOwnProperty.call(value, index)) {
237
+ continue;
238
+ }
239
+ const invalidPath = findNonSerializablePath(value[index], `${path}.${index}`, ancestors);
240
+ if (invalidPath !== undefined) {
241
+ ancestors.delete(value);
242
+ return invalidPath;
243
+ }
244
+ }
245
+ }
246
+ else {
247
+ for (const [key, item] of Object.entries(value)) {
248
+ const invalidPath = findNonSerializablePath(item, `${path}.${key}`, ancestors);
249
+ if (invalidPath !== undefined) {
250
+ ancestors.delete(value);
251
+ return invalidPath;
252
+ }
253
+ }
254
+ }
255
+ ancestors.delete(value);
256
+ return undefined;
257
+ }
258
+ //# sourceMappingURL=main-thread-object.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"main-thread-object.js","sourceRoot":"","sources":["../../src/core/main-thread-object.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D,OAAO,EAAE,aAAa,EAAE,4BAA4B,EAAE,MAAM,yCAAyC,CAAC;AAGtG,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAC3C,OAAO,EAAE,6BAA6B,EAAE,8BAA8B,EAAE,MAAM,yCAAyC,CAAC;AACxH,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AAC,MAAM,CAAC,KAAK,CAAC,CAAC;gBACxB,OAAO,WAAW,CAAC;YACrB,CAAC;QACH,CAAC;IACH,CAAC;SAAM,CAAC;QACN,KAAK,MAAM,CAAC,GAAG,EAAE,IAAI,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;YAChD,MAAM,WAAW,GAAG,uBAAuB,CAAC,IAAI,EAAE,GAAG,IAAI,IAAI,GAAG,EAAE,EAAE,SAAS,CAAC,CAAC;YAC/E,IAAI,WAAW,KAAK,SAAS,EAAE,CAAC;gBAC9B,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;gBACxB,OAAO,WAAW,CAAC;YACrB,CAAC;QACH,CAAC;IACH,CAAC;IACD,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IACxB,OAAO,SAAS,CAAC;AACnB,CAAC","sourcesContent":["// Copyright 2026 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 { WorkletEvents, registerMainThreadObjectType } from '@lynx-js/react/worklet-runtime/bindings';\nimport type { Worklet, WorkletRefImpl } from '@lynx-js/react/worklet-runtime/bindings';\n\nimport { useMemo } from './hooks/react.js';\nimport { getMainThreadObjectHandleType, registerMainThreadObjectHandle } from './main-thread-object-handle-registry.js';\nimport { allocateMainThreadRefId } from './main-thread-ref-id.js';\nimport { addMainThreadRefInitValue } from './main-thread-ref-init-value.js';\n\nconst mainThreadObjectTypeDefinitions = new WeakMap<\n object,\n MainThreadObjectTypeDefinition<unknown, object>\n>();\n\n/**\n * Describes how a serializable initialization payload becomes a stable object\n * in the main-thread runtime.\n *\n * @public\n */\nexport interface MainThreadObjectTypeDefinition<I, O extends object> {\n /** A globally unique and stable type key. */\n readonly type: string;\n /**\n * Create the realized main-thread object.\n *\n * This must be a capture-free Main Thread Function. Imports used by the\n * function must come from shared-runtime modules.\n */\n readonly create: (initialValue: I) => O;\n}\n\n/**\n * An immutable MainThreadObject type token with source-handle inspection.\n *\n * The factory function belongs to the input definition and is not exposed\n * by the returned token. In the background runtime they compile to opaque\n * Main Thread Function descriptors rather than bundling their implementation.\n *\n * @public\n */\nexport interface MainThreadObjectType<I, O extends object> {\n /** A globally unique and stable type key. */\n readonly type: string;\n /**\n * Narrow a value to a source-runtime handle of this exact type.\n *\n * This does not create or access the realized main-thread object.\n */\n readonly downcast: (value: unknown) => MainThreadObjectHandle<I, O> | undefined;\n}\n\n/**\n * An opaque source-runtime handle for an object realized on the main thread.\n *\n * A handle has logical identity and is serializable, but it is not the target\n * object or an RPC stub. Capturing it in a main-thread function resolves it to\n * the corresponding local target object. Development builds may wrap the\n * background handle in a throwing guard solely to diagnose invalid access;\n * that guard never forwards operations between runtimes.\n *\n * @public\n */\nexport abstract class MainThreadObjectHandle<I, O extends object> {\n /** @internal */\n declare private readonly _mainThreadObjectTargetType: O;\n /** @internal */\n protected _wvid: number;\n /** @internal */\n protected _initValue: I;\n /** @internal */\n protected _type: string;\n /** @internal */\n protected _releaseObserver?: unknown;\n\n /** @internal */\n protected constructor(initialValue: I, type: string) {\n if (__DEV__ && __JS__) {\n assertSerializableMainThreadObjectPayload(initialValue, type);\n }\n\n this._wvid = allocateMainThreadRefId();\n this._initValue = initialValue;\n this._type = type;\n registerMainThreadObjectHandle(this, type);\n\n if (__JS__) {\n addMainThreadRefInitValue(\n this._wvid,\n initialValue,\n type,\n );\n\n const id = this._wvid;\n this._releaseObserver = lynx.getNativeApp().createJSObjectDestructionObserver?.(() => {\n lynx.getCoreContext?.().dispatchEvent({\n type: WorkletEvents.releaseWorkletRef,\n data: { id },\n });\n });\n }\n }\n\n /**\n * The payload used to create the realized object.\n *\n * Readonly is a TypeScript contract; the value is not frozen at runtime.\n */\n public get creationPayload(): Readonly<I> {\n return this._initValue;\n }\n\n /** @internal */\n toJSON(): Pick<WorkletRefImpl<unknown>, '_wvid' | '_initValue' | '_type'> {\n return {\n _wvid: this._wvid,\n _initValue: this._initValue,\n _type: this._type,\n };\n }\n}\n\nclass MainThreadObjectHandleImpl<I, O extends object> extends MainThreadObjectHandle<I, O> {\n constructor(initialValue: I, type: string) {\n super(initialValue, type);\n }\n}\n\n/**\n * Define a main-thread object type for use by a library-provided hook.\n *\n * @param definition - Stable type key and target-object factory function.\n * @returns An immutable object type definition.\n * @public\n */\nexport function defineMainThreadObjectType<I, O extends object>(\n definition: MainThreadObjectTypeDefinition<I, O>,\n): MainThreadObjectType<I, O> {\n // Read accessor-backed fields once so validation and deferred registration\n // operate on the same definition values.\n const { type, create } = definition;\n if (typeof type !== 'string' || type.length === 0) {\n throw new Error('MainThreadObject type must be a non-empty string.');\n }\n if (type === 'main-thread') {\n throw new Error(\n 'MainThreadObject type \"main-thread\" is reserved for MainThreadRef.',\n );\n }\n if (!isMainThreadLifecycleFunction(create)) {\n throw new Error(\n `MainThreadObject type \"${type}\" must provide a create Main Thread Function.`,\n );\n }\n if (__DEV__) {\n assertCaptureFreeLifecycleFunction(type, 'create', create);\n }\n\n // Keep the validated fields independent from the caller-owned definition.\n // Registration may be deferred until the first main-thread hook use, so a\n // later mutation of `definition` must not change the type or factory that is\n // registered for this token.\n const validatedDefinition = Object.freeze({\n type,\n create,\n });\n const objectType = Object.freeze({\n type,\n downcast(value: unknown): MainThreadObjectHandle<I, O> | undefined {\n return getMainThreadObjectHandleType(value) === type\n ? value as MainThreadObjectHandle<I, O>\n : undefined;\n },\n });\n mainThreadObjectTypeDefinitions.set(\n objectType,\n validatedDefinition as unknown as MainThreadObjectTypeDefinition<unknown, object>,\n );\n registerMainThreadObjectDefinition(validatedDefinition);\n return objectType;\n}\n\n/**\n * Create a stable handle that resolves to an object of the supplied type in\n * main-thread functions.\n *\n * This primitive is intended for library hooks. The returned target type is\n * only callable in a main-thread function; it must not be used from the\n * background runtime.\n *\n * @param objectType - Definition used to realize the target object.\n * @param initialValue - JSON-serializable initialization payload.\n * @returns The main-thread-only target type.\n * @public\n */\nexport function useMainThreadObject<I, O extends object>(\n objectType: MainThreadObjectType<I, O>,\n initialValue: I,\n): O {\n return useMemo(() => {\n const definition = mainThreadObjectTypeDefinitions.get(objectType);\n if (definition === undefined) {\n throw new Error(\n `Invalid MainThreadObject type token for \"${objectType.type}\". Create it with defineMainThreadObjectType().`,\n );\n }\n // A library module normally registers its type while the MTS bundle is\n // evaluated. Register again at the first hook use so runtimes that retain\n // the module but reset their per-page worklet registry remain correct.\n // The registry treats an equivalent duplicate as an idempotent lookup.\n registerMainThreadObjectDefinition(definition);\n const handle = new MainThreadObjectHandleImpl<I, O>(initialValue, objectType.type);\n return guardBackgroundMainThreadObjectAccess(handle, objectType.type) as unknown as O;\n }, []);\n}\n\nfunction registerMainThreadObjectDefinition<I, O extends object>(\n definition: MainThreadObjectTypeDefinition<I, O>,\n): void {\n if (__JS__) {\n return;\n }\n\n registerMainThreadObjectType(\n definition.type,\n definition.create as ((initialValue: unknown) => object) | Worklet,\n );\n}\n\nfunction isMainThreadLifecycleFunction(\n value: unknown,\n): value is ((...args: never[]) => unknown) | Worklet {\n return typeof value === 'function'\n || (typeof value === 'object' && value !== null\n && typeof (value as Partial<Worklet>)._wkltId === 'string');\n}\n\nfunction assertCaptureFreeLifecycleFunction(\n type: string,\n name: 'create',\n value: ((...args: never[]) => unknown) | Worklet,\n): void {\n if (typeof value === 'function') {\n return;\n }\n const descriptors = Object.getOwnPropertyDescriptors(value);\n const hasCaptures = Reflect.ownKeys(descriptors).some(key => {\n if (typeof key !== 'string') {\n return true;\n }\n if (key === '_wkltId' || key === '_workletType' || key === '_lepusWorkletHash') {\n return false;\n }\n if (key === '_c') {\n const descriptor = descriptors[key]!;\n const closure = 'value' in descriptor ? descriptor.value : undefined;\n return !('value' in descriptor)\n || (closure !== undefined\n && (typeof closure !== 'object' || closure === null\n || Reflect.ownKeys(closure).length !== 0));\n }\n return true;\n });\n if (hasCaptures) {\n throw new Error(\n `MainThreadObject ${name} function for \"${type}\" must not capture values. Import dependencies from a shared-runtime module instead.`,\n );\n }\n}\n\nfunction guardBackgroundMainThreadObjectAccess<I, O extends object>(\n handle: MainThreadObjectHandle<I, O>,\n type: string,\n): MainThreadObjectHandle<I, O> {\n if (!__DEV__ || !__JS__) {\n return handle;\n }\n\n // This development-only guard never forwards a call to the main thread. It\n // only turns an otherwise opaque \"method is not a function\" failure into a\n // diagnostic. Production handles remain plain serializable objects.\n const guardedHandle = new Proxy(handle, {\n get(target, property, receiver): unknown {\n if (property in target) {\n return Reflect.get(target, property, receiver) as unknown;\n }\n if (\n typeof property === 'symbol'\n || property === 'then'\n || property === '$$typeof'\n ) {\n return undefined;\n }\n throw new Error(\n `MainThreadObject handle for \"${type}\" cannot access \"${\n String(property)\n }\" in the background runtime. Use the object only inside a main-thread function.`,\n );\n },\n set(target, property, value, receiver) {\n if (property in target) {\n return Reflect.set(target, property, value, receiver);\n }\n throw new Error(\n `MainThreadObject handle for \"${type}\" cannot set \"${\n String(property)\n }\" in the background runtime. Use the object only inside a main-thread function.`,\n );\n },\n });\n registerMainThreadObjectHandle(guardedHandle, type);\n return guardedHandle;\n}\n\nfunction assertSerializableMainThreadObjectPayload(value: unknown, type: string): void {\n const invalidPath = findNonSerializablePath(value, '$', new Set<object>());\n if (invalidPath !== undefined) {\n throw new Error(\n `MainThreadObject initial value for \"${type}\" must be JSON-serializable; invalid value at ${invalidPath}.`,\n );\n }\n}\n\nfunction findNonSerializablePath(\n value: unknown,\n path: string,\n ancestors: Set<object>,\n): string | undefined {\n if (\n value === undefined\n || typeof value === 'function'\n || typeof value === 'symbol'\n || typeof value === 'bigint'\n || (typeof value === 'number' && !Number.isFinite(value))\n ) {\n return path;\n }\n if (value === null || typeof value !== 'object') {\n return undefined;\n }\n if (ancestors.has(value)) {\n return path;\n }\n\n const prototype = Object.getPrototypeOf(value) as object | null;\n if (!Array.isArray(value) && prototype !== Object.prototype && prototype !== null) {\n return path;\n }\n\n ancestors.add(value);\n if (Array.isArray(value)) {\n for (let index = 0; index < value.length; index++) {\n if (!Object.prototype.hasOwnProperty.call(value, index)) {\n continue;\n }\n const invalidPath = findNonSerializablePath(\n value[index],\n `${path}.${index}`,\n ancestors,\n );\n if (invalidPath !== undefined) {\n ancestors.delete(value);\n return invalidPath;\n }\n }\n } else {\n for (const [key, item] of Object.entries(value)) {\n const invalidPath = findNonSerializablePath(item, `${path}.${key}`, ancestors);\n if (invalidPath !== undefined) {\n ancestors.delete(value);\n return invalidPath;\n }\n }\n }\n ancestors.delete(value);\n return undefined;\n}\n"]}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,14 @@
1
+ // Copyright 2026 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
+ let lastIdBG = 0;
5
+ let lastIdMT = 0;
6
+ /** @internal */
7
+ export function allocateMainThreadRefId() {
8
+ return __JS__ ? ++lastIdBG : --lastIdMT;
9
+ }
10
+ /** @internal */
11
+ export function clearMainThreadRefIdsForTesting() {
12
+ lastIdBG = lastIdMT = 0;
13
+ }
14
+ //# sourceMappingURL=main-thread-ref-id.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"main-thread-ref-id.js","sourceRoot":"","sources":["../../src/core/main-thread-ref-id.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D,IAAI,QAAQ,GAAG,CAAC,CAAC;AACjB,IAAI,QAAQ,GAAG,CAAC,CAAC;AAEjB,gBAAgB;AAChB,MAAM,UAAU,uBAAuB;IACrC,OAAO,MAAM,CAAC,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC,CAAC,EAAE,QAAQ,CAAC;AAC1C,CAAC;AAED,gBAAgB;AAChB,MAAM,UAAU,+BAA+B;IAC7C,QAAQ,GAAG,QAAQ,GAAG,CAAC,CAAC;AAC1B,CAAC","sourcesContent":["// Copyright 2026 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\nlet lastIdBG = 0;\nlet lastIdMT = 0;\n\n/** @internal */\nexport function allocateMainThreadRefId(): number {\n return __JS__ ? ++lastIdBG : --lastIdMT;\n}\n\n/** @internal */\nexport function clearMainThreadRefIdsForTesting(): void {\n lastIdBG = lastIdMT = 0;\n}\n"]}
@@ -1 +1 @@
1
- export type MainThreadRefInitValuePatch = [id: number, value: unknown][];
1
+ export {};
@@ -6,11 +6,13 @@ let mainThreadRefInitValuePatch = [];
6
6
  /**
7
7
  * @internal
8
8
  */
9
- export function addMainThreadRefInitValue(id, value) {
9
+ export function addMainThreadRefInitValue(id, value, type) {
10
10
  if (!isMtsEnabled()) {
11
11
  return;
12
12
  }
13
- mainThreadRefInitValuePatch.push([id, value]);
13
+ mainThreadRefInitValuePatch.push(type === undefined
14
+ ? [id, value]
15
+ : [id, value, type]);
14
16
  }
15
17
  /**
16
18
  * @internal
@@ -1 +1 @@
1
- {"version":3,"file":"main-thread-ref-init-value.js","sourceRoot":"","sources":["../../src/core/main-thread-ref-init-value.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAInD,IAAI,2BAA2B,GAAgC,EAAE,CAAC;AAElE;;GAEG;AACH,MAAM,UAAU,yBAAyB,CAAC,EAAU,EAAE,KAAc;IAClE,IAAI,CAAC,YAAY,EAAE,EAAE,CAAC;QACpB,OAAO;IACT,CAAC;IAED,2BAA2B,CAAC,IAAI,CAAC,CAAC,EAAE,EAAE,KAAK,CAAC,CAAC,CAAC;AAChD,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,+BAA+B;IAC7C,MAAM,KAAK,GAAG,2BAA2B,CAAC;IAC1C,2BAA2B,GAAG,EAAE,CAAC;IACjC,OAAO,KAAK,CAAC;AACf,CAAC"}
1
+ {"version":3,"file":"main-thread-ref-init-value.js","sourceRoot":"","sources":["../../src/core/main-thread-ref-init-value.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAI1D,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAEnD,IAAI,2BAA2B,GAAgC,EAAE,CAAC;AAElE;;GAEG;AACH,MAAM,UAAU,yBAAyB,CACvC,EAAU,EACV,KAAc,EACd,IAAa;IAEb,IAAI,CAAC,YAAY,EAAE,EAAE,CAAC;QACpB,OAAO;IACT,CAAC;IAED,2BAA2B,CAAC,IAAI,CAC9B,IAAI,KAAK,SAAS;QAChB,CAAC,CAAC,CAAC,EAAE,EAAE,KAAK,CAAC;QACb,CAAC,CAAC,CAAC,EAAE,EAAE,KAAK,EAAE,IAAI,CAAC,CACtB,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,+BAA+B;IAC7C,MAAM,KAAK,GAAG,2BAA2B,CAAC;IAC1C,2BAA2B,GAAG,EAAE,CAAC;IACjC,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["// Copyright 2026 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 { MainThreadRefInitValuePatch } from '@lynx-js/react/worklet-runtime/bindings';\n\nimport { isMtsEnabled } from './mts-capability.js';\n\nlet mainThreadRefInitValuePatch: MainThreadRefInitValuePatch = [];\n\n/**\n * @internal\n */\nexport function addMainThreadRefInitValue(\n id: number,\n value: unknown,\n type?: string,\n): void {\n if (!isMtsEnabled()) {\n return;\n }\n\n mainThreadRefInitValuePatch.push(\n type === undefined\n ? [id, value]\n : [id, value, type],\n );\n}\n\n/**\n * @internal\n */\nexport function takeMainThreadRefInitValuePatch(): MainThreadRefInitValuePatch {\n const patch = mainThreadRefInitValuePatch;\n mainThreadRefInitValuePatch = [];\n return patch;\n}\n"]}
@@ -8,6 +8,8 @@ export declare function isMainThreadRef(value: unknown): value is WorkletRefImpl
8
8
  * The data saved in `current` property of the `MainThreadRef` can be read and written in
9
9
  * multiple main thread functions.
10
10
  * @public
11
+ *
12
+ * @group Types
11
13
  */
12
14
  export declare class MainThreadRef<T> {
13
15
  constructor(initValue: T);
@@ -51,6 +53,8 @@ export declare class MainThreadRef<T> {
51
53
  * ```
52
54
  *
53
55
  * @public
56
+ *
57
+ * @group Hooks
54
58
  */
55
59
  export declare function useMainThreadRef<T>(initValue: T): MainThreadRef<T>;
56
60
  /**
@@ -1,11 +1,9 @@
1
1
  import { useMemo } from './hooks/react.js';
2
+ import { allocateMainThreadRefId, clearMainThreadRefIdsForTesting } from './main-thread-ref-id.js';
2
3
  import { addMainThreadRefInitValue } from './main-thread-ref-init-value.js';
3
4
  import { WorkletEvents } from '../worklet-runtime/bindings/events.js';
4
- // Split into two variables for testing purposes.
5
- let lastIdBG = 0;
6
- let lastIdMT = 0;
7
5
  export function clearMainThreadRefLastIdForTesting() {
8
- lastIdBG = lastIdMT = 0;
6
+ clearMainThreadRefIdsForTesting();
9
7
  }
10
8
  export function isMainThreadRef(value) {
11
9
  return typeof value === 'object'
@@ -18,6 +16,8 @@ export function isMainThreadRef(value) {
18
16
  * The data saved in `current` property of the `MainThreadRef` can be read and written in
19
17
  * multiple main thread functions.
20
18
  * @public
19
+ *
20
+ * @group Types
21
21
  */
22
22
  export class MainThreadRef {
23
23
  /**
@@ -39,8 +39,8 @@ export class MainThreadRef {
39
39
  constructor(initValue) {
40
40
  this._initValue = initValue;
41
41
  this._type = 'main-thread';
42
+ this._wvid = allocateMainThreadRefId();
42
43
  if (__JS__) {
43
- this._wvid = ++lastIdBG;
44
44
  addMainThreadRefInitValue(this._wvid, initValue);
45
45
  const id = this._wvid;
46
46
  this._lifecycleObserver = lynx.getNativeApp().createJSObjectDestructionObserver?.(() => {
@@ -52,9 +52,6 @@ export class MainThreadRef {
52
52
  });
53
53
  });
54
54
  }
55
- else {
56
- this._wvid = --lastIdMT;
57
- }
58
55
  }
59
56
  get current() {
60
57
  if (__JS__ && __DEV__) {
@@ -1 +1 @@
1
- {"version":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QACD,OAAO,SAAc,CAAC;IACxB,CAAC;IAED,IAAI,OAAO,CAAC,CAAI;QACd,IAAI,MAAM,IAAI,OAAO,EAAE,CAAC;YACtB,MAAM,IAAI,KAAK,CAAC,sFAAsF,CAAC,CAAC;QAC1G,CAAC;QACD,IAAI,SAAS,IAAI,OAAO,EAAE,CAAC;YACzB,MAAM,IAAI,KAAK,CAAC,2FAA2F,CAAC,CAAC;QAC/G,CAAC;IACH,CAAC;IAED;;OAEG;IACH,MAAM;QACJ,OAAO;YACL,KAAK,EAAE,IAAI,CAAC,KAAK;SAClB,CAAC;IACJ,CAAC;CACF;AA6HD,MAAM,UAAU,gBAAgB,CAAI,SAAa;IAC/C,OAAO,OAAO,CAAC,GAAG,EAAE;QAClB,OAAO,IAAI,aAAa,CAAC,SAAS,CAAC,CAAC;IACtC,CAAC,EAAE,EAAE,CAAC,CAAC;AACT,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 { RefObject } from 'react';\n\nimport { useMemo } from './hooks/react.js';\nimport { allocateMainThreadRefId, clearMainThreadRefIdsForTesting } from './main-thread-ref-id.js';\nimport { addMainThreadRefInitValue } from './main-thread-ref-init-value.js';\nimport { WorkletEvents } from '../worklet-runtime/bindings/events.js';\nimport type { WorkletRefImpl } from '../worklet-runtime/bindings/types.js';\n\nexport function clearMainThreadRefLastIdForTesting(): void {\n clearMainThreadRefIdsForTesting();\n}\n\nexport function isMainThreadRef(value: unknown): value is WorkletRefImpl<unknown> {\n return typeof value === 'object'\n && value !== null\n && typeof (value as { _wvid?: unknown })._wvid === 'number';\n}\n\n/**\n * A `MainThreadRef` is a ref that can only be accessed on the main thread. It is used to preserve\n * states between main thread function calls.\n * The data saved in `current` property of the `MainThreadRef` can be read and written in\n * multiple main thread functions.\n * @public\n *\n * @group Types\n */\nexport class MainThreadRef<T> {\n /**\n * @internal\n */\n protected _wvid: number;\n /**\n * @internal\n */\n protected _initValue: T | undefined;\n /**\n * @internal\n */\n protected _type: string;\n /**\n * @internal\n */\n protected _lifecycleObserver: unknown;\n\n constructor(initValue: T) {\n this._initValue = initValue;\n this._type = 'main-thread';\n this._wvid = allocateMainThreadRefId();\n if (__JS__) {\n addMainThreadRefInitValue(this._wvid, initValue);\n const id = this._wvid;\n this._lifecycleObserver = lynx.getNativeApp().createJSObjectDestructionObserver?.(() => {\n lynx.getCoreContext().dispatchEvent({\n type: WorkletEvents.releaseWorkletRef,\n data: {\n id,\n },\n });\n });\n }\n }\n\n get current(): T {\n if (__JS__ && __DEV__) {\n throw new Error('MainThreadRef: value of a MainThreadRef cannot be accessed in the background thread.');\n }\n if (__LEPUS__ && __DEV__) {\n /* v8 ignore next 3 */\n throw new Error('MainThreadRef: value of a MainThreadRef cannot be accessed outside of main thread script.');\n }\n return undefined as T;\n }\n\n set current(_: T) {\n if (__JS__ && __DEV__) {\n throw new Error('MainThreadRef: value of a MainThreadRef cannot be accessed in the background thread.');\n }\n if (__LEPUS__ && __DEV__) {\n throw new Error('MainThreadRef: value of a MainThreadRef cannot be accessed outside of main thread script.');\n }\n }\n\n /**\n * @internal\n */\n toJSON(): { _wvid: WorkletRefImpl<T>['_wvid'] } {\n return {\n _wvid: this._wvid,\n };\n }\n}\n\n/**\n * Create A `MainThreadRef`.\n *\n * A `MainThreadRef` is a ref that can only be accessed on the main thread. It is used to preserve\n * states between main thread function calls.\n * The data saved in `current` property of the `MainThreadRef` can be read and written in\n * multiple main thread functions.\n *\n * It is a hook and it should only be called at the top level of your component.\n *\n * @param initValue - The init value of the `MainThreadRef`.\n *\n * @example\n *\n * ```ts\n * import { useMainThreadRef } from '@lynx-js/react'\n * import type { MainThread } from '@lynx-js/types'\n *\n * export function App() {\n * const ref = useMainThreadRef<MainThread.Element>(null)\n *\n * const handleTap = () => {\n * 'main thread'\n * ref.current?.setStyleProperty('background-color', 'blue')\n * }\n *\n * return (\n * <view\n * main-thread:ref={ref}\n * main-thread:bindtap={handleTap}\n * style={{ width: '300px', height: '300px' }}\n * />\n * )\n * }\n * ```\n *\n * @public\n *\n * @group Hooks\n */\nexport function useMainThreadRef<T>(initValue: T): MainThreadRef<T>;\n\n// Convenience overload for refs given as a ref prop as they typically start with a null value.\n/**\n * Create A `MainThreadRef`.\n *\n * A `MainThreadRef` is a ref that can only be accessed on the main thread. It is used to preserve\n * states between main thread function calls.\n * The data saved in `current` property of the `MainThreadRef` can be read and written in\n * multiple main thread functions.\n *\n * It is a hook and it should only be called at the top level of your component.\n *\n * @param initValue - The init value of the `MainThreadRef`.\n *\n * @example\n *\n * ```ts\n * import { useMainThreadRef } from '@lynx-js/react'\n * import type { MainThread } from '@lynx-js/types'\n *\n * export function App() {\n * const ref = useMainThreadRef<MainThread.Element>(null)\n *\n * const handleTap = () => {\n * 'main thread'\n * ref.current?.setStyleProperty('background-color', 'blue')\n * }\n *\n * return (\n * <view\n * main-thread:ref={ref}\n * main-thread:bindtap={handleTap}\n * style={{ width: '300px', height: '300px' }}\n * />\n * )\n * }\n * ```\n *\n * @public\n */\nexport function useMainThreadRef<T>(initValue: T | null): RefObject<T>;\n\n// Convenience overload for potentially undefined initialValue / call with 0 arguments\n// has a default to stop it from defaulting to {} instead.\n/**\n * Create A `MainThreadRef`.\n *\n * A `MainThreadRef` is a ref that can only be accessed on the main thread. It is used to preserve\n * states between main thread function calls.\n * The data saved in `current` property of the `MainThreadRef` can be read and written in\n * multiple main thread functions.\n *\n * It is a hook and it should only be called at the top level of your component.\n *\n * @example\n *\n * ```ts\n * import { useMainThreadRef } from '@lynx-js/react'\n * import type { MainThread } from '@lynx-js/types'\n *\n * export function App() {\n * const ref = useMainThreadRef<MainThread.Element>(null)\n *\n * const handleTap = () => {\n * 'main thread'\n * ref.current?.setStyleProperty('background-color', 'blue')\n * }\n *\n * return (\n * <view\n * main-thread:ref={ref}\n * main-thread:bindtap={handleTap}\n * style={{ width: '300px', height: '300px' }}\n * />\n * )\n * }\n * ```\n *\n * @public\n */\nexport function useMainThreadRef<T = undefined>(): MainThreadRef<T | undefined>;\n\nexport function useMainThreadRef<T>(initValue?: T): MainThreadRef<T | undefined> {\n return useMemo(() => {\n return new MainThreadRef(initValue);\n }, []);\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"mts-capability.js","sourceRoot":"","sources":["../../src/core/mts-capability.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAE7C,IAAI,UAA+B,CAAC;AAEpC;;GAEG;AACH,MAAM,UAAU,YAAY;IAC1B,OAAO,UAAU,KAAK,cAAc,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;AAC9C,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,6BAA6B;IAC3C,UAAU,GAAG,SAAS,CAAC;AACzB,CAAC"}
1
+ {"version":3,"file":"mts-capability.js","sourceRoot":"","sources":["../../src/core/mts-capability.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAE7C,IAAI,UAA+B,CAAC;AAEpC;;GAEG;AACH,MAAM,UAAU,YAAY;IAC1B,OAAO,UAAU,KAAK,cAAc,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;AAC9C,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,6BAA6B;IAC3C,UAAU,GAAG,SAAS,CAAC;AACzB,CAAC","sourcesContent":["// Copyright 2026 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 { isSdkVersionGt } from '../utils.js';\n\nlet mtsEnabled: boolean | undefined;\n\n/**\n * @internal\n */\nexport function isMtsEnabled(): boolean {\n return mtsEnabled ??= isSdkVersionGt(2, 13);\n}\n\n/**\n * @internal\n */\nexport function clearMtsConfigCacheForTesting(): void {\n mtsEnabled = undefined;\n}\n"]}