@capybara-hq/plugin-browser 0.1.0-rc.3 → 0.1.0-rc.5
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 +110 -18
- package/dist/index.mjs +249 -79
- package/package.json +1 -1
- package/ui/panel.js +758 -118
- package/ui/service/daemon.mjs +1258 -151
package/ui/panel.js
CHANGED
|
@@ -3,6 +3,63 @@
|
|
|
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;
|
|
8
65
|
|
|
@@ -18,11 +75,17 @@
|
|
|
18
75
|
closeTab: "Close tab",
|
|
19
76
|
takeover: "Take over",
|
|
20
77
|
handback: "Hand back to the agent",
|
|
21
|
-
|
|
22
|
-
|
|
78
|
+
statusUser: "You are in control",
|
|
79
|
+
statusUserDetail: "the agent is paused; press Esc to hand back",
|
|
80
|
+
statusAgent: "The agent is working",
|
|
23
81
|
statusUserElsewhere: "You are controlling the browser from another view",
|
|
24
|
-
statusLoading: "
|
|
25
|
-
statusConnecting: "Connecting…",
|
|
82
|
+
statusLoading: "loading the page",
|
|
83
|
+
statusConnecting: "Connecting to the browser…",
|
|
84
|
+
tabs: "Tabs",
|
|
85
|
+
more: "More",
|
|
86
|
+
verifyTitle: "Verification needed",
|
|
87
|
+
verifyBody: "The site asks for a human check. Hand back when you are done; the agent continues from here.",
|
|
88
|
+
verifyGo: "Verify",
|
|
26
89
|
blocked: "Blocked by the network setting:",
|
|
27
90
|
allow: "Allow",
|
|
28
91
|
dialog: "The page shows a dialog:",
|
|
@@ -52,11 +115,17 @@
|
|
|
52
115
|
closeTab: "关闭标签页",
|
|
53
116
|
takeover: "接管",
|
|
54
117
|
handback: "交还智能体",
|
|
55
|
-
|
|
56
|
-
|
|
118
|
+
statusUser: "你正在操作",
|
|
119
|
+
statusUserDetail: "智能体已暂停,按 Esc 交还",
|
|
120
|
+
statusAgent: "智能体正在操作",
|
|
57
121
|
statusUserElsewhere: "你正在另一个视图中控制浏览器",
|
|
58
|
-
statusLoading: "
|
|
59
|
-
statusConnecting: "
|
|
122
|
+
statusLoading: "正在加载页面",
|
|
123
|
+
statusConnecting: "正在连接浏览器…",
|
|
124
|
+
tabs: "标签页",
|
|
125
|
+
more: "更多",
|
|
126
|
+
verifyTitle: "需要你完成验证",
|
|
127
|
+
verifyBody: "网站要求人工验证。完成后交还,智能体从这里继续。",
|
|
128
|
+
verifyGo: "去验证",
|
|
60
129
|
blocked: "被网络设置拦截:",
|
|
61
130
|
allow: "允许",
|
|
62
131
|
dialog: "页面弹出了对话框:",
|
|
@@ -81,13 +150,442 @@
|
|
|
81
150
|
return STRINGS[locale][key];
|
|
82
151
|
}
|
|
83
152
|
|
|
153
|
+
// ui-src/panel/input.ts
|
|
154
|
+
var MOVE_EVERY_MS = 33;
|
|
155
|
+
var PRESS_MAX_MS = 1e3;
|
|
156
|
+
function mountInput(opts) {
|
|
157
|
+
const win = opts.window;
|
|
158
|
+
const doc = win.document;
|
|
159
|
+
const { view, stage, send, interactive } = opts;
|
|
160
|
+
const sink = doc.createElement("textarea");
|
|
161
|
+
sink.id = "input-sink";
|
|
162
|
+
sink.setAttribute("aria-label", opts.label);
|
|
163
|
+
sink.setAttribute("autocomplete", "off");
|
|
164
|
+
sink.setAttribute("autocapitalize", "off");
|
|
165
|
+
sink.setAttribute("autocorrect", "off");
|
|
166
|
+
sink.spellcheck = false;
|
|
167
|
+
sink.tabIndex = -1;
|
|
168
|
+
Object.assign(sink.style, {
|
|
169
|
+
position: "absolute",
|
|
170
|
+
left: "0px",
|
|
171
|
+
top: "0px",
|
|
172
|
+
width: "1px",
|
|
173
|
+
height: "1px",
|
|
174
|
+
padding: "0",
|
|
175
|
+
border: "0",
|
|
176
|
+
margin: "0",
|
|
177
|
+
opacity: "0",
|
|
178
|
+
resize: "none",
|
|
179
|
+
overflow: "hidden",
|
|
180
|
+
pointerEvents: "none",
|
|
181
|
+
whiteSpace: "pre"
|
|
182
|
+
});
|
|
183
|
+
stage.appendChild(sink);
|
|
184
|
+
const press = doc.createElement("div");
|
|
185
|
+
press.id = "press";
|
|
186
|
+
press.hidden = true;
|
|
187
|
+
press.setAttribute("aria-hidden", "true");
|
|
188
|
+
Object.assign(press.style, {
|
|
189
|
+
position: "absolute",
|
|
190
|
+
width: "18px",
|
|
191
|
+
height: "18px",
|
|
192
|
+
margin: "-9px 0 0 -9px",
|
|
193
|
+
borderRadius: "50%",
|
|
194
|
+
border: "2px solid var(--cb-accent, Highlight)",
|
|
195
|
+
pointerEvents: "none"
|
|
196
|
+
});
|
|
197
|
+
stage.appendChild(press);
|
|
198
|
+
let pressTimer;
|
|
199
|
+
let pressReleased = false;
|
|
200
|
+
let cursor = "default";
|
|
201
|
+
let focusWanted = false;
|
|
202
|
+
let held = null;
|
|
203
|
+
const downKeys = /* @__PURE__ */ new Map();
|
|
204
|
+
let lastPointer = { x: 0, y: 0 };
|
|
205
|
+
let moveTimer;
|
|
206
|
+
let nextMove = null;
|
|
207
|
+
const inStage = (clientX, clientY) => {
|
|
208
|
+
const r = stage.getBoundingClientRect();
|
|
209
|
+
return { left: clientX - r.left, top: clientY - r.top };
|
|
210
|
+
};
|
|
211
|
+
function placeSink(clientX, clientY) {
|
|
212
|
+
const p = inStage(clientX, clientY);
|
|
213
|
+
sink.style.left = `${Math.round(p.left)}px`;
|
|
214
|
+
sink.style.top = `${Math.round(p.top)}px`;
|
|
215
|
+
}
|
|
216
|
+
function showPress(clientX, clientY) {
|
|
217
|
+
const p = inStage(clientX, clientY);
|
|
218
|
+
press.style.left = `${Math.round(p.left)}px`;
|
|
219
|
+
press.style.top = `${Math.round(p.top)}px`;
|
|
220
|
+
press.setAttribute("data-state", "down");
|
|
221
|
+
press.hidden = false;
|
|
222
|
+
pressReleased = false;
|
|
223
|
+
if (pressTimer !== void 0) clearTimeout(pressTimer);
|
|
224
|
+
pressTimer = setTimeout(hidePress, PRESS_MAX_MS);
|
|
225
|
+
}
|
|
226
|
+
function hidePress() {
|
|
227
|
+
if (pressTimer !== void 0) clearTimeout(pressTimer);
|
|
228
|
+
pressTimer = void 0;
|
|
229
|
+
press.hidden = true;
|
|
230
|
+
press.removeAttribute("data-state");
|
|
231
|
+
pressReleased = false;
|
|
232
|
+
}
|
|
233
|
+
function applyCursor() {
|
|
234
|
+
view.style.cursor = interactive() ? cursor : "default";
|
|
235
|
+
}
|
|
236
|
+
function queueMove(p) {
|
|
237
|
+
nextMove = p;
|
|
238
|
+
if (moveTimer !== void 0) return;
|
|
239
|
+
flushMove();
|
|
240
|
+
}
|
|
241
|
+
function flushMove() {
|
|
242
|
+
const p = nextMove;
|
|
243
|
+
nextMove = null;
|
|
244
|
+
if (p === null) {
|
|
245
|
+
moveTimer = void 0;
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
248
|
+
if (interactive()) send({ t: "mouse", kind: "move", ...p });
|
|
249
|
+
moveTimer = setTimeout(flushMove, MOVE_EVERY_MS);
|
|
250
|
+
}
|
|
251
|
+
function dropMove() {
|
|
252
|
+
nextMove = null;
|
|
253
|
+
}
|
|
254
|
+
view.addEventListener("mousedown", (e) => {
|
|
255
|
+
if (!interactive()) return;
|
|
256
|
+
e.preventDefault();
|
|
257
|
+
const button = e.button === 2 ? "right" : "left";
|
|
258
|
+
held = button;
|
|
259
|
+
dropMove();
|
|
260
|
+
placeSink(e.clientX, e.clientY);
|
|
261
|
+
sink.focus();
|
|
262
|
+
showPress(e.clientX, e.clientY);
|
|
263
|
+
lastPointer = opts.toPage(e.clientX, e.clientY);
|
|
264
|
+
send({ t: "mouse", kind: "down", ...lastPointer, button });
|
|
265
|
+
});
|
|
266
|
+
const release = (e) => {
|
|
267
|
+
if (held === null) return;
|
|
268
|
+
const button = held;
|
|
269
|
+
held = null;
|
|
270
|
+
if (!interactive()) return;
|
|
271
|
+
dropMove();
|
|
272
|
+
press.setAttribute("data-state", "up");
|
|
273
|
+
pressReleased = true;
|
|
274
|
+
send({ t: "mouse", kind: "up", ...opts.toPage(e.clientX, e.clientY), button });
|
|
275
|
+
};
|
|
276
|
+
win.addEventListener("mouseup", release);
|
|
277
|
+
const moved = (e) => {
|
|
278
|
+
if (!interactive()) return;
|
|
279
|
+
lastPointer = opts.toPage(e.clientX, e.clientY);
|
|
280
|
+
queueMove(lastPointer);
|
|
281
|
+
};
|
|
282
|
+
view.addEventListener("mousemove", moved);
|
|
283
|
+
win.addEventListener("mousemove", (e) => {
|
|
284
|
+
if (held !== null && e.target !== view) moved(e);
|
|
285
|
+
});
|
|
286
|
+
view.addEventListener(
|
|
287
|
+
"wheel",
|
|
288
|
+
(e) => {
|
|
289
|
+
if (!interactive()) return;
|
|
290
|
+
e.preventDefault();
|
|
291
|
+
dropMove();
|
|
292
|
+
send({
|
|
293
|
+
t: "mouse",
|
|
294
|
+
kind: "wheel",
|
|
295
|
+
...opts.toPage(e.clientX, e.clientY),
|
|
296
|
+
dx: e.deltaX,
|
|
297
|
+
dy: e.deltaY
|
|
298
|
+
});
|
|
299
|
+
},
|
|
300
|
+
{ passive: false }
|
|
301
|
+
);
|
|
302
|
+
view.addEventListener("contextmenu", (e) => e.preventDefault());
|
|
303
|
+
const composing = (e) => e.isComposing || e.key === "Process" || e.keyCode === 229;
|
|
304
|
+
const isPasteShortcut = (e) => (e.metaKey || e.ctrlKey) && !e.altKey && e.key.toLowerCase() === "v";
|
|
305
|
+
function sendText(text) {
|
|
306
|
+
if (text === "") return;
|
|
307
|
+
const t2 = clipCodePoints(text, VIEWER_TEXT_MAX_CHARS);
|
|
308
|
+
send({ t: "key", kind: "char", key: t2, text: t2 });
|
|
309
|
+
}
|
|
310
|
+
sink.addEventListener("keydown", (e) => {
|
|
311
|
+
if (!interactive() || e.key === "Escape" || composing(e) || isPasteShortcut(e)) return;
|
|
312
|
+
e.preventDefault();
|
|
313
|
+
downKeys.set(e.key, e.code);
|
|
314
|
+
send({ t: "key", kind: "down", key: e.key, code: e.code });
|
|
315
|
+
});
|
|
316
|
+
sink.addEventListener("keyup", (e) => {
|
|
317
|
+
if (!interactive() || e.key === "Escape" || composing(e) || isPasteShortcut(e)) return;
|
|
318
|
+
e.preventDefault();
|
|
319
|
+
downKeys.delete(e.key);
|
|
320
|
+
send({ t: "key", kind: "up", key: e.key, code: e.code });
|
|
321
|
+
});
|
|
322
|
+
function releaseAll() {
|
|
323
|
+
if (interactive()) {
|
|
324
|
+
for (const [key, code] of downKeys) send({ t: "key", kind: "up", key, code });
|
|
325
|
+
if (held !== null) send({ t: "mouse", kind: "up", ...lastPointer, button: held });
|
|
326
|
+
}
|
|
327
|
+
downKeys.clear();
|
|
328
|
+
held = null;
|
|
329
|
+
}
|
|
330
|
+
win.addEventListener("blur", releaseAll);
|
|
331
|
+
sink.addEventListener("blur", releaseAll);
|
|
332
|
+
doc.addEventListener("visibilitychange", () => {
|
|
333
|
+
if (doc.visibilityState === "hidden") releaseAll();
|
|
334
|
+
});
|
|
335
|
+
sink.addEventListener("compositionend", (e) => {
|
|
336
|
+
if (interactive()) sendText(e.data ?? "");
|
|
337
|
+
sink.value = "";
|
|
338
|
+
});
|
|
339
|
+
sink.addEventListener("input", (e) => {
|
|
340
|
+
const ie = e;
|
|
341
|
+
if (ie.isComposing || (ie.inputType ?? "").includes("Composition")) return;
|
|
342
|
+
if (interactive()) sendText(sink.value);
|
|
343
|
+
sink.value = "";
|
|
344
|
+
});
|
|
345
|
+
sink.addEventListener("paste", (e) => {
|
|
346
|
+
e.preventDefault();
|
|
347
|
+
if (!interactive()) return;
|
|
348
|
+
sendText(e.clipboardData?.getData("text/plain") ?? "");
|
|
349
|
+
});
|
|
350
|
+
return {
|
|
351
|
+
sink,
|
|
352
|
+
sync() {
|
|
353
|
+
applyCursor();
|
|
354
|
+
if (!interactive()) {
|
|
355
|
+
held = null;
|
|
356
|
+
downKeys.clear();
|
|
357
|
+
nextMove = null;
|
|
358
|
+
hidePress();
|
|
359
|
+
if (doc.activeElement === sink) sink.blur();
|
|
360
|
+
return;
|
|
361
|
+
}
|
|
362
|
+
if (focusWanted) {
|
|
363
|
+
focusWanted = false;
|
|
364
|
+
sink.focus();
|
|
365
|
+
}
|
|
366
|
+
},
|
|
367
|
+
frame() {
|
|
368
|
+
if (pressReleased) hidePress();
|
|
369
|
+
},
|
|
370
|
+
cursor(value) {
|
|
371
|
+
cursor = toViewerCursor(value);
|
|
372
|
+
applyCursor();
|
|
373
|
+
},
|
|
374
|
+
focus() {
|
|
375
|
+
focusWanted = !interactive();
|
|
376
|
+
sink.focus();
|
|
377
|
+
}
|
|
378
|
+
};
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
// ui-src/panel/page.ts
|
|
382
|
+
var ICONS = {
|
|
383
|
+
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>',
|
|
384
|
+
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>',
|
|
385
|
+
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>',
|
|
386
|
+
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>',
|
|
387
|
+
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>',
|
|
388
|
+
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>',
|
|
389
|
+
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>',
|
|
390
|
+
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>',
|
|
391
|
+
dot: '<svg width="12" height="12" viewBox="0 0 24 24" aria-hidden="true"><circle cx="12" cy="12" r="4" fill="currentColor"/></svg>',
|
|
392
|
+
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>',
|
|
393
|
+
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>'
|
|
394
|
+
};
|
|
395
|
+
var bone = (style) => `<span class="bone" style="${style}"></span>`;
|
|
396
|
+
var PANEL_HTML = `<!doctype html>
|
|
397
|
+
<html lang="en">
|
|
398
|
+
<head>
|
|
399
|
+
<meta charset="utf-8">
|
|
400
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
401
|
+
<title>Browser</title>
|
|
402
|
+
<style>
|
|
403
|
+
:root {
|
|
404
|
+
color-scheme: light;
|
|
405
|
+
--ground: color-mix(in srgb, var(--cb-ink, #1A1A18) 5%, var(--cb-bg, #FAF9F6));
|
|
406
|
+
--frame-shadow: 0 1px 2px rgba(26,26,24,.06), 0 4px 16px rgba(26,26,24,.06);
|
|
407
|
+
--bone: color-mix(in srgb, var(--cb-ink, #1A1A18) 7%, transparent);
|
|
408
|
+
--radius: 6px;
|
|
409
|
+
}
|
|
410
|
+
:root[data-theme="dark"] {
|
|
411
|
+
color-scheme: dark;
|
|
412
|
+
--ground: var(--cb-bg, #0A0A0A);
|
|
413
|
+
--frame-shadow: 0 0 0 1px rgba(255,255,255,.08);
|
|
414
|
+
}
|
|
415
|
+
* { box-sizing: border-box; }
|
|
416
|
+
html, body { height: 100%; }
|
|
417
|
+
body {
|
|
418
|
+
margin: 0; position: relative; overflow: hidden;
|
|
419
|
+
background: var(--cb-panel-2, Canvas); color: var(--cb-ink, CanvasText);
|
|
420
|
+
font-family: var(--cb-font, ui-monospace, "SF Mono", Menlo, monospace);
|
|
421
|
+
font-size: var(--cb-type-body-size, 13px); line-height: var(--cb-type-body-line, 20px);
|
|
422
|
+
}
|
|
423
|
+
/* nothing before the host's tokens and language (init) */
|
|
424
|
+
body:not([data-ready]) { visibility: hidden; }
|
|
425
|
+
[hidden] { display: none !important; }
|
|
426
|
+
button, input { font: inherit; color: inherit; margin: 0; }
|
|
427
|
+
button {
|
|
428
|
+
display: inline-grid; place-items: center; flex: none; height: 28px; min-width: 28px;
|
|
429
|
+
padding: 0; border: 0; border-radius: var(--radius); background: transparent; cursor: pointer;
|
|
430
|
+
white-space: nowrap;
|
|
431
|
+
}
|
|
432
|
+
button:hover:not(:disabled) { background: var(--cb-hover, rgba(26,26,24,.04)); }
|
|
433
|
+
button:disabled { color: var(--cb-disabled, GrayText); cursor: default; }
|
|
434
|
+
button:focus-visible, input:focus-visible { outline: 2px solid var(--cb-focus-ring, Highlight); outline-offset: 1px; }
|
|
435
|
+
.primary, .secondary, .outline { padding: 0 14px; font-weight: 600; }
|
|
436
|
+
.primary { background: var(--cb-accent, #CC4609); color: var(--cb-on-accent, #fff); }
|
|
437
|
+
.primary:hover:not(:disabled) { background: var(--cb-accent-hover, var(--cb-accent, #CC4609)); }
|
|
438
|
+
.secondary { font-weight: 400; box-shadow: inset 0 0 0 1px var(--cb-line, #D9D8D2); }
|
|
439
|
+
.outline { padding: 0 12px; color: var(--cb-accent, #CC4609); box-shadow: inset 0 0 0 1px var(--cb-accent, #CC4609); }
|
|
440
|
+
|
|
441
|
+
.layer { position: absolute; inset: 0; display: flex; flex-direction: column; }
|
|
442
|
+
#app[data-loading] { visibility: hidden; }
|
|
443
|
+
.row { flex: none; display: flex; align-items: center; padding: 0 12px; }
|
|
444
|
+
|
|
445
|
+
/* tab strip */
|
|
446
|
+
#tabs { height: 32px; align-items: stretch; gap: 2px; overflow-x: auto; scrollbar-width: none; }
|
|
447
|
+
.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); }
|
|
448
|
+
.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; }
|
|
449
|
+
.fav { width: 14px; height: 14px; border-radius: 3px; flex: none; background: var(--cb-line-soft, #E8E7E2); }
|
|
450
|
+
.tab[data-active="true"] .fav { background: var(--cb-line, #D9D8D2); }
|
|
451
|
+
.tab .label { flex: 1; min-width: 0; display: block; height: auto; text-align: left; overflow: hidden; text-overflow: ellipsis; font-weight: inherit; }
|
|
452
|
+
.tab .label:hover:not(:disabled) { background: transparent; }
|
|
453
|
+
.tab .label:disabled { color: inherit; }
|
|
454
|
+
.tab .x { width: 20px; min-width: 20px; height: 20px; border-radius: 4px; color: var(--cb-muted, #5E5E5A); }
|
|
455
|
+
#tabs .add { align-self: center; color: var(--cb-muted, #5E5E5A); }
|
|
456
|
+
|
|
457
|
+
/* toolbar */
|
|
458
|
+
#bar { height: 44px; gap: 4px; }
|
|
459
|
+
#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)); }
|
|
460
|
+
#field[data-edit] { background: var(--cb-panel, #fff); box-shadow: inset 0 0 0 1px var(--cb-line, #D9D8D2); }
|
|
461
|
+
#lock { display: inline-flex; flex: none; margin-left: 10px; color: var(--cb-muted, #5E5E5A); }
|
|
462
|
+
#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; }
|
|
463
|
+
#lock[hidden] + #url, #lock[hidden] ~ #urltext { padding-left: 10px; }
|
|
464
|
+
#url:focus { color: var(--cb-ink, #1A1A18); }
|
|
465
|
+
#urltext { position: absolute; inset: 0 10px 0 26px; display: flex; align-items: center; pointer-events: none; white-space: nowrap; overflow: hidden; }
|
|
466
|
+
#lock[hidden] ~ #urltext { left: 10px; padding-left: 0; }
|
|
467
|
+
#urltext span:first-child { flex: none; max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
|
|
468
|
+
#urltext span:last-child { color: var(--cb-muted, #5E5E5A); overflow: hidden; text-overflow: ellipsis; }
|
|
469
|
+
#url:focus ~ #urltext { visibility: hidden; }
|
|
470
|
+
#takeover, #handback { margin-left: 4px; }
|
|
471
|
+
/* the takeover slot is always reserved: gone only when hand back takes its place */
|
|
472
|
+
#takeover[hidden]:not([data-gone]) { display: inline-grid !important; visibility: hidden; }
|
|
473
|
+
#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; }
|
|
474
|
+
#tabsbtn .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
|
|
475
|
+
#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); }
|
|
476
|
+
#tabsbtn, #more { display: none; }
|
|
477
|
+
@media (max-width: 440px) {
|
|
478
|
+
#tabs, #forward, #reload, #field { display: none; }
|
|
479
|
+
#tabsbtn { display: flex; }
|
|
480
|
+
#more { display: inline-grid; color: var(--cb-muted, #5E5E5A); }
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
/* status line: one fixed-height line */
|
|
484
|
+
#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; }
|
|
485
|
+
#status .ico { display: inline-flex; flex: none; }
|
|
486
|
+
#status .lead { flex: none; }
|
|
487
|
+
#status .detail { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
|
|
488
|
+
#status[data-tone="agent"] .ico, #status[data-tone="agent"] .lead { color: var(--cb-accent, #CC4609); }
|
|
489
|
+
#status[data-tone="user"] .ico, #status[data-tone="user"] .lead { color: var(--cb-ink, #1A1A18); }
|
|
490
|
+
.spin { animation: spin 1s linear infinite; }
|
|
491
|
+
@keyframes spin { to { transform: rotate(360deg); } }
|
|
492
|
+
|
|
493
|
+
/* needs the person: a warn strip in the status line's place */
|
|
494
|
+
.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); }
|
|
495
|
+
.warn > .ico { display: inline-flex; flex: none; color: var(--cb-warn, #8F6500); }
|
|
496
|
+
.warn .text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
|
|
497
|
+
.warn .title { color: var(--cb-warn, #8F6500); font-weight: 500; overflow-wrap: anywhere; }
|
|
498
|
+
.warn .body { font-family: var(--cb-font-prose, system-ui, sans-serif); color: var(--cb-muted, #5E5E5A); overflow-wrap: anywhere; }
|
|
499
|
+
.warn .actions { display: flex; gap: 6px; flex: none; }
|
|
500
|
+
|
|
501
|
+
/* the picture, contained and centred on a neutral ground */
|
|
502
|
+
#stage { flex: 1; min-height: 0; position: relative; display: flex; align-items: center; justify-content: center; padding: 12px; overflow: hidden; background: var(--ground); }
|
|
503
|
+
#view { display: block; flex: none; border-radius: var(--radius); background: #fff; box-shadow: var(--frame-shadow); outline: none; }
|
|
504
|
+
#stage[data-control="user"] #view { box-shadow: 0 0 0 2px var(--cb-accent, #CC4609), 0 4px 16px rgba(26,26,24,.08); }
|
|
505
|
+
#view:focus-visible { box-shadow: 0 0 0 2px var(--cb-focus-ring, Highlight), var(--frame-shadow); }
|
|
506
|
+
#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; }
|
|
507
|
+
.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(--cb-panel-2, Canvas); }
|
|
508
|
+
.center h2 { margin: 0; font-size: inherit; font-weight: 600; }
|
|
509
|
+
.center p { margin: 0; font-family: var(--cb-font-prose, system-ui, sans-serif); color: var(--cb-muted, #5E5E5A); }
|
|
510
|
+
.center button { margin-top: 6px; }
|
|
511
|
+
/* short-lived notices float over the picture's bottom edge: they never move it */
|
|
512
|
+
#strips { position: absolute; left: 12px; right: 12px; bottom: 12px; display: flex; flex-direction: column; gap: 6px; pointer-events: none; }
|
|
513
|
+
.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); }
|
|
514
|
+
.strip p { flex: 1; min-width: 0; margin: 0; overflow-wrap: anywhere; }
|
|
515
|
+
.strip .label { color: var(--cb-muted, #5E5E5A); }
|
|
516
|
+
.strip:not(:has(button)) { padding-right: 12px; }
|
|
517
|
+
|
|
518
|
+
/* menus (narrow: tabs, more) */
|
|
519
|
+
.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); }
|
|
520
|
+
.menu button { display: flex; width: 100%; justify-content: flex-start; gap: 8px; padding: 0 8px; text-align: left; overflow: hidden; text-overflow: ellipsis; }
|
|
521
|
+
.menu button[aria-current="true"] { font-weight: 600; }
|
|
522
|
+
|
|
523
|
+
/* the skeleton: the panel's own shape, quietly pulsing */
|
|
524
|
+
.bone { display: block; flex: none; border-radius: 2px; background: var(--bone); animation: pulse 1.6s ease-in-out infinite; }
|
|
525
|
+
@keyframes pulse { 50% { opacity: .5; } }
|
|
526
|
+
#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); }
|
|
527
|
+
:root[data-theme="dark"] #skeleton .shot { background: var(--cb-raised, #141413); box-shadow: var(--frame-shadow); }
|
|
528
|
+
#skeleton .narrow { display: none; }
|
|
529
|
+
@media (max-width: 440px) {
|
|
530
|
+
#skeleton .wide { display: none; }
|
|
531
|
+
#skeleton .narrow { display: block; }
|
|
532
|
+
}
|
|
533
|
+
@media (prefers-reduced-motion: reduce) { .bone, .spin { animation: none; } }
|
|
534
|
+
</style>
|
|
535
|
+
</head>
|
|
536
|
+
<body>
|
|
537
|
+
<div id="skeleton" class="layer" aria-busy="true">
|
|
538
|
+
<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>
|
|
539
|
+
<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>
|
|
540
|
+
<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>
|
|
541
|
+
<div style="flex:1;min-height:0;display:flex;align-items:center;justify-content:center;padding:12px;background:var(--ground)">
|
|
542
|
+
<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>
|
|
543
|
+
</div>
|
|
544
|
+
</div>
|
|
545
|
+
<div id="app" class="layer" data-loading>
|
|
546
|
+
<div id="tabs" class="row" role="tablist"></div>
|
|
547
|
+
<div id="bar" class="row">
|
|
548
|
+
<button type="button" id="back">${ICONS.back}</button>
|
|
549
|
+
<button type="button" id="forward">${ICONS.forward}</button>
|
|
550
|
+
<button type="button" id="reload">${ICONS.reload}</button>
|
|
551
|
+
<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>
|
|
552
|
+
<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>
|
|
553
|
+
<button type="button" id="more" aria-haspopup="menu">${ICONS.more}</button>
|
|
554
|
+
<button type="button" id="takeover" class="primary" hidden></button>
|
|
555
|
+
<button type="button" id="handback" class="outline" hidden></button>
|
|
556
|
+
</div>
|
|
557
|
+
<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>
|
|
558
|
+
<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>
|
|
559
|
+
<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>
|
|
560
|
+
<div id="stage">
|
|
561
|
+
<canvas id="view" tabindex="0"></canvas>
|
|
562
|
+
<div id="flash" hidden></div>
|
|
563
|
+
<div id="empty" class="center" hidden>
|
|
564
|
+
<h2 id="empty-title"></h2>
|
|
565
|
+
<p id="empty-body"></p>
|
|
566
|
+
<button type="button" id="reconnect" class="secondary"></button>
|
|
567
|
+
</div>
|
|
568
|
+
<div id="strips">
|
|
569
|
+
<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>
|
|
570
|
+
<div id="dialog" class="strip" hidden><p><span id="dialog-label" class="label"></span> <span id="dialog-text"></span></p></div>
|
|
571
|
+
<div id="notice" class="strip" role="alert" hidden><p><span id="notice-text"></span></p></div>
|
|
572
|
+
</div>
|
|
573
|
+
</div>
|
|
574
|
+
</div>
|
|
575
|
+
<div id="menu" class="menu" role="menu" hidden></div>
|
|
576
|
+
<script src="panel.js"><\/script>
|
|
577
|
+
</body>
|
|
578
|
+
</html>
|
|
579
|
+
`;
|
|
580
|
+
|
|
84
581
|
// ui-src/panel/panel.ts
|
|
85
582
|
var PROTOCOL = "capybara-embed/1";
|
|
86
583
|
var ASPECT = VIEWPORT.width / VIEWPORT.height;
|
|
87
584
|
var SIDE_MAX_WIDTH = 640;
|
|
585
|
+
var MAX_DPR = 1.25;
|
|
586
|
+
var STAGE_PAD = 12;
|
|
88
587
|
var HIDDEN_CLOSE_MS = 6e4;
|
|
89
588
|
var COMPACT_BELOW = 600;
|
|
90
|
-
var MOVE_INTERVAL_MS = 50;
|
|
91
589
|
var RESTART_RETRY_MS = [1e3, 3e3];
|
|
92
590
|
var EMPTY_POLL_MS = 1e4;
|
|
93
591
|
var EMPTY_POLL_FOR_MS = 30 * 6e4;
|
|
@@ -132,6 +630,9 @@
|
|
|
132
630
|
let retried401 = false;
|
|
133
631
|
let attempts = 0;
|
|
134
632
|
let restartRetries = 0;
|
|
633
|
+
let wasLive = false;
|
|
634
|
+
let quiet = false;
|
|
635
|
+
let full = false;
|
|
135
636
|
let retryTimer;
|
|
136
637
|
let emptyTimer;
|
|
137
638
|
let emptySince;
|
|
@@ -146,22 +647,47 @@
|
|
|
146
647
|
let blockedUrl = "";
|
|
147
648
|
let pendingHandoff = null;
|
|
148
649
|
let sentSize = "";
|
|
149
|
-
let lastMove = Number.NEGATIVE_INFINITY;
|
|
150
650
|
let image = null;
|
|
151
|
-
const compact = () =>
|
|
651
|
+
const compact = () => {
|
|
652
|
+
const sw = win.screen?.width ?? 0;
|
|
653
|
+
return sw > 0 && sw < COMPACT_BELOW;
|
|
654
|
+
};
|
|
152
655
|
const text = (key) => t(locale, key);
|
|
153
656
|
const interactive = () => !compact() && control === "user";
|
|
154
657
|
function send(msg) {
|
|
155
658
|
if (sock === null) return;
|
|
156
659
|
sock.send(new TextEncoder().encode(JSON.stringify(msg)));
|
|
157
660
|
}
|
|
158
|
-
const
|
|
661
|
+
const input = mountInput({
|
|
662
|
+
window: win,
|
|
663
|
+
view,
|
|
664
|
+
stage,
|
|
665
|
+
send,
|
|
666
|
+
interactive: () => interactive(),
|
|
667
|
+
toPage: (clientX, clientY) => {
|
|
668
|
+
const r = view.getBoundingClientRect();
|
|
669
|
+
return mapPoint(clientX - r.left, clientY - r.top, { x: 0, y: 0, w: r.width, h: r.height });
|
|
670
|
+
},
|
|
671
|
+
label: t(locale, "view")
|
|
672
|
+
});
|
|
673
|
+
function askMode(next) {
|
|
674
|
+
post({ protocol: PROTOCOL, type: "panel-mode", full: next });
|
|
675
|
+
}
|
|
676
|
+
function hostMode(next) {
|
|
677
|
+
if (next === full) return;
|
|
678
|
+
full = next;
|
|
679
|
+
onBoxChange();
|
|
680
|
+
}
|
|
159
681
|
function setLabels() {
|
|
160
682
|
const set = (id, key) => {
|
|
161
683
|
$(id).textContent = text(key);
|
|
162
684
|
};
|
|
163
685
|
set("takeover", "takeover");
|
|
164
686
|
set("handback", "handback");
|
|
687
|
+
set("verify-title", "verifyTitle");
|
|
688
|
+
set("verify-body", "verifyBody");
|
|
689
|
+
set("verify-go", "verifyGo");
|
|
690
|
+
set("skeleton-status", "statusConnecting");
|
|
165
691
|
set("allow", "allow");
|
|
166
692
|
set("reconnect", "reconnect");
|
|
167
693
|
set("blocked-label", "blocked");
|
|
@@ -169,16 +695,17 @@
|
|
|
169
695
|
set("handoff-label", "handoff");
|
|
170
696
|
set("handoff-done", "handoffDone");
|
|
171
697
|
set("handoff-cancel", "handoffCancel");
|
|
698
|
+
input.sink.setAttribute("aria-label", text("view"));
|
|
172
699
|
$("lock").setAttribute("aria-label", text("secure"));
|
|
173
700
|
$("lock").setAttribute("title", text("secure"));
|
|
174
701
|
for (const [id, key] of [
|
|
175
702
|
["back", "back"],
|
|
176
703
|
["forward", "forward"],
|
|
177
|
-
["reload", "reload"]
|
|
704
|
+
["reload", "reload"],
|
|
705
|
+
["more", "more"]
|
|
178
706
|
]) {
|
|
179
707
|
$(id).setAttribute("aria-label", text(key));
|
|
180
708
|
$(id).setAttribute("title", text(key));
|
|
181
|
-
$(id).textContent = id === "back" ? "<" : id === "forward" ? ">" : "↻";
|
|
182
709
|
}
|
|
183
710
|
url.setAttribute("aria-label", text("address"));
|
|
184
711
|
view.setAttribute("aria-label", text("view"));
|
|
@@ -188,22 +715,50 @@
|
|
|
188
715
|
function renderStatus() {
|
|
189
716
|
const el = $("status");
|
|
190
717
|
el.setAttribute("data-control", control);
|
|
191
|
-
let
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
718
|
+
let tone = "quiet";
|
|
719
|
+
let icon = "";
|
|
720
|
+
let lead = null;
|
|
721
|
+
let detail = null;
|
|
722
|
+
if (mode === "connecting") lead = "statusConnecting";
|
|
723
|
+
else if (mode === "live" && control === "user") {
|
|
724
|
+
if (interactive()) {
|
|
725
|
+
tone = "user";
|
|
726
|
+
icon = ICONS.hand;
|
|
727
|
+
lead = "statusUser";
|
|
728
|
+
detail = "statusUserDetail";
|
|
729
|
+
} else lead = "statusUserElsewhere";
|
|
730
|
+
} else if (mode === "live") {
|
|
731
|
+
tone = "agent";
|
|
732
|
+
const loading = lastState?.loading === true;
|
|
733
|
+
icon = loading ? ICONS.spin : ICONS.dot;
|
|
734
|
+
lead = "statusAgent";
|
|
735
|
+
if (loading) detail = "statusLoading";
|
|
736
|
+
}
|
|
737
|
+
el.setAttribute("data-tone", tone);
|
|
738
|
+
$("status-icon").innerHTML = icon;
|
|
739
|
+
$("status-lead").textContent = lead === null ? "" : text(lead);
|
|
740
|
+
$("status-detail").textContent = detail === null ? "" : ` · ${text(detail)}`;
|
|
197
741
|
}
|
|
198
742
|
function renderChrome() {
|
|
199
743
|
const watchOnly = compact();
|
|
744
|
+
const readOnly = !interactive();
|
|
200
745
|
const isLive = mode === "live";
|
|
201
746
|
$("takeover").hidden = watchOnly || !isLive || control === "user";
|
|
202
747
|
$("handback").hidden = watchOnly || !isLive || control !== "user";
|
|
748
|
+
$("takeover").toggleAttribute("data-gone", watchOnly || isLive && control === "user");
|
|
749
|
+
const verifying = isLive && control === "agent" && tabs.find((x) => x.active)?.blocker?.kind === "verification" && !watchOnly;
|
|
750
|
+
$("verify").hidden = !verifying;
|
|
751
|
+
$("takeover").className = verifying ? "secondary" : "primary";
|
|
752
|
+
$("handoff").hidden = pendingHandoff === null || verifying;
|
|
753
|
+
$("status").hidden = verifying || pendingHandoff !== null;
|
|
754
|
+
$("stage").setAttribute("data-control", isLive ? control : "agent");
|
|
755
|
+
$("field").toggleAttribute("data-edit", interactive());
|
|
203
756
|
for (const id of ["back", "forward", "reload"])
|
|
204
|
-
$(id).disabled =
|
|
205
|
-
|
|
206
|
-
|
|
757
|
+
$(id).disabled = readOnly;
|
|
758
|
+
$("more").disabled = readOnly;
|
|
759
|
+
$("tabsbtn").disabled = readOnly;
|
|
760
|
+
url.readOnly = readOnly;
|
|
761
|
+
input.sync();
|
|
207
762
|
$("lock").hidden = !isLive || lastState?.secure !== true;
|
|
208
763
|
const showEmpty = mode === "empty" || mode === "offline" || mode === "error";
|
|
209
764
|
$("empty").hidden = !showEmpty;
|
|
@@ -221,27 +776,40 @@
|
|
|
221
776
|
$("blocked").hidden = blockedHost === "";
|
|
222
777
|
$("blocked-host").textContent = blockedHost;
|
|
223
778
|
renderStatus();
|
|
779
|
+
renderLoading();
|
|
780
|
+
}
|
|
781
|
+
function renderLoading() {
|
|
782
|
+
const loading = mode === "connecting" || mode === "live" && image === null;
|
|
783
|
+
$("app").toggleAttribute("data-loading", loading);
|
|
784
|
+
$("skeleton").hidden = !loading;
|
|
785
|
+
if (!loading) onBoxChange();
|
|
224
786
|
}
|
|
225
787
|
function renderTabs() {
|
|
226
788
|
const box = $("tabs");
|
|
227
789
|
box.textContent = "";
|
|
228
|
-
const watchOnly =
|
|
790
|
+
const watchOnly = !interactive();
|
|
229
791
|
for (const tab of tabs) {
|
|
230
792
|
const el = doc.createElement("div");
|
|
231
793
|
el.className = "tab";
|
|
232
794
|
el.setAttribute("role", "tab");
|
|
233
795
|
el.setAttribute("data-active", String(tab.active));
|
|
796
|
+
el.setAttribute("aria-selected", String(tab.active));
|
|
797
|
+
const fav = doc.createElement("span");
|
|
798
|
+
fav.className = "fav";
|
|
799
|
+
el.appendChild(fav);
|
|
234
800
|
const label = doc.createElement("button");
|
|
235
801
|
label.type = "button";
|
|
236
802
|
label.className = "label";
|
|
237
|
-
label.textContent = tab
|
|
803
|
+
label.textContent = tabName(tab);
|
|
804
|
+
label.title = tabName(tab);
|
|
238
805
|
label.disabled = watchOnly;
|
|
239
806
|
label.addEventListener("click", () => send({ t: "tab", action: "switch", tabId: tab.id }));
|
|
240
807
|
el.appendChild(label);
|
|
241
|
-
if (!watchOnly) {
|
|
808
|
+
if (!watchOnly && tab.active && control === "user") {
|
|
242
809
|
const close = doc.createElement("button");
|
|
243
810
|
close.type = "button";
|
|
244
|
-
close.
|
|
811
|
+
close.className = "x";
|
|
812
|
+
close.innerHTML = ICONS.close;
|
|
245
813
|
close.setAttribute("aria-label", text("closeTab"));
|
|
246
814
|
close.addEventListener("click", () => send({ t: "tab", action: "close", tabId: tab.id }));
|
|
247
815
|
el.appendChild(close);
|
|
@@ -251,11 +819,65 @@
|
|
|
251
819
|
if (!watchOnly) {
|
|
252
820
|
const add = doc.createElement("button");
|
|
253
821
|
add.type = "button";
|
|
254
|
-
add.
|
|
822
|
+
add.className = "add";
|
|
823
|
+
add.innerHTML = ICONS.plus;
|
|
255
824
|
add.setAttribute("aria-label", text("newTab"));
|
|
256
825
|
add.addEventListener("click", () => send({ t: "tab", action: "open" }));
|
|
257
826
|
box.appendChild(add);
|
|
258
827
|
}
|
|
828
|
+
const active = tabs.find((x) => x.active);
|
|
829
|
+
$("tabsbtn-name").textContent = active === void 0 ? "" : hostOf(active.url) || tabName(active);
|
|
830
|
+
$("tabsbtn-count").textContent = String(tabs.length);
|
|
831
|
+
$("tabsbtn").setAttribute("aria-label", `${text("tabs")}: ${tabs.length}`);
|
|
832
|
+
}
|
|
833
|
+
const tabName = (tab) => tab.title === "" ? tab.url : tab.title;
|
|
834
|
+
function hostOf(u) {
|
|
835
|
+
try {
|
|
836
|
+
return new URL(u).host;
|
|
837
|
+
} catch {
|
|
838
|
+
return "";
|
|
839
|
+
}
|
|
840
|
+
}
|
|
841
|
+
function renderUrl(u) {
|
|
842
|
+
let host = u;
|
|
843
|
+
let rest = "";
|
|
844
|
+
try {
|
|
845
|
+
const p = new URL(u);
|
|
846
|
+
if (p.protocol === "http:" || p.protocol === "https:") {
|
|
847
|
+
host = p.host;
|
|
848
|
+
rest = `${p.pathname === "/" ? "" : p.pathname}${p.search}${p.hash}`;
|
|
849
|
+
}
|
|
850
|
+
} catch {
|
|
851
|
+
}
|
|
852
|
+
$("urltext-host").textContent = host;
|
|
853
|
+
$("urltext-path").textContent = rest;
|
|
854
|
+
}
|
|
855
|
+
function openMenu(anchor, items) {
|
|
856
|
+
const menu = $("menu");
|
|
857
|
+
menu.textContent = "";
|
|
858
|
+
for (const it of items) {
|
|
859
|
+
const b = doc.createElement("button");
|
|
860
|
+
b.type = "button";
|
|
861
|
+
b.setAttribute("role", "menuitem");
|
|
862
|
+
b.textContent = it.label;
|
|
863
|
+
if (it.current) b.setAttribute("aria-current", "true");
|
|
864
|
+
b.addEventListener("click", () => {
|
|
865
|
+
closeMenu();
|
|
866
|
+
it.run();
|
|
867
|
+
});
|
|
868
|
+
menu.appendChild(b);
|
|
869
|
+
}
|
|
870
|
+
const r = anchor.getBoundingClientRect();
|
|
871
|
+
menu.style.top = `${Math.round(r.bottom + 4)}px`;
|
|
872
|
+
menu.style.right = `${Math.max(12, Math.round(win.innerWidth - r.right))}px`;
|
|
873
|
+
menu.hidden = false;
|
|
874
|
+
anchor.setAttribute("aria-expanded", "true");
|
|
875
|
+
menu.firstElementChild?.focus();
|
|
876
|
+
}
|
|
877
|
+
function closeMenu() {
|
|
878
|
+
$("menu").hidden = true;
|
|
879
|
+
$("tabsbtn").removeAttribute("aria-expanded");
|
|
880
|
+
$("more").removeAttribute("aria-expanded");
|
|
259
881
|
}
|
|
260
882
|
function applyState(s) {
|
|
261
883
|
lastState = s;
|
|
@@ -263,9 +885,13 @@
|
|
|
263
885
|
$("handoff").hidden = pendingHandoff === null;
|
|
264
886
|
$("handoff-message").textContent = pendingHandoff?.message ?? "";
|
|
265
887
|
tabs = s.tabs;
|
|
888
|
+
const was = control;
|
|
266
889
|
control = s.control;
|
|
890
|
+
if (full && was === "user" && control === "agent") askMode(false);
|
|
891
|
+
if (was === "user" && control === "agent" && pendingNav?.sentOn === sock) pendingNav = null;
|
|
267
892
|
const active = tabs.find((x) => x.active);
|
|
268
893
|
if (doc.activeElement !== url) url.value = active?.url ?? "";
|
|
894
|
+
renderUrl(active?.url ?? "");
|
|
269
895
|
renderTabs();
|
|
270
896
|
renderChrome();
|
|
271
897
|
if (sock !== null) {
|
|
@@ -301,6 +927,7 @@
|
|
|
301
927
|
}
|
|
302
928
|
if (p.sentOn !== sock && sock !== null) {
|
|
303
929
|
p.sentOn = sock;
|
|
930
|
+
if (control !== "user" && !compact()) takeover();
|
|
304
931
|
send({ t: "nav", url: p.url });
|
|
305
932
|
}
|
|
306
933
|
}
|
|
@@ -332,14 +959,23 @@
|
|
|
332
959
|
}
|
|
333
960
|
function layout() {
|
|
334
961
|
const st = stage.getBoundingClientRect();
|
|
335
|
-
const box = letterbox(
|
|
962
|
+
const box = letterbox(
|
|
963
|
+
Math.max(0, Math.floor(st.width) - 2 * STAGE_PAD),
|
|
964
|
+
Math.max(0, Math.floor(st.height) - 2 * STAGE_PAD)
|
|
965
|
+
);
|
|
336
966
|
view.style.width = `${box.w}px`;
|
|
337
967
|
view.style.height = `${box.h}px`;
|
|
338
968
|
const dpr = win.devicePixelRatio || 1;
|
|
339
|
-
const cap = control === "user" ? VIEWPORT.width : SIDE_MAX_WIDTH;
|
|
340
|
-
const w = Math.max(1, Math.min(cap, Math.round(box.w * dpr)));
|
|
969
|
+
const cap = control === "user" || full ? VIEWPORT.width : SIDE_MAX_WIDTH;
|
|
970
|
+
const w = Math.max(1, Math.min(cap, Math.round(box.w * Math.min(dpr, MAX_DPR))));
|
|
341
971
|
return { w, h: Math.max(1, Math.round(w / ASPECT)) };
|
|
342
972
|
}
|
|
973
|
+
function onBoxChange() {
|
|
974
|
+
if (sock === null || mode !== "live") return;
|
|
975
|
+
const { w, h } = layout();
|
|
976
|
+
if (sentSize !== `${w}x${h}`) sizeMessage("resize");
|
|
977
|
+
draw();
|
|
978
|
+
}
|
|
343
979
|
function sizeMessage(kind) {
|
|
344
980
|
const { w, h } = layout();
|
|
345
981
|
sentSize = `${w}x${h}`;
|
|
@@ -357,18 +993,21 @@
|
|
|
357
993
|
}
|
|
358
994
|
async function onFrame(m) {
|
|
359
995
|
try {
|
|
360
|
-
const
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
image = await decode(bytes);
|
|
996
|
+
const first = image === null;
|
|
997
|
+
image = await decode(m.jpeg);
|
|
998
|
+
if (first) renderLoading();
|
|
364
999
|
draw();
|
|
1000
|
+
input.frame();
|
|
365
1001
|
} catch {
|
|
366
1002
|
}
|
|
367
1003
|
send({ t: "frame-ack", seq: m.seq });
|
|
368
1004
|
}
|
|
369
1005
|
function show(next) {
|
|
370
1006
|
mode = next;
|
|
371
|
-
if (next === "empty")
|
|
1007
|
+
if (next === "empty") {
|
|
1008
|
+
wasLive = false;
|
|
1009
|
+
armEmptyPoll();
|
|
1010
|
+
}
|
|
372
1011
|
renderChrome();
|
|
373
1012
|
}
|
|
374
1013
|
function armEmptyPoll() {
|
|
@@ -379,7 +1018,7 @@
|
|
|
379
1018
|
if (mode !== "empty" || emptySince === void 0) return;
|
|
380
1019
|
if (Date.now() - emptySince >= EMPTY_POLL_FOR_MS) return;
|
|
381
1020
|
if (doc.visibilityState === "hidden") armEmptyPoll();
|
|
382
|
-
else void connect();
|
|
1021
|
+
else void connect(true);
|
|
383
1022
|
}, EMPTY_POLL_MS);
|
|
384
1023
|
}
|
|
385
1024
|
function stop() {
|
|
@@ -395,10 +1034,15 @@
|
|
|
395
1034
|
s.close();
|
|
396
1035
|
}
|
|
397
1036
|
}
|
|
398
|
-
async function connect() {
|
|
1037
|
+
async function connect(lookOnly = false) {
|
|
399
1038
|
stop();
|
|
400
1039
|
const mine = gen;
|
|
401
|
-
|
|
1040
|
+
quiet = lookOnly && mode === "empty";
|
|
1041
|
+
if (quiet) armEmptyPoll();
|
|
1042
|
+
else {
|
|
1043
|
+
image = null;
|
|
1044
|
+
show("connecting");
|
|
1045
|
+
}
|
|
402
1046
|
let ticketUrl;
|
|
403
1047
|
try {
|
|
404
1048
|
const res = await doFetch("stream-ticket", {
|
|
@@ -411,10 +1055,10 @@
|
|
|
411
1055
|
if (mine !== gen) return;
|
|
412
1056
|
const code = body.code ?? body.error?.code;
|
|
413
1057
|
if (code === "service_not_running") return show("empty");
|
|
414
|
-
if (!res.ok || typeof body.url !== "string") return show("offline");
|
|
1058
|
+
if (!res.ok || typeof body.url !== "string") return show(quiet ? "empty" : "offline");
|
|
415
1059
|
ticketUrl = body.url;
|
|
416
1060
|
} catch {
|
|
417
|
-
if (mine === gen) show("offline");
|
|
1061
|
+
if (mine === gen) show(quiet ? "empty" : "offline");
|
|
418
1062
|
return;
|
|
419
1063
|
}
|
|
420
1064
|
const ws = new SocketCtor(ticketUrl);
|
|
@@ -430,31 +1074,42 @@
|
|
|
430
1074
|
};
|
|
431
1075
|
}
|
|
432
1076
|
async function onMessage(data) {
|
|
433
|
-
let
|
|
434
|
-
if (typeof data === "string")
|
|
435
|
-
else if (data instanceof ArrayBuffer)
|
|
436
|
-
else if (ArrayBuffer.isView(data))
|
|
1077
|
+
let bytes;
|
|
1078
|
+
if (typeof data === "string") bytes = new TextEncoder().encode(data);
|
|
1079
|
+
else if (data instanceof ArrayBuffer) bytes = new Uint8Array(data);
|
|
1080
|
+
else if (ArrayBuffer.isView(data))
|
|
1081
|
+
bytes = new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
|
|
437
1082
|
else if (typeof data.arrayBuffer === "function")
|
|
438
|
-
|
|
1083
|
+
bytes = new Uint8Array(await data.arrayBuffer());
|
|
439
1084
|
else return;
|
|
1085
|
+
retried401 = false;
|
|
1086
|
+
attempts = 0;
|
|
1087
|
+
restartRetries = 0;
|
|
1088
|
+
const frame = decodeFrame(bytes);
|
|
1089
|
+
if (frame !== null) {
|
|
1090
|
+
void onFrame(frame);
|
|
1091
|
+
return;
|
|
1092
|
+
}
|
|
440
1093
|
let msg;
|
|
441
1094
|
try {
|
|
442
|
-
msg = JSON.parse(
|
|
1095
|
+
msg = JSON.parse(new TextDecoder().decode(bytes));
|
|
443
1096
|
} catch {
|
|
444
1097
|
return;
|
|
445
1098
|
}
|
|
446
|
-
retried401 = false;
|
|
447
|
-
attempts = 0;
|
|
448
|
-
restartRetries = 0;
|
|
449
1099
|
switch (msg.t) {
|
|
1100
|
+
case "ping":
|
|
1101
|
+
send({ t: "pong", id: msg.id });
|
|
1102
|
+
break;
|
|
1103
|
+
case "cursor":
|
|
1104
|
+
input.cursor(msg.cursor);
|
|
1105
|
+
break;
|
|
450
1106
|
case "state":
|
|
451
1107
|
mode = "live";
|
|
1108
|
+
wasLive = true;
|
|
1109
|
+
quiet = false;
|
|
452
1110
|
emptySince = void 0;
|
|
453
1111
|
applyState(msg);
|
|
454
1112
|
break;
|
|
455
|
-
case "frame":
|
|
456
|
-
void onFrame(msg);
|
|
457
|
-
break;
|
|
458
1113
|
case "blocked":
|
|
459
1114
|
blockedHost = msg.host;
|
|
460
1115
|
blockedUrl = msg.url;
|
|
@@ -468,11 +1123,15 @@
|
|
|
468
1123
|
function onClose(code) {
|
|
469
1124
|
sock = null;
|
|
470
1125
|
lastState = null;
|
|
1126
|
+
if (quiet && code !== 4401 && code !== 4409 && code !== 1009) {
|
|
1127
|
+
show("empty");
|
|
1128
|
+
return;
|
|
1129
|
+
}
|
|
471
1130
|
if (code === 4401 && !retried401) {
|
|
472
1131
|
retried401 = true;
|
|
473
|
-
void connect();
|
|
1132
|
+
void connect(quiet);
|
|
474
1133
|
} else if (code === 4404) {
|
|
475
|
-
const wait = RESTART_RETRY_MS[restartRetries];
|
|
1134
|
+
const wait = wasLive ? RESTART_RETRY_MS[restartRetries] : void 0;
|
|
476
1135
|
if (wait === void 0) show("empty");
|
|
477
1136
|
else {
|
|
478
1137
|
restartRetries++;
|
|
@@ -494,13 +1153,14 @@
|
|
|
494
1153
|
}
|
|
495
1154
|
function takeover() {
|
|
496
1155
|
send({ t: "takeover" });
|
|
497
|
-
|
|
498
|
-
|
|
1156
|
+
askMode(true);
|
|
1157
|
+
input.focus();
|
|
499
1158
|
renderChrome();
|
|
500
1159
|
}
|
|
501
1160
|
function handback() {
|
|
1161
|
+
pendingNav = null;
|
|
502
1162
|
send({ t: "handback" });
|
|
503
|
-
|
|
1163
|
+
askMode(false);
|
|
504
1164
|
renderChrome();
|
|
505
1165
|
if (pendingHandoff !== null) void answerHandoff(true);
|
|
506
1166
|
}
|
|
@@ -530,6 +1190,7 @@
|
|
|
530
1190
|
blockedHost = "";
|
|
531
1191
|
blockedUrl = "";
|
|
532
1192
|
renderChrome();
|
|
1193
|
+
if (!interactive()) return;
|
|
533
1194
|
if (target === "") {
|
|
534
1195
|
send({ t: "nav", action: "reload" });
|
|
535
1196
|
return;
|
|
@@ -563,27 +1224,31 @@
|
|
|
563
1224
|
return;
|
|
564
1225
|
}
|
|
565
1226
|
}
|
|
566
|
-
function onPointer(kind, e) {
|
|
567
|
-
if (compact()) return;
|
|
568
|
-
if (kind === "move") {
|
|
569
|
-
if (!interactive() || e.timeStamp - lastMove < MOVE_INTERVAL_MS) return;
|
|
570
|
-
lastMove = e.timeStamp;
|
|
571
|
-
}
|
|
572
|
-
const r = view.getBoundingClientRect();
|
|
573
|
-
const p = mapPoint(e.clientX - r.left, e.clientY - r.top, {
|
|
574
|
-
x: 0,
|
|
575
|
-
y: 0,
|
|
576
|
-
w: r.width,
|
|
577
|
-
h: r.height
|
|
578
|
-
});
|
|
579
|
-
send({
|
|
580
|
-
t: "mouse",
|
|
581
|
-
kind,
|
|
582
|
-
...p,
|
|
583
|
-
...kind === "move" ? {} : { button: e.button === 2 ? "right" : "left" }
|
|
584
|
-
});
|
|
585
|
-
}
|
|
586
1227
|
$("takeover").addEventListener("click", takeover);
|
|
1228
|
+
$("verify-go").addEventListener("click", takeover);
|
|
1229
|
+
$("tabsbtn").addEventListener("click", (e) => {
|
|
1230
|
+
if (!interactive()) return;
|
|
1231
|
+
openMenu(e.currentTarget, [
|
|
1232
|
+
...tabs.map((tab) => ({
|
|
1233
|
+
label: tabName(tab),
|
|
1234
|
+
current: tab.active,
|
|
1235
|
+
run: () => send({ t: "tab", action: "switch", tabId: tab.id })
|
|
1236
|
+
})),
|
|
1237
|
+
{ label: text("newTab"), run: () => send({ t: "tab", action: "open" }) }
|
|
1238
|
+
]);
|
|
1239
|
+
});
|
|
1240
|
+
$("more").addEventListener("click", (e) => {
|
|
1241
|
+
openMenu(e.currentTarget, [
|
|
1242
|
+
{ label: text("forward"), run: () => send({ t: "nav", action: "forward" }) },
|
|
1243
|
+
{ label: text("reload"), run: () => send({ t: "nav", action: "reload" }) }
|
|
1244
|
+
]);
|
|
1245
|
+
});
|
|
1246
|
+
doc.addEventListener("mousedown", (e) => {
|
|
1247
|
+
const m = $("menu");
|
|
1248
|
+
if (m.hidden || m.contains(e.target)) return;
|
|
1249
|
+
if (e.target?.closest?.("#tabsbtn, #more")) return;
|
|
1250
|
+
closeMenu();
|
|
1251
|
+
});
|
|
587
1252
|
$("handback").addEventListener("click", handback);
|
|
588
1253
|
$("handoff-done").addEventListener("click", () => void answerHandoff(true));
|
|
589
1254
|
$("handoff-cancel").addEventListener("click", () => void answerHandoff(false));
|
|
@@ -597,54 +1262,26 @@
|
|
|
597
1262
|
$("forward").addEventListener("click", () => send({ t: "nav", action: "forward" }));
|
|
598
1263
|
$("reload").addEventListener("click", () => send({ t: "nav", action: "reload" }));
|
|
599
1264
|
url.addEventListener("keydown", (e) => {
|
|
600
|
-
if (e.key !== "Enter" ||
|
|
1265
|
+
if (e.key !== "Enter" || !interactive() || url.value.trim() === "") return;
|
|
601
1266
|
send({ t: "nav", url: normalizeUrl(url.value) });
|
|
602
|
-
|
|
603
|
-
});
|
|
604
|
-
view.addEventListener("mousedown", (e) => onPointer("down", e));
|
|
605
|
-
view.addEventListener("mouseup", (e) => onPointer("up", e));
|
|
606
|
-
view.addEventListener("mousemove", (e) => onPointer("move", e));
|
|
607
|
-
view.addEventListener("contextmenu", (e) => e.preventDefault());
|
|
608
|
-
view.addEventListener(
|
|
609
|
-
"wheel",
|
|
610
|
-
(e) => {
|
|
611
|
-
if (compact()) return;
|
|
612
|
-
e.preventDefault();
|
|
613
|
-
const r = view.getBoundingClientRect();
|
|
614
|
-
const p = mapPoint(e.clientX - r.left, e.clientY - r.top, {
|
|
615
|
-
x: 0,
|
|
616
|
-
y: 0,
|
|
617
|
-
w: r.width,
|
|
618
|
-
h: r.height
|
|
619
|
-
});
|
|
620
|
-
send({ t: "mouse", kind: "wheel", ...p, dx: e.deltaX, dy: e.deltaY });
|
|
621
|
-
},
|
|
622
|
-
{ passive: false }
|
|
623
|
-
);
|
|
624
|
-
view.addEventListener("keydown", (e) => {
|
|
625
|
-
if (!interactive() || e.key === "Escape" || e.isComposing) return;
|
|
626
|
-
e.preventDefault();
|
|
627
|
-
send({ t: "key", kind: "down", key: e.key, code: e.code });
|
|
628
|
-
});
|
|
629
|
-
view.addEventListener("keyup", (e) => {
|
|
630
|
-
if (!interactive() || e.key === "Escape" || e.isComposing) return;
|
|
631
|
-
e.preventDefault();
|
|
632
|
-
send({ t: "key", kind: "up", key: e.key, code: e.code });
|
|
633
|
-
});
|
|
634
|
-
view.addEventListener("compositionend", (e) => {
|
|
635
|
-
if (interactive() && e.data !== "") send({ t: "key", kind: "char", key: e.data, text: e.data });
|
|
1267
|
+
input.focus();
|
|
636
1268
|
});
|
|
637
1269
|
doc.addEventListener("keydown", (e) => {
|
|
638
|
-
if (e.key
|
|
1270
|
+
if (e.key !== "Escape") return;
|
|
1271
|
+
if (!$("menu").hidden) {
|
|
1272
|
+
closeMenu();
|
|
1273
|
+
return;
|
|
1274
|
+
}
|
|
1275
|
+
if (interactive()) handback();
|
|
639
1276
|
});
|
|
640
1277
|
win.addEventListener("resize", () => {
|
|
1278
|
+
onBoxChange();
|
|
641
1279
|
if (sock === null || mode !== "live") return;
|
|
642
|
-
const { w, h } = layout();
|
|
643
|
-
if (sentSize !== `${w}x${h}`) sizeMessage("resize");
|
|
644
1280
|
renderChrome();
|
|
645
1281
|
renderTabs();
|
|
646
|
-
draw();
|
|
647
1282
|
});
|
|
1283
|
+
const Ro = win.ResizeObserver;
|
|
1284
|
+
if (Ro !== void 0) new Ro(onBoxChange).observe(stage);
|
|
648
1285
|
doc.addEventListener("visibilitychange", () => {
|
|
649
1286
|
if (doc.visibilityState === "hidden") {
|
|
650
1287
|
if (hiddenTimer === void 0) {
|
|
@@ -661,7 +1298,7 @@
|
|
|
661
1298
|
hiddenTimer = void 0;
|
|
662
1299
|
if (pausedForHidden) {
|
|
663
1300
|
pausedForHidden = false;
|
|
664
|
-
void connect();
|
|
1301
|
+
void connect(true);
|
|
665
1302
|
}
|
|
666
1303
|
}
|
|
667
1304
|
});
|
|
@@ -687,6 +1324,7 @@
|
|
|
687
1324
|
applyTheme(m.tokens, m.theme);
|
|
688
1325
|
setLabels();
|
|
689
1326
|
renderChrome();
|
|
1327
|
+
doc.body.setAttribute("data-ready", "");
|
|
690
1328
|
if (!started) {
|
|
691
1329
|
started = true;
|
|
692
1330
|
void connect();
|
|
@@ -695,6 +1333,8 @@
|
|
|
695
1333
|
token = m.token;
|
|
696
1334
|
} else if (m.type === "theme") {
|
|
697
1335
|
applyTheme(m.tokens, m.theme);
|
|
1336
|
+
} else if (m.type === "panel-mode" && typeof m.full === "boolean") {
|
|
1337
|
+
hostMode(m.full);
|
|
698
1338
|
}
|
|
699
1339
|
});
|
|
700
1340
|
}
|