ansimax 1.3.2 → 1.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +282 -0
- package/README.es.md +93 -11
- package/README.md +93 -11
- package/dist/index.d.mts +452 -196
- package/dist/index.d.ts +452 -196
- package/dist/index.js +396 -46
- package/dist/index.mjs +388 -46
- 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
|
@@ -62,6 +62,7 @@ __export(index_exports, {
|
|
|
62
62
|
clamp: () => clamp,
|
|
63
63
|
clearAnsiCache: () => clearAnsiCache,
|
|
64
64
|
clearColorCache: () => clearColorCache,
|
|
65
|
+
clearLine: () => clearLine,
|
|
65
66
|
clearRenderCache: () => clearRenderCache,
|
|
66
67
|
clearThemeColorCache: () => clearThemeColorCache,
|
|
67
68
|
color: () => color,
|
|
@@ -79,6 +80,7 @@ __export(index_exports, {
|
|
|
79
80
|
debounce: () => debounce,
|
|
80
81
|
default: () => index_default,
|
|
81
82
|
diffLines: () => diffLines,
|
|
83
|
+
escapeForRegex: () => escapeForRegex,
|
|
82
84
|
escapeRegex: () => escapeRegex,
|
|
83
85
|
fg256: () => fg256,
|
|
84
86
|
fgRgb: () => fgRgb,
|
|
@@ -99,11 +101,14 @@ __export(index_exports, {
|
|
|
99
101
|
gradient: () => gradient,
|
|
100
102
|
gradientColor: () => gradientColor,
|
|
101
103
|
gradientRect: () => gradientRect,
|
|
104
|
+
gradientStops: () => gradientStops,
|
|
102
105
|
graphemes: () => graphemes,
|
|
106
|
+
grid: () => grid,
|
|
103
107
|
hasFont: () => hasFont,
|
|
104
108
|
hexToRgb: () => hexToRgb,
|
|
105
109
|
hideCursor: () => hideCursor,
|
|
106
110
|
hsplit: () => hsplit,
|
|
111
|
+
hyperlink: () => hyperlink,
|
|
107
112
|
images: () => images,
|
|
108
113
|
isHexColor: () => isHexColor,
|
|
109
114
|
isNoColor: () => isNoColor,
|
|
@@ -116,6 +121,7 @@ __export(index_exports, {
|
|
|
116
121
|
listPresets: () => listPresets,
|
|
117
122
|
loader: () => loader,
|
|
118
123
|
mapTree: () => mapTree,
|
|
124
|
+
measureBlock: () => measureBlock,
|
|
119
125
|
measureTree: () => measureTree,
|
|
120
126
|
memoize: () => memoize,
|
|
121
127
|
nextTick: () => nextTick,
|
|
@@ -153,6 +159,7 @@ __export(index_exports, {
|
|
|
153
159
|
rotate90: () => rotate90,
|
|
154
160
|
safeJson: () => safeJson,
|
|
155
161
|
screen: () => screen,
|
|
162
|
+
setConfigValue: () => setConfigValue,
|
|
156
163
|
setNoColor: () => setNoColor,
|
|
157
164
|
setTitle: () => setTitle,
|
|
158
165
|
sgr: () => sgr,
|
|
@@ -163,6 +170,7 @@ __export(index_exports, {
|
|
|
163
170
|
stripAnsi: () => stripAnsi2,
|
|
164
171
|
stripAnsiCodes: () => stripAnsi,
|
|
165
172
|
stripAnsiColors: () => stripAnsi3,
|
|
173
|
+
subscribeConfig: () => subscribeConfig,
|
|
166
174
|
supportsColor: () => supportsColor,
|
|
167
175
|
supportsColorLevel: () => supportsColorLevel,
|
|
168
176
|
termSize: () => termSize,
|
|
@@ -566,6 +574,14 @@ var sleepFrame = (ms = FRAME_MS, opts = {}) => sleep(
|
|
|
566
574
|
Math.max(FRAME_MS, Math.round((isFiniteNumber(ms) ? ms : FRAME_MS) / FRAME_MS) * FRAME_MS),
|
|
567
575
|
opts
|
|
568
576
|
);
|
|
577
|
+
var hyperlink = (url, label) => {
|
|
578
|
+
if (typeof url !== "string" || url.length === 0) {
|
|
579
|
+
return typeof label === "string" ? label : "";
|
|
580
|
+
}
|
|
581
|
+
const safeLabel = typeof label === "string" && label.length > 0 ? label : url;
|
|
582
|
+
return `${OSC}8;;${url}${ST}${safeLabel}${OSC}8;;${ST}`;
|
|
583
|
+
};
|
|
584
|
+
var clearLine = () => `${CSI}2K\r`;
|
|
569
585
|
|
|
570
586
|
// src/utils/helpers.ts
|
|
571
587
|
var clamp = (n, min, max) => Math.min(Math.max(n, min), max);
|
|
@@ -988,6 +1004,35 @@ var padBoth = (str, width, ch = " ") => {
|
|
|
988
1004
|
const r = pad - l;
|
|
989
1005
|
return ch.repeat(l) + str + ch.repeat(r);
|
|
990
1006
|
};
|
|
1007
|
+
var gradientStops = (start, end, count) => {
|
|
1008
|
+
const safeCount = Math.max(2, Math.floor(Number.isFinite(count) ? count : 2));
|
|
1009
|
+
if (!isHexColor(start) || !isHexColor(end)) return [];
|
|
1010
|
+
const a = hexToRgb(start);
|
|
1011
|
+
const b = hexToRgb(end);
|
|
1012
|
+
const result = [];
|
|
1013
|
+
for (let i = 0; i < safeCount; i++) {
|
|
1014
|
+
const t = i / (safeCount - 1);
|
|
1015
|
+
const c = lerpColor(a, b, t);
|
|
1016
|
+
result.push(rgbToHex(c.r, c.g, c.b));
|
|
1017
|
+
}
|
|
1018
|
+
return result;
|
|
1019
|
+
};
|
|
1020
|
+
var escapeForRegex = (str) => {
|
|
1021
|
+
if (typeof str !== "string") return "";
|
|
1022
|
+
return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
1023
|
+
};
|
|
1024
|
+
var measureBlock = (block) => {
|
|
1025
|
+
if (typeof block !== "string" || block.length === 0) {
|
|
1026
|
+
return { width: 0, height: 0 };
|
|
1027
|
+
}
|
|
1028
|
+
const lines = block.split("\n");
|
|
1029
|
+
let width = 0;
|
|
1030
|
+
for (const line of lines) {
|
|
1031
|
+
const w = visibleLen(line);
|
|
1032
|
+
if (w > width) width = w;
|
|
1033
|
+
}
|
|
1034
|
+
return { width, height: lines.length };
|
|
1035
|
+
};
|
|
991
1036
|
|
|
992
1037
|
// src/colors/index.ts
|
|
993
1038
|
var _noColor = null;
|
|
@@ -2111,6 +2156,131 @@ var delay = (ms) => async (opts = {}) => {
|
|
|
2111
2156
|
} catch {
|
|
2112
2157
|
}
|
|
2113
2158
|
};
|
|
2159
|
+
var shake = async (text, opts = {}) => {
|
|
2160
|
+
const {
|
|
2161
|
+
times = 5,
|
|
2162
|
+
intensity = 2,
|
|
2163
|
+
interval = 50,
|
|
2164
|
+
newline = true,
|
|
2165
|
+
signal,
|
|
2166
|
+
reducedMotion = false,
|
|
2167
|
+
onFrame,
|
|
2168
|
+
onDone,
|
|
2169
|
+
onAbort
|
|
2170
|
+
} = opts;
|
|
2171
|
+
const hooks = { onFrame, onDone, onAbort };
|
|
2172
|
+
if (reducedMotion || isAborted(signal)) {
|
|
2173
|
+
safeWrite(text);
|
|
2174
|
+
if (newline) writeln();
|
|
2175
|
+
fireDone(hooks, isAborted(signal));
|
|
2176
|
+
return;
|
|
2177
|
+
}
|
|
2178
|
+
const safeText = typeof text === "string" ? text : "";
|
|
2179
|
+
const safeTimes = Math.max(1, Math.round(times));
|
|
2180
|
+
const safeIntensity = Math.max(1, Math.round(intensity));
|
|
2181
|
+
const safeInterval = Math.max(FRAME_MS, interval);
|
|
2182
|
+
const pattern = [0, safeIntensity, 0, -safeIntensity];
|
|
2183
|
+
registerCrashHandlers();
|
|
2184
|
+
hideCursorSafe();
|
|
2185
|
+
let aborted = false;
|
|
2186
|
+
let frame2 = 0;
|
|
2187
|
+
try {
|
|
2188
|
+
for (let cycle = 0; cycle < safeTimes; cycle++) {
|
|
2189
|
+
for (const offset of pattern) {
|
|
2190
|
+
if (isAborted(signal)) {
|
|
2191
|
+
aborted = true;
|
|
2192
|
+
break;
|
|
2193
|
+
}
|
|
2194
|
+
const prefix = offset > 0 ? " ".repeat(offset) : "";
|
|
2195
|
+
await safeWriteAsync(
|
|
2196
|
+
cursor.save() + screen.clearLine() + "\r" + prefix + safeText + cursor.restore()
|
|
2197
|
+
);
|
|
2198
|
+
fireFrame(hooks, frame2++);
|
|
2199
|
+
await sleep(safeInterval, { signal });
|
|
2200
|
+
}
|
|
2201
|
+
if (aborted) break;
|
|
2202
|
+
}
|
|
2203
|
+
if (!aborted) {
|
|
2204
|
+
await safeWriteAsync(cursor.save() + screen.clearLine() + "\r" + safeText + cursor.restore());
|
|
2205
|
+
}
|
|
2206
|
+
} finally {
|
|
2207
|
+
showCursorSafe();
|
|
2208
|
+
if (newline) writeln();
|
|
2209
|
+
fireDone(hooks, aborted);
|
|
2210
|
+
}
|
|
2211
|
+
};
|
|
2212
|
+
var countUp = async (from, to, opts = {}) => {
|
|
2213
|
+
const {
|
|
2214
|
+
duration = 1500,
|
|
2215
|
+
steps = 60,
|
|
2216
|
+
decimals = 0,
|
|
2217
|
+
format = (n) => n.toString(),
|
|
2218
|
+
easing = (t) => t,
|
|
2219
|
+
newline = true,
|
|
2220
|
+
signal,
|
|
2221
|
+
reducedMotion = false,
|
|
2222
|
+
onFrame,
|
|
2223
|
+
onDone,
|
|
2224
|
+
onAbort
|
|
2225
|
+
} = opts;
|
|
2226
|
+
const hooks = { onFrame, onDone, onAbort };
|
|
2227
|
+
const safeFrom = Number.isFinite(from) ? from : 0;
|
|
2228
|
+
const safeTo = Number.isFinite(to) ? to : 0;
|
|
2229
|
+
const safeDecimals = Math.max(0, Math.min(20, Math.floor(decimals)));
|
|
2230
|
+
const safeFormat = typeof format === "function" ? format : (n) => n.toString();
|
|
2231
|
+
const safeEasing = typeof easing === "function" ? easing : (t) => t;
|
|
2232
|
+
if (reducedMotion || isAborted(signal)) {
|
|
2233
|
+
safeWrite(safeFormat(parseFloat(safeTo.toFixed(safeDecimals))));
|
|
2234
|
+
if (newline) writeln();
|
|
2235
|
+
fireDone(hooks, isAborted(signal));
|
|
2236
|
+
return;
|
|
2237
|
+
}
|
|
2238
|
+
const safeSteps2 = Math.max(1, Math.round(steps));
|
|
2239
|
+
const interval = Math.max(FRAME_MS, Math.round(duration / safeSteps2));
|
|
2240
|
+
registerCrashHandlers();
|
|
2241
|
+
hideCursorSafe();
|
|
2242
|
+
let aborted = false;
|
|
2243
|
+
let frame2 = 0;
|
|
2244
|
+
try {
|
|
2245
|
+
for (let i = 0; i <= safeSteps2; i++) {
|
|
2246
|
+
if (isAborted(signal)) {
|
|
2247
|
+
aborted = true;
|
|
2248
|
+
break;
|
|
2249
|
+
}
|
|
2250
|
+
const t = i / safeSteps2;
|
|
2251
|
+
const eased = safeEasing(Math.max(0, Math.min(1, t)));
|
|
2252
|
+
const current = safeFrom + (safeTo - safeFrom) * eased;
|
|
2253
|
+
const rounded = parseFloat(current.toFixed(safeDecimals));
|
|
2254
|
+
let display;
|
|
2255
|
+
try {
|
|
2256
|
+
display = safeFormat(rounded);
|
|
2257
|
+
} catch {
|
|
2258
|
+
display = String(rounded);
|
|
2259
|
+
}
|
|
2260
|
+
await safeWriteAsync(
|
|
2261
|
+
cursor.save() + screen.clearLine() + "\r" + display + cursor.restore()
|
|
2262
|
+
);
|
|
2263
|
+
fireFrame(hooks, frame2++);
|
|
2264
|
+
if (i < safeSteps2) await sleep(interval, { signal });
|
|
2265
|
+
}
|
|
2266
|
+
if (!aborted) {
|
|
2267
|
+
const final = parseFloat(safeTo.toFixed(safeDecimals));
|
|
2268
|
+
let display;
|
|
2269
|
+
try {
|
|
2270
|
+
display = safeFormat(final);
|
|
2271
|
+
} catch {
|
|
2272
|
+
display = String(final);
|
|
2273
|
+
}
|
|
2274
|
+
await safeWriteAsync(
|
|
2275
|
+
cursor.save() + screen.clearLine() + "\r" + display + cursor.restore()
|
|
2276
|
+
);
|
|
2277
|
+
}
|
|
2278
|
+
} finally {
|
|
2279
|
+
showCursorSafe();
|
|
2280
|
+
if (newline) writeln();
|
|
2281
|
+
fireDone(hooks, aborted);
|
|
2282
|
+
}
|
|
2283
|
+
};
|
|
2114
2284
|
var animate = {
|
|
2115
2285
|
typewriter,
|
|
2116
2286
|
fadeIn,
|
|
@@ -2123,7 +2293,10 @@ var animate = {
|
|
|
2123
2293
|
sequence,
|
|
2124
2294
|
chain: chain2,
|
|
2125
2295
|
parallel,
|
|
2126
|
-
delay
|
|
2296
|
+
delay,
|
|
2297
|
+
// v1.3.4
|
|
2298
|
+
shake,
|
|
2299
|
+
countUp
|
|
2127
2300
|
};
|
|
2128
2301
|
|
|
2129
2302
|
// src/ascii/index.ts
|
|
@@ -2457,23 +2630,61 @@ var banner = (text, opts = {}) => {
|
|
|
2457
2630
|
};
|
|
2458
2631
|
var box = (text, opts = {}) => {
|
|
2459
2632
|
const safe = ensureString2(text, "box(text)");
|
|
2460
|
-
const {
|
|
2633
|
+
const {
|
|
2634
|
+
padding = 1,
|
|
2635
|
+
borderStyle = "rounded",
|
|
2636
|
+
width = null,
|
|
2637
|
+
title = null,
|
|
2638
|
+
// v1.3.3
|
|
2639
|
+
titleAlign = "center"
|
|
2640
|
+
// v1.3.3
|
|
2641
|
+
} = opts;
|
|
2461
2642
|
const padNum = typeof padding === "number" && Number.isFinite(padding) ? padding : 1;
|
|
2462
2643
|
const safePadding = Math.max(0, Math.floor(padNum));
|
|
2463
2644
|
const b = BOX_STYLES[borderStyle] ?? BOX_STYLES.rounded;
|
|
2464
2645
|
const lines = safe.split("\n");
|
|
2465
2646
|
const inner = width != null ? lines.map((l) => padEnd(truncateAnsi(l, width, ""), width)) : lines;
|
|
2466
|
-
const
|
|
2647
|
+
const contentW = inner.length > 0 ? Math.max(0, ...inner.map((l) => visibleLen(l))) : 0;
|
|
2648
|
+
let w = contentW;
|
|
2649
|
+
let titleStr = "";
|
|
2650
|
+
let titleW = 0;
|
|
2651
|
+
if (typeof title === "string" && title.length > 0) {
|
|
2652
|
+
titleStr = ` ${title} `;
|
|
2653
|
+
titleW = visibleLen(titleStr);
|
|
2654
|
+
const titleNeeded = titleW + 2;
|
|
2655
|
+
const innerNeeded = w + safePadding * 2;
|
|
2656
|
+
if (titleNeeded > innerNeeded) {
|
|
2657
|
+
w = titleNeeded - safePadding * 2;
|
|
2658
|
+
}
|
|
2659
|
+
}
|
|
2660
|
+
const innerW = w + safePadding * 2;
|
|
2467
2661
|
const pad = " ".repeat(safePadding);
|
|
2468
|
-
|
|
2469
|
-
|
|
2470
|
-
|
|
2662
|
+
let top;
|
|
2663
|
+
if (titleStr.length > 0 && titleW < innerW) {
|
|
2664
|
+
let before;
|
|
2665
|
+
let after;
|
|
2666
|
+
if (titleAlign === "left") {
|
|
2667
|
+
before = 1;
|
|
2668
|
+
after = innerW - titleW - before;
|
|
2669
|
+
} else if (titleAlign === "right") {
|
|
2670
|
+
after = 1;
|
|
2671
|
+
before = innerW - titleW - after;
|
|
2672
|
+
} else {
|
|
2673
|
+
before = Math.floor((innerW - titleW) / 2);
|
|
2674
|
+
after = innerW - titleW - before;
|
|
2675
|
+
}
|
|
2676
|
+
top = b.tl + b.h.repeat(before) + titleStr + b.h.repeat(after) + b.tr;
|
|
2677
|
+
} else {
|
|
2678
|
+
top = b.tl + b.h.repeat(innerW) + b.tr;
|
|
2679
|
+
}
|
|
2680
|
+
const bottom = b.bl + b.h.repeat(innerW) + b.br;
|
|
2681
|
+
const emptyRow = b.v + " ".repeat(innerW) + b.v;
|
|
2471
2682
|
const rows = inner.map((l) => b.v + pad + padEnd(l, w) + pad + b.v);
|
|
2472
2683
|
const vPad = Array(safePadding).fill(emptyRow);
|
|
2473
2684
|
return [top, ...vPad, ...rows, ...vPad, bottom].join("\n");
|
|
2474
2685
|
};
|
|
2475
2686
|
var divider = (opts = {}) => {
|
|
2476
|
-
const { char, width = null, label = null, style = "single" } = opts;
|
|
2687
|
+
const { char, width = null, label = null, style = "single", align = "center" } = opts;
|
|
2477
2688
|
const { cols } = termSize();
|
|
2478
2689
|
const w = Math.max(0, width ?? cols);
|
|
2479
2690
|
const b = BOX_STYLES[style] ?? BOX_STYLES.single;
|
|
@@ -2482,8 +2693,18 @@ var divider = (opts = {}) => {
|
|
|
2482
2693
|
if (label) {
|
|
2483
2694
|
const labelLen = visibleLen(label);
|
|
2484
2695
|
if (labelLen >= w - 2) return label;
|
|
2485
|
-
|
|
2486
|
-
|
|
2696
|
+
let side;
|
|
2697
|
+
let trailLen;
|
|
2698
|
+
if (align === "left") {
|
|
2699
|
+
side = 1;
|
|
2700
|
+
trailLen = Math.max(0, w - labelLen - side - 2);
|
|
2701
|
+
} else if (align === "right") {
|
|
2702
|
+
trailLen = 1;
|
|
2703
|
+
side = Math.max(0, w - labelLen - trailLen - 2);
|
|
2704
|
+
} else {
|
|
2705
|
+
side = Math.max(0, Math.floor((w - labelLen - 2) / 2));
|
|
2706
|
+
trailLen = Math.max(0, w - side - labelLen - 2);
|
|
2707
|
+
}
|
|
2487
2708
|
return fill.repeat(side) + " " + label + " " + fill.repeat(trailLen);
|
|
2488
2709
|
}
|
|
2489
2710
|
return fill.repeat(w);
|
|
@@ -4004,7 +4225,7 @@ var progressBar = (percent, opts = {}) => {
|
|
|
4004
4225
|
showPercentage = true,
|
|
4005
4226
|
label = "",
|
|
4006
4227
|
color: color2 = null,
|
|
4007
|
-
gradient:
|
|
4228
|
+
gradient: gradientStops2 = null
|
|
4008
4229
|
} = opts;
|
|
4009
4230
|
const safeWidth = clampPositive2(width, 30);
|
|
4010
4231
|
const safeChar = typeof char === "string" && char.length > 0 ? char : "\u2588";
|
|
@@ -4014,8 +4235,8 @@ var progressBar = (percent, opts = {}) => {
|
|
|
4014
4235
|
const filled = Math.floor(clamped / 100 * safeWidth);
|
|
4015
4236
|
const empty = Math.max(0, safeWidth - filled);
|
|
4016
4237
|
let filledStr = safeChar.repeat(filled);
|
|
4017
|
-
if (Array.isArray(
|
|
4018
|
-
filledStr = gradient(filledStr,
|
|
4238
|
+
if (Array.isArray(gradientStops2) && gradientStops2.length >= 1 && filled > 0) {
|
|
4239
|
+
filledStr = gradient(filledStr, gradientStops2);
|
|
4019
4240
|
} else if (color2 !== null && isFiniteNumber4(color2)) {
|
|
4020
4241
|
filledStr = sgr(safeSgrCode(color2, FG.white)) + filledStr + reset();
|
|
4021
4242
|
}
|
|
@@ -5136,16 +5357,16 @@ var ensurePixelGrid = (pixels) => {
|
|
|
5136
5357
|
return pixels.map((row) => Array.isArray(row) ? row : []);
|
|
5137
5358
|
};
|
|
5138
5359
|
var renderPixelArt = (pixels, opts = {}) => {
|
|
5139
|
-
const
|
|
5140
|
-
if (!
|
|
5360
|
+
const grid2 = ensurePixelGrid(pixels);
|
|
5361
|
+
if (!grid2 || grid2.length === 0) return "";
|
|
5141
5362
|
const { scale = 1, halfBlock = true, braille = false } = opts;
|
|
5142
5363
|
const safeScale = clampInt(scale, 1, 100, 1);
|
|
5143
|
-
if (braille) return _renderBraille(
|
|
5364
|
+
if (braille) return _renderBraille(grid2);
|
|
5144
5365
|
const lines = [];
|
|
5145
5366
|
if (halfBlock) {
|
|
5146
|
-
for (let row = 0; row <
|
|
5147
|
-
const topRow =
|
|
5148
|
-
const botRow =
|
|
5367
|
+
for (let row = 0; row < grid2.length; row += 2) {
|
|
5368
|
+
const topRow = grid2[row] ?? [];
|
|
5369
|
+
const botRow = grid2[row + 1] ?? [];
|
|
5149
5370
|
const colCount = Math.max(topRow.length, botRow.length);
|
|
5150
5371
|
let line = "";
|
|
5151
5372
|
let curFg = -1;
|
|
@@ -5202,7 +5423,7 @@ var renderPixelArt = (pixels, opts = {}) => {
|
|
|
5202
5423
|
lines.push(line);
|
|
5203
5424
|
}
|
|
5204
5425
|
} else {
|
|
5205
|
-
for (const row of
|
|
5426
|
+
for (const row of grid2) {
|
|
5206
5427
|
let line = "";
|
|
5207
5428
|
let curFg = -1;
|
|
5208
5429
|
for (const pixel of row) {
|
|
@@ -5317,24 +5538,24 @@ var SPRITES = {
|
|
|
5317
5538
|
] }
|
|
5318
5539
|
};
|
|
5319
5540
|
var flipHorizontal = (pixels) => {
|
|
5320
|
-
const
|
|
5321
|
-
if (!
|
|
5322
|
-
return
|
|
5541
|
+
const grid2 = ensurePixelGrid(pixels);
|
|
5542
|
+
if (!grid2) return [];
|
|
5543
|
+
return grid2.map((row) => [...row].reverse());
|
|
5323
5544
|
};
|
|
5324
5545
|
var flipVertical = (pixels) => {
|
|
5325
|
-
const
|
|
5326
|
-
if (!
|
|
5327
|
-
return [...
|
|
5546
|
+
const grid2 = ensurePixelGrid(pixels);
|
|
5547
|
+
if (!grid2) return [];
|
|
5548
|
+
return [...grid2].reverse();
|
|
5328
5549
|
};
|
|
5329
5550
|
var rotate90 = (pixels) => {
|
|
5330
|
-
const
|
|
5331
|
-
if (!
|
|
5332
|
-
const rows =
|
|
5333
|
-
const cols = Math.max(0, ...
|
|
5551
|
+
const grid2 = ensurePixelGrid(pixels);
|
|
5552
|
+
if (!grid2 || grid2.length === 0) return [];
|
|
5553
|
+
const rows = grid2.length;
|
|
5554
|
+
const cols = Math.max(0, ...grid2.map((r) => r.length));
|
|
5334
5555
|
if (cols === 0) return [];
|
|
5335
5556
|
return Array.from(
|
|
5336
5557
|
{ length: cols },
|
|
5337
|
-
(_, c) => Array.from({ length: rows }, (__, r) =>
|
|
5558
|
+
(_, c) => Array.from({ length: rows }, (__, r) => grid2[rows - 1 - r]?.[c] ?? null)
|
|
5338
5559
|
);
|
|
5339
5560
|
};
|
|
5340
5561
|
var BAYER_4x4 = [
|
|
@@ -5729,7 +5950,9 @@ var frame = (block, opts = {}) => {
|
|
|
5729
5950
|
paddingX,
|
|
5730
5951
|
topChar = "\u2500",
|
|
5731
5952
|
bottomChar,
|
|
5732
|
-
title
|
|
5953
|
+
title,
|
|
5954
|
+
titleAlign = "center"
|
|
5955
|
+
// v1.3.3
|
|
5733
5956
|
} = opts;
|
|
5734
5957
|
const safePadY = Math.max(0, Math.floor(paddingY ?? padding));
|
|
5735
5958
|
const safePadX = Math.max(0, Math.floor(paddingX ?? padding));
|
|
@@ -5750,8 +5973,18 @@ var frame = (block, opts = {}) => {
|
|
|
5750
5973
|
}
|
|
5751
5974
|
let topLine;
|
|
5752
5975
|
if (titleStr.length > 0 && titleW < innerW) {
|
|
5753
|
-
|
|
5754
|
-
|
|
5976
|
+
let before;
|
|
5977
|
+
let after;
|
|
5978
|
+
if (titleAlign === "left") {
|
|
5979
|
+
before = 1;
|
|
5980
|
+
after = innerW - titleW - before;
|
|
5981
|
+
} else if (titleAlign === "right") {
|
|
5982
|
+
after = 1;
|
|
5983
|
+
before = innerW - titleW - after;
|
|
5984
|
+
} else {
|
|
5985
|
+
before = Math.floor((innerW - titleW) / 2);
|
|
5986
|
+
after = innerW - titleW - before;
|
|
5987
|
+
}
|
|
5755
5988
|
topLine = safeTop.repeat(before) + titleStr + safeTop.repeat(after);
|
|
5756
5989
|
} else {
|
|
5757
5990
|
topLine = safeTop.repeat(innerW);
|
|
@@ -5772,12 +6005,54 @@ var frame = (block, opts = {}) => {
|
|
|
5772
6005
|
out.push(bottomLine);
|
|
5773
6006
|
return out.join("\n");
|
|
5774
6007
|
};
|
|
6008
|
+
var grid = (blocks, opts) => {
|
|
6009
|
+
if (!Array.isArray(blocks) || blocks.length === 0) return "";
|
|
6010
|
+
if (!opts || typeof opts !== "object") return "";
|
|
6011
|
+
const columns2 = Math.max(1, Math.floor(opts.columns ?? 1));
|
|
6012
|
+
const gapX = Math.max(0, Math.floor(opts.gapX ?? 1));
|
|
6013
|
+
const gapY = Math.max(0, Math.floor(opts.gapY ?? 0));
|
|
6014
|
+
const alignX = opts.alignX ?? "start";
|
|
6015
|
+
const alignY = opts.alignY ?? "start";
|
|
6016
|
+
const cellW = opts.cellWidth != null ? Math.max(0, Math.floor(opts.cellWidth)) : null;
|
|
6017
|
+
const rows = [];
|
|
6018
|
+
for (let i = 0; i < blocks.length; i += columns2) {
|
|
6019
|
+
rows.push(blocks.slice(i, i + columns2));
|
|
6020
|
+
}
|
|
6021
|
+
let widths = null;
|
|
6022
|
+
if (cellW != null) {
|
|
6023
|
+
widths = Array(columns2).fill(cellW);
|
|
6024
|
+
} else {
|
|
6025
|
+
widths = Array(columns2).fill(0);
|
|
6026
|
+
for (const row of rows) {
|
|
6027
|
+
for (let c = 0; c < row.length; c++) {
|
|
6028
|
+
const { maxWidth } = _splitBlock(row[c]);
|
|
6029
|
+
if (maxWidth > widths[c]) {
|
|
6030
|
+
widths[c] = maxWidth;
|
|
6031
|
+
}
|
|
6032
|
+
}
|
|
6033
|
+
}
|
|
6034
|
+
}
|
|
6035
|
+
const renderedRows = rows.map((row) => {
|
|
6036
|
+
const padded = [];
|
|
6037
|
+
for (let c = 0; c < columns2; c++) {
|
|
6038
|
+
padded.push(row[c] ?? "");
|
|
6039
|
+
}
|
|
6040
|
+
return vsplit(padded, {
|
|
6041
|
+
gap: gapX,
|
|
6042
|
+
align: alignY,
|
|
6043
|
+
widths
|
|
6044
|
+
});
|
|
6045
|
+
});
|
|
6046
|
+
return hsplit(renderedRows, { gap: gapY, align: alignX });
|
|
6047
|
+
};
|
|
5775
6048
|
var panels = {
|
|
5776
6049
|
vsplit,
|
|
5777
6050
|
hsplit,
|
|
5778
6051
|
// v1.3.1
|
|
5779
6052
|
center: center2,
|
|
5780
|
-
frame
|
|
6053
|
+
frame,
|
|
6054
|
+
// v1.3.3
|
|
6055
|
+
grid
|
|
5781
6056
|
};
|
|
5782
6057
|
|
|
5783
6058
|
// src/json/index.ts
|
|
@@ -5797,11 +6072,12 @@ var _truncString = (s, maxLength) => {
|
|
|
5797
6072
|
return s.slice(0, maxLength - 3) + "...";
|
|
5798
6073
|
};
|
|
5799
6074
|
var _formatPrimitive = (value, opts) => {
|
|
5800
|
-
const { useColor, maxStringLength } = opts;
|
|
6075
|
+
const { useColor, maxStringLength, mode } = opts;
|
|
5801
6076
|
if (value === null) {
|
|
5802
6077
|
return _c("null", COLORS.null, useColor);
|
|
5803
6078
|
}
|
|
5804
6079
|
if (value === void 0) {
|
|
6080
|
+
if (mode === "json") return _c("null", COLORS.null, useColor);
|
|
5805
6081
|
return _c("undefined", COLORS.null, useColor);
|
|
5806
6082
|
}
|
|
5807
6083
|
if (typeof value === "string") {
|
|
@@ -5810,8 +6086,12 @@ var _formatPrimitive = (value, opts) => {
|
|
|
5810
6086
|
return _c(quoted, COLORS.string, useColor);
|
|
5811
6087
|
}
|
|
5812
6088
|
if (typeof value === "number") {
|
|
5813
|
-
if (Number.isNaN(value))
|
|
6089
|
+
if (Number.isNaN(value)) {
|
|
6090
|
+
if (mode === "json") return _c("null", COLORS.null, useColor);
|
|
6091
|
+
return _c("NaN", COLORS.number, useColor);
|
|
6092
|
+
}
|
|
5814
6093
|
if (!Number.isFinite(value)) {
|
|
6094
|
+
if (mode === "json") return _c("null", COLORS.null, useColor);
|
|
5815
6095
|
return _c(value > 0 ? "Infinity" : "-Infinity", COLORS.number, useColor);
|
|
5816
6096
|
}
|
|
5817
6097
|
return _c(String(value), COLORS.number, useColor);
|
|
@@ -5820,16 +6100,23 @@ var _formatPrimitive = (value, opts) => {
|
|
|
5820
6100
|
return _c(String(value), COLORS.boolean, useColor);
|
|
5821
6101
|
}
|
|
5822
6102
|
if (typeof value === "bigint") {
|
|
6103
|
+
if (mode === "json") {
|
|
6104
|
+
const big2 = value;
|
|
6105
|
+
const asNum = Number(big2);
|
|
6106
|
+
if (Number.isSafeInteger(asNum) && BigInt(asNum) === big2) {
|
|
6107
|
+
return _c(String(asNum), COLORS.number, useColor);
|
|
6108
|
+
}
|
|
6109
|
+
return _c(JSON.stringify(String(big2)), COLORS.string, useColor);
|
|
6110
|
+
}
|
|
5823
6111
|
return _c(`${value}n`, COLORS.number, useColor);
|
|
5824
6112
|
}
|
|
5825
6113
|
if (typeof value === "function") {
|
|
6114
|
+
if (mode === "json") return _c("null", COLORS.null, useColor);
|
|
5826
6115
|
const name = value.name || "anonymous";
|
|
5827
6116
|
return _c(`[Function: ${name}]`, COLORS.comment, useColor);
|
|
5828
6117
|
}
|
|
5829
|
-
if (
|
|
5830
|
-
|
|
5831
|
-
}
|
|
5832
|
-
return _c(String(value), COLORS.comment, useColor);
|
|
6118
|
+
if (mode === "json") return _c("null", COLORS.null, useColor);
|
|
6119
|
+
return _c(value.toString(), COLORS.comment, useColor);
|
|
5833
6120
|
};
|
|
5834
6121
|
var _renderValue = (value, depth, config) => {
|
|
5835
6122
|
const {
|
|
@@ -5840,15 +6127,56 @@ var _renderValue = (value, depth, config) => {
|
|
|
5840
6127
|
useColor,
|
|
5841
6128
|
seen,
|
|
5842
6129
|
sortKeys,
|
|
5843
|
-
inlineArrayMaxLength
|
|
6130
|
+
inlineArrayMaxLength,
|
|
6131
|
+
mode
|
|
5844
6132
|
} = config;
|
|
5845
6133
|
if (value === null || typeof value !== "object") {
|
|
5846
|
-
return _formatPrimitive(value, { useColor, maxStringLength });
|
|
6134
|
+
return _formatPrimitive(value, { useColor, maxStringLength, mode });
|
|
5847
6135
|
}
|
|
5848
6136
|
if (seen.has(value)) {
|
|
6137
|
+
if (mode === "json") {
|
|
6138
|
+
throw new TypeError("Cannot serialize circular reference to JSON");
|
|
6139
|
+
}
|
|
5849
6140
|
return _c("[Circular]", COLORS.comment, useColor);
|
|
5850
6141
|
}
|
|
5851
6142
|
seen.add(value);
|
|
6143
|
+
if (value instanceof Date) {
|
|
6144
|
+
const iso = value.toISOString();
|
|
6145
|
+
if (mode === "json") {
|
|
6146
|
+
return _c(JSON.stringify(iso), COLORS.string, useColor);
|
|
6147
|
+
}
|
|
6148
|
+
return _c(`Date(${iso})`, COLORS.comment, useColor);
|
|
6149
|
+
}
|
|
6150
|
+
if (value instanceof Map) {
|
|
6151
|
+
if (mode === "json") {
|
|
6152
|
+
const obj = {};
|
|
6153
|
+
for (const [k, v] of value) {
|
|
6154
|
+
if (typeof k === "string") obj[k] = v;
|
|
6155
|
+
else obj[String(k)] = v;
|
|
6156
|
+
}
|
|
6157
|
+
return _renderValue(obj, depth, config);
|
|
6158
|
+
}
|
|
6159
|
+
const entries2 = Array.from(value);
|
|
6160
|
+
const sizeLabel = _c(`Map(${entries2.length})`, COLORS.comment, useColor);
|
|
6161
|
+
if (entries2.length === 0) {
|
|
6162
|
+
return `${sizeLabel} ${_c("{}", COLORS.bracket, useColor)}`;
|
|
6163
|
+
}
|
|
6164
|
+
if (depth >= maxDepth - 1 && depth > 0) {
|
|
6165
|
+
return `${sizeLabel} ${_c("{...}", COLORS.bracket, useColor)}`;
|
|
6166
|
+
}
|
|
6167
|
+
return `${sizeLabel} ${_renderValue(entries2, depth, config)}`;
|
|
6168
|
+
}
|
|
6169
|
+
if (value instanceof Set) {
|
|
6170
|
+
if (mode === "json") {
|
|
6171
|
+
return _renderValue(Array.from(value), depth, config);
|
|
6172
|
+
}
|
|
6173
|
+
const arr = Array.from(value);
|
|
6174
|
+
const sizeLabel = _c(`Set(${arr.length})`, COLORS.comment, useColor);
|
|
6175
|
+
if (arr.length === 0) {
|
|
6176
|
+
return `${sizeLabel} ${_c("[]", COLORS.bracket, useColor)}`;
|
|
6177
|
+
}
|
|
6178
|
+
return `${sizeLabel} ${_renderValue(arr, depth, config)}`;
|
|
6179
|
+
}
|
|
5852
6180
|
if (depth >= maxDepth) {
|
|
5853
6181
|
if (Array.isArray(value)) {
|
|
5854
6182
|
return _c("[", COLORS.bracket, useColor) + _c("...", COLORS.comment, useColor) + _c("]", COLORS.bracket, useColor);
|
|
@@ -5867,7 +6195,7 @@ var _renderValue = (value, depth, config) => {
|
|
|
5867
6195
|
const displayCount2 = Math.min(value.length, maxItems);
|
|
5868
6196
|
const inlineItems = [];
|
|
5869
6197
|
for (let i = 0; i < displayCount2; i++) {
|
|
5870
|
-
inlineItems.push(_formatPrimitive(value[i], { useColor, maxStringLength }));
|
|
6198
|
+
inlineItems.push(_formatPrimitive(value[i], { useColor, maxStringLength, mode }));
|
|
5871
6199
|
}
|
|
5872
6200
|
if (value.length > maxItems) {
|
|
5873
6201
|
const remaining = value.length - maxItems;
|
|
@@ -5893,6 +6221,12 @@ var _renderValue = (value, depth, config) => {
|
|
|
5893
6221
|
return _c("[", COLORS.bracket, useColor) + "\n" + items.join(",\n") + "\n" + closePad + _c("]", COLORS.bracket, useColor);
|
|
5894
6222
|
}
|
|
5895
6223
|
let keys = Object.keys(value);
|
|
6224
|
+
if (mode === "json") {
|
|
6225
|
+
keys = keys.filter((k) => {
|
|
6226
|
+
const v = value[k];
|
|
6227
|
+
return typeof v !== "function" && typeof v !== "symbol" && v !== void 0;
|
|
6228
|
+
});
|
|
6229
|
+
}
|
|
5896
6230
|
if (keys.length === 0) {
|
|
5897
6231
|
return _c("{}", COLORS.bracket, useColor);
|
|
5898
6232
|
}
|
|
@@ -5921,14 +6255,17 @@ var pretty = (value, opts = {}) => {
|
|
|
5921
6255
|
maxStringLength = Infinity,
|
|
5922
6256
|
// v1.3.1
|
|
5923
6257
|
sortKeys = false,
|
|
5924
|
-
inlineArrayMaxLength = 60
|
|
6258
|
+
inlineArrayMaxLength = 60,
|
|
6259
|
+
// v1.3.3
|
|
6260
|
+
mode = "display"
|
|
5925
6261
|
} = opts;
|
|
5926
6262
|
const safeIndent = Math.max(0, Math.floor(Number(indent) || 0));
|
|
5927
6263
|
const safeMaxDepth = Number.isFinite(maxDepth) ? Math.max(0, Math.floor(maxDepth)) : Infinity;
|
|
5928
6264
|
const safeMaxItems = Number.isFinite(maxItems) ? Math.max(0, Math.floor(maxItems)) : Infinity;
|
|
5929
6265
|
const safeMaxStrLen = Number.isFinite(maxStringLength) ? Math.max(0, Math.floor(maxStringLength)) : Infinity;
|
|
5930
6266
|
const safeInlineMax = Number.isFinite(inlineArrayMaxLength) ? Math.max(0, Math.floor(inlineArrayMaxLength)) : 60;
|
|
5931
|
-
const
|
|
6267
|
+
const safeMode = mode === "json" ? "json" : "display";
|
|
6268
|
+
const useColor = safeMode === "json" ? false : colors && !isNoColor();
|
|
5932
6269
|
return _renderValue(value, 0, {
|
|
5933
6270
|
indent: safeIndent,
|
|
5934
6271
|
maxDepth: safeMaxDepth,
|
|
@@ -5937,7 +6274,8 @@ var pretty = (value, opts = {}) => {
|
|
|
5937
6274
|
useColor,
|
|
5938
6275
|
seen: /* @__PURE__ */ new WeakSet(),
|
|
5939
6276
|
sortKeys: Boolean(sortKeys),
|
|
5940
|
-
inlineArrayMaxLength: safeInlineMax
|
|
6277
|
+
inlineArrayMaxLength: safeInlineMax,
|
|
6278
|
+
mode: safeMode
|
|
5941
6279
|
});
|
|
5942
6280
|
};
|
|
5943
6281
|
var json = {
|
|
@@ -6156,6 +6494,10 @@ var withConfig = (overrides, fn) => {
|
|
|
6156
6494
|
throw err;
|
|
6157
6495
|
}
|
|
6158
6496
|
};
|
|
6497
|
+
var setConfigValue = (key, value) => {
|
|
6498
|
+
configure({ [key]: value });
|
|
6499
|
+
};
|
|
6500
|
+
var subscribeConfig = onConfigChange;
|
|
6159
6501
|
|
|
6160
6502
|
// src/index.ts
|
|
6161
6503
|
var ansimax = { color, animate, ascii, loader, frames, components, trees, themes, images, configure };
|
|
@@ -6194,6 +6536,7 @@ var index_default = ansimax;
|
|
|
6194
6536
|
clamp,
|
|
6195
6537
|
clearAnsiCache,
|
|
6196
6538
|
clearColorCache,
|
|
6539
|
+
clearLine,
|
|
6197
6540
|
clearRenderCache,
|
|
6198
6541
|
clearThemeColorCache,
|
|
6199
6542
|
color,
|
|
@@ -6210,6 +6553,7 @@ var index_default = ansimax;
|
|
|
6210
6553
|
cursor,
|
|
6211
6554
|
debounce,
|
|
6212
6555
|
diffLines,
|
|
6556
|
+
escapeForRegex,
|
|
6213
6557
|
escapeRegex,
|
|
6214
6558
|
fg256,
|
|
6215
6559
|
fgRgb,
|
|
@@ -6230,11 +6574,14 @@ var index_default = ansimax;
|
|
|
6230
6574
|
gradient,
|
|
6231
6575
|
gradientColor,
|
|
6232
6576
|
gradientRect,
|
|
6577
|
+
gradientStops,
|
|
6233
6578
|
graphemes,
|
|
6579
|
+
grid,
|
|
6234
6580
|
hasFont,
|
|
6235
6581
|
hexToRgb,
|
|
6236
6582
|
hideCursor,
|
|
6237
6583
|
hsplit,
|
|
6584
|
+
hyperlink,
|
|
6238
6585
|
images,
|
|
6239
6586
|
isHexColor,
|
|
6240
6587
|
isNoColor,
|
|
@@ -6247,6 +6594,7 @@ var index_default = ansimax;
|
|
|
6247
6594
|
listPresets,
|
|
6248
6595
|
loader,
|
|
6249
6596
|
mapTree,
|
|
6597
|
+
measureBlock,
|
|
6250
6598
|
measureTree,
|
|
6251
6599
|
memoize,
|
|
6252
6600
|
nextTick,
|
|
@@ -6284,6 +6632,7 @@ var index_default = ansimax;
|
|
|
6284
6632
|
rotate90,
|
|
6285
6633
|
safeJson,
|
|
6286
6634
|
screen,
|
|
6635
|
+
setConfigValue,
|
|
6287
6636
|
setNoColor,
|
|
6288
6637
|
setTitle,
|
|
6289
6638
|
sgr,
|
|
@@ -6294,6 +6643,7 @@ var index_default = ansimax;
|
|
|
6294
6643
|
stripAnsi,
|
|
6295
6644
|
stripAnsiCodes,
|
|
6296
6645
|
stripAnsiColors,
|
|
6646
|
+
subscribeConfig,
|
|
6297
6647
|
supportsColor,
|
|
6298
6648
|
supportsColorLevel,
|
|
6299
6649
|
termSize,
|