ansimax 1.4.0 → 1.4.2

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.ts CHANGED
@@ -1,3 +1,76 @@
1
+ /** Visual theme for rendered output. */
2
+ type MarkdownTheme = 'dark' | 'light';
3
+ interface MarkdownOptions {
4
+ /**
5
+ * Maximum width in columns. Long lines wrap. Default: terminal width
6
+ * or 80 if unavailable.
7
+ */
8
+ width?: number;
9
+ /**
10
+ * Color theme. `'dark'` (default) uses bright colors for dark backgrounds.
11
+ * `'light'` uses dimmer/contrast colors for light backgrounds.
12
+ */
13
+ theme?: MarkdownTheme;
14
+ /**
15
+ * Override the gradient used for top-level (`# H1`) headings. Receives
16
+ * a list of hex colors. Default uses the dracula palette.
17
+ */
18
+ headingGradient?: string[];
19
+ /**
20
+ * Render code blocks inside an ASCII box. Default `true`. If `false`,
21
+ * code blocks render as indented dim text.
22
+ */
23
+ boxCodeBlocks?: boolean;
24
+ /**
25
+ * Inline code background tint. Default `true`. If `false`, inline code
26
+ * shows only as dim text (cleaner in some terminals).
27
+ */
28
+ inlineCodeBackground?: boolean;
29
+ }
30
+ /**
31
+ * Internal options shape passed to `parseInline`. Exposed for advanced
32
+ * use cases that bypass `render` (custom block handlers, etc.).
33
+ *
34
+ * @since 1.4.0
35
+ */
36
+ interface InlineOptions {
37
+ theme: MarkdownTheme;
38
+ inlineCodeBackground: boolean;
39
+ }
40
+ /**
41
+ * Block-level token after parsing the markdown into structural pieces.
42
+ * Tokens contain raw inline text — inline parsing happens at render time.
43
+ *
44
+ * @since 1.4.0
45
+ */
46
+ type Block = {
47
+ type: 'heading';
48
+ level: number;
49
+ text: string;
50
+ } | {
51
+ type: 'paragraph';
52
+ text: string;
53
+ } | {
54
+ type: 'codeblock';
55
+ lang: string;
56
+ code: string;
57
+ } | {
58
+ type: 'list';
59
+ ordered: boolean;
60
+ items: string[];
61
+ } | {
62
+ type: 'blockquote';
63
+ text: string;
64
+ } | {
65
+ type: 'table';
66
+ headers: string[];
67
+ rows: string[][];
68
+ } | {
69
+ type: 'hr';
70
+ } | {
71
+ type: 'blank';
72
+ };
73
+
1
74
  /** Color rendering capability. 'none' suppresses all color output. */
2
75
  type ColorMode = 'none' | 'basic' | '256' | 'truecolor' | 'auto';
3
76
  /** Animation pacing multiplier preset. */
@@ -204,6 +277,60 @@ declare const clampPercent: (p: unknown) => number;
204
277
  * @since 1.3.7
205
278
  */
206
279
  declare const clampInt: (value: unknown, min: number, max: number, fallback?: number) => number;
280
+ /**
281
+ * Coerce any value to a string. Non-strings go through `String()`. `null`
282
+ * and `undefined` become `''` (not `'null'`/`'undefined'`). Consolidates
283
+ * the `typeof v === 'string' ? v : String(v ?? '')` pattern previously
284
+ * duplicated across 5 modules (components, frames, loaders, trees, ansi).
285
+ *
286
+ * @example
287
+ * ```ts
288
+ * ensureString('hello') // → 'hello'
289
+ * ensureString(42) // → '42'
290
+ * ensureString(null) // → ''
291
+ * ensureString(undefined) // → ''
292
+ * ensureString({}) // → '[object Object]'
293
+ * ```
294
+ *
295
+ * @since 1.4.2
296
+ */
297
+ declare const ensureString: (v: unknown) => string;
298
+ /**
299
+ * Coerce to a non-negative integer (≥ 0). Falls back to `fallback` for
300
+ * non-finite input. Floors fractional values.
301
+ *
302
+ * Consolidates the `Math.max(0, Math.floor(n))` pattern previously
303
+ * duplicated as a private `clampNonNeg` in components + trees.
304
+ *
305
+ * @example
306
+ * ```ts
307
+ * clampNonNeg(5.7) // → 5
308
+ * clampNonNeg(-3) // → 0
309
+ * clampNonNeg(NaN, 10) // → 10
310
+ * clampNonNeg('abc', 5) // → 5
311
+ * ```
312
+ *
313
+ * @since 1.4.2
314
+ */
315
+ declare const clampNonNeg: (n: unknown, fallback?: number) => number;
316
+ /**
317
+ * Coerce to a positive integer (≥ 1). Falls back to `fallback` for
318
+ * non-finite input. Floors fractional values.
319
+ *
320
+ * Consolidates the `Math.max(1, Math.floor(n))` pattern previously
321
+ * duplicated as private `clampPositive` / `clampPositiveInt` in
322
+ * components + loaders.
323
+ *
324
+ * @example
325
+ * ```ts
326
+ * clampPositiveInt(5.7) // → 5
327
+ * clampPositiveInt(0) // → 1 (clamped up)
328
+ * clampPositiveInt(NaN, 10) // → 10
329
+ * ```
330
+ *
331
+ * @since 1.4.2
332
+ */
333
+ declare const clampPositiveInt: (n: unknown, fallback?: number) => number;
207
334
  /** Returns true when a string is a valid 3- or 6-digit hex color. */
