@opentui/core 0.1.5 → 0.1.6
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 +93 -33
- package/LICENSE +21 -0
- package/Renderable.d.ts +1 -0
- package/index.d.ts +1 -0
- package/index.js +481 -327
- package/lib/hast-styled-text.d.ts +38 -0
- package/lib/index.d.ts +1 -0
- package/lib/styled-text.d.ts +5 -3
- package/package.json +15 -8
package/index.js
CHANGED
|
@@ -2046,6 +2046,18 @@ function parseJustify(value) {
|
|
|
2046
2046
|
return Justify.FlexStart;
|
|
2047
2047
|
}
|
|
2048
2048
|
}
|
|
2049
|
+
function parsePositionType(value) {
|
|
2050
|
+
switch (value.toLowerCase()) {
|
|
2051
|
+
case "static":
|
|
2052
|
+
return PositionType.Static;
|
|
2053
|
+
case "relative":
|
|
2054
|
+
return PositionType.Relative;
|
|
2055
|
+
case "absolute":
|
|
2056
|
+
return PositionType.Absolute;
|
|
2057
|
+
default:
|
|
2058
|
+
return PositionType.Static;
|
|
2059
|
+
}
|
|
2060
|
+
}
|
|
2049
2061
|
|
|
2050
2062
|
// src/Renderable.ts
|
|
2051
2063
|
var LayoutEvents;
|
|
@@ -2368,8 +2380,8 @@ class Renderable extends EventEmitter3 {
|
|
|
2368
2380
|
this.layoutNode.setHeight(options.height);
|
|
2369
2381
|
}
|
|
2370
2382
|
this._positionType = options.position ?? "relative";
|
|
2371
|
-
if (this._positionType
|
|
2372
|
-
node.setPositionType(
|
|
2383
|
+
if (this._positionType !== "relative") {
|
|
2384
|
+
node.setPositionType(parsePositionType(this._positionType));
|
|
2373
2385
|
}
|
|
2374
2386
|
const hasPositionProps = options.top !== undefined || options.right !== undefined || options.bottom !== undefined || options.left !== undefined;
|
|
2375
2387
|
if (hasPositionProps) {
|
|
@@ -2428,6 +2440,14 @@ class Renderable extends EventEmitter3 {
|
|
|
2428
2440
|
node.setPadding(Edge.Left, options.paddingLeft);
|
|
2429
2441
|
}
|
|
2430
2442
|
}
|
|
2443
|
+
set position(positionType) {
|
|
2444
|
+
if (this._positionType === positionType)
|
|
2445
|
+
return;
|
|
2446
|
+
this._positionType = positionType;
|
|
2447
|
+
this.layoutNode.yogaNode.setPositionType(parsePositionType(positionType));
|
|
2448
|
+
this.needsUpdate();
|
|
2449
|
+
this._yogaPerformancePositionUpdated = true;
|
|
2450
|
+
}
|
|
2431
2451
|
setPosition(position) {
|
|
2432
2452
|
this._position = { ...this._position, ...position };
|
|
2433
2453
|
this.updateYogaPosition(position);
|
|
@@ -5472,6 +5492,306 @@ function renderFontToFrameBuffer(buffer, {
|
|
|
5472
5492
|
height: fontDef.lines
|
|
5473
5493
|
};
|
|
5474
5494
|
}
|
|
5495
|
+
// src/lib/styled-text.ts
|
|
5496
|
+
var textEncoder = new TextEncoder;
|
|
5497
|
+
|
|
5498
|
+
class StyledText {
|
|
5499
|
+
chunks;
|
|
5500
|
+
_plainText = "";
|
|
5501
|
+
constructor(chunks) {
|
|
5502
|
+
this.chunks = chunks;
|
|
5503
|
+
for (let i = 0;i < chunks.length; i++) {
|
|
5504
|
+
this._plainText += chunks[i].plainText;
|
|
5505
|
+
}
|
|
5506
|
+
}
|
|
5507
|
+
toString() {
|
|
5508
|
+
return this._plainText;
|
|
5509
|
+
}
|
|
5510
|
+
_chunksToPlainText() {
|
|
5511
|
+
this._plainText = "";
|
|
5512
|
+
for (const chunk of this.chunks) {
|
|
5513
|
+
this._plainText += chunk.plainText;
|
|
5514
|
+
}
|
|
5515
|
+
}
|
|
5516
|
+
insert(chunk, index) {
|
|
5517
|
+
const originalLength = this.chunks.length;
|
|
5518
|
+
if (index === undefined) {
|
|
5519
|
+
this.chunks.push(chunk);
|
|
5520
|
+
} else {
|
|
5521
|
+
this.chunks.splice(index, 0, chunk);
|
|
5522
|
+
}
|
|
5523
|
+
if (index === undefined || index === originalLength) {
|
|
5524
|
+
this._plainText += chunk.plainText;
|
|
5525
|
+
} else {
|
|
5526
|
+
this._chunksToPlainText();
|
|
5527
|
+
}
|
|
5528
|
+
}
|
|
5529
|
+
remove(chunk) {
|
|
5530
|
+
const originalLength = this.chunks.length;
|
|
5531
|
+
const index = this.chunks.indexOf(chunk);
|
|
5532
|
+
if (index === -1)
|
|
5533
|
+
return;
|
|
5534
|
+
this.chunks.splice(index, 1);
|
|
5535
|
+
if (index === originalLength - 1) {
|
|
5536
|
+
this._plainText = this._plainText.slice(0, this._plainText.length - chunk.plainText.length);
|
|
5537
|
+
} else {
|
|
5538
|
+
this._chunksToPlainText();
|
|
5539
|
+
}
|
|
5540
|
+
}
|
|
5541
|
+
replace(chunk, oldChunk) {
|
|
5542
|
+
const index = this.chunks.indexOf(oldChunk);
|
|
5543
|
+
if (index === -1)
|
|
5544
|
+
return;
|
|
5545
|
+
this.chunks.splice(index, 1, chunk);
|
|
5546
|
+
if (index === this.chunks.length - 1) {
|
|
5547
|
+
this._plainText = this._plainText.slice(0, this._plainText.length - oldChunk.plainText.length) + chunk.plainText;
|
|
5548
|
+
} else {
|
|
5549
|
+
this._chunksToPlainText();
|
|
5550
|
+
}
|
|
5551
|
+
}
|
|
5552
|
+
}
|
|
5553
|
+
function stringToStyledText(content) {
|
|
5554
|
+
const textEncoder2 = new TextEncoder;
|
|
5555
|
+
const chunk = {
|
|
5556
|
+
__isChunk: true,
|
|
5557
|
+
text: textEncoder2.encode(content),
|
|
5558
|
+
plainText: content
|
|
5559
|
+
};
|
|
5560
|
+
return new StyledText([chunk]);
|
|
5561
|
+
}
|
|
5562
|
+
var templateCache = new WeakMap;
|
|
5563
|
+
function applyStyle(input, style) {
|
|
5564
|
+
if (typeof input === "object" && "__isChunk" in input) {
|
|
5565
|
+
const existingChunk = input;
|
|
5566
|
+
const fg = style.fg ? parseColor(style.fg) : existingChunk.fg;
|
|
5567
|
+
const bg = style.bg ? parseColor(style.bg) : existingChunk.bg;
|
|
5568
|
+
const newAttrs = createTextAttributes(style);
|
|
5569
|
+
const mergedAttrs = existingChunk.attributes ? existingChunk.attributes | newAttrs : newAttrs;
|
|
5570
|
+
return {
|
|
5571
|
+
__isChunk: true,
|
|
5572
|
+
text: existingChunk.text,
|
|
5573
|
+
plainText: existingChunk.plainText,
|
|
5574
|
+
fg,
|
|
5575
|
+
bg,
|
|
5576
|
+
attributes: mergedAttrs
|
|
5577
|
+
};
|
|
5578
|
+
} else {
|
|
5579
|
+
const plainTextStr = String(input);
|
|
5580
|
+
const text = textEncoder.encode(plainTextStr);
|
|
5581
|
+
const fg = style.fg ? parseColor(style.fg) : undefined;
|
|
5582
|
+
const bg = style.bg ? parseColor(style.bg) : undefined;
|
|
5583
|
+
const attributes = createTextAttributes(style);
|
|
5584
|
+
return {
|
|
5585
|
+
__isChunk: true,
|
|
5586
|
+
text,
|
|
5587
|
+
plainText: plainTextStr,
|
|
5588
|
+
fg,
|
|
5589
|
+
bg,
|
|
5590
|
+
attributes
|
|
5591
|
+
};
|
|
5592
|
+
}
|
|
5593
|
+
}
|
|
5594
|
+
var black = (input) => applyStyle(input, { fg: "black" });
|
|
5595
|
+
var red = (input) => applyStyle(input, { fg: "red" });
|
|
5596
|
+
var green = (input) => applyStyle(input, { fg: "green" });
|
|
5597
|
+
var yellow = (input) => applyStyle(input, { fg: "yellow" });
|
|
5598
|
+
var blue = (input) => applyStyle(input, { fg: "blue" });
|
|
5599
|
+
var magenta = (input) => applyStyle(input, { fg: "magenta" });
|
|
5600
|
+
var cyan = (input) => applyStyle(input, { fg: "cyan" });
|
|
5601
|
+
var white = (input) => applyStyle(input, { fg: "white" });
|
|
5602
|
+
var brightBlack = (input) => applyStyle(input, { fg: "brightBlack" });
|
|
5603
|
+
var brightRed = (input) => applyStyle(input, { fg: "brightRed" });
|
|
5604
|
+
var brightGreen = (input) => applyStyle(input, { fg: "brightGreen" });
|
|
5605
|
+
var brightYellow = (input) => applyStyle(input, { fg: "brightYellow" });
|
|
5606
|
+
var brightBlue = (input) => applyStyle(input, { fg: "brightBlue" });
|
|
5607
|
+
var brightMagenta = (input) => applyStyle(input, { fg: "brightMagenta" });
|
|
5608
|
+
var brightCyan = (input) => applyStyle(input, { fg: "brightCyan" });
|
|
5609
|
+
var brightWhite = (input) => applyStyle(input, { fg: "brightWhite" });
|
|
5610
|
+
var bgBlack = (input) => applyStyle(input, { bg: "black" });
|
|
5611
|
+
var bgRed = (input) => applyStyle(input, { bg: "red" });
|
|
5612
|
+
var bgGreen = (input) => applyStyle(input, { bg: "green" });
|
|
5613
|
+
var bgYellow = (input) => applyStyle(input, { bg: "yellow" });
|
|
5614
|
+
var bgBlue = (input) => applyStyle(input, { bg: "blue" });
|
|
5615
|
+
var bgMagenta = (input) => applyStyle(input, { bg: "magenta" });
|
|
5616
|
+
var bgCyan = (input) => applyStyle(input, { bg: "cyan" });
|
|
5617
|
+
var bgWhite = (input) => applyStyle(input, { bg: "white" });
|
|
5618
|
+
var bold = (input) => applyStyle(input, { bold: true });
|
|
5619
|
+
var italic = (input) => applyStyle(input, { italic: true });
|
|
5620
|
+
var underline = (input) => applyStyle(input, { underline: true });
|
|
5621
|
+
var strikethrough = (input) => applyStyle(input, { strikethrough: true });
|
|
5622
|
+
var dim = (input) => applyStyle(input, { dim: true });
|
|
5623
|
+
var reverse = (input) => applyStyle(input, { reverse: true });
|
|
5624
|
+
var blink = (input) => applyStyle(input, { blink: true });
|
|
5625
|
+
var fg = (color) => (input) => applyStyle(input, { fg: color });
|
|
5626
|
+
var bg = (color) => (input) => applyStyle(input, { bg: color });
|
|
5627
|
+
function tn(strings, ...values) {
|
|
5628
|
+
const chunks = [];
|
|
5629
|
+
let length = 0;
|
|
5630
|
+
let plainText = "";
|
|
5631
|
+
for (let i = 0;i < strings.length; i++) {
|
|
5632
|
+
const raw = strings[i];
|
|
5633
|
+
if (raw) {
|
|
5634
|
+
chunks.push({
|
|
5635
|
+
__isChunk: true,
|
|
5636
|
+
text: textEncoder.encode(raw),
|
|
5637
|
+
plainText: raw,
|
|
5638
|
+
attributes: 0
|
|
5639
|
+
});
|
|
5640
|
+
length += raw.length;
|
|
5641
|
+
plainText += raw;
|
|
5642
|
+
}
|
|
5643
|
+
const val = values[i];
|
|
5644
|
+
if (typeof val === "object" && "__isChunk" in val) {
|
|
5645
|
+
chunks.push(val);
|
|
5646
|
+
length += val.plainText.length;
|
|
5647
|
+
plainText += val.plainText;
|
|
5648
|
+
} else if (val !== undefined) {
|
|
5649
|
+
const plainTextStr = String(val);
|
|
5650
|
+
chunks.push({
|
|
5651
|
+
__isChunk: true,
|
|
5652
|
+
text: textEncoder.encode(plainTextStr),
|
|
5653
|
+
plainText: plainTextStr,
|
|
5654
|
+
attributes: 0
|
|
5655
|
+
});
|
|
5656
|
+
length += plainTextStr.length;
|
|
5657
|
+
plainText += plainTextStr;
|
|
5658
|
+
}
|
|
5659
|
+
}
|
|
5660
|
+
return new StyledText(chunks);
|
|
5661
|
+
}
|
|
5662
|
+
function t(strings, ...values) {
|
|
5663
|
+
let cachedStringChunks = templateCache.get(strings);
|
|
5664
|
+
let length = 0;
|
|
5665
|
+
let plainText = "";
|
|
5666
|
+
if (!cachedStringChunks) {
|
|
5667
|
+
cachedStringChunks = [];
|
|
5668
|
+
for (let i = 0;i < strings.length; i++) {
|
|
5669
|
+
const raw = strings[i];
|
|
5670
|
+
if (raw) {
|
|
5671
|
+
cachedStringChunks.push({
|
|
5672
|
+
__isChunk: true,
|
|
5673
|
+
text: textEncoder.encode(raw),
|
|
5674
|
+
plainText: raw,
|
|
5675
|
+
attributes: 0
|
|
5676
|
+
});
|
|
5677
|
+
} else {
|
|
5678
|
+
cachedStringChunks.push(null);
|
|
5679
|
+
}
|
|
5680
|
+
}
|
|
5681
|
+
templateCache.set(strings, cachedStringChunks);
|
|
5682
|
+
}
|
|
5683
|
+
const chunks = [];
|
|
5684
|
+
for (let i = 0;i < strings.length; i++) {
|
|
5685
|
+
const stringChunk = cachedStringChunks[i];
|
|
5686
|
+
if (stringChunk) {
|
|
5687
|
+
chunks.push(stringChunk);
|
|
5688
|
+
length += stringChunk.plainText.length;
|
|
5689
|
+
plainText += stringChunk.plainText;
|
|
5690
|
+
}
|
|
5691
|
+
const val = values[i];
|
|
5692
|
+
if (typeof val === "object" && "__isChunk" in val) {
|
|
5693
|
+
chunks.push(val);
|
|
5694
|
+
length += val.plainText.length;
|
|
5695
|
+
plainText += val.plainText;
|
|
5696
|
+
} else if (val !== undefined) {
|
|
5697
|
+
const plainTextStr = String(val);
|
|
5698
|
+
chunks.push({
|
|
5699
|
+
__isChunk: true,
|
|
5700
|
+
text: textEncoder.encode(plainTextStr),
|
|
5701
|
+
plainText: plainTextStr,
|
|
5702
|
+
attributes: 0
|
|
5703
|
+
});
|
|
5704
|
+
length += plainTextStr.length;
|
|
5705
|
+
plainText += plainTextStr;
|
|
5706
|
+
}
|
|
5707
|
+
}
|
|
5708
|
+
return new StyledText(chunks);
|
|
5709
|
+
}
|
|
5710
|
+
|
|
5711
|
+
// src/lib/hast-styled-text.ts
|
|
5712
|
+
class SyntaxStyle {
|
|
5713
|
+
styles;
|
|
5714
|
+
mergedStyleCache;
|
|
5715
|
+
constructor(styles) {
|
|
5716
|
+
this.styles = styles;
|
|
5717
|
+
this.mergedStyleCache = new Map;
|
|
5718
|
+
}
|
|
5719
|
+
mergeStyles(...styleNames) {
|
|
5720
|
+
const cacheKey = styleNames.join(":");
|
|
5721
|
+
const cached = this.mergedStyleCache.get(cacheKey);
|
|
5722
|
+
if (cached)
|
|
5723
|
+
return cached;
|
|
5724
|
+
const styleDefinition = {};
|
|
5725
|
+
for (const name of styleNames) {
|
|
5726
|
+
const style = this.styles[name];
|
|
5727
|
+
if (!style)
|
|
5728
|
+
continue;
|
|
5729
|
+
if (style.fg)
|
|
5730
|
+
styleDefinition.fg = style.fg;
|
|
5731
|
+
if (style.bg)
|
|
5732
|
+
styleDefinition.bg = style.bg;
|
|
5733
|
+
if (style.bold !== undefined)
|
|
5734
|
+
styleDefinition.bold = style.bold;
|
|
5735
|
+
if (style.italic !== undefined)
|
|
5736
|
+
styleDefinition.italic = style.italic;
|
|
5737
|
+
if (style.underline !== undefined)
|
|
5738
|
+
styleDefinition.underline = style.underline;
|
|
5739
|
+
if (style.dim !== undefined)
|
|
5740
|
+
styleDefinition.dim = style.dim;
|
|
5741
|
+
}
|
|
5742
|
+
const attributes = createTextAttributes({
|
|
5743
|
+
bold: styleDefinition.bold,
|
|
5744
|
+
italic: styleDefinition.italic,
|
|
5745
|
+
underline: styleDefinition.underline,
|
|
5746
|
+
dim: styleDefinition.dim
|
|
5747
|
+
});
|
|
5748
|
+
const merged = {
|
|
5749
|
+
fg: styleDefinition.fg,
|
|
5750
|
+
bg: styleDefinition.bg,
|
|
5751
|
+
attributes
|
|
5752
|
+
};
|
|
5753
|
+
this.mergedStyleCache.set(cacheKey, merged);
|
|
5754
|
+
return merged;
|
|
5755
|
+
}
|
|
5756
|
+
clearCache() {
|
|
5757
|
+
this.mergedStyleCache.clear();
|
|
5758
|
+
}
|
|
5759
|
+
getCacheSize() {
|
|
5760
|
+
return this.mergedStyleCache.size;
|
|
5761
|
+
}
|
|
5762
|
+
}
|
|
5763
|
+
var textEncoder2 = new TextEncoder;
|
|
5764
|
+
function hastToTextChunks(node, syntaxStyle, parentStyles = []) {
|
|
5765
|
+
const chunks = [];
|
|
5766
|
+
if (node.type === "text") {
|
|
5767
|
+
const stylesToMerge = parentStyles.length > 0 ? parentStyles : ["default"];
|
|
5768
|
+
const mergedStyle = syntaxStyle.mergeStyles(...stylesToMerge);
|
|
5769
|
+
chunks.push({
|
|
5770
|
+
__isChunk: true,
|
|
5771
|
+
text: textEncoder2.encode(node.value),
|
|
5772
|
+
plainText: node.value,
|
|
5773
|
+
fg: mergedStyle.fg,
|
|
5774
|
+
bg: mergedStyle.bg,
|
|
5775
|
+
attributes: mergedStyle.attributes
|
|
5776
|
+
});
|
|
5777
|
+
} else if (node.type === "element") {
|
|
5778
|
+
let currentStyles = [...parentStyles];
|
|
5779
|
+
if (node.properties?.className) {
|
|
5780
|
+
const classes = node.properties.className.split(" ");
|
|
5781
|
+
for (const cls of classes) {
|
|
5782
|
+
currentStyles.push(cls);
|
|
5783
|
+
}
|
|
5784
|
+
}
|
|
5785
|
+
for (const child of node.children) {
|
|
5786
|
+
chunks.push(...hastToTextChunks(child, syntaxStyle, currentStyles));
|
|
5787
|
+
}
|
|
5788
|
+
}
|
|
5789
|
+
return chunks;
|
|
5790
|
+
}
|
|
5791
|
+
function hastToStyledText(hast, syntaxStyle) {
|
|
5792
|
+
const chunks = hastToTextChunks(hast, syntaxStyle);
|
|
5793
|
+
return new StyledText(chunks);
|
|
5794
|
+
}
|
|
5475
5795
|
// src/buffer.ts
|
|
5476
5796
|
var fbIdCounter = 0;
|
|
5477
5797
|
function isRGBAWithAlpha(color) {
|
|
@@ -5566,14 +5886,14 @@ class OptimizedBuffer {
|
|
|
5566
5886
|
this.lib.bufferSetRespectAlpha(this.bufferPtr, respectAlpha);
|
|
5567
5887
|
this.respectAlpha = respectAlpha;
|
|
5568
5888
|
}
|
|
5569
|
-
clear(
|
|
5889
|
+
clear(bg2 = RGBA.fromValues(0, 0, 0, 1), clearChar = " ") {
|
|
5570
5890
|
if (this.useFFI) {
|
|
5571
|
-
this.clearFFI(
|
|
5891
|
+
this.clearFFI(bg2);
|
|
5572
5892
|
} else {
|
|
5573
|
-
this.clearLocal(
|
|
5893
|
+
this.clearLocal(bg2, clearChar);
|
|
5574
5894
|
}
|
|
5575
5895
|
}
|
|
5576
|
-
clearLocal(
|
|
5896
|
+
clearLocal(bg2 = RGBA.fromValues(0, 0, 0, 1), clearChar = " ") {
|
|
5577
5897
|
this.buffer.char.fill(clearChar.charCodeAt(0));
|
|
5578
5898
|
this.buffer.attributes.fill(0);
|
|
5579
5899
|
for (let i = 0;i < this.width * this.height; i++) {
|
|
@@ -5582,27 +5902,27 @@ class OptimizedBuffer {
|
|
|
5582
5902
|
this.buffer.fg[index + 1] = 1;
|
|
5583
5903
|
this.buffer.fg[index + 2] = 1;
|
|
5584
5904
|
this.buffer.fg[index + 3] = 1;
|
|
5585
|
-
this.buffer.bg[index] =
|
|
5586
|
-
this.buffer.bg[index + 1] =
|
|
5587
|
-
this.buffer.bg[index + 2] =
|
|
5588
|
-
this.buffer.bg[index + 3] =
|
|
5905
|
+
this.buffer.bg[index] = bg2.r;
|
|
5906
|
+
this.buffer.bg[index + 1] = bg2.g;
|
|
5907
|
+
this.buffer.bg[index + 2] = bg2.b;
|
|
5908
|
+
this.buffer.bg[index + 3] = bg2.a;
|
|
5589
5909
|
}
|
|
5590
5910
|
}
|
|
5591
|
-
setCell(x, y, char,
|
|
5911
|
+
setCell(x, y, char, fg2, bg2, attributes = 0) {
|
|
5592
5912
|
if (x < 0 || x >= this.width || y < 0 || y >= this.height)
|
|
5593
5913
|
return;
|
|
5594
5914
|
const index = this.coordsToIndex(x, y);
|
|
5595
5915
|
const colorIndex = index * 4;
|
|
5596
5916
|
this.buffer.char[index] = char.charCodeAt(0);
|
|
5597
5917
|
this.buffer.attributes[index] = attributes;
|
|
5598
|
-
this.buffer.fg[colorIndex] =
|
|
5599
|
-
this.buffer.fg[colorIndex + 1] =
|
|
5600
|
-
this.buffer.fg[colorIndex + 2] =
|
|
5601
|
-
this.buffer.fg[colorIndex + 3] =
|
|
5602
|
-
this.buffer.bg[colorIndex] =
|
|
5603
|
-
this.buffer.bg[colorIndex + 1] =
|
|
5604
|
-
this.buffer.bg[colorIndex + 2] =
|
|
5605
|
-
this.buffer.bg[colorIndex + 3] =
|
|
5918
|
+
this.buffer.fg[colorIndex] = fg2.r;
|
|
5919
|
+
this.buffer.fg[colorIndex + 1] = fg2.g;
|
|
5920
|
+
this.buffer.fg[colorIndex + 2] = fg2.b;
|
|
5921
|
+
this.buffer.fg[colorIndex + 3] = fg2.a;
|
|
5922
|
+
this.buffer.bg[colorIndex] = bg2.r;
|
|
5923
|
+
this.buffer.bg[colorIndex + 1] = bg2.g;
|
|
5924
|
+
this.buffer.bg[colorIndex + 2] = bg2.b;
|
|
5925
|
+
this.buffer.bg[colorIndex + 3] = bg2.a;
|
|
5606
5926
|
}
|
|
5607
5927
|
get(x, y) {
|
|
5608
5928
|
if (x < 0 || x >= this.width || y < 0 || y >= this.height)
|
|
@@ -5616,41 +5936,41 @@ class OptimizedBuffer {
|
|
|
5616
5936
|
attributes: this.buffer.attributes[index]
|
|
5617
5937
|
};
|
|
5618
5938
|
}
|
|
5619
|
-
setCellWithAlphaBlending(x, y, char,
|
|
5939
|
+
setCellWithAlphaBlending(x, y, char, fg2, bg2, attributes = 0) {
|
|
5620
5940
|
if (this.useFFI) {
|
|
5621
|
-
this.setCellWithAlphaBlendingFFI(x, y, char,
|
|
5941
|
+
this.setCellWithAlphaBlendingFFI(x, y, char, fg2, bg2, attributes);
|
|
5622
5942
|
} else {
|
|
5623
|
-
this.setCellWithAlphaBlendingLocal(x, y, char,
|
|
5943
|
+
this.setCellWithAlphaBlendingLocal(x, y, char, fg2, bg2, attributes);
|
|
5624
5944
|
}
|
|
5625
5945
|
}
|
|
5626
|
-
setCellWithAlphaBlendingLocal(x, y, char,
|
|
5946
|
+
setCellWithAlphaBlendingLocal(x, y, char, fg2, bg2, attributes = 0) {
|
|
5627
5947
|
if (x < 0 || x >= this.width || y < 0 || y >= this.height)
|
|
5628
5948
|
return;
|
|
5629
|
-
const hasBgAlpha = isRGBAWithAlpha(
|
|
5630
|
-
const hasFgAlpha = isRGBAWithAlpha(
|
|
5949
|
+
const hasBgAlpha = isRGBAWithAlpha(bg2);
|
|
5950
|
+
const hasFgAlpha = isRGBAWithAlpha(fg2);
|
|
5631
5951
|
if (hasBgAlpha || hasFgAlpha) {
|
|
5632
5952
|
const destCell = this.get(x, y);
|
|
5633
5953
|
if (destCell) {
|
|
5634
|
-
const blendedBgRgb = hasBgAlpha ? blendColors(
|
|
5954
|
+
const blendedBgRgb = hasBgAlpha ? blendColors(bg2, destCell.bg) : bg2;
|
|
5635
5955
|
const preserveChar = char === " " && destCell.char !== 0 && String.fromCharCode(destCell.char) !== " ";
|
|
5636
5956
|
const finalChar = preserveChar ? destCell.char : char.charCodeAt(0);
|
|
5637
5957
|
let finalFg;
|
|
5638
5958
|
if (preserveChar) {
|
|
5639
|
-
finalFg = blendColors(
|
|
5959
|
+
finalFg = blendColors(bg2, destCell.fg);
|
|
5640
5960
|
} else {
|
|
5641
|
-
finalFg = hasFgAlpha ? blendColors(
|
|
5961
|
+
finalFg = hasFgAlpha ? blendColors(fg2, destCell.bg) : fg2;
|
|
5642
5962
|
}
|
|
5643
5963
|
const finalAttributes = preserveChar ? destCell.attributes : attributes;
|
|
5644
|
-
const finalBg = RGBA.fromValues(blendedBgRgb.r, blendedBgRgb.g, blendedBgRgb.b,
|
|
5964
|
+
const finalBg = RGBA.fromValues(blendedBgRgb.r, blendedBgRgb.g, blendedBgRgb.b, bg2.a);
|
|
5645
5965
|
this.setCell(x, y, String.fromCharCode(finalChar), finalFg, finalBg, finalAttributes);
|
|
5646
5966
|
return;
|
|
5647
5967
|
}
|
|
5648
5968
|
}
|
|
5649
|
-
this.setCell(x, y, char,
|
|
5969
|
+
this.setCell(x, y, char, fg2, bg2, attributes);
|
|
5650
5970
|
}
|
|
5651
|
-
drawText(text, x, y,
|
|
5971
|
+
drawText(text, x, y, fg2, bg2, attributes = 0, selection) {
|
|
5652
5972
|
if (!selection) {
|
|
5653
|
-
this.drawTextFFI.call(this, text, x, y,
|
|
5973
|
+
this.drawTextFFI.call(this, text, x, y, fg2, bg2, attributes);
|
|
5654
5974
|
return;
|
|
5655
5975
|
}
|
|
5656
5976
|
const { start, end } = selection;
|
|
@@ -5658,15 +5978,15 @@ class OptimizedBuffer {
|
|
|
5658
5978
|
let selectionFg;
|
|
5659
5979
|
if (selection.bgColor) {
|
|
5660
5980
|
selectionBg = selection.bgColor;
|
|
5661
|
-
selectionFg = selection.fgColor ||
|
|
5981
|
+
selectionFg = selection.fgColor || fg2;
|
|
5662
5982
|
} else {
|
|
5663
|
-
const defaultBg =
|
|
5983
|
+
const defaultBg = bg2 || RGBA.fromValues(0, 0, 0, 0);
|
|
5664
5984
|
selectionFg = defaultBg.a > 0 ? defaultBg : RGBA.fromValues(0, 0, 0, 1);
|
|
5665
|
-
selectionBg =
|
|
5985
|
+
selectionBg = fg2;
|
|
5666
5986
|
}
|
|
5667
5987
|
if (start > 0) {
|
|
5668
5988
|
const beforeText = text.slice(0, start);
|
|
5669
|
-
this.drawTextFFI.call(this, beforeText, x, y,
|
|
5989
|
+
this.drawTextFFI.call(this, beforeText, x, y, fg2, bg2, attributes);
|
|
5670
5990
|
}
|
|
5671
5991
|
if (end > start) {
|
|
5672
5992
|
const selectedText = text.slice(start, end);
|
|
@@ -5674,29 +5994,29 @@ class OptimizedBuffer {
|
|
|
5674
5994
|
}
|
|
5675
5995
|
if (end < text.length) {
|
|
5676
5996
|
const afterText = text.slice(end);
|
|
5677
|
-
this.drawTextFFI.call(this, afterText, x + end, y,
|
|
5997
|
+
this.drawTextFFI.call(this, afterText, x + end, y, fg2, bg2, attributes);
|
|
5678
5998
|
}
|
|
5679
5999
|
}
|
|
5680
|
-
fillRect(x, y, width, height,
|
|
6000
|
+
fillRect(x, y, width, height, bg2) {
|
|
5681
6001
|
if (this.useFFI) {
|
|
5682
|
-
this.fillRectFFI(x, y, width, height,
|
|
6002
|
+
this.fillRectFFI(x, y, width, height, bg2);
|
|
5683
6003
|
} else {
|
|
5684
|
-
this.fillRectLocal(x, y, width, height,
|
|
6004
|
+
this.fillRectLocal(x, y, width, height, bg2);
|
|
5685
6005
|
}
|
|
5686
6006
|
}
|
|
5687
|
-
fillRectLocal(x, y, width, height,
|
|
6007
|
+
fillRectLocal(x, y, width, height, bg2) {
|
|
5688
6008
|
const startX = Math.max(0, x);
|
|
5689
6009
|
const startY = Math.max(0, y);
|
|
5690
6010
|
const endX = Math.min(this.getWidth() - 1, x + width - 1);
|
|
5691
6011
|
const endY = Math.min(this.getHeight() - 1, y + height - 1);
|
|
5692
6012
|
if (startX > endX || startY > endY)
|
|
5693
6013
|
return;
|
|
5694
|
-
const hasAlpha = isRGBAWithAlpha(
|
|
6014
|
+
const hasAlpha = isRGBAWithAlpha(bg2);
|
|
5695
6015
|
if (hasAlpha) {
|
|
5696
|
-
const
|
|
6016
|
+
const fg2 = RGBA.fromValues(1, 1, 1, 1);
|
|
5697
6017
|
for (let fillY = startY;fillY <= endY; fillY++) {
|
|
5698
6018
|
for (let fillX = startX;fillX <= endX; fillX++) {
|
|
5699
|
-
this.setCellWithAlphaBlending(fillX, fillY, " ",
|
|
6019
|
+
this.setCellWithAlphaBlending(fillX, fillY, " ", fg2, bg2, 0);
|
|
5700
6020
|
}
|
|
5701
6021
|
}
|
|
5702
6022
|
} else {
|
|
@@ -5710,10 +6030,10 @@ class OptimizedBuffer {
|
|
|
5710
6030
|
this.buffer.fg[colorIndex + 1] = 1;
|
|
5711
6031
|
this.buffer.fg[colorIndex + 2] = 1;
|
|
5712
6032
|
this.buffer.fg[colorIndex + 3] = 1;
|
|
5713
|
-
this.buffer.bg[colorIndex] =
|
|
5714
|
-
this.buffer.bg[colorIndex + 1] =
|
|
5715
|
-
this.buffer.bg[colorIndex + 2] =
|
|
5716
|
-
this.buffer.bg[colorIndex + 3] =
|
|
6033
|
+
this.buffer.bg[colorIndex] = bg2.r;
|
|
6034
|
+
this.buffer.bg[colorIndex + 1] = bg2.g;
|
|
6035
|
+
this.buffer.bg[colorIndex + 2] = bg2.b;
|
|
6036
|
+
this.buffer.bg[colorIndex + 3] = bg2.a;
|
|
5717
6037
|
}
|
|
5718
6038
|
}
|
|
5719
6039
|
}
|
|
@@ -5777,10 +6097,10 @@ class OptimizedBuffer {
|
|
|
5777
6097
|
continue;
|
|
5778
6098
|
}
|
|
5779
6099
|
const charCode = frameBuffer.buffer.char[srcIndex];
|
|
5780
|
-
const
|
|
5781
|
-
const
|
|
6100
|
+
const fg2 = RGBA.fromArray(frameBuffer.buffer.fg.slice(srcColorIndex, srcColorIndex + 4));
|
|
6101
|
+
const bg2 = RGBA.fromArray(frameBuffer.buffer.bg.slice(srcColorIndex, srcColorIndex + 4));
|
|
5782
6102
|
const attributes = frameBuffer.buffer.attributes[srcIndex];
|
|
5783
|
-
this.setCellWithAlphaBlending(dX, dY, String.fromCharCode(charCode),
|
|
6103
|
+
this.setCellWithAlphaBlending(dX, dY, String.fromCharCode(charCode), fg2, bg2, attributes);
|
|
5784
6104
|
}
|
|
5785
6105
|
}
|
|
5786
6106
|
}
|
|
@@ -5799,11 +6119,11 @@ class OptimizedBuffer {
|
|
|
5799
6119
|
drawPackedBuffer(dataPtr, dataLen, posX, posY, terminalWidthCells, terminalHeightCells) {
|
|
5800
6120
|
this.lib.bufferDrawPackedBuffer(this.bufferPtr, dataPtr, dataLen, posX, posY, terminalWidthCells, terminalHeightCells);
|
|
5801
6121
|
}
|
|
5802
|
-
setCellWithAlphaBlendingFFI(x, y, char,
|
|
5803
|
-
this.lib.bufferSetCellWithAlphaBlending(this.bufferPtr, x, y, char,
|
|
6122
|
+
setCellWithAlphaBlendingFFI(x, y, char, fg2, bg2, attributes) {
|
|
6123
|
+
this.lib.bufferSetCellWithAlphaBlending(this.bufferPtr, x, y, char, fg2, bg2, attributes);
|
|
5804
6124
|
}
|
|
5805
|
-
fillRectFFI(x, y, width, height,
|
|
5806
|
-
this.lib.bufferFillRect(this.bufferPtr, x, y, width, height,
|
|
6125
|
+
fillRectFFI(x, y, width, height, bg2) {
|
|
6126
|
+
this.lib.bufferFillRect(this.bufferPtr, x, y, width, height, bg2);
|
|
5807
6127
|
}
|
|
5808
6128
|
resize(width, height) {
|
|
5809
6129
|
if (this.width === width && this.height === height)
|
|
@@ -5812,11 +6132,11 @@ class OptimizedBuffer {
|
|
|
5812
6132
|
this.height = height;
|
|
5813
6133
|
this.buffer = this.lib.bufferResize(this.bufferPtr, width, height);
|
|
5814
6134
|
}
|
|
5815
|
-
clearFFI(
|
|
5816
|
-
this.lib.bufferClear(this.bufferPtr,
|
|
6135
|
+
clearFFI(bg2 = RGBA.fromValues(0, 0, 0, 1)) {
|
|
6136
|
+
this.lib.bufferClear(this.bufferPtr, bg2);
|
|
5817
6137
|
}
|
|
5818
|
-
drawTextFFI(text, x, y,
|
|
5819
|
-
this.lib.bufferDrawText(this.bufferPtr, text, x, y,
|
|
6138
|
+
drawTextFFI(text, x, y, fg2 = RGBA.fromValues(1, 1, 1, 1), bg2, attributes = 0) {
|
|
6139
|
+
this.lib.bufferDrawText(this.bufferPtr, text, x, y, fg2, bg2, attributes);
|
|
5820
6140
|
}
|
|
5821
6141
|
drawFrameBufferFFI(destX, destY, frameBuffer, sourceX, sourceY, sourceWidth, sourceHeight) {
|
|
5822
6142
|
this.lib.drawFrameBuffer(this.bufferPtr, destX, destY, frameBuffer.ptr, sourceX, sourceY, sourceWidth, sourceHeight);
|
|
@@ -5832,91 +6152,91 @@ class OptimizedBuffer {
|
|
|
5832
6152
|
function applyScanlines(buffer, strength = 0.8, step = 2) {
|
|
5833
6153
|
const width = buffer.getWidth();
|
|
5834
6154
|
const height = buffer.getHeight();
|
|
5835
|
-
const
|
|
6155
|
+
const bg2 = buffer.buffers.bg;
|
|
5836
6156
|
for (let y = 0;y < height; y += step) {
|
|
5837
6157
|
for (let x = 0;x < width; x++) {
|
|
5838
6158
|
const colorIndex = (y * width + x) * 4;
|
|
5839
|
-
|
|
5840
|
-
|
|
5841
|
-
|
|
6159
|
+
bg2[colorIndex] *= strength;
|
|
6160
|
+
bg2[colorIndex + 1] *= strength;
|
|
6161
|
+
bg2[colorIndex + 2] *= strength;
|
|
5842
6162
|
}
|
|
5843
6163
|
}
|
|
5844
6164
|
}
|
|
5845
6165
|
function applyGrayscale(buffer) {
|
|
5846
6166
|
const size = buffer.getWidth() * buffer.getHeight();
|
|
5847
|
-
const
|
|
5848
|
-
const
|
|
6167
|
+
const fg2 = buffer.buffers.fg;
|
|
6168
|
+
const bg2 = buffer.buffers.bg;
|
|
5849
6169
|
for (let i = 0;i < size; i++) {
|
|
5850
6170
|
const colorIndex = i * 4;
|
|
5851
|
-
const fgR =
|
|
5852
|
-
const fgG =
|
|
5853
|
-
const fgB =
|
|
6171
|
+
const fgR = fg2[colorIndex];
|
|
6172
|
+
const fgG = fg2[colorIndex + 1];
|
|
6173
|
+
const fgB = fg2[colorIndex + 2];
|
|
5854
6174
|
const fgLum = 0.299 * fgR + 0.587 * fgG + 0.114 * fgB;
|
|
5855
|
-
|
|
5856
|
-
|
|
5857
|
-
|
|
5858
|
-
const bgR =
|
|
5859
|
-
const bgG =
|
|
5860
|
-
const bgB =
|
|
6175
|
+
fg2[colorIndex] = fgLum;
|
|
6176
|
+
fg2[colorIndex + 1] = fgLum;
|
|
6177
|
+
fg2[colorIndex + 2] = fgLum;
|
|
6178
|
+
const bgR = bg2[colorIndex];
|
|
6179
|
+
const bgG = bg2[colorIndex + 1];
|
|
6180
|
+
const bgB = bg2[colorIndex + 2];
|
|
5861
6181
|
const bgLum = 0.299 * bgR + 0.587 * bgG + 0.114 * bgB;
|
|
5862
|
-
|
|
5863
|
-
|
|
5864
|
-
|
|
6182
|
+
bg2[colorIndex] = bgLum;
|
|
6183
|
+
bg2[colorIndex + 1] = bgLum;
|
|
6184
|
+
bg2[colorIndex + 2] = bgLum;
|
|
5865
6185
|
}
|
|
5866
6186
|
}
|
|
5867
6187
|
function applySepia(buffer) {
|
|
5868
6188
|
const size = buffer.getWidth() * buffer.getHeight();
|
|
5869
|
-
const
|
|
5870
|
-
const
|
|
6189
|
+
const fg2 = buffer.buffers.fg;
|
|
6190
|
+
const bg2 = buffer.buffers.bg;
|
|
5871
6191
|
for (let i = 0;i < size; i++) {
|
|
5872
6192
|
const colorIndex = i * 4;
|
|
5873
|
-
let fgR =
|
|
5874
|
-
let fgG =
|
|
5875
|
-
let fgB =
|
|
6193
|
+
let fgR = fg2[colorIndex];
|
|
6194
|
+
let fgG = fg2[colorIndex + 1];
|
|
6195
|
+
let fgB = fg2[colorIndex + 2];
|
|
5876
6196
|
let newFgR = Math.min(1, fgR * 0.393 + fgG * 0.769 + fgB * 0.189);
|
|
5877
6197
|
let newFgG = Math.min(1, fgR * 0.349 + fgG * 0.686 + fgB * 0.168);
|
|
5878
6198
|
let newFgB = Math.min(1, fgR * 0.272 + fgG * 0.534 + fgB * 0.131);
|
|
5879
|
-
|
|
5880
|
-
|
|
5881
|
-
|
|
5882
|
-
let bgR =
|
|
5883
|
-
let bgG =
|
|
5884
|
-
let bgB =
|
|
6199
|
+
fg2[colorIndex] = newFgR;
|
|
6200
|
+
fg2[colorIndex + 1] = newFgG;
|
|
6201
|
+
fg2[colorIndex + 2] = newFgB;
|
|
6202
|
+
let bgR = bg2[colorIndex];
|
|
6203
|
+
let bgG = bg2[colorIndex + 1];
|
|
6204
|
+
let bgB = bg2[colorIndex + 2];
|
|
5885
6205
|
let newBgR = Math.min(1, bgR * 0.393 + bgG * 0.769 + bgB * 0.189);
|
|
5886
6206
|
let newBgG = Math.min(1, bgR * 0.349 + bgG * 0.686 + bgB * 0.168);
|
|
5887
6207
|
let newBgB = Math.min(1, bgR * 0.272 + bgG * 0.534 + bgB * 0.131);
|
|
5888
|
-
|
|
5889
|
-
|
|
5890
|
-
|
|
6208
|
+
bg2[colorIndex] = newBgR;
|
|
6209
|
+
bg2[colorIndex + 1] = newBgG;
|
|
6210
|
+
bg2[colorIndex + 2] = newBgB;
|
|
5891
6211
|
}
|
|
5892
6212
|
}
|
|
5893
6213
|
function applyInvert(buffer) {
|
|
5894
6214
|
const size = buffer.getWidth() * buffer.getHeight();
|
|
5895
|
-
const
|
|
5896
|
-
const
|
|
6215
|
+
const fg2 = buffer.buffers.fg;
|
|
6216
|
+
const bg2 = buffer.buffers.bg;
|
|
5897
6217
|
for (let i = 0;i < size; i++) {
|
|
5898
6218
|
const colorIndex = i * 4;
|
|
5899
|
-
|
|
5900
|
-
|
|
5901
|
-
|
|
5902
|
-
|
|
5903
|
-
|
|
5904
|
-
|
|
6219
|
+
fg2[colorIndex] = 1 - fg2[colorIndex];
|
|
6220
|
+
fg2[colorIndex + 1] = 1 - fg2[colorIndex + 1];
|
|
6221
|
+
fg2[colorIndex + 2] = 1 - fg2[colorIndex + 2];
|
|
6222
|
+
bg2[colorIndex] = 1 - bg2[colorIndex];
|
|
6223
|
+
bg2[colorIndex + 1] = 1 - bg2[colorIndex + 1];
|
|
6224
|
+
bg2[colorIndex + 2] = 1 - bg2[colorIndex + 2];
|
|
5905
6225
|
}
|
|
5906
6226
|
}
|
|
5907
6227
|
function applyNoise(buffer, strength = 0.1) {
|
|
5908
6228
|
const size = buffer.getWidth() * buffer.getHeight();
|
|
5909
|
-
const
|
|
5910
|
-
const
|
|
6229
|
+
const fg2 = buffer.buffers.fg;
|
|
6230
|
+
const bg2 = buffer.buffers.bg;
|
|
5911
6231
|
for (let i = 0;i < size; i++) {
|
|
5912
6232
|
const colorIndex = i * 4;
|
|
5913
6233
|
const noise = (Math.random() - 0.5) * strength;
|
|
5914
|
-
|
|
5915
|
-
|
|
5916
|
-
|
|
5917
|
-
|
|
5918
|
-
|
|
5919
|
-
|
|
6234
|
+
fg2[colorIndex] = Math.max(0, Math.min(1, fg2[colorIndex] + noise));
|
|
6235
|
+
fg2[colorIndex + 1] = Math.max(0, Math.min(1, fg2[colorIndex + 1] + noise));
|
|
6236
|
+
fg2[colorIndex + 2] = Math.max(0, Math.min(1, fg2[colorIndex + 2] + noise));
|
|
6237
|
+
bg2[colorIndex] = Math.max(0, Math.min(1, bg2[colorIndex] + noise));
|
|
6238
|
+
bg2[colorIndex + 1] = Math.max(0, Math.min(1, bg2[colorIndex + 1] + noise));
|
|
6239
|
+
bg2[colorIndex + 2] = Math.max(0, Math.min(1, bg2[colorIndex + 2] + noise));
|
|
5920
6240
|
}
|
|
5921
6241
|
}
|
|
5922
6242
|
function applyChromaticAberration(buffer, strength = 1) {
|
|
@@ -5947,15 +6267,15 @@ function applyAsciiArt(buffer, ramp = " .:-=+*#%@") {
|
|
|
5947
6267
|
const width = buffer.getWidth();
|
|
5948
6268
|
const height = buffer.getHeight();
|
|
5949
6269
|
const chars = buffer.buffers.char;
|
|
5950
|
-
const
|
|
6270
|
+
const bg2 = buffer.buffers.bg;
|
|
5951
6271
|
const rampLength = ramp.length;
|
|
5952
6272
|
for (let y = 0;y < height; y++) {
|
|
5953
6273
|
for (let x = 0;x < width; x++) {
|
|
5954
6274
|
const index = y * width + x;
|
|
5955
6275
|
const colorIndex = index * 4;
|
|
5956
|
-
const bgR =
|
|
5957
|
-
const bgG =
|
|
5958
|
-
const bgB =
|
|
6276
|
+
const bgR = bg2[colorIndex];
|
|
6277
|
+
const bgG = bg2[colorIndex + 1];
|
|
6278
|
+
const bgB = bg2[colorIndex + 2];
|
|
5959
6279
|
const lum = 0.299 * bgR + 0.587 * bgG + 0.114 * bgB;
|
|
5960
6280
|
const rampIndex = Math.min(rampLength - 1, Math.floor(lum * rampLength));
|
|
5961
6281
|
chars[index] = ramp[rampIndex].charCodeAt(0);
|
|
@@ -6215,20 +6535,20 @@ class BrightnessEffect {
|
|
|
6215
6535
|
}
|
|
6216
6536
|
apply(buffer) {
|
|
6217
6537
|
const size = buffer.getWidth() * buffer.getHeight();
|
|
6218
|
-
const
|
|
6219
|
-
const
|
|
6538
|
+
const fg2 = buffer.buffers.fg;
|
|
6539
|
+
const bg2 = buffer.buffers.bg;
|
|
6220
6540
|
const factor = this._brightness;
|
|
6221
6541
|
if (factor === 1) {
|
|
6222
6542
|
return;
|
|
6223
6543
|
}
|
|
6224
6544
|
for (let i = 0;i < size; i++) {
|
|
6225
6545
|
const colorIndex = i * 4;
|
|
6226
|
-
|
|
6227
|
-
|
|
6228
|
-
|
|
6229
|
-
|
|
6230
|
-
|
|
6231
|
-
|
|
6546
|
+
fg2[colorIndex] = Math.min(1, fg2[colorIndex] * factor);
|
|
6547
|
+
fg2[colorIndex + 1] = Math.min(1, fg2[colorIndex + 1] * factor);
|
|
6548
|
+
fg2[colorIndex + 2] = Math.min(1, fg2[colorIndex + 2] * factor);
|
|
6549
|
+
bg2[colorIndex] = Math.min(1, bg2[colorIndex] * factor);
|
|
6550
|
+
bg2[colorIndex + 1] = Math.min(1, bg2[colorIndex + 1] * factor);
|
|
6551
|
+
bg2[colorIndex + 2] = Math.min(1, bg2[colorIndex + 2] * factor);
|
|
6232
6552
|
}
|
|
6233
6553
|
}
|
|
6234
6554
|
}
|
|
@@ -6480,45 +6800,45 @@ class BloomEffect {
|
|
|
6480
6800
|
}
|
|
6481
6801
|
// src/animation/Timeline.ts
|
|
6482
6802
|
var easingFunctions = {
|
|
6483
|
-
linear: (
|
|
6484
|
-
inQuad: (
|
|
6485
|
-
outQuad: (
|
|
6486
|
-
inOutQuad: (
|
|
6487
|
-
inExpo: (
|
|
6488
|
-
outExpo: (
|
|
6489
|
-
inOutSine: (
|
|
6490
|
-
outBounce: (
|
|
6803
|
+
linear: (t2) => t2,
|
|
6804
|
+
inQuad: (t2) => t2 * t2,
|
|
6805
|
+
outQuad: (t2) => t2 * (2 - t2),
|
|
6806
|
+
inOutQuad: (t2) => t2 < 0.5 ? 2 * t2 * t2 : -1 + (4 - 2 * t2) * t2,
|
|
6807
|
+
inExpo: (t2) => t2 === 0 ? 0 : Math.pow(2, 10 * (t2 - 1)),
|
|
6808
|
+
outExpo: (t2) => t2 === 1 ? 1 : 1 - Math.pow(2, -10 * t2),
|
|
6809
|
+
inOutSine: (t2) => -(Math.cos(Math.PI * t2) - 1) / 2,
|
|
6810
|
+
outBounce: (t2) => {
|
|
6491
6811
|
const n1 = 7.5625;
|
|
6492
6812
|
const d1 = 2.75;
|
|
6493
|
-
if (
|
|
6494
|
-
return n1 *
|
|
6495
|
-
} else if (
|
|
6496
|
-
return n1 * (
|
|
6497
|
-
} else if (
|
|
6498
|
-
return n1 * (
|
|
6813
|
+
if (t2 < 1 / d1) {
|
|
6814
|
+
return n1 * t2 * t2;
|
|
6815
|
+
} else if (t2 < 2 / d1) {
|
|
6816
|
+
return n1 * (t2 -= 1.5 / d1) * t2 + 0.75;
|
|
6817
|
+
} else if (t2 < 2.5 / d1) {
|
|
6818
|
+
return n1 * (t2 -= 2.25 / d1) * t2 + 0.9375;
|
|
6499
6819
|
} else {
|
|
6500
|
-
return n1 * (
|
|
6820
|
+
return n1 * (t2 -= 2.625 / d1) * t2 + 0.984375;
|
|
6501
6821
|
}
|
|
6502
6822
|
},
|
|
6503
|
-
outElastic: (
|
|
6823
|
+
outElastic: (t2) => {
|
|
6504
6824
|
const c4 = 2 * Math.PI / 3;
|
|
6505
|
-
return
|
|
6825
|
+
return t2 === 0 ? 0 : t2 === 1 ? 1 : Math.pow(2, -10 * t2) * Math.sin((t2 * 10 - 0.75) * c4) + 1;
|
|
6506
6826
|
},
|
|
6507
|
-
inBounce: (
|
|
6508
|
-
inCirc: (
|
|
6509
|
-
outCirc: (
|
|
6510
|
-
inOutCirc: (
|
|
6511
|
-
if ((
|
|
6512
|
-
return -0.5 * (Math.sqrt(1 -
|
|
6513
|
-
return 0.5 * (Math.sqrt(1 - (
|
|
6827
|
+
inBounce: (t2) => 1 - easingFunctions.outBounce(1 - t2),
|
|
6828
|
+
inCirc: (t2) => 1 - Math.sqrt(1 - t2 * t2),
|
|
6829
|
+
outCirc: (t2) => Math.sqrt(1 - Math.pow(t2 - 1, 2)),
|
|
6830
|
+
inOutCirc: (t2) => {
|
|
6831
|
+
if ((t2 *= 2) < 1)
|
|
6832
|
+
return -0.5 * (Math.sqrt(1 - t2 * t2) - 1);
|
|
6833
|
+
return 0.5 * (Math.sqrt(1 - (t2 -= 2) * t2) + 1);
|
|
6514
6834
|
},
|
|
6515
|
-
inBack: (
|
|
6516
|
-
outBack: (
|
|
6517
|
-
inOutBack: (
|
|
6835
|
+
inBack: (t2, s = 1.70158) => t2 * t2 * ((s + 1) * t2 - s),
|
|
6836
|
+
outBack: (t2, s = 1.70158) => --t2 * t2 * ((s + 1) * t2 + s) + 1,
|
|
6837
|
+
inOutBack: (t2, s = 1.70158) => {
|
|
6518
6838
|
s *= 1.525;
|
|
6519
|
-
if ((
|
|
6520
|
-
return 0.5 * (
|
|
6521
|
-
return 0.5 * ((
|
|
6839
|
+
if ((t2 *= 2) < 1)
|
|
6840
|
+
return 0.5 * (t2 * t2 * ((s + 1) * t2 - s));
|
|
6841
|
+
return 0.5 * ((t2 -= 2) * t2 * ((s + 1) * t2 + s) + 2);
|
|
6522
6842
|
}
|
|
6523
6843
|
};
|
|
6524
6844
|
function captureInitialValues(item) {
|
|
@@ -6850,182 +7170,6 @@ function createTimeline(options = {}) {
|
|
|
6850
7170
|
engine.register(timeline);
|
|
6851
7171
|
return timeline;
|
|
6852
7172
|
}
|
|
6853
|
-
// src/lib/styled-text.ts
|
|
6854
|
-
var textEncoder = new TextEncoder;
|
|
6855
|
-
|
|
6856
|
-
class StyledText {
|
|
6857
|
-
chunks;
|
|
6858
|
-
_length;
|
|
6859
|
-
_plainText;
|
|
6860
|
-
constructor(chunks, length, plainText) {
|
|
6861
|
-
this.chunks = chunks;
|
|
6862
|
-
this._length = length;
|
|
6863
|
-
this._plainText = plainText;
|
|
6864
|
-
}
|
|
6865
|
-
toString() {
|
|
6866
|
-
return this._plainText;
|
|
6867
|
-
}
|
|
6868
|
-
get length() {
|
|
6869
|
-
return this._length;
|
|
6870
|
-
}
|
|
6871
|
-
}
|
|
6872
|
-
function stringToStyledText(content) {
|
|
6873
|
-
const textEncoder2 = new TextEncoder;
|
|
6874
|
-
const chunk = {
|
|
6875
|
-
__isChunk: true,
|
|
6876
|
-
text: textEncoder2.encode(content),
|
|
6877
|
-
plainText: content
|
|
6878
|
-
};
|
|
6879
|
-
return new StyledText([chunk], content.length, content);
|
|
6880
|
-
}
|
|
6881
|
-
var templateCache = new WeakMap;
|
|
6882
|
-
function applyStyle(input, style) {
|
|
6883
|
-
if (typeof input === "object" && "__isChunk" in input) {
|
|
6884
|
-
const existingChunk = input;
|
|
6885
|
-
const fg = style.fg ? parseColor(style.fg) : existingChunk.fg;
|
|
6886
|
-
const bg = style.bg ? parseColor(style.bg) : existingChunk.bg;
|
|
6887
|
-
const newAttrs = createTextAttributes(style);
|
|
6888
|
-
const mergedAttrs = existingChunk.attributes ? existingChunk.attributes | newAttrs : newAttrs;
|
|
6889
|
-
return {
|
|
6890
|
-
__isChunk: true,
|
|
6891
|
-
text: existingChunk.text,
|
|
6892
|
-
plainText: existingChunk.plainText,
|
|
6893
|
-
fg,
|
|
6894
|
-
bg,
|
|
6895
|
-
attributes: mergedAttrs
|
|
6896
|
-
};
|
|
6897
|
-
} else {
|
|
6898
|
-
const plainTextStr = String(input);
|
|
6899
|
-
const text = textEncoder.encode(plainTextStr);
|
|
6900
|
-
const fg = style.fg ? parseColor(style.fg) : undefined;
|
|
6901
|
-
const bg = style.bg ? parseColor(style.bg) : undefined;
|
|
6902
|
-
const attributes = createTextAttributes(style);
|
|
6903
|
-
return {
|
|
6904
|
-
__isChunk: true,
|
|
6905
|
-
text,
|
|
6906
|
-
plainText: plainTextStr,
|
|
6907
|
-
fg,
|
|
6908
|
-
bg,
|
|
6909
|
-
attributes
|
|
6910
|
-
};
|
|
6911
|
-
}
|
|
6912
|
-
}
|
|
6913
|
-
var black = (input) => applyStyle(input, { fg: "black" });
|
|
6914
|
-
var red = (input) => applyStyle(input, { fg: "red" });
|
|
6915
|
-
var green = (input) => applyStyle(input, { fg: "green" });
|
|
6916
|
-
var yellow = (input) => applyStyle(input, { fg: "yellow" });
|
|
6917
|
-
var blue = (input) => applyStyle(input, { fg: "blue" });
|
|
6918
|
-
var magenta = (input) => applyStyle(input, { fg: "magenta" });
|
|
6919
|
-
var cyan = (input) => applyStyle(input, { fg: "cyan" });
|
|
6920
|
-
var white = (input) => applyStyle(input, { fg: "white" });
|
|
6921
|
-
var brightBlack = (input) => applyStyle(input, { fg: "brightBlack" });
|
|
6922
|
-
var brightRed = (input) => applyStyle(input, { fg: "brightRed" });
|
|
6923
|
-
var brightGreen = (input) => applyStyle(input, { fg: "brightGreen" });
|
|
6924
|
-
var brightYellow = (input) => applyStyle(input, { fg: "brightYellow" });
|
|
6925
|
-
var brightBlue = (input) => applyStyle(input, { fg: "brightBlue" });
|
|
6926
|
-
var brightMagenta = (input) => applyStyle(input, { fg: "brightMagenta" });
|
|
6927
|
-
var brightCyan = (input) => applyStyle(input, { fg: "brightCyan" });
|
|
6928
|
-
var brightWhite = (input) => applyStyle(input, { fg: "brightWhite" });
|
|
6929
|
-
var bgBlack = (input) => applyStyle(input, { bg: "black" });
|
|
6930
|
-
var bgRed = (input) => applyStyle(input, { bg: "red" });
|
|
6931
|
-
var bgGreen = (input) => applyStyle(input, { bg: "green" });
|
|
6932
|
-
var bgYellow = (input) => applyStyle(input, { bg: "yellow" });
|
|
6933
|
-
var bgBlue = (input) => applyStyle(input, { bg: "blue" });
|
|
6934
|
-
var bgMagenta = (input) => applyStyle(input, { bg: "magenta" });
|
|
6935
|
-
var bgCyan = (input) => applyStyle(input, { bg: "cyan" });
|
|
6936
|
-
var bgWhite = (input) => applyStyle(input, { bg: "white" });
|
|
6937
|
-
var bold = (input) => applyStyle(input, { bold: true });
|
|
6938
|
-
var italic = (input) => applyStyle(input, { italic: true });
|
|
6939
|
-
var underline = (input) => applyStyle(input, { underline: true });
|
|
6940
|
-
var strikethrough = (input) => applyStyle(input, { strikethrough: true });
|
|
6941
|
-
var dim = (input) => applyStyle(input, { dim: true });
|
|
6942
|
-
var reverse = (input) => applyStyle(input, { reverse: true });
|
|
6943
|
-
var blink = (input) => applyStyle(input, { blink: true });
|
|
6944
|
-
var fg = (color) => (input) => applyStyle(input, { fg: color });
|
|
6945
|
-
var bg = (color) => (input) => applyStyle(input, { bg: color });
|
|
6946
|
-
function tn(strings, ...values) {
|
|
6947
|
-
const chunks = [];
|
|
6948
|
-
let length = 0;
|
|
6949
|
-
let plainText = "";
|
|
6950
|
-
for (let i = 0;i < strings.length; i++) {
|
|
6951
|
-
const raw = strings[i];
|
|
6952
|
-
if (raw) {
|
|
6953
|
-
chunks.push({
|
|
6954
|
-
__isChunk: true,
|
|
6955
|
-
text: textEncoder.encode(raw),
|
|
6956
|
-
plainText: raw,
|
|
6957
|
-
attributes: 0
|
|
6958
|
-
});
|
|
6959
|
-
length += raw.length;
|
|
6960
|
-
plainText += raw;
|
|
6961
|
-
}
|
|
6962
|
-
const val = values[i];
|
|
6963
|
-
if (typeof val === "object" && "__isChunk" in val) {
|
|
6964
|
-
chunks.push(val);
|
|
6965
|
-
length += val.plainText.length;
|
|
6966
|
-
plainText += val.plainText;
|
|
6967
|
-
} else if (val !== undefined) {
|
|
6968
|
-
const plainTextStr = String(val);
|
|
6969
|
-
chunks.push({
|
|
6970
|
-
__isChunk: true,
|
|
6971
|
-
text: textEncoder.encode(plainTextStr),
|
|
6972
|
-
plainText: plainTextStr,
|
|
6973
|
-
attributes: 0
|
|
6974
|
-
});
|
|
6975
|
-
length += plainTextStr.length;
|
|
6976
|
-
plainText += plainTextStr;
|
|
6977
|
-
}
|
|
6978
|
-
}
|
|
6979
|
-
return new StyledText(chunks, length, plainText);
|
|
6980
|
-
}
|
|
6981
|
-
function t(strings, ...values) {
|
|
6982
|
-
let cachedStringChunks = templateCache.get(strings);
|
|
6983
|
-
let length = 0;
|
|
6984
|
-
let plainText = "";
|
|
6985
|
-
if (!cachedStringChunks) {
|
|
6986
|
-
cachedStringChunks = [];
|
|
6987
|
-
for (let i = 0;i < strings.length; i++) {
|
|
6988
|
-
const raw = strings[i];
|
|
6989
|
-
if (raw) {
|
|
6990
|
-
cachedStringChunks.push({
|
|
6991
|
-
__isChunk: true,
|
|
6992
|
-
text: textEncoder.encode(raw),
|
|
6993
|
-
plainText: raw,
|
|
6994
|
-
attributes: 0
|
|
6995
|
-
});
|
|
6996
|
-
} else {
|
|
6997
|
-
cachedStringChunks.push(null);
|
|
6998
|
-
}
|
|
6999
|
-
}
|
|
7000
|
-
templateCache.set(strings, cachedStringChunks);
|
|
7001
|
-
}
|
|
7002
|
-
const chunks = [];
|
|
7003
|
-
for (let i = 0;i < strings.length; i++) {
|
|
7004
|
-
const stringChunk = cachedStringChunks[i];
|
|
7005
|
-
if (stringChunk) {
|
|
7006
|
-
chunks.push(stringChunk);
|
|
7007
|
-
length += stringChunk.plainText.length;
|
|
7008
|
-
plainText += stringChunk.plainText;
|
|
7009
|
-
}
|
|
7010
|
-
const val = values[i];
|
|
7011
|
-
if (typeof val === "object" && "__isChunk" in val) {
|
|
7012
|
-
chunks.push(val);
|
|
7013
|
-
length += val.plainText.length;
|
|
7014
|
-
plainText += val.plainText;
|
|
7015
|
-
} else if (val !== undefined) {
|
|
7016
|
-
const plainTextStr = String(val);
|
|
7017
|
-
chunks.push({
|
|
7018
|
-
__isChunk: true,
|
|
7019
|
-
text: textEncoder.encode(plainTextStr),
|
|
7020
|
-
plainText: plainTextStr,
|
|
7021
|
-
attributes: 0
|
|
7022
|
-
});
|
|
7023
|
-
length += plainTextStr.length;
|
|
7024
|
-
plainText += plainTextStr;
|
|
7025
|
-
}
|
|
7026
|
-
}
|
|
7027
|
-
return new StyledText(chunks, length, plainText);
|
|
7028
|
-
}
|
|
7029
7173
|
// src/lib/selection.ts
|
|
7030
7174
|
class Selection {
|
|
7031
7175
|
_anchor;
|
|
@@ -7473,6 +7617,13 @@ var terminalConsoleCache = new TerminalConsoleCache;
|
|
|
7473
7617
|
process.on("exit", () => {
|
|
7474
7618
|
terminalConsoleCache.destroy();
|
|
7475
7619
|
});
|
|
7620
|
+
var ConsolePosition;
|
|
7621
|
+
((ConsolePosition2) => {
|
|
7622
|
+
ConsolePosition2["TOP"] = "top";
|
|
7623
|
+
ConsolePosition2["BOTTOM"] = "bottom";
|
|
7624
|
+
ConsolePosition2["LEFT"] = "left";
|
|
7625
|
+
ConsolePosition2["RIGHT"] = "right";
|
|
7626
|
+
})(ConsolePosition ||= {});
|
|
7476
7627
|
var DEFAULT_CONSOLE_OPTIONS = {
|
|
7477
7628
|
position: "bottom" /* BOTTOM */,
|
|
7478
7629
|
sizePercent: 30,
|
|
@@ -9217,8 +9368,6 @@ class TextRenderable extends Renderable {
|
|
|
9217
9368
|
set content(value) {
|
|
9218
9369
|
this._text = typeof value === "string" ? stringToStyledText(value) : value;
|
|
9219
9370
|
this.updateTextInfo();
|
|
9220
|
-
this.setupMeasureFunc();
|
|
9221
|
-
this.needsUpdate();
|
|
9222
9371
|
}
|
|
9223
9372
|
get fg() {
|
|
9224
9373
|
return this._defaultFg;
|
|
@@ -10286,6 +10435,7 @@ export {
|
|
|
10286
10435
|
isDimensionType,
|
|
10287
10436
|
hsvToRgb,
|
|
10288
10437
|
hexToRgb,
|
|
10438
|
+
hastToStyledText,
|
|
10289
10439
|
green,
|
|
10290
10440
|
getKeyHandler,
|
|
10291
10441
|
getCharacterPositions,
|
|
@@ -10301,6 +10451,7 @@ export {
|
|
|
10301
10451
|
createTextAttributes,
|
|
10302
10452
|
createCliRenderer,
|
|
10303
10453
|
coordinateToCharacterIndex,
|
|
10454
|
+
capture,
|
|
10304
10455
|
brightYellow,
|
|
10305
10456
|
brightWhite,
|
|
10306
10457
|
brightRed,
|
|
@@ -10337,8 +10488,10 @@ export {
|
|
|
10337
10488
|
TextRenderable,
|
|
10338
10489
|
TextBuffer,
|
|
10339
10490
|
TextAttributes,
|
|
10491
|
+
TerminalConsole,
|
|
10340
10492
|
TabSelectRenderableEvents,
|
|
10341
10493
|
TabSelectRenderable,
|
|
10494
|
+
SyntaxStyle,
|
|
10342
10495
|
StyledText,
|
|
10343
10496
|
Selection,
|
|
10344
10497
|
SelectRenderableEvents,
|
|
@@ -10358,6 +10511,7 @@ export {
|
|
|
10358
10511
|
FrameBufferRenderable,
|
|
10359
10512
|
DistortionEffect,
|
|
10360
10513
|
DebugOverlayCorner,
|
|
10514
|
+
ConsolePosition,
|
|
10361
10515
|
CliRenderer,
|
|
10362
10516
|
CliRenderEvents,
|
|
10363
10517
|
BrightnessEffect,
|