reamkit 1.15.0 → 1.15.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/core/arc-to-bezier.d.ts +23 -0
- package/dist/esm/core/arc-to-bezier.js +23 -0
- package/dist/esm/core/bidi/algorithm.d.ts +26 -0
- package/dist/esm/core/bidi/algorithm.js +21 -0
- package/dist/esm/core/bidi/char-types.d.ts +17 -0
- package/dist/esm/core/bidi/char-types.js +10 -0
- package/dist/esm/core/bidi/index.d.ts +42 -0
- package/dist/esm/core/bidi/index.js +27 -0
- package/dist/esm/core/bidi/segments.d.ts +22 -0
- package/dist/esm/core/bidi/segments.js +14 -0
- package/dist/esm/core/bytes.d.ts +9 -0
- package/dist/esm/core/bytes.js +9 -0
- package/dist/esm/core/converter/facade.d.ts +38 -1
- package/dist/esm/core/converter/facade.js +25 -0
- package/dist/esm/core/converter/project.d.ts +12 -0
- package/dist/esm/core/converter/project.js +11 -0
- package/dist/esm/core/converter/ream.d.ts +107 -0
- package/dist/esm/core/converter/ream.js +76 -0
- package/dist/esm/core/crypto/asn1.d.ts +77 -0
- package/dist/esm/core/crypto/asn1.js +65 -0
- package/dist/esm/core/crypto/cms.d.ts +25 -0
- package/dist/esm/core/crypto/cms.js +8 -0
- package/dist/esm/core/document-model/index.d.ts +7 -0
- package/dist/esm/core/document-model/types.d.ts +328 -0
- package/dist/esm/core/drawingml/chart-geometry.d.ts +125 -0
- package/dist/esm/core/drawingml/chart-geometry.js +96 -0
- package/dist/esm/core/drawingml/chart-parser.d.ts +34 -0
- package/dist/esm/core/drawingml/chart-parser.js +34 -0
- package/dist/esm/core/drawingml/chart-serializer.d.ts +12 -0
- package/dist/esm/core/drawingml/chart-serializer.js +12 -0
- package/dist/esm/core/drawingml/colors.d.ts +53 -0
- package/dist/esm/core/drawingml/colors.js +41 -0
- package/dist/esm/core/drawingml/preset-geometry.d.ts +30 -0
- package/dist/esm/core/drawingml/preset-geometry.js +30 -0
- package/dist/esm/core/drawingml/shape-render.d.ts +54 -0
- package/dist/esm/core/drawingml/shape-render.js +54 -0
- package/dist/esm/core/drawingml/sparkline-geometry.d.ts +15 -0
- package/dist/esm/core/drawingml/sparkline-geometry.js +13 -0
- package/dist/esm/core/drawingml/theme-parser.d.ts +11 -0
- package/dist/esm/core/drawingml/theme-parser.js +11 -0
- package/dist/esm/core/font/arabic-joining.d.ts +21 -0
- package/dist/esm/core/font/arabic-joining.js +16 -0
- package/dist/esm/core/font/binary-reader.d.ts +17 -0
- package/dist/esm/core/font/binary-reader.js +17 -0
- package/dist/esm/core/font/font-registry.d.ts +37 -0
- package/dist/esm/core/font/font-registry.js +31 -0
- package/dist/esm/core/font/measure.d.ts +20 -0
- package/dist/esm/core/font/measure.js +11 -0
- package/dist/esm/core/font/opentype-layout.d.ts +49 -0
- package/dist/esm/core/font/opentype-layout.js +37 -0
- package/dist/esm/core/font/ttf-parser.d.ts +32 -0
- package/dist/esm/core/font/ttf-parser.js +7 -0
- package/dist/esm/core/font/ttf-subset.d.ts +21 -0
- package/dist/esm/core/font/ttf-subset.js +21 -0
- package/dist/esm/core/fonts/provider.d.ts +8 -1
- package/dist/esm/core/fonts/provider.js +1 -0
- package/dist/esm/core/fonts/remote-fonts.d.ts +22 -0
- package/dist/esm/core/fonts/remote-fonts.js +16 -0
- package/dist/esm/core/hyphenation/index.d.ts +25 -0
- package/dist/esm/core/hyphenation/index.js +17 -0
- package/dist/esm/core/hyphenation/liang.d.ts +27 -0
- package/dist/esm/core/hyphenation/liang.js +14 -0
- package/dist/esm/core/images.d.ts +32 -0
- package/dist/esm/core/images.js +12 -0
- package/dist/esm/core/ir/adapters.d.ts +23 -0
- package/dist/esm/core/ir/features.d.ts +8 -0
- package/dist/esm/core/ir/features.js +1 -0
- package/dist/esm/core/ir/flow.d.ts +20 -0
- package/dist/esm/core/ir/index.d.ts +7 -0
- package/dist/esm/core/ir/loss.d.ts +12 -0
- package/dist/esm/core/ir/loss.js +8 -0
- package/dist/esm/core/ir/resources.d.ts +12 -0
- package/dist/esm/core/ir/resources.js +11 -0
- package/dist/esm/core/ir/sheet.d.ts +81 -0
- package/dist/esm/core/ir/units.d.ts +9 -0
- package/dist/esm/core/ir/units.js +2 -0
- package/dist/esm/core/line-breaker/cjk.d.ts +26 -0
- package/dist/esm/core/line-breaker/cjk.js +60 -0
- package/dist/esm/core/line-breaker/greedy.d.ts +14 -0
- package/dist/esm/core/line-breaker/greedy.js +14 -0
- package/dist/esm/core/line-breaker/index.d.ts +1 -0
- package/dist/esm/core/line-breaker/index.js +3 -0
- package/dist/esm/core/line-breaker/knuth-plass.d.ts +29 -5
- package/dist/esm/core/line-breaker/knuth-plass.js +10 -5
- package/dist/esm/core/numbering/apply.d.ts +19 -0
- package/dist/esm/core/numbering/apply.js +19 -0
- package/dist/esm/core/numbering/state.d.ts +15 -0
- package/dist/esm/core/numbering/state.js +15 -0
- package/dist/esm/core/ole/cfb.d.ts +19 -0
- package/dist/esm/core/ole/cfb.js +50 -4
- package/dist/esm/core/opc/core-properties.d.ts +12 -0
- package/dist/esm/core/opc/core-properties.js +5 -0
- package/dist/esm/core/opc/opc-writer.d.ts +24 -4
- package/dist/esm/core/opc/opc-writer.js +12 -0
- package/dist/esm/core/opc/package.d.ts +55 -0
- package/dist/esm/core/opc/package.js +46 -0
- package/dist/esm/core/opc/relationship-types.d.ts +8 -0
- package/dist/esm/core/opc/relationship-types.js +5 -0
- package/dist/esm/core/opc/relationships.d.ts +12 -0
- package/dist/esm/core/opc/relationships.js +7 -0
- package/dist/esm/core/po-helpers.d.ts +38 -0
- package/dist/esm/core/po-helpers.js +33 -0
- package/dist/esm/core/spreadsheet-model/types.d.ts +281 -0
- package/dist/esm/core/style-cascade/resolver.d.ts +31 -0
- package/dist/esm/core/style-cascade/resolver.js +31 -0
- package/dist/esm/core/style-cascade/table.d.ts +7 -0
- package/dist/esm/core/style-cascade/table.js +7 -0
- package/dist/esm/core/style-cascade/types.d.ts +27 -0
- package/dist/esm/core/style-cascade/types.js +2 -0
- package/dist/esm/core/vector.d.ts +67 -0
- package/dist/esm/core/vector.js +23 -0
- package/dist/esm/excel/activex-parser.d.ts +31 -0
- package/dist/esm/excel/activex-parser.js +24 -0
- package/dist/esm/excel/cell-reference.d.ts +14 -0
- package/dist/esm/excel/cell-reference.js +9 -0
- package/dist/esm/excel/column-bands.d.ts +29 -0
- package/dist/esm/excel/column-bands.js +26 -0
- package/dist/esm/excel/comments-parser.d.ts +19 -0
- package/dist/esm/excel/comments-parser.js +19 -0
- package/dist/esm/excel/conditional-format.d.ts +38 -0
- package/dist/esm/excel/conditional-format.js +25 -0
- package/dist/esm/excel/defined-name-ref.d.ts +21 -0
- package/dist/esm/excel/defined-name-ref.js +20 -0
- package/dist/esm/excel/form-control-parser.d.ts +13 -0
- package/dist/esm/excel/form-control-parser.js +5 -0
- package/dist/esm/excel/formula/context.d.ts +37 -0
- package/dist/esm/excel/formula/dates.d.ts +23 -0
- package/dist/esm/excel/formula/dates.js +20 -0
- package/dist/esm/excel/formula/eval.d.ts +21 -0
- package/dist/esm/excel/formula/eval.js +11 -0
- package/dist/esm/excel/formula/functions.d.ts +12 -0
- package/dist/esm/excel/formula/functions.js +12 -0
- package/dist/esm/excel/formula/index.d.ts +21 -0
- package/dist/esm/excel/formula/index.js +16 -0
- package/dist/esm/excel/formula/lexer.d.ts +12 -0
- package/dist/esm/excel/formula/lexer.js +10 -0
- package/dist/esm/excel/formula/parser.d.ts +20 -0
- package/dist/esm/excel/formula/parser.js +53 -0
- package/dist/esm/excel/formula/value.d.ts +53 -0
- package/dist/esm/excel/formula/value.js +30 -0
- package/dist/esm/excel/header-footer.d.ts +9 -0
- package/dist/esm/excel/header-footer.js +9 -0
- package/dist/esm/excel/number-format.d.ts +34 -0
- package/dist/esm/excel/number-format.js +34 -0
- package/dist/esm/excel/pivot-table-parser.d.ts +8 -0
- package/dist/esm/excel/pivot-table-parser.js +8 -0
- package/dist/esm/excel/print-model.d.ts +56 -0
- package/dist/esm/excel/print-model.js +43 -0
- package/dist/esm/excel/shared-strings-parser.d.ts +13 -0
- package/dist/esm/excel/shared-strings-parser.js +5 -0
- package/dist/esm/excel/sheet-drawing.d.ts +34 -0
- package/dist/esm/excel/sheet-drawing.js +21 -0
- package/dist/esm/excel/sheet-shape-parser.d.ts +12 -0
- package/dist/esm/excel/sheet-shape-parser.js +12 -0
- package/dist/esm/excel/sheet-to-flow.d.ts +19 -0
- package/dist/esm/excel/sheet-to-flow.js +10 -0
- package/dist/esm/excel/slicer-parser.d.ts +23 -0
- package/dist/esm/excel/slicer-parser.js +10 -0
- package/dist/esm/excel/styles-parser.d.ts +8 -0
- package/dist/esm/excel/styles-parser.js +8 -0
- package/dist/esm/excel/table-parser.d.ts +24 -0
- package/dist/esm/excel/table-parser.js +5 -0
- package/dist/esm/excel/workbook-parser.d.ts +17 -0
- package/dist/esm/excel/workbook-parser.js +5 -0
- package/dist/esm/excel/worksheet-parser.d.ts +9 -0
- package/dist/esm/excel/worksheet-parser.js +9 -0
- package/dist/esm/excel/xls/biff-chart.d.ts +10 -0
- package/dist/esm/excel/xls/biff-chart.js +10 -0
- package/dist/esm/excel/xls/biff-reader.d.ts +27 -0
- package/dist/esm/excel/xls/biff-reader.js +44 -0
- package/dist/esm/excel/xls/biff-styles.d.ts +20 -0
- package/dist/esm/excel/xls/biff-styles.js +20 -0
- package/dist/esm/excel/xls/escher.d.ts +27 -0
- package/dist/esm/excel/xls/escher.js +18 -0
- package/dist/esm/excel/xls/xls-reader.d.ts +6 -0
- package/dist/esm/excel/xls/xls-reader.js +6 -0
- package/dist/esm/excel/xlsx-reader.d.ts +26 -0
- package/dist/esm/excel/xlsx-reader.js +26 -0
- package/dist/esm/excel/xlsx-to-pdf.d.ts +27 -0
- package/dist/esm/excel/xlsx-writer.d.ts +14 -0
- package/dist/esm/excel/xlsx-writer.js +13 -0
- package/dist/esm/html/html-writer.d.ts +18 -0
- package/dist/esm/html/html-writer.js +18 -0
- package/dist/esm/index.d.ts +23 -0
- package/dist/esm/layout/math-layout.d.ts +39 -0
- package/dist/esm/layout/math-layout.js +18 -0
- package/dist/esm/layout/page-doc.d.ts +91 -0
- package/dist/esm/layout/styled-layout.d.ts +175 -0
- package/dist/esm/layout/styled-layout.js +117 -2
- package/dist/esm/pdf/builtin-fonts.d.ts +5 -0
- package/dist/esm/pdf/cid-font.d.ts +22 -0
- package/dist/esm/pdf/cid-font.js +10 -0
- package/dist/esm/pdf/embedded-file.d.ts +16 -0
- package/dist/esm/pdf/embedded-file.js +9 -0
- package/dist/esm/pdf/encryption.d.ts +59 -0
- package/dist/esm/pdf/encryption.js +37 -0
- package/dist/esm/pdf/icc-profile.d.ts +8 -0
- package/dist/esm/pdf/icc-profile.js +8 -0
- package/dist/esm/pdf/image-xobject.d.ts +19 -0
- package/dist/esm/pdf/image-xobject.js +9 -0
- package/dist/esm/pdf/objects.d.ts +40 -0
- package/dist/esm/pdf/objects.js +36 -0
- package/dist/esm/pdf/serialize.d.ts +18 -0
- package/dist/esm/pdf/serialize.js +18 -0
- package/dist/esm/pdf/shading.d.ts +16 -0
- package/dist/esm/pdf/shading.js +16 -0
- package/dist/esm/pdf/signature.d.ts +36 -0
- package/dist/esm/pdf/signature.js +22 -0
- package/dist/esm/pdf/struct-tree.d.ts +64 -0
- package/dist/esm/pdf/struct-tree.js +60 -0
- package/dist/esm/pdf/styled-page-emitter.d.ts +33 -0
- package/dist/esm/pdf/styled-page-emitter.js +21 -0
- package/dist/esm/pdf/styled-page-renderer.d.ts +18 -0
- package/dist/esm/pdf/styled-page-renderer.js +18 -0
- package/dist/esm/pdf/text-encoding.d.ts +16 -0
- package/dist/esm/pdf/text-page-renderer.d.ts +11 -0
- package/dist/esm/pdf/vector-graphics.d.ts +12 -0
- package/dist/esm/pdf/vector-graphics.js +12 -0
- package/dist/esm/pdf/writer.d.ts +39 -0
- package/dist/esm/pdf/writer.js +27 -0
- package/dist/esm/pdf/xmp.d.ts +16 -0
- package/dist/esm/pdf/xmp.js +9 -0
- package/dist/esm/pdf-reader/ccitt.d.ts +25 -0
- package/dist/esm/pdf-reader/ccitt.js +15 -0
- package/dist/esm/pdf-reader/cmap.d.ts +12 -0
- package/dist/esm/pdf-reader/cmap.js +9 -0
- package/dist/esm/pdf-reader/content.d.ts +69 -0
- package/dist/esm/pdf-reader/content.js +16 -0
- package/dist/esm/pdf-reader/crypto.d.ts +5 -0
- package/dist/esm/pdf-reader/crypto.js +5 -0
- package/dist/esm/pdf-reader/decrypt.d.ts +17 -0
- package/dist/esm/pdf-reader/decrypt.js +12 -0
- package/dist/esm/pdf-reader/document.d.ts +53 -0
- package/dist/esm/pdf-reader/document.js +50 -0
- package/dist/esm/pdf-reader/flow-build.d.ts +51 -2
- package/dist/esm/pdf-reader/flow-build.js +67 -2
- package/dist/esm/pdf-reader/font.d.ts +12 -0
- package/dist/esm/pdf-reader/font.js +12 -0
- package/dist/esm/pdf-reader/image-decode.d.ts +21 -0
- package/dist/esm/pdf-reader/image-decode.js +14 -0
- package/dist/esm/pdf-reader/images.d.ts +19 -0
- package/dist/esm/pdf-reader/images.js +9 -0
- package/dist/esm/pdf-reader/layout.d.ts +15 -0
- package/dist/esm/pdf-reader/layout.js +17 -2
- package/dist/esm/pdf-reader/lexer.d.ts +43 -0
- package/dist/esm/pdf-reader/lexer.js +38 -0
- package/dist/esm/pdf-reader/parser.d.ts +15 -0
- package/dist/esm/pdf-reader/parser.js +8 -0
- package/dist/esm/pdf-reader/png-encode.d.ts +9 -0
- package/dist/esm/pdf-reader/png-encode.js +8 -0
- package/dist/esm/pdf-reader/predictor.d.ts +9 -0
- package/dist/esm/pdf-reader/predictor.js +8 -0
- package/dist/esm/pdf-reader/reader.d.ts +16 -0
- package/dist/esm/pdf-reader/reader.js +16 -0
- package/dist/esm/pdf-reader/shading.d.ts +10 -0
- package/dist/esm/pdf-reader/shading.js +10 -0
- package/dist/esm/pdf-reader/struct-tree.d.ts +24 -0
- package/dist/esm/pdf-reader/struct-tree.js +12 -0
- package/dist/esm/pdf-reader/tagged.d.ts +13 -0
- package/dist/esm/pdf-reader/tagged.js +15 -2
- package/dist/esm/pdf-reader/text.d.ts +11 -0
- package/dist/esm/pdf-reader/text.js +11 -0
- package/dist/esm/pdf-reader/vector.d.ts +19 -0
- package/dist/esm/pdf-reader/vector.js +9 -0
- package/dist/esm/pptx/placeholder-cascade.d.ts +21 -0
- package/dist/esm/pptx/placeholder-cascade.js +10 -0
- package/dist/esm/pptx/ppt/ppt-reader.d.ts +16 -0
- package/dist/esm/pptx/ppt/ppt-reader.js +16 -0
- package/dist/esm/pptx/ppt/ppt-text.d.ts +55 -0
- package/dist/esm/pptx/ppt/ppt-text.js +14 -0
- package/dist/esm/pptx/pptx-reader.d.ts +21 -0
- package/dist/esm/pptx/pptx-reader.js +37 -1
- package/dist/esm/pptx/slide-parser.d.ts +102 -0
- package/dist/esm/pptx/slide-parser.js +78 -0
- package/dist/esm/pptx/sp-helpers.d.ts +28 -0
- package/dist/esm/pptx/sp-helpers.js +22 -0
- package/dist/esm/svg/svg-writer.d.ts +17 -0
- package/dist/esm/svg/svg-writer.js +16 -0
- package/dist/esm/word/doc/doc-reader.d.ts +16 -0
- package/dist/esm/word/doc/doc-reader.js +26 -4
- package/dist/esm/word/doc/doc-text.d.ts +81 -0
- package/dist/esm/word/doc/doc-text.js +38 -0
- package/dist/esm/word/document-parser.d.ts +134 -0
- package/dist/esm/word/document-parser.js +86 -0
- package/dist/esm/word/docx-reader.d.ts +16 -0
- package/dist/esm/word/docx-reader.js +16 -0
- package/dist/esm/word/docx-to-pdf.d.ts +52 -0
- package/dist/esm/word/docx-to-pdf.js +21 -0
- package/dist/esm/word/docx-writer.d.ts +17 -0
- package/dist/esm/word/docx-writer.js +17 -0
- package/dist/esm/word/drawing-parser.d.ts +88 -0
- package/dist/esm/word/drawing-parser.js +68 -0
- package/dist/esm/word/font-table.d.ts +24 -0
- package/dist/esm/word/font-table.js +24 -0
- package/dist/esm/word/numbering-parser.d.ts +11 -0
- package/dist/esm/word/numbering-parser.js +11 -0
- package/dist/esm/word/omml-parser.d.ts +15 -0
- package/dist/esm/word/omml-parser.js +15 -0
- package/dist/esm/word/omml-serializer.d.ts +9 -0
- package/dist/esm/word/omml-serializer.js +9 -0
- package/dist/esm/word/paragraph-properties.d.ts +10 -0
- package/dist/esm/word/paragraph-properties.js +10 -0
- package/dist/esm/word/po-to-flat.d.ts +11 -0
- package/dist/esm/word/po-to-flat.js +11 -0
- package/dist/esm/word/run-properties.d.ts +10 -0
- package/dist/esm/word/run-properties.js +10 -0
- package/dist/esm/word/settings-parser.d.ts +13 -0
- package/dist/esm/word/settings-parser.js +8 -0
- package/dist/esm/word/styles-parser.d.ts +10 -0
- package/dist/esm/word/styles-parser.js +10 -0
- package/dist/esm/word/table-parser.d.ts +11 -0
- package/dist/esm/word/table-parser.js +11 -0
- package/dist/esm/word/text-extractor.d.ts +9 -0
- package/dist/esm/word/xml-helpers.d.ts +44 -0
- package/dist/esm/word/xml-helpers.js +38 -0
- package/package.json +1 -1
|
@@ -53,6 +53,15 @@ function parseAnchorPos(anchor, tag, allowed) {
|
|
|
53
53
|
...tag === "wp:positionH" && ANCHOR_ALIGNS.has(alignRaw) ? { align: alignRaw } : {}
|
|
54
54
|
};
|
|
55
55
|
}
|
|
56
|
+
/**
|
|
57
|
+
* ECMA-376 Part 3 (Markup Compatibility) — resolve an `<mc:AlternateContent>` to
|
|
58
|
+
* the children of the first `<mc:Choice>` whose `Requires` lists only namespaces
|
|
59
|
+
* we understand, else the `<mc:Fallback>` children, else nothing. (`Requires`
|
|
60
|
+
* holds space-separated namespace prefixes as declared in the document.)
|
|
61
|
+
*
|
|
62
|
+
* @param altContent The `mc:AlternateContent` node.
|
|
63
|
+
* @returns The chosen branch's children.
|
|
64
|
+
*/
|
|
56
65
|
function resolveMc(altContent) {
|
|
57
66
|
for (const choice of poChildren(altContent)) {
|
|
58
67
|
if (!poIs(choice, "mc:Choice")) continue;
|
|
@@ -62,12 +71,32 @@ function resolveMc(altContent) {
|
|
|
62
71
|
const fallback = poChildren(altContent).find((c) => poIs(c, "mc:Fallback"));
|
|
63
72
|
return fallback ? poChildren(fallback) : [];
|
|
64
73
|
}
|
|
74
|
+
/**
|
|
75
|
+
* Flatten a children list, expanding any `<mc:AlternateContent>` to its chosen
|
|
76
|
+
* branch (via {@link resolveMc}) so downstream scanning sees plain elements (a
|
|
77
|
+
* `<w:drawing>`, or the VML we ignore). Used both at run level and inside
|
|
78
|
+
* `a:graphicData`.
|
|
79
|
+
*
|
|
80
|
+
* @param children The raw child list.
|
|
81
|
+
* @returns The flattened children.
|
|
82
|
+
*/
|
|
65
83
|
function expandMcChildren(children) {
|
|
66
84
|
const out = [];
|
|
67
85
|
for (const c of children) if (poIs(c, "mc:AlternateContent")) out.push(...resolveMc(c));
|
|
68
86
|
else out.push(c);
|
|
69
87
|
return out;
|
|
70
88
|
}
|
|
89
|
+
/**
|
|
90
|
+
* Parse a `<w:drawing>` (ECMA-376 Part 1 §20) into a {@link DrawingContent}. The
|
|
91
|
+
* `a:graphicData` `@uri` selects the branch: a `wps:wsp` shape, a chart, a
|
|
92
|
+
* SmartArt diagram, or — falling through — an embedded picture from
|
|
93
|
+
* `a:blip @r:embed`.
|
|
94
|
+
*
|
|
95
|
+
* @param drawing The `w:drawing` node.
|
|
96
|
+
* @param resolveColor Resolver for theme/scheme colours used by shape fills/lines.
|
|
97
|
+
* @param parseBody Optional body parser for a shape's text box (omitted ⇒ no text).
|
|
98
|
+
* @returns The parsed content, or `null` when no anchor / recognizable graphic is found.
|
|
99
|
+
*/
|
|
71
100
|
function parseDrawing(drawing, resolveColor, parseBody) {
|
|
72
101
|
const anchor = poChildren(drawing).find((c) => poIs(c, "wp:inline")) ?? poChildren(drawing).find((c) => poIs(c, "wp:anchor"));
|
|
73
102
|
if (!anchor) return null;
|
|
@@ -128,6 +157,18 @@ function parseDrawing(drawing, resolveColor, parseBody) {
|
|
|
128
157
|
};
|
|
129
158
|
return null;
|
|
130
159
|
}
|
|
160
|
+
/**
|
|
161
|
+
* Parse a legacy `<w:pict>`/`<w:object>` VML picture (ISO/IEC 29500-1 §14, VML
|
|
162
|
+
* transitional) into an `image` {@link DrawingContent}. Modern files use
|
|
163
|
+
* `<w:drawing>` ({@link parseDrawing}); VML still shows up in headers, OLE-object
|
|
164
|
+
* previews (`@o:ole`) and documents last saved by older Word. A VML shape carries
|
|
165
|
+
* an `<v:imagedata r:id>` pointing at the media part and a CSS-like `@style`
|
|
166
|
+
* (`"width:75.6pt;height:49.2pt"`) giving its box; just enough is read to recover
|
|
167
|
+
* the relationship id, the size and the `@alt` text.
|
|
168
|
+
*
|
|
169
|
+
* @param node The `w:pict` / `w:object` node.
|
|
170
|
+
* @returns The picture, or `null` when there is no embedded `v:imagedata` or no usable size.
|
|
171
|
+
*/
|
|
131
172
|
function parseVmlPicture(node) {
|
|
132
173
|
const imagedata = poFindDescendant(node, "v:imagedata");
|
|
133
174
|
if (!imagedata) return null;
|
|
@@ -242,6 +283,11 @@ function parseXfrm(xfrm) {
|
|
|
242
283
|
...flipV ? { flipV: true } : {}
|
|
243
284
|
};
|
|
244
285
|
}
|
|
286
|
+
/**
|
|
287
|
+
* Parse an `a:prstGeom` (§20.1.9.18) into a preset {@link ShapeGeometry}: the
|
|
288
|
+
* `@prst` preset name plus the `a:avLst` adjust values (each `a:gd`'s `val …`
|
|
289
|
+
* formula). Defaults to the `rect` preset when `@prst` is absent.
|
|
290
|
+
*/
|
|
245
291
|
function parsePrstGeom(prst) {
|
|
246
292
|
const preset = poAttr(prst, "prst") ?? "rect";
|
|
247
293
|
const adjust = /* @__PURE__ */ new Map();
|
|
@@ -260,6 +306,13 @@ function parsePrstGeom(prst) {
|
|
|
260
306
|
adjust
|
|
261
307
|
};
|
|
262
308
|
}
|
|
309
|
+
/**
|
|
310
|
+
* Parse an `a:custGeom` (ECMA-376 §20.1.9.11) → its first `<a:path>`
|
|
311
|
+
* (§20.1.9.15) into a custom {@link ShapeGeometry}. Coordinates stay in
|
|
312
|
+
* path-space (the geometry layer scales + y-flips them). Multiple subpaths with
|
|
313
|
+
* differing `w`/`h` are a follow-up; falls back to a `rect` preset when the path
|
|
314
|
+
* is empty or has no usable size.
|
|
315
|
+
*/
|
|
263
316
|
function parseCustGeom(cust) {
|
|
264
317
|
const pathLst = poChildren(cust).find((c) => poIs(c, "a:pathLst"));
|
|
265
318
|
const path = pathLst ? poChildren(pathLst).find((c) => poIs(c, "a:path")) : void 0;
|
|
@@ -355,6 +408,13 @@ function pts(node) {
|
|
|
355
408
|
return out;
|
|
356
409
|
}
|
|
357
410
|
var firstPt = (node) => pts(node)[0];
|
|
411
|
+
/**
|
|
412
|
+
* Parse a shape's fill from its `a:spPr`: the first of `a:noFill`, `a:solidFill`
|
|
413
|
+
* or `a:gradFill` wins. An unresolvable colour degrades to `{ kind: 'none' }`.
|
|
414
|
+
*
|
|
415
|
+
* @param spPr The `wps:spPr` node.
|
|
416
|
+
* @param resolveColor Resolver for theme/scheme colours.
|
|
417
|
+
*/
|
|
358
418
|
function parseFill(spPr, resolveColor) {
|
|
359
419
|
for (const child of poChildren(spPr)) {
|
|
360
420
|
if (poIs(child, "a:noFill")) return { kind: "none" };
|
|
@@ -375,6 +435,14 @@ function parseFill(spPr, resolveColor) {
|
|
|
375
435
|
}
|
|
376
436
|
return { kind: "none" };
|
|
377
437
|
}
|
|
438
|
+
/**
|
|
439
|
+
* Parse a shape's outline (`a:ln`) from its `a:spPr` into a {@link ShapeLine}:
|
|
440
|
+
* width, cap, solid colour, dash pattern, and an explicit `a:noFill` (an unstroked
|
|
441
|
+
* outline). Returns `undefined` when the shape has no `a:ln`.
|
|
442
|
+
*
|
|
443
|
+
* @param spPr The `wps:spPr` node.
|
|
444
|
+
* @param resolveColor Resolver for theme/scheme colours.
|
|
445
|
+
*/
|
|
378
446
|
function parseLine(spPr, resolveColor) {
|
|
379
447
|
const ln = poChildren(spPr).find((c) => poIs(c, "a:ln"));
|
|
380
448
|
if (!ln) return void 0;
|
|
@@ -9,7 +9,31 @@ interface FontTableEntry {
|
|
|
9
9
|
readonly name: string;
|
|
10
10
|
readonly embeds: Partial<Record<EmbedVariant, EmbedRef>>;
|
|
11
11
|
}
|
|
12
|
+
/**
|
|
13
|
+
* §17.8.1 — restore an obfuscated embedded font by XOR-ing its first 32 bytes
|
|
14
|
+
* with the `fontKey` GUID bytes in reverse order, recovering a normal sfnt.
|
|
15
|
+
*
|
|
16
|
+
* @param data The obfuscated `.odttf` bytes.
|
|
17
|
+
* @param fontKey The 16-byte `w:fontKey` GUID (with or without braces/dashes).
|
|
18
|
+
* @returns The de-obfuscated bytes, or `data` unchanged when `fontKey` is not a GUID.
|
|
19
|
+
*/
|
|
12
20
|
export declare function deobfuscateEmbeddedFont(data: Uint8Array, fontKey: string): Uint8Array;
|
|
21
|
+
/**
|
|
22
|
+
* Parse `word/fontTable.xml` for its embedded-font references (§17.8). Returns
|
|
23
|
+
* one `FontTableEntry` per `w:font` that carries at least one `w:embed*` child,
|
|
24
|
+
* each naming the relationship id + `w:fontKey` for a Regular/Bold/Italic/
|
|
25
|
+
* BoldItalic face. A regex pass, not a full XML parse — only the embed refs matter.
|
|
26
|
+
*/
|
|
13
27
|
export declare function parseFontTable(data: Uint8Array): Array<FontTableEntry>;
|
|
28
|
+
/**
|
|
29
|
+
* De-obfuscate and load every embedded font in the package, building one
|
|
30
|
+
* {@link FontRegistry} per font keyed by its normalized (trimmed, lower-cased)
|
|
31
|
+
* name so a run's `w:ascii` can match it. Each candidate face is validated
|
|
32
|
+
* against the sfnt signature; a font lacking a usable Regular face, or whose
|
|
33
|
+
* faces fail to parse, is skipped (the family then falls back to substitution).
|
|
34
|
+
*
|
|
35
|
+
* @param pkg The opened OPC package for the `.docx`.
|
|
36
|
+
* @returns A map from normalized font name to its registry (empty when nothing embeds).
|
|
37
|
+
*/
|
|
14
38
|
export declare function loadEmbeddedFonts(pkg: OpcPackage): Map<string, FontRegistry>;
|
|
15
39
|
export {};
|
|
@@ -8,6 +8,14 @@ var VARIANT_BY_TAG = {
|
|
|
8
8
|
Italic: "italic",
|
|
9
9
|
BoldItalic: "boldItalic"
|
|
10
10
|
};
|
|
11
|
+
/**
|
|
12
|
+
* §17.8.1 — restore an obfuscated embedded font by XOR-ing its first 32 bytes
|
|
13
|
+
* with the `fontKey` GUID bytes in reverse order, recovering a normal sfnt.
|
|
14
|
+
*
|
|
15
|
+
* @param data The obfuscated `.odttf` bytes.
|
|
16
|
+
* @param fontKey The 16-byte `w:fontKey` GUID (with or without braces/dashes).
|
|
17
|
+
* @returns The de-obfuscated bytes, or `data` unchanged when `fontKey` is not a GUID.
|
|
18
|
+
*/
|
|
11
19
|
function deobfuscateEmbeddedFont(data, fontKey) {
|
|
12
20
|
const hex = fontKey.replace(/[{}-]/g, "");
|
|
13
21
|
if (hex.length !== 32) return data;
|
|
@@ -19,6 +27,12 @@ function deobfuscateEmbeddedFont(data, fontKey) {
|
|
|
19
27
|
for (let i = 0; i < n; i++) out[i] = out[i] ^ key[i % 16];
|
|
20
28
|
return out;
|
|
21
29
|
}
|
|
30
|
+
/**
|
|
31
|
+
* Parse `word/fontTable.xml` for its embedded-font references (§17.8). Returns
|
|
32
|
+
* one `FontTableEntry` per `w:font` that carries at least one `w:embed*` child,
|
|
33
|
+
* each naming the relationship id + `w:fontKey` for a Regular/Bold/Italic/
|
|
34
|
+
* BoldItalic face. A regex pass, not a full XML parse — only the embed refs matter.
|
|
35
|
+
*/
|
|
22
36
|
function parseFontTable(data) {
|
|
23
37
|
const xml = new TextDecoder("utf-8").decode(data);
|
|
24
38
|
const out = [];
|
|
@@ -44,6 +58,16 @@ function parseFontTable(data) {
|
|
|
44
58
|
}
|
|
45
59
|
return out;
|
|
46
60
|
}
|
|
61
|
+
/**
|
|
62
|
+
* De-obfuscate and load every embedded font in the package, building one
|
|
63
|
+
* {@link FontRegistry} per font keyed by its normalized (trimmed, lower-cased)
|
|
64
|
+
* name so a run's `w:ascii` can match it. Each candidate face is validated
|
|
65
|
+
* against the sfnt signature; a font lacking a usable Regular face, or whose
|
|
66
|
+
* faces fail to parse, is skipped (the family then falls back to substitution).
|
|
67
|
+
*
|
|
68
|
+
* @param pkg The opened OPC package for the `.docx`.
|
|
69
|
+
* @returns A map from normalized font name to its registry (empty when nothing embeds).
|
|
70
|
+
*/
|
|
47
71
|
function loadEmbeddedFonts(pkg) {
|
|
48
72
|
const out = /* @__PURE__ */ new Map();
|
|
49
73
|
const ftData = pkg.getPart(FONT_TABLE_PART);
|
|
@@ -1,3 +1,14 @@
|
|
|
1
1
|
import { Numbering } from '../core/document-model/index.js';
|
|
2
|
+
/** The empty {@link Numbering} returned when a document has no `numbering.xml`. */
|
|
2
3
|
export declare const EMPTY_NUMBERING: Numbering;
|
|
4
|
+
/**
|
|
5
|
+
* Parse `word/numbering.xml` (ECMA-376 Part 1 §17.9) into a {@link Numbering}:
|
|
6
|
+
* the abstract numbering definitions (each level's format, start, text template
|
|
7
|
+
* and indent/run properties) plus the num instances that bind a `numId` to an
|
|
8
|
+
* `abstractNumId`. `basedOn` inheritance and per-level overrides are not resolved
|
|
9
|
+
* here; an unparseable format defaults to `decimal`.
|
|
10
|
+
*
|
|
11
|
+
* @param data The raw `numbering.xml` bytes.
|
|
12
|
+
* @returns The parsed numbering, or {@link EMPTY_NUMBERING} when the root is absent.
|
|
13
|
+
*/
|
|
3
14
|
export declare function parseNumbering(data: Uint8Array): Numbering;
|
|
@@ -21,10 +21,21 @@ var FORMATS = new Set([
|
|
|
21
21
|
"bullet",
|
|
22
22
|
"none"
|
|
23
23
|
]);
|
|
24
|
+
/** The empty {@link Numbering} returned when a document has no `numbering.xml`. */
|
|
24
25
|
var EMPTY_NUMBERING = {
|
|
25
26
|
abstractNums: /* @__PURE__ */ new Map(),
|
|
26
27
|
numInstances: /* @__PURE__ */ new Map()
|
|
27
28
|
};
|
|
29
|
+
/**
|
|
30
|
+
* Parse `word/numbering.xml` (ECMA-376 Part 1 §17.9) into a {@link Numbering}:
|
|
31
|
+
* the abstract numbering definitions (each level's format, start, text template
|
|
32
|
+
* and indent/run properties) plus the num instances that bind a `numId` to an
|
|
33
|
+
* `abstractNumId`. `basedOn` inheritance and per-level overrides are not resolved
|
|
34
|
+
* here; an unparseable format defaults to `decimal`.
|
|
35
|
+
*
|
|
36
|
+
* @param data The raw `numbering.xml` bytes.
|
|
37
|
+
* @returns The parsed numbering, or {@link EMPTY_NUMBERING} when the root is absent.
|
|
38
|
+
*/
|
|
28
39
|
function parseNumbering(data) {
|
|
29
40
|
const xml = decoder.decode(data);
|
|
30
41
|
const root = asElement(parser.parse(xml)["w:numbering"]);
|
|
@@ -1,4 +1,19 @@
|
|
|
1
1
|
import { MathNode } from '../core/document-model/index.js';
|
|
2
2
|
import { PoNode } from '../core/po-helpers.js';
|
|
3
|
+
/**
|
|
4
|
+
* Parse an `<m:oMath>` subtree (ECMA-376 Part 1 §22) into a recursive
|
|
5
|
+
* {@link MathNode}. Coverage grows by milestone; unrecognized constructs degrade
|
|
6
|
+
* by recursing into their content so any literal symbols still surface.
|
|
7
|
+
*
|
|
8
|
+
* @param oMath The `m:oMath` PoNode.
|
|
9
|
+
* @returns A `row` node wrapping the parsed content.
|
|
10
|
+
*/
|
|
3
11
|
export declare function parseOMath(oMath: PoNode): MathNode;
|
|
12
|
+
/**
|
|
13
|
+
* Collect a named child element's content as a `row` node (`m:num`, `m:den`,
|
|
14
|
+
* `m:e`, …). Returns an empty row when the child is absent.
|
|
15
|
+
*
|
|
16
|
+
* @param parent The enclosing math element.
|
|
17
|
+
* @param tag The child element's qualified tag.
|
|
18
|
+
*/
|
|
4
19
|
export declare function childRow(parent: PoNode, tag: string): MathNode;
|
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
import { poChildren, poChildrenWith, poIs, poTag, poText, poToggle, poVal } from "../core/po-helpers.js";
|
|
2
2
|
//#region src/word/omml-parser.ts
|
|
3
|
+
/**
|
|
4
|
+
* Parse an `<m:oMath>` subtree (ECMA-376 Part 1 §22) into a recursive
|
|
5
|
+
* {@link MathNode}. Coverage grows by milestone; unrecognized constructs degrade
|
|
6
|
+
* by recursing into their content so any literal symbols still surface.
|
|
7
|
+
*
|
|
8
|
+
* @param oMath The `m:oMath` PoNode.
|
|
9
|
+
* @returns A `row` node wrapping the parsed content.
|
|
10
|
+
*/
|
|
3
11
|
function parseOMath(oMath) {
|
|
4
12
|
return {
|
|
5
13
|
type: "row",
|
|
@@ -65,6 +73,13 @@ function parseMathNode(node) {
|
|
|
65
73
|
}
|
|
66
74
|
}
|
|
67
75
|
}
|
|
76
|
+
/**
|
|
77
|
+
* Collect a named child element's content as a `row` node (`m:num`, `m:den`,
|
|
78
|
+
* `m:e`, …). Returns an empty row when the child is absent.
|
|
79
|
+
*
|
|
80
|
+
* @param parent The enclosing math element.
|
|
81
|
+
* @param tag The child element's qualified tag.
|
|
82
|
+
*/
|
|
68
83
|
function childRow(parent, tag) {
|
|
69
84
|
const el = poChildren(parent).find((c) => poIs(c, tag));
|
|
70
85
|
return {
|
|
@@ -1,2 +1,11 @@
|
|
|
1
1
|
import { MathNode } from '../core/document-model/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* Serialize a {@link MathNode} tree to the inner content of an `<m:oMath>`
|
|
4
|
+
* element (ECMA-376 Part 1 §22). The inverse of `parseOMath`; the `m:` namespace
|
|
5
|
+
* is declared by the caller, and the output round-trips back through the parser
|
|
6
|
+
* (WT3).
|
|
7
|
+
*
|
|
8
|
+
* @param node The math tree (typically a `row` node).
|
|
9
|
+
* @returns The serialized OMML markup.
|
|
10
|
+
*/
|
|
2
11
|
export declare function omathXml(node: MathNode): string;
|
|
@@ -1,4 +1,13 @@
|
|
|
1
1
|
//#region src/word/omml-serializer.ts
|
|
2
|
+
/**
|
|
3
|
+
* Serialize a {@link MathNode} tree to the inner content of an `<m:oMath>`
|
|
4
|
+
* element (ECMA-376 Part 1 §22). The inverse of `parseOMath`; the `m:` namespace
|
|
5
|
+
* is declared by the caller, and the output round-trips back through the parser
|
|
6
|
+
* (WT3).
|
|
7
|
+
*
|
|
8
|
+
* @param node The math tree (typically a `row` node).
|
|
9
|
+
* @returns The serialized OMML markup.
|
|
10
|
+
*/
|
|
2
11
|
function omathXml(node) {
|
|
3
12
|
return ser(node);
|
|
4
13
|
}
|
|
@@ -1,2 +1,12 @@
|
|
|
1
1
|
import { ParagraphProperties } from '../core/document-model/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* Parse a `w:pPr` element (ECMA-376 Part 1 §17.3.1) into {@link ParagraphProperties}.
|
|
4
|
+
* Reads the style reference, alignment, spacing, indentation, page-break-before,
|
|
5
|
+
* bidi, outline level, numbering reference (`w:numPr`) and paragraph-mark run
|
|
6
|
+
* properties (`w:rPr`); unrecognized or out-of-range values are skipped.
|
|
7
|
+
*
|
|
8
|
+
* @param pPr The `w:pPr` element in flat (fast-xml-parser) shape, or anything
|
|
9
|
+
* non-element (yielding an empty result).
|
|
10
|
+
* @returns The extracted properties; an empty object when `pPr` is absent.
|
|
11
|
+
*/
|
|
2
12
|
export declare function parseParagraphProperties(pPr: unknown): ParagraphProperties;
|
|
@@ -14,6 +14,16 @@ var LINE_RULES = new Set([
|
|
|
14
14
|
"exact",
|
|
15
15
|
"atLeast"
|
|
16
16
|
]);
|
|
17
|
+
/**
|
|
18
|
+
* Parse a `w:pPr` element (ECMA-376 Part 1 §17.3.1) into {@link ParagraphProperties}.
|
|
19
|
+
* Reads the style reference, alignment, spacing, indentation, page-break-before,
|
|
20
|
+
* bidi, outline level, numbering reference (`w:numPr`) and paragraph-mark run
|
|
21
|
+
* properties (`w:rPr`); unrecognized or out-of-range values are skipped.
|
|
22
|
+
*
|
|
23
|
+
* @param pPr The `w:pPr` element in flat (fast-xml-parser) shape, or anything
|
|
24
|
+
* non-element (yielding an empty result).
|
|
25
|
+
* @returns The extracted properties; an empty object when `pPr` is absent.
|
|
26
|
+
*/
|
|
17
27
|
function parseParagraphProperties(pPr) {
|
|
18
28
|
const el = asElement(pPr);
|
|
19
29
|
if (!el) return {};
|
|
@@ -1,2 +1,13 @@
|
|
|
1
1
|
import { PoNode } from '../core/po-helpers.js';
|
|
2
|
+
/**
|
|
3
|
+
* Convert one `preserveOrder` element ({@link PoNode}) into the flat object shape
|
|
4
|
+
* `fast-xml-parser` produces *without* `preserveOrder`, so the flat-tree property
|
|
5
|
+
* parsers (`run-properties.ts`, `paragraph-properties.ts`) can consume it unchanged.
|
|
6
|
+
*
|
|
7
|
+
* Attributes are flattened to `@_`-prefixed keys, text nodes concatenate into
|
|
8
|
+
* `#text`, and repeated child tags collapse to an array under the tag name.
|
|
9
|
+
*
|
|
10
|
+
* @param node The PO element to flatten; `undefined` yields an empty object.
|
|
11
|
+
* @returns The flat `{ "@_w:val": …, "w:b": {…}, "w:r": [{…}], "#text": "…" }` shape.
|
|
12
|
+
*/
|
|
2
13
|
export declare function poElementToFlat(node: PoNode | undefined): Record<string, unknown>;
|
|
@@ -2,6 +2,17 @@ import { poChildren, poTag } from "../core/po-helpers.js";
|
|
|
2
2
|
//#region src/word/po-to-flat.ts
|
|
3
3
|
var ATTRS_KEY = ":@";
|
|
4
4
|
var TEXT_KEY = "#text";
|
|
5
|
+
/**
|
|
6
|
+
* Convert one `preserveOrder` element ({@link PoNode}) into the flat object shape
|
|
7
|
+
* `fast-xml-parser` produces *without* `preserveOrder`, so the flat-tree property
|
|
8
|
+
* parsers (`run-properties.ts`, `paragraph-properties.ts`) can consume it unchanged.
|
|
9
|
+
*
|
|
10
|
+
* Attributes are flattened to `@_`-prefixed keys, text nodes concatenate into
|
|
11
|
+
* `#text`, and repeated child tags collapse to an array under the tag name.
|
|
12
|
+
*
|
|
13
|
+
* @param node The PO element to flatten; `undefined` yields an empty object.
|
|
14
|
+
* @returns The flat `{ "@_w:val": …, "w:b": {…}, "w:r": [{…}], "#text": "…" }` shape.
|
|
15
|
+
*/
|
|
5
16
|
function poElementToFlat(node) {
|
|
6
17
|
const out = {};
|
|
7
18
|
if (!node) return out;
|
|
@@ -1,2 +1,12 @@
|
|
|
1
1
|
import { RunProperties } from '../core/document-model/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* Parse a run-properties element (`w:rPr`, ECMA-376 Part 1 §17.3.2) into the
|
|
4
|
+
* typed {@link RunProperties}. Reads the character formatting the renderer needs:
|
|
5
|
+
* style reference, bold/italic/strike toggles, underline style, size, colour,
|
|
6
|
+
* font family map, vertical alignment, RTL, and language; sizes convert from
|
|
7
|
+
* half-points to points and colours normalize to uppercase hex.
|
|
8
|
+
*
|
|
9
|
+
* @param rPr The flat-tree `w:rPr` element (or `undefined`/non-element).
|
|
10
|
+
* @returns The parsed properties; an empty object when `rPr` is absent.
|
|
11
|
+
*/
|
|
2
12
|
export declare function parseRunProperties(rPr: unknown): RunProperties;
|
|
@@ -17,6 +17,16 @@ var VERTICAL_ALIGNS = new Set([
|
|
|
17
17
|
"superscript",
|
|
18
18
|
"subscript"
|
|
19
19
|
]);
|
|
20
|
+
/**
|
|
21
|
+
* Parse a run-properties element (`w:rPr`, ECMA-376 Part 1 §17.3.2) into the
|
|
22
|
+
* typed {@link RunProperties}. Reads the character formatting the renderer needs:
|
|
23
|
+
* style reference, bold/italic/strike toggles, underline style, size, colour,
|
|
24
|
+
* font family map, vertical alignment, RTL, and language; sizes convert from
|
|
25
|
+
* half-points to points and colours normalize to uppercase hex.
|
|
26
|
+
*
|
|
27
|
+
* @param rPr The flat-tree `w:rPr` element (or `undefined`/non-element).
|
|
28
|
+
* @returns The parsed properties; an empty object when `rPr` is absent.
|
|
29
|
+
*/
|
|
20
30
|
function parseRunProperties(rPr) {
|
|
21
31
|
const el = asElement(rPr);
|
|
22
32
|
if (!el) return {};
|
|
@@ -1,5 +1,18 @@
|
|
|
1
|
+
/** The handful of `word/settings.xml` flags the renderer consumes. */
|
|
1
2
|
export interface DocumentSettings {
|
|
3
|
+
/**
|
|
4
|
+
* ECMA-376 §17.15.1.36 — `w:evenAndOddHeaders`. When `true`, even-numbered
|
|
5
|
+
* pages use the `'even'` header/footer references instead of `'default'`.
|
|
6
|
+
*/
|
|
2
7
|
readonly evenAndOddHeaders: boolean;
|
|
3
8
|
}
|
|
9
|
+
/** The all-defaults {@link DocumentSettings}, returned when no `w:settings` root is found. */
|
|
4
10
|
export declare const EMPTY_SETTINGS: DocumentSettings;
|
|
11
|
+
/**
|
|
12
|
+
* Parse `word/settings.xml` (ECMA-376 §17.15), extracting only the flags the
|
|
13
|
+
* renderer needs; everything else (compat, autoSpaceDE, …) is ignored.
|
|
14
|
+
*
|
|
15
|
+
* @param data The raw `word/settings.xml` bytes.
|
|
16
|
+
* @returns The extracted {@link DocumentSettings}, or {@link EMPTY_SETTINGS} when the root is absent.
|
|
17
|
+
*/
|
|
5
18
|
export declare function parseSettings(data: Uint8Array): DocumentSettings;
|
|
@@ -10,7 +10,15 @@ var parser = new XMLParser({
|
|
|
10
10
|
parseTagValue: false,
|
|
11
11
|
trimValues: false
|
|
12
12
|
});
|
|
13
|
+
/** The all-defaults {@link DocumentSettings}, returned when no `w:settings` root is found. */
|
|
13
14
|
var EMPTY_SETTINGS = { evenAndOddHeaders: false };
|
|
15
|
+
/**
|
|
16
|
+
* Parse `word/settings.xml` (ECMA-376 §17.15), extracting only the flags the
|
|
17
|
+
* renderer needs; everything else (compat, autoSpaceDE, …) is ignored.
|
|
18
|
+
*
|
|
19
|
+
* @param data The raw `word/settings.xml` bytes.
|
|
20
|
+
* @returns The extracted {@link DocumentSettings}, or {@link EMPTY_SETTINGS} when the root is absent.
|
|
21
|
+
*/
|
|
14
22
|
function parseSettings(data) {
|
|
15
23
|
const xml = decoder.decode(data);
|
|
16
24
|
const settings = poFindByPath(parser.parse(xml), ["w:settings"]);
|
|
@@ -1,2 +1,12 @@
|
|
|
1
1
|
import { StyleSheet } from '../core/document-model/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* Parse `word/styles.xml` (ECMA-376 Part 1 §17.7) into a {@link StyleSheet}: the
|
|
4
|
+
* document defaults (`w:docDefaults` run/paragraph properties) plus the named
|
|
5
|
+
* styles, keyed by `styleId`. Table styles additionally carry their base layer,
|
|
6
|
+
* conditional (`w:tblStylePr`) layers and banding sizes. `basedOn` inheritance is
|
|
7
|
+
* recorded but not resolved — that happens in the style-cascade module.
|
|
8
|
+
*
|
|
9
|
+
* @param stylesXml The raw `styles.xml` bytes.
|
|
10
|
+
* @returns The parsed stylesheet, or `EMPTY_STYLE_SHEET` when the root is absent.
|
|
11
|
+
*/
|
|
2
12
|
export declare function parseStyles(stylesXml: Uint8Array): StyleSheet;
|
|
@@ -21,6 +21,16 @@ var STYLE_TYPES = new Set([
|
|
|
21
21
|
"table",
|
|
22
22
|
"numbering"
|
|
23
23
|
]);
|
|
24
|
+
/**
|
|
25
|
+
* Parse `word/styles.xml` (ECMA-376 Part 1 §17.7) into a {@link StyleSheet}: the
|
|
26
|
+
* document defaults (`w:docDefaults` run/paragraph properties) plus the named
|
|
27
|
+
* styles, keyed by `styleId`. Table styles additionally carry their base layer,
|
|
28
|
+
* conditional (`w:tblStylePr`) layers and banding sizes. `basedOn` inheritance is
|
|
29
|
+
* recorded but not resolved — that happens in the style-cascade module.
|
|
30
|
+
*
|
|
31
|
+
* @param stylesXml The raw `styles.xml` bytes.
|
|
32
|
+
* @returns The parsed stylesheet, or `EMPTY_STYLE_SHEET` when the root is absent.
|
|
33
|
+
*/
|
|
24
34
|
function parseStyles(stylesXml) {
|
|
25
35
|
const xml = decoder.decode(stylesXml);
|
|
26
36
|
const root = asElement(parser.parse(xml)["w:styles"]);
|
|
@@ -1,4 +1,15 @@
|
|
|
1
1
|
import { Table } from '../core/document-model/index.js';
|
|
2
2
|
import { PoNode } from '../core/po-helpers.js';
|
|
3
3
|
import { ParseContext } from './document-parser.js';
|
|
4
|
+
/**
|
|
5
|
+
* Parse a `w:tbl` (ECMA-376 Part 1 §17.4) in preserveOrder shape into the typed
|
|
6
|
+
* {@link Table} model: its properties (style ref, look, width, layout, borders,
|
|
7
|
+
* default cell margins), column grid and rows. Vertical merges are resolved in a
|
|
8
|
+
* second pass so cells carry the resolved {@link CellMerge} role, not the raw
|
|
9
|
+
* `w:vMerge` markers.
|
|
10
|
+
*
|
|
11
|
+
* @param tbl The `w:tbl` PoNode.
|
|
12
|
+
* @param ctx The document-wide parse context (resolvers for colour, images, etc.).
|
|
13
|
+
* @returns The parsed table.
|
|
14
|
+
*/
|
|
4
15
|
export declare function parseTable(tbl: PoNode, ctx?: ParseContext): Table;
|
|
@@ -21,6 +21,17 @@ var HEIGHT_RULES = new Set([
|
|
|
21
21
|
"atLeast",
|
|
22
22
|
"exact"
|
|
23
23
|
]);
|
|
24
|
+
/**
|
|
25
|
+
* Parse a `w:tbl` (ECMA-376 Part 1 §17.4) in preserveOrder shape into the typed
|
|
26
|
+
* {@link Table} model: its properties (style ref, look, width, layout, borders,
|
|
27
|
+
* default cell margins), column grid and rows. Vertical merges are resolved in a
|
|
28
|
+
* second pass so cells carry the resolved {@link CellMerge} role, not the raw
|
|
29
|
+
* `w:vMerge` markers.
|
|
30
|
+
*
|
|
31
|
+
* @param tbl The `w:tbl` PoNode.
|
|
32
|
+
* @param ctx The document-wide parse context (resolvers for colour, images, etc.).
|
|
33
|
+
* @returns The parsed table.
|
|
34
|
+
*/
|
|
24
35
|
function parseTable(tbl, ctx = DEFAULT_PARSE_CONTEXT) {
|
|
25
36
|
const properties = parseTableProperties(poFirstChild(tbl, "w:tblPr"));
|
|
26
37
|
const grid = parseTableGrid(poFirstChild(tbl, "w:tblGrid"));
|
|
@@ -1 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Extract the body paragraphs of a WordprocessingML document as a flat array of
|
|
3
|
+
* plain text — one string per paragraph, runs concatenated. A backwards-compatible
|
|
4
|
+
* convenience over {@link parseDocument} for tests/tools that want only text;
|
|
5
|
+
* table contents and all formatting are dropped.
|
|
6
|
+
*
|
|
7
|
+
* @param documentXml The raw `word/document.xml` bytes.
|
|
8
|
+
* @returns One joined run-text string per body paragraph, in document order.
|
|
9
|
+
*/
|
|
1
10
|
export declare function extractParagraphs(documentXml: Uint8Array): Array<string>;
|
|
@@ -1,9 +1,53 @@
|
|
|
1
|
+
/** The value of a parsed XML attribute (always a string in this flat tree). */
|
|
1
2
|
export type XmlAttrValue = string;
|
|
3
|
+
/** A parsed XML element: attributes (`@_`-prefixed) and child tags keyed by name. */
|
|
2
4
|
export type XmlElement = Record<string, unknown>;
|
|
5
|
+
/**
|
|
6
|
+
* Narrow an arbitrary parsed value to an {@link XmlElement}.
|
|
7
|
+
*
|
|
8
|
+
* @returns The value as an element record, or `undefined` when it is null, a
|
|
9
|
+
* primitive, or an array (i.e. not a single element node).
|
|
10
|
+
*/
|
|
3
11
|
export declare function asElement(v: unknown): XmlElement | undefined;
|
|
12
|
+
/**
|
|
13
|
+
* Coerce a value to an array, treating a lone element as a one-item array.
|
|
14
|
+
* `fast-xml-parser` collapses a single repeated child to a bare object; this
|
|
15
|
+
* normalizes it so callers can always iterate.
|
|
16
|
+
*
|
|
17
|
+
* @returns The value as an array (empty for null/undefined).
|
|
18
|
+
*/
|
|
4
19
|
export declare function asArray(v: unknown): ReadonlyArray<unknown>;
|
|
20
|
+
/**
|
|
21
|
+
* Read a string attribute off an element, trying the `w:`-prefixed name first
|
|
22
|
+
* then the unprefixed fallback (e.g. `@_w:val` then `@_val`).
|
|
23
|
+
*
|
|
24
|
+
* @param node The element to read from.
|
|
25
|
+
* @param name The local attribute name (without the `@_`/`w:` prefix).
|
|
26
|
+
* @returns The attribute value, or `undefined` when the node is not an element
|
|
27
|
+
* or the attribute is absent / non-string.
|
|
28
|
+
*/
|
|
5
29
|
export declare function getAttr(node: unknown, name: string): string | undefined;
|
|
30
|
+
/** Shorthand for {@link getAttr}`(node, 'val')` — the ubiquitous `@w:val` attribute. */
|
|
6
31
|
export declare function getVal(node: unknown): string | undefined;
|
|
32
|
+
/**
|
|
33
|
+
* Read an attribute and parse it as a finite number.
|
|
34
|
+
*
|
|
35
|
+
* @param node The element to read from.
|
|
36
|
+
* @param name The local attribute name.
|
|
37
|
+
* @returns The parsed number, or `undefined` when absent or not finite.
|
|
38
|
+
*/
|
|
7
39
|
export declare function parseIntAttr(node: unknown, name: string): number | undefined;
|
|
40
|
+
/**
|
|
41
|
+
* Parse a toggle (boolean) property per ECMA-376 Part 1 §17.17.4:
|
|
42
|
+
* - Absent → `undefined` (inherit)
|
|
43
|
+
* - Present without `val`, or `val ∈ {true, 1, on}` → `true`
|
|
44
|
+
* - Present with `val ∈ {false, 0, off}` → `false`
|
|
45
|
+
*
|
|
46
|
+
* @returns The toggle state, or `undefined` when the property is absent.
|
|
47
|
+
*/
|
|
8
48
|
export declare function parseToggle(node: unknown): boolean | undefined;
|
|
49
|
+
/**
|
|
50
|
+
* Read the `#text` content of a node. A bare string/number is returned directly;
|
|
51
|
+
* an element returns its `#text` child (coerced to string), else the empty string.
|
|
52
|
+
*/
|
|
9
53
|
export declare function getText(node: unknown): string;
|
|
@@ -1,22 +1,52 @@
|
|
|
1
1
|
//#region src/word/xml-helpers.ts
|
|
2
|
+
/**
|
|
3
|
+
* Narrow an arbitrary parsed value to an {@link XmlElement}.
|
|
4
|
+
*
|
|
5
|
+
* @returns The value as an element record, or `undefined` when it is null, a
|
|
6
|
+
* primitive, or an array (i.e. not a single element node).
|
|
7
|
+
*/
|
|
2
8
|
function asElement(v) {
|
|
3
9
|
if (v === null || v === void 0) return void 0;
|
|
4
10
|
if (typeof v !== "object" || Array.isArray(v)) return void 0;
|
|
5
11
|
return v;
|
|
6
12
|
}
|
|
13
|
+
/**
|
|
14
|
+
* Coerce a value to an array, treating a lone element as a one-item array.
|
|
15
|
+
* `fast-xml-parser` collapses a single repeated child to a bare object; this
|
|
16
|
+
* normalizes it so callers can always iterate.
|
|
17
|
+
*
|
|
18
|
+
* @returns The value as an array (empty for null/undefined).
|
|
19
|
+
*/
|
|
7
20
|
function asArray(v) {
|
|
8
21
|
if (v === null || v === void 0) return [];
|
|
9
22
|
return Array.isArray(v) ? v : [v];
|
|
10
23
|
}
|
|
24
|
+
/**
|
|
25
|
+
* Read a string attribute off an element, trying the `w:`-prefixed name first
|
|
26
|
+
* then the unprefixed fallback (e.g. `@_w:val` then `@_val`).
|
|
27
|
+
*
|
|
28
|
+
* @param node The element to read from.
|
|
29
|
+
* @param name The local attribute name (without the `@_`/`w:` prefix).
|
|
30
|
+
* @returns The attribute value, or `undefined` when the node is not an element
|
|
31
|
+
* or the attribute is absent / non-string.
|
|
32
|
+
*/
|
|
11
33
|
function getAttr(node, name) {
|
|
12
34
|
const el = asElement(node);
|
|
13
35
|
if (!el) return void 0;
|
|
14
36
|
const v = el[`@_w:${name}`] ?? el[`@_${name}`];
|
|
15
37
|
return typeof v === "string" ? v : void 0;
|
|
16
38
|
}
|
|
39
|
+
/** Shorthand for {@link getAttr}`(node, 'val')` — the ubiquitous `@w:val` attribute. */
|
|
17
40
|
function getVal(node) {
|
|
18
41
|
return getAttr(node, "val");
|
|
19
42
|
}
|
|
43
|
+
/**
|
|
44
|
+
* Read an attribute and parse it as a finite number.
|
|
45
|
+
*
|
|
46
|
+
* @param node The element to read from.
|
|
47
|
+
* @param name The local attribute name.
|
|
48
|
+
* @returns The parsed number, or `undefined` when absent or not finite.
|
|
49
|
+
*/
|
|
20
50
|
function parseIntAttr(node, name) {
|
|
21
51
|
const v = getAttr(node, name);
|
|
22
52
|
if (v === void 0) return void 0;
|
|
@@ -24,6 +54,14 @@ function parseIntAttr(node, name) {
|
|
|
24
54
|
if (!Number.isFinite(n)) return void 0;
|
|
25
55
|
return n;
|
|
26
56
|
}
|
|
57
|
+
/**
|
|
58
|
+
* Parse a toggle (boolean) property per ECMA-376 Part 1 §17.17.4:
|
|
59
|
+
* - Absent → `undefined` (inherit)
|
|
60
|
+
* - Present without `val`, or `val ∈ {true, 1, on}` → `true`
|
|
61
|
+
* - Present with `val ∈ {false, 0, off}` → `false`
|
|
62
|
+
*
|
|
63
|
+
* @returns The toggle state, or `undefined` when the property is absent.
|
|
64
|
+
*/
|
|
27
65
|
function parseToggle(node) {
|
|
28
66
|
if (node === void 0) return void 0;
|
|
29
67
|
if (node === null || node === "" || typeof node === "boolean" || typeof node === "number") return true;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "reamkit",
|
|
3
|
-
"version": "1.15.
|
|
3
|
+
"version": "1.15.2",
|
|
4
4
|
"description": "Ream — convert DOCX, XLSX, PPTX and PDF to PDF, SVG, HTML, DOCX and XLSX, built from scratch on the ECMA-376 and ISO 32000 specifications. Parse once, convert anywhere.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Alex Krassavin <info@reamkit.dev>",
|