@opentui/core 0.1.1 → 0.1.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
@@ -2,7 +2,7 @@
2
2
  // src/Renderable.ts
3
3
  import { EventEmitter as EventEmitter3 } from "events";
4
4
 
5
- // node_modules/yoga-layout/dist/binaries/yoga-wasm-base64-esm.js
5
+ // ../../node_modules/yoga-layout/dist/binaries/yoga-wasm-base64-esm.js
6
6
  var loadYoga = (() => {
7
7
  var _scriptDir = import.meta.url;
8
8
  return function(loadYoga2) {
@@ -1307,7 +1307,7 @@ var loadYoga = (() => {
1307
1307
  })();
1308
1308
  var yoga_wasm_base64_esm_default = loadYoga;
1309
1309
 
1310
- // node_modules/yoga-layout/dist/src/generated/YGEnums.js
1310
+ // ../../node_modules/yoga-layout/dist/src/generated/YGEnums.js
1311
1311
  var Align = /* @__PURE__ */ function(Align2) {
1312
1312
  Align2[Align2["Auto"] = 0] = "Auto";
1313
1313
  Align2[Align2["FlexStart"] = 1] = "FlexStart";
@@ -1510,7 +1510,7 @@ var constants = {
1510
1510
  };
1511
1511
  var YGEnums_default = constants;
1512
1512
 
1513
- // node_modules/yoga-layout/dist/src/wrapAssembly.js
1513
+ // ../../node_modules/yoga-layout/dist/src/wrapAssembly.js
1514
1514
  function wrapAssembly(lib) {
1515
1515
  function patch(prototype, name, fn) {
1516
1516
  const original = prototype[name];
@@ -1612,7 +1612,7 @@ function wrapAssembly(lib) {
1612
1612
  };
1613
1613
  }
1614
1614
 
1615
- // node_modules/yoga-layout/dist/src/index.js
1615
+ // ../../node_modules/yoga-layout/dist/src/index.js
1616
1616
  var Yoga = wrapAssembly(await yoga_wasm_base64_esm_default());
1617
1617
  var src_default = Yoga;
1618
1618
 
@@ -1626,7 +1626,6 @@ class TrackedNode extends EventEmitter {
1626
1626
  metadata;
1627
1627
  parent;
1628
1628
  children;
1629
- zIndex;
1630
1629
  _destroyed = false;
1631
1630
  _width = "auto";
1632
1631
  _height = "auto";
@@ -1637,7 +1636,6 @@ class TrackedNode extends EventEmitter {
1637
1636
  this.metadata = metadata;
1638
1637
  this.parent = null;
1639
1638
  this.children = [];
1640
- this.zIndex = 0;
1641
1639
  }
1642
1640
  parseWidth(width) {
1643
1641
  if (this._destroyed) {
@@ -1694,9 +1692,6 @@ class TrackedNode extends EventEmitter {
1694
1692
  childNode.parent = this;
1695
1693
  const index = this.children.length;
1696
1694
  this.children.push(childNode);
1697
- if (!childNode.zIndex) {
1698
- childNode.zIndex = this.zIndex + 100;
1699
- }
1700
1695
  this.yogaNode.insertChild(childNode.yogaNode, index);
1701
1696
  try {
1702
1697
  childNode.yogaNode.setWidth(childNode.parseWidth(childNode._width));
@@ -1749,7 +1744,6 @@ class TrackedNode extends EventEmitter {
1749
1744
  childNode.parent.removeChild(childNode);
1750
1745
  }
1751
1746
  childNode.parent = this;
1752
- childNode.zIndex = this.zIndex + 100;
1753
1747
  const boundedIndex = Math.max(0, Math.min(index, this.children.length));
1754
1748
  this.children.splice(boundedIndex, 0, childNode);
1755
1749
  this.yogaNode.insertChild(childNode.yogaNode, boundedIndex);
@@ -1995,6 +1989,64 @@ function getKeyHandler() {
1995
1989
  return keyHandler;
1996
1990
  }
1997
1991
 
1992
+ // src/lib/yoga.options.ts
1993
+ function parseAlign(value) {
1994
+ switch (value.toLowerCase()) {
1995
+ case "auto":
1996
+ return Align.Auto;
1997
+ case "flex-start":
1998
+ return Align.FlexStart;
1999
+ case "center":
2000
+ return Align.Center;
2001
+ case "flex-end":
2002
+ return Align.FlexEnd;
2003
+ case "stretch":
2004
+ return Align.Stretch;
2005
+ case "baseline":
2006
+ return Align.Baseline;
2007
+ case "space-between":
2008
+ return Align.SpaceBetween;
2009
+ case "space-around":
2010
+ return Align.SpaceAround;
2011
+ case "space-evenly":
2012
+ return Align.SpaceEvenly;
2013
+ default:
2014
+ return Align.Auto;
2015
+ }
2016
+ }
2017
+ function parseFlexDirection(value) {
2018
+ switch (value.toLowerCase()) {
2019
+ case "column":
2020
+ return FlexDirection.Column;
2021
+ case "column-reverse":
2022
+ return FlexDirection.ColumnReverse;
2023
+ case "row":
2024
+ return FlexDirection.Row;
2025
+ case "row-reverse":
2026
+ return FlexDirection.RowReverse;
2027
+ default:
2028
+ return FlexDirection.Column;
2029
+ }
2030
+ }
2031
+ function parseJustify(value) {
2032
+ switch (value.toLowerCase()) {
2033
+ case "flex-start":
2034
+ return Justify.FlexStart;
2035
+ case "center":
2036
+ return Justify.Center;
2037
+ case "flex-end":
2038
+ return Justify.FlexEnd;
2039
+ case "space-between":
2040
+ return Justify.SpaceBetween;
2041
+ case "space-around":
2042
+ return Justify.SpaceAround;
2043
+ case "space-evenly":
2044
+ return Justify.SpaceEvenly;
2045
+ default:
2046
+ return Justify.FlexStart;
2047
+ }
2048
+ }
2049
+
1998
2050
  // src/Renderable.ts
1999
2051
  var LayoutEvents;
2000
2052
  ((LayoutEvents2) => {
@@ -2021,6 +2073,59 @@ function validateOptions(id, options) {
2021
2073
  }
2022
2074
  }
2023
2075
  }
2076
+ function isValidPercentage(value) {
2077
+ if (typeof value === "string" && value.endsWith("%")) {
2078
+ const numPart = value.slice(0, -1);
2079
+ const num = parseFloat(numPart);
2080
+ return !Number.isNaN(num);
2081
+ }
2082
+ return false;
2083
+ }
2084
+ function isMarginType(value) {
2085
+ if (typeof value === "number" && !Number.isNaN(value)) {
2086
+ return true;
2087
+ }
2088
+ if (value === "auto") {
2089
+ return true;
2090
+ }
2091
+ return isValidPercentage(value);
2092
+ }
2093
+ function isPaddingType(value) {
2094
+ if (typeof value === "number" && !Number.isNaN(value)) {
2095
+ return true;
2096
+ }
2097
+ return isValidPercentage(value);
2098
+ }
2099
+ function isPositionType(value) {
2100
+ if (typeof value === "number" && !Number.isNaN(value)) {
2101
+ return true;
2102
+ }
2103
+ if (value === "auto") {
2104
+ return true;
2105
+ }
2106
+ return isValidPercentage(value);
2107
+ }
2108
+ function isDimensionType(value) {
2109
+ return isPositionType(value);
2110
+ }
2111
+ function isFlexBasisType(value) {
2112
+ if (value === undefined || value === "auto") {
2113
+ return true;
2114
+ }
2115
+ if (typeof value === "number" && !Number.isNaN(value)) {
2116
+ return true;
2117
+ }
2118
+ return false;
2119
+ }
2120
+ function isSizeType(value) {
2121
+ if (value === undefined) {
2122
+ return true;
2123
+ }
2124
+ if (typeof value === "number" && !Number.isNaN(value)) {
2125
+ return true;
2126
+ }
2127
+ return isValidPercentage(value);
2128
+ }
2024
2129
 
2025
2130
  class Renderable extends EventEmitter3 {
2026
2131
  static renderablesByNumber = new Map;
@@ -2142,19 +2247,39 @@ class Renderable extends EventEmitter3 {
2142
2247
  return this._x;
2143
2248
  }
2144
2249
  set x(value) {
2145
- this.setPosition({
2146
- left: value
2147
- });
2250
+ this.left = value;
2251
+ }
2252
+ get top() {
2253
+ return this._position.top;
2148
2254
  }
2149
2255
  set top(value) {
2150
- this.setPosition({
2151
- top: value
2152
- });
2256
+ if (isPositionType(value) || value === undefined) {
2257
+ this.setPosition({ top: value });
2258
+ }
2259
+ }
2260
+ get right() {
2261
+ return this._position.right;
2262
+ }
2263
+ set right(value) {
2264
+ if (isPositionType(value) || value === undefined) {
2265
+ this.setPosition({ right: value });
2266
+ }
2267
+ }
2268
+ get bottom() {
2269
+ return this._position.bottom;
2270
+ }
2271
+ set bottom(value) {
2272
+ if (isPositionType(value) || value === undefined) {
2273
+ this.setPosition({ bottom: value });
2274
+ }
2275
+ }
2276
+ get left() {
2277
+ return this._position.left;
2153
2278
  }
2154
2279
  set left(value) {
2155
- this.setPosition({
2156
- left: value
2157
- });
2280
+ if (isPositionType(value) || value === undefined) {
2281
+ this.setPosition({ left: value });
2282
+ }
2158
2283
  }
2159
2284
  get y() {
2160
2285
  if (this.parent && this._positionType === "relative") {
@@ -2163,25 +2288,27 @@ class Renderable extends EventEmitter3 {
2163
2288
  return this._y;
2164
2289
  }
2165
2290
  set y(value) {
2166
- this.setPosition({
2167
- top: value
2168
- });
2291
+ this.top = value;
2169
2292
  }
2170
2293
  get width() {
2171
2294
  return this._widthValue;
2172
2295
  }
2173
2296
  set width(value) {
2174
- this._width = value;
2175
- this.layoutNode.setWidth(value);
2176
- this.requestLayout();
2297
+ if (isDimensionType(value)) {
2298
+ this._width = value;
2299
+ this.layoutNode.setWidth(value);
2300
+ this.requestLayout();
2301
+ }
2177
2302
  }
2178
2303
  get height() {
2179
2304
  return this._heightValue;
2180
2305
  }
2181
2306
  set height(value) {
2182
- this._height = value;
2183
- this.layoutNode.setHeight(value);
2184
- this.requestLayout();
2307
+ if (isDimensionType(value)) {
2308
+ this._height = value;
2309
+ this.layoutNode.setHeight(value);
2310
+ this.requestLayout();
2311
+ }
2185
2312
  }
2186
2313
  get zIndex() {
2187
2314
  return this._zIndex;
@@ -2203,13 +2330,13 @@ class Renderable extends EventEmitter3 {
2203
2330
  }
2204
2331
  setupYogaProperties(options) {
2205
2332
  const node = this.layoutNode.yogaNode;
2206
- if (options.flexBasis !== undefined) {
2333
+ if (isFlexBasisType(options.flexBasis)) {
2207
2334
  node.setFlexBasis(options.flexBasis);
2208
2335
  }
2209
- if (options.minWidth !== undefined) {
2336
+ if (isSizeType(options.minWidth)) {
2210
2337
  node.setMinWidth(options.minWidth);
2211
2338
  }
2212
- if (options.minHeight !== undefined) {
2339
+ if (isSizeType(options.minHeight)) {
2213
2340
  node.setMinHeight(options.minHeight);
2214
2341
  }
2215
2342
  if (options.flexGrow !== undefined) {
@@ -2224,19 +2351,19 @@ class Renderable extends EventEmitter3 {
2224
2351
  node.setFlexShrink(shrinkValue);
2225
2352
  }
2226
2353
  if (options.flexDirection !== undefined) {
2227
- node.setFlexDirection(options.flexDirection);
2354
+ node.setFlexDirection(parseFlexDirection(options.flexDirection));
2228
2355
  }
2229
2356
  if (options.alignItems !== undefined) {
2230
- node.setAlignItems(options.alignItems);
2357
+ node.setAlignItems(parseAlign(options.alignItems));
2231
2358
  }
2232
2359
  if (options.justifyContent !== undefined) {
2233
- node.setJustifyContent(options.justifyContent);
2360
+ node.setJustifyContent(parseJustify(options.justifyContent));
2234
2361
  }
2235
- if (options.width !== undefined) {
2362
+ if (isDimensionType(options.width)) {
2236
2363
  this._width = options.width;
2237
2364
  this.layoutNode.setWidth(options.width);
2238
2365
  }
2239
- if (options.height !== undefined) {
2366
+ if (isDimensionType(options.height)) {
2240
2367
  this._height = options.height;
2241
2368
  this.layoutNode.setHeight(options.height);
2242
2369
  }
@@ -2244,79 +2371,93 @@ class Renderable extends EventEmitter3 {
2244
2371
  if (this._positionType === "absolute") {
2245
2372
  node.setPositionType(PositionType.Absolute);
2246
2373
  }
2247
- if (options.position) {
2248
- this._position = options.position;
2249
- this.updateYogaPosition(options.position);
2374
+ const hasPositionProps = options.top !== undefined || options.right !== undefined || options.bottom !== undefined || options.left !== undefined;
2375
+ if (hasPositionProps) {
2376
+ this._position = {
2377
+ top: options.top,
2378
+ right: options.right,
2379
+ bottom: options.bottom,
2380
+ left: options.left
2381
+ };
2382
+ this.updateYogaPosition(this._position);
2250
2383
  }
2251
- if (options.maxWidth !== undefined) {
2384
+ if (isSizeType(options.maxWidth)) {
2252
2385
  node.setMaxWidth(options.maxWidth);
2253
2386
  }
2254
- if (options.maxHeight !== undefined) {
2387
+ if (isSizeType(options.maxHeight)) {
2255
2388
  node.setMaxHeight(options.maxHeight);
2256
2389
  }
2257
- if (typeof options.margin === "object") {
2258
- const { top, right, bottom, left } = options.margin;
2259
- if (top !== undefined)
2260
- node.setMargin(Edge.Top, top);
2261
- if (right !== undefined)
2262
- node.setMargin(Edge.Right, right);
2263
- if (bottom !== undefined)
2264
- node.setMargin(Edge.Bottom, bottom);
2265
- if (left !== undefined)
2266
- node.setMargin(Edge.Left, left);
2267
- } else if (options.margin !== undefined) {
2390
+ this.setupMarginAndPadding(options);
2391
+ }
2392
+ setupMarginAndPadding(options) {
2393
+ const node = this.layoutNode.yogaNode;
2394
+ if (isMarginType(options.margin)) {
2268
2395
  node.setMargin(Edge.Top, options.margin);
2269
2396
  node.setMargin(Edge.Right, options.margin);
2270
2397
  node.setMargin(Edge.Bottom, options.margin);
2271
2398
  node.setMargin(Edge.Left, options.margin);
2272
2399
  }
2273
- if (typeof options.padding === "object") {
2274
- const { top, right, bottom, left } = options.padding;
2275
- if (top !== undefined)
2276
- node.setPadding(Edge.Top, top);
2277
- if (right !== undefined)
2278
- node.setPadding(Edge.Right, right);
2279
- if (bottom !== undefined)
2280
- node.setPadding(Edge.Bottom, bottom);
2281
- if (left !== undefined)
2282
- node.setPadding(Edge.Left, left);
2283
- } else if (options.padding !== undefined) {
2400
+ if (isMarginType(options.marginTop)) {
2401
+ node.setMargin(Edge.Top, options.marginTop);
2402
+ }
2403
+ if (isMarginType(options.marginRight)) {
2404
+ node.setMargin(Edge.Right, options.marginRight);
2405
+ }
2406
+ if (isMarginType(options.marginBottom)) {
2407
+ node.setMargin(Edge.Bottom, options.marginBottom);
2408
+ }
2409
+ if (isMarginType(options.marginLeft)) {
2410
+ node.setMargin(Edge.Left, options.marginLeft);
2411
+ }
2412
+ if (isPaddingType(options.padding)) {
2284
2413
  node.setPadding(Edge.Top, options.padding);
2285
2414
  node.setPadding(Edge.Right, options.padding);
2286
2415
  node.setPadding(Edge.Bottom, options.padding);
2287
2416
  node.setPadding(Edge.Left, options.padding);
2288
2417
  }
2418
+ if (isPaddingType(options.paddingTop)) {
2419
+ node.setPadding(Edge.Top, options.paddingTop);
2420
+ }
2421
+ if (isPaddingType(options.paddingRight)) {
2422
+ node.setPadding(Edge.Right, options.paddingRight);
2423
+ }
2424
+ if (isPaddingType(options.paddingBottom)) {
2425
+ node.setPadding(Edge.Bottom, options.paddingBottom);
2426
+ }
2427
+ if (isPaddingType(options.paddingLeft)) {
2428
+ node.setPadding(Edge.Left, options.paddingLeft);
2429
+ }
2289
2430
  }
2290
2431
  setPosition(position) {
2291
- this._position = position;
2432
+ this._position = { ...this._position, ...position };
2292
2433
  this.updateYogaPosition(position);
2293
2434
  }
2294
2435
  updateYogaPosition(position) {
2295
2436
  const node = this.layoutNode.yogaNode;
2296
2437
  const { top, right, bottom, left } = position;
2297
2438
  if (this._positionType === "relative") {
2298
- if (top !== undefined) {
2439
+ if (isPositionType(top)) {
2299
2440
  if (top === "auto") {
2300
2441
  node.setPositionAuto(Edge.Top);
2301
2442
  } else {
2302
2443
  node.setPosition(Edge.Top, top);
2303
2444
  }
2304
2445
  }
2305
- if (right !== undefined) {
2446
+ if (isPositionType(right)) {
2306
2447
  if (right === "auto") {
2307
2448
  node.setPositionAuto(Edge.Right);
2308
2449
  } else {
2309
2450
  node.setPosition(Edge.Right, right);
2310
2451
  }
2311
2452
  }
2312
- if (bottom !== undefined) {
2453
+ if (isPositionType(bottom)) {
2313
2454
  if (bottom === "auto") {
2314
2455
  node.setPositionAuto(Edge.Bottom);
2315
2456
  } else {
2316
2457
  node.setPosition(Edge.Bottom, bottom);
2317
2458
  }
2318
2459
  }
2319
- if (left !== undefined) {
2460
+ if (isPositionType(left)) {
2320
2461
  if (left === "auto") {
2321
2462
  node.setPositionAuto(Edge.Left);
2322
2463
  } else {
@@ -2344,36 +2485,114 @@ class Renderable extends EventEmitter3 {
2344
2485
  this.requestLayout();
2345
2486
  }
2346
2487
  set flexDirection(direction) {
2347
- this.layoutNode.yogaNode.setFlexDirection(direction);
2488
+ this.layoutNode.yogaNode.setFlexDirection(parseFlexDirection(direction));
2348
2489
  this.requestLayout();
2349
2490
  }
2350
2491
  set alignItems(alignItems) {
2351
- this.layoutNode.yogaNode.setAlignItems(alignItems);
2492
+ this.layoutNode.yogaNode.setAlignItems(parseAlign(alignItems));
2352
2493
  this.requestLayout();
2353
2494
  }
2354
2495
  set justifyContent(justifyContent) {
2355
- this.layoutNode.yogaNode.setJustifyContent(justifyContent);
2496
+ this.layoutNode.yogaNode.setJustifyContent(parseJustify(justifyContent));
2356
2497
  this.requestLayout();
2357
2498
  }
2358
2499
  set flexBasis(basis) {
2359
- this.layoutNode.yogaNode.setFlexBasis(basis);
2360
- this.requestLayout();
2500
+ if (isFlexBasisType(basis)) {
2501
+ this.layoutNode.yogaNode.setFlexBasis(basis);
2502
+ this.requestLayout();
2503
+ }
2361
2504
  }
2362
2505
  set minWidth(minWidth) {
2363
- this.layoutNode.yogaNode.setMinWidth(minWidth);
2364
- this.requestLayout();
2506
+ if (isSizeType(minWidth)) {
2507
+ this.layoutNode.yogaNode.setMinWidth(minWidth);
2508
+ this.requestLayout();
2509
+ }
2365
2510
  }
2366
2511
  set maxWidth(maxWidth) {
2367
- this.layoutNode.yogaNode.setMaxWidth(maxWidth);
2368
- this.requestLayout();
2512
+ if (isSizeType(maxWidth)) {
2513
+ this.layoutNode.yogaNode.setMaxWidth(maxWidth);
2514
+ this.requestLayout();
2515
+ }
2369
2516
  }
2370
2517
  set minHeight(minHeight) {
2371
- this.layoutNode.yogaNode.setMinHeight(minHeight);
2372
- this.requestLayout();
2518
+ if (isSizeType(minHeight)) {
2519
+ this.layoutNode.yogaNode.setMinHeight(minHeight);
2520
+ this.requestLayout();
2521
+ }
2373
2522
  }
2374
2523
  set maxHeight(maxHeight) {
2375
- this.layoutNode.yogaNode.setMaxHeight(maxHeight);
2376
- this.requestLayout();
2524
+ if (isSizeType(maxHeight)) {
2525
+ this.layoutNode.yogaNode.setMaxHeight(maxHeight);
2526
+ this.requestLayout();
2527
+ }
2528
+ }
2529
+ set margin(margin) {
2530
+ if (isMarginType(margin)) {
2531
+ const node = this.layoutNode.yogaNode;
2532
+ node.setMargin(Edge.Top, margin);
2533
+ node.setMargin(Edge.Right, margin);
2534
+ node.setMargin(Edge.Bottom, margin);
2535
+ node.setMargin(Edge.Left, margin);
2536
+ this.requestLayout();
2537
+ }
2538
+ }
2539
+ set marginTop(margin) {
2540
+ if (isMarginType(margin)) {
2541
+ this.layoutNode.yogaNode.setMargin(Edge.Top, margin);
2542
+ this.requestLayout();
2543
+ }
2544
+ }
2545
+ set marginRight(margin) {
2546
+ if (isMarginType(margin)) {
2547
+ this.layoutNode.yogaNode.setMargin(Edge.Right, margin);
2548
+ this.requestLayout();
2549
+ }
2550
+ }
2551
+ set marginBottom(margin) {
2552
+ if (isMarginType(margin)) {
2553
+ this.layoutNode.yogaNode.setMargin(Edge.Bottom, margin);
2554
+ this.requestLayout();
2555
+ }
2556
+ }
2557
+ set marginLeft(margin) {
2558
+ if (isMarginType(margin)) {
2559
+ this.layoutNode.yogaNode.setMargin(Edge.Left, margin);
2560
+ this.requestLayout();
2561
+ }
2562
+ }
2563
+ set padding(padding) {
2564
+ if (isPaddingType(padding)) {
2565
+ const node = this.layoutNode.yogaNode;
2566
+ node.setPadding(Edge.Top, padding);
2567
+ node.setPadding(Edge.Right, padding);
2568
+ node.setPadding(Edge.Bottom, padding);
2569
+ node.setPadding(Edge.Left, padding);
2570
+ this.requestLayout();
2571
+ }
2572
+ }
2573
+ set paddingTop(padding) {
2574
+ if (isPaddingType(padding)) {
2575
+ this.layoutNode.yogaNode.setPadding(Edge.Top, padding);
2576
+ this.requestLayout();
2577
+ }
2578
+ }
2579
+ set paddingRight(padding) {
2580
+ if (isPaddingType(padding)) {
2581
+ this.layoutNode.yogaNode.setPadding(Edge.Right, padding);
2582
+ this.requestLayout();
2583
+ }
2584
+ }
2585
+ set paddingBottom(padding) {
2586
+ if (isPaddingType(padding)) {
2587
+ this.layoutNode.yogaNode.setPadding(Edge.Bottom, padding);
2588
+ this.requestLayout();
2589
+ }
2590
+ }
2591
+ set paddingLeft(padding) {
2592
+ if (isPaddingType(padding)) {
2593
+ this.layoutNode.yogaNode.setPadding(Edge.Left, padding);
2594
+ this.requestLayout();
2595
+ }
2377
2596
  }
2378
2597
  getLayoutNode() {
2379
2598
  return this.layoutNode;
@@ -2439,10 +2658,7 @@ class Renderable extends EventEmitter3 {
2439
2658
  }
2440
2659
  this.needsUpdate();
2441
2660
  }
2442
- add(obj) {
2443
- if (this.renderableMap.has(obj.id)) {
2444
- this.remove(obj.id);
2445
- }
2661
+ replaceParent(obj) {
2446
2662
  if (obj.parent) {
2447
2663
  obj.parent.remove(obj.id);
2448
2664
  }
@@ -2450,13 +2666,40 @@ class Renderable extends EventEmitter3 {
2450
2666
  if (this.ctx) {
2451
2667
  obj.propagateContext(this.ctx);
2452
2668
  }
2453
- this.renderableArray.push(obj);
2669
+ }
2670
+ add(obj, index) {
2671
+ if (this.renderableMap.has(obj.id)) {
2672
+ console.warn(`A renderable with id ${obj.id} already exists in ${this.id}, removing it`);
2673
+ this.remove(obj.id);
2674
+ }
2675
+ this.replaceParent(obj);
2676
+ const childLayoutNode = obj.getLayoutNode();
2677
+ let insertedIndex;
2678
+ if (index !== undefined) {
2679
+ this.renderableArray.splice(index, 0, obj);
2680
+ insertedIndex = this.layoutNode.insertChild(childLayoutNode, index);
2681
+ } else {
2682
+ this.renderableArray.push(obj);
2683
+ insertedIndex = this.layoutNode.addChild(childLayoutNode);
2684
+ }
2454
2685
  this.needsZIndexSort = true;
2455
2686
  this.renderableMap.set(obj.id, obj);
2456
- const childLayoutNode = obj.getLayoutNode();
2457
- this.layoutNode.addChild(childLayoutNode);
2458
2687
  this.requestLayout();
2459
2688
  this.emit("child:added", obj);
2689
+ return insertedIndex;
2690
+ }
2691
+ insertBefore(obj, anchor) {
2692
+ if (!anchor) {
2693
+ return this.add(obj);
2694
+ }
2695
+ if (!this.renderableMap.has(anchor.id)) {
2696
+ throw new Error("Anchor does not exist");
2697
+ }
2698
+ const anchorIndex = this.renderableArray.indexOf(anchor);
2699
+ if (anchorIndex === -1) {
2700
+ throw new Error("Anchor does not exist");
2701
+ }
2702
+ return this.add(obj, anchorIndex);
2460
2703
  }
2461
2704
  propagateContext(ctx) {
2462
2705
  this.ctx = ctx;
@@ -2530,6 +2773,12 @@ class Renderable extends EventEmitter3 {
2530
2773
  this.removeAllListeners();
2531
2774
  this.destroySelf();
2532
2775
  }
2776
+ destroyRecursively() {
2777
+ this.destroy();
2778
+ for (const child of this.renderableArray) {
2779
+ child.destroyRecursively();
2780
+ }
2781
+ }
2533
2782
  destroySelf() {}
2534
2783
  processMouseEvent(event) {
2535
2784
  this.onMouseEvent(event);
@@ -2557,22 +2806,6 @@ class RootRenderable extends Renderable {
2557
2806
  this.layoutNode.yogaNode.setFlexDirection(FlexDirection.Column);
2558
2807
  this.calculateLayout();
2559
2808
  }
2560
- add(obj) {
2561
- super.add(obj);
2562
- const childLayoutNode = obj.getLayoutNode();
2563
- this.layoutNode.addChild(childLayoutNode);
2564
- this.requestLayout();
2565
- this.emit("added" /* ADDED */, obj);
2566
- }
2567
- remove(id) {
2568
- const obj = this.getRenderable(id);
2569
- if (obj) {
2570
- this.layoutNode.removeChild(obj.getLayoutNode());
2571
- this.emit("removed" /* REMOVED */, obj);
2572
- this.requestLayout();
2573
- }
2574
- super.remove(id);
2575
- }
2576
2809
  requestLayout() {
2577
2810
  this.needsUpdate();
2578
2811
  }
@@ -2816,9 +3049,8 @@ var DebugOverlayCorner;
2816
3049
  DebugOverlayCorner2[DebugOverlayCorner2["bottomRight"] = 3] = "bottomRight";
2817
3050
  })(DebugOverlayCorner ||= {});
2818
3051
  // src/zig.ts
2819
- import { dlopen, suffix, toArrayBuffer } from "bun:ffi";
2820
- import { dirname, join } from "path";
2821
- import { existsSync, readFileSync } from "fs";
3052
+ import { dlopen, toArrayBuffer } from "bun:ffi";
3053
+ import { existsSync } from "fs";
2822
3054
 
2823
3055
  // src/text-buffer.ts
2824
3056
  class TextBuffer {
@@ -2905,25 +3137,13 @@ class TextBuffer {
2905
3137
  }
2906
3138
 
2907
3139
  // src/zig.ts
2908
- import { createRequire } from "module";
2909
- import { fileURLToPath } from "url";
2910
- var require2 = createRequire(import.meta.url);
2911
- var __filename2 = fileURLToPath(import.meta.url);
2912
- var __dirname2 = dirname(__filename2);
2913
- var packageJson = JSON.parse(readFileSync(join(__dirname2, ...__filename2.endsWith(".ts") ? ["..", "dist", "./package.json"] : ["./package.json"]), { encoding: "utf8" }));
2914
- function findLibrary() {
2915
- try {
2916
- const isWindows = process.platform === "win32";
2917
- const libraryName = isWindows ? "opentui" : "libopentui";
2918
- const targetLibPath = require2.resolve(`${packageJson.name}-${process.platform}-${process.arch}/${libraryName}.${suffix}`);
2919
- if (existsSync(targetLibPath)) {
2920
- return targetLibPath;
2921
- }
2922
- } catch {}
3140
+ var module = await import(`@opentui/core-${process.platform}-${process.arch}/index.ts`);
3141
+ var targetLibPath = module.default;
3142
+ if (!existsSync(targetLibPath)) {
2923
3143
  throw new Error(`opentui is not supported on the current platform: ${process.platform}-${process.arch}`);
2924
3144
  }
2925
3145
  function getOpenTUILib(libPath) {
2926
- const resolvedLibPath = libPath || findLibrary();
3146
+ const resolvedLibPath = libPath || targetLibPath;
2927
3147
  return dlopen(resolvedLibPath, {
2928
3148
  createRenderer: {
2929
3149
  args: ["u32", "u32"],
@@ -3547,6 +3767,9 @@ class FFIRenderLib {
3547
3767
  }
3548
3768
  var opentuiLibPath;
3549
3769
  var opentuiLib;
3770
+ function setRenderLibPath(libPath) {
3771
+ opentuiLibPath = libPath;
3772
+ }
3550
3773
  function resolveRenderLib() {
3551
3774
  if (!opentuiLib) {
3552
3775
  opentuiLib = new FFIRenderLib(opentuiLibPath);
@@ -7160,6 +7383,22 @@ function getCallerInfo() {
7160
7383
  const columnNumber = parseInt(match[4], 10) || 0;
7161
7384
  return { functionName, fullPath, fileName, lineNumber, columnNumber };
7162
7385
  }
7386
+ var capture = new Capture;
7387
+ var mockStdout = new CapturedWritableStream("stdout", capture);
7388
+ var mockStderr = new CapturedWritableStream("stderr", capture);
7389
+ if (process.env.SKIP_CONSOLE_CACHE !== "true") {
7390
+ global.console = new console.Console({
7391
+ stdout: mockStdout,
7392
+ stderr: mockStderr,
7393
+ colorMode: true,
7394
+ inspectOptions: {
7395
+ compact: false,
7396
+ breakLength: 80,
7397
+ depth: 2
7398
+ }
7399
+ });
7400
+ }
7401
+
7163
7402
  class TerminalConsoleCache extends EventEmitter5 {
7164
7403
  originalConsole;
7165
7404
  _cachedLogs = [];
@@ -7240,19 +7479,6 @@ class TerminalConsoleCache extends EventEmitter5 {
7240
7479
  this.deactivate();
7241
7480
  }
7242
7481
  }
7243
- var capture = new Capture;
7244
- var mockStdout = new CapturedWritableStream("stdout", capture);
7245
- var mockStderr = new CapturedWritableStream("stderr", capture);
7246
- global.console = new console.Console({
7247
- stdout: mockStdout,
7248
- stderr: mockStderr,
7249
- colorMode: true,
7250
- inspectOptions: {
7251
- compact: false,
7252
- breakLength: 80,
7253
- depth: 2
7254
- }
7255
- });
7256
7482
  var terminalConsoleCache = new TerminalConsoleCache;
7257
7483
  process.on("exit", () => {
7258
7484
  terminalConsoleCache.destroy();
@@ -8805,7 +9031,7 @@ Error details:
8805
9031
  }
8806
9032
  // src/renderables/Box.ts
8807
9033
  class BoxRenderable extends Renderable {
8808
- _bg;
9034
+ _backgroundColor;
8809
9035
  _border;
8810
9036
  _borderStyle;
8811
9037
  _borderColor;
@@ -8817,7 +9043,7 @@ class BoxRenderable extends Renderable {
8817
9043
  _titleAlignment;
8818
9044
  constructor(id, options) {
8819
9045
  super(id, options);
8820
- this._bg = parseColor(options.bg || "transparent");
9046
+ this._backgroundColor = parseColor(options.backgroundColor || "transparent");
8821
9047
  this._border = options.border ?? true;
8822
9048
  this._borderStyle = options.borderStyle || "single";
8823
9049
  this._borderColor = parseColor(options.borderColor || "#FFFFFF");
@@ -8829,14 +9055,14 @@ class BoxRenderable extends Renderable {
8829
9055
  this._titleAlignment = options.titleAlignment || "left";
8830
9056
  this.applyYogaBorders();
8831
9057
  }
8832
- get bg() {
8833
- return this._bg;
9058
+ get backgroundColor() {
9059
+ return this._backgroundColor;
8834
9060
  }
8835
- set bg(value) {
9061
+ set backgroundColor(value) {
8836
9062
  if (value) {
8837
9063
  const newColor = parseColor(value);
8838
- if (this._bg !== newColor) {
8839
- this._bg = newColor;
9064
+ if (this._backgroundColor !== newColor) {
9065
+ this._backgroundColor = newColor;
8840
9066
  this.needsUpdate();
8841
9067
  }
8842
9068
  }
@@ -8913,7 +9139,7 @@ class BoxRenderable extends Renderable {
8913
9139
  customBorderChars: this.customBorderChars,
8914
9140
  border: this._border,
8915
9141
  borderColor: currentBorderColor,
8916
- backgroundColor: this._bg,
9142
+ backgroundColor: this._backgroundColor,
8917
9143
  shouldFill: this.shouldFill,
8918
9144
  title: this._title,
8919
9145
  titleAlignment: this._titleAlignment
@@ -8953,7 +9179,7 @@ class FrameBufferRenderable extends Renderable {
8953
9179
  buffer.drawFrameBuffer(this.x, this.y, this.frameBuffer);
8954
9180
  }
8955
9181
  destroySelf() {
8956
- this.frameBuffer.destroy();
9182
+ this.frameBuffer?.destroy();
8957
9183
  super.destroySelf();
8958
9184
  }
8959
9185
  }
@@ -8966,7 +9192,7 @@ class GroupRenderable extends Renderable {
8966
9192
  // src/renderables/Text.ts
8967
9193
  class TextRenderable extends Renderable {
8968
9194
  selectable = true;
8969
- _text;
9195
+ _text = stringToStyledText("");
8970
9196
  _defaultFg;
8971
9197
  _defaultBg;
8972
9198
  _defaultAttributes;
@@ -8979,7 +9205,9 @@ class TextRenderable extends Renderable {
8979
9205
  constructor(id, options) {
8980
9206
  super(id, options);
8981
9207
  this.selectionHelper = new TextSelectionHelper(() => this.x, () => this.y, () => this._plainText.length, () => this._lineInfo);
8982
- this._text = typeof options.content === "string" ? stringToStyledText(options.content) : options.content;
9208
+ if (options.content) {
9209
+ this._text = typeof options.content === "string" ? stringToStyledText(options.content) : options.content;
9210
+ }
8983
9211
  this._defaultFg = options.fg ? parseColor(options.fg) : RGBA.fromValues(1, 1, 1, 1);
8984
9212
  this._defaultBg = options.bg ? parseColor(options.bg) : RGBA.fromValues(0, 0, 0, 0);
8985
9213
  this._defaultAttributes = options.attributes ?? 0;
@@ -9141,14 +9369,15 @@ class ASCIIFontRenderable extends FrameBufferRenderable {
9141
9369
  selectionHelper;
9142
9370
  constructor(id, options) {
9143
9371
  const font = options.font || "tiny";
9144
- const measurements = measureText({ text: options.text, font });
9372
+ const text = options.text || "";
9373
+ const measurements = measureText({ text, font });
9145
9374
  super(id, {
9146
9375
  ...options,
9147
- width: measurements.width,
9148
- height: measurements.height,
9376
+ width: measurements.width || 1,
9377
+ height: measurements.height || 1,
9149
9378
  respectAlpha: true
9150
9379
  });
9151
- this._text = options.text;
9380
+ this._text = text;
9152
9381
  this._font = font;
9153
9382
  this._fg = Array.isArray(options.fg) ? options.fg : [options.fg || RGBA.fromInts(255, 255, 255, 255)];
9154
9383
  this._bg = options.bg || RGBA.fromValues(0, 0, 0, 0);
@@ -9276,30 +9505,30 @@ var InputRenderableEvents;
9276
9505
 
9277
9506
  class InputRenderable extends Renderable {
9278
9507
  focusable = true;
9279
- value = "";
9280
- cursorPosition = 0;
9281
- placeholder;
9282
- backgroundColor;
9283
- textColor;
9284
- focusedBackgroundColor;
9285
- focusedTextColor;
9286
- placeholderColor;
9287
- cursorColor;
9288
- maxLength;
9289
- lastCommittedValue = "";
9508
+ _value = "";
9509
+ _cursorPosition = 0;
9510
+ _placeholder;
9511
+ _backgroundColor;
9512
+ _textColor;
9513
+ _focusedBackgroundColor;
9514
+ _focusedTextColor;
9515
+ _placeholderColor;
9516
+ _cursorColor;
9517
+ _maxLength;
9518
+ _lastCommittedValue = "";
9290
9519
  constructor(id, options) {
9291
9520
  super(id, { ...options, buffered: true });
9292
- this.backgroundColor = parseColor(options.backgroundColor || "transparent");
9293
- this.textColor = parseColor(options.textColor || "#FFFFFF");
9294
- this.focusedBackgroundColor = parseColor(options.focusedBackgroundColor || options.backgroundColor || "#1a1a1a");
9295
- this.focusedTextColor = parseColor(options.focusedTextColor || options.textColor || "#FFFFFF");
9296
- this.placeholder = options.placeholder || "";
9297
- this.value = options.value || "";
9298
- this.lastCommittedValue = this.value;
9299
- this.cursorPosition = this.value.length;
9300
- this.maxLength = options.maxLength || 1000;
9301
- this.placeholderColor = parseColor(options.placeholderColor || "#666666");
9302
- this.cursorColor = parseColor(options.cursorColor || "#FFFFFF");
9521
+ this._backgroundColor = parseColor(options.backgroundColor || "transparent");
9522
+ this._textColor = parseColor(options.textColor || "#FFFFFF");
9523
+ this._focusedBackgroundColor = parseColor(options.focusedBackgroundColor || options.backgroundColor || "#1a1a1a");
9524
+ this._focusedTextColor = parseColor(options.focusedTextColor || options.textColor || "#FFFFFF");
9525
+ this._placeholder = options.placeholder || "";
9526
+ this._value = options.value || "";
9527
+ this._lastCommittedValue = this._value;
9528
+ this._cursorPosition = this._value.length;
9529
+ this._maxLength = options.maxLength || 1000;
9530
+ this._placeholderColor = parseColor(options.placeholderColor || "#666666");
9531
+ this._cursorColor = parseColor(options.cursorColor || "#FFFFFF");
9303
9532
  }
9304
9533
  updateCursorPosition() {
9305
9534
  if (!this._focused)
@@ -9309,28 +9538,28 @@ class InputRenderable extends Renderable {
9309
9538
  const contentWidth = this.width;
9310
9539
  const maxVisibleChars = contentWidth - 1;
9311
9540
  let displayStartIndex = 0;
9312
- if (this.cursorPosition >= maxVisibleChars) {
9313
- displayStartIndex = this.cursorPosition - maxVisibleChars + 1;
9541
+ if (this._cursorPosition >= maxVisibleChars) {
9542
+ displayStartIndex = this._cursorPosition - maxVisibleChars + 1;
9314
9543
  }
9315
- const cursorDisplayX = this.cursorPosition - displayStartIndex;
9544
+ const cursorDisplayX = this._cursorPosition - displayStartIndex;
9316
9545
  if (cursorDisplayX >= 0 && cursorDisplayX < contentWidth) {
9317
9546
  const absoluteCursorX = this.x + contentX + cursorDisplayX + 1;
9318
9547
  const absoluteCursorY = this.y + contentY + 1;
9319
9548
  CliRenderer.setCursorPosition(absoluteCursorX, absoluteCursorY, true);
9320
- CliRenderer.setCursorColor(this.cursorColor);
9549
+ CliRenderer.setCursorColor(this._cursorColor);
9321
9550
  }
9322
9551
  }
9323
9552
  focus() {
9324
9553
  super.focus();
9325
- CliRenderer.setCursorStyle("block", true, this.cursorColor);
9554
+ CliRenderer.setCursorStyle("block", true, this._cursorColor);
9326
9555
  this.updateCursorPosition();
9327
9556
  }
9328
9557
  blur() {
9329
9558
  super.blur();
9330
9559
  CliRenderer.setCursorPosition(0, 0, false);
9331
- if (this.value !== this.lastCommittedValue) {
9332
- this.lastCommittedValue = this.value;
9333
- this.emit("change" /* CHANGE */, this.value);
9560
+ if (this._value !== this._lastCommittedValue) {
9561
+ this._lastCommittedValue = this._value;
9562
+ this.emit("change" /* CHANGE */, this._value);
9334
9563
  }
9335
9564
  }
9336
9565
  renderSelf(buffer, deltaTime) {
@@ -9343,20 +9572,20 @@ class InputRenderable extends Renderable {
9343
9572
  refreshFrameBuffer() {
9344
9573
  if (!this.frameBuffer)
9345
9574
  return;
9346
- const bgColor = this._focused ? this.focusedBackgroundColor : this.backgroundColor;
9575
+ const bgColor = this._focused ? this._focusedBackgroundColor : this._backgroundColor;
9347
9576
  this.frameBuffer.clear(bgColor);
9348
9577
  const contentX = 0;
9349
9578
  const contentY = 0;
9350
9579
  const contentWidth = this.width;
9351
9580
  const contentHeight = this.height;
9352
- const displayText = this.value || this.placeholder;
9353
- const isPlaceholder = !this.value && this.placeholder;
9354
- const baseTextColor = this._focused ? this.focusedTextColor : this.textColor;
9355
- const textColor = isPlaceholder ? this.placeholderColor : baseTextColor;
9581
+ const displayText = this._value || this._placeholder;
9582
+ const isPlaceholder = !this._value && this._placeholder;
9583
+ const baseTextColor = this._focused ? this._focusedTextColor : this._textColor;
9584
+ const textColor = isPlaceholder ? this._placeholderColor : baseTextColor;
9356
9585
  const maxVisibleChars = contentWidth - 1;
9357
9586
  let displayStartIndex = 0;
9358
- if (this.cursorPosition >= maxVisibleChars) {
9359
- displayStartIndex = this.cursorPosition - maxVisibleChars + 1;
9587
+ if (this._cursorPosition >= maxVisibleChars) {
9588
+ displayStartIndex = this._cursorPosition - maxVisibleChars + 1;
9360
9589
  }
9361
9590
  const visibleText = displayText.substring(displayStartIndex, displayStartIndex + maxVisibleChars);
9362
9591
  if (visibleText) {
@@ -9366,67 +9595,61 @@ class InputRenderable extends Renderable {
9366
9595
  this.updateCursorPosition();
9367
9596
  }
9368
9597
  }
9369
- setValue(value) {
9370
- const newValue = value.substring(0, this.maxLength);
9371
- if (this.value !== newValue) {
9372
- this.value = newValue;
9373
- this.cursorPosition = Math.min(this.cursorPosition, this.value.length);
9598
+ get value() {
9599
+ return this._value;
9600
+ }
9601
+ set value(value) {
9602
+ const newValue = value.substring(0, this._maxLength);
9603
+ if (this._value !== newValue) {
9604
+ this._value = newValue;
9605
+ this._cursorPosition = Math.min(this._cursorPosition, this._value.length);
9374
9606
  this.needsUpdate();
9375
9607
  this.updateCursorPosition();
9376
- this.emit("input" /* INPUT */, this.value);
9608
+ this.emit("input" /* INPUT */, this._value);
9377
9609
  }
9378
9610
  }
9379
- getValue() {
9380
- return this.value;
9381
- }
9382
- getPlaceholder() {
9383
- return this.placeholder;
9384
- }
9385
- setPlaceholder(placeholder) {
9386
- if (this.placeholder !== placeholder) {
9387
- this.placeholder = placeholder;
9611
+ set placeholder(placeholder) {
9612
+ if (this._placeholder !== placeholder) {
9613
+ this._placeholder = placeholder;
9388
9614
  this.needsUpdate();
9389
9615
  }
9390
9616
  }
9391
- getCursorPosition() {
9392
- return this.cursorPosition;
9393
- }
9394
- setCursorPosition(position) {
9395
- const newPosition = Math.max(0, Math.min(position, this.value.length));
9396
- if (this.cursorPosition !== newPosition) {
9397
- this.cursorPosition = newPosition;
9617
+ set cursorPosition(position) {
9618
+ const newPosition = Math.max(0, Math.min(position, this._value.length));
9619
+ if (this._cursorPosition !== newPosition) {
9620
+ this._cursorPosition = newPosition;
9398
9621
  this.needsUpdate();
9399
9622
  this.updateCursorPosition();
9400
9623
  }
9401
9624
  }
9402
9625
  insertText(text) {
9403
- if (this.value.length + text.length > this.maxLength) {
9626
+ if (this._value.length + text.length > this._maxLength) {
9404
9627
  return;
9405
9628
  }
9406
- const beforeCursor = this.value.substring(0, this.cursorPosition);
9407
- const afterCursor = this.value.substring(this.cursorPosition);
9408
- this.value = beforeCursor + text + afterCursor;
9409
- this.cursorPosition += text.length;
9629
+ const beforeCursor = this._value.substring(0, this._cursorPosition);
9630
+ const afterCursor = this._value.substring(this._cursorPosition);
9631
+ this._value = beforeCursor + text + afterCursor;
9632
+ this._cursorPosition += text.length;
9410
9633
  this.needsUpdate();
9411
9634
  this.updateCursorPosition();
9412
- this.emit("input" /* INPUT */, this.value);
9635
+ this.emit("input" /* INPUT */, this._value);
9413
9636
  }
9414
9637
  deleteCharacter(direction) {
9415
- if (direction === "backward" && this.cursorPosition > 0) {
9416
- const beforeCursor = this.value.substring(0, this.cursorPosition - 1);
9417
- const afterCursor = this.value.substring(this.cursorPosition);
9418
- this.value = beforeCursor + afterCursor;
9419
- this.cursorPosition--;
9638
+ if (direction === "backward" && this._cursorPosition > 0) {
9639
+ const beforeCursor = this._value.substring(0, this._cursorPosition - 1);
9640
+ const afterCursor = this._value.substring(this._cursorPosition);
9641
+ this._value = beforeCursor + afterCursor;
9642
+ this._cursorPosition--;
9420
9643
  this.needsUpdate();
9421
9644
  this.updateCursorPosition();
9422
- this.emit("input" /* INPUT */, this.value);
9423
- } else if (direction === "forward" && this.cursorPosition < this.value.length) {
9424
- const beforeCursor = this.value.substring(0, this.cursorPosition);
9425
- const afterCursor = this.value.substring(this.cursorPosition + 1);
9426
- this.value = beforeCursor + afterCursor;
9645
+ this.emit("input" /* INPUT */, this._value);
9646
+ } else if (direction === "forward" && this._cursorPosition < this._value.length) {
9647
+ const beforeCursor = this._value.substring(0, this._cursorPosition);
9648
+ const afterCursor = this._value.substring(this._cursorPosition + 1);
9649
+ this._value = beforeCursor + afterCursor;
9427
9650
  this.needsUpdate();
9428
9651
  this.updateCursorPosition();
9429
- this.emit("input" /* INPUT */, this.value);
9652
+ this.emit("input" /* INPUT */, this._value);
9430
9653
  }
9431
9654
  }
9432
9655
  handleKeyPress(key) {
@@ -9434,16 +9657,16 @@ class InputRenderable extends Renderable {
9434
9657
  const keySequence = typeof key === "string" ? key : key.sequence;
9435
9658
  switch (keyName2) {
9436
9659
  case "left":
9437
- this.setCursorPosition(this.cursorPosition - 1);
9660
+ this.cursorPosition = this._cursorPosition - 1;
9438
9661
  return true;
9439
9662
  case "right":
9440
- this.setCursorPosition(this.cursorPosition + 1);
9663
+ this.cursorPosition = this._cursorPosition + 1;
9441
9664
  return true;
9442
9665
  case "home":
9443
- this.setCursorPosition(0);
9666
+ this.cursorPosition = 0;
9444
9667
  return true;
9445
9668
  case "end":
9446
- this.setCursorPosition(this.value.length);
9669
+ this.cursorPosition = this._value.length;
9447
9670
  return true;
9448
9671
  case "backspace":
9449
9672
  this.deleteCharacter("backward");
@@ -9453,11 +9676,11 @@ class InputRenderable extends Renderable {
9453
9676
  return true;
9454
9677
  case "return":
9455
9678
  case "enter":
9456
- if (this.value !== this.lastCommittedValue) {
9457
- this.lastCommittedValue = this.value;
9458
- this.emit("change" /* CHANGE */, this.value);
9679
+ if (this._value !== this._lastCommittedValue) {
9680
+ this._lastCommittedValue = this._value;
9681
+ this.emit("change" /* CHANGE */, this._value);
9459
9682
  }
9460
- this.emit("enter" /* ENTER */, this.value);
9683
+ this.emit("enter" /* ENTER */, this._value);
9461
9684
  return true;
9462
9685
  default:
9463
9686
  if (keySequence && keySequence.length === 1 && keySequence.charCodeAt(0) >= 32 && keySequence.charCodeAt(0) <= 126) {
@@ -9468,15 +9691,37 @@ class InputRenderable extends Renderable {
9468
9691
  }
9469
9692
  return false;
9470
9693
  }
9471
- getMaxLength() {
9472
- return this.maxLength;
9473
- }
9474
- setMaxLength(maxLength) {
9475
- this.maxLength = maxLength;
9476
- if (this.value.length > maxLength) {
9477
- this.setValue(this.value.substring(0, maxLength));
9694
+ set maxLength(maxLength) {
9695
+ this._maxLength = maxLength;
9696
+ if (this._value.length > maxLength) {
9697
+ this._value = this._value.substring(0, maxLength);
9698
+ this.needsUpdate();
9478
9699
  }
9479
9700
  }
9701
+ set backgroundColor(color) {
9702
+ this._backgroundColor = parseColor(color);
9703
+ this.needsUpdate();
9704
+ }
9705
+ set textColor(color) {
9706
+ this._textColor = parseColor(color);
9707
+ this.needsUpdate();
9708
+ }
9709
+ set focusedBackgroundColor(color) {
9710
+ this._focusedBackgroundColor = parseColor(color);
9711
+ this.needsUpdate();
9712
+ }
9713
+ set focusedTextColor(color) {
9714
+ this._focusedTextColor = parseColor(color);
9715
+ this.needsUpdate();
9716
+ }
9717
+ set placeholderColor(color) {
9718
+ this._placeholderColor = parseColor(color);
9719
+ this.needsUpdate();
9720
+ }
9721
+ set cursorColor(color) {
9722
+ this._cursorColor = parseColor(color);
9723
+ this.needsUpdate();
9724
+ }
9480
9725
  destroySelf() {
9481
9726
  if (this._focused) {
9482
9727
  CliRenderer.setCursorPosition(0, 0, false);
@@ -9493,47 +9738,47 @@ var SelectRenderableEvents;
9493
9738
 
9494
9739
  class SelectRenderable extends Renderable {
9495
9740
  focusable = true;
9496
- options;
9741
+ _options = [];
9497
9742
  selectedIndex = 0;
9498
9743
  scrollOffset = 0;
9499
9744
  maxVisibleItems;
9500
- backgroundColor;
9501
- textColor;
9502
- focusedBackgroundColor;
9503
- focusedTextColor;
9504
- selectedBackgroundColor;
9505
- selectedTextColor;
9506
- descriptionColor;
9507
- selectedDescriptionColor;
9508
- showScrollIndicator;
9509
- wrapSelection;
9510
- showDescription;
9511
- font;
9512
- itemSpacing;
9745
+ _backgroundColor;
9746
+ _textColor;
9747
+ _focusedBackgroundColor;
9748
+ _focusedTextColor;
9749
+ _selectedBackgroundColor;
9750
+ _selectedTextColor;
9751
+ _descriptionColor;
9752
+ _selectedDescriptionColor;
9753
+ _showScrollIndicator;
9754
+ _wrapSelection;
9755
+ _showDescription;
9756
+ _font;
9757
+ _itemSpacing;
9513
9758
  linesPerItem;
9514
9759
  fontHeight;
9515
- fastScrollStep;
9760
+ _fastScrollStep;
9516
9761
  constructor(id, options) {
9517
9762
  super(id, { ...options, buffered: true });
9518
- this.backgroundColor = parseColor(options.backgroundColor || "transparent");
9519
- this.textColor = parseColor(options.textColor || "#FFFFFF");
9520
- this.focusedBackgroundColor = parseColor(options.focusedBackgroundColor || options.backgroundColor || "#1a1a1a");
9521
- this.focusedTextColor = parseColor(options.focusedTextColor || options.textColor || "#FFFFFF");
9522
- this.options = options.options || [];
9523
- this.showScrollIndicator = options.showScrollIndicator ?? false;
9524
- this.wrapSelection = options.wrapSelection ?? false;
9525
- this.showDescription = options.showDescription ?? true;
9526
- this.font = options.font;
9527
- this.itemSpacing = options.itemSpacing || 0;
9528
- this.fontHeight = this.font ? measureText({ text: "A", font: this.font }).height : 1;
9529
- this.linesPerItem = this.showDescription ? this.font ? this.fontHeight + 1 : 2 : this.font ? this.fontHeight : 1;
9530
- this.linesPerItem += this.itemSpacing;
9763
+ this._backgroundColor = parseColor(options.backgroundColor || "transparent");
9764
+ this._textColor = parseColor(options.textColor || "#FFFFFF");
9765
+ this._focusedBackgroundColor = parseColor(options.focusedBackgroundColor || options.backgroundColor || "#1a1a1a");
9766
+ this._focusedTextColor = parseColor(options.focusedTextColor || options.textColor || "#FFFFFF");
9767
+ this._options = options.options || [];
9768
+ this._showScrollIndicator = options.showScrollIndicator ?? false;
9769
+ this._wrapSelection = options.wrapSelection ?? false;
9770
+ this._showDescription = options.showDescription ?? true;
9771
+ this._font = options.font;
9772
+ this._itemSpacing = options.itemSpacing || 0;
9773
+ this.fontHeight = this._font ? measureText({ text: "A", font: this._font }).height : 1;
9774
+ this.linesPerItem = this._showDescription ? this._font ? this.fontHeight + 1 : 2 : this._font ? this.fontHeight : 1;
9775
+ this.linesPerItem += this._itemSpacing;
9531
9776
  this.maxVisibleItems = Math.max(1, Math.floor(this.height / this.linesPerItem));
9532
- this.selectedBackgroundColor = parseColor(options.selectedBackgroundColor || "#334455");
9533
- this.selectedTextColor = parseColor(options.selectedTextColor || "#FFFF00");
9534
- this.descriptionColor = parseColor(options.descriptionColor || "#888888");
9535
- this.selectedDescriptionColor = parseColor(options.selectedDescriptionColor || "#CCCCCC");
9536
- this.fastScrollStep = options.fastScrollStep || 5;
9777
+ this._selectedBackgroundColor = parseColor(options.selectedBackgroundColor || "#334455");
9778
+ this._selectedTextColor = parseColor(options.selectedTextColor || "#FFFF00");
9779
+ this._descriptionColor = parseColor(options.descriptionColor || "#888888");
9780
+ this._selectedDescriptionColor = parseColor(options.selectedDescriptionColor || "#CCCCCC");
9781
+ this._fastScrollStep = options.fastScrollStep || 5;
9537
9782
  this.needsUpdate();
9538
9783
  }
9539
9784
  renderSelf(buffer, deltaTime) {
@@ -9544,15 +9789,15 @@ class SelectRenderable extends Renderable {
9544
9789
  }
9545
9790
  }
9546
9791
  refreshFrameBuffer() {
9547
- if (!this.frameBuffer || this.options.length === 0)
9792
+ if (!this.frameBuffer || this._options.length === 0)
9548
9793
  return;
9549
- const bgColor = this._focused ? this.focusedBackgroundColor : this.backgroundColor;
9794
+ const bgColor = this._focused ? this._focusedBackgroundColor : this._backgroundColor;
9550
9795
  this.frameBuffer.clear(bgColor);
9551
9796
  const contentX = 0;
9552
9797
  const contentY = 0;
9553
9798
  const contentWidth = this.width;
9554
9799
  const contentHeight = this.height;
9555
- const visibleOptions = this.options.slice(this.scrollOffset, this.scrollOffset + this.maxVisibleItems);
9800
+ const visibleOptions = this._options.slice(this.scrollOffset, this.scrollOffset + this.maxVisibleItems);
9556
9801
  for (let i = 0;i < visibleOptions.length; i++) {
9557
9802
  const actualIndex = this.scrollOffset + i;
9558
9803
  const option = visibleOptions[i];
@@ -9561,14 +9806,14 @@ class SelectRenderable extends Renderable {
9561
9806
  if (itemY + this.linesPerItem - 1 >= contentY + contentHeight)
9562
9807
  break;
9563
9808
  if (isSelected) {
9564
- const contentHeight2 = this.linesPerItem - this.itemSpacing;
9565
- this.frameBuffer.fillRect(contentX, itemY, contentWidth, contentHeight2, this.selectedBackgroundColor);
9809
+ const contentHeight2 = this.linesPerItem - this._itemSpacing;
9810
+ this.frameBuffer.fillRect(contentX, itemY, contentWidth, contentHeight2, this._selectedBackgroundColor);
9566
9811
  }
9567
9812
  const nameContent = `${isSelected ? "\u25B6 " : " "}${option.name}`;
9568
- const baseTextColor = this._focused ? this.focusedTextColor : this.textColor;
9569
- const nameColor = isSelected ? this.selectedTextColor : baseTextColor;
9813
+ const baseTextColor = this._focused ? this._focusedTextColor : this._textColor;
9814
+ const nameColor = isSelected ? this._selectedTextColor : baseTextColor;
9570
9815
  let descX = contentX + 3;
9571
- if (this.font) {
9816
+ if (this._font) {
9572
9817
  const indicator = isSelected ? "\u25B6 " : " ";
9573
9818
  this.frameBuffer.drawText(indicator, contentX + 1, itemY, nameColor);
9574
9819
  const indicatorWidth = 2;
@@ -9577,40 +9822,43 @@ class SelectRenderable extends Renderable {
9577
9822
  x: contentX + 1 + indicatorWidth,
9578
9823
  y: itemY,
9579
9824
  fg: nameColor,
9580
- bg: isSelected ? this.selectedBackgroundColor : bgColor,
9581
- font: this.font
9825
+ bg: isSelected ? this._selectedBackgroundColor : bgColor,
9826
+ font: this._font
9582
9827
  });
9583
9828
  descX = contentX + 1 + indicatorWidth;
9584
9829
  } else {
9585
9830
  this.frameBuffer.drawText(nameContent, contentX + 1, itemY, nameColor);
9586
9831
  }
9587
- if (this.showDescription && itemY + this.fontHeight < contentY + contentHeight) {
9588
- const descColor = isSelected ? this.selectedDescriptionColor : this.descriptionColor;
9589
- const descBg = this._focused ? this.focusedBackgroundColor : this.backgroundColor;
9832
+ if (this._showDescription && itemY + this.fontHeight < contentY + contentHeight) {
9833
+ const descColor = isSelected ? this._selectedDescriptionColor : this._descriptionColor;
9834
+ const descBg = this._focused ? this._focusedBackgroundColor : this._backgroundColor;
9590
9835
  this.frameBuffer.drawText(option.description, descX, itemY + this.fontHeight, descColor);
9591
9836
  }
9592
9837
  }
9593
- if (this.showScrollIndicator && this.options.length > this.maxVisibleItems) {
9838
+ if (this._showScrollIndicator && this._options.length > this.maxVisibleItems) {
9594
9839
  this.renderScrollIndicatorToFrameBuffer(contentX, contentY, contentWidth, contentHeight);
9595
9840
  }
9596
9841
  }
9597
9842
  renderScrollIndicatorToFrameBuffer(contentX, contentY, contentWidth, contentHeight) {
9598
9843
  if (!this.frameBuffer)
9599
9844
  return;
9600
- const scrollPercent = this.selectedIndex / Math.max(1, this.options.length - 1);
9845
+ const scrollPercent = this.selectedIndex / Math.max(1, this._options.length - 1);
9601
9846
  const indicatorHeight = Math.max(1, contentHeight - 2);
9602
9847
  const indicatorY = contentY + 1 + Math.floor(scrollPercent * indicatorHeight);
9603
9848
  const indicatorX = contentX + contentWidth - 1;
9604
9849
  this.frameBuffer.drawText("\u2588", indicatorX, indicatorY, parseColor("#666666"));
9605
9850
  }
9606
- setOptions(options) {
9607
- this.options = options;
9851
+ get options() {
9852
+ return this._options;
9853
+ }
9854
+ set options(options) {
9855
+ this._options = options;
9608
9856
  this.selectedIndex = Math.min(this.selectedIndex, Math.max(0, options.length - 1));
9609
9857
  this.updateScrollOffset();
9610
9858
  this.needsUpdate();
9611
9859
  }
9612
9860
  getSelectedOption() {
9613
- return this.options[this.selectedIndex] || null;
9861
+ return this._options[this.selectedIndex] || null;
9614
9862
  }
9615
9863
  getSelectedIndex() {
9616
9864
  return this.selectedIndex;
@@ -9619,8 +9867,8 @@ class SelectRenderable extends Renderable {
9619
9867
  const newIndex = this.selectedIndex - steps;
9620
9868
  if (newIndex >= 0) {
9621
9869
  this.selectedIndex = newIndex;
9622
- } else if (this.wrapSelection && this.options.length > 0) {
9623
- this.selectedIndex = this.options.length - 1;
9870
+ } else if (this._wrapSelection && this._options.length > 0) {
9871
+ this.selectedIndex = this._options.length - 1;
9624
9872
  } else {
9625
9873
  this.selectedIndex = 0;
9626
9874
  }
@@ -9630,12 +9878,12 @@ class SelectRenderable extends Renderable {
9630
9878
  }
9631
9879
  moveDown(steps = 1) {
9632
9880
  const newIndex = this.selectedIndex + steps;
9633
- if (newIndex < this.options.length) {
9881
+ if (newIndex < this._options.length) {
9634
9882
  this.selectedIndex = newIndex;
9635
- } else if (this.wrapSelection && this.options.length > 0) {
9883
+ } else if (this._wrapSelection && this._options.length > 0) {
9636
9884
  this.selectedIndex = 0;
9637
9885
  } else {
9638
- this.selectedIndex = this.options.length - 1;
9886
+ this.selectedIndex = this._options.length - 1;
9639
9887
  }
9640
9888
  this.updateScrollOffset();
9641
9889
  this.needsUpdate();
@@ -9648,7 +9896,7 @@ class SelectRenderable extends Renderable {
9648
9896
  }
9649
9897
  }
9650
9898
  setSelectedIndex(index) {
9651
- if (index >= 0 && index < this.options.length) {
9899
+ if (index >= 0 && index < this._options.length) {
9652
9900
  this.selectedIndex = index;
9653
9901
  this.updateScrollOffset();
9654
9902
  this.needsUpdate();
@@ -9656,10 +9904,10 @@ class SelectRenderable extends Renderable {
9656
9904
  }
9657
9905
  }
9658
9906
  updateScrollOffset() {
9659
- if (!this.options)
9907
+ if (!this._options)
9660
9908
  return;
9661
9909
  const halfVisible = Math.floor(this.maxVisibleItems / 2);
9662
- const newScrollOffset = Math.max(0, Math.min(this.selectedIndex - halfVisible, this.options.length - this.maxVisibleItems));
9910
+ const newScrollOffset = Math.max(0, Math.min(this.selectedIndex - halfVisible, this._options.length - this.maxVisibleItems));
9663
9911
  if (newScrollOffset !== this.scrollOffset) {
9664
9912
  this.scrollOffset = newScrollOffset;
9665
9913
  this.needsUpdate();
@@ -9676,11 +9924,11 @@ class SelectRenderable extends Renderable {
9676
9924
  switch (keyName2) {
9677
9925
  case "up":
9678
9926
  case "k":
9679
- this.moveUp(isShift ? this.fastScrollStep : 1);
9927
+ this.moveUp(isShift ? this._fastScrollStep : 1);
9680
9928
  return true;
9681
9929
  case "down":
9682
9930
  case "j":
9683
- this.moveDown(isShift ? this.fastScrollStep : 1);
9931
+ this.moveDown(isShift ? this._fastScrollStep : 1);
9684
9932
  return true;
9685
9933
  case "return":
9686
9934
  case "enter":
@@ -9689,31 +9937,83 @@ class SelectRenderable extends Renderable {
9689
9937
  }
9690
9938
  return false;
9691
9939
  }
9692
- getShowScrollIndicator() {
9693
- return this.showScrollIndicator;
9940
+ get showScrollIndicator() {
9941
+ return this._showScrollIndicator;
9694
9942
  }
9695
- setShowScrollIndicator(show) {
9696
- this.showScrollIndicator = show;
9943
+ set showScrollIndicator(show) {
9944
+ this._showScrollIndicator = show;
9697
9945
  this.needsUpdate();
9698
9946
  }
9699
- getShowDescription() {
9700
- return this.showDescription;
9947
+ get showDescription() {
9948
+ return this._showDescription;
9701
9949
  }
9702
- setShowDescription(show) {
9703
- if (this.showDescription !== show) {
9704
- this.showDescription = show;
9705
- this.linesPerItem = this.showDescription ? this.font ? this.fontHeight + 1 : 2 : this.font ? this.fontHeight : 1;
9706
- this.linesPerItem += this.itemSpacing;
9950
+ set showDescription(show) {
9951
+ if (this._showDescription !== show) {
9952
+ this._showDescription = show;
9953
+ this.linesPerItem = this._showDescription ? this._font ? this.fontHeight + 1 : 2 : this._font ? this.fontHeight : 1;
9954
+ this.linesPerItem += this._itemSpacing;
9707
9955
  this.maxVisibleItems = Math.max(1, Math.floor(this.height / this.linesPerItem));
9708
9956
  this.updateScrollOffset();
9709
9957
  this.needsUpdate();
9710
9958
  }
9711
9959
  }
9712
- getWrapSelection() {
9713
- return this.wrapSelection;
9960
+ get wrapSelection() {
9961
+ return this._wrapSelection;
9714
9962
  }
9715
- setWrapSelection(wrap) {
9716
- this.wrapSelection = wrap;
9963
+ set wrapSelection(wrap) {
9964
+ this._wrapSelection = wrap;
9965
+ }
9966
+ set backgroundColor(color) {
9967
+ this._backgroundColor = parseColor(color);
9968
+ this.needsUpdate();
9969
+ }
9970
+ set textColor(color) {
9971
+ this._textColor = parseColor(color);
9972
+ this.needsUpdate();
9973
+ }
9974
+ set focusedBackgroundColor(color) {
9975
+ this._focusedBackgroundColor = parseColor(color);
9976
+ this.needsUpdate();
9977
+ }
9978
+ set focusedTextColor(color) {
9979
+ this._focusedTextColor = parseColor(color);
9980
+ this.needsUpdate();
9981
+ }
9982
+ set selectedBackgroundColor(color) {
9983
+ this._selectedBackgroundColor = parseColor(color);
9984
+ this.needsUpdate();
9985
+ }
9986
+ set selectedTextColor(color) {
9987
+ this._selectedTextColor = parseColor(color);
9988
+ this.needsUpdate();
9989
+ }
9990
+ set descriptionColor(color) {
9991
+ this._descriptionColor = parseColor(color);
9992
+ this.needsUpdate();
9993
+ }
9994
+ set selectedDescriptionColor(color) {
9995
+ this._selectedDescriptionColor = parseColor(color);
9996
+ this.needsUpdate();
9997
+ }
9998
+ set font(font) {
9999
+ this._font = font;
10000
+ this.fontHeight = measureText({ text: "A", font: this._font }).height;
10001
+ this.linesPerItem = this._showDescription ? this._font ? this.fontHeight + 1 : 2 : this._font ? this.fontHeight : 1;
10002
+ this.linesPerItem += this._itemSpacing;
10003
+ this.maxVisibleItems = Math.max(1, Math.floor(this.height / this.linesPerItem));
10004
+ this.updateScrollOffset();
10005
+ this.needsUpdate();
10006
+ }
10007
+ set itemSpacing(spacing) {
10008
+ this._itemSpacing = spacing;
10009
+ this.linesPerItem = this._showDescription ? this._font ? this.fontHeight + 1 : 2 : this._font ? this.fontHeight : 1;
10010
+ this.linesPerItem += this._itemSpacing;
10011
+ this.maxVisibleItems = Math.max(1, Math.floor(this.height / this.linesPerItem));
10012
+ this.updateScrollOffset();
10013
+ this.needsUpdate();
10014
+ }
10015
+ set fastScrollStep(step) {
10016
+ this._fastScrollStep = step;
9717
10017
  }
9718
10018
  }
9719
10019
  // src/renderables/TabSelect.ts
@@ -9735,7 +10035,7 @@ function calculateDynamicHeight(showUnderline, showDescription) {
9735
10035
 
9736
10036
  class TabSelectRenderable extends Renderable {
9737
10037
  focusable = true;
9738
- options;
10038
+ options = [];
9739
10039
  selectedIndex = 0;
9740
10040
  scrollOffset = 0;
9741
10041
  tabWidth;
@@ -9976,8 +10276,10 @@ export {
9976
10276
  t,
9977
10277
  stringToStyledText,
9978
10278
  strikethrough,
10279
+ setRenderLibPath,
9979
10280
  rgbToHex,
9980
10281
  reverse,
10282
+ resolveRenderLib,
9981
10283
  renderFontToFrameBuffer,
9982
10284
  red,
9983
10285
  parseKeypress,
@@ -9987,6 +10289,12 @@ export {
9987
10289
  magenta,
9988
10290
  loadTemplate,
9989
10291
  italic,
10292
+ isSizeType,
10293
+ isPositionType,
10294
+ isPaddingType,
10295
+ isMarginType,
10296
+ isFlexBasisType,
10297
+ isDimensionType,
9990
10298
  hsvToRgb,
9991
10299
  hexToRgb,
9992
10300
  green,
@@ -10051,21 +10359,16 @@ export {
10051
10359
  RenderableEvents,
10052
10360
  Renderable,
10053
10361
  RGBA,
10054
- PositionType,
10055
10362
  OptimizedBuffer,
10056
10363
  MouseEvent,
10057
10364
  MouseButton,
10058
10365
  LayoutEvents,
10059
10366
  KeyHandler,
10060
- Justify,
10061
10367
  InputRenderableEvents,
10062
10368
  InputRenderable,
10063
10369
  GroupRenderable,
10064
10370
  FrameBufferRenderable,
10065
- FlexDirection,
10066
- Edge,
10067
10371
  DistortionEffect,
10068
- Direction,
10069
10372
  DebugOverlayCorner,
10070
10373
  CliRenderer,
10071
10374
  CliRenderEvents,
@@ -10075,7 +10378,6 @@ export {
10075
10378
  BorderCharArrays,
10076
10379
  BlurEffect,
10077
10380
  BloomEffect,
10078
- Align,
10079
10381
  ASCIIFontSelectionHelper,
10080
10382
  ASCIIFontRenderable
10081
10383
  };