@fairyhunter13/opentui-core 0.1.97 → 0.1.99

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.
@@ -8089,1006 +8089,6 @@ class InputRenderable extends TextareaRenderable {
8089
8089
  }
8090
8090
  set initialValue(value) {}
8091
8091
  }
8092
- // src/renderables/TextTable.ts
8093
- var MEASURE_HEIGHT = 1e4;
8094
-
8095
- class TextTableRenderable extends Renderable {
8096
- _content;
8097
- _wrapMode;
8098
- _columnWidthMode;
8099
- _columnFitter;
8100
- _cellPadding;
8101
- _showBorders;
8102
- _border;
8103
- _outerBorder;
8104
- _hasExplicitOuterBorder;
8105
- _borderStyle;
8106
- _borderColor;
8107
- _borderBackgroundColor;
8108
- _backgroundColor;
8109
- _defaultFg;
8110
- _defaultBg;
8111
- _defaultAttributes;
8112
- _selectionBg;
8113
- _selectionFg;
8114
- _lastLocalSelection = null;
8115
- _lastSelectionMode = null;
8116
- _cells = [];
8117
- _prevCellContent = [];
8118
- _rowCount = 0;
8119
- _columnCount = 0;
8120
- _layout = this.createEmptyLayout();
8121
- _layoutDirty = true;
8122
- _rasterDirty = true;
8123
- _cachedMeasureLayout = null;
8124
- _cachedMeasureWidth = undefined;
8125
- _defaultOptions = {
8126
- content: [],
8127
- wrapMode: "word",
8128
- columnWidthMode: "full",
8129
- columnFitter: "proportional",
8130
- cellPadding: 0,
8131
- showBorders: true,
8132
- border: true,
8133
- outerBorder: true,
8134
- selectable: true,
8135
- selectionBg: undefined,
8136
- selectionFg: undefined,
8137
- borderStyle: "single",
8138
- borderColor: "#FFFFFF",
8139
- borderBackgroundColor: "transparent",
8140
- backgroundColor: "transparent",
8141
- fg: "#FFFFFF",
8142
- bg: "transparent",
8143
- attributes: 0
8144
- };
8145
- constructor(ctx, options = {}) {
8146
- super(ctx, { ...options, flexShrink: options.flexShrink ?? 0, buffered: true });
8147
- this._content = options.content ?? this._defaultOptions.content;
8148
- this._wrapMode = options.wrapMode ?? this._defaultOptions.wrapMode;
8149
- this._columnWidthMode = options.columnWidthMode ?? this._defaultOptions.columnWidthMode;
8150
- this._columnFitter = this.resolveColumnFitter(options.columnFitter);
8151
- this._cellPadding = this.resolveCellPadding(options.cellPadding);
8152
- this._showBorders = options.showBorders ?? this._defaultOptions.showBorders;
8153
- this._border = options.border ?? this._defaultOptions.border;
8154
- this._hasExplicitOuterBorder = options.outerBorder !== undefined;
8155
- this._outerBorder = options.outerBorder ?? this._border;
8156
- this.selectable = options.selectable ?? this._defaultOptions.selectable;
8157
- this._selectionBg = options.selectionBg ? parseColor(options.selectionBg) : undefined;
8158
- this._selectionFg = options.selectionFg ? parseColor(options.selectionFg) : undefined;
8159
- this._borderStyle = parseBorderStyle(options.borderStyle, this._defaultOptions.borderStyle);
8160
- this._borderColor = parseColor(options.borderColor ?? this._defaultOptions.borderColor);
8161
- this._borderBackgroundColor = parseColor(options.borderBackgroundColor ?? this._defaultOptions.borderBackgroundColor);
8162
- this._backgroundColor = parseColor(options.backgroundColor ?? this._defaultOptions.backgroundColor);
8163
- this._defaultFg = parseColor(options.fg ?? this._defaultOptions.fg);
8164
- this._defaultBg = parseColor(options.bg ?? this._defaultOptions.bg);
8165
- this._defaultAttributes = options.attributes ?? this._defaultOptions.attributes;
8166
- this.setupMeasureFunc();
8167
- this.rebuildCells();
8168
- }
8169
- get content() {
8170
- return this._content;
8171
- }
8172
- set content(value) {
8173
- this._content = value ?? [];
8174
- this.rebuildCells();
8175
- }
8176
- get wrapMode() {
8177
- return this._wrapMode;
8178
- }
8179
- set wrapMode(value) {
8180
- if (this._wrapMode === value)
8181
- return;
8182
- this._wrapMode = value;
8183
- for (const row of this._cells) {
8184
- for (const cell of row) {
8185
- cell.textBufferView.setWrapMode(value);
8186
- }
8187
- }
8188
- this.invalidateLayoutAndRaster();
8189
- }
8190
- get columnWidthMode() {
8191
- return this._columnWidthMode;
8192
- }
8193
- set columnWidthMode(value) {
8194
- if (this._columnWidthMode === value)
8195
- return;
8196
- this._columnWidthMode = value;
8197
- this.invalidateLayoutAndRaster();
8198
- }
8199
- get columnFitter() {
8200
- return this._columnFitter;
8201
- }
8202
- set columnFitter(value) {
8203
- const next = this.resolveColumnFitter(value);
8204
- if (this._columnFitter === next)
8205
- return;
8206
- this._columnFitter = next;
8207
- this.invalidateLayoutAndRaster();
8208
- }
8209
- get cellPadding() {
8210
- return this._cellPadding;
8211
- }
8212
- set cellPadding(value) {
8213
- const next = this.resolveCellPadding(value);
8214
- if (this._cellPadding === next)
8215
- return;
8216
- this._cellPadding = next;
8217
- this.invalidateLayoutAndRaster();
8218
- }
8219
- get showBorders() {
8220
- return this._showBorders;
8221
- }
8222
- set showBorders(value) {
8223
- if (this._showBorders === value)
8224
- return;
8225
- this._showBorders = value;
8226
- this.invalidateRasterOnly();
8227
- }
8228
- get outerBorder() {
8229
- return this._outerBorder;
8230
- }
8231
- set outerBorder(value) {
8232
- if (this._outerBorder === value)
8233
- return;
8234
- this._hasExplicitOuterBorder = true;
8235
- this._outerBorder = value;
8236
- this.invalidateLayoutAndRaster();
8237
- }
8238
- get border() {
8239
- return this._border;
8240
- }
8241
- set border(value) {
8242
- if (this._border === value)
8243
- return;
8244
- this._border = value;
8245
- if (!this._hasExplicitOuterBorder) {
8246
- this._outerBorder = value;
8247
- }
8248
- this.invalidateLayoutAndRaster();
8249
- }
8250
- get borderStyle() {
8251
- return this._borderStyle;
8252
- }
8253
- set borderStyle(value) {
8254
- const next = parseBorderStyle(value, this._defaultOptions.borderStyle);
8255
- if (this._borderStyle === next)
8256
- return;
8257
- this._borderStyle = next;
8258
- this.invalidateRasterOnly();
8259
- }
8260
- get borderColor() {
8261
- return this._borderColor;
8262
- }
8263
- set borderColor(value) {
8264
- const next = parseColor(value);
8265
- if (this._borderColor === next)
8266
- return;
8267
- this._borderColor = next;
8268
- this.invalidateRasterOnly();
8269
- }
8270
- shouldStartSelection(x, y) {
8271
- if (!this.selectable)
8272
- return false;
8273
- this.ensureLayoutReady();
8274
- const localX = x - this.x;
8275
- const localY = y - this.y;
8276
- return this.getCellAtLocalPosition(localX, localY) !== null;
8277
- }
8278
- onSelectionChanged(selection) {
8279
- this.ensureLayoutReady();
8280
- const previousLocalSelection = this._lastLocalSelection;
8281
- const localSelection = convertGlobalToLocalSelection(selection, this.x, this.y);
8282
- this._lastLocalSelection = localSelection;
8283
- const dirtyRows = this.getDirtySelectionRowRange(previousLocalSelection, localSelection);
8284
- if (!localSelection?.isActive) {
8285
- this.resetCellSelections();
8286
- this._lastSelectionMode = null;
8287
- } else {
8288
- this.applySelectionToCells(localSelection, selection?.isStart ?? false);
8289
- }
8290
- if (dirtyRows !== null) {
8291
- this.redrawSelectionRows(dirtyRows.firstRow, dirtyRows.lastRow);
8292
- }
8293
- return this.hasSelection();
8294
- }
8295
- hasSelection() {
8296
- for (const row of this._cells) {
8297
- for (const cell of row) {
8298
- if (cell.textBufferView.hasSelection()) {
8299
- return true;
8300
- }
8301
- }
8302
- }
8303
- return false;
8304
- }
8305
- getSelection() {
8306
- for (const row of this._cells) {
8307
- for (const cell of row) {
8308
- const selection = cell.textBufferView.getSelection();
8309
- if (selection) {
8310
- return selection;
8311
- }
8312
- }
8313
- }
8314
- return null;
8315
- }
8316
- getSelectedText() {
8317
- const selectedRows = [];
8318
- for (let rowIdx = 0;rowIdx < this._rowCount; rowIdx++) {
8319
- const rowSelections = [];
8320
- for (let colIdx = 0;colIdx < this._columnCount; colIdx++) {
8321
- const cell = this._cells[rowIdx]?.[colIdx];
8322
- if (!cell || !cell.textBufferView.hasSelection())
8323
- continue;
8324
- const selectedText = cell.textBufferView.getSelectedText();
8325
- if (selectedText.length > 0) {
8326
- rowSelections.push(selectedText);
8327
- }
8328
- }
8329
- if (rowSelections.length > 0) {
8330
- selectedRows.push(rowSelections.join("\t"));
8331
- }
8332
- }
8333
- return selectedRows.join(`
8334
- `);
8335
- }
8336
- onResize(width, height) {
8337
- this.invalidateLayoutAndRaster(false);
8338
- super.onResize(width, height);
8339
- }
8340
- renderSelf(buffer) {
8341
- if (!this.visible || this.isDestroyed)
8342
- return;
8343
- if (this._layoutDirty) {
8344
- this.rebuildLayoutForCurrentWidth();
8345
- }
8346
- if (!this._rasterDirty)
8347
- return;
8348
- buffer.clear(this._backgroundColor);
8349
- if (this._rowCount === 0 || this._columnCount === 0) {
8350
- this._rasterDirty = false;
8351
- return;
8352
- }
8353
- this.drawBorders(buffer);
8354
- this.drawCells(buffer);
8355
- this._rasterDirty = false;
8356
- }
8357
- destroySelf() {
8358
- this.destroyCells();
8359
- super.destroySelf();
8360
- }
8361
- setupMeasureFunc() {
8362
- const measureFunc = (width, widthMode, _height, _heightMode) => {
8363
- const hasWidthConstraint = widthMode !== MeasureMode.Undefined && Number.isFinite(width);
8364
- const rawWidthConstraint = hasWidthConstraint ? Math.max(1, Math.floor(width)) : undefined;
8365
- const widthConstraint = this.resolveLayoutWidthConstraint(rawWidthConstraint);
8366
- const measuredLayout = this.computeLayout(widthConstraint);
8367
- this._cachedMeasureLayout = measuredLayout;
8368
- this._cachedMeasureWidth = widthConstraint;
8369
- let measuredWidth = measuredLayout.tableWidth > 0 ? measuredLayout.tableWidth : 1;
8370
- let measuredHeight = measuredLayout.tableHeight > 0 ? measuredLayout.tableHeight : 1;
8371
- if (widthMode === MeasureMode.AtMost && rawWidthConstraint !== undefined && this._positionType !== "absolute") {
8372
- measuredWidth = Math.min(rawWidthConstraint, measuredWidth);
8373
- }
8374
- return {
8375
- width: measuredWidth,
8376
- height: measuredHeight
8377
- };
8378
- };
8379
- this.yogaNode.setMeasureFunc(measureFunc);
8380
- }
8381
- rebuildCells() {
8382
- const newRowCount = this._content.length;
8383
- const newColumnCount = this._content.reduce((max, row) => Math.max(max, row.length), 0);
8384
- if (this._cells.length === 0) {
8385
- this._rowCount = newRowCount;
8386
- this._columnCount = newColumnCount;
8387
- this._cells = [];
8388
- this._prevCellContent = [];
8389
- for (let rowIdx = 0;rowIdx < newRowCount; rowIdx++) {
8390
- const row = this._content[rowIdx] ?? [];
8391
- const rowCells = [];
8392
- const rowRefs = [];
8393
- for (let colIdx = 0;colIdx < newColumnCount; colIdx++) {
8394
- const cellContent = row[colIdx];
8395
- rowCells.push(this.createCell(cellContent));
8396
- rowRefs.push(cellContent);
8397
- }
8398
- this._cells.push(rowCells);
8399
- this._prevCellContent.push(rowRefs);
8400
- }
8401
- this.invalidateLayoutAndRaster();
8402
- return;
8403
- }
8404
- this.updateCellsDiff(newRowCount, newColumnCount);
8405
- this.invalidateLayoutAndRaster();
8406
- }
8407
- updateCellsDiff(newRowCount, newColumnCount) {
8408
- const oldRowCount = this._rowCount;
8409
- const oldColumnCount = this._columnCount;
8410
- const keepRows = Math.min(oldRowCount, newRowCount);
8411
- const keepCols = Math.min(oldColumnCount, newColumnCount);
8412
- for (let rowIdx = 0;rowIdx < keepRows; rowIdx++) {
8413
- const newRow = this._content[rowIdx] ?? [];
8414
- const cellRow = this._cells[rowIdx];
8415
- const refRow = this._prevCellContent[rowIdx];
8416
- for (let colIdx = 0;colIdx < keepCols; colIdx++) {
8417
- const cellContent = newRow[colIdx];
8418
- if (cellContent === refRow[colIdx])
8419
- continue;
8420
- const oldCell = cellRow[colIdx];
8421
- oldCell.textBufferView.destroy();
8422
- oldCell.textBuffer.destroy();
8423
- oldCell.syntaxStyle.destroy();
8424
- cellRow[colIdx] = this.createCell(cellContent);
8425
- refRow[colIdx] = cellContent;
8426
- }
8427
- if (newColumnCount > oldColumnCount) {
8428
- for (let colIdx = oldColumnCount;colIdx < newColumnCount; colIdx++) {
8429
- const cellContent = newRow[colIdx];
8430
- cellRow.push(this.createCell(cellContent));
8431
- refRow.push(cellContent);
8432
- }
8433
- } else if (newColumnCount < oldColumnCount) {
8434
- for (let colIdx = newColumnCount;colIdx < oldColumnCount; colIdx++) {
8435
- const cell = cellRow[colIdx];
8436
- cell.textBufferView.destroy();
8437
- cell.textBuffer.destroy();
8438
- cell.syntaxStyle.destroy();
8439
- }
8440
- cellRow.length = newColumnCount;
8441
- refRow.length = newColumnCount;
8442
- }
8443
- }
8444
- if (newRowCount > oldRowCount) {
8445
- for (let rowIdx = oldRowCount;rowIdx < newRowCount; rowIdx++) {
8446
- const newRow = this._content[rowIdx] ?? [];
8447
- const rowCells = [];
8448
- const rowRefs = [];
8449
- for (let colIdx = 0;colIdx < newColumnCount; colIdx++) {
8450
- const cellContent = newRow[colIdx];
8451
- rowCells.push(this.createCell(cellContent));
8452
- rowRefs.push(cellContent);
8453
- }
8454
- this._cells.push(rowCells);
8455
- this._prevCellContent.push(rowRefs);
8456
- }
8457
- } else if (newRowCount < oldRowCount) {
8458
- for (let rowIdx = newRowCount;rowIdx < oldRowCount; rowIdx++) {
8459
- const row = this._cells[rowIdx];
8460
- for (const cell of row) {
8461
- cell.textBufferView.destroy();
8462
- cell.textBuffer.destroy();
8463
- cell.syntaxStyle.destroy();
8464
- }
8465
- }
8466
- this._cells.length = newRowCount;
8467
- this._prevCellContent.length = newRowCount;
8468
- }
8469
- this._rowCount = newRowCount;
8470
- this._columnCount = newColumnCount;
8471
- }
8472
- createCell(content) {
8473
- const styledText = this.toStyledText(content);
8474
- const textBuffer = TextBuffer.create(this._ctx.widthMethod);
8475
- const syntaxStyle = SyntaxStyle.create();
8476
- textBuffer.setDefaultFg(this._defaultFg);
8477
- textBuffer.setDefaultBg(this._defaultBg);
8478
- textBuffer.setDefaultAttributes(this._defaultAttributes);
8479
- textBuffer.setSyntaxStyle(syntaxStyle);
8480
- textBuffer.setStyledText(styledText);
8481
- const textBufferView = TextBufferView.create(textBuffer);
8482
- textBufferView.setWrapMode(this._wrapMode);
8483
- return { textBuffer, textBufferView, syntaxStyle };
8484
- }
8485
- toStyledText(content) {
8486
- if (Array.isArray(content)) {
8487
- return new StyledText(content);
8488
- }
8489
- if (content === null || content === undefined) {
8490
- return stringToStyledText("");
8491
- }
8492
- return stringToStyledText(String(content));
8493
- }
8494
- destroyCells() {
8495
- for (const row of this._cells) {
8496
- for (const cell of row) {
8497
- cell.textBufferView.destroy();
8498
- cell.textBuffer.destroy();
8499
- cell.syntaxStyle.destroy();
8500
- }
8501
- }
8502
- this._cells = [];
8503
- this._prevCellContent = [];
8504
- this._rowCount = 0;
8505
- this._columnCount = 0;
8506
- this._layout = this.createEmptyLayout();
8507
- }
8508
- rebuildLayoutForCurrentWidth() {
8509
- const maxTableWidth = this.resolveLayoutWidthConstraint(this.width);
8510
- let layout;
8511
- if (this._cachedMeasureLayout !== null && this._cachedMeasureWidth === maxTableWidth) {
8512
- layout = this._cachedMeasureLayout;
8513
- } else {
8514
- layout = this.computeLayout(maxTableWidth);
8515
- }
8516
- this._cachedMeasureLayout = null;
8517
- this._cachedMeasureWidth = undefined;
8518
- this._layout = layout;
8519
- this.applyLayoutToViews(layout);
8520
- this._layoutDirty = false;
8521
- if (this._lastLocalSelection?.isActive) {
8522
- this.applySelectionToCells(this._lastLocalSelection, true);
8523
- }
8524
- }
8525
- computeLayout(maxTableWidth) {
8526
- if (this._rowCount === 0 || this._columnCount === 0) {
8527
- return this.createEmptyLayout();
8528
- }
8529
- const borderLayout = this.resolveBorderLayout();
8530
- const columnWidths = this.computeColumnWidths(maxTableWidth, borderLayout);
8531
- const rowHeights = this.computeRowHeights(columnWidths);
8532
- const columnOffsets = this.computeOffsets(columnWidths, borderLayout.left, borderLayout.right, borderLayout.innerVertical);
8533
- const rowOffsets = this.computeOffsets(rowHeights, borderLayout.top, borderLayout.bottom, borderLayout.innerHorizontal);
8534
- return {
8535
- columnWidths,
8536
- rowHeights,
8537
- columnOffsets,
8538
- rowOffsets,
8539
- columnOffsetsI32: new Int32Array(columnOffsets),
8540
- rowOffsetsI32: new Int32Array(rowOffsets),
8541
- tableWidth: (columnOffsets[columnOffsets.length - 1] ?? 0) + 1,
8542
- tableHeight: (rowOffsets[rowOffsets.length - 1] ?? 0) + 1
8543
- };
8544
- }
8545
- isFullWidthMode() {
8546
- return this._columnWidthMode === "full";
8547
- }
8548
- computeColumnWidths(maxTableWidth, borderLayout) {
8549
- const horizontalPadding = this.getHorizontalCellPadding();
8550
- const intrinsicWidths = new Array(this._columnCount).fill(1 + horizontalPadding);
8551
- for (let rowIdx = 0;rowIdx < this._rowCount; rowIdx++) {
8552
- for (let colIdx = 0;colIdx < this._columnCount; colIdx++) {
8553
- const cell = this._cells[rowIdx]?.[colIdx];
8554
- if (!cell)
8555
- continue;
8556
- const measure = cell.textBufferView.measureForDimensions(0, MEASURE_HEIGHT);
8557
- const measuredWidth = Math.max(1, measure?.widthColsMax ?? 0) + horizontalPadding;
8558
- intrinsicWidths[colIdx] = Math.max(intrinsicWidths[colIdx], measuredWidth);
8559
- }
8560
- }
8561
- if (maxTableWidth === undefined || !Number.isFinite(maxTableWidth) || maxTableWidth <= 0) {
8562
- return intrinsicWidths;
8563
- }
8564
- const maxContentWidth = Math.max(1, Math.floor(maxTableWidth) - this.getVerticalBorderCount(borderLayout));
8565
- const currentWidth = intrinsicWidths.reduce((sum, width) => sum + width, 0);
8566
- if (currentWidth === maxContentWidth) {
8567
- return intrinsicWidths;
8568
- }
8569
- if (currentWidth < maxContentWidth) {
8570
- if (this.isFullWidthMode()) {
8571
- return this.expandColumnWidths(intrinsicWidths, maxContentWidth);
8572
- }
8573
- return intrinsicWidths;
8574
- }
8575
- if (this._wrapMode === "none") {
8576
- return intrinsicWidths;
8577
- }
8578
- return this.fitColumnWidths(intrinsicWidths, maxContentWidth);
8579
- }
8580
- expandColumnWidths(widths, targetContentWidth) {
8581
- const baseWidths = widths.map((width) => Math.max(1, Math.floor(width)));
8582
- const totalBaseWidth = baseWidths.reduce((sum, width) => sum + width, 0);
8583
- if (totalBaseWidth >= targetContentWidth) {
8584
- return baseWidths;
8585
- }
8586
- const expanded = [...baseWidths];
8587
- const columns = expanded.length;
8588
- const extraWidth = targetContentWidth - totalBaseWidth;
8589
- const sharedWidth = Math.floor(extraWidth / columns);
8590
- const remainder = extraWidth % columns;
8591
- for (let idx = 0;idx < columns; idx++) {
8592
- expanded[idx] += sharedWidth;
8593
- if (idx < remainder) {
8594
- expanded[idx] += 1;
8595
- }
8596
- }
8597
- return expanded;
8598
- }
8599
- fitColumnWidths(widths, targetContentWidth) {
8600
- if (this._columnFitter === "balanced") {
8601
- return this.fitColumnWidthsBalanced(widths, targetContentWidth);
8602
- }
8603
- return this.fitColumnWidthsProportional(widths, targetContentWidth);
8604
- }
8605
- fitColumnWidthsProportional(widths, targetContentWidth) {
8606
- const minWidth = 1 + this.getHorizontalCellPadding();
8607
- const hardMinWidths = new Array(widths.length).fill(minWidth);
8608
- const baseWidths = widths.map((width) => Math.max(1, Math.floor(width)));
8609
- const preferredMinWidths = baseWidths.map((width) => Math.min(width, minWidth + 1));
8610
- const preferredMinTotal = preferredMinWidths.reduce((sum, width) => sum + width, 0);
8611
- const floorWidths = preferredMinTotal <= targetContentWidth ? preferredMinWidths : hardMinWidths;
8612
- const floorTotal = floorWidths.reduce((sum, width) => sum + width, 0);
8613
- const clampedTarget = Math.max(floorTotal, targetContentWidth);
8614
- const totalBaseWidth = baseWidths.reduce((sum, width) => sum + width, 0);
8615
- if (totalBaseWidth <= clampedTarget) {
8616
- return baseWidths;
8617
- }
8618
- const shrinkable = baseWidths.map((width, idx) => width - floorWidths[idx]);
8619
- const totalShrinkable = shrinkable.reduce((sum, value) => sum + value, 0);
8620
- if (totalShrinkable <= 0) {
8621
- return [...floorWidths];
8622
- }
8623
- const targetShrink = totalBaseWidth - clampedTarget;
8624
- const integerShrink = new Array(baseWidths.length).fill(0);
8625
- const fractions = new Array(baseWidths.length).fill(0);
8626
- let usedShrink = 0;
8627
- for (let idx = 0;idx < baseWidths.length; idx++) {
8628
- if (shrinkable[idx] <= 0)
8629
- continue;
8630
- const exact = shrinkable[idx] / totalShrinkable * targetShrink;
8631
- const whole = Math.min(shrinkable[idx], Math.floor(exact));
8632
- integerShrink[idx] = whole;
8633
- fractions[idx] = exact - whole;
8634
- usedShrink += whole;
8635
- }
8636
- let remainingShrink = targetShrink - usedShrink;
8637
- while (remainingShrink > 0) {
8638
- let bestIdx = -1;
8639
- let bestFraction = -1;
8640
- for (let idx = 0;idx < baseWidths.length; idx++) {
8641
- if (shrinkable[idx] - integerShrink[idx] <= 0)
8642
- continue;
8643
- if (fractions[idx] > bestFraction) {
8644
- bestFraction = fractions[idx];
8645
- bestIdx = idx;
8646
- }
8647
- }
8648
- if (bestIdx === -1)
8649
- break;
8650
- integerShrink[bestIdx] += 1;
8651
- fractions[bestIdx] = 0;
8652
- remainingShrink -= 1;
8653
- }
8654
- return baseWidths.map((width, idx) => Math.max(floorWidths[idx], width - integerShrink[idx]));
8655
- }
8656
- fitColumnWidthsBalanced(widths, targetContentWidth) {
8657
- const minWidth = 1 + this.getHorizontalCellPadding();
8658
- const hardMinWidths = new Array(widths.length).fill(minWidth);
8659
- const baseWidths = widths.map((width) => Math.max(1, Math.floor(width)));
8660
- const totalBaseWidth = baseWidths.reduce((sum, width) => sum + width, 0);
8661
- const columns = baseWidths.length;
8662
- if (columns === 0 || totalBaseWidth <= targetContentWidth) {
8663
- return baseWidths;
8664
- }
8665
- const evenShare = Math.max(minWidth, Math.floor(targetContentWidth / columns));
8666
- const preferredMinWidths = baseWidths.map((width) => Math.min(width, evenShare));
8667
- const preferredMinTotal = preferredMinWidths.reduce((sum, width) => sum + width, 0);
8668
- const floorWidths = preferredMinTotal <= targetContentWidth ? preferredMinWidths : hardMinWidths;
8669
- const floorTotal = floorWidths.reduce((sum, width) => sum + width, 0);
8670
- const clampedTarget = Math.max(floorTotal, targetContentWidth);
8671
- if (totalBaseWidth <= clampedTarget) {
8672
- return baseWidths;
8673
- }
8674
- const shrinkable = baseWidths.map((width, idx) => width - floorWidths[idx]);
8675
- const totalShrinkable = shrinkable.reduce((sum, value) => sum + value, 0);
8676
- if (totalShrinkable <= 0) {
8677
- return [...floorWidths];
8678
- }
8679
- const targetShrink = totalBaseWidth - clampedTarget;
8680
- const shrink = this.allocateShrinkByWeight(shrinkable, targetShrink, "sqrt");
8681
- return baseWidths.map((width, idx) => Math.max(floorWidths[idx], width - shrink[idx]));
8682
- }
8683
- allocateShrinkByWeight(shrinkable, targetShrink, mode) {
8684
- const shrink = new Array(shrinkable.length).fill(0);
8685
- if (targetShrink <= 0) {
8686
- return shrink;
8687
- }
8688
- const weights = shrinkable.map((value) => {
8689
- if (value <= 0) {
8690
- return 0;
8691
- }
8692
- return mode === "sqrt" ? Math.sqrt(value) : value;
8693
- });
8694
- const totalWeight = weights.reduce((sum, value) => sum + value, 0);
8695
- if (totalWeight <= 0) {
8696
- return shrink;
8697
- }
8698
- const fractions = new Array(shrinkable.length).fill(0);
8699
- let usedShrink = 0;
8700
- for (let idx = 0;idx < shrinkable.length; idx++) {
8701
- if (shrinkable[idx] <= 0 || weights[idx] <= 0)
8702
- continue;
8703
- const exact = weights[idx] / totalWeight * targetShrink;
8704
- const whole = Math.min(shrinkable[idx], Math.floor(exact));
8705
- shrink[idx] = whole;
8706
- fractions[idx] = exact - whole;
8707
- usedShrink += whole;
8708
- }
8709
- let remainingShrink = targetShrink - usedShrink;
8710
- while (remainingShrink > 0) {
8711
- let bestIdx = -1;
8712
- let bestFraction = -1;
8713
- for (let idx = 0;idx < shrinkable.length; idx++) {
8714
- if (shrinkable[idx] - shrink[idx] <= 0)
8715
- continue;
8716
- if (bestIdx === -1 || fractions[idx] > bestFraction || fractions[idx] === bestFraction && shrinkable[idx] > shrinkable[bestIdx]) {
8717
- bestIdx = idx;
8718
- bestFraction = fractions[idx];
8719
- }
8720
- }
8721
- if (bestIdx === -1) {
8722
- break;
8723
- }
8724
- shrink[bestIdx] += 1;
8725
- fractions[bestIdx] = 0;
8726
- remainingShrink -= 1;
8727
- }
8728
- return shrink;
8729
- }
8730
- computeRowHeights(columnWidths) {
8731
- const horizontalPadding = this.getHorizontalCellPadding();
8732
- const verticalPadding = this.getVerticalCellPadding();
8733
- const rowHeights = new Array(this._rowCount).fill(1 + verticalPadding);
8734
- for (let rowIdx = 0;rowIdx < this._rowCount; rowIdx++) {
8735
- for (let colIdx = 0;colIdx < this._columnCount; colIdx++) {
8736
- const cell = this._cells[rowIdx]?.[colIdx];
8737
- if (!cell)
8738
- continue;
8739
- const width = Math.max(1, (columnWidths[colIdx] ?? 1) - horizontalPadding);
8740
- const measure = cell.textBufferView.measureForDimensions(width, MEASURE_HEIGHT);
8741
- const lineCount = Math.max(1, measure?.lineCount ?? 1);
8742
- rowHeights[rowIdx] = Math.max(rowHeights[rowIdx], lineCount + verticalPadding);
8743
- }
8744
- }
8745
- return rowHeights;
8746
- }
8747
- computeOffsets(parts, startBoundary, endBoundary, includeInnerBoundaries) {
8748
- const offsets = [startBoundary ? 0 : -1];
8749
- let cursor = offsets[0] ?? 0;
8750
- for (let idx = 0;idx < parts.length; idx++) {
8751
- const size = parts[idx] ?? 1;
8752
- const hasBoundaryAfter = idx < parts.length - 1 ? includeInnerBoundaries : endBoundary;
8753
- cursor += size + (hasBoundaryAfter ? 1 : 0);
8754
- offsets.push(cursor);
8755
- }
8756
- return offsets;
8757
- }
8758
- applyLayoutToViews(layout) {
8759
- const horizontalPadding = this.getHorizontalCellPadding();
8760
- const verticalPadding = this.getVerticalCellPadding();
8761
- for (let rowIdx = 0;rowIdx < this._rowCount; rowIdx++) {
8762
- for (let colIdx = 0;colIdx < this._columnCount; colIdx++) {
8763
- const cell = this._cells[rowIdx]?.[colIdx];
8764
- if (!cell)
8765
- continue;
8766
- const colWidth = layout.columnWidths[colIdx] ?? 1;
8767
- const rowHeight = layout.rowHeights[rowIdx] ?? 1;
8768
- const contentWidth = Math.max(1, colWidth - horizontalPadding);
8769
- const contentHeight = Math.max(1, rowHeight - verticalPadding);
8770
- if (this._wrapMode === "none") {
8771
- cell.textBufferView.setWrapWidth(null);
8772
- } else {
8773
- cell.textBufferView.setWrapWidth(contentWidth);
8774
- }
8775
- cell.textBufferView.setViewport(0, 0, contentWidth, contentHeight);
8776
- }
8777
- }
8778
- }
8779
- resolveBorderLayout() {
8780
- return {
8781
- left: this._outerBorder,
8782
- right: this._outerBorder,
8783
- top: this._outerBorder,
8784
- bottom: this._outerBorder,
8785
- innerVertical: this._border && this._columnCount > 1,
8786
- innerHorizontal: this._border && this._rowCount > 1
8787
- };
8788
- }
8789
- getVerticalBorderCount(borderLayout) {
8790
- return (borderLayout.left ? 1 : 0) + (borderLayout.right ? 1 : 0) + (borderLayout.innerVertical ? Math.max(0, this._columnCount - 1) : 0);
8791
- }
8792
- getHorizontalBorderCount(borderLayout) {
8793
- return (borderLayout.top ? 1 : 0) + (borderLayout.bottom ? 1 : 0) + (borderLayout.innerHorizontal ? Math.max(0, this._rowCount - 1) : 0);
8794
- }
8795
- drawBorders(buffer) {
8796
- if (!this._showBorders) {
8797
- return;
8798
- }
8799
- const borderLayout = this.resolveBorderLayout();
8800
- if (this.getVerticalBorderCount(borderLayout) === 0 && this.getHorizontalBorderCount(borderLayout) === 0) {
8801
- return;
8802
- }
8803
- buffer.drawGrid({
8804
- borderChars: BorderCharArrays[this._borderStyle],
8805
- borderFg: this._borderColor,
8806
- borderBg: this._borderBackgroundColor,
8807
- columnOffsets: this._layout.columnOffsetsI32,
8808
- rowOffsets: this._layout.rowOffsetsI32,
8809
- drawInner: this._border,
8810
- drawOuter: this._outerBorder
8811
- });
8812
- }
8813
- drawCells(buffer) {
8814
- this.drawCellRange(buffer, 0, this._rowCount - 1);
8815
- }
8816
- drawCellRange(buffer, firstRow, lastRow) {
8817
- const colOffsets = this._layout.columnOffsets;
8818
- const rowOffsets = this._layout.rowOffsets;
8819
- const cellPadding = this._cellPadding;
8820
- for (let rowIdx = firstRow;rowIdx <= lastRow; rowIdx++) {
8821
- const cellY = (rowOffsets[rowIdx] ?? 0) + 1 + cellPadding;
8822
- for (let colIdx = 0;colIdx < this._columnCount; colIdx++) {
8823
- const cell = this._cells[rowIdx]?.[colIdx];
8824
- if (!cell)
8825
- continue;
8826
- buffer.drawTextBuffer(cell.textBufferView, (colOffsets[colIdx] ?? 0) + 1 + cellPadding, cellY);
8827
- }
8828
- }
8829
- }
8830
- redrawSelectionRows(firstRow, lastRow) {
8831
- if (firstRow > lastRow)
8832
- return;
8833
- if (this._backgroundColor.a < 1) {
8834
- this.invalidateRasterOnly();
8835
- return;
8836
- }
8837
- const buffer = this.frameBuffer;
8838
- if (!buffer)
8839
- return;
8840
- this.clearCellRange(buffer, firstRow, lastRow);
8841
- this.drawCellRange(buffer, firstRow, lastRow);
8842
- this.requestRender();
8843
- }
8844
- clearCellRange(buffer, firstRow, lastRow) {
8845
- const colWidths = this._layout.columnWidths;
8846
- const rowHeights = this._layout.rowHeights;
8847
- const colOffsets = this._layout.columnOffsets;
8848
- const rowOffsets = this._layout.rowOffsets;
8849
- for (let rowIdx = firstRow;rowIdx <= lastRow; rowIdx++) {
8850
- const cellY = (rowOffsets[rowIdx] ?? 0) + 1;
8851
- const rowHeight = rowHeights[rowIdx] ?? 1;
8852
- for (let colIdx = 0;colIdx < this._columnCount; colIdx++) {
8853
- const cellX = (colOffsets[colIdx] ?? 0) + 1;
8854
- const colWidth = colWidths[colIdx] ?? 1;
8855
- buffer.fillRect(cellX, cellY, colWidth, rowHeight, this._backgroundColor);
8856
- }
8857
- }
8858
- }
8859
- ensureLayoutReady() {
8860
- if (!this._layoutDirty)
8861
- return;
8862
- this.rebuildLayoutForCurrentWidth();
8863
- }
8864
- getCellAtLocalPosition(localX, localY) {
8865
- if (this._rowCount === 0 || this._columnCount === 0)
8866
- return null;
8867
- if (localX < 0 || localY < 0 || localX >= this._layout.tableWidth || localY >= this._layout.tableHeight) {
8868
- return null;
8869
- }
8870
- let rowIdx = -1;
8871
- for (let idx = 0;idx < this._rowCount; idx++) {
8872
- const top = (this._layout.rowOffsets[idx] ?? 0) + 1;
8873
- const bottom = top + (this._layout.rowHeights[idx] ?? 1) - 1;
8874
- if (localY >= top && localY <= bottom) {
8875
- rowIdx = idx;
8876
- break;
8877
- }
8878
- }
8879
- if (rowIdx < 0)
8880
- return null;
8881
- let colIdx = -1;
8882
- for (let idx = 0;idx < this._columnCount; idx++) {
8883
- const left = (this._layout.columnOffsets[idx] ?? 0) + 1;
8884
- const right = left + (this._layout.columnWidths[idx] ?? 1) - 1;
8885
- if (localX >= left && localX <= right) {
8886
- colIdx = idx;
8887
- break;
8888
- }
8889
- }
8890
- if (colIdx < 0)
8891
- return null;
8892
- return { rowIdx, colIdx };
8893
- }
8894
- applySelectionToCells(localSelection, isStart) {
8895
- const minSelY = Math.min(localSelection.anchorY, localSelection.focusY);
8896
- const maxSelY = Math.max(localSelection.anchorY, localSelection.focusY);
8897
- const firstRow = this.findRowForLocalY(minSelY);
8898
- const lastRow = this.findRowForLocalY(maxSelY);
8899
- const selection = this.resolveSelectionResolution(localSelection);
8900
- const modeChanged = this._lastSelectionMode !== selection.mode;
8901
- this._lastSelectionMode = selection.mode;
8902
- const lockToAnchorColumn = selection.mode === "column-locked" && selection.anchorColumn !== null;
8903
- for (let rowIdx = 0;rowIdx < this._rowCount; rowIdx++) {
8904
- if (rowIdx < firstRow || rowIdx > lastRow) {
8905
- this.resetRowSelection(rowIdx);
8906
- continue;
8907
- }
8908
- const cellTop = (this._layout.rowOffsets[rowIdx] ?? 0) + 1 + this._cellPadding;
8909
- for (let colIdx = 0;colIdx < this._columnCount; colIdx++) {
8910
- const cell = this._cells[rowIdx]?.[colIdx];
8911
- if (!cell)
8912
- continue;
8913
- if (lockToAnchorColumn && colIdx !== selection.anchorColumn) {
8914
- cell.textBufferView.resetLocalSelection();
8915
- continue;
8916
- }
8917
- const cellLeft = (this._layout.columnOffsets[colIdx] ?? 0) + 1 + this._cellPadding;
8918
- let coords = {
8919
- anchorX: localSelection.anchorX - cellLeft,
8920
- anchorY: localSelection.anchorY - cellTop,
8921
- focusX: localSelection.focusX - cellLeft,
8922
- focusY: localSelection.focusY - cellTop
8923
- };
8924
- const isAnchorCell = selection.anchorCell !== null && selection.anchorCell.rowIdx === rowIdx && selection.anchorCell.colIdx === colIdx;
8925
- const forceSet = isAnchorCell && selection.mode !== "single-cell";
8926
- if (forceSet) {
8927
- coords = this.getFullCellSelectionCoords(rowIdx, colIdx);
8928
- }
8929
- const shouldUseSet = isStart || modeChanged || forceSet;
8930
- if (shouldUseSet) {
8931
- cell.textBufferView.setLocalSelection(coords.anchorX, coords.anchorY, coords.focusX, coords.focusY, this._selectionBg, this._selectionFg);
8932
- } else {
8933
- cell.textBufferView.updateLocalSelection(coords.anchorX, coords.anchorY, coords.focusX, coords.focusY, this._selectionBg, this._selectionFg);
8934
- }
8935
- }
8936
- }
8937
- }
8938
- resolveSelectionResolution(localSelection) {
8939
- const anchorCell = this.getCellAtLocalPosition(localSelection.anchorX, localSelection.anchorY);
8940
- const focusCell = this.getCellAtLocalPosition(localSelection.focusX, localSelection.focusY);
8941
- const anchorColumn = anchorCell?.colIdx ?? this.getColumnAtLocalX(localSelection.anchorX);
8942
- if (anchorCell !== null && focusCell !== null && anchorCell.rowIdx === focusCell.rowIdx && anchorCell.colIdx === focusCell.colIdx) {
8943
- return {
8944
- mode: "single-cell",
8945
- anchorCell,
8946
- anchorColumn
8947
- };
8948
- }
8949
- const focusColumn = this.getColumnAtLocalX(localSelection.focusX);
8950
- if (anchorColumn !== null && focusColumn === anchorColumn) {
8951
- return {
8952
- mode: "column-locked",
8953
- anchorCell,
8954
- anchorColumn
8955
- };
8956
- }
8957
- return {
8958
- mode: "grid",
8959
- anchorCell,
8960
- anchorColumn
8961
- };
8962
- }
8963
- getColumnAtLocalX(localX) {
8964
- if (this._columnCount === 0)
8965
- return null;
8966
- if (localX < 0 || localX >= this._layout.tableWidth)
8967
- return null;
8968
- for (let colIdx = 0;colIdx < this._columnCount; colIdx++) {
8969
- const colStart = (this._layout.columnOffsets[colIdx] ?? 0) + 1;
8970
- const colEnd = colStart + (this._layout.columnWidths[colIdx] ?? 1) - 1;
8971
- if (localX >= colStart && localX <= colEnd) {
8972
- return colIdx;
8973
- }
8974
- }
8975
- return null;
8976
- }
8977
- getFullCellSelectionCoords(rowIdx, colIdx) {
8978
- const colWidth = this._layout.columnWidths[colIdx] ?? 1;
8979
- const rowHeight = this._layout.rowHeights[rowIdx] ?? 1;
8980
- const contentWidth = Math.max(1, colWidth - this.getHorizontalCellPadding());
8981
- const contentHeight = Math.max(1, rowHeight - this.getVerticalCellPadding());
8982
- return {
8983
- anchorX: -1,
8984
- anchorY: 0,
8985
- focusX: contentWidth,
8986
- focusY: contentHeight
8987
- };
8988
- }
8989
- findRowForLocalY(localY) {
8990
- if (this._rowCount === 0)
8991
- return 0;
8992
- if (localY < 0)
8993
- return 0;
8994
- for (let rowIdx = 0;rowIdx < this._rowCount; rowIdx++) {
8995
- const rowStart = (this._layout.rowOffsets[rowIdx] ?? 0) + 1;
8996
- const rowEnd = rowStart + (this._layout.rowHeights[rowIdx] ?? 1) - 1;
8997
- if (localY <= rowEnd)
8998
- return rowIdx;
8999
- }
9000
- return this._rowCount - 1;
9001
- }
9002
- getSelectionRowRange(selection) {
9003
- if (!selection?.isActive || this._rowCount === 0)
9004
- return null;
9005
- const minSelY = Math.min(selection.anchorY, selection.focusY);
9006
- const maxSelY = Math.max(selection.anchorY, selection.focusY);
9007
- return {
9008
- firstRow: this.findRowForLocalY(minSelY),
9009
- lastRow: this.findRowForLocalY(maxSelY)
9010
- };
9011
- }
9012
- getDirtySelectionRowRange(previousSelection, currentSelection) {
9013
- const previousRange = this.getSelectionRowRange(previousSelection);
9014
- const currentRange = this.getSelectionRowRange(currentSelection);
9015
- if (previousRange === null)
9016
- return currentRange;
9017
- if (currentRange === null)
9018
- return previousRange;
9019
- return {
9020
- firstRow: Math.min(previousRange.firstRow, currentRange.firstRow),
9021
- lastRow: Math.max(previousRange.lastRow, currentRange.lastRow)
9022
- };
9023
- }
9024
- resetRowSelection(rowIdx) {
9025
- const row = this._cells[rowIdx];
9026
- if (!row)
9027
- return;
9028
- for (const cell of row) {
9029
- cell.textBufferView.resetLocalSelection();
9030
- }
9031
- }
9032
- resetCellSelections() {
9033
- for (let rowIdx = 0;rowIdx < this._rowCount; rowIdx++) {
9034
- this.resetRowSelection(rowIdx);
9035
- }
9036
- }
9037
- createEmptyLayout() {
9038
- return {
9039
- columnWidths: [],
9040
- rowHeights: [],
9041
- columnOffsets: [0],
9042
- rowOffsets: [0],
9043
- columnOffsetsI32: new Int32Array([0]),
9044
- rowOffsetsI32: new Int32Array([0]),
9045
- tableWidth: 0,
9046
- tableHeight: 0
9047
- };
9048
- }
9049
- resolveLayoutWidthConstraint(width) {
9050
- if (width === undefined || !Number.isFinite(width) || width <= 0) {
9051
- return;
9052
- }
9053
- if (this._wrapMode !== "none" || this.isFullWidthMode()) {
9054
- return Math.max(1, Math.floor(width));
9055
- }
9056
- return;
9057
- }
9058
- getHorizontalCellPadding() {
9059
- return this._cellPadding * 2;
9060
- }
9061
- getVerticalCellPadding() {
9062
- return this._cellPadding * 2;
9063
- }
9064
- resolveColumnFitter(value) {
9065
- if (value === undefined) {
9066
- return this._defaultOptions.columnFitter;
9067
- }
9068
- return value === "balanced" ? "balanced" : "proportional";
9069
- }
9070
- resolveCellPadding(value) {
9071
- if (value === undefined || !Number.isFinite(value)) {
9072
- return this._defaultOptions.cellPadding;
9073
- }
9074
- return Math.max(0, Math.floor(value));
9075
- }
9076
- invalidateLayoutAndRaster(markYogaDirty = true) {
9077
- this._layoutDirty = true;
9078
- this._rasterDirty = true;
9079
- this._cachedMeasureLayout = null;
9080
- this._cachedMeasureWidth = undefined;
9081
- if (markYogaDirty) {
9082
- this.yogaNode.markDirty();
9083
- }
9084
- this.requestRender();
9085
- }
9086
- invalidateRasterOnly() {
9087
- this._rasterDirty = true;
9088
- this.requestRender();
9089
- }
9090
- }
9091
-
9092
8092
  // ../../node_modules/.bun/marked@17.0.1/node_modules/marked/lib/marked.esm.js
