@lynx-js/react 0.105.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 (337) hide show
  1. package/CHANGELOG.md +250 -0
  2. package/LICENSE +202 -0
  3. package/README.md +20 -0
  4. package/components/lib/Page.d.ts +3 -0
  5. package/components/lib/Page.js +56 -0
  6. package/components/lib/Page.js.map +1 -0
  7. package/components/lib/index.d.ts +1 -0
  8. package/components/lib/index.js +5 -0
  9. package/components/lib/index.js.map +1 -0
  10. package/components/src/Page.ts +75 -0
  11. package/components/src/index.ts +5 -0
  12. package/package.json +162 -0
  13. package/refresh/.gitignore +1 -0
  14. package/refresh/.npmignore +3 -0
  15. package/refresh/.turbo/turbo-build.log +8 -0
  16. package/refresh/dist/index.js +311 -0
  17. package/refresh/package.json +21 -0
  18. package/refresh/src/index.ts +6 -0
  19. package/refresh/src/prefresh.d.ts +11 -0
  20. package/refresh/tsconfig.json +4 -0
  21. package/refresh/turbo.json +15 -0
  22. package/runtime/jsx-dev-runtime/index.d.ts +5 -0
  23. package/runtime/jsx-dev-runtime/index.js +4 -0
  24. package/runtime/jsx-runtime/index.d.ts +4 -0
  25. package/runtime/jsx-runtime/index.js +4 -0
  26. package/runtime/lazy/import.d.ts +1 -0
  27. package/runtime/lazy/import.js +55 -0
  28. package/runtime/lazy/internal.js +39 -0
  29. package/runtime/lazy/jsx-dev-runtime.js +12 -0
  30. package/runtime/lazy/jsx-runtime.js +12 -0
  31. package/runtime/lazy/legacy-react-runtime.js +20 -0
  32. package/runtime/lazy/react-lepus.js +9 -0
  33. package/runtime/lazy/react.js +46 -0
  34. package/runtime/lazy/target.js +11 -0
  35. package/runtime/lepus/index.d.ts +4 -0
  36. package/runtime/lepus/index.js +43 -0
  37. package/runtime/lepus/jsx-dev-runtime/index.js +4 -0
  38. package/runtime/lepus/jsx-runtime/index.js +66 -0
  39. package/runtime/lib/backgroundSnapshot.d.ts +23 -0
  40. package/runtime/lib/backgroundSnapshot.js +348 -0
  41. package/runtime/lib/backgroundSnapshot.js.map +1 -0
  42. package/runtime/lib/compat/componentIs.d.ts +4 -0
  43. package/runtime/lib/compat/componentIs.js +20 -0
  44. package/runtime/lib/compat/componentIs.js.map +1 -0
  45. package/runtime/lib/compat/initData.d.ts +43 -0
  46. package/runtime/lib/compat/initData.js +93 -0
  47. package/runtime/lib/compat/initData.js.map +1 -0
  48. package/runtime/lib/compat/lynxComponent.d.ts +5 -0
  49. package/runtime/lib/compat/lynxComponent.js +71 -0
  50. package/runtime/lib/compat/lynxComponent.js.map +1 -0
  51. package/runtime/lib/debug/debug.d.ts +2 -0
  52. package/runtime/lib/debug/debug.js +9 -0
  53. package/runtime/lib/debug/debug.js.map +1 -0
  54. package/runtime/lib/debug/printSnapshot.d.ts +3 -0
  55. package/runtime/lib/debug/printSnapshot.js +21 -0
  56. package/runtime/lib/debug/printSnapshot.js.map +1 -0
  57. package/runtime/lib/debug/profile.d.ts +1 -0
  58. package/runtime/lib/debug/profile.js +51 -0
  59. package/runtime/lib/debug/profile.js.map +1 -0
  60. package/runtime/lib/document.d.ts +4 -0
  61. package/runtime/lib/document.js +49 -0
  62. package/runtime/lib/document.js.map +1 -0
  63. package/runtime/lib/gesture/processGesture.d.ts +4 -0
  64. package/runtime/lib/gesture/processGesture.js +48 -0
  65. package/runtime/lib/gesture/processGesture.js.map +1 -0
  66. package/runtime/lib/gesture/processGestureBagkround.d.ts +2 -0
  67. package/runtime/lib/gesture/processGestureBagkround.js +16 -0
  68. package/runtime/lib/gesture/processGestureBagkround.js.map +1 -0
  69. package/runtime/lib/gesture/types.d.ts +34 -0
  70. package/runtime/lib/gesture/types.js +13 -0
  71. package/runtime/lib/gesture/types.js.map +1 -0
  72. package/runtime/lib/hooks/react.d.ts +26 -0
  73. package/runtime/lib/hooks/react.js +35 -0
  74. package/runtime/lib/hooks/react.js.map +1 -0
  75. package/runtime/lib/hooks/useLynxGlobalEventListener.d.ts +29 -0
  76. package/runtime/lib/hooks/useLynxGlobalEventListener.js +53 -0
  77. package/runtime/lib/hooks/useLynxGlobalEventListener.js.map +1 -0
  78. package/runtime/lib/hydrate.d.ts +18 -0
  79. package/runtime/lib/hydrate.js +271 -0
  80. package/runtime/lib/hydrate.js.map +1 -0
  81. package/runtime/lib/index.d.ts +9 -0
  82. package/runtime/lib/index.js +46 -0
  83. package/runtime/lib/index.js.map +1 -0
  84. package/runtime/lib/internal.d.ts +26 -0
  85. package/runtime/lib/internal.js +41 -0
  86. package/runtime/lib/internal.js.map +1 -0
  87. package/runtime/lib/legacy-react-runtime/index.d.ts +7 -0
  88. package/runtime/lib/legacy-react-runtime/index.js +34 -0
  89. package/runtime/lib/legacy-react-runtime/index.js.map +1 -0
  90. package/runtime/lib/lifecycle/delayUnmount.d.ts +8 -0
  91. package/runtime/lib/lifecycle/delayUnmount.js +68 -0
  92. package/runtime/lib/lifecycle/delayUnmount.js.map +1 -0
  93. package/runtime/lib/lifecycle/destroy.d.ts +2 -0
  94. package/runtime/lib/lifecycle/destroy.js +21 -0
  95. package/runtime/lib/lifecycle/destroy.js.map +1 -0
  96. package/runtime/lib/lifecycle/pass.d.ts +3 -0
  97. package/runtime/lib/lifecycle/pass.js +12 -0
  98. package/runtime/lib/lifecycle/pass.js.map +1 -0
  99. package/runtime/lib/lifecycle/patchUpdate.d.ts +23 -0
  100. package/runtime/lib/lifecycle/patchUpdate.js +179 -0
  101. package/runtime/lib/lifecycle/patchUpdate.js.map +1 -0
  102. package/runtime/lib/lifecycle/reload.d.ts +3 -0
  103. package/runtime/lib/lifecycle/reload.js +63 -0
  104. package/runtime/lib/lifecycle/reload.js.map +1 -0
  105. package/runtime/lib/lifecycle/render.d.ts +2 -0
  106. package/runtime/lib/lifecycle/render.js +44 -0
  107. package/runtime/lib/lifecycle/render.js.map +1 -0
  108. package/runtime/lib/lifecycleConstant.d.ts +12 -0
  109. package/runtime/lib/lifecycleConstant.js +17 -0
  110. package/runtime/lib/lifecycleConstant.js.map +1 -0
  111. package/runtime/lib/list.d.ts +40 -0
  112. package/runtime/lib/list.js +305 -0
  113. package/runtime/lib/list.js.map +1 -0
  114. package/runtime/lib/lynx/calledByNative.d.ts +2 -0
  115. package/runtime/lib/lynx/calledByNative.js +113 -0
  116. package/runtime/lib/lynx/calledByNative.js.map +1 -0
  117. package/runtime/lib/lynx/component.d.ts +1 -0
  118. package/runtime/lib/lynx/component.js +69 -0
  119. package/runtime/lib/lynx/component.js.map +1 -0
  120. package/runtime/lib/lynx/dynamic-js.d.ts +2 -0
  121. package/runtime/lib/lynx/dynamic-js.js +31 -0
  122. package/runtime/lib/lynx/dynamic-js.js.map +1 -0
  123. package/runtime/lib/lynx/env.d.ts +1 -0
  124. package/runtime/lib/lynx/env.js +92 -0
  125. package/runtime/lib/lynx/env.js.map +1 -0
  126. package/runtime/lib/lynx/injectLepusMethods.d.ts +2 -0
  127. package/runtime/lib/lynx/injectLepusMethods.js +50 -0
  128. package/runtime/lib/lynx/injectLepusMethods.js.map +1 -0
  129. package/runtime/lib/lynx/lazy-bundle.d.ts +9 -0
  130. package/runtime/lib/lynx/lazy-bundle.js +119 -0
  131. package/runtime/lib/lynx/lazy-bundle.js.map +1 -0
  132. package/runtime/lib/lynx/performance.d.ts +29 -0
  133. package/runtime/lib/lynx/performance.js +100 -0
  134. package/runtime/lib/lynx/performance.js.map +1 -0
  135. package/runtime/lib/lynx/tt.d.ts +4 -0
  136. package/runtime/lib/lynx/tt.js +193 -0
  137. package/runtime/lib/lynx/tt.js.map +1 -0
  138. package/runtime/lib/lynx-api.d.ts +311 -0
  139. package/runtime/lib/lynx-api.js +116 -0
  140. package/runtime/lib/lynx-api.js.map +1 -0
  141. package/runtime/lib/lynx.d.ts +2 -0
  142. package/runtime/lib/lynx.js +91 -0
  143. package/runtime/lib/lynx.js.map +1 -0
  144. package/runtime/lib/opcodes.d.ts +2 -0
  145. package/runtime/lib/opcodes.js +59 -0
  146. package/runtime/lib/opcodes.js.map +1 -0
  147. package/runtime/lib/renderToOpcodes/constants.d.ts +17 -0
  148. package/runtime/lib/renderToOpcodes/constants.js +23 -0
  149. package/runtime/lib/renderToOpcodes/constants.js.map +1 -0
  150. package/runtime/lib/renderToOpcodes/index.d.ts +13 -0
  151. package/runtime/lib/renderToOpcodes/index.js +227 -0
  152. package/runtime/lib/renderToOpcodes/index.js.map +1 -0
  153. package/runtime/lib/root.d.ts +7 -0
  154. package/runtime/lib/root.js +17 -0
  155. package/runtime/lib/root.js.map +1 -0
  156. package/runtime/lib/snapshot/event.d.ts +3 -0
  157. package/runtime/lib/snapshot/event.js +24 -0
  158. package/runtime/lib/snapshot/event.js.map +1 -0
  159. package/runtime/lib/snapshot/gesture.d.ts +2 -0
  160. package/runtime/lib/snapshot/gesture.js +18 -0
  161. package/runtime/lib/snapshot/gesture.js.map +1 -0
  162. package/runtime/lib/snapshot/platformInfo.d.ts +4 -0
  163. package/runtime/lib/snapshot/platformInfo.js +35 -0
  164. package/runtime/lib/snapshot/platformInfo.js.map +1 -0
  165. package/runtime/lib/snapshot/ref.d.ts +10 -0
  166. package/runtime/lib/snapshot/ref.js +119 -0
  167. package/runtime/lib/snapshot/ref.js.map +1 -0
  168. package/runtime/lib/snapshot/spread.d.ts +5 -0
  169. package/runtime/lib/snapshot/spread.js +289 -0
  170. package/runtime/lib/snapshot/spread.js.map +1 -0
  171. package/runtime/lib/snapshot/workletEvent.d.ts +3 -0
  172. package/runtime/lib/snapshot/workletEvent.js +22 -0
  173. package/runtime/lib/snapshot/workletEvent.js.map +1 -0
  174. package/runtime/lib/snapshot/workletRef.d.ts +5 -0
  175. package/runtime/lib/snapshot/workletRef.js +52 -0
  176. package/runtime/lib/snapshot/workletRef.js.map +1 -0
  177. package/runtime/lib/snapshot.d.ts +81 -0
  178. package/runtime/lib/snapshot.js +477 -0
  179. package/runtime/lib/snapshot.js.map +1 -0
  180. package/runtime/lib/snapshotPatch.d.ts +14 -0
  181. package/runtime/lib/snapshotPatch.js +31 -0
  182. package/runtime/lib/snapshotPatch.js.map +1 -0
  183. package/runtime/lib/snapshotPatchApply.d.ts +2 -0
  184. package/runtime/lib/snapshotPatchApply.js +110 -0
  185. package/runtime/lib/snapshotPatchApply.js.map +1 -0
  186. package/runtime/lib/utils.d.ts +4 -0
  187. package/runtime/lib/utils.js +32 -0
  188. package/runtime/lib/utils.js.map +1 -0
  189. package/runtime/lib/worklet/ctx.d.ts +1 -0
  190. package/runtime/lib/worklet/ctx.js +17 -0
  191. package/runtime/lib/worklet/ctx.js.map +1 -0
  192. package/runtime/lib/worklet/execMap.d.ts +1 -0
  193. package/runtime/lib/worklet/execMap.js +42 -0
  194. package/runtime/lib/worklet/execMap.js.map +1 -0
  195. package/runtime/lib/worklet/functionality.d.ts +1 -0
  196. package/runtime/lib/worklet/functionality.js +11 -0
  197. package/runtime/lib/worklet/functionality.js.map +1 -0
  198. package/runtime/lib/worklet/hmr.d.ts +1 -0
  199. package/runtime/lib/worklet/hmr.js +21 -0
  200. package/runtime/lib/worklet/hmr.js.map +1 -0
  201. package/runtime/lib/worklet/indexMap.d.ts +8 -0
  202. package/runtime/lib/worklet/indexMap.js +17 -0
  203. package/runtime/lib/worklet/indexMap.js.map +1 -0
  204. package/runtime/lib/worklet/jsImpl.d.ts +11 -0
  205. package/runtime/lib/worklet/jsImpl.js +68 -0
  206. package/runtime/lib/worklet/jsImpl.js.map +1 -0
  207. package/runtime/lib/worklet/runWorklet.d.ts +14 -0
  208. package/runtime/lib/worklet/runWorklet.js +82 -0
  209. package/runtime/lib/worklet/runWorklet.js.map +1 -0
  210. package/runtime/lib/worklet/workletRef.d.ts +131 -0
  211. package/runtime/lib/worklet/workletRef.js +96 -0
  212. package/runtime/lib/worklet/workletRef.js.map +1 -0
  213. package/runtime/lib/worklet/workletRefPool.d.ts +2 -0
  214. package/runtime/lib/worklet/workletRefPool.js +22 -0
  215. package/runtime/lib/worklet/workletRefPool.js.map +1 -0
  216. package/runtime/src/backgroundSnapshot.ts +452 -0
  217. package/runtime/src/compat/componentIs.ts +30 -0
  218. package/runtime/src/compat/initData.ts +140 -0
  219. package/runtime/src/compat/lynxComponent.ts +80 -0
  220. package/runtime/src/debug/debug.ts +9 -0
  221. package/runtime/src/debug/printSnapshot.ts +28 -0
  222. package/runtime/src/debug/profile.ts +54 -0
  223. package/runtime/src/document.ts +53 -0
  224. package/runtime/src/gesture/processGesture.ts +77 -0
  225. package/runtime/src/gesture/processGestureBagkround.ts +15 -0
  226. package/runtime/src/gesture/types.ts +39 -0
  227. package/runtime/src/hooks/react.ts +62 -0
  228. package/runtime/src/hooks/useLynxGlobalEventListener.ts +59 -0
  229. package/runtime/src/hydrate.ts +364 -0
  230. package/runtime/src/index.ts +89 -0
  231. package/runtime/src/internal.ts +60 -0
  232. package/runtime/src/legacy-react-runtime/index.ts +40 -0
  233. package/runtime/src/lifecycle/delayUnmount.ts +77 -0
  234. package/runtime/src/lifecycle/destroy.ts +26 -0
  235. package/runtime/src/lifecycle/pass.ts +14 -0
  236. package/runtime/src/lifecycle/patchUpdate.ts +240 -0
  237. package/runtime/src/lifecycle/reload.ts +79 -0
  238. package/runtime/src/lifecycle/render.ts +46 -0
  239. package/runtime/src/lifecycleConstant.ts +16 -0
  240. package/runtime/src/list.ts +375 -0
  241. package/runtime/src/lynx/calledByNative.ts +132 -0
  242. package/runtime/src/lynx/component.ts +116 -0
  243. package/runtime/src/lynx/dynamic-js.ts +33 -0
  244. package/runtime/src/lynx/env.ts +110 -0
  245. package/runtime/src/lynx/injectLepusMethods.ts +53 -0
  246. package/runtime/src/lynx/lazy-bundle.ts +126 -0
  247. package/runtime/src/lynx/performance.ts +117 -0
  248. package/runtime/src/lynx/tt.ts +212 -0
  249. package/runtime/src/lynx-api.ts +374 -0
  250. package/runtime/src/lynx.ts +105 -0
  251. package/runtime/src/opcodes.ts +64 -0
  252. package/runtime/src/renderToOpcodes/constants.ts +24 -0
  253. package/runtime/src/renderToOpcodes/index.ts +301 -0
  254. package/runtime/src/root.ts +19 -0
  255. package/runtime/src/snapshot/event.ts +33 -0
  256. package/runtime/src/snapshot/gesture.ts +25 -0
  257. package/runtime/src/snapshot/platformInfo.ts +48 -0
  258. package/runtime/src/snapshot/ref.ts +151 -0
  259. package/runtime/src/snapshot/spread.ts +287 -0
  260. package/runtime/src/snapshot/workletEvent.ts +33 -0
  261. package/runtime/src/snapshot/workletRef.ts +63 -0
  262. package/runtime/src/snapshot.ts +576 -0
  263. package/runtime/src/snapshotPatch.ts +56 -0
  264. package/runtime/src/snapshotPatchApply.ts +117 -0
  265. package/runtime/src/utils.ts +35 -0
  266. package/runtime/src/worklet/ctx.ts +22 -0
  267. package/runtime/src/worklet/execMap.ts +50 -0
  268. package/runtime/src/worklet/functionality.ts +12 -0
  269. package/runtime/src/worklet/hmr.ts +26 -0
  270. package/runtime/src/worklet/indexMap.ts +20 -0
  271. package/runtime/src/worklet/jsImpl.ts +86 -0
  272. package/runtime/src/worklet/runWorklet.ts +88 -0
  273. package/runtime/src/worklet/workletRef.ts +229 -0
  274. package/runtime/src/worklet/workletRefPool.ts +25 -0
  275. package/transform/cjs/main.cjs +6 -0
  276. package/transform/cjs/main.d.cts +3 -0
  277. package/transform/cjs/package.json +3 -0
  278. package/transform/dist/wasm.cjs +8478 -0
  279. package/transform/index.d.ts +187 -0
  280. package/transform/main.js +15 -0
  281. package/types/react.d.ts +147 -0
  282. package/types/react.docs.d.ts +74 -0
  283. package/worklet-runtime/dist/dev.js +414 -0
  284. package/worklet-runtime/dist/dev.js.map +8 -0
  285. package/worklet-runtime/dist/main.js +414 -0
  286. package/worklet-runtime/dist/main.js.map +8 -0
  287. package/worklet-runtime/lib/api/element.d.ts +14 -0
  288. package/worklet-runtime/lib/api/element.js +71 -0
  289. package/worklet-runtime/lib/api/element.js.map +1 -0
  290. package/worklet-runtime/lib/api/lepusQuerySelector.d.ts +3 -0
  291. package/worklet-runtime/lib/api/lepusQuerySelector.js +23 -0
  292. package/worklet-runtime/lib/api/lepusQuerySelector.js.map +1 -0
  293. package/worklet-runtime/lib/api/lynxApi.d.ts +2 -0
  294. package/worklet-runtime/lib/api/lynxApi.js +35 -0
  295. package/worklet-runtime/lib/api/lynxApi.js.map +1 -0
  296. package/worklet-runtime/lib/bindings/bindings.d.ts +14 -0
  297. package/worklet-runtime/lib/bindings/bindings.js +61 -0
  298. package/worklet-runtime/lib/bindings/bindings.js.map +1 -0
  299. package/worklet-runtime/lib/bindings/events.d.ts +7 -0
  300. package/worklet-runtime/lib/bindings/events.js +9 -0
  301. package/worklet-runtime/lib/bindings/events.js.map +1 -0
  302. package/worklet-runtime/lib/bindings/index.d.ts +4 -0
  303. package/worklet-runtime/lib/bindings/index.js +7 -0
  304. package/worklet-runtime/lib/bindings/index.js.map +1 -0
  305. package/worklet-runtime/lib/bindings/loadRuntime.d.ts +8 -0
  306. package/worklet-runtime/lib/bindings/loadRuntime.js +25 -0
  307. package/worklet-runtime/lib/bindings/loadRuntime.js.map +1 -0
  308. package/worklet-runtime/lib/bindings/types.d.ts +35 -0
  309. package/worklet-runtime/lib/bindings/types.js +2 -0
  310. package/worklet-runtime/lib/bindings/types.js.map +1 -0
  311. package/worklet-runtime/lib/delayWorkletEvent.d.ts +11 -0
  312. package/worklet-runtime/lib/delayWorkletEvent.js +49 -0
  313. package/worklet-runtime/lib/delayWorkletEvent.js.map +1 -0
  314. package/worklet-runtime/lib/global.d.ts +15 -0
  315. package/worklet-runtime/lib/global.js +2 -0
  316. package/worklet-runtime/lib/global.js.map +1 -0
  317. package/worklet-runtime/lib/index.d.ts +1 -0
  318. package/worklet-runtime/lib/index.js +12 -0
  319. package/worklet-runtime/lib/index.js.map +1 -0
  320. package/worklet-runtime/lib/jsFunctionLifecycle.d.ts +18 -0
  321. package/worklet-runtime/lib/jsFunctionLifecycle.js +55 -0
  322. package/worklet-runtime/lib/jsFunctionLifecycle.js.map +1 -0
  323. package/worklet-runtime/lib/listeners.d.ts +2 -0
  324. package/worklet-runtime/lib/listeners.js +17 -0
  325. package/worklet-runtime/lib/listeners.js.map +1 -0
  326. package/worklet-runtime/lib/utils/profile.d.ts +1 -0
  327. package/worklet-runtime/lib/utils/profile.js +20 -0
  328. package/worklet-runtime/lib/utils/profile.js.map +1 -0
  329. package/worklet-runtime/lib/utils/version.d.ts +1 -0
  330. package/worklet-runtime/lib/utils/version.js +10 -0
  331. package/worklet-runtime/lib/utils/version.js.map +1 -0
  332. package/worklet-runtime/lib/workletRef.d.ts +12 -0
  333. package/worklet-runtime/lib/workletRef.js +50 -0
  334. package/worklet-runtime/lib/workletRef.js.map +1 -0
  335. package/worklet-runtime/lib/workletRuntime.d.ts +2 -0
  336. package/worklet-runtime/lib/workletRuntime.js +128 -0
  337. package/worklet-runtime/lib/workletRuntime.js.map +1 -0
