@opentui/core 0.1.8 → 0.1.10

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,35 +9550,52 @@ 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;
9565
9558
  _titleAlignment;
9559
+ _defaultOptions = {
9560
+ backgroundColor: "transparent",
9561
+ borderStyle: "single",
9562
+ border: false,
9563
+ borderColor: "#FFFFFF",
9564
+ shouldFill: true,
9565
+ titleAlignment: "left",
9566
+ focusedBorderColor: "#00AAFF"
9567
+ };
9566
9568
  constructor(id, options) {
9567
9569
  super(id, options);
9568
- this._backgroundColor = parseColor(options.backgroundColor || "transparent");
9569
- this._border = options.border ?? true;
9570
- this._borderStyle = options.borderStyle || "single";
9571
- this._borderColor = parseColor(options.borderColor || "#FFFFFF");
9572
- this._focusedBorderColor = parseColor(options.focusedBorderColor || "#00AAFF");
9573
- this.customBorderChars = options.customBorderChars ? borderCharsToArray(options.customBorderChars) : undefined;
9570
+ this._backgroundColor = parseColor(options.backgroundColor || this._defaultOptions.backgroundColor);
9571
+ this._border = options.border ?? this._defaultOptions.border;
9572
+ this._borderStyle = options.borderStyle || this._defaultOptions.borderStyle;
9573
+ this._borderColor = parseColor(options.borderColor || this._defaultOptions.borderColor);
9574
+ this._focusedBorderColor = parseColor(options.focusedBorderColor || this._defaultOptions.focusedBorderColor);
9575
+ this._customBorderCharsObj = options.customBorderChars;
9576
+ this._customBorderChars = this._customBorderCharsObj ? borderCharsToArray(this._customBorderCharsObj) : undefined;
9574
9577
  this.borderSides = getBorderSides(this._border);
9575
- this.shouldFill = options.shouldFill ?? true;
9578
+ this.shouldFill = options.shouldFill ?? this._defaultOptions.shouldFill;
9576
9579
  this._title = options.title;
9577
- this._titleAlignment = options.titleAlignment || "left";
9580
+ this._titleAlignment = options.titleAlignment || this._defaultOptions.titleAlignment;
9578
9581
  this.applyYogaBorders();
9579
9582
  }
9583
+ get customBorderChars() {
9584
+ return this._customBorderCharsObj;
9585
+ }
9586
+ set customBorderChars(value) {
9587
+ this._customBorderCharsObj = value;
9588
+ this._customBorderChars = value ? borderCharsToArray(value) : undefined;
9589
+ this.needsUpdate();
9590
+ }
9580
9591
  get backgroundColor() {
9581
9592
  return this._backgroundColor;
9582
9593
  }
