@opentui/core 0.0.0-20250908-4906ddad → 0.0.0-20250912-12c969f4
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 +60 -18
- package/buffer.d.ts +2 -1
- package/{index-d6kwx5pm.js → index-mh94hn7d.js} +328 -155
- package/index-mh94hn7d.js.map +37 -0
- package/index.js +647 -84
- package/index.js.map +14 -13
- package/lib/objects-in-viewport.d.ts +10 -0
- package/lib/styled-text.d.ts +4 -0
- package/package.json +7 -7
- package/renderables/Input.d.ts +1 -1
- package/renderables/ScrollBar.d.ts +1 -1
- package/renderables/ScrollBox.d.ts +17 -2
- package/renderables/Select.d.ts +1 -1
- package/renderables/Slider.d.ts +24 -11
- package/renderables/TabSelect.d.ts +1 -1
- package/renderables/Text.d.ts +12 -1
- package/renderables/TextNode.d.ts +64 -0
- package/renderables/composition/constructs.d.ts +30 -9
- package/renderables/composition/vnode.d.ts +1 -1
- package/renderables/index.d.ts +1 -0
- package/renderer.d.ts +10 -2
- package/testing/mock-keys.d.ts +67 -0
- package/testing/mock-mouse.d.ts +38 -0
- package/testing/test-renderer.d.ts +15 -0
- package/text-buffer.d.ts +3 -2
- package/types.d.ts +6 -0
- package/utils.d.ts +2 -0
- package/zig.d.ts +3 -1
- package/index-d6kwx5pm.js.map +0 -36
|
@@ -1790,21 +1790,11 @@ class TrackedNode extends EventEmitter {
|
|
|
1790
1790
|
}
|
|
1791
1791
|
setWidth(width) {
|
|
1792
1792
|
this._width = width;
|
|
1793
|
-
|
|
1794
|
-
if (parsedWidth === "auto") {
|
|
1795
|
-
this.yogaNode.setWidthAuto();
|
|
1796
|
-
} else {
|
|
1797
|
-
this.yogaNode.setWidth(parsedWidth);
|
|
1798
|
-
}
|
|
1793
|
+
this.yogaNode.setWidth(width);
|
|
1799
1794
|
}
|
|
1800
1795
|
setHeight(height) {
|
|
1801
1796
|
this._height = height;
|
|
1802
|
-
|
|
1803
|
-
if (parsedHeight === "auto") {
|
|
1804
|
-
this.yogaNode.setHeightAuto();
|
|
1805
|
-
} else {
|
|
1806
|
-
this.yogaNode.setHeight(parsedHeight);
|
|
1807
|
-
}
|
|
1797
|
+
this.yogaNode.setHeight(height);
|
|
1808
1798
|
}
|
|
1809
1799
|
addChild(childNode) {
|
|
1810
1800
|
if (childNode.parent) {
|
|
@@ -3936,11 +3926,40 @@ function createTextAttributes({
|
|
|
3936
3926
|
attributes |= TextAttributes.STRIKETHROUGH;
|
|
3937
3927
|
return attributes;
|
|
3938
3928
|
}
|
|
3929
|
+
function visualizeRenderableTree(renderable, maxDepth = 10) {
|
|
3930
|
+
function buildTreeLines(node, prefix = "", parentPrefix = "", isLastChild = true, depth = 0) {
|
|
3931
|
+
if (depth >= maxDepth) {
|
|
3932
|
+
return [`${prefix}${node.id} ... (max depth reached)`];
|
|
3933
|
+
}
|
|
3934
|
+
const lines = [];
|
|
3935
|
+
const children = node.getChildren();
|
|
3936
|
+
lines.push(`${prefix}${node.id}`);
|
|
3937
|
+
if (children.length > 0) {
|
|
3938
|
+
const lastChildIndex = children.length - 1;
|
|
3939
|
+
children.forEach((child, index) => {
|
|
3940
|
+
const childIsLast = index === lastChildIndex;
|
|
3941
|
+
const connector = childIsLast ? "\u2514\u2500\u2500 " : "\u251C\u2500\u2500 ";
|
|
3942
|
+
const childPrefix = parentPrefix + (isLastChild ? " " : "\u2502 ");
|
|
3943
|
+
const childLines = buildTreeLines(child, childPrefix + connector, childPrefix, childIsLast, depth + 1);
|
|
3944
|
+
lines.push(...childLines);
|
|
3945
|
+
});
|
|
3946
|
+
}
|
|
3947
|
+
return lines;
|
|
3948
|
+
}
|
|
3949
|
+
const treeLines = buildTreeLines(renderable);
|
|
3950
|
+
console.log(`Renderable Tree:
|
|
3951
|
+
` + treeLines.join(`
|
|
3952
|
+
`));
|
|
3953
|
+
}
|
|
3939
3954
|
|
|
3940
3955
|
// src/lib/styled-text.ts
|
|
3941
|
-
var
|
|
3956
|
+
var BrandedStyledText = Symbol.for("@opentui/core/StyledText");
|
|
3957
|
+
function isStyledText(obj) {
|
|
3958
|
+
return obj && obj[BrandedStyledText];
|
|
3959
|
+
}
|
|
3942
3960
|
|
|
3943
3961
|
class StyledText {
|
|
3962
|
+
[BrandedStyledText] = true;
|
|
3944
3963
|
chunks;
|
|
3945
3964
|
textRenderable;
|
|
3946
3965
|
constructor(chunks) {
|
|
@@ -3998,11 +4017,9 @@ class StyledText {
|
|
|
3998
4017
|
}
|
|
3999
4018
|
}
|
|
4000
4019
|
function stringToStyledText(content) {
|
|
4001
|
-
const textEncoder2 = new TextEncoder;
|
|
4002
4020
|
const chunk = {
|
|
4003
4021
|
__isChunk: true,
|
|
4004
|
-
text:
|
|
4005
|
-
plainText: content
|
|
4022
|
+
text: content
|
|
4006
4023
|
};
|
|
4007
4024
|
return new StyledText([chunk]);
|
|
4008
4025
|
}
|
|
@@ -4016,21 +4033,18 @@ function applyStyle(input, style) {
|
|
|
4016
4033
|
return {
|
|
4017
4034
|
__isChunk: true,
|
|
4018
4035
|
text: existingChunk.text,
|
|
4019
|
-
plainText: existingChunk.plainText,
|
|
4020
4036
|
fg,
|
|
4021
4037
|
bg,
|
|
4022
4038
|
attributes: mergedAttrs
|
|
4023
4039
|
};
|
|
4024
4040
|
} else {
|
|
4025
4041
|
const plainTextStr = String(input);
|
|
4026
|
-
const text = textEncoder.encode(plainTextStr);
|
|
4027
4042
|
const fg = style.fg ? parseColor(style.fg) : undefined;
|
|
4028
4043
|
const bg = style.bg ? parseColor(style.bg) : undefined;
|
|
4029
4044
|
const attributes = createTextAttributes(style);
|
|
4030
4045
|
return {
|
|
4031
4046
|
__isChunk: true,
|
|
4032
|
-
text,
|
|
4033
|
-
plainText: plainTextStr,
|
|
4047
|
+
text: plainTextStr,
|
|
4034
4048
|
fg,
|
|
4035
4049
|
bg,
|
|
4036
4050
|
attributes
|
|
@@ -4077,8 +4091,7 @@ function t(strings, ...values) {
|
|
|
4077
4091
|
if (raw) {
|
|
4078
4092
|
chunks.push({
|
|
4079
4093
|
__isChunk: true,
|
|
4080
|
-
text:
|
|
4081
|
-
plainText: raw,
|
|
4094
|
+
text: raw,
|
|
4082
4095
|
attributes: 0
|
|
4083
4096
|
});
|
|
4084
4097
|
}
|
|
@@ -4089,8 +4102,7 @@ function t(strings, ...values) {
|
|
|
4089
4102
|
const plainTextStr = String(val);
|
|
4090
4103
|
chunks.push({
|
|
4091
4104
|
__isChunk: true,
|
|
4092
|
-
text:
|
|
4093
|
-
plainText: plainTextStr,
|
|
4105
|
+
text: plainTextStr,
|
|
4094
4106
|
attributes: 0
|
|
4095
4107
|
});
|
|
4096
4108
|
}
|
|
@@ -4150,7 +4162,6 @@ class SyntaxStyle {
|
|
|
4150
4162
|
return this.mergedStyleCache.size;
|
|
4151
4163
|
}
|
|
4152
4164
|
}
|
|
4153
|
-
var textEncoder2 = new TextEncoder;
|
|
4154
4165
|
function hastToTextChunks(node, syntaxStyle, parentStyles = []) {
|
|
4155
4166
|
const chunks = [];
|
|
4156
4167
|
if (node.type === "text") {
|
|
@@ -4158,8 +4169,7 @@ function hastToTextChunks(node, syntaxStyle, parentStyles = []) {
|
|
|
4158
4169
|
const mergedStyle = syntaxStyle.mergeStyles(...stylesToMerge);
|
|
4159
4170
|
chunks.push({
|
|
4160
4171
|
__isChunk: true,
|
|
4161
|
-
text:
|
|
4162
|
-
plainText: node.value,
|
|
4172
|
+
text: node.value,
|
|
4163
4173
|
fg: mergedStyle.fg,
|
|
4164
4174
|
bg: mergedStyle.bg,
|
|
4165
4175
|
attributes: mergedStyle.attributes
|
|
@@ -4718,10 +4728,16 @@ class OptimizedBuffer {
|
|
|
4718
4728
|
_height;
|
|
4719
4729
|
respectAlpha = false;
|
|
4720
4730
|
_rawBuffers = null;
|
|
4731
|
+
_destroyed = false;
|
|
4721
4732
|
get ptr() {
|
|
4722
4733
|
return this.bufferPtr;
|
|
4723
4734
|
}
|
|
4735
|
+
guard() {
|
|
4736
|
+
if (this._destroyed)
|
|
4737
|
+
throw new Error(`Buffer ${this.id} is destroyed`);
|
|
4738
|
+
}
|
|
4724
4739
|
get buffers() {
|
|
4740
|
+
this.guard();
|
|
4725
4741
|
if (this._rawBuffers === null) {
|
|
4726
4742
|
const size = this._width * this._height;
|
|
4727
4743
|
const charPtr = this.lib.bufferGetCharPtr(this.bufferPtr);
|
|
@@ -4751,9 +4767,6 @@ class OptimizedBuffer {
|
|
|
4751
4767
|
const id = options.id && options.id.trim() !== "" ? options.id : "unnamed buffer";
|
|
4752
4768
|
return lib.createOptimizedBuffer(width, height, widthMethod, respectAlpha, id);
|
|
4753
4769
|
}
|
|
4754
|
-
coordsToIndex(x, y) {
|
|
4755
|
-
return y * this._width + x;
|
|
4756
|
-
}
|
|
4757
4770
|
get width() {
|
|
4758
4771
|
return this._width;
|
|
4759
4772
|
}
|
|
@@ -4761,22 +4774,28 @@ class OptimizedBuffer {
|
|
|
4761
4774
|
return this._height;
|
|
4762
4775
|
}
|
|
4763
4776
|
setRespectAlpha(respectAlpha) {
|
|
4777
|
+
this.guard();
|
|
4764
4778
|
this.lib.bufferSetRespectAlpha(this.bufferPtr, respectAlpha);
|
|
4765
4779
|
this.respectAlpha = respectAlpha;
|
|
4766
4780
|
}
|
|
4767
4781
|
getNativeId() {
|
|
4782
|
+
this.guard();
|
|
4768
4783
|
return this.lib.bufferGetId(this.bufferPtr);
|
|
4769
4784
|
}
|
|
4770
4785
|
clear(bg2 = RGBA.fromValues(0, 0, 0, 1)) {
|
|
4786
|
+
this.guard();
|
|
4771
4787
|
this.lib.bufferClear(this.bufferPtr, bg2);
|
|
4772
4788
|
}
|
|
4773
4789
|
setCell(x, y, char, fg2, bg2, attributes = 0) {
|
|
4790
|
+
this.guard();
|
|
4774
4791
|
this.lib.bufferSetCell(this.bufferPtr, x, y, char, fg2, bg2, attributes);
|
|
4775
4792
|
}
|
|
4776
4793
|
setCellWithAlphaBlending(x, y, char, fg2, bg2, attributes = 0) {
|
|
4794
|
+
this.guard();
|
|
4777
4795
|
this.lib.bufferSetCellWithAlphaBlending(this.bufferPtr, x, y, char, fg2, bg2, attributes);
|
|
4778
4796
|
}
|
|
4779
4797
|
drawText(text, x, y, fg2, bg2, attributes = 0, selection2) {
|
|
4798
|
+
this.guard();
|
|
4780
4799
|
if (!selection2) {
|
|
4781
4800
|
this.lib.bufferDrawText(this.bufferPtr, text, x, y, fg2, bg2, attributes);
|
|
4782
4801
|
return;
|
|
@@ -4809,21 +4828,29 @@ class OptimizedBuffer {
|
|
|
4809
4828
|
this.lib.bufferFillRect(this.bufferPtr, x, y, width, height, bg2);
|
|
4810
4829
|
}
|
|
4811
4830
|
drawFrameBuffer(destX, destY, frameBuffer, sourceX, sourceY, sourceWidth, sourceHeight) {
|
|
4831
|
+
this.guard();
|
|
4812
4832
|
this.lib.drawFrameBuffer(this.bufferPtr, destX, destY, frameBuffer.ptr, sourceX, sourceY, sourceWidth, sourceHeight);
|
|
4813
4833
|
}
|
|
4814
4834
|
destroy() {
|
|
4835
|
+
if (this._destroyed)
|
|
4836
|
+
return;
|
|
4837
|
+
this._destroyed = true;
|
|
4815
4838
|
this.lib.destroyOptimizedBuffer(this.bufferPtr);
|
|
4816
4839
|
}
|
|
4817
4840
|
drawTextBuffer(textBuffer, x, y, clipRect) {
|
|
4841
|
+
this.guard();
|
|
4818
4842
|
this.lib.bufferDrawTextBuffer(this.bufferPtr, textBuffer.ptr, x, y, clipRect);
|
|
4819
4843
|
}
|
|
4820
4844
|
drawSuperSampleBuffer(x, y, pixelDataPtr, pixelDataLength, format, alignedBytesPerRow) {
|
|
4845
|
+
this.guard();
|
|
4821
4846
|
this.lib.bufferDrawSuperSampleBuffer(this.bufferPtr, x, y, pixelDataPtr, pixelDataLength, format, alignedBytesPerRow);
|
|
4822
4847
|
}
|
|
4823
4848
|
drawPackedBuffer(dataPtr, dataLen, posX, posY, terminalWidthCells, terminalHeightCells) {
|
|
4849
|
+
this.guard();
|
|
4824
4850
|
this.lib.bufferDrawPackedBuffer(this.bufferPtr, dataPtr, dataLen, posX, posY, terminalWidthCells, terminalHeightCells);
|
|
4825
4851
|
}
|
|
4826
4852
|
resize(width, height) {
|
|
4853
|
+
this.guard();
|
|
4827
4854
|
if (this._width === width && this._height === height)
|
|
4828
4855
|
return;
|
|
4829
4856
|
this._width = width;
|
|
@@ -4832,18 +4859,22 @@ class OptimizedBuffer {
|
|
|
4832
4859
|
this.lib.bufferResize(this.bufferPtr, width, height);
|
|
4833
4860
|
}
|
|
4834
4861
|
drawBox(options) {
|
|
4862
|
+
this.guard();
|
|
4835
4863
|
const style = options.borderStyle || "single";
|
|
4836
4864
|
const borderChars = options.customBorderChars ?? BorderCharArrays[style];
|
|
4837
4865
|
const packedOptions = packDrawOptions(options.border, options.shouldFill ?? false, options.titleAlignment || "left");
|
|
4838
4866
|
this.lib.bufferDrawBox(this.bufferPtr, options.x, options.y, options.width, options.height, borderChars, packedOptions, options.borderColor, options.backgroundColor, options.title ?? null);
|
|
4839
4867
|
}
|
|
4840
4868
|
pushScissorRect(x, y, width, height) {
|
|
4869
|
+
this.guard();
|
|
4841
4870
|
this.lib.bufferPushScissorRect(this.bufferPtr, x, y, width, height);
|
|
4842
4871
|
}
|
|
4843
4872
|
popScissorRect() {
|
|
4873
|
+
this.guard();
|
|
4844
4874
|
this.lib.bufferPopScissorRect(this.bufferPtr);
|
|
4845
4875
|
}
|
|
4846
4876
|
clearScissorRects() {
|
|
4877
|
+
this.guard();
|
|
4847
4878
|
this.lib.bufferClearScissorRects(this.bufferPtr);
|
|
4848
4879
|
}
|
|
4849
4880
|
}
|
|
@@ -4862,7 +4893,7 @@ function getOpenTUILib(libPath) {
|
|
|
4862
4893
|
returns: "void"
|
|
4863
4894
|
},
|
|
4864
4895
|
createRenderer: {
|
|
4865
|
-
args: ["u32", "u32"],
|
|
4896
|
+
args: ["u32", "u32", "bool"],
|
|
4866
4897
|
returns: "ptr"
|
|
4867
4898
|
},
|
|
4868
4899
|
destroyRenderer: {
|
|
@@ -5249,8 +5280,8 @@ class FFIRenderLib {
|
|
|
5249
5280
|
setLogCallback(callbackPtr) {
|
|
5250
5281
|
this.opentui.symbols.setLogCallback(callbackPtr);
|
|
5251
5282
|
}
|
|
5252
|
-
createRenderer(width, height) {
|
|
5253
|
-
return this.opentui.symbols.createRenderer(width, height);
|
|
5283
|
+
createRenderer(width, height, options = { testing: false }) {
|
|
5284
|
+
return this.opentui.symbols.createRenderer(width, height, options.testing);
|
|
5254
5285
|
}
|
|
5255
5286
|
destroyRenderer(renderer, useAlternateScreen, splitHeight) {
|
|
5256
5287
|
this.opentui.symbols.destroyRenderer(renderer, useAlternateScreen, splitHeight);
|
|
@@ -5676,21 +5707,28 @@ class TextBuffer {
|
|
|
5676
5707
|
_length = 0;
|
|
5677
5708
|
_capacity;
|
|
5678
5709
|
_lineInfo;
|
|
5710
|
+
_destroyed = false;
|
|
5679
5711
|
constructor(lib, ptr2, capacity) {
|
|
5680
5712
|
this.lib = lib;
|
|
5681
5713
|
this.bufferPtr = ptr2;
|
|
5682
5714
|
this._capacity = capacity;
|
|
5683
5715
|
}
|
|
5684
|
-
static create(capacity =
|
|
5716
|
+
static create(capacity = 64, widthMethod) {
|
|
5685
5717
|
const lib = resolveRenderLib();
|
|
5686
5718
|
return lib.createTextBuffer(capacity, widthMethod);
|
|
5687
5719
|
}
|
|
5720
|
+
guard() {
|
|
5721
|
+
if (this._destroyed)
|
|
5722
|
+
throw new Error("TextBuffer is destroyed");
|
|
5723
|
+
}
|
|
5688
5724
|
setStyledText(text) {
|
|
5725
|
+
this.guard();
|
|
5689
5726
|
this.lib.textBufferReset(this.bufferPtr);
|
|
5690
5727
|
this._length = 0;
|
|
5691
5728
|
this._lineInfo = undefined;
|
|
5692
5729
|
for (const chunk of text.chunks) {
|
|
5693
|
-
const
|
|
5730
|
+
const textBytes = this.lib.encoder.encode(chunk.text);
|
|
5731
|
+
const result = this.lib.textBufferWriteChunk(this.bufferPtr, textBytes, chunk.fg || null, chunk.bg || null, chunk.attributes ?? null);
|
|
5694
5732
|
if (result & 1) {
|
|
5695
5733
|
this._capacity = this.lib.textBufferGetCapacity(this.bufferPtr);
|
|
5696
5734
|
}
|
|
@@ -5699,27 +5737,35 @@ class TextBuffer {
|
|
|
5699
5737
|
this._length = this.lib.textBufferGetLength(this.bufferPtr);
|
|
5700
5738
|
}
|
|
5701
5739
|
setDefaultFg(fg2) {
|
|
5740
|
+
this.guard();
|
|
5702
5741
|
this.lib.textBufferSetDefaultFg(this.bufferPtr, fg2);
|
|
5703
5742
|
}
|
|
5704
5743
|
setDefaultBg(bg2) {
|
|
5744
|
+
this.guard();
|
|
5705
5745
|
this.lib.textBufferSetDefaultBg(this.bufferPtr, bg2);
|
|
5706
5746
|
}
|
|
5707
5747
|
setDefaultAttributes(attributes) {
|
|
5748
|
+
this.guard();
|
|
5708
5749
|
this.lib.textBufferSetDefaultAttributes(this.bufferPtr, attributes);
|
|
5709
5750
|
}
|
|
5710
5751
|
resetDefaults() {
|
|
5752
|
+
this.guard();
|
|
5711
5753
|
this.lib.textBufferResetDefaults(this.bufferPtr);
|
|
5712
5754
|
}
|
|
5713
5755
|
get length() {
|
|
5756
|
+
this.guard();
|
|
5714
5757
|
return this._length;
|
|
5715
5758
|
}
|
|
5716
5759
|
get capacity() {
|
|
5760
|
+
this.guard();
|
|
5717
5761
|
return this._capacity;
|
|
5718
5762
|
}
|
|
5719
5763
|
get ptr() {
|
|
5764
|
+
this.guard();
|
|
5720
5765
|
return this.bufferPtr;
|
|
5721
5766
|
}
|
|
5722
5767
|
getSelectedText() {
|
|
5768
|
+
this.guard();
|
|
5723
5769
|
if (this._length === 0)
|
|
5724
5770
|
return "";
|
|
5725
5771
|
const selectedBytes = this.lib.getSelectedTextBytes(this.bufferPtr, this.length * 4);
|
|
@@ -5728,6 +5774,7 @@ class TextBuffer {
|
|
|
5728
5774
|
return this.lib.decoder.decode(selectedBytes);
|
|
5729
5775
|
}
|
|
5730
5776
|
getPlainText() {
|
|
5777
|
+
this.guard();
|
|
5731
5778
|
if (this._length === 0)
|
|
5732
5779
|
return "";
|
|
5733
5780
|
const plainBytes = this.lib.getPlainTextBytes(this.bufferPtr, this.length * 4);
|
|
@@ -5736,53 +5783,69 @@ class TextBuffer {
|
|
|
5736
5783
|
return this.lib.decoder.decode(plainBytes);
|
|
5737
5784
|
}
|
|
5738
5785
|
get lineInfo() {
|
|
5786
|
+
this.guard();
|
|
5739
5787
|
if (!this._lineInfo) {
|
|
5740
5788
|
this._lineInfo = this.lib.textBufferGetLineInfo(this.bufferPtr);
|
|
5741
5789
|
}
|
|
5742
5790
|
return this._lineInfo;
|
|
5743
5791
|
}
|
|
5744
5792
|
setSelection(start, end, bgColor, fgColor) {
|
|
5793
|
+
this.guard();
|
|
5745
5794
|
this.lib.textBufferSetSelection(this.bufferPtr, start, end, bgColor || null, fgColor || null);
|
|
5746
5795
|
}
|
|
5747
5796
|
resetSelection() {
|
|
5797
|
+
this.guard();
|
|
5748
5798
|
this.lib.textBufferResetSelection(this.bufferPtr);
|
|
5749
5799
|
}
|
|
5750
5800
|
setLocalSelection(anchorX, anchorY, focusX, focusY, bgColor, fgColor) {
|
|
5801
|
+
this.guard();
|
|
5751
5802
|
return this.lib.textBufferSetLocalSelection(this.bufferPtr, anchorX, anchorY, focusX, focusY, bgColor || null, fgColor || null);
|
|
5752
5803
|
}
|
|
5753
5804
|
resetLocalSelection() {
|
|
5805
|
+
this.guard();
|
|
5754
5806
|
this.lib.textBufferResetLocalSelection(this.bufferPtr);
|
|
5755
5807
|
}
|
|
5756
5808
|
getSelection() {
|
|
5809
|
+
this.guard();
|
|
5757
5810
|
return this.lib.textBufferGetSelection(this.bufferPtr);
|
|
5758
5811
|
}
|
|
5759
5812
|
hasSelection() {
|
|
5813
|
+
this.guard();
|
|
5760
5814
|
return this.getSelection() !== null;
|
|
5761
5815
|
}
|
|
5762
5816
|
insertChunkGroup(index, text, fg2, bg2, attributes) {
|
|
5817
|
+
this.guard();
|
|
5763
5818
|
const textBytes = this.lib.encoder.encode(text);
|
|
5764
5819
|
this.insertEncodedChunkGroup(index, textBytes, fg2, bg2, attributes);
|
|
5765
5820
|
}
|
|
5766
5821
|
insertEncodedChunkGroup(index, textBytes, fg2, bg2, attributes) {
|
|
5822
|
+
this.guard();
|
|
5767
5823
|
this._length = this.lib.textBufferInsertChunkGroup(this.bufferPtr, index, textBytes, fg2 || null, bg2 || null, attributes ?? null);
|
|
5768
5824
|
this._lineInfo = undefined;
|
|
5769
5825
|
}
|
|
5770
5826
|
removeChunkGroup(index) {
|
|
5827
|
+
this.guard();
|
|
5771
5828
|
this._length = this.lib.textBufferRemoveChunkGroup(this.bufferPtr, index);
|
|
5772
5829
|
this._lineInfo = undefined;
|
|
5773
5830
|
}
|
|
5774
5831
|
replaceChunkGroup(index, text, fg2, bg2, attributes) {
|
|
5832
|
+
this.guard();
|
|
5775
5833
|
const textBytes = this.lib.encoder.encode(text);
|
|
5776
5834
|
this.replaceEncodedChunkGroup(index, textBytes, fg2, bg2, attributes);
|
|
5777
5835
|
}
|
|
5778
5836
|
replaceEncodedChunkGroup(index, textBytes, fg2, bg2, attributes) {
|
|
5837
|
+
this.guard();
|
|
5779
5838
|
this._length = this.lib.textBufferReplaceChunkGroup(this.bufferPtr, index, textBytes, fg2 || null, bg2 || null, attributes ?? null);
|
|
5780
5839
|
this._lineInfo = undefined;
|
|
5781
5840
|
}
|
|
5782
5841
|
get chunkGroupCount() {
|
|
5842
|
+
this.guard();
|
|
5783
5843
|
return this.lib.textBufferGetChunkGroupCount(this.bufferPtr);
|
|
5784
5844
|
}
|
|
5785
5845
|
destroy() {
|
|
5846
|
+
if (this._destroyed)
|
|
5847
|
+
return;
|
|
5848
|
+
this._destroyed = true;
|
|
5786
5849
|
this.lib.destroyTextBuffer(this.bufferPtr);
|
|
5787
5850
|
}
|
|
5788
5851
|
}
|
|
@@ -5877,12 +5940,40 @@ function isRenderable(obj) {
|
|
|
5877
5940
|
return !!obj?.[BrandedRenderable];
|
|
5878
5941
|
}
|
|
5879
5942
|
|
|
5880
|
-
class
|
|
5943
|
+
class BaseRenderable extends EventEmitter3 {
|
|
5881
5944
|
[BrandedRenderable] = true;
|
|
5882
5945
|
static renderableNumber = 1;
|
|
5883
|
-
static renderablesByNumber = new Map;
|
|
5884
5946
|
id;
|
|
5885
5947
|
num;
|
|
5948
|
+
_dirty = false;
|
|
5949
|
+
parent = null;
|
|
5950
|
+
_visible = true;
|
|
5951
|
+
constructor(options) {
|
|
5952
|
+
super();
|
|
5953
|
+
this.num = BaseRenderable.renderableNumber++;
|
|
5954
|
+
this.id = options.id ?? `renderable-${this.num}`;
|
|
5955
|
+
}
|
|
5956
|
+
get isDirty() {
|
|
5957
|
+
return this._dirty;
|
|
5958
|
+
}
|
|
5959
|
+
markClean() {
|
|
5960
|
+
this._dirty = false;
|
|
5961
|
+
}
|
|
5962
|
+
markDirty() {
|
|
5963
|
+
this._dirty = true;
|
|
5964
|
+
}
|
|
5965
|
+
destroy() {}
|
|
5966
|
+
destroyRecursively() {}
|
|
5967
|
+
get visible() {
|
|
5968
|
+
return this._visible;
|
|
5969
|
+
}
|
|
5970
|
+
set visible(value) {
|
|
5971
|
+
this._visible = value;
|
|
5972
|
+
}
|
|
5973
|
+
}
|
|
5974
|
+
|
|
5975
|
+
class Renderable extends BaseRenderable {
|
|
5976
|
+
static renderablesByNumber = new Map;
|
|
5886
5977
|
_isDestroyed = false;
|
|
5887
5978
|
_ctx;
|
|
5888
5979
|
_translateX = 0;
|
|
@@ -5894,12 +5985,10 @@ class Renderable extends EventEmitter3 {
|
|
|
5894
5985
|
_widthValue = 0;
|
|
5895
5986
|
_heightValue = 0;
|
|
5896
5987
|
_zIndex;
|
|
5897
|
-
_visible;
|
|
5898
5988
|
selectable = false;
|
|
5899
5989
|
buffered;
|
|
5900
5990
|
frameBuffer = null;
|
|
5901
|
-
|
|
5902
|
-
focusable = false;
|
|
5991
|
+
_focusable = false;
|
|
5903
5992
|
_focused = false;
|
|
5904
5993
|
keyHandler = getKeyHandler();
|
|
5905
5994
|
keypressHandler = null;
|
|
@@ -5919,12 +6008,12 @@ class Renderable extends EventEmitter3 {
|
|
|
5919
6008
|
parent = null;
|
|
5920
6009
|
childrenPrimarySortDirty = true;
|
|
5921
6010
|
childrenSortedByPrimaryAxis = [];
|
|
6011
|
+
_newChildren = [];
|
|
6012
|
+
onLifecyclePass = null;
|
|
5922
6013
|
renderBefore;
|
|
5923
6014
|
renderAfter;
|
|
5924
6015
|
constructor(ctx, options) {
|
|
5925
|
-
super();
|
|
5926
|
-
this.num = Renderable.renderableNumber++;
|
|
5927
|
-
this.id = options.id ?? `renderable-${this.num}`;
|
|
6016
|
+
super(options);
|
|
5928
6017
|
this._ctx = ctx;
|
|
5929
6018
|
Renderable.renderablesByNumber.set(this.num, this);
|
|
5930
6019
|
validateOptions(this.id, options);
|
|
@@ -5951,12 +6040,19 @@ class Renderable extends EventEmitter3 {
|
|
|
5951
6040
|
this.createFrameBuffer();
|
|
5952
6041
|
}
|
|
5953
6042
|
}
|
|
6043
|
+
get focusable() {
|
|
6044
|
+
return this._focusable;
|
|
6045
|
+
}
|
|
5954
6046
|
get ctx() {
|
|
5955
6047
|
return this._ctx;
|
|
5956
6048
|
}
|
|
5957
6049
|
get visible() {
|
|
5958
6050
|
return this._visible;
|
|
5959
6051
|
}
|
|
6052
|
+
get primaryAxis() {
|
|
6053
|
+
const dir = this.layoutNode.yogaNode.getFlexDirection();
|
|
6054
|
+
return dir === 2 || dir === 3 ? "row" : "column";
|
|
6055
|
+
}
|
|
5960
6056
|
set visible(value) {
|
|
5961
6057
|
if (this._visible === value)
|
|
5962
6058
|
return;
|
|
@@ -5988,8 +6084,9 @@ class Renderable extends EventEmitter3 {
|
|
|
5988
6084
|
return false;
|
|
5989
6085
|
}
|
|
5990
6086
|
focus() {
|
|
5991
|
-
if (this._focused || !this.
|
|
6087
|
+
if (this._focused || !this._focusable)
|
|
5992
6088
|
return;
|
|
6089
|
+
this._ctx.focusRenderable(this);
|
|
5993
6090
|
this._focused = true;
|
|
5994
6091
|
this.requestRender();
|
|
5995
6092
|
this.keypressHandler = (key) => {
|
|
@@ -6002,7 +6099,7 @@ class Renderable extends EventEmitter3 {
|
|
|
6002
6099
|
this.emit("focused" /* FOCUSED */);
|
|
6003
6100
|
}
|
|
6004
6101
|
blur() {
|
|
6005
|
-
if (!this._focused || !this.
|
|
6102
|
+
if (!this._focused || !this._focusable)
|
|
6006
6103
|
return;
|
|
6007
6104
|
this._focused = false;
|
|
6008
6105
|
this.requestRender();
|
|
@@ -6034,9 +6131,6 @@ class Renderable extends EventEmitter3 {
|
|
|
6034
6131
|
this._liveCount += delta;
|
|
6035
6132
|
this.parent?.propagateLiveCount(delta);
|
|
6036
6133
|
}
|
|
6037
|
-
get isDirty() {
|
|
6038
|
-
return this._dirty;
|
|
6039
|
-
}
|
|
6040
6134
|
findDescendantById(id) {
|
|
6041
6135
|
for (const child of this.renderableArray) {
|
|
6042
6136
|
if (child.id === id)
|
|
@@ -6047,11 +6141,8 @@ class Renderable extends EventEmitter3 {
|
|
|
6047
6141
|
}
|
|
6048
6142
|
return;
|
|
6049
6143
|
}
|
|
6050
|
-
markClean() {
|
|
6051
|
-
this._dirty = false;
|
|
6052
|
-
}
|
|
6053
6144
|
requestRender() {
|
|
6054
|
-
this.
|
|
6145
|
+
this.markDirty();
|
|
6055
6146
|
this._ctx.requestRender();
|
|
6056
6147
|
}
|
|
6057
6148
|
get translateX() {
|
|
@@ -6164,80 +6255,6 @@ class Renderable extends EventEmitter3 {
|
|
|
6164
6255
|
this.needsZIndexSort = false;
|
|
6165
6256
|
}
|
|
6166
6257
|
}
|
|
6167
|
-
getChildrenInViewport(viewport, padding = 10, minTriggerSize = 16) {
|
|
6168
|
-
if (this.renderableArray.length < minTriggerSize)
|
|
6169
|
-
return this.renderableArray;
|
|
6170
|
-
const viewportTop = viewport.y - padding;
|
|
6171
|
-
const viewportBottom = viewport.y + viewport.height + padding;
|
|
6172
|
-
const viewportLeft = viewport.x - padding;
|
|
6173
|
-
const viewportRight = viewport.x + viewport.width + padding;
|
|
6174
|
-
const dir = this.layoutNode.yogaNode.getFlexDirection();
|
|
6175
|
-
const isRow = dir === 2 || dir === 3;
|
|
6176
|
-
const children = this.getChildrenSortedByPrimaryAxis();
|
|
6177
|
-
const totalChildren = children.length;
|
|
6178
|
-
if (totalChildren === 0)
|
|
6179
|
-
return [];
|
|
6180
|
-
const vpStart = isRow ? viewportLeft : viewportTop;
|
|
6181
|
-
const vpEnd = isRow ? viewportRight : viewportBottom;
|
|
6182
|
-
let lo = 0;
|
|
6183
|
-
let hi = totalChildren - 1;
|
|
6184
|
-
let candidate = -1;
|
|
6185
|
-
while (lo <= hi) {
|
|
6186
|
-
const mid = lo + hi >> 1;
|
|
6187
|
-
const c = children[mid];
|
|
6188
|
-
const start = isRow ? c.x : c.y;
|
|
6189
|
-
const end = isRow ? c.x + c.width : c.y + c.height;
|
|
6190
|
-
if (end < vpStart) {
|
|
6191
|
-
lo = mid + 1;
|
|
6192
|
-
} else if (start > vpEnd) {
|
|
6193
|
-
hi = mid - 1;
|
|
6194
|
-
} else {
|
|
6195
|
-
candidate = mid;
|
|
6196
|
-
break;
|
|
6197
|
-
}
|
|
6198
|
-
}
|
|
6199
|
-
const visibleChildren = [];
|
|
6200
|
-
if (candidate === -1) {
|
|
6201
|
-
return visibleChildren;
|
|
6202
|
-
}
|
|
6203
|
-
let left = candidate;
|
|
6204
|
-
while (left - 1 >= 0) {
|
|
6205
|
-
const prev = children[left - 1];
|
|
6206
|
-
if ((isRow ? prev.x + prev.width : prev.y + prev.height) < vpStart)
|
|
6207
|
-
break;
|
|
6208
|
-
left--;
|
|
6209
|
-
}
|
|
6210
|
-
let right = candidate + 1;
|
|
6211
|
-
while (right < totalChildren) {
|
|
6212
|
-
const next = children[right];
|
|
6213
|
-
if ((isRow ? next.x : next.y) > vpEnd)
|
|
6214
|
-
break;
|
|
6215
|
-
right++;
|
|
6216
|
-
}
|
|
6217
|
-
for (let i = left;i < right; i++) {
|
|
6218
|
-
const child = children[i];
|
|
6219
|
-
if (isRow) {
|
|
6220
|
-
const childBottom = child.y + child.height;
|
|
6221
|
-
if (childBottom < viewportTop)
|
|
6222
|
-
continue;
|
|
6223
|
-
const childTop = child.y;
|
|
6224
|
-
if (childTop > viewportBottom)
|
|
6225
|
-
continue;
|
|
6226
|
-
} else {
|
|
6227
|
-
const childRight = child.x + child.width;
|
|
6228
|
-
if (childRight < viewportLeft)
|
|
6229
|
-
continue;
|
|
6230
|
-
const childLeft = child.x;
|
|
6231
|
-
if (childLeft > viewportRight)
|
|
6232
|
-
continue;
|
|
6233
|
-
}
|
|
6234
|
-
visibleChildren.push(child);
|
|
6235
|
-
}
|
|
6236
|
-
if (visibleChildren.length > 1) {
|
|
6237
|
-
visibleChildren.sort((a, b) => a.zIndex > b.zIndex ? 1 : a.zIndex < b.zIndex ? -1 : 0);
|
|
6238
|
-
}
|
|
6239
|
-
return visibleChildren;
|
|
6240
|
-
}
|
|
6241
6258
|
getChildrenSortedByPrimaryAxis() {
|
|
6242
6259
|
if (!this.childrenPrimarySortDirty && this.childrenSortedByPrimaryAxis.length === this.renderableArray.length) {
|
|
6243
6260
|
return this.childrenSortedByPrimaryAxis;
|
|
@@ -6609,6 +6626,7 @@ class Renderable extends EventEmitter3 {
|
|
|
6609
6626
|
}
|
|
6610
6627
|
obj.parent = this;
|
|
6611
6628
|
}
|
|
6629
|
+
_forceLayoutUpdateFor = null;
|
|
6612
6630
|
add(obj, index) {
|
|
6613
6631
|
if (!obj) {
|
|
6614
6632
|
return -1;
|
|
@@ -6632,6 +6650,7 @@ class Renderable extends EventEmitter3 {
|
|
|
6632
6650
|
let insertedIndex;
|
|
6633
6651
|
if (index !== undefined) {
|
|
6634
6652
|
this.renderableArray.splice(index, 0, renderable);
|
|
6653
|
+
this._forceLayoutUpdateFor = this.renderableArray.slice(index);
|
|
6635
6654
|
insertedIndex = this.layoutNode.insertChild(childLayoutNode, index);
|
|
6636
6655
|
} else {
|
|
6637
6656
|
this.renderableArray.push(renderable);
|
|
@@ -6640,6 +6659,10 @@ class Renderable extends EventEmitter3 {
|
|
|
6640
6659
|
this.needsZIndexSort = true;
|
|
6641
6660
|
this.childrenPrimarySortDirty = true;
|
|
6642
6661
|
this.renderableMap.set(renderable.id, renderable);
|
|
6662
|
+
if (typeof renderable.onLifecyclePass === "function") {
|
|
6663
|
+
this._ctx.registerLifecyclePass(renderable);
|
|
6664
|
+
}
|
|
6665
|
+
this._newChildren.push(renderable);
|
|
6643
6666
|
if (renderable._liveCount > 0) {
|
|
6644
6667
|
this.propagateLiveCount(renderable._liveCount);
|
|
6645
6668
|
}
|
|
@@ -6657,6 +6680,9 @@ class Renderable extends EventEmitter3 {
|
|
|
6657
6680
|
if (!anchor) {
|
|
6658
6681
|
return this.add(renderable);
|
|
6659
6682
|
}
|
|
6683
|
+
if (!isRenderable(anchor)) {
|
|
6684
|
+
throw new Error("Anchor must be a Renderable");
|
|
6685
|
+
}
|
|
6660
6686
|
if (!this.renderableMap.has(anchor.id)) {
|
|
6661
6687
|
throw new Error("Anchor does not exist");
|
|
6662
6688
|
}
|
|
@@ -6684,6 +6710,7 @@ class Renderable extends EventEmitter3 {
|
|
|
6684
6710
|
this.requestRender();
|
|
6685
6711
|
obj.onRemove();
|
|
6686
6712
|
obj.parent = null;
|
|
6713
|
+
this._ctx.unregisterLifecyclePass(obj);
|
|
6687
6714
|
}
|
|
6688
6715
|
this.renderableMap.delete(id);
|
|
6689
6716
|
const index = this.renderableArray.findIndex((obj2) => obj2.id === id);
|
|
@@ -6700,11 +6727,44 @@ class Renderable extends EventEmitter3 {
|
|
|
6700
6727
|
getChildrenCount() {
|
|
6701
6728
|
return this.renderableArray.length;
|
|
6702
6729
|
}
|
|
6703
|
-
|
|
6730
|
+
updateLayout(deltaTime, renderList = []) {
|
|
6704
6731
|
if (!this.visible)
|
|
6705
6732
|
return;
|
|
6706
6733
|
this.onUpdate(deltaTime);
|
|
6707
6734
|
this.updateFromLayout();
|
|
6735
|
+
renderList.push({ action: "render", renderable: this });
|
|
6736
|
+
if (this._newChildren.length > 0) {
|
|
6737
|
+
for (const child of this._newChildren) {
|
|
6738
|
+
child.updateFromLayout();
|
|
6739
|
+
}
|
|
6740
|
+
this._newChildren = [];
|
|
6741
|
+
}
|
|
6742
|
+
if (this._forceLayoutUpdateFor) {
|
|
6743
|
+
for (const child of this._forceLayoutUpdateFor) {
|
|
6744
|
+
child.updateFromLayout();
|
|
6745
|
+
}
|
|
6746
|
+
this._forceLayoutUpdateFor = null;
|
|
6747
|
+
}
|
|
6748
|
+
this.ensureZIndexSorted();
|
|
6749
|
+
const shouldPushScissor = this._overflow !== "visible" && this.width > 0 && this.height > 0;
|
|
6750
|
+
if (shouldPushScissor) {
|
|
6751
|
+
const scissorRect = this.getScissorRect();
|
|
6752
|
+
renderList.push({
|
|
6753
|
+
action: "pushScissorRect",
|
|
6754
|
+
x: scissorRect.x,
|
|
6755
|
+
y: scissorRect.y,
|
|
6756
|
+
width: scissorRect.width,
|
|
6757
|
+
height: scissorRect.height
|
|
6758
|
+
});
|
|
6759
|
+
}
|
|
6760
|
+
for (const child of this._getChildren()) {
|
|
6761
|
+
child.updateLayout(deltaTime, renderList);
|
|
6762
|
+
}
|
|
6763
|
+
if (shouldPushScissor) {
|
|
6764
|
+
renderList.push({ action: "popScissorRect" });
|
|
6765
|
+
}
|
|
6766
|
+
}
|
|
6767
|
+
render(buffer, deltaTime) {
|
|
6708
6768
|
let renderBuffer = buffer;
|
|
6709
6769
|
if (this.buffered && this.frameBuffer) {
|
|
6710
6770
|
renderBuffer = this.frameBuffer;
|
|
@@ -6718,18 +6778,6 @@ class Renderable extends EventEmitter3 {
|
|
|
6718
6778
|
}
|
|
6719
6779
|
this.markClean();
|
|
6720
6780
|
this._ctx.addToHitGrid(this.x, this.y, this.width, this.height, this.num);
|
|
6721
|
-
this.ensureZIndexSorted();
|
|
6722
|
-
const shouldPushScissor = this._overflow !== "visible" && this.width > 0 && this.height > 0;
|
|
6723
|
-
if (shouldPushScissor) {
|
|
6724
|
-
const scissorRect = this.getScissorRect();
|
|
6725
|
-
renderBuffer.pushScissorRect(scissorRect.x, scissorRect.y, scissorRect.width, scissorRect.height);
|
|
6726
|
-
}
|
|
6727
|
-
for (const child of this._getChildren()) {
|
|
6728
|
-
child.render(renderBuffer, deltaTime);
|
|
6729
|
-
}
|
|
6730
|
-
if (shouldPushScissor) {
|
|
6731
|
-
renderBuffer.popScissorRect();
|
|
6732
|
-
}
|
|
6733
6781
|
if (this.buffered && this.frameBuffer) {
|
|
6734
6782
|
buffer.drawFrameBuffer(this.x, this.y, this.frameBuffer);
|
|
6735
6783
|
}
|
|
@@ -6882,6 +6930,7 @@ class Renderable extends EventEmitter3 {
|
|
|
6882
6930
|
|
|
6883
6931
|
class RootRenderable extends Renderable {
|
|
6884
6932
|
yogaConfig;
|
|
6933
|
+
renderList = [];
|
|
6885
6934
|
constructor(ctx) {
|
|
6886
6935
|
super(ctx, { id: "__root__", zIndex: 0, visible: true, width: ctx.width, height: ctx.height, enableLayout: true });
|
|
6887
6936
|
this.yogaConfig = src_default.Config.create();
|
|
@@ -6896,6 +6945,32 @@ class RootRenderable extends Renderable {
|
|
|
6896
6945
|
this.layoutNode.yogaNode.setFlexDirection(FlexDirection.Column);
|
|
6897
6946
|
this.calculateLayout();
|
|
6898
6947
|
}
|
|
6948
|
+
render(buffer, deltaTime) {
|
|
6949
|
+
if (!this.visible)
|
|
6950
|
+
return;
|
|
6951
|
+
for (const renderable of this._ctx.getLifecyclePasses()) {
|
|
6952
|
+
renderable.onLifecyclePass?.call(renderable);
|
|
6953
|
+
}
|
|
6954
|
+
if (this.layoutNode.yogaNode.isDirty()) {
|
|
6955
|
+
this.calculateLayout();
|
|
6956
|
+
}
|
|
6957
|
+
this.renderList.length = 0;
|
|
6958
|
+
this.updateLayout(deltaTime, this.renderList);
|
|
6959
|
+
for (let i = 1;i < this.renderList.length; i++) {
|
|
6960
|
+
const command = this.renderList[i];
|
|
6961
|
+
switch (command.action) {
|
|
6962
|
+
case "render":
|
|
6963
|
+
command.renderable.render(buffer, deltaTime);
|
|
6964
|
+
break;
|
|
6965
|
+
case "pushScissorRect":
|
|
6966
|
+
buffer.pushScissorRect(command.x, command.y, command.width, command.height);
|
|
6967
|
+
break;
|
|
6968
|
+
case "popScissorRect":
|
|
6969
|
+
buffer.popScissorRect();
|
|
6970
|
+
break;
|
|
6971
|
+
}
|
|
6972
|
+
}
|
|
6973
|
+
}
|
|
6899
6974
|
propagateLiveCount(delta) {
|
|
6900
6975
|
const oldCount = this._liveCount;
|
|
6901
6976
|
this._liveCount += delta;
|
|
@@ -6914,15 +6989,7 @@ class RootRenderable extends Renderable {
|
|
|
6914
6989
|
this.height = height;
|
|
6915
6990
|
this.emit("resized" /* RESIZED */, { width, height });
|
|
6916
6991
|
}
|
|
6917
|
-
onUpdate() {
|
|
6918
|
-
if (this.layoutNode.yogaNode.isDirty()) {
|
|
6919
|
-
this.calculateLayout();
|
|
6920
|
-
}
|
|
6921
|
-
}
|
|
6922
6992
|
destroySelf() {
|
|
6923
|
-
if (this.layoutNode) {
|
|
6924
|
-
this.layoutNode.destroy();
|
|
6925
|
-
}
|
|
6926
6993
|
try {
|
|
6927
6994
|
this.yogaConfig.free();
|
|
6928
6995
|
} catch (error) {}
|
|
@@ -7783,6 +7850,83 @@ var ANSI = {
|
|
|
7783
7850
|
|
|
7784
7851
|
// src/renderer.ts
|
|
7785
7852
|
import { EventEmitter as EventEmitter6 } from "events";
|
|
7853
|
+
|
|
7854
|
+
// src/lib/objects-in-viewport.ts
|
|
7855
|
+
function getObjectsInViewport(viewport, objects, direction = "column", padding = 10, minTriggerSize = 16) {
|
|
7856
|
+
if (objects.length < minTriggerSize)
|
|
7857
|
+
return objects;
|
|
7858
|
+
const viewportTop = viewport.y - padding;
|
|
7859
|
+
const viewportBottom = viewport.y + viewport.height + padding;
|
|
7860
|
+
const viewportLeft = viewport.x - padding;
|
|
7861
|
+
const viewportRight = viewport.x + viewport.width + padding;
|
|
7862
|
+
const isRow = direction === "row";
|
|
7863
|
+
const children = objects;
|
|
7864
|
+
const totalChildren = children.length;
|
|
7865
|
+
if (totalChildren === 0)
|
|
7866
|
+
return [];
|
|
7867
|
+
const vpStart = isRow ? viewportLeft : viewportTop;
|
|
7868
|
+
const vpEnd = isRow ? viewportRight : viewportBottom;
|
|
7869
|
+
let lo = 0;
|
|
7870
|
+
let hi = totalChildren - 1;
|
|
7871
|
+
let candidate = -1;
|
|
7872
|
+
while (lo <= hi) {
|
|
7873
|
+
const mid = lo + hi >> 1;
|
|
7874
|
+
const c = children[mid];
|
|
7875
|
+
const start = isRow ? c.x : c.y;
|
|
7876
|
+
const end = isRow ? c.x + c.width : c.y + c.height;
|
|
7877
|
+
if (end < vpStart) {
|
|
7878
|
+
lo = mid + 1;
|
|
7879
|
+
} else if (start > vpEnd) {
|
|
7880
|
+
hi = mid - 1;
|
|
7881
|
+
} else {
|
|
7882
|
+
candidate = mid;
|
|
7883
|
+
break;
|
|
7884
|
+
}
|
|
7885
|
+
}
|
|
7886
|
+
const visibleChildren = [];
|
|
7887
|
+
if (candidate === -1) {
|
|
7888
|
+
return visibleChildren;
|
|
7889
|
+
}
|
|
7890
|
+
let left = candidate;
|
|
7891
|
+
while (left - 1 >= 0) {
|
|
7892
|
+
const prev = children[left - 1];
|
|
7893
|
+
if ((isRow ? prev.x + prev.width : prev.y + prev.height) < vpStart)
|
|
7894
|
+
break;
|
|
7895
|
+
left--;
|
|
7896
|
+
}
|
|
7897
|
+
let right = candidate + 1;
|
|
7898
|
+
while (right < totalChildren) {
|
|
7899
|
+
const next = children[right];
|
|
7900
|
+
if ((isRow ? next.x : next.y) > vpEnd)
|
|
7901
|
+
break;
|
|
7902
|
+
right++;
|
|
7903
|
+
}
|
|
7904
|
+
for (let i = left;i < right; i++) {
|
|
7905
|
+
const child = children[i];
|
|
7906
|
+
if (isRow) {
|
|
7907
|
+
const childBottom = child.y + child.height;
|
|
7908
|
+
if (childBottom < viewportTop)
|
|
7909
|
+
continue;
|
|
7910
|
+
const childTop = child.y;
|
|
7911
|
+
if (childTop > viewportBottom)
|
|
7912
|
+
continue;
|
|
7913
|
+
} else {
|
|
7914
|
+
const childRight = child.x + child.width;
|
|
7915
|
+
if (childRight < viewportLeft)
|
|
7916
|
+
continue;
|
|
7917
|
+
const childLeft = child.x;
|
|
7918
|
+
if (childLeft > viewportRight)
|
|
7919
|
+
continue;
|
|
7920
|
+
}
|
|
7921
|
+
visibleChildren.push(child);
|
|
7922
|
+
}
|
|
7923
|
+
if (visibleChildren.length > 1) {
|
|
7924
|
+
visibleChildren.sort((a, b) => a.zIndex > b.zIndex ? 1 : a.zIndex < b.zIndex ? -1 : 0);
|
|
7925
|
+
}
|
|
7926
|
+
return visibleChildren;
|
|
7927
|
+
}
|
|
7928
|
+
|
|
7929
|
+
// src/renderer.ts
|
|
7786
7930
|
class MouseEvent {
|
|
7787
7931
|
type;
|
|
7788
7932
|
button;
|
|
@@ -7944,6 +8088,8 @@ class CliRenderer extends EventEmitter6 {
|
|
|
7944
8088
|
sigwinchHandler = null;
|
|
7945
8089
|
_capabilities = null;
|
|
7946
8090
|
_latestPointer = { x: 0, y: 0 };
|
|
8091
|
+
_currentFocusedRenderable = null;
|
|
8092
|
+
lifecyclePasses = new Set;
|
|
7947
8093
|
constructor(lib, rendererPtr, stdin, stdout, width, height, config = {}) {
|
|
7948
8094
|
super();
|
|
7949
8095
|
this.stdin = stdin;
|
|
@@ -8036,6 +8182,7 @@ Error details:
|
|
|
8036
8182
|
global.requestAnimationFrame = (callback) => {
|
|
8037
8183
|
const id = CliRenderer.animationFrameId++;
|
|
8038
8184
|
this.animationRequest.set(id, callback);
|
|
8185
|
+
this.requestLive();
|
|
8039
8186
|
return id;
|
|
8040
8187
|
};
|
|
8041
8188
|
global.cancelAnimationFrame = (handle) => {
|
|
@@ -8053,6 +8200,27 @@ Error details:
|
|
|
8053
8200
|
}
|
|
8054
8201
|
};
|
|
8055
8202
|
}
|
|
8203
|
+
this.setupInput();
|
|
8204
|
+
}
|
|
8205
|
+
registerLifecyclePass(renderable) {
|
|
8206
|
+
this.lifecyclePasses.add(renderable);
|
|
8207
|
+
}
|
|
8208
|
+
unregisterLifecyclePass(renderable) {
|
|
8209
|
+
this.lifecyclePasses.delete(renderable);
|
|
8210
|
+
}
|
|
8211
|
+
getLifecyclePasses() {
|
|
8212
|
+
return this.lifecyclePasses;
|
|
8213
|
+
}
|
|
8214
|
+
get currentFocusedRenderable() {
|
|
8215
|
+
return this._currentFocusedRenderable;
|
|
8216
|
+
}
|
|
8217
|
+
focusRenderable(renderable) {
|
|
8218
|
+
if (this._currentFocusedRenderable === renderable)
|
|
8219
|
+
return;
|
|
8220
|
+
if (this._currentFocusedRenderable) {
|
|
8221
|
+
this._currentFocusedRenderable.blur();
|
|
8222
|
+
}
|
|
8223
|
+
this._currentFocusedRenderable = renderable;
|
|
8056
8224
|
}
|
|
8057
8225
|
addToHitGrid(x, y, width, height, id) {
|
|
8058
8226
|
if (id !== this.capturedRenderable?.num) {
|
|
@@ -8246,6 +8414,9 @@ Error details:
|
|
|
8246
8414
|
if (this._useMouse) {
|
|
8247
8415
|
this.enableMouse();
|
|
8248
8416
|
}
|
|
8417
|
+
this.queryPixelResolution();
|
|
8418
|
+
}
|
|
8419
|
+
setupInput() {
|
|
8249
8420
|
this.stdin.on("data", (data) => {
|
|
8250
8421
|
const str = data.toString();
|
|
8251
8422
|
if (this.waitingForPixelResolution && /\x1b\[4;\d+;\d+t/.test(str)) {
|
|
@@ -8271,7 +8442,6 @@ Error details:
|
|
|
8271
8442
|
}
|
|
8272
8443
|
this.emit("key", data);
|
|
8273
8444
|
});
|
|
8274
|
-
this.queryPixelResolution();
|
|
8275
8445
|
}
|
|
8276
8446
|
handleMouseData(data) {
|
|
8277
8447
|
const mouseEvent = this.mouseParser.parseMouseEvent(data);
|
|
@@ -8298,7 +8468,7 @@ Error details:
|
|
|
8298
8468
|
this.lastOverRenderableNum = maybeRenderableId;
|
|
8299
8469
|
const maybeRenderable = Renderable.renderablesByNumber.get(maybeRenderableId);
|
|
8300
8470
|
if (mouseEvent.type === "down" && mouseEvent.button === 0 /* LEFT */ && !this.currentSelection?.isSelecting && !mouseEvent.modifiers.ctrl) {
|
|
8301
|
-
if (maybeRenderable && maybeRenderable.selectable && maybeRenderable.shouldStartSelection(mouseEvent.x, mouseEvent.y)) {
|
|
8471
|
+
if (maybeRenderable && maybeRenderable.selectable && !maybeRenderable.isDestroyed && maybeRenderable.shouldStartSelection(mouseEvent.x, mouseEvent.y)) {
|
|
8302
8472
|
this.startSelection(maybeRenderable, mouseEvent.x, mouseEvent.y);
|
|
8303
8473
|
const event2 = new MouseEvent(maybeRenderable, mouseEvent);
|
|
8304
8474
|
maybeRenderable.processMouseEvent(event2);
|
|
@@ -8646,7 +8816,10 @@ Error details:
|
|
|
8646
8816
|
const frameRequests = Array.from(this.animationRequest.values());
|
|
8647
8817
|
this.animationRequest.clear();
|
|
8648
8818
|
const animationRequestStart = performance.now();
|
|
8649
|
-
frameRequests.forEach((callback) =>
|
|
8819
|
+
frameRequests.forEach((callback) => {
|
|
8820
|
+
callback(deltaTime);
|
|
8821
|
+
this.dropLive();
|
|
8822
|
+
});
|
|
8650
8823
|
const animationRequestEnd = performance.now();
|
|
8651
8824
|
const animationRequestTime = animationRequestEnd - animationRequestStart;
|
|
8652
8825
|
const start = performance.now();
|
|
@@ -8740,7 +8913,7 @@ Error details:
|
|
|
8740
8913
|
clearSelection() {
|
|
8741
8914
|
if (this.currentSelection) {
|
|
8742
8915
|
for (const renderable of this.currentSelection.touchedRenderables) {
|
|
8743
|
-
if (renderable.selectable) {
|
|
8916
|
+
if (renderable.selectable && !renderable.isDestroyed) {
|
|
8744
8917
|
renderable.onSelectionChanged(null);
|
|
8745
8918
|
}
|
|
8746
8919
|
}
|
|
@@ -8815,7 +8988,7 @@ Error details:
|
|
|
8815
8988
|
}
|
|
8816
8989
|
}
|
|
8817
8990
|
walkSelectableRenderables(container, selectionBounds, selectedRenderables, touchedRenderables) {
|
|
8818
|
-
const children = container.
|
|
8991
|
+
const children = getObjectsInViewport(selectionBounds, container.getChildrenSortedByPrimaryAxis(), container.primaryAxis, 0);
|
|
8819
8992
|
for (const child of children) {
|
|
8820
8993
|
if (child.selectable) {
|
|
8821
8994
|
const hasSelection = child.onSelectionChanged(this.currentSelection);
|
|
@@ -8831,7 +9004,7 @@ Error details:
|
|
|
8831
9004
|
}
|
|
8832
9005
|
}
|
|
8833
9006
|
|
|
8834
|
-
export { __toESM, __commonJS, __export, __require, Edge, Gutter, MeasureMode, BorderChars, getBorderFromSides, getBorderSides, borderCharsToArray, BorderCharArrays, TrackedNode, createTrackedNode, nonAlphanumericKeys, parseKeypress, KeyHandler, getKeyHandler, RGBA, hexToRgb, rgbToHex, hsvToRgb, parseColor, fonts, measureText, getCharacterPositions, coordinateToCharacterIndex, renderFontToFrameBuffer, TextAttributes, DebugOverlayCorner, createTextAttributes, StyledText, stringToStyledText, black, red, green, yellow, blue, magenta, cyan, white, brightBlack, brightRed, brightGreen, brightYellow, brightBlue, brightMagenta, brightCyan, brightWhite, bgBlack, bgRed, bgGreen, bgYellow, bgBlue, bgMagenta, bgCyan, bgWhite, bold, italic, underline, strikethrough, dim, reverse, blink, fg, bg, t, SyntaxStyle, hastToStyledText, parseAlign, parseBoxSizing, parseDimension, parseDirection, parseDisplay, parseEdge, parseFlexDirection, parseGutter, parseJustify, parseLogLevel, parseMeasureMode, parseOverflow, parsePositionType, parseUnit, parseWrap, MouseParser, Selection, convertGlobalToLocalSelection, ASCIIFontSelectionHelper, TextBuffer, LogLevel2 as LogLevel, setRenderLibPath, resolveRenderLib, OptimizedBuffer, h, isVNode, maybeMakeRenderable, wrapWithDelegates, instantiate, delegate, LayoutEvents, RenderableEvents, isValidPercentage, isMarginType, isPaddingType, isPositionType, isPositionTypeType, isOverflowType, isDimensionType, isFlexBasisType, isSizeType, isRenderable, Renderable, RootRenderable, capture, ConsolePosition, TerminalConsole, MouseEvent, MouseButton, createCliRenderer, CliRenderEvents, CliRenderer };
|
|
9007
|
+
export { __toESM, __commonJS, __export, __require, Edge, Gutter, MeasureMode, BorderChars, getBorderFromSides, getBorderSides, borderCharsToArray, BorderCharArrays, TrackedNode, createTrackedNode, nonAlphanumericKeys, parseKeypress, KeyHandler, getKeyHandler, RGBA, hexToRgb, rgbToHex, hsvToRgb, parseColor, fonts, measureText, getCharacterPositions, coordinateToCharacterIndex, renderFontToFrameBuffer, TextAttributes, DebugOverlayCorner, createTextAttributes, visualizeRenderableTree, isStyledText, StyledText, stringToStyledText, black, red, green, yellow, blue, magenta, cyan, white, brightBlack, brightRed, brightGreen, brightYellow, brightBlue, brightMagenta, brightCyan, brightWhite, bgBlack, bgRed, bgGreen, bgYellow, bgBlue, bgMagenta, bgCyan, bgWhite, bold, italic, underline, strikethrough, dim, reverse, blink, fg, bg, t, SyntaxStyle, hastToStyledText, parseAlign, parseBoxSizing, parseDimension, parseDirection, parseDisplay, parseEdge, parseFlexDirection, parseGutter, parseJustify, parseLogLevel, parseMeasureMode, parseOverflow, parsePositionType, parseUnit, parseWrap, MouseParser, Selection, convertGlobalToLocalSelection, ASCIIFontSelectionHelper, TextBuffer, LogLevel2 as LogLevel, setRenderLibPath, resolveRenderLib, OptimizedBuffer, h, isVNode, maybeMakeRenderable, wrapWithDelegates, instantiate, delegate, LayoutEvents, RenderableEvents, isValidPercentage, isMarginType, isPaddingType, isPositionType, isPositionTypeType, isOverflowType, isDimensionType, isFlexBasisType, isSizeType, isRenderable, BaseRenderable, Renderable, RootRenderable, capture, ConsolePosition, TerminalConsole, getObjectsInViewport, MouseEvent, MouseButton, createCliRenderer, CliRenderEvents, CliRenderer };
|
|
8835
9008
|
|
|
8836
|
-
//# debugId=
|
|
8837
|
-
//# sourceMappingURL=index-
|
|
9009
|
+
//# debugId=5DA797F1A7D4887764756E2164756E21
|
|
9010
|
+
//# sourceMappingURL=index-mh94hn7d.js.map
|