ansimax 1.2.8 → 1.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -359,7 +359,7 @@ declare const sliceAnsi: (str: string, start: number, end?: number) => string;
359
359
  declare const truncateAnsi: (str: string, width: number, ellipsis?: string) => string;
360
360
  declare const padEnd: (str: string, width: number, ch?: string) => string;
361
361
  declare const padStart: (str: string, width: number, ch?: string) => string;
362
- declare const center: (str: string, width: number, ch?: string) => string;
362
+ declare const center$1: (str: string, width: number, ch?: string) => string;
363
363
  /** Repeats a string until its visible length reaches the target width. */
364
364
  declare const repeatVisible: (str: string, width: number) => string;
365
365
  /**
@@ -1904,6 +1904,352 @@ declare const clearThemeColorCache: () => void;
1904
1904
  */
1905
1905
  declare const themes: ThemeInstance;
1906
1906
 
1907
+ /**
1908
+ * ansimax — panels module
1909
+ * ─────────────────────────────────────────────
1910
+ *
1911
+ * Split layouts for composing terminal UIs: hsplit (top/bottom) and
1912
+ * vsplit (left/right). Both operate on already-rendered string blocks
1913
+ * (typically from `ascii.box`, `components.table`, etc.) and handle:
1914
+ *
1915
+ * • ANSI-aware width measurement
1916
+ * • Variable height (each block keeps its own line count)
1917
+ * • Alignment within columns
1918
+ * • Configurable gap between blocks
1919
+ * • Nesting (panels can contain panels)
1920
+ *
1921
+ * Philosophy: panels do composition, not styling. Style your blocks
1922
+ * first (with `ascii.box`, `components.timeline`, etc.), then compose
1923
+ * them with `panels.hsplit` / `panels.vsplit`.
1924
+ */
1925
+ type Alignment = 'start' | 'center' | 'end';
1926
+ interface VsplitOptions {
1927
+ /** Horizontal gap (in space characters) between columns. Default `1`. */
1928
+ gap?: number;
1929
+ /**
1930
+ * Vertical alignment of shorter blocks within the joined column row.
1931
+ * `'start'` (default) keeps blocks top-aligned; shorter blocks have
1932
+ * padding below. `'center'` centers each block. `'end'` aligns to bottom.
1933
+ */
1934
+ align?: Alignment;
1935
+ /**
1936
+ * Pad each block with spaces to a fixed width. Useful for grids where
1937
+ * each cell should be the same size regardless of content.
1938
+ * If omitted, each column uses its natural max-line width.
1939
+ */
1940
+ widths?: number[] | null;
1941
+ }
1942
+ interface HsplitOptions {
1943
+ /** Vertical gap (in blank lines) between rows. Default `0`. */
1944
+ gap?: number;
1945
+ /**
1946
+ * Horizontal alignment of narrower blocks within the joined width.
1947
+ * `'start'` (default) keeps blocks left-aligned. `'center'` and `'end'`
1948
+ * pad with spaces on the appropriate side.
1949
+ */
1950
+ align?: Alignment;
1951
+ }
1952
+ /**
1953
+ * Split blocks side-by-side (left / right / right ...).
1954
+ *
1955
+ * Each block is split into lines, then joined column-by-column with a
1956
+ * configurable gap. Shorter blocks are padded to match the tallest one.
1957
+ *
1958
+ * @param blocks - Pre-rendered string blocks (multi-line OK).
1959
+ * @param opts - Layout options.
1960
+ *
1961
+ * @example basic two-column layout
1962
+ * ```js
1963
+ * import { panels, ascii } from 'ansimax';
1964
+ *
1965
+ * console.log(panels.vsplit([
1966
+ * ascii.box('Left side', { borderStyle: 'rounded' }),
1967
+ * ascii.box('Right side', { borderStyle: 'rounded' }),
1968
+ * ], { gap: 2 }));
1969
+ * ```
1970
+ *
1971
+ * @example three columns with centered vertical alignment
1972
+ * ```js
1973
+ * console.log(panels.vsplit([
1974
+ * 'Short',
1975
+ * 'A\nMedium\nblock',
1976
+ * 'A\nlonger\nblock\nwith\nfive lines',
1977
+ * ], { align: 'center', gap: 4 }));
1978
+ * ```
1979
+ *
1980
+ * @example fixed column widths (grid-like)
1981
+ * ```js
1982
+ * console.log(panels.vsplit([col1, col2, col3], {
1983
+ * widths: [20, 30, 20],
1984
+ * gap: 2,
1985
+ * }));
1986
+ * ```
1987
+ */
1988
+ declare const vsplit: (blocks: string[], opts?: VsplitOptions) => string;
1989
+ /**
1990
+ * Stack blocks vertically (top / bottom / bottom ...).
1991
+ *
1992
+ * Each block is concatenated with `\n` between them. With `gap > 0`,
1993
+ * additional blank lines are inserted between blocks.
1994
+ *
1995
+ * @param blocks - Pre-rendered string blocks (multi-line OK).
1996
+ * @param opts - Layout options.
1997
+ *
1998
+ * @example basic stacking
1999
+ * ```js
2000
+ * import { panels, ascii } from 'ansimax';
2001
+ *
2002
+ * console.log(panels.hsplit([
2003
+ * '── Header ──',
2004
+ * ascii.box('Body content', { borderStyle: 'rounded' }),
2005
+ * '── Footer ──',
2006
+ * ]));
2007
+ * ```
2008
+ *
2009
+ * @example with vertical gap + centered alignment
2010
+ * ```js
2011
+ * console.log(panels.hsplit([
2012
+ * 'Top',
2013
+ * ascii.box('Middle'),
2014
+ * 'Bottom',
2015
+ * ], { gap: 1, align: 'center' }));
2016
+ * ```
2017
+ *
2018
+ * @example nested (an hsplit inside a vsplit)
2019
+ * ```js
2020
+ * const sidebar = ascii.box('Sidebar', { width: 20 });
2021
+ * const main = ascii.box('Main content area', { width: 40 });
2022
+ *
2023
+ * console.log(panels.hsplit([
2024
+ * '── Application ──',
2025
+ * panels.vsplit([sidebar, main], { gap: 2 }),
2026
+ * '── End ──',
2027
+ * ]));
2028
+ * ```
2029
+ */
2030
+ declare const hsplit: (blocks: string[], opts?: HsplitOptions) => string;
2031
+ interface CenterOptions {
2032
+ /** Total width to center within. Required. */
2033
+ width: number;
2034
+ /**
2035
+ * Vertical alignment if `height` is also specified.
2036
+ * Default `'start'`.
2037
+ */
2038
+ align?: Alignment;
2039
+ /**
2040
+ * Total height to fit the block into. Optional — if omitted, only
2041
+ * horizontal centering is applied.
2042
+ */
2043
+ height?: number;
2044
+ }
2045
+ /**
2046
+ * Center a multi-line block horizontally (and optionally vertically)
2047
+ * within a given width/height. Each line is padded with spaces on both
2048
+ * sides; ANSI escapes are preserved.
2049
+ *
2050
+ * @example horizontal centering only
2051
+ * ```js
2052
+ * import { panels } from 'ansimax';
2053
+ *
2054
+ * console.log(panels.center('Hello!', { width: 30 }));
2055
+ * // " Hello! "
2056
+ * ```
2057
+ *
2058
+ * @example multi-line centered in a fixed area
2059
+ * ```js
2060
+ * console.log(panels.center('Line 1\nLine 2\nLine 3', {
2061
+ * width: 30,
2062
+ * height: 7,
2063
+ * align: 'center',
2064
+ * }));
2065
+ * ```
2066
+ *
2067
+ * @example combined with box for a centered card
2068
+ * ```js
2069
+ * import { ascii, panels } from 'ansimax';
2070
+ *
2071
+ * console.log(panels.center(ascii.box('Hello'), { width: 80 }));
2072
+ * // Box appears centered in a 80-wide terminal
2073
+ * ```
2074
+ */
2075
+ declare const center: (block: string, opts: CenterOptions) => string;
2076
+ interface FrameOptions {
2077
+ /**
2078
+ * Padding (in spaces) between the block content and the inner edge of
2079
+ * the frame. Default `0`.
2080
+ */
2081
+ padding?: number;
2082
+ /**
2083
+ * Padding above + below the block. If unset, falls back to `padding`.
2084
+ */
2085
+ paddingY?: number;
2086
+ /**
2087
+ * Padding left + right of the block. If unset, falls back to `padding`.
2088
+ */
2089
+ paddingX?: number;
2090
+ /**
2091
+ * Top decoration character — e.g. `'─'`, `'═'`, `'━'`, `'·'`.
2092
+ * Default `'─'`.
2093
+ */
2094
+ topChar?: string;
2095
+ /**
2096
+ * Bottom decoration character. Default same as `topChar`.
2097
+ */
2098
+ bottomChar?: string;
2099
+ /**
2100
+ * Optional title shown centered in the top edge.
2101
+ */
2102
+ title?: string;
2103
+ }
2104
+ /**
2105
+ * Add decorative top/bottom rule lines around a block (lighter than `ascii.box`
2106
+ * which draws four sides). Useful for visual separation without full borders.
2107
+ *
2108
+ * @example simple top/bottom rules
2109
+ * ```js
2110
+ * console.log(panels.frame('Hello world!'));
2111
+ * // ─────────────
2112
+ * // Hello world!
2113
+ * // ─────────────
2114
+ * ```
2115
+ *
2116
+ * @example with title and padding
2117
+ * ```js
2118
+ * console.log(panels.frame('Body content\nMore content', {
2119
+ * title: 'Header',
2120
+ * padding: 1,
2121
+ * }));
2122
+ * // ───── Header ─────
2123
+ * //
2124
+ * // Body content
2125
+ * // More content
2126
+ * //
2127
+ * // ──────────────────
2128
+ * ```
2129
+ *
2130
+ * @example custom decorations
2131
+ * ```js
2132
+ * console.log(panels.frame('Important!', {
2133
+ * topChar: '═',
2134
+ * bottomChar: '═',
2135
+ * padding: 2,
2136
+ * }));
2137
+ * ```
2138
+ */
2139
+ declare const frame: (block: string, opts?: FrameOptions) => string;
2140
+ declare const panels: {
2141
+ vsplit: (blocks: string[], opts?: VsplitOptions) => string;
2142
+ hsplit: (blocks: string[], opts?: HsplitOptions) => string;
2143
+ center: (block: string, opts: CenterOptions) => string;
2144
+ frame: (block: string, opts?: FrameOptions) => string;
2145
+ };
2146
+
2147
+ /**
2148
+ * ansimax — json module
2149
+ * ─────────────────────────────────────────────
2150
+ *
2151
+ * Colored JSON / YAML pretty-printer for terminal display.
2152
+ *
2153
+ * Features:
2154
+ * • Configurable indent
2155
+ * • Color-coded by value type (string, number, boolean, null, key)
2156
+ * • Max depth with collapse marker (`{...}` / `[...]`)
2157
+ * • Circular reference detection (avoids infinite recursion)
2158
+ * • ANSI cleanly disabled in NO_COLOR / non-TTY environments
2159
+ *
2160
+ * Philosophy: data → human-readable text. Not a parser, not a validator —
2161
+ * just pretty rendering of in-memory JS values.
2162
+ */
2163
+ interface PrettyOptions {
2164
+ /** Indent width in spaces. Default `2`. */
2165
+ indent?: number;
2166
+ /**
2167
+ * Apply ANSI colors to keys/values. Default `true`. Auto-disabled when
2168
+ * `NO_COLOR` is set or output is non-TTY.
2169
+ */
2170
+ colors?: boolean;
2171
+ /**
2172
+ * Maximum nesting depth. Objects/arrays beyond this level are collapsed
2173
+ * to `{...}` / `[...]`. Default `Infinity` (no limit).
2174
+ */
2175
+ maxDepth?: number;
2176
+ /**
2177
+ * Maximum array length to display fully. Arrays longer than this show
2178
+ * the first N items + a `... (M more)` marker. Default `Infinity`.
2179
+ */
2180
+ maxItems?: number;
2181
+ /**
2182
+ * Maximum string length before truncation with ellipsis. Default `Infinity`.
2183
+ */
2184
+ maxStringLength?: number;
2185
+ /**
2186
+ * Sort object keys alphabetically. Useful for deterministic diffs (e.g.,
2187
+ * comparing two JSON snapshots) and for visual scanning of large objects.
2188
+ * Default `false` (insertion order preserved).
2189
+ *
2190
+ * @since 1.3.1
2191
+ */
2192
+ sortKeys?: boolean;
2193
+ /**
2194
+ * Arrays of primitives shorter than this character width (in their
2195
+ * rendered form) are displayed on a single line: `[1, 2, 3]` instead of
2196
+ * three lines. Nested objects/arrays never inline regardless of size.
2197
+ * Set to `0` to disable inlining. Default `60`.
2198
+ *
2199
+ * @since 1.3.1
2200
+ */
2201
+ inlineArrayMaxLength?: number;
2202
+ }
2203
+ /**
2204
+ * Pretty-print a JavaScript value with colored output suitable for
2205
+ * terminal display. Handles primitives, objects, arrays, and circular
2206
+ * references gracefully.
2207
+ *
2208
+ * @param value - Any JavaScript value to render.
2209
+ * @param opts - Optional formatting configuration.
2210
+ *
2211
+ * @example basic
2212
+ * ```js
2213
+ * import { json } from 'ansimax';
2214
+ *
2215
+ * console.log(json.pretty({
2216
+ * name: 'ansimax',
2217
+ * version: '1.3.0',
2218
+ * features: ['colors', 'gradients', 'panels'],
2219
+ * stats: { tests: 2000, coverage: 0.98 },
2220
+ * }));
2221
+ * ```
2222
+ *
2223
+ * @example with depth limit (collapses deeply nested objects)
2224
+ * ```js
2225
+ * console.log(json.pretty(deeplyNestedObject, { maxDepth: 2 }));
2226
+ * // Anything beyond depth 2 renders as {...} or [...]
2227
+ * ```
2228
+ *
2229
+ * @example with item limit (for huge arrays)
2230
+ * ```js
2231
+ * console.log(json.pretty(largeArray, { maxItems: 10 }));
2232
+ * // Shows first 10 items + "... (N more)"
2233
+ * ```
2234
+ *
2235
+ * @example monochrome (e.g. for log files)
2236
+ * ```js
2237
+ * console.log(json.pretty(data, { colors: false }));
2238
+ * ```
2239
+ *
2240
+ * @example handles circular references
2241
+ * ```js
2242
+ * const obj = { name: 'foo' };
2243
+ * obj.self = obj; // circular!
2244
+ * console.log(json.pretty(obj));
2245
+ * // → { "name": "foo", "self": [Circular] }
2246
+ * ```
2247
+ */
2248
+ declare const pretty: (value: unknown, opts?: PrettyOptions) => string;
2249
+ declare const json: {
2250
+ pretty: (value: unknown, opts?: PrettyOptions) => string;
2251
+ };
2252
+
1907
2253
  declare const ansimax: {
1908
2254
  color: {
1909
2255
  black: ColorFn;
@@ -2070,4 +2416,4 @@ declare const ansimax: {
2070
2416
  configure: (opts?: AnsimaxConfig, meta?: ConfigureOptions) => void;
2071
2417
  };
2072
2418
 
2073
- export { ASCII_RAMPS, type AnimateGradientController, type AnimateGradientOptions, type AnimationHooks, type AnimationSpeed, type AnsiCode, type AnsimaxConfig, type AsciiRamp, BEL, BG, type BadgeOptions, type BallOptions, type BannerOptions, type BoxOptions, type BoxStyle, type BreatheOptions, DEFAULTS as CONFIG_DEFAULTS, CSI, type Canvas, type CanvasRenderOptions, type ColorChain, type ColorFn, type ColorLevel, type ColorMode, type ColorSupport, type ColumnsOptions, type ConfigChangeListener, type ConfigKey, type ConfigKeyListener, type ConfigureOptions, type CountdownOptions, type CustomOptions, DEFAULT_TERM_COLS, DEFAULT_TERM_ROWS, type DebounceOptions, type DiffType, type Dimensions, type DividerOptions, type DotsOptions, ESC, type EasingFn, type EasingName, type EraseMode, FG, FRAME_MS, type FadeOptions, type FigletFont, type FigletOptions, type FontMap, type FontName, type FrameCallback, type FrameHandle, type FromImageOptions, type GlitchOptions, type Glyph, type GradientOptions, type GradientRectOptions, type LineDiff, type LiveController, type LiveOptions, type LoadingBarOptions, type LogoOptions, MENU_CANCELLED, type MemoizeOptions, type MenuInput, type MenuOptions, type MenuOutput, type MenuResult, type MultiLoader, type MultiLoaderItem, OSC, type OnResizeOptions, type OutputBuffer, type ParallelOptions, type ParallelStep, type Pixel, type PixelGrid, type PlayController, type PlayOptions, type PresetName, type ProgressAnimateOptions, type ProgressBarOptions, type ProgressOptions, type PulseOptions, type RGB, type RGBA, type RegisterFontOptions, type RenderOptions$1 as RenderOptions, type ResizeListener, type ReusableGradient, type RevealOptions, SPINNERS, SPRITES, ST, STYLE, type SectionOptions, type SleepOptions, type SlideOptions, type SpinOptions, type SpinnerType, type StatusOptions, type StatusType, type StopFn, type StreamOptions, type TableBorderStyle, type TableOptions, type Task, type TaskResult, type TasksOptions, type Theme, type BannerOpts as ThemeBannerOpts, type ThemeChangeListener, type ThemeInstance, type ThemeStyleName, type TimelineEvent, type TimelineOptions, type TreeData, type TreeDimensions, type TreeNode, type RenderOptions as TreeRenderOptions, type TreeStyle, type TypeDeleteOptions, type TypewriterOptions, type WalkVisitor, type WaveOptions, type WriteAsyncOptions, animate, animateGradient, ascii, bell, bg256, bgRgb, box, canAnimate, cancelTerminalFrame, center, chain, charWidth, clamp, clearAnsiCache, clearColorCache, clearRenderCache, clearThemeColorCache, color, colorLevel, presets as colorPresets, components, compose, configure, countNodes, createCanvas, createGradient, createOutputBuffer, createTheme, cursor, debounce, ansimax as default, diffLines, escapeRegex, fg256, fgRgb, figletText, filterTree, findInTree, flipHorizontal, flipVertical, frames, fromImage, getConfig, getConfigValue, getRenderCacheSize, getSpeedMultiplier, getTerminalHeight, getTerminalWidth, gradient, gradientColor, gradientRect, graphemes, hasFont, hexToRgb, hideCursor, images, isHexColor, isNoColor, lerp, lerpColor, link, listFonts, listPresets, loader, mapTree, measureTree, memoize, nextTick, onConfigChange, onConfigKeyChange, onResize, once, padBoth, padEnd, padStart, parseFiglet, pauseListeners, presetNames, presets, rainbow, registerFont, registerPreset, renderPixelArt, renderTree, renderTreeStream, repeatVisible, requestTerminalFrame, reset, resetColorSupportCache, resetConfig, resetCursorRefCount, resetFramesCursorCount, resetLoaderCursorCount, resetNoColor, resumeListeners, reverseGradient, rgbTo256, rgbToHex, rotate90, safeJson, screen, setNoColor, setTitle, sgr, showCursor, sleep, sleepFrame, sliceAnsi, stripAnsi$1 as stripAnsi, stripAnsi$2 as stripAnsiCodes, stripAnsi as stripAnsiColors, supportsColor, supportsColorLevel, termSize, themes, throttle, tree, trees, truncateAnsi, visibleLen, walkTree, withConfig, wordWrap, wrapAnsi, write, writeAsync, writeErr, writeln, writelnErr };
2419
+ export { ASCII_RAMPS, type Alignment, type AnimateGradientController, type AnimateGradientOptions, type AnimationHooks, type AnimationSpeed, type AnsiCode, type AnsimaxConfig, type AsciiRamp, BEL, BG, type BadgeOptions, type BallOptions, type BannerOptions, type BoxOptions, type BoxStyle, type BreatheOptions, DEFAULTS as CONFIG_DEFAULTS, CSI, type Canvas, type CanvasRenderOptions, type CenterOptions, type ColorChain, type ColorFn, type ColorLevel, type ColorMode, type ColorSupport, type ColumnsOptions, type ConfigChangeListener, type ConfigKey, type ConfigKeyListener, type ConfigureOptions, type CountdownOptions, type CustomOptions, DEFAULT_TERM_COLS, DEFAULT_TERM_ROWS, type DebounceOptions, type DiffType, type Dimensions, type DividerOptions, type DotsOptions, ESC, type EasingFn, type EasingName, type EraseMode, FG, FRAME_MS, type FadeOptions, type FigletFont, type FigletOptions, type FontMap, type FontName, type FrameCallback, type FrameHandle, type FrameOptions, type FromImageOptions, type GlitchOptions, type Glyph, type GradientOptions, type GradientRectOptions, type HsplitOptions, type PrettyOptions as JsonPrettyOptions, type LineDiff, type LiveController, type LiveOptions, type LoadingBarOptions, type LogoOptions, MENU_CANCELLED, type MemoizeOptions, type MenuInput, type MenuOptions, type MenuOutput, type MenuResult, type MultiLoader, type MultiLoaderItem, OSC, type OnResizeOptions, type OutputBuffer, type ParallelOptions, type ParallelStep, type Pixel, type PixelGrid, type PlayController, type PlayOptions, type PresetName, type ProgressAnimateOptions, type ProgressBarOptions, type ProgressOptions, type PulseOptions, type RGB, type RGBA, type RegisterFontOptions, type RenderOptions$1 as RenderOptions, type ResizeListener, type ReusableGradient, type RevealOptions, SPINNERS, SPRITES, ST, STYLE, type SectionOptions, type SleepOptions, type SlideOptions, type SpinOptions, type SpinnerType, type StatusOptions, type StatusType, type StopFn, type StreamOptions, type TableBorderStyle, type TableOptions, type Task, type TaskResult, type TasksOptions, type Theme, type BannerOpts as ThemeBannerOpts, type ThemeChangeListener, type ThemeInstance, type ThemeStyleName, type TimelineEvent, type TimelineOptions, type TreeData, type TreeDimensions, type TreeNode, type RenderOptions as TreeRenderOptions, type TreeStyle, type TypeDeleteOptions, type TypewriterOptions, type VsplitOptions, type WalkVisitor, type WaveOptions, type WriteAsyncOptions, animate, animateGradient, ascii, bell, bg256, bgRgb, box, canAnimate, cancelTerminalFrame, center$1 as center, center as centerBlock, chain, charWidth, clamp, clearAnsiCache, clearColorCache, clearRenderCache, clearThemeColorCache, color, colorLevel, presets as colorPresets, components, compose, configure, countNodes, createCanvas, createGradient, createOutputBuffer, createTheme, cursor, debounce, ansimax as default, diffLines, escapeRegex, fg256, fgRgb, figletText, filterTree, findInTree, flipHorizontal, flipVertical, frame, frames, fromImage, getConfig, getConfigValue, getRenderCacheSize, getSpeedMultiplier, getTerminalHeight, getTerminalWidth, gradient, gradientColor, gradientRect, graphemes, hasFont, hexToRgb, hideCursor, hsplit, images, isHexColor, isNoColor, json, pretty as jsonPretty, lerp, lerpColor, link, listFonts, listPresets, loader, mapTree, measureTree, memoize, nextTick, onConfigChange, onConfigKeyChange, onResize, once, padBoth, padEnd, padStart, panels, parseFiglet, pauseListeners, presetNames, presets, rainbow, registerFont, registerPreset, renderPixelArt, renderTree, renderTreeStream, repeatVisible, requestTerminalFrame, reset, resetColorSupportCache, resetConfig, resetCursorRefCount, resetFramesCursorCount, resetLoaderCursorCount, resetNoColor, resumeListeners, reverseGradient, rgbTo256, rgbToHex, rotate90, safeJson, screen, setNoColor, setTitle, sgr, showCursor, sleep, sleepFrame, sliceAnsi, stripAnsi$1 as stripAnsi, stripAnsi$2 as stripAnsiCodes, stripAnsi as stripAnsiColors, supportsColor, supportsColorLevel, termSize, themes, throttle, tree, trees, truncateAnsi, visibleLen, vsplit, walkTree, withConfig, wordWrap, wrapAnsi, write, writeAsync, writeErr, writeln, writelnErr };