reamkit 1.15.1 → 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 +16 -0
- 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 +47 -0
- package/dist/esm/pdf-reader/flow-build.js +42 -0
- 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 +15 -0
- 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 +13 -0
- 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 +21 -0
- 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 +16 -0
- package/dist/esm/word/doc/doc-text.d.ts +77 -0
- package/dist/esm/word/doc/doc-text.js +13 -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
|
@@ -1,6 +1,21 @@
|
|
|
1
1
|
import { AbstractNumbering, Numbering, NumberingLevel, NumberingReference } from '../document-model/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* Mutable list-counter state for one numbering scope (e.g. a body or a single
|
|
4
|
+
* header/footer band). Tracks a counter per list per level and advances them as
|
|
5
|
+
* paragraphs are visited in order.
|
|
6
|
+
*/
|
|
2
7
|
export declare class NumberingState {
|
|
3
8
|
private readonly counters;
|
|
9
|
+
/**
|
|
10
|
+
* Advance the counter for `ref` (resetting deeper levels) and format its
|
|
11
|
+
* marker text. The first hit at a level seeds it from the level's `start`;
|
|
12
|
+
* subsequent hits increment.
|
|
13
|
+
*
|
|
14
|
+
* @param numbering The parsed numbering definitions.
|
|
15
|
+
* @param ref The paragraph's `numId` + `ilvl` reference.
|
|
16
|
+
* @returns The formatted marker (e.g. `"2."`, `"•"`), or `null` when the
|
|
17
|
+
* reference does not resolve to a known list level.
|
|
18
|
+
*/
|
|
4
19
|
resolveMarker(numbering: Numbering, ref: NumberingReference): string | null;
|
|
5
20
|
}
|
|
6
21
|
export declare function formatLevelMarker(abstractNum: AbstractNumbering, currentLevel: NumberingLevel, counters: ReadonlyArray<number>): string;
|
|
@@ -1,6 +1,21 @@
|
|
|
1
1
|
//#region src/core/numbering/state.ts
|
|
2
|
+
/**
|
|
3
|
+
* Mutable list-counter state for one numbering scope (e.g. a body or a single
|
|
4
|
+
* header/footer band). Tracks a counter per list per level and advances them as
|
|
5
|
+
* paragraphs are visited in order.
|
|
6
|
+
*/
|
|
2
7
|
var NumberingState = class {
|
|
3
8
|
counters = /* @__PURE__ */ new Map();
|
|
9
|
+
/**
|
|
10
|
+
* Advance the counter for `ref` (resetting deeper levels) and format its
|
|
11
|
+
* marker text. The first hit at a level seeds it from the level's `start`;
|
|
12
|
+
* subsequent hits increment.
|
|
13
|
+
*
|
|
14
|
+
* @param numbering The parsed numbering definitions.
|
|
15
|
+
* @param ref The paragraph's `numId` + `ilvl` reference.
|
|
16
|
+
* @returns The formatted marker (e.g. `"2."`, `"•"`), or `null` when the
|
|
17
|
+
* reference does not resolve to a known list level.
|
|
18
|
+
*/
|
|
4
19
|
resolveMarker(numbering, ref) {
|
|
5
20
|
const instance = numbering.numInstances.get(ref.numId);
|
|
6
21
|
if (!instance) return null;
|
|
@@ -1,12 +1,16 @@
|
|
|
1
|
+
/** The object type of a CFB directory entry (MS-CFB §2.6.1). */
|
|
1
2
|
export type CfbEntryType = 'root' | 'storage' | 'stream' | 'unknown';
|
|
3
|
+
/** One CFB directory entry: its name, type, starting sector and byte size. */
|
|
2
4
|
export interface CfbEntry {
|
|
3
5
|
readonly name: string;
|
|
4
6
|
readonly type: CfbEntryType;
|
|
5
7
|
readonly startSector: number;
|
|
6
8
|
readonly size: number;
|
|
7
9
|
}
|
|
10
|
+
/** Error thrown for a malformed or unsupported compound file. */
|
|
8
11
|
export declare class CfbError extends Error {
|
|
9
12
|
}
|
|
13
|
+
/** A parsed compound file: its directory entries plus stream-access helpers. */
|
|
10
14
|
export interface Cfb {
|
|
11
15
|
/** Every directory entry, in directory order (index 0 is the root storage). */
|
|
12
16
|
readonly entries: ReadonlyArray<CfbEntry>;
|
|
@@ -15,5 +19,20 @@ export interface Cfb {
|
|
|
15
19
|
/** Whether a stream entry with that name exists (case-insensitive). */
|
|
16
20
|
hasStream: (name: string) => boolean;
|
|
17
21
|
}
|
|
22
|
+
/**
|
|
23
|
+
* Cheap magic-byte probe — the first eight bytes are the CFB signature. Shared
|
|
24
|
+
* by the legacy readers' sniff and by `OpcPackage` to tell an OLE file from a
|
|
25
|
+
* ZIP.
|
|
26
|
+
*/
|
|
18
27
|
export declare function isCfb(bytes: Uint8Array): boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Parse a compound file's bytes into a {@link Cfb}: read the header, FAT (via the
|
|
30
|
+
* DIFAT), directory and mini-FAT, and expose its streams by name. The
|
|
31
|
+
* main-document storage's own streams win a name clash over an embedded object's
|
|
32
|
+
* (MS-CFB §2.6). Every sector index is bounds-checked and every chain walk is
|
|
33
|
+
* capped, so a crafted container aborts rather than looping or exhausting memory.
|
|
34
|
+
*
|
|
35
|
+
* @throws CfbError on a bad signature, an unsupported sector layout, or a
|
|
36
|
+
* corrupt/cyclic FAT, mini-FAT or DIFAT chain.
|
|
37
|
+
*/
|
|
19
38
|
export declare function openCfb(bytes: Uint8Array): Cfb;
|
package/dist/esm/core/ole/cfb.js
CHANGED
|
@@ -14,12 +14,28 @@ var FREESECT = 4294967295;
|
|
|
14
14
|
var HEADER_SIZE = 512;
|
|
15
15
|
var DIR_ENTRY_SIZE = 128;
|
|
16
16
|
var MAX_TOTAL_BYTES = 512 * 1024 * 1024;
|
|
17
|
+
/** Error thrown for a malformed or unsupported compound file. */
|
|
17
18
|
var CfbError = class extends Error {};
|
|
19
|
+
/**
|
|
20
|
+
* Cheap magic-byte probe — the first eight bytes are the CFB signature. Shared
|
|
21
|
+
* by the legacy readers' sniff and by `OpcPackage` to tell an OLE file from a
|
|
22
|
+
* ZIP.
|
|
23
|
+
*/
|
|
18
24
|
function isCfb(bytes) {
|
|
19
25
|
if (bytes.length < HEADER_SIZE) return false;
|
|
20
26
|
for (let i = 0; i < SIGNATURE.length; i++) if (bytes[i] !== SIGNATURE[i]) return false;
|
|
21
27
|
return true;
|
|
22
28
|
}
|
|
29
|
+
/**
|
|
30
|
+
* Parse a compound file's bytes into a {@link Cfb}: read the header, FAT (via the
|
|
31
|
+
* DIFAT), directory and mini-FAT, and expose its streams by name. The
|
|
32
|
+
* main-document storage's own streams win a name clash over an embedded object's
|
|
33
|
+
* (MS-CFB §2.6). Every sector index is bounds-checked and every chain walk is
|
|
34
|
+
* capped, so a crafted container aborts rather than looping or exhausting memory.
|
|
35
|
+
*
|
|
36
|
+
* @throws CfbError on a bad signature, an unsupported sector layout, or a
|
|
37
|
+
* corrupt/cyclic FAT, mini-FAT or DIFAT chain.
|
|
38
|
+
*/
|
|
23
39
|
function openCfb(bytes) {
|
|
24
40
|
if (!isCfb(bytes)) throw new CfbError("not a compound file (bad signature)");
|
|
25
41
|
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
@@ -1,11 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Package-level metadata from `docProps/core.xml` (ECMA-376 Part 2 §11.1), in
|
|
3
|
+
* the Dublin Core / OPC core vocabulary. Shared by docx and xlsx packages.
|
|
4
|
+
*/
|
|
1
5
|
export interface CoreProperties {
|
|
2
6
|
readonly title?: string;
|
|
3
7
|
readonly subject?: string;
|
|
8
|
+
/** `dc:creator` → PDF "Author". */
|
|
4
9
|
readonly creator?: string;
|
|
5
10
|
readonly keywords?: string;
|
|
6
11
|
readonly description?: string;
|
|
7
12
|
readonly lastModifiedBy?: string;
|
|
13
|
+
/** `dcterms:created` timestamp. */
|
|
8
14
|
readonly created?: Date;
|
|
15
|
+
/** `dcterms:modified` timestamp. */
|
|
9
16
|
readonly modified?: Date;
|
|
10
17
|
}
|
|
18
|
+
/**
|
|
19
|
+
* Parse `docProps/core.xml` into {@link CoreProperties}. Tolerates the
|
|
20
|
+
* `cp:`/`dc:`/`dcterms:` prefixed and the bare element forms; returns `{}` when
|
|
21
|
+
* the root element is absent.
|
|
22
|
+
*/
|
|
11
23
|
export declare function parseCoreProperties(data: Uint8Array): CoreProperties;
|
|
@@ -9,6 +9,11 @@ var parser = new XMLParser({
|
|
|
9
9
|
parseTagValue: false,
|
|
10
10
|
trimValues: false
|
|
11
11
|
});
|
|
12
|
+
/**
|
|
13
|
+
* Parse `docProps/core.xml` into {@link CoreProperties}. Tolerates the
|
|
14
|
+
* `cp:`/`dc:`/`dcterms:` prefixed and the bare element forms; returns `{}` when
|
|
15
|
+
* the root element is absent.
|
|
16
|
+
*/
|
|
12
17
|
function parseCoreProperties(data) {
|
|
13
18
|
const tree = parser.parse(decoder.decode(data));
|
|
14
19
|
const root = tree["cp:coreProperties"] ?? tree["coreProperties"];
|
|
@@ -1,19 +1,27 @@
|
|
|
1
1
|
import { Relationship } from './relationships.js';
|
|
2
|
+
/** One part to write into the package: its path, bytes, and content type. */
|
|
2
3
|
export interface OpcPart {
|
|
3
|
-
/** Package path, e.g. 'word/document.xml'
|
|
4
|
+
/** Package path, e.g. `'word/document.xml'`. No leading slash. */
|
|
4
5
|
readonly path: string;
|
|
5
6
|
readonly data: Uint8Array;
|
|
6
|
-
/** Content type for the [Content_Types].xml Override (XML parts). */
|
|
7
|
+
/** Content type for the `[Content_Types].xml` Override (XML parts). */
|
|
7
8
|
readonly contentType: string;
|
|
8
9
|
}
|
|
10
|
+
/**
|
|
11
|
+
* A part's relationships (id/type/target[/External]). The reader returns the
|
|
12
|
+
* same {@link Relationship} shape, so a writer round-trips through
|
|
13
|
+
* `parseRelationships`.
|
|
14
|
+
*/
|
|
9
15
|
export interface OpcPartRelationships {
|
|
10
|
-
/** The owning part, e.g. 'word/document.xml' (or '' for the package root). */
|
|
16
|
+
/** The owning part, e.g. `'word/document.xml'` (or `''` for the package root). */
|
|
11
17
|
readonly sourcePart: string;
|
|
12
18
|
readonly relationships: ReadonlyArray<Relationship>;
|
|
13
19
|
}
|
|
20
|
+
/** The full input to {@link buildOpcPackage}: parts plus their relationships. */
|
|
14
21
|
export interface OpcWriteOptions {
|
|
22
|
+
/** The content parts (excluding `[Content_Types].xml` and `.rels`, which are generated). */
|
|
15
23
|
readonly parts: ReadonlyArray<OpcPart>;
|
|
16
|
-
/** Package-level relationships (_rels/.rels). */
|
|
24
|
+
/** Package-level relationships (`_rels/.rels`). */
|
|
17
25
|
readonly rootRelationships: ReadonlyArray<Relationship>;
|
|
18
26
|
/** Per-part relationships (word/_rels/<part>.rels). */
|
|
19
27
|
readonly partRelationships?: ReadonlyArray<OpcPartRelationships>;
|
|
@@ -24,5 +32,17 @@ export interface OpcWriteOptions {
|
|
|
24
32
|
*/
|
|
25
33
|
readonly defaultsByExtension?: Readonly<Record<string, string>>;
|
|
26
34
|
}
|
|
35
|
+
/**
|
|
36
|
+
* Assemble parts + relationships into a deterministic OPC ZIP: it synthesizes
|
|
37
|
+
* `[Content_Types].xml` and the `.rels` parts, then zips everything with a fixed
|
|
38
|
+
* timestamp so the same input always yields byte-identical output.
|
|
39
|
+
*
|
|
40
|
+
* @returns The packaged `.docx`/`.xlsx`/… bytes.
|
|
41
|
+
*/
|
|
27
42
|
export declare function buildOpcPackage(options: OpcWriteOptions): Uint8Array;
|
|
43
|
+
/**
|
|
44
|
+
* The relationships-part path for a part: `word/document.xml` →
|
|
45
|
+
* `word/_rels/document.xml.rels`. (`''` (root) is handled separately as
|
|
46
|
+
* `_rels/.rels`.)
|
|
47
|
+
*/
|
|
28
48
|
export declare function relsPathFor(partPath: string): string;
|
|
@@ -4,6 +4,13 @@ var encoder = new TextEncoder();
|
|
|
4
4
|
var RELS_NS = "http://schemas.openxmlformats.org/package/2006/relationships";
|
|
5
5
|
var CT_NS = "http://schemas.openxmlformats.org/package/2006/content-types";
|
|
6
6
|
var FIXED_MTIME = Date.UTC(1980, 0, 1, 0, 0, 0);
|
|
7
|
+
/**
|
|
8
|
+
* Assemble parts + relationships into a deterministic OPC ZIP: it synthesizes
|
|
9
|
+
* `[Content_Types].xml` and the `.rels` parts, then zips everything with a fixed
|
|
10
|
+
* timestamp so the same input always yields byte-identical output.
|
|
11
|
+
*
|
|
12
|
+
* @returns The packaged `.docx`/`.xlsx`/… bytes.
|
|
13
|
+
*/
|
|
7
14
|
function buildOpcPackage(options) {
|
|
8
15
|
const entries = {};
|
|
9
16
|
const add = (path, data) => {
|
|
@@ -18,6 +25,11 @@ function buildOpcPackage(options) {
|
|
|
18
25
|
}
|
|
19
26
|
return zipSync(entries);
|
|
20
27
|
}
|
|
28
|
+
/**
|
|
29
|
+
* The relationships-part path for a part: `word/document.xml` →
|
|
30
|
+
* `word/_rels/document.xml.rels`. (`''` (root) is handled separately as
|
|
31
|
+
* `_rels/.rels`.)
|
|
32
|
+
*/
|
|
21
33
|
function relsPathFor(partPath) {
|
|
22
34
|
const slash = partPath.lastIndexOf("/");
|
|
23
35
|
const dir = slash >= 0 ? partPath.slice(0, slash) : "";
|
|
@@ -1,25 +1,80 @@
|
|
|
1
1
|
import { Relationship } from './relationships.js';
|
|
2
|
+
/**
|
|
3
|
+
* Resource caps applied while unzipping a package — a defence against
|
|
4
|
+
* decompression ("zip") bombs and pathological archives. Generous defaults that
|
|
5
|
+
* never reject a legitimate office document; tighten for untrusted input.
|
|
6
|
+
*/
|
|
2
7
|
export interface OpcOpenOptions {
|
|
8
|
+
/** Reject an archive whose raw (compressed) size exceeds this (default 128 MiB). */
|
|
3
9
|
readonly maxArchiveBytes?: number;
|
|
10
|
+
/** Reject any single entry declaring an uncompressed size over this (default 256 MiB). */
|
|
4
11
|
readonly maxEntryBytes?: number;
|
|
12
|
+
/** Reject if the total declared uncompressed size exceeds this (default 512 MiB). */
|
|
5
13
|
readonly maxTotalBytes?: number;
|
|
14
|
+
/** Reject archives with more than this many entries (default 65 536). */
|
|
6
15
|
readonly maxEntries?: number;
|
|
7
16
|
}
|
|
17
|
+
/**
|
|
18
|
+
* An opened OPC package (ECMA-376 Part 2): a ZIP archive's parts plus its
|
|
19
|
+
* package-level relationships, with helpers to look up parts, resolve part
|
|
20
|
+
* relationships, and find the main document part.
|
|
21
|
+
*/
|
|
8
22
|
export declare class OpcPackage {
|
|
9
23
|
private readonly parts;
|
|
10
24
|
private readonly rootRelationships;
|
|
25
|
+
/**
|
|
26
|
+
* @param parts The package parts keyed by ZIP-convention path (no leading slash).
|
|
27
|
+
* @param rootRelationships The package-level relationships from `_rels/.rels`.
|
|
28
|
+
*/
|
|
11
29
|
private constructor();
|
|
12
30
|
private readonly relsCache;
|
|
31
|
+
/**
|
|
32
|
+
* Unzip and validate a package's bytes. Rejects an OLE compound file (an
|
|
33
|
+
* encrypted OOXML container or a legacy binary `.doc`/`.xls`) and enforces the
|
|
34
|
+
* zip-bomb caps from `options`.
|
|
35
|
+
*
|
|
36
|
+
* @throws Error when the bytes are not a ZIP package, a cap is exceeded, or
|
|
37
|
+
* `_rels/.rels` is missing.
|
|
38
|
+
*/
|
|
13
39
|
static open(buffer: Uint8Array, options?: OpcOpenOptions): OpcPackage;
|
|
40
|
+
/** The bytes of the part at `path`, or undefined when absent. */
|
|
14
41
|
getPart(path: string): Uint8Array | undefined;
|
|
42
|
+
/**
|
|
43
|
+
* The bytes of the part at `path`.
|
|
44
|
+
*
|
|
45
|
+
* @throws Error when the part is absent.
|
|
46
|
+
*/
|
|
15
47
|
requirePart(path: string): Uint8Array;
|
|
48
|
+
/** Every part path in the package (ZIP convention, no leading slash). */
|
|
16
49
|
listParts(): Array<string>;
|
|
50
|
+
/**
|
|
51
|
+
* The relationships of the part at `partPath` (ECMA-376 Part 2 §9.3.4). For a
|
|
52
|
+
* part at `dir/name.ext` they live at `dir/_rels/name.ext.rels`. Returns `[]`
|
|
53
|
+
* if the rels part is absent. Parsed rels are cached per part.
|
|
54
|
+
*/
|
|
17
55
|
getPartRelationships(partPath: string): ReadonlyArray<Relationship>;
|
|
56
|
+
/**
|
|
57
|
+
* Resolve a relationship against its source part and return the related part's
|
|
58
|
+
* resolved path + data (Internal relationships only). External relationships
|
|
59
|
+
* (e.g. http hyperlinks) and unresolvable targets return undefined.
|
|
60
|
+
*/
|
|
18
61
|
resolveRelatedPart(sourcePartPath: string, relationship: Relationship): {
|
|
19
62
|
readonly path: string;
|
|
20
63
|
readonly data: Uint8Array;
|
|
21
64
|
} | undefined;
|
|
65
|
+
/**
|
|
66
|
+
* The path of the main document part, from the package's single
|
|
67
|
+
* `officeDocument` relationship (ECMA-376 Part 2 §11.1).
|
|
68
|
+
*
|
|
69
|
+
* @throws Error when there is no such relationship, or more than one.
|
|
70
|
+
*/
|
|
22
71
|
getMainDocumentPath(): string;
|
|
72
|
+
/**
|
|
73
|
+
* The main document part's path and bytes.
|
|
74
|
+
*
|
|
75
|
+
* @throws Error when the officeDocument relationship is missing/ambiguous or
|
|
76
|
+
* the part it points at is absent.
|
|
77
|
+
*/
|
|
23
78
|
getMainDocument(): {
|
|
24
79
|
path: string;
|
|
25
80
|
data: Uint8Array;
|
|
@@ -4,12 +4,29 @@ import { unzipSync } from "fflate";
|
|
|
4
4
|
//#region src/core/opc/package.ts
|
|
5
5
|
var ROOT_RELS_PATH = "_rels/.rels";
|
|
6
6
|
var MIB = 1024 * 1024;
|
|
7
|
+
/**
|
|
8
|
+
* An opened OPC package (ECMA-376 Part 2): a ZIP archive's parts plus its
|
|
9
|
+
* package-level relationships, with helpers to look up parts, resolve part
|
|
10
|
+
* relationships, and find the main document part.
|
|
11
|
+
*/
|
|
7
12
|
var OpcPackage = class OpcPackage {
|
|
13
|
+
/**
|
|
14
|
+
* @param parts The package parts keyed by ZIP-convention path (no leading slash).
|
|
15
|
+
* @param rootRelationships The package-level relationships from `_rels/.rels`.
|
|
16
|
+
*/
|
|
8
17
|
constructor(parts, rootRelationships) {
|
|
9
18
|
this.parts = parts;
|
|
10
19
|
this.rootRelationships = rootRelationships;
|
|
11
20
|
}
|
|
12
21
|
relsCache = /* @__PURE__ */ new Map();
|
|
22
|
+
/**
|
|
23
|
+
* Unzip and validate a package's bytes. Rejects an OLE compound file (an
|
|
24
|
+
* encrypted OOXML container or a legacy binary `.doc`/`.xls`) and enforces the
|
|
25
|
+
* zip-bomb caps from `options`.
|
|
26
|
+
*
|
|
27
|
+
* @throws Error when the bytes are not a ZIP package, a cap is exceeded, or
|
|
28
|
+
* `_rels/.rels` is missing.
|
|
29
|
+
*/
|
|
13
30
|
static open(buffer, options = {}) {
|
|
14
31
|
if (buffer.length >= 4 && buffer[0] === 208 && buffer[1] === 207 && buffer[2] === 17 && buffer[3] === 224) throw new Error("OLE compound file: a password-protected (encrypted) OOXML document or a legacy binary .doc/.xls — re-save as an unencrypted .docx/.xlsx");
|
|
15
32
|
const maxArchive = options.maxArchiveBytes ?? 128 * MIB;
|
|
@@ -43,17 +60,29 @@ var OpcPackage = class OpcPackage {
|
|
|
43
60
|
if (!relsBytes) throw new Error(`OPC package missing ${ROOT_RELS_PATH}`);
|
|
44
61
|
return new OpcPackage(parts, parseRelationships(relsBytes));
|
|
45
62
|
}
|
|
63
|
+
/** The bytes of the part at `path`, or undefined when absent. */
|
|
46
64
|
getPart(path) {
|
|
47
65
|
return this.parts.get(normalizePath(path));
|
|
48
66
|
}
|
|
67
|
+
/**
|
|
68
|
+
* The bytes of the part at `path`.
|
|
69
|
+
*
|
|
70
|
+
* @throws Error when the part is absent.
|
|
71
|
+
*/
|
|
49
72
|
requirePart(path) {
|
|
50
73
|
const data = this.getPart(path);
|
|
51
74
|
if (!data) throw new Error(`OPC part not found: ${path}`);
|
|
52
75
|
return data;
|
|
53
76
|
}
|
|
77
|
+
/** Every part path in the package (ZIP convention, no leading slash). */
|
|
54
78
|
listParts() {
|
|
55
79
|
return [...this.parts.keys()];
|
|
56
80
|
}
|
|
81
|
+
/**
|
|
82
|
+
* The relationships of the part at `partPath` (ECMA-376 Part 2 §9.3.4). For a
|
|
83
|
+
* part at `dir/name.ext` they live at `dir/_rels/name.ext.rels`. Returns `[]`
|
|
84
|
+
* if the rels part is absent. Parsed rels are cached per part.
|
|
85
|
+
*/
|
|
57
86
|
getPartRelationships(partPath) {
|
|
58
87
|
const normalized = normalizePath(partPath);
|
|
59
88
|
const cached = this.relsCache.get(normalized);
|
|
@@ -67,6 +96,11 @@ var OpcPackage = class OpcPackage {
|
|
|
67
96
|
this.relsCache.set(normalized, rels);
|
|
68
97
|
return rels;
|
|
69
98
|
}
|
|
99
|
+
/**
|
|
100
|
+
* Resolve a relationship against its source part and return the related part's
|
|
101
|
+
* resolved path + data (Internal relationships only). External relationships
|
|
102
|
+
* (e.g. http hyperlinks) and unresolvable targets return undefined.
|
|
103
|
+
*/
|
|
70
104
|
resolveRelatedPart(sourcePartPath, relationship) {
|
|
71
105
|
if (relationship.targetMode !== "Internal") return void 0;
|
|
72
106
|
const resolved = resolveTarget(`/${normalizePath(sourcePartPath)}`, relationship.target);
|
|
@@ -77,12 +111,24 @@ var OpcPackage = class OpcPackage {
|
|
|
77
111
|
data
|
|
78
112
|
};
|
|
79
113
|
}
|
|
114
|
+
/**
|
|
115
|
+
* The path of the main document part, from the package's single
|
|
116
|
+
* `officeDocument` relationship (ECMA-376 Part 2 §11.1).
|
|
117
|
+
*
|
|
118
|
+
* @throws Error when there is no such relationship, or more than one.
|
|
119
|
+
*/
|
|
80
120
|
getMainDocumentPath() {
|
|
81
121
|
const candidates = this.rootRelationships.filter((r) => isOoxmlRel(r.type, "officeDocument") && r.targetMode === "Internal");
|
|
82
122
|
if (candidates.length === 0) throw new Error("OPC package has no officeDocument relationship");
|
|
83
123
|
if (candidates.length > 1) throw new Error(`OPC package has multiple officeDocument relationships (${candidates.length})`);
|
|
84
124
|
return resolveTarget("/", candidates[0].target);
|
|
85
125
|
}
|
|
126
|
+
/**
|
|
127
|
+
* The main document part's path and bytes.
|
|
128
|
+
*
|
|
129
|
+
* @throws Error when the officeDocument relationship is missing/ambiguous or
|
|
130
|
+
* the part it points at is absent.
|
|
131
|
+
*/
|
|
86
132
|
getMainDocument() {
|
|
87
133
|
const path = this.getMainDocumentPath();
|
|
88
134
|
return {
|
|
@@ -1,4 +1,12 @@
|
|
|
1
|
+
/** Relationship Type URI of the package's main document part (officeDocument). */
|
|
1
2
|
export declare const REL_OFFICE_DOCUMENT = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument";
|
|
3
|
+
/** Relationship Type URI of the core-properties part (`docProps/core.xml`). */
|
|
2
4
|
export declare const REL_CORE_PROPERTIES = "http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties";
|
|
5
|
+
/** Relationship Type URI of the extended-properties part (`docProps/app.xml`). */
|
|
3
6
|
export declare const REL_EXTENDED_PROPERTIES = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties";
|
|
7
|
+
/**
|
|
8
|
+
* Whether a relationship `type` URI names the OOXML relationship `name` (e.g.
|
|
9
|
+
* `'officeDocument'`), matching against both the Transitional
|
|
10
|
+
* (`schemas.openxmlformats.org`) and Strict (`purl.oclc.org`) base URIs.
|
|
11
|
+
*/
|
|
4
12
|
export declare function isOoxmlRel(type: string, name: string): boolean;
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
//#region src/core/opc/relationship-types.ts
|
|
2
2
|
var OOXML_REL_BASES = ["http://schemas.openxmlformats.org/officeDocument/2006/relationships/", "http://purl.oclc.org/ooxml/officeDocument/relationships/"];
|
|
3
|
+
/**
|
|
4
|
+
* Whether a relationship `type` URI names the OOXML relationship `name` (e.g.
|
|
5
|
+
* `'officeDocument'`), matching against both the Transitional
|
|
6
|
+
* (`schemas.openxmlformats.org`) and Strict (`purl.oclc.org`) base URIs.
|
|
7
|
+
*/
|
|
3
8
|
function isOoxmlRel(type, name) {
|
|
4
9
|
return OOXML_REL_BASES.some((base) => type === base + name);
|
|
5
10
|
}
|
|
@@ -1,7 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One `<Relationship>` (ECMA-376 Part 2 §9.3): its id, Type URI, target, and
|
|
3
|
+
* whether the target is package-`Internal` or `External` (defaults to Internal
|
|
4
|
+
* when the attribute is absent).
|
|
5
|
+
*/
|
|
1
6
|
export interface Relationship {
|
|
2
7
|
readonly id: string;
|
|
3
8
|
readonly type: string;
|
|
4
9
|
readonly target: string;
|
|
5
10
|
readonly targetMode: 'Internal' | 'External';
|
|
6
11
|
}
|
|
12
|
+
/**
|
|
13
|
+
* Parse a relationships part (`_rels/*.rels`) into {@link Relationship}s.
|
|
14
|
+
* Tolerates a namespace prefix on the elements; returns `[]` when there are no
|
|
15
|
+
* relationships.
|
|
16
|
+
*
|
|
17
|
+
* @throws Error when a `<Relationship>` lacks a required `Id`/`Type`/`Target`.
|
|
18
|
+
*/
|
|
7
19
|
export declare function parseRelationships(data: Uint8Array): Array<Relationship>;
|
|
@@ -9,6 +9,13 @@ var parser = new XMLParser({
|
|
|
9
9
|
removeNSPrefix: true,
|
|
10
10
|
isArray: (tagName) => tagName === "Relationship"
|
|
11
11
|
});
|
|
12
|
+
/**
|
|
13
|
+
* Parse a relationships part (`_rels/*.rels`) into {@link Relationship}s.
|
|
14
|
+
* Tolerates a namespace prefix on the elements; returns `[]` when there are no
|
|
15
|
+
* relationships.
|
|
16
|
+
*
|
|
17
|
+
* @throws Error when a `<Relationship>` lacks a required `Id`/`Type`/`Target`.
|
|
18
|
+
*/
|
|
12
19
|
function parseRelationships(data) {
|
|
13
20
|
const xml = decoder.decode(data);
|
|
14
21
|
const list = parser.parse(xml).Relationships?.Relationship;
|
|
@@ -1,16 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One element node in a fast-xml-parser `preserveOrder` tree: a record with a
|
|
3
|
+
* single tag-name key (its children) plus an optional `:@` attributes object.
|
|
4
|
+
*/
|
|
1
5
|
export type PoNode = Record<string, unknown>;
|
|
6
|
+
/** An ordered list of sibling {@link PoNode}s (the parser's array form). */
|
|
2
7
|
export type PoTree = ReadonlyArray<PoNode>;
|
|
8
|
+
/** The element's tag name (the one key that is neither `:@` nor `#text`), or undefined. */
|
|
3
9
|
export declare function poTag(node: PoNode | undefined): string | undefined;
|
|
10
|
+
/** Whether the node's tag equals `tag` exactly (prefix-sensitive). */
|
|
4
11
|
export declare function poIs(node: PoNode | undefined, tag: string): boolean;
|
|
12
|
+
/** The node's child elements (the value under its tag key), or `[]`. */
|
|
5
13
|
export declare function poChildren(node: PoNode | undefined): ReadonlyArray<PoNode>;
|
|
14
|
+
/** The node's direct children with tag `tag`. */
|
|
6
15
|
export declare function poChildrenWith(node: PoNode | undefined, tag: string): Array<PoNode>;
|
|
16
|
+
/** The node's first direct child with tag `tag`, or undefined. */
|
|
7
17
|
export declare function poFirstChild(node: PoNode | undefined, tag: string): PoNode | undefined;
|
|
18
|
+
/**
|
|
19
|
+
* An attribute value by local `name`, trying the common OOXML namespace prefixes
|
|
20
|
+
* (`w:`/`r:`/`m:`/`xml:`, then bare) in priority order. Returns undefined when
|
|
21
|
+
* absent or non-string.
|
|
22
|
+
*/
|
|
8
23
|
export declare function poAttr(node: PoNode | undefined, name: string): string | undefined;
|
|
24
|
+
/**
|
|
25
|
+
* Like `poAttr` but matches by LOCAL name regardless of the prefix — for vendor
|
|
26
|
+
* extensions whose namespace `poAttr` does not special-case (e.g. `w14:paraId`,
|
|
27
|
+
* `w15:done`, `w15:paraIdParent`).
|
|
28
|
+
*/
|
|
9
29
|
export declare function poAttrLocal(node: PoNode | undefined, name: string): string | undefined;
|
|
30
|
+
/**
|
|
31
|
+
* Like `poIs` but matches a tag by LOCAL name, so an element authored under any
|
|
32
|
+
* prefix (`w15:commentsEx`, `mc:commentsEx`, …) still resolves.
|
|
33
|
+
*/
|
|
10
34
|
export declare function poIsLocal(node: PoNode | undefined, name: string): boolean;
|
|
35
|
+
/** {@link poAttr} parsed as a finite number, or undefined when absent/non-numeric. */
|
|
11
36
|
export declare function poIntAttr(node: PoNode | undefined, name: string): number | undefined;
|
|
37
|
+
/** Shorthand for the `val` attribute (`@w:val`/…). */
|
|
12
38
|
export declare function poVal(node: PoNode | undefined): string | undefined;
|
|
39
|
+
/**
|
|
40
|
+
* Read an OOXML boolean toggle property (§17.17.4): a present element with no
|
|
41
|
+
* `val` (or `val` true/1/on) is `true`; `false`/`0`/`off` is `false`; an absent
|
|
42
|
+
* element (`node` undefined) is undefined ("inherit").
|
|
43
|
+
*/
|
|
13
44
|
export declare function poToggle(node: PoNode | undefined): boolean | undefined;
|
|
45
|
+
/** Concatenate the node's direct `#text` leaf children into a single string. */
|
|
14
46
|
export declare function poText(node: PoNode | undefined): string;
|
|
47
|
+
/**
|
|
48
|
+
* Walk a chain of tags from the tree root, descending into the first child that
|
|
49
|
+
* matches each successive `path` segment. Returns the node at the path end, or
|
|
50
|
+
* undefined if any segment is missing.
|
|
51
|
+
*/
|
|
15
52
|
export declare function poFindByPath(tree: PoTree, path: ReadonlyArray<string>): PoNode | undefined;
|
|
53
|
+
/** Depth-first search for the first descendant with the given `tag`. */
|
|
16
54
|
export declare function poFindDescendant(node: PoNode | undefined, tag: string): PoNode | undefined;
|
|
@@ -1,25 +1,35 @@
|
|
|
1
1
|
//#region src/core/po-helpers.ts
|
|
2
2
|
var ATTRS_KEY = ":@";
|
|
3
3
|
var TEXT_KEY = "#text";
|
|
4
|
+
/** The element's tag name (the one key that is neither `:@` nor `#text`), or undefined. */
|
|
4
5
|
function poTag(node) {
|
|
5
6
|
if (!node || typeof node !== "object") return void 0;
|
|
6
7
|
for (const key of Object.keys(node)) if (key !== ATTRS_KEY && key !== TEXT_KEY) return key;
|
|
7
8
|
}
|
|
9
|
+
/** Whether the node's tag equals `tag` exactly (prefix-sensitive). */
|
|
8
10
|
function poIs(node, tag) {
|
|
9
11
|
return poTag(node) === tag;
|
|
10
12
|
}
|
|
13
|
+
/** The node's child elements (the value under its tag key), or `[]`. */
|
|
11
14
|
function poChildren(node) {
|
|
12
15
|
const tag = poTag(node);
|
|
13
16
|
if (!tag || !node) return [];
|
|
14
17
|
const arr = node[tag];
|
|
15
18
|
return Array.isArray(arr) ? arr : [];
|
|
16
19
|
}
|
|
20
|
+
/** The node's direct children with tag `tag`. */
|
|
17
21
|
function poChildrenWith(node, tag) {
|
|
18
22
|
return poChildren(node).filter((c) => poIs(c, tag));
|
|
19
23
|
}
|
|
24
|
+
/** The node's first direct child with tag `tag`, or undefined. */
|
|
20
25
|
function poFirstChild(node, tag) {
|
|
21
26
|
return poChildren(node).find((c) => poIs(c, tag));
|
|
22
27
|
}
|
|
28
|
+
/**
|
|
29
|
+
* An attribute value by local `name`, trying the common OOXML namespace prefixes
|
|
30
|
+
* (`w:`/`r:`/`m:`/`xml:`, then bare) in priority order. Returns undefined when
|
|
31
|
+
* absent or non-string.
|
|
32
|
+
*/
|
|
23
33
|
function poAttr(node, name) {
|
|
24
34
|
if (!node || typeof node !== "object") return void 0;
|
|
25
35
|
const attrs = node[ATTRS_KEY];
|
|
@@ -28,6 +38,11 @@ function poAttr(node, name) {
|
|
|
28
38
|
const v = a[`@_w:${name}`] ?? a[`@_r:${name}`] ?? a[`@_m:${name}`] ?? a[`@_xml:${name}`] ?? a[`@_${name}`];
|
|
29
39
|
return typeof v === "string" ? v : void 0;
|
|
30
40
|
}
|
|
41
|
+
/**
|
|
42
|
+
* Like `poAttr` but matches by LOCAL name regardless of the prefix — for vendor
|
|
43
|
+
* extensions whose namespace `poAttr` does not special-case (e.g. `w14:paraId`,
|
|
44
|
+
* `w15:done`, `w15:paraIdParent`).
|
|
45
|
+
*/
|
|
31
46
|
function poAttrLocal(node, name) {
|
|
32
47
|
if (!node || typeof node !== "object") return void 0;
|
|
33
48
|
const attrs = node[ATTRS_KEY];
|
|
@@ -37,25 +52,37 @@ function poAttrLocal(node, name) {
|
|
|
37
52
|
if (k.slice(2).split(":").pop() === name && typeof v === "string") return v;
|
|
38
53
|
}
|
|
39
54
|
}
|
|
55
|
+
/**
|
|
56
|
+
* Like `poIs` but matches a tag by LOCAL name, so an element authored under any
|
|
57
|
+
* prefix (`w15:commentsEx`, `mc:commentsEx`, …) still resolves.
|
|
58
|
+
*/
|
|
40
59
|
function poIsLocal(node, name) {
|
|
41
60
|
const tag = poTag(node);
|
|
42
61
|
return tag !== void 0 && (tag === name || tag.split(":").pop() === name);
|
|
43
62
|
}
|
|
63
|
+
/** {@link poAttr} parsed as a finite number, or undefined when absent/non-numeric. */
|
|
44
64
|
function poIntAttr(node, name) {
|
|
45
65
|
const v = poAttr(node, name);
|
|
46
66
|
if (v === void 0) return void 0;
|
|
47
67
|
const n = Number(v);
|
|
48
68
|
return Number.isFinite(n) ? n : void 0;
|
|
49
69
|
}
|
|
70
|
+
/** Shorthand for the `val` attribute (`@w:val`/…). */
|
|
50
71
|
function poVal(node) {
|
|
51
72
|
return poAttr(node, "val");
|
|
52
73
|
}
|
|
74
|
+
/**
|
|
75
|
+
* Read an OOXML boolean toggle property (§17.17.4): a present element with no
|
|
76
|
+
* `val` (or `val` true/1/on) is `true`; `false`/`0`/`off` is `false`; an absent
|
|
77
|
+
* element (`node` undefined) is undefined ("inherit").
|
|
78
|
+
*/
|
|
53
79
|
function poToggle(node) {
|
|
54
80
|
if (!node) return void 0;
|
|
55
81
|
const v = poAttr(node, "val");
|
|
56
82
|
if (v === void 0) return true;
|
|
57
83
|
return !(v === "false" || v === "0" || v === "off");
|
|
58
84
|
}
|
|
85
|
+
/** Concatenate the node's direct `#text` leaf children into a single string. */
|
|
59
86
|
function poText(node) {
|
|
60
87
|
if (!node) return "";
|
|
61
88
|
const children = poChildren(node);
|
|
@@ -67,6 +94,11 @@ function poText(node) {
|
|
|
67
94
|
}
|
|
68
95
|
return out;
|
|
69
96
|
}
|
|
97
|
+
/**
|
|
98
|
+
* Walk a chain of tags from the tree root, descending into the first child that
|
|
99
|
+
* matches each successive `path` segment. Returns the node at the path end, or
|
|
100
|
+
* undefined if any segment is missing.
|
|
101
|
+
*/
|
|
70
102
|
function poFindByPath(tree, path) {
|
|
71
103
|
let cursor = tree;
|
|
72
104
|
let current;
|
|
@@ -77,6 +109,7 @@ function poFindByPath(tree, path) {
|
|
|
77
109
|
}
|
|
78
110
|
return current;
|
|
79
111
|
}
|
|
112
|
+
/** Depth-first search for the first descendant with the given `tag`. */
|
|
80
113
|
function poFindDescendant(node, tag) {
|
|
81
114
|
if (!node) return void 0;
|
|
82
115
|
for (const child of poChildren(node)) {
|