@opentui/core 0.0.0-20250929-69eb6c87 → 0.0.0-20250930-a8fe63ce

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
@@ -7,6 +7,7 @@ import {
7
7
  CliRenderEvents,
8
8
  CliRenderer,
9
9
  ConsolePosition,
10
+ DataPathsManager,
10
11
  DebugOverlayCorner,
11
12
  Edge,
12
13
  Gutter,
@@ -30,6 +31,8 @@ import {
30
31
  TerminalConsole,
31
32
  TextAttributes,
32
33
  TextBuffer,
34
+ TreeSitterClient,
35
+ addDefaultParsers,
33
36
  bg,
34
37
  bgBlack,
35
38
  bgBlue,
@@ -53,7 +56,9 @@ import {
53
56
  brightWhite,
54
57
  brightYellow,
55
58
  capture,
59
+ clearEnvCache,
56
60
  convertGlobalToLocalSelection,
61
+ convertThemeToStyles,
57
62
  coordinateToCharacterIndex,
58
63
  createCliRenderer,
59
64
  createTextAttributes,
@@ -63,6 +68,7 @@ import {
63
68
  env,
64
69
  envRegistry,
65
70
  exports_src,
71
+ extToFiletype,
66
72
  fg,
67
73
  fonts,
68
74
  generateEnvColored,
@@ -70,7 +76,9 @@ import {
70
76
  getBorderFromSides,
71
77
  getBorderSides,
72
78
  getCharacterPositions,
79
+ getDataPaths,
73
80
  getObjectsInViewport,
81
+ getTreeSitterClient,
74
82
  green,
75
83
  h,
76
84
  hastToStyledText,
@@ -83,6 +91,7 @@ import {
83
91
  isValidPercentage,
84
92
  italic,
85
93
  magenta,
94
+ main,
86
95
  maybeMakeRenderable,
87
96
  measureText,
88
97
  nonAlphanumericKeys,
@@ -103,6 +112,7 @@ import {
103
112
  parsePositionType,
104
113
  parseUnit,
105
114
  parseWrap,
115
+ pathToFiletype,
106
116
  red,
107
117
  registerEnvVar,
108
118
  renderFontToFrameBuffer,
@@ -113,12 +123,14 @@ import {
113
123
  strikethrough,
114
124
  stringToStyledText,
115
125
  t,
126
+ treeSitterToStyledText,
127
+ treeSitterToTextChunks,
116
128
  underline,
117
129
  visualizeRenderableTree,
118
130
  white,
119
131
  wrapWithDelegates,
120
132
  yellow
121
- } from "./index-yd5hcdcm.js";
133
+ } from "./index-h87jjatk.js";
122
134
  // src/post/filters.ts
123
135
  function applyScanlines(buffer, strength = 0.8, step = 2) {
124
136
  const width = buffer.width;
@@ -1414,6 +1426,353 @@ class BoxRenderable extends Renderable {
1414
1426
  }
1415
1427
  }
1416
1428
  }
1429
+ // src/renderables/TextBufferRenderable.ts
1430
+ class TextBufferRenderable extends Renderable {
1431
+ selectable = true;
1432
+ _defaultFg;
1433
+ _defaultBg;
1434
+ _defaultAttributes;
1435
+ _selectionBg;
1436
+ _selectionFg;
1437
+ _wrap = false;
1438
+ _wrapMode = "word";
1439
+ lastLocalSelection = null;
1440
+ textBuffer;
1441
+ _lineInfo = { lineStarts: [], lineWidths: [], maxLineWidth: 0 };
1442
+ _defaultOptions = {
1443
+ fg: RGBA.fromValues(1, 1, 1, 1),
1444
+ bg: RGBA.fromValues(0, 0, 0, 0),
1445
+ selectionBg: undefined,
1446
+ selectionFg: undefined,
1447
+ selectable: true,
1448
+ attributes: 0,
1449
+ wrap: true,
1450
+ wrapMode: "word"
1451
+ };
1452
+ constructor(ctx, options) {
1453
+ super(ctx, options);
1454
+ this._defaultFg = parseColor(options.fg ?? this._defaultOptions.fg);
1455
+ this._defaultBg = parseColor(options.bg ?? this._defaultOptions.bg);
1456
+ this._defaultAttributes = options.attributes ?? this._defaultOptions.attributes;
1457
+ this._selectionBg = options.selectionBg ? parseColor(options.selectionBg) : this._defaultOptions.selectionBg;
1458
+ this._selectionFg = options.selectionFg ? parseColor(options.selectionFg) : this._defaultOptions.selectionFg;
1459
+ this.selectable = options.selectable ?? this._defaultOptions.selectable;
1460
+ this._wrap = options.wrap ?? this._defaultOptions.wrap;
1461
+ this._wrapMode = options.wrapMode ?? this._defaultOptions.wrapMode;
1462
+ this.textBuffer = TextBuffer.create(this._ctx.widthMethod);
1463
+ this.textBuffer.setWrapMode(this._wrapMode);
1464
+ this.setupMeasureFunc();
1465
+ this.textBuffer.setDefaultFg(this._defaultFg);
1466
+ this.textBuffer.setDefaultBg(this._defaultBg);
1467
+ this.textBuffer.setDefaultAttributes(this._defaultAttributes);
1468
+ if (this._wrap && this.width > 0) {
1469
+ this.updateWrapWidth(this.width);
1470
+ }
1471
+ this.updateTextInfo();
1472
+ }
1473
+ get plainText() {
1474
+ return this.textBuffer.getPlainText();
1475
+ }
1476
+ get textLength() {
1477
+ return this.textBuffer.length;
1478
+ }
1479
+ get fg() {
1480
+ return this._defaultFg;
1481
+ }
1482
+ set fg(value) {
1483
+ const newColor = parseColor(value ?? this._defaultOptions.fg);
1484
+ if (this._defaultFg !== newColor) {
1485
+ this._defaultFg = newColor;
1486
+ this.textBuffer.setDefaultFg(this._defaultFg);
1487
+ this.onFgChanged(newColor);
1488
+ this.requestRender();
1489
+ }
1490
+ }
1491
+ get selectionBg() {
1492
+ return this._selectionBg;
1493
+ }
1494
+ set selectionBg(value) {
1495
+ const newColor = value ? parseColor(value) : this._defaultOptions.selectionBg;
1496
+ if (this._selectionBg !== newColor) {
1497
+ this._selectionBg = newColor;
1498
+ if (this.lastLocalSelection) {
1499
+ this.updateLocalSelection(this.lastLocalSelection);
1500
+ }
1501
+ this.requestRender();
1502
+ }
1503
+ }
1504
+ get selectionFg() {
1505
+ return this._selectionFg;
1506
+ }
1507
+ set selectionFg(value) {
1508
+ const newColor = value ? parseColor(value) : this._defaultOptions.selectionFg;
1509
+ if (this._selectionFg !== newColor) {
1510
+ this._selectionFg = newColor;
1511
+ if (this.lastLocalSelection) {
1512
+ this.updateLocalSelection(this.lastLocalSelection);
1513
+ }
1514
+ this.requestRender();
1515
+ }
1516
+ }
1517
+ get bg() {
1518
+ return this._defaultBg;
1519
+ }
1520
+ set bg(value) {
1521
+ const newColor = parseColor(value ?? this._defaultOptions.bg);
1522
+ if (this._defaultBg !== newColor) {
1523
+ this._defaultBg = newColor;
1524
+ this.textBuffer.setDefaultBg(this._defaultBg);
1525
+ this.onBgChanged(newColor);
1526
+ this.requestRender();
1527
+ }
1528
+ }
1529
+ get attributes() {
1530
+ return this._defaultAttributes;
1531
+ }
1532
+ set attributes(value) {
1533
+ if (this._defaultAttributes !== value) {
1534
+ this._defaultAttributes = value;
1535
+ this.textBuffer.setDefaultAttributes(this._defaultAttributes);
1536
+ this.onAttributesChanged(value);
1537
+ this.requestRender();
1538
+ }
1539
+ }
1540
+ get wrap() {
1541
+ return this._wrap;
1542
+ }
1543
+ set wrap(value) {
1544
+ if (this._wrap !== value) {
1545
+ this._wrap = value;
1546
+ this.textBuffer.setWrapWidth(this._wrap ? this.width : null);
1547
+ this.requestRender();
1548
+ }
1549
+ }
1550
+ get wrapMode() {
1551
+ return this._wrapMode;
1552
+ }
1553
+ set wrapMode(value) {
1554
+ if (this._wrapMode !== value) {
1555
+ this._wrapMode = value;
1556
+ this.textBuffer.setWrapMode(this._wrapMode);
1557
+ this.requestRender();
1558
+ }
1559
+ }
1560
+ onResize(width, height) {
1561
+ if (this.lastLocalSelection) {
1562
+ const changed = this.updateLocalSelection(this.lastLocalSelection);
1563
+ if (changed) {
1564
+ this.requestRender();
1565
+ }
1566
+ }
1567
+ }
1568
+ refreshLocalSelection() {
1569
+ if (this.lastLocalSelection) {
1570
+ return this.updateLocalSelection(this.lastLocalSelection);
1571
+ }
1572
+ return false;
1573
+ }
1574
+ updateLocalSelection(localSelection) {
1575
+ if (!localSelection?.isActive) {
1576
+ this.textBuffer.resetLocalSelection();
1577
+ return true;
1578
+ }
1579
+ return this.textBuffer.setLocalSelection(localSelection.anchorX, localSelection.anchorY, localSelection.focusX, localSelection.focusY, this._selectionBg, this._selectionFg);
1580
+ }
1581
+ updateTextInfo() {
1582
+ if (this.lastLocalSelection) {
1583
+ const changed = this.updateLocalSelection(this.lastLocalSelection);
1584
+ if (changed) {
1585
+ this.requestRender();
1586
+ }
1587
+ }
1588
+ this.yogaNode.markDirty();
1589
+ this.requestRender();
1590
+ }
1591
+ updateLineInfo() {
1592
+ const lineInfo = this.textBuffer.lineInfo;
1593
+ this._lineInfo.lineStarts = lineInfo.lineStarts;
1594
+ this._lineInfo.lineWidths = lineInfo.lineWidths;
1595
+ this._lineInfo.maxLineWidth = lineInfo.maxLineWidth;
1596
+ }
1597
+ updateWrapWidth(width) {
1598
+ this.textBuffer.setWrapWidth(width);
1599
+ this.updateLineInfo();
1600
+ }
1601
+ setupMeasureFunc() {
1602
+ const measureFunc = (width, widthMode, height, heightMode) => {
1603
+ if (this._wrap && this.width !== width) {
1604
+ this.updateWrapWidth(width);
1605
+ } else {
1606
+ this.updateLineInfo();
1607
+ }
1608
+ const measuredWidth = this._lineInfo.maxLineWidth;
1609
+ const measuredHeight = this._lineInfo.lineStarts.length;
1610
+ return {
1611
+ width: Math.max(1, measuredWidth),
1612
+ height: Math.max(1, measuredHeight)
1613
+ };
1614
+ };
1615
+ this.yogaNode.setMeasureFunc(measureFunc);
1616
+ }
1617
+ insertChunk(chunk, index) {
1618
+ this.textBuffer.insertChunkGroup(index ?? this.textBuffer.chunkGroupCount, chunk.text, chunk.fg, chunk.bg, chunk.attributes);
1619
+ this.updateTextInfo();
1620
+ }
1621
+ removeChunk(index) {
1622
+ this.textBuffer.removeChunkGroup(index);
1623
+ this.updateTextInfo();
1624
+ }
1625
+ replaceChunk(index, chunk) {
1626
+ this.textBuffer.replaceChunkGroup(index, chunk.text, chunk.fg, chunk.bg, chunk.attributes);
1627
+ this.updateTextInfo();
1628
+ }
1629
+ shouldStartSelection(x, y) {
1630
+ if (!this.selectable)
1631
+ return false;
1632
+ const localX = x - this.x;
1633
+ const localY = y - this.y;
1634
+ return localX >= 0 && localX < this.width && localY >= 0 && localY < this.height;
1635
+ }
1636
+ onSelectionChanged(selection) {
1637
+ const localSelection = convertGlobalToLocalSelection(selection, this.x, this.y);
1638
+ this.lastLocalSelection = localSelection;
1639
+ const changed = this.updateLocalSelection(localSelection);
1640
+ if (changed) {
1641
+ this.requestRender();
1642
+ }
1643
+ return this.hasSelection();
1644
+ }
1645
+ getSelectedText() {
1646
+ return this.textBuffer.getSelectedText();
1647
+ }
1648
+ hasSelection() {
1649
+ return this.textBuffer.hasSelection();
1650
+ }
1651
+ getSelection() {
1652
+ return this.textBuffer.getSelection();
1653
+ }
1654
+ render(buffer, deltaTime) {
1655
+ if (!this.visible)
1656
+ return;
1657
+ this.markClean();
1658
+ this._ctx.addToHitGrid(this.x, this.y, this.width, this.height, this.num);
1659
+ this.renderSelf(buffer);
1660
+ }
1661
+ renderSelf(buffer) {
1662
+ if (this.textBuffer.ptr) {
1663
+ const clipRect = {
1664
+ x: this.x,
1665
+ y: this.y,
1666
+ width: this.width,
1667
+ height: this.height
1668
+ };
1669
+ buffer.drawTextBuffer(this.textBuffer, this.x, this.y, clipRect);
1670
+ }
1671
+ }
1672
+ destroy() {
1673
+ this.textBuffer.destroy();
1674
+ super.destroy();
1675
+ }
1676
+ onFgChanged(newColor) {}
1677
+ onBgChanged(newColor) {}
1678
+ onAttributesChanged(newAttributes) {}
1679
+ }
1680
+
1681
+ // src/renderables/Code.ts
1682
+ class CodeRenderable extends TextBufferRenderable {
1683
+ _content;
1684
+ _filetype;
1685
+ _syntaxStyle;
1686
+ _isHighlighting = false;
1687
+ _treeSitterClient;
1688
+ _pendingRehighlight = false;
1689
+ _contentDefaultOptions = {
1690
+ content: ""
1691
+ };
1692
+ constructor(ctx, options) {
1693
+ super(ctx, options);
1694
+ this._content = options.content ?? this._contentDefaultOptions.content;
1695
+ this._filetype = options.filetype;
1696
+ this._syntaxStyle = options.syntaxStyle;
1697
+ this._treeSitterClient = options.treeSitterClient ?? getTreeSitterClient();
1698
+ this.updateContent(this._content);
1699
+ }
1700
+ get content() {
1701
+ return this._content;
1702
+ }
1703
+ set content(value) {
1704
+ if (this._content !== value) {
1705
+ this._content = value;
1706
+ this.updateContent(value);
1707
+ }
1708
+ }
1709
+ get filetype() {
1710
+ return this._filetype;
1711
+ }
1712
+ set filetype(value) {
1713
+ if (this._filetype !== value) {
1714
+ this._filetype = value;
1715
+ this.updateContent(this._content);
1716
+ }
1717
+ }
1718
+ get syntaxStyle() {
1719
+ return this._syntaxStyle;
1720
+ }
1721
+ set syntaxStyle(value) {
1722
+ if (this._syntaxStyle !== value) {
1723
+ this._syntaxStyle = value;
1724
+ this.updateContent(this._content);
1725
+ }
1726
+ }
1727
+ async updateContent(content) {
1728
+ if (content.length === 0)
1729
+ return;
1730
+ if (this._isHighlighting) {
1731
+ this._pendingRehighlight = true;
1732
+ return;
1733
+ }
1734
+ if (!this._filetype) {
1735
+ this.fallback(content);
1736
+ return;
1737
+ }
1738
+ this._isHighlighting = true;
1739
+ try {
1740
+ const styledText = await treeSitterToStyledText(content, this._filetype, this._syntaxStyle, this._treeSitterClient);
1741
+ if (this.isDestroyed)
1742
+ return;
1743
+ this.textBuffer.setStyledText(styledText);
1744
+ this.updateTextInfo();
1745
+ } catch (error) {
1746
+ console.warn("Code highlighting failed, falling back to plain text:", error);
1747
+ this.fallback(content);
1748
+ } finally {
1749
+ this._isHighlighting = false;
1750
+ if (this._pendingRehighlight) {
1751
+ this._pendingRehighlight = false;
1752
+ process.nextTick(() => this.updateContent(this._content));
1753
+ }
1754
+ }
1755
+ }
1756
+ fallback(content) {
1757
+ const fallbackStyledText = this.createFallbackStyledText(content);
1758
+ if (this.isDestroyed)
1759
+ return;
1760
+ this.textBuffer.setStyledText(fallbackStyledText);
1761
+ this.updateTextInfo();
1762
+ }
1763
+ createFallbackStyledText(content) {
1764
+ const chunks = [
1765
+ {
1766
+ __isChunk: true,
1767
+ text: content,
1768
+ fg: this._defaultFg,
1769
+ bg: this._defaultBg,
1770
+ attributes: this._defaultAttributes
1771
+ }
1772
+ ];
1773
+ return new StyledText(chunks);
1774
+ }
1775
+ }
1417
1776
  // src/renderables/FrameBuffer.ts
1418
1777
  class FrameBufferRenderable extends Renderable {
1419
1778
  frameBuffer;
@@ -1671,52 +2030,19 @@ class RootTextNodeRenderable extends TextNodeRenderable {
1671
2030
  }
1672
2031
 
1673
2032
  // src/renderables/Text.ts
1674
- class TextRenderable extends Renderable {
1675
- selectable = true;
2033
+ class TextRenderable extends TextBufferRenderable {
1676
2034
  _text;
1677
2035
  _hasManualStyledText = false;
1678
- _defaultFg;
1679
- _defaultBg;
1680
- _defaultAttributes;
1681
- _selectionBg;
1682
- _selectionFg;
1683
- _wrap = false;
1684
- _wrapMode = "word";
1685
- lastLocalSelection = null;
1686
- textBuffer;
1687
- _lineInfo = { lineStarts: [], lineWidths: [], maxLineWidth: 0 };
1688
2036
  rootTextNode;
1689
- _defaultOptions = {
1690
- content: "",
1691
- fg: RGBA.fromValues(1, 1, 1, 1),
1692
- bg: RGBA.fromValues(0, 0, 0, 0),
1693
- selectionBg: undefined,
1694
- selectionFg: undefined,
1695
- selectable: true,
1696
- attributes: 0,
1697
- wrap: true,
1698
- wrapMode: "word"
2037
+ _contentDefaultOptions = {
2038
+ content: ""
1699
2039
  };
1700
2040
  constructor(ctx, options) {
1701
2041
  super(ctx, options);
1702
- const content = options.content ?? this._defaultOptions.content;
2042
+ const content = options.content ?? this._contentDefaultOptions.content;
1703
2043
  const styledText = typeof content === "string" ? stringToStyledText(content) : content;
1704
2044
  this._text = styledText;
1705
- this._hasManualStyledText = !!options.content;
1706
- this._defaultFg = parseColor(options.fg ?? this._defaultOptions.fg);
1707
- this._defaultBg = parseColor(options.bg ?? this._defaultOptions.bg);
1708
- this._defaultAttributes = options.attributes ?? this._defaultOptions.attributes;
1709
- this._selectionBg = options.selectionBg ? parseColor(options.selectionBg) : this._defaultOptions.selectionBg;
1710
- this._selectionFg = options.selectionFg ? parseColor(options.selectionFg) : this._defaultOptions.selectionFg;
1711
- this.selectable = options.selectable ?? this._defaultOptions.selectable;
1712
- this._wrap = options.wrap ?? this._defaultOptions.wrap;
1713
- this._wrapMode = options.wrapMode ?? this._defaultOptions.wrapMode;
1714
- this.textBuffer = TextBuffer.create(this._ctx.widthMethod);
1715
- this.textBuffer.setWrapMode(this._wrapMode);
1716
- this.setupMeasureFunc();
1717
- this.textBuffer.setDefaultFg(this._defaultFg);
1718
- this.textBuffer.setDefaultBg(this._defaultBg);
1719
- this.textBuffer.setDefaultAttributes(this._defaultAttributes);
2045
+ this._hasManualStyledText = options.content !== undefined && content !== "";
1720
2046
  this.rootTextNode = new RootTextNodeRenderable(ctx, {
1721
2047
  id: `${this.id}-root`,
1722
2048
  fg: this._defaultFg,
@@ -1724,11 +2050,6 @@ class TextRenderable extends Renderable {
1724
2050
  attributes: this._defaultAttributes
1725
2051
  }, this);
1726
2052
  this.updateTextBuffer(styledText);
1727
- this._text.mount(this);
1728
- if (this._wrap && this.width > 0) {
1729
- this.updateWrapWidth(this.width);
1730
- }
1731
- this.updateTextInfo();
1732
2053
  }
1733
2054
  updateTextBuffer(styledText) {
1734
2055
  this.textBuffer.setStyledText(styledText);
@@ -1738,12 +2059,6 @@ class TextRenderable extends Renderable {
1738
2059
  get content() {
1739
2060
  return this._text;
1740
2061
  }
1741
- get plainText() {
1742
- return this.textBuffer.getPlainText();
1743
- }
1744
- get textLength() {
1745
- return this.textBuffer.length;
1746
- }
1747
2062
  get chunks() {
1748
2063
  return this._text.chunks;
1749
2064
  }
@@ -1755,166 +2070,26 @@ class TextRenderable extends Renderable {
1755
2070
  const styledText = typeof value === "string" ? stringToStyledText(value) : value;
1756
2071
  if (this._text !== styledText) {
1757
2072
  this._text = styledText;
1758
- styledText.mount(this);
1759
2073
  this.updateTextBuffer(styledText);
1760
2074
  this.updateTextInfo();
1761
2075
  }
1762
2076
  }
1763
- get fg() {
1764
- return this._defaultFg;
1765
- }
1766
- set fg(value) {
1767
- const newColor = parseColor(value ?? this._defaultOptions.fg);
1768
- this.rootTextNode.fg = newColor;
1769
- if (this._defaultFg !== newColor) {
1770
- this._defaultFg = newColor;
1771
- this.textBuffer.setDefaultFg(this._defaultFg);
1772
- this.rootTextNode.fg = newColor;
1773
- this.requestRender();
1774
- }
1775
- }
1776
- get selectionBg() {
1777
- return this._selectionBg;
1778
- }
1779
- set selectionBg(value) {
1780
- const newColor = value ? parseColor(value) : this._defaultOptions.selectionBg;
1781
- if (this._selectionBg !== newColor) {
1782
- this._selectionBg = newColor;
1783
- if (this.lastLocalSelection) {
1784
- this.updateLocalSelection(this.lastLocalSelection);
1785
- }
1786
- this.requestRender();
1787
- }
1788
- }
1789
- get selectionFg() {
1790
- return this._selectionFg;
1791
- }
1792
- set selectionFg(value) {
1793
- const newColor = value ? parseColor(value) : this._defaultOptions.selectionFg;
1794
- if (this._selectionFg !== newColor) {
1795
- this._selectionFg = newColor;
1796
- if (this.lastLocalSelection) {
1797
- this.updateLocalSelection(this.lastLocalSelection);
1798
- }
1799
- this.requestRender();
1800
- }
1801
- }
1802
- get bg() {
1803
- return this._defaultBg;
1804
- }
1805
- set bg(value) {
1806
- const newColor = parseColor(value ?? this._defaultOptions.bg);
1807
- this.rootTextNode.bg = newColor;
1808
- if (this._defaultBg !== newColor) {
1809
- this._defaultBg = newColor;
1810
- this.textBuffer.setDefaultBg(this._defaultBg);
1811
- this.rootTextNode.bg = newColor;
1812
- this.requestRender();
1813
- }
1814
- }
1815
- get attributes() {
1816
- return this._defaultAttributes;
1817
- }
1818
- set attributes(value) {
1819
- if (this._defaultAttributes !== value) {
1820
- this._defaultAttributes = value;
1821
- this.textBuffer.setDefaultAttributes(this._defaultAttributes);
1822
- this.rootTextNode.attributes = value;
1823
- this.requestRender();
1824
- }
1825
- }
1826
- get wrap() {
1827
- return this._wrap;
1828
- }
1829
- set wrap(value) {
1830
- if (this._wrap !== value) {
1831
- this._wrap = value;
1832
- this.textBuffer.setWrapWidth(this._wrap ? this.width : null);
1833
- this.requestRender();
1834
- }
1835
- }
1836
- get wrapMode() {
1837
- return this._wrapMode;
1838
- }
1839
- set wrapMode(value) {
1840
- if (this._wrapMode !== value) {
1841
- this._wrapMode = value;
1842
- this.textBuffer.setWrapMode(this._wrapMode);
1843
- this.requestRender();
1844
- }
1845
- }
1846
- onResize(width, height) {
1847
- if (this.lastLocalSelection) {
1848
- const changed = this.updateLocalSelection(this.lastLocalSelection);
1849
- if (changed) {
1850
- this.requestRender();
1851
- }
1852
- }
1853
- }
1854
- updateLocalSelection(localSelection) {
1855
- if (!localSelection?.isActive) {
1856
- this.textBuffer.resetLocalSelection();
1857
- return true;
1858
- }
1859
- return this.textBuffer.setLocalSelection(localSelection.anchorX, localSelection.anchorY, localSelection.focusX, localSelection.focusY, this._selectionBg, this._selectionFg);
1860
- }
1861
- updateTextInfo() {
1862
- if (this.lastLocalSelection) {
1863
- const changed = this.updateLocalSelection(this.lastLocalSelection);
1864
- if (changed) {
1865
- this.requestRender();
1866
- }
1867
- }
1868
- this.yogaNode.markDirty();
1869
- this.requestRender();
1870
- }
1871
- updateLineInfo() {
1872
- const lineInfo = this.textBuffer.lineInfo;
1873
- this._lineInfo.lineStarts = lineInfo.lineStarts;
1874
- this._lineInfo.lineWidths = lineInfo.lineWidths;
1875
- this._lineInfo.maxLineWidth = lineInfo.maxLineWidth;
1876
- }
1877
- updateWrapWidth(width) {
1878
- this.textBuffer.setWrapWidth(width);
1879
- this.updateLineInfo();
1880
- }
1881
- setupMeasureFunc() {
1882
- const measureFunc = (width, widthMode, height, heightMode) => {
1883
- if (this._wrap) {
1884
- if (this.width !== width) {
1885
- this.updateWrapWidth(width);
1886
- }
1887
- } else {
1888
- this.updateLineInfo();
1889
- }
1890
- const measuredWidth = this._lineInfo.maxLineWidth;
1891
- const measuredHeight = this._lineInfo.lineStarts.length;
1892
- return {
1893
- width: Math.max(1, measuredWidth),
1894
- height: Math.max(1, measuredHeight)
1895
- };
1896
- };
1897
- this.yogaNode.setMeasureFunc(measureFunc);
1898
- }
1899
2077
  insertChunk(chunk, index) {
1900
- this.textBuffer.insertChunkGroup(index ?? this.textBuffer.chunkGroupCount, chunk.text, chunk.fg, chunk.bg, chunk.attributes);
1901
- this.updateTextInfo();
2078
+ super.insertChunk(chunk, index);
1902
2079
  this.clearChunks(this._text);
1903
2080
  }
1904
- removeChunk(chunk) {
2081
+ removeChunkByObject(chunk) {
1905
2082
  const index = this._text.chunks.indexOf(chunk);
1906
2083
  if (index === -1)
1907
2084
  return;
1908
- this.textBuffer.removeChunkGroup(index);
1909
- this.updateTextInfo();
2085
+ super.removeChunk(index);
1910
2086
  this.clearChunks(this._text);
1911
2087
  }
1912
- replaceChunk(chunk, oldChunk) {
2088
+ replaceChunkByObject(chunk, oldChunk) {
1913
2089
  const index = this._text.chunks.indexOf(oldChunk);
1914
2090
  if (index === -1)
1915
2091
  return;
1916
- this.textBuffer.replaceChunkGroup(index, chunk.text, chunk.fg, chunk.bg, chunk.attributes);
1917
- this.updateTextInfo();
2092
+ super.replaceChunk(index, chunk);
1918
2093
  this.clearChunks(this._text);
1919
2094
  }
1920
2095
  updateTextFromNodes() {
@@ -1925,7 +2100,7 @@ class TextRenderable extends Renderable {
1925
2100
  attributes: this._defaultAttributes
1926
2101
  });
1927
2102
  this.textBuffer.setStyledText(new StyledText(chunks));
1928
- this.updateLineInfo();
2103
+ this.refreshLocalSelection();
1929
2104
  this.yogaNode.markDirty();
1930
2105
  }
1931
2106
  }
@@ -1949,59 +2124,23 @@ class TextRenderable extends Renderable {
1949
2124
  this.rootTextNode.clear();
1950
2125
  const emptyStyledText = stringToStyledText("");
1951
2126
  this._text = emptyStyledText;
1952
- emptyStyledText.mount(this);
1953
2127
  this.updateTextBuffer(emptyStyledText);
1954
2128
  this.updateTextInfo();
1955
2129
  this.requestRender();
1956
2130
  }
1957
- shouldStartSelection(x, y) {
1958
- if (!this.selectable)
1959
- return false;
1960
- const localX = x - this.x;
1961
- const localY = y - this.y;
1962
- return localX >= 0 && localX < this.width && localY >= 0 && localY < this.height;
1963
- }
1964
- onSelectionChanged(selection) {
1965
- const localSelection = convertGlobalToLocalSelection(selection, this.x, this.y);
1966
- this.lastLocalSelection = localSelection;
1967
- const changed = this.updateLocalSelection(localSelection);
1968
- if (changed) {
1969
- this.requestRender();
1970
- }
1971
- return this.hasSelection();
1972
- }
1973
- getSelectedText() {
1974
- return this.textBuffer.getSelectedText();
1975
- }
1976
- hasSelection() {
1977
- return this.textBuffer.hasSelection();
1978
- }
1979
- getSelection() {
1980
- return this.textBuffer.getSelection();
1981
- }
1982
2131
  onLifecyclePass = () => {
1983
2132
  this.updateTextFromNodes();
1984
2133
  };
1985
- render(buffer, deltaTime) {
1986
- if (!this.visible)
1987
- return;
1988
- this.markClean();
1989
- this._ctx.addToHitGrid(this.x, this.y, this.width, this.height, this.num);
1990
- this.renderSelf(buffer);
2134
+ onFgChanged(newColor) {
2135
+ this.rootTextNode.fg = newColor;
1991
2136
  }
1992
- renderSelf(buffer) {
1993
- if (this.textBuffer.ptr) {
1994
- const clipRect = {
1995
- x: this.x,
1996
- y: this.y,
1997
- width: this.width,
1998
- height: this.height
1999
- };
2000
- buffer.drawTextBuffer(this.textBuffer, this.x, this.y, clipRect);
2001
- }
2137
+ onBgChanged(newColor) {
2138
+ this.rootTextNode.bg = newColor;
2139
+ }
2140
+ onAttributesChanged(newAttributes) {
2141
+ this.rootTextNode.attributes = newAttributes;
2002
2142
  }
2003
2143
  destroy() {
2004
- this.textBuffer.destroy();
2005
2144
  this.rootTextNode.children.length = 0;
2006
2145
  super.destroy();
2007
2146
  }
@@ -4170,7 +4309,10 @@ export {
4170
4309
  white,
4171
4310
  vstyles,
4172
4311
  visualizeRenderableTree,
4312
+ main as updateAssets,
4173
4313
  underline,
4314
+ treeSitterToTextChunks,
4315
+ treeSitterToStyledText,
4174
4316
  t,
4175
4317
  stringToStyledText,
4176
4318
  strikethrough,
@@ -4181,6 +4323,7 @@ export {
4181
4323
  renderFontToFrameBuffer,
4182
4324
  registerEnvVar,
4183
4325
  red,
4326
+ pathToFiletype,
4184
4327
  parseWrap,
4185
4328
  parseUnit,
4186
4329
  parsePositionType,
@@ -4213,6 +4356,8 @@ export {
4213
4356
  hastToStyledText,
4214
4357
  h,
4215
4358
  green,
4359
+ getTreeSitterClient,
4360
+ getDataPaths,
4216
4361
  getCharacterPositions,
4217
4362
  getBorderSides,
4218
4363
  getBorderFromSides,
@@ -4220,6 +4365,7 @@ export {
4220
4365
  generateEnvColored,
4221
4366
  fonts,
4222
4367
  fg,
4368
+ extToFiletype,
4223
4369
  envRegistry,
4224
4370
  env,
4225
4371
  engine,
@@ -4230,7 +4376,9 @@ export {
4230
4376
  createTextAttributes,
4231
4377
  createCliRenderer,
4232
4378
  coordinateToCharacterIndex,
4379
+ convertThemeToStyles,
4233
4380
  convertGlobalToLocalSelection,
4381
+ clearEnvCache,
4234
4382
  capture,
4235
4383
  brightYellow,
4236
4384
  brightWhite,
@@ -4261,12 +4409,15 @@ export {
4261
4409
  applyGrayscale,
4262
4410
  applyChromaticAberration,
4263
4411
  applyAsciiArt,
4412
+ addDefaultParsers,
4264
4413
  exports_src as Yoga,
4265
4414
  VignetteEffect,
4266
4415
  VRenderable,
4416
+ TreeSitterClient,
4267
4417
  Timeline,
4268
4418
  TextRenderable,
4269
4419
  TextNodeRenderable,
4420
+ TextBufferRenderable,
4270
4421
  TextBuffer,
4271
4422
  TextAttributes,
4272
4423
  Text,
@@ -4305,7 +4456,9 @@ export {
4305
4456
  FrameBuffer,
4306
4457
  DistortionEffect,
4307
4458
  DebugOverlayCorner,
4459
+ DataPathsManager,
4308
4460
  ConsolePosition,
4461
+ CodeRenderable,
4309
4462
  CliRenderer,
4310
4463
  CliRenderEvents,
4311
4464
  BrightnessEffect,
@@ -4322,5 +4475,5 @@ export {
4322
4475
  ASCIIFont
4323
4476
  };
4324
4477
 
4325
- //# debugId=A2F53C1AC6A2B62F64756E2164756E21
4478
+ //# debugId=E76E0BC5C702E8AC64756E2164756E21
4326
4479
  //# sourceMappingURL=index.js.map