//#region src/types.d.ts /** * Shared public types for all entrypoints. * * @module ansispeck/types */ /** Input accepted by all formatters. */ type Formattable = string | number | boolean | bigint | null | undefined; /** Wraps input in ANSI escape codes. */ type Formatter = (input: Formattable) => string; /** * Wraps text in an OSC 8 terminal hyperlink. Text defaults to the URL. * * Emission is gated by hyperlink support ({@link Colors.isHyperlinkSupported}), * which is independent of color. When unsupported, the text is returned * plain — so an omitted label degrades to the destination URL. * * @see https://no-hyperlinks.org/ */ interface LinkFormatter { (url: string | InstanceType, text?: Formattable | InstanceType): string; (strings: TemplateStringsArray, ...values: readonly unknown[]): string; } /** Template-tag formatter (`ansispeck/safe`) that re-opens its style across interpolations. */ type TemplateFormatter = (strings: TemplateStringsArray, ...values: readonly Formattable[]) => string; /** ANSI text style modifier names. */ type StyleName = "blink" | "bold" | "dim" | "doubleUnderline" | "hidden" | "inverse" | "italic" | "overline" | "reset" | "strikethrough" | "underline"; /** Base 8 ANSI foreground color names (plus gray/grey). */ type BaseColorName = "black" | "blue" | "cyan" | "gray" | "green" | "grey" | "magenta" | "red" | "white" | "yellow"; /** Only these get `Bright`/`bg` variants (so `gray`/`grey` won't). */ type VariantBaseColorName = Exclude; /** Union of all valid formatter keys. */ type FormatterName = StyleName | BaseColorName | `${VariantBaseColorName}Bright` | `bg${Capitalize}` | `bg${Capitalize}Bright`; /** Plain formatter palette (`raw`/`auto`/`noop` entrypoints). */ interface Palette extends Readonly> {} /** Template-tag palette (`ansispeck/safe`). */ interface TemplatePalette extends Readonly> {} /** 256-color and truecolor formatter factories, generic over formatter flavor. */ interface Factories { /** Set the background with a 256-color palette index. */ readonly bg256: (n: number) => T; /** Set the background from a `#rgb` or `#rrggbb` hex string. */ readonly bgHex: (color: string) => T; /** Set the background with a 24-bit RGB triple. */ readonly bgRgb: (r: number, g: number, b: number) => T; /** Color the foreground with a 256-color palette index. */ readonly fg256: (n: number) => T; /** Color the foreground from a `#rgb` or `#rrggbb` hex string. */ readonly hex: (color: string) => T; /** Color the foreground with a 24-bit RGB triple. */ readonly rgb: (r: number, g: number, b: number) => T; } /** All available color/style formatters plus support flags. */ interface Colors extends Palette, Factories { /** Whether ANSI output is enabled. */ readonly isColorSupported: boolean; /** Whether {@link link} emits OSC 8 sequences. Independent of color. */ readonly isHyperlinkSupported: boolean; /** Wrap text in an OSC 8 terminal hyperlink. */ readonly link: LinkFormatter; /** Produce one space, or `count` spaces when provided. */ readonly space: (count?: number) => string; /** Produce one tab, or `count` tabs when provided. */ readonly tab: (count?: number) => string; } /** Template-tag color set (`ansispeck/safe`). */ interface SafeColors extends TemplatePalette, Factories { /** Whether ANSI output is enabled. */ readonly isColorSupported: boolean; /** Whether {@link link} emits OSC 8 sequences. Independent of color. */ readonly isHyperlinkSupported: boolean; /** Wrap text in an OSC 8 terminal hyperlink. */ readonly link: LinkFormatter; /** Produce one space, or `count` spaces when provided. */ readonly space: (count?: number) => string; /** Produce one tab, or `count` tabs when provided. */ readonly tab: (count?: number) => string; } /** Internal brand for rope/chunk nodes. */ declare const CHUNK_BRAND: unique symbol; /** Rope text leaf. */ interface TextChunk { /** Discriminant for a text leaf. */ readonly kind: "text"; /** String value stored by the leaf. */ readonly value: string; /** Identifies this value as an ansispeck chunk. */ readonly [CHUNK_BRAND]: true; } /** Rope concat node (O(1) composition). */ interface ConcatChunk { /** Discriminant for a concatenation node. */ readonly kind: "concat"; /** Left child. */ readonly left: Chunk; /** Right child. */ readonly right: Chunk; /** Identifies this value as an ansispeck chunk. */ readonly [CHUNK_BRAND]: true; } /** Rope style wrapper node. */ interface StyledChunk { /** ANSI sequence that closes the style. */ readonly close: string; /** Chunk wrapped by the style. */ readonly inner: Chunk; /** Discriminant for a style node. */ readonly kind: "style"; /** ANSI sequence that opens the style. */ readonly open: string; /** Identifies this value as an ansispeck chunk. */ readonly [CHUNK_BRAND]: true; } /** Immutable chunk tree used by the rope API. */ type Chunk = TextChunk | ConcatChunk | StyledChunk; /** Values accepted by rope operations. */ type Chunkable = Chunk | Formattable; /** Chunk formatter used by the rope entrypoint. */ type ChunkFormatter = (input: Chunkable) => Chunk; /** Rope formatter palette (`ansispeck/rope`). */ interface ChunkPalette extends Readonly> {} /** Rope API for O(1) composition + O(n) final render. */ interface Rope extends ChunkPalette, Factories { /** Concatenate chunks and values into one chunk. */ readonly concat: (...inputs: readonly Chunkable[]) => Chunk; /** Whether ANSI output is enabled. */ readonly isColorSupported: boolean; /** Render a chunk tree or plain value to a string. */ readonly render: (input: Chunkable) => string; /** Produce one space, or `count` spaces when provided. */ readonly space: (count?: number) => string; /** Produce one tab, or `count` tabs when provided. */ readonly tab: (count?: number) => string; /** Create a text leaf chunk. */ readonly text: (input: Formattable) => Chunk; } //#endregion //#region src/internal/whitespace.d.ts /** Produce one space, or `count` spaces when provided. */ declare const space: (count?: number) => string; /** Produce one tab, or `count` tabs when provided. */ declare const tab: (count?: number) => string; //#endregion export { TextChunk as C, TemplatePalette as S, Rope as _, Chunk as a, StyledChunk as b, Chunkable as c, Factories as d, Formattable as f, Palette as g, LinkFormatter as h, CHUNK_BRAND as i, Colors as l, FormatterName as m, tab as n, ChunkFormatter as o, Formatter as p, BaseColorName as r, ChunkPalette as s, space as t, ConcatChunk as u, SafeColors as v, VariantBaseColorName as w, TemplateFormatter as x, StyleName as y };