@hex1b/web-terminal 0.1.0 → 0.166.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.
Files changed (50) hide show
  1. package/README.md +314 -11
  2. package/dist/backend-selection.d.ts +7 -0
  3. package/dist/backend-selection.d.ts.map +1 -0
  4. package/dist/backend-selection.js +23 -0
  5. package/dist/backend-selection.js.map +1 -0
  6. package/dist/hyperlinks.d.ts +10 -0
  7. package/dist/hyperlinks.d.ts.map +1 -0
  8. package/dist/hyperlinks.js +28 -0
  9. package/dist/hyperlinks.js.map +1 -0
  10. package/dist/mouse-input.d.ts +3 -0
  11. package/dist/mouse-input.d.ts.map +1 -1
  12. package/dist/mouse-input.js +69 -2
  13. package/dist/mouse-input.js.map +1 -1
  14. package/dist/protocol.d.ts +1 -0
  15. package/dist/protocol.d.ts.map +1 -1
  16. package/dist/protocol.js +40 -0
  17. package/dist/protocol.js.map +1 -1
  18. package/dist/render-backend.d.ts +31 -0
  19. package/dist/render-backend.d.ts.map +1 -0
  20. package/dist/render-backend.js +5 -0
  21. package/dist/render-backend.js.map +1 -0
  22. package/dist/renderer-options.d.ts +3 -0
  23. package/dist/renderer-options.d.ts.map +1 -0
  24. package/dist/renderer-options.js +6 -0
  25. package/dist/renderer-options.js.map +1 -0
  26. package/dist/renderer.d.ts +12 -24
  27. package/dist/renderer.d.ts.map +1 -1
  28. package/dist/renderer.js +35 -173
  29. package/dist/renderer.js.map +1 -1
  30. package/dist/terminal-worker.js +18 -10
  31. package/dist/terminal-worker.js.map +1 -1
  32. package/dist/types.d.ts +77 -0
  33. package/dist/types.d.ts.map +1 -1
  34. package/dist/types.js.map +1 -1
  35. package/dist/web-terminal.d.ts +8 -1
  36. package/dist/web-terminal.d.ts.map +1 -1
  37. package/dist/web-terminal.js +130 -17
  38. package/dist/web-terminal.js.map +1 -1
  39. package/dist/webgl2-backend.d.ts +38 -0
  40. package/dist/webgl2-backend.d.ts.map +1 -0
  41. package/dist/webgl2-backend.js +456 -0
  42. package/dist/webgl2-backend.js.map +1 -0
  43. package/dist/webgpu-backend.d.ts +24 -0
  44. package/dist/webgpu-backend.d.ts.map +1 -0
  45. package/dist/webgpu-backend.js +234 -0
  46. package/dist/webgpu-backend.js.map +1 -0
  47. package/dist/wire-types.d.ts +20 -2
  48. package/dist/wire-types.d.ts.map +1 -1
  49. package/dist/wire-types.js.map +1 -1
  50. package/package.json +2 -2
package/dist/renderer.js CHANGED
@@ -1,53 +1,14 @@
1
1
  import { LIMITS } from "./protocol.js";
2
2
  import { loadFont, measureFont, normalizeFont } from "./terminal-font.js";
3
+ import { createRenderBackend } from "./backend-selection.js";
4
+ import { QUAD_STRIDE } from "./render-backend.js";
3
5
  const CELL_WIDTH = 10;
4
6
  const CELL_HEIGHT = 20;
5
7
  const MAX_QUADS = 1024 * 1024;
6
8
  const MAX_GLYPHS = 16384;
7
9
  const MAX_GLYPH_KEY_UNITS = 1024 * 1024;
8
- const STRIDE = 16;
10
+ const STRIDE = QUAD_STRIDE;
9
11
  const WHITE = [1, 1, 1, 1];
10
- const shader = /* wgsl */ `
11
- struct Viewport { size: vec2f, padding: vec2f }
12
- @group(0) @binding(0) var<uniform> viewport: Viewport;
13
- @group(0) @binding(1) var image: texture_2d<f32>;
14
- @group(0) @binding(2) var imageSampler: sampler;
15
-
16
- struct VertexOut {
17
- @builtin(position) position: vec4f,
18
- @location(0) uv: vec2f,
19
- @location(1) color: vec4f,
20
- @location(2) @interpolate(flat) mode: f32,
21
- }
22
-
23
- @vertex fn vertex(
24
- @builtin(vertex_index) index: u32,
25
- @location(0) rect: vec4f,
26
- @location(1) uvRect: vec4f,
27
- @location(2) color: vec4f,
28
- @location(3) mode: f32,
29
- ) -> VertexOut {
30
- let corners = array<vec2f, 6>(
31
- vec2f(0, 0), vec2f(1, 0), vec2f(0, 1),
32
- vec2f(0, 1), vec2f(1, 0), vec2f(1, 1)
33
- );
34
- let corner = corners[index];
35
- let position = rect.xy + corner * rect.zw;
36
- var out: VertexOut;
37
- out.position = vec4f(position / viewport.size * vec2f(2, -2) + vec2f(-1, 1), 0, 1);
38
- out.uv = mix(uvRect.xy, uvRect.zw, corner);
39
- out.color = color;
40
- out.mode = mode;
41
- return out;
42
- }
43
-
44
- @fragment fn fragment(in: VertexOut) -> @location(0) vec4f {
45
- // Explicit LOD avoids derivative-uniformity requirements across solid/mask/image batches.
46
- let texel = textureSampleLevel(image, imageSampler, in.uv, 0);
47
- if (in.mode < 0.5) { return in.color; }
48
- if (in.mode < 1.5) { return vec4f(in.color.rgb, in.color.a * texel.a); }
49
- return texel * in.color;
50
- }`;
51
12
  function rgba(packed) {
52
13
  return [
53
14
  (packed & 255) / 255,
@@ -81,15 +42,15 @@ function packGlyphs(glyphs, size, scale, initial = { x: 0, y: 0, rowHeight: 0 })
81
42
  }
82
43
  return { placements, shelf: { x, y, rowHeight } };
83
44
  }
