@snap/valdi 1.1.5 → 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.
Files changed (82) hide show
  1. package/.metadata/.bazelrc.template +9 -3
  2. package/.metadata/MODULE.bazel.template +112 -3
  3. package/.metadata/bzl/patches/rules_python/1.9.0/BUILD.bazel.template +1 -0
  4. package/.metadata/bzl/patches/rules_python/1.9.0/remove_setuptools_spaces.patch.template +96 -0
  5. package/README.md +35 -1
  6. package/bundled-skills/registry.json +2 -1
  7. package/bundled-skills/skills/valdi-animations/skill.md +49 -0
  8. package/bundled-skills/skills/valdi-async/skill.md +3 -2
  9. package/bundled-skills/skills/valdi-bazel/skill.md +2 -6
  10. package/bundled-skills/skills/valdi-compiler/skill.md +4 -4
  11. package/bundled-skills/skills/valdi-cpp-runtime/skill.md +18 -0
  12. package/bundled-skills/skills/valdi-error-handling/skill.md +1 -1
  13. package/bundled-skills/skills/valdi-gestures/skill.md +3 -3
  14. package/bundled-skills/skills/valdi-migrate/skill.md +2 -1
  15. package/bundled-skills/skills/valdi-mock-breakdown/skill.md +4 -4
  16. package/bundled-skills/skills/valdi-mock-to-module/skill.md +9 -6
  17. package/bundled-skills/skills/valdi-overview/skill.md +2 -1
  18. package/bundled-skills/skills/valdi-perf/skill.md +121 -5
  19. package/bundled-skills/skills/valdi-pr-review/skill.md +189 -0
  20. package/bundled-skills/skills/valdi-profile/skill.md +5 -3
  21. package/bundled-skills/skills/valdi-setup/skill.md +3 -6
  22. package/bundled-skills/skills/valdi-testing/skill.md +1 -1
  23. package/bundled-skills/skills/valdi-tsx/skill.md +47 -11
  24. package/debugger/README.md +356 -0
  25. package/debugger/debugger-actions.js +373 -0
  26. package/debugger/debugger-api.js +225 -0
  27. package/debugger/debugger-bootstrap.js +295 -0
  28. package/debugger/debugger-model.js +790 -0
  29. package/debugger/debugger-performance.js +573 -0
  30. package/debugger/debugger-preview-html.js +676 -0
  31. package/debugger/debugger-providers.js +389 -0
  32. package/debugger/debugger-render.js +529 -0
  33. package/debugger/debugger-runtime.js +387 -0
  34. package/debugger/debugger-session.js +188 -0
  35. package/debugger/debugger-settings.js +209 -0
  36. package/debugger/debugger-state.js +221 -0
  37. package/debugger/debugger-tree-model.js +539 -0
  38. package/debugger/debugger.css +1865 -0
  39. package/debugger/devtools-panel.css +1318 -0
  40. package/debugger/devtools-panel.html +273 -0
  41. package/debugger/devtools-panel.js +3329 -0
  42. package/debugger/index.html +279 -0
  43. package/dist/commands/bootstrap.js +6 -5
  44. package/dist/commands/build.js +6 -0
  45. package/dist/commands/debugger.js +163 -0
  46. package/dist/commands/doctor.js +5 -125
  47. package/dist/commands/inspect.js +5 -2
  48. package/dist/commands/inspect_commands/input.js +176 -0
  49. package/dist/commands/inspect_commands/snapshot.js +1 -1
  50. package/dist/commands/inspect_commands/tree.js +1 -1
  51. package/dist/commands/install.js +6 -0
  52. package/dist/commands/projectsync.js +15 -0
  53. package/dist/commands/webHotreload.js +31 -0
  54. package/dist/core/constants.js +26 -7
  55. package/dist/debugger/chromiumConsole.js +279 -0
  56. package/dist/debugger/inputClient.js +473 -0
  57. package/dist/debugger/server.js +3801 -0
  58. package/dist/debugger/targetRegistry.js +436 -0
  59. package/dist/debugger/webPreviewPerformance.js +864 -0
  60. package/dist/index.js +0 -0
  61. package/dist/setup/DevSetupHelper.js +0 -3
  62. package/dist/setup/linuxSetup.js +0 -14
  63. package/dist/setup/macOSSetup.js +1 -2
  64. package/dist/utils/BazelClient.js +34 -5
  65. package/dist/utils/applicationUtils.js +18 -0
  66. package/dist/utils/chromiumDevToolsClient.js +350 -0
  67. package/dist/utils/daemonClient.js +364 -44
  68. package/dist/utils/hermesClient.js +82 -176
  69. package/dist/utils/linuxDistro.js +0 -21
  70. package/dist/utils/loopbackHost.js +14 -0
  71. package/dist/utils/owlCdpClient.js +282 -0
  72. package/dist/utils/owlDevToolsExtension.js +142 -0
  73. package/dist/utils/skillsAdapters.js +40 -14
  74. package/dist/utils/stringUtils.js +13 -1
  75. package/package.json +4 -2
  76. package/dist/commands/inspect_commands/snapshot.spec.js +0 -105
  77. package/dist/core/packageFiles.spec.js +0 -29
  78. package/dist/preview/previewGenerator.spec.js +0 -203
  79. package/dist/preview/viewModelParser.spec.js +0 -171
  80. package/dist/utils/linuxDistro.spec.js +0 -170
  81. package/dist/utils/skillsAdapters.spec.js +0 -60
  82. package/dist/utils/stringUtils.spec.js +0 -81
