@gjermundgaraba/clankermux 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,7 @@
1
1
  import { CanvasRenderer } from "../renderer/index.js";
2
- import { browserKeeps, keyInput } from "./keyboard.js";
3
- import { profileFrom } from "./profile.js";
2
+ import { ClientError } from "./connection.js";
3
+ import { Typing } from "./keyboard.js";
4
+ import { profileFrom, schemeOf } from "./profile.js";
4
5
  /** Cell metrics from the font. */
5
6
  function measure(font) {
6
7
  const ctx = document.createElement("canvas").getContext("2d");
@@ -22,7 +23,7 @@ function measure(font) {
22
23
  export function mountTerminal(options) {
23
24
  const { worker, canvas, container, colors } = options;
24
25
  const light = matchMedia("(prefers-color-scheme: light)");
25
- const scheme = options.scheme ?? (() => (light.matches ? "light" : "dark"));
26
+ const scheme = options.scheme ?? (() => schemeOf(getComputedStyle(canvas).colorScheme, light.matches));
26
27
  const metrics = measure(options.font);
27
28
  const ctx = canvas.getContext("2d");
28
29
  const renderer = new CanvasRenderer(ctx, metrics, { cursor: colors().cursor });
@@ -62,13 +63,84 @@ export function mountTerminal(options) {
62
63
  .then((map) => (keyboard.layout = map))
63
64
  .catch(() => { });
64
65
  const send = (message) => worker.postMessage(message);
66
+ /** Requests waiting for their `done`, by id. They reject with a
67
+ * `ClientError` for a server's refusal, a lost connection or a
68
+ * disposed terminal, or an `Error` when no session is attached. */
69
+ const pending = new Map();
70
+ let nextId = 1;
71
+ let disposed = false;
72
+ function request(message) {
73
+ if (disposed)
74
+ return Promise.reject(new ClientError("closed", "disposed"));
75
+ const id = nextId++;
76
+ return new Promise((resolve, reject) => {
77
+ pending.set(id, { resolve, reject });
78
+ send(message(id));
79
+ });
80
+ }
81
+ const failure = (error) => error.kind ? new ClientError(error.kind, error.message, error.server) : new Error(error.message);
82
+ /** The selection's text, for a copy. */
83
+ let selected;
84
+ /** The clipboard write a release started, waiting for the worker to say
85
+ * what was selected. */
86
+ let copying;
87
+ /** Starts the copy of what a release selected. Safari writes to the
88
+ * clipboard only within the user's gesture, which is over before the
89
+ * worker answers: the write starts here with the text to come, and
90
+ * fails, leaving the clipboard alone, when nothing was selected. */
91
+ function startCopy() {
92
+ copying?.reject();
93
+ copying = undefined;
94
+ if (typeof ClipboardItem === "undefined" || !navigator.clipboard?.write)
95
+ return;
96
+ let settle;
97
+ const text = new Promise((resolve, reject) => {
98
+ settle = {
99
+ resolve: (value) => resolve(new Blob([value], { type: "text/plain" })),
100
+ reject: () => reject(new Error("nothing selected")),
101
+ };
102
+ });
103
+ navigator.clipboard.write([new ClipboardItem({ "text/plain": text })]).catch(() => { });
104
+ const timer = setTimeout(() => settle.reject(), 2000);
105
+ copying = {
106
+ resolve: (value) => {
107
+ clearTimeout(timer);
108
+ settle.resolve(value);
109
+ },
110
+ reject: () => {
111
+ clearTimeout(timer);
112
+ settle.reject();
113
+ },
114
+ };
115
+ }
116
+ /** Rows the view is scrolled back, as `onScroll` last reported. */
117
+ let scrolled = 0;
65
118
  worker.onmessage = (e) => {
66
119
  const message = e.data;
67
120
  switch (message.type) {
68
121
  case "status":
69
122
  options.onStatus?.(message.text);
70
123
  break;
71
- case "frame":
124
+ case "link":
125
+ options.onLink?.(message.link);
126
+ break;
127
+ case "done": {
128
+ const waiter = pending.get(message.id);
129
+ pending.delete(message.id);
130
+ if (message.error)
131
+ waiter?.reject(failure(message.error));
132
+ else
133
+ waiter?.resolve(message.session);
134
+ break;
135
+ }
136
+ case "frame": {
137
+ if (message.frame.cursor)
138
+ cursorAt = { x: message.frame.cursor.x, y: message.frame.cursor.y };
139
+ const { total, offset, len } = message.frame.scrollbar;
140
+ if (total - offset - len !== scrolled) {
141
+ scrolled = total - offset - len;
142
+ options.onScroll?.(scrolled);
143
+ }
72
144
  fitCanvas(message.frame.cols, message.frame.rows);
73
145
  if (fullNext && !message.frame.full) {
74
146
  // The backing store was recreated; a partial frame cannot fill it.
@@ -79,33 +151,257 @@ export function mountTerminal(options) {
79
151
  renderer.draw(message.frame);
80
152
  }
81
153
  break;
154
+ }
82
155
  case "sessions":
83
156
  options.onSessions?.(message.sessions, message.current);
84
157
  break;
85
158
  case "clipboard":
86
159
  navigator.clipboard?.writeText(message.text).catch(() => { });
87
160
  break;
161
+ case "selection": {
162
+ selected = message.text;
163
+ if (!message.copy)
164
+ break;
165
+ const copy = copying;
166
+ copying = undefined;
167
+ if (message.text === undefined)
168
+ copy?.reject();
169
+ else if (copy)
170
+ copy.resolve(message.text);
171
+ else
172
+ navigator.clipboard?.writeText(message.text).catch(() => { });
173
+ break;
174
+ }
88
175
  }
89
176
  };
90
- for (const type of ["keydown", "keyup"]) {
91
- canvas.addEventListener(type, (e) => {
92
- if (browserKeeps(e))
93
- return;
94
- send({ type: "key", input: keyInput(e, keyboard) });
95
- e.preventDefault();
96
- }, { signal });
177
+ /** Where the input element goes for a composition: the cursor's cell,
178
+ * as the latest frame that had the cursor in view placed it. */
179
+ let cursorAt = { x: 0, y: 0 };
180
+ // An input method composes only into an editable element: a textarea
181
+ // after the canvas takes the focus, invisible but at the cursor so the
182
+ // input method's window opens there, and shows the composition while
183
+ // there is one.
184
+ const input = document.createElement("textarea");
185
+ input.setAttribute("aria-label", "Terminal input");
186
+ input.setAttribute("autocapitalize", "off");
187
+ input.setAttribute("autocomplete", "off");
188
+ input.setAttribute("autocorrect", "off");
189
+ input.spellcheck = false;
190
+ input.tabIndex = -1;
191
+ const hidden = { opacity: "0", width: "1px", height: "1px" };
192
+ Object.assign(input.style, {
193
+ ...hidden,
194
+ position: "absolute",
195
+ margin: "0",
196
+ padding: "0",
197
+ border: "0",
198
+ outline: "none",
199
+ resize: "none",
200
+ overflow: "hidden",
201
+ whiteSpace: "pre",
202
+ pointerEvents: "none",
203
+ font: metrics.font,
204
+ lineHeight: `${metrics.cellHeight}px`,
205
+ caretColor: "transparent",
206
+ });
207
+ canvas.after(input);
208
+ /** Moves the input element to the cursor, and shows it while composing. */
209
+ function placeInput(composing) {
210
+ // Its position is against its containing block: a positioned
211
+ // ancestor, or else the document.
212
+ const cell = canvas.getBoundingClientRect();
213
+ const parent = input.offsetParent;
214
+ let left = cell.left + window.scrollX;
215
+ let top = cell.top + window.scrollY;
216
+ if (parent && getComputedStyle(parent).position !== "static") {
217
+ const box = parent.getBoundingClientRect();
218
+ left = cell.left - box.left - parent.clientLeft + parent.scrollLeft;
219
+ top = cell.top - box.top - parent.clientTop + parent.scrollTop;
220
+ }
221
+ input.style.left = `${left + cursorAt.x * metrics.cellWidth}px`;
222
+ input.style.top = `${top + cursorAt.y * metrics.cellHeight}px`;
223
+ if (!composing) {
224
+ Object.assign(input.style, hidden);
225
+ return;
226
+ }
227
+ const { fg, bg } = colors();
228
+ Object.assign(input.style, {
229
+ opacity: "1",
230
+ width: `${Math.max(1, grid.cols - cursorAt.x) * metrics.cellWidth}px`,
231
+ height: `${metrics.cellHeight}px`,
232
+ color: fg,
233
+ background: bg,
234
+ });
97
235
  }
98
- canvas.addEventListener("paste", (e) => {
236
+ canvas.addEventListener("focus", () => input.focus({ preventScroll: true }), { signal });
237
+ const typing = new Typing(keyboard);
238
+ const typed = (what) => send("text" in what ? { type: "text", text: what.text } : { type: "key", input: what.key });
239
+ input.addEventListener("keydown", (e) => {
240
+ // Ctrl+Shift+C copies a selection, where Ctrl+C is the terminal's;
241
+ // without one it is a key.
242
+ if (e.ctrlKey && e.shiftKey && !e.altKey && !e.metaKey && e.code === "KeyC" && selected) {
243
+ navigator.clipboard?.writeText(selected).catch(() => { });
244
+ e.preventDefault();
245
+ return;
246
+ }
247
+ const key = typing.keydown(e);
248
+ if (key) {
249
+ send({ type: "key", input: key });
250
+ e.preventDefault();
251
+ }
252
+ else if (e.isComposing || e.key === "Dead" || e.keyCode === 229) {
253
+ // At the cursor before the input method opens its window; shown
254
+ // once a composition starts.
255
+ placeInput(false);
256
+ }
257
+ }, { signal });
258
+ input.addEventListener("keyup", (e) => {
259
+ const key = typing.keyup(e);
260
+ if (!key)
261
+ return;
262
+ send({ type: "key", input: key });
263
+ e.preventDefault();
264
+ }, { signal });
265
+ input.addEventListener("beforeinput", (e) => {
266
+ const what = typing.beforeinput(e);
267
+ if (!what)
268
+ return;
269
+ typed(what);
270
+ e.preventDefault();
271
+ }, { signal });
272
+ input.addEventListener("compositionstart", () => placeInput(true), { signal });
273
+ input.addEventListener("blur", () => placeInput(false), { signal });
274
+ input.addEventListener("compositionend", (e) => {
275
+ const what = typing.compositionend(e.data);
276
+ if (what)
277
+ typed(what);
278
+ placeInput(false);
279
+ // Emptied once the composition has left it.
280
+ setTimeout(() => (input.value = ""));
281
+ }, { signal });
282
+ input.addEventListener("input", (e) => {
283
+ if (!e.isComposing)
284
+ input.value = "";
285
+ }, { signal });
286
+ input.addEventListener("paste", (e) => {
99
287
  const text = e.clipboardData?.getData("text");
100
288
  if (text)
101
289
  send({ type: "paste", text });
102
290
  e.preventDefault();
103
291
  }, { signal });
104
- canvas.addEventListener("mousedown", () => canvas.focus(), { signal });
105
- const report = () => send({ type: "viewport", size: viewport(), profile: profileFrom(colors(), scheme()) });
292
+ // The browser's copy (Cmd+C, Ctrl+C in a menu) copies the selection.
293
+ // WebKit offers Copy on an empty textarea only when `beforecopy` is
294
+ // cancelled.
295
+ input.addEventListener("beforecopy", (e) => {
296
+ if (selected !== undefined)
297
+ e.preventDefault();
298
+ }, { signal });
299
+ input.addEventListener("copy", (e) => {
300
+ if (selected === undefined || !e.clipboardData)
301
+ return;
302
+ e.clipboardData.setData("text/plain", selected);
303
+ e.preventDefault();
304
+ }, { signal });
305
+ /** The pointer in cells of the grid, fractions included, kept inside it. */
306
+ function cellAt(e) {
307
+ const rect = canvas.getBoundingClientRect();
308
+ const inside = (value, cells) => Math.min(Math.max(value, 0), Math.max(cells - 0.01, 0));
309
+ return {
310
+ x: inside((e.clientX - rect.left) / metrics.cellWidth, grid.cols),
311
+ y: inside((e.clientY - rect.top) / metrics.cellHeight, grid.rows),
312
+ };
313
+ }
314
+ // Selection: press, drag (once a frame) and release, followed outside
315
+ // the canvas until the button is up. A release the page never saw (the
316
+ // button let go over another window) ends the drag at the next move or
317
+ // press.
318
+ let endDrag;
319
+ canvas.addEventListener("mousedown", (e) => {
320
+ e.preventDefault();
321
+ input.focus({ preventScroll: true });
322
+ if (e.button !== 0)
323
+ return;
324
+ endDrag?.(cellAt(e), e.timeStamp);
325
+ send({ type: "select", action: "press", at: cellAt(e), time: e.timeStamp });
326
+ let pending;
327
+ let frame = 0;
328
+ const flush = () => {
329
+ cancelAnimationFrame(frame);
330
+ frame = 0;
331
+ if (pending)
332
+ send({ type: "select", action: "drag", at: pending, time: 0 });
333
+ pending = undefined;
334
+ };
335
+ const end = (at, time) => {
336
+ flush();
337
+ window.removeEventListener("mousemove", move);
338
+ window.removeEventListener("mouseup", up);
339
+ endDrag = undefined;
340
+ startCopy();
341
+ send({ type: "select", action: "release", at, time });
342
+ };
343
+ const move = (m) => {
344
+ if ((m.buttons & 1) === 0)
345
+ return end(cellAt(m), m.timeStamp);
346
+ pending = cellAt(m);
347
+ frame ||= requestAnimationFrame(flush);
348
+ };
349
+ const up = (u) => {
350
+ if (u.button === 0)
351
+ end(cellAt(u), u.timeStamp);
352
+ };
353
+ endDrag = end;
354
+ window.addEventListener("mousemove", move, { signal });
355
+ window.addEventListener("mouseup", up, { signal });
356
+ }, { signal });
357
+ // The wheel scrolls the history in whole rows; what a trackpad sends in
358
+ // pixels adds up until it makes one. Ctrl+wheel stays the browser's zoom.
359
+ let wheeled = 0;
360
+ canvas.addEventListener("wheel", (e) => {
361
+ if (e.ctrlKey)
362
+ return;
363
+ e.preventDefault();
364
+ const rows = e.deltaMode === WheelEvent.DOM_DELTA_LINE
365
+ ? e.deltaY
366
+ : e.deltaMode === WheelEvent.DOM_DELTA_PAGE
367
+ ? e.deltaY * grid.rows
368
+ : e.deltaY / metrics.cellHeight;
369
+ wheeled += rows;
370
+ const whole = Math.trunc(wheeled);
371
+ if (whole === 0)
372
+ return;
373
+ wheeled -= whole;
374
+ send({ type: "scroll", rows: whole });
375
+ }, { passive: false, signal });
376
+ /** The profile last reported, to tell when it changed. */
377
+ let reported = "";
378
+ const profile = () => {
379
+ const current = profileFrom(colors(), scheme());
380
+ reported = JSON.stringify(current);
381
+ return current;
382
+ };
383
+ /** Whether the user is looking at this page: it is visible and its
384
+ * window has the focus. Only then does the session get its size, so
385
+ * of several clients the one in use sets it. */
386
+ const active = () => document.visibilityState === "visible" && document.hasFocus();
387
+ const report = () => send({ type: "viewport", size: viewport(), profile: profile(), active: active() });
106
388
  const resizes = new ResizeObserver(report);
107
389
  resizes.observe(container);
108
390
  light.addEventListener("change", report, { signal });
391
+ // Shown or focused: the session takes this page's size again; hidden or
392
+ // blurred: the worker stops reporting.
393
+ document.addEventListener("visibilitychange", report, { signal });
394
+ window.addEventListener("focus", report, { signal });
395
+ window.addEventListener("blur", report, { signal });
396
+ // A page pins its scheme (and its colours with it) with an attribute or
397
+ // a class on the canvas or an ancestor, which no event announces.
398
+ const restyles = new MutationObserver(() => {
399
+ if (JSON.stringify(profileFrom(colors(), scheme())) !== reported)
400
+ report();
401
+ });
402
+ for (let element = canvas; element; element = element.parentElement) {
403
+ restyles.observe(element, { attributes: true });
404
+ }
109
405
  // Zoom or a move to another screen changes the pixel ratio: the canvas
110
406
  // is refitted on the next frame; the cell size in pixels is re-reported.
111
407
  const watchRatio = () => {
@@ -121,19 +417,33 @@ export function mountTerminal(options) {
121
417
  wasm: new URL(options.wasm, location.href).toString(),
122
418
  url: options.url,
123
419
  viewport: viewport(),
124
- profile: profileFrom(colors(), scheme()),
420
+ profile: profile(),
421
+ active: active(),
125
422
  session: options.session,
126
423
  });
127
424
  return {
128
425
  attach: (session) => send({ type: "attach", session }),
129
- create: () => send({ type: "create" }),
426
+ create: async (create) => {
427
+ const session = await request((id) => ({ type: "create", id, ...(create?.onExit && { onExit: create.onExit }) }));
428
+ return session;
429
+ },
430
+ end: async () => void (await request((id) => ({ type: "end", id }))),
431
+ remove: async () => void (await request((id) => ({ type: "remove", id }))),
432
+ focus: () => input.focus({ preventScroll: true }),
433
+ selection: () => selected,
130
434
  report,
131
435
  paste: (text) => send({ type: "paste", text }),
132
436
  dispose: () => {
437
+ disposed = true;
133
438
  listening.abort();
134
439
  resizes.disconnect();
440
+ restyles.disconnect();
441
+ input.remove();
135
442
  worker.onmessage = null;
136
443
  worker.terminate();
444
+ for (const waiter of pending.values())
445
+ waiter.reject(new ClientError("closed", "disposed"));
446
+ pending.clear();
137
447
  },
138
448
  };
139
449
  }
@@ -2,6 +2,10 @@ import type { Profile, Scheme } from "../proto/index.ts";
2
2
  /** `#rrggbb` from a CSS colour as a custom property holds it (hex, or
3
3
  * `rgb()` when the stylesheet writes it that way); undefined otherwise. */
4
4
  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
+ export declare function schemeOf(colorScheme: string, prefersLight: boolean): Scheme;
5
9
  /** The profile a page with these colours and scheme reports. */
6
10
  export declare function profileFrom(colors: {
7
11
  fg: string;
@@ -14,6 +14,17 @@ export function hexColor(value) {
14
14
  const channel = (s) => Math.min(255, Number(s)).toString(16).padStart(2, "0");
15
15
  return `#${channel(rgb[1])}${channel(rgb[2])}${channel(rgb[3])}`;
16
16
  }
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
+ export function schemeOf(colorScheme, prefersLight) {
21
+ const names = colorScheme.split(/\s+/);
22
+ const light = names.includes("light");
23
+ const dark = names.includes("dark");
24
+ if (light !== dark)
25
+ return light ? "light" : "dark";
26
+ return prefersLight ? "light" : "dark";
27
+ }
17
28
  /** The profile a page with these colours and scheme reports. */
18
29
  export function profileFrom(colors, scheme) {
19
30
  const profile = { scheme };
@@ -4,31 +4,110 @@
4
4
  * reports input. Imported as `@gjermundgaraba/clankermux/worker`, so a worker
5
5
  * typechecked without the DOM library does not see the page's types.
6
6
  */
7
- import { type Frame, type KeyInput } from "../engine/index.ts";
8
- import { type Profile, type Session, type Size } from "../proto/index.ts";
7
+ import { type CellPoint, type Frame, type KeyInput } from "../engine/index.ts";
8
+ import { type ErrorCode, type ErrorMessage, type Exit, type OnExit, type Profile, type Session, type Size } from "../proto/index.ts";
9
+ import { type ErrorKind } from "./connection.ts";
10
+ /** Why the link to the session ended. `closed`: the connection closed
11
+ * (not a `CLOSED` frame, which the worker does not wait for when it
12
+ * detaches); `removed` and `stopping`: the server's `CLOSED`; `exited`:
13
+ * the session's program exited; `no_such_session` and `engine_mismatch`:
14
+ * an `OPEN` refused; `error`: any other error, the server's or the
15
+ * client's own. */
16
+ export type LinkEnd = "closed" | "removed" | "stopping" | "exited" | "no_such_session" | "engine_mismatch" | "error";
17
+ /** The page's link to its session, through the connection and the
18
+ * attachment. */
19
+ export type Link =
20
+ /** Opening a connection; `attempt` counts from 1 and starts again once
21
+ * a server answers. */
22
+ {
23
+ state: "connecting";
24
+ attempt: number;
25
+ }
26
+ /** Connected, and showing `session` as `ATTACHED` described it (its
27
+ * `status` may be `restored` or `exited`), or attached to none. */
28
+ | {
29
+ state: "connected";
30
+ session: Session | undefined;
31
+ }
32
+ /** The link ended. `code` and `message` are the error's, when there is
33
+ * one; `exit` is the program's, for `exited`. `retry`: the worker
34
+ * reconnects or attaches again by itself, so `connecting` or
35
+ * `connected` follows; otherwise nothing does until the page attaches
36
+ * or creates. */
37
+ | {
38
+ state: "ended";
39
+ reason: LinkEnd;
40
+ code?: ErrorCode;
41
+ message?: string;
42
+ exit?: Exit;
43
+ retry: boolean;
44
+ };
45
+ /** A failed request, as it crosses to the page. */
46
+ export interface Failure {
47
+ /** Absent for a request that needs a session when none is attached. */
48
+ kind?: ErrorKind;
49
+ message: string;
50
+ server?: ErrorMessage;
51
+ }
9
52
  /** Messages from the page to the worker. */
10
- export type ToWorker = {
53
+ export type ToWorker =
54
+ /** `active`: the user is looking at the page (below). */
55
+ {
11
56
  type: "init";
12
57
  wasm: string;
13
58
  url: string;
14
59
  viewport: Size;
15
60
  profile: Profile;
61
+ active: boolean;
16
62
  session: string | undefined;
17
63
  } | {
18
64
  type: "attach";
19
65
  session: string;
20
- } | {
66
+ }
67
+ /** Each request is answered by a `done` with its `id`. */
68
+ | {
21
69
  type: "create";
70
+ id: number;
71
+ onExit?: OnExit;
72
+ } | {
73
+ type: "end";
74
+ id: number;
75
+ } | {
76
+ type: "remove";
77
+ id: number;
22
78
  } | {
23
79
  type: "key";
24
80
  input: KeyInput;
25
81
  } | {
26
82
  type: "paste";
27
83
  text: string;
28
- } | {
84
+ }
85
+ /** The mouse on the canvas, `at` in cells of the viewport, fractions
86
+ * included; `time` in ms, for double and triple clicks. */
87
+ | {
88
+ type: "select";
89
+ action: "press" | "drag" | "release";
90
+ at: CellPoint;
91
+ time: number;
92
+ }
93
+ /** Text as typed, which no key sent: a composition's, the emoji picker's. */
94
+ | {
95
+ type: "text";
96
+ text: string;
97
+ }
98
+ /** The wheel: `rows` through the history, up when negative. */
99
+ | {
100
+ type: "scroll";
101
+ rows: number;
102
+ }
103
+ /** The page's size and profile. Only an `active` page, one the user is
104
+ * looking at, reports them to the session: the server applies the
105
+ * latest report, so the session takes the size of the page in use. */
106
+ | {
29
107
  type: "viewport";
30
108
  size: Size;
31
109
  profile: Profile;
110
+ active: boolean;
32
111
  }
33
112
  /** The page lost its drawing: send the whole screen again. */
34
113
  | {
@@ -38,6 +117,14 @@ export type ToWorker = {
38
117
  export type ToPage = {
39
118
  type: "status";
40
119
  text: string;
120
+ } | {
121
+ type: "link";
122
+ link: Link;
123
+ } | {
124
+ type: "done";
125
+ id: number;
126
+ session?: Session;
127
+ error?: Failure;
41
128
  } | {
42
129
  type: "frame";
43
130
  frame: Frame;
@@ -48,6 +135,13 @@ export type ToPage = {
48
135
  } | {
49
136
  type: "clipboard";
50
137
  text: string;
138
+ }
139
+ /** The selection's text, or undefined once there is none; `copy`: the
140
+ * answer to a release, so the text (if any) goes to the clipboard. */
141
+ | {
142
+ type: "selection";
143
+ text: string | undefined;
144
+ copy: boolean;
51
145
  };
52
146
  /** The worker's end of the page's messages: `self` in a dedicated worker. */
53
147
  export interface WorkerPort {