@opentui/core 0.1.25 → 0.1.26

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.
Files changed (54) hide show
  1. package/3d.js +1 -1
  2. package/README.md +5 -1
  3. package/Renderable.d.ts +8 -7
  4. package/animation/Timeline.d.ts +2 -1
  5. package/assets/javascript/highlights.scm +205 -0
  6. package/assets/javascript/tree-sitter-javascript.wasm +0 -0
  7. package/assets/typescript/highlights.scm +604 -0
  8. package/assets/typescript/tree-sitter-typescript.wasm +0 -0
  9. package/{index-6kvgbzah.js → index-pxa2sv92.js} +1426 -117
  10. package/index-pxa2sv92.js.map +52 -0
  11. package/index.js +432 -248
  12. package/index.js.map +13 -11
  13. package/lib/KeyHandler.d.ts +51 -12
  14. package/lib/data-paths.d.ts +26 -0
  15. package/lib/debounce.d.ts +42 -0
  16. package/lib/env.d.ts +2 -1
  17. package/lib/hast-styled-text.d.ts +3 -23
  18. package/lib/index.d.ts +5 -0
  19. package/lib/parse.keypress.d.ts +2 -2
  20. package/lib/queue.d.ts +15 -0
  21. package/lib/scroll-acceleration.d.ts +43 -0
  22. package/lib/singleton.d.ts +2 -0
  23. package/lib/styled-text.d.ts +0 -15
  24. package/lib/syntax-style.d.ts +36 -0
  25. package/lib/tree-sitter/assets/update.d.ts +11 -0
  26. package/lib/tree-sitter/client.d.ts +46 -0
  27. package/lib/tree-sitter/default-parsers.d.ts +2 -0
  28. package/lib/tree-sitter/download-utils.d.ts +21 -0
  29. package/lib/tree-sitter/index.d.ts +10 -0
  30. package/lib/tree-sitter/parser.worker.d.ts +1 -0
  31. package/lib/tree-sitter/resolve-ft.d.ts +2 -0
  32. package/lib/tree-sitter/types.d.ts +64 -0
  33. package/lib/tree-sitter-styled-text.d.ts +7 -0
  34. package/lib/validate-dir-name.d.ts +1 -0
  35. package/package.json +21 -8
  36. package/parser.worker.js +640 -0
  37. package/parser.worker.js.map +11 -0
  38. package/renderables/Code.d.ts +31 -0
  39. package/renderables/Input.d.ts +2 -2
  40. package/renderables/ScrollBar.d.ts +2 -2
  41. package/renderables/ScrollBox.d.ts +7 -3
  42. package/renderables/Select.d.ts +2 -2
  43. package/renderables/TabSelect.d.ts +2 -2
  44. package/renderables/Text.d.ts +10 -67
  45. package/renderables/TextBufferRenderable.d.ts +81 -0
  46. package/renderables/TextNode.d.ts +1 -0
  47. package/renderables/index.d.ts +2 -0
  48. package/renderer.d.ts +4 -2
  49. package/testing/spy.d.ts +7 -0
  50. package/testing.d.ts +1 -0
  51. package/testing.js +17 -2
  52. package/testing.js.map +5 -4
  53. package/types.d.ts +2 -1
  54. package/index-6kvgbzah.js.map +0 -39
