react-native-live-widgets 1.1.1 → 1.2.1
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 +21 -0
- package/README.md +113 -10
- package/android/src/main/java/com/reactnativeliveactivity/bridge/LiveActivityModule.kt +5 -1
- package/android/src/main/java/com/reactnativeliveactivity/renderer/DynamicWidgetCanvasRenderer.kt +443 -46
- package/android/src/main/java/com/reactnativeliveactivity/storage/DynamicWidgetStateStore.kt +86 -24
- package/android/src/main/java/com/reactnativeliveactivity/widgets/DynamicHomeScreenWidgetProvider.kt +126 -56
- package/android/src/main/res/layout/rn_live_widget_hit_zone.xml +16 -0
- package/android/src/main/res/layout/rn_live_widget_host.xml +16 -87
- package/docs/GUIDE-EN.md +332 -7
- package/docs/GUIDE-VI.md +357 -7
- package/docs/index.html +1143 -227
- package/docs/llms-full.txt +46 -6
- package/docs/llms.txt +37 -7
- package/ios/Models/DynamicLayoutModels.swift +11 -1
- package/ios/Renderer/DynamicNodeView.swift +169 -14
- package/ios/Widgets/DynamicHomeScreenWidget.swift +7 -3
- package/lib/builder.d.ts.map +1 -1
- package/lib/builder.js +92 -28
- package/lib/builder.js.map +1 -1
- package/lib/dispatcher.d.ts +7 -0
- package/lib/dispatcher.d.ts.map +1 -1
- package/lib/dispatcher.js +23 -6
- package/lib/dispatcher.js.map +1 -1
- package/lib/hooks.d.ts +66 -0
- package/lib/hooks.d.ts.map +1 -0
- package/lib/hooks.js +171 -0
- package/lib/hooks.js.map +1 -0
- package/lib/index.d.ts +48 -8
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +216 -35
- package/lib/index.js.map +1 -1
- package/lib/ir.d.ts +15 -0
- package/lib/ir.d.ts.map +1 -0
- package/lib/ir.js +379 -0
- package/lib/ir.js.map +1 -0
- package/lib/jsx.d.ts +87 -0
- package/lib/jsx.d.ts.map +1 -0
- package/lib/jsx.js +243 -0
- package/lib/jsx.js.map +1 -0
- package/lib/preview.d.ts +31 -0
- package/lib/preview.d.ts.map +1 -0
- package/lib/preview.js +735 -0
- package/lib/preview.js.map +1 -0
- package/lib/types.d.ts +212 -12
- package/lib/types.d.ts.map +1 -1
- package/lib/types.js +2 -1
- package/lib/types.js.map +1 -1
- package/package.json +3 -1
- package/src/builder.ts +86 -21
- package/src/dispatcher.ts +17 -0
- package/src/hooks.ts +223 -0
- package/src/index.ts +202 -13
- package/src/ir.ts +430 -0
- package/src/jsx.tsx +326 -0
- package/src/preview.tsx +1043 -0
- package/src/react-ambient.d.ts +10 -0
- package/src/react-native-env.d.ts +44 -0
- package/src/types.ts +261 -13
package/src/ir.ts
ADDED
|
@@ -0,0 +1,430 @@
|
|
|
1
|
+
import {
|
|
2
|
+
LayoutNode,
|
|
3
|
+
WidgetSinglePageConfig,
|
|
4
|
+
WidgetIR,
|
|
5
|
+
SemanticNode,
|
|
6
|
+
NodeRenderPlan,
|
|
7
|
+
RenderPlanTarget,
|
|
8
|
+
StateBinding,
|
|
9
|
+
AccessibilityRole,
|
|
10
|
+
} from './types';
|
|
11
|
+
|
|
12
|
+
let nodeCounter = 0;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* 🌲 Trình biên dịch UI Intermediate Representation (IR).
|
|
16
|
+
* Chuyển hóa cây DSL thành cấu trúc dữ liệu trung gian chuẩn gồm:
|
|
17
|
+
* 1. Root LayoutNode (đã chuẩn hóa thuộc tính & định danh).
|
|
18
|
+
* 2. Semantic Tree độc lập (Tách biệt hoàn toàn khỏi việc vẽ hình của Canvas).
|
|
19
|
+
* 3. Render Plan (Renderer Planner phân loại Native RemoteViews vs Canvas Bitmap).
|
|
20
|
+
* 4. State Bindings (Danh sách các liên kết tương tác & đồng bộ trạng thái).
|
|
21
|
+
*/
|
|
22
|
+
export function compileToIR(input: LayoutNode | WidgetSinglePageConfig): WidgetIR {
|
|
23
|
+
nodeCounter = 0;
|
|
24
|
+
const rootNode = resolveRootLayoutNode(input);
|
|
25
|
+
|
|
26
|
+
// 1. Gán ID duy nhất và lập bản đồ cây
|
|
27
|
+
const indexedRoot = assignNodeIds(rootNode, '0');
|
|
28
|
+
|
|
29
|
+
// 2. Xây dựng Semantic Tree độc lập
|
|
30
|
+
const semanticTree: SemanticNode[] = [];
|
|
31
|
+
buildSemanticNodes(indexedRoot, '0', semanticTree);
|
|
32
|
+
const semanticSummary = synthesizeSemanticSummary(semanticTree);
|
|
33
|
+
|
|
34
|
+
// 3. Renderer Planner: Phân loại node theo khả năng native
|
|
35
|
+
const planNodes: Record<string, NodeRenderPlan> = {};
|
|
36
|
+
let nativeCount = 0;
|
|
37
|
+
let canvasCount = 0;
|
|
38
|
+
classifyRenderTargets(indexedRoot, planNodes, () => {
|
|
39
|
+
nativeCount++;
|
|
40
|
+
}, () => {
|
|
41
|
+
canvasCount++;
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
// 4. Trích xuất State Bindings
|
|
45
|
+
const stateBindings: StateBinding[] = [];
|
|
46
|
+
extractBindings(indexedRoot, stateBindings);
|
|
47
|
+
|
|
48
|
+
return {
|
|
49
|
+
version: '2.0',
|
|
50
|
+
timestamp: Date.now(),
|
|
51
|
+
root: indexedRoot,
|
|
52
|
+
semanticTree,
|
|
53
|
+
semanticSummary,
|
|
54
|
+
renderPlan: {
|
|
55
|
+
overallStrategy: nativeCount >= canvasCount ? 'native_first_hybrid' : 'canvas_fallback',
|
|
56
|
+
nativeNodeCount: nativeCount,
|
|
57
|
+
canvasNodeCount: canvasCount,
|
|
58
|
+
nodes: planNodes,
|
|
59
|
+
},
|
|
60
|
+
stateBindings,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function resolveRootLayoutNode(input: LayoutNode | WidgetSinglePageConfig): LayoutNode {
|
|
65
|
+
if ('type' in input) {
|
|
66
|
+
return input;
|
|
67
|
+
}
|
|
68
|
+
return input.medium || input.large || input.small || { type: 'VStack', children: [] };
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function assignNodeIds(node: any, path: string): LayoutNode {
|
|
72
|
+
if (!node || typeof node !== 'object') return node;
|
|
73
|
+
|
|
74
|
+
const cloned = { ...node };
|
|
75
|
+
if (!cloned.id) {
|
|
76
|
+
cloned.id = `node_${path}_${++nodeCounter}`;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (Array.isArray(cloned.children)) {
|
|
80
|
+
cloned.children = cloned.children.map((child: any, idx: number) =>
|
|
81
|
+
assignNodeIds(child, `${path}.${idx}`)
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return cloned as LayoutNode;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function buildSemanticNodes(node: any, path: string, result: SemanticNode[]): void {
|
|
89
|
+
if (!node || typeof node !== 'object') return;
|
|
90
|
+
|
|
91
|
+
const props = node.props || {};
|
|
92
|
+
const accessible = props.accessible !== false;
|
|
93
|
+
const type = node.type;
|
|
94
|
+
|
|
95
|
+
let role: AccessibilityRole = props.accessibilityRole || 'none';
|
|
96
|
+
let label = props.accessibilityLabel || '';
|
|
97
|
+
let hint = props.accessibilityHint;
|
|
98
|
+
let value = props.accessibilityValue;
|
|
99
|
+
let interactive = false;
|
|
100
|
+
let actionId = props.actionId;
|
|
101
|
+
let deepLink = props.deepLink;
|
|
102
|
+
|
|
103
|
+
switch (type) {
|
|
104
|
+
case 'Text': {
|
|
105
|
+
if (role === 'none') {
|
|
106
|
+
const typo = props.typography || '';
|
|
107
|
+
role = typo.startsWith('title') || typo === 'largeTitle' || typo === 'headline'
|
|
108
|
+
? 'header'
|
|
109
|
+
: 'text';
|
|
110
|
+
}
|
|
111
|
+
if (!label && props.text !== undefined) {
|
|
112
|
+
label = String(props.text);
|
|
113
|
+
}
|
|
114
|
+
break;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
case 'Button': {
|
|
118
|
+
role = 'button';
|
|
119
|
+
interactive = true;
|
|
120
|
+
if (!label && props.title !== undefined) {
|
|
121
|
+
label = String(props.title);
|
|
122
|
+
}
|
|
123
|
+
if (!hint) {
|
|
124
|
+
hint = actionId ? `Kích hoạt hành động ${actionId}` : 'Chạm để thực hiện';
|
|
125
|
+
}
|
|
126
|
+
break;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
case 'Progress': {
|
|
130
|
+
role = 'progressbar';
|
|
131
|
+
if (!label) label = 'Tiến độ';
|
|
132
|
+
if (value === undefined && props.value !== undefined) {
|
|
133
|
+
value = `${Math.round(props.value * 100)}%`;
|
|
134
|
+
}
|
|
135
|
+
break;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
case 'Gauge': {
|
|
139
|
+
role = 'progressbar';
|
|
140
|
+
label = props.label || label || 'Chỉ số';
|
|
141
|
+
if (value === undefined) {
|
|
142
|
+
value = props.valueText || (props.value !== undefined ? `${Math.round(props.value * 100)}%` : undefined);
|
|
143
|
+
}
|
|
144
|
+
break;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
case 'Timer': {
|
|
148
|
+
role = 'timer';
|
|
149
|
+
if (!label) label = 'Đồng hồ đếm';
|
|
150
|
+
break;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
case 'Toggle': {
|
|
154
|
+
role = 'switch';
|
|
155
|
+
interactive = true;
|
|
156
|
+
if (!label && props.label) label = String(props.label);
|
|
157
|
+
value = props.isChecked ? 'Đã chọn' : 'Chưa chọn';
|
|
158
|
+
hint = 'Chạm để thay đổi trạng thái';
|
|
159
|
+
break;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
case 'Badge': {
|
|
163
|
+
role = 'summary';
|
|
164
|
+
if (!label && props.text) label = String(props.text);
|
|
165
|
+
break;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
case 'Image': {
|
|
169
|
+
role = props.systemName || props.url ? 'image' : 'none';
|
|
170
|
+
if (!label && props.systemName) {
|
|
171
|
+
label = `Biểu tượng ${props.systemName}`;
|
|
172
|
+
}
|
|
173
|
+
break;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
default:
|
|
177
|
+
break;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
if (accessible && (label || value || interactive)) {
|
|
181
|
+
result.push({
|
|
182
|
+
id: node.id || `semantic_${path}`,
|
|
183
|
+
path,
|
|
184
|
+
type,
|
|
185
|
+
role,
|
|
186
|
+
label: label.trim(),
|
|
187
|
+
hint,
|
|
188
|
+
value,
|
|
189
|
+
interactive,
|
|
190
|
+
actionId,
|
|
191
|
+
deepLink,
|
|
192
|
+
isDecorative: !accessible,
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
if (Array.isArray(node.children)) {
|
|
197
|
+
node.children.forEach((child: any, idx: number) => {
|
|
198
|
+
buildSemanticNodes(child, `${path}.${idx}`, result);
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
function synthesizeSemanticSummary(tree: SemanticNode[]): string {
|
|
204
|
+
const parts: string[] = [];
|
|
205
|
+
for (const node of tree) {
|
|
206
|
+
if (node.isDecorative) continue;
|
|
207
|
+
|
|
208
|
+
let phrase = '';
|
|
209
|
+
if (node.role === 'header' || node.role === 'text') {
|
|
210
|
+
phrase = node.label;
|
|
211
|
+
} else if (node.role === 'button') {
|
|
212
|
+
phrase = `Nút ${node.label}`;
|
|
213
|
+
if (node.hint) phrase += ` (${node.hint})`;
|
|
214
|
+
} else if (node.role === 'progressbar' || node.role === 'timer') {
|
|
215
|
+
phrase = `${node.label} ${node.value ?? ''}`.trim();
|
|
216
|
+
} else if (node.role === 'switch') {
|
|
217
|
+
phrase = `${node.label}: ${node.value ?? ''}`.trim();
|
|
218
|
+
} else if (node.label) {
|
|
219
|
+
phrase = node.label;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
if (phrase && !parts.includes(phrase)) {
|
|
223
|
+
parts.push(phrase);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
return parts.join('. ');
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* 🎯 Phân loại Render Target (Native RemoteViews vs Canvas Bitmap).
|
|
232
|
+
* Áp dụng nguyên tắc "Native-first, Canvas-when-needed".
|
|
233
|
+
*/
|
|
234
|
+
function classifyRenderTargets(
|
|
235
|
+
node: any,
|
|
236
|
+
registry: Record<string, NodeRenderPlan>,
|
|
237
|
+
onNative: () => void,
|
|
238
|
+
onCanvas: () => void
|
|
239
|
+
): void {
|
|
240
|
+
if (!node || typeof node !== 'object') return;
|
|
241
|
+
|
|
242
|
+
const type = node.type;
|
|
243
|
+
const props = node.props || {};
|
|
244
|
+
const id = node.id || 'anonymous';
|
|
245
|
+
|
|
246
|
+
let target: RenderPlanTarget = 'native_remote_view';
|
|
247
|
+
let reason = '';
|
|
248
|
+
let hasNative = true;
|
|
249
|
+
let requiresCanvas = false;
|
|
250
|
+
|
|
251
|
+
switch (type) {
|
|
252
|
+
case 'Text':
|
|
253
|
+
target = 'native_remote_view';
|
|
254
|
+
reason = 'Ánh xạ trực tiếp sang native TextView với đầy đủ font scaling';
|
|
255
|
+
hasNative = true;
|
|
256
|
+
requiresCanvas = false;
|
|
257
|
+
onNative();
|
|
258
|
+
break;
|
|
259
|
+
|
|
260
|
+
case 'Button':
|
|
261
|
+
target = 'native_remote_view';
|
|
262
|
+
reason = 'Ánh xạ trực tiếp sang native Button với PendingIntent';
|
|
263
|
+
hasNative = true;
|
|
264
|
+
requiresCanvas = false;
|
|
265
|
+
onNative();
|
|
266
|
+
break;
|
|
267
|
+
|
|
268
|
+
case 'Progress':
|
|
269
|
+
if (props.style === 'circular') {
|
|
270
|
+
target = 'canvas_bitmap';
|
|
271
|
+
reason = 'Vòng tròn tiến độ 360° đòi hỏi vẽ đường cong Canvas 2D';
|
|
272
|
+
hasNative = false;
|
|
273
|
+
requiresCanvas = true;
|
|
274
|
+
onCanvas();
|
|
275
|
+
} else {
|
|
276
|
+
target = 'native_remote_view';
|
|
277
|
+
reason = 'Thanh tiến độ ngang ánh xạ trực tiếp sang native ProgressBar';
|
|
278
|
+
hasNative = true;
|
|
279
|
+
requiresCanvas = false;
|
|
280
|
+
onNative();
|
|
281
|
+
}
|
|
282
|
+
break;
|
|
283
|
+
|
|
284
|
+
case 'Gauge':
|
|
285
|
+
target = 'canvas_bitmap';
|
|
286
|
+
reason = 'Đồng hồ cung tròn 240° đòi hỏi tính toán góc quét và bóng kim bằng Canvas';
|
|
287
|
+
hasNative = false;
|
|
288
|
+
requiresCanvas = true;
|
|
289
|
+
onCanvas();
|
|
290
|
+
break;
|
|
291
|
+
|
|
292
|
+
case 'Equalizer':
|
|
293
|
+
target = 'canvas_bitmap';
|
|
294
|
+
reason = 'Dải sóng âm thanh nhiều cột đòi hỏi hoạt họa pha sóng Canvas';
|
|
295
|
+
hasNative = false;
|
|
296
|
+
requiresCanvas = true;
|
|
297
|
+
onCanvas();
|
|
298
|
+
break;
|
|
299
|
+
|
|
300
|
+
case 'Divider':
|
|
301
|
+
target = 'native_remote_view';
|
|
302
|
+
reason = 'Đường phân cách ánh xạ trực tiếp sang native View với background/height';
|
|
303
|
+
hasNative = true;
|
|
304
|
+
requiresCanvas = false;
|
|
305
|
+
onNative();
|
|
306
|
+
break;
|
|
307
|
+
|
|
308
|
+
case 'Image':
|
|
309
|
+
target = 'native_remote_view';
|
|
310
|
+
reason = 'Ảnh ánh xạ trực tiếp sang native ImageView';
|
|
311
|
+
hasNative = true;
|
|
312
|
+
requiresCanvas = false;
|
|
313
|
+
onNative();
|
|
314
|
+
break;
|
|
315
|
+
|
|
316
|
+
case 'VStack':
|
|
317
|
+
case 'HStack':
|
|
318
|
+
case 'ZStack':
|
|
319
|
+
case 'Grid': {
|
|
320
|
+
const hasDashed = props.borderStyle === 'dashed' || props.borderStyle === 'dotted';
|
|
321
|
+
const hasComplexGradient = props.gradient && props.gradient.colors?.length > 2;
|
|
322
|
+
|
|
323
|
+
if (hasDashed || hasComplexGradient) {
|
|
324
|
+
target = 'composite';
|
|
325
|
+
reason = 'Vùng chứa có viền đứt nét hoặc gradient đa điểm cần nền Canvas kèm con Native';
|
|
326
|
+
hasNative = false;
|
|
327
|
+
requiresCanvas = true;
|
|
328
|
+
onCanvas();
|
|
329
|
+
} else {
|
|
330
|
+
target = 'native_remote_view';
|
|
331
|
+
reason = 'Khung bố cục chuẩn ánh xạ sang LinearLayout hoặc FrameLayout';
|
|
332
|
+
hasNative = true;
|
|
333
|
+
requiresCanvas = false;
|
|
334
|
+
onNative();
|
|
335
|
+
}
|
|
336
|
+
break;
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
default:
|
|
340
|
+
target = 'native_remote_view';
|
|
341
|
+
reason = 'Thành phần tiêu chuẩn';
|
|
342
|
+
hasNative = true;
|
|
343
|
+
onNative();
|
|
344
|
+
break;
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
const childrenTargets: RenderPlanTarget[] = [];
|
|
348
|
+
if (Array.isArray(node.children)) {
|
|
349
|
+
node.children.forEach((child: any) => {
|
|
350
|
+
classifyRenderTargets(child, registry, onNative, onCanvas);
|
|
351
|
+
const childPlan = registry[child.id];
|
|
352
|
+
if (childPlan) {
|
|
353
|
+
childrenTargets.push(childPlan.target);
|
|
354
|
+
}
|
|
355
|
+
});
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
registry[id] = {
|
|
359
|
+
id,
|
|
360
|
+
type,
|
|
361
|
+
target,
|
|
362
|
+
reason,
|
|
363
|
+
hasNativeEquivalent: hasNative,
|
|
364
|
+
requiresCanvas,
|
|
365
|
+
childrenTargets: childrenTargets.length > 0 ? childrenTargets : undefined,
|
|
366
|
+
};
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
function extractBindings(node: any, bindings: StateBinding[]): void {
|
|
370
|
+
if (!node || typeof node !== 'object') return;
|
|
371
|
+
|
|
372
|
+
const props = node.props || {};
|
|
373
|
+
const actionId = props.actionId;
|
|
374
|
+
|
|
375
|
+
if (actionId) {
|
|
376
|
+
let bindingType: StateBinding['bindingType'] = 'custom';
|
|
377
|
+
let targetKey: string | undefined = undefined;
|
|
378
|
+
|
|
379
|
+
if (actionId.startsWith('toggle:')) {
|
|
380
|
+
bindingType = 'toggle';
|
|
381
|
+
targetKey = actionId.replace('toggle:', '');
|
|
382
|
+
} else if (actionId.startsWith('page:')) {
|
|
383
|
+
bindingType = 'page';
|
|
384
|
+
targetKey = actionId.replace('page:', '');
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
bindings.push({
|
|
388
|
+
id: node.id || `bind_${bindings.length}`,
|
|
389
|
+
actionId,
|
|
390
|
+
bindingType,
|
|
391
|
+
targetKey,
|
|
392
|
+
initialValue: props.isChecked,
|
|
393
|
+
});
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
if (Array.isArray(node.children)) {
|
|
397
|
+
node.children.forEach((child: any) => extractBindings(child, bindings));
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
/**
|
|
402
|
+
* 🔍 Tiện ích gỡ lỗi: In ra cây kiểm tra trực quan của Intermediate Representation.
|
|
403
|
+
*/
|
|
404
|
+
export function inspectIR(input: LayoutNode | WidgetSinglePageConfig): string {
|
|
405
|
+
const ir = compileToIR(input);
|
|
406
|
+
const lines: string[] = [];
|
|
407
|
+
|
|
408
|
+
lines.push(`🌲 Widget IR v${ir.version} [${new Date(ir.timestamp).toISOString()}]`);
|
|
409
|
+
lines.push(`📊 Chiến lược kết xuất: ${ir.renderPlan.overallStrategy.toUpperCase()}`);
|
|
410
|
+
lines.push(` - Native RemoteViews nodes: ${ir.renderPlan.nativeNodeCount}`);
|
|
411
|
+
lines.push(` - Canvas Bitmap nodes: ${ir.renderPlan.canvasNodeCount}`);
|
|
412
|
+
lines.push(`\n♿ Tóm tắt âm thanh Trợ năng (Synthesized A11y Summary):`);
|
|
413
|
+
lines.push(` "${ir.semanticSummary}"`);
|
|
414
|
+
|
|
415
|
+
lines.push(`\n🎯 Kế hoạch phân bổ (Render Plan Tree):`);
|
|
416
|
+
for (const node of ir.semanticTree) {
|
|
417
|
+
const plan = ir.renderPlan.nodes[node.id];
|
|
418
|
+
const targetTag = plan?.target === 'native_remote_view' ? '[NATIVE]' : (plan?.target === 'canvas_bitmap' ? '[CANVAS]' : '[COMPOSITE]');
|
|
419
|
+
lines.push(` ${targetTag} ${node.path} <${node.type}> role=${node.role} label="${node.label}" ${node.interactive ? `(Action: ${node.actionId})` : ''}`);
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
if (ir.stateBindings.length > 0) {
|
|
423
|
+
lines.push(`\n⚡ Liên kết trạng thái (State Bindings):`);
|
|
424
|
+
for (const b of ir.stateBindings) {
|
|
425
|
+
lines.push(` - [${b.bindingType.toUpperCase()}] action=${b.actionId} target=${b.targetKey ?? 'N/A'}`);
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
return lines.join('\n');
|
|
430
|
+
}
|