@syncfusion/ej2-docx 0.0.0-stage → 35.1.40
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/.gitleaksignore +35 -0
- package/README.md +68 -2
- package/core.js +4 -0
- package/dist/ej2-docx.umd.min.js +11 -0
- package/dist/ej2-docx.umd.min.js.map +1 -0
- package/dist/es6/ej2-docx.es2015.js +66697 -0
- package/dist/es6/ej2-docx.es2015.js.map +1 -0
- package/dist/es6/ej2-docx.es5.js +77568 -0
- package/dist/es6/ej2-docx.es5.js.map +1 -0
- package/dist/global/ej2-docx.min.js +11 -0
- package/dist/global/ej2-docx.min.js.map +1 -0
- package/dist/global/index.d.ts +14 -0
- package/features.js +4 -0
- package/index.js +4 -0
- package/license +10 -0
- package/package.json +30 -3
- package/src/all.d.ts +50 -0
- package/src/all.js +147 -0
- package/src/core/compat/base64.d.ts +13 -0
- package/src/core/compat/base64.js +90 -0
- package/src/core/compat/object-compat.d.ts +30 -0
- package/src/core/compat/object-compat.js +40 -0
- package/src/core/compat/sha256.d.ts +9 -0
- package/src/core/compat/sha256.js +98 -0
- package/src/core/errors/docx-error.d.ts +89 -0
- package/src/core/errors/docx-error.js +138 -0
- package/src/core/errors/error-codes.d.ts +8 -0
- package/src/core/errors/error-codes.js +0 -0
- package/src/core/errors/index.d.ts +10 -0
- package/src/core/errors/index.js +9 -0
- package/src/core/index.d.ts +12 -0
- package/src/core/index.js +12 -0
- package/src/core/mc/alternate-content.d.ts +7 -0
- package/src/core/mc/alternate-content.js +67 -0
- package/src/core/mc/attributes.d.ts +24 -0
- package/src/core/mc/attributes.js +82 -0
- package/src/core/mc/index.d.ts +7 -0
- package/src/core/mc/index.js +5 -0
- package/src/core/mc/inspect.d.ts +16 -0
- package/src/core/mc/inspect.js +148 -0
- package/src/core/mc/namespaces.d.ts +4 -0
- package/src/core/mc/namespaces.js +4 -0
- package/src/core/mc/scope.d.ts +6 -0
- package/src/core/mc/scope.js +47 -0
- package/src/core/opc/content-types.d.ts +34 -0
- package/src/core/opc/content-types.js +162 -0
- package/src/core/opc/index.d.ts +8 -0
- package/src/core/opc/index.js +4 -0
- package/src/core/opc/package.d.ts +49 -0
- package/src/core/opc/package.js +324 -0
- package/src/core/opc/part-name.d.ts +47 -0
- package/src/core/opc/part-name.js +205 -0
- package/src/core/opc/relationships.d.ts +46 -0
- package/src/core/opc/relationships.js +212 -0
- package/src/core/preservation/index.d.ts +2 -0
- package/src/core/preservation/index.js +1 -0
- package/src/core/preservation/opaque-body.d.ts +16 -0
- package/src/core/preservation/opaque-body.js +69 -0
- package/src/core/registry/block-handlers.d.ts +30 -0
- package/src/core/registry/block-handlers.js +36 -0
- package/src/core/registry/create-defaults.d.ts +39 -0
- package/src/core/registry/create-defaults.js +42 -0
- package/src/core/registry/feature-registry.d.ts +20 -0
- package/src/core/registry/feature-registry.js +29 -0
- package/src/core/registry/index.d.ts +9 -0
- package/src/core/registry/index.js +8 -0
- package/src/core/registry/inline-handlers.d.ts +20 -0
- package/src/core/registry/inline-handlers.js +30 -0
- package/src/core/registry/materialize-handlers.d.ts +35 -0
- package/src/core/registry/materialize-handlers.js +75 -0
- package/src/core/registry/multi-part-handlers.d.ts +37 -0
- package/src/core/registry/multi-part-handlers.js +206 -0
- package/src/core/registry/package-part-handlers.d.ts +28 -0
- package/src/core/registry/package-part-handlers.js +190 -0
- package/src/core/registry/part-handlers.d.ts +24 -0
- package/src/core/registry/part-handlers.js +172 -0
- package/src/core/registry/run-leaf-handlers.d.ts +26 -0
- package/src/core/registry/run-leaf-handlers.js +72 -0
- package/src/core/security/limits.d.ts +40 -0
- package/src/core/security/limits.js +26 -0
- package/src/core/xml/index.d.ts +7 -0
- package/src/core/xml/index.js +3 -0
- package/src/core/xml/model.d.ts +66 -0
- package/src/core/xml/model.js +17 -0
- package/src/core/xml/parse.d.ts +12 -0
- package/src/core/xml/parse.js +382 -0
- package/src/core/xml/serialize.d.ts +6 -0
- package/src/core/xml/serialize.js +93 -0
- package/src/core/zip/crc32.d.ts +2 -0
- package/src/core/zip/crc32.js +25 -0
- package/src/core/zip/deflate.d.ts +6 -0
- package/src/core/zip/deflate.js +6 -0
- package/src/core/zip/index.d.ts +10 -0
- package/src/core/zip/index.js +4 -0
- package/src/core/zip/inflate-raw.d.ts +17 -0
- package/src/core/zip/inflate-raw.js +450 -0
- package/src/core/zip/names.d.ts +6 -0
- package/src/core/zip/names.js +52 -0
- package/src/core/zip/read.d.ts +8 -0
- package/src/core/zip/read.js +262 -0
- package/src/core/zip/write.d.ts +7 -0
- package/src/core/zip/write.js +189 -0
- package/src/core/zip/zip-entry.d.ts +4 -0
- package/src/core/zip/zip-entry.js +0 -0
- package/src/features/bibliography/index.d.ts +100 -0
- package/src/features/bibliography/index.js +290 -0
- package/src/features/bookmarks/index.d.ts +331 -0
- package/src/features/bookmarks/index.js +1009 -0
- package/src/features/comments/comment-extensions.d.ts +157 -0
- package/src/features/comments/comment-extensions.js +356 -0
- package/src/features/comments/index.d.ts +579 -0
- package/src/features/comments/index.js +1727 -0
- package/src/features/content-controls/index.d.ts +821 -0
- package/src/features/content-controls/index.js +2857 -0
- package/src/features/custom-xml/index.d.ts +236 -0
- package/src/features/custom-xml/index.js +661 -0
- package/src/features/document/alignment.d.ts +23 -0
- package/src/features/document/alignment.js +36 -0
- package/src/features/document/alt-chunk.d.ts +103 -0
- package/src/features/document/alt-chunk.js +221 -0
- package/src/features/document/assert-never.d.ts +1 -0
- package/src/features/document/assert-never.js +4 -0
- package/src/features/document/augmentations.d.ts +578 -0
- package/src/features/document/augmentations.js +0 -0
- package/src/features/document/body-always-on.d.ts +36 -0
- package/src/features/document/body-always-on.js +66 -0
- package/src/features/document/body-blocks.d.ts +7 -0
- package/src/features/document/body-blocks.js +78 -0
- package/src/features/document/body-item-adapters.d.ts +62 -0
- package/src/features/document/body-item-adapters.js +97 -0
- package/src/features/document/body-item-collection.d.ts +151 -0
- package/src/features/document/body-item-collection.js +440 -0
- package/src/features/document/body-item.d.ts +35 -0
- package/src/features/document/body-item.js +8 -0
- package/src/features/document/body.d.ts +150 -0
- package/src/features/document/body.js +263 -0
- package/src/features/document/character-format.d.ts +413 -0
- package/src/features/document/character-format.js +2054 -0
- package/src/features/document/color.d.ts +178 -0
- package/src/features/document/color.js +495 -0
- package/src/features/document/document.d.ts +410 -0
- package/src/features/document/document.js +1049 -0
- package/src/features/document/element-type.d.ts +68 -0
- package/src/features/document/element-type.js +133 -0
- package/src/features/document/entity-type.d.ts +92 -0
- package/src/features/document/entity-type.js +93 -0
- package/src/features/document/feature-block.d.ts +16 -0
- package/src/features/document/feature-block.js +0 -0
- package/src/features/document/feature-inline.d.ts +13 -0
- package/src/features/document/feature-inline.js +0 -0
- package/src/features/document/feature-multi-package-part.d.ts +19 -0
- package/src/features/document/feature-multi-package-part.js +8 -0
- package/src/features/document/feature-package-level-part.d.ts +18 -0
- package/src/features/document/feature-package-level-part.js +8 -0
- package/src/features/document/feature-package-part.d.ts +14 -0
- package/src/features/document/feature-package-part.js +0 -0
- package/src/features/document/feature-run-leaf.d.ts +9 -0
- package/src/features/document/feature-run-leaf.js +0 -0
- package/src/features/document/headers-footers.d.ts +206 -0
- package/src/features/document/headers-footers.js +384 -0
- package/src/features/document/index.d.ts +41 -0
- package/src/features/document/index.js +34 -0
- package/src/features/document/length.d.ts +152 -0
- package/src/features/document/length.js +245 -0
- package/src/features/document/load-options.d.ts +14 -0
- package/src/features/document/load-options.js +0 -0
- package/src/features/document/locale-ids.d.ts +227 -0
- package/src/features/document/locale-ids.js +485 -0
- package/src/features/document/on-off.d.ts +9 -0
- package/src/features/document/on-off.js +27 -0
- package/src/features/document/page-setup.d.ts +339 -0
- package/src/features/document/page-setup.js +244 -0
- package/src/features/document/paragraph-format.d.ts +880 -0
- package/src/features/document/paragraph-format.js +2807 -0
- package/src/features/document/paragraph-item-collection.d.ts +162 -0
- package/src/features/document/paragraph-item-collection.js +363 -0
- package/src/features/document/paragraph-item.d.ts +83 -0
- package/src/features/document/paragraph-item.js +103 -0
- package/src/features/document/paragraph.d.ts +435 -0
- package/src/features/document/paragraph.js +888 -0
- package/src/features/document/run.d.ts +1 -0
- package/src/features/document/run.js +768 -0
- package/src/features/document/section-partition-flatten.d.ts +124 -0
- package/src/features/document/section-partition-flatten.js +217 -0
- package/src/features/document/section-properties-model.d.ts +13 -0
- package/src/features/document/section-properties-model.js +0 -0
- package/src/features/document/section.d.ts +93 -0
- package/src/features/document/section.js +178 -0
- package/src/features/document/sections.d.ts +103 -0
- package/src/features/document/sections.js +217 -0
- package/src/features/document/sub-super-script.d.ts +23 -0
- package/src/features/document/sub-super-script.js +43 -0
- package/src/features/document/text-range.d.ts +445 -0
- package/src/features/document/text-range.js +1156 -0
- package/src/features/document/typed-body-collections.d.ts +162 -0
- package/src/features/document/typed-body-collections.js +371 -0
- package/src/features/document/underline-style.d.ts +38 -0
- package/src/features/document/underline-style.js +126 -0
- package/src/features/document/units.d.ts +8 -0
- package/src/features/document/units.js +7 -0
- package/src/features/document/wml.d.ts +16 -0
- package/src/features/document/wml.js +67 -0
- package/src/features/drawing/authoring.d.ts +27 -0
- package/src/features/drawing/authoring.js +271 -0
- package/src/features/drawing/body-pr.d.ts +271 -0
- package/src/features/drawing/body-pr.js +663 -0
- package/src/features/drawing/drawing-shape.d.ts +1192 -0
- package/src/features/drawing/drawing-shape.js +3239 -0
- package/src/features/drawing/encode-builders.d.ts +176 -0
- package/src/features/drawing/encode-builders.js +390 -0
- package/src/features/drawing/fill-format.d.ts +52 -0
- package/src/features/drawing/fill-format.js +124 -0
- package/src/features/drawing/host-codec.d.ts +632 -0
- package/src/features/drawing/host-codec.js +2595 -0
- package/src/features/drawing/index.d.ts +13 -0
- package/src/features/drawing/index.js +33 -0
- package/src/features/drawing/line-format.d.ts +76 -0
- package/src/features/drawing/line-format.js +343 -0
- package/src/features/drawing/parse-register.d.ts +50 -0
- package/src/features/drawing/parse-register.js +257 -0
- package/src/features/drawing/residual-utils.d.ts +47 -0
- package/src/features/drawing/residual-utils.js +290 -0
- package/src/features/drawing/shape-types.d.ts +433 -0
- package/src/features/drawing/shape-types.js +437 -0
- package/src/features/drawing/sp-pr.d.ts +396 -0
- package/src/features/drawing/sp-pr.js +610 -0
- package/src/features/drawing/text-frame.d.ts +90 -0
- package/src/features/drawing/text-frame.js +152 -0
- package/src/features/drawing/types.d.ts +352 -0
- package/src/features/drawing/types.js +60 -0
- package/src/features/drawing/wrap-format.d.ts +62 -0
- package/src/features/drawing/wrap-format.js +114 -0
- package/src/features/editable-ranges/index.d.ts +494 -0
- package/src/features/editable-ranges/index.js +1348 -0
- package/src/features/fields/index.d.ts +428 -0
- package/src/features/fields/index.js +2148 -0
- package/src/features/fields/paragraph-field.d.ts +187 -0
- package/src/features/fields/paragraph-field.js +692 -0
- package/src/features/font-table/font-substitution-table.d.ts +75 -0
- package/src/features/font-table/font-substitution-table.js +257 -0
- package/src/features/font-table/font-table-entry.d.ts +255 -0
- package/src/features/font-table/font-table-entry.js +823 -0
- package/src/features/font-table/font-table.d.ts +128 -0
- package/src/features/font-table/font-table.js +313 -0
- package/src/features/font-table/index.d.ts +27 -0
- package/src/features/font-table/index.js +48 -0
- package/src/features/glossary/index.d.ts +97 -0
- package/src/features/glossary/index.js +286 -0
- package/src/features/headers-footers/index.d.ts +506 -0
- package/src/features/headers-footers/index.js +1666 -0
- package/src/features/hyperlinks/index.d.ts +230 -0
- package/src/features/hyperlinks/index.js +685 -0
- package/src/features/images/caption-authoring-api.d.ts +33 -0
- package/src/features/images/caption-authoring-api.js +33 -0
- package/src/features/images/caption-enums.d.ts +52 -0
- package/src/features/images/caption-enums.js +141 -0
- package/src/features/images/caption-host.d.ts +10 -0
- package/src/features/images/caption-host.js +21 -0
- package/src/features/images/captions.d.ts +13 -0
- package/src/features/images/captions.js +142 -0
- package/src/features/images/host-codec.d.ts +103 -0
- package/src/features/images/host-codec.js +720 -0
- package/src/features/images/image-sniff.d.ts +21 -0
- package/src/features/images/image-sniff.js +71 -0
- package/src/features/images/index.d.ts +506 -0
- package/src/features/images/index.js +1429 -0
- package/src/features/images/layout-types.d.ts +232 -0
- package/src/features/images/layout-types.js +294 -0
- package/src/features/images/public-entry.d.ts +9 -0
- package/src/features/images/public-entry.js +9 -0
- package/src/features/index.d.ts +35 -0
- package/src/features/index.js +36 -0
- package/src/features/mail-merge/index.d.ts +113 -0
- package/src/features/mail-merge/index.js +315 -0
- package/src/features/notes/index.d.ts +573 -0
- package/src/features/notes/index.js +1725 -0
- package/src/features/numbering/abstract-numbering.d.ts +90 -0
- package/src/features/numbering/abstract-numbering.js +292 -0
- package/src/features/numbering/index.d.ts +182 -0
- package/src/features/numbering/index.js +668 -0
- package/src/features/numbering/list-format.d.ts +158 -0
- package/src/features/numbering/list-format.js +590 -0
- package/src/features/numbering/list-string.d.ts +7 -0
- package/src/features/numbering/list-string.js +423 -0
- package/src/features/numbering/list-style.d.ts +204 -0
- package/src/features/numbering/list-style.js +1084 -0
- package/src/features/numbering/numbering-instance.d.ts +101 -0
- package/src/features/numbering/numbering-instance.js +329 -0
- package/src/features/numbering/numbering-level.d.ts +118 -0
- package/src/features/numbering/numbering-level.js +501 -0
- package/src/features/numbering/picture-bullet.d.ts +34 -0
- package/src/features/numbering/picture-bullet.js +88 -0
- package/src/features/ole-object/catalog.d.ts +300 -0
- package/src/features/ole-object/catalog.js +908 -0
- package/src/features/ole-object/index.d.ts +526 -0
- package/src/features/ole-object/index.js +1421 -0
- package/src/features/ole-object/relationship.d.ts +27 -0
- package/src/features/ole-object/relationship.js +27 -0
- package/src/features/ole-object/typed-dom.d.ts +186 -0
- package/src/features/ole-object/typed-dom.js +595 -0
- package/src/features/properties/index.d.ts +205 -0
- package/src/features/properties/index.js +549 -0
- package/src/features/revisions/index.d.ts +204 -0
- package/src/features/revisions/index.js +695 -0
- package/src/features/sections/column-collection.d.ts +119 -0
- package/src/features/sections/column-collection.js +478 -0
- package/src/features/sections/column.d.ts +15 -0
- package/src/features/sections/column.js +37 -0
- package/src/features/sections/index.d.ts +91 -0
- package/src/features/sections/index.js +1096 -0
- package/src/features/sections/margins.d.ts +40 -0
- package/src/features/sections/margins.js +105 -0
- package/src/features/sections/page-number-style.d.ts +21 -0
- package/src/features/sections/page-number-style.js +62 -0
- package/src/features/sections/page-orientation.d.ts +10 -0
- package/src/features/sections/page-orientation.js +10 -0
- package/src/features/sections/page-setup.d.ts +435 -0
- package/src/features/sections/page-setup.js +1479 -0
- package/src/features/sections/page-size.d.ts +59 -0
- package/src/features/sections/page-size.js +68 -0
- package/src/features/sections/section-break-code.d.ts +27 -0
- package/src/features/sections/section-break-code.js +60 -0
- package/src/features/sections/section-document-association.d.ts +18 -0
- package/src/features/sections/section-document-association.js +31 -0
- package/src/features/sections/section-validation.d.ts +43 -0
- package/src/features/sections/section-validation.js +97 -0
- package/src/features/settings/attached-template.d.ts +35 -0
- package/src/features/settings/attached-template.js +98 -0
- package/src/features/settings/compat-settings.d.ts +216 -0
- package/src/features/settings/compat-settings.js +508 -0
- package/src/features/settings/document-background.d.ts +59 -0
- package/src/features/settings/document-background.js +131 -0
- package/src/features/settings/document-protection.d.ts +65 -0
- package/src/features/settings/document-protection.js +157 -0
- package/src/features/settings/document-settings-facades.d.ts +108 -0
- package/src/features/settings/document-settings-facades.js +312 -0
- package/src/features/settings/document-settings-values.d.ts +43 -0
- package/src/features/settings/document-settings-values.js +60 -0
- package/src/features/settings/footnote-properties.d.ts +211 -0
- package/src/features/settings/footnote-properties.js +591 -0
- package/src/features/settings/index.d.ts +356 -0
- package/src/features/settings/index.js +829 -0
- package/src/features/settings/settings-children.d.ts +151 -0
- package/src/features/settings/settings-children.js +505 -0
- package/src/features/settings/web-settings.d.ts +88 -0
- package/src/features/settings/web-settings.js +227 -0
- package/src/features/settings/zoom.d.ts +79 -0
- package/src/features/settings/zoom.js +147 -0
- package/src/features/styles/builtin-catalog.d.ts +159 -0
- package/src/features/styles/builtin-catalog.js +963 -0
- package/src/features/styles/builtin-resolver.d.ts +49 -0
- package/src/features/styles/builtin-resolver.js +165 -0
- package/src/features/styles/default-styles.d.ts +37 -0
- package/src/features/styles/default-styles.js +186 -0
- package/src/features/styles/default-theme.d.ts +13 -0
- package/src/features/styles/default-theme.js +13 -0
- package/src/features/styles/doc-defaults.d.ts +58 -0
- package/src/features/styles/doc-defaults.js +178 -0
- package/src/features/styles/formatting-resolver.d.ts +27 -0
- package/src/features/styles/formatting-resolver.js +72 -0
- package/src/features/styles/index.d.ts +256 -0
- package/src/features/styles/index.js +1325 -0
- package/src/features/styles/latent-styles.d.ts +68 -0
- package/src/features/styles/latent-styles.js +305 -0
- package/src/features/styles/paragraph-properties.d.ts +71 -0
- package/src/features/styles/paragraph-properties.js +237 -0
- package/src/features/styles/run-properties.d.ts +93 -0
- package/src/features/styles/run-properties.js +516 -0
- package/src/features/styles/style-base.d.ts +402 -0
- package/src/features/styles/style-base.js +1026 -0
- package/src/features/styles/style-collection.d.ts +264 -0
- package/src/features/styles/style-collection.js +714 -0
- package/src/features/styles/style-format-bridge.d.ts +64 -0
- package/src/features/styles/style-format-bridge.js +100 -0
- package/src/features/styles/style.d.ts +84 -0
- package/src/features/styles/style.js +375 -0
- package/src/features/styles/styles-with-effects.d.ts +71 -0
- package/src/features/styles/styles-with-effects.js +180 -0
- package/src/features/styles/table-style.d.ts +272 -0
- package/src/features/styles/table-style.js +1226 -0
- package/src/features/styles/theme.d.ts +126 -0
- package/src/features/styles/theme.js +377 -0
- package/src/features/tables/border-style-map.d.ts +24 -0
- package/src/features/tables/border-style-map.js +81 -0
- package/src/features/tables/borders.d.ts +126 -0
- package/src/features/tables/borders.js +527 -0
- package/src/features/tables/collections.d.ts +113 -0
- package/src/features/tables/collections.js +261 -0
- package/src/features/tables/format.d.ts +208 -0
- package/src/features/tables/format.js +716 -0
- package/src/features/tables/index.d.ts +597 -0
- package/src/features/tables/index.js +2386 -0
- package/src/features/tables/paddings.d.ts +41 -0
- package/src/features/tables/paddings.js +97 -0
- package/src/features/tables/tbl-pr-positioning.d.ts +27 -0
- package/src/features/tables/tbl-pr-positioning.js +178 -0
- package/src/features/tables/tbl-pr.d.ts +528 -0
- package/src/features/tables/tbl-pr.js +1208 -0
- package/src/features/tables/tc-pr.d.ts +168 -0
- package/src/features/tables/tc-pr.js +553 -0
- package/src/features/tables/tr-pr.d.ts +60 -0
- package/src/features/tables/tr-pr.js +215 -0
- package/src/features/watermark/detect.d.ts +76 -0
- package/src/features/watermark/detect.js +219 -0
- package/src/features/watermark/index.d.ts +28 -0
- package/src/features/watermark/index.js +91 -0
- package/src/features/watermark/logical-store.d.ts +29 -0
- package/src/features/watermark/logical-store.js +31 -0
- package/src/features/watermark/model.d.ts +285 -0
- package/src/features/watermark/model.js +597 -0
- package/src/features/watermark/parse.d.ts +84 -0
- package/src/features/watermark/parse.js +815 -0
- package/src/features/watermark/serialize.d.ts +98 -0
- package/src/features/watermark/serialize.js +1517 -0
- package/src/global.js +1 -0
- package/src/index.d.ts +2 -0
- package/src/index.js +2 -0
|
@@ -0,0 +1,1666 @@
|
|
|
1
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
2
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
3
|
+
if (!m) return o;
|
|
4
|
+
var i = m.call(o), r, ar = [], e;
|
|
5
|
+
try {
|
|
6
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
7
|
+
}
|
|
8
|
+
catch (error) { e = { error: error }; }
|
|
9
|
+
finally {
|
|
10
|
+
try {
|
|
11
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
12
|
+
}
|
|
13
|
+
finally { if (e) throw e.error; }
|
|
14
|
+
}
|
|
15
|
+
return ar;
|
|
16
|
+
};
|
|
17
|
+
var __spread = (this && this.__spread) || function () {
|
|
18
|
+
for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i]));
|
|
19
|
+
return ar;
|
|
20
|
+
};
|
|
21
|
+
var __values = (this && this.__values) || function (o) {
|
|
22
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator], i = 0;
|
|
23
|
+
if (m) return m.call(o);
|
|
24
|
+
return {
|
|
25
|
+
next: function () {
|
|
26
|
+
if (o && i >= o.length) o = void 0;
|
|
27
|
+
return { value: o && o[i++], done: !o };
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
import { DetachedObjectError, DocxError } from '../../core/errors/docx-error';
|
|
32
|
+
import { registerAlwaysOnBodyFeatureBootstrap } from '../document/body-always-on';
|
|
33
|
+
import { bodyItemToBlock, isSupportedBodyItem, projectBlockToBodyItem, } from '../document/body-item-adapters';
|
|
34
|
+
import { isParagraphBodyItem } from '../document/body-item';
|
|
35
|
+
import { parseBodyBlocks, serializeBodyBlocks } from '../document/body-blocks';
|
|
36
|
+
import { Paragraph } from '../document/paragraph';
|
|
37
|
+
import { TextRange } from '../document/text-range';
|
|
38
|
+
import { isWml, wmlElement } from '../document/wml';
|
|
39
|
+
import { detachedBodyBlockParseContext } from '../../core/registry/block-handlers';
|
|
40
|
+
import { allocateRelationshipId } from '../../core/opc/relationships';
|
|
41
|
+
import { partByName, relationshipsForPart } from '../../core/opc/package';
|
|
42
|
+
import { partName, partNameKey, resolveInternalTarget } from '../../core/opc/part-name';
|
|
43
|
+
import { featureId, isFeatureRegistered, registerFeature, registerFeatureMultiPartHandler, replaceOrAddPackagePart, } from '../../core/registry/index';
|
|
44
|
+
import { parseXml, serializeXml, WML_TRANSITIONAL_NAMESPACE } from '../../core/xml/index';
|
|
45
|
+
import { defaultLetterPageSetup, finalSection, paragraphSectionBreak, setFinalSection, setParagraphSectionBreak, ownerDocumentOf, associatePageSetupDocument, ensureFinalSectionProperties, PageSetup, } from '../sections/index';
|
|
46
|
+
import { HeaderFooter, registerHeadersFootersSlotFactory, resetHeadersFootersSlotFactoryForTests, registerHeadersFootersLinkToPreviousHandlers, resetHeadersFootersLinkToPreviousHandlersForTests, } from '../document/headers-footers';
|
|
47
|
+
/** @public Compat value alias for instanceof / legacy callers. */
|
|
48
|
+
export var Header = HeaderFooter;
|
|
49
|
+
/** @public Compat value alias for instanceof / legacy callers. */
|
|
50
|
+
export var Footer = HeaderFooter;
|
|
51
|
+
export { HeaderFooter };
|
|
52
|
+
var HEADERS_FOOTERS = featureId('headers-footers');
|
|
53
|
+
/**
|
|
54
|
+
* Cross-bundle identity for HeadersFootersCatalog.
|
|
55
|
+
*
|
|
56
|
+
* Main entry and @syncfusion/ej2-docx/headers-footers can load separate module graphs of the
|
|
57
|
+
* same class. instanceof fails across those graphs; Symbol.for stays shared.
|
|
58
|
+
* @private
|
|
59
|
+
*/
|
|
60
|
+
var HEADERS_FOOTERS_CATALOG_BRAND = Symbol.for('@syncfusion/ej2-docx.HeadersFootersCatalog');
|
|
61
|
+
/**
|
|
62
|
+
* @private
|
|
63
|
+
* Transitional header relationship (ECMA-376-4 §9.2.8). */
|
|
64
|
+
export var HEADER_RELATIONSHIP_TYPE = 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/header';
|
|
65
|
+
/**
|
|
66
|
+
* @private
|
|
67
|
+
* Transitional footer relationship (ECMA-376-4 §9.2.7). */
|
|
68
|
+
export var FOOTER_RELATIONSHIP_TYPE = 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/footer';
|
|
69
|
+
/**
|
|
70
|
+
* @private
|
|
71
|
+
* Strict header relationship (ECMA-376-1 §11.3.6). */
|
|
72
|
+
export var STRICT_HEADER_RELATIONSHIP_TYPE = 'http://purl.oclc.org/ooxml/officeDocument/relationships/header';
|
|
73
|
+
/**
|
|
74
|
+
* @private
|
|
75
|
+
* Strict footer relationship (ECMA-376-1 §11.3.9). */
|
|
76
|
+
export var STRICT_FOOTER_RELATIONSHIP_TYPE = 'http://purl.oclc.org/ooxml/officeDocument/relationships/footer';
|
|
77
|
+
/**
|
|
78
|
+
* @private
|
|
79
|
+
* ECMA-376-1 §11.3.6 Header part content type. */
|
|
80
|
+
export var HEADER_CONTENT_TYPE = 'application/vnd.openxmlformats-officedocument.wordprocessingml.header+xml';
|
|
81
|
+
/**
|
|
82
|
+
* @private
|
|
83
|
+
* ECMA-376-1 §11.3.9 Footer part content type. */
|
|
84
|
+
export var FOOTER_CONTENT_TYPE = 'application/vnd.openxmlformats-officedocument.wordprocessingml.footer+xml';
|
|
85
|
+
var HEADER_RELATIONSHIP_TYPES = [HEADER_RELATIONSHIP_TYPE, STRICT_HEADER_RELATIONSHIP_TYPE];
|
|
86
|
+
var FOOTER_RELATIONSHIP_TYPES = [FOOTER_RELATIONSHIP_TYPE, STRICT_FOOTER_RELATIONSHIP_TYPE];
|
|
87
|
+
var ALL_RELATIONSHIP_TYPES = __spread(HEADER_RELATIONSHIP_TYPES, FOOTER_RELATIONSHIP_TYPES);
|
|
88
|
+
var utf8Decoder = new TextDecoder('utf-8');
|
|
89
|
+
var utf8 = new TextEncoder();
|
|
90
|
+
function kindForRelationshipType(type) {
|
|
91
|
+
if (HEADER_RELATIONSHIP_TYPES.indexOf(type) !== -1) {
|
|
92
|
+
return 'header';
|
|
93
|
+
}
|
|
94
|
+
if (FOOTER_RELATIONSHIP_TYPES.indexOf(type) !== -1) {
|
|
95
|
+
return 'footer';
|
|
96
|
+
}
|
|
97
|
+
return undefined;
|
|
98
|
+
}
|
|
99
|
+
function contentTypeForKind(kind) {
|
|
100
|
+
return kind === 'header' ? HEADER_CONTENT_TYPE : FOOTER_CONTENT_TYPE;
|
|
101
|
+
}
|
|
102
|
+
function rootLocalName(kind) {
|
|
103
|
+
return kind === 'header' ? 'hdr' : 'ftr';
|
|
104
|
+
}
|
|
105
|
+
function relativeTarget(partNameValue) {
|
|
106
|
+
var logical = partNameValue.slice('/word/'.length);
|
|
107
|
+
return logical;
|
|
108
|
+
}
|
|
109
|
+
function firstParagraphText(blocks) {
|
|
110
|
+
var e_1, _a, e_2, _b;
|
|
111
|
+
try {
|
|
112
|
+
for (var blocks_1 = __values(blocks), blocks_1_1 = blocks_1.next(); !blocks_1_1.done; blocks_1_1 = blocks_1.next()) {
|
|
113
|
+
var block = blocks_1_1.value;
|
|
114
|
+
if (block.type !== 'paragraph') {
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
try {
|
|
118
|
+
for (var _c = __values(block.paragraph.items), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
119
|
+
var inline = _d.value;
|
|
120
|
+
if (inline instanceof TextRange) {
|
|
121
|
+
return inline.text;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
126
|
+
finally {
|
|
127
|
+
try {
|
|
128
|
+
if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
|
|
129
|
+
}
|
|
130
|
+
finally { if (e_2) throw e_2.error; }
|
|
131
|
+
}
|
|
132
|
+
return '';
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
136
|
+
finally {
|
|
137
|
+
try {
|
|
138
|
+
if (blocks_1_1 && !blocks_1_1.done && (_a = blocks_1.return)) _a.call(blocks_1);
|
|
139
|
+
}
|
|
140
|
+
finally { if (e_1) throw e_1.error; }
|
|
141
|
+
}
|
|
142
|
+
return undefined;
|
|
143
|
+
}
|
|
144
|
+
function blocksWithSimpleText(text, owner) {
|
|
145
|
+
if (owner === void 0) { owner = detachedParagraphOwner; }
|
|
146
|
+
var paragraph = Paragraph.fromXml(wmlElement('p', {
|
|
147
|
+
children: [
|
|
148
|
+
wmlElement('r', {
|
|
149
|
+
children: [
|
|
150
|
+
wmlElement('t', {
|
|
151
|
+
children: [{ kind: 'text', value: text }],
|
|
152
|
+
}),
|
|
153
|
+
],
|
|
154
|
+
}),
|
|
155
|
+
],
|
|
156
|
+
}), owner);
|
|
157
|
+
return [{ type: 'paragraph', paragraph: paragraph }];
|
|
158
|
+
}
|
|
159
|
+
var detachedParagraphOwner = {
|
|
160
|
+
assertAttachedParagraph: function () {
|
|
161
|
+
return;
|
|
162
|
+
},
|
|
163
|
+
owningDocument: function () {
|
|
164
|
+
throw new DetachedObjectError('Header or footer content is not in a document');
|
|
165
|
+
},
|
|
166
|
+
};
|
|
167
|
+
/**
|
|
168
|
+
* Paragraph owner scoped to one header/footer catalog entry.
|
|
169
|
+
* Membership is checked against the live entry blocks.
|
|
170
|
+
*/
|
|
171
|
+
var HeaderFooterPartOwner = /** @class */ (function () {
|
|
172
|
+
function HeaderFooterPartOwner(document, relationshipId) {
|
|
173
|
+
this.document = document;
|
|
174
|
+
this.relationshipId = relationshipId;
|
|
175
|
+
}
|
|
176
|
+
HeaderFooterPartOwner.prototype.assertAttachedParagraph = function (target) {
|
|
177
|
+
var catalog = headersFootersFor(this.document);
|
|
178
|
+
var entry = catalog.entryForRelationship(this.relationshipId);
|
|
179
|
+
if (entry === undefined) {
|
|
180
|
+
throw new DetachedObjectError('Header or footer part is no longer loaded');
|
|
181
|
+
}
|
|
182
|
+
var found = entry.blocks.some(function (block) { return block.type === 'paragraph' && block.paragraph === target; });
|
|
183
|
+
if (!found) {
|
|
184
|
+
throw new DetachedObjectError('This paragraph is no longer in its header or footer');
|
|
185
|
+
}
|
|
186
|
+
};
|
|
187
|
+
/**
|
|
188
|
+
* @private
|
|
189
|
+
*/
|
|
190
|
+
HeaderFooterPartOwner.prototype.owningDocument = function () {
|
|
191
|
+
return this.document;
|
|
192
|
+
};
|
|
193
|
+
return HeaderFooterPartOwner;
|
|
194
|
+
}());
|
|
195
|
+
function ownerForEntry(document, relationshipId) {
|
|
196
|
+
return new HeaderFooterPartOwner(document, relationshipId);
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Bind a feature body block (table, content control, …) to the owning document when
|
|
200
|
+
* the value exposes `bindDocument`. Mirrors {@link Body} without exporting
|
|
201
|
+
* that helper from `document.ts`.
|
|
202
|
+
*/
|
|
203
|
+
function bindDocumentToFeatureBlock(value, document) {
|
|
204
|
+
if (typeof value !== 'object' || value === null || !('bindDocument' in value)) {
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
var bindDocument = value.bindDocument;
|
|
208
|
+
bindDocument.call(value, document);
|
|
209
|
+
}
|
|
210
|
+
function releaseFeatureBlockContent(value) {
|
|
211
|
+
if (typeof value !== 'object' || value === null || !('releaseContent' in value)) {
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
var releaseContent = value.releaseContent;
|
|
215
|
+
// TS 3.3: Function.call typing treats free functions as `this: void`.
|
|
216
|
+
if (typeof releaseContent === 'function') {
|
|
217
|
+
releaseContent.call(value);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
function attachEntryParagraphs(document, entry) {
|
|
221
|
+
var e_3, _a;
|
|
222
|
+
var owner = ownerForEntry(document, entry.relationshipId);
|
|
223
|
+
try {
|
|
224
|
+
for (var _b = __values(entry.blocks), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
225
|
+
var block = _c.value;
|
|
226
|
+
if (block.type === 'paragraph') {
|
|
227
|
+
block.paragraph.attach(owner);
|
|
228
|
+
}
|
|
229
|
+
else if (block.type === 'feature') {
|
|
230
|
+
bindDocumentToFeatureBlock(block.value, document);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
235
|
+
finally {
|
|
236
|
+
try {
|
|
237
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
238
|
+
}
|
|
239
|
+
finally { if (e_3) throw e_3.error; }
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
function detachEntryBlocks(blocks) {
|
|
243
|
+
var e_4, _a;
|
|
244
|
+
try {
|
|
245
|
+
for (var blocks_2 = __values(blocks), blocks_2_1 = blocks_2.next(); !blocks_2_1.done; blocks_2_1 = blocks_2.next()) {
|
|
246
|
+
var block = blocks_2_1.value;
|
|
247
|
+
if (block.type === 'paragraph') {
|
|
248
|
+
block.paragraph.detach();
|
|
249
|
+
}
|
|
250
|
+
else if (block.type === 'feature') {
|
|
251
|
+
releaseFeatureBlockContent(block.value);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
256
|
+
finally {
|
|
257
|
+
try {
|
|
258
|
+
if (blocks_2_1 && !blocks_2_1.done && (_a = blocks_2.return)) _a.call(blocks_2);
|
|
259
|
+
}
|
|
260
|
+
finally { if (e_4) throw e_4.error; }
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
function parseHeaderFooterPart(part, relationship, kind) {
|
|
264
|
+
var root = parseXml(utf8Decoder.decode(part.data));
|
|
265
|
+
var localName = rootLocalName(kind);
|
|
266
|
+
if (!isWml(root, localName)) {
|
|
267
|
+
return undefined;
|
|
268
|
+
}
|
|
269
|
+
var blocks = parseBodyBlocks(root.children, detachedBodyBlockParseContext());
|
|
270
|
+
return {
|
|
271
|
+
partName: part.name,
|
|
272
|
+
relationshipId: relationship.id,
|
|
273
|
+
relationshipType: relationship.type,
|
|
274
|
+
kind: kind,
|
|
275
|
+
rootExtra: {
|
|
276
|
+
attributes: root.attributes,
|
|
277
|
+
namespaceDeclarations: root.namespaceDeclarations.length > 0
|
|
278
|
+
? root.namespaceDeclarations
|
|
279
|
+
: [{ prefix: 'w', namespaceUri: WML_TRANSITIONAL_NAMESPACE }],
|
|
280
|
+
},
|
|
281
|
+
blocks: blocks,
|
|
282
|
+
dirty: false,
|
|
283
|
+
pendingRelationship: undefined,
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* In-memory header and footer parts linked from the Main Document.
|
|
288
|
+
* @private
|
|
289
|
+
*/
|
|
290
|
+
var HeadersFootersCatalog = /** @class */ (function () {
|
|
291
|
+
/**
|
|
292
|
+
* @private
|
|
293
|
+
*/
|
|
294
|
+
function HeadersFootersCatalog(entries) {
|
|
295
|
+
var e_5, _a;
|
|
296
|
+
this.entries = entries;
|
|
297
|
+
// TS 3.3 widens mapped pair literals to (T|U)[] rather than [T, U].
|
|
298
|
+
var byRelationshipIdEntries = [];
|
|
299
|
+
try {
|
|
300
|
+
for (var _b = __values(entries.values()), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
301
|
+
var entry = _c.value;
|
|
302
|
+
byRelationshipIdEntries.push([entry.relationshipId, entry]);
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
catch (e_5_1) { e_5 = { error: e_5_1 }; }
|
|
306
|
+
finally {
|
|
307
|
+
try {
|
|
308
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
309
|
+
}
|
|
310
|
+
finally { if (e_5) throw e_5.error; }
|
|
311
|
+
}
|
|
312
|
+
this.byRelationshipId = new Map(byRelationshipIdEntries);
|
|
313
|
+
this.catalogDirty = false;
|
|
314
|
+
this.boundDocument = undefined;
|
|
315
|
+
// Shared across duplicate ESM graphs (main bundle vs feature subpath).
|
|
316
|
+
this[HEADERS_FOOTERS_CATALOG_BRAND] = true;
|
|
317
|
+
}
|
|
318
|
+
/**
|
|
319
|
+
* Bind this catalog to a live document so paragraph owners can resolve.
|
|
320
|
+
* Re-attaches existing paragraph blocks to entry-scoped owners.
|
|
321
|
+
* @private
|
|
322
|
+
*/
|
|
323
|
+
HeadersFootersCatalog.prototype.bindDocument = function (document) {
|
|
324
|
+
var e_6, _a;
|
|
325
|
+
this.boundDocument = document;
|
|
326
|
+
try {
|
|
327
|
+
for (var _b = __values(this.entries.values()), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
328
|
+
var entry = _c.value;
|
|
329
|
+
attachEntryParagraphs(document, entry);
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
catch (e_6_1) { e_6 = { error: e_6_1 }; }
|
|
333
|
+
finally {
|
|
334
|
+
try {
|
|
335
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
336
|
+
}
|
|
337
|
+
finally { if (e_6) throw e_6.error; }
|
|
338
|
+
}
|
|
339
|
+
};
|
|
340
|
+
/**
|
|
341
|
+
* @private
|
|
342
|
+
*/
|
|
343
|
+
HeadersFootersCatalog.prototype.entryForRelationship = function (relationshipId) {
|
|
344
|
+
return this.byRelationshipId.get(relationshipId);
|
|
345
|
+
};
|
|
346
|
+
HeadersFootersCatalog.prototype.requireBoundDocument = function () {
|
|
347
|
+
if (this.boundDocument === undefined) {
|
|
348
|
+
throw new DocxError('content/invalid-header-footer-reference', 'Headers/footers catalog is not bound to a document');
|
|
349
|
+
}
|
|
350
|
+
return this.boundDocument;
|
|
351
|
+
};
|
|
352
|
+
HeadersFootersCatalog.prototype.requireEntry = function (relationshipId) {
|
|
353
|
+
var entry = this.byRelationshipId.get(relationshipId);
|
|
354
|
+
if (entry === undefined) {
|
|
355
|
+
throw new DocxError('content/invalid-header-footer-reference', "Header/footer relationship " + relationshipId + " is not loaded in this document");
|
|
356
|
+
}
|
|
357
|
+
return entry;
|
|
358
|
+
};
|
|
359
|
+
/**
|
|
360
|
+
* @private
|
|
361
|
+
*/
|
|
362
|
+
HeadersFootersCatalog.prototype.isDirty = function () {
|
|
363
|
+
var e_7, _a;
|
|
364
|
+
if (this.catalogDirty) {
|
|
365
|
+
return true;
|
|
366
|
+
}
|
|
367
|
+
try {
|
|
368
|
+
for (var _b = __values(this.entries.values()), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
369
|
+
var entry = _c.value;
|
|
370
|
+
if (entry.dirty || entry.pendingRelationship !== undefined) {
|
|
371
|
+
return true;
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
catch (e_7_1) { e_7 = { error: e_7_1 }; }
|
|
376
|
+
finally {
|
|
377
|
+
try {
|
|
378
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
379
|
+
}
|
|
380
|
+
finally { if (e_7) throw e_7.error; }
|
|
381
|
+
}
|
|
382
|
+
return false;
|
|
383
|
+
};
|
|
384
|
+
/**
|
|
385
|
+
* @private
|
|
386
|
+
*/
|
|
387
|
+
HeadersFootersCatalog.prototype.applyToPackage = function (pkg, mainPartName) {
|
|
388
|
+
var e_8, _a;
|
|
389
|
+
var next = pkg;
|
|
390
|
+
var _loop_1 = function (entry) {
|
|
391
|
+
if (!entry.dirty && entry.pendingRelationship === undefined) {
|
|
392
|
+
return "continue";
|
|
393
|
+
}
|
|
394
|
+
var xml = serializeHeaderFooterPart(entry);
|
|
395
|
+
var rel = entry.pendingRelationship != null ? entry.pendingRelationship : relationshipsForPart(next, mainPartName).items.find(function (item) { return item.id === entry.relationshipId; });
|
|
396
|
+
next = replaceOrAddPackagePart(next, mainPartName, entry.partName, contentTypeForKind(entry.kind), xml, rel);
|
|
397
|
+
entry.dirty = false;
|
|
398
|
+
entry.pendingRelationship = undefined;
|
|
399
|
+
};
|
|
400
|
+
try {
|
|
401
|
+
for (var _b = __values(this.entries.values()), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
402
|
+
var entry = _c.value;
|
|
403
|
+
_loop_1(entry);
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
catch (e_8_1) { e_8 = { error: e_8_1 }; }
|
|
407
|
+
finally {
|
|
408
|
+
try {
|
|
409
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
410
|
+
}
|
|
411
|
+
finally { if (e_8) throw e_8.error; }
|
|
412
|
+
}
|
|
413
|
+
this.catalogDirty = false;
|
|
414
|
+
return next;
|
|
415
|
+
};
|
|
416
|
+
/**
|
|
417
|
+
* @private
|
|
418
|
+
*/
|
|
419
|
+
HeadersFootersCatalog.prototype.ensureDefaultPart = function (kind, section, usedRelIds, usedPartNames) {
|
|
420
|
+
return this.ensurePart(kind, section, 'default', usedRelIds, usedPartNames);
|
|
421
|
+
};
|
|
422
|
+
/**
|
|
423
|
+
* @private
|
|
424
|
+
*/
|
|
425
|
+
HeadersFootersCatalog.prototype.ensurePart = function (kind, section, refType, usedRelIds, usedPartNames) {
|
|
426
|
+
var existingRel = section.headerFooterReferenceId(kind, refType);
|
|
427
|
+
if (existingRel !== undefined) {
|
|
428
|
+
var entry_1 = this.byRelationshipId.get(existingRel);
|
|
429
|
+
if (entry_1 !== undefined) {
|
|
430
|
+
return { entry: entry_1, relationshipId: existingRel };
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
// Include catalog-pending part names so a second allocate on the same kind
|
|
434
|
+
// does not collide with a part already added to the catalog but not yet in the package.
|
|
435
|
+
var catalogPartNameKeys = new Set(__spread(this.entries.keys()).map(function (n) { return partNameKey(n); }));
|
|
436
|
+
var allUsedPartNames = new Set(__spread(usedPartNames, catalogPartNameKeys));
|
|
437
|
+
var partNameValue = allocatePartName(kind, allUsedPartNames);
|
|
438
|
+
// Accumulate all tried IDs to avoid cycling back to an already-tried value.
|
|
439
|
+
// usedRelIds reflects only package relationships; catalog entries may not be
|
|
440
|
+
// persisted yet, so we must also exclude every ID already in this catalog.
|
|
441
|
+
var allUsedRelIds = new Set(__spread(usedRelIds, this.byRelationshipId.keys()));
|
|
442
|
+
var relId = allocateRelationshipId(allUsedRelIds);
|
|
443
|
+
var relationshipType = kind === 'header' ? HEADER_RELATIONSHIP_TYPE : FOOTER_RELATIONSHIP_TYPE;
|
|
444
|
+
var entry = {
|
|
445
|
+
partName: partNameValue,
|
|
446
|
+
relationshipId: relId,
|
|
447
|
+
relationshipType: relationshipType,
|
|
448
|
+
kind: kind,
|
|
449
|
+
rootExtra: {
|
|
450
|
+
attributes: [],
|
|
451
|
+
namespaceDeclarations: [{ prefix: 'w', namespaceUri: WML_TRANSITIONAL_NAMESPACE }],
|
|
452
|
+
},
|
|
453
|
+
// Always-present section slots stay empty until content is written.
|
|
454
|
+
// setSimpleText / authoring helpers still add paragraphs explicitly.
|
|
455
|
+
blocks: [],
|
|
456
|
+
dirty: true,
|
|
457
|
+
pendingRelationship: {
|
|
458
|
+
id: relId,
|
|
459
|
+
type: relationshipType,
|
|
460
|
+
target: relativeTarget(partNameValue),
|
|
461
|
+
extraAttributes: [],
|
|
462
|
+
children: [],
|
|
463
|
+
},
|
|
464
|
+
};
|
|
465
|
+
this.entries.set(partNameValue, entry);
|
|
466
|
+
this.byRelationshipId.set(relId, entry);
|
|
467
|
+
this.catalogDirty = true;
|
|
468
|
+
return { entry: entry, relationshipId: relId };
|
|
469
|
+
};
|
|
470
|
+
/**
|
|
471
|
+
* @private
|
|
472
|
+
* Whether a header or footer relationship id is loaded in this catalog. */
|
|
473
|
+
HeadersFootersCatalog.prototype.hasRelationship = function (relationshipId) {
|
|
474
|
+
return this.byRelationshipId.has(relationshipId);
|
|
475
|
+
};
|
|
476
|
+
/**
|
|
477
|
+
* Relationship ids for loaded parts of the given kind, in catalog order.
|
|
478
|
+
* @private
|
|
479
|
+
*/
|
|
480
|
+
HeadersFootersCatalog.prototype.relationshipIds = function (kind) {
|
|
481
|
+
var e_9, _a;
|
|
482
|
+
var ids = [];
|
|
483
|
+
try {
|
|
484
|
+
for (var _b = __values(this.entries.values()), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
485
|
+
var entry = _c.value;
|
|
486
|
+
if (entry.kind === kind) {
|
|
487
|
+
ids.push(entry.relationshipId);
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
catch (e_9_1) { e_9 = { error: e_9_1 }; }
|
|
492
|
+
finally {
|
|
493
|
+
try {
|
|
494
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
495
|
+
}
|
|
496
|
+
finally { if (e_9) throw e_9.error; }
|
|
497
|
+
}
|
|
498
|
+
return ids;
|
|
499
|
+
};
|
|
500
|
+
/**
|
|
501
|
+
* Body items for a header/footer part by relationship id (paragraphs, tables,
|
|
502
|
+
* block content controls, residuals), in document order.
|
|
503
|
+
*
|
|
504
|
+
* Empty when the relationship is missing. When the catalog is document-bound,
|
|
505
|
+
* paragraphs and feature blocks are attached for mutation.
|
|
506
|
+
* @private
|
|
507
|
+
*/
|
|
508
|
+
HeadersFootersCatalog.prototype.itemsForRelationship = function (relationshipId) {
|
|
509
|
+
var e_10, _a;
|
|
510
|
+
var entry = this.byRelationshipId.get(relationshipId);
|
|
511
|
+
if (entry === undefined) {
|
|
512
|
+
return [];
|
|
513
|
+
}
|
|
514
|
+
if (this.boundDocument !== undefined) {
|
|
515
|
+
attachEntryParagraphs(this.boundDocument, entry);
|
|
516
|
+
}
|
|
517
|
+
var projected = [];
|
|
518
|
+
try {
|
|
519
|
+
for (var _b = __values(entry.blocks), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
520
|
+
var block = _c.value;
|
|
521
|
+
var item = projectBlockToBodyItem(block);
|
|
522
|
+
if (item !== undefined) {
|
|
523
|
+
projected.push(item);
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
catch (e_10_1) { e_10 = { error: e_10_1 }; }
|
|
528
|
+
finally {
|
|
529
|
+
try {
|
|
530
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
531
|
+
}
|
|
532
|
+
finally { if (e_10) throw e_10.error; }
|
|
533
|
+
}
|
|
534
|
+
return projected;
|
|
535
|
+
};
|
|
536
|
+
/**
|
|
537
|
+
* Modeled paragraphs for a header/footer part by relationship id.
|
|
538
|
+
*
|
|
539
|
+
* Empty when the relationship is missing or has no paragraph blocks.
|
|
540
|
+
* When the catalog is document-bound, paragraphs are attached for mutation.
|
|
541
|
+
* @private
|
|
542
|
+
*/
|
|
543
|
+
HeadersFootersCatalog.prototype.paragraphsForRelationship = function (relationshipId) {
|
|
544
|
+
var e_11, _a;
|
|
545
|
+
var entry = this.byRelationshipId.get(relationshipId);
|
|
546
|
+
if (entry === undefined) {
|
|
547
|
+
return [];
|
|
548
|
+
}
|
|
549
|
+
if (this.boundDocument !== undefined) {
|
|
550
|
+
attachEntryParagraphs(this.boundDocument, entry);
|
|
551
|
+
}
|
|
552
|
+
var paragraphs = [];
|
|
553
|
+
try {
|
|
554
|
+
for (var _b = __values(this.itemsForRelationship(relationshipId)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
555
|
+
var item = _c.value;
|
|
556
|
+
if (isParagraphBodyItem(item)) {
|
|
557
|
+
paragraphs.push(item);
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
catch (e_11_1) { e_11 = { error: e_11_1 }; }
|
|
562
|
+
finally {
|
|
563
|
+
try {
|
|
564
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
565
|
+
}
|
|
566
|
+
finally { if (e_11) throw e_11.error; }
|
|
567
|
+
}
|
|
568
|
+
return paragraphs;
|
|
569
|
+
};
|
|
570
|
+
/**
|
|
571
|
+
* @private
|
|
572
|
+
*/
|
|
573
|
+
HeadersFootersCatalog.prototype.setSimpleText = function (entry, text) {
|
|
574
|
+
var bound = boundHeaderFooterByRelId.get(entry.relationshipId);
|
|
575
|
+
detachEntryBlocks(entry.blocks);
|
|
576
|
+
if (bound !== undefined) {
|
|
577
|
+
entry.blocks = blocksWithSimpleText(text, bound);
|
|
578
|
+
// Keep Body store in sync without re-dirtying via lifecycle sync.
|
|
579
|
+
bound.replaceItemsSilent(entry.blocks.slice());
|
|
580
|
+
}
|
|
581
|
+
else if (this.boundDocument !== undefined) {
|
|
582
|
+
var owner = ownerForEntry(this.boundDocument, entry.relationshipId);
|
|
583
|
+
entry.blocks = blocksWithSimpleText(text, owner);
|
|
584
|
+
}
|
|
585
|
+
else {
|
|
586
|
+
entry.blocks = blocksWithSimpleText(text);
|
|
587
|
+
}
|
|
588
|
+
entry.dirty = true;
|
|
589
|
+
};
|
|
590
|
+
/**
|
|
591
|
+
* Replace the body of a loaded part with a single plain-text paragraph.
|
|
592
|
+
*
|
|
593
|
+
* Clears any prior rich body (multiple paragraphs, tables, opaque blocks).
|
|
594
|
+
*
|
|
595
|
+
* @throws DocxError `content/invalid-header-footer-reference` when the id is unknown.
|
|
596
|
+
* @private
|
|
597
|
+
*/
|
|
598
|
+
HeadersFootersCatalog.prototype.setSimpleTextForRelationship = function (relationshipId, text) {
|
|
599
|
+
var entry = this.requireEntry(relationshipId);
|
|
600
|
+
this.setSimpleText(entry, text);
|
|
601
|
+
};
|
|
602
|
+
/**
|
|
603
|
+
* Insert a body item at `index` in a header/footer part (`0…length` inclusive).
|
|
604
|
+
*
|
|
605
|
+
* Attaches paragraphs and feature blocks when the catalog is document-bound.
|
|
606
|
+
* Returns the same `item` reference for chaining.
|
|
607
|
+
*
|
|
608
|
+
* @throws RangeError if `index` is out of range.
|
|
609
|
+
* @throws DocxError when the relationship id is unknown or the catalog is unbound.
|
|
610
|
+
* @private
|
|
611
|
+
*/
|
|
612
|
+
HeadersFootersCatalog.prototype.insertBodyItemAtForRelationship = function (relationshipId, index, item) {
|
|
613
|
+
var _this = this;
|
|
614
|
+
var document = this.requireBoundDocument();
|
|
615
|
+
var entry = this.requireEntry(relationshipId);
|
|
616
|
+
if (!isSupportedBodyItem(item)) {
|
|
617
|
+
throw new TypeError('Unsupported body item type');
|
|
618
|
+
}
|
|
619
|
+
// Public index is over projected BodyItem instances (opaque blocks omitted).
|
|
620
|
+
var publicItems = this.itemsForRelationship(relationshipId);
|
|
621
|
+
if (index < 0 || index > publicItems.length) {
|
|
622
|
+
throw new RangeError("Body item index " + String(index) + " is out of range");
|
|
623
|
+
}
|
|
624
|
+
var block = bodyItemToBlock(item);
|
|
625
|
+
var bound = boundHeaderFooterByRelId.get(relationshipId);
|
|
626
|
+
if (block.type === 'paragraph') {
|
|
627
|
+
// Prefer HeaderFooter Body as paragraph owner when a live view is bound.
|
|
628
|
+
block.paragraph.attach(bound !== undefined ? bound : ownerForEntry(document, relationshipId));
|
|
629
|
+
}
|
|
630
|
+
else if (block.type === 'feature') {
|
|
631
|
+
bindDocumentToFeatureBlock(block.value, document);
|
|
632
|
+
}
|
|
633
|
+
var storeIndex;
|
|
634
|
+
if (index === publicItems.length) {
|
|
635
|
+
storeIndex = entry.blocks.length;
|
|
636
|
+
}
|
|
637
|
+
else {
|
|
638
|
+
var target_1 = publicItems[index];
|
|
639
|
+
storeIndex = entry.blocks.findIndex(function (candidate) {
|
|
640
|
+
var projected = projectBlockToBodyItem(candidate);
|
|
641
|
+
return projected !== undefined && _this.publicBodyItemsEqual(projected, target_1);
|
|
642
|
+
});
|
|
643
|
+
if (storeIndex < 0) {
|
|
644
|
+
throw new DetachedObjectError('Body item index is inconsistent');
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
var next = entry.blocks.slice();
|
|
648
|
+
next.splice(storeIndex, 0, block);
|
|
649
|
+
entry.blocks = next;
|
|
650
|
+
entry.dirty = true;
|
|
651
|
+
if (bound !== undefined) {
|
|
652
|
+
// Catalog wrote first; keep Body store identical without re-dirty via sync.
|
|
653
|
+
bound.replaceItemsSilent(entry.blocks.slice());
|
|
654
|
+
}
|
|
655
|
+
return item;
|
|
656
|
+
};
|
|
657
|
+
/**
|
|
658
|
+
* Remove the body item at `index` in a header/footer part (`0…length-1`).
|
|
659
|
+
* Paragraphs detach; feature blocks may release content.
|
|
660
|
+
*
|
|
661
|
+
* @throws RangeError if `index` is out of range.
|
|
662
|
+
* @throws DocxError when the relationship id is unknown.
|
|
663
|
+
* @private
|
|
664
|
+
*/
|
|
665
|
+
HeadersFootersCatalog.prototype.removeBodyItemAtForRelationship = function (relationshipId, index) {
|
|
666
|
+
var _this = this;
|
|
667
|
+
var entry = this.requireEntry(relationshipId);
|
|
668
|
+
var publicItems = this.itemsForRelationship(relationshipId);
|
|
669
|
+
if (index < 0 || index >= publicItems.length) {
|
|
670
|
+
throw new RangeError("Body item index " + String(index) + " is out of range");
|
|
671
|
+
}
|
|
672
|
+
var target = publicItems[index];
|
|
673
|
+
if (target === undefined) {
|
|
674
|
+
throw new RangeError("Body item index " + String(index) + " is out of range");
|
|
675
|
+
}
|
|
676
|
+
var storeIndex = entry.blocks.findIndex(function (candidate) {
|
|
677
|
+
var projected = projectBlockToBodyItem(candidate);
|
|
678
|
+
return projected !== undefined && _this.publicBodyItemsEqual(projected, target);
|
|
679
|
+
});
|
|
680
|
+
if (storeIndex < 0) {
|
|
681
|
+
throw new DetachedObjectError('Body item index is inconsistent');
|
|
682
|
+
}
|
|
683
|
+
var block = entry.blocks[storeIndex];
|
|
684
|
+
if (block === undefined) {
|
|
685
|
+
throw new RangeError("Body item index " + String(index) + " is out of range");
|
|
686
|
+
}
|
|
687
|
+
var next = entry.blocks.slice();
|
|
688
|
+
next.splice(storeIndex, 1);
|
|
689
|
+
entry.blocks = next;
|
|
690
|
+
if (block.type === 'paragraph') {
|
|
691
|
+
block.paragraph.detach();
|
|
692
|
+
}
|
|
693
|
+
else if (block.type === 'feature') {
|
|
694
|
+
releaseFeatureBlockContent(block.value);
|
|
695
|
+
}
|
|
696
|
+
entry.dirty = true;
|
|
697
|
+
var bound = boundHeaderFooterByRelId.get(relationshipId);
|
|
698
|
+
if (bound !== undefined) {
|
|
699
|
+
bound.replaceItemsSilent(entry.blocks.slice());
|
|
700
|
+
}
|
|
701
|
+
};
|
|
702
|
+
/**
|
|
703
|
+
* Remove a body item from a header/footer part by collection or payload identity.
|
|
704
|
+
*
|
|
705
|
+
* @throws DetachedObjectError when the item is not in the part.
|
|
706
|
+
* @throws DocxError when the relationship id is unknown.
|
|
707
|
+
* @private
|
|
708
|
+
*/
|
|
709
|
+
HeadersFootersCatalog.prototype.removeBodyItemForRelationship = function (relationshipId, item) {
|
|
710
|
+
var _this = this;
|
|
711
|
+
var entry = this.requireEntry(relationshipId);
|
|
712
|
+
var at = entry.blocks.findIndex(function (candidate) {
|
|
713
|
+
var projected = projectBlockToBodyItem(candidate);
|
|
714
|
+
return projected !== undefined && _this.publicBodyItemsEqual(projected, item);
|
|
715
|
+
});
|
|
716
|
+
if (at === -1) {
|
|
717
|
+
throw new DetachedObjectError('Body item is not in this header or footer');
|
|
718
|
+
}
|
|
719
|
+
var publicItems = this.itemsForRelationship(relationshipId);
|
|
720
|
+
var publicIndex = -1;
|
|
721
|
+
for (var i = 0; i < publicItems.length; i += 1) {
|
|
722
|
+
if (this.publicBodyItemsEqual(publicItems[i], item)) {
|
|
723
|
+
publicIndex = i;
|
|
724
|
+
break;
|
|
725
|
+
}
|
|
726
|
+
}
|
|
727
|
+
if (publicIndex === -1) {
|
|
728
|
+
throw new DetachedObjectError('Body item is not in this header or footer');
|
|
729
|
+
}
|
|
730
|
+
this.removeBodyItemAtForRelationship(relationshipId, publicIndex);
|
|
731
|
+
};
|
|
732
|
+
/**
|
|
733
|
+
* Append a paragraph to a header/footer part body.
|
|
734
|
+
*
|
|
735
|
+
* @param options - Optional style id and/or initial text (mirrors {@link Body.appendParagraph}).
|
|
736
|
+
* @throws DocxError when the relationship id is unknown or the catalog is unbound.
|
|
737
|
+
* @private
|
|
738
|
+
*/
|
|
739
|
+
HeadersFootersCatalog.prototype.appendParagraphForRelationship = function (relationshipId, options) {
|
|
740
|
+
var document = this.requireBoundDocument();
|
|
741
|
+
var entry = this.requireEntry(relationshipId);
|
|
742
|
+
var bound = boundHeaderFooterByRelId.get(relationshipId);
|
|
743
|
+
var owner = bound !== undefined ? bound : ownerForEntry(document, relationshipId);
|
|
744
|
+
var paragraph = new Paragraph(owner);
|
|
745
|
+
this.insertBodyItemAtForRelationship(relationshipId, this.itemsForRelationship(relationshipId).length, paragraph);
|
|
746
|
+
if ((options == null ? undefined : options.style) !== undefined) {
|
|
747
|
+
// Route through the styles facade so built-in ids/names resolve.
|
|
748
|
+
paragraph.applyStyle(options.style);
|
|
749
|
+
}
|
|
750
|
+
if ((options == null ? undefined : options.text) !== undefined) {
|
|
751
|
+
paragraph.appendText(options.text);
|
|
752
|
+
}
|
|
753
|
+
return paragraph;
|
|
754
|
+
};
|
|
755
|
+
/**
|
|
756
|
+
* Insert an empty paragraph among existing paragraphs of a part.
|
|
757
|
+
* Opaque / non-paragraph siblings keep their relative places.
|
|
758
|
+
*
|
|
759
|
+
* @param index - Index in the paragraph list, `0…length` inclusive.
|
|
760
|
+
* @throws RangeError if `index` is out of range.
|
|
761
|
+
* @throws DocxError when the relationship id is unknown or the catalog is unbound.
|
|
762
|
+
* @private
|
|
763
|
+
*/
|
|
764
|
+
HeadersFootersCatalog.prototype.insertParagraphForRelationship = function (relationshipId, index) {
|
|
765
|
+
var document = this.requireBoundDocument();
|
|
766
|
+
this.requireEntry(relationshipId);
|
|
767
|
+
var paragraphs = this.paragraphsForRelationship(relationshipId);
|
|
768
|
+
if (index < 0 || index > paragraphs.length) {
|
|
769
|
+
throw new RangeError("Paragraph index " + String(index) + " is out of range");
|
|
770
|
+
}
|
|
771
|
+
var bound = boundHeaderFooterByRelId.get(relationshipId);
|
|
772
|
+
var owner = bound !== undefined ? bound : ownerForEntry(document, relationshipId);
|
|
773
|
+
var paragraph = new Paragraph(owner);
|
|
774
|
+
if (index === paragraphs.length) {
|
|
775
|
+
this.insertBodyItemAtForRelationship(relationshipId, this.itemsForRelationship(relationshipId).length, paragraph);
|
|
776
|
+
}
|
|
777
|
+
else {
|
|
778
|
+
var target_2 = paragraphs[index];
|
|
779
|
+
if (target_2 === undefined) {
|
|
780
|
+
throw new RangeError("Paragraph index " + String(index) + " is out of range");
|
|
781
|
+
}
|
|
782
|
+
var publicItems = this.itemsForRelationship(relationshipId);
|
|
783
|
+
var at = publicItems.findIndex(function (item) { return isParagraphBodyItem(item) && item === target_2; });
|
|
784
|
+
if (at < 0) {
|
|
785
|
+
throw new DetachedObjectError('Paragraph index is inconsistent');
|
|
786
|
+
}
|
|
787
|
+
this.insertBodyItemAtForRelationship(relationshipId, at, paragraph);
|
|
788
|
+
}
|
|
789
|
+
return paragraph;
|
|
790
|
+
};
|
|
791
|
+
/**
|
|
792
|
+
* Remove a paragraph from a header/footer part. Further mutation throws {@link DetachedObjectError}.
|
|
793
|
+
*
|
|
794
|
+
* @throws DetachedObjectError when the paragraph is not in the part.
|
|
795
|
+
* @throws DocxError when the relationship id is unknown.
|
|
796
|
+
* @private
|
|
797
|
+
*/
|
|
798
|
+
HeadersFootersCatalog.prototype.removeParagraphForRelationship = function (relationshipId, paragraph) {
|
|
799
|
+
this.removeBodyItemForRelationship(relationshipId, paragraph);
|
|
800
|
+
};
|
|
801
|
+
/**
|
|
802
|
+
* Remove all body blocks from a header/footer part (empty `w:hdr` / `w:ftr`).
|
|
803
|
+
*
|
|
804
|
+
* @throws DocxError when the relationship id is unknown.
|
|
805
|
+
* @private
|
|
806
|
+
*/
|
|
807
|
+
HeadersFootersCatalog.prototype.clearForRelationship = function (relationshipId) {
|
|
808
|
+
var entry = this.requireEntry(relationshipId);
|
|
809
|
+
detachEntryBlocks(entry.blocks);
|
|
810
|
+
entry.blocks = [];
|
|
811
|
+
entry.dirty = true;
|
|
812
|
+
var bound = boundHeaderFooterByRelId.get(relationshipId);
|
|
813
|
+
if (bound !== undefined) {
|
|
814
|
+
bound.replaceItemsSilent([]);
|
|
815
|
+
}
|
|
816
|
+
};
|
|
817
|
+
/**
|
|
818
|
+
* @private
|
|
819
|
+
*/
|
|
820
|
+
HeadersFootersCatalog.prototype.textForRelationship = function (relationshipId) {
|
|
821
|
+
if (relationshipId === undefined) {
|
|
822
|
+
return undefined;
|
|
823
|
+
}
|
|
824
|
+
var entry = this.byRelationshipId.get(relationshipId);
|
|
825
|
+
if (entry === undefined) {
|
|
826
|
+
return undefined;
|
|
827
|
+
}
|
|
828
|
+
return firstParagraphText(entry.blocks);
|
|
829
|
+
};
|
|
830
|
+
/**
|
|
831
|
+
* True when two body items refer to the same payload
|
|
832
|
+
* (paragraph instance, feature value, or opaque XML node).
|
|
833
|
+
*/
|
|
834
|
+
HeadersFootersCatalog.prototype.publicBodyItemsEqual = function (a, b) {
|
|
835
|
+
return a === b;
|
|
836
|
+
};
|
|
837
|
+
HeadersFootersCatalog.prototype.storeBlocksEqual = function (a, b) {
|
|
838
|
+
if (a.type !== b.type) {
|
|
839
|
+
return false;
|
|
840
|
+
}
|
|
841
|
+
if (a.type === 'paragraph' && b.type === 'paragraph') {
|
|
842
|
+
return a.paragraph === b.paragraph;
|
|
843
|
+
}
|
|
844
|
+
if (a.type === 'feature' && b.type === 'feature') {
|
|
845
|
+
return a.featureId === b.featureId && a.value === b.value;
|
|
846
|
+
}
|
|
847
|
+
if (a.type === 'opaque' && b.type === 'opaque') {
|
|
848
|
+
return a.xml === b.xml;
|
|
849
|
+
}
|
|
850
|
+
return false;
|
|
851
|
+
};
|
|
852
|
+
return HeadersFootersCatalog;
|
|
853
|
+
}());
|
|
854
|
+
export { HeadersFootersCatalog };
|
|
855
|
+
/**
|
|
856
|
+
* Bound HeaderFooter instances by relationship id (document-scoped views).
|
|
857
|
+
* Catalog text helpers and Body mutations stay in sync through this map.
|
|
858
|
+
* @private
|
|
859
|
+
*/
|
|
860
|
+
var boundHeaderFooterByRelId = new Map();
|
|
861
|
+
/**
|
|
862
|
+
* @private
|
|
863
|
+
*/
|
|
864
|
+
function registerBoundHeaderFooter(relationshipId, hf) {
|
|
865
|
+
if (relationshipId === '') {
|
|
866
|
+
return;
|
|
867
|
+
}
|
|
868
|
+
boundHeaderFooterByRelId.set(relationshipId, hf);
|
|
869
|
+
}
|
|
870
|
+
/**
|
|
871
|
+
* Keep bound HeaderFooter Body store aligned after catalog-only mutations.
|
|
872
|
+
* @private
|
|
873
|
+
*/
|
|
874
|
+
function refreshBoundHeaderFooterFromEntry(relationshipId, entry) {
|
|
875
|
+
var e_12, _a;
|
|
876
|
+
var bound = boundHeaderFooterByRelId.get(relationshipId);
|
|
877
|
+
if (bound === undefined) {
|
|
878
|
+
return;
|
|
879
|
+
}
|
|
880
|
+
var document = bound.owningDocument();
|
|
881
|
+
try {
|
|
882
|
+
for (var _b = __values(entry.blocks), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
883
|
+
var block = _c.value;
|
|
884
|
+
if (block.type === 'paragraph') {
|
|
885
|
+
block.paragraph.attach(bound);
|
|
886
|
+
}
|
|
887
|
+
else if (block.type === 'feature') {
|
|
888
|
+
bindDocumentToFeatureBlock(block.value, document);
|
|
889
|
+
}
|
|
890
|
+
}
|
|
891
|
+
}
|
|
892
|
+
catch (e_12_1) { e_12 = { error: e_12_1 }; }
|
|
893
|
+
finally {
|
|
894
|
+
try {
|
|
895
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
896
|
+
}
|
|
897
|
+
finally { if (e_12) throw e_12.error; }
|
|
898
|
+
}
|
|
899
|
+
bound.replaceItemsSilent(entry.blocks.slice());
|
|
900
|
+
}
|
|
901
|
+
/**
|
|
902
|
+
* Attach catalog blocks to a HeaderFooter Body store without marking dirty.
|
|
903
|
+
* @private
|
|
904
|
+
*/
|
|
905
|
+
function loadCatalogBlocksIntoHeaderFooter(document, entry, hf) {
|
|
906
|
+
var e_13, _a;
|
|
907
|
+
try {
|
|
908
|
+
// Prefer Body as paragraph owner when bound; keeps assertAttached on Body.
|
|
909
|
+
for (var _b = __values(entry.blocks), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
910
|
+
var block = _c.value;
|
|
911
|
+
if (block.type === 'paragraph') {
|
|
912
|
+
block.paragraph.attach(hf);
|
|
913
|
+
}
|
|
914
|
+
else if (block.type === 'feature') {
|
|
915
|
+
bindDocumentToFeatureBlock(block.value, document);
|
|
916
|
+
}
|
|
917
|
+
}
|
|
918
|
+
}
|
|
919
|
+
catch (e_13_1) { e_13 = { error: e_13_1 }; }
|
|
920
|
+
finally {
|
|
921
|
+
try {
|
|
922
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
923
|
+
}
|
|
924
|
+
finally { if (e_13) throw e_13.error; }
|
|
925
|
+
}
|
|
926
|
+
hf.replaceItemsSilent(entry.blocks.slice());
|
|
927
|
+
}
|
|
928
|
+
/**
|
|
929
|
+
* Push HeaderFooter Body store into the catalog entry and mark dirty.
|
|
930
|
+
* @private
|
|
931
|
+
*/
|
|
932
|
+
function syncHeaderFooterToCatalog(document, relationshipId, hf) {
|
|
933
|
+
if (relationshipId === '') {
|
|
934
|
+
return;
|
|
935
|
+
}
|
|
936
|
+
var catalog = headersFootersFor(document);
|
|
937
|
+
var entry = catalog.entryForRelationship(relationshipId);
|
|
938
|
+
if (entry === undefined) {
|
|
939
|
+
return;
|
|
940
|
+
}
|
|
941
|
+
// Do not detach: paragraphs remain owned by the HeaderFooter Body.
|
|
942
|
+
entry.blocks = hf.rawBlocks().slice();
|
|
943
|
+
entry.dirty = true;
|
|
944
|
+
}
|
|
945
|
+
/**
|
|
946
|
+
* Live HeaderFooter for an already-materialized relationship id.
|
|
947
|
+
* @private
|
|
948
|
+
*/
|
|
949
|
+
function createHeaderFooterForRelationship(document, relationshipId, kind, refType, section) {
|
|
950
|
+
if (refType === void 0) { refType = 'default'; }
|
|
951
|
+
var existing = boundHeaderFooterByRelId.get(relationshipId);
|
|
952
|
+
if (existing !== undefined) {
|
|
953
|
+
return existing;
|
|
954
|
+
}
|
|
955
|
+
var catalog = headersFootersFor(document);
|
|
956
|
+
var entry = catalog.entryForRelationship(relationshipId);
|
|
957
|
+
var blocks = entry !== undefined ? entry.blocks.slice() : [];
|
|
958
|
+
var hf = new HeaderFooter(section, kind, refType, blocks, document, relationshipId);
|
|
959
|
+
if (entry !== undefined) {
|
|
960
|
+
loadCatalogBlocksIntoHeaderFooter(document, entry, hf);
|
|
961
|
+
}
|
|
962
|
+
hf.bindLifecycleHandlers(function () {
|
|
963
|
+
// Already materialized.
|
|
964
|
+
}, function () {
|
|
965
|
+
syncHeaderFooterToCatalog(document, hf.relationshipId, hf);
|
|
966
|
+
});
|
|
967
|
+
registerBoundHeaderFooter(relationshipId, hf);
|
|
968
|
+
return hf;
|
|
969
|
+
}
|
|
970
|
+
/**
|
|
971
|
+
* Lazy always-present header/footer slot bound to a DocSection + ref type.
|
|
972
|
+
* Package part + sectPr reference are created on first content mutation.
|
|
973
|
+
* @private
|
|
974
|
+
*/
|
|
975
|
+
function createSectionHeaderFooterSlot(section, kind, refType) {
|
|
976
|
+
var document = section.owningDocument();
|
|
977
|
+
var hf = new HeaderFooter(section, kind, refType, [], document, '');
|
|
978
|
+
var tryBindExisting = function () {
|
|
979
|
+
if (hf.relationshipId !== '') {
|
|
980
|
+
return;
|
|
981
|
+
}
|
|
982
|
+
var props = section.pageSetup;
|
|
983
|
+
if (!(props instanceof PageSetup)) {
|
|
984
|
+
return;
|
|
985
|
+
}
|
|
986
|
+
var relId = props.headerFooterReferenceId(kind, refType);
|
|
987
|
+
if (relId === undefined) {
|
|
988
|
+
return;
|
|
989
|
+
}
|
|
990
|
+
var catalog = headersFootersFor(document);
|
|
991
|
+
if (!catalog.hasRelationship(relId)) {
|
|
992
|
+
return;
|
|
993
|
+
}
|
|
994
|
+
hf.bindRelationshipId(relId);
|
|
995
|
+
registerBoundHeaderFooter(relId, hf);
|
|
996
|
+
var entry = catalog.entryForRelationship(relId);
|
|
997
|
+
if (entry !== undefined) {
|
|
998
|
+
loadCatalogBlocksIntoHeaderFooter(document, entry, hf);
|
|
999
|
+
}
|
|
1000
|
+
};
|
|
1001
|
+
var ensureBound = function () {
|
|
1002
|
+
tryBindExisting();
|
|
1003
|
+
if (hf.relationshipId !== '') {
|
|
1004
|
+
return;
|
|
1005
|
+
}
|
|
1006
|
+
var props = ensurePageSetupForSlot(section);
|
|
1007
|
+
var catalog = headersFootersFor(document);
|
|
1008
|
+
var ensured = catalog.ensurePart(kind, props, refType, usedRelationshipIds(document), usedPartNameKeys(document));
|
|
1009
|
+
props.setHeaderFooterReference(kind, refType, ensured.relationshipId);
|
|
1010
|
+
hf.bindRelationshipId(ensured.relationshipId);
|
|
1011
|
+
registerBoundHeaderFooter(ensured.relationshipId, hf);
|
|
1012
|
+
loadCatalogBlocksIntoHeaderFooter(document, ensured.entry, hf);
|
|
1013
|
+
};
|
|
1014
|
+
hf.bindLifecycleHandlers(function () {
|
|
1015
|
+
ensureBound();
|
|
1016
|
+
}, function () {
|
|
1017
|
+
if (hf.relationshipId === '') {
|
|
1018
|
+
return;
|
|
1019
|
+
}
|
|
1020
|
+
syncHeaderFooterToCatalog(document, hf.relationshipId, hf);
|
|
1021
|
+
});
|
|
1022
|
+
tryBindExisting();
|
|
1023
|
+
return hf;
|
|
1024
|
+
}
|
|
1025
|
+
/**
|
|
1026
|
+
* Resolve live {@link PageSetup} on a section for header/footer writes.
|
|
1027
|
+
* Final section uses dual-hold ensure; non-final sections seed pageSetup when missing.
|
|
1028
|
+
*
|
|
1029
|
+
* @private
|
|
1030
|
+
*/
|
|
1031
|
+
function ensurePageSetupForSlot(section) {
|
|
1032
|
+
var document = section.owningDocument();
|
|
1033
|
+
var sections = document.sections;
|
|
1034
|
+
var index = sections.indexOf(section);
|
|
1035
|
+
var isFinal = index >= 0 && index === sections.count - 1;
|
|
1036
|
+
if (isFinal) {
|
|
1037
|
+
var props = ensureFinalSectionProperties(document);
|
|
1038
|
+
section.setPageSetup(props);
|
|
1039
|
+
return props;
|
|
1040
|
+
}
|
|
1041
|
+
var existing = section.pageSetup;
|
|
1042
|
+
if (existing instanceof PageSetup) {
|
|
1043
|
+
associatePageSetupDocument(existing, document);
|
|
1044
|
+
return existing;
|
|
1045
|
+
}
|
|
1046
|
+
var seeded = defaultLetterPageSetup();
|
|
1047
|
+
associatePageSetupDocument(seeded, document);
|
|
1048
|
+
section.setPageSetup(seeded);
|
|
1049
|
+
// Dual-hold non-final closer when the body already has a last paragraph.
|
|
1050
|
+
var blocks = section.body.listBlocks();
|
|
1051
|
+
for (var i = blocks.length - 1; i >= 0; i -= 1) {
|
|
1052
|
+
var block = blocks[i];
|
|
1053
|
+
if (block !== undefined && block.type === 'paragraph') {
|
|
1054
|
+
setParagraphSectionBreak(block.paragraph, seeded);
|
|
1055
|
+
break;
|
|
1056
|
+
}
|
|
1057
|
+
}
|
|
1058
|
+
return seeded;
|
|
1059
|
+
}
|
|
1060
|
+
/**
|
|
1061
|
+
* True when `part` is a headers/footers catalog from this module graph or a
|
|
1062
|
+
* duplicate published chunk of the same implementation.
|
|
1063
|
+
* @private
|
|
1064
|
+
*/
|
|
1065
|
+
function isHeadersFootersCatalog(part) {
|
|
1066
|
+
if (part instanceof HeadersFootersCatalog) {
|
|
1067
|
+
return true;
|
|
1068
|
+
}
|
|
1069
|
+
if (part === null || typeof part !== 'object') {
|
|
1070
|
+
return false;
|
|
1071
|
+
}
|
|
1072
|
+
var candidate = part;
|
|
1073
|
+
if (candidate[HEADERS_FOOTERS_CATALOG_BRAND] === true) {
|
|
1074
|
+
return true;
|
|
1075
|
+
}
|
|
1076
|
+
// Duck-type fallback for catalogs built before the brand existed.
|
|
1077
|
+
return typeof candidate.bindDocument === 'function'
|
|
1078
|
+
&& typeof candidate.ensurePart === 'function'
|
|
1079
|
+
&& typeof candidate.setSimpleText === 'function'
|
|
1080
|
+
&& typeof candidate.textForRelationship === 'function'
|
|
1081
|
+
&& typeof candidate.applyToPackage === 'function';
|
|
1082
|
+
}
|
|
1083
|
+
/**
|
|
1084
|
+
* Headers and footers catalog for a document.
|
|
1085
|
+
*
|
|
1086
|
+
* On a loaded package this is the catalog built from header/footer parts.
|
|
1087
|
+
* On a newly authored document there may be no header/footer parts yet, so this
|
|
1088
|
+
* function attaches an empty catalog on first use when the feature is registered.
|
|
1089
|
+
*
|
|
1090
|
+
* Accepts catalogs from either the main entry graph or `@syncfusion/ej2-docx/headers-footers`
|
|
1091
|
+
* (duplicate class identity across published chunks).
|
|
1092
|
+
*
|
|
1093
|
+
* @throws DocxError `feature/not-registered` when the module was not registered.
|
|
1094
|
+
* @private
|
|
1095
|
+
*/
|
|
1096
|
+
export function headersFootersFor(document) {
|
|
1097
|
+
var part = document.featurePart(HEADERS_FOOTERS);
|
|
1098
|
+
if (isHeadersFootersCatalog(part)) {
|
|
1099
|
+
part.bindDocument(document);
|
|
1100
|
+
return part;
|
|
1101
|
+
}
|
|
1102
|
+
if (part !== undefined) {
|
|
1103
|
+
throw new DocxError('feature/not-registered', 'Headers/footers feature state was replaced with an unexpected part type');
|
|
1104
|
+
}
|
|
1105
|
+
if (!isFeatureRegistered(HEADERS_FOOTERS)) {
|
|
1106
|
+
throw new DocxError('feature/not-registered', 'Headers/footers feature is not registered; call registerHeadersFootersFeature() before use');
|
|
1107
|
+
}
|
|
1108
|
+
var created = new HeadersFootersCatalog(new Map());
|
|
1109
|
+
created.bindDocument(document);
|
|
1110
|
+
document.setFeaturePart(HEADERS_FOOTERS, created);
|
|
1111
|
+
return created;
|
|
1112
|
+
}
|
|
1113
|
+
/**
|
|
1114
|
+
* Live {@link HeaderFooter} views for every loaded header part, in catalog order.
|
|
1115
|
+
* @private
|
|
1116
|
+
*/
|
|
1117
|
+
export function headersInDocument(document) {
|
|
1118
|
+
return headersFootersFor(document)
|
|
1119
|
+
.relationshipIds('header')
|
|
1120
|
+
.map(function (relationshipId) { return createHeaderFooterForRelationship(document, relationshipId, 'header'); });
|
|
1121
|
+
}
|
|
1122
|
+
/**
|
|
1123
|
+
* Live {@link HeaderFooter} views for every loaded footer part, in catalog order.
|
|
1124
|
+
* @private
|
|
1125
|
+
*/
|
|
1126
|
+
export function footersInDocument(document) {
|
|
1127
|
+
return headersFootersFor(document)
|
|
1128
|
+
.relationshipIds('footer')
|
|
1129
|
+
.map(function (relationshipId) { return createHeaderFooterForRelationship(document, relationshipId, 'footer'); });
|
|
1130
|
+
}
|
|
1131
|
+
/**
|
|
1132
|
+
* Live header linked from a section's `w:headerReference`, when present and loaded.
|
|
1133
|
+
* @private
|
|
1134
|
+
*/
|
|
1135
|
+
export function headerForSection(document, section, refType) {
|
|
1136
|
+
if (refType === void 0) { refType = 'default'; }
|
|
1137
|
+
var relationshipId = section.headerFooterReferenceId('header', refType);
|
|
1138
|
+
if (relationshipId === undefined) {
|
|
1139
|
+
return undefined;
|
|
1140
|
+
}
|
|
1141
|
+
var catalog = headersFootersFor(document);
|
|
1142
|
+
if (!catalog.hasRelationship(relationshipId)) {
|
|
1143
|
+
return undefined;
|
|
1144
|
+
}
|
|
1145
|
+
return createHeaderFooterForRelationship(document, relationshipId, 'header', refType);
|
|
1146
|
+
}
|
|
1147
|
+
/**
|
|
1148
|
+
* Live footer linked from a section's `w:footerReference`, when present and loaded.
|
|
1149
|
+
* @private
|
|
1150
|
+
*/
|
|
1151
|
+
export function footerForSection(document, section, refType) {
|
|
1152
|
+
if (refType === void 0) { refType = 'default'; }
|
|
1153
|
+
var relationshipId = section.headerFooterReferenceId('footer', refType);
|
|
1154
|
+
if (relationshipId === undefined) {
|
|
1155
|
+
return undefined;
|
|
1156
|
+
}
|
|
1157
|
+
var catalog = headersFootersFor(document);
|
|
1158
|
+
if (!catalog.hasRelationship(relationshipId)) {
|
|
1159
|
+
return undefined;
|
|
1160
|
+
}
|
|
1161
|
+
return createHeaderFooterForRelationship(document, relationshipId, 'footer', refType);
|
|
1162
|
+
}
|
|
1163
|
+
/**
|
|
1164
|
+
* Default header for the body-final section, when linked and loaded.
|
|
1165
|
+
* @private
|
|
1166
|
+
*/
|
|
1167
|
+
export function defaultHeader(document) {
|
|
1168
|
+
var section = finalSection(document);
|
|
1169
|
+
if (section === undefined) {
|
|
1170
|
+
return undefined;
|
|
1171
|
+
}
|
|
1172
|
+
return headerForSection(document, section, 'default');
|
|
1173
|
+
}
|
|
1174
|
+
/**
|
|
1175
|
+
* Default footer for the body-final section, when linked and loaded.
|
|
1176
|
+
* @private
|
|
1177
|
+
*/
|
|
1178
|
+
export function defaultFooter(document) {
|
|
1179
|
+
var section = finalSection(document);
|
|
1180
|
+
if (section === undefined) {
|
|
1181
|
+
return undefined;
|
|
1182
|
+
}
|
|
1183
|
+
return footerForSection(document, section, 'default');
|
|
1184
|
+
}
|
|
1185
|
+
/**
|
|
1186
|
+
* First-page header for the body-final section, when linked and loaded.
|
|
1187
|
+
* @private
|
|
1188
|
+
*/
|
|
1189
|
+
export function firstHeader(document) {
|
|
1190
|
+
var section = finalSection(document);
|
|
1191
|
+
if (section === undefined) {
|
|
1192
|
+
return undefined;
|
|
1193
|
+
}
|
|
1194
|
+
return headerForSection(document, section, 'first');
|
|
1195
|
+
}
|
|
1196
|
+
/**
|
|
1197
|
+
* Even-page header for the body-final section, when linked and loaded.
|
|
1198
|
+
* @private
|
|
1199
|
+
*/
|
|
1200
|
+
export function evenHeader(document) {
|
|
1201
|
+
var section = finalSection(document);
|
|
1202
|
+
if (section === undefined) {
|
|
1203
|
+
return undefined;
|
|
1204
|
+
}
|
|
1205
|
+
return headerForSection(document, section, 'even');
|
|
1206
|
+
}
|
|
1207
|
+
/**
|
|
1208
|
+
* First-page footer for the body-final section, when linked and loaded.
|
|
1209
|
+
* @private
|
|
1210
|
+
*/
|
|
1211
|
+
export function firstFooter(document) {
|
|
1212
|
+
var section = finalSection(document);
|
|
1213
|
+
if (section === undefined) {
|
|
1214
|
+
return undefined;
|
|
1215
|
+
}
|
|
1216
|
+
return footerForSection(document, section, 'first');
|
|
1217
|
+
}
|
|
1218
|
+
/**
|
|
1219
|
+
* Even-page footer for the body-final section, when linked and loaded.
|
|
1220
|
+
* @private
|
|
1221
|
+
*/
|
|
1222
|
+
export function evenFooter(document) {
|
|
1223
|
+
var section = finalSection(document);
|
|
1224
|
+
if (section === undefined) {
|
|
1225
|
+
return undefined;
|
|
1226
|
+
}
|
|
1227
|
+
return footerForSection(document, section, 'even');
|
|
1228
|
+
}
|
|
1229
|
+
function serializeHeaderFooterPart(entry) {
|
|
1230
|
+
var root = wmlElement(rootLocalName(entry.kind), {
|
|
1231
|
+
attributes: entry.rootExtra.attributes,
|
|
1232
|
+
namespaceDeclarations: entry.rootExtra.namespaceDeclarations,
|
|
1233
|
+
children: serializeBodyBlocks(entry.blocks),
|
|
1234
|
+
});
|
|
1235
|
+
return utf8.encode(serializeXml(root));
|
|
1236
|
+
}
|
|
1237
|
+
function allocatePartName(kind, used) {
|
|
1238
|
+
var stem = kind === 'header' ? 'header' : 'footer';
|
|
1239
|
+
var index = 1;
|
|
1240
|
+
while (used.has(partNameKey(partName("/word/" + stem + String(index) + ".xml")))) {
|
|
1241
|
+
index += 1;
|
|
1242
|
+
}
|
|
1243
|
+
return partName("/word/" + stem + String(index) + ".xml");
|
|
1244
|
+
}
|
|
1245
|
+
function loadCatalog(pkg, mainPartName) {
|
|
1246
|
+
var e_14, _a;
|
|
1247
|
+
var rels = relationshipsForPart(pkg, mainPartName);
|
|
1248
|
+
var entries = new Map();
|
|
1249
|
+
try {
|
|
1250
|
+
for (var _b = __values(rels.items), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
1251
|
+
var rel = _c.value;
|
|
1252
|
+
var kind = kindForRelationshipType(rel.type);
|
|
1253
|
+
if (kind === undefined) {
|
|
1254
|
+
continue;
|
|
1255
|
+
}
|
|
1256
|
+
var target = resolveInternalTarget(rel.target, mainPartName);
|
|
1257
|
+
var part = partByName(pkg, target);
|
|
1258
|
+
if (part === undefined) {
|
|
1259
|
+
continue;
|
|
1260
|
+
}
|
|
1261
|
+
var loaded = parseHeaderFooterPart(part, rel, kind);
|
|
1262
|
+
if (loaded !== undefined) {
|
|
1263
|
+
entries.set(loaded.partName, loaded);
|
|
1264
|
+
}
|
|
1265
|
+
}
|
|
1266
|
+
}
|
|
1267
|
+
catch (e_14_1) { e_14 = { error: e_14_1 }; }
|
|
1268
|
+
finally {
|
|
1269
|
+
try {
|
|
1270
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
1271
|
+
}
|
|
1272
|
+
finally { if (e_14) throw e_14.error; }
|
|
1273
|
+
}
|
|
1274
|
+
return new HeadersFootersCatalog(entries);
|
|
1275
|
+
}
|
|
1276
|
+
function usedRelationshipIds(document) {
|
|
1277
|
+
var e_15, _a;
|
|
1278
|
+
var main = partName('/word/document.xml');
|
|
1279
|
+
var used = new Set();
|
|
1280
|
+
try {
|
|
1281
|
+
for (var _b = __values(relationshipsForPart(document.opcPackage(), main).items), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
1282
|
+
var rel = _c.value;
|
|
1283
|
+
used.add(rel.id);
|
|
1284
|
+
}
|
|
1285
|
+
}
|
|
1286
|
+
catch (e_15_1) { e_15 = { error: e_15_1 }; }
|
|
1287
|
+
finally {
|
|
1288
|
+
try {
|
|
1289
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
1290
|
+
}
|
|
1291
|
+
finally { if (e_15) throw e_15.error; }
|
|
1292
|
+
}
|
|
1293
|
+
return used;
|
|
1294
|
+
}
|
|
1295
|
+
function usedPartNameKeys(document) {
|
|
1296
|
+
var e_16, _a;
|
|
1297
|
+
var used = new Set();
|
|
1298
|
+
try {
|
|
1299
|
+
for (var _b = __values(document.opcPackage().parts), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
1300
|
+
var part = _c.value;
|
|
1301
|
+
used.add(partNameKey(part.name));
|
|
1302
|
+
}
|
|
1303
|
+
}
|
|
1304
|
+
catch (e_16_1) { e_16 = { error: e_16_1 }; }
|
|
1305
|
+
finally {
|
|
1306
|
+
try {
|
|
1307
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
1308
|
+
}
|
|
1309
|
+
finally { if (e_16) throw e_16.error; }
|
|
1310
|
+
}
|
|
1311
|
+
return used;
|
|
1312
|
+
}
|
|
1313
|
+
function sectionForWrite(document) {
|
|
1314
|
+
var existing = finalSection(document);
|
|
1315
|
+
if (existing !== undefined) {
|
|
1316
|
+
return existing;
|
|
1317
|
+
}
|
|
1318
|
+
var seeded = defaultLetterPageSetup();
|
|
1319
|
+
// Pin the live model so subsequent header/footer writes keep object identity.
|
|
1320
|
+
// Prefer setFinalSection over document.lastSection so feature checks do not
|
|
1321
|
+
// depend on module-augmentation merge for the relative WordDocument import.
|
|
1322
|
+
setFinalSection(document, seeded);
|
|
1323
|
+
return seeded;
|
|
1324
|
+
}
|
|
1325
|
+
var registered = false;
|
|
1326
|
+
/**
|
|
1327
|
+
* @private
|
|
1328
|
+
* Test hook */
|
|
1329
|
+
export function resetHeadersFootersFeatureForTests() {
|
|
1330
|
+
registered = false;
|
|
1331
|
+
boundHeaderFooterByRelId.clear();
|
|
1332
|
+
resetHeadersFootersSlotFactoryForTests();
|
|
1333
|
+
resetHeadersFootersLinkToPreviousHandlersForTests();
|
|
1334
|
+
}
|
|
1335
|
+
/**
|
|
1336
|
+
* @private
|
|
1337
|
+
* Register the headers/footers multi-part handler. Idempotent. */
|
|
1338
|
+
export function registerHeadersFootersFeature() {
|
|
1339
|
+
if (registered) {
|
|
1340
|
+
return;
|
|
1341
|
+
}
|
|
1342
|
+
registered = true;
|
|
1343
|
+
registerFeature({ id: HEADERS_FOOTERS });
|
|
1344
|
+
registerFeatureMultiPartHandler({
|
|
1345
|
+
featureId: HEADERS_FOOTERS,
|
|
1346
|
+
relationshipTypes: ALL_RELATIONSHIP_TYPES,
|
|
1347
|
+
loadParts: function (pkg, ctx) {
|
|
1348
|
+
return loadCatalog(pkg, ctx.mainPartName);
|
|
1349
|
+
},
|
|
1350
|
+
});
|
|
1351
|
+
registerHeadersFootersSlotFactory({
|
|
1352
|
+
createHeader: function (section, refType) {
|
|
1353
|
+
return createSectionHeaderFooterSlot(section, 'header', refType);
|
|
1354
|
+
},
|
|
1355
|
+
createFooter: function (section, refType) {
|
|
1356
|
+
return createSectionHeaderFooterSlot(section, 'footer', refType);
|
|
1357
|
+
},
|
|
1358
|
+
});
|
|
1359
|
+
registerHeadersFootersLinkToPreviousHandlers(function (section, link) {
|
|
1360
|
+
var props = section.pageSetup;
|
|
1361
|
+
if (!(props instanceof PageSetup)) {
|
|
1362
|
+
return;
|
|
1363
|
+
}
|
|
1364
|
+
var document = section.owningDocument();
|
|
1365
|
+
if (link) {
|
|
1366
|
+
props.setHeaderFooterReference('header', 'default', undefined);
|
|
1367
|
+
props.setHeaderFooterReference('header', 'first', undefined);
|
|
1368
|
+
props.setHeaderFooterReference('header', 'even', undefined);
|
|
1369
|
+
props.setHeaderFooterReference('footer', 'default', undefined);
|
|
1370
|
+
props.setHeaderFooterReference('footer', 'first', undefined);
|
|
1371
|
+
props.setHeaderFooterReference('footer', 'even', undefined);
|
|
1372
|
+
return;
|
|
1373
|
+
}
|
|
1374
|
+
// Materialize empty local parts so the section no longer inherits.
|
|
1375
|
+
getOrCreateSectionHeader(document, props, 'default');
|
|
1376
|
+
getOrCreateSectionHeader(document, props, 'first');
|
|
1377
|
+
getOrCreateSectionHeader(document, props, 'even');
|
|
1378
|
+
getOrCreateSectionFooter(document, props, 'default');
|
|
1379
|
+
getOrCreateSectionFooter(document, props, 'first');
|
|
1380
|
+
getOrCreateSectionFooter(document, props, 'even');
|
|
1381
|
+
}, function (section) {
|
|
1382
|
+
var props = section.pageSetup;
|
|
1383
|
+
if (!(props instanceof PageSetup)) {
|
|
1384
|
+
return true;
|
|
1385
|
+
}
|
|
1386
|
+
var hasLocal = props.headerFooterReferenceId('header', 'default') !== undefined
|
|
1387
|
+
|| props.headerFooterReferenceId('header', 'first') !== undefined
|
|
1388
|
+
|| props.headerFooterReferenceId('header', 'even') !== undefined
|
|
1389
|
+
|| props.headerFooterReferenceId('footer', 'default') !== undefined
|
|
1390
|
+
|| props.headerFooterReferenceId('footer', 'first') !== undefined
|
|
1391
|
+
|| props.headerFooterReferenceId('footer', 'even') !== undefined;
|
|
1392
|
+
return !hasLocal;
|
|
1393
|
+
});
|
|
1394
|
+
}
|
|
1395
|
+
/**
|
|
1396
|
+
* Text from the default header part, when linked from body-final `sectPr`.
|
|
1397
|
+
* @private
|
|
1398
|
+
*/
|
|
1399
|
+
export function defaultHeaderText(document) {
|
|
1400
|
+
var catalog = headersFootersFor(document);
|
|
1401
|
+
var section = finalSection(document);
|
|
1402
|
+
var relId = section == null ? undefined : section.headerFooterReferenceId('header', 'default');
|
|
1403
|
+
return catalog.textForRelationship(relId);
|
|
1404
|
+
}
|
|
1405
|
+
/**
|
|
1406
|
+
* Text from the default footer part, when linked from body-final `sectPr`.
|
|
1407
|
+
* @private
|
|
1408
|
+
*/
|
|
1409
|
+
export function defaultFooterText(document) {
|
|
1410
|
+
var catalog = headersFootersFor(document);
|
|
1411
|
+
var section = finalSection(document);
|
|
1412
|
+
var relId = section == null ? undefined : section.headerFooterReferenceId('footer', 'default');
|
|
1413
|
+
return catalog.textForRelationship(relId);
|
|
1414
|
+
}
|
|
1415
|
+
/**
|
|
1416
|
+
* Set default header text, creating the part and `sectPr` reference when needed.
|
|
1417
|
+
* @private
|
|
1418
|
+
*/
|
|
1419
|
+
export function setDefaultHeader(document, text) {
|
|
1420
|
+
var section = sectionForWrite(document);
|
|
1421
|
+
setSectionHeader(document, section, text, 'default');
|
|
1422
|
+
setFinalSection(document, section);
|
|
1423
|
+
}
|
|
1424
|
+
/**
|
|
1425
|
+
* Set default footer text, creating the part and `sectPr` reference when needed.
|
|
1426
|
+
* @private
|
|
1427
|
+
*/
|
|
1428
|
+
export function setDefaultFooter(document, text) {
|
|
1429
|
+
var section = sectionForWrite(document);
|
|
1430
|
+
setSectionFooter(document, section, text, 'default');
|
|
1431
|
+
setFinalSection(document, section);
|
|
1432
|
+
}
|
|
1433
|
+
/**
|
|
1434
|
+
* Header text linked from a section's `sectPr`.
|
|
1435
|
+
* @private
|
|
1436
|
+
*/
|
|
1437
|
+
export function headerTextForSection(document, section, refType) {
|
|
1438
|
+
if (refType === void 0) { refType = 'default'; }
|
|
1439
|
+
var catalog = headersFootersFor(document);
|
|
1440
|
+
var relId = section.headerFooterReferenceId('header', refType);
|
|
1441
|
+
return catalog.textForRelationship(relId);
|
|
1442
|
+
}
|
|
1443
|
+
/**
|
|
1444
|
+
* Footer text linked from a section's `sectPr`.
|
|
1445
|
+
* @private
|
|
1446
|
+
*/
|
|
1447
|
+
export function footerTextForSection(document, section, refType) {
|
|
1448
|
+
if (refType === void 0) { refType = 'default'; }
|
|
1449
|
+
var catalog = headersFootersFor(document);
|
|
1450
|
+
var relId = section.headerFooterReferenceId('footer', refType);
|
|
1451
|
+
return catalog.textForRelationship(relId);
|
|
1452
|
+
}
|
|
1453
|
+
/**
|
|
1454
|
+
* Set header text on a section, reusing an existing linked part when present.
|
|
1455
|
+
* @private
|
|
1456
|
+
*/
|
|
1457
|
+
export function setSectionHeader(document, section, text, refType) {
|
|
1458
|
+
if (refType === void 0) { refType = 'default'; }
|
|
1459
|
+
var catalog = headersFootersFor(document);
|
|
1460
|
+
var _a = catalog.ensurePart('header', section, refType, usedRelationshipIds(document), usedPartNameKeys(document)), entry = _a.entry, relationshipId = _a.relationshipId;
|
|
1461
|
+
catalog.setSimpleText(entry, text);
|
|
1462
|
+
section.setHeaderFooterReference('header', refType, relationshipId);
|
|
1463
|
+
}
|
|
1464
|
+
/**
|
|
1465
|
+
* Set footer text on a section, reusing an existing linked part when present.
|
|
1466
|
+
* @private
|
|
1467
|
+
*/
|
|
1468
|
+
export function setSectionFooter(document, section, text, refType) {
|
|
1469
|
+
if (refType === void 0) { refType = 'default'; }
|
|
1470
|
+
var catalog = headersFootersFor(document);
|
|
1471
|
+
var _a = catalog.ensurePart('footer', section, refType, usedRelationshipIds(document), usedPartNameKeys(document)), entry = _a.entry, relationshipId = _a.relationshipId;
|
|
1472
|
+
catalog.setSimpleText(entry, text);
|
|
1473
|
+
section.setHeaderFooterReference('footer', refType, relationshipId);
|
|
1474
|
+
}
|
|
1475
|
+
/**
|
|
1476
|
+
* Link an existing header part to a section without creating a duplicate part.
|
|
1477
|
+
* @private
|
|
1478
|
+
*/
|
|
1479
|
+
export function linkSectionHeader(document, section, relationshipId, refType) {
|
|
1480
|
+
if (refType === void 0) { refType = 'default'; }
|
|
1481
|
+
var catalog = headersFootersFor(document);
|
|
1482
|
+
if (!catalog.hasRelationship(relationshipId)) {
|
|
1483
|
+
throw new DocxError('content/invalid-header-footer-reference', "Header/footer relationship " + relationshipId + " is not loaded in this document");
|
|
1484
|
+
}
|
|
1485
|
+
section.setHeaderFooterReference('header', refType, relationshipId);
|
|
1486
|
+
}
|
|
1487
|
+
/**
|
|
1488
|
+
* Link an existing footer part to a section without creating a duplicate part.
|
|
1489
|
+
* @private
|
|
1490
|
+
*/
|
|
1491
|
+
export function linkSectionFooter(document, section, relationshipId, refType) {
|
|
1492
|
+
if (refType === void 0) { refType = 'default'; }
|
|
1493
|
+
var catalog = headersFootersFor(document);
|
|
1494
|
+
if (!catalog.hasRelationship(relationshipId)) {
|
|
1495
|
+
throw new DocxError('content/invalid-header-footer-reference', "Header/footer relationship " + relationshipId + " is not loaded in this document");
|
|
1496
|
+
}
|
|
1497
|
+
section.setHeaderFooterReference('footer', refType, relationshipId);
|
|
1498
|
+
}
|
|
1499
|
+
/**
|
|
1500
|
+
* @private
|
|
1501
|
+
* Require section properties associated with a document (section.pageSetup / document.sections).
|
|
1502
|
+
*/
|
|
1503
|
+
function requireAssociatedSectionDocument(section) {
|
|
1504
|
+
var document = ownerDocumentOf(section);
|
|
1505
|
+
if (document === undefined) {
|
|
1506
|
+
throw new Error('sections: header/footer association requires section properties associated with a document (use section.pageSetup on a document section)');
|
|
1507
|
+
}
|
|
1508
|
+
return document;
|
|
1509
|
+
}
|
|
1510
|
+
/**
|
|
1511
|
+
* @private
|
|
1512
|
+
* Resolve ref type; default slot when omitted.
|
|
1513
|
+
*/
|
|
1514
|
+
function resolveRefType(refType) {
|
|
1515
|
+
return refType === undefined ? 'default' : refType;
|
|
1516
|
+
}
|
|
1517
|
+
/**
|
|
1518
|
+
* @private
|
|
1519
|
+
* Ensure a header part + sectPr reference without wiping body text.
|
|
1520
|
+
* Unlike {@link setSectionHeader}, does not call setSimpleText.
|
|
1521
|
+
*/
|
|
1522
|
+
function getOrCreateSectionHeader(document, section, refType) {
|
|
1523
|
+
var catalog = headersFootersFor(document);
|
|
1524
|
+
var ensured = catalog.ensurePart('header', section, refType, usedRelationshipIds(document), usedPartNameKeys(document));
|
|
1525
|
+
section.setHeaderFooterReference('header', refType, ensured.relationshipId);
|
|
1526
|
+
return createHeaderFooterForRelationship(document, ensured.relationshipId, 'header', refType);
|
|
1527
|
+
}
|
|
1528
|
+
/**
|
|
1529
|
+
* @private
|
|
1530
|
+
* Ensure a footer part + sectPr reference without wiping body text.
|
|
1531
|
+
* Unlike {@link setSectionFooter}, does not call setSimpleText.
|
|
1532
|
+
*/
|
|
1533
|
+
function getOrCreateSectionFooter(document, section, refType) {
|
|
1534
|
+
var catalog = headersFootersFor(document);
|
|
1535
|
+
var ensured = catalog.ensurePart('footer', section, refType, usedRelationshipIds(document), usedPartNameKeys(document));
|
|
1536
|
+
section.setHeaderFooterReference('footer', refType, ensured.relationshipId);
|
|
1537
|
+
return createHeaderFooterForRelationship(document, ensured.relationshipId, 'footer', refType);
|
|
1538
|
+
}
|
|
1539
|
+
function defineSectionHeaderFooterProperty(name, refType) {
|
|
1540
|
+
var isHeader = name.endsWith('Header');
|
|
1541
|
+
Object.defineProperty(PageSetup.prototype, name, {
|
|
1542
|
+
configurable: true,
|
|
1543
|
+
enumerable: false,
|
|
1544
|
+
get: function () {
|
|
1545
|
+
var document = requireAssociatedSectionDocument(this);
|
|
1546
|
+
return isHeader
|
|
1547
|
+
? getOrCreateSectionHeader(document, this, refType)
|
|
1548
|
+
: getOrCreateSectionFooter(document, this, refType);
|
|
1549
|
+
},
|
|
1550
|
+
set: function (value) {
|
|
1551
|
+
var document = requireAssociatedSectionDocument(this);
|
|
1552
|
+
if (value === undefined) {
|
|
1553
|
+
this.setHeaderFooterReference(isHeader ? 'header' : 'footer', refType, undefined);
|
|
1554
|
+
return;
|
|
1555
|
+
}
|
|
1556
|
+
if (!(value instanceof HeaderFooter)) {
|
|
1557
|
+
throw new DocxError('argument/invalid', name + " setter expects HeaderFooter | undefined");
|
|
1558
|
+
}
|
|
1559
|
+
if (isHeader) {
|
|
1560
|
+
if (value.kind !== 'header') {
|
|
1561
|
+
throw new DocxError('argument/invalid', name + " setter expects a header HeaderFooter");
|
|
1562
|
+
}
|
|
1563
|
+
linkSectionHeader(document, this, value.relationshipId, refType);
|
|
1564
|
+
return;
|
|
1565
|
+
}
|
|
1566
|
+
if (value.kind !== 'footer') {
|
|
1567
|
+
throw new DocxError('argument/invalid', name + " setter expects a footer HeaderFooter");
|
|
1568
|
+
}
|
|
1569
|
+
linkSectionFooter(document, this, value.relationshipId, refType);
|
|
1570
|
+
},
|
|
1571
|
+
});
|
|
1572
|
+
}
|
|
1573
|
+
defineSectionHeaderFooterProperty('oddHeader', 'default');
|
|
1574
|
+
defineSectionHeaderFooterProperty('oddFooter', 'default');
|
|
1575
|
+
defineSectionHeaderFooterProperty('firstPageHeader', 'first');
|
|
1576
|
+
defineSectionHeaderFooterProperty('firstPageFooter', 'first');
|
|
1577
|
+
defineSectionHeaderFooterProperty('evenHeader', 'even');
|
|
1578
|
+
defineSectionHeaderFooterProperty('evenFooter', 'even');
|
|
1579
|
+
/**
|
|
1580
|
+
|
|
1581
|
+
* or {@link PageSetup.evenHeader}. Returns the live header when already linked; does not create.
|
|
1582
|
+
*/
|
|
1583
|
+
PageSetup.prototype.header = function (refType) {
|
|
1584
|
+
var document = requireAssociatedSectionDocument(this);
|
|
1585
|
+
return headerForSection(document, this, resolveRefType(refType));
|
|
1586
|
+
};
|
|
1587
|
+
/**
|
|
1588
|
+
|
|
1589
|
+
* or {@link PageSetup.evenFooter}. Returns the live footer when already linked; does not create.
|
|
1590
|
+
*/
|
|
1591
|
+
PageSetup.prototype.footer = function (refType) {
|
|
1592
|
+
var document = requireAssociatedSectionDocument(this);
|
|
1593
|
+
return footerForSection(document, this, resolveRefType(refType));
|
|
1594
|
+
};
|
|
1595
|
+
/**
|
|
1596
|
+
/ `firstPageHeader` / `evenHeader`).
|
|
1597
|
+
*/
|
|
1598
|
+
PageSetup.prototype.getOrCreateHeader = function (refType) {
|
|
1599
|
+
var document = requireAssociatedSectionDocument(this);
|
|
1600
|
+
return getOrCreateSectionHeader(document, this, resolveRefType(refType));
|
|
1601
|
+
};
|
|
1602
|
+
/**
|
|
1603
|
+
/ `firstPageFooter` / `evenFooter`).
|
|
1604
|
+
*/
|
|
1605
|
+
PageSetup.prototype.getOrCreateFooter = function (refType) {
|
|
1606
|
+
var document = requireAssociatedSectionDocument(this);
|
|
1607
|
+
return getOrCreateSectionFooter(document, this, resolveRefType(refType));
|
|
1608
|
+
};
|
|
1609
|
+
/**
|
|
1610
|
+
/even).
|
|
1611
|
+
*/
|
|
1612
|
+
PageSetup.prototype.linkHeader = function (header, refType) {
|
|
1613
|
+
var document = requireAssociatedSectionDocument(this);
|
|
1614
|
+
linkSectionHeader(document, this, header.relationshipId, resolveRefType(refType));
|
|
1615
|
+
};
|
|
1616
|
+
/**
|
|
1617
|
+
/even).
|
|
1618
|
+
*/
|
|
1619
|
+
PageSetup.prototype.linkFooter = function (footer, refType) {
|
|
1620
|
+
var document = requireAssociatedSectionDocument(this);
|
|
1621
|
+
linkSectionFooter(document, this, footer.relationshipId, resolveRefType(refType));
|
|
1622
|
+
};
|
|
1623
|
+
/**
|
|
1624
|
+
/even).
|
|
1625
|
+
*/
|
|
1626
|
+
PageSetup.prototype.removeHeader = function (refType) {
|
|
1627
|
+
requireAssociatedSectionDocument(this);
|
|
1628
|
+
this.setHeaderFooterReference('header', resolveRefType(refType), undefined);
|
|
1629
|
+
};
|
|
1630
|
+
/**
|
|
1631
|
+
/even).
|
|
1632
|
+
*/
|
|
1633
|
+
PageSetup.prototype.removeFooter = function (refType) {
|
|
1634
|
+
requireAssociatedSectionDocument(this);
|
|
1635
|
+
this.setHeaderFooterReference('footer', resolveRefType(refType), undefined);
|
|
1636
|
+
};
|
|
1637
|
+
/**
|
|
1638
|
+
* Set header text on a paragraph section break (`w:pPr/w:sectPr`).
|
|
1639
|
+
* @private
|
|
1640
|
+
*/
|
|
1641
|
+
export function setParagraphSectionHeader(document, paragraph, text, refType) {
|
|
1642
|
+
if (refType === void 0) { refType = 'default'; }
|
|
1643
|
+
var section = paragraphSectionBreak(paragraph);
|
|
1644
|
+
if (section === undefined) {
|
|
1645
|
+
section = defaultLetterPageSetup();
|
|
1646
|
+
}
|
|
1647
|
+
setSectionHeader(document, section, text, refType);
|
|
1648
|
+
setParagraphSectionBreak(paragraph, section);
|
|
1649
|
+
}
|
|
1650
|
+
/**
|
|
1651
|
+
* Set footer text on a paragraph section break (`w:pPr/w:sectPr`).
|
|
1652
|
+
* @private
|
|
1653
|
+
*/
|
|
1654
|
+
export function setParagraphSectionFooter(document, paragraph, text, refType) {
|
|
1655
|
+
if (refType === void 0) { refType = 'default'; }
|
|
1656
|
+
var section = paragraphSectionBreak(paragraph);
|
|
1657
|
+
if (section === undefined) {
|
|
1658
|
+
section = defaultLetterPageSetup();
|
|
1659
|
+
}
|
|
1660
|
+
setSectionFooter(document, section, text, refType);
|
|
1661
|
+
setParagraphSectionBreak(paragraph, section);
|
|
1662
|
+
}
|
|
1663
|
+
registerAlwaysOnBodyFeatureBootstrap(function () {
|
|
1664
|
+
registerHeadersFootersFeature();
|
|
1665
|
+
});
|
|
1666
|
+
registerHeadersFootersFeature();
|