@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,311 @@
1
+ import type { Consumer, FC, ReactNode } from 'react';
2
+ import { withInitDataInState } from './compat/initData.js';
3
+ /**
4
+ * The default root exported by `@lynx-js/react` for you to render a JSX
5
+ * @public
6
+ */
7
+ export interface Root {
8
+ /**
9
+ * Use this API to pass in your JSX to render
10
+ *
11
+ * @example
12
+ *
13
+ * ```ts
14
+ * import { root } from "@lynx-js/react"
15
+ *
16
+ * function App() {
17
+ * // Your app
18
+ * return <view>...</view>
19
+ * }
20
+ *
21
+ * root.render(<App/>);
22
+ * ```
23
+ *
24
+ * @example
25
+ *
26
+ * ```tsx
27
+ * import { root } from "@lynx-js/react"
28
+ *
29
+ * function App() {
30
+ * // Your app
31
+ * return <view>...</view>
32
+ * }
33
+ *
34
+ * if (__LEPUS__) {
35
+ * root.render(
36
+ * <DataProvider data={DEFAULT_DATA}>
37
+ * <App/>
38
+ * </DataProvider>
39
+ * );
40
+ * } else if (__JS__) {
41
+ * fetchData().then((data) => {
42
+ * root.render(
43
+ * <DataProvider data={data}>
44
+ * <App/>
45
+ * </DataProvider>
46
+ * ); // You can render later after your data is ready
47
+ * })
48
+ * }
49
+ * ```
50
+ *
51
+ * @public
52
+ */
53
+ render: (jsx: ReactNode) => void;
54
+ /**
55
+ * {@inheritDoc Lynx.registerDataProcessors}
56
+ * @deprecated use {@link Lynx.registerDataProcessors | lynx.registerDataProcessors} instead
57
+ * @public
58
+ */
59
+ registerDataProcessors: (dataProcessorDefinition: DataProcessorDefinition) => void;
60
+ }
61
+ /**
62
+ * The default and only root of ReactLynx for you to render JSX
63
+ * @example
64
+ * ```ts
65
+ * import { root } from "@lynx-js/react"
66
+ * ```
67
+ *
68
+ * @public
69
+ */
70
+ export declare const root: Root;
71
+ /**
72
+ * The {@link https://react.dev/reference/react/createContext#provider | Provider} Component that provide `initData`,
73
+ * you must wrap your JSX inside it
74
+ * @group Components
75
+ *
76
+ * @example
77
+ *
78
+ * ```ts
79
+ * import { root } from "@lynx-js/react"
80
+ *
81
+ * function App() {
82
+ * return (
83
+ * <InitDataConsumer children={(initData) => <view>...</view>}/>
84
+ * )
85
+ * }
86
+ *
87
+ * root.render(
88
+ * <InitDataProvider>
89
+ * <App/>
90
+ * </InitDataProvider>
91
+ * );
92
+ *
93
+ * ```
94
+ *
95
+ * @public
96
+ */
97
+ export declare const InitDataProvider: FC<{
98
+ children?: ReactNode | undefined;
99
+ }>;
100
+ /**
101
+ * The {@link https://react.dev/reference/react/createContext#consumer | Consumer} Component that provide `initData`.
102
+ * This should be used with {@link InitDataProvider}
103
+ * @group Components
104
+ * @public
105
+ */
106
+ export declare const InitDataConsumer: Consumer<InitData>;
107
+ /**
108
+ * A React Hooks for you to get `initData`.
109
+ * If `initData` is changed, a re-render will be triggered automatically.
110
+ *
111
+ * @example
112
+ *
113
+ * ```ts
114
+ * function App() {
115
+ * const initData = useInitData();
116
+ *
117
+ * initData.someProperty // use it
118
+ * }
119
+ * ```
120
+ *
121
+ * @public
122
+ */
123
+ export declare const useInitData: () => InitData;
124
+ /**
125
+ * A React Hooks for you to get notified when `initData` changed.
126
+ *
127
+ * @example
128
+ * ```ts
129
+ * function App() {
130
+ * useInitDataChanged((data) => {
131
+ * data.someProperty // can use it
132
+ * })
133
+ * }
134
+ * ```
135
+ * @public
136
+ */
137
+ export declare const useInitDataChanged: (callback: (data: InitData) => void) => void;
138
+ /**
139
+ * The interface you can extends so that the `defaultDataProcessor` parameter can be customized
140
+ *
141
+ * Should be used with `lynx.registerDataProcessors`. See more examples at {@link Lynx.registerDataProcessors}.
142
+ *
143
+ * @public
144
+ */
145
+ export interface InitDataRaw {
146
+ }
147
+ /**
148
+ * The interface you can extends so that the `defaultDataProcessor` returning value can be customized
149
+ *
150
+ * Should be used with `lynx.registerDataProcessors`. See more examples at {@link Lynx.registerDataProcessors}.
151
+ *
152
+ * @public
153
+ */
154
+ export interface InitData {
155
+ }
156
+ export { withInitDataInState };
157
+ /**
158
+ * Definition of DataProcessor(s)
159
+ * @public
160
+ */
161
+ export interface DataProcessorDefinition {
162
+ /**
163
+ * You can custom input and output type of `defaultDataProcessor` by extends {@link InitDataRaw} and {@link InitData}
164
+ *
165
+ * Should be used with `lynx.registerDataProcessors`. See more examples at {@link Lynx.registerDataProcessors}.
166
+ *
167
+ * @param rawInitData - initData passed from native code
168
+ * @returns
169
+ * @public
170
+ */
171
+ defaultDataProcessor?: (rawInitData: InitDataRaw) => InitData;
172
+ /**
173
+ * Should be used with `lynx.registerDataProcessors`. See more examples at {@link Lynx.registerDataProcessors}.
174
+ *
175
+ * @public
176
+ */
177
+ dataProcessors?: Record<string, Function>;
178
+ }
179
+ /**
180
+ * APIs under `lynx` global variable that added by ReactLynx.
181
+ *
182
+ * @example
183
+ *
184
+ * ```ts
185
+ * lynx.registerDataProcessors(...);
186
+ * lynx.querySelector(...);
187
+ * lynx.querySelectorAll(...);
188
+ * ```
189
+ *
190
+ * @public
191
+ */
192
+ export interface Lynx {
193
+ /**
194
+ * An alias of `lynx.getJSModule("GlobalEventEmitter").trigger(eventName, params)` only in Lepus
195
+ *
196
+ * @public
197
+ */
198
+ triggerGlobalEventFromLepus: (eventName: string, params: any) => void;
199
+ /**
200
+ * Register DataProcessors. You MUST call this before `root.render()`.
201
+ *
202
+ * @example
203
+ *
204
+ * You MUST call `lynx.registerDataProcessors` before calling `root.render()`.
205
+ *
206
+ * ```ts
207
+ * import { root } from "@lynx-js/react"
208
+ *
209
+ * // You MUST call this before `root.render()`
210
+ * lynx.registerDataProcessors({
211
+ * defaultDataProcessor: () => {...} // default DataProcessor
212
+ * dataProcessors: {
213
+ * getScreenMetricsOverride: () => {...} // named DataProcessor
214
+ * }
215
+ * })
216
+ *
217
+ * root.render(<App/>);
218
+ * ```
219
+ *
220
+ * @example
221
+ *
222
+ * If you have a class component with `static defaultDataProcessor`
223
+ * or `static dataProcessors`, you can use it to register DataProcessors.
224
+ *
225
+ * ```ts
226
+ * import { root, Component } from "@lynx-js/react"
227
+ *
228
+ * class App extends Component {
229
+ * static defaultDataProcessor() {
230
+ * ...
231
+ * }
232
+ *
233
+ * static dataProcessors = {
234
+ * getScreenMetricsOverride() {
235
+ * ...
236
+ * }
237
+ * }
238
+ * }
239
+ *
240
+ * lynx.registerDataProcessors(App); // You can pass `App` because it has the required shape
241
+ * root.render(<App/>);
242
+ * ```
243
+ *
244
+ * @example
245
+ *
246
+ * For developers who want fully typed `defaultDataProcessor`,
247
+ * they can achieve it by extends interface `InitDataRaw` and `InitData`.
248
+ *
249
+ * ```ts
250
+ * import { root } from "@lynx-js/react"
251
+ *
252
+ * interface ExistingInterface {
253
+ * somePropertyFromExistingInterface: number
254
+ * }
255
+ *
256
+ * declare module '@lynx-js/react' {
257
+ * interface InitDataRaw extends ExistingInterface {
258
+ * someAnotherCustomProperty: string
259
+ * }
260
+ * }
261
+ *
262
+ * lynx.registerDataProcessors({
263
+ * defaultDataProcessor: (initDataRaw) => {
264
+ * initDataRaw.somePropertyFromExistingInterface // will be typed
265
+ * }
266
+ * })
267
+ *
268
+ * ```
269
+ *
270
+ * @example
271
+ *
272
+ * For developers who want fully typed `defaultDataProcessor`,
273
+ * they can achieve it by extends interface `InitDataRaw` and `InitData`.
274
+ *
275
+ * ```ts
276
+ * import { root, useInitData } from "@lynx-js/react"
277
+ *
278
+ * interface AnotherExistingInterface {
279
+ * someAnotherPropertyFromExistingInterface: number
280
+ * }
281
+ *
282
+ * declare module '@lynx-js/react' {
283
+ * interface InitData extends AnotherExistingInterface {
284
+ * someCustomProperty: string
285
+ * }
286
+ * }
287
+ *
288
+ * root.registerDataProcessors({
289
+ * defaultDataProcessor: () => {
290
+ * return {
291
+ * someCustomProperty: 'value', // will be typed
292
+ * someAnotherPropertyFromExistingInterface: 1, // will be typed
293
+ * }
294
+ * }
295
+ * })
296
+ *
297
+ * function App() {
298
+ * const initData = useInitData();
299
+ *
300
+ * initData.someCustomProperty // will be typed
301
+ * initData.someAnotherPropertyFromExistingInterface // will be typed
302
+ * }
303
+ *
304
+ * ```
305
+ * @public
306
+ */
307
+ registerDataProcessors: (dataProcessorDefinition: DataProcessorDefinition) => void;
308
+ }
309
+ export { runOnBackground, runOnMainThread } from './worklet/runWorklet.js';
310
+ export { MainThreadRef, useMainThreadRef } from './worklet/workletRef.js';
311
+ export { useLynxGlobalEventListener } from './hooks/useLynxGlobalEventListener.js';
@@ -0,0 +1,116 @@
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 { render } from 'preact';
5
+ import { createContext, createElement } from 'preact/compat';
6
+ import { useState } from 'preact/hooks';
7
+ import { factory, withInitDataInState } from './compat/initData.js';
8
+ import { LifecycleConstant } from './lifecycleConstant.js';
9
+ import { flushDelayedLifecycleEvents } from './lynx/tt.js';
10
+ import { useLynxGlobalEventListener } from './hooks/useLynxGlobalEventListener.js';
11
+ import { __root } from './root.js';
12
+ /**
13
+ * The default and only root of ReactLynx for you to render JSX
14
+ * @example
15
+ * ```ts
16
+ * import { root } from "@lynx-js/react"
17
+ * ```
18
+ *
19
+ * @public
20
+ */
21
+ export const root = {
22
+ render: (jsx) => {
23
+ if (__LEPUS__) {
24
+ __root.__jsx = jsx;
25
+ }
26
+ else {
27
+ __root.__jsx = jsx;
28
+ render(jsx, __root);
29
+ if (__FIRST_SCREEN_SYNC_TIMING__ === 'immediately') {
30
+ }
31
+ else {
32
+ lynx.getNativeApp().callLepusMethod(LifecycleConstant.jsReady, {});
33
+ }
34
+ flushDelayedLifecycleEvents();
35
+ }
36
+ },
37
+ registerDataProcessors: (dataProcessorDefinition) => {
38
+ lynx.registerDataProcessors(dataProcessorDefinition);
39
+ },
40
+ };
41
+ const _InitData = /* @__PURE__ */ factory({
42
+ createContext,
43
+ useState,
44
+ createElement,
45
+ useLynxGlobalEventListener,
46
+ }, '__initData', 'onDataChanged');
47
+ /**
48
+ * The {@link https://react.dev/reference/react/createContext#provider | Provider} Component that provide `initData`,
49
+ * you must wrap your JSX inside it
50
+ * @group Components
51
+ *
52
+ * @example
53
+ *
54
+ * ```ts
55
+ * import { root } from "@lynx-js/react"
56
+ *
57
+ * function App() {
58
+ * return (
59
+ * <InitDataConsumer children={(initData) => <view>...</view>}/>
60
+ * )
61
+ * }
62
+ *
63
+ * root.render(
64
+ * <InitDataProvider>
65
+ * <App/>
66
+ * </InitDataProvider>
67
+ * );
68
+ *
69
+ * ```
70
+ *
71
+ * @public
72
+ */
73
+ export const InitDataProvider = /* @__PURE__ */ _InitData.Provider();
74
+ /**
75
+ * The {@link https://react.dev/reference/react/createContext#consumer | Consumer} Component that provide `initData`.
76
+ * This should be used with {@link InitDataProvider}
77
+ * @group Components
78
+ * @public
79
+ */
80
+ export const InitDataConsumer = /* @__PURE__ */ _InitData.Consumer();
81
+ /**
82
+ * A React Hooks for you to get `initData`.
83
+ * If `initData` is changed, a re-render will be triggered automatically.
84
+ *
85
+ * @example
86
+ *
87
+ * ```ts
88
+ * function App() {
89
+ * const initData = useInitData();
90
+ *
91
+ * initData.someProperty // use it
92
+ * }
93
+ * ```
94
+ *
95
+ * @public
96
+ */
97
+ export const useInitData = /* @__PURE__ */ _InitData.use();
98
+ /**
99
+ * A React Hooks for you to get notified when `initData` changed.
100
+ *
101
+ * @example
102
+ * ```ts
103
+ * function App() {
104
+ * useInitDataChanged((data) => {
105
+ * data.someProperty // can use it
106
+ * })
107
+ * }
108
+ * ```
109
+ * @public
110
+ */
111
+ export const useInitDataChanged = /* @__PURE__ */ _InitData.useChanged();
112
+ export { withInitDataInState };
113
+ export { runOnBackground, runOnMainThread } from './worklet/runWorklet.js';
114
+ export { MainThreadRef, useMainThreadRef } from './worklet/workletRef.js';
115
+ export { useLynxGlobalEventListener } from './hooks/useLynxGlobalEventListener.js';
116
+ //# sourceMappingURL=lynx-api.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lynx-api.js","sourceRoot":"","sources":["../src/lynx-api.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAC1D,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAC7D,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAGxC,OAAO,EAAE,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AACpE,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,2BAA2B,EAAE,MAAM,cAAc,CAAC;AAC3D,OAAO,EAAE,0BAA0B,EAAE,MAAM,uCAAuC,CAAC;AACnF,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AA6DnC;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,IAAI,GAAS;IACxB,MAAM,EAAE,CAAC,GAAc,EAAQ,EAAE;QAC/B,IAAI,SAAS,EAAE,CAAC;YACd,MAAM,CAAC,KAAK,GAAG,GAAG,CAAC;QACrB,CAAC;aAAM,CAAC;YACN,MAAM,CAAC,KAAK,GAAG,GAAG,CAAC;YACnB,MAAM,CAAC,GAAG,EAAE,MAAa,CAAC,CAAC;YAC3B,IAAI,4BAA4B,KAAK,aAAa,EAAE,CAAC;YACrD,CAAC;iBAAM,CAAC;gBACN,IAAI,CAAC,YAAY,EAAE,CAAC,eAAe,CAAC,iBAAiB,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;YACrE,CAAC;YAED,2BAA2B,EAAE,CAAC;QAChC,CAAC;IACH,CAAC;IACD,sBAAsB,EAAE,CAAC,uBAAgD,EAAQ,EAAE;QACjF,IAAI,CAAC,sBAAsB,CAAC,uBAAuB,CAAC,CAAC;IACvD,CAAC;CACF,CAAC;AAEF,MAAM,SAAS,GAAG,eAAe,CAAC,OAAO,CACvC;IACE,aAAa;IACb,QAAQ;IACR,aAAa;IACb,0BAA0B;CACpB,EACR,YAAY,EACZ,eAAe,CAChB,CAAC;AACF;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAA6C,eAAe,CAAC,SAAS,CAAC,QAAQ,EAAE,CAAC;AAC/G;;;;;GAKG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAuB,eAAe,CAAC,SAAS,CAAC,QAAQ,EAAE,CAAC;AACzF;;;;;;;;;;;;;;;GAeG;AACH,MAAM,CAAC,MAAM,WAAW,GAAmB,eAAe,CAAC,SAAS,CAAC,GAAG,EAAE,CAAC;AAC3E;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAiD,eAAe,CAAC,SAAS,CAAC,UAAU,EAAE,CAAC;AAsCvH,OAAO,EAAE,mBAAmB,EAAE,CAAC;AA6J/B,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC3E,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC1E,OAAO,EAAE,0BAA0B,EAAE,MAAM,uCAAuC,CAAC"}
@@ -0,0 +1,2 @@
1
+ import './hooks/react.js';
2
+ export declare function runWithForce(cb: () => void): void;
@@ -0,0 +1,91 @@
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 { options } from 'preact';
5
+ // to make sure preact's hooks to register earlier than ours
6
+ import './hooks/react.js';
7
+ import { initProfileHook } from './debug/profile.js';
8
+ import { document, setupBackgroundDocument } from './document.js';
9
+ import { initDelayUnmount } from './lifecycle/delayUnmount.js';
10
+ import { injectUpdatePatch, replaceCommitHook, replaceRequestAnimationFrame } from './lifecycle/patchUpdate.js';
11
+ import { injectCalledByNative } from './lynx/calledByNative.js';
12
+ import { setupLynxEnv } from './lynx/env.js';
13
+ import { injectLepusMethods } from './lynx/injectLepusMethods.js';
14
+ import { initTimingAPI } from './lynx/performance.js';
15
+ import { injectTt } from './lynx/tt.js';
16
+ import { COMPONENT, DIFF, DIFFED, FORCE } from './renderToOpcodes/constants.js';
17
+ // @ts-expect-error Element implicitly has an 'any' type because type 'typeof globalThis' has no index signature
18
+ if (__LEPUS__ && typeof globalThis.processEvalResult === 'undefined') {
19
+ // @ts-expect-error Element implicitly has an 'any' type because type 'typeof globalThis' has no index signature
20
+ globalThis.processEvalResult = (result, schema) => {
21
+ return result(schema);
22
+ };
23
+ }
24
+ export function runWithForce(cb) {
25
+ // save vnode and its `_component` in WeakMap
26
+ const m = new WeakMap();
27
+ const oldDiff = options[DIFF];
28
+ options[DIFF] = (vnode) => {
29
+ if (oldDiff) {
30
+ oldDiff(vnode);
31
+ }
32
+ // when `options[DIFF]` is called, a newVnode is passed in
33
+ // so its `vnode[COMPONENT]` should be null,
34
+ // but it will be set later
35
+ Object.defineProperty(vnode, COMPONENT, {
36
+ configurable: true,
37
+ set(c) {
38
+ m.set(vnode, c);
39
+ if (c) {
40
+ c[FORCE] = true;
41
+ }
42
+ },
43
+ get() {
44
+ return m.get(vnode);
45
+ },
46
+ });
47
+ };
48
+ const oldDiffed = options[DIFFED];
49
+ options[DIFFED] = (vnode) => {
50
+ if (oldDiffed) {
51
+ oldDiffed(vnode);
52
+ }
53
+ // delete is a reverse operation of previous `Object.defineProperty`
54
+ delete vnode[COMPONENT];
55
+ // restore
56
+ vnode[COMPONENT] = m.get(vnode);
57
+ };
58
+ try {
59
+ cb();
60
+ }
61
+ finally {
62
+ options[DIFF] = oldDiff;
63
+ options[DIFFED] = oldDiffed;
64
+ }
65
+ }
66
+ if (__LEPUS__) {
67
+ injectCalledByNative();
68
+ injectUpdatePatch();
69
+ if (__DEV__) {
70
+ injectLepusMethods();
71
+ }
72
+ }
73
+ // TODO: replace this with __PROFILE__
74
+ if (__PROFILE__) {
75
+ // We are profiling both main-thread and background.
76
+ initProfileHook();
77
+ }
78
+ if (__JS__) {
79
+ options.document = document;
80
+ setupBackgroundDocument();
81
+ injectTt();
82
+ if (process.env['NODE_ENV'] === 'test') { }
83
+ else {
84
+ replaceCommitHook();
85
+ replaceRequestAnimationFrame();
86
+ initTimingAPI();
87
+ initDelayUnmount();
88
+ }
89
+ }
90
+ setupLynxEnv();
91
+ //# sourceMappingURL=lynx.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lynx.js","sourceRoot":"","sources":["../src/lynx.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,2 @@
1
+ import { SnapshotInstance } from './snapshot.js';
2
+ export declare function renderOpcodesInto(opcodes: any[], into: SnapshotInstance): void;
@@ -0,0 +1,59 @@
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 { CHILDREN } from './renderToOpcodes/constants.js';
5
+ import { SnapshotInstance } from './snapshot.js';
6
+ var Opcode;
7
+ (function (Opcode) {
8
+ Opcode[Opcode["Begin"] = 0] = "Begin";
9
+ Opcode[Opcode["End"] = 1] = "End";
10
+ Opcode[Opcode["Attr"] = 2] = "Attr";
11
+ Opcode[Opcode["Text"] = 3] = "Text";
12
+ })(Opcode || (Opcode = {}));
13
+ export function renderOpcodesInto(opcodes, into) {
14
+ let top = into;
15
+ const stack = [into];
16
+ for (let i = 0; i < opcodes.length;) {
17
+ const opcode = opcodes[i];
18
+ switch (opcode) {
19
+ case Opcode.Begin: {
20
+ const p = top;
21
+ top = opcodes[i + 1];
22
+ // @ts-ignore
23
+ if (top.__parent) {
24
+ // already inserted
25
+ top = new SnapshotInstance(top.type);
26
+ }
27
+ p.insertBefore(top);
28
+ stack.push(top);
29
+ i += 2;
30
+ break;
31
+ }
32
+ case Opcode.End: {
33
+ // @ts-ignore
34
+ top[CHILDREN] = undefined;
35
+ stack.pop();
36
+ const p = stack[stack.length - 1];
37
+ top = p;
38
+ i += 1;
39
+ break;
40
+ }
41
+ case Opcode.Attr: {
42
+ const key = opcodes[i + 1];
43
+ const value = opcodes[i + 2];
44
+ top.setAttribute(key, value);
45
+ i += 3;
46
+ break;
47
+ }
48
+ case Opcode.Text: {
49
+ const text = opcodes[i + 1];
50
+ const s = new SnapshotInstance(null);
51
+ s.setAttribute(0, text);
52
+ top.insertBefore(s);
53
+ i += 2;
54
+ break;
55
+ }
56
+ }
57
+ }
58
+ }
59
+ //# sourceMappingURL=opcodes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"opcodes.js","sourceRoot":"","sources":["../src/opcodes.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAC1D,OAAO,EAAE,QAAQ,EAAE,MAAM,gCAAgC,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAEjD,IAAW,MAKV;AALD,WAAW,MAAM;IACf,qCAAS,CAAA;IACT,iCAAG,CAAA;IACH,mCAAI,CAAA;IACJ,mCAAI,CAAA;AACN,CAAC,EALU,MAAM,KAAN,MAAM,QAKhB;AAED,MAAM,UAAU,iBAAiB,CAAC,OAAc,EAAE,IAAsB;IACtE,IAAI,GAAG,GAAqB,IAAI,CAAC;IACjC,MAAM,KAAK,GAAuB,CAAC,IAAI,CAAC,CAAC;IACzC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,MAAM,GAAG,CAAC;QACpC,MAAM,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;QAC1B,QAAQ,MAAM,EAAE,CAAC;YACf,KAAK,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;gBAClB,MAAM,CAAC,GAAG,GAAG,CAAC;gBACd,GAAG,GAAG,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;gBACrB,aAAa;gBACb,IAAI,GAAG,CAAC,QAAQ,EAAE,CAAC;oBACjB,mBAAmB;oBACnB,GAAG,GAAG,IAAI,gBAAgB,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;gBACvC,CAAC;gBACD,CAAC,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC;gBACpB,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;gBAEhB,CAAC,IAAI,CAAC,CAAC;gBACP,MAAM;YACR,CAAC;YACD,KAAK,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;gBAChB,aAAa;gBACb,GAAG,CAAC,QAAQ,CAAC,GAAG,SAAS,CAAC;gBAE1B,KAAK,CAAC,GAAG,EAAE,CAAC;gBACZ,MAAM,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;gBAClC,GAAG,GAAG,CAAE,CAAC;gBAET,CAAC,IAAI,CAAC,CAAC;gBACP,MAAM;YACR,CAAC;YACD,KAAK,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC;gBACjB,MAAM,GAAG,GAAG,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;gBAC3B,MAAM,KAAK,GAAG,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;gBAC7B,GAAG,CAAC,YAAY,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;gBAE7B,CAAC,IAAI,CAAC,CAAC;gBACP,MAAM;YACR,CAAC;YACD,KAAK,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC;gBACjB,MAAM,IAAI,GAAG,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;gBAC5B,MAAM,CAAC,GAAG,IAAI,gBAAgB,CAAC,IAAyB,CAAC,CAAC;gBAC1D,CAAC,CAAC,YAAY,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC;gBACxB,GAAG,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;gBAEpB,CAAC,IAAI,CAAC,CAAC;gBACP,MAAM;YACR,CAAC;QACH,CAAC;IACH,CAAC;AACH,CAAC"}
@@ -0,0 +1,17 @@
1
+ export declare const DIFF = "__b";
2
+ export declare const RENDER = "__r";
3
+ export declare const DIFFED = "diffed";
4
+ export declare const COMMIT = "__c";
5
+ export declare const SKIP_EFFECTS = "__s";
6
+ export declare const CATCH_ERROR = "__e";
7
+ export declare const COMPONENT = "__c";
8
+ export declare const CHILDREN = "__k";
9
+ export declare const PARENT = "__";
10
+ export declare const MASK = "__m";
11
+ export declare const VNODE = "__v";
12
+ export declare const DIRTY = "__d";
13
+ export declare const FORCE = "__e";
14
+ export declare const NEXT_STATE = "__s";
15
+ export declare const CHILD_DID_SUSPEND = "__c";
16
+ export declare const RENDER_CALLBACKS = "__h";
17
+ export declare const HOOK = "__h";
@@ -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
+ export const DIFF = '__b';
5
+ export const RENDER = '__r';
6
+ export const DIFFED = 'diffed';
7
+ export const COMMIT = '__c';
8
+ export const SKIP_EFFECTS = '__s';
9
+ export const CATCH_ERROR = '__e';
10
+ // VNode properties
11
+ export const COMPONENT = '__c';
12
+ export const CHILDREN = '__k';
13
+ export const PARENT = '__';
14
+ export const MASK = '__m';
15
+ // Component properties
16
+ export const VNODE = '__v';
17
+ export const DIRTY = '__d';
18
+ export const FORCE = '__e';
19
+ export const NEXT_STATE = '__s';
20
+ export const CHILD_DID_SUSPEND = '__c';
21
+ export const RENDER_CALLBACKS = '__h';
22
+ export const HOOK = '__h';
23
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/renderToOpcodes/constants.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAC1D,MAAM,CAAC,MAAM,IAAI,GAAG,KAAK,CAAC;AAC1B,MAAM,CAAC,MAAM,MAAM,GAAG,KAAK,CAAC;AAC5B,MAAM,CAAC,MAAM,MAAM,GAAG,QAAQ,CAAC;AAC/B,MAAM,CAAC,MAAM,MAAM,GAAG,KAAK,CAAC;AAC5B,MAAM,CAAC,MAAM,YAAY,GAAG,KAAK,CAAC;AAClC,MAAM,CAAC,MAAM,WAAW,GAAG,KAAK,CAAC;AAEjC,mBAAmB;AACnB,MAAM,CAAC,MAAM,SAAS,GAAG,KAAK,CAAC;AAC/B,MAAM,CAAC,MAAM,QAAQ,GAAG,KAAK,CAAC;AAC9B,MAAM,CAAC,MAAM,MAAM,GAAG,IAAI,CAAC;AAC3B,MAAM,CAAC,MAAM,IAAI,GAAG,KAAK,CAAC;AAE1B,uBAAuB;AACvB,MAAM,CAAC,MAAM,KAAK,GAAG,KAAK,CAAC;AAC3B,MAAM,CAAC,MAAM,KAAK,GAAG,KAAK,CAAC;AAC3B,MAAM,CAAC,MAAM,KAAK,GAAG,KAAK,CAAC;AAC3B,MAAM,CAAC,MAAM,UAAU,GAAG,KAAK,CAAC;AAChC,MAAM,CAAC,MAAM,iBAAiB,GAAG,KAAK,CAAC;AACvC,MAAM,CAAC,MAAM,gBAAgB,GAAG,KAAK,CAAC;AACtC,MAAM,CAAC,MAAM,IAAI,GAAG,KAAK,CAAC"}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Render Preact JSX + Components to an HTML string.
3
+ * @param {VNode} vnode JSX Element / VNode to render
4
+ * @param {object} [context] Initial root context object
5
+ */
6
+ export declare function renderToString(vnode: any, context: any): any[];
7
+ export declare const __OpBegin = 0;
8
+ export declare const __OpEnd = 1;
9
+ export declare const __OpAttr = 2;
10
+ export declare const __OpText = 3;
11
+ export default renderToString;
12
+ export declare const render: typeof renderToString;
13
+ export declare const renderToStaticMarkup: typeof renderToString;