@lynx-js/react 0.111.1 → 0.111.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +52 -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/src/DeferredListItem.tsx +5 -3
- package/package.json +6 -1
- package/refresh/.turbo/turbo-build.log +1 -1
- package/runtime/debug/index.cjs +8 -0
- package/runtime/debug/index.d.ts +4 -0
- package/runtime/debug/index.js +5 -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 +1 -3
- 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/lifecycle/patch/commit.js +1 -1
- package/runtime/lib/lifecycle/patch/commit.js.map +1 -1
- 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/lynx.js +9 -0
- 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/root.d.ts +6 -0
- package/runtime/lib/root.js +4 -0
- package/runtime/lib/root.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.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 +12 -4
- package/types/react.d.ts +13 -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
package/runtime/src/lynx-api.ts
DELETED
|
@@ -1,455 +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 { render } from 'preact';
|
|
5
|
-
import { createContext, createElement } from 'preact/compat';
|
|
6
|
-
import { useState } from 'preact/hooks';
|
|
7
|
-
import type { Consumer, FC, ReactNode } from 'react';
|
|
8
|
-
|
|
9
|
-
import { factory, withInitDataInState } from './compat/initData.js';
|
|
10
|
-
import { useLynxGlobalEventListener } from './hooks/useLynxGlobalEventListener.js';
|
|
11
|
-
import { LifecycleConstant } from './lifecycleConstant.js';
|
|
12
|
-
import { flushDelayedLifecycleEvents } from './lynx/tt.js';
|
|
13
|
-
import { __root } from './root.js';
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* The default root exported by `@lynx-js/react` for you to render a JSX
|
|
17
|
-
* @public
|
|
18
|
-
*/
|
|
19
|
-
export interface Root {
|
|
20
|
-
/**
|
|
21
|
-
* Use this API to pass in your JSX to render
|
|
22
|
-
*
|
|
23
|
-
* @example
|
|
24
|
-
*
|
|
25
|
-
* ```ts
|
|
26
|
-
* import { root } from "@lynx-js/react"
|
|
27
|
-
*
|
|
28
|
-
* function App() {
|
|
29
|
-
* // Your app
|
|
30
|
-
* return <view>...</view>
|
|
31
|
-
* }
|
|
32
|
-
*
|
|
33
|
-
* root.render(<App/>);
|
|
34
|
-
* ```
|
|
35
|
-
*
|
|
36
|
-
* @example
|
|
37
|
-
*
|
|
38
|
-
* ```tsx
|
|
39
|
-
* import { root } from "@lynx-js/react"
|
|
40
|
-
*
|
|
41
|
-
* function App() {
|
|
42
|
-
* // Your app
|
|
43
|
-
* return <view>...</view>
|
|
44
|
-
* }
|
|
45
|
-
*
|
|
46
|
-
* if (__MAIN_THREAD__) {
|
|
47
|
-
* root.render(
|
|
48
|
-
* <DataProvider data={DEFAULT_DATA}>
|
|
49
|
-
* <App/>
|
|
50
|
-
* </DataProvider>
|
|
51
|
-
* );
|
|
52
|
-
* } else if (__BACKGROUND__) {
|
|
53
|
-
* fetchData().then((data) => {
|
|
54
|
-
* root.render(
|
|
55
|
-
* <DataProvider data={data}>
|
|
56
|
-
* <App/>
|
|
57
|
-
* </DataProvider>
|
|
58
|
-
* ); // You can render later after your data is ready
|
|
59
|
-
* })
|
|
60
|
-
* }
|
|
61
|
-
* ```
|
|
62
|
-
*
|
|
63
|
-
* @public
|
|
64
|
-
*/
|
|
65
|
-
render: (jsx: ReactNode) => void;
|
|
66
|
-
/**
|
|
67
|
-
* {@inheritDoc Lynx.registerDataProcessors}
|
|
68
|
-
* @deprecated use {@link Lynx.registerDataProcessors | lynx.registerDataProcessors} instead
|
|
69
|
-
* @public
|
|
70
|
-
*/
|
|
71
|
-
registerDataProcessors: (dataProcessorDefinition: DataProcessorDefinition) => void;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* The default and only root of ReactLynx for you to render JSX
|
|
76
|
-
* @example
|
|
77
|
-
* ```ts
|
|
78
|
-
* import { root } from "@lynx-js/react"
|
|
79
|
-
* ```
|
|
80
|
-
*
|
|
81
|
-
* @public
|
|
82
|
-
*/
|
|
83
|
-
export const root: Root = {
|
|
84
|
-
render: (jsx: ReactNode): void => {
|
|
85
|
-
if (__MAIN_THREAD__) {
|
|
86
|
-
__root.__jsx = jsx;
|
|
87
|
-
} else {
|
|
88
|
-
__root.__jsx = jsx;
|
|
89
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
90
|
-
render(jsx, __root as any);
|
|
91
|
-
if (__FIRST_SCREEN_SYNC_TIMING__ === 'immediately') {
|
|
92
|
-
// This is for cases where `root.render()` is called asynchronously,
|
|
93
|
-
// `firstScreen` message might have been reached.
|
|
94
|
-
flushDelayedLifecycleEvents();
|
|
95
|
-
} else {
|
|
96
|
-
lynx.getNativeApp().callLepusMethod(LifecycleConstant.jsReady, {});
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
},
|
|
100
|
-
registerDataProcessors: (dataProcessorDefinition: DataProcessorDefinition): void => {
|
|
101
|
-
lynx.registerDataProcessors(dataProcessorDefinition);
|
|
102
|
-
},
|
|
103
|
-
};
|
|
104
|
-
|
|
105
|
-
const _InitData = /* @__PURE__ */ factory<InitData>(
|
|
106
|
-
{
|
|
107
|
-
createContext,
|
|
108
|
-
useState,
|
|
109
|
-
createElement,
|
|
110
|
-
useLynxGlobalEventListener,
|
|
111
|
-
},
|
|
112
|
-
'__initData',
|
|
113
|
-
'onDataChanged',
|
|
114
|
-
);
|
|
115
|
-
/**
|
|
116
|
-
* The {@link https://react.dev/reference/react/createContext#provider | Provider} Component that provide `initData`,
|
|
117
|
-
* you must wrap your JSX inside it
|
|
118
|
-
* @group Components
|
|
119
|
-
*
|
|
120
|
-
* @example
|
|
121
|
-
*
|
|
122
|
-
* ```ts
|
|
123
|
-
* import { root } from "@lynx-js/react"
|
|
124
|
-
*
|
|
125
|
-
* function App() {
|
|
126
|
-
* return (
|
|
127
|
-
* <InitDataConsumer children={(initData) => <view>...</view>}/>
|
|
128
|
-
* )
|
|
129
|
-
* }
|
|
130
|
-
*
|
|
131
|
-
* root.render(
|
|
132
|
-
* <InitDataProvider>
|
|
133
|
-
* <App/>
|
|
134
|
-
* </InitDataProvider>
|
|
135
|
-
* );
|
|
136
|
-
*
|
|
137
|
-
* ```
|
|
138
|
-
*
|
|
139
|
-
* @public
|
|
140
|
-
*/
|
|
141
|
-
// @ts-expect-error make preact and react types work
|
|
142
|
-
export const InitDataProvider: FC<{ children?: ReactNode | undefined }> = /* @__PURE__ */ _InitData.Provider();
|
|
143
|
-
/**
|
|
144
|
-
* The {@link https://react.dev/reference/react/createContext#consumer | Consumer} Component that provide `initData`.
|
|
145
|
-
* This should be used with {@link InitDataProvider}
|
|
146
|
-
* @group Components
|
|
147
|
-
* @public
|
|
148
|
-
*/
|
|
149
|
-
// @ts-expect-error make preact and react types work
|
|
150
|
-
export const InitDataConsumer: Consumer<InitData> = /* @__PURE__ */ _InitData.Consumer();
|
|
151
|
-
/**
|
|
152
|
-
* A React Hooks for you to get `initData`.
|
|
153
|
-
* If `initData` is changed, a re-render will be triggered automatically.
|
|
154
|
-
*
|
|
155
|
-
* @example
|
|
156
|
-
*
|
|
157
|
-
* ```ts
|
|
158
|
-
* function App() {
|
|
159
|
-
* const initData = useInitData();
|
|
160
|
-
*
|
|
161
|
-
* initData.someProperty // use it
|
|
162
|
-
* }
|
|
163
|
-
* ```
|
|
164
|
-
*
|
|
165
|
-
* @public
|
|
166
|
-
*/
|
|
167
|
-
export const useInitData: () => InitData = /* @__PURE__ */ _InitData.use();
|
|
168
|
-
/**
|
|
169
|
-
* A React Hooks for you to get notified when `initData` changed.
|
|
170
|
-
*
|
|
171
|
-
* @example
|
|
172
|
-
* ```ts
|
|
173
|
-
* function App() {
|
|
174
|
-
* useInitDataChanged((data) => {
|
|
175
|
-
* data.someProperty // can use it
|
|
176
|
-
* })
|
|
177
|
-
* }
|
|
178
|
-
* ```
|
|
179
|
-
* @public
|
|
180
|
-
*/
|
|
181
|
-
export const useInitDataChanged: (callback: (data: InitData) => void) => void = /* @__PURE__ */ _InitData.useChanged();
|
|
182
|
-
|
|
183
|
-
// const {
|
|
184
|
-
// Provider: GlobalPropsProvider,
|
|
185
|
-
// Consumer: GlobalPropsConsumer,
|
|
186
|
-
// // InitDataContext,
|
|
187
|
-
// use: useGlobalProps,
|
|
188
|
-
// useChanged: useGlobalPropsChanged,
|
|
189
|
-
// } = /* @__PURE__ */ factory(
|
|
190
|
-
// {
|
|
191
|
-
// createContext,
|
|
192
|
-
// useState,
|
|
193
|
-
// useEffect,
|
|
194
|
-
// createElement,
|
|
195
|
-
// } as any,
|
|
196
|
-
// "__globalProps",
|
|
197
|
-
// "onGlobalPropsChanged"
|
|
198
|
-
// );
|
|
199
|
-
|
|
200
|
-
// export { GlobalPropsProvider, GlobalPropsConsumer, useGlobalProps, useGlobalPropsChanged };
|
|
201
|
-
|
|
202
|
-
/**
|
|
203
|
-
* The interface you can extends so that the `defaultDataProcessor` parameter can be customized
|
|
204
|
-
*
|
|
205
|
-
* Should be used with `lynx.registerDataProcessors`. See more examples at {@link Lynx.registerDataProcessors}.
|
|
206
|
-
*
|
|
207
|
-
* @public
|
|
208
|
-
*/
|
|
209
|
-
export interface InitDataRaw {}
|
|
210
|
-
/**
|
|
211
|
-
* The interface you can extends so that the `defaultDataProcessor` returning value can be customized
|
|
212
|
-
*
|
|
213
|
-
* Should be used with `lynx.registerDataProcessors`. See more examples at {@link Lynx.registerDataProcessors}.
|
|
214
|
-
*
|
|
215
|
-
* @public
|
|
216
|
-
*/
|
|
217
|
-
export interface InitData {}
|
|
218
|
-
|
|
219
|
-
export { withInitDataInState };
|
|
220
|
-
|
|
221
|
-
/**
|
|
222
|
-
* The data processors that registered with {@link Lynx.registerDataProcessors}.
|
|
223
|
-
*
|
|
224
|
-
* @example
|
|
225
|
-
*
|
|
226
|
-
* Extending `dataProcessors` interface
|
|
227
|
-
*
|
|
228
|
-
* ```ts
|
|
229
|
-
* import type { DataProcessors as WellKnownDataProcessors } from '@lynx-js/react';
|
|
230
|
-
*
|
|
231
|
-
* declare module '@lynx-js/react' {
|
|
232
|
-
* interface DataProcessors extends WellKnownDataProcessors {
|
|
233
|
-
* foo(bar: string): number;
|
|
234
|
-
* }
|
|
235
|
-
* }
|
|
236
|
-
* ```
|
|
237
|
-
*
|
|
238
|
-
* Then you can use `lynx.registerDataProcessors` with types.
|
|
239
|
-
*
|
|
240
|
-
* ```js
|
|
241
|
-
* lynx.registerDataProcessors({
|
|
242
|
-
* dataProcessors: {
|
|
243
|
-
* foo(bar) {
|
|
244
|
-
* return 1;
|
|
245
|
-
* }
|
|
246
|
-
* }
|
|
247
|
-
* })
|
|
248
|
-
* ```
|
|
249
|
-
*
|
|
250
|
-
* @public
|
|
251
|
-
*/
|
|
252
|
-
export interface DataProcessors {
|
|
253
|
-
/**
|
|
254
|
-
* Optional processor to override screen metrics used by the app
|
|
255
|
-
*
|
|
256
|
-
* @param metrics - The physical screen dimensions in pixels
|
|
257
|
-
*
|
|
258
|
-
* @returns New screen dimensions to be used by the app
|
|
259
|
-
*
|
|
260
|
-
* @example
|
|
261
|
-
*
|
|
262
|
-
* ```ts
|
|
263
|
-
* lynx.registerDataProcessors({
|
|
264
|
-
* dataProcessors: {
|
|
265
|
-
* getScreenMetricsOverride: (metrics) => {
|
|
266
|
-
* // Force a specific aspect ratio
|
|
267
|
-
* return {
|
|
268
|
-
* width: metrics.width,
|
|
269
|
-
* height: metrics.width * (16/9)
|
|
270
|
-
* };
|
|
271
|
-
* }
|
|
272
|
-
* }
|
|
273
|
-
* });
|
|
274
|
-
* ```
|
|
275
|
-
*/
|
|
276
|
-
getScreenMetricsOverride?(metrics: {
|
|
277
|
-
/**
|
|
278
|
-
* The physical pixel width of the screen
|
|
279
|
-
*/
|
|
280
|
-
width: number;
|
|
281
|
-
/**
|
|
282
|
-
* The physical pixel height of the screen
|
|
283
|
-
*/
|
|
284
|
-
height: number;
|
|
285
|
-
}): { width: number; height: number };
|
|
286
|
-
|
|
287
|
-
/**
|
|
288
|
-
* Custom unknown data processors.
|
|
289
|
-
*
|
|
290
|
-
* @remarks
|
|
291
|
-
*
|
|
292
|
-
* You may extends the `DataProcessors` interface for better TypeScript types. See {@link DataProcessors}.
|
|
293
|
-
*/
|
|
294
|
-
[processorName: string]: (...args: any[]) => any;
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
/**
|
|
298
|
-
* Definition of DataProcessor(s)
|
|
299
|
-
* @public
|
|
300
|
-
*/
|
|
301
|
-
export interface DataProcessorDefinition {
|
|
302
|
-
/**
|
|
303
|
-
* You can custom input and output type of `defaultDataProcessor` by extends {@link InitDataRaw} and {@link InitData}
|
|
304
|
-
*
|
|
305
|
-
* Should be used with `lynx.registerDataProcessors`. See more examples at {@link Lynx.registerDataProcessors}.
|
|
306
|
-
*
|
|
307
|
-
* @param rawInitData - initData passed from native code
|
|
308
|
-
* @returns
|
|
309
|
-
* @public
|
|
310
|
-
*/
|
|
311
|
-
defaultDataProcessor?: (rawInitData: InitDataRaw) => InitData;
|
|
312
|
-
/**
|
|
313
|
-
* Should be used with `lynx.registerDataProcessors`. See more examples at {@link Lynx.registerDataProcessors}.
|
|
314
|
-
*
|
|
315
|
-
* @public
|
|
316
|
-
*/
|
|
317
|
-
dataProcessors?: DataProcessors;
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
/**
|
|
321
|
-
* APIs under `lynx` global variable that added by ReactLynx.
|
|
322
|
-
*
|
|
323
|
-
* @example
|
|
324
|
-
*
|
|
325
|
-
* ```ts
|
|
326
|
-
* lynx.registerDataProcessors(...);
|
|
327
|
-
* lynx.querySelector(...);
|
|
328
|
-
* lynx.querySelectorAll(...);
|
|
329
|
-
* ```
|
|
330
|
-
*
|
|
331
|
-
* @public
|
|
332
|
-
*/
|
|
333
|
-
export interface Lynx {
|
|
334
|
-
/**
|
|
335
|
-
* An alias of `lynx.getJSModule("GlobalEventEmitter").trigger(eventName, params)` only in Lepus
|
|
336
|
-
*
|
|
337
|
-
* @public
|
|
338
|
-
*/
|
|
339
|
-
triggerGlobalEventFromLepus: (eventName: string, params: any) => void;
|
|
340
|
-
|
|
341
|
-
/**
|
|
342
|
-
* Register DataProcessors. You MUST call this before `root.render()`.
|
|
343
|
-
*
|
|
344
|
-
* @example
|
|
345
|
-
*
|
|
346
|
-
* You MUST call `lynx.registerDataProcessors` before calling `root.render()`.
|
|
347
|
-
*
|
|
348
|
-
* ```ts
|
|
349
|
-
* import { root } from "@lynx-js/react"
|
|
350
|
-
*
|
|
351
|
-
* // You MUST call this before `root.render()`
|
|
352
|
-
* lynx.registerDataProcessors({
|
|
353
|
-
* defaultDataProcessor: () => {...} // default DataProcessor
|
|
354
|
-
* dataProcessors: {
|
|
355
|
-
* getScreenMetricsOverride: () => {...} // named DataProcessor
|
|
356
|
-
* }
|
|
357
|
-
* })
|
|
358
|
-
*
|
|
359
|
-
* root.render(<App/>);
|
|
360
|
-
* ```
|
|
361
|
-
*
|
|
362
|
-
* @example
|
|
363
|
-
*
|
|
364
|
-
* If you have a class component with `static defaultDataProcessor`
|
|
365
|
-
* or `static dataProcessors`, you can use it to register DataProcessors.
|
|
366
|
-
*
|
|
367
|
-
* ```ts
|
|
368
|
-
* import { root, Component } from "@lynx-js/react"
|
|
369
|
-
*
|
|
370
|
-
* class App extends Component {
|
|
371
|
-
* static defaultDataProcessor() {
|
|
372
|
-
* ...
|
|
373
|
-
* }
|
|
374
|
-
*
|
|
375
|
-
* static dataProcessors = {
|
|
376
|
-
* getScreenMetricsOverride() {
|
|
377
|
-
* ...
|
|
378
|
-
* }
|
|
379
|
-
* }
|
|
380
|
-
* }
|
|
381
|
-
*
|
|
382
|
-
* lynx.registerDataProcessors(App); // You can pass `App` because it has the required shape
|
|
383
|
-
* root.render(<App/>);
|
|
384
|
-
* ```
|
|
385
|
-
*
|
|
386
|
-
* @example
|
|
387
|
-
*
|
|
388
|
-
* For developers who want fully typed `defaultDataProcessor`,
|
|
389
|
-
* they can achieve it by extends interface `InitDataRaw` and `InitData`.
|
|
390
|
-
*
|
|
391
|
-
* ```ts
|
|
392
|
-
* import { root } from "@lynx-js/react"
|
|
393
|
-
*
|
|
394
|
-
* interface ExistingInterface {
|
|
395
|
-
* somePropertyFromExistingInterface: number
|
|
396
|
-
* }
|
|
397
|
-
*
|
|
398
|
-
* declare module '@lynx-js/react' {
|
|
399
|
-
* interface InitDataRaw extends ExistingInterface {
|
|
400
|
-
* someAnotherCustomProperty: string
|
|
401
|
-
* }
|
|
402
|
-
* }
|
|
403
|
-
*
|
|
404
|
-
* lynx.registerDataProcessors({
|
|
405
|
-
* defaultDataProcessor: (initDataRaw) => {
|
|
406
|
-
* initDataRaw.somePropertyFromExistingInterface // will be typed
|
|
407
|
-
* }
|
|
408
|
-
* })
|
|
409
|
-
*
|
|
410
|
-
* ```
|
|
411
|
-
*
|
|
412
|
-
* @example
|
|
413
|
-
*
|
|
414
|
-
* For developers who want fully typed `defaultDataProcessor`,
|
|
415
|
-
* they can achieve it by extends interface `InitDataRaw` and `InitData`.
|
|
416
|
-
*
|
|
417
|
-
* ```ts
|
|
418
|
-
* import { root, useInitData } from "@lynx-js/react"
|
|
419
|
-
*
|
|
420
|
-
* interface AnotherExistingInterface {
|
|
421
|
-
* someAnotherPropertyFromExistingInterface: number
|
|
422
|
-
* }
|
|
423
|
-
*
|
|
424
|
-
* declare module '@lynx-js/react' {
|
|
425
|
-
* interface InitData extends AnotherExistingInterface {
|
|
426
|
-
* someCustomProperty: string
|
|
427
|
-
* }
|
|
428
|
-
* }
|
|
429
|
-
*
|
|
430
|
-
* root.registerDataProcessors({
|
|
431
|
-
* defaultDataProcessor: () => {
|
|
432
|
-
* return {
|
|
433
|
-
* someCustomProperty: 'value', // will be typed
|
|
434
|
-
* someAnotherPropertyFromExistingInterface: 1, // will be typed
|
|
435
|
-
* }
|
|
436
|
-
* }
|
|
437
|
-
* })
|
|
438
|
-
*
|
|
439
|
-
* function App() {
|
|
440
|
-
* const initData = useInitData();
|
|
441
|
-
*
|
|
442
|
-
* initData.someCustomProperty // will be typed
|
|
443
|
-
* initData.someAnotherPropertyFromExistingInterface // will be typed
|
|
444
|
-
* }
|
|
445
|
-
*
|
|
446
|
-
* ```
|
|
447
|
-
* @public
|
|
448
|
-
*/
|
|
449
|
-
registerDataProcessors: (dataProcessorDefinition?: DataProcessorDefinition) => void;
|
|
450
|
-
}
|
|
451
|
-
|
|
452
|
-
export { useLynxGlobalEventListener } from './hooks/useLynxGlobalEventListener.js';
|
|
453
|
-
export { runOnBackground } from './worklet/runOnBackground.js';
|
|
454
|
-
export { runOnMainThread } from './worklet/runOnMainThread.js';
|
|
455
|
-
export { MainThreadRef, useMainThreadRef } from './worklet/workletRef.js';
|
package/runtime/src/lynx.ts
DELETED
|
@@ -1,58 +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
|
-
// to make sure preact's hooks to register earlier than ours
|
|
6
|
-
import './hooks/react.js';
|
|
7
|
-
|
|
8
|
-
import { initProfileHook } from './debug/profile.js';
|
|
9
|
-
import { document, setupBackgroundDocument } from './document.js';
|
|
10
|
-
import { replaceCommitHook } from './lifecycle/patch/commit.js';
|
|
11
|
-
import { addCtxNotFoundEventListener } from './lifecycle/patch/error.js';
|
|
12
|
-
import { injectUpdateMainThread } from './lifecycle/patch/updateMainThread.js';
|
|
13
|
-
import { injectCalledByNative } from './lynx/calledByNative.js';
|
|
14
|
-
import { setupLynxEnv } from './lynx/env.js';
|
|
15
|
-
import { injectLepusMethods } from './lynx/injectLepusMethods.js';
|
|
16
|
-
import { initTimingAPI } from './lynx/performance.js';
|
|
17
|
-
import { injectTt } from './lynx/tt.js';
|
|
18
|
-
|
|
19
|
-
export { runWithForce } from './lynx/runWithForce.js';
|
|
20
|
-
|
|
21
|
-
// @ts-expect-error Element implicitly has an 'any' type because type 'typeof globalThis' has no index signature
|
|
22
|
-
if (__MAIN_THREAD__ && typeof globalThis.processEvalResult === 'undefined') {
|
|
23
|
-
// @ts-expect-error Element implicitly has an 'any' type because type 'typeof globalThis' has no index signature
|
|
24
|
-
globalThis.processEvalResult = <T>(result: ((schema: string) => T) | undefined, schema: string) => {
|
|
25
|
-
return result?.(schema);
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
if (__MAIN_THREAD__) {
|
|
30
|
-
injectCalledByNative();
|
|
31
|
-
injectUpdateMainThread();
|
|
32
|
-
if (__DEV__) {
|
|
33
|
-
injectLepusMethods();
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
// TODO: replace this with __PROFILE__
|
|
38
|
-
if (__PROFILE__) {
|
|
39
|
-
// We are profiling both main-thread and background.
|
|
40
|
-
initProfileHook();
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
if (__BACKGROUND__) {
|
|
44
|
-
// Trick Preact and TypeScript to accept our custom document adapter.
|
|
45
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
46
|
-
options.document = document as any;
|
|
47
|
-
setupBackgroundDocument();
|
|
48
|
-
injectTt();
|
|
49
|
-
addCtxNotFoundEventListener();
|
|
50
|
-
|
|
51
|
-
if (process.env['NODE_ENV'] === 'test') {}
|
|
52
|
-
else {
|
|
53
|
-
replaceCommitHook();
|
|
54
|
-
initTimingAPI();
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
setupLynxEnv();
|
package/runtime/src/opcodes.ts
DELETED
|
@@ -1,155 +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 { hydrate } from './hydrate.js';
|
|
5
|
-
import { componentAtIndexFactory, enqueueComponentFactory, gRecycleMap, gSignMap } from './list.js';
|
|
6
|
-
import { CHILDREN } from './renderToOpcodes/constants.js';
|
|
7
|
-
import { SnapshotInstance } from './snapshot.js';
|
|
8
|
-
|
|
9
|
-
const enum Opcode {
|
|
10
|
-
Begin = 0,
|
|
11
|
-
End,
|
|
12
|
-
Attr,
|
|
13
|
-
Text,
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
interface SSRFiberElement {
|
|
17
|
-
ssrID: string;
|
|
18
|
-
}
|
|
19
|
-
export type SSRSnapshotInstance = [string, number, SSRFiberElement[]];
|
|
20
|
-
|
|
21
|
-
export function ssrHydrateByOpcodes(
|
|
22
|
-
opcodes: any[],
|
|
23
|
-
into: SnapshotInstance,
|
|
24
|
-
refMap?: Record<string, FiberElement>,
|
|
25
|
-
): void {
|
|
26
|
-
let top: SnapshotInstance & { __pendingElements?: SSRFiberElement[] } = into;
|
|
27
|
-
const stack: SnapshotInstance[] = [into];
|
|
28
|
-
for (let i = 0; i < opcodes.length;) {
|
|
29
|
-
const opcode = opcodes[i];
|
|
30
|
-
switch (opcode) {
|
|
31
|
-
case Opcode.Begin: {
|
|
32
|
-
const p = top;
|
|
33
|
-
const [type, __id, elements] = opcodes[i + 1] as SSRSnapshotInstance;
|
|
34
|
-
top = new SnapshotInstance(type, __id);
|
|
35
|
-
top.__pendingElements = elements;
|
|
36
|
-
p.insertBefore(top);
|
|
37
|
-
stack.push(top);
|
|
38
|
-
|
|
39
|
-
i += 2;
|
|
40
|
-
break;
|
|
41
|
-
}
|
|
42
|
-
case Opcode.End: {
|
|
43
|
-
// @ts-ignore
|
|
44
|
-
top[CHILDREN] = undefined;
|
|
45
|
-
|
|
46
|
-
top.__elements = top.__pendingElements!.map(({ ssrID }) => refMap![ssrID]!);
|
|
47
|
-
top.__element_root = top.__elements[0];
|
|
48
|
-
delete top.__pendingElements;
|
|
49
|
-
|
|
50
|
-
if (top.__snapshot_def.isListHolder) {
|
|
51
|
-
const listElement = top.__element_root!;
|
|
52
|
-
const listElementUniqueID = __GetElementUniqueID(listElement);
|
|
53
|
-
const signMap = gSignMap[listElementUniqueID] = new Map();
|
|
54
|
-
gRecycleMap[listElementUniqueID] = new Map();
|
|
55
|
-
const enqueueFunc = enqueueComponentFactory();
|
|
56
|
-
const [componentAtIndex, componentAtIndexes] = componentAtIndexFactory(top.childNodes, hydrate);
|
|
57
|
-
for (const child of top.childNodes) {
|
|
58
|
-
if (child.__element_root) {
|
|
59
|
-
const childElementUniqueID = __GetElementUniqueID(child.__element_root);
|
|
60
|
-
signMap.set(childElementUniqueID, child);
|
|
61
|
-
enqueueFunc(
|
|
62
|
-
listElement,
|
|
63
|
-
listElementUniqueID,
|
|
64
|
-
childElementUniqueID,
|
|
65
|
-
);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
__UpdateListCallbacks(listElement, componentAtIndex, enqueueFunc, componentAtIndexes);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
stack.pop();
|
|
72
|
-
const p = stack[stack.length - 1];
|
|
73
|
-
top = p!;
|
|
74
|
-
|
|
75
|
-
i += 1;
|
|
76
|
-
break;
|
|
77
|
-
}
|
|
78
|
-
case Opcode.Attr: {
|
|
79
|
-
const key = opcodes[i + 1];
|
|
80
|
-
const value = opcodes[i + 2];
|
|
81
|
-
top.setAttribute(key, value);
|
|
82
|
-
|
|
83
|
-
i += 3;
|
|
84
|
-
break;
|
|
85
|
-
}
|
|
86
|
-
case Opcode.Text: {
|
|
87
|
-
const [[type, __id, elements], text] = opcodes[i + 1] as [SSRSnapshotInstance, string];
|
|
88
|
-
const s = new SnapshotInstance(type, __id);
|
|
89
|
-
s.setAttribute(0, text);
|
|
90
|
-
top.insertBefore(s);
|
|
91
|
-
s.__elements = elements.map(({ ssrID }) => refMap![ssrID]!);
|
|
92
|
-
s.__element_root = s.__elements[0];
|
|
93
|
-
i += 2;
|
|
94
|
-
break;
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
export function renderOpcodesInto(opcodes: any[], into: SnapshotInstance): void {
|
|
101
|
-
let top: SnapshotInstance = into;
|
|
102
|
-
const stack: SnapshotInstance[] = [into];
|
|
103
|
-
for (let i = 0; i < opcodes.length;) {
|
|
104
|
-
const opcode = opcodes[i];
|
|
105
|
-
switch (opcode) {
|
|
106
|
-
case Opcode.Begin: {
|
|
107
|
-
const p = top;
|
|
108
|
-
top = opcodes[i + 1];
|
|
109
|
-
// @ts-ignore
|
|
110
|
-
if (top.__parent) {
|
|
111
|
-
// already inserted
|
|
112
|
-
top = new SnapshotInstance(top.type);
|
|
113
|
-
opcodes[i + 1] = top;
|
|
114
|
-
}
|
|
115
|
-
p.insertBefore(top);
|
|
116
|
-
stack.push(top);
|
|
117
|
-
|
|
118
|
-
i += 2;
|
|
119
|
-
break;
|
|
120
|
-
}
|
|
121
|
-
case Opcode.End: {
|
|
122
|
-
// @ts-ignore
|
|
123
|
-
top[CHILDREN] = undefined;
|
|
124
|
-
|
|
125
|
-
stack.pop();
|
|
126
|
-
const p = stack[stack.length - 1];
|
|
127
|
-
top = p!;
|
|
128
|
-
|
|
129
|
-
i += 1;
|
|
130
|
-
break;
|
|
131
|
-
}
|
|
132
|
-
case Opcode.Attr: {
|
|
133
|
-
const key = opcodes[i + 1];
|
|
134
|
-
const value = opcodes[i + 2];
|
|
135
|
-
top.setAttribute(key, value);
|
|
136
|
-
|
|
137
|
-
i += 3;
|
|
138
|
-
break;
|
|
139
|
-
}
|
|
140
|
-
case Opcode.Text: {
|
|
141
|
-
const text = opcodes[i + 1];
|
|
142
|
-
const s = new SnapshotInstance(null as unknown as string);
|
|
143
|
-
if (__ENABLE_SSR__) {
|
|
144
|
-
// We need store the just created SnapshotInstance, or it will be lost when we leave the function
|
|
145
|
-
opcodes[i + 1] = [s, text];
|
|
146
|
-
}
|
|
147
|
-
s.setAttribute(0, text);
|
|
148
|
-
top.insertBefore(s);
|
|
149
|
-
|
|
150
|
-
i += 2;
|
|
151
|
-
break;
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
}
|
|
@@ -1,18 +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
|
-
|
|
5
|
-
import type { ListUpdateInfo } from './listUpdateInfo.js';
|
|
6
|
-
|
|
7
|
-
export const __pendingListUpdates = {
|
|
8
|
-
values: {} as Record<number, ListUpdateInfo>,
|
|
9
|
-
clear(): void {
|
|
10
|
-
this.values = {};
|
|
11
|
-
},
|
|
12
|
-
flush(): void {
|
|
13
|
-
Object.values(this.values).forEach(update => {
|
|
14
|
-
update.flush();
|
|
15
|
-
});
|
|
16
|
-
this.clear();
|
|
17
|
-
},
|
|
18
|
-
};
|
|
@@ -1,24 +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
|
-
export const DIFF = '__b';
|
|
5
|
-
export const RENDER = '__r';
|
|
6
|
-
export const DIFFED = 'diffed';
|
|
7
|
-
export const COMMIT = '__c';
|
|
8
|
-
export const SKIP_EFFECTS = '__s';
|
|
9
|
-
export const CATCH_ERROR = '__e';
|
|
10
|
-
|
|
11
|
-
// VNode properties
|
|
12
|
-
export const COMPONENT = '__c';
|
|
13
|
-
export const CHILDREN = '__k';
|
|
14
|
-
export const PARENT = '__';
|
|
15
|
-
export const MASK = '__m';
|
|
16
|
-
|
|
17
|
-
// Component properties
|
|
18
|
-
export const VNODE = '__v';
|
|
19
|
-
export const DIRTY = '__d';
|
|
20
|
-
export const FORCE = '__e';
|
|
21
|
-
export const NEXT_STATE = '__s';
|
|
22
|
-
export const CHILD_DID_SUSPEND = '__c';
|
|
23
|
-
export const RENDER_CALLBACKS = '__h';
|
|
24
|
-
export const HOOK = '__h';
|