@blit-sh/core 0.17.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/dist/BlitConnection.d.ts +132 -0
- package/dist/BlitConnection.d.ts.map +1 -0
- package/dist/BlitConnection.js +875 -0
- package/dist/BlitConnection.js.map +1 -0
- package/dist/BlitWorkspace.d.ts +65 -0
- package/dist/BlitWorkspace.d.ts.map +1 -0
- package/dist/BlitWorkspace.js +298 -0
- package/dist/BlitWorkspace.js.map +1 -0
- package/dist/TerminalStore.d.ts +125 -0
- package/dist/TerminalStore.d.ts.map +1 -0
- package/dist/TerminalStore.js +468 -0
- package/dist/TerminalStore.js.map +1 -0
- package/dist/bsp/dsl.d.ts +56 -0
- package/dist/bsp/dsl.d.ts.map +1 -0
- package/dist/bsp/dsl.js +247 -0
- package/dist/bsp/dsl.js.map +1 -0
- package/dist/bsp/index.d.ts +5 -0
- package/dist/bsp/index.d.ts.map +1 -0
- package/dist/bsp/index.js +3 -0
- package/dist/bsp/index.js.map +1 -0
- package/dist/bsp/layout.d.ts +32 -0
- package/dist/bsp/layout.d.ts.map +1 -0
- package/dist/bsp/layout.js +84 -0
- package/dist/bsp/layout.js.map +1 -0
- package/dist/gl-renderer.d.ts +10 -0
- package/dist/gl-renderer.d.ts.map +1 -0
- package/dist/gl-renderer.js +297 -0
- package/dist/gl-renderer.js.map +1 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +13 -0
- package/dist/index.js.map +1 -0
- package/dist/keyboard.d.ts +7 -0
- package/dist/keyboard.d.ts.map +1 -0
- package/dist/keyboard.js +118 -0
- package/dist/keyboard.js.map +1 -0
- package/dist/measure.d.ts +19 -0
- package/dist/measure.d.ts.map +1 -0
- package/dist/measure.js +55 -0
- package/dist/measure.js.map +1 -0
- package/dist/palettes.d.ts +3 -0
- package/dist/palettes.d.ts.map +1 -0
- package/dist/palettes.js +803 -0
- package/dist/palettes.js.map +1 -0
- package/dist/protocol.d.ts +34 -0
- package/dist/protocol.d.ts.map +1 -0
- package/dist/protocol.js +195 -0
- package/dist/protocol.js.map +1 -0
- package/dist/transports/index.d.ts +8 -0
- package/dist/transports/index.d.ts.map +1 -0
- package/dist/transports/index.js +5 -0
- package/dist/transports/index.js.map +1 -0
- package/dist/transports/webrtc-share.d.ts +11 -0
- package/dist/transports/webrtc-share.d.ts.map +1 -0
- package/dist/transports/webrtc-share.js +299 -0
- package/dist/transports/webrtc-share.js.map +1 -0
- package/dist/transports/webrtc.d.ts +11 -0
- package/dist/transports/webrtc.d.ts.map +1 -0
- package/dist/transports/webrtc.js +234 -0
- package/dist/transports/webrtc.js.map +1 -0
- package/dist/transports/websocket.d.ts +37 -0
- package/dist/transports/websocket.d.ts.map +1 -0
- package/dist/transports/websocket.js +200 -0
- package/dist/transports/websocket.js.map +1 -0
- package/dist/transports/webtransport.d.ts +53 -0
- package/dist/transports/webtransport.d.ts.map +1 -0
- package/dist/transports/webtransport.js +277 -0
- package/dist/transports/webtransport.js.map +1 -0
- package/dist/types.d.ts +163 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +42 -0
- package/dist/types.js.map +1 -0
- package/package.json +75 -0
|
@@ -0,0 +1,468 @@
|
|
|
1
|
+
import { DEFAULT_FONT, DEFAULT_FONT_SIZE } from "./types";
|
|
2
|
+
import { buildAckMessage, buildClientMetricsMessage, buildDisplayRateMessage, buildSubscribeMessage, buildUnsubscribeMessage, } from "./protocol";
|
|
3
|
+
import { createGlRenderer } from "./gl-renderer";
|
|
4
|
+
export class TerminalStore {
|
|
5
|
+
constructor(delegate, wasm) {
|
|
6
|
+
this.mod = null;
|
|
7
|
+
this.terminals = new Map();
|
|
8
|
+
this.staleTerminals = new Map();
|
|
9
|
+
this.retainCount = new Map();
|
|
10
|
+
this.pendingFree = new Set();
|
|
11
|
+
this.subscribed = new Set();
|
|
12
|
+
this.desired = new Set();
|
|
13
|
+
this.dirtyListeners = new Set();
|
|
14
|
+
this.leadPtyId = null;
|
|
15
|
+
this.fontFamily = DEFAULT_FONT;
|
|
16
|
+
this.fontSize = DEFAULT_FONT_SIZE *
|
|
17
|
+
(typeof devicePixelRatio !== "undefined" ? devicePixelRatio : 1);
|
|
18
|
+
this.cellPw = 1;
|
|
19
|
+
this.cellPh = 1;
|
|
20
|
+
this.palette = null;
|
|
21
|
+
this.disposed = false;
|
|
22
|
+
this.ready = false;
|
|
23
|
+
this.readyListeners = new Set();
|
|
24
|
+
this.frozenPtys = new Set();
|
|
25
|
+
/** Incremented every time any terminal's cell metrics are set, so renderers can detect stale state. */
|
|
26
|
+
this.metricsGeneration = 0;
|
|
27
|
+
this.frozenBuffers = new Map();
|
|
28
|
+
this.sharedRenderer = null;
|
|
29
|
+
this.sharedCanvas = null;
|
|
30
|
+
this.displayFps = 0;
|
|
31
|
+
this.rafHandle = 0;
|
|
32
|
+
this.rafPrev = 0;
|
|
33
|
+
this.rafSamples = [];
|
|
34
|
+
this.pendingAppliedFrames = 0;
|
|
35
|
+
this.ackAheadFrames = 0;
|
|
36
|
+
this.applyMsX10 = 0;
|
|
37
|
+
this.metricsFlushQueued = false;
|
|
38
|
+
this.metricsHeartbeat = null;
|
|
39
|
+
this.pendingAcks = 0;
|
|
40
|
+
/** Queued compressed payloads per PTY, drained in the rAF callback. */
|
|
41
|
+
this.pendingFrames = new Map();
|
|
42
|
+
this._wasmMem = null;
|
|
43
|
+
this.delegate = delegate;
|
|
44
|
+
this.startRafProbe();
|
|
45
|
+
if (wasm instanceof Promise) {
|
|
46
|
+
wasm
|
|
47
|
+
.then((mod) => {
|
|
48
|
+
if (this.disposed)
|
|
49
|
+
return;
|
|
50
|
+
this.mod = mod;
|
|
51
|
+
this.ready = true;
|
|
52
|
+
for (const l of this.readyListeners)
|
|
53
|
+
l();
|
|
54
|
+
})
|
|
55
|
+
.catch((err) => {
|
|
56
|
+
console.error("blit: failed to load WASM module:", err);
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
this.mod = wasm;
|
|
61
|
+
this.ready = true;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
nowMs() {
|
|
65
|
+
if (typeof performance !== "undefined" &&
|
|
66
|
+
typeof performance.now === "function") {
|
|
67
|
+
return performance.now();
|
|
68
|
+
}
|
|
69
|
+
return Date.now();
|
|
70
|
+
}
|
|
71
|
+
resetClientMetrics() {
|
|
72
|
+
this.pendingAppliedFrames = 0;
|
|
73
|
+
this.ackAheadFrames = 0;
|
|
74
|
+
this.applyMsX10 = 0;
|
|
75
|
+
this.metricsFlushQueued = false;
|
|
76
|
+
}
|
|
77
|
+
queueClientMetricsFlush() {
|
|
78
|
+
if (this.metricsFlushQueued)
|
|
79
|
+
return;
|
|
80
|
+
this.metricsFlushQueued = true;
|
|
81
|
+
const flush = () => {
|
|
82
|
+
this.metricsFlushQueued = false;
|
|
83
|
+
this.flushClientMetrics();
|
|
84
|
+
};
|
|
85
|
+
if (typeof queueMicrotask === "function") {
|
|
86
|
+
queueMicrotask(flush);
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
void Promise.resolve().then(flush);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
startMetricsHeartbeat() {
|
|
93
|
+
this.stopMetricsHeartbeat();
|
|
94
|
+
// Send metrics every 250ms so the server always has fresh backlog info,
|
|
95
|
+
// even when no renders are happening (which would otherwise cause a
|
|
96
|
+
// deadlock: server stops sending because backlog is high, client never
|
|
97
|
+
// renders because no new frames arrive, backlog never clears).
|
|
98
|
+
this.metricsHeartbeat = setInterval(() => this.flushClientMetrics(), 250);
|
|
99
|
+
}
|
|
100
|
+
stopMetricsHeartbeat() {
|
|
101
|
+
if (this.metricsHeartbeat !== null) {
|
|
102
|
+
clearInterval(this.metricsHeartbeat);
|
|
103
|
+
this.metricsHeartbeat = null;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
flushClientMetrics() {
|
|
107
|
+
if (this.disposed || this.delegate.getStatus() !== "connected")
|
|
108
|
+
return;
|
|
109
|
+
this.delegate.send(buildClientMetricsMessage(Math.min(this.pendingAppliedFrames, 0xffff), Math.min(this.ackAheadFrames, 0xffff), Math.min(this.applyMsX10, 0xffff)));
|
|
110
|
+
}
|
|
111
|
+
noteAppliedFrame(applyMs) {
|
|
112
|
+
this.pendingAppliedFrames = Math.min(this.pendingAppliedFrames + 1, 0xffff);
|
|
113
|
+
this.ackAheadFrames = Math.min(this.ackAheadFrames + 1, 0xffff);
|
|
114
|
+
const sampleX10 = Math.min(Math.round(applyMs * 10), 0xffff);
|
|
115
|
+
this.applyMsX10 =
|
|
116
|
+
this.applyMsX10 > 0
|
|
117
|
+
? Math.round(this.applyMsX10 * 0.8 + sampleX10 * 0.2)
|
|
118
|
+
: sampleX10;
|
|
119
|
+
this.queueClientMetricsFlush();
|
|
120
|
+
}
|
|
121
|
+
isReady() {
|
|
122
|
+
return this.ready;
|
|
123
|
+
}
|
|
124
|
+
/** Get the WASM linear memory for zero-copy typed array views. */
|
|
125
|
+
wasmMemory() {
|
|
126
|
+
if (this._wasmMem)
|
|
127
|
+
return this._wasmMem;
|
|
128
|
+
if (!this.mod)
|
|
129
|
+
return null;
|
|
130
|
+
const m = this.mod;
|
|
131
|
+
if (typeof m.wasm_memory === "function") {
|
|
132
|
+
this._wasmMem = m.wasm_memory();
|
|
133
|
+
return this._wasmMem;
|
|
134
|
+
}
|
|
135
|
+
return null;
|
|
136
|
+
}
|
|
137
|
+
onReady(listener) {
|
|
138
|
+
if (this.ready) {
|
|
139
|
+
listener();
|
|
140
|
+
return () => { };
|
|
141
|
+
}
|
|
142
|
+
this.readyListeners.add(listener);
|
|
143
|
+
return () => this.readyListeners.delete(listener);
|
|
144
|
+
}
|
|
145
|
+
createTerminal() {
|
|
146
|
+
const t = new this.mod.Terminal(24, 80, this.cellPw, this.cellPh);
|
|
147
|
+
if (typeof t.set_font_family === "function")
|
|
148
|
+
t.set_font_family(this.fontFamily);
|
|
149
|
+
if (typeof t.set_font_size === "function")
|
|
150
|
+
t.set_font_size(this.fontSize);
|
|
151
|
+
if (this.palette) {
|
|
152
|
+
t.set_default_colors(...this.palette.fg, ...this.palette.bg);
|
|
153
|
+
for (let i = 0; i < 16; i++)
|
|
154
|
+
t.set_ansi_color(i, ...this.palette.ansi[i]);
|
|
155
|
+
}
|
|
156
|
+
return t;
|
|
157
|
+
}
|
|
158
|
+
handleUpdate(ptyId, payload) {
|
|
159
|
+
this.pendingAcks++;
|
|
160
|
+
// Buffer frames for frozen PTYs (e.g. during selection).
|
|
161
|
+
if (this.frozenPtys.has(ptyId)) {
|
|
162
|
+
let buf = this.frozenBuffers.get(ptyId);
|
|
163
|
+
if (!buf) {
|
|
164
|
+
buf = [];
|
|
165
|
+
this.frozenBuffers.set(ptyId, buf);
|
|
166
|
+
}
|
|
167
|
+
buf.push(new Uint8Array(payload));
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
const applyStart = this.nowMs();
|
|
171
|
+
let terminal = this.terminals.get(ptyId);
|
|
172
|
+
if (!terminal) {
|
|
173
|
+
if (!this.mod)
|
|
174
|
+
return;
|
|
175
|
+
terminal = this.createTerminal();
|
|
176
|
+
this.terminals.set(ptyId, terminal);
|
|
177
|
+
const stale = this.staleTerminals.get(ptyId);
|
|
178
|
+
if (stale) {
|
|
179
|
+
this.staleTerminals.delete(ptyId);
|
|
180
|
+
stale.free();
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
terminal.feed_compressed(payload);
|
|
184
|
+
this.noteAppliedFrame(this.nowMs() - applyStart);
|
|
185
|
+
for (const listener of this.dirtyListeners)
|
|
186
|
+
listener(ptyId);
|
|
187
|
+
}
|
|
188
|
+
handleStatusChange(status) {
|
|
189
|
+
if (status === "connected") {
|
|
190
|
+
this.resetClientMetrics();
|
|
191
|
+
this.flushClientMetrics();
|
|
192
|
+
this.resync();
|
|
193
|
+
this.startMetricsHeartbeat();
|
|
194
|
+
}
|
|
195
|
+
else if (status === "disconnected" || status === "error") {
|
|
196
|
+
this.subscribed.clear();
|
|
197
|
+
this.resetClientMetrics();
|
|
198
|
+
this.pendingAcks = 0;
|
|
199
|
+
this.stopMetricsHeartbeat();
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
getTerminal(ptyId) {
|
|
203
|
+
return this.terminals.get(ptyId) ?? this.staleTerminals.get(ptyId) ?? null;
|
|
204
|
+
}
|
|
205
|
+
setLead(ptyId) {
|
|
206
|
+
this.leadPtyId = ptyId;
|
|
207
|
+
}
|
|
208
|
+
setFontFamily(fontFamily) {
|
|
209
|
+
this.fontFamily = fontFamily;
|
|
210
|
+
}
|
|
211
|
+
setFontSize(fontSize) {
|
|
212
|
+
this.fontSize = fontSize;
|
|
213
|
+
}
|
|
214
|
+
/** Get a shared GL renderer for readOnly (preview) terminals. */
|
|
215
|
+
getSharedRenderer() {
|
|
216
|
+
if (this.sharedRenderer?.supported) {
|
|
217
|
+
return { renderer: this.sharedRenderer, canvas: this.sharedCanvas };
|
|
218
|
+
}
|
|
219
|
+
if (!this.sharedCanvas) {
|
|
220
|
+
this.sharedCanvas = document.createElement("canvas");
|
|
221
|
+
}
|
|
222
|
+
this.sharedRenderer = createGlRenderer(this.sharedCanvas);
|
|
223
|
+
if (!this.sharedRenderer.supported)
|
|
224
|
+
return null;
|
|
225
|
+
return { renderer: this.sharedRenderer, canvas: this.sharedCanvas };
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Drain queued compressed frames for a PTY into the WASM terminal.
|
|
229
|
+
* Called at the start of the rAF callback so decode + render happen
|
|
230
|
+
* in one JS turn, avoiding budget fragmentation.
|
|
231
|
+
* Returns true if any frames were applied.
|
|
232
|
+
*/
|
|
233
|
+
drainPending(ptyId) {
|
|
234
|
+
const q = this.pendingFrames.get(ptyId);
|
|
235
|
+
if (!q || q.length === 0)
|
|
236
|
+
return false;
|
|
237
|
+
const t = this.terminals.get(ptyId);
|
|
238
|
+
if (!t) {
|
|
239
|
+
q.length = 0;
|
|
240
|
+
return false;
|
|
241
|
+
}
|
|
242
|
+
const applyStart = this.nowMs();
|
|
243
|
+
for (const payload of q) {
|
|
244
|
+
t.feed_compressed(payload);
|
|
245
|
+
}
|
|
246
|
+
q.length = 0;
|
|
247
|
+
this.noteAppliedFrame(this.nowMs() - applyStart);
|
|
248
|
+
return true;
|
|
249
|
+
}
|
|
250
|
+
/** Mark the latest applied terminal state as painted to the screen. */
|
|
251
|
+
noteFrameRendered() {
|
|
252
|
+
// Send ACKs now that the frames have been rendered — not before.
|
|
253
|
+
// This keeps ACKs in sync with actual rendering, so the server's
|
|
254
|
+
// RTT measurement reflects render time and backlog stays accurate.
|
|
255
|
+
while (this.pendingAcks > 0 && this.delegate.getStatus() === "connected") {
|
|
256
|
+
this.pendingAcks--;
|
|
257
|
+
this.delegate.send(buildAckMessage());
|
|
258
|
+
}
|
|
259
|
+
this.pendingAppliedFrames = 0;
|
|
260
|
+
this.ackAheadFrames = 0;
|
|
261
|
+
this.queueClientMetricsFlush();
|
|
262
|
+
}
|
|
263
|
+
getDebugStats(leadPtyId) {
|
|
264
|
+
let totalPending = 0;
|
|
265
|
+
for (const q of this.pendingFrames.values())
|
|
266
|
+
totalPending += q.length;
|
|
267
|
+
const lead = leadPtyId != null ? this.terminals.get(leadPtyId) : null;
|
|
268
|
+
return {
|
|
269
|
+
displayFps: this.displayFps,
|
|
270
|
+
pendingApplied: this.pendingAppliedFrames,
|
|
271
|
+
ackAhead: this.ackAheadFrames,
|
|
272
|
+
applyMs: this.applyMsX10 / 10,
|
|
273
|
+
mouseMode: lead ? lead.mouse_mode() : 0,
|
|
274
|
+
mouseEncoding: lead ? lead.mouse_encoding() : 0,
|
|
275
|
+
terminals: this.terminals.size,
|
|
276
|
+
staleTerminals: this.staleTerminals.size,
|
|
277
|
+
subscribed: this.subscribed.size,
|
|
278
|
+
frozenPtys: this.frozenPtys.size,
|
|
279
|
+
pendingFrameQueues: this.pendingFrames.size,
|
|
280
|
+
totalPendingFrames: totalPending,
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
invalidateAtlas() {
|
|
284
|
+
for (const t of this.terminals.values()) {
|
|
285
|
+
t.invalidate_render_cache();
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
setPalette(palette) {
|
|
289
|
+
this.palette = palette;
|
|
290
|
+
for (const t of this.terminals.values()) {
|
|
291
|
+
t.set_default_colors(...palette.fg, ...palette.bg);
|
|
292
|
+
for (let i = 0; i < 16; i++)
|
|
293
|
+
t.set_ansi_color(i, ...palette.ansi[i]);
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
setCellSize(pw, ph) {
|
|
297
|
+
this.cellPw = pw;
|
|
298
|
+
this.cellPh = ph;
|
|
299
|
+
}
|
|
300
|
+
getCellSize() {
|
|
301
|
+
return { pw: this.cellPw, ph: this.cellPh };
|
|
302
|
+
}
|
|
303
|
+
/** Freeze a PTY: buffer incoming frames instead of applying them. */
|
|
304
|
+
freeze(ptyId) {
|
|
305
|
+
this.frozenPtys.add(ptyId);
|
|
306
|
+
}
|
|
307
|
+
isFrozen(ptyId) {
|
|
308
|
+
return this.frozenPtys.has(ptyId);
|
|
309
|
+
}
|
|
310
|
+
/** Thaw a PTY: apply all buffered frames and resume normal updates. */
|
|
311
|
+
thaw(ptyId) {
|
|
312
|
+
this.frozenPtys.delete(ptyId);
|
|
313
|
+
const buf = this.frozenBuffers.get(ptyId);
|
|
314
|
+
if (buf && buf.length > 0) {
|
|
315
|
+
this.frozenBuffers.delete(ptyId);
|
|
316
|
+
let t = this.terminals.get(ptyId);
|
|
317
|
+
if (!t && this.mod) {
|
|
318
|
+
t = this.createTerminal();
|
|
319
|
+
this.terminals.set(ptyId, t);
|
|
320
|
+
}
|
|
321
|
+
if (t) {
|
|
322
|
+
for (const frame of buf) {
|
|
323
|
+
t.feed_compressed(frame);
|
|
324
|
+
}
|
|
325
|
+
for (const l of this.dirtyListeners)
|
|
326
|
+
l(ptyId);
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
else {
|
|
330
|
+
this.frozenBuffers.delete(ptyId);
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
setDesiredSubscriptions(ptyIds) {
|
|
334
|
+
this.desired = new Set(ptyIds);
|
|
335
|
+
this.syncSubscriptions();
|
|
336
|
+
}
|
|
337
|
+
/**
|
|
338
|
+
* Get the current retain count for a PTY.
|
|
339
|
+
*/
|
|
340
|
+
getRetainCount(ptyId) {
|
|
341
|
+
return this.retainCount.get(ptyId) ?? 0;
|
|
342
|
+
}
|
|
343
|
+
retain(ptyId) {
|
|
344
|
+
this.retainCount.set(ptyId, (this.retainCount.get(ptyId) ?? 0) + 1);
|
|
345
|
+
}
|
|
346
|
+
release(ptyId) {
|
|
347
|
+
const count = (this.retainCount.get(ptyId) ?? 1) - 1;
|
|
348
|
+
if (count <= 0) {
|
|
349
|
+
this.retainCount.delete(ptyId);
|
|
350
|
+
if (this.pendingFree.has(ptyId)) {
|
|
351
|
+
this.pendingFree.delete(ptyId);
|
|
352
|
+
this.doFree(ptyId);
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
else {
|
|
356
|
+
this.retainCount.set(ptyId, count);
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
freeTerminal(ptyId) {
|
|
360
|
+
if ((this.retainCount.get(ptyId) ?? 0) > 0) {
|
|
361
|
+
this.pendingFree.add(ptyId);
|
|
362
|
+
}
|
|
363
|
+
else {
|
|
364
|
+
this.doFree(ptyId);
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
doFree(ptyId) {
|
|
368
|
+
this.pendingFrames.delete(ptyId);
|
|
369
|
+
const t = this.terminals.get(ptyId);
|
|
370
|
+
if (t) {
|
|
371
|
+
t.free();
|
|
372
|
+
this.terminals.delete(ptyId);
|
|
373
|
+
}
|
|
374
|
+
this.subscribed.delete(ptyId);
|
|
375
|
+
}
|
|
376
|
+
addDirtyListener(listener) {
|
|
377
|
+
this.dirtyListeners.add(listener);
|
|
378
|
+
return () => this.dirtyListeners.delete(listener);
|
|
379
|
+
}
|
|
380
|
+
syncSubscriptions() {
|
|
381
|
+
if (this.delegate.getStatus() !== "connected")
|
|
382
|
+
return;
|
|
383
|
+
for (const id of this.desired) {
|
|
384
|
+
if (!this.subscribed.has(id)) {
|
|
385
|
+
this.subscribed.add(id);
|
|
386
|
+
// Move the old terminal to stale so the component can keep
|
|
387
|
+
// rendering it until the first fresh frame arrives and creates
|
|
388
|
+
// a new terminal — avoids a black flash.
|
|
389
|
+
const old = this.terminals.get(id);
|
|
390
|
+
if (old) {
|
|
391
|
+
this.terminals.delete(id);
|
|
392
|
+
this.staleTerminals.set(id, old);
|
|
393
|
+
}
|
|
394
|
+
this.delegate.send(buildSubscribeMessage(id));
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
for (const id of this.subscribed) {
|
|
398
|
+
if (!this.desired.has(id)) {
|
|
399
|
+
this.subscribed.delete(id);
|
|
400
|
+
this.delegate.send(buildUnsubscribeMessage(id));
|
|
401
|
+
// Don't free the terminal — BlitTerminal may still hold a ref.
|
|
402
|
+
// It will be freed on PTY close or store dispose.
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
sendDisplayFps() {
|
|
407
|
+
if (this.displayFps > 0 && this.delegate.getStatus() === "connected") {
|
|
408
|
+
this.delegate.send(buildDisplayRateMessage(this.displayFps));
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
startRafProbe() {
|
|
412
|
+
if (this.rafHandle || typeof requestAnimationFrame === "undefined")
|
|
413
|
+
return;
|
|
414
|
+
const measure = (ts) => {
|
|
415
|
+
if (this.disposed)
|
|
416
|
+
return;
|
|
417
|
+
if (this.rafPrev > 0) {
|
|
418
|
+
const dt = ts - this.rafPrev;
|
|
419
|
+
if (dt > 0) {
|
|
420
|
+
this.rafSamples.push(dt);
|
|
421
|
+
if (this.rafSamples.length >= 20) {
|
|
422
|
+
this.rafSamples.sort((a, b) => a - b);
|
|
423
|
+
const median = this.rafSamples[this.rafSamples.length >> 1];
|
|
424
|
+
const fps = Math.round(1000 / median);
|
|
425
|
+
this.rafSamples = [];
|
|
426
|
+
if (fps > 0 && fps !== this.displayFps) {
|
|
427
|
+
this.displayFps = fps;
|
|
428
|
+
this.sendDisplayFps();
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
this.rafPrev = ts;
|
|
434
|
+
this.rafHandle = requestAnimationFrame(measure);
|
|
435
|
+
};
|
|
436
|
+
this.rafHandle = requestAnimationFrame(measure);
|
|
437
|
+
}
|
|
438
|
+
stopRafProbe() {
|
|
439
|
+
if (this.rafHandle) {
|
|
440
|
+
cancelAnimationFrame(this.rafHandle);
|
|
441
|
+
this.rafHandle = 0;
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
resync() {
|
|
445
|
+
this.sendDisplayFps();
|
|
446
|
+
this.subscribed.clear();
|
|
447
|
+
this.syncSubscriptions();
|
|
448
|
+
}
|
|
449
|
+
/** Permanently destroy the store — free all WASM terminals and GL resources. */
|
|
450
|
+
destroy() {
|
|
451
|
+
this.disposed = true;
|
|
452
|
+
this.stopRafProbe();
|
|
453
|
+
this.stopMetricsHeartbeat();
|
|
454
|
+
for (const t of this.terminals.values())
|
|
455
|
+
t.free();
|
|
456
|
+
this.terminals.clear();
|
|
457
|
+
for (const t of this.staleTerminals.values())
|
|
458
|
+
t.free();
|
|
459
|
+
this.staleTerminals.clear();
|
|
460
|
+
this.subscribed.clear();
|
|
461
|
+
this.dirtyListeners.clear();
|
|
462
|
+
this.readyListeners.clear();
|
|
463
|
+
this.sharedRenderer?.dispose();
|
|
464
|
+
this.sharedRenderer = null;
|
|
465
|
+
this.sharedCanvas = null;
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
//# sourceMappingURL=TerminalStore.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TerminalStore.js","sourceRo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|
2
|
+
* BSP layout DSL parser and serializer.
|
|
3
|
+
*
|
|
4
|
+
* Syntax:
|
|
5
|
+
* layout = node
|
|
6
|
+
* node = split | leaf
|
|
7
|
+
* split = ("line" | "col" | "tabs") "(" entries ")"
|
|
8
|
+
* entries = entry ("," entry)*
|
|
9
|
+
* entry = [label ":"] node [weight] ["=" command] ["@" fontSize]
|
|
10
|
+
* label = identifier | quoted-string
|
|
11
|
+
* leaf = identifier | quoted-string
|
|
12
|
+
* command = identifier | quoted-string
|
|
13
|
+
* weight = number
|
|
14
|
+
* fontSize = number ["px" | "pt" | "%"]
|
|
15
|
+
* identifier = [a-zA-Z_][a-zA-Z0-9_-]*
|
|
16
|
+
*
|
|
17
|
+
* Examples:
|
|
18
|
+
* shell
|
|
19
|
+
* line(chat 2, col(shell, tail, htop))
|
|
20
|
+
* line(editor 3 @14, col(shell @11, logs))
|
|
21
|
+
* tabs(shell, htop, logs)
|
|
22
|
+
* tabs("Editor": col(a, b), "Terminal": col(c, d))
|
|
23
|
+
* line(editor 2, tabs(shell, logs))
|
|
24
|
+
* col(htop="htop", shell="cd /src && make watch")
|
|
25
|
+
*/
|
|
26
|
+
export type BSPNode = BSPSplit | BSPLeaf;
|
|
27
|
+
export interface BSPSplit {
|
|
28
|
+
type: "split";
|
|
29
|
+
direction: "horizontal" | "vertical" | "tabs";
|
|
30
|
+
children: BSPChild[];
|
|
31
|
+
}
|
|
32
|
+
export interface BSPChild {
|
|
33
|
+
node: BSPNode;
|
|
34
|
+
weight: number;
|
|
35
|
+
label?: string;
|
|
36
|
+
}
|
|
37
|
+
export interface BSPLeaf {
|
|
38
|
+
type: "leaf";
|
|
39
|
+
tag: string;
|
|
40
|
+
/** Shell command to run when the pane is created. */
|
|
41
|
+
command?: string;
|
|
42
|
+
/** Raw font size, e.g. 14, "12px", "13pt", "80%" */
|
|
43
|
+
fontSize?: number | string;
|
|
44
|
+
}
|
|
45
|
+
export declare class DSLParseError extends Error {
|
|
46
|
+
readonly offset: number;
|
|
47
|
+
constructor(message: string, offset: number);
|
|
48
|
+
}
|
|
49
|
+
export declare function parseDSL(input: string): {
|
|
50
|
+
root: BSPNode;
|
|
51
|
+
weight: number;
|
|
52
|
+
};
|
|
53
|
+
export declare function serializeDSL(root: BSPNode, weight?: number): string;
|
|
54
|
+
export declare function collectTags(node: BSPNode): string[];
|
|
55
|
+
export declare function leafCount(node: BSPNode): number;
|
|
56
|
+
//# sourceMappingURL=dsl.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dsl.d.ts","sourceRoot":"","sources":["../../src/bsp/dsl.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,MAAM,MAAM,OAAO,GAAG,QAAQ,GAAG,OAAO,CAAC;AAEzC,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE,OAAO,CAAC;IACd,SAAS,EAAE,YAAY,GAAG,UAAU,GAAG,MAAM,CAAC;IAC9C,QAAQ,EAAE,QAAQ,EAAE,CAAC;CACtB;AAED,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE,OAAO,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,OAAO;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;IACZ,qDAAqD;IACrD,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,oDAAoD;IACpD,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;CAC5B;AAID,qBAAa,aAAc,SAAQ,KAAK;aAGpB,MAAM,EAAE,MAAM;gBAD9B,OAAO,EAAE,MAAM,EACC,MAAM,EAAE,MAAM;CAIjC;AAMD,wBAAgB,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAkMzE;AAqCD,wBAAgB,YAAY,CAAC,IAAI,EAAE,OAAO,EAAE,MAAM,SAAI,GAAG,MAAM,CAE9D;AAMD,wBAAgB,WAAW,CAAC,IAAI,EAAE,OAAO,GAAG,MAAM,EAAE,CAGnD;AAED,wBAAgB,SAAS,CAAC,IAAI,EAAE,OAAO,GAAG,MAAM,CAG/C"}
|