ansimax 1.2.8 → 1.3.0

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
@@ -5428,6 +5428,225 @@ var images = {
5428
5428
  clearAnsiCache
5429
5429
  };
5430
5430
 
5431
+ // src/panels/index.ts
5432
+ var _splitBlock = (block) => {
5433
+ if (typeof block !== "string" || block.length === 0) {
5434
+ return { lines: [""], maxWidth: 0 };
5435
+ }
5436
+ const lines = block.split("\n");
5437
+ let maxWidth = 0;
5438
+ for (const line of lines) {
5439
+ const w = visibleLen(line);
5440
+ if (w > maxWidth) maxWidth = w;
5441
+ }
5442
+ return { lines, maxWidth };
5443
+ };
5444
+ var _padLinesRight = (lines, targetWidth) => {
5445
+ return lines.map((line) => padEnd(line, targetWidth, " "));
5446
+ };
5447
+ var _padLinesAligned = (lines, targetWidth, align) => {
5448
+ return lines.map((line) => {
5449
+ const w = visibleLen(line);
5450
+ const space = Math.max(0, targetWidth - w);
5451
+ if (space === 0) return line;
5452
+ if (align === "end") return " ".repeat(space) + line;
5453
+ if (align === "center") {
5454
+ const left = Math.floor(space / 2);
5455
+ const right = space - left;
5456
+ return " ".repeat(left) + line + " ".repeat(right);
5457
+ }
5458
+ return line + " ".repeat(space);
5459
+ });
5460
+ };
5461
+ var _alignVertical = (lines, targetLines, width, align) => {
5462
+ const current = lines.length;
5463
+ if (current >= targetLines) return lines.slice(0, targetLines);
5464
+ const diff = targetLines - current;
5465
+ const empty = " ".repeat(width);
5466
+ if (align === "end") {
5467
+ return [...Array(diff).fill(empty), ...lines];
5468
+ }
5469
+ if (align === "center") {
5470
+ const above = Math.floor(diff / 2);
5471
+ const below = diff - above;
5472
+ return [...Array(above).fill(empty), ...lines, ...Array(below).fill(empty)];
5473
+ }
5474
+ return [...lines, ...Array(diff).fill(empty)];
5475
+ };
5476
+ var vsplit = (blocks, opts = {}) => {
5477
+ if (!Array.isArray(blocks) || blocks.length === 0) return "";
5478
+ const { gap = 1, align = "start", widths = null } = opts;
5479
+ const safeGap = Math.max(0, Math.floor(gap));
5480
+ const splits = blocks.map((b) => _splitBlock(b));
5481
+ const colWidths = splits.map((s, i) => {
5482
+ if (widths && Array.isArray(widths) && widths[i] != null) {
5483
+ return Math.max(0, Math.floor(widths[i]));
5484
+ }
5485
+ return s.maxWidth;
5486
+ });
5487
+ const targetLines = splits.reduce((m, s) => Math.max(m, s.lines.length), 0);
5488
+ const normalized = splits.map((s, i) => {
5489
+ const w = colWidths[i];
5490
+ const padded = _padLinesRight(s.lines, w);
5491
+ return _alignVertical(padded, targetLines, w, align);
5492
+ });
5493
+ const gapStr = " ".repeat(safeGap);
5494
+ const result = [];
5495
+ for (let r = 0; r < targetLines; r++) {
5496
+ const row = normalized.map((block) => block[r] ?? "").join(gapStr);
5497
+ result.push(row);
5498
+ }
5499
+ return result.join("\n");
5500
+ };
5501
+ var hsplit = (blocks, opts = {}) => {
5502
+ if (!Array.isArray(blocks) || blocks.length === 0) return "";
5503
+ const { gap = 0, align = "start" } = opts;
5504
+ const safeGap = Math.max(0, Math.floor(gap));
5505
+ const splits = blocks.map((b) => _splitBlock(b));
5506
+ const maxWidth = splits.reduce((m, s) => Math.max(m, s.maxWidth), 0);
5507
+ const aligned = splits.map((s) => _padLinesAligned(s.lines, maxWidth, align));
5508
+ const gapLines = safeGap > 0 ? Array(safeGap).fill(" ".repeat(maxWidth)) : [];
5509
+ const parts = [];
5510
+ for (let i = 0; i < aligned.length; i++) {
5511
+ parts.push(...aligned[i]);
5512
+ if (i < aligned.length - 1 && gapLines.length > 0) {
5513
+ parts.push(...gapLines);
5514
+ }
5515
+ }
5516
+ return parts.join("\n");
5517
+ };
5518
+ var panels = {
5519
+ vsplit,
5520
+ hsplit
5521
+ };
5522
+
5523
+ // src/json/index.ts
5524
+ var COLORS = {
5525
+ key: FG.cyan,
5526
+ string: FG.green,
5527
+ number: FG.yellow,
5528
+ boolean: FG.magenta,
5529
+ null: FG.brightBlack,
5530
+ bracket: FG.white,
5531
+ comment: FG.brightBlack
5532
+ };
5533
+ var _c = (text, code, useColor) => useColor ? sgr(code) + text + reset() : text;
5534
+ var _truncString = (s, maxLength) => {
5535
+ if (!Number.isFinite(maxLength) || s.length <= maxLength) return s;
5536
+ if (maxLength <= 3) return s.slice(0, maxLength);
5537
+ return s.slice(0, maxLength - 3) + "...";
5538
+ };
5539
+ var _formatPrimitive = (value, opts) => {
5540
+ const { useColor, maxStringLength } = opts;
5541
+ if (value === null) {
5542
+ return _c("null", COLORS.null, useColor);
5543
+ }
5544
+ if (value === void 0) {
5545
+ return _c("undefined", COLORS.null, useColor);
5546
+ }
5547
+ if (typeof value === "string") {
5548
+ const truncated = _truncString(value, maxStringLength);
5549
+ const quoted = JSON.stringify(truncated);
5550
+ return _c(quoted, COLORS.string, useColor);
5551
+ }
5552
+ if (typeof value === "number") {
5553
+ if (Number.isNaN(value)) return _c("NaN", COLORS.number, useColor);
5554
+ if (!Number.isFinite(value)) {
5555
+ return _c(value > 0 ? "Infinity" : "-Infinity", COLORS.number, useColor);
5556
+ }
5557
+ return _c(String(value), COLORS.number, useColor);
5558
+ }
5559
+ if (typeof value === "boolean") {
5560
+ return _c(String(value), COLORS.boolean, useColor);
5561
+ }
5562
+ if (typeof value === "bigint") {
5563
+ return _c(`${value}n`, COLORS.number, useColor);
5564
+ }
5565
+ if (typeof value === "function") {
5566
+ const name = value.name || "anonymous";
5567
+ return _c(`[Function: ${name}]`, COLORS.comment, useColor);
5568
+ }
5569
+ if (typeof value === "symbol") {
5570
+ return _c(value.toString(), COLORS.comment, useColor);
5571
+ }
5572
+ return _c(String(value), COLORS.comment, useColor);
5573
+ };
5574
+ var _renderValue = (value, depth, config) => {
5575
+ const { indent, maxDepth, maxItems, maxStringLength, useColor, seen } = config;
5576
+ if (value === null || typeof value !== "object") {
5577
+ return _formatPrimitive(value, { useColor, maxStringLength });
5578
+ }
5579
+ if (seen.has(value)) {
5580
+ return _c("[Circular]", COLORS.comment, useColor);
5581
+ }
5582
+ seen.add(value);
5583
+ if (depth >= maxDepth) {
5584
+ if (Array.isArray(value)) {
5585
+ return _c("[", COLORS.bracket, useColor) + _c("...", COLORS.comment, useColor) + _c("]", COLORS.bracket, useColor);
5586
+ }
5587
+ return _c("{", COLORS.bracket, useColor) + _c("...", COLORS.comment, useColor) + _c("}", COLORS.bracket, useColor);
5588
+ }
5589
+ const pad = " ".repeat(indent * (depth + 1));
5590
+ const closePad = " ".repeat(indent * depth);
5591
+ if (Array.isArray(value)) {
5592
+ if (value.length === 0) {
5593
+ return _c("[]", COLORS.bracket, useColor);
5594
+ }
5595
+ const items = [];
5596
+ const displayCount = Math.min(value.length, maxItems);
5597
+ for (let i = 0; i < displayCount; i++) {
5598
+ const rendered = _renderValue(value[i], depth + 1, config);
5599
+ items.push(pad + rendered);
5600
+ }
5601
+ if (value.length > maxItems) {
5602
+ const remaining = value.length - maxItems;
5603
+ items.push(pad + _c(`... (${remaining} more)`, COLORS.comment, useColor));
5604
+ }
5605
+ return _c("[", COLORS.bracket, useColor) + "\n" + items.join(",\n") + "\n" + closePad + _c("]", COLORS.bracket, useColor);
5606
+ }
5607
+ const keys = Object.keys(value);
5608
+ if (keys.length === 0) {
5609
+ return _c("{}", COLORS.bracket, useColor);
5610
+ }
5611
+ const entries = [];
5612
+ for (const key of keys) {
5613
+ const keyStr = JSON.stringify(key);
5614
+ const renderedKey = _c(keyStr, COLORS.key, useColor);
5615
+ const renderedVal = _renderValue(
5616
+ value[key],
5617
+ depth + 1,
5618
+ config
5619
+ );
5620
+ entries.push(`${pad}${renderedKey}: ${renderedVal}`);
5621
+ }
5622
+ return _c("{", COLORS.bracket, useColor) + "\n" + entries.join(",\n") + "\n" + closePad + _c("}", COLORS.bracket, useColor);
5623
+ };
5624
+ var pretty = (value, opts = {}) => {
5625
+ const {
5626
+ indent = 2,
5627
+ colors = true,
5628
+ maxDepth = Infinity,
5629
+ maxItems = Infinity,
5630
+ maxStringLength = Infinity
5631
+ } = opts;
5632
+ const safeIndent = Math.max(0, Math.floor(Number(indent) || 0));
5633
+ const safeMaxDepth = Number.isFinite(maxDepth) ? Math.max(0, Math.floor(maxDepth)) : Infinity;
5634
+ const safeMaxItems = Number.isFinite(maxItems) ? Math.max(0, Math.floor(maxItems)) : Infinity;
5635
+ const safeMaxStrLen = Number.isFinite(maxStringLength) ? Math.max(0, Math.floor(maxStringLength)) : Infinity;
5636
+ const useColor = colors && !isNoColor();
5637
+ return _renderValue(value, 0, {
5638
+ indent: safeIndent,
5639
+ maxDepth: safeMaxDepth,
5640
+ maxItems: safeMaxItems,
5641
+ maxStringLength: safeMaxStrLen,
5642
+ useColor,
5643
+ seen: /* @__PURE__ */ new WeakSet()
5644
+ });
5645
+ };
5646
+ var json = {
5647
+ pretty
5648
+ };
5649
+
5431
5650
  // src/configure.ts
