@cj-tech-master/excelts 9.4.2 → 9.5.0
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/browser/index.browser.d.ts +8 -5
- package/dist/browser/index.browser.js +19 -1
- package/dist/browser/index.d.ts +4 -2
- package/dist/browser/index.js +9 -1
- package/dist/browser/modules/excel/chart/cache-populator.d.ts +49 -0
- package/dist/browser/modules/excel/chart/cache-populator.js +1171 -0
- package/dist/browser/modules/excel/chart/chart-api.d.ts +92 -0
- package/dist/browser/modules/excel/chart/chart-api.js +364 -0
- package/dist/browser/modules/excel/chart/chart-builder.d.ts +48 -0
- package/dist/browser/modules/excel/chart/chart-builder.js +2432 -0
- package/dist/browser/modules/excel/chart/chart-ex-builder.d.ts +36 -0
- package/dist/browser/modules/excel/chart/chart-ex-builder.js +903 -0
- package/dist/browser/modules/excel/chart/chart-ex-parser.d.ts +8 -0
- package/dist/browser/modules/excel/chart/chart-ex-parser.js +1205 -0
- package/dist/browser/modules/excel/chart/chart-ex-renderer.d.ts +187 -0
- package/dist/browser/modules/excel/chart/chart-ex-renderer.js +5352 -0
- package/dist/browser/modules/excel/chart/chart-ex-types.d.ts +531 -0
- package/dist/browser/modules/excel/chart/chart-ex-types.js +11 -0
- package/dist/browser/modules/excel/chart/chart-images.d.ts +78 -0
- package/dist/browser/modules/excel/chart/chart-images.js +363 -0
- package/dist/browser/modules/excel/chart/chart-presets.d.ts +392 -0
- package/dist/browser/modules/excel/chart/chart-presets.js +179 -0
- package/dist/browser/modules/excel/chart/chart-renderer.d.ts +550 -0
- package/dist/browser/modules/excel/chart/chart-renderer.js +6440 -0
- package/dist/browser/modules/excel/chart/chart-sidecar.d.ts +21 -0
- package/dist/browser/modules/excel/chart/chart-sidecar.js +427 -0
- package/dist/browser/modules/excel/chart/chart-utils.d.ts +306 -0
- package/dist/browser/modules/excel/chart/chart-utils.js +821 -0
- package/dist/browser/modules/excel/chart/chart.d.ts +504 -0
- package/dist/browser/modules/excel/chart/chart.js +1320 -0
- package/dist/browser/modules/excel/chart/glyph-rasterizer.d.ts +62 -0
- package/dist/browser/modules/excel/chart/glyph-rasterizer.js +658 -0
- package/dist/browser/modules/excel/chart/index.d.ts +54 -0
- package/dist/browser/modules/excel/chart/index.js +46 -0
- package/dist/browser/modules/excel/chart/install.d.ts +44 -0
- package/dist/browser/modules/excel/chart/install.js +91 -0
- package/dist/browser/modules/excel/chart/shape-properties.d.ts +156 -0
- package/dist/browser/modules/excel/chart/shape-properties.js +1557 -0
- package/dist/browser/modules/excel/chart/stroke-font.d.ts +36 -0
- package/dist/browser/modules/excel/chart/stroke-font.js +1556 -0
- package/dist/browser/modules/excel/chart/topojson.d.ts +98 -0
- package/dist/browser/modules/excel/chart/topojson.js +236 -0
- package/dist/browser/modules/excel/chart/types.d.ts +2559 -0
- package/dist/browser/modules/excel/chart/types.js +8 -0
- package/dist/browser/modules/excel/chart-host-registry.d.ts +157 -0
- package/dist/browser/modules/excel/chart-host-registry.js +90 -0
- package/dist/browser/modules/excel/chartsheet.d.ts +102 -0
- package/dist/browser/modules/excel/chartsheet.js +196 -0
- package/dist/browser/modules/excel/defined-names.d.ts +35 -0
- package/dist/browser/modules/excel/defined-names.js +44 -4
- package/dist/browser/modules/excel/errors.d.ts +6 -0
- package/dist/browser/modules/excel/errors.js +9 -0
- package/dist/browser/modules/excel/form-control.d.ts +6 -0
- package/dist/browser/modules/excel/form-control.js +17 -0
- package/dist/browser/modules/excel/image.js +12 -2
- package/dist/browser/modules/excel/pivot-chart.d.ts +7 -0
- package/dist/browser/modules/excel/pivot-chart.js +53 -0
- package/dist/browser/modules/excel/pivot-table.d.ts +55 -0
- package/dist/browser/modules/excel/pivot-table.js +35 -0
- package/dist/browser/modules/excel/range.js +5 -1
- package/dist/browser/modules/excel/sparkline/index.d.ts +7 -0
- package/dist/browser/modules/excel/sparkline/index.js +7 -0
- package/dist/browser/modules/excel/sparkline/sparkline.d.ts +206 -0
- package/dist/browser/modules/excel/sparkline/sparkline.js +750 -0
- package/dist/browser/modules/excel/stream/worksheet-writer.js +3 -2
- package/dist/browser/modules/excel/table.js +42 -6
- package/dist/browser/modules/excel/types.d.ts +72 -0
- package/dist/browser/modules/excel/utils/address.d.ts +18 -0
- package/dist/browser/modules/excel/utils/address.js +28 -0
- package/dist/browser/modules/excel/utils/drawing-utils.js +11 -6
- package/dist/browser/modules/excel/utils/guid.d.ts +15 -0
- package/dist/browser/modules/excel/utils/guid.js +35 -0
- package/dist/browser/modules/excel/utils/ooxml-paths.d.ts +74 -0
- package/dist/browser/modules/excel/utils/ooxml-paths.js +206 -9
- package/dist/browser/modules/excel/utils/ooxml-validator/check-chart-sidecar.d.ts +35 -0
- package/dist/browser/modules/excel/utils/ooxml-validator/check-chart-sidecar.js +101 -0
- package/dist/browser/modules/excel/utils/ooxml-validator/check-chart.d.ts +32 -0
- package/dist/browser/modules/excel/utils/ooxml-validator/check-chart.js +2125 -0
- package/dist/browser/modules/excel/utils/ooxml-validator/check-chartsheet.d.ts +9 -0
- package/dist/browser/modules/excel/utils/ooxml-validator/check-chartsheet.js +26 -0
- package/dist/browser/modules/excel/utils/ooxml-validator/check-content-types.d.ts +16 -0
- package/dist/browser/modules/excel/utils/ooxml-validator/check-content-types.js +181 -0
- package/dist/browser/modules/excel/utils/ooxml-validator/check-drawing.d.ts +34 -0
- package/dist/browser/modules/excel/utils/ooxml-validator/check-drawing.js +267 -0
- package/dist/browser/modules/excel/utils/ooxml-validator/check-pivot.d.ts +14 -0
- package/dist/browser/modules/excel/utils/ooxml-validator/check-pivot.js +104 -0
- package/dist/browser/modules/excel/utils/ooxml-validator/check-relationships.d.ts +18 -0
- package/dist/browser/modules/excel/utils/ooxml-validator/check-relationships.js +184 -0
- package/dist/browser/modules/excel/utils/ooxml-validator/check-structure.d.ts +21 -0
- package/dist/browser/modules/excel/utils/ooxml-validator/check-structure.js +56 -0
- package/dist/browser/modules/excel/utils/ooxml-validator/check-styles.d.ts +15 -0
- package/dist/browser/modules/excel/utils/ooxml-validator/check-styles.js +89 -0
- package/dist/browser/modules/excel/utils/ooxml-validator/check-table.d.ts +31 -0
- package/dist/browser/modules/excel/utils/ooxml-validator/check-table.js +177 -0
- package/dist/browser/modules/excel/utils/ooxml-validator/check-workbook.d.ts +19 -0
- package/dist/browser/modules/excel/utils/ooxml-validator/check-workbook.js +163 -0
- package/dist/browser/modules/excel/utils/ooxml-validator/check-worksheet.d.ts +25 -0
- package/dist/browser/modules/excel/utils/ooxml-validator/check-worksheet.js +569 -0
- package/dist/browser/modules/excel/utils/ooxml-validator/context.d.ts +85 -0
- package/dist/browser/modules/excel/utils/ooxml-validator/context.js +191 -0
- package/dist/browser/modules/excel/utils/ooxml-validator/index.d.ts +31 -0
- package/dist/browser/modules/excel/utils/ooxml-validator/index.js +102 -0
- package/dist/browser/modules/excel/utils/ooxml-validator/path-utils.d.ts +67 -0
- package/dist/browser/modules/excel/utils/ooxml-validator/path-utils.js +156 -0
- package/dist/browser/modules/excel/utils/ooxml-validator/reporter.d.ts +41 -0
- package/dist/browser/modules/excel/utils/ooxml-validator/reporter.js +61 -0
- package/dist/browser/modules/excel/utils/ooxml-validator/types.d.ts +109 -0
- package/dist/browser/modules/excel/utils/ooxml-validator/types.js +12 -0
- package/dist/browser/modules/excel/utils/ooxml-validator/xml-utils.d.ts +38 -0
- package/dist/browser/modules/excel/utils/ooxml-validator/xml-utils.js +100 -0
- package/dist/browser/modules/excel/workbook.browser.d.ts +248 -30
- package/dist/browser/modules/excel/workbook.browser.js +966 -31
- package/dist/browser/modules/excel/workbook.d.ts +43 -0
- package/dist/browser/modules/excel/workbook.js +48 -0
- package/dist/browser/modules/excel/worksheet.d.ts +157 -3
- package/dist/browser/modules/excel/worksheet.js +394 -35
- package/dist/browser/modules/excel/xlsx/rel-type.d.ts +40 -0
- package/dist/browser/modules/excel/xlsx/rel-type.js +41 -1
- package/dist/browser/modules/excel/xlsx/xform/book/defined-name-xform.d.ts +1 -0
- package/dist/browser/modules/excel/xlsx/xform/book/defined-name-xform.js +11 -2
- package/dist/browser/modules/excel/xlsx/xform/book/external-link-xform.js +12 -10
- package/dist/browser/modules/excel/xlsx/xform/book/workbook-xform.js +96 -22
- package/dist/browser/modules/excel/xlsx/xform/chart/chart-space-xform.d.ts +353 -0
- package/dist/browser/modules/excel/xlsx/xform/chart/chart-space-xform.js +6000 -0
- package/dist/browser/modules/excel/xlsx/xform/comment/threaded-comments-xform.d.ts +60 -0
- package/dist/browser/modules/excel/xlsx/xform/comment/threaded-comments-xform.js +213 -0
- package/dist/browser/modules/excel/xlsx/xform/core/content-types-xform.js +150 -11
- package/dist/browser/modules/excel/xlsx/xform/drawing/absolute-anchor-xform.js +20 -1
- package/dist/browser/modules/excel/xlsx/xform/drawing/base-cell-anchor-xform.js +1 -1
- package/dist/browser/modules/excel/xlsx/xform/drawing/drawing-xform.d.ts +30 -0
- package/dist/browser/modules/excel/xlsx/xform/drawing/drawing-xform.js +109 -5
- package/dist/browser/modules/excel/xlsx/xform/drawing/graphic-frame-xform.d.ts +54 -0
- package/dist/browser/modules/excel/xlsx/xform/drawing/graphic-frame-xform.js +225 -0
- package/dist/browser/modules/excel/xlsx/xform/drawing/one-cell-anchor-xform.d.ts +3 -1
- package/dist/browser/modules/excel/xlsx/xform/drawing/one-cell-anchor-xform.js +18 -3
- package/dist/browser/modules/excel/xlsx/xform/drawing/two-cell-anchor-xform.d.ts +46 -0
- package/dist/browser/modules/excel/xlsx/xform/drawing/two-cell-anchor-xform.js +294 -12
- package/dist/browser/modules/excel/xlsx/xform/pivot-table/pivot-table-xform.d.ts +13 -2
- package/dist/browser/modules/excel/xlsx/xform/pivot-table/pivot-table-xform.js +32 -6
- package/dist/browser/modules/excel/xlsx/xform/sheet/chartsheet-xform.d.ts +185 -0
- package/dist/browser/modules/excel/xlsx/xform/sheet/chartsheet-xform.js +441 -0
- package/dist/browser/modules/excel/xlsx/xform/sheet/ext-lst-xform.d.ts +1 -0
- package/dist/browser/modules/excel/xlsx/xform/sheet/ext-lst-xform.js +51 -2
- package/dist/browser/modules/excel/xlsx/xform/sheet/worksheet-xform.js +196 -20
- package/dist/browser/modules/excel/xlsx/xform/table/auto-filter-xform.js +16 -1
- package/dist/browser/modules/excel/xlsx/xform/table/table-column-xform.js +17 -2
- package/dist/browser/modules/excel/xlsx/xform/xsd-values.d.ts +63 -0
- package/dist/browser/modules/excel/xlsx/xform/xsd-values.js +101 -0
- package/dist/browser/modules/excel/xlsx/xlsx.browser.d.ts +115 -21
- package/dist/browser/modules/excel/xlsx/xlsx.browser.js +4422 -78
- package/dist/browser/modules/pdf/builder/document-builder.d.ts +74 -0
- package/dist/browser/modules/pdf/builder/document-builder.js +507 -2
- package/dist/browser/modules/pdf/builder/pdf-editor.js +48 -3
- package/dist/browser/modules/pdf/excel-bridge.d.ts +69 -0
- package/dist/browser/modules/pdf/excel-bridge.js +683 -12
- package/dist/browser/modules/pdf/font/font-manager.d.ts +25 -0
- package/dist/browser/modules/pdf/font/font-manager.js +39 -0
- package/dist/browser/modules/pdf/index.d.ts +5 -2
- package/dist/browser/modules/pdf/index.js +3 -1
- package/dist/browser/modules/pdf/render/chart-surface.d.ts +33 -0
- package/dist/browser/modules/pdf/render/chart-surface.js +200 -0
- package/dist/browser/modules/pdf/render/layout-engine.d.ts +22 -1
- package/dist/browser/modules/pdf/render/layout-engine.js +436 -56
- package/dist/browser/modules/pdf/render/page-renderer.js +169 -28
- package/dist/browser/modules/pdf/render/pdf-exporter.js +117 -7
- package/dist/browser/modules/pdf/types.d.ts +227 -23
- package/dist/browser/modules/pdf/types.js +4 -0
- package/dist/browser/modules/pdf/word-bridge.d.ts +47 -0
- package/dist/browser/modules/pdf/word-bridge.js +304 -0
- package/dist/browser/modules/word/constants.d.ts +179 -0
- package/dist/browser/modules/word/constants.js +231 -0
- package/dist/browser/modules/word/content-types.d.ts +27 -0
- package/dist/browser/modules/word/content-types.js +53 -0
- package/dist/browser/modules/word/digital-signatures.d.ts +87 -0
- package/dist/browser/modules/word/digital-signatures.js +134 -0
- package/dist/browser/modules/word/document.d.ts +728 -0
- package/dist/browser/modules/word/document.js +1795 -0
- package/dist/browser/modules/word/docx-packager.d.ts +14 -0
- package/dist/browser/modules/word/docx-packager.js +822 -0
- package/dist/browser/modules/word/docx-reader.d.ts +11 -0
- package/dist/browser/modules/word/docx-reader.js +4929 -0
- package/dist/browser/modules/word/encryption.d.ts +102 -0
- package/dist/browser/modules/word/encryption.js +274 -0
- package/dist/browser/modules/word/errors.d.ts +49 -0
- package/dist/browser/modules/word/errors.js +68 -0
- package/dist/browser/modules/word/font-obfuscation.d.ts +31 -0
- package/dist/browser/modules/word/font-obfuscation.js +83 -0
- package/dist/browser/modules/word/html-renderer.d.ts +38 -0
- package/dist/browser/modules/word/html-renderer.js +782 -0
- package/dist/browser/modules/word/index.base.d.ts +19 -0
- package/dist/browser/modules/word/index.base.js +51 -0
- package/dist/browser/modules/word/index.browser.d.ts +4 -0
- package/dist/browser/modules/word/index.browser.js +4 -0
- package/dist/browser/modules/word/index.d.ts +4 -0
- package/dist/browser/modules/word/index.js +4 -0
- package/dist/browser/modules/word/internal-utils.d.ts +23 -0
- package/dist/browser/modules/word/internal-utils.js +54 -0
- package/dist/browser/modules/word/relationships.d.ts +31 -0
- package/dist/browser/modules/word/relationships.js +56 -0
- package/dist/browser/modules/word/types.d.ts +2325 -0
- package/dist/browser/modules/word/types.js +10 -0
- package/dist/browser/modules/word/units.d.ts +49 -0
- package/dist/browser/modules/word/units.js +111 -0
- package/dist/browser/modules/word/writers/chart-writer.d.ts +10 -0
- package/dist/browser/modules/word/writers/chart-writer.js +385 -0
- package/dist/browser/modules/word/writers/checkbox-writer.d.ts +9 -0
- package/dist/browser/modules/word/writers/checkbox-writer.js +42 -0
- package/dist/browser/modules/word/writers/comment-writer.d.ts +15 -0
- package/dist/browser/modules/word/writers/comment-writer.js +70 -0
- package/dist/browser/modules/word/writers/document-writer.d.ts +16 -0
- package/dist/browser/modules/word/writers/document-writer.js +461 -0
- package/dist/browser/modules/word/writers/footnote-writer.d.ts +11 -0
- package/dist/browser/modules/word/writers/footnote-writer.js +72 -0
- package/dist/browser/modules/word/writers/header-footer-writer.d.ts +13 -0
- package/dist/browser/modules/word/writers/header-footer-writer.js +129 -0
- package/dist/browser/modules/word/writers/image-writer.d.ts +10 -0
- package/dist/browser/modules/word/writers/image-writer.js +185 -0
- package/dist/browser/modules/word/writers/math-writer.d.ts +9 -0
- package/dist/browser/modules/word/writers/math-writer.js +428 -0
- package/dist/browser/modules/word/writers/numbering-writer.d.ts +10 -0
- package/dist/browser/modules/word/writers/numbering-writer.js +125 -0
- package/dist/browser/modules/word/writers/paragraph-writer.d.ts +13 -0
- package/dist/browser/modules/word/writers/paragraph-writer.js +516 -0
- package/dist/browser/modules/word/writers/parts-writer.d.ts +26 -0
- package/dist/browser/modules/word/writers/parts-writer.js +660 -0
- package/dist/browser/modules/word/writers/run-writer.d.ts +15 -0
- package/dist/browser/modules/word/writers/run-writer.js +649 -0
- package/dist/browser/modules/word/writers/section-writer.d.ts +10 -0
- package/dist/browser/modules/word/writers/section-writer.js +238 -0
- package/dist/browser/modules/word/writers/styles-writer.d.ts +10 -0
- package/dist/browser/modules/word/writers/styles-writer.js +242 -0
- package/dist/browser/modules/word/writers/table-writer.d.ts +10 -0
- package/dist/browser/modules/word/writers/table-writer.js +503 -0
- package/dist/browser/modules/word/writers/textbox-writer.d.ts +9 -0
- package/dist/browser/modules/word/writers/textbox-writer.js +53 -0
- package/dist/browser/modules/word/writers/toc-writer.d.ts +9 -0
- package/dist/browser/modules/word/writers/toc-writer.js +79 -0
- package/dist/browser/modules/xml/encode.d.ts +56 -7
- package/dist/browser/modules/xml/encode.js +157 -11
- package/dist/cjs/index.js +13 -2
- package/dist/cjs/modules/excel/chart/cache-populator.js +1178 -0
- package/dist/cjs/modules/excel/chart/chart-api.js +371 -0
- package/dist/cjs/modules/excel/chart/chart-builder.js +2440 -0
- package/dist/cjs/modules/excel/chart/chart-ex-builder.js +907 -0
- package/dist/cjs/modules/excel/chart/chart-ex-parser.js +1208 -0
- package/dist/cjs/modules/excel/chart/chart-ex-renderer.js +5364 -0
- package/dist/cjs/modules/excel/chart/chart-ex-types.js +12 -0
- package/dist/cjs/modules/excel/chart/chart-images.js +366 -0
- package/dist/cjs/modules/excel/chart/chart-presets.js +184 -0
- package/dist/cjs/modules/excel/chart/chart-renderer.js +6450 -0
- package/dist/cjs/modules/excel/chart/chart-sidecar.js +433 -0
- package/dist/cjs/modules/excel/chart/chart-utils.js +845 -0
- package/dist/cjs/modules/excel/chart/chart.js +1324 -0
- package/dist/cjs/modules/excel/chart/glyph-rasterizer.js +664 -0
- package/dist/cjs/modules/excel/chart/index.js +101 -0
- package/dist/cjs/modules/excel/chart/install.js +95 -0
- package/dist/cjs/modules/excel/chart/shape-properties.js +1577 -0
- package/dist/cjs/modules/excel/chart/stroke-font.js +1559 -0
- package/dist/cjs/modules/excel/chart/topojson.js +239 -0
- package/dist/cjs/modules/excel/chart/types.js +9 -0
- package/dist/cjs/modules/excel/chart-host-registry.js +96 -0
- package/dist/cjs/modules/excel/chartsheet.js +199 -0
- package/dist/cjs/modules/excel/defined-names.js +44 -4
- package/dist/cjs/modules/excel/errors.js +11 -1
- package/dist/cjs/modules/excel/form-control.js +17 -0
- package/dist/cjs/modules/excel/image.js +12 -2
- package/dist/cjs/modules/excel/pivot-chart.js +56 -0
- package/dist/cjs/modules/excel/pivot-table.js +35 -0
- package/dist/cjs/modules/excel/range.js +5 -1
- package/dist/cjs/modules/excel/sparkline/index.js +23 -0
- package/dist/cjs/modules/excel/sparkline/sparkline.js +756 -0
- package/dist/cjs/modules/excel/stream/worksheet-writer.js +3 -2
- package/dist/cjs/modules/excel/table.js +42 -6
- package/dist/cjs/modules/excel/utils/address.js +29 -0
- package/dist/cjs/modules/excel/utils/drawing-utils.js +11 -6
- package/dist/cjs/modules/excel/utils/guid.js +38 -0
- package/dist/cjs/modules/excel/utils/ooxml-paths.js +246 -9
- package/dist/cjs/modules/excel/utils/ooxml-validator/check-chart-sidecar.js +103 -0
- package/dist/cjs/modules/excel/utils/ooxml-validator/check-chart.js +2128 -0
- package/dist/cjs/modules/excel/utils/ooxml-validator/check-chartsheet.js +29 -0
- package/dist/cjs/modules/excel/utils/ooxml-validator/check-content-types.js +184 -0
- package/dist/cjs/modules/excel/utils/ooxml-validator/check-drawing.js +270 -0
- package/dist/cjs/modules/excel/utils/ooxml-validator/check-pivot.js +107 -0
- package/dist/cjs/modules/excel/utils/ooxml-validator/check-relationships.js +188 -0
- package/dist/cjs/modules/excel/utils/ooxml-validator/check-structure.js +60 -0
- package/dist/cjs/modules/excel/utils/ooxml-validator/check-styles.js +92 -0
- package/dist/cjs/modules/excel/utils/ooxml-validator/check-table.js +180 -0
- package/dist/cjs/modules/excel/utils/ooxml-validator/check-workbook.js +166 -0
- package/dist/cjs/modules/excel/utils/ooxml-validator/check-worksheet.js +572 -0
- package/dist/cjs/modules/excel/utils/ooxml-validator/context.js +196 -0
- package/dist/cjs/modules/excel/utils/ooxml-validator/index.js +105 -0
- package/dist/cjs/modules/excel/utils/ooxml-validator/path-utils.js +168 -0
- package/dist/cjs/modules/excel/utils/ooxml-validator/reporter.js +66 -0
- package/dist/cjs/modules/excel/utils/ooxml-validator/types.js +13 -0
- package/dist/cjs/modules/excel/utils/ooxml-validator/xml-utils.js +110 -0
- package/dist/cjs/modules/excel/workbook.browser.js +973 -38
- package/dist/cjs/modules/excel/workbook.js +48 -0
- package/dist/cjs/modules/excel/worksheet.js +393 -34
- package/dist/cjs/modules/excel/xlsx/rel-type.js +41 -1
- package/dist/cjs/modules/excel/xlsx/xform/book/defined-name-xform.js +11 -2
- package/dist/cjs/modules/excel/xlsx/xform/book/external-link-xform.js +12 -10
- package/dist/cjs/modules/excel/xlsx/xform/book/workbook-xform.js +96 -22
- package/dist/cjs/modules/excel/xlsx/xform/chart/chart-space-xform.js +6003 -0
- package/dist/cjs/modules/excel/xlsx/xform/comment/threaded-comments-xform.js +219 -0
- package/dist/cjs/modules/excel/xlsx/xform/core/content-types-xform.js +149 -10
- package/dist/cjs/modules/excel/xlsx/xform/drawing/absolute-anchor-xform.js +20 -1
- package/dist/cjs/modules/excel/xlsx/xform/drawing/base-cell-anchor-xform.js +1 -1
- package/dist/cjs/modules/excel/xlsx/xform/drawing/drawing-xform.js +109 -5
- package/dist/cjs/modules/excel/xlsx/xform/drawing/graphic-frame-xform.js +228 -0
- package/dist/cjs/modules/excel/xlsx/xform/drawing/one-cell-anchor-xform.js +18 -3
- package/dist/cjs/modules/excel/xlsx/xform/drawing/two-cell-anchor-xform.js +294 -12
- package/dist/cjs/modules/excel/xlsx/xform/pivot-table/pivot-table-xform.js +32 -6
- package/dist/cjs/modules/excel/xlsx/xform/sheet/chartsheet-xform.js +444 -0
- package/dist/cjs/modules/excel/xlsx/xform/sheet/ext-lst-xform.js +51 -2
- package/dist/cjs/modules/excel/xlsx/xform/sheet/worksheet-xform.js +195 -19
- package/dist/cjs/modules/excel/xlsx/xform/table/auto-filter-xform.js +16 -1
- package/dist/cjs/modules/excel/xlsx/xform/table/table-column-xform.js +17 -2
- package/dist/cjs/modules/excel/xlsx/xform/xsd-values.js +106 -0
- package/dist/cjs/modules/excel/xlsx/xlsx.browser.js +4420 -76
- package/dist/cjs/modules/pdf/builder/document-builder.js +506 -1
- package/dist/cjs/modules/pdf/builder/pdf-editor.js +48 -3
- package/dist/cjs/modules/pdf/excel-bridge.js +684 -12
- package/dist/cjs/modules/pdf/font/font-manager.js +39 -0
- package/dist/cjs/modules/pdf/index.js +5 -1
- package/dist/cjs/modules/pdf/render/chart-surface.js +203 -0
- package/dist/cjs/modules/pdf/render/layout-engine.js +437 -56
- package/dist/cjs/modules/pdf/render/page-renderer.js +169 -28
- package/dist/cjs/modules/pdf/render/pdf-exporter.js +115 -5
- package/dist/cjs/modules/pdf/types.js +5 -0
- package/dist/cjs/modules/pdf/word-bridge.js +307 -0
- package/dist/cjs/modules/word/constants.js +234 -0
- package/dist/cjs/modules/word/content-types.js +57 -0
- package/dist/cjs/modules/word/digital-signatures.js +140 -0
- package/dist/cjs/modules/word/document.js +1909 -0
- package/dist/cjs/modules/word/docx-packager.js +825 -0
- package/dist/cjs/modules/word/docx-reader.js +4932 -0
- package/dist/cjs/modules/word/encryption.js +282 -0
- package/dist/cjs/modules/word/errors.js +88 -0
- package/dist/cjs/modules/word/font-obfuscation.js +88 -0
- package/dist/cjs/modules/word/html-renderer.js +785 -0
- package/dist/cjs/modules/word/index.base.js +199 -0
- package/dist/cjs/modules/word/index.browser.js +20 -0
- package/dist/cjs/modules/word/index.js +20 -0
- package/dist/cjs/modules/word/internal-utils.js +59 -0
- package/dist/cjs/modules/word/relationships.js +60 -0
- package/dist/cjs/modules/word/types.js +11 -0
- package/dist/cjs/modules/word/units.js +135 -0
- package/dist/cjs/modules/word/writers/chart-writer.js +388 -0
- package/dist/cjs/modules/word/writers/checkbox-writer.js +45 -0
- package/dist/cjs/modules/word/writers/comment-writer.js +74 -0
- package/dist/cjs/modules/word/writers/document-writer.js +465 -0
- package/dist/cjs/modules/word/writers/footnote-writer.js +76 -0
- package/dist/cjs/modules/word/writers/header-footer-writer.js +134 -0
- package/dist/cjs/modules/word/writers/image-writer.js +188 -0
- package/dist/cjs/modules/word/writers/math-writer.js +431 -0
- package/dist/cjs/modules/word/writers/numbering-writer.js +128 -0
- package/dist/cjs/modules/word/writers/paragraph-writer.js +521 -0
- package/dist/cjs/modules/word/writers/parts-writer.js +671 -0
- package/dist/cjs/modules/word/writers/run-writer.js +655 -0
- package/dist/cjs/modules/word/writers/section-writer.js +241 -0
- package/dist/cjs/modules/word/writers/styles-writer.js +245 -0
- package/dist/cjs/modules/word/writers/table-writer.js +506 -0
- package/dist/cjs/modules/word/writers/textbox-writer.js +56 -0
- package/dist/cjs/modules/word/writers/toc-writer.js +82 -0
- package/dist/cjs/modules/xml/encode.js +158 -11
- package/dist/esm/index.browser.js +20 -2
- package/dist/esm/index.js +9 -1
- package/dist/esm/modules/excel/chart/cache-populator.js +1171 -0
- package/dist/esm/modules/excel/chart/chart-api.js +364 -0
- package/dist/esm/modules/excel/chart/chart-builder.js +2432 -0
- package/dist/esm/modules/excel/chart/chart-ex-builder.js +903 -0
- package/dist/esm/modules/excel/chart/chart-ex-parser.js +1205 -0
- package/dist/esm/modules/excel/chart/chart-ex-renderer.js +5352 -0
- package/dist/esm/modules/excel/chart/chart-ex-types.js +11 -0
- package/dist/esm/modules/excel/chart/chart-images.js +363 -0
- package/dist/esm/modules/excel/chart/chart-presets.js +179 -0
- package/dist/esm/modules/excel/chart/chart-renderer.js +6440 -0
- package/dist/esm/modules/excel/chart/chart-sidecar.js +427 -0
- package/dist/esm/modules/excel/chart/chart-utils.js +821 -0
- package/dist/esm/modules/excel/chart/chart.js +1320 -0
- package/dist/esm/modules/excel/chart/glyph-rasterizer.js +658 -0
- package/dist/esm/modules/excel/chart/index.js +46 -0
- package/dist/esm/modules/excel/chart/install.js +91 -0
- package/dist/esm/modules/excel/chart/shape-properties.js +1557 -0
- package/dist/esm/modules/excel/chart/stroke-font.js +1556 -0
- package/dist/esm/modules/excel/chart/topojson.js +236 -0
- package/dist/esm/modules/excel/chart/types.js +8 -0
- package/dist/esm/modules/excel/chart-host-registry.js +90 -0
- package/dist/esm/modules/excel/chartsheet.js +196 -0
- package/dist/esm/modules/excel/defined-names.js +44 -4
- package/dist/esm/modules/excel/errors.js +9 -0
- package/dist/esm/modules/excel/form-control.js +17 -0
- package/dist/esm/modules/excel/image.js +12 -2
- package/dist/esm/modules/excel/pivot-chart.js +53 -0
- package/dist/esm/modules/excel/pivot-table.js +35 -0
- package/dist/esm/modules/excel/range.js +5 -1
- package/dist/esm/modules/excel/sparkline/index.js +7 -0
- package/dist/esm/modules/excel/sparkline/sparkline.js +750 -0
- package/dist/esm/modules/excel/stream/worksheet-writer.js +3 -2
- package/dist/esm/modules/excel/table.js +42 -6
- package/dist/esm/modules/excel/utils/address.js +28 -0
- package/dist/esm/modules/excel/utils/drawing-utils.js +11 -6
- package/dist/esm/modules/excel/utils/guid.js +35 -0
- package/dist/esm/modules/excel/utils/ooxml-paths.js +206 -9
- package/dist/esm/modules/excel/utils/ooxml-validator/check-chart-sidecar.js +101 -0
- package/dist/esm/modules/excel/utils/ooxml-validator/check-chart.js +2125 -0
- package/dist/esm/modules/excel/utils/ooxml-validator/check-chartsheet.js +26 -0
- package/dist/esm/modules/excel/utils/ooxml-validator/check-content-types.js +181 -0
- package/dist/esm/modules/excel/utils/ooxml-validator/check-drawing.js +267 -0
- package/dist/esm/modules/excel/utils/ooxml-validator/check-pivot.js +104 -0
- package/dist/esm/modules/excel/utils/ooxml-validator/check-relationships.js +184 -0
- package/dist/esm/modules/excel/utils/ooxml-validator/check-structure.js +56 -0
- package/dist/esm/modules/excel/utils/ooxml-validator/check-styles.js +89 -0
- package/dist/esm/modules/excel/utils/ooxml-validator/check-table.js +177 -0
- package/dist/esm/modules/excel/utils/ooxml-validator/check-workbook.js +163 -0
- package/dist/esm/modules/excel/utils/ooxml-validator/check-worksheet.js +569 -0
- package/dist/esm/modules/excel/utils/ooxml-validator/context.js +191 -0
- package/dist/esm/modules/excel/utils/ooxml-validator/index.js +102 -0
- package/dist/esm/modules/excel/utils/ooxml-validator/path-utils.js +156 -0
- package/dist/esm/modules/excel/utils/ooxml-validator/reporter.js +61 -0
- package/dist/esm/modules/excel/utils/ooxml-validator/types.js +12 -0
- package/dist/esm/modules/excel/utils/ooxml-validator/xml-utils.js +100 -0
- package/dist/esm/modules/excel/workbook.browser.js +969 -34
- package/dist/esm/modules/excel/workbook.js +48 -0
- package/dist/esm/modules/excel/worksheet.js +394 -35
- package/dist/esm/modules/excel/xlsx/rel-type.js +41 -1
- package/dist/esm/modules/excel/xlsx/xform/book/defined-name-xform.js +11 -2
- package/dist/esm/modules/excel/xlsx/xform/book/external-link-xform.js +12 -10
- package/dist/esm/modules/excel/xlsx/xform/book/workbook-xform.js +96 -22
- package/dist/esm/modules/excel/xlsx/xform/chart/chart-space-xform.js +6000 -0
- package/dist/esm/modules/excel/xlsx/xform/comment/threaded-comments-xform.js +213 -0
- package/dist/esm/modules/excel/xlsx/xform/core/content-types-xform.js +150 -11
- package/dist/esm/modules/excel/xlsx/xform/drawing/absolute-anchor-xform.js +20 -1
- package/dist/esm/modules/excel/xlsx/xform/drawing/base-cell-anchor-xform.js +1 -1
- package/dist/esm/modules/excel/xlsx/xform/drawing/drawing-xform.js +109 -5
- package/dist/esm/modules/excel/xlsx/xform/drawing/graphic-frame-xform.js +225 -0
- package/dist/esm/modules/excel/xlsx/xform/drawing/one-cell-anchor-xform.js +18 -3
- package/dist/esm/modules/excel/xlsx/xform/drawing/two-cell-anchor-xform.js +294 -12
- package/dist/esm/modules/excel/xlsx/xform/pivot-table/pivot-table-xform.js +32 -6
- package/dist/esm/modules/excel/xlsx/xform/sheet/chartsheet-xform.js +441 -0
- package/dist/esm/modules/excel/xlsx/xform/sheet/ext-lst-xform.js +51 -2
- package/dist/esm/modules/excel/xlsx/xform/sheet/worksheet-xform.js +196 -20
- package/dist/esm/modules/excel/xlsx/xform/table/auto-filter-xform.js +16 -1
- package/dist/esm/modules/excel/xlsx/xform/table/table-column-xform.js +17 -2
- package/dist/esm/modules/excel/xlsx/xform/xsd-values.js +101 -0
- package/dist/esm/modules/excel/xlsx/xlsx.browser.js +4422 -78
- package/dist/esm/modules/pdf/builder/document-builder.js +507 -2
- package/dist/esm/modules/pdf/builder/pdf-editor.js +48 -3
- package/dist/esm/modules/pdf/excel-bridge.js +683 -12
- package/dist/esm/modules/pdf/font/font-manager.js +39 -0
- package/dist/esm/modules/pdf/index.js +3 -1
- package/dist/esm/modules/pdf/render/chart-surface.js +200 -0
- package/dist/esm/modules/pdf/render/layout-engine.js +436 -56
- package/dist/esm/modules/pdf/render/page-renderer.js +169 -28
- package/dist/esm/modules/pdf/render/pdf-exporter.js +117 -7
- package/dist/esm/modules/pdf/types.js +4 -0
- package/dist/esm/modules/pdf/word-bridge.js +304 -0
- package/dist/esm/modules/word/constants.js +231 -0
- package/dist/esm/modules/word/content-types.js +53 -0
- package/dist/esm/modules/word/digital-signatures.js +134 -0
- package/dist/esm/modules/word/document.js +1795 -0
- package/dist/esm/modules/word/docx-packager.js +822 -0
- package/dist/esm/modules/word/docx-reader.js +4929 -0
- package/dist/esm/modules/word/encryption.js +274 -0
- package/dist/esm/modules/word/errors.js +68 -0
- package/dist/esm/modules/word/font-obfuscation.js +83 -0
- package/dist/esm/modules/word/html-renderer.js +782 -0
- package/dist/esm/modules/word/index.base.js +51 -0
- package/dist/esm/modules/word/index.browser.js +4 -0
- package/dist/esm/modules/word/index.js +4 -0
- package/dist/esm/modules/word/internal-utils.js +54 -0
- package/dist/esm/modules/word/relationships.js +56 -0
- package/dist/esm/modules/word/types.js +10 -0
- package/dist/esm/modules/word/units.js +111 -0
- package/dist/esm/modules/word/writers/chart-writer.js +385 -0
- package/dist/esm/modules/word/writers/checkbox-writer.js +42 -0
- package/dist/esm/modules/word/writers/comment-writer.js +70 -0
- package/dist/esm/modules/word/writers/document-writer.js +461 -0
- package/dist/esm/modules/word/writers/footnote-writer.js +72 -0
- package/dist/esm/modules/word/writers/header-footer-writer.js +129 -0
- package/dist/esm/modules/word/writers/image-writer.js +185 -0
- package/dist/esm/modules/word/writers/math-writer.js +428 -0
- package/dist/esm/modules/word/writers/numbering-writer.js +125 -0
- package/dist/esm/modules/word/writers/paragraph-writer.js +516 -0
- package/dist/esm/modules/word/writers/parts-writer.js +660 -0
- package/dist/esm/modules/word/writers/run-writer.js +649 -0
- package/dist/esm/modules/word/writers/section-writer.js +238 -0
- package/dist/esm/modules/word/writers/styles-writer.js +242 -0
- package/dist/esm/modules/word/writers/table-writer.js +503 -0
- package/dist/esm/modules/word/writers/textbox-writer.js +53 -0
- package/dist/esm/modules/word/writers/toc-writer.js +79 -0
- package/dist/esm/modules/xml/encode.js +157 -11
- package/dist/iife/excelts.iife.js +11789 -687
- package/dist/iife/excelts.iife.js.map +1 -1
- package/dist/iife/excelts.iife.min.js +52 -44
- package/dist/types/index.browser.d.ts +8 -5
- package/dist/types/index.d.ts +4 -2
- package/dist/types/modules/excel/chart/cache-populator.d.ts +49 -0
- package/dist/types/modules/excel/chart/chart-api.d.ts +92 -0
- package/dist/types/modules/excel/chart/chart-builder.d.ts +48 -0
- package/dist/types/modules/excel/chart/chart-ex-builder.d.ts +36 -0
- package/dist/types/modules/excel/chart/chart-ex-parser.d.ts +8 -0
- package/dist/types/modules/excel/chart/chart-ex-renderer.d.ts +187 -0
- package/dist/types/modules/excel/chart/chart-ex-types.d.ts +531 -0
- package/dist/types/modules/excel/chart/chart-images.d.ts +78 -0
- package/dist/types/modules/excel/chart/chart-presets.d.ts +392 -0
- package/dist/types/modules/excel/chart/chart-renderer.d.ts +550 -0
- package/dist/types/modules/excel/chart/chart-sidecar.d.ts +21 -0
- package/dist/types/modules/excel/chart/chart-utils.d.ts +306 -0
- package/dist/types/modules/excel/chart/chart.d.ts +504 -0
- package/dist/types/modules/excel/chart/glyph-rasterizer.d.ts +62 -0
- package/dist/types/modules/excel/chart/index.d.ts +54 -0
- package/dist/types/modules/excel/chart/install.d.ts +44 -0
- package/dist/types/modules/excel/chart/shape-properties.d.ts +156 -0
- package/dist/types/modules/excel/chart/stroke-font.d.ts +36 -0
- package/dist/types/modules/excel/chart/topojson.d.ts +98 -0
- package/dist/types/modules/excel/chart/types.d.ts +2559 -0
- package/dist/types/modules/excel/chart-host-registry.d.ts +157 -0
- package/dist/types/modules/excel/chartsheet.d.ts +102 -0
- package/dist/types/modules/excel/defined-names.d.ts +35 -0
- package/dist/types/modules/excel/errors.d.ts +6 -0
- package/dist/types/modules/excel/form-control.d.ts +6 -0
- package/dist/types/modules/excel/pivot-chart.d.ts +7 -0
- package/dist/types/modules/excel/pivot-table.d.ts +55 -0
- package/dist/types/modules/excel/sparkline/index.d.ts +7 -0
- package/dist/types/modules/excel/sparkline/sparkline.d.ts +206 -0
- package/dist/types/modules/excel/types.d.ts +72 -0
- package/dist/types/modules/excel/utils/address.d.ts +18 -0
- package/dist/types/modules/excel/utils/guid.d.ts +15 -0
- package/dist/types/modules/excel/utils/ooxml-paths.d.ts +74 -0
- package/dist/types/modules/excel/utils/ooxml-validator/check-chart-sidecar.d.ts +35 -0
- package/dist/types/modules/excel/utils/ooxml-validator/check-chart.d.ts +32 -0
- package/dist/types/modules/excel/utils/ooxml-validator/check-chartsheet.d.ts +9 -0
- package/dist/types/modules/excel/utils/ooxml-validator/check-content-types.d.ts +16 -0
- package/dist/types/modules/excel/utils/ooxml-validator/check-drawing.d.ts +34 -0
- package/dist/types/modules/excel/utils/ooxml-validator/check-pivot.d.ts +14 -0
- package/dist/types/modules/excel/utils/ooxml-validator/check-relationships.d.ts +18 -0
- package/dist/types/modules/excel/utils/ooxml-validator/check-structure.d.ts +21 -0
- package/dist/types/modules/excel/utils/ooxml-validator/check-styles.d.ts +15 -0
- package/dist/types/modules/excel/utils/ooxml-validator/check-table.d.ts +31 -0
- package/dist/types/modules/excel/utils/ooxml-validator/check-workbook.d.ts +19 -0
- package/dist/types/modules/excel/utils/ooxml-validator/check-worksheet.d.ts +25 -0
- package/dist/types/modules/excel/utils/ooxml-validator/context.d.ts +85 -0
- package/dist/types/modules/excel/utils/ooxml-validator/index.d.ts +31 -0
- package/dist/types/modules/excel/utils/ooxml-validator/path-utils.d.ts +67 -0
- package/dist/types/modules/excel/utils/ooxml-validator/reporter.d.ts +41 -0
- package/dist/types/modules/excel/utils/ooxml-validator/types.d.ts +109 -0
- package/dist/types/modules/excel/utils/ooxml-validator/xml-utils.d.ts +38 -0
- package/dist/types/modules/excel/workbook.browser.d.ts +248 -30
- package/dist/types/modules/excel/workbook.d.ts +43 -0
- package/dist/types/modules/excel/worksheet.d.ts +157 -3
- package/dist/types/modules/excel/xlsx/rel-type.d.ts +40 -0
- package/dist/types/modules/excel/xlsx/xform/book/defined-name-xform.d.ts +1 -0
- package/dist/types/modules/excel/xlsx/xform/chart/chart-space-xform.d.ts +353 -0
- package/dist/types/modules/excel/xlsx/xform/comment/threaded-comments-xform.d.ts +60 -0
- package/dist/types/modules/excel/xlsx/xform/drawing/drawing-xform.d.ts +30 -0
- package/dist/types/modules/excel/xlsx/xform/drawing/graphic-frame-xform.d.ts +54 -0
- package/dist/types/modules/excel/xlsx/xform/drawing/one-cell-anchor-xform.d.ts +3 -1
- package/dist/types/modules/excel/xlsx/xform/drawing/two-cell-anchor-xform.d.ts +46 -0
- package/dist/types/modules/excel/xlsx/xform/pivot-table/pivot-table-xform.d.ts +13 -2
- package/dist/types/modules/excel/xlsx/xform/sheet/chartsheet-xform.d.ts +185 -0
- package/dist/types/modules/excel/xlsx/xform/sheet/ext-lst-xform.d.ts +1 -0
- package/dist/types/modules/excel/xlsx/xform/xsd-values.d.ts +63 -0
- package/dist/types/modules/excel/xlsx/xlsx.browser.d.ts +115 -21
- package/dist/types/modules/pdf/builder/document-builder.d.ts +74 -0
- package/dist/types/modules/pdf/excel-bridge.d.ts +69 -0
- package/dist/types/modules/pdf/font/font-manager.d.ts +25 -0
- package/dist/types/modules/pdf/index.d.ts +5 -2
- package/dist/types/modules/pdf/render/chart-surface.d.ts +33 -0
- package/dist/types/modules/pdf/render/layout-engine.d.ts +22 -1
- package/dist/types/modules/pdf/types.d.ts +227 -23
- package/dist/types/modules/pdf/word-bridge.d.ts +47 -0
- package/dist/types/modules/word/constants.d.ts +179 -0
- package/dist/types/modules/word/content-types.d.ts +27 -0
- package/dist/types/modules/word/digital-signatures.d.ts +87 -0
- package/dist/types/modules/word/document.d.ts +728 -0
- package/dist/types/modules/word/docx-packager.d.ts +14 -0
- package/dist/types/modules/word/docx-reader.d.ts +11 -0
- package/dist/types/modules/word/encryption.d.ts +102 -0
- package/dist/types/modules/word/errors.d.ts +49 -0
- package/dist/types/modules/word/font-obfuscation.d.ts +31 -0
- package/dist/types/modules/word/html-renderer.d.ts +38 -0
- package/dist/types/modules/word/index.base.d.ts +19 -0
- package/dist/types/modules/word/index.browser.d.ts +4 -0
- package/dist/types/modules/word/index.d.ts +4 -0
- package/dist/types/modules/word/internal-utils.d.ts +23 -0
- package/dist/types/modules/word/relationships.d.ts +31 -0
- package/dist/types/modules/word/types.d.ts +2325 -0
- package/dist/types/modules/word/units.d.ts +49 -0
- package/dist/types/modules/word/writers/chart-writer.d.ts +10 -0
- package/dist/types/modules/word/writers/checkbox-writer.d.ts +9 -0
- package/dist/types/modules/word/writers/comment-writer.d.ts +15 -0
- package/dist/types/modules/word/writers/document-writer.d.ts +16 -0
- package/dist/types/modules/word/writers/footnote-writer.d.ts +11 -0
- package/dist/types/modules/word/writers/header-footer-writer.d.ts +13 -0
- package/dist/types/modules/word/writers/image-writer.d.ts +10 -0
- package/dist/types/modules/word/writers/math-writer.d.ts +9 -0
- package/dist/types/modules/word/writers/numbering-writer.d.ts +10 -0
- package/dist/types/modules/word/writers/paragraph-writer.d.ts +13 -0
- package/dist/types/modules/word/writers/parts-writer.d.ts +26 -0
- package/dist/types/modules/word/writers/run-writer.d.ts +15 -0
- package/dist/types/modules/word/writers/section-writer.d.ts +10 -0
- package/dist/types/modules/word/writers/styles-writer.d.ts +10 -0
- package/dist/types/modules/word/writers/table-writer.d.ts +10 -0
- package/dist/types/modules/word/writers/textbox-writer.d.ts +9 -0
- package/dist/types/modules/word/writers/toc-writer.d.ts +9 -0
- package/dist/types/modules/xml/encode.d.ts +56 -7
- package/package.json +29 -11
- package/dist/browser/modules/excel/utils/ooxml-validator.d.ts +0 -48
- package/dist/browser/modules/excel/utils/ooxml-validator.js +0 -493
- package/dist/browser/modules/excel/utils/passthrough-manager.d.ts +0 -77
- package/dist/browser/modules/excel/utils/passthrough-manager.js +0 -129
- package/dist/cjs/modules/excel/utils/ooxml-validator.js +0 -499
- package/dist/cjs/modules/excel/utils/passthrough-manager.js +0 -133
- package/dist/esm/modules/excel/utils/ooxml-validator.js +0 -493
- package/dist/esm/modules/excel/utils/passthrough-manager.js +0 -129
- package/dist/types/modules/excel/utils/ooxml-validator.d.ts +0 -48
- package/dist/types/modules/excel/utils/passthrough-manager.d.ts +0 -77
|
@@ -0,0 +1,1909 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* DOCX Module - Document Builder
|
|
4
|
+
*
|
|
5
|
+
* High-level fluent API for constructing DOCX documents programmatically.
|
|
6
|
+
* Provides convenience methods for common operations including comments,
|
|
7
|
+
* track changes, TOC, math, text boxes, checkboxes, and custom properties.
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.DocumentBuilder = void 0;
|
|
11
|
+
exports.text = text;
|
|
12
|
+
exports.bold = bold;
|
|
13
|
+
exports.italic = italic;
|
|
14
|
+
exports.pageBreak = pageBreak;
|
|
15
|
+
exports.lineBreak = lineBreak;
|
|
16
|
+
exports.columnBreak = columnBreak;
|
|
17
|
+
exports.tab = tab;
|
|
18
|
+
exports.positionalTab = positionalTab;
|
|
19
|
+
exports.ruby = ruby;
|
|
20
|
+
exports.carriageReturn = carriageReturn;
|
|
21
|
+
exports.noBreakHyphen = noBreakHyphen;
|
|
22
|
+
exports.softHyphen = softHyphen;
|
|
23
|
+
exports.field = field;
|
|
24
|
+
exports.pageNumberField = pageNumberField;
|
|
25
|
+
exports.totalPagesField = totalPagesField;
|
|
26
|
+
exports.sectionPagesField = sectionPagesField;
|
|
27
|
+
exports.sectionField = sectionField;
|
|
28
|
+
exports.dateField = dateField;
|
|
29
|
+
exports.sequenceField = sequenceField;
|
|
30
|
+
exports.timeField = timeField;
|
|
31
|
+
exports.authorField = authorField;
|
|
32
|
+
exports.titleField = titleField;
|
|
33
|
+
exports.subjectField = subjectField;
|
|
34
|
+
exports.keywordsField = keywordsField;
|
|
35
|
+
exports.fileNameField = fileNameField;
|
|
36
|
+
exports.fileSizeField = fileSizeField;
|
|
37
|
+
exports.styleRefField = styleRefField;
|
|
38
|
+
exports.refField = refField;
|
|
39
|
+
exports.pageRefField = pageRefField;
|
|
40
|
+
exports.noteRefField = noteRefField;
|
|
41
|
+
exports.hyperlinkField = hyperlinkField;
|
|
42
|
+
exports.quoteField = quoteField;
|
|
43
|
+
exports.tocField = tocField;
|
|
44
|
+
exports.tcField = tcField;
|
|
45
|
+
exports.indexEntryField = indexEntryField;
|
|
46
|
+
exports.indexField = indexField;
|
|
47
|
+
exports.ifField = ifField;
|
|
48
|
+
exports.includeTextField = includeTextField;
|
|
49
|
+
exports.includePictureField = includePictureField;
|
|
50
|
+
exports.formTextField = formTextField;
|
|
51
|
+
exports.formCheckboxField = formCheckboxField;
|
|
52
|
+
exports.formDropdownField = formDropdownField;
|
|
53
|
+
exports.paragraph = paragraph;
|
|
54
|
+
exports.textParagraph = textParagraph;
|
|
55
|
+
exports.heading = heading;
|
|
56
|
+
exports.hyperlink = hyperlink;
|
|
57
|
+
exports.bookmarkStart = bookmarkStart;
|
|
58
|
+
exports.bookmarkEnd = bookmarkEnd;
|
|
59
|
+
exports.commentRangeStart = commentRangeStart;
|
|
60
|
+
exports.commentRangeEnd = commentRangeEnd;
|
|
61
|
+
exports.commentReference = commentReference;
|
|
62
|
+
exports.insertedRun = insertedRun;
|
|
63
|
+
exports.deletedRun = deletedRun;
|
|
64
|
+
exports.movedFromRun = movedFromRun;
|
|
65
|
+
exports.movedToRun = movedToRun;
|
|
66
|
+
exports.moveFromRangeStart = moveFromRangeStart;
|
|
67
|
+
exports.moveFromRangeEnd = moveFromRangeEnd;
|
|
68
|
+
exports.moveToRangeStart = moveToRangeStart;
|
|
69
|
+
exports.moveToRangeEnd = moveToRangeEnd;
|
|
70
|
+
exports.checkBox = checkBox;
|
|
71
|
+
exports.mathBlock = mathBlock;
|
|
72
|
+
exports.mathRun = mathRun;
|
|
73
|
+
exports.mathFraction = mathFraction;
|
|
74
|
+
exports.mathSqrt = mathSqrt;
|
|
75
|
+
exports.mathRoot = mathRoot;
|
|
76
|
+
exports.mathSum = mathSum;
|
|
77
|
+
exports.mathIntegral = mathIntegral;
|
|
78
|
+
exports.mathProduct = mathProduct;
|
|
79
|
+
exports.mathSuperScript = mathSuperScript;
|
|
80
|
+
exports.mathSubScript = mathSubScript;
|
|
81
|
+
exports.mathSubSuperScript = mathSubSuperScript;
|
|
82
|
+
exports.mathPreSubSuperScript = mathPreSubSuperScript;
|
|
83
|
+
exports.mathPhantom = mathPhantom;
|
|
84
|
+
exports.mathGroupChar = mathGroupChar;
|
|
85
|
+
exports.mathBorderBox = mathBorderBox;
|
|
86
|
+
exports.mathDelimiter = mathDelimiter;
|
|
87
|
+
exports.mathNary = mathNary;
|
|
88
|
+
exports.mathFunction = mathFunction;
|
|
89
|
+
exports.mathLimit = mathLimit;
|
|
90
|
+
exports.mathMatrix = mathMatrix;
|
|
91
|
+
exports.mathAccent = mathAccent;
|
|
92
|
+
exports.mathBar = mathBar;
|
|
93
|
+
exports.mathBox = mathBox;
|
|
94
|
+
exports.mathEquationArray = mathEquationArray;
|
|
95
|
+
exports.symbol = symbol;
|
|
96
|
+
exports.floatingImage = floatingImage;
|
|
97
|
+
exports.drawingShape = drawingShape;
|
|
98
|
+
exports.chart = chart;
|
|
99
|
+
exports.structuredDocumentTag = structuredDocumentTag;
|
|
100
|
+
exports.border = border;
|
|
101
|
+
exports.gridBorders = gridBorders;
|
|
102
|
+
exports.cell = cell;
|
|
103
|
+
exports.row = row;
|
|
104
|
+
exports.table = table;
|
|
105
|
+
exports.simpleTable = simpleTable;
|
|
106
|
+
exports.resolveThemeColor = resolveThemeColor;
|
|
107
|
+
exports.paragraphCount = paragraphCount;
|
|
108
|
+
exports.countWords = countWords;
|
|
109
|
+
exports.getHeadings = getHeadings;
|
|
110
|
+
exports.findBookmark = findBookmark;
|
|
111
|
+
exports.findComment = findComment;
|
|
112
|
+
exports.listImages = listImages;
|
|
113
|
+
exports.listTables = listTables;
|
|
114
|
+
exports.listHyperlinks = listHyperlinks;
|
|
115
|
+
exports.tableCount = tableCount;
|
|
116
|
+
exports.extractText = extractText;
|
|
117
|
+
exports.searchText = searchText;
|
|
118
|
+
exports.replaceText = replaceText;
|
|
119
|
+
exports.mailMerge = mailMerge;
|
|
120
|
+
exports.patchDocument = patchDocument;
|
|
121
|
+
const docx_packager_1 = require("./docx-packager");
|
|
122
|
+
const docx_reader_1 = require("./docx-reader");
|
|
123
|
+
const internal_utils_1 = require("./internal-utils");
|
|
124
|
+
// =============================================================================
|
|
125
|
+
// Helper Builders
|
|
126
|
+
// =============================================================================
|
|
127
|
+
/** Create a text run. */
|
|
128
|
+
function text(content, properties) {
|
|
129
|
+
return { properties, content: [{ type: "text", text: content }] };
|
|
130
|
+
}
|
|
131
|
+
/** Create a bold text run. */
|
|
132
|
+
function bold(content, properties) {
|
|
133
|
+
return text(content, { ...properties, bold: true });
|
|
134
|
+
}
|
|
135
|
+
/** Create an italic text run. */
|
|
136
|
+
function italic(content, properties) {
|
|
137
|
+
return text(content, { ...properties, italic: true });
|
|
138
|
+
}
|
|
139
|
+
/** Create a run with a page break. */
|
|
140
|
+
function pageBreak() {
|
|
141
|
+
return { content: [{ type: "break", breakType: "page" }] };
|
|
142
|
+
}
|
|
143
|
+
/** Create a run with a line break. */
|
|
144
|
+
function lineBreak() {
|
|
145
|
+
return { content: [{ type: "break" }] };
|
|
146
|
+
}
|
|
147
|
+
/** Create a run with a column break. */
|
|
148
|
+
function columnBreak() {
|
|
149
|
+
return { content: [{ type: "break", breakType: "column" }] };
|
|
150
|
+
}
|
|
151
|
+
/** Create a tab run. */
|
|
152
|
+
function tab() {
|
|
153
|
+
return { content: [{ type: "tab" }] };
|
|
154
|
+
}
|
|
155
|
+
/** Create a positional tab (w:ptab). */
|
|
156
|
+
function positionalTab(options) {
|
|
157
|
+
return {
|
|
158
|
+
content: [
|
|
159
|
+
{
|
|
160
|
+
type: "ptab",
|
|
161
|
+
alignment: options.alignment,
|
|
162
|
+
relativeTo: options.relativeTo,
|
|
163
|
+
leader: options.leader
|
|
164
|
+
}
|
|
165
|
+
]
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Create a ruby (phonetic guide) run — e.g. Japanese furigana or Chinese pinyin.
|
|
170
|
+
*
|
|
171
|
+
* @param baseText - The main text being annotated.
|
|
172
|
+
* @param rubyText - The phonetic text shown above the base.
|
|
173
|
+
* @param properties - Optional ruby properties (alignment, font size, language).
|
|
174
|
+
*/
|
|
175
|
+
function ruby(baseText, rubyText, properties) {
|
|
176
|
+
const normalize = (v) => {
|
|
177
|
+
if (typeof v === "string") {
|
|
178
|
+
return [text(v)];
|
|
179
|
+
}
|
|
180
|
+
if (Array.isArray(v)) {
|
|
181
|
+
return v;
|
|
182
|
+
}
|
|
183
|
+
return [v];
|
|
184
|
+
};
|
|
185
|
+
return {
|
|
186
|
+
content: [
|
|
187
|
+
{
|
|
188
|
+
type: "ruby",
|
|
189
|
+
properties,
|
|
190
|
+
baseText: normalize(baseText),
|
|
191
|
+
rubyText: normalize(rubyText)
|
|
192
|
+
}
|
|
193
|
+
]
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
/** Create a carriage return run. */
|
|
197
|
+
function carriageReturn() {
|
|
198
|
+
return { content: [{ type: "carriageReturn" }] };
|
|
199
|
+
}
|
|
200
|
+
/** Create a no-break hyphen run. */
|
|
201
|
+
function noBreakHyphen() {
|
|
202
|
+
return { content: [{ type: "noBreakHyphen" }] };
|
|
203
|
+
}
|
|
204
|
+
/** Create a soft hyphen run. */
|
|
205
|
+
function softHyphen() {
|
|
206
|
+
return { content: [{ type: "softHyphen" }] };
|
|
207
|
+
}
|
|
208
|
+
/** Create a run with a field code. */
|
|
209
|
+
function field(instruction, cachedValue) {
|
|
210
|
+
return { content: [{ type: "field", instruction, cachedValue }] };
|
|
211
|
+
}
|
|
212
|
+
/** Create a PAGE field (current page number). */
|
|
213
|
+
function pageNumberField(cachedValue) {
|
|
214
|
+
return field(" PAGE ", cachedValue ?? "1");
|
|
215
|
+
}
|
|
216
|
+
/** Create a NUMPAGES field (total page count). */
|
|
217
|
+
function totalPagesField(cachedValue) {
|
|
218
|
+
return field(" NUMPAGES ", cachedValue ?? "1");
|
|
219
|
+
}
|
|
220
|
+
/** Create a SECTIONPAGES field (pages in section). */
|
|
221
|
+
function sectionPagesField(cachedValue) {
|
|
222
|
+
return field(" SECTIONPAGES ", cachedValue ?? "1");
|
|
223
|
+
}
|
|
224
|
+
/** Create a SECTION field (current section number). */
|
|
225
|
+
function sectionField(cachedValue) {
|
|
226
|
+
return field(" SECTION ", cachedValue ?? "1");
|
|
227
|
+
}
|
|
228
|
+
/** Create a DATE field. */
|
|
229
|
+
function dateField(format, cachedValue) {
|
|
230
|
+
const fmt = format ?? "yyyy-MM-dd";
|
|
231
|
+
return field(` DATE \\@ "${fmt}" `, cachedValue);
|
|
232
|
+
}
|
|
233
|
+
/** Create a SEQ (sequence) field for numbering figures, tables, etc. */
|
|
234
|
+
function sequenceField(identifier, options) {
|
|
235
|
+
let instruction = ` SEQ ${identifier} `;
|
|
236
|
+
if (options?.hide) {
|
|
237
|
+
instruction += "\\h ";
|
|
238
|
+
}
|
|
239
|
+
return field(instruction, options?.cachedValue);
|
|
240
|
+
}
|
|
241
|
+
/** Create a TIME field (current time). */
|
|
242
|
+
function timeField(format, cachedValue) {
|
|
243
|
+
const fmt = format ?? "HH:mm:ss";
|
|
244
|
+
return field(` TIME \\@ "${fmt}" `, cachedValue);
|
|
245
|
+
}
|
|
246
|
+
/** Create an AUTHOR field. */
|
|
247
|
+
function authorField(cachedValue) {
|
|
248
|
+
return field(" AUTHOR ", cachedValue);
|
|
249
|
+
}
|
|
250
|
+
/** Create a TITLE field. */
|
|
251
|
+
function titleField(cachedValue) {
|
|
252
|
+
return field(" TITLE ", cachedValue);
|
|
253
|
+
}
|
|
254
|
+
/** Create a SUBJECT field. */
|
|
255
|
+
function subjectField(cachedValue) {
|
|
256
|
+
return field(" SUBJECT ", cachedValue);
|
|
257
|
+
}
|
|
258
|
+
/** Create a KEYWORDS field. */
|
|
259
|
+
function keywordsField(cachedValue) {
|
|
260
|
+
return field(" KEYWORDS ", cachedValue);
|
|
261
|
+
}
|
|
262
|
+
/** Create a FILENAME field. */
|
|
263
|
+
function fileNameField(options) {
|
|
264
|
+
const instruction = options?.includePath ? " FILENAME \\p " : " FILENAME ";
|
|
265
|
+
return field(instruction, options?.cachedValue);
|
|
266
|
+
}
|
|
267
|
+
/** Create a FILESIZE field. */
|
|
268
|
+
function fileSizeField(cachedValue) {
|
|
269
|
+
return field(" FILESIZE ", cachedValue);
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* Create a STYLEREF field (references text from nearest paragraph with given style).
|
|
273
|
+
*
|
|
274
|
+
* Commonly used in headers to show current chapter/section heading.
|
|
275
|
+
*/
|
|
276
|
+
function styleRefField(styleName, options) {
|
|
277
|
+
let instruction = ` STYLEREF "${styleName}" `;
|
|
278
|
+
if (options?.fromBottom) {
|
|
279
|
+
instruction += "\\l ";
|
|
280
|
+
}
|
|
281
|
+
if (options?.insertParagraphNumber) {
|
|
282
|
+
instruction += "\\n ";
|
|
283
|
+
}
|
|
284
|
+
if (options?.insertPosition) {
|
|
285
|
+
instruction += "\\p ";
|
|
286
|
+
}
|
|
287
|
+
if (options?.suppressNonNumeric) {
|
|
288
|
+
instruction += "\\t ";
|
|
289
|
+
}
|
|
290
|
+
return field(instruction, options?.cachedValue);
|
|
291
|
+
}
|
|
292
|
+
/**
|
|
293
|
+
* Create a REF field (references a bookmark).
|
|
294
|
+
*/
|
|
295
|
+
function refField(bookmarkName, options) {
|
|
296
|
+
let instruction = ` REF ${bookmarkName} `;
|
|
297
|
+
if (options?.insertNumber) {
|
|
298
|
+
instruction += "\\n ";
|
|
299
|
+
}
|
|
300
|
+
if (options?.hyperlink) {
|
|
301
|
+
instruction += "\\h ";
|
|
302
|
+
}
|
|
303
|
+
if (options?.paragraphNumber) {
|
|
304
|
+
instruction += "\\w ";
|
|
305
|
+
}
|
|
306
|
+
if (options?.relativeParagraphNumber) {
|
|
307
|
+
instruction += "\\r ";
|
|
308
|
+
}
|
|
309
|
+
if (options?.fullContext) {
|
|
310
|
+
instruction += "\\w ";
|
|
311
|
+
}
|
|
312
|
+
if (options?.suppressNonDelimiter) {
|
|
313
|
+
instruction += "\\t ";
|
|
314
|
+
}
|
|
315
|
+
return field(instruction, options?.cachedValue);
|
|
316
|
+
}
|
|
317
|
+
/** Create a PAGEREF field (references page of bookmark). */
|
|
318
|
+
function pageRefField(bookmarkName, options) {
|
|
319
|
+
let instruction = ` PAGEREF ${bookmarkName} `;
|
|
320
|
+
if (options?.hyperlink) {
|
|
321
|
+
instruction += "\\h ";
|
|
322
|
+
}
|
|
323
|
+
if (options?.relativePosition) {
|
|
324
|
+
instruction += "\\p ";
|
|
325
|
+
}
|
|
326
|
+
return field(instruction, options?.cachedValue);
|
|
327
|
+
}
|
|
328
|
+
/** Create a NOTEREF field (references a footnote/endnote). */
|
|
329
|
+
function noteRefField(bookmarkName, options) {
|
|
330
|
+
let instruction = ` NOTEREF ${bookmarkName} `;
|
|
331
|
+
if (options?.hyperlink) {
|
|
332
|
+
instruction += "\\h ";
|
|
333
|
+
}
|
|
334
|
+
if (options?.insertNumberFormat) {
|
|
335
|
+
instruction += "\\f ";
|
|
336
|
+
}
|
|
337
|
+
return field(instruction, options?.cachedValue);
|
|
338
|
+
}
|
|
339
|
+
/** Create a HYPERLINK field (alternative to w:hyperlink element). */
|
|
340
|
+
function hyperlinkField(target, options) {
|
|
341
|
+
let instruction = ` HYPERLINK "${target}" `;
|
|
342
|
+
if (options?.anchor) {
|
|
343
|
+
instruction += `\\l "${options.anchor}" `;
|
|
344
|
+
}
|
|
345
|
+
if (options?.newWindow) {
|
|
346
|
+
instruction += "\\n ";
|
|
347
|
+
}
|
|
348
|
+
if (options?.tooltip) {
|
|
349
|
+
instruction += `\\o "${options.tooltip}" `;
|
|
350
|
+
}
|
|
351
|
+
return field(instruction, options?.cachedValue ?? options?.displayText);
|
|
352
|
+
}
|
|
353
|
+
/** Create a QUOTE field (literal text). */
|
|
354
|
+
function quoteField(text, cachedValue) {
|
|
355
|
+
return field(` QUOTE "${text}" `, cachedValue ?? text);
|
|
356
|
+
}
|
|
357
|
+
/**
|
|
358
|
+
* Create a TOC field for table of contents.
|
|
359
|
+
*
|
|
360
|
+
* @param options - TOC options.
|
|
361
|
+
*/
|
|
362
|
+
function tocField(options) {
|
|
363
|
+
let instruction = " TOC ";
|
|
364
|
+
if (options?.headingLevels) {
|
|
365
|
+
instruction += `\\o "${options.headingLevels}" `;
|
|
366
|
+
}
|
|
367
|
+
if (options?.styles && options.styles.length > 0) {
|
|
368
|
+
instruction += `\\t "${options.styles.join(";")}" `;
|
|
369
|
+
}
|
|
370
|
+
if (options?.tcLevels) {
|
|
371
|
+
instruction += `\\f ${options.tcLevels} `;
|
|
372
|
+
}
|
|
373
|
+
if (options?.hyperlink) {
|
|
374
|
+
instruction += "\\h ";
|
|
375
|
+
}
|
|
376
|
+
if (options?.rightAlignedPageNumbers) {
|
|
377
|
+
instruction += "\\z ";
|
|
378
|
+
}
|
|
379
|
+
if (options?.tabLeader) {
|
|
380
|
+
instruction += `\\p "${options.tabLeader}" `;
|
|
381
|
+
}
|
|
382
|
+
if (options?.noPageNumbers) {
|
|
383
|
+
instruction += "\\n ";
|
|
384
|
+
}
|
|
385
|
+
if (options?.captionIdentifier) {
|
|
386
|
+
instruction += `\\c "${options.captionIdentifier}" `;
|
|
387
|
+
}
|
|
388
|
+
return field(instruction, options?.cachedValue);
|
|
389
|
+
}
|
|
390
|
+
/** Create a TC (table of contents entry) field. */
|
|
391
|
+
function tcField(text, options) {
|
|
392
|
+
let instruction = ` TC "${text}" `;
|
|
393
|
+
if (options?.level !== undefined) {
|
|
394
|
+
instruction += `\\l ${options.level} `;
|
|
395
|
+
}
|
|
396
|
+
if (options?.suppressPageNumber) {
|
|
397
|
+
instruction += "\\n ";
|
|
398
|
+
}
|
|
399
|
+
return field(instruction, options?.cachedValue);
|
|
400
|
+
}
|
|
401
|
+
/** Create an XE (index entry) field. */
|
|
402
|
+
function indexEntryField(text, options) {
|
|
403
|
+
let instruction = ` XE "${text}" `;
|
|
404
|
+
if (options?.bold) {
|
|
405
|
+
instruction += "\\b ";
|
|
406
|
+
}
|
|
407
|
+
if (options?.italic) {
|
|
408
|
+
instruction += "\\i ";
|
|
409
|
+
}
|
|
410
|
+
return field(instruction, options?.cachedValue);
|
|
411
|
+
}
|
|
412
|
+
/** Create an INDEX field (renders index from XE entries). */
|
|
413
|
+
function indexField(options) {
|
|
414
|
+
let instruction = " INDEX ";
|
|
415
|
+
if (options?.bookmark) {
|
|
416
|
+
instruction += `\\b ${options.bookmark} `;
|
|
417
|
+
}
|
|
418
|
+
if (options?.columns) {
|
|
419
|
+
instruction += `\\c ${options.columns} `;
|
|
420
|
+
}
|
|
421
|
+
if (options?.entryType) {
|
|
422
|
+
instruction += `\\f "${options.entryType}" `;
|
|
423
|
+
}
|
|
424
|
+
return field(instruction, options?.cachedValue);
|
|
425
|
+
}
|
|
426
|
+
/** Create an IF field (conditional content). */
|
|
427
|
+
function ifField(condition, trueText, falseText, cachedValue) {
|
|
428
|
+
return field(` IF ${condition} "${trueText}" "${falseText}" `, cachedValue);
|
|
429
|
+
}
|
|
430
|
+
/** Create an INCLUDETEXT field (includes external file content). */
|
|
431
|
+
function includeTextField(filePath, options) {
|
|
432
|
+
let instruction = ` INCLUDETEXT "${filePath}" `;
|
|
433
|
+
if (options?.bookmark) {
|
|
434
|
+
instruction += `${options.bookmark} `;
|
|
435
|
+
}
|
|
436
|
+
return field(instruction, options?.cachedValue);
|
|
437
|
+
}
|
|
438
|
+
/** Create an INCLUDEPICTURE field. */
|
|
439
|
+
function includePictureField(filePath, cachedValue) {
|
|
440
|
+
return field(` INCLUDEPICTURE "${filePath}" `, cachedValue);
|
|
441
|
+
}
|
|
442
|
+
/** Create a FORMTEXT field (legacy text form field). */
|
|
443
|
+
function formTextField(cachedValue) {
|
|
444
|
+
return field(" FORMTEXT ", cachedValue);
|
|
445
|
+
}
|
|
446
|
+
/** Create a FORMCHECKBOX field (legacy checkbox form field). */
|
|
447
|
+
function formCheckboxField(cachedValue) {
|
|
448
|
+
return field(" FORMCHECKBOX ", cachedValue);
|
|
449
|
+
}
|
|
450
|
+
/** Create a FORMDROPDOWN field (legacy dropdown form field). */
|
|
451
|
+
function formDropdownField(cachedValue) {
|
|
452
|
+
return field(" FORMDROPDOWN ", cachedValue);
|
|
453
|
+
}
|
|
454
|
+
/** Create a paragraph. */
|
|
455
|
+
function paragraph(children, properties) {
|
|
456
|
+
return { type: "paragraph", properties, children };
|
|
457
|
+
}
|
|
458
|
+
/** Create a simple text paragraph. */
|
|
459
|
+
function textParagraph(content, properties) {
|
|
460
|
+
const { run: runProps, ...pProps } = properties ?? {};
|
|
461
|
+
return paragraph([text(content, runProps)], Object.keys(pProps).length > 0 ? pProps : undefined);
|
|
462
|
+
}
|
|
463
|
+
/** Create a heading paragraph. */
|
|
464
|
+
function heading(content, level) {
|
|
465
|
+
return paragraph([text(content)], { style: `Heading${level}` });
|
|
466
|
+
}
|
|
467
|
+
/** Create a hyperlink. */
|
|
468
|
+
function hyperlink(linkText, options) {
|
|
469
|
+
return {
|
|
470
|
+
type: "hyperlink",
|
|
471
|
+
rId: options.rId,
|
|
472
|
+
url: options.url,
|
|
473
|
+
anchor: options.anchor,
|
|
474
|
+
tooltip: options.tooltip,
|
|
475
|
+
children: [text(linkText, options.properties ?? { color: "0563C1", underline: "single" })]
|
|
476
|
+
};
|
|
477
|
+
}
|
|
478
|
+
/** Create a bookmark start. */
|
|
479
|
+
function bookmarkStart(id, name) {
|
|
480
|
+
return { type: "bookmarkStart", id, name };
|
|
481
|
+
}
|
|
482
|
+
/** Create a bookmark end. */
|
|
483
|
+
function bookmarkEnd(id) {
|
|
484
|
+
return { type: "bookmarkEnd", id };
|
|
485
|
+
}
|
|
486
|
+
/** Create a comment range start marker. */
|
|
487
|
+
function commentRangeStart(id) {
|
|
488
|
+
return { type: "commentRangeStart", id };
|
|
489
|
+
}
|
|
490
|
+
/** Create a comment range end marker. */
|
|
491
|
+
function commentRangeEnd(id) {
|
|
492
|
+
return { type: "commentRangeEnd", id };
|
|
493
|
+
}
|
|
494
|
+
/** Create a comment reference (inside paragraph children). */
|
|
495
|
+
function commentReference(id) {
|
|
496
|
+
return { type: "commentReference", id };
|
|
497
|
+
}
|
|
498
|
+
/** Create an inserted run (track changes). */
|
|
499
|
+
function insertedRun(run, revision) {
|
|
500
|
+
return { type: "insertedRun", revision, run };
|
|
501
|
+
}
|
|
502
|
+
/** Create a deleted run (track changes). */
|
|
503
|
+
function deletedRun(run, revision) {
|
|
504
|
+
return { type: "deletedRun", revision, run };
|
|
505
|
+
}
|
|
506
|
+
/** Create a moved-from run (track changes — source of a move). */
|
|
507
|
+
function movedFromRun(run, revision) {
|
|
508
|
+
return { type: "movedFromRun", revision, run };
|
|
509
|
+
}
|
|
510
|
+
/** Create a moved-to run (track changes — destination of a move). */
|
|
511
|
+
function movedToRun(run, revision) {
|
|
512
|
+
return { type: "movedToRun", revision, run };
|
|
513
|
+
}
|
|
514
|
+
/** Create a move range start marker. */
|
|
515
|
+
function moveFromRangeStart(id, author, options) {
|
|
516
|
+
return { type: "moveFromRangeStart", id, author, date: options?.date, name: options?.name };
|
|
517
|
+
}
|
|
518
|
+
/** Create a move range end marker. */
|
|
519
|
+
function moveFromRangeEnd(id) {
|
|
520
|
+
return { type: "moveFromRangeEnd", id };
|
|
521
|
+
}
|
|
522
|
+
/** Create a move-to range start marker. */
|
|
523
|
+
function moveToRangeStart(id, author, options) {
|
|
524
|
+
return { type: "moveToRangeStart", id, author, date: options?.date, name: options?.name };
|
|
525
|
+
}
|
|
526
|
+
/** Create a move-to range end marker. */
|
|
527
|
+
function moveToRangeEnd(id) {
|
|
528
|
+
return { type: "moveToRangeEnd", id };
|
|
529
|
+
}
|
|
530
|
+
/** Create a checkbox. */
|
|
531
|
+
function checkBox(options) {
|
|
532
|
+
return {
|
|
533
|
+
type: "checkBox",
|
|
534
|
+
checked: options?.checked,
|
|
535
|
+
checkedState: options?.checkedState,
|
|
536
|
+
uncheckedState: options?.uncheckedState
|
|
537
|
+
};
|
|
538
|
+
}
|
|
539
|
+
// =============================================================================
|
|
540
|
+
// Math Builders
|
|
541
|
+
// =============================================================================
|
|
542
|
+
/** Create a math block. */
|
|
543
|
+
function mathBlock(content) {
|
|
544
|
+
return { type: "math", content };
|
|
545
|
+
}
|
|
546
|
+
/** Create a math text run. */
|
|
547
|
+
function mathRun(mathText, properties) {
|
|
548
|
+
return { type: "mathRun", text: mathText, properties };
|
|
549
|
+
}
|
|
550
|
+
/** Create a math fraction. */
|
|
551
|
+
function mathFraction(numerator, denominator, fractionType) {
|
|
552
|
+
return { type: "mathFraction", fractionType, numerator, denominator };
|
|
553
|
+
}
|
|
554
|
+
/** Create a math square root. */
|
|
555
|
+
function mathSqrt(content) {
|
|
556
|
+
return { type: "mathRadical", content, hideDegree: true };
|
|
557
|
+
}
|
|
558
|
+
/** Create a math nth root. */
|
|
559
|
+
function mathRoot(degree, content) {
|
|
560
|
+
return { type: "mathRadical", degree, content };
|
|
561
|
+
}
|
|
562
|
+
/** Create a math summation. */
|
|
563
|
+
function mathSum(content, sub, sup) {
|
|
564
|
+
return { type: "mathNary", char: "\u2211", sub, sup, content };
|
|
565
|
+
}
|
|
566
|
+
/** Create a math integral. */
|
|
567
|
+
function mathIntegral(content, sub, sup) {
|
|
568
|
+
return { type: "mathNary", char: "\u222B", sub, sup, content };
|
|
569
|
+
}
|
|
570
|
+
/** Create a math product. */
|
|
571
|
+
function mathProduct(content, sub, sup) {
|
|
572
|
+
return { type: "mathNary", char: "\u220F", sub, sup, content };
|
|
573
|
+
}
|
|
574
|
+
/** Create a math superscript. */
|
|
575
|
+
function mathSuperScript(base, superScript) {
|
|
576
|
+
return { type: "mathSuperScript", base, superScript };
|
|
577
|
+
}
|
|
578
|
+
/** Create a math subscript. */
|
|
579
|
+
function mathSubScript(base, subScript) {
|
|
580
|
+
return { type: "mathSubScript", base, subScript };
|
|
581
|
+
}
|
|
582
|
+
/** Create a math sub-superscript. */
|
|
583
|
+
function mathSubSuperScript(base, subScript, superScript) {
|
|
584
|
+
return { type: "mathSubSuperScript", base, subScript, superScript };
|
|
585
|
+
}
|
|
586
|
+
/** Create a math pre-sub-superscript (subscript/superscript before the base). */
|
|
587
|
+
function mathPreSubSuperScript(base, preSubScript, preSuperScript) {
|
|
588
|
+
return { type: "mathPreSubSuperScript", base, preSubScript, preSuperScript };
|
|
589
|
+
}
|
|
590
|
+
/** Create a math phantom (invisible expression that takes up space). */
|
|
591
|
+
function mathPhantom(content, options) {
|
|
592
|
+
return { type: "mathPhantom", content, ...options };
|
|
593
|
+
}
|
|
594
|
+
/** Create a math group character (e.g. a horizontal brace over an expression). */
|
|
595
|
+
function mathGroupChar(base, options) {
|
|
596
|
+
return { type: "mathGroupChar", base, ...options };
|
|
597
|
+
}
|
|
598
|
+
/** Create a math border box (draw borders around / strike through an expression). */
|
|
599
|
+
function mathBorderBox(content, options) {
|
|
600
|
+
return { type: "mathBorderBox", content, ...options };
|
|
601
|
+
}
|
|
602
|
+
/** Create a math delimiter (parentheses, brackets, etc.). */
|
|
603
|
+
function mathDelimiter(content, options) {
|
|
604
|
+
return {
|
|
605
|
+
type: "mathDelimiter",
|
|
606
|
+
beginChar: options?.beginChar,
|
|
607
|
+
endChar: options?.endChar,
|
|
608
|
+
separatorChar: options?.separatorChar,
|
|
609
|
+
content
|
|
610
|
+
};
|
|
611
|
+
}
|
|
612
|
+
/** Create a math n-ary operator (sum, integral, product, etc.). */
|
|
613
|
+
function mathNary(char, content, sub, sup) {
|
|
614
|
+
return { type: "mathNary", char, sub, sup, content };
|
|
615
|
+
}
|
|
616
|
+
/** Create a math function (sin, cos, lim, etc.). */
|
|
617
|
+
function mathFunction(name, content) {
|
|
618
|
+
return { type: "mathFunction", name, content };
|
|
619
|
+
}
|
|
620
|
+
/** Create a math limit (upper or lower). */
|
|
621
|
+
function mathLimit(base, limit, limitType = "lower") {
|
|
622
|
+
return { type: "mathLimit", base, limit, limitType };
|
|
623
|
+
}
|
|
624
|
+
/** Create a math matrix. */
|
|
625
|
+
function mathMatrix(rows) {
|
|
626
|
+
return { type: "mathMatrix", rows };
|
|
627
|
+
}
|
|
628
|
+
/** Create a math accent (hat, tilde, etc.). */
|
|
629
|
+
function mathAccent(content, char) {
|
|
630
|
+
return { type: "mathAccent", content, char };
|
|
631
|
+
}
|
|
632
|
+
/** Create a math bar (overbar/underbar). */
|
|
633
|
+
function mathBar(content, position) {
|
|
634
|
+
return { type: "mathBar", content, position: position ?? "top" };
|
|
635
|
+
}
|
|
636
|
+
/** Create a math box. */
|
|
637
|
+
function mathBox(content) {
|
|
638
|
+
return { type: "mathBox", content };
|
|
639
|
+
}
|
|
640
|
+
/** Create a math equation array. */
|
|
641
|
+
function mathEquationArray(rows) {
|
|
642
|
+
return { type: "mathEquationArray", rows };
|
|
643
|
+
}
|
|
644
|
+
/** Create a symbol run. */
|
|
645
|
+
function symbol(font, char, properties) {
|
|
646
|
+
return { properties, content: [{ type: "symbol", font, char }] };
|
|
647
|
+
}
|
|
648
|
+
/** Create a floating image (body-level). */
|
|
649
|
+
function floatingImage(options) {
|
|
650
|
+
return {
|
|
651
|
+
type: "floatingImage",
|
|
652
|
+
rId: options.rId,
|
|
653
|
+
width: options.width,
|
|
654
|
+
height: options.height,
|
|
655
|
+
horizontalPosition: options.horizontalPosition ?? { relativeTo: "column", offset: 0 },
|
|
656
|
+
verticalPosition: options.verticalPosition ?? { relativeTo: "paragraph", offset: 0 },
|
|
657
|
+
wrap: options.wrap ?? { style: "square" },
|
|
658
|
+
altText: options.altText,
|
|
659
|
+
name: options.name,
|
|
660
|
+
behindDoc: options.behindDoc,
|
|
661
|
+
lockAnchor: options.lockAnchor,
|
|
662
|
+
layoutInCell: options.layoutInCell,
|
|
663
|
+
allowOverlap: options.allowOverlap,
|
|
664
|
+
simplePos: options.simplePos,
|
|
665
|
+
distT: options.distT,
|
|
666
|
+
distB: options.distB,
|
|
667
|
+
distL: options.distL,
|
|
668
|
+
distR: options.distR,
|
|
669
|
+
rotation: options.rotation,
|
|
670
|
+
flipHorizontal: options.flipHorizontal,
|
|
671
|
+
flipVertical: options.flipVertical,
|
|
672
|
+
srcRect: options.srcRect
|
|
673
|
+
};
|
|
674
|
+
}
|
|
675
|
+
/** Create a DrawingML shape. */
|
|
676
|
+
function drawingShape(options) {
|
|
677
|
+
return {
|
|
678
|
+
type: "drawingShape",
|
|
679
|
+
shapeType: options.shapeType,
|
|
680
|
+
width: options.width,
|
|
681
|
+
height: options.height,
|
|
682
|
+
fillColor: options.fillColor,
|
|
683
|
+
noFill: options.noFill,
|
|
684
|
+
outlineColor: options.outlineColor,
|
|
685
|
+
outlineWidth: options.outlineWidth,
|
|
686
|
+
noOutline: options.noOutline,
|
|
687
|
+
textContent: options.textContent,
|
|
688
|
+
altText: options.altText,
|
|
689
|
+
name: options.name,
|
|
690
|
+
horizontalPosition: options.horizontalPosition ?? { relativeTo: "column", offset: 0 },
|
|
691
|
+
verticalPosition: options.verticalPosition ?? { relativeTo: "paragraph", offset: 0 },
|
|
692
|
+
wrap: options.wrap ?? { style: "square" },
|
|
693
|
+
behindDoc: options.behindDoc,
|
|
694
|
+
rotation: options.rotation
|
|
695
|
+
};
|
|
696
|
+
}
|
|
697
|
+
/** Create a chart content block. */
|
|
698
|
+
function chart(options) {
|
|
699
|
+
return {
|
|
700
|
+
type: "chart",
|
|
701
|
+
chart: {
|
|
702
|
+
type: options.type,
|
|
703
|
+
series: options.series,
|
|
704
|
+
title: options.title,
|
|
705
|
+
legend: options.legend,
|
|
706
|
+
categoryAxis: options.categoryAxis,
|
|
707
|
+
valueAxis: options.valueAxis,
|
|
708
|
+
plotAreaColor: options.plotAreaColor,
|
|
709
|
+
chartAreaColor: options.chartAreaColor,
|
|
710
|
+
view3d: options.view3d,
|
|
711
|
+
style: options.style,
|
|
712
|
+
width: options.width,
|
|
713
|
+
height: options.height
|
|
714
|
+
},
|
|
715
|
+
altText: options.altText,
|
|
716
|
+
name: options.name
|
|
717
|
+
};
|
|
718
|
+
}
|
|
719
|
+
/** Create a structured document tag (content control). */
|
|
720
|
+
function structuredDocumentTag(content, properties) {
|
|
721
|
+
return { type: "sdt", properties: properties ?? {}, content };
|
|
722
|
+
}
|
|
723
|
+
// =============================================================================
|
|
724
|
+
// Table Builders
|
|
725
|
+
// =============================================================================
|
|
726
|
+
/** Shorthand border. */
|
|
727
|
+
function border(style = "single", size = 4, color = "auto") {
|
|
728
|
+
return { style, size, space: 0, color };
|
|
729
|
+
}
|
|
730
|
+
/** Create standard grid borders for a table. */
|
|
731
|
+
function gridBorders(size = 4, color = "auto") {
|
|
732
|
+
const b = border("single", size, color);
|
|
733
|
+
return { top: b, left: b, bottom: b, right: b, insideH: b, insideV: b };
|
|
734
|
+
}
|
|
735
|
+
/** Create a table cell. */
|
|
736
|
+
function cell(content, properties) {
|
|
737
|
+
if (typeof content === "string") {
|
|
738
|
+
return { properties, content: [textParagraph(content)] };
|
|
739
|
+
}
|
|
740
|
+
return { properties, content };
|
|
741
|
+
}
|
|
742
|
+
/** Create a table row. */
|
|
743
|
+
function row(cells, properties) {
|
|
744
|
+
return { properties, cells };
|
|
745
|
+
}
|
|
746
|
+
/** Create a table. */
|
|
747
|
+
function table(rows, properties, columnWidths) {
|
|
748
|
+
return { type: "table", properties, columnWidths, rows };
|
|
749
|
+
}
|
|
750
|
+
/** Create a simple table from a 2D string array. */
|
|
751
|
+
function simpleTable(data, options) {
|
|
752
|
+
const opts = { headerRow: true, borders: true, ...options };
|
|
753
|
+
const tableRows = data.map((rowData, rowIndex) => {
|
|
754
|
+
const cells = rowData.map(cellText => cell(cellText));
|
|
755
|
+
return row(cells, rowIndex === 0 && opts.headerRow ? { tableHeader: true } : undefined);
|
|
756
|
+
});
|
|
757
|
+
return table(tableRows, {
|
|
758
|
+
width: opts.width ?? { value: 5000, type: "pct" },
|
|
759
|
+
borders: opts.borders ? gridBorders() : undefined
|
|
760
|
+
}, opts.columnWidths);
|
|
761
|
+
}
|
|
762
|
+
// =============================================================================
|
|
763
|
+
// Document Builder Class
|
|
764
|
+
// =============================================================================
|
|
765
|
+
/**
|
|
766
|
+
* Fluent builder for constructing DOCX documents.
|
|
767
|
+
*
|
|
768
|
+
* @example
|
|
769
|
+
* ```ts
|
|
770
|
+
* const doc = new DocumentBuilder()
|
|
771
|
+
* .addHeading("Hello World", 1)
|
|
772
|
+
* .addParagraph("This is a paragraph.")
|
|
773
|
+
* .addTable([["Name", "Age"], ["Alice", "30"]])
|
|
774
|
+
* .build();
|
|
775
|
+
*
|
|
776
|
+
* const bytes = await doc.toBuffer();
|
|
777
|
+
* ```
|
|
778
|
+
*/
|
|
779
|
+
class DocumentBuilder {
|
|
780
|
+
constructor() {
|
|
781
|
+
this._body = [];
|
|
782
|
+
this._styles = [];
|
|
783
|
+
this._abstractNumberings = [];
|
|
784
|
+
this._numberingInstances = [];
|
|
785
|
+
this._headers = new Map();
|
|
786
|
+
this._footers = new Map();
|
|
787
|
+
this._footnotes = [];
|
|
788
|
+
this._endnotes = [];
|
|
789
|
+
this._images = [];
|
|
790
|
+
this._fonts = [];
|
|
791
|
+
this._comments = [];
|
|
792
|
+
this._customProperties = [];
|
|
793
|
+
this._nextImageId = 1;
|
|
794
|
+
this._nextFootnoteId = 1;
|
|
795
|
+
this._nextEndnoteId = 1;
|
|
796
|
+
this._nextBookmarkId = 0;
|
|
797
|
+
this._nextAbstractNumId = 0;
|
|
798
|
+
this._nextNumId = 1;
|
|
799
|
+
this._nextDrawingId = 1;
|
|
800
|
+
this._nextCommentId = 0;
|
|
801
|
+
}
|
|
802
|
+
/** Add raw body content. */
|
|
803
|
+
addContent(content) {
|
|
804
|
+
this._body.push(content);
|
|
805
|
+
return this;
|
|
806
|
+
}
|
|
807
|
+
/** Add a paragraph with runs. */
|
|
808
|
+
addParagraphElement(para) {
|
|
809
|
+
this._body.push(para);
|
|
810
|
+
return this;
|
|
811
|
+
}
|
|
812
|
+
/** Add a simple text paragraph. */
|
|
813
|
+
addParagraph(content, properties) {
|
|
814
|
+
this._body.push(textParagraph(content, properties));
|
|
815
|
+
return this;
|
|
816
|
+
}
|
|
817
|
+
/** Add a heading. */
|
|
818
|
+
addHeading(content, level = 1) {
|
|
819
|
+
this._body.push(heading(content, level));
|
|
820
|
+
return this;
|
|
821
|
+
}
|
|
822
|
+
/** Add a page break. */
|
|
823
|
+
addPageBreak() {
|
|
824
|
+
this._body.push(paragraph([pageBreak()]));
|
|
825
|
+
return this;
|
|
826
|
+
}
|
|
827
|
+
/** Add a table from a 2D array. */
|
|
828
|
+
addTable(data, options) {
|
|
829
|
+
this._body.push(simpleTable(data, options));
|
|
830
|
+
return this;
|
|
831
|
+
}
|
|
832
|
+
/** Add a table element. */
|
|
833
|
+
addTableElement(tbl) {
|
|
834
|
+
this._body.push(tbl);
|
|
835
|
+
return this;
|
|
836
|
+
}
|
|
837
|
+
/** Add an inline image. Returns the image relationship ID and drawing ID. */
|
|
838
|
+
addImage(data, mediaType, width, height, options) {
|
|
839
|
+
const fileName = `image${this._nextImageId}.${mediaType}`;
|
|
840
|
+
const rId = `__img_${this._nextImageId}`;
|
|
841
|
+
const drawingId = this._nextDrawingId++;
|
|
842
|
+
this._images.push({ data, mediaType, fileName, rId });
|
|
843
|
+
this._body.push(paragraph([
|
|
844
|
+
{
|
|
845
|
+
content: [
|
|
846
|
+
{
|
|
847
|
+
type: "image",
|
|
848
|
+
rId,
|
|
849
|
+
width,
|
|
850
|
+
height,
|
|
851
|
+
altText: options?.altText,
|
|
852
|
+
name: options?.name ?? `Picture ${this._nextImageId}`,
|
|
853
|
+
drawingId
|
|
854
|
+
}
|
|
855
|
+
]
|
|
856
|
+
}
|
|
857
|
+
]));
|
|
858
|
+
this._nextImageId++;
|
|
859
|
+
return { rId, drawingId };
|
|
860
|
+
}
|
|
861
|
+
/** Add a floating image. Returns the image relationship ID. */
|
|
862
|
+
addFloatingImage(data, mediaType, width, height, options) {
|
|
863
|
+
const fileName = `image${this._nextImageId}.${mediaType}`;
|
|
864
|
+
const rId = `__img_${this._nextImageId}`;
|
|
865
|
+
this._images.push({ data, mediaType, fileName, rId });
|
|
866
|
+
this._body.push(floatingImage({
|
|
867
|
+
rId,
|
|
868
|
+
width,
|
|
869
|
+
height,
|
|
870
|
+
altText: options?.altText,
|
|
871
|
+
name: options?.name ?? `Picture ${this._nextImageId}`,
|
|
872
|
+
horizontalPosition: options?.horizontalPosition,
|
|
873
|
+
verticalPosition: options?.verticalPosition,
|
|
874
|
+
wrap: options?.wrap,
|
|
875
|
+
behindDoc: options?.behindDoc,
|
|
876
|
+
lockAnchor: options?.lockAnchor,
|
|
877
|
+
layoutInCell: options?.layoutInCell,
|
|
878
|
+
allowOverlap: options?.allowOverlap,
|
|
879
|
+
distT: options?.distT,
|
|
880
|
+
distB: options?.distB,
|
|
881
|
+
distL: options?.distL,
|
|
882
|
+
distR: options?.distR,
|
|
883
|
+
rotation: options?.rotation,
|
|
884
|
+
flipHorizontal: options?.flipHorizontal,
|
|
885
|
+
flipVertical: options?.flipVertical
|
|
886
|
+
}));
|
|
887
|
+
this._nextImageId++;
|
|
888
|
+
return rId;
|
|
889
|
+
}
|
|
890
|
+
/** Add a custom font definition. */
|
|
891
|
+
addFont(font) {
|
|
892
|
+
this._fonts.push(font);
|
|
893
|
+
return this;
|
|
894
|
+
}
|
|
895
|
+
/** Set a text watermark on the document. */
|
|
896
|
+
setWatermark(watermark) {
|
|
897
|
+
this._watermark = watermark;
|
|
898
|
+
return this;
|
|
899
|
+
}
|
|
900
|
+
/** Add a footnote. Returns the footnote ID. */
|
|
901
|
+
addFootnote(content) {
|
|
902
|
+
const id = this._nextFootnoteId++;
|
|
903
|
+
const paras = typeof content === "string" ? [textParagraph(content)] : content;
|
|
904
|
+
this._footnotes.push({ id, content: paras });
|
|
905
|
+
return id;
|
|
906
|
+
}
|
|
907
|
+
/** Add an endnote. Returns the endnote ID. */
|
|
908
|
+
addEndnote(content) {
|
|
909
|
+
const id = this._nextEndnoteId++;
|
|
910
|
+
const paras = typeof content === "string" ? [textParagraph(content)] : content;
|
|
911
|
+
this._endnotes.push({ id, content: paras });
|
|
912
|
+
return id;
|
|
913
|
+
}
|
|
914
|
+
/** Add a comment. Returns the comment ID. */
|
|
915
|
+
addComment(author, content, options) {
|
|
916
|
+
const id = this._nextCommentId++;
|
|
917
|
+
const paras = typeof content === "string" ? [textParagraph(content)] : content;
|
|
918
|
+
this._comments.push({
|
|
919
|
+
id,
|
|
920
|
+
author,
|
|
921
|
+
date: options?.date,
|
|
922
|
+
initials: options?.initials,
|
|
923
|
+
content: paras
|
|
924
|
+
});
|
|
925
|
+
return id;
|
|
926
|
+
}
|
|
927
|
+
/** Add a Table of Contents. */
|
|
928
|
+
addTableOfContents(options) {
|
|
929
|
+
this._body.push({
|
|
930
|
+
type: "tableOfContents",
|
|
931
|
+
headingStyleRange: options?.headingStyleRange ?? "1-3",
|
|
932
|
+
hyperlink: options?.hyperlink ?? true,
|
|
933
|
+
...options
|
|
934
|
+
});
|
|
935
|
+
return this;
|
|
936
|
+
}
|
|
937
|
+
/** Add a math equation block. */
|
|
938
|
+
addMath(content) {
|
|
939
|
+
this._body.push(mathBlock(content));
|
|
940
|
+
return this;
|
|
941
|
+
}
|
|
942
|
+
/** Add a text box. */
|
|
943
|
+
addTextBox(content, options) {
|
|
944
|
+
const paras = typeof content === "string" ? [textParagraph(content)] : content;
|
|
945
|
+
this._body.push({
|
|
946
|
+
type: "textBox",
|
|
947
|
+
content: paras,
|
|
948
|
+
width: options?.width,
|
|
949
|
+
height: options?.height,
|
|
950
|
+
stroke: options?.stroke,
|
|
951
|
+
fill: options?.fill
|
|
952
|
+
});
|
|
953
|
+
return this;
|
|
954
|
+
}
|
|
955
|
+
/** Add a bullet list. */
|
|
956
|
+
addBulletList(items, level = 0) {
|
|
957
|
+
// Create abstract numbering for bullets if not exists
|
|
958
|
+
let bulletAbsId = this._abstractNumberings.find(a => a.levels[0]?.format === "bullet")?.abstractNumId;
|
|
959
|
+
if (bulletAbsId === undefined) {
|
|
960
|
+
bulletAbsId = this._nextAbstractNumId++;
|
|
961
|
+
this._abstractNumberings.push({
|
|
962
|
+
abstractNumId: bulletAbsId,
|
|
963
|
+
multiLevelType: "hybridMultilevel",
|
|
964
|
+
levels: [
|
|
965
|
+
{
|
|
966
|
+
level: 0,
|
|
967
|
+
start: 1,
|
|
968
|
+
format: "bullet",
|
|
969
|
+
text: "\uF0B7",
|
|
970
|
+
justification: "left",
|
|
971
|
+
paragraphProperties: { indent: { left: 720, hanging: 360 } },
|
|
972
|
+
runProperties: { font: { ascii: "Symbol", hAnsi: "Symbol" } }
|
|
973
|
+
},
|
|
974
|
+
{
|
|
975
|
+
level: 1,
|
|
976
|
+
start: 1,
|
|
977
|
+
format: "bullet",
|
|
978
|
+
text: "o",
|
|
979
|
+
justification: "left",
|
|
980
|
+
paragraphProperties: { indent: { left: 1440, hanging: 360 } },
|
|
981
|
+
runProperties: { font: { ascii: "Courier New", hAnsi: "Courier New" } }
|
|
982
|
+
},
|
|
983
|
+
{
|
|
984
|
+
level: 2,
|
|
985
|
+
start: 1,
|
|
986
|
+
format: "bullet",
|
|
987
|
+
text: "\uF0A7",
|
|
988
|
+
justification: "left",
|
|
989
|
+
paragraphProperties: { indent: { left: 2160, hanging: 360 } },
|
|
990
|
+
runProperties: { font: { ascii: "Wingdings", hAnsi: "Wingdings" } }
|
|
991
|
+
}
|
|
992
|
+
]
|
|
993
|
+
});
|
|
994
|
+
this._numberingInstances.push({
|
|
995
|
+
numId: this._nextNumId++,
|
|
996
|
+
abstractNumId: bulletAbsId
|
|
997
|
+
});
|
|
998
|
+
}
|
|
999
|
+
const numId = this._numberingInstances.find(n => n.abstractNumId === bulletAbsId).numId;
|
|
1000
|
+
for (const item of items) {
|
|
1001
|
+
this._body.push(textParagraph(item, { numbering: { numId, level } }));
|
|
1002
|
+
}
|
|
1003
|
+
return this;
|
|
1004
|
+
}
|
|
1005
|
+
/** Add a numbered list. */
|
|
1006
|
+
addNumberedList(items, level = 0) {
|
|
1007
|
+
let numAbsId = this._abstractNumberings.find(a => a.levels[0]?.format === "decimal")?.abstractNumId;
|
|
1008
|
+
if (numAbsId === undefined) {
|
|
1009
|
+
numAbsId = this._nextAbstractNumId++;
|
|
1010
|
+
this._abstractNumberings.push({
|
|
1011
|
+
abstractNumId: numAbsId,
|
|
1012
|
+
multiLevelType: "hybridMultilevel",
|
|
1013
|
+
levels: [
|
|
1014
|
+
{
|
|
1015
|
+
level: 0,
|
|
1016
|
+
start: 1,
|
|
1017
|
+
format: "decimal",
|
|
1018
|
+
text: "%1.",
|
|
1019
|
+
justification: "left",
|
|
1020
|
+
paragraphProperties: { indent: { left: 720, hanging: 360 } }
|
|
1021
|
+
},
|
|
1022
|
+
{
|
|
1023
|
+
level: 1,
|
|
1024
|
+
start: 1,
|
|
1025
|
+
format: "lowerLetter",
|
|
1026
|
+
text: "%2.",
|
|
1027
|
+
justification: "left",
|
|
1028
|
+
paragraphProperties: { indent: { left: 1440, hanging: 360 } }
|
|
1029
|
+
},
|
|
1030
|
+
{
|
|
1031
|
+
level: 2,
|
|
1032
|
+
start: 1,
|
|
1033
|
+
format: "lowerRoman",
|
|
1034
|
+
text: "%3.",
|
|
1035
|
+
justification: "right",
|
|
1036
|
+
paragraphProperties: { indent: { left: 2160, hanging: 180 } }
|
|
1037
|
+
}
|
|
1038
|
+
]
|
|
1039
|
+
});
|
|
1040
|
+
this._numberingInstances.push({
|
|
1041
|
+
numId: this._nextNumId++,
|
|
1042
|
+
abstractNumId: numAbsId
|
|
1043
|
+
});
|
|
1044
|
+
}
|
|
1045
|
+
const numId = this._numberingInstances.find(n => n.abstractNumId === numAbsId).numId;
|
|
1046
|
+
for (const item of items) {
|
|
1047
|
+
this._body.push(textParagraph(item, { numbering: { numId, level } }));
|
|
1048
|
+
}
|
|
1049
|
+
return this;
|
|
1050
|
+
}
|
|
1051
|
+
/** Set section properties (page size, margins, etc.). */
|
|
1052
|
+
setSectionProperties(props) {
|
|
1053
|
+
this._sectionProperties = props;
|
|
1054
|
+
return this;
|
|
1055
|
+
}
|
|
1056
|
+
/** Set document defaults. */
|
|
1057
|
+
setDocDefaults(defaults) {
|
|
1058
|
+
this._docDefaults = defaults;
|
|
1059
|
+
return this;
|
|
1060
|
+
}
|
|
1061
|
+
/** Add a style definition. */
|
|
1062
|
+
addStyle(style) {
|
|
1063
|
+
this._styles.push(style);
|
|
1064
|
+
return this;
|
|
1065
|
+
}
|
|
1066
|
+
/** Set default styles (Normal, Heading1-6, Hyperlink, etc.). */
|
|
1067
|
+
useDefaultStyles() {
|
|
1068
|
+
this._docDefaults = {
|
|
1069
|
+
runProperties: {
|
|
1070
|
+
font: { ascii: "Calibri", hAnsi: "Calibri", eastAsia: "SimSun", cs: "Times New Roman" },
|
|
1071
|
+
size: 22,
|
|
1072
|
+
sizeCs: 22,
|
|
1073
|
+
language: { val: "en-US" }
|
|
1074
|
+
},
|
|
1075
|
+
paragraphProperties: {
|
|
1076
|
+
spacing: { after: 160, line: 259, lineRule: "auto" }
|
|
1077
|
+
}
|
|
1078
|
+
};
|
|
1079
|
+
this._styles.push({ type: "paragraph", styleId: "Normal", name: "Normal", isDefault: true, qFormat: true }, {
|
|
1080
|
+
type: "paragraph",
|
|
1081
|
+
styleId: "Heading1",
|
|
1082
|
+
name: "heading 1",
|
|
1083
|
+
basedOn: "Normal",
|
|
1084
|
+
next: "Normal",
|
|
1085
|
+
qFormat: true,
|
|
1086
|
+
uiPriority: 9,
|
|
1087
|
+
paragraphProperties: {
|
|
1088
|
+
keepNext: true,
|
|
1089
|
+
keepLines: true,
|
|
1090
|
+
spacing: { before: 240, after: 0 }
|
|
1091
|
+
},
|
|
1092
|
+
runProperties: { font: "Calibri Light", color: "2F5496", size: 32 }
|
|
1093
|
+
}, {
|
|
1094
|
+
type: "paragraph",
|
|
1095
|
+
styleId: "Heading2",
|
|
1096
|
+
name: "heading 2",
|
|
1097
|
+
basedOn: "Normal",
|
|
1098
|
+
next: "Normal",
|
|
1099
|
+
qFormat: true,
|
|
1100
|
+
uiPriority: 9,
|
|
1101
|
+
paragraphProperties: { keepNext: true, keepLines: true, spacing: { before: 40, after: 0 } },
|
|
1102
|
+
runProperties: { font: "Calibri Light", color: "2F5496", size: 26 }
|
|
1103
|
+
}, {
|
|
1104
|
+
type: "paragraph",
|
|
1105
|
+
styleId: "Heading3",
|
|
1106
|
+
name: "heading 3",
|
|
1107
|
+
basedOn: "Normal",
|
|
1108
|
+
next: "Normal",
|
|
1109
|
+
qFormat: true,
|
|
1110
|
+
uiPriority: 9,
|
|
1111
|
+
paragraphProperties: { keepNext: true, keepLines: true, spacing: { before: 40, after: 0 } },
|
|
1112
|
+
runProperties: { font: "Calibri Light", color: "1F3763", size: 24 }
|
|
1113
|
+
}, {
|
|
1114
|
+
type: "character",
|
|
1115
|
+
styleId: "Hyperlink",
|
|
1116
|
+
name: "Hyperlink",
|
|
1117
|
+
uiPriority: 99,
|
|
1118
|
+
runProperties: { color: "0563C1", underline: "single" }
|
|
1119
|
+
}, {
|
|
1120
|
+
type: "table",
|
|
1121
|
+
styleId: "TableGrid",
|
|
1122
|
+
name: "Table Grid",
|
|
1123
|
+
basedOn: "TableNormal",
|
|
1124
|
+
uiPriority: 39,
|
|
1125
|
+
tableProperties: { borders: gridBorders(4, "auto") }
|
|
1126
|
+
});
|
|
1127
|
+
return this;
|
|
1128
|
+
}
|
|
1129
|
+
/** Set a header for the given type. */
|
|
1130
|
+
setHeader(type, content) {
|
|
1131
|
+
this._headers.set(type, { content });
|
|
1132
|
+
return this;
|
|
1133
|
+
}
|
|
1134
|
+
/** Set a footer for the given type. */
|
|
1135
|
+
setFooter(type, content) {
|
|
1136
|
+
this._footers.set(type, { content });
|
|
1137
|
+
return this;
|
|
1138
|
+
}
|
|
1139
|
+
/** Set document settings. */
|
|
1140
|
+
setSettings(settings) {
|
|
1141
|
+
this._settings = settings;
|
|
1142
|
+
return this;
|
|
1143
|
+
}
|
|
1144
|
+
/** Set core properties (metadata). */
|
|
1145
|
+
setCoreProperties(props) {
|
|
1146
|
+
this._coreProperties = props;
|
|
1147
|
+
return this;
|
|
1148
|
+
}
|
|
1149
|
+
/** Set application properties. */
|
|
1150
|
+
setAppProperties(props) {
|
|
1151
|
+
this._appProperties = props;
|
|
1152
|
+
return this;
|
|
1153
|
+
}
|
|
1154
|
+
/** Set document background. */
|
|
1155
|
+
setBackground(background) {
|
|
1156
|
+
this._background = background;
|
|
1157
|
+
return this;
|
|
1158
|
+
}
|
|
1159
|
+
/** Add a custom document property. */
|
|
1160
|
+
addCustomProperty(name, value) {
|
|
1161
|
+
this._customProperties.push({ name, value });
|
|
1162
|
+
return this;
|
|
1163
|
+
}
|
|
1164
|
+
/** Add a section break with properties. */
|
|
1165
|
+
addSectionBreak(props) {
|
|
1166
|
+
// Insert as the last paragraph's section properties
|
|
1167
|
+
if (this._body.length > 0) {
|
|
1168
|
+
const last = this._body[this._body.length - 1];
|
|
1169
|
+
if (last.type === "paragraph") {
|
|
1170
|
+
const existingProps = last.properties ?? {};
|
|
1171
|
+
this._body[this._body.length - 1] = {
|
|
1172
|
+
...last,
|
|
1173
|
+
properties: { ...existingProps, sectionProperties: props }
|
|
1174
|
+
};
|
|
1175
|
+
return this;
|
|
1176
|
+
}
|
|
1177
|
+
}
|
|
1178
|
+
// If no previous paragraph, add an empty one with section properties
|
|
1179
|
+
this._body.push(paragraph([], { sectionProperties: props }));
|
|
1180
|
+
return this;
|
|
1181
|
+
}
|
|
1182
|
+
/** Get next available bookmark ID. */
|
|
1183
|
+
nextBookmarkId() {
|
|
1184
|
+
return this._nextBookmarkId++;
|
|
1185
|
+
}
|
|
1186
|
+
/** Build the DocxDocument model. */
|
|
1187
|
+
build() {
|
|
1188
|
+
return {
|
|
1189
|
+
body: this._body,
|
|
1190
|
+
sectionProperties: this._sectionProperties ?? {
|
|
1191
|
+
pageSize: { width: 12240, height: 15840 },
|
|
1192
|
+
margins: { top: 1440, right: 1440, bottom: 1440, left: 1440 }
|
|
1193
|
+
},
|
|
1194
|
+
styles: this._styles.length > 0 ? this._styles : undefined,
|
|
1195
|
+
docDefaults: this._docDefaults,
|
|
1196
|
+
abstractNumberings: this._abstractNumberings.length > 0 ? this._abstractNumberings : undefined,
|
|
1197
|
+
numberingInstances: this._numberingInstances.length > 0 ? this._numberingInstances : undefined,
|
|
1198
|
+
headers: this._headers.size > 0 ? this._headers : undefined,
|
|
1199
|
+
footers: this._footers.size > 0 ? this._footers : undefined,
|
|
1200
|
+
footnotes: this._footnotes.length > 0 ? this._footnotes : undefined,
|
|
1201
|
+
endnotes: this._endnotes.length > 0 ? this._endnotes : undefined,
|
|
1202
|
+
images: this._images.length > 0 ? this._images : undefined,
|
|
1203
|
+
fonts: this._fonts.length > 0 ? this._fonts : undefined,
|
|
1204
|
+
settings: this._settings,
|
|
1205
|
+
coreProperties: this._coreProperties,
|
|
1206
|
+
appProperties: this._appProperties,
|
|
1207
|
+
comments: this._comments.length > 0 ? this._comments : undefined,
|
|
1208
|
+
background: this._background,
|
|
1209
|
+
customProperties: this._customProperties.length > 0 ? this._customProperties : undefined,
|
|
1210
|
+
watermark: this._watermark
|
|
1211
|
+
};
|
|
1212
|
+
}
|
|
1213
|
+
/** Build and package to DOCX bytes. */
|
|
1214
|
+
async toBuffer(compressionLevel) {
|
|
1215
|
+
return (0, docx_packager_1.packageDocx)(this.build(), compressionLevel);
|
|
1216
|
+
}
|
|
1217
|
+
/** Build and package to base64 string. */
|
|
1218
|
+
async toBase64(compressionLevel) {
|
|
1219
|
+
const bytes = await this.toBuffer(compressionLevel);
|
|
1220
|
+
return (0, internal_utils_1.bytesToBase64)(bytes);
|
|
1221
|
+
}
|
|
1222
|
+
}
|
|
1223
|
+
exports.DocumentBuilder = DocumentBuilder;
|
|
1224
|
+
// =============================================================================
|
|
1225
|
+
// Theme Color Resolution
|
|
1226
|
+
// =============================================================================
|
|
1227
|
+
/**
|
|
1228
|
+
* Map OOXML theme color attribute names to theme color scheme keys.
|
|
1229
|
+
* Word uses different names in run/paragraph properties vs the theme XML.
|
|
1230
|
+
*/
|
|
1231
|
+
const THEME_COLOR_MAP = {
|
|
1232
|
+
dark1: "dk1",
|
|
1233
|
+
light1: "lt1",
|
|
1234
|
+
dark2: "dk2",
|
|
1235
|
+
light2: "lt2",
|
|
1236
|
+
accent1: "accent1",
|
|
1237
|
+
accent2: "accent2",
|
|
1238
|
+
accent3: "accent3",
|
|
1239
|
+
accent4: "accent4",
|
|
1240
|
+
accent5: "accent5",
|
|
1241
|
+
accent6: "accent6",
|
|
1242
|
+
hyperlink: "hlink",
|
|
1243
|
+
followedHyperlink: "folHlink",
|
|
1244
|
+
// Direct names also work
|
|
1245
|
+
dk1: "dk1",
|
|
1246
|
+
lt1: "lt1",
|
|
1247
|
+
dk2: "dk2",
|
|
1248
|
+
lt2: "lt2",
|
|
1249
|
+
hlink: "hlink",
|
|
1250
|
+
folHlink: "folHlink"
|
|
1251
|
+
};
|
|
1252
|
+
/**
|
|
1253
|
+
* Resolve a ColorSpec to an actual hex RGB color using the document theme.
|
|
1254
|
+
*
|
|
1255
|
+
* Applies theme color lookup + tint/shade transformations per OOXML spec.
|
|
1256
|
+
*
|
|
1257
|
+
* @param color - The color value (HexColor string or ColorSpec).
|
|
1258
|
+
* @param theme - The document theme (from `doc.theme`).
|
|
1259
|
+
* @returns Resolved hex color string (6 chars, no #), or undefined if unresolvable.
|
|
1260
|
+
*/
|
|
1261
|
+
function resolveThemeColor(color, theme) {
|
|
1262
|
+
if (color === undefined) {
|
|
1263
|
+
return undefined;
|
|
1264
|
+
}
|
|
1265
|
+
if (typeof color === "string") {
|
|
1266
|
+
return color;
|
|
1267
|
+
}
|
|
1268
|
+
// ColorSpec with val — use directly
|
|
1269
|
+
if (color.val && color.val !== "auto") {
|
|
1270
|
+
return color.val;
|
|
1271
|
+
}
|
|
1272
|
+
// Resolve via theme
|
|
1273
|
+
if (!color.themeColor || !theme) {
|
|
1274
|
+
return color.val;
|
|
1275
|
+
}
|
|
1276
|
+
const key = THEME_COLOR_MAP[color.themeColor] ?? color.themeColor;
|
|
1277
|
+
const base = theme.colorScheme.colors[key];
|
|
1278
|
+
if (!base) {
|
|
1279
|
+
return color.val;
|
|
1280
|
+
}
|
|
1281
|
+
// Apply tint or shade
|
|
1282
|
+
if (color.themeTint) {
|
|
1283
|
+
return applyTint(base, parseInt(color.themeTint, 16) / 255);
|
|
1284
|
+
}
|
|
1285
|
+
if (color.themeShade) {
|
|
1286
|
+
return applyShade(base, parseInt(color.themeShade, 16) / 255);
|
|
1287
|
+
}
|
|
1288
|
+
return base;
|
|
1289
|
+
}
|
|
1290
|
+
/** Apply tint to a hex color. tint=1 → white, tint=0 → original. */
|
|
1291
|
+
function applyTint(hex, tint) {
|
|
1292
|
+
const r = parseInt(hex.slice(0, 2), 16);
|
|
1293
|
+
const g = parseInt(hex.slice(2, 4), 16);
|
|
1294
|
+
const b = parseInt(hex.slice(4, 6), 16);
|
|
1295
|
+
const nr = Math.round(r + (255 - r) * tint);
|
|
1296
|
+
const ng = Math.round(g + (255 - g) * tint);
|
|
1297
|
+
const nb = Math.round(b + (255 - b) * tint);
|
|
1298
|
+
return toHex2(nr) + toHex2(ng) + toHex2(nb);
|
|
1299
|
+
}
|
|
1300
|
+
/** Apply shade to a hex color. shade=1 → original, shade=0 → black. */
|
|
1301
|
+
function applyShade(hex, shade) {
|
|
1302
|
+
const r = parseInt(hex.slice(0, 2), 16);
|
|
1303
|
+
const g = parseInt(hex.slice(2, 4), 16);
|
|
1304
|
+
const b = parseInt(hex.slice(4, 6), 16);
|
|
1305
|
+
const nr = Math.round(r * shade);
|
|
1306
|
+
const ng = Math.round(g * shade);
|
|
1307
|
+
const nb = Math.round(b * shade);
|
|
1308
|
+
return toHex2(nr) + toHex2(ng) + toHex2(nb);
|
|
1309
|
+
}
|
|
1310
|
+
function toHex2(n) {
|
|
1311
|
+
const h = Math.max(0, Math.min(255, n)).toString(16);
|
|
1312
|
+
return h.length < 2 ? "0" + h : h;
|
|
1313
|
+
}
|
|
1314
|
+
/** Extract concatenated plain text from a paragraph's runs. */
|
|
1315
|
+
function paragraphText(para) {
|
|
1316
|
+
let text = "";
|
|
1317
|
+
for (const child of para.children) {
|
|
1318
|
+
if ("content" in child && Array.isArray(child.content)) {
|
|
1319
|
+
for (const c of child.content) {
|
|
1320
|
+
if ("type" in c && c.type === "text" && "text" in c) {
|
|
1321
|
+
text += c.text;
|
|
1322
|
+
}
|
|
1323
|
+
}
|
|
1324
|
+
}
|
|
1325
|
+
}
|
|
1326
|
+
return text;
|
|
1327
|
+
}
|
|
1328
|
+
// =============================================================================
|
|
1329
|
+
// Document Query API (read-only helpers)
|
|
1330
|
+
// =============================================================================
|
|
1331
|
+
/**
|
|
1332
|
+
* Count all top-level paragraphs in the document body.
|
|
1333
|
+
*/
|
|
1334
|
+
function paragraphCount(doc) {
|
|
1335
|
+
let count = 0;
|
|
1336
|
+
for (const block of doc.body) {
|
|
1337
|
+
if (block.type === "paragraph") {
|
|
1338
|
+
count++;
|
|
1339
|
+
}
|
|
1340
|
+
}
|
|
1341
|
+
return count;
|
|
1342
|
+
}
|
|
1343
|
+
/**
|
|
1344
|
+
* Count words across all paragraphs in the document body.
|
|
1345
|
+
* Uses simple whitespace splitting; for East Asian text, each CJK character
|
|
1346
|
+
* is counted as one "word" to approximate meaningful unit count.
|
|
1347
|
+
*/
|
|
1348
|
+
function countWords(doc) {
|
|
1349
|
+
let count = 0;
|
|
1350
|
+
const cjkRe = /[\u4e00-\u9fff\u3040-\u30ff\uac00-\ud7af]/g;
|
|
1351
|
+
const walkParagraphs = (blocks) => {
|
|
1352
|
+
for (const block of blocks) {
|
|
1353
|
+
if (block.type === "paragraph") {
|
|
1354
|
+
const text = paragraphText(block);
|
|
1355
|
+
// Count CJK chars + latin word-like tokens
|
|
1356
|
+
const cjkCount = (text.match(cjkRe) ?? []).length;
|
|
1357
|
+
const latin = text.replace(cjkRe, " ").trim();
|
|
1358
|
+
const latinCount = latin ? latin.split(/\s+/).length : 0;
|
|
1359
|
+
count += cjkCount + latinCount;
|
|
1360
|
+
}
|
|
1361
|
+
else if (block.type === "table") {
|
|
1362
|
+
for (const row of block.rows) {
|
|
1363
|
+
for (const cell of row.cells) {
|
|
1364
|
+
walkParagraphs(cell.content);
|
|
1365
|
+
}
|
|
1366
|
+
}
|
|
1367
|
+
}
|
|
1368
|
+
else if (block.type === "sdt") {
|
|
1369
|
+
const filtered = block.content.filter(c => "type" in c && (c.type === "paragraph" || c.type === "table"));
|
|
1370
|
+
walkParagraphs(filtered);
|
|
1371
|
+
}
|
|
1372
|
+
}
|
|
1373
|
+
};
|
|
1374
|
+
walkParagraphs(doc.body);
|
|
1375
|
+
return count;
|
|
1376
|
+
}
|
|
1377
|
+
/**
|
|
1378
|
+
* Extract the heading outline from a document.
|
|
1379
|
+
*
|
|
1380
|
+
* Matches paragraphs whose style is `Heading1` through `Heading9` (case-insensitive),
|
|
1381
|
+
* or whose `outlineLevel` property is set (0-8).
|
|
1382
|
+
*/
|
|
1383
|
+
function getHeadings(doc) {
|
|
1384
|
+
const out = [];
|
|
1385
|
+
doc.body.forEach((block, i) => {
|
|
1386
|
+
if (block.type !== "paragraph") {
|
|
1387
|
+
return;
|
|
1388
|
+
}
|
|
1389
|
+
const style = block.properties?.style;
|
|
1390
|
+
const styleMatch = style ? /^Heading\s*(\d)$/i.exec(style) : null;
|
|
1391
|
+
let level;
|
|
1392
|
+
if (styleMatch) {
|
|
1393
|
+
level = parseInt(styleMatch[1], 10);
|
|
1394
|
+
}
|
|
1395
|
+
else if (block.properties?.outlineLevel !== undefined && block.properties.outlineLevel < 9) {
|
|
1396
|
+
level = block.properties.outlineLevel + 1;
|
|
1397
|
+
}
|
|
1398
|
+
if (level !== undefined && level >= 1 && level <= 9) {
|
|
1399
|
+
out.push({
|
|
1400
|
+
level,
|
|
1401
|
+
text: paragraphText(block),
|
|
1402
|
+
paragraphIndex: i,
|
|
1403
|
+
style
|
|
1404
|
+
});
|
|
1405
|
+
}
|
|
1406
|
+
});
|
|
1407
|
+
return out;
|
|
1408
|
+
}
|
|
1409
|
+
/**
|
|
1410
|
+
* Find a bookmark by name.
|
|
1411
|
+
*
|
|
1412
|
+
* @returns The bookmark start marker + its location, or `undefined` if not found.
|
|
1413
|
+
*/
|
|
1414
|
+
function findBookmark(doc, name) {
|
|
1415
|
+
for (let i = 0; i < doc.body.length; i++) {
|
|
1416
|
+
const block = doc.body[i];
|
|
1417
|
+
if (block.type !== "paragraph") {
|
|
1418
|
+
continue;
|
|
1419
|
+
}
|
|
1420
|
+
for (let j = 0; j < block.children.length; j++) {
|
|
1421
|
+
const ch = block.children[j];
|
|
1422
|
+
if ("type" in ch && ch.type === "bookmarkStart" && ch.name === name) {
|
|
1423
|
+
return { bookmark: ch, paragraphIndex: i, childIndex: j };
|
|
1424
|
+
}
|
|
1425
|
+
}
|
|
1426
|
+
}
|
|
1427
|
+
return undefined;
|
|
1428
|
+
}
|
|
1429
|
+
/**
|
|
1430
|
+
* Find a comment by its ID.
|
|
1431
|
+
*/
|
|
1432
|
+
function findComment(doc, id) {
|
|
1433
|
+
return doc.comments?.find(c => c.id === id);
|
|
1434
|
+
}
|
|
1435
|
+
/**
|
|
1436
|
+
* List all images registered in the document.
|
|
1437
|
+
*/
|
|
1438
|
+
function listImages(doc) {
|
|
1439
|
+
return doc.images ?? [];
|
|
1440
|
+
}
|
|
1441
|
+
/**
|
|
1442
|
+
* List all tables in the document body (top-level only).
|
|
1443
|
+
*/
|
|
1444
|
+
function listTables(doc) {
|
|
1445
|
+
return doc.body.filter((b) => b.type === "table");
|
|
1446
|
+
}
|
|
1447
|
+
/**
|
|
1448
|
+
* Collect all hyperlinks in the document body.
|
|
1449
|
+
*/
|
|
1450
|
+
function listHyperlinks(doc) {
|
|
1451
|
+
const out = [];
|
|
1452
|
+
const walk = (children) => {
|
|
1453
|
+
for (const ch of children) {
|
|
1454
|
+
if ("type" in ch && ch.type === "hyperlink") {
|
|
1455
|
+
out.push(ch);
|
|
1456
|
+
walk(ch.children);
|
|
1457
|
+
}
|
|
1458
|
+
}
|
|
1459
|
+
};
|
|
1460
|
+
for (const block of doc.body) {
|
|
1461
|
+
if (block.type === "paragraph") {
|
|
1462
|
+
walk(block.children);
|
|
1463
|
+
}
|
|
1464
|
+
}
|
|
1465
|
+
return out;
|
|
1466
|
+
}
|
|
1467
|
+
/**
|
|
1468
|
+
* Get the total number of tables (top-level) and nested tables.
|
|
1469
|
+
*/
|
|
1470
|
+
function tableCount(doc) {
|
|
1471
|
+
let count = 0;
|
|
1472
|
+
const walk = (blocks) => {
|
|
1473
|
+
for (const block of blocks) {
|
|
1474
|
+
if (block.type === "table") {
|
|
1475
|
+
count++;
|
|
1476
|
+
for (const row of block.rows) {
|
|
1477
|
+
for (const cell of row.cells) {
|
|
1478
|
+
walk(cell.content);
|
|
1479
|
+
}
|
|
1480
|
+
}
|
|
1481
|
+
}
|
|
1482
|
+
}
|
|
1483
|
+
};
|
|
1484
|
+
walk(doc.body);
|
|
1485
|
+
return count;
|
|
1486
|
+
}
|
|
1487
|
+
/**
|
|
1488
|
+
* Extract plain text from the entire document body.
|
|
1489
|
+
*
|
|
1490
|
+
* Paragraphs are separated by `\n`. Tables render as tab-separated cell text.
|
|
1491
|
+
*/
|
|
1492
|
+
function extractText(doc) {
|
|
1493
|
+
const lines = [];
|
|
1494
|
+
const walk = (blocks) => {
|
|
1495
|
+
for (const block of blocks) {
|
|
1496
|
+
if (block.type === "paragraph") {
|
|
1497
|
+
lines.push(paragraphText(block));
|
|
1498
|
+
}
|
|
1499
|
+
else if (block.type === "table") {
|
|
1500
|
+
for (const row of block.rows) {
|
|
1501
|
+
const cellTexts = [];
|
|
1502
|
+
for (const cell of row.cells) {
|
|
1503
|
+
const cellLines = [];
|
|
1504
|
+
walk(cell.content);
|
|
1505
|
+
// collect last paragraphs text
|
|
1506
|
+
cellTexts.push(cellLines.join(" "));
|
|
1507
|
+
}
|
|
1508
|
+
lines.push(cellTexts.join("\t"));
|
|
1509
|
+
}
|
|
1510
|
+
}
|
|
1511
|
+
}
|
|
1512
|
+
};
|
|
1513
|
+
walk(doc.body);
|
|
1514
|
+
return lines.join("\n");
|
|
1515
|
+
}
|
|
1516
|
+
/**
|
|
1517
|
+
* Search for text occurrences in a document's body paragraphs.
|
|
1518
|
+
*
|
|
1519
|
+
* @param doc - The document model to search.
|
|
1520
|
+
* @param query - String or RegExp to search for.
|
|
1521
|
+
* @returns Array of search results.
|
|
1522
|
+
*/
|
|
1523
|
+
function searchText(doc, query) {
|
|
1524
|
+
const results = [];
|
|
1525
|
+
for (let i = 0; i < doc.body.length; i++) {
|
|
1526
|
+
const block = doc.body[i];
|
|
1527
|
+
if (block.type !== "paragraph") {
|
|
1528
|
+
continue;
|
|
1529
|
+
}
|
|
1530
|
+
const text = paragraphText(block);
|
|
1531
|
+
if (typeof query === "string") {
|
|
1532
|
+
let idx = text.indexOf(query);
|
|
1533
|
+
while (idx !== -1) {
|
|
1534
|
+
results.push({ paragraphIndex: i, match: query, offset: idx });
|
|
1535
|
+
idx = text.indexOf(query, idx + 1);
|
|
1536
|
+
}
|
|
1537
|
+
}
|
|
1538
|
+
else {
|
|
1539
|
+
const re = new RegExp(query.source, query.flags.includes("g") ? query.flags : query.flags + "g");
|
|
1540
|
+
let m;
|
|
1541
|
+
while ((m = re.exec(text)) !== null) {
|
|
1542
|
+
results.push({ paragraphIndex: i, match: m[0], offset: m.index });
|
|
1543
|
+
if (!re.global) {
|
|
1544
|
+
break;
|
|
1545
|
+
}
|
|
1546
|
+
}
|
|
1547
|
+
}
|
|
1548
|
+
}
|
|
1549
|
+
return results;
|
|
1550
|
+
}
|
|
1551
|
+
/**
|
|
1552
|
+
* Replace text in a document's body paragraphs (mutates the document).
|
|
1553
|
+
*
|
|
1554
|
+
* Performs simple text replacement within run content. Each run's text content
|
|
1555
|
+
* is individually searched and replaced. For cross-run matches, the paragraph
|
|
1556
|
+
* text is reconstructed and split back into runs.
|
|
1557
|
+
*
|
|
1558
|
+
* @param doc - The document model to modify (mutated in place).
|
|
1559
|
+
* @param search - String or RegExp to find.
|
|
1560
|
+
* @param replacement - Replacement string (supports $1, $2 etc. for RegExp).
|
|
1561
|
+
* @returns Number of replacements made.
|
|
1562
|
+
*/
|
|
1563
|
+
function replaceText(doc, search, replacement) {
|
|
1564
|
+
let count = 0;
|
|
1565
|
+
for (const block of doc.body) {
|
|
1566
|
+
if (block.type !== "paragraph") {
|
|
1567
|
+
continue;
|
|
1568
|
+
}
|
|
1569
|
+
count += replaceInParagraph(block, search, replacement);
|
|
1570
|
+
}
|
|
1571
|
+
return count;
|
|
1572
|
+
}
|
|
1573
|
+
// =============================================================================
|
|
1574
|
+
// Mail Merge
|
|
1575
|
+
// =============================================================================
|
|
1576
|
+
/** Regex to parse MERGEFIELD instruction: MERGEFIELD "FieldName" or MERGEFIELD FieldName */
|
|
1577
|
+
const MERGEFIELD_RE = /^\s*MERGEFIELD\s+(?:"([^"]+)"|(\S+))/i;
|
|
1578
|
+
/**
|
|
1579
|
+
* Execute a mail merge: replace all MERGEFIELD fields in the document with values from the data map.
|
|
1580
|
+
*
|
|
1581
|
+
* Fields not found in the data map are left unchanged (or optionally cleared).
|
|
1582
|
+
*
|
|
1583
|
+
* @param doc - The document to modify (mutated in place).
|
|
1584
|
+
* @param data - Map of field names to replacement values.
|
|
1585
|
+
* @param options - Optional settings.
|
|
1586
|
+
* @returns The number of fields replaced.
|
|
1587
|
+
*/
|
|
1588
|
+
function mailMerge(doc, data, options) {
|
|
1589
|
+
let count = 0;
|
|
1590
|
+
const removeUnmatched = options?.removeUnmatched ?? false;
|
|
1591
|
+
// Process body
|
|
1592
|
+
for (const block of doc.body) {
|
|
1593
|
+
if (block.type === "paragraph") {
|
|
1594
|
+
count += mergeFieldsInParagraph(block, data, removeUnmatched);
|
|
1595
|
+
}
|
|
1596
|
+
else if (block.type === "table") {
|
|
1597
|
+
count += mergeFieldsInTable(block, data, removeUnmatched);
|
|
1598
|
+
}
|
|
1599
|
+
else if (block.type === "sdt") {
|
|
1600
|
+
for (const sdtChild of block.content) {
|
|
1601
|
+
if ("type" in sdtChild && sdtChild.type === "paragraph") {
|
|
1602
|
+
count += mergeFieldsInParagraph(sdtChild, data, removeUnmatched);
|
|
1603
|
+
}
|
|
1604
|
+
else if ("type" in sdtChild && sdtChild.type === "table") {
|
|
1605
|
+
count += mergeFieldsInTable(sdtChild, data, removeUnmatched);
|
|
1606
|
+
}
|
|
1607
|
+
}
|
|
1608
|
+
}
|
|
1609
|
+
}
|
|
1610
|
+
// Process headers and footers
|
|
1611
|
+
if (doc.headers) {
|
|
1612
|
+
for (const [, header] of doc.headers) {
|
|
1613
|
+
count += mergeFieldsInHeaderFooter(header.content, data, removeUnmatched);
|
|
1614
|
+
}
|
|
1615
|
+
}
|
|
1616
|
+
if (doc.footers) {
|
|
1617
|
+
for (const [, footer] of doc.footers) {
|
|
1618
|
+
count += mergeFieldsInHeaderFooter(footer.content, data, removeUnmatched);
|
|
1619
|
+
}
|
|
1620
|
+
}
|
|
1621
|
+
return count;
|
|
1622
|
+
}
|
|
1623
|
+
function mergeFieldsInTable(table, data, removeUnmatched) {
|
|
1624
|
+
let count = 0;
|
|
1625
|
+
for (const row of table.rows) {
|
|
1626
|
+
for (const cell of row.cells) {
|
|
1627
|
+
for (const block of cell.content) {
|
|
1628
|
+
if (block.type === "paragraph") {
|
|
1629
|
+
count += mergeFieldsInParagraph(block, data, removeUnmatched);
|
|
1630
|
+
}
|
|
1631
|
+
else if (block.type === "table") {
|
|
1632
|
+
count += mergeFieldsInTable(block, data, removeUnmatched);
|
|
1633
|
+
}
|
|
1634
|
+
}
|
|
1635
|
+
}
|
|
1636
|
+
}
|
|
1637
|
+
return count;
|
|
1638
|
+
}
|
|
1639
|
+
function mergeFieldsInHeaderFooter(content, data, removeUnmatched) {
|
|
1640
|
+
let count = 0;
|
|
1641
|
+
for (const child of content.children) {
|
|
1642
|
+
if (child.type === "paragraph") {
|
|
1643
|
+
count += mergeFieldsInParagraph(child, data, removeUnmatched);
|
|
1644
|
+
}
|
|
1645
|
+
else if (child.type === "table") {
|
|
1646
|
+
count += mergeFieldsInTable(child, data, removeUnmatched);
|
|
1647
|
+
}
|
|
1648
|
+
}
|
|
1649
|
+
return count;
|
|
1650
|
+
}
|
|
1651
|
+
function mergeFieldsInParagraph(para, data, removeUnmatched) {
|
|
1652
|
+
let count = 0;
|
|
1653
|
+
const children = para.children;
|
|
1654
|
+
for (let i = 0; i < children.length; i++) {
|
|
1655
|
+
const child = children[i];
|
|
1656
|
+
if (!("content" in child) || !Array.isArray(child.content)) {
|
|
1657
|
+
continue;
|
|
1658
|
+
}
|
|
1659
|
+
const run = child;
|
|
1660
|
+
const content = run.content;
|
|
1661
|
+
for (let j = 0; j < content.length; j++) {
|
|
1662
|
+
const c = content[j];
|
|
1663
|
+
if (c.type !== "field") {
|
|
1664
|
+
continue;
|
|
1665
|
+
}
|
|
1666
|
+
const match = MERGEFIELD_RE.exec(c.instruction);
|
|
1667
|
+
if (!match) {
|
|
1668
|
+
continue;
|
|
1669
|
+
}
|
|
1670
|
+
const fieldName = match[1] ?? match[2];
|
|
1671
|
+
if (fieldName in data) {
|
|
1672
|
+
// Replace field with text
|
|
1673
|
+
content[j] = { type: "text", text: data[fieldName] };
|
|
1674
|
+
count++;
|
|
1675
|
+
}
|
|
1676
|
+
else if (removeUnmatched) {
|
|
1677
|
+
// Remove unmatched field
|
|
1678
|
+
content[j] = { type: "text", text: "" };
|
|
1679
|
+
count++;
|
|
1680
|
+
}
|
|
1681
|
+
}
|
|
1682
|
+
}
|
|
1683
|
+
return count;
|
|
1684
|
+
}
|
|
1685
|
+
/** Replace text within a single paragraph. */
|
|
1686
|
+
function replaceInParagraph(para, search, replacement) {
|
|
1687
|
+
// First try simple per-run replacement
|
|
1688
|
+
let count = 0;
|
|
1689
|
+
for (const child of para.children) {
|
|
1690
|
+
if (!("content" in child) || !Array.isArray(child.content)) {
|
|
1691
|
+
continue;
|
|
1692
|
+
}
|
|
1693
|
+
for (const c of child.content) {
|
|
1694
|
+
if (!("type" in c) || c.type !== "text" || !("text" in c)) {
|
|
1695
|
+
continue;
|
|
1696
|
+
}
|
|
1697
|
+
const before = c.text;
|
|
1698
|
+
const after = typeof search === "string"
|
|
1699
|
+
? replaceAll(before, search, replacement)
|
|
1700
|
+
: before.replace(search, replacement);
|
|
1701
|
+
if (after !== before) {
|
|
1702
|
+
c.text = after;
|
|
1703
|
+
count += typeof search === "string" ? countOccurrences(before, search) : 1;
|
|
1704
|
+
}
|
|
1705
|
+
}
|
|
1706
|
+
}
|
|
1707
|
+
// If no per-run matches, try cross-run replacement
|
|
1708
|
+
if (count === 0) {
|
|
1709
|
+
const fullText = paragraphText(para);
|
|
1710
|
+
const newText = typeof search === "string"
|
|
1711
|
+
? replaceAll(fullText, search, replacement)
|
|
1712
|
+
: fullText.replace(search, replacement);
|
|
1713
|
+
if (newText !== fullText) {
|
|
1714
|
+
// Rebuild: put all text into first text run, clear others
|
|
1715
|
+
let placed = false;
|
|
1716
|
+
for (const child of para.children) {
|
|
1717
|
+
if (!("content" in child) || !Array.isArray(child.content)) {
|
|
1718
|
+
continue;
|
|
1719
|
+
}
|
|
1720
|
+
for (const c of child.content) {
|
|
1721
|
+
if (!("type" in c) || c.type !== "text" || !("text" in c)) {
|
|
1722
|
+
continue;
|
|
1723
|
+
}
|
|
1724
|
+
if (!placed) {
|
|
1725
|
+
c.text = newText;
|
|
1726
|
+
placed = true;
|
|
1727
|
+
}
|
|
1728
|
+
else {
|
|
1729
|
+
c.text = "";
|
|
1730
|
+
}
|
|
1731
|
+
}
|
|
1732
|
+
}
|
|
1733
|
+
count = typeof search === "string" ? countOccurrences(fullText, search) : 1;
|
|
1734
|
+
}
|
|
1735
|
+
}
|
|
1736
|
+
return count;
|
|
1737
|
+
}
|
|
1738
|
+
function replaceAll(str, search, replacement) {
|
|
1739
|
+
if (search === "") {
|
|
1740
|
+
return str;
|
|
1741
|
+
}
|
|
1742
|
+
return str.replaceAll(search, replacement);
|
|
1743
|
+
}
|
|
1744
|
+
function countOccurrences(str, search) {
|
|
1745
|
+
if (search === "") {
|
|
1746
|
+
return 0;
|
|
1747
|
+
}
|
|
1748
|
+
return str.split(search).length - 1;
|
|
1749
|
+
}
|
|
1750
|
+
/**
|
|
1751
|
+
* Read an existing DOCX file, replace placeholders with content, and produce a new DOCX.
|
|
1752
|
+
*
|
|
1753
|
+
* Placeholders are strings like `{{name}}` embedded in the document text.
|
|
1754
|
+
* They may span across multiple runs — the patcher handles cross-run matching.
|
|
1755
|
+
*
|
|
1756
|
+
* Supported patch content types:
|
|
1757
|
+
* - `text` — simple text replacement (preserves formatting of the first run)
|
|
1758
|
+
* - `paragraph` — replaces the entire paragraph containing the placeholder
|
|
1759
|
+
* - `table` — replaces the entire paragraph with a table
|
|
1760
|
+
* - `image` — replaces the placeholder with an inline image
|
|
1761
|
+
*
|
|
1762
|
+
* @param buffer - The source DOCX file as a Uint8Array.
|
|
1763
|
+
* @param patches - Array of patch operations to apply.
|
|
1764
|
+
* @param options - Optional compression settings.
|
|
1765
|
+
* @returns New DOCX file as a Uint8Array.
|
|
1766
|
+
*/
|
|
1767
|
+
async function patchDocument(buffer, patches, options) {
|
|
1768
|
+
const doc = await (0, docx_reader_1.readDocx)(buffer);
|
|
1769
|
+
// Build lookup map for quick placeholder matching
|
|
1770
|
+
const patchMap = new Map();
|
|
1771
|
+
for (const patch of patches) {
|
|
1772
|
+
patchMap.set(patch.placeholder, patch);
|
|
1773
|
+
}
|
|
1774
|
+
// Process body content
|
|
1775
|
+
const newBody = [];
|
|
1776
|
+
for (const block of doc.body) {
|
|
1777
|
+
if (block.type === "paragraph") {
|
|
1778
|
+
const result = patchParagraph(block, patchMap);
|
|
1779
|
+
if (result) {
|
|
1780
|
+
if (Array.isArray(result)) {
|
|
1781
|
+
newBody.push(...result);
|
|
1782
|
+
}
|
|
1783
|
+
else {
|
|
1784
|
+
newBody.push(result);
|
|
1785
|
+
}
|
|
1786
|
+
}
|
|
1787
|
+
}
|
|
1788
|
+
else if (block.type === "table") {
|
|
1789
|
+
patchTable(block, patchMap);
|
|
1790
|
+
newBody.push(block);
|
|
1791
|
+
}
|
|
1792
|
+
else {
|
|
1793
|
+
newBody.push(block);
|
|
1794
|
+
}
|
|
1795
|
+
}
|
|
1796
|
+
// Patch headers
|
|
1797
|
+
if (doc.headers) {
|
|
1798
|
+
for (const [, headerDef] of doc.headers) {
|
|
1799
|
+
patchHeaderFooterContent(headerDef.content, patchMap);
|
|
1800
|
+
}
|
|
1801
|
+
}
|
|
1802
|
+
// Patch footers
|
|
1803
|
+
if (doc.footers) {
|
|
1804
|
+
for (const [, footerDef] of doc.footers) {
|
|
1805
|
+
patchHeaderFooterContent(footerDef.content, patchMap);
|
|
1806
|
+
}
|
|
1807
|
+
}
|
|
1808
|
+
// Add any new images from patches
|
|
1809
|
+
const images = doc.images ? [...doc.images] : [];
|
|
1810
|
+
for (const patch of patches) {
|
|
1811
|
+
if (patch.content.type === "image") {
|
|
1812
|
+
const imgContent = patch.content;
|
|
1813
|
+
const existing = images.find(i => i.fileName === imgContent.image.fileName);
|
|
1814
|
+
if (!existing) {
|
|
1815
|
+
images.push(imgContent.image);
|
|
1816
|
+
}
|
|
1817
|
+
}
|
|
1818
|
+
}
|
|
1819
|
+
const patched = {
|
|
1820
|
+
...doc,
|
|
1821
|
+
body: newBody,
|
|
1822
|
+
images: images.length > 0 ? images : undefined
|
|
1823
|
+
};
|
|
1824
|
+
return (0, docx_packager_1.packageDocx)(patched, options?.compressionLevel);
|
|
1825
|
+
}
|
|
1826
|
+
/** Patch a paragraph — returns replacement content or null to remove. */
|
|
1827
|
+
function patchParagraph(para, patchMap) {
|
|
1828
|
+
const text = paragraphText(para);
|
|
1829
|
+
for (const [placeholder, patch] of patchMap) {
|
|
1830
|
+
if (!text.includes(placeholder)) {
|
|
1831
|
+
continue;
|
|
1832
|
+
}
|
|
1833
|
+
switch (patch.content.type) {
|
|
1834
|
+
case "text": {
|
|
1835
|
+
replaceInParagraph(para, placeholder, patch.content.text);
|
|
1836
|
+
return para;
|
|
1837
|
+
}
|
|
1838
|
+
case "paragraph": {
|
|
1839
|
+
return patch.content.children;
|
|
1840
|
+
}
|
|
1841
|
+
case "table": {
|
|
1842
|
+
return patch.content.table;
|
|
1843
|
+
}
|
|
1844
|
+
case "image": {
|
|
1845
|
+
const img = patch.content.image;
|
|
1846
|
+
const rId = img.rId ?? `rId_img_${img.fileName}`;
|
|
1847
|
+
const imgContent = {
|
|
1848
|
+
type: "image",
|
|
1849
|
+
rId,
|
|
1850
|
+
width: patch.content.width,
|
|
1851
|
+
height: patch.content.height,
|
|
1852
|
+
altText: img.fileName,
|
|
1853
|
+
name: img.fileName
|
|
1854
|
+
};
|
|
1855
|
+
const newPara = {
|
|
1856
|
+
type: "paragraph",
|
|
1857
|
+
properties: para.properties,
|
|
1858
|
+
children: [{ content: [imgContent] }]
|
|
1859
|
+
};
|
|
1860
|
+
return newPara;
|
|
1861
|
+
}
|
|
1862
|
+
}
|
|
1863
|
+
}
|
|
1864
|
+
return para;
|
|
1865
|
+
}
|
|
1866
|
+
/** Patch text inside table cells recursively. */
|
|
1867
|
+
function patchTable(table, patchMap) {
|
|
1868
|
+
for (const row of table.rows) {
|
|
1869
|
+
for (const cell of row.cells) {
|
|
1870
|
+
const newContent = [];
|
|
1871
|
+
for (const block of cell.content) {
|
|
1872
|
+
if (block.type === "paragraph") {
|
|
1873
|
+
const result = patchParagraph(block, patchMap);
|
|
1874
|
+
if (result) {
|
|
1875
|
+
if (Array.isArray(result)) {
|
|
1876
|
+
newContent.push(...result);
|
|
1877
|
+
}
|
|
1878
|
+
else {
|
|
1879
|
+
newContent.push(result);
|
|
1880
|
+
}
|
|
1881
|
+
}
|
|
1882
|
+
}
|
|
1883
|
+
else if (block.type === "table") {
|
|
1884
|
+
patchTable(block, patchMap);
|
|
1885
|
+
newContent.push(block);
|
|
1886
|
+
}
|
|
1887
|
+
else {
|
|
1888
|
+
newContent.push(block);
|
|
1889
|
+
}
|
|
1890
|
+
}
|
|
1891
|
+
cell.content = newContent;
|
|
1892
|
+
}
|
|
1893
|
+
}
|
|
1894
|
+
}
|
|
1895
|
+
/** Patch text in header/footer content. */
|
|
1896
|
+
function patchHeaderFooterContent(content, patchMap) {
|
|
1897
|
+
for (const child of content.children) {
|
|
1898
|
+
if (child.type === "paragraph") {
|
|
1899
|
+
for (const [placeholder, patch] of patchMap) {
|
|
1900
|
+
if (patch.content.type === "text") {
|
|
1901
|
+
const text = paragraphText(child);
|
|
1902
|
+
if (text.includes(placeholder)) {
|
|
1903
|
+
replaceInParagraph(child, placeholder, patch.content.text);
|
|
1904
|
+
}
|
|
1905
|
+
}
|
|
1906
|
+
}
|
|
1907
|
+
}
|
|
1908
|
+
}
|
|
1909
|
+
}
|