@opentui/core 0.8.0 → 0.8.2

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 (36) hide show
  1. package/NativeScene.d.ts +10 -2
  2. package/NativeSession.d.ts +22 -2
  3. package/buffer.d.ts +2 -0
  4. package/{chunk-bun-6kxdhkdc.js → chunk-bun-vd3rj9kv.js} +451 -74
  5. package/{chunk-bun-6kxdhkdc.js.map → chunk-bun-vd3rj9kv.js.map} +10 -10
  6. package/{chunk-bun-x6cz4jyg.js → chunk-bun-wdetc10w.js} +222 -10
  7. package/chunk-bun-wdetc10w.js.map +35 -0
  8. package/{chunk-node-y0w0hq5m.js → chunk-node-m8mjyx7h.js} +222 -10
  9. package/chunk-node-m8mjyx7h.js.map +34 -0
  10. package/{chunk-node-q5ccgbk5.js → chunk-node-s9be55eh.js} +451 -74
  11. package/{chunk-node-q5ccgbk5.js.map → chunk-node-s9be55eh.js.map} +10 -10
  12. package/index.bun.js +684 -415
  13. package/index.bun.js.map +13 -12
  14. package/index.d.ts +1 -1
  15. package/index.node.js +684 -415
  16. package/index.node.js.map +13 -11
  17. package/native-abi.generated.d.ts +171 -3
  18. package/package.json +9 -9
  19. package/renderables/Image.d.ts +13 -1
  20. package/renderables/LineNumberRenderable.d.ts +1 -1
  21. package/renderables/Markdown.d.ts +1 -6
  22. package/renderables/ScrollBox.d.ts +1 -1
  23. package/renderables/Select.d.ts +0 -2
  24. package/renderables/TabSelect.d.ts +0 -3
  25. package/renderables/TextTable.d.ts +1 -8
  26. package/renderables/Video.d.ts +126 -0
  27. package/renderables/index.d.ts +1 -0
  28. package/renderables/markdown-parser.d.ts +1 -0
  29. package/renderer.d.ts +23 -2
  30. package/testing.bun.js +2 -2
  31. package/testing.js +2 -2
  32. package/yoga.bun.js +1 -1
  33. package/yoga.js +1 -1
  34. package/zig.d.ts +54 -2
  35. package/chunk-bun-x6cz4jyg.js.map +0 -35
  36. package/chunk-node-y0w0hq5m.js.map +0 -34
