@nextgensoftwares/folio-docx (import)
Word documents (.docx, .dotx, .docm, .dotm) into Folio documents. DOM-free: runs in the browser, in a worker and in Node. Depends on @nextgensoftwares/folio-import, @nextgensoftwares/folio-model and fflate (MIT). Guide: Import ▸ Word.
Importing
| Export | Description |
|---|---|
docxImporter | the Importer for importFile(src, [docxImporter, ...]): sniffs a ZIP whose central directory has word/ parts, then the extension / MIME type |
importDocx(bytes, opts?) => Promise<DocxImportResult> | the import itself. Throws on non-Word files, on limit violations (DocxLimitError) and on abort (AbortError); everything it can't represent becomes a warning |
looksLikeDocx(bytes) | the magic-byte half of sniff |
DocxImportOptions | ImportOptions (upload, signal, onProgress, limits) plus trackedChanges ('accept' default, 'reject'; 'keep' accepts with a warning), assets ('inline' data: URLs by default, or 'refs'), convertImage (EMF/WMF/TIFF → a browser format), drawings ('objects' default: shapes, text boxes, groups and anchored pictures with crop/rotation/outlines become positioned drawing nodes for @nextgensoftwares/folio-plugin-layers; 'flatten': the older approximation), textBoxes ('callout' default, or 'paragraphs', with drawings: 'flatten'), notes (a NoteMapping), lineMetrics, fontFallbacks (default true: Calibri → Carlito, Times New Roman → Liberation Serif…), availableFonts (report used fonts missing from it), resolveFonts (loads the document's fonts before layout: the styles' families and embedded faces before conversion, then the families runs used; missing families and stand-ins become one warning each), wordLeading (default true: theme.leading: 'below', Word's line positions) |
FontRequest, FontResolution, FontResolver | { used, embedded: { family, weight, style, data }[] } → { missing?, substituted?: { family, with }[] }: what resolveFonts gets and returns (createFontLoader(...) from @nextgensoftwares/folio-fonts fits) |
DocxImportResult | ImportResult plus fonts: { used, embedded } |
EmbeddedFont | { family, weight: 400 | 700, style, ref }: an embedded font, deobfuscated, returned as a font/ttf asset under ref |
DocxLimits, DEFAULT_LIMITS | maxBytes (uncompressed, 400 MB), maxEntries (20,000), maxBlocks (500,000), maxDepth (XML nesting, 256) |
DocxLimitError, AbortError | thrown for limit violations and signal aborts |
ImageConverter, AssetMode | (asset) => Promise<ImportAsset | null>; 'inline' | 'refs' |
LineMetrics | (family) => number: a family's single line height as a multiple of its size (exact values from the host's font files; built-in table otherwise) |
ImportedThread | the comment threads in result.comments (plugin-comments' CommentThread shape: root, replies, resolved, a text anchor with the quoted text) |
docxImportSchema | schema part declaring id on paragraphs/headings (bookmarks and note anchors, targets of #id links). Add it to the editor's schema so internal links survive |
Notes
| Export | Description |
|---|---|
NoteMapping | { reference(note, links) → inline nodes, finish(notes, links) → blocks }: how footnotes and endnotes enter the document |
endnotesMapping(opts?), EndnotesOptions | the default: superscript numbers linking to a "Notes" section at the end (title, heading level), each note linked back |
DocxNote, AnchorLinker | a note (kind, number, refAnchor, noteAnchor, blocks); resolves bookmark-style anchors to #id links |
Workers
| Export | Description |
|---|---|
importDocxInWorker(worker, bytes, opts?) | runs the import in a worker (the bytes are transferred). signal and onProgress cross the boundary; with upload, assets come back as refs and are uploaded on the calling side |
serveDocxImports(scope) | worker side; @nextgensoftwares/folio-docx/worker is a ready-made entry |
DocxWorkerLike, WorkerImportOptions | the postMessage/addEventListener surface used; the options that can cross |
ts
// Vite
import DocxWorker from '@nextgensoftwares/folio-docx/worker?worker';
const result = await importDocxInWorker(new DocxWorker(), bytes, { onProgress, signal });Lower level
| Export | Description |
|---|---|
ommlToLatex(el) | an OMML equation (m:oMath element) as LaTeX: fractions, scripts, radicals, n-ary, delimiters, matrices, cases, accents, bars, functions, limits, group characters, boxes, equation arrays, text |
SaxParser, SaxHandler, XmlLimitError | the incremental, namespace-aware XML parser (no DOM, no DTD, no entity expansion) |
parseXml(text, maxDepth?), XEl, XNode | a small part parsed into a light tree |