@opentui/core 0.6.0 → 0.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -8,7 +8,6 @@ import {
8
8
  registerEnvVar2,
9
9
  env2,
10
10
  stringWidth,
11
- stripANSI,
12
11
  Worker,
13
12
  DEFAULT_FOREGROUND_RGB2,
14
13
  DEFAULT_BACKGROUND_RGB2,
@@ -64,7 +63,7 @@ import {
64
63
  PositionType2,
65
64
  Unit2,
66
65
  Wrap2
67
- } from "./chunk-bun-tsc14mt5.js";
66
+ } from "./chunk-bun-b3p27aka.js";
68
67
 
69
68
  // src/lib/border.ts
70
69
  var VALID_BORDER_STYLES = ["single", "double", "rounded", "heavy"];
@@ -4102,8 +4101,7 @@ var parseKeypress2 = (s = "", options = {}) => {
4102
4101
  let parts;
4103
4102
  if (Buffer2.isBuffer(s)) {
4104
4103
  if (s[0] > 127 && s[1] === undefined) {
4105
- s[0] -= 128;
4106
- s = "\x1B" + String(s);
4104
+ s = "\x1B" + String.fromCharCode(s[0] - 128);
4107
4105
  } else {
4108
4106
  s = String(s);
4109
4107
  }
@@ -8081,8 +8079,7 @@ class ExtmarksController2 {
8081
8079
  return;
8082
8080
  }
8083
8081
  const targetOffset = currentOffset + 1;
8084
- const textLength = this.editBuffer.getText().length;
8085
- if (targetOffset > textLength) {
8082
+ if (this.editBuffer.offsetToPosition(targetOffset) === null) {
8086
8083
  this.originalMoveCursorRight();
8087
8084
  return;
8088
8085
  }
@@ -8256,28 +8253,12 @@ class ExtmarksController2 {
8256
8253
  this.originalDeleteLine();
8257
8254
  return;
8258
8255
  }
8259
- const text = this.editBuffer.getText();
8260
- const currentOffset = this.editorView.getVisualCursor().offset;
8261
- let lineStart = 0;
8262
- for (let i = currentOffset - 1;i >= 0; i--) {
8263
- if (text[i] === `
8264
- `) {
8265
- lineStart = i + 1;
8266
- break;
8267
- }
8268
- }
8269
- let lineEnd = text.length;
8270
- for (let i = currentOffset;i < text.length; i++) {
8271
- if (text[i] === `
8272
- `) {
8273
- lineEnd = i + 1;
8274
- break;
8275
- }
8276
- }
8277
- const deleteLength = lineEnd - lineStart;
8256
+ const row = this.editBuffer.getCursorPosition().row;
8257
+ const lineStart = this.editBuffer.getLineStartOffset(row);
8258
+ const [start, end] = row + 1 < this.editBuffer.getLineCount() ? [lineStart, this.editBuffer.getLineStartOffset(row + 1)] : [Math.max(0, lineStart - 1), this.editBuffer.getEOL().offset];
8278
8259
  this.originalDeleteLine();
8279
8260
  this.saveSnapshot();
8280
- this.adjustExtmarksAfterDeletion(lineStart, deleteLength);
8261
+ this.adjustExtmarksAfterDeletion(start, end - start);
8281
8262
  });
8282
8263
  }
