@snap/valdi 1.1.7 → 1.2.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/.metadata/.bazelrc.template +8 -2
- package/.metadata/MODULE.bazel.template +20 -3
- package/.metadata/bzl/patches/rules_python/1.9.0/BUILD.bazel.template +1 -0
- package/.metadata/bzl/patches/rules_python/1.9.0/remove_setuptools_spaces.patch.template +96 -0
- package/README.md +35 -1
- package/bundled-skills/registry.json +2 -1
- package/bundled-skills/skills/valdi-animations/skill.md +49 -0
- package/bundled-skills/skills/valdi-async/skill.md +3 -2
- package/bundled-skills/skills/valdi-bazel/skill.md +2 -6
- package/bundled-skills/skills/valdi-cpp-runtime/skill.md +18 -0
- package/bundled-skills/skills/valdi-error-handling/skill.md +1 -1
- package/bundled-skills/skills/valdi-gestures/skill.md +3 -3
- package/bundled-skills/skills/valdi-migrate/skill.md +2 -1
- package/bundled-skills/skills/valdi-mock-breakdown/skill.md +4 -4
- package/bundled-skills/skills/valdi-mock-to-module/skill.md +9 -6
- package/bundled-skills/skills/valdi-overview/skill.md +2 -1
- package/bundled-skills/skills/valdi-perf/skill.md +121 -5
- package/bundled-skills/skills/valdi-pr-review/skill.md +189 -0
- package/bundled-skills/skills/valdi-profile/skill.md +5 -3
- package/bundled-skills/skills/valdi-setup/skill.md +3 -6
- package/bundled-skills/skills/valdi-testing/skill.md +1 -1
- package/bundled-skills/skills/valdi-tsx/skill.md +47 -11
- package/debugger/README.md +356 -0
- package/debugger/debugger-actions.js +373 -0
- package/debugger/debugger-api.js +225 -0
- package/debugger/debugger-bootstrap.js +295 -0
- package/debugger/debugger-model.js +790 -0
- package/debugger/debugger-performance.js +573 -0
- package/debugger/debugger-preview-html.js +676 -0
- package/debugger/debugger-providers.js +389 -0
- package/debugger/debugger-render.js +529 -0
- package/debugger/debugger-runtime.js +387 -0
- package/debugger/debugger-session.js +188 -0
- package/debugger/debugger-settings.js +209 -0
- package/debugger/debugger-state.js +221 -0
- package/debugger/debugger-tree-model.js +539 -0
- package/debugger/debugger.css +1865 -0
- package/debugger/devtools-panel.css +1318 -0
- package/debugger/devtools-panel.html +273 -0
- package/debugger/devtools-panel.js +3329 -0
- package/debugger/index.html +279 -0
- package/dist/commands/bootstrap.js +6 -5
- package/dist/commands/debugger.js +163 -0
- package/dist/commands/doctor.js +3 -62
- package/dist/commands/inspect.js +5 -2
- package/dist/commands/inspect_commands/input.js +176 -0
- package/dist/commands/inspect_commands/snapshot.js +1 -1
- package/dist/commands/inspect_commands/tree.js +1 -1
- package/dist/commands/projectsync.js +15 -0
- package/dist/commands/webHotreload.js +31 -0
- package/dist/core/constants.js +22 -6
- package/dist/debugger/chromiumConsole.js +279 -0
- package/dist/debugger/inputClient.js +473 -0
- package/dist/debugger/server.js +3801 -0
- package/dist/debugger/targetRegistry.js +436 -0
- package/dist/debugger/webPreviewPerformance.js +864 -0
- package/dist/index.js +0 -0
- package/dist/utils/BazelClient.js +34 -5
- package/dist/utils/applicationUtils.js +3 -0
- package/dist/utils/chromiumDevToolsClient.js +350 -0
- package/dist/utils/daemonClient.js +364 -44
- package/dist/utils/hermesClient.js +82 -176
- package/dist/utils/loopbackHost.js +14 -0
- package/dist/utils/owlCdpClient.js +282 -0
- package/dist/utils/owlDevToolsExtension.js +142 -0
- package/dist/utils/stringUtils.js +13 -1
- package/package.json +4 -2
- package/dist/commands/inspect_commands/snapshot.spec.js +0 -105
- package/dist/core/packageFiles.spec.js +0 -29
- package/dist/preview/previewGenerator.spec.js +0 -203
- package/dist/preview/viewModelParser.spec.js +0 -171
- package/dist/utils/linuxDistro.spec.js +0 -122
- package/dist/utils/skillsAdapters.spec.js +0 -141
- package/dist/utils/stringUtils.spec.js +0 -81
|
@@ -0,0 +1,790 @@
|
|
|
1
|
+
// Target selection, tree decoration, geometry, search, and analysis helpers.
|
|
2
|
+
function lastItem(items) {
|
|
3
|
+
return items[items.length - 1];
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
function matchingTargetForCurrentSelection(targets) {
|
|
7
|
+
const current = state.snapshot.target || {};
|
|
8
|
+
if (!current.id && !current.clientId && !current.contextId) return null;
|
|
9
|
+
|
|
10
|
+
return (
|
|
11
|
+
targets.find(target => target.id === current.id) ||
|
|
12
|
+
targets.find(target => target.clientId === current.clientId && target.contextId === current.contextId) ||
|
|
13
|
+
targets.find(
|
|
14
|
+
target =>
|
|
15
|
+
target.clientId === current.clientId &&
|
|
16
|
+
target.applicationId === current.applicationId &&
|
|
17
|
+
target.name === current.name,
|
|
18
|
+
) ||
|
|
19
|
+
null
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function chooseLiveTarget(targets) {
|
|
24
|
+
const selectedPort = selectedDaemonPort(null);
|
|
25
|
+
const portTargets = selectedPort === null ? [] : targets.filter(target => target.port === selectedPort);
|
|
26
|
+
const candidates = portTargets.length ? portTargets : targets;
|
|
27
|
+
if (!state.followLatestTarget) {
|
|
28
|
+
return (
|
|
29
|
+
matchingTargetForCurrentSelection(candidates) ||
|
|
30
|
+
matchingTargetForCurrentSelection(targets) ||
|
|
31
|
+
lastItem(candidates)
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const current = state.snapshot.target || {};
|
|
36
|
+
const appTargets = candidates.filter(
|
|
37
|
+
target =>
|
|
38
|
+
current.clientId && target.clientId === current.clientId && target.applicationId === current.applicationId,
|
|
39
|
+
);
|
|
40
|
+
return lastItem(appTargets.length ? appTargets : candidates);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function markSelectedTarget(targets, selectedTarget) {
|
|
44
|
+
return targets.map(target => ({
|
|
45
|
+
...target,
|
|
46
|
+
state: target.id === selectedTarget.id ? 'attached' : 'available',
|
|
47
|
+
}));
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function decorateSnapshot(snapshot) {
|
|
51
|
+
snapshot.tree = valdiDebuggerTreeModel.restoreTree(snapshot.tree);
|
|
52
|
+
if (!snapshot.tree) {
|
|
53
|
+
snapshot.target = snapshot.target || { ...emptyTarget };
|
|
54
|
+
snapshot.targets = snapshot.targets || [];
|
|
55
|
+
snapshot.issues = snapshot.issues || [];
|
|
56
|
+
snapshot.logs = snapshot.logs || [];
|
|
57
|
+
state.geometry = null;
|
|
58
|
+
return snapshot;
|
|
59
|
+
}
|
|
60
|
+
decorateNode(snapshot.tree);
|
|
61
|
+
if (!hasAnyRenderableBounds(snapshot.tree)) {
|
|
62
|
+
ensureBounds(snapshot.tree);
|
|
63
|
+
}
|
|
64
|
+
snapshot.issues = mergeIssues(snapshot.issues || [], analyzeTree(snapshot.tree));
|
|
65
|
+
state.geometry = computeGeometry(snapshot.tree);
|
|
66
|
+
return snapshot;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function decorateNode(node, path = '0') {
|
|
70
|
+
const records = [];
|
|
71
|
+
const childrenByNode = new Map();
|
|
72
|
+
const paths = new Map();
|
|
73
|
+
valdiDebuggerTreeModel.walk(
|
|
74
|
+
node,
|
|
75
|
+
(current, ancestors, _depth, sourceChildIndex) => {
|
|
76
|
+
const parent = ancestors.at(-1);
|
|
77
|
+
const parentPath = parent ? paths.get(parent) : null;
|
|
78
|
+
const childIndex = parent ? Math.max(0, sourceChildIndex ?? 0) : 0;
|
|
79
|
+
const currentPath = parentPath === null || parentPath === undefined ? path : `${parentPath}.${childIndex}`;
|
|
80
|
+
paths.set(current, currentPath);
|
|
81
|
+
if (parent) {
|
|
82
|
+
const children = childrenByNode.get(parent) || [];
|
|
83
|
+
children.push(current);
|
|
84
|
+
childrenByNode.set(parent, children);
|
|
85
|
+
}
|
|
86
|
+
childrenByNode.set(current, childrenByNode.get(current) || []);
|
|
87
|
+
|
|
88
|
+
if (current.element && current.element.frame) {
|
|
89
|
+
current.bounds = normalizeBounds(current.element.frame);
|
|
90
|
+
}
|
|
91
|
+
if (!current.id) {
|
|
92
|
+
if (current.element && current.element.id !== undefined) {
|
|
93
|
+
current.id = String(current.element.id);
|
|
94
|
+
} else if (current.key !== undefined) {
|
|
95
|
+
current.id = `${current.tag}:${current.key}:${currentPath}`;
|
|
96
|
+
} else {
|
|
97
|
+
current.id = `${current.tag}:${currentPath}`;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
records.push(current);
|
|
101
|
+
},
|
|
102
|
+
[],
|
|
103
|
+
0,
|
|
104
|
+
);
|
|
105
|
+
for (let index = records.length - 1; index >= 0; index -= 1) {
|
|
106
|
+
const current = records[index];
|
|
107
|
+
if (!current.bounds) {
|
|
108
|
+
const childBounds = (childrenByNode.get(current) || []).map(child => child.bounds).filter(Boolean);
|
|
109
|
+
if (childBounds.length) current.bounds = unionBounds(childBounds);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function normalizeBounds(bounds) {
|
|
115
|
+
return {
|
|
116
|
+
x: Number.parseFloat(bounds.x) || 0,
|
|
117
|
+
y: Number.parseFloat(bounds.y) || 0,
|
|
118
|
+
width: Math.max(0, Number.parseFloat(bounds.width) || 0),
|
|
119
|
+
height: Math.max(0, Number.parseFloat(bounds.height) || 0),
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function getNodeId(node) {
|
|
124
|
+
return valdiDebuggerTreeModel.id(node);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function getNodeKind(node) {
|
|
128
|
+
return node.component ? 'component' : 'element';
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function normalizeLabelValue(value) {
|
|
132
|
+
if (value === undefined || value === null || value === '') return '';
|
|
133
|
+
return valdiDebuggerTreeModel.formatValue(value, 0).replace(/^"|"$/g, '').trim();
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function isReadableLabelToken(value) {
|
|
137
|
+
if (!value) return false;
|
|
138
|
+
if (/^-?\d+(\.\d+)?$/.test(value)) return false;
|
|
139
|
+
if (/^#[0-9a-f]{3,8}$/i.test(value)) return false;
|
|
140
|
+
if (/^rgba?\(/i.test(value)) return false;
|
|
141
|
+
if (/^system(-[a-z]+)?\s+\d+$/i.test(value)) return false;
|
|
142
|
+
if (/^(prose|caption|heading|body|title|subtitle|primary|secondary|emphasis)$/i.test(value)) return false;
|
|
143
|
+
return true;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function firstReadableValue(sources, keys) {
|
|
147
|
+
for (const source of sources) {
|
|
148
|
+
if (!source || typeof source !== 'object') continue;
|
|
149
|
+
for (const key of keys) {
|
|
150
|
+
const value = normalizeLabelValue(source[key]);
|
|
151
|
+
if (value) return value;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
return '';
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
function truncateLabel(value, maxLength = 58) {
|
|
158
|
+
return value.length > maxLength ? `${value.slice(0, maxLength - 1)}...` : value;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
function overlayNodeLabel(node) {
|
|
162
|
+
return `${node.tag} #${getNodeId(node)}`;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
function overlayNodeDetail(node) {
|
|
166
|
+
const attrs = getNodeAttributes(node);
|
|
167
|
+
const text = firstReadableValue(
|
|
168
|
+
[attrs, node.viewModel, node],
|
|
169
|
+
[
|
|
170
|
+
'accessibilityLabel',
|
|
171
|
+
'accessibilityValue',
|
|
172
|
+
'accessibilityHint',
|
|
173
|
+
'accessible',
|
|
174
|
+
'ariaLabel',
|
|
175
|
+
'label',
|
|
176
|
+
'value',
|
|
177
|
+
'title',
|
|
178
|
+
'text',
|
|
179
|
+
'placeholder',
|
|
180
|
+
'name',
|
|
181
|
+
'accessibilityId',
|
|
182
|
+
'id',
|
|
183
|
+
],
|
|
184
|
+
);
|
|
185
|
+
const style = firstReadableValue(
|
|
186
|
+
[attrs, node],
|
|
187
|
+
['style', 'font', 'color', 'backgroundColor', 'iosClass', 'androidClass', 'macosClass', 'webClass'],
|
|
188
|
+
);
|
|
189
|
+
return truncateLabel(text || style || '', 72);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
function describeOverlayNode(node) {
|
|
193
|
+
const label = overlayNodeLabel(node);
|
|
194
|
+
const detail = overlayNodeDetail(node);
|
|
195
|
+
return detail ? `${label}\n${detail}` : label;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
function getNodeAttributes(node) {
|
|
199
|
+
return valdiDebuggerTreeModel.attributes(node);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
function getNumericAttribute(node, name) {
|
|
203
|
+
const value = getNodeAttributes(node)[name];
|
|
204
|
+
if (value === undefined || value === null) return 0;
|
|
205
|
+
const parsed = Number.parseFloat(String(value).replace(/^"|"$/g, ''));
|
|
206
|
+
return Number.isFinite(parsed) ? parsed : 0;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
function getScrollOffset(node) {
|
|
210
|
+
return {
|
|
211
|
+
x: getNumericAttribute(node, 'contentOffsetX'),
|
|
212
|
+
y: getNumericAttribute(node, 'contentOffsetY'),
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
function getTranslation(node) {
|
|
217
|
+
return {
|
|
218
|
+
x: getNumericAttribute(node, 'translationX'),
|
|
219
|
+
y: getNumericAttribute(node, 'translationY'),
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
function hasScrollState(node) {
|
|
224
|
+
const attrs = getNodeAttributes(node);
|
|
225
|
+
return attrs.contentOffsetX !== undefined || attrs.contentOffsetY !== undefined;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
function hasAnyRenderableBounds(root) {
|
|
229
|
+
let found = false;
|
|
230
|
+
walk(root, node => {
|
|
231
|
+
if (!node.bounds && !(node.element && node.element.frame)) return true;
|
|
232
|
+
found = true;
|
|
233
|
+
return false;
|
|
234
|
+
});
|
|
235
|
+
return found;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
function hasLocalFrames(root) {
|
|
239
|
+
let found = false;
|
|
240
|
+
walk(root, node => {
|
|
241
|
+
if (!node.element || !node.element.frame) return true;
|
|
242
|
+
found = true;
|
|
243
|
+
return false;
|
|
244
|
+
});
|
|
245
|
+
return found;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
function unionBounds(boundsList) {
|
|
249
|
+
const bounds = boundsList.filter(Boolean);
|
|
250
|
+
if (!bounds.length) return null;
|
|
251
|
+
const minX = Math.min(...bounds.map(item => item.x));
|
|
252
|
+
const minY = Math.min(...bounds.map(item => item.y));
|
|
253
|
+
const maxX = Math.max(...bounds.map(item => item.x + item.width));
|
|
254
|
+
const maxY = Math.max(...bounds.map(item => item.y + item.height));
|
|
255
|
+
return { x: minX, y: minY, width: maxX - minX, height: maxY - minY };
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
function firstElementWithFrame(root) {
|
|
259
|
+
let result = null;
|
|
260
|
+
walk(root, node => {
|
|
261
|
+
if (node.element && node.element.frame) {
|
|
262
|
+
const bounds = normalizeBounds(node.element.frame);
|
|
263
|
+
if (bounds.width > 0 && bounds.height > 0) {
|
|
264
|
+
result = node;
|
|
265
|
+
return false;
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
return true;
|
|
269
|
+
});
|
|
270
|
+
return result;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
function computeGeometry(root) {
|
|
274
|
+
const localFrames = hasLocalFrames(root);
|
|
275
|
+
const map = new Map();
|
|
276
|
+
const absoluteByNode = new Map();
|
|
277
|
+
const records = [];
|
|
278
|
+
const childrenByNode = new Map();
|
|
279
|
+
const childOffsets = new Map();
|
|
280
|
+
valdiDebuggerTreeModel.walk(
|
|
281
|
+
root,
|
|
282
|
+
(node, ancestors) => {
|
|
283
|
+
const parent = ancestors.at(-1);
|
|
284
|
+
const offset = parent ? childOffsets.get(parent) || { x: 0, y: 0 } : { x: 0, y: 0 };
|
|
285
|
+
if (parent) {
|
|
286
|
+
const children = childrenByNode.get(parent) || [];
|
|
287
|
+
children.push(node);
|
|
288
|
+
childrenByNode.set(parent, children);
|
|
289
|
+
}
|
|
290
|
+
childrenByNode.set(node, childrenByNode.get(node) || []);
|
|
291
|
+
const frame = node.element && node.element.frame ? normalizeBounds(node.element.frame) : null;
|
|
292
|
+
const absoluteCandidate = !localFrames && node.bounds ? normalizeBounds(node.bounds) : null;
|
|
293
|
+
let absolute = null;
|
|
294
|
+
let childOffset = offset;
|
|
295
|
+
if (frame) {
|
|
296
|
+
// Include the node's own translation in its absolute bounds so hit-testing
|
|
297
|
+
// and overlay boxes track transformed elements. Children inherit that
|
|
298
|
+
// translation through the absolute origin without double-counting it.
|
|
299
|
+
const translation = getTranslation(node);
|
|
300
|
+
absolute = {
|
|
301
|
+
x: offset.x + frame.x + translation.x,
|
|
302
|
+
y: offset.y + frame.y + translation.y,
|
|
303
|
+
width: frame.width,
|
|
304
|
+
height: frame.height,
|
|
305
|
+
};
|
|
306
|
+
const scrollOffset = getScrollOffset(node);
|
|
307
|
+
childOffset = {
|
|
308
|
+
x: absolute.x - scrollOffset.x,
|
|
309
|
+
y: absolute.y - scrollOffset.y,
|
|
310
|
+
};
|
|
311
|
+
} else if (absoluteCandidate) {
|
|
312
|
+
absolute = absoluteCandidate;
|
|
313
|
+
}
|
|
314
|
+
childOffsets.set(node, childOffset);
|
|
315
|
+
records.push({ absolute, frame, node });
|
|
316
|
+
},
|
|
317
|
+
[],
|
|
318
|
+
0,
|
|
319
|
+
);
|
|
320
|
+
for (let index = records.length - 1; index >= 0; index -= 1) {
|
|
321
|
+
const item = records[index];
|
|
322
|
+
let absolute = item.absolute;
|
|
323
|
+
const childBounds = (childrenByNode.get(item.node) || [])
|
|
324
|
+
.map(child => absoluteByNode.get(child))
|
|
325
|
+
.filter(Boolean);
|
|
326
|
+
if (!absolute || item.node.component) absolute = unionBounds(childBounds) || absolute;
|
|
327
|
+
if (absolute) {
|
|
328
|
+
absoluteByNode.set(item.node, absolute);
|
|
329
|
+
map.set(getNodeId(item.node), {
|
|
330
|
+
local: item.node.bounds ? normalizeBounds(item.node.bounds) : item.frame,
|
|
331
|
+
absolute,
|
|
332
|
+
});
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
const rootBounds = absoluteByNode.get(root) || null;
|
|
337
|
+
const viewportNode = localFrames ? firstElementWithFrame(root) : root;
|
|
338
|
+
const viewportGeometry = viewportNode ? map.get(getNodeId(viewportNode)) : null;
|
|
339
|
+
const viewport = viewportGeometry?.absolute || rootBounds || { x: 0, y: 0, width: 390, height: 760 };
|
|
340
|
+
return {
|
|
341
|
+
localFrames,
|
|
342
|
+
map,
|
|
343
|
+
viewport: {
|
|
344
|
+
x: viewport.x,
|
|
345
|
+
y: viewport.y,
|
|
346
|
+
width: Math.max(1, viewport.width),
|
|
347
|
+
height: Math.max(1, viewport.height),
|
|
348
|
+
},
|
|
349
|
+
};
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
function getNodeGeometry(node) {
|
|
353
|
+
return state.geometry?.map.get(getNodeId(node)) || null;
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
function getViewportBounds() {
|
|
357
|
+
return state.geometry?.viewport || { x: 0, y: 0, width: 390, height: 760 };
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
function getElementIdForNode(node) {
|
|
361
|
+
if (!node) return null;
|
|
362
|
+
if (node.element && node.element.id !== undefined) return Number(node.element.id);
|
|
363
|
+
const parsed = Number.parseInt(getNodeId(node), 10);
|
|
364
|
+
return Number.isNaN(parsed) ? null : parsed;
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
function pointFromScreenEvent(event) {
|
|
368
|
+
const viewport = getViewportBounds();
|
|
369
|
+
const screenBounds = elements.screen.getBoundingClientRect();
|
|
370
|
+
const ratioX = Math.min(1, Math.max(0, (event.clientX - screenBounds.left) / Math.max(1, screenBounds.width)));
|
|
371
|
+
const ratioY = Math.min(1, Math.max(0, (event.clientY - screenBounds.top) / Math.max(1, screenBounds.height)));
|
|
372
|
+
return {
|
|
373
|
+
x: viewport.x + ratioX * viewport.width,
|
|
374
|
+
y: viewport.y + ratioY * viewport.height,
|
|
375
|
+
scaleX: viewport.width / Math.max(1, screenBounds.width),
|
|
376
|
+
scaleY: viewport.height / Math.max(1, screenBounds.height),
|
|
377
|
+
};
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
function boundsContainPoint(bounds, point) {
|
|
381
|
+
return (
|
|
382
|
+
bounds &&
|
|
383
|
+
point.x >= bounds.x &&
|
|
384
|
+
point.y >= bounds.y &&
|
|
385
|
+
point.x <= bounds.x + bounds.width &&
|
|
386
|
+
point.y <= bounds.y + bounds.height
|
|
387
|
+
);
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
function findNodeAtPoint(point, predicate = () => true) {
|
|
391
|
+
const hits = [];
|
|
392
|
+
if (!hasSnapshotTree()) return null;
|
|
393
|
+
walk(state.snapshot.tree, (node, _parent, depth) => {
|
|
394
|
+
if (!predicate(node)) return;
|
|
395
|
+
const geometry = getNodeGeometry(node);
|
|
396
|
+
if (!boundsContainPoint(geometry?.absolute, point)) return;
|
|
397
|
+
const bounds = geometry.absolute;
|
|
398
|
+
hits.push({
|
|
399
|
+
node,
|
|
400
|
+
depth,
|
|
401
|
+
area: Math.max(1, bounds.width * bounds.height),
|
|
402
|
+
});
|
|
403
|
+
});
|
|
404
|
+
|
|
405
|
+
hits.sort((a, b) => b.depth - a.depth || a.area - b.area);
|
|
406
|
+
return hits[0]?.node || null;
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
function findInputNodeAtEvent(event) {
|
|
410
|
+
const point = pointFromScreenEvent(event);
|
|
411
|
+
const overlayNode = event.target.closest('.overlay-node');
|
|
412
|
+
const overlayTreeNode =
|
|
413
|
+
overlayNode && elements.screen.contains(overlayNode) ? findNode(overlayNode.dataset.nodeId) : null;
|
|
414
|
+
const nodeWithElement =
|
|
415
|
+
overlayTreeNode && getElementIdForNode(overlayTreeNode) !== null
|
|
416
|
+
? overlayTreeNode
|
|
417
|
+
: findNodeAtPoint(point, node => getElementIdForNode(node) !== null);
|
|
418
|
+
return { node: nodeWithElement, point };
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
function findOverlayNodeAtEvent(event) {
|
|
422
|
+
const overlayNode = event.target.closest('.overlay-node');
|
|
423
|
+
if (!overlayNode || !elements.screen.contains(overlayNode)) return null;
|
|
424
|
+
return findNode(overlayNode.dataset.nodeId);
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
let debuggerInputDispatchTail = Promise.resolve(null);
|
|
428
|
+
|
|
429
|
+
function captureDebuggerInputTarget() {
|
|
430
|
+
if (state.source !== 'daemon') return null;
|
|
431
|
+
const params = getSelectedTargetParams();
|
|
432
|
+
if (!params.clientId || !params.contextId || !Number.isFinite(params.port)) return null;
|
|
433
|
+
return Object.freeze({
|
|
434
|
+
port: params.port,
|
|
435
|
+
clientId: params.clientId,
|
|
436
|
+
contextId: params.contextId,
|
|
437
|
+
});
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
function debuggerInputTargetKey(target) {
|
|
441
|
+
return JSON.stringify([target.port, target.clientId, target.contextId]);
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
function debuggerInputTargetElementKey(target, elementId) {
|
|
445
|
+
return JSON.stringify([target.port, target.clientId, target.contextId, elementId]);
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
function isSelectedDebuggerInputTarget(target) {
|
|
449
|
+
const selectedTarget = captureDebuggerInputTarget();
|
|
450
|
+
return selectedTarget !== null && debuggerInputTargetKey(selectedTarget) === debuggerInputTargetKey(target);
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
function scheduleInputRefresh(target, delayMs) {
|
|
454
|
+
const key = debuggerInputTargetKey(target);
|
|
455
|
+
const previousTimer = state.inputRefreshTimers.get(key);
|
|
456
|
+
if (previousTimer) window.clearTimeout(previousTimer);
|
|
457
|
+
const timer = window.setTimeout(() => {
|
|
458
|
+
state.inputRefreshTimers.delete(key);
|
|
459
|
+
if (!isSelectedDebuggerInputTarget(target)) return;
|
|
460
|
+
loadRealSnapshot(target, { silent: true, preserveSelection: true });
|
|
461
|
+
}, delayMs);
|
|
462
|
+
state.inputRefreshTimers.set(key, timer);
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
async function dispatchDebuggerInput(target, payload, options) {
|
|
466
|
+
if (!target) {
|
|
467
|
+
addLog('warn', 'input', 'Attach to a live Valdi daemon target before dispatching input.');
|
|
468
|
+
return null;
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
try {
|
|
472
|
+
const result = await apiPost('/api/input', target, payload, { timeoutMs: 5000 });
|
|
473
|
+
const input = result.input || {};
|
|
474
|
+
if (input.handled) {
|
|
475
|
+
if (!options.quiet) {
|
|
476
|
+
const action = input.action ? ` via ${input.action}` : '';
|
|
477
|
+
addLog('info', 'input', `${payload.type} handled by #${input.elementId}${action}.`);
|
|
478
|
+
}
|
|
479
|
+
if (options.refresh !== false) {
|
|
480
|
+
scheduleInputRefresh(target, options.refreshDelayMs ?? 120);
|
|
481
|
+
}
|
|
482
|
+
} else if (!options.quiet) {
|
|
483
|
+
addLog('warn', 'input', input.message || `${payload.type} was not handled.`);
|
|
484
|
+
}
|
|
485
|
+
return input;
|
|
486
|
+
} catch (error) {
|
|
487
|
+
addLog('error', 'input', `${payload.type} failed: ${error.message}`);
|
|
488
|
+
return null;
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
function reserveDebuggerInput(target) {
|
|
493
|
+
let releaseReservation;
|
|
494
|
+
let cancelled = false;
|
|
495
|
+
const reservation = new Promise(resolve => {
|
|
496
|
+
releaseReservation = resolve;
|
|
497
|
+
});
|
|
498
|
+
const dispatch = debuggerInputDispatchTail
|
|
499
|
+
.catch(error => {
|
|
500
|
+
addLog('warn', 'input', `Continuing after a queued input failed: ${error?.message || String(error)}`);
|
|
501
|
+
return null;
|
|
502
|
+
})
|
|
503
|
+
.then(() => reservation)
|
|
504
|
+
.then(input => (input && !cancelled ? dispatchDebuggerInput(target, input.payload, input.options) : null));
|
|
505
|
+
debuggerInputDispatchTail = dispatch;
|
|
506
|
+
let released = false;
|
|
507
|
+
return Object.freeze({
|
|
508
|
+
dispatch(payload, options) {
|
|
509
|
+
if (!released) {
|
|
510
|
+
released = true;
|
|
511
|
+
releaseReservation({ payload, options });
|
|
512
|
+
}
|
|
513
|
+
return dispatch;
|
|
514
|
+
},
|
|
515
|
+
cancel() {
|
|
516
|
+
cancelled = true;
|
|
517
|
+
if (!released) {
|
|
518
|
+
released = true;
|
|
519
|
+
releaseReservation(null);
|
|
520
|
+
}
|
|
521
|
+
return dispatch;
|
|
522
|
+
},
|
|
523
|
+
});
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
function enqueueDebuggerInput(target, payload, options) {
|
|
527
|
+
return reserveDebuggerInput(target).dispatch(payload, options);
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
function getPageScrollTarget() {
|
|
531
|
+
return document.scrollingElement || document.documentElement || document.body;
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
function getPageScrollPosition() {
|
|
535
|
+
return {
|
|
536
|
+
x: window.scrollX || getPageScrollTarget().scrollLeft || 0,
|
|
537
|
+
y: window.scrollY || getPageScrollTarget().scrollTop || 0,
|
|
538
|
+
};
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
function restorePageScrollPosition(position) {
|
|
542
|
+
window.scrollTo(position.x, position.y);
|
|
543
|
+
const scrollTarget = getPageScrollTarget();
|
|
544
|
+
scrollTarget.scrollLeft = position.x;
|
|
545
|
+
scrollTarget.scrollTop = position.y;
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
function filterHierarchyToNode(id) {
|
|
549
|
+
elements.treeSearch.value = `#${id}`;
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
function selectPreviewNode(node) {
|
|
553
|
+
const scrollPosition = getPageScrollPosition();
|
|
554
|
+
const id = getNodeId(node);
|
|
555
|
+
filterHierarchyToNode(id);
|
|
556
|
+
selectNode(id, { scrollTree: false });
|
|
557
|
+
restorePageScrollPosition(scrollPosition);
|
|
558
|
+
window.requestAnimationFrame(() => restorePageScrollPosition(scrollPosition));
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
function canScrollBy(element, deltaY) {
|
|
562
|
+
if (!element || !deltaY) return false;
|
|
563
|
+
const maxScrollTop = Math.max(0, element.scrollHeight - element.clientHeight);
|
|
564
|
+
if (maxScrollTop <= 0) return false;
|
|
565
|
+
if (deltaY < 0) return element.scrollTop > 0;
|
|
566
|
+
return element.scrollTop < maxScrollTop;
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
function forwardPreviewWheelToPage(event) {
|
|
570
|
+
if (event.target.closest('.html-preview-root')) return;
|
|
571
|
+
const scrollTarget = getPageScrollTarget();
|
|
572
|
+
if (!canScrollBy(scrollTarget, event.deltaY)) return;
|
|
573
|
+
|
|
574
|
+
event.preventDefault();
|
|
575
|
+
scrollTarget.scrollBy({
|
|
576
|
+
top: event.deltaY,
|
|
577
|
+
left: event.deltaX,
|
|
578
|
+
behavior: 'auto',
|
|
579
|
+
});
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
async function dispatchTapInput(event) {
|
|
583
|
+
if (event.target.closest('.html-preview-root')) return;
|
|
584
|
+
const overlaySelection = findOverlayNodeAtEvent(event);
|
|
585
|
+
const { node, point } = findInputNodeAtEvent(event);
|
|
586
|
+
const selectedPreviewNode = overlaySelection || node;
|
|
587
|
+
const elementId = getElementIdForNode(node);
|
|
588
|
+
|
|
589
|
+
if (selectedPreviewNode) {
|
|
590
|
+
event.preventDefault();
|
|
591
|
+
event.stopPropagation();
|
|
592
|
+
selectPreviewNode(selectedPreviewNode);
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
if (elementId === null) {
|
|
596
|
+
if (!selectedPreviewNode) {
|
|
597
|
+
addLog('warn', 'input', 'Click ignored because no Valdi element was under the cursor.');
|
|
598
|
+
}
|
|
599
|
+
return;
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
const target = captureDebuggerInputTarget();
|
|
603
|
+
await enqueueDebuggerInput(
|
|
604
|
+
target,
|
|
605
|
+
{
|
|
606
|
+
type: 'tap',
|
|
607
|
+
elementId,
|
|
608
|
+
x: point.x,
|
|
609
|
+
y: point.y,
|
|
610
|
+
},
|
|
611
|
+
{},
|
|
612
|
+
);
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
function isInteractiveNode(node) {
|
|
616
|
+
const attrs = getNodeAttributes(node);
|
|
617
|
+
return Boolean(attrs.onTap || attrs.onPress || attrs.onClick || attrs.title || node.tag === 'button');
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
function analyzeTree(root) {
|
|
621
|
+
const issues = [];
|
|
622
|
+
const seen = new Set();
|
|
623
|
+
|
|
624
|
+
function addIssue(issue) {
|
|
625
|
+
if (seen.has(issue.id)) return;
|
|
626
|
+
seen.add(issue.id);
|
|
627
|
+
issues.push(issue);
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
walk(root, node => {
|
|
631
|
+
const id = getNodeId(node);
|
|
632
|
+
const attrs = getNodeAttributes(node);
|
|
633
|
+
const bounds = node.bounds ? normalizeBounds(node.bounds) : null;
|
|
634
|
+
if (!bounds) return;
|
|
635
|
+
|
|
636
|
+
if (bounds.width <= 0 || bounds.height <= 0) {
|
|
637
|
+
addIssue({
|
|
638
|
+
id: `bounds-${id}`,
|
|
639
|
+
severity: 'error',
|
|
640
|
+
nodeId: id,
|
|
641
|
+
title: 'Invalid bounds',
|
|
642
|
+
message: `${node.tag} #${id} has non-positive layout bounds.`,
|
|
643
|
+
});
|
|
644
|
+
}
|
|
645
|
+
|
|
646
|
+
if (isInteractiveNode(node) && (bounds.width < 44 || bounds.height < 44)) {
|
|
647
|
+
addIssue({
|
|
648
|
+
id: `touch-${id}`,
|
|
649
|
+
severity: 'warn',
|
|
650
|
+
nodeId: id,
|
|
651
|
+
title: 'Small touch target',
|
|
652
|
+
message: `${node.tag} #${id} is ${bounds.width}x${bounds.height}. Native targets usually need at least 44x44.`,
|
|
653
|
+
});
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
if (
|
|
657
|
+
node.tag === 'label' &&
|
|
658
|
+
attrs.numberOfLines === '1' &&
|
|
659
|
+
attrs.value &&
|
|
660
|
+
String(attrs.value).length * 6 > bounds.width
|
|
661
|
+
) {
|
|
662
|
+
addIssue({
|
|
663
|
+
id: `label-${id}`,
|
|
664
|
+
severity: 'warn',
|
|
665
|
+
nodeId: id,
|
|
666
|
+
title: 'Possible label truncation',
|
|
667
|
+
message: `Label #${id} has numberOfLines=1 and text that may exceed its measured width.`,
|
|
668
|
+
});
|
|
669
|
+
}
|
|
670
|
+
});
|
|
671
|
+
|
|
672
|
+
return issues.slice(0, 80);
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
function mergeIssues(existing, generated) {
|
|
676
|
+
const byId = new Map();
|
|
677
|
+
for (const issue of [...existing, ...generated]) {
|
|
678
|
+
const id = issue.id || `${issue.title}:${issue.nodeId || ''}:${issue.message}`;
|
|
679
|
+
byId.set(id, { ...issue, id });
|
|
680
|
+
}
|
|
681
|
+
return Array.from(byId.values());
|
|
682
|
+
}
|
|
683
|
+
|
|
684
|
+
function walk(node, visitor, parent = null, depth = 0) {
|
|
685
|
+
return valdiDebuggerTreeModel.walk(
|
|
686
|
+
node,
|
|
687
|
+
(current, ancestors, currentDepth) => {
|
|
688
|
+
return visitor(current, ancestors.at(-1) ?? parent, depth + currentDepth);
|
|
689
|
+
},
|
|
690
|
+
[],
|
|
691
|
+
0,
|
|
692
|
+
);
|
|
693
|
+
}
|
|
694
|
+
|
|
695
|
+
function walkVisible(node, visitor, parent = null, depth = 0) {
|
|
696
|
+
if (!node) return true;
|
|
697
|
+
return valdiDebuggerTreeModel.walkVisible(
|
|
698
|
+
node,
|
|
699
|
+
(current, ancestors, currentDepth) => {
|
|
700
|
+
return visitor(current, ancestors.at(-1) ?? parent, depth + currentDepth);
|
|
701
|
+
},
|
|
702
|
+
current => state.expandedNodeIds.has(getNodeId(current)),
|
|
703
|
+
[],
|
|
704
|
+
0,
|
|
705
|
+
);
|
|
706
|
+
}
|
|
707
|
+
|
|
708
|
+
function findNodeInTree(root, id) {
|
|
709
|
+
return valdiDebuggerTreeModel.findNode(root, id);
|
|
710
|
+
}
|
|
711
|
+
|
|
712
|
+
function findNode(id) {
|
|
713
|
+
if (!hasSnapshotTree() || id === null || id === undefined) return null;
|
|
714
|
+
return findNodeInTree(state.snapshot.tree, id);
|
|
715
|
+
}
|
|
716
|
+
|
|
717
|
+
function getPathToNode(id) {
|
|
718
|
+
return hasSnapshotTree() ? valdiDebuggerTreeModel.pathToNode(state.snapshot.tree, id) : [];
|
|
719
|
+
}
|
|
720
|
+
|
|
721
|
+
function expandPathToNode(id) {
|
|
722
|
+
const path = getPathToNode(id);
|
|
723
|
+
for (const node of path.slice(0, -1)) {
|
|
724
|
+
state.expandedNodeIds.add(getNodeId(node));
|
|
725
|
+
}
|
|
726
|
+
}
|
|
727
|
+
|
|
728
|
+
function collapseTree() {
|
|
729
|
+
state.expandedNodeIds.clear();
|
|
730
|
+
}
|
|
731
|
+
|
|
732
|
+
function collapseTreeNode(node) {
|
|
733
|
+
walk(node, descendant => {
|
|
734
|
+
state.expandedNodeIds.delete(getNodeId(descendant));
|
|
735
|
+
});
|
|
736
|
+
}
|
|
737
|
+
|
|
738
|
+
function toggleTreeNode(id) {
|
|
739
|
+
const node = findNode(id);
|
|
740
|
+
if (!node || !valdiDebuggerTreeModel.hasChildren(node)) return;
|
|
741
|
+
if (state.expandedNodeIds.has(id)) {
|
|
742
|
+
collapseTreeNode(node);
|
|
743
|
+
} else {
|
|
744
|
+
state.expandedNodeIds.add(id);
|
|
745
|
+
}
|
|
746
|
+
renderTree();
|
|
747
|
+
}
|
|
748
|
+
|
|
749
|
+
function ensureBounds(node, depth = 0, index = 0) {
|
|
750
|
+
if (!node) return;
|
|
751
|
+
valdiDebuggerTreeModel.walk(
|
|
752
|
+
node,
|
|
753
|
+
(current, _ancestors, currentDepth, sourceChildIndex) => {
|
|
754
|
+
const currentIndex = sourceChildIndex === null ? index : sourceChildIndex;
|
|
755
|
+
const hasChildren = valdiDebuggerTreeModel.hasChildren(current);
|
|
756
|
+
if (!current.bounds) {
|
|
757
|
+
current.bounds = {
|
|
758
|
+
x: 12 + (depth + currentDepth) * 16,
|
|
759
|
+
y: 24 + currentIndex * 54 + (depth + currentDepth) * 14,
|
|
760
|
+
width: Math.max(80, 360 - (depth + currentDepth) * 28),
|
|
761
|
+
height: hasChildren ? 110 : 42,
|
|
762
|
+
};
|
|
763
|
+
}
|
|
764
|
+
},
|
|
765
|
+
[],
|
|
766
|
+
0,
|
|
767
|
+
);
|
|
768
|
+
}
|
|
769
|
+
|
|
770
|
+
function escapeHtml(value) {
|
|
771
|
+
return String(value)
|
|
772
|
+
.replace(/&/g, '&')
|
|
773
|
+
.replace(/</g, '<')
|
|
774
|
+
.replace(/>/g, '>')
|
|
775
|
+
.replace(/"/g, '"')
|
|
776
|
+
.replace(/'/g, ''');
|
|
777
|
+
}
|
|
778
|
+
|
|
779
|
+
function isMacDesktopTarget(target = state.snapshot.target) {
|
|
780
|
+
return target?.applicationId === 'ValdiDesktop' && String(target.platform).toLowerCase() === 'ios';
|
|
781
|
+
}
|
|
782
|
+
|
|
783
|
+
function displayPlatform(target = state.snapshot.target) {
|
|
784
|
+
return isMacDesktopTarget(target) ? 'macOS desktop (iOS class bridge)' : target.platform;
|
|
785
|
+
}
|
|
786
|
+
|
|
787
|
+
function hierarchySourceLabel() {
|
|
788
|
+
if (state.source === 'daemon') return 'Live';
|
|
789
|
+
return 'Empty';
|
|
790
|
+
}
|