@lynx-js/react 0.111.0 → 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 +58 -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 +7 -3
- package/refresh/dist/index.js +223 -284
- package/refresh/package.json +3 -4
- package/refresh/rslib.config.ts +24 -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/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 +18 -7
- package/testing-library/dist/pure.js +3 -1
- package/testing-library/dist/vitest-global-setup.js +2 -2
- package/transform/dist/wasm.cjs +1 -1
- package/types/react.d.ts +13 -1
- package/worklet-runtime/dist/dev.js +403 -506
- package/worklet-runtime/dist/main.js +1 -517
- package/worklet-runtime/lib/workletRuntime.js +5 -5
- package/worklet-runtime/lib/workletRuntime.js.map +1 -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,306 +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
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Implements rendering to opcodes.
|
|
7
|
-
* This module is modified from preact-render-to-string@6.0.3 to generate
|
|
8
|
-
* opcodes instead of HTML strings for Lynx.
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
// @ts-nocheck
|
|
12
|
-
|
|
13
|
-
import { Fragment, h, options } from 'preact';
|
|
14
|
-
|
|
15
|
-
import {
|
|
16
|
-
CHILDREN,
|
|
17
|
-
COMMIT,
|
|
18
|
-
COMPONENT,
|
|
19
|
-
DIFF,
|
|
20
|
-
DIFFED,
|
|
21
|
-
DIRTY,
|
|
22
|
-
NEXT_STATE,
|
|
23
|
-
PARENT,
|
|
24
|
-
RENDER,
|
|
25
|
-
SKIP_EFFECTS,
|
|
26
|
-
VNODE,
|
|
27
|
-
} from './constants.js';
|
|
28
|
-
|
|
29
|
-
/** @typedef {import('preact').VNode} VNode */
|
|
30
|
-
|
|
31
|
-
const EMPTY_ARR = [];
|
|
32
|
-
const isArray = /* @__PURE__ */ Array.isArray;
|
|
33
|
-
const assign = /* @__PURE__ */ Object.assign;
|
|
34
|
-
|
|
35
|
-
// Global state for the current render pass
|
|
36
|
-
let beforeDiff, afterDiff, renderHook, ummountHook;
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Render Preact JSX + Components to an HTML string.
|
|
40
|
-
* @param {VNode} vnode JSX Element / VNode to render
|
|
41
|
-
* @param {object} [context] Initial root context object
|
|
42
|
-
*/
|
|
43
|
-
export function renderToString(vnode: any, context: any): any[] {
|
|
44
|
-
// Performance optimization: `renderToString` is synchronous and we
|
|
45
|
-
// therefore don't execute any effects. To do that we pass an empty
|
|
46
|
-
// array to `options._commit` (`__c`). But we can go one step further
|
|
47
|
-
// and avoid a lot of dirty checks and allocations by setting
|
|
48
|
-
// `options._skipEffects` (`__s`) too.
|
|
49
|
-
const previousSkipEffects = options[SKIP_EFFECTS];
|
|
50
|
-
options[SKIP_EFFECTS] = true;
|
|
51
|
-
|
|
52
|
-
// store options hooks once before each synchronous render call
|
|
53
|
-
beforeDiff = options[DIFF];
|
|
54
|
-
afterDiff = options[DIFFED];
|
|
55
|
-
renderHook = options[RENDER];
|
|
56
|
-
ummountHook = options.unmount;
|
|
57
|
-
|
|
58
|
-
const parent = h(Fragment, null);
|
|
59
|
-
parent[CHILDREN] = [vnode];
|
|
60
|
-
|
|
61
|
-
const opcodes = [];
|
|
62
|
-
|
|
63
|
-
try {
|
|
64
|
-
_renderToString(
|
|
65
|
-
vnode,
|
|
66
|
-
context || EMPTY_OBJ,
|
|
67
|
-
false,
|
|
68
|
-
undefined,
|
|
69
|
-
parent,
|
|
70
|
-
opcodes,
|
|
71
|
-
);
|
|
72
|
-
} finally {
|
|
73
|
-
// options._commit, we don't schedule any effects in this library right now,
|
|
74
|
-
// so we can pass an empty queue to this hook.
|
|
75
|
-
if (options[COMMIT]) options[COMMIT](vnode, EMPTY_ARR);
|
|
76
|
-
options[SKIP_EFFECTS] = previousSkipEffects;
|
|
77
|
-
EMPTY_ARR.length = 0;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
return opcodes;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
// Installed as setState/forceUpdate for function components
|
|
84
|
-
function markAsDirty() {
|
|
85
|
-
this.__d = true;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
const EMPTY_OBJ = {};
|
|
89
|
-
|
|
90
|
-
export const __OpBegin = 0;
|
|
91
|
-
export const __OpEnd = 1;
|
|
92
|
-
export const __OpAttr = 2;
|
|
93
|
-
export const __OpText = 3;
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* @param {VNode} vnode
|
|
97
|
-
* @param {Record<string, unknown>} context
|
|
98
|
-
*/
|
|
99
|
-
function renderClassComponent(vnode, context) {
|
|
100
|
-
const type = /** @type {import("preact").ComponentClass<typeof vnode.props>} */ (vnode.type);
|
|
101
|
-
|
|
102
|
-
const c = new type(vnode.props, context);
|
|
103
|
-
|
|
104
|
-
vnode[COMPONENT] = c;
|
|
105
|
-
c[VNODE] = vnode;
|
|
106
|
-
|
|
107
|
-
c.props = vnode.props;
|
|
108
|
-
c.context = context;
|
|
109
|
-
// turn off stateful re-rendering:
|
|
110
|
-
c[DIRTY] = true;
|
|
111
|
-
|
|
112
|
-
if (c.state == null) c.state = EMPTY_OBJ;
|
|
113
|
-
|
|
114
|
-
if (c[NEXT_STATE] == null) {
|
|
115
|
-
c[NEXT_STATE] = c.state;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
if (type.getDerivedStateFromProps) {
|
|
119
|
-
c.state = assign(
|
|
120
|
-
{},
|
|
121
|
-
c.state,
|
|
122
|
-
type.getDerivedStateFromProps(c.props, c.state),
|
|
123
|
-
);
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
if (renderHook) renderHook(vnode);
|
|
127
|
-
|
|
128
|
-
return c.render(c.props, c.state, context);
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
/**
|
|
132
|
-
* Recursively render VNodes to HTML.
|
|
133
|
-
* @param {VNode|any} vnode
|
|
134
|
-
* @param {any} context
|
|
135
|
-
* @param {boolean} isSvgMode
|
|
136
|
-
* @param {any} selectValue
|
|
137
|
-
* @param {VNode} parent
|
|
138
|
-
* @param opcodes
|
|
139
|
-
*/
|
|
140
|
-
function _renderToString(
|
|
141
|
-
vnode,
|
|
142
|
-
context,
|
|
143
|
-
isSvgMode,
|
|
144
|
-
selectValue,
|
|
145
|
-
parent,
|
|
146
|
-
opcodes,
|
|
147
|
-
) {
|
|
148
|
-
// Ignore non-rendered VNodes/values
|
|
149
|
-
if (vnode == null || vnode === true || vnode === false || vnode === '') {
|
|
150
|
-
return;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
// Text VNodes: escape as HTML
|
|
154
|
-
if (typeof vnode !== 'object') {
|
|
155
|
-
if (typeof vnode === 'function') return;
|
|
156
|
-
|
|
157
|
-
opcodes.push(__OpText, vnode + '');
|
|
158
|
-
return;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
// Recurse into children / Arrays
|
|
162
|
-
if (isArray(vnode)) {
|
|
163
|
-
parent[CHILDREN] = vnode;
|
|
164
|
-
for (let i = 0; i < vnode.length; i++) {
|
|
165
|
-
const child = vnode[i];
|
|
166
|
-
if (child == null || typeof child === 'boolean') continue;
|
|
167
|
-
|
|
168
|
-
_renderToString(child, context, isSvgMode, selectValue, parent, opcodes);
|
|
169
|
-
}
|
|
170
|
-
return;
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
// VNodes have {constructor:undefined} to prevent JSON injection:
|
|
174
|
-
// if (vnode.constructor !== undefined) return;
|
|
175
|
-
|
|
176
|
-
vnode[PARENT] = parent;
|
|
177
|
-
if (beforeDiff) beforeDiff(vnode);
|
|
178
|
-
|
|
179
|
-
let type = vnode.type,
|
|
180
|
-
props = vnode.props,
|
|
181
|
-
cctx = context,
|
|
182
|
-
contextType,
|
|
183
|
-
rendered,
|
|
184
|
-
component;
|
|
185
|
-
|
|
186
|
-
// Invoke rendering on Components
|
|
187
|
-
if (typeof type === 'function') {
|
|
188
|
-
if (type === Fragment) {
|
|
189
|
-
rendered = props.children;
|
|
190
|
-
} else {
|
|
191
|
-
contextType = type.contextType;
|
|
192
|
-
if (contextType != null) {
|
|
193
|
-
const provider = context[contextType.__c];
|
|
194
|
-
cctx = provider ? provider.props.value : contextType.__;
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
if (type.prototype && typeof type.prototype.render === 'function') {
|
|
198
|
-
rendered = /**#__NOINLINE__**/ renderClassComponent(vnode, cctx);
|
|
199
|
-
component = vnode[COMPONENT];
|
|
200
|
-
} else {
|
|
201
|
-
component = {
|
|
202
|
-
__v: vnode,
|
|
203
|
-
props,
|
|
204
|
-
context: cctx,
|
|
205
|
-
// silently drop state updates
|
|
206
|
-
setState: markAsDirty,
|
|
207
|
-
forceUpdate: markAsDirty,
|
|
208
|
-
__d: true,
|
|
209
|
-
// hooks
|
|
210
|
-
__h: [],
|
|
211
|
-
};
|
|
212
|
-
vnode[COMPONENT] = component;
|
|
213
|
-
component.constructor = type;
|
|
214
|
-
component.render = doRender;
|
|
215
|
-
|
|
216
|
-
// If a hook invokes setState() to invalidate the component during rendering,
|
|
217
|
-
// re-render it up to 25 times to allow "settling" of memoized states.
|
|
218
|
-
// Note:
|
|
219
|
-
// This will need to be updated for Preact 11 to use internal.flags rather than component._dirty:
|
|
220
|
-
// https://github.com/preactjs/preact/blob/d4ca6fdb19bc715e49fd144e69f7296b2f4daa40/src/diff/component.js#L35-L44
|
|
221
|
-
let count = 0;
|
|
222
|
-
while (component[DIRTY] && count++ < 25) {
|
|
223
|
-
component[DIRTY] = false;
|
|
224
|
-
|
|
225
|
-
if (renderHook) renderHook(vnode);
|
|
226
|
-
|
|
227
|
-
rendered = component.render(props, component.state, cctx);
|
|
228
|
-
}
|
|
229
|
-
component[DIRTY] = true;
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
if (component.getChildContext != null) {
|
|
233
|
-
context = assign({}, context, component.getChildContext());
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
// When a component returns a Fragment node we flatten it in core, so we
|
|
238
|
-
// need to mirror that logic here too
|
|
239
|
-
const isTopLevelFragment = rendered != null && rendered.type === Fragment
|
|
240
|
-
&& rendered.key == null;
|
|
241
|
-
rendered = isTopLevelFragment ? rendered.props.children : rendered;
|
|
242
|
-
|
|
243
|
-
// Recurse into children before invoking the after-diff hook
|
|
244
|
-
_renderToString(rendered, context, isSvgMode, selectValue, vnode, opcodes);
|
|
245
|
-
if (afterDiff) afterDiff(vnode);
|
|
246
|
-
vnode[PARENT] = undefined;
|
|
247
|
-
|
|
248
|
-
if (ummountHook) ummountHook(vnode);
|
|
249
|
-
|
|
250
|
-
return;
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
let children;
|
|
254
|
-
|
|
255
|
-
opcodes.push(__OpBegin, vnode);
|
|
256
|
-
|
|
257
|
-
for (const name in props) {
|
|
258
|
-
const v = props[name];
|
|
259
|
-
|
|
260
|
-
switch (name) {
|
|
261
|
-
case 'children':
|
|
262
|
-
children = v;
|
|
263
|
-
continue;
|
|
264
|
-
|
|
265
|
-
// VDOM-specific props
|
|
266
|
-
/* c8 ignore next 5 */
|
|
267
|
-
case 'key':
|
|
268
|
-
case 'ref':
|
|
269
|
-
case '__self':
|
|
270
|
-
case '__source':
|
|
271
|
-
continue;
|
|
272
|
-
|
|
273
|
-
default: {}
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
// write this attribute to the buffer
|
|
277
|
-
if (v != null && v !== false && typeof v !== 'function') {
|
|
278
|
-
opcodes.push(__OpAttr, name, v);
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
if (typeof children === 'string') {
|
|
283
|
-
// single text child
|
|
284
|
-
opcodes.push(__OpText, children);
|
|
285
|
-
} else if (children != null && children !== false && children !== true) {
|
|
286
|
-
// recurse into this element VNode's children
|
|
287
|
-
_renderToString(children, context, false, selectValue, vnode, opcodes);
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
if (afterDiff) afterDiff(vnode);
|
|
291
|
-
vnode[PARENT] = undefined;
|
|
292
|
-
if (ummountHook) ummountHook(vnode);
|
|
293
|
-
|
|
294
|
-
opcodes.push(__OpEnd);
|
|
295
|
-
|
|
296
|
-
return;
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
/** The `.render()` method for a PFC backing instance. */
|
|
300
|
-
function doRender(props, state, context) {
|
|
301
|
-
return this.constructor(props, context);
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
export default renderToString;
|
|
305
|
-
export const render: typeof renderToString = renderToString;
|
|
306
|
-
export const renderToStaticMarkup: typeof renderToString = renderToString;
|
package/runtime/src/root.ts
DELETED
|
@@ -1,23 +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
|
-
* The internal ReactLynx's root.
|
|
9
|
-
* {@link @lynx-js/react!Root | root}.
|
|
10
|
-
*/
|
|
11
|
-
let __root: (SnapshotInstance | BackgroundSnapshotInstance) & { __jsx?: React.ReactNode; __opcodes?: any[] };
|
|
12
|
-
|
|
13
|
-
function setRoot(root: typeof __root): void {
|
|
14
|
-
__root = root;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
if (__MAIN_THREAD__) {
|
|
18
|
-
setRoot(new SnapshotInstance('root'));
|
|
19
|
-
} else if (__BACKGROUND__) {
|
|
20
|
-
setRoot(new BackgroundSnapshotInstance('root'));
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export { __root, setRoot };
|
|
@@ -1,16 +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
|
-
/**
|
|
6
|
-
* Types of dynamic parts that can be updated in a snapshot
|
|
7
|
-
* These are determined at compile time through static analysis
|
|
8
|
-
*/
|
|
9
|
-
export const enum DynamicPartType {
|
|
10
|
-
Attr = 0, // Regular attribute updates
|
|
11
|
-
Spread, // Spread operator in JSX
|
|
12
|
-
Slot, // Slot for component children
|
|
13
|
-
Children, // Regular children updates
|
|
14
|
-
ListChildren, // List/array children updates
|
|
15
|
-
MultiChildren, // Multiple children updates (compat layer)
|
|
16
|
-
}
|
|
@@ -1,33 +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 { SnapshotInstance } from '../snapshot.js';
|
|
5
|
-
|
|
6
|
-
function updateEvent(
|
|
7
|
-
snapshot: SnapshotInstance,
|
|
8
|
-
expIndex: number,
|
|
9
|
-
_oldValue: any,
|
|
10
|
-
elementIndex: number,
|
|
11
|
-
eventType: string,
|
|
12
|
-
eventName: string,
|
|
13
|
-
spreadKey: string,
|
|
14
|
-
): void {
|
|
15
|
-
const value = snapshot.__values![expIndex];
|
|
16
|
-
let event;
|
|
17
|
-
if (!value) {
|
|
18
|
-
event = undefined;
|
|
19
|
-
} else if (typeof value === 'string') {
|
|
20
|
-
event = value;
|
|
21
|
-
} else {
|
|
22
|
-
event = `${snapshot.__id}:${expIndex}:${spreadKey}`;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
// todo: reuseId?
|
|
26
|
-
|
|
27
|
-
snapshot.__values![expIndex] = event;
|
|
28
|
-
if (snapshot.__elements) {
|
|
29
|
-
__AddEvent(snapshot.__elements[elementIndex]!, eventType, eventName, event);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export { updateEvent };
|
|
@@ -1,30 +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 { processGesture } from '../gesture/processGesture.js';
|
|
5
|
-
import type { GestureKind } from '../gesture/types.js';
|
|
6
|
-
import { isMainThreadHydrationFinished } from '../lifecycle/patch/isMainThreadHydrationFinished.js';
|
|
7
|
-
import { SnapshotInstance } from '../snapshot.js';
|
|
8
|
-
|
|
9
|
-
export function updateGesture(
|
|
10
|
-
snapshot: SnapshotInstance,
|
|
11
|
-
expIndex: number,
|
|
12
|
-
oldValue: any,
|
|
13
|
-
elementIndex: number,
|
|
14
|
-
workletType: string,
|
|
15
|
-
): void {
|
|
16
|
-
if (!snapshot.__elements) {
|
|
17
|
-
return;
|
|
18
|
-
}
|
|
19
|
-
if (__PROFILE__) {
|
|
20
|
-
console.profile('updateGesture');
|
|
21
|
-
}
|
|
22
|
-
const value = snapshot.__values![expIndex] as GestureKind;
|
|
23
|
-
|
|
24
|
-
if (workletType === 'main-thread') {
|
|
25
|
-
processGesture(snapshot.__elements[elementIndex]!, value, oldValue as GestureKind, !isMainThreadHydrationFinished);
|
|
26
|
-
}
|
|
27
|
-
if (__PROFILE__) {
|
|
28
|
-
console.profileEnd();
|
|
29
|
-
}
|
|
30
|
-
}
|
|
@@ -1,36 +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 { hydrate } from '../hydrate.js';
|
|
6
|
-
import { componentAtIndexFactory, enqueueComponentFactory, gRecycleMap, gSignMap } from '../list.js';
|
|
7
|
-
import type { SnapshotInstance } from '../snapshot.js';
|
|
8
|
-
|
|
9
|
-
export function snapshotCreateList(
|
|
10
|
-
pageId: number,
|
|
11
|
-
_ctx: SnapshotInstance,
|
|
12
|
-
_expIndex: number,
|
|
13
|
-
): FiberElement {
|
|
14
|
-
const signMap = new Map<number, SnapshotInstance>();
|
|
15
|
-
const recycleMap = new Map<string, Map<number, SnapshotInstance>>();
|
|
16
|
-
const [componentAtIndex, componentAtIndexes] = componentAtIndexFactory([], hydrate);
|
|
17
|
-
const list = __CreateList(
|
|
18
|
-
pageId,
|
|
19
|
-
componentAtIndex,
|
|
20
|
-
enqueueComponentFactory(),
|
|
21
|
-
{},
|
|
22
|
-
componentAtIndexes,
|
|
23
|
-
);
|
|
24
|
-
const listID = __GetElementUniqueID(list);
|
|
25
|
-
gSignMap[listID] = signMap;
|
|
26
|
-
gRecycleMap[listID] = recycleMap;
|
|
27
|
-
return list;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export function snapshotDestroyList(si: SnapshotInstance): void {
|
|
31
|
-
const [, elementIndex] = si.__snapshot_def.slot[0]!;
|
|
32
|
-
const list = si.__elements![elementIndex]!;
|
|
33
|
-
const listID = __GetElementUniqueID(list);
|
|
34
|
-
delete gSignMap[listID];
|
|
35
|
-
delete gRecycleMap[listID];
|
|
36
|
-
}
|
|
@@ -1,62 +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 { ListUpdateInfoRecording } from '../listUpdateInfo.js';
|
|
5
|
-
import { __pendingListUpdates } from '../pendingListUpdates.js';
|
|
6
|
-
import { SnapshotInstance } from '../snapshot.js';
|
|
7
|
-
|
|
8
|
-
const platformInfoVirtualAttributes: Set<string> = /* @__PURE__ */ new Set<string>(['reuse-identifier']);
|
|
9
|
-
const platformInfoAttributes: Set<string> = /* @__PURE__ */ new Set<string>([
|
|
10
|
-
'reuse-identifier',
|
|
11
|
-
'full-span',
|
|
12
|
-
'item-key',
|
|
13
|
-
'sticky-top',
|
|
14
|
-
'sticky-bottom',
|
|
15
|
-
'estimated-height',
|
|
16
|
-
'estimated-height-px',
|
|
17
|
-
'estimated-main-axis-size-px',
|
|
18
|
-
]);
|
|
19
|
-
|
|
20
|
-
export interface PlatformInfo {
|
|
21
|
-
'reuse-identifier'?: string;
|
|
22
|
-
'full-span'?: boolean;
|
|
23
|
-
'item-key'?: string;
|
|
24
|
-
'sticky-top'?: boolean;
|
|
25
|
-
'sticky-bottom'?: boolean;
|
|
26
|
-
'estimated-height'?: number;
|
|
27
|
-
'estimated-height-px'?: number;
|
|
28
|
-
'estimated-main-axis-size-px'?: number;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
function updateListItemPlatformInfo(
|
|
32
|
-
ctx: SnapshotInstance,
|
|
33
|
-
index: number,
|
|
34
|
-
oldValue: any,
|
|
35
|
-
elementIndex: number,
|
|
36
|
-
): void {
|
|
37
|
-
const newValue = ctx.__listItemPlatformInfo = ctx.__values![index] as PlatformInfo;
|
|
38
|
-
|
|
39
|
-
const list = ctx.parentNode;
|
|
40
|
-
if (list?.__snapshot_def.isListHolder) {
|
|
41
|
-
(__pendingListUpdates.values[list.__id] ??= new ListUpdateInfoRecording(list)).onSetAttribute(
|
|
42
|
-
ctx,
|
|
43
|
-
newValue,
|
|
44
|
-
oldValue,
|
|
45
|
-
);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
// In this updater, unlike `updateSpread`, the shape of the value is guaranteed to be an fixed object.
|
|
49
|
-
// No adding / removing keys.
|
|
50
|
-
if (ctx.__elements) {
|
|
51
|
-
const e = ctx.__elements[elementIndex]!;
|
|
52
|
-
const value = ctx.__values![index] as Record<string, unknown>;
|
|
53
|
-
for (const k in value) {
|
|
54
|
-
if (platformInfoVirtualAttributes.has(k)) {
|
|
55
|
-
continue;
|
|
56
|
-
}
|
|
57
|
-
__SetAttribute(e, k, value[k]);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
export { updateListItemPlatformInfo, platformInfoAttributes };
|
|
@@ -1,139 +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 { Element, Worklet, WorkletRefImpl } from '@lynx-js/react/worklet-runtime/bindings';
|
|
5
|
-
|
|
6
|
-
import type { SnapshotInstance } from '../snapshot.js';
|
|
7
|
-
import { workletUnRef } from './workletRef.js';
|
|
8
|
-
import { RefProxy } from '../lifecycle/ref/delay.js';
|
|
9
|
-
|
|
10
|
-
const refsToClear: Ref[] = [];
|
|
11
|
-
const refsToApply: (Ref | [snapshotInstanceId: number, expIndex: number])[] = [];
|
|
12
|
-
|
|
13
|
-
type Ref = (((ref: RefProxy) => () => void) | { current: RefProxy | null }) & {
|
|
14
|
-
_unmount?: () => void;
|
|
15
|
-
__ref?: { value: number };
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
function unref(snapshot: SnapshotInstance, recursive: boolean): void {
|
|
19
|
-
snapshot.__worklet_ref_set?.forEach(v => {
|
|
20
|
-
if (v) {
|
|
21
|
-
workletUnRef(v as Worklet | WorkletRefImpl<Element>);
|
|
22
|
-
}
|
|
23
|
-
});
|
|
24
|
-
snapshot.__worklet_ref_set?.clear();
|
|
25
|
-
|
|
26
|
-
if (recursive) {
|
|
27
|
-
snapshot.childNodes.forEach(it => {
|
|
28
|
-
unref(it, recursive);
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
// This function is modified from preact source code.
|
|
34
|
-
function applyRef(ref: Ref, value: null | [snapshotInstanceId: number, expIndex: number]): void {
|
|
35
|
-
const newRef = value && new RefProxy(value);
|
|
36
|
-
|
|
37
|
-
try {
|
|
38
|
-
if (typeof ref == 'function') {
|
|
39
|
-
const hasRefUnmount = typeof ref._unmount == 'function';
|
|
40
|
-
if (hasRefUnmount) {
|
|
41
|
-
ref._unmount!();
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
if (!hasRefUnmount || newRef != null) {
|
|
45
|
-
// Store the cleanup function on the function
|
|
46
|
-
// instance object itself to avoid shape
|
|
47
|
-
// transitioning vnode
|
|
48
|
-
ref._unmount = ref(newRef!);
|
|
49
|
-
}
|
|
50
|
-
} else ref.current = newRef;
|
|
51
|
-
/* v8 ignore start */
|
|
52
|
-
} catch (e) {
|
|
53
|
-
lynx.reportError(e as Error);
|
|
54
|
-
}
|
|
55
|
-
/* v8 ignore stop */
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
function updateRef(
|
|
59
|
-
snapshot: SnapshotInstance,
|
|
60
|
-
expIndex: number,
|
|
61
|
-
oldValue: string | null,
|
|
62
|
-
elementIndex: number,
|
|
63
|
-
): void {
|
|
64
|
-
const value: unknown = snapshot.__values![expIndex];
|
|
65
|
-
let ref;
|
|
66
|
-
if (typeof value === 'string') {
|
|
67
|
-
ref = value;
|
|
68
|
-
} else {
|
|
69
|
-
ref = `react-ref-${snapshot.__id}-${expIndex}`;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
snapshot.__values![expIndex] = ref;
|
|
73
|
-
if (snapshot.__elements && oldValue !== ref) {
|
|
74
|
-
if (oldValue) {
|
|
75
|
-
__SetAttribute(snapshot.__elements[elementIndex]!, oldValue, undefined);
|
|
76
|
-
}
|
|
77
|
-
if (ref) {
|
|
78
|
-
__SetAttribute(snapshot.__elements[elementIndex]!, ref, 1);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
function transformRef(ref: unknown): Ref | null | undefined {
|
|
84
|
-
if (ref === undefined || ref === null) {
|
|
85
|
-
return ref;
|
|
86
|
-
}
|
|
87
|
-
if (typeof ref === 'function' || (typeof ref === 'object' && 'current' in ref)) {
|
|
88
|
-
if ('__ref' in ref) {
|
|
89
|
-
return ref as Ref;
|
|
90
|
-
}
|
|
91
|
-
return Object.defineProperty(ref, '__ref', { value: 1 }) as Ref;
|
|
92
|
-
}
|
|
93
|
-
throw new Error(
|
|
94
|
-
`Elements' "ref" property should be a function, or an object created `
|
|
95
|
-
+ `by createRef(), but got [${typeof ref}] instead`,
|
|
96
|
-
);
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
function applyQueuedRefs(): void {
|
|
100
|
-
try {
|
|
101
|
-
for (const ref of refsToClear) {
|
|
102
|
-
applyRef(ref, null);
|
|
103
|
-
}
|
|
104
|
-
for (let i = 0; i < refsToApply.length; i += 2) {
|
|
105
|
-
const ref = refsToApply[i] as Ref;
|
|
106
|
-
const value = refsToApply[i + 1] as [snapshotInstanceId: number, expIndex: number] | null;
|
|
107
|
-
applyRef(ref, value);
|
|
108
|
-
}
|
|
109
|
-
} finally {
|
|
110
|
-
clearQueuedRefs();
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
function queueRefAttrUpdate(
|
|
115
|
-
oldRef: Ref | null | undefined,
|
|
116
|
-
newRef: Ref | null | undefined,
|
|
117
|
-
snapshotInstanceId: number,
|
|
118
|
-
expIndex: number,
|
|
119
|
-
): void {
|
|
120
|
-
if (oldRef === newRef) {
|
|
121
|
-
return;
|
|
122
|
-
}
|
|
123
|
-
if (oldRef) {
|
|
124
|
-
refsToClear.push(oldRef);
|
|
125
|
-
}
|
|
126
|
-
if (newRef) {
|
|
127
|
-
refsToApply.push(newRef, [snapshotInstanceId, expIndex]);
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
function clearQueuedRefs(): void {
|
|
132
|
-
refsToClear.length = 0;
|
|
133
|
-
refsToApply.length = 0;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
/**
|
|
137
|
-
* @internal
|
|
138
|
-
*/
|
|
139
|
-
export { queueRefAttrUpdate, updateRef, unref, transformRef, applyRef, applyQueuedRefs, clearQueuedRefs, type Ref };
|