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.mjs
CHANGED
|
@@ -3192,7 +3192,7 @@ var spin = (text = "Loading", opts = {}) => {
|
|
|
3192
3192
|
const animInterval = Math.max(FRAME_MS, safeInterval);
|
|
3193
3193
|
acquireCursor();
|
|
3194
3194
|
const startTime = Date.now();
|
|
3195
|
-
const
|
|
3195
|
+
const render2 = () => {
|
|
3196
3196
|
if (stopped) return;
|
|
3197
3197
|
const elapsed = Date.now() - startTime;
|
|
3198
3198
|
frame2 = Math.floor(elapsed / animInterval) % frames2.length;
|
|
@@ -3202,8 +3202,8 @@ var spin = (text = "Loading", opts = {}) => {
|
|
|
3202
3202
|
const buf = createOutputBuffer().push("\r").push(screen.clearLine()).push(line).toString();
|
|
3203
3203
|
write(buf);
|
|
3204
3204
|
};
|
|
3205
|
-
|
|
3206
|
-
timer = setInterval(
|
|
3205
|
+
render2();
|
|
3206
|
+
timer = setInterval(render2, animInterval);
|
|
3207
3207
|
let abortedBySignal = false;
|
|
3208
3208
|
const onAbort = () => {
|
|
3209
3209
|
abortedBySignal = true;
|
|
@@ -3374,15 +3374,15 @@ var dots = (text = "Processing", opts = {}) => {
|
|
|
3374
3374
|
let count = 0;
|
|
3375
3375
|
let stopped = false;
|
|
3376
3376
|
let timer = null;
|
|
3377
|
-
const
|
|
3377
|
+
const render2 = () => {
|
|
3378
3378
|
if (stopped) return;
|
|
3379
3379
|
const dotStr = ".".repeat(count);
|
|
3380
3380
|
const colored = applyColor(dotStr, hex);
|
|
3381
3381
|
write("\r" + screen.clearLine() + text + colored);
|
|
3382
3382
|
count = (count + 1) % (max + 1);
|
|
3383
3383
|
};
|
|
3384
|
-
|
|
3385
|
-
timer = setInterval(
|
|
3384
|
+
render2();
|
|
3385
|
+
timer = setInterval(render2, Math.max(FRAME_MS, interval));
|
|
3386
3386
|
const onAbort = () => stopFn();
|
|
3387
3387
|
if (signal) signal.addEventListener("abort", onAbort, { once: true });
|
|
3388
3388
|
const stopFn = () => {
|
|
@@ -3414,15 +3414,15 @@ var custom = (frames2, text = "", opts = {}) => {
|
|
|
3414
3414
|
let timer = null;
|
|
3415
3415
|
const safeInterval = Math.max(FRAME_MS, interval);
|
|
3416
3416
|
const startTime = Date.now();
|
|
3417
|
-
const
|
|
3417
|
+
const render2 = () => {
|
|
3418
3418
|
if (stopped) return;
|
|
3419
3419
|
const elapsed = Date.now() - startTime;
|
|
3420
3420
|
frame2 = Math.floor(elapsed / safeInterval) % frames2.length;
|
|
3421
3421
|
const f = frames2[frame2] ?? "";
|
|
3422
3422
|
write("\r" + screen.clearLine() + applyColor(f, hex) + " " + text);
|
|
3423
3423
|
};
|
|
3424
|
-
|
|
3425
|
-
timer = setInterval(
|
|
3424
|
+
render2();
|
|
3425
|
+
timer = setInterval(render2, safeInterval);
|
|
3426
3426
|
const onAbort = () => stopFn();
|
|
3427
3427
|
if (signal) signal.addEventListener("abort", onAbort, { once: true });
|
|
3428
3428
|
const stopFn = () => {
|
|
@@ -3529,7 +3529,7 @@ var multi = (opts = {}) => {
|
|
|
3529
3529
|
let frame2 = 0;
|
|
3530
3530
|
let timer = null;
|
|
3531
3531
|
let lastLineCount = 0;
|
|
3532
|
-
const
|
|
3532
|
+
const render2 = () => {
|
|
3533
3533
|
if (lastLineCount > 0) {
|
|
3534
3534
|
write("\r" + cursor.up(lastLineCount) + screen.clearDown());
|
|
3535
3535
|
}
|
|
@@ -3551,8 +3551,8 @@ var multi = (opts = {}) => {
|
|
|
3551
3551
|
const start = () => {
|
|
3552
3552
|
if (timer) return;
|
|
3553
3553
|
acquireCursor();
|
|
3554
|
-
|
|
3555
|
-
timer = setInterval(
|
|
3554
|
+
render2();
|
|
3555
|
+
timer = setInterval(render2, interval);
|
|
3556
3556
|
};
|
|
3557
3557
|
const tick = () => {
|
|
3558
3558
|
if (!timer) start();
|
|
@@ -3576,35 +3576,35 @@ var multi = (opts = {}) => {
|
|
|
3576
3576
|
},
|
|
3577
3577
|
set text(v) {
|
|
3578
3578
|
item.text = v;
|
|
3579
|
-
|
|
3579
|
+
render2();
|
|
3580
3580
|
},
|
|
3581
3581
|
update(newText) {
|
|
3582
3582
|
item.text = newText;
|
|
3583
|
-
|
|
3583
|
+
render2();
|
|
3584
3584
|
},
|
|
3585
3585
|
succeed(t) {
|
|
3586
3586
|
item.state = "success";
|
|
3587
3587
|
if (t !== void 0) item.finalText = t;
|
|
3588
|
-
|
|
3588
|
+
render2();
|
|
3589
3589
|
setTimeout(() => {
|
|
3590
3590
|
items.delete(id);
|
|
3591
|
-
|
|
3591
|
+
render2();
|
|
3592
3592
|
checkEmpty();
|
|
3593
3593
|
}, interval);
|
|
3594
3594
|
},
|
|
3595
3595
|
fail(t) {
|
|
3596
3596
|
item.state = "fail";
|
|
3597
3597
|
if (t !== void 0) item.finalText = t;
|
|
3598
|
-
|
|
3598
|
+
render2();
|
|
3599
3599
|
setTimeout(() => {
|
|
3600
3600
|
items.delete(id);
|
|
3601
|
-
|
|
3601
|
+
render2();
|
|
3602
3602
|
checkEmpty();
|
|
3603
3603
|
}, interval);
|
|
3604
3604
|
},
|
|
3605
3605
|
stop() {
|
|
3606
3606
|
items.delete(id);
|
|
3607
|
-
|
|
3607
|
+
render2();
|
|
3608
3608
|
checkEmpty();
|
|
3609
3609
|
}
|
|
3610
3610
|
};
|
|
@@ -3914,7 +3914,7 @@ var live = (opts = {}) => {
|
|
|
3914
3914
|
let running = false;
|
|
3915
3915
|
let timer = null;
|
|
3916
3916
|
let abortHandler = null;
|
|
3917
|
-
const
|
|
3917
|
+
const render2 = () => {
|
|
3918
3918
|
if (lastLines > 0) clearLines(lastLines);
|
|
3919
3919
|
const frame2 = isColorless2() ? stripAnsi(currentFrame) : currentFrame;
|
|
3920
3920
|
try {
|
|
@@ -3929,7 +3929,7 @@ var live = (opts = {}) => {
|
|
|
3929
3929
|
running = true;
|
|
3930
3930
|
registerCrashHandlers3();
|
|
3931
3931
|
hideCursorSafe2();
|
|
3932
|
-
timer = setInterval(
|
|
3932
|
+
timer = setInterval(render2, interval);
|
|
3933
3933
|
if (signal && !abortHandler) {
|
|
3934
3934
|
abortHandler = () => stop({ clear: false });
|
|
3935
3935
|
if (signal.aborted) abortHandler();
|
|
@@ -3958,7 +3958,7 @@ var live = (opts = {}) => {
|
|
|
3958
3958
|
};
|
|
3959
3959
|
const update = (newFrame) => {
|
|
3960
3960
|
currentFrame = ensureString4(newFrame);
|
|
3961
|
-
if (running)
|
|
3961
|
+
if (running) render2();
|
|
3962
3962
|
};
|
|
3963
3963
|
if (autoStart) start();
|
|
3964
3964
|
return { start, stop, update, isRunning: () => running };
|
|
@@ -4307,7 +4307,7 @@ var menu = (items, opts = {}) => {
|
|
|
4307
4307
|
} catch {
|
|
4308
4308
|
}
|
|
4309
4309
|
};
|
|
4310
|
-
const
|
|
4310
|
+
const render2 = () => {
|
|
4311
4311
|
let totalLines = 0;
|
|
4312
4312
|
const { cols: termCols } = termSize();
|
|
4313
4313
|
const safeTermCols = Math.max(1, termCols);
|
|
@@ -4381,7 +4381,7 @@ var menu = (items, opts = {}) => {
|
|
|
4381
4381
|
try {
|
|
4382
4382
|
emit(cursor.hide());
|
|
4383
4383
|
cursorHidden = true;
|
|
4384
|
-
lastRenderedLines =
|
|
4384
|
+
lastRenderedLines = render2();
|
|
4385
4385
|
} catch {
|
|
4386
4386
|
cleanup(null);
|
|
4387
4387
|
return Promise.resolve(MENU_CANCELLED);
|
|
@@ -4422,7 +4422,7 @@ var menu = (items, opts = {}) => {
|
|
|
4422
4422
|
return;
|
|
4423
4423
|
}
|
|
4424
4424
|
clearLinesLocal();
|
|
4425
|
-
lastRenderedLines =
|
|
4425
|
+
lastRenderedLines = render2();
|
|
4426
4426
|
} catch {
|
|
4427
4427
|
cleanup(onKey);
|
|
4428
4428
|
safeResolve(MENU_CANCELLED);
|
|
@@ -5946,37 +5946,105 @@ var grid = (blocks, opts) => {
|
|
|
5946
5946
|
const alignX = opts.alignX ?? "start";
|
|
5947
5947
|
const alignY = opts.alignY ?? "start";
|
|
5948
5948
|
const cellW = opts.cellWidth != null ? Math.max(0, Math.floor(opts.cellWidth)) : null;
|
|
5949
|
-
const
|
|
5950
|
-
|
|
5951
|
-
|
|
5949
|
+
const cellH = opts.cellHeight != null ? Math.max(1, Math.floor(opts.cellHeight)) : null;
|
|
5950
|
+
const flow = opts.flow === "column" ? "column" : "row";
|
|
5951
|
+
const spans = blocks.map((_, i) => {
|
|
5952
|
+
const raw = opts.colSpan?.[i];
|
|
5953
|
+
if (typeof raw !== "number" || !Number.isFinite(raw) || raw < 1) return 1;
|
|
5954
|
+
return Math.min(columns2, Math.floor(raw));
|
|
5955
|
+
});
|
|
5956
|
+
const hasSpans = spans.some((s) => s > 1);
|
|
5957
|
+
const cellRows = [];
|
|
5958
|
+
if (flow === "column" && !hasSpans) {
|
|
5959
|
+
const rowCount = Math.ceil(blocks.length / columns2);
|
|
5960
|
+
for (let r = 0; r < rowCount; r++) cellRows.push([]);
|
|
5961
|
+
for (let i = 0; i < blocks.length; i++) {
|
|
5962
|
+
const c = Math.floor(i / rowCount);
|
|
5963
|
+
const r = i % rowCount;
|
|
5964
|
+
cellRows[r].push({ block: blocks[i], span: 1, col: c });
|
|
5965
|
+
}
|
|
5966
|
+
} else {
|
|
5967
|
+
let row = [];
|
|
5968
|
+
let colInRow = 0;
|
|
5969
|
+
for (let i = 0; i < blocks.length; i++) {
|
|
5970
|
+
const span = spans[i];
|
|
5971
|
+
if (colInRow + span > columns2 && row.length > 0) {
|
|
5972
|
+
cellRows.push(row);
|
|
5973
|
+
row = [];
|
|
5974
|
+
colInRow = 0;
|
|
5975
|
+
}
|
|
5976
|
+
row.push({ block: blocks[i], span, col: colInRow });
|
|
5977
|
+
colInRow += span;
|
|
5978
|
+
}
|
|
5979
|
+
if (row.length > 0) cellRows.push(row);
|
|
5952
5980
|
}
|
|
5953
|
-
let widths
|
|
5981
|
+
let widths;
|
|
5954
5982
|
if (cellW != null) {
|
|
5955
5983
|
widths = Array(columns2).fill(cellW);
|
|
5956
5984
|
} else {
|
|
5957
5985
|
widths = Array(columns2).fill(0);
|
|
5958
|
-
for (const
|
|
5959
|
-
for (
|
|
5960
|
-
|
|
5961
|
-
|
|
5962
|
-
widths[
|
|
5986
|
+
for (const r of cellRows) {
|
|
5987
|
+
for (const cell of r) {
|
|
5988
|
+
if (cell.span === 1) {
|
|
5989
|
+
const { maxWidth } = _splitBlock(cell.block);
|
|
5990
|
+
if (maxWidth > widths[cell.col]) {
|
|
5991
|
+
widths[cell.col] = maxWidth;
|
|
5992
|
+
}
|
|
5963
5993
|
}
|
|
5964
5994
|
}
|
|
5965
5995
|
}
|
|
5966
|
-
}
|
|
5967
|
-
const renderedRows = rows.map((row) => {
|
|
5968
|
-
const padded = [];
|
|
5969
5996
|
for (let c = 0; c < columns2; c++) {
|
|
5970
|
-
|
|
5997
|
+
if (widths[c] === 0) {
|
|
5998
|
+
for (const r of cellRows) {
|
|
5999
|
+
for (const cell of r) {
|
|
6000
|
+
if (cell.col <= c && cell.col + cell.span > c) {
|
|
6001
|
+
const { maxWidth } = _splitBlock(cell.block);
|
|
6002
|
+
const each = Math.ceil(maxWidth / cell.span);
|
|
6003
|
+
if (each > widths[c]) widths[c] = each;
|
|
6004
|
+
}
|
|
6005
|
+
}
|
|
6006
|
+
}
|
|
6007
|
+
}
|
|
5971
6008
|
}
|
|
5972
|
-
|
|
6009
|
+
}
|
|
6010
|
+
const renderedRows = cellRows.map((row) => {
|
|
6011
|
+
const mergedBlocks = [];
|
|
6012
|
+
const mergedWidths = [];
|
|
6013
|
+
let nextCol = 0;
|
|
6014
|
+
for (const cell of row) {
|
|
6015
|
+
let w = 0;
|
|
6016
|
+
for (let k = 0; k < cell.span; k++) {
|
|
6017
|
+
w += widths[cell.col + k];
|
|
6018
|
+
}
|
|
6019
|
+
w += Math.max(0, cell.span - 1) * gapX;
|
|
6020
|
+
let blockToRender = cell.block;
|
|
6021
|
+
if (cellH != null) {
|
|
6022
|
+
blockToRender = _fitHeight(cell.block, cellH);
|
|
6023
|
+
}
|
|
6024
|
+
mergedBlocks.push(blockToRender);
|
|
6025
|
+
mergedWidths.push(w);
|
|
6026
|
+
nextCol += cell.span;
|
|
6027
|
+
}
|
|
6028
|
+
while (nextCol < columns2) {
|
|
6029
|
+
mergedBlocks.push("");
|
|
6030
|
+
mergedWidths.push(widths[nextCol]);
|
|
6031
|
+
nextCol++;
|
|
6032
|
+
}
|
|
6033
|
+
return vsplit(mergedBlocks, {
|
|
5973
6034
|
gap: gapX,
|
|
5974
6035
|
align: alignY,
|
|
5975
|
-
widths
|
|
6036
|
+
widths: mergedWidths
|
|
5976
6037
|
});
|
|
5977
6038
|
});
|
|
5978
6039
|
return hsplit(renderedRows, { gap: gapY, align: alignX });
|
|
5979
6040
|
};
|
|
6041
|
+
var _fitHeight = (block, targetH) => {
|
|
6042
|
+
const lines = block.split("\n");
|
|
6043
|
+
if (lines.length === targetH) return block;
|
|
6044
|
+
if (lines.length > targetH) return lines.slice(0, targetH).join("\n");
|
|
6045
|
+
const pad = Array(targetH - lines.length).fill("");
|
|
6046
|
+
return [...lines, ...pad].join("\n");
|
|
6047
|
+
};
|
|
5980
6048
|
var panels = {
|
|
5981
6049
|
vsplit,
|
|
5982
6050
|
hsplit,
|
|
@@ -6214,6 +6282,274 @@ var json = {
|
|
|
6214
6282
|
pretty
|
|
6215
6283
|
};
|
|
6216
6284
|
|
|
6285
|
+
// src/markdown/block-parser.ts
|
|
6286
|
+
var HEADING_RE = /^(#{1,6})\s+(.+?)\s*#*\s*$/;
|
|
6287
|
+
var ORDERED_LIST_RE = /^(\s*)(\d+)[.)]\s+(.+)$/;
|
|
6288
|
+
var UNORDERED_LIST_RE = /^(\s*)[-*+]\s+(.+)$/;
|
|
6289
|
+
var HR_RE = /^[ \t]*(?:-{3,}|\*{3,}|_{3,})[ \t]*$/;
|
|
6290
|
+
var CODEBLOCK_OPEN_RE = /^```[ \t]*(\S*)[ \t]*$/;
|
|
6291
|
+
var CODEBLOCK_CLOSE_RE = /^```\s*$/;
|
|
6292
|
+
var BLOCKQUOTE_RE = /^>\s?(.*)$/;
|
|
6293
|
+
var TABLE_SEPARATOR_RE = /^\|?[ \t]*:?-{2,}:?[ \t]*(\|[ \t]*:?-{2,}:?[ \t]*)+\|?[ \t]*$/;
|
|
6294
|
+
var TABLE_ROW_RE = /^\|.*\|[ \t]*$/;
|
|
6295
|
+
var _normalize = (text) => typeof text === "string" ? text.replace(/\r\n/g, "\n").replace(/\r/g, "\n") : "";
|
|
6296
|
+
var _splitTableRow = (row) => {
|
|
6297
|
+
const stripped = row.trim().replace(/^\|/, "").replace(/\|[ \t]*$/, "");
|
|
6298
|
+
return stripped.split("|").map((c) => c.trim());
|
|
6299
|
+
};
|
|
6300
|
+
var parseBlocks = (source) => {
|
|
6301
|
+
if (typeof source !== "string" || source.length === 0) return [];
|
|
6302
|
+
const lines = _normalize(source).split("\n");
|
|
6303
|
+
const out = [];
|
|
6304
|
+
let i = 0;
|
|
6305
|
+
while (i < lines.length) {
|
|
6306
|
+
const line = lines[i];
|
|
6307
|
+
if (line.trim() === "") {
|
|
6308
|
+
out.push({ type: "blank" });
|
|
6309
|
+
i++;
|
|
6310
|
+
continue;
|
|
6311
|
+
}
|
|
6312
|
+
if (HR_RE.test(line)) {
|
|
6313
|
+
out.push({ type: "hr" });
|
|
6314
|
+
i++;
|
|
6315
|
+
continue;
|
|
6316
|
+
}
|
|
6317
|
+
const headingMatch = HEADING_RE.exec(line);
|
|
6318
|
+
if (headingMatch) {
|
|
6319
|
+
const level = headingMatch[1].length;
|
|
6320
|
+
const text = headingMatch[2].trim();
|
|
6321
|
+
out.push({ type: "heading", level, text });
|
|
6322
|
+
i++;
|
|
6323
|
+
continue;
|
|
6324
|
+
}
|
|
6325
|
+
const codeOpen = CODEBLOCK_OPEN_RE.exec(line);
|
|
6326
|
+
if (codeOpen) {
|
|
6327
|
+
const lang = codeOpen[1].trim();
|
|
6328
|
+
const codeLines = [];
|
|
6329
|
+
i++;
|
|
6330
|
+
while (i < lines.length && !CODEBLOCK_CLOSE_RE.test(lines[i])) {
|
|
6331
|
+
codeLines.push(lines[i]);
|
|
6332
|
+
i++;
|
|
6333
|
+
}
|
|
6334
|
+
if (i < lines.length) i++;
|
|
6335
|
+
out.push({ type: "codeblock", lang, code: codeLines.join("\n") });
|
|
6336
|
+
continue;
|
|
6337
|
+
}
|
|
6338
|
+
if (BLOCKQUOTE_RE.test(line)) {
|
|
6339
|
+
const qLines = [];
|
|
6340
|
+
while (i < lines.length && BLOCKQUOTE_RE.test(lines[i])) {
|
|
6341
|
+
const m = BLOCKQUOTE_RE.exec(lines[i]);
|
|
6342
|
+
qLines.push((m?.[1] ?? "").trim());
|
|
6343
|
+
i++;
|
|
6344
|
+
}
|
|
6345
|
+
out.push({ type: "blockquote", text: qLines.join("\n") });
|
|
6346
|
+
continue;
|
|
6347
|
+
}
|
|
6348
|
+
if (TABLE_ROW_RE.test(line) && i + 1 < lines.length && TABLE_SEPARATOR_RE.test(lines[i + 1])) {
|
|
6349
|
+
const headers = _splitTableRow(line);
|
|
6350
|
+
i += 2;
|
|
6351
|
+
const rows = [];
|
|
6352
|
+
while (i < lines.length && TABLE_ROW_RE.test(lines[i])) {
|
|
6353
|
+
rows.push(_splitTableRow(lines[i]));
|
|
6354
|
+
i++;
|
|
6355
|
+
}
|
|
6356
|
+
out.push({ type: "table", headers, rows });
|
|
6357
|
+
continue;
|
|
6358
|
+
}
|
|
6359
|
+
const ulMatch = UNORDERED_LIST_RE.exec(line);
|
|
6360
|
+
const olMatch = ORDERED_LIST_RE.exec(line);
|
|
6361
|
+
if (ulMatch || olMatch) {
|
|
6362
|
+
const ordered = olMatch != null;
|
|
6363
|
+
const items = [];
|
|
6364
|
+
while (i < lines.length) {
|
|
6365
|
+
const ln = lines[i];
|
|
6366
|
+
const u = UNORDERED_LIST_RE.exec(ln);
|
|
6367
|
+
const o = ORDERED_LIST_RE.exec(ln);
|
|
6368
|
+
if (ordered && o) {
|
|
6369
|
+
items.push(o[3].trim());
|
|
6370
|
+
i++;
|
|
6371
|
+
} else if (!ordered && u) {
|
|
6372
|
+
items.push(u[2].trim());
|
|
6373
|
+
i++;
|
|
6374
|
+
} else {
|
|
6375
|
+
break;
|
|
6376
|
+
}
|
|
6377
|
+
}
|
|
6378
|
+
out.push({ type: "list", ordered, items });
|
|
6379
|
+
continue;
|
|
6380
|
+
}
|
|
6381
|
+
const paraLines = [line];
|
|
6382
|
+
i++;
|
|
6383
|
+
while (i < lines.length) {
|
|
6384
|
+
const next = lines[i];
|
|
6385
|
+
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)) {
|
|
6386
|
+
break;
|
|
6387
|
+
}
|
|
6388
|
+
paraLines.push(next);
|
|
6389
|
+
i++;
|
|
6390
|
+
}
|
|
6391
|
+
out.push({ type: "paragraph", text: paraLines.join(" ").trim() });
|
|
6392
|
+
}
|
|
6393
|
+
return out;
|
|
6394
|
+
};
|
|
6395
|
+
|
|
6396
|
+
// src/markdown/theme.ts
|
|
6397
|
+
var THEMES = {
|
|
6398
|
+
dark: {
|
|
6399
|
+
h1: ["#ff79c6", "#bd93f9", "#8be9fd"],
|
|
6400
|
+
h2: "#bd93f9",
|
|
6401
|
+
h3: "#8be9fd",
|
|
6402
|
+
h4: "#50fa7b",
|
|
6403
|
+
h5: "#f1fa8c",
|
|
6404
|
+
h6: "#ffb86c",
|
|
6405
|
+
code: "#ff79c6",
|
|
6406
|
+
codeBlockBorder: "#6272a4",
|
|
6407
|
+
link: "#8be9fd",
|
|
6408
|
+
blockquote: "#6272a4",
|
|
6409
|
+
hr: "#6272a4",
|
|
6410
|
+
tableHeader: "#bd93f9"
|
|
6411
|
+
},
|
|
6412
|
+
light: {
|
|
6413
|
+
h1: ["#d63384", "#6f42c1", "#0d6efd"],
|
|
6414
|
+
h2: "#6f42c1",
|
|
6415
|
+
h3: "#0d6efd",
|
|
6416
|
+
h4: "#198754",
|
|
6417
|
+
h5: "#664d03",
|
|
6418
|
+
h6: "#fd7e14",
|
|
6419
|
+
code: "#d63384",
|
|
6420
|
+
codeBlockBorder: "#adb5bd",
|
|
6421
|
+
link: "#0d6efd",
|
|
6422
|
+
blockquote: "#6c757d",
|
|
6423
|
+
hr: "#adb5bd",
|
|
6424
|
+
tableHeader: "#6f42c1"
|
|
6425
|
+
}
|
|
6426
|
+
};
|
|
6427
|
+
|
|
6428
|
+
// src/markdown/inline-parser.ts
|
|
6429
|
+
var parseInline = (text, opts = { theme: "dark", inlineCodeBackground: true }) => {
|
|
6430
|
+
if (typeof text !== "string" || text.length === 0) return "";
|
|
6431
|
+
const t = THEMES[opts.theme];
|
|
6432
|
+
const codeSlots = [];
|
|
6433
|
+
let s = text.replace(/`([^`\n]+)`/g, (_m, code) => {
|
|
6434
|
+
const styled = opts.inlineCodeBackground ? color.dim(color.hex(t.code)("\xA0" + code + "\xA0")) : color.dim(color.hex(t.code)(code));
|
|
6435
|
+
codeSlots.push(styled);
|
|
6436
|
+
return `\0CODE${codeSlots.length - 1}\0`;
|
|
6437
|
+
});
|
|
6438
|
+
s = s.replace(/\[([^\]]+)\]\(([^)\s]+)\)/g, (_m, label, url) => {
|
|
6439
|
+
return hyperlink(url, color.hex(t.link)(color.underline(label)));
|
|
6440
|
+
});
|
|
6441
|
+
s = s.replace(/~~([^~\n]+)~~/g, (_m, inner) => color.strikethrough(inner));
|
|
6442
|
+
s = s.replace(/\*\*([^*\n]+)\*\*/g, (_m, inner) => color.bold(inner));
|
|
6443
|
+
s = s.replace(/__([^_\n]+)__/g, (_m, inner) => color.bold(inner));
|
|
6444
|
+
s = s.replace(/(^|[^*])\*([^*\n]+)\*(?!\*)/g, (_m, pre, inner) => pre + color.italic(inner));
|
|
6445
|
+
s = s.replace(/(^|[^_])_([^_\n]+)_(?!_)/g, (_m, pre, inner) => pre + color.italic(inner));
|
|
6446
|
+
s = s.replace(/\x00CODE(\d+)\x00/g, (_m, idx) => codeSlots[Number(idx)] ?? "");
|
|
6447
|
+
return s;
|
|
6448
|
+
};
|
|
6449
|
+
|
|
6450
|
+
// src/markdown/renderer.ts
|
|
6451
|
+
var _detectWidth = () => {
|
|
6452
|
+
const w = process.stdout?.columns;
|
|
6453
|
+
return isFiniteNumber2(w) && w > 10 ? w : 80;
|
|
6454
|
+
};
|
|
6455
|
+
var render = (source, opts = {}) => {
|
|
6456
|
+
if (typeof source !== "string" || source.length === 0) return "";
|
|
6457
|
+
const {
|
|
6458
|
+
width = _detectWidth(),
|
|
6459
|
+
theme = "dark",
|
|
6460
|
+
headingGradient,
|
|
6461
|
+
boxCodeBlocks = true,
|
|
6462
|
+
inlineCodeBackground = true
|
|
6463
|
+
} = opts;
|
|
6464
|
+
const safeWidth = isFiniteNumber2(width) && width > 4 ? Math.floor(width) : 80;
|
|
6465
|
+
const t = THEMES[theme] ?? THEMES.dark;
|
|
6466
|
+
const h1Colors = headingGradient && headingGradient.length >= 2 ? headingGradient : t.h1;
|
|
6467
|
+
const blocks = parseBlocks(source);
|
|
6468
|
+
const inlineOpts = { theme, inlineCodeBackground };
|
|
6469
|
+
const out = [];
|
|
6470
|
+
for (const block of blocks) {
|
|
6471
|
+
switch (block.type) {
|
|
6472
|
+
case "blank":
|
|
6473
|
+
out.push("");
|
|
6474
|
+
break;
|
|
6475
|
+
case "hr":
|
|
6476
|
+
out.push(color.hex(t.hr)(ascii.divider({ width: safeWidth, char: "\u2500" })));
|
|
6477
|
+
break;
|
|
6478
|
+
case "heading": {
|
|
6479
|
+
const inline = parseInline(block.text, inlineOpts);
|
|
6480
|
+
if (block.level === 1) {
|
|
6481
|
+
out.push(color.bold(gradient(inline, h1Colors)));
|
|
6482
|
+
} else if (block.level === 2) {
|
|
6483
|
+
out.push(color.bold(color.underline(color.hex(t.h2)(inline))));
|
|
6484
|
+
} else {
|
|
6485
|
+
const colorKey = `h${block.level}`;
|
|
6486
|
+
const hex = t[colorKey];
|
|
6487
|
+
out.push(color.bold(color.hex(hex)(inline)));
|
|
6488
|
+
}
|
|
6489
|
+
break;
|
|
6490
|
+
}
|
|
6491
|
+
case "paragraph": {
|
|
6492
|
+
out.push(parseInline(block.text, inlineOpts));
|
|
6493
|
+
break;
|
|
6494
|
+
}
|
|
6495
|
+
case "codeblock": {
|
|
6496
|
+
const codeText = block.code.length > 0 ? block.code : " ";
|
|
6497
|
+
if (boxCodeBlocks) {
|
|
6498
|
+
const labeled = block.lang ? ` ${block.lang} ` : null;
|
|
6499
|
+
const box3 = ascii.box(codeText, {
|
|
6500
|
+
borderStyle: "rounded",
|
|
6501
|
+
padding: 1,
|
|
6502
|
+
title: labeled
|
|
6503
|
+
});
|
|
6504
|
+
out.push(color.hex(t.codeBlockBorder)(box3));
|
|
6505
|
+
} else {
|
|
6506
|
+
const indented = codeText.split("\n").map((l) => " " + l).join("\n");
|
|
6507
|
+
out.push(color.dim(indented));
|
|
6508
|
+
}
|
|
6509
|
+
break;
|
|
6510
|
+
}
|
|
6511
|
+
case "list": {
|
|
6512
|
+
const lines = [];
|
|
6513
|
+
for (let idx = 0; idx < block.items.length; idx++) {
|
|
6514
|
+
const marker = block.ordered ? `${idx + 1}.` : "\u2022";
|
|
6515
|
+
const rendered = parseInline(block.items[idx], inlineOpts);
|
|
6516
|
+
lines.push(` ${color.hex(t.h3)(marker)} ${rendered}`);
|
|
6517
|
+
}
|
|
6518
|
+
out.push(lines.join("\n"));
|
|
6519
|
+
break;
|
|
6520
|
+
}
|
|
6521
|
+
case "blockquote": {
|
|
6522
|
+
const rendered = parseInline(block.text, inlineOpts);
|
|
6523
|
+
const quoted = rendered.split("\n").map((l) => color.hex(t.blockquote)("\u2502 ") + color.dim(l)).join("\n");
|
|
6524
|
+
out.push(quoted);
|
|
6525
|
+
break;
|
|
6526
|
+
}
|
|
6527
|
+
case "table": {
|
|
6528
|
+
const styledHeaders = block.headers.map(
|
|
6529
|
+
(h) => color.bold(color.hex(t.tableHeader)(parseInline(h, inlineOpts)))
|
|
6530
|
+
);
|
|
6531
|
+
const styledRows = block.rows.map(
|
|
6532
|
+
(row) => row.map((cell) => parseInline(cell, inlineOpts))
|
|
6533
|
+
);
|
|
6534
|
+
out.push(components.table([styledHeaders, ...styledRows], {
|
|
6535
|
+
borderStyle: "rounded",
|
|
6536
|
+
padding: 1
|
|
6537
|
+
}));
|
|
6538
|
+
break;
|
|
6539
|
+
}
|
|
6540
|
+
}
|
|
6541
|
+
}
|
|
6542
|
+
while (out.length > 0 && out[out.length - 1] === "") out.pop();
|
|
6543
|
+
return out.join("\n");
|
|
6544
|
+
};
|
|
6545
|
+
|
|
6546
|
+
// src/markdown/index.ts
|
|
6547
|
+
var markdown = {
|
|
6548
|
+
render,
|
|
6549
|
+
parseBlocks,
|
|
6550
|
+
parseInline
|
|
6551
|
+
};
|
|
6552
|
+
|
|
6217
6553
|
// src/configure.ts
|
|
6218
6554
|
var DEFAULTS = Object.freeze({
|
|
6219
6555
|
colorMode: "auto",
|
|
@@ -6521,7 +6857,23 @@ var resolveEasingByName = (e) => {
|
|
|
6521
6857
|
};
|
|
6522
6858
|
|
|
6523
6859
|
// src/index.ts
|
|
6524
|
-
var ansimax = {
|
|
6860
|
+
var ansimax = {
|
|
6861
|
+
color,
|
|
6862
|
+
animate,
|
|
6863
|
+
ascii,
|
|
6864
|
+
loader,
|
|
6865
|
+
frames,
|
|
6866
|
+
components,
|
|
6867
|
+
trees,
|
|
6868
|
+
themes,
|
|
6869
|
+
images,
|
|
6870
|
+
configure,
|
|
6871
|
+
// v1.3.0+
|
|
6872
|
+
panels,
|
|
6873
|
+
json,
|
|
6874
|
+
// v1.4.0
|
|
6875
|
+
markdown
|
|
6876
|
+
};
|
|
6525
6877
|
var index_default = ansimax;
|
|
6526
6878
|
export {
|
|
6527
6879
|
ASCII_RAMPS,
|
|
@@ -6621,6 +6973,7 @@ export {
|
|
|
6621
6973
|
listPresets,
|
|
6622
6974
|
loader,
|
|
6623
6975
|
mapTree,
|
|
6976
|
+
markdown,
|
|
6624
6977
|
measureBlock,
|
|
6625
6978
|
measureTree,
|
|
6626
6979
|
memoize,
|
|
@@ -6636,6 +6989,8 @@ export {
|
|
|
6636
6989
|
padStart,
|
|
6637
6990
|
panels,
|
|
6638
6991
|
parseFiglet,
|
|
6992
|
+
parseBlocks as parseMarkdownBlocks,
|
|
6993
|
+
parseInline as parseMarkdownInline,
|
|
6639
6994
|
pauseListeners,
|
|
6640
6995
|
presetNames,
|
|
6641
6996
|
presets,
|
|
@@ -6643,6 +6998,7 @@ export {
|
|
|
6643
6998
|
rainbow,
|
|
6644
6999
|
registerFont,
|
|
6645
7000
|
registerPreset,
|
|
7001
|
+
render as renderMarkdown,
|
|
6646
7002
|
renderPixelArt,
|
|
6647
7003
|
renderTree,
|
|
6648
7004
|
renderTreeStream,
|
package/examples/all-in-one.cjs
CHANGED
|
@@ -118,7 +118,7 @@ async function main() {
|
|
|
118
118
|
console.log(components.section('🏷️ Badges & Status', { width: 60 }));
|
|
119
119
|
console.log();
|
|
120
120
|
console.log(' ',
|
|
121
|
-
components.badge('VERSION', 'v1.
|
|
121
|
+
components.badge('VERSION', 'v1.4.1'),
|
|
122
122
|
components.badge('BUILD', 'passing'),
|
|
123
123
|
components.badge('LICENSE', 'Apache 2.0'));
|
|
124
124
|
console.log();
|
package/examples/all-in-one.mjs
CHANGED
|
@@ -117,7 +117,7 @@ console.log();
|
|
|
117
117
|
console.log(components.section('🏷️ Badges & Status', { width: 60 }));
|
|
118
118
|
console.log();
|
|
119
119
|
console.log(' ',
|
|
120
|
-
components.badge('VERSION', 'v1.
|
|
120
|
+
components.badge('VERSION', 'v1.4.1'),
|
|
121
121
|
components.badge('BUILD', 'passing'),
|
|
122
122
|
components.badge('LICENSE', 'Apache 2.0'));
|
|
123
123
|
console.log();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ansimax",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.1",
|
|
4
4
|
"description": "Zero-dependency CLI rendering library: colors, gradients, animations, ASCII art, pixel art, components, and themes \u2014 all in TypeScript.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|