5432
5651
  var DEFAULTS = Object.freeze({
5433
5652
  colorMode: "auto",
@@ -5716,9 +5935,12 @@ export {
5716
5935
  hasFont,
5717
5936
  hexToRgb,
5718
5937
  hideCursor,
5938
+ hsplit,
5719
5939
  images,
5720
5940
  isHexColor,
5721
5941
  isNoColor,
5942
+ json,
5943
+ pretty as jsonPretty,
5722
5944
  lerp,
5723
5945
  lerpColor,
5724
5946
  link,
@@ -5736,6 +5958,7 @@ export {
5736
5958
  padBoth,
5737
5959
  padEnd,
5738
5960
  padStart,
5961
+ panels,
5739
5962
  parseFiglet,
5740
5963
  pauseListeners,
5741
5964
  presetNames,
@@ -5781,6 +6004,7 @@ export {
5781
6004
  trees,
5782
6005
  truncateAnsi,
5783
6006
  visibleLen,
6007
+ vsplit,
5784
6008
  walkTree,
5785
6009
  withConfig,
5786
6010
  wordWrap,
@@ -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.2.8'),
121
+ components.badge('VERSION', 'v1.3.0'),
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.2.8'),
120
+ components.badge('VERSION', 'v1.3.0'),
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.2.8",
3
+ "version": "1.3.0",
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",