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