@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 CHANGED
@@ -7,7 +7,7 @@ The browser client of [clankermux](https://github.com/gjermundgaraba/clankermux)
7
7
  | `.` | `connect`, `Client`, the `Terminal` it mounts, their types, `ClientError` |
8
8
  | `./worker` | `runWorker`, for the worker module; no DOM types |
9
9
  | `./ghostty-vt.wasm` | the engine build the server's engine id names |
10
- | `./proto`, `./engine`, `./renderer` | the protocol messages, the engine and the canvas renderer; `Methods` maps each method to its params and result types, and `Catalog` is what `describe()` answers: the server's methods, events, frames and error codes with their JSON Schemas |
10
+ | `./proto`, `./renderer` | the protocol messages and the canvas renderer; `Methods` maps each method to its params and result types, and `Catalog` is what `describe()` answers: the server's methods, events, frames and error codes with their JSON Schemas |
11
11
 
12
12
  ```ts
13
13
  // worker.ts, started as a module worker
@@ -1,11 +1,9 @@
1
1
  import { type Engine, type Terminal } from "../engine/index.ts";
2
- import { type Closed, type ErrorMessage, type Exit, type Frame, type Gap, type Resume, type Session, type Welcome } from "../proto/index.ts";
3
- /** What a client does in response to frames. */
4
- export type Action =
5
- /** The screen is renderable from the local engine. The session may
6
- * already have exited: see `Attachment.session`. */
7
- {
2
+ import { type Closed, type ErrorMessage, type Exit, type Frame, type Resume, type Session, type Welcome } from "../proto/index.ts";
3
+ export type Action = {
8
4
  type: "screen";
5
+ } | {
6
+ type: "resumed";
9
7
  } | {
10
8
  type: "output";
11
9
  bytes: Uint8Array;
@@ -16,57 +14,37 @@ export type Action =
16
14
  } | {
17
15
  type: "exited";
18
16
  exit: Exit;
19
- }
20
- /** Bytes were lost; the terminal was discarded and a new bootstrap follows. */
21
- | {
17
+ } | {
22
18
  type: "gap";
23
- gap: Gap;
24
19
  } | {
25
20
  type: "closed";
26
21
  reason: Closed["reason"];
27
22
  message?: string;
28
- }
29
- /** `read_only`, `not_running` and `input_overflow` keep the attachment;
30
- * any other code ended it. */
31
- | {
23
+ } | {
32
24
  type: "error";
33
25
  error: ErrorMessage;
34
26
  };
35
- /**
36
- * The attachment state machine: frames in, actions out. It keeps the
37
- * local engine current and tracks the cursor for resuming.
38
- */
39
27
  export declare class Attachment {
40
28
  readonly engine: Engine;
41
29
  private state;
42
30
  private cursor;
43
- /** The server the cursor was obtained from, and its limit. */
44
31
  private incarnation;
45
32
  private continuation;
46
- /** The server of the connection the next `ATTACHED` arrives on. */
47
- private next;
33
+ private pendingServer;
48
34
  session: Session | undefined;
49
35
  constructor(engine: Engine);
50
- /** Records the server an `OPEN` is about to go to; its incarnation
51
- * becomes the cursor's once that `ATTACHED` arrives. */
52
36
  openOn(welcome: Welcome): void;
53
- /** The cursor to resume from, once the terminal reflects the stream. */
54
37
  resume(): Resume | undefined;
55
38
  ended(): boolean;
56
- /** The server ended the attachment (`CLOSED` or a fatal `ERROR`). */
57
39
  closed(): boolean;
58
- /** The local engine, once `READY` has been decoded. */
59
40
  term(): Terminal | undefined;
60
41
  handle(frame: Frame): Action[];
61
- /** Releases the engine objects. */
62
42
  free(): void;
63
43
  private json;
44
+ private assertWellFormed;
64
45
  private step;
65
- /** A stream frame at the cursor. */
66
46
  private stream;
67
47
  private checkMarker;
68
- /** Keeps the terminal for display, if there is one. */
69
48
  private end;
70
- /** Frees whatever engine objects the state holds. */
71
49
  private discard;
72
50
  }
@@ -2,29 +2,25 @@ import { Decoder } from "../engine/index.js";
2
2
  import { FrameType, parseOutput, } from "../proto/index.js";
3
3
  import { ClientError } from "./connection.js";
4
4
  const KEEPS_ATTACHMENT = new Set(["read_only", "not_running", "input_overflow"]);
5
- /**
6
- * The attachment state machine: frames in, actions out. It keeps the
7
- * local engine current and tracks the cursor for resuming.
8
- */
5
+ const MAX_HELD_BYTES = 4 * 1024 * 1024;
6
+ const HELD_FRAME_OVERHEAD_BYTES = 64;
7
+ function mustHoldUntilSnapshotEnd(held, type) {
8
+ return held.length > 0 || type !== FrameType.Output;
9
+ }
9
10
  export class Attachment {
10
11
  engine;
11
12
  state = { kind: "opening" };
12
13
  cursor = { offset: 0, marker: 0 };
13
- /** The server the cursor was obtained from, and its limit. */
14
14
  incarnation = "";
15
15
  continuation = 0;
16
- /** The server of the connection the next `ATTACHED` arrives on. */
17
- next;
16
+ pendingServer;
18
17
  session;
19
18
  constructor(engine) {
20
19
  this.engine = engine;
21
20
  }
22
- /** Records the server an `OPEN` is about to go to; its incarnation
23
- * becomes the cursor's once that `ATTACHED` arrives. */
24
21
  openOn(welcome) {
25
- this.next = { incarnation: welcome.incarnation, continuation: welcome.limits.continuation };
22
+ this.pendingServer = { incarnation: welcome.incarnation, continuation: welcome.limits.continuation };
26
23
  }
27
- /** The cursor to resume from, once the terminal reflects the stream. */
28
24
  resume() {
29
25
  return this.state.kind === "streaming"
30
26
  ? { incarnation: this.incarnation, offset: this.cursor.offset, marker: this.cursor.marker }
@@ -33,11 +29,9 @@ export class Attachment {
33
29
  ended() {
34
30
  return this.state.kind === "ended";
35
31
  }
36
- /** The server ended the attachment (`CLOSED` or a fatal `ERROR`). */
37
32
  closed() {
38
- return this.state.kind === "ended" && this.state.closed;
33
+ return this.state.kind === "ended" && this.state.serverClosed;
39
34
  }
40
- /** The local engine, once `READY` has been decoded. */
41
35
  term() {
42
36
  switch (this.state.kind) {
43
37
  case "bootstrapping":
@@ -54,10 +48,9 @@ export class Attachment {
54
48
  this.step(frame, actions);
55
49
  return actions;
56
50
  }
57
- /** Releases the engine objects. */
58
51
  free() {
59
52
  this.discard();
60
- this.state = { kind: "ended", term: undefined, closed: true };
53
+ this.state = { kind: "ended", term: undefined, serverClosed: true };
61
54
  }
62
55
  json(frame) {
63
56
  try {
@@ -67,15 +60,18 @@ export class Attachment {
67
60
  throw ClientError.protocol(`malformed ${frame.header.type}: ${err}`);
68
61
  }
69
62
  }
63
+ assertWellFormed(frame) {
64
+ this.json(frame);
65
+ }
70
66
  step(frame, actions) {
71
67
  const type = frame.header.type;
72
68
  switch (type) {
73
69
  case FrameType.Attached: {
74
70
  const attached = this.json(frame);
75
- if (this.next) {
76
- this.incarnation = this.next.incarnation;
77
- this.continuation = this.next.continuation;
78
- this.next = undefined;
71
+ if (this.pendingServer) {
72
+ this.incarnation = this.pendingServer.incarnation;
73
+ this.continuation = this.pendingServer.continuation;
74
+ this.pendingServer = undefined;
79
75
  }
80
76
  this.cursor = { offset: attached.offset, marker: attached.marker };
81
77
  this.session = attached.session;
@@ -91,9 +87,12 @@ export class Attachment {
91
87
  decoder.free();
92
88
  throw err;
93
89
  }
94
- this.state = { kind: "bootstrapping", decoder, held: [] };
90
+ this.state = { kind: "bootstrapping", decoder, held: [], heldBytes: 0 };
91
+ }
92
+ else if (this.state.kind === "streaming") {
93
+ actions.push({ type: "resumed" });
95
94
  }
96
- else if (this.state.kind !== "streaming") {
95
+ else {
97
96
  throw ClientError.protocol("resume without a terminal");
98
97
  }
99
98
  break;
@@ -138,7 +137,13 @@ export class Attachment {
138
137
  case FrameType.Output:
139
138
  case FrameType.Resized:
140
139
  case FrameType.Exited:
141
- if (this.state.kind === "bootstrapping" && (this.state.held.length > 0 || type !== FrameType.Output)) {
140
+ if (this.state.kind === "bootstrapping" && mustHoldUntilSnapshotEnd(this.state.held, type)) {
141
+ const bytes = frame.payload.byteLength + HELD_FRAME_OVERHEAD_BYTES;
142
+ if (bytes > MAX_HELD_BYTES - this.state.heldBytes) {
143
+ this.end(false);
144
+ throw ClientError.desync("bootstrap stream buffer full; fresh OPEN required");
145
+ }
146
+ this.state.heldBytes += bytes;
142
147
  this.state.held.push(frame);
143
148
  return;
144
149
  }
@@ -147,12 +152,11 @@ export class Attachment {
147
152
  }
148
153
  this.stream(frame, actions);
149
154
  break;
150
- case FrameType.Gap: {
151
- const gap = this.json(frame);
155
+ case FrameType.Gap:
156
+ this.assertWellFormed(frame);
152
157
  this.discard();
153
- actions.push({ type: "gap", gap });
158
+ actions.push({ type: "gap" });
154
159
  break;
155
- }
156
160
  case FrameType.Closed: {
157
161
  const closed = this.json(frame);
158
162
  this.end(true);
@@ -170,7 +174,6 @@ export class Attachment {
170
174
  throw ClientError.protocol(`${type} on an attachment`);
171
175
  }
172
176
  }
173
- /** A stream frame at the cursor. */
174
177
  stream(frame, actions) {
175
178
  switch (frame.header.type) {
176
179
  case FrameType.Output: {
@@ -210,8 +213,7 @@ export class Attachment {
210
213
  }
211
214
  this.cursor.marker = seq;
212
215
  }
213
- /** Keeps the terminal for display, if there is one. */
214
- end(closed) {
216
+ end(serverClosed) {
215
217
  let term;
216
218
  switch (this.state.kind) {
217
219
  case "bootstrapping":
@@ -222,9 +224,8 @@ export class Attachment {
222
224
  term = this.state.term;
223
225
  break;
224
226
  }
225
- this.state = { kind: "ended", term, closed };
227
+ this.state = { kind: "ended", term, serverClosed };
226
228
  }
227
- /** Frees whatever engine objects the state holds. */
228
229
  discard() {
229
230
  switch (this.state.kind) {
230
231
  case "bootstrapping":
@@ -1,5 +1,3 @@
1
- /** The page side of a client: one worker, one connection, the control
2
- * surface, and the terminals mounted from it. */
3
1
  import type { Acked, Catalog, CreateParams, Description, Event, Page, Peer, Read, ReadParams, ResizeParams, SendParams, Sent, Session, StreamCursor, Tail, Until, Waited } from "../proto/index.ts";
4
2
  import { type MountOptions, type Terminal } from "./mount.ts";
5
3
  import type { Link, ToWorker } from "./worker.ts";
@@ -51,17 +49,13 @@ export declare class Client {
51
49
  private nextId;
52
50
  private readonly pending;
53
51
  private readonly mounts;
54
- private readonly terminals;
55
52
  private readonly sessionListeners;
56
- private readonly eventListeners;
57
53
  private readonly linkListeners;
58
- private latest;
59
- private link;
54
+ private readonly eventListeners;
60
55
  private started;
61
56
  private closed;
62
57
  /** @internal Use `connect`. */
63
58
  constructor(worker: Worker, started: (error?: Error) => void);
64
- private setLink;
65
59
  /** @internal */
66
60
  post(message: ToWorker): void;
67
61
  private call;
@@ -1,4 +1,5 @@
1
1
  import { ClientError } from "./connection.js";
2
+ import { Listeners } from "./listeners.js";
2
3
  import { mountOn } from "./mount.js";
3
4
  /**
4
5
  * Starts the worker and its connection to the server at `url`. Resolves
@@ -34,28 +35,22 @@ export class Client {
34
35
  nextId = 1;
35
36
  pending = new Map();
36
37
  mounts = new Map();
37
- terminals = new Set();
38
- sessionListeners = new Set();
38
+ sessionListeners = new Listeners();
39
+ linkListeners = new Listeners();
39
40
  eventListeners = new Set();
40
- linkListeners = new Set();
41
- latest;
42
- link;
43
41
  started = false;
44
42
  closed = false;
45
43
  /** @internal Use `connect`. */
46
44
  constructor(worker, started) {
47
45
  this.worker = worker;
48
- // A worker script that does not load posts nothing, so `connect`
49
- // would never settle. Once it runs, an error event is an exception in
50
- // one of its handlers, which costs that message only: the browser
51
- // reports it, and the client goes on.
52
- worker.onerror = (e) => {
46
+ const failStartIfWorkerDidNotLoad = (e) => {
53
47
  if (this.started)
54
48
  return;
55
- e.preventDefault?.();
49
+ e.preventDefault();
56
50
  started(new Error(`the worker failed: ${e.message || "it did not load"}`));
57
51
  this.close();
58
52
  };
53
+ worker.onerror = failStartIfWorkerDidNotLoad;
59
54
  worker.onmessage = (e) => {
60
55
  const message = e.data;
61
56
  switch (message.type) {
@@ -78,12 +73,10 @@ export class Client {
78
73
  break;
79
74
  }
80
75
  case "connection":
81
- this.setLink(message.link);
76
+ this.linkListeners.emit(message.link);
82
77
  break;
83
78
  case "sessions":
84
- this.latest = message.sessions;
85
- for (const listener of this.sessionListeners)
86
- listener(message.sessions);
79
+ this.sessionListeners.emit(message.sessions);
87
80
  break;
88
81
  case "event":
89
82
  for (const listener of this.eventListeners)
@@ -94,15 +87,10 @@ export class Client {
94
87
  listener({ event: "gap", incarnation: message.incarnation });
95
88
  break;
96
89
  default:
97
- this.mounts.get(message.mount)?.(message);
90
+ this.mounts.get(message.mount)?.receive(message);
98
91
  }
99
92
  };
100
93
  }
101
- setLink(link) {
102
- this.link = link;
103
- for (const listener of this.linkListeners)
104
- listener(link);
105
- }
106
94
  /** @internal */
107
95
  post(message) {
108
96
  if (!this.closed)
@@ -113,16 +101,14 @@ export class Client {
113
101
  return Promise.reject(new ClientError("closed", "closed"));
114
102
  const id = this.nextId++;
115
103
  return new Promise((resolve, reject) => {
116
- // Cancelled by the server, so the rejection is its `cancelled`,
117
- // also when the signal was aborted already.
118
- const cancel = () => this.post({ type: "cancel", id });
119
- const done = () => signal?.removeEventListener("abort", cancel);
104
+ const cancelOnServer = () => this.post({ type: "cancel", id });
105
+ const done = () => signal?.removeEventListener("abort", cancelOnServer);
120
106
  this.pending.set(id, { resolve: resolve, reject, done });
121
107
  this.post({ type: "request", id, method, params });
122
108
  if (signal?.aborted)
123
- cancel();
109
+ cancelOnServer();
124
110
  else
125
- signal?.addEventListener("abort", cancel, { once: true });
111
+ signal?.addEventListener("abort", cancelOnServer, { once: true });
126
112
  });
127
113
  }
128
114
  describe(method) {
@@ -199,18 +185,12 @@ export class Client {
199
185
  * `onLink` reports the connection-level changes. Requests need
200
186
  * `connected`. A listener added later gets the latest at once. */
201
187
  onLink(listener) {
202
- this.linkListeners.add(listener);
203
- if (this.link)
204
- listener(this.link);
205
- return () => void this.linkListeners.delete(listener);
188
+ return this.linkListeners.add(listener);
206
189
  }
207
190
  /** Every session on the server, at each change; a listener added once
208
191
  * the list is known gets it at once. */
209
192
  onSessions(listener) {
210
- this.sessionListeners.add(listener);
211
- if (this.latest)
212
- listener(this.latest);
213
- return () => void this.sessionListeners.delete(listener);
193
+ return this.sessionListeners.add(listener);
214
194
  }
215
195
  /** Each server event, in `seq` order, without loss across reconnects:
216
196
  * the ones missed while the connection was down are replayed, or an
@@ -227,28 +207,18 @@ export class Client {
227
207
  const id = this.nextId++;
228
208
  const host = {
229
209
  send: (message) => this.post(message),
230
- receive: (handler) => {
231
- if (handler)
232
- this.mounts.set(id, handler);
233
- else
234
- this.mounts.delete(id);
235
- },
236
- };
237
- const terminal = mountOn(host, id, options);
238
- const dispose = terminal.dispose;
239
- terminal.dispose = () => {
240
- this.terminals.delete(terminal);
241
- dispose();
210
+ disposed: () => void this.mounts.delete(id),
242
211
  };
243
- this.terminals.add(terminal);
244
- return terminal;
212
+ const mounted = mountOn(host, id, options);
213
+ this.mounts.set(id, mounted);
214
+ return mounted.terminal;
245
215
  }
246
216
  /** Disposes the terminals and terminates the worker, which ends the
247
217
  * connection; requests in flight reject with `closed`. */
248
218
  close() {
249
219
  if (this.closed)
250
220
  return;
251
- for (const terminal of [...this.terminals])
221
+ for (const { terminal } of [...this.mounts.values()])
252
222
  terminal.dispose();
253
223
  this.closed = true;
254
224
  this.worker.onmessage = null;
@@ -1,13 +1,10 @@
1
1
  import { type Catalog, type Description, type ErrorCode, type ErrorMessage, type Event, type Frame, FrameType, type Hello, type Peer, type Welcome } from "../proto/index.ts";
2
- /** A message-oriented byte transport: one frame per message, as over WebSocket. */
3
2
  export interface Transport {
4
3
  send(bytes: Uint8Array): void;
5
4
  close(): void;
6
5
  onMessage: ((bytes: Uint8Array) => void) | undefined;
7
6
  onClose: (() => void) | undefined;
8
7
  }
9
- /** `desync`: a stream frame did not continue from the cursor; a fresh
10
- * OPEN recovers it, where any other fault would only repeat. */
11
8
  export type ErrorKind = "protocol" | "desync" | "server" | "closed";
12
9
  /** A failed request or connection. `kind: "server"` carries the server's
13
10
  * `ERROR` as `server`, and its code as `code`: a refused request, or a
@@ -22,13 +19,7 @@ export declare class ClientError extends Error {
22
19
  static desync(message: string): ClientError;
23
20
  static fromServer(error: ErrorMessage): ClientError;
24
21
  }
25
- /** `HELLO` for `client`: a name and version, or a name with this
26
- * package's version. */
27
22
  export declare function hello(client: string | Peer, engine?: string): Hello;
28
- /**
29
- * One protocol connection: the handshake, requests answered by id, events,
30
- * and attachment channels routed to their receivers.
31
- */
32
23
  export declare class Connection {
33
24
  private readonly transport;
34
25
  readonly welcome: Welcome;
@@ -36,29 +27,20 @@ export declare class Connection {
36
27
  private readonly pending;
37
28
  private readonly channels;
38
29
  private ended;
39
- /** Session events, once subscribed. */
40
30
  onEvent: ((event: Event) => void) | undefined;
41
- /** The connection ended: the transport closed, or an error without id. */
42
31
  onEnd: ((error: ClientError) => void) | undefined;
43
32
  private constructor();
44
- /** Sends `HELLO` and resolves at `WELCOME`; rejects on an `ERROR` or close. */
45
33
  static connect(transport: Transport, hello: Hello): Promise<Connection>;
46
34
  send(type: FrameType, channel: number, payload: Uint8Array): void;
47
35
  sendJson(type: FrameType, channel: number, body: unknown): void;
48
- /** A request; the reply's `result`, or a rejection with the server's error. */
49
36
  call<R>(method: string, params: unknown): Promise<R>;
50
- /** A request and its id on this connection, which `cancel` takes. */
51
37
  request<R>(method: string, params: unknown): {
52
38
  id: number;
53
39
  reply: Promise<R>;
54
40
  };
55
- /** The server's catalog (`describe {}`), or one method of it. */
56
41
  describe(): Promise<Catalog>;
57
42
  describe(method: string): Promise<Description>;
58
- /** Opens `channel`; its frames go to `receive` until `release` or the
59
- * connection's end. */
60
43
  open(channel: number, open: unknown, receive: (frame: Frame) => void): void;
61
- /** Stops routing `channel`; later frames on it are dropped. */
62
44
  release(channel: number): void;
63
45
  close(): void;
64
46
  private route;
@@ -25,11 +25,7 @@ export class ClientError extends Error {
25
25
  return new ClientError("server", `${error.code}: ${error.message}`, error);
26
26
  }
27
27
  }
28
- /** Frames before `WELCOME` tells us the real limit: the protocol's
29
- * default `max_frame`, as the Rust client. */
30
28
  const HELLO_MAX_FRAME = 1024 * 1024;
31
- /** `HELLO` for `client`: a name and version, or a name with this
32
- * package's version. */
33
29
  export function hello(client, engine) {
34
30
  const peer = typeof client === "string" ? { name: client, version: pkg.version } : client;
35
31
  const h = { version: VERSION, client: peer, capabilities: [] };
@@ -37,10 +33,6 @@ export function hello(client, engine) {
37
33
  h.engine = engine;
38
34
  return h;
39
35
  }
40
- /**
41
- * One protocol connection: the handshake, requests answered by id, events,
42
- * and attachment channels routed to their receivers.
43
- */
44
36
  export class Connection {
45
37
  transport;
46
38
  welcome;
@@ -48,9 +40,7 @@ export class Connection {
48
40
  pending = new Map();
49
41
  channels = new Map();
50
42
  ended;
51
- /** Session events, once subscribed. */
52
43
  onEvent;
53
- /** The connection ended: the transport closed, or an error without id. */
54
44
  onEnd;
55
45
  constructor(transport, welcome) {
56
46
  this.transport = transport;
@@ -58,7 +48,6 @@ export class Connection {
58
48
  transport.onMessage = (bytes) => this.route(bytes);
59
49
  transport.onClose = () => this.end(new ClientError("closed", "connection closed"));
60
50
  }
61
- /** Sends `HELLO` and resolves at `WELCOME`; rejects on an `ERROR` or close. */
62
51
  static connect(transport, hello) {
63
52
  return new Promise((resolve, reject) => {
64
53
  transport.onMessage = (bytes) => {
@@ -91,11 +80,9 @@ export class Connection {
91
80
  sendJson(type, channel, body) {
92
81
  this.send(type, channel, new TextEncoder().encode(JSON.stringify(body)));
93
82
  }
94
- /** A request; the reply's `result`, or a rejection with the server's error. */
95
83
  call(method, params) {
96
84
  return this.request(method, params).reply;
97
85
  }
98
- /** A request and its id on this connection, which `cancel` takes. */
99
86
  request(method, params) {
100
87
  const id = this.nextId++;
101
88
  const reply = new Promise((resolve, reject) => {
@@ -113,15 +100,12 @@ export class Connection {
113
100
  describe(method) {
114
101
  return this.call("describe", method === undefined ? {} : { method });
115
102
  }
116
- /** Opens `channel`; its frames go to `receive` until `release` or the
117
- * connection's end. */
118
103
  open(channel, open, receive) {
119
104
  if (this.ended)
120
105
  throw this.ended;
121
106
  this.channels.set(channel, receive);
122
107
  this.sendJson(FrameType.Open, channel, open);
123
108
  }
124
- /** Stops routing `channel`; later frames on it are dropped. */
125
109
  release(channel) {
126
110
  this.channels.delete(channel);
127
111
  }
@@ -151,7 +135,6 @@ export class Connection {
151
135
  }
152
136
  switch (frame.header.type) {
153
137
  case FrameType.Reply: {
154
- // A reply or error for a request no longer waited for is dropped.
155
138
  const reply = body;
156
139
  this.pending.get(reply.id)?.resolve(reply.result);
157
140
  this.pending.delete(reply.id);
@@ -1,4 +1,3 @@
1
- /** The page's copies to the clipboard, and what each came to. */
2
1
  /** What started a copy: the release of a selection, Ctrl+Shift+C, the
3
2
  * browser's copy (Cmd+C, the Copy menu), or the program (OSC 52). */
4
3
  export type CopySource = "release" | "keys" | "browser" | "program";
@@ -19,31 +18,21 @@ export type Copy = {
19
18
  chars?: number;
20
19
  message?: string;
21
20
  };
22
- /** The parts of `navigator.clipboard` a copy uses. */
23
21
  export interface ClipboardLike {
24
22
  write?(items: ClipboardItem[]): Promise<void>;
25
23
  writeText?(text: string): Promise<void>;
26
24
  }
27
25
  export interface CopyHost {
28
- /** The clipboard, read at each copy; undefined where there is none. */
29
26
  clipboard(): ClipboardLike | undefined;
30
- /** A `ClipboardItem` of text to come; undefined where the browser has
31
- * no `ClipboardItem`. */
32
27
  item: ((text: Promise<Blob>) => ClipboardItem) | undefined;
33
28
  report(copy: Copy): void;
34
29
  }
35
- /** How long a copy may take: the worker's answer and the write. */
36
- export declare const COPY_TIMEOUT_MS = 2000;
37
- /** A mounted terminal's copies. */
38
30
  export declare class Copier {
39
31
  private readonly host;
40
- private readonly timeoutMs;
41
- /** The releases' copies waiting for the worker's answer, by number. */
42
- private readonly pending;
32
+ private pending;
43
33
  private next;
44
- /** Every copy not yet reported or dropped, for `dispose`. */
45
34
  private readonly live;
46
- constructor(host: CopyHost, timeoutMs?: number);
35
+ constructor(host: CopyHost);
47
36
  /** Starts the copy of what a release selected, and returns its number
48
37
  * for the worker's answer. Safari writes to the clipboard only within
49
38
  * the user's gesture, which is over before the worker answers: the
@@ -53,15 +42,9 @@ export declare class Copier {
53
42
  * release's copy still waiting is dropped, so the clipboard gets the
54
43
  * latest. */
55
44
  start(): number;
56
- /** The worker's answer to release `id`: the selected text, or undefined
57
- * when nothing was selected, which is no copy. An answer to a copy that
58
- * was dropped or timed out is ignored. */
59
45
  answer(id: number, text: string | undefined): void;
60
- /** Copies `text` known now. */
61
46
  write(text: string, source: CopySource): void;
62
- /** A copy the browser made itself (the `copy` event's data). */
63
- copied(text: string, source: CopySource): void;
64
- /** Drops every copy under way, unreported. */
47
+ copied(text: string): void;
65
48
  dispose(): void;
66
49
  private attempt;
67
50
  private dropOne;