@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,576 @@
|
|
|
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 type { Worklet, WorkletRefImpl } from '@lynx-js/react/worklet-runtime/bindings';
|
|
5
|
+
|
|
6
|
+
import type { BackgroundSnapshotInstance } from './backgroundSnapshot.js';
|
|
7
|
+
import { ListUpdateInfoRecording, __pendingListUpdates, snapshotDestroyList } from './list.js';
|
|
8
|
+
import { unref } from './snapshot/ref.js';
|
|
9
|
+
import { SnapshotOperation, __globalSnapshotPatch } from './snapshotPatch.js';
|
|
10
|
+
import { isDirectOrDeepEqual } from './utils.js';
|
|
11
|
+
|
|
12
|
+
export const enum DynamicPartType {
|
|
13
|
+
Attr = 0,
|
|
14
|
+
Spread,
|
|
15
|
+
Slot,
|
|
16
|
+
// Component,
|
|
17
|
+
Children,
|
|
18
|
+
ListChildren,
|
|
19
|
+
|
|
20
|
+
// Used by compat layer
|
|
21
|
+
MultiChildren,
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
interface Snapshot {
|
|
25
|
+
create: null | ((ctx: SnapshotInstance) => FiberElement[]);
|
|
26
|
+
update: null | ((ctx: SnapshotInstance, index: number, oldValue: any) => void)[];
|
|
27
|
+
slot: [DynamicPartType, number][];
|
|
28
|
+
|
|
29
|
+
isListHolder?: boolean;
|
|
30
|
+
cssId?: number | undefined;
|
|
31
|
+
entryName?: string | undefined;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export let __page: FiberElement;
|
|
35
|
+
export let __pageId = 0;
|
|
36
|
+
export function setupPage(page: FiberElement): void {
|
|
37
|
+
__page = page;
|
|
38
|
+
__pageId = __GetElementUniqueID(page);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export const snapshotManager: {
|
|
42
|
+
values: Map<string, Snapshot>;
|
|
43
|
+
} = {
|
|
44
|
+
values: /* @__PURE__ */ new Map<string, Snapshot>([
|
|
45
|
+
[
|
|
46
|
+
'root',
|
|
47
|
+
{
|
|
48
|
+
create() {
|
|
49
|
+
/* v8 ignore start */
|
|
50
|
+
if (__JS__ && !__DEV__) {
|
|
51
|
+
return [];
|
|
52
|
+
}
|
|
53
|
+
/* v8 ignore stop */
|
|
54
|
+
return [__page!];
|
|
55
|
+
},
|
|
56
|
+
update: [],
|
|
57
|
+
slot: [[DynamicPartType.Children, 0]],
|
|
58
|
+
isListHolder: false,
|
|
59
|
+
cssId: 0,
|
|
60
|
+
},
|
|
61
|
+
],
|
|
62
|
+
[
|
|
63
|
+
'wrapper',
|
|
64
|
+
{
|
|
65
|
+
create() {
|
|
66
|
+
/* v8 ignore start */
|
|
67
|
+
if (__JS__ && !__DEV__) {
|
|
68
|
+
return [];
|
|
69
|
+
}
|
|
70
|
+
/* v8 ignore stop */
|
|
71
|
+
return [__CreateWrapperElement(__pageId)];
|
|
72
|
+
},
|
|
73
|
+
update: [],
|
|
74
|
+
slot: [[DynamicPartType.Children, 0]],
|
|
75
|
+
isListHolder: false,
|
|
76
|
+
},
|
|
77
|
+
],
|
|
78
|
+
[
|
|
79
|
+
null as unknown as string,
|
|
80
|
+
{
|
|
81
|
+
create() {
|
|
82
|
+
/* v8 ignore start */
|
|
83
|
+
if (__JS__ && !__DEV__) {
|
|
84
|
+
return [];
|
|
85
|
+
}
|
|
86
|
+
/* v8 ignore stop */
|
|
87
|
+
return [__CreateElement('raw-text', __pageId)];
|
|
88
|
+
},
|
|
89
|
+
update: [
|
|
90
|
+
ctx => {
|
|
91
|
+
/* v8 ignore start */
|
|
92
|
+
if (__JS__ && !__DEV__) {
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
/* v8 ignore stop */
|
|
96
|
+
if (ctx.__elements) {
|
|
97
|
+
__SetAttribute(ctx.__elements[0]!, 'text', ctx.__values![0]);
|
|
98
|
+
}
|
|
99
|
+
},
|
|
100
|
+
],
|
|
101
|
+
slot: [],
|
|
102
|
+
isListHolder: false,
|
|
103
|
+
},
|
|
104
|
+
],
|
|
105
|
+
]),
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
export const snapshotInstanceManager: {
|
|
109
|
+
nextId: number;
|
|
110
|
+
values: Map<number, SnapshotInstance>;
|
|
111
|
+
clear(): void;
|
|
112
|
+
} = {
|
|
113
|
+
nextId: 0,
|
|
114
|
+
values: /* @__PURE__ */ new Map<number, SnapshotInstance>(),
|
|
115
|
+
clear() {
|
|
116
|
+
// not resetting `nextId` to prevent id collision
|
|
117
|
+
this.values.clear();
|
|
118
|
+
},
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
export const backgroundSnapshotInstanceManager: {
|
|
122
|
+
nextId: number;
|
|
123
|
+
values: Map<number, BackgroundSnapshotInstance>;
|
|
124
|
+
clear(): void;
|
|
125
|
+
updateId(id: number, newId: number): void;
|
|
126
|
+
getValueBySign(str: string): unknown;
|
|
127
|
+
} = {
|
|
128
|
+
nextId: 0,
|
|
129
|
+
values: /* @__PURE__ */ new Map<number, BackgroundSnapshotInstance>(),
|
|
130
|
+
clear() {
|
|
131
|
+
// not resetting `nextId` to prevent id collision
|
|
132
|
+
this.values.clear();
|
|
133
|
+
},
|
|
134
|
+
updateId(id: number, newId: number) {
|
|
135
|
+
const values = this.values;
|
|
136
|
+
const si = values.get(id)!;
|
|
137
|
+
values.delete(id);
|
|
138
|
+
values.set(newId, si);
|
|
139
|
+
si.__id = newId;
|
|
140
|
+
},
|
|
141
|
+
getValueBySign(str: string): unknown {
|
|
142
|
+
const res = str?.split(':');
|
|
143
|
+
if (!res || (res.length != 2 && res.length != 3)) {
|
|
144
|
+
throw new Error('Invalid ctx format: ' + str);
|
|
145
|
+
}
|
|
146
|
+
let id = Number(res[0]);
|
|
147
|
+
const expIndex = Number(res[1]);
|
|
148
|
+
const ctx = this.values.get(id);
|
|
149
|
+
if (!ctx) {
|
|
150
|
+
return null;
|
|
151
|
+
}
|
|
152
|
+
const spreadKey = res[2];
|
|
153
|
+
if (spreadKey) {
|
|
154
|
+
return ctx.__values![expIndex][spreadKey];
|
|
155
|
+
} else {
|
|
156
|
+
return ctx.__values![expIndex];
|
|
157
|
+
}
|
|
158
|
+
},
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
export function createSnapshot(
|
|
162
|
+
uniqID: string,
|
|
163
|
+
create: Snapshot['create'] | null,
|
|
164
|
+
update: Snapshot['update'] | null,
|
|
165
|
+
slot: Snapshot['slot'],
|
|
166
|
+
cssId?: number,
|
|
167
|
+
entryName?: string,
|
|
168
|
+
): string {
|
|
169
|
+
if (
|
|
170
|
+
__DEV__ && __JS__
|
|
171
|
+
// `__globalSnapshotPatch` does not exist before hydration,
|
|
172
|
+
// so the snapshot of the first screen will not be sent to the main thread.
|
|
173
|
+
&& __globalSnapshotPatch
|
|
174
|
+
&& !snapshotManager.values.has(uniqID)
|
|
175
|
+
// `create` may be `null` when loading a lazy bundle after hydration.
|
|
176
|
+
&& create !== null
|
|
177
|
+
) {
|
|
178
|
+
// We only update the lepus snapshot if the `uniqID` is different.
|
|
179
|
+
// This means that `uniqID` is considered the "hash" of the snapshot.
|
|
180
|
+
// When HMR (Hot Module Replacement) or fast refresh updates occur, `createSnapshot` will be re-executed with the new snapshot definition.
|
|
181
|
+
__globalSnapshotPatch.push(
|
|
182
|
+
SnapshotOperation.DEV_ONLY_AddSnapshot,
|
|
183
|
+
uniqID,
|
|
184
|
+
// We use `Function.prototype.toString` to serialize the `create` and `update` functions for Lepus.
|
|
185
|
+
// This allows the updates to be applied to Lepus.
|
|
186
|
+
// As a result, both the static part (`create`) and the dynamic parts (`update` and `slot`) can be updated.
|
|
187
|
+
create.toString(),
|
|
188
|
+
update?.map(f => f.toString()) ?? [],
|
|
189
|
+
slot,
|
|
190
|
+
cssId,
|
|
191
|
+
entryName,
|
|
192
|
+
);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
if (entryName) {
|
|
196
|
+
uniqID = `${entryName}:${uniqID}`;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
const s: Snapshot = { create, update, slot, cssId, entryName };
|
|
200
|
+
snapshotManager.values.set(uniqID, s);
|
|
201
|
+
if (slot && slot[0] && slot[0][0] === DynamicPartType.ListChildren) {
|
|
202
|
+
s.isListHolder = true;
|
|
203
|
+
}
|
|
204
|
+
return uniqID;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
export interface WithChildren {
|
|
208
|
+
childNodes: WithChildren[];
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
export function traverseSnapshotInstance<I extends WithChildren>(
|
|
212
|
+
si: I,
|
|
213
|
+
callback: (si: I) => void,
|
|
214
|
+
): void {
|
|
215
|
+
const c = si.childNodes;
|
|
216
|
+
callback(si);
|
|
217
|
+
for (const vv of c) {
|
|
218
|
+
traverseSnapshotInstance(vv as I, callback);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
export interface SerializedSnapshotInstance {
|
|
223
|
+
id: number;
|
|
224
|
+
type: string;
|
|
225
|
+
values?: any[] | undefined;
|
|
226
|
+
children?: SerializedSnapshotInstance[] | undefined;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
const DEFAULT_ENTRY_NAME = '__Card__';
|
|
230
|
+
const DEFAULT_CSS_ID = 0;
|
|
231
|
+
|
|
232
|
+
export class SnapshotInstance {
|
|
233
|
+
__id: number;
|
|
234
|
+
__snapshot_def: Snapshot;
|
|
235
|
+
__elements?: FiberElement[] | undefined;
|
|
236
|
+
__element_root?: FiberElement | undefined;
|
|
237
|
+
__values?: any[] | undefined;
|
|
238
|
+
__current_slot_index = 0;
|
|
239
|
+
__ref_set?: Set<string>;
|
|
240
|
+
__worklet_ref_set?: Set<WorkletRefImpl<any> | Worklet>;
|
|
241
|
+
__listItemPlatformInfo?: any;
|
|
242
|
+
|
|
243
|
+
constructor(public type: string, id?: number) {
|
|
244
|
+
this.__snapshot_def = snapshotManager.values.get(type)!;
|
|
245
|
+
|
|
246
|
+
id ||= snapshotInstanceManager.nextId -= 1;
|
|
247
|
+
this.__id = id;
|
|
248
|
+
snapshotInstanceManager.values.set(id, this);
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
ensureElements(): void {
|
|
252
|
+
const { create, slot, isListHolder, cssId, entryName } = this.__snapshot_def;
|
|
253
|
+
const elements = create!(this);
|
|
254
|
+
this.__elements = elements;
|
|
255
|
+
this.__element_root = elements[0];
|
|
256
|
+
|
|
257
|
+
if (cssId === undefined) {
|
|
258
|
+
// This means either:
|
|
259
|
+
// CSS Scope is removed(We only need to call `__SetCSSId` when there is `entryName`)
|
|
260
|
+
// Or an old bundle(`__SetCSSId` is called in `create`), we skip calling `__SetCSSId`
|
|
261
|
+
if (entryName !== DEFAULT_ENTRY_NAME && entryName !== undefined) {
|
|
262
|
+
__SetCSSId(this.__elements!, DEFAULT_CSS_ID, entryName);
|
|
263
|
+
}
|
|
264
|
+
} else {
|
|
265
|
+
// cssId !== undefined
|
|
266
|
+
if (entryName !== DEFAULT_ENTRY_NAME && entryName !== undefined) {
|
|
267
|
+
// For lazy bundle, we need add `entryName` to the third params
|
|
268
|
+
__SetCSSId(this.__elements!, cssId, entryName);
|
|
269
|
+
} else {
|
|
270
|
+
__SetCSSId(this.__elements!, cssId);
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
const values = this.__values;
|
|
275
|
+
if (values) {
|
|
276
|
+
this.__values = undefined;
|
|
277
|
+
this.setAttribute('values', values);
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
if (isListHolder) {
|
|
281
|
+
// never recurse into list's children
|
|
282
|
+
} else {
|
|
283
|
+
let index = 0;
|
|
284
|
+
let child = this.__firstChild;
|
|
285
|
+
while (child) {
|
|
286
|
+
child.ensureElements();
|
|
287
|
+
|
|
288
|
+
const [type, elementIndex] = slot[index]!;
|
|
289
|
+
switch (type) {
|
|
290
|
+
case DynamicPartType.Slot: {
|
|
291
|
+
__ReplaceElement(child.__element_root!, elements[elementIndex]!);
|
|
292
|
+
elements[elementIndex] = child.__element_root!;
|
|
293
|
+
index++;
|
|
294
|
+
break;
|
|
295
|
+
}
|
|
296
|
+
/* v8 ignore start */
|
|
297
|
+
case DynamicPartType.MultiChildren: {
|
|
298
|
+
if (__GetTag(elements[elementIndex]!) === 'wrapper') {
|
|
299
|
+
__ReplaceElement(child.__element_root!, elements[elementIndex]!);
|
|
300
|
+
} else {
|
|
301
|
+
__AppendElement(elements[elementIndex]!, child.__element_root!);
|
|
302
|
+
}
|
|
303
|
+
index++;
|
|
304
|
+
break;
|
|
305
|
+
}
|
|
306
|
+
/* v8 ignore end */
|
|
307
|
+
case DynamicPartType.Children:
|
|
308
|
+
case DynamicPartType.ListChildren: {
|
|
309
|
+
__AppendElement(elements[elementIndex]!, child.__element_root!);
|
|
310
|
+
break;
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
child = child.__nextSibling;
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
unRenderElements(): void {
|
|
320
|
+
const { isListHolder } = this.__snapshot_def;
|
|
321
|
+
this.__elements = undefined;
|
|
322
|
+
this.__element_root = undefined;
|
|
323
|
+
|
|
324
|
+
if (isListHolder) {
|
|
325
|
+
// never recurse into list's children
|
|
326
|
+
} else {
|
|
327
|
+
let child = this.__firstChild;
|
|
328
|
+
while (child) {
|
|
329
|
+
child.unRenderElements();
|
|
330
|
+
child = child.__nextSibling;
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
takeElements(): SnapshotInstance {
|
|
336
|
+
const a = Object.create(SnapshotInstance.prototype) as SnapshotInstance;
|
|
337
|
+
|
|
338
|
+
a.__id = this.__id;
|
|
339
|
+
a.__snapshot_def = this.__snapshot_def;
|
|
340
|
+
a.__values = this.__values;
|
|
341
|
+
|
|
342
|
+
// all clear
|
|
343
|
+
a.__parent = null;
|
|
344
|
+
a.__firstChild = null;
|
|
345
|
+
a.__lastChild = null;
|
|
346
|
+
a.__nextSibling = null;
|
|
347
|
+
a.__previousSibling = null;
|
|
348
|
+
|
|
349
|
+
this.childNodes.map(c => c.takeElements()).forEach(node => a.__insertBefore(node));
|
|
350
|
+
|
|
351
|
+
a.__elements = this.__elements;
|
|
352
|
+
a.__element_root = this.__element_root;
|
|
353
|
+
|
|
354
|
+
this.__elements = undefined;
|
|
355
|
+
this.__element_root = undefined;
|
|
356
|
+
return a;
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
// onCreate?: () => void;
|
|
360
|
+
// onAttach?: () => void;
|
|
361
|
+
// onDetach?: () => void;
|
|
362
|
+
// onRef?: () => void;
|
|
363
|
+
// onUnref?: () => void;
|
|
364
|
+
|
|
365
|
+
private __parent: SnapshotInstance | null = null;
|
|
366
|
+
private __firstChild: SnapshotInstance | null = null;
|
|
367
|
+
private __lastChild: SnapshotInstance | null = null;
|
|
368
|
+
private __previousSibling: SnapshotInstance | null = null;
|
|
369
|
+
private __nextSibling: SnapshotInstance | null = null;
|
|
370
|
+
|
|
371
|
+
get parentNode(): SnapshotInstance | null {
|
|
372
|
+
return this.__parent;
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
get nextSibling(): SnapshotInstance | null {
|
|
376
|
+
return this.__nextSibling;
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
// get isConnected() {
|
|
380
|
+
// return !!this.__parent;
|
|
381
|
+
// }
|
|
382
|
+
|
|
383
|
+
contains(child: SnapshotInstance): boolean {
|
|
384
|
+
return child.parentNode === this;
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
get childNodes(): SnapshotInstance[] {
|
|
388
|
+
const nodes: SnapshotInstance[] = [];
|
|
389
|
+
let node = this.__firstChild;
|
|
390
|
+
while (node) {
|
|
391
|
+
nodes.push(node);
|
|
392
|
+
node = node.__nextSibling;
|
|
393
|
+
}
|
|
394
|
+
return nodes;
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
__insertBefore(node: SnapshotInstance, beforeNode?: SnapshotInstance): void {
|
|
398
|
+
// If the node already has a parent, remove it from its current parent
|
|
399
|
+
if (node.__parent) {
|
|
400
|
+
node.__parent.__removeChild(node);
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
// If beforeNode is not provided, add the new node as the last child
|
|
404
|
+
if (beforeNode) {
|
|
405
|
+
// If beforeNode is provided, insert the new node before beforeNode
|
|
406
|
+
if (beforeNode.__previousSibling) {
|
|
407
|
+
beforeNode.__previousSibling.__nextSibling = node;
|
|
408
|
+
node.__previousSibling = beforeNode.__previousSibling;
|
|
409
|
+
} else {
|
|
410
|
+
this.__firstChild = node;
|
|
411
|
+
node.__previousSibling = null;
|
|
412
|
+
}
|
|
413
|
+
beforeNode.__previousSibling = node;
|
|
414
|
+
node.__nextSibling = beforeNode;
|
|
415
|
+
node.__parent = this;
|
|
416
|
+
} else {
|
|
417
|
+
if (this.__lastChild) {
|
|
418
|
+
this.__lastChild.__nextSibling = node;
|
|
419
|
+
node.__previousSibling = this.__lastChild;
|
|
420
|
+
} else {
|
|
421
|
+
this.__firstChild = node;
|
|
422
|
+
node.__previousSibling = null;
|
|
423
|
+
}
|
|
424
|
+
this.__lastChild = node;
|
|
425
|
+
node.__parent = this;
|
|
426
|
+
node.__nextSibling = null;
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
__removeChild(node: SnapshotInstance): void {
|
|
431
|
+
if (node.__parent !== this) {
|
|
432
|
+
throw new Error('The node to be removed is not a child of this node.');
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
if (node.__previousSibling) {
|
|
436
|
+
node.__previousSibling.__nextSibling = node.__nextSibling;
|
|
437
|
+
} else {
|
|
438
|
+
this.__firstChild = node.__nextSibling;
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
if (node.__nextSibling) {
|
|
442
|
+
node.__nextSibling.__previousSibling = node.__previousSibling;
|
|
443
|
+
} else {
|
|
444
|
+
this.__lastChild = node.__previousSibling;
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
node.__parent = null;
|
|
448
|
+
node.__previousSibling = null;
|
|
449
|
+
node.__nextSibling = null;
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
insertBefore(newNode: SnapshotInstance, existingNode?: SnapshotInstance): void {
|
|
453
|
+
const __snapshot_def = this.__snapshot_def;
|
|
454
|
+
if (__snapshot_def.isListHolder) {
|
|
455
|
+
(__pendingListUpdates.values[this.__id] ??= new ListUpdateInfoRecording(
|
|
456
|
+
this,
|
|
457
|
+
)).onInsertBefore(newNode, existingNode);
|
|
458
|
+
this.__insertBefore(newNode, existingNode);
|
|
459
|
+
return;
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
const shouldRemove = newNode.__parent === this;
|
|
463
|
+
this.__insertBefore(newNode, existingNode);
|
|
464
|
+
const __elements = this.__elements;
|
|
465
|
+
if (__elements) {
|
|
466
|
+
if (!newNode.__elements) {
|
|
467
|
+
newNode.ensureElements();
|
|
468
|
+
}
|
|
469
|
+
} else {
|
|
470
|
+
return;
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
const count = __snapshot_def.slot.length;
|
|
474
|
+
if (count === 1) {
|
|
475
|
+
const [, elementIndex] = __snapshot_def.slot[0]!;
|
|
476
|
+
const parent = __elements[elementIndex]!;
|
|
477
|
+
if (shouldRemove) {
|
|
478
|
+
__RemoveElement(parent, newNode.__element_root!);
|
|
479
|
+
}
|
|
480
|
+
if (existingNode) {
|
|
481
|
+
__InsertElementBefore(
|
|
482
|
+
parent,
|
|
483
|
+
newNode.__element_root!,
|
|
484
|
+
existingNode.__element_root,
|
|
485
|
+
);
|
|
486
|
+
} else {
|
|
487
|
+
__AppendElement(parent, newNode.__element_root!);
|
|
488
|
+
}
|
|
489
|
+
} else if (count > 1) {
|
|
490
|
+
const index = this.__current_slot_index++;
|
|
491
|
+
const [s, elementIndex] = __snapshot_def.slot[index]!;
|
|
492
|
+
|
|
493
|
+
if (s === DynamicPartType.Slot) {
|
|
494
|
+
__ReplaceElement(newNode.__element_root!, __elements[elementIndex]!);
|
|
495
|
+
__elements[elementIndex] = newNode.__element_root!;
|
|
496
|
+
|
|
497
|
+
/* v8 ignore start */
|
|
498
|
+
} else if (s === DynamicPartType.MultiChildren) {
|
|
499
|
+
if (__GetTag(__elements[elementIndex]!) === 'wrapper') {
|
|
500
|
+
__ReplaceElement(newNode.__element_root!, __elements[elementIndex]!);
|
|
501
|
+
} else {
|
|
502
|
+
__AppendElement(__elements[elementIndex]!, newNode.__element_root!);
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
/* v8 ignore end */
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
removeChild(child: SnapshotInstance): void {
|
|
510
|
+
const r = () => {
|
|
511
|
+
this.__removeChild(child);
|
|
512
|
+
traverseSnapshotInstance(child, v => {
|
|
513
|
+
v.__parent = null;
|
|
514
|
+
snapshotInstanceManager.values.delete(v.__id);
|
|
515
|
+
});
|
|
516
|
+
};
|
|
517
|
+
|
|
518
|
+
const __snapshot_def = this.__snapshot_def;
|
|
519
|
+
if (__snapshot_def.isListHolder) {
|
|
520
|
+
(__pendingListUpdates.values[this.__id] ??= new ListUpdateInfoRecording(
|
|
521
|
+
this,
|
|
522
|
+
)).onRemoveChild(child);
|
|
523
|
+
r();
|
|
524
|
+
return;
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
// TODO: ref: can this be done on the background thread?
|
|
528
|
+
unref(child, true);
|
|
529
|
+
r();
|
|
530
|
+
if (this.__elements) {
|
|
531
|
+
const [, elementIndex] = __snapshot_def.slot[0]!;
|
|
532
|
+
__RemoveElement(this.__elements[elementIndex]!, child.__element_root!);
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
if (child.__snapshot_def.isListHolder) {
|
|
536
|
+
snapshotDestroyList(child);
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
setAttribute(key: string | number, value: any): void {
|
|
541
|
+
const helper = (index: number, oldValue: any, newValue: any) => {
|
|
542
|
+
if (isDirectOrDeepEqual(oldValue, newValue)) {}
|
|
543
|
+
else {
|
|
544
|
+
this.__snapshot_def.update![index]!(this, index, oldValue);
|
|
545
|
+
}
|
|
546
|
+
};
|
|
547
|
+
|
|
548
|
+
if (key === 'values') {
|
|
549
|
+
const oldValues = this.__values;
|
|
550
|
+
this.__values = value;
|
|
551
|
+
if (oldValues) {
|
|
552
|
+
for (let index = 0; index < value.length; index++) {
|
|
553
|
+
helper(index, oldValues[index], value[index]);
|
|
554
|
+
}
|
|
555
|
+
} else {
|
|
556
|
+
for (let index = 0; index < value.length; index++) {
|
|
557
|
+
helper(index, undefined, value[index]);
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
return;
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
const index = typeof key === 'string' ? Number(key.slice(2)) : key;
|
|
564
|
+
this.__values ??= [];
|
|
565
|
+
helper(index, this.__values[index], this.__values[index] = value);
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
toJSON(): Omit<SerializedSnapshotInstance, 'children'> & { children: SnapshotInstance[] | undefined } {
|
|
569
|
+
return {
|
|
570
|
+
id: this.__id,
|
|
571
|
+
type: this.type,
|
|
572
|
+
values: this.__values,
|
|
573
|
+
children: this.__firstChild ? this.childNodes : undefined,
|
|
574
|
+
};
|
|
575
|
+
}
|
|
576
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// Copyright 2024 The Lynx Authors. All rights reserved.
|
|
2
|
+
// Licensed under the Apache License Version 2.0 that can be found in the
|
|
3
|
+
// LICENSE file in the root directory of this source tree.
|
|
4
|
+
export const enum SnapshotOperation {
|
|
5
|
+
CreateElement,
|
|
6
|
+
InsertBefore,
|
|
7
|
+
RemoveChild,
|
|
8
|
+
SetAttribute,
|
|
9
|
+
SetAttributes,
|
|
10
|
+
|
|
11
|
+
DEV_ONLY_AddSnapshot = 100,
|
|
12
|
+
DEV_ONLY_RegisterWorklet = 101,
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// [opcode: SnapshotOperation.CreateElement, type: string, id: number]
|
|
16
|
+
// [opcode: SnapshotOperation.InsertBefore, parentId: number, id: number, beforeId: number | undefined]
|
|
17
|
+
// [opcode: SnapshotOperation.RemoveChild, parentId: number, childId: number]
|
|
18
|
+
// [opcode: SnapshotOperation.SetAttribute, id: number, dynamicPartIndex: number, value: any]
|
|
19
|
+
// [opcode: SnapshotOperation.SetAttributes, id: number, value: any]
|
|
20
|
+
// [
|
|
21
|
+
// opcode: SnapshotOperation.DEV_ONLY_AddSnapshot,
|
|
22
|
+
// uniqID: string,
|
|
23
|
+
// create: string,
|
|
24
|
+
// update: string[],
|
|
25
|
+
// /** The same as Snapshot['slot'] */
|
|
26
|
+
// slot: [DynamicPartType, number][],
|
|
27
|
+
// cssId: number | undefined,
|
|
28
|
+
// entryName: string | undefined
|
|
29
|
+
// ]
|
|
30
|
+
// [
|
|
31
|
+
// opcode: SnapshotOperation.DEV_ONLY_RegisterWorklet,
|
|
32
|
+
// hash: string,
|
|
33
|
+
// fn: string,
|
|
34
|
+
// ]
|
|
35
|
+
|
|
36
|
+
export type SnapshotPatch = any[];
|
|
37
|
+
|
|
38
|
+
export let __globalSnapshotPatch: any;
|
|
39
|
+
|
|
40
|
+
export function takeGlobalSnapshotPatch(): SnapshotPatch | undefined {
|
|
41
|
+
if (__globalSnapshotPatch) {
|
|
42
|
+
const list = __globalSnapshotPatch;
|
|
43
|
+
__globalSnapshotPatch = [];
|
|
44
|
+
return list;
|
|
45
|
+
} else {
|
|
46
|
+
return undefined;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function initGlobalSnapshotPatch(): void {
|
|
51
|
+
__globalSnapshotPatch = [];
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function deinitGlobalSnapshotPatch(): void {
|
|
55
|
+
__globalSnapshotPatch = undefined;
|
|
56
|
+
}
|