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
|
@@ -21,6 +21,17 @@ var RECT_GEOMETRY = {
|
|
|
21
21
|
adjust: /* @__PURE__ */ new Map()
|
|
22
22
|
};
|
|
23
23
|
var IDENTITY_TRANSFORM = (box) => box;
|
|
24
|
+
/**
|
|
25
|
+
* Walk a shape container (`p:spTree` or a `p:grpSp`), turning each `p:sp` into a
|
|
26
|
+
* floating text/graphic shape, each `p:pic` into a floating image, each
|
|
27
|
+
* `p:graphicFrame` into a chart/table, and recursing into nested `p:grpSp` groups
|
|
28
|
+
* (composing their transforms).
|
|
29
|
+
*
|
|
30
|
+
* @param container The shape container node.
|
|
31
|
+
* @param ctx The per-slide parsing context.
|
|
32
|
+
* @param transform Maps child-space boxes to the slide (identity at the top level).
|
|
33
|
+
* @returns The container's shapes as positioned {@link BodyElement}s.
|
|
34
|
+
*/
|
|
24
35
|
function parseSlideShapes(container, ctx = {}, transform = IDENTITY_TRANSFORM) {
|
|
25
36
|
const out = [];
|
|
26
37
|
for (const child of poChildren(container)) if (poIs(child, "p:sp")) {
|
|
@@ -148,6 +159,16 @@ function parseGraphicFrame(gf, ctx, transform) {
|
|
|
148
159
|
}
|
|
149
160
|
return [];
|
|
150
161
|
}
|
|
162
|
+
/**
|
|
163
|
+
* The diagram's child shapes live in the spTree's own coordinate space
|
|
164
|
+
* (`dsp:grpSpPr/a:xfrm` `chOff`/`chExt`); map that onto a target box (the frame on
|
|
165
|
+
* a slide, or the inline/anchored box in docx). Usually the child space equals
|
|
166
|
+
* the box, so the scale is 1. Shared by pptx and docx (E-SMARTART).
|
|
167
|
+
*
|
|
168
|
+
* @param spTree The diagram drawing's `dsp:spTree`.
|
|
169
|
+
* @param frame The target box the diagram is placed into.
|
|
170
|
+
* @returns A transform mapping diagram-space boxes onto `frame`.
|
|
171
|
+
*/
|
|
151
172
|
function diagramTransform(spTree, frame) {
|
|
152
173
|
const grpSpPr = poChildren(spTree).find((c) => poIs(c, "dsp:grpSpPr"));
|
|
153
174
|
const xfrm = grpSpPr ? poChildren(grpSpPr).find((c) => poIs(c, "a:xfrm")) : void 0;
|
|
@@ -166,6 +187,16 @@ function diagramTransform(spTree, frame) {
|
|
|
166
187
|
cy: b.cy * sy
|
|
167
188
|
});
|
|
168
189
|
}
|
|
190
|
+
/**
|
|
191
|
+
* A {@link Loss} for a SmartArt diagram that declares its data part but ships no
|
|
192
|
+
* pre-rendered drawing override (older files, or a generator that omitted the
|
|
193
|
+
* fallback). Ream renders the override rather than executing Office's layout
|
|
194
|
+
* engine, so without it the diagram can't be drawn — this records the gap as a
|
|
195
|
+
* dropped feature instead of letting it vanish. Shared by pptx and docx
|
|
196
|
+
* (E-SMARTART SA3).
|
|
197
|
+
*
|
|
198
|
+
* @param where Optional location tag for the loss report (e.g. `slide 3`).
|
|
199
|
+
*/
|
|
169
200
|
function noDiagramOverrideLoss(where) {
|
|
170
201
|
return {
|
|
171
202
|
severity: "dropped",
|
|
@@ -174,6 +205,20 @@ function noDiagramOverrideLoss(where) {
|
|
|
174
205
|
...where ? { where } : {}
|
|
175
206
|
};
|
|
176
207
|
}
|
|
208
|
+
/**
|
|
209
|
+
* Render a SmartArt drawing override (a `dsp:spTree`) into floating shapes. The
|
|
210
|
+
* `dsp:` wrapper holds an ordinary `a:` `spPr`/`txBody`, so the shared DrawingML
|
|
211
|
+
* readers apply unchanged. Shared by pptx and docx (E-SMARTART); diagrams carry
|
|
212
|
+
* no placeholder cascade.
|
|
213
|
+
*
|
|
214
|
+
* @param spTree The diagram drawing's `dsp:spTree`.
|
|
215
|
+
* @param transform Maps each shape's diagram-space box to the target space.
|
|
216
|
+
* @param makeFloat Anchors a box — page-relative for a slide, column/paragraph-
|
|
217
|
+
* relative for an inline docx diagram.
|
|
218
|
+
* @param colors The colour resolver for the shapes' fills/strokes/text.
|
|
219
|
+
* @param resolveLink A run hyperlink resolver, or `undefined`.
|
|
220
|
+
* @returns The diagram's visible shapes as positioned {@link ShapeBlock}s.
|
|
221
|
+
*/
|
|
177
222
|
function parseDiagramDrawing(spTree, transform, makeFloat, colors, resolveLink) {
|
|
178
223
|
const out = [];
|
|
179
224
|
for (const sp of poChildren(spTree)) {
|
|
@@ -202,6 +247,13 @@ function parseDiagramDrawing(spTree, transform, makeFloat, colors, resolveLink)
|
|
|
202
247
|
}
|
|
203
248
|
return out;
|
|
204
249
|
}
|
|
250
|
+
/**
|
|
251
|
+
* `p:bg` → the background fill, or `undefined` when none/unsupported. `p:bgPr`
|
|
252
|
+
* carries the fill directly (`a:solidFill`/`a:gradFill` — the same children
|
|
253
|
+
* `parseFill` reads; a picture background is not yet supported); `p:bgRef` (a
|
|
254
|
+
* theme fill-style index) is approximated by its colour child as a solid fill.
|
|
255
|
+
* Used for the slide's own background and the inherited layout/master one (PX5b).
|
|
256
|
+
*/
|
|
205
257
|
function parseBackgroundFill(bg, colors) {
|
|
206
258
|
const bgPr = poChildren(bg).find((c) => poIs(c, "p:bgPr"));
|
|
207
259
|
if (bgPr) {
|
|
@@ -217,6 +269,14 @@ function parseBackgroundFill(bg, colors) {
|
|
|
217
269
|
};
|
|
218
270
|
}
|
|
219
271
|
}
|
|
272
|
+
/**
|
|
273
|
+
* A full-slide backdrop element for a background fill: a rectangle covering the
|
|
274
|
+
* page, anchored behind the content (PX5b).
|
|
275
|
+
*
|
|
276
|
+
* @param fill The resolved background fill.
|
|
277
|
+
* @param widthPt The page width in points.
|
|
278
|
+
* @param heightPt The page height in points.
|
|
279
|
+
*/
|
|
220
280
|
function backdropElement(fill, widthPt, heightPt) {
|
|
221
281
|
return {
|
|
222
282
|
kind: "shape",
|
|
@@ -241,6 +301,11 @@ function backdropElement(fill, widthPt, heightPt) {
|
|
|
241
301
|
}
|
|
242
302
|
};
|
|
243
303
|
}
|
|
304
|
+
/**
|
|
305
|
+
* `p:spPr` geometry: `a:prstGeom` (preset) or `a:custGeom` (custom path), default
|
|
306
|
+
* rect. Exported for sheet shapes (E-SHEET W2), whose `xdr:spPr` carries the same
|
|
307
|
+
* `a:` children.
|
|
308
|
+
*/
|
|
244
309
|
function parseGeometry(spPr) {
|
|
245
310
|
if (!spPr) return RECT_GEOMETRY;
|
|
246
311
|
const prst = poChildren(spPr).find((c) => poIs(c, "a:prstGeom"));
|
|
@@ -286,6 +351,19 @@ function txBodyParagraphs(txBody, ph, cascade, colors, resolveLink) {
|
|
|
286
351
|
}
|
|
287
352
|
return content;
|
|
288
353
|
}
|
|
354
|
+
/**
|
|
355
|
+
* `p:txBody` → {@link ShapeTextBody}. `a:bodyPr` carries the insets and the
|
|
356
|
+
* vertical anchor (PX6: anchor `t`/`ctr`/`b`). Exported for sheet shapes
|
|
357
|
+
* (E-SHEET W2) — like SmartArt, they pass no placeholder cascade, so runs use
|
|
358
|
+
* their direct `a:rPr` formatting.
|
|
359
|
+
*
|
|
360
|
+
* @param txBody The `p:txBody` node.
|
|
361
|
+
* @param ph The owning placeholder ref, when this is a placeholder shape.
|
|
362
|
+
* @param cascade The placeholder cascade supplying inherited run defaults.
|
|
363
|
+
* @param colors The colour resolver for run colours.
|
|
364
|
+
* @param resolveLink A run hyperlink resolver, or `undefined`.
|
|
365
|
+
* @returns The text body, or `undefined` when it holds no paragraphs.
|
|
366
|
+
*/
|
|
289
367
|
function parseTxBody(txBody, ph, cascade, colors, resolveLink) {
|
|
290
368
|
const content = txBodyParagraphs(txBody, ph, cascade, colors, resolveLink);
|
|
291
369
|
if (content.length === 0) return void 0;
|
|
@@ -1,17 +1,45 @@
|
|
|
1
1
|
import { RunProperties } from '../core/document-model/index.js';
|
|
2
2
|
import { ColorResolver } from '../core/drawingml/colors.js';
|
|
3
3
|
import { PoNode } from '../core/po-helpers.js';
|
|
4
|
+
/**
|
|
5
|
+
* §19.3.1.36 `p:ph` — a shape's placeholder reference. `type`/`idx` tie a slide
|
|
6
|
+
* shape to the matching prototype in its layout and master.
|
|
7
|
+
*/
|
|
4
8
|
export interface PlaceholderRef {
|
|
9
|
+
/** The placeholder type, e.g. `'title'`, `'ctrTitle'`, `'subTitle'`, `'body'`, `'obj'`. */
|
|
5
10
|
readonly type?: string;
|
|
6
11
|
readonly idx?: string;
|
|
7
12
|
}
|
|
13
|
+
/** An `a:xfrm` box in EMU (`off` + `ext`). */
|
|
8
14
|
export interface ShapeBoxEmu {
|
|
9
15
|
readonly x: number;
|
|
10
16
|
readonly y: number;
|
|
11
17
|
readonly cx: number;
|
|
12
18
|
readonly cy: number;
|
|
13
19
|
}
|
|
20
|
+
/**
|
|
21
|
+
* `p:nvSpPr/p:nvPr/p:ph` → the placeholder reference, or `undefined` for an
|
|
22
|
+
* ordinary (non-placeholder) shape. A bare `<p:ph/>` returns an empty ref (still
|
|
23
|
+
* a placeholder: `type` defaults to `'obj'`).
|
|
24
|
+
*/
|
|
14
25
|
export declare function parsePh(sp: PoNode): PlaceholderRef | undefined;
|
|
26
|
+
/**
|
|
27
|
+
* An xfrm node (`a:off` + `a:ext` children) → the EMU box. Works for both
|
|
28
|
+
* `a:xfrm` (in `p:spPr`) and `p:xfrm` (on a `p:graphicFrame`), whose children are
|
|
29
|
+
* identical. Returns `undefined` for a missing or degenerate (non-positive)
|
|
30
|
+
* extent.
|
|
31
|
+
*/
|
|
15
32
|
export declare function boxFromXfrm(xfrm: PoNode | undefined): ShapeBoxEmu | undefined;
|
|
33
|
+
/**
|
|
34
|
+
* `p:spPr/a:xfrm` → the EMU box, or `undefined` when the shape carries no
|
|
35
|
+
* explicit transform (a placeholder that inherits it from the layout/master).
|
|
36
|
+
*/
|
|
16
37
|
export declare function parseXfrmBox(spPr: PoNode | undefined): ShapeBoxEmu | undefined;
|
|
38
|
+
/**
|
|
39
|
+
* `a:rPr` / `a:defRPr` → {@link RunProperties}. Both the direct run formatting on
|
|
40
|
+
* a slide (`a:rPr`) and the per-level defaults in a master's `p:txStyles`
|
|
41
|
+
* (`a:defRPr`) share this element, so the cascade reuses the same reader: size
|
|
42
|
+
* (`sz`, hundredths of a point), bold/italic/underline, solid colour and the
|
|
43
|
+
* latin typeface. Scheme colours and the theme font cascade come in PX5.
|
|
44
|
+
*/
|
|
17
45
|
export declare function rPrToRunProps(rPr: PoNode | undefined, colors: ColorResolver): RunProperties;
|
|
@@ -3,6 +3,11 @@ import { poAttr, poChildren, poIntAttr, poIs } from "../core/po-helpers.js";
|
|
|
3
3
|
import { resolveColorNode } from "../core/drawingml/colors.js";
|
|
4
4
|
//#region src/pptx/sp-helpers.ts
|
|
5
5
|
var isTrue = (v) => v === "1" || v === "true" || v === "on";
|
|
6
|
+
/**
|
|
7
|
+
* `p:nvSpPr/p:nvPr/p:ph` → the placeholder reference, or `undefined` for an
|
|
8
|
+
* ordinary (non-placeholder) shape. A bare `<p:ph/>` returns an empty ref (still
|
|
9
|
+
* a placeholder: `type` defaults to `'obj'`).
|
|
10
|
+
*/
|
|
6
11
|
function parsePh(sp) {
|
|
7
12
|
const nvSpPr = poChildren(sp).find((c) => poIs(c, "p:nvSpPr"));
|
|
8
13
|
const nvPr = nvSpPr ? poChildren(nvSpPr).find((c) => poIs(c, "p:nvPr")) : void 0;
|
|
@@ -15,6 +20,12 @@ function parsePh(sp) {
|
|
|
15
20
|
...idx !== void 0 ? { idx } : {}
|
|
16
21
|
};
|
|
17
22
|
}
|
|
23
|
+
/**
|
|
24
|
+
* An xfrm node (`a:off` + `a:ext` children) → the EMU box. Works for both
|
|
25
|
+
* `a:xfrm` (in `p:spPr`) and `p:xfrm` (on a `p:graphicFrame`), whose children are
|
|
26
|
+
* identical. Returns `undefined` for a missing or degenerate (non-positive)
|
|
27
|
+
* extent.
|
|
28
|
+
*/
|
|
18
29
|
function boxFromXfrm(xfrm) {
|
|
19
30
|
if (!xfrm) return void 0;
|
|
20
31
|
const off = poChildren(xfrm).find((c) => poIs(c, "a:off"));
|
|
@@ -29,9 +40,20 @@ function boxFromXfrm(xfrm) {
|
|
|
29
40
|
cy
|
|
30
41
|
};
|
|
31
42
|
}
|
|
43
|
+
/**
|
|
44
|
+
* `p:spPr/a:xfrm` → the EMU box, or `undefined` when the shape carries no
|
|
45
|
+
* explicit transform (a placeholder that inherits it from the layout/master).
|
|
46
|
+
*/
|
|
32
47
|
function parseXfrmBox(spPr) {
|
|
33
48
|
return boxFromXfrm(spPr ? poChildren(spPr).find((c) => poIs(c, "a:xfrm")) : void 0);
|
|
34
49
|
}
|
|
50
|
+
/**
|
|
51
|
+
* `a:rPr` / `a:defRPr` → {@link RunProperties}. Both the direct run formatting on
|
|
52
|
+
* a slide (`a:rPr`) and the per-level defaults in a master's `p:txStyles`
|
|
53
|
+
* (`a:defRPr`) share this element, so the cascade reuses the same reader: size
|
|
54
|
+
* (`sz`, hundredths of a point), bold/italic/underline, solid colour and the
|
|
55
|
+
* latin typeface. Scheme colours and the theme font cascade come in PX5.
|
|
56
|
+
*/
|
|
35
57
|
function rPrToRunProps(rPr, colors) {
|
|
36
58
|
if (!rPr) return {};
|
|
37
59
|
const sz = poIntAttr(rPr, "sz");
|
|
@@ -1,8 +1,25 @@
|
|
|
1
1
|
import { DocumentWriter, WriteResult } from '../core/ir/adapters.js';
|
|
2
2
|
import { LaidOutDocument } from '../layout/page-doc.js';
|
|
3
|
+
/** Options for {@link writeSvg}. */
|
|
3
4
|
export interface SvgWriteOptions {
|
|
4
5
|
/** Gap between stacked pages, in px/pt (default 12). */
|
|
5
6
|
readonly pageGap?: number;
|
|
6
7
|
}
|
|
8
|
+
/**
|
|
9
|
+
* Render a {@link LaidOutDocument} to a single SVG preview (ir-design §7 /
|
|
10
|
+
* stage 6). Written purely against the PageDoc schema; knows nothing about OOXML
|
|
11
|
+
* or the PDF writer. PageItem coordinates are already top-left/y-down — SVG's own
|
|
12
|
+
* frame — so they are emitted verbatim. Pages stack vertically in one `<svg>`,
|
|
13
|
+
* separated by {@link SvgWriteOptions.pageGap}, each on a white outlined rect so
|
|
14
|
+
* they read as pages.
|
|
15
|
+
*
|
|
16
|
+
* @param laid The laid-out, paginated document from the layout engine.
|
|
17
|
+
* @param opts Optional page-gap override.
|
|
18
|
+
* @returns The encoded SVG bytes plus the recorded {@link Loss} list.
|
|
19
|
+
*/
|
|
7
20
|
export declare function writeSvg(laid: LaidOutDocument, opts?: SvgWriteOptions): WriteResult;
|
|
21
|
+
/**
|
|
22
|
+
* The page-medium {@link DocumentWriter} adapter (id `'svg'`), wrapping
|
|
23
|
+
* {@link writeSvg}, with the set of {@link FEATURES} it renders.
|
|
24
|
+
*/
|
|
8
25
|
export declare const svgWriter: DocumentWriter<LaidOutDocument>;
|
|
@@ -5,6 +5,18 @@ import { paintPlan } from "../layout/page-doc.js";
|
|
|
5
5
|
import { toBase64 } from "../core/bytes.js";
|
|
6
6
|
//#region src/svg/svg-writer.ts
|
|
7
7
|
var PAGE_GAP = 12;
|
|
8
|
+
/**
|
|
9
|
+
* Render a {@link LaidOutDocument} to a single SVG preview (ir-design §7 /
|
|
10
|
+
* stage 6). Written purely against the PageDoc schema; knows nothing about OOXML
|
|
11
|
+
* or the PDF writer. PageItem coordinates are already top-left/y-down — SVG's own
|
|
12
|
+
* frame — so they are emitted verbatim. Pages stack vertically in one `<svg>`,
|
|
13
|
+
* separated by {@link SvgWriteOptions.pageGap}, each on a white outlined rect so
|
|
14
|
+
* they read as pages.
|
|
15
|
+
*
|
|
16
|
+
* @param laid The laid-out, paginated document from the layout engine.
|
|
17
|
+
* @param opts Optional page-gap override.
|
|
18
|
+
* @returns The encoded SVG bytes plus the recorded {@link Loss} list.
|
|
19
|
+
*/
|
|
8
20
|
function writeSvg(laid, opts = {}) {
|
|
9
21
|
const gap = opts.pageGap ?? PAGE_GAP;
|
|
10
22
|
const losses = [];
|
|
@@ -27,6 +39,10 @@ function writeSvg(laid, opts = {}) {
|
|
|
27
39
|
losses
|
|
28
40
|
};
|
|
29
41
|
}
|
|
42
|
+
/**
|
|
43
|
+
* The page-medium {@link DocumentWriter} adapter (id `'svg'`), wrapping
|
|
44
|
+
* {@link writeSvg}, with the set of {@link FEATURES} it renders.
|
|
45
|
+
*/
|
|
30
46
|
var svgWriter = {
|
|
31
47
|
id: "svg",
|
|
32
48
|
consumes: "page",
|
|
@@ -1,4 +1,20 @@
|
|
|
1
1
|
import { DocumentReader, ReadResult } from '../../core/ir/adapters.js';
|
|
2
2
|
import { FlowDoc } from '../../core/ir/flow.js';
|
|
3
|
+
/**
|
|
4
|
+
* Read a legacy Word 97–2003 `.doc` (DOC-1..11) into the same {@link FlowDoc} the
|
|
5
|
+
* OOXML docx reader produces: paragraphs of formatted runs, tables (column widths,
|
|
6
|
+
* cell borders, vertical merges, shading), inline images, list items, the first
|
|
7
|
+
* section's page size and the section's headers/footers. The text + formatting is
|
|
8
|
+
* read; drawing shapes / text boxes and comments are not, so a `degraded` (or
|
|
9
|
+
* `dropped`, for an encrypted file) {@link Loss} is reported.
|
|
10
|
+
*
|
|
11
|
+
* @param bytes The `.doc` (OLE2/CFB) bytes.
|
|
12
|
+
* @returns The projected {@link FlowDoc} and the read loss(es).
|
|
13
|
+
*/
|
|
3
14
|
export declare function readDoc(bytes: Uint8Array): ReadResult<FlowDoc>;
|
|
15
|
+
/**
|
|
16
|
+
* The {@link DocumentReader} for legacy `.doc`: sniffs a Word 97–2003 binary (a
|
|
17
|
+
* CFB with a `WordDocument` stream) and reads it via {@link readDoc} into a
|
|
18
|
+
* {@link FlowDoc}.
|
|
19
|
+
*/
|
|
4
20
|
export declare const docReader: DocumentReader<FlowDoc>;
|
|
@@ -114,6 +114,17 @@ var DOC_ENCRYPTED_LOSS = {
|
|
|
114
114
|
feature: FEATURES.text,
|
|
115
115
|
detail: "legacy .doc is encrypted/obfuscated — its text cannot be read"
|
|
116
116
|
};
|
|
117
|
+
/**
|
|
118
|
+
* Read a legacy Word 97–2003 `.doc` (DOC-1..11) into the same {@link FlowDoc} the
|
|
119
|
+
* OOXML docx reader produces: paragraphs of formatted runs, tables (column widths,
|
|
120
|
+
* cell borders, vertical merges, shading), inline images, list items, the first
|
|
121
|
+
* section's page size and the section's headers/footers. The text + formatting is
|
|
122
|
+
* read; drawing shapes / text boxes and comments are not, so a `degraded` (or
|
|
123
|
+
* `dropped`, for an encrypted file) {@link Loss} is reported.
|
|
124
|
+
*
|
|
125
|
+
* @param bytes The `.doc` (OLE2/CFB) bytes.
|
|
126
|
+
* @returns The projected {@link FlowDoc} and the read loss(es).
|
|
127
|
+
*/
|
|
117
128
|
function readDoc(bytes) {
|
|
118
129
|
const content = extractDocContent(bytes);
|
|
119
130
|
const resources = new ResourceStore();
|
|
@@ -140,16 +151,22 @@ function readDoc(bytes) {
|
|
|
140
151
|
addStory(hf.firstFooter, "footer", "first");
|
|
141
152
|
addStory(hf.evenFooter, "footer", "even");
|
|
142
153
|
}
|
|
154
|
+
const ps = content.pageSize;
|
|
155
|
+
const pageSize = ps ? {
|
|
156
|
+
width: pt(ps.widthPt),
|
|
157
|
+
height: pt(ps.heightPt),
|
|
158
|
+
orientation: ps.widthPt > ps.heightPt ? "landscape" : "portrait"
|
|
159
|
+
} : {
|
|
160
|
+
width: pt(612),
|
|
161
|
+
height: pt(792)
|
|
162
|
+
};
|
|
143
163
|
return {
|
|
144
164
|
doc: {
|
|
145
165
|
kind: "flow",
|
|
146
166
|
body: resolveBodyStyles(body, EMPTY_STYLE_SHEET),
|
|
147
167
|
sections: [],
|
|
148
168
|
section: {
|
|
149
|
-
pageSize
|
|
150
|
-
width: pt(612),
|
|
151
|
-
height: pt(792)
|
|
152
|
-
},
|
|
169
|
+
pageSize,
|
|
153
170
|
margins: {
|
|
154
171
|
top: pt(72),
|
|
155
172
|
right: pt(72),
|
|
@@ -410,6 +427,11 @@ function alignmentFromJc(jc) {
|
|
|
410
427
|
default: return;
|
|
411
428
|
}
|
|
412
429
|
}
|
|
430
|
+
/**
|
|
431
|
+
* The {@link DocumentReader} for legacy `.doc`: sniffs a Word 97–2003 binary (a
|
|
432
|
+
* CFB with a `WordDocument` stream) and reads it via {@link readDoc} into a
|
|
433
|
+
* {@link FlowDoc}.
|
|
434
|
+
*/
|
|
413
435
|
var docReader = {
|
|
414
436
|
id: "doc",
|
|
415
437
|
produces: "flow",
|
|
@@ -1,21 +1,37 @@
|
|
|
1
|
+
/** Run (character) formatting decoded from a CHPX grpprl. */
|
|
1
2
|
export interface DocCharProps {
|
|
2
3
|
readonly bold?: boolean;
|
|
3
4
|
readonly italic?: boolean;
|
|
5
|
+
/** Word `kul` underline code (0 = none). */
|
|
4
6
|
readonly underlineKul?: number;
|
|
7
|
+
/** Font size in half-points. */
|
|
5
8
|
readonly sizeHalfPts?: number;
|
|
9
|
+
/** The character is special — `sprmCFSpec` (e.g. a picture placeholder). */
|
|
6
10
|
readonly fSpec?: boolean;
|
|
11
|
+
/** `sprmCPicLocation` — offset into the `Data` stream of the picture's PICF. */
|
|
7
12
|
readonly picOffset?: number;
|
|
8
13
|
}
|
|
14
|
+
/** An embedded picture: the extracted image bytes and its display size (twips). */
|
|
9
15
|
export interface DocPicture {
|
|
10
16
|
readonly bytes: Uint8Array;
|
|
11
17
|
readonly widthTwips: number;
|
|
12
18
|
readonly heightTwips: number;
|
|
13
19
|
}
|
|
20
|
+
/**
|
|
21
|
+
* One cell border (DOC-11) from a Brc80: its width in points, colour and whether
|
|
22
|
+
* it is a double line. Absent when the cell edge has no border.
|
|
23
|
+
*/
|
|
14
24
|
export interface DocBorder {
|
|
15
25
|
readonly widthPt: number;
|
|
16
26
|
readonly colorHex: string;
|
|
27
|
+
/** The border is a double line (`brcType` 0x03). */
|
|
17
28
|
readonly double?: boolean;
|
|
18
29
|
}
|
|
30
|
+
/**
|
|
31
|
+
* A table cell's TC80 descriptor (DOC-11): its four edge borders and its
|
|
32
|
+
* vertical-merge marker (`restart` = the top of a vertical span, `continue` = a
|
|
33
|
+
* cell merged into the one above). Carried per cell on the row's TTP.
|
|
34
|
+
*/
|
|
19
35
|
export interface DocTc {
|
|
20
36
|
readonly borders?: {
|
|
21
37
|
readonly top?: DocBorder;
|
|
@@ -25,31 +41,62 @@ export interface DocTc {
|
|
|
25
41
|
};
|
|
26
42
|
readonly vMerge?: 'restart' | 'continue';
|
|
27
43
|
}
|
|
44
|
+
/** Paragraph formatting decoded from a PAPX grpprl. */
|
|
28
45
|
export interface DocParaProps {
|
|
46
|
+
/** Word justification (0 left, 1 center, 2 right, 3 both, 4 distribute). */
|
|
29
47
|
readonly jc?: number;
|
|
30
48
|
readonly indentLeftTwips?: number;
|
|
31
49
|
readonly indentRightTwips?: number;
|
|
50
|
+
/** First-line indent, signed (negative = hanging). */
|
|
32
51
|
readonly indentFirstTwips?: number;
|
|
33
52
|
readonly spaceBeforeTwips?: number;
|
|
34
53
|
readonly spaceAfterTwips?: number;
|
|
54
|
+
/** The paragraph is in a table — `sprmPFInTable`. */
|
|
35
55
|
readonly inTable?: boolean;
|
|
56
|
+
/** This is the row's terminating paragraph (TTP) — `sprmPFTtp`. */
|
|
36
57
|
readonly rowEnd?: boolean;
|
|
58
|
+
/**
|
|
59
|
+
* `sprmTDefTable` rgdxaCenter — the (cols+1) cell-boundary x-positions (twips);
|
|
60
|
+
* present on the TTP. Cell `i` width = `edge[i+1] − edge[i]`.
|
|
61
|
+
*/
|
|
37
62
|
readonly cellEdgesTwips?: ReadonlyArray<number>;
|
|
63
|
+
/**
|
|
64
|
+
* `sprmTDefTable` TC80 per-cell descriptors (borders + vertical merge), one per
|
|
65
|
+
* cell, present on the TTP alongside `cellEdgesTwips` (DOC-11).
|
|
66
|
+
*/
|
|
38
67
|
readonly cellDescriptors?: ReadonlyArray<DocTc>;
|
|
68
|
+
/**
|
|
69
|
+
* `sprmTDefTableShd` — each cell's background fill hex (cvBack), or `undefined`
|
|
70
|
+
* for an auto (no-fill) cell. Indexed parallel to `cellDescriptors`.
|
|
71
|
+
*/
|
|
39
72
|
readonly cellShadings?: ReadonlyArray<string | undefined>;
|
|
73
|
+
/** `sprmPIlfo` — list-format override index (>0 ⇒ the paragraph is a list item). */
|
|
40
74
|
readonly listIlfo?: number;
|
|
75
|
+
/** `sprmPIlvl` — list level (0–8). */
|
|
41
76
|
readonly listIlvl?: number;
|
|
42
77
|
}
|
|
78
|
+
/** One maximal same-formatting run of text, or an embedded picture. */
|
|
43
79
|
export interface DocRun {
|
|
44
80
|
readonly text: string;
|
|
45
81
|
readonly props: DocCharProps;
|
|
82
|
+
/** Set instead of `text` when the run is an embedded picture. */
|
|
46
83
|
readonly picture?: DocPicture;
|
|
47
84
|
}
|
|
85
|
+
/** One paragraph: its runs plus the decoded paragraph properties. */
|
|
48
86
|
export interface DocParagraph {
|
|
49
87
|
readonly runs: ReadonlyArray<DocRun>;
|
|
50
88
|
readonly props: DocParaProps;
|
|
89
|
+
/**
|
|
90
|
+
* The paragraph was ended by a cell mark (0x07) rather than a CR — i.e. it
|
|
91
|
+
* closes a table cell. With `props.rowEnd` it also closes the row.
|
|
92
|
+
*/
|
|
51
93
|
readonly cellMark?: boolean;
|
|
52
94
|
}
|
|
95
|
+
/**
|
|
96
|
+
* The section's header/footer stories (best-effort: the binary story ordering
|
|
97
|
+
* cannot be validated against a real file, so only well-formed, non-empty stories
|
|
98
|
+
* are surfaced). `default` is the odd-page (primary) header/footer.
|
|
99
|
+
*/
|
|
53
100
|
export interface DocHeaderFooters {
|
|
54
101
|
readonly defaultHeader?: ReadonlyArray<DocParagraph>;
|
|
55
102
|
readonly defaultFooter?: ReadonlyArray<DocParagraph>;
|
|
@@ -58,11 +105,21 @@ export interface DocHeaderFooters {
|
|
|
58
105
|
readonly evenHeader?: ReadonlyArray<DocParagraph>;
|
|
59
106
|
readonly evenFooter?: ReadonlyArray<DocParagraph>;
|
|
60
107
|
}
|
|
108
|
+
/**
|
|
109
|
+
* One list level (LVL) — the format of its number (DOC-10). `nfc` is the MSONFC
|
|
110
|
+
* code (0 arabic, 1/2 upper/lower roman, 3/4 upper/lower letter, 23 bullet, 0xFF
|
|
111
|
+
* none); `xst` is the number-text template as UTF-16 code units, where a code unit
|
|
112
|
+
* ≤ 8 is a placeholder for the number of that (zero-based) level.
|
|
113
|
+
*/
|
|
61
114
|
export interface DocLvl {
|
|
62
115
|
readonly nfc: number;
|
|
63
116
|
readonly iStartAt: number;
|
|
64
117
|
readonly xst: ReadonlyArray<number>;
|
|
65
118
|
}
|
|
119
|
+
/**
|
|
120
|
+
* The document's list tables (DOC-10): an LFO → lsid map (a paragraph's 1-based
|
|
121
|
+
* `sprmPIlfo` indexes it) and, per lsid, the list's levels.
|
|
122
|
+
*/
|
|
66
123
|
export interface DocListTables {
|
|
67
124
|
readonly lfoLsids: ReadonlyArray<number>;
|
|
68
125
|
readonly lists: ReadonlyMap<number, {
|
|
@@ -70,10 +127,34 @@ export interface DocListTables {
|
|
|
70
127
|
readonly levels: ReadonlyArray<DocLvl>;
|
|
71
128
|
}>;
|
|
72
129
|
}
|
|
130
|
+
/** Everything extracted from a `.doc`'s `WordDocument` stream. */
|
|
73
131
|
export interface DocContent {
|
|
74
132
|
readonly paragraphs: ReadonlyArray<DocParagraph>;
|
|
75
133
|
readonly headerFooters?: DocHeaderFooters;
|
|
134
|
+
/** The list tables resolving a paragraph's (ilfo, ilvl) to its number format. */
|
|
76
135
|
readonly listTables?: DocListTables;
|
|
136
|
+
/**
|
|
137
|
+
* The first section's page size in points (xaPage/yaPage from its SEP), when
|
|
138
|
+
* present and sane; absent ⇒ the reader's default (US Letter) applies.
|
|
139
|
+
*/
|
|
140
|
+
readonly pageSize?: {
|
|
141
|
+
readonly widthPt: number;
|
|
142
|
+
readonly heightPt: number;
|
|
143
|
+
};
|
|
144
|
+
/** The file is encrypted/obfuscated — text cannot be read without the key. */
|
|
77
145
|
readonly encrypted: boolean;
|
|
78
146
|
}
|
|
147
|
+
/**
|
|
148
|
+
* Extract a `.doc`'s `WordDocument` stream into its main-document paragraphs plus
|
|
149
|
+
* the section's header/footer stories, list tables and first-section page size.
|
|
150
|
+
* Joins the piece table (CLX → CPs/FCs), CHPX run formatting and PAPX paragraph
|
|
151
|
+
* formatting, splitting at the CR / cell marks. Every offset is bounds-checked, so
|
|
152
|
+
* a structurally odd file yields no text rather than throwing.
|
|
153
|
+
*
|
|
154
|
+
* @param bytes The `.doc` (OLE2/CFB) bytes.
|
|
155
|
+
* @returns The extracted {@link DocContent}; `encrypted` is set (with no
|
|
156
|
+
* paragraphs) for an encrypted file, and an empty result is returned when the
|
|
157
|
+
* stream is missing, not a Word file, or has no piece table (Word 6/95 is out of
|
|
158
|
+
* scope).
|
|
159
|
+
*/
|
|
79
160
|
export declare function extractDocContent(bytes: Uint8Array): DocContent;
|
|
@@ -13,6 +13,8 @@ var OFF_FCPLCFBTEPAPX = 258;
|
|
|
13
13
|
var OFF_LCBPLCFBTEPAPX = 262;
|
|
14
14
|
var OFF_FCCLX = 418;
|
|
15
15
|
var OFF_LCBCLX = 422;
|
|
16
|
+
var OFF_FCPLCFSED = 202;
|
|
17
|
+
var OFF_LCBPLCFSED = 206;
|
|
16
18
|
var OFF_FCPLFLST = 738;
|
|
17
19
|
var OFF_LCBPLFLST = 742;
|
|
18
20
|
var OFF_FCPLFLFO = 746;
|
|
@@ -43,6 +45,9 @@ var SPRM_T_DEF_TABLE_SHD = 54802;
|
|
|
43
45
|
var MAX_ROW_CELLS = 256;
|
|
44
46
|
var SPRM_P_ILVL = 9738;
|
|
45
47
|
var SPRM_P_ILFO = 17931;
|
|
48
|
+
var SPRM_S_XA_PAGE = 45087;
|
|
49
|
+
var SPRM_S_YA_PAGE = 45088;
|
|
50
|
+
var MAX_PAGE_TWIPS = 31680;
|
|
46
51
|
var SPRA_LEN = [
|
|
47
52
|
1,
|
|
48
53
|
1,
|
|
@@ -63,6 +68,37 @@ var EMPTY = {
|
|
|
63
68
|
paragraphs: [],
|
|
64
69
|
encrypted: false
|
|
65
70
|
};
|
|
71
|
+
function readSectionPageSize(wd, table) {
|
|
72
|
+
const fc = u32(wd, OFF_FCPLCFSED);
|
|
73
|
+
const lcb = u32(wd, OFF_LCBPLCFSED);
|
|
74
|
+
if (lcb < 20 || fc + lcb > table.length) return void 0;
|
|
75
|
+
const fcSepx = u32(table.subarray(fc, fc + lcb), (Math.floor((lcb - 4) / 16) + 1) * 4 + 2);
|
|
76
|
+
if (fcSepx === 4294967295 || fcSepx + 2 > wd.length) return void 0;
|
|
77
|
+
const cb = u16(wd, fcSepx);
|
|
78
|
+
const grpprl = wd.subarray(fcSepx + 2, Math.min(wd.length, fcSepx + 2 + cb));
|
|
79
|
+
let xa = 0;
|
|
80
|
+
let ya = 0;
|
|
81
|
+
for (const { sprm, op } of sprms(grpprl)) if (sprm === SPRM_S_XA_PAGE) xa = u16(grpprl, op);
|
|
82
|
+
else if (sprm === SPRM_S_YA_PAGE) ya = u16(grpprl, op);
|
|
83
|
+
if (xa < 1 || ya < 1 || xa > MAX_PAGE_TWIPS || ya > MAX_PAGE_TWIPS) return void 0;
|
|
84
|
+
return {
|
|
85
|
+
widthPt: xa / 20,
|
|
86
|
+
heightPt: ya / 20
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Extract a `.doc`'s `WordDocument` stream into its main-document paragraphs plus
|
|
91
|
+
* the section's header/footer stories, list tables and first-section page size.
|
|
92
|
+
* Joins the piece table (CLX → CPs/FCs), CHPX run formatting and PAPX paragraph
|
|
93
|
+
* formatting, splitting at the CR / cell marks. Every offset is bounds-checked, so
|
|
94
|
+
* a structurally odd file yields no text rather than throwing.
|
|
95
|
+
*
|
|
96
|
+
* @param bytes The `.doc` (OLE2/CFB) bytes.
|
|
97
|
+
* @returns The extracted {@link DocContent}; `encrypted` is set (with no
|
|
98
|
+
* paragraphs) for an encrypted file, and an empty result is returned when the
|
|
99
|
+
* stream is missing, not a Word file, or has no piece table (Word 6/95 is out of
|
|
100
|
+
* scope).
|
|
101
|
+
*/
|
|
66
102
|
function extractDocContent(bytes) {
|
|
67
103
|
const cfb = openCfb(bytes);
|
|
68
104
|
const wd = cfb.readStream("WordDocument");
|
|
@@ -89,10 +125,12 @@ function extractDocContent(bytes) {
|
|
|
89
125
|
const main = buildParagraphs(wd, pieces, chpx, papx, 0, ccpText, data);
|
|
90
126
|
const headerFooters = extractHeaderFooters(wd, table, pieces, chpx, papx, data, ccpText);
|
|
91
127
|
const listTables = parseListTables(wd, table);
|
|
128
|
+
const pageSize = readSectionPageSize(wd, table);
|
|
92
129
|
return {
|
|
93
130
|
paragraphs: main,
|
|
94
131
|
...headerFooters ? { headerFooters } : {},
|
|
95
132
|
...listTables ? { listTables } : {},
|
|
133
|
+
...pageSize ? { pageSize } : {},
|
|
96
134
|
encrypted: false
|
|
97
135
|
};
|
|
98
136
|
}
|