/** * Resource numbering pipeline (issue #49 §3). * * Assigns a rendered number string (e.g. `"1.7"`) to every resource referenced * in the document. Numbering follows **order of first reference** in reading * order — a resource is numbered the first time it is encountered, whether via * a `::resource{…}` block embed or an inline `:ref{…}`. Inserting a new * reference earlier in the document therefore auto-renumbers the rest. * * The renderer is shared with heading numbering through * {@link renderCounterTemplate}; only the template syntax differs. Resource * templates use `{n}` for the per-type counter and `{h1}`..`{h6}` for the * heading numbers in effect at the point of first reference. Each token * takes the style suffix a heading template's does (`{h1:A}.{n}`, #730). */ import type { ContentBlock } from '../parse/index.js'; import type { DigitSystem, HeadingCounters, Resource, ResourceNumberEntry, ResourceType, ResourceCounterFormat } from '../types.js'; /** Heading counters (1-indexed by level) in effect at a given point in the * document. `h1`..`h6` carry the running heading number for each level. */ export type HeadingContext = HeadingCounters; export type { ResourceNumberEntry }; /** Maps each referenced `Resource.id` to its computed numbering entry. */ export type ResourceNumberingMap = Record; /** Walk `blocks` and produce, for each block index, the heading counters in * effect at that block. A heading at index `i` is reflected in * `result[i]` (i.e. the heading counts itself). Mirrors the counter logic in * `computeHeadingNumbers` but exposes the raw per-level values rather than the * rendered prefix. */ export declare function computeHeadingContext(blocks: ContentBlock[], start?: HeadingContext, /** Whether a heading advances its counter (see `computeHeadingNumbers`). */ isNumbered?: (block: ContentBlock) => boolean): HeadingContext[]; /** * Compute the numbering map for every resource referenced in `blocks`. * * @param blocks parsed content blocks in reading order * @param resourceTypes user-defined resource types (drives template + reset) * @param resources known resources (maps `resourceId → typeId`) * @param headingContext per-block heading counters (see * {@link computeHeadingContext}); must align with * `blocks` by index */ /** Per-type counter state at the end of a document: the `{n}` counter and * the heading counters of the last numbered resource (what `resetOn` * compares against). */ export type ResourceCounterState = Record; /** What precedes the document: resources already numbered (they keep the * number of their first mention) and the per-type counters to continue. */ export interface ResourceNumberingStart { counters?: ResourceCounterState; numbered?: ResourceNumberingMap; } export interface ResourceNumberingResult { /** Every referenced resource — including the inherited ones. */ map: ResourceNumberingMap; /** Counter state at the end of the document, to continue from. */ counters: ResourceCounterState; /** The numbers of the comic strips counted in a resource type's * sequence (`:::strip{type=figure caption=…}`, #590), by the content * index of their block. A strip with an `id` is in `map` under it too, * so a `:ref` names it. */ strips: Record; } export declare function computeResourceNumbering(blocks: ContentBlock[], resourceTypes: ResourceType[], resources: Resource[], headingContext: HeadingContext[], start?: ResourceNumberingStart, /** The document's digit system (`documentNumerals`). */ digits?: DigitSystem, /** The document language (`documentLocale`), for the `一` and `壹` * counter tokens. */ locale?: string): ResourceNumberingMap; /** {@link computeResourceNumbering} plus the counter state at the end of the * document. */ export declare function computeResourceNumberingState(blocks: ContentBlock[], resourceTypes: ResourceType[], resources: Resource[], headingContext: HeadingContext[], start?: ResourceNumberingStart, digits?: DigitSystem, locale?: string): ResourceNumberingResult; /** A number written with a resource-style template (`{n}`, `{h1}`..`{h6}`, * each with an optional style: `{h1:A}.{n}`, #730): what labelled * equations and numbered statements print (#530), and the Sandbox's * preview of a resource type's number. */ export declare function renderTemplateNumber(template: string, counter: number, format: ResourceCounterFormat, heading: HeadingContext, digits?: DigitSystem, locale?: string): string; /** Whether a counter reset at `resetOn` starts again between its last * count (`prev`, none yet: `null`) and `cur` (#530). */ export declare function counterResets(prev: HeadingContext | null, cur: HeadingContext, resetOn: ResourceType['resetOn']): boolean; //# sourceMappingURL=resourceNumbering.d.ts.map