9093
8093
  function L() {
9094
8094
  return { async: false, breaks: false, extensions: null, gfm: true, hooks: null, pedantic: false, renderer: null, silent: false, tokenizer: null, walkTokens: null };
@@ -9221,1138 +8221,2138 @@ function z(u, e, t2) {
9221
8221
  else
9222
8222
  break;
9223
8223
  }
9224
- return u.slice(0, n - r);
9225
- }
9226
- function de(u, e) {
9227
- if (u.indexOf(e[1]) === -1)
9228
- return -1;
9229
- let t2 = 0;
9230
- for (let n = 0;n < u.length; n++)
9231
- if (u[n] === "\\")
9232
- n++;
9233
- else if (u[n] === e[0])
9234
- t2++;
9235
- else if (u[n] === e[1] && (t2--, t2 < 0))
9236
- return n;
9237
- return t2 > 0 ? -2 : -1;
9238
- }
9239
- function ge(u, e, t2, n, r) {
9240
- let i = e.href, s = e.title || null, a = u[1].replace(r.other.outputLinkReplace, "$1");
9241
- n.state.inLink = true;
9242
- let o = { type: u[0].charAt(0) === "!" ? "image" : "link", raw: t2, href: i, title: s, text: a, tokens: n.inlineTokens(a) };
9243
- return n.state.inLink = false, o;
9244
- }
9245
- function Je(u, e, t2) {
9246
- let n = u.match(t2.other.indentCodeCompensation);
9247
- if (n === null)
9248
- return e;
9249
- let r = n[1];
9250
- return e.split(`
9251
- `).map((i) => {
9252
- let s = i.match(t2.other.beginningSpace);
9253
- if (s === null)
9254
- return i;
9255
- let [a] = s;
9256
- return a.length >= r.length ? i.slice(r.length) : i;
9257
- }).join(`
9258
- `);
9259
- }
9260
- var y = class {
9261
- options;
9262
- rules;
9263
- lexer;
9264
- constructor(e) {
9265
- this.options = e || T;
8224
+ return u.slice(0, n - r);
8225
+ }
8226
+ function de(u, e) {
8227
+ if (u.indexOf(e[1]) === -1)
8228
+ return -1;
8229
+ let t2 = 0;
8230
+ for (let n = 0;n < u.length; n++)
8231
+ if (u[n] === "\\")
8232
+ n++;
8233
+ else if (u[n] === e[0])
8234
+ t2++;
8235
+ else if (u[n] === e[1] && (t2--, t2 < 0))
8236
+ return n;
8237
+ return t2 > 0 ? -2 : -1;
8238
+ }
8239
+ function ge(u, e, t2, n, r) {
8240
+ let i = e.href, s = e.title || null, a = u[1].replace(r.other.outputLinkReplace, "$1");
8241
+ n.state.inLink = true;
8242
+ let o = { type: u[0].charAt(0) === "!" ? "image" : "link", raw: t2, href: i, title: s, text: a, tokens: n.inlineTokens(a) };
8243
+ return n.state.inLink = false, o;
8244
+ }
8245
+ function Je(u, e, t2) {
8246
+ let n = u.match(t2.other.indentCodeCompensation);
8247
+ if (n === null)
8248
+ return e;
8249
+ let r = n[1];
8250
+ return e.split(`
8251
+ `).map((i) => {
8252
+ let s = i.match(t2.other.beginningSpace);
8253
+ if (s === null)
8254
+ return i;
8255
+ let [a] = s;
8256
+ return a.length >= r.length ? i.slice(r.length) : i;
8257
+ }).join(`
8258
+ `);
8259
+ }
8260
+ var y = class {
8261
+ options;
8262
+ rules;
8263
+ lexer;
8264
+ constructor(e) {
8265
+ this.options = e || T;
8266
+ }
8267
+ space(e) {
8268
+ let t2 = this.rules.block.newline.exec(e);
8269
+ if (t2 && t2[0].length > 0)
8270
+ return { type: "space", raw: t2[0] };
8271
+ }
8272
+ code(e) {
8273
+ let t2 = this.rules.block.code.exec(e);
8274
+ if (t2) {
8275
+ let n = t2[0].replace(this.rules.other.codeRemoveIndent, "");
8276
+ return { type: "code", raw: t2[0], codeBlockStyle: "indented", text: this.options.pedantic ? n : z(n, `
8277
+ `) };
8278
+ }
8279
+ }
8280
+ fences(e) {
8281
+ let t2 = this.rules.block.fences.exec(e);
8282
+ if (t2) {
8283
+ let n = t2[0], r = Je(n, t2[3] || "", this.rules);
8284
+ return { type: "code", raw: n, lang: t2[2] ? t2[2].trim().replace(this.rules.inline.anyPunctuation, "$1") : t2[2], text: r };
8285
+ }
8286
+ }
8287
+ heading(e) {
8288
+ let t2 = this.rules.block.heading.exec(e);
8289
+ if (t2) {
8290
+ let n = t2[2].trim();
8291
+ if (this.rules.other.endingHash.test(n)) {
8292
+ let r = z(n, "#");
8293
+ (this.options.pedantic || !r || this.rules.other.endingSpaceChar.test(r)) && (n = r.trim());
8294
+ }
8295
+ return { type: "heading", raw: t2[0], depth: t2[1].length, text: n, tokens: this.lexer.inline(n) };
8296
+ }
8297
+ }
8298
+ hr(e) {
8299
+ let t2 = this.rules.block.hr.exec(e);
8300
+ if (t2)
8301
+ return { type: "hr", raw: z(t2[0], `
8302
+ `) };
8303
+ }
8304
+ blockquote(e) {
8305
+ let t2 = this.rules.block.blockquote.exec(e);
8306
+ if (t2) {
8307
+ let n = z(t2[0], `
8308
+ `).split(`
8309
+ `), r = "", i = "", s = [];
8310
+ for (;n.length > 0; ) {
8311
+ let a = false, o = [], l;
8312
+ for (l = 0;l < n.length; l++)
8313
+ if (this.rules.other.blockquoteStart.test(n[l]))
8314
+ o.push(n[l]), a = true;
8315
+ else if (!a)
8316
+ o.push(n[l]);
8317
+ else
8318
+ break;
8319
+ n = n.slice(l);
8320
+ let p = o.join(`
8321
+ `), c = p.replace(this.rules.other.blockquoteSetextReplace, `
8322
+ $1`).replace(this.rules.other.blockquoteSetextReplace2, "");
8323
+ r = r ? `${r}
8324
+ ${p}` : p, i = i ? `${i}
8325
+ ${c}` : c;
8326
+ let g = this.lexer.state.top;
8327
+ if (this.lexer.state.top = true, this.lexer.blockTokens(c, s, true), this.lexer.state.top = g, n.length === 0)
8328
+ break;
8329
+ let h2 = s.at(-1);
8330
+ if (h2?.type === "code")
8331
+ break;
8332
+ if (h2?.type === "blockquote") {
8333
+ let R = h2, f = R.raw + `
8334
+ ` + n.join(`
8335
+ `), O = this.blockquote(f);
8336
+ 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;
8337
+ break;
8338
+ } else if (h2?.type === "list") {
8339
+ let R = h2, f = R.raw + `
8340
+ ` + n.join(`
8341
+ `), O = this.list(f);
8342
+ 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(`
8343
+ `);
8344
+ continue;
8345
+ }
8346
+ }
8347
+ return { type: "blockquote", raw: r, tokens: s, text: i };
8348
+ }
8349
+ }
8350
+ list(e) {
8351
+ let t2 = this.rules.block.list.exec(e);
8352
+ if (t2) {
8353
+ let n = t2[1].trim(), r = n.length > 1, i = { type: "list", raw: "", ordered: r, start: r ? +n.slice(0, -1) : "", loose: false, items: [] };
8354
+ n = r ? `\\d{1,9}\\${n.slice(-1)}` : `\\${n}`, this.options.pedantic && (n = r ? n : "[*+-]");
8355
+ let s = this.rules.other.listItemRegex(n), a = false;
8356
+ for (;e; ) {
8357
+ let l = false, p = "", c = "";
8358
+ if (!(t2 = s.exec(e)) || this.rules.block.hr.test(e))
8359
+ break;
8360
+ p = t2[0], e = e.substring(p.length);
8361
+ let g = t2[2].split(`
8362
+ `, 1)[0].replace(this.rules.other.listReplaceTabs, (O) => " ".repeat(3 * O.length)), h2 = e.split(`
8363
+ `, 1)[0], R = !g.trim(), f = 0;
8364
+ 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 + `
8365
+ `, e = e.substring(h2.length + 1), l = true), !l) {
8366
+ 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);
8367
+ for (;e; ) {
8368
+ let H = e.split(`
8369
+ `, 1)[0], A;
8370
+ 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))
8371
+ break;
8372
+ if (A.search(this.rules.other.nonSpaceChar) >= f || !h2.trim())
8373
+ c += `
8374
+ ` + A.slice(f);
8375
+ else {
8376
+ if (R || g.replace(this.rules.other.tabCharGlobal, " ").search(this.rules.other.nonSpaceChar) >= 4 || Y.test(g) || ee.test(g) || V.test(g))
8377
+ break;
8378
+ c += `
8379
+ ` + h2;
8380
+ }
8381
+ !R && !h2.trim() && (R = true), p += H + `
8382
+ `, e = e.substring(H.length + 1), g = A.slice(f);
8383
+ }
8384
+ }
8385
+ 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;
8386
+ }
8387
+ let o = i.items.at(-1);
8388
+ if (o)
8389
+ o.raw = o.raw.trimEnd(), o.text = o.text.trimEnd();
8390
+ else
8391
+ return;
8392
+ i.raw = i.raw.trimEnd();
8393
+ for (let l of i.items) {
8394
+ if (this.lexer.state.top = false, l.tokens = this.lexer.blockTokens(l.text, []), l.task) {
8395
+ if (l.text = l.text.replace(this.rules.other.listReplaceTask, ""), l.tokens[0]?.type === "text" || l.tokens[0]?.type === "paragraph") {
8396
+ 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, "");
8397
+ for (let c = this.lexer.inlineQueue.length - 1;c >= 0; c--)
8398
+ if (this.rules.other.listIsTask.test(this.lexer.inlineQueue[c].src)) {
8399
+ this.lexer.inlineQueue[c].src = this.lexer.inlineQueue[c].src.replace(this.rules.other.listReplaceTask, "");
8400
+ break;
8401
+ }
8402
+ }
8403
+ let p = this.rules.other.listTaskCheckbox.exec(l.raw);
8404
+ if (p) {
8405
+ let c = { type: "checkbox", raw: p[0] + " ", checked: p[0] !== "[ ]" };
8406
+ 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);
8407
+ }
8408
+ }
8409
+ if (!i.loose) {
8410
+ let p = l.tokens.filter((g) => g.type === "space"), c = p.length > 0 && p.some((g) => this.rules.other.anyLine.test(g.raw));
8411
+ i.loose = c;
8412
+ }
8413
+ }
8414
+ if (i.loose)
8415
+ for (let l of i.items) {
8416
+ l.loose = true;
8417
+ for (let p of l.tokens)
8418
+ p.type === "text" && (p.type = "paragraph");
8419
+ }
8420
+ return i;
8421
+ }
8422
+ }
8423
+ html(e) {
8424
+ let t2 = this.rules.block.html.exec(e);
8425
+ if (t2)
8426
+ return { type: "html", block: true, raw: t2[0], pre: t2[1] === "pre" || t2[1] === "script" || t2[1] === "style", text: t2[0] };
8427
+ }
8428
+ def(e) {
8429
+ let t2 = this.rules.block.def.exec(e);
8430
+ if (t2) {
8431
+ 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];
8432
+ return { type: "def", tag: n, raw: t2[0], href: r, title: i };
8433
+ }
8434
+ }
8435
+ table(e) {
8436
+ let t2 = this.rules.block.table.exec(e);
8437
+ if (!t2 || !this.rules.other.tableDelimiter.test(t2[2]))
8438
+ return;
8439
+ 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(`
8440
+ `) : [], s = { type: "table", raw: t2[0], header: [], align: [], rows: [] };
8441
+ if (n.length === r.length) {
8442
+ for (let a of r)
8443
+ 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);
8444
+ for (let a = 0;a < n.length; a++)
8445
+ s.header.push({ text: n[a], tokens: this.lexer.inline(n[a]), header: true, align: s.align[a] });
8446
+ for (let a of i)
8447
+ s.rows.push(J(a, s.header.length).map((o, l) => ({ text: o, tokens: this.lexer.inline(o), header: false, align: s.align[l] })));
8448
+ return s;
8449
+ }
8450
+ }
8451
+ lheading(e) {
8452
+ let t2 = this.rules.block.lheading.exec(e);
8453
+ if (t2)
8454
+ return { type: "heading", raw: t2[0], depth: t2[2].charAt(0) === "=" ? 1 : 2, text: t2[1], tokens: this.lexer.inline(t2[1]) };
8455
+ }
8456
+ paragraph(e) {
8457
+ let t2 = this.rules.block.paragraph.exec(e);
8458
+ if (t2) {
8459
+ let n = t2[1].charAt(t2[1].length - 1) === `
8460
+ ` ? t2[1].slice(0, -1) : t2[1];
8461
+ return { type: "paragraph", raw: t2[0], text: n, tokens: this.lexer.inline(n) };
8462
+ }
8463
+ }
8464
+ text(e) {
8465
+ let t2 = this.rules.block.text.exec(e);
8466
+ if (t2)
8467
+ return { type: "text", raw: t2[0], text: t2[0], tokens: this.lexer.inline(t2[0]) };
8468
+ }
8469
+ escape(e) {
8470
+ let t2 = this.rules.inline.escape.exec(e);
8471
+ if (t2)
8472
+ return { type: "escape", raw: t2[0], text: t2[1] };
8473
+ }
8474
+ tag(e) {
8475
+ let t2 = this.rules.inline.tag.exec(e);
8476
+ if (t2)
8477
+ 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] };
8478
+ }
8479
+ link(e) {
8480
+ let t2 = this.rules.inline.link.exec(e);
8481
+ if (t2) {
8482
+ let n = t2[2].trim();
8483
+ if (!this.options.pedantic && this.rules.other.startAngleBracket.test(n)) {
8484
+ if (!this.rules.other.endAngleBracket.test(n))
8485
+ return;
8486
+ let s = z(n.slice(0, -1), "\\");
8487
+ if ((n.length - s.length) % 2 === 0)
8488
+ return;
8489
+ } else {
8490
+ let s = de(t2[2], "()");
8491
+ if (s === -2)
8492
+ return;
8493
+ if (s > -1) {
8494
+ let o = (t2[0].indexOf("!") === 0 ? 5 : 4) + t2[1].length + s;
8495
+ t2[2] = t2[2].substring(0, s), t2[0] = t2[0].substring(0, o).trim(), t2[3] = "";
8496
+ }
8497
+ }
8498
+ let r = t2[2], i = "";
8499
+ if (this.options.pedantic) {
8500
+ let s = this.rules.other.pedanticHrefTitle.exec(r);
8501
+ s && (r = s[1], i = s[3]);
8502
+ } else
8503
+ i = t2[3] ? t2[3].slice(1, -1) : "";
8504
+ 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);
8505
+ }
9266
8506
  }
