ansimax 1.3.7 → 1.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +217 -0
- package/README.es.md +58 -2
- package/README.md +58 -2
- package/dist/index.d.mts +189 -1
- package/dist/index.d.ts +189 -1
- package/dist/index.js +401 -41
- package/dist/index.mjs +397 -41
- package/examples/all-in-one.cjs +1 -1
- package/examples/all-in-one.mjs +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -127,6 +127,7 @@ __export(index_exports, {
|
|
|
127
127
|
listPresets: () => listPresets,
|
|
128
128
|
loader: () => loader,
|
|
129
129
|
mapTree: () => mapTree,
|
|
130
|
+
markdown: () => markdown,
|
|
130
131
|
measureBlock: () => measureBlock,
|
|
131
132
|
measureTree: () => measureTree,
|
|
132
133
|
memoize: () => memoize,
|
|
@@ -142,6 +143,8 @@ __export(index_exports, {
|
|
|
142
143
|
padStart: () => padStart,
|
|
143
144
|
panels: () => panels,
|
|
144
145
|
parseFiglet: () => parseFiglet,
|
|
146
|
+
parseMarkdownBlocks: () => parseBlocks,
|
|
147
|
+
parseMarkdownInline: () => parseInline,
|
|
145
148
|
pauseListeners: () => pauseListeners,
|
|
146
149
|
presetNames: () => presetNames,
|
|
147
150
|
presets: () => presets,
|
|
@@ -149,6 +152,7 @@ __export(index_exports, {
|
|
|
149
152
|
rainbow: () => rainbow,
|
|
150
153
|
registerFont: () => registerFont,
|
|
151
154
|
registerPreset: () => registerPreset,
|
|
155
|
+
renderMarkdown: () => render,
|
|
152
156
|
renderPixelArt: () => renderPixelArt,
|
|
153
157
|
renderTree: () => renderTree,
|
|
154
158
|
renderTreeStream: () => renderTreeStream,
|
|
@@ -3400,7 +3404,7 @@ var spin = (text = "Loading", opts = {}) => {
|
|
|
3400
3404
|
const animInterval = Math.max(FRAME_MS, safeInterval);
|
|
3401
3405
|
acquireCursor();
|
|
3402
3406
|
const startTime = Date.now();
|
|
3403
|
-
const
|
|
3407
|
+
const render2 = () => {
|
|
3404
3408
|
if (stopped) return;
|
|
3405
3409
|
const elapsed = Date.now() - startTime;
|
|
3406
3410
|
frame2 = Math.floor(elapsed / animInterval) % frames2.length;
|
|
@@ -3410,8 +3414,8 @@ var spin = (text = "Loading", opts = {}) => {
|
|
|
3410
3414
|
const buf = createOutputBuffer().push("\r").push(screen.clearLine()).push(line).toString();
|
|
3411
3415
|
write(buf);
|
|
3412
3416
|
};
|
|
3413
|
-
|
|
3414
|
-
timer = setInterval(
|
|
3417
|
+
render2();
|
|
3418
|
+
timer = setInterval(render2, animInterval);
|
|
3415
3419
|
let abortedBySignal = false;
|
|
3416
3420
|
const onAbort = () => {
|
|
3417
3421
|
abortedBySignal = true;
|
|
@@ -3582,15 +3586,15 @@ var dots = (text = "Processing", opts = {}) => {
|
|
|
3582
3586
|
let count = 0;
|
|
3583
3587
|
let stopped = false;
|
|
3584
3588
|
let timer = null;
|
|
3585
|
-
const
|
|
3589
|
+
const render2 = () => {
|
|
3586
3590
|
if (stopped) return;
|
|
3587
3591
|
const dotStr = ".".repeat(count);
|
|
3588
3592
|
const colored = applyColor(dotStr, hex);
|
|
3589
3593
|
write("\r" + screen.clearLine() + text + colored);
|
|
3590
3594
|
count = (count + 1) % (max + 1);
|
|
3591
3595
|
};
|
|
3592
|
-
|
|
3593
|
-
timer = setInterval(
|
|
3596
|
+
render2();
|
|
3597
|
+
timer = setInterval(render2, Math.max(FRAME_MS, interval));
|
|
3594
3598
|
const onAbort = () => stopFn();
|
|
3595
3599
|
if (signal) signal.addEventListener("abort", onAbort, { once: true });
|
|
3596
3600
|
const stopFn = () => {
|
|
@@ -3622,15 +3626,15 @@ var custom = (frames2, text = "", opts = {}) => {
|
|
|
3622
3626
|
let timer = null;
|
|
3623
3627
|
const safeInterval = Math.max(FRAME_MS, interval);
|
|
3624
3628
|
const startTime = Date.now();
|
|
3625
|
-
const
|
|
3629
|
+
const render2 = () => {
|
|
3626
3630
|
if (stopped) return;
|
|
3627
3631
|
const elapsed = Date.now() - startTime;
|
|
3628
3632
|
frame2 = Math.floor(elapsed / safeInterval) % frames2.length;
|
|
3629
3633
|
const f = frames2[frame2] ?? "";
|
|
3630
3634
|
write("\r" + screen.clearLine() + applyColor(f, hex) + " " + text);
|
|
3631
3635
|
};
|
|
3632
|
-
|
|
3633
|
-
timer = setInterval(
|
|
3636
|
+
render2();
|
|
3637
|
+
timer = setInterval(render2, safeInterval);
|
|
3634
3638
|
const onAbort = () => stopFn();
|
|
3635
3639
|
if (signal) signal.addEventListener("abort", onAbort, { once: true });
|
|
3636
3640
|
const stopFn = () => {
|
|
@@ -3737,7 +3741,7 @@ var multi = (opts = {}) => {
|
|
|
3737
3741
|
let frame2 = 0;
|
|
3738
3742
|
let timer = null;
|
|
3739
3743
|
let lastLineCount = 0;
|
|
3740
|
-
const
|
|
3744
|
+
const render2 = () => {
|
|
3741
3745
|
if (lastLineCount > 0) {
|
|
3742
3746
|
write("\r" + cursor.up(lastLineCount) + screen.clearDown());
|
|
3743
3747
|
}
|
|
@@ -3759,8 +3763,8 @@ var multi = (opts = {}) => {
|
|
|
3759
3763
|
const start = () => {
|
|
3760
3764
|
if (timer) return;
|
|
3761
3765
|
acquireCursor();
|
|
3762
|
-
|
|
3763
|
-
timer = setInterval(
|
|
3766
|
+
render2();
|
|
3767
|
+
timer = setInterval(render2, interval);
|
|
3764
3768
|
};
|
|
3765
3769
|
const tick = () => {
|
|
3766
3770
|
if (!timer) start();
|
|
@@ -3784,35 +3788,35 @@ var multi = (opts = {}) => {
|
|
|
3784
3788
|
},
|
|
3785
3789
|
set text(v) {
|
|
3786
3790
|
item.text = v;
|
|
3787
|
-
|
|
3791
|
+
render2();
|
|
3788
3792
|
},
|
|
3789
3793
|
update(newText) {
|
|
3790
3794
|
item.text = newText;
|
|
3791
|
-
|
|
3795
|
+
render2();
|
|
3792
3796
|
},
|
|
3793
3797
|
succeed(t) {
|
|
3794
3798
|
item.state = "success";
|
|
3795
3799
|
if (t !== void 0) item.finalText = t;
|
|
3796
|
-
|
|
3800
|
+
render2();
|
|
3797
3801
|
setTimeout(() => {
|
|
3798
3802
|
items.delete(id);
|
|
3799
|
-
|
|
3803
|
+
render2();
|
|
3800
3804
|
checkEmpty();
|
|
3801
3805
|
}, interval);
|
|
3802
3806
|
},
|
|
3803
3807
|
fail(t) {
|
|
3804
3808
|
item.state = "fail";
|
|
3805
3809
|
if (t !== void 0) item.finalText = t;
|
|
3806
|
-
|
|
3810
|
+
render2();
|
|
3807
3811
|
setTimeout(() => {
|
|
3808
3812
|
items.delete(id);
|
|
3809
|
-
|
|
3813
|
+
render2();
|
|
3810
3814
|
checkEmpty();
|
|
3811
3815
|
}, interval);
|
|
3812
3816
|
},
|
|
3813
3817
|
stop() {
|
|
3814
3818
|
items.delete(id);
|
|
3815
|
-
|
|
3819
|
+
render2();
|
|
3816
3820
|
checkEmpty();
|
|
3817
3821
|
}
|
|
3818
3822
|
};
|
|
@@ -4122,7 +4126,7 @@ var live = (opts = {}) => {
|
|
|
4122
4126
|
let running = false;
|
|
4123
4127
|
let timer = null;
|
|
4124
4128
|
let abortHandler = null;
|
|
4125
|
-
const
|
|
4129
|
+
const render2 = () => {
|
|
4126
4130
|
if (lastLines > 0) clearLines(lastLines);
|
|
4127
4131
|
const frame2 = isColorless2() ? stripAnsi(currentFrame) : currentFrame;
|
|
4128
4132
|
try {
|
|
@@ -4137,7 +4141,7 @@ var live = (opts = {}) => {
|
|
|
4137
4141
|
running = true;
|
|
4138
4142
|
registerCrashHandlers3();
|
|
4139
4143
|
hideCursorSafe2();
|
|
4140
|
-
timer = setInterval(
|
|
4144
|
+
timer = setInterval(render2, interval);
|
|
4141
4145
|
if (signal && !abortHandler) {
|
|
4142
4146
|
abortHandler = () => stop({ clear: false });
|
|
4143
4147
|
if (signal.aborted) abortHandler();
|
|
@@ -4166,7 +4170,7 @@ var live = (opts = {}) => {
|
|
|
4166
4170
|
};
|
|
4167
4171
|
const update = (newFrame) => {
|
|
4168
4172
|
currentFrame = ensureString4(newFrame);
|
|
4169
|
-
if (running)
|
|
4173
|
+
if (running) render2();
|
|
4170
4174
|
};
|
|
4171
4175
|
if (autoStart) start();
|
|
4172
4176
|
return { start, stop, update, isRunning: () => running };
|
|
@@ -4515,7 +4519,7 @@ var menu = (items, opts = {}) => {
|
|
|
4515
4519
|
} catch {
|
|
4516
4520
|
}
|
|
4517
4521
|
};
|
|
4518
|
-
const
|
|
4522
|
+
const render2 = () => {
|
|
4519
4523
|
let totalLines = 0;
|
|
4520
4524
|
const { cols: termCols } = termSize();
|
|
4521
4525
|
const safeTermCols = Math.max(1, termCols);
|
|
@@ -4589,7 +4593,7 @@ var menu = (items, opts = {}) => {
|
|
|
4589
4593
|
try {
|
|
4590
4594
|
emit(cursor.hide());
|
|
4591
4595
|
cursorHidden = true;
|
|
4592
|
-
lastRenderedLines =
|
|
4596
|
+
lastRenderedLines = render2();
|
|
4593
4597
|
} catch {
|
|
4594
4598
|
cleanup(null);
|
|
4595
4599
|
return Promise.resolve(MENU_CANCELLED);
|
|
@@ -4630,7 +4634,7 @@ var menu = (items, opts = {}) => {
|
|
|
4630
4634
|
return;
|
|
4631
4635
|
}
|
|
4632
4636
|
clearLinesLocal();
|
|
4633
|
-
lastRenderedLines =
|
|
4637
|
+
lastRenderedLines = render2();
|
|
4634
4638
|
} catch {
|
|
4635
4639
|
cleanup(onKey);
|
|
4636
4640
|
safeResolve(MENU_CANCELLED);
|
|
@@ -6154,37 +6158,105 @@ var grid = (blocks, opts) => {
|
|
|
6154
6158
|
const alignX = opts.alignX ?? "start";
|
|
6155
6159
|
const alignY = opts.alignY ?? "start";
|
|
6156
6160
|
const cellW = opts.cellWidth != null ? Math.max(0, Math.floor(opts.cellWidth)) : null;
|
|
6157
|
-
const
|
|
6158
|
-
|
|
6159
|
-
|
|
6161
|
+
const cellH = opts.cellHeight != null ? Math.max(1, Math.floor(opts.cellHeight)) : null;
|
|
6162
|
+
const flow = opts.flow === "column" ? "column" : "row";
|
|
6163
|
+
const spans = blocks.map((_, i) => {
|
|
6164
|
+
const raw = opts.colSpan?.[i];
|
|
6165
|
+
if (typeof raw !== "number" || !Number.isFinite(raw) || raw < 1) return 1;
|
|
6166
|
+
return Math.min(columns2, Math.floor(raw));
|
|
6167
|
+
});
|
|
6168
|
+
const hasSpans = spans.some((s) => s > 1);
|
|
6169
|
+
const cellRows = [];
|
|
6170
|
+
if (flow === "column" && !hasSpans) {
|
|
6171
|
+
const rowCount = Math.ceil(blocks.length / columns2);
|
|
6172
|
+
for (let r = 0; r < rowCount; r++) cellRows.push([]);
|
|
6173
|
+
for (let i = 0; i < blocks.length; i++) {
|
|
6174
|
+
const c = Math.floor(i / rowCount);
|
|
6175
|
+
const r = i % rowCount;
|
|
6176
|
+
cellRows[r].push({ block: blocks[i], span: 1, col: c });
|
|
6177
|
+
}
|
|
6178
|
+
} else {
|
|
6179
|
+
let row = [];
|
|
6180
|
+
let colInRow = 0;
|
|
6181
|
+
for (let i = 0; i < blocks.length; i++) {
|
|
6182
|
+
const span = spans[i];
|
|
6183
|
+
if (colInRow + span > columns2 && row.length > 0) {
|
|
6184
|
+
cellRows.push(row);
|
|
6185
|
+
row = [];
|
|
6186
|
+
colInRow = 0;
|
|
6187
|
+
}
|
|
6188
|
+
row.push({ block: blocks[i], span, col: colInRow });
|
|
6189
|
+
colInRow += span;
|
|
6190
|
+
}
|
|
6191
|
+
if (row.length > 0) cellRows.push(row);
|
|
6160
6192
|
}
|
|
6161
|
-
let widths
|
|
6193
|
+
let widths;
|
|
6162
6194
|
if (cellW != null) {
|
|
6163
6195
|
widths = Array(columns2).fill(cellW);
|
|
6164
6196
|
} else {
|
|
6165
6197
|
widths = Array(columns2).fill(0);
|
|
6166
|
-
for (const
|
|
6167
|
-
for (
|
|
6168
|
-
|
|
6169
|
-
|
|
6170
|
-
widths[
|
|
6198
|
+
for (const r of cellRows) {
|
|
6199
|
+
for (const cell of r) {
|
|
6200
|
+
if (cell.span === 1) {
|
|
6201
|
+
const { maxWidth } = _splitBlock(cell.block);
|
|
6202
|
+
if (maxWidth > widths[cell.col]) {
|
|
6203
|
+
widths[cell.col] = maxWidth;
|
|
6204
|
+
}
|
|
6171
6205
|
}
|
|
6172
6206
|
}
|
|
6173
6207
|
}
|
|
6174
|
-
}
|
|
6175
|
-
const renderedRows = rows.map((row) => {
|
|
6176
|
-
const padded = [];
|
|
6177
6208
|
for (let c = 0; c < columns2; c++) {
|
|
6178
|
-
|
|
6209
|
+
if (widths[c] === 0) {
|
|
6210
|
+
for (const r of cellRows) {
|
|
6211
|
+
for (const cell of r) {
|
|
6212
|
+
if (cell.col <= c && cell.col + cell.span > c) {
|
|
6213
|
+
const { maxWidth } = _splitBlock(cell.block);
|
|
6214
|
+
const each = Math.ceil(maxWidth / cell.span);
|
|
6215
|
+
if (each > widths[c]) widths[c] = each;
|
|
6216
|
+
}
|
|
6217
|
+
}
|
|
6218
|
+
}
|
|
6219
|
+
}
|
|
6179
6220
|
}
|
|
6180
|
-
|
|
6221
|
+
}
|
|
6222
|
+
const renderedRows = cellRows.map((row) => {
|
|
6223
|
+
const mergedBlocks = [];
|
|
6224
|
+
const mergedWidths = [];
|
|
6225
|
+
let nextCol = 0;
|
|
6226
|
+
for (const cell of row) {
|
|
6227
|
+
let w = 0;
|
|
6228
|
+
for (let k = 0; k < cell.span; k++) {
|
|
6229
|
+
w += widths[cell.col + k];
|
|
6230
|
+
}
|
|
6231
|
+
w += Math.max(0, cell.span - 1) * gapX;
|
|
6232
|
+
let blockToRender = cell.block;
|
|
6233
|
+
if (cellH != null) {
|
|
6234
|
+
blockToRender = _fitHeight(cell.block, cellH);
|
|
6235
|
+
}
|
|
6236
|
+
mergedBlocks.push(blockToRender);
|
|
6237
|
+
mergedWidths.push(w);
|
|
6238
|
+
nextCol += cell.span;
|
|
6239
|
+
}
|
|
6240
|
+
while (nextCol < columns2) {
|
|
6241
|
+
mergedBlocks.push("");
|
|
6242
|
+
mergedWidths.push(widths[nextCol]);
|
|
6243
|
+
nextCol++;
|
|
6244
|
+
}
|
|
6245
|
+
return vsplit(mergedBlocks, {
|
|
6181
6246
|
gap: gapX,
|
|
6182
6247
|
align: alignY,
|
|
6183
|
-
widths
|
|
6248
|
+
widths: mergedWidths
|
|
6184
6249
|
});
|
|
6185
6250
|
});
|
|
6186
6251
|
return hsplit(renderedRows, { gap: gapY, align: alignX });
|
|
6187
6252
|
};
|
|
6253
|
+
var _fitHeight = (block, targetH) => {
|
|
6254
|
+
const lines = block.split("\n");
|
|
6255
|
+
if (lines.length === targetH) return block;
|
|
6256
|
+
if (lines.length > targetH) return lines.slice(0, targetH).join("\n");
|
|
6257
|
+
const pad = Array(targetH - lines.length).fill("");
|
|
6258
|
+
return [...lines, ...pad].join("\n");
|
|
6259
|
+
};
|
|
6188
6260
|
var panels = {
|
|
6189
6261
|
vsplit,
|
|
6190
6262
|
hsplit,
|
|
@@ -6422,6 +6494,274 @@ var json = {
|
|
|
6422
6494
|
pretty
|
|
6423
6495
|
};
|
|
6424
6496
|
|
|
6497
|
+
// src/markdown/block-parser.ts
|
|
6498
|
+
var HEADING_RE = /^(#{1,6})\s+(.+?)\s*#*\s*$/;
|
|
6499
|
+
var ORDERED_LIST_RE = /^(\s*)(\d+)[.)]\s+(.+)$/;
|
|
6500
|
+
var UNORDERED_LIST_RE = /^(\s*)[-*+]\s+(.+)$/;
|
|
6501
|
+
var HR_RE = /^[ \t]*(?:-{3,}|\*{3,}|_{3,})[ \t]*$/;
|
|
6502
|
+
var CODEBLOCK_OPEN_RE = /^```[ \t]*(\S*)[ \t]*$/;
|
|
6503
|
+
var CODEBLOCK_CLOSE_RE = /^```\s*$/;
|
|
6504
|
+
var BLOCKQUOTE_RE = /^>\s?(.*)$/;
|
|
6505
|
+
var TABLE_SEPARATOR_RE = /^\|?[ \t]*:?-{2,}:?[ \t]*(\|[ \t]*:?-{2,}:?[ \t]*)+\|?[ \t]*$/;
|
|
6506
|
+
var TABLE_ROW_RE = /^\|.*\|[ \t]*$/;
|
|
6507
|
+
var _normalize = (text) => typeof text === "string" ? text.replace(/\r\n/g, "\n").replace(/\r/g, "\n") : "";
|
|
6508
|
+
var _splitTableRow = (row) => {
|
|
6509
|
+
const stripped = row.trim().replace(/^\|/, "").replace(/\|[ \t]*$/, "");
|
|
6510
|
+
return stripped.split("|").map((c) => c.trim());
|
|
6511
|
+
};
|
|
6512
|
+
var parseBlocks = (source) => {
|
|
6513
|
+
if (typeof source !== "string" || source.length === 0) return [];
|
|
6514
|
+
const lines = _normalize(source).split("\n");
|
|
6515
|
+
const out = [];
|
|
6516
|
+
let i = 0;
|
|
6517
|
+
while (i < lines.length) {
|
|
6518
|
+
const line = lines[i];
|
|
6519
|
+
if (line.trim() === "") {
|
|
6520
|
+
out.push({ type: "blank" });
|
|
6521
|
+
i++;
|
|
6522
|
+
continue;
|
|
6523
|
+
}
|
|
6524
|
+
if (HR_RE.test(line)) {
|
|
6525
|
+
out.push({ type: "hr" });
|
|
6526
|
+
i++;
|
|
6527
|
+
continue;
|
|
6528
|
+
}
|
|
6529
|
+
const headingMatch = HEADING_RE.exec(line);
|
|
6530
|
+
if (headingMatch) {
|
|
6531
|
+
const level = headingMatch[1].length;
|
|
6532
|
+
const text = headingMatch[2].trim();
|
|
6533
|
+
out.push({ type: "heading", level, text });
|
|
6534
|
+
i++;
|
|
6535
|
+
continue;
|
|
6536
|
+
}
|
|
6537
|
+
const codeOpen = CODEBLOCK_OPEN_RE.exec(line);
|
|
6538
|
+
if (codeOpen) {
|
|
6539
|
+
const lang = codeOpen[1].trim();
|
|
6540
|
+
const codeLines = [];
|
|
6541
|
+
i++;
|
|
6542
|
+
while (i < lines.length && !CODEBLOCK_CLOSE_RE.test(lines[i])) {
|
|
6543
|
+
codeLines.push(lines[i]);
|
|
6544
|
+
i++;
|
|
6545
|
+
}
|
|
6546
|
+
if (i < lines.length) i++;
|
|
6547
|
+
out.push({ type: "codeblock", lang, code: codeLines.join("\n") });
|
|
6548
|
+
continue;
|
|
6549
|
+
}
|
|
6550
|
+
if (BLOCKQUOTE_RE.test(line)) {
|
|
6551
|
+
const qLines = [];
|
|
6552
|
+
while (i < lines.length && BLOCKQUOTE_RE.test(lines[i])) {
|
|
6553
|
+
const m = BLOCKQUOTE_RE.exec(lines[i]);
|
|
6554
|
+
qLines.push((m?.[1] ?? "").trim());
|
|
6555
|
+
i++;
|
|
6556
|
+
}
|
|
6557
|
+
out.push({ type: "blockquote", text: qLines.join("\n") });
|
|
6558
|
+
continue;
|
|
6559
|
+
}
|
|
6560
|
+
if (TABLE_ROW_RE.test(line) && i + 1 < lines.length && TABLE_SEPARATOR_RE.test(lines[i + 1])) {
|
|
6561
|
+
const headers = _splitTableRow(line);
|
|
6562
|
+
i += 2;
|
|
6563
|
+
const rows = [];
|
|
6564
|
+
while (i < lines.length && TABLE_ROW_RE.test(lines[i])) {
|
|
6565
|
+
rows.push(_splitTableRow(lines[i]));
|
|
6566
|
+
i++;
|
|
6567
|
+
}
|
|
6568
|
+
out.push({ type: "table", headers, rows });
|
|
6569
|
+
continue;
|
|
6570
|
+
}
|
|
6571
|
+
const ulMatch = UNORDERED_LIST_RE.exec(line);
|
|
6572
|
+
const olMatch = ORDERED_LIST_RE.exec(line);
|
|
6573
|
+
if (ulMatch || olMatch) {
|
|
6574
|
+
const ordered = olMatch != null;
|
|
6575
|
+
const items = [];
|
|
6576
|
+
while (i < lines.length) {
|
|
6577
|
+
const ln = lines[i];
|
|
6578
|
+
const u = UNORDERED_LIST_RE.exec(ln);
|
|
6579
|
+
const o = ORDERED_LIST_RE.exec(ln);
|
|
6580
|
+
if (ordered && o) {
|
|
6581
|
+
items.push(o[3].trim());
|
|
6582
|
+
i++;
|
|
6583
|
+
} else if (!ordered && u) {
|
|
6584
|
+
items.push(u[2].trim());
|
|
6585
|
+
i++;
|
|
6586
|
+
} else {
|
|
6587
|
+
break;
|
|
6588
|
+
}
|
|
6589
|
+
}
|
|
6590
|
+
out.push({ type: "list", ordered, items });
|
|
6591
|
+
continue;
|
|
6592
|
+
}
|
|
6593
|
+
const paraLines = [line];
|
|
6594
|
+
i++;
|
|
6595
|
+
while (i < lines.length) {
|
|
6596
|
+
const next = lines[i];
|
|
6597
|
+
if (next.trim() === "" || HEADING_RE.test(next) || HR_RE.test(next) || CODEBLOCK_OPEN_RE.test(next) || BLOCKQUOTE_RE.test(next) || UNORDERED_LIST_RE.test(next) || ORDERED_LIST_RE.test(next) || TABLE_ROW_RE.test(next)) {
|
|
6598
|
+
break;
|
|
6599
|
+
}
|
|
6600
|
+
paraLines.push(next);
|
|
6601
|
+
i++;
|
|
6602
|
+
}
|
|
6603
|
+
out.push({ type: "paragraph", text: paraLines.join(" ").trim() });
|
|
6604
|
+
}
|
|
6605
|
+
return out;
|
|
6606
|
+
};
|
|
6607
|
+
|
|
6608
|
+
// src/markdown/theme.ts
|
|
6609
|
+
var THEMES = {
|
|
6610
|
+
dark: {
|
|
6611
|
+
h1: ["#ff79c6", "#bd93f9", "#8be9fd"],
|
|
6612
|
+
h2: "#bd93f9",
|
|
6613
|
+
h3: "#8be9fd",
|
|
6614
|
+
h4: "#50fa7b",
|
|
6615
|
+
h5: "#f1fa8c",
|
|
6616
|
+
h6: "#ffb86c",
|
|
6617
|
+
code: "#ff79c6",
|
|
6618
|
+
codeBlockBorder: "#6272a4",
|
|
6619
|
+
link: "#8be9fd",
|
|
6620
|
+
blockquote: "#6272a4",
|
|
6621
|
+
hr: "#6272a4",
|
|
6622
|
+
tableHeader: "#bd93f9"
|
|
6623
|
+
},
|
|
6624
|
+
light: {
|
|
6625
|
+
h1: ["#d63384", "#6f42c1", "#0d6efd"],
|
|
6626
|
+
h2: "#6f42c1",
|
|
6627
|
+
h3: "#0d6efd",
|
|
6628
|
+
h4: "#198754",
|
|
6629
|
+
h5: "#664d03",
|
|
6630
|
+
h6: "#fd7e14",
|
|
6631
|
+
code: "#d63384",
|
|
6632
|
+
codeBlockBorder: "#adb5bd",
|
|
6633
|
+
link: "#0d6efd",
|
|
6634
|
+
blockquote: "#6c757d",
|
|
6635
|
+
hr: "#adb5bd",
|
|
6636
|
+
tableHeader: "#6f42c1"
|
|
6637
|
+
}
|
|
6638
|
+
};
|
|
6639
|
+
|
|
6640
|
+
// src/markdown/inline-parser.ts
|
|
6641
|
+
var parseInline = (text, opts = { theme: "dark", inlineCodeBackground: true }) => {
|
|
6642
|
+
if (typeof text !== "string" || text.length === 0) return "";
|
|
6643
|
+
const t = THEMES[opts.theme];
|
|
6644
|
+
const codeSlots = [];
|
|
6645
|
+
let s = text.replace(/`([^`\n]+)`/g, (_m, code) => {
|
|
6646
|
+
const styled = opts.inlineCodeBackground ? color.dim(color.hex(t.code)("\xA0" + code + "\xA0")) : color.dim(color.hex(t.code)(code));
|
|
6647
|
+
codeSlots.push(styled);
|
|
6648
|
+
return `\0CODE${codeSlots.length - 1}\0`;
|
|
6649
|
+
});
|
|
6650
|
+
s = s.replace(/\[([^\]]+)\]\(([^)\s]+)\)/g, (_m, label, url) => {
|
|
6651
|
+
return hyperlink(url, color.hex(t.link)(color.underline(label)));
|
|
6652
|
+
});
|
|
6653
|
+
s = s.replace(/~~([^~\n]+)~~/g, (_m, inner) => color.strikethrough(inner));
|
|
6654
|
+
s = s.replace(/\*\*([^*\n]+)\*\*/g, (_m, inner) => color.bold(inner));
|
|
6655
|
+
s = s.replace(/__([^_\n]+)__/g, (_m, inner) => color.bold(inner));
|
|
6656
|
+
s = s.replace(/(^|[^*])\*([^*\n]+)\*(?!\*)/g, (_m, pre, inner) => pre + color.italic(inner));
|
|
6657
|
+
s = s.replace(/(^|[^_])_([^_\n]+)_(?!_)/g, (_m, pre, inner) => pre + color.italic(inner));
|
|
6658
|
+
s = s.replace(/\x00CODE(\d+)\x00/g, (_m, idx) => codeSlots[Number(idx)] ?? "");
|
|
6659
|
+
return s;
|
|
6660
|
+
};
|
|
6661
|
+
|
|
6662
|
+
// src/markdown/renderer.ts
|
|
6663
|
+
var _detectWidth = () => {
|
|
6664
|
+
const w = process.stdout?.columns;
|
|
6665
|
+
return isFiniteNumber2(w) && w > 10 ? w : 80;
|
|
6666
|
+
};
|
|
6667
|
+
var render = (source, opts = {}) => {
|
|
6668
|
+
if (typeof source !== "string" || source.length === 0) return "";
|
|
6669
|
+
const {
|
|
6670
|
+
width = _detectWidth(),
|
|
6671
|
+
theme = "dark",
|
|
6672
|
+
headingGradient,
|
|
6673
|
+
boxCodeBlocks = true,
|
|
6674
|
+
inlineCodeBackground = true
|
|
6675
|
+
} = opts;
|
|
6676
|
+
const safeWidth = isFiniteNumber2(width) && width > 4 ? Math.floor(width) : 80;
|
|
6677
|
+
const t = THEMES[theme] ?? THEMES.dark;
|
|
6678
|
+
const h1Colors = headingGradient && headingGradient.length >= 2 ? headingGradient : t.h1;
|
|
6679
|
+
const blocks = parseBlocks(source);
|
|
6680
|
+
const inlineOpts = { theme, inlineCodeBackground };
|
|
6681
|
+
const out = [];
|
|
6682
|
+
for (const block of blocks) {
|
|
6683
|
+
switch (block.type) {
|
|
6684
|
+
case "blank":
|
|
6685
|
+
out.push("");
|
|
6686
|
+
break;
|
|
6687
|
+
case "hr":
|
|
6688
|
+
out.push(color.hex(t.hr)(ascii.divider({ width: safeWidth, char: "\u2500" })));
|
|
6689
|
+
break;
|
|
6690
|
+
case "heading": {
|
|
6691
|
+
const inline = parseInline(block.text, inlineOpts);
|
|
6692
|
+
if (block.level === 1) {
|
|
6693
|
+
out.push(color.bold(gradient(inline, h1Colors)));
|
|
6694
|
+
} else if (block.level === 2) {
|
|
6695
|
+
out.push(color.bold(color.underline(color.hex(t.h2)(inline))));
|
|
6696
|
+
} else {
|
|
6697
|
+
const colorKey = `h${block.level}`;
|
|
6698
|
+
const hex = t[colorKey];
|
|
6699
|
+
out.push(color.bold(color.hex(hex)(inline)));
|
|
6700
|
+
}
|
|
6701
|
+
break;
|
|
6702
|
+
}
|
|
6703
|
+
case "paragraph": {
|
|
6704
|
+
out.push(parseInline(block.text, inlineOpts));
|
|
6705
|
+
break;
|
|
6706
|
+
}
|
|
6707
|
+
case "codeblock": {
|
|
6708
|
+
const codeText = block.code.length > 0 ? block.code : " ";
|
|
6709
|
+
if (boxCodeBlocks) {
|
|
6710
|
+
const labeled = block.lang ? ` ${block.lang} ` : null;
|
|
6711
|
+
const box3 = ascii.box(codeText, {
|
|
6712
|
+
borderStyle: "rounded",
|
|
6713
|
+
padding: 1,
|
|
6714
|
+
title: labeled
|
|
6715
|
+
});
|
|
6716
|
+
out.push(color.hex(t.codeBlockBorder)(box3));
|
|
6717
|
+
} else {
|
|
6718
|
+
const indented = codeText.split("\n").map((l) => " " + l).join("\n");
|
|
6719
|
+
out.push(color.dim(indented));
|
|
6720
|
+
}
|
|
6721
|
+
break;
|
|
6722
|
+
}
|
|
6723
|
+
case "list": {
|
|
6724
|
+
const lines = [];
|
|
6725
|
+
for (let idx = 0; idx < block.items.length; idx++) {
|
|
6726
|
+
const marker = block.ordered ? `${idx + 1}.` : "\u2022";
|
|
6727
|
+
const rendered = parseInline(block.items[idx], inlineOpts);
|
|
6728
|
+
lines.push(` ${color.hex(t.h3)(marker)} ${rendered}`);
|
|
6729
|
+
}
|
|
6730
|
+
out.push(lines.join("\n"));
|
|
6731
|
+
break;
|
|
6732
|
+
}
|
|
6733
|
+
case "blockquote": {
|
|
6734
|
+
const rendered = parseInline(block.text, inlineOpts);
|
|
6735
|
+
const quoted = rendered.split("\n").map((l) => color.hex(t.blockquote)("\u2502 ") + color.dim(l)).join("\n");
|
|
6736
|
+
out.push(quoted);
|
|
6737
|
+
break;
|
|
6738
|
+
}
|
|
6739
|
+
case "table": {
|
|
6740
|
+
const styledHeaders = block.headers.map(
|
|
6741
|
+
(h) => color.bold(color.hex(t.tableHeader)(parseInline(h, inlineOpts)))
|
|
6742
|
+
);
|
|
6743
|
+
const styledRows = block.rows.map(
|
|
6744
|
+
(row) => row.map((cell) => parseInline(cell, inlineOpts))
|
|
6745
|
+
);
|
|
6746
|
+
out.push(components.table([styledHeaders, ...styledRows], {
|
|
6747
|
+
borderStyle: "rounded",
|
|
6748
|
+
padding: 1
|
|
6749
|
+
}));
|
|
6750
|
+
break;
|
|
6751
|
+
}
|
|
6752
|
+
}
|
|
6753
|
+
}
|
|
6754
|
+
while (out.length > 0 && out[out.length - 1] === "") out.pop();
|
|
6755
|
+
return out.join("\n");
|
|
6756
|
+
};
|
|
6757
|
+
|
|
6758
|
+
// src/markdown/index.ts
|
|
6759
|
+
var markdown = {
|
|
6760
|
+
render,
|
|
6761
|
+
parseBlocks,
|
|
6762
|
+
parseInline
|
|
6763
|
+
};
|
|
6764
|
+
|
|
6425
6765
|
// src/configure.ts
|
|
6426
6766
|
var DEFAULTS = Object.freeze({
|
|
6427
6767
|
colorMode: "auto",
|
|
@@ -6729,7 +7069,23 @@ var resolveEasingByName = (e) => {
|
|
|
6729
7069
|
};
|
|
6730
7070
|
|
|
6731
7071
|
// src/index.ts
|
|
6732
|
-
var ansimax = {
|
|
7072
|
+
var ansimax = {
|
|
7073
|
+
color,
|
|
7074
|
+
animate,
|
|
7075
|
+
ascii,
|
|
7076
|
+
loader,
|
|
7077
|
+
frames,
|
|
7078
|
+
components,
|
|
7079
|
+
trees,
|
|
7080
|
+
themes,
|
|
7081
|
+
images,
|
|
7082
|
+
configure,
|
|
7083
|
+
// v1.3.0+
|
|
7084
|
+
panels,
|
|
7085
|
+
json,
|
|
7086
|
+
// v1.4.0
|
|
7087
|
+
markdown
|
|
7088
|
+
};
|
|
6733
7089
|
var index_default = ansimax;
|
|
6734
7090
|
// Annotate the CommonJS export names for ESM import in node:
|
|
6735
7091
|
0 && (module.exports = {
|
|
@@ -6829,6 +7185,7 @@ var index_default = ansimax;
|
|
|
6829
7185
|
listPresets,
|
|
6830
7186
|
loader,
|
|
6831
7187
|
mapTree,
|
|
7188
|
+
markdown,
|
|
6832
7189
|
measureBlock,
|
|
6833
7190
|
measureTree,
|
|
6834
7191
|
memoize,
|
|
@@ -6844,6 +7201,8 @@ var index_default = ansimax;
|
|
|
6844
7201
|
padStart,
|
|
6845
7202
|
panels,
|
|
6846
7203
|
parseFiglet,
|
|
7204
|
+
parseMarkdownBlocks,
|
|
7205
|
+
parseMarkdownInline,
|
|
6847
7206
|
pauseListeners,
|
|
6848
7207
|
presetNames,
|
|
6849
7208
|
presets,
|
|
@@ -6851,6 +7210,7 @@ var index_default = ansimax;
|
|
|
6851
7210
|
rainbow,
|
|
6852
7211
|
registerFont,
|
|
6853
7212
|
registerPreset,
|
|
7213
|
+
renderMarkdown,
|
|
6854
7214
|
renderPixelArt,
|
|
6855
7215
|
renderTree,
|
|
6856
7216
|
renderTreeStream,
|