@opentui/core 0.1.24 → 0.1.25
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/3d.js +1 -1
- package/Renderable.d.ts +11 -2
- package/ansi.d.ts +2 -17
- package/{index-0yx9rnxg.js → index-6kvgbzah.js} +338 -107
- package/{index-0yx9rnxg.js.map → index-6kvgbzah.js.map} +11 -10
- package/index.js +45 -26
- package/index.js.map +7 -7
- package/lib/KeyHandler.d.ts +4 -1
- package/lib/env.d.ts +41 -0
- package/lib/index.d.ts +1 -0
- package/package.json +7 -7
- package/renderables/ASCIIFont.d.ts +1 -1
- package/renderables/Input.d.ts +2 -2
- package/renderables/Text.d.ts +3 -0
- package/renderer.d.ts +1 -1
- package/testing/mock-keys.d.ts +1 -0
- package/testing/test-renderer.d.ts +1 -0
- package/testing.js +16 -6
- package/testing.js.map +4 -4
- package/zig.d.ts +1 -0
- /package/{singleton.d.ts → lib/singleton.d.ts} +0 -0
package/index.js
CHANGED
|
@@ -57,13 +57,16 @@ import {
|
|
|
57
57
|
cyan,
|
|
58
58
|
delegate,
|
|
59
59
|
dim,
|
|
60
|
+
env,
|
|
61
|
+
envRegistry,
|
|
60
62
|
exports_src,
|
|
61
63
|
fg,
|
|
62
64
|
fonts,
|
|
65
|
+
generateEnvColored,
|
|
66
|
+
generateEnvMarkdown,
|
|
63
67
|
getBorderFromSides,
|
|
64
68
|
getBorderSides,
|
|
65
69
|
getCharacterPositions,
|
|
66
|
-
getKeyHandler,
|
|
67
70
|
getObjectsInViewport,
|
|
68
71
|
green,
|
|
69
72
|
h,
|
|
@@ -98,6 +101,7 @@ import {
|
|
|
98
101
|
parseUnit,
|
|
99
102
|
parseWrap,
|
|
100
103
|
red,
|
|
104
|
+
registerEnvVar,
|
|
101
105
|
renderFontToFrameBuffer,
|
|
102
106
|
resolveRenderLib,
|
|
103
107
|
reverse,
|
|
@@ -111,7 +115,7 @@ import {
|
|
|
111
115
|
white,
|
|
112
116
|
wrapWithDelegates,
|
|
113
117
|
yellow
|
|
114
|
-
} from "./index-
|
|
118
|
+
} from "./index-6kvgbzah.js";
|
|
115
119
|
// src/post/filters.ts
|
|
116
120
|
function applyScanlines(buffer, strength = 0.8, step = 2) {
|
|
117
121
|
const width = buffer.width;
|
|
@@ -1667,6 +1671,7 @@ class RootTextNodeRenderable extends TextNodeRenderable {
|
|
|
1667
1671
|
class TextRenderable extends Renderable {
|
|
1668
1672
|
selectable = true;
|
|
1669
1673
|
_text;
|
|
1674
|
+
_hasManualStyledText = false;
|
|
1670
1675
|
_defaultFg;
|
|
1671
1676
|
_defaultBg;
|
|
1672
1677
|
_defaultAttributes;
|
|
@@ -1694,6 +1699,7 @@ class TextRenderable extends Renderable {
|
|
|
1694
1699
|
const content = options.content ?? this._defaultOptions.content;
|
|
1695
1700
|
const styledText = typeof content === "string" ? stringToStyledText(content) : content;
|
|
1696
1701
|
this._text = styledText;
|
|
1702
|
+
this._hasManualStyledText = !!options.content;
|
|
1697
1703
|
this._defaultFg = parseColor(options.fg ?? this._defaultOptions.fg);
|
|
1698
1704
|
this._defaultBg = parseColor(options.bg ?? this._defaultOptions.bg);
|
|
1699
1705
|
this._defaultAttributes = options.attributes ?? this._defaultOptions.attributes;
|
|
@@ -1704,13 +1710,10 @@ class TextRenderable extends Renderable {
|
|
|
1704
1710
|
this._wrapMode = options.wrapMode ?? this._defaultOptions.wrapMode;
|
|
1705
1711
|
this.textBuffer = TextBuffer.create(this._ctx.widthMethod);
|
|
1706
1712
|
this.textBuffer.setWrapMode(this._wrapMode);
|
|
1707
|
-
|
|
1708
|
-
this.textBuffer.setWrapWidth(this.width > 0 ? this.width : 40);
|
|
1709
|
-
}
|
|
1713
|
+
this.setupMeasureFunc();
|
|
1710
1714
|
this.textBuffer.setDefaultFg(this._defaultFg);
|
|
1711
1715
|
this.textBuffer.setDefaultBg(this._defaultBg);
|
|
1712
1716
|
this.textBuffer.setDefaultAttributes(this._defaultAttributes);
|
|
1713
|
-
this.setupMeasureFunc();
|
|
1714
1717
|
this.rootTextNode = new RootTextNodeRenderable(ctx, {
|
|
1715
1718
|
id: `${this.id}-root`,
|
|
1716
1719
|
fg: this._defaultFg,
|
|
@@ -1719,6 +1722,9 @@ class TextRenderable extends Renderable {
|
|
|
1719
1722
|
}, this);
|
|
1720
1723
|
this.updateTextBuffer(styledText);
|
|
1721
1724
|
this._text.mount(this);
|
|
1725
|
+
if (this._wrap && this.width > 0) {
|
|
1726
|
+
this.updateWrapWidth(this.width);
|
|
1727
|
+
}
|
|
1722
1728
|
this.updateTextInfo();
|
|
1723
1729
|
}
|
|
1724
1730
|
updateTextBuffer(styledText) {
|
|
@@ -1742,6 +1748,7 @@ class TextRenderable extends Renderable {
|
|
|
1742
1748
|
return this.rootTextNode;
|
|
1743
1749
|
}
|
|
1744
1750
|
set content(value) {
|
|
1751
|
+
this._hasManualStyledText = true;
|
|
1745
1752
|
const styledText = typeof value === "string" ? stringToStyledText(value) : value;
|
|
1746
1753
|
if (this._text !== styledText) {
|
|
1747
1754
|
this._text = styledText;
|
|
@@ -1834,10 +1841,7 @@ class TextRenderable extends Renderable {
|
|
|
1834
1841
|
}
|
|
1835
1842
|
}
|
|
1836
1843
|
onResize(width, height) {
|
|
1837
|
-
if (this.
|
|
1838
|
-
this.textBuffer.setWrapWidth(width);
|
|
1839
|
-
this.updateTextInfo();
|
|
1840
|
-
} else if (this.lastLocalSelection) {
|
|
1844
|
+
if (this.lastLocalSelection) {
|
|
1841
1845
|
const changed = this.updateLocalSelection(this.lastLocalSelection);
|
|
1842
1846
|
if (changed) {
|
|
1843
1847
|
this.requestRender();
|
|
@@ -1852,10 +1856,6 @@ class TextRenderable extends Renderable {
|
|
|
1852
1856
|
return this.textBuffer.setLocalSelection(localSelection.anchorX, localSelection.anchorY, localSelection.focusX, localSelection.focusY, this._selectionBg, this._selectionFg);
|
|
1853
1857
|
}
|
|
1854
1858
|
updateTextInfo() {
|
|
1855
|
-
const lineInfo = this.textBuffer.lineInfo;
|
|
1856
|
-
this._lineInfo.lineStarts = lineInfo.lineStarts;
|
|
1857
|
-
this._lineInfo.lineWidths = lineInfo.lineWidths;
|
|
1858
|
-
this._lineInfo.maxLineWidth = lineInfo.maxLineWidth;
|
|
1859
1859
|
if (this.lastLocalSelection) {
|
|
1860
1860
|
const changed = this.updateLocalSelection(this.lastLocalSelection);
|
|
1861
1861
|
if (changed) {
|
|
@@ -1865,12 +1865,27 @@ class TextRenderable extends Renderable {
|
|
|
1865
1865
|
this.yogaNode.markDirty();
|
|
1866
1866
|
this.requestRender();
|
|
1867
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
|
+
}
|
|
1868
1878
|
setupMeasureFunc() {
|
|
1869
1879
|
const measureFunc = (width, widthMode, height, heightMode) => {
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
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;
|
|
1874
1889
|
return {
|
|
1875
1890
|
width: Math.max(1, measuredWidth),
|
|
1876
1891
|
height: Math.max(1, measuredHeight)
|
|
@@ -1900,14 +1915,15 @@ class TextRenderable extends Renderable {
|
|
|
1900
1915
|
this.clearChunks(this._text);
|
|
1901
1916
|
}
|
|
1902
1917
|
updateTextFromNodes() {
|
|
1903
|
-
if (this.rootTextNode.isDirty) {
|
|
1918
|
+
if (this.rootTextNode.isDirty && !this._hasManualStyledText) {
|
|
1904
1919
|
const chunks = this.rootTextNode.gatherWithInheritedStyle({
|
|
1905
1920
|
fg: this._defaultFg,
|
|
1906
1921
|
bg: this._defaultBg,
|
|
1907
1922
|
attributes: this._defaultAttributes
|
|
1908
1923
|
});
|
|
1909
1924
|
this.textBuffer.setStyledText(new StyledText(chunks));
|
|
1910
|
-
this.
|
|
1925
|
+
this.updateLineInfo();
|
|
1926
|
+
this.yogaNode.markDirty();
|
|
1911
1927
|
}
|
|
1912
1928
|
}
|
|
1913
1929
|
add(obj, index) {
|
|
@@ -2003,6 +2019,7 @@ class ASCIIFontRenderable extends FrameBufferRenderable {
|
|
|
2003
2019
|
const text = options.text || "";
|
|
2004
2020
|
const measurements = measureText({ text, font });
|
|
2005
2021
|
super(ctx, {
|
|
2022
|
+
flexShrink: 0,
|
|
2006
2023
|
...options,
|
|
2007
2024
|
width: measurements.width || 1,
|
|
2008
2025
|
height: measurements.height || 1,
|
|
@@ -3052,7 +3069,7 @@ class SliderRenderable extends Renderable {
|
|
|
3052
3069
|
_foregroundColor;
|
|
3053
3070
|
_onChange;
|
|
3054
3071
|
constructor(ctx, options) {
|
|
3055
|
-
super(ctx, options);
|
|
3072
|
+
super(ctx, { flexShrink: 0, ...options });
|
|
3056
3073
|
this.orientation = options.orientation;
|
|
3057
3074
|
this._min = options.min ?? 0;
|
|
3058
3075
|
this._max = options.max ?? 100;
|
|
@@ -3762,7 +3779,6 @@ class ScrollBoxRenderable extends BoxRenderable {
|
|
|
3762
3779
|
...options
|
|
3763
3780
|
}) {
|
|
3764
3781
|
super(ctx, {
|
|
3765
|
-
flexShrink: 1,
|
|
3766
3782
|
flexDirection: "row",
|
|
3767
3783
|
alignItems: "stretch",
|
|
3768
3784
|
...options,
|
|
@@ -3774,7 +3790,6 @@ class ScrollBoxRenderable extends BoxRenderable {
|
|
|
3774
3790
|
this.wrapper = new BoxRenderable(ctx, {
|
|
3775
3791
|
flexDirection: "column",
|
|
3776
3792
|
flexGrow: 1,
|
|
3777
|
-
flexShrink: 1,
|
|
3778
3793
|
...wrapperOptions,
|
|
3779
3794
|
id: `scroll-box-wrapper-${this.internalId}`
|
|
3780
3795
|
});
|
|
@@ -3782,7 +3797,6 @@ class ScrollBoxRenderable extends BoxRenderable {
|
|
|
3782
3797
|
this.viewport = new BoxRenderable(ctx, {
|
|
3783
3798
|
flexDirection: "column",
|
|
3784
3799
|
flexGrow: 1,
|
|
3785
|
-
flexShrink: 1,
|
|
3786
3800
|
overflow: "hidden",
|
|
3787
3801
|
onSizeChange: () => {
|
|
3788
3802
|
this.recalculateBarProps();
|
|
@@ -3793,6 +3807,7 @@ class ScrollBoxRenderable extends BoxRenderable {
|
|
|
3793
3807
|
this.wrapper.add(this.viewport);
|
|
3794
3808
|
this.content = new ContentRenderable(ctx, this.viewport, {
|
|
3795
3809
|
alignSelf: "flex-start",
|
|
3810
|
+
flexShrink: 0,
|
|
3796
3811
|
...scrollX ? { minWidth: "100%" } : { minWidth: "100%", maxWidth: "100%" },
|
|
3797
3812
|
...scrollY ? { minHeight: "100%" } : { minHeight: "100%", maxHeight: "100%" },
|
|
3798
3813
|
onSizeChange: () => {
|
|
@@ -4161,6 +4176,7 @@ export {
|
|
|
4161
4176
|
reverse,
|
|
4162
4177
|
resolveRenderLib,
|
|
4163
4178
|
renderFontToFrameBuffer,
|
|
4179
|
+
registerEnvVar,
|
|
4164
4180
|
red,
|
|
4165
4181
|
parseWrap,
|
|
4166
4182
|
parseUnit,
|
|
@@ -4194,12 +4210,15 @@ export {
|
|
|
4194
4210
|
hastToStyledText,
|
|
4195
4211
|
h,
|
|
4196
4212
|
green,
|
|
4197
|
-
getKeyHandler,
|
|
4198
4213
|
getCharacterPositions,
|
|
4199
4214
|
getBorderSides,
|
|
4200
4215
|
getBorderFromSides,
|
|
4216
|
+
generateEnvMarkdown,
|
|
4217
|
+
generateEnvColored,
|
|
4201
4218
|
fonts,
|
|
4202
4219
|
fg,
|
|
4220
|
+
envRegistry,
|
|
4221
|
+
env,
|
|
4203
4222
|
engine,
|
|
4204
4223
|
dim,
|
|
4205
4224
|
delegate,
|
|
@@ -4297,5 +4316,5 @@ export {
|
|
|
4297
4316
|
ASCIIFont
|
|
4298
4317
|
};
|
|
4299
4318
|
|
|
4300
|
-
//# debugId=
|
|
4319
|
+
//# debugId=9C915E7AEEBC51B664756E2164756E21
|
|
4301
4320
|
//# sourceMappingURL=index.js.map
|