9267
- space(e) {
9268
- let t2 = this.rules.block.newline.exec(e);
9269
- if (t2 && t2[0].length > 0)
9270
- return { type: "space", raw: t2[0] };
8507
+ reflink(e, t2) {
8508
+ let n;
8509
+ if ((n = this.rules.inline.reflink.exec(e)) || (n = this.rules.inline.nolink.exec(e))) {
8510
+ let r = (n[2] || n[1]).replace(this.rules.other.multipleSpaceGlobal, " "), i = t2[r.toLowerCase()];
8511
+ if (!i) {
8512
+ let s = n[0].charAt(0);
8513
+ return { type: "text", raw: s, text: s };
8514
+ }
8515
+ return ge(n, i, n[0], this.lexer, this.rules);
8516
+ }
9271
8517
  }
9272
- code(e) {
9273
- let t2 = this.rules.block.code.exec(e);
8518
+ emStrong(e, t2, n = "") {
8519
+ let r = this.rules.inline.emStrongLDelim.exec(e);
8520
+ if (!r || r[3] && n.match(this.rules.other.unicodeAlphaNumeric))
8521
+ return;
8522
+ if (!(r[1] || r[2] || "") || !n || this.rules.inline.punctuation.exec(n)) {
8523
+ let s = [...r[0]].length - 1, a, o, l = s, p = 0, c = r[0][0] === "*" ? this.rules.inline.emStrongRDelimAst : this.rules.inline.emStrongRDelimUnd;
8524
+ for (c.lastIndex = 0, t2 = t2.slice(-1 * e.length + s);(r = c.exec(t2)) != null; ) {
8525
+ if (a = r[1] || r[2] || r[3] || r[4] || r[5] || r[6], !a)
8526
+ continue;
8527
+ if (o = [...a].length, r[3] || r[4]) {
8528
+ l += o;
8529
+ continue;
8530
+ } else if ((r[5] || r[6]) && s % 3 && !((s + o) % 3)) {
8531
+ p += o;
8532
+ continue;
8533
+ }
8534
+ if (l -= o, l > 0)
8535
+ continue;
8536
+ o = Math.min(o, o + l + p);
8537
+ let g = [...r[0]][0].length, h2 = e.slice(0, s + r.index + g + o);
8538
+ if (Math.min(s, o) % 2) {
8539
+ let f = h2.slice(1, -1);
8540
+ return { type: "em", raw: h2, text: f, tokens: this.lexer.inlineTokens(f) };
8541
+ }
8542
+ let R = h2.slice(2, -2);
8543
+ return { type: "strong", raw: h2, text: R, tokens: this.lexer.inlineTokens(R) };
8544
+ }
8545
+ }
8546
+ }
8547
+ codespan(e) {
8548
+ let t2 = this.rules.inline.code.exec(e);
9274
8549
  if (t2) {
9275
- let n = t2[0].replace(this.rules.other.codeRemoveIndent, "");
9276
- return { type: "code", raw: t2[0], codeBlockStyle: "indented", text: this.options.pedantic ? n : z(n, `
9277
- `) };
8550
+ 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);
8551
+ return r && i && (n = n.substring(1, n.length - 1)), { type: "codespan", raw: t2[0], text: n };
9278
8552
  }
9279
8553
  }
9280
- fences(e) {
9281
- let t2 = this.rules.block.fences.exec(e);
8554
+ br(e) {
8555
+ let t2 = this.rules.inline.br.exec(e);
8556
+ if (t2)
8557
+ return { type: "br", raw: t2[0] };
8558
+ }
8559
+ del(e) {
8560
+ let t2 = this.rules.inline.del.exec(e);
8561
+ if (t2)
8562
+ return { type: "del", raw: t2[0], text: t2[2], tokens: this.lexer.inlineTokens(t2[2]) };
8563
+ }
8564
+ autolink(e) {
8565
+ let t2 = this.rules.inline.autolink.exec(e);
9282
8566
  if (t2) {
9283
- let n = t2[0], r = Je(n, t2[3] || "", this.rules);
9284
- return { type: "code", raw: n, lang: t2[2] ? t2[2].trim().replace(this.rules.inline.anyPunctuation, "$1") : t2[2], text: r };
8567
+ let n, r;
8568
+ 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 }] };
9285
8569
  }
9286
8570
  }
9287
- heading(e) {
9288
- let t2 = this.rules.block.heading.exec(e);
8571
+ url(e) {
8572
+ let t2;
8573
+ if (t2 = this.rules.inline.url.exec(e)) {
8574
+ let n, r;
8575
+ if (t2[2] === "@")
8576
+ n = t2[0], r = "mailto:" + n;
8577
+ else {
8578
+ let i;
8579
+ do
8580
+ i = t2[0], t2[0] = this.rules.inline._backpedal.exec(t2[0])?.[0] ?? "";
8581
+ while (i !== t2[0]);
8582
+ n = t2[0], t2[1] === "www." ? r = "http://" + t2[0] : r = t2[0];
8583
+ }
8584
+ return { type: "link", raw: t2[0], text: n, href: r, tokens: [{ type: "text", raw: n, text: n }] };
8585
+ }
8586
+ }
8587
+ inlineText(e) {
8588
+ let t2 = this.rules.inline.text.exec(e);
9289
8589
  if (t2) {
9290
- let n = t2[2].trim();
9291
- if (this.rules.other.endingHash.test(n)) {
9292
- let r = z(n, "#");
9293
- (this.options.pedantic || !r || this.rules.other.endingSpaceChar.test(r)) && (n = r.trim());
8590
+ let n = this.lexer.state.inRawBlock;
8591
+ return { type: "text", raw: t2[0], text: t2[0], escaped: n };
8592
+ }
8593
+ }
8594
+ };
8595
+ var x = class u {
8596
+ tokens;
8597
+ options;
8598
+ state;
8599
+ inlineQueue;
8600
+ tokenizer;
8601
+ constructor(e) {
8602
+ 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 };
8603
+ let t2 = { other: m, block: E.normal, inline: M.normal };
8604
+ 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;
8605
+ }
8606
+ static get rules() {
8607
+ return { block: E, inline: M };
8608
+ }
8609
+ static lex(e, t2) {
8610
+ return new u(t2).lex(e);
8611
+ }
8612
+ static lexInline(e, t2) {
8613
+ return new u(t2).inlineTokens(e);
8614
+ }
8615
+ lex(e) {
8616
+ e = e.replace(m.carriageReturn, `
8617
+ `), this.blockTokens(e, this.tokens);
8618
+ for (let t2 = 0;t2 < this.inlineQueue.length; t2++) {
8619
+ let n = this.inlineQueue[t2];
8620
+ this.inlineTokens(n.src, n.tokens);
8621
+ }
8622
+ return this.inlineQueue = [], this.tokens;
8623
+ }
8624
+ blockTokens(e, t2 = [], n = false) {
8625
+ for (this.options.pedantic && (e = e.replace(m.tabCharGlobal, " ").replace(m.spaceLine, ""));e; ) {
8626
+ let r;
8627
+ 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))
8628
+ continue;
8629
+ if (r = this.tokenizer.space(e)) {
8630
+ e = e.substring(r.raw.length);
8631
+ let s = t2.at(-1);
8632
+ r.raw.length === 1 && s !== undefined ? s.raw += `
8633
+ ` : t2.push(r);
8634
+ continue;
8635
+ }
8636
+ if (r = this.tokenizer.code(e)) {
8637
+ e = e.substring(r.raw.length);
8638
+ let s = t2.at(-1);
8639
+ s?.type === "paragraph" || s?.type === "text" ? (s.raw += (s.raw.endsWith(`
8640
+ `) ? "" : `
8641
+ `) + r.raw, s.text += `
8642
+ ` + r.text, this.inlineQueue.at(-1).src = s.text) : t2.push(r);
8643
+ continue;
8644
+ }
8645
+ if (r = this.tokenizer.fences(e)) {
8646
+ e = e.substring(r.raw.length), t2.push(r);
8647
+ continue;
8648
+ }
8649
+ if (r = this.tokenizer.heading(e)) {
8650
+ e = e.substring(r.raw.length), t2.push(r);
8651
+ continue;
8652
+ }
8653
+ if (r = this.tokenizer.hr(e)) {
8654
+ e = e.substring(r.raw.length), t2.push(r);
8655
+ continue;
8656
+ }
8657
+ if (r = this.tokenizer.blockquote(e)) {
8658
+ e = e.substring(r.raw.length), t2.push(r);
8659
+ continue;
8660
+ }
8661
+ if (r = this.tokenizer.list(e)) {
8662
+ e = e.substring(r.raw.length), t2.push(r);
8663
+ continue;
8664
+ }
8665
+ if (r = this.tokenizer.html(e)) {
8666
+ e = e.substring(r.raw.length), t2.push(r);
8667
+ continue;
8668
+ }
8669
+ if (r = this.tokenizer.def(e)) {
8670
+ e = e.substring(r.raw.length);
8671
+ let s = t2.at(-1);
8672
+ s?.type === "paragraph" || s?.type === "text" ? (s.raw += (s.raw.endsWith(`
8673
+ `) ? "" : `
8674
+ `) + r.raw, s.text += `
8675
+ ` + 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));
8676
+ continue;
8677
+ }
8678
+ if (r = this.tokenizer.table(e)) {
8679
+ e = e.substring(r.raw.length), t2.push(r);
8680
+ continue;
8681
+ }
8682
+ if (r = this.tokenizer.lheading(e)) {
8683
+ e = e.substring(r.raw.length), t2.push(r);
8684
+ continue;
9294
8685
  }
9295
- return { type: "heading", raw: t2[0], depth: t2[1].length, text: n, tokens: this.lexer.inline(n) };
9296
- }
9297
- }
9298
- hr(e) {
9299
- let t2 = this.rules.block.hr.exec(e);
9300
- if (t2)
9301
- return { type: "hr", raw: z(t2[0], `
9302
- `) };
9303
- }
9304
- blockquote(e) {
9305
- let t2 = this.rules.block.blockquote.exec(e);
9306
- if (t2) {
9307
- let n = z(t2[0], `
9308
- `).split(`
9309
- `), r = "", i = "", s = [];
9310
- for (;n.length > 0; ) {
9311
- let a = false, o = [], l;
9312
- for (l = 0;l < n.length; l++)
9313
- if (this.rules.other.blockquoteStart.test(n[l]))
9314
- o.push(n[l]), a = true;
9315
- else if (!a)
9316
- o.push(n[l]);
9317
- else
9318
- break;
9319
- n = n.slice(l);
9320
- let p = o.join(`
9321
- `), c = p.replace(this.rules.other.blockquoteSetextReplace, `
9322
- $1`).replace(this.rules.other.blockquoteSetextReplace2, "");
9323
- r = r ? `${r}
9324
- ${p}` : p, i = i ? `${i}
9325
- ${c}` : c;
9326
- let g = this.lexer.state.top;
9327
- if (this.lexer.state.top = true, this.lexer.blockTokens(c, s, true), this.lexer.state.top = g, n.length === 0)
9328
- break;
9329
- let h2 = s.at(-1);
9330
- if (h2?.type === "code")
9331
- break;
9332
- if (h2?.type === "blockquote") {
9333
- let R = h2, f = R.raw + `
9334
- ` + n.join(`
9335
- `), O = this.blockquote(f);
9336
- 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;
8686
+ let i = e;
8687
+ if (this.options.extensions?.startBlock) {
8688
+ let s = 1 / 0, a = e.slice(1), o;
8689
+ this.options.extensions.startBlock.forEach((l) => {
8690
+ o = l.call({ lexer: this }, a), typeof o == "number" && o >= 0 && (s = Math.min(s, o));
8691
+ }), s < 1 / 0 && s >= 0 && (i = e.substring(0, s + 1));
8692
+ }
8693
+ if (this.state.top && (r = this.tokenizer.paragraph(i))) {
8694
+ let s = t2.at(-1);
8695
+ n && s?.type === "paragraph" ? (s.raw += (s.raw.endsWith(`
8696
+ `) ? "" : `
8697
+ `) + r.raw, s.text += `
8698
+ ` + 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);
8699
+ continue;
8700
+ }
8701
+ if (r = this.tokenizer.text(e)) {
8702
+ e = e.substring(r.raw.length);
8703
+ let s = t2.at(-1);
8704
+ s?.type === "text" ? (s.raw += (s.raw.endsWith(`
8705
+ `) ? "" : `
8706
+ `) + r.raw, s.text += `
8707
+ ` + r.text, this.inlineQueue.pop(), this.inlineQueue.at(-1).src = s.text) : t2.push(r);
8708
+ continue;
8709
+ }
8710
+ if (e) {
8711
+ let s = "Infinite loop on byte: " + e.charCodeAt(0);
8712
+ if (this.options.silent) {
8713
+ console.error(s);
9337
8714
  break;
9338
- } else if (h2?.type === "list") {
9339
- let R = h2, f = R.raw + `
9340
- ` + n.join(`
9341
- `), O = this.list(f);
9342
- 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(`
9343
- `);
9344
- continue;
9345
- }
8715
+ } else
8716
+ throw new Error(s);
9346
8717
  }
9347
- return { type: "blockquote", raw: r, tokens: s, text: i };
9348
8718
  }
8719
+ return this.state.top = true, t2;
9349
8720
  }
9350
- list(e) {
9351
- let t2 = this.rules.block.list.exec(e);
9352
- if (t2) {
9353
- let n = t2[1].trim(), r = n.length > 1, i = { type: "list", raw: "", ordered: r, start: r ? +n.slice(0, -1) : "", loose: false, items: [] };
9354
- n = r ? `\\d{1,9}\\${n.slice(-1)}` : `\\${n}`, this.options.pedantic && (n = r ? n : "[*+-]");
9355
- let s = this.rules.other.listItemRegex(n), a = false;
9356
- for (;e; ) {
9357
- let l = false, p = "", c = "";
9358
- if (!(t2 = s.exec(e)) || this.rules.block.hr.test(e))
9359
- break;
9360
- p = t2[0], e = e.substring(p.length);
9361
- let g = t2[2].split(`
9362
- `, 1)[0].replace(this.rules.other.listReplaceTabs, (O) => " ".repeat(3 * O.length)), h2 = e.split(`
9363
- `, 1)[0], R = !g.trim(), f = 0;
9364
- 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 + `
9365
- `, e = e.substring(h2.length + 1), l = true), !l) {
9366
- 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);
9367
- for (;e; ) {
9368
- let H = e.split(`
9369
- `, 1)[0], A;
9370
- 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))
9371
- break;
9372
- if (A.search(this.rules.other.nonSpaceChar) >= f || !h2.trim())
9373
- c += `
9374
- ` + A.slice(f);
9375
- else {
9376
- if (R || g.replace(this.rules.other.tabCharGlobal, " ").search(this.rules.other.nonSpaceChar) >= 4 || Y.test(g) || ee.test(g) || V.test(g))
9377
- break;
9378
- c += `
9379
- ` + h2;
9380
- }
9381
- !R && !h2.trim() && (R = true), p += H + `
9382
- `, e = e.substring(H.length + 1), g = A.slice(f);
9383
- }
9384
- }
9385
- 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;
8721
+ inline(e, t2 = []) {
8722
+ return this.inlineQueue.push({ src: e, tokens: t2 }), t2;
8723
+ }
8724
+ inlineTokens(e, t2 = []) {
8725
+ let n = e, r = null;
8726
+ if (this.tokens.links) {
8727
+ let o = Object.keys(this.tokens.links);
8728
+ if (o.length > 0)
8729
+ for (;(r = this.tokenizer.rules.inline.reflinkSearch.exec(n)) != null; )
8730
+ 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));
8731
+ }
8732
+ for (;(r = this.tokenizer.rules.inline.anyPunctuation.exec(n)) != null; )
8733
+ n = n.slice(0, r.index) + "++" + n.slice(this.tokenizer.rules.inline.anyPunctuation.lastIndex);
8734
+ let i;
8735
+ for (;(r = this.tokenizer.rules.inline.blockSkip.exec(n)) != null; )
8736
+ 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);
8737
+ n = this.options.hooks?.emStrongMask?.call({ lexer: this }, n) ?? n;
8738
+ let s = false, a = "";
8739
+ for (;e; ) {
8740
+ s || (a = ""), s = false;
8741
+ let o;
8742
+ 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))
8743
+ continue;
8744
+ if (o = this.tokenizer.escape(e)) {
8745
+ e = e.substring(o.raw.length), t2.push(o);
8746
+ continue;
9386
8747
  }