8283
8264
  wrapInsertion() {
@@ -8468,15 +8449,11 @@ class ExtmarksController2 {
8468
8449
  }
8469
8450
  updateHighlights() {
8470
8451
  this.editBuffer.clearAllHighlights();
8471
- let text;
8472
8452
  for (const extmark of this.extmarks.values()) {
8473
8453
  if (extmark.styleId !== undefined) {
8474
- text ??= this.editBuffer.getText();
8475
- const startWithoutNewlines = this.offsetExcludingNewlines(extmark.start, text);
8476
- const endWithoutNewlines = this.offsetExcludingNewlines(extmark.end, text);
8477
8454
  this.editBuffer.addHighlightByCharRange({
8478
- start: startWithoutNewlines,
8479
- end: endWithoutNewlines,
8455
+ start: this.offsetExcludingNewlines(extmark.start),
8456
+ end: this.offsetExcludingNewlines(extmark.end),
8480
8457
  styleId: extmark.styleId,
8481
8458
  priority: extmark.priority ?? 0,
8482
8459
  hlRef: extmark.id & 65535
@@ -8484,37 +8461,8 @@ class ExtmarksController2 {
8484
8461
  }
8485
8462
  }
8486
8463
  }
8487
- offsetExcludingNewlines(offset, text) {
8488
- let displayWidthSoFar = 0;
8489
- let newlineCount = 0;
8490
- let i = 0;
8491
- while (i < text.length && displayWidthSoFar < offset) {
8492
- if (text[i] === `
8493
- `) {
8494
- displayWidthSoFar++;
8495
- newlineCount++;
8496
- i++;
8497
- } else {
8498
- let j = i;
8499
- while (j < text.length && text[j] !== `
8500
- `) {
8501
- j++;
8502
- }
8503
- const chunk = text.substring(i, j);
8504
- const chunkWidth = stringWidth(chunk);
8505
- if (displayWidthSoFar + chunkWidth < offset) {
8506
- displayWidthSoFar += chunkWidth;
8507
- i = j;
8508
- } else {
8509
- for (let k = i;k < j && displayWidthSoFar < offset; k++) {
8510
- const charWidth = stringWidth(text[k]);
8511
- displayWidthSoFar += charWidth;
8512
- }
8513
- break;
8514
- }
8515
- }
8516
- }
8517
- return offset - newlineCount;
8464
+ offsetExcludingNewlines(offset) {
8465
+ return offset - (this.editBuffer.offsetToPosition(offset)?.row ?? 0);
8518
8466
  }
8519
8467
  create(options) {
8520
8468
  if (this.destroyed) {
@@ -9033,11 +8981,12 @@ function buildTerminalPaletteSignature2(colors) {
9033
8981
 
9034
8982
  // src/lib/paste.ts
9035
8983
  var PASTE_TEXT_DECODER = new TextDecoder;
8984
+ var ANSI_SEQUENCES = /(?:\x1b\[|\x9b)[\x30-\x3f]*[\x20-\x2f]*[\x40-\x7e]?|(?:\x1b[P\]X^_]|[\x90\x98\x9d-\x9f])[^\x07\x1b\x9c]*(?:\x07|\x1b\\|\x9c)?|\x1b[\x20-\x2f]*[\x30-\x7e]?/g;
9036
8985
  function decodePasteBytes2(bytes) {
9037
8986
  return PASTE_TEXT_DECODER.decode(bytes);
9038
8987
  }
9039
8988
  function stripAnsiSequences2(text) {
9040
- return stripANSI(text);
8989
+ return text.replace(ANSI_SEQUENCES, "");
9041
8990
  }
9042
8991
 
9043
8992
  // src/lib/host-clipboard.internal.ts
@@ -13429,6 +13378,10 @@ class EditBuffer2 extends EventEmitter5 {
13429
13378
  getLineStartOffset(row) {
13430
13379
  return this.position(6 /* LineStart */, row)?.offset ?? 0;
13431
13380
  }
13381
+ measureText(text) {
13382
+ this.guard();
13383
+ return this.lib.contextEditBufferMeasureText(this.native.handle.context, this.native.handle, this.lib.encoder.encode(text));
13384
+ }
13432
13385
  getTextRange(startOffset, endOffset) {
13433
13386
  this.guard();
13434
13387
  if (startOffset >= endOffset)
@@ -13520,6 +13473,10 @@ class EditBuffer2 extends EventEmitter5 {
13520
13473
  });
13521
13474
  }
13522
13475
  }
13476
+ function measureEditText2(text, options) {
13477
+ const lib = resolveRenderLib2();
13478
+ return lib.editMeasureText(lib.encoder.encode(text), options.widthMethod, options.tabWidth ?? 0);
13479
+ }
13523
13480
 
13524
13481
  // src/editor-view.ts
13525
13482
  class EditorView2 {
@@ -24908,7 +24865,7 @@ Captured external output:
24908
24865
  }
24909
24866
  }
24910
24867
 
24911
- export { isValidBorderStyle2, parseBorderStyle2, BorderChars2, getBorderFromSides2, getBorderSides2, borderCharsToArray2, BorderCharArrays2, KeyEvent2, PasteEvent2, KeyHandler2, InternalKeyHandler2, fonts2, measureText2, getCharacterPositions2, coordinateToCharacterIndex2, renderFontToFrameBuffer2, convertThemeToStyles2, SyntaxStyle2, hastToStyledText2, SystemClock2, nonAlphanumericKeys2, terminalNamedSingleStrokeKeys2, parseKeypress2, LinearScrollAccel2, MacOSScrollAccel2, parseAlign2, parseAlignItems2, parseBoxSizing2, parseDimension2, parseDirection2, parseDisplay2, parseEdge2, parseFlexDirection2, parseGutter2, parseJustify2, parseLogLevel2, parseMeasureMode2, parseOverflow2, parsePositionType2, parseUnit2, parseWrap2, MouseParser2, Selection2, convertGlobalToLocalSelection2, ASCIIFontSelectionHelper2, StdinParser2, addDefaultParsers2, TreeSitterClient2, treeSitterToTextChunks2, treeSitterToStyledText2, DataPathsManager2, getDataPaths2, extensionToFiletype2, basenameToFiletype2, extToFiletype2, pathToFiletype2, infoStringToFiletype2, getTreeSitterClient2, destroyTreeSitterClient2, ExtmarksController2, createExtmarksController2, TerminalPalette2, createTerminalPalette2, normalizeTerminalPalette2, buildTerminalPaletteSignature2, decodePasteBytes2, stripAnsiSequences2, createHostClipboard2, createClipboard2, ClipboardTarget2, createRendererClipboardAdapter2, normalizeMarkdownLinkTarget, detectLinks2, acquireSessionBufferLease2, ResourceContext2, OptimizedBuffer2, h2, isVNode2, maybeMakeRenderable2, wrapWithDelegates2, instantiate2, delegate2, LayoutEvents2, RenderableEvents2, isRenderable2, BaseRenderable2, Renderable2, RootRenderable2, TextBuffer2, TextBufferView2, EditBuffer2, EditorView2, Timeline2, engine2, getTimelineEngine2, createTimeline2, ANSI, BoxRenderable2, TextBufferRenderable2, CodeRenderable2, ImageLoadError2, ImageError2, imageInfo2, NativeImage2, NativeImagePool2, resolveImageRenderProtocol2, ImageRenderable2, isTextNodeRenderable2, TextNodeRenderable2, RootTextNodeRenderable2, TextRenderable2, NativeSession2, defaultKeyAliases, mergeKeyAliases, mergeKeyBindings, getKeyBindingAction, buildKeyBindingsMap, capture2, ConsolePosition2, TerminalConsole2, EditBufferRenderableEvents2, isEditBufferRenderable2, EditBufferRenderable2, buildKittyKeyboardFlags2, MouseEvent2, MouseButton2, createCliRenderer2, CliRenderEvents2, RendererControlState2, CliRenderer2 };
24868
+ export { isValidBorderStyle2, parseBorderStyle2, BorderChars2, getBorderFromSides2, getBorderSides2, borderCharsToArray2, BorderCharArrays2, KeyEvent2, PasteEvent2, KeyHandler2, InternalKeyHandler2, fonts2, measureText2, getCharacterPositions2, coordinateToCharacterIndex2, renderFontToFrameBuffer2, convertThemeToStyles2, SyntaxStyle2, hastToStyledText2, SystemClock2, nonAlphanumericKeys2, terminalNamedSingleStrokeKeys2, parseKeypress2, LinearScrollAccel2, MacOSScrollAccel2, parseAlign2, parseAlignItems2, parseBoxSizing2, parseDimension2, parseDirection2, parseDisplay2, parseEdge2, parseFlexDirection2, parseGutter2, parseJustify2, parseLogLevel2, parseMeasureMode2, parseOverflow2, parsePositionType2, parseUnit2, parseWrap2, MouseParser2, Selection2, convertGlobalToLocalSelection2, ASCIIFontSelectionHelper2, StdinParser2, addDefaultParsers2, TreeSitterClient2, treeSitterToTextChunks2, treeSitterToStyledText2, DataPathsManager2, getDataPaths2, extensionToFiletype2, basenameToFiletype2, extToFiletype2, pathToFiletype2, infoStringToFiletype2, getTreeSitterClient2, destroyTreeSitterClient2, ExtmarksController2, createExtmarksController2, TerminalPalette2, createTerminalPalette2, normalizeTerminalPalette2, buildTerminalPaletteSignature2, decodePasteBytes2, stripAnsiSequences2, createHostClipboard2, createClipboard2, ClipboardTarget2, createRendererClipboardAdapter2, normalizeMarkdownLinkTarget, detectLinks2, acquireSessionBufferLease2, ResourceContext2, OptimizedBuffer2, h2, isVNode2, maybeMakeRenderable2, wrapWithDelegates2, instantiate2, delegate2, LayoutEvents2, RenderableEvents2, isRenderable2, BaseRenderable2, Renderable2, RootRenderable2, TextBuffer2, TextBufferView2, EditBuffer2, measureEditText2, EditorView2, Timeline2, engine2, getTimelineEngine2, createTimeline2, ANSI, BoxRenderable2, TextBufferRenderable2, CodeRenderable2, ImageLoadError2, ImageError2, imageInfo2, NativeImage2, NativeImagePool2, resolveImageRenderProtocol2, ImageRenderable2, isTextNodeRenderable2, TextNodeRenderable2, RootTextNodeRenderable2, TextRenderable2, NativeSession2, defaultKeyAliases, mergeKeyAliases, mergeKeyBindings, getKeyBindingAction, buildKeyBindingsMap, capture2, ConsolePosition2, TerminalConsole2, EditBufferRenderableEvents2, isEditBufferRenderable2, EditBufferRenderable2, buildKittyKeyboardFlags2, MouseEvent2, MouseButton2, createCliRenderer2, CliRenderEvents2, RendererControlState2, CliRenderer2 };
24912
24869
 
24913
- //# debugId=979769E7103DB2AA64756E2164756E21
24914
- //# sourceMappingURL=chunk-bun-s01c2jyn.js.map
24870
+ //# debugId=31E2841B7F89BB7A64756E2164756E21
24871
+ //# sourceMappingURL=chunk-bun-ehstr7d7.js.map