@opentui/core 0.1.8 → 0.1.9

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
@@ -1646,9 +1646,9 @@ var src_default = Yoga;
1646
1646
 
1647
1647
  // src/lib/TrackedNode.ts
1648
1648
  import { EventEmitter } from "events";
1649
- var idCounter = 0;
1650
1649
 
1651
1650
  class TrackedNode extends EventEmitter {
1651
+ static idCounter = 0;
1652
1652
  id;
1653
1653
  yogaNode;
1654
1654
  metadata;
@@ -1659,7 +1659,7 @@ class TrackedNode extends EventEmitter {
1659
1659
  _height = "auto";
1660
1660
  constructor(yogaNode, metadata = {}) {
1661
1661
  super();
1662
- this.id = idCounter++;
1662
+ this.id = TrackedNode.idCounter++;
1663
1663
  this.yogaNode = yogaNode;
1664
1664
  this.metadata = metadata;
1665
1665
  this.parent = null;
@@ -1991,6 +1991,16 @@ var parseKeypress = (s = "") => {
1991
1991
  return key;
1992
1992
  };
1993
1993
 
1994
+ // src/singleton.ts
1995
+ var singletonCacheSymbol = Symbol.for("@opentui/core/singleton");
1996
+ function singleton(key, factory) {
1997
+ const bag = globalThis[singletonCacheSymbol] ??= {};
1998
+ if (!(key in bag)) {
1999
+ bag[key] = factory();
2000
+ }
2001
+ return bag[key];
2002
+ }
2003
+
1994
2004
  // src/lib/KeyHandler.ts
1995
2005
  class KeyHandler extends EventEmitter2 {
1996
2006
  constructor() {
@@ -2012,7 +2022,7 @@ class KeyHandler extends EventEmitter2 {
2012
2022
  var keyHandler = null;
2013
2023
  function getKeyHandler() {
2014
2024
  if (!keyHandler) {
2015
- keyHandler = new KeyHandler;
2025
+ keyHandler = singleton("KeyHandler", () => new KeyHandler);
2016
2026
  }
2017
2027
  return keyHandler;
2018
2028
  }
@@ -2248,7 +2258,6 @@ var RenderableEvents;
2248
2258
  RenderableEvents2["FOCUSED"] = "focused";
2249
2259
  RenderableEvents2["BLURRED"] = "blurred";
2250
2260
  })(RenderableEvents ||= {});
2251
- var renderableNumber = 1;
2252
2261
  function validateOptions(id, options) {
2253
2262
  if (typeof options.width === "number") {
2254
2263
  if (options.width < 0) {
@@ -2319,6 +2328,7 @@ function isSizeType(value) {
2319
2328
  }
2320
2329
 
2321
2330
  class Renderable extends EventEmitter3 {
2331
+ static renderableNumber = 1;
2322
2332
  static renderablesByNumber = new Map;
2323
2333
  id;
2324
2334
  num;
@@ -2350,11 +2360,10 @@ class Renderable extends EventEmitter3 {
2350
2360
  renderableArray = [];
2351
2361
  needsZIndexSort = false;
2352
2362
  parent = null;
2353
- _yogaPerformancePositionUpdated = false;
2354
2363
  constructor(id, options) {
2355
2364
  super();
2356
2365
  this.id = id;
2357
- this.num = renderableNumber++;
2366
+ this.num = Renderable.renderableNumber++;
2358
2367
  Renderable.renderablesByNumber.set(this.num, this);
2359
2368
  validateOptions(id, options);
2360
2369
  this._width = options.width ?? "auto";
@@ -2397,7 +2406,7 @@ class Renderable extends EventEmitter3 {
2397
2406
  if (this._focused) {
2398
2407
  this.blur();
2399
2408
  }
2400
- this.requestLayout();
2409
+ this.needsUpdate();
2401
2410
  }
2402
2411
  hasSelection() {
2403
2412
  return false;
@@ -2525,7 +2534,7 @@ class Renderable extends EventEmitter3 {
2525
2534
  if (isDimensionType(value)) {
2526
2535
  this._width = value;
2527
2536
  this.layoutNode.setWidth(value);
2528
- this.requestLayout();
2537
+ this.needsUpdate();
2529
2538
  }
2530
2539
  }
2531
2540
  get height() {
@@ -2535,7 +2544,7 @@ class Renderable extends EventEmitter3 {
2535
2544
  if (isDimensionType(value)) {
2536
2545
  this._height = value;
2537
2546
  this.layoutNode.setHeight(value);
2538
- this.requestLayout();
2547
+ this.needsUpdate();
2539
2548
  }
2540
2549
  }
2541
2550
  get zIndex() {
@@ -2662,7 +2671,6 @@ class Renderable extends EventEmitter3 {
2662
2671
  this._positionType = positionType;
2663
2672
  this.layoutNode.yogaNode.setPositionType(parsePositionType(positionType));
2664
2673
  this.needsUpdate();
2665
- this._yogaPerformancePositionUpdated = true;
2666
2674
  }
2667
2675
  setPosition(position) {
2668
2676
  this._position = { ...this._position, ...position };
@@ -2671,95 +2679,84 @@ class Renderable extends EventEmitter3 {
2671
2679
  updateYogaPosition(position) {
2672
2680
  const node = this.layoutNode.yogaNode;
2673
2681
  const { top, right, bottom, left } = position;
2674
- if (this._positionType === "relative") {
2675
- if (isPositionType(top)) {
2676
- if (top === "auto") {
2677
- node.setPositionAuto(Edge.Top);
2678
- } else {
2679
- node.setPosition(Edge.Top, top);
2680
- }
2681
- }
2682
- if (isPositionType(right)) {
2683
- if (right === "auto") {
2684
- node.setPositionAuto(Edge.Right);
2685
- } else {
2686
- node.setPosition(Edge.Right, right);
2687
- }
2688
- }
2689
- if (isPositionType(bottom)) {
2690
- if (bottom === "auto") {
2691
- node.setPositionAuto(Edge.Bottom);
2692
- } else {
2693
- node.setPosition(Edge.Bottom, bottom);
2694
- }
2682
+ if (isPositionType(top)) {
2683
+ if (top === "auto") {
2684
+ node.setPositionAuto(Edge.Top);
2685
+ } else {
2686
+ node.setPosition(Edge.Top, top);
2695
2687
  }
2696
- if (isPositionType(left)) {
2697
- if (left === "auto") {
2698
- node.setPositionAuto(Edge.Left);
2699
- } else {
2700
- node.setPosition(Edge.Left, left);
2701
- }
2688
+ }
2689
+ if (isPositionType(right)) {
2690
+ if (right === "auto") {
2691
+ node.setPositionAuto(Edge.Right);
2692
+ } else {
2693
+ node.setPosition(Edge.Right, right);
2702
2694
  }
2703
- this.requestLayout();
2704
- } else {
2705
- if (typeof top === "number" && this._positionType === "absolute") {
2706
- this._y = top;
2695
+ }
2696
+ if (isPositionType(bottom)) {
2697
+ if (bottom === "auto") {
2698
+ node.setPositionAuto(Edge.Bottom);
2699
+ } else {
2700
+ node.setPosition(Edge.Bottom, bottom);
2707
2701
  }
2708
- if (typeof left === "number" && this._positionType === "absolute") {
2709
- this._x = left;
2702
+ }
2703
+ if (isPositionType(left)) {
2704
+ if (left === "auto") {
2705
+ node.setPositionAuto(Edge.Left);
2706
+ } else {
2707
+ node.setPosition(Edge.Left, left);
2710
2708
  }
2711
- this.needsUpdate();
2712
- this._yogaPerformancePositionUpdated = false;
2713
2709
  }
2710
+ this.needsUpdate();
2714
2711
  }
2715
2712
  set flexGrow(grow) {
2716
2713
  this.layoutNode.yogaNode.setFlexGrow(grow);
2717
- this.requestLayout();
2714
+ this.needsUpdate();
2718
2715
  }
2719
2716
  set flexShrink(shrink) {
2720
2717
  this.layoutNode.yogaNode.setFlexShrink(shrink);
2721
- this.requestLayout();
2718
+ this.needsUpdate();
2722
2719
  }
2723
2720
  set flexDirection(direction) {
2724
2721
  this.layoutNode.yogaNode.setFlexDirection(parseFlexDirection(direction));
2725
- this.requestLayout();
2722
+ this.needsUpdate();
2726
2723
  }
2727
2724
  set alignItems(alignItems) {
2728
2725
  this.layoutNode.yogaNode.setAlignItems(parseAlign(alignItems));
2729
- this.requestLayout();
2726
+ this.needsUpdate();
2730
2727
  }
2731
2728
  set justifyContent(justifyContent) {
2732
2729
  this.layoutNode.yogaNode.setJustifyContent(parseJustify(justifyContent));
2733
- this.requestLayout();
2730
+ this.needsUpdate();
2734
2731
  }
2735
2732
  set flexBasis(basis) {
2736
2733
  if (isFlexBasisType(basis)) {
2737
2734
  this.layoutNode.yogaNode.setFlexBasis(basis);
2738
- this.requestLayout();
2735
+ this.needsUpdate();
2739
2736
  }
2740
2737
  }
2741
2738
  set minWidth(minWidth) {
2742
2739
  if (isSizeType(minWidth)) {
2743
2740
  this.layoutNode.yogaNode.setMinWidth(minWidth);
2744
- this.requestLayout();
2741
+ this.needsUpdate();
2745
2742
  }
2746
2743
  }
2747
2744
  set maxWidth(maxWidth) {
2748
2745
  if (isSizeType(maxWidth)) {
2749
2746
  this.layoutNode.yogaNode.setMaxWidth(maxWidth);
2750
- this.requestLayout();
2747
+ this.needsUpdate();
2751
2748
  }
2752
2749
  }
2753
2750
  set minHeight(minHeight) {
2754
2751
  if (isSizeType(minHeight)) {
2755
2752
  this.layoutNode.yogaNode.setMinHeight(minHeight);
2756
- this.requestLayout();
2753
+ this.needsUpdate();
2757
2754
  }
2758
2755
  }
2759
2756
  set maxHeight(maxHeight) {
2760
2757
  if (isSizeType(maxHeight)) {
2761
2758
  this.layoutNode.yogaNode.setMaxHeight(maxHeight);
2762
- this.requestLayout();
2759
+ this.needsUpdate();
2763
2760
  }
2764
2761
  }
2765
2762
  set margin(margin) {
@@ -2769,31 +2766,31 @@ class Renderable extends EventEmitter3 {
2769
2766
  node.setMargin(Edge.Right, margin);
2770
2767
  node.setMargin(Edge.Bottom, margin);
2771
2768
  node.setMargin(Edge.Left, margin);
2772
- this.requestLayout();
2769
+ this.needsUpdate();
2773
2770
  }
2774
2771
  }
2775
2772
  set marginTop(margin) {
2776
2773
  if (isMarginType(margin)) {
2777
2774
  this.layoutNode.yogaNode.setMargin(Edge.Top, margin);
2778
- this.requestLayout();
2775
+ this.needsUpdate();
2779
2776
  }
2780
2777
  }
2781
2778
  set marginRight(margin) {
2782
2779
  if (isMarginType(margin)) {
2783
2780
  this.layoutNode.yogaNode.setMargin(Edge.Right, margin);
2784
- this.requestLayout();
2781
+ this.needsUpdate();
2785
2782
  }
2786
2783
  }
2787
2784
  set marginBottom(margin) {
2788
2785
  if (isMarginType(margin)) {
2789
2786
  this.layoutNode.yogaNode.setMargin(Edge.Bottom, margin);
2790
- this.requestLayout();
2787
+ this.needsUpdate();
2791
2788
  }
2792
2789
  }
2793
2790
  set marginLeft(margin) {
2794
2791
  if (isMarginType(margin)) {
2795
2792
  this.layoutNode.yogaNode.setMargin(Edge.Left, margin);
2796
- this.requestLayout();
2793
+ this.needsUpdate();
2797
2794
  }
2798
2795
  }
2799
2796
  set padding(padding) {
@@ -2803,31 +2800,31 @@ class Renderable extends EventEmitter3 {
2803
2800
  node.setPadding(Edge.Right, padding);
2804
2801
  node.setPadding(Edge.Bottom, padding);
2805
2802
  node.setPadding(Edge.Left, padding);
2806
- this.requestLayout();
2803
+ this.needsUpdate();
2807
2804
  }
2808
2805
  }
2809
2806
  set paddingTop(padding) {
2810
2807
  if (isPaddingType(padding)) {
2811
2808
  this.layoutNode.yogaNode.setPadding(Edge.Top, padding);
2812
- this.requestLayout();
2809
+ this.needsUpdate();
2813
2810
  }
2814
2811
  }
2815
2812
  set paddingRight(padding) {
2816
2813
  if (isPaddingType(padding)) {
2817
2814
  this.layoutNode.yogaNode.setPadding(Edge.Right, padding);
2818
- this.requestLayout();
2815
+ this.needsUpdate();
2819
2816
  }
2820
2817
  }
2821
2818
  set paddingBottom(padding) {
2822
2819
  if (isPaddingType(padding)) {
2823
2820
  this.layoutNode.yogaNode.setPadding(Edge.Bottom, padding);
2824
- this.requestLayout();
2821
+ this.needsUpdate();
2825
2822
  }
2826
2823
  }
2827
2824
  set paddingLeft(padding) {
2828
2825
  if (isPaddingType(padding)) {
2829
2826
  this.layoutNode.yogaNode.setPadding(Edge.Left, padding);
2830
- this.requestLayout();
2827
+ this.needsUpdate();
2831
2828
  }
2832
2829
  }
2833
2830
  getLayoutNode() {
@@ -2835,10 +2832,8 @@ class Renderable extends EventEmitter3 {
2835
2832
  }
2836
2833
  updateFromLayout() {
2837
2834
  const layout = this.layoutNode.yogaNode.getComputedLayout();
2838
- if (this._positionType === "relative" || this._yogaPerformancePositionUpdated) {
2839
- this._x = layout.left;
2840
- this._y = layout.top;
2841
- }
2835
+ this._x = layout.left;
2836
+ this._y = layout.top;
2842
2837
  const newWidth = Math.max(layout.width, 1);
2843
2838
  const newHeight = Math.max(layout.height, 1);
2844
2839
  const sizeChanged = this.width !== newWidth || this.height !== newHeight;
@@ -2883,17 +2878,6 @@ class Renderable extends EventEmitter3 {
2883
2878
  }
2884
2879
  }
2885
2880
  onResize(width, height) {}
2886
- requestLayout() {
2887
- if (!this._yogaPerformancePositionUpdated) {
2888
- const layout = this.layoutNode.yogaNode.getComputedLayout();
2889
- if (layout.left !== this._x || layout.top !== this._y) {
2890
- this.layoutNode.yogaNode.setPosition(Edge.Left, this._x);
2891
- this.layoutNode.yogaNode.setPosition(Edge.Top, this._y);
2892
- }
2893
- this._yogaPerformancePositionUpdated = true;
2894
- }
2895
- this.needsUpdate();
2896
- }
2897
2881
  replaceParent(obj) {
2898
2882
  if (obj.parent) {
2899
2883
  obj.parent.remove(obj.id);
@@ -2923,7 +2907,7 @@ class Renderable extends EventEmitter3 {
2923
2907
  if (obj._liveCount > 0) {
2924
2908
  this.propagateLiveCount(obj._liveCount);
2925
2909
  }
2926
- this.requestLayout();
2910
+ this.needsUpdate();
2927
2911
  this.emit("child:added", obj);
2928
2912
  return insertedIndex;
2929
2913
  }
@@ -2961,7 +2945,7 @@ class Renderable extends EventEmitter3 {
2961
2945
  }
2962
2946
  const childLayoutNode = obj.getLayoutNode();
2963
2947
  this.layoutNode.removeChild(childLayoutNode);
2964
- this.requestLayout();
2948
+ this.needsUpdate();
2965
2949
  obj.parent = null;
2966
2950
  obj.propagateContext(null);
2967
2951
  }
@@ -3136,9 +3120,6 @@ class RootRenderable extends Renderable {
3136
3120
  this.layoutNode.yogaNode.setFlexDirection(FlexDirection.Column);
3137
3121
  this.calculateLayout();
3138
3122
  }
3139
- requestLayout() {
3140
- this.needsUpdate();
3141
- }
3142
3123
  propagateLiveCount(delta) {
3143
3124
  const oldCount = this._liveCount;
3144
3125
  this._liveCount += delta;
@@ -6480,7 +6461,10 @@ class FFIRenderLib {
6480
6461
  var opentuiLibPath;
6481
6462
  var opentuiLib;
6482
6463
  function setRenderLibPath(libPath) {
6483
- opentuiLibPath = libPath;
6464
+ if (opentuiLibPath !== libPath) {
6465
+ opentuiLibPath = libPath;
6466
+ opentuiLib = undefined;
6467
+ }
6484
6468
  }
6485
6469
  function resolveRenderLib() {
6486
6470
  if (!opentuiLib) {
@@ -6490,7 +6474,6 @@ function resolveRenderLib() {
6490
6474
  }
6491
6475
 
6492
6476
  // src/buffer.ts
6493
- var fbIdCounter = 0;
6494
6477
  function isRGBAWithAlpha(color) {
6495
6478
  return color.a < 1;
6496
6479
  }
@@ -6542,6 +6525,7 @@ function blendColors(overlay, text) {
6542
6525
  }
6543
6526
 
6544
6527
  class OptimizedBuffer {
6528
+ static fbIdCounter = 0;
6545
6529
  id;
6546
6530
  lib;
6547
6531
  bufferPtr;
@@ -6554,7 +6538,7 @@ class OptimizedBuffer {
6554
6538
  return this.bufferPtr;
6555
6539
  }
6556
6540
  constructor(lib, ptr, buffer, width, height, options) {
6557
- this.id = `fb_${fbIdCounter++}`;
6541
+ this.id = `fb_${OptimizedBuffer.fbIdCounter++}`;
6558
6542
  this.lib = lib;
6559
6543
  this.respectAlpha = options.respectAlpha || false;
6560
6544
  this.width = width;
@@ -7900,6 +7884,7 @@ var ANSI = {
7900
7884
 
7901
7885
  // src/console.ts
7902
7886
  import { EventEmitter as EventEmitter5 } from "events";
7887
+ import { Console } from "console";
7903
7888
  import util from "util";
7904
7889
  import fs from "fs";
7905
7890
  import path from "path";
@@ -7970,21 +7955,24 @@ function getCallerInfo() {
7970
7955
  const columnNumber = parseInt(match[4], 10) || 0;
7971
7956
  return { functionName, fullPath, fileName, lineNumber, columnNumber };
7972
7957
  }
7973
- var capture = new Capture;
7974
- var mockStdout = new CapturedWritableStream("stdout", capture);
7975
- var mockStderr = new CapturedWritableStream("stderr", capture);
7976
- if (process.env.SKIP_CONSOLE_CACHE !== "true") {
7977
- global.console = new console.Console({
7978
- stdout: mockStdout,
7979
- stderr: mockStderr,
7980
- colorMode: true,
7981
- inspectOptions: {
7982
- compact: false,
7983
- breakLength: 80,
7984
- depth: 2
7985
- }
7986
- });
7987
- }
7958
+ var { capture } = singleton("ConsoleCapture", () => {
7959
+ const capture2 = new Capture;
7960
+ const mockStdout = new CapturedWritableStream("stdout", capture2);
7961
+ const mockStderr = new CapturedWritableStream("stderr", capture2);
7962
+ if (process.env.SKIP_CONSOLE_CACHE !== "true") {
7963
+ global.console = new Console({
7964
+ stdout: mockStdout,
7965
+ stderr: mockStderr,
7966
+ colorMode: true,
7967
+ inspectOptions: {
7968
+ compact: false,
7969
+ breakLength: 80,
7970
+ depth: 2
7971
+ }
7972
+ });
7973
+ }
7974
+ return { capture: capture2 };
7975
+ });
7988
7976
 
7989
7977
  class TerminalConsoleCache extends EventEmitter5 {
7990
7978
  originalConsole;
@@ -8066,9 +8054,12 @@ class TerminalConsoleCache extends EventEmitter5 {
8066
8054
  this.deactivate();
8067
8055
  }
8068
8056
  }
8069
- var terminalConsoleCache = new TerminalConsoleCache;
8070
- process.on("exit", () => {
8071
- terminalConsoleCache.destroy();
8057
+ var terminalConsoleCache = singleton("TerminalConsoleCache", () => {
8058
+ const terminalConsoleCache2 = new TerminalConsoleCache;
8059
+ process.on("exit", () => {
8060
+ terminalConsoleCache2.destroy();
8061
+ });
8062
+ return terminalConsoleCache2;
8072
8063
  });
8073
8064
  var ConsolePosition;
8074
8065
  ((ConsolePosition2) => {
@@ -8557,7 +8548,6 @@ class TerminalConsole extends EventEmitter5 {
8557
8548
 
8558
8549
  // src/renderer.ts
8559
8550
  import { EventEmitter as EventEmitter6 } from "events";
8560
-
8561
8551
  class MouseEvent {
8562
8552
  type;
8563
8553
  button;
@@ -8593,9 +8583,11 @@ var MouseButton;
8593
8583
  MouseButton2[MouseButton2["WHEEL_UP"] = 4] = "WHEEL_UP";
8594
8584
  MouseButton2[MouseButton2["WHEEL_DOWN"] = 5] = "WHEEL_DOWN";
8595
8585
  })(MouseButton ||= {});
8596
- ["SIGINT", "SIGTERM", "SIGQUIT", "SIGABRT"].forEach((signal) => {
8597
- process.on(signal, () => {
8598
- process.exit();
8586
+ singleton("ProcessExitSignals", () => {
8587
+ ["SIGINT", "SIGTERM", "SIGQUIT", "SIGABRT"].forEach((signal) => {
8588
+ process.on(signal, () => {
8589
+ process.exit();
8590
+ });
8599
8591
  });
8600
8592
  });
8601
8593
  async function createCliRenderer(config = {}) {
@@ -8625,9 +8617,8 @@ var CliRenderEvents;
8625
8617
  ((CliRenderEvents2) => {
8626
8618
  CliRenderEvents2["DEBUG_OVERLAY_TOGGLE"] = "debugOverlay:toggle";
8627
8619
  })(CliRenderEvents ||= {});
8628
- var animationFrameId = 0;
8629
-
8630
8620
  class CliRenderer extends EventEmitter6 {
8621
+ static animationFrameId = 0;
8631
8622
  lib;
8632
8623
  rendererPtr;
8633
8624
  stdin;
@@ -8815,7 +8806,7 @@ Error details:
8815
8806
  this._console = new TerminalConsole(this, config.consoleOptions);
8816
8807
  this.useConsole = config.useConsole ?? true;
8817
8808
  global.requestAnimationFrame = (callback) => {
8818
- const id = animationFrameId++;
8809
+ const id = CliRenderer.animationFrameId++;
8819
8810
  this.animationRequest.set(id, callback);
8820
8811
  return id;
8821
8812
  };
@@ -9320,6 +9311,7 @@ Error details:
9320
9311
  }
9321
9312
  }
9322
9313
  destroy() {
9314
+ this.stdin.setRawMode(false);
9323
9315
  if (this.isDestroyed)
9324
9316
  return;
9325
9317
  this.isDestroyed = true;
@@ -9330,8 +9322,8 @@ Error details:
9330
9322
  this.sigwinchHandler = null;
9331
9323
  }
9332
9324
  this._console.deactivate();
9333
- this.lib.destroyRenderer(this.rendererPtr, this._useAlternateScreen, this._splitHeight);
9334
9325
  this.disableStdoutInterception();
9326
+ this.lib.destroyRenderer(this.rendererPtr, this._useAlternateScreen, this._splitHeight);
9335
9327
  }
9336
9328
  startRenderLoop() {
9337
9329
  if (!this._isRunning)
@@ -9364,7 +9356,7 @@ Error details:
9364
9356
  this.renderStats.frameCount++;
9365
9357
  this.renderStats.fps = this.currentFps;
9366
9358
  const overallStart = performance.now();
9367
- const frameRequests = this.animationRequest.values();
9359
+ const frameRequests = Array.from(this.animationRequest.values());
9368
9360
  this.animationRequest.clear();
9369
9361
  const animationRequestStart = performance.now();
9370
9362
  frameRequests.forEach((callback) => callback(deltaTime));
@@ -9558,7 +9550,8 @@ class BoxRenderable extends Renderable {
9558
9550
  _borderStyle;
9559
9551
  _borderColor;
9560
9552
  _focusedBorderColor;
9561
- customBorderChars;
9553
+ _customBorderCharsObj;
9554
+ _customBorderChars;
9562
9555
  borderSides;
9563
9556
  shouldFill;
9564
9557
  _title;
@@ -9570,13 +9563,22 @@ class BoxRenderable extends Renderable {
9570
9563
  this._borderStyle = options.borderStyle || "single";
9571
9564
  this._borderColor = parseColor(options.borderColor || "#FFFFFF");
9572
9565
  this._focusedBorderColor = parseColor(options.focusedBorderColor || "#00AAFF");
9573
- this.customBorderChars = options.customBorderChars ? borderCharsToArray(options.customBorderChars) : undefined;
9566
+ this._customBorderCharsObj = options.customBorderChars;
9567
+ this._customBorderChars = this._customBorderCharsObj ? borderCharsToArray(this._customBorderCharsObj) : undefined;
9574
9568
  this.borderSides = getBorderSides(this._border);
9575
9569
  this.shouldFill = options.shouldFill ?? true;
9576
9570
  this._title = options.title;
9577
9571
  this._titleAlignment = options.titleAlignment || "left";
9578
9572
  this.applyYogaBorders();
9579
9573
  }
9574
+ get customBorderChars() {
9575
+ return this._customBorderCharsObj;
9576
+ }
9577
+ set customBorderChars(value) {
9578
+ this._customBorderCharsObj = value;
9579
+ this._customBorderChars = value ? borderCharsToArray(value) : undefined;
9580
+ this.needsUpdate();
9581
+ }
9580
9582
  get backgroundColor() {
9581
9583
  return this._backgroundColor;
9582
9584
  }
@@ -9606,7 +9608,7 @@ class BoxRenderable extends Renderable {
9606
9608
  set borderStyle(value) {
9607
9609
  if (this._borderStyle !== value) {
9608
9610
  this._borderStyle = value;
9609
- this.customBorderChars = undefined;
9611
+ this._customBorderChars = undefined;
9610
9612
  this.needsUpdate();
9611
9613
  }
9612
9614
  }
@@ -9658,7 +9660,7 @@ class BoxRenderable extends Renderable {
9658
9660
  width: this.width,
9659
9661
  height: this.height,
9660
9662
  borderStyle: this._borderStyle,
9661
- customBorderChars: this.customBorderChars,
9663
+ customBorderChars: this._customBorderChars,
9662
9664
  border: this._border,
9663
9665
  borderColor: currentBorderColor,
9664
9666
  backgroundColor: this._backgroundColor,
@@ -9673,7 +9675,7 @@ class BoxRenderable extends Renderable {
9673
9675
  node.setBorder(Edge.Right, this.borderSides.right ? 1 : 0);
9674
9676
  node.setBorder(Edge.Top, this.borderSides.top ? 1 : 0);
9675
9677
  node.setBorder(Edge.Bottom, this.borderSides.bottom ? 1 : 0);
9676
- this.requestLayout();
9678
+ this.needsUpdate();
9677
9679
  }
9678
9680
  }
9679
9681
  // src/renderables/FrameBuffer.ts
@@ -10241,6 +10243,14 @@ class InputRenderable extends Renderable {
10241
10243
  this._cursorColor = parseColor(color);
10242
10244
  this.needsUpdate();
10243
10245
  }
10246
+ updateFromLayout() {
10247
+ super.updateFromLayout();
10248
+ this.updateCursorPosition();
10249
+ }
10250
+ onResize(width, height) {
10251
+ super.onResize(width, height);
10252
+ this.updateCursorPosition();
10253
+ }
10244
10254
  destroySelf() {
10245
10255
  if (this._focused) {
10246
10256
  CliRenderer.setCursorPosition(0, 0, false);
@@ -10554,42 +10564,42 @@ function calculateDynamicHeight(showUnderline, showDescription) {
10554
10564
 
10555
10565
  class TabSelectRenderable extends Renderable {
10556
10566
  focusable = true;
10557
- options = [];
10567
+ _options = [];
10558
10568
  selectedIndex = 0;
10559
10569
  scrollOffset = 0;
10560
- tabWidth;
10570
+ _tabWidth;
10561
10571
  maxVisibleTabs;
10562
- backgroundColor;
10563
- textColor;
10564
- focusedBackgroundColor;
10565
- focusedTextColor;
10566
- selectedBackgroundColor;
10567
- selectedTextColor;
10568
- selectedDescriptionColor;
10569
- showScrollArrows;
10570
- showDescription;
10571
- showUnderline;
10572
- wrapSelection;
10572
+ _backgroundColor;
10573
+ _textColor;
10574
+ _focusedBackgroundColor;
10575
+ _focusedTextColor;
10576
+ _selectedBackgroundColor;
10577
+ _selectedTextColor;
10578
+ _selectedDescriptionColor;
10579
+ _showScrollArrows;
10580
+ _showDescription;
10581
+ _showUnderline;
10582
+ _wrapSelection;
10573
10583
  constructor(id, options) {
10574
10584
  const calculatedHeight = calculateDynamicHeight(options.showUnderline ?? true, options.showDescription ?? true);
10575
10585
  super(id, { ...options, height: calculatedHeight, buffered: true });
10576
- this.backgroundColor = parseColor(options.backgroundColor || "transparent");
10577
- this.textColor = parseColor(options.textColor || "#FFFFFF");
10578
- this.focusedBackgroundColor = parseColor(options.focusedBackgroundColor || options.backgroundColor || "#1a1a1a");
10579
- this.focusedTextColor = parseColor(options.focusedTextColor || options.textColor || "#FFFFFF");
10580
- this.options = options.options || [];
10581
- this.tabWidth = options.tabWidth || 20;
10582
- this.showDescription = options.showDescription ?? true;
10583
- this.showUnderline = options.showUnderline ?? true;
10584
- this.showScrollArrows = options.showScrollArrows ?? true;
10585
- this.wrapSelection = options.wrapSelection ?? false;
10586
- this.maxVisibleTabs = Math.max(1, Math.floor(this.width / this.tabWidth));
10587
- this.selectedBackgroundColor = parseColor(options.selectedBackgroundColor || "#334455");
10588
- this.selectedTextColor = parseColor(options.selectedTextColor || "#FFFF00");
10589
- this.selectedDescriptionColor = parseColor(options.selectedDescriptionColor || "#CCCCCC");
10586
+ this._backgroundColor = parseColor(options.backgroundColor || "transparent");
10587
+ this._textColor = parseColor(options.textColor || "#FFFFFF");
10588
+ this._focusedBackgroundColor = parseColor(options.focusedBackgroundColor || options.backgroundColor || "#1a1a1a");
10589
+ this._focusedTextColor = parseColor(options.focusedTextColor || options.textColor || "#FFFFFF");
10590
+ this._options = options.options || [];
10591
+ this._tabWidth = options.tabWidth || 20;
10592
+ this._showDescription = options.showDescription ?? true;
10593
+ this._showUnderline = options.showUnderline ?? true;
10594
+ this._showScrollArrows = options.showScrollArrows ?? true;
10595
+ this._wrapSelection = options.wrapSelection ?? false;
10596
+ this.maxVisibleTabs = Math.max(1, Math.floor(this.width / this._tabWidth));
10597
+ this._selectedBackgroundColor = parseColor(options.selectedBackgroundColor || "#334455");
10598
+ this._selectedTextColor = parseColor(options.selectedTextColor || "#FFFF00");
10599
+ this._selectedDescriptionColor = parseColor(options.selectedDescriptionColor || "#CCCCCC");
10590
10600
  }
10591
10601
  calculateDynamicHeight() {
10592
- return calculateDynamicHeight(this.showUnderline, this.showDescription);
10602
+ return calculateDynamicHeight(this._showUnderline, this._showDescription);
10593
10603
  }
10594
10604
  renderSelf(buffer, deltaTime) {
10595
10605
  if (!this.visible || !this.frameBuffer)
@@ -10599,46 +10609,46 @@ class TabSelectRenderable extends Renderable {
10599
10609
  }
10600
10610
  }
10601
10611
  refreshFrameBuffer() {
10602
- if (!this.frameBuffer || this.options.length === 0)
10612
+ if (!this.frameBuffer || this._options.length === 0)
10603
10613
  return;
10604
- const bgColor = this._focused ? this.focusedBackgroundColor : this.backgroundColor;
10614
+ const bgColor = this._focused ? this._focusedBackgroundColor : this._backgroundColor;
10605
10615
  this.frameBuffer.clear(bgColor);
10606
10616
  const contentX = 0;
10607
10617
  const contentY = 0;
10608
10618
  const contentWidth = this.width;
10609
10619
  const contentHeight = this.height;
10610
- const visibleOptions = this.options.slice(this.scrollOffset, this.scrollOffset + this.maxVisibleTabs);
10620
+ const visibleOptions = this._options.slice(this.scrollOffset, this.scrollOffset + this.maxVisibleTabs);
10611
10621
  for (let i = 0;i < visibleOptions.length; i++) {
10612
10622
  const actualIndex = this.scrollOffset + i;
10613
10623
  const option = visibleOptions[i];
10614
10624
  const isSelected = actualIndex === this.selectedIndex;
10615
- const tabX = contentX + i * this.tabWidth;
10625
+ const tabX = contentX + i * this._tabWidth;
10616
10626
  if (tabX >= contentX + contentWidth)
10617
10627
  break;
10618
- const actualTabWidth = Math.min(this.tabWidth, contentWidth - i * this.tabWidth);
10628
+ const actualTabWidth = Math.min(this._tabWidth, contentWidth - i * this._tabWidth);
10619
10629
  if (isSelected) {
10620
- this.frameBuffer.fillRect(tabX, contentY, actualTabWidth, 1, this.selectedBackgroundColor);
10630
+ this.frameBuffer.fillRect(tabX, contentY, actualTabWidth, 1, this._selectedBackgroundColor);
10621
10631
  }
10622
- const baseTextColor = this._focused ? this.focusedTextColor : this.textColor;
10623
- const nameColor = isSelected ? this.selectedTextColor : baseTextColor;
10632
+ const baseTextColor = this._focused ? this._focusedTextColor : this._textColor;
10633
+ const nameColor = isSelected ? this._selectedTextColor : baseTextColor;
10624
10634
  const nameContent = this.truncateText(option.name, actualTabWidth - 2);
10625
10635
  this.frameBuffer.drawText(nameContent, tabX + 1, contentY, nameColor);
10626
- if (isSelected && this.showUnderline && contentHeight >= 2) {
10636
+ if (isSelected && this._showUnderline && contentHeight >= 2) {
10627
10637
  const underlineY = contentY + 1;
10628
- const underlineBg = isSelected ? this.selectedBackgroundColor : bgColor;
10638
+ const underlineBg = isSelected ? this._selectedBackgroundColor : bgColor;
10629
10639
  this.frameBuffer.drawText("\u25AC".repeat(actualTabWidth), tabX, underlineY, nameColor, underlineBg);
10630
10640
  }
10631
10641
  }
10632
- if (this.showDescription && contentHeight >= (this.showUnderline ? 3 : 2)) {
10642
+ if (this._showDescription && contentHeight >= (this._showUnderline ? 3 : 2)) {
10633
10643
  const selectedOption = this.getSelectedOption();
10634
10644
  if (selectedOption) {
10635
- const descriptionY = contentY + (this.showUnderline ? 2 : 1);
10636
- const descColor = this.selectedDescriptionColor;
10645
+ const descriptionY = contentY + (this._showUnderline ? 2 : 1);
10646
+ const descColor = this._selectedDescriptionColor;
10637
10647
  const descContent = this.truncateText(selectedOption.description, contentWidth - 2);
10638
10648
  this.frameBuffer.drawText(descContent, contentX + 1, descriptionY, descColor);
10639
10649
  }
10640
10650
  }
10641
- if (this.showScrollArrows && this.options.length > this.maxVisibleTabs) {
10651
+ if (this._showScrollArrows && this._options.length > this.maxVisibleTabs) {
10642
10652
  this.renderScrollArrowsToFrameBuffer(contentX, contentY, contentWidth, contentHeight);
10643
10653
  }
10644
10654
  }
@@ -10651,7 +10661,7 @@ class TabSelectRenderable extends Renderable {
10651
10661
  if (!this.frameBuffer)
10652
10662
  return;
10653
10663
  const hasMoreLeft = this.scrollOffset > 0;
10654
- const hasMoreRight = this.scrollOffset + this.maxVisibleTabs < this.options.length;
10664
+ const hasMoreRight = this.scrollOffset + this.maxVisibleTabs < this._options.length;
10655
10665
  if (hasMoreLeft) {
10656
10666
  this.frameBuffer.drawText("\u2039", contentX, contentY, parseColor("#AAAAAA"));
10657
10667
  }
@@ -10660,13 +10670,13 @@ class TabSelectRenderable extends Renderable {
10660
10670
  }
10661
10671
  }
10662
10672
  setOptions(options) {
10663
- this.options = options;
10673
+ this._options = options;
10664
10674
  this.selectedIndex = Math.min(this.selectedIndex, Math.max(0, options.length - 1));
10665
10675
  this.updateScrollOffset();
10666
10676
  this.needsUpdate();
10667
10677
  }
10668
10678
  getSelectedOption() {
10669
- return this.options[this.selectedIndex] || null;
10679
+ return this._options[this.selectedIndex] || null;
10670
10680
  }
10671
10681
  getSelectedIndex() {
10672
10682
  return this.selectedIndex;
@@ -10674,8 +10684,8 @@ class TabSelectRenderable extends Renderable {
10674
10684
  moveLeft() {
10675
10685
  if (this.selectedIndex > 0) {
10676
10686
  this.selectedIndex--;
10677
- } else if (this.wrapSelection && this.options.length > 0) {
10678
- this.selectedIndex = this.options.length - 1;
10687
+ } else if (this._wrapSelection && this._options.length > 0) {
10688
+ this.selectedIndex = this._options.length - 1;
10679
10689
  } else {
10680
10690
  return;
10681
10691
  }
@@ -10684,9 +10694,9 @@ class TabSelectRenderable extends Renderable {
10684
10694
  this.emit("selectionChanged" /* SELECTION_CHANGED */, this.selectedIndex, this.getSelectedOption());
10685
10695
  }
10686
10696
  moveRight() {
10687
- if (this.selectedIndex < this.options.length - 1) {
10697
+ if (this.selectedIndex < this._options.length - 1) {
10688
10698
  this.selectedIndex++;
10689
- } else if (this.wrapSelection && this.options.length > 0) {
10699
+ } else if (this._wrapSelection && this._options.length > 0) {
10690
10700
  this.selectedIndex = 0;
10691
10701
  } else {
10692
10702
  return;
@@ -10702,7 +10712,7 @@ class TabSelectRenderable extends Renderable {
10702
10712
  }
10703
10713
  }
10704
10714
  setSelectedIndex(index) {
10705
- if (index >= 0 && index < this.options.length) {
10715
+ if (index >= 0 && index < this._options.length) {
10706
10716
  this.selectedIndex = index;
10707
10717
  this.updateScrollOffset();
10708
10718
  this.needsUpdate();
@@ -10711,27 +10721,27 @@ class TabSelectRenderable extends Renderable {
10711
10721
  }
10712
10722
  updateScrollOffset() {
10713
10723
  const halfVisible = Math.floor(this.maxVisibleTabs / 2);
10714
- const newScrollOffset = Math.max(0, Math.min(this.selectedIndex - halfVisible, this.options.length - this.maxVisibleTabs));
10724
+ const newScrollOffset = Math.max(0, Math.min(this.selectedIndex - halfVisible, this._options.length - this.maxVisibleTabs));
10715
10725
  if (newScrollOffset !== this.scrollOffset) {
10716
10726
  this.scrollOffset = newScrollOffset;
10717
10727
  this.needsUpdate();
10718
10728
  }
10719
10729
  }
10720
10730
  onResize(width, height) {
10721
- this.maxVisibleTabs = Math.max(1, Math.floor(width / this.tabWidth));
10731
+ this.maxVisibleTabs = Math.max(1, Math.floor(width / this._tabWidth));
10722
10732
  this.updateScrollOffset();
10723
10733
  this.needsUpdate();
10724
10734
  }
10725
10735
  setTabWidth(tabWidth) {
10726
- if (this.tabWidth === tabWidth)
10736
+ if (this._tabWidth === tabWidth)
10727
10737
  return;
10728
- this.tabWidth = tabWidth;
10729
- this.maxVisibleTabs = Math.max(1, Math.floor(this.width / this.tabWidth));
10738
+ this._tabWidth = tabWidth;
10739
+ this.maxVisibleTabs = Math.max(1, Math.floor(this.width / this._tabWidth));
10730
10740
  this.updateScrollOffset();
10731
10741
  this.needsUpdate();
10732
10742
  }
10733
10743
  getTabWidth() {
10734
- return this.tabWidth;
10744
+ return this._tabWidth;
10735
10745
  }
10736
10746
  handleKeyPress(key) {
10737
10747
  const keyName2 = typeof key === "string" ? key : key.name;
@@ -10751,40 +10761,90 @@ class TabSelectRenderable extends Renderable {
10751
10761
  }
10752
10762
  return false;
10753
10763
  }
10754
- setShowDescription(show) {
10755
- if (this.showDescription !== show) {
10756
- this.showDescription = show;
10764
+ get options() {
10765
+ return this._options;
10766
+ }
10767
+ set options(options) {
10768
+ this._options = options;
10769
+ this.selectedIndex = Math.min(this.selectedIndex, Math.max(0, options.length - 1));
10770
+ this.updateScrollOffset();
10771
+ this.needsUpdate();
10772
+ }
10773
+ set backgroundColor(color) {
10774
+ this._backgroundColor = parseColor(color);
10775
+ this.needsUpdate();
10776
+ }
10777
+ set textColor(color) {
10778
+ this._textColor = parseColor(color);
10779
+ this.needsUpdate();
10780
+ }
10781
+ set focusedBackgroundColor(color) {
10782
+ this._focusedBackgroundColor = parseColor(color);
10783
+ this.needsUpdate();
10784
+ }
10785
+ set focusedTextColor(color) {
10786
+ this._focusedTextColor = parseColor(color);
10787
+ this.needsUpdate();
10788
+ }
10789
+ set selectedBackgroundColor(color) {
10790
+ this._selectedBackgroundColor = parseColor(color);
10791
+ this.needsUpdate();
10792
+ }
10793
+ set selectedTextColor(color) {
10794
+ this._selectedTextColor = parseColor(color);
10795
+ this.needsUpdate();
10796
+ }
10797
+ set selectedDescriptionColor(color) {
10798
+ this._selectedDescriptionColor = parseColor(color);
10799
+ this.needsUpdate();
10800
+ }
10801
+ get showDescription() {
10802
+ return this._showDescription;
10803
+ }
10804
+ set showDescription(show) {
10805
+ if (this._showDescription !== show) {
10806
+ this._showDescription = show;
10757
10807
  const newHeight = this.calculateDynamicHeight();
10758
10808
  this.height = newHeight;
10809
+ this.needsUpdate();
10759
10810
  }
10760
10811
  }
10761
- getShowDescription() {
10762
- return this.showDescription;
10812
+ get showUnderline() {
10813
+ return this._showUnderline;
10763
10814
  }
10764
- setShowUnderline(show) {
10765
- if (this.showUnderline !== show) {
10766
- this.showUnderline = show;
10815
+ set showUnderline(show) {
10816
+ if (this._showUnderline !== show) {
10817
+ this._showUnderline = show;
10767
10818
  const newHeight = this.calculateDynamicHeight();
10768
10819
  this.height = newHeight;
10820
+ this.needsUpdate();
10769
10821
  }
10770
10822
  }
10771
- getShowUnderline() {
10772
- return this.showUnderline;
10823
+ get showScrollArrows() {
10824
+ return this._showScrollArrows;
10773
10825
  }
10774
- setShowScrollArrows(show) {
10775
- if (this.showScrollArrows !== show) {
10776
- this.showScrollArrows = show;
10826
+ set showScrollArrows(show) {
10827
+ if (this._showScrollArrows !== show) {
10828
+ this._showScrollArrows = show;
10777
10829
  this.needsUpdate();
10778
10830
  }
10779
10831
  }
10780
- getShowScrollArrows() {
10781
- return this.showScrollArrows;
10832
+ get wrapSelection() {
10833
+ return this._wrapSelection;
10834
+ }
10835
+ set wrapSelection(wrap) {
10836
+ this._wrapSelection = wrap;
10782
10837
  }
10783
- setWrapSelection(wrap) {
10784
- this.wrapSelection = wrap;
10838
+ get tabWidth() {
10839
+ return this._tabWidth;
10785
10840
  }
10786
- getWrapSelection() {
10787
- return this.wrapSelection;
10841
+ set tabWidth(tabWidth) {
10842
+ if (this._tabWidth === tabWidth)
10843
+ return;
10844
+ this._tabWidth = tabWidth;
10845
+ this.maxVisibleTabs = Math.max(1, Math.floor(this.width / this._tabWidth));
10846
+ this.updateScrollOffset();
10847
+ this.needsUpdate();
10788
10848
  }
10789
10849
  }
10790
10850
  export {
@@ -10921,5 +10981,5 @@ export {
10921
10981
  ASCIIFontRenderable
10922
10982
  };
10923
10983
  export { __toESM, __commonJS, __export, __require };
10924
- //# debugId=D2D08A0277CDE28864756E2164756E21
10984
+ //# debugId=173A228A48201A5364756E2164756E21
10925
10985
  //# sourceMappingURL=index.js.map