@doxi/docx
v0.11.0
Published
Doxiva DOCX (OOXML) exporter and importer — zero runtime deps.
Downloads
43
Maintainers
Readme
@doxi/docx
DOCX (OOXML) export and import for Doxiva. Zero runtime dependencies — hand-written ZIP reader/writer, hand-written OOXML builder, hand-rolled XML parser with a DOMParser fast path.
Status: v0.10.x preview. Round-trips Doxiva-authored DOCX losslessly within the supported schema subset; foreign docs (Word / LibreOffice / Google Docs export) come in best-effort with explicit warnings.
Install
pnpm add @doxi/docx @doxi/coreExport
import { exportDocx } from '@doxi/docx'
const bytes: Uint8Array = exportDocx(doc) // pure function. Deterministic output.
// Save to disk, send to server, trigger a browser download — your call.Pure function: no DOM, no view state, no IO. Deterministic byte output, suitable for golden-file snapshots.
Import
import { importDocx } from '@doxi/docx'
const { doc, warnings } = await importDocx(bytes)
// warnings: ImportWarning[] — surface in your UI
view.dispatch(view.state.tr.replace(0, view.state.doc.content.size, doc))Async because ZIP decompression goes through the platform DecompressionStream (Web Streams). Returns a Doxiva document tree plus structured warnings for anything the importer couldn't handle.
Supported schema subset
Paragraphs (alignment + line height), headings, lists (bullet + numbered, multiple instances), tables (incl. colspan/rowspan + header rows), text with bold/italic/underline/color/font-size/font-family marks, hyperlinks, horizontal rule, forced page break, blockquote.
Self-round-trip guarantee
@doxi/docx ships a property-test harness (fast-check) with 200 runs per arbitrary across 5 arbitraries (1000 runs total). Every generator round-trips through importDocx(exportDocx(doc)) and asserts deep equality against the input.
Honest deferrals
- Images —
word/media/binaries andimage*.xmlrels are read past silently; no image nodes materialize yet. page_varfield codes (PAGE,NUMPAGES) — exported as literal placeholder text; imported as literal text.- Multi-section documents — only the body's first
<w:sectPr>is considered. - Headers / footers from
header*.xml/footer*.xmlparts are not yet wired into the importedpageMeta. - Track changes / comments / footnotes — ignored.
- DEFLATE compression — exports are ~2-3× the size of typical
.docx. Word reads them without complaint.
Security
importDocx rejects <w:hyperlink> targets matching javascript:, vbscript:, and non-image data: URLs. An 'unsafe-content' ImportWarning is emitted so the host UI can surface "1 unsafe link was removed". See docs/security-review.md.
