/** * Breakdown rendering with consumer-supplied markers. * * `RollResult.rendered` bakes one markdown dialect into a string. This module * rebuilds the same breakdown from `RollResult.parts`, letting the caller * decide how each die is marked — HTML spans, ANSI codes, Telegram * MarkdownV2, or nothing at all. Import it from `roll-parser/render`. * * @module render */ import type { DieResult, RollResult } from './types.js'; /** * Per-die markers. Every slot is optional; an omitted slot leaves the die's * text untouched, so `{}` renders a breakdown with no markup whatsoever. * * `text` arrives as the die's value already wrapped by any inner mark, and * composition order is fixed: `critical` then `fumble` innermost, then * exactly one of `dropped`, `success`, or `failure` outermost — matching the * priority `RollResult.rendered` uses, where a dropped die is never also * shown as a success. * * @example A die that is both critical and dropped * ```typescript * { critical: (_die, text) => `${text}`, dropped: (_die, text) => `${text}` } * // renders 20 * ``` * * @category Rendering */ export type DieMarks = { /** Excluded from the total by `kh`/`kl`/`dh`/`dl`, a reroll, or group selection. */ dropped?: (die: DieResult, text: string) => string; /** Met a success-count threshold. */ success?: (die: DieResult, text: string) => string; /** Met a failure threshold. */ failure?: (die: DieResult, text: string) => string; /** `DieResult.critical` — the default rule or an explicit `cs` threshold. */ critical?: (die: DieResult, text: string) => string; /** `DieResult.fumble` — the default rule or an explicit `cf` threshold. */ fumble?: (die: DieResult, text: string) => string; /** * Wraps a whole sub-roll dropped by group selection (`{1d8, 1d10}kh1`). * * Inside it, `dropped`, `success`, and `failure` are suppressed — the * wrapper already carries the verdict, and marking a dropped die inside a * dropped sub-roll says nothing extra. `critical` and `fumble` still apply: * they describe the face, not the selection. A nested `droppedGroup` also * survives, so `{{1d6, 1d8}kh1, 1d10}kh1` can wrap twice. */ droppedGroup?: (inner: string) => string; }; /** * The marks `RollResult.rendered` itself uses. Applied when * {@link renderBreakdown} is called without a `marks` argument; spread it to * override one slot while keeping the rest markdown. * * @category Rendering */ export declare const MARKDOWN_MARKS: DieMarks; /** * Rebuilds a roll's breakdown from `RollResult.parts`, applying `marks` to * every die. * * With no `marks` the output is byte-identical to `RollResult.rendered` — a * property test pins that over generated notation. Pass any object to take * over: omitted slots render plain, so `{}` strips markup entirely and * `{ ...MARKDOWN_MARKS, critical: … }` keeps the rest of the markdown. * * The trailing `= ` is included, and becomes the degree label for a * `vs` roll, exactly as `rendered` does. * * @param result - A finished result from `roll` or `evaluate` * @param marks - Per-die markers; defaults to {@link MARKDOWN_MARKS} * @returns The rendered breakdown * * @example * ```typescript * import { roll } from 'roll-parser'; * import { renderBreakdown } from 'roll-parser/render'; * import { createMockRng } from 'roll-parser/testing'; * * const result = roll('4d6kh3', { rng: createMockRng([3, 6, 2, 5]) }); * * renderBreakdown(result); // '4d6[3, 6, ~~2~~, 5] = 14' * renderBreakdown(result, {}); // '4d6[3, 6, 2, 5] = 14' * renderBreakdown(result, { * dropped: (_die, text) => `${text}`, * critical: (_die, text) => `${text}`, * }); // '4d6[3, 6, 2, 5] = 14' * ``` * * @category Rendering */ export declare function renderBreakdown(result: RollResult, marks?: DieMarks): string; //# sourceMappingURL=render.d.ts.map