import type { ContentBlock } from './parse/index.js'; import type { DigitSystem, OrderedListNumberFormat } from './types.js'; /** The East Asian numeral styles, named as in CSS Counter Styles 3: Chinese * numerals in the informal (一百二十) and formal (壹佰贰拾) longhand of * either script, Japanese counted numerals (`japanese-informal` 百二十, * `japanese-formal` 壱百弐拾), the kana series in gojūon (`hiragana` * あいう, `katakana` アイウ) and iroha order (`hiragana-iroha` いろは, * `katakana-iroha` イロハ), digit by digit (`cjk-decimal`, 二〇二六), the * heavenly stems (甲乙丙) and earthly branches (子丑寅), circled (①) and * fullwidth (123) digits. Every numbering setting takes them. */ export type EastAsianNumeralStyle = 'simp-chinese-informal' | 'trad-chinese-informal' | 'simp-chinese-formal' | 'trad-chinese-formal' | 'japanese-informal' | 'japanese-formal' | 'hiragana' | 'katakana' | 'hiragana-iroha' | 'katakana-iroha' | 'cjk-decimal' | 'cjk-heavenly-stem' | 'cjk-earthly-branch' | 'circled-decimal' | 'fullwidth-decimal'; /** Every {@link EastAsianNumeralStyle}, in the order a picker lists them. */ export declare const EAST_ASIAN_NUMERAL_STYLES: readonly EastAsianNumeralStyle[]; /** The Arabic-script numeral styles: the Arabic-Indic digits of the * Mashriq (`arabic-indic`, ١٢٣) and the Extended Arabic-Indic digits of * Persian and Urdu (`persian`, ۱۲۳), named as in CSS Counter Styles 3; the * additive abjad numerals of Classical Arabic (`arabic-abjad`, يا = 11) * and their Maghrebi values (`arabic-abjad-maghrebi`); and the letter * series of list items, in abjad order (`abjad`: أ ب ج د هـ) and in * alphabetical order (`hijai`: أ ب ت ث). `'arabic'` is not among them: it * has always meant the European decimal digits. */ export type ArabicNumeralStyle = 'arabic-indic' | 'persian' | 'arabic-abjad' | 'arabic-abjad-maghrebi' | 'abjad' | 'hijai'; /** Every {@link ArabicNumeralStyle}, in the order a picker lists them. */ export declare const ARABIC_NUMERAL_STYLES: readonly ArabicNumeralStyle[]; export type NumeralStyle = 'decimal' | 'decimal-02' | 'upper-alpha' | 'lower-alpha' | 'upper-roman' | 'lower-roman' | EastAsianNumeralStyle | ArabicNumeralStyle; type SpelledBase = 'words' | 'Words' | 'WORDS' | 'ordinal' | 'Ordinal' | 'ORDINAL'; /** A counter spelled out in words (heading templates only): cardinal * (`words`) or ordinal (`ordinal`), the case of the suffix picking the * case of the words — `{1:words}` "twenty-one", `{1:Words}` "Twenty-one", * `{1:WORDS}` "TWENTY-ONE". Modifiers after a hyphen choose the gender * and the spelling of a language that inflects them: * `{1:ordinal-feminine}` (or `-f`) الأولى, «prima», « première », * `-masculine` (`-m`, the default) الأول, «primo»; `-neuter` (`-n`) the * German „erstes“ (`-m` „erster“, `-f` „erste“; none, the „erste“ after * the article); `-classical` مائة for مئة (Arabic); * `{1:ordinal-f-classical}` combines them. Other languages ignore the * modifiers. */ export type SpelledNumeralStyle = SpelledBase | `${SpelledBase}-${string}`; /** Format of a counter in a heading numbering template. */ export type CounterStyle = NumeralStyle | SpelledNumeralStyle; type Token = { kind: 'literal'; text: string; } | { kind: 'counter'; level: number; style: CounterStyle; }; /** The numeral styles a format field can name: every {@link NumeralStyle} * but the template-only zero-padded `decimal-02`. */ export type NumberFormatStyle = Exclude; /** The informal Chinese style of a document's script: `trad-chinese-informal` * for a Traditional tag, else `simp-chinese-informal`. What spelled-out * Chinese numbers use. */ export declare function chineseInformalStyle(locale?: string): 'simp-chinese-informal' | 'trad-chinese-informal'; /** The counted kanji numerals of a document's language: `japanese-informal` * for a Japanese tag (百一, ja-typography §9), else the informal Chinese * style of its script (一百零一). What `{1:一}` and the `{numberHan}` * placeholder write. */ export declare function hanInformalStyle(locale?: string): 'japanese-informal' | 'simp-chinese-informal' | 'trad-chinese-informal'; /** * The numeral style a numbering-format value names, in any of the * spellings the engine accepts (see `NUMBER_FORMAT_NAMES`: `decimal` / * `arabic`, `lower-roman` / `roman-lower` / `i`, `upper-alpha` / * `alpha-upper` / `upper-latin` / `A`, the CSS names of the East Asian * styles and their one-character tokens `〇`, `①`, `甲`, `子`, `1`…, the * Japanese tokens `壱`, `あ`, `ア`, `い`, `イ`, the Arabic styles and their * tokens `١`, `۱`, `أبجد`, `أبتث`; names are case-insensitive). `一` names * the counted numerals of the document's language: `japanese-informal` * when `locale` is Japanese, else the informal Chinese of its script. `壹` * names the formal Chinese numerals of the script (Japanese daiji are * `壱`). The script is Traditional when `locale` is (`zh-Hant`, `zh-TW`…), * else Simplified. `undefined` for anything else — the caller numbers in * decimal. */ export declare function parseNumberFormat(value: unknown, locale?: string): NumberFormatStyle | undefined; /** A numeral style in the ordered-list vocabulary (`arabic` for decimal). */ export declare function toOrderedListNumberFormat(style: NumberFormatStyle): OrderedListNumberFormat; /** The style a template token names after its colon (`{1:A}`, `{h1:A}`, * `{n:i}`): the short aliases, any numbering-format name or one-character * token, a spelled style. None, or one the engine does not know, counts * in decimal. Heading templates and resource templates share it (#730). */ export declare function counterStyleOf(raw: string | undefined, locale?: string): CounterStyle; /** Whether `raw` names a style {@link counterStyleOf} knows (rather than * one it counts in decimal for want of another). */ export declare function isCounterStyle(raw: string): boolean; /** A counter value in a template style; spelled-out styles use the * document language `locale`, decimal ones the document's `digits`. */ export declare function formatCounter(n: number, style: CounterStyle, locale?: string, digits?: DigitSystem): string; /** The tokens of a numbering template. `locale` (the document language) * decides the numerals of the `{1:一}` token (Japanese or the Chinese of * its script) and the script of `{1:壹}`. */ export declare function parseTemplate(tpl: string, locale?: string): Token[]; /** * The style a document writes `style` in: `decimal` takes the document's * digit system (`'arab'` → `arabic-indic`, `'arabext'` → `persian`); every * other style, and every style in a `'latn'` document, is kept. What a * page label records as its format, so that the PDF's `/PageLabels` and a * book's next chapter see the digits the page prints. */ export declare function documentNumeralStyle(style: S, digits: DigitSystem | undefined): S | 'arabic-indic' | 'persian'; /** * `n` in `style`. `digits`, the document's digit system, writes the * decimal styles (`decimal`, `decimal-02`) in Arabic-Indic or Persian * digits; a style the author names is printed as named. */ export declare function formatNumeral(n: number, style: NumeralStyle, digits?: DigitSystem): string; /** A pre-resolved template piece fed to {@link renderCounterTemplate}. A * `counter` piece whose `text` is empty is treated as a "missing" counter and * triggers separator collapsing — its adjacent literal separator is dropped so * the rendered string never carries dangling punctuation. */ export type RenderPiece = { kind: 'literal'; text: string; } | { kind: 'counter'; text: string; }; /** Shared template renderer used by both heading and resource numbering. Joins * the pieces in order, dropping a literal separator that sits next to an empty * counter so a missing leading/trailing counter doesn't leave orphan * punctuation (e.g. `{h1}.{n}` with no h1 renders as `1`, not `.1`). */ export declare function renderCounterTemplate(pieces: RenderPiece[]): string; export type HeadingTemplates = Partial>; /** A switch in the page-numbering sequence. At `startPageIndex`, the * (optional) `format` and/or (optional) `startAt` take effect. * A `format`-only segment keeps the counter flowing; a `startAt`-only * segment resets the counter without changing the format. The first * segment (typically pushed from `cfg.page.pageNumbering`) must set both * and have `startPageIndex === 0`. */ export interface PageNumberSegment { startPageIndex: number; format?: NumeralStyle; startAt?: number; } export interface PageLabelInfo { value: number; label: string; format: NumeralStyle; } /** Assign (format, numeric value, rendered label) to every page. * * Segments must be sorted by `startPageIndex`. The first segment is * treated as the document-wide default and must define both `format` * and `startAt`. Later segments with an omitted field carry over the * previous one. */ export declare function buildPageLabels(pageCount: number, segments: PageNumberSegment[], /** The document's digit system: a decimal page is labelled in it, and * records `arabic-indic` or `persian` as its format (see * {@link documentNumeralStyle}). */ digits?: DigitSystem): PageLabelInfo[]; /** One contiguous run of pages sharing `(format, counter)`. Boundary rule: * a run starts whenever the format differs from the previous page or the * counter is not exactly `previous + 1`. Feeds the PDF `/PageLabels` * emitter. `maxValue` is the max `value` seen in the run — used by the * PDF backend to detect the alpha-overflow (`>26`) case. */ export interface PageLabelRun { startPageIndex: number; endPageIndex: number; format: NumeralStyle; startAt: number; maxValue: number; } export declare function collectPageLabelRuns(labels: PageLabelInfo[]): PageLabelRun[]; /** Heading counters carried over from preceding content: `[h1..h6]`. */ export type HeadingCounterStart = readonly number[]; /** The value a heading's `startAt` attribute (`# Appendix {startAt=1}`) * sets its level's counter to, in place of advancing it: a positive * integer, in any digits (`{startAt=٣}`), else undefined (the attribute * is ignored). */ export declare function headingCounterStart(block: Pick): number | undefined; /** A numbered heading's counter after it: its `startAt`, else one more * than the level's running count. */ export declare function nextHeadingCounter(block: Pick, current: number): number; export interface HeadingNumberingOptions { /** Document language of spelled-out counters (`{1:words}`, * `{1:ordinal}`). English when unset. */ locale?: string; /** The document's digit system, for the decimal counters (`{1}`, * `{1:01}`); `'latn'` when unset. */ numerals?: DigitSystem; /** A template replacing the level's for one heading (a heading style's * `numberingTemplate`); `undefined` keeps the level's. */ templateFor?: (block: ContentBlock) => string | undefined; } export interface HeadingNumbering { /** Rendered number prefix per block index; undefined where none. */ prefixes: Array; /** Counter value of each numbered heading (its level's running count) * per block index; undefined for other blocks and unnumbered headings. */ values: Array; } export declare function computeHeadingNumbering(blocks: ContentBlock[], templates: HeadingTemplates, start?: HeadingCounterStart, /** Whether a heading block advances its counter; an unnumbered heading * (a style with `numbered: false`) gets no prefix and counts for nothing. * Every heading is numbered when omitted. */ isNumbered?: (block: ContentBlock) => boolean, options?: HeadingNumberingOptions): HeadingNumbering; /** The rendered number prefix of every heading (see * {@link computeHeadingNumbering}). */ export declare function computeHeadingNumbers(blocks: ContentBlock[], templates: HeadingTemplates, start?: HeadingCounterStart, isNumbered?: (block: ContentBlock) => boolean, options?: HeadingNumberingOptions): Array; export {}; //# sourceMappingURL=numbering.d.ts.map