208
335
  declare const isHexColor: (hex: string) => boolean;
209
336
  /**
@@ -2713,6 +2840,46 @@ interface GridOptions {
2713
2840
  * use the max width of the widest block in their column.
2714
2841
  */
2715
2842
  cellWidth?: number | null;
2843
+ /**
2844
+ * **v1.4.1+** Fix each row to this height (in lines). When the block has
2845
+ * fewer lines, it is padded (using `alignY`). When it has more lines, it
2846
+ * is truncated. If omitted (default), rows take the natural height of
2847
+ * their tallest block.
2848
+ *
2849
+ * @since 1.4.1
2850
+ */
2851
+ cellHeight?: number | null;
2852
+ /**
2853
+ * **v1.4.1+** Per-block column span. `colSpan[i]` is the number of
2854
+ * columns block `i` occupies. Defaults to `1` for every block when
2855
+ * omitted or shorter than `blocks`.
2856
+ *
2857
+ * The auto-flow algorithm wraps to the next row when the current row's
2858
+ * remaining capacity is less than the next block's span. Spans that
2859
+ * exceed `columns` are clamped to `columns`.
2860
+ *
2861
+ * @example
2862
+ * ```js
2863
+ * // Header spans full width, then 2 cells in a row
2864
+ * panels.grid([header, left, right], {
2865
+ * columns: 2,
2866
+ * colSpan: [2, 1, 1],
2867
+ * });
2868
+ * ```
2869
+ *
2870
+ * @since 1.4.1
2871
+ */
2872
+ colSpan?: number[];
2873
+ /**
2874
+ * **v1.4.1+** Auto-flow direction. `'row'` (default) fills cells
2875
+ * left-to-right then wraps to the next row — matches CSS Grid's
2876
+ * `grid-auto-flow: row`. `'column'` fills top-to-bottom then wraps to
2877
+ * the next column. Not applicable when `colSpan` is set with any
2878
+ * span > 1 (forces 'row' mode).
2879
+ *
2880
+ * @since 1.4.1
2881
+ */
2882
+ flow?: 'row' | 'column';
2716
2883
  }
2717
2884
  /**
2718
2885
  * Arrange blocks in a grid of N columns, flowing left-to-right then
@@ -2887,63 +3054,6 @@ declare const json: {
2887
3054
  pretty: (value: unknown, opts?: PrettyOptions) => string;
2888
3055
  };
2889
3056
 
2890
- /** Visual theme for rendered output. */
2891
- type MarkdownTheme = 'dark' | 'light';
2892
- interface MarkdownOptions {
2893
- /**
2894
- * Maximum width in columns. Long lines wrap. Default: terminal width
2895
- * or 80 if unavailable.
2896
- */
2897
- width?: number;
2898
- /**
2899
- * Color theme. `'dark'` (default) uses bright colors for dark backgrounds.
2900
- * `'light'` uses dimmer/contrast colors for light backgrounds.
2901
- */
2902
- theme?: MarkdownTheme;
2903
- /**
2904
- * Override the gradient used for top-level (`# H1`) headings. Receives
2905
- * a list of hex colors. Default uses the dracula palette.
2906
- */
2907
- headingGradient?: string[];
2908
- /**
2909
- * Render code blocks inside an ASCII box. Default `true`. If `false`,
2910
- * code blocks render as indented dim text.
2911
- */
2912
- boxCodeBlocks?: boolean;
2913
- /**
2914
- * Inline code background tint. Default `true`. If `false`, inline code
2915
- * shows only as dim text (cleaner in some terminals).
2916
- */
2917
- inlineCodeBackground?: boolean;
2918
- }
2919
- /** Block-level token after parsing the markdown into structural pieces. */
2920
- type Block = {
2921
- type: 'heading';
2922
- level: number;
2923
- text: string;
2924
- } | {
2925
- type: 'paragraph';
2926
- text: string;
2927
- } | {
2928
- type: 'codeblock';
2929
- lang: string;
2930
- code: string;
2931
- } | {
2932
- type: 'list';
2933
- ordered: boolean;
2934
- items: string[];
2935
- } | {
2936
- type: 'blockquote';
2937
- text: string;
2938
- } | {
2939
- type: 'table';
2940
- headers: string[];
2941
- rows: string[][];
2942
- } | {
2943
- type: 'hr';
2944
- } | {
2945
- type: 'blank';
2946
- };
2947
3057
  /**
2948
3058
  * Parse markdown source into a flat sequence of block tokens.
2949
3059
  * Tokens contain raw inline text — inline parsing happens at render time.
@@ -2951,15 +3061,14 @@ type Block = {
2951
3061
  * @since 1.4.0
2952
3062
  */
