@lynx-js/react 0.126.2 → 0.128.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 +36 -0
- package/components/tsconfig.tsbuildinfo +1 -1
- package/docs/directives.md +90 -0
- package/docs/global-events.md +50 -0
- package/docs/import-attributes.md +43 -0
- package/docs/macros.md +285 -0
- package/package.json +7 -14
- package/refresh/.turbo/turbo-build.log +2 -2
- package/refresh/dist/index.js +26 -6
- package/refresh/package.json +1 -1
- package/runtime/__test__/core/main-thread-object.test.js +149 -0
- package/runtime/__test__/element-template/fixtures/background/main-thread-function/run-on-main-thread/index.tsx +26 -3
- package/runtime/__test__/element-template/imports/main-thread-object-api.test.ts +10 -0
- package/runtime/__test__/element-template/internal/legacy-internal-guardrail.test.ts +4 -1
- package/runtime/__test__/element-template/runtime/background/event/compiled-fixtures.test.tsx +39 -48
- package/runtime/__test__/element-template/runtime/background/main-thread-function/compiled-fixtures.test.tsx +11 -9
- package/runtime/__test__/element-template/runtime/render/render-transform.contract.test.ts +6 -3
- package/runtime/__test__/element-template/test-utils/mock/globals.js +6 -0
- package/runtime/__test__/element-template/vitest.config.ts +4 -0
- package/runtime/__test__/snapshot/ctxNotFound.test.ts +271 -0
- package/runtime/__test__/snapshot/event.test.jsx +7 -7
- package/runtime/__test__/snapshot/lazy.test.js +73 -1
- package/runtime/__test__/snapshot/lynx/portals.test.jsx +75 -37
- package/runtime/__test__/snapshot/snapshotPatch.test.jsx +59 -47
- package/runtime/__test__/snapshot/spread.test.jsx +10 -10
- package/runtime/__test__/snapshot/worklet/main-thread-object.test.jsx +306 -0
- package/runtime/__test__/snapshot/worklet/workletRef.test.jsx +1 -0
- package/runtime/__test__/worklet-runtime/initEntry.test.js +109 -0
- package/runtime/__test__/worklet-runtime/mainThreadObject.test.js +182 -0
- package/runtime/__test__/worklet-runtime/object-methods.test.js +59 -0
- package/runtime/__test__/worklet-runtime/workletRef.test.js +362 -2
- package/runtime/__test__/worklet-runtime/workletRuntime.test.js +246 -1
- package/runtime/lazy/compat.js +2 -0
- package/runtime/lazy/element-template-internal.js +1 -1
- package/runtime/lazy/element-template.js +2 -0
- package/runtime/lazy/internal.js +2 -1
- package/runtime/lazy/react.js +2 -0
- package/runtime/lib/core/background-function/exec-map.js.map +1 -1
- package/runtime/lib/core/background-function/handle.js.map +1 -1
- package/runtime/lib/core/background-function/run-on-background.d.ts +16 -0
- package/runtime/lib/core/background-function/run-on-background.js +16 -0
- package/runtime/lib/core/background-function/run-on-background.js.map +1 -1
- package/runtime/lib/core/capture-main-thread-object.d.ts +1 -0
- package/runtime/lib/core/capture-main-thread-object.js +16 -0
- package/runtime/lib/core/capture-main-thread-object.js.map +1 -0
- package/runtime/lib/core/commit-context.js.map +1 -1
- package/runtime/lib/core/compat/legacy-react-runtime.js.map +1 -1
- package/runtime/lib/core/compat/lynxComponent.js.map +1 -1
- package/runtime/lib/core/component.js.map +1 -1
- package/runtime/lib/core/forceRootRender.js.map +1 -1
- package/runtime/lib/core/globalProps.d.ts +2 -0
- package/runtime/lib/core/globalProps.js.map +1 -1
- package/runtime/lib/core/hooks/mainThread.js.map +1 -1
- package/runtime/lib/core/hooks/mainThreadImpl.js.map +1 -1
- package/runtime/lib/core/hooks/react.d.ts +4 -0
- package/runtime/lib/core/hooks/react.js +4 -0
- package/runtime/lib/core/hooks/react.js.map +1 -1
- package/runtime/lib/core/hooks/useLynxGlobalEventListener.d.ts +2 -0
- package/runtime/lib/core/hooks/useLynxGlobalEventListener.js +2 -0
- package/runtime/lib/core/hooks/useLynxGlobalEventListener.js.map +1 -1
- package/runtime/lib/core/initData.d.ts +2 -0
- package/runtime/lib/core/initData.js +2 -0
- package/runtime/lib/core/initData.js.map +1 -1
- package/runtime/lib/core/lynx/dynamic-import.js.map +1 -1
- package/runtime/lib/core/lynx/lazy-bundle.js.map +1 -1
- package/runtime/lib/core/lynx/runtime-backend.js.map +1 -1
- package/runtime/lib/core/lynx/runtime-version.js.map +1 -1
- package/runtime/lib/core/lynx-data-processors.js.map +1 -1
- package/runtime/lib/core/lynx-page-data.js.map +1 -1
- package/runtime/lib/core/lynx-update-data.js.map +1 -1
- package/runtime/lib/core/main-thread-function.js.map +1 -1
- package/runtime/lib/core/main-thread-object-handle-registry.d.ts +3 -0
- package/runtime/lib/core/main-thread-object-handle-registry.js +17 -0
- package/runtime/lib/core/main-thread-object-handle-registry.js.map +1 -0
- package/runtime/lib/core/main-thread-object.d.ts +77 -0
- package/runtime/lib/core/main-thread-object.js +258 -0
- package/runtime/lib/core/main-thread-object.js.map +1 -0
- package/runtime/lib/core/main-thread-ref-id.d.ts +1 -0
- package/runtime/lib/core/main-thread-ref-id.js +14 -0
- package/runtime/lib/core/main-thread-ref-id.js.map +1 -0
- package/runtime/lib/core/main-thread-ref-init-value.d.ts +1 -1
- package/runtime/lib/core/main-thread-ref-init-value.js +4 -2
- package/runtime/lib/core/main-thread-ref-init-value.js.map +1 -1
- package/runtime/lib/core/main-thread-ref.d.ts +4 -0
- package/runtime/lib/core/main-thread-ref.js +5 -8
- package/runtime/lib/core/main-thread-ref.js.map +1 -1
- package/runtime/lib/core/mts-capability.js.map +1 -1
- package/runtime/lib/core/performance.js.map +1 -1
- package/runtime/lib/core/ref.js.map +1 -1
- package/runtime/lib/core/reload-version.js.map +1 -1
- package/runtime/lib/core/runtime-destroy.js.map +1 -1
- package/runtime/lib/core/thread-function-call/main-thread.js.map +1 -1
- package/runtime/lib/core/thread-function-call/return-value.js.map +1 -1
- package/runtime/lib/document.js.map +1 -1
- package/runtime/lib/element-template/background/attr-slots.js.map +1 -1
- package/runtime/lib/element-template/background/commit-context.js.map +1 -1
- package/runtime/lib/element-template/background/commit-hook.js.map +1 -1
- package/runtime/lib/element-template/background/destroy.js.map +1 -1
- package/runtime/lib/element-template/background/document.js.map +1 -1
- package/runtime/lib/element-template/background/hydrate.js.map +1 -1
- package/runtime/lib/element-template/background/hydration-listener.js.map +1 -1
- package/runtime/lib/element-template/background/instance.js.map +1 -1
- package/runtime/lib/element-template/background/manager.js.map +1 -1
- package/runtime/lib/element-template/background/page-root-hydrate.js.map +1 -1
- package/runtime/lib/element-template/background/render-scope.js.map +1 -1
- package/runtime/lib/element-template/client/root.js.map +1 -1
- package/runtime/lib/element-template/debug/alog.js.map +1 -1
- package/runtime/lib/element-template/debug/elementPAPICall.js.map +1 -1
- package/runtime/lib/element-template/debug/profile.js.map +1 -1
- package/runtime/lib/element-template/hydration-map.js.map +1 -1
- package/runtime/lib/element-template/index.d.ts +2 -0
- package/runtime/lib/element-template/index.js +1 -0
- package/runtime/lib/element-template/index.js.map +1 -1
- package/runtime/lib/element-template/internal.d.ts +1 -1
- package/runtime/lib/element-template/internal.js +1 -1
- package/runtime/lib/element-template/internal.js.map +1 -1
- package/runtime/lib/element-template/jsx-dev-runtime/index.js.map +1 -1
- package/runtime/lib/element-template/jsx-runtime/index.js.map +1 -1
- package/runtime/lib/element-template/lynx/env.js.map +1 -1
- package/runtime/lib/element-template/lynx/performance.js.map +1 -1
- package/runtime/lib/element-template/native/callDestroyLifetimeFun.js.map +1 -1
- package/runtime/lib/element-template/native/index.js.map +1 -1
- package/runtime/lib/element-template/native/main-thread-api.js.map +1 -1
- package/runtime/lib/element-template/native/mts-destroy.js.map +1 -1
- package/runtime/lib/element-template/native/patch-listener.js.map +1 -1
- package/runtime/lib/element-template/native/reload-background.js.map +1 -1
- package/runtime/lib/element-template/native/reload-main-thread.js.map +1 -1
- package/runtime/lib/element-template/prop-adapters/event-value.js.map +1 -1
- package/runtime/lib/element-template/prop-adapters/event.js.map +1 -1
- package/runtime/lib/element-template/prop-adapters/ref.js.map +1 -1
- package/runtime/lib/element-template/prop-adapters/spread.js.map +1 -1
- package/runtime/lib/element-template/protocol/lifecycle-constant.js.map +1 -1
- package/runtime/lib/element-template/protocol/opcodes.js.map +1 -1
- package/runtime/lib/element-template/protocol/page.js.map +1 -1
- package/runtime/lib/element-template/protocol/template-type.js.map +1 -1
- package/runtime/lib/element-template/protocol/types.d.ts +1 -1
- package/runtime/lib/element-template/protocol/types.js.map +1 -1
- package/runtime/lib/element-template/protocol/update-event.js.map +1 -1
- package/runtime/lib/element-template/runtime/list/list.js.map +1 -1
- package/runtime/lib/element-template/runtime/page/authored-page.js.map +1 -1
- package/runtime/lib/element-template/runtime/page/page.js.map +1 -1
- package/runtime/lib/element-template/runtime/page/root-instance.js.map +1 -1
- package/runtime/lib/element-template/runtime/patch.js.map +1 -1
- package/runtime/lib/element-template/runtime/render/create-rendered-host.js.map +1 -1
- package/runtime/lib/element-template/runtime/render/host.js.map +1 -1
- package/runtime/lib/element-template/runtime/render/render-components.js.map +1 -1
- package/runtime/lib/element-template/runtime/render/render-direct.js.map +1 -1
- package/runtime/lib/element-template/runtime/render/render-main-thread.js.map +1 -1
- package/runtime/lib/element-template/runtime/template/attr-slot-plan.js.map +1 -1
- package/runtime/lib/element-template/runtime/template/handle.js.map +1 -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.js.map +1 -1
- package/runtime/lib/element-template/runtime/template/main-thread-event-ctx.js.map +1 -1
- package/runtime/lib/element-template/runtime/template/main-thread-function.js.map +1 -1
- package/runtime/lib/element-template/runtime/template/main-thread-ref-ctx.js.map +1 -1
- package/runtime/lib/element-template/runtime/template/registry.js.map +1 -1
- package/runtime/lib/element-template/runtime/template/typed-attributes.js.map +1 -1
- package/runtime/lib/element-template/runtime-marker.js.map +1 -1
- package/runtime/lib/index.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 +34 -0
- package/runtime/lib/lynx-api.js +21 -0
- package/runtime/lib/lynx-api.js.map +1 -1
- package/runtime/lib/lynx.js +4 -1
- package/runtime/lib/lynx.js.map +1 -1
- package/runtime/lib/root.js.map +1 -1
- package/runtime/lib/runtime-marker.js.map +1 -1
- package/runtime/lib/shared/attribute-name.js.map +1 -1
- package/runtime/lib/shared/component-stack.js.map +1 -1
- package/runtime/lib/shared/index-map.js.map +1 -1
- package/runtime/lib/shared/profile.js.map +1 -1
- package/runtime/lib/shared/render-constants.js.map +1 -1
- package/runtime/lib/snapshot/alog/elementPAPICall.js.map +1 -1
- package/runtime/lib/snapshot/alog/index.js.map +1 -1
- package/runtime/lib/snapshot/alog/render.js.map +1 -1
- package/runtime/lib/snapshot/compat/componentIs.js.map +1 -1
- package/runtime/lib/snapshot/debug/debug.js.map +1 -1
- package/runtime/lib/snapshot/debug/describeInvalidValue.js.map +1 -1
- package/runtime/lib/snapshot/debug/formatPatch.js.map +1 -1
- package/runtime/lib/snapshot/debug/printSnapshot.js.map +1 -1
- package/runtime/lib/snapshot/debug/profileHooks.js.map +1 -1
- package/runtime/lib/snapshot/debug/vnodeSource.js.map +1 -1
- package/runtime/lib/snapshot/gesture/processGesture.js.map +1 -1
- package/runtime/lib/snapshot/gesture/processGestureBagkround.js.map +1 -1
- package/runtime/lib/snapshot/gesture/types.js.map +1 -1
- package/runtime/lib/snapshot/index.js.map +1 -1
- package/runtime/lib/snapshot/lifecycle/constant.js.map +1 -1
- package/runtime/lib/snapshot/lifecycle/destroy.js.map +1 -1
- package/runtime/lib/snapshot/lifecycle/event/delayEvents.js.map +1 -1
- package/runtime/lib/snapshot/lifecycle/event/delayLifecycleEvents.js.map +1 -1
- package/runtime/lib/snapshot/lifecycle/event/firstScreenSync.js.map +1 -1
- package/runtime/lib/snapshot/lifecycle/isRendering.js.map +1 -1
- package/runtime/lib/snapshot/lifecycle/patch/commit.js.map +1 -1
- package/runtime/lib/snapshot/lifecycle/patch/error.d.ts +11 -1
- package/runtime/lib/snapshot/lifecycle/patch/error.js +24 -16
- package/runtime/lib/snapshot/lifecycle/patch/error.js.map +1 -1
- package/runtime/lib/snapshot/lifecycle/patch/globalState.js.map +1 -1
- package/runtime/lib/snapshot/lifecycle/patch/isMainThreadHydrating.js.map +1 -1
- package/runtime/lib/snapshot/lifecycle/patch/nodesRefApply.js.map +1 -1
- package/runtime/lib/snapshot/lifecycle/patch/snapshotPatch.js.map +1 -1
- package/runtime/lib/snapshot/lifecycle/patch/snapshotPatchApply.d.ts +1 -1
- package/runtime/lib/snapshot/lifecycle/patch/snapshotPatchApply.js +29 -7
- package/runtime/lib/snapshot/lifecycle/patch/snapshotPatchApply.js.map +1 -1
- package/runtime/lib/snapshot/lifecycle/patch/updateMainThread.js +2 -2
- package/runtime/lib/snapshot/lifecycle/patch/updateMainThread.js.map +1 -1
- package/runtime/lib/snapshot/lifecycle/ref/delay.js.map +1 -1
- package/runtime/lib/snapshot/lifecycle/reload.js.map +1 -1
- package/runtime/lib/snapshot/lifecycle/render.js.map +1 -1
- package/runtime/lib/snapshot/list/list.js.map +1 -1
- package/runtime/lib/snapshot/list/listUpdateInfo.js.map +1 -1
- package/runtime/lib/snapshot/list/pendingListUpdates.js.map +1 -1
- package/runtime/lib/snapshot/lynx/calledByNative.js.map +1 -1
- package/runtime/lib/snapshot/lynx/children.d.ts +2 -0
- package/runtime/lib/snapshot/lynx/children.js.map +1 -1
- package/runtime/lib/snapshot/lynx/element.d.ts +8 -0
- package/runtime/lib/snapshot/lynx/element.js +4 -0
- package/runtime/lib/snapshot/lynx/element.js.map +1 -1
- package/runtime/lib/snapshot/lynx/env.js.map +1 -1
- package/runtime/lib/snapshot/lynx/injectLepusMethods.js.map +1 -1
- package/runtime/lib/snapshot/lynx/lazyBundleConstants.js.map +1 -1
- package/runtime/lib/snapshot/lynx/nodesRef.js.map +1 -1
- package/runtime/lib/snapshot/lynx/performance.js.map +1 -1
- package/runtime/lib/snapshot/lynx/portals.js.map +1 -1
- package/runtime/lib/snapshot/lynx/portalsPending.js.map +1 -1
- package/runtime/lib/snapshot/lynx/prepareLazyBundleMTS.js.map +1 -1
- package/runtime/lib/snapshot/lynx/runWithForce.js.map +1 -1
- package/runtime/lib/snapshot/lynx/suspense.js.map +1 -1
- package/runtime/lib/snapshot/lynx/tt.js.map +1 -1
- package/runtime/lib/snapshot/renderToOpcodes/hydrate.js.map +1 -1
- package/runtime/lib/snapshot/renderToOpcodes/index.js.map +1 -1
- package/runtime/lib/snapshot/renderToOpcodes/opcodes.js.map +1 -1
- package/runtime/lib/snapshot/snapshot/backgroundSnapshot.js.map +1 -1
- package/runtime/lib/snapshot/snapshot/constants.js.map +1 -1
- package/runtime/lib/snapshot/snapshot/definition.js.map +1 -1
- package/runtime/lib/snapshot/snapshot/dynamicPartType.js.map +1 -1
- package/runtime/lib/snapshot/snapshot/event.js.map +1 -1
- package/runtime/lib/snapshot/snapshot/gesture.js.map +1 -1
- package/runtime/lib/snapshot/snapshot/index.js.map +1 -1
- package/runtime/lib/snapshot/snapshot/list.js.map +1 -1
- package/runtime/lib/snapshot/snapshot/platformInfo.js.map +1 -1
- package/runtime/lib/snapshot/snapshot/reconstructInstanceTree.js.map +1 -1
- package/runtime/lib/snapshot/snapshot/ref.js.map +1 -1
- package/runtime/lib/snapshot/snapshot/snapshot.js.map +1 -1
- package/runtime/lib/snapshot/snapshot/snapshotCreatorMap.js.map +1 -1
- package/runtime/lib/snapshot/snapshot/snapshotInstanceHydrationMap.js.map +1 -1
- package/runtime/lib/snapshot/snapshot/snapshotInstanceManager.js.map +1 -1
- package/runtime/lib/snapshot/snapshot/spread.js.map +1 -1
- package/runtime/lib/snapshot/snapshot/types.js.map +1 -1
- package/runtime/lib/snapshot/snapshot/utils.js.map +1 -1
- package/runtime/lib/snapshot/snapshot/workletEvent.js.map +1 -1
- package/runtime/lib/snapshot/snapshot/workletRef.js.map +1 -1
- package/runtime/lib/snapshot/worklet/call/runOnMainThread.d.ts +2 -0
- package/runtime/lib/snapshot/worklet/call/runOnMainThread.js +2 -0
- package/runtime/lib/snapshot/worklet/call/runOnMainThread.js.map +1 -1
- package/runtime/lib/snapshot/worklet/ctx.js.map +1 -1
- package/runtime/lib/snapshot/worklet/destroy.js.map +1 -1
- package/runtime/lib/snapshot/worklet/functionality.js.map +1 -1
- package/runtime/lib/snapshot/worklet/hmr.js.map +1 -1
- package/runtime/lib/snapshot/worklet/ref/updateInitValue.js.map +1 -1
- package/runtime/lib/tsconfig.tsbuildinfo +1 -1
- package/runtime/lib/utils.js.map +1 -1
- package/runtime/lib/worklet-runtime/api/animation/animation.js.map +1 -1
- package/runtime/lib/worklet-runtime/api/animation/effect.js.map +1 -1
- package/runtime/lib/worklet-runtime/api/element.js.map +1 -1
- package/runtime/lib/worklet-runtime/api/lepusQuerySelector.js.map +1 -1
- package/runtime/lib/worklet-runtime/api/lynxApi.js.map +1 -1
- package/runtime/lib/worklet-runtime/bindings/bindings.d.ts +3 -3
- package/runtime/lib/worklet-runtime/bindings/bindings.js +9 -1
- package/runtime/lib/worklet-runtime/bindings/bindings.js.map +1 -1
- package/runtime/lib/worklet-runtime/bindings/events.js.map +1 -1
- package/runtime/lib/worklet-runtime/bindings/index.d.ts +0 -1
- package/runtime/lib/worklet-runtime/bindings/index.js +0 -1
- package/runtime/lib/worklet-runtime/bindings/index.js.map +1 -1
- package/runtime/lib/worklet-runtime/bindings/observers.js.map +1 -1
- package/runtime/lib/worklet-runtime/bindings/types.d.ts +3 -6
- package/runtime/lib/worklet-runtime/bindings/types.js.map +1 -1
- package/runtime/lib/worklet-runtime/delayRunOnBackground.js.map +1 -1
- package/runtime/lib/worklet-runtime/delayWorkletEvent.js.map +1 -1
- package/runtime/lib/worklet-runtime/eomImpl.js.map +1 -1
- package/runtime/lib/worklet-runtime/eventPropagation.js.map +1 -1
- package/runtime/lib/worklet-runtime/global.js.map +1 -1
- package/runtime/lib/worklet-runtime/hydrate.js +26 -7
- package/runtime/lib/worklet-runtime/hydrate.js.map +1 -1
- package/runtime/lib/worklet-runtime/index.js +6 -0
- package/runtime/lib/worklet-runtime/index.js.map +1 -1
- package/runtime/lib/worklet-runtime/jsFunctionLifecycle.js.map +1 -1
- package/runtime/lib/worklet-runtime/listeners.js.map +1 -1
- package/runtime/lib/worklet-runtime/mainThreadObject.d.ts +8 -0
- package/runtime/lib/worklet-runtime/mainThreadObject.js +67 -0
- package/runtime/lib/worklet-runtime/mainThreadObject.js.map +1 -0
- package/runtime/lib/worklet-runtime/runOnMainThread.js.map +1 -1
- package/runtime/lib/worklet-runtime/utils/mainThreadFlushLoopGuard.js.map +1 -1
- package/runtime/lib/worklet-runtime/utils/profile.js.map +1 -1
- package/runtime/lib/worklet-runtime/utils/version.js.map +1 -1
- package/runtime/lib/worklet-runtime/workletRef.d.ts +11 -7
- package/runtime/lib/worklet-runtime/workletRef.js +72 -9
- package/runtime/lib/worklet-runtime/workletRef.js.map +1 -1
- package/runtime/lib/worklet-runtime/workletRuntime.js +68 -9
- package/runtime/lib/worklet-runtime/workletRuntime.js.map +1 -1
- package/runtime/package.json +2 -3
- package/runtime/src/core/background-function/run-on-background.ts +16 -0
- package/runtime/src/core/capture-main-thread-object.ts +17 -0
- package/runtime/src/core/globalProps.ts +2 -0
- package/runtime/src/core/hooks/react.ts +4 -0
- package/runtime/src/core/hooks/useLynxGlobalEventListener.ts +2 -0
- package/runtime/src/core/initData.ts +2 -0
- package/runtime/src/core/main-thread-object-handle-registry.ts +25 -0
- package/runtime/src/core/main-thread-object.ts +380 -0
- package/runtime/src/core/main-thread-ref-id.ts +16 -0
- package/runtime/src/core/main-thread-ref-init-value.ts +12 -4
- package/runtime/src/core/main-thread-ref.ts +7 -8
- package/runtime/src/element-template/background/commit-hook.ts +1 -1
- package/runtime/src/element-template/index.ts +6 -0
- package/runtime/src/element-template/internal.ts +2 -1
- package/runtime/src/element-template/protocol/types.ts +1 -1
- package/runtime/src/internal.ts +1 -1
- package/runtime/src/lynx-api.ts +38 -0
- package/runtime/src/lynx.ts +5 -1
- package/runtime/src/snapshot/lifecycle/patch/error.ts +36 -19
- package/runtime/src/snapshot/lifecycle/patch/snapshotPatchApply.ts +29 -7
- package/runtime/src/snapshot/lifecycle/patch/updateMainThread.ts +2 -2
- package/runtime/src/snapshot/lynx/children.ts +2 -0
- package/runtime/src/snapshot/lynx/element.ts +8 -0
- package/runtime/src/snapshot/worklet/call/runOnMainThread.ts +2 -0
- package/runtime/src/snapshot/worklet/ref/updateInitValue.ts +1 -1
- package/runtime/src/worklet-runtime/bindings/bindings.ts +17 -2
- package/runtime/src/worklet-runtime/bindings/index.ts +0 -1
- package/runtime/src/worklet-runtime/bindings/types.ts +7 -11
- package/runtime/src/worklet-runtime/hydrate.ts +43 -10
- package/runtime/src/worklet-runtime/index.ts +7 -0
- package/runtime/src/worklet-runtime/mainThreadObject.ts +117 -0
- package/runtime/src/worklet-runtime/workletRef.ts +120 -19
- package/runtime/src/worklet-runtime/workletRuntime.ts +83 -11
- package/runtime/tsconfig.json +2 -0
- package/runtime/vitest.config.ts +4 -0
- package/testing-library/.turbo/turbo-build.log +11 -11
- package/testing-library/dist/env/index.js +3 -15
- package/testing-library/dist/index.d.ts +165 -2
- package/testing-library/dist/plugins/index.js +10 -0
- package/testing-library/dist/rstest-config.js +15 -0
- package/testing-library/dist/setupFiles/common/worklet-runtime-init.js +11 -0
- package/testing-library/package.json +2 -1
- package/testing-library/rstest.config.ts +3 -0
- package/testing-library/src/__tests__/lynx.test.jsx +1 -1
- package/testing-library/src/__tests__/rstest-config.test.js +34 -1
- package/testing-library/src/__tests__/worklet.test.jsx +87 -33
- package/testing-library/src/plugins/vitest.ts +5 -1
- package/testing-library/src/rstest-config.ts +17 -1
- package/testing-library/src/setupFiles/common/worklet-runtime-init.js +22 -0
- package/testing-library/tsconfig.docs.json +9 -0
- package/testing-library/typedoc.json +22 -0
- package/transform/.turbo/turbo-build$colon$wasm.log +135 -73
- package/transform/__test__/defines.spec.js +80 -12
- package/transform/__test__/fixture.spec.js +231 -71
- package/transform/__test__/object-methods.spec.js +82 -0
- package/transform/crates/swc_plugin_worklet/decl_collect.rs +10 -0
- package/transform/crates/swc_plugin_worklet/extract_ident.rs +14 -0
- package/transform/crates/swc_plugin_worklet/gen_stmt.rs +228 -13
- package/transform/crates/swc_plugin_worklet/lib.rs +599 -150
- package/transform/crates/swc_plugin_worklet/napi.rs +10 -1
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_capture_env_js.js +8 -1
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_capture_env_lepus.js +12 -7
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_expose_object_method_capture_channels_js.js +27 -0
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_expose_object_method_capture_channels_lepus.js +43 -0
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_ident_from_this_lepus.js +2 -4
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_2_js.js +16 -14
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_2_lepus.js +18 -18
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_3_lepus.js +3 -5
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_4_lepus.js +2 -4
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_js.js +7 -5
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_lepus.js +9 -9
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_not_capture_computed_object_method_key_lepus.js +22 -0
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_not_capture_globals.js +2 -4
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_not_capture_object_method_local_decls_lepus.js +14 -0
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_not_capture_type_annotations.js +2 -4
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_not_destructure_from_closure.js +2 -4
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_not_extract_catch_clause_params.js +2 -4
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_not_extract_idents_inside_of_ctx.js +2 -4
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_not_transform_recursively.js +2 -4
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_preserve_main_thread_objects_in_class_js.js +42 -0
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_preserve_main_thread_objects_in_class_lepus.js +58 -0
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_skip_shared_identifiers_lepus.js +2 -4
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_arrow_function.js +2 -4
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_fn_decl_lepus.js +2 -4
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_function_expr.js +2 -4
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_in_class_lepus.js +2 -4
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_in_class_property_lepus.js +2 -4
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_in_class_static_lepus.js +2 -4
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_in_class_static_property_lepus.js +2 -4
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_js.js +3 -1
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_js_fn_in_run_on_js_lepus.js +2 -4
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_lepus.js +5 -5
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_lepus_alias.js +2 -4
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_lepus_general.js +2 -4
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_lepus_general_mixed.js +2 -4
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_multiple_worklets.js +3 -5
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_multiple_worklets_in_func.js +3 -5
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_object_methods_js.js +9 -0
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_object_methods_lepus.js +14 -0
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_ui_worklet_lepus.js +2 -4
- package/transform/dist/wasm.cjs +1 -1
- package/transform/index.d.ts +25 -1
- package/transform/rspack-napi/tsconfig.tsbuildinfo +1 -1
- package/transform/src/lib.rs +193 -23
- package/transform/swc-plugin-reactlynx/.turbo/turbo-build.log +63 -467
- package/transform/swc-plugin-reactlynx/swc_plugin_reactlynx.wasm +0 -0
- package/transform/swc-plugin-reactlynx-compat/.turbo/turbo-build.log +340 -28
- package/transform/swc-plugin-reactlynx-compat/swc_plugin_reactlynx_compat.wasm +0 -0
- package/transform/vitest.config.ts +5 -1
- package/types/react.docs.d.ts +130 -11
- package/runtime/lib/worklet-runtime/bindings/loadRuntime.d.ts +0 -8
- package/runtime/lib/worklet-runtime/bindings/loadRuntime.js +0 -23
- package/runtime/lib/worklet-runtime/bindings/loadRuntime.js.map +0 -1
- package/runtime/src/worklet-runtime/bindings/loadRuntime.ts +0 -25
- package/runtime/worklet-runtime/dev.js +0 -638
- package/runtime/worklet-runtime/main.js +0 -1
- package/testing-library/node_modules/.bin/rsbuild +0 -68
- package/testing-library/node_modules/.bin/rspeedy +0 -68
- package/testing-library/node_modules/.bin/rstest +0 -68
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_add_worklet_runtime_ident_with_inner_ident.js +0 -13
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_add_worklet_runtime_ident_with_outer_ident.js +0 -13
- package/transform/node_modules/.bin/esbuild +0 -59
- package/transform/node_modules/.bin/napi +0 -68
|
@@ -1,15 +1,19 @@
|
|
|
1
1
|
import { Element } from './api/element.js';
|
|
2
|
-
import type { WorkletRef, WorkletRefId, WorkletRefImpl } from './bindings/types.js';
|
|
2
|
+
import type { MainThreadRefInitValuePatch, Worklet, WorkletRef, WorkletRefId, WorkletRefImpl } from './bindings/types.js';
|
|
3
|
+
import type { MainThreadObjectFactory } from './mainThreadObject.js';
|
|
3
4
|
interface RefImpl {
|
|
4
|
-
_workletRefMap: Record<WorkletRefId,
|
|
5
|
-
_firstScreenWorkletRefMap: Record<WorkletRefId,
|
|
5
|
+
_workletRefMap: Record<WorkletRefId, object>;
|
|
6
|
+
_firstScreenWorkletRefMap: Record<WorkletRefId, object>;
|
|
6
7
|
updateWorkletRef(refImpl: WorkletRefImpl<Element | null>, element: ElementNode | null): void;
|
|
7
|
-
updateWorkletRefInitValueChanges(patch:
|
|
8
|
+
updateWorkletRefInitValueChanges(patch: MainThreadRefInitValuePatch): void;
|
|
9
|
+
registerMainThreadObjectType(type: string, create: MainThreadObjectFactory | Worklet): void;
|
|
8
10
|
clearFirstScreenWorkletRefMap(): void;
|
|
9
11
|
}
|
|
10
12
|
declare function initWorkletRef(): RefImpl;
|
|
11
13
|
declare const createWorkletRef: <T>(id: WorkletRefId, value: T) => WorkletRef<T>;
|
|
12
|
-
declare
|
|
14
|
+
declare function isHydratedWorkletValue(value: unknown): value is object;
|
|
15
|
+
declare const getFromWorkletRefMap: (refImpl: WorkletRefImpl<unknown>) => object | undefined;
|
|
13
16
|
declare function removeValueFromWorkletRefMap(id: WorkletRefId): void;
|
|
14
|
-
declare function
|
|
15
|
-
|
|
17
|
+
declare function hydrateWorkletValue(handle: WorkletRefImpl<unknown>, value: object): void;
|
|
18
|
+
declare function updateWorkletRefInitValueChanges(patch: MainThreadRefInitValuePatch): void;
|
|
19
|
+
export { type RefImpl, createWorkletRef, initWorkletRef, getFromWorkletRefMap, removeValueFromWorkletRefMap, hydrateWorkletValue, isHydratedWorkletValue, updateWorkletRefInitValueChanges, };
|
|
@@ -2,10 +2,12 @@
|
|
|
2
2
|
// Licensed under the Apache License Version 2.0 that can be found in the
|
|
3
3
|
// LICENSE file in the root directory of this source tree.
|
|
4
4
|
import { Element } from './api/element.js';
|
|
5
|
+
import { assertCompatibleMainThreadObject, createMainThreadObject, initMainThreadObjects, isRealizedMainThreadObject, registerMainThreadObjectType, } from './mainThreadObject.js';
|
|
5
6
|
import { mainThreadFlushLoopMark } from './utils/mainThreadFlushLoopGuard.js';
|
|
6
7
|
import { profile } from './utils/profile.js';
|
|
7
8
|
let impl;
|
|
8
9
|
function initWorkletRef() {
|
|
10
|
+
initMainThreadObjects();
|
|
9
11
|
return (impl = {
|
|
10
12
|
_workletRefMap: {},
|
|
11
13
|
/**
|
|
@@ -17,15 +19,53 @@ function initWorkletRef() {
|
|
|
17
19
|
_firstScreenWorkletRefMap: {},
|
|
18
20
|
updateWorkletRef,
|
|
19
21
|
updateWorkletRefInitValueChanges,
|
|
22
|
+
registerMainThreadObjectType,
|
|
20
23
|
clearFirstScreenWorkletRefMap,
|
|
21
24
|
});
|
|
22
25
|
}
|
|
23
26
|
const createWorkletRef = (id, value) => {
|
|
24
|
-
|
|
27
|
+
const ref = {
|
|
25
28
|
current: value,
|
|
26
29
|
_wvid: id,
|
|
27
30
|
};
|
|
31
|
+
return ref;
|
|
28
32
|
};
|
|
33
|
+
function createWorkletValue(refImpl) {
|
|
34
|
+
return !refImpl._type || refImpl._type === 'main-thread'
|
|
35
|
+
? createWorkletRef(refImpl._wvid, refImpl._initValue)
|
|
36
|
+
: createMainThreadObject(refImpl);
|
|
37
|
+
}
|
|
38
|
+
function isMutableCell(value) {
|
|
39
|
+
return typeof value === 'object' && value !== null
|
|
40
|
+
&& typeof value._wvid === 'number'
|
|
41
|
+
&& Object.prototype.hasOwnProperty.call(value, 'current');
|
|
42
|
+
}
|
|
43
|
+
function isHydratedWorkletValue(value) {
|
|
44
|
+
return typeof value === 'object' && value !== null
|
|
45
|
+
&& (isRealizedMainThreadObject(value) || isMutableCell(value));
|
|
46
|
+
}
|
|
47
|
+
function assertCompatibleWorkletValue(handle, value, operation) {
|
|
48
|
+
let actualKind;
|
|
49
|
+
if (isRealizedMainThreadObject(value)) {
|
|
50
|
+
actualKind = 'typed-object';
|
|
51
|
+
}
|
|
52
|
+
else if (isMutableCell(value)) {
|
|
53
|
+
actualKind = 'mutable-cell';
|
|
54
|
+
}
|
|
55
|
+
if (!actualKind) {
|
|
56
|
+
throw new Error(`Cannot apply MainThreadObject ${operation} for handle ${handle._wvid}: the existing target has no worklet-value metadata.`);
|
|
57
|
+
}
|
|
58
|
+
const expectedType = handle._type;
|
|
59
|
+
const expectedKind = !expectedType || expectedType === 'main-thread'
|
|
60
|
+
? 'mutable-cell'
|
|
61
|
+
: 'typed-object';
|
|
62
|
+
if (actualKind !== expectedKind) {
|
|
63
|
+
throw new Error(`Worklet value kind mismatch during ${operation} for handle ${handle._wvid}: background handle expects ${expectedKind}, but the main-thread target is ${actualKind}.`);
|
|
64
|
+
}
|
|
65
|
+
if (actualKind === 'typed-object') {
|
|
66
|
+
assertCompatibleMainThreadObject(handle, value, operation);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
29
69
|
const getFromWorkletRefMap = (refImpl) => {
|
|
30
70
|
const id = refImpl._wvid;
|
|
31
71
|
/* v8 ignore next 3 */
|
|
@@ -38,10 +78,7 @@ const getFromWorkletRefMap = (refImpl) => {
|
|
|
38
78
|
// Might be called in two scenarios:
|
|
39
79
|
// 1. In MTS events
|
|
40
80
|
// 2. In `main-thread:ref`
|
|
41
|
-
value = impl._firstScreenWorkletRefMap[id];
|
|
42
|
-
if (!value) {
|
|
43
|
-
value = impl._firstScreenWorkletRefMap[id] = createWorkletRef(id, refImpl._initValue);
|
|
44
|
-
}
|
|
81
|
+
value = impl._firstScreenWorkletRefMap[id] ??= createWorkletValue(refImpl);
|
|
45
82
|
}
|
|
46
83
|
else {
|
|
47
84
|
value = impl._workletRefMap[id];
|
|
@@ -55,6 +92,10 @@ const getFromWorkletRefMap = (refImpl) => {
|
|
|
55
92
|
function removeValueFromWorkletRefMap(id) {
|
|
56
93
|
delete impl._workletRefMap[id];
|
|
57
94
|
}
|
|
95
|
+
function hydrateWorkletValue(handle, value) {
|
|
96
|
+
assertCompatibleWorkletValue(handle, value, 'hydration');
|
|
97
|
+
impl._workletRefMap[handle._wvid] = value;
|
|
98
|
+
}
|
|
58
99
|
/**
|
|
59
100
|
* Create an element instance of the given element node, then set the worklet value to it.
|
|
60
101
|
* This is called in `snapshotContextUpdateWorkletRef`.
|
|
@@ -68,15 +109,37 @@ function updateWorkletRef(handle, element) {
|
|
|
68
109
|
}
|
|
69
110
|
function updateWorkletRefInitValueChanges(patch) {
|
|
70
111
|
profile('updateWorkletRefInitValueChanges', () => {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
112
|
+
let firstError;
|
|
113
|
+
let hasError = false;
|
|
114
|
+
patch.forEach(([id, value, type]) => {
|
|
115
|
+
try {
|
|
116
|
+
const handle = {
|
|
117
|
+
_wvid: id,
|
|
118
|
+
_initValue: value,
|
|
119
|
+
_type: type,
|
|
120
|
+
};
|
|
121
|
+
const existing = impl._workletRefMap[id];
|
|
122
|
+
if (existing) {
|
|
123
|
+
assertCompatibleWorkletValue(handle, existing, 'initialization patch');
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
impl._workletRefMap[id] = createWorkletValue(handle);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
catch (error) {
|
|
130
|
+
if (!hasError) {
|
|
131
|
+
firstError = error;
|
|
132
|
+
hasError = true;
|
|
133
|
+
}
|
|
74
134
|
}
|
|
75
135
|
});
|
|
136
|
+
if (hasError) {
|
|
137
|
+
throw firstError;
|
|
138
|
+
}
|
|
76
139
|
});
|
|
77
140
|
}
|
|
78
141
|
function clearFirstScreenWorkletRefMap() {
|
|
79
142
|
impl._firstScreenWorkletRefMap = {};
|
|
80
143
|
}
|
|
81
|
-
export { createWorkletRef, initWorkletRef, getFromWorkletRefMap, removeValueFromWorkletRefMap, updateWorkletRefInitValueChanges, };
|
|
144
|
+
export { createWorkletRef, initWorkletRef, getFromWorkletRefMap, removeValueFromWorkletRefMap, hydrateWorkletValue, isHydratedWorkletValue, updateWorkletRefInitValueChanges, };
|
|
82
145
|
//# sourceMappingURL=workletRef.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"workletRef.js","sourceRoot":"","sources":["../../src/worklet-runtime/workletRef.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAC1D,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAE3C,OAAO,EAAE,uBAAuB,EAAE,MAAM,qCAAqC,CAAC;AAC9E,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAa7C,IAAI,IAAyB,CAAC;AAE9B,SAAS,cAAc;IACrB,OAAO,CAAC,IAAI,GAAG;QACb,cAAc,EAAE,EAAE;QAClB;;;;;WAKG;QACH,yBAAyB,EAAE,EAAE;QAC7B,gBAAgB;QAChB,gCAAgC;QAChC,6BAA6B;KAC9B,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,OAA0B,EACX,EAAE;IACjB,MAAM,EAAE,GAAG,OAAO,CAAC,KAAK,CAAC;IACzB,sBAAsB;IACtB,IAAI,OAAO,EAAE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ACvC,CAAC;AAED,OAAO,EAEL,gBAAgB,EAChB,cAAc,EACd,oBAAoB,EACpB,4BAA4B,EAC5B,mBAAmB,EACnB,sBAAsB,EACtB,gCAAgC,GACjC,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 {\n MainThreadRefInitValuePatch,\n Worklet,\n WorkletRef,\n WorkletRefId,\n WorkletRefImpl,\n} from './bindings/types.js';\nimport {\n assertCompatibleMainThreadObject,\n createMainThreadObject,\n initMainThreadObjects,\n isRealizedMainThreadObject,\n registerMainThreadObjectType,\n} from './mainThreadObject.js';\nimport type { MainThreadObjectFactory } from './mainThreadObject.js';\nimport { mainThreadFlushLoopMark } from './utils/mainThreadFlushLoopGuard.js';\nimport { profile } from './utils/profile.js';\n\ninterface RefImpl {\n _workletRefMap: Record<WorkletRefId, object>;\n _firstScreenWorkletRefMap: Record<WorkletRefId, object>;\n updateWorkletRef(\n refImpl: WorkletRefImpl<Element | null>,\n element: ElementNode | null,\n ): void;\n updateWorkletRefInitValueChanges(\n patch: MainThreadRefInitValuePatch,\n ): void;\n registerMainThreadObjectType(\n type: string,\n create: MainThreadObjectFactory | Worklet,\n ): void;\n clearFirstScreenWorkletRefMap(): void;\n}\n\nlet impl: RefImpl | undefined;\nfunction initWorkletRef(): RefImpl {\n initMainThreadObjects();\n return (impl = {\n _workletRefMap: {},\n /**\n * Map of worklet refs that are created during first screen rendering.\n * These refs are created with negative IDs and need to be hydrated\n * when the app starts. The map is cleared after hydration is complete\n * to free up memory.\n */\n _firstScreenWorkletRefMap: {},\n updateWorkletRef,\n updateWorkletRefInitValueChanges,\n registerMainThreadObjectType,\n clearFirstScreenWorkletRefMap,\n });\n}\n\nconst createWorkletRef = <T>(\n id: WorkletRefId,\n value: T,\n): WorkletRef<T> => {\n const ref = {\n current: value,\n _wvid: id,\n };\n return ref;\n};\n\nfunction createWorkletValue(refImpl: WorkletRefImpl<unknown>): object {\n return !refImpl._type || refImpl._type === 'main-thread'\n ? createWorkletRef(refImpl._wvid, refImpl._initValue)\n : createMainThreadObject(refImpl);\n}\n\nfunction isMutableCell(value: unknown): value is WorkletRef<unknown> {\n return typeof value === 'object' && value !== null\n && typeof (value as Partial<WorkletRef<unknown>>)._wvid === 'number'\n && Object.prototype.hasOwnProperty.call(value, 'current');\n}\n\nfunction isHydratedWorkletValue(value: unknown): value is object {\n return typeof value === 'object' && value !== null\n && (isRealizedMainThreadObject(value) || isMutableCell(value));\n}\n\nfunction assertCompatibleWorkletValue(\n handle: WorkletRefImpl<unknown>,\n value: object,\n operation: 'hydration' | 'initialization patch',\n): void {\n let actualKind: 'typed-object' | 'mutable-cell' | undefined;\n if (isRealizedMainThreadObject(value)) {\n actualKind = 'typed-object';\n } else if (isMutableCell(value)) {\n actualKind = 'mutable-cell';\n }\n if (!actualKind) {\n throw new Error(\n `Cannot apply MainThreadObject ${operation} for handle ${handle._wvid}: the existing target has no worklet-value metadata.`,\n );\n }\n\n const expectedType = handle._type;\n const expectedKind = !expectedType || expectedType === 'main-thread'\n ? 'mutable-cell'\n : 'typed-object';\n if (actualKind !== expectedKind) {\n throw new Error(\n `Worklet value kind mismatch during ${operation} for handle ${handle._wvid}: background handle expects ${expectedKind}, but the main-thread target is ${actualKind}.`,\n );\n }\n if (actualKind === 'typed-object') {\n assertCompatibleMainThreadObject(handle, value, operation);\n }\n}\n\nconst getFromWorkletRefMap = (\n refImpl: WorkletRefImpl<unknown>,\n): object | undefined => {\n const id = refImpl._wvid;\n /* v8 ignore next 3 */\n if (__DEV__) {\n mainThreadFlushLoopMark(`MainThreadRef:get id=${id}`);\n }\n let value;\n if (id < 0) {\n // At the first screen rendering, the worklet ref is created with a negative ID.\n // Might be called in two scenarios:\n // 1. In MTS events\n // 2. In `main-thread:ref`\n value = impl!._firstScreenWorkletRefMap[id] ??= createWorkletValue(refImpl);\n } else {\n value = impl!._workletRefMap[id];\n }\n\n /* v8 ignore next 3 */\n if (__DEV__ && value === undefined) {\n throw new Error('MainThreadRef is not initialized: ' + id);\n }\n return value;\n};\n\nfunction removeValueFromWorkletRefMap(id: WorkletRefId): void {\n delete impl!._workletRefMap[id];\n}\n\nfunction hydrateWorkletValue(\n handle: WorkletRefImpl<unknown>,\n value: object,\n): void {\n assertCompatibleWorkletValue(handle, value, 'hydration');\n impl!._workletRefMap[handle._wvid] = value;\n}\n\n/**\n * Create an element instance of the given element node, then set the worklet value to it.\n * This is called in `snapshotContextUpdateWorkletRef`.\n * @param handle handle of the worklet value.\n * @param element the element node.\n */\nfunction updateWorkletRef(\n handle: WorkletRefImpl<Element | null>,\n element: ElementNode | null,\n): void {\n (getFromWorkletRefMap(handle) as WorkletRef<Element | null>).current = element\n ? new Element(element)\n : null;\n}\n\nfunction updateWorkletRefInitValueChanges(\n patch: MainThreadRefInitValuePatch,\n): void {\n profile('updateWorkletRefInitValueChanges', () => {\n let firstError: unknown;\n let hasError = false;\n patch.forEach(([id, value, type]) => {\n try {\n const handle = {\n _wvid: id,\n _initValue: value,\n _type: type,\n } as WorkletRefImpl<unknown>;\n const existing = impl!._workletRefMap[id];\n if (existing) {\n assertCompatibleWorkletValue(\n handle,\n existing,\n 'initialization patch',\n );\n } else {\n impl!._workletRefMap[id] = createWorkletValue(handle);\n }\n } catch (error) {\n if (!hasError) {\n firstError = error;\n hasError = true;\n }\n }\n });\n if (hasError) {\n throw firstError;\n }\n });\n}\n\nfunction clearFirstScreenWorkletRefMap(): void {\n impl!._firstScreenWorkletRefMap = {};\n}\n\nexport {\n type RefImpl,\n createWorkletRef,\n initWorkletRef,\n getFromWorkletRefMap,\n removeValueFromWorkletRefMap,\n hydrateWorkletValue,\n isHydratedWorkletValue,\n updateWorkletRefInitValueChanges,\n};\n"]}
|
|
@@ -9,6 +9,7 @@ import { initEomImpl } from './eomImpl.js';
|
|
|
9
9
|
import { addEventMethodsIfNeeded } from './eventPropagation.js';
|
|
10
10
|
import { hydrateCtx } from './hydrate.js';
|
|
11
11
|
import { JsFunctionLifecycleManager, isRunOnBackgroundEnabled } from './jsFunctionLifecycle.js';
|
|
12
|
+
import { isRealizedMainThreadObject } from './mainThreadObject.js';
|
|
12
13
|
import { runRunOnMainThreadTask } from './runOnMainThread.js';
|
|
13
14
|
import { mainThreadFlushLoopMark } from './utils/mainThreadFlushLoopGuard.js';
|
|
14
15
|
import { profile } from './utils/profile.js';
|
|
@@ -95,8 +96,7 @@ function transformWorklet(ctx, isWorklet) {
|
|
|
95
96
|
return res;
|
|
96
97
|
}
|
|
97
98
|
}
|
|
98
|
-
const worklet = { main: ctx };
|
|
99
|
-
transformWorkletInner(worklet, 0, ctx);
|
|
99
|
+
const worklet = transformWorkletInner({ main: ctx }, 0, ctx);
|
|
100
100
|
if (isWorklet) {
|
|
101
101
|
workletCache.set(ctx, worklet.main);
|
|
102
102
|
}
|
|
@@ -109,22 +109,33 @@ const transformWorkletInner = (value, depth, ctx) => {
|
|
|
109
109
|
}
|
|
110
110
|
/* v8 ignore next 3 */
|
|
111
111
|
if (typeof value !== 'object' || value === null) {
|
|
112
|
-
return;
|
|
112
|
+
return value;
|
|
113
113
|
}
|
|
114
|
-
|
|
114
|
+
let obj = value;
|
|
115
115
|
for (const key in obj) {
|
|
116
116
|
const subObj = obj[key];
|
|
117
117
|
if (typeof subObj !== 'object' || subObj === null) {
|
|
118
118
|
continue;
|
|
119
119
|
}
|
|
120
|
+
// A MainThreadObject initialization payload is user data. Resolve the
|
|
121
|
+
// typed descriptor before walking it so payload properties that resemble
|
|
122
|
+
// worklet metadata remain untouched. Legacy MainThreadRef descriptors retain
|
|
123
|
+
// the existing recursive path.
|
|
124
|
+
if (isRealizedMainThreadObject(subObj)) {
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
if (isMainThreadObjectDescriptor(subObj)) {
|
|
128
|
+
obj = replaceCapturedProperty(obj, value, key, getFromWorkletRefMap(subObj));
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
120
131
|
if ( /** isEventTarget */'elementRefptr' in subObj) {
|
|
121
|
-
obj[key] = new Element(subObj
|
|
132
|
+
obj[key] = new Element(subObj.elementRefptr);
|
|
122
133
|
continue;
|
|
123
134
|
}
|
|
124
135
|
else if (subObj instanceof Element) {
|
|
125
136
|
continue;
|
|
126
137
|
}
|
|
127
|
-
transformWorkletInner(subObj, depth, ctx);
|
|
138
|
+
const transformedSubObj = transformWorkletInner(subObj, depth, ctx);
|
|
128
139
|
const isWorkletRef = '_wvid' in subObj;
|
|
129
140
|
if (isWorkletRef) {
|
|
130
141
|
obj[key] = getFromWorkletRefMap(subObj);
|
|
@@ -133,18 +144,28 @@ const transformWorkletInner = (value, depth, ctx) => {
|
|
|
133
144
|
const isWorklet = '_wkltId' in subObj;
|
|
134
145
|
if (isWorklet) {
|
|
135
146
|
const isRootWorklet = subObj === ctx;
|
|
136
|
-
const boundCtx = { ...
|
|
147
|
+
const boundCtx = { ...transformedSubObj };
|
|
137
148
|
// Keep the original context collectible. PrimJS traces WeakMap values even
|
|
138
149
|
// when their keys are otherwise unreachable, so the cached function must not point back to its key.
|
|
139
|
-
|
|
150
|
+
const boundWorklet = lynxWorkletImpl
|
|
151
|
+
._workletMap[subObj._wkltId]
|
|
140
152
|
.bind(boundCtx);
|
|
153
|
+
if (transformedSubObj !== subObj && obj === value && obj !== ctx)
|
|
154
|
+
obj = copyAccessorCapture(obj);
|
|
155
|
+
obj = replaceCapturedProperty(obj, value, key, boundWorklet);
|
|
141
156
|
if (!isRootWorklet) {
|
|
142
157
|
// Hydration needs the same context that the function already owns through bind().
|
|
143
158
|
// The original nested context can disappear after its parent replaces it with this function.
|
|
144
|
-
|
|
159
|
+
boundWorklet.boundCtx = boundCtx;
|
|
145
160
|
}
|
|
146
161
|
continue;
|
|
147
162
|
}
|
|
163
|
+
if (transformedSubObj !== subObj) {
|
|
164
|
+
// The root context is runtime-owned: hydration must see its captured copy.
|
|
165
|
+
if (obj === value && obj !== ctx)
|
|
166
|
+
obj = copyAccessorCapture(obj);
|
|
167
|
+
obj = replaceCapturedProperty(obj, value, key, transformedSubObj);
|
|
168
|
+
}
|
|
148
169
|
const isJsFn = '_jsFnId' in subObj;
|
|
149
170
|
if (isJsFn) {
|
|
150
171
|
subObj['_execId'] = ctx._execId;
|
|
@@ -152,6 +173,44 @@ const transformWorkletInner = (value, depth, ctx) => {
|
|
|
152
173
|
continue;
|
|
153
174
|
}
|
|
154
175
|
}
|
|
176
|
+
return obj;
|
|
155
177
|
};
|
|
178
|
+
function replaceCapturedProperty(obj, source, key, value) {
|
|
179
|
+
const descriptor = Object.getOwnPropertyDescriptor(obj, key);
|
|
180
|
+
if (descriptor?.get) {
|
|
181
|
+
// Getters can refresh handles or method receivers. Materialize the captured
|
|
182
|
+
// value without consuming the source getter or invoking its setter.
|
|
183
|
+
const capturedDescriptor = {
|
|
184
|
+
value,
|
|
185
|
+
writable: true,
|
|
186
|
+
enumerable: descriptor.enumerable,
|
|
187
|
+
configurable: descriptor.configurable,
|
|
188
|
+
};
|
|
189
|
+
if (obj === source || !descriptor.configurable) {
|
|
190
|
+
// Replace before defining the copy, including non-configurable getters.
|
|
191
|
+
const descriptors = Object.getOwnPropertyDescriptors(obj);
|
|
192
|
+
descriptors[key] = capturedDescriptor;
|
|
193
|
+
return copyAccessorCapture(obj, descriptors);
|
|
194
|
+
}
|
|
195
|
+
Object.defineProperty(obj, key, capturedDescriptor);
|
|
196
|
+
}
|
|
197
|
+
else {
|
|
198
|
+
obj[key] = value;
|
|
199
|
+
}
|
|
200
|
+
return obj;
|
|
201
|
+
}
|
|
202
|
+
function copyAccessorCapture(obj, descriptors = Object.getOwnPropertyDescriptors(obj)) {
|
|
203
|
+
// Copy descriptors without evaluating getters a second time. Array ancestors
|
|
204
|
+
// retain their array identity when a nested accessor requires a captured copy.
|
|
205
|
+
return Object.defineProperties(Array.isArray(obj)
|
|
206
|
+
? []
|
|
207
|
+
: Object.create(Object.getPrototypeOf(obj)), descriptors);
|
|
208
|
+
}
|
|
209
|
+
function isMainThreadObjectDescriptor(value) {
|
|
210
|
+
const descriptor = value;
|
|
211
|
+
return typeof descriptor._wvid === 'number'
|
|
212
|
+
&& typeof descriptor._type === 'string'
|
|
213
|
+
&& descriptor._type !== 'main-thread';
|
|
214
|
+
}
|
|
156
215
|
export { initWorklet };
|
|
157
216
|
//# sourceMappingURL=workletRuntime.js.map
|
|
@@ -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,MAAM,uBAAuB,CAAC;AAChE,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,0BAA0B,EAAE,wBAAwB,EAAE,MAAM,0BAA0B,CAAC;AAChG,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,oBAAoB,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAEvE,SAAS,WAAW;IAClB,UAAU,CAAC,eAAe,GAAG;QAC3B,WAAW,EAAE,EAAE;QACf,QAAQ,EAAE,cAAc,EAAE;QAC1B,yBAAyB,EAAE,wBAAwB,EAAE;QACrD,WAAW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,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 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
|
@@ -16,10 +16,9 @@
|
|
|
16
16
|
],
|
|
17
17
|
"scripts": {
|
|
18
18
|
"build": "tsc6 --build",
|
|
19
|
-
"test": "pnpm run test:snapshot && pnpm run test:
|
|
20
|
-
"test:core": "vitest run __test__/core",
|
|
19
|
+
"test": "pnpm run test:snapshot && pnpm run test:et",
|
|
21
20
|
"test:et": "vitest run -c __test__/element-template/vitest.config.ts --coverage",
|
|
22
|
-
"test:snapshot": "vitest run --coverage __test__/snapshot __test__/worklet-runtime __test__/guardrails"
|
|
21
|
+
"test:snapshot": "vitest run --coverage __test__/snapshot __test__/core __test__/worklet-runtime __test__/guardrails"
|
|
23
22
|
},
|
|
24
23
|
"devDependencies": {
|
|
25
24
|
"@lynx-js/react": "workspace:*",
|
|
@@ -101,6 +101,22 @@ export function resetBackgroundFunctionRuntime(): void {
|
|
|
101
101
|
* @param f - The js function to be called.
|
|
102
102
|
* @returns A function. Calling which with the arguments to be passed to the js function to trigger it on the background thread. This function returns a promise that resolves to the return value of the js function.
|
|
103
103
|
* @public
|
|
104
|
+
*
|
|
105
|
+
* @example
|
|
106
|
+
*
|
|
107
|
+
* ```ts
|
|
108
|
+
* import { runOnBackground } from '@lynx-js/react';
|
|
109
|
+
*
|
|
110
|
+
* async function someMainthreadFunction() {
|
|
111
|
+
* 'main thread';
|
|
112
|
+
* const fn = runOnBackground(() => {
|
|
113
|
+
* return 'hello';
|
|
114
|
+
* });
|
|
115
|
+
* const result = await fn();
|
|
116
|
+
* }
|
|
117
|
+
* ```
|
|
118
|
+
*
|
|
119
|
+
* @group Functions
|
|
104
120
|
*/
|
|
105
121
|
export function runOnBackground<R, Fn extends (...args: any[]) => R>(
|
|
106
122
|
f: Fn,
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// Copyright 2026 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
|
+
import { isMainThreadObjectHandle } from './main-thread-object-handle-registry.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Preserve opaque main-thread object handles when the worklet transform narrows a
|
|
9
|
+
* captured member expression. Ordinary objects keep the transform's compact
|
|
10
|
+
* fallback shape. The transform evaluates that shape lazily with
|
|
11
|
+
* `captureMainThreadObject(source) ?? fallback`.
|
|
12
|
+
*
|
|
13
|
+
* @internal
|
|
14
|
+
*/
|
|
15
|
+
export function captureMainThreadObject<T>(source: T): T | undefined {
|
|
16
|
+
return isMainThreadObjectHandle(source) ? source : undefined;
|
|
17
|
+
}
|
|
@@ -135,6 +135,8 @@ const useState: typeof usePreactState = (__BACKGROUND__ && isProfiling)
|
|
|
135
135
|
*
|
|
136
136
|
* @function
|
|
137
137
|
* @public
|
|
138
|
+
*
|
|
139
|
+
* @group Hooks
|
|
138
140
|
*/
|
|
139
141
|
const useEffect: (effect: EffectCallback, deps?: DependencyList) => void = (__BACKGROUND__ && isProfiling)
|
|
140
142
|
? useEffectProfiled
|
|
@@ -151,6 +153,8 @@ const useEffect: (effect: EffectCallback, deps?: DependencyList) => void = (__BA
|
|
|
151
153
|
* @function
|
|
152
154
|
* @public
|
|
153
155
|
*
|
|
156
|
+
* @group Hooks
|
|
157
|
+
*
|
|
154
158
|
* @deprecated `useLayoutEffect` in the background thread cannot offer the precise timing for reading layout information and synchronously re-render, which is different from React.
|
|
155
159
|
*/
|
|
156
160
|
const useLayoutEffect: (effect: EffectCallback, deps?: DependencyList) => void = (__BACKGROUND__ && isProfiling)
|
|
@@ -30,6 +30,8 @@ import { useEffect, useMemo, useRef } from '@lynx-js/react/hooks';
|
|
|
30
30
|
* @param eventName - Event name to listen
|
|
31
31
|
* @param listener - Event handler
|
|
32
32
|
* @public
|
|
33
|
+
*
|
|
34
|
+
* @group Hooks
|
|
33
35
|
*/
|
|
34
36
|
export function useLynxGlobalEventListener<T extends (...args: any[]) => void>(
|
|
35
37
|
eventName: string,
|
|
@@ -123,6 +123,8 @@ export const RESET_WITH_INIT_DATA_IN_STATE_ERROR =
|
|
|
123
123
|
* export default withInitDataInState(App);
|
|
124
124
|
* ```
|
|
125
125
|
* @public
|
|
126
|
+
*
|
|
127
|
+
* @group Functions
|
|
126
128
|
*/
|
|
127
129
|
export function withInitDataInState<P, S>(App: ComponentClass<P, S>): ComponentClass<P, S> {
|
|
128
130
|
const isClassComponent = 'prototype' in App && 'render' in App.prototype;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// Copyright 2026 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
|
+
let mainThreadObjectHandleTypes: WeakMap<object, string> | undefined;
|
|
6
|
+
|
|
7
|
+
export function registerMainThreadObjectHandle(
|
|
8
|
+
handle: object,
|
|
9
|
+
type: string,
|
|
10
|
+
): void {
|
|
11
|
+
(mainThreadObjectHandleTypes ??= new WeakMap()).set(handle, type);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function isMainThreadObjectHandle(value: unknown): value is object {
|
|
15
|
+
return typeof value === 'object' && value !== null
|
|
16
|
+
&& mainThreadObjectHandleTypes?.has(value) === true;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function getMainThreadObjectHandleType(
|
|
20
|
+
value: unknown,
|
|
21
|
+
): string | undefined {
|
|
22
|
+
return typeof value === 'object' && value !== null
|
|
23
|
+
? mainThreadObjectHandleTypes?.get(value)
|
|
24
|
+
: undefined;
|
|
25
|
+
}
|