@ai-ecoverse/slicc-spectrum 1.86.2 → 1.86.3

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.
@@ -3611,20 +3611,20 @@ var OutputAnnouncements = class {
3611
3611
  const rows = core.getRows();
3612
3612
  const history = core.getScrollbackCount();
3613
3613
  const discarded = core.getScrollbackDiscardedCount?.() ?? 0;
3614
- const base = history + discarded;
3615
- const first = start ?? base;
3616
- if (first < discarded || (base + rows - first) * cols > MAX_CELLS)
3614
+ const base2 = history + discarded;
3615
+ const first = start ?? base2;
3616
+ if (first < discarded || (base2 + rows - first) * cols > MAX_CELLS)
3617
3617
  return null;
3618
3618
  const lines = [];
3619
3619
  let length = 0;
3620
- for (let row = first; row < base + rows; row++) {
3621
- const offset = base - row - 1;
3622
- const width = row < base ? core.getScrollbackLineLen(offset) : cols;
3620
+ for (let row = first; row < base2 + rows; row++) {
3621
+ const offset = base2 - row - 1;
3622
+ const width = row < base2 ? core.getScrollbackLineLen(offset) : cols;
3623
3623
  if (width > cols)
3624
3624
  return null;
3625
3625
  let text = "";
3626
3626
  for (let col = 0; col < width; col++) {
3627
- const cell = row < base ? core.getScrollbackCell(offset, col) : core.getCell(row - base, col);
3627
+ const cell = row < base2 ? core.getScrollbackCell(offset, col) : core.getCell(row - base2, col);
3628
3628
  if (cell.width === 0 || cell.spacerHead)
3629
3629
  continue;
3630
3630
  const chars = cell.chars ?? String.fromCodePoint(cell.char || 32);
@@ -3641,8 +3641,8 @@ var OutputAnnouncements = class {
3641
3641
  const previous = this.previous;
3642
3642
  if (!previous)
3643
3643
  return;
3644
- const base = core.getScrollbackCount() + (core.getScrollbackDiscardedCount?.() ?? 0);
3645
- if (previous.cols !== core.getCols() || previous.rows !== core.getRows() || previous.alternate !== core.usingAltScreen() || base < previous.base) {
3644
+ const base2 = core.getScrollbackCount() + (core.getScrollbackDiscardedCount?.() ?? 0);
3645
+ if (previous.cols !== core.getCols() || previous.rows !== core.getRows() || previous.alternate !== core.usingAltScreen() || base2 < previous.base) {
3646
3646
  this.previous = this.snapshot(core);
3647
3647
  return;
3648
3648
  }
@@ -3654,8 +3654,8 @@ var OutputAnnouncements = class {
3654
3654
  const changed = current.lines.filter((line, index) => line.trim() && line !== previous.lines[index]);
3655
3655
  this.previous = {
3656
3656
  ...current,
3657
- base,
3658
- lines: current.lines.slice(base - current.base)
3657
+ base: base2,
3658
+ lines: current.lines.slice(base2 - current.base)
3659
3659
  };
3660
3660
  if (!changed.length)
3661
3661
  return;
@@ -5193,6 +5193,1022 @@ function colorReply(code, rgb, end) {
5193
5193
  return `\x1B]${code};rgb:${rgb.slice(0, 3).map(hex).join("/")}${end}`;
5194
5194
  }
5195
5195
 
5196
+ // node_modules/@wterm/ghostty/dist/wasm-bindings.js
5197
+ var CELL_BYTES = 16;
5198
+ var CELL_BYTES_V2 = 20;
5199
+ var UNDERLINE_STYLES = [
5200
+ "none",
5201
+ "single",
5202
+ "double",
5203
+ "curly",
5204
+ "dotted",
5205
+ "dashed"
5206
+ ];
5207
+ var REMEDY = 'Serve the binary from your app and pass its URL: GhosttyCore.load({ wasmPath: "/ghostty-vt.wasm" }). The file ships with the package as @wterm/ghostty/ghostty-vt.wasm. See the Bundlers section of the @wterm/ghostty README.';
5208
+ function defaultWasmUrl() {
5209
+ return new URL("../wasm/ghostty-vt.wasm", import.meta.url).href;
5210
+ }
5211
+ function hasWasmMagic(bytes) {
5212
+ if (bytes.byteLength < 4)
5213
+ return false;
5214
+ const head = new Uint8Array(bytes, 0, 4);
5215
+ return head[0] === 0 && head[1] === 97 && head[2] === 115 && head[3] === 109;
5216
+ }
5217
+ var modules2 = /* @__PURE__ */ new Map();
5218
+ var MAX_CACHED_MODULES2 = 4;
5219
+ async function compileWasm(url) {
5220
+ const response = await fetch(url);
5221
+ if (!response.ok) {
5222
+ throw new Error(`@wterm/ghostty: fetching ${url} returned ${response.status} ${response.statusText}. ${REMEDY}`);
5223
+ }
5224
+ if (typeof WebAssembly.compileStreaming === "function" && response.headers.get("Content-Type")?.trim().toLowerCase() === "application/wasm") {
5225
+ try {
5226
+ return await WebAssembly.compileStreaming(response.clone());
5227
+ } catch {
5228
+ }
5229
+ }
5230
+ const bytes = await response.arrayBuffer();
5231
+ if (!hasWasmMagic(bytes)) {
5232
+ throw new Error(`@wterm/ghostty: ${url} did not return a WASM module. ${REMEDY}`);
5233
+ }
5234
+ return WebAssembly.compile(bytes);
5235
+ }
5236
+ function loadModule(url) {
5237
+ const cached = modules2.get(url);
5238
+ if (cached) {
5239
+ modules2.delete(url);
5240
+ modules2.set(url, cached);
5241
+ return cached;
5242
+ }
5243
+ const pending = compileWasm(url).catch((error) => {
5244
+ if (modules2.get(url) === pending)
5245
+ modules2.delete(url);
5246
+ throw error;
5247
+ });
5248
+ modules2.set(url, pending);
5249
+ if (modules2.size > MAX_CACHED_MODULES2)
5250
+ modules2.delete(modules2.keys().next().value);
5251
+ return pending;
5252
+ }
5253
+ async function loadGhosttyWasm(wasmUrl) {
5254
+ let url = wasmUrl ?? defaultWasmUrl();
5255
+ if (wasmUrl === void 0 && url.startsWith("file:") && typeof document !== "undefined") {
5256
+ throw new Error(`@wterm/ghostty: your bundler resolved the WASM URL to ${url}, a path on the machine that built the bundle, so the browser cannot fetch it. ${REMEDY}`);
5257
+ }
5258
+ if (typeof document !== "undefined")
5259
+ url = new URL(url, document.baseURI).href;
5260
+ else if (typeof location !== "undefined")
5261
+ url = new URL(url, location.href).href;
5262
+ const module = await loadModule(url);
5263
+ let wasmMemory;
5264
+ const instance = await WebAssembly.instantiate(module, {
5265
+ env: {
5266
+ log(ptr, len) {
5267
+ const text = new TextDecoder().decode(new Uint8Array(wasmMemory.buffer, ptr, len));
5268
+ console.log("[ghostty-vt]", text);
5269
+ }
5270
+ }
5271
+ });
5272
+ wasmMemory = instance.exports.memory;
5273
+ const exports = instance.exports;
5274
+ return { exports, instance };
5275
+ }
5276
+ function parseCell(view, byteOffset, cellBytes = CELL_BYTES) {
5277
+ const colorFlags = view.getUint8(byteOffset + 12);
5278
+ const contentFlags = view.getUint8(byteOffset + 13);
5279
+ const cell = {
5280
+ codepoint: view.getUint32(byteOffset, true),
5281
+ fgR: view.getUint8(byteOffset + 4),
5282
+ fgG: view.getUint8(byteOffset + 5),
5283
+ fgB: view.getUint8(byteOffset + 6),
5284
+ bgR: view.getUint8(byteOffset + 7),
5285
+ bgG: view.getUint8(byteOffset + 8),
5286
+ bgB: view.getUint8(byteOffset + 9),
5287
+ flags: view.getUint8(byteOffset + 10),
5288
+ width: view.getUint8(byteOffset + 11),
5289
+ colorFlags,
5290
+ hasGrapheme: (contentFlags & 1) !== 0,
5291
+ hasHyperlink: (contentFlags & 2) !== 0,
5292
+ spacerHead: (contentFlags & 4) !== 0
5293
+ };
5294
+ if (cellBytes === CELL_BYTES_V2) {
5295
+ cell.underlineStyle = UNDERLINE_STYLES[view.getUint8(byteOffset + 16)];
5296
+ cell.underlineRgb = colorFlags & 4 ? view.getUint8(byteOffset + 17) << 16 | view.getUint8(byteOffset + 18) << 8 | view.getUint8(byteOffset + 19) : void 0;
5297
+ }
5298
+ return cell;
5299
+ }
5300
+ function allocBuffer(wasm, size) {
5301
+ if (!Number.isSafeInteger(size) || size <= 0 || size > 4294967295)
5302
+ return 0;
5303
+ try {
5304
+ return wasm.exports.alloc_buffer(size);
5305
+ } catch {
5306
+ return 0;
5307
+ }
5308
+ }
5309
+ function freeBuffer(wasm, ptr, size) {
5310
+ if (ptr === 0 || !Number.isSafeInteger(size) || size <= 0)
5311
+ return;
5312
+ try {
5313
+ wasm.exports.free_buffer(ptr, size);
5314
+ } catch {
5315
+ }
5316
+ }
5317
+ var GRAPHICS_IMAGE_BYTES = 16;
5318
+ var GRAPHICS_PLACEMENT_BYTES = 60;
5319
+ function readGraphicsImages(wasm, termPtr, bufPtr, capacity) {
5320
+ const read2 = wasm.exports.graphics_images;
5321
+ if (!read2 || !Number.isSafeInteger(capacity) || capacity < 0)
5322
+ return [];
5323
+ let count;
5324
+ try {
5325
+ count = read2(termPtr, bufPtr, capacity);
5326
+ } catch {
5327
+ return [];
5328
+ }
5329
+ if (!Number.isSafeInteger(count) || count < 0 || count > capacity)
5330
+ return [];
5331
+ const byteLength = count * GRAPHICS_IMAGE_BYTES;
5332
+ if (!Number.isSafeInteger(byteLength))
5333
+ return [];
5334
+ let view;
5335
+ try {
5336
+ view = new DataView(wasm.exports.memory.buffer, bufPtr, byteLength);
5337
+ } catch {
5338
+ return [];
5339
+ }
5340
+ const result = [];
5341
+ for (let i = 0; i < count; i++) {
5342
+ const offset = i * GRAPHICS_IMAGE_BYTES;
5343
+ result.push({
5344
+ imageId: view.getUint32(offset, true),
5345
+ version: view.getUint32(offset + 4, true),
5346
+ width: view.getUint32(offset + 8, true),
5347
+ height: view.getUint32(offset + 12, true)
5348
+ });
5349
+ }
5350
+ return result;
5351
+ }
5352
+ function readGraphicsPlacements(wasm, termPtr, bufPtr, capacity) {
5353
+ const read2 = wasm.exports.graphics_placements;
5354
+ if (!read2 || !Number.isSafeInteger(capacity) || capacity < 0)
5355
+ return [];
5356
+ let count;
5357
+ try {
5358
+ count = read2(termPtr, bufPtr, capacity);
5359
+ } catch {
5360
+ return [];
5361
+ }
5362
+ if (!Number.isSafeInteger(count) || count < 0 || count > capacity)
5363
+ return [];
5364
+ const byteLength = count * GRAPHICS_PLACEMENT_BYTES;
5365
+ if (!Number.isSafeInteger(byteLength))
5366
+ return [];
5367
+ let view;
5368
+ try {
5369
+ view = new DataView(wasm.exports.memory.buffer, bufPtr, byteLength);
5370
+ } catch {
5371
+ return [];
5372
+ }
5373
+ const result = [];
5374
+ for (let i = 0; i < count; i++) {
5375
+ const offset = i * GRAPHICS_PLACEMENT_BYTES;
5376
+ const imageId = view.getUint32(offset, true);
5377
+ const placementId = view.getUint32(offset + 4, true);
5378
+ const placementTag = view.getUint32(offset + 56, true);
5379
+ result.push({
5380
+ placementKey: `${imageId}:${placementId}:${placementTag}`,
5381
+ imageId,
5382
+ imageVersion: view.getUint32(offset + 8, true),
5383
+ row: view.getUint32(offset + 12, true),
5384
+ col: view.getUint32(offset + 16, true),
5385
+ offsetX: view.getUint32(offset + 20, true),
5386
+ offsetY: view.getUint32(offset + 24, true),
5387
+ sourceX: view.getUint32(offset + 28, true),
5388
+ sourceY: view.getUint32(offset + 32, true),
5389
+ sourceWidth: view.getUint32(offset + 36, true),
5390
+ sourceHeight: view.getUint32(offset + 40, true),
5391
+ columns: view.getUint32(offset + 44, true),
5392
+ rows: view.getUint32(offset + 48, true),
5393
+ z: view.getInt32(offset + 52, true)
5394
+ });
5395
+ }
5396
+ return result;
5397
+ }
5398
+ function writeString(wasm, termPtr, str, afterChunk) {
5399
+ const encoded = new TextEncoder().encode(str);
5400
+ writeBytes(wasm, termPtr, encoded, afterChunk);
5401
+ }
5402
+ function writeBytes(wasm, termPtr, data, afterChunk) {
5403
+ let offset = 0;
5404
+ while (offset < data.length) {
5405
+ const length = Math.min(data.length - offset, 8192);
5406
+ const bufPtr = allocBuffer(wasm, length);
5407
+ if (bufPtr === 0)
5408
+ return;
5409
+ try {
5410
+ new Uint8Array(wasm.exports.memory.buffer, bufPtr, length).set(data.subarray(offset, offset + length));
5411
+ wasm.exports.write(termPtr, bufPtr, length);
5412
+ } finally {
5413
+ freeBuffer(wasm, bufPtr, length);
5414
+ }
5415
+ offset += length;
5416
+ afterChunk?.();
5417
+ }
5418
+ }
5419
+
5420
+ // node_modules/@wterm/ghostty/dist/ghostty-core.js
5421
+ var DEFAULT_COLOR2 = 256;
5422
+ var GRAPHEME_BUFFER_BYTES = 256;
5423
+ var HYPERLINK_BUFFER_BYTES = 1024;
5424
+ var DEFAULT_FOREGROUND = "#d4d4d4";
5425
+ var DEFAULT_BACKGROUND = "#1e1e1e";
5426
+ var SHELL_PHASES = [
5427
+ "unknown",
5428
+ "prompt",
5429
+ "input",
5430
+ "running",
5431
+ "complete"
5432
+ ];
5433
+ var MAX_IMAGE_BYTES = 32 * 1024 * 1024;
5434
+ var DEFAULT_IMAGE_STORAGE_LIMIT = MAX_IMAGE_BYTES;
5435
+ var MAX_WASM_U32 = 4294967295;
5436
+ function packRgb(r, g, b) {
5437
+ return r << 16 | g << 8 | b;
5438
+ }
5439
+ var BLANK_CELL = {
5440
+ char: 32,
5441
+ fg: DEFAULT_COLOR2,
5442
+ bg: DEFAULT_COLOR2,
5443
+ flags: 0,
5444
+ width: 1
5445
+ };
5446
+ function parseColor(value, option) {
5447
+ if (!/^#[0-9a-f]{6}$/i.test(value)) {
5448
+ throw new Error(`@wterm/ghostty: ${option} must be a #RRGGBB color`);
5449
+ }
5450
+ return Number.parseInt(value.slice(1), 16);
5451
+ }
5452
+ function imageStorageLimit(options) {
5453
+ const value = options.imageStorageLimit ?? DEFAULT_IMAGE_STORAGE_LIMIT;
5454
+ if (!Number.isSafeInteger(value) || value < 0 || value > MAX_WASM_U32) {
5455
+ throw new Error("@wterm/ghostty: imageStorageLimit must be an integer between 0 and 4294967295");
5456
+ }
5457
+ return value;
5458
+ }
5459
+ function cloneGraphicsState(state) {
5460
+ return {
5461
+ generation: state.generation,
5462
+ images: state.images.map((image) => ({ ...image })),
5463
+ placements: state.placements.map((placement) => ({ ...placement }))
5464
+ };
5465
+ }
5466
+ var GhosttyCore = class _GhosttyCore {
5467
+ constructor(wasm, options) {
5468
+ this.termPtr = 0;
5469
+ this._themeColors = null;
5470
+ this._viewportBufPtr = 0;
5471
+ this._viewportBufSize = 0;
5472
+ this._viewportView = null;
5473
+ this._viewportStale = true;
5474
+ this._cols = 0;
5475
+ this._rows = 0;
5476
+ this._scrollbackBufPtr = 0;
5477
+ this._scrollbackBufSize = 0;
5478
+ this._scrollbackView = null;
5479
+ this._scrollbackOffset = -1;
5480
+ this._scrollbackLen = 0;
5481
+ this._graphemeBufPtr = 0;
5482
+ this._graphemeBufSize = GRAPHEME_BUFFER_BYTES;
5483
+ this._hyperlinkBufPtr = 0;
5484
+ this._hyperlinkBufSize = HYPERLINK_BUFFER_BYTES;
5485
+ this._graphicsBufPtr = 0;
5486
+ this._graphicsBufSize = 0;
5487
+ this._graphicsState = null;
5488
+ this._disposed = false;
5489
+ this._positionOwner = {};
5490
+ this.wasm = wasm;
5491
+ this._cellBytes = wasm.exports.get_viewport_v2 && wasm.exports.get_scrollback_line_v2 ? CELL_BYTES_V2 : CELL_BYTES;
5492
+ this._options = options;
5493
+ this._foregroundRgb = parseColor(options.foregroundColor ?? DEFAULT_FOREGROUND, "foregroundColor");
5494
+ this._backgroundRgb = parseColor(options.backgroundColor ?? DEFAULT_BACKGROUND, "backgroundColor");
5495
+ }
5496
+ /**
5497
+ * Load the ghostty-vt WASM binary and create a new `GhosttyCore`.
5498
+ * The returned core is ready to be passed as the `core` option to `WTerm`.
5499
+ */
5500
+ static async load(options = {}) {
5501
+ const wasm = await loadGhosttyWasm(options.wasmPath);
5502
+ return new _GhosttyCore(wasm, options);
5503
+ }
5504
+ // -- Lifecycle --
5505
+ init(cols, rows) {
5506
+ if (this._disposed)
5507
+ return;
5508
+ if (this.termPtr !== 0)
5509
+ this._deinitTerminal();
5510
+ this._cols = cols;
5511
+ this._rows = rows;
5512
+ const scrollback = this._options.scrollbackLimit ?? 1e4;
5513
+ this.termPtr = this.wasm.exports.init(cols, rows, scrollback, this._foregroundRgb, this._backgroundRgb, imageStorageLimit(this._options));
5514
+ if (this.termPtr === 0)
5515
+ return;
5516
+ if (this._themeColors)
5517
+ this.setThemeColors(this._themeColors);
5518
+ if (this._graphemeBufPtr !== 0)
5519
+ freeBuffer(this.wasm, this._graphemeBufPtr, this._graphemeBufSize);
5520
+ this._graphemeBufPtr = allocBuffer(this.wasm, GRAPHEME_BUFFER_BYTES);
5521
+ if (this._hyperlinkBufPtr !== 0) {
5522
+ freeBuffer(this.wasm, this._hyperlinkBufPtr, this._hyperlinkBufSize);
5523
+ }
5524
+ this._hyperlinkBufSize = HYPERLINK_BUFFER_BYTES;
5525
+ this._hyperlinkBufPtr = allocBuffer(this.wasm, HYPERLINK_BUFFER_BYTES);
5526
+ this._allocViewportBuffer();
5527
+ this._invalidate();
5528
+ }
5529
+ resize(cols, rows) {
5530
+ if (this._disposed || this.termPtr === 0)
5531
+ return;
5532
+ this._cols = cols;
5533
+ this._rows = rows;
5534
+ this.wasm.exports.resize(this.termPtr, cols, rows);
5535
+ this._allocViewportBuffer();
5536
+ this._invalidate();
5537
+ }
5538
+ // -- I/O --
5539
+ getColorOverrides() {
5540
+ const read2 = this.wasm.exports.get_color_override;
5541
+ const colors = {};
5542
+ if (this._disposed || this.termPtr === 0 || !read2)
5543
+ return colors;
5544
+ for (const [index, key] of ["foreground", "background", "cursor"].entries()) {
5545
+ const value = read2(this.termPtr, index);
5546
+ if (value >= 0)
5547
+ colors[key] = value;
5548
+ }
5549
+ return colors;
5550
+ }
5551
+ writeString(str, afterChunk) {
5552
+ if (this._disposed || this.termPtr === 0)
5553
+ return;
5554
+ writeString(this.wasm, this.termPtr, str, afterChunk);
5555
+ this._invalidate();
5556
+ }
5557
+ writeRaw(data, afterChunk) {
5558
+ if (this._disposed || this.termPtr === 0)
5559
+ return;
5560
+ writeBytes(this.wasm, this.termPtr, data, afterChunk);
5561
+ this._invalidate();
5562
+ }
5563
+ // -- Grid --
5564
+ trackPosition(position) {
5565
+ const { track_position, resolve_position, release_position } = this.wasm.exports;
5566
+ if (this._disposed || !this.termPtr || !track_position || !resolve_position || !release_position || !Number.isInteger(position.row) || position.row < 0 || position.row > MAX_WASM_U32 || !Number.isInteger(position.col) || position.col < 0 || position.col >= 65536)
5567
+ return null;
5568
+ const ptr = this.termPtr;
5569
+ const owner = this._positionOwner;
5570
+ const handle = track_position(ptr, position.row, position.col);
5571
+ if (!handle)
5572
+ return null;
5573
+ let disposed = false;
5574
+ const tracked = {
5575
+ resolve: () => {
5576
+ if (disposed || owner !== this._positionOwner)
5577
+ return null;
5578
+ const value = resolve_position(ptr, handle);
5579
+ if (value < 0)
5580
+ return null;
5581
+ return { row: Math.floor(value / 65536), col: value % 65536 };
5582
+ },
5583
+ dispose: () => {
5584
+ if (disposed)
5585
+ return;
5586
+ disposed = true;
5587
+ if (owner === this._positionOwner)
5588
+ release_position(ptr, handle);
5589
+ }
5590
+ };
5591
+ return tracked;
5592
+ }
5593
+ getRowMetadata(row) {
5594
+ return this._readRowMetadata(this.wasm.exports.get_row_wraps, row);
5595
+ }
5596
+ getCell(row, col) {
5597
+ if (this._disposed || this.termPtr === 0)
5598
+ return BLANK_CELL;
5599
+ this._ensureViewport();
5600
+ const view = this._viewportView;
5601
+ if (!view)
5602
+ return BLANK_CELL;
5603
+ const idx = row * this._cols + col;
5604
+ const byteOffset = idx * this._cellBytes;
5605
+ if (byteOffset + this._cellBytes > this._viewportBufSize)
5606
+ return BLANK_CELL;
5607
+ const cell = parseCell(view, byteOffset, this._cellBytes);
5608
+ if (cell.codepoint === 0 && cell.flags === 0 && cell.colorFlags === 0 && !cell.hasHyperlink && !cell.spacerHead && cell.width !== 0)
5609
+ return BLANK_CELL;
5610
+ const result = {
5611
+ char: cell.codepoint || 32,
5612
+ fg: DEFAULT_COLOR2,
5613
+ bg: DEFAULT_COLOR2,
5614
+ flags: cell.flags,
5615
+ width: cell.width
5616
+ };
5617
+ if (cell.underlineStyle !== void 0)
5618
+ result.underlineStyle = cell.underlineStyle;
5619
+ if (cell.underlineRgb !== void 0)
5620
+ result.underlineRgb = cell.underlineRgb;
5621
+ if (cell.hasGrapheme)
5622
+ result.chars = this._readGrapheme(row, col);
5623
+ if (cell.spacerHead)
5624
+ result.spacerHead = true;
5625
+ if (cell.hasHyperlink)
5626
+ Object.assign(result, this._readHyperlink(row, col, false));
5627
+ if (cell.colorFlags & 1)
5628
+ result.fgRgb = packRgb(cell.fgR, cell.fgG, cell.fgB);
5629
+ if (cell.colorFlags & 2)
5630
+ result.bgRgb = packRgb(cell.bgR, cell.bgG, cell.bgB);
5631
+ return result;
5632
+ }
5633
+ isDirtyRow(row) {
5634
+ if (this._disposed || this.termPtr === 0)
5635
+ return false;
5636
+ this._ensureViewport();
5637
+ return this.wasm.exports.is_dirty_row(this.termPtr, row) !== 0;
5638
+ }
5639
+ clearDirty() {
5640
+ if (this._disposed || this.termPtr === 0)
5641
+ return;
5642
+ this.wasm.exports.clear_dirty(this.termPtr);
5643
+ this._viewportStale = true;
5644
+ }
5645
+ getCols() {
5646
+ return this._cols;
5647
+ }
5648
+ getRows() {
5649
+ return this._rows;
5650
+ }
5651
+ // -- Cursor --
5652
+ getCursor() {
5653
+ if (this._disposed || this.termPtr === 0) {
5654
+ return { row: 0, col: 0, visible: false };
5655
+ }
5656
+ this._ensureViewport();
5657
+ const shape = this.wasm.exports.get_cursor_shape?.(this.termPtr) ?? 0;
5658
+ return {
5659
+ row: this.wasm.exports.get_cursor_row(this.termPtr),
5660
+ col: this.wasm.exports.get_cursor_col(this.termPtr),
5661
+ visible: this.wasm.exports.get_cursor_visible(this.termPtr) !== 0,
5662
+ shape: shape === 1 ? "underline" : shape === 2 ? "bar" : "block",
5663
+ blinking: (this.wasm.exports.get_cursor_blinking?.(this.termPtr) ?? 0) !== 0
5664
+ };
5665
+ }
5666
+ // -- Modes --
5667
+ cursorKeysApp() {
5668
+ if (this._disposed || this.termPtr === 0)
5669
+ return false;
5670
+ return this.wasm.exports.cursor_keys_app(this.termPtr) !== 0;
5671
+ }
5672
+ bracketedPaste() {
5673
+ if (this._disposed || this.termPtr === 0)
5674
+ return false;
5675
+ return this.wasm.exports.bracketed_paste(this.termPtr) !== 0;
5676
+ }
5677
+ usingAltScreen() {
5678
+ if (this._disposed || this.termPtr === 0)
5679
+ return false;
5680
+ return this.wasm.exports.using_alt_screen(this.termPtr) !== 0;
5681
+ }
5682
+ mouseTracking() {
5683
+ if (this._disposed || this.termPtr === 0)
5684
+ return 0;
5685
+ const mode = this.wasm.exports.mouse_tracking(this.termPtr);
5686
+ return mode === 1e3 || mode === 1002 || mode === 1003 ? mode : 0;
5687
+ }
5688
+ mouseSgr() {
5689
+ if (this._disposed || this.termPtr === 0)
5690
+ return false;
5691
+ return this.wasm.exports.mouse_sgr(this.termPtr) !== 0;
5692
+ }
5693
+ mouseEncoding() {
5694
+ if (this._disposed || this.termPtr === 0)
5695
+ return null;
5696
+ const mode = this.wasm.exports.mouse_encoding?.(this.termPtr);
5697
+ if (mode === void 0)
5698
+ return this.mouseSgr() ? "sgr" : null;
5699
+ switch (mode) {
5700
+ case 0:
5701
+ return "x10";
5702
+ case 1:
5703
+ return "utf8";
5704
+ case 2:
5705
+ return "sgr";
5706
+ case 3:
5707
+ return "urxvt";
5708
+ case 4:
5709
+ return "sgr-pixels";
5710
+ default:
5711
+ return null;
5712
+ }
5713
+ }
5714
+ focusEvents() {
5715
+ if (this._disposed || this.termPtr === 0)
5716
+ return false;
5717
+ return this.wasm.exports.focus_events(this.termPtr) !== 0;
5718
+ }
5719
+ synchronizedOutput() {
5720
+ if (this._disposed || this.termPtr === 0)
5721
+ return false;
5722
+ return this.wasm.exports.synchronized_output(this.termPtr) !== 0;
5723
+ }
5724
+ synchronizedOutputGeneration() {
5725
+ if (this._disposed || this.termPtr === 0)
5726
+ return 0;
5727
+ return this.wasm.exports.synchronized_output_generation(this.termPtr);
5728
+ }
5729
+ kittyKeyboardFlags() {
5730
+ if (this._disposed || this.termPtr === 0)
5731
+ return 0;
5732
+ return this.wasm.exports.kitty_keyboard_flags?.(this.termPtr) ?? 0;
5733
+ }
5734
+ getGraphicsState() {
5735
+ if (this._disposed || this.termPtr === 0)
5736
+ return null;
5737
+ const generation = this.wasm.exports.graphics_generation?.(this.termPtr);
5738
+ const imageCount = this.wasm.exports.graphics_image_count?.(this.termPtr) ?? 0;
5739
+ const placementCount = this.wasm.exports.graphics_placement_count?.(this.termPtr) ?? 0;
5740
+ if (generation === void 0 || !Number.isSafeInteger(generation))
5741
+ return null;
5742
+ if (!Number.isSafeInteger(imageCount) || !Number.isSafeInteger(placementCount) || imageCount < 0 || placementCount < 0)
5743
+ return null;
5744
+ if (imageCount > 16384 || placementCount > 16384)
5745
+ return null;
5746
+ const imageCapacity = imageCount;
5747
+ const placementCapacity = placementCount;
5748
+ if (!Number.isSafeInteger(imageCapacity) || !Number.isSafeInteger(placementCapacity))
5749
+ return null;
5750
+ const size = imageCapacity * GRAPHICS_IMAGE_BYTES + placementCapacity * GRAPHICS_PLACEMENT_BYTES;
5751
+ if (!Number.isSafeInteger(size))
5752
+ return null;
5753
+ if (size === 0) {
5754
+ if (this._graphicsBufPtr !== 0)
5755
+ freeBuffer(this.wasm, this._graphicsBufPtr, this._graphicsBufSize);
5756
+ this._graphicsBufPtr = 0;
5757
+ this._graphicsBufSize = 0;
5758
+ const result = {
5759
+ generation,
5760
+ images: [],
5761
+ placements: []
5762
+ };
5763
+ this._graphicsState = result;
5764
+ return cloneGraphicsState(result);
5765
+ }
5766
+ if (size !== this._graphicsBufSize || this._graphicsBufPtr === 0) {
5767
+ if (this._graphicsBufPtr !== 0)
5768
+ freeBuffer(this.wasm, this._graphicsBufPtr, this._graphicsBufSize);
5769
+ this._graphicsBufSize = size;
5770
+ this._graphicsBufPtr = allocBuffer(this.wasm, size);
5771
+ }
5772
+ if (this._graphicsBufPtr === 0)
5773
+ return null;
5774
+ try {
5775
+ const images = readGraphicsImages(this.wasm, this.termPtr, this._graphicsBufPtr, imageCapacity);
5776
+ const placements = readGraphicsPlacements(this.wasm, this.termPtr, this._graphicsBufPtr + imageCapacity * GRAPHICS_IMAGE_BYTES, placementCapacity);
5777
+ const result = {
5778
+ generation,
5779
+ images: images.map((image) => ({ ...image })),
5780
+ placements: placements.map((placement) => ({ ...placement }))
5781
+ };
5782
+ this._graphicsState = result;
5783
+ return cloneGraphicsState(result);
5784
+ } catch {
5785
+ return null;
5786
+ }
5787
+ }
5788
+ getGraphicsImage(imageId, version) {
5789
+ if (this._disposed || this.termPtr === 0)
5790
+ return null;
5791
+ const state = this._graphicsState ?? this.getGraphicsState();
5792
+ const image = state?.images.find((value) => value.imageId === imageId && value.version === version);
5793
+ if (!image || !this.wasm.exports.graphics_image_size || !this.wasm.exports.graphics_image_copy)
5794
+ return null;
5795
+ let size;
5796
+ try {
5797
+ size = this.wasm.exports.graphics_image_size(this.termPtr, imageId, version);
5798
+ } catch {
5799
+ return null;
5800
+ }
5801
+ const expectedSize = image.width * image.height * 4;
5802
+ if (!Number.isSafeInteger(size) || size <= 0 || !Number.isSafeInteger(expectedSize) || size !== expectedSize)
5803
+ return null;
5804
+ const ptr = allocBuffer(this.wasm, size);
5805
+ if (ptr === 0)
5806
+ return null;
5807
+ try {
5808
+ const copied = this.wasm.exports.graphics_image_copy(this.termPtr, imageId, version, ptr, size);
5809
+ if (copied !== size)
5810
+ return null;
5811
+ const rgba = new Uint8Array(this.wasm.exports.memory.buffer, ptr, copied).slice();
5812
+ return {
5813
+ imageId,
5814
+ version,
5815
+ width: image.width,
5816
+ height: image.height,
5817
+ rgba
5818
+ };
5819
+ } catch {
5820
+ return null;
5821
+ } finally {
5822
+ freeBuffer(this.wasm, ptr, size);
5823
+ }
5824
+ }
5825
+ getResourceState() {
5826
+ const limit = imageStorageLimit(this._options);
5827
+ if (this._disposed || !this.termPtr || !this.wasm.exports.graphics_image_count)
5828
+ return {};
5829
+ const state = this.getGraphicsState();
5830
+ const used = this.wasm.exports.graphics_bytes_used?.(this.termPtr) ?? 0;
5831
+ const capacity = this.wasm.exports.graphics_capacity?.(this.termPtr) ?? limit;
5832
+ const rejected = this.wasm.exports.graphics_rejected?.(this.termPtr) ?? 0;
5833
+ const evicted = this.wasm.exports.graphics_evicted?.(this.termPtr) ?? 0;
5834
+ return {
5835
+ graphics: {
5836
+ capacity: Number.isSafeInteger(capacity) ? capacity : limit,
5837
+ used: Number.isSafeInteger(used) ? used : 0,
5838
+ imageCount: state?.images.length ?? 0,
5839
+ placementCount: state?.placements.length ?? 0,
5840
+ rejected: Number.isSafeInteger(rejected) ? rejected : 0,
5841
+ evicted: Number.isSafeInteger(evicted) ? evicted : 0,
5842
+ saturated: limit > 0 && used >= limit
5843
+ }
5844
+ };
5845
+ }
5846
+ dispose() {
5847
+ if (this._disposed)
5848
+ return;
5849
+ this._disposed = true;
5850
+ this._deinitTerminal();
5851
+ this._cols = 0;
5852
+ this._rows = 0;
5853
+ }
5854
+ _deinitTerminal() {
5855
+ this._positionOwner = {};
5856
+ if (this.termPtr !== 0) {
5857
+ try {
5858
+ this.wasm.exports.deinit(this.termPtr);
5859
+ } catch {
5860
+ }
5861
+ }
5862
+ this.termPtr = 0;
5863
+ for (const [ptr, size] of [
5864
+ [this._viewportBufPtr, this._viewportBufSize],
5865
+ [this._scrollbackBufPtr, this._scrollbackBufSize],
5866
+ [this._graphemeBufPtr, this._graphemeBufSize],
5867
+ [this._hyperlinkBufPtr, this._hyperlinkBufSize],
5868
+ [this._graphicsBufPtr, this._graphicsBufSize]
5869
+ ])
5870
+ if (ptr !== 0)
5871
+ freeBuffer(this.wasm, ptr, size);
5872
+ this._viewportBufPtr = this._scrollbackBufPtr = this._graphemeBufPtr = this._hyperlinkBufPtr = this._graphicsBufPtr = 0;
5873
+ this._viewportBufSize = this._scrollbackBufSize = this._graphicsBufSize = 0;
5874
+ this._viewportView = this._scrollbackView = null;
5875
+ this._scrollbackOffset = -1;
5876
+ this._scrollbackLen = 0;
5877
+ this._viewportStale = true;
5878
+ this._graphicsState = null;
5879
+ }
5880
+ // -- Side outputs --
5881
+ getTitle() {
5882
+ if (this._disposed || this.termPtr === 0)
5883
+ return null;
5884
+ const { get_title_len, get_title_ptr, memory } = this.wasm.exports;
5885
+ if (!get_title_len || !get_title_ptr)
5886
+ return null;
5887
+ const len = get_title_len(this.termPtr);
5888
+ if (len < 0)
5889
+ return null;
5890
+ return new TextDecoder().decode(new Uint8Array(memory.buffer, get_title_ptr(this.termPtr), len));
5891
+ }
5892
+ getBellCount() {
5893
+ if (this._disposed || this.termPtr === 0)
5894
+ return 0;
5895
+ return this.wasm.exports.get_bell_count?.(this.termPtr) ?? 0;
5896
+ }
5897
+ getWorkingDirectory() {
5898
+ if (this._disposed || this.termPtr === 0)
5899
+ return null;
5900
+ const { get_working_directory_len, get_working_directory_ptr, memory } = this.wasm.exports;
5901
+ if (!get_working_directory_len || !get_working_directory_ptr)
5902
+ return null;
5903
+ const len = get_working_directory_len(this.termPtr);
5904
+ if (!Number.isInteger(len) || len < 0 || len > 2047)
5905
+ return null;
5906
+ return new TextDecoder("utf-8", { ignoreBOM: true }).decode(new Uint8Array(memory.buffer, get_working_directory_ptr(this.termPtr), len));
5907
+ }
5908
+ getClipboardWrite() {
5909
+ if (this._disposed || this.termPtr === 0)
5910
+ return null;
5911
+ const { get_clipboard_write_len, get_clipboard_write_ptr, memory } = this.wasm.exports;
5912
+ if (!get_clipboard_write_len || !get_clipboard_write_ptr)
5913
+ return null;
5914
+ const len = get_clipboard_write_len(this.termPtr);
5915
+ if (len < 0)
5916
+ return null;
5917
+ return new TextDecoder("utf-8", { ignoreBOM: true }).decode(new Uint8Array(memory.buffer, get_clipboard_write_ptr(this.termPtr), len));
5918
+ }
5919
+ findPrompt(row, direction) {
5920
+ const find = this.wasm.exports.find_prompt;
5921
+ if (this._disposed || this.termPtr === 0 || !find || !Number.isInteger(row) || row < 0 || row > MAX_WASM_U32 || direction !== -1 && direction !== 1)
5922
+ return null;
5923
+ const result = find(this.termPtr, row, direction);
5924
+ return Number.isInteger(result) && result >= 0 ? result : null;
5925
+ }
5926
+ getShellIntegrationState() {
5927
+ if (this._disposed || this.termPtr === 0)
5928
+ return null;
5929
+ const { get_shell_phase, get_shell_exit_code } = this.wasm.exports;
5930
+ if (!get_shell_phase || !get_shell_exit_code)
5931
+ return null;
5932
+ const phase = get_shell_phase(this.termPtr);
5933
+ if (!Number.isInteger(phase) || phase < 0 || phase >= SHELL_PHASES.length)
5934
+ return null;
5935
+ const exitCode = get_shell_exit_code(this.termPtr);
5936
+ return {
5937
+ phase: SHELL_PHASES[phase],
5938
+ exitCode: Number.isInteger(exitCode) ? exitCode : null
5939
+ };
5940
+ }
5941
+ getResponse() {
5942
+ if (this._disposed || this.termPtr === 0)
5943
+ return null;
5944
+ const bufSize = 4096;
5945
+ const bufPtr = allocBuffer(this.wasm, bufSize);
5946
+ if (bufPtr === 0)
5947
+ return null;
5948
+ const len = this.wasm.exports.read_response(this.termPtr, bufPtr, bufSize);
5949
+ if (len === 0) {
5950
+ freeBuffer(this.wasm, bufPtr, bufSize);
5951
+ return null;
5952
+ }
5953
+ const bytes = new Uint8Array(this.wasm.exports.memory.buffer, bufPtr, len);
5954
+ const text = new TextDecoder().decode(bytes);
5955
+ freeBuffer(this.wasm, bufPtr, bufSize);
5956
+ return text;
5957
+ }
5958
+ // -- Scrollback --
5959
+ getScrollbackCount() {
5960
+ if (this._disposed || this.termPtr === 0)
5961
+ return 0;
5962
+ return this.wasm.exports.get_scrollback_count(this.termPtr);
5963
+ }
5964
+ getScrollbackDiscardedCount() {
5965
+ if (this._disposed || this.termPtr === 0)
5966
+ return 0;
5967
+ return this.wasm.exports.get_scrollback_discarded_count(this.termPtr);
5968
+ }
5969
+ getScrollbackCell(offset, col) {
5970
+ if (this._disposed || this.termPtr === 0)
5971
+ return BLANK_CELL;
5972
+ const len = this._ensureScrollbackLine(offset);
5973
+ const view = this._scrollbackView;
5974
+ if (!view || col >= len)
5975
+ return BLANK_CELL;
5976
+ const cell = parseCell(view, col * this._cellBytes, this._cellBytes);
5977
+ const result = {
5978
+ char: cell.codepoint || 32,
5979
+ fg: DEFAULT_COLOR2,
5980
+ bg: DEFAULT_COLOR2,
5981
+ flags: cell.flags,
5982
+ width: cell.width
5983
+ };
5984
+ if (cell.underlineStyle !== void 0)
5985
+ result.underlineStyle = cell.underlineStyle;
5986
+ if (cell.underlineRgb !== void 0)
5987
+ result.underlineRgb = cell.underlineRgb;
5988
+ if (cell.hasGrapheme)
5989
+ result.chars = this._readScrollbackGrapheme(offset, col);
5990
+ if (cell.spacerHead)
5991
+ result.spacerHead = true;
5992
+ if (cell.hasHyperlink)
5993
+ Object.assign(result, this._readHyperlink(offset, col, true));
5994
+ if (cell.colorFlags & 1)
5995
+ result.fgRgb = packRgb(cell.fgR, cell.fgG, cell.fgB);
5996
+ if (cell.colorFlags & 2)
5997
+ result.bgRgb = packRgb(cell.bgR, cell.bgG, cell.bgB);
5998
+ return result;
5999
+ }
6000
+ getScrollbackLineLen(offset) {
6001
+ if (this._disposed || this.termPtr === 0)
6002
+ return 0;
6003
+ return this._ensureScrollbackLine(offset);
6004
+ }
6005
+ getScrollbackRowMetadata(offset) {
6006
+ return this._readRowMetadata(this.wasm.exports.get_scrollback_row_wraps, offset);
6007
+ }
6008
+ // -- Debug --
6009
+ getUnhandledSequences() {
6010
+ return [];
6011
+ }
6012
+ // -- Internal helpers --
6013
+ _readRowMetadata(read2, index) {
6014
+ if (this._disposed || this.termPtr === 0 || !read2 || !Number.isInteger(index) || index < 0 || index > MAX_WASM_U32)
6015
+ return null;
6016
+ const flags = read2(this.termPtr, index);
6017
+ if (flags < 0)
6018
+ return null;
6019
+ return {
6020
+ wrapsToNext: (flags & 1) !== 0,
6021
+ continuesPrevious: (flags & 2) !== 0
6022
+ };
6023
+ }
6024
+ /** Update host defaults while preserving application overrides and parser state. */
6025
+ setThemeColors(colors) {
6026
+ const values = [
6027
+ colors.foreground,
6028
+ colors.background,
6029
+ colors.cursor,
6030
+ ...colors.palette
6031
+ ];
6032
+ if (colors.palette.length !== 16 || values.some((value) => !Number.isInteger(value) || value < 0 || value > 16777215))
6033
+ throw new RangeError("Theme colors must be 24-bit RGB values with exactly 16 palette entries");
6034
+ if (this._disposed)
6035
+ return;
6036
+ this._themeColors = { ...colors, palette: [...colors.palette] };
6037
+ this._foregroundRgb = colors.foreground;
6038
+ this._backgroundRgb = colors.background;
6039
+ const apply = this.wasm.exports.set_theme_colors;
6040
+ if (!this.termPtr || !apply)
6041
+ return;
6042
+ const bytes = values.length * 4;
6043
+ const ptr = allocBuffer(this.wasm, bytes);
6044
+ try {
6045
+ const view = new DataView(this.wasm.exports.memory.buffer, ptr, bytes);
6046
+ values.forEach((value, index) => view.setUint32(index * 4, value, true));
6047
+ apply(this.termPtr, ptr);
6048
+ this._invalidate();
6049
+ } finally {
6050
+ freeBuffer(this.wasm, ptr, bytes);
6051
+ }
6052
+ }
6053
+ _invalidate() {
6054
+ this._viewportStale = true;
6055
+ this._scrollbackOffset = -1;
6056
+ this._graphicsState = null;
6057
+ }
6058
+ _decodeGrapheme(len) {
6059
+ if (len === 0 || this._graphemeBufPtr === 0)
6060
+ return void 0;
6061
+ return new TextDecoder().decode(new Uint8Array(this.wasm.exports.memory.buffer, this._graphemeBufPtr, len));
6062
+ }
6063
+ _ensureGraphemeBuffer(required) {
6064
+ if (required <= this._graphemeBufSize)
6065
+ return;
6066
+ if (this._graphemeBufPtr !== 0) {
6067
+ freeBuffer(this.wasm, this._graphemeBufPtr, this._graphemeBufSize);
6068
+ }
6069
+ this._graphemeBufSize = required;
6070
+ this._graphemeBufPtr = allocBuffer(this.wasm, required);
6071
+ }
6072
+ _ensureHyperlinkBuffer(required) {
6073
+ if (required <= this._hyperlinkBufSize)
6074
+ return;
6075
+ if (this._hyperlinkBufPtr !== 0) {
6076
+ freeBuffer(this.wasm, this._hyperlinkBufPtr, this._hyperlinkBufSize);
6077
+ }
6078
+ this._hyperlinkBufSize = required;
6079
+ this._hyperlinkBufPtr = allocBuffer(this.wasm, required);
6080
+ }
6081
+ _readHyperlink(rowOrOffset, col, scrollback) {
6082
+ if (this._hyperlinkBufPtr === 0)
6083
+ return void 0;
6084
+ const read2 = scrollback ? this.wasm.exports.get_scrollback_hyperlink : this.wasm.exports.get_viewport_hyperlink;
6085
+ let len = read2(this.termPtr, rowOrOffset, col, this._hyperlinkBufPtr, this._hyperlinkBufSize);
6086
+ if (len > this._hyperlinkBufSize) {
6087
+ this._ensureHyperlinkBuffer(len);
6088
+ if (this._hyperlinkBufPtr === 0)
6089
+ return void 0;
6090
+ len = read2(this.termPtr, rowOrOffset, col, this._hyperlinkBufPtr, this._hyperlinkBufSize);
6091
+ }
6092
+ if (len === 0 || len > this._hyperlinkBufSize)
6093
+ return void 0;
6094
+ const text = new TextDecoder().decode(new Uint8Array(this.wasm.exports.memory.buffer, this._hyperlinkBufPtr, len));
6095
+ const [linkUri, linkId = "", implicitId = ""] = text.split("\0");
6096
+ if (!linkUri)
6097
+ return void 0;
6098
+ const linkKey = linkId ? `e\0${linkId}\0${linkUri}` : `g\0${implicitId}\0${linkUri}`;
6099
+ return {
6100
+ linkUri,
6101
+ linkId: linkId || void 0,
6102
+ linkKey
6103
+ };
6104
+ }
6105
+ _readGrapheme(row, col) {
6106
+ if (this._graphemeBufPtr === 0 || !this.wasm.exports.get_viewport_grapheme)
6107
+ return void 0;
6108
+ let len = this.wasm.exports.get_viewport_grapheme(this.termPtr, row, col, this._graphemeBufPtr, this._graphemeBufSize);
6109
+ if (len > this._graphemeBufSize) {
6110
+ this._ensureGraphemeBuffer(len);
6111
+ len = this.wasm.exports.get_viewport_grapheme(this.termPtr, row, col, this._graphemeBufPtr, this._graphemeBufSize);
6112
+ }
6113
+ return this._decodeGrapheme(len);
6114
+ }
6115
+ _readScrollbackGrapheme(offset, col) {
6116
+ if (this._graphemeBufPtr === 0 || !this.wasm.exports.get_scrollback_grapheme)
6117
+ return void 0;
6118
+ let len = this.wasm.exports.get_scrollback_grapheme(this.termPtr, offset, col, this._graphemeBufPtr, this._graphemeBufSize);
6119
+ if (len > this._graphemeBufSize) {
6120
+ this._ensureGraphemeBuffer(len);
6121
+ len = this.wasm.exports.get_scrollback_grapheme(this.termPtr, offset, col, this._graphemeBufPtr, this._graphemeBufSize);
6122
+ }
6123
+ return this._decodeGrapheme(len);
6124
+ }
6125
+ _allocViewportBuffer() {
6126
+ if (this._viewportBufPtr !== 0) {
6127
+ freeBuffer(this.wasm, this._viewportBufPtr, this._viewportBufSize);
6128
+ }
6129
+ this._viewportBufSize = this._cols * this._rows * this._cellBytes;
6130
+ this._viewportBufPtr = allocBuffer(this.wasm, this._viewportBufSize);
6131
+ this._viewportView = null;
6132
+ this._viewportStale = true;
6133
+ if (this._scrollbackBufPtr !== 0) {
6134
+ freeBuffer(this.wasm, this._scrollbackBufPtr, this._scrollbackBufSize);
6135
+ }
6136
+ this._scrollbackBufSize = this._cols * this._cellBytes;
6137
+ this._scrollbackBufPtr = allocBuffer(this.wasm, this._scrollbackBufSize);
6138
+ this._scrollbackView = null;
6139
+ this._scrollbackOffset = -1;
6140
+ }
6141
+ /**
6142
+ * Decode one scrollback row into the shared buffer, at most once per row
6143
+ * per invalidation, and return its length. The renderer reads a row column
6144
+ * by column, so without this each cell would cost a page-list walk.
6145
+ */
6146
+ _ensureScrollbackLine(offset) {
6147
+ if (this._scrollbackBufPtr === 0)
6148
+ return 0;
6149
+ if (this._scrollbackOffset !== offset) {
6150
+ const read2 = this._cellBytes === CELL_BYTES_V2 ? this.wasm.exports.get_scrollback_line_v2 : this.wasm.exports.get_scrollback_line;
6151
+ this._scrollbackLen = read2(this.termPtr, offset, this._scrollbackBufPtr, this._cols);
6152
+ this._scrollbackOffset = offset;
6153
+ }
6154
+ if (this._scrollbackView?.buffer !== this.wasm.exports.memory.buffer) {
6155
+ this._scrollbackView = new DataView(this.wasm.exports.memory.buffer, this._scrollbackBufPtr, this._scrollbackBufSize);
6156
+ }
6157
+ return this._scrollbackLen;
6158
+ }
6159
+ _ensureViewport() {
6160
+ if (this._viewportStale) {
6161
+ this.wasm.exports.update(this.termPtr);
6162
+ const read2 = this._cellBytes === CELL_BYTES_V2 ? this.wasm.exports.get_viewport_v2 : this.wasm.exports.get_viewport;
6163
+ read2(this.termPtr, this._viewportBufPtr);
6164
+ this._viewportStale = false;
6165
+ }
6166
+ if (this._viewportView?.buffer !== this.wasm.exports.memory.buffer) {
6167
+ this._viewportView = new DataView(this.wasm.exports.memory.buffer, this._viewportBufPtr, this._viewportBufSize);
6168
+ }
6169
+ }
6170
+ };
6171
+
6172
+ // src/ghostty.ts
6173
+ var base = 5360640;
6174
+ var replies = /\x1b\]1[01];rgb:[0-9a-f/]+(?:\x07|\x1b\\)/gi;
6175
+ var slot = (rgb) => rgb !== void 0 && rgb >>> 4 === base >>> 4 ? rgb & 15 : void 0;
6176
+ function indexed(cell) {
6177
+ const fg = slot(cell.fgRgb);
6178
+ const bg = slot(cell.bgRgb);
6179
+ if (fg !== void 0) {
6180
+ cell.fg = fg;
6181
+ delete cell.fgRgb;
6182
+ }
6183
+ if (bg !== void 0) {
6184
+ cell.bg = bg;
6185
+ delete cell.bgRgb;
6186
+ }
6187
+ return cell;
6188
+ }
6189
+ async function loadCore(wasmPath) {
6190
+ const core = await GhosttyCore.load({ wasmPath, scrollbackLimit: 4e6 });
6191
+ core.setThemeColors({
6192
+ foreground: 13948116,
6193
+ background: 1907997,
6194
+ cursor: 11448237,
6195
+ palette: Array.from({ length: 16 }, (_, index) => base + index)
6196
+ });
6197
+ const cell = core.getCell.bind(core);
6198
+ const history = core.getScrollbackCell.bind(core);
6199
+ const response = core.getResponse.bind(core);
6200
+ core.getCell = (row, col) => indexed(cell(row, col));
6201
+ core.getScrollbackCell = (offset, col) => indexed(history(offset, col));
6202
+ core.getResponse = () => {
6203
+ for (let reply = response(); reply !== null; reply = response()) {
6204
+ const kept = reply.replace(replies, "");
6205
+ if (kept) return kept;
6206
+ }
6207
+ return null;
6208
+ };
6209
+ return core;
6210
+ }
6211
+
5196
6212
  // node_modules/@wterm/dom/src/terminal.css
5197
6213
  var terminal_default = '.wterm {\n /* Application overrides are owned by the renderer; each terminal is isolated. */\n --term-app-fg: initial;\n --term-app-bg: initial;\n --term-app-cursor: initial;\n\n --term-fg: #d4d4d4;\n --term-bg: #1e1e1e;\n --term-cursor: #aeafad;\n\n --term-color-0: #1e1e1e;\n --term-color-1: #f44747;\n --term-color-2: #6a9955;\n --term-color-3: #d7ba7d;\n --term-color-4: #569cd6;\n --term-color-5: #c586c0;\n --term-color-6: #4ec9b0;\n --term-color-7: #d4d4d4;\n --term-color-8: #808080;\n --term-color-9: #f44747;\n --term-color-10: #6a9955;\n --term-color-11: #d7ba7d;\n --term-color-12: #569cd6;\n --term-color-13: #c586c0;\n --term-color-14: #4ec9b0;\n --term-color-15: #ffffff;\n\n --term-font-family:\n "Menlo", "Consolas", "DejaVu Sans Mono", "Courier New", monospace;\n --term-font-size: 14px;\n --term-line-height: 1.2;\n --term-row-height: 17px;\n\n position: relative;\n background: var(--term-app-bg, var(--term-bg));\n color: var(--term-app-fg, var(--term-fg));\n font-family: var(--term-font-family);\n font-size: var(--term-font-size);\n font-kerning: none;\n font-variant-ligatures: none;\n line-height: var(--term-line-height);\n padding: 12px;\n border-radius: 8px;\n box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);\n outline: none;\n overflow: hidden;\n overflow-anchor: none;\n}\n\n.wterm:focus,\n.wterm:focus-visible {\n outline: none;\n}\n\n.term-grid {\n display: block;\n position: relative;\n white-space: pre;\n contain: layout paint style;\n will-change: contents;\n}\n\n.term-announcements {\n position: absolute;\n left: 0;\n top: 0;\n width: 1px;\n height: 1px;\n padding: 0;\n margin: -1px;\n overflow: hidden;\n clip-path: inset(50%);\n white-space: pre;\n pointer-events: none;\n user-select: none;\n}\n\n.term-images {\n position: absolute;\n inset: 0;\n pointer-events: none;\n overflow: visible;\n z-index: 1;\n}\n\n.term-search-layer {\n position: absolute;\n inset: 0;\n pointer-events: none;\n user-select: none;\n z-index: 2;\n}\n\n.term-search-match {\n position: absolute;\n background: var(--term-search-match, rgb(255 200 0 / 25%));\n}\n\n.term-search-active {\n background: var(--term-search-active, rgb(255 150 0 / 40%));\n box-shadow: inset 0 0 0 1px var(--term-search-border, #ffb000);\n}\n\n.term-image-flow-spacer {\n display: block;\n height: 0;\n pointer-events: none;\n}\n\n.term-image {\n position: absolute;\n display: block;\n pointer-events: none;\n user-select: none;\n}\n\n.term-row {\n display: block;\n height: var(--term-row-height);\n line-height: var(--term-row-height);\n contain: layout style;\n}\n\n.term-select-all .term-row,\n.term-rectangle-row {\n position: relative;\n}\n\n.term-select-all .term-row::after,\n.term-rectangle-row::after {\n content: "";\n position: absolute;\n inset: 0;\n background: var(--term-selection-bg, rgb(80 140 255 / 30%));\n pointer-events: none;\n user-select: none;\n z-index: 3;\n}\n\n.term-rectangle-row::after {\n left: var(--term-selection-left);\n width: var(--term-selection-width);\n right: auto;\n}\n\n.term-selection-status {\n position: sticky;\n bottom: 0;\n width: fit-content;\n max-width: 100%;\n white-space: normal;\n background: var(--term-app-bg, var(--term-bg));\n color: var(--term-app-fg, var(--term-fg));\n user-select: none;\n pointer-events: none;\n z-index: 4;\n}\n\n.term-selection-status:empty {\n display: none;\n}\n\n.term-scrollback-spacer {\n display: block;\n pointer-events: none;\n}\n\n.term-size-probe {\n position: absolute;\n top: 0;\n left: 0;\n visibility: hidden;\n pointer-events: none;\n white-space: pre;\n width: auto;\n height: var(--term-row-height);\n}\n\n.term-row > span,\n.term-row > .term-link,\n.term-link > span {\n display: inline-block;\n height: var(--term-row-height);\n vertical-align: top;\n}\n\n.term-row > span,\n.term-link > span {\n width: calc(var(--term-span-cols, 1) * var(--term-cell-width, 1ch));\n /* Glyph ink may overhang its advance without moving the following cell. */\n overflow: visible;\n}\n\n.term-link {\n color: inherit;\n cursor: text;\n}\n\n.wterm.link-modifier-active .term-link:hover,\n.term-link:focus-visible {\n cursor: pointer;\n}\n\n.wterm.link-modifier-active .term-link:hover > span,\n.term-link:focus-visible > span {\n text-decoration: underline;\n text-underline-offset: 0.15em;\n}\n\n.term-block {\n width: var(--term-cell-width, 1ch);\n overflow: hidden;\n -webkit-text-fill-color: transparent;\n}\n\n.term-box {\n --term-box-stroke: max(\n 1px,\n round(calc(var(--term-cell-width, 1ch) * 0.18), 1px)\n );\n -webkit-text-fill-color: transparent;\n}\n\n.term-box-heavy,\n.term-box-bold {\n --term-box-stroke: max(\n 2px,\n round(calc(var(--term-cell-width, 1ch) * 0.3), 1px)\n );\n}\n\n.term-box-round {\n position: relative;\n}\n\n.term-box-round::after {\n content: "";\n position: absolute;\n box-sizing: border-box;\n border: 0 solid currentColor;\n pointer-events: none;\n}\n\n.term-box-round-tl::after {\n inset: calc(50% - var(--term-box-stroke) * 0.5) 0 0\n calc(50% - var(--term-box-stroke) * 0.5);\n border-top-width: var(--term-box-stroke);\n border-left-width: var(--term-box-stroke);\n border-top-left-radius: 100%;\n}\n\n.term-box-round-tr::after {\n inset: calc(50% - var(--term-box-stroke) * 0.5)\n calc(50% - var(--term-box-stroke) * 0.5) 0 0;\n border-top-width: var(--term-box-stroke);\n border-right-width: var(--term-box-stroke);\n border-top-right-radius: 100%;\n}\n\n.term-box-round-br::after {\n inset: 0 calc(50% - var(--term-box-stroke) * 0.5)\n calc(50% - var(--term-box-stroke) * 0.5) 0;\n border-bottom-width: var(--term-box-stroke);\n border-right-width: var(--term-box-stroke);\n border-bottom-right-radius: 100%;\n}\n\n.term-box-round-bl::after {\n inset: 0 0 calc(50% - var(--term-box-stroke) * 0.5)\n calc(50% - var(--term-box-stroke) * 0.5);\n border-bottom-width: var(--term-box-stroke);\n border-left-width: var(--term-box-stroke);\n border-bottom-left-radius: 100%;\n}\n\n@media (forced-colors: active), print {\n .term-block {\n background: none !important;\n -webkit-text-fill-color: currentColor;\n }\n\n .term-box {\n background-image: none !important;\n -webkit-text-fill-color: currentColor;\n }\n\n .term-box-round::after {\n display: none;\n }\n}\n\n.term-wide {\n --term-span-cols: 2;\n overflow: visible;\n}\n\n.term-cursor {\n color: var(--term-cell-fg, inherit);\n background: var(--term-cell-bg, transparent);\n outline: 1px solid var(--term-app-cursor, var(--term-cursor));\n outline-offset: -1px;\n}\n\n/* Native text selection can blur the input until click-to-focus runs. Keep\n the cursor active during that press without cancelling the selection. */\n.wterm:is(.focused, :active) .term-cursor {\n background: var(--term-app-cursor, var(--term-cursor));\n color: var(--term-app-bg, var(--term-bg));\n outline: none;\n}\n\n.wterm:is(.focused, :active) .term-grid[data-cursor-shape="bar"] .term-cursor,\n.wterm:is(.focused, :active) .term-grid[data-cursor-shape="underline"] .term-cursor {\n background: var(--term-cell-bg, transparent);\n color: var(--term-cell-fg, inherit);\n box-shadow: var(--term-cursor-shadow);\n --term-cursor-animation: cursor-line-blink;\n}\n\n.term-grid[data-cursor-shape="bar"] .term-cursor {\n --term-cursor-shadow: inset 2px 0 0 var(--term-app-cursor, var(--term-cursor));\n}\n\n.term-grid[data-cursor-shape="underline"] .term-cursor {\n --term-cursor-shadow: inset 0 -2px 0\n var(--term-app-cursor, var(--term-cursor));\n}\n\n.wterm:is(.focused, :active).cursor-blink .term-cursor,\n.wterm:is(.focused, :active):not(.cursor-steady)\n .term-grid[data-cursor-blink="true"]\n .term-cursor {\n animation: var(--term-cursor-animation, cursor-blink) 1s step-end infinite;\n}\n\n@keyframes cursor-blink {\n 0%,\n 100% {\n background: var(--term-app-cursor, var(--term-cursor));\n color: var(--term-app-bg, var(--term-bg));\n }\n 50% {\n background: var(--term-cell-bg, transparent);\n color: var(--term-cell-fg, inherit);\n }\n}\n\n@keyframes cursor-line-blink {\n 0%,\n 100% {\n box-shadow: var(--term-cursor-shadow);\n }\n 50% {\n box-shadow: none;\n }\n}\n\n.wterm.has-scrollback,\n.wterm.has-image-flow {\n overflow-y: auto;\n}\n\n.wterm ::selection {\n background: rgba(86, 156, 214, 0.3);\n}\n\n/* Solarized Dark */\n.wterm.theme-solarized-dark {\n --term-fg: #839496;\n --term-bg: #002b36;\n --term-cursor: #93a1a1;\n --term-color-0: #073642;\n --term-color-1: #dc322f;\n --term-color-2: #859900;\n --term-color-3: #b58900;\n --term-color-4: #268bd2;\n --term-color-5: #d33682;\n --term-color-6: #2aa198;\n --term-color-7: #eee8d5;\n --term-color-8: #586e75;\n --term-color-9: #cb4b16;\n --term-color-10: #586e75;\n --term-color-11: #657b83;\n --term-color-12: #839496;\n --term-color-13: #6c71c4;\n --term-color-14: #93a1a1;\n --term-color-15: #fdf6e3;\n}\n\n/* Monokai */\n.wterm.theme-monokai {\n --term-fg: #f8f8f2;\n --term-bg: #272822;\n --term-cursor: #f8f8f0;\n --term-color-0: #272822;\n --term-color-1: #f92672;\n --term-color-2: #a6e22e;\n --term-color-3: #f4bf75;\n --term-color-4: #66d9ef;\n --term-color-5: #ae81ff;\n --term-color-6: #a1efe4;\n --term-color-7: #f8f8f2;\n --term-color-8: #75715e;\n --term-color-9: #f92672;\n --term-color-10: #a6e22e;\n --term-color-11: #f4bf75;\n --term-color-12: #66d9ef;\n --term-color-13: #ae81ff;\n --term-color-14: #a1efe4;\n --term-color-15: #f9f8f5;\n}\n\n/* Light */\n.wterm.theme-light {\n --term-fg: #383a42;\n --term-bg: #fafafa;\n --term-cursor: #526eff;\n --term-color-0: #383a42;\n --term-color-1: #e45649;\n --term-color-2: #50a14f;\n --term-color-3: #c18401;\n --term-color-4: #4078f2;\n --term-color-5: #a626a4;\n --term-color-6: #0184bc;\n --term-color-7: #fafafa;\n --term-color-8: #a0a1a7;\n --term-color-9: #e45649;\n --term-color-10: #50a14f;\n --term-color-11: #c18401;\n --term-color-12: #4078f2;\n --term-color-13: #a626a4;\n --term-color-14: #0184bc;\n --term-color-15: #ffffff;\n}\n';
5198
6214
 
@@ -5226,9 +6242,10 @@ function dimension(value) {
5226
6242
  }
5227
6243
  var SliccTerminal = class _SliccTerminal extends HTMLElement {
5228
6244
  static observedAttributes = ["cols", "rows"];
5229
- static wasmUrl = new URL("./wterm.wasm", import.meta.url).href;
6245
+ static wasmUrl = new URL("./ghostty-vt.wasm", import.meta.url).href;
5230
6246
  #backend = null;
5231
6247
  #term = null;
6248
+ #core = null;
5232
6249
  #session = null;
5233
6250
  #queue = null;
5234
6251
  #generation = 0;
@@ -5275,6 +6292,8 @@ var SliccTerminal = class _SliccTerminal extends HTMLElement {
5275
6292
  this.#close();
5276
6293
  this.#term?.destroy();
5277
6294
  this.#term = null;
6295
+ this.#core?.dispose();
6296
+ this.#core = null;
5278
6297
  this.replaceChildren();
5279
6298
  this.#renew();
5280
6299
  }
@@ -5330,24 +6349,31 @@ var SliccTerminal = class _SliccTerminal extends HTMLElement {
5330
6349
  const cols = dimension(this.getAttribute("cols"));
5331
6350
  const rows = dimension(this.getAttribute("rows"));
5332
6351
  const mine = () => generation === this.#generation;
6352
+ let core;
6353
+ try {
6354
+ core = await loadCore(_SliccTerminal.wasmUrl);
6355
+ } catch (error) {
6356
+ if (mine()) throw error;
6357
+ return;
6358
+ }
6359
+ if (!mine()) return core.dispose();
5333
6360
  const term = new WTerm(host, {
5334
6361
  cols,
5335
6362
  rows,
5336
- wasmUrl: _SliccTerminal.wasmUrl,
6363
+ core,
5337
6364
  onData: (data) => mine() && this.send(this.#pasting ? data.replace(/\r?\n/g, "\r") : data),
5338
6365
  onBinary: (data) => mine() && this.send(data),
5339
6366
  onResize: (c, r) => mine() && this.#resized(c, r),
5340
6367
  onTitle: (title) => mine() && this.#emit("title", { title }),
5341
6368
  onBell: (count) => mine() && this.#emit("bell", { count })
5342
6369
  });
5343
- try {
5344
- await term.init();
5345
- } catch (error) {
5346
- if (generation === this.#generation) throw error;
5347
- return;
6370
+ await term.init();
6371
+ if (!mine()) {
6372
+ term.destroy();
6373
+ return core.dispose();
5348
6374
  }
5349
- if (generation !== this.#generation) return term.destroy();
5350
6375
  this.#term = term;
6376
+ this.#core = core;
5351
6377
  this.attributeChangedCallback();
5352
6378
  await this.#open(generation);
5353
6379
  }
@@ -5459,4 +6485,4 @@ export {
5459
6485
  SliccTerminal,
5460
6486
  define
5461
6487
  };
5462
- //# sourceMappingURL=chunk-ZGJM5WUN.js.map
6488
+ //# sourceMappingURL=chunk-SQG7U2FN.js.map