9583
9594
  set backgroundColor(value) {
9584
- if (value) {
9585
- const newColor = parseColor(value);
9586
- if (this._backgroundColor !== newColor) {
9587
- this._backgroundColor = newColor;
9588
- this.needsUpdate();
9589
- }
9595
+ const newColor = parseColor(value ?? this._defaultOptions.backgroundColor);
9596
+ if (this._backgroundColor !== newColor) {
9597
+ this._backgroundColor = newColor;
9598
+ this.needsUpdate();
9590
9599
  }
9591
9600
  }
9592
9601
  get border() {
@@ -9604,9 +9613,10 @@ class BoxRenderable extends Renderable {
9604
9613
  return this._borderStyle;
9605
9614
  }
9606
9615
  set borderStyle(value) {
9607
- if (this._borderStyle !== value) {
9608
- this._borderStyle = value;
9609
- this.customBorderChars = undefined;
9616
+ let _value = value ?? this._defaultOptions.borderStyle;
9617
+ if (this._borderStyle !== _value) {
9618
+ this._borderStyle = _value;
9619
+ this._customBorderChars = undefined;
9610
9620
  this.needsUpdate();
9611
9621
  }
9612
9622
  }
@@ -9614,7 +9624,7 @@ class BoxRenderable extends Renderable {
9614
9624
  return this._borderColor;
9615
9625
  }
9616
9626
  set borderColor(value) {
9617
- const newColor = parseColor(value);
9627
+ const newColor = parseColor(value ?? this._defaultOptions.borderColor);
9618
9628
  if (this._borderColor !== newColor) {
9619
9629
  this._borderColor = newColor;
9620
9630
  this.needsUpdate();
@@ -9624,7 +9634,7 @@ class BoxRenderable extends Renderable {
9624
9634
  return this._focusedBorderColor;
9625
9635
  }
9626
9636
  set focusedBorderColor(value) {
9627
- const newColor = parseColor(value);
9637
+ const newColor = parseColor(value ?? this._defaultOptions.focusedBorderColor);
9628
9638
  if (this._focusedBorderColor !== newColor) {
9629
9639
  this._focusedBorderColor = newColor;
9630
9640
  if (this._focused) {
@@ -9658,7 +9668,7 @@ class BoxRenderable extends Renderable {
9658
9668
  width: this.width,
9659
9669
  height: this.height,
9660
9670
  borderStyle: this._borderStyle,
9661
- customBorderChars: this.customBorderChars,
9671
+ customBorderChars: this._customBorderChars,
9662
9672
  border: this._border,
9663
9673
  borderColor: currentBorderColor,
9664
9674
  backgroundColor: this._backgroundColor,
@@ -9673,7 +9683,7 @@ class BoxRenderable extends Renderable {
9673
9683
  node.setBorder(Edge.Right, this.borderSides.right ? 1 : 0);
9674
9684
  node.setBorder(Edge.Top, this.borderSides.top ? 1 : 0);
9675
9685
  node.setBorder(Edge.Bottom, this.borderSides.bottom ? 1 : 0);
9676
- this.requestLayout();
9686
+ this.needsUpdate();
9677
9687
  }
9678
9688
  }
9679
9689
  // src/renderables/FrameBuffer.ts
@@ -10035,19 +10045,30 @@ class InputRenderable extends Renderable {
10035
10045
  _cursorColor;
10036
10046
  _maxLength;
10037
10047
  _lastCommittedValue = "";
10048
+ _defaultOptions = {
10049
+ backgroundColor: "transparent",
10050
+ textColor: "#FFFFFF",
10051
+ focusedBackgroundColor: "#1a1a1a",
10052
+ focusedTextColor: "#FFFFFF",
10053
+ placeholder: "",
10054
+ placeholderColor: "#666666",
10055
+ cursorColor: "#FFFFFF",
10056
+ maxLength: 1000,
10057
+ value: ""
10058
+ };
10038
10059
  constructor(id, options) {
10039
10060
  super(id, { ...options, buffered: true });
10040
- this._backgroundColor = parseColor(options.backgroundColor || "transparent");
10041
- this._textColor = parseColor(options.textColor || "#FFFFFF");
10042
- this._focusedBackgroundColor = parseColor(options.focusedBackgroundColor || options.backgroundColor || "#1a1a1a");
10043
- this._focusedTextColor = parseColor(options.focusedTextColor || options.textColor || "#FFFFFF");
10044
- this._placeholder = options.placeholder || "";
10045
- this._value = options.value || "";
10061
+ this._backgroundColor = parseColor(options.backgroundColor || this._defaultOptions.backgroundColor);
10062
+ this._textColor = parseColor(options.textColor || this._defaultOptions.textColor);
10063
+ this._focusedBackgroundColor = parseColor(options.focusedBackgroundColor || options.backgroundColor || this._defaultOptions.focusedBackgroundColor);
10064
+ this._focusedTextColor = parseColor(options.focusedTextColor || options.textColor || this._defaultOptions.focusedTextColor);
10065
+ this._placeholder = options.placeholder || this._defaultOptions.placeholder;
10066
+ this._value = options.value || this._defaultOptions.value;
10046
10067
  this._lastCommittedValue = this._value;
10047
10068
  this._cursorPosition = this._value.length;
10048
- this._maxLength = options.maxLength || 1000;
10049
- this._placeholderColor = parseColor(options.placeholderColor || "#666666");
10050
- this._cursorColor = parseColor(options.cursorColor || "#FFFFFF");
10069
+ this._maxLength = options.maxLength || this._defaultOptions.maxLength;
10070
+ this._placeholderColor = parseColor(options.placeholderColor || this._defaultOptions.placeholderColor);
10071
+ this._cursorColor = parseColor(options.cursorColor || this._defaultOptions.cursorColor);
10051
10072
  }
10052
10073
  updateCursorPosition() {
10053
10074
  if (!this._focused)
@@ -10217,29 +10238,55 @@ class InputRenderable extends Renderable {
10217
10238
  this.needsUpdate();
10218
10239
  }
10219
10240
  }
10220
- set backgroundColor(color) {
10221
- this._backgroundColor = parseColor(color);
10222
- this.needsUpdate();
10241
+ set backgroundColor(value) {
10242
+ const newColor = parseColor(value ?? this._defaultOptions.backgroundColor);
10243
+ if (this._backgroundColor !== newColor) {
10244
+ this._backgroundColor = newColor;
10245
+ this.needsUpdate();
10246
+ }
10223
10247
  }
10224
- set textColor(color) {
10225
- this._textColor = parseColor(color);
10226
- this.needsUpdate();
10248
+ set textColor(value) {
10249
+ const newColor = parseColor(value ?? this._defaultOptions.textColor);
10250
+ if (this._textColor !== newColor) {
10251
+ this._textColor = newColor;
10252
+ this.needsUpdate();
10253
+ }
10227
10254
  }
10228
- set focusedBackgroundColor(color) {
10229
- this._focusedBackgroundColor = parseColor(color);
10230
- this.needsUpdate();
10255
+ set focusedBackgroundColor(value) {
10256
+ const newColor = parseColor(value ?? this._defaultOptions.focusedBackgroundColor);
10257
+ if (this._focusedBackgroundColor !== newColor) {
10258
+ this._focusedBackgroundColor = newColor;
10259
+ this.needsUpdate();
10260
+ }
10231
10261
  }
10232
- set focusedTextColor(color) {
10233
- this._focusedTextColor = parseColor(color);
10234
- this.needsUpdate();
10262
+ set focusedTextColor(value) {
10263
+ const newColor = parseColor(value ?? this._defaultOptions.focusedTextColor);
10264
+ if (this._focusedTextColor !== newColor) {
10265
+ this._focusedTextColor = newColor;
10266
+ this.needsUpdate();
10267
+ }
10235
10268
  }
10236
- set placeholderColor(color) {
10237
- this._placeholderColor = parseColor(color);
10238
- this.needsUpdate();
10269
+ set placeholderColor(value) {
10270
+ const newColor = parseColor(value ?? this._defaultOptions.placeholderColor);
10271
+ if (this._placeholderColor !== newColor) {
10272
+ this._placeholderColor = newColor;
10273
+ this.needsUpdate();
10274
+ }
10239
10275
  }
10240
- set cursorColor(color) {
10241
- this._cursorColor = parseColor(color);
10242
- this.needsUpdate();
10276
+ set cursorColor(value) {
10277
+ const newColor = parseColor(value ?? this._defaultOptions.cursorColor);
10278
+ if (this._cursorColor !== newColor) {
10279
+ this._cursorColor = newColor;
10280
+ this.needsUpdate();
10281
+ }
10282
+ }
10283
+ updateFromLayout() {
10284
+ super.updateFromLayout();
10285
+ this.updateCursorPosition();
10286
+ }
10287
+ onResize(width, height) {
10288
+ super.onResize(width, height);
10289
+ this.updateCursorPosition();
10243
10290
  }
10244
10291
  destroySelf() {
10245
10292
  if (this._focused) {
@@ -10277,27 +10324,42 @@ class SelectRenderable extends Renderable {
10277
10324
  linesPerItem;
10278
10325
  fontHeight;
10279
10326
  _fastScrollStep;
10327
+ _defaultOptions = {
10328
+ backgroundColor: "transparent",
10329
+ textColor: "#FFFFFF",
10330
+ focusedBackgroundColor: "#1a1a1a",
10331
+ focusedTextColor: "#FFFFFF",
10332
+ selectedBackgroundColor: "#334455",
10333
+ selectedTextColor: "#FFFF00",
10334
+ descriptionColor: "#888888",
10335
+ selectedDescriptionColor: "#CCCCCC",
10336
+ showScrollIndicator: false,
10337
+ wrapSelection: false,
10338
+ showDescription: true,
10339
+ itemSpacing: 0,
10340
+ fastScrollStep: 5
10341
+ };
10280
10342
  constructor(id, options) {
10281
10343
  super(id, { ...options, buffered: true });
10282
- this._backgroundColor = parseColor(options.backgroundColor || "transparent");
10283
- this._textColor = parseColor(options.textColor || "#FFFFFF");
10284
- this._focusedBackgroundColor = parseColor(options.focusedBackgroundColor || options.backgroundColor || "#1a1a1a");
10285
- this._focusedTextColor = parseColor(options.focusedTextColor || options.textColor || "#FFFFFF");
10344
+ this._backgroundColor = parseColor(options.backgroundColor || this._defaultOptions.backgroundColor);
10345
+ this._textColor = parseColor(options.textColor || this._defaultOptions.textColor);
10346
+ this._focusedBackgroundColor = parseColor(options.focusedBackgroundColor || this._defaultOptions.focusedBackgroundColor);
10347
+ this._focusedTextColor = parseColor(options.focusedTextColor || this._defaultOptions.focusedTextColor);
10286
10348
  this._options = options.options || [];
10287
- this._showScrollIndicator = options.showScrollIndicator ?? false;
10288
- this._wrapSelection = options.wrapSelection ?? false;
10289
- this._showDescription = options.showDescription ?? true;
10349
+ this._showScrollIndicator = options.showScrollIndicator ?? this._defaultOptions.showScrollIndicator;
10350
+ this._wrapSelection = options.wrapSelection ?? this._defaultOptions.wrapSelection;
10351
+ this._showDescription = options.showDescription ?? this._defaultOptions.showDescription;
10290
10352
  this._font = options.font;
10291
- this._itemSpacing = options.itemSpacing || 0;
10353
+ this._itemSpacing = options.itemSpacing || this._defaultOptions.itemSpacing;
10292
10354
  this.fontHeight = this._font ? measureText({ text: "A", font: this._font }).height : 1;
10293
10355
  this.linesPerItem = this._showDescription ? this._font ? this.fontHeight + 1 : 2 : this._font ? this.fontHeight : 1;
10294
10356
  this.linesPerItem += this._itemSpacing;
10295
10357
  this.maxVisibleItems = Math.max(1, Math.floor(this.height / this.linesPerItem));
10296
- this._selectedBackgroundColor = parseColor(options.selectedBackgroundColor || "#334455");
10297
- this._selectedTextColor = parseColor(options.selectedTextColor || "#FFFF00");
10298
- this._descriptionColor = parseColor(options.descriptionColor || "#888888");
10299
- this._selectedDescriptionColor = parseColor(options.selectedDescriptionColor || "#CCCCCC");
10300
- this._fastScrollStep = options.fastScrollStep || 5;
10358
+ this._selectedBackgroundColor = parseColor(options.selectedBackgroundColor || this._defaultOptions.selectedBackgroundColor);
10359
+ this._selectedTextColor = parseColor(options.selectedTextColor || this._defaultOptions.selectedTextColor);
10360
+ this._descriptionColor = parseColor(options.descriptionColor || this._defaultOptions.descriptionColor);
10361
+ this._selectedDescriptionColor = parseColor(options.selectedDescriptionColor || this._defaultOptions.selectedDescriptionColor);
10362
+ this._fastScrollStep = options.fastScrollStep || this._defaultOptions.fastScrollStep;
10301
10363
  this.needsUpdate();
10302
10364
  }
10303
10365
  renderSelf(buffer, deltaTime) {
@@ -10482,37 +10544,61 @@ class SelectRenderable extends Renderable {
10482
10544
  set wrapSelection(wrap) {
10483
10545
  this._wrapSelection = wrap;
10484
10546
  }
10485
- set backgroundColor(color) {
10486
- this._backgroundColor = parseColor(color);
10487
- this.needsUpdate();
10547
+ set backgroundColor(value) {
10548
+ const newColor = parseColor(value ?? this._defaultOptions.backgroundColor);
10549
+ if (this._backgroundColor !== newColor) {
10550
+ this._backgroundColor = newColor;
10551
+ this.needsUpdate();
10552
+ }
10488
10553
  }
10489
- set textColor(color) {
10490
- this._textColor = parseColor(color);
10491
- this.needsUpdate();
10554
+ set textColor(value) {
10555
+ const newColor = parseColor(value ?? this._defaultOptions.textColor);
10556
+ if (this._textColor !== newColor) {
10557
+ this._textColor = newColor;
10558
+ this.needsUpdate();
10559
+ }
10492
10560
  }
10493
- set focusedBackgroundColor(color) {
10494
- this._focusedBackgroundColor = parseColor(color);
10495
- this.needsUpdate();
10561
+ set focusedBackgroundColor(value) {
10562
+ const newColor = parseColor(value ?? this._defaultOptions.focusedBackgroundColor);
10563
+ if (this._focusedBackgroundColor !== newColor) {
10564
+ this._focusedBackgroundColor = newColor;
10565
+ this.needsUpdate();
10566
+ }
10496
10567
  }
10497
- set focusedTextColor(color) {
10498
- this._focusedTextColor = parseColor(color);
10499
- this.needsUpdate();
10568
+ set focusedTextColor(value) {
10569
+ const newColor = parseColor(value ?? this._defaultOptions.focusedTextColor);
10570
+ if (this._focusedTextColor !== newColor) {
10571
+ this._focusedTextColor = newColor;
10572
+ this.needsUpdate();
10573
+ }
10500
10574
  }
10501
- set selectedBackgroundColor(color) {
10502
- this._selectedBackgroundColor = parseColor(color);
10503
- this.needsUpdate();
10575
+ set selectedBackgroundColor(value) {
10576
+ const newColor = parseColor(value ?? this._defaultOptions.selectedBackgroundColor);
10577
+ if (this._selectedBackgroundColor !== newColor) {
10578
+ this._selectedBackgroundColor = newColor;
10579
+ this.needsUpdate();
10580
+ }
10504
10581
  }
10505
- set selectedTextColor(color) {
10506
- this._selectedTextColor = parseColor(color);
10507
- this.needsUpdate();
10582
+ set selectedTextColor(value) {
10583
+ const newColor = parseColor(value ?? this._defaultOptions.selectedTextColor);
10584
+ if (this._selectedTextColor !== newColor) {
10585
+ this._selectedTextColor = newColor;
10586
+ this.needsUpdate();
10587
+ }
10508
10588
  }
10509
- set descriptionColor(color) {
10510
- this._descriptionColor = parseColor(color);
10511
- this.needsUpdate();
10589
+ set descriptionColor(value) {
10590
+ const newColor = parseColor(value ?? this._defaultOptions.descriptionColor);
10591
+ if (this._descriptionColor !== newColor) {
10592
+ this._descriptionColor = newColor;
10593
+ this.needsUpdate();
10594
+ }
10512
10595
  }
10513
- set selectedDescriptionColor(color) {
10514
- this._selectedDescriptionColor = parseColor(color);
10515
- this.needsUpdate();
10596
+ set selectedDescriptionColor(value) {
10597
+ const newColor = parseColor(value ?? this._defaultOptions.selectedDescriptionColor);
10598
+ if (this._selectedDescriptionColor !== newColor) {
10599
+ this._selectedDescriptionColor = newColor;
10600
+ this.needsUpdate();
10601
+ }
10516
10602
  }
10517
10603
  set font(font) {
10518
10604
  this._font = font;
@@ -10554,42 +10640,42 @@ function calculateDynamicHeight(showUnderline, showDescription) {
10554
10640
 
10555
10641
  class TabSelectRenderable extends Renderable {
10556
10642
  focusable = true;
10557
- options = [];
10643
+ _options = [];
10558
10644
  selectedIndex = 0;
10559
10645
  scrollOffset = 0;
10560
- tabWidth;
10646
+ _tabWidth;
10561
10647
  maxVisibleTabs;
10562
- backgroundColor;
10563
- textColor;
10564
- focusedBackgroundColor;
10565
- focusedTextColor;
10566
- selectedBackgroundColor;
10567
- selectedTextColor;
10568
- selectedDescriptionColor;
10569
- showScrollArrows;
10570
- showDescription;
10571
- showUnderline;
10572
- wrapSelection;
10648
+ _backgroundColor;
10649
+ _textColor;
10650
+ _focusedBackgroundColor;
10651
+ _focusedTextColor;
10652
+ _selectedBackgroundColor;
10653
+ _selectedTextColor;
10654
+ _selectedDescriptionColor;
10655
+ _showScrollArrows;
10656
+ _showDescription;
10657
+ _showUnderline;
10658
+ _wrapSelection;
10573
10659
  constructor(id, options) {
10574
10660
  const calculatedHeight = calculateDynamicHeight(options.showUnderline ?? true, options.showDescription ?? true);
10575
10661
  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");
10662
+ this._backgroundColor = parseColor(options.backgroundColor || "transparent");
10663
+ this._textColor = parseColor(options.textColor || "#FFFFFF");
10664
+ this._focusedBackgroundColor = parseColor(options.focusedBackgroundColor || options.backgroundColor || "#1a1a1a");
10665
+ this._focusedTextColor = parseColor(options.focusedTextColor || options.textColor || "#FFFFFF");
10666
+ this._options = options.options || [];
10667
+ this._tabWidth = options.tabWidth || 20;
10668
+ this._showDescription = options.showDescription ?? true;
10669
+ this._showUnderline = options.showUnderline ?? true;
10670
+ this._showScrollArrows = options.showScrollArrows ?? true;
10671
+ this._wrapSelection = options.wrapSelection ?? false;
10672
+ this.maxVisibleTabs = Math.max(1, Math.floor(this.width / this._tabWidth));
10673
+ this._selectedBackgroundColor = parseColor(options.selectedBackgroundColor || "#334455");
10674
+ this._selectedTextColor = parseColor(options.selectedTextColor || "#FFFF00");
10675
+ this._selectedDescriptionColor = parseColor(options.selectedDescriptionColor || "#CCCCCC");
10590
10676
  }
10591
10677
  calculateDynamicHeight() {
10592
- return calculateDynamicHeight(this.showUnderline, this.showDescription);
10678
+ return calculateDynamicHeight(this._showUnderline, this._showDescription);
10593
10679
  }
10594
10680
  renderSelf(buffer, deltaTime) {
10595
10681
  if (!this.visible || !this.frameBuffer)
@@ -10599,46 +10685,46 @@ class TabSelectRenderable extends Renderable {
10599
10685
  }
10600
10686
  }
10601
10687
  refreshFrameBuffer() {
10602
- if (!this.frameBuffer || this.options.length === 0)
10688
+ if (!this.frameBuffer || this._options.length === 0)
10603
10689
  return;
10604
- const bgColor = this._focused ? this.focusedBackgroundColor : this.backgroundColor;
10690
+ const bgColor = this._focused ? this._focusedBackgroundColor : this._backgroundColor;
10605
10691
  this.frameBuffer.clear(bgColor);
10606
10692
  const contentX = 0;
10607
10693
  const contentY = 0;
10608
10694
  const contentWidth = this.width;
10609
10695
  const contentHeight = this.height;
10610
- const visibleOptions = this.options.slice(this.scrollOffset, this.scrollOffset + this.maxVisibleTabs);
10696
+ const visibleOptions = this._options.slice(this.scrollOffset, this.scrollOffset + this.maxVisibleTabs);
10611
10697
  for (let i = 0;i < visibleOptions.length; i++) {
10612
10698
  const actualIndex = this.scrollOffset + i;
10613
10699
  const option = visibleOptions[i];
10614
10700
  const isSelected = actualIndex === this.selectedIndex;
10615
- const tabX = contentX + i * this.tabWidth;
10701
+ const tabX = contentX + i * this._tabWidth;
10616
10702
  if (tabX >= contentX + contentWidth)
10617
10703
  break;
10618
- const actualTabWidth = Math.min(this.tabWidth, contentWidth - i * this.tabWidth);
10704
+ const actualTabWidth = Math.min(this._tabWidth, contentWidth - i * this._tabWidth);
10619
10705
  if (isSelected) {
10620
- this.frameBuffer.fillRect(tabX, contentY, actualTabWidth, 1, this.selectedBackgroundColor);
10706
+ this.frameBuffer.fillRect(tabX, contentY, actualTabWidth, 1, this._selectedBackgroundColor);
10621
10707
  }
10622
- const baseTextColor = this._focused ? this.focusedTextColor : this.textColor;
10623
- const nameColor = isSelected ? this.selectedTextColor : baseTextColor;
10708
+ const baseTextColor = this._focused ? this._focusedTextColor : this._textColor;
10709
+ const nameColor = isSelected ? this._selectedTextColor : baseTextColor;
10624
10710
  const nameContent = this.truncateText(option.name, actualTabWidth - 2);
10625
10711
  this.frameBuffer.drawText(nameContent, tabX + 1, contentY, nameColor);
10626
- if (isSelected && this.showUnderline && contentHeight >= 2) {
10712
+ if (isSelected && this._showUnderline && contentHeight >= 2) {
10627
10713
  const underlineY = contentY + 1;
10628
- const underlineBg = isSelected ? this.selectedBackgroundColor : bgColor;
10714
+ const underlineBg = isSelected ? this._selectedBackgroundColor : bgColor;
10629
10715
  this.frameBuffer.drawText("\u25AC".repeat(actualTabWidth), tabX, underlineY, nameColor, underlineBg);
10630
10716
  }
10631
10717
  }
10632
- if (this.showDescription && contentHeight >= (this.showUnderline ? 3 : 2)) {
10718
+ if (this._showDescription && contentHeight >= (this._showUnderline ? 3 : 2)) {
10633
10719
  const selectedOption = this.getSelectedOption();
10634
10720
  if (selectedOption) {
10635
- const descriptionY = contentY + (this.showUnderline ? 2 : 1);
10636
- const descColor = this.selectedDescriptionColor;
10721
+ const descriptionY = contentY + (this._showUnderline ? 2 : 1);
10722
+ const descColor = this._selectedDescriptionColor;
10637
10723
  const descContent = this.truncateText(selectedOption.description, contentWidth - 2);
10638
10724
  this.frameBuffer.drawText(descContent, contentX + 1, descriptionY, descColor);
10639
10725
  }
10640
10726
  }
10641
- if (this.showScrollArrows && this.options.length > this.maxVisibleTabs) {
10727
+ if (this._showScrollArrows && this._options.length > this.maxVisibleTabs) {
10642
10728
  this.renderScrollArrowsToFrameBuffer(contentX, contentY, contentWidth, contentHeight);
10643
10729
  }
10644
10730
  }
@@ -10651,7 +10737,7 @@ class TabSelectRenderable extends Renderable {
10651
10737
  if (!this.frameBuffer)
10652
10738
  return;
10653
10739
  const hasMoreLeft = this.scrollOffset > 0;
10654
- const hasMoreRight = this.scrollOffset + this.maxVisibleTabs < this.options.length;
10740
+ const hasMoreRight = this.scrollOffset + this.maxVisibleTabs < this._options.length;
10655
10741
  if (hasMoreLeft) {
10656
10742
  this.frameBuffer.drawText("\u2039", contentX, contentY, parseColor("#AAAAAA"));
10657
10743
  }
@@ -10660,13 +10746,13 @@ class TabSelectRenderable extends Renderable {
10660
10746
  }
10661
10747
  }
10662
10748
  setOptions(options) {
10663
- this.options = options;
10749
+ this._options = options;
10664
10750
  this.selectedIndex = Math.min(this.selectedIndex, Math.max(0, options.length - 1));
10665
10751
  this.updateScrollOffset();
10666
10752
  this.needsUpdate();
10667
10753
  }
10668
10754
  getSelectedOption() {
10669
- return this.options[this.selectedIndex] || null;
10755
+ return this._options[this.selectedIndex] || null;
10670
10756
  }
10671
10757
  getSelectedIndex() {
10672
10758
  return this.selectedIndex;
@@ -10674,8 +10760,8 @@ class TabSelectRenderable extends Renderable {
10674
10760
  moveLeft() {
10675
10761
  if (this.selectedIndex > 0) {
10676
10762
  this.selectedIndex--;
10677
- } else if (this.wrapSelection && this.options.length > 0) {
10678
- this.selectedIndex = this.options.length - 1;
10763
+ } else if (this._wrapSelection && this._options.length > 0) {
10764
+ this.selectedIndex = this._options.length - 1;
10679
10765
  } else {
10680
10766
  return;
10681
10767
  }
@@ -10684,9 +10770,9 @@ class TabSelectRenderable extends Renderable {
10684
10770
  this.emit("selectionChanged" /* SELECTION_CHANGED */, this.selectedIndex, this.getSelectedOption());
10685
10771
  }
10686
10772
  moveRight() {
10687
- if (this.selectedIndex < this.options.length - 1) {
10773
+ if (this.selectedIndex < this._options.length - 1) {
10688
10774
  this.selectedIndex++;
10689
- } else if (this.wrapSelection && this.options.length > 0) {
10775
+ } else if (this._wrapSelection && this._options.length > 0) {
10690
10776
  this.selectedIndex = 0;
10691
10777
  } else {
10692
10778
  return;
@@ -10702,7 +10788,7 @@ class TabSelectRenderable extends Renderable {
10702
10788
  }
10703
10789
  }
10704
10790
  setSelectedIndex(index) {
10705
- if (index >= 0 && index < this.options.length) {
10791
+ if (index >= 0 && index < this._options.length) {
10706
10792
  this.selectedIndex = index;
10707
10793
  this.updateScrollOffset();
10708
10794
  this.needsUpdate();
@@ -10711,27 +10797,27 @@ class TabSelectRenderable extends Renderable {
10711
10797
  }
10712
10798
  updateScrollOffset() {
10713
10799
  const halfVisible = Math.floor(this.maxVisibleTabs / 2);
10714
- const newScrollOffset = Math.max(0, Math.min(this.selectedIndex - halfVisible, this.options.length - this.maxVisibleTabs));
10800
+ const newScrollOffset = Math.max(0, Math.min(this.selectedIndex - halfVisible, this._options.length - this.maxVisibleTabs));
10715
10801
  if (newScrollOffset !== this.scrollOffset) {
10716
10802
  this.scrollOffset = newScrollOffset;
10717
10803
  this.needsUpdate();
10718
10804
  }
10719
10805
  }
10720
10806
  onResize(width, height) {
10721
- this.maxVisibleTabs = Math.max(1, Math.floor(width / this.tabWidth));
10807
+ this.maxVisibleTabs = Math.max(1, Math.floor(width / this._tabWidth));
10722
10808
  this.updateScrollOffset();
10723
10809
  this.needsUpdate();
10724
10810
  }
10725
10811
  setTabWidth(tabWidth) {
10726
- if (this.tabWidth === tabWidth)
10812
+ if (this._tabWidth === tabWidth)
10727
10813
  return;
10728
- this.tabWidth = tabWidth;
10729
- this.maxVisibleTabs = Math.max(1, Math.floor(this.width / this.tabWidth));
10814
+ this._tabWidth = tabWidth;
10815
+ this.maxVisibleTabs = Math.max(1, Math.floor(this.width / this._tabWidth));
10730
10816
  this.updateScrollOffset();
10731
10817
  this.needsUpdate();
10732
10818
  }
10733
10819
  getTabWidth() {
10734
- return this.tabWidth;
10820
+ return this._tabWidth;
10735
10821
  }
10736
10822
  handleKeyPress(key) {
10737
10823
  const keyName2 = typeof key === "string" ? key : key.name;
@@ -10751,40 +10837,90 @@ class TabSelectRenderable extends Renderable {
10751
10837
  }
10752
10838
  return false;
10753
10839
  }
10754
- setShowDescription(show) {
10755
- if (this.showDescription !== show) {
10756
- this.showDescription = show;
10840
+ get options() {
10841
+ return this._options;
10842
+ }
10843
+ set options(options) {
10844
+ this._options = options;
10845
+ this.selectedIndex = Math.min(this.selectedIndex, Math.max(0, options.length - 1));
10846
+ this.updateScrollOffset();
10847
+ this.needsUpdate();
10848
+ }
10849
+ set backgroundColor(color) {
10850
+ this._backgroundColor = parseColor(color);
10851
+ this.needsUpdate();
10852
+ }
10853
+ set textColor(color) {
10854
+ this._textColor = parseColor(color);
10855
+ this.needsUpdate();
10856
+ }
10857
+ set focusedBackgroundColor(color) {
10858
+ this._focusedBackgroundColor = parseColor(color);
10859
+ this.needsUpdate();
10860
+ }
10861
+ set focusedTextColor(color) {
10862
+ this._focusedTextColor = parseColor(color);
10863
+ this.needsUpdate();
10864
+ }
10865
+ set selectedBackgroundColor(color) {
10866
+ this._selectedBackgroundColor = parseColor(color);
10867
+ this.needsUpdate();
10868
+ }
10869
+ set selectedTextColor(color) {
10870
+ this._selectedTextColor = parseColor(color);
10871
+ this.needsUpdate();
10872
+ }
10873
+ set selectedDescriptionColor(color) {
10874
+ this._selectedDescriptionColor = parseColor(color);
10875
+ this.needsUpdate();
10876
+ }
10877
+ get showDescription() {
10878
+ return this._showDescription;
10879
+ }
10880
+ set showDescription(show) {
10881
+ if (this._showDescription !== show) {
10882
+ this._showDescription = show;
10757
10883
  const newHeight = this.calculateDynamicHeight();
10758
10884
  this.height = newHeight;
10885
+ this.needsUpdate();
10759
10886
  }
10760
10887
  }
10761
- getShowDescription() {
10762
- return this.showDescription;
10888
+ get showUnderline() {
10889
+ return this._showUnderline;
10763
10890
  }
10764
- setShowUnderline(show) {
10765
- if (this.showUnderline !== show) {
10766
- this.showUnderline = show;
10891
+ set showUnderline(show) {
10892
+ if (this._showUnderline !== show) {
10893
+ this._showUnderline = show;
10767
10894
  const newHeight = this.calculateDynamicHeight();
10768
10895
  this.height = newHeight;
10896
+ this.needsUpdate();
10769
10897
  }
10770
10898
  }
10771
- getShowUnderline() {
10772
- return this.showUnderline;
10899
+ get showScrollArrows() {
10900
+ return this._showScrollArrows;
10773
10901
  }
10774
- setShowScrollArrows(show) {
10775
- if (this.showScrollArrows !== show) {
10776
- this.showScrollArrows = show;
10902
+ set showScrollArrows(show) {
10903
+ if (this._showScrollArrows !== show) {
10904
+ this._showScrollArrows = show;
10777
10905
  this.needsUpdate();
10778
10906
  }
10779
10907
  }
10780
- getShowScrollArrows() {
10781
- return this.showScrollArrows;
10908
+ get wrapSelection() {
10909
+ return this._wrapSelection;
10910
+ }
10911
+ set wrapSelection(wrap) {
10912
+ this._wrapSelection = wrap;
10782
10913
  }
10783
- setWrapSelection(wrap) {
10784
- this.wrapSelection = wrap;
10914
+ get tabWidth() {
10915
+ return this._tabWidth;
10785
10916
  }
10786
- getWrapSelection() {
10787
- return this.wrapSelection;
10917
+ set tabWidth(tabWidth) {
10918
+ if (this._tabWidth === tabWidth)
10919
+ return;
10920
+ this._tabWidth = tabWidth;
10921
+ this.maxVisibleTabs = Math.max(1, Math.floor(this.width / this._tabWidth));
10922
+ this.updateScrollOffset();
10923
+ this.needsUpdate();
10788
10924
  }
10789
10925
  }
10790
10926
  export {
@@ -10921,5 +11057,5 @@ export {
10921
11057
  ASCIIFontRenderable
10922
11058
  };
10923
11059
  export { __toESM, __commonJS, __export, __require };
10924
- //# debugId=D2D08A0277CDE28864756E2164756E21
11060
+ //# debugId=63F280D9D38C7F3F64756E2164756E21
10925
11061
  //# sourceMappingURL=index.js.map