@opentui/core 0.6.5 → 0.6.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.bun.js CHANGED
@@ -110,7 +110,7 @@ import {
110
110
  resolveRenderLib2,
111
111
  MeasureMode2,
112
112
  exports_yoga
113
- } from "./chunk-bun-gwy4vfr3.js";
113
+ } from "./chunk-bun-ehr9v0n8.js";
114
114
  import {
115
115
  isValidBorderStyle2,
116
116
  parseBorderStyle2,
@@ -242,7 +242,7 @@ import {
242
242
  CliRenderEvents2,
243
243
  RendererControlState2,
244
244
  CliRenderer2
245
- } from "./chunk-bun-2kxv0ysg.js";
245
+ } from "./chunk-bun-rk6266v5.js";
246
246
  // src/post/effects.ts
247
247
  function toU8(value) {
248
248
  return Math.round(Math.max(0, Math.min(1, Number.isFinite(value) ? value : 0)) * 255);
@@ -5693,6 +5693,9 @@ class ASCIIFontRenderable extends FrameBufferRenderable {
5693
5693
  this.renderFontToBuffer();
5694
5694
  this.requestRender();
5695
5695
  }
5696
+ defaultDimension(kind) {
5697
+ return measureText2({ text: this._text, font: this._font })[kind] || 1;
5698
+ }
5696
5699
  updateDimensions() {
5697
5700
  const measurements = measureText2({ text: this._text, font: this._font });
5698
5701
  this.width = measurements.width;
@@ -5857,8 +5860,7 @@ class GutterRenderable extends Renderable2 {
5857
5860
  target;
5858
5861
  _fg;
5859
5862
  _bg;
5860
- _minWidth;
5861
- _paddingRight;
5863
+ _layout;
5862
5864
  _lineColorsGutter;
5863
5865
  _lineColorsContent;
5864
5866
  _lineSigns;
@@ -5882,8 +5884,7 @@ class GutterRenderable extends Renderable2 {
5882
5884
  this.target = target;
5883
5885
  this._fg = options.fg;
5884
5886
  this._bg = options.bg;
5885
- this._minWidth = options.minWidth;
5886
- this._paddingRight = options.paddingRight;
5887
+ this._layout = options.layout;
5887
5888
  this._lineColorsGutter = options.lineColorsGutter;
5888
5889
  this._lineColorsContent = options.lineColorsContent;
5889
5890
  this._lineSigns = options.lineSigns;
@@ -5937,9 +5938,15 @@ class GutterRenderable extends Renderable2 {
5937
5938
  this.invalidateIntrinsicSize();
5938
5939
  this.requestRender();
5939
5940
  }
5941
+ setLayout(layout) {
5942
+ this._layout = layout;
5943
+ this.calculateSignWidths();
5944
+ this.invalidateIntrinsicSize();
5945
+ this.requestRender();
5946
+ }
5940
5947
  calculateSignWidths() {
5941
5948
  this._maxBeforeWidth = 0;
5942
- this._maxAfterWidth = 0;
5949
+ this._maxAfterWidth = this._layout.minAfterWidth;
5943
5950
  for (const sign of this._lineSigns.values()) {
5944
5951
  if (sign.before) {
5945
5952
  const width = stringWidth(sign.before);
@@ -5959,8 +5966,8 @@ class GutterRenderable extends Renderable2 {
5959
5966
  maxLineNumber = Math.max(maxLineNumber, customLineNum);
5960
5967
  }
5961
5968
  }
5962
- const digits = maxLineNumber > 0 ? Math.floor(Math.log10(maxLineNumber)) + 1 : 1;
5963
- const baseWidth = Math.max(this._minWidth, digits + this._paddingRight + 1);
5969
+ const digits = Math.max(maxLineNumber > 0 ? Math.floor(Math.log10(maxLineNumber)) + 1 : 1, this._layout.minDigits);
5970
+ const baseWidth = Math.max(this._layout.minWidth, digits + this._layout.paddingLeft + this._layout.paddingRight);
5964
5971
  return baseWidth + this._maxBeforeWidth + this._maxAfterWidth;
5965
5972
  }
5966
5973
  setLineColors(lineColorsGutter, lineColorsContent) {
@@ -6065,14 +6072,13 @@ class GutterRenderable extends Renderable2 {
6065
6072
  const lineNum = customLineNum !== undefined ? customLineNum : logicalLine + 1 + this._lineNumberOffset;
6066
6073
  const lineNumStr = lineNum.toString();
6067
6074
  const lineNumWidth = lineNumStr.length;
6068
- const availableSpace = this.width - this._maxBeforeWidth - this._maxAfterWidth - this._paddingRight;
6069
- const lineNumX = this._maxBeforeWidth + 1 + availableSpace - lineNumWidth - 1;
6070
- if (lineNumX >= this._maxBeforeWidth + 1) {
6075
+ const lineNumX = this.width - this._maxAfterWidth - this._layout.paddingRight - lineNumWidth;
6076
+ if (lineNumX >= this._maxBeforeWidth + this._layout.paddingLeft) {
6071
6077
  buffer.drawText(lineNumStr, lineNumX, i, this._fg, lineBg);
6072
6078
  }
6073
6079
  }
6074
6080
  if (sign?.after) {
6075
- const afterX = this.width - this._paddingRight - this._maxAfterWidth;
6081
+ const afterX = this.width - this._layout.paddingRight - this._maxAfterWidth;
6076
6082
  const afterColor = sign.afterColor ? parseColor2(sign.afterColor) : this._fg;
6077
6083
  buffer.drawText(sign.after, afterX, i, afterColor, lineBg);
6078
6084
  }
@@ -6098,8 +6104,7 @@ class LineNumberRenderable extends Renderable2 {
6098
6104
  _lineSigns;
6099
6105
  _fg;
6100
6106
  _bg;
6101
- _minWidth;
6102
- _paddingRight;
6107
+ _layout;
6103
6108
  _lineNumberOffset;
6104
6109
  _hideLineNumbers;
6105
6110
  _lineNumbers;
@@ -6134,8 +6139,13 @@ class LineNumberRenderable extends Renderable2 {
6134
6139
  try {
6135
6140
  this._fg = RGBA2.clone(parseColor2(options.fg ?? DEFAULT_GUTTER_FG));
6136
6141
  this._bg = RGBA2.clone(parseColor2(options.bg ?? DEFAULT_GUTTER_BG));
6137
- this._minWidth = options.minWidth ?? 3;
6138
- this._paddingRight = options.paddingRight ?? 1;
6142
+ this._layout = {
6143
+ minWidth: options.minWidth ?? 3,
6144
+ paddingLeft: 1,
6145
+ paddingRight: options.paddingRight ?? 1,
6146
+ minDigits: 0,
6147
+ minAfterWidth: 0
6148
+ };
6139
6149
  this._lineNumberOffset = options.lineNumberOffset ?? 0;
6140
6150
  this._hideLineNumbers = options.hideLineNumbers ?? new Set;
6141
6151
  this._lineNumbers = options.lineNumbers ?? new Map;
@@ -6171,8 +6181,7 @@ class LineNumberRenderable extends Renderable2 {
6171
6181
  this.gutter = new GutterRenderable(this.ctx, target, {
6172
6182
  fg: this._fg,
6173
6183
  bg: this._bg,
6174
- minWidth: this._minWidth,
6175
- paddingRight: this._paddingRight,
6184
+ layout: this._layout,
6176
6185
  lineColorsGutter: this._lineColorsGutter,
6177
6186
  lineColorsContent: this._lineColorsContent,
6178
6187
  lineSigns: this._lineSigns,
@@ -6376,6 +6385,15 @@ class LineNumberRenderable extends Renderable2 {
6376
6385
  getLineSigns() {
6377
6386
  return new Map(Array.from(this._lineSigns, ([line, sign]) => [line, cloneLineSign(sign)]));
6378
6387
  }
6388
+ getGutterLayout() {
6389
+ return { ...this._layout };
6390
+ }
6391
+ setGutterLayout(layout) {
6392
+ if (layout.minWidth === this._layout.minWidth && layout.paddingLeft === this._layout.paddingLeft && layout.paddingRight === this._layout.paddingRight && layout.minDigits === this._layout.minDigits && layout.minAfterWidth === this._layout.minAfterWidth)
6393
+ return;
6394
+ this._layout = { ...layout };
6395
+ this.gutter?.setLayout(this._layout);
6396
+ }
6379
6397
  set lineNumberOffset(value) {
6380
6398
  if (this._lineNumberOffset !== value) {
6381
6399
  this._lineNumberOffset = value;
@@ -6753,6 +6771,7 @@ function parsePatch(uniDiff) {
6753
6771
  return list;
6754
6772
  }
6755
6773
  // src/renderables/Diff.ts
6774
+ var SIGN_WIDTH = 2;
6756
6775
  var defaultColors = {
6757
6776
  lineNumberFg: "#888888",
6758
6777
  lineNumberBg: "transparent",
@@ -6789,6 +6808,7 @@ class DiffRenderable extends Renderable2 {
6789
6808
  _showLineNumbers;
6790
6809
  _lineNumberFg;
6791
6810
  _lineNumberBg;
6811
+ _gutter;
6792
6812
  _addedBg;
6793
6813
  _removedBg;
6794
6814
  _contextBg;
@@ -6831,6 +6851,7 @@ class DiffRenderable extends Renderable2 {
6831
6851
  this._showLineNumbers = options.showLineNumbers ?? true;
6832
6852
  this._lineNumberFg = RGBA2.clone(parseColor2(options.lineNumberFg ?? defaultColors.lineNumberFg));
6833
6853
  this._lineNumberBg = RGBA2.clone(parseColor2(options.lineNumberBg ?? defaultColors.lineNumberBg));
6854
+ this._gutter = { ...options.gutter };
6834
6855
  this._addedBg = RGBA2.clone(parseColor2(options.addedBg ?? defaultColors.addedBg));
6835
6856
  this._removedBg = RGBA2.clone(parseColor2(options.removedBg ?? defaultColors.removedBg));
6836
6857
  this._contextBg = RGBA2.clone(parseColor2(options.contextBg ?? defaultColors.contextBg));
@@ -7131,6 +7152,7 @@ class DiffRenderable extends Renderable2 {
7131
7152
  height: "100%"
7132
7153
  });
7133
7154
  newSide.showLineNumbers = this._showLineNumbers;
7155
+ newSide.setGutterLayout(this.gutterLayout());
7134
7156
  super.add(newSide);
7135
7157
  if (side === "left") {
7136
7158
  this.leftSide = newSide;
@@ -7143,6 +7165,7 @@ class DiffRenderable extends Renderable2 {
7143
7165
  sideRef.width = width;
7144
7166
  sideRef.fg = this._lineNumberFg;
7145
7167
  sideRef.bg = this._lineNumberBg;
7168
+ sideRef.setGutterLayout(this.gutterLayout());
7146
7169
  sideRef.setLineColors(lineColors);
7147
7170
  const padding = sideRef.getLineSigns().get(-1);
7148
7171
  if (padding)
@@ -7160,6 +7183,15 @@ class DiffRenderable extends Renderable2 {
7160
7183
  }
7161
7184
  }
7162
7185
  }
7186
+ gutterLayout() {
7187
+ return {
7188
+ minWidth: 0,
7189
+ paddingLeft: this._gutter.paddingLeft ?? 1,
7190
+ paddingRight: this._gutter.paddingRight ?? 1,
7191
+ minDigits: this._gutter.minDigits ?? 0,
7192
+ minAfterWidth: this._gutter.minDigits === undefined ? 0 : SIGN_WIDTH
7193
+ };
7194
+ }
7163
7195
  buildUnifiedView() {
7164
7196
  if (!this._parsedDiff)
7165
7197
  return;
@@ -7666,6 +7698,16 @@ class DiffRenderable extends Renderable2 {
7666
7698
  this._lineNumberBg = RGBA2.clone(parseColor2(value ?? defaultColors.lineNumberBg));
7667
7699
  this.rebuildView();
7668
7700
  }
7701
+ get gutter() {
7702
+ return { ...this._gutter };
7703
+ }
7704
+ set gutter(value) {
7705
+ const next = { ...value };
7706
+ if (next.paddingLeft === this._gutter.paddingLeft && next.paddingRight === this._gutter.paddingRight && next.minDigits === this._gutter.minDigits)
7707
+ return;
7708
+ this._gutter = next;
7709
+ this.rebuildView();
7710
+ }
7669
7711
  get addedContentBg() {
7670
7712
  return this._addedContentBg ? RGBA2.clone(this._addedContentBg) : null;
7671
7713
  }
@@ -7820,6 +7862,7 @@ class EmbeddedTerminalRenderable extends Renderable2 {
7820
7862
  selection = false;
7821
7863
  composedHookGeneration = 0n;
7822
7864
  _transparentBackground = false;
7865
+ sizeDefaults;
7823
7866
  constructor(ctx, options) {
7824
7867
  const cols = options.cols ?? (typeof options.width === "number" ? options.width : 80);
7825
7868
  const rows = options.rows ?? (typeof options.height === "number" ? options.height : 24);
@@ -7831,6 +7874,7 @@ class EmbeddedTerminalRenderable extends Renderable2 {
7831
7874
  });
7832
7875
  this._focusable = true;
7833
7876
  this.lib = ctx.nativeScene.driver.renderLib;
7877
+ this.sizeDefaults = { width: options.cols ?? 80, height: options.rows ?? 24 };
7834
7878
  try {
7835
7879
  this._onData = options.onData;
7836
7880
  this._onTerminalResize = options.onTerminalResize;
@@ -7844,6 +7888,9 @@ class EmbeddedTerminalRenderable extends Renderable2 {
7844
7888
  this.rollbackConstruction(error);
7845
7889
  }
7846
7890
  }
7891
+ defaultDimension(kind) {
7892
+ return this.sizeDefaults[kind];
7893
+ }
7847
7894
  get onData() {
7848
7895
  return this._onData;
7849
7896
  }
@@ -8632,6 +8679,9 @@ class InputRenderable extends TextareaRenderable {
8632
8679
  this.emit("input" /* INPUT */, this.plainText);
8633
8680
  });
8634
8681
  }
8682
+ defaultDimension(kind) {
8683
+ return kind === "height" ? 1 : super.defaultDimension(kind);
8684
+ }
8635
8685
  get value() {
8636
8686
  return this.plainText;
8637
8687
  }
@@ -13207,6 +13257,10 @@ class ScrollBarRenderable extends Renderable2 {
13207
13257
  return super.visible;
13208
13258
  }
13209
13259
  set visible(value) {
13260
+ if (value == null) {
13261
+ this.resetVisibilityControl();
13262
+ return;
13263
+ }
13210
13264
  this._manualVisibility = true;
13211
13265
  super.visible = value;
13212
13266
  }
@@ -13279,6 +13333,7 @@ class ScrollBarRenderable extends Renderable2 {
13279
13333
  return this._showArrows;
13280
13334
  }
13281
13335
  set showArrows(value) {
13336
+ value ??= false;
13282
13337
  if (this.isDestroyed || value === this._showArrows)
13283
13338
  return;
13284
13339
  this.assertMutable();
@@ -13521,15 +13576,8 @@ class ArrowRenderable extends Renderable2 {
13521
13576
  right: "\u25B6",
13522
13577
  ...options.arrowChars
13523
13578
  };
13524
- if (!options.width) {
13525
- const { context, renderLib } = ctx.nativeScene.driver;
13526
- const unicode = renderLib.createContextUnicode(context, this.getArrowChar(), ctx.widthMethod);
13527
- try {
13528
- this.width = renderLib.getContextUnicode(context, unicode).reduce((width, glyph) => width + glyph.width, 0);
13529
- } finally {
13530
- renderLib.destroyContextUnicode(context, unicode);
13531
- }
13532
- }
13579
+ if (!options.width)
13580
+ this.width = this.glyphWidth();
13533
13581
  this.setNativeSceneArrow();
13534
13582
  this.setNativeScenePaint();
13535
13583
  } catch (error) {
@@ -13600,6 +13648,18 @@ class ArrowRenderable extends Renderable2 {
13600
13648
  const char = this.getArrowChar();
13601
13649
  buffer.drawText(char, this.x, this.y, this._foregroundColor, this._backgroundColor, this._attributes);
13602
13650
  }
13651
+ defaultDimension(kind) {
13652
+ return kind === "width" ? this.glyphWidth() : super.defaultDimension(kind);
13653
+ }
13654
+ glyphWidth() {
13655
+ const { context, renderLib } = this._ctx.nativeScene.driver;
13656
+ const unicode = renderLib.createContextUnicode(context, this.getArrowChar(), this._ctx.widthMethod);
13657
+ try {
13658
+ return renderLib.getContextUnicode(context, unicode).reduce((width, glyph) => width + glyph.width, 0);
13659
+ } finally {
13660
+ renderLib.destroyContextUnicode(context, unicode);
13661
+ }
13662
+ }
13603
13663
  getArrowChar() {
13604
13664
  return this._arrowChars[this._direction];
13605
13665
  }
@@ -14790,6 +14850,9 @@ class TabSelectRenderable extends Renderable2 {
14790
14850
  calculateDynamicHeight() {
14791
14851
  return calculateDynamicHeight(this._showUnderline, this._showDescription);
14792
14852
  }
14853
+ defaultDimension(kind) {
14854
+ return kind === "height" ? this.calculateDynamicHeight() : super.defaultDimension(kind);
14855
+ }
14793
14856
  renderSelf(buffer, deltaTime) {
14794
14857
  if (!this.visible || !this.frameBuffer)
14795
14858
  return;
@@ -15081,6 +15144,9 @@ class TimeToFirstDrawRenderable extends Renderable2 {
15081
15144
  this.label = options.label ?? "Time to first draw";
15082
15145
  this.precision = this.normalizePrecision(options.precision ?? 2);
15083
15146
  }
15147
+ defaultDimension(kind) {
15148
+ return kind === "width" ? "100%" : 1;
15149
+ }
15084
15150
  get runtimeMs() {
15085
15151
  return this._runtimeMs;
15086
15152
  }
@@ -15435,5 +15501,5 @@ export {
15435
15501
  yellow2 as yellow
15436
15502
  };
15437
15503
 
15438
- //# debugId=1B5615355BC40CFF64756E2164756E21
15504
+ //# debugId=7177BFBAA0B78F6664756E2164756E21
15439
15505
  //# sourceMappingURL=index.bun.js.map