@opentui/core 0.1.4 → 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 +295 -50
- package/LICENSE +21 -0
- package/Renderable.d.ts +1 -0
- package/index.d.ts +1 -0
- package/index.js +481 -339
- 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/utils.d.ts +0 -4
- package/supersampling-jw3fem06.wgsl +0 -201
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);
|
|
@@ -2967,16 +2987,6 @@ function createTextAttributes({
|
|
|
2967
2987
|
attributes |= TextAttributes.STRIKETHROUGH;
|
|
2968
2988
|
return attributes;
|
|
2969
2989
|
}
|
|
2970
|
-
async function loadTemplate(filePath, params) {
|
|
2971
|
-
const template = await Bun.file(filePath).text();
|
|
2972
|
-
return template.replace(/\${(\w+)}/g, (match, key) => params[key] || match);
|
|
2973
|
-
}
|
|
2974
|
-
function fixPaths(paths) {
|
|
2975
|
-
if (process.env.BUN_PACKER_BUNDLE) {
|
|
2976
|
-
return Object.fromEntries(Object.entries(paths).map(([key, value]) => [key, value.replace("../", "")]));
|
|
2977
|
-
}
|
|
2978
|
-
return paths;
|
|
2979
|
-
}
|
|
2980
2990
|
|
|
2981
2991
|
// src/types.ts
|
|
2982
2992
|
class RGBA {
|
|
@@ -5482,6 +5492,306 @@ function renderFontToFrameBuffer(buffer, {
|
|
|
5482
5492
|
height: fontDef.lines
|
|
5483
5493
|
};
|
|
5484
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
|
+
}
|
|
5485
5795
|
// src/buffer.ts
|
|
5486
5796
|
var fbIdCounter = 0;
|
|
5487
5797
|
function isRGBAWithAlpha(color) {
|
|
@@ -5576,14 +5886,14 @@ class OptimizedBuffer {
|
|
|
5576
5886
|
this.lib.bufferSetRespectAlpha(this.bufferPtr, respectAlpha);
|
|
5577
5887
|
this.respectAlpha = respectAlpha;
|
|
5578
5888
|
}
|
|
5579
|
-
clear(
|
|
5889
|
+
clear(bg2 = RGBA.fromValues(0, 0, 0, 1), clearChar = " ") {
|
|
5580
5890
|
if (this.useFFI) {
|
|
5581
|
-
this.clearFFI(
|
|
5891
|
+
this.clearFFI(bg2);
|
|
5582
5892
|
} else {
|
|
5583
|
-
this.clearLocal(
|
|
5893
|
+
this.clearLocal(bg2, clearChar);
|
|
5584
5894
|
}
|
|
5585
5895
|
}
|
|
5586
|
-
clearLocal(
|
|
5896
|
+
clearLocal(bg2 = RGBA.fromValues(0, 0, 0, 1), clearChar = " ") {
|
|
5587
5897
|
this.buffer.char.fill(clearChar.charCodeAt(0));
|
|
5588
5898
|
this.buffer.attributes.fill(0);
|
|
5589
5899
|
for (let i = 0;i < this.width * this.height; i++) {
|
|
@@ -5592,27 +5902,27 @@ class OptimizedBuffer {
|
|
|
5592
5902
|
this.buffer.fg[index + 1] = 1;
|
|
5593
5903
|
this.buffer.fg[index + 2] = 1;
|
|
5594
5904
|
this.buffer.fg[index + 3] = 1;
|
|
5595
|
-
this.buffer.bg[index] =
|
|
5596
|
-
this.buffer.bg[index + 1] =
|
|
5597
|
-
this.buffer.bg[index + 2] =
|
|
5598
|
-
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;
|
|
5599
5909
|
}
|
|
5600
5910
|
}
|
|
5601
|
-
setCell(x, y, char,
|
|
5911
|
+
setCell(x, y, char, fg2, bg2, attributes = 0) {
|
|
5602
5912
|
if (x < 0 || x >= this.width || y < 0 || y >= this.height)
|
|
5603
5913
|
return;
|
|
5604
5914
|
const index = this.coordsToIndex(x, y);
|
|
5605
5915
|
const colorIndex = index * 4;
|
|
5606
5916
|
this.buffer.char[index] = char.charCodeAt(0);
|
|
5607
5917
|
this.buffer.attributes[index] = attributes;
|
|
5608
|
-
this.buffer.fg[colorIndex] =
|
|
5609
|
-
this.buffer.fg[colorIndex + 1] =
|
|
5610
|
-
this.buffer.fg[colorIndex + 2] =
|
|
5611
|
-
this.buffer.fg[colorIndex + 3] =
|
|
5612
|
-
this.buffer.bg[colorIndex] =
|
|
5613
|
-
this.buffer.bg[colorIndex + 1] =
|
|
5614
|
-
this.buffer.bg[colorIndex + 2] =
|
|
5615
|
-
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;
|
|
5616
5926
|
}
|
|
5617
5927
|
get(x, y) {
|
|
5618
5928
|
if (x < 0 || x >= this.width || y < 0 || y >= this.height)
|
|
@@ -5626,41 +5936,41 @@ class OptimizedBuffer {
|
|
|
5626
5936
|
attributes: this.buffer.attributes[index]
|
|
5627
5937
|
};
|
|
5628
5938
|
}
|
|
5629
|
-
setCellWithAlphaBlending(x, y, char,
|
|
5939
|
+
setCellWithAlphaBlending(x, y, char, fg2, bg2, attributes = 0) {
|
|
5630
5940
|
if (this.useFFI) {
|
|
5631
|
-
this.setCellWithAlphaBlendingFFI(x, y, char,
|
|
5941
|
+
this.setCellWithAlphaBlendingFFI(x, y, char, fg2, bg2, attributes);
|
|
5632
5942
|
} else {
|
|
5633
|
-
this.setCellWithAlphaBlendingLocal(x, y, char,
|
|
5943
|
+
this.setCellWithAlphaBlendingLocal(x, y, char, fg2, bg2, attributes);
|
|
5634
5944
|
}
|
|
5635
5945
|
}
|
|
5636
|
-
setCellWithAlphaBlendingLocal(x, y, char,
|
|
5946
|
+
setCellWithAlphaBlendingLocal(x, y, char, fg2, bg2, attributes = 0) {
|
|
5637
5947
|
if (x < 0 || x >= this.width || y < 0 || y >= this.height)
|
|
5638
5948
|
return;
|
|
5639
|
-
const hasBgAlpha = isRGBAWithAlpha(
|
|
5640
|
-
const hasFgAlpha = isRGBAWithAlpha(
|
|
5949
|
+
const hasBgAlpha = isRGBAWithAlpha(bg2);
|
|
5950
|
+
const hasFgAlpha = isRGBAWithAlpha(fg2);
|
|
5641
5951
|
if (hasBgAlpha || hasFgAlpha) {
|
|
5642
5952
|
const destCell = this.get(x, y);
|
|
5643
5953
|
if (destCell) {
|
|
5644
|
-
const blendedBgRgb = hasBgAlpha ? blendColors(
|
|
5954
|
+
const blendedBgRgb = hasBgAlpha ? blendColors(bg2, destCell.bg) : bg2;
|
|
5645
5955
|
const preserveChar = char === " " && destCell.char !== 0 && String.fromCharCode(destCell.char) !== " ";
|
|
5646
5956
|
const finalChar = preserveChar ? destCell.char : char.charCodeAt(0);
|
|
5647
5957
|
let finalFg;
|
|
5648
5958
|
if (preserveChar) {
|
|
5649
|
-
finalFg = blendColors(
|
|
5959
|
+
finalFg = blendColors(bg2, destCell.fg);
|
|
5650
5960
|
} else {
|
|
5651
|
-
finalFg = hasFgAlpha ? blendColors(
|
|
5961
|
+
finalFg = hasFgAlpha ? blendColors(fg2, destCell.bg) : fg2;
|
|
5652
5962
|
}
|
|
5653
5963
|
const finalAttributes = preserveChar ? destCell.attributes : attributes;
|
|
5654
|
-
const finalBg = RGBA.fromValues(blendedBgRgb.r, blendedBgRgb.g, blendedBgRgb.b,
|
|
5964
|
+
const finalBg = RGBA.fromValues(blendedBgRgb.r, blendedBgRgb.g, blendedBgRgb.b, bg2.a);
|
|
5655
5965
|
this.setCell(x, y, String.fromCharCode(finalChar), finalFg, finalBg, finalAttributes);
|
|
5656
5966
|
return;
|
|
5657
5967
|
}
|
|
5658
5968
|
}
|
|
5659
|
-
this.setCell(x, y, char,
|
|
5969
|
+
this.setCell(x, y, char, fg2, bg2, attributes);
|
|
5660
5970
|
}
|
|
5661
|
-
drawText(text, x, y,
|
|
5971
|
+
drawText(text, x, y, fg2, bg2, attributes = 0, selection) {
|
|
5662
5972
|
if (!selection) {
|
|
5663
|
-
this.drawTextFFI.call(this, text, x, y,
|
|
5973
|
+
this.drawTextFFI.call(this, text, x, y, fg2, bg2, attributes);
|
|
5664
5974
|
return;
|
|
5665
5975
|
}
|
|
5666
5976
|
const { start, end } = selection;
|
|
@@ -5668,15 +5978,15 @@ class OptimizedBuffer {
|
|
|
5668
5978
|
let selectionFg;
|
|
5669
5979
|
if (selection.bgColor) {
|
|
5670
5980
|
selectionBg = selection.bgColor;
|
|
5671
|
-
selectionFg = selection.fgColor ||
|
|
5981
|
+
selectionFg = selection.fgColor || fg2;
|
|
5672
5982
|
} else {
|
|
5673
|
-
const defaultBg =
|
|
5983
|
+
const defaultBg = bg2 || RGBA.fromValues(0, 0, 0, 0);
|
|
5674
5984
|
selectionFg = defaultBg.a > 0 ? defaultBg : RGBA.fromValues(0, 0, 0, 1);
|
|
5675
|
-
selectionBg =
|
|
5985
|
+
selectionBg = fg2;
|
|
5676
5986
|
}
|
|
5677
5987
|
if (start > 0) {
|
|
5678
5988
|
const beforeText = text.slice(0, start);
|
|
5679
|
-
this.drawTextFFI.call(this, beforeText, x, y,
|
|
5989
|
+
this.drawTextFFI.call(this, beforeText, x, y, fg2, bg2, attributes);
|
|
5680
5990
|
}
|
|
5681
5991
|
if (end > start) {
|
|
5682
5992
|
const selectedText = text.slice(start, end);
|
|
@@ -5684,29 +5994,29 @@ class OptimizedBuffer {
|
|
|
5684
5994
|
}
|
|
5685
5995
|
if (end < text.length) {
|
|
5686
5996
|
const afterText = text.slice(end);
|
|
5687
|
-
this.drawTextFFI.call(this, afterText, x + end, y,
|
|
5997
|
+
this.drawTextFFI.call(this, afterText, x + end, y, fg2, bg2, attributes);
|
|
5688
5998
|
}
|
|
5689
5999
|
}
|
|
5690
|
-
fillRect(x, y, width, height,
|
|
6000
|
+
fillRect(x, y, width, height, bg2) {
|
|
5691
6001
|
if (this.useFFI) {
|
|
5692
|
-
this.fillRectFFI(x, y, width, height,
|
|
6002
|
+
this.fillRectFFI(x, y, width, height, bg2);
|
|
5693
6003
|
} else {
|
|
5694
|
-
this.fillRectLocal(x, y, width, height,
|
|
6004
|
+
this.fillRectLocal(x, y, width, height, bg2);
|
|
5695
6005
|
}
|
|
5696
6006
|
}
|
|
5697
|
-
fillRectLocal(x, y, width, height,
|
|
6007
|
+
fillRectLocal(x, y, width, height, bg2) {
|
|
5698
6008
|
const startX = Math.max(0, x);
|
|
5699
6009
|
const startY = Math.max(0, y);
|
|
5700
6010
|
const endX = Math.min(this.getWidth() - 1, x + width - 1);
|
|
5701
6011
|
const endY = Math.min(this.getHeight() - 1, y + height - 1);
|
|
5702
6012
|
if (startX > endX || startY > endY)
|
|
5703
6013
|
return;
|
|
5704
|
-
const hasAlpha = isRGBAWithAlpha(
|
|
6014
|
+
const hasAlpha = isRGBAWithAlpha(bg2);
|
|
5705
6015
|
if (hasAlpha) {
|
|
5706
|
-
const
|
|
6016
|
+
const fg2 = RGBA.fromValues(1, 1, 1, 1);
|
|
5707
6017
|
for (let fillY = startY;fillY <= endY; fillY++) {
|
|
5708
6018
|
for (let fillX = startX;fillX <= endX; fillX++) {
|
|
5709
|
-
this.setCellWithAlphaBlending(fillX, fillY, " ",
|
|
6019
|
+
this.setCellWithAlphaBlending(fillX, fillY, " ", fg2, bg2, 0);
|
|
5710
6020
|
}
|
|
5711
6021
|
}
|
|
5712
6022
|
} else {
|
|
@@ -5720,10 +6030,10 @@ class OptimizedBuffer {
|
|
|
5720
6030
|
this.buffer.fg[colorIndex + 1] = 1;
|
|
5721
6031
|
this.buffer.fg[colorIndex + 2] = 1;
|
|
5722
6032
|
this.buffer.fg[colorIndex + 3] = 1;
|
|
5723
|
-
this.buffer.bg[colorIndex] =
|
|
5724
|
-
this.buffer.bg[colorIndex + 1] =
|
|
5725
|
-
this.buffer.bg[colorIndex + 2] =
|
|
5726
|
-
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;
|
|
5727
6037
|
}
|
|
5728
6038
|
}
|
|
5729
6039
|
}
|
|
@@ -5787,10 +6097,10 @@ class OptimizedBuffer {
|
|
|
5787
6097
|
continue;
|
|
5788
6098
|
}
|
|
5789
6099
|
const charCode = frameBuffer.buffer.char[srcIndex];
|
|
5790
|
-
const
|
|
5791
|
-
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));
|
|
5792
6102
|
const attributes = frameBuffer.buffer.attributes[srcIndex];
|
|
5793
|
-
this.setCellWithAlphaBlending(dX, dY, String.fromCharCode(charCode),
|
|
6103
|
+
this.setCellWithAlphaBlending(dX, dY, String.fromCharCode(charCode), fg2, bg2, attributes);
|
|
5794
6104
|
}
|
|
5795
6105
|
}
|
|
5796
6106
|
}
|
|
@@ -5809,11 +6119,11 @@ class OptimizedBuffer {
|
|
|
5809
6119
|
drawPackedBuffer(dataPtr, dataLen, posX, posY, terminalWidthCells, terminalHeightCells) {
|
|
5810
6120
|
this.lib.bufferDrawPackedBuffer(this.bufferPtr, dataPtr, dataLen, posX, posY, terminalWidthCells, terminalHeightCells);
|
|
5811
6121
|
}
|
|
5812
|
-
setCellWithAlphaBlendingFFI(x, y, char,
|
|
5813
|
-
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);
|
|
5814
6124
|
}
|
|
5815
|
-
fillRectFFI(x, y, width, height,
|
|
5816
|
-
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);
|
|
5817
6127
|
}
|
|
5818
6128
|
resize(width, height) {
|
|
5819
6129
|
if (this.width === width && this.height === height)
|
|
@@ -5822,11 +6132,11 @@ class OptimizedBuffer {
|
|
|
5822
6132
|
this.height = height;
|
|
5823
6133
|
this.buffer = this.lib.bufferResize(this.bufferPtr, width, height);
|
|
5824
6134
|
}
|
|
5825
|
-
clearFFI(
|
|
5826
|
-
this.lib.bufferClear(this.bufferPtr,
|
|
6135
|
+
clearFFI(bg2 = RGBA.fromValues(0, 0, 0, 1)) {
|
|
6136
|
+
this.lib.bufferClear(this.bufferPtr, bg2);
|
|
5827
6137
|
}
|
|
5828
|
-
drawTextFFI(text, x, y,
|
|
5829
|
-
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);
|
|
5830
6140
|
}
|
|
5831
6141
|
drawFrameBufferFFI(destX, destY, frameBuffer, sourceX, sourceY, sourceWidth, sourceHeight) {
|
|
5832
6142
|
this.lib.drawFrameBuffer(this.bufferPtr, destX, destY, frameBuffer.ptr, sourceX, sourceY, sourceWidth, sourceHeight);
|
|
@@ -5842,91 +6152,91 @@ class OptimizedBuffer {
|
|
|
5842
6152
|
function applyScanlines(buffer, strength = 0.8, step = 2) {
|
|
5843
6153
|
const width = buffer.getWidth();
|
|
5844
6154
|
const height = buffer.getHeight();
|
|
5845
|
-
const
|
|
6155
|
+
const bg2 = buffer.buffers.bg;
|
|
5846
6156
|
for (let y = 0;y < height; y += step) {
|
|
5847
6157
|
for (let x = 0;x < width; x++) {
|
|
5848
6158
|
const colorIndex = (y * width + x) * 4;
|
|
5849
|
-
|
|
5850
|
-
|
|
5851
|
-
|
|
6159
|
+
bg2[colorIndex] *= strength;
|
|
6160
|
+
bg2[colorIndex + 1] *= strength;
|
|
6161
|
+
bg2[colorIndex + 2] *= strength;
|
|
5852
6162
|
}
|
|
5853
6163
|
}
|
|
5854
6164
|
}
|
|
5855
6165
|
function applyGrayscale(buffer) {
|
|
5856
6166
|
const size = buffer.getWidth() * buffer.getHeight();
|
|
5857
|
-
const
|
|
5858
|
-
const
|
|
6167
|
+
const fg2 = buffer.buffers.fg;
|
|
6168
|
+
const bg2 = buffer.buffers.bg;
|
|
5859
6169
|
for (let i = 0;i < size; i++) {
|
|
5860
6170
|
const colorIndex = i * 4;
|
|
5861
|
-
const fgR =
|
|
5862
|
-
const fgG =
|
|
5863
|
-
const fgB =
|
|
6171
|
+
const fgR = fg2[colorIndex];
|
|
6172
|
+
const fgG = fg2[colorIndex + 1];
|
|
6173
|
+
const fgB = fg2[colorIndex + 2];
|
|
5864
6174
|
const fgLum = 0.299 * fgR + 0.587 * fgG + 0.114 * fgB;
|
|
5865
|
-
|
|
5866
|
-
|
|
5867
|
-
|
|
5868
|
-
const bgR =
|
|
5869
|
-
const bgG =
|
|
5870
|
-
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];
|
|
5871
6181
|
const bgLum = 0.299 * bgR + 0.587 * bgG + 0.114 * bgB;
|
|
5872
|
-
|
|
5873
|
-
|
|
5874
|
-
|
|
6182
|
+
bg2[colorIndex] = bgLum;
|
|
6183
|
+
bg2[colorIndex + 1] = bgLum;
|
|
6184
|
+
bg2[colorIndex + 2] = bgLum;
|
|
5875
6185
|
}
|
|
5876
6186
|
}
|
|
5877
6187
|
function applySepia(buffer) {
|
|
5878
6188
|
const size = buffer.getWidth() * buffer.getHeight();
|
|
5879
|
-
const
|
|
5880
|
-
const
|
|
6189
|
+
const fg2 = buffer.buffers.fg;
|
|
6190
|
+
const bg2 = buffer.buffers.bg;
|
|
5881
6191
|
for (let i = 0;i < size; i++) {
|
|
5882
6192
|
const colorIndex = i * 4;
|
|
5883
|
-
let fgR =
|
|
5884
|
-
let fgG =
|
|
5885
|
-
let fgB =
|
|
6193
|
+
let fgR = fg2[colorIndex];
|
|
6194
|
+
let fgG = fg2[colorIndex + 1];
|
|
6195
|
+
let fgB = fg2[colorIndex + 2];
|
|
5886
6196
|
let newFgR = Math.min(1, fgR * 0.393 + fgG * 0.769 + fgB * 0.189);
|
|
5887
6197
|
let newFgG = Math.min(1, fgR * 0.349 + fgG * 0.686 + fgB * 0.168);
|
|
5888
6198
|
let newFgB = Math.min(1, fgR * 0.272 + fgG * 0.534 + fgB * 0.131);
|
|
5889
|
-
|
|
5890
|
-
|
|
5891
|
-
|
|
5892
|
-
let bgR =
|
|
5893
|
-
let bgG =
|
|
5894
|
-
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];
|
|
5895
6205
|
let newBgR = Math.min(1, bgR * 0.393 + bgG * 0.769 + bgB * 0.189);
|
|
5896
6206
|
let newBgG = Math.min(1, bgR * 0.349 + bgG * 0.686 + bgB * 0.168);
|
|
5897
6207
|
let newBgB = Math.min(1, bgR * 0.272 + bgG * 0.534 + bgB * 0.131);
|
|
5898
|
-
|
|
5899
|
-
|
|
5900
|
-
|
|
6208
|
+
bg2[colorIndex] = newBgR;
|
|
6209
|
+
bg2[colorIndex + 1] = newBgG;
|
|
6210
|
+
bg2[colorIndex + 2] = newBgB;
|
|
5901
6211
|
}
|
|
5902
6212
|
}
|
|
5903
6213
|
function applyInvert(buffer) {
|
|
5904
6214
|
const size = buffer.getWidth() * buffer.getHeight();
|
|
5905
|
-
const
|
|
5906
|
-
const
|
|
6215
|
+
const fg2 = buffer.buffers.fg;
|
|
6216
|
+
const bg2 = buffer.buffers.bg;
|
|
5907
6217
|
for (let i = 0;i < size; i++) {
|
|
5908
6218
|
const colorIndex = i * 4;
|
|
5909
|
-
|
|
5910
|
-
|
|
5911
|
-
|
|
5912
|
-
|
|
5913
|
-
|
|
5914
|
-
|
|
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];
|
|
5915
6225
|
}
|
|
5916
6226
|
}
|
|
5917
6227
|
function applyNoise(buffer, strength = 0.1) {
|
|
5918
6228
|
const size = buffer.getWidth() * buffer.getHeight();
|
|
5919
|
-
const
|
|
5920
|
-
const
|
|
6229
|
+
const fg2 = buffer.buffers.fg;
|
|
6230
|
+
const bg2 = buffer.buffers.bg;
|
|
5921
6231
|
for (let i = 0;i < size; i++) {
|
|
5922
6232
|
const colorIndex = i * 4;
|
|
5923
6233
|
const noise = (Math.random() - 0.5) * strength;
|
|
5924
|
-
|
|
5925
|
-
|
|
5926
|
-
|
|
5927
|
-
|
|
5928
|
-
|
|
5929
|
-
|
|
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));
|
|
5930
6240
|
}
|
|
5931
6241
|
}
|
|
5932
6242
|
function applyChromaticAberration(buffer, strength = 1) {
|
|
@@ -5957,15 +6267,15 @@ function applyAsciiArt(buffer, ramp = " .:-=+*#%@") {
|
|
|
5957
6267
|
const width = buffer.getWidth();
|
|
5958
6268
|
const height = buffer.getHeight();
|
|
5959
6269
|
const chars = buffer.buffers.char;
|
|
5960
|
-
const
|
|
6270
|
+
const bg2 = buffer.buffers.bg;
|
|
5961
6271
|
const rampLength = ramp.length;
|
|
5962
6272
|
for (let y = 0;y < height; y++) {
|
|
5963
6273
|
for (let x = 0;x < width; x++) {
|
|
5964
6274
|
const index = y * width + x;
|
|
5965
6275
|
const colorIndex = index * 4;
|
|
5966
|
-
const bgR =
|
|
5967
|
-
const bgG =
|
|
5968
|
-
const bgB =
|
|
6276
|
+
const bgR = bg2[colorIndex];
|
|
6277
|
+
const bgG = bg2[colorIndex + 1];
|
|
6278
|
+
const bgB = bg2[colorIndex + 2];
|
|
5969
6279
|
const lum = 0.299 * bgR + 0.587 * bgG + 0.114 * bgB;
|
|
5970
6280
|
const rampIndex = Math.min(rampLength - 1, Math.floor(lum * rampLength));
|
|
5971
6281
|
chars[index] = ramp[rampIndex].charCodeAt(0);
|
|
@@ -6225,20 +6535,20 @@ class BrightnessEffect {
|
|
|
6225
6535
|
}
|
|
6226
6536
|
apply(buffer) {
|
|
6227
6537
|
const size = buffer.getWidth() * buffer.getHeight();
|
|
6228
|
-
const
|
|
6229
|
-
const
|
|
6538
|
+
const fg2 = buffer.buffers.fg;
|
|
6539
|
+
const bg2 = buffer.buffers.bg;
|
|
6230
6540
|
const factor = this._brightness;
|
|
6231
6541
|
if (factor === 1) {
|
|
6232
6542
|
return;
|
|
6233
6543
|
}
|
|
6234
6544
|
for (let i = 0;i < size; i++) {
|
|
6235
6545
|
const colorIndex = i * 4;
|
|
6236
|
-
|
|
6237
|
-
|
|
6238
|
-
|
|
6239
|
-
|
|
6240
|
-
|
|
6241
|
-
|
|
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);
|
|
6242
6552
|
}
|
|
6243
6553
|
}
|
|
6244
6554
|
}
|
|
@@ -6490,45 +6800,45 @@ class BloomEffect {
|
|
|
6490
6800
|
}
|
|
6491
6801
|
// src/animation/Timeline.ts
|
|
6492
6802
|
var easingFunctions = {
|
|
6493
|
-
linear: (
|
|
6494
|
-
inQuad: (
|
|
6495
|
-
outQuad: (
|
|
6496
|
-
inOutQuad: (
|
|
6497
|
-
inExpo: (
|
|
6498
|
-
outExpo: (
|
|
6499
|
-
inOutSine: (
|
|
6500
|
-
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) => {
|
|
6501
6811
|
const n1 = 7.5625;
|
|
6502
6812
|
const d1 = 2.75;
|
|
6503
|
-
if (
|
|
6504
|
-
return n1 *
|
|
6505
|
-
} else if (
|
|
6506
|
-
return n1 * (
|
|
6507
|
-
} else if (
|
|
6508
|
-
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;
|
|
6509
6819
|
} else {
|
|
6510
|
-
return n1 * (
|
|
6820
|
+
return n1 * (t2 -= 2.625 / d1) * t2 + 0.984375;
|
|
6511
6821
|
}
|
|
6512
6822
|
},
|
|
6513
|
-
outElastic: (
|
|
6823
|
+
outElastic: (t2) => {
|
|
6514
6824
|
const c4 = 2 * Math.PI / 3;
|
|
6515
|
-
return
|
|
6825
|
+
return t2 === 0 ? 0 : t2 === 1 ? 1 : Math.pow(2, -10 * t2) * Math.sin((t2 * 10 - 0.75) * c4) + 1;
|
|
6516
6826
|
},
|
|
6517
|
-
inBounce: (
|
|
6518
|
-
inCirc: (
|
|
6519
|
-
outCirc: (
|
|
6520
|
-
inOutCirc: (
|
|
6521
|
-
if ((
|
|
6522
|
-
return -0.5 * (Math.sqrt(1 -
|
|
6523
|
-
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);
|
|
6524
6834
|
},
|
|
6525
|
-
inBack: (
|
|
6526
|
-
outBack: (
|
|
6527
|
-
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) => {
|
|
6528
6838
|
s *= 1.525;
|
|
6529
|
-
if ((
|
|
6530
|
-
return 0.5 * (
|
|
6531
|
-
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);
|
|
6532
6842
|
}
|
|
6533
6843
|
};
|
|
6534
6844
|
function captureInitialValues(item) {
|
|
@@ -6860,182 +7170,6 @@ function createTimeline(options = {}) {
|
|
|
6860
7170
|
engine.register(timeline);
|
|
6861
7171
|
return timeline;
|
|
6862
7172
|
}
|
|
6863
|
-
// src/lib/styled-text.ts
|
|
6864
|
-
var textEncoder = new TextEncoder;
|
|
6865
|
-
|
|
6866
|
-
class StyledText {
|
|
6867
|
-
chunks;
|
|
6868
|
-
_length;
|
|
6869
|
-
_plainText;
|
|
6870
|
-
constructor(chunks, length, plainText) {
|
|
6871
|
-
this.chunks = chunks;
|
|
6872
|
-
this._length = length;
|
|
6873
|
-
this._plainText = plainText;
|
|
6874
|
-
}
|
|
6875
|
-
toString() {
|
|
6876
|
-
return this._plainText;
|
|
6877
|
-
}
|
|
6878
|
-
get length() {
|
|
6879
|
-
return this._length;
|
|
6880
|
-
}
|
|
6881
|
-
}
|
|
6882
|
-
function stringToStyledText(content) {
|
|
6883
|
-
const textEncoder2 = new TextEncoder;
|
|
6884
|
-
const chunk = {
|
|
6885
|
-
__isChunk: true,
|
|
6886
|
-
text: textEncoder2.encode(content),
|
|
6887
|
-
plainText: content
|
|
6888
|
-
};
|
|
6889
|
-
return new StyledText([chunk], content.length, content);
|
|
6890
|
-
}
|
|
6891
|
-
var templateCache = new WeakMap;
|
|
6892
|
-
function applyStyle(input, style) {
|
|
6893
|
-
if (typeof input === "object" && "__isChunk" in input) {
|
|
6894
|
-
const existingChunk = input;
|
|
6895
|
-
const fg = style.fg ? parseColor(style.fg) : existingChunk.fg;
|
|
6896
|
-
const bg = style.bg ? parseColor(style.bg) : existingChunk.bg;
|
|
6897
|
-
const newAttrs = createTextAttributes(style);
|
|
6898
|
-
const mergedAttrs = existingChunk.attributes ? existingChunk.attributes | newAttrs : newAttrs;
|
|
6899
|
-
return {
|
|
6900
|
-
__isChunk: true,
|
|
6901
|
-
text: existingChunk.text,
|
|
6902
|
-
plainText: existingChunk.plainText,
|
|
6903
|
-
fg,
|
|
6904
|
-
bg,
|
|
6905
|
-
attributes: mergedAttrs
|
|
6906
|
-
};
|
|
6907
|
-
} else {
|
|
6908
|
-
const plainTextStr = String(input);
|
|
6909
|
-
const text = textEncoder.encode(plainTextStr);
|
|
6910
|
-
const fg = style.fg ? parseColor(style.fg) : undefined;
|
|
6911
|
-
const bg = style.bg ? parseColor(style.bg) : undefined;
|
|
6912
|
-
const attributes = createTextAttributes(style);
|
|
6913
|
-
return {
|
|
6914
|
-
__isChunk: true,
|
|
6915
|
-
text,
|
|
6916
|
-
plainText: plainTextStr,
|
|
6917
|
-
fg,
|
|
6918
|
-
bg,
|
|
6919
|
-
attributes
|
|
6920
|
-
};
|
|
6921
|
-
}
|
|
6922
|
-
}
|
|
6923
|
-
var black = (input) => applyStyle(input, { fg: "black" });
|
|
6924
|
-
var red = (input) => applyStyle(input, { fg: "red" });
|
|
6925
|
-
var green = (input) => applyStyle(input, { fg: "green" });
|
|
6926
|
-
var yellow = (input) => applyStyle(input, { fg: "yellow" });
|
|
6927
|
-
var blue = (input) => applyStyle(input, { fg: "blue" });
|
|
6928
|
-
var magenta = (input) => applyStyle(input, { fg: "magenta" });
|
|
6929
|
-
var cyan = (input) => applyStyle(input, { fg: "cyan" });
|
|
6930
|
-
var white = (input) => applyStyle(input, { fg: "white" });
|
|
6931
|
-
var brightBlack = (input) => applyStyle(input, { fg: "brightBlack" });
|
|
6932
|
-
var brightRed = (input) => applyStyle(input, { fg: "brightRed" });
|
|
6933
|
-
var brightGreen = (input) => applyStyle(input, { fg: "brightGreen" });
|
|
6934
|
-
var brightYellow = (input) => applyStyle(input, { fg: "brightYellow" });
|
|
6935
|
-
var brightBlue = (input) => applyStyle(input, { fg: "brightBlue" });
|
|
6936
|
-
var brightMagenta = (input) => applyStyle(input, { fg: "brightMagenta" });
|
|
6937
|
-
var brightCyan = (input) => applyStyle(input, { fg: "brightCyan" });
|
|
6938
|
-
var brightWhite = (input) => applyStyle(input, { fg: "brightWhite" });
|
|
6939
|
-
var bgBlack = (input) => applyStyle(input, { bg: "black" });
|
|
6940
|
-
var bgRed = (input) => applyStyle(input, { bg: "red" });
|
|
6941
|
-
var bgGreen = (input) => applyStyle(input, { bg: "green" });
|
|
6942
|
-
var bgYellow = (input) => applyStyle(input, { bg: "yellow" });
|
|
6943
|
-
var bgBlue = (input) => applyStyle(input, { bg: "blue" });
|
|
6944
|
-
var bgMagenta = (input) => applyStyle(input, { bg: "magenta" });
|
|
6945
|
-
var bgCyan = (input) => applyStyle(input, { bg: "cyan" });
|
|
6946
|
-
var bgWhite = (input) => applyStyle(input, { bg: "white" });
|
|
6947
|
-
var bold = (input) => applyStyle(input, { bold: true });
|
|
6948
|
-
var italic = (input) => applyStyle(input, { italic: true });
|
|
6949
|
-
var underline = (input) => applyStyle(input, { underline: true });
|
|
6950
|
-
var strikethrough = (input) => applyStyle(input, { strikethrough: true });
|
|
6951
|
-
var dim = (input) => applyStyle(input, { dim: true });
|
|
6952
|
-
var reverse = (input) => applyStyle(input, { reverse: true });
|
|
6953
|
-
var blink = (input) => applyStyle(input, { blink: true });
|
|
6954
|
-
var fg = (color) => (input) => applyStyle(input, { fg: color });
|
|
6955
|
-
var bg = (color) => (input) => applyStyle(input, { bg: color });
|
|
6956
|
-
function tn(strings, ...values) {
|
|
6957
|
-
const chunks = [];
|
|
6958
|
-
let length = 0;
|
|
6959
|
-
let plainText = "";
|
|
6960
|
-
for (let i = 0;i < strings.length; i++) {
|
|
6961
|
-
const raw = strings[i];
|
|
6962
|
-
if (raw) {
|
|
6963
|
-
chunks.push({
|
|
6964
|
-
__isChunk: true,
|
|
6965
|
-
text: textEncoder.encode(raw),
|
|
6966
|
-
plainText: raw,
|
|
6967
|
-
attributes: 0
|
|
6968
|
-
});
|
|
6969
|
-
length += raw.length;
|
|
6970
|
-
plainText += raw;
|
|
6971
|
-
}
|
|
6972
|
-
const val = values[i];
|
|
6973
|
-
if (typeof val === "object" && "__isChunk" in val) {
|
|
6974
|
-
chunks.push(val);
|
|
6975
|
-
length += val.plainText.length;
|
|
6976
|
-
plainText += val.plainText;
|
|
6977
|
-
} else if (val !== undefined) {
|
|
6978
|
-
const plainTextStr = String(val);
|
|
6979
|
-
chunks.push({
|
|
6980
|
-
__isChunk: true,
|
|
6981
|
-
text: textEncoder.encode(plainTextStr),
|
|
6982
|
-
plainText: plainTextStr,
|
|
6983
|
-
attributes: 0
|
|
6984
|
-
});
|
|
6985
|
-
length += plainTextStr.length;
|
|
6986
|
-
plainText += plainTextStr;
|
|
6987
|
-
}
|
|
6988
|
-
}
|
|
6989
|
-
return new StyledText(chunks, length, plainText);
|
|
6990
|
-
}
|
|
6991
|
-
function t(strings, ...values) {
|
|
6992
|
-
let cachedStringChunks = templateCache.get(strings);
|
|
6993
|
-
let length = 0;
|
|
6994
|
-
let plainText = "";
|
|
6995
|
-
if (!cachedStringChunks) {
|
|
6996
|
-
cachedStringChunks = [];
|
|
6997
|
-
for (let i = 0;i < strings.length; i++) {
|
|
6998
|
-
const raw = strings[i];
|
|
6999
|
-
if (raw) {
|
|
7000
|
-
cachedStringChunks.push({
|
|
7001
|
-
__isChunk: true,
|
|
7002
|
-
text: textEncoder.encode(raw),
|
|
7003
|
-
plainText: raw,
|
|
7004
|
-
attributes: 0
|
|
7005
|
-
});
|
|
7006
|
-
} else {
|
|
7007
|
-
cachedStringChunks.push(null);
|
|
7008
|
-
}
|
|
7009
|
-
}
|
|
7010
|
-
templateCache.set(strings, cachedStringChunks);
|
|
7011
|
-
}
|
|
7012
|
-
const chunks = [];
|
|
7013
|
-
for (let i = 0;i < strings.length; i++) {
|
|
7014
|
-
const stringChunk = cachedStringChunks[i];
|
|
7015
|
-
if (stringChunk) {
|
|
7016
|
-
chunks.push(stringChunk);
|
|
7017
|
-
length += stringChunk.plainText.length;
|
|
7018
|
-
plainText += stringChunk.plainText;
|
|
7019
|
-
}
|
|
7020
|
-
const val = values[i];
|
|
7021
|
-
if (typeof val === "object" && "__isChunk" in val) {
|
|
7022
|
-
chunks.push(val);
|
|
7023
|
-
length += val.plainText.length;
|
|
7024
|
-
plainText += val.plainText;
|
|
7025
|
-
} else if (val !== undefined) {
|
|
7026
|
-
const plainTextStr = String(val);
|
|
7027
|
-
chunks.push({
|
|
7028
|
-
__isChunk: true,
|
|
7029
|
-
text: textEncoder.encode(plainTextStr),
|
|
7030
|
-
plainText: plainTextStr,
|
|
7031
|
-
attributes: 0
|
|
7032
|
-
});
|
|
7033
|
-
length += plainTextStr.length;
|
|
7034
|
-
plainText += plainTextStr;
|
|
7035
|
-
}
|
|
7036
|
-
}
|
|
7037
|
-
return new StyledText(chunks, length, plainText);
|
|
7038
|
-
}
|
|
7039
7173
|
// src/lib/selection.ts
|
|
7040
7174
|
class Selection {
|
|
7041
7175
|
_anchor;
|
|
@@ -7483,6 +7617,13 @@ var terminalConsoleCache = new TerminalConsoleCache;
|
|
|
7483
7617
|
process.on("exit", () => {
|
|
7484
7618
|
terminalConsoleCache.destroy();
|
|
7485
7619
|
});
|
|
7620
|
+
var ConsolePosition;
|
|
7621
|
+
((ConsolePosition2) => {
|
|
7622
|
+
ConsolePosition2["TOP"] = "top";
|
|
7623
|
+
ConsolePosition2["BOTTOM"] = "bottom";
|
|
7624
|
+
ConsolePosition2["LEFT"] = "left";
|
|
7625
|
+
ConsolePosition2["RIGHT"] = "right";
|
|
7626
|
+
})(ConsolePosition ||= {});
|
|
7486
7627
|
var DEFAULT_CONSOLE_OPTIONS = {
|
|
7487
7628
|
position: "bottom" /* BOTTOM */,
|
|
7488
7629
|
sizePercent: 30,
|
|
@@ -9227,8 +9368,6 @@ class TextRenderable extends Renderable {
|
|
|
9227
9368
|
set content(value) {
|
|
9228
9369
|
this._text = typeof value === "string" ? stringToStyledText(value) : value;
|
|
9229
9370
|
this.updateTextInfo();
|
|
9230
|
-
this.setupMeasureFunc();
|
|
9231
|
-
this.needsUpdate();
|
|
9232
9371
|
}
|
|
9233
9372
|
get fg() {
|
|
9234
9373
|
return this._defaultFg;
|
|
@@ -10287,7 +10426,6 @@ export {
|
|
|
10287
10426
|
nonAlphanumericKeys,
|
|
10288
10427
|
measureText,
|
|
10289
10428
|
magenta,
|
|
10290
|
-
loadTemplate,
|
|
10291
10429
|
italic,
|
|
10292
10430
|
isSizeType,
|
|
10293
10431
|
isPositionType,
|
|
@@ -10297,13 +10435,13 @@ export {
|
|
|
10297
10435
|
isDimensionType,
|
|
10298
10436
|
hsvToRgb,
|
|
10299
10437
|
hexToRgb,
|
|
10438
|
+
hastToStyledText,
|
|
10300
10439
|
green,
|
|
10301
10440
|
getKeyHandler,
|
|
10302
10441
|
getCharacterPositions,
|
|
10303
10442
|
getBorderSides,
|
|
10304
10443
|
getBorderFromSides,
|
|
10305
10444
|
fonts,
|
|
10306
|
-
fixPaths,
|
|
10307
10445
|
fg,
|
|
10308
10446
|
engine,
|
|
10309
10447
|
dim,
|
|
@@ -10313,6 +10451,7 @@ export {
|
|
|
10313
10451
|
createTextAttributes,
|
|
10314
10452
|
createCliRenderer,
|
|
10315
10453
|
coordinateToCharacterIndex,
|
|
10454
|
+
capture,
|
|
10316
10455
|
brightYellow,
|
|
10317
10456
|
brightWhite,
|
|
10318
10457
|
brightRed,
|
|
@@ -10349,8 +10488,10 @@ export {
|
|
|
10349
10488
|
TextRenderable,
|
|
10350
10489
|
TextBuffer,
|
|
10351
10490
|
TextAttributes,
|
|
10491
|
+
TerminalConsole,
|
|
10352
10492
|
TabSelectRenderableEvents,
|
|
10353
10493
|
TabSelectRenderable,
|
|
10494
|
+
SyntaxStyle,
|
|
10354
10495
|
StyledText,
|
|
10355
10496
|
Selection,
|
|
10356
10497
|
SelectRenderableEvents,
|
|
@@ -10370,6 +10511,7 @@ export {
|
|
|
10370
10511
|
FrameBufferRenderable,
|
|
10371
10512
|
DistortionEffect,
|
|
10372
10513
|
DebugOverlayCorner,
|
|
10514
|
+
ConsolePosition,
|
|
10373
10515
|
CliRenderer,
|
|
10374
10516
|
CliRenderEvents,
|
|
10375
10517
|
BrightnessEffect,
|