@opentui/core 0.3.3 → 0.3.4
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/{index-qndc8vq8.js → index-0nvgrgam.js} +2098 -2084
- package/{index-qndc8vq8.js.map → index-0nvgrgam.js.map} +5 -5
- package/{index-mn090kzf.js → index-54s7pk0d.js} +26 -6
- package/{index-mn090kzf.js.map → index-54s7pk0d.js.map} +3 -3
- package/{index-jh82sd41.js → index-8t841rbx.js} +2 -2
- package/{index-mbck6rbg.js → index-r49y8kdq.js} +3 -3
- package/index.js +2 -2
- package/package.json +9 -9
- package/renderables/Code.d.ts +4 -0
- package/renderables/Markdown.d.ts +1 -0
- package/runtime-plugin-support-configure.js +4 -4
- package/runtime-plugin-support.js +4 -4
- package/runtime-plugin.js +3 -3
- package/testing.js +1 -1
- /package/{index-jh82sd41.js.map → index-8t841rbx.js.map} +0 -0
- /package/{index-mbck6rbg.js.map → index-r49y8kdq.js.map} +0 -0
|
@@ -182,7 +182,7 @@ import {
|
|
|
182
182
|
white,
|
|
183
183
|
wrapWithDelegates,
|
|
184
184
|
yellow
|
|
185
|
-
} from "./index-
|
|
185
|
+
} from "./index-54s7pk0d.js";
|
|
186
186
|
|
|
187
187
|
// src/index.ts
|
|
188
188
|
var exports_src2 = {};
|
|
@@ -5754,1077 +5754,6 @@ class InputRenderable extends TextareaRenderable {
|
|
|
5754
5754
|
}
|
|
5755
5755
|
set initialValue(value) {}
|
|
5756
5756
|
}
|
|
5757
|
-
// src/renderables/TextTable.ts
|
|
5758
|
-
var MEASURE_HEIGHT = 1e4;
|
|
5759
|
-
|
|
5760
|
-
class TextTableRenderable extends Renderable {
|
|
5761
|
-
_content;
|
|
5762
|
-
_wrapMode;
|
|
5763
|
-
_columnWidthMode;
|
|
5764
|
-
_columnFitter;
|
|
5765
|
-
_cellPaddingX;
|
|
5766
|
-
_cellPaddingY;
|
|
5767
|
-
_columnGap;
|
|
5768
|
-
_showBorders;
|
|
5769
|
-
_border;
|
|
5770
|
-
_outerBorder;
|
|
5771
|
-
_hasExplicitOuterBorder;
|
|
5772
|
-
_borderStyle;
|
|
5773
|
-
_borderColor;
|
|
5774
|
-
_borderBackgroundColor;
|
|
5775
|
-
_backgroundColor;
|
|
5776
|
-
_defaultFg;
|
|
5777
|
-
_defaultBg;
|
|
5778
|
-
_defaultAttributes;
|
|
5779
|
-
_selectionBg;
|
|
5780
|
-
_selectionFg;
|
|
5781
|
-
_lastLocalSelection = null;
|
|
5782
|
-
_lastSelectionMode = null;
|
|
5783
|
-
_cells = [];
|
|
5784
|
-
_prevCellContent = [];
|
|
5785
|
-
_rowCount = 0;
|
|
5786
|
-
_columnCount = 0;
|
|
5787
|
-
_layout = this.createEmptyLayout();
|
|
5788
|
-
_layoutDirty = true;
|
|
5789
|
-
_rasterDirty = true;
|
|
5790
|
-
_cachedMeasureLayout = null;
|
|
5791
|
-
_cachedMeasureWidth = undefined;
|
|
5792
|
-
_defaultOptions = {
|
|
5793
|
-
content: [],
|
|
5794
|
-
wrapMode: "word",
|
|
5795
|
-
columnWidthMode: "full",
|
|
5796
|
-
columnFitter: "proportional",
|
|
5797
|
-
cellPadding: 0,
|
|
5798
|
-
cellPaddingX: undefined,
|
|
5799
|
-
cellPaddingY: undefined,
|
|
5800
|
-
columnGap: 0,
|
|
5801
|
-
showBorders: true,
|
|
5802
|
-
border: true,
|
|
5803
|
-
outerBorder: true,
|
|
5804
|
-
selectable: true,
|
|
5805
|
-
selectionBg: undefined,
|
|
5806
|
-
selectionFg: undefined,
|
|
5807
|
-
borderStyle: "single",
|
|
5808
|
-
borderColor: "#FFFFFF",
|
|
5809
|
-
borderBackgroundColor: "transparent",
|
|
5810
|
-
backgroundColor: "transparent",
|
|
5811
|
-
fg: "#FFFFFF",
|
|
5812
|
-
bg: "transparent",
|
|
5813
|
-
attributes: 0
|
|
5814
|
-
};
|
|
5815
|
-
constructor(ctx, options = {}) {
|
|
5816
|
-
super(ctx, { ...options, flexShrink: options.flexShrink ?? 0, buffered: true });
|
|
5817
|
-
this._content = options.content ?? this._defaultOptions.content;
|
|
5818
|
-
this._wrapMode = options.wrapMode ?? this._defaultOptions.wrapMode;
|
|
5819
|
-
this._columnWidthMode = options.columnWidthMode ?? this._defaultOptions.columnWidthMode;
|
|
5820
|
-
this._columnFitter = this.resolveColumnFitter(options.columnFitter);
|
|
5821
|
-
this._cellPaddingX = this.resolveCellPadding(options.cellPaddingX ?? options.cellPadding);
|
|
5822
|
-
this._cellPaddingY = this.resolveCellPadding(options.cellPaddingY ?? options.cellPadding);
|
|
5823
|
-
this._columnGap = this.resolveColumnGap(options.columnGap);
|
|
5824
|
-
this._showBorders = options.showBorders ?? this._defaultOptions.showBorders;
|
|
5825
|
-
this._border = options.border ?? this._defaultOptions.border;
|
|
5826
|
-
this._hasExplicitOuterBorder = options.outerBorder !== undefined;
|
|
5827
|
-
this._outerBorder = options.outerBorder ?? this._border;
|
|
5828
|
-
this.selectable = options.selectable ?? this._defaultOptions.selectable;
|
|
5829
|
-
this._selectionBg = options.selectionBg ? parseColor(options.selectionBg) : undefined;
|
|
5830
|
-
this._selectionFg = options.selectionFg ? parseColor(options.selectionFg) : undefined;
|
|
5831
|
-
this._borderStyle = parseBorderStyle(options.borderStyle, this._defaultOptions.borderStyle);
|
|
5832
|
-
this._borderColor = parseColor(options.borderColor ?? this._defaultOptions.borderColor);
|
|
5833
|
-
this._borderBackgroundColor = parseColor(options.borderBackgroundColor ?? this._defaultOptions.borderBackgroundColor);
|
|
5834
|
-
this._backgroundColor = parseColor(options.backgroundColor ?? this._defaultOptions.backgroundColor);
|
|
5835
|
-
this._defaultFg = parseColor(options.fg ?? this._defaultOptions.fg);
|
|
5836
|
-
this._defaultBg = parseColor(options.bg ?? this._defaultOptions.bg);
|
|
5837
|
-
this._defaultAttributes = options.attributes ?? this._defaultOptions.attributes;
|
|
5838
|
-
this.setupMeasureFunc();
|
|
5839
|
-
this.rebuildCells();
|
|
5840
|
-
}
|
|
5841
|
-
get content() {
|
|
5842
|
-
return this._content;
|
|
5843
|
-
}
|
|
5844
|
-
set content(value) {
|
|
5845
|
-
this._content = value ?? [];
|
|
5846
|
-
this.rebuildCells();
|
|
5847
|
-
}
|
|
5848
|
-
get wrapMode() {
|
|
5849
|
-
return this._wrapMode;
|
|
5850
|
-
}
|
|
5851
|
-
set wrapMode(value) {
|
|
5852
|
-
if (this._wrapMode === value)
|
|
5853
|
-
return;
|
|
5854
|
-
this._wrapMode = value;
|
|
5855
|
-
for (const row of this._cells) {
|
|
5856
|
-
for (const cell of row) {
|
|
5857
|
-
cell.textBufferView.setWrapMode(value);
|
|
5858
|
-
}
|
|
5859
|
-
}
|
|
5860
|
-
this.invalidateLayoutAndRaster();
|
|
5861
|
-
}
|
|
5862
|
-
get columnWidthMode() {
|
|
5863
|
-
return this._columnWidthMode;
|
|
5864
|
-
}
|
|
5865
|
-
set columnWidthMode(value) {
|
|
5866
|
-
if (this._columnWidthMode === value)
|
|
5867
|
-
return;
|
|
5868
|
-
this._columnWidthMode = value;
|
|
5869
|
-
this.invalidateLayoutAndRaster();
|
|
5870
|
-
}
|
|
5871
|
-
get columnFitter() {
|
|
5872
|
-
return this._columnFitter;
|
|
5873
|
-
}
|
|
5874
|
-
set columnFitter(value) {
|
|
5875
|
-
const next = this.resolveColumnFitter(value);
|
|
5876
|
-
if (this._columnFitter === next)
|
|
5877
|
-
return;
|
|
5878
|
-
this._columnFitter = next;
|
|
5879
|
-
this.invalidateLayoutAndRaster();
|
|
5880
|
-
}
|
|
5881
|
-
get cellPadding() {
|
|
5882
|
-
return this._cellPaddingX === this._cellPaddingY ? this._cellPaddingX : 0;
|
|
5883
|
-
}
|
|
5884
|
-
set cellPadding(value) {
|
|
5885
|
-
const next = this.resolveCellPadding(value);
|
|
5886
|
-
if (this._cellPaddingX === next && this._cellPaddingY === next)
|
|
5887
|
-
return;
|
|
5888
|
-
this._cellPaddingX = next;
|
|
5889
|
-
this._cellPaddingY = next;
|
|
5890
|
-
this.invalidateLayoutAndRaster();
|
|
5891
|
-
}
|
|
5892
|
-
get cellPaddingX() {
|
|
5893
|
-
return this._cellPaddingX;
|
|
5894
|
-
}
|
|
5895
|
-
set cellPaddingX(value) {
|
|
5896
|
-
const next = this.resolveCellPadding(value);
|
|
5897
|
-
if (this._cellPaddingX === next)
|
|
5898
|
-
return;
|
|
5899
|
-
this._cellPaddingX = next;
|
|
5900
|
-
this.invalidateLayoutAndRaster();
|
|
5901
|
-
}
|
|
5902
|
-
get cellPaddingY() {
|
|
5903
|
-
return this._cellPaddingY;
|
|
5904
|
-
}
|
|
5905
|
-
set cellPaddingY(value) {
|
|
5906
|
-
const next = this.resolveCellPadding(value);
|
|
5907
|
-
if (this._cellPaddingY === next)
|
|
5908
|
-
return;
|
|
5909
|
-
this._cellPaddingY = next;
|
|
5910
|
-
this.invalidateLayoutAndRaster();
|
|
5911
|
-
}
|
|
5912
|
-
get columnGap() {
|
|
5913
|
-
return this._columnGap;
|
|
5914
|
-
}
|
|
5915
|
-
set columnGap(value) {
|
|
5916
|
-
const next = this.resolveColumnGap(value);
|
|
5917
|
-
if (this._columnGap === next)
|
|
5918
|
-
return;
|
|
5919
|
-
this._columnGap = next;
|
|
5920
|
-
this.invalidateLayoutAndRaster();
|
|
5921
|
-
}
|
|
5922
|
-
get showBorders() {
|
|
5923
|
-
return this._showBorders;
|
|
5924
|
-
}
|
|
5925
|
-
set showBorders(value) {
|
|
5926
|
-
if (this._showBorders === value)
|
|
5927
|
-
return;
|
|
5928
|
-
this._showBorders = value;
|
|
5929
|
-
this.invalidateRasterOnly();
|
|
5930
|
-
}
|
|
5931
|
-
get outerBorder() {
|
|
5932
|
-
return this._outerBorder;
|
|
5933
|
-
}
|
|
5934
|
-
set outerBorder(value) {
|
|
5935
|
-
if (this._outerBorder === value)
|
|
5936
|
-
return;
|
|
5937
|
-
this._hasExplicitOuterBorder = true;
|
|
5938
|
-
this._outerBorder = value;
|
|
5939
|
-
this.invalidateLayoutAndRaster();
|
|
5940
|
-
}
|
|
5941
|
-
get border() {
|
|
5942
|
-
return this._border;
|
|
5943
|
-
}
|
|
5944
|
-
set border(value) {
|
|
5945
|
-
if (this._border === value)
|
|
5946
|
-
return;
|
|
5947
|
-
this._border = value;
|
|
5948
|
-
if (!this._hasExplicitOuterBorder) {
|
|
5949
|
-
this._outerBorder = value;
|
|
5950
|
-
}
|
|
5951
|
-
this.invalidateLayoutAndRaster();
|
|
5952
|
-
}
|
|
5953
|
-
get borderStyle() {
|
|
5954
|
-
return this._borderStyle;
|
|
5955
|
-
}
|
|
5956
|
-
set borderStyle(value) {
|
|
5957
|
-
const next = parseBorderStyle(value, this._defaultOptions.borderStyle);
|
|
5958
|
-
if (this._borderStyle === next)
|
|
5959
|
-
return;
|
|
5960
|
-
this._borderStyle = next;
|
|
5961
|
-
this.invalidateRasterOnly();
|
|
5962
|
-
}
|
|
5963
|
-
get borderColor() {
|
|
5964
|
-
return this._borderColor;
|
|
5965
|
-
}
|
|
5966
|
-
set borderColor(value) {
|
|
5967
|
-
const next = parseColor(value);
|
|
5968
|
-
if (this._borderColor === next)
|
|
5969
|
-
return;
|
|
5970
|
-
this._borderColor = next;
|
|
5971
|
-
this.invalidateRasterOnly();
|
|
5972
|
-
}
|
|
5973
|
-
shouldStartSelection(x, y) {
|
|
5974
|
-
if (!this.selectable)
|
|
5975
|
-
return false;
|
|
5976
|
-
this.ensureLayoutReady();
|
|
5977
|
-
const localX = x - this.x;
|
|
5978
|
-
const localY = y - this.y;
|
|
5979
|
-
return this.getCellAtLocalPosition(localX, localY) !== null;
|
|
5980
|
-
}
|
|
5981
|
-
onSelectionChanged(selection) {
|
|
5982
|
-
this.ensureLayoutReady();
|
|
5983
|
-
const previousLocalSelection = this._lastLocalSelection;
|
|
5984
|
-
const localSelection = convertGlobalToLocalSelection(selection, this.x, this.y);
|
|
5985
|
-
this._lastLocalSelection = localSelection;
|
|
5986
|
-
const dirtyRows = this.getDirtySelectionRowRange(previousLocalSelection, localSelection);
|
|
5987
|
-
if (!localSelection?.isActive) {
|
|
5988
|
-
this.resetCellSelections();
|
|
5989
|
-
this._lastSelectionMode = null;
|
|
5990
|
-
} else {
|
|
5991
|
-
this.applySelectionToCells(localSelection, selection?.isStart ?? false);
|
|
5992
|
-
}
|
|
5993
|
-
if (dirtyRows !== null) {
|
|
5994
|
-
this.redrawSelectionRows(dirtyRows.firstRow, dirtyRows.lastRow);
|
|
5995
|
-
}
|
|
5996
|
-
return this.hasSelection();
|
|
5997
|
-
}
|
|
5998
|
-
hasSelection() {
|
|
5999
|
-
for (const row of this._cells) {
|
|
6000
|
-
for (const cell of row) {
|
|
6001
|
-
if (cell.textBufferView.hasSelection()) {
|
|
6002
|
-
return true;
|
|
6003
|
-
}
|
|
6004
|
-
}
|
|
6005
|
-
}
|
|
6006
|
-
return false;
|
|
6007
|
-
}
|
|
6008
|
-
getSelection() {
|
|
6009
|
-
for (const row of this._cells) {
|
|
6010
|
-
for (const cell of row) {
|
|
6011
|
-
const selection = cell.textBufferView.getSelection();
|
|
6012
|
-
if (selection) {
|
|
6013
|
-
return selection;
|
|
6014
|
-
}
|
|
6015
|
-
}
|
|
6016
|
-
}
|
|
6017
|
-
return null;
|
|
6018
|
-
}
|
|
6019
|
-
getSelectedText() {
|
|
6020
|
-
const selectedRows = [];
|
|
6021
|
-
for (let rowIdx = 0;rowIdx < this._rowCount; rowIdx++) {
|
|
6022
|
-
const rowSelections = [];
|
|
6023
|
-
for (let colIdx = 0;colIdx < this._columnCount; colIdx++) {
|
|
6024
|
-
const cell = this._cells[rowIdx]?.[colIdx];
|
|
6025
|
-
if (!cell || !cell.textBufferView.hasSelection())
|
|
6026
|
-
continue;
|
|
6027
|
-
const selectedText = cell.textBufferView.getSelectedText();
|
|
6028
|
-
if (selectedText.length > 0) {
|
|
6029
|
-
rowSelections.push(selectedText);
|
|
6030
|
-
}
|
|
6031
|
-
}
|
|
6032
|
-
if (rowSelections.length > 0) {
|
|
6033
|
-
selectedRows.push(rowSelections.join("\t"));
|
|
6034
|
-
}
|
|
6035
|
-
}
|
|
6036
|
-
return selectedRows.join(`
|
|
6037
|
-
`);
|
|
6038
|
-
}
|
|
6039
|
-
onResize(width, height) {
|
|
6040
|
-
this.invalidateLayoutAndRaster(false);
|
|
6041
|
-
super.onResize(width, height);
|
|
6042
|
-
}
|
|
6043
|
-
renderSelf(buffer) {
|
|
6044
|
-
if (!this.visible || this.isDestroyed)
|
|
6045
|
-
return;
|
|
6046
|
-
if (this._layoutDirty) {
|
|
6047
|
-
this.rebuildLayoutForCurrentWidth();
|
|
6048
|
-
}
|
|
6049
|
-
if (!this._rasterDirty)
|
|
6050
|
-
return;
|
|
6051
|
-
buffer.clear(this._backgroundColor);
|
|
6052
|
-
if (this._rowCount === 0 || this._columnCount === 0) {
|
|
6053
|
-
this._rasterDirty = false;
|
|
6054
|
-
return;
|
|
6055
|
-
}
|
|
6056
|
-
this.drawBorders(buffer);
|
|
6057
|
-
this.drawCells(buffer);
|
|
6058
|
-
this._rasterDirty = false;
|
|
6059
|
-
}
|
|
6060
|
-
destroySelf() {
|
|
6061
|
-
this.destroyCells();
|
|
6062
|
-
super.destroySelf();
|
|
6063
|
-
}
|
|
6064
|
-
setupMeasureFunc() {
|
|
6065
|
-
const measureFunc = (width, widthMode, _height, _heightMode) => {
|
|
6066
|
-
const hasWidthConstraint = widthMode !== MeasureMode.Undefined && Number.isFinite(width);
|
|
6067
|
-
const rawWidthConstraint = hasWidthConstraint ? Math.max(1, Math.floor(width)) : undefined;
|
|
6068
|
-
const widthConstraint = this.resolveLayoutWidthConstraint(rawWidthConstraint);
|
|
6069
|
-
const measuredLayout = this.computeLayout(widthConstraint);
|
|
6070
|
-
this._cachedMeasureLayout = measuredLayout;
|
|
6071
|
-
this._cachedMeasureWidth = widthConstraint;
|
|
6072
|
-
let measuredWidth = measuredLayout.tableWidth > 0 ? measuredLayout.tableWidth : 1;
|
|
6073
|
-
let measuredHeight = measuredLayout.tableHeight > 0 ? measuredLayout.tableHeight : 1;
|
|
6074
|
-
if (widthMode === MeasureMode.AtMost && rawWidthConstraint !== undefined && this._positionType !== "absolute") {
|
|
6075
|
-
measuredWidth = Math.min(rawWidthConstraint, measuredWidth);
|
|
6076
|
-
}
|
|
6077
|
-
return {
|
|
6078
|
-
width: measuredWidth,
|
|
6079
|
-
height: measuredHeight
|
|
6080
|
-
};
|
|
6081
|
-
};
|
|
6082
|
-
this.yogaNode.setMeasureFunc(measureFunc);
|
|
6083
|
-
}
|
|
6084
|
-
rebuildCells() {
|
|
6085
|
-
const newRowCount = this._content.length;
|
|
6086
|
-
const newColumnCount = this._content.reduce((max, row) => Math.max(max, row.length), 0);
|
|
6087
|
-
if (this._cells.length === 0) {
|
|
6088
|
-
this._rowCount = newRowCount;
|
|
6089
|
-
this._columnCount = newColumnCount;
|
|
6090
|
-
this._cells = [];
|
|
6091
|
-
this._prevCellContent = [];
|
|
6092
|
-
for (let rowIdx = 0;rowIdx < newRowCount; rowIdx++) {
|
|
6093
|
-
const row = this._content[rowIdx] ?? [];
|
|
6094
|
-
const rowCells = [];
|
|
6095
|
-
const rowRefs = [];
|
|
6096
|
-
for (let colIdx = 0;colIdx < newColumnCount; colIdx++) {
|
|
6097
|
-
const cellContent = row[colIdx];
|
|
6098
|
-
rowCells.push(this.createCell(cellContent));
|
|
6099
|
-
rowRefs.push(cellContent);
|
|
6100
|
-
}
|
|
6101
|
-
this._cells.push(rowCells);
|
|
6102
|
-
this._prevCellContent.push(rowRefs);
|
|
6103
|
-
}
|
|
6104
|
-
this.invalidateLayoutAndRaster();
|
|
6105
|
-
return;
|
|
6106
|
-
}
|
|
6107
|
-
this.updateCellsDiff(newRowCount, newColumnCount);
|
|
6108
|
-
this.invalidateLayoutAndRaster();
|
|
6109
|
-
}
|
|
6110
|
-
updateCellsDiff(newRowCount, newColumnCount) {
|
|
6111
|
-
const oldRowCount = this._rowCount;
|
|
6112
|
-
const oldColumnCount = this._columnCount;
|
|
6113
|
-
const keepRows = Math.min(oldRowCount, newRowCount);
|
|
6114
|
-
const keepCols = Math.min(oldColumnCount, newColumnCount);
|
|
6115
|
-
for (let rowIdx = 0;rowIdx < keepRows; rowIdx++) {
|
|
6116
|
-
const newRow = this._content[rowIdx] ?? [];
|
|
6117
|
-
const cellRow = this._cells[rowIdx];
|
|
6118
|
-
const refRow = this._prevCellContent[rowIdx];
|
|
6119
|
-
for (let colIdx = 0;colIdx < keepCols; colIdx++) {
|
|
6120
|
-
const cellContent = newRow[colIdx];
|
|
6121
|
-
if (cellContent === refRow[colIdx])
|
|
6122
|
-
continue;
|
|
6123
|
-
const oldCell = cellRow[colIdx];
|
|
6124
|
-
oldCell.textBufferView.destroy();
|
|
6125
|
-
oldCell.textBuffer.destroy();
|
|
6126
|
-
oldCell.syntaxStyle.destroy();
|
|
6127
|
-
cellRow[colIdx] = this.createCell(cellContent);
|
|
6128
|
-
refRow[colIdx] = cellContent;
|
|
6129
|
-
}
|
|
6130
|
-
if (newColumnCount > oldColumnCount) {
|
|
6131
|
-
for (let colIdx = oldColumnCount;colIdx < newColumnCount; colIdx++) {
|
|
6132
|
-
const cellContent = newRow[colIdx];
|
|
6133
|
-
cellRow.push(this.createCell(cellContent));
|
|
6134
|
-
refRow.push(cellContent);
|
|
6135
|
-
}
|
|
6136
|
-
} else if (newColumnCount < oldColumnCount) {
|
|
6137
|
-
for (let colIdx = newColumnCount;colIdx < oldColumnCount; colIdx++) {
|
|
6138
|
-
const cell = cellRow[colIdx];
|
|
6139
|
-
cell.textBufferView.destroy();
|
|
6140
|
-
cell.textBuffer.destroy();
|
|
6141
|
-
cell.syntaxStyle.destroy();
|
|
6142
|
-
}
|
|
6143
|
-
cellRow.length = newColumnCount;
|
|
6144
|
-
refRow.length = newColumnCount;
|
|
6145
|
-
}
|
|
6146
|
-
}
|
|
6147
|
-
if (newRowCount > oldRowCount) {
|
|
6148
|
-
for (let rowIdx = oldRowCount;rowIdx < newRowCount; rowIdx++) {
|
|
6149
|
-
const newRow = this._content[rowIdx] ?? [];
|
|
6150
|
-
const rowCells = [];
|
|
6151
|
-
const rowRefs = [];
|
|
6152
|
-
for (let colIdx = 0;colIdx < newColumnCount; colIdx++) {
|
|
6153
|
-
const cellContent = newRow[colIdx];
|
|
6154
|
-
rowCells.push(this.createCell(cellContent));
|
|
6155
|
-
rowRefs.push(cellContent);
|
|
6156
|
-
}
|
|
6157
|
-
this._cells.push(rowCells);
|
|
6158
|
-
this._prevCellContent.push(rowRefs);
|
|
6159
|
-
}
|
|
6160
|
-
} else if (newRowCount < oldRowCount) {
|
|
6161
|
-
for (let rowIdx = newRowCount;rowIdx < oldRowCount; rowIdx++) {
|
|
6162
|
-
const row = this._cells[rowIdx];
|
|
6163
|
-
for (const cell of row) {
|
|
6164
|
-
cell.textBufferView.destroy();
|
|
6165
|
-
cell.textBuffer.destroy();
|
|
6166
|
-
cell.syntaxStyle.destroy();
|
|
6167
|
-
}
|
|
6168
|
-
}
|
|
6169
|
-
this._cells.length = newRowCount;
|
|
6170
|
-
this._prevCellContent.length = newRowCount;
|
|
6171
|
-
}
|
|
6172
|
-
this._rowCount = newRowCount;
|
|
6173
|
-
this._columnCount = newColumnCount;
|
|
6174
|
-
}
|
|
6175
|
-
createCell(content) {
|
|
6176
|
-
const styledText = this.toStyledText(content);
|
|
6177
|
-
const textBuffer = TextBuffer.create(this._ctx.widthMethod);
|
|
6178
|
-
const syntaxStyle = SyntaxStyle.create();
|
|
6179
|
-
textBuffer.setDefaultFg(this._defaultFg);
|
|
6180
|
-
textBuffer.setDefaultBg(this._defaultBg);
|
|
6181
|
-
textBuffer.setDefaultAttributes(this._defaultAttributes);
|
|
6182
|
-
textBuffer.setSyntaxStyle(syntaxStyle);
|
|
6183
|
-
textBuffer.setStyledText(styledText);
|
|
6184
|
-
const textBufferView = TextBufferView.create(textBuffer);
|
|
6185
|
-
textBufferView.setWrapMode(this._wrapMode);
|
|
6186
|
-
return { textBuffer, textBufferView, syntaxStyle };
|
|
6187
|
-
}
|
|
6188
|
-
toStyledText(content) {
|
|
6189
|
-
if (Array.isArray(content)) {
|
|
6190
|
-
return new StyledText(content);
|
|
6191
|
-
}
|
|
6192
|
-
if (content === null || content === undefined) {
|
|
6193
|
-
return stringToStyledText("");
|
|
6194
|
-
}
|
|
6195
|
-
return stringToStyledText(String(content));
|
|
6196
|
-
}
|
|
6197
|
-
destroyCells() {
|
|
6198
|
-
for (const row of this._cells) {
|
|
6199
|
-
for (const cell of row) {
|
|
6200
|
-
cell.textBufferView.destroy();
|
|
6201
|
-
cell.textBuffer.destroy();
|
|
6202
|
-
cell.syntaxStyle.destroy();
|
|
6203
|
-
}
|
|
6204
|
-
}
|
|
6205
|
-
this._cells = [];
|
|
6206
|
-
this._prevCellContent = [];
|
|
6207
|
-
this._rowCount = 0;
|
|
6208
|
-
this._columnCount = 0;
|
|
6209
|
-
this._layout = this.createEmptyLayout();
|
|
6210
|
-
}
|
|
6211
|
-
rebuildLayoutForCurrentWidth() {
|
|
6212
|
-
const maxTableWidth = this.resolveLayoutWidthConstraint(this.width);
|
|
6213
|
-
let layout;
|
|
6214
|
-
if (this._cachedMeasureLayout !== null && this._cachedMeasureWidth === maxTableWidth) {
|
|
6215
|
-
layout = this._cachedMeasureLayout;
|
|
6216
|
-
} else {
|
|
6217
|
-
layout = this.computeLayout(maxTableWidth);
|
|
6218
|
-
}
|
|
6219
|
-
this._cachedMeasureLayout = null;
|
|
6220
|
-
this._cachedMeasureWidth = undefined;
|
|
6221
|
-
this._layout = layout;
|
|
6222
|
-
this.applyLayoutToViews(layout);
|
|
6223
|
-
this._layoutDirty = false;
|
|
6224
|
-
if (this._lastLocalSelection?.isActive) {
|
|
6225
|
-
this.applySelectionToCells(this._lastLocalSelection, true);
|
|
6226
|
-
}
|
|
6227
|
-
}
|
|
6228
|
-
computeLayout(maxTableWidth) {
|
|
6229
|
-
if (this._rowCount === 0 || this._columnCount === 0) {
|
|
6230
|
-
return this.createEmptyLayout();
|
|
6231
|
-
}
|
|
6232
|
-
const borderLayout = this.resolveBorderLayout();
|
|
6233
|
-
const columnWidths = this.computeColumnWidths(maxTableWidth, borderLayout);
|
|
6234
|
-
const rowHeights = this.computeRowHeights(columnWidths);
|
|
6235
|
-
const columnOffsets = this.computeOffsets(columnWidths, borderLayout.left, borderLayout.right, borderLayout.innerVertical, this.getInterColumnGap(borderLayout));
|
|
6236
|
-
const rowOffsets = this.computeOffsets(rowHeights, borderLayout.top, borderLayout.bottom, borderLayout.innerHorizontal);
|
|
6237
|
-
return {
|
|
6238
|
-
columnWidths,
|
|
6239
|
-
rowHeights,
|
|
6240
|
-
columnOffsets,
|
|
6241
|
-
rowOffsets,
|
|
6242
|
-
columnOffsetsI32: new Int32Array(columnOffsets),
|
|
6243
|
-
rowOffsetsI32: new Int32Array(rowOffsets),
|
|
6244
|
-
tableWidth: (columnOffsets[columnOffsets.length - 1] ?? 0) + 1,
|
|
6245
|
-
tableHeight: (rowOffsets[rowOffsets.length - 1] ?? 0) + 1
|
|
6246
|
-
};
|
|
6247
|
-
}
|
|
6248
|
-
isFullWidthMode() {
|
|
6249
|
-
return this._columnWidthMode === "full";
|
|
6250
|
-
}
|
|
6251
|
-
computeColumnWidths(maxTableWidth, borderLayout) {
|
|
6252
|
-
const horizontalPadding = this.getHorizontalCellPadding();
|
|
6253
|
-
const intrinsicWidths = new Array(this._columnCount).fill(1 + horizontalPadding);
|
|
6254
|
-
for (let rowIdx = 0;rowIdx < this._rowCount; rowIdx++) {
|
|
6255
|
-
for (let colIdx = 0;colIdx < this._columnCount; colIdx++) {
|
|
6256
|
-
const cell = this._cells[rowIdx]?.[colIdx];
|
|
6257
|
-
if (!cell)
|
|
6258
|
-
continue;
|
|
6259
|
-
const measure = cell.textBufferView.measureForDimensions(0, MEASURE_HEIGHT);
|
|
6260
|
-
const measuredWidth = Math.max(1, measure?.widthColsMax ?? 0) + horizontalPadding;
|
|
6261
|
-
intrinsicWidths[colIdx] = Math.max(intrinsicWidths[colIdx], measuredWidth);
|
|
6262
|
-
}
|
|
6263
|
-
}
|
|
6264
|
-
if (maxTableWidth === undefined || !Number.isFinite(maxTableWidth) || maxTableWidth <= 0) {
|
|
6265
|
-
return intrinsicWidths;
|
|
6266
|
-
}
|
|
6267
|
-
const maxContentWidth = Math.max(1, Math.floor(maxTableWidth) - this.getVerticalBorderCount(borderLayout) - this.getTotalInterColumnGap(borderLayout));
|
|
6268
|
-
const currentWidth = intrinsicWidths.reduce((sum, width) => sum + width, 0);
|
|
6269
|
-
if (currentWidth === maxContentWidth) {
|
|
6270
|
-
return intrinsicWidths;
|
|
6271
|
-
}
|
|
6272
|
-
if (currentWidth < maxContentWidth) {
|
|
6273
|
-
if (this.isFullWidthMode()) {
|
|
6274
|
-
return this.expandColumnWidths(intrinsicWidths, maxContentWidth);
|
|
6275
|
-
}
|
|
6276
|
-
return intrinsicWidths;
|
|
6277
|
-
}
|
|
6278
|
-
if (this._wrapMode === "none") {
|
|
6279
|
-
return intrinsicWidths;
|
|
6280
|
-
}
|
|
6281
|
-
return this.fitColumnWidths(intrinsicWidths, maxContentWidth);
|
|
6282
|
-
}
|
|
6283
|
-
expandColumnWidths(widths, targetContentWidth) {
|
|
6284
|
-
const baseWidths = widths.map((width) => Math.max(1, Math.floor(width)));
|
|
6285
|
-
const totalBaseWidth = baseWidths.reduce((sum, width) => sum + width, 0);
|
|
6286
|
-
if (totalBaseWidth >= targetContentWidth) {
|
|
6287
|
-
return baseWidths;
|
|
6288
|
-
}
|
|
6289
|
-
const expanded = [...baseWidths];
|
|
6290
|
-
const columns = expanded.length;
|
|
6291
|
-
const extraWidth = targetContentWidth - totalBaseWidth;
|
|
6292
|
-
const sharedWidth = Math.floor(extraWidth / columns);
|
|
6293
|
-
const remainder = extraWidth % columns;
|
|
6294
|
-
for (let idx = 0;idx < columns; idx++) {
|
|
6295
|
-
expanded[idx] += sharedWidth;
|
|
6296
|
-
if (idx < remainder) {
|
|
6297
|
-
expanded[idx] += 1;
|
|
6298
|
-
}
|
|
6299
|
-
}
|
|
6300
|
-
return expanded;
|
|
6301
|
-
}
|
|
6302
|
-
fitColumnWidths(widths, targetContentWidth) {
|
|
6303
|
-
if (this._columnFitter === "balanced") {
|
|
6304
|
-
return this.fitColumnWidthsBalanced(widths, targetContentWidth);
|
|
6305
|
-
}
|
|
6306
|
-
return this.fitColumnWidthsProportional(widths, targetContentWidth);
|
|
6307
|
-
}
|
|
6308
|
-
fitColumnWidthsProportional(widths, targetContentWidth) {
|
|
6309
|
-
const minWidth = 1 + this.getHorizontalCellPadding();
|
|
6310
|
-
const hardMinWidths = new Array(widths.length).fill(minWidth);
|
|
6311
|
-
const baseWidths = widths.map((width) => Math.max(1, Math.floor(width)));
|
|
6312
|
-
const preferredMinWidths = baseWidths.map((width) => Math.min(width, minWidth + 1));
|
|
6313
|
-
const preferredMinTotal = preferredMinWidths.reduce((sum, width) => sum + width, 0);
|
|
6314
|
-
const floorWidths = preferredMinTotal <= targetContentWidth ? preferredMinWidths : hardMinWidths;
|
|
6315
|
-
const floorTotal = floorWidths.reduce((sum, width) => sum + width, 0);
|
|
6316
|
-
const clampedTarget = Math.max(floorTotal, targetContentWidth);
|
|
6317
|
-
const totalBaseWidth = baseWidths.reduce((sum, width) => sum + width, 0);
|
|
6318
|
-
if (totalBaseWidth <= clampedTarget) {
|
|
6319
|
-
return baseWidths;
|
|
6320
|
-
}
|
|
6321
|
-
const shrinkable = baseWidths.map((width, idx) => width - floorWidths[idx]);
|
|
6322
|
-
const totalShrinkable = shrinkable.reduce((sum, value) => sum + value, 0);
|
|
6323
|
-
if (totalShrinkable <= 0) {
|
|
6324
|
-
return [...floorWidths];
|
|
6325
|
-
}
|
|
6326
|
-
const targetShrink = totalBaseWidth - clampedTarget;
|
|
6327
|
-
const integerShrink = new Array(baseWidths.length).fill(0);
|
|
6328
|
-
const fractions = new Array(baseWidths.length).fill(0);
|
|
6329
|
-
let usedShrink = 0;
|
|
6330
|
-
for (let idx = 0;idx < baseWidths.length; idx++) {
|
|
6331
|
-
if (shrinkable[idx] <= 0)
|
|
6332
|
-
continue;
|
|
6333
|
-
const exact = shrinkable[idx] / totalShrinkable * targetShrink;
|
|
6334
|
-
const whole = Math.min(shrinkable[idx], Math.floor(exact));
|
|
6335
|
-
integerShrink[idx] = whole;
|
|
6336
|
-
fractions[idx] = exact - whole;
|
|
6337
|
-
usedShrink += whole;
|
|
6338
|
-
}
|
|
6339
|
-
let remainingShrink = targetShrink - usedShrink;
|
|
6340
|
-
while (remainingShrink > 0) {
|
|
6341
|
-
let bestIdx = -1;
|
|
6342
|
-
let bestFraction = -1;
|
|
6343
|
-
for (let idx = 0;idx < baseWidths.length; idx++) {
|
|
6344
|
-
if (shrinkable[idx] - integerShrink[idx] <= 0)
|
|
6345
|
-
continue;
|
|
6346
|
-
if (fractions[idx] > bestFraction) {
|
|
6347
|
-
bestFraction = fractions[idx];
|
|
6348
|
-
bestIdx = idx;
|
|
6349
|
-
}
|
|
6350
|
-
}
|
|
6351
|
-
if (bestIdx === -1)
|
|
6352
|
-
break;
|
|
6353
|
-
integerShrink[bestIdx] += 1;
|
|
6354
|
-
fractions[bestIdx] = 0;
|
|
6355
|
-
remainingShrink -= 1;
|
|
6356
|
-
}
|
|
6357
|
-
return baseWidths.map((width, idx) => Math.max(floorWidths[idx], width - integerShrink[idx]));
|
|
6358
|
-
}
|
|
6359
|
-
fitColumnWidthsBalanced(widths, targetContentWidth) {
|
|
6360
|
-
const minWidth = 1 + this.getHorizontalCellPadding();
|
|
6361
|
-
const hardMinWidths = new Array(widths.length).fill(minWidth);
|
|
6362
|
-
const baseWidths = widths.map((width) => Math.max(1, Math.floor(width)));
|
|
6363
|
-
const totalBaseWidth = baseWidths.reduce((sum, width) => sum + width, 0);
|
|
6364
|
-
const columns = baseWidths.length;
|
|
6365
|
-
if (columns === 0 || totalBaseWidth <= targetContentWidth) {
|
|
6366
|
-
return baseWidths;
|
|
6367
|
-
}
|
|
6368
|
-
const evenShare = Math.max(minWidth, Math.floor(targetContentWidth / columns));
|
|
6369
|
-
const preferredMinWidths = baseWidths.map((width) => Math.min(width, evenShare));
|
|
6370
|
-
const preferredMinTotal = preferredMinWidths.reduce((sum, width) => sum + width, 0);
|
|
6371
|
-
const floorWidths = preferredMinTotal <= targetContentWidth ? preferredMinWidths : hardMinWidths;
|
|
6372
|
-
const floorTotal = floorWidths.reduce((sum, width) => sum + width, 0);
|
|
6373
|
-
const clampedTarget = Math.max(floorTotal, targetContentWidth);
|
|
6374
|
-
if (totalBaseWidth <= clampedTarget) {
|
|
6375
|
-
return baseWidths;
|
|
6376
|
-
}
|
|
6377
|
-
const shrinkable = baseWidths.map((width, idx) => width - floorWidths[idx]);
|
|
6378
|
-
const totalShrinkable = shrinkable.reduce((sum, value) => sum + value, 0);
|
|
6379
|
-
if (totalShrinkable <= 0) {
|
|
6380
|
-
return [...floorWidths];
|
|
6381
|
-
}
|
|
6382
|
-
const targetShrink = totalBaseWidth - clampedTarget;
|
|
6383
|
-
const shrink = this.allocateShrinkByWeight(shrinkable, targetShrink, "sqrt");
|
|
6384
|
-
return baseWidths.map((width, idx) => Math.max(floorWidths[idx], width - shrink[idx]));
|
|
6385
|
-
}
|
|
6386
|
-
allocateShrinkByWeight(shrinkable, targetShrink, mode) {
|
|
6387
|
-
const shrink = new Array(shrinkable.length).fill(0);
|
|
6388
|
-
if (targetShrink <= 0) {
|
|
6389
|
-
return shrink;
|
|
6390
|
-
}
|
|
6391
|
-
const weights = shrinkable.map((value) => {
|
|
6392
|
-
if (value <= 0) {
|
|
6393
|
-
return 0;
|
|
6394
|
-
}
|
|
6395
|
-
return mode === "sqrt" ? Math.sqrt(value) : value;
|
|
6396
|
-
});
|
|
6397
|
-
const totalWeight = weights.reduce((sum, value) => sum + value, 0);
|
|
6398
|
-
if (totalWeight <= 0) {
|
|
6399
|
-
return shrink;
|
|
6400
|
-
}
|
|
6401
|
-
const fractions = new Array(shrinkable.length).fill(0);
|
|
6402
|
-
let usedShrink = 0;
|
|
6403
|
-
for (let idx = 0;idx < shrinkable.length; idx++) {
|
|
6404
|
-
if (shrinkable[idx] <= 0 || weights[idx] <= 0)
|
|
6405
|
-
continue;
|
|
6406
|
-
const exact = weights[idx] / totalWeight * targetShrink;
|
|
6407
|
-
const whole = Math.min(shrinkable[idx], Math.floor(exact));
|
|
6408
|
-
shrink[idx] = whole;
|
|
6409
|
-
fractions[idx] = exact - whole;
|
|
6410
|
-
usedShrink += whole;
|
|
6411
|
-
}
|
|
6412
|
-
let remainingShrink = targetShrink - usedShrink;
|
|
6413
|
-
while (remainingShrink > 0) {
|
|
6414
|
-
let bestIdx = -1;
|
|
6415
|
-
let bestFraction = -1;
|
|
6416
|
-
for (let idx = 0;idx < shrinkable.length; idx++) {
|
|
6417
|
-
if (shrinkable[idx] - shrink[idx] <= 0)
|
|
6418
|
-
continue;
|
|
6419
|
-
if (bestIdx === -1 || fractions[idx] > bestFraction || fractions[idx] === bestFraction && shrinkable[idx] > shrinkable[bestIdx]) {
|
|
6420
|
-
bestIdx = idx;
|
|
6421
|
-
bestFraction = fractions[idx];
|
|
6422
|
-
}
|
|
6423
|
-
}
|
|
6424
|
-
if (bestIdx === -1) {
|
|
6425
|
-
break;
|
|
6426
|
-
}
|
|
6427
|
-
shrink[bestIdx] += 1;
|
|
6428
|
-
fractions[bestIdx] = 0;
|
|
6429
|
-
remainingShrink -= 1;
|
|
6430
|
-
}
|
|
6431
|
-
return shrink;
|
|
6432
|
-
}
|
|
6433
|
-
computeRowHeights(columnWidths) {
|
|
6434
|
-
const horizontalPadding = this.getHorizontalCellPadding();
|
|
6435
|
-
const verticalPadding = this.getVerticalCellPadding();
|
|
6436
|
-
const rowHeights = new Array(this._rowCount).fill(1 + verticalPadding);
|
|
6437
|
-
for (let rowIdx = 0;rowIdx < this._rowCount; rowIdx++) {
|
|
6438
|
-
for (let colIdx = 0;colIdx < this._columnCount; colIdx++) {
|
|
6439
|
-
const cell = this._cells[rowIdx]?.[colIdx];
|
|
6440
|
-
if (!cell)
|
|
6441
|
-
continue;
|
|
6442
|
-
const width = Math.max(1, (columnWidths[colIdx] ?? 1) - horizontalPadding);
|
|
6443
|
-
const measure = cell.textBufferView.measureForDimensions(width, MEASURE_HEIGHT);
|
|
6444
|
-
const lineCount = Math.max(1, measure?.lineCount ?? 1);
|
|
6445
|
-
rowHeights[rowIdx] = Math.max(rowHeights[rowIdx], lineCount + verticalPadding);
|
|
6446
|
-
}
|
|
6447
|
-
}
|
|
6448
|
-
return rowHeights;
|
|
6449
|
-
}
|
|
6450
|
-
computeOffsets(parts, startBoundary, endBoundary, includeInnerBoundaries, innerGap = 0) {
|
|
6451
|
-
const offsets = [startBoundary ? 0 : -1];
|
|
6452
|
-
let cursor = offsets[0] ?? 0;
|
|
6453
|
-
for (let idx = 0;idx < parts.length; idx++) {
|
|
6454
|
-
const size = parts[idx] ?? 1;
|
|
6455
|
-
const separatorAfter = idx < parts.length - 1 ? includeInnerBoundaries ? 1 : innerGap : endBoundary ? 1 : 0;
|
|
6456
|
-
cursor += size + separatorAfter;
|
|
6457
|
-
offsets.push(cursor);
|
|
6458
|
-
}
|
|
6459
|
-
return offsets;
|
|
6460
|
-
}
|
|
6461
|
-
getInterColumnGap(borderLayout) {
|
|
6462
|
-
if (borderLayout.innerVertical) {
|
|
6463
|
-
return 0;
|
|
6464
|
-
}
|
|
6465
|
-
return this._columnGap;
|
|
6466
|
-
}
|
|
6467
|
-
getTotalInterColumnGap(borderLayout) {
|
|
6468
|
-
return Math.max(0, this._columnCount - 1) * this.getInterColumnGap(borderLayout);
|
|
6469
|
-
}
|
|
6470
|
-
applyLayoutToViews(layout) {
|
|
6471
|
-
const horizontalPadding = this.getHorizontalCellPadding();
|
|
6472
|
-
const verticalPadding = this.getVerticalCellPadding();
|
|
6473
|
-
for (let rowIdx = 0;rowIdx < this._rowCount; rowIdx++) {
|
|
6474
|
-
for (let colIdx = 0;colIdx < this._columnCount; colIdx++) {
|
|
6475
|
-
const cell = this._cells[rowIdx]?.[colIdx];
|
|
6476
|
-
if (!cell)
|
|
6477
|
-
continue;
|
|
6478
|
-
const colWidth = layout.columnWidths[colIdx] ?? 1;
|
|
6479
|
-
const rowHeight = layout.rowHeights[rowIdx] ?? 1;
|
|
6480
|
-
const contentWidth = Math.max(1, colWidth - horizontalPadding);
|
|
6481
|
-
const contentHeight = Math.max(1, rowHeight - verticalPadding);
|
|
6482
|
-
if (this._wrapMode === "none") {
|
|
6483
|
-
cell.textBufferView.setWrapWidth(null);
|
|
6484
|
-
} else {
|
|
6485
|
-
cell.textBufferView.setWrapWidth(contentWidth);
|
|
6486
|
-
}
|
|
6487
|
-
cell.textBufferView.setViewport(0, 0, contentWidth, contentHeight);
|
|
6488
|
-
}
|
|
6489
|
-
}
|
|
6490
|
-
}
|
|
6491
|
-
resolveBorderLayout() {
|
|
6492
|
-
return {
|
|
6493
|
-
left: this._outerBorder,
|
|
6494
|
-
right: this._outerBorder,
|
|
6495
|
-
top: this._outerBorder,
|
|
6496
|
-
bottom: this._outerBorder,
|
|
6497
|
-
innerVertical: this._border && this._columnCount > 1,
|
|
6498
|
-
innerHorizontal: this._border && this._rowCount > 1
|
|
6499
|
-
};
|
|
6500
|
-
}
|
|
6501
|
-
getVerticalBorderCount(borderLayout) {
|
|
6502
|
-
return (borderLayout.left ? 1 : 0) + (borderLayout.right ? 1 : 0) + (borderLayout.innerVertical ? Math.max(0, this._columnCount - 1) : 0);
|
|
6503
|
-
}
|
|
6504
|
-
getHorizontalBorderCount(borderLayout) {
|
|
6505
|
-
return (borderLayout.top ? 1 : 0) + (borderLayout.bottom ? 1 : 0) + (borderLayout.innerHorizontal ? Math.max(0, this._rowCount - 1) : 0);
|
|
6506
|
-
}
|
|
6507
|
-
drawBorders(buffer) {
|
|
6508
|
-
if (!this._showBorders) {
|
|
6509
|
-
return;
|
|
6510
|
-
}
|
|
6511
|
-
const borderLayout = this.resolveBorderLayout();
|
|
6512
|
-
if (this.getVerticalBorderCount(borderLayout) === 0 && this.getHorizontalBorderCount(borderLayout) === 0) {
|
|
6513
|
-
return;
|
|
6514
|
-
}
|
|
6515
|
-
buffer.drawGrid({
|
|
6516
|
-
borderChars: BorderCharArrays[this._borderStyle],
|
|
6517
|
-
borderFg: this._borderColor,
|
|
6518
|
-
borderBg: this._borderBackgroundColor,
|
|
6519
|
-
columnOffsets: this._layout.columnOffsetsI32,
|
|
6520
|
-
rowOffsets: this._layout.rowOffsetsI32,
|
|
6521
|
-
drawInner: this._border,
|
|
6522
|
-
drawOuter: this._outerBorder
|
|
6523
|
-
});
|
|
6524
|
-
}
|
|
6525
|
-
drawCells(buffer) {
|
|
6526
|
-
this.drawCellRange(buffer, 0, this._rowCount - 1);
|
|
6527
|
-
}
|
|
6528
|
-
drawCellRange(buffer, firstRow, lastRow) {
|
|
6529
|
-
const colOffsets = this._layout.columnOffsets;
|
|
6530
|
-
const rowOffsets = this._layout.rowOffsets;
|
|
6531
|
-
const cellPaddingX = this._cellPaddingX;
|
|
6532
|
-
const cellPaddingY = this._cellPaddingY;
|
|
6533
|
-
for (let rowIdx = firstRow;rowIdx <= lastRow; rowIdx++) {
|
|
6534
|
-
const cellY = (rowOffsets[rowIdx] ?? 0) + 1 + cellPaddingY;
|
|
6535
|
-
for (let colIdx = 0;colIdx < this._columnCount; colIdx++) {
|
|
6536
|
-
const cell = this._cells[rowIdx]?.[colIdx];
|
|
6537
|
-
if (!cell)
|
|
6538
|
-
continue;
|
|
6539
|
-
buffer.drawTextBuffer(cell.textBufferView, (colOffsets[colIdx] ?? 0) + 1 + cellPaddingX, cellY);
|
|
6540
|
-
}
|
|
6541
|
-
}
|
|
6542
|
-
}
|
|
6543
|
-
redrawSelectionRows(firstRow, lastRow) {
|
|
6544
|
-
if (firstRow > lastRow)
|
|
6545
|
-
return;
|
|
6546
|
-
if (this._backgroundColor.a < 1) {
|
|
6547
|
-
this.invalidateRasterOnly();
|
|
6548
|
-
return;
|
|
6549
|
-
}
|
|
6550
|
-
const buffer = this.frameBuffer;
|
|
6551
|
-
if (!buffer)
|
|
6552
|
-
return;
|
|
6553
|
-
this.clearCellRange(buffer, firstRow, lastRow);
|
|
6554
|
-
this.drawCellRange(buffer, firstRow, lastRow);
|
|
6555
|
-
this.requestRender();
|
|
6556
|
-
}
|
|
6557
|
-
clearCellRange(buffer, firstRow, lastRow) {
|
|
6558
|
-
const colWidths = this._layout.columnWidths;
|
|
6559
|
-
const rowHeights = this._layout.rowHeights;
|
|
6560
|
-
const colOffsets = this._layout.columnOffsets;
|
|
6561
|
-
const rowOffsets = this._layout.rowOffsets;
|
|
6562
|
-
for (let rowIdx = firstRow;rowIdx <= lastRow; rowIdx++) {
|
|
6563
|
-
const cellY = (rowOffsets[rowIdx] ?? 0) + 1;
|
|
6564
|
-
const rowHeight = rowHeights[rowIdx] ?? 1;
|
|
6565
|
-
for (let colIdx = 0;colIdx < this._columnCount; colIdx++) {
|
|
6566
|
-
const cellX = (colOffsets[colIdx] ?? 0) + 1;
|
|
6567
|
-
const colWidth = colWidths[colIdx] ?? 1;
|
|
6568
|
-
if (this._backgroundColor.a < 1) {
|
|
6569
|
-
for (let y = cellY;y < cellY + rowHeight; y++) {
|
|
6570
|
-
for (let x = cellX;x < cellX + colWidth; x++) {
|
|
6571
|
-
buffer.setCell(x, y, " ", this._defaultFg, this._backgroundColor, this._defaultAttributes);
|
|
6572
|
-
}
|
|
6573
|
-
}
|
|
6574
|
-
} else {
|
|
6575
|
-
buffer.fillRect(cellX, cellY, colWidth, rowHeight, this._backgroundColor);
|
|
6576
|
-
}
|
|
6577
|
-
}
|
|
6578
|
-
}
|
|
6579
|
-
}
|
|
6580
|
-
ensureLayoutReady() {
|
|
6581
|
-
if (!this._layoutDirty)
|
|
6582
|
-
return;
|
|
6583
|
-
this.rebuildLayoutForCurrentWidth();
|
|
6584
|
-
}
|
|
6585
|
-
getCellAtLocalPosition(localX, localY) {
|
|
6586
|
-
if (this._rowCount === 0 || this._columnCount === 0)
|
|
6587
|
-
return null;
|
|
6588
|
-
if (localX < 0 || localY < 0 || localX >= this._layout.tableWidth || localY >= this._layout.tableHeight) {
|
|
6589
|
-
return null;
|
|
6590
|
-
}
|
|
6591
|
-
let rowIdx = -1;
|
|
6592
|
-
for (let idx = 0;idx < this._rowCount; idx++) {
|
|
6593
|
-
const top = (this._layout.rowOffsets[idx] ?? 0) + 1;
|
|
6594
|
-
const bottom = top + (this._layout.rowHeights[idx] ?? 1) - 1;
|
|
6595
|
-
if (localY >= top && localY <= bottom) {
|
|
6596
|
-
rowIdx = idx;
|
|
6597
|
-
break;
|
|
6598
|
-
}
|
|
6599
|
-
}
|
|
6600
|
-
if (rowIdx < 0)
|
|
6601
|
-
return null;
|
|
6602
|
-
let colIdx = -1;
|
|
6603
|
-
for (let idx = 0;idx < this._columnCount; idx++) {
|
|
6604
|
-
const left = (this._layout.columnOffsets[idx] ?? 0) + 1;
|
|
6605
|
-
const right = left + (this._layout.columnWidths[idx] ?? 1) - 1;
|
|
6606
|
-
if (localX >= left && localX <= right) {
|
|
6607
|
-
colIdx = idx;
|
|
6608
|
-
break;
|
|
6609
|
-
}
|
|
6610
|
-
}
|
|
6611
|
-
if (colIdx < 0)
|
|
6612
|
-
return null;
|
|
6613
|
-
return { rowIdx, colIdx };
|
|
6614
|
-
}
|
|
6615
|
-
applySelectionToCells(localSelection, isStart) {
|
|
6616
|
-
if (localSelection.anchorX === localSelection.focusX && localSelection.anchorY === localSelection.focusY) {
|
|
6617
|
-
this.resetCellSelections();
|
|
6618
|
-
this._lastSelectionMode = null;
|
|
6619
|
-
return;
|
|
6620
|
-
}
|
|
6621
|
-
const minSelY = Math.min(localSelection.anchorY, localSelection.focusY);
|
|
6622
|
-
const maxSelY = Math.max(localSelection.anchorY, localSelection.focusY);
|
|
6623
|
-
const firstRow = this.findRowForLocalY(minSelY);
|
|
6624
|
-
const lastRow = this.findRowForLocalY(maxSelY);
|
|
6625
|
-
const selection = this.resolveSelectionResolution(localSelection);
|
|
6626
|
-
const modeChanged = this._lastSelectionMode !== selection.mode;
|
|
6627
|
-
this._lastSelectionMode = selection.mode;
|
|
6628
|
-
const lockToAnchorColumn = selection.mode === "column-locked" && selection.anchorColumn !== null;
|
|
6629
|
-
for (let rowIdx = 0;rowIdx < this._rowCount; rowIdx++) {
|
|
6630
|
-
if (rowIdx < firstRow || rowIdx > lastRow) {
|
|
6631
|
-
this.resetRowSelection(rowIdx);
|
|
6632
|
-
continue;
|
|
6633
|
-
}
|
|
6634
|
-
const cellTop = (this._layout.rowOffsets[rowIdx] ?? 0) + 1 + this._cellPaddingY;
|
|
6635
|
-
for (let colIdx = 0;colIdx < this._columnCount; colIdx++) {
|
|
6636
|
-
const cell = this._cells[rowIdx]?.[colIdx];
|
|
6637
|
-
if (!cell)
|
|
6638
|
-
continue;
|
|
6639
|
-
if (lockToAnchorColumn && colIdx !== selection.anchorColumn) {
|
|
6640
|
-
cell.textBufferView.resetLocalSelection();
|
|
6641
|
-
continue;
|
|
6642
|
-
}
|
|
6643
|
-
const cellLeft = (this._layout.columnOffsets[colIdx] ?? 0) + 1 + this._cellPaddingX;
|
|
6644
|
-
let coords = {
|
|
6645
|
-
anchorX: localSelection.anchorX - cellLeft,
|
|
6646
|
-
anchorY: localSelection.anchorY - cellTop,
|
|
6647
|
-
focusX: localSelection.focusX - cellLeft,
|
|
6648
|
-
focusY: localSelection.focusY - cellTop
|
|
6649
|
-
};
|
|
6650
|
-
const isAnchorCell = selection.anchorCell !== null && selection.anchorCell.rowIdx === rowIdx && selection.anchorCell.colIdx === colIdx;
|
|
6651
|
-
if (selection.mode === "single-cell" && !isAnchorCell) {
|
|
6652
|
-
cell.textBufferView.resetLocalSelection();
|
|
6653
|
-
continue;
|
|
6654
|
-
}
|
|
6655
|
-
const forceSet = isAnchorCell && selection.mode !== "single-cell";
|
|
6656
|
-
if (forceSet) {
|
|
6657
|
-
coords = this.getFullCellSelectionCoords(rowIdx, colIdx);
|
|
6658
|
-
}
|
|
6659
|
-
const shouldUseSet = isStart || modeChanged || forceSet;
|
|
6660
|
-
if (shouldUseSet) {
|
|
6661
|
-
cell.textBufferView.setLocalSelection(coords.anchorX, coords.anchorY, coords.focusX, coords.focusY, this._selectionBg, this._selectionFg);
|
|
6662
|
-
} else {
|
|
6663
|
-
cell.textBufferView.updateLocalSelection(coords.anchorX, coords.anchorY, coords.focusX, coords.focusY, this._selectionBg, this._selectionFg);
|
|
6664
|
-
}
|
|
6665
|
-
}
|
|
6666
|
-
}
|
|
6667
|
-
}
|
|
6668
|
-
resolveSelectionResolution(localSelection) {
|
|
6669
|
-
const anchorCell = this.getCellAtLocalPosition(localSelection.anchorX, localSelection.anchorY);
|
|
6670
|
-
const focusCell = this.getCellAtLocalPosition(localSelection.focusX, localSelection.focusY);
|
|
6671
|
-
const anchorColumn = anchorCell?.colIdx ?? this.getColumnAtLocalX(localSelection.anchorX);
|
|
6672
|
-
if (anchorCell !== null && focusCell !== null && anchorCell.rowIdx === focusCell.rowIdx && anchorCell.colIdx === focusCell.colIdx) {
|
|
6673
|
-
return {
|
|
6674
|
-
mode: "single-cell",
|
|
6675
|
-
anchorCell,
|
|
6676
|
-
anchorColumn
|
|
6677
|
-
};
|
|
6678
|
-
}
|
|
6679
|
-
const focusColumn = this.getColumnAtLocalX(localSelection.focusX);
|
|
6680
|
-
if (anchorColumn !== null && focusColumn === anchorColumn) {
|
|
6681
|
-
return {
|
|
6682
|
-
mode: "column-locked",
|
|
6683
|
-
anchorCell,
|
|
6684
|
-
anchorColumn
|
|
6685
|
-
};
|
|
6686
|
-
}
|
|
6687
|
-
return {
|
|
6688
|
-
mode: "grid",
|
|
6689
|
-
anchorCell,
|
|
6690
|
-
anchorColumn
|
|
6691
|
-
};
|
|
6692
|
-
}
|
|
6693
|
-
getColumnAtLocalX(localX) {
|
|
6694
|
-
if (this._columnCount === 0)
|
|
6695
|
-
return null;
|
|
6696
|
-
if (localX < 0 || localX >= this._layout.tableWidth)
|
|
6697
|
-
return null;
|
|
6698
|
-
for (let colIdx = 0;colIdx < this._columnCount; colIdx++) {
|
|
6699
|
-
const colStart = (this._layout.columnOffsets[colIdx] ?? 0) + 1;
|
|
6700
|
-
const colEnd = colStart + (this._layout.columnWidths[colIdx] ?? 1) - 1;
|
|
6701
|
-
if (localX >= colStart && localX <= colEnd) {
|
|
6702
|
-
return colIdx;
|
|
6703
|
-
}
|
|
6704
|
-
}
|
|
6705
|
-
return null;
|
|
6706
|
-
}
|
|
6707
|
-
getFullCellSelectionCoords(rowIdx, colIdx) {
|
|
6708
|
-
const colWidth = this._layout.columnWidths[colIdx] ?? 1;
|
|
6709
|
-
const rowHeight = this._layout.rowHeights[rowIdx] ?? 1;
|
|
6710
|
-
const contentWidth = Math.max(1, colWidth - this.getHorizontalCellPadding());
|
|
6711
|
-
const contentHeight = Math.max(1, rowHeight - this.getVerticalCellPadding());
|
|
6712
|
-
return {
|
|
6713
|
-
anchorX: -1,
|
|
6714
|
-
anchorY: 0,
|
|
6715
|
-
focusX: contentWidth,
|
|
6716
|
-
focusY: contentHeight
|
|
6717
|
-
};
|
|
6718
|
-
}
|
|
6719
|
-
findRowForLocalY(localY) {
|
|
6720
|
-
if (this._rowCount === 0)
|
|
6721
|
-
return 0;
|
|
6722
|
-
if (localY < 0)
|
|
6723
|
-
return 0;
|
|
6724
|
-
for (let rowIdx = 0;rowIdx < this._rowCount; rowIdx++) {
|
|
6725
|
-
const rowStart = (this._layout.rowOffsets[rowIdx] ?? 0) + 1;
|
|
6726
|
-
const rowEnd = rowStart + (this._layout.rowHeights[rowIdx] ?? 1) - 1;
|
|
6727
|
-
if (localY <= rowEnd)
|
|
6728
|
-
return rowIdx;
|
|
6729
|
-
}
|
|
6730
|
-
return this._rowCount - 1;
|
|
6731
|
-
}
|
|
6732
|
-
getSelectionRowRange(selection) {
|
|
6733
|
-
if (!selection?.isActive || this._rowCount === 0)
|
|
6734
|
-
return null;
|
|
6735
|
-
const minSelY = Math.min(selection.anchorY, selection.focusY);
|
|
6736
|
-
const maxSelY = Math.max(selection.anchorY, selection.focusY);
|
|
6737
|
-
return {
|
|
6738
|
-
firstRow: this.findRowForLocalY(minSelY),
|
|
6739
|
-
lastRow: this.findRowForLocalY(maxSelY)
|
|
6740
|
-
};
|
|
6741
|
-
}
|
|
6742
|
-
getDirtySelectionRowRange(previousSelection, currentSelection) {
|
|
6743
|
-
const previousRange = this.getSelectionRowRange(previousSelection);
|
|
6744
|
-
const currentRange = this.getSelectionRowRange(currentSelection);
|
|
6745
|
-
if (previousRange === null)
|
|
6746
|
-
return currentRange;
|
|
6747
|
-
if (currentRange === null)
|
|
6748
|
-
return previousRange;
|
|
6749
|
-
return {
|
|
6750
|
-
firstRow: Math.min(previousRange.firstRow, currentRange.firstRow),
|
|
6751
|
-
lastRow: Math.max(previousRange.lastRow, currentRange.lastRow)
|
|
6752
|
-
};
|
|
6753
|
-
}
|
|
6754
|
-
resetRowSelection(rowIdx) {
|
|
6755
|
-
const row = this._cells[rowIdx];
|
|
6756
|
-
if (!row)
|
|
6757
|
-
return;
|
|
6758
|
-
for (const cell of row) {
|
|
6759
|
-
cell.textBufferView.resetLocalSelection();
|
|
6760
|
-
}
|
|
6761
|
-
}
|
|
6762
|
-
resetCellSelections() {
|
|
6763
|
-
for (let rowIdx = 0;rowIdx < this._rowCount; rowIdx++) {
|
|
6764
|
-
this.resetRowSelection(rowIdx);
|
|
6765
|
-
}
|
|
6766
|
-
}
|
|
6767
|
-
createEmptyLayout() {
|
|
6768
|
-
return {
|
|
6769
|
-
columnWidths: [],
|
|
6770
|
-
rowHeights: [],
|
|
6771
|
-
columnOffsets: [0],
|
|
6772
|
-
rowOffsets: [0],
|
|
6773
|
-
columnOffsetsI32: new Int32Array([0]),
|
|
6774
|
-
rowOffsetsI32: new Int32Array([0]),
|
|
6775
|
-
tableWidth: 0,
|
|
6776
|
-
tableHeight: 0
|
|
6777
|
-
};
|
|
6778
|
-
}
|
|
6779
|
-
resolveLayoutWidthConstraint(width) {
|
|
6780
|
-
if (width === undefined || !Number.isFinite(width) || width <= 0) {
|
|
6781
|
-
return;
|
|
6782
|
-
}
|
|
6783
|
-
if (this._wrapMode !== "none" || this.isFullWidthMode()) {
|
|
6784
|
-
return Math.max(1, Math.floor(width));
|
|
6785
|
-
}
|
|
6786
|
-
return;
|
|
6787
|
-
}
|
|
6788
|
-
getHorizontalCellPadding() {
|
|
6789
|
-
return this._cellPaddingX * 2;
|
|
6790
|
-
}
|
|
6791
|
-
getVerticalCellPadding() {
|
|
6792
|
-
return this._cellPaddingY * 2;
|
|
6793
|
-
}
|
|
6794
|
-
resolveColumnFitter(value) {
|
|
6795
|
-
if (value === undefined) {
|
|
6796
|
-
return this._defaultOptions.columnFitter;
|
|
6797
|
-
}
|
|
6798
|
-
return value === "balanced" ? "balanced" : "proportional";
|
|
6799
|
-
}
|
|
6800
|
-
resolveCellPadding(value) {
|
|
6801
|
-
if (value === undefined || !Number.isFinite(value)) {
|
|
6802
|
-
return this._defaultOptions.cellPadding;
|
|
6803
|
-
}
|
|
6804
|
-
return Math.max(0, Math.floor(value));
|
|
6805
|
-
}
|
|
6806
|
-
resolveColumnGap(value) {
|
|
6807
|
-
if (value === undefined || !Number.isFinite(value)) {
|
|
6808
|
-
return this._defaultOptions.columnGap;
|
|
6809
|
-
}
|
|
6810
|
-
return Math.max(0, Math.floor(value));
|
|
6811
|
-
}
|
|
6812
|
-
invalidateLayoutAndRaster(markYogaDirty = true) {
|
|
6813
|
-
this._layoutDirty = true;
|
|
6814
|
-
this._rasterDirty = true;
|
|
6815
|
-
this._cachedMeasureLayout = null;
|
|
6816
|
-
this._cachedMeasureWidth = undefined;
|
|
6817
|
-
if (markYogaDirty) {
|
|
6818
|
-
this.yogaNode.markDirty();
|
|
6819
|
-
}
|
|
6820
|
-
this.requestRender();
|
|
6821
|
-
}
|
|
6822
|
-
invalidateRasterOnly() {
|
|
6823
|
-
this._rasterDirty = true;
|
|
6824
|
-
this.requestRender();
|
|
6825
|
-
}
|
|
6826
|
-
}
|
|
6827
|
-
|
|
6828
5757
|
// ../../node_modules/.bun/marked@17.0.1/node_modules/marked/lib/marked.esm.js
|
|
6829
5758
|
function L() {
|
|
6830
5759
|
return { async: false, breaks: false, extensions: null, gfm: true, hooks: null, pedantic: false, renderer: null, silent: false, tokenizer: null, walkTokens: null };
|
|
@@ -6957,1138 +5886,2209 @@ function z(u, e, t2) {
|
|
|
6957
5886
|
else
|
|
6958
5887
|
break;
|
|
6959
5888
|
}
|
|
6960
|
-
return u.slice(0, n - r);
|
|
6961
|
-
}
|
|
6962
|
-
function de(u, e) {
|
|
6963
|
-
if (u.indexOf(e[1]) === -1)
|
|
6964
|
-
return -1;
|
|
6965
|
-
let t2 = 0;
|
|
6966
|
-
for (let n = 0;n < u.length; n++)
|
|
6967
|
-
if (u[n] === "\\")
|
|
6968
|
-
n++;
|
|
6969
|
-
else if (u[n] === e[0])
|
|
6970
|
-
t2++;
|
|
6971
|
-
else if (u[n] === e[1] && (t2--, t2 < 0))
|
|
6972
|
-
return n;
|
|
6973
|
-
return t2 > 0 ? -2 : -1;
|
|
6974
|
-
}
|
|
6975
|
-
function ge(u, e, t2, n, r) {
|
|
6976
|
-
let i = e.href, s = e.title || null, a = u[1].replace(r.other.outputLinkReplace, "$1");
|
|
6977
|
-
n.state.inLink = true;
|
|
6978
|
-
let o = { type: u[0].charAt(0) === "!" ? "image" : "link", raw: t2, href: i, title: s, text: a, tokens: n.inlineTokens(a) };
|
|
6979
|
-
return n.state.inLink = false, o;
|
|
6980
|
-
}
|
|
6981
|
-
function Je(u, e, t2) {
|
|
6982
|
-
let n = u.match(t2.other.indentCodeCompensation);
|
|
6983
|
-
if (n === null)
|
|
6984
|
-
return e;
|
|
6985
|
-
let r = n[1];
|
|
6986
|
-
return e.split(`
|
|
6987
|
-
`).map((i) => {
|
|
6988
|
-
let s = i.match(t2.other.beginningSpace);
|
|
6989
|
-
if (s === null)
|
|
6990
|
-
return i;
|
|
6991
|
-
let [a] = s;
|
|
6992
|
-
return a.length >= r.length ? i.slice(r.length) : i;
|
|
6993
|
-
}).join(`
|
|
6994
|
-
`);
|
|
6995
|
-
}
|
|
6996
|
-
var y = class {
|
|
6997
|
-
options;
|
|
6998
|
-
rules;
|
|
6999
|
-
lexer;
|
|
7000
|
-
constructor(e) {
|
|
7001
|
-
this.options = e || T;
|
|
5889
|
+
return u.slice(0, n - r);
|
|
5890
|
+
}
|
|
5891
|
+
function de(u, e) {
|
|
5892
|
+
if (u.indexOf(e[1]) === -1)
|
|
5893
|
+
return -1;
|
|
5894
|
+
let t2 = 0;
|
|
5895
|
+
for (let n = 0;n < u.length; n++)
|
|
5896
|
+
if (u[n] === "\\")
|
|
5897
|
+
n++;
|
|
5898
|
+
else if (u[n] === e[0])
|
|
5899
|
+
t2++;
|
|
5900
|
+
else if (u[n] === e[1] && (t2--, t2 < 0))
|
|
5901
|
+
return n;
|
|
5902
|
+
return t2 > 0 ? -2 : -1;
|
|
5903
|
+
}
|
|
5904
|
+
function ge(u, e, t2, n, r) {
|
|
5905
|
+
let i = e.href, s = e.title || null, a = u[1].replace(r.other.outputLinkReplace, "$1");
|
|
5906
|
+
n.state.inLink = true;
|
|
5907
|
+
let o = { type: u[0].charAt(0) === "!" ? "image" : "link", raw: t2, href: i, title: s, text: a, tokens: n.inlineTokens(a) };
|
|
5908
|
+
return n.state.inLink = false, o;
|
|
5909
|
+
}
|
|
5910
|
+
function Je(u, e, t2) {
|
|
5911
|
+
let n = u.match(t2.other.indentCodeCompensation);
|
|
5912
|
+
if (n === null)
|
|
5913
|
+
return e;
|
|
5914
|
+
let r = n[1];
|
|
5915
|
+
return e.split(`
|
|
5916
|
+
`).map((i) => {
|
|
5917
|
+
let s = i.match(t2.other.beginningSpace);
|
|
5918
|
+
if (s === null)
|
|
5919
|
+
return i;
|
|
5920
|
+
let [a] = s;
|
|
5921
|
+
return a.length >= r.length ? i.slice(r.length) : i;
|
|
5922
|
+
}).join(`
|
|
5923
|
+
`);
|
|
5924
|
+
}
|
|
5925
|
+
var y = class {
|
|
5926
|
+
options;
|
|
5927
|
+
rules;
|
|
5928
|
+
lexer;
|
|
5929
|
+
constructor(e) {
|
|
5930
|
+
this.options = e || T;
|
|
5931
|
+
}
|
|
5932
|
+
space(e) {
|
|
5933
|
+
let t2 = this.rules.block.newline.exec(e);
|
|
5934
|
+
if (t2 && t2[0].length > 0)
|
|
5935
|
+
return { type: "space", raw: t2[0] };
|
|
5936
|
+
}
|
|
5937
|
+
code(e) {
|
|
5938
|
+
let t2 = this.rules.block.code.exec(e);
|
|
5939
|
+
if (t2) {
|
|
5940
|
+
let n = t2[0].replace(this.rules.other.codeRemoveIndent, "");
|
|
5941
|
+
return { type: "code", raw: t2[0], codeBlockStyle: "indented", text: this.options.pedantic ? n : z(n, `
|
|
5942
|
+
`) };
|
|
5943
|
+
}
|
|
5944
|
+
}
|
|
5945
|
+
fences(e) {
|
|
5946
|
+
let t2 = this.rules.block.fences.exec(e);
|
|
5947
|
+
if (t2) {
|
|
5948
|
+
let n = t2[0], r = Je(n, t2[3] || "", this.rules);
|
|
5949
|
+
return { type: "code", raw: n, lang: t2[2] ? t2[2].trim().replace(this.rules.inline.anyPunctuation, "$1") : t2[2], text: r };
|
|
5950
|
+
}
|
|
5951
|
+
}
|
|
5952
|
+
heading(e) {
|
|
5953
|
+
let t2 = this.rules.block.heading.exec(e);
|
|
5954
|
+
if (t2) {
|
|
5955
|
+
let n = t2[2].trim();
|
|
5956
|
+
if (this.rules.other.endingHash.test(n)) {
|
|
5957
|
+
let r = z(n, "#");
|
|
5958
|
+
(this.options.pedantic || !r || this.rules.other.endingSpaceChar.test(r)) && (n = r.trim());
|
|
5959
|
+
}
|
|
5960
|
+
return { type: "heading", raw: t2[0], depth: t2[1].length, text: n, tokens: this.lexer.inline(n) };
|
|
5961
|
+
}
|
|
5962
|
+
}
|
|
5963
|
+
hr(e) {
|
|
5964
|
+
let t2 = this.rules.block.hr.exec(e);
|
|
5965
|
+
if (t2)
|
|
5966
|
+
return { type: "hr", raw: z(t2[0], `
|
|
5967
|
+
`) };
|
|
5968
|
+
}
|
|
5969
|
+
blockquote(e) {
|
|
5970
|
+
let t2 = this.rules.block.blockquote.exec(e);
|
|
5971
|
+
if (t2) {
|
|
5972
|
+
let n = z(t2[0], `
|
|
5973
|
+
`).split(`
|
|
5974
|
+
`), r = "", i = "", s = [];
|
|
5975
|
+
for (;n.length > 0; ) {
|
|
5976
|
+
let a = false, o = [], l;
|
|
5977
|
+
for (l = 0;l < n.length; l++)
|
|
5978
|
+
if (this.rules.other.blockquoteStart.test(n[l]))
|
|
5979
|
+
o.push(n[l]), a = true;
|
|
5980
|
+
else if (!a)
|
|
5981
|
+
o.push(n[l]);
|
|
5982
|
+
else
|
|
5983
|
+
break;
|
|
5984
|
+
n = n.slice(l);
|
|
5985
|
+
let p = o.join(`
|
|
5986
|
+
`), c = p.replace(this.rules.other.blockquoteSetextReplace, `
|
|
5987
|
+
$1`).replace(this.rules.other.blockquoteSetextReplace2, "");
|
|
5988
|
+
r = r ? `${r}
|
|
5989
|
+
${p}` : p, i = i ? `${i}
|
|
5990
|
+
${c}` : c;
|
|
5991
|
+
let g = this.lexer.state.top;
|
|
5992
|
+
if (this.lexer.state.top = true, this.lexer.blockTokens(c, s, true), this.lexer.state.top = g, n.length === 0)
|
|
5993
|
+
break;
|
|
5994
|
+
let h2 = s.at(-1);
|
|
5995
|
+
if (h2?.type === "code")
|
|
5996
|
+
break;
|
|
5997
|
+
if (h2?.type === "blockquote") {
|
|
5998
|
+
let R = h2, f = R.raw + `
|
|
5999
|
+
` + n.join(`
|
|
6000
|
+
`), O = this.blockquote(f);
|
|
6001
|
+
s[s.length - 1] = O, r = r.substring(0, r.length - R.raw.length) + O.raw, i = i.substring(0, i.length - R.text.length) + O.text;
|
|
6002
|
+
break;
|
|
6003
|
+
} else if (h2?.type === "list") {
|
|
6004
|
+
let R = h2, f = R.raw + `
|
|
6005
|
+
` + n.join(`
|
|
6006
|
+
`), O = this.list(f);
|
|
6007
|
+
s[s.length - 1] = O, r = r.substring(0, r.length - h2.raw.length) + O.raw, i = i.substring(0, i.length - R.raw.length) + O.raw, n = f.substring(s.at(-1).raw.length).split(`
|
|
6008
|
+
`);
|
|
6009
|
+
continue;
|
|
6010
|
+
}
|
|
6011
|
+
}
|
|
6012
|
+
return { type: "blockquote", raw: r, tokens: s, text: i };
|
|
6013
|
+
}
|
|
6014
|
+
}
|
|
6015
|
+
list(e) {
|
|
6016
|
+
let t2 = this.rules.block.list.exec(e);
|
|
6017
|
+
if (t2) {
|
|
6018
|
+
let n = t2[1].trim(), r = n.length > 1, i = { type: "list", raw: "", ordered: r, start: r ? +n.slice(0, -1) : "", loose: false, items: [] };
|
|
6019
|
+
n = r ? `\\d{1,9}\\${n.slice(-1)}` : `\\${n}`, this.options.pedantic && (n = r ? n : "[*+-]");
|
|
6020
|
+
let s = this.rules.other.listItemRegex(n), a = false;
|
|
6021
|
+
for (;e; ) {
|
|
6022
|
+
let l = false, p = "", c = "";
|
|
6023
|
+
if (!(t2 = s.exec(e)) || this.rules.block.hr.test(e))
|
|
6024
|
+
break;
|
|
6025
|
+
p = t2[0], e = e.substring(p.length);
|
|
6026
|
+
let g = t2[2].split(`
|
|
6027
|
+
`, 1)[0].replace(this.rules.other.listReplaceTabs, (O) => " ".repeat(3 * O.length)), h2 = e.split(`
|
|
6028
|
+
`, 1)[0], R = !g.trim(), f = 0;
|
|
6029
|
+
if (this.options.pedantic ? (f = 2, c = g.trimStart()) : R ? f = t2[1].length + 1 : (f = t2[2].search(this.rules.other.nonSpaceChar), f = f > 4 ? 1 : f, c = g.slice(f), f += t2[1].length), R && this.rules.other.blankLine.test(h2) && (p += h2 + `
|
|
6030
|
+
`, e = e.substring(h2.length + 1), l = true), !l) {
|
|
6031
|
+
let O = this.rules.other.nextBulletRegex(f), V = this.rules.other.hrRegex(f), Y = this.rules.other.fencesBeginRegex(f), ee = this.rules.other.headingBeginRegex(f), fe = this.rules.other.htmlBeginRegex(f);
|
|
6032
|
+
for (;e; ) {
|
|
6033
|
+
let H = e.split(`
|
|
6034
|
+
`, 1)[0], A;
|
|
6035
|
+
if (h2 = H, this.options.pedantic ? (h2 = h2.replace(this.rules.other.listReplaceNesting, " "), A = h2) : A = h2.replace(this.rules.other.tabCharGlobal, " "), Y.test(h2) || ee.test(h2) || fe.test(h2) || O.test(h2) || V.test(h2))
|
|
6036
|
+
break;
|
|
6037
|
+
if (A.search(this.rules.other.nonSpaceChar) >= f || !h2.trim())
|
|
6038
|
+
c += `
|
|
6039
|
+
` + A.slice(f);
|
|
6040
|
+
else {
|
|
6041
|
+
if (R || g.replace(this.rules.other.tabCharGlobal, " ").search(this.rules.other.nonSpaceChar) >= 4 || Y.test(g) || ee.test(g) || V.test(g))
|
|
6042
|
+
break;
|
|
6043
|
+
c += `
|
|
6044
|
+
` + h2;
|
|
6045
|
+
}
|
|
6046
|
+
!R && !h2.trim() && (R = true), p += H + `
|
|
6047
|
+
`, e = e.substring(H.length + 1), g = A.slice(f);
|
|
6048
|
+
}
|
|
6049
|
+
}
|
|
6050
|
+
i.loose || (a ? i.loose = true : this.rules.other.doubleBlankLine.test(p) && (a = true)), i.items.push({ type: "list_item", raw: p, task: !!this.options.gfm && this.rules.other.listIsTask.test(c), loose: false, text: c, tokens: [] }), i.raw += p;
|
|
6051
|
+
}
|
|
6052
|
+
let o = i.items.at(-1);
|
|
6053
|
+
if (o)
|
|
6054
|
+
o.raw = o.raw.trimEnd(), o.text = o.text.trimEnd();
|
|
6055
|
+
else
|
|
6056
|
+
return;
|
|
6057
|
+
i.raw = i.raw.trimEnd();
|
|
6058
|
+
for (let l of i.items) {
|
|
6059
|
+
if (this.lexer.state.top = false, l.tokens = this.lexer.blockTokens(l.text, []), l.task) {
|
|
6060
|
+
if (l.text = l.text.replace(this.rules.other.listReplaceTask, ""), l.tokens[0]?.type === "text" || l.tokens[0]?.type === "paragraph") {
|
|
6061
|
+
l.tokens[0].raw = l.tokens[0].raw.replace(this.rules.other.listReplaceTask, ""), l.tokens[0].text = l.tokens[0].text.replace(this.rules.other.listReplaceTask, "");
|
|
6062
|
+
for (let c = this.lexer.inlineQueue.length - 1;c >= 0; c--)
|
|
6063
|
+
if (this.rules.other.listIsTask.test(this.lexer.inlineQueue[c].src)) {
|
|
6064
|
+
this.lexer.inlineQueue[c].src = this.lexer.inlineQueue[c].src.replace(this.rules.other.listReplaceTask, "");
|
|
6065
|
+
break;
|
|
6066
|
+
}
|
|
6067
|
+
}
|
|
6068
|
+
let p = this.rules.other.listTaskCheckbox.exec(l.raw);
|
|
6069
|
+
if (p) {
|
|
6070
|
+
let c = { type: "checkbox", raw: p[0] + " ", checked: p[0] !== "[ ]" };
|
|
6071
|
+
l.checked = c.checked, i.loose ? l.tokens[0] && ["paragraph", "text"].includes(l.tokens[0].type) && "tokens" in l.tokens[0] && l.tokens[0].tokens ? (l.tokens[0].raw = c.raw + l.tokens[0].raw, l.tokens[0].text = c.raw + l.tokens[0].text, l.tokens[0].tokens.unshift(c)) : l.tokens.unshift({ type: "paragraph", raw: c.raw, text: c.raw, tokens: [c] }) : l.tokens.unshift(c);
|
|
6072
|
+
}
|
|
6073
|
+
}
|
|
6074
|
+
if (!i.loose) {
|
|
6075
|
+
let p = l.tokens.filter((g) => g.type === "space"), c = p.length > 0 && p.some((g) => this.rules.other.anyLine.test(g.raw));
|
|
6076
|
+
i.loose = c;
|
|
6077
|
+
}
|
|
6078
|
+
}
|
|
6079
|
+
if (i.loose)
|
|
6080
|
+
for (let l of i.items) {
|
|
6081
|
+
l.loose = true;
|
|
6082
|
+
for (let p of l.tokens)
|
|
6083
|
+
p.type === "text" && (p.type = "paragraph");
|
|
6084
|
+
}
|
|
6085
|
+
return i;
|
|
6086
|
+
}
|
|
6087
|
+
}
|
|
6088
|
+
html(e) {
|
|
6089
|
+
let t2 = this.rules.block.html.exec(e);
|
|
6090
|
+
if (t2)
|
|
6091
|
+
return { type: "html", block: true, raw: t2[0], pre: t2[1] === "pre" || t2[1] === "script" || t2[1] === "style", text: t2[0] };
|
|
6092
|
+
}
|
|
6093
|
+
def(e) {
|
|
6094
|
+
let t2 = this.rules.block.def.exec(e);
|
|
6095
|
+
if (t2) {
|
|
6096
|
+
let n = t2[1].toLowerCase().replace(this.rules.other.multipleSpaceGlobal, " "), r = t2[2] ? t2[2].replace(this.rules.other.hrefBrackets, "$1").replace(this.rules.inline.anyPunctuation, "$1") : "", i = t2[3] ? t2[3].substring(1, t2[3].length - 1).replace(this.rules.inline.anyPunctuation, "$1") : t2[3];
|
|
6097
|
+
return { type: "def", tag: n, raw: t2[0], href: r, title: i };
|
|
6098
|
+
}
|
|
6099
|
+
}
|
|
6100
|
+
table(e) {
|
|
6101
|
+
let t2 = this.rules.block.table.exec(e);
|
|
6102
|
+
if (!t2 || !this.rules.other.tableDelimiter.test(t2[2]))
|
|
6103
|
+
return;
|
|
6104
|
+
let n = J(t2[1]), r = t2[2].replace(this.rules.other.tableAlignChars, "").split("|"), i = t2[3]?.trim() ? t2[3].replace(this.rules.other.tableRowBlankLine, "").split(`
|
|
6105
|
+
`) : [], s = { type: "table", raw: t2[0], header: [], align: [], rows: [] };
|
|
6106
|
+
if (n.length === r.length) {
|
|
6107
|
+
for (let a of r)
|
|
6108
|
+
this.rules.other.tableAlignRight.test(a) ? s.align.push("right") : this.rules.other.tableAlignCenter.test(a) ? s.align.push("center") : this.rules.other.tableAlignLeft.test(a) ? s.align.push("left") : s.align.push(null);
|
|
6109
|
+
for (let a = 0;a < n.length; a++)
|
|
6110
|
+
s.header.push({ text: n[a], tokens: this.lexer.inline(n[a]), header: true, align: s.align[a] });
|
|
6111
|
+
for (let a of i)
|
|
6112
|
+
s.rows.push(J(a, s.header.length).map((o, l) => ({ text: o, tokens: this.lexer.inline(o), header: false, align: s.align[l] })));
|
|
6113
|
+
return s;
|
|
6114
|
+
}
|
|
6115
|
+
}
|
|
6116
|
+
lheading(e) {
|
|
6117
|
+
let t2 = this.rules.block.lheading.exec(e);
|
|
6118
|
+
if (t2)
|
|
6119
|
+
return { type: "heading", raw: t2[0], depth: t2[2].charAt(0) === "=" ? 1 : 2, text: t2[1], tokens: this.lexer.inline(t2[1]) };
|
|
6120
|
+
}
|
|
6121
|
+
paragraph(e) {
|
|
6122
|
+
let t2 = this.rules.block.paragraph.exec(e);
|
|
6123
|
+
if (t2) {
|
|
6124
|
+
let n = t2[1].charAt(t2[1].length - 1) === `
|
|
6125
|
+
` ? t2[1].slice(0, -1) : t2[1];
|
|
6126
|
+
return { type: "paragraph", raw: t2[0], text: n, tokens: this.lexer.inline(n) };
|
|
6127
|
+
}
|
|
6128
|
+
}
|
|
6129
|
+
text(e) {
|
|
6130
|
+
let t2 = this.rules.block.text.exec(e);
|
|
6131
|
+
if (t2)
|
|
6132
|
+
return { type: "text", raw: t2[0], text: t2[0], tokens: this.lexer.inline(t2[0]) };
|
|
6133
|
+
}
|
|
6134
|
+
escape(e) {
|
|
6135
|
+
let t2 = this.rules.inline.escape.exec(e);
|
|
6136
|
+
if (t2)
|
|
6137
|
+
return { type: "escape", raw: t2[0], text: t2[1] };
|
|
6138
|
+
}
|
|
6139
|
+
tag(e) {
|
|
6140
|
+
let t2 = this.rules.inline.tag.exec(e);
|
|
6141
|
+
if (t2)
|
|
6142
|
+
return !this.lexer.state.inLink && this.rules.other.startATag.test(t2[0]) ? this.lexer.state.inLink = true : this.lexer.state.inLink && this.rules.other.endATag.test(t2[0]) && (this.lexer.state.inLink = false), !this.lexer.state.inRawBlock && this.rules.other.startPreScriptTag.test(t2[0]) ? this.lexer.state.inRawBlock = true : this.lexer.state.inRawBlock && this.rules.other.endPreScriptTag.test(t2[0]) && (this.lexer.state.inRawBlock = false), { type: "html", raw: t2[0], inLink: this.lexer.state.inLink, inRawBlock: this.lexer.state.inRawBlock, block: false, text: t2[0] };
|
|
7002
6143
|
}
|
|
7003
|
-
|
|
7004
|
-
let t2 = this.rules.
|
|
7005
|
-
if (t2
|
|
7006
|
-
|
|
6144
|
+
link(e) {
|
|
6145
|
+
let t2 = this.rules.inline.link.exec(e);
|
|
6146
|
+
if (t2) {
|
|
6147
|
+
let n = t2[2].trim();
|
|
6148
|
+
if (!this.options.pedantic && this.rules.other.startAngleBracket.test(n)) {
|
|
6149
|
+
if (!this.rules.other.endAngleBracket.test(n))
|
|
6150
|
+
return;
|
|
6151
|
+
let s = z(n.slice(0, -1), "\\");
|
|
6152
|
+
if ((n.length - s.length) % 2 === 0)
|
|
6153
|
+
return;
|
|
6154
|
+
} else {
|
|
6155
|
+
let s = de(t2[2], "()");
|
|
6156
|
+
if (s === -2)
|
|
6157
|
+
return;
|
|
6158
|
+
if (s > -1) {
|
|
6159
|
+
let o = (t2[0].indexOf("!") === 0 ? 5 : 4) + t2[1].length + s;
|
|
6160
|
+
t2[2] = t2[2].substring(0, s), t2[0] = t2[0].substring(0, o).trim(), t2[3] = "";
|
|
6161
|
+
}
|
|
6162
|
+
}
|
|
6163
|
+
let r = t2[2], i = "";
|
|
6164
|
+
if (this.options.pedantic) {
|
|
6165
|
+
let s = this.rules.other.pedanticHrefTitle.exec(r);
|
|
6166
|
+
s && (r = s[1], i = s[3]);
|
|
6167
|
+
} else
|
|
6168
|
+
i = t2[3] ? t2[3].slice(1, -1) : "";
|
|
6169
|
+
return r = r.trim(), this.rules.other.startAngleBracket.test(r) && (this.options.pedantic && !this.rules.other.endAngleBracket.test(n) ? r = r.slice(1) : r = r.slice(1, -1)), ge(t2, { href: r && r.replace(this.rules.inline.anyPunctuation, "$1"), title: i && i.replace(this.rules.inline.anyPunctuation, "$1") }, t2[0], this.lexer, this.rules);
|
|
6170
|
+
}
|
|
7007
6171
|
}
|
|
7008
|
-
|
|
7009
|
-
let
|
|
6172
|
+
reflink(e, t2) {
|
|
6173
|
+
let n;
|
|
6174
|
+
if ((n = this.rules.inline.reflink.exec(e)) || (n = this.rules.inline.nolink.exec(e))) {
|
|
6175
|
+
let r = (n[2] || n[1]).replace(this.rules.other.multipleSpaceGlobal, " "), i = t2[r.toLowerCase()];
|
|
6176
|
+
if (!i) {
|
|
6177
|
+
let s = n[0].charAt(0);
|
|
6178
|
+
return { type: "text", raw: s, text: s };
|
|
6179
|
+
}
|
|
6180
|
+
return ge(n, i, n[0], this.lexer, this.rules);
|
|
6181
|
+
}
|
|
6182
|
+
}
|
|
6183
|
+
emStrong(e, t2, n = "") {
|
|
6184
|
+
let r = this.rules.inline.emStrongLDelim.exec(e);
|
|
6185
|
+
if (!r || r[3] && n.match(this.rules.other.unicodeAlphaNumeric))
|
|
6186
|
+
return;
|
|
6187
|
+
if (!(r[1] || r[2] || "") || !n || this.rules.inline.punctuation.exec(n)) {
|
|
6188
|
+
let s = [...r[0]].length - 1, a, o, l = s, p = 0, c = r[0][0] === "*" ? this.rules.inline.emStrongRDelimAst : this.rules.inline.emStrongRDelimUnd;
|
|
6189
|
+
for (c.lastIndex = 0, t2 = t2.slice(-1 * e.length + s);(r = c.exec(t2)) != null; ) {
|
|
6190
|
+
if (a = r[1] || r[2] || r[3] || r[4] || r[5] || r[6], !a)
|
|
6191
|
+
continue;
|
|
6192
|
+
if (o = [...a].length, r[3] || r[4]) {
|
|
6193
|
+
l += o;
|
|
6194
|
+
continue;
|
|
6195
|
+
} else if ((r[5] || r[6]) && s % 3 && !((s + o) % 3)) {
|
|
6196
|
+
p += o;
|
|
6197
|
+
continue;
|
|
6198
|
+
}
|
|
6199
|
+
if (l -= o, l > 0)
|
|
6200
|
+
continue;
|
|
6201
|
+
o = Math.min(o, o + l + p);
|
|
6202
|
+
let g = [...r[0]][0].length, h2 = e.slice(0, s + r.index + g + o);
|
|
6203
|
+
if (Math.min(s, o) % 2) {
|
|
6204
|
+
let f = h2.slice(1, -1);
|
|
6205
|
+
return { type: "em", raw: h2, text: f, tokens: this.lexer.inlineTokens(f) };
|
|
6206
|
+
}
|
|
6207
|
+
let R = h2.slice(2, -2);
|
|
6208
|
+
return { type: "strong", raw: h2, text: R, tokens: this.lexer.inlineTokens(R) };
|
|
6209
|
+
}
|
|
6210
|
+
}
|
|
6211
|
+
}
|
|
6212
|
+
codespan(e) {
|
|
6213
|
+
let t2 = this.rules.inline.code.exec(e);
|
|
7010
6214
|
if (t2) {
|
|
7011
|
-
let n = t2[
|
|
7012
|
-
return { type: "
|
|
7013
|
-
`) };
|
|
6215
|
+
let n = t2[2].replace(this.rules.other.newLineCharGlobal, " "), r = this.rules.other.nonSpaceChar.test(n), i = this.rules.other.startingSpaceChar.test(n) && this.rules.other.endingSpaceChar.test(n);
|
|
6216
|
+
return r && i && (n = n.substring(1, n.length - 1)), { type: "codespan", raw: t2[0], text: n };
|
|
7014
6217
|
}
|
|
7015
6218
|
}
|
|
7016
|
-
|
|
7017
|
-
let t2 = this.rules.
|
|
6219
|
+
br(e) {
|
|
6220
|
+
let t2 = this.rules.inline.br.exec(e);
|
|
6221
|
+
if (t2)
|
|
6222
|
+
return { type: "br", raw: t2[0] };
|
|
6223
|
+
}
|
|
6224
|
+
del(e) {
|
|
6225
|
+
let t2 = this.rules.inline.del.exec(e);
|
|
6226
|
+
if (t2)
|
|
6227
|
+
return { type: "del", raw: t2[0], text: t2[2], tokens: this.lexer.inlineTokens(t2[2]) };
|
|
6228
|
+
}
|
|
6229
|
+
autolink(e) {
|
|
6230
|
+
let t2 = this.rules.inline.autolink.exec(e);
|
|
7018
6231
|
if (t2) {
|
|
7019
|
-
let n
|
|
7020
|
-
return
|
|
6232
|
+
let n, r;
|
|
6233
|
+
return t2[2] === "@" ? (n = t2[1], r = "mailto:" + n) : (n = t2[1], r = n), { type: "link", raw: t2[0], text: n, href: r, tokens: [{ type: "text", raw: n, text: n }] };
|
|
7021
6234
|
}
|
|
7022
6235
|
}
|
|
7023
|
-
|
|
7024
|
-
let t2
|
|
6236
|
+
url(e) {
|
|
6237
|
+
let t2;
|
|
6238
|
+
if (t2 = this.rules.inline.url.exec(e)) {
|
|
6239
|
+
let n, r;
|
|
6240
|
+
if (t2[2] === "@")
|
|
6241
|
+
n = t2[0], r = "mailto:" + n;
|
|
6242
|
+
else {
|
|
6243
|
+
let i;
|
|
6244
|
+
do
|
|
6245
|
+
i = t2[0], t2[0] = this.rules.inline._backpedal.exec(t2[0])?.[0] ?? "";
|
|
6246
|
+
while (i !== t2[0]);
|
|
6247
|
+
n = t2[0], t2[1] === "www." ? r = "http://" + t2[0] : r = t2[0];
|
|
6248
|
+
}
|
|
6249
|
+
return { type: "link", raw: t2[0], text: n, href: r, tokens: [{ type: "text", raw: n, text: n }] };
|
|
6250
|
+
}
|
|
6251
|
+
}
|
|
6252
|
+
inlineText(e) {
|
|
6253
|
+
let t2 = this.rules.inline.text.exec(e);
|
|
7025
6254
|
if (t2) {
|
|
7026
|
-
let n =
|
|
7027
|
-
|
|
7028
|
-
|
|
7029
|
-
|
|
6255
|
+
let n = this.lexer.state.inRawBlock;
|
|
6256
|
+
return { type: "text", raw: t2[0], text: t2[0], escaped: n };
|
|
6257
|
+
}
|
|
6258
|
+
}
|
|
6259
|
+
};
|
|
6260
|
+
var x = class u {
|
|
6261
|
+
tokens;
|
|
6262
|
+
options;
|
|
6263
|
+
state;
|
|
6264
|
+
inlineQueue;
|
|
6265
|
+
tokenizer;
|
|
6266
|
+
constructor(e) {
|
|
6267
|
+
this.tokens = [], this.tokens.links = Object.create(null), this.options = e || T, this.options.tokenizer = this.options.tokenizer || new y, this.tokenizer = this.options.tokenizer, this.tokenizer.options = this.options, this.tokenizer.lexer = this, this.inlineQueue = [], this.state = { inLink: false, inRawBlock: false, top: true };
|
|
6268
|
+
let t2 = { other: m, block: E.normal, inline: M.normal };
|
|
6269
|
+
this.options.pedantic ? (t2.block = E.pedantic, t2.inline = M.pedantic) : this.options.gfm && (t2.block = E.gfm, this.options.breaks ? t2.inline = M.breaks : t2.inline = M.gfm), this.tokenizer.rules = t2;
|
|
6270
|
+
}
|
|
6271
|
+
static get rules() {
|
|
6272
|
+
return { block: E, inline: M };
|
|
6273
|
+
}
|
|
6274
|
+
static lex(e, t2) {
|
|
6275
|
+
return new u(t2).lex(e);
|
|
6276
|
+
}
|
|
6277
|
+
static lexInline(e, t2) {
|
|
6278
|
+
return new u(t2).inlineTokens(e);
|
|
6279
|
+
}
|
|
6280
|
+
lex(e) {
|
|
6281
|
+
e = e.replace(m.carriageReturn, `
|
|
6282
|
+
`), this.blockTokens(e, this.tokens);
|
|
6283
|
+
for (let t2 = 0;t2 < this.inlineQueue.length; t2++) {
|
|
6284
|
+
let n = this.inlineQueue[t2];
|
|
6285
|
+
this.inlineTokens(n.src, n.tokens);
|
|
6286
|
+
}
|
|
6287
|
+
return this.inlineQueue = [], this.tokens;
|
|
6288
|
+
}
|
|
6289
|
+
blockTokens(e, t2 = [], n = false) {
|
|
6290
|
+
for (this.options.pedantic && (e = e.replace(m.tabCharGlobal, " ").replace(m.spaceLine, ""));e; ) {
|
|
6291
|
+
let r;
|
|
6292
|
+
if (this.options.extensions?.block?.some((s) => (r = s.call({ lexer: this }, e, t2)) ? (e = e.substring(r.raw.length), t2.push(r), true) : false))
|
|
6293
|
+
continue;
|
|
6294
|
+
if (r = this.tokenizer.space(e)) {
|
|
6295
|
+
e = e.substring(r.raw.length);
|
|
6296
|
+
let s = t2.at(-1);
|
|
6297
|
+
r.raw.length === 1 && s !== undefined ? s.raw += `
|
|
6298
|
+
` : t2.push(r);
|
|
6299
|
+
continue;
|
|
6300
|
+
}
|
|
6301
|
+
if (r = this.tokenizer.code(e)) {
|
|
6302
|
+
e = e.substring(r.raw.length);
|
|
6303
|
+
let s = t2.at(-1);
|
|
6304
|
+
s?.type === "paragraph" || s?.type === "text" ? (s.raw += (s.raw.endsWith(`
|
|
6305
|
+
`) ? "" : `
|
|
6306
|
+
`) + r.raw, s.text += `
|
|
6307
|
+
` + r.text, this.inlineQueue.at(-1).src = s.text) : t2.push(r);
|
|
6308
|
+
continue;
|
|
6309
|
+
}
|
|
6310
|
+
if (r = this.tokenizer.fences(e)) {
|
|
6311
|
+
e = e.substring(r.raw.length), t2.push(r);
|
|
6312
|
+
continue;
|
|
6313
|
+
}
|
|
6314
|
+
if (r = this.tokenizer.heading(e)) {
|
|
6315
|
+
e = e.substring(r.raw.length), t2.push(r);
|
|
6316
|
+
continue;
|
|
6317
|
+
}
|
|
6318
|
+
if (r = this.tokenizer.hr(e)) {
|
|
6319
|
+
e = e.substring(r.raw.length), t2.push(r);
|
|
6320
|
+
continue;
|
|
6321
|
+
}
|
|
6322
|
+
if (r = this.tokenizer.blockquote(e)) {
|
|
6323
|
+
e = e.substring(r.raw.length), t2.push(r);
|
|
6324
|
+
continue;
|
|
6325
|
+
}
|
|
6326
|
+
if (r = this.tokenizer.list(e)) {
|
|
6327
|
+
e = e.substring(r.raw.length), t2.push(r);
|
|
6328
|
+
continue;
|
|
6329
|
+
}
|
|
6330
|
+
if (r = this.tokenizer.html(e)) {
|
|
6331
|
+
e = e.substring(r.raw.length), t2.push(r);
|
|
6332
|
+
continue;
|
|
6333
|
+
}
|
|
6334
|
+
if (r = this.tokenizer.def(e)) {
|
|
6335
|
+
e = e.substring(r.raw.length);
|
|
6336
|
+
let s = t2.at(-1);
|
|
6337
|
+
s?.type === "paragraph" || s?.type === "text" ? (s.raw += (s.raw.endsWith(`
|
|
6338
|
+
`) ? "" : `
|
|
6339
|
+
`) + r.raw, s.text += `
|
|
6340
|
+
` + r.raw, this.inlineQueue.at(-1).src = s.text) : this.tokens.links[r.tag] || (this.tokens.links[r.tag] = { href: r.href, title: r.title }, t2.push(r));
|
|
6341
|
+
continue;
|
|
6342
|
+
}
|
|
6343
|
+
if (r = this.tokenizer.table(e)) {
|
|
6344
|
+
e = e.substring(r.raw.length), t2.push(r);
|
|
6345
|
+
continue;
|
|
7030
6346
|
}
|
|
7031
|
-
|
|
7032
|
-
|
|
7033
|
-
|
|
7034
|
-
|
|
7035
|
-
|
|
7036
|
-
|
|
7037
|
-
|
|
7038
|
-
|
|
7039
|
-
|
|
7040
|
-
|
|
7041
|
-
|
|
7042
|
-
|
|
7043
|
-
|
|
7044
|
-
|
|
7045
|
-
`)
|
|
7046
|
-
|
|
7047
|
-
|
|
7048
|
-
|
|
7049
|
-
|
|
7050
|
-
|
|
7051
|
-
|
|
7052
|
-
|
|
7053
|
-
|
|
7054
|
-
|
|
7055
|
-
|
|
7056
|
-
|
|
7057
|
-
|
|
7058
|
-
|
|
7059
|
-
|
|
7060
|
-
|
|
7061
|
-
|
|
7062
|
-
|
|
7063
|
-
if (this.lexer.state.top = true, this.lexer.blockTokens(c, s, true), this.lexer.state.top = g, n.length === 0)
|
|
7064
|
-
break;
|
|
7065
|
-
let h2 = s.at(-1);
|
|
7066
|
-
if (h2?.type === "code")
|
|
7067
|
-
break;
|
|
7068
|
-
if (h2?.type === "blockquote") {
|
|
7069
|
-
let R = h2, f = R.raw + `
|
|
7070
|
-
` + n.join(`
|
|
7071
|
-
`), O = this.blockquote(f);
|
|
7072
|
-
s[s.length - 1] = O, r = r.substring(0, r.length - R.raw.length) + O.raw, i = i.substring(0, i.length - R.text.length) + O.text;
|
|
6347
|
+
if (r = this.tokenizer.lheading(e)) {
|
|
6348
|
+
e = e.substring(r.raw.length), t2.push(r);
|
|
6349
|
+
continue;
|
|
6350
|
+
}
|
|
6351
|
+
let i = e;
|
|
6352
|
+
if (this.options.extensions?.startBlock) {
|
|
6353
|
+
let s = 1 / 0, a = e.slice(1), o;
|
|
6354
|
+
this.options.extensions.startBlock.forEach((l) => {
|
|
6355
|
+
o = l.call({ lexer: this }, a), typeof o == "number" && o >= 0 && (s = Math.min(s, o));
|
|
6356
|
+
}), s < 1 / 0 && s >= 0 && (i = e.substring(0, s + 1));
|
|
6357
|
+
}
|
|
6358
|
+
if (this.state.top && (r = this.tokenizer.paragraph(i))) {
|
|
6359
|
+
let s = t2.at(-1);
|
|
6360
|
+
n && s?.type === "paragraph" ? (s.raw += (s.raw.endsWith(`
|
|
6361
|
+
`) ? "" : `
|
|
6362
|
+
`) + r.raw, s.text += `
|
|
6363
|
+
` + r.text, this.inlineQueue.pop(), this.inlineQueue.at(-1).src = s.text) : t2.push(r), n = i.length !== e.length, e = e.substring(r.raw.length);
|
|
6364
|
+
continue;
|
|
6365
|
+
}
|
|
6366
|
+
if (r = this.tokenizer.text(e)) {
|
|
6367
|
+
e = e.substring(r.raw.length);
|
|
6368
|
+
let s = t2.at(-1);
|
|
6369
|
+
s?.type === "text" ? (s.raw += (s.raw.endsWith(`
|
|
6370
|
+
`) ? "" : `
|
|
6371
|
+
`) + r.raw, s.text += `
|
|
6372
|
+
` + r.text, this.inlineQueue.pop(), this.inlineQueue.at(-1).src = s.text) : t2.push(r);
|
|
6373
|
+
continue;
|
|
6374
|
+
}
|
|
6375
|
+
if (e) {
|
|
6376
|
+
let s = "Infinite loop on byte: " + e.charCodeAt(0);
|
|
6377
|
+
if (this.options.silent) {
|
|
6378
|
+
console.error(s);
|
|
7073
6379
|
break;
|
|
7074
|
-
} else
|
|
7075
|
-
|
|
7076
|
-
` + n.join(`
|
|
7077
|
-
`), O = this.list(f);
|
|
7078
|
-
s[s.length - 1] = O, r = r.substring(0, r.length - h2.raw.length) + O.raw, i = i.substring(0, i.length - R.raw.length) + O.raw, n = f.substring(s.at(-1).raw.length).split(`
|
|
7079
|
-
`);
|
|
7080
|
-
continue;
|
|
7081
|
-
}
|
|
6380
|
+
} else
|
|
6381
|
+
throw new Error(s);
|
|
7082
6382
|
}
|
|
7083
|
-
return { type: "blockquote", raw: r, tokens: s, text: i };
|
|
7084
6383
|
}
|
|
6384
|
+
return this.state.top = true, t2;
|
|
7085
6385
|
}
|
|
7086
|
-
|
|
7087
|
-
|
|
7088
|
-
|
|
7089
|
-
|
|
7090
|
-
|
|
7091
|
-
|
|
7092
|
-
|
|
7093
|
-
|
|
7094
|
-
|
|
7095
|
-
|
|
7096
|
-
|
|
7097
|
-
|
|
7098
|
-
|
|
7099
|
-
|
|
7100
|
-
|
|
7101
|
-
|
|
7102
|
-
|
|
7103
|
-
|
|
7104
|
-
|
|
7105
|
-
|
|
7106
|
-
|
|
7107
|
-
|
|
7108
|
-
|
|
7109
|
-
|
|
7110
|
-
|
|
7111
|
-
|
|
7112
|
-
if (R || g.replace(this.rules.other.tabCharGlobal, " ").search(this.rules.other.nonSpaceChar) >= 4 || Y.test(g) || ee.test(g) || V.test(g))
|
|
7113
|
-
break;
|
|
7114
|
-
c += `
|
|
7115
|
-
` + h2;
|
|
7116
|
-
}
|
|
7117
|
-
!R && !h2.trim() && (R = true), p += H + `
|
|
7118
|
-
`, e = e.substring(H.length + 1), g = A.slice(f);
|
|
7119
|
-
}
|
|
7120
|
-
}
|
|
7121
|
-
i.loose || (a ? i.loose = true : this.rules.other.doubleBlankLine.test(p) && (a = true)), i.items.push({ type: "list_item", raw: p, task: !!this.options.gfm && this.rules.other.listIsTask.test(c), loose: false, text: c, tokens: [] }), i.raw += p;
|
|
6386
|
+
inline(e, t2 = []) {
|
|
6387
|
+
return this.inlineQueue.push({ src: e, tokens: t2 }), t2;
|
|
6388
|
+
}
|
|
6389
|
+
inlineTokens(e, t2 = []) {
|
|
6390
|
+
let n = e, r = null;
|
|
6391
|
+
if (this.tokens.links) {
|
|
6392
|
+
let o = Object.keys(this.tokens.links);
|
|
6393
|
+
if (o.length > 0)
|
|
6394
|
+
for (;(r = this.tokenizer.rules.inline.reflinkSearch.exec(n)) != null; )
|
|
6395
|
+
o.includes(r[0].slice(r[0].lastIndexOf("[") + 1, -1)) && (n = n.slice(0, r.index) + "[" + "a".repeat(r[0].length - 2) + "]" + n.slice(this.tokenizer.rules.inline.reflinkSearch.lastIndex));
|
|
6396
|
+
}
|
|
6397
|
+
for (;(r = this.tokenizer.rules.inline.anyPunctuation.exec(n)) != null; )
|
|
6398
|
+
n = n.slice(0, r.index) + "++" + n.slice(this.tokenizer.rules.inline.anyPunctuation.lastIndex);
|
|
6399
|
+
let i;
|
|
6400
|
+
for (;(r = this.tokenizer.rules.inline.blockSkip.exec(n)) != null; )
|
|
6401
|
+
i = r[2] ? r[2].length : 0, n = n.slice(0, r.index + i) + "[" + "a".repeat(r[0].length - i - 2) + "]" + n.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);
|
|
6402
|
+
n = this.options.hooks?.emStrongMask?.call({ lexer: this }, n) ?? n;
|
|
6403
|
+
let s = false, a = "";
|
|
6404
|
+
for (;e; ) {
|
|
6405
|
+
s || (a = ""), s = false;
|
|
6406
|
+
let o;
|
|
6407
|
+
if (this.options.extensions?.inline?.some((p) => (o = p.call({ lexer: this }, e, t2)) ? (e = e.substring(o.raw.length), t2.push(o), true) : false))
|
|
6408
|
+
continue;
|
|
6409
|
+
if (o = this.tokenizer.escape(e)) {
|
|
6410
|
+
e = e.substring(o.raw.length), t2.push(o);
|
|
6411
|
+
continue;
|
|
7122
6412
|
}
|
|
7123
|
-
|
|
7124
|
-
|
|
7125
|
-
|
|
7126
|
-
|
|
7127
|
-
|
|
7128
|
-
|
|
7129
|
-
|
|
7130
|
-
|
|
7131
|
-
|
|
7132
|
-
|
|
7133
|
-
|
|
7134
|
-
|
|
7135
|
-
|
|
7136
|
-
|
|
7137
|
-
|
|
7138
|
-
|
|
7139
|
-
|
|
7140
|
-
|
|
7141
|
-
|
|
7142
|
-
|
|
7143
|
-
|
|
7144
|
-
|
|
7145
|
-
|
|
7146
|
-
|
|
7147
|
-
|
|
7148
|
-
|
|
6413
|
+
if (o = this.tokenizer.tag(e)) {
|
|
6414
|
+
e = e.substring(o.raw.length), t2.push(o);
|
|
6415
|
+
continue;
|
|
6416
|
+
}
|
|
6417
|
+
if (o = this.tokenizer.link(e)) {
|
|
6418
|
+
e = e.substring(o.raw.length), t2.push(o);
|
|
6419
|
+
continue;
|
|
6420
|
+
}
|
|
6421
|
+
if (o = this.tokenizer.reflink(e, this.tokens.links)) {
|
|
6422
|
+
e = e.substring(o.raw.length);
|
|
6423
|
+
let p = t2.at(-1);
|
|
6424
|
+
o.type === "text" && p?.type === "text" ? (p.raw += o.raw, p.text += o.text) : t2.push(o);
|
|
6425
|
+
continue;
|
|
6426
|
+
}
|
|
6427
|
+
if (o = this.tokenizer.emStrong(e, n, a)) {
|
|
6428
|
+
e = e.substring(o.raw.length), t2.push(o);
|
|
6429
|
+
continue;
|
|
6430
|
+
}
|
|
6431
|
+
if (o = this.tokenizer.codespan(e)) {
|
|
6432
|
+
e = e.substring(o.raw.length), t2.push(o);
|
|
6433
|
+
continue;
|
|
6434
|
+
}
|
|
6435
|
+
if (o = this.tokenizer.br(e)) {
|
|
6436
|
+
e = e.substring(o.raw.length), t2.push(o);
|
|
6437
|
+
continue;
|
|
6438
|
+
}
|
|
6439
|
+
if (o = this.tokenizer.del(e)) {
|
|
6440
|
+
e = e.substring(o.raw.length), t2.push(o);
|
|
6441
|
+
continue;
|
|
6442
|
+
}
|
|
6443
|
+
if (o = this.tokenizer.autolink(e)) {
|
|
6444
|
+
e = e.substring(o.raw.length), t2.push(o);
|
|
6445
|
+
continue;
|
|
6446
|
+
}
|
|
6447
|
+
if (!this.state.inLink && (o = this.tokenizer.url(e))) {
|
|
6448
|
+
e = e.substring(o.raw.length), t2.push(o);
|
|
6449
|
+
continue;
|
|
6450
|
+
}
|
|
6451
|
+
let l = e;
|
|
6452
|
+
if (this.options.extensions?.startInline) {
|
|
6453
|
+
let p = 1 / 0, c = e.slice(1), g;
|
|
6454
|
+
this.options.extensions.startInline.forEach((h2) => {
|
|
6455
|
+
g = h2.call({ lexer: this }, c), typeof g == "number" && g >= 0 && (p = Math.min(p, g));
|
|
6456
|
+
}), p < 1 / 0 && p >= 0 && (l = e.substring(0, p + 1));
|
|
6457
|
+
}
|
|
6458
|
+
if (o = this.tokenizer.inlineText(l)) {
|
|
6459
|
+
e = e.substring(o.raw.length), o.raw.slice(-1) !== "_" && (a = o.raw.slice(-1)), s = true;
|
|
6460
|
+
let p = t2.at(-1);
|
|
6461
|
+
p?.type === "text" ? (p.raw += o.raw, p.text += o.text) : t2.push(o);
|
|
6462
|
+
continue;
|
|
6463
|
+
}
|
|
6464
|
+
if (e) {
|
|
6465
|
+
let p = "Infinite loop on byte: " + e.charCodeAt(0);
|
|
6466
|
+
if (this.options.silent) {
|
|
6467
|
+
console.error(p);
|
|
6468
|
+
break;
|
|
6469
|
+
} else
|
|
6470
|
+
throw new Error(p);
|
|
7149
6471
|
}
|
|
7150
|
-
if (i.loose)
|
|
7151
|
-
for (let l of i.items) {
|
|
7152
|
-
l.loose = true;
|
|
7153
|
-
for (let p of l.tokens)
|
|
7154
|
-
p.type === "text" && (p.type = "paragraph");
|
|
7155
|
-
}
|
|
7156
|
-
return i;
|
|
7157
6472
|
}
|
|
6473
|
+
return t2;
|
|
6474
|
+
}
|
|
6475
|
+
};
|
|
6476
|
+
var P = class {
|
|
6477
|
+
options;
|
|
6478
|
+
parser;
|
|
6479
|
+
constructor(e) {
|
|
6480
|
+
this.options = e || T;
|
|
6481
|
+
}
|
|
6482
|
+
space(e) {
|
|
6483
|
+
return "";
|
|
6484
|
+
}
|
|
6485
|
+
code({ text: e, lang: t2, escaped: n }) {
|
|
6486
|
+
let r = (t2 || "").match(m.notSpaceStart)?.[0], i = e.replace(m.endingNewline, "") + `
|
|
6487
|
+
`;
|
|
6488
|
+
return r ? '<pre><code class="language-' + w(r) + '">' + (n ? i : w(i, true)) + `</code></pre>
|
|
6489
|
+
` : "<pre><code>" + (n ? i : w(i, true)) + `</code></pre>
|
|
6490
|
+
`;
|
|
7158
6491
|
}
|
|
7159
|
-
|
|
7160
|
-
|
|
7161
|
-
|
|
7162
|
-
|
|
6492
|
+
blockquote({ tokens: e }) {
|
|
6493
|
+
return `<blockquote>
|
|
6494
|
+
${this.parser.parse(e)}</blockquote>
|
|
6495
|
+
`;
|
|
6496
|
+
}
|
|
6497
|
+
html({ text: e }) {
|
|
6498
|
+
return e;
|
|
7163
6499
|
}
|
|
7164
6500
|
def(e) {
|
|
7165
|
-
|
|
7166
|
-
if (t2) {
|
|
7167
|
-
let n = t2[1].toLowerCase().replace(this.rules.other.multipleSpaceGlobal, " "), r = t2[2] ? t2[2].replace(this.rules.other.hrefBrackets, "$1").replace(this.rules.inline.anyPunctuation, "$1") : "", i = t2[3] ? t2[3].substring(1, t2[3].length - 1).replace(this.rules.inline.anyPunctuation, "$1") : t2[3];
|
|
7168
|
-
return { type: "def", tag: n, raw: t2[0], href: r, title: i };
|
|
7169
|
-
}
|
|
6501
|
+
return "";
|
|
7170
6502
|
}
|
|
7171
|
-
|
|
7172
|
-
|
|
7173
|
-
|
|
7174
|
-
return;
|
|
7175
|
-
let n = J(t2[1]), r = t2[2].replace(this.rules.other.tableAlignChars, "").split("|"), i = t2[3]?.trim() ? t2[3].replace(this.rules.other.tableRowBlankLine, "").split(`
|
|
7176
|
-
`) : [], s = { type: "table", raw: t2[0], header: [], align: [], rows: [] };
|
|
7177
|
-
if (n.length === r.length) {
|
|
7178
|
-
for (let a of r)
|
|
7179
|
-
this.rules.other.tableAlignRight.test(a) ? s.align.push("right") : this.rules.other.tableAlignCenter.test(a) ? s.align.push("center") : this.rules.other.tableAlignLeft.test(a) ? s.align.push("left") : s.align.push(null);
|
|
7180
|
-
for (let a = 0;a < n.length; a++)
|
|
7181
|
-
s.header.push({ text: n[a], tokens: this.lexer.inline(n[a]), header: true, align: s.align[a] });
|
|
7182
|
-
for (let a of i)
|
|
7183
|
-
s.rows.push(J(a, s.header.length).map((o, l) => ({ text: o, tokens: this.lexer.inline(o), header: false, align: s.align[l] })));
|
|
7184
|
-
return s;
|
|
7185
|
-
}
|
|
6503
|
+
heading({ tokens: e, depth: t2 }) {
|
|
6504
|
+
return `<h${t2}>${this.parser.parseInline(e)}</h${t2}>
|
|
6505
|
+
`;
|
|
7186
6506
|
}
|
|
7187
|
-
|
|
7188
|
-
|
|
7189
|
-
|
|
7190
|
-
return { type: "heading", raw: t2[0], depth: t2[2].charAt(0) === "=" ? 1 : 2, text: t2[1], tokens: this.lexer.inline(t2[1]) };
|
|
6507
|
+
hr(e) {
|
|
6508
|
+
return `<hr>
|
|
6509
|
+
`;
|
|
7191
6510
|
}
|
|
7192
|
-
|
|
7193
|
-
let t2 =
|
|
7194
|
-
|
|
7195
|
-
let
|
|
7196
|
-
|
|
7197
|
-
return { type: "paragraph", raw: t2[0], text: n, tokens: this.lexer.inline(n) };
|
|
6511
|
+
list(e) {
|
|
6512
|
+
let { ordered: t2, start: n } = e, r = "";
|
|
6513
|
+
for (let a = 0;a < e.items.length; a++) {
|
|
6514
|
+
let o = e.items[a];
|
|
6515
|
+
r += this.listitem(o);
|
|
7198
6516
|
}
|
|
6517
|
+
let i = t2 ? "ol" : "ul", s = t2 && n !== 1 ? ' start="' + n + '"' : "";
|
|
6518
|
+
return "<" + i + s + `>
|
|
6519
|
+
` + r + "</" + i + `>
|
|
6520
|
+
`;
|
|
7199
6521
|
}
|
|
7200
|
-
|
|
7201
|
-
|
|
7202
|
-
|
|
7203
|
-
return { type: "text", raw: t2[0], text: t2[0], tokens: this.lexer.inline(t2[0]) };
|
|
6522
|
+
listitem(e) {
|
|
6523
|
+
return `<li>${this.parser.parse(e.tokens)}</li>
|
|
6524
|
+
`;
|
|
7204
6525
|
}
|
|
7205
|
-
|
|
7206
|
-
|
|
7207
|
-
if (t2)
|
|
7208
|
-
return { type: "escape", raw: t2[0], text: t2[1] };
|
|
6526
|
+
checkbox({ checked: e }) {
|
|
6527
|
+
return "<input " + (e ? 'checked="" ' : "") + 'disabled="" type="checkbox"> ';
|
|
7209
6528
|
}
|
|
7210
|
-
|
|
7211
|
-
|
|
7212
|
-
|
|
7213
|
-
return !this.lexer.state.inLink && this.rules.other.startATag.test(t2[0]) ? this.lexer.state.inLink = true : this.lexer.state.inLink && this.rules.other.endATag.test(t2[0]) && (this.lexer.state.inLink = false), !this.lexer.state.inRawBlock && this.rules.other.startPreScriptTag.test(t2[0]) ? this.lexer.state.inRawBlock = true : this.lexer.state.inRawBlock && this.rules.other.endPreScriptTag.test(t2[0]) && (this.lexer.state.inRawBlock = false), { type: "html", raw: t2[0], inLink: this.lexer.state.inLink, inRawBlock: this.lexer.state.inRawBlock, block: false, text: t2[0] };
|
|
6529
|
+
paragraph({ tokens: e }) {
|
|
6530
|
+
return `<p>${this.parser.parseInline(e)}</p>
|
|
6531
|
+
`;
|
|
7214
6532
|
}
|
|
7215
|
-
|
|
7216
|
-
let t2 =
|
|
7217
|
-
|
|
7218
|
-
|
|
7219
|
-
|
|
7220
|
-
|
|
7221
|
-
|
|
7222
|
-
|
|
7223
|
-
|
|
7224
|
-
|
|
7225
|
-
|
|
7226
|
-
|
|
7227
|
-
if (s === -2)
|
|
7228
|
-
return;
|
|
7229
|
-
if (s > -1) {
|
|
7230
|
-
let o = (t2[0].indexOf("!") === 0 ? 5 : 4) + t2[1].length + s;
|
|
7231
|
-
t2[2] = t2[2].substring(0, s), t2[0] = t2[0].substring(0, o).trim(), t2[3] = "";
|
|
7232
|
-
}
|
|
7233
|
-
}
|
|
7234
|
-
let r = t2[2], i = "";
|
|
7235
|
-
if (this.options.pedantic) {
|
|
7236
|
-
let s = this.rules.other.pedanticHrefTitle.exec(r);
|
|
7237
|
-
s && (r = s[1], i = s[3]);
|
|
7238
|
-
} else
|
|
7239
|
-
i = t2[3] ? t2[3].slice(1, -1) : "";
|
|
7240
|
-
return r = r.trim(), this.rules.other.startAngleBracket.test(r) && (this.options.pedantic && !this.rules.other.endAngleBracket.test(n) ? r = r.slice(1) : r = r.slice(1, -1)), ge(t2, { href: r && r.replace(this.rules.inline.anyPunctuation, "$1"), title: i && i.replace(this.rules.inline.anyPunctuation, "$1") }, t2[0], this.lexer, this.rules);
|
|
6533
|
+
table(e) {
|
|
6534
|
+
let t2 = "", n = "";
|
|
6535
|
+
for (let i = 0;i < e.header.length; i++)
|
|
6536
|
+
n += this.tablecell(e.header[i]);
|
|
6537
|
+
t2 += this.tablerow({ text: n });
|
|
6538
|
+
let r = "";
|
|
6539
|
+
for (let i = 0;i < e.rows.length; i++) {
|
|
6540
|
+
let s = e.rows[i];
|
|
6541
|
+
n = "";
|
|
6542
|
+
for (let a = 0;a < s.length; a++)
|
|
6543
|
+
n += this.tablecell(s[a]);
|
|
6544
|
+
r += this.tablerow({ text: n });
|
|
7241
6545
|
}
|
|
6546
|
+
return r && (r = `<tbody>${r}</tbody>`), `<table>
|
|
6547
|
+
<thead>
|
|
6548
|
+
` + t2 + `</thead>
|
|
6549
|
+
` + r + `</table>
|
|
6550
|
+
`;
|
|
7242
6551
|
}
|
|
7243
|
-
|
|
7244
|
-
|
|
7245
|
-
|
|
7246
|
-
|
|
7247
|
-
if (!i) {
|
|
7248
|
-
let s = n[0].charAt(0);
|
|
7249
|
-
return { type: "text", raw: s, text: s };
|
|
7250
|
-
}
|
|
7251
|
-
return ge(n, i, n[0], this.lexer, this.rules);
|
|
7252
|
-
}
|
|
6552
|
+
tablerow({ text: e }) {
|
|
6553
|
+
return `<tr>
|
|
6554
|
+
${e}</tr>
|
|
6555
|
+
`;
|
|
7253
6556
|
}
|
|
7254
|
-
|
|
7255
|
-
let
|
|
7256
|
-
|
|
7257
|
-
|
|
7258
|
-
if (!(r[1] || r[2] || "") || !n || this.rules.inline.punctuation.exec(n)) {
|
|
7259
|
-
let s = [...r[0]].length - 1, a, o, l = s, p = 0, c = r[0][0] === "*" ? this.rules.inline.emStrongRDelimAst : this.rules.inline.emStrongRDelimUnd;
|
|
7260
|
-
for (c.lastIndex = 0, t2 = t2.slice(-1 * e.length + s);(r = c.exec(t2)) != null; ) {
|
|
7261
|
-
if (a = r[1] || r[2] || r[3] || r[4] || r[5] || r[6], !a)
|
|
7262
|
-
continue;
|
|
7263
|
-
if (o = [...a].length, r[3] || r[4]) {
|
|
7264
|
-
l += o;
|
|
7265
|
-
continue;
|
|
7266
|
-
} else if ((r[5] || r[6]) && s % 3 && !((s + o) % 3)) {
|
|
7267
|
-
p += o;
|
|
7268
|
-
continue;
|
|
7269
|
-
}
|
|
7270
|
-
if (l -= o, l > 0)
|
|
7271
|
-
continue;
|
|
7272
|
-
o = Math.min(o, o + l + p);
|
|
7273
|
-
let g = [...r[0]][0].length, h2 = e.slice(0, s + r.index + g + o);
|
|
7274
|
-
if (Math.min(s, o) % 2) {
|
|
7275
|
-
let f = h2.slice(1, -1);
|
|
7276
|
-
return { type: "em", raw: h2, text: f, tokens: this.lexer.inlineTokens(f) };
|
|
7277
|
-
}
|
|
7278
|
-
let R = h2.slice(2, -2);
|
|
7279
|
-
return { type: "strong", raw: h2, text: R, tokens: this.lexer.inlineTokens(R) };
|
|
7280
|
-
}
|
|
7281
|
-
}
|
|
6557
|
+
tablecell(e) {
|
|
6558
|
+
let t2 = this.parser.parseInline(e.tokens), n = e.header ? "th" : "td";
|
|
6559
|
+
return (e.align ? `<${n} align="${e.align}">` : `<${n}>`) + t2 + `</${n}>
|
|
6560
|
+
`;
|
|
7282
6561
|
}
|
|
7283
|
-
|
|
7284
|
-
|
|
7285
|
-
|
|
7286
|
-
|
|
7287
|
-
|
|
7288
|
-
|
|
6562
|
+
strong({ tokens: e }) {
|
|
6563
|
+
return `<strong>${this.parser.parseInline(e)}</strong>`;
|
|
6564
|
+
}
|
|
6565
|
+
em({ tokens: e }) {
|
|
6566
|
+
return `<em>${this.parser.parseInline(e)}</em>`;
|
|
6567
|
+
}
|
|
6568
|
+
codespan({ text: e }) {
|
|
6569
|
+
return `<code>${w(e, true)}</code>`;
|
|
7289
6570
|
}
|
|
7290
6571
|
br(e) {
|
|
7291
|
-
|
|
7292
|
-
if (t2)
|
|
7293
|
-
return { type: "br", raw: t2[0] };
|
|
6572
|
+
return "<br>";
|
|
7294
6573
|
}
|
|
7295
|
-
del(e) {
|
|
7296
|
-
|
|
7297
|
-
if (t2)
|
|
7298
|
-
return { type: "del", raw: t2[0], text: t2[2], tokens: this.lexer.inlineTokens(t2[2]) };
|
|
6574
|
+
del({ tokens: e }) {
|
|
6575
|
+
return `<del>${this.parser.parseInline(e)}</del>`;
|
|
7299
6576
|
}
|
|
7300
|
-
|
|
7301
|
-
let
|
|
7302
|
-
if (
|
|
7303
|
-
|
|
7304
|
-
|
|
7305
|
-
|
|
6577
|
+
link({ href: e, title: t2, tokens: n }) {
|
|
6578
|
+
let r = this.parser.parseInline(n), i = X(e);
|
|
6579
|
+
if (i === null)
|
|
6580
|
+
return r;
|
|
6581
|
+
e = i;
|
|
6582
|
+
let s = '<a href="' + e + '"';
|
|
6583
|
+
return t2 && (s += ' title="' + w(t2) + '"'), s += ">" + r + "</a>", s;
|
|
7306
6584
|
}
|
|
7307
|
-
|
|
7308
|
-
|
|
7309
|
-
|
|
7310
|
-
|
|
7311
|
-
|
|
7312
|
-
|
|
7313
|
-
|
|
7314
|
-
|
|
7315
|
-
|
|
7316
|
-
|
|
7317
|
-
|
|
7318
|
-
|
|
7319
|
-
|
|
7320
|
-
|
|
7321
|
-
|
|
6585
|
+
image({ href: e, title: t2, text: n, tokens: r }) {
|
|
6586
|
+
r && (n = this.parser.parseInline(r, this.parser.textRenderer));
|
|
6587
|
+
let i = X(e);
|
|
6588
|
+
if (i === null)
|
|
6589
|
+
return w(n);
|
|
6590
|
+
e = i;
|
|
6591
|
+
let s = `<img src="${e}" alt="${n}"`;
|
|
6592
|
+
return t2 && (s += ` title="${w(t2)}"`), s += ">", s;
|
|
6593
|
+
}
|
|
6594
|
+
text(e) {
|
|
6595
|
+
return "tokens" in e && e.tokens ? this.parser.parseInline(e.tokens) : ("escaped" in e) && e.escaped ? e.text : w(e.text);
|
|
6596
|
+
}
|
|
6597
|
+
};
|
|
6598
|
+
var $ = class {
|
|
6599
|
+
strong({ text: e }) {
|
|
6600
|
+
return e;
|
|
6601
|
+
}
|
|
6602
|
+
em({ text: e }) {
|
|
6603
|
+
return e;
|
|
6604
|
+
}
|
|
6605
|
+
codespan({ text: e }) {
|
|
6606
|
+
return e;
|
|
6607
|
+
}
|
|
6608
|
+
del({ text: e }) {
|
|
6609
|
+
return e;
|
|
6610
|
+
}
|
|
6611
|
+
html({ text: e }) {
|
|
6612
|
+
return e;
|
|
6613
|
+
}
|
|
6614
|
+
text({ text: e }) {
|
|
6615
|
+
return e;
|
|
6616
|
+
}
|
|
6617
|
+
link({ text: e }) {
|
|
6618
|
+
return "" + e;
|
|
7322
6619
|
}
|
|
7323
|
-
|
|
7324
|
-
|
|
7325
|
-
|
|
7326
|
-
|
|
7327
|
-
|
|
7328
|
-
|
|
6620
|
+
image({ text: e }) {
|
|
6621
|
+
return "" + e;
|
|
6622
|
+
}
|
|
6623
|
+
br() {
|
|
6624
|
+
return "";
|
|
6625
|
+
}
|
|
6626
|
+
checkbox({ raw: e }) {
|
|
6627
|
+
return e;
|
|
7329
6628
|
}
|
|
7330
6629
|
};
|
|
7331
|
-
var
|
|
7332
|
-
tokens;
|
|
6630
|
+
var b = class u2 {
|
|
7333
6631
|
options;
|
|
7334
|
-
|
|
7335
|
-
|
|
7336
|
-
tokenizer;
|
|
6632
|
+
renderer;
|
|
6633
|
+
textRenderer;
|
|
7337
6634
|
constructor(e) {
|
|
7338
|
-
this.
|
|
7339
|
-
let t2 = { other: m, block: E.normal, inline: M.normal };
|
|
7340
|
-
this.options.pedantic ? (t2.block = E.pedantic, t2.inline = M.pedantic) : this.options.gfm && (t2.block = E.gfm, this.options.breaks ? t2.inline = M.breaks : t2.inline = M.gfm), this.tokenizer.rules = t2;
|
|
7341
|
-
}
|
|
7342
|
-
static get rules() {
|
|
7343
|
-
return { block: E, inline: M };
|
|
7344
|
-
}
|
|
7345
|
-
static lex(e, t2) {
|
|
7346
|
-
return new u(t2).lex(e);
|
|
6635
|
+
this.options = e || T, this.options.renderer = this.options.renderer || new P, this.renderer = this.options.renderer, this.renderer.options = this.options, this.renderer.parser = this, this.textRenderer = new $;
|
|
7347
6636
|
}
|
|
7348
|
-
static
|
|
7349
|
-
return new
|
|
6637
|
+
static parse(e, t2) {
|
|
6638
|
+
return new u2(t2).parse(e);
|
|
7350
6639
|
}
|
|
7351
|
-
|
|
7352
|
-
|
|
7353
|
-
`), this.blockTokens(e, this.tokens);
|
|
7354
|
-
for (let t2 = 0;t2 < this.inlineQueue.length; t2++) {
|
|
7355
|
-
let n = this.inlineQueue[t2];
|
|
7356
|
-
this.inlineTokens(n.src, n.tokens);
|
|
7357
|
-
}
|
|
7358
|
-
return this.inlineQueue = [], this.tokens;
|
|
6640
|
+
static parseInline(e, t2) {
|
|
6641
|
+
return new u2(t2).parseInline(e);
|
|
7359
6642
|
}
|
|
7360
|
-
|
|
7361
|
-
|
|
7362
|
-
|
|
7363
|
-
|
|
7364
|
-
|
|
7365
|
-
|
|
7366
|
-
|
|
7367
|
-
|
|
7368
|
-
|
|
7369
|
-
|
|
7370
|
-
continue;
|
|
7371
|
-
}
|
|
7372
|
-
if (r = this.tokenizer.code(e)) {
|
|
7373
|
-
e = e.substring(r.raw.length);
|
|
7374
|
-
let s = t2.at(-1);
|
|
7375
|
-
s?.type === "paragraph" || s?.type === "text" ? (s.raw += (s.raw.endsWith(`
|
|
7376
|
-
`) ? "" : `
|
|
7377
|
-
`) + r.raw, s.text += `
|
|
7378
|
-
` + r.text, this.inlineQueue.at(-1).src = s.text) : t2.push(r);
|
|
7379
|
-
continue;
|
|
7380
|
-
}
|
|
7381
|
-
if (r = this.tokenizer.fences(e)) {
|
|
7382
|
-
e = e.substring(r.raw.length), t2.push(r);
|
|
7383
|
-
continue;
|
|
7384
|
-
}
|
|
7385
|
-
if (r = this.tokenizer.heading(e)) {
|
|
7386
|
-
e = e.substring(r.raw.length), t2.push(r);
|
|
7387
|
-
continue;
|
|
7388
|
-
}
|
|
7389
|
-
if (r = this.tokenizer.hr(e)) {
|
|
7390
|
-
e = e.substring(r.raw.length), t2.push(r);
|
|
7391
|
-
continue;
|
|
7392
|
-
}
|
|
7393
|
-
if (r = this.tokenizer.blockquote(e)) {
|
|
7394
|
-
e = e.substring(r.raw.length), t2.push(r);
|
|
7395
|
-
continue;
|
|
7396
|
-
}
|
|
7397
|
-
if (r = this.tokenizer.list(e)) {
|
|
7398
|
-
e = e.substring(r.raw.length), t2.push(r);
|
|
7399
|
-
continue;
|
|
7400
|
-
}
|
|
7401
|
-
if (r = this.tokenizer.html(e)) {
|
|
7402
|
-
e = e.substring(r.raw.length), t2.push(r);
|
|
7403
|
-
continue;
|
|
7404
|
-
}
|
|
7405
|
-
if (r = this.tokenizer.def(e)) {
|
|
7406
|
-
e = e.substring(r.raw.length);
|
|
7407
|
-
let s = t2.at(-1);
|
|
7408
|
-
s?.type === "paragraph" || s?.type === "text" ? (s.raw += (s.raw.endsWith(`
|
|
7409
|
-
`) ? "" : `
|
|
7410
|
-
`) + r.raw, s.text += `
|
|
7411
|
-
` + r.raw, this.inlineQueue.at(-1).src = s.text) : this.tokens.links[r.tag] || (this.tokens.links[r.tag] = { href: r.href, title: r.title }, t2.push(r));
|
|
7412
|
-
continue;
|
|
7413
|
-
}
|
|
7414
|
-
if (r = this.tokenizer.table(e)) {
|
|
7415
|
-
e = e.substring(r.raw.length), t2.push(r);
|
|
7416
|
-
continue;
|
|
7417
|
-
}
|
|
7418
|
-
if (r = this.tokenizer.lheading(e)) {
|
|
7419
|
-
e = e.substring(r.raw.length), t2.push(r);
|
|
7420
|
-
continue;
|
|
7421
|
-
}
|
|
7422
|
-
let i = e;
|
|
7423
|
-
if (this.options.extensions?.startBlock) {
|
|
7424
|
-
let s = 1 / 0, a = e.slice(1), o;
|
|
7425
|
-
this.options.extensions.startBlock.forEach((l) => {
|
|
7426
|
-
o = l.call({ lexer: this }, a), typeof o == "number" && o >= 0 && (s = Math.min(s, o));
|
|
7427
|
-
}), s < 1 / 0 && s >= 0 && (i = e.substring(0, s + 1));
|
|
6643
|
+
parse(e) {
|
|
6644
|
+
let t2 = "";
|
|
6645
|
+
for (let n = 0;n < e.length; n++) {
|
|
6646
|
+
let r = e[n];
|
|
6647
|
+
if (this.options.extensions?.renderers?.[r.type]) {
|
|
6648
|
+
let s = r, a = this.options.extensions.renderers[s.type].call({ parser: this }, s);
|
|
6649
|
+
if (a !== false || !["space", "hr", "heading", "code", "table", "blockquote", "list", "html", "def", "paragraph", "text"].includes(s.type)) {
|
|
6650
|
+
t2 += a || "";
|
|
6651
|
+
continue;
|
|
6652
|
+
}
|
|
7428
6653
|
}
|
|
7429
|
-
|
|
7430
|
-
|
|
7431
|
-
|
|
7432
|
-
|
|
7433
|
-
|
|
7434
|
-
|
|
7435
|
-
|
|
6654
|
+
let i = r;
|
|
6655
|
+
switch (i.type) {
|
|
6656
|
+
case "space": {
|
|
6657
|
+
t2 += this.renderer.space(i);
|
|
6658
|
+
break;
|
|
6659
|
+
}
|
|
6660
|
+
case "hr": {
|
|
6661
|
+
t2 += this.renderer.hr(i);
|
|
6662
|
+
break;
|
|
6663
|
+
}
|
|
6664
|
+
case "heading": {
|
|
6665
|
+
t2 += this.renderer.heading(i);
|
|
6666
|
+
break;
|
|
6667
|
+
}
|
|
6668
|
+
case "code": {
|
|
6669
|
+
t2 += this.renderer.code(i);
|
|
6670
|
+
break;
|
|
6671
|
+
}
|
|
6672
|
+
case "table": {
|
|
6673
|
+
t2 += this.renderer.table(i);
|
|
6674
|
+
break;
|
|
6675
|
+
}
|
|
6676
|
+
case "blockquote": {
|
|
6677
|
+
t2 += this.renderer.blockquote(i);
|
|
6678
|
+
break;
|
|
6679
|
+
}
|
|
6680
|
+
case "list": {
|
|
6681
|
+
t2 += this.renderer.list(i);
|
|
6682
|
+
break;
|
|
6683
|
+
}
|
|
6684
|
+
case "checkbox": {
|
|
6685
|
+
t2 += this.renderer.checkbox(i);
|
|
6686
|
+
break;
|
|
6687
|
+
}
|
|
6688
|
+
case "html": {
|
|
6689
|
+
t2 += this.renderer.html(i);
|
|
6690
|
+
break;
|
|
6691
|
+
}
|
|
6692
|
+
case "def": {
|
|
6693
|
+
t2 += this.renderer.def(i);
|
|
6694
|
+
break;
|
|
6695
|
+
}
|
|
6696
|
+
case "paragraph": {
|
|
6697
|
+
t2 += this.renderer.paragraph(i);
|
|
6698
|
+
break;
|
|
6699
|
+
}
|
|
6700
|
+
case "text": {
|
|
6701
|
+
t2 += this.renderer.text(i);
|
|
6702
|
+
break;
|
|
6703
|
+
}
|
|
6704
|
+
default: {
|
|
6705
|
+
let s = 'Token with "' + i.type + '" type was not found.';
|
|
6706
|
+
if (this.options.silent)
|
|
6707
|
+
return console.error(s), "";
|
|
6708
|
+
throw new Error(s);
|
|
6709
|
+
}
|
|
7436
6710
|
}
|
|
7437
|
-
|
|
7438
|
-
|
|
7439
|
-
|
|
7440
|
-
|
|
7441
|
-
|
|
7442
|
-
|
|
7443
|
-
|
|
7444
|
-
|
|
6711
|
+
}
|
|
6712
|
+
return t2;
|
|
6713
|
+
}
|
|
6714
|
+
parseInline(e, t2 = this.renderer) {
|
|
6715
|
+
let n = "";
|
|
6716
|
+
for (let r = 0;r < e.length; r++) {
|
|
6717
|
+
let i = e[r];
|
|
6718
|
+
if (this.options.extensions?.renderers?.[i.type]) {
|
|
6719
|
+
let a = this.options.extensions.renderers[i.type].call({ parser: this }, i);
|
|
6720
|
+
if (a !== false || !["escape", "html", "link", "image", "strong", "em", "codespan", "br", "del", "text"].includes(i.type)) {
|
|
6721
|
+
n += a || "";
|
|
6722
|
+
continue;
|
|
6723
|
+
}
|
|
7445
6724
|
}
|
|
7446
|
-
|
|
7447
|
-
|
|
7448
|
-
|
|
7449
|
-
|
|
6725
|
+
let s = i;
|
|
6726
|
+
switch (s.type) {
|
|
6727
|
+
case "escape": {
|
|
6728
|
+
n += t2.text(s);
|
|
6729
|
+
break;
|
|
6730
|
+
}
|
|
6731
|
+
case "html": {
|
|
6732
|
+
n += t2.html(s);
|
|
6733
|
+
break;
|
|
6734
|
+
}
|
|
6735
|
+
case "link": {
|
|
6736
|
+
n += t2.link(s);
|
|
6737
|
+
break;
|
|
6738
|
+
}
|
|
6739
|
+
case "image": {
|
|
6740
|
+
n += t2.image(s);
|
|
6741
|
+
break;
|
|
6742
|
+
}
|
|
6743
|
+
case "checkbox": {
|
|
6744
|
+
n += t2.checkbox(s);
|
|
6745
|
+
break;
|
|
6746
|
+
}
|
|
6747
|
+
case "strong": {
|
|
6748
|
+
n += t2.strong(s);
|
|
6749
|
+
break;
|
|
6750
|
+
}
|
|
6751
|
+
case "em": {
|
|
6752
|
+
n += t2.em(s);
|
|
6753
|
+
break;
|
|
6754
|
+
}
|
|
6755
|
+
case "codespan": {
|
|
6756
|
+
n += t2.codespan(s);
|
|
6757
|
+
break;
|
|
6758
|
+
}
|
|
6759
|
+
case "br": {
|
|
6760
|
+
n += t2.br(s);
|
|
6761
|
+
break;
|
|
6762
|
+
}
|
|
6763
|
+
case "del": {
|
|
6764
|
+
n += t2.del(s);
|
|
6765
|
+
break;
|
|
6766
|
+
}
|
|
6767
|
+
case "text": {
|
|
6768
|
+
n += t2.text(s);
|
|
7450
6769
|
break;
|
|
7451
|
-
}
|
|
7452
|
-
|
|
6770
|
+
}
|
|
6771
|
+
default: {
|
|
6772
|
+
let a = 'Token with "' + s.type + '" type was not found.';
|
|
6773
|
+
if (this.options.silent)
|
|
6774
|
+
return console.error(a), "";
|
|
6775
|
+
throw new Error(a);
|
|
6776
|
+
}
|
|
7453
6777
|
}
|
|
7454
6778
|
}
|
|
7455
|
-
return
|
|
6779
|
+
return n;
|
|
7456
6780
|
}
|
|
7457
|
-
|
|
7458
|
-
|
|
6781
|
+
};
|
|
6782
|
+
var S = class {
|
|
6783
|
+
options;
|
|
6784
|
+
block;
|
|
6785
|
+
constructor(e) {
|
|
6786
|
+
this.options = e || T;
|
|
7459
6787
|
}
|
|
7460
|
-
|
|
7461
|
-
|
|
7462
|
-
|
|
7463
|
-
|
|
7464
|
-
|
|
7465
|
-
|
|
7466
|
-
|
|
7467
|
-
|
|
7468
|
-
|
|
7469
|
-
|
|
7470
|
-
|
|
7471
|
-
|
|
7472
|
-
|
|
7473
|
-
|
|
7474
|
-
|
|
7475
|
-
|
|
7476
|
-
|
|
7477
|
-
|
|
7478
|
-
|
|
7479
|
-
|
|
7480
|
-
|
|
7481
|
-
|
|
7482
|
-
|
|
7483
|
-
|
|
7484
|
-
|
|
7485
|
-
|
|
7486
|
-
|
|
7487
|
-
|
|
7488
|
-
|
|
7489
|
-
|
|
7490
|
-
|
|
7491
|
-
|
|
7492
|
-
|
|
7493
|
-
|
|
7494
|
-
|
|
7495
|
-
|
|
7496
|
-
|
|
7497
|
-
|
|
7498
|
-
|
|
7499
|
-
|
|
7500
|
-
|
|
7501
|
-
|
|
7502
|
-
|
|
7503
|
-
|
|
7504
|
-
|
|
6788
|
+
static passThroughHooks = new Set(["preprocess", "postprocess", "processAllTokens", "emStrongMask"]);
|
|
6789
|
+
static passThroughHooksRespectAsync = new Set(["preprocess", "postprocess", "processAllTokens"]);
|
|
6790
|
+
preprocess(e) {
|
|
6791
|
+
return e;
|
|
6792
|
+
}
|
|
6793
|
+
postprocess(e) {
|
|
6794
|
+
return e;
|
|
6795
|
+
}
|
|
6796
|
+
processAllTokens(e) {
|
|
6797
|
+
return e;
|
|
6798
|
+
}
|
|
6799
|
+
emStrongMask(e) {
|
|
6800
|
+
return e;
|
|
6801
|
+
}
|
|
6802
|
+
provideLexer() {
|
|
6803
|
+
return this.block ? x.lex : x.lexInline;
|
|
6804
|
+
}
|
|
6805
|
+
provideParser() {
|
|
6806
|
+
return this.block ? b.parse : b.parseInline;
|
|
6807
|
+
}
|
|
6808
|
+
};
|
|
6809
|
+
var B = class {
|
|
6810
|
+
defaults = L();
|
|
6811
|
+
options = this.setOptions;
|
|
6812
|
+
parse = this.parseMarkdown(true);
|
|
6813
|
+
parseInline = this.parseMarkdown(false);
|
|
6814
|
+
Parser = b;
|
|
6815
|
+
Renderer = P;
|
|
6816
|
+
TextRenderer = $;
|
|
6817
|
+
Lexer = x;
|
|
6818
|
+
Tokenizer = y;
|
|
6819
|
+
Hooks = S;
|
|
6820
|
+
constructor(...e) {
|
|
6821
|
+
this.use(...e);
|
|
6822
|
+
}
|
|
6823
|
+
walkTokens(e, t2) {
|
|
6824
|
+
let n = [];
|
|
6825
|
+
for (let r of e)
|
|
6826
|
+
switch (n = n.concat(t2.call(this, r)), r.type) {
|
|
6827
|
+
case "table": {
|
|
6828
|
+
let i = r;
|
|
6829
|
+
for (let s of i.header)
|
|
6830
|
+
n = n.concat(this.walkTokens(s.tokens, t2));
|
|
6831
|
+
for (let s of i.rows)
|
|
6832
|
+
for (let a of s)
|
|
6833
|
+
n = n.concat(this.walkTokens(a.tokens, t2));
|
|
6834
|
+
break;
|
|
6835
|
+
}
|
|
6836
|
+
case "list": {
|
|
6837
|
+
let i = r;
|
|
6838
|
+
n = n.concat(this.walkTokens(i.items, t2));
|
|
6839
|
+
break;
|
|
6840
|
+
}
|
|
6841
|
+
default: {
|
|
6842
|
+
let i = r;
|
|
6843
|
+
this.defaults.extensions?.childTokens?.[i.type] ? this.defaults.extensions.childTokens[i.type].forEach((s) => {
|
|
6844
|
+
let a = i[s].flat(1 / 0);
|
|
6845
|
+
n = n.concat(this.walkTokens(a, t2));
|
|
6846
|
+
}) : i.tokens && (n = n.concat(this.walkTokens(i.tokens, t2)));
|
|
6847
|
+
}
|
|
7505
6848
|
}
|
|
7506
|
-
|
|
7507
|
-
|
|
7508
|
-
|
|
6849
|
+
return n;
|
|
6850
|
+
}
|
|
6851
|
+
use(...e) {
|
|
6852
|
+
let t2 = this.defaults.extensions || { renderers: {}, childTokens: {} };
|
|
6853
|
+
return e.forEach((n) => {
|
|
6854
|
+
let r = { ...n };
|
|
6855
|
+
if (r.async = this.defaults.async || r.async || false, n.extensions && (n.extensions.forEach((i) => {
|
|
6856
|
+
if (!i.name)
|
|
6857
|
+
throw new Error("extension name required");
|
|
6858
|
+
if ("renderer" in i) {
|
|
6859
|
+
let s = t2.renderers[i.name];
|
|
6860
|
+
s ? t2.renderers[i.name] = function(...a) {
|
|
6861
|
+
let o = i.renderer.apply(this, a);
|
|
6862
|
+
return o === false && (o = s.apply(this, a)), o;
|
|
6863
|
+
} : t2.renderers[i.name] = i.renderer;
|
|
6864
|
+
}
|
|
6865
|
+
if ("tokenizer" in i) {
|
|
6866
|
+
if (!i.level || i.level !== "block" && i.level !== "inline")
|
|
6867
|
+
throw new Error("extension level must be 'block' or 'inline'");
|
|
6868
|
+
let s = t2[i.level];
|
|
6869
|
+
s ? s.unshift(i.tokenizer) : t2[i.level] = [i.tokenizer], i.start && (i.level === "block" ? t2.startBlock ? t2.startBlock.push(i.start) : t2.startBlock = [i.start] : i.level === "inline" && (t2.startInline ? t2.startInline.push(i.start) : t2.startInline = [i.start]));
|
|
6870
|
+
}
|
|
6871
|
+
"childTokens" in i && i.childTokens && (t2.childTokens[i.name] = i.childTokens);
|
|
6872
|
+
}), r.extensions = t2), n.renderer) {
|
|
6873
|
+
let i = this.defaults.renderer || new P(this.defaults);
|
|
6874
|
+
for (let s in n.renderer) {
|
|
6875
|
+
if (!(s in i))
|
|
6876
|
+
throw new Error(`renderer '${s}' does not exist`);
|
|
6877
|
+
if (["options", "parser"].includes(s))
|
|
6878
|
+
continue;
|
|
6879
|
+
let a = s, o = n.renderer[a], l = i[a];
|
|
6880
|
+
i[a] = (...p) => {
|
|
6881
|
+
let c = o.apply(i, p);
|
|
6882
|
+
return c === false && (c = l.apply(i, p)), c || "";
|
|
6883
|
+
};
|
|
6884
|
+
}
|
|
6885
|
+
r.renderer = i;
|
|
7509
6886
|
}
|
|
7510
|
-
if (
|
|
7511
|
-
|
|
7512
|
-
|
|
6887
|
+
if (n.tokenizer) {
|
|
6888
|
+
let i = this.defaults.tokenizer || new y(this.defaults);
|
|
6889
|
+
for (let s in n.tokenizer) {
|
|
6890
|
+
if (!(s in i))
|
|
6891
|
+
throw new Error(`tokenizer '${s}' does not exist`);
|
|
6892
|
+
if (["options", "rules", "lexer"].includes(s))
|
|
6893
|
+
continue;
|
|
6894
|
+
let a = s, o = n.tokenizer[a], l = i[a];
|
|
6895
|
+
i[a] = (...p) => {
|
|
6896
|
+
let c = o.apply(i, p);
|
|
6897
|
+
return c === false && (c = l.apply(i, p)), c;
|
|
6898
|
+
};
|
|
6899
|
+
}
|
|
6900
|
+
r.tokenizer = i;
|
|
7513
6901
|
}
|
|
7514
|
-
if (
|
|
7515
|
-
|
|
7516
|
-
|
|
6902
|
+
if (n.hooks) {
|
|
6903
|
+
let i = this.defaults.hooks || new S;
|
|
6904
|
+
for (let s in n.hooks) {
|
|
6905
|
+
if (!(s in i))
|
|
6906
|
+
throw new Error(`hook '${s}' does not exist`);
|
|
6907
|
+
if (["options", "block"].includes(s))
|
|
6908
|
+
continue;
|
|
6909
|
+
let a = s, o = n.hooks[a], l = i[a];
|
|
6910
|
+
S.passThroughHooks.has(s) ? i[a] = (p) => {
|
|
6911
|
+
if (this.defaults.async && S.passThroughHooksRespectAsync.has(s))
|
|
6912
|
+
return (async () => {
|
|
6913
|
+
let g = await o.call(i, p);
|
|
6914
|
+
return l.call(i, g);
|
|
6915
|
+
})();
|
|
6916
|
+
let c = o.call(i, p);
|
|
6917
|
+
return l.call(i, c);
|
|
6918
|
+
} : i[a] = (...p) => {
|
|
6919
|
+
if (this.defaults.async)
|
|
6920
|
+
return (async () => {
|
|
6921
|
+
let g = await o.apply(i, p);
|
|
6922
|
+
return g === false && (g = await l.apply(i, p)), g;
|
|
6923
|
+
})();
|
|
6924
|
+
let c = o.apply(i, p);
|
|
6925
|
+
return c === false && (c = l.apply(i, p)), c;
|
|
6926
|
+
};
|
|
6927
|
+
}
|
|
6928
|
+
r.hooks = i;
|
|
7517
6929
|
}
|
|
7518
|
-
if (
|
|
7519
|
-
|
|
7520
|
-
|
|
6930
|
+
if (n.walkTokens) {
|
|
6931
|
+
let i = this.defaults.walkTokens, s = n.walkTokens;
|
|
6932
|
+
r.walkTokens = function(a) {
|
|
6933
|
+
let o = [];
|
|
6934
|
+
return o.push(s.call(this, a)), i && (o = o.concat(i.call(this, a))), o;
|
|
6935
|
+
};
|
|
7521
6936
|
}
|
|
7522
|
-
|
|
7523
|
-
|
|
7524
|
-
|
|
7525
|
-
|
|
7526
|
-
|
|
7527
|
-
|
|
6937
|
+
this.defaults = { ...this.defaults, ...r };
|
|
6938
|
+
}), this;
|
|
6939
|
+
}
|
|
6940
|
+
setOptions(e) {
|
|
6941
|
+
return this.defaults = { ...this.defaults, ...e }, this;
|
|
6942
|
+
}
|
|
6943
|
+
lexer(e, t2) {
|
|
6944
|
+
return x.lex(e, t2 ?? this.defaults);
|
|
6945
|
+
}
|
|
6946
|
+
parser(e, t2) {
|
|
6947
|
+
return b.parse(e, t2 ?? this.defaults);
|
|
6948
|
+
}
|
|
6949
|
+
parseMarkdown(e) {
|
|
6950
|
+
return (n, r) => {
|
|
6951
|
+
let i = { ...r }, s = { ...this.defaults, ...i }, a = this.onError(!!s.silent, !!s.async);
|
|
6952
|
+
if (this.defaults.async === true && i.async === false)
|
|
6953
|
+
return a(new Error("marked(): The async option was set to true by an extension. Remove async: false from the parse options object to return a Promise."));
|
|
6954
|
+
if (typeof n > "u" || n === null)
|
|
6955
|
+
return a(new Error("marked(): input parameter is undefined or null"));
|
|
6956
|
+
if (typeof n != "string")
|
|
6957
|
+
return a(new Error("marked(): input parameter is of type " + Object.prototype.toString.call(n) + ", string expected"));
|
|
6958
|
+
if (s.hooks && (s.hooks.options = s, s.hooks.block = e), s.async)
|
|
6959
|
+
return (async () => {
|
|
6960
|
+
let o = s.hooks ? await s.hooks.preprocess(n) : n, p = await (s.hooks ? await s.hooks.provideLexer() : e ? x.lex : x.lexInline)(o, s), c = s.hooks ? await s.hooks.processAllTokens(p) : p;
|
|
6961
|
+
s.walkTokens && await Promise.all(this.walkTokens(c, s.walkTokens));
|
|
6962
|
+
let h2 = await (s.hooks ? await s.hooks.provideParser() : e ? b.parse : b.parseInline)(c, s);
|
|
6963
|
+
return s.hooks ? await s.hooks.postprocess(h2) : h2;
|
|
6964
|
+
})().catch(a);
|
|
6965
|
+
try {
|
|
6966
|
+
s.hooks && (n = s.hooks.preprocess(n));
|
|
6967
|
+
let l = (s.hooks ? s.hooks.provideLexer() : e ? x.lex : x.lexInline)(n, s);
|
|
6968
|
+
s.hooks && (l = s.hooks.processAllTokens(l)), s.walkTokens && this.walkTokens(l, s.walkTokens);
|
|
6969
|
+
let c = (s.hooks ? s.hooks.provideParser() : e ? b.parse : b.parseInline)(l, s);
|
|
6970
|
+
return s.hooks && (c = s.hooks.postprocess(c)), c;
|
|
6971
|
+
} catch (o) {
|
|
6972
|
+
return a(o);
|
|
7528
6973
|
}
|
|
7529
|
-
|
|
7530
|
-
|
|
7531
|
-
|
|
7532
|
-
|
|
7533
|
-
|
|
6974
|
+
};
|
|
6975
|
+
}
|
|
6976
|
+
onError(e, t2) {
|
|
6977
|
+
return (n) => {
|
|
6978
|
+
if (n.message += `
|
|
6979
|
+
Please report this to https://github.com/markedjs/marked.`, e) {
|
|
6980
|
+
let r = "<p>An error occurred:</p><pre>" + w(n.message + "", true) + "</pre>";
|
|
6981
|
+
return t2 ? Promise.resolve(r) : r;
|
|
7534
6982
|
}
|
|
7535
|
-
if (
|
|
7536
|
-
|
|
7537
|
-
|
|
7538
|
-
|
|
7539
|
-
|
|
7540
|
-
|
|
7541
|
-
|
|
6983
|
+
if (t2)
|
|
6984
|
+
return Promise.reject(n);
|
|
6985
|
+
throw n;
|
|
6986
|
+
};
|
|
6987
|
+
}
|
|
6988
|
+
};
|
|
6989
|
+
var _ = new B;
|
|
6990
|
+
function d(u3, e) {
|
|
6991
|
+
return _.parse(u3, e);
|
|
6992
|
+
}
|
|
6993
|
+
d.options = d.setOptions = function(u3) {
|
|
6994
|
+
return _.setOptions(u3), d.defaults = _.defaults, Z(d.defaults), d;
|
|
6995
|
+
};
|
|
6996
|
+
d.getDefaults = L;
|
|
6997
|
+
d.defaults = T;
|
|
6998
|
+
d.use = function(...u3) {
|
|
6999
|
+
return _.use(...u3), d.defaults = _.defaults, Z(d.defaults), d;
|
|
7000
|
+
};
|
|
7001
|
+
d.walkTokens = function(u3, e) {
|
|
7002
|
+
return _.walkTokens(u3, e);
|
|
7003
|
+
};
|
|
7004
|
+
d.parseInline = _.parseInline;
|
|
7005
|
+
d.Parser = b;
|
|
7006
|
+
d.parser = b.parse;
|
|
7007
|
+
d.Renderer = P;
|
|
7008
|
+
d.TextRenderer = $;
|
|
7009
|
+
d.Lexer = x;
|
|
7010
|
+
d.lexer = x.lex;
|
|
7011
|
+
d.Tokenizer = y;
|
|
7012
|
+
d.Hooks = S;
|
|
7013
|
+
d.parse = d;
|
|
7014
|
+
var Dt = d.options;
|
|
7015
|
+
var Ht = d.setOptions;
|
|
7016
|
+
var Zt = d.use;
|
|
7017
|
+
var Gt = d.walkTokens;
|
|
7018
|
+
var Nt = d.parseInline;
|
|
7019
|
+
var Ft = b.parse;
|
|
7020
|
+
var jt = x.lex;
|
|
7021
|
+
|
|
7022
|
+
// src/renderables/TextTable.ts
|
|
7023
|
+
var MEASURE_HEIGHT = 1e4;
|
|
7024
|
+
|
|
7025
|
+
class TextTableRenderable extends Renderable {
|
|
7026
|
+
_content;
|
|
7027
|
+
_wrapMode;
|
|
7028
|
+
_columnWidthMode;
|
|
7029
|
+
_columnFitter;
|
|
7030
|
+
_cellPaddingX;
|
|
7031
|
+
_cellPaddingY;
|
|
7032
|
+
_columnGap;
|
|
7033
|
+
_showBorders;
|
|
7034
|
+
_border;
|
|
7035
|
+
_outerBorder;
|
|
7036
|
+
_hasExplicitOuterBorder;
|
|
7037
|
+
_borderStyle;
|
|
7038
|
+
_borderColor;
|
|
7039
|
+
_borderBackgroundColor;
|
|
7040
|
+
_backgroundColor;
|
|
7041
|
+
_defaultFg;
|
|
7042
|
+
_defaultBg;
|
|
7043
|
+
_defaultAttributes;
|
|
7044
|
+
_selectionBg;
|
|
7045
|
+
_selectionFg;
|
|
7046
|
+
_lastLocalSelection = null;
|
|
7047
|
+
_lastSelectionMode = null;
|
|
7048
|
+
_cells = [];
|
|
7049
|
+
_prevCellContent = [];
|
|
7050
|
+
_rowCount = 0;
|
|
7051
|
+
_columnCount = 0;
|
|
7052
|
+
_layout = this.createEmptyLayout();
|
|
7053
|
+
_layoutDirty = true;
|
|
7054
|
+
_rasterDirty = true;
|
|
7055
|
+
_cachedMeasureLayout = null;
|
|
7056
|
+
_cachedMeasureWidth = undefined;
|
|
7057
|
+
_defaultOptions = {
|
|
7058
|
+
content: [],
|
|
7059
|
+
wrapMode: "word",
|
|
7060
|
+
columnWidthMode: "full",
|
|
7061
|
+
columnFitter: "proportional",
|
|
7062
|
+
cellPadding: 0,
|
|
7063
|
+
cellPaddingX: undefined,
|
|
7064
|
+
cellPaddingY: undefined,
|
|
7065
|
+
columnGap: 0,
|
|
7066
|
+
showBorders: true,
|
|
7067
|
+
border: true,
|
|
7068
|
+
outerBorder: true,
|
|
7069
|
+
selectable: true,
|
|
7070
|
+
selectionBg: undefined,
|
|
7071
|
+
selectionFg: undefined,
|
|
7072
|
+
borderStyle: "single",
|
|
7073
|
+
borderColor: "#FFFFFF",
|
|
7074
|
+
borderBackgroundColor: "transparent",
|
|
7075
|
+
backgroundColor: "transparent",
|
|
7076
|
+
fg: "#FFFFFF",
|
|
7077
|
+
bg: "transparent",
|
|
7078
|
+
attributes: 0
|
|
7079
|
+
};
|
|
7080
|
+
constructor(ctx, options = {}) {
|
|
7081
|
+
super(ctx, { ...options, flexShrink: options.flexShrink ?? 0, buffered: true });
|
|
7082
|
+
this._content = options.content ?? this._defaultOptions.content;
|
|
7083
|
+
this._wrapMode = options.wrapMode ?? this._defaultOptions.wrapMode;
|
|
7084
|
+
this._columnWidthMode = options.columnWidthMode ?? this._defaultOptions.columnWidthMode;
|
|
7085
|
+
this._columnFitter = this.resolveColumnFitter(options.columnFitter);
|
|
7086
|
+
this._cellPaddingX = this.resolveCellPadding(options.cellPaddingX ?? options.cellPadding);
|
|
7087
|
+
this._cellPaddingY = this.resolveCellPadding(options.cellPaddingY ?? options.cellPadding);
|
|
7088
|
+
this._columnGap = this.resolveColumnGap(options.columnGap);
|
|
7089
|
+
this._showBorders = options.showBorders ?? this._defaultOptions.showBorders;
|
|
7090
|
+
this._border = options.border ?? this._defaultOptions.border;
|
|
7091
|
+
this._hasExplicitOuterBorder = options.outerBorder !== undefined;
|
|
7092
|
+
this._outerBorder = options.outerBorder ?? this._border;
|
|
7093
|
+
this.selectable = options.selectable ?? this._defaultOptions.selectable;
|
|
7094
|
+
this._selectionBg = options.selectionBg ? parseColor(options.selectionBg) : undefined;
|
|
7095
|
+
this._selectionFg = options.selectionFg ? parseColor(options.selectionFg) : undefined;
|
|
7096
|
+
this._borderStyle = parseBorderStyle(options.borderStyle, this._defaultOptions.borderStyle);
|
|
7097
|
+
this._borderColor = parseColor(options.borderColor ?? this._defaultOptions.borderColor);
|
|
7098
|
+
this._borderBackgroundColor = parseColor(options.borderBackgroundColor ?? this._defaultOptions.borderBackgroundColor);
|
|
7099
|
+
this._backgroundColor = parseColor(options.backgroundColor ?? this._defaultOptions.backgroundColor);
|
|
7100
|
+
this._defaultFg = parseColor(options.fg ?? this._defaultOptions.fg);
|
|
7101
|
+
this._defaultBg = parseColor(options.bg ?? this._defaultOptions.bg);
|
|
7102
|
+
this._defaultAttributes = options.attributes ?? this._defaultOptions.attributes;
|
|
7103
|
+
this.setupMeasureFunc();
|
|
7104
|
+
this.rebuildCells();
|
|
7105
|
+
}
|
|
7106
|
+
get content() {
|
|
7107
|
+
return this._content;
|
|
7108
|
+
}
|
|
7109
|
+
set content(value) {
|
|
7110
|
+
this._content = value ?? [];
|
|
7111
|
+
this.rebuildCells();
|
|
7112
|
+
}
|
|
7113
|
+
get wrapMode() {
|
|
7114
|
+
return this._wrapMode;
|
|
7115
|
+
}
|
|
7116
|
+
set wrapMode(value) {
|
|
7117
|
+
if (this._wrapMode === value)
|
|
7118
|
+
return;
|
|
7119
|
+
this._wrapMode = value;
|
|
7120
|
+
for (const row of this._cells) {
|
|
7121
|
+
for (const cell of row) {
|
|
7122
|
+
cell.textBufferView.setWrapMode(value);
|
|
7542
7123
|
}
|
|
7543
7124
|
}
|
|
7544
|
-
|
|
7125
|
+
this.invalidateLayoutAndRaster();
|
|
7545
7126
|
}
|
|
7546
|
-
|
|
7547
|
-
|
|
7548
|
-
options;
|
|
7549
|
-
parser;
|
|
7550
|
-
constructor(e) {
|
|
7551
|
-
this.options = e || T;
|
|
7127
|
+
get columnWidthMode() {
|
|
7128
|
+
return this._columnWidthMode;
|
|
7552
7129
|
}
|
|
7553
|
-
|
|
7554
|
-
|
|
7130
|
+
set columnWidthMode(value) {
|
|
7131
|
+
if (this._columnWidthMode === value)
|
|
7132
|
+
return;
|
|
7133
|
+
this._columnWidthMode = value;
|
|
7134
|
+
this.invalidateLayoutAndRaster();
|
|
7555
7135
|
}
|
|
7556
|
-
|
|
7557
|
-
|
|
7558
|
-
`;
|
|
7559
|
-
return r ? '<pre><code class="language-' + w(r) + '">' + (n ? i : w(i, true)) + `</code></pre>
|
|
7560
|
-
` : "<pre><code>" + (n ? i : w(i, true)) + `</code></pre>
|
|
7561
|
-
`;
|
|
7136
|
+
get columnFitter() {
|
|
7137
|
+
return this._columnFitter;
|
|
7562
7138
|
}
|
|
7563
|
-
|
|
7564
|
-
|
|
7565
|
-
|
|
7566
|
-
|
|
7139
|
+
set columnFitter(value) {
|
|
7140
|
+
const next = this.resolveColumnFitter(value);
|
|
7141
|
+
if (this._columnFitter === next)
|
|
7142
|
+
return;
|
|
7143
|
+
this._columnFitter = next;
|
|
7144
|
+
this.invalidateLayoutAndRaster();
|
|
7567
7145
|
}
|
|
7568
|
-
|
|
7569
|
-
return
|
|
7146
|
+
get cellPadding() {
|
|
7147
|
+
return this._cellPaddingX === this._cellPaddingY ? this._cellPaddingX : 0;
|
|
7570
7148
|
}
|
|
7571
|
-
|
|
7572
|
-
|
|
7149
|
+
set cellPadding(value) {
|
|
7150
|
+
const next = this.resolveCellPadding(value);
|
|
7151
|
+
if (this._cellPaddingX === next && this._cellPaddingY === next)
|
|
7152
|
+
return;
|
|
7153
|
+
this._cellPaddingX = next;
|
|
7154
|
+
this._cellPaddingY = next;
|
|
7155
|
+
this.invalidateLayoutAndRaster();
|
|
7156
|
+
}
|
|
7157
|
+
get cellPaddingX() {
|
|
7158
|
+
return this._cellPaddingX;
|
|
7159
|
+
}
|
|
7160
|
+
set cellPaddingX(value) {
|
|
7161
|
+
const next = this.resolveCellPadding(value);
|
|
7162
|
+
if (this._cellPaddingX === next)
|
|
7163
|
+
return;
|
|
7164
|
+
this._cellPaddingX = next;
|
|
7165
|
+
this.invalidateLayoutAndRaster();
|
|
7166
|
+
}
|
|
7167
|
+
get cellPaddingY() {
|
|
7168
|
+
return this._cellPaddingY;
|
|
7169
|
+
}
|
|
7170
|
+
set cellPaddingY(value) {
|
|
7171
|
+
const next = this.resolveCellPadding(value);
|
|
7172
|
+
if (this._cellPaddingY === next)
|
|
7173
|
+
return;
|
|
7174
|
+
this._cellPaddingY = next;
|
|
7175
|
+
this.invalidateLayoutAndRaster();
|
|
7176
|
+
}
|
|
7177
|
+
get columnGap() {
|
|
7178
|
+
return this._columnGap;
|
|
7179
|
+
}
|
|
7180
|
+
set columnGap(value) {
|
|
7181
|
+
const next = this.resolveColumnGap(value);
|
|
7182
|
+
if (this._columnGap === next)
|
|
7183
|
+
return;
|
|
7184
|
+
this._columnGap = next;
|
|
7185
|
+
this.invalidateLayoutAndRaster();
|
|
7186
|
+
}
|
|
7187
|
+
get showBorders() {
|
|
7188
|
+
return this._showBorders;
|
|
7189
|
+
}
|
|
7190
|
+
set showBorders(value) {
|
|
7191
|
+
if (this._showBorders === value)
|
|
7192
|
+
return;
|
|
7193
|
+
this._showBorders = value;
|
|
7194
|
+
this.invalidateRasterOnly();
|
|
7195
|
+
}
|
|
7196
|
+
get outerBorder() {
|
|
7197
|
+
return this._outerBorder;
|
|
7573
7198
|
}
|
|
7574
|
-
|
|
7575
|
-
|
|
7576
|
-
|
|
7199
|
+
set outerBorder(value) {
|
|
7200
|
+
if (this._outerBorder === value)
|
|
7201
|
+
return;
|
|
7202
|
+
this._hasExplicitOuterBorder = true;
|
|
7203
|
+
this._outerBorder = value;
|
|
7204
|
+
this.invalidateLayoutAndRaster();
|
|
7577
7205
|
}
|
|
7578
|
-
|
|
7579
|
-
return
|
|
7580
|
-
`;
|
|
7206
|
+
get border() {
|
|
7207
|
+
return this._border;
|
|
7581
7208
|
}
|
|
7582
|
-
|
|
7583
|
-
|
|
7584
|
-
|
|
7585
|
-
|
|
7586
|
-
|
|
7209
|
+
set border(value) {
|
|
7210
|
+
if (this._border === value)
|
|
7211
|
+
return;
|
|
7212
|
+
this._border = value;
|
|
7213
|
+
if (!this._hasExplicitOuterBorder) {
|
|
7214
|
+
this._outerBorder = value;
|
|
7587
7215
|
}
|
|
7588
|
-
|
|
7589
|
-
return "<" + i + s + `>
|
|
7590
|
-
` + r + "</" + i + `>
|
|
7591
|
-
`;
|
|
7592
|
-
}
|
|
7593
|
-
listitem(e) {
|
|
7594
|
-
return `<li>${this.parser.parse(e.tokens)}</li>
|
|
7595
|
-
`;
|
|
7216
|
+
this.invalidateLayoutAndRaster();
|
|
7596
7217
|
}
|
|
7597
|
-
|
|
7598
|
-
return
|
|
7218
|
+
get borderStyle() {
|
|
7219
|
+
return this._borderStyle;
|
|
7599
7220
|
}
|
|
7600
|
-
|
|
7601
|
-
|
|
7602
|
-
|
|
7221
|
+
set borderStyle(value) {
|
|
7222
|
+
const next = parseBorderStyle(value, this._defaultOptions.borderStyle);
|
|
7223
|
+
if (this._borderStyle === next)
|
|
7224
|
+
return;
|
|
7225
|
+
this._borderStyle = next;
|
|
7226
|
+
this.invalidateRasterOnly();
|
|
7603
7227
|
}
|
|
7604
|
-
|
|
7605
|
-
|
|
7606
|
-
for (let i = 0;i < e.header.length; i++)
|
|
7607
|
-
n += this.tablecell(e.header[i]);
|
|
7608
|
-
t2 += this.tablerow({ text: n });
|
|
7609
|
-
let r = "";
|
|
7610
|
-
for (let i = 0;i < e.rows.length; i++) {
|
|
7611
|
-
let s = e.rows[i];
|
|
7612
|
-
n = "";
|
|
7613
|
-
for (let a = 0;a < s.length; a++)
|
|
7614
|
-
n += this.tablecell(s[a]);
|
|
7615
|
-
r += this.tablerow({ text: n });
|
|
7616
|
-
}
|
|
7617
|
-
return r && (r = `<tbody>${r}</tbody>`), `<table>
|
|
7618
|
-
<thead>
|
|
7619
|
-
` + t2 + `</thead>
|
|
7620
|
-
` + r + `</table>
|
|
7621
|
-
`;
|
|
7228
|
+
get borderColor() {
|
|
7229
|
+
return this._borderColor;
|
|
7622
7230
|
}
|
|
7623
|
-
|
|
7624
|
-
|
|
7625
|
-
|
|
7626
|
-
|
|
7231
|
+
set borderColor(value) {
|
|
7232
|
+
const next = parseColor(value);
|
|
7233
|
+
if (this._borderColor === next)
|
|
7234
|
+
return;
|
|
7235
|
+
this._borderColor = next;
|
|
7236
|
+
this.invalidateRasterOnly();
|
|
7627
7237
|
}
|
|
7628
|
-
|
|
7629
|
-
|
|
7630
|
-
|
|
7631
|
-
|
|
7238
|
+
shouldStartSelection(x2, y2) {
|
|
7239
|
+
if (!this.selectable)
|
|
7240
|
+
return false;
|
|
7241
|
+
this.ensureLayoutReady();
|
|
7242
|
+
const localX = x2 - this.x;
|
|
7243
|
+
const localY = y2 - this.y;
|
|
7244
|
+
return this.getCellAtLocalPosition(localX, localY) !== null;
|
|
7632
7245
|
}
|
|
7633
|
-
|
|
7634
|
-
|
|
7246
|
+
onSelectionChanged(selection) {
|
|
7247
|
+
this.ensureLayoutReady();
|
|
7248
|
+
const previousLocalSelection = this._lastLocalSelection;
|
|
7249
|
+
const localSelection = convertGlobalToLocalSelection(selection, this.x, this.y);
|
|
7250
|
+
this._lastLocalSelection = localSelection;
|
|
7251
|
+
const dirtyRows = this.getDirtySelectionRowRange(previousLocalSelection, localSelection);
|
|
7252
|
+
if (!localSelection?.isActive) {
|
|
7253
|
+
this.resetCellSelections();
|
|
7254
|
+
this._lastSelectionMode = null;
|
|
7255
|
+
} else {
|
|
7256
|
+
this.applySelectionToCells(localSelection, selection?.isStart ?? false);
|
|
7257
|
+
}
|
|
7258
|
+
if (dirtyRows !== null) {
|
|
7259
|
+
this.redrawSelectionRows(dirtyRows.firstRow, dirtyRows.lastRow);
|
|
7260
|
+
}
|
|
7261
|
+
return this.hasSelection();
|
|
7635
7262
|
}
|
|
7636
|
-
|
|
7637
|
-
|
|
7263
|
+
hasSelection() {
|
|
7264
|
+
for (const row of this._cells) {
|
|
7265
|
+
for (const cell of row) {
|
|
7266
|
+
if (cell.textBufferView.hasSelection()) {
|
|
7267
|
+
return true;
|
|
7268
|
+
}
|
|
7269
|
+
}
|
|
7270
|
+
}
|
|
7271
|
+
return false;
|
|
7638
7272
|
}
|
|
7639
|
-
|
|
7640
|
-
|
|
7273
|
+
getSelection() {
|
|
7274
|
+
for (const row of this._cells) {
|
|
7275
|
+
for (const cell of row) {
|
|
7276
|
+
const selection = cell.textBufferView.getSelection();
|
|
7277
|
+
if (selection) {
|
|
7278
|
+
return selection;
|
|
7279
|
+
}
|
|
7280
|
+
}
|
|
7281
|
+
}
|
|
7282
|
+
return null;
|
|
7641
7283
|
}
|
|
7642
|
-
|
|
7643
|
-
|
|
7284
|
+
getSelectedText() {
|
|
7285
|
+
const selectedRows = [];
|
|
7286
|
+
for (let rowIdx = 0;rowIdx < this._rowCount; rowIdx++) {
|
|
7287
|
+
const rowSelections = [];
|
|
7288
|
+
for (let colIdx = 0;colIdx < this._columnCount; colIdx++) {
|
|
7289
|
+
const cell = this._cells[rowIdx]?.[colIdx];
|
|
7290
|
+
if (!cell || !cell.textBufferView.hasSelection())
|
|
7291
|
+
continue;
|
|
7292
|
+
const selectedText = cell.textBufferView.getSelectedText();
|
|
7293
|
+
if (selectedText.length > 0) {
|
|
7294
|
+
rowSelections.push(selectedText);
|
|
7295
|
+
}
|
|
7296
|
+
}
|
|
7297
|
+
if (rowSelections.length > 0) {
|
|
7298
|
+
selectedRows.push(rowSelections.join("\t"));
|
|
7299
|
+
}
|
|
7300
|
+
}
|
|
7301
|
+
return selectedRows.join(`
|
|
7302
|
+
`);
|
|
7644
7303
|
}
|
|
7645
|
-
|
|
7646
|
-
|
|
7304
|
+
onResize(width, height) {
|
|
7305
|
+
this.invalidateLayoutAndRaster(false);
|
|
7306
|
+
super.onResize(width, height);
|
|
7647
7307
|
}
|
|
7648
|
-
|
|
7649
|
-
|
|
7650
|
-
|
|
7651
|
-
|
|
7652
|
-
|
|
7653
|
-
|
|
7654
|
-
|
|
7308
|
+
renderSelf(buffer) {
|
|
7309
|
+
if (!this.visible || this.isDestroyed)
|
|
7310
|
+
return;
|
|
7311
|
+
if (this._layoutDirty) {
|
|
7312
|
+
this.rebuildLayoutForCurrentWidth();
|
|
7313
|
+
}
|
|
7314
|
+
if (!this._rasterDirty)
|
|
7315
|
+
return;
|
|
7316
|
+
buffer.clear(this._backgroundColor);
|
|
7317
|
+
if (this._rowCount === 0 || this._columnCount === 0) {
|
|
7318
|
+
this._rasterDirty = false;
|
|
7319
|
+
return;
|
|
7320
|
+
}
|
|
7321
|
+
this.drawBorders(buffer);
|
|
7322
|
+
this.drawCells(buffer);
|
|
7323
|
+
this._rasterDirty = false;
|
|
7655
7324
|
}
|
|
7656
|
-
|
|
7657
|
-
|
|
7658
|
-
|
|
7659
|
-
if (i === null)
|
|
7660
|
-
return w(n);
|
|
7661
|
-
e = i;
|
|
7662
|
-
let s = `<img src="${e}" alt="${n}"`;
|
|
7663
|
-
return t2 && (s += ` title="${w(t2)}"`), s += ">", s;
|
|
7325
|
+
destroySelf() {
|
|
7326
|
+
this.destroyCells();
|
|
7327
|
+
super.destroySelf();
|
|
7664
7328
|
}
|
|
7665
|
-
|
|
7666
|
-
|
|
7329
|
+
setupMeasureFunc() {
|
|
7330
|
+
const measureFunc = (width, widthMode, _height, _heightMode) => {
|
|
7331
|
+
const hasWidthConstraint = widthMode !== MeasureMode.Undefined && Number.isFinite(width);
|
|
7332
|
+
const rawWidthConstraint = hasWidthConstraint ? Math.max(1, Math.floor(width)) : undefined;
|
|
7333
|
+
const widthConstraint = this.resolveLayoutWidthConstraint(rawWidthConstraint);
|
|
7334
|
+
const measuredLayout = this.computeLayout(widthConstraint);
|
|
7335
|
+
this._cachedMeasureLayout = measuredLayout;
|
|
7336
|
+
this._cachedMeasureWidth = widthConstraint;
|
|
7337
|
+
let measuredWidth = measuredLayout.tableWidth > 0 ? measuredLayout.tableWidth : 1;
|
|
7338
|
+
let measuredHeight = measuredLayout.tableHeight > 0 ? measuredLayout.tableHeight : 1;
|
|
7339
|
+
if (widthMode === MeasureMode.AtMost && rawWidthConstraint !== undefined && this._positionType !== "absolute") {
|
|
7340
|
+
measuredWidth = Math.min(rawWidthConstraint, measuredWidth);
|
|
7341
|
+
}
|
|
7342
|
+
return {
|
|
7343
|
+
width: measuredWidth,
|
|
7344
|
+
height: measuredHeight
|
|
7345
|
+
};
|
|
7346
|
+
};
|
|
7347
|
+
this.yogaNode.setMeasureFunc(measureFunc);
|
|
7667
7348
|
}
|
|
7668
|
-
|
|
7669
|
-
|
|
7670
|
-
|
|
7671
|
-
|
|
7349
|
+
rebuildCells() {
|
|
7350
|
+
const newRowCount = this._content.length;
|
|
7351
|
+
const newColumnCount = this._content.reduce((max, row) => Math.max(max, row.length), 0);
|
|
7352
|
+
if (this._cells.length === 0) {
|
|
7353
|
+
this._rowCount = newRowCount;
|
|
7354
|
+
this._columnCount = newColumnCount;
|
|
7355
|
+
this._cells = [];
|
|
7356
|
+
this._prevCellContent = [];
|
|
7357
|
+
for (let rowIdx = 0;rowIdx < newRowCount; rowIdx++) {
|
|
7358
|
+
const row = this._content[rowIdx] ?? [];
|
|
7359
|
+
const rowCells = [];
|
|
7360
|
+
const rowRefs = [];
|
|
7361
|
+
for (let colIdx = 0;colIdx < newColumnCount; colIdx++) {
|
|
7362
|
+
const cellContent = row[colIdx];
|
|
7363
|
+
rowCells.push(this.createCell(cellContent));
|
|
7364
|
+
rowRefs.push(cellContent);
|
|
7365
|
+
}
|
|
7366
|
+
this._cells.push(rowCells);
|
|
7367
|
+
this._prevCellContent.push(rowRefs);
|
|
7368
|
+
}
|
|
7369
|
+
this.invalidateLayoutAndRaster();
|
|
7370
|
+
return;
|
|
7371
|
+
}
|
|
7372
|
+
this.updateCellsDiff(newRowCount, newColumnCount);
|
|
7373
|
+
this.invalidateLayoutAndRaster();
|
|
7672
7374
|
}
|
|
7673
|
-
|
|
7674
|
-
|
|
7375
|
+
updateCellsDiff(newRowCount, newColumnCount) {
|
|
7376
|
+
const oldRowCount = this._rowCount;
|
|
7377
|
+
const oldColumnCount = this._columnCount;
|
|
7378
|
+
const keepRows = Math.min(oldRowCount, newRowCount);
|
|
7379
|
+
const keepCols = Math.min(oldColumnCount, newColumnCount);
|
|
7380
|
+
for (let rowIdx = 0;rowIdx < keepRows; rowIdx++) {
|
|
7381
|
+
const newRow = this._content[rowIdx] ?? [];
|
|
7382
|
+
const cellRow = this._cells[rowIdx];
|
|
7383
|
+
const refRow = this._prevCellContent[rowIdx];
|
|
7384
|
+
for (let colIdx = 0;colIdx < keepCols; colIdx++) {
|
|
7385
|
+
const cellContent = newRow[colIdx];
|
|
7386
|
+
if (cellContent === refRow[colIdx])
|
|
7387
|
+
continue;
|
|
7388
|
+
const oldCell = cellRow[colIdx];
|
|
7389
|
+
oldCell.textBufferView.destroy();
|
|
7390
|
+
oldCell.textBuffer.destroy();
|
|
7391
|
+
oldCell.syntaxStyle.destroy();
|
|
7392
|
+
cellRow[colIdx] = this.createCell(cellContent);
|
|
7393
|
+
refRow[colIdx] = cellContent;
|
|
7394
|
+
}
|
|
7395
|
+
if (newColumnCount > oldColumnCount) {
|
|
7396
|
+
for (let colIdx = oldColumnCount;colIdx < newColumnCount; colIdx++) {
|
|
7397
|
+
const cellContent = newRow[colIdx];
|
|
7398
|
+
cellRow.push(this.createCell(cellContent));
|
|
7399
|
+
refRow.push(cellContent);
|
|
7400
|
+
}
|
|
7401
|
+
} else if (newColumnCount < oldColumnCount) {
|
|
7402
|
+
for (let colIdx = newColumnCount;colIdx < oldColumnCount; colIdx++) {
|
|
7403
|
+
const cell = cellRow[colIdx];
|
|
7404
|
+
cell.textBufferView.destroy();
|
|
7405
|
+
cell.textBuffer.destroy();
|
|
7406
|
+
cell.syntaxStyle.destroy();
|
|
7407
|
+
}
|
|
7408
|
+
cellRow.length = newColumnCount;
|
|
7409
|
+
refRow.length = newColumnCount;
|
|
7410
|
+
}
|
|
7411
|
+
}
|
|
7412
|
+
if (newRowCount > oldRowCount) {
|
|
7413
|
+
for (let rowIdx = oldRowCount;rowIdx < newRowCount; rowIdx++) {
|
|
7414
|
+
const newRow = this._content[rowIdx] ?? [];
|
|
7415
|
+
const rowCells = [];
|
|
7416
|
+
const rowRefs = [];
|
|
7417
|
+
for (let colIdx = 0;colIdx < newColumnCount; colIdx++) {
|
|
7418
|
+
const cellContent = newRow[colIdx];
|
|
7419
|
+
rowCells.push(this.createCell(cellContent));
|
|
7420
|
+
rowRefs.push(cellContent);
|
|
7421
|
+
}
|
|
7422
|
+
this._cells.push(rowCells);
|
|
7423
|
+
this._prevCellContent.push(rowRefs);
|
|
7424
|
+
}
|
|
7425
|
+
} else if (newRowCount < oldRowCount) {
|
|
7426
|
+
for (let rowIdx = newRowCount;rowIdx < oldRowCount; rowIdx++) {
|
|
7427
|
+
const row = this._cells[rowIdx];
|
|
7428
|
+
for (const cell of row) {
|
|
7429
|
+
cell.textBufferView.destroy();
|
|
7430
|
+
cell.textBuffer.destroy();
|
|
7431
|
+
cell.syntaxStyle.destroy();
|
|
7432
|
+
}
|
|
7433
|
+
}
|
|
7434
|
+
this._cells.length = newRowCount;
|
|
7435
|
+
this._prevCellContent.length = newRowCount;
|
|
7436
|
+
}
|
|
7437
|
+
this._rowCount = newRowCount;
|
|
7438
|
+
this._columnCount = newColumnCount;
|
|
7675
7439
|
}
|
|
7676
|
-
|
|
7677
|
-
|
|
7440
|
+
createCell(content) {
|
|
7441
|
+
const styledText = this.toStyledText(content);
|
|
7442
|
+
const textBuffer = TextBuffer.create(this._ctx.widthMethod);
|
|
7443
|
+
const syntaxStyle = SyntaxStyle.create();
|
|
7444
|
+
textBuffer.setDefaultFg(this._defaultFg);
|
|
7445
|
+
textBuffer.setDefaultBg(this._defaultBg);
|
|
7446
|
+
textBuffer.setDefaultAttributes(this._defaultAttributes);
|
|
7447
|
+
textBuffer.setSyntaxStyle(syntaxStyle);
|
|
7448
|
+
textBuffer.setStyledText(styledText);
|
|
7449
|
+
const textBufferView = TextBufferView.create(textBuffer);
|
|
7450
|
+
textBufferView.setWrapMode(this._wrapMode);
|
|
7451
|
+
return { textBuffer, textBufferView, syntaxStyle };
|
|
7678
7452
|
}
|
|
7679
|
-
|
|
7680
|
-
|
|
7453
|
+
toStyledText(content) {
|
|
7454
|
+
if (Array.isArray(content)) {
|
|
7455
|
+
return new StyledText(content);
|
|
7456
|
+
}
|
|
7457
|
+
if (content === null || content === undefined) {
|
|
7458
|
+
return stringToStyledText("");
|
|
7459
|
+
}
|
|
7460
|
+
return stringToStyledText(String(content));
|
|
7681
7461
|
}
|
|
7682
|
-
|
|
7683
|
-
|
|
7462
|
+
destroyCells() {
|
|
7463
|
+
for (const row of this._cells) {
|
|
7464
|
+
for (const cell of row) {
|
|
7465
|
+
cell.textBufferView.destroy();
|
|
7466
|
+
cell.textBuffer.destroy();
|
|
7467
|
+
cell.syntaxStyle.destroy();
|
|
7468
|
+
}
|
|
7469
|
+
}
|
|
7470
|
+
this._cells = [];
|
|
7471
|
+
this._prevCellContent = [];
|
|
7472
|
+
this._rowCount = 0;
|
|
7473
|
+
this._columnCount = 0;
|
|
7474
|
+
this._layout = this.createEmptyLayout();
|
|
7684
7475
|
}
|
|
7685
|
-
|
|
7686
|
-
|
|
7476
|
+
rebuildLayoutForCurrentWidth() {
|
|
7477
|
+
const maxTableWidth = this.resolveLayoutWidthConstraint(this.width);
|
|
7478
|
+
let layout;
|
|
7479
|
+
if (this._cachedMeasureLayout !== null && this._cachedMeasureWidth === maxTableWidth) {
|
|
7480
|
+
layout = this._cachedMeasureLayout;
|
|
7481
|
+
} else {
|
|
7482
|
+
layout = this.computeLayout(maxTableWidth);
|
|
7483
|
+
}
|
|
7484
|
+
this._cachedMeasureLayout = null;
|
|
7485
|
+
this._cachedMeasureWidth = undefined;
|
|
7486
|
+
this._layout = layout;
|
|
7487
|
+
this.applyLayoutToViews(layout);
|
|
7488
|
+
this._layoutDirty = false;
|
|
7489
|
+
if (this._lastLocalSelection?.isActive) {
|
|
7490
|
+
this.applySelectionToCells(this._lastLocalSelection, true);
|
|
7491
|
+
}
|
|
7687
7492
|
}
|
|
7688
|
-
|
|
7689
|
-
|
|
7493
|
+
computeLayout(maxTableWidth) {
|
|
7494
|
+
if (this._rowCount === 0 || this._columnCount === 0) {
|
|
7495
|
+
return this.createEmptyLayout();
|
|
7496
|
+
}
|
|
7497
|
+
const borderLayout = this.resolveBorderLayout();
|
|
7498
|
+
const columnWidths = this.computeColumnWidths(maxTableWidth, borderLayout);
|
|
7499
|
+
const rowHeights = this.computeRowHeights(columnWidths);
|
|
7500
|
+
const columnOffsets = this.computeOffsets(columnWidths, borderLayout.left, borderLayout.right, borderLayout.innerVertical, this.getInterColumnGap(borderLayout));
|
|
7501
|
+
const rowOffsets = this.computeOffsets(rowHeights, borderLayout.top, borderLayout.bottom, borderLayout.innerHorizontal);
|
|
7502
|
+
return {
|
|
7503
|
+
columnWidths,
|
|
7504
|
+
rowHeights,
|
|
7505
|
+
columnOffsets,
|
|
7506
|
+
rowOffsets,
|
|
7507
|
+
columnOffsetsI32: new Int32Array(columnOffsets),
|
|
7508
|
+
rowOffsetsI32: new Int32Array(rowOffsets),
|
|
7509
|
+
tableWidth: (columnOffsets[columnOffsets.length - 1] ?? 0) + 1,
|
|
7510
|
+
tableHeight: (rowOffsets[rowOffsets.length - 1] ?? 0) + 1
|
|
7511
|
+
};
|
|
7690
7512
|
}
|
|
7691
|
-
|
|
7692
|
-
return ""
|
|
7513
|
+
isFullWidthMode() {
|
|
7514
|
+
return this._columnWidthMode === "full";
|
|
7693
7515
|
}
|
|
7694
|
-
|
|
7695
|
-
|
|
7516
|
+
computeColumnWidths(maxTableWidth, borderLayout) {
|
|
7517
|
+
const horizontalPadding = this.getHorizontalCellPadding();
|
|
7518
|
+
const intrinsicWidths = new Array(this._columnCount).fill(1 + horizontalPadding);
|
|
7519
|
+
for (let rowIdx = 0;rowIdx < this._rowCount; rowIdx++) {
|
|
7520
|
+
for (let colIdx = 0;colIdx < this._columnCount; colIdx++) {
|
|
7521
|
+
const cell = this._cells[rowIdx]?.[colIdx];
|
|
7522
|
+
if (!cell)
|
|
7523
|
+
continue;
|
|
7524
|
+
const measure = cell.textBufferView.measureForDimensions(0, MEASURE_HEIGHT);
|
|
7525
|
+
const measuredWidth = Math.max(1, measure?.widthColsMax ?? 0) + horizontalPadding;
|
|
7526
|
+
intrinsicWidths[colIdx] = Math.max(intrinsicWidths[colIdx], measuredWidth);
|
|
7527
|
+
}
|
|
7528
|
+
}
|
|
7529
|
+
if (maxTableWidth === undefined || !Number.isFinite(maxTableWidth) || maxTableWidth <= 0) {
|
|
7530
|
+
return intrinsicWidths;
|
|
7531
|
+
}
|
|
7532
|
+
const maxContentWidth = Math.max(1, Math.floor(maxTableWidth) - this.getVerticalBorderCount(borderLayout) - this.getTotalInterColumnGap(borderLayout));
|
|
7533
|
+
const currentWidth = intrinsicWidths.reduce((sum, width) => sum + width, 0);
|
|
7534
|
+
if (currentWidth === maxContentWidth) {
|
|
7535
|
+
return intrinsicWidths;
|
|
7536
|
+
}
|
|
7537
|
+
if (currentWidth < maxContentWidth) {
|
|
7538
|
+
if (this.isFullWidthMode()) {
|
|
7539
|
+
return this.expandColumnWidths(intrinsicWidths, maxContentWidth);
|
|
7540
|
+
}
|
|
7541
|
+
return intrinsicWidths;
|
|
7542
|
+
}
|
|
7543
|
+
if (this._wrapMode === "none") {
|
|
7544
|
+
return intrinsicWidths;
|
|
7545
|
+
}
|
|
7546
|
+
return this.fitColumnWidths(intrinsicWidths, maxContentWidth);
|
|
7696
7547
|
}
|
|
7697
|
-
|
|
7698
|
-
|
|
7548
|
+
expandColumnWidths(widths, targetContentWidth) {
|
|
7549
|
+
const baseWidths = widths.map((width) => Math.max(1, Math.floor(width)));
|
|
7550
|
+
const totalBaseWidth = baseWidths.reduce((sum, width) => sum + width, 0);
|
|
7551
|
+
if (totalBaseWidth >= targetContentWidth) {
|
|
7552
|
+
return baseWidths;
|
|
7553
|
+
}
|
|
7554
|
+
const expanded = [...baseWidths];
|
|
7555
|
+
const columns = expanded.length;
|
|
7556
|
+
const extraWidth = targetContentWidth - totalBaseWidth;
|
|
7557
|
+
const sharedWidth = Math.floor(extraWidth / columns);
|
|
7558
|
+
const remainder = extraWidth % columns;
|
|
7559
|
+
for (let idx = 0;idx < columns; idx++) {
|
|
7560
|
+
expanded[idx] += sharedWidth;
|
|
7561
|
+
if (idx < remainder) {
|
|
7562
|
+
expanded[idx] += 1;
|
|
7563
|
+
}
|
|
7564
|
+
}
|
|
7565
|
+
return expanded;
|
|
7699
7566
|
}
|
|
7700
|
-
|
|
7701
|
-
|
|
7702
|
-
|
|
7703
|
-
|
|
7704
|
-
|
|
7705
|
-
constructor(e) {
|
|
7706
|
-
this.options = e || T, this.options.renderer = this.options.renderer || new P, this.renderer = this.options.renderer, this.renderer.options = this.options, this.renderer.parser = this, this.textRenderer = new $;
|
|
7567
|
+
fitColumnWidths(widths, targetContentWidth) {
|
|
7568
|
+
if (this._columnFitter === "balanced") {
|
|
7569
|
+
return this.fitColumnWidthsBalanced(widths, targetContentWidth);
|
|
7570
|
+
}
|
|
7571
|
+
return this.fitColumnWidthsProportional(widths, targetContentWidth);
|
|
7707
7572
|
}
|
|
7708
|
-
|
|
7709
|
-
|
|
7573
|
+
fitColumnWidthsProportional(widths, targetContentWidth) {
|
|
7574
|
+
const minWidth = 1 + this.getHorizontalCellPadding();
|
|
7575
|
+
const hardMinWidths = new Array(widths.length).fill(minWidth);
|
|
7576
|
+
const baseWidths = widths.map((width) => Math.max(1, Math.floor(width)));
|
|
7577
|
+
const preferredMinWidths = baseWidths.map((width) => Math.min(width, minWidth + 1));
|
|
7578
|
+
const preferredMinTotal = preferredMinWidths.reduce((sum, width) => sum + width, 0);
|
|
7579
|
+
const floorWidths = preferredMinTotal <= targetContentWidth ? preferredMinWidths : hardMinWidths;
|
|
7580
|
+
const floorTotal = floorWidths.reduce((sum, width) => sum + width, 0);
|
|
7581
|
+
const clampedTarget = Math.max(floorTotal, targetContentWidth);
|
|
7582
|
+
const totalBaseWidth = baseWidths.reduce((sum, width) => sum + width, 0);
|
|
7583
|
+
if (totalBaseWidth <= clampedTarget) {
|
|
7584
|
+
return baseWidths;
|
|
7585
|
+
}
|
|
7586
|
+
const shrinkable = baseWidths.map((width, idx) => width - floorWidths[idx]);
|
|
7587
|
+
const totalShrinkable = shrinkable.reduce((sum, value) => sum + value, 0);
|
|
7588
|
+
if (totalShrinkable <= 0) {
|
|
7589
|
+
return [...floorWidths];
|
|
7590
|
+
}
|
|
7591
|
+
const targetShrink = totalBaseWidth - clampedTarget;
|
|
7592
|
+
const integerShrink = new Array(baseWidths.length).fill(0);
|
|
7593
|
+
const fractions = new Array(baseWidths.length).fill(0);
|
|
7594
|
+
let usedShrink = 0;
|
|
7595
|
+
for (let idx = 0;idx < baseWidths.length; idx++) {
|
|
7596
|
+
if (shrinkable[idx] <= 0)
|
|
7597
|
+
continue;
|
|
7598
|
+
const exact = shrinkable[idx] / totalShrinkable * targetShrink;
|
|
7599
|
+
const whole = Math.min(shrinkable[idx], Math.floor(exact));
|
|
7600
|
+
integerShrink[idx] = whole;
|
|
7601
|
+
fractions[idx] = exact - whole;
|
|
7602
|
+
usedShrink += whole;
|
|
7603
|
+
}
|
|
7604
|
+
let remainingShrink = targetShrink - usedShrink;
|
|
7605
|
+
while (remainingShrink > 0) {
|
|
7606
|
+
let bestIdx = -1;
|
|
7607
|
+
let bestFraction = -1;
|
|
7608
|
+
for (let idx = 0;idx < baseWidths.length; idx++) {
|
|
7609
|
+
if (shrinkable[idx] - integerShrink[idx] <= 0)
|
|
7610
|
+
continue;
|
|
7611
|
+
if (fractions[idx] > bestFraction) {
|
|
7612
|
+
bestFraction = fractions[idx];
|
|
7613
|
+
bestIdx = idx;
|
|
7614
|
+
}
|
|
7615
|
+
}
|
|
7616
|
+
if (bestIdx === -1)
|
|
7617
|
+
break;
|
|
7618
|
+
integerShrink[bestIdx] += 1;
|
|
7619
|
+
fractions[bestIdx] = 0;
|
|
7620
|
+
remainingShrink -= 1;
|
|
7621
|
+
}
|
|
7622
|
+
return baseWidths.map((width, idx) => Math.max(floorWidths[idx], width - integerShrink[idx]));
|
|
7710
7623
|
}
|
|
7711
|
-
|
|
7712
|
-
|
|
7624
|
+
fitColumnWidthsBalanced(widths, targetContentWidth) {
|
|
7625
|
+
const minWidth = 1 + this.getHorizontalCellPadding();
|
|
7626
|
+
const hardMinWidths = new Array(widths.length).fill(minWidth);
|
|
7627
|
+
const baseWidths = widths.map((width) => Math.max(1, Math.floor(width)));
|
|
7628
|
+
const totalBaseWidth = baseWidths.reduce((sum, width) => sum + width, 0);
|
|
7629
|
+
const columns = baseWidths.length;
|
|
7630
|
+
if (columns === 0 || totalBaseWidth <= targetContentWidth) {
|
|
7631
|
+
return baseWidths;
|
|
7632
|
+
}
|
|
7633
|
+
const evenShare = Math.max(minWidth, Math.floor(targetContentWidth / columns));
|
|
7634
|
+
const preferredMinWidths = baseWidths.map((width) => Math.min(width, evenShare));
|
|
7635
|
+
const preferredMinTotal = preferredMinWidths.reduce((sum, width) => sum + width, 0);
|
|
7636
|
+
const floorWidths = preferredMinTotal <= targetContentWidth ? preferredMinWidths : hardMinWidths;
|
|
7637
|
+
const floorTotal = floorWidths.reduce((sum, width) => sum + width, 0);
|
|
7638
|
+
const clampedTarget = Math.max(floorTotal, targetContentWidth);
|
|
7639
|
+
if (totalBaseWidth <= clampedTarget) {
|
|
7640
|
+
return baseWidths;
|
|
7641
|
+
}
|
|
7642
|
+
const shrinkable = baseWidths.map((width, idx) => width - floorWidths[idx]);
|
|
7643
|
+
const totalShrinkable = shrinkable.reduce((sum, value) => sum + value, 0);
|
|
7644
|
+
if (totalShrinkable <= 0) {
|
|
7645
|
+
return [...floorWidths];
|
|
7646
|
+
}
|
|
7647
|
+
const targetShrink = totalBaseWidth - clampedTarget;
|
|
7648
|
+
const shrink = this.allocateShrinkByWeight(shrinkable, targetShrink, "sqrt");
|
|
7649
|
+
return baseWidths.map((width, idx) => Math.max(floorWidths[idx], width - shrink[idx]));
|
|
7713
7650
|
}
|
|
7714
|
-
|
|
7715
|
-
|
|
7716
|
-
|
|
7717
|
-
|
|
7718
|
-
|
|
7719
|
-
|
|
7720
|
-
|
|
7721
|
-
|
|
7651
|
+
allocateShrinkByWeight(shrinkable, targetShrink, mode) {
|
|
7652
|
+
const shrink = new Array(shrinkable.length).fill(0);
|
|
7653
|
+
if (targetShrink <= 0) {
|
|
7654
|
+
return shrink;
|
|
7655
|
+
}
|
|
7656
|
+
const weights = shrinkable.map((value) => {
|
|
7657
|
+
if (value <= 0) {
|
|
7658
|
+
return 0;
|
|
7659
|
+
}
|
|
7660
|
+
return mode === "sqrt" ? Math.sqrt(value) : value;
|
|
7661
|
+
});
|
|
7662
|
+
const totalWeight = weights.reduce((sum, value) => sum + value, 0);
|
|
7663
|
+
if (totalWeight <= 0) {
|
|
7664
|
+
return shrink;
|
|
7665
|
+
}
|
|
7666
|
+
const fractions = new Array(shrinkable.length).fill(0);
|
|
7667
|
+
let usedShrink = 0;
|
|
7668
|
+
for (let idx = 0;idx < shrinkable.length; idx++) {
|
|
7669
|
+
if (shrinkable[idx] <= 0 || weights[idx] <= 0)
|
|
7670
|
+
continue;
|
|
7671
|
+
const exact = weights[idx] / totalWeight * targetShrink;
|
|
7672
|
+
const whole = Math.min(shrinkable[idx], Math.floor(exact));
|
|
7673
|
+
shrink[idx] = whole;
|
|
7674
|
+
fractions[idx] = exact - whole;
|
|
7675
|
+
usedShrink += whole;
|
|
7676
|
+
}
|
|
7677
|
+
let remainingShrink = targetShrink - usedShrink;
|
|
7678
|
+
while (remainingShrink > 0) {
|
|
7679
|
+
let bestIdx = -1;
|
|
7680
|
+
let bestFraction = -1;
|
|
7681
|
+
for (let idx = 0;idx < shrinkable.length; idx++) {
|
|
7682
|
+
if (shrinkable[idx] - shrink[idx] <= 0)
|
|
7722
7683
|
continue;
|
|
7684
|
+
if (bestIdx === -1 || fractions[idx] > bestFraction || fractions[idx] === bestFraction && shrinkable[idx] > shrinkable[bestIdx]) {
|
|
7685
|
+
bestIdx = idx;
|
|
7686
|
+
bestFraction = fractions[idx];
|
|
7723
7687
|
}
|
|
7724
7688
|
}
|
|
7725
|
-
|
|
7726
|
-
|
|
7727
|
-
case "space": {
|
|
7728
|
-
t2 += this.renderer.space(i);
|
|
7729
|
-
break;
|
|
7730
|
-
}
|
|
7731
|
-
case "hr": {
|
|
7732
|
-
t2 += this.renderer.hr(i);
|
|
7733
|
-
break;
|
|
7734
|
-
}
|
|
7735
|
-
case "heading": {
|
|
7736
|
-
t2 += this.renderer.heading(i);
|
|
7737
|
-
break;
|
|
7738
|
-
}
|
|
7739
|
-
case "code": {
|
|
7740
|
-
t2 += this.renderer.code(i);
|
|
7741
|
-
break;
|
|
7742
|
-
}
|
|
7743
|
-
case "table": {
|
|
7744
|
-
t2 += this.renderer.table(i);
|
|
7745
|
-
break;
|
|
7746
|
-
}
|
|
7747
|
-
case "blockquote": {
|
|
7748
|
-
t2 += this.renderer.blockquote(i);
|
|
7749
|
-
break;
|
|
7750
|
-
}
|
|
7751
|
-
case "list": {
|
|
7752
|
-
t2 += this.renderer.list(i);
|
|
7753
|
-
break;
|
|
7754
|
-
}
|
|
7755
|
-
case "checkbox": {
|
|
7756
|
-
t2 += this.renderer.checkbox(i);
|
|
7757
|
-
break;
|
|
7758
|
-
}
|
|
7759
|
-
case "html": {
|
|
7760
|
-
t2 += this.renderer.html(i);
|
|
7761
|
-
break;
|
|
7762
|
-
}
|
|
7763
|
-
case "def": {
|
|
7764
|
-
t2 += this.renderer.def(i);
|
|
7765
|
-
break;
|
|
7766
|
-
}
|
|
7767
|
-
case "paragraph": {
|
|
7768
|
-
t2 += this.renderer.paragraph(i);
|
|
7769
|
-
break;
|
|
7770
|
-
}
|
|
7771
|
-
case "text": {
|
|
7772
|
-
t2 += this.renderer.text(i);
|
|
7773
|
-
break;
|
|
7774
|
-
}
|
|
7775
|
-
default: {
|
|
7776
|
-
let s = 'Token with "' + i.type + '" type was not found.';
|
|
7777
|
-
if (this.options.silent)
|
|
7778
|
-
return console.error(s), "";
|
|
7779
|
-
throw new Error(s);
|
|
7780
|
-
}
|
|
7689
|
+
if (bestIdx === -1) {
|
|
7690
|
+
break;
|
|
7781
7691
|
}
|
|
7692
|
+
shrink[bestIdx] += 1;
|
|
7693
|
+
fractions[bestIdx] = 0;
|
|
7694
|
+
remainingShrink -= 1;
|
|
7782
7695
|
}
|
|
7783
|
-
return
|
|
7696
|
+
return shrink;
|
|
7784
7697
|
}
|
|
7785
|
-
|
|
7786
|
-
|
|
7787
|
-
|
|
7788
|
-
|
|
7789
|
-
|
|
7790
|
-
|
|
7791
|
-
|
|
7792
|
-
|
|
7698
|
+
computeRowHeights(columnWidths) {
|
|
7699
|
+
const horizontalPadding = this.getHorizontalCellPadding();
|
|
7700
|
+
const verticalPadding = this.getVerticalCellPadding();
|
|
7701
|
+
const rowHeights = new Array(this._rowCount).fill(1 + verticalPadding);
|
|
7702
|
+
for (let rowIdx = 0;rowIdx < this._rowCount; rowIdx++) {
|
|
7703
|
+
for (let colIdx = 0;colIdx < this._columnCount; colIdx++) {
|
|
7704
|
+
const cell = this._cells[rowIdx]?.[colIdx];
|
|
7705
|
+
if (!cell)
|
|
7793
7706
|
continue;
|
|
7794
|
-
|
|
7707
|
+
const width = Math.max(1, (columnWidths[colIdx] ?? 1) - horizontalPadding);
|
|
7708
|
+
const measure = cell.textBufferView.measureForDimensions(width, MEASURE_HEIGHT);
|
|
7709
|
+
const lineCount = Math.max(1, measure?.lineCount ?? 1);
|
|
7710
|
+
rowHeights[rowIdx] = Math.max(rowHeights[rowIdx], lineCount + verticalPadding);
|
|
7795
7711
|
}
|
|
7796
|
-
|
|
7797
|
-
|
|
7798
|
-
|
|
7799
|
-
|
|
7800
|
-
|
|
7801
|
-
|
|
7802
|
-
|
|
7803
|
-
|
|
7804
|
-
|
|
7805
|
-
|
|
7806
|
-
|
|
7807
|
-
|
|
7808
|
-
|
|
7809
|
-
|
|
7810
|
-
|
|
7811
|
-
|
|
7812
|
-
|
|
7813
|
-
|
|
7814
|
-
|
|
7815
|
-
|
|
7816
|
-
|
|
7817
|
-
|
|
7818
|
-
|
|
7819
|
-
|
|
7820
|
-
|
|
7821
|
-
|
|
7822
|
-
|
|
7823
|
-
|
|
7824
|
-
|
|
7825
|
-
|
|
7826
|
-
|
|
7827
|
-
|
|
7828
|
-
|
|
7829
|
-
|
|
7830
|
-
|
|
7831
|
-
|
|
7832
|
-
|
|
7833
|
-
}
|
|
7834
|
-
|
|
7835
|
-
n += t2.del(s);
|
|
7836
|
-
break;
|
|
7837
|
-
}
|
|
7838
|
-
case "text": {
|
|
7839
|
-
n += t2.text(s);
|
|
7840
|
-
break;
|
|
7841
|
-
}
|
|
7842
|
-
default: {
|
|
7843
|
-
let a = 'Token with "' + s.type + '" type was not found.';
|
|
7844
|
-
if (this.options.silent)
|
|
7845
|
-
return console.error(a), "";
|
|
7846
|
-
throw new Error(a);
|
|
7712
|
+
}
|
|
7713
|
+
return rowHeights;
|
|
7714
|
+
}
|
|
7715
|
+
computeOffsets(parts, startBoundary, endBoundary, includeInnerBoundaries, innerGap = 0) {
|
|
7716
|
+
const offsets = [startBoundary ? 0 : -1];
|
|
7717
|
+
let cursor = offsets[0] ?? 0;
|
|
7718
|
+
for (let idx = 0;idx < parts.length; idx++) {
|
|
7719
|
+
const size = parts[idx] ?? 1;
|
|
7720
|
+
const separatorAfter = idx < parts.length - 1 ? includeInnerBoundaries ? 1 : innerGap : endBoundary ? 1 : 0;
|
|
7721
|
+
cursor += size + separatorAfter;
|
|
7722
|
+
offsets.push(cursor);
|
|
7723
|
+
}
|
|
7724
|
+
return offsets;
|
|
7725
|
+
}
|
|
7726
|
+
getInterColumnGap(borderLayout) {
|
|
7727
|
+
if (borderLayout.innerVertical) {
|
|
7728
|
+
return 0;
|
|
7729
|
+
}
|
|
7730
|
+
return this._columnGap;
|
|
7731
|
+
}
|
|
7732
|
+
getTotalInterColumnGap(borderLayout) {
|
|
7733
|
+
return Math.max(0, this._columnCount - 1) * this.getInterColumnGap(borderLayout);
|
|
7734
|
+
}
|
|
7735
|
+
applyLayoutToViews(layout) {
|
|
7736
|
+
const horizontalPadding = this.getHorizontalCellPadding();
|
|
7737
|
+
const verticalPadding = this.getVerticalCellPadding();
|
|
7738
|
+
for (let rowIdx = 0;rowIdx < this._rowCount; rowIdx++) {
|
|
7739
|
+
for (let colIdx = 0;colIdx < this._columnCount; colIdx++) {
|
|
7740
|
+
const cell = this._cells[rowIdx]?.[colIdx];
|
|
7741
|
+
if (!cell)
|
|
7742
|
+
continue;
|
|
7743
|
+
const colWidth = layout.columnWidths[colIdx] ?? 1;
|
|
7744
|
+
const rowHeight = layout.rowHeights[rowIdx] ?? 1;
|
|
7745
|
+
const contentWidth = Math.max(1, colWidth - horizontalPadding);
|
|
7746
|
+
const contentHeight = Math.max(1, rowHeight - verticalPadding);
|
|
7747
|
+
if (this._wrapMode === "none") {
|
|
7748
|
+
cell.textBufferView.setWrapWidth(null);
|
|
7749
|
+
} else {
|
|
7750
|
+
cell.textBufferView.setWrapWidth(contentWidth);
|
|
7847
7751
|
}
|
|
7752
|
+
cell.textBufferView.setViewport(0, 0, contentWidth, contentHeight);
|
|
7848
7753
|
}
|
|
7849
7754
|
}
|
|
7850
|
-
return n;
|
|
7851
|
-
}
|
|
7852
|
-
};
|
|
7853
|
-
var S = class {
|
|
7854
|
-
options;
|
|
7855
|
-
block;
|
|
7856
|
-
constructor(e) {
|
|
7857
|
-
this.options = e || T;
|
|
7858
7755
|
}
|
|
7859
|
-
|
|
7860
|
-
|
|
7861
|
-
|
|
7862
|
-
|
|
7756
|
+
resolveBorderLayout() {
|
|
7757
|
+
return {
|
|
7758
|
+
left: this._outerBorder,
|
|
7759
|
+
right: this._outerBorder,
|
|
7760
|
+
top: this._outerBorder,
|
|
7761
|
+
bottom: this._outerBorder,
|
|
7762
|
+
innerVertical: this._border && this._columnCount > 1,
|
|
7763
|
+
innerHorizontal: this._border && this._rowCount > 1
|
|
7764
|
+
};
|
|
7863
7765
|
}
|
|
7864
|
-
|
|
7865
|
-
return
|
|
7766
|
+
getVerticalBorderCount(borderLayout) {
|
|
7767
|
+
return (borderLayout.left ? 1 : 0) + (borderLayout.right ? 1 : 0) + (borderLayout.innerVertical ? Math.max(0, this._columnCount - 1) : 0);
|
|
7866
7768
|
}
|
|
7867
|
-
|
|
7868
|
-
return
|
|
7769
|
+
getHorizontalBorderCount(borderLayout) {
|
|
7770
|
+
return (borderLayout.top ? 1 : 0) + (borderLayout.bottom ? 1 : 0) + (borderLayout.innerHorizontal ? Math.max(0, this._rowCount - 1) : 0);
|
|
7869
7771
|
}
|
|
7870
|
-
|
|
7871
|
-
|
|
7772
|
+
drawBorders(buffer) {
|
|
7773
|
+
if (!this._showBorders) {
|
|
7774
|
+
return;
|
|
7775
|
+
}
|
|
7776
|
+
const borderLayout = this.resolveBorderLayout();
|
|
7777
|
+
if (this.getVerticalBorderCount(borderLayout) === 0 && this.getHorizontalBorderCount(borderLayout) === 0) {
|
|
7778
|
+
return;
|
|
7779
|
+
}
|
|
7780
|
+
buffer.drawGrid({
|
|
7781
|
+
borderChars: BorderCharArrays[this._borderStyle],
|
|
7782
|
+
borderFg: this._borderColor,
|
|
7783
|
+
borderBg: this._borderBackgroundColor,
|
|
7784
|
+
columnOffsets: this._layout.columnOffsetsI32,
|
|
7785
|
+
rowOffsets: this._layout.rowOffsetsI32,
|
|
7786
|
+
drawInner: this._border,
|
|
7787
|
+
drawOuter: this._outerBorder
|
|
7788
|
+
});
|
|
7872
7789
|
}
|
|
7873
|
-
|
|
7874
|
-
|
|
7790
|
+
drawCells(buffer) {
|
|
7791
|
+
this.drawCellRange(buffer, 0, this._rowCount - 1);
|
|
7875
7792
|
}
|
|
7876
|
-
|
|
7877
|
-
|
|
7793
|
+
drawCellRange(buffer, firstRow, lastRow) {
|
|
7794
|
+
const colOffsets = this._layout.columnOffsets;
|
|
7795
|
+
const rowOffsets = this._layout.rowOffsets;
|
|
7796
|
+
const cellPaddingX = this._cellPaddingX;
|
|
7797
|
+
const cellPaddingY = this._cellPaddingY;
|
|
7798
|
+
for (let rowIdx = firstRow;rowIdx <= lastRow; rowIdx++) {
|
|
7799
|
+
const cellY = (rowOffsets[rowIdx] ?? 0) + 1 + cellPaddingY;
|
|
7800
|
+
for (let colIdx = 0;colIdx < this._columnCount; colIdx++) {
|
|
7801
|
+
const cell = this._cells[rowIdx]?.[colIdx];
|
|
7802
|
+
if (!cell)
|
|
7803
|
+
continue;
|
|
7804
|
+
buffer.drawTextBuffer(cell.textBufferView, (colOffsets[colIdx] ?? 0) + 1 + cellPaddingX, cellY);
|
|
7805
|
+
}
|
|
7806
|
+
}
|
|
7878
7807
|
}
|
|
7879
|
-
|
|
7880
|
-
|
|
7881
|
-
|
|
7882
|
-
|
|
7883
|
-
|
|
7884
|
-
|
|
7885
|
-
|
|
7886
|
-
|
|
7887
|
-
|
|
7888
|
-
|
|
7889
|
-
|
|
7890
|
-
|
|
7891
|
-
|
|
7892
|
-
this.use(...e);
|
|
7808
|
+
redrawSelectionRows(firstRow, lastRow) {
|
|
7809
|
+
if (firstRow > lastRow)
|
|
7810
|
+
return;
|
|
7811
|
+
if (this._backgroundColor.a < 1) {
|
|
7812
|
+
this.invalidateRasterOnly();
|
|
7813
|
+
return;
|
|
7814
|
+
}
|
|
7815
|
+
const buffer = this.frameBuffer;
|
|
7816
|
+
if (!buffer)
|
|
7817
|
+
return;
|
|
7818
|
+
this.clearCellRange(buffer, firstRow, lastRow);
|
|
7819
|
+
this.drawCellRange(buffer, firstRow, lastRow);
|
|
7820
|
+
this.requestRender();
|
|
7893
7821
|
}
|
|
7894
|
-
|
|
7895
|
-
|
|
7896
|
-
|
|
7897
|
-
|
|
7898
|
-
|
|
7899
|
-
|
|
7900
|
-
|
|
7901
|
-
|
|
7902
|
-
|
|
7903
|
-
|
|
7904
|
-
|
|
7905
|
-
|
|
7906
|
-
|
|
7907
|
-
|
|
7908
|
-
|
|
7909
|
-
|
|
7910
|
-
|
|
7911
|
-
}
|
|
7912
|
-
|
|
7913
|
-
let i = r;
|
|
7914
|
-
this.defaults.extensions?.childTokens?.[i.type] ? this.defaults.extensions.childTokens[i.type].forEach((s) => {
|
|
7915
|
-
let a = i[s].flat(1 / 0);
|
|
7916
|
-
n = n.concat(this.walkTokens(a, t2));
|
|
7917
|
-
}) : i.tokens && (n = n.concat(this.walkTokens(i.tokens, t2)));
|
|
7822
|
+
clearCellRange(buffer, firstRow, lastRow) {
|
|
7823
|
+
const colWidths = this._layout.columnWidths;
|
|
7824
|
+
const rowHeights = this._layout.rowHeights;
|
|
7825
|
+
const colOffsets = this._layout.columnOffsets;
|
|
7826
|
+
const rowOffsets = this._layout.rowOffsets;
|
|
7827
|
+
for (let rowIdx = firstRow;rowIdx <= lastRow; rowIdx++) {
|
|
7828
|
+
const cellY = (rowOffsets[rowIdx] ?? 0) + 1;
|
|
7829
|
+
const rowHeight = rowHeights[rowIdx] ?? 1;
|
|
7830
|
+
for (let colIdx = 0;colIdx < this._columnCount; colIdx++) {
|
|
7831
|
+
const cellX = (colOffsets[colIdx] ?? 0) + 1;
|
|
7832
|
+
const colWidth = colWidths[colIdx] ?? 1;
|
|
7833
|
+
if (this._backgroundColor.a < 1) {
|
|
7834
|
+
for (let y2 = cellY;y2 < cellY + rowHeight; y2++) {
|
|
7835
|
+
for (let x2 = cellX;x2 < cellX + colWidth; x2++) {
|
|
7836
|
+
buffer.setCell(x2, y2, " ", this._defaultFg, this._backgroundColor, this._defaultAttributes);
|
|
7837
|
+
}
|
|
7838
|
+
}
|
|
7839
|
+
} else {
|
|
7840
|
+
buffer.fillRect(cellX, cellY, colWidth, rowHeight, this._backgroundColor);
|
|
7918
7841
|
}
|
|
7919
7842
|
}
|
|
7920
|
-
|
|
7843
|
+
}
|
|
7921
7844
|
}
|
|
7922
|
-
|
|
7923
|
-
|
|
7924
|
-
|
|
7925
|
-
|
|
7926
|
-
|
|
7927
|
-
|
|
7928
|
-
|
|
7929
|
-
|
|
7930
|
-
|
|
7931
|
-
|
|
7932
|
-
|
|
7933
|
-
|
|
7934
|
-
|
|
7935
|
-
|
|
7936
|
-
|
|
7937
|
-
|
|
7938
|
-
|
|
7939
|
-
|
|
7940
|
-
s ? s.unshift(i.tokenizer) : t2[i.level] = [i.tokenizer], i.start && (i.level === "block" ? t2.startBlock ? t2.startBlock.push(i.start) : t2.startBlock = [i.start] : i.level === "inline" && (t2.startInline ? t2.startInline.push(i.start) : t2.startInline = [i.start]));
|
|
7941
|
-
}
|
|
7942
|
-
"childTokens" in i && i.childTokens && (t2.childTokens[i.name] = i.childTokens);
|
|
7943
|
-
}), r.extensions = t2), n.renderer) {
|
|
7944
|
-
let i = this.defaults.renderer || new P(this.defaults);
|
|
7945
|
-
for (let s in n.renderer) {
|
|
7946
|
-
if (!(s in i))
|
|
7947
|
-
throw new Error(`renderer '${s}' does not exist`);
|
|
7948
|
-
if (["options", "parser"].includes(s))
|
|
7949
|
-
continue;
|
|
7950
|
-
let a = s, o = n.renderer[a], l = i[a];
|
|
7951
|
-
i[a] = (...p) => {
|
|
7952
|
-
let c = o.apply(i, p);
|
|
7953
|
-
return c === false && (c = l.apply(i, p)), c || "";
|
|
7954
|
-
};
|
|
7955
|
-
}
|
|
7956
|
-
r.renderer = i;
|
|
7845
|
+
ensureLayoutReady() {
|
|
7846
|
+
if (!this._layoutDirty)
|
|
7847
|
+
return;
|
|
7848
|
+
this.rebuildLayoutForCurrentWidth();
|
|
7849
|
+
}
|
|
7850
|
+
getCellAtLocalPosition(localX, localY) {
|
|
7851
|
+
if (this._rowCount === 0 || this._columnCount === 0)
|
|
7852
|
+
return null;
|
|
7853
|
+
if (localX < 0 || localY < 0 || localX >= this._layout.tableWidth || localY >= this._layout.tableHeight) {
|
|
7854
|
+
return null;
|
|
7855
|
+
}
|
|
7856
|
+
let rowIdx = -1;
|
|
7857
|
+
for (let idx = 0;idx < this._rowCount; idx++) {
|
|
7858
|
+
const top = (this._layout.rowOffsets[idx] ?? 0) + 1;
|
|
7859
|
+
const bottom = top + (this._layout.rowHeights[idx] ?? 1) - 1;
|
|
7860
|
+
if (localY >= top && localY <= bottom) {
|
|
7861
|
+
rowIdx = idx;
|
|
7862
|
+
break;
|
|
7957
7863
|
}
|
|
7958
|
-
|
|
7959
|
-
|
|
7960
|
-
|
|
7961
|
-
|
|
7962
|
-
|
|
7963
|
-
|
|
7964
|
-
|
|
7965
|
-
|
|
7966
|
-
|
|
7967
|
-
|
|
7968
|
-
return c === false && (c = l.apply(i, p)), c;
|
|
7969
|
-
};
|
|
7970
|
-
}
|
|
7971
|
-
r.tokenizer = i;
|
|
7864
|
+
}
|
|
7865
|
+
if (rowIdx < 0)
|
|
7866
|
+
return null;
|
|
7867
|
+
let colIdx = -1;
|
|
7868
|
+
for (let idx = 0;idx < this._columnCount; idx++) {
|
|
7869
|
+
const left = (this._layout.columnOffsets[idx] ?? 0) + 1;
|
|
7870
|
+
const right = left + (this._layout.columnWidths[idx] ?? 1) - 1;
|
|
7871
|
+
if (localX >= left && localX <= right) {
|
|
7872
|
+
colIdx = idx;
|
|
7873
|
+
break;
|
|
7972
7874
|
}
|
|
7973
|
-
|
|
7974
|
-
|
|
7975
|
-
|
|
7976
|
-
|
|
7977
|
-
|
|
7978
|
-
|
|
7979
|
-
|
|
7980
|
-
|
|
7981
|
-
|
|
7982
|
-
|
|
7983
|
-
|
|
7984
|
-
|
|
7985
|
-
|
|
7986
|
-
|
|
7987
|
-
|
|
7988
|
-
|
|
7989
|
-
|
|
7990
|
-
|
|
7991
|
-
|
|
7992
|
-
|
|
7993
|
-
|
|
7994
|
-
|
|
7995
|
-
|
|
7996
|
-
|
|
7997
|
-
|
|
7875
|
+
}
|
|
7876
|
+
if (colIdx < 0)
|
|
7877
|
+
return null;
|
|
7878
|
+
return { rowIdx, colIdx };
|
|
7879
|
+
}
|
|
7880
|
+
applySelectionToCells(localSelection, isStart) {
|
|
7881
|
+
if (localSelection.anchorX === localSelection.focusX && localSelection.anchorY === localSelection.focusY) {
|
|
7882
|
+
this.resetCellSelections();
|
|
7883
|
+
this._lastSelectionMode = null;
|
|
7884
|
+
return;
|
|
7885
|
+
}
|
|
7886
|
+
const minSelY = Math.min(localSelection.anchorY, localSelection.focusY);
|
|
7887
|
+
const maxSelY = Math.max(localSelection.anchorY, localSelection.focusY);
|
|
7888
|
+
const firstRow = this.findRowForLocalY(minSelY);
|
|
7889
|
+
const lastRow = this.findRowForLocalY(maxSelY);
|
|
7890
|
+
const selection = this.resolveSelectionResolution(localSelection);
|
|
7891
|
+
const modeChanged = this._lastSelectionMode !== selection.mode;
|
|
7892
|
+
this._lastSelectionMode = selection.mode;
|
|
7893
|
+
const lockToAnchorColumn = selection.mode === "column-locked" && selection.anchorColumn !== null;
|
|
7894
|
+
for (let rowIdx = 0;rowIdx < this._rowCount; rowIdx++) {
|
|
7895
|
+
if (rowIdx < firstRow || rowIdx > lastRow) {
|
|
7896
|
+
this.resetRowSelection(rowIdx);
|
|
7897
|
+
continue;
|
|
7898
|
+
}
|
|
7899
|
+
const cellTop = (this._layout.rowOffsets[rowIdx] ?? 0) + 1 + this._cellPaddingY;
|
|
7900
|
+
for (let colIdx = 0;colIdx < this._columnCount; colIdx++) {
|
|
7901
|
+
const cell = this._cells[rowIdx]?.[colIdx];
|
|
7902
|
+
if (!cell)
|
|
7903
|
+
continue;
|
|
7904
|
+
if (lockToAnchorColumn && colIdx !== selection.anchorColumn) {
|
|
7905
|
+
cell.textBufferView.resetLocalSelection();
|
|
7906
|
+
continue;
|
|
7907
|
+
}
|
|
7908
|
+
const cellLeft = (this._layout.columnOffsets[colIdx] ?? 0) + 1 + this._cellPaddingX;
|
|
7909
|
+
let coords = {
|
|
7910
|
+
anchorX: localSelection.anchorX - cellLeft,
|
|
7911
|
+
anchorY: localSelection.anchorY - cellTop,
|
|
7912
|
+
focusX: localSelection.focusX - cellLeft,
|
|
7913
|
+
focusY: localSelection.focusY - cellTop
|
|
7914
|
+
};
|
|
7915
|
+
const isAnchorCell = selection.anchorCell !== null && selection.anchorCell.rowIdx === rowIdx && selection.anchorCell.colIdx === colIdx;
|
|
7916
|
+
if (selection.mode === "single-cell" && !isAnchorCell) {
|
|
7917
|
+
cell.textBufferView.resetLocalSelection();
|
|
7918
|
+
continue;
|
|
7919
|
+
}
|
|
7920
|
+
const forceSet = isAnchorCell && selection.mode !== "single-cell";
|
|
7921
|
+
if (forceSet) {
|
|
7922
|
+
coords = this.getFullCellSelectionCoords(rowIdx, colIdx);
|
|
7923
|
+
}
|
|
7924
|
+
const shouldUseSet = isStart || modeChanged || forceSet;
|
|
7925
|
+
if (shouldUseSet) {
|
|
7926
|
+
cell.textBufferView.setLocalSelection(coords.anchorX, coords.anchorY, coords.focusX, coords.focusY, this._selectionBg, this._selectionFg);
|
|
7927
|
+
} else {
|
|
7928
|
+
cell.textBufferView.updateLocalSelection(coords.anchorX, coords.anchorY, coords.focusX, coords.focusY, this._selectionBg, this._selectionFg);
|
|
7998
7929
|
}
|
|
7999
|
-
r.hooks = i;
|
|
8000
7930
|
}
|
|
8001
|
-
|
|
8002
|
-
|
|
8003
|
-
|
|
8004
|
-
|
|
8005
|
-
|
|
8006
|
-
|
|
7931
|
+
}
|
|
7932
|
+
}
|
|
7933
|
+
resolveSelectionResolution(localSelection) {
|
|
7934
|
+
const anchorCell = this.getCellAtLocalPosition(localSelection.anchorX, localSelection.anchorY);
|
|
7935
|
+
const focusCell = this.getCellAtLocalPosition(localSelection.focusX, localSelection.focusY);
|
|
7936
|
+
const anchorColumn = anchorCell?.colIdx ?? this.getColumnAtLocalX(localSelection.anchorX);
|
|
7937
|
+
if (anchorCell !== null && focusCell !== null && anchorCell.rowIdx === focusCell.rowIdx && anchorCell.colIdx === focusCell.colIdx) {
|
|
7938
|
+
return {
|
|
7939
|
+
mode: "single-cell",
|
|
7940
|
+
anchorCell,
|
|
7941
|
+
anchorColumn
|
|
7942
|
+
};
|
|
7943
|
+
}
|
|
7944
|
+
const focusColumn = this.getColumnAtLocalX(localSelection.focusX);
|
|
7945
|
+
if (anchorColumn !== null && focusColumn === anchorColumn) {
|
|
7946
|
+
return {
|
|
7947
|
+
mode: "column-locked",
|
|
7948
|
+
anchorCell,
|
|
7949
|
+
anchorColumn
|
|
7950
|
+
};
|
|
7951
|
+
}
|
|
7952
|
+
return {
|
|
7953
|
+
mode: "grid",
|
|
7954
|
+
anchorCell,
|
|
7955
|
+
anchorColumn
|
|
7956
|
+
};
|
|
7957
|
+
}
|
|
7958
|
+
getColumnAtLocalX(localX) {
|
|
7959
|
+
if (this._columnCount === 0)
|
|
7960
|
+
return null;
|
|
7961
|
+
if (localX < 0 || localX >= this._layout.tableWidth)
|
|
7962
|
+
return null;
|
|
7963
|
+
for (let colIdx = 0;colIdx < this._columnCount; colIdx++) {
|
|
7964
|
+
const colStart = (this._layout.columnOffsets[colIdx] ?? 0) + 1;
|
|
7965
|
+
const colEnd = colStart + (this._layout.columnWidths[colIdx] ?? 1) - 1;
|
|
7966
|
+
if (localX >= colStart && localX <= colEnd) {
|
|
7967
|
+
return colIdx;
|
|
8007
7968
|
}
|
|
8008
|
-
|
|
8009
|
-
|
|
7969
|
+
}
|
|
7970
|
+
return null;
|
|
8010
7971
|
}
|
|
8011
|
-
|
|
8012
|
-
|
|
7972
|
+
getFullCellSelectionCoords(rowIdx, colIdx) {
|
|
7973
|
+
const colWidth = this._layout.columnWidths[colIdx] ?? 1;
|
|
7974
|
+
const rowHeight = this._layout.rowHeights[rowIdx] ?? 1;
|
|
7975
|
+
const contentWidth = Math.max(1, colWidth - this.getHorizontalCellPadding());
|
|
7976
|
+
const contentHeight = Math.max(1, rowHeight - this.getVerticalCellPadding());
|
|
7977
|
+
return {
|
|
7978
|
+
anchorX: -1,
|
|
7979
|
+
anchorY: 0,
|
|
7980
|
+
focusX: contentWidth,
|
|
7981
|
+
focusY: contentHeight
|
|
7982
|
+
};
|
|
8013
7983
|
}
|
|
8014
|
-
|
|
8015
|
-
|
|
7984
|
+
findRowForLocalY(localY) {
|
|
7985
|
+
if (this._rowCount === 0)
|
|
7986
|
+
return 0;
|
|
7987
|
+
if (localY < 0)
|
|
7988
|
+
return 0;
|
|
7989
|
+
for (let rowIdx = 0;rowIdx < this._rowCount; rowIdx++) {
|
|
7990
|
+
const rowStart = (this._layout.rowOffsets[rowIdx] ?? 0) + 1;
|
|
7991
|
+
const rowEnd = rowStart + (this._layout.rowHeights[rowIdx] ?? 1) - 1;
|
|
7992
|
+
if (localY <= rowEnd)
|
|
7993
|
+
return rowIdx;
|
|
7994
|
+
}
|
|
7995
|
+
return this._rowCount - 1;
|
|
8016
7996
|
}
|
|
8017
|
-
|
|
8018
|
-
|
|
7997
|
+
getSelectionRowRange(selection) {
|
|
7998
|
+
if (!selection?.isActive || this._rowCount === 0)
|
|
7999
|
+
return null;
|
|
8000
|
+
const minSelY = Math.min(selection.anchorY, selection.focusY);
|
|
8001
|
+
const maxSelY = Math.max(selection.anchorY, selection.focusY);
|
|
8002
|
+
return {
|
|
8003
|
+
firstRow: this.findRowForLocalY(minSelY),
|
|
8004
|
+
lastRow: this.findRowForLocalY(maxSelY)
|
|
8005
|
+
};
|
|
8019
8006
|
}
|
|
8020
|
-
|
|
8021
|
-
|
|
8022
|
-
|
|
8023
|
-
|
|
8024
|
-
|
|
8025
|
-
|
|
8026
|
-
|
|
8027
|
-
|
|
8028
|
-
|
|
8029
|
-
|
|
8030
|
-
return (async () => {
|
|
8031
|
-
let o = s.hooks ? await s.hooks.preprocess(n) : n, p = await (s.hooks ? await s.hooks.provideLexer() : e ? x.lex : x.lexInline)(o, s), c = s.hooks ? await s.hooks.processAllTokens(p) : p;
|
|
8032
|
-
s.walkTokens && await Promise.all(this.walkTokens(c, s.walkTokens));
|
|
8033
|
-
let h2 = await (s.hooks ? await s.hooks.provideParser() : e ? b.parse : b.parseInline)(c, s);
|
|
8034
|
-
return s.hooks ? await s.hooks.postprocess(h2) : h2;
|
|
8035
|
-
})().catch(a);
|
|
8036
|
-
try {
|
|
8037
|
-
s.hooks && (n = s.hooks.preprocess(n));
|
|
8038
|
-
let l = (s.hooks ? s.hooks.provideLexer() : e ? x.lex : x.lexInline)(n, s);
|
|
8039
|
-
s.hooks && (l = s.hooks.processAllTokens(l)), s.walkTokens && this.walkTokens(l, s.walkTokens);
|
|
8040
|
-
let c = (s.hooks ? s.hooks.provideParser() : e ? b.parse : b.parseInline)(l, s);
|
|
8041
|
-
return s.hooks && (c = s.hooks.postprocess(c)), c;
|
|
8042
|
-
} catch (o) {
|
|
8043
|
-
return a(o);
|
|
8044
|
-
}
|
|
8007
|
+
getDirtySelectionRowRange(previousSelection, currentSelection) {
|
|
8008
|
+
const previousRange = this.getSelectionRowRange(previousSelection);
|
|
8009
|
+
const currentRange = this.getSelectionRowRange(currentSelection);
|
|
8010
|
+
if (previousRange === null)
|
|
8011
|
+
return currentRange;
|
|
8012
|
+
if (currentRange === null)
|
|
8013
|
+
return previousRange;
|
|
8014
|
+
return {
|
|
8015
|
+
firstRow: Math.min(previousRange.firstRow, currentRange.firstRow),
|
|
8016
|
+
lastRow: Math.max(previousRange.lastRow, currentRange.lastRow)
|
|
8045
8017
|
};
|
|
8046
8018
|
}
|
|
8047
|
-
|
|
8048
|
-
|
|
8049
|
-
|
|
8050
|
-
|
|
8051
|
-
|
|
8052
|
-
|
|
8053
|
-
|
|
8054
|
-
|
|
8055
|
-
|
|
8056
|
-
|
|
8019
|
+
resetRowSelection(rowIdx) {
|
|
8020
|
+
const row = this._cells[rowIdx];
|
|
8021
|
+
if (!row)
|
|
8022
|
+
return;
|
|
8023
|
+
for (const cell of row) {
|
|
8024
|
+
cell.textBufferView.resetLocalSelection();
|
|
8025
|
+
}
|
|
8026
|
+
}
|
|
8027
|
+
resetCellSelections() {
|
|
8028
|
+
for (let rowIdx = 0;rowIdx < this._rowCount; rowIdx++) {
|
|
8029
|
+
this.resetRowSelection(rowIdx);
|
|
8030
|
+
}
|
|
8031
|
+
}
|
|
8032
|
+
createEmptyLayout() {
|
|
8033
|
+
return {
|
|
8034
|
+
columnWidths: [],
|
|
8035
|
+
rowHeights: [],
|
|
8036
|
+
columnOffsets: [0],
|
|
8037
|
+
rowOffsets: [0],
|
|
8038
|
+
columnOffsetsI32: new Int32Array([0]),
|
|
8039
|
+
rowOffsetsI32: new Int32Array([0]),
|
|
8040
|
+
tableWidth: 0,
|
|
8041
|
+
tableHeight: 0
|
|
8057
8042
|
};
|
|
8058
8043
|
}
|
|
8059
|
-
|
|
8060
|
-
|
|
8061
|
-
|
|
8062
|
-
|
|
8044
|
+
resolveLayoutWidthConstraint(width) {
|
|
8045
|
+
if (width === undefined || !Number.isFinite(width) || width <= 0) {
|
|
8046
|
+
return;
|
|
8047
|
+
}
|
|
8048
|
+
if (this._wrapMode !== "none" || this.isFullWidthMode()) {
|
|
8049
|
+
return Math.max(1, Math.floor(width));
|
|
8050
|
+
}
|
|
8051
|
+
return;
|
|
8052
|
+
}
|
|
8053
|
+
getHorizontalCellPadding() {
|
|
8054
|
+
return this._cellPaddingX * 2;
|
|
8055
|
+
}
|
|
8056
|
+
getVerticalCellPadding() {
|
|
8057
|
+
return this._cellPaddingY * 2;
|
|
8058
|
+
}
|
|
8059
|
+
resolveColumnFitter(value) {
|
|
8060
|
+
if (value === undefined) {
|
|
8061
|
+
return this._defaultOptions.columnFitter;
|
|
8062
|
+
}
|
|
8063
|
+
return value === "balanced" ? "balanced" : "proportional";
|
|
8064
|
+
}
|
|
8065
|
+
resolveCellPadding(value) {
|
|
8066
|
+
if (value === undefined || !Number.isFinite(value)) {
|
|
8067
|
+
return this._defaultOptions.cellPadding;
|
|
8068
|
+
}
|
|
8069
|
+
return Math.max(0, Math.floor(value));
|
|
8070
|
+
}
|
|
8071
|
+
resolveColumnGap(value) {
|
|
8072
|
+
if (value === undefined || !Number.isFinite(value)) {
|
|
8073
|
+
return this._defaultOptions.columnGap;
|
|
8074
|
+
}
|
|
8075
|
+
return Math.max(0, Math.floor(value));
|
|
8076
|
+
}
|
|
8077
|
+
invalidateLayoutAndRaster(markYogaDirty = true) {
|
|
8078
|
+
this._layoutDirty = true;
|
|
8079
|
+
this._rasterDirty = true;
|
|
8080
|
+
this._cachedMeasureLayout = null;
|
|
8081
|
+
this._cachedMeasureWidth = undefined;
|
|
8082
|
+
if (markYogaDirty) {
|
|
8083
|
+
this.yogaNode.markDirty();
|
|
8084
|
+
}
|
|
8085
|
+
this.requestRender();
|
|
8086
|
+
}
|
|
8087
|
+
invalidateRasterOnly() {
|
|
8088
|
+
this._rasterDirty = true;
|
|
8089
|
+
this.requestRender();
|
|
8090
|
+
}
|
|
8063
8091
|
}
|
|
8064
|
-
d.options = d.setOptions = function(u3) {
|
|
8065
|
-
return _.setOptions(u3), d.defaults = _.defaults, Z(d.defaults), d;
|
|
8066
|
-
};
|
|
8067
|
-
d.getDefaults = L;
|
|
8068
|
-
d.defaults = T;
|
|
8069
|
-
d.use = function(...u3) {
|
|
8070
|
-
return _.use(...u3), d.defaults = _.defaults, Z(d.defaults), d;
|
|
8071
|
-
};
|
|
8072
|
-
d.walkTokens = function(u3, e) {
|
|
8073
|
-
return _.walkTokens(u3, e);
|
|
8074
|
-
};
|
|
8075
|
-
d.parseInline = _.parseInline;
|
|
8076
|
-
d.Parser = b;
|
|
8077
|
-
d.parser = b.parse;
|
|
8078
|
-
d.Renderer = P;
|
|
8079
|
-
d.TextRenderer = $;
|
|
8080
|
-
d.Lexer = x;
|
|
8081
|
-
d.lexer = x.lex;
|
|
8082
|
-
d.Tokenizer = y;
|
|
8083
|
-
d.Hooks = S;
|
|
8084
|
-
d.parse = d;
|
|
8085
|
-
var Dt = d.options;
|
|
8086
|
-
var Ht = d.setOptions;
|
|
8087
|
-
var Zt = d.use;
|
|
8088
|
-
var Gt = d.walkTokens;
|
|
8089
|
-
var Nt = d.parseInline;
|
|
8090
|
-
var Ft = b.parse;
|
|
8091
|
-
var jt = x.lex;
|
|
8092
8092
|
|
|
8093
8093
|
// src/renderables/markdown-parser.ts
|
|
8094
8094
|
function parseMarkdownIncremental(newContent, prevState, trailingUnstable = 2) {
|
|
@@ -8358,6 +8358,18 @@ class MarkdownRenderable extends Renderable {
|
|
|
8358
8358
|
createDefaultChunk(text) {
|
|
8359
8359
|
return this.createChunk(text, "default");
|
|
8360
8360
|
}
|
|
8361
|
+
createInitialStyledText(token) {
|
|
8362
|
+
if (!this._streaming)
|
|
8363
|
+
return;
|
|
8364
|
+
const chunks = [];
|
|
8365
|
+
if ("tokens" in token && Array.isArray(token.tokens)) {
|
|
8366
|
+
this.renderInlineContent(token.tokens, chunks);
|
|
8367
|
+
}
|
|
8368
|
+
if (chunks.length === 0 && "text" in token && typeof token.text === "string") {
|
|
8369
|
+
this.renderInlineContent(x.lexInline(token.text), chunks);
|
|
8370
|
+
}
|
|
8371
|
+
return chunks.length > 0 ? new StyledText(chunks) : undefined;
|
|
8372
|
+
}
|
|
8361
8373
|
renderInlineContent(tokens, chunks) {
|
|
8362
8374
|
for (const token of tokens) {
|
|
8363
8375
|
this.renderInlineToken(token, chunks);
|
|
@@ -8485,7 +8497,7 @@ class MarkdownRenderable extends Renderable {
|
|
|
8485
8497
|
renderable.marginTop = marginTop;
|
|
8486
8498
|
renderable.marginBottom = marginBottom;
|
|
8487
8499
|
}
|
|
8488
|
-
createMarkdownCodeRenderable(content, id, marginBottom = 0, onChunks = this._linkifyMarkdownChunks, baseHighlight) {
|
|
8500
|
+
createMarkdownCodeRenderable(content, id, marginBottom = 0, onChunks = this._linkifyMarkdownChunks, baseHighlight, initialStyledText) {
|
|
8489
8501
|
return new CodeRenderable(this.ctx, {
|
|
8490
8502
|
id,
|
|
8491
8503
|
content,
|
|
@@ -8494,8 +8506,9 @@ class MarkdownRenderable extends Renderable {
|
|
|
8494
8506
|
fg: this._fg,
|
|
8495
8507
|
bg: this._bg,
|
|
8496
8508
|
conceal: this._conceal,
|
|
8497
|
-
drawUnstyledText:
|
|
8509
|
+
drawUnstyledText: initialStyledText !== undefined,
|
|
8498
8510
|
streaming: true,
|
|
8511
|
+
initialStyledText,
|
|
8499
8512
|
baseHighlight,
|
|
8500
8513
|
onChunks,
|
|
8501
8514
|
treeSitterClient: this._treeSitterClient,
|
|
@@ -8701,7 +8714,7 @@ class MarkdownRenderable extends Renderable {
|
|
|
8701
8714
|
}
|
|
8702
8715
|
createListChildRenderable(token, id) {
|
|
8703
8716
|
if (token.type === "text" || token.type === "paragraph") {
|
|
8704
|
-
return this.createMarkdownCodeRenderable(this.normalizeScrollbackMarkdownBlockRaw(token.raw), id);
|
|
8717
|
+
return this.createMarkdownCodeRenderable(this.normalizeScrollbackMarkdownBlockRaw(token.raw), id, 0, this._linkifyMarkdownChunks, undefined, this.createInitialStyledText(token));
|
|
8705
8718
|
}
|
|
8706
8719
|
if (token.type === "list")
|
|
8707
8720
|
return this.createListRenderable(token, id);
|
|
@@ -8713,7 +8726,7 @@ class MarkdownRenderable extends Renderable {
|
|
|
8713
8726
|
return this.createHorizontalRuleRenderable(id);
|
|
8714
8727
|
if (token.type === "table")
|
|
8715
8728
|
return this.createTableBlock(token, id).renderable;
|
|
8716
|
-
return token.raw ? this.createMarkdownCodeRenderable(token.raw, id) : null;
|
|
8729
|
+
return token.raw ? this.createMarkdownCodeRenderable(token.raw, id, 0, this._linkifyMarkdownChunks, undefined, this.createInitialStyledText(token)) : null;
|
|
8717
8730
|
}
|
|
8718
8731
|
createHorizontalRuleRenderable(id, marginBottom = 0) {
|
|
8719
8732
|
return new BoxRenderable(this.ctx, {
|
|
@@ -8742,16 +8755,17 @@ class MarkdownRenderable extends Renderable {
|
|
|
8742
8755
|
marginBottom
|
|
8743
8756
|
});
|
|
8744
8757
|
}
|
|
8745
|
-
applyMarkdownCodeRenderable(renderable, content, marginBottom, baseHighlight) {
|
|
8746
|
-
renderable.
|
|
8758
|
+
applyMarkdownCodeRenderable(renderable, content, marginBottom, baseHighlight, initialStyledText) {
|
|
8759
|
+
renderable.initialStyledText = initialStyledText;
|
|
8747
8760
|
renderable.filetype = "markdown";
|
|
8748
8761
|
renderable.syntaxStyle = this._syntaxStyle;
|
|
8749
8762
|
renderable.fg = this._fg;
|
|
8750
8763
|
renderable.bg = this._bg;
|
|
8751
8764
|
renderable.conceal = this._conceal;
|
|
8752
|
-
renderable.drawUnstyledText =
|
|
8765
|
+
renderable.drawUnstyledText = initialStyledText !== undefined;
|
|
8753
8766
|
renderable.streaming = true;
|
|
8754
8767
|
renderable.baseHighlight = baseHighlight;
|
|
8768
|
+
renderable.content = content;
|
|
8755
8769
|
renderable.marginBottom = marginBottom;
|
|
8756
8770
|
}
|
|
8757
8771
|
applyBlockquoteRenderable(renderable, token, marginBottom) {
|
|
@@ -9161,7 +9175,7 @@ class MarkdownRenderable extends Renderable {
|
|
|
9161
9175
|
if (!markdownRaw) {
|
|
9162
9176
|
return { renderable: undefined, canUpdateInPlace: true };
|
|
9163
9177
|
}
|
|
9164
|
-
const renderable = this.createMarkdownCodeRenderable(markdownRaw, id);
|
|
9178
|
+
const renderable = this.createMarkdownCodeRenderable(markdownRaw, id, 0, this._linkifyMarkdownChunks, undefined, this.createInitialStyledText(token));
|
|
9165
9179
|
renderable.marginTop = marginTop;
|
|
9166
9180
|
return { renderable, canUpdateInPlace: true };
|
|
9167
9181
|
}
|
|
@@ -9204,7 +9218,7 @@ class MarkdownRenderable extends Renderable {
|
|
|
9204
9218
|
if (!token.raw) {
|
|
9205
9219
|
return null;
|
|
9206
9220
|
}
|
|
9207
|
-
return this.createMarkdownCodeRenderable(token.raw, id, marginBottom);
|
|
9221
|
+
return this.createMarkdownCodeRenderable(token.raw, id, marginBottom, this._linkifyMarkdownChunks, undefined, this.createInitialStyledText(token));
|
|
9208
9222
|
}
|
|
9209
9223
|
createCustomRenderable(token, index, nextToken) {
|
|
9210
9224
|
const custom = this.renderCustomNode(token, () => {
|
|
@@ -9312,11 +9326,11 @@ class MarkdownRenderable extends Renderable {
|
|
|
9312
9326
|
return;
|
|
9313
9327
|
}
|
|
9314
9328
|
if (state.renderable instanceof CodeRenderable) {
|
|
9315
|
-
this.applyMarkdownCodeRenderable(state.renderable, this.getTopLevelBlockRaw(token) ?? token.raw, marginBottom);
|
|
9329
|
+
this.applyMarkdownCodeRenderable(state.renderable, this.getTopLevelBlockRaw(token) ?? token.raw, marginBottom, undefined, this.createInitialStyledText(token));
|
|
9316
9330
|
return;
|
|
9317
9331
|
}
|
|
9318
9332
|
state.renderable.destroyRecursively();
|
|
9319
|
-
const markdownRenderable = this.createMarkdownCodeRenderable(this.getTopLevelBlockRaw(token) ?? token.raw, `${this.id}-block-${index}`, marginBottom);
|
|
9333
|
+
const markdownRenderable = this.createMarkdownCodeRenderable(this.getTopLevelBlockRaw(token) ?? token.raw, `${this.id}-block-${index}`, marginBottom, this._linkifyMarkdownChunks, undefined, this.createInitialStyledText(token));
|
|
9320
9334
|
this.add(markdownRenderable, index);
|
|
9321
9335
|
state.renderable = markdownRenderable;
|
|
9322
9336
|
}
|
|
@@ -9602,11 +9616,11 @@ class MarkdownRenderable extends Renderable {
|
|
|
9602
9616
|
continue;
|
|
9603
9617
|
}
|
|
9604
9618
|
if (state.renderable instanceof CodeRenderable) {
|
|
9605
|
-
this.applyMarkdownCodeRenderable(state.renderable, this.getTopLevelBlockRaw(state.token) ?? state.token.raw, marginBottom);
|
|
9619
|
+
this.applyMarkdownCodeRenderable(state.renderable, this.getTopLevelBlockRaw(state.token) ?? state.token.raw, marginBottom, undefined, this.createInitialStyledText(state.token));
|
|
9606
9620
|
continue;
|
|
9607
9621
|
}
|
|
9608
9622
|
state.renderable.destroyRecursively();
|
|
9609
|
-
const markdownRenderable = this.createMarkdownCodeRenderable(this.getTopLevelBlockRaw(state.token) ?? state.token.raw, `${this.id}-block-${i}`, marginBottom);
|
|
9623
|
+
const markdownRenderable = this.createMarkdownCodeRenderable(this.getTopLevelBlockRaw(state.token) ?? state.token.raw, `${this.id}-block-${i}`, marginBottom, this._linkifyMarkdownChunks, undefined, this.createInitialStyledText(state.token));
|
|
9610
9624
|
this.add(markdownRenderable, i);
|
|
9611
9625
|
state.renderable = markdownRenderable;
|
|
9612
9626
|
}
|
|
@@ -11666,5 +11680,5 @@ class TimeToFirstDrawRenderable extends Renderable {
|
|
|
11666
11680
|
}
|
|
11667
11681
|
export { DistortionEffect, VignetteEffect, CloudsEffect, FlamesEffect, CRTRollingBarEffect, RainbowTextEffect, applyScanlines, applyInvert, applyNoise, applyChromaticAberration, applyAsciiArt, applyBrightness, applyGain, applySaturation, BloomEffect, SEPIA_MATRIX, PROTANOPIA_SIM_MATRIX, DEUTERANOPIA_SIM_MATRIX, TRITANOPIA_SIM_MATRIX, ACHROMATOPSIA_MATRIX, PROTANOPIA_COMP_MATRIX, DEUTERANOPIA_COMP_MATRIX, TRITANOPIA_COMP_MATRIX, TECHNICOLOR_MATRIX, SOLARIZATION_MATRIX, SYNTHWAVE_MATRIX, GREENSCALE_MATRIX, GRAYSCALE_MATRIX, INVERT_MATRIX, Timeline, engine, createTimeline, SlotRegistry, createSlotRegistry, createCoreSlotRegistry, registerCorePlugin, resolveCoreSlot, SlotRenderable, Audio, setupAudio, FrameBufferRenderable, ASCIIFontRenderable, Generic, Box, Text, ASCIIFont, Input, Select, TabSelect, FrameBuffer, Code, ScrollBox, vstyles, VRenderable, LineNumberRenderable, DiffRenderable, defaultTextareaKeyBindings, TextareaRenderable, InputRenderableEvents, InputRenderable, TextTableRenderable, createMarkdownCodeBlockRenderer, MarkdownRenderable, SliderRenderable, ScrollBarRenderable, ArrowRenderable, ScrollBoxRenderable, SelectRenderableEvents, SelectRenderable, TabSelectRenderableEvents, TabSelectRenderable, TimeToFirstDrawRenderable, exports_src2 as exports_src };
|
|
11668
11682
|
|
|
11669
|
-
//# debugId=
|
|
11670
|
-
//# sourceMappingURL=index-
|
|
11683
|
+
//# debugId=62478FB2F54165DB64756E2164756E21
|
|
11684
|
+
//# sourceMappingURL=index-0nvgrgam.js.map
|