@opentui/core 0.6.6 → 0.6.8

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.node.js CHANGED
@@ -109,7 +109,7 @@ import {
109
109
  resolveRenderLib2,
110
110
  MeasureMode2,
111
111
  exports_yoga
112
- } from "./chunk-node-p43t2gam.js";
112
+ } from "./chunk-node-jhq62x0c.js";
113
113
  import {
114
114
  isValidBorderStyle2,
115
115
  parseBorderStyle2,
@@ -241,7 +241,7 @@ import {
241
241
  CliRenderEvents2,
242
242
  RendererControlState2,
243
243
  CliRenderer2
244
- } from "./chunk-node-2rg7pskw.js";
244
+ } from "./chunk-node-yyjd8p1g.js";
245
245
  // src/post/effects.ts
246
246
  function toU8(value) {
247
247
  return Math.round(Math.max(0, Math.min(1, Number.isFinite(value) ? value : 0)) * 255);
@@ -5859,8 +5859,7 @@ class GutterRenderable extends Renderable2 {
5859
5859
  target;
5860
5860
  _fg;
5861
5861
  _bg;
5862
- _minWidth;
5863
- _paddingRight;
5862
+ _layout;
5864
5863
  _lineColorsGutter;
5865
5864
  _lineColorsContent;
5866
5865
  _lineSigns;
@@ -5884,8 +5883,7 @@ class GutterRenderable extends Renderable2 {
5884
5883
  this.target = target;
5885
5884
  this._fg = options.fg;
5886
5885
  this._bg = options.bg;
5887
- this._minWidth = options.minWidth;
5888
- this._paddingRight = options.paddingRight;
5886
+ this._layout = options.layout;
5889
5887
  this._lineColorsGutter = options.lineColorsGutter;
5890
5888
  this._lineColorsContent = options.lineColorsContent;
5891
5889
  this._lineSigns = options.lineSigns;
@@ -5939,9 +5937,15 @@ class GutterRenderable extends Renderable2 {
5939
5937
  this.invalidateIntrinsicSize();
5940
5938
  this.requestRender();
5941
5939
  }
5940
+ setLayout(layout) {
5941
+ this._layout = layout;
5942
+ this.calculateSignWidths();
5943
+ this.invalidateIntrinsicSize();
5944
+ this.requestRender();
5945
+ }
5942
5946
  calculateSignWidths() {
5943
5947
  this._maxBeforeWidth = 0;
5944
- this._maxAfterWidth = 0;
5948
+ this._maxAfterWidth = this._layout.minAfterWidth;
5945
5949
  for (const sign of this._lineSigns.values()) {
5946
5950
  if (sign.before) {
5947
5951
  const width = stringWidth(sign.before);
@@ -5961,8 +5965,8 @@ class GutterRenderable extends Renderable2 {
5961
5965
  maxLineNumber = Math.max(maxLineNumber, customLineNum);
5962
5966
  }
5963
5967
  }
5964
- const digits = maxLineNumber > 0 ? Math.floor(Math.log10(maxLineNumber)) + 1 : 1;
5965
- const baseWidth = Math.max(this._minWidth, digits + this._paddingRight + 1);
5968
+ const digits = Math.max(maxLineNumber > 0 ? Math.floor(Math.log10(maxLineNumber)) + 1 : 1, this._layout.minDigits);
5969
+ const baseWidth = Math.max(this._layout.minWidth, digits + this._layout.paddingLeft + this._layout.paddingRight);
5966
5970
  return baseWidth + this._maxBeforeWidth + this._maxAfterWidth;
5967
5971
  }
5968
5972
  setLineColors(lineColorsGutter, lineColorsContent) {
@@ -6067,14 +6071,13 @@ class GutterRenderable extends Renderable2 {
6067
6071
  const lineNum = customLineNum !== undefined ? customLineNum : logicalLine + 1 + this._lineNumberOffset;
6068
6072
  const lineNumStr = lineNum.toString();
6069
6073
  const lineNumWidth = lineNumStr.length;
6070
- const availableSpace = this.width - this._maxBeforeWidth - this._maxAfterWidth - this._paddingRight;
6071
- const lineNumX = this._maxBeforeWidth + 1 + availableSpace - lineNumWidth - 1;
6072
- if (lineNumX >= this._maxBeforeWidth + 1) {
6074
+ const lineNumX = this.width - this._maxAfterWidth - this._layout.paddingRight - lineNumWidth;
6075
+ if (lineNumX >= this._maxBeforeWidth + this._layout.paddingLeft) {
6073
6076
  buffer.drawText(lineNumStr, lineNumX, i, this._fg, lineBg);
6074
6077
  }
6075
6078
  }
6076
6079
  if (sign?.after) {
6077
- const afterX = this.width - this._paddingRight - this._maxAfterWidth;
6080
+ const afterX = this.width - this._layout.paddingRight - this._maxAfterWidth;
6078
6081
  const afterColor = sign.afterColor ? parseColor2(sign.afterColor) : this._fg;
6079
6082
  buffer.drawText(sign.after, afterX, i, afterColor, lineBg);
6080
6083
  }
@@ -6100,8 +6103,7 @@ class LineNumberRenderable extends Renderable2 {
6100
6103
  _lineSigns;
6101
6104
  _fg;
6102
6105
  _bg;
6103
- _minWidth;
6104
- _paddingRight;
6106
+ _layout;
6105
6107
  _lineNumberOffset;
6106
6108
  _hideLineNumbers;
6107
6109
  _lineNumbers;
@@ -6136,8 +6138,13 @@ class LineNumberRenderable extends Renderable2 {
6136
6138
  try {
6137
6139
  this._fg = RGBA2.clone(parseColor2(options.fg ?? DEFAULT_GUTTER_FG));
6138
6140
  this._bg = RGBA2.clone(parseColor2(options.bg ?? DEFAULT_GUTTER_BG));
6139
- this._minWidth = options.minWidth ?? 3;
6140
- this._paddingRight = options.paddingRight ?? 1;
6141
+ this._layout = {
6142
+ minWidth: options.minWidth ?? 3,
6143
+ paddingLeft: 1,
6144
+ paddingRight: options.paddingRight ?? 1,
6145
+ minDigits: 0,
6146
+ minAfterWidth: 0
6147
+ };
6141
6148
  this._lineNumberOffset = options.lineNumberOffset ?? 0;
6142
6149
  this._hideLineNumbers = options.hideLineNumbers ?? new Set;
6143
6150
  this._lineNumbers = options.lineNumbers ?? new Map;
@@ -6173,8 +6180,7 @@ class LineNumberRenderable extends Renderable2 {
6173
6180
  this.gutter = new GutterRenderable(this.ctx, target, {
6174
6181
  fg: this._fg,
6175
6182
  bg: this._bg,
6176
- minWidth: this._minWidth,
6177
- paddingRight: this._paddingRight,
6183
+ layout: this._layout,
6178
6184
  lineColorsGutter: this._lineColorsGutter,
6179
6185
  lineColorsContent: this._lineColorsContent,
6180
6186
  lineSigns: this._lineSigns,
@@ -6378,6 +6384,15 @@ class LineNumberRenderable extends Renderable2 {
6378
6384
  getLineSigns() {
6379
6385
  return new Map(Array.from(this._lineSigns, ([line, sign]) => [line, cloneLineSign(sign)]));
6380
6386
  }
6387
+ getGutterLayout() {
6388
+ return { ...this._layout };
6389
+ }
6390
+ setGutterLayout(layout) {
6391
+ 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)
6392
+ return;
6393
+ this._layout = { ...layout };
6394
+ this.gutter?.setLayout(this._layout);
6395
+ }
6381
6396
  set lineNumberOffset(value) {
6382
6397
  if (this._lineNumberOffset !== value) {
6383
6398
  this._lineNumberOffset = value;
@@ -6755,6 +6770,7 @@ function parsePatch(uniDiff) {
6755
6770
  return list;
6756
6771
  }
6757
6772
  // src/renderables/Diff.ts
6773
+ var SIGN_WIDTH = 2;
6758
6774
  var defaultColors = {
6759
6775
  lineNumberFg: "#888888",
6760
6776
  lineNumberBg: "transparent",
@@ -6791,6 +6807,7 @@ class DiffRenderable extends Renderable2 {
6791
6807
  _showLineNumbers;
6792
6808
  _lineNumberFg;
6793
6809
  _lineNumberBg;
6810
+ _gutter;
6794
6811
  _addedBg;
6795
6812
  _removedBg;
6796
6813
  _contextBg;
@@ -6833,6 +6850,7 @@ class DiffRenderable extends Renderable2 {
6833
6850
  this._showLineNumbers = options.showLineNumbers ?? true;
6834
6851
  this._lineNumberFg = RGBA2.clone(parseColor2(options.lineNumberFg ?? defaultColors.lineNumberFg));
6835
6852
  this._lineNumberBg = RGBA2.clone(parseColor2(options.lineNumberBg ?? defaultColors.lineNumberBg));
6853
+ this._gutter = { ...options.gutter };
6836
6854
  this._addedBg = RGBA2.clone(parseColor2(options.addedBg ?? defaultColors.addedBg));
6837
6855
  this._removedBg = RGBA2.clone(parseColor2(options.removedBg ?? defaultColors.removedBg));
6838
6856
  this._contextBg = RGBA2.clone(parseColor2(options.contextBg ?? defaultColors.contextBg));
@@ -7133,6 +7151,7 @@ class DiffRenderable extends Renderable2 {
7133
7151
  height: "100%"
7134
7152
  });
7135
7153
  newSide.showLineNumbers = this._showLineNumbers;
7154
+ newSide.setGutterLayout(this.gutterLayout());
7136
7155
  super.add(newSide);
7137
7156
  if (side === "left") {
7138
7157
  this.leftSide = newSide;
@@ -7145,6 +7164,7 @@ class DiffRenderable extends Renderable2 {
7145
7164
  sideRef.width = width;
7146
7165
  sideRef.fg = this._lineNumberFg;
7147
7166
  sideRef.bg = this._lineNumberBg;
7167
+ sideRef.setGutterLayout(this.gutterLayout());
7148
7168
  sideRef.setLineColors(lineColors);
7149
7169
  const padding = sideRef.getLineSigns().get(-1);
7150
7170
  if (padding)
@@ -7162,6 +7182,15 @@ class DiffRenderable extends Renderable2 {
7162
7182
  }
7163
7183
  }
7164
7184
  }
7185
+ gutterLayout() {
7186
+ return {
7187
+ minWidth: 0,
7188
+ paddingLeft: this._gutter.paddingLeft ?? 1,
7189
+ paddingRight: this._gutter.paddingRight ?? 1,
7190
+ minDigits: this._gutter.minDigits ?? 0,
7191
+ minAfterWidth: this._gutter.minDigits === undefined ? 0 : SIGN_WIDTH
7192
+ };
7193
+ }
7165
7194
  buildUnifiedView() {
7166
7195
  if (!this._parsedDiff)
7167
7196
  return;
@@ -7668,6 +7697,16 @@ class DiffRenderable extends Renderable2 {
7668
7697
  this._lineNumberBg = RGBA2.clone(parseColor2(value ?? defaultColors.lineNumberBg));
7669
7698
  this.rebuildView();
7670
7699
  }
7700
+ get gutter() {
7701
+ return { ...this._gutter };
7702
+ }
7703
+ set gutter(value) {
7704
+ const next = { ...value };
7705
+ if (next.paddingLeft === this._gutter.paddingLeft && next.paddingRight === this._gutter.paddingRight && next.minDigits === this._gutter.minDigits)
7706
+ return;
7707
+ this._gutter = next;
7708
+ this.rebuildView();
7709
+ }
7671
7710
  get addedContentBg() {
7672
7711
  return this._addedContentBg ? RGBA2.clone(this._addedContentBg) : null;
7673
7712
  }
@@ -15461,5 +15500,5 @@ export {
15461
15500
  yellow2 as yellow
15462
15501
  };
15463
15502
 
15464
- //# debugId=C1B12A177A7D3E0364756E2164756E21
15503
+ //# debugId=7D2171B169F19E4C64756E2164756E21
15465
15504
  //# sourceMappingURL=index.node.js.map