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