9387
- let o = i.items.at(-1);
9388
- if (o)
9389
- o.raw = o.raw.trimEnd(), o.text = o.text.trimEnd();
9390
- else
9391
- return;
9392
- i.raw = i.raw.trimEnd();
9393
- for (let l of i.items) {
9394
- if (this.lexer.state.top = false, l.tokens = this.lexer.blockTokens(l.text, []), l.task) {
9395
- if (l.text = l.text.replace(this.rules.other.listReplaceTask, ""), l.tokens[0]?.type === "text" || l.tokens[0]?.type === "paragraph") {
9396
- 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, "");
9397
- for (let c = this.lexer.inlineQueue.length - 1;c >= 0; c--)
9398
- if (this.rules.other.listIsTask.test(this.lexer.inlineQueue[c].src)) {
9399
- this.lexer.inlineQueue[c].src = this.lexer.inlineQueue[c].src.replace(this.rules.other.listReplaceTask, "");
9400
- break;
9401
- }
9402
- }
9403
- let p = this.rules.other.listTaskCheckbox.exec(l.raw);
9404
- if (p) {
9405
- let c = { type: "checkbox", raw: p[0] + " ", checked: p[0] !== "[ ]" };
9406
- 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);
9407
- }
9408
- }
9409
- if (!i.loose) {
9410
- let p = l.tokens.filter((g) => g.type === "space"), c = p.length > 0 && p.some((g) => this.rules.other.anyLine.test(g.raw));
9411
- i.loose = c;
9412
- }
8748
+ if (o = this.tokenizer.tag(e)) {
8749
+ e = e.substring(o.raw.length), t2.push(o);
8750
+ continue;
8751
+ }
8752
+ if (o = this.tokenizer.link(e)) {
8753
+ e = e.substring(o.raw.length), t2.push(o);
8754
+ continue;
8755
+ }
8756
+ if (o = this.tokenizer.reflink(e, this.tokens.links)) {
8757
+ e = e.substring(o.raw.length);
8758
+ let p = t2.at(-1);
8759
+ o.type === "text" && p?.type === "text" ? (p.raw += o.raw, p.text += o.text) : t2.push(o);
8760
+ continue;
8761
+ }
8762
+ if (o = this.tokenizer.emStrong(e, n, a)) {
8763
+ e = e.substring(o.raw.length), t2.push(o);
8764
+ continue;
8765
+ }
8766
+ if (o = this.tokenizer.codespan(e)) {
8767
+ e = e.substring(o.raw.length), t2.push(o);
8768
+ continue;
8769
+ }
8770
+ if (o = this.tokenizer.br(e)) {
8771
+ e = e.substring(o.raw.length), t2.push(o);
8772
+ continue;
8773
+ }
8774
+ if (o = this.tokenizer.del(e)) {
8775
+ e = e.substring(o.raw.length), t2.push(o);
8776
+ continue;
8777
+ }
8778
+ if (o = this.tokenizer.autolink(e)) {
8779
+ e = e.substring(o.raw.length), t2.push(o);
8780
+ continue;
8781
+ }
8782
+ if (!this.state.inLink && (o = this.tokenizer.url(e))) {
8783
+ e = e.substring(o.raw.length), t2.push(o);
8784
+ continue;
8785
+ }
8786
+ let l = e;
8787
+ if (this.options.extensions?.startInline) {
8788
+ let p = 1 / 0, c = e.slice(1), g;
8789
+ this.options.extensions.startInline.forEach((h2) => {
8790
+ g = h2.call({ lexer: this }, c), typeof g == "number" && g >= 0 && (p = Math.min(p, g));
8791
+ }), p < 1 / 0 && p >= 0 && (l = e.substring(0, p + 1));
8792
+ }
8793
+ if (o = this.tokenizer.inlineText(l)) {
8794
+ e = e.substring(o.raw.length), o.raw.slice(-1) !== "_" && (a = o.raw.slice(-1)), s = true;
8795
+ let p = t2.at(-1);
8796
+ p?.type === "text" ? (p.raw += o.raw, p.text += o.text) : t2.push(o);
8797
+ continue;
8798
+ }
8799
+ if (e) {
8800
+ let p = "Infinite loop on byte: " + e.charCodeAt(0);
8801
+ if (this.options.silent) {
8802
+ console.error(p);
8803
+ break;
8804
+ } else
8805
+ throw new Error(p);
9413
8806
  }
9414
- if (i.loose)
9415
- for (let l of i.items) {
9416
- l.loose = true;
9417
- for (let p of l.tokens)
9418
- p.type === "text" && (p.type = "paragraph");
9419
- }
9420
- return i;
9421
8807
  }