@@ -0,0 +1,529 @@
1
+ // Main UI rendering for preview, hierarchy, overlay, targets, and inspector.
2
+ function render() {
3
+ renderHeader();
4
+ renderTargets();
5
+ renderDaemonStatus();
6
+ renderTree();
7
+ renderPreview();
8
+ renderOverlay();
9
+ renderInspector();
10
+ renderLogs();
11
+ renderPerformance();
12
+ renderDebuggerProviders();
13
+ renderDebugSettings();
14
+ }
15
+
16
+ function renderPreview() {
17
+ elements.appPreview.querySelectorAll('.preview-warning').forEach(node => node.remove());
18
+ const htmlPreviewRendered = renderHtmlPreview();
19
+ if (state.rootSnapshotImage && !htmlPreviewRendered) {
20
+ elements.rootSnapshotImage.src = state.rootSnapshotImage;
21
+ elements.rootSnapshotImage.hidden = false;
22
+ } else {
23
+ elements.rootSnapshotImage.removeAttribute('src');
24
+ elements.rootSnapshotImage.hidden = true;
25
+ }
26
+ if (!hasSnapshotTree()) {
27
+ const empty = document.createElement('div');
28
+ empty.className = 'preview-warning';
29
+ empty.textContent = 'No Valdi snapshot loaded. Attach to a live target.';
30
+ elements.appPreview.appendChild(empty);
31
+ } else if (state.source !== 'daemon' && state.snapshot.target?.clientId && state.snapshot.target?.contextId) {
32
+ const warning = document.createElement('div');
33
+ warning.className = 'preview-warning';
34
+ warning.textContent =
35
+ 'Live Valdi target found, but this preview is not attached. Press Attach or Refresh to fetch the current tree.';
36
+ elements.appPreview.appendChild(warning);
37
+ }
38
+ elements.copyPreviewButton.disabled = !state.rootSnapshotImage && !hasSnapshotTree();
39
+ }
40
+
41
+ function renderPreviewTargetSelect() {
42
+ const options = [
43
+ {
44
+ value: String(STANDALONE_DAEMON_PORT),
45
+ label: `SnapDrawing / standalone :${STANDALONE_DAEMON_PORT}`,
46
+ },
47
+ {
48
+ value: String(MOBILE_DAEMON_PORT),
49
+ label: `mobile :${MOBILE_DAEMON_PORT}`,
50
+ },
51
+ ];
52
+
53
+ const selectedPort = String(selectedDaemonPort());
54
+ const selectedValue = options.some(option => option.value === selectedPort)
55
+ ? selectedPort
56
+ : String(STANDALONE_DAEMON_PORT);
57
+ const markup = options
58
+ .map(option => `<option value="${escapeHtml(option.value)}">${escapeHtml(option.label)}</option>`)
59
+ .join('');
60
+ if (elements.portSelect.innerHTML !== markup) {
61
+ elements.portSelect.innerHTML = markup;
62
+ }
63
+ elements.portSelect.value = selectedValue;
64
+ }
65
+
66
+ function renderHeader() {
67
+ renderPreviewTargetSelect();
68
+ const target = state.snapshot.target || emptyTarget;
69
+ const attached = isDebuggerAttached();
70
+ elements.sessionSubtitle.textContent =
71
+ state.source === 'empty'
72
+ ? 'No session selected'
73
+ : `${target.name} - ${displayPlatform(target)} - ${target.transport || 'daemon'}`;
74
+ elements.reloaderDot.className = state.source === 'daemon' ? 'dot good' : 'dot warn';
75
+ elements.reloaderState.textContent = state.source === 'daemon' ? 'Live snapshot' : 'No live snapshot';
76
+ const proxyOnline = state.lastStatus?.hotReloadProxy?.connected;
77
+ elements.proxyDot.className = proxyOnline || attached ? 'dot good' : 'dot warn';
78
+ elements.proxyState.textContent = proxyOnline
79
+ ? `Proxy ${state.lastStatus.hotReloadProxy.port} online`
80
+ : attached
81
+ ? `Target ${target.proxyPort || target.port || elements.portSelect.value} attached`
82
+ : hasSelectedLiveTarget()
83
+ ? `Target ${target.proxyPort || target.port || elements.portSelect.value} available`
84
+ : `Port ${elements.portSelect.value} idle`;
85
+ elements.attachButton.textContent = attached ? 'Detach' : hasSelectedLiveTarget() ? 'Resume' : 'Attach';
86
+ elements.autoRefreshToggle.checked = state.autoRefresh;
87
+ elements.hierarchySource.textContent = hierarchySourceLabel();
88
+ elements.hierarchySource.className = `source-pill ${state.source === 'daemon' ? 'live' : ''}`;
89
+ }
90
+
91
+ function renderTargets() {
92
+ const targets = debuggerTargets();
93
+ if (!targets.length) {
94
+ elements.targetList.innerHTML = `<div class="empty">No Valdi targets found. Start a playground app and hot reloader, then refresh.</div>`;
95
+ return;
96
+ }
97
+
98
+ elements.targetList.innerHTML = targets
99
+ .map(target => {
100
+ const active = target.id === state.snapshot.target?.id ? ' active' : '';
101
+ const dot = target.state === 'attached' ? 'good' : target.state === 'paused' ? 'warn' : '';
102
+ return `
103
+ <div class="target${active}" data-target-id="${escapeHtml(target.id)}" role="button" tabindex="0">
104
+ <div class="target-top">
105
+ <span class="target-name">${escapeHtml(target.name)}</span>
106
+ <span class="status-pill"><span class="dot ${dot}"></span>${escapeHtml(target.state)}</span>
107
+ </div>
108
+ <div class="meta-grid">
109
+ <div class="metric"><div class="metric-label">Platform</div><div class="metric-value">${escapeHtml(displayPlatform(target))}</div></div>
110
+ <div class="metric"><div class="metric-label">Transport</div><div class="metric-value">${escapeHtml(target.transport || state.snapshot.target.transport || 'n/a')}</div></div>
111
+ ${target.applicationId ? `<div class="metric"><div class="metric-label">App</div><div class="metric-value">${escapeHtml(target.applicationId)}</div></div>` : ''}
112
+ </div>
113
+ </div>
114
+ `;
115
+ })
116
+ .join('');
117
+ }
118
+
119
+ function renderDaemonStatus() {
120
+ if (!state.lastStatus) {
121
+ elements.daemonStatus.innerHTML = `<div class="empty">Status has not been checked yet.</div>`;
122
+ return;
123
+ }
124
+
125
+ const rows = [];
126
+ for (const portStatus of state.lastStatus.ports || []) {
127
+ const contextCount = (portStatus.clients || []).reduce((sum, client) => sum + (client.contexts || []).length, 0);
128
+ const dot = portStatus.connected && contextCount ? 'good' : portStatus.connected ? 'warn' : 'bad';
129
+ const detail = portStatus.connected
130
+ ? `${(portStatus.clients || []).length} client(s), ${contextCount} context(s)`
131
+ : portStatus.error || 'not reachable';
132
+ rows.push(`
133
+ <div class="daemon-row">
134
+ <div class="daemon-row-top">
135
+ <strong>${escapeHtml(portStatus.portName)} :${escapeHtml(portStatus.port)}</strong>
136
+ <span class="status-pill"><span class="dot ${dot}"></span>${portStatus.connected ? 'reachable' : 'offline'}</span>
137
+ </div>
138
+ <div class="daemon-detail">${escapeHtml(detail)}</div>
139
+ </div>
140
+ `);
141
+ }
142
+
143
+ const proxy = state.lastStatus.hotReloadProxy;
144
+ if (proxy) {
145
+ rows.push(`
146
+ <div class="daemon-row">
147
+ <div class="daemon-row-top">
148
+ <strong>hotreload proxy :${escapeHtml(proxy.port)}</strong>
149
+ <span class="status-pill"><span class="dot ${proxy.connected ? 'good' : 'warn'}"></span>${proxy.connected ? 'online' : 'idle'}</span>
150
+ </div>
151
+ <div class="daemon-detail">hot reload connection proxy</div>
152
+ </div>
153
+ `);
154
+ }
155
+
156
+ elements.daemonStatus.innerHTML = rows.join('');
157
+ }
158
+
159
+ function nodeMatchesSearch(node, search) {
160
+ if (!search) return true;
161
+ const id = getNodeId(node);
162
+ const attributes = valdiDebuggerTreeModel.stringifyValue(getNodeAttributes(node), 0).toLowerCase();
163
+ const viewModel = valdiDebuggerTreeModel.stringifyValue(node.viewModel || {}, 0).toLowerCase();
164
+ const component = valdiDebuggerTreeModel.stringifyValue(node.component || {}, 0).toLowerCase();
165
+ const componentState = valdiDebuggerTreeModel.stringifyValue(node.state || {}, 0).toLowerCase();
166
+ const haystack = `${node.tag} ${id} #${id} ${attributes} ${viewModel} ${component} ${componentState}`.toLowerCase();
167
+ return haystack.includes(search);
168
+ }
169
+
170
+ function collectSearchVisibleNodeIds(root, search) {
171
+ const visibleNodeIds = new Set();
172
+ const matchedLineage = new Set();
173
+ const records = [];
174
+ valdiDebuggerTreeModel.walk(
175
+ root,
176
+ (node, ancestors) => {
177
+ const parent = ancestors.at(-1);
178
+ const ancestorMatched = parent ? matchedLineage.has(parent) : false;
179
+ const selfMatched = nodeMatchesSearch(node, search);
180
+ records.push({ node, parent, selfMatched });
181
+ if (ancestorMatched || selfMatched || getNodeId(node) === state.selectedNodeId) {
182
+ visibleNodeIds.add(getNodeId(node));
183
+ }
184
+ if (ancestorMatched || selfMatched) matchedLineage.add(node);
185
+ },
186
+ [],
187
+ 0,
188
+ );
189
+ const matchedSubtrees = new Set();
190
+ for (let index = records.length - 1; index >= 0; index -= 1) {
191
+ const record = records[index];
192
+ if (!record.selfMatched && !matchedSubtrees.has(record.node)) continue;
193
+ visibleNodeIds.add(getNodeId(record.node));
194
+ if (record.parent) matchedSubtrees.add(record.parent);
195
+ }
196
+ return visibleNodeIds;
197
+ }
198
+
199
+ function parseExactNodeIdSearch(search) {
200
+ const match = search.match(/^#?(\d+)$/);
201
+ return match ? match[1] : null;
202
+ }
203
+
204
+ function renderTree() {
205
+ if (!hasSnapshotTree()) {
206
+ elements.tree.innerHTML = `<div class="empty">No hierarchy loaded. Attach to a target.</div>`;
207
+ return;
208
+ }
209
+ const search = elements.treeSearch.value.trim().toLowerCase();
210
+ const exactSearchNodeId = search ? parseExactNodeIdSearch(search) : null;
211
+ const exactSearchRoot = exactSearchNodeId ? findNodeInTree(state.snapshot.tree, exactSearchNodeId) : null;
212
+ const searchVisibleNodeIds =
213
+ search && !exactSearchRoot ? collectSearchVisibleNodeIds(state.snapshot.tree, search) : null;
214
+ const rows = [];
215
+ const traversal = exactSearchRoot ? walk : search ? walk : walkVisible;
216
+ const traversalRoot = exactSearchRoot || state.snapshot.tree;
217
+ traversal(traversalRoot, (node, parent, depth) => {
218
+ const id = getNodeId(node);
219
+ const isSelected = id === state.selectedNodeId;
220
+ const selected = isSelected ? ' selected' : '';
221
+ const hidden = searchVisibleNodeIds && !searchVisibleNodeIds.has(id) ? ' filtered-out' : '';
222
+ const kind = getNodeKind(node);
223
+ const hasChildren = valdiDebuggerTreeModel.hasChildren(node);
224
+ const expanded = search || exactSearchRoot ? hasChildren : state.expandedNodeIds.has(id);
225
+ const toggleClass = hasChildren ? '' : ' empty';
226
+ const toggleLabel = hasChildren ? (expanded ? '-' : '+') : '';
227
+ const ariaExpanded = hasChildren ? `aria-expanded="${expanded}"` : '';
228
+ rows.push(`
229
+ <div class="tree-node${selected}${hidden}" data-node-id="${escapeHtml(id)}" role="button" tabindex="0" style="padding-left: ${7 + depth * 14}px">
230
+ <button class="tree-toggle${toggleClass}" data-toggle-node-id="${escapeHtml(id)}" ${ariaExpanded} tabindex="-1" title="${hasChildren ? (expanded ? 'Collapse' : 'Expand') : ''}">${toggleLabel}</button>
231
+ <span class="node-kind ${kind}"></span>
232
+ <span class="node-label">${escapeHtml(node.tag)}</span>
233
+ <span class="node-id">#${escapeHtml(id)}</span>
234
+ </div>
235
+ `);
236
+ });
237
+ elements.tree.innerHTML = rows.join('');
238
+ }
239
+
240
+ function clipBoundsToViewport(bounds, viewport) {
241
+ const left = Math.max(bounds.x, viewport.x);
242
+ const top = Math.max(bounds.y, viewport.y);
243
+ const right = Math.min(bounds.x + bounds.width, viewport.x + viewport.width);
244
+ const bottom = Math.min(bounds.y + bounds.height, viewport.y + viewport.height);
245
+ if (right <= left || bottom <= top) return null;
246
+ return {
247
+ x: left,
248
+ y: top,
249
+ width: right - left,
250
+ height: bottom - top,
251
+ };
252
+ }
253
+
254
+ function shouldRenderOverlayNode(node) {
255
+ const id = getNodeId(node);
256
+ if (state.overlayMode === 'issues') {
257
+ return state.snapshot.issues.some(issue => String(issue.nodeId) === id);
258
+ }
259
+ return false;
260
+ }
261
+
262
+ function collectOverlayEntries(viewport) {
263
+ const entries = [];
264
+ if (!hasSnapshotTree()) return entries;
265
+ walk(state.snapshot.tree, (node, _parent, depth) => {
266
+ if (!shouldRenderOverlayNode(node)) return;
267
+ const geometry = getNodeGeometry(node);
268
+ if (!geometry) return;
269
+ const bounds = clipBoundsToViewport(geometry.absolute, viewport);
270
+ if (!bounds) return;
271
+ entries.push({ node, depth, bounds });
272
+ });
273
+
274
+ return entries;
275
+ }
276
+
277
+ function renderOverlay() {
278
+ elements.screen.querySelectorAll('.overlay-node').forEach(node => node.remove());
279
+ const viewport = getViewportBounds();
280
+ elements.device.style.setProperty('--device-w', viewport.width);
281
+ elements.device.style.setProperty('--device-h', viewport.height);
282
+ updateHtmlPreviewScale();
283
+ markHtmlPreviewSelection();
284
+ const screenBounds = elements.screen.getBoundingClientRect();
285
+ const scaleX = screenBounds.width / viewport.width;
286
+ const scaleY = screenBounds.height / viewport.height;
287
+ for (const entry of collectOverlayEntries(viewport)) {
288
+ const node = entry.node;
289
+ const id = getNodeId(node);
290
+ const bounds = entry.bounds;
291
+ const left = (bounds.x - viewport.x) * scaleX;
292
+ const top = (bounds.y - viewport.y) * scaleY;
293
+ const overlay = document.createElement('button');
294
+ overlay.className = `overlay-node ${getNodeKind(node)}${id === state.selectedNodeId ? ' selected' : ''}`;
295
+ overlay.dataset.nodeId = id;
296
+ overlay.style.left = `${left}px`;
297
+ overlay.style.top = `${top}px`;
298
+ overlay.style.width = `${Math.max(8, bounds.width * scaleX)}px`;
299
+ overlay.style.height = `${Math.max(8, bounds.height * scaleY)}px`;
300
+ const label = overlayNodeLabel(node);
301
+ const detail = overlayNodeDetail(node);
302
+ overlay.title = describeOverlayNode(node);
303
+ overlay.innerHTML = detail
304
+ ? `<span class="label"><span class="label-line">${escapeHtml(label)}</span><span class="label-line label-detail">${escapeHtml(detail)}</span></span>`
305
+ : `<span class="label"><span class="label-line">${escapeHtml(label)}</span></span>`;
306
+ elements.screen.appendChild(overlay);
307
+ }
308
+ }
309
+
310
+ function selectedNode() {
311
+ if (!hasSnapshotTree()) return null;
312
+ return findNode(state.selectedNodeId) || state.snapshot.tree;
313
+ }
314
+
315
+ function getComponentDebugData(node) {
316
+ return node.component && typeof node.component === 'object' ? node.component : {};
317
+ }
318
+
319
+ function isComponentDebugDataOmitted(node) {
320
+ return getComponentDebugData(node).debugDataOmitted === true;
321
+ }
322
+
323
+ function hasDebugPayload(value) {
324
+ return value !== undefined;
325
+ }
326
+
327
+ function getNodeViewModelPayload(node) {
328
+ const componentData = getComponentDebugData(node);
329
+ if (componentData.viewModel !== undefined) return componentData.viewModel;
330
+ if (node.viewModel !== undefined) return node.viewModel;
331
+ return undefined;
332
+ }
333
+
334
+ function getNodeStatePayload(node) {
335
+ const componentData = getComponentDebugData(node);
336
+ if (componentData.state !== undefined) return componentData.state;
337
+ if (node.state !== undefined) return node.state;
338
+ return undefined;
339
+ }
340
+
341
+ function payloadToDisplayString(payload) {
342
+ return valdiDebuggerTreeModel.formatValue(payload, 2);
343
+ }
344
+
345
+ function renderPayload(payload) {
346
+ return `<pre class="codebox">${escapeHtml(payloadToDisplayString(payload))}</pre>`;
347
+ }
348
+
349
+ function renderDataSection(title, body) {
350
+ return `
351
+ <section class="data-section">
352
+ <h3 class="data-heading">${escapeHtml(title)}</h3>
353
+ ${body}
354
+ </section>
355
+ `;
356
+ }
357
+
358
+ function renderAttributesTable(attributes) {
359
+ const rows = Object.entries(attributes)
360
+ .map(
361
+ ([key, value]) =>
362
+ `<div>${escapeHtml(key)}</div><div>${escapeHtml(valdiDebuggerTreeModel.formatValue(value, 0))}</div>`,
363
+ )
364
+ .join('');
365
+ return rows ? `<div class="kv">${rows}</div>` : '';
366
+ }
367
+
368
+ function serializeRawInspectorNode(node, geometry, target) {
369
+ const projectedGeometry = valdiDebuggerTreeModel.projectValue(geometry);
370
+ const projectedNode = valdiDebuggerTreeModel.projectTree(node);
371
+ const projectedTarget = valdiDebuggerTreeModel.projectValue(target);
372
+ return JSON.stringify(
373
+ {
374
+ geometry: projectedGeometry.value,
375
+ node: projectedNode,
376
+ projectionComplete: projectedGeometry.complete && projectedNode.complete && projectedTarget.complete,
377
+ target: projectedTarget.value,
378
+ },
379
+ null,
380
+ 2,
381
+ );
382
+ }
383
+
384
+ async function captureRootSnapshot(params, options = {}) {
385
+ if (!hasSnapshotTree()) {
386
+ state.rootSnapshotImage = null;
387
+ renderPreview();
388
+ return;
389
+ }
390
+ const rootElement = firstElementWithFrame(state.snapshot.tree);
391
+ if (state.source !== 'daemon' || !rootElement?.element) {
392
+ state.rootSnapshotImage = null;
393
+ renderPreview();
394
+ return;
395
+ }
396
+
397
+ const requestId = ++state.rootSnapshotRequestId;
398
+ try {
399
+ const result = await apiGet(
400
+ '/api/element-snapshot',
401
+ {
402
+ ...params,
403
+ elementId: rootElement.element.id,
404
+ },
405
+ { timeoutMs: 20000 },
406
+ );
407
+ if (requestId !== state.rootSnapshotRequestId || state.source !== 'daemon') return;
408
+ state.rootSnapshotImage = result.image || null;
409
+ renderPreview();
410
+ } catch (error) {
411
+ if (requestId !== state.rootSnapshotRequestId) return;
412
+ state.rootSnapshotImage = null;
413
+ renderPreview();
414
+ if (!options.silent) addLog('warn', 'inspector', `Could not capture live root snapshot: ${error.message}`);
415
+ }
416
+ }
417
+
418
+ function renderInspector() {
419
+ const node = selectedNode();
420
+ if (!node) {
421
+ elements.selectedSummary.textContent = 'No node selected';
422
+ elements.inspector.innerHTML = `<div class="empty">No node is selected because no snapshot is loaded.</div>`;
423
+ return;
424
+ }
425
+ const id = getNodeId(node);
426
+ const kind = getNodeKind(node);
427
+ const path = getPathToNode(id);
428
+ const geometry = getNodeGeometry(node);
429
+ const scrollOffset = getScrollOffset(node);
430
+ const viewModelPayload = getNodeViewModelPayload(node);
431
+ const statePayload = getNodeStatePayload(node);
432
+ elements.selectedSummary.textContent = `${node.tag} #${id} - ${kind}`;
433
+
434
+ const tab = state.activeTab;
435
+ if (tab === 'overview') {
436
+ elements.inspector.innerHTML = `
437
+ ${renderBreadcrumb(path)}
438
+ <div class="kv">
439
+ <div>Tag</div><div>${escapeHtml(node.tag)}</div>
440
+ <div>Kind</div><div>${escapeHtml(kind)}</div>
441
+ <div>Node id</div><div>${escapeHtml(id)}</div>
442
+ <div>Key</div><div>${escapeHtml(node.key || 'n/a')}</div>
443
+ <div>Children</div><div>${valdiDebuggerTreeModel.children(node).length}</div>
444
+ <div>Local bounds</div><div>${renderBounds(geometry?.local || node.bounds)}</div>
445
+ <div>Absolute bounds</div><div>${renderBounds(geometry?.absolute)}</div>
446
+ ${hasScrollState(node) ? `<div>Host scroll offset</div><div>x ${scrollOffset.x}, y ${scrollOffset.y}</div>` : ''}
447
+ <div>Platform class</div><div>${escapeHtml(resolvePlatformClass(node))}</div>
448
+ <div>Props</div><div>${hasDebugPayload(viewModelPayload) || Object.keys(getNodeAttributes(node)).length ? 'available' : isComponentDebugDataOmitted(node) ? 'omitted by snapshot budget' : 'not exported'}</div>
449
+ <div>State</div><div>${hasDebugPayload(statePayload) ? 'available' : isComponentDebugDataOmitted(node) ? 'omitted by snapshot budget' : 'not present'}</div>
450
+ <div>Last updated</div><div>${escapeHtml(state.lastUpdated || 'n/a')}</div>
451
+ </div>
452
+ ${state.selectedSnapshotImage ? `<div class="snapshot-preview" data-selected-snapshot></div>` : ''}
453
+ `;
454
+ if (state.selectedSnapshotImage) {
455
+ const snapshotContainer = elements.inspector.querySelector('[data-selected-snapshot]');
456
+ if (snapshotContainer) {
457
+ const snapshotImage = document.createElement('img');
458
+ snapshotImage.alt = 'Selected element snapshot';
459
+ snapshotImage.src = state.selectedSnapshotImage;
460
+ snapshotContainer.appendChild(snapshotImage);
461
+ }
462
+ }
463
+ return;
464
+ }
465
+
466
+ if (tab === 'props') {
467
+ const attributes = getNodeAttributes(node);
468
+ const sections = [];
469
+ if (hasDebugPayload(viewModelPayload)) {
470
+ sections.push(renderDataSection('ViewModel', renderPayload(viewModelPayload)));
471
+ }
472
+ const attributesTable = renderAttributesTable(attributes);
473
+ if (attributesTable) {
474
+ sections.push(renderDataSection('Element Attributes', attributesTable));
475
+ }
476
+ elements.inspector.innerHTML = sections.length
477
+ ? `${sections.join('')}${isComponentDebugDataOmitted(node) ? '<div class="empty">Some component debug data was omitted by the snapshot budget.</div>' : ''}`
478
+ : `<div class="empty">This node has no exported ViewModel or element attributes.</div>`;
479
+ return;
480
+ }
481
+
482
+ if (tab === 'state') {
483
+ elements.inspector.innerHTML = hasDebugPayload(statePayload)
484
+ ? renderDataSection('Component State', renderPayload(statePayload))
485
+ : isComponentDebugDataOmitted(node)
486
+ ? `<div class="empty">Component state was omitted by the snapshot budget.</div>`
487
+ : `<div class="empty">No component state is exported for this node. State appears for StatefulComponent instances after the runtime exports a non-undefined state value.</div>`;
488
+ return;
489
+ }
490
+
491
+ if (tab === 'raw') {
492
+ const payload = serializeRawInspectorNode(node, geometry, state.snapshot.target);
493
+ elements.inspector.innerHTML = `<pre class="codebox">${escapeHtml(payload)}</pre>`;
494
+ return;
495
+ }
496
+
497
+ const related = state.snapshot.issues.filter(issue => String(issue.nodeId) === id || issue.nodeId === undefined);
498
+ elements.inspector.innerHTML = related.length
499
+ ? `<div class="issue-list">${related.map(renderIssue).join('')}</div>`
500
+ : `<div class="empty">No runtime issues are attached to this node.</div>`;
501
+ }
502
+
503
+ function renderBreadcrumb(path) {
504
+ return `<div class="breadcrumb">${path
505
+ .map(node => `<span class="crumb">${escapeHtml(node.tag)} #${escapeHtml(getNodeId(node))}</span>`)
506
+ .join('')}</div>`;
507
+ }
508
+
509
+ function renderBounds(bounds) {
510
+ if (!bounds) return 'not reported';
511
+ return `x ${bounds.x}, y ${bounds.y}, ${bounds.width} x ${bounds.height}`;
512
+ }
513
+
514
+ function resolvePlatformClass(node) {
515
+ const attrs = getNodeAttributes(node);
516
+ if ((state.snapshot.target?.platform === 'macOS' || isMacDesktopTarget()) && !attrs.macosClass && attrs.iosClass) {
517
+ return `${attrs.iosClass} (macOS fallback from iosClass)`;
518
+ }
519
+ return attrs.macosClass || attrs.iosClass || attrs.androidClass || attrs.webClass || 'n/a';
520
+ }
521
+
522
+ function renderIssue(issue) {
523
+ return `
524
+ <div class="issue ${issue.severity === 'error' ? 'error' : 'warn'}" data-issue-node="${escapeHtml(issue.nodeId || '')}" role="button" tabindex="0">
525
+ <div class="issue-title">${escapeHtml(issue.title)} <span class="node-id">${escapeHtml(issue.time || '')}</span></div>
526
+ <div class="issue-message">${escapeHtml(issue.message)}</div>
527
+ </div>
528
+ `;
529
+ }