84
- /** WebGPU instanced quads; Canvas2D is used only to rasterize reusable glyphs. */
45
+ /** Shared instanced-quad preparation; Canvas2D rasterizes reusable glyphs for either backend. */
85
46
  export class TerminalRenderer {
86
47
  canvas;
87
48
  scale;
88
49
  backingScale;
89
- device;
50
+ backend;
51
+ fallbackReason;
90
52
  fontConfiguration;
91
53
  fontMetrics;
92
- context;
93
54
  images;
94
55
  glyphs;
95
56
  imageUploadBytes;
@@ -98,17 +59,11 @@ export class TerminalRenderer {
98
59
  atlasRebuilds;
99
60
  textureBytes;
100
61
  instances;
101
- instanceBuffer;
102
- instanceBufferBytes;
103
62
  disposed;
104
63
  columns;
105
64
  rows;
106
65
  // Initialized by create() before the renderer can prepare or submit frames.
107
66
  font;
108
- format;
109
- uniform;
110
- sampler;
111
- pipeline;
112
67
  rasterCanvas;
113
68
  raster;
114
69
  atlas;
@@ -119,22 +74,13 @@ export class TerminalRenderer {
119
74
  height = 0;
120
75
  quadCount = 0;
121
76
  batches = [];
122
- static async create(canvas, scale, onFatal, font) {
77
+ static async create(canvas, scale, onFatal, font, preference = "auto") {
123
78
  const normalizedFont = normalizeFont(font);
124
- if (!self.isSecureContext)
125
- throw new Error("WebGPU requires HTTPS or localhost");
126
- if (!navigator.gpu)
127
- throw new Error("WebGPU is unavailable in this browser worker");
128
- const adapter = await navigator.gpu.requestAdapter();
129
- if (!adapter)
130
- throw new Error("No WebGPU adapter is available; check browser GPU support");
131
- const device = await adapter.requestDevice();
132
- const renderer = new TerminalRenderer(canvas, scale, device, normalizedFont);
133
- device.lost.then(info => {
134
- if (!renderer.disposed)
135
- onFatal(new Error(`WebGPU device lost: ${info.message || info.reason}`));
136
- });
137
- device.addEventListener("uncapturederror", event => onFatal(event.error));
79
+ if (!Number.isFinite(scale) || scale < 0.5 || scale > 3)
80
+ throw new Error("Invalid backing scale");
81
+ const { backend, fallbackReason } = await createRenderBackend(canvas, onFatal, preference);
82
+ const renderer = new TerminalRenderer(canvas, scale, backend, normalizedFont);
83
+ renderer.fallbackReason = fallbackReason;
138
84
  try {
139
85
  await renderer.initialize();
140
86
  return renderer;
@@ -144,19 +90,15 @@ export class TerminalRenderer {
144
90
  throw error;
145
91
  }
146
92
  }
147
- constructor(canvas, scale, device, font) {
93
+ constructor(canvas, scale, backend, font) {
148
94
  if (!Number.isFinite(scale) || scale < 0.5 || scale > 3)
149
95
  throw new Error("Invalid backing scale");
150
96
  this.canvas = canvas;
151
97
  this.scale = scale;
152
98
  this.backingScale = scale;
153
- this.device = device;
99
+ this.backend = backend;
154
100
  this.fontConfiguration = font;
155
101
  this.fontMetrics = new Map();
156
- const context = canvas.getContext("webgpu");
157
- if (!context)
158
- throw new Error("Could not create an OffscreenCanvas WebGPU context");
159
- this.context = context;
160
102
  this.images = new Map();
161
103
  this.glyphs = new Map();
162
104
  this.imageUploadBytes = 0;
@@ -165,78 +107,24 @@ export class TerminalRenderer {
165
107
  this.atlasRebuilds = 0;
166
108
  this.textureBytes = 0;
167
109
  this.instances = new Float32Array(4096 * STRIDE);
168
- this.instanceBuffer = null;
169
- this.instanceBufferBytes = 0;
170
110
  this.disposed = false;
171
111
  this.columns = 0;
172
112
  this.rows = 0;
173
113
  }
174
114
  async initialize() {
175
115
  this.font = await loadFont(this.fontConfiguration);
176
- const device = this.device;
177
- this.format = navigator.gpu.getPreferredCanvasFormat();
178
- this.context.configure({ device, format: this.format, alphaMode: "opaque" });
179
- this.uniform = device.createBuffer({ size: 16, usage: GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST });
180
- this.sampler = device.createSampler({ minFilter: "linear", magFilter: "linear" });
181
- const module = device.createShaderModule({ code: shader });
182
- this.pipeline = await device.createRenderPipelineAsync({
183
- layout: "auto",
184
- vertex: {
185
- module,
186
- entryPoint: "vertex",
187
- buffers: [{
188
- arrayStride: STRIDE * 4,
189
- stepMode: "instance",
190
- attributes: [
191
- { shaderLocation: 0, offset: 0, format: "float32x4" },
192
- { shaderLocation: 1, offset: 16, format: "float32x4" },
193
- { shaderLocation: 2, offset: 32, format: "float32x4" },
194
- { shaderLocation: 3, offset: 48, format: "float32" },
195
- ],
196
- }],
197
- },
198
- fragment: {
199
- module,
200
- entryPoint: "fragment",
201
- targets: [{
202
- format: this.format,
203
- blend: {
204
- color: { srcFactor: "src-alpha", dstFactor: "one-minus-src-alpha" },
205
- alpha: { srcFactor: "one", dstFactor: "one-minus-src-alpha" },
206
- },
207
- }],
208
- },
209
- primitive: { topology: "triangle-list" },
210
- });
211
116
  this.rasterCanvas = new OffscreenCanvas(1, 1);
212
117
  const raster = this.rasterCanvas.getContext("2d", { willReadFrequently: true });
213
118
  if (!raster)
214
119
  throw new Error("Worker glyph rasterization is unavailable");
215
120
  this.raster = raster;
216
- this.resetAtlas(Math.min(2048, device.limits.maxTextureDimension2D));
121
+ this.resetAtlas(Math.min(2048, this.backend.maxTextureDimension2D));
217
122
  }
218
123
  createTexture(width, height, label) {
219
- if (width > this.device.limits.maxTextureDimension2D || height > this.device.limits.maxTextureDimension2D) {
220
- throw new Error(`${label} exceeds the GPU texture dimension limit`);
221
- }
222
- const texture = this.device.createTexture({
223
- label,
224
- size: [width, height],
225
- format: "rgba8unorm",
226
- usage: GPUTextureUsage.TEXTURE_BINDING | GPUTextureUsage.COPY_DST | GPUTextureUsage.RENDER_ATTACHMENT,
227
- });
228
- const bindGroup = this.device.createBindGroup({
229
- layout: this.pipeline.getBindGroupLayout(0),
230
- entries: [
231
- { binding: 0, resource: { buffer: this.uniform } },
232
- { binding: 1, resource: texture.createView() },
233
- { binding: 2, resource: this.sampler },
234
- ],
235
- });
236
- return { texture, bindGroup, width, height };
124
+ return this.backend.createTexture(width, height, label);
237
125
  }
238
126
  resetAtlas(size) {
239
- this.atlas?.texture.destroy();
127
+ this.atlas?.destroy();
240
128
  this.atlas = this.createTexture(size, size, "Glyph atlas");
241
129
  this.glyphs.clear();
242
130
  this.glyphKeyUnits = 0;
@@ -245,7 +133,7 @@ export class TerminalRenderer {
245
133
  resize(columns, rows, viewport) {
246
134
  const width = columns * CELL_WIDTH;
247
135
  const height = rows * CELL_HEIGHT;
248
- const limit = this.device.limits.maxTextureDimension2D;
136
+ const limit = this.backend.maxCanvasDimension2D;
249
137
  const requested = Math.min(this.scale, viewport ? viewport.width / width : Infinity, viewport ? viewport.height / height : Infinity);
250
138
  this.canvasLimited = width * requested > limit || height * requested > limit;
251
139
  this.backingScale = Math.min(requested, limit / width, limit / height);
@@ -259,7 +147,7 @@ export class TerminalRenderer {
259
147
  this.height = height;
260
148
  this.canvas.width = backingWidth;
261
149
  this.canvas.height = backingHeight;
262
- this.device.queue.writeBuffer(this.uniform, 0, new Float32Array([width, height, 0, 0]));
150
+ this.backend.resize(width, height);
263
151
  }
264
152
  /** Call only between submissions. Missing/over-budget resources terminate the session. */
265
153
  async updateImages(incoming, retainedKeys) {
@@ -276,7 +164,7 @@ export class TerminalRenderer {
276
164
  throw new Error("Retained images exceed the 256 MiB texture budget");
277
165
  for (const [key, image] of this.images) {
278
166
  if (!retained.has(key) || replacements.has(key)) {
279
- image.texture.destroy();
167
+ image.destroy();
280
168
  this.textureBytes -= image.width * image.height * 4;
281
169
  this.images.delete(key);
282
170
  }
@@ -285,7 +173,7 @@ export class TerminalRenderer {
285
173
  const resource = this.createTexture(image.width, image.height, `Image ${image.key}`);
286
174
  try {
287
175
  if (image.format === "rgba") {
288
- this.device.queue.writeTexture({ texture: resource.texture }, image.bytes, { bytesPerRow: image.width * 4, rowsPerImage: image.height }, [image.width, image.height]);
176
+ resource.writePixels(image.bytes, image.width, image.height);
289
177
  }
290
178
  else {
291
179
  // Check IHDR before decoding so a tiny PNG cannot claim unbounded decoded dimensions.
@@ -302,7 +190,7 @@ export class TerminalRenderer {
302
190
  try {
303
191
  if (bitmap.width !== image.width || bitmap.height !== image.height)
304
192
  throw new Error("Decoded PNG dimension mismatch");
305
- this.device.queue.copyExternalImageToTexture({ source: bitmap }, { texture: resource.texture, premultipliedAlpha: false }, [image.width, image.height]);
193
+ resource.writeBitmap(bitmap);
306
194
  }
307
195
  finally {
308
196
  bitmap.close();
@@ -314,7 +202,7 @@ export class TerminalRenderer {
314
202
  this.imagePayloadBytes += image.byteLength;
315
203
  }
316
204
  catch (error) {
317
- resource.texture.destroy();
205
+ resource.destroy();
318
206
  throw error;
319
207
  }
320
208
  }
@@ -338,7 +226,7 @@ export class TerminalRenderer {
338
226
  let plan = metadataFits ? packGlyphs(missing, this.atlas.width, this.scale, this.shelf) : null;
339
227
  if (!plan) {
340
228
  let size = this.atlas.width;
341
- const maxSize = Math.min(4096, this.device.limits.maxTextureDimension2D);
229
+ const maxSize = Math.min(4096, this.backend.maxTextureDimension2D);
342
230
  while (!(plan = packGlyphs(visible, size, this.scale)) && size < maxSize) {
343
231
  size = Math.min(size * 2, maxSize);
344
232
  }
@@ -378,7 +266,7 @@ export class TerminalRenderer {
378
266
  break;
379
267
  }
380
268
  }
381
- this.device.queue.writeTexture({ texture: this.atlas.texture, origin: [x, y] }, pixels.data, { bytesPerRow: width * 4, rowsPerImage: height }, [width, height]);
269
+ this.atlas.writePixels(pixels.data, width, height, x, y);
382
270
  this.glyphUploadBytes += width * height * 4;
383
271
  this.glyphs.set(key, {
384
272
  colored,
@@ -526,39 +414,14 @@ export class TerminalRenderer {
526
414
  this.solid(x, y, CELL_WIDTH, CELL_HEIGHT, color);
527
415
  }
528
416
  }
529
- const usedBytes = this.quadCount * STRIDE * 4;
530
- if (!this.instanceBuffer || usedBytes > this.instanceBufferBytes) {
531
- this.instanceBuffer?.destroy();
532
- this.instanceBufferBytes = Math.max(256, this.instances.byteLength);
533
- this.instanceBuffer = this.device.createBuffer({
534
- size: this.instanceBufferBytes,
535
- usage: GPUBufferUsage.VERTEX | GPUBufferUsage.COPY_DST,
536
- });
537
- }
538
- if (usedBytes)
539
- this.device.queue.writeBuffer(this.instanceBuffer, 0, this.instances, 0, this.quadCount * STRIDE);
540
- const encoder = this.device.createCommandEncoder();
541
417
  const base = rgba(metadata.defaultBackground ?? cells[0]?.background ?? 0xff000000);
542
- const pass = encoder.beginRenderPass({
543
- colorAttachments: [{
544
- view: this.context.getCurrentTexture().createView(),
545
- clearValue: { r: base[0], g: base[1], b: base[2], a: 1 },
546
- loadOp: "clear",
547
- storeOp: "store",
548
- }],
549
- });
550
- pass.setPipeline(this.pipeline);
551
- pass.setVertexBuffer(0, this.instanceBuffer);
552
- for (const batch of this.batches) {
553
- pass.setBindGroup(0, batch.resource.bindGroup);
554
- pass.draw(6, batch.count, 0, batch.start);
555
- }
556
- pass.end();
557
- this.device.queue.submit([encoder.finish()]);
418
+ this.backend.submit(this.instances, this.quadCount, this.batches, base);
558
419
  return { cpuMs: performance.now() - start, quads: this.quadCount, drawCalls: this.batches.length };
559
420
  }
560
421
  metrics() {
561
422
  return {
423
+ renderer: this.backend.kind,
424
+ rendererFallbackReason: this.fallbackReason,
562
425
  fontFamily: this.font.family,
563
426
  rasterScale: this.scale,
564
427
  backingScale: this.backingScale,
@@ -572,24 +435,23 @@ export class TerminalRenderer {
572
435
  imageUploadBytes: this.imageUploadBytes,
573
436
  imagePayloadBytes: this.imagePayloadBytes,
574
437
  glyphUploadBytes: this.glyphUploadBytes,
575
- instanceBufferBytes: this.instanceBufferBytes,
438
+ instanceBufferBytes: this.backend.instanceBufferBytes,
576
439
  };
577
440
  }
578
441
  async idle() {
579
- await this.device.queue.onSubmittedWorkDone();
442
+ await this.backend.idle();
580
443
  }
581
444
  dispose() {
445
+ if (this.disposed)
446
+ return;
582
447
  this.disposed = true;
583
448
  for (const image of this.images.values())
584
- image.texture.destroy();
449
+ image.destroy();
585
450
  this.images.clear();
586
- this.atlas?.texture.destroy();
587
- this.instanceBuffer?.destroy();
588
- this.uniform?.destroy();
451
+ this.atlas?.destroy();
589
452
  this.font?.dispose();
590
453
  this.fontMetrics.clear();
591
- this.context.unconfigure();
592
- this.device.destroy();
454
+ this.backend.dispose();
593
455
  }
594
456
  }
595
457
  //# sourceMappingURL=renderer.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"renderer.js","sourceRoot":"","sources":["../src/renderer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACvC,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAY1E,MAAM,UAAU,GAAG,EAAE,CAAC;AACtB,MAAM,WAAW,GAAG,EAAE,CAAC;AACvB,MAAM,SAAS,GAAG,IAAI,GAAG,IAAI,CAAC;AAC9B,MAAM,UAAU,GAAG,KAAK,CAAC;AACzB,MAAM,mBAAmB,GAAG,IAAI,GAAG,IAAI,CAAC;AACxC,MAAM,MAAM,GAAG,EAAE,CAAC;AAClB,MAAM,KAAK,GAAY,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;AAEpC,MAAM,MAAM,GAAG,UAAU,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAwCxB,CAAC;AAEH,SAAS,IAAI,CAAC,MAAc;IAC1B,OAAO;QACL,CAAC,MAAM,GAAG,GAAG,CAAC,GAAG,GA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AC;IACxB,CAAC;CACF","sourcesContent":["import { LIMITS } from \"./protocol.js\";\nimport { loadFont, measureFont, normalizeFont } from \"./terminal-font.js\";\nimport type { FontMetrics, LoadedFont, NormalizedFont } from \"./terminal-font.js\";\nimport type { TerminalFont, TerminalSize } from \"./types.js\";\nimport type { FrameImage, FrameMetadata, ImagePlacement, TerminalCell } from \"./wire-types.js\";\n\ntype Vector4 = [number, number, number, number];\ninterface TextureResource { texture: GPUTexture; bindGroup: GPUBindGroup; width: number; height: number }\ninterface Shelf { x: number; y: number; rowHeight: number }\ninterface GlyphPlacement { key: string; cell: TerminalCell; x: number; y: number; width: number; height: number }\ninterface Glyph { colored: boolean; u0: number; v0: number; u1: number; v1: number }\ninterface Batch { resource: TextureResource; start: number; count: number }\n\nconst CELL_WIDTH = 10;\nconst CELL_HEIGHT = 20;\nconst MAX_QUADS = 1024 * 1024;\nconst MAX_GLYPHS = 16384;\nconst MAX_GLYPH_KEY_UNITS = 1024 * 1024;\nconst STRIDE = 16;\nconst WHITE: Vector4 = [1, 1, 1, 1];\n\nconst shader = /* wgsl */ `\nstruct Viewport { size: vec2f, padding: vec2f }\n@group(0) @binding(0) var<uniform> viewport: Viewport;\n@group(0) @binding(1) var image: texture_2d<f32>;\n@group(0) @binding(2) var imageSampler: sampler;\n\nstruct VertexOut {\n @builtin(position) position: vec4f,\n @location(0) uv: vec2f,\n @location(1) color: vec4f,\n @location(2) @interpolate(flat) mode: f32,\n}\n\n@vertex fn vertex(\n @builtin(vertex_index) index: u32,\n @location(0) rect: vec4f,\n @location(1) uvRect: vec4f,\n @location(2) color: vec4f,\n @location(3) mode: f32,\n) -> VertexOut {\n let corners = array<vec2f, 6>(\n vec2f(0, 0), vec2f(1, 0), vec2f(0, 1),\n vec2f(0, 1), vec2f(1, 0), vec2f(1, 1)\n );\n let corner = corners[index];\n let position = rect.xy + corner * rect.zw;\n var out: VertexOut;\n out.position = vec4f(position / viewport.size * vec2f(2, -2) + vec2f(-1, 1), 0, 1);\n out.uv = mix(uvRect.xy, uvRect.zw, corner);\n out.color = color;\n out.mode = mode;\n return out;\n}\n\n@fragment fn fragment(in: VertexOut) -> @location(0) vec4f {\n // Explicit LOD avoids derivative-uniformity requirements across solid/mask/image batches.\n let texel = textureSampleLevel(image, imageSampler, in.uv, 0);\n if (in.mode < 0.5) { return in.color; }\n if (in.mode < 1.5) { return vec4f(in.color.rgb, in.color.a * texel.a); }\n return texel * in.color;\n}`;\n\nfunction rgba(packed: number): Vector4 {\n return [\n (packed & 255) / 255,\n ((packed >>> 8) & 255) / 255,\n ((packed >>> 16) & 255) / 255,\n ((packed >>> 24) & 255) / 255,\n ];\n}\n\nfunction glyphKey(cell: TerminalCell): string {\n return `${cell.attributes & 5}/${cell.width}/${cell.text}`;\n}\n\n/** Shelf packer. Plans are computed before mutating the atlas used by a submitted frame. */\nfunction packGlyphs(glyphs: ReadonlyMap<string, TerminalCell>, size: number, scale: number,\n initial: Shelf = { x: 0, y: 0, rowHeight: 0 }): { placements: GlyphPlacement[]; shelf: Shelf } | null {\n let { x, y, rowHeight } = initial;\n const placements = [];\n for (const [key, cell] of glyphs) {\n const width = Math.ceil(cell.width * CELL_WIDTH * scale) + 4;\n const height = Math.ceil(CELL_HEIGHT * scale) + 4;\n if (width > size || height > size) return null;\n if (x + width > size) { x = 0; y += rowHeight; rowHeight = 0; }\n if (y + height > size) return null;\n placements.push({ key, cell, x, y, width, height });\n x += width;\n rowHeight = Math.max(rowHeight, height);\n }\n return { placements, shelf: { x, y, rowHeight } };\n}\n\n/** WebGPU instanced quads; Canvas2D is used only to rasterize reusable glyphs. */\nexport class TerminalRenderer {\n canvas: OffscreenCanvas;\n scale: number;\n backingScale: number;\n device: GPUDevice;\n fontConfiguration: NormalizedFont;\n fontMetrics: Map<number, FontMetrics>;\n context: GPUCanvasContext;\n images: Map<string, TextureResource>;\n glyphs: Map<string, Glyph>;\n imageUploadBytes: number;\n imagePayloadBytes: number;\n glyphUploadBytes: number;\n atlasRebuilds: number;\n textureBytes: number;\n instances: Float32Array<ArrayBuffer>;\n instanceBuffer: GPUBuffer | null;\n instanceBufferBytes: number;\n disposed: boolean;\n columns: number;\n rows: number;\n // Initialized by create() before the renderer can prepare or submit frames.\n font!: LoadedFont;\n format!: GPUTextureFormat;\n uniform!: GPUBuffer;\n sampler!: GPUSampler;\n pipeline!: GPURenderPipeline;\n rasterCanvas!: OffscreenCanvas;\n raster!: OffscreenCanvasRenderingContext2D;\n atlas!: TextureResource;\n glyphKeyUnits = 0;\n shelf: Shelf = { x: 0, y: 0, rowHeight: 0 };\n canvasLimited = false;\n width = 0;\n height = 0;\n quadCount = 0;\n batches: Batch[] = [];\n\n static async create(canvas: OffscreenCanvas, scale: number, onFatal: (error: Error | GPUError) => void,\n font: TerminalFont): Promise<TerminalRenderer> {\n const normalizedFont = normalizeFont(font);\n if (!self.isSecureContext) throw new Error(\"WebGPU requires HTTPS or localhost\");\n if (!navigator.gpu) throw new Error(\"WebGPU is unavailable in this browser worker\");\n const adapter = await navigator.gpu.requestAdapter();\n if (!adapter) throw new Error(\"No WebGPU adapter is available; check browser GPU support\");\n const device = await adapter.requestDevice();\n const renderer = new TerminalRenderer(canvas, scale, device, normalizedFont);\n device.lost.then(info => {\n if (!renderer.disposed) onFatal(new Error(`WebGPU device lost: ${info.message || info.reason}`));\n });\n device.addEventListener(\"uncapturederror\", event => onFatal(event.error));\n try {\n await renderer.initialize();\n return renderer;\n } catch (error) {\n renderer.dispose();\n throw error;\n }\n }\n\n constructor(canvas: OffscreenCanvas, scale: number, device: GPUDevice, font: NormalizedFont) {\n if (!Number.isFinite(scale) || scale < 0.5 || scale > 3) throw new Error(\"Invalid backing scale\");\n this.canvas = canvas;\n this.scale = scale;\n this.backingScale = scale;\n this.device = device;\n this.fontConfiguration = font;\n this.fontMetrics = new Map();\n const context = canvas.getContext(\"webgpu\");\n if (!context) throw new Error(\"Could not create an OffscreenCanvas WebGPU context\");\n this.context = context;\n this.images = new Map();\n this.glyphs = new Map();\n this.imageUploadBytes = 0;\n this.imagePayloadBytes = 0;\n this.glyphUploadBytes = 0;\n this.atlasRebuilds = 0;\n this.textureBytes = 0;\n this.instances = new Float32Array(4096 * STRIDE);\n this.instanceBuffer = null;\n this.instanceBufferBytes = 0;\n this.disposed = false;\n this.columns = 0;\n this.rows = 0;\n }\n\n async initialize() {\n this.font = await loadFont(this.fontConfiguration);\n const device = this.device;\n this.format = navigator.gpu.getPreferredCanvasFormat();\n this.context.configure({ device, format: this.format, alphaMode: \"opaque\" });\n this.uniform = device.createBuffer({ size: 16, usage: GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST });\n this.sampler = device.createSampler({ minFilter: \"linear\", magFilter: \"linear\" });\n const module = device.createShaderModule({ code: shader });\n this.pipeline = await device.createRenderPipelineAsync({\n layout: \"auto\",\n vertex: {\n module,\n entryPoint: \"vertex\",\n buffers: [{\n arrayStride: STRIDE * 4,\n stepMode: \"instance\",\n attributes: [\n { shaderLocation: 0, offset: 0, format: \"float32x4\" },\n { shaderLocation: 1, offset: 16, format: \"float32x4\" },\n { shaderLocation: 2, offset: 32, format: \"float32x4\" },\n { shaderLocation: 3, offset: 48, format: \"float32\" },\n ],\n }],\n },\n fragment: {\n module,\n entryPoint: \"fragment\",\n targets: [{\n format: this.format,\n blend: {\n color: { srcFactor: \"src-alpha\", dstFactor: \"one-minus-src-alpha\" },\n alpha: { srcFactor: \"one\", dstFactor: \"one-minus-src-alpha\" },\n },\n }],\n },\n primitive: { topology: \"triangle-list\" },\n });\n this.rasterCanvas = new OffscreenCanvas(1, 1);\n const raster = this.rasterCanvas.getContext(\"2d\", { willReadFrequently: true });\n if (!raster) throw new Error(\"Worker glyph rasterization is unavailable\");\n this.raster = raster;\n this.resetAtlas(Math.min(2048, device.limits.maxTextureDimension2D));\n }\n\n createTexture(width: number, height: number, label: string): TextureResource {\n if (width > this.device.limits.maxTextureDimension2D || height > this.device.limits.maxTextureDimension2D) {\n throw new Error(`${label} exceeds the GPU texture dimension limit`);\n }\n const texture = this.device.createTexture({\n label,\n size: [width, height],\n format: \"rgba8unorm\",\n usage: GPUTextureUsage.TEXTURE_BINDING | GPUTextureUsage.COPY_DST | GPUTextureUsage.RENDER_ATTACHMENT,\n });\n const bindGroup = this.device.createBindGroup({\n layout: this.pipeline.getBindGroupLayout(0),\n entries: [\n { binding: 0, resource: { buffer: this.uniform } },\n { binding: 1, resource: texture.createView() },\n { binding: 2, resource: this.sampler },\n ],\n });\n return { texture, bindGroup, width, height };\n }\n\n resetAtlas(size: number): void {\n this.atlas?.texture.destroy();\n this.atlas = this.createTexture(size, size, \"Glyph atlas\");\n this.glyphs.clear();\n this.glyphKeyUnits = 0;\n this.shelf = { x: 0, y: 0, rowHeight: 0 };\n }\n\n resize(columns: number, rows: number, viewport?: TerminalSize): void {\n const width = columns * CELL_WIDTH;\n const height = rows * CELL_HEIGHT;\n const limit = this.device.limits.maxTextureDimension2D;\n const requested = Math.min(this.scale, viewport ? viewport.width / width : Infinity, viewport ? viewport.height / height : Infinity);\n this.canvasLimited = width * requested > limit || height * requested > limit;\n this.backingScale = Math.min(requested, limit / width, limit / height);\n const backingWidth = Math.max(1, Math.min(limit, Math.ceil(width * this.backingScale)));\n const backingHeight = Math.max(1, Math.min(limit, Math.ceil(height * this.backingScale)));\n if (this.columns === columns && this.rows === rows && this.canvas.width === backingWidth && this.canvas.height === backingHeight) return;\n this.columns = columns;\n this.rows = rows;\n this.width = width;\n this.height = height;\n this.canvas.width = backingWidth;\n this.canvas.height = backingHeight;\n this.device.queue.writeBuffer(this.uniform, 0, new Float32Array([width, height, 0, 0]));\n }\n\n /** Call only between submissions. Missing/over-budget resources terminate the session. */\n async updateImages(incoming: readonly FrameImage[], retainedKeys: readonly string[]): Promise<void> {\n const retained = new Set(retainedKeys);\n const replacements = new Map(incoming.map(image => [image.key, image]));\n let projectedBytes = 0;\n for (const key of retained) {\n const image = replacements.get(key) || this.images.get(key);\n if (!image) throw new Error(`Missing retained image resource: ${key}`);\n projectedBytes += image.width * image.height * 4;\n }\n if (projectedBytes > LIMITS.textureBytes) throw new Error(\"Retained images exceed the 256 MiB texture budget\");\n for (const [key, image] of this.images) {\n if (!retained.has(key) || replacements.has(key)) {\n image.texture.destroy();\n this.textureBytes -= image.width * image.height * 4;\n this.images.delete(key);\n }\n }\n for (const image of incoming) {\n const resource = this.createTexture(image.width, image.height, `Image ${image.key}`);\n try {\n if (image.format === \"rgba\") {\n this.device.queue.writeTexture(\n { texture: resource.texture },\n image.bytes,\n { bytesPerRow: image.width * 4, rowsPerImage: image.height },\n [image.width, image.height],\n );\n } else {\n // Check IHDR before decoding so a tiny PNG cannot claim unbounded decoded dimensions.\n const png = new DataView(image.bytes.buffer, image.bytes.byteOffset, image.bytes.byteLength);\n if (png.byteLength < 33 || png.getUint32(0) !== 0x89504e47 || png.getUint32(4) !== 0x0d0a1a0a ||\n png.getUint32(8) !== 13 || png.getUint32(12) !== 0x49484452 ||\n png.getUint32(16) !== image.width || png.getUint32(20) !== image.height) {\n throw new Error(`PNG header dimensions do not match resource ${image.key}`);\n }\n const bitmap = await createImageBitmap(new Blob([image.bytes], { type: \"image/png\" }), {\n premultiplyAlpha: \"none\",\n colorSpaceConversion: \"none\",\n });\n try {\n if (bitmap.width !== image.width || bitmap.height !== image.height) throw new Error(\"Decoded PNG dimension mismatch\");\n this.device.queue.copyExternalImageToTexture(\n { source: bitmap },\n { texture: resource.texture, premultipliedAlpha: false },\n [image.width, image.height],\n );\n } finally {\n bitmap.close();\n }\n }\n this.images.set(image.key, resource);\n this.textureBytes += image.width * image.height * 4;\n this.imageUploadBytes += image.width * image.height * 4;\n this.imagePayloadBytes += image.byteLength;\n } catch (error) {\n resource.texture.destroy();\n throw error;\n }\n }\n }\n\n prepareGlyphs(cells: readonly (TerminalCell | undefined)[]): void {\n const visible = new Map<string, TerminalCell>();\n for (const cell of cells) {\n if (!cell || !cell.width || !cell.text.trim() || (cell.attributes & 64)) continue;\n visible.set(glyphKey(cell), cell);\n }\n const keyUnits = (glyphs: ReadonlyMap<string, TerminalCell>) => [...glyphs.keys()].reduce((total, key) => total + key.length, 0);\n if (visible.size > MAX_GLYPHS || keyUnits(visible) > MAX_GLYPH_KEY_UNITS) {\n throw new Error(\"Visible glyph metadata exceeds the bounded glyph cache\");\n }\n const missing = new Map([...visible].filter(([key]) => !this.glyphs.has(key)));\n if (!missing.size) return;\n const metadataFits = this.glyphs.size + missing.size <= MAX_GLYPHS &&\n this.glyphKeyUnits + keyUnits(missing) <= MAX_GLYPH_KEY_UNITS;\n let plan = metadataFits ? packGlyphs(missing, this.atlas.width, this.scale, this.shelf) : null;\n if (!plan) {\n let size = this.atlas.width;\n const maxSize = Math.min(4096, this.device.limits.maxTextureDimension2D);\n while (!(plan = packGlyphs(visible, size, this.scale)) && size < maxSize) {\n size = Math.min(size * 2, maxSize);\n }\n if (!plan) throw new Error(\"Visible glyphs exceed the bounded 4096² mask atlas; reduce the grid or backing scale\");\n this.resetAtlas(size);\n this.atlasRebuilds++;\n }\n for (const placement of plan.placements) this.uploadGlyph(placement);\n this.shelf = plan.shelf;\n }\n\n uploadGlyph({ key, cell, x, y, width, height }: GlyphPlacement): void {\n const scale = this.scale;\n const raster = this.raster;\n const style = cell.attributes & 5;\n let metrics = this.fontMetrics.get(style);\n if (!metrics) {\n metrics = measureFont(raster, this.font.cssFamily, style, scale, CELL_WIDTH, CELL_HEIGHT);\n this.fontMetrics.set(style, metrics);\n }\n this.rasterCanvas.width = width;\n this.rasterCanvas.height = height;\n raster.font = metrics.font;\n raster.textBaseline = \"alphabetic\";\n raster.textAlign = \"left\";\n raster.fillStyle = \"white\";\n // One transform per font style, not per glyph: borders remain font outlines,\n // and graphemes are clipped to their server-owned span without individual stretching.\n raster.setTransform(metrics.xScale, 0, 0, metrics.yScale, 2, 2 + metrics.baseline);\n raster.fillText(cell.text, 0, 0);\n const pixels = raster.getImageData(0, 0, width, height);\n let colored = false;\n for (let i = 0; i < pixels.data.length; i += 4) {\n if (pixels.data[i + 3] && (pixels.data[i] !== pixels.data[i + 1] || pixels.data[i + 1] !== pixels.data[i + 2])) {\n colored = true;\n break;\n }\n }\n this.device.queue.writeTexture(\n { texture: this.atlas.texture, origin: [x, y] },\n pixels.data,\n { bytesPerRow: width * 4, rowsPerImage: height },\n [width, height],\n );\n this.glyphUploadBytes += width * height * 4;\n this.glyphs.set(key, {\n colored,\n u0: (x + 2) / this.atlas.width,\n v0: (y + 2) / this.atlas.height,\n u1: (x + 2 + cell.width * CELL_WIDTH * scale) / this.atlas.width,\n v1: (y + 2 + CELL_HEIGHT * scale) / this.atlas.height,\n });\n this.glyphKeyUnits += key.length;\n }\n\n /** Clip geometry and UVs together. Only adjacent compatible textures may coalesce. */\n quad(resource: TextureResource, x: number, y: number, width: number, height: number,\n color: Vector4, mode = 0, uv: Vector4 = [0, 0, 1, 1],\n clip: Vector4 = [0, 0, this.width, this.height]): void {\n if (width <= 0 || height <= 0 || color[3] <= 0) return;\n const left = Math.max(0, x, clip[0]);\n const top = Math.max(0, y, clip[1]);\n const right = Math.min(this.width, x + width, clip[0] + clip[2]);\n const bottom = Math.min(this.height, y + height, clip[1] + clip[3]);\n if (right <= left || bottom <= top) return;\n if (this.quadCount >= MAX_QUADS) throw new Error(\"Frame exceeds bounded quad budget\");\n const offset = this.quadCount * STRIDE;\n if (offset + STRIDE > this.instances.length) {\n const grown = new Float32Array(Math.min(this.instances.length * 2, MAX_QUADS * STRIDE));\n grown.set(this.instances);\n this.instances = grown;\n }\n const du = uv[2] - uv[0];\n const dv = uv[3] - uv[1];\n this.instances.set([\n left, top, right - left, bottom - top,\n uv[0] + (left - x) / width * du,\n uv[1] + (top - y) / height * dv,\n uv[0] + (right - x) / width * du,\n uv[1] + (bottom - y) / height * dv,\n ...color, mode, 0, 0, 0,\n ], offset);\n const last = this.batches[this.batches.length - 1];\n if (last?.resource === resource) last.count++;\n else this.batches.push({ resource, start: this.quadCount, count: 1 });\n this.quadCount++;\n }\n\n solid(x: number, y: number, width: number, height: number, color: Vector4): void {\n this.quad(this.atlas, x, y, width, height, color);\n }\n\n placement(placement: ImagePlacement): void {\n const image = this.images.get(placement.key);\n if (!image) throw new Error(`Placement texture is missing: ${placement.key}`);\n const { sourceX: sx, sourceY: sy, sourceWidth: sw, sourceHeight: sh } = placement;\n if (!sw || !sh || !placement.width || !placement.height) return;\n // Clip out-of-texture source regions in destination space instead of stretching edge texels.\n const sourceLeft = placement.x + Math.max(0, -sx) / sw * placement.width;\n const sourceTop = placement.y + Math.max(0, -sy) / sh * placement.height;\n const sourceRight = placement.x + Math.min(sw, image.width - sx) / sw * placement.width;\n const sourceBottom = placement.y + Math.min(sh, image.height - sy) / sh * placement.height;\n const left = Math.max(sourceLeft, placement.clipX);\n const top = Math.max(sourceTop, placement.clipY);\n const right = Math.min(sourceRight, placement.clipX + placement.clipWidth);\n const bottom = Math.min(sourceBottom, placement.clipY + placement.clipHeight);\n this.quad(\n image, placement.x, placement.y, placement.width, placement.height, WHITE, 2,\n [sx / image.width, sy / image.height, (sx + sw) / image.width, (sy + sh) / image.height],\n [left, top, Math.max(0, right - left), Math.max(0, bottom - top)],\n );\n }\n\n decorations(cell: TerminalCell, x: number, y: number, width: number, foreground: Vector4): void {\n if (cell.attributes & 128) this.solid(x, y + 10, width, 1, foreground);\n if (cell.attributes & 256) this.solid(x, y + 1, width, 1, foreground);\n const style = cell.underlineStyle || (cell.attributes & 8 ? 1 : 0);\n const color = rgba(cell.underlineColor);\n if (style === 1) this.solid(x, y + 18, width, 1, color);\n else if (style === 2) {\n this.solid(x, y + 16, width, 1, color);\n this.solid(x, y + 18, width, 1, color);\n } else if (style === 3) {\n for (let dx = 0; dx < width; dx++) {\n this.solid(x + dx, y + 17 + Math.round(Math.sin((x + dx) * Math.PI / 4)), 1, 1, color);\n }\n } else if (style === 4 || style === 5) {\n const step = style === 4 ? 2 : 5;\n const segment = style === 4 ? 1 : 3;\n for (let dx = 0; dx < width; dx += step) this.solid(x + dx, y + 18, Math.min(segment, width - dx), 1, color);\n }\n }\n\n render(cells: readonly (TerminalCell | undefined)[], metadata: FrameMetadata, blinkOn: boolean) {\n const start = performance.now();\n this.quadCount = 0;\n this.batches = [];\n const placements = metadata.placements.map((placement, order) => ({\n placement,\n order,\n z: placement.kind === \"sixel\" ? -1 : placement.z,\n })).sort((a, b) => a.z - b.z || a.order - b.order);\n for (const item of placements) if (item.z < -1073741824) this.placement(item.placement);\n for (let i = 0; i < cells.length; i++) {\n const cell = cells[i];\n if (!cell) continue;\n this.solid((i % this.columns) * CELL_WIDTH, Math.floor(i / this.columns) * CELL_HEIGHT, CELL_WIDTH, CELL_HEIGHT, rgba(cell.background));\n }\n for (const item of placements) if (item.z >= -1073741824 && item.z < 0) this.placement(item.placement);\n for (let i = 0; i < cells.length; i++) {\n const cell = cells[i];\n if (!cell || !cell.width || (cell.attributes & 64) || ((cell.attributes & 16) && !blinkOn)) continue;\n const x = (i % this.columns) * CELL_WIDTH;\n const y = Math.floor(i / this.columns) * CELL_HEIGHT;\n const width = Math.min(cell.width * CELL_WIDTH, this.width - x);\n const foreground = rgba(cell.foreground);\n const glyph = this.glyphs.get(glyphKey(cell));\n if (glyph) {\n const tint: Vector4 = glyph.colored ? (cell.attributes & 2 ? [0.5, 0.5, 0.5, 1] : WHITE) : foreground;\n this.quad(this.atlas, x, y, cell.width * CELL_WIDTH, CELL_HEIGHT,\n tint, glyph.colored ? 2 : 1, [glyph.u0, glyph.v0, glyph.u1, glyph.v1]);\n }\n // Reverse and dim are already reflected in server-projected colors.\n this.decorations(cell, x, y, width, foreground);\n }\n for (const item of placements) if (item.z >= 0) this.placement(item.placement);\n const cursor = metadata.cursor;\n const cursorBlink = cursor.shape === 0 || cursor.shape % 2 === 1;\n if (cursor.visible && (!cursorBlink || blinkOn) && cursor.x >= 0 && cursor.x < this.columns && cursor.y >= 0 && cursor.y < this.rows) {\n const cell = cells[cursor.y * this.columns + cursor.x];\n const color = rgba(cell?.foreground ?? 0xffffffff);\n const x = cursor.x * CELL_WIDTH;\n const y = cursor.y * CELL_HEIGHT;\n if (cursor.shape === 3 || cursor.shape === 4) this.solid(x, y + 18, CELL_WIDTH, 2, color);\n else if (cursor.shape === 5 || cursor.shape === 6) this.solid(x, y, 2, CELL_HEIGHT, color);\n else {\n color[3] *= 0.55;\n this.solid(x, y, CELL_WIDTH, CELL_HEIGHT, color);\n }\n }\n const usedBytes = this.quadCount * STRIDE * 4;\n if (!this.instanceBuffer || usedBytes > this.instanceBufferBytes) {\n this.instanceBuffer?.destroy();\n this.instanceBufferBytes = Math.max(256, this.instances.byteLength);\n this.instanceBuffer = this.device.createBuffer({\n size: this.instanceBufferBytes,\n usage: GPUBufferUsage.VERTEX | GPUBufferUsage.COPY_DST,\n });\n }\n if (usedBytes) this.device.queue.writeBuffer(this.instanceBuffer, 0, this.instances, 0, this.quadCount * STRIDE);\n const encoder = this.device.createCommandEncoder();\n const base = rgba(metadata.defaultBackground ?? cells[0]?.background ?? 0xff000000);\n const pass = encoder.beginRenderPass({\n colorAttachments: [{\n view: this.context.getCurrentTexture().createView(),\n clearValue: { r: base[0], g: base[1], b: base[2], a: 1 },\n loadOp: \"clear\",\n storeOp: \"store\",\n }],\n });\n pass.setPipeline(this.pipeline);\n pass.setVertexBuffer(0, this.instanceBuffer);\n for (const batch of this.batches) {\n pass.setBindGroup(0, batch.resource.bindGroup);\n pass.draw(6, batch.count, 0, batch.start);\n }\n pass.end();\n this.device.queue.submit([encoder.finish()]);\n return { cpuMs: performance.now() - start, quads: this.quadCount, drawCalls: this.batches.length };\n }\n\n metrics() {\n return {\n fontFamily: this.font.family,\n rasterScale: this.scale,\n backingScale: this.backingScale,\n backingWidth: this.canvas.width,\n backingHeight: this.canvas.height,\n imageCount: this.images.size,\n textureBytes: this.textureBytes,\n atlasGlyphs: this.glyphs.size,\n atlasBytes: this.atlas.width * this.atlas.height * 4,\n atlasRebuilds: this.atlasRebuilds,\n imageUploadBytes: this.imageUploadBytes,\n imagePayloadBytes: this.imagePayloadBytes,\n glyphUploadBytes: this.glyphUploadBytes,\n instanceBufferBytes: this.instanceBufferBytes,\n };\n }\n\n async idle() {\n await this.device.queue.onSubmittedWorkDone();\n }\n\n dispose() {\n this.disposed = true;\n for (const image of this.images.values()) image.texture.destroy();\n this.images.clear();\n this.atlas?.texture.destroy();\n this.instanceBuffer?.destroy();\n this.uniform?.destroy();\n this.font?.dispose();\n this.fontMetrics.clear();\n this.context.unconfigure();\n this.device.destroy();\n }\n}\n"]}
1
+ {"version":3,"file":"renderer.js","sourceRoot":"","sources":["../src/renderer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACvC,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAC1E,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAC7D,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAalD,MAAM,UAAU,GAAG,EAAE,CAAC;AACtB,MAAM,WAAW,GAAG,EAAE,CAAC;AACvB,MAAM,SAAS,GAAG,IAAI,GAAG,IAAI,CAAC;AAC9B,MAAM,UAAU,GAAG,KAAK,CAAC;AACzB,MAAM,mBAAmB,GAAG,IAAI,GAAG,IAAI,CAAC;AACxC,MAAM,MAAM,GAAG,WAAW,CAAC;AAC3B,MAAM,KAAK,GAAY,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;AAEpC,SAAS,IAAI,CAAC,MAAc;IAC1B,OAAO;QACL,CAAC,MAAM,GAAG,GAAG,CAAC,GAAG,GAAG;QACpB,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC,GAAG,GAAG,CAAC,GAAG,GAAG;QAC5B,CAAC,CAAC,MAAM,KAAK,EAAE,CAAC,GAAG,GAAG,CAAC,GAAG,GAAG;QAC7B,CAAC,CAAC,MAAM,KAAK,EAAE,CAAC,GAAG,GAAG,CAAC,GAAG,GAAG;KAC9B,CAAC;AACJ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;YAAE,KAAK,CAAC,OAAO,EAAE,CAAC;QAC1D,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;QACpB,IAAI,CAAC,KAAK,EAAE,OAAO,EAAE,CAAC;QACtB,IAAI,CAAC,IAAI,EAAE,OAAO,EAAE,CAAC;QACrB,IAAI,CAAC,WAAW,CAAC,KAAK,EAAE,CAAC;QACzB,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC;IACzB,CAAC;CACF","sourcesContent":["import { LIMITS } from \"./protocol.js\";\nimport { loadFont, measureFont, normalizeFont } from \"./terminal-font.js\";\nimport { createRenderBackend } from \"./backend-selection.js\";\nimport { QUAD_STRIDE } from \"./render-backend.js\";\nimport type { RenderBackend, RenderBatch, RenderColor, RenderTexture } from \"./render-backend.js\";\nimport type { FontMetrics, LoadedFont, NormalizedFont } from \"./terminal-font.js\";\nimport type { TerminalFont, TerminalRendererPreference, TerminalSize } from \"./types.js\";\nimport type { FrameImage, FrameMetadata, ImagePlacement, TerminalCell } from \"./wire-types.js\";\n\ntype Vector4 = RenderColor;\ntype TextureResource = RenderTexture;\ninterface Shelf { x: number; y: number; rowHeight: number }\ninterface GlyphPlacement { key: string; cell: TerminalCell; x: number; y: number; width: number; height: number }\ninterface Glyph { colored: boolean; u0: number; v0: number; u1: number; v1: number }\ntype Batch = RenderBatch;\n\nconst CELL_WIDTH = 10;\nconst CELL_HEIGHT = 20;\nconst MAX_QUADS = 1024 * 1024;\nconst MAX_GLYPHS = 16384;\nconst MAX_GLYPH_KEY_UNITS = 1024 * 1024;\nconst STRIDE = QUAD_STRIDE;\nconst WHITE: Vector4 = [1, 1, 1, 1];\n\nfunction rgba(packed: number): Vector4 {\n return [\n (packed & 255) / 255,\n ((packed >>> 8) & 255) / 255,\n ((packed >>> 16) & 255) / 255,\n ((packed >>> 24) & 255) / 255,\n ];\n}\n\nfunction glyphKey(cell: TerminalCell): string {\n return `${cell.attributes & 5}/${cell.width}/${cell.text}`;\n}\n\n/** Shelf packer. Plans are computed before mutating the atlas used by a submitted frame. */\nfunction packGlyphs(glyphs: ReadonlyMap<string, TerminalCell>, size: number, scale: number,\n initial: Shelf = { x: 0, y: 0, rowHeight: 0 }): { placements: GlyphPlacement[]; shelf: Shelf } | null {\n let { x, y, rowHeight } = initial;\n const placements = [];\n for (const [key, cell] of glyphs) {\n const width = Math.ceil(cell.width * CELL_WIDTH * scale) + 4;\n const height = Math.ceil(CELL_HEIGHT * scale) + 4;\n if (width > size || height > size) return null;\n if (x + width > size) { x = 0; y += rowHeight; rowHeight = 0; }\n if (y + height > size) return null;\n placements.push({ key, cell, x, y, width, height });\n x += width;\n rowHeight = Math.max(rowHeight, height);\n }\n return { placements, shelf: { x, y, rowHeight } };\n}\n\n/** Shared instanced-quad preparation; Canvas2D rasterizes reusable glyphs for either backend. */\nexport class TerminalRenderer {\n canvas: OffscreenCanvas;\n scale: number;\n backingScale: number;\n backend: RenderBackend;\n fallbackReason?: string;\n fontConfiguration: NormalizedFont;\n fontMetrics: Map<number, FontMetrics>;\n images: Map<string, TextureResource>;\n glyphs: Map<string, Glyph>;\n imageUploadBytes: number;\n imagePayloadBytes: number;\n glyphUploadBytes: number;\n atlasRebuilds: number;\n textureBytes: number;\n instances: Float32Array<ArrayBuffer>;\n disposed: boolean;\n columns: number;\n rows: number;\n // Initialized by create() before the renderer can prepare or submit frames.\n font!: LoadedFont;\n rasterCanvas!: OffscreenCanvas;\n raster!: OffscreenCanvasRenderingContext2D;\n atlas!: TextureResource;\n glyphKeyUnits = 0;\n shelf: Shelf = { x: 0, y: 0, rowHeight: 0 };\n canvasLimited = false;\n width = 0;\n height = 0;\n quadCount = 0;\n batches: Batch[] = [];\n\n static async create(canvas: OffscreenCanvas, scale: number, onFatal: (error: Error) => void,\n font?: TerminalFont, preference: TerminalRendererPreference = \"auto\"): Promise<TerminalRenderer> {\n const normalizedFont = normalizeFont(font);\n if (!Number.isFinite(scale) || scale < 0.5 || scale > 3) throw new Error(\"Invalid backing scale\");\n const { backend, fallbackReason } = await createRenderBackend(canvas, onFatal, preference);\n const renderer = new TerminalRenderer(canvas, scale, backend, normalizedFont);\n renderer.fallbackReason = fallbackReason;\n try {\n await renderer.initialize();\n return renderer;\n } catch (error) {\n renderer.dispose();\n throw error;\n }\n }\n\n constructor(canvas: OffscreenCanvas, scale: number, backend: RenderBackend, font: NormalizedFont) {\n if (!Number.isFinite(scale) || scale < 0.5 || scale > 3) throw new Error(\"Invalid backing scale\");\n this.canvas = canvas;\n this.scale = scale;\n this.backingScale = scale;\n this.backend = backend;\n this.fontConfiguration = font;\n this.fontMetrics = new Map();\n this.images = new Map();\n this.glyphs = new Map();\n this.imageUploadBytes = 0;\n this.imagePayloadBytes = 0;\n this.glyphUploadBytes = 0;\n this.atlasRebuilds = 0;\n this.textureBytes = 0;\n this.instances = new Float32Array(4096 * STRIDE);\n this.disposed = false;\n this.columns = 0;\n this.rows = 0;\n }\n\n async initialize() {\n this.font = await loadFont(this.fontConfiguration);\n this.rasterCanvas = new OffscreenCanvas(1, 1);\n const raster = this.rasterCanvas.getContext(\"2d\", { willReadFrequently: true });\n if (!raster) throw new Error(\"Worker glyph rasterization is unavailable\");\n this.raster = raster;\n this.resetAtlas(Math.min(2048, this.backend.maxTextureDimension2D));\n }\n\n createTexture(width: number, height: number, label: string): TextureResource {\n return this.backend.createTexture(width, height, label);\n }\n\n resetAtlas(size: number): void {\n this.atlas?.destroy();\n this.atlas = this.createTexture(size, size, \"Glyph atlas\");\n this.glyphs.clear();\n this.glyphKeyUnits = 0;\n this.shelf = { x: 0, y: 0, rowHeight: 0 };\n }\n\n resize(columns: number, rows: number, viewport?: TerminalSize): void {\n const width = columns * CELL_WIDTH;\n const height = rows * CELL_HEIGHT;\n const limit = this.backend.maxCanvasDimension2D;\n const requested = Math.min(this.scale, viewport ? viewport.width / width : Infinity, viewport ? viewport.height / height : Infinity);\n this.canvasLimited = width * requested > limit || height * requested > limit;\n this.backingScale = Math.min(requested, limit / width, limit / height);\n const backingWidth = Math.max(1, Math.min(limit, Math.ceil(width * this.backingScale)));\n const backingHeight = Math.max(1, Math.min(limit, Math.ceil(height * this.backingScale)));\n if (this.columns === columns && this.rows === rows && this.canvas.width === backingWidth && this.canvas.height === backingHeight) return;\n this.columns = columns;\n this.rows = rows;\n this.width = width;\n this.height = height;\n this.canvas.width = backingWidth;\n this.canvas.height = backingHeight;\n this.backend.resize(width, height);\n }\n\n /** Call only between submissions. Missing/over-budget resources terminate the session. */\n async updateImages(incoming: readonly FrameImage[], retainedKeys: readonly string[]): Promise<void> {\n const retained = new Set(retainedKeys);\n const replacements = new Map(incoming.map(image => [image.key, image]));\n let projectedBytes = 0;\n for (const key of retained) {\n const image = replacements.get(key) || this.images.get(key);\n if (!image) throw new Error(`Missing retained image resource: ${key}`);\n projectedBytes += image.width * image.height * 4;\n }\n if (projectedBytes > LIMITS.textureBytes) throw new Error(\"Retained images exceed the 256 MiB texture budget\");\n for (const [key, image] of this.images) {\n if (!retained.has(key) || replacements.has(key)) {\n image.destroy();\n this.textureBytes -= image.width * image.height * 4;\n this.images.delete(key);\n }\n }\n for (const image of incoming) {\n const resource = this.createTexture(image.width, image.height, `Image ${image.key}`);\n try {\n if (image.format === \"rgba\") {\n resource.writePixels(image.bytes, image.width, image.height);\n } else {\n // Check IHDR before decoding so a tiny PNG cannot claim unbounded decoded dimensions.\n const png = new DataView(image.bytes.buffer, image.bytes.byteOffset, image.bytes.byteLength);\n if (png.byteLength < 33 || png.getUint32(0) !== 0x89504e47 || png.getUint32(4) !== 0x0d0a1a0a ||\n png.getUint32(8) !== 13 || png.getUint32(12) !== 0x49484452 ||\n png.getUint32(16) !== image.width || png.getUint32(20) !== image.height) {\n throw new Error(`PNG header dimensions do not match resource ${image.key}`);\n }\n const bitmap = await createImageBitmap(new Blob([image.bytes], { type: \"image/png\" }), {\n premultiplyAlpha: \"none\",\n colorSpaceConversion: \"none\",\n });\n try {\n if (bitmap.width !== image.width || bitmap.height !== image.height) throw new Error(\"Decoded PNG dimension mismatch\");\n resource.writeBitmap(bitmap);\n } finally {\n bitmap.close();\n }\n }\n this.images.set(image.key, resource);\n this.textureBytes += image.width * image.height * 4;\n this.imageUploadBytes += image.width * image.height * 4;\n this.imagePayloadBytes += image.byteLength;\n } catch (error) {\n resource.destroy();\n throw error;\n }\n }\n }\n\n prepareGlyphs(cells: readonly (TerminalCell | undefined)[]): void {\n const visible = new Map<string, TerminalCell>();\n for (const cell of cells) {\n if (!cell || !cell.width || !cell.text.trim() || (cell.attributes & 64)) continue;\n visible.set(glyphKey(cell), cell);\n }\n const keyUnits = (glyphs: ReadonlyMap<string, TerminalCell>) => [...glyphs.keys()].reduce((total, key) => total + key.length, 0);\n if (visible.size > MAX_GLYPHS || keyUnits(visible) > MAX_GLYPH_KEY_UNITS) {\n throw new Error(\"Visible glyph metadata exceeds the bounded glyph cache\");\n }\n const missing = new Map([...visible].filter(([key]) => !this.glyphs.has(key)));\n if (!missing.size) return;\n const metadataFits = this.glyphs.size + missing.size <= MAX_GLYPHS &&\n this.glyphKeyUnits + keyUnits(missing) <= MAX_GLYPH_KEY_UNITS;\n let plan = metadataFits ? packGlyphs(missing, this.atlas.width, this.scale, this.shelf) : null;\n if (!plan) {\n let size = this.atlas.width;\n const maxSize = Math.min(4096, this.backend.maxTextureDimension2D);\n while (!(plan = packGlyphs(visible, size, this.scale)) && size < maxSize) {\n size = Math.min(size * 2, maxSize);\n }\n if (!plan) throw new Error(\"Visible glyphs exceed the bounded 4096² mask atlas; reduce the grid or backing scale\");\n this.resetAtlas(size);\n this.atlasRebuilds++;\n }\n for (const placement of plan.placements) this.uploadGlyph(placement);\n this.shelf = plan.shelf;\n }\n\n uploadGlyph({ key, cell, x, y, width, height }: GlyphPlacement): void {\n const scale = this.scale;\n const raster = this.raster;\n const style = cell.attributes & 5;\n let metrics = this.fontMetrics.get(style);\n if (!metrics) {\n metrics = measureFont(raster, this.font.cssFamily, style, scale, CELL_WIDTH, CELL_HEIGHT);\n this.fontMetrics.set(style, metrics);\n }\n this.rasterCanvas.width = width;\n this.rasterCanvas.height = height;\n raster.font = metrics.font;\n raster.textBaseline = \"alphabetic\";\n raster.textAlign = \"left\";\n raster.fillStyle = \"white\";\n // One transform per font style, not per glyph: borders remain font outlines,\n // and graphemes are clipped to their server-owned span without individual stretching.\n raster.setTransform(metrics.xScale, 0, 0, metrics.yScale, 2, 2 + metrics.baseline);\n raster.fillText(cell.text, 0, 0);\n const pixels = raster.getImageData(0, 0, width, height);\n let colored = false;\n for (let i = 0; i < pixels.data.length; i += 4) {\n if (pixels.data[i + 3] && (pixels.data[i] !== pixels.data[i + 1] || pixels.data[i + 1] !== pixels.data[i + 2])) {\n colored = true;\n break;\n }\n }\n this.atlas.writePixels(pixels.data, width, height, x, y);\n this.glyphUploadBytes += width * height * 4;\n this.glyphs.set(key, {\n colored,\n u0: (x + 2) / this.atlas.width,\n v0: (y + 2) / this.atlas.height,\n u1: (x + 2 + cell.width * CELL_WIDTH * scale) / this.atlas.width,\n v1: (y + 2 + CELL_HEIGHT * scale) / this.atlas.height,\n });\n this.glyphKeyUnits += key.length;\n }\n\n /** Clip geometry and UVs together. Only adjacent compatible textures may coalesce. */\n quad(resource: TextureResource, x: number, y: number, width: number, height: number,\n color: Vector4, mode = 0, uv: Vector4 = [0, 0, 1, 1],\n clip: Vector4 = [0, 0, this.width, this.height]): void {\n if (width <= 0 || height <= 0 || color[3] <= 0) return;\n const left = Math.max(0, x, clip[0]);\n const top = Math.max(0, y, clip[1]);\n const right = Math.min(this.width, x + width, clip[0] + clip[2]);\n const bottom = Math.min(this.height, y + height, clip[1] + clip[3]);\n if (right <= left || bottom <= top) return;\n if (this.quadCount >= MAX_QUADS) throw new Error(\"Frame exceeds bounded quad budget\");\n const offset = this.quadCount * STRIDE;\n if (offset + STRIDE > this.instances.length) {\n const grown = new Float32Array(Math.min(this.instances.length * 2, MAX_QUADS * STRIDE));\n grown.set(this.instances);\n this.instances = grown;\n }\n const du = uv[2] - uv[0];\n const dv = uv[3] - uv[1];\n this.instances.set([\n left, top, right - left, bottom - top,\n uv[0] + (left - x) / width * du,\n uv[1] + (top - y) / height * dv,\n uv[0] + (right - x) / width * du,\n uv[1] + (bottom - y) / height * dv,\n ...color, mode, 0, 0, 0,\n ], offset);\n const last = this.batches[this.batches.length - 1];\n if (last?.resource === resource) last.count++;\n else this.batches.push({ resource, start: this.quadCount, count: 1 });\n this.quadCount++;\n }\n\n solid(x: number, y: number, width: number, height: number, color: Vector4): void {\n this.quad(this.atlas, x, y, width, height, color);\n }\n\n placement(placement: ImagePlacement): void {\n const image = this.images.get(placement.key);\n if (!image) throw new Error(`Placement texture is missing: ${placement.key}`);\n const { sourceX: sx, sourceY: sy, sourceWidth: sw, sourceHeight: sh } = placement;\n if (!sw || !sh || !placement.width || !placement.height) return;\n // Clip out-of-texture source regions in destination space instead of stretching edge texels.\n const sourceLeft = placement.x + Math.max(0, -sx) / sw * placement.width;\n const sourceTop = placement.y + Math.max(0, -sy) / sh * placement.height;\n const sourceRight = placement.x + Math.min(sw, image.width - sx) / sw * placement.width;\n const sourceBottom = placement.y + Math.min(sh, image.height - sy) / sh * placement.height;\n const left = Math.max(sourceLeft, placement.clipX);\n const top = Math.max(sourceTop, placement.clipY);\n const right = Math.min(sourceRight, placement.clipX + placement.clipWidth);\n const bottom = Math.min(sourceBottom, placement.clipY + placement.clipHeight);\n this.quad(\n image, placement.x, placement.y, placement.width, placement.height, WHITE, 2,\n [sx / image.width, sy / image.height, (sx + sw) / image.width, (sy + sh) / image.height],\n [left, top, Math.max(0, right - left), Math.max(0, bottom - top)],\n );\n }\n\n decorations(cell: TerminalCell, x: number, y: number, width: number, foreground: Vector4): void {\n if (cell.attributes & 128) this.solid(x, y + 10, width, 1, foreground);\n if (cell.attributes & 256) this.solid(x, y + 1, width, 1, foreground);\n const style = cell.underlineStyle || (cell.attributes & 8 ? 1 : 0);\n const color = rgba(cell.underlineColor);\n if (style === 1) this.solid(x, y + 18, width, 1, color);\n else if (style === 2) {\n this.solid(x, y + 16, width, 1, color);\n this.solid(x, y + 18, width, 1, color);\n } else if (style === 3) {\n for (let dx = 0; dx < width; dx++) {\n this.solid(x + dx, y + 17 + Math.round(Math.sin((x + dx) * Math.PI / 4)), 1, 1, color);\n }\n } else if (style === 4 || style === 5) {\n const step = style === 4 ? 2 : 5;\n const segment = style === 4 ? 1 : 3;\n for (let dx = 0; dx < width; dx += step) this.solid(x + dx, y + 18, Math.min(segment, width - dx), 1, color);\n }\n }\n\n render(cells: readonly (TerminalCell | undefined)[], metadata: FrameMetadata, blinkOn: boolean) {\n const start = performance.now();\n this.quadCount = 0;\n this.batches = [];\n const placements = metadata.placements.map((placement, order) => ({\n placement,\n order,\n z: placement.kind === \"sixel\" ? -1 : placement.z,\n })).sort((a, b) => a.z - b.z || a.order - b.order);\n for (const item of placements) if (item.z < -1073741824) this.placement(item.placement);\n for (let i = 0; i < cells.length; i++) {\n const cell = cells[i];\n if (!cell) continue;\n this.solid((i % this.columns) * CELL_WIDTH, Math.floor(i / this.columns) * CELL_HEIGHT, CELL_WIDTH, CELL_HEIGHT, rgba(cell.background));\n }\n for (const item of placements) if (item.z >= -1073741824 && item.z < 0) this.placement(item.placement);\n for (let i = 0; i < cells.length; i++) {\n const cell = cells[i];\n if (!cell || !cell.width || (cell.attributes & 64) || ((cell.attributes & 16) && !blinkOn)) continue;\n const x = (i % this.columns) * CELL_WIDTH;\n const y = Math.floor(i / this.columns) * CELL_HEIGHT;\n const width = Math.min(cell.width * CELL_WIDTH, this.width - x);\n const foreground = rgba(cell.foreground);\n const glyph = this.glyphs.get(glyphKey(cell));\n if (glyph) {\n const tint: Vector4 = glyph.colored ? (cell.attributes & 2 ? [0.5, 0.5, 0.5, 1] : WHITE) : foreground;\n this.quad(this.atlas, x, y, cell.width * CELL_WIDTH, CELL_HEIGHT,\n tint, glyph.colored ? 2 : 1, [glyph.u0, glyph.v0, glyph.u1, glyph.v1]);\n }\n // Reverse and dim are already reflected in server-projected colors.\n this.decorations(cell, x, y, width, foreground);\n }\n for (const item of placements) if (item.z >= 0) this.placement(item.placement);\n const cursor = metadata.cursor;\n const cursorBlink = cursor.shape === 0 || cursor.shape % 2 === 1;\n if (cursor.visible && (!cursorBlink || blinkOn) && cursor.x >= 0 && cursor.x < this.columns && cursor.y >= 0 && cursor.y < this.rows) {\n const cell = cells[cursor.y * this.columns + cursor.x];\n const color = rgba(cell?.foreground ?? 0xffffffff);\n const x = cursor.x * CELL_WIDTH;\n const y = cursor.y * CELL_HEIGHT;\n if (cursor.shape === 3 || cursor.shape === 4) this.solid(x, y + 18, CELL_WIDTH, 2, color);\n else if (cursor.shape === 5 || cursor.shape === 6) this.solid(x, y, 2, CELL_HEIGHT, color);\n else {\n color[3] *= 0.55;\n this.solid(x, y, CELL_WIDTH, CELL_HEIGHT, color);\n }\n }\n const base = rgba(metadata.defaultBackground ?? cells[0]?.background ?? 0xff000000);\n this.backend.submit(this.instances, this.quadCount, this.batches, base);\n return { cpuMs: performance.now() - start, quads: this.quadCount, drawCalls: this.batches.length };\n }\n\n metrics() {\n return {\n renderer: this.backend.kind,\n rendererFallbackReason: this.fallbackReason,\n fontFamily: this.font.family,\n rasterScale: this.scale,\n backingScale: this.backingScale,\n backingWidth: this.canvas.width,\n backingHeight: this.canvas.height,\n imageCount: this.images.size,\n textureBytes: this.textureBytes,\n atlasGlyphs: this.glyphs.size,\n atlasBytes: this.atlas.width * this.atlas.height * 4,\n atlasRebuilds: this.atlasRebuilds,\n imageUploadBytes: this.imageUploadBytes,\n imagePayloadBytes: this.imagePayloadBytes,\n glyphUploadBytes: this.glyphUploadBytes,\n instanceBufferBytes: this.backend.instanceBufferBytes,\n };\n }\n\n async idle() {\n await this.backend.idle();\n }\n\n dispose() {\n if (this.disposed) return;\n this.disposed = true;\n for (const image of this.images.values()) image.destroy();\n this.images.clear();\n this.atlas?.destroy();\n this.font?.dispose();\n this.fontMetrics.clear();\n this.backend.dispose();\n }\n}\n"]}