@oh-my-pi-zen/pi-utils 16.3.6-zen.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/CHANGELOG.md +245 -0
- package/README.md +36 -0
- package/dist/types/abortable.d.ts +32 -0
- package/dist/types/async.d.ts +6 -0
- package/dist/types/binary.d.ts +17 -0
- package/dist/types/cli.d.ts +117 -0
- package/dist/types/color.d.ts +102 -0
- package/dist/types/dirs.d.ts +260 -0
- package/dist/types/env.d.ts +74 -0
- package/dist/types/fetch-retry.d.ts +94 -0
- package/dist/types/format.d.ts +37 -0
- package/dist/types/frontmatter.d.ts +25 -0
- package/dist/types/fs-error.d.ts +31 -0
- package/dist/types/glob.d.ts +28 -0
- package/dist/types/index.d.ts +35 -0
- package/dist/types/json-parse.d.ts +48 -0
- package/dist/types/json.d.ts +4 -0
- package/dist/types/logger.d.ts +83 -0
- package/dist/types/loop-phase.d.ts +10 -0
- package/dist/types/mermaid-ascii.d.ts +11 -0
- package/dist/types/mime.d.ts +29 -0
- package/dist/types/module-timer.d.ts +1 -0
- package/dist/types/path-tree.d.ts +76 -0
- package/dist/types/path.d.ts +2 -0
- package/dist/types/peek-file.d.ts +29 -0
- package/dist/types/postmortem.d.ts +37 -0
- package/dist/types/procmgr.d.ts +29 -0
- package/dist/types/prompt.d.ts +18 -0
- package/dist/types/ptree.d.ts +108 -0
- package/dist/types/ring.d.ts +93 -0
- package/dist/types/runtime-install.d.ts +68 -0
- package/dist/types/sanitize-text.d.ts +29 -0
- package/dist/types/snowflake.d.ts +25 -0
- package/dist/types/stream.d.ts +68 -0
- package/dist/types/tab-spacing.d.ts +24 -0
- package/dist/types/temp.d.ts +17 -0
- package/dist/types/timing-buffer.d.ts +22 -0
- package/dist/types/tls-fetch.d.ts +37 -0
- package/dist/types/type-guards.d.ts +3 -0
- package/dist/types/vendor/mermaid-ascii/ascii/ansi.d.ts +41 -0
- package/dist/types/vendor/mermaid-ascii/ascii/canvas.d.ts +89 -0
- package/dist/types/vendor/mermaid-ascii/ascii/class-diagram.d.ts +7 -0
- package/dist/types/vendor/mermaid-ascii/ascii/converter.d.ts +12 -0
- package/dist/types/vendor/mermaid-ascii/ascii/draw.d.ts +66 -0
- package/dist/types/vendor/mermaid-ascii/ascii/edge-bundling.d.ts +48 -0
- package/dist/types/vendor/mermaid-ascii/ascii/edge-routing.d.ts +43 -0
- package/dist/types/vendor/mermaid-ascii/ascii/er-diagram.d.ts +7 -0
- package/dist/types/vendor/mermaid-ascii/ascii/grid.d.ts +56 -0
- package/dist/types/vendor/mermaid-ascii/ascii/index.d.ts +65 -0
- package/dist/types/vendor/mermaid-ascii/ascii/multiline-utils.d.ts +27 -0
- package/dist/types/vendor/mermaid-ascii/ascii/pathfinder.d.ts +17 -0
- package/dist/types/vendor/mermaid-ascii/ascii/sequence.d.ts +7 -0
- package/dist/types/vendor/mermaid-ascii/ascii/shapes/circle.d.ts +11 -0
- package/dist/types/vendor/mermaid-ascii/ascii/shapes/corners.d.ts +34 -0
- package/dist/types/vendor/mermaid-ascii/ascii/shapes/diamond.d.ts +11 -0
- package/dist/types/vendor/mermaid-ascii/ascii/shapes/hexagon.d.ts +11 -0
- package/dist/types/vendor/mermaid-ascii/ascii/shapes/index.d.ts +26 -0
- package/dist/types/vendor/mermaid-ascii/ascii/shapes/rectangle.d.ts +31 -0
- package/dist/types/vendor/mermaid-ascii/ascii/shapes/rounded.d.ts +11 -0
- package/dist/types/vendor/mermaid-ascii/ascii/shapes/special.d.ts +59 -0
- package/dist/types/vendor/mermaid-ascii/ascii/shapes/stadium.d.ts +17 -0
- package/dist/types/vendor/mermaid-ascii/ascii/shapes/state.d.ts +30 -0
- package/dist/types/vendor/mermaid-ascii/ascii/shapes/types.d.ts +55 -0
- package/dist/types/vendor/mermaid-ascii/ascii/types.d.ts +206 -0
- package/dist/types/vendor/mermaid-ascii/ascii/validate.d.ts +51 -0
- package/dist/types/vendor/mermaid-ascii/ascii/xychart.d.ts +2 -0
- package/dist/types/vendor/mermaid-ascii/class/parser.d.ts +6 -0
- package/dist/types/vendor/mermaid-ascii/class/types.d.ts +102 -0
- package/dist/types/vendor/mermaid-ascii/er/parser.d.ts +6 -0
- package/dist/types/vendor/mermaid-ascii/er/types.d.ts +76 -0
- package/dist/types/vendor/mermaid-ascii/index.d.ts +1 -0
- package/dist/types/vendor/mermaid-ascii/multiline-utils.d.ts +9 -0
- package/dist/types/vendor/mermaid-ascii/parser.d.ts +7 -0
- package/dist/types/vendor/mermaid-ascii/sequence/parser.d.ts +6 -0
- package/dist/types/vendor/mermaid-ascii/sequence/types.d.ts +130 -0
- package/dist/types/vendor/mermaid-ascii/text-metrics.d.ts +21 -0
- package/dist/types/vendor/mermaid-ascii/types.d.ts +114 -0
- package/dist/types/vendor/mermaid-ascii/xychart/colors.d.ts +25 -0
- package/dist/types/vendor/mermaid-ascii/xychart/parser.d.ts +6 -0
- package/dist/types/vendor/mermaid-ascii/xychart/types.d.ts +145 -0
- package/dist/types/which.d.ts +37 -0
- package/dist/types/worker-host.d.ts +47 -0
- package/package.json +62 -0
- package/src/abortable.ts +109 -0
- package/src/async.ts +50 -0
- package/src/binary.ts +50 -0
- package/src/cli.ts +457 -0
- package/src/color.ts +302 -0
- package/src/dirs.ts +925 -0
- package/src/env.ts +226 -0
- package/src/fetch-retry.ts +355 -0
- package/src/format.ts +113 -0
- package/src/frontmatter.ts +162 -0
- package/src/fs-error.ts +56 -0
- package/src/glob.ts +189 -0
- package/src/index.ts +55 -0
- package/src/json-parse.ts +612 -0
- package/src/json.ts +10 -0
- package/src/logger.ts +672 -0
- package/src/loop-phase.ts +49 -0
- package/src/mermaid-ascii.ts +31 -0
- package/src/mime.ts +159 -0
- package/src/module-timer.ts +148 -0
- package/src/path-tree.ts +147 -0
- package/src/path.ts +28 -0
- package/src/peek-file.ts +188 -0
- package/src/postmortem.ts +222 -0
- package/src/procmgr.ts +195 -0
- package/src/prompt.ts +562 -0
- package/src/ptree.ts +395 -0
- package/src/ring.ts +169 -0
- package/src/runtime-install.ts +372 -0
- package/src/sanitize-text.ts +96 -0
- package/src/snowflake.ts +121 -0
- package/src/stream.ts +432 -0
- package/src/tab-spacing.ts +336 -0
- package/src/temp.ts +134 -0
- package/src/timing-buffer.ts +47 -0
- package/src/tls-fetch.ts +178 -0
- package/src/type-guards.ts +11 -0
- package/src/vendor/mermaid-ascii/NOTICE +33 -0
- package/src/vendor/mermaid-ascii/ascii/ansi.ts +409 -0
- package/src/vendor/mermaid-ascii/ascii/canvas.ts +476 -0
- package/src/vendor/mermaid-ascii/ascii/class-diagram.ts +699 -0
- package/src/vendor/mermaid-ascii/ascii/converter.ts +271 -0
- package/src/vendor/mermaid-ascii/ascii/draw.ts +1382 -0
- package/src/vendor/mermaid-ascii/ascii/edge-bundling.ts +328 -0
- package/src/vendor/mermaid-ascii/ascii/edge-routing.ts +297 -0
- package/src/vendor/mermaid-ascii/ascii/er-diagram.ts +441 -0
- package/src/vendor/mermaid-ascii/ascii/grid.ts +578 -0
- package/src/vendor/mermaid-ascii/ascii/index.ts +187 -0
- package/src/vendor/mermaid-ascii/ascii/multiline-utils.ts +78 -0
- package/src/vendor/mermaid-ascii/ascii/pathfinder.ts +215 -0
- package/src/vendor/mermaid-ascii/ascii/sequence.ts +460 -0
- package/src/vendor/mermaid-ascii/ascii/shapes/circle.ts +27 -0
- package/src/vendor/mermaid-ascii/ascii/shapes/corners.ts +127 -0
- package/src/vendor/mermaid-ascii/ascii/shapes/diamond.ts +27 -0
- package/src/vendor/mermaid-ascii/ascii/shapes/hexagon.ts +27 -0
- package/src/vendor/mermaid-ascii/ascii/shapes/index.ts +101 -0
- package/src/vendor/mermaid-ascii/ascii/shapes/rectangle.ts +175 -0
- package/src/vendor/mermaid-ascii/ascii/shapes/rounded.ts +27 -0
- package/src/vendor/mermaid-ascii/ascii/shapes/special.ts +296 -0
- package/src/vendor/mermaid-ascii/ascii/shapes/stadium.ts +114 -0
- package/src/vendor/mermaid-ascii/ascii/shapes/state.ts +192 -0
- package/src/vendor/mermaid-ascii/ascii/shapes/types.ts +73 -0
- package/src/vendor/mermaid-ascii/ascii/types.ts +273 -0
- package/src/vendor/mermaid-ascii/ascii/validate.ts +120 -0
- package/src/vendor/mermaid-ascii/ascii/xychart.ts +875 -0
- package/src/vendor/mermaid-ascii/class/parser.ts +290 -0
- package/src/vendor/mermaid-ascii/class/types.ts +121 -0
- package/src/vendor/mermaid-ascii/er/parser.ts +181 -0
- package/src/vendor/mermaid-ascii/er/types.ts +91 -0
- package/src/vendor/mermaid-ascii/index.ts +14 -0
- package/src/vendor/mermaid-ascii/multiline-utils.ts +30 -0
- package/src/vendor/mermaid-ascii/parser.ts +645 -0
- package/src/vendor/mermaid-ascii/sequence/parser.ts +207 -0
- package/src/vendor/mermaid-ascii/sequence/types.ts +146 -0
- package/src/vendor/mermaid-ascii/text-metrics.ts +71 -0
- package/src/vendor/mermaid-ascii/types.ts +164 -0
- package/src/vendor/mermaid-ascii/xychart/colors.ts +140 -0
- package/src/vendor/mermaid-ascii/xychart/parser.ts +115 -0
- package/src/vendor/mermaid-ascii/xychart/types.ts +150 -0
- package/src/which.ts +232 -0
- package/src/worker-host.ts +92 -0
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
export declare function readLines(stream: ReadableStream<Uint8Array>, signal?: AbortSignal): AsyncGenerator<Uint8Array>;
|
|
2
|
+
export declare function readJsonl<T>(stream: ReadableStream<Uint8Array>, signal?: AbortSignal): AsyncGenerator<T>;
|
|
3
|
+
/**
|
|
4
|
+
* Stream parsed JSON objects from SSE `data:` lines.
|
|
5
|
+
*
|
|
6
|
+
* Thin wrapper over {@link readSseEvents}: yields one parsed JSON value per
|
|
7
|
+
* dispatched SSE event, skipping events with empty `data` and stopping at the
|
|
8
|
+
* OpenAI-style `[DONE]` sentinel. If your consumer doesn't care about `event:`
|
|
9
|
+
* names or doesn't need a custom parse step, use this; otherwise call
|
|
10
|
+
* `readSseEvents` directly.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* for await (const obj of readSseJson(response.body!)) {
|
|
15
|
+
* console.log(obj);
|
|
16
|
+
* }
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export type SseEventObserver = (event: ServerSentEvent) => void;
|
|
20
|
+
export declare function readSseJson<T>(stream: ReadableStream<Uint8Array>, signal?: AbortSignal, onEvent?: SseEventObserver): AsyncGenerator<T>;
|
|
21
|
+
/**
|
|
22
|
+
* A single Server-Sent Event dispatched on a blank-line boundary.
|
|
23
|
+
*
|
|
24
|
+
* - `event` is the value of the most recent `event:` field, or `null` if none.
|
|
25
|
+
* - `data` is the concatenation (joined by `\n`) of every `data:` field in the
|
|
26
|
+
* event, exactly as required by the SSE spec.
|
|
27
|
+
* - `raw` is the list of decoded non-empty lines that made up the event,
|
|
28
|
+
* preserved for diagnostic context (error reporting, debugging). The
|
|
29
|
+
* dispatching blank line is not included.
|
|
30
|
+
*/
|
|
31
|
+
export interface ServerSentEvent {
|
|
32
|
+
event: string | null;
|
|
33
|
+
data: string;
|
|
34
|
+
raw: string[];
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Stream raw Server-Sent Events from an HTTP response body.
|
|
38
|
+
*
|
|
39
|
+
* Yields one `ServerSentEvent` per blank-line dispatch. The consumer is
|
|
40
|
+
* responsible for parsing `data` (e.g. JSON, plain text, error envelope).
|
|
41
|
+
* Use `readSseJson` instead when every event is a single `data:` JSON object
|
|
42
|
+
* and you don't need access to the `event:` field.
|
|
43
|
+
*
|
|
44
|
+
* Internally backed by a Buffer-based line reader (`ConcatSink`) so chunk
|
|
45
|
+
* concatenation is O(n) and never triggers per-line string slicing of the
|
|
46
|
+
* accumulated buffer.
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```ts
|
|
50
|
+
* for await (const sse of readSseEvents(response.body!)) {
|
|
51
|
+
* if (sse.event === "ping") continue;
|
|
52
|
+
* const obj = JSON.parse(sse.data);
|
|
53
|
+
* }
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
export declare function readSseEvents(stream: ReadableStream<Uint8Array>, signal?: AbortSignal): AsyncGenerator<ServerSentEvent>;
|
|
57
|
+
/**
|
|
58
|
+
* Parse a complete JSONL string, skipping malformed lines instead of throwing.
|
|
59
|
+
*
|
|
60
|
+
* Uses `Bun.JSONL.parseChunk` internally. On parse errors, the malformed
|
|
61
|
+
* region is skipped up to the next newline and parsing continues.
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* ```ts
|
|
65
|
+
* const entries = parseJsonlLenient<MyType>(fileContents);
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
export declare function parseJsonlLenient<T>(buffer: string): T[];
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export declare const MIN_TAB_WIDTH = 1;
|
|
2
|
+
export declare const MAX_TAB_WIDTH = 16;
|
|
3
|
+
export declare const DEFAULT_TAB_WIDTH = 3;
|
|
4
|
+
/**
|
|
5
|
+
* `.editorconfig`-derived formatting options for an LSP `textDocument/formatting` request.
|
|
6
|
+
*
|
|
7
|
+
* Both fields are absent when the resolved `.editorconfig` chain does not pin them, so callers
|
|
8
|
+
* can layer their own fallbacks (content sniffing, project defaults) underneath. Returned values
|
|
9
|
+
* are clamped to {@link MIN_TAB_WIDTH}..{@link MAX_TAB_WIDTH}.
|
|
10
|
+
*/
|
|
11
|
+
export interface EditorConfigFormatting {
|
|
12
|
+
/** Effective indent width in columns, from `indent_size` or `tab_width`. */
|
|
13
|
+
tabSize?: number;
|
|
14
|
+
/** `true` for `indent_style = space`, `false` for `indent_style = tab` (or `indent_size = tab`). */
|
|
15
|
+
insertSpaces?: boolean;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Resolve `.editorconfig` formatting hints for `file` without falling back to any default.
|
|
19
|
+
*
|
|
20
|
+
* Used by the LSP format-on-write path so a missing `.editorconfig` declaration falls through
|
|
21
|
+
* to caller-provided defaults instead of clobbering the file with the renderer's
|
|
22
|
+
* display tab width (issue #2329).
|
|
23
|
+
*/
|
|
24
|
+
export declare function getEditorConfigFormatting(file?: string | null, projectDir?: string | null): EditorConfigFormatting;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export declare class TempDir {
|
|
2
|
+
#private;
|
|
3
|
+
private constructor();
|
|
4
|
+
static createSync(prefix?: string): TempDir;
|
|
5
|
+
static create(prefix?: string): Promise<TempDir>;
|
|
6
|
+
path(): string;
|
|
7
|
+
absolute(): string;
|
|
8
|
+
remove(): Promise<void>;
|
|
9
|
+
removeSync(): void;
|
|
10
|
+
toString(): string;
|
|
11
|
+
join(...paths: string[]): string;
|
|
12
|
+
[Symbol.asyncDispose](): Promise<void>;
|
|
13
|
+
[Symbol.dispose](): void;
|
|
14
|
+
}
|
|
15
|
+
/** Removes a path recursively, retrying transient Windows deletion failures. */
|
|
16
|
+
export declare function removeWithRetries(target: string): Promise<void>;
|
|
17
|
+
export declare function removeSyncWithRetries(target: string): void;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared contract between the {@link module-timer} preload and {@link logger}'s
|
|
3
|
+
* timing tree. Kept in its own dependency-free module so the preload can import
|
|
4
|
+
* it without pulling in winston (via logger) and the logger can drain the buffer
|
|
5
|
+
* without importing the Bun-plugin preload.
|
|
6
|
+
*/
|
|
7
|
+
export interface ModuleLoadEvent {
|
|
8
|
+
/** Absolute or Bun-resolved module path. */
|
|
9
|
+
path: string;
|
|
10
|
+
/** `performance.now()` timestamp captured at Bun `onLoad` entry. */
|
|
11
|
+
start: number;
|
|
12
|
+
/** Inclusive module window: `onLoad` entry → appended final marker. */
|
|
13
|
+
durationMs: number;
|
|
14
|
+
/** Own top-level body / TLA time: prepended body marker → appended final marker. */
|
|
15
|
+
bodyMs?: number;
|
|
16
|
+
/** Resolved static children imported by this module. */
|
|
17
|
+
imports: string[];
|
|
18
|
+
}
|
|
19
|
+
/** The append-only buffer the preload pushes into (created on first access). */
|
|
20
|
+
export declare function moduleLoadBuffer(): ModuleLoadEvent[];
|
|
21
|
+
/** Drain and return all buffered events, leaving the buffer empty. */
|
|
22
|
+
export declare function drainModuleLoadEvents(): ModuleLoadEvent[];
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `fetch`-compatible function. Accepts any callable matching the standard
|
|
3
|
+
* fetch signature; `preconnect` is optional because non-Bun runtimes
|
|
4
|
+
* (browsers, test mocks) won't expose it.
|
|
5
|
+
*/
|
|
6
|
+
export type FetchImpl = ((input: string | URL | Request, init?: RequestInit) => Promise<Response>) & {
|
|
7
|
+
preconnect?: typeof globalThis.fetch.preconnect;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* `NODE_EXTRA_CA_CERTS` was set but unusable (path does not exist). This is
|
|
11
|
+
* a config/contract error, not a transient transport fault — it is never
|
|
12
|
+
* retried.
|
|
13
|
+
*/
|
|
14
|
+
export declare class ExtraCaError extends Error {
|
|
15
|
+
constructor(message: string, options?: {
|
|
16
|
+
cause?: unknown;
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
/** Test seam: drop the cached PEM so a follow-up call re-reads the env. */
|
|
20
|
+
export declare function __resetExtraCaCache(): void;
|
|
21
|
+
/**
|
|
22
|
+
* Wrap `fetchImpl` so every call honours `NODE_EXTRA_CA_CERTS`. Idempotent:
|
|
23
|
+
* a fetch already wrapped is returned unchanged so repeated composition
|
|
24
|
+
* (Anthropic auth-retry replays, request-debug fan-out) never stacks
|
|
25
|
+
* wrappers. When the env var is unset the original fetch is returned, so
|
|
26
|
+
* default deployments pay nothing.
|
|
27
|
+
*/
|
|
28
|
+
export declare function wrapFetchForExtraCa(fetchImpl: FetchImpl): FetchImpl;
|
|
29
|
+
/**
|
|
30
|
+
* Convenience for options-bag composition (e.g. the stream-entry path in
|
|
31
|
+
* `@oh-my-pi-zen/pi-ai`'s `stream.ts`, which mirrors `withRequestDebugFetch` so
|
|
32
|
+
* the proxy/debug/extra-CA wrappers compose uniformly). No-op when the env
|
|
33
|
+
* var is unset.
|
|
34
|
+
*/
|
|
35
|
+
export declare function withExtraCaFetch<T extends {
|
|
36
|
+
fetch?: FetchImpl;
|
|
37
|
+
} | undefined>(options: T): T;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { CharRole, AsciiTheme, ColorMode } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Default ASCII theme derived from the SVG renderer's color palette.
|
|
4
|
+
* Uses the same mixing ratios to maintain visual consistency.
|
|
5
|
+
*/
|
|
6
|
+
export declare const DEFAULT_ASCII_THEME: AsciiTheme;
|
|
7
|
+
/**
|
|
8
|
+
* Detect the best color mode for the current environment.
|
|
9
|
+
*
|
|
10
|
+
* Terminal detection order:
|
|
11
|
+
* 1. COLORTERM=truecolor or COLORTERM=24bit → truecolor
|
|
12
|
+
* 2. TERM contains "256color" → ansi256
|
|
13
|
+
* 3. TERM is set and not "dumb" → ansi16
|
|
14
|
+
*
|
|
15
|
+
* Browser: returns 'html' (uses <span> tags with inline styles).
|
|
16
|
+
* Unknown/piped: returns 'none'.
|
|
17
|
+
*/
|
|
18
|
+
export declare function detectColorMode(): ColorMode;
|
|
19
|
+
/**
|
|
20
|
+
* Generate the ANSI escape sequence for a role color.
|
|
21
|
+
*/
|
|
22
|
+
export declare function getAnsiColor(role: CharRole, theme: AsciiTheme, mode: ColorMode): string;
|
|
23
|
+
/**
|
|
24
|
+
* Get the ANSI reset sequence.
|
|
25
|
+
*/
|
|
26
|
+
export declare function getAnsiReset(mode: ColorMode): string;
|
|
27
|
+
/**
|
|
28
|
+
* Wrap a character with ANSI color codes based on its role.
|
|
29
|
+
*/
|
|
30
|
+
export declare function colorizeChar(char: string, role: CharRole | null, theme: AsciiTheme, mode: ColorMode): string;
|
|
31
|
+
/**
|
|
32
|
+
* Colorize an entire line efficiently by grouping consecutive same-role characters.
|
|
33
|
+
* This reduces the number of escape sequences (ANSI) or span tags (HTML) in the output.
|
|
34
|
+
*/
|
|
35
|
+
export declare function colorizeLine(chars: string[], roles: (CharRole | null)[], theme: AsciiTheme, mode: ColorMode): string;
|
|
36
|
+
/**
|
|
37
|
+
* Colorize a text string with a direct hex color.
|
|
38
|
+
* Used by renderers that need per-cell color control (e.g. multi-series xychart).
|
|
39
|
+
* Handles all output modes: ANSI (16/256/truecolor) and HTML.
|
|
40
|
+
*/
|
|
41
|
+
export declare function colorizeText(text: string, hex: string, mode: ColorMode): string;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import type { Canvas, DrawingCoord, RoleCanvas, CharRole, AsciiTheme, ColorMode } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Create a blank canvas filled with spaces.
|
|
4
|
+
* Dimensions are inclusive: mkCanvas(3, 2) creates a 4x3 grid (indices 0..3, 0..2).
|
|
5
|
+
*/
|
|
6
|
+
export declare function mkCanvas(x: number, y: number): Canvas;
|
|
7
|
+
/** Create a blank canvas with the same dimensions as the given canvas. */
|
|
8
|
+
export declare function copyCanvas(source: Canvas): Canvas;
|
|
9
|
+
/**
|
|
10
|
+
* Create a blank role canvas filled with nulls.
|
|
11
|
+
* Same dimensions as mkCanvas — column-major, roleCanvas[x][y].
|
|
12
|
+
*/
|
|
13
|
+
export declare function mkRoleCanvas(x: number, y: number): RoleCanvas;
|
|
14
|
+
/** Create a blank role canvas with the same dimensions as the given role canvas. */
|
|
15
|
+
export declare function copyRoleCanvas(source: RoleCanvas): RoleCanvas;
|
|
16
|
+
/**
|
|
17
|
+
* Grow the role canvas to fit at least (newX, newY), preserving existing roles.
|
|
18
|
+
* Mutates the role canvas in place and returns it.
|
|
19
|
+
*/
|
|
20
|
+
export declare function increaseRoleCanvasSize(roleCanvas: RoleCanvas, newX: number, newY: number): RoleCanvas;
|
|
21
|
+
/**
|
|
22
|
+
* Set a role at a specific coordinate.
|
|
23
|
+
* Expands the role canvas if necessary.
|
|
24
|
+
*/
|
|
25
|
+
export declare function setRole(roleCanvas: RoleCanvas, x: number, y: number, role: CharRole): void;
|
|
26
|
+
/**
|
|
27
|
+
* Merge role canvases — same logic as mergeCanvases but for roles.
|
|
28
|
+
* Non-null roles in overlays overwrite null roles in base.
|
|
29
|
+
*/
|
|
30
|
+
export declare function mergeRoleCanvases(base: RoleCanvas, offset: DrawingCoord, ...overlays: RoleCanvas[]): RoleCanvas;
|
|
31
|
+
/** Returns [maxX, maxY] — the highest valid indices in each dimension. */
|
|
32
|
+
export declare function getCanvasSize(canvas: Canvas): [number, number];
|
|
33
|
+
/**
|
|
34
|
+
* Grow the canvas to fit at least (newX, newY), preserving existing content.
|
|
35
|
+
* Mutates the canvas in place and returns it.
|
|
36
|
+
*/
|
|
37
|
+
export declare function increaseSize(canvas: Canvas, newX: number, newY: number): Canvas;
|
|
38
|
+
export declare function isJunctionChar(c: string): boolean;
|
|
39
|
+
export declare function mergeJunctions(c1: string, c2: string): string;
|
|
40
|
+
/**
|
|
41
|
+
* Merge overlay canvases onto a base canvas at the given offset.
|
|
42
|
+
* Non-space characters in overlays overwrite the base.
|
|
43
|
+
* When both characters are Unicode junction chars, they're merged intelligently.
|
|
44
|
+
*/
|
|
45
|
+
export declare function mergeCanvases(base: Canvas, offset: DrawingCoord, useAscii: boolean, ...overlays: Canvas[]): Canvas;
|
|
46
|
+
/** Options for converting canvas to string with optional coloring. */
|
|
47
|
+
export interface CanvasToStringOptions {
|
|
48
|
+
/** Role canvas for applying colors. If not provided, output is plain text. */
|
|
49
|
+
roleCanvas?: RoleCanvas;
|
|
50
|
+
/** Color mode for terminal output. Default: 'none' */
|
|
51
|
+
colorMode?: ColorMode;
|
|
52
|
+
/** Theme colors for ASCII output. Uses default theme if not provided. */
|
|
53
|
+
theme?: AsciiTheme;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Convert the canvas to a multi-line string (row by row, left to right).
|
|
57
|
+
* Optionally applies ANSI color codes based on character roles.
|
|
58
|
+
*/
|
|
59
|
+
export declare function canvasToString(canvas: Canvas, options?: CanvasToStringOptions): string;
|
|
60
|
+
/**
|
|
61
|
+
* Flip the canvas vertically (mirror across the horizontal center).
|
|
62
|
+
* Reverses row order within each column and remaps directional characters
|
|
63
|
+
* (arrows, corners, junctions) so they point the correct way after flip.
|
|
64
|
+
*
|
|
65
|
+
* Used to transform a TD-rendered canvas into BT output.
|
|
66
|
+
* Mutates the canvas in place and returns it.
|
|
67
|
+
*/
|
|
68
|
+
export declare function flipCanvasVertically(canvas: Canvas): Canvas;
|
|
69
|
+
/**
|
|
70
|
+
* Flip the role canvas vertically to match flipCanvasVertically.
|
|
71
|
+
* Mutates the role canvas in place and returns it.
|
|
72
|
+
*/
|
|
73
|
+
export declare function flipRoleCanvasVertically(roleCanvas: RoleCanvas): RoleCanvas;
|
|
74
|
+
/**
|
|
75
|
+
* Draw text string onto the canvas starting at the given coordinate.
|
|
76
|
+
* By default, preserves existing non-space characters (labels don't overwrite each other).
|
|
77
|
+
* Set forceOverwrite=true to always overwrite (for box content).
|
|
78
|
+
*/
|
|
79
|
+
export declare function drawText(canvas: Canvas, start: DrawingCoord, text: string, forceOverwrite?: boolean): void;
|
|
80
|
+
/**
|
|
81
|
+
* Set the canvas size to fit all grid columns and rows.
|
|
82
|
+
* Called after layout to ensure the canvas covers the full drawing area.
|
|
83
|
+
*/
|
|
84
|
+
export declare function setCanvasSizeToGrid(canvas: Canvas, columnWidth: Map<number, number>, rowHeight: Map<number, number>): void;
|
|
85
|
+
/**
|
|
86
|
+
* Set the role canvas size to match the grid dimensions.
|
|
87
|
+
* Should be called alongside setCanvasSizeToGrid.
|
|
88
|
+
*/
|
|
89
|
+
export declare function setRoleCanvasSizeToGrid(roleCanvas: RoleCanvas, columnWidth: Map<number, number>, rowHeight: Map<number, number>): void;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { AsciiConfig, AsciiTheme, ColorMode } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Render a Mermaid class diagram to ASCII/Unicode text.
|
|
4
|
+
*
|
|
5
|
+
* Pipeline: parse → build boxes → level-based layout → draw boxes → draw relationships → string.
|
|
6
|
+
*/
|
|
7
|
+
export declare function renderClassAscii(text: string, config: AsciiConfig, colorMode?: ColorMode, theme?: AsciiTheme): string;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { MermaidGraph } from '../types';
|
|
2
|
+
import type { AsciiGraph, AsciiConfig } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Convert a parsed MermaidGraph into an AsciiGraph ready for grid layout.
|
|
5
|
+
*
|
|
6
|
+
* Key mappings:
|
|
7
|
+
* - MermaidGraph.nodes (Map) → ordered AsciiNode[] preserving insertion order
|
|
8
|
+
* - MermaidGraph.edges → AsciiEdge[] with resolved node references
|
|
9
|
+
* - MermaidGraph.subgraphs → AsciiSubgraph[] with parent/child tree
|
|
10
|
+
* - Node labels are used as display names (not raw IDs)
|
|
11
|
+
*/
|
|
12
|
+
export declare function convertToAsciiGraph(parsed: MermaidGraph, config: AsciiConfig): AsciiGraph;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import type { Canvas, DrawingCoord, AsciiGraph, AsciiNode, AsciiEdge, AsciiSubgraph, AsciiEdgeStyle } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Draw a node using its shape type.
|
|
4
|
+
* Returns a standalone canvas containing the rendered shape.
|
|
5
|
+
*
|
|
6
|
+
* For basic shapes (rectangle, rounded), uses grid-determined dimensions
|
|
7
|
+
* to ensure consistent sizing across nodes in the same column.
|
|
8
|
+
* For special shapes (diamond, circle, state pseudo-states, etc.),
|
|
9
|
+
* uses shape-specific dimension calculation but centers the content
|
|
10
|
+
* within the grid cell dimensions to ensure proper vertical alignment.
|
|
11
|
+
*/
|
|
12
|
+
export declare function drawNode(node: AsciiNode, graph: AsciiGraph): Canvas;
|
|
13
|
+
/**
|
|
14
|
+
* Draw a node box with centered label text.
|
|
15
|
+
* Returns a standalone canvas containing just the box.
|
|
16
|
+
* Box size is determined by the grid column/row sizes for the node's position.
|
|
17
|
+
*/
|
|
18
|
+
export declare function drawBox(node: AsciiNode, graph: AsciiGraph): Canvas;
|
|
19
|
+
/**
|
|
20
|
+
* Draw a multi-section box with horizontal dividers between sections.
|
|
21
|
+
* Used by class diagrams (header | attributes | methods) and ER diagrams (header | attributes).
|
|
22
|
+
* Each section is an array of text lines to render left-aligned with padding.
|
|
23
|
+
*
|
|
24
|
+
* @param sections - Array of sections, each section is an array of text lines
|
|
25
|
+
* @param useAscii - true for ASCII chars, false for Unicode box-drawing
|
|
26
|
+
* @param padding - horizontal padding inside the box (default 1)
|
|
27
|
+
* @returns A standalone Canvas containing the multi-section box
|
|
28
|
+
*/
|
|
29
|
+
export declare function drawMultiBox(sections: string[][], useAscii: boolean, padding?: number): Canvas;
|
|
30
|
+
/**
|
|
31
|
+
* Draw a line between two drawing coordinates using orthogonal Manhattan routing.
|
|
32
|
+
* Returns the list of coordinates that were drawn on.
|
|
33
|
+
* offsetFrom/offsetTo control how many cells to skip at the start/end.
|
|
34
|
+
*
|
|
35
|
+
* All lines use 90° bends only - no diagonal lines are produced.
|
|
36
|
+
* For diagonal directions, uses horizontal-first routing (draws horizontal
|
|
37
|
+
* segment, then vertical segment).
|
|
38
|
+
*/
|
|
39
|
+
export declare function drawLine(canvas: Canvas, from: DrawingCoord, to: DrawingCoord, offsetFrom: number, offsetTo: number, useAscii: boolean, style?: AsciiEdgeStyle): DrawingCoord[];
|
|
40
|
+
/**
|
|
41
|
+
* Draw a complete arrow (edge) between two nodes.
|
|
42
|
+
* Returns 6 separate canvases for layered compositing:
|
|
43
|
+
* [path, boxStart, arrowHeadEnd, arrowHeadStart, corners, label]
|
|
44
|
+
*
|
|
45
|
+
* Supports bidirectional arrows via edge.hasArrowStart and edge.hasArrowEnd.
|
|
46
|
+
*/
|
|
47
|
+
export declare function drawArrow(graph: AsciiGraph, edge: AsciiEdge): [Canvas, Canvas, Canvas, Canvas, Canvas, Canvas];
|
|
48
|
+
/** Draw a subgraph border rectangle. */
|
|
49
|
+
export declare function drawSubgraphBox(sg: AsciiSubgraph, graph: AsciiGraph): Canvas;
|
|
50
|
+
/** Draw a subgraph label centered in its header area. Supports multi-line labels. */
|
|
51
|
+
export declare function drawSubgraphLabel(sg: AsciiSubgraph, graph: AsciiGraph): [Canvas, DrawingCoord];
|
|
52
|
+
/**
|
|
53
|
+
* Main draw function — renders the entire graph onto the canvas.
|
|
54
|
+
* Drawing order matters for correct layering:
|
|
55
|
+
* 1. Subgraph borders (bottom layer)
|
|
56
|
+
* 2. Node boxes
|
|
57
|
+
* 3. Edge paths (lines)
|
|
58
|
+
* 4. Edge corners
|
|
59
|
+
* 5. Arrowheads
|
|
60
|
+
* 6. Box-start junctions
|
|
61
|
+
* 7. Edge labels
|
|
62
|
+
* 8. Subgraph labels (top layer)
|
|
63
|
+
*
|
|
64
|
+
* Also fills the roleCanvas with character roles for colored output.
|
|
65
|
+
*/
|
|
66
|
+
export declare function drawGraph(graph: AsciiGraph): Canvas;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { AsciiGraph, EdgeBundle, GridCoord } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Analyze graph edges and create bundles for parallel links.
|
|
4
|
+
*
|
|
5
|
+
* Groups edges by:
|
|
6
|
+
* - Fan-in: Multiple edges sharing the same target (A & B --> C)
|
|
7
|
+
* - Fan-out: Multiple edges sharing the same source (A --> B & C)
|
|
8
|
+
*
|
|
9
|
+
* Only creates bundles when:
|
|
10
|
+
* - Graph direction is TD (top-down) - LR routing handles merging naturally
|
|
11
|
+
* - 2+ edges share the endpoint
|
|
12
|
+
* - All edges have the same style (solid/dotted/thick)
|
|
13
|
+
* - None of the edges have labels (labels would overlap at junction)
|
|
14
|
+
* - Edges are not self-loops
|
|
15
|
+
*
|
|
16
|
+
* @returns Array of bundles. Each edge can belong to at most one bundle.
|
|
17
|
+
*/
|
|
18
|
+
export declare function analyzeEdgeBundles(graph: AsciiGraph): EdgeBundle[];
|
|
19
|
+
/**
|
|
20
|
+
* Calculate the optimal junction point for a bundle.
|
|
21
|
+
*
|
|
22
|
+
* For fan-in (A & B --> C):
|
|
23
|
+
* - Junction is placed between the sources and the target
|
|
24
|
+
* - In TD: above the target, horizontally centered between sources
|
|
25
|
+
* - In LR: left of the target, vertically centered between sources
|
|
26
|
+
*
|
|
27
|
+
* For fan-out (A --> B & C):
|
|
28
|
+
* - Junction is placed between the source and the targets
|
|
29
|
+
* - In TD: below the source, horizontally centered between targets
|
|
30
|
+
* - In LR: right of the source, vertically centered between targets
|
|
31
|
+
*/
|
|
32
|
+
export declare function calculateJunctionPoint(graph: AsciiGraph, bundle: EdgeBundle): GridCoord;
|
|
33
|
+
/**
|
|
34
|
+
* Route all edges in a bundle through the junction point.
|
|
35
|
+
*
|
|
36
|
+
* For fan-in bundles:
|
|
37
|
+
* 1. Route each source → junction (stored in edge.pathToJunction)
|
|
38
|
+
* 2. Route junction → target (stored in bundle.sharedPath)
|
|
39
|
+
*
|
|
40
|
+
* For fan-out bundles:
|
|
41
|
+
* 1. Route source → junction (stored in bundle.sharedPath)
|
|
42
|
+
* 2. Route junction → each target (stored in edge.pathToJunction)
|
|
43
|
+
*/
|
|
44
|
+
export declare function routeBundledEdges(graph: AsciiGraph, bundle: EdgeBundle): void;
|
|
45
|
+
/**
|
|
46
|
+
* Process all bundles in a graph: calculate junction points and route edges.
|
|
47
|
+
*/
|
|
48
|
+
export declare function processBundles(graph: AsciiGraph): void;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { Direction, AsciiEdge, AsciiGraph } from './types';
|
|
2
|
+
export declare function getOpposite(d: Direction): Direction;
|
|
3
|
+
/** Compare directions by value (not reference). */
|
|
4
|
+
export declare function dirEquals(a: Direction, b: Direction): boolean;
|
|
5
|
+
/**
|
|
6
|
+
* Determine 8-way direction from one coordinate to another.
|
|
7
|
+
* Uses the coordinate difference to pick one of 8 cardinal/ordinal directions.
|
|
8
|
+
*/
|
|
9
|
+
export declare function determineDirection(from: {
|
|
10
|
+
x: number;
|
|
11
|
+
y: number;
|
|
12
|
+
}, to: {
|
|
13
|
+
x: number;
|
|
14
|
+
y: number;
|
|
15
|
+
}): Direction;
|
|
16
|
+
/**
|
|
17
|
+
* Determine preferred and alternative start/end directions for an edge.
|
|
18
|
+
* Returns [preferredStart, preferredEnd, alternativeStart, alternativeEnd].
|
|
19
|
+
*
|
|
20
|
+
* The edge routing tries both pairs and picks the shorter path.
|
|
21
|
+
* Direction selection depends on relative node positions and graph direction (LR vs TD).
|
|
22
|
+
*/
|
|
23
|
+
export declare function determineStartAndEndDir(edge: AsciiEdge, graphDirection: string): [Direction, Direction, Direction, Direction];
|
|
24
|
+
/**
|
|
25
|
+
* Determine the path for an edge by trying two candidate routes (preferred + alternative)
|
|
26
|
+
* and picking the shorter one. Sets edge.path, edge.startDir, edge.endDir.
|
|
27
|
+
*
|
|
28
|
+
* When both A* paths fail (common for edges crossing subgraph boundaries), falls back
|
|
29
|
+
* to a direct path using the start/end points. This ensures edges always have a path
|
|
30
|
+
* for arrowhead rendering.
|
|
31
|
+
*
|
|
32
|
+
* Uses the effective direction for edge routing, respecting subgraph direction overrides
|
|
33
|
+
* when both source and target are in the same subgraph.
|
|
34
|
+
*/
|
|
35
|
+
export declare function determinePath(graph: AsciiGraph, edge: AsciiEdge): void;
|
|
36
|
+
/**
|
|
37
|
+
* Find the best line segment in an edge's path to place a label on.
|
|
38
|
+
* Prefers vertical segments for TD/BT graphs and horizontal for LR/RL to avoid
|
|
39
|
+
* label collisions when multiple edges share initial segments.
|
|
40
|
+
* Falls back to the widest segment if none are suitable.
|
|
41
|
+
* Also increases the column width at the label position to fit the text.
|
|
42
|
+
*/
|
|
43
|
+
export declare function determineLabelLine(graph: AsciiGraph, edge: AsciiEdge): void;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { AsciiConfig, AsciiTheme, ColorMode } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Render a Mermaid ER diagram to ASCII/Unicode text.
|
|
4
|
+
*
|
|
5
|
+
* Pipeline: parse → build boxes → component-aware layout → draw boxes → draw relationships → string.
|
|
6
|
+
*/
|
|
7
|
+
export declare function renderErAscii(text: string, config: AsciiConfig, colorMode?: ColorMode, theme?: AsciiTheme): string;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { GridCoord, DrawingCoord, Direction, AsciiGraph, AsciiNode, AsciiSubgraph } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Convert a grid coordinate to a drawing (character) coordinate.
|
|
4
|
+
* Sums column widths up to the target column, and row heights up to the target row,
|
|
5
|
+
* then centers within the cell.
|
|
6
|
+
*/
|
|
7
|
+
export declare function gridToDrawingCoord(graph: AsciiGraph, c: GridCoord, dir?: Direction): DrawingCoord;
|
|
8
|
+
/** Convert a path of grid coords to drawing coords. */
|
|
9
|
+
export declare function lineToDrawing(graph: AsciiGraph, line: GridCoord[]): DrawingCoord[];
|
|
10
|
+
/**
|
|
11
|
+
* Reserve a 3x3 block in the grid for a node.
|
|
12
|
+
* If the requested position is occupied, recursively shift by 4 grid units
|
|
13
|
+
* (in the perpendicular direction based on effective direction) until a free spot is found.
|
|
14
|
+
*
|
|
15
|
+
* @param effectiveDir - Optional direction override. If not provided, uses the node's
|
|
16
|
+
* effective direction (subgraph direction if in a subgraph with override,
|
|
17
|
+
* otherwise graph direction).
|
|
18
|
+
*/
|
|
19
|
+
export declare function reserveSpotInGrid(graph: AsciiGraph, node: AsciiNode, requested: GridCoord, effectiveDir?: 'LR' | 'TD'): GridCoord;
|
|
20
|
+
/**
|
|
21
|
+
* Set column widths and row heights for a node's 3x3 grid block.
|
|
22
|
+
* Each node occupies 3 columns (border, content, border) and 3 rows.
|
|
23
|
+
* Uses shape-aware dimensions to properly size non-rectangular shapes.
|
|
24
|
+
*/
|
|
25
|
+
export declare function setColumnWidth(graph: AsciiGraph, node: AsciiNode): void;
|
|
26
|
+
/** Ensure grid has width/height entries for all cells along an edge path. */
|
|
27
|
+
export declare function increaseGridSizeForPath(graph: AsciiGraph, path: GridCoord[]): void;
|
|
28
|
+
/**
|
|
29
|
+
* Get the innermost subgraph that directly contains this node.
|
|
30
|
+
* Returns null if node is not in any subgraph.
|
|
31
|
+
*/
|
|
32
|
+
export declare function getNodeSubgraph(graph: AsciiGraph, node: AsciiNode): AsciiSubgraph | null;
|
|
33
|
+
/**
|
|
34
|
+
* Get the effective direction for a node's layout.
|
|
35
|
+
* Returns the subgraph's direction override if the node is in a subgraph with one,
|
|
36
|
+
* otherwise returns the graph-level direction.
|
|
37
|
+
*/
|
|
38
|
+
export declare function getEffectiveDirection(graph: AsciiGraph, node: AsciiNode): 'LR' | 'TD';
|
|
39
|
+
export declare function calculateSubgraphBoundingBoxes(graph: AsciiGraph): void;
|
|
40
|
+
/**
|
|
41
|
+
* Offset all drawing coordinates so subgraph borders don't go negative.
|
|
42
|
+
* If any subgraph has negative min coordinates, shift everything positive.
|
|
43
|
+
*/
|
|
44
|
+
export declare function offsetDrawingForSubgraphs(graph: AsciiGraph): void;
|
|
45
|
+
/**
|
|
46
|
+
* createMapping performs the full grid layout:
|
|
47
|
+
* 1. Place root nodes on the grid
|
|
48
|
+
* 2. Place child nodes level by level
|
|
49
|
+
* 3. Compute column widths and row heights
|
|
50
|
+
* 4. Run A* pathfinding for all edges
|
|
51
|
+
* 5. Determine label placement
|
|
52
|
+
* 6. Convert grid coords → drawing coords
|
|
53
|
+
* 7. Generate node box drawings
|
|
54
|
+
* 8. Calculate subgraph bounding boxes
|
|
55
|
+
*/
|
|
56
|
+
export declare function createMapping(graph: AsciiGraph): void;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { detectColorMode, DEFAULT_ASCII_THEME } from './ansi';
|
|
2
|
+
import type { AsciiTheme, ColorMode } from './types';
|
|
3
|
+
import type { Direction } from '../types';
|
|
4
|
+
export type { AsciiTheme, ColorMode };
|
|
5
|
+
export { DEFAULT_ASCII_THEME, detectColorMode };
|
|
6
|
+
export interface AsciiRenderOptions {
|
|
7
|
+
/** true = ASCII chars (+,-,|,>), false = Unicode box-drawing (┌,─,│,►). Default: false */
|
|
8
|
+
useAscii?: boolean;
|
|
9
|
+
/** Horizontal spacing between nodes. Default: 5 */
|
|
10
|
+
paddingX?: number;
|
|
11
|
+
/** Vertical spacing between nodes. Default: 5 */
|
|
12
|
+
paddingY?: number;
|
|
13
|
+
/** Padding inside node boxes. Default: 1 */
|
|
14
|
+
boxBorderPadding?: number;
|
|
15
|
+
/**
|
|
16
|
+
* Force the layout direction, overriding the direction parsed from the
|
|
17
|
+
* diagram source. Applies to the flowchart + state-diagram grid pipeline
|
|
18
|
+
* (sequence/class/ER/xychart renderers ignore it). Useful for re-fitting a
|
|
19
|
+
* wide `LR` graph into a narrow viewport by laying it out top-down.
|
|
20
|
+
* Default: undefined (use the source's own direction).
|
|
21
|
+
*/
|
|
22
|
+
direction?: Direction;
|
|
23
|
+
/**
|
|
24
|
+
* Color mode for output.
|
|
25
|
+
* - 'none': No colors (plain text)
|
|
26
|
+
* - 'auto': Auto-detect (terminal ANSI capabilities, or HTML in browsers)
|
|
27
|
+
* - 'ansi16': 16-color ANSI
|
|
28
|
+
* - 'ansi256': 256-color xterm
|
|
29
|
+
* - 'truecolor': 24-bit RGB
|
|
30
|
+
* - 'html': HTML <span> tags with inline color styles (for browser rendering)
|
|
31
|
+
* Default: 'auto'
|
|
32
|
+
*/
|
|
33
|
+
colorMode?: ColorMode | 'auto';
|
|
34
|
+
/** Theme colors for ASCII output. Uses default theme if not provided. */
|
|
35
|
+
theme?: Partial<AsciiTheme>;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Render Mermaid diagram text to an ASCII/Unicode string.
|
|
39
|
+
*
|
|
40
|
+
* Synchronous — no async layout engine needed (unlike the SVG renderer).
|
|
41
|
+
* Auto-detects diagram type from the header line and dispatches to
|
|
42
|
+
* the appropriate renderer.
|
|
43
|
+
*
|
|
44
|
+
* @param text - Mermaid source text (any supported diagram type)
|
|
45
|
+
* @param options - Rendering options
|
|
46
|
+
* @returns Multi-line ASCII/Unicode string
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```ts
|
|
50
|
+
* const result = renderMermaidAscii(`
|
|
51
|
+
* graph LR
|
|
52
|
+
* A --> B --> C
|
|
53
|
+
* `, { useAscii: true })
|
|
54
|
+
*
|
|
55
|
+
* // Output:
|
|
56
|
+
* // +---+ +---+ +---+
|
|
57
|
+
* // | | | | | |
|
|
58
|
+
* // | A |---->| B |---->| C |
|
|
59
|
+
* // | | | | | |
|
|
60
|
+
* // +---+ +---+ +---+
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
export declare function renderMermaidASCII(text: string, options?: AsciiRenderOptions): string;
|
|
64
|
+
/** Lowercase alias kept as the public name used by the pi-utils wrapper. */
|
|
65
|
+
export declare const renderMermaidAscii: typeof renderMermaidASCII;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { Canvas } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Split a label into lines.
|
|
4
|
+
* Labels are already normalized by parsers (br tags → \n).
|
|
5
|
+
*/
|
|
6
|
+
export declare function splitLines(label: string): string[];
|
|
7
|
+
/**
|
|
8
|
+
* Get the maximum line width for sizing calculations.
|
|
9
|
+
* Used to determine column widths for multi-line labels.
|
|
10
|
+
*/
|
|
11
|
+
export declare function maxLineWidth(label: string): number;
|
|
12
|
+
/**
|
|
13
|
+
* Get the number of lines for height calculations.
|
|
14
|
+
* Used to determine row heights for multi-line labels.
|
|
15
|
+
*/
|
|
16
|
+
export declare function lineCount(label: string): number;
|
|
17
|
+
/**
|
|
18
|
+
* Draw multi-line text centered at (cx, cy).
|
|
19
|
+
* Expands vertically from the center point.
|
|
20
|
+
* Each line is horizontally centered independently.
|
|
21
|
+
*/
|
|
22
|
+
export declare function drawMultilineTextCentered(canvas: Canvas, label: string, cx: number, cy: number): void;
|
|
23
|
+
/**
|
|
24
|
+
* Draw multi-line text left-aligned starting at (x, y).
|
|
25
|
+
* Each subsequent line is placed one row below.
|
|
26
|
+
*/
|
|
27
|
+
export declare function drawMultilineTextLeft(canvas: Canvas, label: string, x: number, y: number): void;
|