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/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
@@ -2270,23 +2435,61 @@ var banner = (text, opts = {}) => {
2270
2435
  };
2271
2436
  var box = (text, opts = {}) => {
2272
2437
  const safe = ensureString2(text, "box(text)");
2273
- const { padding = 1, borderStyle = "rounded", width = null } = opts;
2438
+ const {
2439
+ padding = 1,
2440
+ borderStyle = "rounded",
2441
+ width = null,
2442
+ title = null,
2443
+ // v1.3.3
2444
+ titleAlign = "center"
2445
+ // v1.3.3
2446
+ } = opts;
2274
2447
  const padNum = typeof padding === "number" && Number.isFinite(padding) ? padding : 1;
2275
2448
  const safePadding = Math.max(0, Math.floor(padNum));
2276
2449
  const b = BOX_STYLES[borderStyle] ?? BOX_STYLES.rounded;
2277
2450
  const lines = safe.split("\n");
2278
2451
  const inner = width != null ? lines.map((l) => padEnd(truncateAnsi(l, width, ""), width)) : lines;
2279
- const w = inner.length > 0 ? Math.max(0, ...inner.map((l) => visibleLen(l))) : 0;
2452
+ const contentW = inner.length > 0 ? Math.max(0, ...inner.map((l) => visibleLen(l))) : 0;
2453
+ let w = contentW;
2454
+ let titleStr = "";
2455
+ let titleW = 0;
2456
+ if (typeof title === "string" && title.length > 0) {
2457
+ titleStr = ` ${title} `;
2458
+ titleW = visibleLen(titleStr);
2459
+ const titleNeeded = titleW + 2;
2460
+ const innerNeeded = w + safePadding * 2;
2461
+ if (titleNeeded > innerNeeded) {
2462
+ w = titleNeeded - safePadding * 2;
2463
+ }
2464
+ }
2465
+ const innerW = w + safePadding * 2;
2280
2466
  const pad = " ".repeat(safePadding);
2281
- const top = b.tl + b.h.repeat(w + safePadding * 2) + b.tr;
2282
- const bottom = b.bl + b.h.repeat(w + safePadding * 2) + b.br;
2283
- const emptyRow = b.v + " ".repeat(w + safePadding * 2) + b.v;
2467
+ let top;
2468
+ if (titleStr.length > 0 && titleW < innerW) {
2469
+ let before;
2470
+ let after;
2471
+ if (titleAlign === "left") {
2472
+ before = 1;
2473
+ after = innerW - titleW - before;
2474
+ } else if (titleAlign === "right") {
2475
+ after = 1;
2476
+ before = innerW - titleW - after;
2477
+ } else {
2478
+ before = Math.floor((innerW - titleW) / 2);
2479
+ after = innerW - titleW - before;
2480
+ }
2481
+ top = b.tl + b.h.repeat(before) + titleStr + b.h.repeat(after) + b.tr;
2482
+ } else {
2483
+ top = b.tl + b.h.repeat(innerW) + b.tr;
2484
+ }
2485
+ const bottom = b.bl + b.h.repeat(innerW) + b.br;
2486
+ const emptyRow = b.v + " ".repeat(innerW) + b.v;
2284
2487
  const rows = inner.map((l) => b.v + pad + padEnd(l, w) + pad + b.v);
2285
2488
  const vPad = Array(safePadding).fill(emptyRow);
2286
2489
  return [top, ...vPad, ...rows, ...vPad, bottom].join("\n");
2287
2490
  };