package/index.js CHANGED
@@ -7,16 +7,22 @@ import {
7
7
  CliRenderEvents,
8
8
  CliRenderer,
9
9
  ConsolePosition,
10
+ DataPathsManager,
10
11
  DebugOverlayCorner,
11
12
  Edge,
12
13
  Gutter,
14
+ InternalKeyHandler,
15
+ KeyEvent,
13
16
  KeyHandler,
14
17
  LayoutEvents,
18
+ LinearScrollAccel,
15
19
  LogLevel,
20
+ MacOSScrollAccel,
16
21
  MouseButton,
17
22
  MouseEvent,
18
23
  MouseParser,
19
24
  OptimizedBuffer,
25
+ PasteEvent,
20
26
  RGBA,
21
27
  Renderable,
22
28
  RenderableEvents,
@@ -27,6 +33,8 @@ import {
27
33
  TerminalConsole,
28
34
  TextAttributes,
29
35
  TextBuffer,
36
+ TreeSitterClient,
37
+ addDefaultParsers,
30
38
  bg,
31
39
  bgBlack,
32
40
  bgBlue,
@@ -50,7 +58,9 @@ import {
50
58
  brightWhite,
51
59
  brightYellow,
52
60
  capture,
61
+ clearEnvCache,
53
62
  convertGlobalToLocalSelection,
63
+ convertThemeToStyles,
54
64
  coordinateToCharacterIndex,
55
65
  createCliRenderer,
56
66
  createTextAttributes,
@@ -60,6 +70,7 @@ import {
60
70
  env,
61
71
  envRegistry,
62
72
  exports_src,
73
+ extToFiletype,
63
74
  fg,
64
75
  fonts,
65
76
  generateEnvColored,
@@ -67,7 +78,9 @@ import {
67
78
  getBorderFromSides,
68
79
  getBorderSides,
69
80
  getCharacterPositions,
81
+ getDataPaths,
70
82
  getObjectsInViewport,
83
+ getTreeSitterClient,
71
84
  green,
72
85
  h,
73
86
  hastToStyledText,
@@ -80,6 +93,7 @@ import {
80
93
  isValidPercentage,
81
94
  italic,
82
95
  magenta,
96
+ main,
83
97
  maybeMakeRenderable,
84
98
  measureText,
85
99
  nonAlphanumericKeys,
@@ -100,6 +114,7 @@ import {
100
114
  parsePositionType,
101
115
  parseUnit,
102
116
  parseWrap,
117
+ pathToFiletype,
103
118
  red,
104
119
  registerEnvVar,
105
120
  renderFontToFrameBuffer,
@@ -110,12 +125,14 @@ import {
110
125
  strikethrough,
111
126
  stringToStyledText,
112
127
  t,
128
+ treeSitterToStyledText,
129
+ treeSitterToTextChunks,
113
130
  underline,
114
131
  visualizeRenderableTree,
115
132
  white,
116
133
  wrapWithDelegates,
117
134
  yellow
118
- } from "./index-6kvgbzah.js";
135
+ } from "./index-pxa2sv92.js";
119
136
  // src/post/filters.ts
120
137
  function applyScanlines(buffer, strength = 0.8, step = 2) {
121
138
  const width = buffer.width;
@@ -1411,6 +1428,354 @@ class BoxRenderable extends Renderable {
1411
1428
  }
1412
1429
  }
1413
1430
  }
1431
+ // src/renderables/TextBufferRenderable.ts
1432
+ class TextBufferRenderable extends Renderable {
1433
+ selectable = true;
1434
+ _defaultFg;
1435
+ _defaultBg;
1436
+ _defaultAttributes;
1437
+ _selectionBg;
1438
+ _selectionFg;
1439
+ _wrap = false;
1440
+ _wrapMode = "word";
1441
+ lastLocalSelection = null;
1442
+ textBuffer;
1443
+ _lineInfo = { lineStarts: [], lineWidths: [], maxLineWidth: 0 };
1444
+ _defaultOptions = {
1445
+ fg: RGBA.fromValues(1, 1, 1, 1),
1446
+ bg: RGBA.fromValues(0, 0, 0, 0),
1447
+ selectionBg: undefined,
1448
+ selectionFg: undefined,
1449
+ selectable: true,
1450
+ attributes: 0,
1451
+ wrap: true,
1452
+ wrapMode: "word"
1453
+ };
1454
+ constructor(ctx, options) {
1455
+ super(ctx, options);
1456
+ this._defaultFg = parseColor(options.fg ?? this._defaultOptions.fg);
1457
+ this._defaultBg = parseColor(options.bg ?? this._defaultOptions.bg);
1458
+ this._defaultAttributes = options.attributes ?? this._defaultOptions.attributes;
1459
+ this._selectionBg = options.selectionBg ? parseColor(options.selectionBg) : this._defaultOptions.selectionBg;
1460
+ this._selectionFg = options.selectionFg ? parseColor(options.selectionFg) : this._defaultOptions.selectionFg;
1461
+ this.selectable = options.selectable ?? this._defaultOptions.selectable;
1462
+ this._wrap = options.wrap ?? this._defaultOptions.wrap;
1463
+ this._wrapMode = options.wrapMode ?? this._defaultOptions.wrapMode;
1464
+ this.textBuffer = TextBuffer.create(this._ctx.widthMethod);
1465
+ this.textBuffer.setWrapMode(this._wrapMode);
1466
+ this.setupMeasureFunc();
1467
+ this.textBuffer.setDefaultFg(this._defaultFg);
1468
+ this.textBuffer.setDefaultBg(this._defaultBg);
1469
+ this.textBuffer.setDefaultAttributes(this._defaultAttributes);
1470
+ if (this._wrap && this.width > 0) {
1471
+ this.updateWrapWidth(this.width);
1472
+ }
1473
+ this.updateTextInfo();
1474
+ }
1475
+ get plainText() {
1476
+ return this.textBuffer.getPlainText();
1477
+ }
1478
+ get textLength() {
1479
+ return this.textBuffer.length;
1480
+ }
1481
+ get fg() {
1482
+ return this._defaultFg;
1483
+ }
1484
+ set fg(value) {
1485
+ const newColor = parseColor(value ?? this._defaultOptions.fg);
1486
+ if (this._defaultFg !== newColor) {
1487
+ this._defaultFg = newColor;
1488
+ this.textBuffer.setDefaultFg(this._defaultFg);
1489
+ this.onFgChanged(newColor);
1490
+ this.requestRender();
1491
+ }
1492
+ }
1493
+ get selectionBg() {
1494
+ return this._selectionBg;
1495
+ }
1496
+ set selectionBg(value) {
1497
+ const newColor = value ? parseColor(value) : this._defaultOptions.selectionBg;
1498
+ if (this._selectionBg !== newColor) {
1499
+ this._selectionBg = newColor;
1500
+ if (this.lastLocalSelection) {
1501
+ this.updateLocalSelection(this.lastLocalSelection);
1502
+ }
1503
+ this.requestRender();
1504
+ }
1505
+ }
1506
+ get selectionFg() {
1507
+ return this._selectionFg;
1508
+ }
1509
+ set selectionFg(value) {
1510
+ const newColor = value ? parseColor(value) : this._defaultOptions.selectionFg;
1511
+ if (this._selectionFg !== newColor) {
1512
+ this._selectionFg = newColor;
1513
+ if (this.lastLocalSelection) {
1514
+ this.updateLocalSelection(this.lastLocalSelection);
1515
+ }
1516
+ this.requestRender();
1517
+ }
1518
+ }
1519
+ get bg() {
1520
+ return this._defaultBg;
1521
+ }
1522
+ set bg(value) {
1523
+ const newColor = parseColor(value ?? this._defaultOptions.bg);
1524
+ if (this._defaultBg !== newColor) {
1525
+ this._defaultBg = newColor;
1526
+ this.textBuffer.setDefaultBg(this._defaultBg);
1527
+ this.onBgChanged(newColor);
1528
+ this.requestRender();
1529
+ }
1530
+ }
1531
+ get attributes() {
1532
+ return this._defaultAttributes;
1533
+ }
1534
+ set attributes(value) {
1535
+ if (this._defaultAttributes !== value) {
1536
+ this._defaultAttributes = value;
1537
+ this.textBuffer.setDefaultAttributes(this._defaultAttributes);
1538
+ this.onAttributesChanged(value);
1539
+ this.requestRender();
1540
+ }
1541
+ }
1542
+ get wrap() {
1543
+ return this._wrap;
1544
+ }
1545
+ set wrap(value) {
1546
+ if (this._wrap !== value) {
1547
+ this._wrap = value;
1548
+ this.textBuffer.setWrapWidth(this._wrap ? this.width : null);
1549
+ this.requestRender();
1550
+ }
1551
+ }
1552
+ get wrapMode() {
1553
+ return this._wrapMode;
1554
+ }
1555
+ set wrapMode(value) {
1556
+ if (this._wrapMode !== value) {
1557
+ this._wrapMode = value;
1558
+ this.textBuffer.setWrapMode(this._wrapMode);
1559
+ this.requestRender();
1560
+ }
1561
+ }
1562
+ onResize(width, height) {
1563
+ if (this.lastLocalSelection) {
1564
+ const changed = this.updateLocalSelection(this.lastLocalSelection);
1565
+ if (changed) {
1566
+ this.requestRender();
1567
+ }
1568
+ }
1569
+ }
1570
+ refreshLocalSelection() {
1571
+ if (this.lastLocalSelection) {
1572
+ return this.updateLocalSelection(this.lastLocalSelection);
1573
+ }
1574
+ return false;
1575
+ }
1576
+ updateLocalSelection(localSelection) {
1577
+ if (!localSelection?.isActive) {
1578
+ this.textBuffer.resetLocalSelection();
1579
+ return true;
1580
+ }
1581
+ return this.textBuffer.setLocalSelection(localSelection.anchorX, localSelection.anchorY, localSelection.focusX, localSelection.focusY, this._selectionBg, this._selectionFg);
1582
+ }
1583
+ updateTextInfo() {
1584
+ if (this.lastLocalSelection) {
1585
+ const changed = this.updateLocalSelection(this.lastLocalSelection);
1586
+ if (changed) {
1587
+ this.requestRender();
1588
+ }
1589
+ }
1590
+ this.yogaNode.markDirty();
1591
+ this.requestRender();
1592
+ }
1593
+ updateLineInfo() {
1594
+ const lineInfo = this.textBuffer.lineInfo;
1595
+ this._lineInfo.lineStarts = lineInfo.lineStarts;
1596
+ this._lineInfo.lineWidths = lineInfo.lineWidths;
1597
+ this._lineInfo.maxLineWidth = lineInfo.maxLineWidth;
1598
+ }
1599
+ updateWrapWidth(width) {
1600
+ this.textBuffer.setWrapWidth(width);
1601
+ this.updateLineInfo();
1602
+ }
1603
+ setupMeasureFunc() {
1604
+ const measureFunc = (width, widthMode, height, heightMode) => {
1605
+ if (this._wrap && this.width !== width) {
1606
+ this.updateWrapWidth(width);
1607
+ } else {
1608
+ this.updateLineInfo();
1609
+ }
1610
+ const measuredWidth = this._lineInfo.maxLineWidth;
1611
+ const measuredHeight = this._lineInfo.lineStarts.length;
1612
+ return {
1613
+ width: Math.max(1, measuredWidth),
1614
+ height: Math.max(1, measuredHeight)
1615
+ };
1616
+ };
1617
+ this.yogaNode.setMeasureFunc(measureFunc);
1618
+ }
1619
+ insertChunk(chunk, index) {
1620
+ this.textBuffer.insertChunkGroup(index ?? this.textBuffer.chunkGroupCount, chunk.text, chunk.fg, chunk.bg, chunk.attributes);
1621
+ this.updateTextInfo();
1622
+ }
1623
+ removeChunk(index) {
1624
+ this.textBuffer.removeChunkGroup(index);
1625
+ this.updateTextInfo();
1626
+ }
1627
+ replaceChunk(index, chunk) {
1628
+ this.textBuffer.replaceChunkGroup(index, chunk.text, chunk.fg, chunk.bg, chunk.attributes);
1629
+ this.updateTextInfo();
1630
+ }
1631
+ shouldStartSelection(x, y) {
1632
+ if (!this.selectable)
1633
+ return false;
1634
+ const localX = x - this.x;
1635
+ const localY = y - this.y;
1636
+ return localX >= 0 && localX < this.width && localY >= 0 && localY < this.height;
1637
+ }
1638
+ onSelectionChanged(selection) {
1639
+ const localSelection = convertGlobalToLocalSelection(selection, this.x, this.y);
1640
+ this.lastLocalSelection = localSelection;
1641
+ const changed = this.updateLocalSelection(localSelection);
1642
+ if (changed) {
1643
+ this.requestRender();
1644
+ }
1645
+ return this.hasSelection();
1646
+ }
1647
+ getSelectedText() {
1648
+ return this.textBuffer.getSelectedText();
1649
+ }
1650
+ hasSelection() {
1651
+ return this.textBuffer.hasSelection();
1652
+ }
1653
+ getSelection() {
1654
+ return this.textBuffer.getSelection();
1655
+ }
1656
+ render(buffer, deltaTime) {
1657
+ if (!this.visible)
1658
+ return;
1659
+ this.markClean();
1660
+ this._ctx.addToHitGrid(this.x, this.y, this.width, this.height, this.num);
1661
+ this.renderSelf(buffer);
1662
+ }
1663
+ renderSelf(buffer) {
1664
+ if (this.textBuffer.ptr) {
1665
+ const clipRect = {
1666
+ x: this.x,
1667
+ y: this.y,
1668
+ width: this.width,
1669
+ height: this.height
1670
+ };
1671
+ buffer.drawTextBuffer(this.textBuffer, this.x, this.y, clipRect);
1672
+ }
1673
+ }
1674
+ destroy() {
1675
+ this.textBuffer.destroy();
1676
+ super.destroy();
1677
+ }
1678
+ onFgChanged(newColor) {}
1679
+ onBgChanged(newColor) {}
1680
+ onAttributesChanged(newAttributes) {}
1681
+ }
1682
+
1683
+ // src/renderables/Code.ts
1684
+ class CodeRenderable extends TextBufferRenderable {
1685
+ _content;
1686
+ _filetype;
1687
+ _syntaxStyle;
1688
+ _isHighlighting = false;
1689
+ _treeSitterClient;
1690
+ _pendingRehighlight = false;
1691
+ _contentDefaultOptions = {
1692
+ content: ""
1693
+ };
1694
+ constructor(ctx, options) {
1695
+ super(ctx, options);
1696
+ this._content = options.content ?? this._contentDefaultOptions.content;
1697
+ this._filetype = options.filetype;
1698
+ this._syntaxStyle = options.syntaxStyle;
1699
+ this._treeSitterClient = options.treeSitterClient ?? getTreeSitterClient();
1700
+ this.updateContent(this._content);
1701
+ }
1702
+ get content() {
1703
+ return this._content;
1704
+ }
1705
+ set content(value) {
1706
+ if (this._content !== value) {
1707
+ this._content = value;
1708
+ this.updateContent(value);
1709
+ }
1710
+ }
1711
+ get filetype() {
1712
+ return this._filetype;
1713
+ }
1714
+ set filetype(value) {
1715
+ if (this._filetype !== value) {
1716
+ this._filetype = value;
1717
+ this.updateContent(this._content);
1718
+ }
1719
+ }
1720
+ get syntaxStyle() {
1721
+ return this._syntaxStyle;
1722
+ }
1723
+ set syntaxStyle(value) {
1724
+ if (this._syntaxStyle !== value) {
1725
+ this._syntaxStyle = value;
1726
+ this.updateContent(this._content);
1727
+ }
1728
+ }
1729
+ async updateContent(content) {
1730
+ if (content.length === 0)
1731
+ return;
1732
+ if (this._isHighlighting) {
1733
+ this._pendingRehighlight = true;
1734
+ return;
1735
+ }
1736
+ if (!this._filetype) {
1737
+ this.fallback(content);
1738
+ return;
1739
+ }
1740
+ this.fallback(content);
1741
+ this._isHighlighting = true;
1742
+ try {
1743
+ const styledText = await treeSitterToStyledText(content, this._filetype, this._syntaxStyle, this._treeSitterClient);
1744
+ if (this.isDestroyed)
1745
+ return;
1746
+ this.textBuffer.setStyledText(styledText);
1747
+ this.updateTextInfo();
1748
+ } catch (error) {
1749
+ console.warn("Code highlighting failed, falling back to plain text:", error);
1750
+ this.fallback(content);
1751
+ } finally {
1752
+ this._isHighlighting = false;
1753
+ if (this._pendingRehighlight) {
1754
+ this._pendingRehighlight = false;
1755
+ process.nextTick(() => this.updateContent(this._content));
1756
+ }
1757
+ }
1758
+ }
1759
+ fallback(content) {
1760
+ const fallbackStyledText = this.createFallbackStyledText(content);
1761
+ if (this.isDestroyed)
1762
+ return;
1763
+ this.textBuffer.setStyledText(fallbackStyledText);
1764
+ this.updateTextInfo();
1765
+ }
1766
+ createFallbackStyledText(content) {
1767
+ const chunks = [
1768
+ {
1769
+ __isChunk: true,
1770
+ text: content,
1771
+ fg: this._defaultFg,
1772
+ bg: this._defaultBg,
1773
+ attributes: this._defaultAttributes
1774
+ }
1775
+ ];
1776
+ return new StyledText(chunks);
1777
+ }
1778
+ }
1414
1779
  // src/renderables/FrameBuffer.ts
1415
1780
  class FrameBufferRenderable extends Renderable {
1416
1781
  frameBuffer;
@@ -1651,6 +2016,9 @@ class TextNodeRenderable extends BaseRenderable {
1651
2016
  get attributes() {
1652
2017
  return this._attributes;
1653
2018
  }
2019
+ findDescendantById(id) {
2020
+ return;
2021
+ }
1654
2022
  }
1655
2023
 
1656
2024
  class RootTextNodeRenderable extends TextNodeRenderable {
@@ -1668,52 +2036,19 @@ class RootTextNodeRenderable extends TextNodeRenderable {
1668
2036
  }
1669
2037
 
1670
2038
  // src/renderables/Text.ts
1671
- class TextRenderable extends Renderable {
1672
- selectable = true;
2039
+ class TextRenderable extends TextBufferRenderable {
1673
2040
  _text;
1674
2041
  _hasManualStyledText = false;
1675
- _defaultFg;
1676
- _defaultBg;
1677
- _defaultAttributes;
1678
- _selectionBg;
1679
- _selectionFg;
1680
- _wrap = false;
1681
- _wrapMode = "word";
1682
- lastLocalSelection = null;
1683
- textBuffer;
1684
- _lineInfo = { lineStarts: [], lineWidths: [], maxLineWidth: 0 };
1685
2042
  rootTextNode;
1686
- _defaultOptions = {
1687
- content: "",
1688
- fg: RGBA.fromValues(1, 1, 1, 1),
1689
- bg: RGBA.fromValues(0, 0, 0, 0),
1690
- selectionBg: undefined,
1691
- selectionFg: undefined,
1692
- selectable: true,
1693
- attributes: 0,
1694
- wrap: true,
1695
- wrapMode: "word"
2043
+ _contentDefaultOptions = {
2044
+ content: ""
1696
2045
  };
1697
2046
  constructor(ctx, options) {
1698
2047
  super(ctx, options);
1699
- const content = options.content ?? this._defaultOptions.content;
2048
+ const content = options.content ?? this._contentDefaultOptions.content;
1700
2049
  const styledText = typeof content === "string" ? stringToStyledText(content) : content;
1701
2050
  this._text = styledText;
1702
- this._hasManualStyledText = !!options.content;
1703
- this._defaultFg = parseColor(options.fg ?? this._defaultOptions.fg);
1704
- this._defaultBg = parseColor(options.bg ?? this._defaultOptions.bg);
1705
- this._defaultAttributes = options.attributes ?? this._defaultOptions.attributes;
1706
- this._selectionBg = options.selectionBg ? parseColor(options.selectionBg) : this._defaultOptions.selectionBg;
1707
- this._selectionFg = options.selectionFg ? parseColor(options.selectionFg) : this._defaultOptions.selectionFg;
1708
- this.selectable = options.selectable ?? this._defaultOptions.selectable;
1709
- this._wrap = options.wrap ?? this._defaultOptions.wrap;
1710
- this._wrapMode = options.wrapMode ?? this._defaultOptions.wrapMode;
1711
- this.textBuffer = TextBuffer.create(this._ctx.widthMethod);
1712
- this.textBuffer.setWrapMode(this._wrapMode);
1713
- this.setupMeasureFunc();
1714
- this.textBuffer.setDefaultFg(this._defaultFg);
1715
- this.textBuffer.setDefaultBg(this._defaultBg);
1716
- this.textBuffer.setDefaultAttributes(this._defaultAttributes);
2051
+ this._hasManualStyledText = options.content !== undefined && content !== "";
1717
2052
  this.rootTextNode = new RootTextNodeRenderable(ctx, {
1718
2053
  id: `${this.id}-root`,
1719
2054
  fg: this._defaultFg,
@@ -1721,11 +2056,6 @@ class TextRenderable extends Renderable {
1721
2056
  attributes: this._defaultAttributes
1722
2057
  }, this);
1723
2058
  this.updateTextBuffer(styledText);
1724
- this._text.mount(this);
1725
- if (this._wrap && this.width > 0) {
1726
- this.updateWrapWidth(this.width);
1727
- }
1728
- this.updateTextInfo();
1729
2059
  }
1730
2060
  updateTextBuffer(styledText) {
1731
2061
  this.textBuffer.setStyledText(styledText);
@@ -1735,12 +2065,6 @@ class TextRenderable extends Renderable {
1735
2065
  get content() {
1736
2066
  return this._text;
1737
2067
  }
1738
- get plainText() {
1739
- return this.textBuffer.getPlainText();
1740
- }
1741
- get textLength() {
1742
- return this.textBuffer.length;
1743
- }
1744
2068
  get chunks() {
1745
2069
  return this._text.chunks;
1746
2070
  }
@@ -1752,166 +2076,26 @@ class TextRenderable extends Renderable {
1752
2076
  const styledText = typeof value === "string" ? stringToStyledText(value) : value;
1753
2077
  if (this._text !== styledText) {
1754
2078
  this._text = styledText;
1755
- styledText.mount(this);
1756
2079
  this.updateTextBuffer(styledText);
1757
2080
  this.updateTextInfo();
1758
2081
  }
1759
2082
  }
1760
- get fg() {
1761
- return this._defaultFg;
1762
- }
1763
- set fg(value) {
1764
- const newColor = parseColor(value ?? this._defaultOptions.fg);
1765
- this.rootTextNode.fg = newColor;
1766
- if (this._defaultFg !== newColor) {
1767
- this._defaultFg = newColor;
1768
- this.textBuffer.setDefaultFg(this._defaultFg);
1769
- this.rootTextNode.fg = newColor;
1770
- this.requestRender();
1771
- }
1772
- }
1773
- get selectionBg() {
1774
- return this._selectionBg;
1775
- }
1776
- set selectionBg(value) {
1777
- const newColor = value ? parseColor(value) : this._defaultOptions.selectionBg;
1778
- if (this._selectionBg !== newColor) {
1779
- this._selectionBg = newColor;
1780
- if (this.lastLocalSelection) {
1781
- this.updateLocalSelection(this.lastLocalSelection);
1782
- }
1783
- this.requestRender();
1784
- }
1785
- }
1786
- get selectionFg() {
1787
- return this._selectionFg;
1788
- }
1789
- set selectionFg(value) {
1790
- const newColor = value ? parseColor(value) : this._defaultOptions.selectionFg;
1791
- if (this._selectionFg !== newColor) {
1792
- this._selectionFg = newColor;
1793
- if (this.lastLocalSelection) {
1794
- this.updateLocalSelection(this.lastLocalSelection);
1795
- }
1796
- this.requestRender();
1797
- }
1798
- }
1799
- get bg() {
1800
- return this._defaultBg;
1801
- }
1802
- set bg(value) {
1803
- const newColor = parseColor(value ?? this._defaultOptions.bg);
1804
- this.rootTextNode.bg = newColor;
1805
- if (this._defaultBg !== newColor) {
1806
- this._defaultBg = newColor;
1807
- this.textBuffer.setDefaultBg(this._defaultBg);
1808
- this.rootTextNode.bg = newColor;
1809
- this.requestRender();
1810
- }
1811
- }
1812
- get attributes() {
1813
- return this._defaultAttributes;
1814
- }
1815
- set attributes(value) {
1816
- if (this._defaultAttributes !== value) {
1817
- this._defaultAttributes = value;
1818
- this.textBuffer.setDefaultAttributes(this._defaultAttributes);
1819
- this.rootTextNode.attributes = value;
1820
- this.requestRender();
1821
- }
1822
- }
1823
- get wrap() {
1824
- return this._wrap;
1825
- }
1826
- set wrap(value) {
1827
- if (this._wrap !== value) {
1828
- this._wrap = value;
1829
- this.textBuffer.setWrapWidth(this._wrap ? this.width : null);
1830
- this.requestRender();
1831
- }
1832
- }
1833
- get wrapMode() {
1834
- return this._wrapMode;
1835
- }
1836
- set wrapMode(value) {
1837
- if (this._wrapMode !== value) {
1838
- this._wrapMode = value;
1839
- this.textBuffer.setWrapMode(this._wrapMode);
1840
- this.requestRender();
1841
- }
1842
- }
1843
- onResize(width, height) {
1844
- if (this.lastLocalSelection) {
1845
- const changed = this.updateLocalSelection(this.lastLocalSelection);
1846
- if (changed) {
1847
- this.requestRender();
1848
- }
1849
- }
1850
- }
1851
- updateLocalSelection(localSelection) {
1852
- if (!localSelection?.isActive) {
1853
- this.textBuffer.resetLocalSelection();
1854
- return true;
1855
- }
1856
- return this.textBuffer.setLocalSelection(localSelection.anchorX, localSelection.anchorY, localSelection.focusX, localSelection.focusY, this._selectionBg, this._selectionFg);
1857
- }
1858
- updateTextInfo() {
1859
- if (this.lastLocalSelection) {
1860
- const changed = this.updateLocalSelection(this.lastLocalSelection);
1861
- if (changed) {
1862
- this.requestRender();
1863
- }
1864
- }
1865
- this.yogaNode.markDirty();
1866
- this.requestRender();
1867
- }
1868
- updateLineInfo() {
1869
- const lineInfo = this.textBuffer.lineInfo;
1870
- this._lineInfo.lineStarts = lineInfo.lineStarts;
1871
- this._lineInfo.lineWidths = lineInfo.lineWidths;
1872
- this._lineInfo.maxLineWidth = lineInfo.maxLineWidth;
1873
- }
1874
- updateWrapWidth(width) {
1875
- this.textBuffer.setWrapWidth(width);
1876
- this.updateLineInfo();
1877
- }
1878
- setupMeasureFunc() {
1879
- const measureFunc = (width, widthMode, height, heightMode) => {
1880
- if (this._wrap) {
1881
- if (this.width !== width) {
1882
- this.updateWrapWidth(width);
1883
- }
1884
- } else {
1885
- this.updateLineInfo();
1886
- }
1887
- const measuredWidth = this._lineInfo.maxLineWidth;
1888
- const measuredHeight = this._lineInfo.lineStarts.length;
1889
- return {
1890
- width: Math.max(1, measuredWidth),
1891
- height: Math.max(1, measuredHeight)
1892
- };
1893
- };
1894
- this.yogaNode.setMeasureFunc(measureFunc);
1895
- }
1896
2083
  insertChunk(chunk, index) {
1897
- this.textBuffer.insertChunkGroup(index ?? this.textBuffer.chunkGroupCount, chunk.text, chunk.fg, chunk.bg, chunk.attributes);
1898
- this.updateTextInfo();
2084
+ super.insertChunk(chunk, index);
1899
2085
  this.clearChunks(this._text);
1900
2086
  }
1901
- removeChunk(chunk) {
2087
+ removeChunkByObject(chunk) {
1902
2088
  const index = this._text.chunks.indexOf(chunk);
1903
2089
  if (index === -1)
1904
2090
  return;
1905
- this.textBuffer.removeChunkGroup(index);
1906
- this.updateTextInfo();
2091
+ super.removeChunk(index);
1907
2092
  this.clearChunks(this._text);
1908
2093
  }
1909
- replaceChunk(chunk, oldChunk) {
2094
+ replaceChunkByObject(chunk, oldChunk) {
1910
2095
  const index = this._text.chunks.indexOf(oldChunk);
1911
2096
  if (index === -1)
1912
2097
  return;
1913
- this.textBuffer.replaceChunkGroup(index, chunk.text, chunk.fg, chunk.bg, chunk.attributes);
1914
- this.updateTextInfo();
2098
+ super.replaceChunk(index, chunk);
1915
2099
  this.clearChunks(this._text);
1916
2100
  }
1917
2101
  updateTextFromNodes() {
@@ -1922,7 +2106,7 @@ class TextRenderable extends Renderable {
1922
2106
  attributes: this._defaultAttributes
1923
2107
  });
1924
2108
  this.textBuffer.setStyledText(new StyledText(chunks));
1925
- this.updateLineInfo();
2109
+ this.refreshLocalSelection();
1926
2110
  this.yogaNode.markDirty();
1927
2111
  }
1928
2112
  }
@@ -1946,59 +2130,23 @@ class TextRenderable extends Renderable {
1946
2130
  this.rootTextNode.clear();
1947
2131
  const emptyStyledText = stringToStyledText("");
1948
2132
  this._text = emptyStyledText;
1949
- emptyStyledText.mount(this);
1950
2133
  this.updateTextBuffer(emptyStyledText);
1951
2134
  this.updateTextInfo();
1952
2135
  this.requestRender();
1953
2136
  }
1954
- shouldStartSelection(x, y) {
1955
- if (!this.selectable)
1956
- return false;
1957
- const localX = x - this.x;
1958
- const localY = y - this.y;
1959
- return localX >= 0 && localX < this.width && localY >= 0 && localY < this.height;
1960
- }
1961
- onSelectionChanged(selection) {
1962
- const localSelection = convertGlobalToLocalSelection(selection, this.x, this.y);
1963
- this.lastLocalSelection = localSelection;
1964
- const changed = this.updateLocalSelection(localSelection);
1965
- if (changed) {
1966
- this.requestRender();
1967
- }
1968
- return this.hasSelection();
1969
- }
1970
- getSelectedText() {
1971
- return this.textBuffer.getSelectedText();
1972
- }
1973
- hasSelection() {
1974
- return this.textBuffer.hasSelection();
1975
- }
1976
- getSelection() {
1977
- return this.textBuffer.getSelection();
1978
- }
1979
2137
  onLifecyclePass = () => {
1980
2138
  this.updateTextFromNodes();
1981
2139
  };
1982
- render(buffer, deltaTime) {
1983
- if (!this.visible)
1984
- return;
1985
- this.markClean();
1986
- this._ctx.addToHitGrid(this.x, this.y, this.width, this.height, this.num);
1987
- this.renderSelf(buffer);
2140
+ onFgChanged(newColor) {
2141
+ this.rootTextNode.fg = newColor;
1988
2142
  }
1989
- renderSelf(buffer) {
1990
- if (this.textBuffer.ptr) {
1991
- const clipRect = {
1992
- x: this.x,
1993
- y: this.y,
1994
- width: this.width,
1995
- height: this.height
1996
- };
1997
- buffer.drawTextBuffer(this.textBuffer, this.x, this.y, clipRect);
1998
- }
2143
+ onBgChanged(newColor) {
2144
+ this.rootTextNode.bg = newColor;
2145
+ }
2146
+ onAttributesChanged(newAttributes) {
2147
+ this.rootTextNode.attributes = newAttributes;
1999
2148
  }
2000
2149
  destroy() {
2001
- this.textBuffer.destroy();
2002
2150
  this.rootTextNode.children.length = 0;
2003
2151
  super.destroy();
2004
2152
  }
@@ -3678,6 +3826,7 @@ class ScrollBoxRenderable extends BoxRenderable {
3678
3826
  _stickyScrollRight = false;
3679
3827
  _stickyStart;
3680
3828
  _hasManualScroll = false;
3829
+ scrollAccel;
3681
3830
  get stickyScroll() {
3682
3831
  return this._stickyScroll;
3683
3832
  }
@@ -3776,6 +3925,7 @@ class ScrollBoxRenderable extends BoxRenderable {
3776
3925
  stickyStart,
3777
3926
  scrollX = false,
3778
3927
  scrollY = true,
3928
+ scrollAcceleration,
3779
3929
  ...options
3780
3930
  }) {
3781
3931
  super(ctx, {
@@ -3787,6 +3937,12 @@ class ScrollBoxRenderable extends BoxRenderable {
3787
3937
  this.internalId = ScrollBoxRenderable.idCounter++;
3788
3938
  this._stickyScroll = stickyScroll;
3789
3939
  this._stickyStart = stickyStart;
3940
+ if (scrollAcceleration) {
3941
+ this.scrollAccel = scrollAcceleration;
3942
+ } else if (process.platform === "darwin") {
3943
+ this.scrollAccel = new MacOSScrollAccel;
3944
+ }
3945
+ this.scrollAccel ??= new LinearScrollAccel;
3790
3946
  this.wrapper = new BoxRenderable(ctx, {
3791
3947
  flexDirection: "column",
3792
3948
  flexGrow: 1,
@@ -3884,6 +4040,9 @@ class ScrollBoxRenderable extends BoxRenderable {
3884
4040
  add(obj, index) {
3885
4041
  return this.content.add(obj, index);
3886
4042
  }
4043
+ insertBefore(obj, anchor) {
4044
+ return this.content.insertBefore(obj, anchor);
4045
+ }
3887
4046
  remove(id) {
3888
4047
  this.content.remove(id);
3889
4048
  }
@@ -3895,14 +4054,18 @@ class ScrollBoxRenderable extends BoxRenderable {
3895
4054
  let dir = event.scroll?.direction;
3896
4055
  if (event.modifiers.shift)
3897
4056
  dir = dir === "up" ? "left" : dir === "down" ? "right" : dir === "right" ? "down" : "up";
3898
- if (dir === "up")
3899
- this.scrollTop -= event.scroll?.delta ?? 0;
3900
- else if (dir === "down")
3901
- this.scrollTop += event.scroll?.delta ?? 0;
3902
- else if (dir === "left")
3903
- this.scrollLeft -= event.scroll?.delta ?? 0;
3904
- else if (dir === "right")
3905
- this.scrollLeft += event.scroll?.delta ?? 0;
4057
+ const baseDelta = event.scroll?.delta ?? 0;
4058
+ const now = Date.now();
4059
+ const multiplier = this.scrollAccel.tick(now);
4060
+ if (dir === "up") {
4061
+ this.scrollTop -= baseDelta * multiplier;
4062
+ } else if (dir === "down") {
4063
+ this.scrollTop += baseDelta * multiplier;
4064
+ } else if (dir === "left") {
4065
+ this.scrollLeft -= baseDelta * multiplier;
4066
+ } else if (dir === "right") {
4067
+ this.scrollLeft += baseDelta * multiplier;
4068
+ }
3906
4069
  this._hasManualScroll = true;
3907
4070
  }
3908
4071
  if (event.type === "drag" && event.isSelecting) {
@@ -3914,10 +4077,12 @@ class ScrollBoxRenderable extends BoxRenderable {
3914
4077
  handleKeyPress(key) {
3915
4078
  if (this.verticalScrollBar.handleKeyPress(key)) {
3916
4079
  this._hasManualScroll = true;
4080
+ this.scrollAccel.reset();
3917
4081
  return true;
3918
4082
  }
3919
4083
  if (this.horizontalScrollBar.handleKeyPress(key)) {
3920
4084
  this._hasManualScroll = true;
4085
+ this.scrollAccel.reset();
3921
4086
  return true;
3922
4087
  }
3923
4088
  return false;
@@ -4167,7 +4332,10 @@ export {
4167
4332
  white,
4168
4333
  vstyles,
4169
4334
  visualizeRenderableTree,
4335
+ main as updateAssets,
4170
4336
  underline,
4337
+ treeSitterToTextChunks,
4338
+ treeSitterToStyledText,
4171
4339
  t,
4172
4340
  stringToStyledText,
4173
4341
  strikethrough,
@@ -4178,6 +4346,7 @@ export {
4178
4346
  renderFontToFrameBuffer,
4179
4347
  registerEnvVar,
4180
4348
  red,
4349
+ pathToFiletype,
4181
4350
  parseWrap,
4182
4351
  parseUnit,
4183
4352
  parsePositionType,
@@ -4210,6 +4379,8 @@ export {
4210
4379
  hastToStyledText,
4211
4380
  h,
4212
4381
  green,
4382
+ getTreeSitterClient,
4383
+ getDataPaths,
4213
4384
  getCharacterPositions,
4214
4385
  getBorderSides,
4215
4386
  getBorderFromSides,
@@ -4217,6 +4388,7 @@ export {
4217
4388
  generateEnvColored,
4218
4389
  fonts,
4219
4390
  fg,
4391
+ extToFiletype,
4220
4392
  envRegistry,
4221
4393
  env,
4222
4394
  engine,
@@ -4227,7 +4399,9 @@ export {
4227
4399
  createTextAttributes,
4228
4400
  createCliRenderer,
4229
4401
  coordinateToCharacterIndex,
4402
+ convertThemeToStyles,
4230
4403
  convertGlobalToLocalSelection,
4404
+ clearEnvCache,
4231
4405
  capture,
4232
4406
  brightYellow,
4233
4407
  brightWhite,
@@ -4258,12 +4432,15 @@ export {
4258
4432
  applyGrayscale,
4259
4433
  applyChromaticAberration,
4260
4434
  applyAsciiArt,
4435
+ addDefaultParsers,
4261
4436
  exports_src as Yoga,
4262
4437
  VignetteEffect,
4263
4438
  VRenderable,
4439
+ TreeSitterClient,
4264
4440
  Timeline,
4265
4441
  TextRenderable,
4266
4442
  TextNodeRenderable,
4443
+ TextBufferRenderable,
4267
4444
  TextBuffer,
4268
4445
  TextAttributes,
4269
4446
  Text,
@@ -4284,13 +4461,18 @@ export {
4284
4461
  RenderableEvents,
4285
4462
  Renderable,
4286
4463
  RGBA,
4464
+ PasteEvent,
4287
4465
  OptimizedBuffer,
4288
4466
  MouseParser,
4289
4467
  MouseEvent,
4290
4468
  MouseButton,
4469
+ MacOSScrollAccel,
4291
4470
  LogLevel,
4471
+ LinearScrollAccel,
4292
4472
  LayoutEvents,
4293
4473
  KeyHandler,
4474
+ KeyEvent,
4475
+ InternalKeyHandler,
4294
4476
  InputRenderableEvents,
4295
4477
  InputRenderable,
4296
4478
  Input,
@@ -4299,7 +4481,9 @@ export {
4299
4481
  FrameBuffer,
4300
4482
  DistortionEffect,
4301
4483
  DebugOverlayCorner,
4484
+ DataPathsManager,
4302
4485
  ConsolePosition,
4486
+ CodeRenderable,
4303
4487
  CliRenderer,
4304
4488
  CliRenderEvents,
4305
4489
  BrightnessEffect,
@@ -4316,5 +4500,5 @@ export {
4316
4500
  ASCIIFont
4317
4501
  };
4318
4502
 
4319
- //# debugId=9C915E7AEEBC51B664756E2164756E21
4503
+ //# debugId=F1FAFC796A264ABA64756E2164756E21
4320
4504
  //# sourceMappingURL=index.js.map