@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': the body's inserted and deleted text become suggestions, suggestInsert / suggestDelete marks { id, author, authorName, time } from w:author and w:date, adjacent revisions of one author and time sharing an id; the host's schema needs the suggest-mode marks. What has no suggestion form takes its accepted state, reported as tracked-accepted: moves, formatting and paragraph-property changes, inserted/deleted table rows and paragraph marks, deleted pictures and breaks, inserted-then-deleted text, revisions outside the body), assets ('inline' data: URLs by default, or 'refs'), convertImage (EMF/WMF/TIFF → a browser format; WMF/EMF it doesn't convert are drawn as SVG by folio-metafile), 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 for hosts without the layer: a group's pictures float at their places in the group, behind or in front of the text as the group does, or in front over an empty line as tall as they reach when the group takes room in the text; shapes are left out; text boxes become their blocks in the flow, so documents full of floating text boxes, such as PDF conversions, come out longer than in Word: keep 'objects' for those), textBoxes ('callout' default, or 'paragraphs', with drawings: 'flatten'), charts (default false; true: Word charts become chart nodes for @nextgensoftwares/folio-plugin-charts, read from the chart part's cached values with their size, alt text and placement, the embedded workbook kept as the node's workbook up to 8 MB), notes (a NoteMapping), lineMetrics, complexScriptFont (face for Arabic/Hebrew/… text whose complex-script font the document leaves unspecified: no w:cs, or a theme reference to an empty typeface; default: the run's Latin face. LibreOffice uses the system default font there, e.g. DejaVu Sans), 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), fonts (the shared importer font policy, see import: per-family font-* warnings and DocxImportResult.fonts.report) |
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 |