@syncfusion/ej2-docx 0.0.0-stage → 35.1.39
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/README.md +68 -2
- package/core.js +4 -0
- package/dist/ej2-docx.umd.min.js +2 -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 +2 -0
- package/dist/global/ej2-docx.min.js.map +1 -0
- package/dist/global/index.d.ts +5 -0
- package/features.js +4 -0
- package/index.js +4 -0
- package/license +10 -0
- package/package.json +31 -4
- 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,2148 @@
|
|
|
1
|
+
var __extends = (this && this.__extends) || (function () {
|
|
2
|
+
var extendStatics = function (d, b) {
|
|
3
|
+
extendStatics = Object.setPrototypeOf ||
|
|
4
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
5
|
+
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
|
6
|
+
return extendStatics(d, b);
|
|
7
|
+
};
|
|
8
|
+
return function (d, b) {
|
|
9
|
+
extendStatics(d, b);
|
|
10
|
+
function __() { this.constructor = d; }
|
|
11
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
12
|
+
};
|
|
13
|
+
})();
|
|
14
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
15
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
16
|
+
if (!m) return o;
|
|
17
|
+
var i = m.call(o), r, ar = [], e;
|
|
18
|
+
try {
|
|
19
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
20
|
+
}
|
|
21
|
+
catch (error) { e = { error: error }; }
|
|
22
|
+
finally {
|
|
23
|
+
try {
|
|
24
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
25
|
+
}
|
|
26
|
+
finally { if (e) throw e.error; }
|
|
27
|
+
}
|
|
28
|
+
return ar;
|
|
29
|
+
};
|
|
30
|
+
var __spread = (this && this.__spread) || function () {
|
|
31
|
+
for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i]));
|
|
32
|
+
return ar;
|
|
33
|
+
};
|
|
34
|
+
var __values = (this && this.__values) || function (o) {
|
|
35
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator], i = 0;
|
|
36
|
+
if (m) return m.call(o);
|
|
37
|
+
return {
|
|
38
|
+
next: function () {
|
|
39
|
+
if (o && i >= o.length) o = void 0;
|
|
40
|
+
return { value: o && o[i++], done: !o };
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
import { DetachedObjectError, DocxError } from '../../core/errors/docx-error';
|
|
45
|
+
import { registerAlwaysOnBodyFeatureBootstrap } from '../document/body-always-on';
|
|
46
|
+
import { parseOnOff } from '../document/on-off';
|
|
47
|
+
import { Paragraph } from '../document/paragraph';
|
|
48
|
+
import { FeatureInlineParagraphItem, FeatureRunParagraphItem, serializeRun, TextRange, } from '../document/text-range';
|
|
49
|
+
import { elementChildren, isWml, textContent, wValAttribute, wmlAttr, wmlElement, xmlSpaceIsPreserve, xmlSpacePreserve, } from '../document/wml';
|
|
50
|
+
import { featureId, registerFeature, registerFeatureInlineHandler, registerFeatureRunLeafHandler, visitParagraphsInDocumentOrder, } from '../../core/registry/index';
|
|
51
|
+
import { FieldMark as ParagraphFieldMark, FieldMarkType as ParagraphFieldMarkType, Field, IfField, MergeField, } from './paragraph-field';
|
|
52
|
+
export { Field, IfField, MergeField, FieldMark, FieldMarkType } from './paragraph-field';
|
|
53
|
+
import { Picture } from '../images/index';
|
|
54
|
+
import { hyperlinksFor } from '../hyperlinks/index';
|
|
55
|
+
var FIELDS = featureId('fields');
|
|
56
|
+
/**
|
|
57
|
+
* Customer-facing Word field types (ECMA-376-1 §17.16 instruction keywords).
|
|
58
|
+
*
|
|
59
|
+
* Only PAGE, NUMPAGES, IF, MERGEFIELD, and HYPERLINK are public in this phase.
|
|
60
|
+
* Other instructions load as opaque content and are excluded from {@link fieldsInParagraph}.
|
|
61
|
+
*
|
|
62
|
+
* @public
|
|
63
|
+
*/
|
|
64
|
+
export var FieldType = {
|
|
65
|
+
/** `PAGE` — current page number. */
|
|
66
|
+
Page: 'PAGE',
|
|
67
|
+
/** `NUMPAGES` — total number of pages. */
|
|
68
|
+
NumPages: 'NUMPAGES',
|
|
69
|
+
/** `IF` — conditional field. */
|
|
70
|
+
If: 'IF',
|
|
71
|
+
/** `MERGEFIELD` — mail-merge field. */
|
|
72
|
+
MergeField: 'MERGEFIELD',
|
|
73
|
+
/** `HYPERLINK` — hyperlink field. */
|
|
74
|
+
Hyperlink: 'HYPERLINK',
|
|
75
|
+
};
|
|
76
|
+
var SUPPORTED_FIELD_TYPES = new Map([
|
|
77
|
+
[FieldType.Page, FieldType.Page],
|
|
78
|
+
[FieldType.NumPages, FieldType.NumPages],
|
|
79
|
+
[FieldType.If, FieldType.If],
|
|
80
|
+
[FieldType.MergeField, FieldType.MergeField],
|
|
81
|
+
[FieldType.Hyperlink, FieldType.Hyperlink],
|
|
82
|
+
]);
|
|
83
|
+
/**
|
|
84
|
+
* Hyperlink classification for field-based ({@link Hyperlink}) authoring.
|
|
85
|
+
*
|
|
86
|
+
* @public
|
|
87
|
+
*/
|
|
88
|
+
export var HyperlinkType = {
|
|
89
|
+
WebLink: 'WebLink',
|
|
90
|
+
EmailLink: 'EmailLink',
|
|
91
|
+
FileLink: 'FileLink',
|
|
92
|
+
Bookmark: 'Bookmark',
|
|
93
|
+
};
|
|
94
|
+
function wmlAttribute(el, localName) {
|
|
95
|
+
var __ts33_0;
|
|
96
|
+
return ((__ts33_0 = el.attributes.find(function (a) { return a.localName === localName && (a.namespaceUri === '' || a.prefix === 'w'); })), __ts33_0 == null ? undefined : __ts33_0.value);
|
|
97
|
+
}
|
|
98
|
+
function parseFieldMarkType(raw) {
|
|
99
|
+
if (raw === 'begin' || raw === 'separate' || raw === 'end') {
|
|
100
|
+
return raw;
|
|
101
|
+
}
|
|
102
|
+
return undefined;
|
|
103
|
+
}
|
|
104
|
+
var SimpleFieldRunOwner = /** @class */ (function () {
|
|
105
|
+
function SimpleFieldRunOwner() {
|
|
106
|
+
this.runs = [];
|
|
107
|
+
}
|
|
108
|
+
SimpleFieldRunOwner.prototype.assertAttachedItem = function (target) {
|
|
109
|
+
if (!(target instanceof TextRange) || this.runs.indexOf(target) < 0) {
|
|
110
|
+
throw new DetachedObjectError('This run is no longer in its field');
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
SimpleFieldRunOwner.prototype.appendRun = function () {
|
|
114
|
+
var run = new TextRange(this);
|
|
115
|
+
this.runs = __spread(this.runs, [run]);
|
|
116
|
+
return run;
|
|
117
|
+
};
|
|
118
|
+
SimpleFieldRunOwner.prototype.listRuns = function () {
|
|
119
|
+
return this.runs;
|
|
120
|
+
};
|
|
121
|
+
SimpleFieldRunOwner.prototype.detachRuns = function () {
|
|
122
|
+
var e_1, _a;
|
|
123
|
+
try {
|
|
124
|
+
for (var _b = __values(this.runs), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
125
|
+
var run = _c.value;
|
|
126
|
+
run.detach();
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
130
|
+
finally {
|
|
131
|
+
try {
|
|
132
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
133
|
+
}
|
|
134
|
+
finally { if (e_1) throw e_1.error; }
|
|
135
|
+
}
|
|
136
|
+
this.runs = [];
|
|
137
|
+
};
|
|
138
|
+
SimpleFieldRunOwner.prototype.hydrateRuns = function (runs) {
|
|
139
|
+
var e_2, _a;
|
|
140
|
+
this.runs = runs;
|
|
141
|
+
try {
|
|
142
|
+
for (var runs_1 = __values(runs), runs_1_1 = runs_1.next(); !runs_1_1.done; runs_1_1 = runs_1.next()) {
|
|
143
|
+
var run = runs_1_1.value;
|
|
144
|
+
run.attach(this);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
148
|
+
finally {
|
|
149
|
+
try {
|
|
150
|
+
if (runs_1_1 && !runs_1_1.done && (_a = runs_1.return)) _a.call(runs_1);
|
|
151
|
+
}
|
|
152
|
+
finally { if (e_2) throw e_2.error; }
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
return SimpleFieldRunOwner;
|
|
156
|
+
}());
|
|
157
|
+
/**
|
|
158
|
+
* Simple field storage (`w:fldSimple`).
|
|
159
|
+
*
|
|
160
|
+
* @private
|
|
161
|
+
*/
|
|
162
|
+
var SimpleField = /** @class */ (function () {
|
|
163
|
+
/**
|
|
164
|
+
* @private
|
|
165
|
+
*/
|
|
166
|
+
function SimpleField(runOwner, extras, items, instruction, fldLock, dirty) {
|
|
167
|
+
this.runOwner = runOwner;
|
|
168
|
+
this.extras = extras;
|
|
169
|
+
this.items = items;
|
|
170
|
+
this.instructionValue = instruction;
|
|
171
|
+
this.fldLock = fldLock;
|
|
172
|
+
this.dirty = dirty;
|
|
173
|
+
}
|
|
174
|
+
Object.defineProperty(SimpleField.prototype, "instruction", {
|
|
175
|
+
/**
|
|
176
|
+
* Field instruction (`w:fldSimple/@w:instr`).
|
|
177
|
+
* @private
|
|
178
|
+
*/
|
|
179
|
+
get: function () {
|
|
180
|
+
return this.instructionValue;
|
|
181
|
+
},
|
|
182
|
+
enumerable: true,
|
|
183
|
+
configurable: true
|
|
184
|
+
});
|
|
185
|
+
/**
|
|
186
|
+
* @private
|
|
187
|
+
*/
|
|
188
|
+
SimpleField.prototype.setInstruction = function (value) {
|
|
189
|
+
this.instructionValue = value;
|
|
190
|
+
};
|
|
191
|
+
Object.defineProperty(SimpleField.prototype, "runs", {
|
|
192
|
+
/**
|
|
193
|
+
* Result text ranges inside the simple field.
|
|
194
|
+
* @private
|
|
195
|
+
*/
|
|
196
|
+
get: function () {
|
|
197
|
+
return this.runOwner.listRuns();
|
|
198
|
+
},
|
|
199
|
+
enumerable: true,
|
|
200
|
+
configurable: true
|
|
201
|
+
});
|
|
202
|
+
/**
|
|
203
|
+
* @private
|
|
204
|
+
*/
|
|
205
|
+
SimpleField.prototype.releaseContent = function () {
|
|
206
|
+
this.runOwner.detachRuns();
|
|
207
|
+
};
|
|
208
|
+
SimpleField.prototype.toOpenXml = function () {
|
|
209
|
+
var e_3, _a;
|
|
210
|
+
var attributes = [wmlAttr('instr', this.instructionValue)];
|
|
211
|
+
if (this.fldLock !== undefined) {
|
|
212
|
+
attributes.push(wmlAttr('fldLock', this.fldLock ? '1' : '0'));
|
|
213
|
+
}
|
|
214
|
+
if (this.dirty !== undefined) {
|
|
215
|
+
attributes.push(wmlAttr('dirty', this.dirty ? '1' : '0'));
|
|
216
|
+
}
|
|
217
|
+
var children = __spread(this.extras);
|
|
218
|
+
try {
|
|
219
|
+
for (var _b = __values(this.items), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
220
|
+
var item = _c.value;
|
|
221
|
+
if (item.type === 'textRange') {
|
|
222
|
+
children.push(serializeRun(item.run));
|
|
223
|
+
}
|
|
224
|
+
else {
|
|
225
|
+
children.push(item.xml);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
230
|
+
finally {
|
|
231
|
+
try {
|
|
232
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
233
|
+
}
|
|
234
|
+
finally { if (e_3) throw e_3.error; }
|
|
235
|
+
}
|
|
236
|
+
return wmlElement('fldSimple', { attributes: attributes, children: children });
|
|
237
|
+
};
|
|
238
|
+
return SimpleField;
|
|
239
|
+
}());
|
|
240
|
+
/**
|
|
241
|
+
* Complex field character marker (`w:fldChar`).
|
|
242
|
+
*
|
|
243
|
+
* Children such as `w:ffData` and `w:fldData` are retained and re-emitted
|
|
244
|
+
* unchanged. Typed form-field access is via {@link FormField}.
|
|
245
|
+
*
|
|
246
|
+
* @private
|
|
247
|
+
*/
|
|
248
|
+
var FieldMark = /** @class */ (function () {
|
|
249
|
+
/**
|
|
250
|
+
* @private
|
|
251
|
+
*/
|
|
252
|
+
function FieldMark(fldCharType, fldLock, dirty, extras) {
|
|
253
|
+
this.fldCharType = fldCharType;
|
|
254
|
+
this.fldLock = fldLock;
|
|
255
|
+
this.dirty = dirty;
|
|
256
|
+
this.extras = extras;
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Unmodeled / pass-through children of `w:fldChar` (includes `w:ffData`).
|
|
260
|
+
*
|
|
261
|
+
* @private
|
|
262
|
+
*/
|
|
263
|
+
FieldMark.prototype.childElements = function () {
|
|
264
|
+
return this.extras;
|
|
265
|
+
};
|
|
266
|
+
FieldMark.prototype.toOpenXml = function () {
|
|
267
|
+
var attributes = [wmlAttr('fldCharType', this.fldCharType)];
|
|
268
|
+
if (this.fldLock !== undefined) {
|
|
269
|
+
attributes.push(wmlAttr('fldLock', this.fldLock ? '1' : '0'));
|
|
270
|
+
}
|
|
271
|
+
if (this.dirty !== undefined) {
|
|
272
|
+
attributes.push(wmlAttr('dirty', this.dirty ? '1' : '0'));
|
|
273
|
+
}
|
|
274
|
+
var children = __spread(this.extras);
|
|
275
|
+
return wmlElement('fldChar', { attributes: attributes, children: children });
|
|
276
|
+
};
|
|
277
|
+
return FieldMark;
|
|
278
|
+
}());
|
|
279
|
+
/**
|
|
280
|
+
* Field instruction text (`w:instrText`).
|
|
281
|
+
*
|
|
282
|
+
* @private
|
|
283
|
+
*/
|
|
284
|
+
var InstrText = /** @class */ (function () {
|
|
285
|
+
/**
|
|
286
|
+
* @private
|
|
287
|
+
*/
|
|
288
|
+
function InstrText(text, xmlSpacePreserve) {
|
|
289
|
+
this.textValue = text;
|
|
290
|
+
this.xmlSpacePreserve = xmlSpacePreserve;
|
|
291
|
+
}
|
|
292
|
+
Object.defineProperty(InstrText.prototype, "text", {
|
|
293
|
+
/**
|
|
294
|
+
* Instruction text content.
|
|
295
|
+
* @private
|
|
296
|
+
*/
|
|
297
|
+
get: function () {
|
|
298
|
+
return this.textValue;
|
|
299
|
+
},
|
|
300
|
+
enumerable: true,
|
|
301
|
+
configurable: true
|
|
302
|
+
});
|
|
303
|
+
/**
|
|
304
|
+
* @private
|
|
305
|
+
*/
|
|
306
|
+
InstrText.prototype.setText = function (value) {
|
|
307
|
+
this.textValue = value;
|
|
308
|
+
};
|
|
309
|
+
InstrText.prototype.toOpenXml = function () {
|
|
310
|
+
var attributes = this.xmlSpacePreserve ? [xmlSpacePreserve()] : [];
|
|
311
|
+
return wmlElement('instrText', {
|
|
312
|
+
attributes: attributes,
|
|
313
|
+
children: [{ kind: 'text', value: this.textValue }],
|
|
314
|
+
});
|
|
315
|
+
};
|
|
316
|
+
return InstrText;
|
|
317
|
+
}());
|
|
318
|
+
/**
|
|
319
|
+
* A complex field span within one paragraph (begin → instr → separate → result → end).
|
|
320
|
+
*
|
|
321
|
+
* Markers and instruction text are elevated {@link FeatureRunParagraphItem} values on the
|
|
322
|
+
* paragraph; result content is plain {@link TextRange} siblings between separate and end.
|
|
323
|
+
*
|
|
324
|
+
* @private
|
|
325
|
+
*/
|
|
326
|
+
var ComplexField = /** @class */ (function () {
|
|
327
|
+
/**
|
|
328
|
+
* @private
|
|
329
|
+
*/
|
|
330
|
+
function ComplexField(instruction, resultRuns, markerValues, instructionTexts) {
|
|
331
|
+
if (instructionTexts === void 0) { instructionTexts = []; }
|
|
332
|
+
this.instructionValue = instruction;
|
|
333
|
+
this.resultRuns = resultRuns;
|
|
334
|
+
this.markerValues = markerValues;
|
|
335
|
+
this.instructionTexts = instructionTexts;
|
|
336
|
+
}
|
|
337
|
+
Object.defineProperty(ComplexField.prototype, "instruction", {
|
|
338
|
+
/**
|
|
339
|
+
* Instruction snapshot / live value.
|
|
340
|
+
* @private
|
|
341
|
+
*/
|
|
342
|
+
get: function () {
|
|
343
|
+
return this.instructionValue;
|
|
344
|
+
},
|
|
345
|
+
enumerable: true,
|
|
346
|
+
configurable: true
|
|
347
|
+
});
|
|
348
|
+
/**
|
|
349
|
+
* @private
|
|
350
|
+
*/
|
|
351
|
+
ComplexField.prototype.setInstruction = function (value) {
|
|
352
|
+
var e_4, _a;
|
|
353
|
+
this.instructionValue = value;
|
|
354
|
+
var trimmed = value.trim();
|
|
355
|
+
var padded = trimmed.length === 0 ? ' ' : " " + trimmed + " ";
|
|
356
|
+
var wrote = false;
|
|
357
|
+
try {
|
|
358
|
+
for (var _b = __values(this.instructionTexts), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
359
|
+
var instr = _c.value;
|
|
360
|
+
if (!wrote) {
|
|
361
|
+
instr.setText(padded);
|
|
362
|
+
wrote = true;
|
|
363
|
+
}
|
|
364
|
+
else {
|
|
365
|
+
instr.setText('');
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
370
|
+
finally {
|
|
371
|
+
try {
|
|
372
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
373
|
+
}
|
|
374
|
+
finally { if (e_4) throw e_4.error; }
|
|
375
|
+
}
|
|
376
|
+
};
|
|
377
|
+
/**
|
|
378
|
+
* All feature-run marker/instr values plus result text ranges, used for removal.
|
|
379
|
+
* @private
|
|
380
|
+
*/
|
|
381
|
+
ComplexField.prototype.allFeatureValues = function () {
|
|
382
|
+
return this.markerValues;
|
|
383
|
+
};
|
|
384
|
+
return ComplexField;
|
|
385
|
+
}());
|
|
386
|
+
/**
|
|
387
|
+
* Read-only view of a legacy Word form field (`w:ffData` on begin `w:fldChar`).
|
|
388
|
+
*
|
|
389
|
+
* Form fields are complex-field spans whose begin marker carries form-field
|
|
390
|
+
* data (ECMA-376-1 §17.16.17 `ffData`; Transitional `wml.xsd` `CT_FFData`).
|
|
391
|
+
* This helper does **not** implement `FeatureInline` / `FeatureRunLeaf` and is
|
|
392
|
+
* never serialized on its own — the begin `w:fldChar` re-emits the stored
|
|
393
|
+
* `w:ffData` element (no double-emit). Internal field markers and complex-field
|
|
394
|
+
* spans are not part of the public surface.
|
|
395
|
+
*
|
|
396
|
+
* Kind-specific members apply only when {@link type} matches; otherwise they
|
|
397
|
+
* are `undefined` / empty. Mutation of `ffData` is out of scope for this MVP.
|
|
398
|
+
*
|
|
399
|
+
* @public
|
|
400
|
+
*/
|
|
401
|
+
var FormField = /** @class */ (function () {
|
|
402
|
+
/**
|
|
403
|
+
* @private
|
|
404
|
+
*/
|
|
405
|
+
function FormField(_beginMark, data, kind, _complex) {
|
|
406
|
+
this.data = data;
|
|
407
|
+
this.kindValue = kind;
|
|
408
|
+
}
|
|
409
|
+
Object.defineProperty(FormField.prototype, "type", {
|
|
410
|
+
/**
|
|
411
|
+
* Control kind derived from the exclusive `w:textInput` / `w:checkBox` /
|
|
412
|
+
* `w:ddList` child under `w:ffData`.
|
|
413
|
+
*/
|
|
414
|
+
get: function () {
|
|
415
|
+
return this.kindValue;
|
|
416
|
+
},
|
|
417
|
+
enumerable: true,
|
|
418
|
+
configurable: true
|
|
419
|
+
});
|
|
420
|
+
Object.defineProperty(FormField.prototype, "name", {
|
|
421
|
+
/** `w:ffData/w:name/@w:val` (`ST_FFName`). */
|
|
422
|
+
get: function () {
|
|
423
|
+
return firstChildVal(this.data, 'name');
|
|
424
|
+
},
|
|
425
|
+
enumerable: true,
|
|
426
|
+
configurable: true
|
|
427
|
+
});
|
|
428
|
+
Object.defineProperty(FormField.prototype, "enabled", {
|
|
429
|
+
/**
|
|
430
|
+
* `w:ffData/w:enabled` (`CT_OnOff`). Absent means enabled in Word UI; this
|
|
431
|
+
* surface returns `undefined` when the element is missing, `true`/`false`
|
|
432
|
+
* when present (including empty `w:enabled` = true).
|
|
433
|
+
*/
|
|
434
|
+
get: function () {
|
|
435
|
+
return firstChildOnOff(this.data, 'enabled');
|
|
436
|
+
},
|
|
437
|
+
enumerable: true,
|
|
438
|
+
configurable: true
|
|
439
|
+
});
|
|
440
|
+
Object.defineProperty(FormField.prototype, "tabIndex", {
|
|
441
|
+
/** `w:ffData/w:tabIndex/@w:val` (`CT_UnsignedDecimalNumber`). */
|
|
442
|
+
get: function () {
|
|
443
|
+
return firstChildDecimal(this.data, 'tabIndex');
|
|
444
|
+
},
|
|
445
|
+
enumerable: true,
|
|
446
|
+
configurable: true
|
|
447
|
+
});
|
|
448
|
+
Object.defineProperty(FormField.prototype, "helpText", {
|
|
449
|
+
/** `w:ffData/w:helpText/@w:val` (type attribute is preserved on the element). */
|
|
450
|
+
get: function () {
|
|
451
|
+
return firstChildVal(this.data, 'helpText');
|
|
452
|
+
},
|
|
453
|
+
enumerable: true,
|
|
454
|
+
configurable: true
|
|
455
|
+
});
|
|
456
|
+
Object.defineProperty(FormField.prototype, "statusText", {
|
|
457
|
+
/** `w:ffData/w:statusText/@w:val`. */
|
|
458
|
+
get: function () {
|
|
459
|
+
return firstChildVal(this.data, 'statusText');
|
|
460
|
+
},
|
|
461
|
+
enumerable: true,
|
|
462
|
+
configurable: true
|
|
463
|
+
});
|
|
464
|
+
Object.defineProperty(FormField.prototype, "maxLength", {
|
|
465
|
+
// --- textInput (CT_FFTextInput) ---
|
|
466
|
+
/** `w:textInput/w:maxLength/@w:val` (`CT_DecimalNumber`; 0 = unlimited). */
|
|
467
|
+
get: function () {
|
|
468
|
+
return nestedChildDecimal(this.data, 'textInput', 'maxLength');
|
|
469
|
+
},
|
|
470
|
+
enumerable: true,
|
|
471
|
+
configurable: true
|
|
472
|
+
});
|
|
473
|
+
Object.defineProperty(FormField.prototype, "format", {
|
|
474
|
+
/** `w:textInput/w:format/@w:val`. */
|
|
475
|
+
get: function () {
|
|
476
|
+
return nestedChildVal(this.data, 'textInput', 'format');
|
|
477
|
+
},
|
|
478
|
+
enumerable: true,
|
|
479
|
+
configurable: true
|
|
480
|
+
});
|
|
481
|
+
Object.defineProperty(FormField.prototype, "defaultText", {
|
|
482
|
+
/** `w:textInput/w:default/@w:val`. */
|
|
483
|
+
get: function () {
|
|
484
|
+
return nestedChildVal(this.data, 'textInput', 'default');
|
|
485
|
+
},
|
|
486
|
+
enumerable: true,
|
|
487
|
+
configurable: true
|
|
488
|
+
});
|
|
489
|
+
Object.defineProperty(FormField.prototype, "checked", {
|
|
490
|
+
// --- checkBox (CT_FFCheckBox) ---
|
|
491
|
+
/** `w:checkBox/w:checked` (`CT_OnOff`) — current checked state. */
|
|
492
|
+
get: function () {
|
|
493
|
+
return nestedChildOnOff(this.data, 'checkBox', 'checked');
|
|
494
|
+
},
|
|
495
|
+
enumerable: true,
|
|
496
|
+
configurable: true
|
|
497
|
+
});
|
|
498
|
+
Object.defineProperty(FormField.prototype, "defaultChecked", {
|
|
499
|
+
/** `w:checkBox/w:default` (`CT_OnOff`) — default checked state. */
|
|
500
|
+
get: function () {
|
|
501
|
+
return nestedChildOnOff(this.data, 'checkBox', 'default');
|
|
502
|
+
},
|
|
503
|
+
enumerable: true,
|
|
504
|
+
configurable: true
|
|
505
|
+
});
|
|
506
|
+
Object.defineProperty(FormField.prototype, "entries", {
|
|
507
|
+
// --- dropDown (CT_FFDDList; product kind `'dropDown'`) ---
|
|
508
|
+
/**
|
|
509
|
+
* `w:ddList/w:listEntry/@w:val` entries in document order.
|
|
510
|
+
* Empty when kind is not drop-down or no entries are present.
|
|
511
|
+
*/
|
|
512
|
+
get: function () {
|
|
513
|
+
var e_5, _a;
|
|
514
|
+
var list = firstWmlChild(this.data, 'ddList');
|
|
515
|
+
if (list === undefined) {
|
|
516
|
+
return [];
|
|
517
|
+
}
|
|
518
|
+
var out = [];
|
|
519
|
+
try {
|
|
520
|
+
for (var _b = __values(elementChildren(list)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
521
|
+
var child = _c.value;
|
|
522
|
+
if (!isWml(child, 'listEntry')) {
|
|
523
|
+
continue;
|
|
524
|
+
}
|
|
525
|
+
var val = wValAttribute(child);
|
|
526
|
+
if (val !== undefined) {
|
|
527
|
+
out.push(val);
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
catch (e_5_1) { e_5 = { error: e_5_1 }; }
|
|
532
|
+
finally {
|
|
533
|
+
try {
|
|
534
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
535
|
+
}
|
|
536
|
+
finally { if (e_5) throw e_5.error; }
|
|
537
|
+
}
|
|
538
|
+
return out;
|
|
539
|
+
},
|
|
540
|
+
enumerable: true,
|
|
541
|
+
configurable: true
|
|
542
|
+
});
|
|
543
|
+
Object.defineProperty(FormField.prototype, "selected", {
|
|
544
|
+
/**
|
|
545
|
+
* `w:ddList/w:result/@w:val` — zero-based selected index when present.
|
|
546
|
+
*/
|
|
547
|
+
get: function () {
|
|
548
|
+
return nestedChildDecimal(this.data, 'ddList', 'result');
|
|
549
|
+
},
|
|
550
|
+
enumerable: true,
|
|
551
|
+
configurable: true
|
|
552
|
+
});
|
|
553
|
+
Object.defineProperty(FormField.prototype, "selectedEntry", {
|
|
554
|
+
/**
|
|
555
|
+
* Entry text at {@link selected}, or `undefined` if index is missing or
|
|
556
|
+
* out of range.
|
|
557
|
+
*/
|
|
558
|
+
get: function () {
|
|
559
|
+
var index = this.selected;
|
|
560
|
+
if (index === undefined) {
|
|
561
|
+
return undefined;
|
|
562
|
+
}
|
|
563
|
+
return this.entries[index];
|
|
564
|
+
},
|
|
565
|
+
enumerable: true,
|
|
566
|
+
configurable: true
|
|
567
|
+
});
|
|
568
|
+
return FormField;
|
|
569
|
+
}());
|
|
570
|
+
export { FormField };
|
|
571
|
+
/**
|
|
572
|
+
* Customer-facing Word field (PAGE / NUMPAGES base; subclasses for IF / MERGEFIELD).
|
|
573
|
+
*
|
|
574
|
+
* Wraps either a simple field (`w:fldSimple`) or a complex field span
|
|
575
|
+
* (`w:fldChar` / `w:instrText`). Does **not** recalculate Word field results.
|
|
576
|
+
*
|
|
577
|
+
* @public
|
|
578
|
+
*/
|
|
579
|
+
var LegacyField = /** @class */ (function () {
|
|
580
|
+
/**
|
|
581
|
+
* @private
|
|
582
|
+
*/
|
|
583
|
+
function LegacyField(kind, simple, complex, host, lockedType) {
|
|
584
|
+
this.kind = kind;
|
|
585
|
+
this.simple = simple;
|
|
586
|
+
this.complex = complex;
|
|
587
|
+
this.host = host;
|
|
588
|
+
this.lockedType = lockedType;
|
|
589
|
+
}
|
|
590
|
+
Object.defineProperty(LegacyField.prototype, "fieldCode", {
|
|
591
|
+
/**
|
|
592
|
+
* Full field instruction / field code (for example ` PAGE `, ` MERGEFIELD Name `).
|
|
593
|
+
*
|
|
594
|
+
* The instruction keyword must remain this field’s {@link fieldType}.
|
|
595
|
+
*/
|
|
596
|
+
get: function () {
|
|
597
|
+
if (this.kind === 'simple' && this.simple !== undefined) {
|
|
598
|
+
return this.simple.instruction;
|
|
599
|
+
}
|
|
600
|
+
if (this.complex !== undefined) {
|
|
601
|
+
return this.complex.instruction;
|
|
602
|
+
}
|
|
603
|
+
return '';
|
|
604
|
+
},
|
|
605
|
+
set: function (value) {
|
|
606
|
+
if (value.trim().length === 0) {
|
|
607
|
+
throw new DocxError('content/invalid-field', 'Field instruction must not be empty');
|
|
608
|
+
}
|
|
609
|
+
var nextType = trySupportedFieldTypeFromInstruction(value);
|
|
610
|
+
if (nextType === undefined || nextType !== this.lockedType) {
|
|
611
|
+
throw new DocxError('content/invalid-field', 'Field instruction keyword must match fieldType ' + this.lockedType);
|
|
612
|
+
}
|
|
613
|
+
if (this.kind === 'simple' && this.simple !== undefined) {
|
|
614
|
+
this.simple.setInstruction(value);
|
|
615
|
+
return;
|
|
616
|
+
}
|
|
617
|
+
if (this.complex !== undefined) {
|
|
618
|
+
this.complex.setInstruction(value);
|
|
619
|
+
}
|
|
620
|
+
},
|
|
621
|
+
enumerable: true,
|
|
622
|
+
configurable: true
|
|
623
|
+
});
|
|
624
|
+
Object.defineProperty(LegacyField.prototype, "fieldType", {
|
|
625
|
+
/**
|
|
626
|
+
* Supported field type for this instance (fixed at construction).
|
|
627
|
+
*/
|
|
628
|
+
get: function () {
|
|
629
|
+
return this.lockedType;
|
|
630
|
+
},
|
|
631
|
+
enumerable: true,
|
|
632
|
+
configurable: true
|
|
633
|
+
});
|
|
634
|
+
Object.defineProperty(LegacyField.prototype, "fieldValue", {
|
|
635
|
+
/**
|
|
636
|
+
* Cached field-result text (read-only). Prefer {@link text} to mutate display text.
|
|
637
|
+
*/
|
|
638
|
+
get: function () {
|
|
639
|
+
return this.readResultText();
|
|
640
|
+
},
|
|
641
|
+
enumerable: true,
|
|
642
|
+
configurable: true
|
|
643
|
+
});
|
|
644
|
+
Object.defineProperty(LegacyField.prototype, "text", {
|
|
645
|
+
/**
|
|
646
|
+
* Cached visible field-result text.
|
|
647
|
+
*/
|
|
648
|
+
get: function () {
|
|
649
|
+
return this.readResultText();
|
|
650
|
+
},
|
|
651
|
+
set: function (value) {
|
|
652
|
+
this.writeResultText(value);
|
|
653
|
+
},
|
|
654
|
+
enumerable: true,
|
|
655
|
+
configurable: true
|
|
656
|
+
});
|
|
657
|
+
Object.defineProperty(LegacyField.prototype, "characterFormat", {
|
|
658
|
+
/**
|
|
659
|
+
* Character formatting of the first result {@link TextRange}.
|
|
660
|
+
*/
|
|
661
|
+
get: function () {
|
|
662
|
+
var run = this.firstResultRun();
|
|
663
|
+
if (run === undefined) {
|
|
664
|
+
throw new DocxError('content/invalid-field', 'Field has no result run for characterFormat');
|
|
665
|
+
}
|
|
666
|
+
return run.characterFormat;
|
|
667
|
+
},
|
|
668
|
+
enumerable: true,
|
|
669
|
+
configurable: true
|
|
670
|
+
});
|
|
671
|
+
LegacyField.prototype.readResultText = function () {
|
|
672
|
+
if (this.kind === 'simple' && this.simple !== undefined) {
|
|
673
|
+
return concatenateRunText(this.simple.runs);
|
|
674
|
+
}
|
|
675
|
+
if (this.complex !== undefined) {
|
|
676
|
+
return concatenateRunText(this.complex.resultRuns);
|
|
677
|
+
}
|
|
678
|
+
return '';
|
|
679
|
+
};
|
|
680
|
+
LegacyField.prototype.writeResultText = function (value) {
|
|
681
|
+
var runs = this.resultRuns();
|
|
682
|
+
if (runs.length === 0) {
|
|
683
|
+
throw new DocxError('content/invalid-field', 'Field has no result run');
|
|
684
|
+
}
|
|
685
|
+
var first = runs[0];
|
|
686
|
+
if (first === undefined) {
|
|
687
|
+
throw new DocxError('content/invalid-field', 'Field has no result run');
|
|
688
|
+
}
|
|
689
|
+
first.text = value;
|
|
690
|
+
for (var index = 1; index < runs.length; index += 1) {
|
|
691
|
+
runs[index].text = '';
|
|
692
|
+
}
|
|
693
|
+
};
|
|
694
|
+
LegacyField.prototype.resultRuns = function () {
|
|
695
|
+
if (this.kind === 'simple' && this.simple !== undefined) {
|
|
696
|
+
return this.simple.runs;
|
|
697
|
+
}
|
|
698
|
+
if (this.complex !== undefined) {
|
|
699
|
+
return this.complex.resultRuns;
|
|
700
|
+
}
|
|
701
|
+
return [];
|
|
702
|
+
};
|
|
703
|
+
LegacyField.prototype.firstResultRun = function () {
|
|
704
|
+
var runs = this.resultRuns();
|
|
705
|
+
return runs.length > 0 ? runs[0] : undefined;
|
|
706
|
+
};
|
|
707
|
+
return LegacyField;
|
|
708
|
+
}());
|
|
709
|
+
export { LegacyField };
|
|
710
|
+
/**
|
|
711
|
+
* Conditional `IF` field. Expression lives entirely in {@link Field.fieldCode}.
|
|
712
|
+
*
|
|
713
|
+
* @public
|
|
714
|
+
*/
|
|
715
|
+
var LegacyIfField = /** @class */ (function (_super) {
|
|
716
|
+
__extends(LegacyIfField, _super);
|
|
717
|
+
function LegacyIfField() {
|
|
718
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
719
|
+
}
|
|
720
|
+
return LegacyIfField;
|
|
721
|
+
}(LegacyField));
|
|
722
|
+
export { LegacyIfField };
|
|
723
|
+
/**
|
|
724
|
+
* Mail-merge `MERGEFIELD` with typed switch accessors.
|
|
725
|
+
*
|
|
726
|
+
* @public
|
|
727
|
+
*/
|
|
728
|
+
var LegacyMergeField = /** @class */ (function (_super) {
|
|
729
|
+
__extends(LegacyMergeField, _super);
|
|
730
|
+
function LegacyMergeField() {
|
|
731
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
732
|
+
}
|
|
733
|
+
Object.defineProperty(LegacyMergeField.prototype, "fieldName", {
|
|
734
|
+
get: function () {
|
|
735
|
+
return parseMergeFieldInstruction(this.fieldCode).fieldName;
|
|
736
|
+
},
|
|
737
|
+
set: function (value) {
|
|
738
|
+
var name = value.trim();
|
|
739
|
+
if (name.length === 0) {
|
|
740
|
+
throw new DocxError('content/invalid-field', 'MergeField fieldName must not be empty');
|
|
741
|
+
}
|
|
742
|
+
var parsed = parseMergeFieldInstruction(this.fieldCode);
|
|
743
|
+
parsed.fieldName = name;
|
|
744
|
+
this.fieldCode = formatMergeFieldInstruction(parsed);
|
|
745
|
+
},
|
|
746
|
+
enumerable: true,
|
|
747
|
+
configurable: true
|
|
748
|
+
});
|
|
749
|
+
Object.defineProperty(LegacyMergeField.prototype, "textBefore", {
|
|
750
|
+
get: function () {
|
|
751
|
+
return parseMergeFieldInstruction(this.fieldCode).textBefore;
|
|
752
|
+
},
|
|
753
|
+
set: function (value) {
|
|
754
|
+
var parsed = parseMergeFieldInstruction(this.fieldCode);
|
|
755
|
+
parsed.textBefore = value;
|
|
756
|
+
this.fieldCode = formatMergeFieldInstruction(parsed);
|
|
757
|
+
},
|
|
758
|
+
enumerable: true,
|
|
759
|
+
configurable: true
|
|
760
|
+
});
|
|
761
|
+
Object.defineProperty(LegacyMergeField.prototype, "textAfter", {
|
|
762
|
+
get: function () {
|
|
763
|
+
return parseMergeFieldInstruction(this.fieldCode).textAfter;
|
|
764
|
+
},
|
|
765
|
+
set: function (value) {
|
|
766
|
+
var parsed = parseMergeFieldInstruction(this.fieldCode);
|
|
767
|
+
parsed.textAfter = value;
|
|
768
|
+
this.fieldCode = formatMergeFieldInstruction(parsed);
|
|
769
|
+
},
|
|
770
|
+
enumerable: true,
|
|
771
|
+
configurable: true
|
|
772
|
+
});
|
|
773
|
+
Object.defineProperty(LegacyMergeField.prototype, "dateFormat", {
|
|
774
|
+
get: function () {
|
|
775
|
+
return parseMergeFieldInstruction(this.fieldCode).dateFormat;
|
|
776
|
+
},
|
|
777
|
+
enumerable: true,
|
|
778
|
+
configurable: true
|
|
779
|
+
});
|
|
780
|
+
Object.defineProperty(LegacyMergeField.prototype, "numberFormat", {
|
|
781
|
+
get: function () {
|
|
782
|
+
return parseMergeFieldInstruction(this.fieldCode).numberFormat;
|
|
783
|
+
},
|
|
784
|
+
enumerable: true,
|
|
785
|
+
configurable: true
|
|
786
|
+
});
|
|
787
|
+
Object.defineProperty(LegacyMergeField.prototype, "prefix", {
|
|
788
|
+
get: function () {
|
|
789
|
+
// DocIO-style prefix mirrors text-before (`\b`) when present.
|
|
790
|
+
return this.textBefore;
|
|
791
|
+
},
|
|
792
|
+
enumerable: true,
|
|
793
|
+
configurable: true
|
|
794
|
+
});
|
|
795
|
+
return LegacyMergeField;
|
|
796
|
+
}(LegacyField));
|
|
797
|
+
export { LegacyMergeField };
|
|
798
|
+
/**
|
|
799
|
+
* Hyperlink facade over either a HYPERLINK field or a picture DrawingML link.
|
|
800
|
+
*
|
|
801
|
+
* Distinct from the `w:hyperlink` inline model in `features/hyperlinks`.
|
|
802
|
+
* The all-in entry exports this type as {@link Hyperlink}; the inline
|
|
803
|
+
* relationship hyperlink is available from `@syncfusion/ej2-docx/hyperlinks`.
|
|
804
|
+
*
|
|
805
|
+
* @public
|
|
806
|
+
*/
|
|
807
|
+
var Hyperlink = /** @class */ (function () {
|
|
808
|
+
function Hyperlink(fieldOrPicture, uri, type) {
|
|
809
|
+
if (fieldOrPicture instanceof Picture) {
|
|
810
|
+
this.fieldValue = undefined;
|
|
811
|
+
this.pictureValue = fieldOrPicture;
|
|
812
|
+
this.pictureUriValue = uri != null ? uri : '';
|
|
813
|
+
this.pictureTypeValue = type != null ? type : HyperlinkType.WebLink;
|
|
814
|
+
}
|
|
815
|
+
else {
|
|
816
|
+
this.fieldValue = fieldOrPicture;
|
|
817
|
+
this.pictureValue = undefined;
|
|
818
|
+
this.pictureUriValue = '';
|
|
819
|
+
this.pictureTypeValue = HyperlinkType.WebLink;
|
|
820
|
+
}
|
|
821
|
+
}
|
|
822
|
+
Object.defineProperty(Hyperlink.prototype, "field", {
|
|
823
|
+
/**
|
|
824
|
+
* Underlying field when this hyperlink is field-backed.
|
|
825
|
+
*/
|
|
826
|
+
get: function () {
|
|
827
|
+
return this.fieldValue;
|
|
828
|
+
},
|
|
829
|
+
enumerable: true,
|
|
830
|
+
configurable: true
|
|
831
|
+
});
|
|
832
|
+
Object.defineProperty(Hyperlink.prototype, "fieldType", {
|
|
833
|
+
/**
|
|
834
|
+
* Field type when field-backed (used by structure tests).
|
|
835
|
+
*/
|
|
836
|
+
get: function () {
|
|
837
|
+
if (this.fieldValue === undefined) {
|
|
838
|
+
return undefined;
|
|
839
|
+
}
|
|
840
|
+
return this.fieldValue.fieldType;
|
|
841
|
+
},
|
|
842
|
+
enumerable: true,
|
|
843
|
+
configurable: true
|
|
844
|
+
});
|
|
845
|
+
Object.defineProperty(Hyperlink.prototype, "bookmarkName", {
|
|
846
|
+
get: function () {
|
|
847
|
+
if (this.fieldValue === undefined) {
|
|
848
|
+
return this.pictureTypeValue === HyperlinkType.Bookmark ? this.pictureUriValue : '';
|
|
849
|
+
}
|
|
850
|
+
return parseHyperlinkInstruction(this.fieldValue.fieldCode).bookmarkName;
|
|
851
|
+
},
|
|
852
|
+
set: function (value) {
|
|
853
|
+
if (this.fieldValue === undefined) {
|
|
854
|
+
this.pictureUriValue = value;
|
|
855
|
+
this.pictureTypeValue = HyperlinkType.Bookmark;
|
|
856
|
+
return;
|
|
857
|
+
}
|
|
858
|
+
var parsed = parseHyperlinkInstruction(this.fieldValue.fieldCode);
|
|
859
|
+
parsed.bookmarkName = value;
|
|
860
|
+
if (value.trim().length > 0) {
|
|
861
|
+
parsed.type = HyperlinkType.Bookmark;
|
|
862
|
+
}
|
|
863
|
+
this.fieldValue.fieldCode = formatHyperlinkInstruction(parsed);
|
|
864
|
+
},
|
|
865
|
+
enumerable: true,
|
|
866
|
+
configurable: true
|
|
867
|
+
});
|
|
868
|
+
Object.defineProperty(Hyperlink.prototype, "filePath", {
|
|
869
|
+
get: function () {
|
|
870
|
+
if (this.fieldValue === undefined) {
|
|
871
|
+
return this.pictureTypeValue === HyperlinkType.FileLink ? this.pictureUriValue : '';
|
|
872
|
+
}
|
|
873
|
+
var parsed = parseHyperlinkInstruction(this.fieldValue.fieldCode);
|
|
874
|
+
return parsed.type === HyperlinkType.FileLink ? parsed.target : '';
|
|
875
|
+
},
|
|
876
|
+
set: function (value) {
|
|
877
|
+
if (this.fieldValue === undefined) {
|
|
878
|
+
this.pictureUriValue = value;
|
|
879
|
+
this.pictureTypeValue = HyperlinkType.FileLink;
|
|
880
|
+
return;
|
|
881
|
+
}
|
|
882
|
+
var parsed = parseHyperlinkInstruction(this.fieldValue.fieldCode);
|
|
883
|
+
parsed.target = value;
|
|
884
|
+
parsed.type = HyperlinkType.FileLink;
|
|
885
|
+
this.fieldValue.fieldCode = formatHyperlinkInstruction(parsed);
|
|
886
|
+
},
|
|
887
|
+
enumerable: true,
|
|
888
|
+
configurable: true
|
|
889
|
+
});
|
|
890
|
+
Object.defineProperty(Hyperlink.prototype, "localReference", {
|
|
891
|
+
get: function () {
|
|
892
|
+
return this.bookmarkName;
|
|
893
|
+
},
|
|
894
|
+
set: function (value) {
|
|
895
|
+
this.bookmarkName = value;
|
|
896
|
+
},
|
|
897
|
+
enumerable: true,
|
|
898
|
+
configurable: true
|
|
899
|
+
});
|
|
900
|
+
Object.defineProperty(Hyperlink.prototype, "pictureToDisplay", {
|
|
901
|
+
get: function () {
|
|
902
|
+
return this.pictureValue;
|
|
903
|
+
},
|
|
904
|
+
set: function (value) {
|
|
905
|
+
if (this.pictureValue === undefined) {
|
|
906
|
+
throw new DocxError('content/invalid-field', 'pictureToDisplay is only supported on picture-backed hyperlinks');
|
|
907
|
+
}
|
|
908
|
+
if (value === undefined) {
|
|
909
|
+
throw new DocxError('content/invalid-field', 'pictureToDisplay cannot be cleared on a picture-backed hyperlink');
|
|
910
|
+
}
|
|
911
|
+
// Identity is fixed at construction for this phase.
|
|
912
|
+
if (value !== this.pictureValue) {
|
|
913
|
+
throw new DocxError('content/invalid-field', 'pictureToDisplay cannot replace the linked picture in this phase');
|
|
914
|
+
}
|
|
915
|
+
},
|
|
916
|
+
enumerable: true,
|
|
917
|
+
configurable: true
|
|
918
|
+
});
|
|
919
|
+
Object.defineProperty(Hyperlink.prototype, "textToDisplay", {
|
|
920
|
+
get: function () {
|
|
921
|
+
if (this.fieldValue === undefined) {
|
|
922
|
+
return '';
|
|
923
|
+
}
|
|
924
|
+
return this.fieldValue.text;
|
|
925
|
+
},
|
|
926
|
+
set: function (value) {
|
|
927
|
+
if (this.fieldValue === undefined) {
|
|
928
|
+
throw new DocxError('content/invalid-field', 'textToDisplay is not supported on picture-backed hyperlinks');
|
|
929
|
+
}
|
|
930
|
+
this.fieldValue.text = value;
|
|
931
|
+
},
|
|
932
|
+
enumerable: true,
|
|
933
|
+
configurable: true
|
|
934
|
+
});
|
|
935
|
+
Object.defineProperty(Hyperlink.prototype, "type", {
|
|
936
|
+
get: function () {
|
|
937
|
+
if (this.fieldValue === undefined) {
|
|
938
|
+
return this.pictureTypeValue;
|
|
939
|
+
}
|
|
940
|
+
return parseHyperlinkInstruction(this.fieldValue.fieldCode).type;
|
|
941
|
+
},
|
|
942
|
+
set: function (value) {
|
|
943
|
+
if (this.fieldValue === undefined) {
|
|
944
|
+
this.pictureTypeValue = value;
|
|
945
|
+
return;
|
|
946
|
+
}
|
|
947
|
+
var parsed = parseHyperlinkInstruction(this.fieldValue.fieldCode);
|
|
948
|
+
parsed.type = value;
|
|
949
|
+
this.fieldValue.fieldCode = formatHyperlinkInstruction(parsed);
|
|
950
|
+
},
|
|
951
|
+
enumerable: true,
|
|
952
|
+
configurable: true
|
|
953
|
+
});
|
|
954
|
+
Object.defineProperty(Hyperlink.prototype, "uri", {
|
|
955
|
+
get: function () {
|
|
956
|
+
if (this.fieldValue === undefined) {
|
|
957
|
+
if (this.pictureTypeValue === HyperlinkType.Bookmark) {
|
|
958
|
+
return '';
|
|
959
|
+
}
|
|
960
|
+
return this.pictureUriValue;
|
|
961
|
+
}
|
|
962
|
+
var parsed = parseHyperlinkInstruction(this.fieldValue.fieldCode);
|
|
963
|
+
if (parsed.type === HyperlinkType.Bookmark) {
|
|
964
|
+
return '';
|
|
965
|
+
}
|
|
966
|
+
return parsed.target;
|
|
967
|
+
},
|
|
968
|
+
set: function (value) {
|
|
969
|
+
if (this.fieldValue === undefined) {
|
|
970
|
+
this.pictureUriValue = value;
|
|
971
|
+
if (/^mailto:/i.test(value.trim())) {
|
|
972
|
+
this.pictureTypeValue = HyperlinkType.EmailLink;
|
|
973
|
+
}
|
|
974
|
+
else if (this.pictureTypeValue === HyperlinkType.Bookmark) {
|
|
975
|
+
this.pictureTypeValue = HyperlinkType.WebLink;
|
|
976
|
+
}
|
|
977
|
+
if (this.pictureValue !== undefined) {
|
|
978
|
+
this.pictureValue.hyperlinkTarget = value;
|
|
979
|
+
}
|
|
980
|
+
return;
|
|
981
|
+
}
|
|
982
|
+
var parsed = parseHyperlinkInstruction(this.fieldValue.fieldCode);
|
|
983
|
+
parsed.target = value;
|
|
984
|
+
if (/^mailto:/i.test(value.trim())) {
|
|
985
|
+
parsed.type = HyperlinkType.EmailLink;
|
|
986
|
+
}
|
|
987
|
+
else if (parsed.type === HyperlinkType.Bookmark) {
|
|
988
|
+
parsed.type = HyperlinkType.WebLink;
|
|
989
|
+
}
|
|
990
|
+
this.fieldValue.fieldCode = formatHyperlinkInstruction(parsed);
|
|
991
|
+
},
|
|
992
|
+
enumerable: true,
|
|
993
|
+
configurable: true
|
|
994
|
+
});
|
|
995
|
+
return Hyperlink;
|
|
996
|
+
}());
|
|
997
|
+
export { Hyperlink };
|
|
998
|
+
function concatenateRunText(runs) {
|
|
999
|
+
var e_6, _a;
|
|
1000
|
+
var text = '';
|
|
1001
|
+
try {
|
|
1002
|
+
for (var runs_2 = __values(runs), runs_2_1 = runs_2.next(); !runs_2_1.done; runs_2_1 = runs_2.next()) {
|
|
1003
|
+
var run = runs_2_1.value;
|
|
1004
|
+
text += run.text;
|
|
1005
|
+
}
|
|
1006
|
+
}
|
|
1007
|
+
catch (e_6_1) { e_6 = { error: e_6_1 }; }
|
|
1008
|
+
finally {
|
|
1009
|
+
try {
|
|
1010
|
+
if (runs_2_1 && !runs_2_1.done && (_a = runs_2.return)) _a.call(runs_2);
|
|
1011
|
+
}
|
|
1012
|
+
finally { if (e_6) throw e_6.error; }
|
|
1013
|
+
}
|
|
1014
|
+
return text;
|
|
1015
|
+
}
|
|
1016
|
+
function trySupportedFieldTypeFromInstruction(instruction) {
|
|
1017
|
+
var __ts33_1;
|
|
1018
|
+
var token = (((__ts33_1 = tokenizeFieldInstruction(instruction)[0]), __ts33_1 != null ? __ts33_1 : '')).toUpperCase();
|
|
1019
|
+
if (token.length === 0) {
|
|
1020
|
+
return undefined;
|
|
1021
|
+
}
|
|
1022
|
+
return SUPPORTED_FIELD_TYPES.get(token);
|
|
1023
|
+
}
|
|
1024
|
+
function wrapSupportedField(kind, simple, complex, host, instruction) {
|
|
1025
|
+
var type = trySupportedFieldTypeFromInstruction(instruction);
|
|
1026
|
+
if (type === undefined) {
|
|
1027
|
+
return undefined;
|
|
1028
|
+
}
|
|
1029
|
+
if (type === FieldType.If) {
|
|
1030
|
+
return new LegacyIfField(kind, simple, complex, host, type);
|
|
1031
|
+
}
|
|
1032
|
+
if (type === FieldType.MergeField) {
|
|
1033
|
+
return new LegacyMergeField(kind, simple, complex, host, type);
|
|
1034
|
+
}
|
|
1035
|
+
return new LegacyField(kind, simple, complex, host, type);
|
|
1036
|
+
}
|
|
1037
|
+
function parseMergeFieldInstruction(instruction) {
|
|
1038
|
+
var tokens = tokenizeFieldInstruction(instruction);
|
|
1039
|
+
var result = {
|
|
1040
|
+
fieldName: '',
|
|
1041
|
+
textBefore: '',
|
|
1042
|
+
textAfter: '',
|
|
1043
|
+
dateFormat: '',
|
|
1044
|
+
numberFormat: '',
|
|
1045
|
+
otherSwitches: [],
|
|
1046
|
+
};
|
|
1047
|
+
var index = 1;
|
|
1048
|
+
if (tokens.length > 1) {
|
|
1049
|
+
var first = tokens[1];
|
|
1050
|
+
if (first !== undefined && !first.startsWith('\\')) {
|
|
1051
|
+
result.fieldName = first;
|
|
1052
|
+
index = 2;
|
|
1053
|
+
}
|
|
1054
|
+
}
|
|
1055
|
+
while (index < tokens.length) {
|
|
1056
|
+
var token = tokens[index];
|
|
1057
|
+
if (token === undefined) {
|
|
1058
|
+
break;
|
|
1059
|
+
}
|
|
1060
|
+
if (!token.startsWith('\\')) {
|
|
1061
|
+
index += 1;
|
|
1062
|
+
continue;
|
|
1063
|
+
}
|
|
1064
|
+
var next = tokens[index + 1];
|
|
1065
|
+
var hasValue = next !== undefined && !next.startsWith('\\');
|
|
1066
|
+
var value = hasValue ? next : undefined;
|
|
1067
|
+
var flag = token.toLowerCase();
|
|
1068
|
+
if (flag === '\\b') {
|
|
1069
|
+
result.textBefore = value != null ? value : '';
|
|
1070
|
+
}
|
|
1071
|
+
else if (flag === '\\f') {
|
|
1072
|
+
result.textAfter = value != null ? value : '';
|
|
1073
|
+
}
|
|
1074
|
+
else if (flag === '\\@') {
|
|
1075
|
+
result.dateFormat = value != null ? value : '';
|
|
1076
|
+
}
|
|
1077
|
+
else if (flag === '\\#') {
|
|
1078
|
+
result.numberFormat = value != null ? value : '';
|
|
1079
|
+
}
|
|
1080
|
+
else {
|
|
1081
|
+
result.otherSwitches.push({ flag: token, value: value });
|
|
1082
|
+
}
|
|
1083
|
+
index += hasValue ? 2 : 1;
|
|
1084
|
+
}
|
|
1085
|
+
return result;
|
|
1086
|
+
}
|
|
1087
|
+
function quoteFieldOperand(value) {
|
|
1088
|
+
if (value.length === 0) {
|
|
1089
|
+
return '""';
|
|
1090
|
+
}
|
|
1091
|
+
if (/[\s"]/.test(value)) {
|
|
1092
|
+
return '"' + value.replace(/"/g, '') + '"';
|
|
1093
|
+
}
|
|
1094
|
+
return value;
|
|
1095
|
+
}
|
|
1096
|
+
function formatMergeFieldInstruction(parsed) {
|
|
1097
|
+
var code = ' MERGEFIELD ' + parsed.fieldName;
|
|
1098
|
+
if (parsed.textBefore.length > 0) {
|
|
1099
|
+
code += ' \\b ' + quoteFieldOperand(parsed.textBefore);
|
|
1100
|
+
}
|
|
1101
|
+
if (parsed.textAfter.length > 0) {
|
|
1102
|
+
code += ' \\f ' + quoteFieldOperand(parsed.textAfter);
|
|
1103
|
+
}
|
|
1104
|
+
if (parsed.dateFormat.length > 0) {
|
|
1105
|
+
code += ' \\@ ' + quoteFieldOperand(parsed.dateFormat);
|
|
1106
|
+
}
|
|
1107
|
+
if (parsed.numberFormat.length > 0) {
|
|
1108
|
+
code += ' \\# ' + quoteFieldOperand(parsed.numberFormat);
|
|
1109
|
+
}
|
|
1110
|
+
for (var i = 0; i < parsed.otherSwitches.length; i += 1) {
|
|
1111
|
+
var sw = parsed.otherSwitches[i];
|
|
1112
|
+
code += ' ' + sw.flag;
|
|
1113
|
+
if (sw.value !== undefined) {
|
|
1114
|
+
code += ' ' + quoteFieldOperand(sw.value);
|
|
1115
|
+
}
|
|
1116
|
+
}
|
|
1117
|
+
return code + ' ';
|
|
1118
|
+
}
|
|
1119
|
+
function detectHyperlinkType(target, bookmarkName) {
|
|
1120
|
+
if (bookmarkName.trim().length > 0 && target.trim().length === 0) {
|
|
1121
|
+
return HyperlinkType.Bookmark;
|
|
1122
|
+
}
|
|
1123
|
+
var t = target.trim();
|
|
1124
|
+
if (/^mailto:/i.test(t)) {
|
|
1125
|
+
return HyperlinkType.EmailLink;
|
|
1126
|
+
}
|
|
1127
|
+
if (/^[a-zA-Z]:[\\/]/.test(t) || t.indexOf('\\') >= 0 || /^file:/i.test(t)) {
|
|
1128
|
+
return HyperlinkType.FileLink;
|
|
1129
|
+
}
|
|
1130
|
+
if (bookmarkName.trim().length > 0) {
|
|
1131
|
+
return HyperlinkType.Bookmark;
|
|
1132
|
+
}
|
|
1133
|
+
return HyperlinkType.WebLink;
|
|
1134
|
+
}
|
|
1135
|
+
function parseHyperlinkInstruction(instruction) {
|
|
1136
|
+
var tokens = tokenizeFieldInstruction(instruction);
|
|
1137
|
+
var result = {
|
|
1138
|
+
type: HyperlinkType.WebLink,
|
|
1139
|
+
target: '',
|
|
1140
|
+
bookmarkName: '',
|
|
1141
|
+
otherSwitches: [],
|
|
1142
|
+
};
|
|
1143
|
+
var index = 1;
|
|
1144
|
+
if (tokens.length > 1) {
|
|
1145
|
+
var first = tokens[1];
|
|
1146
|
+
if (first !== undefined && !first.startsWith('\\')) {
|
|
1147
|
+
result.target = first;
|
|
1148
|
+
index = 2;
|
|
1149
|
+
}
|
|
1150
|
+
}
|
|
1151
|
+
while (index < tokens.length) {
|
|
1152
|
+
var token = tokens[index];
|
|
1153
|
+
if (token === undefined) {
|
|
1154
|
+
break;
|
|
1155
|
+
}
|
|
1156
|
+
if (!token.startsWith('\\')) {
|
|
1157
|
+
index += 1;
|
|
1158
|
+
continue;
|
|
1159
|
+
}
|
|
1160
|
+
var next = tokens[index + 1];
|
|
1161
|
+
var hasValue = next !== undefined && !next.startsWith('\\');
|
|
1162
|
+
var value = hasValue ? next : undefined;
|
|
1163
|
+
var flag = token.toLowerCase();
|
|
1164
|
+
if (flag === '\\l') {
|
|
1165
|
+
result.bookmarkName = value != null ? value : '';
|
|
1166
|
+
}
|
|
1167
|
+
else {
|
|
1168
|
+
result.otherSwitches.push({ flag: token, value: value });
|
|
1169
|
+
}
|
|
1170
|
+
index += hasValue ? 2 : 1;
|
|
1171
|
+
}
|
|
1172
|
+
result.type = detectHyperlinkType(result.target, result.bookmarkName);
|
|
1173
|
+
return result;
|
|
1174
|
+
}
|
|
1175
|
+
function formatHyperlinkInstruction(parsed) {
|
|
1176
|
+
var code = ' HYPERLINK';
|
|
1177
|
+
if (parsed.type === HyperlinkType.Bookmark) {
|
|
1178
|
+
if (parsed.target.trim().length > 0) {
|
|
1179
|
+
code += ' ' + quoteFieldOperand(parsed.target);
|
|
1180
|
+
}
|
|
1181
|
+
if (parsed.bookmarkName.trim().length > 0) {
|
|
1182
|
+
code += ' \\l ' + quoteFieldOperand(parsed.bookmarkName);
|
|
1183
|
+
}
|
|
1184
|
+
}
|
|
1185
|
+
else {
|
|
1186
|
+
if (parsed.target.trim().length > 0) {
|
|
1187
|
+
code += ' ' + quoteFieldOperand(parsed.target);
|
|
1188
|
+
}
|
|
1189
|
+
if (parsed.bookmarkName.trim().length > 0) {
|
|
1190
|
+
code += ' \\l ' + quoteFieldOperand(parsed.bookmarkName);
|
|
1191
|
+
}
|
|
1192
|
+
}
|
|
1193
|
+
for (var i = 0; i < parsed.otherSwitches.length; i += 1) {
|
|
1194
|
+
var sw = parsed.otherSwitches[i];
|
|
1195
|
+
code += ' ' + sw.flag;
|
|
1196
|
+
if (sw.value !== undefined) {
|
|
1197
|
+
code += ' ' + quoteFieldOperand(sw.value);
|
|
1198
|
+
}
|
|
1199
|
+
}
|
|
1200
|
+
return code + ' ';
|
|
1201
|
+
}
|
|
1202
|
+
function firstWmlChild(parent, localName) {
|
|
1203
|
+
var e_7, _a;
|
|
1204
|
+
try {
|
|
1205
|
+
for (var _b = __values(elementChildren(parent)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
1206
|
+
var child = _c.value;
|
|
1207
|
+
if (isWml(child, localName)) {
|
|
1208
|
+
return child;
|
|
1209
|
+
}
|
|
1210
|
+
}
|
|
1211
|
+
}
|
|
1212
|
+
catch (e_7_1) { e_7 = { error: e_7_1 }; }
|
|
1213
|
+
finally {
|
|
1214
|
+
try {
|
|
1215
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
1216
|
+
}
|
|
1217
|
+
finally { if (e_7) throw e_7.error; }
|
|
1218
|
+
}
|
|
1219
|
+
return undefined;
|
|
1220
|
+
}
|
|
1221
|
+
function firstChildVal(parent, localName) {
|
|
1222
|
+
var child = firstWmlChild(parent, localName);
|
|
1223
|
+
return child === undefined ? undefined : wValAttribute(child);
|
|
1224
|
+
}
|
|
1225
|
+
function firstChildOnOff(parent, localName) {
|
|
1226
|
+
var child = firstWmlChild(parent, localName);
|
|
1227
|
+
return child === undefined ? undefined : parseOnOff(child);
|
|
1228
|
+
}
|
|
1229
|
+
function firstChildDecimal(parent, localName) {
|
|
1230
|
+
var raw = firstChildVal(parent, localName);
|
|
1231
|
+
return parseDecimalNumber(raw);
|
|
1232
|
+
}
|
|
1233
|
+
function nestedChildVal(parent, nestLocalName, childLocalName) {
|
|
1234
|
+
var nest = firstWmlChild(parent, nestLocalName);
|
|
1235
|
+
return nest === undefined ? undefined : firstChildVal(nest, childLocalName);
|
|
1236
|
+
}
|
|
1237
|
+
function nestedChildOnOff(parent, nestLocalName, childLocalName) {
|
|
1238
|
+
var nest = firstWmlChild(parent, nestLocalName);
|
|
1239
|
+
return nest === undefined ? undefined : firstChildOnOff(nest, childLocalName);
|
|
1240
|
+
}
|
|
1241
|
+
function nestedChildDecimal(parent, nestLocalName, childLocalName) {
|
|
1242
|
+
var nest = firstWmlChild(parent, nestLocalName);
|
|
1243
|
+
return nest === undefined ? undefined : firstChildDecimal(nest, childLocalName);
|
|
1244
|
+
}
|
|
1245
|
+
function parseDecimalNumber(raw) {
|
|
1246
|
+
if (raw === undefined || raw.length === 0) {
|
|
1247
|
+
return undefined;
|
|
1248
|
+
}
|
|
1249
|
+
if (!/^-?\d+$/.test(raw.trim())) {
|
|
1250
|
+
return undefined;
|
|
1251
|
+
}
|
|
1252
|
+
var value = Number(raw.trim());
|
|
1253
|
+
return Number.isSafeInteger(value) ? value : undefined;
|
|
1254
|
+
}
|
|
1255
|
+
function formFieldKindFromFfData(data) {
|
|
1256
|
+
var e_8, _a;
|
|
1257
|
+
try {
|
|
1258
|
+
// CT_FFData ends with a choice of one of checkBox | ddList | textInput.
|
|
1259
|
+
// Prefer the first exclusive child found in document order.
|
|
1260
|
+
for (var _b = __values(elementChildren(data)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
1261
|
+
var child = _c.value;
|
|
1262
|
+
if (isWml(child, 'textInput')) {
|
|
1263
|
+
return 'textInput';
|
|
1264
|
+
}
|
|
1265
|
+
if (isWml(child, 'checkBox')) {
|
|
1266
|
+
return 'checkBox';
|
|
1267
|
+
}
|
|
1268
|
+
if (isWml(child, 'ddList')) {
|
|
1269
|
+
return 'dropDown';
|
|
1270
|
+
}
|
|
1271
|
+
}
|
|
1272
|
+
}
|
|
1273
|
+
catch (e_8_1) { e_8 = { error: e_8_1 }; }
|
|
1274
|
+
finally {
|
|
1275
|
+
try {
|
|
1276
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
1277
|
+
}
|
|
1278
|
+
finally { if (e_8) throw e_8.error; }
|
|
1279
|
+
}
|
|
1280
|
+
return undefined;
|
|
1281
|
+
}
|
|
1282
|
+
function ffDataFromFieldMark(fieldMark) {
|
|
1283
|
+
var e_9, _a;
|
|
1284
|
+
try {
|
|
1285
|
+
for (var _b = __values(fieldMark.childElements()), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
1286
|
+
var child = _c.value;
|
|
1287
|
+
if (isWml(child, 'ffData')) {
|
|
1288
|
+
return child;
|
|
1289
|
+
}
|
|
1290
|
+
}
|
|
1291
|
+
}
|
|
1292
|
+
catch (e_9_1) { e_9 = { error: e_9_1 }; }
|
|
1293
|
+
finally {
|
|
1294
|
+
try {
|
|
1295
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
1296
|
+
}
|
|
1297
|
+
finally { if (e_9) throw e_9.error; }
|
|
1298
|
+
}
|
|
1299
|
+
return undefined;
|
|
1300
|
+
}
|
|
1301
|
+
/**
|
|
1302
|
+
* Build a {@link FormField} view when the begin marker hosts typed `w:ffData`.
|
|
1303
|
+
*
|
|
1304
|
+
* @private
|
|
1305
|
+
*/
|
|
1306
|
+
function tryFormFieldFromBegin(beginMark, complex) {
|
|
1307
|
+
if (beginMark.fldCharType !== 'begin') {
|
|
1308
|
+
return undefined;
|
|
1309
|
+
}
|
|
1310
|
+
var data = ffDataFromFieldMark(beginMark);
|
|
1311
|
+
if (data === undefined) {
|
|
1312
|
+
return undefined;
|
|
1313
|
+
}
|
|
1314
|
+
var kind = formFieldKindFromFfData(data);
|
|
1315
|
+
if (kind === undefined) {
|
|
1316
|
+
return undefined;
|
|
1317
|
+
}
|
|
1318
|
+
return new FormField(beginMark, data, kind, complex);
|
|
1319
|
+
}
|
|
1320
|
+
function parseSimpleField(element) {
|
|
1321
|
+
var e_10, _a;
|
|
1322
|
+
if (!isWml(element, 'fldSimple')) {
|
|
1323
|
+
return undefined;
|
|
1324
|
+
}
|
|
1325
|
+
var instruction = wmlAttribute(element, 'instr');
|
|
1326
|
+
if (instruction === undefined || instruction.length === 0) {
|
|
1327
|
+
return undefined;
|
|
1328
|
+
}
|
|
1329
|
+
var runOwner = new SimpleFieldRunOwner();
|
|
1330
|
+
var extras = [];
|
|
1331
|
+
var items = [];
|
|
1332
|
+
var parsedRuns = [];
|
|
1333
|
+
try {
|
|
1334
|
+
for (var _b = __values(elementChildren(element)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
1335
|
+
var child = _c.value;
|
|
1336
|
+
if (isWml(child, 'fldData')) {
|
|
1337
|
+
extras.push(child);
|
|
1338
|
+
continue;
|
|
1339
|
+
}
|
|
1340
|
+
if (isWml(child, 'r')) {
|
|
1341
|
+
var run = TextRange.fromXml(child, runOwner);
|
|
1342
|
+
parsedRuns.push(run);
|
|
1343
|
+
items.push({ type: 'textRange', run: run });
|
|
1344
|
+
continue;
|
|
1345
|
+
}
|
|
1346
|
+
extras.push(child);
|
|
1347
|
+
items.push({ type: 'opaque', xml: child });
|
|
1348
|
+
}
|
|
1349
|
+
}
|
|
1350
|
+
catch (e_10_1) { e_10 = { error: e_10_1 }; }
|
|
1351
|
+
finally {
|
|
1352
|
+
try {
|
|
1353
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
1354
|
+
}
|
|
1355
|
+
finally { if (e_10) throw e_10.error; }
|
|
1356
|
+
}
|
|
1357
|
+
runOwner.hydrateRuns(parsedRuns);
|
|
1358
|
+
return new SimpleField(runOwner, extras, items, instruction, parseOnOffAttribute(wmlAttribute(element, 'fldLock')), parseOnOffAttribute(wmlAttribute(element, 'dirty')));
|
|
1359
|
+
}
|
|
1360
|
+
function parseFieldMark(element) {
|
|
1361
|
+
var e_11, _a;
|
|
1362
|
+
if (!isWml(element, 'fldChar')) {
|
|
1363
|
+
return undefined;
|
|
1364
|
+
}
|
|
1365
|
+
var fldCharType = parseFieldMarkType(wmlAttribute(element, 'fldCharType'));
|
|
1366
|
+
if (fldCharType === undefined) {
|
|
1367
|
+
return undefined;
|
|
1368
|
+
}
|
|
1369
|
+
var extras = [];
|
|
1370
|
+
try {
|
|
1371
|
+
for (var _b = __values(elementChildren(element)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
1372
|
+
var child = _c.value;
|
|
1373
|
+
extras.push(child);
|
|
1374
|
+
}
|
|
1375
|
+
}
|
|
1376
|
+
catch (e_11_1) { e_11 = { error: e_11_1 }; }
|
|
1377
|
+
finally {
|
|
1378
|
+
try {
|
|
1379
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
1380
|
+
}
|
|
1381
|
+
finally { if (e_11) throw e_11.error; }
|
|
1382
|
+
}
|
|
1383
|
+
return new FieldMark(fldCharType, parseOnOffAttribute(wmlAttribute(element, 'fldLock')), parseOnOffAttribute(wmlAttribute(element, 'dirty')), extras);
|
|
1384
|
+
}
|
|
1385
|
+
function parseOnOffAttribute(raw) {
|
|
1386
|
+
if (raw === undefined || raw === '0' || raw === 'false') {
|
|
1387
|
+
return raw === undefined ? undefined : false;
|
|
1388
|
+
}
|
|
1389
|
+
return true;
|
|
1390
|
+
}
|
|
1391
|
+
function parseInstrText(element) {
|
|
1392
|
+
if (!isWml(element, 'instrText')) {
|
|
1393
|
+
return undefined;
|
|
1394
|
+
}
|
|
1395
|
+
return new InstrText(textContent(element), xmlSpaceIsPreserve(element));
|
|
1396
|
+
}
|
|
1397
|
+
function flattenFieldItems(paragraph) {
|
|
1398
|
+
var e_12, _a;
|
|
1399
|
+
var flat = [];
|
|
1400
|
+
try {
|
|
1401
|
+
for (var _b = __values(paragraph.items), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
1402
|
+
var item = _c.value;
|
|
1403
|
+
if (item instanceof TextRange) {
|
|
1404
|
+
flat.push({ item: item });
|
|
1405
|
+
continue;
|
|
1406
|
+
}
|
|
1407
|
+
if (item instanceof FeatureRunParagraphItem &&
|
|
1408
|
+
item.featureId === FIELDS &&
|
|
1409
|
+
(item.value instanceof FieldMark || item.value instanceof InstrText)) {
|
|
1410
|
+
flat.push({ item: item });
|
|
1411
|
+
continue;
|
|
1412
|
+
}
|
|
1413
|
+
// Other paragraph content (tabs/breaks/images/featureInline) is skipped for pairing.
|
|
1414
|
+
}
|
|
1415
|
+
}
|
|
1416
|
+
catch (e_12_1) { e_12 = { error: e_12_1 }; }
|
|
1417
|
+
finally {
|
|
1418
|
+
try {
|
|
1419
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
1420
|
+
}
|
|
1421
|
+
finally { if (e_12) throw e_12.error; }
|
|
1422
|
+
}
|
|
1423
|
+
return flat;
|
|
1424
|
+
}
|
|
1425
|
+
function instructionFromItems(items, start, end) {
|
|
1426
|
+
var instruction = '';
|
|
1427
|
+
for (var index = start; index < end; index += 1) {
|
|
1428
|
+
var entry = items[index];
|
|
1429
|
+
if (entry === undefined) {
|
|
1430
|
+
continue;
|
|
1431
|
+
}
|
|
1432
|
+
var item = entry.item;
|
|
1433
|
+
if (item instanceof FeatureRunParagraphItem && item.value instanceof InstrText) {
|
|
1434
|
+
instruction += item.value.text;
|
|
1435
|
+
}
|
|
1436
|
+
}
|
|
1437
|
+
return instruction.trim();
|
|
1438
|
+
}
|
|
1439
|
+
function pairComplexField(flat, beginIndex) {
|
|
1440
|
+
var begin = flat[beginIndex];
|
|
1441
|
+
if (begin === undefined ||
|
|
1442
|
+
!(begin.item instanceof FeatureRunParagraphItem) ||
|
|
1443
|
+
!(begin.item.value instanceof FieldMark) ||
|
|
1444
|
+
begin.item.value.fldCharType !== 'begin') {
|
|
1445
|
+
return undefined;
|
|
1446
|
+
}
|
|
1447
|
+
var markerValues = [begin.item.value];
|
|
1448
|
+
var instructionTexts = [];
|
|
1449
|
+
var separateIndex = -1;
|
|
1450
|
+
var depth = 1;
|
|
1451
|
+
for (var index = beginIndex + 1; index < flat.length; index += 1) {
|
|
1452
|
+
var entry = flat[index];
|
|
1453
|
+
if (entry === undefined) {
|
|
1454
|
+
return undefined;
|
|
1455
|
+
}
|
|
1456
|
+
var item = entry.item;
|
|
1457
|
+
if (item instanceof FeatureRunParagraphItem && item.value instanceof FieldMark) {
|
|
1458
|
+
var mark = item.value;
|
|
1459
|
+
if (mark.fldCharType === 'begin') {
|
|
1460
|
+
depth += 1;
|
|
1461
|
+
markerValues.push(mark);
|
|
1462
|
+
continue;
|
|
1463
|
+
}
|
|
1464
|
+
if (mark.fldCharType === 'end') {
|
|
1465
|
+
depth -= 1;
|
|
1466
|
+
if (depth === 0) {
|
|
1467
|
+
// End before separate — incomplete outer field.
|
|
1468
|
+
return undefined;
|
|
1469
|
+
}
|
|
1470
|
+
markerValues.push(mark);
|
|
1471
|
+
continue;
|
|
1472
|
+
}
|
|
1473
|
+
if (mark.fldCharType === 'separate' && depth === 1) {
|
|
1474
|
+
separateIndex = index;
|
|
1475
|
+
markerValues.push(mark);
|
|
1476
|
+
break;
|
|
1477
|
+
}
|
|
1478
|
+
markerValues.push(mark);
|
|
1479
|
+
continue;
|
|
1480
|
+
}
|
|
1481
|
+
if (depth === 1 && item instanceof FeatureRunParagraphItem && item.value instanceof InstrText) {
|
|
1482
|
+
instructionTexts.push(item.value);
|
|
1483
|
+
markerValues.push(item.value);
|
|
1484
|
+
}
|
|
1485
|
+
else if (item instanceof FeatureRunParagraphItem && item.value instanceof InstrText) {
|
|
1486
|
+
markerValues.push(item.value);
|
|
1487
|
+
}
|
|
1488
|
+
}
|
|
1489
|
+
if (separateIndex < 0) {
|
|
1490
|
+
return undefined;
|
|
1491
|
+
}
|
|
1492
|
+
var instruction = instructionFromItems(flat, beginIndex + 1, separateIndex);
|
|
1493
|
+
// Nested spans may leave empty outer instruction text; still require non-empty for ComplexField views.
|
|
1494
|
+
if (instruction.length === 0) {
|
|
1495
|
+
return undefined;
|
|
1496
|
+
}
|
|
1497
|
+
var resultRuns = [];
|
|
1498
|
+
var endIndex = -1;
|
|
1499
|
+
depth = 1;
|
|
1500
|
+
for (var index = separateIndex + 1; index < flat.length; index += 1) {
|
|
1501
|
+
var entry = flat[index];
|
|
1502
|
+
if (entry === undefined) {
|
|
1503
|
+
return undefined;
|
|
1504
|
+
}
|
|
1505
|
+
var item = entry.item;
|
|
1506
|
+
if (item instanceof FeatureRunParagraphItem && item.value instanceof FieldMark) {
|
|
1507
|
+
var mark = item.value;
|
|
1508
|
+
if (mark.fldCharType === 'begin') {
|
|
1509
|
+
depth += 1;
|
|
1510
|
+
markerValues.push(mark);
|
|
1511
|
+
continue;
|
|
1512
|
+
}
|
|
1513
|
+
if (mark.fldCharType === 'end') {
|
|
1514
|
+
depth -= 1;
|
|
1515
|
+
if (depth === 0) {
|
|
1516
|
+
endIndex = index;
|
|
1517
|
+
markerValues.push(mark);
|
|
1518
|
+
break;
|
|
1519
|
+
}
|
|
1520
|
+
markerValues.push(mark);
|
|
1521
|
+
continue;
|
|
1522
|
+
}
|
|
1523
|
+
markerValues.push(mark);
|
|
1524
|
+
continue;
|
|
1525
|
+
}
|
|
1526
|
+
if (depth === 1 && item instanceof TextRange) {
|
|
1527
|
+
resultRuns.push(item);
|
|
1528
|
+
}
|
|
1529
|
+
}
|
|
1530
|
+
if (endIndex < 0 || resultRuns.length === 0) {
|
|
1531
|
+
return undefined;
|
|
1532
|
+
}
|
|
1533
|
+
return new ComplexField(instruction, resultRuns, markerValues, instructionTexts);
|
|
1534
|
+
}
|
|
1535
|
+
var registered = false;
|
|
1536
|
+
/**
|
|
1537
|
+
* @private
|
|
1538
|
+
* Test hook */
|
|
1539
|
+
export function resetFieldsFeatureForTests() {
|
|
1540
|
+
registered = false;
|
|
1541
|
+
}
|
|
1542
|
+
/**
|
|
1543
|
+
* @private
|
|
1544
|
+
* Register field inline and run-leaf handlers. Idempotent. */
|
|
1545
|
+
export function registerFieldsFeature() {
|
|
1546
|
+
if (registered) {
|
|
1547
|
+
return;
|
|
1548
|
+
}
|
|
1549
|
+
registered = true;
|
|
1550
|
+
registerFeature({ id: FIELDS });
|
|
1551
|
+
registerFeatureInlineHandler({
|
|
1552
|
+
featureId: FIELDS,
|
|
1553
|
+
wmlLocalName: 'fldSimple',
|
|
1554
|
+
tryParse: function (element) {
|
|
1555
|
+
return parseSimpleField(element);
|
|
1556
|
+
},
|
|
1557
|
+
});
|
|
1558
|
+
registerFeatureRunLeafHandler({
|
|
1559
|
+
featureId: FIELDS,
|
|
1560
|
+
wmlLocalName: 'fldChar',
|
|
1561
|
+
tryParse: function (element) {
|
|
1562
|
+
return parseFieldMark(element);
|
|
1563
|
+
},
|
|
1564
|
+
});
|
|
1565
|
+
registerFeatureRunLeafHandler({
|
|
1566
|
+
featureId: FIELDS,
|
|
1567
|
+
wmlLocalName: 'instrText',
|
|
1568
|
+
tryParse: function (element) {
|
|
1569
|
+
return parseInstrText(element);
|
|
1570
|
+
},
|
|
1571
|
+
});
|
|
1572
|
+
}
|
|
1573
|
+
/**
|
|
1574
|
+
* Simple fields in a paragraph, in document order.
|
|
1575
|
+
*
|
|
1576
|
+
* @private
|
|
1577
|
+
*/
|
|
1578
|
+
function simpleFieldsInParagraph(paragraph) {
|
|
1579
|
+
var e_13, _a;
|
|
1580
|
+
var found = [];
|
|
1581
|
+
try {
|
|
1582
|
+
for (var _b = __values(paragraph.items), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
1583
|
+
var inline = _c.value;
|
|
1584
|
+
if (isSimpleFieldInline(inline)) {
|
|
1585
|
+
found.push(inline.value);
|
|
1586
|
+
}
|
|
1587
|
+
}
|
|
1588
|
+
}
|
|
1589
|
+
catch (e_13_1) { e_13 = { error: e_13_1 }; }
|
|
1590
|
+
finally {
|
|
1591
|
+
try {
|
|
1592
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
1593
|
+
}
|
|
1594
|
+
finally { if (e_13) throw e_13.error; }
|
|
1595
|
+
}
|
|
1596
|
+
return found;
|
|
1597
|
+
}
|
|
1598
|
+
/**
|
|
1599
|
+
* Complex fields in a paragraph, in document order.
|
|
1600
|
+
*
|
|
1601
|
+
* @private
|
|
1602
|
+
*/
|
|
1603
|
+
function complexFieldsInParagraph(paragraph) {
|
|
1604
|
+
var found = [];
|
|
1605
|
+
var flat = flattenFieldItems(paragraph);
|
|
1606
|
+
for (var index = 0; index < flat.length; index += 1) {
|
|
1607
|
+
var entry = flat[index];
|
|
1608
|
+
if (entry === undefined ||
|
|
1609
|
+
!(entry.item instanceof FeatureRunParagraphItem) ||
|
|
1610
|
+
!(entry.item.value instanceof FieldMark) ||
|
|
1611
|
+
entry.item.value.fldCharType !== 'begin') {
|
|
1612
|
+
continue;
|
|
1613
|
+
}
|
|
1614
|
+
var field = pairComplexField(flat, index);
|
|
1615
|
+
if (field !== undefined) {
|
|
1616
|
+
found.push(field);
|
|
1617
|
+
}
|
|
1618
|
+
}
|
|
1619
|
+
return found;
|
|
1620
|
+
}
|
|
1621
|
+
/**
|
|
1622
|
+
* Legacy form fields in a paragraph, in document order.
|
|
1623
|
+
*
|
|
1624
|
+
* A form field is detected whenever a begin {@link FieldMark} hosts `w:ffData`
|
|
1625
|
+
* with a typed control child (`textInput` / `checkBox` / `ddList`). Detection
|
|
1626
|
+
* does **not** require a complete complex-field pair (separate + result + end),
|
|
1627
|
+
* so incomplete markers still surface as {@link FormField} views.
|
|
1628
|
+
*
|
|
1629
|
+
* @private
|
|
1630
|
+
*/
|
|
1631
|
+
export function formFieldsInParagraph(paragraph) {
|
|
1632
|
+
var found = [];
|
|
1633
|
+
var flat = flattenFieldItems(paragraph);
|
|
1634
|
+
for (var index = 0; index < flat.length; index += 1) {
|
|
1635
|
+
var entry = flat[index];
|
|
1636
|
+
if (entry === undefined ||
|
|
1637
|
+
!(entry.item instanceof FeatureRunParagraphItem) ||
|
|
1638
|
+
!(entry.item.value instanceof FieldMark) ||
|
|
1639
|
+
entry.item.value.fldCharType !== 'begin') {
|
|
1640
|
+
continue;
|
|
1641
|
+
}
|
|
1642
|
+
var complex = pairComplexField(flat, index);
|
|
1643
|
+
var form = tryFormFieldFromBegin(entry.item.value, complex);
|
|
1644
|
+
if (form !== undefined) {
|
|
1645
|
+
found.push(form);
|
|
1646
|
+
}
|
|
1647
|
+
}
|
|
1648
|
+
return found;
|
|
1649
|
+
}
|
|
1650
|
+
/**
|
|
1651
|
+
* Tokenize a field instruction into whitespace- and quote-delimited tokens.
|
|
1652
|
+
* Double-quoted spans become a single token with the quotes removed.
|
|
1653
|
+
*/
|
|
1654
|
+
function tokenizeFieldInstruction(instruction) {
|
|
1655
|
+
var tokens = [];
|
|
1656
|
+
var source = instruction.trim();
|
|
1657
|
+
var index = 0;
|
|
1658
|
+
while (index < source.length) {
|
|
1659
|
+
while (index < source.length) {
|
|
1660
|
+
var ch = source[index];
|
|
1661
|
+
if (ch === undefined || !/\s/.test(ch)) {
|
|
1662
|
+
break;
|
|
1663
|
+
}
|
|
1664
|
+
index += 1;
|
|
1665
|
+
}
|
|
1666
|
+
if (index >= source.length) {
|
|
1667
|
+
break;
|
|
1668
|
+
}
|
|
1669
|
+
var startChar = source[index];
|
|
1670
|
+
if (startChar === '"') {
|
|
1671
|
+
index += 1;
|
|
1672
|
+
var value = '';
|
|
1673
|
+
while (index < source.length) {
|
|
1674
|
+
var ch = source[index];
|
|
1675
|
+
if (ch === undefined || ch === '"') {
|
|
1676
|
+
break;
|
|
1677
|
+
}
|
|
1678
|
+
value += ch;
|
|
1679
|
+
index += 1;
|
|
1680
|
+
}
|
|
1681
|
+
if (index < source.length && source[index] === '"') {
|
|
1682
|
+
index += 1;
|
|
1683
|
+
}
|
|
1684
|
+
tokens.push(value);
|
|
1685
|
+
continue;
|
|
1686
|
+
}
|
|
1687
|
+
var token = '';
|
|
1688
|
+
while (index < source.length) {
|
|
1689
|
+
var ch = source[index];
|
|
1690
|
+
if (ch === undefined || /\s/.test(ch) || ch === '"') {
|
|
1691
|
+
break;
|
|
1692
|
+
}
|
|
1693
|
+
token += ch;
|
|
1694
|
+
index += 1;
|
|
1695
|
+
}
|
|
1696
|
+
if (token.length > 0) {
|
|
1697
|
+
tokens.push(token);
|
|
1698
|
+
}
|
|
1699
|
+
}
|
|
1700
|
+
return tokens;
|
|
1701
|
+
}
|
|
1702
|
+
/**
|
|
1703
|
+
* Parse a field instruction into {@link ParsedField}.
|
|
1704
|
+
*
|
|
1705
|
+
* @private
|
|
1706
|
+
*/
|
|
1707
|
+
function parseFieldInstruction(instruction) {
|
|
1708
|
+
var tokens = tokenizeFieldInstruction(instruction);
|
|
1709
|
+
var type = tokens[0] != null ? tokens[0] : '';
|
|
1710
|
+
var switches = new Map();
|
|
1711
|
+
var index = 1;
|
|
1712
|
+
while (index < tokens.length) {
|
|
1713
|
+
var token = tokens[index];
|
|
1714
|
+
if (token === undefined) {
|
|
1715
|
+
break;
|
|
1716
|
+
}
|
|
1717
|
+
if (token.startsWith('\\')) {
|
|
1718
|
+
var next = tokens[index + 1];
|
|
1719
|
+
if (next !== undefined && !next.startsWith('\\')) {
|
|
1720
|
+
switches.set(token, next);
|
|
1721
|
+
index += 2;
|
|
1722
|
+
}
|
|
1723
|
+
else {
|
|
1724
|
+
switches.set(token, '');
|
|
1725
|
+
index += 1;
|
|
1726
|
+
}
|
|
1727
|
+
continue;
|
|
1728
|
+
}
|
|
1729
|
+
// Positional operand (MERGEFIELD name, HYPERLINK target, …) — not a switch.
|
|
1730
|
+
index += 1;
|
|
1731
|
+
}
|
|
1732
|
+
return { type: type, instruction: instruction, switches: switches };
|
|
1733
|
+
}
|
|
1734
|
+
/**
|
|
1735
|
+
* Fields in a paragraph, in document order.
|
|
1736
|
+
*
|
|
1737
|
+
* Simple fields (`w:fldSimple`) and complex field spans (`w:fldChar` /
|
|
1738
|
+
* `w:instrText`) are interleaved by paragraph content order. Cached results are
|
|
1739
|
+
* not recalculated.
|
|
1740
|
+
*
|
|
1741
|
+
* @private
|
|
1742
|
+
*/
|
|
1743
|
+
export function fieldsInParagraph(paragraph) {
|
|
1744
|
+
var e_14, _a;
|
|
1745
|
+
var found = [];
|
|
1746
|
+
var flat = flattenFieldItems(paragraph);
|
|
1747
|
+
var flatIndex = 0;
|
|
1748
|
+
try {
|
|
1749
|
+
for (var _b = __values(paragraph.items), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
1750
|
+
var inline = _c.value;
|
|
1751
|
+
if (inline instanceof Field) {
|
|
1752
|
+
found.push(inline);
|
|
1753
|
+
continue;
|
|
1754
|
+
}
|
|
1755
|
+
if (isSimpleFieldInline(inline)) {
|
|
1756
|
+
var wrapped = wrapSupportedField('simple', inline.value, undefined, paragraph, inline.value.instruction);
|
|
1757
|
+
if (wrapped !== undefined) {
|
|
1758
|
+
found.push(wrapped);
|
|
1759
|
+
}
|
|
1760
|
+
continue;
|
|
1761
|
+
}
|
|
1762
|
+
// Only field-relevant items advance the flatten cursor (TextRange + FIELDS featureRun).
|
|
1763
|
+
var isFieldFlatItem = inline instanceof TextRange ||
|
|
1764
|
+
(inline instanceof FeatureRunParagraphItem &&
|
|
1765
|
+
inline.featureId === FIELDS &&
|
|
1766
|
+
(inline.value instanceof FieldMark || inline.value instanceof InstrText));
|
|
1767
|
+
if (!isFieldFlatItem) {
|
|
1768
|
+
continue;
|
|
1769
|
+
}
|
|
1770
|
+
var beginIndex = flatIndex;
|
|
1771
|
+
flatIndex += 1;
|
|
1772
|
+
var entry = flat[beginIndex];
|
|
1773
|
+
if (entry === undefined ||
|
|
1774
|
+
!(entry.item instanceof FeatureRunParagraphItem) ||
|
|
1775
|
+
!(entry.item.value instanceof FieldMark) ||
|
|
1776
|
+
entry.item.value.fldCharType !== 'begin') {
|
|
1777
|
+
continue;
|
|
1778
|
+
}
|
|
1779
|
+
var field = pairComplexField(flat, beginIndex);
|
|
1780
|
+
if (field !== undefined) {
|
|
1781
|
+
var wrapped = wrapSupportedField('complex', undefined, field, paragraph, field.instruction);
|
|
1782
|
+
if (wrapped !== undefined) {
|
|
1783
|
+
found.push(wrapped);
|
|
1784
|
+
}
|
|
1785
|
+
}
|
|
1786
|
+
}
|
|
1787
|
+
}
|
|
1788
|
+
catch (e_14_1) { e_14 = { error: e_14_1 }; }
|
|
1789
|
+
finally {
|
|
1790
|
+
try {
|
|
1791
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
1792
|
+
}
|
|
1793
|
+
finally { if (e_14) throw e_14.error; }
|
|
1794
|
+
}
|
|
1795
|
+
return found;
|
|
1796
|
+
}
|
|
1797
|
+
/**
|
|
1798
|
+
* Fields across the document, in document order.
|
|
1799
|
+
*
|
|
1800
|
+
* Walks paragraphs via {@link visitParagraphsInDocumentOrder} (main body and
|
|
1801
|
+
* nested paragraph hosts the registry visitor covers). Does not recalculate
|
|
1802
|
+
* field results.
|
|
1803
|
+
*
|
|
1804
|
+
* @private
|
|
1805
|
+
*/
|
|
1806
|
+
export function fieldsInDocument(document) {
|
|
1807
|
+
var found = [];
|
|
1808
|
+
visitParagraphsInDocumentOrder(document, function (paragraph) {
|
|
1809
|
+
found.push.apply(found, __spread(fieldsInParagraph(paragraph)));
|
|
1810
|
+
});
|
|
1811
|
+
return found;
|
|
1812
|
+
}
|
|
1813
|
+
/**
|
|
1814
|
+
* Remove a simple field from its paragraph.
|
|
1815
|
+
*
|
|
1816
|
+
* @private
|
|
1817
|
+
*/
|
|
1818
|
+
function removeSimpleField(paragraph, field) {
|
|
1819
|
+
paragraph.removeFeatureInline(field);
|
|
1820
|
+
}
|
|
1821
|
+
/**
|
|
1822
|
+
* Remove a complex field from its paragraph.
|
|
1823
|
+
*
|
|
1824
|
+
* @private
|
|
1825
|
+
*/
|
|
1826
|
+
function removeComplexField(paragraph, field) {
|
|
1827
|
+
var e_15, _a, e_16, _b;
|
|
1828
|
+
try {
|
|
1829
|
+
for (var _c = __values(field.allFeatureValues()), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
1830
|
+
var value = _d.value;
|
|
1831
|
+
paragraph.removeFeatureRunItem(value);
|
|
1832
|
+
}
|
|
1833
|
+
}
|
|
1834
|
+
catch (e_15_1) { e_15 = { error: e_15_1 }; }
|
|
1835
|
+
finally {
|
|
1836
|
+
try {
|
|
1837
|
+
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
|
|
1838
|
+
}
|
|
1839
|
+
finally { if (e_15) throw e_15.error; }
|
|
1840
|
+
}
|
|
1841
|
+
try {
|
|
1842
|
+
for (var _e = __values(field.resultRuns), _f = _e.next(); !_f.done; _f = _e.next()) {
|
|
1843
|
+
var run = _f.value;
|
|
1844
|
+
paragraph.removeTextRange(run);
|
|
1845
|
+
}
|
|
1846
|
+
}
|
|
1847
|
+
catch (e_16_1) { e_16 = { error: e_16_1 }; }
|
|
1848
|
+
finally {
|
|
1849
|
+
try {
|
|
1850
|
+
if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
|
|
1851
|
+
}
|
|
1852
|
+
finally { if (e_16) throw e_16.error; }
|
|
1853
|
+
}
|
|
1854
|
+
}
|
|
1855
|
+
/**
|
|
1856
|
+
* Remove a {@link Field} from the given paragraph.
|
|
1857
|
+
*
|
|
1858
|
+
* Prefer {@link Field.remove} when the field was listed or appended with a host
|
|
1859
|
+
* paragraph.
|
|
1860
|
+
*
|
|
1861
|
+
* @private
|
|
1862
|
+
*/
|
|
1863
|
+
function removeField(paragraph, field) {
|
|
1864
|
+
var simple = field.simple;
|
|
1865
|
+
if (simple !== undefined) {
|
|
1866
|
+
removeSimpleField(paragraph, simple);
|
|
1867
|
+
return;
|
|
1868
|
+
}
|
|
1869
|
+
var complex = field.complex;
|
|
1870
|
+
if (complex !== undefined) {
|
|
1871
|
+
removeComplexField(paragraph, complex);
|
|
1872
|
+
}
|
|
1873
|
+
}
|
|
1874
|
+
/**
|
|
1875
|
+
* Whether a paragraph item is a simple field from this module.
|
|
1876
|
+
*
|
|
1877
|
+
* @private
|
|
1878
|
+
*/
|
|
1879
|
+
function isSimpleFieldInline(inline) {
|
|
1880
|
+
return (inline instanceof FeatureInlineParagraphItem &&
|
|
1881
|
+
inline.featureId === FIELDS &&
|
|
1882
|
+
inline.value instanceof SimpleField);
|
|
1883
|
+
}
|
|
1884
|
+
/**
|
|
1885
|
+
* Whether a paragraph item is a modeled field mark from this module.
|
|
1886
|
+
*
|
|
1887
|
+
* @private
|
|
1888
|
+
*/
|
|
1889
|
+
function isFieldMarkLeaf(item) {
|
|
1890
|
+
return item instanceof FeatureRunParagraphItem && item.featureId === FIELDS && item.value instanceof FieldMark;
|
|
1891
|
+
}
|
|
1892
|
+
/**
|
|
1893
|
+
* Whether a paragraph item is modeled instruction text from this module.
|
|
1894
|
+
*
|
|
1895
|
+
* @private
|
|
1896
|
+
*/
|
|
1897
|
+
function isInstrTextLeaf(item) {
|
|
1898
|
+
return item instanceof FeatureRunParagraphItem && item.featureId === FIELDS && item.value instanceof InstrText;
|
|
1899
|
+
}
|
|
1900
|
+
function isSupportedFieldType(value) {
|
|
1901
|
+
return SUPPORTED_FIELD_TYPES.has(value);
|
|
1902
|
+
}
|
|
1903
|
+
function defaultInstructionForAppend(fieldName, type) {
|
|
1904
|
+
switch (type) {
|
|
1905
|
+
case FieldType.Page:
|
|
1906
|
+
return ' PAGE ';
|
|
1907
|
+
case FieldType.NumPages:
|
|
1908
|
+
return ' NUMPAGES ';
|
|
1909
|
+
case FieldType.If:
|
|
1910
|
+
return ' IF ';
|
|
1911
|
+
case FieldType.MergeField:
|
|
1912
|
+
return ' MERGEFIELD ' + fieldName + ' ';
|
|
1913
|
+
case FieldType.Hyperlink:
|
|
1914
|
+
// Logical name only; prefer appendHyperlink for target + display text.
|
|
1915
|
+
return ' HYPERLINK ';
|
|
1916
|
+
default: {
|
|
1917
|
+
var _exhaustive = type;
|
|
1918
|
+
return _exhaustive;
|
|
1919
|
+
}
|
|
1920
|
+
}
|
|
1921
|
+
}
|
|
1922
|
+
function defaultCachedResultForAppend(fieldName, type) {
|
|
1923
|
+
switch (type) {
|
|
1924
|
+
case FieldType.MergeField:
|
|
1925
|
+
return '«' + fieldName + '»';
|
|
1926
|
+
case FieldType.Page:
|
|
1927
|
+
case FieldType.NumPages:
|
|
1928
|
+
return '1';
|
|
1929
|
+
case FieldType.If:
|
|
1930
|
+
case FieldType.Hyperlink:
|
|
1931
|
+
return '';
|
|
1932
|
+
default: {
|
|
1933
|
+
var _exhaustive = type;
|
|
1934
|
+
return _exhaustive;
|
|
1935
|
+
}
|
|
1936
|
+
}
|
|
1937
|
+
}
|
|
1938
|
+
function wrapFieldFromStorage(kind, simple, complex, host, instruction) {
|
|
1939
|
+
var wrapped = wrapSupportedField(kind, simple, complex, host, instruction);
|
|
1940
|
+
if (wrapped === undefined) {
|
|
1941
|
+
// Private helpers (SEQ/captions) may build non-customer field types — still need a Field shell for internal use.
|
|
1942
|
+
// Use Page lock only if instruction matches; otherwise treat as opaque-supported failure.
|
|
1943
|
+
var forced = trySupportedFieldTypeFromInstruction(instruction);
|
|
1944
|
+
if (forced !== undefined) {
|
|
1945
|
+
return new LegacyField(kind, simple, complex, host, forced);
|
|
1946
|
+
}
|
|
1947
|
+
throw new DocxError('content/invalid-field', 'Unsupported field instruction for public Field wrapper');
|
|
1948
|
+
}
|
|
1949
|
+
return wrapped;
|
|
1950
|
+
}
|
|
1951
|
+
function appendSimpleFieldImpl(paragraph, instruction, result) {
|
|
1952
|
+
if (instruction.trim().length === 0) {
|
|
1953
|
+
throw new DocxError('content/invalid-field', 'Field instruction must not be empty');
|
|
1954
|
+
}
|
|
1955
|
+
var runOwner = new SimpleFieldRunOwner();
|
|
1956
|
+
var run = runOwner.appendRun();
|
|
1957
|
+
run.text = result;
|
|
1958
|
+
var simple = new SimpleField(runOwner, [], [{ type: 'textRange', run: run }], instruction, undefined, undefined);
|
|
1959
|
+
paragraph.appendFeatureInline(FIELDS, simple);
|
|
1960
|
+
return wrapFieldFromStorage('simple', simple, undefined, paragraph, instruction);
|
|
1961
|
+
}
|
|
1962
|
+
function appendComplexFieldImpl(paragraph, instruction, result) {
|
|
1963
|
+
var trimmed = instruction.trim();
|
|
1964
|
+
if (trimmed.length === 0) {
|
|
1965
|
+
throw new DocxError('content/invalid-field', 'Field instruction must not be empty');
|
|
1966
|
+
}
|
|
1967
|
+
var beginMark = new FieldMark('begin', undefined, undefined, []);
|
|
1968
|
+
paragraph.appendFeatureRunItem(FIELDS, beginMark);
|
|
1969
|
+
var instrText = new InstrText(" " + trimmed + " ", false);
|
|
1970
|
+
paragraph.appendFeatureRunItem(FIELDS, instrText);
|
|
1971
|
+
var separateMark = new FieldMark('separate', undefined, undefined, []);
|
|
1972
|
+
paragraph.appendFeatureRunItem(FIELDS, separateMark);
|
|
1973
|
+
var resultRun = paragraph.appendText(result);
|
|
1974
|
+
var endMark = new FieldMark('end', undefined, undefined, []);
|
|
1975
|
+
paragraph.appendFeatureRunItem(FIELDS, endMark);
|
|
1976
|
+
var complex = new ComplexField(trimmed, [resultRun], [beginMark, instrText, separateMark, endMark], [instrText]);
|
|
1977
|
+
return wrapFieldFromStorage('complex', undefined, complex, paragraph, trimmed);
|
|
1978
|
+
}
|
|
1979
|
+
/**
|
|
1980
|
+
* Append an opaque complex field (any instruction, including SEQ for captions).
|
|
1981
|
+
* Not part of the public customer Field API.
|
|
1982
|
+
*
|
|
1983
|
+
* @private
|
|
1984
|
+
*/
|
|
1985
|
+
export function appendOpaqueComplexField(paragraph, instruction, options) {
|
|
1986
|
+
return appendComplexFieldImplPrivate(paragraph, instruction, options.result);
|
|
1987
|
+
}
|
|
1988
|
+
/**
|
|
1989
|
+
* Opaque complex-field instructions in a paragraph (any keyword, including SEQ).
|
|
1990
|
+
*
|
|
1991
|
+
* @private
|
|
1992
|
+
*/
|
|
1993
|
+
export function opaqueComplexFieldInstructionsInParagraph(paragraph) {
|
|
1994
|
+
return complexFieldsInParagraph(paragraph).map(function (field) { return field.instruction; });
|
|
1995
|
+
}
|
|
1996
|
+
/**
|
|
1997
|
+
* First instruction keyword (e.g. SEQ, PAGE) for opaque complex fields.
|
|
1998
|
+
*
|
|
1999
|
+
* @private
|
|
2000
|
+
*/
|
|
2001
|
+
export function fieldInstructionKeyword(instruction) {
|
|
2002
|
+
return parseFieldInstruction(instruction).type;
|
|
2003
|
+
}
|
|
2004
|
+
/** @private Internal Field for any instruction (SEQ captions etc.). */
|
|
2005
|
+
var InternalField = /** @class */ (function (_super) {
|
|
2006
|
+
__extends(InternalField, _super);
|
|
2007
|
+
function InternalField(kind, simple, complex, host) {
|
|
2008
|
+
// lockedType unused for internal-only; Page is a placeholder the public getters still expose if misused.
|
|
2009
|
+
return _super.call(this, kind, simple, complex, host, FieldType.Page) || this;
|
|
2010
|
+
}
|
|
2011
|
+
return InternalField;
|
|
2012
|
+
}(LegacyField));
|
|
2013
|
+
function appendSimpleFieldImplPrivate(paragraph, instruction, result) {
|
|
2014
|
+
if (instruction.trim().length === 0) {
|
|
2015
|
+
throw new DocxError('content/invalid-field', 'Field instruction must not be empty');
|
|
2016
|
+
}
|
|
2017
|
+
var runOwner = new SimpleFieldRunOwner();
|
|
2018
|
+
var run = runOwner.appendRun();
|
|
2019
|
+
run.text = result;
|
|
2020
|
+
var simple = new SimpleField(runOwner, [], [{ type: 'textRange', run: run }], instruction, undefined, undefined);
|
|
2021
|
+
paragraph.appendFeatureInline(FIELDS, simple);
|
|
2022
|
+
var supported = wrapSupportedField('simple', simple, undefined, paragraph, instruction);
|
|
2023
|
+
if (supported !== undefined) {
|
|
2024
|
+
return supported;
|
|
2025
|
+
}
|
|
2026
|
+
return new InternalField('simple', simple, undefined, paragraph);
|
|
2027
|
+
}
|
|
2028
|
+
function appendComplexFieldImplPrivate(paragraph, instruction, result) {
|
|
2029
|
+
var trimmed = instruction.trim();
|
|
2030
|
+
if (trimmed.length === 0) {
|
|
2031
|
+
throw new DocxError('content/invalid-field', 'Field instruction must not be empty');
|
|
2032
|
+
}
|
|
2033
|
+
var beginMark = new FieldMark('begin', undefined, undefined, []);
|
|
2034
|
+
paragraph.appendFeatureRunItem(FIELDS, beginMark);
|
|
2035
|
+
var instrText = new InstrText(" " + trimmed + " ", false);
|
|
2036
|
+
paragraph.appendFeatureRunItem(FIELDS, instrText);
|
|
2037
|
+
var separateMark = new FieldMark('separate', undefined, undefined, []);
|
|
2038
|
+
paragraph.appendFeatureRunItem(FIELDS, separateMark);
|
|
2039
|
+
var resultRun = paragraph.appendText(result);
|
|
2040
|
+
var endMark = new FieldMark('end', undefined, undefined, []);
|
|
2041
|
+
paragraph.appendFeatureRunItem(FIELDS, endMark);
|
|
2042
|
+
var complex = new ComplexField(trimmed, [resultRun], [beginMark, instrText, separateMark, endMark], [instrText]);
|
|
2043
|
+
var supported = wrapSupportedField('complex', undefined, complex, paragraph, trimmed);
|
|
2044
|
+
if (supported !== undefined) {
|
|
2045
|
+
return supported;
|
|
2046
|
+
}
|
|
2047
|
+
return new InternalField('complex', undefined, complex, paragraph);
|
|
2048
|
+
}
|
|
2049
|
+
/**
|
|
2050
|
+
* Append a supported field as direct ParagraphItem field DOM
|
|
2051
|
+
* (Field begin → instruction TextRange → separator → result → end).
|
|
2052
|
+
*
|
|
2053
|
+
* @public
|
|
2054
|
+
*/
|
|
2055
|
+
Paragraph.prototype.appendField = function (fieldName, fieldType) {
|
|
2056
|
+
var name = fieldName == null ? '' : String(fieldName).trim();
|
|
2057
|
+
if (name.length === 0) {
|
|
2058
|
+
throw new DocxError('content/invalid-field', 'fieldName must not be empty');
|
|
2059
|
+
}
|
|
2060
|
+
if (!isSupportedFieldType(fieldType)) {
|
|
2061
|
+
throw new DocxError('content/invalid-field', 'Unsupported fieldType');
|
|
2062
|
+
}
|
|
2063
|
+
this.assertMutable();
|
|
2064
|
+
var field;
|
|
2065
|
+
if (fieldType === FieldType.If) {
|
|
2066
|
+
field = new IfField(FieldType.If, undefined, undefined, []);
|
|
2067
|
+
}
|
|
2068
|
+
else if (fieldType === FieldType.MergeField) {
|
|
2069
|
+
field = new MergeField(FieldType.MergeField, undefined, undefined, []);
|
|
2070
|
+
}
|
|
2071
|
+
else {
|
|
2072
|
+
field = new Field(fieldType, undefined, undefined, []);
|
|
2073
|
+
}
|
|
2074
|
+
this.items.add(field);
|
|
2075
|
+
var instructionRange = new TextRange();
|
|
2076
|
+
this.items.add(instructionRange);
|
|
2077
|
+
instructionRange.text = defaultInstructionForAppend(name, fieldType);
|
|
2078
|
+
var separator = new ParagraphFieldMark(ParagraphFieldMarkType.Separator, undefined, undefined, []);
|
|
2079
|
+
this.items.add(separator);
|
|
2080
|
+
var resultRange = new TextRange();
|
|
2081
|
+
this.items.add(resultRange);
|
|
2082
|
+
resultRange.text = defaultCachedResultForAppend(name, fieldType);
|
|
2083
|
+
var endMark = new ParagraphFieldMark(ParagraphFieldMarkType.End, undefined, undefined, []);
|
|
2084
|
+
this.items.add(endMark);
|
|
2085
|
+
return field;
|
|
2086
|
+
};
|
|
2087
|
+
/**
|
|
2088
|
+
* Author a field-based or picture-based hyperlink.
|
|
2089
|
+
* Overloads the paragraph method also used by `w:hyperlink` authoring when the
|
|
2090
|
+
* second argument is an options object.
|
|
2091
|
+
*
|
|
2092
|
+
* Picture path uses DrawingML `a:hlinkClick` (no HYPERLINK field markers).
|
|
2093
|
+
*
|
|
2094
|
+
* @public
|
|
2095
|
+
*/
|
|
2096
|
+
/**
|
|
2097
|
+
* Append a hyperlink.
|
|
2098
|
+
* - (url, displayText, type) authors a HYPERLINK field
|
|
2099
|
+
* - (url, picture, type) sets DrawingML a:hlinkClick on the picture
|
|
2100
|
+
*
|
|
2101
|
+
* @public
|
|
2102
|
+
*/
|
|
2103
|
+
Paragraph.prototype.appendHyperlink = function (target, textOrPicture, type) {
|
|
2104
|
+
var linkType = type != null ? type : HyperlinkType.WebLink;
|
|
2105
|
+
if (textOrPicture instanceof Picture) {
|
|
2106
|
+
var resolvedTarget = target;
|
|
2107
|
+
if (linkType === HyperlinkType.EmailLink && !/^mailto:/i.test(target)) {
|
|
2108
|
+
resolvedTarget = 'mailto:' + target;
|
|
2109
|
+
}
|
|
2110
|
+
var document_1 = this.owningDocument();
|
|
2111
|
+
var catalog = hyperlinksFor(document_1);
|
|
2112
|
+
var used = new Set(catalog.relationshipIds());
|
|
2113
|
+
var relationshipId = catalog.allocateExternalTarget(resolvedTarget, used);
|
|
2114
|
+
textOrPicture.hyperlinkRelationshipId = relationshipId;
|
|
2115
|
+
textOrPicture.hyperlinkTarget = resolvedTarget;
|
|
2116
|
+
return new Hyperlink(textOrPicture, resolvedTarget, linkType);
|
|
2117
|
+
}
|
|
2118
|
+
var display = typeof textOrPicture === 'string' ? textOrPicture : '';
|
|
2119
|
+
var instruction = ' HYPERLINK ';
|
|
2120
|
+
if (linkType === HyperlinkType.Bookmark) {
|
|
2121
|
+
instruction = ' HYPERLINK \\l ' + quoteFieldOperand(target) + ' ';
|
|
2122
|
+
}
|
|
2123
|
+
else if (linkType === HyperlinkType.EmailLink) {
|
|
2124
|
+
var mail = /^mailto:/i.test(target) ? target : 'mailto:' + target;
|
|
2125
|
+
instruction = ' HYPERLINK ' + quoteFieldOperand(mail) + ' ';
|
|
2126
|
+
}
|
|
2127
|
+
else {
|
|
2128
|
+
instruction = ' HYPERLINK ' + quoteFieldOperand(target) + ' ';
|
|
2129
|
+
}
|
|
2130
|
+
this.assertMutable();
|
|
2131
|
+
var field = new Field(FieldType.Hyperlink, undefined, undefined, []);
|
|
2132
|
+
this.items.add(field);
|
|
2133
|
+
var instructionRange = new TextRange();
|
|
2134
|
+
this.items.add(instructionRange);
|
|
2135
|
+
instructionRange.text = instruction;
|
|
2136
|
+
var separator = new ParagraphFieldMark(ParagraphFieldMarkType.Separator, undefined, undefined, []);
|
|
2137
|
+
this.items.add(separator);
|
|
2138
|
+
var resultRange = new TextRange();
|
|
2139
|
+
this.items.add(resultRange);
|
|
2140
|
+
resultRange.text = display;
|
|
2141
|
+
var endMark = new ParagraphFieldMark(ParagraphFieldMarkType.End, undefined, undefined, []);
|
|
2142
|
+
this.items.add(endMark);
|
|
2143
|
+
return new Hyperlink(field);
|
|
2144
|
+
};
|
|
2145
|
+
registerAlwaysOnBodyFeatureBootstrap(function () {
|
|
2146
|
+
registerFieldsFeature();
|
|
2147
|
+
});
|
|
2148
|
+
registerFieldsFeature();
|