Project Files
dist / utils / document.d.ts
import JSZip from "jszip";
export interface DocRun {
text: string;
bold?: boolean;
italic?: boolean;
underline?: boolean;
color?: string;
}
export interface DocParagraph {
index: number;
text: string;
style: string;
runs: DocRun[];
isListItem?: boolean;
listLevel?: number;
}
export interface DocTable {
index: number;
rows: string[][];
}
export interface DocComment {
id: string;
author: string;
date: string;
text: string;
}
export interface DocImage {
id: string;
name: string;
type: string;
sizeKB: number;
}
export interface ContentBlock {
type: "heading" | "paragraph" | "list" | "table" | "pagebreak";
level?: number;
text?: string;
bold?: boolean;
italic?: boolean;
align?: "left" | "center" | "right" | "justify";
items?: string[];
ordered?: boolean;
headers?: string[];
rows?: string[][];
}
export declare function escapeXml(s: string): string;
/**
* Remove ALL <w:sectPr> from XML — handles self-closing and element forms.
* MUST be called on extracted body content before injection into another document.
*/
export declare function stripSectPr(xml: string): string;
/**
* Extract content between <w:body> and </w:body>.
* Uses greedy inner match to capture the full body including nested elements.
*/
export declare function extractBodyContent(xml: string): string;
export interface ParaSpan {
start: number;
end: number;
}
/**
* Tokenize top-level <w:p> elements in body content.
* Skips paragraphs nested inside <w:tbl> or <w:sdt> to avoid corrupting table structure.
*/
export declare function findTopLevelParaSpans(bodyContent: string): ParaSpan[];
/**
* Convert ContentBlock[] → raw OOXML XML.
* No external document round-trips. Safe to inject into any document's <w:body>.
*/
export declare function blocksToXml(blocks: ContentBlock[]): string;
export declare class DocxDocument {
private zip;
private docXml;
constructor(zip: JSZip, docXml: string);
static load(filePath: string): Promise<DocxDocument>;
save(filePath: string): Promise<void>;
getXml(): string;
setXml(xml: string): void;
getZip(): JSZip;
getParagraphs(): DocParagraph[];
getTables(): DocTable[];
/** Find/replace inside <w:t> elements only — never modifies XML structure */
findReplace(find: string, replace: string, opts?: {
regex?: boolean;
caseSensitive?: boolean;
}): number;
getMetadata(): Promise<Record<string, unknown>>;
getComments(): Promise<DocComment[]>;
getImages(): Promise<DocImage[]>;
readVba(): Promise<Record<string, string>>;
}
//# sourceMappingURL=document.d.ts.map