@gjermundgaraba/clankermux 0.4.1 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/client/attachment.d.ts +8 -30
- package/dist/client/attachment.js +33 -32
- package/dist/client/client.d.ts +1 -7
- package/dist/client/client.js +20 -50
- package/dist/client/connection.d.ts +0 -18
- package/dist/client/connection.js +0 -17
- package/dist/client/copy.d.ts +3 -20
- package/dist/client/copy.js +22 -44
- package/dist/client/index.d.ts +1 -6
- package/dist/client/index.js +1 -3
- package/dist/client/keyboard.d.ts +1 -27
- package/dist/client/keyboard.js +18 -34
- package/dist/client/listeners.d.ts +10 -0
- package/dist/client/listeners.js +35 -0
- package/dist/client/mount.d.ts +10 -5
- package/dist/client/mount.js +71 -103
- package/dist/client/osc52.d.ts +1 -4
- package/dist/client/osc52.js +31 -23
- package/dist/client/profile.d.ts +0 -6
- package/dist/client/profile.js +0 -6
- package/dist/client/worker.d.ts +16 -10
- package/dist/client/worker.js +201 -301
- package/dist/engine/decoder.d.ts +0 -20
- package/dist/engine/decoder.js +12 -35
- package/dist/engine/index.d.ts +7 -49
- package/dist/engine/index.js +37 -67
- package/dist/engine/keys.d.ts +0 -7
- package/dist/engine/keys.js +9 -15
- package/dist/engine/render.d.ts +21 -17
- package/dist/engine/render.js +67 -37
- package/dist/engine/selection.d.ts +0 -17
- package/dist/engine/selection.js +9 -34
- package/dist/proto/messages.d.ts +800 -475
- package/dist/proto/messages.js +1 -0
- package/dist/renderer/index.d.ts +7 -6
- package/dist/renderer/index.js +73 -54
- package/package.json +1 -5
package/dist/client/mount.js
CHANGED
|
@@ -1,27 +1,8 @@
|
|
|
1
1
|
import { CanvasRenderer } from "../renderer/index.js";
|
|
2
2
|
import { Copier } from "./copy.js";
|
|
3
|
-
import { Typing } from "./keyboard.js";
|
|
3
|
+
import { Typing, composing } from "./keyboard.js";
|
|
4
|
+
import { Listeners } from "./listeners.js";
|
|
4
5
|
import { profileFrom, schemeOf } from "./profile.js";
|
|
5
|
-
/** Listeners of one kind, and the latest value they were told. */
|
|
6
|
-
class Listeners {
|
|
7
|
-
all = new Set();
|
|
8
|
-
latest;
|
|
9
|
-
add(listener) {
|
|
10
|
-
this.all.add(listener);
|
|
11
|
-
if (this.latest)
|
|
12
|
-
listener(this.latest.value);
|
|
13
|
-
return () => void this.all.delete(listener);
|
|
14
|
-
}
|
|
15
|
-
emit(value) {
|
|
16
|
-
this.latest = { value };
|
|
17
|
-
for (const listener of this.all)
|
|
18
|
-
listener(value);
|
|
19
|
-
}
|
|
20
|
-
clear() {
|
|
21
|
-
this.all.clear();
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
/** Cell metrics from the font. */
|
|
25
6
|
function measure(font) {
|
|
26
7
|
const ctx = document.createElement("canvas").getContext("2d");
|
|
27
8
|
ctx.font = font;
|
|
@@ -39,7 +20,9 @@ function measure(font) {
|
|
|
39
20
|
boldItalicFont: `bold italic ${font}`,
|
|
40
21
|
};
|
|
41
22
|
}
|
|
42
|
-
|
|
23
|
+
function isCopyChord(e) {
|
|
24
|
+
return e.ctrlKey && e.shiftKey && !e.altKey && !e.metaKey && e.code === "KeyC";
|
|
25
|
+
}
|
|
43
26
|
export function mountOn(host, id, options) {
|
|
44
27
|
const { canvas, container, colors } = options;
|
|
45
28
|
const light = matchMedia("(prefers-color-scheme: light)");
|
|
@@ -59,10 +42,8 @@ export function mountOn(host, id, options) {
|
|
|
59
42
|
cell_height: Math.round(metrics.cellHeight * dpr()),
|
|
60
43
|
};
|
|
61
44
|
}
|
|
62
|
-
/** The canvas backing store for the grid at the current pixel ratio;
|
|
63
|
-
* the next frame is drawn in full after a change. */
|
|
64
45
|
let grid = { cols: 0, rows: 0, dpr: 0 };
|
|
65
|
-
let
|
|
46
|
+
let backingStoreReset = false;
|
|
66
47
|
function fitCanvas(cols, rows) {
|
|
67
48
|
const scale = dpr();
|
|
68
49
|
if (grid.cols === cols && grid.rows === rows && grid.dpr === scale)
|
|
@@ -74,9 +55,8 @@ export function mountOn(host, id, options) {
|
|
|
74
55
|
canvas.style.height = `${rows * metrics.cellHeight}px`;
|
|
75
56
|
ctx.setTransform(scale, 0, 0, scale, 0, 0);
|
|
76
57
|
ctx.textBaseline = "alphabetic";
|
|
77
|
-
|
|
58
|
+
backingStoreReset = true;
|
|
78
59
|
}
|
|
79
|
-
/** The keyboard layout, when the browser exposes it (Chromium does). */
|
|
80
60
|
const keyboard = { layout: undefined, mac: /Mac|iPhone|iPad/.test(navigator.platform) };
|
|
81
61
|
navigator.keyboard
|
|
82
62
|
?.getLayoutMap()
|
|
@@ -90,31 +70,36 @@ export function mountOn(host, id, options) {
|
|
|
90
70
|
const links = new Listeners();
|
|
91
71
|
const scrolls = new Listeners();
|
|
92
72
|
const statuses = new Listeners();
|
|
93
|
-
const copies = new
|
|
94
|
-
/** The selection's text, for a copy. */
|
|
73
|
+
const copies = new Listeners("isolateErrors");
|
|
95
74
|
let selected;
|
|
96
75
|
const copier = new Copier({
|
|
97
76
|
clipboard: () => navigator.clipboard,
|
|
98
77
|
item: typeof ClipboardItem === "undefined" ? undefined : (text) => new ClipboardItem({ "text/plain": text }),
|
|
99
|
-
|
|
100
|
-
// a listener's throw is elsewhere, and the rest are told.
|
|
101
|
-
report: (copy) => {
|
|
102
|
-
for (const listener of copies) {
|
|
103
|
-
try {
|
|
104
|
-
listener(copy);
|
|
105
|
-
}
|
|
106
|
-
catch (err) {
|
|
107
|
-
queueMicrotask(() => {
|
|
108
|
-
throw err;
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
},
|
|
78
|
+
report: (copy) => copies.emit(copy),
|
|
113
79
|
});
|
|
114
|
-
/** Rows the view is scrolled back, as `onScroll` last reported;
|
|
115
|
-
* undefined before the first frame. */
|
|
116
80
|
let scrolled;
|
|
117
|
-
|
|
81
|
+
const visible = () => document.visibilityState === "visible";
|
|
82
|
+
let pendingFrame;
|
|
83
|
+
let paintRequest = 0;
|
|
84
|
+
const paint = () => {
|
|
85
|
+
paintRequest = 0;
|
|
86
|
+
const frame = pendingFrame;
|
|
87
|
+
pendingFrame = undefined;
|
|
88
|
+
if (!frame || disposed)
|
|
89
|
+
return;
|
|
90
|
+
if (visible()) {
|
|
91
|
+
fitCanvas(frame.cols, frame.rows);
|
|
92
|
+
if (backingStoreReset && !frame.full) {
|
|
93
|
+
send({ type: "repaint" });
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
backingStoreReset = false;
|
|
97
|
+
renderer.draw(frame);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
send({ type: "painted" });
|
|
101
|
+
};
|
|
102
|
+
const receive = (message) => {
|
|
118
103
|
switch (message.type) {
|
|
119
104
|
case "status":
|
|
120
105
|
statuses.emit(message.text);
|
|
@@ -122,25 +107,25 @@ export function mountOn(host, id, options) {
|
|
|
122
107
|
case "link":
|
|
123
108
|
links.emit(message.link);
|
|
124
109
|
break;
|
|
125
|
-
case "frame":
|
|
126
|
-
if (
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
scrolled = total - offset - len;
|
|
131
|
-
scrolls.emit(scrolled);
|
|
132
|
-
}
|
|
133
|
-
fitCanvas(message.frame.cols, message.frame.rows);
|
|
134
|
-
if (fullNext && !message.frame.full) {
|
|
135
|
-
// The backing store was recreated; a partial frame cannot fill it.
|
|
136
|
-
send({ type: "repaint" });
|
|
110
|
+
case "frame":
|
|
111
|
+
if (disposed)
|
|
112
|
+
break;
|
|
113
|
+
if (!visible()) {
|
|
114
|
+
send({ type: "painted" });
|
|
137
115
|
}
|
|
138
116
|
else {
|
|
139
|
-
|
|
140
|
-
|
|
117
|
+
const frame = message.frame;
|
|
118
|
+
if (frame.cursor)
|
|
119
|
+
cursorAt = { x: frame.cursor.x, y: frame.cursor.y };
|
|
120
|
+
const { total, offset, len } = frame.scrollbar;
|
|
121
|
+
if (total - offset - len !== scrolled) {
|
|
122
|
+
scrolled = total - offset - len;
|
|
123
|
+
scrolls.emit(scrolled);
|
|
124
|
+
}
|
|
125
|
+
pendingFrame = frame;
|
|
126
|
+
paintRequest = requestAnimationFrame(paint);
|
|
141
127
|
}
|
|
142
128
|
break;
|
|
143
|
-
}
|
|
144
129
|
case "clipboard":
|
|
145
130
|
copier.write(message.text, "program");
|
|
146
131
|
break;
|
|
@@ -150,9 +135,7 @@ export function mountOn(host, id, options) {
|
|
|
150
135
|
copier.answer(message.copy, message.text);
|
|
151
136
|
break;
|
|
152
137
|
}
|
|
153
|
-
}
|
|
154
|
-
/** Where the input element goes for a composition: the cursor's cell,
|
|
155
|
-
* as the latest frame that had the cursor in view placed it. */
|
|
138
|
+
};
|
|
156
139
|
let cursorAt = { x: 0, y: 0 };
|
|
157
140
|
// An input method composes only into an editable element: a textarea
|
|
158
141
|
// after the canvas takes the focus, invisible but at the cursor so the
|
|
@@ -182,10 +165,7 @@ export function mountOn(host, id, options) {
|
|
|
182
165
|
caretColor: "transparent",
|
|
183
166
|
});
|
|
184
167
|
canvas.after(input);
|
|
185
|
-
/** Moves the input element to the cursor, and shows it while composing. */
|
|
186
168
|
function placeInput(composing) {
|
|
187
|
-
// Its position is against its containing block: a positioned
|
|
188
|
-
// ancestor, or else the document.
|
|
189
169
|
const cell = canvas.getBoundingClientRect();
|
|
190
170
|
const parent = input.offsetParent;
|
|
191
171
|
let left = cell.left + window.scrollX;
|
|
@@ -211,8 +191,6 @@ export function mountOn(host, id, options) {
|
|
|
211
191
|
});
|
|
212
192
|
}
|
|
213
193
|
canvas.addEventListener("focus", () => input.focus({ preventScroll: true }), { signal });
|
|
214
|
-
// Whether the terminal has the keyboard and its window the focus, for
|
|
215
|
-
// `ackOnFocus`.
|
|
216
194
|
let focused = false;
|
|
217
195
|
const watchFocus = () => {
|
|
218
196
|
const now = document.activeElement === input && document.hasFocus();
|
|
@@ -228,9 +206,7 @@ export function mountOn(host, id, options) {
|
|
|
228
206
|
const typing = new Typing(keyboard);
|
|
229
207
|
const typed = (what) => send("text" in what ? { type: "text", text: what.text } : { type: "key", input: what.key });
|
|
230
208
|
input.addEventListener("keydown", (e) => {
|
|
231
|
-
|
|
232
|
-
// without one it is a key.
|
|
233
|
-
if (e.ctrlKey && e.shiftKey && !e.altKey && !e.metaKey && e.code === "KeyC" && selected) {
|
|
209
|
+
if (isCopyChord(e) && selected) {
|
|
234
210
|
copier.write(selected, "keys");
|
|
235
211
|
e.preventDefault();
|
|
236
212
|
return;
|
|
@@ -240,9 +216,7 @@ export function mountOn(host, id, options) {
|
|
|
240
216
|
send({ type: "key", input: key });
|
|
241
217
|
e.preventDefault();
|
|
242
218
|
}
|
|
243
|
-
else if (e
|
|
244
|
-
// At the cursor before the input method opens its window; shown
|
|
245
|
-
// once a composition starts.
|
|
219
|
+
else if (composing(e)) {
|
|
246
220
|
placeInput(false);
|
|
247
221
|
}
|
|
248
222
|
}, { signal });
|
|
@@ -267,7 +241,6 @@ export function mountOn(host, id, options) {
|
|
|
267
241
|
if (what)
|
|
268
242
|
typed(what);
|
|
269
243
|
placeInput(false);
|
|
270
|
-
// Emptied once the composition has left it.
|
|
271
244
|
setTimeout(() => (input.value = ""));
|
|
272
245
|
}, { signal });
|
|
273
246
|
input.addEventListener("input", (e) => {
|
|
@@ -280,7 +253,6 @@ export function mountOn(host, id, options) {
|
|
|
280
253
|
send({ type: "paste", text });
|
|
281
254
|
e.preventDefault();
|
|
282
255
|
}, { signal });
|
|
283
|
-
// The browser's copy (Cmd+C, Ctrl+C in a menu) copies the selection.
|
|
284
256
|
// WebKit offers Copy on an empty textarea only when `beforecopy` is
|
|
285
257
|
// cancelled.
|
|
286
258
|
input.addEventListener("beforecopy", (e) => {
|
|
@@ -292,9 +264,8 @@ export function mountOn(host, id, options) {
|
|
|
292
264
|
return;
|
|
293
265
|
e.clipboardData.setData("text/plain", selected);
|
|
294
266
|
e.preventDefault();
|
|
295
|
-
copier.copied(selected
|
|
267
|
+
copier.copied(selected);
|
|
296
268
|
}, { signal });
|
|
297
|
-
/** The pointer in cells of the grid, fractions included, kept inside it. */
|
|
298
269
|
function cellAt(e) {
|
|
299
270
|
const rect = canvas.getBoundingClientRect();
|
|
300
271
|
const inside = (value, cells) => Math.min(Math.max(value, 0), Math.max(cells - 0.01, 0));
|
|
@@ -303,10 +274,6 @@ export function mountOn(host, id, options) {
|
|
|
303
274
|
y: inside((e.clientY - rect.top) / metrics.cellHeight, grid.rows),
|
|
304
275
|
};
|
|
305
276
|
}
|
|
306
|
-
// Selection: press, drag (once a frame) and release, followed outside
|
|
307
|
-
// the canvas until the button is up. A release the page never saw (the
|
|
308
|
-
// button let go over another window) ends the drag at the next move or
|
|
309
|
-
// press.
|
|
310
277
|
let endDrag;
|
|
311
278
|
canvas.addEventListener("mousedown", (e) => {
|
|
312
279
|
e.preventDefault();
|
|
@@ -345,8 +312,6 @@ export function mountOn(host, id, options) {
|
|
|
345
312
|
window.addEventListener("mousemove", move, { signal });
|
|
346
313
|
window.addEventListener("mouseup", up, { signal });
|
|
347
314
|
}, { signal });
|
|
348
|
-
// The wheel scrolls the history in whole rows; what a trackpad sends in
|
|
349
|
-
// pixels adds up until it makes one. Ctrl+wheel stays the browser's zoom.
|
|
350
315
|
let wheeled = 0;
|
|
351
316
|
canvas.addEventListener("wheel", (e) => {
|
|
352
317
|
if (e.ctrlKey)
|
|
@@ -364,28 +329,32 @@ export function mountOn(host, id, options) {
|
|
|
364
329
|
wheeled -= whole;
|
|
365
330
|
send({ type: "wheel", rows: whole });
|
|
366
331
|
}, { passive: false, signal });
|
|
367
|
-
/** The profile last reported, to tell when it changed. */
|
|
368
332
|
let reported = "";
|
|
369
333
|
const profile = () => {
|
|
370
334
|
const current = profileFrom(colors(), scheme());
|
|
371
335
|
reported = JSON.stringify(current);
|
|
372
336
|
return current;
|
|
373
337
|
};
|
|
374
|
-
|
|
375
|
-
* window has the focus. Only then does the session get its size, so
|
|
376
|
-
* of several clients the one in use sets it. */
|
|
377
|
-
const active = () => document.visibilityState === "visible" && document.hasFocus();
|
|
338
|
+
const active = () => visible() && document.hasFocus();
|
|
378
339
|
const report = () => send({ type: "viewport", size: viewport(), profile: profile(), active: active() });
|
|
379
340
|
const resizes = new ResizeObserver(report);
|
|
380
341
|
resizes.observe(container);
|
|
381
342
|
light.addEventListener("change", report, { signal });
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
343
|
+
const releaseFrameWhileHidden = () => {
|
|
344
|
+
if (visible() || !pendingFrame)
|
|
345
|
+
return;
|
|
346
|
+
cancelAnimationFrame(paintRequest);
|
|
347
|
+
paintRequest = 0;
|
|
348
|
+
pendingFrame = undefined;
|
|
349
|
+
send({ type: "painted" });
|
|
350
|
+
};
|
|
351
|
+
document.addEventListener("visibilitychange", () => {
|
|
352
|
+
send({ type: "visibility", visible: visible() });
|
|
353
|
+
releaseFrameWhileHidden();
|
|
354
|
+
report();
|
|
355
|
+
}, { signal });
|
|
385
356
|
window.addEventListener("focus", report, { signal });
|
|
386
357
|
window.addEventListener("blur", report, { signal });
|
|
387
|
-
// A page pins its scheme (and its colours with it) with an attribute or
|
|
388
|
-
// a class on the canvas or an ancestor, which no event announces.
|
|
389
358
|
const restyles = new MutationObserver(() => {
|
|
390
359
|
if (JSON.stringify(profileFrom(colors(), scheme())) !== reported)
|
|
391
360
|
report();
|
|
@@ -393,8 +362,6 @@ export function mountOn(host, id, options) {
|
|
|
393
362
|
for (let element = canvas; element; element = element.parentElement) {
|
|
394
363
|
restyles.observe(element, { attributes: true });
|
|
395
364
|
}
|
|
396
|
-
// Zoom or a move to another screen changes the pixel ratio: the canvas
|
|
397
|
-
// is refitted on the next frame; the cell size in pixels is re-reported.
|
|
398
365
|
const watchRatio = () => {
|
|
399
366
|
matchMedia(`(resolution: ${dpr()}dppx)`).addEventListener("change", () => {
|
|
400
367
|
send({ type: "repaint" });
|
|
@@ -409,10 +376,11 @@ export function mountOn(host, id, options) {
|
|
|
409
376
|
viewport: viewport(),
|
|
410
377
|
profile: profile(),
|
|
411
378
|
active: active(),
|
|
379
|
+
visible: visible(),
|
|
412
380
|
readOnly: options.readOnly ?? false,
|
|
413
381
|
ackOnFocus: options.ackOnFocus ?? false,
|
|
414
382
|
});
|
|
415
|
-
|
|
383
|
+
const terminal = {
|
|
416
384
|
attach: (session) => send({ type: "attach", session }),
|
|
417
385
|
detach: () => send({ type: "detach" }),
|
|
418
386
|
focus: () => input.focus({ preventScroll: true }),
|
|
@@ -430,7 +398,9 @@ export function mountOn(host, id, options) {
|
|
|
430
398
|
return;
|
|
431
399
|
host.send({ type: "unmount", mount: id });
|
|
432
400
|
disposed = true;
|
|
433
|
-
|
|
401
|
+
cancelAnimationFrame(paintRequest);
|
|
402
|
+
pendingFrame = undefined;
|
|
403
|
+
host.disposed();
|
|
434
404
|
listening.abort();
|
|
435
405
|
resizes.disconnect();
|
|
436
406
|
restyles.disconnect();
|
|
@@ -444,9 +414,7 @@ export function mountOn(host, id, options) {
|
|
|
444
414
|
onLink: (listener) => links.add(listener),
|
|
445
415
|
onScroll: (listener) => scrolls.add(listener),
|
|
446
416
|
onStatus: (listener) => statuses.add(listener),
|
|
447
|
-
onCopy: (listener) =>
|
|
448
|
-
copies.add(listener);
|
|
449
|
-
return () => void copies.delete(listener);
|
|
450
|
-
},
|
|
417
|
+
onCopy: (listener) => copies.add(listener),
|
|
451
418
|
};
|
|
419
|
+
return { terminal, receive };
|
|
452
420
|
}
|
package/dist/client/osc52.d.ts
CHANGED
|
@@ -1,14 +1,11 @@
|
|
|
1
1
|
export interface ClipboardWrite {
|
|
2
|
-
|
|
3
|
-
selection: string;
|
|
2
|
+
toClipboard: boolean;
|
|
4
3
|
text: string;
|
|
5
4
|
}
|
|
6
5
|
export declare class Osc52Scanner {
|
|
7
6
|
private state;
|
|
8
7
|
private payload;
|
|
9
|
-
/** Forgets a sequence in progress: the stream it came from is gone. */
|
|
10
8
|
reset(): void;
|
|
11
|
-
/** Feeds output bytes; returns the clipboard writes they completed. */
|
|
12
9
|
feed(bytes: Uint8Array): ClipboardWrite[];
|
|
13
10
|
private finish;
|
|
14
11
|
}
|
package/dist/client/osc52.js
CHANGED
|
@@ -13,35 +13,34 @@ const ESC = 0x1b;
|
|
|
13
13
|
const BEL = 0x07;
|
|
14
14
|
const CAN = 0x18;
|
|
15
15
|
const SUB = 0x1a;
|
|
16
|
-
/** Longer OSC 52 payloads are abandoned, not buffered. */
|
|
17
16
|
const MAX_OSC = 1 << 20;
|
|
18
17
|
const PREFIX = "52;";
|
|
19
18
|
export class Osc52Scanner {
|
|
20
19
|
state = "text";
|
|
21
20
|
payload = [];
|
|
22
|
-
/** Forgets a sequence in progress: the stream it came from is gone. */
|
|
23
21
|
reset() {
|
|
24
22
|
this.state = "text";
|
|
25
23
|
this.payload = [];
|
|
26
24
|
}
|
|
27
|
-
/** Feeds output bytes; returns the clipboard writes they completed. */
|
|
28
25
|
feed(bytes) {
|
|
29
26
|
const writes = [];
|
|
30
|
-
for (
|
|
27
|
+
for (let at = 0; at < bytes.length; at++) {
|
|
28
|
+
const b = bytes[at];
|
|
31
29
|
switch (this.state) {
|
|
32
30
|
case "text":
|
|
33
|
-
|
|
34
|
-
|
|
31
|
+
at = bytes.indexOf(ESC, at);
|
|
32
|
+
if (at < 0)
|
|
33
|
+
return writes;
|
|
34
|
+
this.state = "esc";
|
|
35
35
|
break;
|
|
36
36
|
case "esc":
|
|
37
|
-
// The payload is empty: every way out of an OSC clears it.
|
|
38
37
|
if (b === 0x5d)
|
|
39
|
-
this.state = "
|
|
38
|
+
this.state = "maybeOsc52";
|
|
40
39
|
else
|
|
41
40
|
this.state = b === ESC ? "esc" : "text";
|
|
42
41
|
break;
|
|
43
|
-
case "
|
|
44
|
-
case "
|
|
42
|
+
case "maybeOsc52":
|
|
43
|
+
case "otherOsc":
|
|
45
44
|
if (b === BEL) {
|
|
46
45
|
this.finish(writes);
|
|
47
46
|
}
|
|
@@ -52,13 +51,15 @@ export class Osc52Scanner {
|
|
|
52
51
|
else if (b === CAN || b === SUB) {
|
|
53
52
|
this.reset();
|
|
54
53
|
}
|
|
55
|
-
else if (this.state === "
|
|
56
|
-
this.payload.
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
this.state = "skip";
|
|
54
|
+
else if (this.state === "maybeOsc52") {
|
|
55
|
+
const length = this.payload.length;
|
|
56
|
+
if ((length < PREFIX.length && b !== PREFIX.charCodeAt(length)) || length === MAX_OSC) {
|
|
57
|
+
this.state = "otherOsc";
|
|
60
58
|
this.payload = [];
|
|
61
59
|
}
|
|
60
|
+
else {
|
|
61
|
+
this.payload.push(b);
|
|
62
|
+
}
|
|
62
63
|
}
|
|
63
64
|
break;
|
|
64
65
|
}
|
|
@@ -66,7 +67,7 @@ export class Osc52Scanner {
|
|
|
66
67
|
return writes;
|
|
67
68
|
}
|
|
68
69
|
finish(writes) {
|
|
69
|
-
const collected = this.state === "
|
|
70
|
+
const collected = this.state === "maybeOsc52";
|
|
70
71
|
const payload = new TextDecoder().decode(Uint8Array.from(this.payload));
|
|
71
72
|
this.reset();
|
|
72
73
|
if (!collected)
|
|
@@ -74,15 +75,22 @@ export class Osc52Scanner {
|
|
|
74
75
|
const match = /^52;([^;]*);(.*)$/s.exec(payload);
|
|
75
76
|
if (!match || match[2] === "?")
|
|
76
77
|
return;
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
// Not base64: ignored, as a terminal would.
|
|
82
|
-
}
|
|
78
|
+
const bytes = base64(match[2]);
|
|
79
|
+
if (bytes === undefined)
|
|
80
|
+
return;
|
|
81
|
+
writes.push({ toClipboard: isClipboardSelection(match[1]), text: new TextDecoder().decode(bytes) });
|
|
83
82
|
}
|
|
84
83
|
}
|
|
84
|
+
function isClipboardSelection(selection) {
|
|
85
|
+
return selection === "" || selection.includes("c");
|
|
86
|
+
}
|
|
85
87
|
function base64(text) {
|
|
86
|
-
|
|
88
|
+
let binary;
|
|
89
|
+
try {
|
|
90
|
+
binary = atob(text.replace(/\s+/g, ""));
|
|
91
|
+
}
|
|
92
|
+
catch {
|
|
93
|
+
return undefined;
|
|
94
|
+
}
|
|
87
95
|
return Uint8Array.from(binary, (c) => c.charCodeAt(0));
|
|
88
96
|
}
|
package/dist/client/profile.d.ts
CHANGED
|
@@ -1,12 +1,6 @@
|
|
|
1
1
|
import type { Profile, Scheme } from "../proto/index.ts";
|
|
2
|
-
/** `#rrggbb` from a CSS colour as a custom property holds it (hex, or
|
|
3
|
-
* `rgb()` when the stylesheet writes it that way); undefined otherwise. */
|
|
4
2
|
export declare function hexColor(value: string): string | undefined;
|
|
5
|
-
/** The scheme of an element whose computed `color-scheme` is
|
|
6
|
-
* `colorScheme`: the one it names when it names one of `light` and
|
|
7
|
-
* `dark`, else (`normal`, or both) the page's preference. */
|
|
8
3
|
export declare function schemeOf(colorScheme: string, prefersLight: boolean): Scheme;
|
|
9
|
-
/** The profile a page with these colours and scheme reports. */
|
|
10
4
|
export declare function profileFrom(colors: {
|
|
11
5
|
fg: string;
|
|
12
6
|
bg: string;
|
package/dist/client/profile.js
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
/** `#rrggbb` from a CSS colour as a custom property holds it (hex, or
|
|
2
|
-
* `rgb()` when the stylesheet writes it that way); undefined otherwise. */
|
|
3
1
|
export function hexColor(value) {
|
|
4
2
|
const text = value.trim();
|
|
5
3
|
const hex = /^#([0-9a-f]{6})$/i.exec(text);
|
|
@@ -14,9 +12,6 @@ export function hexColor(value) {
|
|
|
14
12
|
const channel = (s) => Math.min(255, Number(s)).toString(16).padStart(2, "0");
|
|
15
13
|
return `#${channel(rgb[1])}${channel(rgb[2])}${channel(rgb[3])}`;
|
|
16
14
|
}
|
|
17
|
-
/** The scheme of an element whose computed `color-scheme` is
|
|
18
|
-
* `colorScheme`: the one it names when it names one of `light` and
|
|
19
|
-
* `dark`, else (`normal`, or both) the page's preference. */
|
|
20
15
|
export function schemeOf(colorScheme, prefersLight) {
|
|
21
16
|
const names = colorScheme.split(/\s+/);
|
|
22
17
|
const light = names.includes("light");
|
|
@@ -25,7 +20,6 @@ export function schemeOf(colorScheme, prefersLight) {
|
|
|
25
20
|
return light ? "light" : "dark";
|
|
26
21
|
return prefersLight ? "light" : "dark";
|
|
27
22
|
}
|
|
28
|
-
/** The profile a page with these colours and scheme reports. */
|
|
29
23
|
export function profileFrom(colors, scheme) {
|
|
30
24
|
const profile = { scheme };
|
|
31
25
|
const fg = hexColor(colors.fg);
|
package/dist/client/worker.d.ts
CHANGED
|
@@ -1,11 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
* The engine side of a client: the connection, the attachments and their
|
|
3
|
-
* render state live in a worker; the page draws frames and reports input.
|
|
4
|
-
* One worker serves one `Client` and every terminal mounted from it.
|
|
5
|
-
* Imported as `@gjermundgaraba/clankermux/worker`, so a worker typechecked
|
|
6
|
-
* without the DOM library does not see the page's types.
|
|
7
|
-
*/
|
|
8
|
-
import { type CellPoint, type Frame, type KeyInput } from "../engine/index.ts";
|
|
1
|
+
import { type CellPoint, type PackedFrame, type KeyInput } from "../engine/index.ts";
|
|
9
2
|
import { type ErrorCode, type ErrorMessage, type Event, type Exit, type Peer, type Profile, type Session, type Size } from "../proto/index.ts";
|
|
10
3
|
import { type ErrorKind } from "./connection.ts";
|
|
11
4
|
/** Why the link to the session ended. `closed`: the connection closed
|
|
@@ -57,6 +50,8 @@ export interface MountInit {
|
|
|
57
50
|
viewport: Size;
|
|
58
51
|
profile: Profile;
|
|
59
52
|
active: boolean;
|
|
53
|
+
/** Whether the document is visible, independently of focus. */
|
|
54
|
+
visible: boolean;
|
|
60
55
|
readOnly: boolean;
|
|
61
56
|
ackOnFocus: boolean;
|
|
62
57
|
}
|
|
@@ -155,6 +150,17 @@ export type ToWorker = {
|
|
|
155
150
|
mount: number;
|
|
156
151
|
focused: boolean;
|
|
157
152
|
}
|
|
153
|
+
/** Visibility is independent of focus: visible, unfocused pages still paint. */
|
|
154
|
+
| {
|
|
155
|
+
type: "visibility";
|
|
156
|
+
mount: number;
|
|
157
|
+
visible: boolean;
|
|
158
|
+
}
|
|
159
|
+
/** The page painted its one outstanding frame, or discarded it while hidden. */
|
|
160
|
+
| {
|
|
161
|
+
type: "painted";
|
|
162
|
+
mount: number;
|
|
163
|
+
}
|
|
158
164
|
/** The page lost its drawing: send the whole screen again. */
|
|
159
165
|
| {
|
|
160
166
|
type: "repaint";
|
|
@@ -206,7 +212,7 @@ export type ToPage =
|
|
|
206
212
|
} | {
|
|
207
213
|
type: "frame";
|
|
208
214
|
mount: number;
|
|
209
|
-
frame:
|
|
215
|
+
frame: PackedFrame;
|
|
210
216
|
} | {
|
|
211
217
|
type: "clipboard";
|
|
212
218
|
mount: number;
|
|
@@ -223,7 +229,7 @@ export type ToPage =
|
|
|
223
229
|
};
|
|
224
230
|
/** The worker's end of the page's messages: `self` in a dedicated worker. */
|
|
225
231
|
export interface WorkerPort {
|
|
226
|
-
postMessage(message: ToPage): void;
|
|
232
|
+
postMessage(message: ToPage, options?: StructuredSerializeOptions): void;
|
|
227
233
|
onmessage: ((e: MessageEvent<ToWorker>) => void) | null;
|
|
228
234
|
}
|
|
229
235
|
/** Serves a page's `connect` on `port`: the worker module the page starts
|