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