2953
3063
  declare const parseBlocks: (source: string) => Block[];
3064
+
2954
3065
  /**
2955
3066
  * Apply inline markdown markup (bold/italic/code/links/etc.) to a string.
2956
3067
  *
2957
3068
  * @since 1.4.0
2958
3069
  */
2959
- declare const parseInline: (text: string, opts?: {
2960
- theme: MarkdownTheme;
2961
- inlineCodeBackground: boolean;
2962
- }) => string;
3070
+ declare const parseInline: (text: string, opts?: InlineOptions) => string;
3071
+
2963
3072
  /**
2964
3073
  * Render a markdown source string to a terminal-ready string with ANSI
2965
3074
  * styling. Handles headings, paragraphs, code blocks, lists, blockquotes,
@@ -2988,6 +3097,7 @@ declare const parseInline: (text: string, opts?: {
2988
3097
  * @since 1.4.0
2989
3098
  */
2990
3099
  declare const render: (source: string, opts?: MarkdownOptions) => string;
3100
+
2991
3101
  /**
2992
3102
  * Markdown → terminal renderer. Use `markdown.render(source, opts?)` to
2993
3103
  * convert a markdown string to an ANSI-styled string ready for
@@ -3001,10 +3111,7 @@ declare const render: (source: string, opts?: MarkdownOptions) => string;
3001
3111
  declare const markdown: {
3002
3112
  render: (source: string, opts?: MarkdownOptions) => string;
3003
3113
  parseBlocks: (source: string) => Block[];
3004
- parseInline: (text: string, opts?: {
3005
- theme: MarkdownTheme;
3006
- inlineCodeBackground: boolean;
3007
- }) => string;
3114
+ parseInline: (text: string, opts?: InlineOptions) => string;
3008
3115
  };
3009
3116
 
3010
3117
  type EasingFunction = (t: number) => number;
@@ -3220,38 +3327,9 @@ declare const ansimax: {
3220
3327
  };
3221
3328
  markdown: {
3222
3329
  render: (source: string, opts?: MarkdownOptions) => string;
3223
- parseBlocks: (source: string) => ({
3224
- type: "heading";
3225
- level: number;
3226
- text: string;
3227
- } | {
3228
- type: "paragraph";
3229
- text: string;
3230
- } | {
3231
- type: "codeblock";
3232
- lang: string;
3233
- code: string;
3234
- } | {
3235
- type: "list";
3236
- ordered: boolean;
3237
- items: string[];
3238
- } | {
3239
- type: "blockquote";
3240
- text: string;
3241
- } | {
3242
- type: "table";
3243
- headers: string[];
3244
- rows: string[][];
3245
- } | {
3246
- type: "hr";
3247
- } | {
3248
- type: "blank";
3249
- })[];
3250
- parseInline: (text: string, opts?: {
3251
- theme: MarkdownTheme;
3252
- inlineCodeBackground: boolean;
3253
- }) => string;
3330
+ parseBlocks: (source: string) => Block[];
3331
+ parseInline: (text: string, opts?: InlineOptions) => string;
3254
3332
  };
3255
3333
  };
3256
3334
 
3257
- 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 ColorSpace, 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 EasingFunction, type EasingLibraryName, 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 GridOptions, type HSL, type HsplitOptions, type PrettyOptions as JsonPrettyOptions, type LineDiff, type LiveController, type LiveOptions, type LoadingBarOptions, type LogoOptions, MENU_CANCELLED, type MarkdownOptions, type MarkdownTheme, type MemoizeOptions, type MenuInput, type MenuOptions, type MenuOutput, type MenuResult, type MultiLoader, type MultiLoaderItem, OSC, type Oklab, 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, clampByte, clampInt, clampPercent, clearAnsiCache, clearColorCache, clearLine, clearRenderCache, clearThemeColorCache, color, colorLevel, presets as colorPresets, components, compose, configure, countNodes, createCanvas, createGradient, createOutputBuffer, createTheme, cursor, debounce, ansimax as default, diffLines, easings, escapeForRegex, escapeRegex, fg256, fgRgb, figletText, filterTree, findInTree, flipHorizontal, flipVertical, frame, frames, fromImage, getConfig, getConfigValue, getRenderCacheSize, getSpeedMultiplier, getTerminalHeight, getTerminalWidth, gradient, gradientColor, gradientRect, gradientStops, graphemes, grid, hasFont, hexToRgb, hideCursor, hslToRgb, hsplit, hyperlink, images, isFiniteNumber, isHexColor, isNoColor, json, pretty as jsonPretty, lerp, lerpColor, link, listFonts, listPresets, loader, mapTree, markdown, measureBlock, measureTree, memoize, mixColors, nextTick, oklabToRgb, onConfigChange, onConfigKeyChange, onResize, once, padBoth, padEnd, padStart, panels, parseFiglet, parseBlocks as parseMarkdownBlocks, parseInline as parseMarkdownInline, pauseListeners, presetNames, presets, quantizeColor, rainbow, registerFont, registerPreset, render as renderMarkdown, renderPixelArt, renderTree, renderTreeStream, repeatVisible, requestTerminalFrame, reset, resetColorSupportCache, resetConfig, resetCursorRefCount, resetFramesCursorCount, resetLoaderCursorCount, resetNoColor, resolveEasingByName, resumeListeners, reverseGradient, rgbTo256, rgbToHex, rgbToHsl, rgbToOklab, rotate90, safeInt, safeJson, screen, setConfigValue, setNoColor, setTitle, sgr, showCursor, sleep, sleepFrame, sliceAnsi, stripAnsi$2 as stripAnsi, stripAnsi$1 as stripAnsiCodes, stripAnsi as stripAnsiColors, subscribeConfig, supportsColor, supportsColorLevel, termSize, themes, throttle, tree, trees, truncateAnsi, visibleLen, vsplit, walkTree, withConfig, wordWrap, wrapAnsi, write, writeAsync, writeErr, writeln, writelnErr };
3335
+ 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 ColorSpace, 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 EasingFunction, type EasingLibraryName, 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 GridOptions, type HSL, type HsplitOptions, type PrettyOptions as JsonPrettyOptions, type LineDiff, type LiveController, type LiveOptions, type LoadingBarOptions, type LogoOptions, MENU_CANCELLED, type MarkdownOptions, type MarkdownTheme, type MemoizeOptions, type MenuInput, type MenuOptions, type MenuOutput, type MenuResult, type MultiLoader, type MultiLoaderItem, OSC, type Oklab, 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, clampByte, clampInt, clampNonNeg, clampPercent, clampPositiveInt, clearAnsiCache, clearColorCache, clearLine, clearRenderCache, clearThemeColorCache, color, colorLevel, presets as colorPresets, components, compose, configure, countNodes, createCanvas, createGradient, createOutputBuffer, createTheme, cursor, debounce, ansimax as default, diffLines, easings, ensureString, escapeForRegex, escapeRegex, fg256, fgRgb, figletText, filterTree, findInTree, flipHorizontal, flipVertical, frame, frames, fromImage, getConfig, getConfigValue, getRenderCacheSize, getSpeedMultiplier, getTerminalHeight, getTerminalWidth, gradient, gradientColor, gradientRect, gradientStops, graphemes, grid, hasFont, hexToRgb, hideCursor, hslToRgb, hsplit, hyperlink, images, isFiniteNumber, isHexColor, isNoColor, json, pretty as jsonPretty, lerp, lerpColor, link, listFonts, listPresets, loader, mapTree, markdown, measureBlock, measureTree, memoize, mixColors, nextTick, oklabToRgb, onConfigChange, onConfigKeyChange, onResize, once, padBoth, padEnd, padStart, panels, parseFiglet, parseBlocks as parseMarkdownBlocks, parseInline as parseMarkdownInline, pauseListeners, presetNames, presets, quantizeColor, rainbow, registerFont, registerPreset, render as renderMarkdown, renderPixelArt, renderTree, renderTreeStream, repeatVisible, requestTerminalFrame, reset, resetColorSupportCache, resetConfig, resetCursorRefCount, resetFramesCursorCount, resetLoaderCursorCount, resetNoColor, resolveEasingByName, resumeListeners, reverseGradient, rgbTo256, rgbToHex, rgbToHsl, rgbToOklab, rotate90, safeInt, safeJson, screen, setConfigValue, setNoColor, setTitle, sgr, showCursor, sleep, sleepFrame, sliceAnsi, stripAnsi$2 as stripAnsi, stripAnsi$1 as stripAnsiCodes, stripAnsi as stripAnsiColors, subscribeConfig, supportsColor, supportsColorLevel, termSize, themes, throttle, tree, trees, truncateAnsi, visibleLen, vsplit, walkTree, withConfig, wordWrap, wrapAnsi, write, writeAsync, writeErr, writeln, writelnErr };