@gjermundgaraba/clankermux 0.5.0 → 0.7.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 +9 -29
- package/dist/client/attachment.js +28 -41
- package/dist/client/client.d.ts +0 -2
- package/dist/client/client.js +6 -11
- package/dist/client/connection.d.ts +1 -19
- package/dist/client/connection.js +0 -17
- package/dist/client/copy.d.ts +0 -14
- package/dist/client/copy.js +4 -25
- package/dist/client/keyboard.d.ts +1 -27
- package/dist/client/keyboard.js +18 -34
- package/dist/client/link.d.ts +143 -0
- package/dist/client/link.js +205 -0
- package/dist/client/listeners.d.ts +3 -1
- package/dist/client/listeners.js +20 -4
- package/dist/client/mount.d.ts +0 -5
- package/dist/client/mount.js +20 -72
- package/dist/client/osc52.d.ts +1 -4
- package/dist/client/osc52.js +20 -17
- package/dist/client/profile.d.ts +0 -6
- package/dist/client/profile.js +0 -6
- package/dist/client/worker.d.ts +3 -44
- package/dist/client/worker.js +185 -332
- package/dist/engine/decoder.d.ts +0 -20
- package/dist/engine/decoder.js +8 -27
- package/dist/engine/index.d.ts +2 -49
- package/dist/engine/index.js +7 -48
- package/dist/engine/keys.d.ts +0 -7
- package/dist/engine/keys.js +9 -15
- package/dist/engine/render.d.ts +7 -18
- package/dist/engine/render.js +32 -32
- package/dist/engine/selection.d.ts +0 -17
- package/dist/engine/selection.js +8 -30
- package/dist/proto/frame.d.ts +2 -23
- package/dist/proto/frame.js +1 -21
- package/dist/proto/messages.d.ts +49 -9
- package/dist/proto/messages.js +42 -1
- package/dist/renderer/index.d.ts +3 -4
- package/dist/renderer/index.js +38 -42
- package/package.json +5 -6
package/dist/client/mount.js
CHANGED
|
@@ -3,7 +3,6 @@ import { Copier } from "./copy.js";
|
|
|
3
3
|
import { Typing, composing } from "./keyboard.js";
|
|
4
4
|
import { Listeners } from "./listeners.js";
|
|
5
5
|
import { profileFrom, schemeOf } from "./profile.js";
|
|
6
|
-
/** Cell metrics from the font. */
|
|
7
6
|
function measure(font) {
|
|
8
7
|
const ctx = document.createElement("canvas").getContext("2d");
|
|
9
8
|
ctx.font = font;
|
|
@@ -21,8 +20,9 @@ function measure(font) {
|
|
|
21
20
|
boldItalicFont: `bold italic ${font}`,
|
|
22
21
|
};
|
|
23
22
|
}
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
function isCopyChord(e) {
|
|
24
|
+
return e.ctrlKey && e.shiftKey && !e.altKey && !e.metaKey && e.code === "KeyC";
|
|
25
|
+
}
|
|
26
26
|
export function mountOn(host, id, options) {
|
|
27
27
|
const { canvas, container, colors } = options;
|
|
28
28
|
const light = matchMedia("(prefers-color-scheme: light)");
|
|
@@ -42,10 +42,8 @@ export function mountOn(host, id, options) {
|
|
|
42
42
|
cell_height: Math.round(metrics.cellHeight * dpr()),
|
|
43
43
|
};
|
|
44
44
|
}
|
|
45
|
-
/** The canvas backing store for the grid at the current pixel ratio;
|
|
46
|
-
* the next frame is drawn in full after a change. */
|
|
47
45
|
let grid = { cols: 0, rows: 0, dpr: 0 };
|
|
48
|
-
let
|
|
46
|
+
let backingStoreReset = false;
|
|
49
47
|
function fitCanvas(cols, rows) {
|
|
50
48
|
const scale = dpr();
|
|
51
49
|
if (grid.cols === cols && grid.rows === rows && grid.dpr === scale)
|
|
@@ -57,9 +55,8 @@ export function mountOn(host, id, options) {
|
|
|
57
55
|
canvas.style.height = `${rows * metrics.cellHeight}px`;
|
|
58
56
|
ctx.setTransform(scale, 0, 0, scale, 0, 0);
|
|
59
57
|
ctx.textBaseline = "alphabetic";
|
|
60
|
-
|
|
58
|
+
backingStoreReset = true;
|
|
61
59
|
}
|
|
62
|
-
/** The keyboard layout, when the browser exposes it (Chromium does). */
|
|
63
60
|
const keyboard = { layout: undefined, mac: /Mac|iPhone|iPad/.test(navigator.platform) };
|
|
64
61
|
navigator.keyboard
|
|
65
62
|
?.getLayoutMap()
|
|
@@ -73,29 +70,13 @@ export function mountOn(host, id, options) {
|
|
|
73
70
|
const links = new Listeners();
|
|
74
71
|
const scrolls = new Listeners();
|
|
75
72
|
const statuses = new Listeners();
|
|
76
|
-
const copies = new
|
|
77
|
-
/** The selection's text, for a copy. */
|
|
73
|
+
const copies = new Listeners("isolateErrors");
|
|
78
74
|
let selected;
|
|
79
75
|
const copier = new Copier({
|
|
80
76
|
clipboard: () => navigator.clipboard,
|
|
81
77
|
item: typeof ClipboardItem === "undefined" ? undefined : (text) => new ClipboardItem({ "text/plain": text }),
|
|
82
|
-
|
|
83
|
-
// a listener's throw is elsewhere, and the rest are told.
|
|
84
|
-
report: (copy) => {
|
|
85
|
-
for (const listener of copies) {
|
|
86
|
-
try {
|
|
87
|
-
listener(copy);
|
|
88
|
-
}
|
|
89
|
-
catch (err) {
|
|
90
|
-
queueMicrotask(() => {
|
|
91
|
-
throw err;
|
|
92
|
-
});
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
},
|
|
78
|
+
report: (copy) => copies.emit(copy),
|
|
96
79
|
});
|
|
97
|
-
/** Rows the view is scrolled back, as `onScroll` last reported;
|
|
98
|
-
* undefined before the first frame. */
|
|
99
80
|
let scrolled;
|
|
100
81
|
const visible = () => document.visibilityState === "visible";
|
|
101
82
|
let pendingFrame;
|
|
@@ -108,12 +89,11 @@ export function mountOn(host, id, options) {
|
|
|
108
89
|
return;
|
|
109
90
|
if (visible()) {
|
|
110
91
|
fitCanvas(frame.cols, frame.rows);
|
|
111
|
-
if (
|
|
112
|
-
// The backing store was recreated; a partial frame cannot fill it.
|
|
92
|
+
if (backingStoreReset && !frame.full) {
|
|
113
93
|
send({ type: "repaint" });
|
|
114
94
|
}
|
|
115
95
|
else {
|
|
116
|
-
|
|
96
|
+
backingStoreReset = false;
|
|
117
97
|
renderer.draw(frame);
|
|
118
98
|
}
|
|
119
99
|
}
|
|
@@ -156,8 +136,6 @@ export function mountOn(host, id, options) {
|
|
|
156
136
|
break;
|
|
157
137
|
}
|
|
158
138
|
};
|
|
159
|
-
/** Where the input element goes for a composition: the cursor's cell,
|
|
160
|
-
* as the latest frame that had the cursor in view placed it. */
|
|
161
139
|
let cursorAt = { x: 0, y: 0 };
|
|
162
140
|
// An input method composes only into an editable element: a textarea
|
|
163
141
|
// after the canvas takes the focus, invisible but at the cursor so the
|
|
@@ -187,10 +165,7 @@ export function mountOn(host, id, options) {
|
|
|
187
165
|
caretColor: "transparent",
|
|
188
166
|
});
|
|
189
167
|
canvas.after(input);
|
|
190
|
-
/** Moves the input element to the cursor, and shows it while composing. */
|
|
191
168
|
function placeInput(composing) {
|
|
192
|
-
// Its position is against its containing block: a positioned
|
|
193
|
-
// ancestor, or else the document.
|
|
194
169
|
const cell = canvas.getBoundingClientRect();
|
|
195
170
|
const parent = input.offsetParent;
|
|
196
171
|
let left = cell.left + window.scrollX;
|
|
@@ -216,8 +191,6 @@ export function mountOn(host, id, options) {
|
|
|
216
191
|
});
|
|
217
192
|
}
|
|
218
193
|
canvas.addEventListener("focus", () => input.focus({ preventScroll: true }), { signal });
|
|
219
|
-
// Whether the terminal has the keyboard and its window the focus, for
|
|
220
|
-
// `ackOnFocus`.
|
|
221
194
|
let focused = false;
|
|
222
195
|
const watchFocus = () => {
|
|
223
196
|
const now = document.activeElement === input && document.hasFocus();
|
|
@@ -233,9 +206,7 @@ export function mountOn(host, id, options) {
|
|
|
233
206
|
const typing = new Typing(keyboard);
|
|
234
207
|
const typed = (what) => send("text" in what ? { type: "text", text: what.text } : { type: "key", input: what.key });
|
|
235
208
|
input.addEventListener("keydown", (e) => {
|
|
236
|
-
|
|
237
|
-
// without one it is a key.
|
|
238
|
-
if (e.ctrlKey && e.shiftKey && !e.altKey && !e.metaKey && e.code === "KeyC" && selected) {
|
|
209
|
+
if (isCopyChord(e) && selected) {
|
|
239
210
|
copier.write(selected, "keys");
|
|
240
211
|
e.preventDefault();
|
|
241
212
|
return;
|
|
@@ -246,8 +217,6 @@ export function mountOn(host, id, options) {
|
|
|
246
217
|
e.preventDefault();
|
|
247
218
|
}
|
|
248
219
|
else if (composing(e)) {
|
|
249
|
-
// At the cursor before the input method opens its window; shown
|
|
250
|
-
// once a composition starts.
|
|
251
220
|
placeInput(false);
|
|
252
221
|
}
|
|
253
222
|
}, { signal });
|
|
@@ -272,7 +241,6 @@ export function mountOn(host, id, options) {
|
|
|
272
241
|
if (what)
|
|
273
242
|
typed(what);
|
|
274
243
|
placeInput(false);
|
|
275
|
-
// Emptied once the composition has left it.
|
|
276
244
|
setTimeout(() => (input.value = ""));
|
|
277
245
|
}, { signal });
|
|
278
246
|
input.addEventListener("input", (e) => {
|
|
@@ -285,7 +253,6 @@ export function mountOn(host, id, options) {
|
|
|
285
253
|
send({ type: "paste", text });
|
|
286
254
|
e.preventDefault();
|
|
287
255
|
}, { signal });
|
|
288
|
-
// The browser's copy (Cmd+C, Ctrl+C in a menu) copies the selection.
|
|
289
256
|
// WebKit offers Copy on an empty textarea only when `beforecopy` is
|
|
290
257
|
// cancelled.
|
|
291
258
|
input.addEventListener("beforecopy", (e) => {
|
|
@@ -299,7 +266,6 @@ export function mountOn(host, id, options) {
|
|
|
299
266
|
e.preventDefault();
|
|
300
267
|
copier.copied(selected);
|
|
301
268
|
}, { signal });
|
|
302
|
-
/** The pointer in cells of the grid, fractions included, kept inside it. */
|
|
303
269
|
function cellAt(e) {
|
|
304
270
|
const rect = canvas.getBoundingClientRect();
|
|
305
271
|
const inside = (value, cells) => Math.min(Math.max(value, 0), Math.max(cells - 0.01, 0));
|
|
@@ -308,10 +274,6 @@ export function mountOn(host, id, options) {
|
|
|
308
274
|
y: inside((e.clientY - rect.top) / metrics.cellHeight, grid.rows),
|
|
309
275
|
};
|
|
310
276
|
}
|
|
311
|
-
// Selection: press, drag (once a frame) and release, followed outside
|
|
312
|
-
// the canvas until the button is up. A release the page never saw (the
|
|
313
|
-
// button let go over another window) ends the drag at the next move or
|
|
314
|
-
// press.
|
|
315
277
|
let endDrag;
|
|
316
278
|
canvas.addEventListener("mousedown", (e) => {
|
|
317
279
|
e.preventDefault();
|
|
@@ -350,8 +312,6 @@ export function mountOn(host, id, options) {
|
|
|
350
312
|
window.addEventListener("mousemove", move, { signal });
|
|
351
313
|
window.addEventListener("mouseup", up, { signal });
|
|
352
314
|
}, { signal });
|
|
353
|
-
// The wheel scrolls the history in whole rows; what a trackpad sends in
|
|
354
|
-
// pixels adds up until it makes one. Ctrl+wheel stays the browser's zoom.
|
|
355
315
|
let wheeled = 0;
|
|
356
316
|
canvas.addEventListener("wheel", (e) => {
|
|
357
317
|
if (e.ctrlKey)
|
|
@@ -369,39 +329,32 @@ export function mountOn(host, id, options) {
|
|
|
369
329
|
wheeled -= whole;
|
|
370
330
|
send({ type: "wheel", rows: whole });
|
|
371
331
|
}, { passive: false, signal });
|
|
372
|
-
/** The profile last reported, to tell when it changed. */
|
|
373
332
|
let reported = "";
|
|
374
333
|
const profile = () => {
|
|
375
334
|
const current = profileFrom(colors(), scheme());
|
|
376
335
|
reported = JSON.stringify(current);
|
|
377
336
|
return current;
|
|
378
337
|
};
|
|
379
|
-
/** Whether the user is looking at this page: it is visible and its
|
|
380
|
-
* window has the focus. Only then does the session get its size, so
|
|
381
|
-
* of several clients the one in use sets it. */
|
|
382
338
|
const active = () => visible() && document.hasFocus();
|
|
383
339
|
const report = () => send({ type: "viewport", size: viewport(), profile: profile(), active: active() });
|
|
384
340
|
const resizes = new ResizeObserver(report);
|
|
385
341
|
resizes.observe(container);
|
|
386
342
|
light.addEventListener("change", report, { signal });
|
|
387
|
-
|
|
388
|
-
|
|
343
|
+
const releaseFrameWhileHidden = () => {
|
|
344
|
+
if (visible() || !pendingFrame)
|
|
345
|
+
return;
|
|
346
|
+
cancelAnimationFrame(paintRequest);
|
|
347
|
+
paintRequest = 0;
|
|
348
|
+
pendingFrame = undefined;
|
|
349
|
+
send({ type: "painted" });
|
|
350
|
+
};
|
|
389
351
|
document.addEventListener("visibilitychange", () => {
|
|
390
352
|
send({ type: "visibility", visible: visible() });
|
|
391
|
-
|
|
392
|
-
cancelAnimationFrame(paintRequest);
|
|
393
|
-
paintRequest = 0;
|
|
394
|
-
pendingFrame = undefined;
|
|
395
|
-
// Hidden documents may never get another animation callback. Release
|
|
396
|
-
// the frame after hiding the worker; showing requests a full refresh.
|
|
397
|
-
send({ type: "painted" });
|
|
398
|
-
}
|
|
353
|
+
releaseFrameWhileHidden();
|
|
399
354
|
report();
|
|
400
355
|
}, { signal });
|
|
401
356
|
window.addEventListener("focus", report, { signal });
|
|
402
357
|
window.addEventListener("blur", report, { signal });
|
|
403
|
-
// A page pins its scheme (and its colours with it) with an attribute or
|
|
404
|
-
// a class on the canvas or an ancestor, which no event announces.
|
|
405
358
|
const restyles = new MutationObserver(() => {
|
|
406
359
|
if (JSON.stringify(profileFrom(colors(), scheme())) !== reported)
|
|
407
360
|
report();
|
|
@@ -409,8 +362,6 @@ export function mountOn(host, id, options) {
|
|
|
409
362
|
for (let element = canvas; element; element = element.parentElement) {
|
|
410
363
|
restyles.observe(element, { attributes: true });
|
|
411
364
|
}
|
|
412
|
-
// Zoom or a move to another screen changes the pixel ratio: the canvas
|
|
413
|
-
// is refitted on the next frame; the cell size in pixels is re-reported.
|
|
414
365
|
const watchRatio = () => {
|
|
415
366
|
matchMedia(`(resolution: ${dpr()}dppx)`).addEventListener("change", () => {
|
|
416
367
|
send({ type: "repaint" });
|
|
@@ -463,10 +414,7 @@ export function mountOn(host, id, options) {
|
|
|
463
414
|
onLink: (listener) => links.add(listener),
|
|
464
415
|
onScroll: (listener) => scrolls.add(listener),
|
|
465
416
|
onStatus: (listener) => statuses.add(listener),
|
|
466
|
-
onCopy: (listener) =>
|
|
467
|
-
copies.add(listener);
|
|
468
|
-
return () => void copies.delete(listener);
|
|
469
|
-
},
|
|
417
|
+
onCopy: (listener) => copies.add(listener),
|
|
470
418
|
};
|
|
471
419
|
return { terminal, receive };
|
|
472
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,18 +13,15 @@ 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
27
|
for (let at = 0; at < bytes.length; at++) {
|
|
@@ -37,14 +34,13 @@ export class Osc52Scanner {
|
|
|
37
34
|
this.state = "esc";
|
|
38
35
|
break;
|
|
39
36
|
case "esc":
|
|
40
|
-
// The payload is empty: every way out of an OSC clears it.
|
|
41
37
|
if (b === 0x5d)
|
|
42
|
-
this.state = "
|
|
38
|
+
this.state = "maybeOsc52";
|
|
43
39
|
else
|
|
44
40
|
this.state = b === ESC ? "esc" : "text";
|
|
45
41
|
break;
|
|
46
|
-
case "
|
|
47
|
-
case "
|
|
42
|
+
case "maybeOsc52":
|
|
43
|
+
case "otherOsc":
|
|
48
44
|
if (b === BEL) {
|
|
49
45
|
this.finish(writes);
|
|
50
46
|
}
|
|
@@ -55,10 +51,10 @@ export class Osc52Scanner {
|
|
|
55
51
|
else if (b === CAN || b === SUB) {
|
|
56
52
|
this.reset();
|
|
57
53
|
}
|
|
58
|
-
else if (this.state === "
|
|
54
|
+
else if (this.state === "maybeOsc52") {
|
|
59
55
|
const length = this.payload.length;
|
|
60
56
|
if ((length < PREFIX.length && b !== PREFIX.charCodeAt(length)) || length === MAX_OSC) {
|
|
61
|
-
this.state = "
|
|
57
|
+
this.state = "otherOsc";
|
|
62
58
|
this.payload = [];
|
|
63
59
|
}
|
|
64
60
|
else {
|
|
@@ -71,7 +67,7 @@ export class Osc52Scanner {
|
|
|
71
67
|
return writes;
|
|
72
68
|
}
|
|
73
69
|
finish(writes) {
|
|
74
|
-
const collected = this.state === "
|
|
70
|
+
const collected = this.state === "maybeOsc52";
|
|
75
71
|
const payload = new TextDecoder().decode(Uint8Array.from(this.payload));
|
|
76
72
|
this.reset();
|
|
77
73
|
if (!collected)
|
|
@@ -79,15 +75,22 @@ export class Osc52Scanner {
|
|
|
79
75
|
const match = /^52;([^;]*);(.*)$/s.exec(payload);
|
|
80
76
|
if (!match || match[2] === "?")
|
|
81
77
|
return;
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
// Not base64: ignored, as a terminal would.
|
|
87
|
-
}
|
|
78
|
+
const bytes = base64(match[2]);
|
|
79
|
+
if (bytes === undefined)
|
|
80
|
+
return;
|
|
81
|
+
writes.push({ toClipboard: isClipboardSelection(match[1]), text: new TextDecoder().decode(bytes) });
|
|
88
82
|
}
|
|
89
83
|
}
|
|
84
|
+
function isClipboardSelection(selection) {
|
|
85
|
+
return selection === "" || selection.includes("c");
|
|
86
|
+
}
|
|
90
87
|
function base64(text) {
|
|
91
|
-
|
|
88
|
+
let binary;
|
|
89
|
+
try {
|
|
90
|
+
binary = atob(text.replace(/\s+/g, ""));
|
|
91
|
+
}
|
|
92
|
+
catch {
|
|
93
|
+
return undefined;
|
|
94
|
+
}
|
|
92
95
|
return Uint8Array.from(binary, (c) => c.charCodeAt(0));
|
|
93
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,49 +1,8 @@
|
|
|
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
1
|
import { type CellPoint, type PackedFrame, type KeyInput } from "../engine/index.ts";
|
|
9
|
-
import { type
|
|
2
|
+
import { type ErrorMessage, type Event, type Peer, type Profile, type Session, type Size } from "../proto/index.ts";
|
|
10
3
|
import { type ErrorKind } from "./connection.ts";
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
* detaches); `removed`, `stopping` and `detached` (another client's
|
|
14
|
-
* `detach`): the server's `CLOSED`; `exited`:
|
|
15
|
-
* the session's program exited; `no_such_session` and `engine_mismatch`:
|
|
16
|
-
* an `OPEN` refused; `error`: any other error, the server's or the
|
|
17
|
-
* client's own. */
|
|
18
|
-
export type LinkEnd = "closed" | "removed" | "stopping" | "detached" | "exited" | "no_such_session" | "engine_mismatch" | "error";
|
|
19
|
-
/** A terminal's link to its session, through the client's connection and
|
|
20
|
-
* the terminal's attachment. */
|
|
21
|
-
export type Link =
|
|
22
|
-
/** Opening a connection; `attempt` counts from 1 and starts again once
|
|
23
|
-
* a server answers. */
|
|
24
|
-
{
|
|
25
|
-
state: "connecting";
|
|
26
|
-
attempt: number;
|
|
27
|
-
}
|
|
28
|
-
/** Connected, and showing `session` as `ATTACHED` described it (its
|
|
29
|
-
* `status` may be `restored` or `exited`), or attached to none. */
|
|
30
|
-
| {
|
|
31
|
-
state: "connected";
|
|
32
|
-
session: Session | undefined;
|
|
33
|
-
}
|
|
34
|
-
/** The link ended. `code` and `message` are the error's, when there is
|
|
35
|
-
* one, and `message` the reason a `detach` gave; `exit` is the
|
|
36
|
-
* program's, for `exited`. `retry`: the worker
|
|
37
|
-
* reconnects or attaches again by itself, so `connecting` or
|
|
38
|
-
* `connected` follows; otherwise nothing does until the page attaches. */
|
|
39
|
-
| {
|
|
40
|
-
state: "ended";
|
|
41
|
-
reason: LinkEnd;
|
|
42
|
-
code?: ErrorCode;
|
|
43
|
-
message?: string;
|
|
44
|
-
exit?: Exit;
|
|
45
|
-
retry: boolean;
|
|
46
|
-
};
|
|
4
|
+
import { type Link } from "./link.ts";
|
|
5
|
+
export type { Link, LinkEnd } from "./link.ts";
|
|
47
6
|
/** A failed request, as it crosses to the page. */
|
|
48
7
|
export interface Failure {
|
|
49
8
|
kind: ErrorKind;
|