@@ -0,0 +1,414 @@
1
+ "use strict";
2
+ (() => {
3
+ var __defProp = Object.defineProperty;
4
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
5
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
6
+
7
+ // src/api/element.ts
8
+ var _Element = class _Element {
9
+ constructor(element) {
10
+ // @ts-ignore set in constructor
11
+ __publicField(this, "element");
12
+ Object.defineProperty(this, "element", {
13
+ get() {
14
+ return element;
15
+ }
16
+ });
17
+ }
18
+ setAttribute(name, value) {
19
+ __SetAttribute(this.element, name, value);
20
+ this.flushElementTree();
21
+ }
22
+ setStyleProperty(name, value) {
23
+ __AddInlineStyle(this.element, name, value);
24
+ this.flushElementTree();
25
+ }
26
+ setStyleProperties(styles) {
27
+ for (const key in styles) {
28
+ __AddInlineStyle(this.element, key, styles[key]);
29
+ }
30
+ this.flushElementTree();
31
+ }
32
+ getAttribute(attributeName) {
33
+ return __GetAttributeByName(this.element, attributeName);
34
+ }
35
+ getAttributeNames() {
36
+ return __GetAttributeNames(this.element);
37
+ }
38
+ querySelector(selector) {
39
+ const ref = __QuerySelector(this.element, selector, {});
40
+ return ref ? new _Element(ref) : null;
41
+ }
42
+ querySelectorAll(selector) {
43
+ return __QuerySelectorAll(this.element, selector, {}).map((element) => {
44
+ return new _Element(element);
45
+ });
46
+ }
47
+ invoke(methodName, params) {
48
+ return new Promise((resolve, reject) => {
49
+ __InvokeUIMethod(
50
+ this.element,
51
+ methodName,
52
+ params || {},
53
+ (res) => {
54
+ if (res.code === 0) {
55
+ resolve(res.data);
56
+ } else {
57
+ reject(new Error("UI method invoke: " + JSON.stringify(res)));
58
+ }
59
+ }
60
+ );
61
+ this.flushElementTree();
62
+ });
63
+ }
64
+ flushElementTree() {
65
+ if (_Element.willFlush) {
66
+ return;
67
+ }
68
+ _Element.willFlush = true;
69
+ Promise.resolve().then(() => {
70
+ _Element.willFlush = false;
71
+ __FlushElementTree();
72
+ });
73
+ }
74
+ };
75
+ __publicField(_Element, "willFlush", false);
76
+ var Element = _Element;
77
+
78
+ // src/api/lepusQuerySelector.ts
79
+ var _PageElement = class _PageElement {
80
+ static get() {
81
+ if (_PageElement.pageElement === void 0) {
82
+ _PageElement.pageElement = __GetPageElement();
83
+ }
84
+ return _PageElement.pageElement;
85
+ }
86
+ };
87
+ __publicField(_PageElement, "pageElement");
88
+ var PageElement = _PageElement;
89
+ function querySelector(cssSelector) {
90
+ const element = __QuerySelector(PageElement.get(), cssSelector, {});
91
+ return element ? new Element(element) : null;
92
+ }
93
+ function querySelectorAll(cssSelector) {
94
+ return __QuerySelectorAll(PageElement.get(), cssSelector, {}).map(
95
+ (element) => {
96
+ return new Element(element);
97
+ }
98
+ );
99
+ }
100
+
101
+ // src/utils/version.ts
102
+ function isSdkVersionGt(major, minor) {
103
+ const lynxSdkVersion = SystemInfo.lynxSdkVersion || "1.0";
104
+ const version = lynxSdkVersion.split(".");
105
+ return Number(version[0]) > major || Number(version[0]) == major && Number(version[1]) > minor;
106
+ }
107
+
108
+ // src/api/lynxApi.ts
109
+ function initApiEnv() {
110
+ var _a;
111
+ lynx.querySelector = querySelector;
112
+ lynx.querySelectorAll = querySelectorAll;
113
+ globalThis.setTimeout = lynx.setTimeout;
114
+ globalThis.setInterval = lynx.setInterval;
115
+ globalThis.clearTimeout = lynx.clearTimeout;
116
+ globalThis.clearInterval = (_a = lynx.clearInterval) != null ? _a : lynx.clearTimeInterval;
117
+ {
118
+ const requestAnimationFrame = lynx.requestAnimationFrame;
119
+ lynx.requestAnimationFrame = globalThis.requestAnimationFrame = (callback) => {
120
+ if (!isSdkVersionGt(2, 15)) {
121
+ throw new Error(
122
+ "requestAnimationFrame in main thread script requires Lynx sdk version 2.16"
123
+ );
124
+ }
125
+ return requestAnimationFrame(callback);
126
+ };
127
+ }
128
+ globalThis.cancelAnimationFrame = lynx.cancelAnimationFrame;
129
+ }
130
+
131
+ // src/utils/profile.ts
132
+ function profile(sliceName, f) {
133
+ if (false) {
134
+ console.profile(sliceName);
135
+ try {
136
+ return f();
137
+ } finally {
138
+ console.profileEnd();
139
+ }
140
+ } else {
141
+ return f();
142
+ }
143
+ }
144
+
145
+ // src/workletRef.ts
146
+ var impl;
147
+ function initWorkletRef() {
148
+ return impl = {
149
+ _workletRefMap: {},
150
+ updateWorkletRef,
151
+ updateWorkletRefInitValueChanges
152
+ };
153
+ }
154
+ var createWorkletRef = (id, value) => {
155
+ return {
156
+ current: value,
157
+ _wvid: id
158
+ };
159
+ };
160
+ var getFromWorkletRefMap = (id) => {
161
+ const value = impl._workletRefMap[id];
162
+ if (false) {
163
+ throw new Error("Worklet: ref is not initialized: " + id);
164
+ }
165
+ return value;
166
+ };
167
+ function removeValueFromWorkletRefMap(id) {
168
+ delete impl._workletRefMap[id];
169
+ }
170
+ function updateWorkletRef(handle, element) {
171
+ getFromWorkletRefMap(handle._wvid).current = element ? new Element(element) : null;
172
+ }
173
+ function updateWorkletRefInitValueChanges(patch) {
174
+ profile("updateWorkletRefInitValueChanges", () => {
175
+ patch.forEach(([id, value]) => {
176
+ var _a, _b;
177
+ (_b = (_a = impl._workletRefMap)[id]) != null ? _b : _a[id] = createWorkletRef(id, value);
178
+ });
179
+ });
180
+ }
181
+
182
+ // src/listeners.ts
183
+ function initEventListeners() {
184
+ const jsContext = lynx.getJSContext();
185
+ jsContext.addEventListener(
186
+ "Lynx.Worklet.runWorkletCtx" /* runWorkletCtx */,
187
+ (event) => {
188
+ const data = JSON.parse(event.data);
189
+ runWorklet(data.worklet, data.params);
190
+ }
191
+ );
192
+ jsContext.addEventListener(
193
+ "Lynx.Worklet.releaseWorkletRef" /* releaseWorkletRef */,
194
+ (event) => {
195
+ removeValueFromWorkletRefMap(event.data.id);
196
+ }
197
+ );
198
+ }
199
+
200
+ // src/delayWorkletEvent.ts
201
+ var impl2;
202
+ function initEventDelay() {
203
+ return impl2 = {
204
+ _delayedWorkletParamsMap: /* @__PURE__ */ new Map(),
205
+ runDelayedWorklet,
206
+ clearDelayedWorklets
207
+ };
208
+ }
209
+ function delayExecUntilJsReady(hash, params) {
210
+ profile("delayExecUntilJsReady: " + hash, () => {
211
+ const map = impl2._delayedWorkletParamsMap;
212
+ const paramVec = map.get(hash);
213
+ if (paramVec) {
214
+ paramVec.push(params);
215
+ } else {
216
+ map.set(hash, [params]);
217
+ }
218
+ });
219
+ }
220
+ function runDelayedWorklet(worklet, element) {
221
+ profile("commitDelayedWorklet", () => {
222
+ const paramsVec = impl2._delayedWorkletParamsMap.get(
223
+ worklet._wkltId
224
+ );
225
+ if (paramsVec === void 0) {
226
+ return;
227
+ }
228
+ const leftParamsVec = [];
229
+ paramsVec.forEach((params) => {
230
+ var _a, _b;
231
+ if (((_b = (_a = params[0]) == null ? void 0 : _a.currentTarget) == null ? void 0 : _b.elementRefptr) === element) {
232
+ setTimeout(() => {
233
+ profile("runDelayedWorklet", () => {
234
+ runWorklet(worklet, params);
235
+ });
236
+ }, 0);
237
+ } else {
238
+ leftParamsVec.push(params);
239
+ }
240
+ });
241
+ impl2._delayedWorkletParamsMap.set(
242
+ worklet._wkltId,
243
+ leftParamsVec
244
+ );
245
+ });
246
+ }
247
+ function clearDelayedWorklets() {
248
+ impl2._delayedWorkletParamsMap.clear();
249
+ }
250
+
251
+ // src/jsFunctionLifecycle.ts
252
+ var JsFunctionLifecycleManager = class {
253
+ constructor() {
254
+ __publicField(this, "execIdRefCount", /* @__PURE__ */ new Map());
255
+ __publicField(this, "execIdSetToFire", /* @__PURE__ */ new Set());
256
+ __publicField(this, "willFire", false);
257
+ __publicField(this, "registry");
258
+ this.registry = new FinalizationRegistry(this.removeRef.bind(this));
259
+ }
260
+ addRef(execId, objToRef) {
261
+ this.execIdRefCount.set(
262
+ execId,
263
+ (this.execIdRefCount.get(execId) || 0) + 1
264
+ );
265
+ this.registry.register(objToRef, execId);
266
+ }
267
+ removeRef(execId) {
268
+ const rc = this.execIdRefCount.get(execId);
269
+ if (rc > 1) {
270
+ this.execIdRefCount.set(execId, rc - 1);
271
+ return;
272
+ }
273
+ this.execIdRefCount.delete(execId);
274
+ this.execIdSetToFire.add(execId);
275
+ if (!this.willFire) {
276
+ this.willFire = true;
277
+ Promise.resolve().then(() => {
278
+ this.fire();
279
+ });
280
+ }
281
+ }
282
+ fire() {
283
+ profile("JsFunctionLifecycleManager.fire", () => {
284
+ lynx.getJSContext().dispatchEvent({
285
+ type: "Lynx.Worklet.releaseBackgroundWorkletCtx" /* releaseBackgroundWorkletCtx */,
286
+ data: Array.from(this.execIdSetToFire)
287
+ });
288
+ this.execIdSetToFire.clear();
289
+ this.willFire = false;
290
+ });
291
+ }
292
+ };
293
+ function enableRunOnBackground() {
294
+ return isSdkVersionGt(2, 15);
295
+ }
296
+
297
+ // src/workletRuntime.ts
298
+ function initWorklet() {
299
+ globalThis.lynxWorkletImpl = {
300
+ _workletMap: {},
301
+ _eventDelayImpl: initEventDelay(),
302
+ _refImpl: initWorkletRef()
303
+ };
304
+ if (enableRunOnBackground()) {
305
+ globalThis.lynxWorkletImpl._jsFunctionLifecycleManager = new JsFunctionLifecycleManager();
306
+ }
307
+ globalThis.registerWorklet = registerWorklet;
308
+ globalThis.registerWorkletInternal = registerWorklet;
309
+ globalThis.runWorklet = runWorklet2;
310
+ }
311
+ function registerWorklet(_type, id, worklet) {
312
+ lynxWorkletImpl._workletMap[id] = worklet;
313
+ }
314
+ function runWorklet2(ctx, params) {
315
+ if (!validateWorklet(ctx)) {
316
+ console.warn("Worklet: Invalid worklet object: " + JSON.stringify(ctx));
317
+ return;
318
+ }
319
+ if ("_lepusWorkletHash" in ctx) {
320
+ delayExecUntilJsReady(ctx._lepusWorkletHash, params);
321
+ return;
322
+ }
323
+ return runWorkletImpl(ctx, params);
324
+ }
325
+ function runWorkletImpl(ctx, params) {
326
+ const worklet = profile(
327
+ "transformWorkletCtx " + ctx._wkltId,
328
+ () => transformWorklet(ctx, true)
329
+ );
330
+ const params_ = profile(
331
+ "transformWorkletParams",
332
+ () => transformWorklet(params || [], false)
333
+ );
334
+ let result;
335
+ profile("runWorklet", () => {
336
+ result = worklet(...params_);
337
+ });
338
+ return result;
339
+ }
340
+ function validateWorklet(ctx) {
341
+ return typeof ctx === "object" && ctx !== null && ("_wkltId" in ctx || "_lepusWorkletHash" in ctx);
342
+ }
343
+ var workletCache = /* @__PURE__ */ new WeakMap();
344
+ function transformWorklet(ctx, isWorklet) {
345
+ if (typeof ctx !== "object" || ctx === null) {
346
+ return ctx;
347
+ }
348
+ if (isWorklet) {
349
+ const res = workletCache.get(ctx);
350
+ if (res) {
351
+ return res;
352
+ }
353
+ }
354
+ const worklet = { main: ctx };
355
+ transformWorkletInner(worklet, 0, ctx);
356
+ if (isWorklet) {
357
+ workletCache.set(ctx, worklet.main);
358
+ }
359
+ return worklet.main;
360
+ }
361
+ var transformWorkletInner = (obj, depth, ctx) => {
362
+ var _a;
363
+ const limit = 1e3;
364
+ if (++depth >= limit) {
365
+ throw new Error("Depth of value exceeds limit of " + limit + ".");
366
+ }
367
+ if (typeof obj !== "object" || obj === null) {
368
+ return;
369
+ }
370
+ for (const key in obj) {
371
+ const subObj = obj[key];
372
+ if (typeof subObj !== "object" || subObj === null) {
373
+ continue;
374
+ }
375
+ const isEventTarget = "elementRefptr" in subObj;
376
+ if (!isEventTarget) {
377
+ transformWorkletInner(subObj, depth, ctx);
378
+ }
379
+ if (isEventTarget) {
380
+ obj[key] = new Element(subObj["elementRefptr"]);
381
+ continue;
382
+ }
383
+ const isWorkletRef = "_wvid" in subObj;
384
+ if (isWorkletRef) {
385
+ obj[key] = getFromWorkletRefMap(
386
+ subObj._wvid
387
+ );
388
+ continue;
389
+ }
390
+ const isWorklet = "_wkltId" in subObj;
391
+ if (isWorklet) {
392
+ obj[key] = lynxWorkletImpl._workletMap[subObj._wkltId].bind({ ...subObj });
393
+ continue;
394
+ }
395
+ const isJsFn = "_jsFnId" in subObj;
396
+ if (isJsFn) {
397
+ subObj["_execId"] = ctx._execId;
398
+ (_a = lynxWorkletImpl._jsFunctionLifecycleManager) == null ? void 0 : _a.addRef(
399
+ ctx._execId,
400
+ subObj
401
+ );
402
+ continue;
403
+ }
404
+ }
405
+ };
406
+
407
+ // src/index.ts
408
+ if (globalThis.lynxWorkletImpl === void 0) {
409
+ initWorklet();
410
+ initApiEnv();
411
+ initEventListeners();
412
+ }
413
+ })();
414
+ //# sourceMappingURL=main.js.map
@@ -0,0 +1,8 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/api/element.ts", "../src/api/lepusQuerySelector.ts", "../src/utils/version.ts", "../src/api/lynxApi.ts", "../src/utils/profile.ts", "../src/workletRef.ts", "../src/listeners.ts", "../src/delayWorkletEvent.ts", "../src/jsFunctionLifecycle.ts", "../src/workletRuntime.ts", "../src/index.ts"],
4
+ "sourceRoot": "/home/runner/work/lynx-stack/lynx-stack/packages/react/worklet-runtime/src",
5
+ "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.\nexport class Element {\n private static willFlush = false;\n\n // @ts-ignore 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: any): void {\n __SetAttribute(this.element, name, value);\n this.flushElementTree();\n }\n\n public setStyleProperty(name: string, value: string): void {\n __AddInlineStyle(this.element, name, value);\n this.flushElementTree();\n }\n\n public setStyleProperties(styles: Record<string, string>): void {\n for (const key in styles) {\n __AddInlineStyle(this.element, key, styles[key]);\n }\n this.flushElementTree();\n }\n\n public getAttribute(attributeName: string): any {\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 invoke(\n methodName: string,\n params?: Record<string, any>,\n ): Promise<any> {\n return new Promise((resolve, reject) => {\n __InvokeUIMethod(\n this.element,\n methodName,\n params || {},\n (res: { code: number; data: any }) => {\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 (Element.willFlush) {\n return;\n }\n Element.willFlush = true;\n Promise.resolve().then(() => {\n Element.willFlush = false;\n __FlushElementTree();\n });\n }\n}\n", "// 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 { Element } from './element.js';\n\nclass PageElement {\n private static pageElement: ElementNode | undefined;\n\n static get() {\n if (PageElement.pageElement === undefined) {\n PageElement.pageElement = __GetPageElement();\n }\n return PageElement.pageElement;\n }\n}\n\nexport function querySelector(cssSelector: string): Element | null {\n const element = __QuerySelector(PageElement.get(), cssSelector, {});\n return element ? new Element(element) : null;\n}\n\nexport function querySelectorAll(cssSelector: string): Element[] {\n return __QuerySelectorAll(PageElement.get(), cssSelector, {}).map(\n (element) => {\n return new Element(element);\n },\n );\n}\n", "// 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.\nexport function isSdkVersionGt(major: number, minor: number): boolean {\n const lynxSdkVersion: string = SystemInfo.lynxSdkVersion || '1.0';\n const version = lynxSdkVersion.split('.');\n return (\n Number(version[0]) > major\n || (Number(version[0]) == major && Number(version[1]) > minor)\n );\n}\n", "// 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-ignore\n lynx.querySelector = querySelector;\n // @ts-ignore\n lynx.querySelectorAll = querySelectorAll;\n // @ts-ignore\n globalThis.setTimeout = lynx.setTimeout;\n // @ts-ignore\n globalThis.setInterval = lynx.setInterval;\n // @ts-ignore\n globalThis.clearTimeout = lynx.clearTimeout;\n // In lynx 2.14 `clearInterval` is mistakenly spelled as `clearTimeInterval`. This is fixed in lynx 2.15.\n // @ts-ignore\n globalThis.clearInterval = lynx.clearInterval ?? lynx.clearTimeInterval;\n\n {\n // @ts-ignore\n const requestAnimationFrame = lynx.requestAnimationFrame;\n // @ts-ignore\n lynx.requestAnimationFrame = globalThis.requestAnimationFrame = (\n callback: () => {},\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-ignore\n globalThis.cancelAnimationFrame = lynx.cancelAnimationFrame;\n}\n\nexport { initApiEnv };\n", "// 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.\nexport function profile<Ret, Fn extends (...args: any[]) => Ret>(\n sliceName: string,\n f: Fn,\n): Ret {\n /* v8 ignore next 9 */\n // TODO: change it to __PROFILE__\n if (__DEV__) {\n console.profile(sliceName);\n try {\n return f();\n } finally {\n console.profileEnd();\n }\n } else {\n return f();\n }\n}\n", "// 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 { Element } from './api/element.js';\nimport type { WorkletRef, WorkletRefId, WorkletRefImpl } from './bindings/types.js';\nimport { profile } from './utils/profile.js';\n\ninterface RefImpl {\n _workletRefMap: Record<WorkletRefId, WorkletRef<unknown>>;\n updateWorkletRef(\n handle: WorkletRefImpl<Element>,\n element: ElementNode | null,\n ): void;\n updateWorkletRefInitValueChanges(patch: [number, unknown][]): void;\n}\n\nlet impl: RefImpl | undefined;\n\nfunction initWorkletRef(): RefImpl {\n return (impl = {\n _workletRefMap: {},\n updateWorkletRef,\n updateWorkletRefInitValueChanges,\n });\n}\n\nconst createWorkletRef = <T>(\n id: WorkletRefId,\n value: T,\n): WorkletRef<T> => {\n return {\n current: value,\n _wvid: id,\n };\n};\n\nconst getFromWorkletRefMap = (\n id: WorkletRefId,\n): WorkletRef<unknown> => {\n const value = impl!._workletRefMap[id];\n /* v8 ignore next 3 */\n if (__DEV__ && value === undefined) {\n throw new Error('Worklet: ref is not initialized: ' + id);\n }\n return value!;\n};\n\nfunction removeValueFromWorkletRefMap(id: WorkletRefId): void {\n delete impl!._workletRefMap[id];\n}\n\n/**\n * Create an element instance of the given element node, then set worklet value to it.\n * This is called in `snapshotContextUpdateWorkletRef`.\n * @param handle handle of the worklet value.\n * @param element the element node.\n */\nfunction updateWorkletRef(\n handle: WorkletRefImpl<Element>,\n element: ElementNode | null,\n): void {\n getFromWorkletRefMap(handle._wvid).current = element\n ? new Element(element)\n : null;\n}\n\nfunction updateWorkletRefInitValueChanges(\n patch: [WorkletRefId, unknown][],\n): void {\n profile('updateWorkletRefInitValueChanges', () => {\n patch.forEach(([id, value]) => {\n impl!._workletRefMap[id] ??= createWorkletRef(id, value);\n });\n });\n}\n\nexport {\n type RefImpl,\n initWorkletRef,\n getFromWorkletRefMap,\n removeValueFromWorkletRefMap,\n updateWorkletRefInitValueChanges,\n};\n", "// 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 { removeValueFromWorkletRefMap } from './workletRef.js';\nimport { WorkletEvents } from './bindings/events.js';\n\nfunction initEventListeners(): void {\n const jsContext = lynx.getJSContext();\n jsContext.addEventListener(\n WorkletEvents.runWorkletCtx,\n (event: RuntimeProxy.Event) => {\n const data = JSON.parse(event.data);\n runWorklet(data.worklet, data.params);\n },\n );\n jsContext.addEventListener(\n WorkletEvents.releaseWorkletRef,\n (event: RuntimeProxy.Event) => {\n removeValueFromWorkletRefMap(event.data.id);\n },\n );\n}\n\nexport { initEventListeners };\n", "// 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 // @ts-ignore\n if (params[0]?.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", "// 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 { WorkletEvents } from './bindings/events.js';\nimport { profile } from './utils/profile.js';\nimport { isSdkVersionGt } from './utils/version.js';\n\n/**\n * `JsFunctionLifecycleManager` monitors references to JS function handles to be called by `runOnBackground()`.\n * In JS context, functions to be called by `runOnBackground()` is referenced by `JsFnHandle`s and finally by `execId`.\n * When all `JsFnHandle`s in lepus are released, an event will be sent to JS context to de-ref the `execId`,\n * resulting a de-ref to the js function in JS context.\n */\nclass JsFunctionLifecycleManager {\n private execIdRefCount = new Map<number, number>();\n private execIdSetToFire = new Set<number>();\n private willFire = false;\n private registry?: FinalizationRegistry<number> = undefined;\n\n constructor() {\n this.registry = new FinalizationRegistry<number>(this.removeRef.bind(this));\n }\n\n addRef(execId: number, objToRef: object): void {\n this.execIdRefCount.set(\n execId,\n (this.execIdRefCount.get(execId) || 0) + 1,\n );\n this.registry!.register(objToRef, execId);\n }\n\n removeRef(execId: number): void {\n const rc = this.execIdRefCount.get(execId)!;\n if (rc > 1) {\n this.execIdRefCount.set(execId, rc - 1);\n return;\n }\n this.execIdRefCount.delete(execId);\n this.execIdSetToFire.add(execId);\n if (!this.willFire) {\n this.willFire = true;\n Promise.resolve().then(() => {\n this.fire();\n });\n }\n }\n\n fire(): void {\n profile('JsFunctionLifecycleManager.fire', () => {\n lynx.getJSContext().dispatchEvent({\n type: WorkletEvents.releaseBackgroundWorkletCtx,\n data: Array.from(this.execIdSetToFire),\n });\n this.execIdSetToFire.clear();\n this.willFire = false;\n });\n }\n}\n\nfunction enableRunOnBackground(): boolean {\n return isSdkVersionGt(2, 15);\n}\n\nexport { JsFunctionLifecycleManager, enableRunOnBackground };\n", "// 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 { Element } from './api/element.js';\nimport type { ClosureValueType, Worklet, WorkletRefImpl } from './bindings/types.js';\nimport { delayExecUntilJsReady, initEventDelay } from './delayWorkletEvent.js';\nimport { enableRunOnBackground, JsFunctionLifecycleManager } from './jsFunctionLifecycle.js';\nimport { profile } from './utils/profile.js';\nimport { getFromWorkletRefMap, initWorkletRef } from './workletRef.js';\n\nfunction initWorklet(): void {\n globalThis.lynxWorkletImpl = {\n _workletMap: {},\n _eventDelayImpl: initEventDelay(),\n _refImpl: initWorkletRef(),\n };\n\n if (enableRunOnBackground()) {\n globalThis.lynxWorkletImpl._jsFunctionLifecycleManager = new JsFunctionLifecycleManager();\n }\n\n globalThis.registerWorklet = registerWorklet;\n globalThis.registerWorkletInternal = registerWorklet;\n globalThis.runWorklet = runWorklet;\n}\n\n/**\n * Register a worklet function, allowing it to be executed by `runWorklet()`.\n * This is called in lepus.js.\n * @param _type worklet type, 'main-thread' or 'ui'\n * @param id worklet hash\n * @param worklet worklet function\n */\nfunction registerWorklet(_type: string, id: string, worklet: Function): void {\n lynxWorkletImpl._workletMap[id] = worklet;\n}\n\n/**\n * Entrance of all worklet calls.\n * Native event touch handler will call this function.\n * @param ctx worklet object.\n * @param params worklet params.\n */\nfunction runWorklet(ctx: Worklet, params: ClosureValueType[]): unknown {\n if (!validateWorklet(ctx)) {\n console.warn('Worklet: Invalid worklet object: ' + JSON.stringify(ctx));\n return;\n }\n if ('_lepusWorkletHash' in ctx) {\n delayExecUntilJsReady(ctx._lepusWorkletHash, params);\n return;\n }\n return runWorkletImpl(ctx, params);\n}\n\nfunction runWorkletImpl(ctx: Worklet, params: ClosureValueType[]): unknown {\n const worklet: Function = profile(\n 'transformWorkletCtx ' + ctx._wkltId,\n () => transformWorklet(ctx, true),\n );\n const params_: ClosureValueType[] = profile(\n 'transformWorkletParams',\n () => transformWorklet(params || [], false),\n );\n\n let result;\n profile('runWorklet', () => {\n result = worklet(...params_);\n });\n return result;\n}\n\nfunction validateWorklet(ctx: unknown): ctx is Worklet {\n return typeof ctx === 'object' && ctx !== null && ('_wkltId' in ctx || '_lepusWorkletHash' in ctx);\n}\n\nconst workletCache = new WeakMap<object, ClosureValueType | Function>();\n\nfunction transformWorklet(ctx: Worklet, isWorklet: true): Function;\nfunction transformWorklet(\n ctx: ClosureValueType[],\n isWorklet: false,\n): ClosureValueType[];\n\nfunction transformWorklet(\n ctx: ClosureValueType,\n isWorklet: boolean,\n): ClosureValueType | Function {\n /* v8 ignore next 3 */\n if (typeof ctx !== 'object' || ctx === null) {\n return ctx;\n }\n\n if (isWorklet) {\n const res = workletCache.get(ctx);\n if (res) {\n return res;\n }\n }\n\n const worklet = { main: ctx };\n transformWorkletInner(worklet, 0, ctx);\n\n if (isWorklet) {\n workletCache.set(ctx, worklet.main);\n }\n return worklet.main;\n}\n\nconst transformWorkletInner = (\n obj: ClosureValueType,\n depth: number,\n ctx: unknown,\n) => {\n const limit = 1000;\n if (++depth >= limit) {\n throw new Error('Depth of value exceeds limit of ' + limit + '.');\n }\n /* v8 ignore next 3 */\n if (typeof obj !== 'object' || obj === null) {\n return;\n }\n for (const key in obj) {\n // @ts-ignore\n const subObj: ClosureValueType = obj[key];\n if (typeof subObj !== 'object' || subObj === null) {\n continue;\n }\n\n const isEventTarget = 'elementRefptr' in subObj;\n if (!isEventTarget) {\n transformWorkletInner(subObj, depth, ctx);\n }\n\n if (isEventTarget) {\n // @ts-ignore\n obj[key] = new Element(subObj['elementRefptr'] as ElementNode);\n continue;\n }\n const isWorkletRef = '_wvid' in (subObj as object);\n if (isWorkletRef) {\n // @ts-ignore\n obj[key] = getFromWorkletRefMap(\n (subObj as any as WorkletRefImpl<unknown>)._wvid,\n );\n continue;\n }\n const isWorklet = '_wkltId' in subObj;\n if (isWorklet) {\n // `subObj` is worklet ctx. Shallow copy it to prevent the transformed worklet from referencing ctx.\n // This would result in the value of `workletCache` referencing its key.\n // @ts-ignore\n obj[key] = lynxWorkletImpl._workletMap[(subObj as Worklet)._wkltId]!\n .bind({ ...subObj });\n continue;\n }\n const isJsFn = '_jsFnId' in subObj;\n if (isJsFn) {\n subObj['_execId'] = (ctx as Worklet)._execId;\n lynxWorkletImpl._jsFunctionLifecycleManager?.addRef(\n (ctx as Worklet)._execId!,\n subObj,\n );\n continue;\n }\n }\n};\n\nexport { initWorklet };\n", "// 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 { initApiEnv } from './api/lynxApi.js';\nimport { initEventListeners } from './listeners.js';\nimport { initWorklet } from './workletRuntime.js';\n\nif (globalThis.lynxWorkletImpl === undefined) {\n initWorklet();\n initApiEnv();\n initEventListeners();\n}\n"],
6
+ "mappings": ";;;;;;;AAGO,MAAM,WAAN,MAAM,SAAQ;AAAA,IAMnB,YAAY,SAAsB;AAFlC;AAAA,0BAAiB;AAMf,aAAO,eAAe,MAAM,WAAW;AAAA,QACrC,MAAM;AACJ,iBAAO;AAAA,QACT;AAAA,MACF,CAAC;AAAA,IACH;AAAA,IAEO,aAAa,MAAc,OAAkB;AAClD,qBAAe,KAAK,SAAS,MAAM,KAAK;AACxC,WAAK,iBAAiB;AAAA,IACxB;AAAA,IAEO,iBAAiB,MAAc,OAAqB;AACzD,uBAAiB,KAAK,SAAS,MAAM,KAAK;AAC1C,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AAQ;AACd,QAAI,EAAE,SAAS,OAAO;AACpB,YAAM,IAAI,MAAM,qCAAqC,QAAQ,GAAG;AAAA,IAClE;AAEA,QAAI,OAAO,QAAQ,YAAY,QAAQ,MAAM;AAC3C;AAAA,IACF;AACA,eAAW,OAAO,KAAK;AAErB,YAAM,SAA2B,IAAI,GAAG;AACxC,UAAI,OAAO,WAAW,YAAY,WAAW,MAAM;AACjD;AAAA,MACF;AAEA,YAAM,gBAAgB,mBAAmB;AACzC,UAAI,CAAC,eAAe;AAClB,8BAAsB,QAAQ,OAAO,GAAG;AAAA,MAC1C;AAEA,UAAI,eAAe;AAEjB,YAAI,GAAG,IAAI,IAAI,QAAQ,OAAO,eAAe,CAAgB;AAC7D;AAAA,MACF;AACA,YAAM,eAAe,WAAY;AACjC,UAAI,cAAc;AAEhB,YAAI,GAAG,IAAI;AAAA,UACR,OAA0C;AAAA,QAC7C;AACA;AAAA,MACF;AACA,YAAM,YAAY,aAAa;AAC/B,UAAI,WAAW;AAIb,YAAI,GAAG,IAAI,gBAAgB,YAAa,OAAmB,OAAO,EAC/D,KAAK,EAAE,GAAG,OAAO,CAAC;AACrB;AAAA,MACF;AACA,YAAM,SAAS,aAAa;AAC5B,UAAI,QAAQ;AACV,eAAO,SAAS,IAAK,IAAgB;AACrC,8BAAgB,gCAAhB,mBAA6C;AAAA,UAC1C,IAAgB;AAAA,UACjB;AAAA;AAEF;AAAA,MACF;AAAA,IACF;AAAA,EACF;;;AC/JA,MAAI,WAAW,oBAAoB,QAAW;AAC5C,gBAAY;AACZ,eAAW;AACX,uBAAmB;AAAA,EACrB;",
7
+ "names": ["impl", "runWorklet"]
8
+ }
@@ -0,0 +1,14 @@
1
+ export declare class Element {
2
+ private static willFlush;
3
+ private readonly element;
4
+ constructor(element: ElementNode);
5
+ setAttribute(name: string, value: any): void;
6
+ setStyleProperty(name: string, value: string): void;
7
+ setStyleProperties(styles: Record<string, string>): void;
8
+ getAttribute(attributeName: string): any;
9
+ getAttributeNames(): string[];
10
+ querySelector(selector: string): Element | null;
11
+ querySelectorAll(selector: string): Element[];
12
+ invoke(methodName: string, params?: Record<string, any>): Promise<any>;
13
+ private flushElementTree;
14
+ }
@@ -0,0 +1,71 @@
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
+ export class Element {
5
+ static willFlush = false;
6
+ // @ts-ignore set in constructor
7
+ element;
8
+ constructor(element) {
9
+ // In Lynx versions prior to and including 2.15,
10
+ // a crash occurs when printing or transferring refCounted across threads.
11
+ // Bypass this problem by hiding the element object.
12
+ Object.defineProperty(this, 'element', {
13
+ get() {
14
+ return element;
15
+ },
16
+ });
17
+ }
18
+ setAttribute(name, value) {
19
+ __SetAttribute(this.element, name, value);
20
+ this.flushElementTree();
21
+ }
22
+ setStyleProperty(name, value) {
23
+ __AddInlineStyle(this.element, name, value);
24
+ this.flushElementTree();
25
+ }
26
+ setStyleProperties(styles) {
27
+ for (const key in styles) {
28
+ __AddInlineStyle(this.element, key, styles[key]);
29
+ }
30
+ this.flushElementTree();
31
+ }
32
+ getAttribute(attributeName) {
33
+ return __GetAttributeByName(this.element, attributeName);
34
+ }
35
+ getAttributeNames() {
36
+ return __GetAttributeNames(this.element);
37
+ }
38
+ querySelector(selector) {
39
+ const ref = __QuerySelector(this.element, selector, {});
40
+ return ref ? new Element(ref) : null;
41
+ }
42
+ querySelectorAll(selector) {
43
+ return __QuerySelectorAll(this.element, selector, {}).map((element) => {
44
+ return new Element(element);
45
+ });
46
+ }
47
+ invoke(methodName, params) {
48
+ return new Promise((resolve, reject) => {
49
+ __InvokeUIMethod(this.element, methodName, params || {}, (res) => {
50
+ if (res.code === 0) {
51
+ resolve(res.data);
52
+ }
53
+ else {
54
+ reject(new Error('UI method invoke: ' + JSON.stringify(res)));
55
+ }
56
+ });
57
+ this.flushElementTree();
58
+ });
59
+ }
60
+ flushElementTree() {
61
+ if (Element.willFlush) {
62
+ return;
63
+ }
64
+ Element.willFlush = true;
65
+ Promise.resolve().then(() => {
66
+ Element.willFlush = false;
67
+ __FlushElementTree();
68
+ });
69
+ }
70
+ }
71
+ //# sourceMappingURL=element.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"element.js","sourceRoot":"","sources":["../../src/api/element.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAC1D,MAAM,OAAO,OAAO;IACV,MAAM,CAAC,SAAS,GAAG,KAAK,CAAC;IAEjC,gCAAgC;IACf,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,KAAU;QAC1C,cAAc,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC;QAC1C,IAAI,CAAC,gBAAgB,EAAE,CAAC;IAC1B,CAAC;IAEM,gBAAgB,CAAC,IAAY,EAAE,KAAa;QACjD,gBAAgB,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC;QAC5C,IAAI,CAAC,gBAAgB,EAAE,CAAC;IAC1B,CAAC;IAEM,kBAAkB,CAAC,MAA8B;QACtD,KAAK,MAAM,GAAG,IAAI,MAAM,EAAE,CAAC;YACzB,gBAAgB,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;QACnD,CAAC;QACD,IAAI,CAAC,gBAAgB,EAAE,CAAC;IAC1B,CAAC;IAEM,YAAY,CAAC,aAAqB;QACvC,OAAO,oBAAoB,CAAC,IAAI,CAAC,OAAO,EAAE,aAAa,CAAC,CAAC;IAC3D,CAAC;IAEM,iB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,CAAC,IAAI,CAAC,GAAG,EAAE;YAC1B,OAAO,CAAC,SAAS,GAAG,KAAK,CAAC;YAC1B,kBAAkB,EAAE,CAAC;QACvB,CAAC,CAAC,CAAC;IACL,CAAC"}
@@ -0,0 +1,3 @@
1
+ import { Element } from './element.js';
2
+ export declare function querySelector(cssSelector: string): Element | null;
3
+ export declare function querySelectorAll(cssSelector: string): Element[];
@@ -0,0 +1,23 @@
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 { Element } from './element.js';
5
+ class PageElement {
6
+ static pageElement;
7
+ static get() {
8
+ if (PageElement.pageElement === undefined) {
9
+ PageElement.pageElement = __GetPageElement();
10
+ }
11
+ return PageElement.pageElement;
12
+ }
13
+ }
14
+ export function querySelector(cssSelector) {
15
+ const element = __QuerySelector(PageElement.get(), cssSelector, {});
16
+ return element ? new Element(element) : null;
17
+ }
18
+ export function querySelectorAll(cssSelector) {
19
+ return __QuerySelectorAll(PageElement.get(), cssSelector, {}).map((element) => {
20
+ return new Element(element);
21
+ });
22
+ }
23
+ //# sourceMappingURL=lepusQuerySelector.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lepusQuerySelector.js","sourceRoot":"","sources":["../../src/api/lepusQuerySelector.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAC1D,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC,MAAM,WAAW;IACP,MAAM,CAAC,WAAW,CAA0B;IAEpD,MAAM,CAAC,GAAG;QACR,IAAI,WAAW,CAAC,WAAW,KAAK,SAAS,EAAE,CAAC;YAC1C,WAAW,CAAC,WAAW,GAAG,gBAAgB,EAAE,CAAC;QAC/C,CAAC;QACD,OAAO,WAAW,CAAC,WAAW,CAAC;IACjC,CAAC;CACF;AAED,MAAM,UAAU,aAAa,CAAC,WAAmB;IAC/C,MAAM,OAAO,GAAG,eAAe,CAAC,WAAW,CAAC,GAAG,EAAE,EAAE,WAAW,EAAE,EAAE,CAAC,CAAC;IACpE,OAAO,OAAO,CAAC,CAAC,CAAC,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;AAC/C,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,WAAmB;IAClD,OAAO,kBAAkB,CAAC,WAAW,CAAC,GAAG,EAAE,EAAE,WAAW,EAAE,EAAE,CAAC,CAAC,GAAG,CAC/D,CAAC,OAAO,EAAE,EAAE;QACV,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC;IAC9B,CAAC,CACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,2 @@
1
+ declare function initApiEnv(): void;
2
+ export { initApiEnv };
@@ -0,0 +1,35 @@
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 { querySelector, querySelectorAll } from './lepusQuerySelector.js';
5
+ import { isSdkVersionGt } from '../utils/version.js';
6
+ function initApiEnv() {
7
+ // @ts-ignore
8
+ lynx.querySelector = querySelector;
9
+ // @ts-ignore
10
+ lynx.querySelectorAll = querySelectorAll;
11
+ // @ts-ignore
12
+ globalThis.setTimeout = lynx.setTimeout;
13
+ // @ts-ignore
14
+ globalThis.setInterval = lynx.setInterval;
15
+ // @ts-ignore
16
+ globalThis.clearTimeout = lynx.clearTimeout;
17
+ // In lynx 2.14 `clearInterval` is mistakenly spelled as `clearTimeInterval`. This is fixed in lynx 2.15.
18
+ // @ts-ignore
19
+ globalThis.clearInterval = lynx.clearInterval ?? lynx.clearTimeInterval;
20
+ {
21
+ // @ts-ignore
22
+ const requestAnimationFrame = lynx.requestAnimationFrame;
23
+ // @ts-ignore
24
+ lynx.requestAnimationFrame = globalThis.requestAnimationFrame = (callback) => {
25
+ if (!isSdkVersionGt(2, 15)) {
26
+ throw new Error('requestAnimationFrame in main thread script requires Lynx sdk version 2.16');
27
+ }
28
+ return requestAnimationFrame(callback);
29
+ };
30
+ }
31
+ // @ts-ignore
32
+ globalThis.cancelAnimationFrame = lynx.cancelAnimationFrame;
33
+ }
34
+ export { initApiEnv };
35
+ //# sourceMappingURL=lynxApi.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lynxApi.js","sourceRoot":"","sources":["../../src/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,aAAa;IACb,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;IACnC,aAAa;IACb,IAAI,CAAC,gBAAgB,GAAG,gBAAgB,CAAC;IACzC,aAAa;IACb,UAAU,CAAC,UAAU,GAAG,IAAI,CAAC,UAAU,CAAC;IACxC,aAAa;IACb,UAAU,CAAC,WAAW,GAAG,IAAI,CAAC,WAAW,CAAC;IAC1C,aAAa;IACb,UAAU,CAAC,YAAY,GAAG,IAAI,CAAC,YAAY,CAAC;IAC5C,yGAAyG;IACzG,aAAa;IACb,UAAU,CAAC,aAAa,GAAG,IAAI,CAAC,aAAa,IAAI,IAAI,CAAC,iBAAiB,CAAC;IAExE,CAAC;QACC,aAAa;QACb,MAAM,qBAAqB,GAAG,IAAI,CAAC,qBAAqB,CAAC;QACzD,aAAa;QACb,IAAI,CAAC,qBAAqB,GAAG,UAAU,CAAC,qBAAqB,GAAG,CAC9D,QAAkB,EAClB,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,aAAa;IACb,UAAU,CAAC,oBAAoB,GAAG,IAAI,CAAC,oBAAoB,CAAC;AAC9D,CAAC;AAED,OAAO,EAAE,UAAU,EAAE,CAAC"}
@@ -0,0 +1,14 @@
1
+ import type { ClosureValueType, Worklet } from './types.js';
2
+ /**
3
+ * Executes the worklet ctx.
4
+ * @param worklet - The Worklet ctx to run.
5
+ * @param params - An array as parameters of the worklet run.
6
+ */
7
+ declare function runWorkletCtx(worklet: Worklet, params: ClosureValueType[]): unknown;
8
+ /**
9
+ * Update the initial value of the `WorkletRef`.
10
+ *
11
+ * @param patch - An array containing the index and new value of the worklet value.
12
+ */
13
+ declare function updateWorkletRefInitValueChanges(patch?: [number, unknown][]): void;
14
+ export { onWorkletCtxUpdate, runWorkletCtx, updateWorkletRef, updateWorkletRefInitValueChanges, clearDelayedWorklets, registerWorklet, };