@opentui/core 0.1.5 → 0.1.7

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
@@ -2046,6 +2046,18 @@ function parseJustify(value) {
2046
2046
  return Justify.FlexStart;
2047
2047
  }
2048
2048
  }
2049
+ function parsePositionType(value) {
2050
+ switch (value.toLowerCase()) {
2051
+ case "static":
2052
+ return PositionType.Static;
2053
+ case "relative":
2054
+ return PositionType.Relative;
2055
+ case "absolute":
2056
+ return PositionType.Absolute;
2057
+ default:
2058
+ return PositionType.Static;
2059
+ }
2060
+ }
2049
2061
 
2050
2062
  // src/Renderable.ts
2051
2063
  var LayoutEvents;
@@ -2368,8 +2380,8 @@ class Renderable extends EventEmitter3 {
2368
2380
  this.layoutNode.setHeight(options.height);
2369
2381
  }
2370
2382
  this._positionType = options.position ?? "relative";
2371
- if (this._positionType === "absolute") {
2372
- node.setPositionType(PositionType.Absolute);
2383
+ if (this._positionType !== "relative") {
2384
+ node.setPositionType(parsePositionType(this._positionType));
2373
2385
  }
2374
2386
  const hasPositionProps = options.top !== undefined || options.right !== undefined || options.bottom !== undefined || options.left !== undefined;
2375
2387
  if (hasPositionProps) {
@@ -2428,6 +2440,14 @@ class Renderable extends EventEmitter3 {
2428
2440
  node.setPadding(Edge.Left, options.paddingLeft);
2429
2441
  }
2430
2442
  }
2443
+ set position(positionType) {
2444
+ if (this._positionType === positionType)
2445
+ return;
2446
+ this._positionType = positionType;
2447
+ this.layoutNode.yogaNode.setPositionType(parsePositionType(positionType));
2448
+ this.needsUpdate();
2449
+ this._yogaPerformancePositionUpdated = true;
2450
+ }
2431
2451
  setPosition(position) {
2432
2452
  this._position = { ...this._position, ...position };
2433
2453
  this.updateYogaPosition(position);
@@ -3140,7 +3160,7 @@ function getOpenTUILib(libPath) {
3140
3160
  returns: "ptr"
3141
3161
  },
3142
3162
  destroyRenderer: {
3143
- args: ["ptr"],
3163
+ args: ["ptr", "bool", "u32"],
3144
3164
  returns: "void"
3145
3165
  },
3146
3166
  setUseThread: {
@@ -3295,6 +3315,14 @@ function getOpenTUILib(libPath) {
3295
3315
  args: ["ptr", "i64"],
3296
3316
  returns: "void"
3297
3317
  },
3318
+ enableMouse: {
3319
+ args: ["ptr", "bool"],
3320
+ returns: "void"
3321
+ },
3322
+ disableMouse: {
3323
+ args: ["ptr"],
3324
+ returns: "void"
3325
+ },
3298
3326
  createTextBuffer: {
3299
3327
  args: ["u32"],
3300
3328
  returns: "ptr"
@@ -3403,8 +3431,8 @@ class FFIRenderLib {
3403
3431
  createRenderer(width, height) {
3404
3432
  return this.opentui.symbols.createRenderer(width, height);
3405
3433
  }
3406
- destroyRenderer(renderer) {
3407
- this.opentui.symbols.destroyRenderer(renderer);
3434
+ destroyRenderer(renderer, useAlternateScreen, splitHeight) {
3435
+ this.opentui.symbols.destroyRenderer(renderer, useAlternateScreen, splitHeight);
3408
3436
  }
3409
3437
  setUseThread(renderer, useThread) {
3410
3438
  this.opentui.symbols.setUseThread(renderer, useThread);
@@ -3614,6 +3642,12 @@ class FFIRenderLib {
3614
3642
  const ts = timestamp ?? Date.now();
3615
3643
  this.opentui.symbols.dumpStdoutBuffer(renderer, ts);
3616
3644
  }
3645
+ enableMouse(renderer, enableMovement) {
3646
+ this.opentui.symbols.enableMouse(renderer, enableMovement);
3647
+ }
3648
+ disableMouse(renderer) {
3649
+ this.opentui.symbols.disableMouse(renderer);
3650
+ }
3617
3651
  createTextBuffer(capacity) {
3618
3652
  const bufferPtr = this.opentui.symbols.createTextBuffer(capacity);
3619
3653
  if (!bufferPtr) {
@@ -5472,6 +5506,306 @@ function renderFontToFrameBuffer(buffer, {
5472
5506
  height: fontDef.lines
5473
5507
  };
5474
5508
  }
5509
+ // src/lib/styled-text.ts
5510
+ var textEncoder = new TextEncoder;
5511
+
5512
+ class StyledText {
5513
+ chunks;
5514
+ _plainText = "";
5515
+ constructor(chunks) {
5516
+ this.chunks = chunks;
5517
+ for (let i = 0;i < chunks.length; i++) {
5518
+ this._plainText += chunks[i].plainText;
5519
+ }
5520
+ }
5521
+ toString() {
5522
+ return this._plainText;
5523
+ }
5524
+ _chunksToPlainText() {
5525
+ this._plainText = "";
5526
+ for (const chunk of this.chunks) {
5527
+ this._plainText += chunk.plainText;
5528
+ }
5529
+ }
5530
+ insert(chunk, index) {
5531
+ const originalLength = this.chunks.length;
5532
+ if (index === undefined) {
5533
+ this.chunks.push(chunk);
5534
+ } else {
5535
+ this.chunks.splice(index, 0, chunk);
5536
+ }
5537
+ if (index === undefined || index === originalLength) {
5538
+ this._plainText += chunk.plainText;
5539
+ } else {
5540
+ this._chunksToPlainText();
5541
+ }
5542
+ }
5543
+ remove(chunk) {
5544
+ const originalLength = this.chunks.length;
5545
+ const index = this.chunks.indexOf(chunk);
5546
+ if (index === -1)
5547
+ return;
5548
+ this.chunks.splice(index, 1);
5549
+ if (index === originalLength - 1) {
5550
+ this._plainText = this._plainText.slice(0, this._plainText.length - chunk.plainText.length);
5551
+ } else {
5552
+ this._chunksToPlainText();
5553
+ }
5554
+ }
5555
+ replace(chunk, oldChunk) {
5556
+ const index = this.chunks.indexOf(oldChunk);
5557
+ if (index === -1)
5558
+ return;
5559
+ this.chunks.splice(index, 1, chunk);
5560
+ if (index === this.chunks.length - 1) {
5561
+ this._plainText = this._plainText.slice(0, this._plainText.length - oldChunk.plainText.length) + chunk.plainText;
5562
+ } else {
5563
+ this._chunksToPlainText();
5564
+ }
5565
+ }
5566
+ }
5567
+ function stringToStyledText(content) {
5568
+ const textEncoder2 = new TextEncoder;
5569
+ const chunk = {
5570
+ __isChunk: true,
5571
+ text: textEncoder2.encode(content),
5572
+ plainText: content
5573
+ };
5574
+ return new StyledText([chunk]);
5575
+ }
5576
+ var templateCache = new WeakMap;
5577
+ function applyStyle(input, style) {
5578
+ if (typeof input === "object" && "__isChunk" in input) {
5579
+ const existingChunk = input;
5580
+ const fg = style.fg ? parseColor(style.fg) : existingChunk.fg;
5581
+ const bg = style.bg ? parseColor(style.bg) : existingChunk.bg;
5582
+ const newAttrs = createTextAttributes(style);
5583
+ const mergedAttrs = existingChunk.attributes ? existingChunk.attributes | newAttrs : newAttrs;
5584
+ return {
5585
+ __isChunk: true,
5586
+ text: existingChunk.text,
5587
+ plainText: existingChunk.plainText,
5588
+ fg,
5589
+ bg,
5590
+ attributes: mergedAttrs
5591
+ };
5592
+ } else {
5593
+ const plainTextStr = String(input);
5594
+ const text = textEncoder.encode(plainTextStr);
5595
+ const fg = style.fg ? parseColor(style.fg) : undefined;
5596
+ const bg = style.bg ? parseColor(style.bg) : undefined;
5597
+ const attributes = createTextAttributes(style);
5598
+ return {
5599
+ __isChunk: true,
5600
+ text,
5601
+ plainText: plainTextStr,
5602
+ fg,
5603
+ bg,
5604
+ attributes
5605
+ };
5606
+ }
5607
+ }
5608
+ var black = (input) => applyStyle(input, { fg: "black" });
5609
+ var red = (input) => applyStyle(input, { fg: "red" });
5610
+ var green = (input) => applyStyle(input, { fg: "green" });
5611
+ var yellow = (input) => applyStyle(input, { fg: "yellow" });
5612
+ var blue = (input) => applyStyle(input, { fg: "blue" });
5613
+ var magenta = (input) => applyStyle(input, { fg: "magenta" });
5614
+ var cyan = (input) => applyStyle(input, { fg: "cyan" });
5615
+ var white = (input) => applyStyle(input, { fg: "white" });
5616
+ var brightBlack = (input) => applyStyle(input, { fg: "brightBlack" });
5617
+ var brightRed = (input) => applyStyle(input, { fg: "brightRed" });
5618
+ var brightGreen = (input) => applyStyle(input, { fg: "brightGreen" });
5619
+ var brightYellow = (input) => applyStyle(input, { fg: "brightYellow" });
5620
+ var brightBlue = (input) => applyStyle(input, { fg: "brightBlue" });
5621
+ var brightMagenta = (input) => applyStyle(input, { fg: "brightMagenta" });
5622
+ var brightCyan = (input) => applyStyle(input, { fg: "brightCyan" });
5623
+ var brightWhite = (input) => applyStyle(input, { fg: "brightWhite" });
5624
+ var bgBlack = (input) => applyStyle(input, { bg: "black" });
5625
+ var bgRed = (input) => applyStyle(input, { bg: "red" });
5626
+ var bgGreen = (input) => applyStyle(input, { bg: "green" });
5627
+ var bgYellow = (input) => applyStyle(input, { bg: "yellow" });
5628
+ var bgBlue = (input) => applyStyle(input, { bg: "blue" });
5629
+ var bgMagenta = (input) => applyStyle(input, { bg: "magenta" });
5630
+ var bgCyan = (input) => applyStyle(input, { bg: "cyan" });
5631
+ var bgWhite = (input) => applyStyle(input, { bg: "white" });
5632
+ var bold = (input) => applyStyle(input, { bold: true });
5633
+ var italic = (input) => applyStyle(input, { italic: true });
5634
+ var underline = (input) => applyStyle(input, { underline: true });
5635
+ var strikethrough = (input) => applyStyle(input, { strikethrough: true });
5636
+ var dim = (input) => applyStyle(input, { dim: true });
5637
+ var reverse = (input) => applyStyle(input, { reverse: true });
5638
+ var blink = (input) => applyStyle(input, { blink: true });
5639
+ var fg = (color) => (input) => applyStyle(input, { fg: color });
5640
+ var bg = (color) => (input) => applyStyle(input, { bg: color });
5641
+ function tn(strings, ...values) {
5642
+ const chunks = [];
5643
+ let length = 0;
5644
+ let plainText = "";
5645
+ for (let i = 0;i < strings.length; i++) {
5646
+ const raw = strings[i];
5647
+ if (raw) {
5648
+ chunks.push({
5649
+ __isChunk: true,
5650
+ text: textEncoder.encode(raw),
5651
+ plainText: raw,
5652
+ attributes: 0
5653
+ });
5654
+ length += raw.length;
5655
+ plainText += raw;
5656
+ }
5657
+ const val = values[i];
5658
+ if (typeof val === "object" && "__isChunk" in val) {
5659
+ chunks.push(val);
5660
+ length += val.plainText.length;
5661
+ plainText += val.plainText;
5662
+ } else if (val !== undefined) {
5663
+ const plainTextStr = String(val);
5664
+ chunks.push({
5665
+ __isChunk: true,
5666
+ text: textEncoder.encode(plainTextStr),
5667
+ plainText: plainTextStr,
5668
+ attributes: 0
5669
+ });
5670
+ length += plainTextStr.length;
5671
+ plainText += plainTextStr;
5672
+ }
5673
+ }
5674
+ return new StyledText(chunks);
5675
+ }
5676
+ function t(strings, ...values) {
5677
+ let cachedStringChunks = templateCache.get(strings);
5678
+ let length = 0;
5679
+ let plainText = "";
5680
+ if (!cachedStringChunks) {
5681
+ cachedStringChunks = [];
5682
+ for (let i = 0;i < strings.length; i++) {
5683
+ const raw = strings[i];
5684
+ if (raw) {
5685
+ cachedStringChunks.push({
5686
+ __isChunk: true,
5687
+ text: textEncoder.encode(raw),
5688
+ plainText: raw,
5689
+ attributes: 0
5690
+ });
5691
+ } else {
5692
+ cachedStringChunks.push(null);
5693
+ }
5694
+ }
5695
+ templateCache.set(strings, cachedStringChunks);
5696
+ }
5697
+ const chunks = [];
5698
+ for (let i = 0;i < strings.length; i++) {
5699
+ const stringChunk = cachedStringChunks[i];
5700
+ if (stringChunk) {
5701
+ chunks.push(stringChunk);
5702
+ length += stringChunk.plainText.length;
5703
+ plainText += stringChunk.plainText;
5704
+ }
5705
+ const val = values[i];
5706
+ if (typeof val === "object" && "__isChunk" in val) {
5707
+ chunks.push(val);
5708
+ length += val.plainText.length;
5709
+ plainText += val.plainText;
5710
+ } else if (val !== undefined) {
5711
+ const plainTextStr = String(val);
5712
+ chunks.push({
5713
+ __isChunk: true,
5714
+ text: textEncoder.encode(plainTextStr),
5715
+ plainText: plainTextStr,
5716
+ attributes: 0
5717
+ });
5718
+ length += plainTextStr.length;
5719
+ plainText += plainTextStr;
5720
+ }
5721
+ }
5722
+ return new StyledText(chunks);
5723
+ }
5724
+
5725
+ // src/lib/hast-styled-text.ts
5726
+ class SyntaxStyle {
5727
+ styles;
5728
+ mergedStyleCache;
5729
+ constructor(styles) {
5730
+ this.styles = styles;
5731
+ this.mergedStyleCache = new Map;
5732
+ }
5733
+ mergeStyles(...styleNames) {
5734
+ const cacheKey = styleNames.join(":");
5735
+ const cached = this.mergedStyleCache.get(cacheKey);
5736
+ if (cached)
5737
+ return cached;
5738
+ const styleDefinition = {};
5739
+ for (const name of styleNames) {
5740
+ const style = this.styles[name];
5741
+ if (!style)
5742
+ continue;
5743
+ if (style.fg)
5744
+ styleDefinition.fg = style.fg;
5745
+ if (style.bg)
5746
+ styleDefinition.bg = style.bg;
5747
+ if (style.bold !== undefined)
5748
+ styleDefinition.bold = style.bold;
5749
+ if (style.italic !== undefined)
5750
+ styleDefinition.italic = style.italic;
5751
+ if (style.underline !== undefined)
5752
+ styleDefinition.underline = style.underline;
5753
+ if (style.dim !== undefined)
5754
+ styleDefinition.dim = style.dim;
5755
+ }
5756
+ const attributes = createTextAttributes({
5757
+ bold: styleDefinition.bold,
5758
+ italic: styleDefinition.italic,
5759
+ underline: styleDefinition.underline,
5760
+ dim: styleDefinition.dim
5761
+ });
5762
+ const merged = {
5763
+ fg: styleDefinition.fg,
5764
+ bg: styleDefinition.bg,
5765
+ attributes
5766
+ };
5767
+ this.mergedStyleCache.set(cacheKey, merged);
5768
+ return merged;
5769
+ }
5770
+ clearCache() {
5771
+ this.mergedStyleCache.clear();
5772
+ }
5773
+ getCacheSize() {
5774
+ return this.mergedStyleCache.size;
5775
+ }
5776
+ }
5777
+ var textEncoder2 = new TextEncoder;
5778
+ function hastToTextChunks(node, syntaxStyle, parentStyles = []) {
5779
+ const chunks = [];
5780
+ if (node.type === "text") {
5781
+ const stylesToMerge = parentStyles.length > 0 ? parentStyles : ["default"];
5782
+ const mergedStyle = syntaxStyle.mergeStyles(...stylesToMerge);
5783
+ chunks.push({
5784
+ __isChunk: true,
5785
+ text: textEncoder2.encode(node.value),
5786
+ plainText: node.value,
5787
+ fg: mergedStyle.fg,
5788
+ bg: mergedStyle.bg,
5789
+ attributes: mergedStyle.attributes
5790
+ });
5791
+ } else if (node.type === "element") {
5792
+ let currentStyles = [...parentStyles];
5793
+ if (node.properties?.className) {
5794
+ const classes = node.properties.className.split(" ");
5795
+ for (const cls of classes) {
5796
+ currentStyles.push(cls);
5797
+ }
5798
+ }
5799
+ for (const child of node.children) {
5800
+ chunks.push(...hastToTextChunks(child, syntaxStyle, currentStyles));
5801
+ }
5802
+ }
5803
+ return chunks;
5804
+ }
5805
+ function hastToStyledText(hast, syntaxStyle) {
5806
+ const chunks = hastToTextChunks(hast, syntaxStyle);
5807
+ return new StyledText(chunks);
5808
+ }
5475
5809
  // src/buffer.ts
5476
5810
  var fbIdCounter = 0;
5477
5811
  function isRGBAWithAlpha(color) {
@@ -5566,14 +5900,14 @@ class OptimizedBuffer {
5566
5900
  this.lib.bufferSetRespectAlpha(this.bufferPtr, respectAlpha);
5567
5901
  this.respectAlpha = respectAlpha;
5568
5902
  }
5569
- clear(bg = RGBA.fromValues(0, 0, 0, 1), clearChar = " ") {
5903
+ clear(bg2 = RGBA.fromValues(0, 0, 0, 1), clearChar = " ") {
5570
5904
  if (this.useFFI) {
5571
- this.clearFFI(bg);
5905
+ this.clearFFI(bg2);
5572
5906
  } else {
5573
- this.clearLocal(bg, clearChar);
5907
+ this.clearLocal(bg2, clearChar);
5574
5908
  }
5575
5909
  }
5576
- clearLocal(bg = RGBA.fromValues(0, 0, 0, 1), clearChar = " ") {
5910
+ clearLocal(bg2 = RGBA.fromValues(0, 0, 0, 1), clearChar = " ") {
5577
5911
  this.buffer.char.fill(clearChar.charCodeAt(0));
5578
5912
  this.buffer.attributes.fill(0);
5579
5913
  for (let i = 0;i < this.width * this.height; i++) {
@@ -5582,27 +5916,27 @@ class OptimizedBuffer {
5582
5916
  this.buffer.fg[index + 1] = 1;
5583
5917
  this.buffer.fg[index + 2] = 1;
5584
5918
  this.buffer.fg[index + 3] = 1;
5585
- this.buffer.bg[index] = bg.r;
5586
- this.buffer.bg[index + 1] = bg.g;
5587
- this.buffer.bg[index + 2] = bg.b;
5588
- this.buffer.bg[index + 3] = bg.a;
5919
+ this.buffer.bg[index] = bg2.r;
5920
+ this.buffer.bg[index + 1] = bg2.g;
5921
+ this.buffer.bg[index + 2] = bg2.b;
5922
+ this.buffer.bg[index + 3] = bg2.a;
5589
5923
  }
5590
5924
  }
5591
- setCell(x, y, char, fg, bg, attributes = 0) {
5925
+ setCell(x, y, char, fg2, bg2, attributes = 0) {
5592
5926
  if (x < 0 || x >= this.width || y < 0 || y >= this.height)
5593
5927
  return;
5594
5928
  const index = this.coordsToIndex(x, y);
5595
5929
  const colorIndex = index * 4;
5596
5930
  this.buffer.char[index] = char.charCodeAt(0);
5597
5931
  this.buffer.attributes[index] = attributes;
5598
- this.buffer.fg[colorIndex] = fg.r;
5599
- this.buffer.fg[colorIndex + 1] = fg.g;
5600
- this.buffer.fg[colorIndex + 2] = fg.b;
5601
- this.buffer.fg[colorIndex + 3] = fg.a;
5602
- this.buffer.bg[colorIndex] = bg.r;
5603
- this.buffer.bg[colorIndex + 1] = bg.g;
5604
- this.buffer.bg[colorIndex + 2] = bg.b;
5605
- this.buffer.bg[colorIndex + 3] = bg.a;
5932
+ this.buffer.fg[colorIndex] = fg2.r;
5933
+ this.buffer.fg[colorIndex + 1] = fg2.g;
5934
+ this.buffer.fg[colorIndex + 2] = fg2.b;
5935
+ this.buffer.fg[colorIndex + 3] = fg2.a;
5936
+ this.buffer.bg[colorIndex] = bg2.r;
5937
+ this.buffer.bg[colorIndex + 1] = bg2.g;
5938
+ this.buffer.bg[colorIndex + 2] = bg2.b;
5939
+ this.buffer.bg[colorIndex + 3] = bg2.a;
5606
5940
  }
5607
5941
  get(x, y) {
5608
5942
  if (x < 0 || x >= this.width || y < 0 || y >= this.height)
@@ -5616,41 +5950,41 @@ class OptimizedBuffer {
5616
5950
  attributes: this.buffer.attributes[index]
5617
5951
  };
5618
5952
  }
5619
- setCellWithAlphaBlending(x, y, char, fg, bg, attributes = 0) {
5953
+ setCellWithAlphaBlending(x, y, char, fg2, bg2, attributes = 0) {
5620
5954
  if (this.useFFI) {
5621
- this.setCellWithAlphaBlendingFFI(x, y, char, fg, bg, attributes);
5955
+ this.setCellWithAlphaBlendingFFI(x, y, char, fg2, bg2, attributes);
5622
5956
  } else {
5623
- this.setCellWithAlphaBlendingLocal(x, y, char, fg, bg, attributes);
5957
+ this.setCellWithAlphaBlendingLocal(x, y, char, fg2, bg2, attributes);
5624
5958
  }
5625
5959
  }
5626
- setCellWithAlphaBlendingLocal(x, y, char, fg, bg, attributes = 0) {
5960
+ setCellWithAlphaBlendingLocal(x, y, char, fg2, bg2, attributes = 0) {
5627
5961
  if (x < 0 || x >= this.width || y < 0 || y >= this.height)
5628
5962
  return;
5629
- const hasBgAlpha = isRGBAWithAlpha(bg);
5630
- const hasFgAlpha = isRGBAWithAlpha(fg);
5963
+ const hasBgAlpha = isRGBAWithAlpha(bg2);
5964
+ const hasFgAlpha = isRGBAWithAlpha(fg2);
5631
5965
  if (hasBgAlpha || hasFgAlpha) {
5632
5966
  const destCell = this.get(x, y);
5633
5967
  if (destCell) {
5634
- const blendedBgRgb = hasBgAlpha ? blendColors(bg, destCell.bg) : bg;
5968
+ const blendedBgRgb = hasBgAlpha ? blendColors(bg2, destCell.bg) : bg2;
5635
5969
  const preserveChar = char === " " && destCell.char !== 0 && String.fromCharCode(destCell.char) !== " ";
5636
5970
  const finalChar = preserveChar ? destCell.char : char.charCodeAt(0);
5637
5971
  let finalFg;
5638
5972
  if (preserveChar) {
5639
- finalFg = blendColors(bg, destCell.fg);
5973
+ finalFg = blendColors(bg2, destCell.fg);
5640
5974
  } else {
5641
- finalFg = hasFgAlpha ? blendColors(fg, destCell.bg) : fg;
5975
+ finalFg = hasFgAlpha ? blendColors(fg2, destCell.bg) : fg2;
5642
5976
  }
5643
5977
  const finalAttributes = preserveChar ? destCell.attributes : attributes;
5644
- const finalBg = RGBA.fromValues(blendedBgRgb.r, blendedBgRgb.g, blendedBgRgb.b, bg.a);
5978
+ const finalBg = RGBA.fromValues(blendedBgRgb.r, blendedBgRgb.g, blendedBgRgb.b, bg2.a);
5645
5979
  this.setCell(x, y, String.fromCharCode(finalChar), finalFg, finalBg, finalAttributes);
5646
5980
  return;
5647
5981
  }
5648
5982
  }
5649
- this.setCell(x, y, char, fg, bg, attributes);
5983
+ this.setCell(x, y, char, fg2, bg2, attributes);
5650
5984
  }
5651
- drawText(text, x, y, fg, bg, attributes = 0, selection) {
5985
+ drawText(text, x, y, fg2, bg2, attributes = 0, selection) {
5652
5986
  if (!selection) {
5653
- this.drawTextFFI.call(this, text, x, y, fg, bg, attributes);
5987
+ this.drawTextFFI.call(this, text, x, y, fg2, bg2, attributes);
5654
5988
  return;
5655
5989
  }
5656
5990
  const { start, end } = selection;
@@ -5658,15 +5992,15 @@ class OptimizedBuffer {
5658
5992
  let selectionFg;
5659
5993
  if (selection.bgColor) {
5660
5994
  selectionBg = selection.bgColor;
5661
- selectionFg = selection.fgColor || fg;
5995
+ selectionFg = selection.fgColor || fg2;
5662
5996
  } else {
5663
- const defaultBg = bg || RGBA.fromValues(0, 0, 0, 0);
5997
+ const defaultBg = bg2 || RGBA.fromValues(0, 0, 0, 0);
5664
5998
  selectionFg = defaultBg.a > 0 ? defaultBg : RGBA.fromValues(0, 0, 0, 1);
5665
- selectionBg = fg;
5999
+ selectionBg = fg2;
5666
6000
  }
5667
6001
  if (start > 0) {
5668
6002
  const beforeText = text.slice(0, start);
5669
- this.drawTextFFI.call(this, beforeText, x, y, fg, bg, attributes);
6003
+ this.drawTextFFI.call(this, beforeText, x, y, fg2, bg2, attributes);
5670
6004
  }
5671
6005
  if (end > start) {
5672
6006
  const selectedText = text.slice(start, end);
@@ -5674,29 +6008,29 @@ class OptimizedBuffer {
5674
6008
  }
5675
6009
  if (end < text.length) {
5676
6010
  const afterText = text.slice(end);
5677
- this.drawTextFFI.call(this, afterText, x + end, y, fg, bg, attributes);
6011
+ this.drawTextFFI.call(this, afterText, x + end, y, fg2, bg2, attributes);
5678
6012
  }
5679
6013
  }
5680
- fillRect(x, y, width, height, bg) {
6014
+ fillRect(x, y, width, height, bg2) {
5681
6015
  if (this.useFFI) {
5682
- this.fillRectFFI(x, y, width, height, bg);
6016
+ this.fillRectFFI(x, y, width, height, bg2);
5683
6017
  } else {
5684
- this.fillRectLocal(x, y, width, height, bg);
6018
+ this.fillRectLocal(x, y, width, height, bg2);
5685
6019
  }
5686
6020
  }
5687
- fillRectLocal(x, y, width, height, bg) {
6021
+ fillRectLocal(x, y, width, height, bg2) {
5688
6022
  const startX = Math.max(0, x);
5689
6023
  const startY = Math.max(0, y);
5690
6024
  const endX = Math.min(this.getWidth() - 1, x + width - 1);
5691
6025
  const endY = Math.min(this.getHeight() - 1, y + height - 1);
5692
6026
  if (startX > endX || startY > endY)
5693
6027
  return;
5694
- const hasAlpha = isRGBAWithAlpha(bg);
6028
+ const hasAlpha = isRGBAWithAlpha(bg2);
5695
6029
  if (hasAlpha) {
5696
- const fg = RGBA.fromValues(1, 1, 1, 1);
6030
+ const fg2 = RGBA.fromValues(1, 1, 1, 1);
5697
6031
  for (let fillY = startY;fillY <= endY; fillY++) {
5698
6032
  for (let fillX = startX;fillX <= endX; fillX++) {
5699
- this.setCellWithAlphaBlending(fillX, fillY, " ", fg, bg, 0);
6033
+ this.setCellWithAlphaBlending(fillX, fillY, " ", fg2, bg2, 0);
5700
6034
  }
5701
6035
  }
5702
6036
  } else {
@@ -5710,10 +6044,10 @@ class OptimizedBuffer {
5710
6044
  this.buffer.fg[colorIndex + 1] = 1;
5711
6045
  this.buffer.fg[colorIndex + 2] = 1;
5712
6046
  this.buffer.fg[colorIndex + 3] = 1;
5713
- this.buffer.bg[colorIndex] = bg.r;
5714
- this.buffer.bg[colorIndex + 1] = bg.g;
5715
- this.buffer.bg[colorIndex + 2] = bg.b;
5716
- this.buffer.bg[colorIndex + 3] = bg.a;
6047
+ this.buffer.bg[colorIndex] = bg2.r;
6048
+ this.buffer.bg[colorIndex + 1] = bg2.g;
6049
+ this.buffer.bg[colorIndex + 2] = bg2.b;
6050
+ this.buffer.bg[colorIndex + 3] = bg2.a;
5717
6051
  }
5718
6052
  }
5719
6053
  }
@@ -5777,10 +6111,10 @@ class OptimizedBuffer {
5777
6111
  continue;
5778
6112
  }
5779
6113
  const charCode = frameBuffer.buffer.char[srcIndex];
5780
- const fg = RGBA.fromArray(frameBuffer.buffer.fg.slice(srcColorIndex, srcColorIndex + 4));
5781
- const bg = RGBA.fromArray(frameBuffer.buffer.bg.slice(srcColorIndex, srcColorIndex + 4));
6114
+ const fg2 = RGBA.fromArray(frameBuffer.buffer.fg.slice(srcColorIndex, srcColorIndex + 4));
6115
+ const bg2 = RGBA.fromArray(frameBuffer.buffer.bg.slice(srcColorIndex, srcColorIndex + 4));
5782
6116
  const attributes = frameBuffer.buffer.attributes[srcIndex];
5783
- this.setCellWithAlphaBlending(dX, dY, String.fromCharCode(charCode), fg, bg, attributes);
6117
+ this.setCellWithAlphaBlending(dX, dY, String.fromCharCode(charCode), fg2, bg2, attributes);
5784
6118
  }
5785
6119
  }
5786
6120
  }
@@ -5799,11 +6133,11 @@ class OptimizedBuffer {
5799
6133
  drawPackedBuffer(dataPtr, dataLen, posX, posY, terminalWidthCells, terminalHeightCells) {
5800
6134
  this.lib.bufferDrawPackedBuffer(this.bufferPtr, dataPtr, dataLen, posX, posY, terminalWidthCells, terminalHeightCells);
5801
6135
  }
5802
- setCellWithAlphaBlendingFFI(x, y, char, fg, bg, attributes) {
5803
- this.lib.bufferSetCellWithAlphaBlending(this.bufferPtr, x, y, char, fg, bg, attributes);
6136
+ setCellWithAlphaBlendingFFI(x, y, char, fg2, bg2, attributes) {
6137
+ this.lib.bufferSetCellWithAlphaBlending(this.bufferPtr, x, y, char, fg2, bg2, attributes);
5804
6138
  }
5805
- fillRectFFI(x, y, width, height, bg) {
5806
- this.lib.bufferFillRect(this.bufferPtr, x, y, width, height, bg);
6139
+ fillRectFFI(x, y, width, height, bg2) {
6140
+ this.lib.bufferFillRect(this.bufferPtr, x, y, width, height, bg2);
5807
6141
  }
5808
6142
  resize(width, height) {
5809
6143
  if (this.width === width && this.height === height)
@@ -5812,11 +6146,11 @@ class OptimizedBuffer {
5812
6146
  this.height = height;
5813
6147
  this.buffer = this.lib.bufferResize(this.bufferPtr, width, height);
5814
6148
  }
5815
- clearFFI(bg = RGBA.fromValues(0, 0, 0, 1)) {
5816
- this.lib.bufferClear(this.bufferPtr, bg);
6149
+ clearFFI(bg2 = RGBA.fromValues(0, 0, 0, 1)) {
6150
+ this.lib.bufferClear(this.bufferPtr, bg2);
5817
6151
  }
5818
- drawTextFFI(text, x, y, fg = RGBA.fromValues(1, 1, 1, 1), bg, attributes = 0) {
5819
- this.lib.bufferDrawText(this.bufferPtr, text, x, y, fg, bg, attributes);
6152
+ drawTextFFI(text, x, y, fg2 = RGBA.fromValues(1, 1, 1, 1), bg2, attributes = 0) {
6153
+ this.lib.bufferDrawText(this.bufferPtr, text, x, y, fg2, bg2, attributes);
5820
6154
  }
5821
6155
  drawFrameBufferFFI(destX, destY, frameBuffer, sourceX, sourceY, sourceWidth, sourceHeight) {
5822
6156
  this.lib.drawFrameBuffer(this.bufferPtr, destX, destY, frameBuffer.ptr, sourceX, sourceY, sourceWidth, sourceHeight);
@@ -5832,91 +6166,91 @@ class OptimizedBuffer {
5832
6166
  function applyScanlines(buffer, strength = 0.8, step = 2) {
5833
6167
  const width = buffer.getWidth();
5834
6168
  const height = buffer.getHeight();
5835
- const bg = buffer.buffers.bg;
6169
+ const bg2 = buffer.buffers.bg;
5836
6170
  for (let y = 0;y < height; y += step) {
5837
6171
  for (let x = 0;x < width; x++) {
5838
6172
  const colorIndex = (y * width + x) * 4;
5839
- bg[colorIndex] *= strength;
5840
- bg[colorIndex + 1] *= strength;
5841
- bg[colorIndex + 2] *= strength;
6173
+ bg2[colorIndex] *= strength;
6174
+ bg2[colorIndex + 1] *= strength;
6175
+ bg2[colorIndex + 2] *= strength;
5842
6176
  }
5843
6177
  }
5844
6178
  }
5845
6179
  function applyGrayscale(buffer) {
5846
6180
  const size = buffer.getWidth() * buffer.getHeight();
5847
- const fg = buffer.buffers.fg;
5848
- const bg = buffer.buffers.bg;
6181
+ const fg2 = buffer.buffers.fg;
6182
+ const bg2 = buffer.buffers.bg;
5849
6183
  for (let i = 0;i < size; i++) {
5850
6184
  const colorIndex = i * 4;
5851
- const fgR = fg[colorIndex];
5852
- const fgG = fg[colorIndex + 1];
5853
- const fgB = fg[colorIndex + 2];
6185
+ const fgR = fg2[colorIndex];
6186
+ const fgG = fg2[colorIndex + 1];
6187
+ const fgB = fg2[colorIndex + 2];
5854
6188
  const fgLum = 0.299 * fgR + 0.587 * fgG + 0.114 * fgB;
5855
- fg[colorIndex] = fgLum;
5856
- fg[colorIndex + 1] = fgLum;
5857
- fg[colorIndex + 2] = fgLum;
5858
- const bgR = bg[colorIndex];
5859
- const bgG = bg[colorIndex + 1];
5860
- const bgB = bg[colorIndex + 2];
6189
+ fg2[colorIndex] = fgLum;
6190
+ fg2[colorIndex + 1] = fgLum;
6191
+ fg2[colorIndex + 2] = fgLum;
6192
+ const bgR = bg2[colorIndex];
6193
+ const bgG = bg2[colorIndex + 1];
6194
+ const bgB = bg2[colorIndex + 2];
5861
6195
  const bgLum = 0.299 * bgR + 0.587 * bgG + 0.114 * bgB;
5862
- bg[colorIndex] = bgLum;
5863
- bg[colorIndex + 1] = bgLum;
5864
- bg[colorIndex + 2] = bgLum;
6196
+ bg2[colorIndex] = bgLum;
6197
+ bg2[colorIndex + 1] = bgLum;
6198
+ bg2[colorIndex + 2] = bgLum;
5865
6199
  }
5866
6200
  }
5867
6201
  function applySepia(buffer) {
5868
6202
  const size = buffer.getWidth() * buffer.getHeight();
5869
- const fg = buffer.buffers.fg;
5870
- const bg = buffer.buffers.bg;
6203
+ const fg2 = buffer.buffers.fg;
6204
+ const bg2 = buffer.buffers.bg;
5871
6205
  for (let i = 0;i < size; i++) {
5872
6206
  const colorIndex = i * 4;
5873
- let fgR = fg[colorIndex];
5874
- let fgG = fg[colorIndex + 1];
5875
- let fgB = fg[colorIndex + 2];
6207
+ let fgR = fg2[colorIndex];
6208
+ let fgG = fg2[colorIndex + 1];
6209
+ let fgB = fg2[colorIndex + 2];
5876
6210
  let newFgR = Math.min(1, fgR * 0.393 + fgG * 0.769 + fgB * 0.189);
5877
6211
  let newFgG = Math.min(1, fgR * 0.349 + fgG * 0.686 + fgB * 0.168);
5878
6212
  let newFgB = Math.min(1, fgR * 0.272 + fgG * 0.534 + fgB * 0.131);
5879
- fg[colorIndex] = newFgR;
5880
- fg[colorIndex + 1] = newFgG;
5881
- fg[colorIndex + 2] = newFgB;
5882
- let bgR = bg[colorIndex];
5883
- let bgG = bg[colorIndex + 1];
5884
- let bgB = bg[colorIndex + 2];
6213
+ fg2[colorIndex] = newFgR;
6214
+ fg2[colorIndex + 1] = newFgG;
6215
+ fg2[colorIndex + 2] = newFgB;
6216
+ let bgR = bg2[colorIndex];
6217
+ let bgG = bg2[colorIndex + 1];
6218
+ let bgB = bg2[colorIndex + 2];
5885
6219
  let newBgR = Math.min(1, bgR * 0.393 + bgG * 0.769 + bgB * 0.189);
5886
6220
  let newBgG = Math.min(1, bgR * 0.349 + bgG * 0.686 + bgB * 0.168);
5887
6221
  let newBgB = Math.min(1, bgR * 0.272 + bgG * 0.534 + bgB * 0.131);
5888
- bg[colorIndex] = newBgR;
5889
- bg[colorIndex + 1] = newBgG;
5890
- bg[colorIndex + 2] = newBgB;
6222
+ bg2[colorIndex] = newBgR;
6223
+ bg2[colorIndex + 1] = newBgG;
6224
+ bg2[colorIndex + 2] = newBgB;
5891
6225
  }
5892
6226
  }
5893
6227
  function applyInvert(buffer) {
5894
6228
  const size = buffer.getWidth() * buffer.getHeight();
5895
- const fg = buffer.buffers.fg;
5896
- const bg = buffer.buffers.bg;
6229
+ const fg2 = buffer.buffers.fg;
6230
+ const bg2 = buffer.buffers.bg;
5897
6231
  for (let i = 0;i < size; i++) {
5898
6232
  const colorIndex = i * 4;
5899
- fg[colorIndex] = 1 - fg[colorIndex];
5900
- fg[colorIndex + 1] = 1 - fg[colorIndex + 1];
5901
- fg[colorIndex + 2] = 1 - fg[colorIndex + 2];
5902
- bg[colorIndex] = 1 - bg[colorIndex];
5903
- bg[colorIndex + 1] = 1 - bg[colorIndex + 1];
5904
- bg[colorIndex + 2] = 1 - bg[colorIndex + 2];
6233
+ fg2[colorIndex] = 1 - fg2[colorIndex];
6234
+ fg2[colorIndex + 1] = 1 - fg2[colorIndex + 1];
6235
+ fg2[colorIndex + 2] = 1 - fg2[colorIndex + 2];
6236
+ bg2[colorIndex] = 1 - bg2[colorIndex];
6237
+ bg2[colorIndex + 1] = 1 - bg2[colorIndex + 1];
6238
+ bg2[colorIndex + 2] = 1 - bg2[colorIndex + 2];
5905
6239
  }
5906
6240
  }
5907
6241
  function applyNoise(buffer, strength = 0.1) {
5908
6242
  const size = buffer.getWidth() * buffer.getHeight();
5909
- const fg = buffer.buffers.fg;
5910
- const bg = buffer.buffers.bg;
6243
+ const fg2 = buffer.buffers.fg;
6244
+ const bg2 = buffer.buffers.bg;
5911
6245
  for (let i = 0;i < size; i++) {
5912
6246
  const colorIndex = i * 4;
5913
6247
  const noise = (Math.random() - 0.5) * strength;
5914
- fg[colorIndex] = Math.max(0, Math.min(1, fg[colorIndex] + noise));
5915
- fg[colorIndex + 1] = Math.max(0, Math.min(1, fg[colorIndex + 1] + noise));
5916
- fg[colorIndex + 2] = Math.max(0, Math.min(1, fg[colorIndex + 2] + noise));
5917
- bg[colorIndex] = Math.max(0, Math.min(1, bg[colorIndex] + noise));
5918
- bg[colorIndex + 1] = Math.max(0, Math.min(1, bg[colorIndex + 1] + noise));
5919
- bg[colorIndex + 2] = Math.max(0, Math.min(1, bg[colorIndex + 2] + noise));
6248
+ fg2[colorIndex] = Math.max(0, Math.min(1, fg2[colorIndex] + noise));
6249
+ fg2[colorIndex + 1] = Math.max(0, Math.min(1, fg2[colorIndex + 1] + noise));
6250
+ fg2[colorIndex + 2] = Math.max(0, Math.min(1, fg2[colorIndex + 2] + noise));
6251
+ bg2[colorIndex] = Math.max(0, Math.min(1, bg2[colorIndex] + noise));
6252
+ bg2[colorIndex + 1] = Math.max(0, Math.min(1, bg2[colorIndex + 1] + noise));
6253
+ bg2[colorIndex + 2] = Math.max(0, Math.min(1, bg2[colorIndex + 2] + noise));
5920
6254
  }
5921
6255
  }
5922
6256
  function applyChromaticAberration(buffer, strength = 1) {
@@ -5947,15 +6281,15 @@ function applyAsciiArt(buffer, ramp = " .:-=+*#%@") {
5947
6281
  const width = buffer.getWidth();
5948
6282
  const height = buffer.getHeight();
5949
6283
  const chars = buffer.buffers.char;
5950
- const bg = buffer.buffers.bg;
6284
+ const bg2 = buffer.buffers.bg;
5951
6285
  const rampLength = ramp.length;
5952
6286
  for (let y = 0;y < height; y++) {
5953
6287
  for (let x = 0;x < width; x++) {
5954
6288
  const index = y * width + x;
5955
6289
  const colorIndex = index * 4;
5956
- const bgR = bg[colorIndex];
5957
- const bgG = bg[colorIndex + 1];
5958
- const bgB = bg[colorIndex + 2];
6290
+ const bgR = bg2[colorIndex];
6291
+ const bgG = bg2[colorIndex + 1];
6292
+ const bgB = bg2[colorIndex + 2];
5959
6293
  const lum = 0.299 * bgR + 0.587 * bgG + 0.114 * bgB;
5960
6294
  const rampIndex = Math.min(rampLength - 1, Math.floor(lum * rampLength));
5961
6295
  chars[index] = ramp[rampIndex].charCodeAt(0);
@@ -6215,20 +6549,20 @@ class BrightnessEffect {
6215
6549
  }
6216
6550
  apply(buffer) {
6217
6551
  const size = buffer.getWidth() * buffer.getHeight();
6218
- const fg = buffer.buffers.fg;
6219
- const bg = buffer.buffers.bg;
6552
+ const fg2 = buffer.buffers.fg;
6553
+ const bg2 = buffer.buffers.bg;
6220
6554
  const factor = this._brightness;
6221
6555
  if (factor === 1) {
6222
6556
  return;
6223
6557
  }
6224
6558
  for (let i = 0;i < size; i++) {
6225
6559
  const colorIndex = i * 4;
6226
- fg[colorIndex] = Math.min(1, fg[colorIndex] * factor);
6227
- fg[colorIndex + 1] = Math.min(1, fg[colorIndex + 1] * factor);
6228
- fg[colorIndex + 2] = Math.min(1, fg[colorIndex + 2] * factor);
6229
- bg[colorIndex] = Math.min(1, bg[colorIndex] * factor);
6230
- bg[colorIndex + 1] = Math.min(1, bg[colorIndex + 1] * factor);
6231
- bg[colorIndex + 2] = Math.min(1, bg[colorIndex + 2] * factor);
6560
+ fg2[colorIndex] = Math.min(1, fg2[colorIndex] * factor);
6561
+ fg2[colorIndex + 1] = Math.min(1, fg2[colorIndex + 1] * factor);
6562
+ fg2[colorIndex + 2] = Math.min(1, fg2[colorIndex + 2] * factor);
6563
+ bg2[colorIndex] = Math.min(1, bg2[colorIndex] * factor);
6564
+ bg2[colorIndex + 1] = Math.min(1, bg2[colorIndex + 1] * factor);
6565
+ bg2[colorIndex + 2] = Math.min(1, bg2[colorIndex + 2] * factor);
6232
6566
  }
6233
6567
  }
6234
6568
  }
@@ -6480,45 +6814,45 @@ class BloomEffect {
6480
6814
  }
6481
6815
  // src/animation/Timeline.ts
6482
6816
  var easingFunctions = {
6483
- linear: (t) => t,
6484
- inQuad: (t) => t * t,
6485
- outQuad: (t) => t * (2 - t),
6486
- inOutQuad: (t) => t < 0.5 ? 2 * t * t : -1 + (4 - 2 * t) * t,
6487
- inExpo: (t) => t === 0 ? 0 : Math.pow(2, 10 * (t - 1)),
6488
- outExpo: (t) => t === 1 ? 1 : 1 - Math.pow(2, -10 * t),
6489
- inOutSine: (t) => -(Math.cos(Math.PI * t) - 1) / 2,
6490
- outBounce: (t) => {
6817
+ linear: (t2) => t2,
6818
+ inQuad: (t2) => t2 * t2,
6819
+ outQuad: (t2) => t2 * (2 - t2),
6820
+ inOutQuad: (t2) => t2 < 0.5 ? 2 * t2 * t2 : -1 + (4 - 2 * t2) * t2,
6821
+ inExpo: (t2) => t2 === 0 ? 0 : Math.pow(2, 10 * (t2 - 1)),
6822
+ outExpo: (t2) => t2 === 1 ? 1 : 1 - Math.pow(2, -10 * t2),
6823
+ inOutSine: (t2) => -(Math.cos(Math.PI * t2) - 1) / 2,
6824
+ outBounce: (t2) => {
6491
6825
  const n1 = 7.5625;
6492
6826
  const d1 = 2.75;
6493
- if (t < 1 / d1) {
6494
- return n1 * t * t;
6495
- } else if (t < 2 / d1) {
6496
- return n1 * (t -= 1.5 / d1) * t + 0.75;
6497
- } else if (t < 2.5 / d1) {
6498
- return n1 * (t -= 2.25 / d1) * t + 0.9375;
6827
+ if (t2 < 1 / d1) {
6828
+ return n1 * t2 * t2;
6829
+ } else if (t2 < 2 / d1) {
6830
+ return n1 * (t2 -= 1.5 / d1) * t2 + 0.75;
6831
+ } else if (t2 < 2.5 / d1) {
6832
+ return n1 * (t2 -= 2.25 / d1) * t2 + 0.9375;
6499
6833
  } else {
6500
- return n1 * (t -= 2.625 / d1) * t + 0.984375;
6834
+ return n1 * (t2 -= 2.625 / d1) * t2 + 0.984375;
6501
6835
  }
6502
6836
  },
6503
- outElastic: (t) => {
6837
+ outElastic: (t2) => {
6504
6838
  const c4 = 2 * Math.PI / 3;
6505
- return t === 0 ? 0 : t === 1 ? 1 : Math.pow(2, -10 * t) * Math.sin((t * 10 - 0.75) * c4) + 1;
6839
+ return t2 === 0 ? 0 : t2 === 1 ? 1 : Math.pow(2, -10 * t2) * Math.sin((t2 * 10 - 0.75) * c4) + 1;
6506
6840
  },
6507
- inBounce: (t) => 1 - easingFunctions.outBounce(1 - t),
6508
- inCirc: (t) => 1 - Math.sqrt(1 - t * t),
6509
- outCirc: (t) => Math.sqrt(1 - Math.pow(t - 1, 2)),
6510
- inOutCirc: (t) => {
6511
- if ((t *= 2) < 1)
6512
- return -0.5 * (Math.sqrt(1 - t * t) - 1);
6513
- return 0.5 * (Math.sqrt(1 - (t -= 2) * t) + 1);
6841
+ inBounce: (t2) => 1 - easingFunctions.outBounce(1 - t2),
6842
+ inCirc: (t2) => 1 - Math.sqrt(1 - t2 * t2),
6843
+ outCirc: (t2) => Math.sqrt(1 - Math.pow(t2 - 1, 2)),
6844
+ inOutCirc: (t2) => {
6845
+ if ((t2 *= 2) < 1)
6846
+ return -0.5 * (Math.sqrt(1 - t2 * t2) - 1);
6847
+ return 0.5 * (Math.sqrt(1 - (t2 -= 2) * t2) + 1);
6514
6848
  },
6515
- inBack: (t, s = 1.70158) => t * t * ((s + 1) * t - s),
6516
- outBack: (t, s = 1.70158) => --t * t * ((s + 1) * t + s) + 1,
6517
- inOutBack: (t, s = 1.70158) => {
6849
+ inBack: (t2, s = 1.70158) => t2 * t2 * ((s + 1) * t2 - s),
6850
+ outBack: (t2, s = 1.70158) => --t2 * t2 * ((s + 1) * t2 + s) + 1,
6851
+ inOutBack: (t2, s = 1.70158) => {
6518
6852
  s *= 1.525;
6519
- if ((t *= 2) < 1)
6520
- return 0.5 * (t * t * ((s + 1) * t - s));
6521
- return 0.5 * ((t -= 2) * t * ((s + 1) * t + s) + 2);
6853
+ if ((t2 *= 2) < 1)
6854
+ return 0.5 * (t2 * t2 * ((s + 1) * t2 - s));
6855
+ return 0.5 * ((t2 -= 2) * t2 * ((s + 1) * t2 + s) + 2);
6522
6856
  }
6523
6857
  };
6524
6858
  function captureInitialValues(item) {
@@ -6850,182 +7184,6 @@ function createTimeline(options = {}) {
6850
7184
  engine.register(timeline);
6851
7185
  return timeline;
6852
7186
  }
6853
- // src/lib/styled-text.ts
6854
- var textEncoder = new TextEncoder;
6855
-
6856
- class StyledText {
6857
- chunks;
6858
- _length;
6859
- _plainText;
6860
- constructor(chunks, length, plainText) {
6861
- this.chunks = chunks;
6862
- this._length = length;
6863
- this._plainText = plainText;
6864
- }
6865
- toString() {
6866
- return this._plainText;
6867
- }
6868
- get length() {
6869
- return this._length;
6870
- }
6871
- }
6872
- function stringToStyledText(content) {
6873
- const textEncoder2 = new TextEncoder;
6874
- const chunk = {
6875
- __isChunk: true,
6876
- text: textEncoder2.encode(content),
6877
- plainText: content
6878
- };
6879
- return new StyledText([chunk], content.length, content);
6880
- }
6881
- var templateCache = new WeakMap;
6882
- function applyStyle(input, style) {
6883
- if (typeof input === "object" && "__isChunk" in input) {
6884
- const existingChunk = input;
6885
- const fg = style.fg ? parseColor(style.fg) : existingChunk.fg;
6886
- const bg = style.bg ? parseColor(style.bg) : existingChunk.bg;
6887
- const newAttrs = createTextAttributes(style);
6888
- const mergedAttrs = existingChunk.attributes ? existingChunk.attributes | newAttrs : newAttrs;
6889
- return {
6890
- __isChunk: true,
6891
- text: existingChunk.text,
6892
- plainText: existingChunk.plainText,
6893
- fg,
6894
- bg,
6895
- attributes: mergedAttrs
6896
- };
6897
- } else {
6898
- const plainTextStr = String(input);
6899
- const text = textEncoder.encode(plainTextStr);
6900
- const fg = style.fg ? parseColor(style.fg) : undefined;
6901
- const bg = style.bg ? parseColor(style.bg) : undefined;
6902
- const attributes = createTextAttributes(style);
6903
- return {
6904
- __isChunk: true,
6905
- text,
6906
- plainText: plainTextStr,
6907
- fg,
6908
- bg,
6909
- attributes
6910
- };
6911
- }
6912
- }
6913
- var black = (input) => applyStyle(input, { fg: "black" });
6914
- var red = (input) => applyStyle(input, { fg: "red" });
6915
- var green = (input) => applyStyle(input, { fg: "green" });
6916
- var yellow = (input) => applyStyle(input, { fg: "yellow" });
6917
- var blue = (input) => applyStyle(input, { fg: "blue" });
6918
- var magenta = (input) => applyStyle(input, { fg: "magenta" });
6919
- var cyan = (input) => applyStyle(input, { fg: "cyan" });
6920
- var white = (input) => applyStyle(input, { fg: "white" });
6921
- var brightBlack = (input) => applyStyle(input, { fg: "brightBlack" });
6922
- var brightRed = (input) => applyStyle(input, { fg: "brightRed" });
6923
- var brightGreen = (input) => applyStyle(input, { fg: "brightGreen" });
6924
- var brightYellow = (input) => applyStyle(input, { fg: "brightYellow" });
6925
- var brightBlue = (input) => applyStyle(input, { fg: "brightBlue" });
6926
- var brightMagenta = (input) => applyStyle(input, { fg: "brightMagenta" });
6927
- var brightCyan = (input) => applyStyle(input, { fg: "brightCyan" });
6928
- var brightWhite = (input) => applyStyle(input, { fg: "brightWhite" });
6929
- var bgBlack = (input) => applyStyle(input, { bg: "black" });
6930
- var bgRed = (input) => applyStyle(input, { bg: "red" });
6931
- var bgGreen = (input) => applyStyle(input, { bg: "green" });
6932
- var bgYellow = (input) => applyStyle(input, { bg: "yellow" });
6933
- var bgBlue = (input) => applyStyle(input, { bg: "blue" });
6934
- var bgMagenta = (input) => applyStyle(input, { bg: "magenta" });
6935
- var bgCyan = (input) => applyStyle(input, { bg: "cyan" });
6936
- var bgWhite = (input) => applyStyle(input, { bg: "white" });
6937
- var bold = (input) => applyStyle(input, { bold: true });
6938
- var italic = (input) => applyStyle(input, { italic: true });
6939
- var underline = (input) => applyStyle(input, { underline: true });
6940
- var strikethrough = (input) => applyStyle(input, { strikethrough: true });
6941
- var dim = (input) => applyStyle(input, { dim: true });
6942
- var reverse = (input) => applyStyle(input, { reverse: true });
6943
- var blink = (input) => applyStyle(input, { blink: true });
6944
- var fg = (color) => (input) => applyStyle(input, { fg: color });
6945
- var bg = (color) => (input) => applyStyle(input, { bg: color });
6946
- function tn(strings, ...values) {
6947
- const chunks = [];
6948
- let length = 0;
6949
- let plainText = "";
6950
- for (let i = 0;i < strings.length; i++) {
6951
- const raw = strings[i];
6952
- if (raw) {
6953
- chunks.push({
6954
- __isChunk: true,
6955
- text: textEncoder.encode(raw),
6956
- plainText: raw,
6957
- attributes: 0
6958
- });
6959
- length += raw.length;
6960
- plainText += raw;
6961
- }
6962
- const val = values[i];
6963
- if (typeof val === "object" && "__isChunk" in val) {
6964
- chunks.push(val);
6965
- length += val.plainText.length;
6966
- plainText += val.plainText;
6967
- } else if (val !== undefined) {
6968
- const plainTextStr = String(val);
6969
- chunks.push({
6970
- __isChunk: true,
6971
- text: textEncoder.encode(plainTextStr),
6972
- plainText: plainTextStr,
6973
- attributes: 0
6974
- });
6975
- length += plainTextStr.length;
6976
- plainText += plainTextStr;
6977
- }
6978
- }
6979
- return new StyledText(chunks, length, plainText);
6980
- }
6981
- function t(strings, ...values) {
6982
- let cachedStringChunks = templateCache.get(strings);
6983
- let length = 0;
6984
- let plainText = "";
6985
- if (!cachedStringChunks) {
6986
- cachedStringChunks = [];
6987
- for (let i = 0;i < strings.length; i++) {
6988
- const raw = strings[i];
6989
- if (raw) {
6990
- cachedStringChunks.push({
6991
- __isChunk: true,
6992
- text: textEncoder.encode(raw),
6993
- plainText: raw,
6994
- attributes: 0
6995
- });
6996
- } else {
6997
- cachedStringChunks.push(null);
6998
- }
6999
- }
7000
- templateCache.set(strings, cachedStringChunks);
7001
- }
7002
- const chunks = [];
7003
- for (let i = 0;i < strings.length; i++) {
7004
- const stringChunk = cachedStringChunks[i];
7005
- if (stringChunk) {
7006
- chunks.push(stringChunk);
7007
- length += stringChunk.plainText.length;
7008
- plainText += stringChunk.plainText;
7009
- }
7010
- const val = values[i];
7011
- if (typeof val === "object" && "__isChunk" in val) {
7012
- chunks.push(val);
7013
- length += val.plainText.length;
7014
- plainText += val.plainText;
7015
- } else if (val !== undefined) {
7016
- const plainTextStr = String(val);
7017
- chunks.push({
7018
- __isChunk: true,
7019
- text: textEncoder.encode(plainTextStr),
7020
- plainText: plainTextStr,
7021
- attributes: 0
7022
- });
7023
- length += plainTextStr.length;
7024
- plainText += plainTextStr;
7025
- }
7026
- }
7027
- return new StyledText(chunks, length, plainText);
7028
- }
7029
7187
  // src/lib/selection.ts
7030
7188
  class Selection {
7031
7189
  _anchor;
@@ -7298,7 +7456,10 @@ var ANSI = {
7298
7456
  enableAnyEventTracking: "\x1B[?1003h",
7299
7457
  disableAnyEventTracking: "\x1B[?1003l",
7300
7458
  enableSGRMouseMode: "\x1B[?1006h",
7301
- disableSGRMouseMode: "\x1B[?1006l"
7459
+ disableSGRMouseMode: "\x1B[?1006l",
7460
+ makeRoomForRenderer: (height) => `
7461
+ `.repeat(height) + `\x1B[${height}A`,
7462
+ clearRendererSpace: (height) => `\x1B[${height}A\x1B[1G\x1B[J`
7302
7463
  };
7303
7464
 
7304
7465
  // src/console.ts
@@ -7473,6 +7634,13 @@ var terminalConsoleCache = new TerminalConsoleCache;
7473
7634
  process.on("exit", () => {
7474
7635
  terminalConsoleCache.destroy();
7475
7636
  });
7637
+ var ConsolePosition;
7638
+ ((ConsolePosition2) => {
7639
+ ConsolePosition2["TOP"] = "top";
7640
+ ConsolePosition2["BOTTOM"] = "bottom";
7641
+ ConsolePosition2["LEFT"] = "left";
7642
+ ConsolePosition2["RIGHT"] = "right";
7643
+ })(ConsolePosition ||= {});
7476
7644
  var DEFAULT_CONSOLE_OPTIONS = {
7477
7645
  position: "bottom" /* BOTTOM */,
7478
7646
  sizePercent: 30,
@@ -8089,6 +8257,11 @@ var MouseButton;
8089
8257
  MouseButton2[MouseButton2["WHEEL_UP"] = 4] = "WHEEL_UP";
8090
8258
  MouseButton2[MouseButton2["WHEEL_DOWN"] = 5] = "WHEEL_DOWN";
8091
8259
  })(MouseButton ||= {});
8260
+ ["SIGINT", "SIGTERM", "SIGQUIT", "SIGABRT"].forEach((signal) => {
8261
+ process.on(signal, () => {
8262
+ process.exit();
8263
+ });
8264
+ });
8092
8265
  async function createCliRenderer(config = {}) {
8093
8266
  if (process.argv.includes("--delay-start")) {
8094
8267
  await new Promise((resolve) => setTimeout(resolve, 5000));
@@ -8125,7 +8298,6 @@ class CliRenderer extends EventEmitter6 {
8125
8298
  stdout;
8126
8299
  exitOnCtrlC;
8127
8300
  isDestroyed = false;
8128
- isShuttingDown = false;
8129
8301
  nextRenderBuffer;
8130
8302
  currentRenderBuffer;
8131
8303
  _isRunning = false;
@@ -8147,6 +8319,7 @@ class CliRenderer extends EventEmitter6 {
8147
8319
  postProcessFns = [];
8148
8320
  backgroundColor = RGBA.fromHex("#000000");
8149
8321
  waitingForPixelResolution = false;
8322
+ shutdownRequested = null;
8150
8323
  rendering = false;
8151
8324
  renderingNative = false;
8152
8325
  renderTimeout = null;
@@ -8250,8 +8423,6 @@ class CliRenderer extends EventEmitter6 {
8250
8423
  }
8251
8424
  this.stdout.write = this.interceptStdoutWrite.bind(this);
8252
8425
  this.sigwinchHandler = () => {
8253
- if (this.isShuttingDown)
8254
- return;
8255
8426
  const width2 = this.stdout.columns || 80;
8256
8427
  const height2 = this.stdout.rows || 24;
8257
8428
  this.handleResize(width2, height2);
@@ -8259,6 +8430,7 @@ class CliRenderer extends EventEmitter6 {
8259
8430
  process.on("SIGWINCH", this.sigwinchHandler);
8260
8431
  const handleError = (error) => {
8261
8432
  this.stop();
8433
+ this.destroy();
8262
8434
  new Promise((resolve) => {
8263
8435
  setTimeout(() => {
8264
8436
  resolve(true);
@@ -8292,8 +8464,7 @@ Error details:
8292
8464
  };
8293
8465
  process.on("uncaughtException", handleError);
8294
8466
  process.on("unhandledRejection", handleError);
8295
- process.on("exit", (code) => {
8296
- this.stop();
8467
+ process.on("exit", () => {
8297
8468
  this.destroy();
8298
8469
  });
8299
8470
  this._console = new TerminalConsole(this, config.consoleOptions);
@@ -8312,6 +8483,13 @@ Error details:
8312
8483
  }
8313
8484
  global.window.requestAnimationFrame = requestAnimationFrame;
8314
8485
  this.queryPixelResolution();
8486
+ if (process.env.OTUI_NO_NATIVE_RENDER === "true") {
8487
+ this.renderNative = () => {
8488
+ if (this._splitHeight > 0) {
8489
+ this.flushStdoutCache(this._splitHeight);
8490
+ }
8491
+ };
8492
+ }
8315
8493
  }
8316
8494
  writeOut(chunk, encoding, callback) {
8317
8495
  return this.realStdoutWrite.call(this.stdout, chunk, encoding, callback);
@@ -8443,30 +8621,17 @@ Error details:
8443
8621
  return true;
8444
8622
  }
8445
8623
  enableMouse() {
8446
- this.writeOut(ANSI.enableSGRMouseMode);
8447
- this.writeOut(ANSI.enableMouseTracking);
8448
- this.writeOut(ANSI.enableButtonEventTracking);
8449
- if (this.enableMouseMovement) {
8450
- this.writeOut(ANSI.enableAnyEventTracking);
8451
- }
8624
+ this.lib.enableMouse(this.rendererPtr, this.enableMouseMovement);
8452
8625
  }
8453
8626
  disableMouse() {
8454
- if (this.enableMouseMovement) {
8455
- this.writeOut(ANSI.disableAnyEventTracking);
8456
- }
8457
- this.writeOut(ANSI.disableButtonEventTracking);
8458
- this.writeOut(ANSI.disableMouseTracking);
8459
- this.writeOut(ANSI.disableSGRMouseMode);
8460
8627
  this.capturedRenderable = undefined;
8461
8628
  this.mouseParser.reset();
8629
+ this.lib.disableMouse(this.rendererPtr);
8462
8630
  }
8463
8631
  set useThread(useThread) {
8464
8632
  this._useThread = useThread;
8465
8633
  this.lib.setUseThread(this.rendererPtr, useThread);
8466
8634
  }
8467
- setTerminalSize(width, height) {
8468
- this.handleResize(width, height);
8469
- }
8470
8635
  setupTerminal() {
8471
8636
  this.writeOut(ANSI.saveCursorState);
8472
8637
  if (this.stdin.setRawMode) {
@@ -8493,7 +8658,7 @@ Error details:
8493
8658
  }
8494
8659
  if (this.exitOnCtrlC && str === "\x03") {
8495
8660
  process.nextTick(() => {
8496
- process.exit(0);
8661
+ process.exit();
8497
8662
  });
8498
8663
  return;
8499
8664
  }
@@ -8504,6 +8669,8 @@ Error details:
8504
8669
  });
8505
8670
  if (this._useAlternateScreen) {
8506
8671
  this.writeOut(ANSI.switchToAlternateScreen);
8672
+ } else {
8673
+ this.writeOut(ANSI.makeRoomForRenderer(this.height - 1));
8507
8674
  }
8508
8675
  this.setCursorPosition(0, 0, false);
8509
8676
  }
@@ -8625,7 +8792,7 @@ Error details:
8625
8792
  }
8626
8793
  }
8627
8794
  handleResize(width, height) {
8628
- if (this.isShuttingDown)
8795
+ if (this.isDestroyed)
8629
8796
  return;
8630
8797
  if (this._splitHeight > 0) {
8631
8798
  this.processResize(width, height);
@@ -8762,44 +8929,31 @@ Error details:
8762
8929
  this._isRunning = false;
8763
8930
  }
8764
8931
  stop() {
8765
- if (this.isShuttingDown)
8932
+ if (this.isRunning && !this.isDestroyed) {
8933
+ this._isRunning = false;
8934
+ if (this.memorySnapshotTimer) {
8935
+ clearInterval(this.memorySnapshotTimer);
8936
+ this.memorySnapshotTimer = null;
8937
+ }
8938
+ if (this.renderTimeout) {
8939
+ clearTimeout(this.renderTimeout);
8940
+ this.renderTimeout = null;
8941
+ }
8942
+ }
8943
+ }
8944
+ destroy() {
8945
+ if (this.isDestroyed)
8766
8946
  return;
8767
- this._isRunning = false;
8768
- this.isShuttingDown = true;
8947
+ this.isDestroyed = true;
8769
8948
  this.waitingForPixelResolution = false;
8949
+ this.capturedRenderable = undefined;
8770
8950
  if (this.sigwinchHandler) {
8771
8951
  process.removeListener("SIGWINCH", this.sigwinchHandler);
8772
8952
  this.sigwinchHandler = null;
8773
8953
  }
8774
8954
  this._console.deactivate();
8955
+ this.lib.destroyRenderer(this.rendererPtr, this._useAlternateScreen, this._splitHeight);
8775
8956
  this.disableStdoutInterception();
8776
- if (this.renderTimeout) {
8777
- clearTimeout(this.renderTimeout);
8778
- this.renderTimeout = null;
8779
- }
8780
- if (this.memorySnapshotTimer) {
8781
- clearInterval(this.memorySnapshotTimer);
8782
- this.memorySnapshotTimer = null;
8783
- }
8784
- if (this._splitHeight > 0) {
8785
- const consoleEndLine = this._terminalHeight - this._splitHeight;
8786
- this.writeOut(ANSI.moveCursor(consoleEndLine, 1));
8787
- }
8788
- this.capturedRenderable = undefined;
8789
- if (this._useMouse) {
8790
- this.disableMouse();
8791
- }
8792
- this.writeOut(ANSI.resetCursorColor);
8793
- this.writeOut(ANSI.showCursor);
8794
- if (this._useAlternateScreen) {
8795
- this.writeOut(ANSI.switchToMainScreen);
8796
- }
8797
- }
8798
- destroy() {
8799
- if (this.isDestroyed)
8800
- return;
8801
- this.lib.destroyRenderer(this.rendererPtr);
8802
- this.isDestroyed = true;
8803
8957
  }
8804
8958
  startRenderLoop() {
8805
8959
  if (!this._isRunning)
@@ -8812,7 +8966,7 @@ Error details:
8812
8966
  this.loop();
8813
8967
  }
8814
8968
  async loop() {
8815
- if (this.rendering)
8969
+ if (this.rendering || this.isDestroyed)
8816
8970
  return;
8817
8971
  this.rendering = true;
8818
8972
  if (this.renderTimeout) {
@@ -9217,8 +9371,6 @@ class TextRenderable extends Renderable {
9217
9371
  set content(value) {
9218
9372
  this._text = typeof value === "string" ? stringToStyledText(value) : value;
9219
9373
  this.updateTextInfo();
9220
- this.setupMeasureFunc();
9221
- this.needsUpdate();
9222
9374
  }
9223
9375
  get fg() {
9224
9376
  return this._defaultFg;
@@ -9280,8 +9432,8 @@ class TextRenderable extends Renderable {
9280
9432
  const changed = this.selectionHelper.reevaluateSelection(this.width, this.height);
9281
9433
  if (changed) {
9282
9434
  this.syncSelectionToTextBuffer();
9283
- this.needsUpdate();
9284
9435
  }
9436
+ this.needsUpdate();
9285
9437
  }
9286
9438
  setupMeasureFunc() {
9287
9439
  if (this._positionType === "relative" && this._width === "auto") {
@@ -10286,6 +10438,7 @@ export {
10286
10438
  isDimensionType,
10287
10439
  hsvToRgb,
10288
10440
  hexToRgb,
10441
+ hastToStyledText,
10289
10442
  green,
10290
10443
  getKeyHandler,
10291
10444
  getCharacterPositions,
@@ -10301,6 +10454,7 @@ export {
10301
10454
  createTextAttributes,
10302
10455
  createCliRenderer,
10303
10456
  coordinateToCharacterIndex,
10457
+ capture,
10304
10458
  brightYellow,
10305
10459
  brightWhite,
10306
10460
  brightRed,
@@ -10337,8 +10491,10 @@ export {
10337
10491
  TextRenderable,
10338
10492
  TextBuffer,
10339
10493
  TextAttributes,
10494
+ TerminalConsole,
10340
10495
  TabSelectRenderableEvents,
10341
10496
  TabSelectRenderable,
10497
+ SyntaxStyle,
10342
10498
  StyledText,
10343
10499
  Selection,
10344
10500
  SelectRenderableEvents,
@@ -10358,6 +10514,7 @@ export {
10358
10514
  FrameBufferRenderable,
10359
10515
  DistortionEffect,
10360
10516
  DebugOverlayCorner,
10517
+ ConsolePosition,
10361
10518
  CliRenderer,
10362
10519
  CliRenderEvents,
10363
10520
  BrightnessEffect,