open-agreements
Version:
Open-source legal template filling CLI and library
85 lines • 4.34 kB
TypeScript
import { deriveTableContext } from './table_context.js';
import { type FormattingMode } from './formatting_tags.js';
import type { RelsMap } from './relationships.js';
import type { BuildDocumentViewOptions, DocumentStyles, DocumentViewNode, TableContext } from './document_view-types.js';
export type { BuildDocumentViewOptions, DocumentViewNode, ListMetadata, TableContext } from './document_view-types.js';
export type { HeaderFormatting, HeadingSource, HeadingValue, HeuristicHeadingSource } from './document_view-headings.js';
export { discoverStyles } from './document_view-styles.js';
export type { DocumentStyleInfo, DocumentStyles, FormattingFingerprint } from './document_view-styles.js';
export { INLINE_COMMENT_MARKER_RUNTIME, TOON_INLINE_TAG_RE, collectInlineCommentMarkers, tokenizeToonInline } from './document_view-comments.js';
export type { DocumentViewComment, DocumentViewCommentRange, ToonCommentMarker, ToonCommentMarkerMap, ToonInlineToken } from './document_view-comments.js';
export { collectTableMarkerInfo, formatTableMarker, formatToonCommentEndnoteLines, formatToonCommentLines, formatToonCommentsEndnotesBlock, formatToonDataLine, renderToon, renderToonWithCommentEndnotes, } from './document_view-toon.js';
/**
* Collect the bookmarked paragraphs of a document, each with its derived table
* context, in document order. This is the shared paragraph-collection core used
* by BOTH `DocxDocument.buildDocumentView()` and the free `buildDocumentView()`
* so the two produce identical node sets.
*
* Only paragraphs carrying a `_bk_*` bookmark id are included (the document view
* addresses nodes by that id). This function does NOT insert bookmarks — a
* consumer operating on un-bookmarked source DOCX MUST call
* `DocxDocument.insertParagraphBookmarks()` first, or the result is empty.
*/
export declare function collectViewParagraphs(documentXml: Document): Array<{
id: string;
p: Element;
tableContext?: ReturnType<typeof deriveTableContext>;
}>;
/**
* Free function form of the document-view builder. Delegates to the same shared
* core (`collectViewParagraphs` + `buildNodesForDocumentView`) as
* `DocxDocument.buildDocumentView()`, so it returns populated nodes — one per
* bookmarked paragraph — rather than the empty stub it used to be.
*
* Like the method, it includes only paragraphs carrying a `_bk_*` bookmark id
* and does NOT insert bookmarks itself.
*/
export declare function buildDocumentView(params: {
documentXml: Document;
stylesXml: Document | null;
numberingXml: Document | null;
footnotesXml?: Document | null;
relsMap?: RelsMap;
opts?: BuildDocumentViewOptions & {
show_formatting?: boolean;
formatting_mode?: FormattingMode;
};
}): {
nodes: DocumentViewNode[];
styles: DocumentStyles;
};
export declare function buildNodesForDocumentView(params: {
paragraphs: Array<{
id: string;
p: Element;
tableContext?: TableContext;
}>;
stylesXml: Document | null;
numberingXml: Document | null;
include_semantic_tags?: boolean;
show_formatting?: boolean;
formatting_mode?: FormattingMode;
relsMap?: RelsMap;
documentXml?: Document;
footnotesXml?: Document | null;
}): {
nodes: DocumentViewNode[];
styles: DocumentStyles;
};
/**
* Build a `clean_text → raw_text` offset map for a node. The returned array has
* length `clean_text.length + 1`: index `o` (a clean-text offset, `0..length`)
* holds the corresponding raw-text offset. A clean span `[cs, ce)` therefore
* maps to the raw span `[map[cs], map[ce])`, ready for `replaceTextAtRange`.
*
* When `node.raw_text` is absent (legacy hand-built fixtures), the map is the
* identity — callers operating on real builder output always have `raw_text`.
*/
export declare function buildCleanToRawOffsetMap(node: Pick<DocumentViewNode, 'clean_text' | 'raw_text'>): number[];
/**
* Translate a single `clean_text` offset to its `raw_text` offset for a node.
* Convenience wrapper over {@link buildCleanToRawOffsetMap}; for translating
* many offsets on one node, build the map once and index it directly.
*/
export declare function cleanToRawOffset(node: Pick<DocumentViewNode, 'clean_text' | 'raw_text'>, cleanOffset: number): number;
//# sourceMappingURL=document_view.d.ts.map