@lynx-js/react 0.129.0 → 0.129.1

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 (206) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/components/tsconfig.tsbuildinfo +1 -1
  3. package/package.json +3 -4
  4. package/refresh/.turbo/turbo-build.log +1 -1
  5. package/runtime/__test__/core/hooks/useLynxGlobalEventListener.test.jsx +1 -1
  6. package/runtime/__test__/element-template/imports/no-legacy-imports.test.ts +7 -6
  7. package/runtime/__test__/element-template/internal/legacy-internal-guardrail.test.ts +1 -2
  8. package/runtime/__test__/element-template/native/main-thread-api.test.ts +5 -2
  9. package/runtime/__test__/element-template/native/mts-destroy.test.ts +83 -0
  10. package/runtime/__test__/element-template/native/reload-dual-thread-communication.test.ts +3 -0
  11. package/runtime/__test__/element-template/native/reload.test.ts +31 -2
  12. package/runtime/__test__/element-template/runtime/background/update-timing.test.ts +15 -0
  13. package/runtime/__test__/element-template/runtime/patch/element-template-patch.test.tsx +197 -7
  14. package/runtime/__test__/element-template/runtime/patch/update-timing.test.ts +4 -1
  15. package/runtime/__test__/element-template/runtime/render/render-direct-suspense.test.ts +4 -1
  16. package/runtime/__test__/element-template/runtime/render/render-direct.test.ts +4 -1
  17. package/runtime/__test__/element-template/runtime/render/render-main-thread.test.ts +101 -1
  18. package/runtime/__test__/element-template/runtime/template/element-template-handle.test.ts +32 -0
  19. package/runtime/__test__/element-template/runtime/template/main-thread-dynamic-attr-state.test.ts +121 -26
  20. package/runtime/__test__/element-template/test-utils/debug/envManager.ts +8 -5
  21. package/runtime/__test__/element-template/test-utils/mock/mockNativePapi.ts +35 -2
  22. package/runtime/__test__/guardrails/snapshot-containment.test.ts +45 -11
  23. package/runtime/__test__/shared/component-stack.test.ts +211 -0
  24. package/runtime/__test__/snapshot/debug/formatPatch.test.ts +0 -8
  25. package/runtime/__test__/snapshot/gesture/prepareGestureForCommit.test.js +1 -1
  26. package/runtime/__test__/snapshot/lynx/timing.test.jsx +3 -0
  27. package/runtime/__test__/snapshot/preact.test.jsx +0 -3
  28. package/runtime/__test__/snapshot/snapshotPatch.test.jsx +0 -33
  29. package/runtime/__test__/worklet-runtime/jsFunctionLifecycle.test.js +12 -0
  30. package/runtime/__test__/worklet-runtime/loadRuntime.test.js +68 -0
  31. package/runtime/__test__/worklet-runtime/workletRuntime.test.js +30 -0
  32. package/runtime/lazy/element-template-internal.js +0 -1
  33. package/runtime/lazy/internal.js +1 -1
  34. package/runtime/lazy/jsx-dev-runtime.js +1 -1
  35. package/runtime/lazy/jsx-runtime.js +1 -1
  36. package/runtime/lazy/legacy-react-runtime.js +1 -1
  37. package/runtime/lazy/react-lepus.js +1 -1
  38. package/runtime/lazy/react.js +1 -1
  39. package/runtime/lib/core/capture-main-thread-object.js +2 -1
  40. package/runtime/lib/core/capture-main-thread-object.js.map +1 -1
  41. package/runtime/lib/core/compat/legacy-react-runtime.js +1 -1
  42. package/runtime/lib/core/compat/legacy-react-runtime.js.map +1 -1
  43. package/runtime/lib/core/lynx/lazy-bundle.js +1 -1
  44. package/runtime/lib/core/lynx/lazy-bundle.js.map +1 -1
  45. package/runtime/lib/core/lynx-data-processors.d.ts +125 -1
  46. package/runtime/lib/core/lynx-data-processors.js +3 -0
  47. package/runtime/lib/core/lynx-data-processors.js.map +1 -1
  48. package/runtime/lib/core/runtime-destroy.js +1 -1
  49. package/runtime/lib/core/runtime-destroy.js.map +1 -1
  50. package/runtime/lib/document.js +0 -5
  51. package/runtime/lib/document.js.map +1 -1
  52. package/runtime/lib/element-template/background/commit-hook.js +11 -12
  53. package/runtime/lib/element-template/background/commit-hook.js.map +1 -1
  54. package/runtime/lib/element-template/client/root.d.ts +1 -1
  55. package/runtime/lib/element-template/client/root.js.map +1 -1
  56. package/runtime/lib/element-template/index.d.ts +2 -2
  57. package/runtime/lib/element-template/index.js.map +1 -1
  58. package/runtime/lib/element-template/internal.d.ts +1 -1
  59. package/runtime/lib/element-template/internal.js +0 -13
  60. package/runtime/lib/element-template/internal.js.map +1 -1
  61. package/runtime/lib/element-template/lynx/env.js.map +1 -1
  62. package/runtime/lib/element-template/native/flush.d.ts +1 -0
  63. package/runtime/lib/element-template/native/flush.js +9 -0
  64. package/runtime/lib/element-template/native/flush.js.map +1 -0
  65. package/runtime/lib/element-template/native/main-thread-api.js +3 -7
  66. package/runtime/lib/element-template/native/main-thread-api.js.map +1 -1
  67. package/runtime/lib/element-template/native/mts-destroy.js +8 -2
  68. package/runtime/lib/element-template/native/mts-destroy.js.map +1 -1
  69. package/runtime/lib/element-template/native/patch-listener.js +57 -50
  70. package/runtime/lib/element-template/native/patch-listener.js.map +1 -1
  71. package/runtime/lib/element-template/native/reload-main-thread.js +2 -1
  72. package/runtime/lib/element-template/native/reload-main-thread.js.map +1 -1
  73. package/runtime/lib/element-template/protocol/types.js.map +1 -1
  74. package/runtime/lib/element-template/runtime/page/root-instance.d.ts +0 -1
  75. package/runtime/lib/element-template/runtime/page/root-instance.js.map +1 -1
  76. package/runtime/lib/element-template/runtime/patch.js +4 -0
  77. package/runtime/lib/element-template/runtime/patch.js.map +1 -1
  78. package/runtime/lib/element-template/runtime/render/render-components.js +4 -4
  79. package/runtime/lib/element-template/runtime/render/render-components.js.map +1 -1
  80. package/runtime/lib/element-template/runtime/render/render-main-thread.js +2 -0
  81. package/runtime/lib/element-template/runtime/render/render-main-thread.js.map +1 -1
  82. package/runtime/lib/element-template/runtime/template/main-thread-background-function.js +8 -1
  83. package/runtime/lib/element-template/runtime/template/main-thread-background-function.js.map +1 -1
  84. package/runtime/lib/element-template/runtime/template/main-thread-dynamic-attr-state.d.ts +1 -0
  85. package/runtime/lib/element-template/runtime/template/main-thread-dynamic-attr-state.js +41 -21
  86. package/runtime/lib/element-template/runtime/template/main-thread-dynamic-attr-state.js.map +1 -1
  87. package/runtime/lib/element-template/runtime/template/main-thread-ref-ctx.d.ts +1 -1
  88. package/runtime/lib/element-template/runtime/template/main-thread-ref-ctx.js.map +1 -1
  89. package/runtime/lib/internal.d.ts +1 -1
  90. package/runtime/lib/internal.js +1 -1
  91. package/runtime/lib/internal.js.map +1 -1
  92. package/runtime/lib/lynx-api.d.ts +2 -125
  93. package/runtime/lib/lynx-api.js.map +1 -1
  94. package/runtime/lib/shared/component-stack.d.ts +0 -4
  95. package/runtime/lib/shared/component-stack.js +21 -5
  96. package/runtime/lib/shared/component-stack.js.map +1 -1
  97. package/runtime/lib/snapshot/gesture/{processGestureBagkround.js → processGestureBackground.js} +1 -1
  98. package/runtime/lib/snapshot/gesture/processGestureBackground.js.map +1 -0
  99. package/runtime/lib/snapshot/lifecycle/patch/snapshotPatch.d.ts +0 -1
  100. package/runtime/lib/snapshot/lifecycle/patch/snapshotPatch.js +0 -5
  101. package/runtime/lib/snapshot/lifecycle/patch/snapshotPatch.js.map +1 -1
  102. package/runtime/lib/snapshot/lifecycle/patch/snapshotPatchApply.js +0 -10
  103. package/runtime/lib/snapshot/lifecycle/patch/snapshotPatchApply.js.map +1 -1
  104. package/runtime/lib/snapshot/lifecycle/patch/updateMainThread.js +56 -51
  105. package/runtime/lib/snapshot/lifecycle/patch/updateMainThread.js.map +1 -1
  106. package/runtime/lib/snapshot/list/listUpdateInfo.js +0 -30
  107. package/runtime/lib/snapshot/list/listUpdateInfo.js.map +1 -1
  108. package/runtime/lib/snapshot/lynx/calledByNative.js +11 -8
  109. package/runtime/lib/snapshot/lynx/calledByNative.js.map +1 -1
  110. package/runtime/lib/snapshot/renderToOpcodes/hydrate.js +0 -52
  111. package/runtime/lib/snapshot/renderToOpcodes/hydrate.js.map +1 -1
  112. package/runtime/lib/snapshot/renderToOpcodes/index.js +10 -10
  113. package/runtime/lib/snapshot/renderToOpcodes/index.js.map +1 -1
  114. package/runtime/lib/snapshot/renderToOpcodes/opcodes.js +0 -51
  115. package/runtime/lib/snapshot/renderToOpcodes/opcodes.js.map +1 -1
  116. package/runtime/lib/snapshot/snapshot/backgroundSnapshot.js +1 -1
  117. package/runtime/lib/snapshot/snapshot/backgroundSnapshot.js.map +1 -1
  118. package/runtime/lib/tsconfig.tsbuildinfo +1 -1
  119. package/runtime/lib/worklet-runtime/bindings/index.d.ts +1 -0
  120. package/runtime/lib/worklet-runtime/bindings/index.js +1 -0
  121. package/runtime/lib/worklet-runtime/bindings/index.js.map +1 -1
  122. package/runtime/lib/worklet-runtime/bindings/loadRuntime.d.ts +8 -0
  123. package/runtime/lib/worklet-runtime/bindings/loadRuntime.js +23 -0
  124. package/runtime/lib/worklet-runtime/bindings/loadRuntime.js.map +1 -0
  125. package/runtime/lib/worklet-runtime/jsFunctionLifecycle.d.ts +2 -0
  126. package/runtime/lib/worklet-runtime/jsFunctionLifecycle.js +6 -0
  127. package/runtime/lib/worklet-runtime/jsFunctionLifecycle.js.map +1 -1
  128. package/runtime/lib/worklet-runtime/workletRuntime.js +2 -0
  129. package/runtime/lib/worklet-runtime/workletRuntime.js.map +1 -1
  130. package/runtime/package.json +2 -3
  131. package/runtime/src/core/capture-main-thread-object.ts +2 -1
  132. package/runtime/src/core/compat/legacy-react-runtime.ts +1 -1
  133. package/runtime/src/core/lynx/lazy-bundle.ts +1 -1
  134. package/runtime/src/core/lynx-data-processors.ts +124 -1
  135. package/runtime/src/core/runtime-destroy.ts +1 -1
  136. package/runtime/src/document.ts +0 -6
  137. package/runtime/src/element-template/background/commit-hook.ts +18 -12
  138. package/runtime/src/element-template/client/root.ts +1 -3
  139. package/runtime/src/element-template/index.ts +2 -2
  140. package/runtime/src/element-template/internal.ts +0 -20
  141. package/runtime/src/element-template/lynx/env.ts +1 -1
  142. package/runtime/src/element-template/native/flush.ts +10 -0
  143. package/runtime/src/element-template/native/main-thread-api.ts +3 -6
  144. package/runtime/src/element-template/native/mts-destroy.ts +7 -2
  145. package/runtime/src/element-template/native/patch-listener.ts +62 -57
  146. package/runtime/src/element-template/native/reload-main-thread.ts +2 -1
  147. package/runtime/src/element-template/protocol/types.ts +0 -13
  148. package/runtime/src/element-template/runtime/page/root-instance.ts +0 -1
  149. package/runtime/src/element-template/runtime/patch.ts +5 -0
  150. package/runtime/src/element-template/runtime/render/render-components.ts +3 -3
  151. package/runtime/src/element-template/runtime/render/render-main-thread.ts +2 -0
  152. package/runtime/src/element-template/runtime/template/main-thread-background-function.ts +8 -1
  153. package/runtime/src/element-template/runtime/template/main-thread-dynamic-attr-state.ts +51 -21
  154. package/runtime/src/element-template/runtime/template/main-thread-ref-ctx.ts +2 -2
  155. package/runtime/src/element-template/types.d.ts +6 -0
  156. package/runtime/src/internal.ts +1 -1
  157. package/runtime/src/lynx-api.ts +2 -124
  158. package/runtime/src/shared/component-stack.ts +22 -5
  159. package/runtime/src/snapshot/lifecycle/patch/snapshotPatch.ts +0 -5
  160. package/runtime/src/snapshot/lifecycle/patch/snapshotPatchApply.ts +0 -10
  161. package/runtime/src/snapshot/lifecycle/patch/updateMainThread.ts +62 -58
  162. package/runtime/src/snapshot/list/listUpdateInfo.ts +0 -52
  163. package/runtime/src/snapshot/lynx/calledByNative.ts +11 -9
  164. package/runtime/src/snapshot/renderToOpcodes/hydrate.ts +0 -58
  165. package/runtime/src/snapshot/renderToOpcodes/index.ts +8 -8
  166. package/runtime/src/snapshot/renderToOpcodes/opcodes.ts +0 -57
  167. package/runtime/src/snapshot/snapshot/backgroundSnapshot.ts +1 -1
  168. package/runtime/src/worklet-runtime/README.md +30 -10
  169. package/runtime/src/worklet-runtime/bindings/index.ts +2 -0
  170. package/runtime/src/worklet-runtime/bindings/loadRuntime.ts +25 -0
  171. package/runtime/src/worklet-runtime/jsFunctionLifecycle.ts +6 -0
  172. package/runtime/src/worklet-runtime/workletRuntime.ts +2 -0
  173. package/runtime/vitest.config.ts +0 -2
  174. package/testing-library/.turbo/turbo-build.log +6 -6
  175. package/testing-library/src/__tests__/act.test.jsx +0 -7
  176. package/testing-library/src/__tests__/alog.test.jsx +12 -54
  177. package/testing-library/src/__tests__/end-to-end.test.jsx +0 -7
  178. package/testing-library/src/__tests__/renderComponent.test.jsx +0 -14
  179. package/testing-library/src/__tests__/worklet.test.jsx +49 -0
  180. package/transform/.turbo/turbo-build$colon$wasm.log +98 -376
  181. package/transform/__test__/defines.spec.js +30 -0
  182. package/transform/__test__/object-methods.spec.js +79 -0
  183. package/transform/crates/swc_plugin_worklet/extract_ident.rs +99 -49
  184. package/transform/crates/swc_plugin_worklet/gen_stmt.rs +56 -48
  185. package/transform/crates/swc_plugin_worklet/lib.rs +393 -589
  186. package/transform/crates/swc_plugin_worklet/napi.rs +4 -6
  187. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_2_js.js +6 -1
  188. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_2_lepus.js +7 -1
  189. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_js.js +9 -0
  190. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_lepus.js +12 -1
  191. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_preserve_main_thread_objects_in_class_js.js +1 -1
  192. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_preserve_main_thread_objects_in_class_lepus.js +1 -1
  193. package/transform/dist/wasm.cjs +1 -1
  194. package/transform/package.json +0 -1
  195. package/transform/src/lib.rs +1 -1
  196. package/transform/swc-plugin-reactlynx/.turbo/turbo-build.log +113 -42
  197. package/transform/swc-plugin-reactlynx/src/lib.rs +1 -4
  198. package/transform/swc-plugin-reactlynx/swc_plugin_reactlynx.wasm +0 -0
  199. package/transform/swc-plugin-reactlynx-compat/.turbo/turbo-build.log +273 -66
  200. package/runtime/lib/snapshot/gesture/processGestureBagkround.js.map +0 -1
  201. package/runtime/lib/snapshot/worklet/hmr.d.ts +0 -1
  202. package/runtime/lib/snapshot/worklet/hmr.js +0 -28
  203. package/runtime/lib/snapshot/worklet/hmr.js.map +0 -1
  204. package/runtime/src/snapshot/worklet/hmr.ts +0 -34
  205. /package/runtime/lib/snapshot/gesture/{processGestureBagkround.d.ts → processGestureBackground.d.ts} +0 -0
  206. /package/runtime/src/snapshot/gesture/{processGestureBagkround.ts → processGestureBackground.ts} +0 -0
