ansimax 1.3.6 → 1.4.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.d.ts CHANGED
@@ -168,6 +168,42 @@ declare const lerp: (a: number, b: number, t: number) => number;
168
168
  * @since 1.3.5
169
169
  */
170
170
  declare const clampByte: (v: number) => number;
171
+ /**
172
+ * Clamp + coerce a number to the 0–100 percentage range. Returns `0` for
173
+ * non-finite input. Consolidates duplicate `clampPercent` definitions
174
+ * previously living in `components/index.ts` and `loaders/index.ts`.
175
+ *
176
+ * @example
177
+ * ```ts
178
+ * clampPercent(50) // → 50
179
+ * clampPercent(150) // → 100
180
+ * clampPercent(-5) // → 0
181
+ * clampPercent(NaN) // → 0
182
+ * clampPercent('abc') // → 0
183
+ * ```
184
+ *
185
+ * @since 1.3.7
186
+ */
187
+ declare const clampPercent: (p: unknown) => number;
188
+ /**
189
+ * Coerce any value to an integer clamped between `[min, max]`. Returns
190
+ * `fallback` (which is also clamped) when input is non-finite.
191
+ *
192
+ * More flexible than `safeInt` for the common pattern
193
+ * `Math.max(min, Math.min(max, Math.floor(n)))` that appears 30+ times
194
+ * across the codebase.
195
+ *
196
+ * @example
197
+ * ```ts
198
+ * clampInt(50, 0, 100) // → 50
199
+ * clampInt(150, 0, 100) // → 100
200
+ * clampInt(NaN, 0, 100, 25) // → 25 (fallback)
201
+ * clampInt('abc', 0, 100, 25) // → 25 (fallback)
202
+ * ```
203
+ *
204
+ * @since 1.3.7
205
+ */
206
+ declare const clampInt: (value: unknown, min: number, max: number, fallback?: number) => number;
171
207
  /** Returns true when a string is a valid 3- or 6-digit hex color. */
172
208
  declare const isHexColor: (hex: string) => boolean;
173
209
  /**
@@ -2851,6 +2887,126 @@ declare const json: {
2851
2887
  pretty: (value: unknown, opts?: PrettyOptions) => string;
2852
2888
  };
2853
2889
 
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
+ /**
2948
+ * Parse markdown source into a flat sequence of block tokens.
2949
+ * Tokens contain raw inline text — inline parsing happens at render time.
2950
+ *
2951
+ * @since 1.4.0
2952
+ */
2953
+ declare const parseBlocks: (source: string) => Block[];
2954
+ /**
2955
+ * Apply inline markdown markup (bold/italic/code/links/etc.) to a string.
2956
+ *
2957
+ * @since 1.4.0
2958
+ */
2959
+ declare const parseInline: (text: string, opts?: {
2960
+ theme: MarkdownTheme;
2961
+ inlineCodeBackground: boolean;
2962
+ }) => string;
2963
+ /**
2964
+ * Render a markdown source string to a terminal-ready string with ANSI
2965
+ * styling. Handles headings, paragraphs, code blocks, lists, blockquotes,
2966
+ * tables, inline emphasis, links, and horizontal rules.
2967
+ *
2968
+ * @example
2969
+ * ```ts
2970
+ * import { markdown } from 'ansimax';
2971
+ *
2972
+ * const out = markdown.render(`
2973
+ * # Welcome
2974
+ *
2975
+ * This is **bold** with \`inline code\` and [a link](https://example.com).
2976
+ *
2977
+ * - First item
2978
+ * - Second item
2979
+ *
2980
+ * \`\`\`js
2981
+ * const x = 42;
2982
+ * \`\`\`
2983
+ * `);
2984
+ *
2985
+ * console.log(out);
2986
+ * ```
2987
+ *
2988
+ * @since 1.4.0
2989
+ */
2990
+ declare const render: (source: string, opts?: MarkdownOptions) => string;
2991
+ /**
2992
+ * Markdown → terminal renderer. Use `markdown.render(source, opts?)` to
2993
+ * convert a markdown string to an ANSI-styled string ready for
2994
+ * `console.log` or `process.stdout.write`.
2995
+ *
2996
+ * Lower-level helpers `parseBlocks` and `parseInline` are also exposed
2997
+ * for advanced use cases (custom block handlers, partial rendering).
2998
+ *
2999
+ * @since 1.4.0
3000
+ */
3001
+ declare const markdown: {
3002
+ render: (source: string, opts?: MarkdownOptions) => string;
3003
+ parseBlocks: (source: string) => Block[];
3004
+ parseInline: (text: string, opts?: {
3005
+ theme: MarkdownTheme;
3006
+ inlineCodeBackground: boolean;
3007
+ }) => string;
3008
+ };
3009
+
2854
3010
  type EasingFunction = (t: number) => number;
2855
3011
  /**
2856
3012
  * Union of all built-in easing names in the comprehensive Robert Penner
@@ -3052,6 +3208,50 @@ declare const ansimax: {
3052
3208
  clearAnsiCache: () => void;
3053
3209
  };
3054
3210
  configure: (opts?: AnsimaxConfig, meta?: ConfigureOptions) => void;
3211
+ panels: {
3212
+ vsplit: (blocks: string[], opts?: VsplitOptions) => string;
3213
+ hsplit: (blocks: string[], opts?: HsplitOptions) => string;
3214
+ center: (block: string, opts: CenterOptions) => string;
3215
+ frame: (block: string, opts?: FrameOptions) => string;
3216
+ grid: (blocks: string[], opts: GridOptions) => string;
3217
+ };
3218
+ json: {
3219
+ pretty: (value: unknown, opts?: PrettyOptions) => string;
3220
+ };
3221
+ markdown: {
3222
+ 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;
3254
+ };
3055
3255
  };
3056
3256
 
3057
- 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 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, 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, measureBlock, measureTree, memoize, mixColors, nextTick, oklabToRgb, onConfigChange, onConfigKeyChange, onResize, once, padBoth, padEnd, padStart, panels, parseFiglet, pauseListeners, presetNames, presets, quantizeColor, rainbow, registerFont, registerPreset, 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 };
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 };