@lynx-js/react 0.129.0 → 0.129.2
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 +24 -0
- package/components/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -4
- package/refresh/.turbo/turbo-build.log +1 -1
- package/runtime/__test__/core/globalProps.test.ts +27 -6
- package/runtime/__test__/core/hooks/useLynxGlobalEventListener.test.jsx +1 -1
- package/runtime/__test__/element-template/fixtures/gesture/direct/index.tsx +33 -0
- package/runtime/__test__/element-template/fixtures/spread/mts/index.tsx +197 -0
- package/runtime/__test__/element-template/imports/no-legacy-imports.test.ts +7 -6
- package/runtime/__test__/element-template/internal/legacy-internal-guardrail.test.ts +1 -2
- package/runtime/__test__/element-template/native/callDestroyLifetimeFun.test.ts +89 -3
- package/runtime/__test__/element-template/native/main-thread-api.test.ts +5 -2
- package/runtime/__test__/element-template/native/mts-destroy.test.ts +88 -0
- package/runtime/__test__/element-template/native/reload-dual-thread-communication.test.ts +3 -0
- package/runtime/__test__/element-template/native/reload.test.ts +118 -2
- package/runtime/__test__/element-template/runtime/background/global-props/compiled-fixtures.test.tsx +5 -5
- package/runtime/__test__/element-template/runtime/background/global-props.test.tsx +1 -1
- package/runtime/__test__/element-template/runtime/background/hydrate.test.ts +70 -0
- package/runtime/__test__/element-template/runtime/background/ref/compiled-fixtures.test.tsx +3 -4
- package/runtime/__test__/element-template/runtime/background/reload.test.ts +74 -0
- package/runtime/__test__/element-template/runtime/background/update-timing.test.ts +15 -0
- package/runtime/__test__/element-template/runtime/patch/element-template-patch.test.tsx +212 -7
- package/runtime/__test__/element-template/runtime/patch/update-timing.test.ts +4 -1
- package/runtime/__test__/element-template/runtime/prop-adapters/gesture-compiled.test.ts +200 -0
- package/runtime/__test__/element-template/runtime/prop-adapters/gesture.test.ts +420 -0
- package/runtime/__test__/element-template/runtime/prop-adapters/spread-mts-compiled.test.ts +527 -0
- package/runtime/__test__/element-template/runtime/prop-adapters/spread.test.ts +185 -6
- package/runtime/__test__/element-template/runtime/render/render-direct-native.test.tsx +21 -1
- package/runtime/__test__/element-template/runtime/render/render-direct-suspense.test.ts +4 -1
- package/runtime/__test__/element-template/runtime/render/render-direct.test.ts +4 -1
- package/runtime/__test__/element-template/runtime/render/render-main-thread.test.ts +101 -1
- package/runtime/__test__/element-template/runtime/template/element-template-handle.test.ts +32 -0
- package/runtime/__test__/element-template/runtime/template/main-thread-dynamic-attr-state.test.ts +309 -26
- package/runtime/__test__/element-template/test-utils/debug/envManager.ts +8 -5
- package/runtime/__test__/element-template/test-utils/mock/mockNativePapi.ts +35 -2
- package/runtime/__test__/guardrails/snapshot-containment.test.ts +45 -11
- package/runtime/__test__/shared/component-stack.test.ts +211 -0
- package/runtime/__test__/snapshot/debug/formatPatch.test.ts +0 -8
- package/runtime/__test__/snapshot/gesture/prepareGestureForCommit.test.js +1 -1
- package/runtime/__test__/snapshot/lifecycle/updateGlobalProps.event.test.jsx +2 -2
- package/runtime/__test__/snapshot/lifecycle/updateGlobalProps.test.jsx +3 -3
- package/runtime/__test__/snapshot/lynx/timing.test.jsx +3 -0
- package/runtime/__test__/snapshot/preact.test.jsx +0 -3
- package/runtime/__test__/snapshot/ref.test.jsx +30 -0
- package/runtime/__test__/snapshot/snapshotPatch.test.jsx +0 -33
- package/runtime/__test__/worklet-runtime/jsFunctionLifecycle.test.js +12 -0
- package/runtime/__test__/worklet-runtime/loadRuntime.test.js +68 -0
- package/runtime/__test__/worklet-runtime/workletRuntime.test.js +30 -0
- package/runtime/lazy/element-template-internal.js +1 -1
- package/runtime/lazy/internal.js +1 -1
- package/runtime/lazy/jsx-dev-runtime.js +1 -1
- package/runtime/lazy/jsx-runtime.js +1 -1
- package/runtime/lazy/legacy-react-runtime.js +1 -1
- package/runtime/lazy/react-lepus.js +1 -1
- package/runtime/lazy/react.js +1 -1
- package/runtime/lib/core/capture-main-thread-object.js +2 -1
- package/runtime/lib/core/capture-main-thread-object.js.map +1 -1
- package/runtime/lib/core/compat/legacy-react-runtime.js +1 -1
- package/runtime/lib/core/compat/legacy-react-runtime.js.map +1 -1
- package/runtime/lib/core/globalProps.js +1 -1
- package/runtime/lib/core/globalProps.js.map +1 -1
- package/runtime/lib/core/lynx/lazy-bundle.js +1 -1
- package/runtime/lib/core/lynx/lazy-bundle.js.map +1 -1
- package/runtime/lib/core/lynx-data-processors.d.ts +125 -1
- package/runtime/lib/core/lynx-data-processors.js +3 -0
- package/runtime/lib/core/lynx-data-processors.js.map +1 -1
- package/runtime/lib/core/runtime-destroy.js +1 -1
- package/runtime/lib/core/runtime-destroy.js.map +1 -1
- package/runtime/lib/document.js +0 -5
- package/runtime/lib/document.js.map +1 -1
- package/runtime/lib/element-template/background/attr-slots.js +5 -2
- package/runtime/lib/element-template/background/attr-slots.js.map +1 -1
- package/runtime/lib/element-template/background/commit-hook.js +11 -12
- package/runtime/lib/element-template/background/commit-hook.js.map +1 -1
- package/runtime/lib/element-template/background/destroy.js +16 -11
- package/runtime/lib/element-template/background/destroy.js.map +1 -1
- package/runtime/lib/element-template/background/hydrate.js +23 -0
- package/runtime/lib/element-template/background/hydrate.js.map +1 -1
- package/runtime/lib/element-template/client/root.d.ts +1 -1
- package/runtime/lib/element-template/client/root.js.map +1 -1
- package/runtime/lib/element-template/debug/alog.d.ts +1 -1
- package/runtime/lib/element-template/debug/alog.js +4 -1
- package/runtime/lib/element-template/debug/alog.js.map +1 -1
- package/runtime/lib/element-template/index.d.ts +2 -2
- package/runtime/lib/element-template/index.js.map +1 -1
- package/runtime/lib/element-template/internal.d.ts +2 -2
- package/runtime/lib/element-template/internal.js +1 -14
- package/runtime/lib/element-template/internal.js.map +1 -1
- package/runtime/lib/element-template/lynx/env.js.map +1 -1
- package/runtime/lib/element-template/native/callDestroyLifetimeFun.js +6 -1
- package/runtime/lib/element-template/native/callDestroyLifetimeFun.js.map +1 -1
- package/runtime/lib/element-template/native/flush.d.ts +1 -0
- package/runtime/lib/element-template/native/flush.js +9 -0
- package/runtime/lib/element-template/native/flush.js.map +1 -0
- package/runtime/lib/element-template/native/main-thread-api.js +3 -7
- package/runtime/lib/element-template/native/main-thread-api.js.map +1 -1
- package/runtime/lib/element-template/native/mts-destroy.js +8 -2
- package/runtime/lib/element-template/native/mts-destroy.js.map +1 -1
- package/runtime/lib/element-template/native/patch-listener.js +57 -50
- package/runtime/lib/element-template/native/patch-listener.js.map +1 -1
- package/runtime/lib/element-template/native/reload-background.js +1 -1
- package/runtime/lib/element-template/native/reload-background.js.map +1 -1
- package/runtime/lib/element-template/native/reload-main-thread.js +35 -10
- package/runtime/lib/element-template/native/reload-main-thread.js.map +1 -1
- package/runtime/lib/element-template/prop-adapters/gesture.d.ts +23 -0
- package/runtime/lib/element-template/prop-adapters/gesture.js +97 -0
- package/runtime/lib/element-template/prop-adapters/gesture.js.map +1 -0
- package/runtime/lib/element-template/prop-adapters/spread.d.ts +6 -1
- package/runtime/lib/element-template/prop-adapters/spread.js +72 -2
- package/runtime/lib/element-template/prop-adapters/spread.js.map +1 -1
- package/runtime/lib/element-template/protocol/opcodes.d.ts +1 -0
- package/runtime/lib/element-template/protocol/opcodes.js +1 -0
- package/runtime/lib/element-template/protocol/opcodes.js.map +1 -1
- package/runtime/lib/element-template/protocol/types.d.ts +7 -1
- package/runtime/lib/element-template/protocol/types.js.map +1 -1
- package/runtime/lib/element-template/runtime/page/root-instance.d.ts +0 -1
- package/runtime/lib/element-template/runtime/page/root-instance.js.map +1 -1
- package/runtime/lib/element-template/runtime/patch.js +31 -2
- package/runtime/lib/element-template/runtime/patch.js.map +1 -1
- package/runtime/lib/element-template/runtime/render/render-components.js +4 -4
- package/runtime/lib/element-template/runtime/render/render-components.js.map +1 -1
- package/runtime/lib/element-template/runtime/render/render-main-thread.js +2 -0
- package/runtime/lib/element-template/runtime/render/render-main-thread.js.map +1 -1
- package/runtime/lib/element-template/runtime/template/attr-slot-plan.d.ts +4 -2
- package/runtime/lib/element-template/runtime/template/attr-slot-plan.js +17 -4
- package/runtime/lib/element-template/runtime/template/attr-slot-plan.js.map +1 -1
- package/runtime/lib/element-template/runtime/template/main-thread-background-function.js +8 -1
- package/runtime/lib/element-template/runtime/template/main-thread-background-function.js.map +1 -1
- package/runtime/lib/element-template/runtime/template/main-thread-dynamic-attr-state.d.ts +7 -1
- package/runtime/lib/element-template/runtime/template/main-thread-dynamic-attr-state.js +380 -50
- package/runtime/lib/element-template/runtime/template/main-thread-dynamic-attr-state.js.map +1 -1
- package/runtime/lib/element-template/runtime/template/main-thread-ref-ctx.d.ts +3 -2
- package/runtime/lib/element-template/runtime/template/main-thread-ref-ctx.js +10 -1
- package/runtime/lib/element-template/runtime/template/main-thread-ref-ctx.js.map +1 -1
- package/runtime/lib/element-template/runtime/template/typed-attributes.js +3 -3
- package/runtime/lib/element-template/runtime/template/typed-attributes.js.map +1 -1
- package/runtime/lib/internal.d.ts +1 -1
- package/runtime/lib/internal.js +1 -1
- package/runtime/lib/internal.js.map +1 -1
- package/runtime/lib/lynx-api.d.ts +2 -125
- package/runtime/lib/lynx-api.js.map +1 -1
- package/runtime/lib/shared/component-stack.d.ts +0 -4
- package/runtime/lib/shared/component-stack.js +21 -5
- package/runtime/lib/shared/component-stack.js.map +1 -1
- package/runtime/lib/snapshot/gesture/{processGestureBagkround.js → processGestureBackground.js} +1 -1
- package/runtime/lib/snapshot/gesture/processGestureBackground.js.map +1 -0
- package/runtime/lib/snapshot/lifecycle/destroy.js +23 -17
- package/runtime/lib/snapshot/lifecycle/destroy.js.map +1 -1
- package/runtime/lib/snapshot/lifecycle/patch/snapshotPatch.d.ts +0 -1
- package/runtime/lib/snapshot/lifecycle/patch/snapshotPatch.js +0 -5
- package/runtime/lib/snapshot/lifecycle/patch/snapshotPatch.js.map +1 -1
- package/runtime/lib/snapshot/lifecycle/patch/snapshotPatchApply.js +0 -10
- package/runtime/lib/snapshot/lifecycle/patch/snapshotPatchApply.js.map +1 -1
- package/runtime/lib/snapshot/lifecycle/patch/updateMainThread.js +56 -51
- package/runtime/lib/snapshot/lifecycle/patch/updateMainThread.js.map +1 -1
- package/runtime/lib/snapshot/lifecycle/ref/delay.d.ts +5 -0
- package/runtime/lib/snapshot/lifecycle/ref/delay.js +1 -1
- package/runtime/lib/snapshot/lifecycle/ref/delay.js.map +1 -1
- package/runtime/lib/snapshot/list/listUpdateInfo.js +0 -30
- package/runtime/lib/snapshot/list/listUpdateInfo.js.map +1 -1
- package/runtime/lib/snapshot/lynx/calledByNative.js +11 -8
- package/runtime/lib/snapshot/lynx/calledByNative.js.map +1 -1
- package/runtime/lib/snapshot/renderToOpcodes/hydrate.js +0 -52
- package/runtime/lib/snapshot/renderToOpcodes/hydrate.js.map +1 -1
- package/runtime/lib/snapshot/renderToOpcodes/index.js +10 -10
- package/runtime/lib/snapshot/renderToOpcodes/index.js.map +1 -1
- package/runtime/lib/snapshot/renderToOpcodes/opcodes.js +0 -51
- package/runtime/lib/snapshot/renderToOpcodes/opcodes.js.map +1 -1
- package/runtime/lib/snapshot/snapshot/backgroundSnapshot.js +1 -1
- package/runtime/lib/snapshot/snapshot/backgroundSnapshot.js.map +1 -1
- package/runtime/lib/tsconfig.tsbuildinfo +1 -1
- package/runtime/lib/worklet-runtime/bindings/index.d.ts +1 -0
- package/runtime/lib/worklet-runtime/bindings/index.js +1 -0
- package/runtime/lib/worklet-runtime/bindings/index.js.map +1 -1
- package/runtime/lib/worklet-runtime/bindings/loadRuntime.d.ts +8 -0
- package/runtime/lib/worklet-runtime/bindings/loadRuntime.js +23 -0
- package/runtime/lib/worklet-runtime/bindings/loadRuntime.js.map +1 -0
- package/runtime/lib/worklet-runtime/jsFunctionLifecycle.d.ts +2 -0
- package/runtime/lib/worklet-runtime/jsFunctionLifecycle.js +6 -0
- package/runtime/lib/worklet-runtime/jsFunctionLifecycle.js.map +1 -1
- package/runtime/lib/worklet-runtime/workletRuntime.js +2 -0
- package/runtime/lib/worklet-runtime/workletRuntime.js.map +1 -1
- package/runtime/package.json +2 -3
- package/runtime/src/core/capture-main-thread-object.ts +2 -1
- package/runtime/src/core/compat/legacy-react-runtime.ts +1 -1
- package/runtime/src/core/globalProps.ts +1 -1
- package/runtime/src/core/lynx/lazy-bundle.ts +1 -1
- package/runtime/src/core/lynx-data-processors.ts +124 -1
- package/runtime/src/core/runtime-destroy.ts +1 -1
- package/runtime/src/document.ts +0 -6
- package/runtime/src/element-template/background/attr-slots.ts +5 -1
- package/runtime/src/element-template/background/commit-hook.ts +18 -12
- package/runtime/src/element-template/background/destroy.ts +16 -13
- package/runtime/src/element-template/background/hydrate.ts +23 -0
- package/runtime/src/element-template/client/root.ts +1 -3
- package/runtime/src/element-template/debug/alog.ts +5 -2
- package/runtime/src/element-template/index.ts +2 -2
- package/runtime/src/element-template/internal.ts +1 -20
- package/runtime/src/element-template/lynx/env.ts +1 -1
- package/runtime/src/element-template/native/callDestroyLifetimeFun.ts +5 -1
- package/runtime/src/element-template/native/flush.ts +10 -0
- package/runtime/src/element-template/native/main-thread-api.ts +3 -6
- package/runtime/src/element-template/native/mts-destroy.ts +7 -2
- package/runtime/src/element-template/native/patch-listener.ts +62 -57
- package/runtime/src/element-template/native/reload-background.ts +1 -1
- package/runtime/src/element-template/native/reload-main-thread.ts +32 -11
- package/runtime/src/element-template/prop-adapters/gesture.ts +144 -0
- package/runtime/src/element-template/prop-adapters/spread.ts +110 -2
- package/runtime/src/element-template/protocol/opcodes.ts +1 -0
- package/runtime/src/element-template/protocol/types.ts +8 -13
- package/runtime/src/element-template/runtime/page/root-instance.ts +0 -1
- package/runtime/src/element-template/runtime/patch.ts +38 -0
- package/runtime/src/element-template/runtime/render/render-components.ts +3 -3
- package/runtime/src/element-template/runtime/render/render-main-thread.ts +2 -0
- package/runtime/src/element-template/runtime/template/attr-slot-plan.ts +31 -4
- package/runtime/src/element-template/runtime/template/main-thread-background-function.ts +8 -1
- package/runtime/src/element-template/runtime/template/main-thread-dynamic-attr-state.ts +456 -50
- package/runtime/src/element-template/runtime/template/main-thread-ref-ctx.ts +14 -4
- package/runtime/src/element-template/runtime/template/typed-attributes.ts +3 -3
- package/runtime/src/element-template/types.d.ts +6 -0
- package/runtime/src/internal.ts +1 -1
- package/runtime/src/lynx-api.ts +2 -124
- package/runtime/src/shared/component-stack.ts +22 -5
- package/runtime/src/snapshot/lifecycle/destroy.ts +23 -18
- package/runtime/src/snapshot/lifecycle/patch/snapshotPatch.ts +0 -5
- package/runtime/src/snapshot/lifecycle/patch/snapshotPatchApply.ts +0 -10
- package/runtime/src/snapshot/lifecycle/patch/updateMainThread.ts +62 -58
- package/runtime/src/snapshot/lifecycle/ref/delay.ts +1 -1
- package/runtime/src/snapshot/list/listUpdateInfo.ts +0 -52
- package/runtime/src/snapshot/lynx/calledByNative.ts +11 -9
- package/runtime/src/snapshot/renderToOpcodes/hydrate.ts +0 -58
- package/runtime/src/snapshot/renderToOpcodes/index.ts +8 -8
- package/runtime/src/snapshot/renderToOpcodes/opcodes.ts +0 -57
- package/runtime/src/snapshot/snapshot/backgroundSnapshot.ts +1 -1
- package/runtime/src/worklet-runtime/README.md +30 -10
- package/runtime/src/worklet-runtime/bindings/index.ts +2 -0
- package/runtime/src/worklet-runtime/bindings/loadRuntime.ts +25 -0
- package/runtime/src/worklet-runtime/jsFunctionLifecycle.ts +6 -0
- package/runtime/src/worklet-runtime/workletRuntime.ts +2 -0
- package/runtime/types/types.d.ts +2 -1
- package/runtime/vitest.config.ts +0 -2
- package/testing-library/.turbo/turbo-build.log +7 -7
- package/testing-library/src/__tests__/act.test.jsx +0 -7
- package/testing-library/src/__tests__/alog.test.jsx +12 -54
- package/testing-library/src/__tests__/end-to-end.test.jsx +0 -7
- package/testing-library/src/__tests__/renderComponent.test.jsx +0 -14
- package/testing-library/src/__tests__/worklet.test.jsx +49 -0
- package/transform/.turbo/turbo-build$colon$wasm.log +133 -297
- package/transform/__test__/defines.spec.js +30 -0
- package/transform/__test__/fixture.spec.js +11 -11
- package/transform/__test__/main-thread-object-compat.spec.js +111 -0
- package/transform/__test__/object-methods.spec.js +79 -0
- package/transform/crates/swc_plugin_element_template/lib.rs +11 -0
- package/transform/crates/swc_plugin_element_template/tests/element_template_contract.rs +113 -0
- package/transform/crates/swc_plugin_worklet/extract_ident.rs +99 -49
- package/transform/crates/swc_plugin_worklet/gen_stmt.rs +63 -57
- package/transform/crates/swc_plugin_worklet/lib.rs +393 -589
- package/transform/crates/swc_plugin_worklet/napi.rs +4 -6
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_capture_env_js.js +3 -3
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_capture_env_lepus.js +3 -3
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_2_js.js +11 -6
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_2_lepus.js +12 -6
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_js.js +14 -5
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_lepus.js +17 -6
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_preserve_main_thread_objects_in_class_js.js +5 -5
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_preserve_main_thread_objects_in_class_lepus.js +5 -5
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_js.js +1 -1
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_lepus.js +1 -1
- package/transform/dist/wasm.cjs +1 -1
- package/transform/package.json +0 -1
- package/transform/src/lib.rs +1 -1
- package/transform/swc-plugin-reactlynx/.turbo/turbo-build.log +167 -69
- package/transform/swc-plugin-reactlynx/src/lib.rs +1 -4
- package/transform/swc-plugin-reactlynx/swc_plugin_reactlynx.wasm +0 -0
- package/transform/swc-plugin-reactlynx-compat/.turbo/turbo-build.log +226 -132
- package/runtime/lib/snapshot/gesture/processGestureBagkround.js.map +0 -1
- package/runtime/lib/snapshot/worklet/hmr.d.ts +0 -1
- package/runtime/lib/snapshot/worklet/hmr.js +0 -28
- package/runtime/lib/snapshot/worklet/hmr.js.map +0 -1
- package/runtime/src/snapshot/worklet/hmr.ts +0 -34
- /package/runtime/lib/snapshot/gesture/{processGestureBagkround.d.ts → processGestureBackground.d.ts} +0 -0
- /package/runtime/src/snapshot/gesture/{processGestureBagkround.ts → processGestureBackground.ts} +0 -0
|
@@ -1,6 +1,7 @@
|
|
|
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
|
+
export { loadWorkletRuntime } from './loadRuntime.js';
|
|
4
5
|
export * from './bindings.js';
|
|
5
6
|
export * from './observers.js';
|
|
6
7
|
export { WorkletEvents } from './events.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/worklet-runtime/bindings/index.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D,cAAc,eAAe,CAAC;AAE9B,cAAc,gBAAgB,CAAC;AAI/B,OAAO,EAAE,aAAa,EAAqD,MAAM,aAAa,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\nexport * from './bindings.js';\n\nexport * from './observers.js';\n\nexport type * from './types.js';\n\nexport { WorkletEvents, type RunWorkletCtxData, type RunWorkletCtxRetData } from './events.js';\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/worklet-runtime/bindings/index.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAEtD,cAAc,eAAe,CAAC;AAE9B,cAAc,gBAAgB,CAAC;AAI/B,OAAO,EAAE,aAAa,EAAqD,MAAM,aAAa,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\nexport { loadWorkletRuntime } from './loadRuntime.js';\n\nexport * from './bindings.js';\n\nexport * from './observers.js';\n\nexport type * from './types.js';\n\nexport { WorkletEvents, type RunWorkletCtxData, type RunWorkletCtxRetData } from './events.js';\n"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import '../global.js';
|
|
2
|
+
/**
|
|
3
|
+
* Loads the legacy main-thread worklet chunk or reuses an initialized runtime.
|
|
4
|
+
* @param __schema - The dynamic component entry for loading the Lepus chunk.
|
|
5
|
+
* @returns Whether the worklet runtime was loaded and initialized successfully.
|
|
6
|
+
*/
|
|
7
|
+
declare function loadWorkletRuntime(__schema?: string): boolean;
|
|
8
|
+
export { loadWorkletRuntime };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// Copyright 2024 The Lynx Authors. All rights reserved.
|
|
2
|
+
// Licensed under the Apache License Version 2.0 that can be found in the
|
|
3
|
+
// LICENSE file in the root directory of this source tree.
|
|
4
|
+
import '../global.js';
|
|
5
|
+
/**
|
|
6
|
+
* Loads the legacy main-thread worklet chunk or reuses an initialized runtime.
|
|
7
|
+
* @param __schema - The dynamic component entry for loading the Lepus chunk.
|
|
8
|
+
* @returns Whether the worklet runtime was loaded and initialized successfully.
|
|
9
|
+
*/
|
|
10
|
+
function loadWorkletRuntime(__schema) {
|
|
11
|
+
if (typeof __LoadLepusChunk === 'undefined') {
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
if (globalThis.lynxWorkletImpl) {
|
|
15
|
+
return true;
|
|
16
|
+
}
|
|
17
|
+
return __LoadLepusChunk('worklet-runtime', {
|
|
18
|
+
dynamicComponentEntry: __schema,
|
|
19
|
+
chunkType: 0,
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
export { loadWorkletRuntime };
|
|
23
|
+
//# sourceMappingURL=loadRuntime.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loadRuntime.js","sourceRoot":"","sources":["../../../src/worklet-runtime/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","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\nimport '../global.js';\n\n/**\n * Loads the legacy main-thread worklet chunk or reuses an initialized runtime.\n * @param __schema - The dynamic component entry for loading the Lepus chunk.\n * @returns Whether the worklet runtime was loaded and initialized successfully.\n */\nfunction loadWorkletRuntime(__schema?: string): boolean {\n if (typeof __LoadLepusChunk === 'undefined') {\n return false;\n }\n if (globalThis.lynxWorkletImpl) {\n return true;\n }\n return __LoadLepusChunk('worklet-runtime', {\n dynamicComponentEntry: __schema,\n chunkType: 0,\n });\n}\n\nexport { loadWorkletRuntime };\n"]}
|
|
@@ -9,10 +9,12 @@ declare class JsFunctionLifecycleManager {
|
|
|
9
9
|
private execIdSetToFire;
|
|
10
10
|
private retainedObjects;
|
|
11
11
|
private willFire;
|
|
12
|
+
private active;
|
|
12
13
|
private registry;
|
|
13
14
|
constructor();
|
|
14
15
|
addRef(execId: number, objToRef: object): void;
|
|
15
16
|
removeRef(execId: number): void;
|
|
17
|
+
dispose(): void;
|
|
16
18
|
fire(): void;
|
|
17
19
|
}
|
|
18
20
|
declare function isRunOnBackgroundEnabled(): boolean;
|
|
@@ -15,6 +15,7 @@ class JsFunctionLifecycleManager {
|
|
|
15
15
|
execIdSetToFire = new Set();
|
|
16
16
|
retainedObjects = new WeakSet();
|
|
17
17
|
willFire = false;
|
|
18
|
+
active = true;
|
|
18
19
|
registry;
|
|
19
20
|
constructor() {
|
|
20
21
|
this.registry = new FinalizationRegistry(this.removeRef.bind(this));
|
|
@@ -43,7 +44,12 @@ class JsFunctionLifecycleManager {
|
|
|
43
44
|
});
|
|
44
45
|
}
|
|
45
46
|
}
|
|
47
|
+
dispose() {
|
|
48
|
+
this.active = false;
|
|
49
|
+
}
|
|
46
50
|
fire() {
|
|
51
|
+
if (!this.active)
|
|
52
|
+
return;
|
|
47
53
|
profile('JsFunctionLifecycleManager.fire', () => {
|
|
48
54
|
lynx.getJSContext().dispatchEvent({
|
|
49
55
|
type: WorkletEvents.releaseBackgroundWorkletCtx,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jsFunctionLifecycle.js","sourceRoot":"","sources":["../../src/worklet-runtime/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,eAAe,GAAG,IAAI,OAAO,EAAU,CAAC;IACxC,Q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;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,wBAAwB;IAC/B,OAAO,cAAc,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;AAC/B,CAAC;AAED,OAAO,EAAE,0BAA0B,EAAE,wBAAwB,EAAE,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 { WorkletEvents } from './bindings/events.js';\nimport { profile } from './utils/profile.js';\nimport { isSdkVersionGt } from './utils/version.js';\n\n/**\n * `JsFunctionLifecycleManager` monitors references to JS function handles to be called by `runOnBackground()`.\n * In JS context, functions to be called by `runOnBackground()` is referenced by `JsFnHandle`s and finally by `execId`.\n * When all `JsFnHandle`s in lepus are released, an event will be sent to JS context to de-ref the `execId`,\n * resulting a de-ref to the js function in JS context.\n */\nclass JsFunctionLifecycleManager {\n private execIdRefCount = new Map<number, number>();\n private execIdSetToFire = new Set<number>();\n private retainedObjects = new WeakSet<object>();\n private willFire = false;\n private registry: FinalizationRegistry<number>;\n\n constructor() {\n this.registry = new FinalizationRegistry<number>(this.removeRef.bind(this));\n }\n\n addRef(execId: number, objToRef: object): void {\n if (this.retainedObjects.has(objToRef)) {\n return;\n }\n // A failed engine registration must leave the target eligible for a retry.\n this.registry.register(objToRef, execId);\n this.retainedObjects.add(objToRef);\n this.execIdRefCount.set(\n execId,\n (this.execIdRefCount.get(execId) ?? 0) + 1,\n );\n }\n\n removeRef(execId: number): void {\n const rc = this.execIdRefCount.get(execId)!;\n if (rc > 1) {\n this.execIdRefCount.set(execId, rc - 1);\n return;\n }\n this.execIdRefCount.delete(execId);\n this.execIdSetToFire.add(execId);\n if (!this.willFire) {\n this.willFire = true;\n void Promise.resolve().then(() => {\n this.fire();\n });\n }\n }\n\n fire(): void {\n profile('JsFunctionLifecycleManager.fire', () => {\n lynx.getJSContext().dispatchEvent({\n type: WorkletEvents.releaseBackgroundWorkletCtx,\n data: Array.from(this.execIdSetToFire),\n });\n this.execIdSetToFire.clear();\n this.willFire = false;\n });\n }\n}\n\nfunction isRunOnBackgroundEnabled(): boolean {\n return isSdkVersionGt(2, 15);\n}\n\nexport { JsFunctionLifecycleManager, isRunOnBackgroundEnabled };\n"]}
|
|
1
|
+
{"version":3,"file":"jsFunctionLifecycle.js","sourceRoot":"","sources":["../../src/worklet-runtime/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,eAAe,GAAG,IAAI,OAAO,EAAU,CAAC;IACxC,QAAQ,GAAG,KAAK,CAAC;IACjB,MAAM,GAAG,IAAI,CAAC;IACd,QAAQ,CAA+B;IAE/C;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,IAAI,CAAC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,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,wBAAwB;IAC/B,OAAO,cAAc,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;AAC/B,CAAC;AAED,OAAO,EAAE,0BAA0B,EAAE,wBAAwB,EAAE,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 { WorkletEvents } from './bindings/events.js';\nimport { profile } from './utils/profile.js';\nimport { isSdkVersionGt } from './utils/version.js';\n\n/**\n * `JsFunctionLifecycleManager` monitors references to JS function handles to be called by `runOnBackground()`.\n * In JS context, functions to be called by `runOnBackground()` is referenced by `JsFnHandle`s and finally by `execId`.\n * When all `JsFnHandle`s in lepus are released, an event will be sent to JS context to de-ref the `execId`,\n * resulting a de-ref to the js function in JS context.\n */\nclass JsFunctionLifecycleManager {\n private execIdRefCount = new Map<number, number>();\n private execIdSetToFire = new Set<number>();\n private retainedObjects = new WeakSet<object>();\n private willFire = false;\n private active = true;\n private registry: FinalizationRegistry<number>;\n\n constructor() {\n this.registry = new FinalizationRegistry<number>(this.removeRef.bind(this));\n }\n\n addRef(execId: number, objToRef: object): void {\n if (this.retainedObjects.has(objToRef)) {\n return;\n }\n // A failed engine registration must leave the target eligible for a retry.\n this.registry.register(objToRef, execId);\n this.retainedObjects.add(objToRef);\n this.execIdRefCount.set(\n execId,\n (this.execIdRefCount.get(execId) ?? 0) + 1,\n );\n }\n\n removeRef(execId: number): void {\n const rc = this.execIdRefCount.get(execId)!;\n if (rc > 1) {\n this.execIdRefCount.set(execId, rc - 1);\n return;\n }\n this.execIdRefCount.delete(execId);\n this.execIdSetToFire.add(execId);\n if (!this.willFire) {\n this.willFire = true;\n void Promise.resolve().then(() => {\n this.fire();\n });\n }\n }\n\n dispose(): void {\n this.active = false;\n }\n\n fire(): void {\n if (!this.active) return;\n profile('JsFunctionLifecycleManager.fire', () => {\n lynx.getJSContext().dispatchEvent({\n type: WorkletEvents.releaseBackgroundWorkletCtx,\n data: Array.from(this.execIdSetToFire),\n });\n this.execIdSetToFire.clear();\n this.willFire = false;\n });\n }\n}\n\nfunction isRunOnBackgroundEnabled(): boolean {\n return isSdkVersionGt(2, 15);\n}\n\nexport { JsFunctionLifecycleManager, isRunOnBackgroundEnabled };\n"]}
|
|
@@ -15,6 +15,8 @@ import { mainThreadFlushLoopMark } from './utils/mainThreadFlushLoopGuard.js';
|
|
|
15
15
|
import { profile } from './utils/profile.js';
|
|
16
16
|
import { getFromWorkletRefMap, initWorkletRef } from './workletRef.js';
|
|
17
17
|
function initWorklet() {
|
|
18
|
+
const previousManager = globalThis.lynxWorkletImpl?._jsFunctionLifecycleManager;
|
|
19
|
+
previousManager?.dispose();
|
|
18
20
|
globalThis.lynxWorkletImpl = {
|
|
19
21
|
_workletMap: {},
|
|
20
22
|
_refImpl: initWorkletRef(),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"workletRuntime.js","sourceRoot":"","sources":["../../src/worklet-runtime/workletRuntime.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAC1D,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAE3C,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,EAAE,wBAAwB,EAAE,MAAM,2BAA2B,CAAC;AACrE,OAAO,EAAE,qBAAqB,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAC/E,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,uBAAuB,EAAE,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C,KAAK,KAAK,QAAQ;WACtC,OAAO,UAAU,CAAC,KAAK,KAAK,QAAQ;WACpC,UAAU,CAAC,KAAK,KAAK,aAAa,CAAC;AAC1C,CAAC;AACD,OAAO,EAAE,WAAW,EAAE,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 { Element } from './api/element.js';\nimport type { ClosureValueType, RunWorkletOptions, Worklet, WorkletRefImpl } from './bindings/types.js';\nimport { RunWorkletSource } from './bindings/types.js';\nimport { initRunOnBackgroundDelay } from './delayRunOnBackground.js';\nimport { delayExecUntilJsReady, initEventDelay } from './delayWorkletEvent.js';\nimport { initEomImpl } from './eomImpl.js';\nimport { addEventMethodsIfNeeded } from './eventPropagation.js';\nimport { hydrateCtx } from './hydrate.js';\nimport { JsFunctionLifecycleManager, isRunOnBackgroundEnabled } from './jsFunctionLifecycle.js';\nimport { isRealizedMainThreadObject } from './mainThreadObject.js';\nimport { runRunOnMainThreadTask } from './runOnMainThread.js';\nimport { mainThreadFlushLoopMark } from './utils/mainThreadFlushLoopGuard.js';\nimport { profile } from './utils/profile.js';\nimport { getFromWorkletRefMap, initWorkletRef } from './workletRef.js';\n\nfunction initWorklet(): void {\n globalThis.lynxWorkletImpl = {\n _workletMap: {},\n _refImpl: initWorkletRef(),\n _runOnBackgroundDelayImpl: initRunOnBackgroundDelay(),\n _hydrateCtx: hydrateCtx,\n _eventDelayImpl: initEventDelay(),\n _eomImpl: initEomImpl(),\n _runRunOnMainThreadTask: runRunOnMainThreadTask,\n };\n\n if (isRunOnBackgroundEnabled()) {\n globalThis.lynxWorkletImpl._jsFunctionLifecycleManager = new JsFunctionLifecycleManager();\n }\n\n globalThis.registerWorklet = registerWorklet;\n globalThis.registerWorkletInternal = registerWorklet;\n globalThis.runWorklet = runWorklet;\n}\n\n/**\n * Register a worklet function, allowing it to be executed by `runWorklet()`.\n * This is called in lepus.js.\n * @param _type worklet type, 'main-thread' or 'ui'\n * @param id worklet hash\n * @param worklet worklet function\n */\nfunction registerWorklet(_type: string, id: string, worklet: (...args: unknown[]) => unknown): void {\n lynxWorkletImpl._workletMap[id] = worklet;\n}\n\n/**\n * Entrance of all worklet calls.\n * Native event touch handler will call this function.\n * @param ctx worklet object.\n * @param params worklet params.\n * @param options run worklet options.\n */\nfunction runWorklet(ctx: Worklet, params: ClosureValueType[], options?: RunWorkletOptions): unknown {\n if (!validateWorklet(ctx)) {\n return;\n }\n\n if (__DEV__) {\n if (options?.source === RunWorkletSource.EVENT && Array.isArray(params)) {\n const first = params[0];\n const t = (first as { type?: unknown }).type;\n if (typeof t === 'string') {\n mainThreadFlushLoopMark(`event:${t}`);\n }\n }\n\n mainThreadFlushLoopMark(`MainThreadFunction id=${String(ctx._wkltId)}`);\n }\n\n if ('_lepusWorkletHash' in ctx) {\n delayExecUntilJsReady(ctx._lepusWorkletHash, params);\n return;\n }\n return runWorkletImpl(ctx, params, options);\n}\n\nfunction runWorkletImpl(ctx: Worklet, params: ClosureValueType[], options?: RunWorkletOptions): unknown {\n const worklet: (...args: unknown[]) => unknown = profile(\n 'transformWorkletCtx ' + ctx._wkltId,\n () => transformWorklet(ctx, true),\n );\n const params_: ClosureValueType[] = profile(\n 'transformWorkletParams',\n () => transformWorklet(params || [], false),\n );\n\n const [hasEventMethods, eventCtx] = addEventMethodsIfNeeded(params_, options);\n\n const result = profile('runWorklet', () => worklet(...params_));\n\n if (hasEventMethods) {\n return {\n returnValue: result,\n eventReturnResult: eventCtx._eventReturnResult,\n };\n }\n\n return result;\n}\n\nfunction validateWorklet(ctx: unknown): ctx is Worklet {\n return typeof ctx === 'object' && ctx !== null && ('_wkltId' in ctx || '_lepusWorkletHash' in ctx);\n}\n\nconst workletCache = /*#__PURE__*/ new WeakMap<object, ClosureValueType | ((...args: unknown[]) => unknown)>();\n\nfunction transformWorklet(ctx: Worklet, isWorklet: true): (...args: unknown[]) => unknown;\nfunction transformWorklet(\n ctx: ClosureValueType[],\n isWorklet: false,\n): ClosureValueType[];\n\nfunction transformWorklet(\n ctx: ClosureValueType,\n isWorklet: boolean,\n): ClosureValueType | ((...args: unknown[]) => unknown) {\n /* v8 ignore next 3 */\n if (typeof ctx !== 'object' || ctx === null) {\n return ctx;\n }\n\n if (isWorklet) {\n const res = workletCache.get(ctx);\n if (res) {\n return res;\n }\n }\n\n const worklet = transformWorkletInner({ main: ctx }, 0, ctx) as { main: ClosureValueType };\n\n if (isWorklet) {\n workletCache.set(ctx, worklet.main);\n }\n\n return worklet.main;\n}\n\nconst transformWorkletInner = (\n value: ClosureValueType,\n depth: number,\n ctx: unknown,\n): ClosureValueType => {\n const limit = 1000;\n if (++depth >= limit) {\n throw new Error('Depth of value exceeds limit of ' + limit + '.');\n }\n /* v8 ignore next 3 */\n if (typeof value !== 'object' || value === null) {\n return value;\n }\n let obj = value as Record<string, ClosureValueType>;\n\n for (const key in obj) {\n const subObj: ClosureValueType = obj[key];\n if (typeof subObj !== 'object' || subObj === null) {\n continue;\n }\n\n // A MainThreadObject initialization payload is user data. Resolve the\n // typed descriptor before walking it so payload properties that resemble\n // worklet metadata remain untouched. Legacy MainThreadRef descriptors retain\n // the existing recursive path.\n if (isRealizedMainThreadObject(subObj)) {\n continue;\n }\n if (isMainThreadObjectDescriptor(subObj)) {\n obj = replaceCapturedProperty(obj, value, key, getFromWorkletRefMap(subObj));\n continue;\n }\n\n if (/** isEventTarget */ 'elementRefptr' in subObj) {\n obj[key] = new Element(subObj.elementRefptr as ElementNode);\n continue;\n } else if (subObj instanceof Element) {\n continue;\n }\n\n const transformedSubObj = transformWorkletInner(subObj, depth, ctx) as Record<string, ClosureValueType>;\n\n const isWorkletRef = '_wvid' in (subObj as object);\n if (isWorkletRef) {\n obj[key] = getFromWorkletRefMap(\n subObj as unknown as WorkletRefImpl<unknown>,\n );\n continue;\n }\n const isWorklet = '_wkltId' in subObj;\n if (isWorklet) {\n const isRootWorklet = subObj === ctx;\n const boundCtx = { ...transformedSubObj };\n // Keep the original context collectible. PrimJS traces WeakMap values even\n // when their keys are otherwise unreachable, so the cached function must not point back to its key.\n const boundWorklet: ((...args: unknown[]) => unknown) & { boundCtx?: object } = lynxWorkletImpl\n ._workletMap[(subObj as Worklet)._wkltId]!\n .bind(boundCtx);\n if (transformedSubObj !== subObj && obj === value && obj !== ctx) obj = copyAccessorCapture(obj);\n obj = replaceCapturedProperty(obj, value, key, boundWorklet);\n if (!isRootWorklet) {\n // Hydration needs the same context that the function already owns through bind().\n // The original nested context can disappear after its parent replaces it with this function.\n boundWorklet.boundCtx = boundCtx;\n }\n continue;\n }\n if (transformedSubObj !== subObj) {\n // The root context is runtime-owned: hydration must see its captured copy.\n if (obj === value && obj !== ctx) obj = copyAccessorCapture(obj);\n obj = replaceCapturedProperty(obj, value, key, transformedSubObj);\n }\n const isJsFn = '_jsFnId' in subObj;\n if (isJsFn) {\n (subObj as Record<string, ClosureValueType>)['_execId'] = (ctx as Worklet)._execId;\n lynxWorkletImpl._jsFunctionLifecycleManager?.addRef(\n (ctx as Worklet)._execId!,\n subObj,\n );\n continue;\n }\n }\n return obj;\n};\n\nfunction replaceCapturedProperty(\n obj: Record<string, ClosureValueType>,\n source: object,\n key: string,\n value: ClosureValueType,\n): Record<string, ClosureValueType> {\n const descriptor = Object.getOwnPropertyDescriptor(obj, key);\n if (descriptor?.get) {\n // Getters can refresh handles or method receivers. Materialize the captured\n // value without consuming the source getter or invoking its setter.\n const capturedDescriptor = {\n value,\n writable: true,\n enumerable: descriptor.enumerable!,\n configurable: descriptor.configurable!,\n };\n if (obj === source || !descriptor.configurable) {\n // Replace before defining the copy, including non-configurable getters.\n const descriptors = Object.getOwnPropertyDescriptors(obj);\n descriptors[key] = capturedDescriptor;\n return copyAccessorCapture(obj, descriptors);\n }\n Object.defineProperty(obj, key, capturedDescriptor);\n } else {\n obj[key] = value;\n }\n return obj;\n}\n\nfunction copyAccessorCapture(\n obj: Record<string, ClosureValueType>,\n descriptors: PropertyDescriptorMap = Object.getOwnPropertyDescriptors(obj),\n): Record<string, ClosureValueType> {\n // Copy descriptors without evaluating getters a second time. Array ancestors\n // retain their array identity when a nested accessor requires a captured copy.\n return Object.defineProperties(\n Array.isArray(obj)\n ? []\n : Object.create(Object.getPrototypeOf(obj) as object | null) as Record<string, ClosureValueType>,\n descriptors,\n ) as Record<string, ClosureValueType>;\n}\n\nfunction isMainThreadObjectDescriptor(\n value: object,\n): value is WorkletRefImpl<unknown> {\n const descriptor = value as Partial<WorkletRefImpl<unknown>>;\n return typeof descriptor._wvid === 'number'\n && typeof descriptor._type === 'string'\n && descriptor._type !== 'main-thread';\n}\nexport { initWorklet };\n"]}
|
|
1
|
+
{"version":3,"file":"workletRuntime.js","sourceRoot":"","sources":["../../src/worklet-runtime/workletRuntime.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAC1D,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAE3C,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,EAAE,wBAAwB,EAAE,MAAM,2BAA2B,CAAC;AACrE,OAAO,EAAE,qBAAqB,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAC/E,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAC;AAChE,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,0BAA0B,EAAE,wBAAwB,EAAE,MAAM,0BAA0B,CAAC;AAChG,OAAO,EAAE,0BAA0B,EAAE,MAAM,uBAAuB,CAAC;AACnE,OAAO,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAC;AAC9D,OAAO,EAAE,uBAAuB,EAAE,MAAM,qCAAqC,CAAC;AAC9E,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC7C,OAAO,EAAE,o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AC,UAAW;YAClC,YAAY,EAAE,UAAU,CAAC,YAAa;SACvC,CAAC;QACF,IAAI,GAAG,KAAK,MAAM,IAAI,CAAC,UAAU,CAAC,YAAY,EAAE,CAAC;YAC/C,wEAAwE;YACxE,MAAM,WAAW,GAAG,MAAM,CAAC,yBAAyB,CAAC,GAAG,CAAC,CAAC;YAC1D,WAAW,CAAC,GAAG,CAAC,GAAG,kBAAkB,CAAC;YACtC,OAAO,mBAAmB,CAAC,GAAG,EAAE,WAAW,CAAC,CAAC;QAC/C,CAAC;QACD,MAAM,CAAC,cAAc,CAAC,GAAG,EAAE,GAAG,EAAE,kBAAkB,CAAC,CAAC;IACtD,CAAC;SAAM,CAAC;QACN,GAAG,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;IACnB,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC;AAED,SAAS,mBAAmB,CAC1B,GAAqC,EACrC,cAAqC,MAAM,CAAC,yBAAyB,CAAC,GAAG,CAAC;IAE1E,6EAA6E;IAC7E,+EAA+E;IAC/E,OAAO,MAAM,CAAC,gBAAgB,CAC5B,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC;QAChB,CAAC,CAAC,EAAE;QACJ,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,cAAc,CAAC,GAAG,CAAkB,CAAqC,EAClG,WAAW,CACwB,CAAC;AACxC,CAAC;AAED,SAAS,4BAA4B,CACnC,KAAa;IAEb,MAAM,UAAU,GAAG,KAAyC,CAAC;IAC7D,OAAO,OAAO,UAAU,CAAC,KAAK,KAAK,QAAQ;WACtC,OAAO,UAAU,CAAC,KAAK,KAAK,QAAQ;WACpC,UAAU,CAAC,KAAK,KAAK,aAAa,CAAC;AAC1C,CAAC;AACD,OAAO,EAAE,WAAW,EAAE,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 { Element } from './api/element.js';\nimport type { ClosureValueType, RunWorkletOptions, Worklet, WorkletRefImpl } from './bindings/types.js';\nimport { RunWorkletSource } from './bindings/types.js';\nimport { initRunOnBackgroundDelay } from './delayRunOnBackground.js';\nimport { delayExecUntilJsReady, initEventDelay } from './delayWorkletEvent.js';\nimport { initEomImpl } from './eomImpl.js';\nimport { addEventMethodsIfNeeded } from './eventPropagation.js';\nimport { hydrateCtx } from './hydrate.js';\nimport { JsFunctionLifecycleManager, isRunOnBackgroundEnabled } from './jsFunctionLifecycle.js';\nimport { isRealizedMainThreadObject } from './mainThreadObject.js';\nimport { runRunOnMainThreadTask } from './runOnMainThread.js';\nimport { mainThreadFlushLoopMark } from './utils/mainThreadFlushLoopGuard.js';\nimport { profile } from './utils/profile.js';\nimport { getFromWorkletRefMap, initWorkletRef } from './workletRef.js';\n\nfunction initWorklet(): void {\n const previousManager = globalThis.lynxWorkletImpl?._jsFunctionLifecycleManager;\n previousManager?.dispose();\n globalThis.lynxWorkletImpl = {\n _workletMap: {},\n _refImpl: initWorkletRef(),\n _runOnBackgroundDelayImpl: initRunOnBackgroundDelay(),\n _hydrateCtx: hydrateCtx,\n _eventDelayImpl: initEventDelay(),\n _eomImpl: initEomImpl(),\n _runRunOnMainThreadTask: runRunOnMainThreadTask,\n };\n\n if (isRunOnBackgroundEnabled()) {\n globalThis.lynxWorkletImpl._jsFunctionLifecycleManager = new JsFunctionLifecycleManager();\n }\n\n globalThis.registerWorklet = registerWorklet;\n globalThis.registerWorkletInternal = registerWorklet;\n globalThis.runWorklet = runWorklet;\n}\n\n/**\n * Register a worklet function, allowing it to be executed by `runWorklet()`.\n * This is called in lepus.js.\n * @param _type worklet type, 'main-thread' or 'ui'\n * @param id worklet hash\n * @param worklet worklet function\n */\nfunction registerWorklet(_type: string, id: string, worklet: (...args: unknown[]) => unknown): void {\n lynxWorkletImpl._workletMap[id] = worklet;\n}\n\n/**\n * Entrance of all worklet calls.\n * Native event touch handler will call this function.\n * @param ctx worklet object.\n * @param params worklet params.\n * @param options run worklet options.\n */\nfunction runWorklet(ctx: Worklet, params: ClosureValueType[], options?: RunWorkletOptions): unknown {\n if (!validateWorklet(ctx)) {\n return;\n }\n\n if (__DEV__) {\n if (options?.source === RunWorkletSource.EVENT && Array.isArray(params)) {\n const first = params[0];\n const t = (first as { type?: unknown }).type;\n if (typeof t === 'string') {\n mainThreadFlushLoopMark(`event:${t}`);\n }\n }\n\n mainThreadFlushLoopMark(`MainThreadFunction id=${String(ctx._wkltId)}`);\n }\n\n if ('_lepusWorkletHash' in ctx) {\n delayExecUntilJsReady(ctx._lepusWorkletHash, params);\n return;\n }\n return runWorkletImpl(ctx, params, options);\n}\n\nfunction runWorkletImpl(ctx: Worklet, params: ClosureValueType[], options?: RunWorkletOptions): unknown {\n const worklet: (...args: unknown[]) => unknown = profile(\n 'transformWorkletCtx ' + ctx._wkltId,\n () => transformWorklet(ctx, true),\n );\n const params_: ClosureValueType[] = profile(\n 'transformWorkletParams',\n () => transformWorklet(params || [], false),\n );\n\n const [hasEventMethods, eventCtx] = addEventMethodsIfNeeded(params_, options);\n\n const result = profile('runWorklet', () => worklet(...params_));\n\n if (hasEventMethods) {\n return {\n returnValue: result,\n eventReturnResult: eventCtx._eventReturnResult,\n };\n }\n\n return result;\n}\n\nfunction validateWorklet(ctx: unknown): ctx is Worklet {\n return typeof ctx === 'object' && ctx !== null && ('_wkltId' in ctx || '_lepusWorkletHash' in ctx);\n}\n\nconst workletCache = /*#__PURE__*/ new WeakMap<object, ClosureValueType | ((...args: unknown[]) => unknown)>();\n\nfunction transformWorklet(ctx: Worklet, isWorklet: true): (...args: unknown[]) => unknown;\nfunction transformWorklet(\n ctx: ClosureValueType[],\n isWorklet: false,\n): ClosureValueType[];\n\nfunction transformWorklet(\n ctx: ClosureValueType,\n isWorklet: boolean,\n): ClosureValueType | ((...args: unknown[]) => unknown) {\n /* v8 ignore next 3 */\n if (typeof ctx !== 'object' || ctx === null) {\n return ctx;\n }\n\n if (isWorklet) {\n const res = workletCache.get(ctx);\n if (res) {\n return res;\n }\n }\n\n const worklet = transformWorkletInner({ main: ctx }, 0, ctx) as { main: ClosureValueType };\n\n if (isWorklet) {\n workletCache.set(ctx, worklet.main);\n }\n\n return worklet.main;\n}\n\nconst transformWorkletInner = (\n value: ClosureValueType,\n depth: number,\n ctx: unknown,\n): ClosureValueType => {\n const limit = 1000;\n if (++depth >= limit) {\n throw new Error('Depth of value exceeds limit of ' + limit + '.');\n }\n /* v8 ignore next 3 */\n if (typeof value !== 'object' || value === null) {\n return value;\n }\n let obj = value as Record<string, ClosureValueType>;\n\n for (const key in obj) {\n const subObj: ClosureValueType = obj[key];\n if (typeof subObj !== 'object' || subObj === null) {\n continue;\n }\n\n // A MainThreadObject initialization payload is user data. Resolve the\n // typed descriptor before walking it so payload properties that resemble\n // worklet metadata remain untouched. Legacy MainThreadRef descriptors retain\n // the existing recursive path.\n if (isRealizedMainThreadObject(subObj)) {\n continue;\n }\n if (isMainThreadObjectDescriptor(subObj)) {\n obj = replaceCapturedProperty(obj, value, key, getFromWorkletRefMap(subObj));\n continue;\n }\n\n if (/** isEventTarget */ 'elementRefptr' in subObj) {\n obj[key] = new Element(subObj.elementRefptr as ElementNode);\n continue;\n } else if (subObj instanceof Element) {\n continue;\n }\n\n const transformedSubObj = transformWorkletInner(subObj, depth, ctx) as Record<string, ClosureValueType>;\n\n const isWorkletRef = '_wvid' in (subObj as object);\n if (isWorkletRef) {\n obj[key] = getFromWorkletRefMap(\n subObj as unknown as WorkletRefImpl<unknown>,\n );\n continue;\n }\n const isWorklet = '_wkltId' in subObj;\n if (isWorklet) {\n const isRootWorklet = subObj === ctx;\n const boundCtx = { ...transformedSubObj };\n // Keep the original context collectible. PrimJS traces WeakMap values even\n // when their keys are otherwise unreachable, so the cached function must not point back to its key.\n const boundWorklet: ((...args: unknown[]) => unknown) & { boundCtx?: object } = lynxWorkletImpl\n ._workletMap[(subObj as Worklet)._wkltId]!\n .bind(boundCtx);\n if (transformedSubObj !== subObj && obj === value && obj !== ctx) obj = copyAccessorCapture(obj);\n obj = replaceCapturedProperty(obj, value, key, boundWorklet);\n if (!isRootWorklet) {\n // Hydration needs the same context that the function already owns through bind().\n // The original nested context can disappear after its parent replaces it with this function.\n boundWorklet.boundCtx = boundCtx;\n }\n continue;\n }\n if (transformedSubObj !== subObj) {\n // The root context is runtime-owned: hydration must see its captured copy.\n if (obj === value && obj !== ctx) obj = copyAccessorCapture(obj);\n obj = replaceCapturedProperty(obj, value, key, transformedSubObj);\n }\n const isJsFn = '_jsFnId' in subObj;\n if (isJsFn) {\n (subObj as Record<string, ClosureValueType>)['_execId'] = (ctx as Worklet)._execId;\n lynxWorkletImpl._jsFunctionLifecycleManager?.addRef(\n (ctx as Worklet)._execId!,\n subObj,\n );\n continue;\n }\n }\n return obj;\n};\n\nfunction replaceCapturedProperty(\n obj: Record<string, ClosureValueType>,\n source: object,\n key: string,\n value: ClosureValueType,\n): Record<string, ClosureValueType> {\n const descriptor = Object.getOwnPropertyDescriptor(obj, key);\n if (descriptor?.get) {\n // Getters can refresh handles or method receivers. Materialize the captured\n // value without consuming the source getter or invoking its setter.\n const capturedDescriptor = {\n value,\n writable: true,\n enumerable: descriptor.enumerable!,\n configurable: descriptor.configurable!,\n };\n if (obj === source || !descriptor.configurable) {\n // Replace before defining the copy, including non-configurable getters.\n const descriptors = Object.getOwnPropertyDescriptors(obj);\n descriptors[key] = capturedDescriptor;\n return copyAccessorCapture(obj, descriptors);\n }\n Object.defineProperty(obj, key, capturedDescriptor);\n } else {\n obj[key] = value;\n }\n return obj;\n}\n\nfunction copyAccessorCapture(\n obj: Record<string, ClosureValueType>,\n descriptors: PropertyDescriptorMap = Object.getOwnPropertyDescriptors(obj),\n): Record<string, ClosureValueType> {\n // Copy descriptors without evaluating getters a second time. Array ancestors\n // retain their array identity when a nested accessor requires a captured copy.\n return Object.defineProperties(\n Array.isArray(obj)\n ? []\n : Object.create(Object.getPrototypeOf(obj) as object | null) as Record<string, ClosureValueType>,\n descriptors,\n ) as Record<string, ClosureValueType>;\n}\n\nfunction isMainThreadObjectDescriptor(\n value: object,\n): value is WorkletRefImpl<unknown> {\n const descriptor = value as Partial<WorkletRefImpl<unknown>>;\n return typeof descriptor._wvid === 'number'\n && typeof descriptor._type === 'string'\n && descriptor._type !== 'main-thread';\n}\nexport { initWorklet };\n"]}
|
package/runtime/package.json
CHANGED
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"build": "tsc6 --build",
|
|
19
19
|
"test": "pnpm run test:snapshot && pnpm run test:et",
|
|
20
20
|
"test:et": "vitest run -c __test__/element-template/vitest.config.ts --coverage",
|
|
21
|
-
"test:snapshot": "vitest run --coverage __test__/snapshot __test__/core __test__/worklet-runtime __test__/guardrails"
|
|
21
|
+
"test:snapshot": "vitest run --coverage __test__/snapshot __test__/core __test__/shared __test__/worklet-runtime __test__/guardrails"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
24
|
"@lynx-js/react": "workspace:*",
|
|
@@ -31,6 +31,5 @@
|
|
|
31
31
|
},
|
|
32
32
|
"peerDependencies": {
|
|
33
33
|
"@types/react": "^18.0.0 || ^19.0.0"
|
|
34
|
-
}
|
|
35
|
-
"showcase": "__fake_entry__/showcase.js"
|
|
34
|
+
}
|
|
36
35
|
}
|
|
@@ -8,7 +8,8 @@ import { isMainThreadObjectHandle } from './main-thread-object-handle-registry.j
|
|
|
8
8
|
* Preserve opaque main-thread object handles when the worklet transform narrows a
|
|
9
9
|
* captured member expression. Ordinary objects keep the transform's compact
|
|
10
10
|
* fallback shape. The transform evaluates that shape lazily with
|
|
11
|
-
* `captureMainThreadObject(source) ?? fallback
|
|
11
|
+
* `captureMainThreadObject(source) ?? fallback` (and guards optional-chain
|
|
12
|
+
* bases with `source == null ? source : ...`).
|
|
12
13
|
*
|
|
13
14
|
* @internal
|
|
14
15
|
*/
|
|
@@ -17,7 +17,7 @@ export { ComponentFromReactRuntime as Component } from './lynxComponent.js';
|
|
|
17
17
|
export { ComponentFromReactRuntime as PureComponent } from './lynxComponent.js';
|
|
18
18
|
export { createContext } from 'preact';
|
|
19
19
|
export { lazy } from 'preact/compat';
|
|
20
|
-
export { useState, useReducer, useEffect, useMemo, useCallback
|
|
20
|
+
export { useState, useReducer, useEffect, useMemo, useCallback } from '../hooks/react.js';
|
|
21
21
|
export { __runInJS, createRef, useRef };
|
|
22
22
|
|
|
23
23
|
/**
|
|
@@ -38,7 +38,7 @@ export interface UpdateGlobalPropsOptions {
|
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
export function isGlobalPropsEventMode(): boolean {
|
|
41
|
-
return
|
|
41
|
+
return lynx.__runtime_configs__?.globalPropsMode === 'event';
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
export function createGlobalProps<Data = GlobalProps>(
|
|
@@ -1,9 +1,132 @@
|
|
|
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
|
-
import type { DataProcessorDefinition, InitData, InitDataRaw } from '../lynx-api.js';
|
|
5
4
|
import { profileEnd, profileStart } from '../shared/profile.js';
|
|
6
5
|
|
|
6
|
+
/**
|
|
7
|
+
* The interface you can extends so that the `defaultDataProcessor` parameter can be customized
|
|
8
|
+
*
|
|
9
|
+
* Should be used with `lynx.registerDataProcessors`. See more examples at {@link Lynx.registerDataProcessors}.
|
|
10
|
+
*
|
|
11
|
+
* @public
|
|
12
|
+
*
|
|
13
|
+
* @group Types
|
|
14
|
+
*/
|
|
15
|
+
export interface InitDataRaw {}
|
|
16
|
+
/**
|
|
17
|
+
* The interface you can extends so that the `defaultDataProcessor` returning value can be customized
|
|
18
|
+
*
|
|
19
|
+
* Should be used with `lynx.registerDataProcessors`. See more examples at {@link Lynx.registerDataProcessors}.
|
|
20
|
+
*
|
|
21
|
+
* @public
|
|
22
|
+
*
|
|
23
|
+
* @group Types
|
|
24
|
+
*/
|
|
25
|
+
export interface InitData {}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* The data processors that registered with {@link Lynx.registerDataProcessors}.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
*
|
|
32
|
+
* Extending `dataProcessors` interface
|
|
33
|
+
*
|
|
34
|
+
* ```ts
|
|
35
|
+
* import type { DataProcessors as WellKnownDataProcessors } from '@lynx-js/react';
|
|
36
|
+
*
|
|
37
|
+
* declare module '@lynx-js/react' {
|
|
38
|
+
* interface DataProcessors extends WellKnownDataProcessors {
|
|
39
|
+
* foo(bar: string): number;
|
|
40
|
+
* }
|
|
41
|
+
* }
|
|
42
|
+
* ```
|
|
43
|
+
*
|
|
44
|
+
* Then you can use `lynx.registerDataProcessors` with types.
|
|
45
|
+
*
|
|
46
|
+
* ```js
|
|
47
|
+
* lynx.registerDataProcessors({
|
|
48
|
+
* dataProcessors: {
|
|
49
|
+
* foo(bar) {
|
|
50
|
+
* return 1;
|
|
51
|
+
* }
|
|
52
|
+
* }
|
|
53
|
+
* })
|
|
54
|
+
* ```
|
|
55
|
+
*
|
|
56
|
+
* @public
|
|
57
|
+
*
|
|
58
|
+
* @group Types
|
|
59
|
+
*/
|
|
60
|
+
export interface DataProcessors {
|
|
61
|
+
/**
|
|
62
|
+
* Optional processor to override screen metrics used by the app
|
|
63
|
+
*
|
|
64
|
+
* @param metrics - The physical screen dimensions in pixels
|
|
65
|
+
*
|
|
66
|
+
* @returns New screen dimensions to be used by the app
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
*
|
|
70
|
+
* ```ts
|
|
71
|
+
* lynx.registerDataProcessors({
|
|
72
|
+
* dataProcessors: {
|
|
73
|
+
* getScreenMetricsOverride: (metrics) => {
|
|
74
|
+
* // Force a specific aspect ratio
|
|
75
|
+
* return {
|
|
76
|
+
* width: metrics.width,
|
|
77
|
+
* height: metrics.width * (16/9)
|
|
78
|
+
* };
|
|
79
|
+
* }
|
|
80
|
+
* }
|
|
81
|
+
* });
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
84
|
+
getScreenMetricsOverride?(metrics: {
|
|
85
|
+
/**
|
|
86
|
+
* The physical pixel width of the screen
|
|
87
|
+
*/
|
|
88
|
+
width: number;
|
|
89
|
+
/**
|
|
90
|
+
* The physical pixel height of the screen
|
|
91
|
+
*/
|
|
92
|
+
height: number;
|
|
93
|
+
}): { width: number; height: number };
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Custom unknown data processors.
|
|
97
|
+
*
|
|
98
|
+
* @remarks
|
|
99
|
+
*
|
|
100
|
+
* You may extends the `DataProcessors` interface for better TypeScript types. See {@link DataProcessors}.
|
|
101
|
+
*/
|
|
102
|
+
[processorName: string]: (...args: any[]) => any;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Definition of DataProcessor(s)
|
|
107
|
+
* @public
|
|
108
|
+
*
|
|
109
|
+
* @group Types
|
|
110
|
+
*/
|
|
111
|
+
export interface DataProcessorDefinition {
|
|
112
|
+
/**
|
|
113
|
+
* You can custom input and output type of `defaultDataProcessor` by extends {@link InitDataRaw} and {@link InitData}
|
|
114
|
+
*
|
|
115
|
+
* Should be used with `lynx.registerDataProcessors`. See more examples at {@link Lynx.registerDataProcessors}.
|
|
116
|
+
*
|
|
117
|
+
* @param rawInitData - initData passed from native code
|
|
118
|
+
* @returns
|
|
119
|
+
* @public
|
|
120
|
+
*/
|
|
121
|
+
defaultDataProcessor?: (rawInitData: InitDataRaw) => InitData;
|
|
122
|
+
/**
|
|
123
|
+
* Should be used with `lynx.registerDataProcessors`. See more examples at {@link Lynx.registerDataProcessors}.
|
|
124
|
+
*
|
|
125
|
+
* @public
|
|
126
|
+
*/
|
|
127
|
+
dataProcessors?: DataProcessors;
|
|
128
|
+
}
|
|
129
|
+
|
|
7
130
|
// `true` only while the default data processor is running. `defaultDataProcessor` is
|
|
8
131
|
// invoked by the native side as a separate call *before* `renderPage` / `updatePage`,
|
|
9
132
|
// so a `markFirstScreenSyncReady()` made inside it must not sync the *previous* tree
|
|
@@ -26,8 +26,8 @@ export function registerDestroyTask(task: DestroyTask): () => void {
|
|
|
26
26
|
|
|
27
27
|
export function runDestroyTasks(): void {
|
|
28
28
|
const tasks = Array.from(destroyTasks);
|
|
29
|
+
destroyTasks.clear();
|
|
29
30
|
for (const task of tasks) {
|
|
30
31
|
task();
|
|
31
32
|
}
|
|
32
|
-
destroyTasks.clear();
|
|
33
33
|
}
|
package/runtime/src/document.ts
CHANGED
|
@@ -77,10 +77,4 @@ function setupDocument(_document: SnapshotDocumentAdapter = document): void {
|
|
|
77
77
|
};
|
|
78
78
|
}
|
|
79
79
|
|
|
80
|
-
// if (__JS__) {
|
|
81
|
-
// setupBackgroundDocument();
|
|
82
|
-
// } else if (__LEPUS__) {
|
|
83
|
-
// setupDocument();
|
|
84
|
-
// }
|
|
85
|
-
|
|
86
80
|
export { document, setupBackgroundDocument, setupDocument };
|
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
__etAttrPlanMap,
|
|
11
11
|
adaptRefAttrSlot,
|
|
12
12
|
adaptSpreadAttrSlot,
|
|
13
|
+
adaptTypedSpreadAttrSlot,
|
|
13
14
|
getMainThreadDynamicAttrSlotKinds,
|
|
14
15
|
} from '../runtime/template/attr-slot-plan.js';
|
|
15
16
|
import type { EtAttrAdapter, EtAttrAdapterContext, EtAttrPlan } from '../runtime/template/attr-slot-plan.js';
|
|
@@ -53,7 +54,7 @@ function queuePlannedRefAttributeSlotUpdates(
|
|
|
53
54
|
continue;
|
|
54
55
|
}
|
|
55
56
|
|
|
56
|
-
if (adapter === adaptSpreadAttrSlot) {
|
|
57
|
+
if (adapter === adaptSpreadAttrSlot || adapter === adaptTypedSpreadAttrSlot) {
|
|
57
58
|
const previousSpreadRef = getSpreadRefFromValue(previousRawSlots?.[attrSlotIndex]);
|
|
58
59
|
const nextSpreadRef = getSpreadRefFromValue(nextRawSlots?.[attrSlotIndex]);
|
|
59
60
|
if (previousSpreadRef === undefined && nextSpreadRef === undefined) {
|
|
@@ -122,6 +123,9 @@ export function getAttributeSlotUpdateOp(
|
|
|
122
123
|
attrSlotIndex: number,
|
|
123
124
|
): ElementTemplateUpdateOp {
|
|
124
125
|
const kind = getMainThreadDynamicAttrSlotKinds(templateType)?.get(attrSlotIndex);
|
|
126
|
+
if (kind === 'gesture') {
|
|
127
|
+
return ElementTemplateUpdateOps.setGesture;
|
|
128
|
+
}
|
|
125
129
|
if (kind === 'mt-event') {
|
|
126
130
|
return ElementTemplateUpdateOps.setMainThreadEvent;
|
|
127
131
|
}
|
|
@@ -67,6 +67,19 @@ export function cancelElementTemplateRemovedSubtreeCleanup(): void {
|
|
|
67
67
|
scheduledRemovedSubtreeCleanupTimers.clear();
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
+
function cleanupFailedElementTemplateCommit(
|
|
71
|
+
removedSubtreesAwaitingTeardown: BackgroundElementTemplateInstance[],
|
|
72
|
+
delayedRunOnMainThreadPayload: readonly { resolveId: number }[] | undefined,
|
|
73
|
+
): void {
|
|
74
|
+
if (delayedRunOnMainThreadPayload) {
|
|
75
|
+
dropFunctionCallReturnIds(delayedRunOnMainThreadPayload.map(data => data.resolveId));
|
|
76
|
+
}
|
|
77
|
+
clearPendingRefs();
|
|
78
|
+
resetGlobalCommitContext();
|
|
79
|
+
setPipeline(undefined);
|
|
80
|
+
scheduleElementTemplateRemovedSubtreeCleanup(removedSubtreesAwaitingTeardown);
|
|
81
|
+
}
|
|
82
|
+
|
|
70
83
|
function flushElementTemplateCommitChanges(): void {
|
|
71
84
|
const hasNativeOps = globalCommitContext.ops.length > 0;
|
|
72
85
|
const hasDelayedRunOnMainThread = delayedRunOnMainThreadData.length > 0;
|
|
@@ -127,12 +140,7 @@ function flushElementTemplateCommitChanges(): void {
|
|
|
127
140
|
delayedRunOnMainThreadData: delayedRunOnMainThreadPayload,
|
|
128
141
|
});
|
|
129
142
|
} catch (error) {
|
|
130
|
-
|
|
131
|
-
dropFunctionCallReturnIds(delayedRunOnMainThreadPayload.map(data => data.resolveId));
|
|
132
|
-
}
|
|
133
|
-
clearPendingRefs();
|
|
134
|
-
resetGlobalCommitContext();
|
|
135
|
-
scheduleElementTemplateRemovedSubtreeCleanup(removedSubtreesAwaitingTeardown);
|
|
143
|
+
cleanupFailedElementTemplateCommit(removedSubtreesAwaitingTeardown, delayedRunOnMainThreadPayload);
|
|
136
144
|
throw error;
|
|
137
145
|
}
|
|
138
146
|
|
|
@@ -162,12 +170,10 @@ export function installElementTemplateCommitHook(): void {
|
|
|
162
170
|
try {
|
|
163
171
|
sendMTRefInitValueToMainThread();
|
|
164
172
|
} catch (error) {
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
setPipeline(undefined);
|
|
170
|
-
scheduleElementTemplateRemovedSubtreeCleanup(removedSubtreesAwaitingTeardown);
|
|
173
|
+
cleanupFailedElementTemplateCommit(
|
|
174
|
+
takeRemovedSubtreesForPostDispatchTeardown(),
|
|
175
|
+
takeDelayedRunOnMainThreadData(),
|
|
176
|
+
);
|
|
171
177
|
throw error;
|
|
172
178
|
}
|
|
173
179
|
}
|
|
@@ -17,18 +17,21 @@ import { resetElementTemplateMainThreadFunctionRuntime } from '../runtime/templa
|
|
|
17
17
|
export function destroyElementTemplateBackgroundRuntime(): void {
|
|
18
18
|
resetElementTemplateHydrationListener();
|
|
19
19
|
cancelElementTemplateRemovedSubtreeCleanup();
|
|
20
|
-
|
|
21
|
-
withSyncEffectFlush(() => {
|
|
22
|
-
render(null, __root as unknown as ContainerNode);
|
|
23
|
-
});
|
|
24
|
-
// Run user cleanup before dropping the backend side tables; after clearRefState
|
|
25
|
-
// the raw ref ownership needed to detach callbacks is gone.
|
|
26
|
-
flushPendingRefs();
|
|
27
|
-
|
|
28
20
|
resetElementTemplateCommitState();
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
21
|
+
|
|
22
|
+
try {
|
|
23
|
+
withSyncEffectFlush(() => {
|
|
24
|
+
render(null, __root as unknown as ContainerNode);
|
|
25
|
+
});
|
|
26
|
+
// Run user cleanup before dropping the backend side tables; after clearRefState
|
|
27
|
+
// the raw ref ownership needed to detach callbacks is gone.
|
|
28
|
+
flushPendingRefs();
|
|
29
|
+
} finally {
|
|
30
|
+
resetElementTemplateCommitState();
|
|
31
|
+
resetElementTemplateBackgroundFunctionRuntime();
|
|
32
|
+
resetElementTemplateMainThreadFunctionRuntime();
|
|
33
|
+
clearEventState();
|
|
34
|
+
clearRefState();
|
|
35
|
+
backgroundElementTemplateInstanceManager.clear();
|
|
36
|
+
}
|
|
34
37
|
}
|
|
@@ -16,6 +16,8 @@ import { backgroundElementTemplateInstanceManager } from './manager.js';
|
|
|
16
16
|
import { isMainThreadFunction } from '../../core/main-thread-function.js';
|
|
17
17
|
import { isDirectOrDeepEqual } from '../../utils.js';
|
|
18
18
|
import { hydrationMap } from '../hydration-map.js';
|
|
19
|
+
import { isGestureSlotValue } from '../prop-adapters/gesture.js';
|
|
20
|
+
import { isMainThreadEventPropKey, isSpreadRecord } from '../prop-adapters/spread.js';
|
|
19
21
|
import { ElementTemplateUpdateOps } from '../protocol/opcodes.js';
|
|
20
22
|
import { ELEMENT_TEMPLATE_PAGE_HANDLE_ID, ELEMENT_TEMPLATE_PAGE_ROOT_SLOT_INDEX } from '../protocol/page.js';
|
|
21
23
|
import { elementTemplateIdentityKey, parseElementTemplateType } from '../protocol/template-type.js';
|
|
@@ -629,9 +631,30 @@ function shouldForceMainThreadHydrateSlot(
|
|
|
629
631
|
slotKind: MainThreadDynamicAttrKind | undefined,
|
|
630
632
|
value: SerializableValue | undefined,
|
|
631
633
|
): boolean {
|
|
634
|
+
if (slotKind === 'gesture') {
|
|
635
|
+
return value != null;
|
|
636
|
+
}
|
|
632
637
|
if (slotKind === 'mt-event') {
|
|
633
638
|
return isMTEventNativeWrapper(value);
|
|
634
639
|
}
|
|
640
|
+
if (slotKind === 'spread') {
|
|
641
|
+
if (!isSpreadRecord(value)) {
|
|
642
|
+
return false;
|
|
643
|
+
}
|
|
644
|
+
for (const key of Object.keys(value)) {
|
|
645
|
+
if (key === 'main-thread:ref') {
|
|
646
|
+
return true;
|
|
647
|
+
}
|
|
648
|
+
const entry = value[key];
|
|
649
|
+
if (key === 'main-thread:gesture' && isGestureSlotValue(entry)) {
|
|
650
|
+
return true;
|
|
651
|
+
}
|
|
652
|
+
if (isMainThreadEventPropKey(key) && isMTEventNativeWrapper(entry)) {
|
|
653
|
+
return true;
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
return false;
|
|
657
|
+
}
|
|
635
658
|
return slotKind === 'mt-ref'
|
|
636
659
|
&& (value == null || isMainThreadFunction((value as unknown as MTRefNativeWrapper).value));
|
|
637
660
|
}
|
|
@@ -1,13 +1,11 @@
|
|
|
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
|
-
// import { createContext, createElement } from 'preact/compat';
|
|
5
|
-
// import { useState } from 'preact/hooks';
|
|
6
4
|
import type { ComponentChild, ContainerNode } from 'preact';
|
|
7
5
|
import { render } from 'preact';
|
|
8
6
|
import type { ReactNode } from 'react';
|
|
9
7
|
|
|
10
|
-
import type { DataProcessorDefinition } from '../../lynx-
|
|
8
|
+
import type { DataProcessorDefinition } from '../../core/lynx-data-processors.js';
|
|
11
9
|
import { profileEnd, profileStart } from '../debug/profile.js';
|
|
12
10
|
import { __root } from '../runtime/page/root-instance.js';
|
|
13
11
|
|
|
@@ -31,7 +31,7 @@ export type FormattedElementTemplateUpdateCommand =
|
|
|
31
31
|
value: unknown;
|
|
32
32
|
}
|
|
33
33
|
| {
|
|
34
|
-
op: 'setMainThreadEvent' | 'setMainThreadRef';
|
|
34
|
+
op: 'setMainThreadEvent' | 'setMainThreadRef' | 'setGesture';
|
|
35
35
|
targetId: number;
|
|
36
36
|
attrSlotIndex: number;
|
|
37
37
|
value: unknown;
|
|
@@ -111,10 +111,13 @@ export function formatElementTemplateUpdateCommands(
|
|
|
111
111
|
|
|
112
112
|
case ElementTemplateUpdateOps.setMainThreadEvent:
|
|
113
113
|
case ElementTemplateUpdateOps.setMainThreadRef:
|
|
114
|
+
case ElementTemplateUpdateOps.setGesture:
|
|
114
115
|
result.push({
|
|
115
116
|
op: op === ElementTemplateUpdateOps.setMainThreadEvent
|
|
116
117
|
? 'setMainThreadEvent'
|
|
117
|
-
:
|
|
118
|
+
: (op === ElementTemplateUpdateOps.setMainThreadRef
|
|
119
|
+
? 'setMainThreadRef'
|
|
120
|
+
: 'setGesture'),
|
|
118
121
|
targetId: stream[index++] as number,
|
|
119
122
|
attrSlotIndex: stream[index++] as number,
|
|
120
123
|
value: stream[index++],
|
|
@@ -39,7 +39,7 @@ import { createGlobalProps } from '../core/globalProps.js';
|
|
|
39
39
|
import type { GlobalProps } from '../core/globalProps.js';
|
|
40
40
|
import { useLynxGlobalEventListener } from '../core/hooks/useLynxGlobalEventListener.js';
|
|
41
41
|
import { factory, withInitDataInState } from '../core/initData.js';
|
|
42
|
-
import type { InitData } from '../lynx-
|
|
42
|
+
import type { InitData } from '../core/lynx-data-processors.js';
|
|
43
43
|
import './native/index.js';
|
|
44
44
|
|
|
45
45
|
installComponentCompat();
|
|
@@ -141,4 +141,4 @@ export type {
|
|
|
141
141
|
MainThreadObjectType,
|
|
142
142
|
MainThreadObjectTypeDefinition,
|
|
143
143
|
} from '../core/main-thread-object.js';
|
|
144
|
-
export type { DataProcessorDefinition, DataProcessors, InitData, InitDataRaw } from '../lynx-
|
|
144
|
+
export type { DataProcessorDefinition, DataProcessors, InitData, InitDataRaw } from '../core/lynx-data-processors.js';
|