@@ -1,6 +1,7 @@
1
1
  import type { Consumer, FC, ReactNode } from 'react';
2
2
  import type { GlobalProps } from './core/globalProps.js';
3
3
  import { withInitDataInState } from './core/initData.js';
4
+ import type { DataProcessorDefinition, DataProcessors, InitData, InitDataRaw } from './core/lynx-data-processors.js';
4
5
  /**
5
6
  * The default root exported by `@lynx-js/react` for you to render a JSX
6
7
  * @public
@@ -255,132 +256,8 @@ export declare const useGlobalProps: () => GlobalProps;
255
256
  * @group Hooks
256
257
  */
257
258
  export declare const useGlobalPropsChanged: (callback: (data: GlobalProps) => void) => void;
258
- /**
259
- * The interface you can extends so that the `defaultDataProcessor` parameter can be customized
260
- *
261
- * Should be used with `lynx.registerDataProcessors`. See more examples at {@link Lynx.registerDataProcessors}.
262
- *
263
- * @public
264
- *
265
- * @group Types
266
- */
267
- export interface InitDataRaw {
268
- }
269
- /**
270
- * The interface you can extends so that the `defaultDataProcessor` returning value can be customized
271
- *
272
- * Should be used with `lynx.registerDataProcessors`. See more examples at {@link Lynx.registerDataProcessors}.
273
- *
274
- * @public
275
- *
276
- * @group Types
277
- */
278
- export interface InitData {
279
- }
259
+ export type { DataProcessorDefinition, DataProcessors, InitData, InitDataRaw };
280
260
  export { withInitDataInState };