package/index.node.js CHANGED
@@ -6,7 +6,6 @@ import {
6
6
  generateEnvMarkdown2,
7
7
  generateEnvColored2,
8
8
  env2,
9
- stringWidth,
10
9
  resolveBundledFilePath2,
11
10
  TextAttributes2,
12
11
  ATTRIBUTE_BASE_BITS2,
@@ -120,7 +119,7 @@ import {
120
119
  Gutter2,
121
120
  MeasureMode2,
122
121
  exports_yoga
123
- } from "./chunk-node-y0w0hq5m.js";
122
+ } from "./chunk-node-m8mjyx7h.js";
124
123
  import {
125
124
  isValidBorderStyle2,
126
125
  parseBorderStyle2,
@@ -228,6 +227,8 @@ import {
228
227
  NativeImage2,
229
228
  NativeImagePool2,
230
229
  resolveImageRenderProtocol2,
230
+ checkCrop2,
231
+ sameCrop2,
231
232
  ImageRenderable2,
232
233
  isTextNodeRenderable2,
233
234
  TextNodeRenderable2,
@@ -252,7 +253,7 @@ import {
252
253
  CliRenderEvents2,
253
254
  RendererControlState2,
254
255
  CliRenderer2
255
- } from "./chunk-node-q5ccgbk5.js";
256
+ } from "./chunk-node-s9be55eh.js";
256
257
  // src/syntax-style.ts
257
258
  function cloneStyle(style) {
258
259
  return {
@@ -4741,7 +4742,10 @@ class AudioRecorder extends EventEmitter {
4741
4742
  await this.writeFully(createWavHeader(this.sampleRate, this.channels, Number(this.dataBytesWritten)), 0, "finalize");
4742
4743
  if (this.terminationRequest != null)
4743
4744
  return;
4744
- await this.fileHandle.sync();
4745
+ await this.fileHandle.sync().catch((cause) => {
4746
+ if (cause.code !== "ERR_ACCESS_DENIED")
4747
+ throw cause;
4748
+ });
4745
4749
  if (this.terminationRequest != null)
4746
4750
  return;
4747
4751
  await this.fileHandle.close();
@@ -6086,6 +6090,7 @@ class VRenderable extends Renderable2 {
6086
6090
  // src/renderables/LineNumberRenderable.ts
6087
6091
  var DEFAULT_GUTTER_FG = "#888888";
6088
6092
  var DEFAULT_GUTTER_BG = "transparent";
6093
+ var transparent = RGBA2.fromValues(0, 0, 0, 0);
6089
6094
  function cloneLineSign(sign) {
6090
6095
  return {
6091
6096
  ...sign,
@@ -6108,8 +6113,8 @@ class GutterRenderable extends Renderable2 {
6108
6113
  _maxBeforeWidth = 0;
6109
6114
  _maxAfterWidth = 0;
6110
6115
  _lastKnownLineCount = 0;
6111
- _paintedSources;
6112
- _paintedSourceOffset = 0;
6116
+ _signWidths = new Map;
6117
+ _signWidthMethod;
6113
6118
  constructor(ctx, target, options) {
6114
6119
  super(ctx, {
6115
6120
  id: options.id,
@@ -6134,7 +6139,10 @@ class GutterRenderable extends Renderable2 {
6134
6139
  this.setupMeasureFunc();
6135
6140
  this.onLifecyclePass = () => {
6136
6141
  const currentLineCount = this.target.virtualLineCount;
6137
- if (currentLineCount !== this._lastKnownLineCount) {
6142
+ const signsStale = this._ctx.widthMethod !== this._signWidthMethod;
6143
+ if (signsStale)
6144
+ this.calculateSignWidths();
6145
+ if (currentLineCount !== this._lastKnownLineCount || signsStale) {
6138
6146
  this._lastKnownLineCount = currentLineCount;
6139
6147
  this.invalidateIntrinsicSize();
6140
6148
  this.requestRender();
@@ -6185,16 +6193,30 @@ class GutterRenderable extends Renderable2 {
6185
6193
  calculateSignWidths() {
6186
6194
  this._maxBeforeWidth = 0;
6187
6195
  this._maxAfterWidth = this._layout.minAfterWidth;
6196
+ this._signWidths.clear();
6197
+ this._signWidthMethod = this._ctx.widthMethod;
6188
6198
  for (const sign of this._lineSigns.values()) {
6189
- if (sign.before) {
6190
- const width = stringWidth(sign.before);
6191
- this._maxBeforeWidth = Math.max(this._maxBeforeWidth, width);
6192
- }
6193
- if (sign.after) {
6194
- const width = stringWidth(sign.after);
6195
- this._maxAfterWidth = Math.max(this._maxAfterWidth, width);
6196
- }
6199
+ if (sign.before)
6200
+ this._maxBeforeWidth = Math.max(this._maxBeforeWidth, this.signWidth(sign.before));
6201
+ if (sign.after)
6202
+ this._maxAfterWidth = Math.max(this._maxAfterWidth, this.signWidth(sign.after));
6203
+ }
6204
+ }
6205
+ signWidth(sign) {
6206
+ if (/^[\x20-\x7e]*$/.test(sign))
6207
+ return sign.length;
6208
+ let width = this._signWidths.get(sign);
6209
+ if (width !== undefined)
6210
+ return width;
6211
+ const { context, renderLib } = this._ctx.nativeScene.driver;
6212
+ const unicode = renderLib.createContextUnicode(context, sign, this._signWidthMethod);
6213
+ try {
6214
+ width = renderLib.getContextUnicode(context, unicode).reduce((sum, glyph) => sum + glyph.width, 0);
6215
+ } finally {
6216
+ renderLib.destroyContextUnicode(context, unicode);
6197
6217
  }
6218
+ this._signWidths.set(sign, width);
6219
+ return width;
6198
6220
  }
6199
6221
  calculateWidth() {
6200
6222
  const totalLines = Math.max(this.target.lineCount, this.target.virtualLineCount);
@@ -6250,81 +6272,48 @@ class GutterRenderable extends Renderable2 {
6250
6272
  getLineSigns() {
6251
6273
  return this._lineSigns;
6252
6274
  }
6253
- createFrameBuffer() {}
6254
- handleFrameBufferResize() {}
6255
6275
  renderSelf(buffer) {
6256
- const x = Math.trunc(this._screenX);
6257
- const y = Math.trunc(this._screenY);
6276
+ const [x, y] = this._paintOrigin(buffer);
6258
6277
  const start = Math.max(0, -y);
6259
6278
  const end = Math.min(this.height, buffer.height - y);
6260
6279
  if (end <= start || x >= buffer.width || x + this.width <= 0)
6261
6280
  return;
6262
- if (!this.frameBuffer) {
6263
- this.frameBuffer = OptimizedBuffer2.create(this.width, end - start, this._ctx.widthMethod, {
6264
- respectAlpha: true,
6265
- id: `framebuffer-${this.id}`,
6266
- owner: this._ctx.nativeScene
6267
- });
6268
- } else if (this.frameBuffer.width !== this.width || this.frameBuffer.height !== end - start) {
6269
- this.frameBuffer.resize(this.width, end - start);
6270
- this._paintedSources = undefined;
6271
- }
6272
- this.refreshFrameBuffer(this.frameBuffer, Math.trunc(this.target.scrollY) + start);
6273
- this.markClean();
6274
- buffer.drawFrameBuffer(x, y + start, this.frameBuffer);
6275
- }
6276
- refreshFrameBuffer(buffer, startLine) {
6281
+ const startLine = Math.trunc(this.target.scrollY) + start;
6277
6282
  const sourceStart = Math.max(0, startLine - 1);
6278
6283
  const sourceOffset = startLine - sourceStart;
6279
- const sources = getLineSources(this.target, sourceStart, buffer.height + sourceOffset);
6280
- const paintedSources = this._paintedSources;
6281
- if (!this.isDirty && sourceOffset === this._paintedSourceOffset && paintedSources && sources.length === paintedSources.length && sources.every((source, i) => source === paintedSources[i])) {
6282
- return;
6283
- }
6284
- buffer.clear(this._bg);
6284
+ const sources = getLineSources(this.target, sourceStart, end - start + sourceOffset);
6285
6285
  let lastSource = sourceOffset > 0 ? sources[0] : -1;
6286
- for (let i = 0;i < buffer.height; i++) {
6287
- const visualLineIndex = sourceOffset + i;
6288
- if (visualLineIndex >= sources.length)
6289
- break;
6290
- const logicalLine = sources[visualLineIndex];
6291
- const lineBg = this._lineColorsGutter.get(logicalLine) ?? this._bg;
6292
- if (lineBg !== this._bg) {
6293
- buffer.fillRect(0, i, this.width, 1, lineBg);
6294
- }
6295
- if (logicalLine === lastSource) {} else {
6296
- let currentX = 0;
6286
+ for (let i = sourceOffset;i < end - start + sourceOffset; i++) {
6287
+ const row = y + start + i - sourceOffset;
6288
+ const logicalLine = sources[i];
6289
+ const lineBg = this._lineColorsGutter.get(logicalLine);
6290
+ if (!lineBg || lineBg.a < 1)
6291
+ buffer.fillRect(x, row, this.width, 1, this._bg);
6292
+ if (lineBg)
6293
+ buffer.fillRect(x, row, this.width, 1, lineBg);
6294
+ if (logicalLine !== undefined && logicalLine !== lastSource) {
6297
6295
  const sign = this._lineSigns.get(logicalLine);
6298
6296
  if (sign?.before) {
6299
- const beforeWidth = stringWidth(sign.before);
6300
- const padding = this._maxBeforeWidth - beforeWidth;
6301
- currentX += padding;
6297
+ const beforeX = x + this._maxBeforeWidth - this.signWidth(sign.before);
6302
6298
  const beforeColor = sign.beforeColor ? parseColor2(sign.beforeColor) : this._fg;
6303
- buffer.drawText(sign.before, currentX, i, beforeColor, lineBg);
6304
- currentX += beforeWidth;
6305
- } else if (this._maxBeforeWidth > 0) {
6306
- currentX += this._maxBeforeWidth;
6299
+ buffer.drawText(sign.before, beforeX, row, beforeColor, transparent);
6307
6300
  }
6308
6301
  if (!this._hideLineNumbers.has(logicalLine)) {
6309
6302
  const customLineNum = this._lineNumbers.get(logicalLine);
6310
- const lineNum = customLineNum !== undefined ? customLineNum : logicalLine + 1 + this._lineNumberOffset;
6311
- const lineNumStr = lineNum.toString();
6312
- const lineNumWidth = lineNumStr.length;
6313
- const lineNumX = this.width - this._maxAfterWidth - this._layout.paddingRight - lineNumWidth;
6303
+ const lineNumStr = (customLineNum ?? logicalLine + 1 + this._lineNumberOffset).toString();
6304
+ const lineNumX = this.width - this._maxAfterWidth - this._layout.paddingRight - lineNumStr.length;
6314
6305
  if (lineNumX >= this._maxBeforeWidth + this._layout.paddingLeft) {
6315
- buffer.drawText(lineNumStr, lineNumX, i, this._fg, lineBg);
6306
+ buffer.drawText(lineNumStr, x + lineNumX, row, this._fg, transparent);
6316
6307
  }
6317
6308
  }
6318
6309
  if (sign?.after) {
6319
- const afterX = this.width - this._layout.paddingRight - this._maxAfterWidth;
6310
+ const afterX = x + this.width - this._layout.paddingRight - this._maxAfterWidth;
6320
6311
  const afterColor = sign.afterColor ? parseColor2(sign.afterColor) : this._fg;
6321
- buffer.drawText(sign.after, afterX, i, afterColor, lineBg);
6312
+ buffer.drawText(sign.after, afterX, row, afterColor, transparent);
6322
6313
  }
6323
6314
  }
6324
6315
  lastSource = logicalLine;
6325
6316
  }
6326
- this._paintedSources = sources.slice();
6327
- this._paintedSourceOffset = sourceOffset;
6328
6317
  }
6329
6318
  }
6330
6319
  function getLineSources(target, startLine, lineCount) {
@@ -9042,6 +9031,472 @@ class InputRenderable extends TextareaRenderable {
9042
9031
  }
9043
9032
  set initialValue(value) {}
9044
9033
  }
9034
+ // src/renderables/Video.ts
9035
+ function validateVolume(value) {
9036
+ if (!Number.isFinite(value) || value < 0 || value > 340282346638528860000000000000000000000)
9037
+ throw new RangeError("volume must be a finite, non-negative 32-bit float");
9038
+ }
9039
+ function validateAvSyncOffset(value) {
9040
+ if (!Number.isFinite(value) || Math.abs(value) > 60000)
9041
+ throw new RangeError("avSyncOffsetMs must be from -60000 to 60000");
9042
+ }
9043
+ function validateMaxFps(value) {
9044
+ if (!Number.isInteger(value) || value < 1 || value > 120)
9045
+ throw new RangeError("maxFps must be an integer from 1 to 120");
9046
+ }
9047
+ function toMicroseconds(seconds, label) {
9048
+ const value = Math.round(seconds * 1e6);
9049
+ if (!Number.isFinite(seconds) || !Number.isSafeInteger(value))
9050
+ throw new RangeError(`${label} must be finite`);
9051
+ return BigInt(value);
9052
+ }
9053
+
9054
+ class VideoRenderable extends Renderable2 {
9055
+ static nativeIntegration = {
9056
+ kind: "video",
9057
+ body: { native: this.prototype.renderSelf, buffered: true },
9058
+ bufferComposition: "native"
9059
+ };
9060
+ _source;
9061
+ _fit;
9062
+ _crop;
9063
+ _loop;
9064
+ _audio;
9065
+ _muted;
9066
+ _volume;
9067
+ _avSyncOffsetMs;
9068
+ _maxFps;
9069
+ _autoplay;
9070
+ _metadata = null;
9071
+ _playRequested = false;
9072
+ stopTick;
9073
+ _opens = 0;
9074
+ onReady;
9075
+ onError;
9076
+ onEnd;
9077
+ onPlay;
9078
+ onPause;
9079
+ onSeek;
9080
+ onTimeUpdate;
9081
+ constructor(ctx, options) {
9082
+ super(ctx, options);
9083
+ try {
9084
+ this._fit = options.fit ?? "fit";
9085
+ this._loop = options.loop ?? false;
9086
+ this._audio = options.audio ?? true;
9087
+ this._muted = options.muted ?? false;
9088
+ this._volume = options.volume ?? 1;
9089
+ validateVolume(this._volume);
9090
+ this._avSyncOffsetMs = options.avSyncOffsetMs ?? 0;
9091
+ validateAvSyncOffset(this._avSyncOffsetMs);
9092
+ this._maxFps = options.maxFps ?? 30;
9093
+ validateMaxFps(this._maxFps);
9094
+ this._autoplay = options.autoplay ?? false;
9095
+ this.onReady = options.onReady;
9096
+ this.onError = options.onError;
9097
+ this.onEnd = options.onEnd;
9098
+ this.onPlay = options.onPlay;
9099
+ this.onPause = options.onPause;
9100
+ this.onSeek = options.onSeek;
9101
+ this.onTimeUpdate = options.onTimeUpdate;
9102
+ this.setNativeSceneVideo();
9103
+ if (options.source !== undefined)
9104
+ this.source = options.source;
9105
+ this.crop = options.crop;
9106
+ } catch (error) {
9107
+ this.abortConstruction(error, () => this.destroySelf());
9108
+ }
9109
+ }
9110
+ get source() {
9111
+ return this._source;
9112
+ }
9113
+ set source(value) {
9114
+ value ??= undefined;
9115
+ if (value === this._source && !this.failed() || this.isDestroyed)
9116
+ return;
9117
+ this.open(value, this.playing);
9118
+ }
9119
+ open(value, resume) {
9120
+ this._opens++;
9121
+ this._source = value;
9122
+ this._metadata = null;
9123
+ this._playRequested = resume;
9124
+ const native = this.native();
9125
+ try {
9126
+ const info = native.lib.videoOpen(native.context, native.node, value ?? "", this._audio);
9127
+ if (!value)
9128
+ return;
9129
+ this._playRequested = resume || this._autoplay;
9130
+ this._metadata = {
9131
+ width: info.width,
9132
+ height: info.height,
9133
+ fps: info.fpsDen > 0 ? info.fpsNum / info.fpsDen : 0,
9134
+ duration: Number(info.durationUs) / 1e6,
9135
+ hasAudio: info.hasAudio
9136
+ };
9137
+ native.lib.videoSetLoop(native.context, native.node, this._loop);
9138
+ native.lib.videoSetMuted(native.context, native.node, this._muted);
9139
+ native.lib.videoSetVolume(native.context, native.node, this._volume);
9140
+ native.lib.videoSetAvSyncOffset(native.context, native.node, toMicroseconds(this._avSyncOffsetMs / 1000, "avSyncOffsetMs"));
9141
+ native.lib.videoSetMaxFps(native.context, native.node, this._maxFps);
9142
+ const metadata = { ...this._metadata };
9143
+ this.afterOpen(() => {
9144
+ this.onReady?.(metadata);
9145
+ this.startRequested();
9146
+ try {
9147
+ if (this._crop)
9148
+ checkCrop2(this._crop, metadata.width, metadata.height);
9149
+ } catch (error) {
9150
+ this.reportError(error, "");
9151
+ }
9152
+ });
9153
+ } catch (error) {
9154
+ this._metadata = null;
9155
+ this._playRequested = false;
9156
+ const detail = this.errorDetail("");
9157
+ this.afterOpen(() => this.reportError(error, detail));
9158
+ } finally {
9159
+ this.syncPlayback();
9160
+ this.requestRender();
9161
+ }
9162
+ }
9163
+ get fit() {
9164
+ return this._fit;
9165
+ }
9166
+ set fit(value) {
9167
+ const next = value ?? "fit";
9168
+ if (this._fit === next || this.isDestroyed)
9169
+ return;
9170
+ this.setNativeSceneVideo(next);
9171
+ this._fit = next;
9172
+ this.requestRender();
9173
+ }
9174
+ get crop() {
9175
+ return this._crop && { ...this._crop };
9176
+ }
9177
+ set crop(value) {
9178
+ if (sameCrop2(this._crop, value ?? undefined) || this.isDestroyed)
9179
+ return;
9180
+ const next = this.acceptCrop(value ?? undefined);
9181
+ if (next === null)
9182
+ return;
9183
+ this._ctx.nativeScene.setCrop(this, next);
9184
+ this._crop = next;
9185
+ this.requestRender();
9186
+ }
9187
+ get loop() {
9188
+ return this._loop;
9189
+ }
9190
+ set loop(value) {
9191
+ const next = value ?? false;
9192
+ if (this._loop === next || this.isDestroyed)
9193
+ return;
9194
+ if (this.applyOption((native) => native.lib.videoSetLoop(native.context, native.node, next)))
9195
+ this._loop = next;
9196
+ }
9197
+ get audio() {
9198
+ return this._audio;
9199
+ }
9200
+ set audio(value) {
9201
+ const next = value ?? true;
9202
+ if (this._audio === next || this.isDestroyed)
9203
+ return;
9204
+ this._audio = next;
9205
+ if (this._metadata)
9206
+ this.open(this._source, this.playing);
9207
+ }
9208
+ get muted() {
9209
+ return this._muted;
9210
+ }
9211
+ set muted(value) {
9212
+ const next = value ?? false;
9213
+ if (this._muted === next || this.isDestroyed)
9214
+ return;
9215
+ if (this.applyOption((native) => native.lib.videoSetMuted(native.context, native.node, next)))
9216
+ this._muted = next;
9217
+ }
9218
+ get volume() {
9219
+ return this._volume;
9220
+ }
9221
+ set volume(value) {
9222
+ const next = value ?? 1;
9223
+ validateVolume(next);
9224
+ if (this._volume === next || this.isDestroyed)
9225
+ return;
9226
+ if (this.applyOption((native) => native.lib.videoSetVolume(native.context, native.node, next)))
9227
+ this._volume = next;
9228
+ }
9229
+ get avSyncOffsetMs() {
9230
+ return this._avSyncOffsetMs;
9231
+ }
9232
+ set avSyncOffsetMs(value) {
9233
+ const next = value ?? 0;
9234
+ validateAvSyncOffset(next);
9235
+ if (this._avSyncOffsetMs === next || this.isDestroyed)
9236
+ return;
9237
+ const offset = toMicroseconds(next / 1000, "avSyncOffsetMs");
9238
+ if (this.applyOption((native) => native.lib.videoSetAvSyncOffset(native.context, native.node, offset)))
9239
+ this._avSyncOffsetMs = next;
9240
+ }
9241
+ get maxFps() {
9242
+ return this._maxFps;
9243
+ }
9244
+ set maxFps(value) {
9245
+ const next = value ?? 30;
9246
+ validateMaxFps(next);
9247
+ if (this._maxFps === next || this.isDestroyed)
9248
+ return;
9249
+ if (!this.applyOption((native) => native.lib.videoSetMaxFps(native.context, native.node, next)))
9250
+ return;
9251
+ this._maxFps = next;
9252
+ this.syncPlayback();
9253
+ }
9254
+ get autoplay() {
9255
+ return this._autoplay;
9256
+ }
9257
+ set autoplay(value) {
9258
+ const next = value ?? false;
9259
+ if (this._autoplay === next || this.isDestroyed)
9260
+ return;
9261
+ this._autoplay = next;
9262
+ if (!next || !this._metadata)
9263
+ return;
9264
+ const requested = this.control((native) => {
9265
+ const state = native.lib.videoGetState(native.context, native.node);
9266
+ if (state.playing || state.ended || state.currentTimeUs !== 0n)
9267
+ return false;
9268
+ this._playRequested = true;
9269
+ });
9270
+ if (requested)
9271
+ this.afterOpen(() => this.startRequested());
9272
+ }
9273
+ get ready() {
9274
+ return this._metadata !== null;
9275
+ }
9276
+ get videoMetadata() {
9277
+ return this._metadata ? { ...this._metadata } : null;
9278
+ }
9279
+ get playing() {
9280
+ if (this.isDestroyed)
9281
+ return false;
9282
+ return this._playRequested || this._metadata !== null && this.readState().playing;
9283
+ }
9284
+ get paused() {
9285
+ return !this.playing;
9286
+ }
9287
+ get ended() {
9288
+ return this._metadata !== null && !this.isDestroyed && this.readState().ended;
9289
+ }
9290
+ get duration() {
9291
+ return this._metadata?.duration ?? 0;
9292
+ }
9293
+ get durationMs() {
9294
+ return this.duration * 1000;
9295
+ }
9296
+ get currentTime() {
9297
+ if (!this._metadata || this.isDestroyed)
9298
+ return 0;
9299
+ return Number(this.readState().currentTimeUs) / 1e6;
9300
+ }
9301
+ set currentTime(value) {
9302
+ if (value == null)
9303
+ return;
9304
+ this.seek(value);
9305
+ }
9306
+ get qualityTier() {
9307
+ if (!this._metadata || this.isDestroyed)
9308
+ return 0;
9309
+ return this.readState().qualityTier;
9310
+ }
9311
+ get currentTimeMs() {
9312
+ return this.currentTime * 1000;
9313
+ }
9314
+ play() {
9315
+ if (this.isDestroyed || this._playRequested)
9316
+ return;
9317
+ if (!this._metadata) {
9318
+ if (this._source !== undefined)
9319
+ this.open(this._source, true);
9320
+ else
9321
+ this._playRequested = true;
9322
+ return;
9323
+ }
9324
+ const started = this.control((native) => {
9325
+ if (native.lib.videoGetState(native.context, native.node).playing)
9326
+ return false;
9327
+ native.lib.videoCall(native.context, native.node, "ot_video_play");
9328
+ });
9329
+ if (started)
9330
+ this.onPlay?.();
9331
+ }
9332
+ resume() {
9333
+ this.play();
9334
+ }
9335
+ pause() {
9336
+ if (this.isDestroyed)
9337
+ return;
9338
+ const requested = this._playRequested;
9339
+ this._playRequested = false;
9340
+ if (!this._metadata)
9341
+ return;
9342
+ const paused = this.control((native) => {
9343
+ if (requested)
9344
+ return;
9345
+ if (!native.lib.videoGetState(native.context, native.node).playing)
9346
+ return false;
9347
+ native.lib.videoCall(native.context, native.node, "ot_video_pause");
9348
+ });
9349
+ if (!paused)
9350
+ return;
9351
+ const time = this.currentTime;
9352
+ this.onPause?.();
9353
+ this.onTimeUpdate?.(time);
9354
+ }
9355
+ toggle() {
9356
+ if (this.playing)
9357
+ this.pause();
9358
+ else
9359
+ this.play();
9360
+ }
9361
+ seek(time) {
9362
+ const target = toMicroseconds(time, "Video time");
9363
+ if (!this._metadata || this.isDestroyed)
9364
+ return;
9365
+ if (!this.control((native) => native.lib.videoSeek(native.context, native.node, target)))
9366
+ return;
9367
+ const position = this.currentTime;
9368
+ this.onSeek?.(position);
9369
+ this.onTimeUpdate?.(position);
9370
+ }
9371
+ seekBy(delta) {
9372
+ if (!Number.isFinite(delta))
9373
+ throw new RangeError("Video seek delta must be finite");
9374
+ this.seek(this.currentTime + delta);
9375
+ }
9376
+ seekToMs(milliseconds) {
9377
+ if (!Number.isFinite(milliseconds))
9378
+ throw new RangeError("Video time must be finite");
9379
+ this.seek(milliseconds / 1000);
9380
+ }
9381
+ createFrameBuffer() {
9382
+ const previous = this.frameBuffer;
9383
+ super.createFrameBuffer();
9384
+ if (this._fit === undefined || this.frameBuffer === previous)
9385
+ return;
9386
+ this.setNativeSceneVideo();
9387
+ }
9388
+ renderSelf(_buffer) {}
9389
+ poll() {
9390
+ if (!this._metadata || this.isDestroyed)
9391
+ return;
9392
+ let state;
9393
+ try {
9394
+ state = this.readState();
9395
+ } catch (error) {
9396
+ this.reportError(error);
9397
+ this.syncPlayback(false);
9398
+ return;
9399
+ }
9400
+ if (state.failed) {
9401
+ this.reportError(new Error(this.errorDetail("Video playback failed")));
9402
+ this.syncPlayback();
9403
+ return;
9404
+ }
9405
+ this.onTimeUpdate?.(Number(state.currentTimeUs) / 1e6);
9406
+ if (state.ended) {
9407
+ this.syncPlayback();
9408
+ this.onEnd?.();
9409
+ }
9410
+ }
9411
+ native() {
9412
+ return this._ctx.nativeScene.videoNode(this);
9413
+ }
9414
+ readState() {
9415
+ const native = this.native();
9416
+ return native.lib.videoGetState(native.context, native.node);
9417
+ }
9418
+ failed() {
9419
+ if (!this._metadata)
9420
+ return false;
9421
+ try {
9422
+ return this.readState().failed;
9423
+ } catch {
9424
+ return true;
9425
+ }
9426
+ }
9427
+ errorDetail(fallback) {
9428
+ try {
9429
+ const native = this.native();
9430
+ return native.lib.videoGetError(native.context, native.node) || fallback;
9431
+ } catch {
9432
+ return fallback;
9433
+ }
9434
+ }
9435
+ applyOption(call) {
9436
+ return !this._metadata || this.control(call);
9437
+ }
9438
+ control(call) {
9439
+ let reported = false;
9440
+ try {
9441
+ return call(this.native()) !== false;
9442
+ } catch (error) {
9443
+ reported = true;
9444
+ this.reportError(error);
9445
+ return false;
9446
+ } finally {
9447
+ this.syncPlayback(!reported);
9448
+ this.requestRender();
9449
+ }
9450
+ }
9451
+ syncPlayback(report = true) {
9452
+ if (this.isDestroyed)
9453
+ return;
9454
+ let active = false;
9455
+ try {
9456
+ active = this._metadata !== null && (this._playRequested || this.readState().playing);
9457
+ } catch (error) {
9458
+ if (report)
9459
+ this.reportError(error);
9460
+ }
9461
+ this.stopTick?.();
9462
+ this.stopTick = active ? this._ctx.onAnimationTick(this._maxFps, () => this.poll()) : undefined;
9463
+ }
9464
+ setNativeSceneVideo(fit = this._fit) {
9465
+ this._ctx.nativeScene.setVideo(this, fit, this.buffered ? this.frameBuffer : null);
9466
+ }
9467
+ acceptCrop(crop) {
9468
+ try {
9469
+ return crop && checkCrop2(crop, this._metadata?.width, this._metadata?.height);
9470
+ } catch (error) {
9471
+ queueMicrotask(() => this.isDestroyed || this.reportError(error, ""));
9472
+ return null;
9473
+ }
9474
+ }
9475
+ startRequested() {
9476
+ if (!this._playRequested)
9477
+ return;
9478
+ this._playRequested = false;
9479
+ if (this.control((native) => native.lib.videoCall(native.context, native.node, "ot_video_play")))
9480
+ this.onPlay?.();
9481
+ }
9482
+ afterOpen(report) {
9483
+ const opens = this._opens;
9484
+ queueMicrotask(() => {
9485
+ if (this._opens === opens && !this.isDestroyed)
9486
+ report();
9487
+ });
9488
+ }
9489
+ reportError(error, detail = this.errorDetail("")) {
9490
+ const value = error instanceof Error ? error : new Error(String(error));
9491
+ this.onError?.(detail && !value.message.includes(detail) ? new Error(`${value.message}: ${detail}`) : value);
9492
+ }
9493
+ destroySelf() {
9494
+ this.runCleanup((run) => {
9495
+ run(() => this.stopTick?.());
9496
+ run(() => super.destroySelf());
9497
+ });
9498
+ }
9499
+ }
9045
9500
  // ../../node_modules/.bun/marked@17.0.1/node_modules/marked/lib/marked.esm.js
9046
9501
  function L() {
9047
9502
  return { async: false, breaks: false, extensions: null, gfm: true, hooks: null, pedantic: false, renderer: null, silent: false, tokenizer: null, walkTokens: null };
@@ -10416,7 +10871,6 @@ class TextTableRenderable extends Renderable2 {
10416
10871
  _columnCount = 0;
10417
10872
  _layout = this.createEmptyLayout();
10418
10873
  _layoutDirty = true;
10419
- _rasterDirty = true;
10420
10874
  _cachedMeasureLayout = null;
10421
10875
  _cachedMeasureWidth = undefined;
10422
10876
  _defaultOptions = {
@@ -10443,7 +10897,7 @@ class TextTableRenderable extends Renderable2 {
10443
10897
  attributes: 0
10444
10898
  };
10445
10899
  constructor(ctx, options = {}) {
10446
- super(ctx, { ...options, flexShrink: options.flexShrink ?? 0, buffered: true });
10900
+ super(ctx, { ...options, flexShrink: options.flexShrink ?? 0 });
10447
10901
  try {
10448
10902
  this._content = options.content ?? this._defaultOptions.content;
10449
10903
  this._wrapMode = options.wrapMode ?? this._defaultOptions.wrapMode;
@@ -10490,7 +10944,7 @@ class TextTableRenderable extends Renderable2 {
10490
10944
  for (const cell of row)
10491
10945
  cell.textBufferView.setWrapMode(value);
10492
10946
  }
10493
- this.invalidateLayoutAndRaster();
10947
+ this.invalidateLayout();
10494
10948
  });
10495
10949
  }
10496
10950
  get columnWidthMode() {
@@ -10500,7 +10954,7 @@ class TextTableRenderable extends Renderable2 {
10500
10954
  if (this._columnWidthMode === value)
10501
10955
  return;
10502
10956
  this._columnWidthMode = value;
10503
- this.invalidateLayoutAndRaster();
10957
+ this.invalidateLayout();
10504
10958
  }
10505
10959
  get columnFitter() {
10506
10960
  return this._columnFitter;
@@ -10510,7 +10964,7 @@ class TextTableRenderable extends Renderable2 {
10510
10964
  if (this._columnFitter === next)
10511
10965
  return;
10512
10966
  this._columnFitter = next;
10513
- this.invalidateLayoutAndRaster();
10967
+ this.invalidateLayout();
10514
10968
  }
10515
10969
  get cellPadding() {
10516
10970
  return this._cellPaddingX === this._cellPaddingY ? this._cellPaddingX : 0;
@@ -10521,7 +10975,7 @@ class TextTableRenderable extends Renderable2 {
10521
10975
  return;
10522
10976
  this._cellPaddingX = next;
10523
10977
  this._cellPaddingY = next;
10524
- this.invalidateLayoutAndRaster();
10978
+ this.invalidateLayout();
10525
10979
  }
10526
10980
  get cellPaddingX() {
10527
10981
  return this._cellPaddingX;
@@ -10531,7 +10985,7 @@ class TextTableRenderable extends Renderable2 {
10531
10985
  if (this._cellPaddingX === next)
10532
10986
  return;
10533
10987
  this._cellPaddingX = next;
10534
- this.invalidateLayoutAndRaster();
10988
+ this.invalidateLayout();
10535
10989
  }
10536
10990
  get cellPaddingY() {
10537
10991
  return this._cellPaddingY;
@@ -10541,7 +10995,7 @@ class TextTableRenderable extends Renderable2 {
10541
10995
  if (this._cellPaddingY === next)
10542
10996
  return;
10543
10997
  this._cellPaddingY = next;
10544
- this.invalidateLayoutAndRaster();
10998
+ this.invalidateLayout();
10545
10999
  }
10546
11000
  get columnGap() {
10547
11001
  return this._columnGap;
@@ -10551,7 +11005,7 @@ class TextTableRenderable extends Renderable2 {
10551
11005
  if (this._columnGap === next)
10552
11006
  return;
10553
11007
  this._columnGap = next;
10554
- this.invalidateLayoutAndRaster();
11008
+ this.invalidateLayout();
10555
11009
  }
10556
11010
  get showBorders() {
10557
11011
  return this._showBorders;
@@ -10560,7 +11014,7 @@ class TextTableRenderable extends Renderable2 {
10560
11014
  if (this._showBorders === value)
10561
11015
  return;
10562
11016
  this._showBorders = value;
10563
- this.invalidateRasterOnly();
11017
+ this.requestRender();
10564
11018
  }
10565
11019
  get outerBorder() {
10566
11020
  return this._outerBorder;
@@ -10573,7 +11027,7 @@ class TextTableRenderable extends Renderable2 {
10573
11027
  return;
10574
11028
  this._hasExplicitOuterBorder = value != null;
10575
11029
  this._outerBorder = next;
10576
- this.invalidateLayoutAndRaster();
11030
+ this.invalidateLayout();
10577
11031
  }
10578
11032
  get border() {
10579
11033
  return this._border;
@@ -10585,7 +11039,7 @@ class TextTableRenderable extends Renderable2 {
10585
11039
  if (!this._hasExplicitOuterBorder) {
10586
11040
  this._outerBorder = value;
10587
11041
  }
10588
- this.invalidateLayoutAndRaster();
11042
+ this.invalidateLayout();
10589
11043
  }
10590
11044
  get borderStyle() {
10591
11045
  return this._borderStyle;
@@ -10595,14 +11049,14 @@ class TextTableRenderable extends Renderable2 {
10595
11049
  if (this._borderStyle === next)
10596
11050
  return;
10597
11051
  this._borderStyle = next;
10598
- this.invalidateRasterOnly();
11052
+ this.requestRender();
10599
11053
  }
10600
11054
  get borderColor() {
10601
11055
  return RGBA2.clone(this._borderColor);
10602
11056
  }
10603
11057
  set borderColor(value) {
10604
11058
  this._borderColor = RGBA2.clone(parseColor2(value ?? this._defaultOptions.borderColor));
10605
- this.invalidateRasterOnly();
11059
+ this.requestRender();
10606
11060
  }
10607
11061
  get fg() {
10608
11062
  return this._defaultFg;
@@ -10617,7 +11071,7 @@ class TextTableRenderable extends Renderable2 {
10617
11071
  cell.textBuffer.setDefaultFg(next);
10618
11072
  }
10619
11073
  }
10620
- this.invalidateRasterOnly();
11074
+ this.requestRender();
10621
11075
  }
10622
11076
  shouldStartSelection(x, y) {
10623
11077
  if (!this.selectable)
@@ -10629,19 +11083,15 @@ class TextTableRenderable extends Renderable2 {
10629
11083
  }
10630
11084
  onSelectionChanged(selection) {
10631
11085
  this.ensureLayoutReady();
10632
- const previousLocalSelection = this._lastLocalSelection;
10633
11086
  const localSelection = convertGlobalToLocalSelection2(selection, Math.trunc(this.x), Math.trunc(this.y));
10634
11087
  this._lastLocalSelection = localSelection;
10635
- const dirtyRows = this.getDirtySelectionRowRange(previousLocalSelection, localSelection);
10636
11088
  if (!localSelection?.isActive) {
10637
11089
  this.resetCellSelections();
10638
11090
  this._lastSelectionMode = null;
10639
11091
  } else {
10640
11092
  this.applySelectionToCells(localSelection, selection?.isStart ?? false);
10641
11093
  }
10642
- if (dirtyRows !== null) {
10643
- this.redrawSelectionRows(dirtyRows.firstRow, dirtyRows.lastRow);
10644
- }
11094
+ this.requestRender();
10645
11095
  return this.hasSelection();
10646
11096
  }
10647
11097
  hasSelection() {
@@ -10686,25 +11136,23 @@ class TextTableRenderable extends Renderable2 {
10686
11136
  `);
10687
11137
  }
10688
11138
  onResize(width, height) {
10689
- this.invalidateLayoutAndRaster(false);
11139
+ this.invalidateLayout(false);
10690
11140
  super.onResize(width, height);
10691
11141
  }
10692
11142
  renderSelf(buffer) {
10693
11143
  if (!this.visible || this.isDestroyed)
10694
11144
  return;
10695
- if (this._layoutDirty) {
10696
- this.rebuildLayoutForCurrentWidth();
10697
- }
10698
- if (!this._rasterDirty)
10699
- return;
10700
- buffer.clear(this._backgroundColor);
10701
- if (this._rowCount === 0 || this._columnCount === 0) {
10702
- this._rasterDirty = false;
10703
- return;
11145
+ this.ensureLayoutReady();
11146
+ const [x, y] = this._paintOrigin(buffer);
11147
+ buffer.pushScissorRect(x, y, this._paintWidth, this._paintHeight);
11148
+ if (buffer === this.frameBuffer)
11149
+ buffer.clear(this._backgroundColor);
11150
+ else if (this._backgroundColor.a > 0) {
11151
+ buffer.fillRect(x, y, this._paintWidth, this._paintHeight, this._backgroundColor);
10704
11152
  }
10705
- this.drawBorders(buffer);
10706
- this.drawCells(buffer);
10707
- this._rasterDirty = false;
11153
+ this.drawBorders(buffer, x, y);
11154
+ this.drawCells(buffer, x, y);
11155
+ buffer.popScissorRect();
10708
11156
  }
10709
11157
  destroySelf() {
10710
11158
  this.destroyCells();
@@ -10790,7 +11238,7 @@ class TextTableRenderable extends Renderable2 {
10790
11238
  this._rowCount = newRowCount;
10791
11239
  this._columnCount = newColumnCount;
10792
11240
  this.runCleanup((run) => {
10793
- run(() => this.invalidateLayoutAndRaster());
11241
+ run(() => this.invalidateLayout());
10794
11242
  for (let rowIdx = 0;rowIdx < previous.length; rowIdx++) {
10795
11243
  for (let colIdx = 0;colIdx < previous[rowIdx].length; colIdx++) {
10796
11244
  const cell = previous[rowIdx][colIdx];
@@ -11090,7 +11538,7 @@ class TextTableRenderable extends Renderable2 {
11090
11538
  getHorizontalBorderCount(borderLayout) {
11091
11539
  return (borderLayout.top ? 1 : 0) + (borderLayout.bottom ? 1 : 0) + (borderLayout.innerHorizontal ? Math.max(0, this._rowCount - 1) : 0);
11092
11540
  }
11093
- drawBorders(buffer) {
11541
+ drawBorders(buffer, x, y) {
11094
11542
  if (!this._showBorders) {
11095
11543
  return;
11096
11544
  }
@@ -11098,59 +11546,31 @@ class TextTableRenderable extends Renderable2 {
11098
11546
  if (this.getVerticalBorderCount(borderLayout) === 0 && this.getHorizontalBorderCount(borderLayout) === 0) {
11099
11547
  return;
11100
11548
  }
11549
+ const { columnOffsets, rowOffsets, columnOffsetsI32, rowOffsetsI32 } = this._layout;
11550
+ columnOffsets.forEach((offset, index) => columnOffsetsI32[index] = offset + x);
11551
+ rowOffsets.forEach((offset, index) => rowOffsetsI32[index] = offset + y);
11101
11552
  buffer.drawGrid({
11102
11553
  borderChars: BorderCharArrays2[this._borderStyle],
11103
11554
  borderFg: this._borderColor,
11104
11555
  borderBg: this._borderBackgroundColor,
11105
- columnOffsets: this._layout.columnOffsetsI32,
11106
- rowOffsets: this._layout.rowOffsetsI32,
11556
+ columnOffsets: columnOffsetsI32,
11557
+ rowOffsets: rowOffsetsI32,
11107
11558
  drawInner: this._border,
11108
11559
  drawOuter: this._outerBorder
11109
11560
  });
11110
11561
  }
11111
- drawCells(buffer) {
11112
- this.drawCellRange(buffer, 0, this._rowCount - 1);
11113
- }
11114
- drawCellRange(buffer, firstRow, lastRow) {
11562
+ drawCells(buffer, x, y) {
11115
11563
  const colOffsets = this._layout.columnOffsets;
11116
11564
  const rowOffsets = this._layout.rowOffsets;
11117
- const cellPaddingX = this._cellPaddingX;
11565
+ const cellX = x + 1 + this._cellPaddingX;
11118
11566
  const cellPaddingY = this._cellPaddingY;
11119
- for (let rowIdx = firstRow;rowIdx <= lastRow; rowIdx++) {
11120
- const cellY = (rowOffsets[rowIdx] ?? 0) + 1 + cellPaddingY;
11567
+ for (let rowIdx = 0;rowIdx < this._rowCount; rowIdx++) {
11568
+ const cellY = y + (rowOffsets[rowIdx] ?? 0) + 1 + cellPaddingY;
11121
11569
  for (let colIdx = 0;colIdx < this._columnCount; colIdx++) {
11122
11570
  const cell = this._cells[rowIdx]?.[colIdx];
11123
11571
  if (!cell)
11124
11572
  continue;
11125
- buffer.drawTextBuffer(cell.textBufferView, (colOffsets[colIdx] ?? 0) + 1 + cellPaddingX, cellY);
11126
- }
11127
- }
11128
- }
11129
- redrawSelectionRows(firstRow, lastRow) {
11130
- if (firstRow > lastRow)
11131
- return;
11132
- if (this._backgroundColor.a < 1) {
11133
- this.invalidateRasterOnly();
11134
- return;
11135
- }
11136
- const buffer = this.frameBuffer;
11137
- if (!buffer)
11138
- return;
11139
- this.clearCellRange(buffer, firstRow, lastRow);
11140
- this.drawCellRange(buffer, firstRow, lastRow);
11141
- this.requestRender();
11142
- }
11143
- clearCellRange(buffer, firstRow, lastRow) {
11144
- const colWidths = this._layout.columnWidths;
11145
- const rowHeights = this._layout.rowHeights;
11146
- const colOffsets = this._layout.columnOffsets;
11147
- const rowOffsets = this._layout.rowOffsets;
11148
- for (let rowIdx = firstRow;rowIdx <= lastRow; rowIdx++) {
11149
- const cellY = (rowOffsets[rowIdx] ?? 0) + 1;
11150
- const rowHeight = rowHeights[rowIdx] ?? 1;
11151
- for (let colIdx = 0;colIdx < this._columnCount; colIdx++) {
11152
- const cellX = (colOffsets[colIdx] ?? 0) + 1;
11153
- buffer.fillRect(cellX, cellY, colWidths[colIdx] ?? 1, rowHeight, this._backgroundColor);
11573
+ buffer.drawTextBuffer(cell.textBufferView, cellX + (colOffsets[colIdx] ?? 0), cellY);
11154
11574
  }
11155
11575
  }
11156
11576
  }
@@ -11306,28 +11726,6 @@ class TextTableRenderable extends Renderable2 {
11306
11726
  }
11307
11727
  return this._rowCount - 1;
11308
11728
  }
11309
- getSelectionRowRange(selection) {
11310
- if (!selection?.isActive || this._rowCount === 0)
11311
- return null;
11312
- const minSelY = Math.min(selection.anchorY, selection.focusY);
11313
- const maxSelY = Math.max(selection.anchorY, selection.focusY);
11314
- return {
11315
- firstRow: this.findRowForLocalY(minSelY),
11316
- lastRow: this.findRowForLocalY(maxSelY)
11317
- };
11318
- }
11319
- getDirtySelectionRowRange(previousSelection, currentSelection) {
11320
- const previousRange = this.getSelectionRowRange(previousSelection);
11321
- const currentRange = this.getSelectionRowRange(currentSelection);
11322
- if (previousRange === null)
11323
- return currentRange;
11324
- if (currentRange === null)
11325
- return previousRange;
11326
- return {
11327
- firstRow: Math.min(previousRange.firstRow, currentRange.firstRow),
11328
- lastRow: Math.max(previousRange.lastRow, currentRange.lastRow)
11329
- };
11330
- }
11331
11729
  resetRowSelection(rowIdx) {
11332
11730
  const row = this._cells[rowIdx];
11333
11731
  if (!row)
@@ -11386,9 +11784,8 @@ class TextTableRenderable extends Renderable2 {
11386
11784
  }
11387
11785
  return Math.max(0, Math.floor(value));
11388
11786
  }
11389
- invalidateLayoutAndRaster(markYogaDirty = true) {
11787
+ invalidateLayout(markYogaDirty = true) {
11390
11788
  this._layoutDirty = true;
11391
- this._rasterDirty = true;
11392
11789
  this._cachedMeasureLayout = null;
11393
11790
  this._cachedMeasureWidth = undefined;
11394
11791
  if (markYogaDirty) {
@@ -11396,15 +11793,13 @@ class TextTableRenderable extends Renderable2 {
11396
11793
  }
11397
11794
  this.requestRender();
11398
11795
  }
11399
- invalidateRasterOnly() {
11400
- this._rasterDirty = true;
11401
- this.requestRender();
11402
- }
11403
11796
  }
11404
11797
 
11405
11798
  // src/renderables/markdown-parser.ts
11406
11799
  function parseMarkdownIncremental(newContent, prevState, trailingUnstable = 2) {
11407
- if (!prevState || prevState.tokens.length === 0) {
11800
+ if (trailingUnstable === 0 && prevState?.content === newContent && prevState.stableTokenCount === prevState.tokens.length)
11801
+ return prevState;
11802
+ if (!prevState || prevState.tokens.length === 0 || trailingUnstable === 0) {
11408
11803
  try {
11409
11804
  const tokens = x.lex(newContent, { gfm: true });
11410
11805
  return {
@@ -11434,19 +11829,12 @@ function parseMarkdownIncremental(newContent, prevState, trailingUnstable = 2) {
11434
11829
  }
11435
11830
  const stableTokens = prevState.tokens.slice(0, reuseCount);
11436
11831
  const remainingContent = newContent.slice(offset);
11437
- if (!remainingContent) {
11438
- return {
11439
- content: newContent,
11440
- tokens: stableTokens,
11441
- stableTokenCount: stableTokens.length
11442
- };
11443
- }
11444
11832
  try {
11445
11833
  const newTokens = x.lex(remainingContent, { gfm: true });
11446
11834
  return {
11447
11835
  content: newContent,
11448
11836
  tokens: [...stableTokens, ...newTokens],
11449
- stableTokenCount: trailingUnstable === 0 ? stableTokens.length + newTokens.length : stableTokens.length
11837
+ stableTokenCount: stableTokens.length
11450
11838
  };
11451
11839
  } catch {
11452
11840
  try {
@@ -11696,6 +12084,7 @@ class MarkdownRenderable extends Renderable2 {
11696
12084
  if (this._streaming !== value) {
11697
12085
  this.assertMutable();
11698
12086
  this._streaming = value;
12087
+ this._parseState = parseMarkdownIncremental(this._content, this._parseState, value ? 2 : 0);
11699
12088
  this.updateBlocks(true);
11700
12089
  }
11701
12090
  }
@@ -12228,13 +12617,16 @@ class MarkdownRenderable extends Renderable2 {
12228
12617
  return this.createTableBlock(token, id).renderable;
12229
12618
  return token.raw ? this.createMarkdownCodeRenderable(token.raw, id, 0, this._linkifyMarkdownChunks, undefined, this.createInitialStyledText(token)) : null;
12230
12619
  }
12620
+ getHorizontalRuleColor() {
12621
+ return this.getStyle("conceal")?.fg ?? this._fg ?? "#888888";
12622
+ }
12231
12623
  createHorizontalRuleRenderable(id, marginBottom = 0) {
12232
12624
  return new BoxRenderable2(this.ctx, {
12233
12625
  id,
12234
12626
  width: "100%",
12235
12627
  height: 1,
12236
12628
  border: ["top"],
12237
- borderColor: this.getStyle("conceal")?.fg ?? this._fg ?? "#888888",
12629
+ borderColor: this.getHorizontalRuleColor(),
12238
12630
  flexShrink: 0,
12239
12631
  marginBottom
12240
12632
  });
@@ -12808,6 +13200,8 @@ class MarkdownRenderable extends Renderable2 {
12808
13200
  return;
12809
13201
  }
12810
13202
  if (token.type === "hr") {
13203
+ if (state.renderable instanceof BoxRenderable2)
13204
+ state.renderable.borderColor = this.getHorizontalRuleColor();
12811
13205
  state.renderable.marginBottom = marginBottom;
12812
13206
  return;
12813
13207
  }
@@ -12843,12 +13237,13 @@ class MarkdownRenderable extends Renderable2 {
12843
13237
  state.tableContentCache = cache;
12844
13238
  return;
12845
13239
  }
13240
+ const raw = this._internalBlockMode === "top-level" ? this.getTopLevelBlockRaw(token) ?? token.raw : token.raw;
12846
13241
  if (state.renderable instanceof CodeRenderable2) {
12847
- this.applyMarkdownCodeRenderable(state.renderable, this.getTopLevelBlockRaw(token) ?? token.raw, marginBottom, undefined, this.createInitialStyledText(token));
13242
+ this.applyMarkdownCodeRenderable(state.renderable, raw, marginBottom, undefined, this.createInitialStyledText(token));
12848
13243
  return;
12849
13244
  }
12850
13245
  state.renderable.destroyRecursively();
12851
- const markdownRenderable = this.createMarkdownCodeRenderable(this.getTopLevelBlockRaw(token) ?? token.raw, `${this.id}-block-${index}`, marginBottom, this._linkifyMarkdownChunks, undefined, this.createInitialStyledText(token));
13246
+ const markdownRenderable = this.createMarkdownCodeRenderable(raw, `${this.id}-block-${index}`, marginBottom, this._linkifyMarkdownChunks, undefined, this.createInitialStyledText(token));
12852
13247
  this.add(markdownRenderable, index);
12853
13248
  state.renderable = markdownRenderable;
12854
13249
  }
@@ -12875,7 +13270,7 @@ class MarkdownRenderable extends Renderable2 {
12875
13270
  blockIndex++;
12876
13271
  continue;
12877
13272
  }
12878
- if (existing && existing.canUpdateInPlace && existing.token.type === block.token.type && this.canUpdateBlockRenderable(existing.renderable, block.token)) {
13273
+ if (existing && existing.canUpdateInPlace && existing.token.type === block.token.type && (block.token.type !== "table" || block.token.rows.length > 0 === existing.renderable instanceof TextTableRenderable)) {
12879
13274
  if (this._renderNode) {
12880
13275
  const custom = this.createTopLevelCustomRenderable(block, blockIndex);
12881
13276
  if (custom.renderable && !custom.canUpdateInPlace) {
@@ -12929,19 +13324,6 @@ class MarkdownRenderable extends Renderable2 {
12929
13324
  removed.renderable.destroyRecursively();
12930
13325
  }
12931
13326
  }
12932
- canUpdateBlockRenderable(renderable, token) {
12933
- if (token.type === "code")
12934
- return renderable instanceof CodeRenderable2;
12935
- if (token.type === "table")
12936
- return renderable instanceof TextTableRenderable;
12937
- if (token.type === "blockquote")
12938
- return renderable instanceof BoxRenderable2;
12939
- if (token.type === "list")
12940
- return renderable instanceof BoxRenderable2;
12941
- if (token.type === "hr")
12942
- return renderable instanceof BoxRenderable2;
12943
- return renderable instanceof CodeRenderable2;
12944
- }
12945
13327
  updateBlocks(forceTableRefresh = false) {
12946
13328
  if (this.isDestroyed)
12947
13329
  return;
@@ -12951,8 +13333,9 @@ class MarkdownRenderable extends Renderable2 {
12951
13333
  this._stableBlockCount = 0;
12952
13334
  return;
12953
13335
  }
12954
- const trailingUnstable = this._streaming ? 2 : 0;
12955
- this._parseState = parseMarkdownIncremental(this._content, this._parseState, trailingUnstable);
13336
+ if (this._parseState?.content !== this._content) {
13337
+ this._parseState = parseMarkdownIncremental(this._content, this._parseState, this._streaming ? 2 : 0);
13338
+ }
12956
13339
  const tokens = this._parseState.tokens;
12957
13340
  if (tokens.length === 0 && this._content.length > 0) {
12958
13341
  this.clearBlockStates();
@@ -12982,22 +13365,10 @@ class MarkdownRenderable extends Renderable2 {
12982
13365
  const token = blockTokens[i];
12983
13366
  const nextToken = blockTokens[i + 1];
12984
13367
  const existing = this._blockStates[blockIndex];
12985
- const shouldForceRefresh = forceTableRefresh;
12986
- if (existing && existing.token === token) {
12987
- if (shouldForceRefresh) {
12988
- this.updateBlockRenderable(existing, token, blockIndex, nextToken);
12989
- existing.tokenRaw = token.raw;
12990
- } else {
12991
- this.applyInterBlockMargin(existing, token, nextToken);
12992
- }
12993
- blockIndex++;
12994
- continue;
12995
- }
12996
- if (existing && existing.tokenRaw === token.raw && existing.token.type === token.type) {
13368
+ if (existing && existing.tokenRaw === token.raw && existing.token.type === token.type && (existing.canUpdateInPlace || !forceTableRefresh)) {
12997
13369
  existing.token = token;
12998
- if (shouldForceRefresh) {
12999
- this.updateBlockRenderable(existing, token, blockIndex, nextToken);
13000
- existing.tokenRaw = token.raw;
13370
+ if (forceTableRefresh) {
13371
+ this.updateBlockRenderable(existing, token, blockIndex, nextToken, true);
13001
13372
  } else {
13002
13373
  this.applyInterBlockMargin(existing, token, nextToken);
13003
13374
  }
@@ -13080,69 +13451,6 @@ class MarkdownRenderable extends Renderable2 {
13080
13451
  this._blockStates = [];
13081
13452
  this._stableBlockCount = 0;
13082
13453
  }
13083
- rerenderBlocks() {
13084
- if (this._internalBlockMode === "top-level") {
13085
- this.updateBlocks(true);
13086
- return;
13087
- }
13088
- for (let i = 0;i < this._blockStates.length; i++) {
13089
- const state = this._blockStates[i];
13090
- const marginBottom = this.getInterBlockMargin(state.token, this._blockStates[i + 1]?.token);
13091
- if (state.token.type === "code") {
13092
- this.applyCodeBlockRenderable(state.renderable, state.token, marginBottom);
13093
- continue;
13094
- }
13095
- if (state.token.type === "blockquote") {
13096
- this.applyBlockquoteRenderable(state.renderable, state.token, marginBottom);
13097
- continue;
13098
- }
13099
- if (state.token.type === "list") {
13100
- this.updateBlockRenderable(state, state.token, i, this._blockStates[i + 1]?.token, true);
13101
- continue;
13102
- }
13103
- if (state.token.type === "hr") {
13104
- state.renderable.marginBottom = marginBottom;
13105
- continue;
13106
- }
13107
- if (state.token.type === "table") {
13108
- const tableToken = state.token;
13109
- const { cache } = this.buildTableContentCache(tableToken, state.tableContentCache, true);
13110
- if (!cache) {
13111
- if (state.renderable instanceof CodeRenderable2) {
13112
- this.applyMarkdownCodeRenderable(state.renderable, tableToken.raw, marginBottom);
13113
- } else {
13114
- state.renderable.destroyRecursively();
13115
- const fallbackRenderable = this.createMarkdownCodeRenderable(tableToken.raw, `${this.id}-block-${i}`, marginBottom);
13116
- this.add(fallbackRenderable, i);
13117
- state.renderable = fallbackRenderable;
13118
- }
13119
- state.tableContentCache = undefined;
13120
- continue;
13121
- }
13122
- if (state.renderable instanceof TextTableRenderable) {
13123
- state.renderable.content = cache.content;
13124
- this.applyTableRenderableOptions(state.renderable, this.resolveTableRenderableOptions());
13125
- state.renderable.marginBottom = marginBottom;
13126
- state.tableContentCache = cache;
13127
- continue;
13128
- }
13129
- state.renderable.destroyRecursively();
13130
- const tableRenderable = this.createTextTableRenderable(cache.content, `${this.id}-block-${i}`, marginBottom);
13131
- this.add(tableRenderable, i);
13132
- state.renderable = tableRenderable;
13133
- state.tableContentCache = cache;
13134
- continue;
13135
- }
13136
- if (state.renderable instanceof CodeRenderable2) {
13137
- this.applyMarkdownCodeRenderable(state.renderable, this.getTopLevelBlockRaw(state.token) ?? state.token.raw, marginBottom, undefined, this.createInitialStyledText(state.token));
13138
- continue;
13139
- }
13140
- state.renderable.destroyRecursively();
13141
- const markdownRenderable = this.createMarkdownCodeRenderable(this.getTopLevelBlockRaw(state.token) ?? state.token.raw, `${this.id}-block-${i}`, marginBottom, this._linkifyMarkdownChunks, undefined, this.createInitialStyledText(state.token));
13142
- this.add(markdownRenderable, i);
13143
- state.renderable = markdownRenderable;
13144
- }
13145
- }
13146
13454
  clearCache() {
13147
13455
  this._parseState = null;
13148
13456
  this.clearBlockStates();
@@ -13152,7 +13460,7 @@ class MarkdownRenderable extends Renderable2 {
13152
13460
  refreshStyles() {
13153
13461
  this._styleDirty = false;
13154
13462
  this._ctx.nativeScene.lifecyclePasses.refresh(this);
13155
- this.rerenderBlocks();
13463
+ this.updateBlocks(true);
13156
13464
  this.requestRender();
13157
13465
  }
13158
13466
  markStyleDirty() {
@@ -13164,7 +13472,7 @@ class MarkdownRenderable extends Renderable2 {
13164
13472
  return;
13165
13473
  this._styleDirty = false;
13166
13474
  this._ctx.nativeScene.lifecyclePasses.refresh(this);
13167
- this.rerenderBlocks();
13475
+ this.updateBlocks(true);
13168
13476
  }
13169
13477
  _needsLifecyclePass() {
13170
13478
  if (this.onLifecyclePass !== this.applyStyleChanges)
@@ -14319,7 +14627,7 @@ class ScrollBoxRenderable extends BoxRenderable2 {
14319
14627
  horizontalScrollBar;
14320
14628
  verticalScrollBar;
14321
14629
  static defaultFocusable = true;
14322
- selectionListener;
14630
+ selectionListener = () => this.stopAutoScroll();
14323
14631
  autoScrollMouseX = 0;
14324
14632
  autoScrollMouseY = 0;
14325
14633
  autoScrollThresholdVertical = 3;
@@ -14454,15 +14762,6 @@ class ScrollBoxRenderable extends BoxRenderable2 {
14454
14762
  this._applyScrollArrows(1);
14455
14763
  this.content._assign({ ...forwardedContentPadding, ...contentOptions }, ScrollBoxContent.keys);
14456
14764
  this._refreshScrollHook();
14457
- this.selectionListener = () => {
14458
- if (this.isDestroyed)
14459
- return;
14460
- const selection = this._ctx.getSelection();
14461
- if (!selection || !selection.isDragging) {
14462
- this.stopAutoScroll();
14463
- }
14464
- };
14465
- this._ctx.on("selection", this.selectionListener);
14466
14765
  this.setNativeScenePaint();
14467
14766
  } catch (error) {
14468
14767
  this.abortConstruction(error, (run) => run(() => this.destroySelf()));
@@ -14766,12 +15065,15 @@ class ScrollBoxRenderable extends BoxRenderable2 {
14766
15065
  this.scrollAccumulatorY = 0;
14767
15066
  }
14768
15067
  startAutoScroll(mouseX, mouseY) {
15068
+ if (this.isDestroyed)
15069
+ return;
14769
15070
  this.stopAutoScroll();
14770
15071
  this.autoScrollMouseX = mouseX;
14771
15072
  this.autoScrollMouseY = mouseY;
14772
15073
  this.cachedAutoScrollSpeed = this.getAutoScrollSpeed(mouseX, mouseY);
14773
15074
  this.isAutoScrolling = true;
14774
15075
  this.live = true;
15076
+ this._ctx.on("selection", this.selectionListener);
14775
15077
  this.refreshNativeSceneHooks();
14776
15078
  }
14777
15079
  updateAutoScroll(mouseX, mouseY) {
@@ -14792,6 +15094,7 @@ class ScrollBoxRenderable extends BoxRenderable2 {
14792
15094
  this.autoScrollAccumulatorX = 0;
14793
15095
  this.autoScrollAccumulatorY = 0;
14794
15096
  if (wasAutoScrolling) {
15097
+ this._ctx.off("selection", this.selectionListener);
14795
15098
  this.live = false;
14796
15099
  this.refreshNativeSceneHooks();
14797
15100
  }
@@ -14915,13 +15218,10 @@ class ScrollBoxRenderable extends BoxRenderable2 {
14915
15218
  destroySelf() {
14916
15219
  if (!this.isFreed())
14917
15220
  this._scrollState();
14918
- const selectionListener = this.selectionListener;
14919
- this.selectionListener = undefined;
14920
15221
  this.layoutCallbacks = [];
14921
15222
  this.endBarPress();
14922
15223
  this.runCleanup((run) => {
14923
- if (selectionListener)
14924
- run(() => this._ctx.off("selection", selectionListener));
15224
+ run(() => this._ctx.off("selection", this.selectionListener));
14925
15225
  run(() => super.destroySelf());
14926
15226
  });
14927
15227
  }
@@ -14935,6 +15235,8 @@ for (const key of SCROLLBOX_PADDING_KEYS) {
14935
15235
  });
14936
15236
  }
14937
15237
  // src/renderables/Select.ts
15238
+ var transparent2 = RGBA2.fromValues(0, 0, 0, 0);
15239
+ var indicatorColor = parseColor2("#666666");
14938
15240
  var defaultSelectKeybindings = [
14939
15241
  { name: "up", action: "move-up" },
14940
15242
  { name: "k", action: "move-up" },
@@ -14995,7 +15297,7 @@ class SelectRenderable extends Renderable2 {
14995
15297
  fastScrollStep: 5
14996
15298
  };
14997
15299
  constructor(ctx, options) {
14998
- super(ctx, { ...options, buffered: true });
15300
+ super(ctx, options);
14999
15301
  try {
15000
15302
  this._options = options.options || [];
15001
15303
  const requestedIndex = options.selectedIndex ?? this._defaultOptions.selectedIndex;
@@ -15028,74 +15330,65 @@ class SelectRenderable extends Renderable2 {
15028
15330
  }
15029
15331
  }
15030
15332
  renderSelf(buffer, deltaTime) {
15031
- if (!this.visible || !this.frameBuffer)
15032
- return;
15033
- if (this.isDirty) {
15034
- this.refreshFrameBuffer();
15035
- }
15036
- }
15037
- refreshFrameBuffer() {
15038
- if (!this.frameBuffer)
15039
- return;
15333
+ const [x, y] = this._paintOrigin(buffer);
15334
+ const width = this._paintWidth;
15335
+ const height = this._paintHeight;
15040
15336
  const bgColor = this._focused ? this._focusedBackgroundColor : this._backgroundColor;
15041
- this.frameBuffer.clear(bgColor);
15042
- if (this._options.length === 0)
15043
- return;
15044
- const contentX = 0;
15045
- const contentY = 0;
15046
- const contentWidth = this.width;
15047
- const contentHeight = this.height;
15337
+ const selectedY = (this._selectedIndex - this.scrollOffset) * this.linesPerItem;
15338
+ const selectedHeight = this.linesPerItem - this._itemSpacing;
15339
+ const hole = this._options.length > 0 && selectedY + this.linesPerItem <= height && this._selectedBackgroundColor.a === 1;
15340
+ const top = hole ? selectedY : height;
15341
+ const bottom = hole ? selectedY + selectedHeight : height;
15342
+ const scrolls = this._showScrollIndicator && this._options.length > this.maxVisibleItems;
15343
+ const scrollPercent = this.scrollOffset / (this._options.length - this.maxVisibleItems);
15344
+ const indicatorY = scrolls ? y + 1 + Math.floor(scrollPercent * Math.max(1, height - 2)) : -1;
15345
+ const draw = (text, textX, textY, color) => {
15346
+ const end = textY === indicatorY ? x + width - 1 : x + width;
15347
+ buffer.drawTextFit(text, textX, textY, end - textX, color, transparent2);
15348
+ };
15349
+ buffer.pushScissorRect(x, y, width, height);
15350
+ if (buffer === this.frameBuffer)
15351
+ buffer.clear(bgColor);
15352
+ else {
15353
+ buffer.fillRect(x, y, width, top, bgColor);
15354
+ buffer.fillRect(x, y + bottom, width, height - bottom, bgColor);
15355
+ }
15048
15356
  const visibleOptions = this._options.slice(this.scrollOffset, this.scrollOffset + this.maxVisibleItems);
15049
15357
  for (let i = 0;i < visibleOptions.length; i++) {
15050
- const actualIndex = this.scrollOffset + i;
15051
15358
  const option = visibleOptions[i];
15052
- const isSelected = actualIndex === this._selectedIndex;
15053
- const itemY = contentY + i * this.linesPerItem;
15054
- if (itemY + this.linesPerItem - 1 >= contentY + contentHeight)
15359
+ const isSelected = this.scrollOffset + i === this._selectedIndex;
15360
+ const itemY = y + i * this.linesPerItem;
15361
+ if (itemY + this.linesPerItem - 1 >= y + height)
15055
15362
  break;
15056
15363
  if (isSelected) {
15057
- const contentHeight = this.linesPerItem - this._itemSpacing;
15058
- this.frameBuffer.fillRect(contentX, itemY, contentWidth, contentHeight, this._selectedBackgroundColor);
15364
+ buffer.fillRect(x, itemY, width, selectedHeight, this._selectedBackgroundColor);
15059
15365
  }
15060
15366
  const indicator = this._showSelectionIndicator ? isSelected ? "▶ " : " " : "";
15061
- const indicatorWidth = this._showSelectionIndicator ? 2 : 0;
15062
- const nameContent = `${indicator}${option.name}`;
15063
15367
  const baseTextColor = this._focused ? this._focusedTextColor : this._textColor;
15064
15368
  const nameColor = isSelected ? this._selectedTextColor : baseTextColor;
15065
- const textX = contentX + 1 + indicatorWidth;
15369
+ const textX = x + 1 + (this._showSelectionIndicator ? 2 : 0);
15066
15370
  if (this._font) {
15067
- if (indicator) {
15068
- this.frameBuffer.drawText(indicator, contentX + 1, itemY, nameColor);
15069
- }
15070
- renderFontToFrameBuffer2(this.frameBuffer, {
15371
+ if (indicator)
15372
+ draw(indicator, x + 1, itemY, nameColor);
15373
+ renderFontToFrameBuffer2(buffer, {
15071
15374
  text: option.name,
15072
15375
  x: textX,
15073
15376
  y: itemY,
15074
15377
  color: nameColor,
15075
- backgroundColor: isSelected ? this._selectedBackgroundColor : bgColor,
15378
+ backgroundColor: transparent2,
15076
15379
  font: this._font
15077
15380
  });
15078
15381
  } else {
15079
- this.frameBuffer.drawText(nameContent, contentX + 1, itemY, nameColor);
15382
+ draw(`${indicator}${option.name}`, x + 1, itemY, nameColor);
15080
15383
  }
15081
- if (this._showDescription && itemY + this.fontHeight < contentY + contentHeight) {
15384
+ if (this._showDescription && itemY + this.fontHeight < y + height) {
15082
15385
  const descColor = isSelected ? this._selectedDescriptionColor : this._descriptionColor;
15083
- this.frameBuffer.drawText(option.description, textX, itemY + this.fontHeight, descColor);
15386
+ draw(option.description, textX, itemY + this.fontHeight, descColor);
15084
15387
  }
15085
15388
  }
15086
- if (this._showScrollIndicator && this._options.length > this.maxVisibleItems) {
15087
- this.renderScrollIndicatorToFrameBuffer(contentX, contentY, contentWidth, contentHeight);
15088
- }
15089
- }
15090
- renderScrollIndicatorToFrameBuffer(contentX, contentY, contentWidth, contentHeight) {
15091
- if (!this.frameBuffer)
15092
- return;
15093
- const maxScrollOffset = this._options.length - this.maxVisibleItems;
15094
- const scrollPercent = this.scrollOffset / maxScrollOffset;
15095
- const indicatorHeight = Math.max(1, contentHeight - 2);
15096
- const indicatorY = contentY + 1 + Math.floor(scrollPercent * indicatorHeight);
15097
- const indicatorX = contentX + contentWidth - 1;
15098
- this.frameBuffer.drawText("█", indicatorX, indicatorY, parseColor2("#666666"));
15389
+ if (scrolls)
15390
+ buffer.drawText("█", x + width - 1, indicatorY, indicatorColor, transparent2);
15391
+ buffer.popScissorRect();
15099
15392
  }
15100
15393
  get options() {
15101
15394
  return this._options;
@@ -15296,6 +15589,8 @@ class SelectRenderable extends Renderable2 {
15296
15589
  }
15297
15590
  }
15298
15591
  // src/renderables/TabSelect.ts
15592
+ var transparent3 = RGBA2.fromValues(0, 0, 0, 0);
15593
+ var arrowColor = parseColor2("#AAAAAA");
15299
15594
  var defaultTabSelectKeybindings = [
15300
15595
  { name: "left", action: "move-left" },
15301
15596
  { name: "[", action: "move-left" },
@@ -15352,7 +15647,7 @@ class TabSelectRenderable extends Renderable2 {
15352
15647
  _keyBindings;
15353
15648
  constructor(ctx, options) {
15354
15649
  const calculatedHeight = calculateDynamicHeight(options.showUnderline ?? true, options.showDescription ?? true);
15355
- super(ctx, { ...options, height: calculatedHeight, buffered: true });
15650
+ super(ctx, { ...options, height: calculatedHeight });
15356
15651
  try {
15357
15652
  this._backgroundColor = RGBA2.clone(parseColor2(options.backgroundColor || defaultColors2.backgroundColor));
15358
15653
  this._hasBackgroundColor = !!options.backgroundColor;
@@ -15384,71 +15679,52 @@ class TabSelectRenderable extends Renderable2 {
15384
15679
  return kind === "height" ? this.calculateDynamicHeight() : super.defaultDimension(kind);
15385
15680
  }
15386
15681
  renderSelf(buffer, deltaTime) {
15387
- if (!this.visible || !this.frameBuffer)
15388
- return;
15389
- if (this.isDirty) {
15390
- this.refreshFrameBuffer();
15391
- }
15392
- }
15393
- refreshFrameBuffer() {
15394
- if (!this.frameBuffer)
15395
- return;
15682
+ const [x, y] = this._paintOrigin(buffer);
15683
+ const width = this._paintWidth;
15684
+ const height = this._paintHeight;
15396
15685
  const bgColor = this._focused ? this._focusedBackgroundColor : this._backgroundColor;
15397
- this.frameBuffer.clear(bgColor);
15398
- if (this._options.length === 0)
15399
- return;
15400
- const contentX = 0;
15401
- const contentY = 0;
15402
- const contentWidth = this.width;
15403
- const contentHeight = this.height;
15686
+ const selectedX = (this.selectedIndex - this.scrollOffset) * this._tabWidth;
15687
+ const selectedWidth = Math.min(this._tabWidth, width - selectedX);
15688
+ const selectedRows = this._showUnderline && height >= 2 ? 2 : 1;
15689
+ const hole = this._options.length > 0 && selectedX < width && this._selectedBackgroundColor.a === 1;
15690
+ const rows = hole ? selectedRows : 0;
15691
+ if (buffer === this.frameBuffer)
15692
+ buffer.clear(bgColor);
15693
+ else {
15694
+ buffer.fillRect(x, y, selectedX, rows, bgColor);
15695
+ buffer.fillRect(x + selectedX + selectedWidth, y, width - selectedX - selectedWidth, rows, bgColor);
15696
+ buffer.fillRect(x, y + rows, width, height - rows, bgColor);
15697
+ }
15404
15698
  const visibleOptions = this._options.slice(this.scrollOffset, this.scrollOffset + this.maxVisibleTabs);
15405
15699
  for (let i = 0;i < visibleOptions.length; i++) {
15406
- const actualIndex = this.scrollOffset + i;
15407
15700
  const option = visibleOptions[i];
15408
- const isSelected = actualIndex === this.selectedIndex;
15409
- const tabX = contentX + i * this._tabWidth;
15410
- if (tabX >= contentX + contentWidth)
15701
+ const isSelected = this.scrollOffset + i === this.selectedIndex;
15702
+ const tabX = x + i * this._tabWidth;
15703
+ if (tabX >= x + width)
15411
15704
  break;
15412
- const actualTabWidth = Math.min(this._tabWidth, contentWidth - i * this._tabWidth);
15413
- if (isSelected) {
15414
- this.frameBuffer.fillRect(tabX, contentY, actualTabWidth, 1, this._selectedBackgroundColor);
15415
- }
15705
+ const actualTabWidth = Math.min(this._tabWidth, width - i * this._tabWidth);
15416
15706
  const baseTextColor = this._focused ? this._focusedTextColor : this._textColor;
15417
15707
  const nameColor = isSelected ? this._selectedTextColor : baseTextColor;
15418
- const nameContent = this.truncateText(option.name, actualTabWidth - 2);
15419
- this.frameBuffer.drawText(nameContent, tabX + 1, contentY, nameColor);
15420
- if (isSelected && this._showUnderline && contentHeight >= 2) {
15421
- this.frameBuffer.drawText("▬".repeat(actualTabWidth), tabX, contentY + 1, nameColor, this._selectedBackgroundColor);
15708
+ if (isSelected) {
15709
+ buffer.fillRect(tabX, y, actualTabWidth, selectedRows, this._selectedBackgroundColor);
15422
15710
  }
15423
- }
15424
- if (this._showDescription && contentHeight >= (this._showUnderline ? 3 : 2)) {
15425
- const selectedOption = this.getSelectedOption();
15426
- if (selectedOption) {
15427
- const descriptionY = contentY + (this._showUnderline ? 2 : 1);
15428
- const descColor = this._selectedDescriptionColor;
15429
- const descContent = this.truncateText(selectedOption.description, contentWidth - 2);
15430
- this.frameBuffer.drawText(descContent, contentX + 1, descriptionY, descColor);
15711
+ buffer.drawTextFit(option.name, tabX + 1, y, actualTabWidth - 2, nameColor, transparent3, true);
15712
+ if (isSelected && selectedRows === 2) {
15713
+ buffer.drawText("▬".repeat(actualTabWidth), tabX, y + 1, nameColor, transparent3);
15431
15714
  }
15432
15715
  }
15433
- if (this._showScrollArrows && this._options.length > this.maxVisibleTabs) {
15434
- this.renderScrollArrowsToFrameBuffer(contentX, contentY, contentWidth, contentHeight);
15435
- }
15436
- }
15437
- truncateText(text, maxWidth) {
15438
- if (text.length <= maxWidth)
15439
- return text;
15440
- return text.substring(0, Math.max(0, maxWidth - 1)) + "…";
15441
- }
15442
- renderScrollArrowsToFrameBuffer(contentX, contentY, contentWidth, contentHeight) {
15443
- if (!this.frameBuffer)
15444
- return;
15445
- const hasMoreLeft = this.scrollOffset > 0;
15446
- const hasMoreRight = this.scrollOffset + this.maxVisibleTabs < this._options.length;
15447
- if (hasMoreLeft) {
15448
- this.frameBuffer.drawText("‹", contentX, contentY, parseColor2("#AAAAAA"));
15716
+ const selectedOption = this.getSelectedOption();
15717
+ if (selectedOption && this._showDescription && height >= (this._showUnderline ? 3 : 2)) {
15718
+ const descriptionY = y + (this._showUnderline ? 2 : 1);
15719
+ const description = selectedOption.description;
15720
+ buffer.drawTextFit(description, x + 1, descriptionY, width - 2, this._selectedDescriptionColor, transparent3, true);
15449
15721
  }
15450
- if (hasMoreRight) {
15451
- this.frameBuffer.drawText("›", contentX + contentWidth - 1, contentY, parseColor2("#AAAAAA"));
15722
+ if (this._showScrollArrows && this._options.length > this.maxVisibleTabs) {
15723
+ if (this.scrollOffset > 0)
15724
+ buffer.drawText("‹", x, y, arrowColor, transparent3);
15725
+ if (this.scrollOffset + this.maxVisibleTabs < this._options.length) {
15726
+ buffer.drawText("›", x + width - 1, y, arrowColor, transparent3);
15727
+ }
15452
15728
  }
15453
15729
  }
15454
15730
  setOptions(options) {
@@ -15633,28 +15909,19 @@ class TabSelectRenderable extends Renderable2 {
15633
15909
  }
15634
15910
  }
15635
15911
  // src/renderables/TimeToFirstDraw.ts
15636
- var graphemeSegmenter = new Intl.Segmenter(undefined, { granularity: "grapheme" });
15637
- function measureCellWidth(buffer, text) {
15912
+ var transparent4 = RGBA2.fromValues(0, 0, 0, 0);
15913
+ function fittedWidth(buffer, text, maxWidth) {
15914
+ if (/^[\x20-\x7e]*$/.test(text))
15915
+ return Math.min(text.length, maxWidth);
15638
15916
  const encoded = buffer.encodeUnicode(text);
15639
- if (!encoded)
15640
- return 0;
15641
- try {
15642
- return encoded.data.reduce((width, glyph) => width + glyph.width, 0);
15643
- } finally {
15644
- buffer.freeUnicode(encoded);
15645
- }
15646
- }
15647
- function truncateToCellWidth(buffer, text, maxWidth) {
15648
- let visibleText = "";
15649
- let visibleWidth = 0;
15650
- for (const { segment } of graphemeSegmenter.segment(text)) {
15651
- const segmentWidth = measureCellWidth(buffer, segment);
15652
- if (visibleWidth + segmentWidth > maxWidth)
15917
+ let width = 0;
15918
+ for (const glyph of encoded.data) {
15919
+ if (width + glyph.width > maxWidth)
15653
15920
  break;
15654
- visibleText += segment;
15655
- visibleWidth += segmentWidth;
15921
+ width += glyph.width;
15656
15922
  }
15657
- return { text: visibleText, width: visibleWidth };
15923
+ buffer.freeUnicode(encoded);
15924
+ return width;
15658
15925
  }
15659
15926
 
15660
15927
  class TimeToFirstDrawRenderable extends Renderable2 {
@@ -15712,10 +15979,9 @@ class TimeToFirstDrawRenderable extends Renderable2 {
15712
15979
  }
15713
15980
  const content = `${this.label}: ${this._runtimeMs.toFixed(this.precision)}ms`;
15714
15981
  const maxWidth = Math.max(this.width, 1);
15715
- const visibleContent = truncateToCellWidth(buffer, content, maxWidth);
15716
15982
  const [x, y] = this._paintOrigin(buffer);
15717
- const centeredX = x + Math.max(0, Math.floor((maxWidth - visibleContent.width) / 2));
15718
- buffer.drawText(visibleContent.text, centeredX, y, this.textColor);
15983
+ const width = fittedWidth(buffer, content, maxWidth);
15984
+ buffer.drawTextFit(content, x + Math.floor((maxWidth - width) / 2), y, width, this.textColor, transparent4);
15719
15985
  }
15720
15986
  normalizePrecision(value) {
15721
15987
  if (!Number.isFinite(value)) {
@@ -15885,6 +16151,7 @@ export {
15885
16151
  Timeline2 as Timeline,
15886
16152
  TreeSitterClient2 as TreeSitterClient,
15887
16153
  VRenderable,
16154
+ VideoRenderable,
15888
16155
  VignetteEffect,
15889
16156
  exports_yoga as Yoga,
15890
16157
  acquireSessionBufferLease2 as acquireSessionBufferLease,
@@ -15925,6 +16192,7 @@ export {
15925
16192
  buildKittyKeyboardFlags2 as buildKittyKeyboardFlags,
15926
16193
  buildTerminalPaletteSignature2 as buildTerminalPaletteSignature,
15927
16194
  capture2 as capture,
16195
+ checkCrop2 as checkCrop,
15928
16196
  clearEnvCache2 as clearEnvCache,
15929
16197
  convertGlobalToLocalSelection2 as convertGlobalToLocalSelection,
15930
16198
  convertThemeToStyles,
@@ -16019,6 +16287,7 @@ export {
16019
16287
  resolveRenderLib2 as resolveRenderLib,
16020
16288
  reverse2 as reverse,
16021
16289
  rgbToHex2 as rgbToHex,
16290
+ sameCrop2 as sameCrop,
16022
16291
  scrollUnitSize,
16023
16292
  setRenderLibPath2 as setRenderLibPath,
16024
16293
  setupAudio,
@@ -16037,5 +16306,5 @@ export {
16037
16306
  yellow2 as yellow
16038
16307
  };
16039
16308
 
16040
- //# debugId=41B4409C26AC698364756E2164756E21
16309
+ //# debugId=CD1EAF87C395884164756E2164756E21
16041
16310
  //# sourceMappingURL=index.node.js.map