@opentui/core 0.4.1 → 0.4.3

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.js CHANGED
@@ -43,13 +43,15 @@ import {
43
43
  mergeKeyAliases,
44
44
  mergeKeyBindings,
45
45
  wrapWithDelegates
46
- } from "./index-07zpr2dg.js";
46
+ } from "./index-xt9f071j.js";
47
47
  import {
48
48
  ASCIIFontSelectionHelper,
49
49
  ATTRIBUTE_BASE_BITS,
50
50
  ATTRIBUTE_BASE_MASK,
51
51
  BorderCharArrays,
52
52
  BorderChars,
53
+ Clipboard,
54
+ ClipboardTarget,
53
55
  DEFAULT_BACKGROUND_RGB,
54
56
  DEFAULT_FOREGROUND_RGB,
55
57
  DataPathsManager,
@@ -62,6 +64,7 @@ import {
62
64
  LogLevel,
63
65
  MacOSScrollAccel,
64
66
  MouseParser,
67
+ NativeMeasureTargetKind,
65
68
  OptimizedBuffer,
66
69
  PasteEvent,
67
70
  RGBA,
@@ -182,7 +185,7 @@ import {
182
185
  visualizeRenderableTree,
183
186
  white,
184
187
  yellow
185
- } from "./index-pcvh9d34.js";
188
+ } from "./index-d5xqskty.js";
186
189
  // src/post/effects.ts
187
190
  function toU8(value) {
188
191
  return Math.round(Math.max(0, Math.min(1, Number.isFinite(value) ? value : 0)) * 255);
@@ -2429,7 +2432,7 @@ class SlotRenderable extends Renderable {
2429
2432
  }
2430
2433
  _detachNodeFromMount(node) {
2431
2434
  if (node.parent === this) {
2432
- this.remove(node.id);
2435
+ this.remove(node);
2433
2436
  }
2434
2437
  }
2435
2438
  _cleanupInactivePluginNodes(nextActivePluginIds, registeredPluginIds) {
@@ -2502,7 +2505,7 @@ class SlotRenderable extends Renderable {
2502
2505
  for (const node of this._mountedNodes) {
2503
2506
  if (!desiredNodeSet.has(node)) {
2504
2507
  if (node.parent === this) {
2505
- this.remove(node.id);
2508
+ this.remove(node);
2506
2509
  }
2507
2510
  }
2508
2511
  }
@@ -2513,7 +2516,7 @@ class SlotRenderable extends Renderable {
2513
2516
  continue;
2514
2517
  }
2515
2518
  const childAtIndex = this.getChildren()[index];
2516
- if (childAtIndex?.id !== node.id) {
2519
+ if (childAtIndex !== node) {
2517
2520
  this.add(node, index);
2518
2521
  }
2519
2522
  }
@@ -3433,10 +3436,10 @@ class LineNumberRenderable extends Renderable {
3433
3436
  return;
3434
3437
  if (this.target) {
3435
3438
  this.target.off("line-info-change", this.handleLineInfoChange);
3436
- super.remove(this.target.id);
3439
+ super.remove(this.target);
3437
3440
  }
3438
3441
  if (this.gutter) {
3439
- super.remove(this.gutter.id);
3442
+ super.remove(this.gutter);
3440
3443
  this.gutter = null;
3441
3444
  }
3442
3445
  this.target = target;
@@ -3465,18 +3468,18 @@ class LineNumberRenderable extends Renderable {
3465
3468
  }
3466
3469
  return -1;
3467
3470
  }
3468
- remove(id) {
3471
+ remove(child) {
3469
3472
  if (this._isDestroying) {
3470
- super.remove(id);
3473
+ super.remove(child);
3471
3474
  return;
3472
3475
  }
3473
- if (this.gutter && id === this.gutter.id) {
3476
+ if (this.gutter && child === this.gutter) {
3474
3477
  throw new Error("LineNumberRenderable: Cannot remove gutter directly.");
3475
3478
  }
3476
- if (this.target && id === this.target.id) {
3479
+ if (this.target && child === this.target) {
3477
3480
  throw new Error("LineNumberRenderable: Cannot remove target directly. Use clearTarget() instead.");
3478
3481
  }
3479
- super.remove(id);
3482
+ super.remove(child);
3480
3483
  }
3481
3484
  destroyRecursively() {
3482
3485
  this._isDestroying = true;
@@ -3490,11 +3493,11 @@ class LineNumberRenderable extends Renderable {
3490
3493
  clearTarget() {
3491
3494
  if (this.target) {
3492
3495
  this.target.off("line-info-change", this.handleLineInfoChange);
3493
- super.remove(this.target.id);
3496
+ super.remove(this.target);
3494
3497
  this.target = null;
3495
3498
  }
3496
3499
  if (this.gutter) {
3497
- super.remove(this.gutter.id);
3500
+ super.remove(this.gutter);
3498
3501
  this.gutter = null;
3499
3502
  }
3500
3503
  }
@@ -4207,11 +4210,11 @@ class DiffRenderable extends Renderable {
4207
4210
  buildErrorView() {
4208
4211
  this.flexDirection = "column";
4209
4212
  if (this.leftSide && this.leftSideAdded) {
4210
- super.remove(this.leftSide.id);
4213
+ super.remove(this.leftSide);
4211
4214
  this.leftSideAdded = false;
4212
4215
  }
4213
4216
  if (this.rightSide && this.rightSideAdded) {
4214
- super.remove(this.rightSide.id);
4217
+ super.remove(this.rightSide);
4215
4218
  this.rightSideAdded = false;
4216
4219
  }
4217
4220
  const errorMessage = `Error parsing diff: ${this._parseError?.message || "Unknown error"}
@@ -4359,13 +4362,13 @@ class DiffRenderable extends Renderable {
4359
4362
  if (this.errorTextRenderable) {
4360
4363
  const errorTextIndex = this.getChildren().indexOf(this.errorTextRenderable);
4361
4364
  if (errorTextIndex !== -1) {
4362
- super.remove(this.errorTextRenderable.id);
4365
+ super.remove(this.errorTextRenderable);
4363
4366
  }
4364
4367
  }
4365
4368
  if (this.errorCodeRenderable) {
4366
4369
  const errorCodeIndex = this.getChildren().indexOf(this.errorCodeRenderable);
4367
4370
  if (errorCodeIndex !== -1) {
4368
- super.remove(this.errorCodeRenderable.id);
4371
+ super.remove(this.errorCodeRenderable);
4369
4372
  }
4370
4373
  }
4371
4374
  const contentLines = [];
@@ -4440,7 +4443,7 @@ class DiffRenderable extends Renderable {
4440
4443
  this.attachLineInfoListeners();
4441
4444
  this.createOrUpdateSide("left", codeRenderable, lineColors, lineSigns, lineNumbers, new Set, "100%");
4442
4445
  if (this.rightSide && this.rightSideAdded) {
4443
- super.remove(this.rightSide.id);
4446
+ super.remove(this.rightSide);
4444
4447
  this.rightSideAdded = false;
4445
4448
  }
4446
4449
  }
@@ -4451,13 +4454,13 @@ class DiffRenderable extends Renderable {
4451
4454
  if (this.errorTextRenderable) {
4452
4455
  const errorTextIndex = this.getChildren().indexOf(this.errorTextRenderable);
4453
4456
  if (errorTextIndex !== -1) {
4454
- super.remove(this.errorTextRenderable.id);
4457
+ super.remove(this.errorTextRenderable);
4455
4458
  }
4456
4459
  }
4457
4460
  if (this.errorCodeRenderable) {
4458
4461
  const errorCodeIndex = this.getChildren().indexOf(this.errorCodeRenderable);
4459
4462
  if (errorCodeIndex !== -1) {
4460
- super.remove(this.errorCodeRenderable.id);
4463
+ super.remove(this.errorCodeRenderable);
4461
4464
  }
4462
4465
  }
4463
4466
  const leftLogicalLines = [];
@@ -10373,12 +10376,19 @@ class ScrollBoxRenderable extends BoxRenderable {
10373
10376
  insertBefore(obj, anchor) {
10374
10377
  return this.content.insertBefore(obj, anchor);
10375
10378
  }
10376
- remove(id) {
10377
- this.content.remove(id);
10379
+ remove(child) {
10380
+ if (child.parent === this) {
10381
+ super.remove(child);
10382
+ return;
10383
+ }
10384
+ this.content.remove(child);
10378
10385
  }
10379
10386
  getChildren() {
10380
10387
  return this.content.getChildren();
10381
10388
  }
10389
+ getRenderable(id) {
10390
+ return this.content.getRenderable(id);
10391
+ }
10382
10392
  onMouseEvent(event) {
10383
10393
  if (event.type === "scroll") {
10384
10394
  let dir = event.scroll?.direction;
@@ -10699,6 +10709,7 @@ class SelectRenderable extends Renderable {
10699
10709
  _showScrollIndicator;
10700
10710
  _wrapSelection;
10701
10711
  _showDescription;
10712
+ _showSelectionIndicator;
10702
10713
  _font;
10703
10714
  _itemSpacing;
10704
10715
  linesPerItem;
@@ -10720,6 +10731,7 @@ class SelectRenderable extends Renderable {
10720
10731
  showScrollIndicator: false,
10721
10732
  wrapSelection: false,
10722
10733
  showDescription: true,
10734
+ showSelectionIndicator: true,
10723
10735
  itemSpacing: 0,
10724
10736
  fastScrollStep: 5
10725
10737
  };
@@ -10735,6 +10747,7 @@ class SelectRenderable extends Renderable {
10735
10747
  this._showScrollIndicator = options.showScrollIndicator ?? this._defaultOptions.showScrollIndicator;
10736
10748
  this._wrapSelection = options.wrapSelection ?? this._defaultOptions.wrapSelection;
10737
10749
  this._showDescription = options.showDescription ?? this._defaultOptions.showDescription;
10750
+ this._showSelectionIndicator = options.showSelectionIndicator ?? this._defaultOptions.showSelectionIndicator;
10738
10751
  this._font = options.font;
10739
10752
  this._itemSpacing = options.itemSpacing || this._defaultOptions.itemSpacing;
10740
10753
  this.fontHeight = this._font ? measureText({ text: "A", font: this._font }).height : 1;
@@ -10750,6 +10763,7 @@ class SelectRenderable extends Renderable {
10750
10763
  this._keyBindings = options.keyBindings || [];
10751
10764
  const mergedBindings = mergeKeyBindings(defaultSelectKeybindings, this._keyBindings);
10752
10765
  this._keyBindingsMap = buildKeyBindingsMap(mergedBindings, this._keyAliasMap);
10766
+ this.updateScrollOffset();
10753
10767
  this.requestRender();
10754
10768
  }
10755
10769
  renderSelf(buffer, deltaTime) {
@@ -10782,29 +10796,30 @@ class SelectRenderable extends Renderable {
10782
10796
  const contentHeight2 = this.linesPerItem - this._itemSpacing;
10783
10797
  this.frameBuffer.fillRect(contentX, itemY, contentWidth, contentHeight2, this._selectedBackgroundColor);
10784
10798
  }
10785
- const nameContent = `${isSelected ? "▶ " : " "}${option.name}`;
10799
+ const indicator = this._showSelectionIndicator ? isSelected ? "▶ " : " " : "";
10800
+ const indicatorWidth = this._showSelectionIndicator ? 2 : 0;
10801
+ const nameContent = `${indicator}${option.name}`;
10786
10802
  const baseTextColor = this._focused ? this._focusedTextColor : this._textColor;
10787
10803
  const nameColor = isSelected ? this._selectedTextColor : baseTextColor;
10788
- let descX = contentX + 3;
10804
+ const textX = contentX + 1 + indicatorWidth;
10789
10805
  if (this._font) {
10790
- const indicator = isSelected ? "▶ " : " ";
10791
- this.frameBuffer.drawText(indicator, contentX + 1, itemY, nameColor);
10792
- const indicatorWidth = 2;
10806
+ if (indicator) {
10807
+ this.frameBuffer.drawText(indicator, contentX + 1, itemY, nameColor);
10808
+ }
10793
10809
  renderFontToFrameBuffer(this.frameBuffer, {
10794
10810
  text: option.name,
10795
- x: contentX + 1 + indicatorWidth,
10811
+ x: textX,
10796
10812
  y: itemY,
10797
10813
  color: nameColor,
10798
10814
  backgroundColor: isSelected ? this._selectedBackgroundColor : bgColor,
10799
10815
  font: this._font
10800
10816
  });
10801
- descX = contentX + 1 + indicatorWidth;
10802
10817
  } else {
10803
10818
  this.frameBuffer.drawText(nameContent, contentX + 1, itemY, nameColor);
10804
10819
  }
10805
10820
  if (this._showDescription && itemY + this.fontHeight < contentY + contentHeight) {
10806
10821
  const descColor = isSelected ? this._selectedDescriptionColor : this._descriptionColor;
10807
- this.frameBuffer.drawText(option.description, descX, itemY + this.fontHeight, descColor);
10822
+ this.frameBuffer.drawText(option.description, textX, itemY + this.fontHeight, descColor);
10808
10823
  }
10809
10824
  }
10810
10825
  if (this._showScrollIndicator && this._options.length > this.maxVisibleItems) {
@@ -10814,7 +10829,8 @@ class SelectRenderable extends Renderable {
10814
10829
  renderScrollIndicatorToFrameBuffer(contentX, contentY, contentWidth, contentHeight) {
10815
10830
  if (!this.frameBuffer)
10816
10831
  return;
10817
- const scrollPercent = this._selectedIndex / Math.max(1, this._options.length - 1);
10832
+ const maxScrollOffset = this._options.length - this.maxVisibleItems;
10833
+ const scrollPercent = this.scrollOffset / maxScrollOffset;
10818
10834
  const indicatorHeight = Math.max(1, contentHeight - 2);
10819
10835
  const indicatorY = contentY + 1 + Math.floor(scrollPercent * indicatorHeight);
10820
10836
  const indicatorX = contentX + contentWidth - 1;
@@ -10933,6 +10949,16 @@ class SelectRenderable extends Renderable {
10933
10949
  this.requestRender();
10934
10950
  }
10935
10951
  }
10952
+ get showSelectionIndicator() {
10953
+ return this._showSelectionIndicator;
10954
+ }
10955
+ set showSelectionIndicator(show) {
10956
+ const next = show ?? this._defaultOptions.showSelectionIndicator;
10957
+ if (this._showSelectionIndicator !== next) {
10958
+ this._showSelectionIndicator = next;
10959
+ this.requestRender();
10960
+ }
10961
+ }
10936
10962
  get wrapSelection() {
10937
10963
  return this._wrapSelection;
10938
10964
  }
@@ -11618,6 +11644,7 @@ export {
11618
11644
  PROTANOPIA_COMP_MATRIX,
11619
11645
  OptimizedBuffer,
11620
11646
  NativeSpanFeed,
11647
+ NativeMeasureTargetKind,
11621
11648
  MouseParser,
11622
11649
  MouseEvent,
11623
11650
  MouseButton,
@@ -11657,6 +11684,8 @@ export {
11657
11684
  CodeRenderable,
11658
11685
  Code,
11659
11686
  CloudsEffect,
11687
+ ClipboardTarget,
11688
+ Clipboard,
11660
11689
  CliRenderer,
11661
11690
  CliRenderEvents,
11662
11691
  CRTRollingBarEffect,
@@ -11676,5 +11705,5 @@ export {
11676
11705
  ACHROMATOPSIA_MATRIX
11677
11706
  };
11678
11707
 
11679
- //# debugId=0C019ED1790BA7F464756E2164756E21
11708
+ //# debugId=9FCFC4351B1344F964756E2164756E21
11680
11709
  //# sourceMappingURL=index.js.map