281
- /**
282
- * The data processors that registered with {@link Lynx.registerDataProcessors}.
283
- *
284
- * @example
285
- *
286
- * Extending `dataProcessors` interface
287
- *
288
- * ```ts
289
- * import type { DataProcessors as WellKnownDataProcessors } from '@lynx-js/react';
290
- *
291
- * declare module '@lynx-js/react' {
292
- * interface DataProcessors extends WellKnownDataProcessors {
293
- * foo(bar: string): number;
294
- * }
295
- * }
296
- * ```
297
- *
298
- * Then you can use `lynx.registerDataProcessors` with types.
299
- *
300
- * ```js
301
- * lynx.registerDataProcessors({
302
- * dataProcessors: {
303
- * foo(bar) {
304
- * return 1;
305
- * }
306
- * }
307
- * })
308
- * ```
309
- *
310
- * @public
311
- *
312
- * @group Types
313
- */
314
- export interface DataProcessors {
315
- /**
316
- * Optional processor to override screen metrics used by the app
317
- *
318
- * @param metrics - The physical screen dimensions in pixels
319
- *
320
- * @returns New screen dimensions to be used by the app
321
- *
322
- * @example
323
- *
324
- * ```ts
325
- * lynx.registerDataProcessors({
326
- * dataProcessors: {
327
- * getScreenMetricsOverride: (metrics) => {
328
- * // Force a specific aspect ratio
329
- * return {
330
- * width: metrics.width,
331
- * height: metrics.width * (16/9)
332
- * };
333
- * }
334
- * }
335
- * });
336
- * ```
337
- */
338
- getScreenMetricsOverride?(metrics: {
339
- /**
340
- * The physical pixel width of the screen
341
- */
342
- width: number;
343
- /**
344
- * The physical pixel height of the screen
345
- */
346
- height: number;
347
- }): {
348
- width: number;
349
- height: number;
350
- };
351
- /**
352
- * Custom unknown data processors.
353
- *
354
- * @remarks
355
- *
356
- * You may extends the `DataProcessors` interface for better TypeScript types. See {@link DataProcessors}.
357
- */
358
- [processorName: string]: (...args: any[]) => any;
359
- }
360
- /**
361
- * Definition of DataProcessor(s)
362
- * @public
363
- *
364
- * @group Types
365
- */
366
- export interface DataProcessorDefinition {
367
- /**
368
- * You can custom input and output type of `defaultDataProcessor` by extends {@link InitDataRaw} and {@link InitData}
369
- *
370
- * Should be used with `lynx.registerDataProcessors`. See more examples at {@link Lynx.registerDataProcessors}.
371
- *
372
- * @param rawInitData - initData passed from native code
373
- * @returns
374
- * @public
375
- */
376
- defaultDataProcessor?: (rawInitData: InitDataRaw) => InitData;
377
- /**
378
- * Should be used with `lynx.registerDataProcessors`. See more examples at {@link Lynx.registerDataProcessors}.
379
- *
380
- * @public
381
- */
382
- dataProcessors?: DataProcessors;
383
- }
384
261
  /**
385
262
  * APIs under `lynx` global variable that added by ReactLynx.
386
263
  *
@@ -1 +1 @@
1
- {"version":3,"file":"lynx-api.js","sourceRoot":"","sources":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BG;AACH,MAAM,CAAC,MAAM,WAAW,GAAmB,eAAe,CAAC,SAAS,CAAC,GAAG,EAAE,CAAC;AAC3E;;;;;;;;;;;;;;;GAeG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAiD,eAAe,CAAC,SAAS,CAAC,UAAU,EAAE,CAAC;AAIvH,MAAM,YAAY,GAAG,eAAe,CAAC,iBAAiB,CAAc;IAClE,aAAa;IACb,QAAQ;IACR,aAAa;IACb,0BAA0B;CAC3B,CAAC,CAAC;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,oDAAoD;AACpD,MAAM,CAAC,MAAM,mBAAmB,GAA6C,eAAe,CAAC,YAAY,CAAC,QAAQ,EAAE,CAAC;AAErH;;;;;;;;GAQG;AACH,oDAAoD;AACpD,MAAM,CAAC,MAAM,mBAAmB,GAA0B,eAAe,CAAC,YAAY,CAAC,QAAQ,EAAE,CAAC;AAElG;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,CAAC,MAAM,cAAc,GAAsB,eAAe,CAAC,YAAY,CAAC,GAAG,EAAE,CAAC;AAEpF;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAoD,eAAe,CAAC,YAAY;KAC/G,UAAU,EAAE,CAAC;AAuBhB,OAAO,EAAE,mBAAmB,EAAE,CAAC;AA+O/B,OAAO,EAAE,0BAA0B,EAAE,MAAM,4CAA4C,CAAC;AACxF,OAAO,EAAE,eAAe,EAAE,MAAM,iDAAiD,CAAC;AAClF,OAAO,EAAE,eAAe,EAAE,MAAM,4CAA4C,CAAC;AAC7E,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAC5E,OAAO,EAAE,0BAA0B,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC","sourcesContent":["// Copyright 2024 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\nimport { render } from 'preact';\nimport { createContext, createElement } from 'preact/compat';\nimport { useState } from 'preact/hooks';\nimport type { Consumer, FC, ReactNode } from 'react';\n\nimport { createGlobalProps } from './core/globalProps.js';\nimport type { GlobalProps } from './core/globalProps.js';\nimport { useLynxGlobalEventListener } from './core/hooks/useLynxGlobalEventListener.js';\nimport { factory, withInitDataInState } from './core/initData.js';\nimport { __root } from './root.js';\nimport { profileEnd, profileStart } from './shared/profile.js';\nimport { LifecycleConstant } from './snapshot/lifecycle/constant.js';\nimport { onFirstScreenSyncReady } from './snapshot/lifecycle/event/firstScreenSync.js';\nimport { flushDelayedLifecycleEvents } from './snapshot/lynx/tt.js';\n\n/**\n * The default root exported by `@lynx-js/react` for you to render a JSX\n * @public\n *\n * @group Types\n */\nexport interface Root {\n /**\n * Use this API to pass in your JSX to render\n *\n * @example\n *\n * ```ts\n * import { root } from \"@lynx-js/react\"\n *\n * function App() {\n * // Your app\n * return <view>...</view>\n * }\n *\n * root.render(<App/>);\n * ```\n *\n * @example\n *\n * ```tsx\n * import { root } from \"@lynx-js/react\"\n *\n * function App() {\n * // Your app\n * return <view>...</view>\n * }\n *\n * if (__MAIN_THREAD__) {\n * root.render(\n * <DataProvider data={DEFAULT_DATA}>\n * <App/>\n * </DataProvider>\n * );\n * } else if (__BACKGROUND__) {\n * fetchData().then((data) => {\n * root.render(\n * <DataProvider data={data}>\n * <App/>\n * </DataProvider>\n * ); // You can render later after your data is ready\n * })\n * }\n * ```\n *\n * @public\n */\n render: (jsx: ReactNode) => void;\n /**\n * {@inheritDoc Lynx.registerDataProcessors}\n * @deprecated use {@link Lynx.registerDataProcessors | lynx.registerDataProcessors} instead\n * @public\n */\n registerDataProcessors: (dataProcessorDefinition: DataProcessorDefinition) => void;\n}\n\n/**\n * The default and only root of ReactLynx for you to render JSX\n * @example\n * ```ts\n * import { root } from \"@lynx-js/react\"\n * ```\n *\n * @public\n *\n * @group Functions\n */\nexport const root: Root = {\n render: (jsx: ReactNode): void => {\n /* v8 ignore next 2 */\n if (typeof __MAIN_THREAD__ !== 'undefined' && __MAIN_THREAD__) {\n __root.__jsx = jsx;\n } else {\n __root.__jsx = jsx;\n if (typeof __PROFILE__ !== 'undefined' && __PROFILE__) {\n profileStart('ReactLynx::renderBackground');\n }\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n render(jsx, __root as any);\n if (typeof __PROFILE__ !== 'undefined' && __PROFILE__) {\n profileEnd();\n }\n if (__FIRST_SCREEN_SYNC_TIMING__ === 'jsReady') {\n // `jsReady` is a special case of the `manual` first-screen sync: the\n // framework marks ready automatically once the background is ready.\n lynx.getNativeApp().callLepusMethod(LifecycleConstant.firstScreenSyncReady, {});\n } else {\n // `immediately` or `manual`: the first screen is synced without waiting\n // for the background, so the `firstScreen` message might have been\n // reached when `root.render()` is called asynchronously.\n flushDelayedLifecycleEvents();\n }\n }\n },\n /* v8 ignore next 3 */\n registerDataProcessors: (dataProcessorDefinition: DataProcessorDefinition): void => {\n lynx.registerDataProcessors(dataProcessorDefinition);\n },\n};\n\n/**\n * Mark the first screen as ready to sync when `firstScreenSyncTiming` is `'manual'`.\n *\n * The main thread holds the UI control until this is called, so the handover timing to\n * the background thread (for hydration) is fully controlled by the user. It can be called\n * from both threads (a background-thread call is forwarded to the main thread), is a no-op\n * unless `firstScreenSyncTiming` is `'manual'`, and has no further effect once called.\n *\n * @example\n *\n * ```ts\n * import { markFirstScreenSyncReady } from \"@lynx-js/react\"\n *\n * markFirstScreenSyncReady();\n * ```\n *\n * @public\n *\n * @group Functions\n */\nexport function markFirstScreenSyncReady(): void {\n if (__FIRST_SCREEN_SYNC_TIMING__ !== 'manual') {\n return;\n }\n if (typeof __BACKGROUND__ !== 'undefined' && __BACKGROUND__) {\n // The sync happens on the main thread, forward the mark to it.\n lynx.getNativeApp().callLepusMethod(LifecycleConstant.firstScreenSyncReady, {});\n return;\n }\n onFirstScreenSyncReady();\n}\n\nconst _InitData = /* @__PURE__ */ factory<InitData>(\n {\n createContext,\n useState,\n createElement,\n useLynxGlobalEventListener,\n },\n '__initData',\n 'onDataChanged',\n);\n/**\n * The {@link https://react.dev/reference/react/createContext#provider | Provider} Component that provide `initData`,\n * you must wrap your JSX inside it\n * @group Components\n *\n * @example\n *\n * ```ts\n * import { root } from \"@lynx-js/react\"\n *\n * function App() {\n * return (\n * <InitDataConsumer children={(initData) => <view>...</view>}/>\n * )\n * }\n *\n * root.render(\n * <InitDataProvider>\n * <App/>\n * </InitDataProvider>\n * );\n *\n * ```\n *\n * @public\n *\n * @function\n */\n// @ts-expect-error make preact and react types work\nexport const InitDataProvider: FC<{ children?: ReactNode | undefined }> = /* @__PURE__ */ _InitData.Provider();\n/**\n * The {@link https://react.dev/reference/react/createContext#consumer | Consumer} Component that provide `initData`.\n * This should be used with {@link InitDataProvider}\n * @group Components\n * @public\n *\n * @function\n */\n// @ts-expect-error make preact and react types work\nexport const InitDataConsumer: Consumer<InitData> = /* @__PURE__ */ _InitData.Consumer();\n/**\n * A React Hooks for you to get `initData`.\n * If `initData` is changed, a re-render will be triggered automatically.\n *\n * @example\n *\n * ```ts\n * function App() {\n * const initData = useInitData();\n *\n * initData.someProperty // use it\n * }\n * ```\n *\n * @function\n * @public\n *\n * @group Hooks\n */\nexport const useInitData: () => InitData = /* @__PURE__ */ _InitData.use();\n/**\n * A React Hooks for you to get notified when `initData` changed.\n *\n * @example\n * ```ts\n * function App() {\n * useInitDataChanged((data) => {\n * data.someProperty // can use it\n * })\n * }\n * ```\n * @function\n * @public\n *\n * @group Hooks\n */\nexport const useInitDataChanged: (callback: (data: InitData) => void) => void = /* @__PURE__ */ _InitData.useChanged();\n\nexport type { GlobalProps } from './core/globalProps.js';\n\nconst _GlobalProps = /* @__PURE__ */ createGlobalProps<GlobalProps>({\n createContext,\n useState,\n createElement,\n useLynxGlobalEventListener,\n});\n\n/**\n * The {@link https://react.dev/reference/react/createContext#provider | Provider} Component that provide `lynx.__globalProps`.\n * Only needed with `globalPropsMode: 'event'`; in the default `'reactive'` mode it renders its children directly\n * and updates come from a full re-render.\n * @group Components\n *\n * @example\n *\n * With `globalPropsMode: 'event'`:\n *\n * ```ts\n * import { root } from \"@lynx-js/react\"\n *\n * function App() {\n * return (\n * <GlobalPropsConsumer children={(globalProps) => <view>...</view>}/>\n * )\n * }\n *\n * root.render(\n * <GlobalPropsProvider>\n * <App/>\n * </GlobalPropsProvider>\n * );\n *\n * ```\n *\n * @public\n *\n * @function\n */\n// @ts-expect-error make preact and react types work\nexport const GlobalPropsProvider: FC<{ children?: ReactNode | undefined }> = /* @__PURE__ */ _GlobalProps.Provider();\n\n/**\n * The {@link https://react.dev/reference/react/createContext#consumer | Consumer} Component that provide `lynx.__globalProps`.\n * Only needed with `globalPropsMode: 'event'`, together with {@link GlobalPropsProvider}; in the default `'reactive'` mode\n * it calls `children` with `lynx.__globalProps` directly and updates come from a full re-render.\n * @group Components\n * @public\n *\n * @function\n */\n// @ts-expect-error make preact and react types work\nexport const GlobalPropsConsumer: Consumer<GlobalProps> = /* @__PURE__ */ _GlobalProps.Consumer();\n\n/**\n * A React Hooks for you to get `lynx.__globalProps`.\n * With `globalPropsMode: 'event'`, the component re-renders when `lynx.__globalProps` changes;\n * in the default `'reactive'` mode, updates arrive through a full re-render.\n *\n * @example\n *\n * ```ts\n * function App() {\n * const globalProps = useGlobalProps();\n *\n * globalProps.someProperty // use it\n * }\n * ```\n *\n * @function\n * @public\n *\n * @group Hooks\n */\nexport const useGlobalProps: () => GlobalProps = /* @__PURE__ */ _GlobalProps.use();\n\n/**\n * A React Hooks for you to get notified when `__globalProps` changed.\n *\n * @example\n * ```ts\n * function App() {\n * useGlobalPropsChanged((data) => {\n * lynx.__globalProps.someProperty // can use lynx.__globalProps\n * data.someProperty // can use data\n * })\n * }\n * ```\n * @function\n * @public\n *\n * @group Hooks\n */\nexport const useGlobalPropsChanged: (callback: (data: GlobalProps) => void) => void = /* @__PURE__ */ _GlobalProps\n .useChanged();\n\n/**\n * The interface you can extends so that the `defaultDataProcessor` parameter can be customized\n *\n * Should be used with `lynx.registerDataProcessors`. See more examples at {@link Lynx.registerDataProcessors}.\n *\n * @public\n *\n * @group Types\n */\nexport interface InitDataRaw {}\n/**\n * The interface you can extends so that the `defaultDataProcessor` returning value can be customized\n *\n * Should be used with `lynx.registerDataProcessors`. See more examples at {@link Lynx.registerDataProcessors}.\n *\n * @public\n *\n * @group Types\n */\nexport interface InitData {}\n\nexport { withInitDataInState };\n\n/**\n * The data processors that registered with {@link Lynx.registerDataProcessors}.\n *\n * @example\n *\n * Extending `dataProcessors` interface\n *\n * ```ts\n * import type { DataProcessors as WellKnownDataProcessors } from '@lynx-js/react';\n *\n * declare module '@lynx-js/react' {\n * interface DataProcessors extends WellKnownDataProcessors {\n * foo(bar: string): number;\n * }\n * }\n * ```\n *\n * Then you can use `lynx.registerDataProcessors` with types.\n *\n * ```js\n * lynx.registerDataProcessors({\n * dataProcessors: {\n * foo(bar) {\n * return 1;\n * }\n * }\n * })\n * ```\n *\n * @public\n *\n * @group Types\n */\nexport interface DataProcessors {\n /**\n * Optional processor to override screen metrics used by the app\n *\n * @param metrics - The physical screen dimensions in pixels\n *\n * @returns New screen dimensions to be used by the app\n *\n * @example\n *\n * ```ts\n * lynx.registerDataProcessors({\n * dataProcessors: {\n * getScreenMetricsOverride: (metrics) => {\n * // Force a specific aspect ratio\n * return {\n * width: metrics.width,\n * height: metrics.width * (16/9)\n * };\n * }\n * }\n * });\n * ```\n */\n getScreenMetricsOverride?(metrics: {\n /**\n * The physical pixel width of the screen\n */\n width: number;\n /**\n * The physical pixel height of the screen\n */\n height: number;\n }): { width: number; height: number };\n\n /**\n * Custom unknown data processors.\n *\n * @remarks\n *\n * You may extends the `DataProcessors` interface for better TypeScript types. See {@link DataProcessors}.\n */\n [processorName: string]: (...args: any[]) => any;\n}\n\n/**\n * Definition of DataProcessor(s)\n * @public\n *\n * @group Types\n */\nexport interface DataProcessorDefinition {\n /**\n * You can custom input and output type of `defaultDataProcessor` by extends {@link InitDataRaw} and {@link InitData}\n *\n * Should be used with `lynx.registerDataProcessors`. See more examples at {@link Lynx.registerDataProcessors}.\n *\n * @param rawInitData - initData passed from native code\n * @returns\n * @public\n */\n defaultDataProcessor?: (rawInitData: InitDataRaw) => InitData;\n /**\n * Should be used with `lynx.registerDataProcessors`. See more examples at {@link Lynx.registerDataProcessors}.\n *\n * @public\n */\n dataProcessors?: DataProcessors;\n}\n\n/**\n * APIs under `lynx` global variable that added by ReactLynx.\n *\n * @example\n *\n * ```ts\n * lynx.registerDataProcessors(...);\n * lynx.querySelector(...);\n * lynx.querySelectorAll(...);\n * ```\n *\n * @public\n *\n * @group Types\n */\nexport interface Lynx {\n /**\n * An alias of `lynx.getJSModule(\"GlobalEventEmitter\").trigger(eventName, params)` only in Lepus\n *\n * @public\n */\n triggerGlobalEventFromLepus: (eventName: string, params: any) => void;\n\n /**\n * Register DataProcessors. You MUST call this before `root.render()`.\n *\n * @example\n *\n * You MUST call `lynx.registerDataProcessors` before calling `root.render()`.\n *\n * ```ts\n * import { root } from \"@lynx-js/react\"\n *\n * // You MUST call this before `root.render()`\n * lynx.registerDataProcessors({\n * defaultDataProcessor: () => {...} // default DataProcessor\n * dataProcessors: {\n * getScreenMetricsOverride: () => {...} // named DataProcessor\n * }\n * })\n *\n * root.render(<App/>);\n * ```\n *\n * @example\n *\n * If you have a class component with `static defaultDataProcessor`\n * or `static dataProcessors`, you can use it to register DataProcessors.\n *\n * ```ts\n * import { root, Component } from \"@lynx-js/react\"\n *\n * class App extends Component {\n * static defaultDataProcessor() {\n * ...\n * }\n *\n * static dataProcessors = {\n * getScreenMetricsOverride() {\n * ...\n * }\n * }\n * }\n *\n * lynx.registerDataProcessors(App); // You can pass `App` because it has the required shape\n * root.render(<App/>);\n * ```\n *\n * @example\n *\n * For developers who want fully typed `defaultDataProcessor`,\n * they can achieve it by extends interface `InitDataRaw` and `InitData`.\n *\n * ```ts\n * import { root } from \"@lynx-js/react\"\n *\n * interface ExistingInterface {\n * somePropertyFromExistingInterface: number\n * }\n *\n * declare module '@lynx-js/react' {\n * interface InitDataRaw extends ExistingInterface {\n * someAnotherCustomProperty: string\n * }\n * }\n *\n * lynx.registerDataProcessors({\n * defaultDataProcessor: (initDataRaw) => {\n * initDataRaw.somePropertyFromExistingInterface // will be typed\n * }\n * })\n *\n * ```\n *\n * @example\n *\n * For developers who want fully typed `defaultDataProcessor`,\n * they can achieve it by extends interface `InitDataRaw` and `InitData`.\n *\n * ```ts\n * import { useInitData } from \"@lynx-js/react\"\n *\n * interface AnotherExistingInterface {\n * someAnotherPropertyFromExistingInterface: number\n * }\n *\n * declare module '@lynx-js/react' {\n * interface InitData extends AnotherExistingInterface {\n * someCustomProperty: string\n * }\n * }\n *\n * lynx.registerDataProcessors({\n * defaultDataProcessor: () => {\n * return {\n * someCustomProperty: 'value', // will be typed\n * someAnotherPropertyFromExistingInterface: 1, // will be typed\n * }\n * }\n * })\n *\n * function App() {\n * const initData = useInitData();\n *\n * initData.someCustomProperty // will be typed\n * initData.someAnotherPropertyFromExistingInterface // will be typed\n * }\n *\n * ```\n * @public\n */\n registerDataProcessors: (dataProcessorDefinition?: DataProcessorDefinition) => void;\n}\n\nexport { useLynxGlobalEventListener } from './core/hooks/useLynxGlobalEventListener.js';\nexport { runOnBackground } from './core/background-function/run-on-background.js';\nexport { runOnMainThread } from './snapshot/worklet/call/runOnMainThread.js';\nexport { MainThreadRef, useMainThreadRef } from './core/main-thread-ref.js';\nexport { defineMainThreadObjectType, useMainThreadObject } from './core/main-thread-object.js';\nexport type {\n MainThreadObjectHandle,\n MainThreadObjectType,\n MainThreadObjectTypeDefinition,\n} from './core/main-thread-object.js';\n"]}
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,M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,CAAC,UAAU,EAAE,CAAC;AAIvH,MAAM,YAAY,GAAG,eAAe,CAAC,iBAAiB,CAAc;IAClE,aAAa;IACb,QAAQ;IACR,aAAa;IACb,0BAA0B;CAC3B,CAAC,CAAC;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,oDAAoD;AACpD,MAAM,CAAC,MAAM,mBAAmB,GAA6C,eAAe,CAAC,YAAY,CAAC,QAAQ,EAAE,CAAC;AAErH;;;;;;;;GAQG;AACH,oDAAoD;AACpD,MAAM,CAAC,MAAM,mBAAmB,GAA0B,eAAe,CAAC,YAAY,CAAC,QAAQ,EAAE,CAAC;AAElG;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,CAAC,MAAM,cAAc,GAAsB,eAAe,CAAC,YAAY,CAAC,GAAG,EAAE,CAAC;AAEpF;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAoD,eAAe,CAAC,YAAY;KAC/G,UAAU,EAAE,CAAC;AAGhB,OAAO,EAAE,mBAAmB,EAAE,CAAC;AAwI/B,OAAO,EAAE,0BAA0B,EAAE,MAAM,4CAA4C,CAAC;AACxF,OAAO,EAAE,eAAe,EAAE,MAAM,iDAAiD,CAAC;AAClF,OAAO,EAAE,eAAe,EAAE,MAAM,4CAA4C,CAAC;AAC7E,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAC5E,OAAO,EAAE,0BAA0B,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC","sourcesContent":["// Copyright 2024 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\nimport { render } from 'preact';\nimport { createContext, createElement } from 'preact/compat';\nimport { useState } from 'preact/hooks';\nimport type { Consumer, FC, ReactNode } from 'react';\n\nimport { createGlobalProps } from './core/globalProps.js';\nimport type { GlobalProps } from './core/globalProps.js';\nimport { useLynxGlobalEventListener } from './core/hooks/useLynxGlobalEventListener.js';\nimport { factory, withInitDataInState } from './core/initData.js';\nimport type { DataProcessorDefinition, DataProcessors, InitData, InitDataRaw } from './core/lynx-data-processors.js';\nimport { __root } from './root.js';\nimport { profileEnd, profileStart } from './shared/profile.js';\nimport { LifecycleConstant } from './snapshot/lifecycle/constant.js';\nimport { onFirstScreenSyncReady } from './snapshot/lifecycle/event/firstScreenSync.js';\nimport { flushDelayedLifecycleEvents } from './snapshot/lynx/tt.js';\n\n/**\n * The default root exported by `@lynx-js/react` for you to render a JSX\n * @public\n *\n * @group Types\n */\nexport interface Root {\n /**\n * Use this API to pass in your JSX to render\n *\n * @example\n *\n * ```ts\n * import { root } from \"@lynx-js/react\"\n *\n * function App() {\n * // Your app\n * return <view>...</view>\n * }\n *\n * root.render(<App/>);\n * ```\n *\n * @example\n *\n * ```tsx\n * import { root } from \"@lynx-js/react\"\n *\n * function App() {\n * // Your app\n * return <view>...</view>\n * }\n *\n * if (__MAIN_THREAD__) {\n * root.render(\n * <DataProvider data={DEFAULT_DATA}>\n * <App/>\n * </DataProvider>\n * );\n * } else if (__BACKGROUND__) {\n * fetchData().then((data) => {\n * root.render(\n * <DataProvider data={data}>\n * <App/>\n * </DataProvider>\n * ); // You can render later after your data is ready\n * })\n * }\n * ```\n *\n * @public\n */\n render: (jsx: ReactNode) => void;\n /**\n * {@inheritDoc Lynx.registerDataProcessors}\n * @deprecated use {@link Lynx.registerDataProcessors | lynx.registerDataProcessors} instead\n * @public\n */\n registerDataProcessors: (dataProcessorDefinition: DataProcessorDefinition) => void;\n}\n\n/**\n * The default and only root of ReactLynx for you to render JSX\n * @example\n * ```ts\n * import { root } from \"@lynx-js/react\"\n * ```\n *\n * @public\n *\n * @group Functions\n */\nexport const root: Root = {\n render: (jsx: ReactNode): void => {\n /* v8 ignore next 2 */\n if (typeof __MAIN_THREAD__ !== 'undefined' && __MAIN_THREAD__) {\n __root.__jsx = jsx;\n } else {\n __root.__jsx = jsx;\n if (typeof __PROFILE__ !== 'undefined' && __PROFILE__) {\n profileStart('ReactLynx::renderBackground');\n }\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n render(jsx, __root as any);\n if (typeof __PROFILE__ !== 'undefined' && __PROFILE__) {\n profileEnd();\n }\n if (__FIRST_SCREEN_SYNC_TIMING__ === 'jsReady') {\n // `jsReady` is a special case of the `manual` first-screen sync: the\n // framework marks ready automatically once the background is ready.\n lynx.getNativeApp().callLepusMethod(LifecycleConstant.firstScreenSyncReady, {});\n } else {\n // `immediately` or `manual`: the first screen is synced without waiting\n // for the background, so the `firstScreen` message might have been\n // reached when `root.render()` is called asynchronously.\n flushDelayedLifecycleEvents();\n }\n }\n },\n /* v8 ignore next 3 */\n registerDataProcessors: (dataProcessorDefinition: DataProcessorDefinition): void => {\n lynx.registerDataProcessors(dataProcessorDefinition);\n },\n};\n\n/**\n * Mark the first screen as ready to sync when `firstScreenSyncTiming` is `'manual'`.\n *\n * The main thread holds the UI control until this is called, so the handover timing to\n * the background thread (for hydration) is fully controlled by the user. It can be called\n * from both threads (a background-thread call is forwarded to the main thread), is a no-op\n * unless `firstScreenSyncTiming` is `'manual'`, and has no further effect once called.\n *\n * @example\n *\n * ```ts\n * import { markFirstScreenSyncReady } from \"@lynx-js/react\"\n *\n * markFirstScreenSyncReady();\n * ```\n *\n * @public\n *\n * @group Functions\n */\nexport function markFirstScreenSyncReady(): void {\n if (__FIRST_SCREEN_SYNC_TIMING__ !== 'manual') {\n return;\n }\n if (typeof __BACKGROUND__ !== 'undefined' && __BACKGROUND__) {\n // The sync happens on the main thread, forward the mark to it.\n lynx.getNativeApp().callLepusMethod(LifecycleConstant.firstScreenSyncReady, {});\n return;\n }\n onFirstScreenSyncReady();\n}\n\nconst _InitData = /* @__PURE__ */ factory<InitData>(\n {\n createContext,\n useState,\n createElement,\n useLynxGlobalEventListener,\n },\n '__initData',\n 'onDataChanged',\n);\n/**\n * The {@link https://react.dev/reference/react/createContext#provider | Provider} Component that provide `initData`,\n * you must wrap your JSX inside it\n * @group Components\n *\n * @example\n *\n * ```ts\n * import { root } from \"@lynx-js/react\"\n *\n * function App() {\n * return (\n * <InitDataConsumer children={(initData) => <view>...</view>}/>\n * )\n * }\n *\n * root.render(\n * <InitDataProvider>\n * <App/>\n * </InitDataProvider>\n * );\n *\n * ```\n *\n * @public\n *\n * @function\n */\n// @ts-expect-error make preact and react types work\nexport const InitDataProvider: FC<{ children?: ReactNode | undefined }> = /* @__PURE__ */ _InitData.Provider();\n/**\n * The {@link https://react.dev/reference/react/createContext#consumer | Consumer} Component that provide `initData`.\n * This should be used with {@link InitDataProvider}\n * @group Components\n * @public\n *\n * @function\n */\n// @ts-expect-error make preact and react types work\nexport const InitDataConsumer: Consumer<InitData> = /* @__PURE__ */ _InitData.Consumer();\n/**\n * A React Hooks for you to get `initData`.\n * If `initData` is changed, a re-render will be triggered automatically.\n *\n * @example\n *\n * ```ts\n * function App() {\n * const initData = useInitData();\n *\n * initData.someProperty // use it\n * }\n * ```\n *\n * @function\n * @public\n *\n * @group Hooks\n */\nexport const useInitData: () => InitData = /* @__PURE__ */ _InitData.use();\n/**\n * A React Hooks for you to get notified when `initData` changed.\n *\n * @example\n * ```ts\n * function App() {\n * useInitDataChanged((data) => {\n * data.someProperty // can use it\n * })\n * }\n * ```\n * @function\n * @public\n *\n * @group Hooks\n */\nexport const useInitDataChanged: (callback: (data: InitData) => void) => void = /* @__PURE__ */ _InitData.useChanged();\n\nexport type { GlobalProps } from './core/globalProps.js';\n\nconst _GlobalProps = /* @__PURE__ */ createGlobalProps<GlobalProps>({\n createContext,\n useState,\n createElement,\n useLynxGlobalEventListener,\n});\n\n/**\n * The {@link https://react.dev/reference/react/createContext#provider | Provider} Component that provide `lynx.__globalProps`.\n * Only needed with `globalPropsMode: 'event'`; in the default `'reactive'` mode it renders its children directly\n * and updates come from a full re-render.\n * @group Components\n *\n * @example\n *\n * With `globalPropsMode: 'event'`:\n *\n * ```ts\n * import { root } from \"@lynx-js/react\"\n *\n * function App() {\n * return (\n * <GlobalPropsConsumer children={(globalProps) => <view>...</view>}/>\n * )\n * }\n *\n * root.render(\n * <GlobalPropsProvider>\n * <App/>\n * </GlobalPropsProvider>\n * );\n *\n * ```\n *\n * @public\n *\n * @function\n */\n// @ts-expect-error make preact and react types work\nexport const GlobalPropsProvider: FC<{ children?: ReactNode | undefined }> = /* @__PURE__ */ _GlobalProps.Provider();\n\n/**\n * The {@link https://react.dev/reference/react/createContext#consumer | Consumer} Component that provide `lynx.__globalProps`.\n * Only needed with `globalPropsMode: 'event'`, together with {@link GlobalPropsProvider}; in the default `'reactive'` mode\n * it calls `children` with `lynx.__globalProps` directly and updates come from a full re-render.\n * @group Components\n * @public\n *\n * @function\n */\n// @ts-expect-error make preact and react types work\nexport const GlobalPropsConsumer: Consumer<GlobalProps> = /* @__PURE__ */ _GlobalProps.Consumer();\n\n/**\n * A React Hooks for you to get `lynx.__globalProps`.\n * With `globalPropsMode: 'event'`, the component re-renders when `lynx.__globalProps` changes;\n * in the default `'reactive'` mode, updates arrive through a full re-render.\n *\n * @example\n *\n * ```ts\n * function App() {\n * const globalProps = useGlobalProps();\n *\n * globalProps.someProperty // use it\n * }\n * ```\n *\n * @function\n * @public\n *\n * @group Hooks\n */\nexport const useGlobalProps: () => GlobalProps = /* @__PURE__ */ _GlobalProps.use();\n\n/**\n * A React Hooks for you to get notified when `__globalProps` changed.\n *\n * @example\n * ```ts\n * function App() {\n * useGlobalPropsChanged((data) => {\n * lynx.__globalProps.someProperty // can use lynx.__globalProps\n * data.someProperty // can use data\n * })\n * }\n * ```\n * @function\n * @public\n *\n * @group Hooks\n */\nexport const useGlobalPropsChanged: (callback: (data: GlobalProps) => void) => void = /* @__PURE__ */ _GlobalProps\n .useChanged();\n\nexport type { DataProcessorDefinition, DataProcessors, InitData, InitDataRaw };\nexport { withInitDataInState };\n\n/**\n * APIs under `lynx` global variable that added by ReactLynx.\n *\n * @example\n *\n * ```ts\n * lynx.registerDataProcessors(...);\n * lynx.querySelector(...);\n * lynx.querySelectorAll(...);\n * ```\n *\n * @public\n *\n * @group Types\n */\nexport interface Lynx {\n /**\n * An alias of `lynx.getJSModule(\"GlobalEventEmitter\").trigger(eventName, params)` only in Lepus\n *\n * @public\n */\n triggerGlobalEventFromLepus: (eventName: string, params: any) => void;\n\n /**\n * Register DataProcessors. You MUST call this before `root.render()`.\n *\n * @example\n *\n * You MUST call `lynx.registerDataProcessors` before calling `root.render()`.\n *\n * ```ts\n * import { root } from \"@lynx-js/react\"\n *\n * // You MUST call this before `root.render()`\n * lynx.registerDataProcessors({\n * defaultDataProcessor: () => {...} // default DataProcessor\n * dataProcessors: {\n * getScreenMetricsOverride: () => {...} // named DataProcessor\n * }\n * })\n *\n * root.render(<App/>);\n * ```\n *\n * @example\n *\n * If you have a class component with `static defaultDataProcessor`\n * or `static dataProcessors`, you can use it to register DataProcessors.\n *\n * ```ts\n * import { root, Component } from \"@lynx-js/react\"\n *\n * class App extends Component {\n * static defaultDataProcessor() {\n * ...\n * }\n *\n * static dataProcessors = {\n * getScreenMetricsOverride() {\n * ...\n * }\n * }\n * }\n *\n * lynx.registerDataProcessors(App); // You can pass `App` because it has the required shape\n * root.render(<App/>);\n * ```\n *\n * @example\n *\n * For developers who want fully typed `defaultDataProcessor`,\n * they can achieve it by extends interface `InitDataRaw` and `InitData`.\n *\n * ```ts\n * import { root } from \"@lynx-js/react\"\n *\n * interface ExistingInterface {\n * somePropertyFromExistingInterface: number\n * }\n *\n * declare module '@lynx-js/react' {\n * interface InitDataRaw extends ExistingInterface {\n * someAnotherCustomProperty: string\n * }\n * }\n *\n * lynx.registerDataProcessors({\n * defaultDataProcessor: (initDataRaw) => {\n * initDataRaw.somePropertyFromExistingInterface // will be typed\n * }\n * })\n *\n * ```\n *\n * @example\n *\n * For developers who want fully typed `defaultDataProcessor`,\n * they can achieve it by extends interface `InitDataRaw` and `InitData`.\n *\n * ```ts\n * import { useInitData } from \"@lynx-js/react\"\n *\n * interface AnotherExistingInterface {\n * someAnotherPropertyFromExistingInterface: number\n * }\n *\n * declare module '@lynx-js/react' {\n * interface InitData extends AnotherExistingInterface {\n * someCustomProperty: string\n * }\n * }\n *\n * lynx.registerDataProcessors({\n * defaultDataProcessor: () => {\n * return {\n * someCustomProperty: 'value', // will be typed\n * someAnotherPropertyFromExistingInterface: 1, // will be typed\n * }\n * }\n * })\n *\n * function App() {\n * const initData = useInitData();\n *\n * initData.someCustomProperty // will be typed\n * initData.someAnotherPropertyFromExistingInterface // will be typed\n * }\n *\n * ```\n * @public\n */\n registerDataProcessors: (dataProcessorDefinition?: DataProcessorDefinition) => void;\n}\n\nexport { useLynxGlobalEventListener } from './core/hooks/useLynxGlobalEventListener.js';\nexport { runOnBackground } from './core/background-function/run-on-background.js';\nexport { runOnMainThread } from './snapshot/worklet/call/runOnMainThread.js';\nexport { MainThreadRef, useMainThreadRef } from './core/main-thread-ref.js';\nexport { defineMainThreadObjectType, useMainThreadObject } from './core/main-thread-object.js';\nexport type {\n MainThreadObjectHandle,\n MainThreadObjectType,\n MainThreadObjectTypeDefinition,\n} from './core/main-thread-object.js';\n"]}
@@ -6,10 +6,6 @@ interface PatchedVNode extends VNode {
6
6
  lineNumber: number;
7
7
  };
8
8
  }
9
- /**
10
- * Get human readable name of the component/dom node
11
- */
12
- export declare function getDisplayName(vnode: PatchedVNode): string;
13
9
  /**
14
10
  * Get the currently rendered `vnode`
15
11
  */
@@ -30,7 +30,7 @@ import { DIFF, DIFFED, RENDER, ROOT } from './render-constants.js';
30
30
  /**
31
31
  * Get human readable name of the component/dom node
32
32
  */
33
- export function getDisplayName(vnode) {
33
+ function getVNodeDisplayName(vnode) {
34
34
  if (vnode.type === Fragment) {
35
35
  return 'Fragment';
36
36
  }
@@ -66,6 +66,7 @@ const renderStack = [];
66
66
  * optimization. In these cases the `_owner` will be different.
67
67
  */
68
68
  let ownerStack = [];
69
+ let didInstallComponentStack = false;
69
70
  /**
70
71
  * Get the currently rendered `vnode`
71
72
  */
@@ -89,7 +90,7 @@ export function getOwnerStack(vnode) {
89
90
  next = next._owner;
90
91
  }
91
92
  return stack.reduce((acc, owner) => {
92
- acc += ` in ${getDisplayName(owner)}`;
93
+ acc += ` in ${getVNodeDisplayName(owner)}`;
93
94
  const source = owner.__source;
94
95
  if (source) {
95
96
  acc += ` (at ${source.fileName}:${source.lineNumber})`;
@@ -103,6 +104,12 @@ export function getOwnerStack(vnode) {
103
104
  * debug messages for `this.setState` where the `vnode` is `undefined`.
104
105
  */
105
106
  export function setupComponentStack() {
107
+ renderStack.length = 0;
108
+ ownerStack = [];
109
+ if (didInstallComponentStack) {
110
+ return;
111
+ }
112
+ didInstallComponentStack = true;
106
113
  /* eslint-disable @typescript-eslint/unbound-method */
107
114
  const oldDiff = options[DIFF];
108
115
  const oldDiffed = options[DIFFED];
@@ -112,9 +119,15 @@ export function setupComponentStack() {
112
119
  /* eslint-enable @typescript-eslint/unbound-method */
113
120
  options[DIFFED] = vnode => {
114
121
  if (isPossibleOwner(vnode)) {
115
- ownerStack.pop();
122
+ const ownerIndex = ownerStack.lastIndexOf(vnode);
123
+ if (ownerIndex !== -1) {
124
+ ownerStack.length = ownerIndex;
125
+ }
126
+ const renderIndex = renderStack.lastIndexOf(vnode);
127
+ if (renderIndex !== -1) {
128
+ renderStack.length = renderIndex;
129
+ }
116
130
  }
117
- renderStack.pop();
118
131
  if (oldDiffed)
119
132
  oldDiffed(vnode);
120
133
  };
@@ -126,7 +139,10 @@ export function setupComponentStack() {
126
139
  oldDiff(vnode);
127
140
  };
128
141
  options[ROOT] = (vnode, parent) => {
129
- ownerStack = [];
142
+ if (!parent?.parentNode) {
143
+ renderStack.length = 0;
144
+ ownerStack = [];
145
+ }
130
146
  if (oldRoot)
131
147
  oldRoot(vnode, parent);
132
148
  };
@@ -1 +1 @@
1
- {"version":3,"file":"component-stack.js","sourceRoot":"","sources":["../../src/shared/component-stack.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;A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AAC,KAAK,CAAC,EAAE,CAAC;YAC3B,WAAW,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAC1B,CAAC;QACD,IAAI,OAAO;YAAE,OAAO,CAAC,KAAK,CAAC,CAAC;IAC9B,CAAC,CAAC;IAEF,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE;QAChC,UAAU,GAAG,EAAE,CAAC;QAChB,IAAI,OAAO;YAAE,OAAO,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;IACtC,CAAC,CAAC;IAEF,OAAO,CAAC,KAAK,GAAG,CAAC,KAAmB,EAAE,EAAE;QACtC,gFAAgF;QAChF,4EAA4E;QAC5E,IAAI,KAAK,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC;YAC/B,KAAK,CAAC,MAAM,GAAG,UAAU,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,UAAU,CAAC,MAAM,GAAG,CAAC,CAAE,CAAC,CAAC,CAAC,IAAI,CAAC;QACnF,CAAC;QACD,IAAI,QAAQ;YAAE,QAAQ,CAAC,KAAK,CAAC,CAAC;IAChC,CAAC,CAAC;IAEF,OAAO,CAAC,MAAM,CAAC,GAAG,KAAK,CAAC,EAAE;QACxB,IAAI,eAAe,CAAC,KAAK,CAAC,EAAE,CAAC;YAC3B,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACzB,CAAC;QAED,IAAI,SAAS;YAAE,SAAS,CAAC,KAAK,CAAC,CAAC;IAClC,CAAC,CAAC;AACJ,CAAC","sourcesContent":["// Copyright 2025 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\n/**\n * @license\nThe MIT License (MIT)\n\nCopyright (c) 2015-present Jason Miller\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n */\n\nimport { Fragment, options } from 'preact';\nimport type { VNode } from 'preact';\n\nimport { DIFF, DIFFED, RENDER, ROOT } from './render-constants.js';\n\ninterface PatchedVNode extends VNode {\n _owner?: PatchedVNode | null;\n\n __source?: {\n fileName: string;\n lineNumber: number;\n };\n}\n\n/**\n * Get human readable name of the component/dom node\n */\nexport function getDisplayName(vnode: PatchedVNode): string {\n if (vnode.type === Fragment) {\n return 'Fragment';\n } else if (typeof vnode.type == 'function') {\n return vnode.type.displayName ?? vnode.type.name;\n } else if (typeof vnode.type == 'string') {\n return vnode.type;\n }\n\n return '#text';\n}\n\n/**\n * Used to keep track of the currently rendered `vnode` and print it\n * in debug messages.\n */\nconst renderStack: PatchedVNode[] = [];\n\n/**\n * Keep track of the current owners. An owner describes a component\n * which was responsible to render a specific `vnode`. This exclude\n * children that are passed via `props.children`, because they belong\n * to the parent owner.\n *\n * ```jsx\n * const Foo = props => <div>{props.children}</div> // div's owner is Foo\n * const Bar = props => {\n * return (\n * <Foo><span /></Foo> // Foo's owner is Bar, span's owner is Bar\n * )\n * }\n * ```\n *\n * Note: A `vnode` may be hoisted to the root scope due to compiler\n * optimization. In these cases the `_owner` will be different.\n */\nlet ownerStack: PatchedVNode[] = [];\n\n/**\n * Get the currently rendered `vnode`\n */\nexport function getCurrentVNode(): PatchedVNode | null {\n return renderStack.length > 0 ? renderStack[renderStack.length - 1]! : null;\n}\n\n/**\n * Check if a `vnode` is a possible owner.\n */\nfunction isPossibleOwner(vnode: PatchedVNode) {\n return typeof vnode.type == 'function' && vnode.type != Fragment;\n}\n\n/**\n * Return the component stack that was captured up to this point.\n */\nexport function getOwnerStack(vnode: PatchedVNode): string {\n const stack = [vnode];\n let next = vnode;\n while (next._owner != null) {\n stack.push(next._owner);\n next = next._owner;\n }\n\n return stack.reduce((acc, owner) => {\n acc += ` in ${getDisplayName(owner)}`;\n\n const source = owner.__source;\n if (source) {\n acc += ` (at ${source.fileName}:${source.lineNumber})`;\n }\n\n return (acc += '\\n');\n }, '');\n}\n\n/**\n * Setup code to capture the component trace while rendering. Note that\n * we cannot simply traverse `vnode._parent` upwards, because we have some\n * debug messages for `this.setState` where the `vnode` is `undefined`.\n */\nexport function setupComponentStack(): void {\n /* eslint-disable @typescript-eslint/unbound-method */\n const oldDiff = options[DIFF];\n const oldDiffed = options[DIFFED];\n const oldRoot = options[ROOT];\n const oldVNode = options.vnode;\n const oldRender = options[RENDER];\n /* eslint-enable @typescript-eslint/unbound-method */\n\n options[DIFFED] = vnode => {\n if (isPossibleOwner(vnode)) {\n ownerStack.pop();\n }\n renderStack.pop();\n if (oldDiffed) oldDiffed(vnode);\n };\n\n options[DIFF] = vnode => {\n if (isPossibleOwner(vnode)) {\n renderStack.push(vnode);\n }\n if (oldDiff) oldDiff(vnode);\n };\n\n options[ROOT] = (vnode, parent) => {\n ownerStack = [];\n if (oldRoot) oldRoot(vnode, parent);\n };\n\n options.vnode = (vnode: PatchedVNode) => {\n // Scheduled component updates clone the vnode before entering its render scope.\n // Preserve the original owner when Preact invokes this hook for that clone.\n if (vnode._owner === undefined) {\n vnode._owner = ownerStack.length > 0 ? ownerStack[ownerStack.length - 1]! : null;\n }\n if (oldVNode) oldVNode(vnode);\n };\n\n options[RENDER] = vnode => {\n if (isPossibleOwner(vnode)) {\n ownerStack.push(vnode);\n }\n\n if (oldRender) oldRender(vnode);\n };\n}\n"]}
1
+ {"version":3,"file":"component-stack.js","sourceRoot":"","sources":["../../src/shared/component-stack.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAG3C,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAC;AAWnE;;GAEG;AACH,SAAS,mBAAmB,CAAC,KAAmB;IAC9C,IAAI,KAAK,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;QAC5B,OAAO,UAAU,CAAC;IACpB,CAAC;SAAM,IAAI,OAAO,KAAK,CAAC,IAAI,IAAI,UAAU,EAAE,CAAC;QAC3C,OAAO,KAAK,CAAC,IAAI,CAAC,WAAW,IAAI,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC;IACnD,CAAC;SAAM,IAAI,OAAO,KAAK,CAAC,IAAI,IAAI,QAAQ,EAAE,CAAC;QACzC,OAAO,KAAK,CAAC,IAAI,CAAC;IACpB,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC;AAED;;;GAGG;AACH,MAAM,WAAW,GAAmB,EAAE,CAAC;AAEvC;;;;;;;;;;;;;;;;;GAiBG;AACH,IAAI,UAAU,GAAmB,EAAE,CAAC;AACpC,IAAI,wBAAwB,GAAG,KAAK,CAAC;AAErC;;GAEG;AACH,MAAM,UAAU,eAAe;IAC7B,OAAO,WAAW,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,WAAW,CAAC,MAAM,GAAG,CAAC,CAAE,CAAC,CAAC,CAAC,IAAI,CAAC;AAC9E,CAAC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FAAgF;QAChF,4EAA4E;QAC5E,IAAI,KAAK,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC;YAC/B,KAAK,CAAC,MAAM,GAAG,UAAU,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,UAAU,CAAC,MAAM,GAAG,CAAC,CAAE,CAAC,CAAC,CAAC,IAAI,CAAC;QACnF,CAAC;QACD,IAAI,QAAQ;YAAE,QAAQ,CAAC,KAAK,CAAC,CAAC;IAChC,CAAC,CAAC;IAEF,OAAO,CAAC,MAAM,CAAC,GAAG,KAAK,CAAC,EAAE;QACxB,IAAI,eAAe,CAAC,KAAK,CAAC,EAAE,CAAC;YAC3B,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACzB,CAAC;QAED,IAAI,SAAS;YAAE,SAAS,CAAC,KAAK,CAAC,CAAC;IAClC,CAAC,CAAC;AACJ,CAAC","sourcesContent":["// Copyright 2025 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\n/**\n * @license\nThe MIT License (MIT)\n\nCopyright (c) 2015-present Jason Miller\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n */\n\nimport { Fragment, options } from 'preact';\nimport type { VNode } from 'preact';\n\nimport { DIFF, DIFFED, RENDER, ROOT } from './render-constants.js';\n\ninterface PatchedVNode extends VNode {\n _owner?: PatchedVNode | null;\n\n __source?: {\n fileName: string;\n lineNumber: number;\n };\n}\n\n/**\n * Get human readable name of the component/dom node\n */\nfunction getVNodeDisplayName(vnode: PatchedVNode): string {\n if (vnode.type === Fragment) {\n return 'Fragment';\n } else if (typeof vnode.type == 'function') {\n return vnode.type.displayName ?? vnode.type.name;\n } else if (typeof vnode.type == 'string') {\n return vnode.type;\n }\n\n return '#text';\n}\n\n/**\n * Used to keep track of the currently rendered `vnode` and print it\n * in debug messages.\n */\nconst renderStack: PatchedVNode[] = [];\n\n/**\n * Keep track of the current owners. An owner describes a component\n * which was responsible to render a specific `vnode`. This exclude\n * children that are passed via `props.children`, because they belong\n * to the parent owner.\n *\n * ```jsx\n * const Foo = props => <div>{props.children}</div> // div's owner is Foo\n * const Bar = props => {\n * return (\n * <Foo><span /></Foo> // Foo's owner is Bar, span's owner is Bar\n * )\n * }\n * ```\n *\n * Note: A `vnode` may be hoisted to the root scope due to compiler\n * optimization. In these cases the `_owner` will be different.\n */\nlet ownerStack: PatchedVNode[] = [];\nlet didInstallComponentStack = false;\n\n/**\n * Get the currently rendered `vnode`\n */\nexport function getCurrentVNode(): PatchedVNode | null {\n return renderStack.length > 0 ? renderStack[renderStack.length - 1]! : null;\n}\n\n/**\n * Check if a `vnode` is a possible owner.\n */\nfunction isPossibleOwner(vnode: PatchedVNode) {\n return typeof vnode.type == 'function' && vnode.type != Fragment;\n}\n\n/**\n * Return the component stack that was captured up to this point.\n */\nexport function getOwnerStack(vnode: PatchedVNode): string {\n const stack = [vnode];\n let next = vnode;\n while (next._owner != null) {\n stack.push(next._owner);\n next = next._owner;\n }\n\n return stack.reduce((acc, owner) => {\n acc += ` in ${getVNodeDisplayName(owner)}`;\n\n const source = owner.__source;\n if (source) {\n acc += ` (at ${source.fileName}:${source.lineNumber})`;\n }\n\n return (acc += '\\n');\n }, '');\n}\n\n/**\n * Setup code to capture the component trace while rendering. Note that\n * we cannot simply traverse `vnode._parent` upwards, because we have some\n * debug messages for `this.setState` where the `vnode` is `undefined`.\n */\nexport function setupComponentStack(): void {\n renderStack.length = 0;\n ownerStack = [];\n if (didInstallComponentStack) {\n return;\n }\n didInstallComponentStack = true;\n\n /* eslint-disable @typescript-eslint/unbound-method */\n const oldDiff = options[DIFF];\n const oldDiffed = options[DIFFED];\n const oldRoot = options[ROOT];\n const oldVNode = options.vnode;\n const oldRender = options[RENDER];\n /* eslint-enable @typescript-eslint/unbound-method */\n\n options[DIFFED] = vnode => {\n if (isPossibleOwner(vnode)) {\n const ownerIndex = ownerStack.lastIndexOf(vnode);\n if (ownerIndex !== -1) {\n ownerStack.length = ownerIndex;\n }\n const renderIndex = renderStack.lastIndexOf(vnode);\n if (renderIndex !== -1) {\n renderStack.length = renderIndex;\n }\n }\n if (oldDiffed) oldDiffed(vnode);\n };\n\n options[DIFF] = vnode => {\n if (isPossibleOwner(vnode)) {\n renderStack.push(vnode);\n }\n if (oldDiff) oldDiff(vnode);\n };\n\n options[ROOT] = (vnode, parent) => {\n if (!(parent as { parentNode?: unknown } | null | undefined)?.parentNode) {\n renderStack.length = 0;\n ownerStack = [];\n }\n if (oldRoot) oldRoot(vnode, parent);\n };\n\n options.vnode = (vnode: PatchedVNode) => {\n // Scheduled component updates clone the vnode before entering its render scope.\n // Preserve the original owner when Preact invokes this hook for that clone.\n if (vnode._owner === undefined) {\n vnode._owner = ownerStack.length > 0 ? ownerStack[ownerStack.length - 1]! : null;\n }\n if (oldVNode) oldVNode(vnode);\n };\n\n options[RENDER] = vnode => {\n if (isPossibleOwner(vnode)) {\n ownerStack.push(vnode);\n }\n\n if (oldRender) oldRender(vnode);\n };\n}\n"]}
@@ -77,4 +77,4 @@ export function prepareGestureForCommit(gesture) {
77
77
  };
78
78
  return attachCommittedSerializer(committed);
79
79
  }
80
- //# sourceMappingURL=processGestureBagkround.js.map
80
+ //# sourceMappingURL=processGestureBackground.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"processGestureBackground.js","sourceRoot":"","sources":["../../../src/snapshot/gesture/processGestureBackground.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAE9C,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAErD,SAAS,uBAAuB,CAAC,KAAc;IAC7C,0EAA0E;IAC1E,sFAAsF;IACtF,MAAM,IAAI,GAAG,EAAE,GAAI,KAA4C,EAAwB,CAAC;IACxF,OAAO,gBAAgB,CAAC,IAAI,CAAC,CAAC;AAChC,CAAC;AAED,SAAS,qBAAqB,CAAC,MAA+B;IAC5D,MAAM,eAAe,GAAG,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC;IAC1F,OAAO,MAAM,CAAC,WAAW,CAAC,eAAe,CAAC,CAAC;AAC7C,CAAC;AAED,SAAS,yBAAyB,CAAC,OAAoB;IACrD,IAAI,OAAO,CAAC,IAAI,KAAK,gBAAgB,CAAC,QAAQ,EAAE,CAAC;QAC/C,MAAM,QAAQ,GAAG,OAA0B,CAAC;QAC5C,OAAO;YACL,IAAI,EAAE,QAAQ,CAAC,IAAI;YACnB,QAAQ,EAAE,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,yBAAyB,CAAC,UAAU,CAAC,CAAC;YACtF,cAAc,EAAE,IAAI;SACrB,CAAC;IACJ,CAAC;IAED,MAAM,WAAW,GAAG,OAAsB,CAAC;IAC3C,OAAO,qBAAqB,CAAC;QAC3B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B,CAAC,SAAS,CAAC,CAAC;IAC9C,CAAC;IAED,MAAM,WAAW,GAAG,OAAsB,CAAC;IAC3C,MAAM,kBAAkB,GAA6B,EAAE,GAAG,WAAW,CAAC,SAAS,EAAE,CAAC;IAClF,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,IAAI,CAAC,kBAAkB,CAAC,EAAE,CAAC;QACnD,MAAM,QAAQ,GAAG,kBAAkB,CAAC,IAAI,CAAC,CAAC;QAC1C,IAAI,QAAQ,IAAI,IAAI,EAAE,CAAC;YACrB,wEAAwE;YACxE,8DAA8D;YAC9D,SAAS;QACX,CAAC;QACD,2FAA2F;QAC3F,8EAA8E;QAC9E,kBAAkB,CAAC,IAAI,CAAC,GAAG,uBAAuB,CAAC,QAAQ,CAAE,CAAC;IAChE,CAAC;IAED,MAAM,SAAS,GAAgB;QAC7B,GAAG,WAAW;QACd,SAAS,EAAE,kBAAkB;KAC9B,CAAC;IACF,OAAO,yBAAyB,CAAC,SAAS,CAAC,CAAC;AAC9C,CAAC","sourcesContent":["// Copyright 2025 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\nimport type { Worklet } from '@lynx-js/react/worklet-runtime/bindings';\n\nimport { GestureTypeInner } from './types.js';\nimport type { BaseGesture, ComposedGesture, GestureKind } from './types.js';\nimport { onPostWorkletCtx } from '../worklet/ctx.js';\n\nfunction prepareWorkletForCommit(value: Worklet): Worklet | null {\n // Copy-on-commit: keep the background-side gesture/worklet objects clean.\n // `_execId` is injected into the payload object that will be sent to the main thread.\n const copy = { ...(value as unknown as Record<string, unknown>) } as unknown as Worklet;\n return onPostWorkletCtx(copy);\n}\n\nfunction removeUndefinedFields(record: Record<string, unknown>): Record<string, unknown> {\n const filteredEntries = Object.entries(record).filter(([, value]) => value !== undefined);\n return Object.fromEntries(filteredEntries);\n}\n\nfunction serializeCommittedGesture(gesture: GestureKind): Record<string, unknown> {\n if (gesture.type === GestureTypeInner.COMPOSED) {\n const composed = gesture as ComposedGesture;\n return {\n type: composed.type,\n gestures: composed.gestures.map((subGesture) => serializeCommittedGesture(subGesture)),\n __isSerialized: true,\n };\n }\n\n const baseGesture = gesture as BaseGesture;\n return removeUndefinedFields({\n config: baseGesture.config,\n id: baseGesture.id,\n type: baseGesture.type,\n simultaneousWith: baseGesture.simultaneousWith?.map(subGesture => ({\n id: subGesture.id,\n })) ?? [],\n waitFor: baseGesture.waitFor?.map(subGesture => ({ id: subGesture.id })) ?? [],\n continueWith: baseGesture.continueWith?.map(subGesture => ({\n id: subGesture.id,\n })) ?? [],\n callbacks: baseGesture.callbacks,\n __isSerialized: true,\n });\n}\n\nfunction attachCommittedSerializer<TGesture extends GestureKind>(gesture: TGesture): TGesture {\n const serialize = () => serializeCommittedGesture(gesture);\n\n return Object.assign(gesture as Record<string, unknown>, {\n serialize,\n toJSON: serialize,\n }) as TGesture;\n}\n\n/**\n * Prepare a gesture payload to be sent to the main thread.\n *\n * This function returns a copy of the input object and injects `_execId` into\n * its worklet callbacks. The background-side gesture object MUST NOT be mutated,\n * otherwise `_execId` churn would pollute the cached values and cause redundant patches.\n */\nexport function prepareGestureForCommit(gesture: GestureKind): GestureKind {\n if (gesture.type === GestureTypeInner.COMPOSED) {\n const composed = gesture as ComposedGesture;\n const committed: ComposedGesture = {\n ...composed,\n gestures: composed.gestures.map((g) => prepareGestureForCommit(g)),\n };\n return attachCommittedSerializer(committed);\n }\n\n const baseGesture = gesture as BaseGesture;\n const committedCallbacks: BaseGesture['callbacks'] = { ...baseGesture.callbacks };\n for (const name of Object.keys(committedCallbacks)) {\n const callback = committedCallbacks[name];\n if (callback == null) {\n // Some gesture implementations may intentionally leave callbacks unset.\n // Treat null/undefined as \"no handler\" and keep it untouched.\n continue;\n }\n // `onPostWorkletCtx` may report errors and return null depending on runtime configuration.\n // Keep behavior consistent with the previous implementation (which used `!`).\n committedCallbacks[name] = prepareWorkletForCommit(callback)!;\n }\n\n const committed: BaseGesture = {\n ...baseGesture,\n callbacks: committedCallbacks,\n };\n return attachCommittedSerializer(committed);\n}\n"]}
@@ -12,7 +12,6 @@ export declare const SnapshotOperation: {
12
12
  readonly nodesRefInsertBefore: 5;
13
13
  readonly nodesRefRemoveChild: 6;
14
14
  readonly DEV_ONLY_AddSnapshot: 100;
15
- readonly DEV_ONLY_RegisterWorklet: 101;
16
15
  readonly DEV_ONLY_SetSnapshotEntryName: 102;
17
16
  };
18
17
  export declare const SnapshotOperationParams: Record<number, {
@@ -15,7 +15,6 @@ export const SnapshotOperation = {
15
15
  nodesRefInsertBefore: 5,
16
16
  nodesRefRemoveChild: 6,
17
17
  DEV_ONLY_AddSnapshot: 100,
18
- DEV_ONLY_RegisterWorklet: 101,
19
18
  DEV_ONLY_SetSnapshotEntryName: 102,
20
19
  };
21
20
  export const SnapshotOperationParams = /* @__PURE__ */ {
@@ -60,10 +59,6 @@ export const SnapshotOperationParams = /* @__PURE__ */ {
60
59
  'snapshotCreator', /* string */
61
60
  ],
62
61
  },
63
- [SnapshotOperation.DEV_ONLY_RegisterWorklet]: {
64
- name: 'DEV_ONLY_RegisterWorklet',
65
- params: ['hash', /* string */ 'fnStr' /* string */],
66
- },
67
62
  [SnapshotOperation.DEV_ONLY_SetSnapshotEntryName]: {
68
63
  name: 'DEV_ONLY_SetSnapshotEntryName',
69
64
  params: ['uniqID', /* string */ 'entryName' /* string */],
@@ -1 +1 @@
1
- {"version":3,"file":"snapshotPatch.js","sourceRoot":"","sources":["../../../../src/snapshot/lifecycle/patch/snapshotPatch.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D;;;;GAIG;AAEH,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAC/B,aAAa,EAAE,CAAC;IAChB,YAAY,EAAE,CAAC;IACf,WAAW,EAAE,CAAC;IACd,YAAY,EAAE,CAAC;IACf,aAAa,EAAE,CAAC;IAChB,oBAAoB,EAAE,CAAC;IACvB,mBAAmB,EAAE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E;YACN,YAAY,EAAE,2BAA2B;YACzC,SAAS,EAAE,YAAY;SACxB;KACF;IACD,CAAC,iBAAiB,CAAC,oBAAoB,CAAC,EAAE;QACxC,IAAI,EAAE,sBAAsB;QAC5B,MAAM,EAAE;YACN,QAAQ,EAAE,YAAY;YACtB,iBAAiB,EAAE,YAAY;SAChC;KACF;IACD,CAAC,iBAAiB,CAAC,wBAAwB,CAAC,EAAE;QAC5C,IAAI,EAAE,0BAA0B;QAChC,MAAM,EAAE,CAAC,MAAM,EAAE,YAAY,CAAC,OAAO,CAAC,YAAY,CAAC;KACpD;IACD,CAAC,iBAAiB,CAAC,6BAA6B,CAAC,EAAE;QACjD,IAAI,EAAE,+BAA+B;QACrC,MAAM,EAAE,CAAC,QAAQ,EAAE,YAAY,CAAC,WAAW,CAAC,YAAY,CAAC;KAC1D;CACO,CAAC;AAIX,MAAM,CAAC,IAAI,qBAAgD,CAAC;AAE5D,MAAM,UAAU,uBAAuB;IACrC,IAAI,qBAAqB,EAAE,CAAC;QAC1B,MAAM,IAAI,GAAG,qBAAqB,CAAC;QACnC,qBAAqB,GAAG,EAAE,CAAC;QAC3B,OAAO,IAAI,CAAC;IACd,CAAC;SAAM,CAAC;QACN,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC;AAED,MAAM,UAAU,uBAAuB;IACrC,qBAAqB,GAAG,EAAE,CAAC;AAC7B,CAAC;AAED,MAAM,UAAU,yBAAyB;IACvC,qBAAqB,GAAG,SAAS,CAAC;AACpC,CAAC","sourcesContent":["// Copyright 2024 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\n/**\n * Defines the core patch operations for the snapshot system.\n * The patch operations are designed to be serializable and minimal, allowing\n * efficient transmission between threads and application to element tree.\n */\n\nexport const SnapshotOperation = {\n CreateElement: 0,\n InsertBefore: 1,\n RemoveChild: 2,\n SetAttribute: 3,\n SetAttributes: 4,\n nodesRefInsertBefore: 5,\n nodesRefRemoveChild: 6,\n\n DEV_ONLY_AddSnapshot: 100,\n DEV_ONLY_RegisterWorklet: 101,\n DEV_ONLY_SetSnapshotEntryName: 102,\n} as const;\n\nexport const SnapshotOperationParams: Record<number, { name: string; params: string[] }> = /* @__PURE__ */ {\n [SnapshotOperation.CreateElement]: {\n name: 'CreateElement',\n params: ['type', /* string */ 'id' /* number */],\n },\n [SnapshotOperation.InsertBefore]: {\n name: 'InsertBefore',\n params: [\n 'parentId',\n /* number */ 'childId',\n /* number */ 'beforeId',\n /* number | undefined */ 'slotIndex', /* number | undefined */\n ],\n },\n [SnapshotOperation.RemoveChild]: { name: 'RemoveChild', params: ['parentId', /* number */ 'childId' /* number */] },\n [SnapshotOperation.SetAttribute]: {\n name: 'SetAttribute',\n params: ['id', /* number */ 'dynamicPartIndex', /* number */ 'value' /* any */],\n },\n [SnapshotOperation.SetAttributes]: { name: 'SetAttributes', params: ['id', /* number */ 'values' /* any */] },\n [SnapshotOperation.nodesRefInsertBefore]: {\n name: 'nodesRefInsertBefore',\n params: [\n 'identifier', /* string — CSS selector */\n 'childId', /* number */\n 'beforeId', /* number | undefined */\n ],\n },\n [SnapshotOperation.nodesRefRemoveChild]: {\n name: 'nodesRefRemoveChild',\n params: [\n 'identifier', /* string — CSS selector */\n 'childId', /* number */\n ],\n },\n [SnapshotOperation.DEV_ONLY_AddSnapshot]: {\n name: 'DEV_ONLY_AddSnapshot',\n params: [\n 'uniqID', /* string */\n 'snapshotCreator', /* string */\n ],\n },\n [SnapshotOperation.DEV_ONLY_RegisterWorklet]: {\n name: 'DEV_ONLY_RegisterWorklet',\n params: ['hash', /* string */ 'fnStr' /* string */],\n },\n [SnapshotOperation.DEV_ONLY_SetSnapshotEntryName]: {\n name: 'DEV_ONLY_SetSnapshotEntryName',\n params: ['uniqID', /* string */ 'entryName' /* string */],\n },\n} as const;\n\nexport type SnapshotPatch = unknown[];\n\nexport let __globalSnapshotPatch: SnapshotPatch | undefined;\n\nexport function takeGlobalSnapshotPatch(): SnapshotPatch | undefined {\n if (__globalSnapshotPatch) {\n const list = __globalSnapshotPatch;\n __globalSnapshotPatch = [];\n return list;\n } else {\n return undefined;\n }\n}\n\nexport function initGlobalSnapshotPatch(): void {\n __globalSnapshotPatch = [];\n}\n\nexport function deinitGlobalSnapshotPatch(): void {\n __globalSnapshotPatch = undefined;\n}\n"]}
1
+ {"version":3,"file":"snapshotPatch.js","sourceRoot":"","sources":["../../../../src/snapshot/lifecycle/patch/snapshotPatch.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D;;;;GAIG;AAEH,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAC/B,aAAa,EAAE,CAAC;IAChB,YAAY,EAAE,CAAC;IACf,WAAW,EAAE,CAAC;IACd,YAAY,EAAE,CAAC;IACf,aAAa,EAAE,CAAC;IAChB,oBAAoB,EAAE,CAAC;IACvB,mBAAmB,EAAE,CAAC;IAEtB,oBAAoB,EAAE,GAAG;IACzB,6BAA6B,EAAE,GAAG;CAC1B,CAAC;AAEX,MAAM,CAAC,MAAM,uBAAuB,GAAuD,eAAe,CAAC;IACzG,CAAC,iBAAiB,CAAC,aAAa,CAAC,EAAE;QACjC,IAAI,EAAE,eAAe;QACrB,MAAM,EAAE,CAAC,MAAM,EAAE,YAAY,CAAC,IAAI,CAAC,YAAY,CAAC;KACjD;IACD,CAAC,iBAAiB,CAAC,YAAY,CAAC,EAAE;QAChC,IAAI,EAAE,cAAc;QACpB,MAAM,EAAE;YACN,UAAU;YACV,YAAY,CAAC,SAAS;YACtB,YAAY,CAAC,UAAU;YACvB,wBAAwB,CAAC,WAAW,EAAE,wBAAwB;SAC/D;KACF;IACD,CAAC,iBAAiB,CAAC,WAAW,CAAC,EAAE,EAAE,IAAI,EAAE,aAAa,EAAE,MAAM,EAAE,CAAC,UAAU,EAAE,YAAY,CAAC,SAAS,CAAC,YAAY,CAAC,EAAE;IACnH,CAAC,iBAAiB,CAAC,YAA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C,qBAAqB,GAAG,EAAE,CAAC;AAC7B,CAAC;AAED,MAAM,UAAU,yBAAyB;IACvC,qBAAqB,GAAG,SAAS,CAAC;AACpC,CAAC","sourcesContent":["// Copyright 2024 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\n/**\n * Defines the core patch operations for the snapshot system.\n * The patch operations are designed to be serializable and minimal, allowing\n * efficient transmission between threads and application to element tree.\n */\n\nexport const SnapshotOperation = {\n CreateElement: 0,\n InsertBefore: 1,\n RemoveChild: 2,\n SetAttribute: 3,\n SetAttributes: 4,\n nodesRefInsertBefore: 5,\n nodesRefRemoveChild: 6,\n\n DEV_ONLY_AddSnapshot: 100,\n DEV_ONLY_SetSnapshotEntryName: 102,\n} as const;\n\nexport const SnapshotOperationParams: Record<number, { name: string; params: string[] }> = /* @__PURE__ */ {\n [SnapshotOperation.CreateElement]: {\n name: 'CreateElement',\n params: ['type', /* string */ 'id' /* number */],\n },\n [SnapshotOperation.InsertBefore]: {\n name: 'InsertBefore',\n params: [\n 'parentId',\n /* number */ 'childId',\n /* number */ 'beforeId',\n /* number | undefined */ 'slotIndex', /* number | undefined */\n ],\n },\n [SnapshotOperation.RemoveChild]: { name: 'RemoveChild', params: ['parentId', /* number */ 'childId' /* number */] },\n [SnapshotOperation.SetAttribute]: {\n name: 'SetAttribute',\n params: ['id', /* number */ 'dynamicPartIndex', /* number */ 'value' /* any */],\n },\n [SnapshotOperation.SetAttributes]: { name: 'SetAttributes', params: ['id', /* number */ 'values' /* any */] },\n [SnapshotOperation.nodesRefInsertBefore]: {\n name: 'nodesRefInsertBefore',\n params: [\n 'identifier', /* string — CSS selector */\n 'childId', /* number */\n 'beforeId', /* number | undefined */\n ],\n },\n [SnapshotOperation.nodesRefRemoveChild]: {\n name: 'nodesRefRemoveChild',\n params: [\n 'identifier', /* string — CSS selector */\n 'childId', /* number */\n ],\n },\n [SnapshotOperation.DEV_ONLY_AddSnapshot]: {\n name: 'DEV_ONLY_AddSnapshot',\n params: [\n 'uniqID', /* string */\n 'snapshotCreator', /* string */\n ],\n },\n [SnapshotOperation.DEV_ONLY_SetSnapshotEntryName]: {\n name: 'DEV_ONLY_SetSnapshotEntryName',\n params: ['uniqID', /* string */ 'entryName' /* string */],\n },\n} as const;\n\nexport type SnapshotPatch = unknown[];\n\nexport let __globalSnapshotPatch: SnapshotPatch | undefined;\n\nexport function takeGlobalSnapshotPatch(): SnapshotPatch | undefined {\n if (__globalSnapshotPatch) {\n const list = __globalSnapshotPatch;\n __globalSnapshotPatch = [];\n return list;\n } else {\n return undefined;\n }\n}\n\nexport function initGlobalSnapshotPatch(): void {\n __globalSnapshotPatch = [];\n}\n\nexport function deinitGlobalSnapshotPatch(): void {\n __globalSnapshotPatch = undefined;\n}\n"]}
@@ -160,16 +160,6 @@ export function snapshotPatchApply(snapshotPatch, commitId, isHydration) {
160
160
  }
161
161
  break;
162
162
  }
163
- // case SnapshotOperation.DEV_ONLY_RegisterWorklet: {
164
- // // HMR-related
165
- // if (__DEV__) {
166
- // const hash: string = snapshotPatch[++i];
167
- // const fnStr: string = snapshotPatch[++i];
168
- // const fn = evaluate<(ctx: SnapshotInstance) => FiberElement[]>(fnStr);
169
- // registerWorklet('main-thread', hash, fn);
170
- // }
171
- // break;
172
- // }
173
163
  }
174
164
  }
175
165
  }
@@ -1 +1 @@
1
- {"version":3,"file":"snapshotPatchApply.js","sourceRoot":"","sources":["../../../../src/snapshot/lifecycle/patch/snapshotPatchApply.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D;;;;;;;;;GASG;AAEH,OAAO,EAAE,gCAAgC,EAAE,MAAM,YAAY,CAAC;AAC9D,OAAO,EAAE,yBAAyB,EAAE,wBAAwB,EAAE,MAAM,oBAAoB,CAAC;AAEzF,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,EAAE,gBAAgB,EAAE,kBA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AC;IACD,MAAM,IAAI,KAAK,CAAC,sDAAsD,CAAC,CAAC;AAC1E,CAAC;AACD,oBAAoB","sourcesContent":["// Copyright 2024 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\n/**\n * Implements the patch application logic for the snapshot system.\n * This module is responsible for interpreting and executing patch operations\n * that were generated in the background thread, applying them to the DOM\n * in the main thread.\n *\n * The module handles various operations like element creation, insertion,\n * removal, and attribute updates, ensuring they are applied in the correct\n * order and with proper error handling.\n */\n\nimport { sendCtxNotFoundEventToBackground } from './error.js';\nimport { applyNodesRefInsertBefore, applyNodesRefRemoveChild } from './nodesRefApply.js';\nimport type { SnapshotPatch } from './snapshotPatch.js';\nimport { SnapshotOperation } from './snapshotPatch.js';\nimport { SnapshotInstance, snapshotCreatorMap, snapshotInstanceManager } from '../../snapshot/snapshot.js';\n\n/**\n * Applies a patch of snapshot operations to the main thread.\n * This is the counterpart to the patch generation in the background thread.\n * Each operation in the patch is processed sequentially to update the DOM.\n */\nexport function snapshotPatchApply(snapshotPatch: SnapshotPatch, commitId: number, isHydration: boolean): void {\n const length = snapshotPatch.length;\n for (let i = 0; i < length; ++i) {\n switch (snapshotPatch[i]) {\n case SnapshotOperation.CreateElement: {\n const type = snapshotPatch[++i] as string;\n const id = snapshotPatch[++i] as number;\n new SnapshotInstance(type, id);\n break;\n }\n case SnapshotOperation.InsertBefore: {\n const parentId = snapshotPatch[++i] as number;\n const childId = snapshotPatch[++i] as number;\n const beforeId = snapshotPatch[++i] as number | undefined;\n const __slotIndex = snapshotPatch[++i] as number;\n const parent = snapshotInstanceManager.values.get(parentId);\n const child = snapshotInstanceManager.values.get(childId);\n const existingNode = snapshotInstanceManager.values.get(beforeId!);\n if (!parent || !child) {\n sendCtxNotFoundEventToBackground(parent ? childId : parentId, {\n operation: 'InsertBefore',\n commitId,\n isHydration,\n parent: parentId,\n child: childId,\n missingNode: parent ? 2 : (child ? 1 : 3),\n });\n } else {\n child.__slotIndex = __slotIndex;\n parent.insertBefore(child, existingNode);\n }\n break;\n }\n case SnapshotOperation.RemoveChild: {\n const parentId = snapshotPatch[++i] as number;\n const childId = snapshotPatch[++i] as number;\n const parent = snapshotInstanceManager.values.get(parentId);\n const child = snapshotInstanceManager.values.get(childId);\n if (!parent || !child) {\n sendCtxNotFoundEventToBackground(parent ? childId : parentId, {\n operation: 'RemoveChild',\n commitId,\n isHydration,\n parent: parentId,\n child: childId,\n missingNode: parent ? 2 : (child ? 1 : 3),\n });\n } else {\n parent.removeChild(child);\n }\n break;\n }\n case SnapshotOperation.nodesRefInsertBefore: {\n const identifier = snapshotPatch[++i] as string;\n const childId = snapshotPatch[++i] as number;\n const beforeId = snapshotPatch[++i] as number | undefined;\n const child = snapshotInstanceManager.values.get(childId);\n if (child) {\n applyNodesRefInsertBefore(identifier, child, beforeId);\n } else {\n sendCtxNotFoundEventToBackground(childId, {\n operation: 'nodesRefInsertBefore',\n commitId,\n isHydration,\n });\n }\n break;\n }\n case SnapshotOperation.nodesRefRemoveChild: {\n const identifier = snapshotPatch[++i] as string;\n const childId = snapshotPatch[++i] as number;\n const child = snapshotInstanceManager.values.get(childId);\n if (child) {\n applyNodesRefRemoveChild(identifier, child);\n } else {\n sendCtxNotFoundEventToBackground(childId, {\n operation: 'nodesRefRemoveChild',\n commitId,\n isHydration,\n });\n }\n break;\n }\n case SnapshotOperation.SetAttribute: {\n const id = snapshotPatch[++i] as number;\n const dynamicPartIndex = snapshotPatch[++i] as number;\n const value = snapshotPatch[++i];\n const si = snapshotInstanceManager.values.get(id);\n if (si) {\n si.setAttribute(dynamicPartIndex, value);\n } else {\n sendCtxNotFoundEventToBackground(id, { operation: 'SetAttribute', commitId, isHydration });\n }\n break;\n }\n case SnapshotOperation.SetAttributes: {\n const id = snapshotPatch[++i] as number;\n const values = snapshotPatch[++i];\n const si = snapshotInstanceManager.values.get(id);\n if (si) {\n si.setAttribute('values', values);\n } else {\n sendCtxNotFoundEventToBackground(id, { operation: 'SetAttributes', commitId, isHydration });\n }\n break;\n }\n case SnapshotOperation.DEV_ONLY_AddSnapshot: {\n if (__DEV__) {\n const uniqID = snapshotPatch[++i] as string;\n const snapshotCreator = snapshotPatch[++i] as string;\n\n // HMR-related\n // Update the evaluated snapshots from JS.\n snapshotCreatorMap[uniqID] = evaluate<(uniqId: string) => string>(snapshotCreator);\n }\n break;\n }\n case SnapshotOperation.DEV_ONLY_SetSnapshotEntryName: {\n if (__DEV__) {\n const uniqID = snapshotPatch[++i] as string;\n const entryName = snapshotPatch[++i] as string;\n\n // HMR-related\n // Update the evaluated snapshot entryName from JS.\n const source = snapshotCreatorMap[uniqID]?.toString();\n if (source?.includes('globDynamicComponentEntry')) {\n try {\n snapshotCreatorMap[uniqID] = evaluate<(uniqId: string) => string>(\n source.replace(/globDynamicComponentEntry/g, JSON.stringify(entryName)),\n );\n } catch (e) {\n console.warn(`[ReactLynx] failed to rewrite snapshot entryName for ${uniqID}`, e);\n }\n }\n }\n break;\n }\n // case SnapshotOperation.DEV_ONLY_RegisterWorklet: {\n // // HMR-related\n // if (__DEV__) {\n // const hash: string = snapshotPatch[++i];\n // const fnStr: string = snapshotPatch[++i];\n // const fn = evaluate<(ctx: SnapshotInstance) => FiberElement[]>(fnStr);\n // registerWorklet('main-thread', hash, fn);\n // }\n // break;\n // }\n }\n }\n}\n\n/* v8 ignore start */\n/**\n * Deserializes a stringified snapshot creator for HMR.\n */\nfunction evaluate<T>(code: string): T {\n if (__DEV__) {\n // Creators receive the runtime as a call argument (see `SnapshotCreator`).\n // Direct `eval` is kept for the legacy `__runtime__ || require(...)`\n // fallback, which resolves `__webpack_require__` from this scope on\n // runtimes that call creators with a single argument.\n return eval(`(() => ${code})()`) as T;\n }\n throw new Error('unreachable: evaluate is not supported in production');\n}\n/* v8 ignore stop */\n"]}
1
+ {"version":3,"file":"snapshotPatchApply.js","sourceRoot":"","sources":["../../../../src/snapshot/lifecycle/patch/snapshotPatchApply.ts"],"names":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B,IAAI,OAAO,EAAE,CAAC;QACZ,2EAA2E;QAC3E,qEAAqE;QACrE,oEAAoE;QACpE,sDAAsD;QACtD,OAAO,IAAI,CAAC,UAAU,IAAI,KAAK,CAAM,CAAC;IACxC,CAAC;IACD,MAAM,IAAI,KAAK,CAAC,sDAAsD,CAAC,CAAC;AAC1E,CAAC;AACD,oBAAoB","sourcesContent":["// Copyright 2024 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\n/**\n * Implements the patch application logic for the snapshot system.\n * This module is responsible for interpreting and executing patch operations\n * that were generated in the background thread, applying them to the DOM\n * in the main thread.\n *\n * The module handles various operations like element creation, insertion,\n * removal, and attribute updates, ensuring they are applied in the correct\n * order and with proper error handling.\n */\n\nimport { sendCtxNotFoundEventToBackground } from './error.js';\nimport { applyNodesRefInsertBefore, applyNodesRefRemoveChild } from './nodesRefApply.js';\nimport type { SnapshotPatch } from './snapshotPatch.js';\nimport { SnapshotOperation } from './snapshotPatch.js';\nimport { SnapshotInstance, snapshotCreatorMap, snapshotInstanceManager } from '../../snapshot/snapshot.js';\n\n/**\n * Applies a patch of snapshot operations to the main thread.\n * This is the counterpart to the patch generation in the background thread.\n * Each operation in the patch is processed sequentially to update the DOM.\n */\nexport function snapshotPatchApply(snapshotPatch: SnapshotPatch, commitId: number, isHydration: boolean): void {\n const length = snapshotPatch.length;\n for (let i = 0; i < length; ++i) {\n switch (snapshotPatch[i]) {\n case SnapshotOperation.CreateElement: {\n const type = snapshotPatch[++i] as string;\n const id = snapshotPatch[++i] as number;\n new SnapshotInstance(type, id);\n break;\n }\n case SnapshotOperation.InsertBefore: {\n const parentId = snapshotPatch[++i] as number;\n const childId = snapshotPatch[++i] as number;\n const beforeId = snapshotPatch[++i] as number | undefined;\n const __slotIndex = snapshotPatch[++i] as number;\n const parent = snapshotInstanceManager.values.get(parentId);\n const child = snapshotInstanceManager.values.get(childId);\n const existingNode = snapshotInstanceManager.values.get(beforeId!);\n if (!parent || !child) {\n sendCtxNotFoundEventToBackground(parent ? childId : parentId, {\n operation: 'InsertBefore',\n commitId,\n isHydration,\n parent: parentId,\n child: childId,\n missingNode: parent ? 2 : (child ? 1 : 3),\n });\n } else {\n child.__slotIndex = __slotIndex;\n parent.insertBefore(child, existingNode);\n }\n break;\n }\n case SnapshotOperation.RemoveChild: {\n const parentId = snapshotPatch[++i] as number;\n const childId = snapshotPatch[++i] as number;\n const parent = snapshotInstanceManager.values.get(parentId);\n const child = snapshotInstanceManager.values.get(childId);\n if (!parent || !child) {\n sendCtxNotFoundEventToBackground(parent ? childId : parentId, {\n operation: 'RemoveChild',\n commitId,\n isHydration,\n parent: parentId,\n child: childId,\n missingNode: parent ? 2 : (child ? 1 : 3),\n });\n } else {\n parent.removeChild(child);\n }\n break;\n }\n case SnapshotOperation.nodesRefInsertBefore: {\n const identifier = snapshotPatch[++i] as string;\n const childId = snapshotPatch[++i] as number;\n const beforeId = snapshotPatch[++i] as number | undefined;\n const child = snapshotInstanceManager.values.get(childId);\n if (child) {\n applyNodesRefInsertBefore(identifier, child, beforeId);\n } else {\n sendCtxNotFoundEventToBackground(childId, {\n operation: 'nodesRefInsertBefore',\n commitId,\n isHydration,\n });\n }\n break;\n }\n case SnapshotOperation.nodesRefRemoveChild: {\n const identifier = snapshotPatch[++i] as string;\n const childId = snapshotPatch[++i] as number;\n const child = snapshotInstanceManager.values.get(childId);\n if (child) {\n applyNodesRefRemoveChild(identifier, child);\n } else {\n sendCtxNotFoundEventToBackground(childId, {\n operation: 'nodesRefRemoveChild',\n commitId,\n isHydration,\n });\n }\n break;\n }\n case SnapshotOperation.SetAttribute: {\n const id = snapshotPatch[++i] as number;\n const dynamicPartIndex = snapshotPatch[++i] as number;\n const value = snapshotPatch[++i];\n const si = snapshotInstanceManager.values.get(id);\n if (si) {\n si.setAttribute(dynamicPartIndex, value);\n } else {\n sendCtxNotFoundEventToBackground(id, { operation: 'SetAttribute', commitId, isHydration });\n }\n break;\n }\n case SnapshotOperation.SetAttributes: {\n const id = snapshotPatch[++i] as number;\n const values = snapshotPatch[++i];\n const si = snapshotInstanceManager.values.get(id);\n if (si) {\n si.setAttribute('values', values);\n } else {\n sendCtxNotFoundEventToBackground(id, { operation: 'SetAttributes', commitId, isHydration });\n }\n break;\n }\n case SnapshotOperation.DEV_ONLY_AddSnapshot: {\n if (__DEV__) {\n const uniqID = snapshotPatch[++i] as string;\n const snapshotCreator = snapshotPatch[++i] as string;\n\n // HMR-related\n // Update the evaluated snapshots from JS.\n snapshotCreatorMap[uniqID] = evaluate<(uniqId: string) => string>(snapshotCreator);\n }\n break;\n }\n case SnapshotOperation.DEV_ONLY_SetSnapshotEntryName: {\n if (__DEV__) {\n const uniqID = snapshotPatch[++i] as string;\n const entryName = snapshotPatch[++i] as string;\n\n // HMR-related\n // Update the evaluated snapshot entryName from JS.\n const source = snapshotCreatorMap[uniqID]?.toString();\n if (source?.includes('globDynamicComponentEntry')) {\n try {\n snapshotCreatorMap[uniqID] = evaluate<(uniqId: string) => string>(\n source.replace(/globDynamicComponentEntry/g, JSON.stringify(entryName)),\n );\n } catch (e) {\n console.warn(`[ReactLynx] failed to rewrite snapshot entryName for ${uniqID}`, e);\n }\n }\n }\n break;\n }\n }\n }\n}\n\n/* v8 ignore start */\n/**\n * Deserializes a stringified snapshot creator for HMR.\n */\nfunction evaluate<T>(code: string): T {\n if (__DEV__) {\n // Creators receive the runtime as a call argument (see `SnapshotCreator`).\n // Direct `eval` is kept for the legacy `__runtime__ || require(...)`\n // fallback, which resolves `__webpack_require__` from this scope on\n // runtimes that call creators with a single argument.\n return eval(`(() => ${code})()`) as T;\n }\n throw new Error('unreachable: evaluate is not supported in production');\n}\n/* v8 ignore stop */\n"]}