@lynx-js/react 0.111.1 → 0.112.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 +71 -0
- package/components/lib/DeferredListItem.d.ts +3 -1
- package/components/lib/DeferredListItem.jsx +4 -2
- package/components/lib/DeferredListItem.jsx.map +1 -1
- package/components/lib/Page.js.map +1 -1
- package/components/src/DeferredListItem.tsx +5 -3
- package/components/src/Page.ts +2 -2
- package/package.json +15 -2
- package/refresh/.turbo/turbo-build.log +2 -2
- package/runtime/compat/index.d.ts +40 -0
- package/runtime/compat/index.js +15 -0
- package/runtime/debug/index.cjs +8 -0
- package/runtime/debug/index.d.ts +4 -0
- package/runtime/debug/index.js +5 -0
- package/runtime/lazy/compat.js +51 -0
- package/runtime/lazy/import.js +9 -0
- package/runtime/lazy/target.js +1 -0
- package/runtime/lib/alog/index.d.ts +1 -0
- package/runtime/lib/alog/index.js +8 -0
- package/runtime/lib/alog/index.js.map +1 -0
- package/runtime/lib/alog/render.d.ts +1 -0
- package/runtime/lib/alog/render.js +19 -0
- package/runtime/lib/alog/render.js.map +1 -0
- package/runtime/lib/backgroundSnapshot.d.ts +1 -0
- package/runtime/lib/backgroundSnapshot.js +31 -17
- package/runtime/lib/backgroundSnapshot.js.map +1 -1
- package/runtime/lib/debug/component-stack.d.ts +33 -0
- package/runtime/lib/debug/component-stack.js +145 -0
- package/runtime/lib/debug/component-stack.js.map +1 -0
- package/runtime/lib/debug/formatPatch.d.ts +2 -0
- package/runtime/lib/debug/formatPatch.js +27 -0
- package/runtime/lib/debug/formatPatch.js.map +1 -0
- package/runtime/lib/debug/printSnapshot.d.ts +1 -1
- package/runtime/lib/debug/printSnapshot.js +0 -4
- package/runtime/lib/debug/printSnapshot.js.map +1 -1
- package/runtime/lib/debug/profile.js +3 -5
- package/runtime/lib/debug/profile.js.map +1 -1
- package/runtime/lib/hydrate.js +11 -7
- package/runtime/lib/hydrate.js.map +1 -1
- package/runtime/lib/index.js +3 -5
- package/runtime/lib/index.js.map +1 -1
- package/runtime/lib/lifecycle/patch/commit.js +3 -3
- package/runtime/lib/lifecycle/patch/commit.js.map +1 -1
- package/runtime/lib/lifecycle/patch/isMainThreadHydrating.d.ts +2 -0
- package/runtime/lib/lifecycle/patch/{isMainThreadHydrationFinished.js → isMainThreadHydrating.js} +5 -5
- package/runtime/lib/lifecycle/patch/isMainThreadHydrating.js.map +1 -0
- package/runtime/lib/lifecycle/patch/snapshotPatch.d.ts +4 -0
- package/runtime/lib/lifecycle/patch/snapshotPatch.js +28 -0
- package/runtime/lib/lifecycle/patch/snapshotPatch.js.map +1 -1
- package/runtime/lib/lifecycle/patch/updateMainThread.js +20 -13
- package/runtime/lib/lifecycle/patch/updateMainThread.js.map +1 -1
- package/runtime/lib/lifecycle/reload.js +0 -2
- package/runtime/lib/lifecycle/reload.js.map +1 -1
- package/runtime/lib/lynx/lazy-bundle.js +0 -19
- package/runtime/lib/lynx/lazy-bundle.js.map +1 -1
- package/runtime/lib/lynx/performance.js +2 -2
- package/runtime/lib/lynx/performance.js.map +1 -1
- package/runtime/lib/lynx/runWithForce.js +2 -2
- package/runtime/lib/lynx/runWithForce.js.map +1 -1
- package/runtime/lib/lynx-api.js +17 -3
- package/runtime/lib/lynx-api.js.map +1 -1
- package/runtime/lib/lynx.js +16 -1
- package/runtime/lib/lynx.js.map +1 -1
- package/runtime/lib/pendingListUpdates.d.ts +2 -1
- package/runtime/lib/pendingListUpdates.js +16 -4
- package/runtime/lib/pendingListUpdates.js.map +1 -1
- package/runtime/lib/renderToOpcodes/constants.d.ts +2 -0
- package/runtime/lib/renderToOpcodes/constants.js +2 -0
- package/runtime/lib/renderToOpcodes/constants.js.map +1 -1
- package/runtime/lib/renderToOpcodes/index.js +36 -11
- package/runtime/lib/renderToOpcodes/index.js.map +1 -1
- package/runtime/lib/root.d.ts +6 -0
- package/runtime/lib/root.js +4 -0
- package/runtime/lib/root.js.map +1 -1
- package/runtime/lib/snapshot/gesture.js +2 -2
- package/runtime/lib/snapshot/gesture.js.map +1 -1
- package/runtime/lib/snapshot/platformInfo.js +5 -3
- package/runtime/lib/snapshot/platformInfo.js.map +1 -1
- package/runtime/lib/snapshot/ref.d.ts +2 -2
- package/runtime/lib/snapshot/spread.js +3 -1
- package/runtime/lib/snapshot/spread.js.map +1 -1
- package/runtime/lib/snapshot/workletEvent.js +2 -2
- package/runtime/lib/snapshot/workletEvent.js.map +1 -1
- package/runtime/lib/snapshot/workletRef.js +2 -2
- package/runtime/lib/snapshot/workletRef.js.map +1 -1
- package/runtime/lib/snapshot.js +13 -7
- package/runtime/lib/snapshot.js.map +1 -1
- package/runtime/lib/utils.d.ts +2 -0
- package/runtime/lib/utils.js +23 -2
- package/runtime/lib/utils.js.map +1 -1
- package/testing-library/dist/env/vitest.js +20 -10
- package/testing-library/dist/vitest-global-setup.js +0 -6
- package/testing-library/dist/vitest.config.js +1 -4
- package/transform/dist/wasm.cjs +1 -1
- package/types/react.d.ts +13 -1
- package/runtime/lib/lifecycle/patch/isMainThreadHydrationFinished.d.ts +0 -2
- package/runtime/lib/lifecycle/patch/isMainThreadHydrationFinished.js.map +0 -1
- package/runtime/src/backgroundSnapshot.ts +0 -501
- package/runtime/src/compat/componentIs.ts +0 -30
- package/runtime/src/compat/initData.ts +0 -150
- package/runtime/src/compat/lynxComponent.ts +0 -79
- package/runtime/src/debug/debug.ts +0 -9
- package/runtime/src/debug/printSnapshot.ts +0 -28
- package/runtime/src/debug/profile.ts +0 -55
- package/runtime/src/document.ts +0 -84
- package/runtime/src/gesture/processGesture.ts +0 -89
- package/runtime/src/gesture/processGestureBagkround.ts +0 -19
- package/runtime/src/gesture/types.ts +0 -44
- package/runtime/src/hooks/react.ts +0 -62
- package/runtime/src/hooks/useLynxGlobalEventListener.ts +0 -59
- package/runtime/src/hydrate.ts +0 -368
- package/runtime/src/index.ts +0 -94
- package/runtime/src/internal.ts +0 -63
- package/runtime/src/legacy-react-runtime/index.ts +0 -42
- package/runtime/src/lifecycle/destroy.ts +0 -34
- package/runtime/src/lifecycle/event/delayEvents.ts +0 -11
- package/runtime/src/lifecycle/event/delayLifecycleEvents.ts +0 -15
- package/runtime/src/lifecycle/event/jsReady.ts +0 -34
- package/runtime/src/lifecycle/pass.ts +0 -14
- package/runtime/src/lifecycle/patch/commit.ts +0 -214
- package/runtime/src/lifecycle/patch/error.ts +0 -61
- package/runtime/src/lifecycle/patch/isMainThreadHydrationFinished.ts +0 -13
- package/runtime/src/lifecycle/patch/snapshotPatch.ts +0 -65
- package/runtime/src/lifecycle/patch/snapshotPatchApply.ts +0 -145
- package/runtime/src/lifecycle/patch/updateMainThread.ts +0 -64
- package/runtime/src/lifecycle/ref/delay.ts +0 -99
- package/runtime/src/lifecycle/reload.ts +0 -97
- package/runtime/src/lifecycle/render.ts +0 -54
- package/runtime/src/lifecycleConstant.ts +0 -21
- package/runtime/src/list.ts +0 -307
- package/runtime/src/listUpdateInfo.ts +0 -221
- package/runtime/src/lynx/calledByNative.ts +0 -160
- package/runtime/src/lynx/component.ts +0 -113
- package/runtime/src/lynx/dynamic-js.ts +0 -36
- package/runtime/src/lynx/env.ts +0 -109
- package/runtime/src/lynx/injectLepusMethods.ts +0 -53
- package/runtime/src/lynx/lazy-bundle.ts +0 -175
- package/runtime/src/lynx/performance.ts +0 -148
- package/runtime/src/lynx/runWithForce.ts +0 -67
- package/runtime/src/lynx/tt.ts +0 -215
- package/runtime/src/lynx-api.ts +0 -455
- package/runtime/src/lynx.ts +0 -58
- package/runtime/src/opcodes.ts +0 -155
- package/runtime/src/pendingListUpdates.ts +0 -18
- package/runtime/src/renderToOpcodes/constants.ts +0 -24
- package/runtime/src/renderToOpcodes/index.ts +0 -306
- package/runtime/src/root.ts +0 -23
- package/runtime/src/snapshot/dynamicPartType.ts +0 -16
- package/runtime/src/snapshot/event.ts +0 -33
- package/runtime/src/snapshot/gesture.ts +0 -30
- package/runtime/src/snapshot/list.ts +0 -36
- package/runtime/src/snapshot/platformInfo.ts +0 -62
- package/runtime/src/snapshot/ref.ts +0 -139
- package/runtime/src/snapshot/spread.ts +0 -330
- package/runtime/src/snapshot/workletEvent.ts +0 -35
- package/runtime/src/snapshot/workletRef.ts +0 -88
- package/runtime/src/snapshot.ts +0 -634
- package/runtime/src/snapshotInstanceHydrationMap.ts +0 -17
- package/runtime/src/utils.ts +0 -44
- package/runtime/src/worklet/ctx.ts +0 -22
- package/runtime/src/worklet/destroy.ts +0 -16
- package/runtime/src/worklet/execMap.ts +0 -51
- package/runtime/src/worklet/functionCall.ts +0 -42
- package/runtime/src/worklet/functionality.ts +0 -29
- package/runtime/src/worklet/hmr.ts +0 -34
- package/runtime/src/worklet/indexMap.ts +0 -23
- package/runtime/src/worklet/runOnBackground.ts +0 -147
- package/runtime/src/worklet/runOnMainThread.ts +0 -50
- package/runtime/src/worklet/transformToWorklet.ts +0 -26
- package/runtime/src/worklet/workletRef.ts +0 -231
- package/runtime/src/worklet/workletRefPool.ts +0 -29
|
@@ -1,150 +0,0 @@
|
|
|
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 { ComponentChildren, Consumer, Context, Provider } from 'preact';
|
|
5
|
-
import type { ComponentClass } from 'react';
|
|
6
|
-
|
|
7
|
-
import { useLynxGlobalEventListener } from '../hooks/useLynxGlobalEventListener.js';
|
|
8
|
-
import { globalFlushOptions } from '../lifecycle/patch/commit.js';
|
|
9
|
-
|
|
10
|
-
type Getter<T> = {
|
|
11
|
-
[key in keyof T]: () => T[key];
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
// for better reuse if runtime is changed
|
|
15
|
-
export function factory<Data>(
|
|
16
|
-
{ createContext, useState, createElement, useLynxGlobalEventListener: useListener }: {
|
|
17
|
-
createContext: typeof import('preact').createContext;
|
|
18
|
-
useState: typeof import('preact/hooks').useState;
|
|
19
|
-
createElement: typeof import('preact').createElement;
|
|
20
|
-
useLynxGlobalEventListener: typeof useLynxGlobalEventListener;
|
|
21
|
-
},
|
|
22
|
-
prop: '__globalProps' | '__initData',
|
|
23
|
-
eventName: string,
|
|
24
|
-
): Getter<{
|
|
25
|
-
Context: Context<Data>;
|
|
26
|
-
Provider: Provider<Data>;
|
|
27
|
-
Consumer: Consumer<Data>;
|
|
28
|
-
use: () => Data;
|
|
29
|
-
useChanged: (callback: (data: Data) => void) => void;
|
|
30
|
-
}> {
|
|
31
|
-
const Context = createContext({} as Data);
|
|
32
|
-
|
|
33
|
-
const Provider = ({ children }: { children?: ComponentChildren }) => {
|
|
34
|
-
const [__, set] = useState<Data>(lynx[prop] as Data);
|
|
35
|
-
|
|
36
|
-
const handleChange = () => {
|
|
37
|
-
if (prop === '__initData') {
|
|
38
|
-
globalFlushOptions.triggerDataUpdated = true;
|
|
39
|
-
}
|
|
40
|
-
set(lynx[prop] as Data);
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
useChanged(handleChange);
|
|
44
|
-
|
|
45
|
-
return createElement(
|
|
46
|
-
Context.Provider,
|
|
47
|
-
{
|
|
48
|
-
value: __,
|
|
49
|
-
},
|
|
50
|
-
children,
|
|
51
|
-
);
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
const Consumer: Consumer<Data> = Context.Consumer;
|
|
55
|
-
|
|
56
|
-
const use = (): Data => {
|
|
57
|
-
const [__, set] = useState(lynx[prop]);
|
|
58
|
-
useChanged(() => {
|
|
59
|
-
if (prop === '__initData') {
|
|
60
|
-
globalFlushOptions.triggerDataUpdated = true;
|
|
61
|
-
}
|
|
62
|
-
set(lynx[prop]);
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
return __ as Data;
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
const useChanged = (callback: (__: Data) => void) => {
|
|
69
|
-
if (!__LEPUS__) {
|
|
70
|
-
useListener(eventName, callback);
|
|
71
|
-
}
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
return {
|
|
75
|
-
/* v8 ignore next */
|
|
76
|
-
Context: () => Context,
|
|
77
|
-
Provider: () => Provider,
|
|
78
|
-
Consumer: () => Consumer,
|
|
79
|
-
use: () => use,
|
|
80
|
-
useChanged: () => useChanged,
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* Higher-Order Component (HOC) that injects `initData` into the state of the given class component.
|
|
86
|
-
*
|
|
87
|
-
* This HOC checks if the provided component is a class component. If it is, it wraps the component
|
|
88
|
-
* and injects the `initData` into its state. It also adds a listener
|
|
89
|
-
* to update the state when data changes, and removes the listener when the component unmounts.
|
|
90
|
-
*
|
|
91
|
-
* @typeParam P - The type of the props of the wrapped component.
|
|
92
|
-
* @typeParam S - The type of the state of the wrapped component.
|
|
93
|
-
*
|
|
94
|
-
* @param App - The class component to be wrapped by the HOC.
|
|
95
|
-
*
|
|
96
|
-
* @returns The original component if it is not a class component, otherwise a new class component
|
|
97
|
-
* with `initData` injection and state update functionality.
|
|
98
|
-
*
|
|
99
|
-
* @example
|
|
100
|
-
* ```typescript
|
|
101
|
-
* class App extends React.Component<MyProps, MyState> {
|
|
102
|
-
* // component implementation
|
|
103
|
-
* }
|
|
104
|
-
*
|
|
105
|
-
* export default withInitDataInState(App);
|
|
106
|
-
* ```
|
|
107
|
-
* @public
|
|
108
|
-
*/
|
|
109
|
-
export function withInitDataInState<P, S>(App: ComponentClass<P, S>): ComponentClass<P, S> {
|
|
110
|
-
const isClassComponent = 'prototype' in App && 'render' in App.prototype;
|
|
111
|
-
/* v8 ignore next 4 */
|
|
112
|
-
if (!isClassComponent) {
|
|
113
|
-
// return as-is when not class component
|
|
114
|
-
return App;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
class C extends App {
|
|
118
|
-
h?: () => void;
|
|
119
|
-
|
|
120
|
-
constructor(props: P) {
|
|
121
|
-
super(props);
|
|
122
|
-
this.state = {
|
|
123
|
-
...this.state,
|
|
124
|
-
...lynx.__initData,
|
|
125
|
-
};
|
|
126
|
-
|
|
127
|
-
if (!__LEPUS__) {
|
|
128
|
-
lynx.getJSModule('GlobalEventEmitter').addListener(
|
|
129
|
-
'onDataChanged',
|
|
130
|
-
this.h = () => {
|
|
131
|
-
globalFlushOptions.triggerDataUpdated = true;
|
|
132
|
-
this.setState(lynx.__initData as S);
|
|
133
|
-
},
|
|
134
|
-
);
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
override componentWillUnmount(): void {
|
|
139
|
-
super.componentWillUnmount?.();
|
|
140
|
-
if (!__LEPUS__) {
|
|
141
|
-
lynx.getJSModule('GlobalEventEmitter').removeListener(
|
|
142
|
-
'onDataChanged',
|
|
143
|
-
this.h!,
|
|
144
|
-
);
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
return C;
|
|
150
|
-
}
|
|
@@ -1,79 +0,0 @@
|
|
|
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 { Component } from 'preact';
|
|
5
|
-
import type { ReactNode } from 'react';
|
|
6
|
-
|
|
7
|
-
export function wrapWithLynxComponent(
|
|
8
|
-
jsxSnapshot: (c: ReactNode, spread?: Record<string, any>) => ReactNode,
|
|
9
|
-
jsxComponent: any,
|
|
10
|
-
): ReactNode {
|
|
11
|
-
const C = jsxComponent.type;
|
|
12
|
-
if (
|
|
13
|
-
typeof C === 'function' && (C === ComponentFromReactRuntime || C.prototype instanceof ComponentFromReactRuntime)
|
|
14
|
-
) {
|
|
15
|
-
if (jsxSnapshot.length === 1) {
|
|
16
|
-
return jsxSnapshot(jsxComponent);
|
|
17
|
-
} else {
|
|
18
|
-
// spread
|
|
19
|
-
if (!jsxComponent.props.removeComponentElement) {
|
|
20
|
-
return jsxSnapshot(jsxComponent, takeComponentAttributes(jsxComponent));
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
return jsxComponent;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
// @ts-expect-error
|
|
28
|
-
export class ComponentFromReactRuntime extends Component {}
|
|
29
|
-
|
|
30
|
-
const __COMPONENT_ATTRIBUTES__ = /* @__PURE__ */ new Set([
|
|
31
|
-
'name',
|
|
32
|
-
'style',
|
|
33
|
-
'class',
|
|
34
|
-
'flatten',
|
|
35
|
-
'clip-radius',
|
|
36
|
-
'overlap',
|
|
37
|
-
'user-interaction-enabled',
|
|
38
|
-
'native-interaction-enabled',
|
|
39
|
-
'block-native-event',
|
|
40
|
-
'enableLayoutOnly',
|
|
41
|
-
'cssAlignWithLegacyW3C',
|
|
42
|
-
'intersection-observers',
|
|
43
|
-
'trigger-global-event',
|
|
44
|
-
'exposure-scene',
|
|
45
|
-
'exposure-id',
|
|
46
|
-
'exposure-screen-margin-top',
|
|
47
|
-
'exposure-screen-margin-bottom',
|
|
48
|
-
'exposure-screen-margin-left',
|
|
49
|
-
'exposure-screen-margin-right',
|
|
50
|
-
'focusable',
|
|
51
|
-
'focus-index',
|
|
52
|
-
'accessibility-label',
|
|
53
|
-
'accessibility-element',
|
|
54
|
-
'accessibility-traits',
|
|
55
|
-
'enable-new-animator',
|
|
56
|
-
]);
|
|
57
|
-
|
|
58
|
-
function takeComponentAttributes(jsxComponent: any): Record<string, any> {
|
|
59
|
-
const attributes: Record<string, any> = {};
|
|
60
|
-
Object.keys(jsxComponent.props).forEach((k) => {
|
|
61
|
-
// let re1 = Regex::new(r"^(global-bind|bind|catch|capture-bind|capture-catch)([A-Za-z]+)$").unwrap();
|
|
62
|
-
// let re2 = Regex::new(r"^data-([A-Za-z]+)$").unwrap();
|
|
63
|
-
if (
|
|
64
|
-
__COMPONENT_ATTRIBUTES__.has(k)
|
|
65
|
-
|| k === 'id'
|
|
66
|
-
|| k === 'className'
|
|
67
|
-
|| k === 'dataSet'
|
|
68
|
-
|| k === 'data-set'
|
|
69
|
-
|| k === 'removeComponentElement'
|
|
70
|
-
|| (/^(global-bind|bind|catch|capture-bind|capture-catch)([A-Za-z]+)$/.exec(k))
|
|
71
|
-
|| (/^data-([A-Za-z]+)$/.exec(k))
|
|
72
|
-
) {
|
|
73
|
-
attributes[k] = jsxComponent.props[k];
|
|
74
|
-
delete jsxComponent.props[k];
|
|
75
|
-
}
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
return attributes;
|
|
79
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
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
|
-
const logDebug: (...args: any[]) => void = console.debug;
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* @internal
|
|
8
|
-
*/
|
|
9
|
-
export { logDebug };
|
|
@@ -1,28 +0,0 @@
|
|
|
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 { BackgroundSnapshotInstance } from '../backgroundSnapshot.js';
|
|
5
|
-
import { SnapshotInstance } from '../snapshot.js';
|
|
6
|
-
import { logDebug } from './debug.js';
|
|
7
|
-
|
|
8
|
-
export function printSnapshotInstance(
|
|
9
|
-
instance: BackgroundSnapshotInstance | SnapshotInstance,
|
|
10
|
-
log?: (...data: any[]) => void,
|
|
11
|
-
): void {
|
|
12
|
-
const impl = (
|
|
13
|
-
instance: BackgroundSnapshotInstance | SnapshotInstance,
|
|
14
|
-
level: number,
|
|
15
|
-
) => {
|
|
16
|
-
let msg = '';
|
|
17
|
-
for (let i = 0; i < level; ++i) {
|
|
18
|
-
msg += ' ';
|
|
19
|
-
}
|
|
20
|
-
msg += `| ${instance.__id}(${instance.type}): ${JSON.stringify(instance.__values)}`;
|
|
21
|
-
(log ?? logDebug)(msg);
|
|
22
|
-
for (const c of instance.childNodes) {
|
|
23
|
-
impl(c, level + 1);
|
|
24
|
-
}
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
impl(instance, 0);
|
|
28
|
-
}
|
|
@@ -1,55 +0,0 @@
|
|
|
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 { options } from 'preact';
|
|
5
|
-
import type { Component, ComponentClass, VNode } from 'preact';
|
|
6
|
-
|
|
7
|
-
import { COMPONENT, DIFF, DIFFED, RENDER } from '../renderToOpcodes/constants.js';
|
|
8
|
-
|
|
9
|
-
export function initProfileHook(): void {
|
|
10
|
-
const oldDiff = options[DIFF];
|
|
11
|
-
options[DIFF] = function(vnode: VNode) {
|
|
12
|
-
// This __PROFILE__ is used for DCE testing
|
|
13
|
-
if (__PROFILE__ && typeof vnode.type === 'function') {
|
|
14
|
-
// We only add profiling trace for Component
|
|
15
|
-
console.profile(`diff::${getDisplayName(vnode.type as ComponentClass)}`);
|
|
16
|
-
}
|
|
17
|
-
oldDiff?.(vnode);
|
|
18
|
-
};
|
|
19
|
-
const oldDiffed = options[DIFFED];
|
|
20
|
-
options[DIFFED] = function(vnode) {
|
|
21
|
-
// This __PROFILE__ is used for DCE testing
|
|
22
|
-
if (__PROFILE__ && typeof vnode.type === 'function') {
|
|
23
|
-
console.profileEnd(); // for options[DIFF]
|
|
24
|
-
}
|
|
25
|
-
oldDiffed?.(vnode);
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
// Profile the user-provided `render`.
|
|
29
|
-
const oldRender = options[RENDER];
|
|
30
|
-
options[RENDER] = function(vnode: VNode & { [COMPONENT]: Component }) {
|
|
31
|
-
const displayName = getDisplayName(vnode.type as ComponentClass);
|
|
32
|
-
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
33
|
-
const originalRender = vnode[COMPONENT].render;
|
|
34
|
-
vnode[COMPONENT].render = function render(this, props, state, context) {
|
|
35
|
-
// This __PROFILE__ is used for DCE testing
|
|
36
|
-
if (__PROFILE__) {
|
|
37
|
-
console.profile(`render::${displayName}`);
|
|
38
|
-
}
|
|
39
|
-
try {
|
|
40
|
-
return originalRender.call(this, props, state, context);
|
|
41
|
-
} finally {
|
|
42
|
-
// This __PROFILE__ is used for DCE testing
|
|
43
|
-
if (__PROFILE__) {
|
|
44
|
-
console.profileEnd();
|
|
45
|
-
}
|
|
46
|
-
vnode[COMPONENT].render = originalRender;
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
oldRender?.(vnode);
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
function getDisplayName(type: ComponentClass): string {
|
|
54
|
-
return type.displayName ?? type.name;
|
|
55
|
-
}
|
package/runtime/src/document.ts
DELETED
|
@@ -1,84 +0,0 @@
|
|
|
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 { BackgroundSnapshotInstance } from './backgroundSnapshot.js';
|
|
5
|
-
import { SnapshotInstance } from './snapshot.js';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* This module implements an Interface Adapter Pattern to integrate Preact's
|
|
9
|
-
* rendering system with Lynx's custom Snapshot-based virtual DOM.
|
|
10
|
-
*
|
|
11
|
-
* It works by:
|
|
12
|
-
* 1. Defining a minimal {@link Document}-like interface that Preact expects
|
|
13
|
-
* 2. Implementing this interface to return our {@link Snapshot} instances
|
|
14
|
-
* 3. Maintaining the same method signatures as the standard DOM API
|
|
15
|
-
*
|
|
16
|
-
* This allows Preact to build its virtual tree using our Snapshot system
|
|
17
|
-
* without knowing it's not working with a real DOM.
|
|
18
|
-
*/
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Defines the minimal document interface that Preact expects, depending on
|
|
22
|
-
* which thread is running.
|
|
23
|
-
*/
|
|
24
|
-
interface SnapshotDocumentAdapter {
|
|
25
|
-
createElement(type: string): BackgroundSnapshotInstance | SnapshotInstance;
|
|
26
|
-
createElementNS(ns: string | null, type: string): BackgroundSnapshotInstance | SnapshotInstance;
|
|
27
|
-
createTextNode(text: string): BackgroundSnapshotInstance | SnapshotInstance;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
const document: SnapshotDocumentAdapter = {} as SnapshotDocumentAdapter;
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Sets up the document interface for the background thread.
|
|
34
|
-
* All DOM operations are intercepted to create {@link BackgroundSnapshotInstance}.
|
|
35
|
-
*/
|
|
36
|
-
function setupBackgroundDocument(): void {
|
|
37
|
-
document.createElement = function(type: string) {
|
|
38
|
-
return new BackgroundSnapshotInstance(type);
|
|
39
|
-
};
|
|
40
|
-
document.createElementNS = function(_ns: string, type: string) {
|
|
41
|
-
return new BackgroundSnapshotInstance(type);
|
|
42
|
-
};
|
|
43
|
-
document.createTextNode = function(text: string) {
|
|
44
|
-
const i = new BackgroundSnapshotInstance(null as unknown as string);
|
|
45
|
-
i.setAttribute(0, text);
|
|
46
|
-
Object.defineProperty(i, 'data', {
|
|
47
|
-
set(v) {
|
|
48
|
-
i.setAttribute(0, v);
|
|
49
|
-
},
|
|
50
|
-
});
|
|
51
|
-
return i;
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Sets up the document interface for the main thread.
|
|
57
|
-
* All DOM operations are intercepted to create {@link SnapshotInstance}.
|
|
58
|
-
*/
|
|
59
|
-
function setupDocument(): void {
|
|
60
|
-
document.createElement = function(type: string) {
|
|
61
|
-
return new SnapshotInstance(type);
|
|
62
|
-
};
|
|
63
|
-
document.createElementNS = function(_ns: string, type: string) {
|
|
64
|
-
return new SnapshotInstance(type);
|
|
65
|
-
};
|
|
66
|
-
document.createTextNode = function(text: string) {
|
|
67
|
-
const i = new SnapshotInstance(null as unknown as string);
|
|
68
|
-
i.setAttribute(0, text);
|
|
69
|
-
Object.defineProperty(i, 'data', {
|
|
70
|
-
set(v) {
|
|
71
|
-
i.setAttribute(0, v);
|
|
72
|
-
},
|
|
73
|
-
});
|
|
74
|
-
return i;
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
// if (__JS__) {
|
|
79
|
-
// setupBackgroundDocument();
|
|
80
|
-
// } else if (__LEPUS__) {
|
|
81
|
-
// setupDocument();
|
|
82
|
-
// }
|
|
83
|
-
|
|
84
|
-
export { document, setupBackgroundDocument, setupDocument };
|
|
@@ -1,89 +0,0 @@
|
|
|
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 { GestureTypeInner } from './types.js';
|
|
7
|
-
import type { BaseGesture, ComposedGesture, GestureConfig, GestureKind } from './types.js';
|
|
8
|
-
|
|
9
|
-
function isSerializedGesture(gesture: GestureKind): boolean {
|
|
10
|
-
return gesture.__isSerialized ?? false;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
function getGestureInfo(
|
|
14
|
-
gesture: BaseGesture,
|
|
15
|
-
oldGesture: BaseGesture | undefined,
|
|
16
|
-
isFirstScreen: boolean,
|
|
17
|
-
dom: FiberElement,
|
|
18
|
-
) {
|
|
19
|
-
const config = {
|
|
20
|
-
callbacks: [],
|
|
21
|
-
} as GestureConfig;
|
|
22
|
-
const baseGesture = gesture;
|
|
23
|
-
|
|
24
|
-
if (baseGesture.config) {
|
|
25
|
-
config.config = baseGesture.config;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
for (
|
|
29
|
-
const key of Object.keys(baseGesture.callbacks)
|
|
30
|
-
) {
|
|
31
|
-
const callback = baseGesture.callbacks[key]!;
|
|
32
|
-
const oldCallback = oldGesture?.callbacks[key];
|
|
33
|
-
onWorkletCtxUpdate(callback, oldCallback, isFirstScreen, dom);
|
|
34
|
-
config.callbacks.push({
|
|
35
|
-
name: key,
|
|
36
|
-
callback: callback,
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
const relationMap = {
|
|
41
|
-
waitFor: baseGesture?.waitFor?.map(subGesture => subGesture.id) ?? [],
|
|
42
|
-
simultaneous: baseGesture?.simultaneousWith?.map(subGesture => subGesture.id) ?? [],
|
|
43
|
-
continueWith: baseGesture?.continueWith?.map(subGesture => subGesture.id) ?? [],
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
return {
|
|
47
|
-
config,
|
|
48
|
-
relationMap,
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export function processGesture(
|
|
53
|
-
dom: FiberElement,
|
|
54
|
-
gesture: GestureKind,
|
|
55
|
-
oldGesture: GestureKind | undefined,
|
|
56
|
-
isFirstScreen: boolean,
|
|
57
|
-
gestureOptions?: {
|
|
58
|
-
domSet: boolean;
|
|
59
|
-
},
|
|
60
|
-
): void {
|
|
61
|
-
if (!gesture || !isSerializedGesture(gesture)) {
|
|
62
|
-
return;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
if (!(gestureOptions && gestureOptions.domSet)) {
|
|
66
|
-
__SetAttribute(dom, 'has-react-gesture', true);
|
|
67
|
-
__SetAttribute(dom, 'flatten', false);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
if (gesture.type === GestureTypeInner.COMPOSED) {
|
|
71
|
-
for (const [index, subGesture] of (gesture as ComposedGesture).gestures.entries()) {
|
|
72
|
-
processGesture(dom, subGesture, (oldGesture as ComposedGesture)?.gestures[index], isFirstScreen, {
|
|
73
|
-
domSet: true,
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
} else {
|
|
77
|
-
const baseGesture = gesture as BaseGesture;
|
|
78
|
-
const oldBaseGesture = oldGesture as BaseGesture | undefined;
|
|
79
|
-
|
|
80
|
-
const { config, relationMap } = getGestureInfo(baseGesture, oldBaseGesture, isFirstScreen, dom);
|
|
81
|
-
__SetGestureDetector(
|
|
82
|
-
dom,
|
|
83
|
-
baseGesture.id,
|
|
84
|
-
baseGesture.type,
|
|
85
|
-
config,
|
|
86
|
-
relationMap,
|
|
87
|
-
);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
// Copyright 2025 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 { GestureTypeInner } from './types.js';
|
|
5
|
-
import type { BaseGesture, ComposedGesture, GestureKind } from './types.js';
|
|
6
|
-
import { onPostWorkletCtx } from '../worklet/ctx.js';
|
|
7
|
-
|
|
8
|
-
export function processGestureBackground(gesture: GestureKind): void {
|
|
9
|
-
if (gesture.type === GestureTypeInner.COMPOSED) {
|
|
10
|
-
for (const subGesture of (gesture as ComposedGesture).gestures) {
|
|
11
|
-
processGestureBackground(subGesture);
|
|
12
|
-
}
|
|
13
|
-
} else {
|
|
14
|
-
const baseGesture = gesture as BaseGesture;
|
|
15
|
-
for (const [name, value] of Object.entries(baseGesture.callbacks)) {
|
|
16
|
-
baseGesture.callbacks[name] = onPostWorkletCtx(value)!;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
// Copyright 2025 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 } from '@lynx-js/react/worklet-runtime/bindings';
|
|
5
|
-
|
|
6
|
-
export enum GestureTypeInner {
|
|
7
|
-
COMPOSED = -1,
|
|
8
|
-
PAN = 0,
|
|
9
|
-
FLING = 1,
|
|
10
|
-
DEFAULT = 2,
|
|
11
|
-
TAP = 3,
|
|
12
|
-
LONGPRESS = 4,
|
|
13
|
-
ROTATION = 5,
|
|
14
|
-
PINCH = 6,
|
|
15
|
-
NATIVE = 7,
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export interface GestureKind {
|
|
19
|
-
type: GestureTypeInner;
|
|
20
|
-
__isSerialized?: boolean;
|
|
21
|
-
__isGesture?: boolean;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export interface ComposedGesture extends GestureKind {
|
|
25
|
-
type: GestureTypeInner.COMPOSED;
|
|
26
|
-
gestures: GestureKind[];
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export interface BaseGesture extends GestureKind {
|
|
30
|
-
id: number;
|
|
31
|
-
callbacks: Record<string, Worklet>;
|
|
32
|
-
waitFor: BaseGesture[];
|
|
33
|
-
simultaneousWith: BaseGesture[];
|
|
34
|
-
continueWith: BaseGesture[];
|
|
35
|
-
config?: Record<string, unknown>;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export interface GestureConfig {
|
|
39
|
-
callbacks: {
|
|
40
|
-
name: string;
|
|
41
|
-
callback: Worklet;
|
|
42
|
-
}[];
|
|
43
|
-
config?: Record<string, unknown>;
|
|
44
|
-
}
|
|
@@ -1,62 +0,0 @@
|
|
|
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
|
-
useCallback,
|
|
6
|
-
useContext,
|
|
7
|
-
useDebugValue,
|
|
8
|
-
useErrorBoundary,
|
|
9
|
-
useId,
|
|
10
|
-
useImperativeHandle,
|
|
11
|
-
useMemo,
|
|
12
|
-
useEffect as usePreactEffect,
|
|
13
|
-
useReducer,
|
|
14
|
-
useRef,
|
|
15
|
-
useState,
|
|
16
|
-
} from 'preact/hooks';
|
|
17
|
-
import type { DependencyList, EffectCallback } from 'react';
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* `useLayoutEffect` is now an alias of `useEffect`. Use `useEffect` instead.
|
|
21
|
-
*
|
|
22
|
-
* Accepts a function that contains imperative, possibly effectful code. The effects run after main thread dom update without blocking it.
|
|
23
|
-
*
|
|
24
|
-
* @param effect - Imperative function that can return a cleanup function
|
|
25
|
-
* @param deps - If present, effect will only activate if the values in the list change (using ===).
|
|
26
|
-
*
|
|
27
|
-
* @public
|
|
28
|
-
*
|
|
29
|
-
* @deprecated `useLayoutEffect` in the background thread cannot offer the precise timing for reading layout information and synchronously re-render, which is different from React.
|
|
30
|
-
*/
|
|
31
|
-
function useLayoutEffect(effect: EffectCallback, deps?: DependencyList): void {
|
|
32
|
-
return usePreactEffect(effect, deps);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Accepts a function that contains imperative, possibly effectful code.
|
|
37
|
-
* The effects run after main thread dom update without blocking it.
|
|
38
|
-
*
|
|
39
|
-
* @param effect - Imperative function that can return a cleanup function
|
|
40
|
-
* @param deps - If present, effect will only activate if the values in the list change (using ===).
|
|
41
|
-
*
|
|
42
|
-
* @public
|
|
43
|
-
*/
|
|
44
|
-
function useEffect(effect: EffectCallback, deps?: DependencyList): void {
|
|
45
|
-
return usePreactEffect(effect, deps);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export {
|
|
49
|
-
// preact
|
|
50
|
-
useState,
|
|
51
|
-
useReducer,
|
|
52
|
-
useRef,
|
|
53
|
-
useImperativeHandle,
|
|
54
|
-
useLayoutEffect,
|
|
55
|
-
useEffect,
|
|
56
|
-
useCallback,
|
|
57
|
-
useMemo,
|
|
58
|
-
useContext,
|
|
59
|
-
useDebugValue,
|
|
60
|
-
useErrorBoundary,
|
|
61
|
-
useId,
|
|
62
|
-
};
|
|
@@ -1,59 +0,0 @@
|
|
|
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 { useEffect, useMemo, useRef } from 'preact/hooks';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* `useLynxGlobalEventListener` help you `addListener` as early as possible.
|
|
8
|
-
*
|
|
9
|
-
* @example
|
|
10
|
-
*
|
|
11
|
-
* Use this hooks to listen to event 'exposure' and event 'disexposure'
|
|
12
|
-
*
|
|
13
|
-
* ```jsx
|
|
14
|
-
* function App() {
|
|
15
|
-
* useLynxGlobalEventListener('exposure', (e) => {
|
|
16
|
-
* console.log("exposure", e)
|
|
17
|
-
* })
|
|
18
|
-
* useLynxGlobalEventListener('disexposure', (e) => {
|
|
19
|
-
* console.log("disexposure", e)
|
|
20
|
-
* })
|
|
21
|
-
* return (
|
|
22
|
-
* <view
|
|
23
|
-
* style='width: 100px; height: 100px; background-color: red;'
|
|
24
|
-
* exposure-id='a'
|
|
25
|
-
* />
|
|
26
|
-
* )
|
|
27
|
-
* }
|
|
28
|
-
* ```
|
|
29
|
-
*
|
|
30
|
-
* @param eventName - Event name to listen
|
|
31
|
-
* @param listener - Event handler
|
|
32
|
-
* @public
|
|
33
|
-
*/
|
|
34
|
-
export function useLynxGlobalEventListener<T extends (...args: any[]) => void>(
|
|
35
|
-
eventName: string,
|
|
36
|
-
listener: T,
|
|
37
|
-
): void {
|
|
38
|
-
'background only';
|
|
39
|
-
|
|
40
|
-
const previousArgsRef = useRef<[string, T]>();
|
|
41
|
-
|
|
42
|
-
useMemo(() => {
|
|
43
|
-
if (previousArgsRef.current) {
|
|
44
|
-
const [eventName, listener] = previousArgsRef.current;
|
|
45
|
-
lynx.getJSModule('GlobalEventEmitter').removeListener(eventName, listener);
|
|
46
|
-
}
|
|
47
|
-
lynx.getJSModule('GlobalEventEmitter').addListener(eventName, listener);
|
|
48
|
-
previousArgsRef.current = [eventName, listener];
|
|
49
|
-
}, [eventName, listener]);
|
|
50
|
-
|
|
51
|
-
useEffect(() => {
|
|
52
|
-
return () => {
|
|
53
|
-
if (previousArgsRef.current) {
|
|
54
|
-
const [eventName, listener] = previousArgsRef.current;
|
|
55
|
-
lynx.getJSModule('GlobalEventEmitter').removeListener(eventName, listener);
|
|
56
|
-
}
|
|
57
|
-
};
|
|
58
|
-
}, []);
|
|
59
|
-
}
|