@opentui/core 0.7.0 → 0.8.1

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 (54) hide show
  1. package/NativeScene.d.ts +18 -4
  2. package/NativeSession.d.ts +22 -2
  3. package/Renderable.d.ts +20 -2
  4. package/animation/Timeline.d.ts +9 -0
  5. package/buffer.d.ts +8 -2
  6. package/{chunk-bun-zevtbcf6.js → chunk-bun-ved2tpxm.js} +834 -320
  7. package/chunk-bun-ved2tpxm.js.map +70 -0
  8. package/{chunk-bun-qkpm62w1.js → chunk-bun-wdetc10w.js} +483 -29
  9. package/chunk-bun-wdetc10w.js.map +35 -0
  10. package/{chunk-node-mzgnr3sw.js → chunk-node-m8mjyx7h.js} +483 -29
  11. package/chunk-node-m8mjyx7h.js.map +34 -0
  12. package/{chunk-node-7bcmqh18.js → chunk-node-tpjmjvn7.js} +834 -320
  13. package/chunk-node-tpjmjvn7.js.map +70 -0
  14. package/edit-buffer.d.ts +4 -0
  15. package/index.bun.js +1453 -859
  16. package/index.bun.js.map +15 -13
  17. package/index.d.ts +1 -1
  18. package/index.node.js +1453 -859
  19. package/index.node.js.map +16 -12
  20. package/lib/extmarks.d.ts +3 -1
  21. package/lib/stdin-parser-native.d.ts +2 -0
  22. package/lib/stdin-parser.d.ts +2 -0
  23. package/lib/terminal-capability-detection.d.ts +6 -1
  24. package/native-abi.generated.d.ts +478 -6
  25. package/package.json +9 -9
  26. package/renderables/FrameBuffer.d.ts +1 -0
  27. package/renderables/Image.d.ts +13 -1
  28. package/renderables/LineNumberRenderable.d.ts +1 -1
  29. package/renderables/Markdown.d.ts +1 -1
  30. package/renderables/ScrollBar.d.ts +6 -0
  31. package/renderables/ScrollBox.d.ts +84 -44
  32. package/renderables/ScrollBoxParts.d.ts +165 -0
  33. package/renderables/Select.d.ts +0 -2
  34. package/renderables/TabSelect.d.ts +0 -3
  35. package/renderables/TextTable.d.ts +1 -8
  36. package/renderables/Video.d.ts +126 -0
  37. package/renderables/index.d.ts +2 -1
  38. package/renderer-theme-mode.d.ts +1 -6
  39. package/renderer.d.ts +44 -5
  40. package/testing/test-renderer.d.ts +2 -0
  41. package/testing.bun.js +7 -6
  42. package/testing.bun.js.map +3 -3
  43. package/testing.js +7 -6
  44. package/testing.js.map +3 -3
  45. package/types.d.ts +11 -0
  46. package/yoga.bun.js +1 -1
  47. package/yoga.internal.d.ts +3 -3
  48. package/yoga.js +1 -1
  49. package/zig-structs.d.ts +1 -0
  50. package/zig.d.ts +132 -10
  51. package/chunk-bun-qkpm62w1.js.map +0 -35
  52. package/chunk-bun-zevtbcf6.js.map +0 -70
  53. package/chunk-node-7bcmqh18.js.map +0 -70
  54. package/chunk-node-mzgnr3sw.js.map +0 -34
