/** * DOCX Module - VBA Project (docm) Round-trip Support * * Provides support for preserving VBA macros during document read/write. * The VBA project binary lives on `DocxDocument.vbaProject` — that's what * `readDocx` populates and `packageDocx` writes back. This module exposes * convenience helpers around that field plus best-effort metadata * extraction. * * Note: This module does NOT execute or compile VBA code. It only * preserves the binary VBA project for round-trip fidelity. */ import type { DocxDocument, OpaquePart } from "../types.js"; /** VBA project metadata extracted from the document. */ export interface VbaProjectInfo { /** Whether a VBA project is present. */ readonly hasVba: boolean; /** Path of the vbaProject.bin in the archive. */ readonly projectPath?: string; /** Content type of the VBA project part. */ readonly contentType?: string; /** Module names detected (best-effort extraction). */ readonly moduleNames?: readonly string[]; /** Size in bytes of the VBA project binary. */ readonly sizeBytes?: number; } /** Content types for macro-enabled documents. */ export declare const DOCM_CONTENT_TYPES: { /** Content type for .docm main document part. */ readonly document: "application/vnd.ms-word.document.macroEnabled.main+xml"; /** Content type for vbaProject.bin. */ readonly vbaProject: "application/vnd.ms-office.vbaProject"; /** Content type for vbaData.xml. */ readonly vbaData: "application/vnd.ms-word.vbaData+xml"; }; /** VBA-related relationship type. */ export declare const VBA_REL_TYPE = "http://schemas.microsoft.com/office/2006/relationships/vbaProject"; /** * Check if a document contains a VBA project (is macro-enabled). * * @param doc - The parsed document. * @returns true if VBA macros are present. */ export declare function hasVbaProject(doc: DocxDocument): boolean; /** * Extract VBA project metadata from a document. * * @param doc - The parsed document. * @returns VBA project info, or info with hasVba=false if not present. */ export declare function getVbaProjectInfo(doc: DocxDocument): VbaProjectInfo; /** * Get the raw VBA project binary data. * * @param doc - The parsed document. * @returns The vbaProject.bin bytes, or undefined if not present. */ export declare function getVbaProjectData(doc: DocxDocument): Uint8Array | undefined; /** * Add a VBA project to a document (making it a .docm). * * The VBA project binary should be a valid OLE2 compound document * containing the VBA modules. The first 8 bytes of an OLE2 file are the * fixed signature `D0 CF 11 E0 A1 B1 1A E1`; we sanity-check that here so * obviously-wrong inputs (e.g. a plain text file) fail eagerly instead of * producing a .docm that Word silently rejects. * * The data is stored in the canonical `DocxDocument.vbaProject` field — * `packageDocx` writes that field directly to `word/vbaProject.bin` and * registers the relationship + content type. Any pre-existing copies in * `opaqueParts` are removed so we don't emit two conflicting parts. * * @param doc - The document to add VBA to. * @param vbaProjectBin - The vbaProject.bin binary data (OLE2 compound). * @returns A new document with the VBA project embedded. */ export declare function addVbaProject(doc: DocxDocument, vbaProjectBin: Uint8Array): DocxDocument; /** * Remove VBA project from a document (converting .docm to .docx behavior). * * @param doc - The macro-enabled document. * @returns A new document without VBA parts. */ export declare function removeVbaProject(doc: DocxDocument): DocxDocument; /** * List all VBA-related parts in the document. Includes the canonical * `vbaProject` field (synthesised as an OpaquePart for ergonomics) plus * any auxiliary VBA parts (e.g. `vbaData.xml`) that survive in * `opaqueParts`. */ export declare function listVbaParts(doc: DocxDocument): readonly OpaquePart[];