8808
+ return t2;
8809
+ }
8810
+ };
8811
+ var P = class {
8812
+ options;
8813
+ parser;
8814
+ constructor(e) {
8815
+ this.options = e || T;
8816
+ }
8817
+ space(e) {
8818
+ return "";
8819
+ }
8820
+ code({ text: e, lang: t2, escaped: n }) {
8821
+ let r = (t2 || "").match(m.notSpaceStart)?.[0], i = e.replace(m.endingNewline, "") + `
8822
+ `;
8823
+ return r ? '<pre><code class="language-' + w(r) + '">' + (n ? i : w(i, true)) + `</code></pre>
8824
+ ` : "<pre><code>" + (n ? i : w(i, true)) + `</code></pre>
8825
+ `;
8826
+ }
8827
+ blockquote({ tokens: e }) {
8828
+ return `<blockquote>
8829
+ ${this.parser.parse(e)}</blockquote>
8830
+ `;
9422
8831
  }
9423
- html(e) {
9424
- let t2 = this.rules.block.html.exec(e);
9425
- if (t2)
9426
- return { type: "html", block: true, raw: t2[0], pre: t2[1] === "pre" || t2[1] === "script" || t2[1] === "style", text: t2[0] };
8832
+ html({ text: e }) {
8833
+ return e;
9427
8834
  }
9428
8835
  def(e) {
9429
- let t2 = this.rules.block.def.exec(e);
9430
- if (t2) {
9431
- 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];
9432
- return { type: "def", tag: n, raw: t2[0], href: r, title: i };
9433
- }
8836
+ return "";
9434
8837
  }
9435
- table(e) {
9436
- let t2 = this.rules.block.table.exec(e);
9437
- if (!t2 || !this.rules.other.tableDelimiter.test(t2[2]))
9438
- return;
9439
- 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(`
9440
- `) : [], s = { type: "table", raw: t2[0], header: [], align: [], rows: [] };
9441
- if (n.length === r.length) {
9442
- for (let a of r)
9443
- 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);
9444
- for (let a = 0;a < n.length; a++)
9445
- s.header.push({ text: n[a], tokens: this.lexer.inline(n[a]), header: true, align: s.align[a] });
9446
- for (let a of i)
9447
- s.rows.push(J(a, s.header.length).map((o, l) => ({ text: o, tokens: this.lexer.inline(o), header: false, align: s.align[l] })));
9448
- return s;
9449
- }
8838
+ heading({ tokens: e, depth: t2 }) {
8839
+ return `<h${t2}>${this.parser.parseInline(e)}</h${t2}>
8840
+ `;
9450
8841
  }
9451
- lheading(e) {
9452
- let t2 = this.rules.block.lheading.exec(e);
9453
- if (t2)
9454
- return { type: "heading", raw: t2[0], depth: t2[2].charAt(0) === "=" ? 1 : 2, text: t2[1], tokens: this.lexer.inline(t2[1]) };
8842
+ hr(e) {
8843
+ return `<hr>
8844
+ `;
9455
8845
  }
9456
- paragraph(e) {
9457
- let t2 = this.rules.block.paragraph.exec(e);
9458
- if (t2) {
9459
- let n = t2[1].charAt(t2[1].length - 1) === `
9460
- ` ? t2[1].slice(0, -1) : t2[1];
9461
- return { type: "paragraph", raw: t2[0], text: n, tokens: this.lexer.inline(n) };
8846
+ list(e) {
8847
+ let { ordered: t2, start: n } = e, r = "";
8848
+ for (let a = 0;a < e.items.length; a++) {
8849
+ let o = e.items[a];
8850
+ r += this.listitem(o);
9462
8851
  }
8852
+ let i = t2 ? "ol" : "ul", s = t2 && n !== 1 ? ' start="' + n + '"' : "";
8853
+ return "<" + i + s + `>
8854
+ ` + r + "</" + i + `>
8855
+ `;
9463
8856
  }
9464
- text(e) {
9465
- let t2 = this.rules.block.text.exec(e);
9466
- if (t2)
9467
- return { type: "text", raw: t2[0], text: t2[0], tokens: this.lexer.inline(t2[0]) };
8857
+ listitem(e) {
8858
+ return `<li>${this.parser.parse(e.tokens)}</li>
8859
+ `;
9468
8860
  }
9469
- escape(e) {
9470
- let t2 = this.rules.inline.escape.exec(e);
9471
- if (t2)
9472
- return { type: "escape", raw: t2[0], text: t2[1] };
8861
+ checkbox({ checked: e }) {
8862
+ return "<input " + (e ? 'checked="" ' : "") + 'disabled="" type="checkbox"> ';
9473
8863
  }
9474
- tag(e) {
9475
- let t2 = this.rules.inline.tag.exec(e);
9476
- if (t2)
9477
- 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] };
8864
+ paragraph({ tokens: e }) {
8865
+ return `<p>${this.parser.parseInline(e)}</p>
8866
+ `;
9478
8867
  }
9479
- link(e) {
9480
- let t2 = this.rules.inline.link.exec(e);
9481
- if (t2) {
9482
- let n = t2[2].trim();
9483
- if (!this.options.pedantic && this.rules.other.startAngleBracket.test(n)) {
9484
- if (!this.rules.other.endAngleBracket.test(n))
9485
- return;
9486
- let s = z(n.slice(0, -1), "\\");
9487
- if ((n.length - s.length) % 2 === 0)
9488
- return;
9489
- } else {
9490
- let s = de(t2[2], "()");
9491
- if (s === -2)
9492
- return;
9493
- if (s > -1) {
9494
- let o = (t2[0].indexOf("!") === 0 ? 5 : 4) + t2[1].length + s;
9495
- t2[2] = t2[2].substring(0, s), t2[0] = t2[0].substring(0, o).trim(), t2[3] = "";
9496
- }
9497
- }
9498
- let r = t2[2], i = "";
9499
- if (this.options.pedantic) {
9500
- let s = this.rules.other.pedanticHrefTitle.exec(r);
9501
- s && (r = s[1], i = s[3]);
9502
- } else
9503
- i = t2[3] ? t2[3].slice(1, -1) : "";
9504
- 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);
8868
+ table(e) {
8869
+ let t2 = "", n = "";
8870
+ for (let i = 0;i < e.header.length; i++)
8871
+ n += this.tablecell(e.header[i]);
8872
+ t2 += this.tablerow({ text: n });
8873
+ let r = "";
8874
+ for (let i = 0;i < e.rows.length; i++) {
8875
+ let s = e.rows[i];
8876
+ n = "";
8877
+ for (let a = 0;a < s.length; a++)
8878
+ n += this.tablecell(s[a]);
8879
+ r += this.tablerow({ text: n });
9505
8880
  }
8881
+ return r && (r = `<tbody>${r}</tbody>`), `<table>
8882
+ <thead>
8883
+ ` + t2 + `</thead>
8884
+ ` + r + `</table>
8885
+ `;
9506
8886
  }
9507
- reflink(e, t2) {
9508
- let n;
9509
- if ((n = this.rules.inline.reflink.exec(e)) || (n = this.rules.inline.nolink.exec(e))) {
9510
- let r = (n[2] || n[1]).replace(this.rules.other.multipleSpaceGlobal, " "), i = t2[r.toLowerCase()];
9511
- if (!i) {
9512
- let s = n[0].charAt(0);
9513
- return { type: "text", raw: s, text: s };
9514
- }
9515
- return ge(n, i, n[0], this.lexer, this.rules);
9516
- }
8887
+ tablerow({ text: e }) {
8888
+ return `<tr>
8889
+ ${e}</tr>
8890
+ `;
9517
8891
  }
9518
- emStrong(e, t2, n = "") {
9519
- let r = this.rules.inline.emStrongLDelim.exec(e);
9520
- if (!r || r[3] && n.match(this.rules.other.unicodeAlphaNumeric))
9521
- return;
9522
- if (!(r[1] || r[2] || "") || !n || this.rules.inline.punctuation.exec(n)) {
9523
- let s = [...r[0]].length - 1, a, o, l = s, p = 0, c = r[0][0] === "*" ? this.rules.inline.emStrongRDelimAst : this.rules.inline.emStrongRDelimUnd;
9524
- for (c.lastIndex = 0, t2 = t2.slice(-1 * e.length + s);(r = c.exec(t2)) != null; ) {
9525
- if (a = r[1] || r[2] || r[3] || r[4] || r[5] || r[6], !a)
9526
- continue;
9527
- if (o = [...a].length, r[3] || r[4]) {
9528
- l += o;
9529
- continue;
9530
- } else if ((r[5] || r[6]) && s % 3 && !((s + o) % 3)) {
9531
- p += o;
9532
- continue;
9533
- }
9534
- if (l -= o, l > 0)
9535
- continue;
9536
- o = Math.min(o, o + l + p);
9537
- let g = [...r[0]][0].length, h2 = e.slice(0, s + r.index + g + o);
9538
- if (Math.min(s, o) % 2) {
9539
- let f = h2.slice(1, -1);
9540
- return { type: "em", raw: h2, text: f, tokens: this.lexer.inlineTokens(f) };
9541
- }
9542
- let R = h2.slice(2, -2);
9543
- return { type: "strong", raw: h2, text: R, tokens: this.lexer.inlineTokens(R) };
9544
- }
9545
- }
8892
+ tablecell(e) {
8893
+ let t2 = this.parser.parseInline(e.tokens), n = e.header ? "th" : "td";
8894
+ return (e.align ? `<${n} align="${e.align}">` : `<${n}>`) + t2 + `</${n}>
8895
+ `;
9546
8896
  }
9547
- codespan(e) {
9548
- let t2 = this.rules.inline.code.exec(e);
9549
- if (t2) {
9550
- 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);
9551
- return r && i && (n = n.substring(1, n.length - 1)), { type: "codespan", raw: t2[0], text: n };
9552
- }
8897
+ strong({ tokens: e }) {
8898
+ return `<strong>${this.parser.parseInline(e)}</strong>`;
8899
+ }
8900
+ em({ tokens: e }) {
8901
+ return `<em>${this.parser.parseInline(e)}</em>`;
8902
+ }
8903
+ codespan({ text: e }) {
8904
+ return `<code>${w(e, true)}</code>`;
9553
8905
  }
9554
8906
  br(e) {
9555
- let t2 = this.rules.inline.br.exec(e);
9556
- if (t2)
9557
- return { type: "br", raw: t2[0] };
8907
+ return "<br>";
9558
8908
  }
9559
- del(e) {
9560
- let t2 = this.rules.inline.del.exec(e);
9561
- if (t2)
9562
- return { type: "del", raw: t2[0], text: t2[2], tokens: this.lexer.inlineTokens(t2[2]) };
8909
+ del({ tokens: e }) {
8910
+ return `<del>${this.parser.parseInline(e)}</del>`;
9563
8911
  }
9564
- autolink(e) {
9565
- let t2 = this.rules.inline.autolink.exec(e);
9566
- if (t2) {
9567
- let n, r;
9568
- 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 }] };
9569
- }
8912
+ link({ href: e, title: t2, tokens: n }) {
8913
+ let r = this.parser.parseInline(n), i = X(e);
8914
+ if (i === null)
8915
+ return r;
8916
+ e = i;
8917
+ let s = '<a href="' + e + '"';
8918
+ return t2 && (s += ' title="' + w(t2) + '"'), s += ">" + r + "</a>", s;
9570
8919
  }
9571
- url(e) {
9572
- let t2;
9573
- if (t2 = this.rules.inline.url.exec(e)) {
9574
- let n, r;
9575
- if (t2[2] === "@")
9576
- n = t2[0], r = "mailto:" + n;
9577
- else {
9578
- let i;
9579
- do
9580
- i = t2[0], t2[0] = this.rules.inline._backpedal.exec(t2[0])?.[0] ?? "";
9581
- while (i !== t2[0]);
9582
- n = t2[0], t2[1] === "www." ? r = "http://" + t2[0] : r = t2[0];
9583
- }
9584
- return { type: "link", raw: t2[0], text: n, href: r, tokens: [{ type: "text", raw: n, text: n }] };
9585
- }
8920
+ image({ href: e, title: t2, text: n, tokens: r }) {
8921
+ r && (n = this.parser.parseInline(r, this.parser.textRenderer));
8922
+ let i = X(e);
8923
+ if (i === null)
8924
+ return w(n);
8925
+ e = i;
8926
+ let s = `<img src="${e}" alt="${n}"`;
8927
+ return t2 && (s += ` title="${w(t2)}"`), s += ">", s;
8928
+ }
8929
+ text(e) {
8930
+ return "tokens" in e && e.tokens ? this.parser.parseInline(e.tokens) : ("escaped" in e) && e.escaped ? e.text : w(e.text);
8931
+ }
8932
+ };
8933
+ var $ = class {
8934
+ strong({ text: e }) {
8935
+ return e;
8936
+ }
8937
+ em({ text: e }) {
8938
+ return e;
8939
+ }
8940
+ codespan({ text: e }) {
8941
+ return e;
8942
+ }
8943
+ del({ text: e }) {
8944
+ return e;
8945
+ }
8946
+ html({ text: e }) {
8947
+ return e;
8948
+ }
8949
+ text({ text: e }) {
8950
+ return e;
8951
+ }
8952
+ link({ text: e }) {
8953
+ return "" + e;
8954
+ }
8955
+ image({ text: e }) {
8956
+ return "" + e;
8957
+ }
8958
+ br() {
8959
+ return "";
9586
8960
  }
9587
- inlineText(e) {
9588
- let t2 = this.rules.inline.text.exec(e);
9589
- if (t2) {
9590
- let n = this.lexer.state.inRawBlock;
9591
- return { type: "text", raw: t2[0], text: t2[0], escaped: n };
9592
- }
8961
+ checkbox({ raw: e }) {
8962
+ return e;
9593
8963
  }
9594
8964
  };
9595
- var x = class u {
9596
- tokens;
8965
+ var b = class u2 {
9597
8966
  options;
9598
- state;
9599
- inlineQueue;
9600
- tokenizer;
8967
+ renderer;
8968
+ textRenderer;
9601
8969
  constructor(e) {
9602
- 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 };
9603
- let t2 = { other: m, block: E.normal, inline: M.normal };
9604
- 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;
9605
- }
9606
- static get rules() {
9607
- return { block: E, inline: M };
9608
- }
9609
- static lex(e, t2) {
9610
- return new u(t2).lex(e);
8970
+ 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 $;
9611
8971
  }
9612
- static lexInline(e, t2) {
9613
- return new u(t2).inlineTokens(e);
8972
+ static parse(e, t2) {
8973
+ return new u2(t2).parse(e);
9614
8974
  }
9615
- lex(e) {
9616
- e = e.replace(m.carriageReturn, `
9617
- `), this.blockTokens(e, this.tokens);
9618
- for (let t2 = 0;t2 < this.inlineQueue.length; t2++) {
9619
- let n = this.inlineQueue[t2];
9620
- this.inlineTokens(n.src, n.tokens);
9621
- }
9622
- return this.inlineQueue = [], this.tokens;
8975
+ static parseInline(e, t2) {
8976
+ return new u2(t2).parseInline(e);
9623
8977
  }
9624
- blockTokens(e, t2 = [], n = false) {
9625
- for (this.options.pedantic && (e = e.replace(m.tabCharGlobal, " ").replace(m.spaceLine, ""));e; ) {
9626
- let r;
9627
- 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))
9628
- continue;
9629
- if (r = this.tokenizer.space(e)) {
9630
- e = e.substring(r.raw.length);
9631
- let s = t2.at(-1);
9632
- r.raw.length === 1 && s !== undefined ? s.raw += `
9633
- ` : t2.push(r);
9634
- continue;
9635
- }
9636
- if (r = this.tokenizer.code(e)) {
9637
- e = e.substring(r.raw.length);
9638
- let s = t2.at(-1);
9639
- s?.type === "paragraph" || s?.type === "text" ? (s.raw += (s.raw.endsWith(`
9640
- `) ? "" : `
9641
- `) + r.raw, s.text += `
9642
- ` + r.text, this.inlineQueue.at(-1).src = s.text) : t2.push(r);
9643
- continue;
9644
- }
9645
- if (r = this.tokenizer.fences(e)) {
9646
- e = e.substring(r.raw.length), t2.push(r);
9647
- continue;
9648
- }
9649
- if (r = this.tokenizer.heading(e)) {
9650
- e = e.substring(r.raw.length), t2.push(r);
9651
- continue;
9652
- }
9653
- if (r = this.tokenizer.hr(e)) {
9654
- e = e.substring(r.raw.length), t2.push(r);
9655
- continue;
9656
- }
9657
- if (r = this.tokenizer.blockquote(e)) {
9658
- e = e.substring(r.raw.length), t2.push(r);
9659
- continue;
9660
- }
9661
- if (r = this.tokenizer.list(e)) {
9662
- e = e.substring(r.raw.length), t2.push(r);
9663
- continue;
9664
- }
9665
- if (r = this.tokenizer.html(e)) {
9666
- e = e.substring(r.raw.length), t2.push(r);
9667
- continue;
9668
- }
9669
- if (r = this.tokenizer.def(e)) {
9670
- e = e.substring(r.raw.length);
9671
- let s = t2.at(-1);
9672
- s?.type === "paragraph" || s?.type === "text" ? (s.raw += (s.raw.endsWith(`
9673
- `) ? "" : `
9674
- `) + r.raw, s.text += `
9675
- ` + 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));
9676
- continue;
9677
- }
9678
- if (r = this.tokenizer.table(e)) {
9679
- e = e.substring(r.raw.length), t2.push(r);
9680
- continue;
9681
- }
9682
- if (r = this.tokenizer.lheading(e)) {
9683
- e = e.substring(r.raw.length), t2.push(r);
9684
- continue;
9685
- }
9686
- let i = e;
9687
- if (this.options.extensions?.startBlock) {
9688
- let s = 1 / 0, a = e.slice(1), o;
9689
- this.options.extensions.startBlock.forEach((l) => {
9690
- o = l.call({ lexer: this }, a), typeof o == "number" && o >= 0 && (s = Math.min(s, o));
9691
- }), s < 1 / 0 && s >= 0 && (i = e.substring(0, s + 1));
8978
+ parse(e) {
8979
+ let t2 = "";
8980
+ for (let n = 0;n < e.length; n++) {
8981
+ let r = e[n];
8982
+ if (this.options.extensions?.renderers?.[r.type]) {
8983
+ let s = r, a = this.options.extensions.renderers[s.type].call({ parser: this }, s);
8984
+ if (a !== false || !["space", "hr", "heading", "code", "table", "blockquote", "list", "html", "def", "paragraph", "text"].includes(s.type)) {
8985
+ t2 += a || "";
8986
+ continue;
8987
+ }
9692
8988
  }
9693
- if (this.state.top && (r = this.tokenizer.paragraph(i))) {
9694
- let s = t2.at(-1);
9695
- n && s?.type === "paragraph" ? (s.raw += (s.raw.endsWith(`
9696
- `) ? "" : `
9697
- `) + r.raw, s.text += `
9698
- ` + 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);
9699
- continue;
8989
+ let i = r;
8990
+ switch (i.type) {
8991
+ case "space": {
8992
+ t2 += this.renderer.space(i);
8993
+ break;
8994
+ }
8995
+ case "hr": {
8996
+ t2 += this.renderer.hr(i);
8997
+ break;
8998
+ }
8999
+ case "heading": {
9000
+ t2 += this.renderer.heading(i);
9001
+ break;
9002
+ }
9003
+ case "code": {
9004
+ t2 += this.renderer.code(i);
9005
+ break;
9006
+ }
9007
+ case "table": {
9008
+ t2 += this.renderer.table(i);
9009
+ break;
9010
+ }
9011
+ case "blockquote": {
9012
+ t2 += this.renderer.blockquote(i);
9013
+ break;
9014
+ }
9015
+ case "list": {
9016
+ t2 += this.renderer.list(i);
9017
+ break;
9018
+ }
9019
+ case "checkbox": {
9020
+ t2 += this.renderer.checkbox(i);
9021
+ break;
9022
+ }
9023
+ case "html": {
9024
+ t2 += this.renderer.html(i);
9025
+ break;
9026
+ }
9027
+ case "def": {
9028
+ t2 += this.renderer.def(i);
9029
+ break;
9030
+ }
9031
+ case "paragraph": {
9032
+ t2 += this.renderer.paragraph(i);
9033
+ break;
9034
+ }
9035
+ case "text": {
9036
+ t2 += this.renderer.text(i);
9037
+ break;
9038
+ }
9039
+ default: {
9040
+ let s = 'Token with "' + i.type + '" type was not found.';
9041
+ if (this.options.silent)
9042
+ return console.error(s), "";
9043
+ throw new Error(s);
9044
+ }
9700
9045
  }
9701
- if (r = this.tokenizer.text(e)) {
9702
- e = e.substring(r.raw.length);
9703
- let s = t2.at(-1);
9704
- s?.type === "text" ? (s.raw += (s.raw.endsWith(`
9705
- `) ? "" : `
9706
- `) + r.raw, s.text += `
9707
- ` + r.text, this.inlineQueue.pop(), this.inlineQueue.at(-1).src = s.text) : t2.push(r);
9708
- continue;
9046
+ }
9047
+ return t2;
9048
+ }
9049
+ parseInline(e, t2 = this.renderer) {
9050
+ let n = "";
9051
+ for (let r = 0;r < e.length; r++) {
9052
+ let i = e[r];
9053
+ if (this.options.extensions?.renderers?.[i.type]) {
9054
+ let a = this.options.extensions.renderers[i.type].call({ parser: this }, i);
9055
+ if (a !== false || !["escape", "html", "link", "image", "strong", "em", "codespan", "br", "del", "text"].includes(i.type)) {
9056
+ n += a || "";
9057
+ continue;
9058
+ }
9709
9059
  }
9710
- if (e) {
9711
- let s = "Infinite loop on byte: " + e.charCodeAt(0);
9712
- if (this.options.silent) {
9713
- console.error(s);
9060
+ let s = i;
9061
+ switch (s.type) {
9062
+ case "escape": {
9063
+ n += t2.text(s);
9714
9064
  break;
9715
- } else
9716
- throw new Error(s);
9065
+ }
9066
+ case "html": {
9067
+ n += t2.html(s);
9068
+ break;
9069
+ }
9070
+ case "link": {
9071
+ n += t2.link(s);
9072
+ break;
9073
+ }
9074
+ case "image": {
9075
+ n += t2.image(s);
9076
+ break;
9077
+ }
9078
+ case "checkbox": {
9079
+ n += t2.checkbox(s);
9080
+ break;
9081
+ }
9082
+ case "strong": {
9083
+ n += t2.strong(s);
9084
+ break;
9085
+ }
9086
+ case "em": {
9087
+ n += t2.em(s);
9088
+ break;
9089
+ }
9090
+ case "codespan": {
9091
+ n += t2.codespan(s);
9092
+ break;
9093
+ }
9094
+ case "br": {
9095
+ n += t2.br(s);
9096
+ break;
9097
+ }
9098
+ case "del": {
9099
+ n += t2.del(s);
9100
+ break;
9101
+ }
9102
+ case "text": {
9103
+ n += t2.text(s);
9104
+ break;
9105
+ }
9106
+ default: {
9107
+ let a = 'Token with "' + s.type + '" type was not found.';
9108
+ if (this.options.silent)
9109
+ return console.error(a), "";
9110
+ throw new Error(a);
9111
+ }
9717
9112
  }
9718
9113
  }
9719
- return this.state.top = true, t2;
9114
+ return n;
9720
9115
  }
9721
- inline(e, t2 = []) {
9722
- return this.inlineQueue.push({ src: e, tokens: t2 }), t2;
9116
+ };
9117
+ var S = class {
9118
+ options;
9119
+ block;
9120
+ constructor(e) {
9121
+ this.options = e || T;
9723
9122
  }
9724
- inlineTokens(e, t2 = []) {
9725
- let n = e, r = null;
9726
- if (this.tokens.links) {
9727
- let o = Object.keys(this.tokens.links);
9728
- if (o.length > 0)
9729
- for (;(r = this.tokenizer.rules.inline.reflinkSearch.exec(n)) != null; )
9730
- 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));
9731
- }
9732
- for (;(r = this.tokenizer.rules.inline.anyPunctuation.exec(n)) != null; )
9733
- n = n.slice(0, r.index) + "++" + n.slice(this.tokenizer.rules.inline.anyPunctuation.lastIndex);
9734
- let i;
9735
- for (;(r = this.tokenizer.rules.inline.blockSkip.exec(n)) != null; )
9736
- 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);
9737
- n = this.options.hooks?.emStrongMask?.call({ lexer: this }, n) ?? n;
9738
- let s = false, a = "";
9739
- for (;e; ) {
9740
- s || (a = ""), s = false;
9741
- let o;
9742
- 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))
9743
- continue;
9744
- if (o = this.tokenizer.escape(e)) {
9745
- e = e.substring(o.raw.length), t2.push(o);
9746
- continue;
9747
- }
9748
- if (o = this.tokenizer.tag(e)) {
9749
- e = e.substring(o.raw.length), t2.push(o);
9750
- continue;
9751
- }
9752
- if (o = this.tokenizer.link(e)) {
9753
- e = e.substring(o.raw.length), t2.push(o);
9754
- continue;
9755
- }
9756
- if (o = this.tokenizer.reflink(e, this.tokens.links)) {
9757
- e = e.substring(o.raw.length);
9758
- let p = t2.at(-1);
9759
- o.type === "text" && p?.type === "text" ? (p.raw += o.raw, p.text += o.text) : t2.push(o);
9760
- continue;
9761
- }
9762
- if (o = this.tokenizer.emStrong(e, n, a)) {
9763
- e = e.substring(o.raw.length), t2.push(o);
9764
- continue;
9765
- }
9766
- if (o = this.tokenizer.codespan(e)) {
9767
- e = e.substring(o.raw.length), t2.push(o);
9768
- continue;
9769
- }
9770
- if (o = this.tokenizer.br(e)) {
9771
- e = e.substring(o.raw.length), t2.push(o);
9772
- continue;
9123
+ static passThroughHooks = new Set(["preprocess", "postprocess", "processAllTokens", "emStrongMask"]);
9124
+ static passThroughHooksRespectAsync = new Set(["preprocess", "postprocess", "processAllTokens"]);
9125
+ preprocess(e) {
9126
+ return e;
9127
+ }
9128
+ postprocess(e) {
9129
+ return e;
9130
+ }
9131
+ processAllTokens(e) {
9132
+ return e;
9133
+ }
9134
+ emStrongMask(e) {
9135
+ return e;
9136
+ }
9137
+ provideLexer() {
9138
+ return this.block ? x.lex : x.lexInline;
9139
+ }
9140
+ provideParser() {
9141
+ return this.block ? b.parse : b.parseInline;
9142
+ }
9143
+ };
9144
+ var B = class {
9145
+ defaults = L();
9146
+ options = this.setOptions;
9147
+ parse = this.parseMarkdown(true);
9148
+ parseInline = this.parseMarkdown(false);
9149
+ Parser = b;
9150
+ Renderer = P;
9151
+ TextRenderer = $;
9152
+ Lexer = x;
9153
+ Tokenizer = y;
9154
+ Hooks = S;
9155
+ constructor(...e) {
9156
+ this.use(...e);
9157
+ }
9158
+ walkTokens(e, t2) {
9159
+ let n = [];
9160
+ for (let r of e)
9161
+ switch (n = n.concat(t2.call(this, r)), r.type) {
9162
+ case "table": {
9163
+ let i = r;
9164
+ for (let s of i.header)
9165
+ n = n.concat(this.walkTokens(s.tokens, t2));
9166
+ for (let s of i.rows)
9167
+ for (let a of s)
9168
+ n = n.concat(this.walkTokens(a.tokens, t2));
9169
+ break;
9170
+ }
9171
+ case "list": {
9172
+ let i = r;
9173
+ n = n.concat(this.walkTokens(i.items, t2));
9174
+ break;
9175
+ }
9176
+ default: {
9177
+ let i = r;
9178
+ this.defaults.extensions?.childTokens?.[i.type] ? this.defaults.extensions.childTokens[i.type].forEach((s) => {
9179
+ let a = i[s].flat(1 / 0);
9180
+ n = n.concat(this.walkTokens(a, t2));
9181
+ }) : i.tokens && (n = n.concat(this.walkTokens(i.tokens, t2)));
9182
+ }
9773
9183
  }
9774
- if (o = this.tokenizer.del(e)) {
9775
- e = e.substring(o.raw.length), t2.push(o);
9776
- continue;
9184
+ return n;
9185
+ }
9186
+ use(...e) {
9187
+ let t2 = this.defaults.extensions || { renderers: {}, childTokens: {} };
9188
+ return e.forEach((n) => {
9189
+ let r = { ...n };
9190
+ if (r.async = this.defaults.async || r.async || false, n.extensions && (n.extensions.forEach((i) => {
9191
+ if (!i.name)
9192
+ throw new Error("extension name required");
9193
+ if ("renderer" in i) {
9194
+ let s = t2.renderers[i.name];
9195
+ s ? t2.renderers[i.name] = function(...a) {
9196
+ let o = i.renderer.apply(this, a);
9197
+ return o === false && (o = s.apply(this, a)), o;
9198
+ } : t2.renderers[i.name] = i.renderer;
9199
+ }
9200
+ if ("tokenizer" in i) {
9201
+ if (!i.level || i.level !== "block" && i.level !== "inline")
9202
+ throw new Error("extension level must be 'block' or 'inline'");
9203
+ let s = t2[i.level];
9204
+ 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]));
9205
+ }
9206
+ "childTokens" in i && i.childTokens && (t2.childTokens[i.name] = i.childTokens);
9207
+ }), r.extensions = t2), n.renderer) {
9208
+ let i = this.defaults.renderer || new P(this.defaults);
9209
+ for (let s in n.renderer) {
9210
+ if (!(s in i))
9211
+ throw new Error(`renderer '${s}' does not exist`);
9212
+ if (["options", "parser"].includes(s))
9213
+ continue;
9214
+ let a = s, o = n.renderer[a], l = i[a];
9215
+ i[a] = (...p) => {
9216
+ let c = o.apply(i, p);
9217
+ return c === false && (c = l.apply(i, p)), c || "";
9218
+ };
9219
+ }
9220
+ r.renderer = i;
9777
9221
  }
9778
- if (o = this.tokenizer.autolink(e)) {
9779
- e = e.substring(o.raw.length), t2.push(o);
9780
- continue;
9222
+ if (n.tokenizer) {
9223
+ let i = this.defaults.tokenizer || new y(this.defaults);
9224
+ for (let s in n.tokenizer) {
9225
+ if (!(s in i))
9226
+ throw new Error(`tokenizer '${s}' does not exist`);
9227
+ if (["options", "rules", "lexer"].includes(s))
9228
+ continue;
9229
+ let a = s, o = n.tokenizer[a], l = i[a];
9230
+ i[a] = (...p) => {
9231
+ let c = o.apply(i, p);
9232
+ return c === false && (c = l.apply(i, p)), c;
9233
+ };
9234
+ }
9235
+ r.tokenizer = i;
9781
9236
  }
9782
- if (!this.state.inLink && (o = this.tokenizer.url(e))) {
9783
- e = e.substring(o.raw.length), t2.push(o);
9784
- continue;
9237
+ if (n.hooks) {
9238
+ let i = this.defaults.hooks || new S;
9239
+ for (let s in n.hooks) {
9240
+ if (!(s in i))
9241
+ throw new Error(`hook '${s}' does not exist`);
9242
+ if (["options", "block"].includes(s))
9243
+ continue;
9244
+ let a = s, o = n.hooks[a], l = i[a];
9245
+ S.passThroughHooks.has(s) ? i[a] = (p) => {
9246
+ if (this.defaults.async && S.passThroughHooksRespectAsync.has(s))
9247
+ return (async () => {
9248
+ let g = await o.call(i, p);
9249
+ return l.call(i, g);
9250
+ })();
9251
+ let c = o.call(i, p);
9252
+ return l.call(i, c);
9253
+ } : i[a] = (...p) => {
9254
+ if (this.defaults.async)
9255
+ return (async () => {
9256
+ let g = await o.apply(i, p);
9257
+ return g === false && (g = await l.apply(i, p)), g;
9258
+ })();
9259
+ let c = o.apply(i, p);
9260
+ return c === false && (c = l.apply(i, p)), c;
9261
+ };
9262
+ }
9263
+ r.hooks = i;
9785
9264
  }
9786
- let l = e;
9787
- if (this.options.extensions?.startInline) {
9788
- let p = 1 / 0, c = e.slice(1), g;
9789
- this.options.extensions.startInline.forEach((h2) => {
9790
- g = h2.call({ lexer: this }, c), typeof g == "number" && g >= 0 && (p = Math.min(p, g));
9791
- }), p < 1 / 0 && p >= 0 && (l = e.substring(0, p + 1));
9265
+ if (n.walkTokens) {
9266
+ let i = this.defaults.walkTokens, s = n.walkTokens;
9267
+ r.walkTokens = function(a) {
9268
+ let o = [];
9269
+ return o.push(s.call(this, a)), i && (o = o.concat(i.call(this, a))), o;
9270
+ };
9792
9271
  }
9793
- if (o = this.tokenizer.inlineText(l)) {
9794
- e = e.substring(o.raw.length), o.raw.slice(-1) !== "_" && (a = o.raw.slice(-1)), s = true;
9795
- let p = t2.at(-1);
9796
- p?.type === "text" ? (p.raw += o.raw, p.text += o.text) : t2.push(o);
9797
- continue;
9272
+ this.defaults = { ...this.defaults, ...r };
9273
+ }), this;
9274
+ }
9275
+ setOptions(e) {
9276
+ return this.defaults = { ...this.defaults, ...e }, this;
9277
+ }
9278
+ lexer(e, t2) {
9279
+ return x.lex(e, t2 ?? this.defaults);
9280
+ }
9281
+ parser(e, t2) {
9282
+ return b.parse(e, t2 ?? this.defaults);
9283
+ }
9284
+ parseMarkdown(e) {
9285
+ return (n, r) => {
9286
+ let i = { ...r }, s = { ...this.defaults, ...i }, a = this.onError(!!s.silent, !!s.async);
9287
+ if (this.defaults.async === true && i.async === false)
9288
+ 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."));
9289
+ if (typeof n > "u" || n === null)
9290
+ return a(new Error("marked(): input parameter is undefined or null"));
9291
+ if (typeof n != "string")
9292
+ return a(new Error("marked(): input parameter is of type " + Object.prototype.toString.call(n) + ", string expected"));
9293
+ if (s.hooks && (s.hooks.options = s, s.hooks.block = e), s.async)
9294
+ return (async () => {
9295
+ 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;
9296
+ s.walkTokens && await Promise.all(this.walkTokens(c, s.walkTokens));
9297
+ let h2 = await (s.hooks ? await s.hooks.provideParser() : e ? b.parse : b.parseInline)(c, s);
9298
+ return s.hooks ? await s.hooks.postprocess(h2) : h2;
9299
+ })().catch(a);
9300
+ try {
9301
+ s.hooks && (n = s.hooks.preprocess(n));
9302
+ let l = (s.hooks ? s.hooks.provideLexer() : e ? x.lex : x.lexInline)(n, s);
9303
+ s.hooks && (l = s.hooks.processAllTokens(l)), s.walkTokens && this.walkTokens(l, s.walkTokens);
9304
+ let c = (s.hooks ? s.hooks.provideParser() : e ? b.parse : b.parseInline)(l, s);
9305
+ return s.hooks && (c = s.hooks.postprocess(c)), c;
9306
+ } catch (o) {
9307
+ return a(o);
9798
9308
  }
9799
- if (e) {
9800
- let p = "Infinite loop on byte: " + e.charCodeAt(0);
9801
- if (this.options.silent) {
9802
- console.error(p);
9803
- break;
9804
- } else
9805
- throw new Error(p);
9309
+ };
9310
+ }
9311
+ onError(e, t2) {
9312
+ return (n) => {
9313
+ if (n.message += `
9314
+ Please report this to https://github.com/markedjs/marked.`, e) {
9315
+ let r = "<p>An error occurred:</p><pre>" + w(n.message + "", true) + "</pre>";
9316
+ return t2 ? Promise.resolve(r) : r;
9806
9317
  }
9807
- }
9808
- return t2;
9318
+ if (t2)
9319
+ return Promise.reject(n);
9320
+ throw n;
9321
+ };
9809
9322
  }
9810
9323
  };
9811
- var P = class {
9812
- options;
9813
- parser;
9814
- constructor(e) {
9815
- this.options = e || T;
9324
+ var _ = new B;
9325
+ function d(u3, e) {
9326
+ return _.parse(u3, e);
9327
+ }
9328
+ d.options = d.setOptions = function(u3) {
9329
+ return _.setOptions(u3), d.defaults = _.defaults, Z(d.defaults), d;
9330
+ };
9331
+ d.getDefaults = L;
9332
+ d.defaults = T;
9333
+ d.use = function(...u3) {
9334
+ return _.use(...u3), d.defaults = _.defaults, Z(d.defaults), d;
9335
+ };
9336
+ d.walkTokens = function(u3, e) {
9337
+ return _.walkTokens(u3, e);
9338
+ };
9339
+ d.parseInline = _.parseInline;
9340
+ d.Parser = b;
9341
+ d.parser = b.parse;
9342
+ d.Renderer = P;
9343
+ d.TextRenderer = $;
9344
+ d.Lexer = x;
9345
+ d.lexer = x.lex;
9346
+ d.Tokenizer = y;
9347
+ d.Hooks = S;
9348
+ d.parse = d;
9349
+ var Dt = d.options;
9350
+ var Ht = d.setOptions;
9351
+ var Zt = d.use;
9352
+ var Gt = d.walkTokens;
9353
+ var Nt = d.parseInline;
9354
+ var Ft = b.parse;
9355
+ var jt = x.lex;
9356
+
9357
+ // src/renderables/TextTable.ts
9358
+ var MEASURE_HEIGHT = 1e4;
9359
+
9360
+ class TextTableRenderable extends Renderable {
9361
+ _content;
9362
+ _wrapMode;
9363
+ _columnWidthMode;
9364
+ _columnFitter;
9365
+ _cellPadding;
9366
+ _showBorders;
9367
+ _border;
9368
+ _outerBorder;
9369
+ _hasExplicitOuterBorder;
9370
+ _borderStyle;
9371
+ _borderColor;
9372
+ _borderBackgroundColor;
9373
+ _backgroundColor;
9374
+ _defaultFg;
9375
+ _defaultBg;
9376
+ _defaultAttributes;
9377
+ _selectionBg;
9378
+ _selectionFg;
9379
+ _lastLocalSelection = null;
9380
+ _lastSelectionMode = null;
9381
+ _cells = [];
9382
+ _prevCellContent = [];
9383
+ _rowCount = 0;
9384
+ _columnCount = 0;
9385
+ _layout = this.createEmptyLayout();
9386
+ _layoutDirty = true;
9387
+ _rasterDirty = true;
9388
+ _cachedMeasureLayout = null;
9389
+ _cachedMeasureWidth = undefined;
9390
+ _defaultOptions = {
9391
+ content: [],
9392
+ wrapMode: "word",
9393
+ columnWidthMode: "full",
9394
+ columnFitter: "proportional",
9395
+ cellPadding: 0,
9396
+ showBorders: true,
9397
+ border: true,
9398
+ outerBorder: true,
9399
+ selectable: true,
9400
+ selectionBg: undefined,
9401
+ selectionFg: undefined,
9402
+ borderStyle: "single",
9403
+ borderColor: "#FFFFFF",
9404
+ borderBackgroundColor: "transparent",
9405
+ backgroundColor: "transparent",
9406
+ fg: "#FFFFFF",
9407
+ bg: "transparent",
9408
+ attributes: 0
9409
+ };
9410
+ constructor(ctx, options = {}) {
9411
+ super(ctx, { ...options, flexShrink: options.flexShrink ?? 0, buffered: true });
9412
+ this._content = options.content ?? this._defaultOptions.content;
9413
+ this._wrapMode = options.wrapMode ?? this._defaultOptions.wrapMode;
9414
+ this._columnWidthMode = options.columnWidthMode ?? this._defaultOptions.columnWidthMode;
9415
+ this._columnFitter = this.resolveColumnFitter(options.columnFitter);
9416
+ this._cellPadding = this.resolveCellPadding(options.cellPadding);
9417
+ this._showBorders = options.showBorders ?? this._defaultOptions.showBorders;
9418
+ this._border = options.border ?? this._defaultOptions.border;
9419
+ this._hasExplicitOuterBorder = options.outerBorder !== undefined;
9420
+ this._outerBorder = options.outerBorder ?? this._border;
9421
+ this.selectable = options.selectable ?? this._defaultOptions.selectable;
9422
+ this._selectionBg = options.selectionBg ? parseColor(options.selectionBg) : undefined;
9423
+ this._selectionFg = options.selectionFg ? parseColor(options.selectionFg) : undefined;
9424
+ this._borderStyle = parseBorderStyle(options.borderStyle, this._defaultOptions.borderStyle);
9425
+ this._borderColor = parseColor(options.borderColor ?? this._defaultOptions.borderColor);
9426
+ this._borderBackgroundColor = parseColor(options.borderBackgroundColor ?? this._defaultOptions.borderBackgroundColor);
9427
+ this._backgroundColor = parseColor(options.backgroundColor ?? this._defaultOptions.backgroundColor);
9428
+ this._defaultFg = parseColor(options.fg ?? this._defaultOptions.fg);
9429
+ this._defaultBg = parseColor(options.bg ?? this._defaultOptions.bg);
9430
+ this._defaultAttributes = options.attributes ?? this._defaultOptions.attributes;
9431
+ this.setupMeasureFunc();
9432
+ this.rebuildCells();
9816
9433
  }
9817
- space(e) {
9818
- return "";
9434
+ get content() {
9435
+ return this._content;
9819
9436
  }
9820
- code({ text: e, lang: t2, escaped: n }) {
9821
- let r = (t2 || "").match(m.notSpaceStart)?.[0], i = e.replace(m.endingNewline, "") + `
9822
- `;
9823
- return r ? '<pre><code class="language-' + w(r) + '">' + (n ? i : w(i, true)) + `</code></pre>
9824
- ` : "<pre><code>" + (n ? i : w(i, true)) + `</code></pre>
9825
- `;
9437
+ set content(value) {
9438
+ this._content = value ?? [];
9439
+ this.rebuildCells();
9826
9440
  }
9827
- blockquote({ tokens: e }) {
9828
- return `<blockquote>
9829
- ${this.parser.parse(e)}</blockquote>
9830
- `;
9441
+ get wrapMode() {
9442
+ return this._wrapMode;
9831
9443
  }
9832
- html({ text: e }) {
9833
- return e;
9444
+ set wrapMode(value) {
9445
+ if (this._wrapMode === value)
9446
+ return;
9447
+ this._wrapMode = value;
9448
+ for (const row of this._cells) {
9449
+ for (const cell of row) {
9450
+ cell.textBufferView.setWrapMode(value);
9451
+ }
9452
+ }
9453
+ this.invalidateLayoutAndRaster();
9834
9454
  }
9835
- def(e) {
9836
- return "";
9455
+ get columnWidthMode() {
9456
+ return this._columnWidthMode;
9837
9457
  }
9838
- heading({ tokens: e, depth: t2 }) {
9839
- return `<h${t2}>${this.parser.parseInline(e)}</h${t2}>
9840
- `;
9458
+ set columnWidthMode(value) {
9459
+ if (this._columnWidthMode === value)
9460
+ return;
9461
+ this._columnWidthMode = value;
9462
+ this.invalidateLayoutAndRaster();
9841
9463
  }
9842
- hr(e) {
9843
- return `<hr>
9844
- `;
9464
+ get columnFitter() {
9465
+ return this._columnFitter;
9845
9466
  }
9846
- list(e) {
9847
- let { ordered: t2, start: n } = e, r = "";
9848
- for (let a = 0;a < e.items.length; a++) {
9849
- let o = e.items[a];
9850
- r += this.listitem(o);
9851
- }
9852
- let i = t2 ? "ol" : "ul", s = t2 && n !== 1 ? ' start="' + n + '"' : "";
9853
- return "<" + i + s + `>
9854
- ` + r + "</" + i + `>
9855
- `;
9467
+ set columnFitter(value) {
9468
+ const next = this.resolveColumnFitter(value);
9469
+ if (this._columnFitter === next)
9470
+ return;
9471
+ this._columnFitter = next;
9472
+ this.invalidateLayoutAndRaster();
9856
9473
  }
9857
- listitem(e) {
9858
- return `<li>${this.parser.parse(e.tokens)}</li>
9859
- `;
9474
+ get cellPadding() {
9475
+ return this._cellPadding;
9860
9476
  }
9861
- checkbox({ checked: e }) {
9862
- return "<input " + (e ? 'checked="" ' : "") + 'disabled="" type="checkbox"> ';
9477
+ set cellPadding(value) {
9478
+ const next = this.resolveCellPadding(value);
9479
+ if (this._cellPadding === next)
9480
+ return;
9481
+ this._cellPadding = next;
9482
+ this.invalidateLayoutAndRaster();
9863
9483
  }
9864
- paragraph({ tokens: e }) {
9865
- return `<p>${this.parser.parseInline(e)}</p>
9866
- `;
9484
+ get showBorders() {
9485
+ return this._showBorders;
9867
9486
  }
9868
- table(e) {
9869
- let t2 = "", n = "";
9870
- for (let i = 0;i < e.header.length; i++)
9871
- n += this.tablecell(e.header[i]);
9872
- t2 += this.tablerow({ text: n });
9873
- let r = "";
9874
- for (let i = 0;i < e.rows.length; i++) {
9875
- let s = e.rows[i];
9876
- n = "";
9877
- for (let a = 0;a < s.length; a++)
9878
- n += this.tablecell(s[a]);
9879
- r += this.tablerow({ text: n });
9487
+ set showBorders(value) {
9488
+ if (this._showBorders === value)
9489
+ return;
9490
+ this._showBorders = value;
9491
+ this.invalidateRasterOnly();
9492
+ }
9493
+ get outerBorder() {
9494
+ return this._outerBorder;
9495
+ }
9496
+ set outerBorder(value) {
9497
+ if (this._outerBorder === value)
9498
+ return;
9499
+ this._hasExplicitOuterBorder = true;
9500
+ this._outerBorder = value;
9501
+ this.invalidateLayoutAndRaster();
9502
+ }
9503
+ get border() {
9504
+ return this._border;
9505
+ }
9506
+ set border(value) {
9507
+ if (this._border === value)
9508
+ return;
9509
+ this._border = value;
9510
+ if (!this._hasExplicitOuterBorder) {
9511
+ this._outerBorder = value;
9880
9512
  }
9881
- return r && (r = `<tbody>${r}</tbody>`), `<table>
9882
- <thead>
9883
- ` + t2 + `</thead>
9884
- ` + r + `</table>
9885
- `;
9513
+ this.invalidateLayoutAndRaster();
9886
9514
  }
9887
- tablerow({ text: e }) {
9888
- return `<tr>
9889
- ${e}</tr>
9890
- `;
9515
+ get borderStyle() {
9516
+ return this._borderStyle;
9891
9517
  }
9892
- tablecell(e) {
9893
- let t2 = this.parser.parseInline(e.tokens), n = e.header ? "th" : "td";
9894
- return (e.align ? `<${n} align="${e.align}">` : `<${n}>`) + t2 + `</${n}>
9895
- `;
9518
+ set borderStyle(value) {
9519
+ const next = parseBorderStyle(value, this._defaultOptions.borderStyle);
9520
+ if (this._borderStyle === next)
9521
+ return;
9522
+ this._borderStyle = next;
9523
+ this.invalidateRasterOnly();
9896
9524
  }
9897
- strong({ tokens: e }) {
9898
- return `<strong>${this.parser.parseInline(e)}</strong>`;
9525
+ get borderColor() {
9526
+ return this._borderColor;
9899
9527
  }
9900
- em({ tokens: e }) {
9901
- return `<em>${this.parser.parseInline(e)}</em>`;
9528
+ set borderColor(value) {
9529
+ const next = parseColor(value);
9530
+ if (this._borderColor === next)
9531
+ return;
9532
+ this._borderColor = next;
9533
+ this.invalidateRasterOnly();
9902
9534
  }
9903
- codespan({ text: e }) {
9904
- return `<code>${w(e, true)}</code>`;
9535
+ shouldStartSelection(x2, y2) {
9536
+ if (!this.selectable)
9537
+ return false;
9538
+ this.ensureLayoutReady();
9539
+ const localX = x2 - this.x;
9540
+ const localY = y2 - this.y;
9541
+ return this.getCellAtLocalPosition(localX, localY) !== null;
9905
9542
  }
9906
- br(e) {
9907
- return "<br>";
9543
+ onSelectionChanged(selection) {
9544
+ this.ensureLayoutReady();
9545
+ const previousLocalSelection = this._lastLocalSelection;
9546
+ const localSelection = convertGlobalToLocalSelection(selection, this.x, this.y);
9547
+ this._lastLocalSelection = localSelection;
9548
+ const dirtyRows = this.getDirtySelectionRowRange(previousLocalSelection, localSelection);
9549
+ if (!localSelection?.isActive) {
9550
+ this.resetCellSelections();
9551
+ this._lastSelectionMode = null;
9552
+ } else {
9553
+ this.applySelectionToCells(localSelection, selection?.isStart ?? false);
9554
+ }
9555
+ if (dirtyRows !== null) {
9556
+ this.redrawSelectionRows(dirtyRows.firstRow, dirtyRows.lastRow);
9557
+ }
9558
+ return this.hasSelection();
9908
9559
  }
9909
- del({ tokens: e }) {
9910
- return `<del>${this.parser.parseInline(e)}</del>`;
9560
+ hasSelection() {
9561
+ for (const row of this._cells) {
9562
+ for (const cell of row) {
9563
+ if (cell.textBufferView.hasSelection()) {
9564
+ return true;
9565
+ }
9566
+ }
9567
+ }
9568
+ return false;
9911
9569
  }
9912
- link({ href: e, title: t2, tokens: n }) {
9913
- let r = this.parser.parseInline(n), i = X(e);
9914
- if (i === null)
9915
- return r;
9916
- e = i;
9917
- let s = '<a href="' + e + '"';
9918
- return t2 && (s += ' title="' + w(t2) + '"'), s += ">" + r + "</a>", s;
9570
+ getSelection() {
9571
+ for (const row of this._cells) {
9572
+ for (const cell of row) {
9573
+ const selection = cell.textBufferView.getSelection();
9574
+ if (selection) {
9575
+ return selection;
9576
+ }
9577
+ }
9578
+ }
9579
+ return null;
9919
9580
  }
9920
- image({ href: e, title: t2, text: n, tokens: r }) {
9921
- r && (n = this.parser.parseInline(r, this.parser.textRenderer));
9922
- let i = X(e);
9923
- if (i === null)
9924
- return w(n);
9925
- e = i;
9926
- let s = `<img src="${e}" alt="${n}"`;
9927
- return t2 && (s += ` title="${w(t2)}"`), s += ">", s;
9581
+ getSelectedText() {
9582
+ const selectedRows = [];
9583
+ for (let rowIdx = 0;rowIdx < this._rowCount; rowIdx++) {
9584
+ const rowSelections = [];
9585
+ for (let colIdx = 0;colIdx < this._columnCount; colIdx++) {
9586
+ const cell = this._cells[rowIdx]?.[colIdx];
9587
+ if (!cell || !cell.textBufferView.hasSelection())
9588
+ continue;
9589
+ const selectedText = cell.textBufferView.getSelectedText();
9590
+ if (selectedText.length > 0) {
9591
+ rowSelections.push(selectedText);
9592
+ }
9593
+ }
9594
+ if (rowSelections.length > 0) {
9595
+ selectedRows.push(rowSelections.join("\t"));
9596
+ }
9597
+ }
9598
+ return selectedRows.join(`
9599
+ `);
9928
9600
  }
9929
- text(e) {
9930
- return "tokens" in e && e.tokens ? this.parser.parseInline(e.tokens) : ("escaped" in e) && e.escaped ? e.text : w(e.text);
9601
+ onResize(width, height) {
9602
+ this.invalidateLayoutAndRaster(false);
9603
+ super.onResize(width, height);
9931
9604
  }
9932
- };
9933
- var $ = class {
9934
- strong({ text: e }) {
9935
- return e;
9605
+ renderSelf(buffer) {
9606
+ if (!this.visible || this.isDestroyed)
9607
+ return;
9608
+ if (this._layoutDirty) {
9609
+ this.rebuildLayoutForCurrentWidth();
9610
+ }
9611
+ if (!this._rasterDirty)
9612
+ return;
9613
+ buffer.clear(this._backgroundColor);
9614
+ if (this._rowCount === 0 || this._columnCount === 0) {
9615
+ this._rasterDirty = false;
9616
+ return;
9617
+ }
9618
+ this.drawBorders(buffer);
9619
+ this.drawCells(buffer);
9620
+ this._rasterDirty = false;
9936
9621
  }
9937
- em({ text: e }) {
9938
- return e;
9622
+ destroySelf() {
9623
+ this.destroyCells();
9624
+ super.destroySelf();
9625
+ }
9626
+ setupMeasureFunc() {
9627
+ const measureFunc = (width, widthMode, _height, _heightMode) => {
9628
+ const hasWidthConstraint = widthMode !== MeasureMode.Undefined && Number.isFinite(width);
9629
+ const rawWidthConstraint = hasWidthConstraint ? Math.max(1, Math.floor(width)) : undefined;
9630
+ const widthConstraint = this.resolveLayoutWidthConstraint(rawWidthConstraint);
9631
+ const measuredLayout = this.computeLayout(widthConstraint);
9632
+ this._cachedMeasureLayout = measuredLayout;
9633
+ this._cachedMeasureWidth = widthConstraint;
9634
+ let measuredWidth = measuredLayout.tableWidth > 0 ? measuredLayout.tableWidth : 1;
9635
+ let measuredHeight = measuredLayout.tableHeight > 0 ? measuredLayout.tableHeight : 1;
9636
+ if (widthMode === MeasureMode.AtMost && rawWidthConstraint !== undefined && this._positionType !== "absolute") {
9637
+ measuredWidth = Math.min(rawWidthConstraint, measuredWidth);
9638
+ }
9639
+ return {
9640
+ width: measuredWidth,
9641
+ height: measuredHeight
9642
+ };
9643
+ };
9644
+ this.yogaNode.setMeasureFunc(measureFunc);
9645
+ }
9646
+ rebuildCells() {
9647
+ const newRowCount = this._content.length;
9648
+ const newColumnCount = this._content.reduce((max, row) => Math.max(max, row.length), 0);
9649
+ if (this._cells.length === 0) {
9650
+ this._rowCount = newRowCount;
9651
+ this._columnCount = newColumnCount;
9652
+ this._cells = [];
9653
+ this._prevCellContent = [];
9654
+ for (let rowIdx = 0;rowIdx < newRowCount; rowIdx++) {
9655
+ const row = this._content[rowIdx] ?? [];
9656
+ const rowCells = [];
9657
+ const rowRefs = [];
9658
+ for (let colIdx = 0;colIdx < newColumnCount; colIdx++) {
9659
+ const cellContent = row[colIdx];
9660
+ rowCells.push(this.createCell(cellContent));
9661
+ rowRefs.push(cellContent);
9662
+ }
9663
+ this._cells.push(rowCells);
9664
+ this._prevCellContent.push(rowRefs);
9665
+ }
9666
+ this.invalidateLayoutAndRaster();
9667
+ return;
9668
+ }
9669
+ this.updateCellsDiff(newRowCount, newColumnCount);
9670
+ this.invalidateLayoutAndRaster();
9671
+ }
9672
+ updateCellsDiff(newRowCount, newColumnCount) {
9673
+ const oldRowCount = this._rowCount;
9674
+ const oldColumnCount = this._columnCount;
9675
+ const keepRows = Math.min(oldRowCount, newRowCount);
9676
+ const keepCols = Math.min(oldColumnCount, newColumnCount);
9677
+ for (let rowIdx = 0;rowIdx < keepRows; rowIdx++) {
9678
+ const newRow = this._content[rowIdx] ?? [];
9679
+ const cellRow = this._cells[rowIdx];
9680
+ const refRow = this._prevCellContent[rowIdx];
9681
+ for (let colIdx = 0;colIdx < keepCols; colIdx++) {
9682
+ const cellContent = newRow[colIdx];
9683
+ if (cellContent === refRow[colIdx])
9684
+ continue;
9685
+ const oldCell = cellRow[colIdx];
9686
+ oldCell.textBufferView.destroy();
9687
+ oldCell.textBuffer.destroy();
9688
+ oldCell.syntaxStyle.destroy();
9689
+ cellRow[colIdx] = this.createCell(cellContent);
9690
+ refRow[colIdx] = cellContent;
9691
+ }
9692
+ if (newColumnCount > oldColumnCount) {
9693
+ for (let colIdx = oldColumnCount;colIdx < newColumnCount; colIdx++) {
9694
+ const cellContent = newRow[colIdx];
9695
+ cellRow.push(this.createCell(cellContent));
9696
+ refRow.push(cellContent);
9697
+ }
9698
+ } else if (newColumnCount < oldColumnCount) {
9699
+ for (let colIdx = newColumnCount;colIdx < oldColumnCount; colIdx++) {
9700
+ const cell = cellRow[colIdx];
9701
+ cell.textBufferView.destroy();
9702
+ cell.textBuffer.destroy();
9703
+ cell.syntaxStyle.destroy();
9704
+ }
9705
+ cellRow.length = newColumnCount;
9706
+ refRow.length = newColumnCount;
9707
+ }
9708
+ }
9709
+ if (newRowCount > oldRowCount) {
9710
+ for (let rowIdx = oldRowCount;rowIdx < newRowCount; rowIdx++) {
9711
+ const newRow = this._content[rowIdx] ?? [];
9712
+ const rowCells = [];
9713
+ const rowRefs = [];
9714
+ for (let colIdx = 0;colIdx < newColumnCount; colIdx++) {
9715
+ const cellContent = newRow[colIdx];
9716
+ rowCells.push(this.createCell(cellContent));
9717
+ rowRefs.push(cellContent);
9718
+ }
9719
+ this._cells.push(rowCells);
9720
+ this._prevCellContent.push(rowRefs);
9721
+ }
9722
+ } else if (newRowCount < oldRowCount) {
9723
+ for (let rowIdx = newRowCount;rowIdx < oldRowCount; rowIdx++) {
9724
+ const row = this._cells[rowIdx];
9725
+ for (const cell of row) {
9726
+ cell.textBufferView.destroy();
9727
+ cell.textBuffer.destroy();
9728
+ cell.syntaxStyle.destroy();
9729
+ }
9730
+ }
9731
+ this._cells.length = newRowCount;
9732
+ this._prevCellContent.length = newRowCount;
9733
+ }
9734
+ this._rowCount = newRowCount;
9735
+ this._columnCount = newColumnCount;
9939
9736
  }
9940
- codespan({ text: e }) {
9941
- return e;
9737
+ createCell(content) {
9738
+ const styledText = this.toStyledText(content);
9739
+ const textBuffer = TextBuffer.create(this._ctx.widthMethod);
9740
+ const syntaxStyle = SyntaxStyle.create();
9741
+ textBuffer.setDefaultFg(this._defaultFg);
9742
+ textBuffer.setDefaultBg(this._defaultBg);
9743
+ textBuffer.setDefaultAttributes(this._defaultAttributes);
9744
+ textBuffer.setSyntaxStyle(syntaxStyle);
9745
+ textBuffer.setStyledText(styledText);
9746
+ const textBufferView = TextBufferView.create(textBuffer);
9747
+ textBufferView.setWrapMode(this._wrapMode);
9748
+ return { textBuffer, textBufferView, syntaxStyle };
9942
9749
  }
9943
- del({ text: e }) {
9944
- return e;
9750
+ toStyledText(content) {
9751
+ if (Array.isArray(content)) {
9752
+ return new StyledText(content);
9753
+ }
9754
+ if (content === null || content === undefined) {
9755
+ return stringToStyledText("");
9756
+ }
9757
+ return stringToStyledText(String(content));
9945
9758
  }
9946
- html({ text: e }) {
9947
- return e;
9759
+ destroyCells() {
9760
+ for (const row of this._cells) {
9761
+ for (const cell of row) {
9762
+ cell.textBufferView.destroy();
9763
+ cell.textBuffer.destroy();
9764
+ cell.syntaxStyle.destroy();
9765
+ }
9766
+ }
9767
+ this._cells = [];
9768
+ this._prevCellContent = [];
9769
+ this._rowCount = 0;
9770
+ this._columnCount = 0;
9771
+ this._layout = this.createEmptyLayout();
9948
9772
  }
9949
- text({ text: e }) {
9950
- return e;
9773
+ rebuildLayoutForCurrentWidth() {
9774
+ const maxTableWidth = this.resolveLayoutWidthConstraint(this.width);
9775
+ let layout;
9776
+ if (this._cachedMeasureLayout !== null && this._cachedMeasureWidth === maxTableWidth) {
9777
+ layout = this._cachedMeasureLayout;
9778
+ } else {
9779
+ layout = this.computeLayout(maxTableWidth);
9780
+ }
9781
+ this._cachedMeasureLayout = null;
9782
+ this._cachedMeasureWidth = undefined;
9783
+ this._layout = layout;
9784
+ this.applyLayoutToViews(layout);
9785
+ this._layoutDirty = false;
9786
+ if (this._lastLocalSelection?.isActive) {
9787
+ this.applySelectionToCells(this._lastLocalSelection, true);
9788
+ }
9951
9789
  }
9952
- link({ text: e }) {
9953
- return "" + e;
9790
+ computeLayout(maxTableWidth) {
9791
+ if (this._rowCount === 0 || this._columnCount === 0) {
9792
+ return this.createEmptyLayout();
9793
+ }
9794
+ const borderLayout = this.resolveBorderLayout();
9795
+ const columnWidths = this.computeColumnWidths(maxTableWidth, borderLayout);
9796
+ const rowHeights = this.computeRowHeights(columnWidths);
9797
+ const columnOffsets = this.computeOffsets(columnWidths, borderLayout.left, borderLayout.right, borderLayout.innerVertical);
9798
+ const rowOffsets = this.computeOffsets(rowHeights, borderLayout.top, borderLayout.bottom, borderLayout.innerHorizontal);
9799
+ return {
9800
+ columnWidths,
9801
+ rowHeights,
9802
+ columnOffsets,
9803
+ rowOffsets,
9804
+ columnOffsetsI32: new Int32Array(columnOffsets),
9805
+ rowOffsetsI32: new Int32Array(rowOffsets),
9806
+ tableWidth: (columnOffsets[columnOffsets.length - 1] ?? 0) + 1,
9807
+ tableHeight: (rowOffsets[rowOffsets.length - 1] ?? 0) + 1
9808
+ };
9954
9809
  }
9955
- image({ text: e }) {
9956
- return "" + e;
9810
+ isFullWidthMode() {
9811
+ return this._columnWidthMode === "full";
9957
9812
  }
9958
- br() {
9959
- return "";
9813
+ computeColumnWidths(maxTableWidth, borderLayout) {
9814
+ const horizontalPadding = this.getHorizontalCellPadding();
9815
+ const intrinsicWidths = new Array(this._columnCount).fill(1 + horizontalPadding);
9816
+ for (let rowIdx = 0;rowIdx < this._rowCount; rowIdx++) {
9817
+ for (let colIdx = 0;colIdx < this._columnCount; colIdx++) {
9818
+ const cell = this._cells[rowIdx]?.[colIdx];
9819
+ if (!cell)
9820
+ continue;
9821
+ const measure = cell.textBufferView.measureForDimensions(0, MEASURE_HEIGHT);
9822
+ const measuredWidth = Math.max(1, measure?.widthColsMax ?? 0) + horizontalPadding;
9823
+ intrinsicWidths[colIdx] = Math.max(intrinsicWidths[colIdx], measuredWidth);
9824
+ }
9825
+ }
9826
+ if (maxTableWidth === undefined || !Number.isFinite(maxTableWidth) || maxTableWidth <= 0) {
9827
+ return intrinsicWidths;
9828
+ }
9829
+ const maxContentWidth = Math.max(1, Math.floor(maxTableWidth) - this.getVerticalBorderCount(borderLayout));
9830
+ const currentWidth = intrinsicWidths.reduce((sum, width) => sum + width, 0);
9831
+ if (currentWidth === maxContentWidth) {
9832
+ return intrinsicWidths;
9833
+ }
9834
+ if (currentWidth < maxContentWidth) {
9835
+ if (this.isFullWidthMode()) {
9836
+ return this.expandColumnWidths(intrinsicWidths, maxContentWidth);
9837
+ }
9838
+ return intrinsicWidths;
9839
+ }
9840
+ if (this._wrapMode === "none") {
9841
+ return intrinsicWidths;
9842
+ }
9843
+ return this.fitColumnWidths(intrinsicWidths, maxContentWidth);
9960
9844
  }
9961
- checkbox({ raw: e }) {
9962
- return e;
9845
+ expandColumnWidths(widths, targetContentWidth) {
9846
+ const baseWidths = widths.map((width) => Math.max(1, Math.floor(width)));
9847
+ const totalBaseWidth = baseWidths.reduce((sum, width) => sum + width, 0);
9848
+ if (totalBaseWidth >= targetContentWidth) {
9849
+ return baseWidths;
9850
+ }
9851
+ const expanded = [...baseWidths];
9852
+ const columns = expanded.length;
9853
+ const extraWidth = targetContentWidth - totalBaseWidth;
9854
+ const sharedWidth = Math.floor(extraWidth / columns);
9855
+ const remainder = extraWidth % columns;
9856
+ for (let idx = 0;idx < columns; idx++) {
9857
+ expanded[idx] += sharedWidth;
9858
+ if (idx < remainder) {
9859
+ expanded[idx] += 1;
9860
+ }
9861
+ }
9862
+ return expanded;
9963
9863
  }
9964
- };
9965
- var b = class u2 {
9966
- options;
9967
- renderer;
9968
- textRenderer;
9969
- constructor(e) {
9970
- 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 $;
9864
+ fitColumnWidths(widths, targetContentWidth) {
9865
+ if (this._columnFitter === "balanced") {
9866
+ return this.fitColumnWidthsBalanced(widths, targetContentWidth);
9867
+ }
9868
+ return this.fitColumnWidthsProportional(widths, targetContentWidth);
9971
9869
  }
9972
- static parse(e, t2) {
9973
- return new u2(t2).parse(e);
9870
+ fitColumnWidthsProportional(widths, targetContentWidth) {
9871
+ const minWidth = 1 + this.getHorizontalCellPadding();
9872
+ const hardMinWidths = new Array(widths.length).fill(minWidth);
9873
+ const baseWidths = widths.map((width) => Math.max(1, Math.floor(width)));
9874
+ const preferredMinWidths = baseWidths.map((width) => Math.min(width, minWidth + 1));
9875
+ const preferredMinTotal = preferredMinWidths.reduce((sum, width) => sum + width, 0);
9876
+ const floorWidths = preferredMinTotal <= targetContentWidth ? preferredMinWidths : hardMinWidths;
9877
+ const floorTotal = floorWidths.reduce((sum, width) => sum + width, 0);
9878
+ const clampedTarget = Math.max(floorTotal, targetContentWidth);
9879
+ const totalBaseWidth = baseWidths.reduce((sum, width) => sum + width, 0);
9880
+ if (totalBaseWidth <= clampedTarget) {
9881
+ return baseWidths;
9882
+ }
9883
+ const shrinkable = baseWidths.map((width, idx) => width - floorWidths[idx]);
9884
+ const totalShrinkable = shrinkable.reduce((sum, value) => sum + value, 0);
9885
+ if (totalShrinkable <= 0) {
9886
+ return [...floorWidths];
9887
+ }
9888
+ const targetShrink = totalBaseWidth - clampedTarget;
9889
+ const integerShrink = new Array(baseWidths.length).fill(0);
9890
+ const fractions = new Array(baseWidths.length).fill(0);
9891
+ let usedShrink = 0;
9892
+ for (let idx = 0;idx < baseWidths.length; idx++) {
9893
+ if (shrinkable[idx] <= 0)
9894
+ continue;
9895
+ const exact = shrinkable[idx] / totalShrinkable * targetShrink;
9896
+ const whole = Math.min(shrinkable[idx], Math.floor(exact));
9897
+ integerShrink[idx] = whole;
9898
+ fractions[idx] = exact - whole;
9899
+ usedShrink += whole;
9900
+ }
9901
+ let remainingShrink = targetShrink - usedShrink;
9902
+ while (remainingShrink > 0) {
9903
+ let bestIdx = -1;
9904
+ let bestFraction = -1;
9905
+ for (let idx = 0;idx < baseWidths.length; idx++) {
9906
+ if (shrinkable[idx] - integerShrink[idx] <= 0)
9907
+ continue;
9908
+ if (fractions[idx] > bestFraction) {
9909
+ bestFraction = fractions[idx];
9910
+ bestIdx = idx;
9911
+ }
9912
+ }
9913
+ if (bestIdx === -1)
9914
+ break;
9915
+ integerShrink[bestIdx] += 1;
9916
+ fractions[bestIdx] = 0;
9917
+ remainingShrink -= 1;
9918
+ }
9919
+ return baseWidths.map((width, idx) => Math.max(floorWidths[idx], width - integerShrink[idx]));
9974
9920
  }
9975
- static parseInline(e, t2) {
9976
- return new u2(t2).parseInline(e);
9921
+ fitColumnWidthsBalanced(widths, targetContentWidth) {
9922
+ const minWidth = 1 + this.getHorizontalCellPadding();
9923
+ const hardMinWidths = new Array(widths.length).fill(minWidth);
9924
+ const baseWidths = widths.map((width) => Math.max(1, Math.floor(width)));
9925
+ const totalBaseWidth = baseWidths.reduce((sum, width) => sum + width, 0);
9926
+ const columns = baseWidths.length;
9927
+ if (columns === 0 || totalBaseWidth <= targetContentWidth) {
9928
+ return baseWidths;
9929
+ }
9930
+ const evenShare = Math.max(minWidth, Math.floor(targetContentWidth / columns));
9931
+ const preferredMinWidths = baseWidths.map((width) => Math.min(width, evenShare));
9932
+ const preferredMinTotal = preferredMinWidths.reduce((sum, width) => sum + width, 0);
9933
+ const floorWidths = preferredMinTotal <= targetContentWidth ? preferredMinWidths : hardMinWidths;
9934
+ const floorTotal = floorWidths.reduce((sum, width) => sum + width, 0);
9935
+ const clampedTarget = Math.max(floorTotal, targetContentWidth);
9936
+ if (totalBaseWidth <= clampedTarget) {
9937
+ return baseWidths;
9938
+ }
9939
+ const shrinkable = baseWidths.map((width, idx) => width - floorWidths[idx]);
9940
+ const totalShrinkable = shrinkable.reduce((sum, value) => sum + value, 0);
9941
+ if (totalShrinkable <= 0) {
9942
+ return [...floorWidths];
9943
+ }
9944
+ const targetShrink = totalBaseWidth - clampedTarget;
9945
+ const shrink = this.allocateShrinkByWeight(shrinkable, targetShrink, "sqrt");
9946
+ return baseWidths.map((width, idx) => Math.max(floorWidths[idx], width - shrink[idx]));
9977
9947
  }
9978
- parse(e) {
9979
- let t2 = "";
9980
- for (let n = 0;n < e.length; n++) {
9981
- let r = e[n];
9982
- if (this.options.extensions?.renderers?.[r.type]) {
9983
- let s = r, a = this.options.extensions.renderers[s.type].call({ parser: this }, s);
9984
- if (a !== false || !["space", "hr", "heading", "code", "table", "blockquote", "list", "html", "def", "paragraph", "text"].includes(s.type)) {
9985
- t2 += a || "";
9948
+ allocateShrinkByWeight(shrinkable, targetShrink, mode) {
9949
+ const shrink = new Array(shrinkable.length).fill(0);
9950
+ if (targetShrink <= 0) {
9951
+ return shrink;
9952
+ }
9953
+ const weights = shrinkable.map((value) => {
9954
+ if (value <= 0) {
9955
+ return 0;
9956
+ }
9957
+ return mode === "sqrt" ? Math.sqrt(value) : value;
9958
+ });
9959
+ const totalWeight = weights.reduce((sum, value) => sum + value, 0);
9960
+ if (totalWeight <= 0) {
9961
+ return shrink;
9962
+ }
9963
+ const fractions = new Array(shrinkable.length).fill(0);
9964
+ let usedShrink = 0;
9965
+ for (let idx = 0;idx < shrinkable.length; idx++) {
9966
+ if (shrinkable[idx] <= 0 || weights[idx] <= 0)
9967
+ continue;
9968
+ const exact = weights[idx] / totalWeight * targetShrink;
9969
+ const whole = Math.min(shrinkable[idx], Math.floor(exact));
9970
+ shrink[idx] = whole;
9971
+ fractions[idx] = exact - whole;
9972
+ usedShrink += whole;
9973
+ }
9974
+ let remainingShrink = targetShrink - usedShrink;
9975
+ while (remainingShrink > 0) {
9976
+ let bestIdx = -1;
9977
+ let bestFraction = -1;
9978
+ for (let idx = 0;idx < shrinkable.length; idx++) {
9979
+ if (shrinkable[idx] - shrink[idx] <= 0)
9986
9980
  continue;
9981
+ if (bestIdx === -1 || fractions[idx] > bestFraction || fractions[idx] === bestFraction && shrinkable[idx] > shrinkable[bestIdx]) {
9982
+ bestIdx = idx;
9983
+ bestFraction = fractions[idx];
9987
9984
  }
9988
9985
  }
9989
- let i = r;
9990
- switch (i.type) {
9991
- case "space": {
9992
- t2 += this.renderer.space(i);
9993
- break;
9994
- }
9995
- case "hr": {
9996
- t2 += this.renderer.hr(i);
9997
- break;
9998
- }
9999
- case "heading": {
10000
- t2 += this.renderer.heading(i);
10001
- break;
10002
- }
10003
- case "code": {
10004
- t2 += this.renderer.code(i);
10005
- break;
10006
- }
10007
- case "table": {
10008
- t2 += this.renderer.table(i);
10009
- break;
10010
- }
10011
- case "blockquote": {
10012
- t2 += this.renderer.blockquote(i);
10013
- break;
10014
- }
10015
- case "list": {
10016
- t2 += this.renderer.list(i);
10017
- break;
10018
- }
10019
- case "checkbox": {
10020
- t2 += this.renderer.checkbox(i);
10021
- break;
10022
- }
10023
- case "html": {
10024
- t2 += this.renderer.html(i);
10025
- break;
10026
- }
10027
- case "def": {
10028
- t2 += this.renderer.def(i);
10029
- break;
10030
- }
10031
- case "paragraph": {
10032
- t2 += this.renderer.paragraph(i);
10033
- break;
10034
- }
10035
- case "text": {
10036
- t2 += this.renderer.text(i);
10037
- break;
10038
- }
10039
- default: {
10040
- let s = 'Token with "' + i.type + '" type was not found.';
10041
- if (this.options.silent)
10042
- return console.error(s), "";
10043
- throw new Error(s);
10044
- }
9986
+ if (bestIdx === -1) {
9987
+ break;
10045
9988
  }
9989
+ shrink[bestIdx] += 1;
9990
+ fractions[bestIdx] = 0;
9991
+ remainingShrink -= 1;
10046
9992
  }
10047
- return t2;
9993
+ return shrink;
10048
9994
  }
10049
- parseInline(e, t2 = this.renderer) {
10050
- let n = "";
10051
- for (let r = 0;r < e.length; r++) {
10052
- let i = e[r];
10053
- if (this.options.extensions?.renderers?.[i.type]) {
10054
- let a = this.options.extensions.renderers[i.type].call({ parser: this }, i);
10055
- if (a !== false || !["escape", "html", "link", "image", "strong", "em", "codespan", "br", "del", "text"].includes(i.type)) {
10056
- n += a || "";
9995
+ computeRowHeights(columnWidths) {
9996
+ const horizontalPadding = this.getHorizontalCellPadding();
9997
+ const verticalPadding = this.getVerticalCellPadding();
9998
+ const rowHeights = new Array(this._rowCount).fill(1 + verticalPadding);
9999
+ for (let rowIdx = 0;rowIdx < this._rowCount; rowIdx++) {
10000
+ for (let colIdx = 0;colIdx < this._columnCount; colIdx++) {
10001
+ const cell = this._cells[rowIdx]?.[colIdx];
10002
+ if (!cell)
10057
10003
  continue;
10058
- }
10004
+ const width = Math.max(1, (columnWidths[colIdx] ?? 1) - horizontalPadding);
10005
+ const measure = cell.textBufferView.measureForDimensions(width, MEASURE_HEIGHT);
10006
+ const lineCount = Math.max(1, measure?.lineCount ?? 1);
10007
+ rowHeights[rowIdx] = Math.max(rowHeights[rowIdx], lineCount + verticalPadding);
10059
10008
  }
10060
- let s = i;
10061
- switch (s.type) {
10062
- case "escape": {
10063
- n += t2.text(s);
10064
- break;
10065
- }
10066
- case "html": {
10067
- n += t2.html(s);
10068
- break;
10069
- }
10070
- case "link": {
10071
- n += t2.link(s);
10072
- break;
10073
- }
10074
- case "image": {
10075
- n += t2.image(s);
10076
- break;
10077
- }
10078
- case "checkbox": {
10079
- n += t2.checkbox(s);
10080
- break;
10081
- }
10082
- case "strong": {
10083
- n += t2.strong(s);
10084
- break;
10085
- }
10086
- case "em": {
10087
- n += t2.em(s);
10088
- break;
10089
- }
10090
- case "codespan": {
10091
- n += t2.codespan(s);
10092
- break;
10093
- }
10094
- case "br": {
10095
- n += t2.br(s);
10096
- break;
10097
- }
10098
- case "del": {
10099
- n += t2.del(s);
10100
- break;
10101
- }
10102
- case "text": {
10103
- n += t2.text(s);
10104
- break;
10105
- }
10106
- default: {
10107
- let a = 'Token with "' + s.type + '" type was not found.';
10108
- if (this.options.silent)
10109
- return console.error(a), "";
10110
- throw new Error(a);
10009
+ }
10010
+ return rowHeights;
10011
+ }
10012
+ computeOffsets(parts, startBoundary, endBoundary, includeInnerBoundaries) {
10013
+ const offsets = [startBoundary ? 0 : -1];
10014
+ let cursor = offsets[0] ?? 0;
10015
+ for (let idx = 0;idx < parts.length; idx++) {
10016
+ const size = parts[idx] ?? 1;
10017
+ const hasBoundaryAfter = idx < parts.length - 1 ? includeInnerBoundaries : endBoundary;
10018
+ cursor += size + (hasBoundaryAfter ? 1 : 0);
10019
+ offsets.push(cursor);
10020
+ }
10021
+ return offsets;
10022
+ }
10023
+ applyLayoutToViews(layout) {
10024
+ const horizontalPadding = this.getHorizontalCellPadding();
10025
+ const verticalPadding = this.getVerticalCellPadding();
10026
+ for (let rowIdx = 0;rowIdx < this._rowCount; rowIdx++) {
10027
+ for (let colIdx = 0;colIdx < this._columnCount; colIdx++) {
10028
+ const cell = this._cells[rowIdx]?.[colIdx];
10029
+ if (!cell)
10030
+ continue;
10031
+ const colWidth = layout.columnWidths[colIdx] ?? 1;
10032
+ const rowHeight = layout.rowHeights[rowIdx] ?? 1;
10033
+ const contentWidth = Math.max(1, colWidth - horizontalPadding);
10034
+ const contentHeight = Math.max(1, rowHeight - verticalPadding);
10035
+ if (this._wrapMode === "none") {
10036
+ cell.textBufferView.setWrapWidth(null);
10037
+ } else {
10038
+ cell.textBufferView.setWrapWidth(contentWidth);
10111
10039
  }
10040
+ cell.textBufferView.setViewport(0, 0, contentWidth, contentHeight);
10112
10041
  }
10113
10042
  }
10114
- return n;
10115
10043
  }
10116
- };
10117
- var S = class {
10118
- options;
10119
- block;
10120
- constructor(e) {
10121
- this.options = e || T;
10044
+ resolveBorderLayout() {
10045
+ return {
10046
+ left: this._outerBorder,
10047
+ right: this._outerBorder,
10048
+ top: this._outerBorder,
10049
+ bottom: this._outerBorder,
10050
+ innerVertical: this._border && this._columnCount > 1,
10051
+ innerHorizontal: this._border && this._rowCount > 1
10052
+ };
10122
10053
  }
10123
- static passThroughHooks = new Set(["preprocess", "postprocess", "processAllTokens", "emStrongMask"]);
10124
- static passThroughHooksRespectAsync = new Set(["preprocess", "postprocess", "processAllTokens"]);
10125
- preprocess(e) {
10126
- return e;
10054
+ getVerticalBorderCount(borderLayout) {
10055
+ return (borderLayout.left ? 1 : 0) + (borderLayout.right ? 1 : 0) + (borderLayout.innerVertical ? Math.max(0, this._columnCount - 1) : 0);
10127
10056
  }
10128
- postprocess(e) {
10129
- return e;
10057
+ getHorizontalBorderCount(borderLayout) {
10058
+ return (borderLayout.top ? 1 : 0) + (borderLayout.bottom ? 1 : 0) + (borderLayout.innerHorizontal ? Math.max(0, this._rowCount - 1) : 0);
10130
10059
  }
10131
- processAllTokens(e) {
10132
- return e;
10060
+ drawBorders(buffer) {
10061
+ if (!this._showBorders) {
10062
+ return;
10063
+ }
10064
+ const borderLayout = this.resolveBorderLayout();
10065
+ if (this.getVerticalBorderCount(borderLayout) === 0 && this.getHorizontalBorderCount(borderLayout) === 0) {
10066
+ return;
10067
+ }
10068
+ buffer.drawGrid({
10069
+ borderChars: BorderCharArrays[this._borderStyle],
10070
+ borderFg: this._borderColor,
10071
+ borderBg: this._borderBackgroundColor,
10072
+ columnOffsets: this._layout.columnOffsetsI32,
10073
+ rowOffsets: this._layout.rowOffsetsI32,
10074
+ drawInner: this._border,
10075
+ drawOuter: this._outerBorder
10076
+ });
10133
10077
  }
10134
- emStrongMask(e) {
10135
- return e;
10078
+ drawCells(buffer) {
10079
+ this.drawCellRange(buffer, 0, this._rowCount - 1);
10136
10080
  }
10137
- provideLexer() {
10138
- return this.block ? x.lex : x.lexInline;
10081
+ drawCellRange(buffer, firstRow, lastRow) {
10082
+ const colOffsets = this._layout.columnOffsets;
10083
+ const rowOffsets = this._layout.rowOffsets;
10084
+ const cellPadding = this._cellPadding;
10085
+ for (let rowIdx = firstRow;rowIdx <= lastRow; rowIdx++) {
10086
+ const cellY = (rowOffsets[rowIdx] ?? 0) + 1 + cellPadding;
10087
+ for (let colIdx = 0;colIdx < this._columnCount; colIdx++) {
10088
+ const cell = this._cells[rowIdx]?.[colIdx];
10089
+ if (!cell)
10090
+ continue;
10091
+ buffer.drawTextBuffer(cell.textBufferView, (colOffsets[colIdx] ?? 0) + 1 + cellPadding, cellY);
10092
+ }
10093
+ }
10094
+ }
10095
+ redrawSelectionRows(firstRow, lastRow) {
10096
+ if (firstRow > lastRow)
10097
+ return;
10098
+ if (this._backgroundColor.a < 1) {
10099
+ this.invalidateRasterOnly();
10100
+ return;
10101
+ }
10102
+ const buffer = this.frameBuffer;
10103
+ if (!buffer)
10104
+ return;
10105
+ this.clearCellRange(buffer, firstRow, lastRow);
10106
+ this.drawCellRange(buffer, firstRow, lastRow);
10107
+ this.requestRender();
10139
10108
  }
10140
- provideParser() {
10141
- return this.block ? b.parse : b.parseInline;
10109
+ clearCellRange(buffer, firstRow, lastRow) {
10110
+ const colWidths = this._layout.columnWidths;
10111
+ const rowHeights = this._layout.rowHeights;
10112
+ const colOffsets = this._layout.columnOffsets;
10113
+ const rowOffsets = this._layout.rowOffsets;
10114
+ for (let rowIdx = firstRow;rowIdx <= lastRow; rowIdx++) {
10115
+ const cellY = (rowOffsets[rowIdx] ?? 0) + 1;
10116
+ const rowHeight = rowHeights[rowIdx] ?? 1;
10117
+ for (let colIdx = 0;colIdx < this._columnCount; colIdx++) {
10118
+ const cellX = (colOffsets[colIdx] ?? 0) + 1;
10119
+ const colWidth = colWidths[colIdx] ?? 1;
10120
+ buffer.fillRect(cellX, cellY, colWidth, rowHeight, this._backgroundColor);
10121
+ }
10122
+ }
10142
10123
  }
10143
- };
10144
- var B = class {
10145
- defaults = L();
10146
- options = this.setOptions;
10147
- parse = this.parseMarkdown(true);
10148
- parseInline = this.parseMarkdown(false);
10149
- Parser = b;
10150
- Renderer = P;
10151
- TextRenderer = $;
10152
- Lexer = x;
10153
- Tokenizer = y;
10154
- Hooks = S;
10155
- constructor(...e) {
10156
- this.use(...e);
10124
+ ensureLayoutReady() {
10125
+ if (!this._layoutDirty)
10126
+ return;
10127
+ this.rebuildLayoutForCurrentWidth();
10157
10128
  }
10158
- walkTokens(e, t2) {
10159
- let n = [];
10160
- for (let r of e)
10161
- switch (n = n.concat(t2.call(this, r)), r.type) {
10162
- case "table": {
10163
- let i = r;
10164
- for (let s of i.header)
10165
- n = n.concat(this.walkTokens(s.tokens, t2));
10166
- for (let s of i.rows)
10167
- for (let a of s)
10168
- n = n.concat(this.walkTokens(a.tokens, t2));
10169
- break;
10170
- }
10171
- case "list": {
10172
- let i = r;
10173
- n = n.concat(this.walkTokens(i.items, t2));
10174
- break;
10175
- }
10176
- default: {
10177
- let i = r;
10178
- this.defaults.extensions?.childTokens?.[i.type] ? this.defaults.extensions.childTokens[i.type].forEach((s) => {
10179
- let a = i[s].flat(1 / 0);
10180
- n = n.concat(this.walkTokens(a, t2));
10181
- }) : i.tokens && (n = n.concat(this.walkTokens(i.tokens, t2)));
10182
- }
10129
+ getCellAtLocalPosition(localX, localY) {
10130
+ if (this._rowCount === 0 || this._columnCount === 0)
10131
+ return null;
10132
+ if (localX < 0 || localY < 0 || localX >= this._layout.tableWidth || localY >= this._layout.tableHeight) {
10133
+ return null;
10134
+ }
10135
+ let rowIdx = -1;
10136
+ for (let idx = 0;idx < this._rowCount; idx++) {
10137
+ const top = (this._layout.rowOffsets[idx] ?? 0) + 1;
10138
+ const bottom = top + (this._layout.rowHeights[idx] ?? 1) - 1;
10139
+ if (localY >= top && localY <= bottom) {
10140
+ rowIdx = idx;
10141
+ break;
10183
10142
  }
10184
- return n;
10143
+ }
10144
+ if (rowIdx < 0)
10145
+ return null;
10146
+ let colIdx = -1;
10147
+ for (let idx = 0;idx < this._columnCount; idx++) {
10148
+ const left = (this._layout.columnOffsets[idx] ?? 0) + 1;
10149
+ const right = left + (this._layout.columnWidths[idx] ?? 1) - 1;
10150
+ if (localX >= left && localX <= right) {
10151
+ colIdx = idx;
10152
+ break;
10153
+ }
10154
+ }
10155
+ if (colIdx < 0)
10156
+ return null;
10157
+ return { rowIdx, colIdx };
10185
10158
  }
10186
- use(...e) {
10187
- let t2 = this.defaults.extensions || { renderers: {}, childTokens: {} };
10188
- return e.forEach((n) => {
10189
- let r = { ...n };
10190
- if (r.async = this.defaults.async || r.async || false, n.extensions && (n.extensions.forEach((i) => {
10191
- if (!i.name)
10192
- throw new Error("extension name required");
10193
- if ("renderer" in i) {
10194
- let s = t2.renderers[i.name];
10195
- s ? t2.renderers[i.name] = function(...a) {
10196
- let o = i.renderer.apply(this, a);
10197
- return o === false && (o = s.apply(this, a)), o;
10198
- } : t2.renderers[i.name] = i.renderer;
10199
- }
10200
- if ("tokenizer" in i) {
10201
- if (!i.level || i.level !== "block" && i.level !== "inline")
10202
- throw new Error("extension level must be 'block' or 'inline'");
10203
- let s = t2[i.level];
10204
- 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]));
10205
- }
10206
- "childTokens" in i && i.childTokens && (t2.childTokens[i.name] = i.childTokens);
10207
- }), r.extensions = t2), n.renderer) {
10208
- let i = this.defaults.renderer || new P(this.defaults);
10209
- for (let s in n.renderer) {
10210
- if (!(s in i))
10211
- throw new Error(`renderer '${s}' does not exist`);
10212
- if (["options", "parser"].includes(s))
10213
- continue;
10214
- let a = s, o = n.renderer[a], l = i[a];
10215
- i[a] = (...p) => {
10216
- let c = o.apply(i, p);
10217
- return c === false && (c = l.apply(i, p)), c || "";
10218
- };
10219
- }
10220
- r.renderer = i;
10159
+ applySelectionToCells(localSelection, isStart) {
10160
+ const minSelY = Math.min(localSelection.anchorY, localSelection.focusY);
10161
+ const maxSelY = Math.max(localSelection.anchorY, localSelection.focusY);
10162
+ const firstRow = this.findRowForLocalY(minSelY);
10163
+ const lastRow = this.findRowForLocalY(maxSelY);
10164
+ const selection = this.resolveSelectionResolution(localSelection);
10165
+ const modeChanged = this._lastSelectionMode !== selection.mode;
10166
+ this._lastSelectionMode = selection.mode;
10167
+ const lockToAnchorColumn = selection.mode === "column-locked" && selection.anchorColumn !== null;
10168
+ for (let rowIdx = 0;rowIdx < this._rowCount; rowIdx++) {
10169
+ if (rowIdx < firstRow || rowIdx > lastRow) {
10170
+ this.resetRowSelection(rowIdx);
10171
+ continue;
10221
10172
  }
10222
- if (n.tokenizer) {
10223
- let i = this.defaults.tokenizer || new y(this.defaults);
10224
- for (let s in n.tokenizer) {
10225
- if (!(s in i))
10226
- throw new Error(`tokenizer '${s}' does not exist`);
10227
- if (["options", "rules", "lexer"].includes(s))
10228
- continue;
10229
- let a = s, o = n.tokenizer[a], l = i[a];
10230
- i[a] = (...p) => {
10231
- let c = o.apply(i, p);
10232
- return c === false && (c = l.apply(i, p)), c;
10233
- };
10173
+ const cellTop = (this._layout.rowOffsets[rowIdx] ?? 0) + 1 + this._cellPadding;
10174
+ for (let colIdx = 0;colIdx < this._columnCount; colIdx++) {
10175
+ const cell = this._cells[rowIdx]?.[colIdx];
10176
+ if (!cell)
10177
+ continue;
10178
+ if (lockToAnchorColumn && colIdx !== selection.anchorColumn) {
10179
+ cell.textBufferView.resetLocalSelection();
10180
+ continue;
10234
10181
  }
10235
- r.tokenizer = i;
10236
- }
10237
- if (n.hooks) {
10238
- let i = this.defaults.hooks || new S;
10239
- for (let s in n.hooks) {
10240
- if (!(s in i))
10241
- throw new Error(`hook '${s}' does not exist`);
10242
- if (["options", "block"].includes(s))
10243
- continue;
10244
- let a = s, o = n.hooks[a], l = i[a];
10245
- S.passThroughHooks.has(s) ? i[a] = (p) => {
10246
- if (this.defaults.async && S.passThroughHooksRespectAsync.has(s))
10247
- return (async () => {
10248
- let g = await o.call(i, p);
10249
- return l.call(i, g);
10250
- })();
10251
- let c = o.call(i, p);
10252
- return l.call(i, c);
10253
- } : i[a] = (...p) => {
10254
- if (this.defaults.async)
10255
- return (async () => {
10256
- let g = await o.apply(i, p);
10257
- return g === false && (g = await l.apply(i, p)), g;
10258
- })();
10259
- let c = o.apply(i, p);
10260
- return c === false && (c = l.apply(i, p)), c;
10261
- };
10182
+ const cellLeft = (this._layout.columnOffsets[colIdx] ?? 0) + 1 + this._cellPadding;
10183
+ let coords = {
10184
+ anchorX: localSelection.anchorX - cellLeft,
10185
+ anchorY: localSelection.anchorY - cellTop,
10186
+ focusX: localSelection.focusX - cellLeft,
10187
+ focusY: localSelection.focusY - cellTop
10188
+ };
10189
+ const isAnchorCell = selection.anchorCell !== null && selection.anchorCell.rowIdx === rowIdx && selection.anchorCell.colIdx === colIdx;
10190
+ const forceSet = isAnchorCell && selection.mode !== "single-cell";
10191
+ if (forceSet) {
10192
+ coords = this.getFullCellSelectionCoords(rowIdx, colIdx);
10193
+ }
10194
+ const shouldUseSet = isStart || modeChanged || forceSet;
10195
+ if (shouldUseSet) {
10196
+ cell.textBufferView.setLocalSelection(coords.anchorX, coords.anchorY, coords.focusX, coords.focusY, this._selectionBg, this._selectionFg);
10197
+ } else {
10198
+ cell.textBufferView.updateLocalSelection(coords.anchorX, coords.anchorY, coords.focusX, coords.focusY, this._selectionBg, this._selectionFg);
10262
10199
  }
10263
- r.hooks = i;
10264
10200
  }
10265
- if (n.walkTokens) {
10266
- let i = this.defaults.walkTokens, s = n.walkTokens;
10267
- r.walkTokens = function(a) {
10268
- let o = [];
10269
- return o.push(s.call(this, a)), i && (o = o.concat(i.call(this, a))), o;
10270
- };
10201
+ }
10202
+ }
10203
+ resolveSelectionResolution(localSelection) {
10204
+ const anchorCell = this.getCellAtLocalPosition(localSelection.anchorX, localSelection.anchorY);
10205
+ const focusCell = this.getCellAtLocalPosition(localSelection.focusX, localSelection.focusY);
10206
+ const anchorColumn = anchorCell?.colIdx ?? this.getColumnAtLocalX(localSelection.anchorX);
10207
+ if (anchorCell !== null && focusCell !== null && anchorCell.rowIdx === focusCell.rowIdx && anchorCell.colIdx === focusCell.colIdx) {
10208
+ return {
10209
+ mode: "single-cell",
10210
+ anchorCell,
10211
+ anchorColumn
10212
+ };
10213
+ }
10214
+ const focusColumn = this.getColumnAtLocalX(localSelection.focusX);
10215
+ if (anchorColumn !== null && focusColumn === anchorColumn) {
10216
+ return {
10217
+ mode: "column-locked",
10218
+ anchorCell,
10219
+ anchorColumn
10220
+ };
10221
+ }
10222
+ return {
10223
+ mode: "grid",
10224
+ anchorCell,
10225
+ anchorColumn
10226
+ };
10227
+ }
10228
+ getColumnAtLocalX(localX) {
10229
+ if (this._columnCount === 0)
10230
+ return null;
10231
+ if (localX < 0 || localX >= this._layout.tableWidth)
10232
+ return null;
10233
+ for (let colIdx = 0;colIdx < this._columnCount; colIdx++) {
10234
+ const colStart = (this._layout.columnOffsets[colIdx] ?? 0) + 1;
10235
+ const colEnd = colStart + (this._layout.columnWidths[colIdx] ?? 1) - 1;
10236
+ if (localX >= colStart && localX <= colEnd) {
10237
+ return colIdx;
10271
10238
  }
10272
- this.defaults = { ...this.defaults, ...r };
10273
- }), this;
10239
+ }
10240
+ return null;
10274
10241
  }
10275
- setOptions(e) {
10276
- return this.defaults = { ...this.defaults, ...e }, this;
10242
+ getFullCellSelectionCoords(rowIdx, colIdx) {
10243
+ const colWidth = this._layout.columnWidths[colIdx] ?? 1;
10244
+ const rowHeight = this._layout.rowHeights[rowIdx] ?? 1;
10245
+ const contentWidth = Math.max(1, colWidth - this.getHorizontalCellPadding());
10246
+ const contentHeight = Math.max(1, rowHeight - this.getVerticalCellPadding());
10247
+ return {
10248
+ anchorX: -1,
10249
+ anchorY: 0,
10250
+ focusX: contentWidth,
10251
+ focusY: contentHeight
10252
+ };
10277
10253
  }
10278
- lexer(e, t2) {
10279
- return x.lex(e, t2 ?? this.defaults);
10254
+ findRowForLocalY(localY) {
10255
+ if (this._rowCount === 0)
10256
+ return 0;
10257
+ if (localY < 0)
10258
+ return 0;
10259
+ for (let rowIdx = 0;rowIdx < this._rowCount; rowIdx++) {
10260
+ const rowStart = (this._layout.rowOffsets[rowIdx] ?? 0) + 1;
10261
+ const rowEnd = rowStart + (this._layout.rowHeights[rowIdx] ?? 1) - 1;
10262
+ if (localY <= rowEnd)
10263
+ return rowIdx;
10264
+ }
10265
+ return this._rowCount - 1;
10280
10266
  }
10281
- parser(e, t2) {
10282
- return b.parse(e, t2 ?? this.defaults);
10267
+ getSelectionRowRange(selection) {
10268
+ if (!selection?.isActive || this._rowCount === 0)
10269
+ return null;
10270
+ const minSelY = Math.min(selection.anchorY, selection.focusY);
10271
+ const maxSelY = Math.max(selection.anchorY, selection.focusY);
10272
+ return {
10273
+ firstRow: this.findRowForLocalY(minSelY),
10274
+ lastRow: this.findRowForLocalY(maxSelY)
10275
+ };
10283
10276
  }
10284
- parseMarkdown(e) {
10285
- return (n, r) => {
10286
- let i = { ...r }, s = { ...this.defaults, ...i }, a = this.onError(!!s.silent, !!s.async);
10287
- if (this.defaults.async === true && i.async === false)
10288
- 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."));
10289
- if (typeof n > "u" || n === null)
10290
- return a(new Error("marked(): input parameter is undefined or null"));
10291
- if (typeof n != "string")
10292
- return a(new Error("marked(): input parameter is of type " + Object.prototype.toString.call(n) + ", string expected"));
10293
- if (s.hooks && (s.hooks.options = s, s.hooks.block = e), s.async)
10294
- return (async () => {
10295
- 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;
10296
- s.walkTokens && await Promise.all(this.walkTokens(c, s.walkTokens));
10297
- let h2 = await (s.hooks ? await s.hooks.provideParser() : e ? b.parse : b.parseInline)(c, s);
10298
- return s.hooks ? await s.hooks.postprocess(h2) : h2;
10299
- })().catch(a);
10300
- try {
10301
- s.hooks && (n = s.hooks.preprocess(n));
10302
- let l = (s.hooks ? s.hooks.provideLexer() : e ? x.lex : x.lexInline)(n, s);
10303
- s.hooks && (l = s.hooks.processAllTokens(l)), s.walkTokens && this.walkTokens(l, s.walkTokens);
10304
- let c = (s.hooks ? s.hooks.provideParser() : e ? b.parse : b.parseInline)(l, s);
10305
- return s.hooks && (c = s.hooks.postprocess(c)), c;
10306
- } catch (o) {
10307
- return a(o);
10308
- }
10277
+ getDirtySelectionRowRange(previousSelection, currentSelection) {
10278
+ const previousRange = this.getSelectionRowRange(previousSelection);
10279
+ const currentRange = this.getSelectionRowRange(currentSelection);
10280
+ if (previousRange === null)
10281
+ return currentRange;
10282
+ if (currentRange === null)
10283
+ return previousRange;
10284
+ return {
10285
+ firstRow: Math.min(previousRange.firstRow, currentRange.firstRow),
10286
+ lastRow: Math.max(previousRange.lastRow, currentRange.lastRow)
10309
10287
  };
10310
10288
  }
10311
- onError(e, t2) {
10312
- return (n) => {
10313
- if (n.message += `
10314
- Please report this to https://github.com/markedjs/marked.`, e) {
10315
- let r = "<p>An error occurred:</p><pre>" + w(n.message + "", true) + "</pre>";
10316
- return t2 ? Promise.resolve(r) : r;
10317
- }
10318
- if (t2)
10319
- return Promise.reject(n);
10320
- throw n;
10289
+ resetRowSelection(rowIdx) {
10290
+ const row = this._cells[rowIdx];
10291
+ if (!row)
10292
+ return;
10293
+ for (const cell of row) {
10294
+ cell.textBufferView.resetLocalSelection();
10295
+ }
10296
+ }
10297
+ resetCellSelections() {
10298
+ for (let rowIdx = 0;rowIdx < this._rowCount; rowIdx++) {
10299
+ this.resetRowSelection(rowIdx);
10300
+ }
10301
+ }
10302
+ createEmptyLayout() {
10303
+ return {
10304
+ columnWidths: [],
10305
+ rowHeights: [],
10306
+ columnOffsets: [0],
10307
+ rowOffsets: [0],
10308
+ columnOffsetsI32: new Int32Array([0]),
10309
+ rowOffsetsI32: new Int32Array([0]),
10310
+ tableWidth: 0,
10311
+ tableHeight: 0
10321
10312
  };
10322
10313
  }
10323
- };
10324
- var _ = new B;
10325
- function d(u3, e) {
10326
- return _.parse(u3, e);
10314
+ resolveLayoutWidthConstraint(width) {
10315
+ if (width === undefined || !Number.isFinite(width) || width <= 0) {
10316
+ return;
10317
+ }
10318
+ if (this._wrapMode !== "none" || this.isFullWidthMode()) {
10319
+ return Math.max(1, Math.floor(width));
10320
+ }
10321
+ return;
10322
+ }
10323
+ getHorizontalCellPadding() {
10324
+ return this._cellPadding * 2;
10325
+ }
10326
+ getVerticalCellPadding() {
10327
+ return this._cellPadding * 2;
10328
+ }
10329
+ resolveColumnFitter(value) {
10330
+ if (value === undefined) {
10331
+ return this._defaultOptions.columnFitter;
10332
+ }
10333
+ return value === "balanced" ? "balanced" : "proportional";
10334
+ }
10335
+ resolveCellPadding(value) {
10336
+ if (value === undefined || !Number.isFinite(value)) {
10337
+ return this._defaultOptions.cellPadding;
10338
+ }
10339
+ return Math.max(0, Math.floor(value));
10340
+ }
10341
+ invalidateLayoutAndRaster(markYogaDirty = true) {
10342
+ this._layoutDirty = true;
10343
+ this._rasterDirty = true;
10344
+ this._cachedMeasureLayout = null;
10345
+ this._cachedMeasureWidth = undefined;
10346
+ if (markYogaDirty) {
10347
+ this.yogaNode.markDirty();
10348
+ }
10349
+ this.requestRender();
10350
+ }
10351
+ invalidateRasterOnly() {
10352
+ this._rasterDirty = true;
10353
+ this.requestRender();
10354
+ }
10327
10355
  }
10328
- d.options = d.setOptions = function(u3) {
10329
- return _.setOptions(u3), d.defaults = _.defaults, Z(d.defaults), d;
10330
- };
10331
- d.getDefaults = L;
10332
- d.defaults = T;
10333
- d.use = function(...u3) {
10334
- return _.use(...u3), d.defaults = _.defaults, Z(d.defaults), d;
10335
- };
10336
- d.walkTokens = function(u3, e) {
10337
- return _.walkTokens(u3, e);
10338
- };
10339
- d.parseInline = _.parseInline;
10340
- d.Parser = b;
10341
- d.parser = b.parse;
10342
- d.Renderer = P;
10343
- d.TextRenderer = $;
10344
- d.Lexer = x;
10345
- d.lexer = x.lex;
10346
- d.Tokenizer = y;
10347
- d.Hooks = S;
10348
- d.parse = d;
10349
- var Dt = d.options;
10350
- var Ht = d.setOptions;
10351
- var Zt = d.use;
10352
- var Gt = d.walkTokens;
10353
- var Nt = d.parseInline;
10354
- var Ft = b.parse;
10355
- var jt = x.lex;
10356
10356
 
10357
10357
  // src/renderables/markdown-parser.ts
10358
10358
  function parseMarkdownIncremental(newContent, prevState, trailingUnstable = 2) {
@@ -10424,6 +10424,9 @@ class MarkdownRenderable extends Renderable {
10424
10424
  content: context.content,
10425
10425
  highlights: context.highlights
10426
10426
  });
10427
+ _inlineConcealChunks = (chunks, context) => {
10428
+ return this.buildInlineConcealChunks(chunks, context);
10429
+ };
10427
10430
  _contentDefaultOptions = {
10428
10431
  content: "",
10429
10432
  conceal: true,
@@ -10677,6 +10680,195 @@ class MarkdownRenderable extends Renderable {
10677
10680
  break;
10678
10681
  }
10679
10682
  }
10683
+ buildInlineConcealChunks(chunks, context) {
10684
+ const result = [];
10685
+ try {
10686
+ const tokens = x.lex(context.content, { gfm: true });
10687
+ for (const token of tokens) {
10688
+ this.renderBlockTokenInline(token, result);
10689
+ }
10690
+ } catch {
10691
+ return chunks;
10692
+ }
10693
+ if (result.length > 0 && result[result.length - 1].text === `
10694
+ `) {
10695
+ result.pop();
10696
+ }
10697
+ if (result.length === 0)
10698
+ return chunks;
10699
+ const linked = this._linkifyMarkdownChunks(result, context);
10700
+ if (Array.isArray(linked))
10701
+ return linked;
10702
+ return result;
10703
+ }
10704
+ renderBlockTokenInline(token, chunks) {
10705
+ switch (token.type) {
10706
+ case "heading": {
10707
+ const headingToken = token;
10708
+ const style = `markup.heading.${headingToken.depth}`;
10709
+ for (const child of headingToken.tokens) {
10710
+ this.renderInlineTokenWithStyle(child, chunks, style);
10711
+ }
10712
+ chunks.push(this.createDefaultChunk(`
10713
+ `));
10714
+ break;
10715
+ }
10716
+ case "paragraph": {
10717
+ const paragraphToken = token;
10718
+ this.renderInlineContent(paragraphToken.tokens, chunks);
10719
+ chunks.push(this.createDefaultChunk(`
10720
+ `));
10721
+ break;
10722
+ }
10723
+ case "list": {
10724
+ this.renderListInline(token, chunks, 0);
10725
+ break;
10726
+ }
10727
+ case "blockquote": {
10728
+ const quoteToken = token;
10729
+ for (const child of quoteToken.tokens) {
10730
+ const markedChild = child;
10731
+ if (markedChild.type === "paragraph" && "tokens" in markedChild) {
10732
+ chunks.push(this.createChunk("\u258E ", "markup.quote"));
10733
+ for (const inline of markedChild.tokens) {
10734
+ this.renderInlineTokenWithStyle(inline, chunks, "markup.quote");
10735
+ }
10736
+ chunks.push(this.createDefaultChunk(`
10737
+ `));
10738
+ } else {
10739
+ chunks.push(this.createChunk("\u258E ", "markup.quote"));
10740
+ this.renderBlockTokenInline(markedChild, chunks);
10741
+ }
10742
+ }
10743
+ break;
10744
+ }
10745
+ case "code": {
10746
+ const codeToken = token;
10747
+ const rawStyle = this.getStyle("markup.raw.block");
10748
+ const codeText = codeToken.text;
10749
+ for (const line of codeText.split(`
10750
+ `)) {
10751
+ chunks.push({
10752
+ __isChunk: true,
10753
+ text: " " + line,
10754
+ fg: rawStyle?.fg,
10755
+ bg: rawStyle?.bg,
10756
+ attributes: rawStyle ? createTextAttributes({
10757
+ bold: rawStyle.bold,
10758
+ italic: rawStyle.italic,
10759
+ underline: rawStyle.underline,
10760
+ dim: rawStyle.dim
10761
+ }) : 0
10762
+ });
10763
+ chunks.push(this.createDefaultChunk(`
10764
+ `));
10765
+ }
10766
+ break;
10767
+ }
10768
+ case "html": {
10769
+ chunks.push(this.createDefaultChunk(token.text));
10770
+ chunks.push(this.createDefaultChunk(`
10771
+ `));
10772
+ break;
10773
+ }
10774
+ case "hr": {
10775
+ const hrStyle = this.getStyle("punctuation.special");
10776
+ chunks.push({
10777
+ __isChunk: true,
10778
+ text: "\u2500".repeat(40),
10779
+ fg: hrStyle?.fg,
10780
+ bg: hrStyle?.bg,
10781
+ attributes: hrStyle ? createTextAttributes({
10782
+ bold: hrStyle.bold,
10783
+ italic: hrStyle.italic,
10784
+ underline: hrStyle.underline,
10785
+ dim: hrStyle.dim
10786
+ }) : 0
10787
+ });
10788
+ chunks.push(this.createDefaultChunk(`
10789
+ `));
10790
+ break;
10791
+ }
10792
+ case "table": {
10793
+ chunks.push(this.createDefaultChunk(token.raw ?? ""));
10794
+ chunks.push(this.createDefaultChunk(`
10795
+ `));
10796
+ break;
10797
+ }
10798
+ case "def":
10799
+ break;
10800
+ case "space":
10801
+ chunks.push(this.createDefaultChunk(`
10802
+ `));
10803
+ break;
10804
+ default:
10805
+ if ("tokens" in token && Array.isArray(token.tokens)) {
10806
+ this.renderInlineContent(token.tokens, chunks);
10807
+ } else {
10808
+ chunks.push(this.createDefaultChunk(token.raw ?? ""));
10809
+ }
10810
+ chunks.push(this.createDefaultChunk(`
10811
+ `));
10812
+ break;
10813
+ }
10814
+ }
10815
+ renderListInline(list, chunks, depth) {
10816
+ const listStyle = this.getStyle("markup.list");
10817
+ const checkedStyle = this.getStyle("markup.list.checked");
10818
+ const uncheckedStyle = this.getStyle("markup.list.unchecked");
10819
+ for (let i = 0;i < list.items.length; i++) {
10820
+ const item = list.items[i];
10821
+ const indent = " ".repeat(depth);
10822
+ const start = typeof list.start === "number" ? list.start : 1;
10823
+ if (item.task) {
10824
+ const checkmark = item.checked ? "\u2611 " : "\u2610 ";
10825
+ const checkStyle = item.checked ? checkedStyle : uncheckedStyle;
10826
+ chunks.push({
10827
+ __isChunk: true,
10828
+ text: indent + checkmark,
10829
+ fg: checkStyle?.fg ?? listStyle?.fg,
10830
+ bg: checkStyle?.bg ?? listStyle?.bg,
10831
+ attributes: checkStyle ? createTextAttributes({
10832
+ bold: checkStyle.bold,
10833
+ italic: checkStyle.italic,
10834
+ underline: checkStyle.underline,
10835
+ dim: checkStyle.dim
10836
+ }) : 0
10837
+ });
10838
+ } else {
10839
+ const bullet = list.ordered ? `${start + i}. ` : "\u2022 ";
10840
+ chunks.push({
10841
+ __isChunk: true,
10842
+ text: indent + bullet,
10843
+ fg: listStyle?.fg,
10844
+ bg: listStyle?.bg,
10845
+ attributes: listStyle ? createTextAttributes({
10846
+ bold: listStyle.bold,
10847
+ italic: listStyle.italic,
10848
+ underline: listStyle.underline,
10849
+ dim: listStyle.dim
10850
+ }) : 0
10851
+ });
10852
+ }
10853
+ for (const subToken of item.tokens) {
10854
+ const markedSub = subToken;
10855
+ if (markedSub.type === "text" && "tokens" in markedSub && Array.isArray(markedSub.tokens)) {
10856
+ this.renderInlineContent(markedSub.tokens, chunks);
10857
+ } else if (markedSub.type === "list") {
10858
+ chunks.push(this.createDefaultChunk(`
10859
+ `));
10860
+ this.renderListInline(markedSub, chunks, depth + 1);
10861
+ continue;
10862
+ } else if (markedSub.type === "paragraph" && "tokens" in markedSub) {
10863
+ this.renderInlineContent(markedSub.tokens, chunks);
10864
+ } else {
10865
+ this.renderInlineToken(markedSub, chunks);
10866
+ }
10867
+ }
10868
+ chunks.push(this.createDefaultChunk(`
10869
+ `));
10870
+ }
10871
+ }
10680
10872
  createMarkdownCodeRenderable(content, id, marginBottom = 0) {
10681
10873
  return new CodeRenderable(this.ctx, {
10682
10874
  id,
@@ -10686,9 +10878,9 @@ class MarkdownRenderable extends Renderable {
10686
10878
  fg: this._fg,
10687
10879
  bg: this._bg,
10688
10880
  conceal: this._conceal,
10689
- drawUnstyledText: false,
10881
+ drawUnstyledText: true,
10690
10882
  streaming: true,
10691
- onChunks: this._linkifyMarkdownChunks,
10883
+ onChunks: this._conceal ? this._inlineConcealChunks : this._linkifyMarkdownChunks,
10692
10884
  treeSitterClient: this._treeSitterClient,
10693
10885
  width: "100%",
10694
10886
  marginBottom
@@ -10717,8 +10909,9 @@ class MarkdownRenderable extends Renderable {
10717
10909
  renderable.fg = this._fg;
10718
10910
  renderable.bg = this._bg;
10719
10911
  renderable.conceal = this._conceal;
10720
- renderable.drawUnstyledText = false;
10912
+ renderable.drawUnstyledText = true;
10721
10913
  renderable.streaming = true;
10914
+ renderable.onChunks = this._conceal ? this._inlineConcealChunks : this._linkifyMarkdownChunks;
10722
10915
  renderable.marginBottom = marginBottom;
10723
10916
  }
10724
10917
  applyCodeBlockRenderable(renderable, token, marginBottom) {
@@ -13274,5 +13467,5 @@ class TimeToFirstDrawRenderable extends Renderable {
13274
13467
  }
13275
13468
  export { TextBufferView, EditBuffer, EditorView, convertThemeToStyles, SyntaxStyle, 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, NativeSpanFeed, FrameBufferRenderable, ASCIIFontRenderable, BoxRenderable, TextBufferRenderable, CodeRenderable, isTextNodeRenderable, TextNodeRenderable, RootTextNodeRenderable, Generic, Box, Text, ASCIIFont, Input, Select, TabSelect, FrameBuffer, Code, ScrollBox, vstyles, VRenderable, LineNumberRenderable, TextRenderable, DiffRenderable, TextareaRenderable, InputRenderableEvents, InputRenderable, TextTableRenderable, MarkdownRenderable, SliderRenderable, ScrollBarRenderable, ArrowRenderable, ScrollBoxRenderable, SelectRenderableEvents, SelectRenderable, TabSelectRenderableEvents, TabSelectRenderable, TimeToFirstDrawRenderable, exports_src2 as exports_src };
13276
13469
 
13277
- //# debugId=4D9A55B72D0EDCBA64756E2164756E21
13278
- //# sourceMappingURL=index-dbzy9p5e.js.map
13470
+ //# debugId=D0F8EB175CFCC29D64756E2164756E21
13471
+ //# sourceMappingURL=index-vepf4ezg.js.map