@lynx-js/react 0.105.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +250 -0
- package/LICENSE +202 -0
- package/README.md +20 -0
- package/components/lib/Page.d.ts +3 -0
- package/components/lib/Page.js +56 -0
- package/components/lib/Page.js.map +1 -0
- package/components/lib/index.d.ts +1 -0
- package/components/lib/index.js +5 -0
- package/components/lib/index.js.map +1 -0
- package/components/src/Page.ts +75 -0
- package/components/src/index.ts +5 -0
- package/package.json +162 -0
- package/refresh/.gitignore +1 -0
- package/refresh/.npmignore +3 -0
- package/refresh/.turbo/turbo-build.log +8 -0
- package/refresh/dist/index.js +311 -0
- package/refresh/package.json +21 -0
- package/refresh/src/index.ts +6 -0
- package/refresh/src/prefresh.d.ts +11 -0
- package/refresh/tsconfig.json +4 -0
- package/refresh/turbo.json +15 -0
- package/runtime/jsx-dev-runtime/index.d.ts +5 -0
- package/runtime/jsx-dev-runtime/index.js +4 -0
- package/runtime/jsx-runtime/index.d.ts +4 -0
- package/runtime/jsx-runtime/index.js +4 -0
- package/runtime/lazy/import.d.ts +1 -0
- package/runtime/lazy/import.js +55 -0
- package/runtime/lazy/internal.js +39 -0
- package/runtime/lazy/jsx-dev-runtime.js +12 -0
- package/runtime/lazy/jsx-runtime.js +12 -0
- package/runtime/lazy/legacy-react-runtime.js +20 -0
- package/runtime/lazy/react-lepus.js +9 -0
- package/runtime/lazy/react.js +46 -0
- package/runtime/lazy/target.js +11 -0
- package/runtime/lepus/index.d.ts +4 -0
- package/runtime/lepus/index.js +43 -0
- package/runtime/lepus/jsx-dev-runtime/index.js +4 -0
- package/runtime/lepus/jsx-runtime/index.js +66 -0
- package/runtime/lib/backgroundSnapshot.d.ts +23 -0
- package/runtime/lib/backgroundSnapshot.js +348 -0
- package/runtime/lib/backgroundSnapshot.js.map +1 -0
- package/runtime/lib/compat/componentIs.d.ts +4 -0
- package/runtime/lib/compat/componentIs.js +20 -0
- package/runtime/lib/compat/componentIs.js.map +1 -0
- package/runtime/lib/compat/initData.d.ts +43 -0
- package/runtime/lib/compat/initData.js +93 -0
- package/runtime/lib/compat/initData.js.map +1 -0
- package/runtime/lib/compat/lynxComponent.d.ts +5 -0
- package/runtime/lib/compat/lynxComponent.js +71 -0
- package/runtime/lib/compat/lynxComponent.js.map +1 -0
- package/runtime/lib/debug/debug.d.ts +2 -0
- package/runtime/lib/debug/debug.js +9 -0
- package/runtime/lib/debug/debug.js.map +1 -0
- package/runtime/lib/debug/printSnapshot.d.ts +3 -0
- package/runtime/lib/debug/printSnapshot.js +21 -0
- package/runtime/lib/debug/printSnapshot.js.map +1 -0
- package/runtime/lib/debug/profile.d.ts +1 -0
- package/runtime/lib/debug/profile.js +51 -0
- package/runtime/lib/debug/profile.js.map +1 -0
- package/runtime/lib/document.d.ts +4 -0
- package/runtime/lib/document.js +49 -0
- package/runtime/lib/document.js.map +1 -0
- package/runtime/lib/gesture/processGesture.d.ts +4 -0
- package/runtime/lib/gesture/processGesture.js +48 -0
- package/runtime/lib/gesture/processGesture.js.map +1 -0
- package/runtime/lib/gesture/processGestureBagkround.d.ts +2 -0
- package/runtime/lib/gesture/processGestureBagkround.js +16 -0
- package/runtime/lib/gesture/processGestureBagkround.js.map +1 -0
- package/runtime/lib/gesture/types.d.ts +34 -0
- package/runtime/lib/gesture/types.js +13 -0
- package/runtime/lib/gesture/types.js.map +1 -0
- package/runtime/lib/hooks/react.d.ts +26 -0
- package/runtime/lib/hooks/react.js +35 -0
- package/runtime/lib/hooks/react.js.map +1 -0
- package/runtime/lib/hooks/useLynxGlobalEventListener.d.ts +29 -0
- package/runtime/lib/hooks/useLynxGlobalEventListener.js +53 -0
- package/runtime/lib/hooks/useLynxGlobalEventListener.js.map +1 -0
- package/runtime/lib/hydrate.d.ts +18 -0
- package/runtime/lib/hydrate.js +271 -0
- package/runtime/lib/hydrate.js.map +1 -0
- package/runtime/lib/index.d.ts +9 -0
- package/runtime/lib/index.js +46 -0
- package/runtime/lib/index.js.map +1 -0
- package/runtime/lib/internal.d.ts +26 -0
- package/runtime/lib/internal.js +41 -0
- package/runtime/lib/internal.js.map +1 -0
- package/runtime/lib/legacy-react-runtime/index.d.ts +7 -0
- package/runtime/lib/legacy-react-runtime/index.js +34 -0
- package/runtime/lib/legacy-react-runtime/index.js.map +1 -0
- package/runtime/lib/lifecycle/delayUnmount.d.ts +8 -0
- package/runtime/lib/lifecycle/delayUnmount.js +68 -0
- package/runtime/lib/lifecycle/delayUnmount.js.map +1 -0
- package/runtime/lib/lifecycle/destroy.d.ts +2 -0
- package/runtime/lib/lifecycle/destroy.js +21 -0
- package/runtime/lib/lifecycle/destroy.js.map +1 -0
- package/runtime/lib/lifecycle/pass.d.ts +3 -0
- package/runtime/lib/lifecycle/pass.js +12 -0
- package/runtime/lib/lifecycle/pass.js.map +1 -0
- package/runtime/lib/lifecycle/patchUpdate.d.ts +23 -0
- package/runtime/lib/lifecycle/patchUpdate.js +179 -0
- package/runtime/lib/lifecycle/patchUpdate.js.map +1 -0
- package/runtime/lib/lifecycle/reload.d.ts +3 -0
- package/runtime/lib/lifecycle/reload.js +63 -0
- package/runtime/lib/lifecycle/reload.js.map +1 -0
- package/runtime/lib/lifecycle/render.d.ts +2 -0
- package/runtime/lib/lifecycle/render.js +44 -0
- package/runtime/lib/lifecycle/render.js.map +1 -0
- package/runtime/lib/lifecycleConstant.d.ts +12 -0
- package/runtime/lib/lifecycleConstant.js +17 -0
- package/runtime/lib/lifecycleConstant.js.map +1 -0
- package/runtime/lib/list.d.ts +40 -0
- package/runtime/lib/list.js +305 -0
- package/runtime/lib/list.js.map +1 -0
- package/runtime/lib/lynx/calledByNative.d.ts +2 -0
- package/runtime/lib/lynx/calledByNative.js +113 -0
- package/runtime/lib/lynx/calledByNative.js.map +1 -0
- package/runtime/lib/lynx/component.d.ts +1 -0
- package/runtime/lib/lynx/component.js +69 -0
- package/runtime/lib/lynx/component.js.map +1 -0
- package/runtime/lib/lynx/dynamic-js.d.ts +2 -0
- package/runtime/lib/lynx/dynamic-js.js +31 -0
- package/runtime/lib/lynx/dynamic-js.js.map +1 -0
- package/runtime/lib/lynx/env.d.ts +1 -0
- package/runtime/lib/lynx/env.js +92 -0
- package/runtime/lib/lynx/env.js.map +1 -0
- package/runtime/lib/lynx/injectLepusMethods.d.ts +2 -0
- package/runtime/lib/lynx/injectLepusMethods.js +50 -0
- package/runtime/lib/lynx/injectLepusMethods.js.map +1 -0
- package/runtime/lib/lynx/lazy-bundle.d.ts +9 -0
- package/runtime/lib/lynx/lazy-bundle.js +119 -0
- package/runtime/lib/lynx/lazy-bundle.js.map +1 -0
- package/runtime/lib/lynx/performance.d.ts +29 -0
- package/runtime/lib/lynx/performance.js +100 -0
- package/runtime/lib/lynx/performance.js.map +1 -0
- package/runtime/lib/lynx/tt.d.ts +4 -0
- package/runtime/lib/lynx/tt.js +193 -0
- package/runtime/lib/lynx/tt.js.map +1 -0
- package/runtime/lib/lynx-api.d.ts +311 -0
- package/runtime/lib/lynx-api.js +116 -0
- package/runtime/lib/lynx-api.js.map +1 -0
- package/runtime/lib/lynx.d.ts +2 -0
- package/runtime/lib/lynx.js +91 -0
- package/runtime/lib/lynx.js.map +1 -0
- package/runtime/lib/opcodes.d.ts +2 -0
- package/runtime/lib/opcodes.js +59 -0
- package/runtime/lib/opcodes.js.map +1 -0
- package/runtime/lib/renderToOpcodes/constants.d.ts +17 -0
- package/runtime/lib/renderToOpcodes/constants.js +23 -0
- package/runtime/lib/renderToOpcodes/constants.js.map +1 -0
- package/runtime/lib/renderToOpcodes/index.d.ts +13 -0
- package/runtime/lib/renderToOpcodes/index.js +227 -0
- package/runtime/lib/renderToOpcodes/index.js.map +1 -0
- package/runtime/lib/root.d.ts +7 -0
- package/runtime/lib/root.js +17 -0
- package/runtime/lib/root.js.map +1 -0
- package/runtime/lib/snapshot/event.d.ts +3 -0
- package/runtime/lib/snapshot/event.js +24 -0
- package/runtime/lib/snapshot/event.js.map +1 -0
- package/runtime/lib/snapshot/gesture.d.ts +2 -0
- package/runtime/lib/snapshot/gesture.js +18 -0
- package/runtime/lib/snapshot/gesture.js.map +1 -0
- package/runtime/lib/snapshot/platformInfo.d.ts +4 -0
- package/runtime/lib/snapshot/platformInfo.js +35 -0
- package/runtime/lib/snapshot/platformInfo.js.map +1 -0
- package/runtime/lib/snapshot/ref.d.ts +10 -0
- package/runtime/lib/snapshot/ref.js +119 -0
- package/runtime/lib/snapshot/ref.js.map +1 -0
- package/runtime/lib/snapshot/spread.d.ts +5 -0
- package/runtime/lib/snapshot/spread.js +289 -0
- package/runtime/lib/snapshot/spread.js.map +1 -0
- package/runtime/lib/snapshot/workletEvent.d.ts +3 -0
- package/runtime/lib/snapshot/workletEvent.js +22 -0
- package/runtime/lib/snapshot/workletEvent.js.map +1 -0
- package/runtime/lib/snapshot/workletRef.d.ts +5 -0
- package/runtime/lib/snapshot/workletRef.js +52 -0
- package/runtime/lib/snapshot/workletRef.js.map +1 -0
- package/runtime/lib/snapshot.d.ts +81 -0
- package/runtime/lib/snapshot.js +477 -0
- package/runtime/lib/snapshot.js.map +1 -0
- package/runtime/lib/snapshotPatch.d.ts +14 -0
- package/runtime/lib/snapshotPatch.js +31 -0
- package/runtime/lib/snapshotPatch.js.map +1 -0
- package/runtime/lib/snapshotPatchApply.d.ts +2 -0
- package/runtime/lib/snapshotPatchApply.js +110 -0
- package/runtime/lib/snapshotPatchApply.js.map +1 -0
- package/runtime/lib/utils.d.ts +4 -0
- package/runtime/lib/utils.js +32 -0
- package/runtime/lib/utils.js.map +1 -0
- package/runtime/lib/worklet/ctx.d.ts +1 -0
- package/runtime/lib/worklet/ctx.js +17 -0
- package/runtime/lib/worklet/ctx.js.map +1 -0
- package/runtime/lib/worklet/execMap.d.ts +1 -0
- package/runtime/lib/worklet/execMap.js +42 -0
- package/runtime/lib/worklet/execMap.js.map +1 -0
- package/runtime/lib/worklet/functionality.d.ts +1 -0
- package/runtime/lib/worklet/functionality.js +11 -0
- package/runtime/lib/worklet/functionality.js.map +1 -0
- package/runtime/lib/worklet/hmr.d.ts +1 -0
- package/runtime/lib/worklet/hmr.js +21 -0
- package/runtime/lib/worklet/hmr.js.map +1 -0
- package/runtime/lib/worklet/indexMap.d.ts +8 -0
- package/runtime/lib/worklet/indexMap.js +17 -0
- package/runtime/lib/worklet/indexMap.js.map +1 -0
- package/runtime/lib/worklet/jsImpl.d.ts +11 -0
- package/runtime/lib/worklet/jsImpl.js +68 -0
- package/runtime/lib/worklet/jsImpl.js.map +1 -0
- package/runtime/lib/worklet/runWorklet.d.ts +14 -0
- package/runtime/lib/worklet/runWorklet.js +82 -0
- package/runtime/lib/worklet/runWorklet.js.map +1 -0
- package/runtime/lib/worklet/workletRef.d.ts +131 -0
- package/runtime/lib/worklet/workletRef.js +96 -0
- package/runtime/lib/worklet/workletRef.js.map +1 -0
- package/runtime/lib/worklet/workletRefPool.d.ts +2 -0
- package/runtime/lib/worklet/workletRefPool.js +22 -0
- package/runtime/lib/worklet/workletRefPool.js.map +1 -0
- package/runtime/src/backgroundSnapshot.ts +452 -0
- package/runtime/src/compat/componentIs.ts +30 -0
- package/runtime/src/compat/initData.ts +140 -0
- package/runtime/src/compat/lynxComponent.ts +80 -0
- package/runtime/src/debug/debug.ts +9 -0
- package/runtime/src/debug/printSnapshot.ts +28 -0
- package/runtime/src/debug/profile.ts +54 -0
- package/runtime/src/document.ts +53 -0
- package/runtime/src/gesture/processGesture.ts +77 -0
- package/runtime/src/gesture/processGestureBagkround.ts +15 -0
- package/runtime/src/gesture/types.ts +39 -0
- package/runtime/src/hooks/react.ts +62 -0
- package/runtime/src/hooks/useLynxGlobalEventListener.ts +59 -0
- package/runtime/src/hydrate.ts +364 -0
- package/runtime/src/index.ts +89 -0
- package/runtime/src/internal.ts +60 -0
- package/runtime/src/legacy-react-runtime/index.ts +40 -0
- package/runtime/src/lifecycle/delayUnmount.ts +77 -0
- package/runtime/src/lifecycle/destroy.ts +26 -0
- package/runtime/src/lifecycle/pass.ts +14 -0
- package/runtime/src/lifecycle/patchUpdate.ts +240 -0
- package/runtime/src/lifecycle/reload.ts +79 -0
- package/runtime/src/lifecycle/render.ts +46 -0
- package/runtime/src/lifecycleConstant.ts +16 -0
- package/runtime/src/list.ts +375 -0
- package/runtime/src/lynx/calledByNative.ts +132 -0
- package/runtime/src/lynx/component.ts +116 -0
- package/runtime/src/lynx/dynamic-js.ts +33 -0
- package/runtime/src/lynx/env.ts +110 -0
- package/runtime/src/lynx/injectLepusMethods.ts +53 -0
- package/runtime/src/lynx/lazy-bundle.ts +126 -0
- package/runtime/src/lynx/performance.ts +117 -0
- package/runtime/src/lynx/tt.ts +212 -0
- package/runtime/src/lynx-api.ts +374 -0
- package/runtime/src/lynx.ts +105 -0
- package/runtime/src/opcodes.ts +64 -0
- package/runtime/src/renderToOpcodes/constants.ts +24 -0
- package/runtime/src/renderToOpcodes/index.ts +301 -0
- package/runtime/src/root.ts +19 -0
- package/runtime/src/snapshot/event.ts +33 -0
- package/runtime/src/snapshot/gesture.ts +25 -0
- package/runtime/src/snapshot/platformInfo.ts +48 -0
- package/runtime/src/snapshot/ref.ts +151 -0
- package/runtime/src/snapshot/spread.ts +287 -0
- package/runtime/src/snapshot/workletEvent.ts +33 -0
- package/runtime/src/snapshot/workletRef.ts +63 -0
- package/runtime/src/snapshot.ts +576 -0
- package/runtime/src/snapshotPatch.ts +56 -0
- package/runtime/src/snapshotPatchApply.ts +117 -0
- package/runtime/src/utils.ts +35 -0
- package/runtime/src/worklet/ctx.ts +22 -0
- package/runtime/src/worklet/execMap.ts +50 -0
- package/runtime/src/worklet/functionality.ts +12 -0
- package/runtime/src/worklet/hmr.ts +26 -0
- package/runtime/src/worklet/indexMap.ts +20 -0
- package/runtime/src/worklet/jsImpl.ts +86 -0
- package/runtime/src/worklet/runWorklet.ts +88 -0
- package/runtime/src/worklet/workletRef.ts +229 -0
- package/runtime/src/worklet/workletRefPool.ts +25 -0
- package/transform/cjs/main.cjs +6 -0
- package/transform/cjs/main.d.cts +3 -0
- package/transform/cjs/package.json +3 -0
- package/transform/dist/wasm.cjs +8478 -0
- package/transform/index.d.ts +187 -0
- package/transform/main.js +15 -0
- package/types/react.d.ts +147 -0
- package/types/react.docs.d.ts +74 -0
- package/worklet-runtime/dist/dev.js +414 -0
- package/worklet-runtime/dist/dev.js.map +8 -0
- package/worklet-runtime/dist/main.js +414 -0
- package/worklet-runtime/dist/main.js.map +8 -0
- package/worklet-runtime/lib/api/element.d.ts +14 -0
- package/worklet-runtime/lib/api/element.js +71 -0
- package/worklet-runtime/lib/api/element.js.map +1 -0
- package/worklet-runtime/lib/api/lepusQuerySelector.d.ts +3 -0
- package/worklet-runtime/lib/api/lepusQuerySelector.js +23 -0
- package/worklet-runtime/lib/api/lepusQuerySelector.js.map +1 -0
- package/worklet-runtime/lib/api/lynxApi.d.ts +2 -0
- package/worklet-runtime/lib/api/lynxApi.js +35 -0
- package/worklet-runtime/lib/api/lynxApi.js.map +1 -0
- package/worklet-runtime/lib/bindings/bindings.d.ts +14 -0
- package/worklet-runtime/lib/bindings/bindings.js +61 -0
- package/worklet-runtime/lib/bindings/bindings.js.map +1 -0
- package/worklet-runtime/lib/bindings/events.d.ts +7 -0
- package/worklet-runtime/lib/bindings/events.js +9 -0
- package/worklet-runtime/lib/bindings/events.js.map +1 -0
- package/worklet-runtime/lib/bindings/index.d.ts +4 -0
- package/worklet-runtime/lib/bindings/index.js +7 -0
- package/worklet-runtime/lib/bindings/index.js.map +1 -0
- package/worklet-runtime/lib/bindings/loadRuntime.d.ts +8 -0
- package/worklet-runtime/lib/bindings/loadRuntime.js +25 -0
- package/worklet-runtime/lib/bindings/loadRuntime.js.map +1 -0
- package/worklet-runtime/lib/bindings/types.d.ts +35 -0
- package/worklet-runtime/lib/bindings/types.js +2 -0
- package/worklet-runtime/lib/bindings/types.js.map +1 -0
- package/worklet-runtime/lib/delayWorkletEvent.d.ts +11 -0
- package/worklet-runtime/lib/delayWorkletEvent.js +49 -0
- package/worklet-runtime/lib/delayWorkletEvent.js.map +1 -0
- package/worklet-runtime/lib/global.d.ts +15 -0
- package/worklet-runtime/lib/global.js +2 -0
- package/worklet-runtime/lib/global.js.map +1 -0
- package/worklet-runtime/lib/index.d.ts +1 -0
- package/worklet-runtime/lib/index.js +12 -0
- package/worklet-runtime/lib/index.js.map +1 -0
- package/worklet-runtime/lib/jsFunctionLifecycle.d.ts +18 -0
- package/worklet-runtime/lib/jsFunctionLifecycle.js +55 -0
- package/worklet-runtime/lib/jsFunctionLifecycle.js.map +1 -0
- package/worklet-runtime/lib/listeners.d.ts +2 -0
- package/worklet-runtime/lib/listeners.js +17 -0
- package/worklet-runtime/lib/listeners.js.map +1 -0
- package/worklet-runtime/lib/utils/profile.d.ts +1 -0
- package/worklet-runtime/lib/utils/profile.js +20 -0
- package/worklet-runtime/lib/utils/profile.js.map +1 -0
- package/worklet-runtime/lib/utils/version.d.ts +1 -0
- package/worklet-runtime/lib/utils/version.js +10 -0
- package/worklet-runtime/lib/utils/version.js.map +1 -0
- package/worklet-runtime/lib/workletRef.d.ts +12 -0
- package/worklet-runtime/lib/workletRef.js +50 -0
- package/worklet-runtime/lib/workletRef.js.map +1 -0
- package/worklet-runtime/lib/workletRuntime.d.ts +2 -0
- package/worklet-runtime/lib/workletRuntime.js +128 -0
- package/worklet-runtime/lib/workletRuntime.js.map +1 -0
|
@@ -0,0 +1,61 @@
|
|
|
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
|
+
/**
|
|
5
|
+
* Register a worklet function to the `jsFunctionLifecycleManager`.
|
|
6
|
+
* This function mast be called when a worklet context is updated.
|
|
7
|
+
*
|
|
8
|
+
* @param worklet - The worklet to be updated
|
|
9
|
+
* @param element - The element associated with the worklet
|
|
10
|
+
* @internal
|
|
11
|
+
*/
|
|
12
|
+
function onWorkletCtxUpdate(worklet, element) {
|
|
13
|
+
globalThis.lynxWorkletImpl?._jsFunctionLifecycleManager?.addRef(worklet._execId, worklet);
|
|
14
|
+
globalThis.lynxWorkletImpl?._eventDelayImpl.runDelayedWorklet(worklet, element);
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Executes the worklet ctx.
|
|
18
|
+
* @param worklet - The Worklet ctx to run.
|
|
19
|
+
* @param params - An array as parameters of the worklet run.
|
|
20
|
+
*/
|
|
21
|
+
function runWorkletCtx(worklet, params) {
|
|
22
|
+
return globalThis.runWorklet?.(worklet, params);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Save an element to a `WorkletRef`.
|
|
26
|
+
*
|
|
27
|
+
* @param workletRef - The `WorkletRef` to be updated.
|
|
28
|
+
* @param element - The element.
|
|
29
|
+
* @internal
|
|
30
|
+
*/
|
|
31
|
+
function updateWorkletRef(workletRef, element) {
|
|
32
|
+
globalThis.lynxWorkletImpl?._refImpl.updateWorkletRef(workletRef, element);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Update the initial value of the `WorkletRef`.
|
|
36
|
+
*
|
|
37
|
+
* @param patch - An array containing the index and new value of the worklet value.
|
|
38
|
+
*/
|
|
39
|
+
function updateWorkletRefInitValueChanges(patch) {
|
|
40
|
+
if (patch) {
|
|
41
|
+
globalThis.lynxWorkletImpl?._refImpl.updateWorkletRefInitValueChanges(patch);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Clear all delayed worklets to run.
|
|
46
|
+
*
|
|
47
|
+
* @internal
|
|
48
|
+
*/
|
|
49
|
+
function clearDelayedWorklets() {
|
|
50
|
+
globalThis.lynxWorkletImpl?._eventDelayImpl.clearDelayedWorklets();
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Register a worklet.
|
|
54
|
+
*
|
|
55
|
+
* @internal
|
|
56
|
+
*/
|
|
57
|
+
function registerWorklet(type, id, worklet) {
|
|
58
|
+
globalThis.registerWorklet(type, id, worklet);
|
|
59
|
+
}
|
|
60
|
+
export { onWorkletCtxUpdate, runWorkletCtx, updateWorkletRef, updateWorkletRefInitValueChanges, clearDelayedWorklets, registerWorklet, };
|
|
61
|
+
//# sourceMappingURL=bindings.js.map
|
|
@@ -0,0 +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,eAAe,EAAE,eAAe,CAAC,oBAAoB,EAAE,CAAC;AACrE,CAAC;AAED;;;;GAIG;AACH,SAAS,eAAe,CAAC,IAAY,EAAE,EAAU,EAAE,OAAiB;IAClE,UAAU,CAAC,eAAe,CAAC,IAAI,EAAE,EAAE,EAAE,OAAO,CAAC,CAAC;AAChD,CAAC;AAED,OAAO,EACL,kBAAkB,EAClB,aAAa,EACb,gBAAgB,EAChB,gCAAgC,EAChC,oBAAoB,EACpB,eAAe,GAChB,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
declare const enum WorkletEvents {
|
|
2
|
+
runWorkletCtx = "Lynx.Worklet.runWorkletCtx",
|
|
3
|
+
runOnBackground = "Lynx.Worklet.runOnBackground",
|
|
4
|
+
releaseBackgroundWorkletCtx = "Lynx.Worklet.releaseBackgroundWorkletCtx",
|
|
5
|
+
releaseWorkletRef = "Lynx.Worklet.releaseWorkletRef"
|
|
6
|
+
}
|
|
7
|
+
export { WorkletEvents };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
var WorkletEvents;
|
|
2
|
+
(function (WorkletEvents) {
|
|
3
|
+
WorkletEvents["runWorkletCtx"] = "Lynx.Worklet.runWorkletCtx";
|
|
4
|
+
WorkletEvents["runOnBackground"] = "Lynx.Worklet.runOnBackground";
|
|
5
|
+
WorkletEvents["releaseBackgroundWorkletCtx"] = "Lynx.Worklet.releaseBackgroundWorkletCtx";
|
|
6
|
+
WorkletEvents["releaseWorkletRef"] = "Lynx.Worklet.releaseWorkletRef";
|
|
7
|
+
})(WorkletEvents || (WorkletEvents = {}));
|
|
8
|
+
export { WorkletEvents };
|
|
9
|
+
//# sourceMappingURL=events.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"events.js","sourceRoot":"","sources":["../../src/bindings/events.ts"],"names":[],"mappings":"AAAA,IAAW,aAKV;AALD,WAAW,aAAa;IACtB,6DAA4C,CAAA;IAC5C,iEAAgD,CAAA;IAChD,yFAAwE,CAAA;IACxE,qEAAoD,CAAA;AACtD,CAAC,EALU,aAAa,KAAb,aAAa,QAKvB;AAED,OAAO,EAAE,aAAa,EAAE,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { loadWorkletRuntime } from './loadRuntime.js';
|
|
2
|
+
export { onWorkletCtxUpdate, runWorkletCtx, updateWorkletRef, updateWorkletRefInitValueChanges, clearDelayedWorklets, } from './bindings.js';
|
|
3
|
+
export type * from './types.js';
|
|
4
|
+
export { WorkletEvents } from './events.js';
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// Copyright 2024 The Lynx Authors. All rights reserved.
|
|
2
|
+
// Licensed under the Apache License Version 2.0 that can be found in the
|
|
3
|
+
// LICENSE file in the root directory of this source tree.
|
|
4
|
+
export { loadWorkletRuntime } from './loadRuntime.js';
|
|
5
|
+
export { onWorkletCtxUpdate, runWorkletCtx, updateWorkletRef, updateWorkletRefInitValueChanges, clearDelayedWorklets, } from './bindings.js';
|
|
6
|
+
export { WorkletEvents } from './events.js';
|
|
7
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +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,EAAE,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import '../global.js';
|
|
2
|
+
/**
|
|
3
|
+
* Loads and initializes the Lepus chunk in the main thread.
|
|
4
|
+
* @param __schema - The dynamic component entry for loading the Lepus chunk.
|
|
5
|
+
* @returns A boolean indicating whether the Lepus chunk was loaded and initialized successfully.
|
|
6
|
+
*/
|
|
7
|
+
declare function loadWorkletRuntime(__schema?: string): boolean;
|
|
8
|
+
export { loadWorkletRuntime };
|
|
@@ -0,0 +1,25 @@
|
|
|
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
|
+
/// <reference path="../types/elementApi.d.ts" />
|
|
5
|
+
import '../global.js';
|
|
6
|
+
/**
|
|
7
|
+
* Loads and initializes the Lepus chunk in the main thread.
|
|
8
|
+
* @param __schema - The dynamic component entry for loading the Lepus chunk.
|
|
9
|
+
* @returns A boolean indicating whether the Lepus chunk was loaded and initialized successfully.
|
|
10
|
+
*/
|
|
11
|
+
function loadWorkletRuntime(__schema) {
|
|
12
|
+
if (typeof __LoadLepusChunk === 'undefined') {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
if (globalThis.lynxWorkletImpl) {
|
|
16
|
+
return true;
|
|
17
|
+
}
|
|
18
|
+
return __LoadLepusChunk('worklet-runtime', {
|
|
19
|
+
// @ts-ignore
|
|
20
|
+
dynamicComponentEntry: __schema,
|
|
21
|
+
chunkType: 0,
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
export { loadWorkletRuntime };
|
|
25
|
+
//# sourceMappingURL=loadRuntime.js.map
|
|
@@ -0,0 +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"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export type WorkletRefId = number;
|
|
2
|
+
export interface WorkletRefImpl<T> {
|
|
3
|
+
_wvid: WorkletRefId;
|
|
4
|
+
_initValue: T;
|
|
5
|
+
_type: string;
|
|
6
|
+
_lifecycleObserver?: unknown;
|
|
7
|
+
current?: T;
|
|
8
|
+
}
|
|
9
|
+
export interface WorkletRef<T> {
|
|
10
|
+
_wvid: WorkletRefId;
|
|
11
|
+
current: T;
|
|
12
|
+
[key: string]: unknown;
|
|
13
|
+
}
|
|
14
|
+
interface ClosureValueType_ extends Record<string, ClosureValueType> {
|
|
15
|
+
}
|
|
16
|
+
export type ClosureValueType = null | undefined | string | boolean | number | Worklet | WorkletRef<unknown> | ClosureValueType_ | ClosureValueType[];
|
|
17
|
+
export interface Worklet {
|
|
18
|
+
_wkltId: string;
|
|
19
|
+
_c?: Record<string, ClosureValueType>;
|
|
20
|
+
_lepusWorkletHash?: string;
|
|
21
|
+
_execId?: number;
|
|
22
|
+
_jsFn?: Record<string, string>;
|
|
23
|
+
_unmount?: any;
|
|
24
|
+
[key: string]: ClosureValueType;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* @public
|
|
28
|
+
*/
|
|
29
|
+
export interface JsFnHandle {
|
|
30
|
+
_jsFnId: number;
|
|
31
|
+
_fn?: Function;
|
|
32
|
+
_execId?: number;
|
|
33
|
+
_error?: string;
|
|
34
|
+
}
|
|
35
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/bindings/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ClosureValueType, Worklet } from './bindings/types.js';
|
|
2
|
+
interface EventDelayImpl {
|
|
3
|
+
_delayedWorkletParamsMap: Map<string, ClosureValueType[][]>;
|
|
4
|
+
runDelayedWorklet(worklet: Worklet, element: ElementNode): void;
|
|
5
|
+
clearDelayedWorklets(): void;
|
|
6
|
+
}
|
|
7
|
+
declare function initEventDelay(): EventDelayImpl;
|
|
8
|
+
declare function delayExecUntilJsReady(hash: string, params: ClosureValueType[]): void;
|
|
9
|
+
declare function runDelayedWorklet(worklet: Worklet, element: ElementNode): void;
|
|
10
|
+
declare function clearDelayedWorklets(): void;
|
|
11
|
+
export { type EventDelayImpl, initEventDelay, delayExecUntilJsReady, runDelayedWorklet, clearDelayedWorklets };
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { profile } from './utils/profile.js';
|
|
2
|
+
let impl;
|
|
3
|
+
function initEventDelay() {
|
|
4
|
+
return (impl = {
|
|
5
|
+
_delayedWorkletParamsMap: new Map(),
|
|
6
|
+
runDelayedWorklet,
|
|
7
|
+
clearDelayedWorklets,
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
function delayExecUntilJsReady(hash, params) {
|
|
11
|
+
profile('delayExecUntilJsReady: ' + hash, () => {
|
|
12
|
+
const map = impl._delayedWorkletParamsMap;
|
|
13
|
+
const paramVec = map.get(hash);
|
|
14
|
+
if (paramVec) {
|
|
15
|
+
paramVec.push(params);
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
map.set(hash, [params]);
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
function runDelayedWorklet(worklet, element) {
|
|
23
|
+
profile('commitDelayedWorklet', () => {
|
|
24
|
+
const paramsVec = impl._delayedWorkletParamsMap.get(worklet._wkltId);
|
|
25
|
+
if (paramsVec === undefined) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
const leftParamsVec = [];
|
|
29
|
+
paramsVec.forEach((params) => {
|
|
30
|
+
// @ts-ignore
|
|
31
|
+
if (params[0]?.currentTarget?.elementRefptr === element) {
|
|
32
|
+
setTimeout(() => {
|
|
33
|
+
profile('runDelayedWorklet', () => {
|
|
34
|
+
runWorklet(worklet, params);
|
|
35
|
+
});
|
|
36
|
+
}, 0);
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
leftParamsVec.push(params);
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
impl._delayedWorkletParamsMap.set(worklet._wkltId, leftParamsVec);
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
function clearDelayedWorklets() {
|
|
46
|
+
impl._delayedWorkletParamsMap.clear();
|
|
47
|
+
}
|
|
48
|
+
export { initEventDelay, delayExecUntilJsReady, runDelayedWorklet, clearDelayedWorklets };
|
|
49
|
+
//# sourceMappingURL=delayWorkletEvent.js.map
|
|
@@ -0,0 +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,CAAC,OAAO,CAChB,CAAC;QACF,IAAI,SAAS,KAAK,SAAS,EAAE,CAAC;YAC5B,OAAO;QACT,CAAC;QACD,MAAM,aAAa,GAAyB,EAAE,CAAC;QAC/C,SAAS,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,EAAE;YAC3B,aAAa;YACb,IAAI,MAAM,CAAC,CAAC,CAAC,EAAE,aAAa,EAAE,aAAa,KAAK,OAAO,EAAE,CAAC;gBACxD,UAAU,CAAC,GAAG,EAAE;oBACd,OAAO,CAAC,mBAAmB,EAAE,GAAG,EAAE;wBAChC,UAAU,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;oBAC9B,CAAC,CAAC,CAAC;gBACL,CAAC,EAAE,CAAC,CAAC,CAAC;YACR,CAAC;iBAAM,CAAC;gBACN,aAAa,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;YAC7B,CAAC;QACH,CAAC,CAAC,CAAC;QACH,IAAK,CAAC,wBAAwB,CAAC,GAAG,CAChC,OAAO,CAAC,OAAO,EACf,aAAa,CACd,CAAC;IACJ,CAAC,CAAC,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"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ClosureValueType, Worklet } from './bindings/types.js';
|
|
2
|
+
import type { EventDelayImpl } from './delayWorkletEvent.js';
|
|
3
|
+
import type { JsFunctionLifecycleManager } from './jsFunctionLifecycle.js';
|
|
4
|
+
import type { RefImpl } from './workletRef.js';
|
|
5
|
+
declare global {
|
|
6
|
+
var lynxWorkletImpl: {
|
|
7
|
+
_workletMap: Record<string, Function>;
|
|
8
|
+
_jsFunctionLifecycleManager?: JsFunctionLifecycleManager;
|
|
9
|
+
_eventDelayImpl: EventDelayImpl;
|
|
10
|
+
_refImpl: RefImpl;
|
|
11
|
+
};
|
|
12
|
+
function runWorklet(ctx: Worklet, params: ClosureValueType[]): void;
|
|
13
|
+
function registerWorklet(type: string, id: string, worklet: Function): void;
|
|
14
|
+
function registerWorkletInternal(type: string, id: string, worklet: Function): void;
|
|
15
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"global.js","sourceRoot":"","sources":["../src/global.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
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 { initApiEnv } from './api/lynxApi.js';
|
|
5
|
+
import { initEventListeners } from './listeners.js';
|
|
6
|
+
import { initWorklet } from './workletRuntime.js';
|
|
7
|
+
if (globalThis.lynxWorkletImpl === undefined) {
|
|
8
|
+
initWorklet();
|
|
9
|
+
initApiEnv();
|
|
10
|
+
initEventListeners();
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAC1D,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AACpD,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAElD,IAAI,UAAU,CAAC,eAAe,KAAK,SAAS,EAAE,CAAC;IAC7C,WAAW,EAAE,CAAC;IACd,UAAU,EAAE,CAAC;IACb,kBAAkB,EAAE,CAAC;AACvB,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `JsFunctionLifecycleManager` monitors references to JS function handles to be called by `runOnBackground()`.
|
|
3
|
+
* In JS context, functions to be called by `runOnBackground()` is referenced by `JsFnHandle`s and finally by `execId`.
|
|
4
|
+
* When all `JsFnHandle`s in lepus are released, an event will be sent to JS context to de-ref the `execId`,
|
|
5
|
+
* resulting a de-ref to the js function in JS context.
|
|
6
|
+
*/
|
|
7
|
+
declare class JsFunctionLifecycleManager {
|
|
8
|
+
private execIdRefCount;
|
|
9
|
+
private execIdSetToFire;
|
|
10
|
+
private willFire;
|
|
11
|
+
private registry?;
|
|
12
|
+
constructor();
|
|
13
|
+
addRef(execId: number, objToRef: object): void;
|
|
14
|
+
removeRef(execId: number): void;
|
|
15
|
+
fire(): void;
|
|
16
|
+
}
|
|
17
|
+
declare function enableRunOnBackground(): boolean;
|
|
18
|
+
export { JsFunctionLifecycleManager, enableRunOnBackground };
|
|
@@ -0,0 +1,55 @@
|
|
|
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 { WorkletEvents } from './bindings/events.js';
|
|
5
|
+
import { profile } from './utils/profile.js';
|
|
6
|
+
import { isSdkVersionGt } from './utils/version.js';
|
|
7
|
+
/**
|
|
8
|
+
* `JsFunctionLifecycleManager` monitors references to JS function handles to be called by `runOnBackground()`.
|
|
9
|
+
* In JS context, functions to be called by `runOnBackground()` is referenced by `JsFnHandle`s and finally by `execId`.
|
|
10
|
+
* When all `JsFnHandle`s in lepus are released, an event will be sent to JS context to de-ref the `execId`,
|
|
11
|
+
* resulting a de-ref to the js function in JS context.
|
|
12
|
+
*/
|
|
13
|
+
class JsFunctionLifecycleManager {
|
|
14
|
+
execIdRefCount = new Map();
|
|
15
|
+
execIdSetToFire = new Set();
|
|
16
|
+
willFire = false;
|
|
17
|
+
registry = undefined;
|
|
18
|
+
constructor() {
|
|
19
|
+
this.registry = new FinalizationRegistry(this.removeRef.bind(this));
|
|
20
|
+
}
|
|
21
|
+
addRef(execId, objToRef) {
|
|
22
|
+
this.execIdRefCount.set(execId, (this.execIdRefCount.get(execId) || 0) + 1);
|
|
23
|
+
this.registry.register(objToRef, execId);
|
|
24
|
+
}
|
|
25
|
+
removeRef(execId) {
|
|
26
|
+
const rc = this.execIdRefCount.get(execId);
|
|
27
|
+
if (rc > 1) {
|
|
28
|
+
this.execIdRefCount.set(execId, rc - 1);
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
this.execIdRefCount.delete(execId);
|
|
32
|
+
this.execIdSetToFire.add(execId);
|
|
33
|
+
if (!this.willFire) {
|
|
34
|
+
this.willFire = true;
|
|
35
|
+
Promise.resolve().then(() => {
|
|
36
|
+
this.fire();
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
fire() {
|
|
41
|
+
profile('JsFunctionLifecycleManager.fire', () => {
|
|
42
|
+
lynx.getJSContext().dispatchEvent({
|
|
43
|
+
type: WorkletEvents.releaseBackgroundWorkletCtx,
|
|
44
|
+
data: Array.from(this.execIdSetToFire),
|
|
45
|
+
});
|
|
46
|
+
this.execIdSetToFire.clear();
|
|
47
|
+
this.willFire = false;
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
function enableRunOnBackground() {
|
|
52
|
+
return isSdkVersionGt(2, 15);
|
|
53
|
+
}
|
|
54
|
+
export { JsFunctionLifecycleManager, enableRunOnBackground };
|
|
55
|
+
//# sourceMappingURL=jsFunctionLifecycle.js.map
|
|
@@ -0,0 +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,CAAC;YACxC,OAAO;QACT,CAAC;QACD,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QACnC,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QACjC,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC;YACnB,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;YACrB,OAAO,CAAC,OAAO,EAAE,CAAC,IAAI,CAAC,GAAG,EAAE;gBAC1B,IAAI,CAAC,IAAI,EAAE,CAAC;YACd,CAAC,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IAED,IAAI;QACF,OAAO,CAAC,iCAAiC,EAAE,GAAG,EAAE;YAC9C,IAAI,CAAC,YAAY,EAAE,CAAC,aAAa,CAAC;gBAChC,IAAI,EAAE,aAAa,CAAC,2BAA2B;gBAC/C,IAAI,EAAE,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,eAAe,CAAC;aACvC,CAAC,CAAC;YACH,IAAI,CAAC,eAAe,CAAC,KAAK,EAAE,CAAC;YAC7B,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAC;QACxB,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AAED,SAAS,qBAAqB;IAC5B,OAAO,cAAc,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;AAC/B,CAAC;AAED,OAAO,EAAE,0BAA0B,EAAE,qBAAqB,EAAE,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
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 { removeValueFromWorkletRefMap } from './workletRef.js';
|
|
5
|
+
import { WorkletEvents } from './bindings/events.js';
|
|
6
|
+
function initEventListeners() {
|
|
7
|
+
const jsContext = lynx.getJSContext();
|
|
8
|
+
jsContext.addEventListener(WorkletEvents.runWorkletCtx, (event) => {
|
|
9
|
+
const data = JSON.parse(event.data);
|
|
10
|
+
runWorklet(data.worklet, data.params);
|
|
11
|
+
});
|
|
12
|
+
jsContext.addEventListener(WorkletEvents.releaseWorkletRef, (event) => {
|
|
13
|
+
removeValueFromWorkletRefMap(event.data.id);
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
export { initEventListeners };
|
|
17
|
+
//# sourceMappingURL=listeners.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"listeners.js","sourceRoot":"","sources":["../src/listeners.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAC1D,OAAO,EAAE,4BAA4B,EAAE,MAAM,iBAAiB,CAAC;AAC/D,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAErD,SAAS,kBAAkB;IACzB,MAAM,SAAS,GAAG,IAAI,CAAC,YAAY,EAAE,CAAC;IACtC,SAAS,CAAC,gBAAgB,CACxB,aAAa,CAAC,aAAa,EAC3B,CAAC,KAAyB,EAAE,EAAE;QAC5B,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QACpC,UAAU,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;IACxC,CAAC,CACF,CAAC;IACF,SAAS,CAAC,gBAAgB,CACxB,aAAa,CAAC,iBAAiB,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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function profile<Ret, Fn extends (...args: any[]) => Ret>(sliceName: string, f: Fn): Ret;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// Copyright 2024 The Lynx Authors. All rights reserved.
|
|
2
|
+
// Licensed under the Apache License Version 2.0 that can be found in the
|
|
3
|
+
// LICENSE file in the root directory of this source tree.
|
|
4
|
+
export function profile(sliceName, f) {
|
|
5
|
+
/* v8 ignore next 9 */
|
|
6
|
+
// TODO: change it to __PROFILE__
|
|
7
|
+
if (__DEV__) {
|
|
8
|
+
console.profile(sliceName);
|
|
9
|
+
try {
|
|
10
|
+
return f();
|
|
11
|
+
}
|
|
12
|
+
finally {
|
|
13
|
+
console.profileEnd();
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
return f();
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=profile.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"profile.js","sourceRoot":"","sources":["../../src/utils/profile.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAC1D,MAAM,UAAU,OAAO,CACrB,SAAiB,EACjB,CAAK;IAEL,sBAAsB;IACtB,iCAAiC;IACjC,IAAI,OAAO,EAAE,CAAC;QACZ,OAAO,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;QAC3B,IAAI,CAAC;YACH,OAAO,CAAC,EAAE,CAAC;QACb,CAAC;gBAAS,CAAC;YACT,OAAO,CAAC,UAAU,EAAE,CAAC;QACvB,CAAC;IACH,CAAC;SAAM,CAAC;QACN,OAAO,CAAC,EAAE,CAAC;IACb,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function isSdkVersionGt(major: number, minor: number): boolean;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// Copyright 2024 The Lynx Authors. All rights reserved.
|
|
2
|
+
// Licensed under the Apache License Version 2.0 that can be found in the
|
|
3
|
+
// LICENSE file in the root directory of this source tree.
|
|
4
|
+
export function isSdkVersionGt(major, minor) {
|
|
5
|
+
const lynxSdkVersion = SystemInfo.lynxSdkVersion || '1.0';
|
|
6
|
+
const version = lynxSdkVersion.split('.');
|
|
7
|
+
return (Number(version[0]) > major
|
|
8
|
+
|| (Number(version[0]) == major && Number(version[1]) > minor));
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=version.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/utils/version.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAC1D,MAAM,UAAU,cAAc,CAAC,KAAa,EAAE,KAAa;IACzD,MAAM,cAAc,GAAW,UAAU,CAAC,cAAc,IAAI,KAAK,CAAC;IAClE,MAAM,OAAO,GAAG,cAAc,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAC1C,OAAO,CACL,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,GAAG,KAAK;WACvB,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,KAAK,IAAI,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,CAC/D,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Element } from './api/element.js';
|
|
2
|
+
import type { WorkletRef, WorkletRefId, WorkletRefImpl } from './bindings/types.js';
|
|
3
|
+
interface RefImpl {
|
|
4
|
+
_workletRefMap: Record<WorkletRefId, WorkletRef<unknown>>;
|
|
5
|
+
updateWorkletRef(handle: WorkletRefImpl<Element>, element: ElementNode | null): void;
|
|
6
|
+
updateWorkletRefInitValueChanges(patch: [number, unknown][]): void;
|
|
7
|
+
}
|
|
8
|
+
declare function initWorkletRef(): RefImpl;
|
|
9
|
+
declare const getFromWorkletRefMap: (id: WorkletRefId) => WorkletRef<unknown>;
|
|
10
|
+
declare function removeValueFromWorkletRefMap(id: WorkletRefId): void;
|
|
11
|
+
declare function updateWorkletRefInitValueChanges(patch: [WorkletRefId, unknown][]): void;
|
|
12
|
+
export { type RefImpl, initWorkletRef, getFromWorkletRefMap, removeValueFromWorkletRefMap, updateWorkletRefInitValueChanges, };
|
|
@@ -0,0 +1,50 @@
|
|
|
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
|
+
let impl;
|
|
7
|
+
function initWorkletRef() {
|
|
8
|
+
return (impl = {
|
|
9
|
+
_workletRefMap: {},
|
|
10
|
+
updateWorkletRef,
|
|
11
|
+
updateWorkletRefInitValueChanges,
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
const createWorkletRef = (id, value) => {
|
|
15
|
+
return {
|
|
16
|
+
current: value,
|
|
17
|
+
_wvid: id,
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
const getFromWorkletRefMap = (id) => {
|
|
21
|
+
const value = impl._workletRefMap[id];
|
|
22
|
+
/* v8 ignore next 3 */
|
|
23
|
+
if (__DEV__ && value === undefined) {
|
|
24
|
+
throw new Error('Worklet: ref is not initialized: ' + id);
|
|
25
|
+
}
|
|
26
|
+
return value;
|
|
27
|
+
};
|
|
28
|
+
function removeValueFromWorkletRefMap(id) {
|
|
29
|
+
delete impl._workletRefMap[id];
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Create an element instance of the given element node, then set worklet value to it.
|
|
33
|
+
* This is called in `snapshotContextUpdateWorkletRef`.
|
|
34
|
+
* @param handle handle of the worklet value.
|
|
35
|
+
* @param element the element node.
|
|
36
|
+
*/
|
|
37
|
+
function updateWorkletRef(handle, element) {
|
|
38
|
+
getFromWorkletRefMap(handle._wvid).current = element
|
|
39
|
+
? new Element(element)
|
|
40
|
+
: null;
|
|
41
|
+
}
|
|
42
|
+
function updateWorkletRefInitValueChanges(patch) {
|
|
43
|
+
profile('updateWorkletRefInitValueChanges', () => {
|
|
44
|
+
patch.forEach(([id, value]) => {
|
|
45
|
+
impl._workletRefMap[id] ??= createWorkletRef(id, value);
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
export { initWorkletRef, getFromWorkletRefMap, removeValueFromWorkletRefMap, updateWorkletRefInitValueChanges, };
|
|
50
|
+
//# sourceMappingURL=workletRef.js.map
|
|
@@ -0,0 +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,CAAC;IACD,OAAO,KAAM,CAAC;AAChB,CAAC,CAAC;AAEF,SAAS,4BAA4B,CAAC,EAAgB;IACpD,OAAO,IAAK,CAAC,cAAc,CAAC,EAAE,CAAC,CAAC;AAClC,CAAC;AAED;;;;;GAKG;AACH,SAAS,gBAAgB,CACvB,MAA+B,EAC/B,OAA2B;IAE3B,oBAAoB,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,OAAO,GAAG,OAAO;QAClD,CAAC,CAAC,IAAI,OAAO,CAAC,OAAO,CAAC;QACtB,CAAC,CAAC,IAAI,CAAC;AACX,CAAC;AAED,SAAS,gCAAgC,CACvC,KAAgC;IAEhC,OAAO,CAAC,kCAAkC,EAAE,GAAG,EAAE;QAC/C,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,KAAK,CAAC,EAAE,EAAE;YAC5B,IAAK,CAAC,cAAc,CAAC,EAAE,CAAC,KAAK,gBAAgB,CAAC,EAAE,EAAE,KAAK,CAAC,CAAC;QAC3D,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC;AAED,OAAO,EAEL,cAAc,EACd,oBAAoB,EACpB,4BAA4B,EAC5B,gCAAgC,GACjC,CAAC"}
|