@lynx-js/react 0.108.0 → 0.109.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (98) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/package.json +4 -4
  3. package/refresh/.turbo/turbo-build.log +1 -1
  4. package/runtime/jsx-dev-runtime/index.d.ts +13 -7
  5. package/runtime/jsx-runtime/index.d.ts +17 -7
  6. package/runtime/lib/gesture/processGesture.d.ts +2 -2
  7. package/runtime/lib/gesture/processGesture.js +14 -7
  8. package/runtime/lib/gesture/processGesture.js.map +1 -1
  9. package/runtime/lib/lifecycle/patch/isMainThreadHydrationFinished.d.ts +2 -0
  10. package/runtime/lib/lifecycle/patch/isMainThreadHydrationFinished.js +9 -0
  11. package/runtime/lib/lifecycle/patch/isMainThreadHydrationFinished.js.map +1 -0
  12. package/runtime/lib/lifecycle/patch/snapshotPatchApply.js +2 -2
  13. package/runtime/lib/lifecycle/patch/snapshotPatchApply.js.map +1 -1
  14. package/runtime/lib/lifecycle/patch/updateMainThread.js +4 -3
  15. package/runtime/lib/lifecycle/patch/updateMainThread.js.map +1 -1
  16. package/runtime/lib/lifecycle/reload.js +2 -0
  17. package/runtime/lib/lifecycle/reload.js.map +1 -1
  18. package/runtime/lib/snapshot/gesture.d.ts +1 -1
  19. package/runtime/lib/snapshot/gesture.js +4 -3
  20. package/runtime/lib/snapshot/gesture.js.map +1 -1
  21. package/runtime/lib/snapshot/ref.js.map +1 -1
  22. package/runtime/lib/snapshot/spread.d.ts +0 -6
  23. package/runtime/lib/snapshot/spread.js +4 -10
  24. package/runtime/lib/snapshot/spread.js.map +1 -1
  25. package/runtime/lib/snapshot/workletEvent.d.ts +2 -1
  26. package/runtime/lib/snapshot/workletEvent.js +4 -3
  27. package/runtime/lib/snapshot/workletEvent.js.map +1 -1
  28. package/runtime/lib/snapshot/workletRef.d.ts +4 -4
  29. package/runtime/lib/snapshot/workletRef.js +6 -4
  30. package/runtime/lib/snapshot/workletRef.js.map +1 -1
  31. package/runtime/lib/snapshot.d.ts +1 -0
  32. package/runtime/lib/snapshot.js +5 -4
  33. package/runtime/lib/snapshot.js.map +1 -1
  34. package/runtime/lib/worklet/runOnBackground.js +21 -12
  35. package/runtime/lib/worklet/runOnBackground.js.map +1 -1
  36. package/runtime/lib/worklet/workletRef.d.ts +1 -0
  37. package/runtime/lib/worklet/workletRef.js +14 -12
  38. package/runtime/lib/worklet/workletRef.js.map +1 -1
  39. package/runtime/src/gesture/processGesture.ts +23 -15
  40. package/runtime/src/lifecycle/patch/isMainThreadHydrationFinished.ts +10 -0
  41. package/runtime/src/lifecycle/patch/snapshotPatchApply.ts +8 -2
  42. package/runtime/src/lifecycle/patch/updateMainThread.ts +4 -3
  43. package/runtime/src/lifecycle/reload.ts +2 -0
  44. package/runtime/src/snapshot/gesture.ts +6 -4
  45. package/runtime/src/snapshot/ref.ts +2 -2
  46. package/runtime/src/snapshot/spread.ts +15 -5
  47. package/runtime/src/snapshot/workletEvent.ts +5 -3
  48. package/runtime/src/snapshot/workletRef.ts +17 -18
  49. package/runtime/src/snapshot.ts +6 -4
  50. package/runtime/src/worklet/runOnBackground.ts +37 -15
  51. package/runtime/src/worklet/workletRef.ts +15 -12
  52. package/testing-library/dist/vitest-global-setup.js +7 -0
  53. package/transform/dist/wasm.cjs +1 -1
  54. package/transform/index.d.ts +443 -14
  55. package/types/react.d.ts +1 -1
  56. package/worklet-runtime/dist/dev.js +133 -33
  57. package/worklet-runtime/dist/dev.js.map +4 -4
  58. package/worklet-runtime/dist/main.js +133 -33
  59. package/worklet-runtime/dist/main.js.map +4 -4
  60. package/worklet-runtime/lib/api/element.d.ts +3 -3
  61. package/worklet-runtime/lib/api/element.js +3 -3
  62. package/worklet-runtime/lib/api/element.js.map +1 -1
  63. package/worklet-runtime/lib/api/lepusQuerySelector.js +1 -3
  64. package/worklet-runtime/lib/api/lepusQuerySelector.js.map +1 -1
  65. package/worklet-runtime/lib/api/lynxApi.js +10 -10
  66. package/worklet-runtime/lib/api/lynxApi.js.map +1 -1
  67. package/worklet-runtime/lib/bindings/bindings.d.ts +1 -1
  68. package/worklet-runtime/lib/bindings/bindings.js +21 -8
  69. package/worklet-runtime/lib/bindings/bindings.js.map +1 -1
  70. package/worklet-runtime/lib/bindings/events.d.ts +4 -1
  71. package/worklet-runtime/lib/bindings/events.js.map +1 -1
  72. package/worklet-runtime/lib/bindings/index.d.ts +1 -1
  73. package/worklet-runtime/lib/bindings/index.js +1 -1
  74. package/worklet-runtime/lib/bindings/index.js.map +1 -1
  75. package/worklet-runtime/lib/bindings/loadRuntime.js +0 -2
  76. package/worklet-runtime/lib/bindings/loadRuntime.js.map +1 -1
  77. package/worklet-runtime/lib/bindings/types.d.ts +15 -5
  78. package/worklet-runtime/lib/bindings/types.js +3 -0
  79. package/worklet-runtime/lib/bindings/types.js.map +1 -1
  80. package/worklet-runtime/lib/delayRunOnBackground.d.ts +12 -0
  81. package/worklet-runtime/lib/delayRunOnBackground.js +23 -0
  82. package/worklet-runtime/lib/delayRunOnBackground.js.map +1 -0
  83. package/worklet-runtime/lib/delayWorkletEvent.js +2 -2
  84. package/worklet-runtime/lib/delayWorkletEvent.js.map +1 -1
  85. package/worklet-runtime/lib/global.d.ts +6 -3
  86. package/worklet-runtime/lib/hydrate.d.ts +11 -0
  87. package/worklet-runtime/lib/hydrate.js +86 -0
  88. package/worklet-runtime/lib/hydrate.js.map +1 -0
  89. package/worklet-runtime/lib/jsFunctionLifecycle.js +2 -2
  90. package/worklet-runtime/lib/jsFunctionLifecycle.js.map +1 -1
  91. package/worklet-runtime/lib/listeners.js.map +1 -1
  92. package/worklet-runtime/lib/utils/profile.d.ts +1 -1
  93. package/worklet-runtime/lib/utils/version.js +1 -1
  94. package/worklet-runtime/lib/workletRef.d.ts +6 -3
  95. package/worklet-runtime/lib/workletRef.js +33 -6
  96. package/worklet-runtime/lib/workletRef.js.map +1 -1
  97. package/worklet-runtime/lib/workletRuntime.js +12 -14
  98. package/worklet-runtime/lib/workletRuntime.js.map +1 -1
