@lynx-js/react 0.105.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +250 -0
- package/LICENSE +202 -0
- package/README.md +20 -0
- package/components/lib/Page.d.ts +3 -0
- package/components/lib/Page.js +56 -0
- package/components/lib/Page.js.map +1 -0
- package/components/lib/index.d.ts +1 -0
- package/components/lib/index.js +5 -0
- package/components/lib/index.js.map +1 -0
- package/components/src/Page.ts +75 -0
- package/components/src/index.ts +5 -0
- package/package.json +162 -0
- package/refresh/.gitignore +1 -0
- package/refresh/.npmignore +3 -0
- package/refresh/.turbo/turbo-build.log +8 -0
- package/refresh/dist/index.js +311 -0
- package/refresh/package.json +21 -0
- package/refresh/src/index.ts +6 -0
- package/refresh/src/prefresh.d.ts +11 -0
- package/refresh/tsconfig.json +4 -0
- package/refresh/turbo.json +15 -0
- package/runtime/jsx-dev-runtime/index.d.ts +5 -0
- package/runtime/jsx-dev-runtime/index.js +4 -0
- package/runtime/jsx-runtime/index.d.ts +4 -0
- package/runtime/jsx-runtime/index.js +4 -0
- package/runtime/lazy/import.d.ts +1 -0
- package/runtime/lazy/import.js +55 -0
- package/runtime/lazy/internal.js +39 -0
- package/runtime/lazy/jsx-dev-runtime.js +12 -0
- package/runtime/lazy/jsx-runtime.js +12 -0
- package/runtime/lazy/legacy-react-runtime.js +20 -0
- package/runtime/lazy/react-lepus.js +9 -0
- package/runtime/lazy/react.js +46 -0
- package/runtime/lazy/target.js +11 -0
- package/runtime/lepus/index.d.ts +4 -0
- package/runtime/lepus/index.js +43 -0
- package/runtime/lepus/jsx-dev-runtime/index.js +4 -0
- package/runtime/lepus/jsx-runtime/index.js +66 -0
- package/runtime/lib/backgroundSnapshot.d.ts +23 -0
- package/runtime/lib/backgroundSnapshot.js +348 -0
- package/runtime/lib/backgroundSnapshot.js.map +1 -0
- package/runtime/lib/compat/componentIs.d.ts +4 -0
- package/runtime/lib/compat/componentIs.js +20 -0
- package/runtime/lib/compat/componentIs.js.map +1 -0
- package/runtime/lib/compat/initData.d.ts +43 -0
- package/runtime/lib/compat/initData.js +93 -0
- package/runtime/lib/compat/initData.js.map +1 -0
- package/runtime/lib/compat/lynxComponent.d.ts +5 -0
- package/runtime/lib/compat/lynxComponent.js +71 -0
- package/runtime/lib/compat/lynxComponent.js.map +1 -0
- package/runtime/lib/debug/debug.d.ts +2 -0
- package/runtime/lib/debug/debug.js +9 -0
- package/runtime/lib/debug/debug.js.map +1 -0
- package/runtime/lib/debug/printSnapshot.d.ts +3 -0
- package/runtime/lib/debug/printSnapshot.js +21 -0
- package/runtime/lib/debug/printSnapshot.js.map +1 -0
- package/runtime/lib/debug/profile.d.ts +1 -0
- package/runtime/lib/debug/profile.js +51 -0
- package/runtime/lib/debug/profile.js.map +1 -0
- package/runtime/lib/document.d.ts +4 -0
- package/runtime/lib/document.js +49 -0
- package/runtime/lib/document.js.map +1 -0
- package/runtime/lib/gesture/processGesture.d.ts +4 -0
- package/runtime/lib/gesture/processGesture.js +48 -0
- package/runtime/lib/gesture/processGesture.js.map +1 -0
- package/runtime/lib/gesture/processGestureBagkround.d.ts +2 -0
- package/runtime/lib/gesture/processGestureBagkround.js +16 -0
- package/runtime/lib/gesture/processGestureBagkround.js.map +1 -0
- package/runtime/lib/gesture/types.d.ts +34 -0
- package/runtime/lib/gesture/types.js +13 -0
- package/runtime/lib/gesture/types.js.map +1 -0
- package/runtime/lib/hooks/react.d.ts +26 -0
- package/runtime/lib/hooks/react.js +35 -0
- package/runtime/lib/hooks/react.js.map +1 -0
- package/runtime/lib/hooks/useLynxGlobalEventListener.d.ts +29 -0
- package/runtime/lib/hooks/useLynxGlobalEventListener.js +53 -0
- package/runtime/lib/hooks/useLynxGlobalEventListener.js.map +1 -0
- package/runtime/lib/hydrate.d.ts +18 -0
- package/runtime/lib/hydrate.js +271 -0
- package/runtime/lib/hydrate.js.map +1 -0
- package/runtime/lib/index.d.ts +9 -0
- package/runtime/lib/index.js +46 -0
- package/runtime/lib/index.js.map +1 -0
- package/runtime/lib/internal.d.ts +26 -0
- package/runtime/lib/internal.js +41 -0
- package/runtime/lib/internal.js.map +1 -0
- package/runtime/lib/legacy-react-runtime/index.d.ts +7 -0
- package/runtime/lib/legacy-react-runtime/index.js +34 -0
- package/runtime/lib/legacy-react-runtime/index.js.map +1 -0
- package/runtime/lib/lifecycle/delayUnmount.d.ts +8 -0
- package/runtime/lib/lifecycle/delayUnmount.js +68 -0
- package/runtime/lib/lifecycle/delayUnmount.js.map +1 -0
- package/runtime/lib/lifecycle/destroy.d.ts +2 -0
- package/runtime/lib/lifecycle/destroy.js +21 -0
- package/runtime/lib/lifecycle/destroy.js.map +1 -0
- package/runtime/lib/lifecycle/pass.d.ts +3 -0
- package/runtime/lib/lifecycle/pass.js +12 -0
- package/runtime/lib/lifecycle/pass.js.map +1 -0
- package/runtime/lib/lifecycle/patchUpdate.d.ts +23 -0
- package/runtime/lib/lifecycle/patchUpdate.js +179 -0
- package/runtime/lib/lifecycle/patchUpdate.js.map +1 -0
- package/runtime/lib/lifecycle/reload.d.ts +3 -0
- package/runtime/lib/lifecycle/reload.js +63 -0
- package/runtime/lib/lifecycle/reload.js.map +1 -0
- package/runtime/lib/lifecycle/render.d.ts +2 -0
- package/runtime/lib/lifecycle/render.js +44 -0
- package/runtime/lib/lifecycle/render.js.map +1 -0
- package/runtime/lib/lifecycleConstant.d.ts +12 -0
- package/runtime/lib/lifecycleConstant.js +17 -0
- package/runtime/lib/lifecycleConstant.js.map +1 -0
- package/runtime/lib/list.d.ts +40 -0
- package/runtime/lib/list.js +305 -0
- package/runtime/lib/list.js.map +1 -0
- package/runtime/lib/lynx/calledByNative.d.ts +2 -0
- package/runtime/lib/lynx/calledByNative.js +113 -0
- package/runtime/lib/lynx/calledByNative.js.map +1 -0
- package/runtime/lib/lynx/component.d.ts +1 -0
- package/runtime/lib/lynx/component.js +69 -0
- package/runtime/lib/lynx/component.js.map +1 -0
- package/runtime/lib/lynx/dynamic-js.d.ts +2 -0
- package/runtime/lib/lynx/dynamic-js.js +31 -0
- package/runtime/lib/lynx/dynamic-js.js.map +1 -0
- package/runtime/lib/lynx/env.d.ts +1 -0
- package/runtime/lib/lynx/env.js +92 -0
- package/runtime/lib/lynx/env.js.map +1 -0
- package/runtime/lib/lynx/injectLepusMethods.d.ts +2 -0
- package/runtime/lib/lynx/injectLepusMethods.js +50 -0
- package/runtime/lib/lynx/injectLepusMethods.js.map +1 -0
- package/runtime/lib/lynx/lazy-bundle.d.ts +9 -0
- package/runtime/lib/lynx/lazy-bundle.js +119 -0
- package/runtime/lib/lynx/lazy-bundle.js.map +1 -0
- package/runtime/lib/lynx/performance.d.ts +29 -0
- package/runtime/lib/lynx/performance.js +100 -0
- package/runtime/lib/lynx/performance.js.map +1 -0
- package/runtime/lib/lynx/tt.d.ts +4 -0
- package/runtime/lib/lynx/tt.js +193 -0
- package/runtime/lib/lynx/tt.js.map +1 -0
- package/runtime/lib/lynx-api.d.ts +311 -0
- package/runtime/lib/lynx-api.js +116 -0
- package/runtime/lib/lynx-api.js.map +1 -0
- package/runtime/lib/lynx.d.ts +2 -0
- package/runtime/lib/lynx.js +91 -0
- package/runtime/lib/lynx.js.map +1 -0
- package/runtime/lib/opcodes.d.ts +2 -0
- package/runtime/lib/opcodes.js +59 -0
- package/runtime/lib/opcodes.js.map +1 -0
- package/runtime/lib/renderToOpcodes/constants.d.ts +17 -0
- package/runtime/lib/renderToOpcodes/constants.js +23 -0
- package/runtime/lib/renderToOpcodes/constants.js.map +1 -0
- package/runtime/lib/renderToOpcodes/index.d.ts +13 -0
- package/runtime/lib/renderToOpcodes/index.js +227 -0
- package/runtime/lib/renderToOpcodes/index.js.map +1 -0
- package/runtime/lib/root.d.ts +7 -0
- package/runtime/lib/root.js +17 -0
- package/runtime/lib/root.js.map +1 -0
- package/runtime/lib/snapshot/event.d.ts +3 -0
- package/runtime/lib/snapshot/event.js +24 -0
- package/runtime/lib/snapshot/event.js.map +1 -0
- package/runtime/lib/snapshot/gesture.d.ts +2 -0
- package/runtime/lib/snapshot/gesture.js +18 -0
- package/runtime/lib/snapshot/gesture.js.map +1 -0
- package/runtime/lib/snapshot/platformInfo.d.ts +4 -0
- package/runtime/lib/snapshot/platformInfo.js +35 -0
- package/runtime/lib/snapshot/platformInfo.js.map +1 -0
- package/runtime/lib/snapshot/ref.d.ts +10 -0
- package/runtime/lib/snapshot/ref.js +119 -0
- package/runtime/lib/snapshot/ref.js.map +1 -0
- package/runtime/lib/snapshot/spread.d.ts +5 -0
- package/runtime/lib/snapshot/spread.js +289 -0
- package/runtime/lib/snapshot/spread.js.map +1 -0
- package/runtime/lib/snapshot/workletEvent.d.ts +3 -0
- package/runtime/lib/snapshot/workletEvent.js +22 -0
- package/runtime/lib/snapshot/workletEvent.js.map +1 -0
- package/runtime/lib/snapshot/workletRef.d.ts +5 -0
- package/runtime/lib/snapshot/workletRef.js +52 -0
- package/runtime/lib/snapshot/workletRef.js.map +1 -0
- package/runtime/lib/snapshot.d.ts +81 -0
- package/runtime/lib/snapshot.js +477 -0
- package/runtime/lib/snapshot.js.map +1 -0
- package/runtime/lib/snapshotPatch.d.ts +14 -0
- package/runtime/lib/snapshotPatch.js +31 -0
- package/runtime/lib/snapshotPatch.js.map +1 -0
- package/runtime/lib/snapshotPatchApply.d.ts +2 -0
- package/runtime/lib/snapshotPatchApply.js +110 -0
- package/runtime/lib/snapshotPatchApply.js.map +1 -0
- package/runtime/lib/utils.d.ts +4 -0
- package/runtime/lib/utils.js +32 -0
- package/runtime/lib/utils.js.map +1 -0
- package/runtime/lib/worklet/ctx.d.ts +1 -0
- package/runtime/lib/worklet/ctx.js +17 -0
- package/runtime/lib/worklet/ctx.js.map +1 -0
- package/runtime/lib/worklet/execMap.d.ts +1 -0
- package/runtime/lib/worklet/execMap.js +42 -0
- package/runtime/lib/worklet/execMap.js.map +1 -0
- package/runtime/lib/worklet/functionality.d.ts +1 -0
- package/runtime/lib/worklet/functionality.js +11 -0
- package/runtime/lib/worklet/functionality.js.map +1 -0
- package/runtime/lib/worklet/hmr.d.ts +1 -0
- package/runtime/lib/worklet/hmr.js +21 -0
- package/runtime/lib/worklet/hmr.js.map +1 -0
- package/runtime/lib/worklet/indexMap.d.ts +8 -0
- package/runtime/lib/worklet/indexMap.js +17 -0
- package/runtime/lib/worklet/indexMap.js.map +1 -0
- package/runtime/lib/worklet/jsImpl.d.ts +11 -0
- package/runtime/lib/worklet/jsImpl.js +68 -0
- package/runtime/lib/worklet/jsImpl.js.map +1 -0
- package/runtime/lib/worklet/runWorklet.d.ts +14 -0
- package/runtime/lib/worklet/runWorklet.js +82 -0
- package/runtime/lib/worklet/runWorklet.js.map +1 -0
- package/runtime/lib/worklet/workletRef.d.ts +131 -0
- package/runtime/lib/worklet/workletRef.js +96 -0
- package/runtime/lib/worklet/workletRef.js.map +1 -0
- package/runtime/lib/worklet/workletRefPool.d.ts +2 -0
- package/runtime/lib/worklet/workletRefPool.js +22 -0
- package/runtime/lib/worklet/workletRefPool.js.map +1 -0
- package/runtime/src/backgroundSnapshot.ts +452 -0
- package/runtime/src/compat/componentIs.ts +30 -0
- package/runtime/src/compat/initData.ts +140 -0
- package/runtime/src/compat/lynxComponent.ts +80 -0
- package/runtime/src/debug/debug.ts +9 -0
- package/runtime/src/debug/printSnapshot.ts +28 -0
- package/runtime/src/debug/profile.ts +54 -0
- package/runtime/src/document.ts +53 -0
- package/runtime/src/gesture/processGesture.ts +77 -0
- package/runtime/src/gesture/processGestureBagkround.ts +15 -0
- package/runtime/src/gesture/types.ts +39 -0
- package/runtime/src/hooks/react.ts +62 -0
- package/runtime/src/hooks/useLynxGlobalEventListener.ts +59 -0
- package/runtime/src/hydrate.ts +364 -0
- package/runtime/src/index.ts +89 -0
- package/runtime/src/internal.ts +60 -0
- package/runtime/src/legacy-react-runtime/index.ts +40 -0
- package/runtime/src/lifecycle/delayUnmount.ts +77 -0
- package/runtime/src/lifecycle/destroy.ts +26 -0
- package/runtime/src/lifecycle/pass.ts +14 -0
- package/runtime/src/lifecycle/patchUpdate.ts +240 -0
- package/runtime/src/lifecycle/reload.ts +79 -0
- package/runtime/src/lifecycle/render.ts +46 -0
- package/runtime/src/lifecycleConstant.ts +16 -0
- package/runtime/src/list.ts +375 -0
- package/runtime/src/lynx/calledByNative.ts +132 -0
- package/runtime/src/lynx/component.ts +116 -0
- package/runtime/src/lynx/dynamic-js.ts +33 -0
- package/runtime/src/lynx/env.ts +110 -0
- package/runtime/src/lynx/injectLepusMethods.ts +53 -0
- package/runtime/src/lynx/lazy-bundle.ts +126 -0
- package/runtime/src/lynx/performance.ts +117 -0
- package/runtime/src/lynx/tt.ts +212 -0
- package/runtime/src/lynx-api.ts +374 -0
- package/runtime/src/lynx.ts +105 -0
- package/runtime/src/opcodes.ts +64 -0
- package/runtime/src/renderToOpcodes/constants.ts +24 -0
- package/runtime/src/renderToOpcodes/index.ts +301 -0
- package/runtime/src/root.ts +19 -0
- package/runtime/src/snapshot/event.ts +33 -0
- package/runtime/src/snapshot/gesture.ts +25 -0
- package/runtime/src/snapshot/platformInfo.ts +48 -0
- package/runtime/src/snapshot/ref.ts +151 -0
- package/runtime/src/snapshot/spread.ts +287 -0
- package/runtime/src/snapshot/workletEvent.ts +33 -0
- package/runtime/src/snapshot/workletRef.ts +63 -0
- package/runtime/src/snapshot.ts +576 -0
- package/runtime/src/snapshotPatch.ts +56 -0
- package/runtime/src/snapshotPatchApply.ts +117 -0
- package/runtime/src/utils.ts +35 -0
- package/runtime/src/worklet/ctx.ts +22 -0
- package/runtime/src/worklet/execMap.ts +50 -0
- package/runtime/src/worklet/functionality.ts +12 -0
- package/runtime/src/worklet/hmr.ts +26 -0
- package/runtime/src/worklet/indexMap.ts +20 -0
- package/runtime/src/worklet/jsImpl.ts +86 -0
- package/runtime/src/worklet/runWorklet.ts +88 -0
- package/runtime/src/worklet/workletRef.ts +229 -0
- package/runtime/src/worklet/workletRefPool.ts +25 -0
- package/transform/cjs/main.cjs +6 -0
- package/transform/cjs/main.d.cts +3 -0
- package/transform/cjs/package.json +3 -0
- package/transform/dist/wasm.cjs +8478 -0
- package/transform/index.d.ts +187 -0
- package/transform/main.js +15 -0
- package/types/react.d.ts +147 -0
- package/types/react.docs.d.ts +74 -0
- package/worklet-runtime/dist/dev.js +414 -0
- package/worklet-runtime/dist/dev.js.map +8 -0
- package/worklet-runtime/dist/main.js +414 -0
- package/worklet-runtime/dist/main.js.map +8 -0
- package/worklet-runtime/lib/api/element.d.ts +14 -0
- package/worklet-runtime/lib/api/element.js +71 -0
- package/worklet-runtime/lib/api/element.js.map +1 -0
- package/worklet-runtime/lib/api/lepusQuerySelector.d.ts +3 -0
- package/worklet-runtime/lib/api/lepusQuerySelector.js +23 -0
- package/worklet-runtime/lib/api/lepusQuerySelector.js.map +1 -0
- package/worklet-runtime/lib/api/lynxApi.d.ts +2 -0
- package/worklet-runtime/lib/api/lynxApi.js +35 -0
- package/worklet-runtime/lib/api/lynxApi.js.map +1 -0
- package/worklet-runtime/lib/bindings/bindings.d.ts +14 -0
- package/worklet-runtime/lib/bindings/bindings.js +61 -0
- package/worklet-runtime/lib/bindings/bindings.js.map +1 -0
- package/worklet-runtime/lib/bindings/events.d.ts +7 -0
- package/worklet-runtime/lib/bindings/events.js +9 -0
- package/worklet-runtime/lib/bindings/events.js.map +1 -0
- package/worklet-runtime/lib/bindings/index.d.ts +4 -0
- package/worklet-runtime/lib/bindings/index.js +7 -0
- package/worklet-runtime/lib/bindings/index.js.map +1 -0
- package/worklet-runtime/lib/bindings/loadRuntime.d.ts +8 -0
- package/worklet-runtime/lib/bindings/loadRuntime.js +25 -0
- package/worklet-runtime/lib/bindings/loadRuntime.js.map +1 -0
- package/worklet-runtime/lib/bindings/types.d.ts +35 -0
- package/worklet-runtime/lib/bindings/types.js +2 -0
- package/worklet-runtime/lib/bindings/types.js.map +1 -0
- package/worklet-runtime/lib/delayWorkletEvent.d.ts +11 -0
- package/worklet-runtime/lib/delayWorkletEvent.js +49 -0
- package/worklet-runtime/lib/delayWorkletEvent.js.map +1 -0
- package/worklet-runtime/lib/global.d.ts +15 -0
- package/worklet-runtime/lib/global.js +2 -0
- package/worklet-runtime/lib/global.js.map +1 -0
- package/worklet-runtime/lib/index.d.ts +1 -0
- package/worklet-runtime/lib/index.js +12 -0
- package/worklet-runtime/lib/index.js.map +1 -0
- package/worklet-runtime/lib/jsFunctionLifecycle.d.ts +18 -0
- package/worklet-runtime/lib/jsFunctionLifecycle.js +55 -0
- package/worklet-runtime/lib/jsFunctionLifecycle.js.map +1 -0
- package/worklet-runtime/lib/listeners.d.ts +2 -0
- package/worklet-runtime/lib/listeners.js +17 -0
- package/worklet-runtime/lib/listeners.js.map +1 -0
- package/worklet-runtime/lib/utils/profile.d.ts +1 -0
- package/worklet-runtime/lib/utils/profile.js +20 -0
- package/worklet-runtime/lib/utils/profile.js.map +1 -0
- package/worklet-runtime/lib/utils/version.d.ts +1 -0
- package/worklet-runtime/lib/utils/version.js +10 -0
- package/worklet-runtime/lib/utils/version.js.map +1 -0
- package/worklet-runtime/lib/workletRef.d.ts +12 -0
- package/worklet-runtime/lib/workletRef.js +50 -0
- package/worklet-runtime/lib/workletRef.js.map +1 -0
- package/worklet-runtime/lib/workletRuntime.d.ts +2 -0
- package/worklet-runtime/lib/workletRuntime.js +128 -0
- package/worklet-runtime/lib/workletRuntime.js.map +1 -0
|
@@ -0,0 +1,287 @@
|
|
|
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 { SnapshotInstance } from '../snapshot.js';
|
|
5
|
+
import { updateEvent } from './event.js';
|
|
6
|
+
import { BackgroundSnapshotInstance } from '../backgroundSnapshot.js';
|
|
7
|
+
import { transformRef, updateRef } from './ref.js';
|
|
8
|
+
import { updateWorkletEvent } from './workletEvent.js';
|
|
9
|
+
import { updateWorkletRef } from './workletRef.js';
|
|
10
|
+
import { updateGesture } from './gesture.js';
|
|
11
|
+
import { platformInfoAttributes, updateListItemPlatformInfo } from './platformInfo.js';
|
|
12
|
+
import { isDirectOrDeepEqual, isEmptyObject, pick } from '../utils.js';
|
|
13
|
+
import { __pendingListUpdates, ListUpdateInfoRecording } from '../list.js';
|
|
14
|
+
|
|
15
|
+
const eventRegExp = /^(([A-Za-z-]*):)?(bind|catch|capture-bind|capture-catch|global-bind)([A-Za-z]+)$/;
|
|
16
|
+
const eventTypeMap: Record<string, string> = {
|
|
17
|
+
bind: 'bindEvent',
|
|
18
|
+
catch: 'catchEvent',
|
|
19
|
+
'capture-bind': 'capture-bind',
|
|
20
|
+
'capture-catch': 'capture-catch',
|
|
21
|
+
'global-bind': 'global-bindEvent',
|
|
22
|
+
};
|
|
23
|
+
const noFlattenAttributes = /* @__PURE__ */ new Set<string>([
|
|
24
|
+
'name',
|
|
25
|
+
'clip-radius',
|
|
26
|
+
'overlap',
|
|
27
|
+
'exposure-scene',
|
|
28
|
+
'exposure-id',
|
|
29
|
+
]);
|
|
30
|
+
|
|
31
|
+
function updateSpread(snapshot: SnapshotInstance, index: number, oldValue: any, elementIndex: number): void {
|
|
32
|
+
oldValue ||= {};
|
|
33
|
+
let newValue: Record<string, any> = snapshot.__values![index]; // compiler guarantee this must be an object;
|
|
34
|
+
|
|
35
|
+
// @ts-ignore
|
|
36
|
+
const list = snapshot.__parent;
|
|
37
|
+
if (list?.__snapshot_def.isListHolder) {
|
|
38
|
+
const oldPlatformInfo = pick(oldValue, platformInfoAttributes);
|
|
39
|
+
const platformInfo = pick(newValue, platformInfoAttributes);
|
|
40
|
+
if (!isDirectOrDeepEqual(oldPlatformInfo, platformInfo)) {
|
|
41
|
+
(__pendingListUpdates.values[list.__id] ??= new ListUpdateInfoRecording(list)).onSetAttribute(
|
|
42
|
+
snapshot,
|
|
43
|
+
platformInfo,
|
|
44
|
+
oldPlatformInfo,
|
|
45
|
+
);
|
|
46
|
+
snapshot.__listItemPlatformInfo = platformInfo;
|
|
47
|
+
|
|
48
|
+
// The fakeSnapshot is missing `__parent`, so no `ListUpdateInfoRecording#onSetAttribute` will be called
|
|
49
|
+
const fakeSnapshot = {
|
|
50
|
+
__values: {
|
|
51
|
+
get [index]() {
|
|
52
|
+
return platformInfo;
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
__id: snapshot.__id,
|
|
56
|
+
__elements: snapshot.__elements,
|
|
57
|
+
} as SnapshotInstance;
|
|
58
|
+
updateListItemPlatformInfo(fakeSnapshot, index, oldPlatformInfo, elementIndex);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (!snapshot.__elements) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if ('__spread' in newValue) {
|
|
67
|
+
// first screen
|
|
68
|
+
newValue = transformSpread(snapshot, index, newValue);
|
|
69
|
+
snapshot.__values![index] = newValue;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const dataset: Record<string, any> = {};
|
|
73
|
+
let match: RegExpMatchArray | null = null;
|
|
74
|
+
for (const key in newValue) {
|
|
75
|
+
const v = newValue[key];
|
|
76
|
+
if (v !== oldValue[key]) {
|
|
77
|
+
if (key === 'className') {
|
|
78
|
+
__SetClasses(snapshot.__elements[elementIndex]!, v);
|
|
79
|
+
} else if (key === 'style') {
|
|
80
|
+
__SetInlineStyles(snapshot.__elements[elementIndex]!, v);
|
|
81
|
+
} else if (key === 'id') {
|
|
82
|
+
__SetID(snapshot.__elements[elementIndex]!, v);
|
|
83
|
+
} else if (key.startsWith('data-')) {
|
|
84
|
+
// collected below
|
|
85
|
+
} else if (key === 'ref') {
|
|
86
|
+
snapshot.__ref_set ??= new Set();
|
|
87
|
+
const fakeSnapshot = {
|
|
88
|
+
__values: {
|
|
89
|
+
get [index]() {
|
|
90
|
+
return v;
|
|
91
|
+
},
|
|
92
|
+
set [index](value: unknown) {
|
|
93
|
+
// Modifications to the ref value should be reflected in the corresponding position of the spread.
|
|
94
|
+
newValue[key] = value;
|
|
95
|
+
},
|
|
96
|
+
},
|
|
97
|
+
__id: snapshot.__id,
|
|
98
|
+
__elements: snapshot.__elements,
|
|
99
|
+
__ref_set: snapshot.__ref_set,
|
|
100
|
+
} as SnapshotInstance;
|
|
101
|
+
updateRef(fakeSnapshot, index, oldValue[key], elementIndex, key);
|
|
102
|
+
} else if (key.endsWith(':ref')) {
|
|
103
|
+
snapshot.__worklet_ref_set ??= new Set();
|
|
104
|
+
const fakeSnapshot = {
|
|
105
|
+
__values: {
|
|
106
|
+
get [index]() {
|
|
107
|
+
return v;
|
|
108
|
+
},
|
|
109
|
+
},
|
|
110
|
+
__id: snapshot.__id,
|
|
111
|
+
__elements: snapshot.__elements,
|
|
112
|
+
__worklet_ref_set: snapshot.__worklet_ref_set,
|
|
113
|
+
} as SnapshotInstance;
|
|
114
|
+
updateWorkletRef(fakeSnapshot, index, oldValue[key], elementIndex, key.slice(0, -4));
|
|
115
|
+
} else if (key.endsWith(':gesture')) {
|
|
116
|
+
const workletType = key.slice(0, -8);
|
|
117
|
+
const fakeSnapshot = {
|
|
118
|
+
__values: {
|
|
119
|
+
get [index]() {
|
|
120
|
+
return v;
|
|
121
|
+
},
|
|
122
|
+
},
|
|
123
|
+
__id: snapshot.__id,
|
|
124
|
+
__elements: snapshot.__elements,
|
|
125
|
+
} as SnapshotInstance;
|
|
126
|
+
updateGesture(fakeSnapshot, index, oldValue[key], elementIndex, workletType);
|
|
127
|
+
} else if ((match = key.match(eventRegExp))) {
|
|
128
|
+
const workletType = match[2];
|
|
129
|
+
const eventType = eventTypeMap[match[3]!]!;
|
|
130
|
+
const eventName = match[4]!;
|
|
131
|
+
const fakeSnapshot = {
|
|
132
|
+
__values: {
|
|
133
|
+
get [index]() {
|
|
134
|
+
return v;
|
|
135
|
+
},
|
|
136
|
+
set [index](value: unknown) {
|
|
137
|
+
// Modifications to the event value should be reflected in the corresponding position of the spread.
|
|
138
|
+
newValue[key] = value;
|
|
139
|
+
},
|
|
140
|
+
},
|
|
141
|
+
__id: snapshot.__id,
|
|
142
|
+
__elements: snapshot.__elements,
|
|
143
|
+
} as SnapshotInstance;
|
|
144
|
+
if (workletType) {
|
|
145
|
+
updateWorkletEvent(fakeSnapshot, index, oldValue[key], elementIndex, workletType, eventType, eventName);
|
|
146
|
+
} else {
|
|
147
|
+
updateEvent(fakeSnapshot, index, oldValue[key], elementIndex, eventType, eventName, key);
|
|
148
|
+
}
|
|
149
|
+
} else if (platformInfoAttributes.has(key)) {
|
|
150
|
+
// ignore
|
|
151
|
+
} else {
|
|
152
|
+
__SetAttribute(snapshot.__elements[elementIndex]!, key, v);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// collect data regardless of whether it has changed
|
|
157
|
+
if (key.startsWith('data-')) {
|
|
158
|
+
dataset[key.slice(5)] = v;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
let hasOldDataset = false;
|
|
163
|
+
for (const key in oldValue) {
|
|
164
|
+
if (!(key in newValue)) {
|
|
165
|
+
if (key === 'className') {
|
|
166
|
+
__SetClasses(snapshot.__elements[elementIndex]!, '');
|
|
167
|
+
} else if (key === 'style') {
|
|
168
|
+
__SetInlineStyles(snapshot.__elements[elementIndex]!, '');
|
|
169
|
+
} else if (key === 'id') {
|
|
170
|
+
__SetID(snapshot.__elements[elementIndex]!, null);
|
|
171
|
+
} else if (key.startsWith('data-')) {
|
|
172
|
+
// collected below
|
|
173
|
+
} else if (key === 'ref') {
|
|
174
|
+
snapshot.__ref_set ??= new Set();
|
|
175
|
+
const fakeSnapshot = {
|
|
176
|
+
__values: {
|
|
177
|
+
get [index]() {
|
|
178
|
+
return undefined;
|
|
179
|
+
},
|
|
180
|
+
set [index](value: unknown) {
|
|
181
|
+
// Modifications to the ref value should be reflected in the corresponding position of the spread.
|
|
182
|
+
newValue[key] = value;
|
|
183
|
+
},
|
|
184
|
+
},
|
|
185
|
+
__id: snapshot.__id,
|
|
186
|
+
__elements: snapshot.__elements,
|
|
187
|
+
__ref_set: snapshot.__ref_set,
|
|
188
|
+
} as SnapshotInstance;
|
|
189
|
+
updateRef(fakeSnapshot, index, oldValue[key], elementIndex, key);
|
|
190
|
+
} else if (key.endsWith(':ref')) {
|
|
191
|
+
snapshot.__worklet_ref_set ??= new Set();
|
|
192
|
+
const fakeSnapshot = {
|
|
193
|
+
__values: {
|
|
194
|
+
get [index]() {
|
|
195
|
+
return undefined;
|
|
196
|
+
},
|
|
197
|
+
},
|
|
198
|
+
__id: snapshot.__id,
|
|
199
|
+
__elements: snapshot.__elements,
|
|
200
|
+
__worklet_ref_set: snapshot.__worklet_ref_set,
|
|
201
|
+
} as SnapshotInstance;
|
|
202
|
+
updateWorkletRef(fakeSnapshot, index, oldValue[key], elementIndex, key.slice(0, -4));
|
|
203
|
+
} else if (key.endsWith(':gesture')) {
|
|
204
|
+
const workletType = key.slice(0, -8);
|
|
205
|
+
const fakeSnapshot = {
|
|
206
|
+
__values: {
|
|
207
|
+
get [index]() {
|
|
208
|
+
return undefined;
|
|
209
|
+
},
|
|
210
|
+
},
|
|
211
|
+
__id: snapshot.__id,
|
|
212
|
+
__elements: snapshot.__elements,
|
|
213
|
+
} as SnapshotInstance;
|
|
214
|
+
updateGesture(fakeSnapshot, index, oldValue[key], elementIndex, workletType);
|
|
215
|
+
} else if ((match = key.match(eventRegExp))) {
|
|
216
|
+
const workletType = match[2];
|
|
217
|
+
const eventType = eventTypeMap[match[3]!]!;
|
|
218
|
+
const eventName = match[4]!;
|
|
219
|
+
const fakeSnapshot = {
|
|
220
|
+
__values: {
|
|
221
|
+
get [index]() {
|
|
222
|
+
return undefined;
|
|
223
|
+
},
|
|
224
|
+
set [index](value: unknown) {
|
|
225
|
+
newValue[key] = value;
|
|
226
|
+
},
|
|
227
|
+
},
|
|
228
|
+
__id: snapshot.__id,
|
|
229
|
+
__elements: snapshot.__elements,
|
|
230
|
+
} as SnapshotInstance;
|
|
231
|
+
if (workletType) {
|
|
232
|
+
updateWorkletEvent(fakeSnapshot, index, oldValue[key], elementIndex, workletType, eventType, eventName);
|
|
233
|
+
} else {
|
|
234
|
+
updateEvent(fakeSnapshot, index, oldValue[key], elementIndex, eventType, eventName, key);
|
|
235
|
+
}
|
|
236
|
+
} else if (platformInfoAttributes.has(key)) {
|
|
237
|
+
// ignore
|
|
238
|
+
} else {
|
|
239
|
+
__SetAttribute(snapshot.__elements[elementIndex]!, key, null);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
// collect data regardless of whether it has changed
|
|
244
|
+
if (key.startsWith('data-')) {
|
|
245
|
+
hasOldDataset = true;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
// TODO: compare dataset before commit it to native?
|
|
250
|
+
if (hasOldDataset || !isEmptyObject(dataset)) {
|
|
251
|
+
__SetDataset(snapshot.__elements[elementIndex]!, dataset);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
function transformSpread(
|
|
256
|
+
snapshot: BackgroundSnapshotInstance | SnapshotInstance,
|
|
257
|
+
index: number,
|
|
258
|
+
spread: Record<string, unknown>,
|
|
259
|
+
): Record<string, unknown> {
|
|
260
|
+
const result: Record<string, unknown> = {};
|
|
261
|
+
let hasNoFlattenAttributes = false;
|
|
262
|
+
for (const key in spread) {
|
|
263
|
+
let value = spread[key];
|
|
264
|
+
if (key === '__spread') {}
|
|
265
|
+
else if (key === 'class' || key === 'className') {
|
|
266
|
+
value ??= '';
|
|
267
|
+
result['className'] = value;
|
|
268
|
+
} else if (key === 'ref') {
|
|
269
|
+
// @ts-ignore
|
|
270
|
+
result[key] = transformRef(value)?.__ref;
|
|
271
|
+
} else if (typeof value === 'function') {
|
|
272
|
+
result[key] = `${snapshot.__id}:${index}:${key}`;
|
|
273
|
+
} else {
|
|
274
|
+
if (!hasNoFlattenAttributes && noFlattenAttributes.has(key)) {
|
|
275
|
+
hasNoFlattenAttributes = true;
|
|
276
|
+
}
|
|
277
|
+
result[key] = value;
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
if (hasNoFlattenAttributes) {
|
|
282
|
+
result['flatten'] = false;
|
|
283
|
+
}
|
|
284
|
+
return result;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
export { updateSpread, transformSpread };
|
|
@@ -0,0 +1,33 @@
|
|
|
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 { onWorkletCtxUpdate } from '@lynx-js/react/worklet-runtime/bindings';
|
|
5
|
+
|
|
6
|
+
import { SnapshotInstance } from '../snapshot.js';
|
|
7
|
+
|
|
8
|
+
function updateWorkletEvent(
|
|
9
|
+
snapshot: SnapshotInstance,
|
|
10
|
+
expIndex: number,
|
|
11
|
+
_oldValue: any,
|
|
12
|
+
elementIndex: number,
|
|
13
|
+
workletType: string,
|
|
14
|
+
eventType: string,
|
|
15
|
+
eventName: string,
|
|
16
|
+
): void {
|
|
17
|
+
if (!snapshot.__elements) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
const value = snapshot.__values![expIndex] || {};
|
|
21
|
+
value._workletType = workletType;
|
|
22
|
+
|
|
23
|
+
if (workletType === 'main-thread') {
|
|
24
|
+
onWorkletCtxUpdate(value, snapshot.__elements[elementIndex]!);
|
|
25
|
+
const event = {
|
|
26
|
+
type: 'worklet',
|
|
27
|
+
value,
|
|
28
|
+
};
|
|
29
|
+
__AddEvent(snapshot.__elements[elementIndex]!, eventType, eventName, event);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export { updateWorkletEvent };
|
|
@@ -0,0 +1,63 @@
|
|
|
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 {
|
|
5
|
+
type Worklet,
|
|
6
|
+
type WorkletRef,
|
|
7
|
+
runWorkletCtx,
|
|
8
|
+
updateWorkletRef as update,
|
|
9
|
+
} from '@lynx-js/react/worklet-runtime/bindings';
|
|
10
|
+
|
|
11
|
+
import { SnapshotInstance } from '../snapshot.js';
|
|
12
|
+
|
|
13
|
+
function workletUnRef(value: Worklet | WorkletRef<unknown>): void {
|
|
14
|
+
if ('_wvid' in value) {
|
|
15
|
+
update(value as any, null);
|
|
16
|
+
} else if ('_wkltId' in value) {
|
|
17
|
+
if (typeof value._unmount == 'function') {
|
|
18
|
+
value._unmount();
|
|
19
|
+
} else {
|
|
20
|
+
runWorkletCtx(value as any, [null]);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function updateWorkletRef(
|
|
26
|
+
snapshot: SnapshotInstance,
|
|
27
|
+
expIndex: number,
|
|
28
|
+
oldValue: any,
|
|
29
|
+
elementIndex: number,
|
|
30
|
+
_workletType: string,
|
|
31
|
+
): void {
|
|
32
|
+
if (!snapshot.__elements) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (oldValue && snapshot.__worklet_ref_set?.has(oldValue)) {
|
|
37
|
+
workletUnRef(oldValue);
|
|
38
|
+
snapshot.__worklet_ref_set?.delete(oldValue);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const value = snapshot.__values![expIndex];
|
|
42
|
+
if (value === null || value === undefined) {
|
|
43
|
+
// do nothing
|
|
44
|
+
} else if (value._wvid) {
|
|
45
|
+
update(value as any, snapshot.__elements[elementIndex]!);
|
|
46
|
+
} else if (value._wkltId) {
|
|
47
|
+
// @ts-ignore
|
|
48
|
+
value._unmount = runWorkletCtx(value as any, [{ elementRefptr: snapshot.__elements[elementIndex]! }]);
|
|
49
|
+
} else if (value._type === '__LEPUS__' || value._lepusWorkletHash) {
|
|
50
|
+
// During the initial render, we will not update the WorkletRef because the background thread is not ready yet.
|
|
51
|
+
} else {
|
|
52
|
+
throw new Error('MainThreadRef: main-thread:ref must be of type MainThreadRef or main-thread function.');
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (value) {
|
|
56
|
+
snapshot.__worklet_ref_set ??= new Set();
|
|
57
|
+
snapshot.__worklet_ref_set.add(value);
|
|
58
|
+
}
|
|
59
|
+
// Add an arbitrary attribute to avoid this element being layout-only
|
|
60
|
+
__SetAttribute(snapshot.__elements[elementIndex]!, 'has-react-ref', true);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export { updateWorkletRef, workletUnRef };
|