@opentui/core 0.1.19 → 0.1.20
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 +2 -2
- package/{index-0h2r5adk.js → index-23dkhv32.js} +12 -3
- package/{index-0h2r5adk.js.map → index-23dkhv32.js.map} +5 -5
- package/index.js +51 -27
- package/index.js.map +4 -4
- package/lib/styled-text.d.ts +4 -0
- package/package.json +7 -7
- package/renderables/Text.d.ts +3 -2
- package/renderables/TextNode.d.ts +3 -2
- package/renderables/composition/vnode.d.ts +1 -1
package/index.js
CHANGED
|
@@ -81,6 +81,7 @@ import {
|
|
|
81
81
|
isPositionTypeType,
|
|
82
82
|
isRenderable,
|
|
83
83
|
isSizeType,
|
|
84
|
+
isStyledText,
|
|
84
85
|
isVNode,
|
|
85
86
|
isValidPercentage,
|
|
86
87
|
italic,
|
|
@@ -118,7 +119,7 @@ import {
|
|
|
118
119
|
white,
|
|
119
120
|
wrapWithDelegates,
|
|
120
121
|
yellow
|
|
121
|
-
} from "./index-
|
|
122
|
+
} from "./index-23dkhv32.js";
|
|
122
123
|
// src/post/filters.ts
|
|
123
124
|
function applyScanlines(buffer, strength = 0.8, step = 2) {
|
|
124
125
|
const width = buffer.width;
|
|
@@ -1449,6 +1450,17 @@ var BrandedTextNodeRenderable = Symbol.for("@opentui/core/TextNodeRenderable");
|
|
|
1449
1450
|
function isTextNodeRenderable(obj) {
|
|
1450
1451
|
return !!obj?.[BrandedTextNodeRenderable];
|
|
1451
1452
|
}
|
|
1453
|
+
function styledTextToTextNodes(styledText) {
|
|
1454
|
+
return styledText.chunks.map((chunk) => {
|
|
1455
|
+
const node = new TextNodeRenderable({
|
|
1456
|
+
fg: chunk.fg,
|
|
1457
|
+
bg: chunk.bg,
|
|
1458
|
+
attributes: chunk.attributes
|
|
1459
|
+
});
|
|
1460
|
+
node.add(chunk.text);
|
|
1461
|
+
return node;
|
|
1462
|
+
});
|
|
1463
|
+
}
|
|
1452
1464
|
|
|
1453
1465
|
class TextNodeRenderable extends BaseRenderable {
|
|
1454
1466
|
[BrandedTextNodeRenderable] = true;
|
|
@@ -1480,12 +1492,11 @@ class TextNodeRenderable extends BaseRenderable {
|
|
|
1480
1492
|
this._children.splice(index, 0, obj);
|
|
1481
1493
|
this.requestRender();
|
|
1482
1494
|
return index;
|
|
1483
|
-
} else {
|
|
1484
|
-
const insertIndex = this._children.length;
|
|
1485
|
-
this._children.push(obj);
|
|
1486
|
-
this.requestRender();
|
|
1487
|
-
return insertIndex;
|
|
1488
1495
|
}
|
|
1496
|
+
const insertIndex = this._children.length;
|
|
1497
|
+
this._children.push(obj);
|
|
1498
|
+
this.requestRender();
|
|
1499
|
+
return insertIndex;
|
|
1489
1500
|
}
|
|
1490
1501
|
if (isTextNodeRenderable(obj)) {
|
|
1491
1502
|
if (index !== undefined) {
|
|
@@ -1493,24 +1504,48 @@ class TextNodeRenderable extends BaseRenderable {
|
|
|
1493
1504
|
obj.parent = this;
|
|
1494
1505
|
this.requestRender();
|
|
1495
1506
|
return index;
|
|
1496
|
-
}
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1507
|
+
}
|
|
1508
|
+
const insertIndex = this._children.length;
|
|
1509
|
+
this._children.push(obj);
|
|
1510
|
+
obj.parent = this;
|
|
1511
|
+
this.requestRender();
|
|
1512
|
+
return insertIndex;
|
|
1513
|
+
}
|
|
1514
|
+
if (isStyledText(obj)) {
|
|
1515
|
+
const textNodes = styledTextToTextNodes(obj);
|
|
1516
|
+
if (index !== undefined) {
|
|
1517
|
+
this._children.splice(index, 0, ...textNodes);
|
|
1518
|
+
textNodes.forEach((node) => node.parent = this);
|
|
1500
1519
|
this.requestRender();
|
|
1501
|
-
return
|
|
1520
|
+
return index;
|
|
1502
1521
|
}
|
|
1522
|
+
const insertIndex = this._children.length;
|
|
1523
|
+
this._children.push(...textNodes);
|
|
1524
|
+
textNodes.forEach((node) => node.parent = this);
|
|
1525
|
+
this.requestRender();
|
|
1526
|
+
return insertIndex;
|
|
1503
1527
|
}
|
|
1504
|
-
throw new Error("TextNodeRenderable only accepts strings or
|
|
1528
|
+
throw new Error("TextNodeRenderable only accepts strings, TextNodeRenderable instances, or StyledText instances");
|
|
1505
1529
|
}
|
|
1506
1530
|
insertBefore(child, anchorNode) {
|
|
1531
|
+
if (!anchorNode || !isTextNodeRenderable(anchorNode)) {
|
|
1532
|
+
throw new Error("Anchor must be a TextNodeRenderable");
|
|
1533
|
+
}
|
|
1507
1534
|
const anchorIndex = this._children.indexOf(anchorNode);
|
|
1508
1535
|
if (anchorIndex === -1) {
|
|
1509
1536
|
throw new Error("Anchor node not found in children");
|
|
1510
1537
|
}
|
|
1511
|
-
|
|
1512
|
-
|
|
1538
|
+
if (typeof child === "string") {
|
|
1539
|
+
this._children.splice(anchorIndex, 0, child);
|
|
1540
|
+
} else if (isTextNodeRenderable(child)) {
|
|
1541
|
+
this._children.splice(anchorIndex, 0, child);
|
|
1513
1542
|
child.parent = this;
|
|
1543
|
+
} else if (child instanceof StyledText) {
|
|
1544
|
+
const textNodes = styledTextToTextNodes(child);
|
|
1545
|
+
this._children.splice(anchorIndex, 0, ...textNodes);
|
|
1546
|
+
textNodes.forEach((node) => node.parent = this);
|
|
1547
|
+
} else {
|
|
1548
|
+
throw new Error("Child must be a string, TextNodeRenderable, or StyledText instance");
|
|
1514
1549
|
}
|
|
1515
1550
|
this.requestRender();
|
|
1516
1551
|
return this;
|
|
@@ -1802,7 +1837,6 @@ class TextRenderable extends Renderable {
|
|
|
1802
1837
|
}
|
|
1803
1838
|
updateTextFromNodes() {
|
|
1804
1839
|
if (this.rootTextNode.isDirty) {
|
|
1805
|
-
const startTime = performance.now();
|
|
1806
1840
|
const chunks = this.rootTextNode.gatherWithInheritedStyle({
|
|
1807
1841
|
fg: this._defaultFg,
|
|
1808
1842
|
bg: this._defaultBg,
|
|
@@ -1810,14 +1844,9 @@ class TextRenderable extends Renderable {
|
|
|
1810
1844
|
});
|
|
1811
1845
|
this.textBuffer.setStyledText(new StyledText(chunks));
|
|
1812
1846
|
this.updateTextInfo();
|
|
1813
|
-
const endTime = performance.now();
|
|
1814
|
-
console.log(`updateTextFromNodes took ${endTime - startTime}ms`);
|
|
1815
1847
|
}
|
|
1816
1848
|
}
|
|
1817
1849
|
add(obj, index) {
|
|
1818
|
-
if (!isTextNodeRenderable(obj)) {
|
|
1819
|
-
throw new Error("TextRenderable only accepts TextNodeRenderables. Use add() method.");
|
|
1820
|
-
}
|
|
1821
1850
|
return this.rootTextNode.add(obj, index);
|
|
1822
1851
|
}
|
|
1823
1852
|
remove(id) {
|
|
@@ -1827,12 +1856,6 @@ class TextRenderable extends Renderable {
|
|
|
1827
1856
|
}
|
|
1828
1857
|
}
|
|
1829
1858
|
insertBefore(obj, anchor) {
|
|
1830
|
-
if (!isTextNodeRenderable(obj)) {
|
|
1831
|
-
throw new Error("TextRenderable insertBefore only accepts TextNodeRenderables");
|
|
1832
|
-
}
|
|
1833
|
-
if (!anchor || !isTextNodeRenderable(anchor)) {
|
|
1834
|
-
throw new Error("Anchor must be a TextNodeRenderable");
|
|
1835
|
-
}
|
|
1836
1859
|
this.rootTextNode.insertBefore(obj, anchor);
|
|
1837
1860
|
return this.rootTextNode.children.indexOf(obj);
|
|
1838
1861
|
}
|
|
@@ -3845,6 +3868,7 @@ export {
|
|
|
3845
3868
|
isValidPercentage,
|
|
3846
3869
|
isVNode,
|
|
3847
3870
|
isTextNodeRenderable,
|
|
3871
|
+
isStyledText,
|
|
3848
3872
|
isSizeType,
|
|
3849
3873
|
isRenderable,
|
|
3850
3874
|
isPositionTypeType,
|
|
@@ -3964,5 +3988,5 @@ export {
|
|
|
3964
3988
|
ASCIIFont
|
|
3965
3989
|
};
|
|
3966
3990
|
|
|
3967
|
-
//# debugId=
|
|
3991
|
+
//# debugId=1EBF2F0C32EEED6E64756E2164756E21
|
|
3968
3992
|
//# sourceMappingURL=index.js.map
|