ansimax 1.3.3 → 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 +141 -0
- package/README.es.md +31 -3
- package/README.md +31 -3
- package/dist/index.d.mts +346 -195
- package/dist/index.d.ts +346 -195
- package/dist/index.js +187 -4
- package/dist/index.mjs +180 -4
- 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,12 +101,14 @@ __export(index_exports, {
|
|
|
99
101
|
gradient: () => gradient,
|
|
100
102
|
gradientColor: () => gradientColor,
|
|
101
103
|
gradientRect: () => gradientRect,
|
|
104
|
+
gradientStops: () => gradientStops,
|
|
102
105
|
graphemes: () => graphemes,
|
|
103
106
|
grid: () => grid,
|
|
104
107
|
hasFont: () => hasFont,
|
|
105
108
|
hexToRgb: () => hexToRgb,
|
|
106
109
|
hideCursor: () => hideCursor,
|
|
107
110
|
hsplit: () => hsplit,
|
|
111
|
+
hyperlink: () => hyperlink,
|
|
108
112
|
images: () => images,
|
|
109
113
|
isHexColor: () => isHexColor,
|
|
110
114
|
isNoColor: () => isNoColor,
|
|
@@ -117,6 +121,7 @@ __export(index_exports, {
|
|
|
117
121
|
listPresets: () => listPresets,
|
|
118
122
|
loader: () => loader,
|
|
119
123
|
mapTree: () => mapTree,
|
|
124
|
+
measureBlock: () => measureBlock,
|
|
120
125
|
measureTree: () => measureTree,
|
|
121
126
|
memoize: () => memoize,
|
|
122
127
|
nextTick: () => nextTick,
|
|
@@ -154,6 +159,7 @@ __export(index_exports, {
|
|
|
154
159
|
rotate90: () => rotate90,
|
|
155
160
|
safeJson: () => safeJson,
|
|
156
161
|
screen: () => screen,
|
|
162
|
+
setConfigValue: () => setConfigValue,
|
|
157
163
|
setNoColor: () => setNoColor,
|
|
158
164
|
setTitle: () => setTitle,
|
|
159
165
|
sgr: () => sgr,
|
|
@@ -164,6 +170,7 @@ __export(index_exports, {
|
|
|
164
170
|
stripAnsi: () => stripAnsi2,
|
|
165
171
|
stripAnsiCodes: () => stripAnsi,
|
|
166
172
|
stripAnsiColors: () => stripAnsi3,
|
|
173
|
+
subscribeConfig: () => subscribeConfig,
|
|
167
174
|
supportsColor: () => supportsColor,
|
|
168
175
|
supportsColorLevel: () => supportsColorLevel,
|
|
169
176
|
termSize: () => termSize,
|
|
@@ -567,6 +574,14 @@ var sleepFrame = (ms = FRAME_MS, opts = {}) => sleep(
|
|
|
567
574
|
Math.max(FRAME_MS, Math.round((isFiniteNumber(ms) ? ms : FRAME_MS) / FRAME_MS) * FRAME_MS),
|
|
568
575
|
opts
|
|
569
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`;
|
|
570
585
|
|
|
571
586
|
// src/utils/helpers.ts
|
|
572
587
|
var clamp = (n, min, max) => Math.min(Math.max(n, min), max);
|
|
@@ -989,6 +1004,35 @@ var padBoth = (str, width, ch = " ") => {
|
|
|
989
1004
|
const r = pad - l;
|
|
990
1005
|
return ch.repeat(l) + str + ch.repeat(r);
|
|
991
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
|
+
};
|
|
992
1036
|
|
|
993
1037
|
// src/colors/index.ts
|
|
994
1038
|
var _noColor = null;
|
|
@@ -2112,6 +2156,131 @@ var delay = (ms) => async (opts = {}) => {
|
|
|
2112
2156
|
} catch {
|
|
2113
2157
|
}
|
|
2114
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
|
+
};
|
|
2115
2284
|
var animate = {
|
|
2116
2285
|
typewriter,
|
|
2117
2286
|
fadeIn,
|
|
@@ -2124,7 +2293,10 @@ var animate = {
|
|
|
2124
2293
|
sequence,
|
|
2125
2294
|
chain: chain2,
|
|
2126
2295
|
parallel,
|
|
2127
|
-
delay
|
|
2296
|
+
delay,
|
|
2297
|
+
// v1.3.4
|
|
2298
|
+
shake,
|
|
2299
|
+
countUp
|
|
2128
2300
|
};
|
|
2129
2301
|
|
|
2130
2302
|
// src/ascii/index.ts
|
|
@@ -4053,7 +4225,7 @@ var progressBar = (percent, opts = {}) => {
|
|
|
4053
4225
|
showPercentage = true,
|
|
4054
4226
|
label = "",
|
|
4055
4227
|
color: color2 = null,
|
|
4056
|
-
gradient:
|
|
4228
|
+
gradient: gradientStops2 = null
|
|
4057
4229
|
} = opts;
|
|
4058
4230
|
const safeWidth = clampPositive2(width, 30);
|
|
4059
4231
|
const safeChar = typeof char === "string" && char.length > 0 ? char : "\u2588";
|
|
@@ -4063,8 +4235,8 @@ var progressBar = (percent, opts = {}) => {
|
|
|
4063
4235
|
const filled = Math.floor(clamped / 100 * safeWidth);
|
|
4064
4236
|
const empty = Math.max(0, safeWidth - filled);
|
|
4065
4237
|
let filledStr = safeChar.repeat(filled);
|
|
4066
|
-
if (Array.isArray(
|
|
4067
|
-
filledStr = gradient(filledStr,
|
|
4238
|
+
if (Array.isArray(gradientStops2) && gradientStops2.length >= 1 && filled > 0) {
|
|
4239
|
+
filledStr = gradient(filledStr, gradientStops2);
|
|
4068
4240
|
} else if (color2 !== null && isFiniteNumber4(color2)) {
|
|
4069
4241
|
filledStr = sgr(safeSgrCode(color2, FG.white)) + filledStr + reset();
|
|
4070
4242
|
}
|
|
@@ -6322,6 +6494,10 @@ var withConfig = (overrides, fn) => {
|
|
|
6322
6494
|
throw err;
|
|
6323
6495
|
}
|
|
6324
6496
|
};
|
|
6497
|
+
var setConfigValue = (key, value) => {
|
|
6498
|
+
configure({ [key]: value });
|
|
6499
|
+
};
|
|
6500
|
+
var subscribeConfig = onConfigChange;
|
|
6325
6501
|
|
|
6326
6502
|
// src/index.ts
|
|
6327
6503
|
var ansimax = { color, animate, ascii, loader, frames, components, trees, themes, images, configure };
|
|
@@ -6360,6 +6536,7 @@ var index_default = ansimax;
|
|
|
6360
6536
|
clamp,
|
|
6361
6537
|
clearAnsiCache,
|
|
6362
6538
|
clearColorCache,
|
|
6539
|
+
clearLine,
|
|
6363
6540
|
clearRenderCache,
|
|
6364
6541
|
clearThemeColorCache,
|
|
6365
6542
|
color,
|
|
@@ -6376,6 +6553,7 @@ var index_default = ansimax;
|
|
|
6376
6553
|
cursor,
|
|
6377
6554
|
debounce,
|
|
6378
6555
|
diffLines,
|
|
6556
|
+
escapeForRegex,
|
|
6379
6557
|
escapeRegex,
|
|
6380
6558
|
fg256,
|
|
6381
6559
|
fgRgb,
|
|
@@ -6396,12 +6574,14 @@ var index_default = ansimax;
|
|
|
6396
6574
|
gradient,
|
|
6397
6575
|
gradientColor,
|
|
6398
6576
|
gradientRect,
|
|
6577
|
+
gradientStops,
|
|
6399
6578
|
graphemes,
|
|
6400
6579
|
grid,
|
|
6401
6580
|
hasFont,
|
|
6402
6581
|
hexToRgb,
|
|
6403
6582
|
hideCursor,
|
|
6404
6583
|
hsplit,
|
|
6584
|
+
hyperlink,
|
|
6405
6585
|
images,
|
|
6406
6586
|
isHexColor,
|
|
6407
6587
|
isNoColor,
|
|
@@ -6414,6 +6594,7 @@ var index_default = ansimax;
|
|
|
6414
6594
|
listPresets,
|
|
6415
6595
|
loader,
|
|
6416
6596
|
mapTree,
|
|
6597
|
+
measureBlock,
|
|
6417
6598
|
measureTree,
|
|
6418
6599
|
memoize,
|
|
6419
6600
|
nextTick,
|
|
@@ -6451,6 +6632,7 @@ var index_default = ansimax;
|
|
|
6451
6632
|
rotate90,
|
|
6452
6633
|
safeJson,
|
|
6453
6634
|
screen,
|
|
6635
|
+
setConfigValue,
|
|
6454
6636
|
setNoColor,
|
|
6455
6637
|
setTitle,
|
|
6456
6638
|
sgr,
|
|
@@ -6461,6 +6643,7 @@ var index_default = ansimax;
|
|
|
6461
6643
|
stripAnsi,
|
|
6462
6644
|
stripAnsiCodes,
|
|
6463
6645
|
stripAnsiColors,
|
|
6646
|
+
subscribeConfig,
|
|
6464
6647
|
supportsColor,
|
|
6465
6648
|
supportsColorLevel,
|
|
6466
6649
|
termSize,
|
package/dist/index.mjs
CHANGED
|
@@ -379,6 +379,14 @@ var sleepFrame = (ms = FRAME_MS, opts = {}) => sleep(
|
|
|
379
379
|
Math.max(FRAME_MS, Math.round((isFiniteNumber(ms) ? ms : FRAME_MS) / FRAME_MS) * FRAME_MS),
|
|
380
380
|
opts
|
|
381
381
|
);
|
|
382
|
+
var hyperlink = (url, label) => {
|
|
383
|
+
if (typeof url !== "string" || url.length === 0) {
|
|
384
|
+
return typeof label === "string" ? label : "";
|
|
385
|
+
}
|
|
386
|
+
const safeLabel = typeof label === "string" && label.length > 0 ? label : url;
|
|
387
|
+
return `${OSC}8;;${url}${ST}${safeLabel}${OSC}8;;${ST}`;
|
|
388
|
+
};
|
|
389
|
+
var clearLine = () => `${CSI}2K\r`;
|
|
382
390
|
|
|
383
391
|
// src/utils/helpers.ts
|
|
384
392
|
var clamp = (n, min, max) => Math.min(Math.max(n, min), max);
|
|
@@ -801,6 +809,35 @@ var padBoth = (str, width, ch = " ") => {
|
|
|
801
809
|
const r = pad - l;
|
|
802
810
|
return ch.repeat(l) + str + ch.repeat(r);
|
|
803
811
|
};
|
|
812
|
+
var gradientStops = (start, end, count) => {
|
|
813
|
+
const safeCount = Math.max(2, Math.floor(Number.isFinite(count) ? count : 2));
|
|
814
|
+
if (!isHexColor(start) || !isHexColor(end)) return [];
|
|
815
|
+
const a = hexToRgb(start);
|
|
816
|
+
const b = hexToRgb(end);
|
|
817
|
+
const result = [];
|
|
818
|
+
for (let i = 0; i < safeCount; i++) {
|
|
819
|
+
const t = i / (safeCount - 1);
|
|
820
|
+
const c = lerpColor(a, b, t);
|
|
821
|
+
result.push(rgbToHex(c.r, c.g, c.b));
|
|
822
|
+
}
|
|
823
|
+
return result;
|
|
824
|
+
};
|
|
825
|
+
var escapeForRegex = (str) => {
|
|
826
|
+
if (typeof str !== "string") return "";
|
|
827
|
+
return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
828
|
+
};
|
|
829
|
+
var measureBlock = (block) => {
|
|
830
|
+
if (typeof block !== "string" || block.length === 0) {
|
|
831
|
+
return { width: 0, height: 0 };
|
|
832
|
+
}
|
|
833
|
+
const lines = block.split("\n");
|
|
834
|
+
let width = 0;
|
|
835
|
+
for (const line of lines) {
|
|
836
|
+
const w = visibleLen(line);
|
|
837
|
+
if (w > width) width = w;
|
|
838
|
+
}
|
|
839
|
+
return { width, height: lines.length };
|
|
840
|
+
};
|
|
804
841
|
|
|
805
842
|
// src/colors/index.ts
|
|
806
843
|
var _noColor = null;
|
|
@@ -1924,6 +1961,131 @@ var delay = (ms) => async (opts = {}) => {
|
|
|
1924
1961
|
} catch {
|
|
1925
1962
|
}
|
|
1926
1963
|
};
|
|
1964
|
+
var shake = async (text, opts = {}) => {
|
|
1965
|
+
const {
|
|
1966
|
+
times = 5,
|
|
1967
|
+
intensity = 2,
|
|
1968
|
+
interval = 50,
|
|
1969
|
+
newline = true,
|
|
1970
|
+
signal,
|
|
1971
|
+
reducedMotion = false,
|
|
1972
|
+
onFrame,
|
|
1973
|
+
onDone,
|
|
1974
|
+
onAbort
|
|
1975
|
+
} = opts;
|
|
1976
|
+
const hooks = { onFrame, onDone, onAbort };
|
|
1977
|
+
if (reducedMotion || isAborted(signal)) {
|
|
1978
|
+
safeWrite(text);
|
|
1979
|
+
if (newline) writeln();
|
|
1980
|
+
fireDone(hooks, isAborted(signal));
|
|
1981
|
+
return;
|
|
1982
|
+
}
|
|
1983
|
+
const safeText = typeof text === "string" ? text : "";
|
|
1984
|
+
const safeTimes = Math.max(1, Math.round(times));
|
|
1985
|
+
const safeIntensity = Math.max(1, Math.round(intensity));
|
|
1986
|
+
const safeInterval = Math.max(FRAME_MS, interval);
|
|
1987
|
+
const pattern = [0, safeIntensity, 0, -safeIntensity];
|
|
1988
|
+
registerCrashHandlers();
|
|
1989
|
+
hideCursorSafe();
|
|
1990
|
+
let aborted = false;
|
|
1991
|
+
let frame2 = 0;
|
|
1992
|
+
try {
|
|
1993
|
+
for (let cycle = 0; cycle < safeTimes; cycle++) {
|
|
1994
|
+
for (const offset of pattern) {
|
|
1995
|
+
if (isAborted(signal)) {
|
|
1996
|
+
aborted = true;
|
|
1997
|
+
break;
|
|
1998
|
+
}
|
|
1999
|
+
const prefix = offset > 0 ? " ".repeat(offset) : "";
|
|
2000
|
+
await safeWriteAsync(
|
|
2001
|
+
cursor.save() + screen.clearLine() + "\r" + prefix + safeText + cursor.restore()
|
|
2002
|
+
);
|
|
2003
|
+
fireFrame(hooks, frame2++);
|
|
2004
|
+
await sleep(safeInterval, { signal });
|
|
2005
|
+
}
|
|
2006
|
+
if (aborted) break;
|
|
2007
|
+
}
|
|
2008
|
+
if (!aborted) {
|
|
2009
|
+
await safeWriteAsync(cursor.save() + screen.clearLine() + "\r" + safeText + cursor.restore());
|
|
2010
|
+
}
|
|
2011
|
+
} finally {
|
|
2012
|
+
showCursorSafe();
|
|
2013
|
+
if (newline) writeln();
|
|
2014
|
+
fireDone(hooks, aborted);
|
|
2015
|
+
}
|
|
2016
|
+
};
|
|
2017
|
+
var countUp = async (from, to, opts = {}) => {
|
|
2018
|
+
const {
|
|
2019
|
+
duration = 1500,
|
|
2020
|
+
steps = 60,
|
|
2021
|
+
decimals = 0,
|
|
2022
|
+
format = (n) => n.toString(),
|
|
2023
|
+
easing = (t) => t,
|
|
2024
|
+
newline = true,
|
|
2025
|
+
signal,
|
|
2026
|
+
reducedMotion = false,
|
|
2027
|
+
onFrame,
|
|
2028
|
+
onDone,
|
|
2029
|
+
onAbort
|
|
2030
|
+
} = opts;
|
|
2031
|
+
const hooks = { onFrame, onDone, onAbort };
|
|
2032
|
+
const safeFrom = Number.isFinite(from) ? from : 0;
|
|
2033
|
+
const safeTo = Number.isFinite(to) ? to : 0;
|
|
2034
|
+
const safeDecimals = Math.max(0, Math.min(20, Math.floor(decimals)));
|
|
2035
|
+
const safeFormat = typeof format === "function" ? format : (n) => n.toString();
|
|
2036
|
+
const safeEasing = typeof easing === "function" ? easing : (t) => t;
|
|
2037
|
+
if (reducedMotion || isAborted(signal)) {
|
|
2038
|
+
safeWrite(safeFormat(parseFloat(safeTo.toFixed(safeDecimals))));
|
|
2039
|
+
if (newline) writeln();
|
|
2040
|
+
fireDone(hooks, isAborted(signal));
|
|
2041
|
+
return;
|
|
2042
|
+
}
|
|
2043
|
+
const safeSteps2 = Math.max(1, Math.round(steps));
|
|
2044
|
+
const interval = Math.max(FRAME_MS, Math.round(duration / safeSteps2));
|
|
2045
|
+
registerCrashHandlers();
|
|
2046
|
+
hideCursorSafe();
|
|
2047
|
+
let aborted = false;
|
|
2048
|
+
let frame2 = 0;
|
|
2049
|
+
try {
|
|
2050
|
+
for (let i = 0; i <= safeSteps2; i++) {
|
|
2051
|
+
if (isAborted(signal)) {
|
|
2052
|
+
aborted = true;
|
|
2053
|
+
break;
|
|
2054
|
+
}
|
|
2055
|
+
const t = i / safeSteps2;
|
|
2056
|
+
const eased = safeEasing(Math.max(0, Math.min(1, t)));
|
|
2057
|
+
const current = safeFrom + (safeTo - safeFrom) * eased;
|
|
2058
|
+
const rounded = parseFloat(current.toFixed(safeDecimals));
|
|
2059
|
+
let display;
|
|
2060
|
+
try {
|
|
2061
|
+
display = safeFormat(rounded);
|
|
2062
|
+
} catch {
|
|
2063
|
+
display = String(rounded);
|
|
2064
|
+
}
|
|
2065
|
+
await safeWriteAsync(
|
|
2066
|
+
cursor.save() + screen.clearLine() + "\r" + display + cursor.restore()
|
|
2067
|
+
);
|
|
2068
|
+
fireFrame(hooks, frame2++);
|
|
2069
|
+
if (i < safeSteps2) await sleep(interval, { signal });
|
|
2070
|
+
}
|
|
2071
|
+
if (!aborted) {
|
|
2072
|
+
const final = parseFloat(safeTo.toFixed(safeDecimals));
|
|
2073
|
+
let display;
|
|
2074
|
+
try {
|
|
2075
|
+
display = safeFormat(final);
|
|
2076
|
+
} catch {
|
|
2077
|
+
display = String(final);
|
|
2078
|
+
}
|
|
2079
|
+
await safeWriteAsync(
|
|
2080
|
+
cursor.save() + screen.clearLine() + "\r" + display + cursor.restore()
|
|
2081
|
+
);
|
|
2082
|
+
}
|
|
2083
|
+
} finally {
|
|
2084
|
+
showCursorSafe();
|
|
2085
|
+
if (newline) writeln();
|
|
2086
|
+
fireDone(hooks, aborted);
|
|
2087
|
+
}
|
|
2088
|
+
};
|
|
1927
2089
|
var animate = {
|
|
1928
2090
|
typewriter,
|
|
1929
2091
|
fadeIn,
|
|
@@ -1936,7 +2098,10 @@ var animate = {
|
|
|
1936
2098
|
sequence,
|
|
1937
2099
|
chain: chain2,
|
|
1938
2100
|
parallel,
|
|
1939
|
-
delay
|
|
2101
|
+
delay,
|
|
2102
|
+
// v1.3.4
|
|
2103
|
+
shake,
|
|
2104
|
+
countUp
|
|
1940
2105
|
};
|
|
1941
2106
|
|
|
1942
2107
|
// src/ascii/index.ts
|
|
@@ -3865,7 +4030,7 @@ var progressBar = (percent, opts = {}) => {
|
|
|
3865
4030
|
showPercentage = true,
|
|
3866
4031
|
label = "",
|
|
3867
4032
|
color: color2 = null,
|
|
3868
|
-
gradient:
|
|
4033
|
+
gradient: gradientStops2 = null
|
|
3869
4034
|
} = opts;
|
|
3870
4035
|
const safeWidth = clampPositive2(width, 30);
|
|
3871
4036
|
const safeChar = typeof char === "string" && char.length > 0 ? char : "\u2588";
|
|
@@ -3875,8 +4040,8 @@ var progressBar = (percent, opts = {}) => {
|
|
|
3875
4040
|
const filled = Math.floor(clamped / 100 * safeWidth);
|
|
3876
4041
|
const empty = Math.max(0, safeWidth - filled);
|
|
3877
4042
|
let filledStr = safeChar.repeat(filled);
|
|
3878
|
-
if (Array.isArray(
|
|
3879
|
-
filledStr = gradient(filledStr,
|
|
4043
|
+
if (Array.isArray(gradientStops2) && gradientStops2.length >= 1 && filled > 0) {
|
|
4044
|
+
filledStr = gradient(filledStr, gradientStops2);
|
|
3880
4045
|
} else if (color2 !== null && isFiniteNumber4(color2)) {
|
|
3881
4046
|
filledStr = sgr(safeSgrCode(color2, FG.white)) + filledStr + reset();
|
|
3882
4047
|
}
|
|
@@ -6134,6 +6299,10 @@ var withConfig = (overrides, fn) => {
|
|
|
6134
6299
|
throw err;
|
|
6135
6300
|
}
|
|
6136
6301
|
};
|
|
6302
|
+
var setConfigValue = (key, value) => {
|
|
6303
|
+
configure({ [key]: value });
|
|
6304
|
+
};
|
|
6305
|
+
var subscribeConfig = onConfigChange;
|
|
6137
6306
|
|
|
6138
6307
|
// src/index.ts
|
|
6139
6308
|
var ansimax = { color, animate, ascii, loader, frames, components, trees, themes, images, configure };
|
|
@@ -6171,6 +6340,7 @@ export {
|
|
|
6171
6340
|
clamp,
|
|
6172
6341
|
clearAnsiCache,
|
|
6173
6342
|
clearColorCache,
|
|
6343
|
+
clearLine,
|
|
6174
6344
|
clearRenderCache,
|
|
6175
6345
|
clearThemeColorCache,
|
|
6176
6346
|
color,
|
|
@@ -6188,6 +6358,7 @@ export {
|
|
|
6188
6358
|
debounce,
|
|
6189
6359
|
index_default as default,
|
|
6190
6360
|
diffLines,
|
|
6361
|
+
escapeForRegex,
|
|
6191
6362
|
escapeRegex,
|
|
6192
6363
|
fg256,
|
|
6193
6364
|
fgRgb,
|
|
@@ -6208,12 +6379,14 @@ export {
|
|
|
6208
6379
|
gradient,
|
|
6209
6380
|
gradientColor,
|
|
6210
6381
|
gradientRect,
|
|
6382
|
+
gradientStops,
|
|
6211
6383
|
graphemes,
|
|
6212
6384
|
grid,
|
|
6213
6385
|
hasFont,
|
|
6214
6386
|
hexToRgb,
|
|
6215
6387
|
hideCursor,
|
|
6216
6388
|
hsplit,
|
|
6389
|
+
hyperlink,
|
|
6217
6390
|
images,
|
|
6218
6391
|
isHexColor,
|
|
6219
6392
|
isNoColor,
|
|
@@ -6226,6 +6399,7 @@ export {
|
|
|
6226
6399
|
listPresets,
|
|
6227
6400
|
loader,
|
|
6228
6401
|
mapTree,
|
|
6402
|
+
measureBlock,
|
|
6229
6403
|
measureTree,
|
|
6230
6404
|
memoize,
|
|
6231
6405
|
nextTick,
|
|
@@ -6263,6 +6437,7 @@ export {
|
|
|
6263
6437
|
rotate90,
|
|
6264
6438
|
safeJson,
|
|
6265
6439
|
screen,
|
|
6440
|
+
setConfigValue,
|
|
6266
6441
|
setNoColor,
|
|
6267
6442
|
setTitle,
|
|
6268
6443
|
sgr,
|
|
@@ -6273,6 +6448,7 @@ export {
|
|
|
6273
6448
|
stripAnsi2 as stripAnsi,
|
|
6274
6449
|
stripAnsi as stripAnsiCodes,
|
|
6275
6450
|
stripAnsi3 as stripAnsiColors,
|
|
6451
|
+
subscribeConfig,
|
|
6276
6452
|
supportsColor,
|
|
6277
6453
|
supportsColorLevel,
|
|
6278
6454
|
termSize,
|
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.3.
|
|
121
|
+
components.badge('VERSION', 'v1.3.4'),
|
|
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.3.
|
|
120
|
+
components.badge('VERSION', 'v1.3.4'),
|
|
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.
|
|
3
|
+
"version": "1.3.4",
|
|
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",
|