New

docx-editor 1.x has shipped. Vue support, i18n, agents. Read the migration guide →

API Referencev1.0.2

@eigenpal/docx-editor-core/docx/rezip

DOCX Repacker - Repack modified document into valid DOCX

Takes a Document with modified content and creates a new DOCX file by updating document.xml while preserving all other files from the original ZIP archive.

This ensures round-trip fidelity: - styles.xml, theme1.xml, fontTable.xml remain untouched - Media files preserved - Relationships preserved - Only document.xml is updated with new content

OOXML Package Structure: - [Content_Types].xml - Content type declarations - _rels/.rels - Package relationships - word/document.xml - Main document (modified) - word/styles.xml - Styles (preserved) - word/theme/theme1.xml - Theme (preserved) - word/numbering.xml - Numbering (preserved) - word/fontTable.xml - Font table (preserved) - word/settings.xml - Settings (preserved) - word/header*.xml - Headers (preserved) - word/footer*.xml - Footers (preserved) - word/footnotes.xml - Footnotes (preserved) - word/endnotes.xml - Endnotes (preserved) - word/media/* - Media files (preserved) - word/_rels/document.xml.rels - Document relationships (preserved) - docProps/* - Document properties (preserved)

Orchestrators (repackDocx, selective updates, validation, create-empty) live here. Per-domain helpers — part enumeration, new-image registration, new-hyperlink registration, header/footer & comment packaging, and the empty-DOCX template — live under ./rezip/.

Functions(15)

Add a media file to the DOCX

declare function addMedia(originalBuffer: ArrayBuffer, filename: string, data: ArrayBuffer, mimeType: string): Promise<{
    buffer: ArrayBuffer;
    rId: string;
    path: string;
}>;

Add a new relationship to document.xml.rels

declare function addRelationship(originalBuffer: ArrayBuffer, relationship: {
    type: string;
    target: string;
    targetMode?: 'External' | 'Internal';
}): Promise<{
    buffer: ArrayBuffer;
    rId: string;
}>;

Apply file updates to an already-loaded JSZip instance and generate the output. Use this when the zip is already loaded to avoid a redundant decompression pass.

declare function applyUpdatesToZip(zip: JSZip, updates: Map<string, string | ArrayBuffer>, options?: RepackOptions): Promise<ArrayBuffer>;

Collect serialized header/footer XML updates from the document model. Uses the relationship map to resolve rId → filename.

declare function collectHeaderFooterUpdates(doc: Document): Map<string, string>;

Create a new DOCX from a Document (without requiring original buffer)

declare function createDocx(doc: Document): Promise<ArrayBuffer>;

Create a new empty DOCX file.

declare function createEmptyDocx(): Promise<ArrayBuffer>;

Find the highest rId number in a relationships XML string.

declare function findMaxRId(relsXml: string): number;

Check if buffer looks like a DOCX file (quick check)

declare function isDocxBuffer(buffer: ArrayBuffer): boolean;

Repack a Document into a valid DOCX file

declare function repackDocx(doc: Document, options?: RepackOptions): Promise<ArrayBuffer>;

Repack a Document using raw content for more control

declare function repackDocxFromRaw(doc: Document, rawContent: RawDocxContent, options?: RepackOptions): Promise<ArrayBuffer>;

Update core properties XML with new modification date

declare function updateCoreProperties(corePropsXml: string, options: {
    updateModifiedDate?: boolean;
    modifiedBy?: string;
}): string;

Update only document.xml in a DOCX buffer (minimal changes)

declare function updateDocumentXml(originalBuffer: ArrayBuffer, newDocumentXml: string, options?: RepackOptions): Promise<ArrayBuffer>;
fn

updateMultipleFiles

packages/core/src/core.ts:37

Update multiple files in a DOCX buffer

declare function updateMultipleFiles(originalBuffer: ArrayBuffer, updates: Map<string, string | ArrayBuffer>, options?: RepackOptions): Promise<ArrayBuffer>;

Update a specific XML file in a DOCX buffer

declare function updateXmlFile(originalBuffer: ArrayBuffer, path: string, content: string, options?: RepackOptions): Promise<ArrayBuffer>;

Validate that a buffer is a valid DOCX file

declare function validateDocx(buffer: ArrayBuffer): Promise<{
    valid: boolean;
    errors: string[];
    warnings: string[];
}>;

Interfaces(1)

Options for repacking DOCX

interface RepackOptions
MemberTypeSummary
compressionLevel?numberCompression level (0-9, default: 6)
modifiedBy?stringCustom modifier name for lastModifiedBy
updateModifiedDate?booleanWhether to update modification date in docProps/core.xml

Variables(4)

Header/Footer & Comment Packaging

Serialize modified headers, footers, and comments back into the ZIP and ensure each new part is registered in `[Content_Types].xml` and the document's rels file. Without this step Word silently drops parts that the editor inserted into a previously-blank document (#274).

COMMENTS_CONTENT_TYPE = "application/vnd.openxmlformats-officedocument.wordprocessingml.comments+xml"
const

COMMENTS_EXTENDED_CONTENT_TYPE

packages/core/src/docx/rezip/packaging.ts:32
COMMENTS_EXTENDED_CONTENT_TYPE = "application/vnd.openxmlformats-officedocument.wordprocessingml.commentsExtended+xml"
const

COMMENTS_EXTENSIBLE_CONTENT_TYPE

packages/core/src/docx/rezip/packaging.ts:38
COMMENTS_EXTENSIBLE_CONTENT_TYPE = "application/vnd.openxmlformats-officedocument.wordprocessingml.commentsExtensible+xml"
COMMENTS_IDS_CONTENT_TYPE = "application/vnd.openxmlformats-officedocument.wordprocessingml.commentsIds+xml"