2288
2491
  var divider = (opts = {}) => {
2289
- const { char, width = null, label = null, style = "single" } = opts;
2492
+ const { char, width = null, label = null, style = "single", align = "center" } = opts;
2290
2493
  const { cols } = termSize();
2291
2494
  const w = Math.max(0, width ?? cols);
2292
2495
  const b = BOX_STYLES[style] ?? BOX_STYLES.single;
@@ -2295,8 +2498,18 @@ var divider = (opts = {}) => {
2295
2498
  if (label) {
2296
2499
  const labelLen = visibleLen(label);
2297
2500
  if (labelLen >= w - 2) return label;
2298
- const side = Math.max(0, Math.floor((w - labelLen - 2) / 2));
2299
- const trailLen = Math.max(0, w - side - labelLen - 2);
2501
+ let side;
2502
+ let trailLen;
2503
+ if (align === "left") {
2504
+ side = 1;
2505
+ trailLen = Math.max(0, w - labelLen - side - 2);
2506
+ } else if (align === "right") {
2507
+ trailLen = 1;
2508
+ side = Math.max(0, w - labelLen - trailLen - 2);
2509
+ } else {
2510
+ side = Math.max(0, Math.floor((w - labelLen - 2) / 2));
2511
+ trailLen = Math.max(0, w - side - labelLen - 2);
2512
+ }
2300
2513
  return fill.repeat(side) + " " + label + " " + fill.repeat(trailLen);
2301
2514
  }
2302
2515
  return fill.repeat(w);
@@ -3817,7 +4030,7 @@ var progressBar = (percent, opts = {}) => {
3817
4030
  showPercentage = true,
3818
4031
  label = "",
3819
4032
  color: color2 = null,
3820
- gradient: gradientStops = null
4033
+ gradient: gradientStops2 = null
3821
4034
  } = opts;
3822
4035
  const safeWidth = clampPositive2(width, 30);
3823
4036
  const safeChar = typeof char === "string" && char.length > 0 ? char : "\u2588";
@@ -3827,8 +4040,8 @@ var progressBar = (percent, opts = {}) => {
3827
4040
  const filled = Math.floor(clamped / 100 * safeWidth);
3828
4041
  const empty = Math.max(0, safeWidth - filled);
3829
4042
  let filledStr = safeChar.repeat(filled);
3830
- if (Array.isArray(gradientStops) && gradientStops.length >= 1 && filled > 0) {
3831
- filledStr = gradient(filledStr, gradientStops);
4043
+ if (Array.isArray(gradientStops2) && gradientStops2.length >= 1 && filled > 0) {
4044
+ filledStr = gradient(filledStr, gradientStops2);
3832
4045
  } else if (color2 !== null && isFiniteNumber4(color2)) {
3833
4046
  filledStr = sgr(safeSgrCode(color2, FG.white)) + filledStr + reset();
3834
4047
  }
@@ -4949,16 +5162,16 @@ var ensurePixelGrid = (pixels) => {
4949
5162
  return pixels.map((row) => Array.isArray(row) ? row : []);
4950
5163
  };
4951
5164
  var renderPixelArt = (pixels, opts = {}) => {
4952
- const grid = ensurePixelGrid(pixels);
4953
- if (!grid || grid.length === 0) return "";
5165
+ const grid2 = ensurePixelGrid(pixels);
5166
+ if (!grid2 || grid2.length === 0) return "";
4954
5167
  const { scale = 1, halfBlock = true, braille = false } = opts;
4955
5168
  const safeScale = clampInt(scale, 1, 100, 1);
4956
- if (braille) return _renderBraille(grid);
5169
+ if (braille) return _renderBraille(grid2);
4957
5170
  const lines = [];
4958
5171
  if (halfBlock) {
4959
- for (let row = 0; row < grid.length; row += 2) {
4960
- const topRow = grid[row] ?? [];
4961
- const botRow = grid[row + 1] ?? [];
5172
+ for (let row = 0; row < grid2.length; row += 2) {
5173
+ const topRow = grid2[row] ?? [];
5174
+ const botRow = grid2[row + 1] ?? [];
4962
5175
  const colCount = Math.max(topRow.length, botRow.length);
4963
5176
  let line = "";
4964
5177
  let curFg = -1;
@@ -5015,7 +5228,7 @@ var renderPixelArt = (pixels, opts = {}) => {
5015
5228
  lines.push(line);
5016
5229
  }
5017
5230
  } else {
5018
- for (const row of grid) {
5231
+ for (const row of grid2) {
5019
5232
  let line = "";
5020
5233
  let curFg = -1;
5021
5234
  for (const pixel of row) {
@@ -5130,24 +5343,24 @@ var SPRITES = {
5130
5343
  ] }
5131
5344
  };
5132
5345
  var flipHorizontal = (pixels) => {
5133
- const grid = ensurePixelGrid(pixels);
5134
- if (!grid) return [];
5135
- return grid.map((row) => [...row].reverse());
5346
+ const grid2 = ensurePixelGrid(pixels);
5347
+ if (!grid2) return [];
5348
+ return grid2.map((row) => [...row].reverse());
5136
5349
  };
5137
5350
  var flipVertical = (pixels) => {
5138
- const grid = ensurePixelGrid(pixels);
5139
- if (!grid) return [];
5140
- return [...grid].reverse();
5351
+ const grid2 = ensurePixelGrid(pixels);
5352
+ if (!grid2) return [];
5353
+ return [...grid2].reverse();
5141
5354
  };
5142
5355
  var rotate90 = (pixels) => {
5143
- const grid = ensurePixelGrid(pixels);
5144
- if (!grid || grid.length === 0) return [];
5145
- const rows = grid.length;
5146
- const cols = Math.max(0, ...grid.map((r) => r.length));
5356
+ const grid2 = ensurePixelGrid(pixels);
5357
+ if (!grid2 || grid2.length === 0) return [];
5358
+ const rows = grid2.length;
5359
+ const cols = Math.max(0, ...grid2.map((r) => r.length));
5147
5360
  if (cols === 0) return [];
5148
5361
  return Array.from(
5149
5362
  { length: cols },
5150
- (_, c) => Array.from({ length: rows }, (__, r) => grid[rows - 1 - r]?.[c] ?? null)
5363
+ (_, c) => Array.from({ length: rows }, (__, r) => grid2[rows - 1 - r]?.[c] ?? null)
5151
5364
  );
5152
5365
  };
5153
5366
  var BAYER_4x4 = [
@@ -5542,7 +5755,9 @@ var frame = (block, opts = {}) => {
5542
5755
  paddingX,
5543
5756
  topChar = "\u2500",
5544
5757
  bottomChar,
5545
- title
5758
+ title,
5759
+ titleAlign = "center"
5760
+ // v1.3.3
5546
5761
  } = opts;
5547
5762
  const safePadY = Math.max(0, Math.floor(paddingY ?? padding));
5548
5763
  const safePadX = Math.max(0, Math.floor(paddingX ?? padding));
@@ -5563,8 +5778,18 @@ var frame = (block, opts = {}) => {
5563
5778
  }
5564
5779
  let topLine;
5565
5780
  if (titleStr.length > 0 && titleW < innerW) {
5566
- const before = Math.floor((innerW - titleW) / 2);
5567
- const after = innerW - titleW - before;
5781
+ let before;
5782
+ let after;
5783
+ if (titleAlign === "left") {
5784
+ before = 1;
5785
+ after = innerW - titleW - before;
5786
+ } else if (titleAlign === "right") {
5787
+ after = 1;
5788
+ before = innerW - titleW - after;
5789
+ } else {
5790
+ before = Math.floor((innerW - titleW) / 2);
5791
+ after = innerW - titleW - before;
5792
+ }
5568
5793
  topLine = safeTop.repeat(before) + titleStr + safeTop.repeat(after);
5569
5794
  } else {
5570
5795
  topLine = safeTop.repeat(innerW);
@@ -5585,12 +5810,54 @@ var frame = (block, opts = {}) => {
5585
5810
  out.push(bottomLine);
5586
5811
  return out.join("\n");
5587
5812
  };
5813
+ var grid = (blocks, opts) => {
5814
+ if (!Array.isArray(blocks) || blocks.length === 0) return "";
5815
+ if (!opts || typeof opts !== "object") return "";
5816
+ const columns2 = Math.max(1, Math.floor(opts.columns ?? 1));
5817
+ const gapX = Math.max(0, Math.floor(opts.gapX ?? 1));
5818
+ const gapY = Math.max(0, Math.floor(opts.gapY ?? 0));
5819
+ const alignX = opts.alignX ?? "start";
5820
+ const alignY = opts.alignY ?? "start";
5821
+ const cellW = opts.cellWidth != null ? Math.max(0, Math.floor(opts.cellWidth)) : null;
5822
+ const rows = [];
5823
+ for (let i = 0; i < blocks.length; i += columns2) {
5824
+ rows.push(blocks.slice(i, i + columns2));
5825
+ }
5826
+ let widths = null;
5827
+ if (cellW != null) {
5828
+ widths = Array(columns2).fill(cellW);
5829
+ } else {
5830
+ widths = Array(columns2).fill(0);
5831
+ for (const row of rows) {
5832
+ for (let c = 0; c < row.length; c++) {
5833
+ const { maxWidth } = _splitBlock(row[c]);
5834
+ if (maxWidth > widths[c]) {
5835
+ widths[c] = maxWidth;
5836
+ }
5837
+ }
5838
+ }
5839
+ }
5840
+ const renderedRows = rows.map((row) => {
5841
+ const padded = [];
5842
+ for (let c = 0; c < columns2; c++) {
5843
+ padded.push(row[c] ?? "");
5844
+ }
5845
+ return vsplit(padded, {
5846
+ gap: gapX,
5847
+ align: alignY,
5848
+ widths
5849
+ });
5850
+ });
5851
+ return hsplit(renderedRows, { gap: gapY, align: alignX });
5852
+ };
5588
5853
  var panels = {
5589
5854
  vsplit,
5590
5855
  hsplit,
5591
5856
  // v1.3.1
5592
5857
  center: center2,
5593
- frame
5858
+ frame,
5859
+ // v1.3.3
5860
+ grid
5594
5861
  };
5595
5862
 
5596
5863
  // src/json/index.ts
@@ -5610,11 +5877,12 @@ var _truncString = (s, maxLength) => {
5610
5877
  return s.slice(0, maxLength - 3) + "...";
5611
5878
  };
5612
5879
  var _formatPrimitive = (value, opts) => {
5613
- const { useColor, maxStringLength } = opts;
5880
+ const { useColor, maxStringLength, mode } = opts;
5614
5881
  if (value === null) {
5615
5882
  return _c("null", COLORS.null, useColor);
5616
5883
  }
5617
5884
  if (value === void 0) {
5885
+ if (mode === "json") return _c("null", COLORS.null, useColor);
5618
5886
  return _c("undefined", COLORS.null, useColor);
5619
5887
  }
5620
5888
  if (typeof value === "string") {
@@ -5623,8 +5891,12 @@ var _formatPrimitive = (value, opts) => {
5623
5891
  return _c(quoted, COLORS.string, useColor);
5624
5892
  }
5625
5893
  if (typeof value === "number") {
5626
- if (Number.isNaN(value)) return _c("NaN", COLORS.number, useColor);
5894
+ if (Number.isNaN(value)) {
5895
+ if (mode === "json") return _c("null", COLORS.null, useColor);
5896
+ return _c("NaN", COLORS.number, useColor);
5897
+ }
5627
5898
  if (!Number.isFinite(value)) {
5899
+ if (mode === "json") return _c("null", COLORS.null, useColor);
5628
5900
  return _c(value > 0 ? "Infinity" : "-Infinity", COLORS.number, useColor);
5629
5901
  }
5630
5902
  return _c(String(value), COLORS.number, useColor);
@@ -5633,16 +5905,23 @@ var _formatPrimitive = (value, opts) => {
5633
5905
  return _c(String(value), COLORS.boolean, useColor);
5634
5906
  }
5635
5907
  if (typeof value === "bigint") {
5908
+ if (mode === "json") {
5909
+ const big2 = value;
5910
+ const asNum = Number(big2);
5911
+ if (Number.isSafeInteger(asNum) && BigInt(asNum) === big2) {
5912
+ return _c(String(asNum), COLORS.number, useColor);
5913
+ }
5914
+ return _c(JSON.stringify(String(big2)), COLORS.string, useColor);
5915
+ }
5636
5916
  return _c(`${value}n`, COLORS.number, useColor);
5637
5917
  }
5638
5918
  if (typeof value === "function") {
5919
+ if (mode === "json") return _c("null", COLORS.null, useColor);
5639
5920
  const name = value.name || "anonymous";
5640
5921
  return _c(`[Function: ${name}]`, COLORS.comment, useColor);
5641
5922
  }
5642
- if (typeof value === "symbol") {
5643
- return _c(value.toString(), COLORS.comment, useColor);
5644
- }
5645
- return _c(String(value), COLORS.comment, useColor);
5923
+ if (mode === "json") return _c("null", COLORS.null, useColor);
5924
+ return _c(value.toString(), COLORS.comment, useColor);
5646
5925
  };
5647
5926
  var _renderValue = (value, depth, config) => {
5648
5927
  const {
@@ -5653,15 +5932,56 @@ var _renderValue = (value, depth, config) => {
5653
5932
  useColor,
5654
5933
  seen,
5655
5934
  sortKeys,
5656
- inlineArrayMaxLength
5935
+ inlineArrayMaxLength,
5936
+ mode
5657
5937
  } = config;
5658
5938
  if (value === null || typeof value !== "object") {
5659
- return _formatPrimitive(value, { useColor, maxStringLength });
5939
+ return _formatPrimitive(value, { useColor, maxStringLength, mode });
5660
5940
  }
5661
5941
  if (seen.has(value)) {
5942
+ if (mode === "json") {
5943
+ throw new TypeError("Cannot serialize circular reference to JSON");
5944
+ }
5662
5945
  return _c("[Circular]", COLORS.comment, useColor);
5663
5946
  }
5664
5947
  seen.add(value);
5948
+ if (value instanceof Date) {
5949
+ const iso = value.toISOString();
5950
+ if (mode === "json") {
5951
+ return _c(JSON.stringify(iso), COLORS.string, useColor);
5952
+ }
5953
+ return _c(`Date(${iso})`, COLORS.comment, useColor);
5954
+ }
5955
+ if (value instanceof Map) {
5956
+ if (mode === "json") {
5957
+ const obj = {};
5958
+ for (const [k, v] of value) {
5959
+ if (typeof k === "string") obj[k] = v;
5960
+ else obj[String(k)] = v;
5961
+ }
5962
+ return _renderValue(obj, depth, config);
5963
+ }
5964
+ const entries2 = Array.from(value);
5965
+ const sizeLabel = _c(`Map(${entries2.length})`, COLORS.comment, useColor);
5966
+ if (entries2.length === 0) {
5967
+ return `${sizeLabel} ${_c("{}", COLORS.bracket, useColor)}`;
5968
+ }
5969
+ if (depth >= maxDepth - 1 && depth > 0) {
5970
+ return `${sizeLabel} ${_c("{...}", COLORS.bracket, useColor)}`;
5971
+ }
5972
+ return `${sizeLabel} ${_renderValue(entries2, depth, config)}`;
5973
+ }
5974
+ if (value instanceof Set) {
5975
+ if (mode === "json") {
5976
+ return _renderValue(Array.from(value), depth, config);
5977
+ }
5978
+ const arr = Array.from(value);
5979
+ const sizeLabel = _c(`Set(${arr.length})`, COLORS.comment, useColor);
5980
+ if (arr.length === 0) {
5981
+ return `${sizeLabel} ${_c("[]", COLORS.bracket, useColor)}`;
5982
+ }
5983
+ return `${sizeLabel} ${_renderValue(arr, depth, config)}`;
5984
+ }
5665
5985
  if (depth >= maxDepth) {
5666
5986
  if (Array.isArray(value)) {
5667
5987
  return _c("[", COLORS.bracket, useColor) + _c("...", COLORS.comment, useColor) + _c("]", COLORS.bracket, useColor);
@@ -5680,7 +6000,7 @@ var _renderValue = (value, depth, config) => {
5680
6000
  const displayCount2 = Math.min(value.length, maxItems);
5681
6001
  const inlineItems = [];
5682
6002
  for (let i = 0; i < displayCount2; i++) {
5683
- inlineItems.push(_formatPrimitive(value[i], { useColor, maxStringLength }));
6003
+ inlineItems.push(_formatPrimitive(value[i], { useColor, maxStringLength, mode }));
5684
6004
  }
5685
6005
  if (value.length > maxItems) {
5686
6006
  const remaining = value.length - maxItems;
@@ -5706,6 +6026,12 @@ var _renderValue = (value, depth, config) => {
5706
6026
  return _c("[", COLORS.bracket, useColor) + "\n" + items.join(",\n") + "\n" + closePad + _c("]", COLORS.bracket, useColor);
5707
6027
  }
5708
6028
  let keys = Object.keys(value);
6029
+ if (mode === "json") {
6030
+ keys = keys.filter((k) => {
6031
+ const v = value[k];
6032
+ return typeof v !== "function" && typeof v !== "symbol" && v !== void 0;
6033
+ });
6034
+ }
5709
6035
  if (keys.length === 0) {
5710
6036
  return _c("{}", COLORS.bracket, useColor);
5711
6037
  }
@@ -5734,14 +6060,17 @@ var pretty = (value, opts = {}) => {
5734
6060
  maxStringLength = Infinity,
5735
6061
  // v1.3.1
5736
6062
  sortKeys = false,
5737
- inlineArrayMaxLength = 60
6063
+ inlineArrayMaxLength = 60,
6064
+ // v1.3.3
6065
+ mode = "display"
5738
6066
  } = opts;
5739
6067
  const safeIndent = Math.max(0, Math.floor(Number(indent) || 0));
5740
6068
  const safeMaxDepth = Number.isFinite(maxDepth) ? Math.max(0, Math.floor(maxDepth)) : Infinity;
5741
6069
  const safeMaxItems = Number.isFinite(maxItems) ? Math.max(0, Math.floor(maxItems)) : Infinity;
5742
6070
  const safeMaxStrLen = Number.isFinite(maxStringLength) ? Math.max(0, Math.floor(maxStringLength)) : Infinity;
5743
6071
  const safeInlineMax = Number.isFinite(inlineArrayMaxLength) ? Math.max(0, Math.floor(inlineArrayMaxLength)) : 60;
5744
- const useColor = colors && !isNoColor();
6072
+ const safeMode = mode === "json" ? "json" : "display";
6073
+ const useColor = safeMode === "json" ? false : colors && !isNoColor();
5745
6074
  return _renderValue(value, 0, {
5746
6075
  indent: safeIndent,
5747
6076
  maxDepth: safeMaxDepth,
@@ -5750,7 +6079,8 @@ var pretty = (value, opts = {}) => {
5750
6079
  useColor,
5751
6080
  seen: /* @__PURE__ */ new WeakSet(),
5752
6081
  sortKeys: Boolean(sortKeys),
5753
- inlineArrayMaxLength: safeInlineMax
6082
+ inlineArrayMaxLength: safeInlineMax,
6083
+ mode: safeMode
5754
6084
  });
5755
6085
  };
5756
6086
  var json = {
@@ -5969,6 +6299,10 @@ var withConfig = (overrides, fn) => {
5969
6299
  throw err;
5970
6300
  }
5971
6301
  };
6302
+ var setConfigValue = (key, value) => {
6303
+ configure({ [key]: value });
6304
+ };
6305
+ var subscribeConfig = onConfigChange;
5972
6306
 
5973
6307
  // src/index.ts
5974
6308
  var ansimax = { color, animate, ascii, loader, frames, components, trees, themes, images, configure };
@@ -6006,6 +6340,7 @@ export {
6006
6340
  clamp,
6007
6341
  clearAnsiCache,
6008
6342
  clearColorCache,
6343
+ clearLine,
6009
6344
  clearRenderCache,
6010
6345
  clearThemeColorCache,
6011
6346
  color,
@@ -6023,6 +6358,7 @@ export {
6023
6358
  debounce,
6024
6359
  index_default as default,
6025
6360
  diffLines,
6361
+ escapeForRegex,
6026
6362
  escapeRegex,
6027
6363
  fg256,
6028
6364
  fgRgb,
@@ -6043,11 +6379,14 @@ export {
6043
6379
  gradient,
6044
6380
  gradientColor,
6045
6381
  gradientRect,
6382
+ gradientStops,
6046
6383
  graphemes,
6384
+ grid,
6047
6385
  hasFont,
6048
6386
  hexToRgb,
6049
6387
  hideCursor,
6050
6388
  hsplit,
6389
+ hyperlink,
6051
6390
  images,
6052
6391
  isHexColor,
6053
6392
  isNoColor,
@@ -6060,6 +6399,7 @@ export {
6060
6399
  listPresets,
6061
6400
  loader,
6062
6401
  mapTree,
6402
+ measureBlock,
6063
6403
  measureTree,
6064
6404
  memoize,
6065
6405
  nextTick,
@@ -6097,6 +6437,7 @@ export {
6097
6437
  rotate90,
6098
6438
  safeJson,
6099
6439
  screen,
6440
+ setConfigValue,
6100
6441
  setNoColor,
6101
6442
  setTitle,
6102
6443
  sgr,
@@ -6107,6 +6448,7 @@ export {
6107
6448
  stripAnsi2 as stripAnsi,
6108
6449
  stripAnsi as stripAnsiCodes,
6109
6450
  stripAnsi3 as stripAnsiColors,
6451
+ subscribeConfig,
6110
6452
  supportsColor,
6111
6453
  supportsColorLevel,
6112
6454
  termSize,
@@ -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.2'),
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();
@@ -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.2'),
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();