@@ -2,15 +2,19 @@
2
2
  // Licensed under the Apache License Version 2.0 that can be found in the
3
3
  // LICENSE file in the root directory of this source tree.
4
4
  /**
5
- * Register a worklet function to the `jsFunctionLifecycleManager`.
6
- * This function mast be called when a worklet context is updated.
5
+ * This function must be called when a worklet context is updated.
7
6
  *
8
7
  * @param worklet - The worklet to be updated
9
- * @param element - The element associated with the worklet
8
+ * @param oldWorklet - The old worklet context
9
+ * @param isFirstScreen - Whether it is before the hydration is finished
10
+ * @param element - The element
10
11
  * @internal
11
12
  */
12
- function onWorkletCtxUpdate(worklet, element) {
13
+ function onWorkletCtxUpdate(worklet, oldWorklet, isFirstScreen, element) {
13
14
  globalThis.lynxWorkletImpl?._jsFunctionLifecycleManager?.addRef(worklet._execId, worklet);
15
+ if (isFirstScreen && oldWorklet) {
16
+ globalThis.lynxWorkletImpl?._hydrateCtx(worklet, oldWorklet);
17
+ }
14
18
  globalThis.lynxWorkletImpl?._eventDelayImpl.runDelayedWorklet(worklet, element);
15
19
  }
16
20
  /**
@@ -42,12 +46,13 @@ function updateWorkletRefInitValueChanges(patch) {
42
46
  }
43
47
  }
44
48
  /**
45
- * Clear all delayed worklets to run.
49
+ * This must be called when the hydration is finished.
46
50
  *
47
51
  * @internal
48
52
  */
49
- function clearDelayedWorklets() {
50
- globalThis.lynxWorkletImpl?._eventDelayImpl.clearDelayedWorklets();
53
+ function onHydrationFinished() {
54
+ globalThis.lynxWorkletImpl?._runOnBackgroundDelayImpl.runDelayedBackgroundFunctions();
55
+ globalThis.lynxWorkletImpl?._refImpl.clearFirstScreenWorkletRefMap();
51
56
  }
52
57
  /**
53
58
  * Register a worklet.
@@ -57,5 +62,13 @@ function clearDelayedWorklets() {
57
62
  function registerWorklet(type, id, worklet) {
58
63
  globalThis.registerWorklet(type, id, worklet);
59
64
  }
60
- export { onWorkletCtxUpdate, runWorkletCtx, updateWorkletRef, updateWorkletRefInitValueChanges, clearDelayedWorklets, registerWorklet, };
65
+ /**
66
+ * Delay a runOnBackground after hydration.
67
+ *
68
+ * @internal
69
+ */
70
+ function delayRunOnBackground(fnObj, fn) {
71
+ globalThis.lynxWorkletImpl?._runOnBackgroundDelayImpl.delayRunOnBackground(fnObj, fn);
72
+ }
73
+ export { onWorkletCtxUpdate, runWorkletCtx, updateWorkletRef, updateWorkletRefInitValueChanges, onHydrationFinished, registerWorklet, delayRunOnBackground, };
61
74
  //# sourceMappingURL=bindings.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"bindings.js","sourceRoot":"","sources":["../../src/bindings/bindings.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAO1D;;;;;;;GAOG;AACH,SAAS,kBAAkB,CAAC,OAAgB,EAAE,OAAoB;IAChE,UAAU,CAAC,eAAe,EAAE,2BAA2B,EAAE,MAAM,CAAC,OAAO,CAAC,OAAQ,EAAE,OAAO,CAAC,CAAC;IAC3F,UAAU,CAAC,eAAe,EAAE,eAAe,CAAC,iBAAiB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;AAClF,CAAC;AAED;;;;GAIG;AACH,SAAS,aAAa,CAAC,OAAgB,EAAE,MAA0B;IACjE,OAAO,UAAU,CAAC,UAAU,EAAE,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;AAClD,CAAC;AAED;;;;;;GAMG;AACH,SAAS,gBAAgB,CAAC,UAAmC,EAAE,OAA2B;IACxF,UAAU,CAAC,eAAe,EAAE,QAAQ,CAAC,gBAAgB,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;AAC7E,CAAC;AAED;;;;GAIG;AACH,SAAS,gCAAgC,CAAC,KAA2B;IACnE,IAAI,KAAK,EAAE,CAAC;QACV,UAAU,CAAC,eAAe,EAAE,QAAQ,CAAC,gCAAgC,CAAC,KAAK,CAAC,CAAC;IAC/E,CAAC;AACH,CAAC;AAED;;;;GAIG;AACH,SAAS,oBAAoB;IAC3B,UAAU,CAAC,e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QACV,UAAU,CAAC,eAAe,EAAE,QAAQ,CAAC,gCAAgC,CAAC,KAAK,CAAC,CAAC;IAC/E,CAAC;AACH,CAAC;AAED;;;;GAIG;AACH,SAAS,mBAAmB;IAC1B,UAAU,CAAC,eAAe,EAAE,yBAAyB,CAAC,6BAA6B,EAAE,CAAC;IACtF,UAAU,CAAC,eAAe,EAAE,QAAQ,CAAC,6BAA6B,EAAE,CAAC;AACvE,CAAC;AAED;;;;GAIG;AACH,SAAS,eAAe,CAAC,IAAY,EAAE,EAAU,EAAE,OAAwC;IACzF,UAAU,CAAC,eAAe,CAAC,IAAI,EAAE,EAAE,EAAE,OAAO,CAAC,CAAC;AAChD,CAAC;AAED;;;;GAIG;AACH,SAAS,oBAAoB,CAAC,KAAiB,EAAE,EAA0C;IACzF,UAAU,CAAC,eAAe,EAAE,yBAAyB,CAAC,oBAAoB,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;AACxF,CAAC;AAED,OAAO,EACL,kBAAkB,EAClB,aAAa,EACb,gBAAgB,EAChB,gCAAgC,EAChC,mBAAmB,EACnB,eAAe,EACf,oBAAoB,GACrB,CAAC"}
@@ -15,4 +15,7 @@ interface RunWorkletCtxRetData {
15
15
  resolveId: number;
16
16
  returnValue: unknown;
17
17
  }
18
- export { WorkletEvents, type RunWorkletCtxData, type RunWorkletCtxRetData };
18
+ interface ReleaseWorkletRefData {
19
+ id: number;
20
+ }
21
+ export { WorkletEvents, type RunWorkletCtxData, type RunWorkletCtxRetData, type ReleaseWorkletRefData };
@@ -1 +1 @@
1
- {"version":3,"file":"events.js","sourceRoot":"","sources":["../../src/bindings/events.ts"],"names":[],"mappings":"AAEA,IAAW,aAMV;AAND,WAAW,aAAa;IACtB,6DAA4C,CAAA;IAC5C,iEAAgD,CAAA;IAChD,iEAAgD,CAAA;IAChD,yFAAwE,CAAA;IACxE,qEAAoD,CAAA;AACtD,CAAC,EANU,aAAa,KAAb,aAAa,QAMvB;AAaD,OAAO,EAAE,aAAa,EAAqD,CAAC"}
1
+ {"version":3,"file":"events.js","sourceRoot":"","sources":["../../src/bindings/events.ts"],"names":[],"mappings":"AAKA,IAAW,aAMV;AAND,WAAW,aAAa;IACtB,6DAA4C,CAAA;IAC5C,iEAAgD,CAAA;IAChD,iEAAgD,CAAA;IAChD,yFAAwE,CAAA;IACxE,qEAAoD,CAAA;AACtD,CAAC,EANU,aAAa,KAAb,aAAa,QAMvB;AAiBD,OAAO,EAAE,aAAa,EAAiF,CAAC"}
@@ -1,4 +1,4 @@
1
1
  export { loadWorkletRuntime } from './loadRuntime.js';
2
- export { onWorkletCtxUpdate, runWorkletCtx, updateWorkletRef, updateWorkletRefInitValueChanges, clearDelayedWorklets, } from './bindings.js';
2
+ export { onWorkletCtxUpdate, runWorkletCtx, updateWorkletRef, updateWorkletRefInitValueChanges, onHydrationFinished, delayRunOnBackground, } from './bindings.js';
3
3
  export type * from './types.js';
4
4
  export { WorkletEvents, type RunWorkletCtxData, type RunWorkletCtxRetData } from './events.js';
@@ -2,6 +2,6 @@
2
2
  // Licensed under the Apache License Version 2.0 that can be found in the
3
3
  // LICENSE file in the root directory of this source tree.
4
4
  export { loadWorkletRuntime } from './loadRuntime.js';
5
- export { onWorkletCtxUpdate, runWorkletCtx, updateWorkletRef, updateWorkletRefInitValueChanges, clearDelayedWorklets, } from './bindings.js';
5
+ export { onWorkletCtxUpdate, runWorkletCtx, updateWorkletRef, updateWorkletRefInitValueChanges, onHydrationFinished, delayRunOnBackground, } from './bindings.js';
6
6
  export { WorkletEvents } from './events.js';
7
7
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/bindings/index.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAC1D,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAEtD,OAAO,EACL,kBAAkB,EAClB,aAAa,EACb,gBAAgB,EAChB,gCAAgC,EAChC,oBAAoB,GACrB,MAAM,eAAe,CAAC;AAIvB,OAAO,EAAE,aAAa,EAAqD,MAAM,aAAa,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/bindings/index.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAC1D,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAEtD,OAAO,EACL,kBAAkB,EAClB,aAAa,EACb,gBAAgB,EAChB,gCAAgC,EAChC,mBAAmB,EACnB,oBAAoB,GACrB,MAAM,eAAe,CAAC;AAIvB,OAAO,EAAE,aAAa,EAAqD,MAAM,aAAa,CAAC"}
@@ -1,7 +1,6 @@
1
1
  // Copyright 2024 The Lynx Authors. All rights reserved.
2
2
  // Licensed under the Apache License Version 2.0 that can be found in the
3
3
  // LICENSE file in the root directory of this source tree.
4
- /// <reference path="../types/elementApi.d.ts" />
5
4
  import '../global.js';
6
5
  /**
7
6
  * Loads and initializes the Lepus chunk in the main thread.
@@ -16,7 +15,6 @@ function loadWorkletRuntime(__schema) {
16
15
  return true;
17
16
  }
18
17
  return __LoadLepusChunk('worklet-runtime', {
19
- // @ts-ignore
20
18
  dynamicComponentEntry: __schema,
21
19
  chunkType: 0,
22
20
  });
@@ -1 +1 @@
1
- {"version":3,"file":"loadRuntime.js","sourceRoot":"","sources":["../../src/bindings/loadRuntime.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D,iDAAiD;AAEjD,OAAO,cAAc,CAAC;AAEtB;;;;GAIG;AACH,SAAS,kBAAkB,CAAC,QAAiB;IAC3C,IAAI,OAAO,gBAAgB,KAAK,WAAW,EAAE,CAAC;QAC5C,OAAO,KAAK,CAAC;IACf,CAAC;IACD,IAAI,UAAU,CAAC,eAAe,EAAE,CAAC;QAC/B,OAAO,IAAI,CAAC;IACd,CAAC;IACD,OAAO,gBAAgB,CAAC,iBAAiB,EAAE;QACzC,aAAa;QACb,qBAAqB,EAAE,QAAQ;QAC/B,SAAS,EAAE,CAAC;KACb,CAAC,CAAC;AACL,CAAC;AAED,OAAO,EAAE,kBAAkB,EAAE,CAAC"}
1
+ {"version":3,"file":"loadRuntime.js","sourceRoot":"","sources":["../../src/bindings/loadRuntime.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D,OAAO,cAAc,CAAC;AAEtB;;;;GAIG;AACH,SAAS,kBAAkB,CAAC,QAAiB;IAC3C,IAAI,OAAO,gBAAgB,KAAK,WAAW,EAAE,CAAC;QAC5C,OAAO,KAAK,CAAC;IACf,CAAC;IACD,IAAI,UAAU,CAAC,eAAe,EAAE,CAAC;QAC/B,OAAO,IAAI,CAAC;IACd,CAAC;IACD,OAAO,gBAAgB,CAAC,iBAAiB,EAAE;QACzC,qBAAqB,EAAE,QAAQ;QAC/B,SAAS,EAAE,CAAC;KACb,CAAC,CAAC;AACL,CAAC;AAED,OAAO,EAAE,kBAAkB,EAAE,CAAC"}
@@ -1,3 +1,5 @@
1
+ import type { Element } from '../api/element.js';
2
+ export type { Element };
1
3
  export type WorkletRefId = number;
2
4
  export interface WorkletRefImpl<T> {
3
5
  _wvid: WorkletRefId;
@@ -13,23 +15,31 @@ export interface WorkletRef<T> {
13
15
  }
14
16
  interface ClosureValueType_ extends Record<string, ClosureValueType> {
15
17
  }
16
- export type ClosureValueType = null | undefined | string | boolean | number | Worklet | WorkletRef<unknown> | ClosureValueType_ | ClosureValueType[];
18
+ export type ClosureValueType = null | undefined | string | boolean | number | Worklet | WorkletRef<unknown> | Element | (((...args: unknown[]) => unknown) & {
19
+ ctx?: ClosureValueType;
20
+ }) | ClosureValueType_ | ClosureValueType[];
17
21
  export interface Worklet {
18
22
  _wkltId: string;
23
+ _workletType?: string;
19
24
  _c?: Record<string, ClosureValueType>;
20
- _lepusWorkletHash?: string;
21
25
  _execId?: number;
22
26
  _jsFn?: Record<string, string>;
23
- _unmount?: any;
27
+ _unmount?: () => void;
24
28
  [key: string]: ClosureValueType;
29
+ _lepusWorkletHash?: string;
25
30
  }
26
31
  /**
27
32
  * @public
28
33
  */
29
34
  export interface JsFnHandle {
30
- _jsFnId: number;
35
+ _jsFnId?: number;
31
36
  _fn?: (...args: unknown[]) => unknown;
32
37
  _execId?: number;
33
38
  _error?: string;
39
+ _isFirstScreen?: boolean;
40
+ /**
41
+ * Stores an array of indexes of runOnBackground tasks that should be processed with a delay.
42
+ * This is used before hydration.
43
+ */
44
+ _delayIndices?: number[];
34
45
  }
35
- export {};
@@ -1,2 +1,5 @@
1
+ // Copyright 2024 The Lynx Authors. All rights reserved.
2
+ // Licensed under the Apache License Version 2.0 that can be found in the
3
+ // LICENSE file in the root directory of this source tree.
1
4
  export {};
2
5
  //# sourceMappingURL=types.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/bindings/types.ts"],"names":[],"mappings":""}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/bindings/types.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D"}
@@ -0,0 +1,12 @@
1
+ import type { JsFnHandle } from './bindings/types.js';
2
+ interface Details {
3
+ task: (fnId: number, execId: number) => void;
4
+ jsFnHandle?: JsFnHandle;
5
+ }
6
+ interface RunOnBackgroundDelayImpl {
7
+ delayedBackgroundFunctionArray: Details[];
8
+ delayRunOnBackground(fnObj: JsFnHandle, fn: (fnId: number, execId: number) => void): void;
9
+ runDelayedBackgroundFunctions(): void;
10
+ }
11
+ declare function initRunOnBackgroundDelay(): RunOnBackgroundDelayImpl;
12
+ export { type RunOnBackgroundDelayImpl, initRunOnBackgroundDelay };
@@ -0,0 +1,23 @@
1
+ let impl;
2
+ function initRunOnBackgroundDelay() {
3
+ return (impl = {
4
+ delayedBackgroundFunctionArray: [],
5
+ delayRunOnBackground,
6
+ runDelayedBackgroundFunctions,
7
+ });
8
+ }
9
+ function delayRunOnBackground(fnObj, task) {
10
+ impl.delayedBackgroundFunctionArray.push({ task });
11
+ const delayIndices = fnObj._delayIndices ??= [];
12
+ delayIndices.push(impl.delayedBackgroundFunctionArray.length - 1);
13
+ }
14
+ function runDelayedBackgroundFunctions() {
15
+ for (const details of impl.delayedBackgroundFunctionArray) {
16
+ if (details.jsFnHandle) {
17
+ details.task(details.jsFnHandle._jsFnId, details.jsFnHandle._execId);
18
+ }
19
+ }
20
+ impl.delayedBackgroundFunctionArray.length = 0;
21
+ }
22
+ export { initRunOnBackgroundDelay };
23
+ //# sourceMappingURL=delayRunOnBackground.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"delayRunOnBackground.js","sourceRoot":"","sources":["../src/delayRunOnBackground.ts"],"names":[],"mappings":"AAmBA,IAAI,IAA0C,CAAC;AAE/C,SAAS,wBAAwB;IAC/B,OAAO,CAAC,IAAI,GAAG;QACb,8BAA8B,EAAE,EAAE;QAClC,oBAAoB;QACpB,6BAA6B;KAC9B,CAAC,CAAC;AACL,CAAC;AAED,SAAS,oBAAoB,CAAC,KAAiB,EAAE,IAA4C;IAC3F,IAAK,CAAC,8BAA8B,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC;IACpD,MAAM,YAAY,GAAG,KAAK,CAAC,aAAa,KAAK,EAAE,CAAC;IAChD,YAAY,CAAC,IAAI,CAAC,IAAK,CAAC,8BAA8B,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;AACrE,CAAC;AAED,SAAS,6BAA6B;IACpC,KAAK,MAAM,OAAO,IAAI,IAAK,CAAC,8BAA8B,EAAE,CAAC;QAC3D,IAAI,OAAO,CAAC,UAAU,EAAE,CAAC;YACvB,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,OAAQ,EAAE,OAAO,CAAC,UAAU,CAAC,OAAQ,CAAC,CAAC;QACzE,CAAC;IACH,CAAC;IACD,IAAK,CAAC,8BAA8B,CAAC,MAAM,GAAG,CAAC,CAAC;AAClD,CAAC;AAED,OAAO,EAAiC,wBAAwB,EAAE,CAAC"}
@@ -27,8 +27,8 @@ function runDelayedWorklet(worklet, element) {
27
27
  }
28
28
  const leftParamsVec = [];
29
29
  paramsVec.forEach((params) => {
30
- // @ts-ignore
31
- if (params[0]?.currentTarget?.elementRefptr === element) {
30
+ const firstParam = params[0];
31
+ if (firstParam?.currentTarget?.elementRefptr === element) {
32
32
  setTimeout(() => {
33
33
  profile('runDelayedWorklet', () => {
34
34
  runWorklet(worklet, params);
@@ -1 +1 @@
1
- {"version":3,"file":"delayWorkletEvent.js","sourceRoot":"","sources":["../src/delayWorkletEvent.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAQ7C,IAAI,IAAgC,CAAC;AAErC,SAAS,cAAc;IACrB,OAAO,CAAC,IAAI,GAAG;QACb,wBAAwB,EAAE,IAAI,GAAG,EAAE;QACnC,iBAAiB;QACjB,oBAAoB;KACrB,CAAC,CAAC;AACL,CAAC;AAED,SAAS,qBAAqB,CAC5B,IAAY,EACZ,MAA0B;IAE1B,OAAO,CAAC,yBAAyB,GAAG,IAAI,EAAE,GAAG,EAAE;QAC7C,MAAM,GAAG,GAAG,IAAK,CAAC,wBAAwB,CAAC;QAC3C,MAAM,QAAQ,GAAG,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAC/B,IAAI,QAAQ,EAAE,CAAC;YACb,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACxB,CAAC;aAAM,CAAC;YACN,GAAG,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC;QAC1B,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC;AAED,SAAS,iBAAiB,CAAC,OAAgB,EAAE,OAAoB;IAC/D,OAAO,CAAC,sBAAsB,EAAE,GAAG,EAAE;QACnC,MAAM,SAAS,GAAG,IAAK,CAAC,wBAAwB,CAAC,GAAG,CAClD,OAAO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,CAAC;AACL,CAAC;AAED,SAAS,oBAAoB;IAC3B,IAAK,CAAC,wBAAwB,CAAC,KAAK,EAAE,CAAC;AACzC,CAAC;AAED,OAAO,EAAuB,cAAc,EAAE,qBAAqB,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,CAAC"}
@@ -1,15 +1,18 @@
1
1
  import type { ClosureValueType, Worklet } from './bindings/types.js';
2
+ import type { RunOnBackgroundDelayImpl } from './delayRunOnBackground.js';
2
3
  import type { EventDelayImpl } from './delayWorkletEvent.js';
3
4
  import type { JsFunctionLifecycleManager } from './jsFunctionLifecycle.js';
4
5
  import type { RefImpl } from './workletRef.js';
5
6
  declare global {
6
7
  var lynxWorkletImpl: {
7
- _workletMap: Record<string, Function>;
8
+ _workletMap: Record<string, (...args: unknown[]) => unknown>;
8
9
  _jsFunctionLifecycleManager?: JsFunctionLifecycleManager;
9
10
  _eventDelayImpl: EventDelayImpl;
10
11
  _refImpl: RefImpl;
12
+ _runOnBackgroundDelayImpl: RunOnBackgroundDelayImpl;
13
+ _hydrateCtx: (worklet: Worklet, firstScreenWorklet: Worklet) => void;
11
14
  };
12
15
  function runWorklet(ctx: Worklet, params: ClosureValueType[]): unknown;
13
- function registerWorklet(type: string, id: string, worklet: Function): void;
14
- function registerWorkletInternal(type: string, id: string, worklet: Function): void;
16
+ function registerWorklet(type: string, id: string, worklet: (...args: unknown[]) => unknown): void;
17
+ function registerWorkletInternal(type: string, id: string, worklet: (...args: unknown[]) => unknown): void;
15
18
  }
@@ -0,0 +1,11 @@
1
+ import type { Worklet } from './bindings/index.js';
2
+ /**
3
+ * Hydrates a Worklet context with data from a first-screen Worklet context.
4
+ * This process is typically used to run all delayed `runOnBackground` functions
5
+ * and initialize `WorkletRef` values modified before hydration.
6
+ *
7
+ * @param ctx The target Worklet context to be hydrated.
8
+ * @param firstScreenCtx The Worklet context from the first screen rendering,
9
+ * containing the data to hydrate with.
10
+ */
11
+ export declare function hydrateCtx(ctx: Worklet, firstScreenCtx: Worklet): void;
@@ -0,0 +1,86 @@
1
+ // Copyright 2024 The Lynx Authors. All rights reserved.
2
+ // Licensed under the Apache License Version 2.0 that can be found in the
3
+ // LICENSE file in the root directory of this source tree.
4
+ import { Element } from './api/element.js';
5
+ import { profile } from './utils/profile.js';
6
+ /**
7
+ * Hydrates a Worklet context with data from a first-screen Worklet context.
8
+ * This process is typically used to run all delayed `runOnBackground` functions
9
+ * and initialize `WorkletRef` values modified before hydration.
10
+ *
11
+ * @param ctx The target Worklet context to be hydrated.
12
+ * @param firstScreenCtx The Worklet context from the first screen rendering,
13
+ * containing the data to hydrate with.
14
+ */
15
+ export function hydrateCtx(ctx, firstScreenCtx) {
16
+ profile('hydrateCtx', () => {
17
+ hydrateCtxImpl(ctx, firstScreenCtx, ctx._execId);
18
+ });
19
+ }
20
+ function hydrateCtxImpl(ctx, firstScreenCtx, execId) {
21
+ if (!ctx || typeof ctx !== 'object' || !firstScreenCtx || typeof firstScreenCtx !== 'object')
22
+ return;
23
+ const ctxObj = ctx;
24
+ const firstScreenCtxObj = firstScreenCtx;
25
+ if (ctxObj['_wkltId'] && ctxObj['_wkltId'] !== firstScreenCtxObj['_wkltId']) {
26
+ return;
27
+ }
28
+ // eslint-disable-next-line @typescript-eslint/no-for-in-array
29
+ for (const key in ctx) {
30
+ if (key === '_wvid') {
31
+ hydrateMainThreadRef(ctxObj[key], firstScreenCtxObj);
32
+ }
33
+ else if (key === '_jsFn') {
34
+ hydrateDelayRunOnBackgroundTasks(ctxObj[key], firstScreenCtxObj[key], execId);
35
+ }
36
+ else {
37
+ const firstScreenValue = typeof firstScreenCtxObj[key] === 'function'
38
+ ? firstScreenCtxObj[key].ctx
39
+ : firstScreenCtxObj[key];
40
+ hydrateCtxImpl(ctxObj[key], firstScreenValue, execId);
41
+ }
42
+ }
43
+ }
44
+ /**
45
+ * Hydrates a WorkletRef on the main thread.
46
+ * This is used to update the WorkletRef's background initial value based on changes
47
+ * that occurred in the first-screen Worklet context before hydration.
48
+ *
49
+ * @param refId The ID of the WorkletRef to hydrate.
50
+ * @param value The new value for the WorkletRef.
51
+ */
52
+ function hydrateMainThreadRef(refId, value) {
53
+ if ('_initValue' in value) {
54
+ // The ref has not been accessed yet.
55
+ return;
56
+ }
57
+ const ref = lynxWorkletImpl._refImpl._workletRefMap[refId];
58
+ if (ref.current instanceof Element) {
59
+ // Modified by `main-thread:ref`
60
+ return;
61
+ }
62
+ ref.current = value.current;
63
+ }
64
+ /**
65
+ * Hydrates delayed `runOnBackground` tasks.
66
+ * This function ensures that any `runOnBackground` calls that were delayed
67
+ * during the first-screen rendering are correctly associated with their
68
+ * respective JavaScript function handles in the hydrated Worklet context.
69
+ */
70
+ function hydrateDelayRunOnBackgroundTasks(fnObjs, // example: {"_jsFn1":{"_jsFnId":1}}
71
+ firstScreenFnObjs, // example: {"_jsFn1":{"_isFirstScreen":true,"_delayIndices":[0]}}
72
+ execId) {
73
+ for (const fnName in fnObjs) {
74
+ const fnObj = fnObjs[fnName];
75
+ const firstScreenFnObj = firstScreenFnObjs[fnName];
76
+ if (!firstScreenFnObj?._delayIndices) {
77
+ continue;
78
+ }
79
+ for (const index of firstScreenFnObj._delayIndices) {
80
+ const details = lynxWorkletImpl._runOnBackgroundDelayImpl.delayedBackgroundFunctionArray[index];
81
+ fnObj._execId = execId;
82
+ details.jsFnHandle = fnObj;
83
+ }
84
+ }
85
+ }
86
+ //# sourceMappingURL=hydrate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hydrate.js","sourceRoot":"","sources":["../src/hydrate.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAE3C,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAE7C;;;;;;;;GAQG;AACH,MAAM,UAAU,UAAU,CAAC,GAAY,EAAE,cAAuB;IAC9D,OAAO,CAAC,YAAY,EAAE,GAAG,EAAE;QACz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AAI,KAAK,EAAE,CAAC;QAC1B,qCAAqC;QACrC,OAAO;IACT,CAAC;IACD,MAAM,GAAG,GAAG,eAAgB,CAAC,QAAQ,CAAC,cAAc,CAAC,KAAK,CAAE,CAAC;IAC7D,IAAI,GAAG,CAAC,OAAO,YAAY,OAAO,EAAE,CAAC;QACnC,gCAAgC;QAChC,OAAO;IACT,CAAC;IACD,GAAG,CAAC,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC;AAC9B,CAAC;AAED;;;;;GAKG;AACH,SAAS,gCAAgC,CACvC,MAAkC,EAAE,oCAAoC;AACxE,iBAA6C,EAAE,kEAAkE;AACjH,MAAc;IAEd,KAAK,MAAM,MAAM,IAAI,MAAM,EAAE,CAAC;QAC5B,MAAM,KAAK,GAAG,MAAM,CAAC,MAAM,CAAE,CAAC;QAC9B,MAAM,gBAAgB,GAA2B,iBAAiB,CAAC,MAAM,CAAC,CAAC;QAC3E,IAAI,CAAC,gBAAgB,EAAE,aAAa,EAAE,CAAC;YACrC,SAAS;QACX,CAAC;QACD,KAAK,MAAM,KAAK,IAAI,gBAAgB,CAAC,aAAa,EAAE,CAAC;YACnD,MAAM,OAAO,GAAG,eAAgB,CAAC,yBAAyB,CAAC,8BAA8B,CAAC,KAAK,CAAE,CAAC;YAClG,KAAK,CAAC,OAAO,GAAG,MAAM,CAAC;YACvB,OAAO,CAAC,UAAU,GAAG,KAAK,CAAC;QAC7B,CAAC;IACH,CAAC;AACH,CAAC"}
@@ -19,7 +19,7 @@ class JsFunctionLifecycleManager {
19
19
  this.registry = new FinalizationRegistry(this.removeRef.bind(this));
20
20
  }
21
21
  addRef(execId, objToRef) {
22
- this.execIdRefCount.set(execId, (this.execIdRefCount.get(execId) || 0) + 1);
22
+ this.execIdRefCount.set(execId, (this.execIdRefCount.get(execId) ?? 0) + 1);
23
23
  this.registry.register(objToRef, execId);
24
24
  }
25
25
  removeRef(execId) {
@@ -32,7 +32,7 @@ class JsFunctionLifecycleManager {
32
32
  this.execIdSetToFire.add(execId);
33
33
  if (!this.willFire) {
34
34
  this.willFire = true;
35
- Promise.resolve().then(() => {
35
+ void Promise.resolve().then(() => {
36
36
  this.fire();
37
37
  });
38
38
  }
@@ -1 +1 @@
1
- {"version":3,"file":"jsFunctionLifecycle.js","sourceRoot":"","sources":["../src/jsFunctionLifecycle.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAC1D,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAEpD;;;;;GAKG;AACH,MAAM,0BAA0B;IACtB,cAAc,GAAG,IAAI,GAAG,EAAkB,CAAC;IAC3C,eAAe,GAAG,IAAI,GAAG,EAAU,CAAC;IACpC,QAAQ,GAAG,KAAK,CAAC;IACjB,QAAQ,GAAkC,SAAS,CAAC;IAE5D;QACE,IAAI,CAAC,QAAQ,GAAG,IAAI,oBAAoB,CAAS,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IAC9E,CAAC;IAED,MAAM,CAAC,MAAc,EAAE,QAAgB;QACrC,IAAI,CAAC,cAAc,CAAC,GAAG,CACrB,MAAM,EACN,CAAC,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAC3C,CAAC;QACF,IAAI,CAAC,QAAS,CAAC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;IAC5C,CAAC;IAED,SAAS,CAAC,MAAc;QACtB,MAAM,EAAE,GAAG,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,MAAM,CAAE,CAAC;QAC5C,IAAI,EAAE,GAAG,CAAC,EAAE,CAAC;YACX,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,MAAM,EAAE,EAAE,GAAG,CAAC,CAAC,C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EAC/B,CAAC,KAAyB,EAAE,EAAE;QAC5B,4BAA4B,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAC9C,CAAC,CACF,CAAC;AACJ,CAAC;AAED,OAAO,EAAE,kBAAkB,EAAE,CAAC"}
1
+ {"version":3,"file":"listeners.js","sourceRoot":"","sources":["../src/listeners.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAC1D,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAIrD,OAAO,EAAE,4BAA4B,EAAE,MAAM,iBAAiB,CAAC;AAE/D,SAAS,kBAAkB;IACzB,MAAM,SAAS,GAAG,IAAI,CAAC,YAAY,EAAE,CAAC;IACtC,SAAS,CAAC,gBAAgB,CACxB,aAAa,CAAC,aAAa,EAC3B,CAAC,KAAY,EAAE,EAAE;QACf,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,IAAc,CAAsB,CAAC;QACnE,MAAM,WAAW,GAAG,UAAU,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,MAA4B,CAAC,CAAC;QAChF,SAAS,CAAC,aAAa,CAAC;YACtB,IAAI,EAAE,aAAa,CAAC,eAAe;YACnC,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC;gBACnB,SAAS,EAAE,IAAI,CAAC,SAAS;gBACzB,WAAW;aACY,CAAC;SAC3B,CAAC,CAAC;IACL,CAAC,CACF,CAAC;IACF,SAAS,CAAC,gBAAgB,CACxB,aAAa,CAAC,iBAAiB,EAC/B,CAAC,KAAY,EAAE,EAAE;QACf,4BAA4B,CAAE,KAAK,CAAC,IAA8B,CAAC,EAAE,CAAC,CAAC;IACzE,CAAC,CACF,CAAC;AACJ,CAAC;AAED,OAAO,EAAE,kBAAkB,EAAE,CAAC"}
@@ -1 +1 @@
1
- export declare function profile<Ret, Fn extends (...args: any[]) => Ret>(sliceName: string, f: Fn): Ret;
1
+ export declare function profile<Ret, Fn extends (...args: unknown[]) => Ret>(sliceName: string, f: Fn): Ret;
@@ -2,7 +2,7 @@
2
2
  // Licensed under the Apache License Version 2.0 that can be found in the
3
3
  // LICENSE file in the root directory of this source tree.
4
4
  export function isSdkVersionGt(major, minor) {
5
- const lynxSdkVersion = SystemInfo.lynxSdkVersion || '1.0';
5
+ const lynxSdkVersion = SystemInfo.lynxSdkVersion ?? '1.0';
6
6
  const version = lynxSdkVersion.split('.');
7
7
  return (Number(version[0]) > major
8
8
  || (Number(version[0]) == major && Number(version[1]) > minor));
@@ -2,11 +2,14 @@ import { Element } from './api/element.js';
2
2
  import type { WorkletRef, WorkletRefId, WorkletRefImpl } from './bindings/types.js';
3
3
  interface RefImpl {
4
4
  _workletRefMap: Record<WorkletRefId, WorkletRef<unknown>>;
5
- updateWorkletRef(handle: WorkletRefImpl<Element>, element: ElementNode | null): void;
5
+ _firstScreenWorkletRefMap: Record<WorkletRefId, WorkletRef<unknown>>;
6
+ updateWorkletRef(refImpl: WorkletRefImpl<Element | null>, element: ElementNode | null): void;
6
7
  updateWorkletRefInitValueChanges(patch: [number, unknown][]): void;
8
+ clearFirstScreenWorkletRefMap(): void;
7
9
  }
8
10
  declare function initWorkletRef(): RefImpl;
9
- declare const getFromWorkletRefMap: (id: WorkletRefId) => WorkletRef<unknown>;
11
+ declare const createWorkletRef: <T>(id: WorkletRefId, value: T) => WorkletRef<T>;
12
+ declare const getFromWorkletRefMap: <T>(refImpl: WorkletRefImpl<T>) => WorkletRef<T>;
10
13
  declare function removeValueFromWorkletRefMap(id: WorkletRefId): void;
11
14
  declare function updateWorkletRefInitValueChanges(patch: [WorkletRefId, unknown][]): void;
12
- export { type RefImpl, initWorkletRef, getFromWorkletRefMap, removeValueFromWorkletRefMap, updateWorkletRefInitValueChanges, };
15
+ export { type RefImpl, createWorkletRef, initWorkletRef, getFromWorkletRefMap, removeValueFromWorkletRefMap, updateWorkletRefInitValueChanges, };
@@ -7,8 +7,16 @@ let impl;
7
7
  function initWorkletRef() {
8
8
  return (impl = {
9
9
  _workletRefMap: {},
10
+ /**
11
+ * Map of worklet refs that are created during first screen rendering.
12
+ * These refs are created with negative IDs and need to be hydrated
13
+ * when the app starts. The map is cleared after hydration is complete
14
+ * to free up memory.
15
+ */
16
+ _firstScreenWorkletRefMap: {},
10
17
  updateWorkletRef,
11
18
  updateWorkletRefInitValueChanges,
19
+ clearFirstScreenWorkletRefMap,
12
20
  });
13
21
  }
14
22
  const createWorkletRef = (id, value) => {
@@ -17,8 +25,22 @@ const createWorkletRef = (id, value) => {
17
25
  _wvid: id,
18
26
  };
19
27
  };
20
- const getFromWorkletRefMap = (id) => {
21
- const value = impl._workletRefMap[id];
28
+ const getFromWorkletRefMap = (refImpl) => {
29
+ const id = refImpl._wvid;
30
+ let value;
31
+ if (id < 0) {
32
+ // At the first screen rendering, the worklet ref is created with a negative ID.
33
+ // Might be called in two scenarios:
34
+ // 1. In MTS events
35
+ // 2. In `main-thread:ref`
36
+ value = impl._firstScreenWorkletRefMap[id];
37
+ if (!value) {
38
+ value = impl._firstScreenWorkletRefMap[id] = createWorkletRef(id, refImpl._initValue);
39
+ }
40
+ }
41
+ else {
42
+ value = impl._workletRefMap[id];
43
+ }
22
44
  /* v8 ignore next 3 */
23
45
  if (__DEV__ && value === undefined) {
24
46
  throw new Error('Worklet: ref is not initialized: ' + id);
@@ -29,22 +51,27 @@ function removeValueFromWorkletRefMap(id) {
29
51
  delete impl._workletRefMap[id];
30
52
  }
31
53
  /**
32
- * Create an element instance of the given element node, then set worklet value to it.
54
+ * Create an element instance of the given element node, then set the worklet value to it.
33
55
  * This is called in `snapshotContextUpdateWorkletRef`.
34
56
  * @param handle handle of the worklet value.
35
57
  * @param element the element node.
36
58
  */
37
59
  function updateWorkletRef(handle, element) {
38
- getFromWorkletRefMap(handle._wvid).current = element
60
+ getFromWorkletRefMap(handle).current = element
39
61
  ? new Element(element)
40
62
  : null;
41
63
  }
42
64
  function updateWorkletRefInitValueChanges(patch) {
43
65
  profile('updateWorkletRefInitValueChanges', () => {
44
66
  patch.forEach(([id, value]) => {
45
- impl._workletRefMap[id] ??= createWorkletRef(id, value);
67
+ if (!impl._workletRefMap[id]) {
68
+ impl._workletRefMap[id] = createWorkletRef(id, value);
69
+ }
46
70
  });
47
71
  });
48
72
  }
49
- export { initWorkletRef, getFromWorkletRefMap, removeValueFromWorkletRefMap, updateWorkletRefInitValueChanges, };
73
+ function clearFirstScreenWorkletRefMap() {
74
+ impl._firstScreenWorkletRefMap = {};
75
+ }
76
+ export { createWorkletRef, initWorkletRef, getFromWorkletRefMap, removeValueFromWorkletRefMap, updateWorkletRefInitValueChanges, };
50
77
  //# sourceMappingURL=workletRef.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"workletRef.js","sourceRoot":"","sources":["../src/workletRef.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAC1D,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAE3C,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAW7C,IAAI,IAAyB,CAAC;AAE9B,SAAS,cAAc;IACrB,OAAO,CAAC,IAAI,GAAG;QACb,cAAc,EAAE,EAAE;QAClB,gBAAgB;QAChB,gCAAgC;KACjC,CAAC,CAAC;AACL,CAAC;AAED,MAAM,gBAAgB,GAAG,CACvB,EAAgB,EAChB,KAAQ,EACO,EAAE;IACjB,OAAO;QACL,OAAO,EAAE,KAAK;QACd,KAAK,EAAE,EAAE;KACV,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,oBAAoB,GAAG,CAC3B,EAAgB,EACK,EAAE;IACvB,MAAM,KAAK,GAAG,IAAK,CAAC,cAAc,CAAC,EAAE,CAAC,CAAC;IACvC,sBAAsB;IACtB,IAAI,OAAO,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QACnC,MAAM,IAAI,KAAK,CAAC,mCAAmC,GAAG,EAAE,CAAC,CAAC;IAC5D,CAA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AK,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,KAAK,CAAC,EAAE,EAAE;YAC5B,IAAI,CAAC,IAAK,CAAC,cAAc,CAAC,EAAE,CAAC,EAAE,CAAC;gBAC9B,IAAK,CAAC,cAAc,CAAC,EAAE,CAAC,GAAG,gBAAgB,CAAC,EAAE,EAAE,KAAK,CAAC,CAAC;YACzD,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC;AAED,SAAS,6BAA6B;IACpC,IAAK,CAAC,yBAAyB,GAAG,EAAE,CAAC;AACvC,CAAC;AAED,OAAO,EAEL,gBAAgB,EAChB,cAAc,EACd,oBAAoB,EACpB,4BAA4B,EAC5B,gCAAgC,GACjC,CAAC"}
@@ -2,15 +2,19 @@
2
2
  // Licensed under the Apache License Version 2.0 that can be found in the
3
3
  // LICENSE file in the root directory of this source tree.
4
4
  import { Element } from './api/element.js';
5
+ import { initRunOnBackgroundDelay } from './delayRunOnBackground.js';
5
6
  import { delayExecUntilJsReady, initEventDelay } from './delayWorkletEvent.js';
6
- import { isRunOnBackgroundEnabled, JsFunctionLifecycleManager } from './jsFunctionLifecycle.js';
7
+ import { hydrateCtx } from './hydrate.js';
8
+ import { JsFunctionLifecycleManager, isRunOnBackgroundEnabled } from './jsFunctionLifecycle.js';
7
9
  import { profile } from './utils/profile.js';
8
10
  import { getFromWorkletRefMap, initWorkletRef } from './workletRef.js';
9
11
  function initWorklet() {
10
12
  globalThis.lynxWorkletImpl = {
11
13
  _workletMap: {},
12
- _eventDelayImpl: initEventDelay(),
13
14
  _refImpl: initWorkletRef(),
15
+ _runOnBackgroundDelayImpl: initRunOnBackgroundDelay(),
16
+ _hydrateCtx: hydrateCtx,
17
+ _eventDelayImpl: initEventDelay(),
14
18
  };
15
19
  if (isRunOnBackgroundEnabled()) {
16
20
  globalThis.lynxWorkletImpl._jsFunctionLifecycleManager = new JsFunctionLifecycleManager();
@@ -49,11 +53,7 @@ function runWorklet(ctx, params) {
49
53
  function runWorkletImpl(ctx, params) {
50
54
  const worklet = profile('transformWorkletCtx ' + ctx._wkltId, () => transformWorklet(ctx, true));
51
55
  const params_ = profile('transformWorkletParams', () => transformWorklet(params || [], false));
52
- let result;
53
- profile('runWorklet', () => {
54
- result = worklet(...params_);
55
- });
56
- return result;
56
+ return profile('runWorklet', () => worklet(...params_));
57
57
  }
58
58
  function validateWorklet(ctx) {
59
59
  return typeof ctx === 'object' && ctx !== null && ('_wkltId' in ctx || '_lepusWorkletHash' in ctx);
@@ -77,17 +77,17 @@ function transformWorklet(ctx, isWorklet) {
77
77
  }
78
78
  return worklet.main;
79
79
  }
80
- const transformWorkletInner = (obj, depth, ctx) => {
80
+ const transformWorkletInner = (value, depth, ctx) => {
81
81
  const limit = 1000;
82
82
  if (++depth >= limit) {
83
83
  throw new Error('Depth of value exceeds limit of ' + limit + '.');
84
84
  }
85
85
  /* v8 ignore next 3 */
86
- if (typeof obj !== 'object' || obj === null) {
86
+ if (typeof value !== 'object' || value === null) {
87
87
  return;
88
88
  }
89
+ const obj = value;
89
90
  for (const key in obj) {
90
- // @ts-ignore
91
91
  const subObj = obj[key];
92
92
  if (typeof subObj !== 'object' || subObj === null) {
93
93
  continue;
@@ -97,23 +97,21 @@ const transformWorkletInner = (obj, depth, ctx) => {
97
97
  transformWorkletInner(subObj, depth, ctx);
98
98
  }
99
99
  if (isEventTarget) {
100
- // @ts-ignore
101
100
  obj[key] = new Element(subObj['elementRefptr']);
102
101
  continue;
103
102
  }
104
103
  const isWorkletRef = '_wvid' in subObj;
105
104
  if (isWorkletRef) {
106
- // @ts-ignore
107
- obj[key] = getFromWorkletRefMap(subObj._wvid);
105
+ obj[key] = getFromWorkletRefMap(subObj);
108
106
  continue;
109
107
  }
110
108
  const isWorklet = '_wkltId' in subObj;
111
109
  if (isWorklet) {
112
110
  // `subObj` is worklet ctx. Shallow copy it to prevent the transformed worklet from referencing ctx.
113
111
  // This would result in the value of `workletCache` referencing its key.
114
- // @ts-ignore
115
112
  obj[key] = lynxWorkletImpl._workletMap[subObj._wkltId]
116
113
  .bind({ ...subObj });
114
+ obj[key].ctx = subObj;
117
115
  continue;
118
116
  }
119
117
  const isJsFn = '_jsFnId' in subObj;