@capybara-hq/plugin-browser 0.1.0-rc.4 → 0.1.0-rc.6
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/.capybara-plugin/plugin.json +2 -2
- package/README.md +129 -22
- package/dist/index.mjs +285 -79
- package/package.json +1 -1
- package/ui/panel.js +748 -134
- package/ui/service/daemon.mjs +1452 -173
package/ui/panel.js
CHANGED
|
@@ -3,8 +3,67 @@
|
|
|
3
3
|
// daemon/protocol.ts
|
|
4
4
|
var VIEWPORT = { width: 1280, height: 800 };
|
|
5
5
|
var IDLE_STOP_MS = 15 * 6e4;
|
|
6
|
+
var VIEWER_TEXT_MAX_CHARS = 1e4;
|
|
7
|
+
function clipCodePoints(text, max) {
|
|
8
|
+
if (text.length <= max) return text;
|
|
9
|
+
return Array.from(text).slice(0, max).join("");
|
|
10
|
+
}
|
|
11
|
+
var VIEWER_CURSORS = [
|
|
12
|
+
"default",
|
|
13
|
+
"pointer",
|
|
14
|
+
"text",
|
|
15
|
+
"vertical-text",
|
|
16
|
+
"crosshair",
|
|
17
|
+
"move",
|
|
18
|
+
"grab",
|
|
19
|
+
"grabbing",
|
|
20
|
+
"not-allowed",
|
|
21
|
+
"no-drop",
|
|
22
|
+
"wait",
|
|
23
|
+
"progress",
|
|
24
|
+
"help",
|
|
25
|
+
"context-menu",
|
|
26
|
+
"cell",
|
|
27
|
+
"copy",
|
|
28
|
+
"alias",
|
|
29
|
+
"zoom-in",
|
|
30
|
+
"zoom-out",
|
|
31
|
+
"col-resize",
|
|
32
|
+
"row-resize",
|
|
33
|
+
"ew-resize",
|
|
34
|
+
"ns-resize",
|
|
35
|
+
"nesw-resize",
|
|
36
|
+
"nwse-resize",
|
|
37
|
+
"n-resize",
|
|
38
|
+
"e-resize",
|
|
39
|
+
"s-resize",
|
|
40
|
+
"w-resize",
|
|
41
|
+
"ne-resize",
|
|
42
|
+
"nw-resize",
|
|
43
|
+
"se-resize",
|
|
44
|
+
"sw-resize",
|
|
45
|
+
"all-scroll",
|
|
46
|
+
"none"
|
|
47
|
+
];
|
|
48
|
+
function toViewerCursor(value) {
|
|
49
|
+
return typeof value === "string" && VIEWER_CURSORS.includes(value) ? value : "default";
|
|
50
|
+
}
|
|
51
|
+
var FRAME_TAG = 0;
|
|
52
|
+
var FRAME_HEADER_BYTES = 9;
|
|
53
|
+
function decodeFrame(m) {
|
|
54
|
+
if (m.byteLength < FRAME_HEADER_BYTES || m[0] !== FRAME_TAG) return null;
|
|
55
|
+
const v = new DataView(m.buffer, m.byteOffset, m.byteLength);
|
|
56
|
+
return {
|
|
57
|
+
seq: v.getUint32(1),
|
|
58
|
+
width: v.getUint16(5),
|
|
59
|
+
height: v.getUint16(7),
|
|
60
|
+
jpeg: m.subarray(FRAME_HEADER_BYTES)
|
|
61
|
+
};
|
|
62
|
+
}
|
|
6
63
|
var DEFAULT_FRAME_MAX_BYTES = 256 * 1024;
|
|
7
64
|
var HANDOFF_KEEPALIVE_MS = 24 * 60 * 6e4;
|
|
65
|
+
var FAVICON_MAX_BYTES = 8 * 1024;
|
|
66
|
+
var isIconDataUrl = (s) => typeof s === "string" && s.length <= 64 + Math.ceil(FAVICON_MAX_BYTES * 4 / 3) && /^data:image\/(png|x-icon|gif|jpeg|webp|svg\+xml);base64,[A-Za-z0-9+/=]+$/.test(s);
|
|
8
67
|
|
|
9
68
|
// ui-src/panel/i18n.ts
|
|
10
69
|
var STRINGS = {
|
|
@@ -18,11 +77,17 @@
|
|
|
18
77
|
closeTab: "Close tab",
|
|
19
78
|
takeover: "Take over",
|
|
20
79
|
handback: "Hand back to the agent",
|
|
21
|
-
|
|
22
|
-
|
|
80
|
+
statusUser: "You are in control",
|
|
81
|
+
statusUserDetail: "the agent is paused; press Esc to hand back",
|
|
82
|
+
statusAgent: "The agent is working",
|
|
23
83
|
statusUserElsewhere: "You are controlling the browser from another view",
|
|
24
|
-
statusLoading: "
|
|
25
|
-
statusConnecting: "Connecting…",
|
|
84
|
+
statusLoading: "loading the page",
|
|
85
|
+
statusConnecting: "Connecting to the browser…",
|
|
86
|
+
tabs: "Tabs",
|
|
87
|
+
more: "More",
|
|
88
|
+
verifyTitle: "Verification needed",
|
|
89
|
+
verifyBody: "The site asks for a human check. Hand back when you are done; the agent continues from here.",
|
|
90
|
+
verifyGo: "Verify",
|
|
26
91
|
blocked: "Blocked by the network setting:",
|
|
27
92
|
allow: "Allow",
|
|
28
93
|
dialog: "The page shows a dialog:",
|
|
@@ -52,11 +117,17 @@
|
|
|
52
117
|
closeTab: "关闭标签页",
|
|
53
118
|
takeover: "接管",
|
|
54
119
|
handback: "交还智能体",
|
|
55
|
-
|
|
56
|
-
|
|
120
|
+
statusUser: "你正在操作",
|
|
121
|
+
statusUserDetail: "智能体已暂停,按 Esc 交还",
|
|
122
|
+
statusAgent: "智能体正在操作",
|
|
57
123
|
statusUserElsewhere: "你正在另一个视图中控制浏览器",
|
|
58
|
-
statusLoading: "
|
|
59
|
-
statusConnecting: "
|
|
124
|
+
statusLoading: "正在加载页面",
|
|
125
|
+
statusConnecting: "正在连接浏览器…",
|
|
126
|
+
tabs: "标签页",
|
|
127
|
+
more: "更多",
|
|
128
|
+
verifyTitle: "需要你完成验证",
|
|
129
|
+
verifyBody: "网站要求人工验证。完成后交还,智能体从这里继续。",
|
|
130
|
+
verifyGo: "去验证",
|
|
60
131
|
blocked: "被网络设置拦截:",
|
|
61
132
|
allow: "允许",
|
|
62
133
|
dialog: "页面弹出了对话框:",
|
|
@@ -81,15 +152,444 @@
|
|
|
81
152
|
return STRINGS[locale][key];
|
|
82
153
|
}
|
|
83
154
|
|
|
155
|
+
// ui-src/panel/input.ts
|
|
156
|
+
var MOVE_EVERY_MS = 33;
|
|
157
|
+
var PRESS_MAX_MS = 1e3;
|
|
158
|
+
function mountInput(opts) {
|
|
159
|
+
const win = opts.window;
|
|
160
|
+
const doc = win.document;
|
|
161
|
+
const { view, stage, send, interactive } = opts;
|
|
162
|
+
const sink = doc.createElement("textarea");
|
|
163
|
+
sink.id = "input-sink";
|
|
164
|
+
sink.setAttribute("aria-label", opts.label);
|
|
165
|
+
sink.setAttribute("autocomplete", "off");
|
|
166
|
+
sink.setAttribute("autocapitalize", "off");
|
|
167
|
+
sink.setAttribute("autocorrect", "off");
|
|
168
|
+
sink.spellcheck = false;
|
|
169
|
+
sink.tabIndex = -1;
|
|
170
|
+
Object.assign(sink.style, {
|
|
171
|
+
position: "absolute",
|
|
172
|
+
left: "0px",
|
|
173
|
+
top: "0px",
|
|
174
|
+
width: "1px",
|
|
175
|
+
height: "1px",
|
|
176
|
+
padding: "0",
|
|
177
|
+
border: "0",
|
|
178
|
+
margin: "0",
|
|
179
|
+
opacity: "0",
|
|
180
|
+
resize: "none",
|
|
181
|
+
overflow: "hidden",
|
|
182
|
+
pointerEvents: "none",
|
|
183
|
+
whiteSpace: "pre"
|
|
184
|
+
});
|
|
185
|
+
stage.appendChild(sink);
|
|
186
|
+
const press = doc.createElement("div");
|
|
187
|
+
press.id = "press";
|
|
188
|
+
press.hidden = true;
|
|
189
|
+
press.setAttribute("aria-hidden", "true");
|
|
190
|
+
Object.assign(press.style, {
|
|
191
|
+
position: "absolute",
|
|
192
|
+
width: "18px",
|
|
193
|
+
height: "18px",
|
|
194
|
+
margin: "-9px 0 0 -9px",
|
|
195
|
+
borderRadius: "50%",
|
|
196
|
+
border: "2px solid var(--cb-accent, Highlight)",
|
|
197
|
+
pointerEvents: "none"
|
|
198
|
+
});
|
|
199
|
+
stage.appendChild(press);
|
|
200
|
+
let pressTimer;
|
|
201
|
+
let pressReleased = false;
|
|
202
|
+
let cursor = "default";
|
|
203
|
+
let focusWanted = false;
|
|
204
|
+
let held = null;
|
|
205
|
+
const downKeys = /* @__PURE__ */ new Map();
|
|
206
|
+
let lastPointer = { x: 0, y: 0 };
|
|
207
|
+
let moveTimer;
|
|
208
|
+
let nextMove = null;
|
|
209
|
+
const inStage = (clientX, clientY) => {
|
|
210
|
+
const r = stage.getBoundingClientRect();
|
|
211
|
+
return { left: clientX - r.left, top: clientY - r.top };
|
|
212
|
+
};
|
|
213
|
+
function placeSink(clientX, clientY) {
|
|
214
|
+
const p = inStage(clientX, clientY);
|
|
215
|
+
sink.style.left = `${Math.round(p.left)}px`;
|
|
216
|
+
sink.style.top = `${Math.round(p.top)}px`;
|
|
217
|
+
}
|
|
218
|
+
function showPress(clientX, clientY) {
|
|
219
|
+
const p = inStage(clientX, clientY);
|
|
220
|
+
press.style.left = `${Math.round(p.left)}px`;
|
|
221
|
+
press.style.top = `${Math.round(p.top)}px`;
|
|
222
|
+
press.setAttribute("data-state", "down");
|
|
223
|
+
press.hidden = false;
|
|
224
|
+
pressReleased = false;
|
|
225
|
+
if (pressTimer !== void 0) clearTimeout(pressTimer);
|
|
226
|
+
pressTimer = setTimeout(hidePress, PRESS_MAX_MS);
|
|
227
|
+
}
|
|
228
|
+
function hidePress() {
|
|
229
|
+
if (pressTimer !== void 0) clearTimeout(pressTimer);
|
|
230
|
+
pressTimer = void 0;
|
|
231
|
+
press.hidden = true;
|
|
232
|
+
press.removeAttribute("data-state");
|
|
233
|
+
pressReleased = false;
|
|
234
|
+
}
|
|
235
|
+
function applyCursor() {
|
|
236
|
+
view.style.cursor = interactive() ? cursor : "default";
|
|
237
|
+
}
|
|
238
|
+
function queueMove(p) {
|
|
239
|
+
nextMove = p;
|
|
240
|
+
if (moveTimer !== void 0) return;
|
|
241
|
+
flushMove();
|
|
242
|
+
}
|
|
243
|
+
function flushMove() {
|
|
244
|
+
const p = nextMove;
|
|
245
|
+
nextMove = null;
|
|
246
|
+
if (p === null) {
|
|
247
|
+
moveTimer = void 0;
|
|
248
|
+
return;
|
|
249
|
+
}
|
|
250
|
+
if (interactive()) send({ t: "mouse", kind: "move", ...p });
|
|
251
|
+
moveTimer = setTimeout(flushMove, MOVE_EVERY_MS);
|
|
252
|
+
}
|
|
253
|
+
function dropMove() {
|
|
254
|
+
nextMove = null;
|
|
255
|
+
}
|
|
256
|
+
view.addEventListener("mousedown", (e) => {
|
|
257
|
+
if (!interactive()) return;
|
|
258
|
+
e.preventDefault();
|
|
259
|
+
const button = e.button === 2 ? "right" : "left";
|
|
260
|
+
held = button;
|
|
261
|
+
dropMove();
|
|
262
|
+
placeSink(e.clientX, e.clientY);
|
|
263
|
+
sink.focus();
|
|
264
|
+
showPress(e.clientX, e.clientY);
|
|
265
|
+
lastPointer = opts.toPage(e.clientX, e.clientY);
|
|
266
|
+
send({ t: "mouse", kind: "down", ...lastPointer, button });
|
|
267
|
+
});
|
|
268
|
+
const release = (e) => {
|
|
269
|
+
if (held === null) return;
|
|
270
|
+
const button = held;
|
|
271
|
+
held = null;
|
|
272
|
+
if (!interactive()) return;
|
|
273
|
+
dropMove();
|
|
274
|
+
press.setAttribute("data-state", "up");
|
|
275
|
+
pressReleased = true;
|
|
276
|
+
send({ t: "mouse", kind: "up", ...opts.toPage(e.clientX, e.clientY), button });
|
|
277
|
+
};
|
|
278
|
+
win.addEventListener("mouseup", release);
|
|
279
|
+
const moved = (e) => {
|
|
280
|
+
if (!interactive()) return;
|
|
281
|
+
lastPointer = opts.toPage(e.clientX, e.clientY);
|
|
282
|
+
queueMove(lastPointer);
|
|
283
|
+
};
|
|
284
|
+
view.addEventListener("mousemove", moved);
|
|
285
|
+
win.addEventListener("mousemove", (e) => {
|
|
286
|
+
if (held !== null && e.target !== view) moved(e);
|
|
287
|
+
});
|
|
288
|
+
view.addEventListener(
|
|
289
|
+
"wheel",
|
|
290
|
+
(e) => {
|
|
291
|
+
if (!interactive()) return;
|
|
292
|
+
e.preventDefault();
|
|
293
|
+
dropMove();
|
|
294
|
+
send({
|
|
295
|
+
t: "mouse",
|
|
296
|
+
kind: "wheel",
|
|
297
|
+
...opts.toPage(e.clientX, e.clientY),
|
|
298
|
+
dx: e.deltaX,
|
|
299
|
+
dy: e.deltaY
|
|
300
|
+
});
|
|
301
|
+
},
|
|
302
|
+
{ passive: false }
|
|
303
|
+
);
|
|
304
|
+
view.addEventListener("contextmenu", (e) => e.preventDefault());
|
|
305
|
+
const composing = (e) => e.isComposing || e.key === "Process" || e.keyCode === 229;
|
|
306
|
+
const isPasteShortcut = (e) => (e.metaKey || e.ctrlKey) && !e.altKey && e.key.toLowerCase() === "v";
|
|
307
|
+
function sendText(text) {
|
|
308
|
+
if (text === "") return;
|
|
309
|
+
const t2 = clipCodePoints(text, VIEWER_TEXT_MAX_CHARS);
|
|
310
|
+
send({ t: "key", kind: "char", key: t2, text: t2 });
|
|
311
|
+
}
|
|
312
|
+
sink.addEventListener("keydown", (e) => {
|
|
313
|
+
if (!interactive() || e.key === "Escape" || composing(e) || isPasteShortcut(e)) return;
|
|
314
|
+
e.preventDefault();
|
|
315
|
+
downKeys.set(e.key, e.code);
|
|
316
|
+
send({ t: "key", kind: "down", key: e.key, code: e.code });
|
|
317
|
+
});
|
|
318
|
+
sink.addEventListener("keyup", (e) => {
|
|
319
|
+
if (!interactive() || e.key === "Escape" || composing(e) || isPasteShortcut(e)) return;
|
|
320
|
+
e.preventDefault();
|
|
321
|
+
downKeys.delete(e.key);
|
|
322
|
+
send({ t: "key", kind: "up", key: e.key, code: e.code });
|
|
323
|
+
});
|
|
324
|
+
function releaseAll() {
|
|
325
|
+
if (interactive()) {
|
|
326
|
+
for (const [key, code] of downKeys) send({ t: "key", kind: "up", key, code });
|
|
327
|
+
if (held !== null) send({ t: "mouse", kind: "up", ...lastPointer, button: held });
|
|
328
|
+
}
|
|
329
|
+
downKeys.clear();
|
|
330
|
+
held = null;
|
|
331
|
+
}
|
|
332
|
+
win.addEventListener("blur", releaseAll);
|
|
333
|
+
sink.addEventListener("blur", releaseAll);
|
|
334
|
+
doc.addEventListener("visibilitychange", () => {
|
|
335
|
+
if (doc.visibilityState === "hidden") releaseAll();
|
|
336
|
+
});
|
|
337
|
+
sink.addEventListener("compositionend", (e) => {
|
|
338
|
+
if (interactive()) sendText(e.data ?? "");
|
|
339
|
+
sink.value = "";
|
|
340
|
+
});
|
|
341
|
+
sink.addEventListener("input", (e) => {
|
|
342
|
+
const ie = e;
|
|
343
|
+
if (ie.isComposing || (ie.inputType ?? "").includes("Composition")) return;
|
|
344
|
+
if (interactive()) sendText(sink.value);
|
|
345
|
+
sink.value = "";
|
|
346
|
+
});
|
|
347
|
+
sink.addEventListener("paste", (e) => {
|
|
348
|
+
e.preventDefault();
|
|
349
|
+
if (!interactive()) return;
|
|
350
|
+
sendText(e.clipboardData?.getData("text/plain") ?? "");
|
|
351
|
+
});
|
|
352
|
+
return {
|
|
353
|
+
sink,
|
|
354
|
+
sync() {
|
|
355
|
+
applyCursor();
|
|
356
|
+
if (!interactive()) {
|
|
357
|
+
held = null;
|
|
358
|
+
downKeys.clear();
|
|
359
|
+
nextMove = null;
|
|
360
|
+
hidePress();
|
|
361
|
+
if (doc.activeElement === sink) sink.blur();
|
|
362
|
+
return;
|
|
363
|
+
}
|
|
364
|
+
if (focusWanted) {
|
|
365
|
+
focusWanted = false;
|
|
366
|
+
sink.focus();
|
|
367
|
+
}
|
|
368
|
+
},
|
|
369
|
+
frame() {
|
|
370
|
+
if (pressReleased) hidePress();
|
|
371
|
+
},
|
|
372
|
+
cursor(value) {
|
|
373
|
+
cursor = toViewerCursor(value);
|
|
374
|
+
applyCursor();
|
|
375
|
+
},
|
|
376
|
+
focus() {
|
|
377
|
+
focusWanted = !interactive();
|
|
378
|
+
sink.focus();
|
|
379
|
+
}
|
|
380
|
+
};
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
// ui-src/panel/page.ts
|
|
384
|
+
var ICONS = {
|
|
385
|
+
back: '<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m15 18-6-6 6-6"/></svg>',
|
|
386
|
+
forward: '<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m9 18 6-6-6-6"/></svg>',
|
|
387
|
+
reload: '<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M21 12a9 9 0 1 1-3-6.7L21 8"/><path d="M21 3v5h-5"/></svg>',
|
|
388
|
+
close: '<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" aria-hidden="true"><path d="M18 6 6 18M6 6l12 12"/></svg>',
|
|
389
|
+
plus: '<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" aria-hidden="true"><path d="M12 5v14M5 12h14"/></svg>',
|
|
390
|
+
lock: '<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" aria-hidden="true"><rect x="5" y="11" width="14" height="10" rx="2"/><path d="M8 11V7a4 4 0 0 1 8 0v4"/></svg>',
|
|
391
|
+
more: '<svg width="16" height="16" viewBox="0 0 24 24" fill="currentColor" aria-hidden="true"><circle cx="5" cy="12" r="1.6"/><circle cx="12" cy="12" r="1.6"/><circle cx="19" cy="12" r="1.6"/></svg>',
|
|
392
|
+
spin: '<svg class="spin" width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.4" stroke-linecap="round" aria-hidden="true"><path d="M21 12a9 9 0 1 1-9-9"/></svg>',
|
|
393
|
+
dot: '<svg width="12" height="12" viewBox="0 0 24 24" aria-hidden="true"><circle cx="12" cy="12" r="4" fill="currentColor"/></svg>',
|
|
394
|
+
hand: '<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M9 11V5a2 2 0 0 1 4 0v6"/><path d="M13 10V8a2 2 0 0 1 4 0v5a7 7 0 0 1-7 7h-.5A6.5 6.5 0 0 1 5 17.5L4 15a2 2 0 0 1 3.4-2L9 15"/></svg>',
|
|
395
|
+
pause: '<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" aria-hidden="true"><rect x="6" y="5" width="4" height="14" rx="1"/><rect x="14" y="5" width="4" height="14" rx="1"/></svg>'
|
|
396
|
+
};
|
|
397
|
+
var bone = (style) => `<span class="bone" style="${style}"></span>`;
|
|
398
|
+
var PANEL_HTML = `<!doctype html>
|
|
399
|
+
<html lang="en">
|
|
400
|
+
<head>
|
|
401
|
+
<meta charset="utf-8">
|
|
402
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
403
|
+
<title>Browser</title>
|
|
404
|
+
<style>
|
|
405
|
+
:root {
|
|
406
|
+
color-scheme: light;
|
|
407
|
+
--ground: color-mix(in srgb, var(--cb-ink, #1A1A18) 5%, var(--cb-bg, #FAF9F6));
|
|
408
|
+
--frame-shadow: 0 1px 2px rgba(26,26,24,.06), 0 4px 16px rgba(26,26,24,.06);
|
|
409
|
+
--bone: color-mix(in srgb, var(--cb-ink, #1A1A18) 7%, transparent);
|
|
410
|
+
--radius: 6px;
|
|
411
|
+
}
|
|
412
|
+
:root[data-theme="dark"] {
|
|
413
|
+
color-scheme: dark;
|
|
414
|
+
--ground: var(--cb-bg, #0A0A0A);
|
|
415
|
+
--frame-shadow: 0 0 0 1px rgba(255,255,255,.08);
|
|
416
|
+
}
|
|
417
|
+
* { box-sizing: border-box; }
|
|
418
|
+
html, body { height: 100%; }
|
|
419
|
+
body {
|
|
420
|
+
margin: 0; position: relative; overflow: hidden;
|
|
421
|
+
background: var(--cb-panel-2, Canvas); color: var(--cb-ink, CanvasText);
|
|
422
|
+
font-family: var(--cb-font, ui-monospace, "SF Mono", Menlo, monospace);
|
|
423
|
+
font-size: var(--cb-type-body-size, 13px); line-height: var(--cb-type-body-line, 20px);
|
|
424
|
+
}
|
|
425
|
+
/* nothing before the host's tokens and language (init) */
|
|
426
|
+
body:not([data-ready]) { visibility: hidden; }
|
|
427
|
+
[hidden] { display: none !important; }
|
|
428
|
+
button, input { font: inherit; color: inherit; margin: 0; }
|
|
429
|
+
button {
|
|
430
|
+
display: inline-grid; place-items: center; flex: none; height: 28px; min-width: 28px;
|
|
431
|
+
padding: 0; border: 0; border-radius: var(--radius); background: transparent; cursor: pointer;
|
|
432
|
+
white-space: nowrap;
|
|
433
|
+
}
|
|
434
|
+
button:hover:not(:disabled) { background: var(--cb-hover, rgba(26,26,24,.04)); }
|
|
435
|
+
button:disabled { color: var(--cb-disabled, GrayText); cursor: default; }
|
|
436
|
+
button:focus-visible, input:focus-visible { outline: 2px solid var(--cb-focus-ring, Highlight); outline-offset: 1px; }
|
|
437
|
+
.primary, .secondary, .outline { padding: 0 14px; font-weight: 600; }
|
|
438
|
+
.primary { background: var(--cb-accent, #CC4609); color: var(--cb-on-accent, #fff); }
|
|
439
|
+
.primary:hover:not(:disabled) { background: var(--cb-accent-hover, var(--cb-accent, #CC4609)); }
|
|
440
|
+
.secondary { font-weight: 400; box-shadow: inset 0 0 0 1px var(--cb-line, #D9D8D2); }
|
|
441
|
+
.outline { padding: 0 12px; color: var(--cb-accent, #CC4609); box-shadow: inset 0 0 0 1px var(--cb-accent, #CC4609); }
|
|
442
|
+
|
|
443
|
+
.layer { position: absolute; inset: 0; display: flex; flex-direction: column; }
|
|
444
|
+
/* laid out underneath while the skeleton or the idle state shows, so the switch never reflows */
|
|
445
|
+
#app[data-loading], #app[data-idle] { visibility: hidden; }
|
|
446
|
+
.row { flex: none; display: flex; align-items: center; padding: 0 12px; }
|
|
447
|
+
|
|
448
|
+
/* tab strip */
|
|
449
|
+
#tabs { height: 32px; align-items: stretch; gap: 2px; overflow-x: auto; scrollbar-width: none; }
|
|
450
|
+
.tab { display: flex; align-items: center; gap: 6px; flex: 0 1 auto; min-width: 64px; max-width: 200px; padding: 0 10px; color: var(--cb-muted, #5E5E5A); }
|
|
451
|
+
.tab[data-active="true"] { color: var(--cb-ink, #1A1A18); font-weight: 500; box-shadow: inset 0 -2px 0 var(--cb-accent, #CC4609); padding-right: 6px; }
|
|
452
|
+
.fav { width: 14px; height: 14px; border-radius: 3px; flex: none; background: var(--cb-line-soft, #E8E7E2); }
|
|
453
|
+
img.fav { background: none; object-fit: contain; }
|
|
454
|
+
.tab[data-active="true"] span.fav { background: var(--cb-line, #D9D8D2); }
|
|
455
|
+
.tab .label { flex: 1; min-width: 0; display: block; height: auto; text-align: left; overflow: hidden; text-overflow: ellipsis; font-weight: inherit; }
|
|
456
|
+
.tab .label:hover:not(:disabled) { background: transparent; }
|
|
457
|
+
.tab .label:disabled { color: inherit; }
|
|
458
|
+
.tab .x { width: 20px; min-width: 20px; height: 20px; border-radius: 4px; color: var(--cb-muted, #5E5E5A); }
|
|
459
|
+
#tabs .add { align-self: center; color: var(--cb-muted, #5E5E5A); }
|
|
460
|
+
|
|
461
|
+
/* toolbar */
|
|
462
|
+
#bar { height: 44px; gap: 4px; }
|
|
463
|
+
#field { flex: 1 1 0; min-width: 0; height: 28px; margin-left: 4px; position: relative; display: flex; align-items: center; border-radius: var(--radius); background: var(--cb-hover, rgba(26,26,24,.05)); }
|
|
464
|
+
#field[data-edit] { background: var(--cb-panel, #fff); box-shadow: inset 0 0 0 1px var(--cb-line, #D9D8D2); }
|
|
465
|
+
#lock { display: inline-flex; flex: none; margin-left: 10px; color: var(--cb-muted, #5E5E5A); }
|
|
466
|
+
#url { flex: 1; min-width: 0; height: 100%; padding: 0 10px 0 6px; border: 0; outline: 0; background: transparent; color: transparent; caret-color: var(--cb-ink, #1A1A18); text-overflow: ellipsis; }
|
|
467
|
+
#lock[hidden] + #url, #lock[hidden] ~ #urltext { padding-left: 10px; }
|
|
468
|
+
#url:focus { color: var(--cb-ink, #1A1A18); }
|
|
469
|
+
#urltext { position: absolute; inset: 0 10px 0 26px; display: flex; align-items: center; pointer-events: none; white-space: nowrap; overflow: hidden; }
|
|
470
|
+
#lock[hidden] ~ #urltext { left: 10px; padding-left: 0; }
|
|
471
|
+
#urltext span:first-child { flex: none; max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
|
|
472
|
+
#urltext span:last-child { color: var(--cb-muted, #5E5E5A); overflow: hidden; text-overflow: ellipsis; }
|
|
473
|
+
#url:focus ~ #urltext { visibility: hidden; }
|
|
474
|
+
#takeover, #handback { margin-left: 4px; }
|
|
475
|
+
/* the takeover slot is always reserved: gone only when hand back takes its place */
|
|
476
|
+
#takeover[hidden]:not([data-gone]) { display: inline-grid !important; visibility: hidden; }
|
|
477
|
+
#tabsbtn { flex: 1 1 0; min-width: 0; display: flex; align-items: center; gap: 6px; padding: 0 8px; background: var(--cb-hover, rgba(26,26,24,.05)); text-align: left; }
|
|
478
|
+
#tabsbtn .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
|
|
479
|
+
#tabsbtn .count { min-width: 18px; height: 18px; padding: 0 4px; border-radius: 4px; box-shadow: inset 0 0 0 1px var(--cb-line-strong, #B5B5AE); font-size: 11px; line-height: 18px; text-align: center; color: var(--cb-muted, #5E5E5A); }
|
|
480
|
+
#tabsbtn, #more { display: none; }
|
|
481
|
+
@media (max-width: 440px) {
|
|
482
|
+
#tabs, #forward, #reload, #field { display: none; }
|
|
483
|
+
#tabsbtn { display: flex; }
|
|
484
|
+
#more { display: inline-grid; color: var(--cb-muted, #5E5E5A); }
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
/* status line: one fixed-height line */
|
|
488
|
+
#status { height: 24px; gap: 6px; margin: 0; padding: 0 16px; font-size: var(--cb-type-micro-size, 11px); line-height: var(--cb-type-micro-line, 14px); color: var(--cb-muted, #5E5E5A); white-space: nowrap; overflow: hidden; }
|
|
489
|
+
#status .ico { display: inline-flex; flex: none; }
|
|
490
|
+
#status .lead { flex: none; }
|
|
491
|
+
#status .detail { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
|
|
492
|
+
#status[data-tone="agent"] .ico, #status[data-tone="agent"] .lead { color: var(--cb-accent, #CC4609); }
|
|
493
|
+
#status[data-tone="user"] .ico, #status[data-tone="user"] .lead { color: var(--cb-ink, #1A1A18); }
|
|
494
|
+
.spin { animation: spin 1s linear infinite; }
|
|
495
|
+
@keyframes spin { to { transform: rotate(360deg); } }
|
|
496
|
+
|
|
497
|
+
/* needs the person: a warn strip in the status line's place */
|
|
498
|
+
.warn { flex: none; display: flex; align-items: center; gap: 10px; padding: 8px 12px 8px 16px; background: color-mix(in srgb, var(--cb-warn, #8F6500) 8%, transparent); }
|
|
499
|
+
.warn > .ico { display: inline-flex; flex: none; color: var(--cb-warn, #8F6500); }
|
|
500
|
+
.warn .text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
|
|
501
|
+
.warn .title { color: var(--cb-warn, #8F6500); font-weight: 500; overflow-wrap: anywhere; }
|
|
502
|
+
.warn .body { font-family: var(--cb-font-prose, system-ui, sans-serif); color: var(--cb-muted, #5E5E5A); overflow-wrap: anywhere; }
|
|
503
|
+
.warn .actions { display: flex; gap: 6px; flex: none; }
|
|
504
|
+
|
|
505
|
+
/* the picture, contained and centred on a neutral ground */
|
|
506
|
+
#stage { flex: 1; min-height: 0; position: relative; display: flex; align-items: center; justify-content: center; padding: 12px; overflow: hidden; background: var(--ground); }
|
|
507
|
+
#view { display: block; flex: none; border-radius: var(--radius); background: #fff; box-shadow: var(--frame-shadow); outline: none; }
|
|
508
|
+
#stage[data-control="user"] #view { box-shadow: 0 0 0 2px var(--cb-accent, #CC4609), 0 4px 16px rgba(26,26,24,.08); }
|
|
509
|
+
#view:focus-visible { box-shadow: 0 0 0 2px var(--cb-focus-ring, Highlight), var(--frame-shadow); }
|
|
510
|
+
#flash { position: absolute; width: 24px; height: 24px; margin: -12px 0 0 -12px; border: 2px solid var(--cb-accent, #CC4609); border-radius: 50%; pointer-events: none; }
|
|
511
|
+
.center { position: absolute; inset: 0; display: flex; flex-direction: column; gap: 6px; align-items: center; justify-content: center; padding: 16px; text-align: center; background: var(--ground); }
|
|
512
|
+
.center h2 { margin: 0; font-size: inherit; font-weight: 600; }
|
|
513
|
+
.center p { margin: 0; font-family: var(--cb-font-prose, system-ui, sans-serif); color: var(--cb-muted, #5E5E5A); }
|
|
514
|
+
.center button { margin-top: 6px; }
|
|
515
|
+
/* short-lived notices float over the picture's bottom edge: they never move it */
|
|
516
|
+
#strips { position: absolute; left: 12px; right: 12px; bottom: 12px; display: flex; flex-direction: column; gap: 6px; pointer-events: none; }
|
|
517
|
+
.strip { display: flex; align-items: center; gap: 8px; padding: 6px 6px 6px 12px; pointer-events: auto; border-radius: var(--cb-radius-md, 8px); background: var(--cb-raised, #fff); box-shadow: var(--cb-shadow-float, 0 8px 24px rgba(26,26,24,.08)), 0 0 0 1px var(--cb-line-soft, #E8E7E2); }
|
|
518
|
+
.strip p { flex: 1; min-width: 0; margin: 0; overflow-wrap: anywhere; }
|
|
519
|
+
.strip .label { color: var(--cb-muted, #5E5E5A); }
|
|
520
|
+
.strip:not(:has(button)) { padding-right: 12px; }
|
|
521
|
+
|
|
522
|
+
/* menus (narrow: tabs, more) */
|
|
523
|
+
.menu { position: absolute; z-index: 2; min-width: 180px; max-width: calc(100% - 24px); max-height: 60%; overflow: auto; padding: 4px; border-radius: var(--cb-radius-md, 8px); background: var(--cb-raised, #fff); box-shadow: var(--cb-shadow-float, 0 8px 24px rgba(26,26,24,.08)), 0 0 0 1px var(--cb-line-soft, #E8E7E2); }
|
|
524
|
+
.menu button { display: flex; width: 100%; justify-content: flex-start; gap: 8px; padding: 0 8px; text-align: left; overflow: hidden; text-overflow: ellipsis; }
|
|
525
|
+
.menu button[aria-current="true"] { font-weight: 600; }
|
|
526
|
+
|
|
527
|
+
/* the skeleton: the panel's own shape, quietly pulsing */
|
|
528
|
+
.bone { display: block; flex: none; border-radius: 2px; background: var(--bone); animation: pulse 1.6s ease-in-out infinite; }
|
|
529
|
+
@keyframes pulse { 50% { opacity: .5; } }
|
|
530
|
+
#skeleton .shot { width: 100%; max-height: 100%; aspect-ratio: 16 / 10; display: flex; flex-direction: column; gap: 12px; padding: 20px; border-radius: var(--radius); background: var(--cb-panel, #fff); box-shadow: 0 1px 2px rgba(26,26,24,.06); }
|
|
531
|
+
:root[data-theme="dark"] #skeleton .shot { background: var(--cb-raised, #141413); box-shadow: var(--frame-shadow); }
|
|
532
|
+
#skeleton .narrow { display: none; }
|
|
533
|
+
@media (max-width: 440px) {
|
|
534
|
+
#skeleton .wide { display: none; }
|
|
535
|
+
#skeleton .narrow { display: block; }
|
|
536
|
+
}
|
|
537
|
+
@media (prefers-reduced-motion: reduce) { .bone, .spin { animation: none; } }
|
|
538
|
+
</style>
|
|
539
|
+
</head>
|
|
540
|
+
<body>
|
|
541
|
+
<div id="skeleton" class="layer" aria-busy="true">
|
|
542
|
+
<div class="row wide" style="height:32px;gap:8px;padding:0 22px;display:flex">${bone("width:14px;height:14px;border-radius:3px")}${bone("width:96px;height:10px")}</div>
|
|
543
|
+
<div class="row" style="height:44px;gap:4px">${bone("width:28px;height:28px;border-radius:6px")}<span class="wide" style="display:contents">${bone("width:28px;height:28px;border-radius:6px")}${bone("width:28px;height:28px;border-radius:6px")}</span>${bone("flex:1;height:28px;margin-left:4px;border-radius:6px")}${bone("width:56px;height:28px;margin-left:4px;border-radius:6px")}</div>
|
|
544
|
+
<p id="skeleton-status" class="row" role="status" style="height:24px;margin:0;padding:0 16px;font-size:11px;line-height:14px;color:var(--cb-muted,#5E5E5A)"></p>
|
|
545
|
+
<div style="flex:1;min-height:0;display:flex;align-items:center;justify-content:center;padding:12px;background:var(--ground)">
|
|
546
|
+
<div class="shot">${bone("width:40%;height:12px")}${bone("width:75%;height:10px")}${bone("width:60%;height:10px")}${bone("flex:1;border-radius:4px")}</div>
|
|
547
|
+
</div>
|
|
548
|
+
</div>
|
|
549
|
+
<div id="app" class="layer" data-loading>
|
|
550
|
+
<div id="tabs" class="row" role="tablist"></div>
|
|
551
|
+
<div id="bar" class="row">
|
|
552
|
+
<button type="button" id="back">${ICONS.back}</button>
|
|
553
|
+
<button type="button" id="forward">${ICONS.forward}</button>
|
|
554
|
+
<button type="button" id="reload">${ICONS.reload}</button>
|
|
555
|
+
<button type="button" id="tabsbtn" aria-haspopup="menu"><span class="fav"></span><span class="name" id="tabsbtn-name"></span><span class="count" id="tabsbtn-count"></span></button>
|
|
556
|
+
<label id="field"><span id="lock" role="img" hidden>${ICONS.lock}</span><input id="url" type="text" spellcheck="false" autocomplete="off"><span id="urltext"><span id="urltext-host"></span><span id="urltext-path"></span></span></label>
|
|
557
|
+
<button type="button" id="more" aria-haspopup="menu">${ICONS.more}</button>
|
|
558
|
+
<button type="button" id="takeover" class="primary" hidden></button>
|
|
559
|
+
<button type="button" id="handback" class="outline" hidden></button>
|
|
560
|
+
</div>
|
|
561
|
+
<p id="status" class="row" role="status"><span class="ico" id="status-icon"></span><span class="lead" id="status-lead"></span><span class="detail" id="status-detail"></span></p>
|
|
562
|
+
<div id="verify" class="warn" hidden><span class="ico">${ICONS.pause}</span><div class="text"><span class="title" id="verify-title"></span><span class="body" id="verify-body"></span></div><div class="actions"><button type="button" id="verify-go" class="primary"></button></div></div>
|
|
563
|
+
<div id="handoff" class="warn" hidden><span class="ico">${ICONS.pause}</span><div class="text"><span class="title" id="handoff-label"></span><span class="body" id="handoff-message"></span></div><div class="actions"><button type="button" id="handoff-done" class="primary"></button><button type="button" id="handoff-cancel" class="secondary"></button></div></div>
|
|
564
|
+
<div id="stage">
|
|
565
|
+
<canvas id="view" tabindex="0"></canvas>
|
|
566
|
+
<div id="flash" hidden></div>
|
|
567
|
+
<div id="strips">
|
|
568
|
+
<div id="blocked" class="strip" hidden><p><span id="blocked-label" class="label"></span> <span id="blocked-host"></span></p><button type="button" id="allow" class="primary"></button></div>
|
|
569
|
+
<div id="dialog" class="strip" hidden><p><span id="dialog-label" class="label"></span> <span id="dialog-text"></span></p></div>
|
|
570
|
+
<div id="notice" class="strip" role="alert" hidden><p><span id="notice-text"></span></p></div>
|
|
571
|
+
</div>
|
|
572
|
+
</div>
|
|
573
|
+
</div>
|
|
574
|
+
<div id="empty" class="layer center" hidden>
|
|
575
|
+
<h2 id="empty-title"></h2>
|
|
576
|
+
<p id="empty-body"></p>
|
|
577
|
+
<button type="button" id="reconnect" class="secondary"></button>
|
|
578
|
+
</div>
|
|
579
|
+
<div id="menu" class="menu" role="menu" hidden></div>
|
|
580
|
+
<script src="panel.js"><\/script>
|
|
581
|
+
</body>
|
|
582
|
+
</html>
|
|
583
|
+
`;
|
|
584
|
+
|
|
84
585
|
// ui-src/panel/panel.ts
|
|
85
586
|
var PROTOCOL = "capybara-embed/1";
|
|
86
587
|
var ASPECT = VIEWPORT.width / VIEWPORT.height;
|
|
87
588
|
var SIDE_MAX_WIDTH = 640;
|
|
88
|
-
var
|
|
89
|
-
var
|
|
589
|
+
var MAX_DPR = 1.25;
|
|
590
|
+
var STAGE_PAD = 12;
|
|
90
591
|
var HIDDEN_CLOSE_MS = 6e4;
|
|
91
592
|
var COMPACT_BELOW = 600;
|
|
92
|
-
var MOVE_INTERVAL_MS = 50;
|
|
93
593
|
var RESTART_RETRY_MS = [1e3, 3e3];
|
|
94
594
|
var EMPTY_POLL_MS = 1e4;
|
|
95
595
|
var EMPTY_POLL_FOR_MS = 30 * 6e4;
|
|
@@ -137,7 +637,6 @@
|
|
|
137
637
|
let wasLive = false;
|
|
138
638
|
let quiet = false;
|
|
139
639
|
let full = false;
|
|
140
|
-
let postedHeight = 0;
|
|
141
640
|
let retryTimer;
|
|
142
641
|
let emptyTimer;
|
|
143
642
|
let emptySince;
|
|
@@ -152,22 +651,37 @@
|
|
|
152
651
|
let blockedUrl = "";
|
|
153
652
|
let pendingHandoff = null;
|
|
154
653
|
let sentSize = "";
|
|
155
|
-
let lastMove = Number.NEGATIVE_INFINITY;
|
|
156
654
|
let image = null;
|
|
157
|
-
|
|
655
|
+
let shown = "skeleton";
|
|
656
|
+
const compact = () => {
|
|
657
|
+
const sw = win.screen?.width ?? 0;
|
|
658
|
+
return sw > 0 && sw < COMPACT_BELOW;
|
|
659
|
+
};
|
|
158
660
|
const text = (key) => t(locale, key);
|
|
159
661
|
const interactive = () => !compact() && control === "user";
|
|
160
662
|
function send(msg) {
|
|
161
663
|
if (sock === null) return;
|
|
162
664
|
sock.send(new TextEncoder().encode(JSON.stringify(msg)));
|
|
163
665
|
}
|
|
164
|
-
|
|
165
|
-
|
|
666
|
+
const input = mountInput({
|
|
667
|
+
window: win,
|
|
668
|
+
view,
|
|
669
|
+
stage,
|
|
670
|
+
send,
|
|
671
|
+
interactive: () => interactive(),
|
|
672
|
+
toPage: (clientX, clientY) => {
|
|
673
|
+
const r = view.getBoundingClientRect();
|
|
674
|
+
return mapPoint(clientX - r.left, clientY - r.top, { x: 0, y: 0, w: r.width, h: r.height });
|
|
675
|
+
},
|
|
676
|
+
label: t(locale, "view")
|
|
677
|
+
});
|
|
678
|
+
function askMode(next) {
|
|
166
679
|
post({ protocol: PROTOCOL, type: "panel-mode", full: next });
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
680
|
+
}
|
|
681
|
+
function hostMode(next) {
|
|
682
|
+
if (next === full) return;
|
|
683
|
+
full = next;
|
|
684
|
+
onBoxChange();
|
|
171
685
|
}
|
|
172
686
|
function setLabels() {
|
|
173
687
|
const set = (id, key) => {
|
|
@@ -175,6 +689,10 @@
|
|
|
175
689
|
};
|
|
176
690
|
set("takeover", "takeover");
|
|
177
691
|
set("handback", "handback");
|
|
692
|
+
set("verify-title", "verifyTitle");
|
|
693
|
+
set("verify-body", "verifyBody");
|
|
694
|
+
set("verify-go", "verifyGo");
|
|
695
|
+
set("skeleton-status", "statusConnecting");
|
|
178
696
|
set("allow", "allow");
|
|
179
697
|
set("reconnect", "reconnect");
|
|
180
698
|
set("blocked-label", "blocked");
|
|
@@ -182,16 +700,17 @@
|
|
|
182
700
|
set("handoff-label", "handoff");
|
|
183
701
|
set("handoff-done", "handoffDone");
|
|
184
702
|
set("handoff-cancel", "handoffCancel");
|
|
703
|
+
input.sink.setAttribute("aria-label", text("view"));
|
|
185
704
|
$("lock").setAttribute("aria-label", text("secure"));
|
|
186
705
|
$("lock").setAttribute("title", text("secure"));
|
|
187
706
|
for (const [id, key] of [
|
|
188
707
|
["back", "back"],
|
|
189
708
|
["forward", "forward"],
|
|
190
|
-
["reload", "reload"]
|
|
709
|
+
["reload", "reload"],
|
|
710
|
+
["more", "more"]
|
|
191
711
|
]) {
|
|
192
712
|
$(id).setAttribute("aria-label", text(key));
|
|
193
713
|
$(id).setAttribute("title", text(key));
|
|
194
|
-
$(id).textContent = id === "back" ? "<" : id === "forward" ? ">" : "↻";
|
|
195
714
|
}
|
|
196
715
|
url.setAttribute("aria-label", text("address"));
|
|
197
716
|
view.setAttribute("aria-label", text("view"));
|
|
@@ -201,29 +720,52 @@
|
|
|
201
720
|
function renderStatus() {
|
|
202
721
|
const el = $("status");
|
|
203
722
|
el.setAttribute("data-control", control);
|
|
204
|
-
let
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
723
|
+
let tone = "quiet";
|
|
724
|
+
let icon = "";
|
|
725
|
+
let lead = null;
|
|
726
|
+
let detail = null;
|
|
727
|
+
if (mode === "connecting") lead = "statusConnecting";
|
|
728
|
+
else if (mode === "live" && control === "user") {
|
|
729
|
+
if (interactive()) {
|
|
730
|
+
tone = "user";
|
|
731
|
+
icon = ICONS.hand;
|
|
732
|
+
lead = "statusUser";
|
|
733
|
+
detail = "statusUserDetail";
|
|
734
|
+
} else lead = "statusUserElsewhere";
|
|
735
|
+
} else if (mode === "live") {
|
|
736
|
+
tone = "agent";
|
|
737
|
+
const loading = lastState?.loading === true;
|
|
738
|
+
icon = loading ? ICONS.spin : ICONS.dot;
|
|
739
|
+
lead = "statusAgent";
|
|
740
|
+
if (loading) detail = "statusLoading";
|
|
208
741
|
}
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
el.textContent = text(key);
|
|
742
|
+
el.setAttribute("data-tone", tone);
|
|
743
|
+
$("status-icon").innerHTML = icon;
|
|
744
|
+
$("status-lead").textContent = lead === null ? "" : text(lead);
|
|
745
|
+
$("status-detail").textContent = detail === null ? "" : ` · ${text(detail)}`;
|
|
214
746
|
}
|
|
215
747
|
function renderChrome() {
|
|
216
748
|
const watchOnly = compact();
|
|
749
|
+
const readOnly = !interactive();
|
|
217
750
|
const isLive = mode === "live";
|
|
218
751
|
$("takeover").hidden = watchOnly || !isLive || control === "user";
|
|
219
752
|
$("handback").hidden = watchOnly || !isLive || control !== "user";
|
|
753
|
+
$("takeover").toggleAttribute("data-gone", watchOnly || isLive && control === "user");
|
|
754
|
+
const verifying = isLive && control === "agent" && tabs.find((x) => x.active)?.blocker?.kind === "verification" && !watchOnly;
|
|
755
|
+
$("verify").hidden = !verifying;
|
|
756
|
+
$("takeover").className = verifying ? "secondary" : "primary";
|
|
757
|
+
$("handoff").hidden = pendingHandoff === null || verifying;
|
|
758
|
+
$("status").hidden = verifying || pendingHandoff !== null;
|
|
759
|
+
$("stage").setAttribute("data-control", isLive ? control : "agent");
|
|
760
|
+
$("field").toggleAttribute("data-edit", interactive());
|
|
220
761
|
for (const id of ["back", "forward", "reload"])
|
|
221
|
-
$(id).disabled =
|
|
222
|
-
|
|
223
|
-
|
|
762
|
+
$(id).disabled = readOnly;
|
|
763
|
+
$("more").disabled = readOnly;
|
|
764
|
+
$("tabsbtn").disabled = readOnly;
|
|
765
|
+
url.readOnly = readOnly;
|
|
766
|
+
input.sync();
|
|
224
767
|
$("lock").hidden = !isLive || lastState?.secure !== true;
|
|
225
768
|
const showEmpty = mode === "empty" || mode === "offline" || mode === "error";
|
|
226
|
-
$("empty").hidden = !showEmpty;
|
|
227
769
|
$("reconnect").hidden = !showEmpty;
|
|
228
770
|
const keys = {
|
|
229
771
|
empty: ["emptyTitle", "emptyBody"],
|
|
@@ -238,27 +780,46 @@
|
|
|
238
780
|
$("blocked").hidden = blockedHost === "";
|
|
239
781
|
$("blocked-host").textContent = blockedHost;
|
|
240
782
|
renderStatus();
|
|
783
|
+
renderLoading();
|
|
784
|
+
}
|
|
785
|
+
function renderLoading() {
|
|
786
|
+
const idleMode = mode === "empty" || mode === "offline" || mode === "error";
|
|
787
|
+
let next;
|
|
788
|
+
if (idleMode) next = "idle";
|
|
789
|
+
else if (mode === "live" && image !== null) next = "app";
|
|
790
|
+
else if (mode === "live" && shown === "idle") next = "idle";
|
|
791
|
+
else next = "skeleton";
|
|
792
|
+
shown = next;
|
|
793
|
+
$("app").toggleAttribute("data-loading", next === "skeleton");
|
|
794
|
+
$("app").toggleAttribute("data-idle", next === "idle");
|
|
795
|
+
$("skeleton").hidden = next !== "skeleton";
|
|
796
|
+
$("empty").hidden = next !== "idle";
|
|
797
|
+
if (next === "app") onBoxChange();
|
|
241
798
|
}
|
|
242
799
|
function renderTabs() {
|
|
243
800
|
const box = $("tabs");
|
|
244
801
|
box.textContent = "";
|
|
245
|
-
const watchOnly =
|
|
802
|
+
const watchOnly = !interactive();
|
|
246
803
|
for (const tab of tabs) {
|
|
247
804
|
const el = doc.createElement("div");
|
|
248
805
|
el.className = "tab";
|
|
249
806
|
el.setAttribute("role", "tab");
|
|
250
807
|
el.setAttribute("data-active", String(tab.active));
|
|
808
|
+
el.setAttribute("aria-selected", String(tab.active));
|
|
809
|
+
el.appendChild(favOf(tab));
|
|
251
810
|
const label = doc.createElement("button");
|
|
252
811
|
label.type = "button";
|
|
253
812
|
label.className = "label";
|
|
254
|
-
label.textContent = tab
|
|
813
|
+
label.textContent = tabName(tab);
|
|
814
|
+
label.title = tabName(tab);
|
|
255
815
|
label.disabled = watchOnly;
|
|
256
816
|
label.addEventListener("click", () => send({ t: "tab", action: "switch", tabId: tab.id }));
|
|
257
817
|
el.appendChild(label);
|
|
258
|
-
if (!watchOnly) {
|
|
818
|
+
if (!watchOnly && tab.active && control === "user") {
|
|
259
819
|
const close = doc.createElement("button");
|
|
260
820
|
close.type = "button";
|
|
261
|
-
close.
|
|
821
|
+
close.className = "x";
|
|
822
|
+
close.innerHTML = ICONS.close;
|
|
262
823
|
close.setAttribute("aria-label", text("closeTab"));
|
|
263
824
|
close.addEventListener("click", () => send({ t: "tab", action: "close", tabId: tab.id }));
|
|
264
825
|
el.appendChild(close);
|
|
@@ -268,11 +829,79 @@
|
|
|
268
829
|
if (!watchOnly) {
|
|
269
830
|
const add = doc.createElement("button");
|
|
270
831
|
add.type = "button";
|
|
271
|
-
add.
|
|
832
|
+
add.className = "add";
|
|
833
|
+
add.innerHTML = ICONS.plus;
|
|
272
834
|
add.setAttribute("aria-label", text("newTab"));
|
|
273
835
|
add.addEventListener("click", () => send({ t: "tab", action: "open" }));
|
|
274
836
|
box.appendChild(add);
|
|
275
837
|
}
|
|
838
|
+
const active = tabs.find((x) => x.active);
|
|
839
|
+
$("tabsbtn").querySelector(".fav")?.replaceWith(favOf(active));
|
|
840
|
+
$("tabsbtn-name").textContent = active === void 0 ? "" : hostOf(active.url) || tabName(active);
|
|
841
|
+
$("tabsbtn-count").textContent = String(tabs.length);
|
|
842
|
+
$("tabsbtn").setAttribute("aria-label", `${text("tabs")}: ${tabs.length}`);
|
|
843
|
+
}
|
|
844
|
+
const tabName = (tab) => tab.title === "" ? tab.url : tab.title;
|
|
845
|
+
function favOf(tab) {
|
|
846
|
+
if (tab !== void 0 && isIconDataUrl(tab.favicon)) {
|
|
847
|
+
const img = doc.createElement("img");
|
|
848
|
+
img.className = "fav";
|
|
849
|
+
img.alt = "";
|
|
850
|
+
img.src = tab.favicon;
|
|
851
|
+
img.addEventListener("error", () => img.replaceWith(favOf(void 0)), { once: true });
|
|
852
|
+
return img;
|
|
853
|
+
}
|
|
854
|
+
const fav = doc.createElement("span");
|
|
855
|
+
fav.className = "fav";
|
|
856
|
+
return fav;
|
|
857
|
+
}
|
|
858
|
+
function hostOf(u) {
|
|
859
|
+
try {
|
|
860
|
+
return new URL(u).host;
|
|
861
|
+
} catch {
|
|
862
|
+
return "";
|
|
863
|
+
}
|
|
864
|
+
}
|
|
865
|
+
function renderUrl(u) {
|
|
866
|
+
let host = u;
|
|
867
|
+
let rest = "";
|
|
868
|
+
try {
|
|
869
|
+
const p = new URL(u);
|
|
870
|
+
if (p.protocol === "http:" || p.protocol === "https:") {
|
|
871
|
+
host = p.host;
|
|
872
|
+
rest = `${p.pathname === "/" ? "" : p.pathname}${p.search}${p.hash}`;
|
|
873
|
+
}
|
|
874
|
+
} catch {
|
|
875
|
+
}
|
|
876
|
+
$("urltext-host").textContent = host;
|
|
877
|
+
$("urltext-path").textContent = rest;
|
|
878
|
+
}
|
|
879
|
+
function openMenu(anchor, items) {
|
|
880
|
+
const menu = $("menu");
|
|
881
|
+
menu.textContent = "";
|
|
882
|
+
for (const it of items) {
|
|
883
|
+
const b = doc.createElement("button");
|
|
884
|
+
b.type = "button";
|
|
885
|
+
b.setAttribute("role", "menuitem");
|
|
886
|
+
b.textContent = it.label;
|
|
887
|
+
if (it.current) b.setAttribute("aria-current", "true");
|
|
888
|
+
b.addEventListener("click", () => {
|
|
889
|
+
closeMenu();
|
|
890
|
+
it.run();
|
|
891
|
+
});
|
|
892
|
+
menu.appendChild(b);
|
|
893
|
+
}
|
|
894
|
+
const r = anchor.getBoundingClientRect();
|
|
895
|
+
menu.style.top = `${Math.round(r.bottom + 4)}px`;
|
|
896
|
+
menu.style.right = `${Math.max(12, Math.round(win.innerWidth - r.right))}px`;
|
|
897
|
+
menu.hidden = false;
|
|
898
|
+
anchor.setAttribute("aria-expanded", "true");
|
|
899
|
+
menu.firstElementChild?.focus();
|
|
900
|
+
}
|
|
901
|
+
function closeMenu() {
|
|
902
|
+
$("menu").hidden = true;
|
|
903
|
+
$("tabsbtn").removeAttribute("aria-expanded");
|
|
904
|
+
$("more").removeAttribute("aria-expanded");
|
|
276
905
|
}
|
|
277
906
|
function applyState(s) {
|
|
278
907
|
lastState = s;
|
|
@@ -282,9 +911,11 @@
|
|
|
282
911
|
tabs = s.tabs;
|
|
283
912
|
const was = control;
|
|
284
913
|
control = s.control;
|
|
285
|
-
if (full && was === "user" && control === "agent")
|
|
914
|
+
if (full && was === "user" && control === "agent") askMode(false);
|
|
915
|
+
if (was === "user" && control === "agent" && pendingNav?.sentOn === sock) pendingNav = null;
|
|
286
916
|
const active = tabs.find((x) => x.active);
|
|
287
917
|
if (doc.activeElement !== url) url.value = active?.url ?? "";
|
|
918
|
+
renderUrl(active?.url ?? "");
|
|
288
919
|
renderTabs();
|
|
289
920
|
renderChrome();
|
|
290
921
|
if (sock !== null) {
|
|
@@ -320,6 +951,7 @@
|
|
|
320
951
|
}
|
|
321
952
|
if (p.sentOn !== sock && sock !== null) {
|
|
322
953
|
p.sentOn = sock;
|
|
954
|
+
if (control !== "user" && !compact()) takeover();
|
|
323
955
|
send({ t: "nav", url: p.url });
|
|
324
956
|
}
|
|
325
957
|
}
|
|
@@ -351,27 +983,18 @@
|
|
|
351
983
|
}
|
|
352
984
|
function layout() {
|
|
353
985
|
const st = stage.getBoundingClientRect();
|
|
354
|
-
const box = letterbox(
|
|
986
|
+
const box = letterbox(
|
|
987
|
+
Math.max(0, Math.floor(st.width) - 2 * STAGE_PAD),
|
|
988
|
+
Math.max(0, Math.floor(st.height) - 2 * STAGE_PAD)
|
|
989
|
+
);
|
|
355
990
|
view.style.width = `${box.w}px`;
|
|
356
991
|
view.style.height = `${box.h}px`;
|
|
357
992
|
const dpr = win.devicePixelRatio || 1;
|
|
358
993
|
const cap = control === "user" || full ? VIEWPORT.width : SIDE_MAX_WIDTH;
|
|
359
|
-
const w = Math.max(1, Math.min(cap, Math.round(box.w * dpr)));
|
|
994
|
+
const w = Math.max(1, Math.min(cap, Math.round(box.w * Math.min(dpr, MAX_DPR))));
|
|
360
995
|
return { w, h: Math.max(1, Math.round(w / ASPECT)) };
|
|
361
996
|
}
|
|
362
|
-
function fitHeight() {
|
|
363
|
-
if (full) return;
|
|
364
|
-
const st = stage.getBoundingClientRect();
|
|
365
|
-
const width = Math.max(0, Math.floor(st.width));
|
|
366
|
-
if (width === 0) return;
|
|
367
|
-
const chrome = Math.max(0, win.innerHeight - Math.max(0, st.height));
|
|
368
|
-
const height = Math.max(MIN_HEIGHT, Math.min(MAX_HEIGHT, Math.ceil(chrome + width / ASPECT)));
|
|
369
|
-
if (height === postedHeight) return;
|
|
370
|
-
postedHeight = height;
|
|
371
|
-
post({ protocol: PROTOCOL, type: "resize", height });
|
|
372
|
-
}
|
|
373
997
|
function onBoxChange() {
|
|
374
|
-
fitHeight();
|
|
375
998
|
if (sock === null || mode !== "live") return;
|
|
376
999
|
const { w, h } = layout();
|
|
377
1000
|
if (sentSize !== `${w}x${h}`) sizeMessage("resize");
|
|
@@ -394,17 +1017,18 @@
|
|
|
394
1017
|
}
|
|
395
1018
|
async function onFrame(m) {
|
|
396
1019
|
try {
|
|
397
|
-
const
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
image = await decode(bytes);
|
|
1020
|
+
const first = image === null;
|
|
1021
|
+
image = await decode(m.jpeg);
|
|
1022
|
+
if (first) renderLoading();
|
|
401
1023
|
draw();
|
|
1024
|
+
input.frame();
|
|
402
1025
|
} catch {
|
|
403
1026
|
}
|
|
404
1027
|
send({ t: "frame-ack", seq: m.seq });
|
|
405
1028
|
}
|
|
406
1029
|
function show(next) {
|
|
407
1030
|
mode = next;
|
|
1031
|
+
if (next === "empty" || next === "offline" || next === "error") image = null;
|
|
408
1032
|
if (next === "empty") {
|
|
409
1033
|
wasLive = false;
|
|
410
1034
|
armEmptyPoll();
|
|
@@ -440,7 +1064,10 @@
|
|
|
440
1064
|
const mine = gen;
|
|
441
1065
|
quiet = lookOnly && mode === "empty";
|
|
442
1066
|
if (quiet) armEmptyPoll();
|
|
443
|
-
else
|
|
1067
|
+
else {
|
|
1068
|
+
image = null;
|
|
1069
|
+
show("connecting");
|
|
1070
|
+
}
|
|
444
1071
|
let ticketUrl;
|
|
445
1072
|
try {
|
|
446
1073
|
const res = await doFetch("stream-ticket", {
|
|
@@ -472,23 +1099,35 @@
|
|
|
472
1099
|
};
|
|
473
1100
|
}
|
|
474
1101
|
async function onMessage(data) {
|
|
475
|
-
let
|
|
476
|
-
if (typeof data === "string")
|
|
477
|
-
else if (data instanceof ArrayBuffer)
|
|
478
|
-
else if (ArrayBuffer.isView(data))
|
|
1102
|
+
let bytes;
|
|
1103
|
+
if (typeof data === "string") bytes = new TextEncoder().encode(data);
|
|
1104
|
+
else if (data instanceof ArrayBuffer) bytes = new Uint8Array(data);
|
|
1105
|
+
else if (ArrayBuffer.isView(data))
|
|
1106
|
+
bytes = new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
|
|
479
1107
|
else if (typeof data.arrayBuffer === "function")
|
|
480
|
-
|
|
1108
|
+
bytes = new Uint8Array(await data.arrayBuffer());
|
|
481
1109
|
else return;
|
|
1110
|
+
retried401 = false;
|
|
1111
|
+
attempts = 0;
|
|
1112
|
+
restartRetries = 0;
|
|
1113
|
+
const frame = decodeFrame(bytes);
|
|
1114
|
+
if (frame !== null) {
|
|
1115
|
+
void onFrame(frame);
|
|
1116
|
+
return;
|
|
1117
|
+
}
|
|
482
1118
|
let msg;
|
|
483
1119
|
try {
|
|
484
|
-
msg = JSON.parse(
|
|
1120
|
+
msg = JSON.parse(new TextDecoder().decode(bytes));
|
|
485
1121
|
} catch {
|
|
486
1122
|
return;
|
|
487
1123
|
}
|
|
488
|
-
retried401 = false;
|
|
489
|
-
attempts = 0;
|
|
490
|
-
restartRetries = 0;
|
|
491
1124
|
switch (msg.t) {
|
|
1125
|
+
case "ping":
|
|
1126
|
+
send({ t: "pong", id: msg.id });
|
|
1127
|
+
break;
|
|
1128
|
+
case "cursor":
|
|
1129
|
+
input.cursor(msg.cursor);
|
|
1130
|
+
break;
|
|
492
1131
|
case "state":
|
|
493
1132
|
mode = "live";
|
|
494
1133
|
wasLive = true;
|
|
@@ -496,9 +1135,6 @@
|
|
|
496
1135
|
emptySince = void 0;
|
|
497
1136
|
applyState(msg);
|
|
498
1137
|
break;
|
|
499
|
-
case "frame":
|
|
500
|
-
void onFrame(msg);
|
|
501
|
-
break;
|
|
502
1138
|
case "blocked":
|
|
503
1139
|
blockedHost = msg.host;
|
|
504
1140
|
blockedUrl = msg.url;
|
|
@@ -542,13 +1178,14 @@
|
|
|
542
1178
|
}
|
|
543
1179
|
function takeover() {
|
|
544
1180
|
send({ t: "takeover" });
|
|
545
|
-
|
|
546
|
-
|
|
1181
|
+
askMode(true);
|
|
1182
|
+
input.focus();
|
|
547
1183
|
renderChrome();
|
|
548
1184
|
}
|
|
549
1185
|
function handback() {
|
|
1186
|
+
pendingNav = null;
|
|
550
1187
|
send({ t: "handback" });
|
|
551
|
-
|
|
1188
|
+
askMode(false);
|
|
552
1189
|
renderChrome();
|
|
553
1190
|
if (pendingHandoff !== null) void answerHandoff(true);
|
|
554
1191
|
}
|
|
@@ -578,6 +1215,7 @@
|
|
|
578
1215
|
blockedHost = "";
|
|
579
1216
|
blockedUrl = "";
|
|
580
1217
|
renderChrome();
|
|
1218
|
+
if (!interactive()) return;
|
|
581
1219
|
if (target === "") {
|
|
582
1220
|
send({ t: "nav", action: "reload" });
|
|
583
1221
|
return;
|
|
@@ -611,27 +1249,31 @@
|
|
|
611
1249
|
return;
|
|
612
1250
|
}
|
|
613
1251
|
}
|
|
614
|
-
function onPointer(kind, e) {
|
|
615
|
-
if (compact()) return;
|
|
616
|
-
if (kind === "move") {
|
|
617
|
-
if (!interactive() || e.timeStamp - lastMove < MOVE_INTERVAL_MS) return;
|
|
618
|
-
lastMove = e.timeStamp;
|
|
619
|
-
}
|
|
620
|
-
const r = view.getBoundingClientRect();
|
|
621
|
-
const p = mapPoint(e.clientX - r.left, e.clientY - r.top, {
|
|
622
|
-
x: 0,
|
|
623
|
-
y: 0,
|
|
624
|
-
w: r.width,
|
|
625
|
-
h: r.height
|
|
626
|
-
});
|
|
627
|
-
send({
|
|
628
|
-
t: "mouse",
|
|
629
|
-
kind,
|
|
630
|
-
...p,
|
|
631
|
-
...kind === "move" ? {} : { button: e.button === 2 ? "right" : "left" }
|
|
632
|
-
});
|
|
633
|
-
}
|
|
634
1252
|
$("takeover").addEventListener("click", takeover);
|
|
1253
|
+
$("verify-go").addEventListener("click", takeover);
|
|
1254
|
+
$("tabsbtn").addEventListener("click", (e) => {
|
|
1255
|
+
if (!interactive()) return;
|
|
1256
|
+
openMenu(e.currentTarget, [
|
|
1257
|
+
...tabs.map((tab) => ({
|
|
1258
|
+
label: tabName(tab),
|
|
1259
|
+
current: tab.active,
|
|
1260
|
+
run: () => send({ t: "tab", action: "switch", tabId: tab.id })
|
|
1261
|
+
})),
|
|
1262
|
+
{ label: text("newTab"), run: () => send({ t: "tab", action: "open" }) }
|
|
1263
|
+
]);
|
|
1264
|
+
});
|
|
1265
|
+
$("more").addEventListener("click", (e) => {
|
|
1266
|
+
openMenu(e.currentTarget, [
|
|
1267
|
+
{ label: text("forward"), run: () => send({ t: "nav", action: "forward" }) },
|
|
1268
|
+
{ label: text("reload"), run: () => send({ t: "nav", action: "reload" }) }
|
|
1269
|
+
]);
|
|
1270
|
+
});
|
|
1271
|
+
doc.addEventListener("mousedown", (e) => {
|
|
1272
|
+
const m = $("menu");
|
|
1273
|
+
if (m.hidden || m.contains(e.target)) return;
|
|
1274
|
+
if (e.target?.closest?.("#tabsbtn, #more")) return;
|
|
1275
|
+
closeMenu();
|
|
1276
|
+
});
|
|
635
1277
|
$("handback").addEventListener("click", handback);
|
|
636
1278
|
$("handoff-done").addEventListener("click", () => void answerHandoff(true));
|
|
637
1279
|
$("handoff-cancel").addEventListener("click", () => void answerHandoff(false));
|
|
@@ -645,45 +1287,17 @@
|
|
|
645
1287
|
$("forward").addEventListener("click", () => send({ t: "nav", action: "forward" }));
|
|
646
1288
|
$("reload").addEventListener("click", () => send({ t: "nav", action: "reload" }));
|
|
647
1289
|
url.addEventListener("keydown", (e) => {
|
|
648
|
-
if (e.key !== "Enter" ||
|
|
1290
|
+
if (e.key !== "Enter" || !interactive() || url.value.trim() === "") return;
|
|
649
1291
|
send({ t: "nav", url: normalizeUrl(url.value) });
|
|
650
|
-
|
|
651
|
-
});
|
|
652
|
-
view.addEventListener("mousedown", (e) => onPointer("down", e));
|
|
653
|
-
view.addEventListener("mouseup", (e) => onPointer("up", e));
|
|
654
|
-
view.addEventListener("mousemove", (e) => onPointer("move", e));
|
|
655
|
-
view.addEventListener("contextmenu", (e) => e.preventDefault());
|
|
656
|
-
view.addEventListener(
|
|
657
|
-
"wheel",
|
|
658
|
-
(e) => {
|
|
659
|
-
if (compact()) return;
|
|
660
|
-
e.preventDefault();
|
|
661
|
-
const r = view.getBoundingClientRect();
|
|
662
|
-
const p = mapPoint(e.clientX - r.left, e.clientY - r.top, {
|
|
663
|
-
x: 0,
|
|
664
|
-
y: 0,
|
|
665
|
-
w: r.width,
|
|
666
|
-
h: r.height
|
|
667
|
-
});
|
|
668
|
-
send({ t: "mouse", kind: "wheel", ...p, dx: e.deltaX, dy: e.deltaY });
|
|
669
|
-
},
|
|
670
|
-
{ passive: false }
|
|
671
|
-
);
|
|
672
|
-
view.addEventListener("keydown", (e) => {
|
|
673
|
-
if (!interactive() || e.key === "Escape" || e.isComposing) return;
|
|
674
|
-
e.preventDefault();
|
|
675
|
-
send({ t: "key", kind: "down", key: e.key, code: e.code });
|
|
676
|
-
});
|
|
677
|
-
view.addEventListener("keyup", (e) => {
|
|
678
|
-
if (!interactive() || e.key === "Escape" || e.isComposing) return;
|
|
679
|
-
e.preventDefault();
|
|
680
|
-
send({ t: "key", kind: "up", key: e.key, code: e.code });
|
|
681
|
-
});
|
|
682
|
-
view.addEventListener("compositionend", (e) => {
|
|
683
|
-
if (interactive() && e.data !== "") send({ t: "key", kind: "char", key: e.data, text: e.data });
|
|
1292
|
+
input.focus();
|
|
684
1293
|
});
|
|
685
1294
|
doc.addEventListener("keydown", (e) => {
|
|
686
|
-
if (e.key
|
|
1295
|
+
if (e.key !== "Escape") return;
|
|
1296
|
+
if (!$("menu").hidden) {
|
|
1297
|
+
closeMenu();
|
|
1298
|
+
return;
|
|
1299
|
+
}
|
|
1300
|
+
if (interactive()) handback();
|
|
687
1301
|
});
|
|
688
1302
|
win.addEventListener("resize", () => {
|
|
689
1303
|
onBoxChange();
|
|
@@ -725,7 +1339,6 @@
|
|
|
725
1339
|
}
|
|
726
1340
|
setLabels();
|
|
727
1341
|
renderChrome();
|
|
728
|
-
fitHeight();
|
|
729
1342
|
win.addEventListener("message", (ev) => {
|
|
730
1343
|
if (ev.source !== win.parent) return;
|
|
731
1344
|
const m = ev.data;
|
|
@@ -736,8 +1349,7 @@
|
|
|
736
1349
|
applyTheme(m.tokens, m.theme);
|
|
737
1350
|
setLabels();
|
|
738
1351
|
renderChrome();
|
|
739
|
-
|
|
740
|
-
fitHeight();
|
|
1352
|
+
doc.body.setAttribute("data-ready", "");
|
|
741
1353
|
if (!started) {
|
|
742
1354
|
started = true;
|
|
743
1355
|
void connect();
|
|
@@ -746,6 +1358,8 @@
|
|
|
746
1358
|
token = m.token;
|
|
747
1359
|
} else if (m.type === "theme") {
|
|
748
1360
|
applyTheme(m.tokens, m.theme);
|
|
1361
|
+
} else if (m.type === "panel-mode" && typeof m.full === "boolean") {
|
|
1362
|
+
hostMode(m.full);
|
|
749
1363
|
}
|
|
750
1364
|
});
|
|
751
1365
|
}
|