package/index.bun.js CHANGED
@@ -7,7 +7,6 @@ import {
7
7
  generateEnvMarkdown2,
8
8
  generateEnvColored2,
9
9
  env2,
10
- stringWidth,
11
10
  resolveBundledFilePath2,
12
11
  TextAttributes2,
13
12
  ATTRIBUTE_BASE_BITS2,
@@ -67,6 +66,12 @@ import {
67
66
  bg2,
68
67
  link2,
69
68
  t2,
69
+ YogaEnumKind,
70
+ YogaFloatKind,
71
+ YogaValueKind,
72
+ sceneSetEnum,
73
+ sceneSetFloat,
74
+ sceneSetValue,
70
75
  SpanInfoStruct,
71
76
  NativeAudioStreamFormat2,
72
77
  NativeAudioStreamState2,
@@ -85,11 +90,13 @@ import {
85
90
  NativeEditorSelectionOperation2,
86
91
  NativeEditorPositionQuery2,
87
92
  NativeEditEvent2,
93
+ NativeStyleFlags,
88
94
  NATIVE_EDGE_NONE2,
89
95
  NativeBorder2,
90
96
  NativeSceneHook2,
91
97
  NativeSceneFrame2,
92
98
  NativeScenePaintPhase2,
99
+ emptySceneScrollState,
93
100
  NATIVE_BUFFER_TEXT_BYTES_MAX2,
94
101
  NativeSessionState2,
95
102
  NativeSessionRenderStatus2,
@@ -108,9 +115,12 @@ import {
108
115
  FFIRenderLib2,
109
116
  setRenderLibPath2,
110
117
  resolveRenderLib2,
118
+ Edge2,
119
+ FlexDirection2,
120
+ Gutter2,
111
121
  MeasureMode2,
112
122
  exports_yoga
113
- } from "./chunk-bun-qkpm62w1.js";
123
+ } from "./chunk-bun-wdetc10w.js";
114
124
  import {
115
125
  isValidBorderStyle2,
116
126
  parseBorderStyle2,
@@ -218,6 +228,8 @@ import {
218
228
  NativeImage2,
219
229
  NativeImagePool2,
220
230
  resolveImageRenderProtocol2,
231
+ checkCrop2,
232
+ sameCrop2,
221
233
  ImageRenderable2,
222
234
  isTextNodeRenderable2,
223
235
  TextNodeRenderable2,
@@ -242,7 +254,7 @@ import {
242
254
  CliRenderEvents2,
243
255
  RendererControlState2,
244
256
  CliRenderer2
245
- } from "./chunk-bun-zevtbcf6.js";
257
+ } from "./chunk-bun-ved2tpxm.js";
246
258
  // src/syntax-style.ts
247
259
  function cloneStyle(style) {
248
260
  return {
@@ -6076,6 +6088,7 @@ class VRenderable extends Renderable2 {
6076
6088
  // src/renderables/LineNumberRenderable.ts
6077
6089
  var DEFAULT_GUTTER_FG = "#888888";
6078
6090
  var DEFAULT_GUTTER_BG = "transparent";
6091
+ var transparent = RGBA2.fromValues(0, 0, 0, 0);
6079
6092
  function cloneLineSign(sign) {
6080
6093
  return {
6081
6094
  ...sign,
@@ -6098,8 +6111,8 @@ class GutterRenderable extends Renderable2 {
6098
6111
  _maxBeforeWidth = 0;
6099
6112
  _maxAfterWidth = 0;
6100
6113
  _lastKnownLineCount = 0;
6101
- _paintedSources;
6102
- _paintedSourceOffset = 0;
6114
+ _signWidths = new Map;
6115
+ _signWidthMethod;
6103
6116
  constructor(ctx, target, options) {
6104
6117
  super(ctx, {
6105
6118
  id: options.id,
@@ -6124,7 +6137,10 @@ class GutterRenderable extends Renderable2 {
6124
6137
  this.setupMeasureFunc();
6125
6138
  this.onLifecyclePass = () => {
6126
6139
  const currentLineCount = this.target.virtualLineCount;
6127
- if (currentLineCount !== this._lastKnownLineCount) {
6140
+ const signsStale = this._ctx.widthMethod !== this._signWidthMethod;
6141
+ if (signsStale)
6142
+ this.calculateSignWidths();
6143
+ if (currentLineCount !== this._lastKnownLineCount || signsStale) {
6128
6144
  this._lastKnownLineCount = currentLineCount;
6129
6145
  this.invalidateIntrinsicSize();
6130
6146
  this.requestRender();
@@ -6175,16 +6191,30 @@ class GutterRenderable extends Renderable2 {
6175
6191
  calculateSignWidths() {
6176
6192
  this._maxBeforeWidth = 0;
6177
6193
  this._maxAfterWidth = this._layout.minAfterWidth;
6194
+ this._signWidths.clear();
6195
+ this._signWidthMethod = this._ctx.widthMethod;
6178
6196
  for (const sign of this._lineSigns.values()) {
6179
- if (sign.before) {
6180
- const width = stringWidth(sign.before);
6181
- this._maxBeforeWidth = Math.max(this._maxBeforeWidth, width);
6182
- }
6183
- if (sign.after) {
6184
- const width = stringWidth(sign.after);
6185
- this._maxAfterWidth = Math.max(this._maxAfterWidth, width);
6186
- }
6197
+ if (sign.before)
6198
+ this._maxBeforeWidth = Math.max(this._maxBeforeWidth, this.signWidth(sign.before));
6199
+ if (sign.after)
6200
+ this._maxAfterWidth = Math.max(this._maxAfterWidth, this.signWidth(sign.after));
6201
+ }
6202
+ }
6203
+ signWidth(sign) {
6204
+ if (/^[\x20-\x7e]*$/.test(sign))
6205
+ return sign.length;
6206
+ let width = this._signWidths.get(sign);
6207
+ if (width !== undefined)
6208
+ return width;
6209
+ const { context, renderLib } = this._ctx.nativeScene.driver;
6210
+ const unicode = renderLib.createContextUnicode(context, sign, this._signWidthMethod);
6211
+ try {
6212
+ width = renderLib.getContextUnicode(context, unicode).reduce((sum, glyph) => sum + glyph.width, 0);
6213
+ } finally {
6214
+ renderLib.destroyContextUnicode(context, unicode);
6187
6215
  }
6216
+ this._signWidths.set(sign, width);
6217
+ return width;
6188
6218
  }
6189
6219
  calculateWidth() {
6190
6220
  const totalLines = Math.max(this.target.lineCount, this.target.virtualLineCount);
@@ -6240,81 +6270,48 @@ class GutterRenderable extends Renderable2 {
6240
6270
  getLineSigns() {
6241
6271
  return this._lineSigns;
6242
6272
  }
6243
- createFrameBuffer() {}
6244
- handleFrameBufferResize() {}
6245
6273
  renderSelf(buffer) {
6246
- const x = Math.trunc(this._screenX);
6247
- const y = Math.trunc(this._screenY);
6274
+ const [x, y] = this._paintOrigin(buffer);
6248
6275
  const start = Math.max(0, -y);
6249
6276
  const end = Math.min(this.height, buffer.height - y);
6250
6277
  if (end <= start || x >= buffer.width || x + this.width <= 0)
6251
6278
  return;
6252
- if (!this.frameBuffer) {
6253
- this.frameBuffer = OptimizedBuffer2.create(this.width, end - start, this._ctx.widthMethod, {
6254
- respectAlpha: true,
6255
- id: `framebuffer-${this.id}`,
6256
- owner: this._ctx.nativeScene
6257
- });
6258
- } else if (this.frameBuffer.width !== this.width || this.frameBuffer.height !== end - start) {
6259
- this.frameBuffer.resize(this.width, end - start);
6260
- this._paintedSources = undefined;
6261
- }
6262
- this.refreshFrameBuffer(this.frameBuffer, Math.trunc(this.target.scrollY) + start);
6263
- this.markClean();
6264
- buffer.drawFrameBuffer(x, y + start, this.frameBuffer);
6265
- }
6266
- refreshFrameBuffer(buffer, startLine) {
6279
+ const startLine = Math.trunc(this.target.scrollY) + start;
6267
6280
  const sourceStart = Math.max(0, startLine - 1);
6268
6281
  const sourceOffset = startLine - sourceStart;
6269
- const sources = getLineSources(this.target, sourceStart, buffer.height + sourceOffset);
6270
- const paintedSources = this._paintedSources;
6271
- if (!this.isDirty && sourceOffset === this._paintedSourceOffset && paintedSources && sources.length === paintedSources.length && sources.every((source, i) => source === paintedSources[i])) {
6272
- return;
6273
- }
6274
- buffer.clear(this._bg);
6282
+ const sources = getLineSources(this.target, sourceStart, end - start + sourceOffset);
6275
6283
  let lastSource = sourceOffset > 0 ? sources[0] : -1;
6276
- for (let i = 0;i < buffer.height; i++) {
6277
- const visualLineIndex = sourceOffset + i;
6278
- if (visualLineIndex >= sources.length)
6279
- break;
6280
- const logicalLine = sources[visualLineIndex];
6281
- const lineBg = this._lineColorsGutter.get(logicalLine) ?? this._bg;
6282
- if (lineBg !== this._bg) {
6283
- buffer.fillRect(0, i, this.width, 1, lineBg);
6284
- }
6285
- if (logicalLine === lastSource) {} else {
6286
- let currentX = 0;
6284
+ for (let i = sourceOffset;i < end - start + sourceOffset; i++) {
6285
+ const row = y + start + i - sourceOffset;
6286
+ const logicalLine = sources[i];
6287
+ const lineBg = this._lineColorsGutter.get(logicalLine);
6288
+ if (!lineBg || lineBg.a < 1)
6289
+ buffer.fillRect(x, row, this.width, 1, this._bg);
6290
+ if (lineBg)
6291
+ buffer.fillRect(x, row, this.width, 1, lineBg);
6292
+ if (logicalLine !== undefined && logicalLine !== lastSource) {
6287
6293
  const sign = this._lineSigns.get(logicalLine);
6288
6294
  if (sign?.before) {
6289
- const beforeWidth = stringWidth(sign.before);
6290
- const padding = this._maxBeforeWidth - beforeWidth;
6291
- currentX += padding;
6295
+ const beforeX = x + this._maxBeforeWidth - this.signWidth(sign.before);
6292
6296
  const beforeColor = sign.beforeColor ? parseColor2(sign.beforeColor) : this._fg;
6293
- buffer.drawText(sign.before, currentX, i, beforeColor, lineBg);
6294
- currentX += beforeWidth;
6295
- } else if (this._maxBeforeWidth > 0) {
6296
- currentX += this._maxBeforeWidth;
6297
+ buffer.drawText(sign.before, beforeX, row, beforeColor, transparent);
6297
6298
  }
6298
6299
  if (!this._hideLineNumbers.has(logicalLine)) {
6299
6300
  const customLineNum = this._lineNumbers.get(logicalLine);
6300
- const lineNum = customLineNum !== undefined ? customLineNum : logicalLine + 1 + this._lineNumberOffset;
6301
- const lineNumStr = lineNum.toString();
6302
- const lineNumWidth = lineNumStr.length;
6303
- const lineNumX = this.width - this._maxAfterWidth - this._layout.paddingRight - lineNumWidth;
6301
+ const lineNumStr = (customLineNum ?? logicalLine + 1 + this._lineNumberOffset).toString();
6302
+ const lineNumX = this.width - this._maxAfterWidth - this._layout.paddingRight - lineNumStr.length;
6304
6303
  if (lineNumX >= this._maxBeforeWidth + this._layout.paddingLeft) {
6305
- buffer.drawText(lineNumStr, lineNumX, i, this._fg, lineBg);
6304
+ buffer.drawText(lineNumStr, x + lineNumX, row, this._fg, transparent);
6306
6305
  }
6307
6306
  }
6308
6307
  if (sign?.after) {
6309
- const afterX = this.width - this._layout.paddingRight - this._maxAfterWidth;
6308
+ const afterX = x + this.width - this._layout.paddingRight - this._maxAfterWidth;
6310
6309
  const afterColor = sign.afterColor ? parseColor2(sign.afterColor) : this._fg;
6311
- buffer.drawText(sign.after, afterX, i, afterColor, lineBg);
6310
+ buffer.drawText(sign.after, afterX, row, afterColor, transparent);
6312
6311
  }
6313
6312
  }
6314
6313
  lastSource = logicalLine;
6315
6314
  }
6316
- this._paintedSources = sources.slice();
6317
- this._paintedSourceOffset = sourceOffset;
6318
6315
  }
6319
6316
  }
6320
6317
  function getLineSources(target, startLine, lineCount) {
@@ -6506,10 +6503,10 @@ class LineNumberRenderable extends Renderable2 {
6506
6503
  renderSelf(buffer) {
6507
6504
  if (!this.target || !this.gutter || this._lineColorsContent.size === 0)
6508
6505
  return;
6509
- const y = Math.trunc(this.y);
6506
+ const [x, y] = this._paintOrigin(buffer);
6510
6507
  const start = Math.max(0, -y);
6511
6508
  const end = Math.min(this.height, buffer.height - y);
6512
- if (end <= start || this.x >= buffer.width || this.x + this.width <= 0)
6509
+ if (end <= start || x >= buffer.width || x + this.width <= 0)
6513
6510
  return;
6514
6511
  const sources = getLineSources(this.target, Math.trunc(this.target.scrollY) + start, end - start);
6515
6512
  const gutterWidth = this.gutter.visible ? this.gutter.width : 0;
@@ -6518,7 +6515,7 @@ class LineNumberRenderable extends Renderable2 {
6518
6515
  const logicalLine = sources[i];
6519
6516
  const lineBg = this._lineColorsContent.get(logicalLine);
6520
6517
  if (lineBg) {
6521
- buffer.fillRect(this.x + gutterWidth, y + start + i, contentWidth, 1, lineBg);
6518
+ buffer.fillRect(x + gutterWidth, y + start + i, contentWidth, 1, lineBg);
6522
6519
  }
6523
6520
  }
6524
6521
  }
@@ -9032,6 +9029,472 @@ class InputRenderable extends TextareaRenderable {
9032
9029
  }
9033
9030
  set initialValue(value) {}
9034
9031
  }
9032
+ // src/renderables/Video.ts
9033
+ function validateVolume(value) {
9034
+ if (!Number.isFinite(value) || value < 0 || value > 340282346638528860000000000000000000000)
9035
+ throw new RangeError("volume must be a finite, non-negative 32-bit float");
9036
+ }
9037
+ function validateAvSyncOffset(value) {
9038
+ if (!Number.isFinite(value) || Math.abs(value) > 60000)
9039
+ throw new RangeError("avSyncOffsetMs must be from -60000 to 60000");
9040
+ }
9041
+ function validateMaxFps(value) {
9042
+ if (!Number.isInteger(value) || value < 1 || value > 120)
9043
+ throw new RangeError("maxFps must be an integer from 1 to 120");
9044
+ }
9045
+ function toMicroseconds(seconds, label) {
9046
+ const value = Math.round(seconds * 1e6);
9047
+ if (!Number.isFinite(seconds) || !Number.isSafeInteger(value))
9048
+ throw new RangeError(`${label} must be finite`);
9049
+ return BigInt(value);
9050
+ }
9051
+
9052
+ class VideoRenderable extends Renderable2 {
9053
+ static nativeIntegration = {
9054
+ kind: "video",
9055
+ body: { native: this.prototype.renderSelf, buffered: true },
9056
+ bufferComposition: "native"
9057
+ };
9058
+ _source;
9059
+ _fit;
9060
+ _crop;
9061
+ _loop;
9062
+ _audio;
9063
+ _muted;
9064
+ _volume;
9065
+ _avSyncOffsetMs;
9066
+ _maxFps;
9067
+ _autoplay;
9068
+ _metadata = null;
9069
+ _playRequested = false;
9070
+ stopTick;
9071
+ _opens = 0;
9072
+ onReady;
9073
+ onError;
9074
+ onEnd;
9075
+ onPlay;
9076
+ onPause;
9077
+ onSeek;
9078
+ onTimeUpdate;
9079
+ constructor(ctx, options) {
9080
+ super(ctx, options);
9081
+ try {
9082
+ this._fit = options.fit ?? "fit";
9083
+ this._loop = options.loop ?? false;
9084
+ this._audio = options.audio ?? true;
9085
+ this._muted = options.muted ?? false;
9086
+ this._volume = options.volume ?? 1;
9087
+ validateVolume(this._volume);
9088
+ this._avSyncOffsetMs = options.avSyncOffsetMs ?? 0;
9089
+ validateAvSyncOffset(this._avSyncOffsetMs);
9090
+ this._maxFps = options.maxFps ?? 30;
9091
+ validateMaxFps(this._maxFps);
9092
+ this._autoplay = options.autoplay ?? false;
9093
+ this.onReady = options.onReady;
9094
+ this.onError = options.onError;
9095
+ this.onEnd = options.onEnd;
9096
+ this.onPlay = options.onPlay;
9097
+ this.onPause = options.onPause;
9098
+ this.onSeek = options.onSeek;
9099
+ this.onTimeUpdate = options.onTimeUpdate;
9100
+ this.setNativeSceneVideo();
9101
+ if (options.source !== undefined)
9102
+ this.source = options.source;
9103
+ this.crop = options.crop;
9104
+ } catch (error) {
9105
+ this.abortConstruction(error, () => this.destroySelf());
9106
+ }
9107
+ }
9108
+ get source() {
9109
+ return this._source;
9110
+ }
9111
+ set source(value) {
9112
+ value ??= undefined;
9113
+ if (value === this._source && !this.failed() || this.isDestroyed)
9114
+ return;
9115
+ this.open(value, this.playing);
9116
+ }
9117
+ open(value, resume) {
9118
+ this._opens++;
9119
+ this._source = value;
9120
+ this._metadata = null;
9121
+ this._playRequested = resume;
9122
+ const native = this.native();
9123
+ try {
9124
+ const info = native.lib.videoOpen(native.context, native.node, value ?? "", this._audio);
9125
+ if (!value)
9126
+ return;
9127
+ this._playRequested = resume || this._autoplay;
9128
+ this._metadata = {
9129
+ width: info.width,
9130
+ height: info.height,
9131
+ fps: info.fpsDen > 0 ? info.fpsNum / info.fpsDen : 0,
9132
+ duration: Number(info.durationUs) / 1e6,
9133
+ hasAudio: info.hasAudio
9134
+ };
9135
+ native.lib.videoSetLoop(native.context, native.node, this._loop);
9136
+ native.lib.videoSetMuted(native.context, native.node, this._muted);
9137
+ native.lib.videoSetVolume(native.context, native.node, this._volume);
9138
+ native.lib.videoSetAvSyncOffset(native.context, native.node, toMicroseconds(this._avSyncOffsetMs / 1000, "avSyncOffsetMs"));
9139
+ native.lib.videoSetMaxFps(native.context, native.node, this._maxFps);
9140
+ const metadata = { ...this._metadata };
9141
+ this.afterOpen(() => {
9142
+ this.onReady?.(metadata);
9143
+ this.startRequested();
9144
+ try {
9145
+ if (this._crop)
9146
+ checkCrop2(this._crop, metadata.width, metadata.height);
9147
+ } catch (error) {
9148
+ this.reportError(error, "");
9149
+ }
9150
+ });
9151
+ } catch (error) {
9152
+ this._metadata = null;
9153
+ this._playRequested = false;
9154
+ const detail = this.errorDetail("");
9155
+ this.afterOpen(() => this.reportError(error, detail));
9156
+ } finally {
9157
+ this.syncPlayback();
9158
+ this.requestRender();
9159
+ }
9160
+ }
9161
+ get fit() {
9162
+ return this._fit;
9163
+ }
9164
+ set fit(value) {
9165
+ const next = value ?? "fit";
9166
+ if (this._fit === next || this.isDestroyed)
9167
+ return;
9168
+ this.setNativeSceneVideo(next);
9169
+ this._fit = next;
9170
+ this.requestRender();
9171
+ }
9172
+ get crop() {
9173
+ return this._crop && { ...this._crop };
9174
+ }
9175
+ set crop(value) {
9176
+ if (sameCrop2(this._crop, value ?? undefined) || this.isDestroyed)
9177
+ return;
9178
+ const next = this.acceptCrop(value ?? undefined);
9179
+ if (next === null)
9180
+ return;
9181
+ this._ctx.nativeScene.setCrop(this, next);
9182
+ this._crop = next;
9183
+ this.requestRender();
9184
+ }
9185
+ get loop() {
9186
+ return this._loop;
9187
+ }
9188
+ set loop(value) {
9189
+ const next = value ?? false;
9190
+ if (this._loop === next || this.isDestroyed)
9191
+ return;
9192
+ if (this.applyOption((native) => native.lib.videoSetLoop(native.context, native.node, next)))
9193
+ this._loop = next;
9194
+ }
9195
+ get audio() {
9196
+ return this._audio;
9197
+ }
9198
+ set audio(value) {
9199
+ const next = value ?? true;
9200
+ if (this._audio === next || this.isDestroyed)
9201
+ return;
9202
+ this._audio = next;
9203
+ if (this._metadata)
9204
+ this.open(this._source, this.playing);
9205
+ }
9206
+ get muted() {
9207
+ return this._muted;
9208
+ }
9209
+ set muted(value) {
9210
+ const next = value ?? false;
9211
+ if (this._muted === next || this.isDestroyed)
9212
+ return;
9213
+ if (this.applyOption((native) => native.lib.videoSetMuted(native.context, native.node, next)))
9214
+ this._muted = next;
9215
+ }
9216
+ get volume() {
9217
+ return this._volume;
9218
+ }
9219
+ set volume(value) {
9220
+ const next = value ?? 1;
9221
+ validateVolume(next);
9222
+ if (this._volume === next || this.isDestroyed)
9223
+ return;
9224
+ if (this.applyOption((native) => native.lib.videoSetVolume(native.context, native.node, next)))
9225
+ this._volume = next;
9226
+ }
9227
+ get avSyncOffsetMs() {
9228
+ return this._avSyncOffsetMs;
9229
+ }
9230
+ set avSyncOffsetMs(value) {
9231
+ const next = value ?? 0;
9232
+ validateAvSyncOffset(next);
9233
+ if (this._avSyncOffsetMs === next || this.isDestroyed)
9234
+ return;
9235
+ const offset = toMicroseconds(next / 1000, "avSyncOffsetMs");
9236
+ if (this.applyOption((native) => native.lib.videoSetAvSyncOffset(native.context, native.node, offset)))
9237
+ this._avSyncOffsetMs = next;
9238
+ }
9239
+ get maxFps() {
9240
+ return this._maxFps;
9241
+ }
9242
+ set maxFps(value) {
9243
+ const next = value ?? 30;
9244
+ validateMaxFps(next);
9245
+ if (this._maxFps === next || this.isDestroyed)
9246
+ return;
9247
+ if (!this.applyOption((native) => native.lib.videoSetMaxFps(native.context, native.node, next)))
9248
+ return;
9249
+ this._maxFps = next;
9250
+ this.syncPlayback();
9251
+ }
9252
+ get autoplay() {
9253
+ return this._autoplay;
9254
+ }
9255
+ set autoplay(value) {
9256
+ const next = value ?? false;
9257
+ if (this._autoplay === next || this.isDestroyed)
9258
+ return;
9259
+ this._autoplay = next;
9260
+ if (!next || !this._metadata)
9261
+ return;
9262
+ const requested = this.control((native) => {
9263
+ const state = native.lib.videoGetState(native.context, native.node);
9264
+ if (state.playing || state.ended || state.currentTimeUs !== 0n)
9265
+ return false;
9266
+ this._playRequested = true;
9267
+ });
9268
+ if (requested)
9269
+ this.afterOpen(() => this.startRequested());
9270
+ }
9271
+ get ready() {
9272
+ return this._metadata !== null;
9273
+ }
9274
+ get videoMetadata() {
9275
+ return this._metadata ? { ...this._metadata } : null;
9276
+ }
9277
+ get playing() {
9278
+ if (this.isDestroyed)
9279
+ return false;
9280
+ return this._playRequested || this._metadata !== null && this.readState().playing;
9281
+ }
9282
+ get paused() {
9283
+ return !this.playing;
9284
+ }
9285
+ get ended() {
9286
+ return this._metadata !== null && !this.isDestroyed && this.readState().ended;
9287
+ }
9288
+ get duration() {
9289
+ return this._metadata?.duration ?? 0;
9290
+ }
9291
+ get durationMs() {
9292
+ return this.duration * 1000;
9293
+ }
9294
+ get currentTime() {
9295
+ if (!this._metadata || this.isDestroyed)
9296
+ return 0;
9297
+ return Number(this.readState().currentTimeUs) / 1e6;
9298
+ }
9299
+ set currentTime(value) {
9300
+ if (value == null)
9301
+ return;
9302
+ this.seek(value);
9303
+ }
9304
+ get qualityTier() {
9305
+ if (!this._metadata || this.isDestroyed)
9306
+ return 0;
9307
+ return this.readState().qualityTier;
9308
+ }
9309
+ get currentTimeMs() {
9310
+ return this.currentTime * 1000;
9311
+ }
9312
+ play() {
9313
+ if (this.isDestroyed || this._playRequested)
9314
+ return;
9315
+ if (!this._metadata) {
9316
+ if (this._source !== undefined)
9317
+ this.open(this._source, true);
9318
+ else
9319
+ this._playRequested = true;
9320
+ return;
9321
+ }
9322
+ const started = this.control((native) => {
9323
+ if (native.lib.videoGetState(native.context, native.node).playing)
9324
+ return false;
9325
+ native.lib.videoCall(native.context, native.node, "ot_video_play");
9326
+ });
9327
+ if (started)
9328
+ this.onPlay?.();
9329
+ }
9330
+ resume() {
9331
+ this.play();
9332
+ }
9333
+ pause() {
9334
+ if (this.isDestroyed)
9335
+ return;
9336
+ const requested = this._playRequested;
9337
+ this._playRequested = false;
9338
+ if (!this._metadata)
9339
+ return;
9340
+ const paused = this.control((native) => {
9341
+ if (requested)
9342
+ return;
9343
+ if (!native.lib.videoGetState(native.context, native.node).playing)
9344
+ return false;
9345
+ native.lib.videoCall(native.context, native.node, "ot_video_pause");
9346
+ });
9347
+ if (!paused)
9348
+ return;
9349
+ const time = this.currentTime;
9350
+ this.onPause?.();
9351
+ this.onTimeUpdate?.(time);
9352
+ }
9353
+ toggle() {
9354
+ if (this.playing)
9355
+ this.pause();
9356
+ else
9357
+ this.play();
9358
+ }
9359
+ seek(time) {
9360
+ const target = toMicroseconds(time, "Video time");
9361
+ if (!this._metadata || this.isDestroyed)
9362
+ return;
9363
+ if (!this.control((native) => native.lib.videoSeek(native.context, native.node, target)))
9364
+ return;
9365
+ const position = this.currentTime;
9366
+ this.onSeek?.(position);
9367
+ this.onTimeUpdate?.(position);
9368
+ }
9369
+ seekBy(delta) {
9370
+ if (!Number.isFinite(delta))
9371
+ throw new RangeError("Video seek delta must be finite");
9372
+ this.seek(this.currentTime + delta);
9373
+ }
9374
+ seekToMs(milliseconds) {
9375
+ if (!Number.isFinite(milliseconds))
9376
+ throw new RangeError("Video time must be finite");
9377
+ this.seek(milliseconds / 1000);
9378
+ }
9379
+ createFrameBuffer() {
9380
+ const previous = this.frameBuffer;
9381
+ super.createFrameBuffer();
9382
+ if (this._fit === undefined || this.frameBuffer === previous)
9383
+ return;
9384
+ this.setNativeSceneVideo();
9385
+ }
9386
+ renderSelf(_buffer) {}
9387
+ poll() {
9388
+ if (!this._metadata || this.isDestroyed)
9389
+ return;
9390
+ let state;
9391
+ try {
9392
+ state = this.readState();
9393
+ } catch (error) {
9394
+ this.reportError(error);
9395
+ this.syncPlayback(false);
9396
+ return;
9397
+ }
9398
+ if (state.failed) {
9399
+ this.reportError(new Error(this.errorDetail("Video playback failed")));
9400
+ this.syncPlayback();
9401
+ return;
9402
+ }
9403
+ this.onTimeUpdate?.(Number(state.currentTimeUs) / 1e6);
9404
+ if (state.ended) {
9405
+ this.syncPlayback();
9406
+ this.onEnd?.();
9407
+ }
9408
+ }
9409
+ native() {
9410
+ return this._ctx.nativeScene.videoNode(this);
9411
+ }
9412
+ readState() {
9413
+ const native = this.native();
9414
+ return native.lib.videoGetState(native.context, native.node);
9415
+ }
9416
+ failed() {
9417
+ if (!this._metadata)
9418
+ return false;
9419
+ try {
9420
+ return this.readState().failed;
9421
+ } catch {
9422
+ return true;
9423
+ }
9424
+ }
9425
+ errorDetail(fallback) {
9426
+ try {
9427
+ const native = this.native();
9428
+ return native.lib.videoGetError(native.context, native.node) || fallback;
9429
+ } catch {
9430
+ return fallback;
9431
+ }
9432
+ }
9433
+ applyOption(call) {
9434
+ return !this._metadata || this.control(call);
9435
+ }
9436
+ control(call) {
9437
+ let reported = false;
9438
+ try {
9439
+ return call(this.native()) !== false;
9440
+ } catch (error) {
9441
+ reported = true;
9442
+ this.reportError(error);
9443
+ return false;
9444
+ } finally {
9445
+ this.syncPlayback(!reported);
9446
+ this.requestRender();
9447
+ }
9448
+ }
9449
+ syncPlayback(report = true) {
9450
+ if (this.isDestroyed)
9451
+ return;
9452
+ let active = false;
9453
+ try {
9454
+ active = this._metadata !== null && (this._playRequested || this.readState().playing);
9455
+ } catch (error) {
9456
+ if (report)
9457
+ this.reportError(error);
9458
+ }
9459
+ this.stopTick?.();
9460
+ this.stopTick = active ? this._ctx.onAnimationTick(this._maxFps, () => this.poll()) : undefined;
9461
+ }
9462
+ setNativeSceneVideo(fit = this._fit) {
9463
+ this._ctx.nativeScene.setVideo(this, fit, this.buffered ? this.frameBuffer : null);
9464
+ }
9465
+ acceptCrop(crop) {
9466
+ try {
9467
+ return crop && checkCrop2(crop, this._metadata?.width, this._metadata?.height);
9468
+ } catch (error) {
9469
+ queueMicrotask(() => this.isDestroyed || this.reportError(error, ""));
9470
+ return null;
9471
+ }
9472
+ }
9473
+ startRequested() {
9474
+ if (!this._playRequested)
9475
+ return;
9476
+ this._playRequested = false;
9477
+ if (this.control((native) => native.lib.videoCall(native.context, native.node, "ot_video_play")))
9478
+ this.onPlay?.();
9479
+ }
9480
+ afterOpen(report) {
9481
+ const opens = this._opens;
9482
+ queueMicrotask(() => {
9483
+ if (this._opens === opens && !this.isDestroyed)
9484
+ report();
9485
+ });
9486
+ }
9487
+ reportError(error, detail = this.errorDetail("")) {
9488
+ const value = error instanceof Error ? error : new Error(String(error));
9489
+ this.onError?.(detail && !value.message.includes(detail) ? new Error(`${value.message}: ${detail}`) : value);
9490
+ }
9491
+ destroySelf() {
9492
+ this.runCleanup((run) => {
9493
+ run(() => this.stopTick?.());
9494
+ run(() => super.destroySelf());
9495
+ });
9496
+ }
9497
+ }
9035
9498
  // ../../node_modules/.bun/marked@17.0.1/node_modules/marked/lib/marked.esm.js
9036
9499
  function L() {
9037
9500
  return { async: false, breaks: false, extensions: null, gfm: true, hooks: null, pedantic: false, renderer: null, silent: false, tokenizer: null, walkTokens: null };
@@ -10406,7 +10869,6 @@ class TextTableRenderable extends Renderable2 {
10406
10869
  _columnCount = 0;
10407
10870
  _layout = this.createEmptyLayout();
10408
10871
  _layoutDirty = true;
10409
- _rasterDirty = true;
10410
10872
  _cachedMeasureLayout = null;
10411
10873
  _cachedMeasureWidth = undefined;
10412
10874
  _defaultOptions = {
@@ -10433,7 +10895,7 @@ class TextTableRenderable extends Renderable2 {
10433
10895
  attributes: 0
10434
10896
  };
10435
10897
  constructor(ctx, options = {}) {
10436
- super(ctx, { ...options, flexShrink: options.flexShrink ?? 0, buffered: true });
10898
+ super(ctx, { ...options, flexShrink: options.flexShrink ?? 0 });
10437
10899
  try {
10438
10900
  this._content = options.content ?? this._defaultOptions.content;
10439
10901
  this._wrapMode = options.wrapMode ?? this._defaultOptions.wrapMode;
@@ -10480,7 +10942,7 @@ class TextTableRenderable extends Renderable2 {
10480
10942
  for (const cell of row)
10481
10943
  cell.textBufferView.setWrapMode(value);
10482
10944
  }
10483
- this.invalidateLayoutAndRaster();
10945
+ this.invalidateLayout();
10484
10946
  });
10485
10947
  }
10486
10948
  get columnWidthMode() {
@@ -10490,7 +10952,7 @@ class TextTableRenderable extends Renderable2 {
10490
10952
  if (this._columnWidthMode === value)
10491
10953
  return;
10492
10954
  this._columnWidthMode = value;
10493
- this.invalidateLayoutAndRaster();
10955
+ this.invalidateLayout();
10494
10956
  }
10495
10957
  get columnFitter() {
10496
10958
  return this._columnFitter;
@@ -10500,7 +10962,7 @@ class TextTableRenderable extends Renderable2 {
10500
10962
  if (this._columnFitter === next)
10501
10963
  return;
10502
10964
  this._columnFitter = next;
10503
- this.invalidateLayoutAndRaster();
10965
+ this.invalidateLayout();
10504
10966
  }
10505
10967
  get cellPadding() {
10506
10968
  return this._cellPaddingX === this._cellPaddingY ? this._cellPaddingX : 0;
@@ -10511,7 +10973,7 @@ class TextTableRenderable extends Renderable2 {
10511
10973
  return;
10512
10974
  this._cellPaddingX = next;
10513
10975
  this._cellPaddingY = next;
10514
- this.invalidateLayoutAndRaster();
10976
+ this.invalidateLayout();
10515
10977
  }
10516
10978
  get cellPaddingX() {
10517
10979
  return this._cellPaddingX;
@@ -10521,7 +10983,7 @@ class TextTableRenderable extends Renderable2 {
10521
10983
  if (this._cellPaddingX === next)
10522
10984
  return;
10523
10985
  this._cellPaddingX = next;
10524
- this.invalidateLayoutAndRaster();
10986
+ this.invalidateLayout();
10525
10987
  }
10526
10988
  get cellPaddingY() {
10527
10989
  return this._cellPaddingY;
@@ -10531,7 +10993,7 @@ class TextTableRenderable extends Renderable2 {
10531
10993
  if (this._cellPaddingY === next)
10532
10994
  return;
10533
10995
  this._cellPaddingY = next;
10534
- this.invalidateLayoutAndRaster();
10996
+ this.invalidateLayout();
10535
10997
  }
10536
10998
  get columnGap() {
10537
10999
  return this._columnGap;
@@ -10541,7 +11003,7 @@ class TextTableRenderable extends Renderable2 {
10541
11003
  if (this._columnGap === next)
10542
11004
  return;
10543
11005
  this._columnGap = next;
10544
- this.invalidateLayoutAndRaster();
11006
+ this.invalidateLayout();
10545
11007
  }
10546
11008
  get showBorders() {
10547
11009
  return this._showBorders;
@@ -10550,7 +11012,7 @@ class TextTableRenderable extends Renderable2 {
10550
11012
  if (this._showBorders === value)
10551
11013
  return;
10552
11014
  this._showBorders = value;
10553
- this.invalidateRasterOnly();
11015
+ this.requestRender();
10554
11016
  }
10555
11017
  get outerBorder() {
10556
11018
  return this._outerBorder;
@@ -10563,7 +11025,7 @@ class TextTableRenderable extends Renderable2 {
10563
11025
  return;
10564
11026
  this._hasExplicitOuterBorder = value != null;
10565
11027
  this._outerBorder = next;
10566
- this.invalidateLayoutAndRaster();
11028
+ this.invalidateLayout();
10567
11029
  }
10568
11030
  get border() {
10569
11031
  return this._border;
@@ -10575,7 +11037,7 @@ class TextTableRenderable extends Renderable2 {
10575
11037
  if (!this._hasExplicitOuterBorder) {
10576
11038
  this._outerBorder = value;
10577
11039
  }
10578
- this.invalidateLayoutAndRaster();
11040
+ this.invalidateLayout();
10579
11041
  }
10580
11042
  get borderStyle() {
10581
11043
  return this._borderStyle;
@@ -10585,14 +11047,14 @@ class TextTableRenderable extends Renderable2 {
10585
11047
  if (this._borderStyle === next)
10586
11048
  return;
10587
11049
  this._borderStyle = next;
10588
- this.invalidateRasterOnly();
11050
+ this.requestRender();
10589
11051
  }
10590
11052
  get borderColor() {
10591
11053
  return RGBA2.clone(this._borderColor);
10592
11054
  }
10593
11055
  set borderColor(value) {
10594
11056
  this._borderColor = RGBA2.clone(parseColor2(value ?? this._defaultOptions.borderColor));
10595
- this.invalidateRasterOnly();
11057
+ this.requestRender();
10596
11058
  }
10597
11059
  get fg() {
10598
11060
  return this._defaultFg;
@@ -10607,7 +11069,7 @@ class TextTableRenderable extends Renderable2 {
10607
11069
  cell.textBuffer.setDefaultFg(next);
10608
11070
  }
10609
11071
  }
10610
- this.invalidateRasterOnly();
11072
+ this.requestRender();
10611
11073
  }
10612
11074
  shouldStartSelection(x, y) {
10613
11075
  if (!this.selectable)
@@ -10619,19 +11081,15 @@ class TextTableRenderable extends Renderable2 {
10619
11081
  }
10620
11082
  onSelectionChanged(selection) {
10621
11083
  this.ensureLayoutReady();
10622
- const previousLocalSelection = this._lastLocalSelection;
10623
11084
  const localSelection = convertGlobalToLocalSelection2(selection, Math.trunc(this.x), Math.trunc(this.y));
10624
11085
  this._lastLocalSelection = localSelection;
10625
- const dirtyRows = this.getDirtySelectionRowRange(previousLocalSelection, localSelection);
10626
11086
  if (!localSelection?.isActive) {
10627
11087
  this.resetCellSelections();
10628
11088
  this._lastSelectionMode = null;
10629
11089
  } else {
10630
11090
  this.applySelectionToCells(localSelection, selection?.isStart ?? false);
10631
11091
  }
10632
- if (dirtyRows !== null) {
10633
- this.redrawSelectionRows(dirtyRows.firstRow, dirtyRows.lastRow);
10634
- }
11092
+ this.requestRender();
10635
11093
  return this.hasSelection();
10636
11094
  }
10637
11095
  hasSelection() {
@@ -10676,25 +11134,23 @@ class TextTableRenderable extends Renderable2 {
10676
11134
  `);
10677
11135
  }
10678
11136
  onResize(width, height) {
10679
- this.invalidateLayoutAndRaster(false);
11137
+ this.invalidateLayout(false);
10680
11138
  super.onResize(width, height);
10681
11139
  }
10682
11140
  renderSelf(buffer) {
10683
11141
  if (!this.visible || this.isDestroyed)
10684
11142
  return;
10685
- if (this._layoutDirty) {
10686
- this.rebuildLayoutForCurrentWidth();
10687
- }
10688
- if (!this._rasterDirty)
10689
- return;
10690
- buffer.clear(this._backgroundColor);
10691
- if (this._rowCount === 0 || this._columnCount === 0) {
10692
- this._rasterDirty = false;
10693
- return;
11143
+ this.ensureLayoutReady();
11144
+ const [x, y] = this._paintOrigin(buffer);
11145
+ buffer.pushScissorRect(x, y, this._paintWidth, this._paintHeight);
11146
+ if (buffer === this.frameBuffer)
11147
+ buffer.clear(this._backgroundColor);
11148
+ else if (this._backgroundColor.a > 0) {
11149
+ buffer.fillRect(x, y, this._paintWidth, this._paintHeight, this._backgroundColor);
10694
11150
  }
10695
- this.drawBorders(buffer);
10696
- this.drawCells(buffer);
10697
- this._rasterDirty = false;
11151
+ this.drawBorders(buffer, x, y);
11152
+ this.drawCells(buffer, x, y);
11153
+ buffer.popScissorRect();
10698
11154
  }
10699
11155
  destroySelf() {
10700
11156
  this.destroyCells();
@@ -10780,7 +11236,7 @@ class TextTableRenderable extends Renderable2 {
10780
11236
  this._rowCount = newRowCount;
10781
11237
  this._columnCount = newColumnCount;
10782
11238
  this.runCleanup((run) => {
10783
- run(() => this.invalidateLayoutAndRaster());
11239
+ run(() => this.invalidateLayout());
10784
11240
  for (let rowIdx = 0;rowIdx < previous.length; rowIdx++) {
10785
11241
  for (let colIdx = 0;colIdx < previous[rowIdx].length; colIdx++) {
10786
11242
  const cell = previous[rowIdx][colIdx];
@@ -11080,7 +11536,7 @@ class TextTableRenderable extends Renderable2 {
11080
11536
  getHorizontalBorderCount(borderLayout) {
11081
11537
  return (borderLayout.top ? 1 : 0) + (borderLayout.bottom ? 1 : 0) + (borderLayout.innerHorizontal ? Math.max(0, this._rowCount - 1) : 0);
11082
11538
  }
11083
- drawBorders(buffer) {
11539
+ drawBorders(buffer, x, y) {
11084
11540
  if (!this._showBorders) {
11085
11541
  return;
11086
11542
  }
@@ -11088,59 +11544,31 @@ class TextTableRenderable extends Renderable2 {
11088
11544
  if (this.getVerticalBorderCount(borderLayout) === 0 && this.getHorizontalBorderCount(borderLayout) === 0) {
11089
11545
  return;
11090
11546
  }
11547
+ const { columnOffsets, rowOffsets, columnOffsetsI32, rowOffsetsI32 } = this._layout;
11548
+ columnOffsets.forEach((offset, index) => columnOffsetsI32[index] = offset + x);
11549
+ rowOffsets.forEach((offset, index) => rowOffsetsI32[index] = offset + y);
11091
11550
  buffer.drawGrid({
11092
11551
  borderChars: BorderCharArrays2[this._borderStyle],
11093
11552
  borderFg: this._borderColor,
11094
11553
  borderBg: this._borderBackgroundColor,
11095
- columnOffsets: this._layout.columnOffsetsI32,
11096
- rowOffsets: this._layout.rowOffsetsI32,
11554
+ columnOffsets: columnOffsetsI32,
11555
+ rowOffsets: rowOffsetsI32,
11097
11556
  drawInner: this._border,
11098
11557
  drawOuter: this._outerBorder
11099
11558
  });
11100
11559
  }
11101
- drawCells(buffer) {
11102
- this.drawCellRange(buffer, 0, this._rowCount - 1);
11103
- }
11104
- drawCellRange(buffer, firstRow, lastRow) {
11560
+ drawCells(buffer, x, y) {
11105
11561
  const colOffsets = this._layout.columnOffsets;
11106
11562
  const rowOffsets = this._layout.rowOffsets;
11107
- const cellPaddingX = this._cellPaddingX;
11563
+ const cellX = x + 1 + this._cellPaddingX;
11108
11564
  const cellPaddingY = this._cellPaddingY;
11109
- for (let rowIdx = firstRow;rowIdx <= lastRow; rowIdx++) {
11110
- const cellY = (rowOffsets[rowIdx] ?? 0) + 1 + cellPaddingY;
11565
+ for (let rowIdx = 0;rowIdx < this._rowCount; rowIdx++) {
11566
+ const cellY = y + (rowOffsets[rowIdx] ?? 0) + 1 + cellPaddingY;
11111
11567
  for (let colIdx = 0;colIdx < this._columnCount; colIdx++) {
11112
11568
  const cell = this._cells[rowIdx]?.[colIdx];
11113
11569
  if (!cell)
11114
11570
  continue;
11115
- buffer.drawTextBuffer(cell.textBufferView, (colOffsets[colIdx] ?? 0) + 1 + cellPaddingX, cellY);
11116
- }
11117
- }
11118
- }
11119
- redrawSelectionRows(firstRow, lastRow) {
11120
- if (firstRow > lastRow)
11121
- return;
11122
- if (this._backgroundColor.a < 1) {
11123
- this.invalidateRasterOnly();
11124
- return;
11125
- }
11126
- const buffer = this.frameBuffer;
11127
- if (!buffer)
11128
- return;
11129
- this.clearCellRange(buffer, firstRow, lastRow);
11130
- this.drawCellRange(buffer, firstRow, lastRow);
11131
- this.requestRender();
11132
- }
11133
- clearCellRange(buffer, firstRow, lastRow) {
11134
- const colWidths = this._layout.columnWidths;
11135
- const rowHeights = this._layout.rowHeights;
11136
- const colOffsets = this._layout.columnOffsets;
11137
- const rowOffsets = this._layout.rowOffsets;
11138
- for (let rowIdx = firstRow;rowIdx <= lastRow; rowIdx++) {
11139
- const cellY = (rowOffsets[rowIdx] ?? 0) + 1;
11140
- const rowHeight = rowHeights[rowIdx] ?? 1;
11141
- for (let colIdx = 0;colIdx < this._columnCount; colIdx++) {
11142
- const cellX = (colOffsets[colIdx] ?? 0) + 1;
11143
- buffer.fillRect(cellX, cellY, colWidths[colIdx] ?? 1, rowHeight, this._backgroundColor);
11571
+ buffer.drawTextBuffer(cell.textBufferView, cellX + (colOffsets[colIdx] ?? 0), cellY);
11144
11572
  }
11145
11573
  }
11146
11574
  }
@@ -11296,28 +11724,6 @@ class TextTableRenderable extends Renderable2 {
11296
11724
  }
11297
11725
  return this._rowCount - 1;
11298
11726
  }
11299
- getSelectionRowRange(selection) {
11300
- if (!selection?.isActive || this._rowCount === 0)
11301
- return null;
11302
- const minSelY = Math.min(selection.anchorY, selection.focusY);
11303
- const maxSelY = Math.max(selection.anchorY, selection.focusY);
11304
- return {
11305
- firstRow: this.findRowForLocalY(minSelY),
11306
- lastRow: this.findRowForLocalY(maxSelY)
11307
- };
11308
- }
11309
- getDirtySelectionRowRange(previousSelection, currentSelection) {
11310
- const previousRange = this.getSelectionRowRange(previousSelection);
11311
- const currentRange = this.getSelectionRowRange(currentSelection);
11312
- if (previousRange === null)
11313
- return currentRange;
11314
- if (currentRange === null)
11315
- return previousRange;
11316
- return {
11317
- firstRow: Math.min(previousRange.firstRow, currentRange.firstRow),
11318
- lastRow: Math.max(previousRange.lastRow, currentRange.lastRow)
11319
- };
11320
- }
11321
11727
  resetRowSelection(rowIdx) {
11322
11728
  const row = this._cells[rowIdx];
11323
11729
  if (!row)
@@ -11376,9 +11782,8 @@ class TextTableRenderable extends Renderable2 {
11376
11782
  }
11377
11783
  return Math.max(0, Math.floor(value));
11378
11784
  }
11379
- invalidateLayoutAndRaster(markYogaDirty = true) {
11785
+ invalidateLayout(markYogaDirty = true) {
11380
11786
  this._layoutDirty = true;
11381
- this._rasterDirty = true;
11382
11787
  this._cachedMeasureLayout = null;
11383
11788
  this._cachedMeasureWidth = undefined;
11384
11789
  if (markYogaDirty) {
@@ -11386,10 +11791,6 @@ class TextTableRenderable extends Renderable2 {
11386
11791
  }
11387
11792
  this.requestRender();
11388
11793
  }
11389
- invalidateRasterOnly() {
11390
- this._rasterDirty = true;
11391
- this.requestRender();
11392
- }
11393
11794
  }
11394
11795
 
11395
11796
  // src/renderables/markdown-parser.ts
@@ -12108,7 +12509,7 @@ class MarkdownRenderable extends Renderable2 {
12108
12509
  }
12109
12510
  }
12110
12511
  applyListItemRenderable(row, input, previousItem) {
12111
- this.applyListItemMarker(row, input);
12512
+ this.applyListItemMarker(row, input, previousItem);
12112
12513
  const content = row.getChildren()[1];
12113
12514
  if (!(content instanceof BoxRenderable2))
12114
12515
  return false;
@@ -12175,6 +12576,10 @@ class MarkdownRenderable extends Renderable2 {
12175
12576
  this.applyCodeBlockRenderable(renderable, token, 0);
12176
12577
  return true;
12177
12578
  }
12579
+ if (token.type === "blockquote" && renderable instanceof BoxRenderable2) {
12580
+ this.applyBlockquoteRenderable(renderable, token, 0);
12581
+ return true;
12582
+ }
12178
12583
  return previousToken?.raw === token.raw;
12179
12584
  }
12180
12585
  destroyListItemChildrenAfter(content, index) {
@@ -12183,7 +12588,7 @@ class MarkdownRenderable extends Renderable2 {
12183
12588
  children[i]?.destroyRecursively();
12184
12589
  }
12185
12590
  }
12186
- applyListItemMarker(row, input) {
12591
+ applyListItemMarker(row, input, previousItem) {
12187
12592
  const marker = row.getChildren()[0];
12188
12593
  if (!(marker instanceof TextRenderable2))
12189
12594
  return;
@@ -12194,7 +12599,7 @@ class MarkdownRenderable extends Renderable2 {
12194
12599
  row.marginBottom = marginBottom;
12195
12600
  if (marker.width !== markerWidth)
12196
12601
  marker.width = markerWidth;
12197
- if (marker.chunks[0]?.text !== markerText) {
12602
+ if (!previousItem || marker.chunks[0]?.text !== markerText) {
12198
12603
  marker.content = new StyledText2([this.createChunk(markerText, "markup.list")]);
12199
12604
  }
12200
12605
  }
@@ -12214,13 +12619,16 @@ class MarkdownRenderable extends Renderable2 {
12214
12619
  return this.createTableBlock(token, id).renderable;
12215
12620
  return token.raw ? this.createMarkdownCodeRenderable(token.raw, id, 0, this._linkifyMarkdownChunks, undefined, this.createInitialStyledText(token)) : null;
12216
12621
  }
12622
+ getHorizontalRuleColor() {
12623
+ return this.getStyle("conceal")?.fg ?? this._fg ?? "#888888";
12624
+ }
12217
12625
  createHorizontalRuleRenderable(id, marginBottom = 0) {
12218
12626
  return new BoxRenderable2(this.ctx, {
12219
12627
  id,
12220
12628
  width: "100%",
12221
12629
  height: 1,
12222
12630
  border: ["top"],
12223
- borderColor: this.getStyle("conceal")?.fg ?? this._fg ?? "#888888",
12631
+ borderColor: this.getHorizontalRuleColor(),
12224
12632
  flexShrink: 0,
12225
12633
  marginBottom
12226
12634
  });
@@ -12775,7 +13183,7 @@ class MarkdownRenderable extends Renderable2 {
12775
13183
  return;
12776
13184
  renderable.destroyRecursively();
12777
13185
  }
12778
- updateBlockRenderable(state, token, index, nextToken, forceListRefresh = false) {
13186
+ updateBlockRenderable(state, token, index, nextToken, forceRefresh = false) {
12779
13187
  const marginBottom = this.getInterBlockMargin(token, nextToken);
12780
13188
  if (token.type === "code") {
12781
13189
  this.applyCodeBlockRenderable(state.renderable, token, marginBottom);
@@ -12786,7 +13194,7 @@ class MarkdownRenderable extends Renderable2 {
12786
13194
  return;
12787
13195
  }
12788
13196
  if (token.type === "list") {
12789
- if (!this.applyListRenderable(state.renderable, token, forceListRefresh ? undefined : state.token, `${this.id}-block-${index}`, marginBottom)) {
13197
+ if (!this.applyListRenderable(state.renderable, token, forceRefresh ? undefined : state.token, `${this.id}-block-${index}`, marginBottom)) {
12790
13198
  state.renderable.destroyRecursively();
12791
13199
  state.renderable = this.createListRenderable(token, `${this.id}-block-${index}`, marginBottom);
12792
13200
  this.add(state.renderable, index);
@@ -12794,12 +13202,14 @@ class MarkdownRenderable extends Renderable2 {
12794
13202
  return;
12795
13203
  }
12796
13204
  if (token.type === "hr") {
13205
+ if (state.renderable instanceof BoxRenderable2)
13206
+ state.renderable.borderColor = this.getHorizontalRuleColor();
12797
13207
  state.renderable.marginBottom = marginBottom;
12798
13208
  return;
12799
13209
  }
12800
13210
  if (token.type === "table") {
12801
13211
  const tableToken = token;
12802
- const { cache, changed } = this.buildTableContentCache(tableToken, state.tableContentCache);
13212
+ const { cache, changed } = this.buildTableContentCache(tableToken, state.tableContentCache, forceRefresh);
12803
13213
  if (!cache) {
12804
13214
  if (state.renderable instanceof CodeRenderable2) {
12805
13215
  this.applyMarkdownCodeRenderable(state.renderable, tableToken.raw, marginBottom);
@@ -12829,12 +13239,13 @@ class MarkdownRenderable extends Renderable2 {
12829
13239
  state.tableContentCache = cache;
12830
13240
  return;
12831
13241
  }
13242
+ const raw = this._internalBlockMode === "top-level" ? this.getTopLevelBlockRaw(token) ?? token.raw : token.raw;
12832
13243
  if (state.renderable instanceof CodeRenderable2) {
12833
- this.applyMarkdownCodeRenderable(state.renderable, this.getTopLevelBlockRaw(token) ?? token.raw, marginBottom, undefined, this.createInitialStyledText(token));
13244
+ this.applyMarkdownCodeRenderable(state.renderable, raw, marginBottom, undefined, this.createInitialStyledText(token));
12834
13245
  return;
12835
13246
  }
12836
13247
  state.renderable.destroyRecursively();
12837
- const markdownRenderable = this.createMarkdownCodeRenderable(this.getTopLevelBlockRaw(token) ?? token.raw, `${this.id}-block-${index}`, marginBottom, this._linkifyMarkdownChunks, undefined, this.createInitialStyledText(token));
13248
+ const markdownRenderable = this.createMarkdownCodeRenderable(raw, `${this.id}-block-${index}`, marginBottom, this._linkifyMarkdownChunks, undefined, this.createInitialStyledText(token));
12838
13249
  this.add(markdownRenderable, index);
12839
13250
  state.renderable = markdownRenderable;
12840
13251
  }
@@ -12861,7 +13272,7 @@ class MarkdownRenderable extends Renderable2 {
12861
13272
  blockIndex++;
12862
13273
  continue;
12863
13274
  }
12864
- if (existing && existing.canUpdateInPlace && existing.token.type === block.token.type && this.canUpdateBlockRenderable(existing.renderable, block.token)) {
13275
+ if (existing && existing.canUpdateInPlace && existing.token.type === block.token.type && (block.token.type !== "table" || block.token.rows.length > 0 === existing.renderable instanceof TextTableRenderable)) {
12865
13276
  if (this._renderNode) {
12866
13277
  const custom = this.createTopLevelCustomRenderable(block, blockIndex);
12867
13278
  if (custom.renderable && !custom.canUpdateInPlace) {
@@ -12884,7 +13295,7 @@ class MarkdownRenderable extends Renderable2 {
12884
13295
  }
12885
13296
  this.destroyUnusedDefaultRenderable(custom.renderable);
12886
13297
  }
12887
- this.updateBlockRenderable(existing, block.token, blockIndex, blocks[i + 1]?.token);
13298
+ this.updateBlockRenderable(existing, block.token, blockIndex, blocks[i + 1]?.token, forceTableRefresh);
12888
13299
  existing.renderable.marginBottom = 0;
12889
13300
  if (existing.marginTop !== block.marginTop) {
12890
13301
  this.applyMargins(existing.renderable, block.marginTop, 0);
@@ -12915,19 +13326,6 @@ class MarkdownRenderable extends Renderable2 {
12915
13326
  removed.renderable.destroyRecursively();
12916
13327
  }
12917
13328
  }
12918
- canUpdateBlockRenderable(renderable, token) {
12919
- if (token.type === "code")
12920
- return renderable instanceof CodeRenderable2;
12921
- if (token.type === "table")
12922
- return renderable instanceof TextTableRenderable;
12923
- if (token.type === "blockquote")
12924
- return renderable instanceof BoxRenderable2;
12925
- if (token.type === "list")
12926
- return renderable instanceof BoxRenderable2;
12927
- if (token.type === "hr")
12928
- return renderable instanceof BoxRenderable2;
12929
- return renderable instanceof CodeRenderable2;
12930
- }
12931
13329
  updateBlocks(forceTableRefresh = false) {
12932
13330
  if (this.isDestroyed)
12933
13331
  return;
@@ -12968,22 +13366,10 @@ class MarkdownRenderable extends Renderable2 {
12968
13366
  const token = blockTokens[i];
12969
13367
  const nextToken = blockTokens[i + 1];
12970
13368
  const existing = this._blockStates[blockIndex];
12971
- const shouldForceRefresh = forceTableRefresh;
12972
- if (existing && existing.token === token) {
12973
- if (shouldForceRefresh) {
12974
- this.updateBlockRenderable(existing, token, blockIndex, nextToken);
12975
- existing.tokenRaw = token.raw;
12976
- } else {
12977
- this.applyInterBlockMargin(existing, token, nextToken);
12978
- }
12979
- blockIndex++;
12980
- continue;
12981
- }
12982
13369
  if (existing && existing.tokenRaw === token.raw && existing.token.type === token.type) {
12983
13370
  existing.token = token;
12984
- if (shouldForceRefresh) {
12985
- this.updateBlockRenderable(existing, token, blockIndex, nextToken);
12986
- existing.tokenRaw = token.raw;
13371
+ if (forceTableRefresh) {
13372
+ this.updateBlockRenderable(existing, token, blockIndex, nextToken, true);
12987
13373
  } else {
12988
13374
  this.applyInterBlockMargin(existing, token, nextToken);
12989
13375
  }
@@ -13073,60 +13459,7 @@ class MarkdownRenderable extends Renderable2 {
13073
13459
  }
13074
13460
  for (let i = 0;i < this._blockStates.length; i++) {
13075
13461
  const state = this._blockStates[i];
13076
- const marginBottom = this.getInterBlockMargin(state.token, this._blockStates[i + 1]?.token);
13077
- if (state.token.type === "code") {
13078
- this.applyCodeBlockRenderable(state.renderable, state.token, marginBottom);
13079
- continue;
13080
- }
13081
- if (state.token.type === "blockquote") {
13082
- this.applyBlockquoteRenderable(state.renderable, state.token, marginBottom);
13083
- continue;
13084
- }
13085
- if (state.token.type === "list") {
13086
- this.updateBlockRenderable(state, state.token, i, this._blockStates[i + 1]?.token, true);
13087
- continue;
13088
- }
13089
- if (state.token.type === "hr") {
13090
- state.renderable.marginBottom = marginBottom;
13091
- continue;
13092
- }
13093
- if (state.token.type === "table") {
13094
- const tableToken = state.token;
13095
- const { cache } = this.buildTableContentCache(tableToken, state.tableContentCache, true);
13096
- if (!cache) {
13097
- if (state.renderable instanceof CodeRenderable2) {
13098
- this.applyMarkdownCodeRenderable(state.renderable, tableToken.raw, marginBottom);
13099
- } else {
13100
- state.renderable.destroyRecursively();
13101
- const fallbackRenderable = this.createMarkdownCodeRenderable(tableToken.raw, `${this.id}-block-${i}`, marginBottom);
13102
- this.add(fallbackRenderable, i);
13103
- state.renderable = fallbackRenderable;
13104
- }
13105
- state.tableContentCache = undefined;
13106
- continue;
13107
- }
13108
- if (state.renderable instanceof TextTableRenderable) {
13109
- state.renderable.content = cache.content;
13110
- this.applyTableRenderableOptions(state.renderable, this.resolveTableRenderableOptions());
13111
- state.renderable.marginBottom = marginBottom;
13112
- state.tableContentCache = cache;
13113
- continue;
13114
- }
13115
- state.renderable.destroyRecursively();
13116
- const tableRenderable = this.createTextTableRenderable(cache.content, `${this.id}-block-${i}`, marginBottom);
13117
- this.add(tableRenderable, i);
13118
- state.renderable = tableRenderable;
13119
- state.tableContentCache = cache;
13120
- continue;
13121
- }
13122
- if (state.renderable instanceof CodeRenderable2) {
13123
- this.applyMarkdownCodeRenderable(state.renderable, this.getTopLevelBlockRaw(state.token) ?? state.token.raw, marginBottom, undefined, this.createInitialStyledText(state.token));
13124
- continue;
13125
- }
13126
- state.renderable.destroyRecursively();
13127
- const markdownRenderable = this.createMarkdownCodeRenderable(this.getTopLevelBlockRaw(state.token) ?? state.token.raw, `${this.id}-block-${i}`, marginBottom, this._linkifyMarkdownChunks, undefined, this.createInitialStyledText(state.token));
13128
- this.add(markdownRenderable, i);
13129
- state.renderable = markdownRenderable;
13462
+ this.updateBlockRenderable(state, state.token, i, this._blockStates[i + 1]?.token, true);
13130
13463
  }
13131
13464
  }
13132
13465
  clearCache() {
@@ -13404,56 +13737,7 @@ class SliderRenderable extends Renderable2 {
13404
13737
  }
13405
13738
  }
13406
13739
  renderSelf(buffer) {
13407
- const x = this.x;
13408
- const y = this.y;
13409
- const width = this.width;
13410
- const height = this.height;
13411
- const bufferWidth = buffer.width;
13412
- const bufferHeight = buffer.height;
13413
- const left = Math.max(0, Math.trunc(x));
13414
- const top = Math.max(0, Math.trunc(y));
13415
- const right = Math.min(bufferWidth, Math.trunc(x) + Math.trunc(width));
13416
- const bottom = Math.min(bufferHeight, Math.trunc(y) + Math.trunc(height));
13417
- if (right > left && bottom > top) {
13418
- buffer.fillRect(left, top, right - left, bottom - top, this._backgroundColor);
13419
- }
13420
- const horizontal = this.orientation === "horizontal";
13421
- const origin = horizontal ? x : y;
13422
- const crossOrigin = horizontal ? y : x;
13423
- const length = horizontal ? width : height;
13424
- const crossLength = horizontal ? height : width;
13425
- const limit = horizontal ? bufferWidth : bufferHeight;
13426
- const crossLimit = horizontal ? bufferHeight : bufferWidth;
13427
- const thumb = this._ctx.nativeScene.getSliderThumb(this);
13428
- const virtualThumbSize = thumb.size;
13429
- const virtualThumbStart = thumb.start;
13430
- const virtualThumbEnd = virtualThumbStart + virtualThumbSize;
13431
- const start = Math.max(0, Math.floor(virtualThumbStart / 2), Math.floor(-1 - origin));
13432
- const end = Math.min(Math.floor(length), Math.ceil(virtualThumbEnd / 2), Math.ceil(limit - origin) + 1);
13433
- const crossStart = Math.max(0, Math.floor(-1 - crossOrigin));
13434
- const crossEnd = Math.min(Math.ceil(crossLength), Math.ceil(crossLimit - crossOrigin) + 1);
13435
- for (let along = start;along < end; along++) {
13436
- const cell = Math.trunc(origin + along);
13437
- if (cell < 0 || cell >= limit)
13438
- continue;
13439
- const virtualCellStart = along * 2;
13440
- const thumbStartInCell = Math.max(virtualThumbStart, virtualCellStart);
13441
- const coverage = Math.min(virtualThumbEnd, virtualCellStart + 2) - thumbStartInCell;
13442
- let char = " ";
13443
- if (coverage >= 2) {
13444
- char = "\u2588";
13445
- } else if (horizontal) {
13446
- char = thumbStartInCell === virtualCellStart ? "\u258C" : "\u2590";
13447
- } else if (coverage > 0) {
13448
- char = thumbStartInCell === virtualCellStart ? "\u2580" : "\u2584";
13449
- }
13450
- for (let across = crossStart;across < crossEnd; across++) {
13451
- const crossCell = Math.trunc(crossOrigin + across);
13452
- if (crossCell < 0 || crossCell >= crossLimit)
13453
- continue;
13454
- buffer.setCellWithAlphaBlending(horizontal ? cell : crossCell, horizontal ? crossCell : cell, char, this._foregroundColor, this._backgroundColor);
13455
- }
13456
- }
13740
+ this._drawNativeBody(buffer);
13457
13741
  }
13458
13742
  }
13459
13743
 
@@ -13719,9 +14003,7 @@ class ScrollBarRenderable extends Renderable2 {
13719
14003
  this.slider.value = Math.min(this._scrollPosition, scrollRange);
13720
14004
  }
13721
14005
  scrollBy(delta, unit = "absolute") {
13722
- const multiplier = unit === "viewport" ? this.viewportSize : unit === "content" ? this.scrollSize : unit === "step" ? this.scrollStep ?? 1 : 1;
13723
- const resolvedDelta = multiplier * delta;
13724
- this.scrollPosition += resolvedDelta;
14006
+ this.scrollPosition += scrollUnitSize(this, unit) * delta;
13725
14007
  }
13726
14008
  recalculateVisibility() {
13727
14009
  if (!this._manualVisibility) {
@@ -13867,8 +14149,7 @@ class ArrowRenderable extends Renderable2 {
13867
14149
  });
13868
14150
  }
13869
14151
  renderSelf(buffer) {
13870
- const char = this.getArrowChar();
13871
- buffer.drawText(char, this.x, this.y, this._foregroundColor, this._backgroundColor, this._attributes);
14152
+ this._drawNativeBody(buffer);
13872
14153
  }
13873
14154
  defaultDimension(kind) {
13874
14155
  return kind === "width" ? this.glyphWidth() : super.defaultDimension(kind);
@@ -13886,31 +14167,428 @@ class ArrowRenderable extends Renderable2 {
13886
14167
  return this._arrowChars[this._direction];
13887
14168
  }
13888
14169
  }
13889
- // src/renderables/ScrollBox.ts
13890
- class ContentRenderable extends BoxRenderable2 {
13891
- static nativeIntegration = BoxRenderable2.nativeIntegration;
13892
- viewport;
13893
- _viewportCulling;
13894
- constructor(ctx, viewport, viewportCulling, options) {
13895
- super(ctx, options);
13896
- try {
13897
- this.viewport = viewport;
13898
- ctx.nativeScene.setViewport(this, viewportCulling ? viewport : null);
13899
- this._viewportCulling = viewportCulling;
13900
- } catch (error) {
13901
- this.abortConstruction(error);
14170
+ function scrollUnitSize(bar, unit) {
14171
+ if (unit === "viewport")
14172
+ return bar.viewportSize;
14173
+ if (unit === "content")
14174
+ return bar.scrollSize;
14175
+ return unit === "step" ? bar.scrollStep ?? 1 : 1;
14176
+ }
14177
+ // src/renderables/ScrollBoxParts.ts
14178
+ import { EventEmitter as EventEmitter2 } from "events";
14179
+ class ScrollBoxPart extends EventEmitter2 {
14180
+ box;
14181
+ constructor(box, event) {
14182
+ super();
14183
+ this.box = box;
14184
+ this.on("newListener", (name) => name === event && box._refreshScrollHook(true));
14185
+ this.on("removeListener", (name) => name === event && box._refreshScrollHook());
14186
+ }
14187
+ get isDestroyed() {
14188
+ return this.box.isDestroyed;
14189
+ }
14190
+ get x() {
14191
+ return this.rect().x;
14192
+ }
14193
+ get y() {
14194
+ return this.rect().y;
14195
+ }
14196
+ get screenX() {
14197
+ return this.rect().x;
14198
+ }
14199
+ get screenY() {
14200
+ return this.rect().y;
14201
+ }
14202
+ get width() {
14203
+ return this.rect().width;
14204
+ }
14205
+ get height() {
14206
+ return this.rect().height;
14207
+ }
14208
+ removeAllListeners(event) {
14209
+ for (const name of event === undefined ? this.eventNames() : [event]) {
14210
+ if (name !== "newListener" && name !== "removeListener")
14211
+ super.removeAllListeners(name);
14212
+ }
14213
+ return this;
14214
+ }
14215
+ _assign(options, keys) {
14216
+ if (options == null)
14217
+ return;
14218
+ for (const key of Reflect.ownKeys(options)) {
14219
+ if (typeof key !== "string" || !keys.includes(key))
14220
+ continue;
14221
+ if (!Object.getOwnPropertyDescriptor(options, key)?.enumerable)
14222
+ continue;
14223
+ this[key] = Reflect.get(options, key);
14224
+ if (this.box.isDestroyed)
14225
+ return;
14226
+ }
14227
+ }
14228
+ }
14229
+
14230
+ class ScrollBoxFilledPart extends ScrollBoxPart {
14231
+ _backgroundColor;
14232
+ get backgroundColor() {
14233
+ return RGBA2.clone(this._backgroundColor ?? RGBA2.fromValues(0, 0, 0, 0));
14234
+ }
14235
+ set backgroundColor(value) {
14236
+ this._backgroundColor = value == null ? undefined : RGBA2.clone(parseColor2(value));
14237
+ this.box._applyScrollOptions();
14238
+ }
14239
+ _fill() {
14240
+ return this._backgroundColor;
14241
+ }
14242
+ }
14243
+
14244
+ class ScrollBoxSizedPart extends ScrollBoxFilledPart {
14245
+ _onSizeChange;
14246
+ constructor(box) {
14247
+ super(box, "resize");
14248
+ }
14249
+ get onSizeChange() {
14250
+ return this._onSizeChange;
14251
+ }
14252
+ set onSizeChange(handler) {
14253
+ this._onSizeChange = handler ?? undefined;
14254
+ this.box._refreshScrollHook();
14255
+ }
14256
+ _listening() {
14257
+ return this._onSizeChange !== undefined || this.listenerCount("resize") > 0;
14258
+ }
14259
+ _emitResize() {
14260
+ this._onSizeChange?.();
14261
+ if (!this.box.isDestroyed)
14262
+ this.emit("resize");
14263
+ }
14264
+ }
14265
+
14266
+ class ScrollBoxWrapper extends ScrollBoxFilledPart {
14267
+ static keys = ["backgroundColor"];
14268
+ _listening() {
14269
+ return false;
14270
+ }
14271
+ rect() {
14272
+ return this.box._wrapperRect();
14273
+ }
14274
+ }
14275
+ var paddingKeys = ["padding", "paddingX", "paddingY", "paddingLeft", "paddingTop", "paddingRight", "paddingBottom"];
14276
+
14277
+ class ScrollBoxViewport extends ScrollBoxSizedPart {
14278
+ static keys = ["backgroundColor", "onSizeChange", ...paddingKeys];
14279
+ paddings = {};
14280
+ constructor(box) {
14281
+ super(box);
14282
+ paddingKeys.forEach((key, index) => Object.defineProperty(this, key, {
14283
+ configurable: true,
14284
+ get: index < 3 ? undefined : () => this._edges()[index - 3],
14285
+ set: (value) => this.setPadding(key, value)
14286
+ }));
14287
+ }
14288
+ rect() {
14289
+ return this.box._scrollState().viewport;
14290
+ }
14291
+ setPadding(key, value) {
14292
+ if (value != null && (typeof value !== "number" || !Number.isInteger(value) || value < 0 || value > 65535)) {
14293
+ throw new RangeError("ScrollBox viewport padding must be a whole number of cells");
14294
+ }
14295
+ if (value == null)
14296
+ delete this.paddings[key];
14297
+ else
14298
+ this.paddings[key] = value;
14299
+ this.box._applyScrollOptions();
14300
+ }
14301
+ _edges() {
14302
+ const p = this.paddings;
14303
+ const all = p.padding ?? 0;
14304
+ const x = p.paddingX ?? all;
14305
+ const y = p.paddingY ?? all;
14306
+ return [p.paddingLeft ?? x, p.paddingTop ?? y, p.paddingRight ?? x, p.paddingBottom ?? y];
14307
+ }
14308
+ }
14309
+ var content = NativeStyleFlags.Content;
14310
+ var contentStyles = {};
14311
+ {
14312
+ const value = (kind, edge = NATIVE_EDGE_NONE2) => (scene, node, input) => sceneSetValue(scene, node, kind, edge, input ?? undefined, content);
14313
+ const enums = [
14314
+ ["flexDirection", YogaEnumKind.FlexDirection, parseFlexDirection2],
14315
+ ["flexWrap", YogaEnumKind.FlexWrap, parseWrap2],
14316
+ ["alignItems", YogaEnumKind.AlignItems, parseAlignItems2],
14317
+ ["justifyContent", YogaEnumKind.JustifyContent, parseJustify2],
14318
+ ["alignSelf", YogaEnumKind.AlignSelf, parseAlign2]
14319
+ ];
14320
+ for (const [key, kind, parse] of enums) {
14321
+ contentStyles[key] = (scene, node, input) => sceneSetEnum(scene, node, kind, parse(input ?? undefined), content);
14322
+ }
14323
+ contentStyles.flexGrow = (scene, node, input) => sceneSetFloat(scene, node, YogaFloatKind.FlexGrow, input ?? 0, content);
14324
+ contentStyles.flexShrink = (scene, node, input) => sceneSetFloat(scene, node, YogaFloatKind.FlexShrink, input ?? 0, content);
14325
+ for (const [key, kind] of [
14326
+ ["width", YogaValueKind.Width],
14327
+ ["height", YogaValueKind.Height],
14328
+ ["flexBasis", YogaValueKind.FlexBasis],
14329
+ ["minWidth", YogaValueKind.MinWidth],
14330
+ ["minHeight", YogaValueKind.MinHeight],
14331
+ ["maxWidth", YogaValueKind.MaxWidth],
14332
+ ["maxHeight", YogaValueKind.MaxHeight]
14333
+ ]) {
14334
+ contentStyles[key] = value(kind);
14335
+ }
14336
+ for (const [suffix, edge] of [
14337
+ ["", Edge2.All],
14338
+ ["X", Edge2.Horizontal],
14339
+ ["Y", Edge2.Vertical],
14340
+ ["Top", Edge2.Top],
14341
+ ["Right", Edge2.Right],
14342
+ ["Bottom", Edge2.Bottom],
14343
+ ["Left", Edge2.Left]
14344
+ ]) {
14345
+ contentStyles[`padding${suffix}`] = value(YogaValueKind.Padding, edge);
14346
+ contentStyles[`margin${suffix}`] = value(YogaValueKind.Margin, edge);
14347
+ }
14348
+ contentStyles.gap = value(YogaValueKind.Gap, Gutter2.All);
14349
+ contentStyles.rowGap = value(YogaValueKind.Gap, Gutter2.Row);
14350
+ contentStyles.columnGap = value(YogaValueKind.Gap, Gutter2.Column);
14351
+ }
14352
+
14353
+ class ScrollBoxContent extends ScrollBoxSizedPart {
14354
+ static keys = ["backgroundColor", "onSizeChange", "viewportCulling", ...Object.keys(contentStyles)];
14355
+ styles = new Map;
14356
+ constructor(box) {
14357
+ super(box);
14358
+ for (const key of Object.keys(contentStyles)) {
14359
+ const size = key === "width" || key === "height";
14360
+ Object.defineProperty(this, key, {
14361
+ configurable: true,
14362
+ enumerable: false,
14363
+ get: () => size ? this.rect()[key] : this.styles.get(key),
14364
+ set: (input) => this.setStyle(key, input)
14365
+ });
13902
14366
  }
13903
14367
  }
14368
+ rect() {
14369
+ const { content, offset } = this.box._scrollState();
14370
+ return {
14371
+ x: this.box.screenX + content.x - offset[0],
14372
+ y: this.box.screenY + content.y - offset[1],
14373
+ width: content.width,
14374
+ height: content.height
14375
+ };
14376
+ }
14377
+ setStyle(key, input) {
14378
+ this.box._setContentStyle((scene, node) => contentStyles[key](scene, node, input));
14379
+ if (input == null)
14380
+ this.styles.delete(key);
14381
+ else
14382
+ this.styles.set(key, input);
14383
+ }
14384
+ get _row() {
14385
+ const direction = parseFlexDirection2(this.styles.get("flexDirection"));
14386
+ return direction === FlexDirection2.Row || direction === FlexDirection2.RowReverse;
14387
+ }
13904
14388
  get viewportCulling() {
13905
- return this._viewportCulling;
14389
+ return this.box.viewportCulling;
13906
14390
  }
13907
14391
  set viewportCulling(value) {
13908
- if (this.isFreed())
14392
+ this.box.viewportCulling = value;
14393
+ }
14394
+ add(obj, index) {
14395
+ return this.box.add(obj, index);
14396
+ }
14397
+ insertBefore(obj, anchor) {
14398
+ return this.box.insertBefore(obj, anchor);
14399
+ }
14400
+ remove(child) {
14401
+ this.box.remove(child);
14402
+ }
14403
+ getChildren() {
14404
+ return this.box.getChildren();
14405
+ }
14406
+ getChildrenCount() {
14407
+ return this.box.getChildrenCount();
14408
+ }
14409
+ getRenderable(id) {
14410
+ return this.box.getRenderable(id);
14411
+ }
14412
+ findDescendantById(id) {
14413
+ return this.box.findDescendantById(id);
14414
+ }
14415
+ }
14416
+ var defaultTrack = RGBA2.fromHex("#252527");
14417
+ var defaultThumb = RGBA2.fromHex("#9a9ea3");
14418
+ var defaultArrowForeground2 = RGBA2.fromValues(1, 1, 1, 1);
14419
+ var defaultArrowBackground2 = RGBA2.fromValues(0, 0, 0, 0);
14420
+
14421
+ class ScrollBoxBar extends ScrollBoxPart {
14422
+ static keys = [
14423
+ "visible",
14424
+ "showArrows",
14425
+ "arrowOptions",
14426
+ "trackOptions",
14427
+ "onChange",
14428
+ "width",
14429
+ "height",
14430
+ "paddingLeft",
14431
+ "paddingTop",
14432
+ "position",
14433
+ "scrollStep"
14434
+ ];
14435
+ orientation;
14436
+ scrollStep = null;
14437
+ axis;
14438
+ policy = "auto";
14439
+ _showArrows = false;
14440
+ _arrowOptions = {};
14441
+ trackForeground = defaultThumb;
14442
+ trackBackground = defaultTrack;
14443
+ thickness = 1;
14444
+ gap = 0;
14445
+ overlay = false;
14446
+ _onChange;
14447
+ constructor(box, orientation) {
14448
+ super(box, "change");
14449
+ this.orientation = orientation;
14450
+ this.axis = orientation === "vertical" ? 1 : 0;
14451
+ }
14452
+ rect() {
14453
+ const bar = this.box._scrollState().bars[this.axis];
14454
+ const arrows = this._showArrows ? 1 : 0;
14455
+ return this.axis === 1 ? {
14456
+ x: bar.track.x - this.gap,
14457
+ y: bar.track.y - arrows,
14458
+ width: bar.track.width + this.gap,
14459
+ height: bar.track.height + 2 * arrows
14460
+ } : {
14461
+ x: bar.track.x - arrows,
14462
+ y: bar.track.y - this.gap,
14463
+ width: bar.track.width + 2 * arrows,
14464
+ height: bar.track.height + this.gap
14465
+ };
14466
+ }
14467
+ _listening() {
14468
+ return this._onChange !== undefined || this.listenerCount("change") > 0;
14469
+ }
14470
+ _native() {
14471
+ return {
14472
+ policy: this.policy,
14473
+ overlay: this.overlay,
14474
+ thickness: this.thickness,
14475
+ gap: this.gap,
14476
+ arrows: this._showArrows,
14477
+ foregroundColor: this.trackForeground,
14478
+ backgroundColor: this.trackBackground
14479
+ };
14480
+ }
14481
+ _arrows() {
14482
+ const options = this._arrowOptions;
14483
+ const background = options.backgroundColor ?? undefined;
14484
+ const foreground = options.foregroundColor ?? background;
14485
+ const chars = options.arrowChars ?? {};
14486
+ return (this.axis === 1 ? ["up", "down"] : ["left", "right"]).map((direction) => ({
14487
+ attributes: options.attributes ?? 0,
14488
+ foregroundColor: RGBA2.clone(parseColor2(foreground || defaultArrowForeground2)),
14489
+ backgroundColor: RGBA2.clone(parseColor2(background || defaultArrowBackground2)),
14490
+ text: chars[direction]
14491
+ }));
14492
+ }
14493
+ _emitChange(position) {
14494
+ this._onChange?.(position);
14495
+ if (!this.box.isDestroyed)
14496
+ this.emit("change", { position });
14497
+ }
14498
+ get visible() {
14499
+ return this.box._scrollState().bars[this.axis].visible;
14500
+ }
14501
+ set visible(value) {
14502
+ this.setOption(() => this.policy = value == null ? "auto" : value ? "always" : "never");
14503
+ }
14504
+ resetVisibilityControl() {
14505
+ this.visible = null;
14506
+ }
14507
+ get onChange() {
14508
+ return this._onChange;
14509
+ }
14510
+ set onChange(handler) {
14511
+ this._onChange = handler ?? undefined;
14512
+ this.box._refreshScrollHook();
14513
+ }
14514
+ get showArrows() {
14515
+ return this._showArrows;
14516
+ }
14517
+ set showArrows(value) {
14518
+ this.setOption(() => this._showArrows = value ?? false);
14519
+ }
14520
+ set arrowOptions(options) {
14521
+ this._arrowOptions = { ...this._arrowOptions, ...options };
14522
+ if (!this.box.isDestroyed)
14523
+ this.box._applyScrollArrows(this.axis);
14524
+ }
14525
+ set trackOptions(options) {
14526
+ this.setOption(() => {
14527
+ if (options && "foregroundColor" in options) {
14528
+ this.trackForeground = RGBA2.clone(parseColor2(options.foregroundColor ?? defaultThumb));
14529
+ }
14530
+ if (options && "backgroundColor" in options) {
14531
+ this.trackBackground = RGBA2.clone(parseColor2(options.backgroundColor ?? defaultTrack));
14532
+ }
14533
+ });
14534
+ }
14535
+ get width() {
14536
+ return super.width;
14537
+ }
14538
+ set width(value) {
14539
+ if (this.axis === 1)
14540
+ this.setOption(() => this.thickness = Math.max(1, cells(value, 1)));
14541
+ }
14542
+ get height() {
14543
+ return super.height;
14544
+ }
14545
+ set height(value) {
14546
+ if (this.axis === 0)
14547
+ this.setOption(() => this.thickness = Math.max(1, cells(value, 1)));
14548
+ }
14549
+ set paddingLeft(value) {
14550
+ if (this.axis === 1)
14551
+ this.setOption(() => this.gap = cells(value, 0));
14552
+ }
14553
+ set paddingTop(value) {
14554
+ if (this.axis === 0)
14555
+ this.setOption(() => this.gap = cells(value, 0));
14556
+ }
14557
+ set position(value) {
14558
+ this.setOption(() => this.overlay = value === "absolute");
14559
+ }
14560
+ setOption(change) {
14561
+ if (this.box.isDestroyed)
13909
14562
  return;
13910
- this._ctx.nativeScene.setViewport(this, value ? this.viewport : null);
13911
- this._viewportCulling = value;
14563
+ change();
14564
+ this.box._applyScrollOptions();
14565
+ }
14566
+ get scrollSize() {
14567
+ const { content } = this.box._scrollState();
14568
+ return this.axis === 1 ? content.height : content.width;
14569
+ }
14570
+ get viewportSize() {
14571
+ const { viewport } = this.box._scrollState();
14572
+ return this.axis === 1 ? viewport.height : viewport.width;
14573
+ }
14574
+ get scrollPosition() {
14575
+ return this.box._scrollState().offset[this.axis];
14576
+ }
14577
+ set scrollPosition(value) {
14578
+ this.box._scrollAxis(this.axis, value, false);
14579
+ }
14580
+ scrollBy(delta, unit = "absolute") {
14581
+ this.box._scrollAxis(this.axis, scrollUnitSize(this, unit) * delta, true, true);
14582
+ }
14583
+ handleKeyPress(key) {
14584
+ return ScrollBarRenderable.prototype.handleKeyPress.call(this, key);
13912
14585
  }
13913
14586
  }
14587
+ function cells(value, fallback) {
14588
+ return typeof value === "number" && Number.isFinite(value) ? Math.max(0, Math.min(255, Math.trunc(value))) : fallback;
14589
+ }
14590
+
14591
+ // src/renderables/ScrollBox.ts
13914
14592
  var SCROLLBOX_PADDING_KEYS = [
13915
14593
  "padding",
13916
14594
  "paddingX",
@@ -13947,18 +14625,20 @@ class ScrollBoxRenderable extends BoxRenderable2 {
13947
14625
  update: {
13948
14626
  idle: this.prototype.onUpdate,
13949
14627
  active: (renderable) => renderable["isAutoScrolling"]
14628
+ },
14629
+ scroll: {
14630
+ active: (renderable) => renderable.scrollHook,
14631
+ notify: (renderable) => renderable.notifyScroll()
13950
14632
  }
13951
14633
  }
13952
14634
  };
13953
- static idCounter = 0;
13954
- internalId = 0;
13955
14635
  wrapper;
13956
14636
  viewport;
13957
14637
  content;
13958
14638
  horizontalScrollBar;
13959
14639
  verticalScrollBar;
13960
14640
  static defaultFocusable = true;
13961
- selectionListener;
14641
+ selectionListener = () => this.stopAutoScroll();
13962
14642
  autoScrollMouseX = 0;
13963
14643
  autoScrollMouseY = 0;
13964
14644
  autoScrollThresholdVertical = 3;
@@ -13973,126 +14653,70 @@ class ScrollBoxRenderable extends BoxRenderable2 {
13973
14653
  scrollAccumulatorX = 0;
13974
14654
  scrollAccumulatorY = 0;
13975
14655
  _stickyScroll;
13976
- _stickyScrollTop = false;
13977
- _stickyScrollBottom = false;
13978
- _stickyScrollLeft = false;
13979
- _stickyScrollRight = false;
13980
14656
  _stickyStart;
13981
- _hasManualScroll = false;
13982
- _isApplyingStickyScroll = false;
13983
14657
  scrollAccel;
14658
+ axes;
14659
+ _viewportCulling;
14660
+ state = emptySceneScrollState();
14661
+ stateRevision;
14662
+ scrollHook = false;
14663
+ configured = false;
14664
+ barPress;
14665
+ layoutCallbacks = [];
14666
+ anchorToken;
13984
14667
  get stickyScroll() {
13985
14668
  return this._stickyScroll;
13986
14669
  }
13987
14670
  set stickyScroll(value) {
13988
- this._stickyScroll = value;
13989
- this.updateStickyState();
14671
+ this.setScrollOption(() => this._stickyScroll = value);
13990
14672
  }
13991
14673
  get stickyStart() {
13992
14674
  return this._stickyStart;
13993
14675
  }
13994
14676
  set stickyStart(value) {
13995
- this._stickyStart = value;
13996
- this.updateStickyState();
14677
+ this.setScrollOption(() => this._stickyStart = value);
14678
+ }
14679
+ setScrollOption(change) {
14680
+ const previous = [this._stickyScroll, this._stickyStart, this._viewportCulling];
14681
+ change();
14682
+ try {
14683
+ this._applyScrollOptions();
14684
+ } catch (error) {
14685
+ [this._stickyScroll, this._stickyStart, this._viewportCulling] = previous;
14686
+ throw error;
14687
+ }
14688
+ }
14689
+ get scrollX() {
14690
+ return this.axes.x;
14691
+ }
14692
+ set scrollX(value) {
14693
+ this.axes.x = value ?? false;
14694
+ this._applyScrollOptions();
14695
+ }
14696
+ get scrollY() {
14697
+ return this.axes.y;
14698
+ }
14699
+ set scrollY(value) {
14700
+ this.axes.y = value ?? true;
14701
+ this._applyScrollOptions();
13997
14702
  }
13998
14703
  get scrollTop() {
13999
- return this.verticalScrollBar.scrollPosition;
14704
+ return this._scrollState().offset[1];
14000
14705
  }
14001
14706
  set scrollTop(value) {
14002
- this.verticalScrollBar.scrollPosition = value;
14003
- this.updateStickyState();
14707
+ this._scrollAxis(1, value, false);
14004
14708
  }
14005
14709
  get scrollLeft() {
14006
- return this.horizontalScrollBar.scrollPosition;
14710
+ return this._scrollState().offset[0];
14007
14711
  }
14008
14712
  set scrollLeft(value) {
14009
- this.horizontalScrollBar.scrollPosition = value;
14010
- this.updateStickyState();
14713
+ this._scrollAxis(0, value, false);
14011
14714
  }
14012
14715
  get scrollWidth() {
14013
- return this.horizontalScrollBar.scrollSize;
14716
+ return this._scrollState().content.width;
14014
14717
  }
14015
14718
  get scrollHeight() {
14016
- return this.verticalScrollBar.scrollSize;
14017
- }
14018
- updateStickyState() {
14019
- if (this.isDestroyed)
14020
- return;
14021
- if (!this._stickyScroll) {
14022
- this.syncManualScrollState();
14023
- return;
14024
- }
14025
- const maxScrollTop = Math.max(0, this.scrollHeight - this.viewport.height);
14026
- const maxScrollLeft = Math.max(0, this.scrollWidth - this.viewport.width);
14027
- if (this.scrollTop <= 0) {
14028
- this._stickyScrollTop = true;
14029
- this._stickyScrollBottom = false;
14030
- } else if (this.scrollTop >= maxScrollTop) {
14031
- this._stickyScrollTop = false;
14032
- this._stickyScrollBottom = true;
14033
- } else {
14034
- this._stickyScrollTop = false;
14035
- this._stickyScrollBottom = false;
14036
- }
14037
- if (this.scrollLeft <= 0) {
14038
- this._stickyScrollLeft = true;
14039
- this._stickyScrollRight = false;
14040
- } else if (this.scrollLeft >= maxScrollLeft) {
14041
- this._stickyScrollLeft = false;
14042
- this._stickyScrollRight = true;
14043
- } else {
14044
- this._stickyScrollLeft = false;
14045
- this._stickyScrollRight = false;
14046
- }
14047
- this.syncManualScrollState();
14048
- }
14049
- syncManualScrollState() {
14050
- if (this.isDestroyed)
14051
- return;
14052
- if (!this._stickyScroll) {
14053
- this._hasManualScroll = false;
14054
- return;
14055
- }
14056
- const maxScrollTop = Math.max(0, this.scrollHeight - this.viewport.height);
14057
- const maxScrollLeft = Math.max(0, this.scrollWidth - this.viewport.width);
14058
- const hasScrollableContent = maxScrollTop > 1 || maxScrollLeft > 1;
14059
- if (this._isApplyingStickyScroll) {
14060
- if (this._hasManualScroll && hasScrollableContent && this.isAtStickyPosition()) {
14061
- this._hasManualScroll = false;
14062
- }
14063
- return;
14064
- }
14065
- this._hasManualScroll = hasScrollableContent && !this.isAtStickyPosition();
14066
- }
14067
- applyStickyStart(stickyStart) {
14068
- const wasApplyingStickyScroll = this._isApplyingStickyScroll;
14069
- this._isApplyingStickyScroll = true;
14070
- try {
14071
- switch (stickyStart) {
14072
- case "top":
14073
- this._stickyScrollTop = true;
14074
- this._stickyScrollBottom = false;
14075
- this.verticalScrollBar.scrollPosition = 0;
14076
- break;
14077
- case "bottom":
14078
- this._stickyScrollTop = false;
14079
- this._stickyScrollBottom = true;
14080
- this.verticalScrollBar.scrollPosition = Math.max(0, this.scrollHeight - this.viewport.height);
14081
- break;
14082
- case "left":
14083
- this._stickyScrollLeft = true;
14084
- this._stickyScrollRight = false;
14085
- this.horizontalScrollBar.scrollPosition = 0;
14086
- break;
14087
- case "right":
14088
- this._stickyScrollLeft = false;
14089
- this._stickyScrollRight = true;
14090
- this.horizontalScrollBar.scrollPosition = Math.max(0, this.scrollWidth - this.viewport.width);
14091
- break;
14092
- }
14093
- } finally {
14094
- this._isApplyingStickyScroll = wasApplyingStickyScroll;
14095
- }
14719
+ return this._scrollState().content.height;
14096
14720
  }
14097
14721
  constructor(ctx, options) {
14098
14722
  const {
@@ -14117,114 +14741,183 @@ class ScrollBoxRenderable extends BoxRenderable2 {
14117
14741
  };
14118
14742
  const sanitizedRootBoxOptions = stripScrollBoxPadding(rootBoxOptions);
14119
14743
  const sanitizedRootOptions = rootOptions ? stripScrollBoxPadding(rootOptions) : undefined;
14120
- const mergedContentOptions = {
14121
- ...forwardedContentPadding,
14122
- ...contentOptions
14123
- };
14124
14744
  super(ctx, {
14125
14745
  flexDirection: "row",
14126
14746
  alignItems: "stretch",
14127
14747
  ...sanitizedRootBoxOptions,
14128
- ...sanitizedRootOptions
14748
+ ...sanitizedRootOptions,
14749
+ overflow: "hidden"
14129
14750
  });
14130
- const children = [];
14131
14751
  try {
14132
- this.internalId = ScrollBoxRenderable.idCounter++;
14133
14752
  this._stickyScroll = stickyScroll;
14134
14753
  this._stickyStart = stickyStart;
14135
14754
  this.scrollAccel = scrollAcceleration ?? new LinearScrollAccel2;
14136
- this.wrapper = new BoxRenderable2(ctx, {
14137
- flexDirection: "column",
14138
- flexGrow: 1,
14139
- ...wrapperOptions,
14140
- id: `scroll-box-wrapper-${this.internalId}`
14141
- });
14142
- children.push(this.wrapper);
14143
- super.add(this.wrapper);
14144
- this.viewport = new BoxRenderable2(ctx, {
14145
- flexDirection: "column",
14146
- flexGrow: 1,
14147
- overflow: "hidden",
14148
- onSizeChange: () => {
14149
- this.recalculateBarProps();
14150
- },
14151
- ...viewportOptions,
14152
- id: `scroll-box-viewport-${this.internalId}`
14153
- });
14154
- children.push(this.viewport);
14155
- this.wrapper.add(this.viewport);
14156
- this.content = new ContentRenderable(ctx, this.viewport, viewportCulling, {
14157
- alignSelf: "flex-start",
14158
- flexShrink: 0,
14159
- ...scrollX ? { minWidth: "100%" } : { minWidth: "100%", maxWidth: "100%" },
14160
- ...scrollY ? { minHeight: "100%" } : { minHeight: "100%", maxHeight: "100%" },
14161
- onSizeChange: () => {
14162
- this.recalculateBarProps();
14163
- },
14164
- ...mergedContentOptions,
14165
- id: `scroll-box-content-${this.internalId}`
14166
- });
14167
- children.push(this.content);
14168
- this.viewport.add(this.content);
14169
- this.verticalScrollBar = new ScrollBarRenderable(ctx, {
14170
- ...scrollbarOptions,
14171
- ...verticalScrollbarOptions,
14172
- arrowOptions: {
14173
- ...scrollbarOptions?.arrowOptions,
14174
- ...verticalScrollbarOptions?.arrowOptions
14175
- },
14176
- id: `scroll-box-vertical-scrollbar-${this.internalId}`,
14177
- orientation: "vertical",
14178
- onChange: (position) => {
14179
- if (this.isDestroyed)
14180
- return;
14181
- this.content.translateY = -position;
14182
- this.updateStickyState();
14183
- }
14184
- });
14185
- children.push(this.verticalScrollBar);
14186
- super.add(this.verticalScrollBar);
14187
- this.horizontalScrollBar = new ScrollBarRenderable(ctx, {
14188
- ...scrollbarOptions,
14189
- ...horizontalScrollbarOptions,
14190
- arrowOptions: {
14191
- ...scrollbarOptions?.arrowOptions,
14192
- ...horizontalScrollbarOptions?.arrowOptions
14193
- },
14194
- id: `scroll-box-horizontal-scrollbar-${this.internalId}`,
14195
- orientation: "horizontal",
14196
- onChange: (position) => {
14197
- if (this.isDestroyed)
14198
- return;
14199
- this.content.translateX = -position;
14200
- this.updateStickyState();
14201
- }
14202
- });
14203
- children.push(this.horizontalScrollBar);
14204
- this.wrapper.add(this.horizontalScrollBar);
14205
- this.recalculateBarProps();
14206
- if (stickyStart && stickyScroll) {
14207
- this.applyStickyStart(stickyStart);
14208
- }
14209
- this.selectionListener = () => {
14210
- if (this.isDestroyed)
14211
- return;
14212
- const selection = this._ctx.getSelection();
14213
- if (!selection || !selection.isDragging) {
14214
- this.stopAutoScroll();
14215
- }
14216
- };
14217
- this._ctx.on("selection", this.selectionListener);
14755
+ this.axes = { x: scrollX, y: scrollY };
14756
+ this._viewportCulling = viewportCulling;
14757
+ this.wrapper = new ScrollBoxWrapper(this);
14758
+ this.viewport = new ScrollBoxViewport(this);
14759
+ this.content = new ScrollBoxContent(this);
14760
+ this.verticalScrollBar = new ScrollBoxBar(this, "vertical");
14761
+ this.horizontalScrollBar = new ScrollBoxBar(this, "horizontal");
14762
+ this.wrapper._assign(wrapperOptions, ScrollBoxWrapper.keys);
14763
+ this.viewport._assign(viewportOptions, ScrollBoxViewport.keys);
14764
+ for (const [bar, own] of [
14765
+ [this.verticalScrollBar, verticalScrollbarOptions],
14766
+ [this.horizontalScrollBar, horizontalScrollbarOptions]
14767
+ ]) {
14768
+ bar._assign({ ...scrollbarOptions, ...own, arrowOptions: { ...scrollbarOptions?.arrowOptions, ...own?.arrowOptions } }, ScrollBoxBar.keys);
14769
+ }
14770
+ this.configured = true;
14771
+ this._applyScrollOptions();
14772
+ this._applyScrollArrows(0);
14773
+ this._applyScrollArrows(1);
14774
+ this.content._assign({ ...forwardedContentPadding, ...contentOptions }, ScrollBoxContent.keys);
14775
+ this._refreshScrollHook();
14218
14776
  this.setNativeScenePaint();
14219
14777
  } catch (error) {
14220
- this.abortConstruction(error, (run) => {
14221
- run(() => this.destroySelf());
14222
- for (let index = children.length - 1;index >= 0; index--) {
14223
- run(() => children[index].destroyRecursively());
14224
- }
14225
- });
14778
+ this.abortConstruction(error, (run) => run(() => this.destroySelf()));
14226
14779
  }
14227
14780
  }
14781
+ _applyScrollOptions() {
14782
+ if (!this.configured || this.isFreed())
14783
+ return;
14784
+ const sticky = this._stickyScroll && this._stickyStart;
14785
+ this._ctx.nativeScene.setScroll(this, {
14786
+ scrollX: this.axes.x,
14787
+ scrollY: this.axes.y,
14788
+ follow: sticky ? this._stickyStart : "none",
14789
+ culling: this._viewportCulling,
14790
+ padding: this.viewport._edges(),
14791
+ fills: [this.wrapper._fill(), this.viewport._fill(), this.content._fill()],
14792
+ bars: [this.horizontalScrollBar._native(), this.verticalScrollBar._native()]
14793
+ });
14794
+ this.requestRender();
14795
+ }
14796
+ _applyScrollArrows(axis) {
14797
+ if (!this.configured || this.isFreed())
14798
+ return;
14799
+ const bar = axis === 1 ? this.verticalScrollBar : this.horizontalScrollBar;
14800
+ bar._arrows().forEach((arrow, end) => this._ctx.nativeScene.setScrollArrow(this, axis, end, arrow));
14801
+ this.requestRender();
14802
+ }
14803
+ _setContentStyle(apply) {
14804
+ if (this.isFreed())
14805
+ return;
14806
+ apply(this._ctx.nativeScene, this);
14807
+ this.requestRender();
14808
+ }
14809
+ _scrollState() {
14810
+ if (this.isFreed())
14811
+ return this.state;
14812
+ const revision = this._ctx.nativeScene.observedLayoutRevision;
14813
+ if (revision !== undefined && revision === this.stateRevision)
14814
+ return this.state;
14815
+ this.state = this._ctx.nativeScene.getScroll(this);
14816
+ this.stateRevision = revision;
14817
+ return this.state;
14818
+ }
14819
+ _wrapperRect() {
14820
+ const { viewport, bars } = this._scrollState();
14821
+ const horizontal = bars[0];
14822
+ const gutter = horizontal.visible ? horizontal.track.y + horizontal.track.height - viewport.y - viewport.height : 0;
14823
+ return { ...viewport, height: viewport.height + Math.max(0, gutter) };
14824
+ }
14825
+ _scrollAxis(axis, value, relative, reapply = false) {
14826
+ if (this.isFreed())
14827
+ return;
14828
+ this.assertMutable();
14829
+ value ??= 0;
14830
+ if (Number.isNaN(value))
14831
+ throw new RangeError("Scene scroll positions must be finite numbers");
14832
+ const x = axis === 0 ? value : 0;
14833
+ const y = axis === 1 ? value : 0;
14834
+ this.commitScroll(() => this._ctx.nativeScene.scrollTo(this, x, y, axis !== 0 || relative, axis !== 1 || relative, reapply));
14835
+ }
14836
+ commitScroll(scroll) {
14837
+ const before = this._scrollState().offset;
14838
+ const state = scroll();
14839
+ this.state = state;
14840
+ this.stateRevision = this._ctx.nativeScene.observedLayoutRevision;
14841
+ const moved = (state.offset[0] !== before[0] ? 1 : 0) | (state.offset[1] !== before[1] ? 2 : 0);
14842
+ if (moved)
14843
+ this.requestRender();
14844
+ this.notifyOffsets(state, moved);
14845
+ }
14846
+ notifyOffsets(state, moved) {
14847
+ for (const axis of [1, 0]) {
14848
+ if ((moved & axis + 1) === 0)
14849
+ continue;
14850
+ (axis === 1 ? this.verticalScrollBar : this.horizontalScrollBar)._emitChange(state.offset[axis]);
14851
+ if (this.isDestroyed)
14852
+ return;
14853
+ }
14854
+ }
14855
+ listening() {
14856
+ return this.verticalScrollBar?._listening() || this.horizontalScrollBar?._listening() || this.content?._listening() || this.viewport?._listening() || this.layoutCallbacks.length > 0;
14857
+ }
14858
+ _refreshScrollHook(adding = false) {
14859
+ if (!this.configured || this.isFreed())
14860
+ return;
14861
+ const listening = adding || this.listening();
14862
+ if (listening === this.scrollHook)
14863
+ return;
14864
+ this.scrollHook = listening;
14865
+ this.refreshNativeSceneHooks();
14866
+ }
14867
+ notifyScroll() {
14868
+ const state = this._scrollState();
14869
+ this.notifyOffsets(state, state.changes);
14870
+ if (!this.isDestroyed && state.changes & 8)
14871
+ this.viewport._emitResize();
14872
+ if (!this.isDestroyed && state.changes & 4)
14873
+ this.content._emitResize();
14874
+ if (this.isDestroyed || !(state.changes & 16))
14875
+ return;
14876
+ const frame = this._ctx.frameId;
14877
+ const due = this.layoutCallbacks.filter((entry) => entry.frame < frame);
14878
+ this.layoutCallbacks = this.layoutCallbacks.filter((entry) => entry.frame >= frame);
14879
+ if (this.layoutCallbacks.length > 0)
14880
+ this._ctx.nativeScene.scrollRequest(this, "layout", null);
14881
+ let failure;
14882
+ for (const { callback } of due) {
14883
+ if (this.isDestroyed)
14884
+ break;
14885
+ try {
14886
+ callback();
14887
+ } catch (error) {
14888
+ failure ??= { error };
14889
+ }
14890
+ }
14891
+ this._refreshScrollHook();
14892
+ if (failure)
14893
+ throw failure.error;
14894
+ }
14895
+ afterLayout(callback) {
14896
+ if (this.isFreed())
14897
+ return;
14898
+ this.assertMutable();
14899
+ this.layoutCallbacks.push({ frame: this._ctx.frameId, callback });
14900
+ this._refreshScrollHook();
14901
+ this._ctx.nativeScene.scrollRequest(this, "layout", null);
14902
+ this.requestRender();
14903
+ }
14904
+ anchor(node) {
14905
+ if (this.isFreed())
14906
+ return () => {};
14907
+ this.assertMutable();
14908
+ this._ctx.nativeScene.scrollRequest(this, "anchor", node);
14909
+ const token = {};
14910
+ this.anchorToken = token;
14911
+ return () => {
14912
+ if (this.anchorToken !== token || this.isFreed())
14913
+ return;
14914
+ this._ctx.nativeScene.scrollRequest(this, "anchor", null);
14915
+ this.anchorToken = undefined;
14916
+ };
14917
+ }
14918
+ get primaryAxis() {
14919
+ return this.content._row ? "row" : "column";
14920
+ }
14228
14921
  onUpdate(deltaTime) {
14229
14922
  this.handleAutoScroll(deltaTime);
14230
14923
  }
@@ -14238,120 +14931,42 @@ class ScrollBoxRenderable extends BoxRenderable2 {
14238
14931
  this.horizontalScrollBar.scrollBy(delta.x, unit);
14239
14932
  }
14240
14933
  }
14241
- scrollChildIntoView(childId) {
14242
- const child = this.content.findDescendantById(childId);
14243
- if (!child)
14934
+ scrollChildIntoView(child, options = {}) {
14935
+ const node = typeof child === "string" ? this.findDescendantById(child) : child;
14936
+ if (!node || this.isFreed())
14244
14937
  return;
14245
- const getNearestDelta = (elementStart, elementEnd, viewportStart, viewportEnd) => {
14246
- const elementSize = elementEnd - elementStart;
14247
- const viewportSize = viewportEnd - viewportStart;
14248
- const elementStartOutside = elementStart < viewportStart;
14249
- const elementEndOutside = elementEnd > viewportEnd;
14250
- if (elementStartOutside && elementEndOutside) {
14251
- return 0;
14252
- }
14253
- if (elementStartOutside && elementSize < viewportSize || elementEndOutside && elementSize > viewportSize) {
14254
- return elementStart - viewportStart;
14255
- }
14256
- if (elementStartOutside && elementSize > viewportSize || elementEndOutside && elementSize < viewportSize) {
14257
- return elementEnd - viewportEnd;
14258
- }
14259
- return 0;
14260
- };
14261
- const childTop = child.y;
14262
- const childBottom = child.y + child.height;
14263
- const viewportTop = this.viewport.y;
14264
- const viewportBottom = this.viewport.y + this.viewport.height;
14265
- const dy = getNearestDelta(childTop, childBottom, viewportTop, viewportBottom);
14266
- const childLeft = child.x;
14267
- const childRight = child.x + child.width;
14268
- const viewportLeft = this.viewport.x;
14269
- const viewportRight = this.viewport.x + this.viewport.width;
14270
- const dx = getNearestDelta(childLeft, childRight, viewportLeft, viewportRight);
14271
- if (dx !== 0 || dy !== 0) {
14272
- this.scrollBy({ x: dx, y: dy });
14273
- }
14938
+ this.assertMutable();
14939
+ this.commitScroll(() => this._ctx.nativeScene.scrollRequest(this, "into-view", node, options.align, options.inset));
14274
14940
  }
14275
14941
  scrollTo(position) {
14276
14942
  if (typeof position === "number") {
14277
- this.scrollTop = position;
14943
+ this._scrollAxis(1, position, false, true);
14278
14944
  } else {
14279
- this.scrollTop = position.y;
14945
+ this._scrollAxis(1, position.y, false, true);
14280
14946
  if (this.isDestroyed)
14281
14947
  return;
14282
- this.scrollLeft = position.x;
14283
- }
14284
- }
14285
- isAtStickyPosition() {
14286
- if (!this._stickyScroll || !this._stickyStart) {
14287
- return false;
14948
+ this._scrollAxis(0, position.x, false, true);
14288
14949
  }
14289
- const maxScrollTop = Math.max(0, this.scrollHeight - this.viewport.height);
14290
- const maxScrollLeft = Math.max(0, this.scrollWidth - this.viewport.width);
14291
- switch (this._stickyStart) {
14292
- case "top":
14293
- return this.scrollTop === 0;
14294
- case "bottom":
14295
- return this.scrollTop >= maxScrollTop;
14296
- case "left":
14297
- return this.scrollLeft === 0;
14298
- case "right":
14299
- return this.scrollLeft >= maxScrollLeft;
14300
- default:
14301
- return false;
14302
- }
14303
- }
14304
- isAtStickyReengagePoint(stickyStart, maxScrollTop, maxScrollLeft) {
14305
- switch (stickyStart) {
14306
- case "top":
14307
- return maxScrollTop > 0 && this.scrollTop <= 0;
14308
- case "bottom":
14309
- return maxScrollTop > 0 && this.scrollTop >= maxScrollTop - 1;
14310
- case "left":
14311
- return maxScrollLeft > 0 && this.scrollLeft <= 0;
14312
- case "right":
14313
- return maxScrollLeft > 0 && this.scrollLeft >= maxScrollLeft - 1;
14314
- }
14315
- }
14316
- add(obj, index) {
14317
- return this.content.add(obj, index);
14318
- }
14319
- insertBefore(obj, anchor) {
14320
- return this.content.insertBefore(obj, anchor);
14321
- }
14322
- remove(child) {
14323
- if (child.parent === this) {
14324
- super.remove(child);
14325
- return;
14326
- }
14327
- this.content.remove(child);
14328
- }
14329
- getChildren() {
14330
- return this.content.getChildren();
14331
- }
14332
- getRenderable(id) {
14333
- return this.content.getRenderable(id);
14334
14950
  }
14335
14951
  scrollByWheel(event) {
14336
14952
  const dir = wheelDirection(event);
14337
14953
  const vertical = dir === "up" || dir === "down";
14338
14954
  if (!vertical && dir !== "left" && dir !== "right")
14339
14955
  return false;
14340
- const bar = vertical ? this.verticalScrollBar : this.horizontalScrollBar;
14956
+ const axis = vertical ? 1 : 0;
14341
14957
  const sign = dir === "up" || dir === "left" ? -1 : 1;
14342
- const position = bar.scrollPosition;
14343
- if (sign < 0 ? position <= 0 : position >= bar.scrollSize - bar.viewportSize)
14958
+ const { offset, max } = this._scrollState();
14959
+ const position = offset[axis];
14960
+ if (sign < 0 ? position <= 0 : position >= max[axis])
14344
14961
  return false;
14345
14962
  let remainder = vertical ? this.scrollAccumulatorY : this.scrollAccumulatorX;
14346
14963
  if (remainder * sign < 0)
14347
14964
  remainder = 0;
14348
14965
  remainder += sign * (event.scroll?.delta ?? 0) * this.scrollAccel.tick(Date.now());
14349
14966
  const step = Math.trunc(remainder);
14350
- if (step !== 0 && vertical)
14351
- this.scrollTop = position + step;
14352
- else if (step !== 0)
14353
- this.scrollLeft = position + step;
14354
- remainder = bar.scrollPosition - position === step ? remainder - step : 0;
14967
+ if (step !== 0)
14968
+ this._scrollAxis(axis, position + step, false);
14969
+ remainder = this._scrollState().offset[axis] - position === step ? remainder - step : 0;
14355
14970
  if (vertical)
14356
14971
  this.scrollAccumulatorY = remainder;
14357
14972
  else
@@ -14361,23 +14976,97 @@ class ScrollBoxRenderable extends BoxRenderable2 {
14361
14976
  onMouseEvent(event) {
14362
14977
  if (event.type === "scroll")
14363
14978
  scrollOnce(event, this, () => this.scrollByWheel(event));
14979
+ if (this.handleBarMouse(event))
14980
+ return;
14364
14981
  if (event.type === "drag" && event.isDragging) {
14365
14982
  this.updateAutoScroll(event.x, event.y);
14366
14983
  } else if (event.type === "up") {
14367
14984
  this.stopAutoScroll();
14368
14985
  }
14369
14986
  }
14370
- handleKeyPress(key) {
14371
- if (this.verticalScrollBar.handleKeyPress(key)) {
14372
- this.scrollAccel.reset();
14373
- this.resetScrollAccumulators();
14374
- this.syncManualScrollState();
14987
+ handleBarMouse(event) {
14988
+ const press = this.barPress;
14989
+ if (press && (event.type === "drag" || event.type === "up" || event.type === "drag-end")) {
14990
+ if ("offset" in press && event.type !== "drag-end")
14991
+ this.dragThumb(press, event);
14992
+ if (event.type === "up")
14993
+ this.endBarPress();
14994
+ event.stopPropagation();
14995
+ return true;
14996
+ }
14997
+ if (event.type !== "down" || event.button !== 0 || event.target !== this)
14998
+ return false;
14999
+ const { bars } = this._scrollState();
15000
+ for (const axis of [1, 0]) {
15001
+ const bar = bars[axis];
15002
+ if (!bar.visible)
15003
+ continue;
15004
+ const part = axis === 1 ? this.verticalScrollBar : this.horizontalScrollBar;
15005
+ const inside = (rect) => event.x >= rect.x && event.x < rect.x + rect.width && event.y >= rect.y && event.y < rect.y + rect.height;
15006
+ const arrow = part.showArrows ? inside(bar.startArrow) ? -1 : inside(bar.endArrow) ? 1 : 0 : 0;
15007
+ if (arrow === 0 && !inside(bar.track))
15008
+ continue;
15009
+ event.stopPropagation();
15010
+ event.preventDefault();
15011
+ this.endBarPress();
15012
+ if (arrow !== 0)
15013
+ this.pressArrow(axis, arrow, part);
15014
+ else
15015
+ this.pressTrack(axis, event);
14375
15016
  return true;
14376
15017
  }
14377
- if (this.horizontalScrollBar.handleKeyPress(key)) {
15018
+ return false;
15019
+ }
15020
+ pressArrow(axis, arrow, part) {
15021
+ const press = { axis, arrow, timer: undefined };
15022
+ this.barPress = press;
15023
+ const step = (amount, delay) => {
15024
+ part.scrollBy(arrow * amount, "viewport");
15025
+ if (this.barPress !== press)
15026
+ return;
15027
+ press.timer = this._ctx.clock.setTimeout(() => step(delay === 500 ? 0.5 : 0.2, 200), delay);
15028
+ };
15029
+ step(0.5, 500);
15030
+ }
15031
+ thumbPointer(axis, event) {
15032
+ const bar = this._scrollState().bars[axis];
15033
+ const along = axis === 1 ? event.y - bar.track.y : event.x - bar.track.x;
15034
+ const length = axis === 1 ? bar.track.height : bar.track.width;
15035
+ return {
15036
+ at: Math.max(0, Math.min(length, along)) * 2,
15037
+ length: length * 2,
15038
+ start: bar.thumbStart,
15039
+ size: bar.thumbSize
15040
+ };
15041
+ }
15042
+ pressTrack(axis, event) {
15043
+ let thumb = this.thumbPointer(axis, event);
15044
+ const inThumb = thumb.at >= Math.floor(thumb.start / 2) * 2 && thumb.at < Math.ceil((thumb.start + thumb.size) / 2) * 2;
15045
+ if (!inThumb) {
15046
+ const max = this._scrollState().max[axis];
15047
+ this._scrollAxis(axis, thumb.length === 0 ? 0 : thumb.at / thumb.length * max, false);
15048
+ if (this.isDestroyed)
15049
+ return;
15050
+ thumb = this.thumbPointer(axis, event);
15051
+ }
15052
+ this.barPress = { axis, offset: Math.max(0, Math.min(thumb.size, thumb.at - thumb.start)) };
15053
+ }
15054
+ dragThumb(press, event) {
15055
+ const thumb = this.thumbPointer(press.axis, event);
15056
+ const span = Math.max(0, thumb.length - thumb.size);
15057
+ const start = Math.max(0, Math.min(span, thumb.at - press.offset));
15058
+ this._scrollAxis(press.axis, span === 0 ? 0 : start / span * this._scrollState().max[press.axis], false);
15059
+ }
15060
+ endBarPress() {
15061
+ const press = this.barPress;
15062
+ this.barPress = undefined;
15063
+ if (press && "timer" in press && press.timer !== undefined)
15064
+ this._ctx.clock.clearTimeout(press.timer);
15065
+ }
15066
+ handleKeyPress(key) {
15067
+ if (this.verticalScrollBar.handleKeyPress(key) || this.horizontalScrollBar.handleKeyPress(key)) {
14378
15068
  this.scrollAccel.reset();
14379
15069
  this.resetScrollAccumulators();
14380
- this.syncManualScrollState();
14381
15070
  return true;
14382
15071
  }
14383
15072
  return false;
@@ -14387,12 +15076,15 @@ class ScrollBoxRenderable extends BoxRenderable2 {
14387
15076
  this.scrollAccumulatorY = 0;
14388
15077
  }
14389
15078
  startAutoScroll(mouseX, mouseY) {
15079
+ if (this.isDestroyed)
15080
+ return;
14390
15081
  this.stopAutoScroll();
14391
15082
  this.autoScrollMouseX = mouseX;
14392
15083
  this.autoScrollMouseY = mouseY;
14393
15084
  this.cachedAutoScrollSpeed = this.getAutoScrollSpeed(mouseX, mouseY);
14394
15085
  this.isAutoScrolling = true;
14395
15086
  this.live = true;
15087
+ this._ctx.on("selection", this.selectionListener);
14396
15088
  this.refreshNativeSceneHooks();
14397
15089
  }
14398
15090
  updateAutoScroll(mouseX, mouseY) {
@@ -14413,6 +15105,7 @@ class ScrollBoxRenderable extends BoxRenderable2 {
14413
15105
  this.autoScrollAccumulatorX = 0;
14414
15106
  this.autoScrollAccumulatorY = 0;
14415
15107
  if (wasAutoScrolling) {
15108
+ this._ctx.off("selection", this.selectionListener);
14416
15109
  this.live = false;
14417
15110
  this.refreshNativeSceneHooks();
14418
15111
  }
@@ -14460,8 +15153,7 @@ class ScrollBoxRenderable extends BoxRenderable2 {
14460
15153
  if (distToLeft <= this.autoScrollThresholdHorizontal) {
14461
15154
  return this.scrollLeft > 0 ? -1 : 0;
14462
15155
  } else if (distToRight <= this.autoScrollThresholdHorizontal) {
14463
- const maxScrollLeft = this.scrollWidth - this.viewport.width;
14464
- return this.scrollLeft < maxScrollLeft ? 1 : 0;
15156
+ return this.scrollLeft < this._scrollState().max[0] ? 1 : 0;
14465
15157
  }
14466
15158
  return 0;
14467
15159
  }
@@ -14472,8 +15164,7 @@ class ScrollBoxRenderable extends BoxRenderable2 {
14472
15164
  if (distToTop <= this.autoScrollThresholdVertical) {
14473
15165
  return this.scrollTop > 0 ? -1 : 0;
14474
15166
  } else if (distToBottom <= this.autoScrollThresholdVertical) {
14475
- const maxScrollTop = this.scrollHeight - this.viewport.height;
14476
- return this.scrollTop < maxScrollTop ? 1 : 0;
15167
+ return this.scrollTop < this._scrollState().max[1] ? 1 : 0;
14477
15168
  }
14478
15169
  return 0;
14479
15170
  }
@@ -14493,115 +15184,31 @@ class ScrollBoxRenderable extends BoxRenderable2 {
14493
15184
  return this.autoScrollSpeedSlow;
14494
15185
  }
14495
15186
  }
14496
- recalculateBarProps() {
14497
- if (this.isDestroyed)
14498
- return;
14499
- const wasApplyingStickyScroll = this._isApplyingStickyScroll;
14500
- this._isApplyingStickyScroll = true;
14501
- try {
14502
- this.verticalScrollBar.scrollSize = this.content.height;
14503
- if (this.isDestroyed)
14504
- return;
14505
- this.verticalScrollBar.viewportSize = this.viewport.height;
14506
- if (this.isDestroyed)
14507
- return;
14508
- this.horizontalScrollBar.scrollSize = this.content.width;
14509
- if (this.isDestroyed)
14510
- return;
14511
- this.horizontalScrollBar.viewportSize = this.viewport.width;
14512
- if (this.isDestroyed)
14513
- return;
14514
- if (this._stickyScroll) {
14515
- const newMaxScrollTop = Math.max(0, this.scrollHeight - this.viewport.height);
14516
- const newMaxScrollLeft = Math.max(0, this.scrollWidth - this.viewport.width);
14517
- const stickyStart = this._stickyStart;
14518
- if (stickyStart && !this._hasManualScroll) {
14519
- this.applyStickyStart(stickyStart);
14520
- } else if (stickyStart && this._hasManualScroll && this.isAtStickyReengagePoint(stickyStart, newMaxScrollTop, newMaxScrollLeft)) {
14521
- this._hasManualScroll = false;
14522
- this.applyStickyStart(stickyStart);
14523
- } else if (!this._hasManualScroll) {
14524
- if (this._stickyScrollTop) {
14525
- this.scrollTop = 0;
14526
- } else if (this._stickyScrollBottom && newMaxScrollTop > 0) {
14527
- this.scrollTop = newMaxScrollTop;
14528
- }
14529
- if (this.isDestroyed)
14530
- return;
14531
- if (this._stickyScrollLeft) {
14532
- this.scrollLeft = 0;
14533
- } else if (this._stickyScrollRight && newMaxScrollLeft > 0) {
14534
- this.scrollLeft = newMaxScrollLeft;
14535
- }
14536
- }
14537
- }
14538
- } finally {
14539
- this._isApplyingStickyScroll = wasApplyingStickyScroll;
14540
- }
14541
- }
14542
- set padding(value) {
14543
- this.content.padding = value;
14544
- this.requestRender();
14545
- }
14546
- set paddingX(value) {
14547
- this.content.paddingX = value;
14548
- this.requestRender();
14549
- }
14550
- set paddingY(value) {
14551
- this.content.paddingY = value;
14552
- this.requestRender();
14553
- }
14554
- set paddingTop(value) {
14555
- this.content.paddingTop = value;
14556
- this.requestRender();
14557
- }
14558
- set paddingRight(value) {
14559
- this.content.paddingRight = value;
14560
- this.requestRender();
14561
- }
14562
- set paddingBottom(value) {
14563
- this.content.paddingBottom = value;
14564
- this.requestRender();
14565
- }
14566
- set paddingLeft(value) {
14567
- this.content.paddingLeft = value;
14568
- this.requestRender();
14569
- }
14570
15187
  set rootOptions(options) {
14571
- this.assignOptions(this, options);
15188
+ this.assignOptions(this, options && stripScrollBoxPadding(options));
15189
+ if (options)
15190
+ this.content._assign(pickScrollBoxPadding(options), ScrollBoxContent.keys);
14572
15191
  if (!this.isDestroyed)
14573
15192
  this.requestRender();
14574
15193
  }
14575
15194
  set wrapperOptions(options) {
14576
- this.assignOptions(this.wrapper, options);
14577
- if (!this.isDestroyed)
14578
- this.requestRender();
15195
+ this.wrapper._assign(options, ScrollBoxWrapper.keys);
14579
15196
  }
14580
15197
  set viewportOptions(options) {
14581
- this.assignOptions(this.viewport, options);
14582
- if (!this.isDestroyed)
14583
- this.requestRender();
15198
+ this.viewport._assign(options, ScrollBoxViewport.keys);
14584
15199
  }
14585
15200
  set contentOptions(options) {
14586
- this.assignOptions(this.content, options);
14587
- if (!this.isDestroyed)
14588
- this.requestRender();
15201
+ this.content._assign(options, ScrollBoxContent.keys);
14589
15202
  }
14590
15203
  set scrollbarOptions(options) {
14591
- this.assignOptions(this.verticalScrollBar, options);
14592
- this.assignOptions(this.horizontalScrollBar, options);
14593
- if (!this.isDestroyed)
14594
- this.requestRender();
15204
+ this.verticalScrollBar._assign(options ?? { onChange: undefined }, ScrollBoxBar.keys);
15205
+ this.horizontalScrollBar._assign(options ?? { onChange: undefined }, ScrollBoxBar.keys);
14595
15206
  }
14596
15207
  set verticalScrollbarOptions(options) {
14597
- this.assignOptions(this.verticalScrollBar, options);
14598
- if (!this.isDestroyed)
14599
- this.requestRender();
15208
+ this.verticalScrollBar._assign(options ?? { onChange: undefined }, ScrollBoxBar.keys);
14600
15209
  }
14601
15210
  set horizontalScrollbarOptions(options) {
14602
- this.assignOptions(this.horizontalScrollBar, options);
14603
- if (!this.isDestroyed)
14604
- this.requestRender();
15211
+ this.horizontalScrollBar._assign(options ?? { onChange: undefined }, ScrollBoxBar.keys);
14605
15212
  }
14606
15213
  get scrollAcceleration() {
14607
15214
  return this.scrollAccel;
@@ -14610,23 +15217,37 @@ class ScrollBoxRenderable extends BoxRenderable2 {
14610
15217
  this.scrollAccel = value;
14611
15218
  }
14612
15219
  get viewportCulling() {
14613
- return this.content.viewportCulling;
15220
+ return this._viewportCulling;
14614
15221
  }
14615
15222
  set viewportCulling(value) {
14616
- this.content.viewportCulling = value;
14617
- this.requestRender();
15223
+ this.setScrollOption(() => this._viewportCulling = value ?? true);
14618
15224
  }
15225
+ get overflow() {
15226
+ return "hidden";
15227
+ }
15228
+ set overflow(_value) {}
14619
15229
  destroySelf() {
14620
- const selectionListener = this.selectionListener;
14621
- this.selectionListener = undefined;
15230
+ if (!this.isFreed())
15231
+ this._scrollState();
15232
+ this.layoutCallbacks = [];
15233
+ this.endBarPress();
14622
15234
  this.runCleanup((run) => {
14623
- if (selectionListener)
14624
- run(() => this._ctx.off("selection", selectionListener));
15235
+ run(() => this._ctx.off("selection", this.selectionListener));
14625
15236
  run(() => super.destroySelf());
14626
15237
  });
14627
15238
  }
14628
15239
  }
15240
+ for (const key of SCROLLBOX_PADDING_KEYS) {
15241
+ Object.defineProperty(ScrollBoxRenderable.prototype, key, {
15242
+ configurable: true,
15243
+ set(value) {
15244
+ this.content[key] = value;
15245
+ }
15246
+ });
15247
+ }
14629
15248
  // src/renderables/Select.ts
15249
+ var transparent2 = RGBA2.fromValues(0, 0, 0, 0);
15250
+ var indicatorColor = parseColor2("#666666");
14630
15251
  var defaultSelectKeybindings = [
14631
15252
  { name: "up", action: "move-up" },
14632
15253
  { name: "k", action: "move-up" },
@@ -14687,7 +15308,7 @@ class SelectRenderable extends Renderable2 {
14687
15308
  fastScrollStep: 5
14688
15309
  };
14689
15310
  constructor(ctx, options) {
14690
- super(ctx, { ...options, buffered: true });
15311
+ super(ctx, options);
14691
15312
  try {
14692
15313
  this._options = options.options || [];
14693
15314
  const requestedIndex = options.selectedIndex ?? this._defaultOptions.selectedIndex;
@@ -14720,74 +15341,65 @@ class SelectRenderable extends Renderable2 {
14720
15341
  }
14721
15342
  }
14722
15343
  renderSelf(buffer, deltaTime) {
14723
- if (!this.visible || !this.frameBuffer)
14724
- return;
14725
- if (this.isDirty) {
14726
- this.refreshFrameBuffer();
14727
- }
14728
- }
14729
- refreshFrameBuffer() {
14730
- if (!this.frameBuffer)
14731
- return;
15344
+ const [x, y] = this._paintOrigin(buffer);
15345
+ const width = this._paintWidth;
15346
+ const height = this._paintHeight;
14732
15347
  const bgColor = this._focused ? this._focusedBackgroundColor : this._backgroundColor;
14733
- this.frameBuffer.clear(bgColor);
14734
- if (this._options.length === 0)
14735
- return;
14736
- const contentX = 0;
14737
- const contentY = 0;
14738
- const contentWidth = this.width;
14739
- const contentHeight = this.height;
15348
+ const selectedY = (this._selectedIndex - this.scrollOffset) * this.linesPerItem;
15349
+ const selectedHeight = this.linesPerItem - this._itemSpacing;
15350
+ const hole = this._options.length > 0 && selectedY + this.linesPerItem <= height && this._selectedBackgroundColor.a === 1;
15351
+ const top = hole ? selectedY : height;
15352
+ const bottom = hole ? selectedY + selectedHeight : height;
15353
+ const scrolls = this._showScrollIndicator && this._options.length > this.maxVisibleItems;
15354
+ const scrollPercent = this.scrollOffset / (this._options.length - this.maxVisibleItems);
15355
+ const indicatorY = scrolls ? y + 1 + Math.floor(scrollPercent * Math.max(1, height - 2)) : -1;
15356
+ const draw = (text, textX, textY, color) => {
15357
+ const end = textY === indicatorY ? x + width - 1 : x + width;
15358
+ buffer.drawTextFit(text, textX, textY, end - textX, color, transparent2);
15359
+ };
15360
+ buffer.pushScissorRect(x, y, width, height);
15361
+ if (buffer === this.frameBuffer)
15362
+ buffer.clear(bgColor);
15363
+ else {
15364
+ buffer.fillRect(x, y, width, top, bgColor);
15365
+ buffer.fillRect(x, y + bottom, width, height - bottom, bgColor);
15366
+ }
14740
15367
  const visibleOptions = this._options.slice(this.scrollOffset, this.scrollOffset + this.maxVisibleItems);
14741
15368
  for (let i = 0;i < visibleOptions.length; i++) {
14742
- const actualIndex = this.scrollOffset + i;
14743
15369
  const option = visibleOptions[i];
14744
- const isSelected = actualIndex === this._selectedIndex;
14745
- const itemY = contentY + i * this.linesPerItem;
14746
- if (itemY + this.linesPerItem - 1 >= contentY + contentHeight)
15370
+ const isSelected = this.scrollOffset + i === this._selectedIndex;
15371
+ const itemY = y + i * this.linesPerItem;
15372
+ if (itemY + this.linesPerItem - 1 >= y + height)
14747
15373
  break;
14748
15374
  if (isSelected) {
14749
- const contentHeight = this.linesPerItem - this._itemSpacing;
14750
- this.frameBuffer.fillRect(contentX, itemY, contentWidth, contentHeight, this._selectedBackgroundColor);
15375
+ buffer.fillRect(x, itemY, width, selectedHeight, this._selectedBackgroundColor);
14751
15376
  }
14752
15377
  const indicator = this._showSelectionIndicator ? isSelected ? "\u25B6 " : " " : "";
14753
- const indicatorWidth = this._showSelectionIndicator ? 2 : 0;
14754
- const nameContent = `${indicator}${option.name}`;
14755
15378
  const baseTextColor = this._focused ? this._focusedTextColor : this._textColor;
14756
15379
  const nameColor = isSelected ? this._selectedTextColor : baseTextColor;
14757
- const textX = contentX + 1 + indicatorWidth;
15380
+ const textX = x + 1 + (this._showSelectionIndicator ? 2 : 0);
14758
15381
  if (this._font) {
14759
- if (indicator) {
14760
- this.frameBuffer.drawText(indicator, contentX + 1, itemY, nameColor);
14761
- }
14762
- renderFontToFrameBuffer2(this.frameBuffer, {
15382
+ if (indicator)
15383
+ draw(indicator, x + 1, itemY, nameColor);
15384
+ renderFontToFrameBuffer2(buffer, {
14763
15385
  text: option.name,
14764
15386
  x: textX,
14765
15387
  y: itemY,
14766
15388
  color: nameColor,
14767
- backgroundColor: isSelected ? this._selectedBackgroundColor : bgColor,
15389
+ backgroundColor: transparent2,
14768
15390
  font: this._font
14769
15391
  });
14770
15392
  } else {
14771
- this.frameBuffer.drawText(nameContent, contentX + 1, itemY, nameColor);
15393
+ draw(`${indicator}${option.name}`, x + 1, itemY, nameColor);
14772
15394
  }
14773
- if (this._showDescription && itemY + this.fontHeight < contentY + contentHeight) {
15395
+ if (this._showDescription && itemY + this.fontHeight < y + height) {
14774
15396
  const descColor = isSelected ? this._selectedDescriptionColor : this._descriptionColor;
14775
- this.frameBuffer.drawText(option.description, textX, itemY + this.fontHeight, descColor);
15397
+ draw(option.description, textX, itemY + this.fontHeight, descColor);
14776
15398
  }
14777
15399
  }
14778
- if (this._showScrollIndicator && this._options.length > this.maxVisibleItems) {
14779
- this.renderScrollIndicatorToFrameBuffer(contentX, contentY, contentWidth, contentHeight);
14780
- }
14781
- }
14782
- renderScrollIndicatorToFrameBuffer(contentX, contentY, contentWidth, contentHeight) {
14783
- if (!this.frameBuffer)
14784
- return;
14785
- const maxScrollOffset = this._options.length - this.maxVisibleItems;
14786
- const scrollPercent = this.scrollOffset / maxScrollOffset;
14787
- const indicatorHeight = Math.max(1, contentHeight - 2);
14788
- const indicatorY = contentY + 1 + Math.floor(scrollPercent * indicatorHeight);
14789
- const indicatorX = contentX + contentWidth - 1;
14790
- this.frameBuffer.drawText("\u2588", indicatorX, indicatorY, parseColor2("#666666"));
15400
+ if (scrolls)
15401
+ buffer.drawText("\u2588", x + width - 1, indicatorY, indicatorColor, transparent2);
15402
+ buffer.popScissorRect();
14791
15403
  }
14792
15404
  get options() {
14793
15405
  return this._options;
@@ -14988,6 +15600,8 @@ class SelectRenderable extends Renderable2 {
14988
15600
  }
14989
15601
  }
14990
15602
  // src/renderables/TabSelect.ts
15603
+ var transparent3 = RGBA2.fromValues(0, 0, 0, 0);
15604
+ var arrowColor = parseColor2("#AAAAAA");
14991
15605
  var defaultTabSelectKeybindings = [
14992
15606
  { name: "left", action: "move-left" },
14993
15607
  { name: "[", action: "move-left" },
@@ -15044,7 +15658,7 @@ class TabSelectRenderable extends Renderable2 {
15044
15658
  _keyBindings;
15045
15659
  constructor(ctx, options) {
15046
15660
  const calculatedHeight = calculateDynamicHeight(options.showUnderline ?? true, options.showDescription ?? true);
15047
- super(ctx, { ...options, height: calculatedHeight, buffered: true });
15661
+ super(ctx, { ...options, height: calculatedHeight });
15048
15662
  try {
15049
15663
  this._backgroundColor = RGBA2.clone(parseColor2(options.backgroundColor || defaultColors2.backgroundColor));
15050
15664
  this._hasBackgroundColor = !!options.backgroundColor;
@@ -15076,71 +15690,52 @@ class TabSelectRenderable extends Renderable2 {
15076
15690
  return kind === "height" ? this.calculateDynamicHeight() : super.defaultDimension(kind);
15077
15691
  }
15078
15692
  renderSelf(buffer, deltaTime) {
15079
- if (!this.visible || !this.frameBuffer)
15080
- return;
15081
- if (this.isDirty) {
15082
- this.refreshFrameBuffer();
15083
- }
15084
- }
15085
- refreshFrameBuffer() {
15086
- if (!this.frameBuffer)
15087
- return;
15693
+ const [x, y] = this._paintOrigin(buffer);
15694
+ const width = this._paintWidth;
15695
+ const height = this._paintHeight;
15088
15696
  const bgColor = this._focused ? this._focusedBackgroundColor : this._backgroundColor;
15089
- this.frameBuffer.clear(bgColor);
15090
- if (this._options.length === 0)
15091
- return;
15092
- const contentX = 0;
15093
- const contentY = 0;
15094
- const contentWidth = this.width;
15095
- const contentHeight = this.height;
15697
+ const selectedX = (this.selectedIndex - this.scrollOffset) * this._tabWidth;
15698
+ const selectedWidth = Math.min(this._tabWidth, width - selectedX);
15699
+ const selectedRows = this._showUnderline && height >= 2 ? 2 : 1;
15700
+ const hole = this._options.length > 0 && selectedX < width && this._selectedBackgroundColor.a === 1;
15701
+ const rows = hole ? selectedRows : 0;
15702
+ if (buffer === this.frameBuffer)
15703
+ buffer.clear(bgColor);
15704
+ else {
15705
+ buffer.fillRect(x, y, selectedX, rows, bgColor);
15706
+ buffer.fillRect(x + selectedX + selectedWidth, y, width - selectedX - selectedWidth, rows, bgColor);
15707
+ buffer.fillRect(x, y + rows, width, height - rows, bgColor);
15708
+ }
15096
15709
  const visibleOptions = this._options.slice(this.scrollOffset, this.scrollOffset + this.maxVisibleTabs);
15097
15710
  for (let i = 0;i < visibleOptions.length; i++) {
15098
- const actualIndex = this.scrollOffset + i;
15099
15711
  const option = visibleOptions[i];
15100
- const isSelected = actualIndex === this.selectedIndex;
15101
- const tabX = contentX + i * this._tabWidth;
15102
- if (tabX >= contentX + contentWidth)
15712
+ const isSelected = this.scrollOffset + i === this.selectedIndex;
15713
+ const tabX = x + i * this._tabWidth;
15714
+ if (tabX >= x + width)
15103
15715
  break;
15104
- const actualTabWidth = Math.min(this._tabWidth, contentWidth - i * this._tabWidth);
15105
- if (isSelected) {
15106
- this.frameBuffer.fillRect(tabX, contentY, actualTabWidth, 1, this._selectedBackgroundColor);
15107
- }
15716
+ const actualTabWidth = Math.min(this._tabWidth, width - i * this._tabWidth);
15108
15717
  const baseTextColor = this._focused ? this._focusedTextColor : this._textColor;
15109
15718
  const nameColor = isSelected ? this._selectedTextColor : baseTextColor;
15110
- const nameContent = this.truncateText(option.name, actualTabWidth - 2);
15111
- this.frameBuffer.drawText(nameContent, tabX + 1, contentY, nameColor);
15112
- if (isSelected && this._showUnderline && contentHeight >= 2) {
15113
- this.frameBuffer.drawText("\u25AC".repeat(actualTabWidth), tabX, contentY + 1, nameColor, this._selectedBackgroundColor);
15719
+ if (isSelected) {
15720
+ buffer.fillRect(tabX, y, actualTabWidth, selectedRows, this._selectedBackgroundColor);
15114
15721
  }
15115
- }
15116
- if (this._showDescription && contentHeight >= (this._showUnderline ? 3 : 2)) {
15117
- const selectedOption = this.getSelectedOption();
15118
- if (selectedOption) {
15119
- const descriptionY = contentY + (this._showUnderline ? 2 : 1);
15120
- const descColor = this._selectedDescriptionColor;
15121
- const descContent = this.truncateText(selectedOption.description, contentWidth - 2);
15122
- this.frameBuffer.drawText(descContent, contentX + 1, descriptionY, descColor);
15722
+ buffer.drawTextFit(option.name, tabX + 1, y, actualTabWidth - 2, nameColor, transparent3, true);
15723
+ if (isSelected && selectedRows === 2) {
15724
+ buffer.drawText("\u25AC".repeat(actualTabWidth), tabX, y + 1, nameColor, transparent3);
15123
15725
  }
15124
15726
  }
15125
- if (this._showScrollArrows && this._options.length > this.maxVisibleTabs) {
15126
- this.renderScrollArrowsToFrameBuffer(contentX, contentY, contentWidth, contentHeight);
15127
- }
15128
- }
15129
- truncateText(text, maxWidth) {
15130
- if (text.length <= maxWidth)
15131
- return text;
15132
- return text.substring(0, Math.max(0, maxWidth - 1)) + "\u2026";
15133
- }
15134
- renderScrollArrowsToFrameBuffer(contentX, contentY, contentWidth, contentHeight) {
15135
- if (!this.frameBuffer)
15136
- return;
15137
- const hasMoreLeft = this.scrollOffset > 0;
15138
- const hasMoreRight = this.scrollOffset + this.maxVisibleTabs < this._options.length;
15139
- if (hasMoreLeft) {
15140
- this.frameBuffer.drawText("\u2039", contentX, contentY, parseColor2("#AAAAAA"));
15727
+ const selectedOption = this.getSelectedOption();
15728
+ if (selectedOption && this._showDescription && height >= (this._showUnderline ? 3 : 2)) {
15729
+ const descriptionY = y + (this._showUnderline ? 2 : 1);
15730
+ const description = selectedOption.description;
15731
+ buffer.drawTextFit(description, x + 1, descriptionY, width - 2, this._selectedDescriptionColor, transparent3, true);
15141
15732
  }
15142
- if (hasMoreRight) {
15143
- this.frameBuffer.drawText("\u203A", contentX + contentWidth - 1, contentY, parseColor2("#AAAAAA"));
15733
+ if (this._showScrollArrows && this._options.length > this.maxVisibleTabs) {
15734
+ if (this.scrollOffset > 0)
15735
+ buffer.drawText("\u2039", x, y, arrowColor, transparent3);
15736
+ if (this.scrollOffset + this.maxVisibleTabs < this._options.length) {
15737
+ buffer.drawText("\u203A", x + width - 1, y, arrowColor, transparent3);
15738
+ }
15144
15739
  }
15145
15740
  }
15146
15741
  setOptions(options) {
@@ -15325,28 +15920,19 @@ class TabSelectRenderable extends Renderable2 {
15325
15920
  }
15326
15921
  }
15327
15922
  // src/renderables/TimeToFirstDraw.ts
15328
- var graphemeSegmenter = new Intl.Segmenter(undefined, { granularity: "grapheme" });
15329
- function measureCellWidth(buffer, text) {
15923
+ var transparent4 = RGBA2.fromValues(0, 0, 0, 0);
15924
+ function fittedWidth(buffer, text, maxWidth) {
15925
+ if (/^[\x20-\x7e]*$/.test(text))
15926
+ return Math.min(text.length, maxWidth);
15330
15927
  const encoded = buffer.encodeUnicode(text);
15331
- if (!encoded)
15332
- return 0;
15333
- try {
15334
- return encoded.data.reduce((width, glyph) => width + glyph.width, 0);
15335
- } finally {
15336
- buffer.freeUnicode(encoded);
15337
- }
15338
- }
15339
- function truncateToCellWidth(buffer, text, maxWidth) {
15340
- let visibleText = "";
15341
- let visibleWidth = 0;
15342
- for (const { segment } of graphemeSegmenter.segment(text)) {
15343
- const segmentWidth = measureCellWidth(buffer, segment);
15344
- if (visibleWidth + segmentWidth > maxWidth)
15928
+ let width = 0;
15929
+ for (const glyph of encoded.data) {
15930
+ if (width + glyph.width > maxWidth)
15345
15931
  break;
15346
- visibleText += segment;
15347
- visibleWidth += segmentWidth;
15932
+ width += glyph.width;
15348
15933
  }
15349
- return { text: visibleText, width: visibleWidth };
15934
+ buffer.freeUnicode(encoded);
15935
+ return width;
15350
15936
  }
15351
15937
 
15352
15938
  class TimeToFirstDrawRenderable extends Renderable2 {
@@ -15404,9 +15990,9 @@ class TimeToFirstDrawRenderable extends Renderable2 {
15404
15990
  }
15405
15991
  const content = `${this.label}: ${this._runtimeMs.toFixed(this.precision)}ms`;
15406
15992
  const maxWidth = Math.max(this.width, 1);
15407
- const visibleContent = truncateToCellWidth(buffer, content, maxWidth);
15408
- const centeredX = this.x + Math.max(0, Math.floor((maxWidth - visibleContent.width) / 2));
15409
- buffer.drawText(visibleContent.text, centeredX, this.y, this.textColor);
15993
+ const [x, y] = this._paintOrigin(buffer);
15994
+ const width = fittedWidth(buffer, content, maxWidth);
15995
+ buffer.drawTextFit(content, x + Math.floor((maxWidth - width) / 2), y, width, this.textColor, transparent4);
15410
15996
  }
15411
15997
  normalizePrecision(value) {
15412
15998
  if (!Number.isFinite(value)) {
@@ -15538,7 +16124,11 @@ export {
15538
16124
  SYNTHWAVE_MATRIX,
15539
16125
  ScrollBarRenderable,
15540
16126
  ScrollBox,
16127
+ ScrollBoxBar,
16128
+ ScrollBoxContent,
15541
16129
  ScrollBoxRenderable,
16130
+ ScrollBoxViewport,
16131
+ ScrollBoxWrapper,
15542
16132
  Select,
15543
16133
  SelectRenderable,
15544
16134
  SelectRenderableEvents,
@@ -15572,6 +16162,7 @@ export {
15572
16162
  Timeline2 as Timeline,
15573
16163
  TreeSitterClient2 as TreeSitterClient,
15574
16164
  VRenderable,
16165
+ VideoRenderable,
15575
16166
  VignetteEffect,
15576
16167
  exports_yoga as Yoga,
15577
16168
  acquireSessionBufferLease2 as acquireSessionBufferLease,
@@ -15612,6 +16203,7 @@ export {
15612
16203
  buildKittyKeyboardFlags2 as buildKittyKeyboardFlags,
15613
16204
  buildTerminalPaletteSignature2 as buildTerminalPaletteSignature,
15614
16205
  capture2 as capture,
16206
+ checkCrop2 as checkCrop,
15615
16207
  clearEnvCache2 as clearEnvCache,
15616
16208
  convertGlobalToLocalSelection2 as convertGlobalToLocalSelection,
15617
16209
  convertThemeToStyles,
@@ -15706,6 +16298,8 @@ export {
15706
16298
  resolveRenderLib2 as resolveRenderLib,
15707
16299
  reverse2 as reverse,
15708
16300
  rgbToHex2 as rgbToHex,
16301
+ sameCrop2 as sameCrop,
16302
+ scrollUnitSize,
15709
16303
  setRenderLibPath2 as setRenderLibPath,
15710
16304
  setupAudio,
15711
16305
  strikethrough2 as strikethrough,
@@ -15723,5 +16317,5 @@ export {
15723
16317
  yellow2 as yellow
15724
16318
  };
15725
16319
 
15726
- //# debugId=8DC6B343077360A664756E2164756E21
16320
+ //# debugId=3FC176E86CAEA33964756E2164756E21
15727
16321
  //# sourceMappingURL=index.bun.js.map