@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,676 @@
|
|
|
1
|
+
// Live HTML projection for the debugger preview frame.
|
|
2
|
+
const HTML_PREVIEW_TEXT_INPUT_DEBOUNCE_MS = 180;
|
|
3
|
+
const HTML_PREVIEW_SCROLL_INPUT_DEBOUNCE_MS = 60;
|
|
4
|
+
const htmlPreviewTextInputs = new Map();
|
|
5
|
+
const htmlPreviewScrollInputs = new Map();
|
|
6
|
+
const htmlPreviewInputDispatches = new Map();
|
|
7
|
+
const htmlPreviewQueuedInputs = new Set();
|
|
8
|
+
const htmlPreviewElementTargets = new WeakMap();
|
|
9
|
+
const htmlPreviewElementIncarnations = new WeakMap();
|
|
10
|
+
const htmlPreviewElementEditEpochs = new WeakMap();
|
|
11
|
+
const htmlPreviewElementFocusEpochs = new WeakMap();
|
|
12
|
+
let htmlPreviewIncarnation = 0;
|
|
13
|
+
|
|
14
|
+
function getHtmlPreviewElementEpoch(epochs, element) {
|
|
15
|
+
return epochs.get(element) || 0;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function advanceHtmlPreviewElementEpoch(epochs, element) {
|
|
19
|
+
const epoch = getHtmlPreviewElementEpoch(epochs, element) + 1;
|
|
20
|
+
epochs.set(element, epoch);
|
|
21
|
+
return epoch;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function isCurrentHtmlPreviewElement(element, incarnation) {
|
|
25
|
+
return incarnation === htmlPreviewIncarnation && htmlPreviewElementIncarnations.get(element) === incarnation;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function associateHtmlPreviewElement(element, target) {
|
|
29
|
+
if (target) htmlPreviewElementTargets.set(element, target);
|
|
30
|
+
htmlPreviewElementIncarnations.set(element, htmlPreviewIncarnation);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function cancelPendingHtmlPreviewInputs(pendingInputs) {
|
|
34
|
+
for (const pendingInput of pendingInputs.values()) {
|
|
35
|
+
window.clearTimeout(pendingInput.timer);
|
|
36
|
+
void pendingInput.reservation.cancel();
|
|
37
|
+
}
|
|
38
|
+
pendingInputs.clear();
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function trackQueuedHtmlPreviewInput(incarnation, reservation, dispatch) {
|
|
42
|
+
const queuedInput = { incarnation, reservation };
|
|
43
|
+
htmlPreviewQueuedInputs.add(queuedInput);
|
|
44
|
+
const clearQueuedInput = () => htmlPreviewQueuedInputs.delete(queuedInput);
|
|
45
|
+
void dispatch.then(clearQueuedInput, clearQueuedInput);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function cancelQueuedHtmlPreviewInputs() {
|
|
49
|
+
for (const queuedInput of htmlPreviewQueuedInputs) {
|
|
50
|
+
void queuedInput.reservation.cancel();
|
|
51
|
+
}
|
|
52
|
+
htmlPreviewQueuedInputs.clear();
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function beginHtmlPreviewIncarnation() {
|
|
56
|
+
htmlPreviewIncarnation += 1;
|
|
57
|
+
cancelPendingHtmlPreviewInputs(htmlPreviewTextInputs);
|
|
58
|
+
cancelPendingHtmlPreviewInputs(htmlPreviewScrollInputs);
|
|
59
|
+
cancelQueuedHtmlPreviewInputs();
|
|
60
|
+
htmlPreviewInputDispatches.clear();
|
|
61
|
+
return htmlPreviewIncarnation;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function previewClassName(value) {
|
|
65
|
+
return valdiDebuggerTreeModel
|
|
66
|
+
.formatValue(value || 'unknown', 0)
|
|
67
|
+
.replace(/[^a-z0-9_-]+/gi, '-')
|
|
68
|
+
.toLowerCase();
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function previewValue(value) {
|
|
72
|
+
if (value === undefined || value === null) return '';
|
|
73
|
+
if (typeof value === 'object') {
|
|
74
|
+
const pathDescriptor = Object.getOwnPropertyDescriptor(value, 'path');
|
|
75
|
+
if (pathDescriptor && Object.prototype.hasOwnProperty.call(pathDescriptor, 'value')) {
|
|
76
|
+
return valdiDebuggerTreeModel.formatValue(pathDescriptor.value, 0).replace(/^"|"$/g, '');
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return valdiDebuggerTreeModel.formatValue(value, 0).replace(/^"|"$/g, '');
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function previewBoolean(value, fallback = false) {
|
|
83
|
+
if (value === undefined || value === null || value === '') return fallback;
|
|
84
|
+
if (typeof value === 'boolean') return value;
|
|
85
|
+
const normalized = valdiDebuggerTreeModel.formatValue(value, 0).toLowerCase();
|
|
86
|
+
if (['1', 'true', 'yes', 'on'].includes(normalized)) return true;
|
|
87
|
+
if (['0', 'false', 'no', 'off'].includes(normalized)) return false;
|
|
88
|
+
return fallback;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function previewNumber(value, fallback = 0) {
|
|
92
|
+
if (value === undefined || value === null || value === '') return fallback;
|
|
93
|
+
const parsed = Number.parseFloat(valdiDebuggerTreeModel.formatValue(value, 0).replace(/^"|"$/g, ''));
|
|
94
|
+
return Number.isFinite(parsed) ? parsed : fallback;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function previewCssLength(value) {
|
|
98
|
+
if (value === undefined || value === null || value === '') return '';
|
|
99
|
+
if (typeof value === 'number') return `${value}px`;
|
|
100
|
+
const normalized = valdiDebuggerTreeModel.formatValue(value, 0).replace(/^"|"$/g, '').trim();
|
|
101
|
+
if (!normalized) return '';
|
|
102
|
+
if (/^-?\d+(\.\d+)?$/.test(normalized)) return `${normalized}px`;
|
|
103
|
+
return normalized;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function previewColor(value) {
|
|
107
|
+
const normalized = previewValue(value).trim();
|
|
108
|
+
return normalized || '';
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function previewText(node, attrs) {
|
|
112
|
+
for (const source of [attrs, node.viewModel, node]) {
|
|
113
|
+
if (!source || typeof source !== 'object') continue;
|
|
114
|
+
for (const key of ['value', 'title', 'text', 'placeholder', 'accessibilityLabel', 'label', 'name']) {
|
|
115
|
+
const value = previewValue(source[key]);
|
|
116
|
+
if (value) return value;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
return '';
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function previewImageSource(attrs) {
|
|
123
|
+
const source = attrs.src || attrs.source || attrs.url;
|
|
124
|
+
if (!source) return '';
|
|
125
|
+
if (typeof source === 'string') return previewValue(source);
|
|
126
|
+
if (typeof source === 'object') {
|
|
127
|
+
return previewValue(source.src || source.url || source.path || source.default || '');
|
|
128
|
+
}
|
|
129
|
+
return previewValue(source);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
function previewSafeMediaSource(source) {
|
|
133
|
+
const normalized = valdiDebuggerTreeModel.formatValue(source || '', 0).trim();
|
|
134
|
+
return /^(data|blob):/i.test(normalized) ? normalized : '';
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
function setStyleIfPresent(style, property, value) {
|
|
138
|
+
if (value === '') return;
|
|
139
|
+
style[property] = value;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function applyPreviewFrame(element, node) {
|
|
143
|
+
const frame = node.element?.frame
|
|
144
|
+
? normalizeBounds(node.element.frame)
|
|
145
|
+
: node.bounds
|
|
146
|
+
? normalizeBounds(node.bounds)
|
|
147
|
+
: null;
|
|
148
|
+
element.style.position = 'absolute';
|
|
149
|
+
if (!frame) {
|
|
150
|
+
element.style.left = '0';
|
|
151
|
+
element.style.top = '0';
|
|
152
|
+
element.style.width = '100%';
|
|
153
|
+
element.style.height = '100%';
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
element.style.left = `${frame.x}px`;
|
|
157
|
+
element.style.top = `${frame.y}px`;
|
|
158
|
+
element.style.width = `${frame.width}px`;
|
|
159
|
+
element.style.height = `${frame.height}px`;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
function applyPreviewBoxStyles(element, node) {
|
|
163
|
+
const attrs = getNodeAttributes(node);
|
|
164
|
+
setStyleIfPresent(element.style, 'backgroundColor', previewColor(attrs.backgroundColor || attrs.background));
|
|
165
|
+
setStyleIfPresent(element.style, 'color', previewColor(attrs.color || attrs.textColor));
|
|
166
|
+
setStyleIfPresent(element.style, 'opacity', previewValue(attrs.opacity));
|
|
167
|
+
setStyleIfPresent(element.style, 'borderRadius', previewCssLength(attrs.cornerRadius || attrs.borderRadius));
|
|
168
|
+
setStyleIfPresent(element.style, 'borderColor', previewColor(attrs.borderColor));
|
|
169
|
+
setStyleIfPresent(element.style, 'borderWidth', previewCssLength(attrs.borderWidth));
|
|
170
|
+
if (attrs.borderWidth !== undefined || attrs.borderColor !== undefined) {
|
|
171
|
+
element.style.borderStyle = previewValue(attrs.borderStyle) || 'solid';
|
|
172
|
+
}
|
|
173
|
+
setStyleIfPresent(element.style, 'padding', previewCssLength(attrs.padding));
|
|
174
|
+
setStyleIfPresent(element.style, 'paddingLeft', previewCssLength(attrs.paddingLeft));
|
|
175
|
+
setStyleIfPresent(element.style, 'paddingRight', previewCssLength(attrs.paddingRight));
|
|
176
|
+
setStyleIfPresent(element.style, 'paddingTop', previewCssLength(attrs.paddingTop));
|
|
177
|
+
setStyleIfPresent(element.style, 'paddingBottom', previewCssLength(attrs.paddingBottom));
|
|
178
|
+
const transform = [];
|
|
179
|
+
const translationX = previewNumber(attrs.translationX, 0);
|
|
180
|
+
const translationY = previewNumber(attrs.translationY, 0);
|
|
181
|
+
if (translationX || translationY) transform.push(`translate(${translationX}px, ${translationY}px)`);
|
|
182
|
+
if (attrs.scale !== undefined || attrs.scaleX !== undefined || attrs.scaleY !== undefined) {
|
|
183
|
+
const scale = previewNumber(attrs.scale, 1);
|
|
184
|
+
transform.push(`scale(${previewNumber(attrs.scaleX, scale)}, ${previewNumber(attrs.scaleY, scale)})`);
|
|
185
|
+
}
|
|
186
|
+
if (attrs.rotation !== undefined) transform.push(`rotate(${previewNumber(attrs.rotation, 0)}rad)`);
|
|
187
|
+
if (transform.length) element.style.transform = transform.join(' ');
|
|
188
|
+
if (attrs.hidden !== undefined && previewBoolean(attrs.hidden)) element.style.visibility = 'hidden';
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
function applyPreviewTextStyles(element, attrs) {
|
|
192
|
+
setStyleIfPresent(element.style, 'fontSize', previewCssLength(attrs.fontSize));
|
|
193
|
+
setStyleIfPresent(element.style, 'fontWeight', previewValue(attrs.fontWeight));
|
|
194
|
+
setStyleIfPresent(element.style, 'textAlign', previewValue(attrs.textAlign));
|
|
195
|
+
setStyleIfPresent(element.style, 'lineHeight', previewCssLength(attrs.lineHeight));
|
|
196
|
+
setStyleIfPresent(element.style, 'letterSpacing', previewCssLength(attrs.letterSpacing));
|
|
197
|
+
const font = previewValue(attrs.font);
|
|
198
|
+
const fontSize = font.match(/\b(\d+(?:\.\d+)?)\b/);
|
|
199
|
+
if (fontSize && !element.style.fontSize) element.style.fontSize = `${fontSize[1]}px`;
|
|
200
|
+
if (/bold|semibold|demibold|medium/i.test(font)) element.style.fontWeight = '700';
|
|
201
|
+
if (/mono/i.test(font)) {
|
|
202
|
+
element.style.fontFamily = 'ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace';
|
|
203
|
+
}
|
|
204
|
+
if (attrs.textDecoration !== undefined) {
|
|
205
|
+
const decoration = previewValue(attrs.textDecoration);
|
|
206
|
+
element.style.textDecoration = decoration.includes('underline') ? 'underline' : decoration;
|
|
207
|
+
}
|
|
208
|
+
const lineCount = previewNumber(attrs.numberOfLines, 0);
|
|
209
|
+
if (lineCount > 0) {
|
|
210
|
+
element.style.display = '-webkit-box';
|
|
211
|
+
element.style.webkitLineClamp = String(lineCount);
|
|
212
|
+
element.style.webkitBoxOrient = 'vertical';
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
function createPreviewElement(node, effectivelyDisabled) {
|
|
217
|
+
const tag = valdiDebuggerTreeModel.formatValue(node.tag || 'view', 0).toLowerCase();
|
|
218
|
+
const attrs = getNodeAttributes(node);
|
|
219
|
+
if (tag === 'textfield') {
|
|
220
|
+
const input = document.createElement('input');
|
|
221
|
+
input.type = previewBoolean(attrs.secureTextEntry) ? 'password' : 'text';
|
|
222
|
+
input.value = previewValue(attrs.value);
|
|
223
|
+
input.placeholder = previewValue(attrs.placeholder);
|
|
224
|
+
input.disabled = effectivelyDisabled;
|
|
225
|
+
input.readOnly = previewBoolean(attrs.editable, true) === false;
|
|
226
|
+
return input;
|
|
227
|
+
}
|
|
228
|
+
if (tag === 'textview' && previewBoolean(attrs.editable, true)) {
|
|
229
|
+
const textArea = document.createElement('textarea');
|
|
230
|
+
textArea.value = previewValue(attrs.value);
|
|
231
|
+
textArea.placeholder = previewValue(attrs.placeholder);
|
|
232
|
+
textArea.disabled = effectivelyDisabled;
|
|
233
|
+
textArea.readOnly = previewBoolean(attrs.editable, true) === false;
|
|
234
|
+
return textArea;
|
|
235
|
+
}
|
|
236
|
+
if (tag === 'image' || tag === 'animatedimage') {
|
|
237
|
+
const image = document.createElement('img');
|
|
238
|
+
image.alt = previewValue(attrs.accessibilityLabel || attrs.alt || '');
|
|
239
|
+
const source = previewImageSource(attrs);
|
|
240
|
+
const safeSource = previewSafeMediaSource(source);
|
|
241
|
+
if (safeSource) image.src = safeSource;
|
|
242
|
+
else if (source) image.dataset.previewResourceOmitted = 'true';
|
|
243
|
+
image.draggable = false;
|
|
244
|
+
return image;
|
|
245
|
+
}
|
|
246
|
+
if (tag === 'video') {
|
|
247
|
+
const video = document.createElement('video');
|
|
248
|
+
const source = previewImageSource(attrs);
|
|
249
|
+
const safeSource = previewSafeMediaSource(source);
|
|
250
|
+
if (safeSource) video.src = safeSource;
|
|
251
|
+
else if (source) video.dataset.previewResourceOmitted = 'true';
|
|
252
|
+
video.muted = true;
|
|
253
|
+
video.playsInline = true;
|
|
254
|
+
return video;
|
|
255
|
+
}
|
|
256
|
+
if (tag === 'webview') {
|
|
257
|
+
const placeholder = document.createElement('div');
|
|
258
|
+
placeholder.dataset.previewResourceOmitted = 'true';
|
|
259
|
+
placeholder.textContent = 'WebView content omitted';
|
|
260
|
+
return placeholder;
|
|
261
|
+
}
|
|
262
|
+
if (tag === 'button') {
|
|
263
|
+
const button = document.createElement('button');
|
|
264
|
+
button.textContent = previewText(node, attrs);
|
|
265
|
+
button.disabled = effectivelyDisabled;
|
|
266
|
+
return button;
|
|
267
|
+
}
|
|
268
|
+
return document.createElement('div');
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
function finishPreviewElement(element, node, target, effectivelyDisabled) {
|
|
272
|
+
const attrs = getNodeAttributes(node);
|
|
273
|
+
const tag = valdiDebuggerTreeModel.formatValue(node.tag || 'view', 0).toLowerCase();
|
|
274
|
+
const nodeId = getNodeId(node);
|
|
275
|
+
const elementId = getElementIdForNode(node);
|
|
276
|
+
element.classList.add('valdi-html-node', `valdi-html-${previewClassName(tag)}`);
|
|
277
|
+
if (isInteractiveNode(node) || ['button', 'textfield', 'textview'].includes(tag)) {
|
|
278
|
+
element.classList.add('preview-interactive');
|
|
279
|
+
}
|
|
280
|
+
element.dataset.previewNodeId = nodeId;
|
|
281
|
+
if (elementId !== null) element.dataset.previewElementId = valdiDebuggerTreeModel.formatValue(elementId, 0);
|
|
282
|
+
associateHtmlPreviewElement(element, target);
|
|
283
|
+
if (effectivelyDisabled) {
|
|
284
|
+
element.classList.add('preview-disabled');
|
|
285
|
+
element.setAttribute('aria-disabled', 'true');
|
|
286
|
+
}
|
|
287
|
+
element.title = describeOverlayNode(node);
|
|
288
|
+
applyPreviewFrame(element, node);
|
|
289
|
+
applyPreviewBoxStyles(element, node);
|
|
290
|
+
|
|
291
|
+
if (tag === 'label' || (tag === 'textview' && element.tagName !== 'TEXTAREA')) {
|
|
292
|
+
element.classList.add('valdi-html-text');
|
|
293
|
+
element.textContent = previewText(node, attrs);
|
|
294
|
+
applyPreviewTextStyles(element, attrs);
|
|
295
|
+
element.style.userSelect = previewBoolean(attrs.selectable, false) ? 'text' : 'none';
|
|
296
|
+
} else if (element.tagName === 'INPUT' || element.tagName === 'TEXTAREA' || element.tagName === 'BUTTON') {
|
|
297
|
+
applyPreviewTextStyles(element, attrs);
|
|
298
|
+
} else if (element.tagName === 'IMG' || element.tagName === 'VIDEO') {
|
|
299
|
+
element.style.objectFit = previewValue(attrs.objectFit) || 'cover';
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
if (tag === 'scroll') {
|
|
303
|
+
element.classList.add('valdi-html-scroll');
|
|
304
|
+
element.scrollLeft = previewNumber(attrs.contentOffsetX, 0);
|
|
305
|
+
element.scrollTop = previewNumber(attrs.contentOffsetY, 0);
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
function isHtmlPreviewEffectivelyDisabled(node, ancestorDisabled) {
|
|
310
|
+
const attrs = getNodeAttributes(node);
|
|
311
|
+
return (
|
|
312
|
+
ancestorDisabled ||
|
|
313
|
+
previewBoolean(attrs.enabled, true) === false ||
|
|
314
|
+
previewBoolean(attrs.accessibilityStateDisabled, false) ||
|
|
315
|
+
previewBoolean(attrs.touchEnabled, true) === false
|
|
316
|
+
);
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
function appendPreviewNode(node, parent, target, ancestorDisabled) {
|
|
320
|
+
if (!node) return;
|
|
321
|
+
const childParents = new Map();
|
|
322
|
+
const disabledStates = new Map();
|
|
323
|
+
valdiDebuggerTreeModel.walk(
|
|
324
|
+
node,
|
|
325
|
+
(current, ancestors) => {
|
|
326
|
+
const directParent = ancestors.at(-1);
|
|
327
|
+
const currentParent = directParent ? childParents.get(directParent) || parent : parent;
|
|
328
|
+
const parentDisabled = directParent ? disabledStates.get(directParent) || false : ancestorDisabled;
|
|
329
|
+
if (!current.element) {
|
|
330
|
+
childParents.set(current, currentParent);
|
|
331
|
+
disabledStates.set(current, parentDisabled);
|
|
332
|
+
return;
|
|
333
|
+
}
|
|
334
|
+
const effectivelyDisabled = isHtmlPreviewEffectivelyDisabled(current, parentDisabled);
|
|
335
|
+
const element = createPreviewElement(current, effectivelyDisabled);
|
|
336
|
+
finishPreviewElement(element, current, target, effectivelyDisabled);
|
|
337
|
+
currentParent.appendChild(element);
|
|
338
|
+
childParents.set(current, canHostPreviewChildren(element) ? element : currentParent);
|
|
339
|
+
disabledStates.set(current, effectivelyDisabled);
|
|
340
|
+
},
|
|
341
|
+
[],
|
|
342
|
+
0,
|
|
343
|
+
);
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
function canHostPreviewChildren(element) {
|
|
347
|
+
return !['INPUT', 'IMG', 'TEXTAREA', 'VIDEO'].includes(element.tagName);
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
function updateHtmlPreviewScale() {
|
|
351
|
+
const canvas = elements.htmlPreviewRoot.querySelector('.html-preview-canvas');
|
|
352
|
+
if (!canvas) return;
|
|
353
|
+
const viewport = getViewportBounds();
|
|
354
|
+
const screenBounds = elements.screen.getBoundingClientRect();
|
|
355
|
+
const scaleX = screenBounds.width / Math.max(1, viewport.width);
|
|
356
|
+
const scaleY = screenBounds.height / Math.max(1, viewport.height);
|
|
357
|
+
canvas.style.transform = `scale(${scaleX}, ${scaleY})`;
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
function markHtmlPreviewSelection() {
|
|
361
|
+
elements.htmlPreviewRoot.querySelectorAll('.preview-selected').forEach(element => {
|
|
362
|
+
element.classList.remove('preview-selected');
|
|
363
|
+
});
|
|
364
|
+
if (!state.selectedNodeId) return;
|
|
365
|
+
const selected = Array.from(elements.htmlPreviewRoot.querySelectorAll('[data-preview-node-id]')).find(
|
|
366
|
+
element => element.dataset.previewNodeId === String(state.selectedNodeId),
|
|
367
|
+
);
|
|
368
|
+
selected?.classList.add('preview-selected');
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
function renderHtmlPreview() {
|
|
372
|
+
beginHtmlPreviewIncarnation();
|
|
373
|
+
elements.htmlPreviewRoot.replaceChildren();
|
|
374
|
+
elements.htmlPreviewRoot.classList.toggle('active', false);
|
|
375
|
+
if (!hasSnapshotTree()) return false;
|
|
376
|
+
|
|
377
|
+
const viewport = getViewportBounds();
|
|
378
|
+
elements.device.style.setProperty('--device-w', viewport.width);
|
|
379
|
+
elements.device.style.setProperty('--device-h', viewport.height);
|
|
380
|
+
|
|
381
|
+
const canvas = document.createElement('div');
|
|
382
|
+
canvas.className = 'html-preview-canvas';
|
|
383
|
+
canvas.style.width = `${viewport.width}px`;
|
|
384
|
+
canvas.style.height = `${viewport.height}px`;
|
|
385
|
+
appendPreviewNode(state.snapshot.tree, canvas, captureDebuggerInputTarget(), false);
|
|
386
|
+
if (!canvas.querySelector('[data-preview-node-id]')) return false;
|
|
387
|
+
|
|
388
|
+
elements.htmlPreviewRoot.appendChild(canvas);
|
|
389
|
+
elements.htmlPreviewRoot.classList.toggle('active', true);
|
|
390
|
+
updateHtmlPreviewScale();
|
|
391
|
+
markHtmlPreviewSelection();
|
|
392
|
+
return true;
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
function previewElementNodeFromEvent(event) {
|
|
396
|
+
const element = event.target.closest('[data-preview-node-id]');
|
|
397
|
+
if (!element || !elements.htmlPreviewRoot.contains(element)) {
|
|
398
|
+
return { element: null, node: null, elementId: null, target: null };
|
|
399
|
+
}
|
|
400
|
+
const node = findNode(element.dataset.previewNodeId);
|
|
401
|
+
const parsedElementId = Number.parseInt(element.dataset.previewElementId || '', 10);
|
|
402
|
+
const incarnation = htmlPreviewElementIncarnations.get(element);
|
|
403
|
+
if (incarnation !== htmlPreviewIncarnation) {
|
|
404
|
+
return { element: null, node: null, elementId: null, target: null, incarnation: null };
|
|
405
|
+
}
|
|
406
|
+
return {
|
|
407
|
+
element,
|
|
408
|
+
node,
|
|
409
|
+
elementId: Number.isNaN(parsedElementId) ? null : parsedElementId,
|
|
410
|
+
target: htmlPreviewElementTargets.get(element) || null,
|
|
411
|
+
incarnation,
|
|
412
|
+
};
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
function isEditableHtmlPreviewTarget(target) {
|
|
416
|
+
return target instanceof HTMLInputElement || target instanceof HTMLTextAreaElement || target.isContentEditable;
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
function enqueueHtmlPreviewInput(target, elementId, payload, options) {
|
|
420
|
+
if (!target) return Promise.resolve(null);
|
|
421
|
+
const key = debuggerInputTargetElementKey(target, elementId);
|
|
422
|
+
const dispatch = enqueueDebuggerInput(target, payload, options);
|
|
423
|
+
htmlPreviewInputDispatches.set(key, dispatch);
|
|
424
|
+
const clearDispatch = () => {
|
|
425
|
+
if (htmlPreviewInputDispatches.get(key) === dispatch) {
|
|
426
|
+
htmlPreviewInputDispatches.delete(key);
|
|
427
|
+
}
|
|
428
|
+
};
|
|
429
|
+
void dispatch.then(clearDispatch, clearDispatch);
|
|
430
|
+
return dispatch;
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
function flushHtmlPreviewTextInput(target, elementId) {
|
|
434
|
+
if (!target) return Promise.resolve(null);
|
|
435
|
+
const key = debuggerInputTargetElementKey(target, elementId);
|
|
436
|
+
const pendingInput = htmlPreviewTextInputs.get(key);
|
|
437
|
+
if (!pendingInput) return Promise.resolve(null);
|
|
438
|
+
window.clearTimeout(pendingInput.timer);
|
|
439
|
+
htmlPreviewTextInputs.delete(key);
|
|
440
|
+
if (
|
|
441
|
+
pendingInput.incarnation !== htmlPreviewIncarnation ||
|
|
442
|
+
!isCurrentHtmlPreviewElement(pendingInput.element, pendingInput.incarnation)
|
|
443
|
+
) {
|
|
444
|
+
return pendingInput.reservation.cancel();
|
|
445
|
+
}
|
|
446
|
+
const dispatch = pendingInput.reservation.dispatch(pendingInput.input, {
|
|
447
|
+
quiet: true,
|
|
448
|
+
refresh: false,
|
|
449
|
+
refreshDelayMs: 180,
|
|
450
|
+
});
|
|
451
|
+
trackQueuedHtmlPreviewInput(pendingInput.incarnation, pendingInput.reservation, dispatch);
|
|
452
|
+
void dispatch.then(input => {
|
|
453
|
+
reconcileHtmlPreviewTextInputResult(
|
|
454
|
+
pendingInput.element,
|
|
455
|
+
pendingInput.input.text,
|
|
456
|
+
input,
|
|
457
|
+
pendingInput.incarnation,
|
|
458
|
+
pendingInput.editEpoch,
|
|
459
|
+
);
|
|
460
|
+
});
|
|
461
|
+
htmlPreviewInputDispatches.set(key, dispatch);
|
|
462
|
+
const clearDispatch = () => {
|
|
463
|
+
if (htmlPreviewInputDispatches.get(key) === dispatch) {
|
|
464
|
+
htmlPreviewInputDispatches.delete(key);
|
|
465
|
+
}
|
|
466
|
+
};
|
|
467
|
+
void dispatch.then(clearDispatch, clearDispatch);
|
|
468
|
+
return dispatch;
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
function dispatchHtmlPreviewFocusInput(event, focused) {
|
|
472
|
+
const { element, node, elementId, target } = previewElementNodeFromEvent(event);
|
|
473
|
+
if (!element || !node || elementId === null || !target || !isEditableHtmlPreviewTarget(event.target)) {
|
|
474
|
+
return Promise.resolve(null);
|
|
475
|
+
}
|
|
476
|
+
selectPreviewNode(node);
|
|
477
|
+
advanceHtmlPreviewElementEpoch(htmlPreviewElementFocusEpochs, element);
|
|
478
|
+
if (!focused) {
|
|
479
|
+
void flushHtmlPreviewTextInput(target, elementId);
|
|
480
|
+
}
|
|
481
|
+
return enqueueHtmlPreviewInput(
|
|
482
|
+
target,
|
|
483
|
+
elementId,
|
|
484
|
+
{
|
|
485
|
+
type: 'focus',
|
|
486
|
+
elementId,
|
|
487
|
+
focused,
|
|
488
|
+
},
|
|
489
|
+
{
|
|
490
|
+
quiet: true,
|
|
491
|
+
refresh: !focused,
|
|
492
|
+
refreshDelayMs: 120,
|
|
493
|
+
},
|
|
494
|
+
);
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
async function dispatchHtmlPreviewTapInput(event) {
|
|
498
|
+
const { element, node, elementId, target } = previewElementNodeFromEvent(event);
|
|
499
|
+
if (!element || !node) return;
|
|
500
|
+
event.stopPropagation();
|
|
501
|
+
selectPreviewNode(node);
|
|
502
|
+
if (elementId === null || !target) return;
|
|
503
|
+
|
|
504
|
+
if (isEditableHtmlPreviewTarget(event.target)) return;
|
|
505
|
+
event.preventDefault();
|
|
506
|
+
const point = pointFromScreenEvent(event);
|
|
507
|
+
await enqueueDebuggerInput(
|
|
508
|
+
target,
|
|
509
|
+
{
|
|
510
|
+
type: 'tap',
|
|
511
|
+
elementId,
|
|
512
|
+
x: point.x,
|
|
513
|
+
y: point.y,
|
|
514
|
+
},
|
|
515
|
+
{
|
|
516
|
+
refreshDelayMs: 120,
|
|
517
|
+
},
|
|
518
|
+
);
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
function dispatchHtmlPreviewScrollInput(event) {
|
|
522
|
+
if (!hasSnapshotTree() || state.source !== 'daemon') return;
|
|
523
|
+
const previewElement = event.target.closest('[data-preview-node-id]');
|
|
524
|
+
if (!previewElement || !elements.htmlPreviewRoot.contains(previewElement)) return;
|
|
525
|
+
const target = htmlPreviewElementTargets.get(previewElement) || null;
|
|
526
|
+
const incarnation = htmlPreviewElementIncarnations.get(previewElement);
|
|
527
|
+
if (!target || incarnation !== htmlPreviewIncarnation) return;
|
|
528
|
+
const point = pointFromScreenEvent(event);
|
|
529
|
+
const scrollNode =
|
|
530
|
+
findNodeAtPoint(
|
|
531
|
+
point,
|
|
532
|
+
node => String(node.tag || '').toLowerCase() === 'scroll' && getElementIdForNode(node) !== null,
|
|
533
|
+
) || findNodeAtPoint(point, node => hasScrollState(node) && getElementIdForNode(node) !== null);
|
|
534
|
+
const node = scrollNode || findNodeAtPoint(point, candidate => getElementIdForNode(candidate) !== null);
|
|
535
|
+
const elementId = getElementIdForNode(node);
|
|
536
|
+
if (elementId === null) return;
|
|
537
|
+
event.preventDefault();
|
|
538
|
+
event.stopPropagation();
|
|
539
|
+
const key = debuggerInputTargetElementKey(target, elementId);
|
|
540
|
+
const pending = htmlPreviewScrollInputs.get(key);
|
|
541
|
+
if (pending) {
|
|
542
|
+
pending.input.deltaX += event.deltaX;
|
|
543
|
+
pending.input.deltaY += event.deltaY;
|
|
544
|
+
pending.input.x = point.x;
|
|
545
|
+
pending.input.y = point.y;
|
|
546
|
+
return;
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
const input = {
|
|
550
|
+
type: 'scroll',
|
|
551
|
+
elementId,
|
|
552
|
+
x: point.x,
|
|
553
|
+
y: point.y,
|
|
554
|
+
deltaX: event.deltaX,
|
|
555
|
+
deltaY: event.deltaY,
|
|
556
|
+
};
|
|
557
|
+
const reservation = reserveDebuggerInput(target);
|
|
558
|
+
const timer = window.setTimeout(() => {
|
|
559
|
+
if (incarnation !== htmlPreviewIncarnation || htmlPreviewScrollInputs.get(key)?.reservation !== reservation) {
|
|
560
|
+
void reservation.cancel();
|
|
561
|
+
return;
|
|
562
|
+
}
|
|
563
|
+
htmlPreviewScrollInputs.delete(key);
|
|
564
|
+
const dispatch = reservation.dispatch(input, {
|
|
565
|
+
quiet: true,
|
|
566
|
+
refreshDelayMs: 120,
|
|
567
|
+
});
|
|
568
|
+
trackQueuedHtmlPreviewInput(incarnation, reservation, dispatch);
|
|
569
|
+
}, HTML_PREVIEW_SCROLL_INPUT_DEBOUNCE_MS);
|
|
570
|
+
htmlPreviewScrollInputs.set(key, { incarnation, input, target, reservation, timer });
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
function dispatchHtmlPreviewTextInput(event) {
|
|
574
|
+
const { element, node, elementId, target, incarnation } = previewElementNodeFromEvent(event);
|
|
575
|
+
if (!element || !node || elementId === null || !target) return;
|
|
576
|
+
if (!(event.target instanceof HTMLInputElement) && !(event.target instanceof HTMLTextAreaElement)) return;
|
|
577
|
+
selectPreviewNode(node);
|
|
578
|
+
const editEpoch = advanceHtmlPreviewElementEpoch(htmlPreviewElementEditEpochs, element);
|
|
579
|
+
const text = event.target.value;
|
|
580
|
+
const key = debuggerInputTargetElementKey(target, elementId);
|
|
581
|
+
const pendingInput = htmlPreviewTextInputs.get(key);
|
|
582
|
+
if (pendingInput) {
|
|
583
|
+
window.clearTimeout(pendingInput.timer);
|
|
584
|
+
}
|
|
585
|
+
const input = {
|
|
586
|
+
type: 'text',
|
|
587
|
+
elementId,
|
|
588
|
+
text,
|
|
589
|
+
selectionStart: event.target.selectionStart,
|
|
590
|
+
selectionEnd: event.target.selectionEnd,
|
|
591
|
+
};
|
|
592
|
+
const reservation = pendingInput?.reservation || reserveDebuggerInput(target);
|
|
593
|
+
const timer = window.setTimeout(() => {
|
|
594
|
+
void flushHtmlPreviewTextInput(target, elementId);
|
|
595
|
+
}, HTML_PREVIEW_TEXT_INPUT_DEBOUNCE_MS);
|
|
596
|
+
htmlPreviewTextInputs.set(key, { editEpoch, element, incarnation, input, target, timer, reservation });
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
function reconcileHtmlPreviewTextInputResult(element, expectedValue, input, incarnation, editEpoch) {
|
|
600
|
+
if (!input?.handled || typeof input.value !== 'string') return;
|
|
601
|
+
if (!isCurrentHtmlPreviewElement(element, incarnation)) return;
|
|
602
|
+
if (getHtmlPreviewElementEpoch(htmlPreviewElementEditEpochs, element) !== editEpoch) return;
|
|
603
|
+
if (element.value !== expectedValue) return;
|
|
604
|
+
if (element.value !== input.value) element.value = input.value;
|
|
605
|
+
if (!Number.isInteger(input.selectionStart) || !Number.isInteger(input.selectionEnd)) return;
|
|
606
|
+
const selectionStart = Math.max(0, Math.min(input.value.length, input.selectionStart));
|
|
607
|
+
const selectionEnd = Math.max(selectionStart, Math.min(input.value.length, input.selectionEnd));
|
|
608
|
+
if (element.selectionStart !== selectionStart || element.selectionEnd !== selectionEnd) {
|
|
609
|
+
element.setSelectionRange(selectionStart, selectionEnd);
|
|
610
|
+
}
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
function dispatchHtmlPreviewKeyInput(event) {
|
|
614
|
+
const { element, node, elementId, target, incarnation } = previewElementNodeFromEvent(event);
|
|
615
|
+
if (!element || !node || elementId === null || !target) return Promise.resolve(null);
|
|
616
|
+
if (!(event.target instanceof HTMLInputElement) && !(event.target instanceof HTMLTextAreaElement)) {
|
|
617
|
+
return Promise.resolve(null);
|
|
618
|
+
}
|
|
619
|
+
if (event.key !== 'Enter' && event.key !== 'Escape') return Promise.resolve(null);
|
|
620
|
+
selectPreviewNode(node);
|
|
621
|
+
const attributes = getNodeAttributes(node);
|
|
622
|
+
const editEpoch = advanceHtmlPreviewElementEpoch(htmlPreviewElementEditEpochs, element);
|
|
623
|
+
const focusEpoch = getHtmlPreviewElementEpoch(htmlPreviewElementFocusEpochs, element);
|
|
624
|
+
const selectionStart = event.target.selectionStart;
|
|
625
|
+
const selectionEnd = event.target.selectionEnd;
|
|
626
|
+
if (event.key === 'Enter' && event.target instanceof HTMLTextAreaElement) {
|
|
627
|
+
// The runtime key path owns the newline and onWillChange/onChange/onReturn callbacks. Prevent the
|
|
628
|
+
// browser from also emitting a full-text input, then mirror the pending newline locally so typing
|
|
629
|
+
// stays responsive while the authoritative runtime result is in flight.
|
|
630
|
+
event.preventDefault();
|
|
631
|
+
if (!previewBoolean(attributes.ignoreNewlines, false)) {
|
|
632
|
+
const start = Math.max(0, Math.min(event.target.value.length, selectionStart));
|
|
633
|
+
const end = Math.max(start, Math.min(event.target.value.length, selectionEnd));
|
|
634
|
+
const caret = start + 1;
|
|
635
|
+
event.target.value = event.target.value.slice(0, start) + '\n' + event.target.value.slice(end);
|
|
636
|
+
event.target.setSelectionRange(caret, caret);
|
|
637
|
+
}
|
|
638
|
+
}
|
|
639
|
+
const expectedValue = event.target.value;
|
|
640
|
+
void flushHtmlPreviewTextInput(target, elementId);
|
|
641
|
+
const dispatch = enqueueHtmlPreviewInput(
|
|
642
|
+
target,
|
|
643
|
+
elementId,
|
|
644
|
+
{
|
|
645
|
+
type: 'key',
|
|
646
|
+
elementId,
|
|
647
|
+
key: event.key,
|
|
648
|
+
selectionStart,
|
|
649
|
+
selectionEnd,
|
|
650
|
+
},
|
|
651
|
+
{
|
|
652
|
+
quiet: true,
|
|
653
|
+
refresh: false,
|
|
654
|
+
refreshDelayMs: 180,
|
|
655
|
+
},
|
|
656
|
+
);
|
|
657
|
+
const configuredClose = attributes.closesWhenReturnKeyPressed;
|
|
658
|
+
const closesOnReturn =
|
|
659
|
+
configuredClose === undefined
|
|
660
|
+
? event.target instanceof HTMLInputElement
|
|
661
|
+
: previewBoolean(configuredClose, event.target instanceof HTMLInputElement);
|
|
662
|
+
const shouldBlurAfterDispatch = event.key === 'Escape' || closesOnReturn;
|
|
663
|
+
return dispatch.then(input => {
|
|
664
|
+
reconcileHtmlPreviewTextInputResult(event.target, expectedValue, input, incarnation, editEpoch);
|
|
665
|
+
if (
|
|
666
|
+
shouldBlurAfterDispatch &&
|
|
667
|
+
input?.handled &&
|
|
668
|
+
isCurrentHtmlPreviewElement(event.target, incarnation) &&
|
|
669
|
+
getHtmlPreviewElementEpoch(htmlPreviewElementFocusEpochs, event.target) === focusEpoch &&
|
|
670
|
+
document.activeElement === event.target
|
|
671
|
+
) {
|
|
672
|
+
event.target.blur();
|
|
673
|
+
}
|
|
674
|
+
return input;
|
|
675
|
+
});
|
|
676
|
+
}
|