@syncfusion/ej2-docx 0.0.0-stage → 35.1.40
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.gitleaksignore +35 -0
- package/README.md +68 -2
- package/core.js +4 -0
- package/dist/ej2-docx.umd.min.js +11 -0
- package/dist/ej2-docx.umd.min.js.map +1 -0
- package/dist/es6/ej2-docx.es2015.js +66697 -0
- package/dist/es6/ej2-docx.es2015.js.map +1 -0
- package/dist/es6/ej2-docx.es5.js +77568 -0
- package/dist/es6/ej2-docx.es5.js.map +1 -0
- package/dist/global/ej2-docx.min.js +11 -0
- package/dist/global/ej2-docx.min.js.map +1 -0
- package/dist/global/index.d.ts +14 -0
- package/features.js +4 -0
- package/index.js +4 -0
- package/license +10 -0
- package/package.json +30 -3
- package/src/all.d.ts +50 -0
- package/src/all.js +147 -0
- package/src/core/compat/base64.d.ts +13 -0
- package/src/core/compat/base64.js +90 -0
- package/src/core/compat/object-compat.d.ts +30 -0
- package/src/core/compat/object-compat.js +40 -0
- package/src/core/compat/sha256.d.ts +9 -0
- package/src/core/compat/sha256.js +98 -0
- package/src/core/errors/docx-error.d.ts +89 -0
- package/src/core/errors/docx-error.js +138 -0
- package/src/core/errors/error-codes.d.ts +8 -0
- package/src/core/errors/error-codes.js +0 -0
- package/src/core/errors/index.d.ts +10 -0
- package/src/core/errors/index.js +9 -0
- package/src/core/index.d.ts +12 -0
- package/src/core/index.js +12 -0
- package/src/core/mc/alternate-content.d.ts +7 -0
- package/src/core/mc/alternate-content.js +67 -0
- package/src/core/mc/attributes.d.ts +24 -0
- package/src/core/mc/attributes.js +82 -0
- package/src/core/mc/index.d.ts +7 -0
- package/src/core/mc/index.js +5 -0
- package/src/core/mc/inspect.d.ts +16 -0
- package/src/core/mc/inspect.js +148 -0
- package/src/core/mc/namespaces.d.ts +4 -0
- package/src/core/mc/namespaces.js +4 -0
- package/src/core/mc/scope.d.ts +6 -0
- package/src/core/mc/scope.js +47 -0
- package/src/core/opc/content-types.d.ts +34 -0
- package/src/core/opc/content-types.js +162 -0
- package/src/core/opc/index.d.ts +8 -0
- package/src/core/opc/index.js +4 -0
- package/src/core/opc/package.d.ts +49 -0
- package/src/core/opc/package.js +324 -0
- package/src/core/opc/part-name.d.ts +47 -0
- package/src/core/opc/part-name.js +205 -0
- package/src/core/opc/relationships.d.ts +46 -0
- package/src/core/opc/relationships.js +212 -0
- package/src/core/preservation/index.d.ts +2 -0
- package/src/core/preservation/index.js +1 -0
- package/src/core/preservation/opaque-body.d.ts +16 -0
- package/src/core/preservation/opaque-body.js +69 -0
- package/src/core/registry/block-handlers.d.ts +30 -0
- package/src/core/registry/block-handlers.js +36 -0
- package/src/core/registry/create-defaults.d.ts +39 -0
- package/src/core/registry/create-defaults.js +42 -0
- package/src/core/registry/feature-registry.d.ts +20 -0
- package/src/core/registry/feature-registry.js +29 -0
- package/src/core/registry/index.d.ts +9 -0
- package/src/core/registry/index.js +8 -0
- package/src/core/registry/inline-handlers.d.ts +20 -0
- package/src/core/registry/inline-handlers.js +30 -0
- package/src/core/registry/materialize-handlers.d.ts +35 -0
- package/src/core/registry/materialize-handlers.js +75 -0
- package/src/core/registry/multi-part-handlers.d.ts +37 -0
- package/src/core/registry/multi-part-handlers.js +206 -0
- package/src/core/registry/package-part-handlers.d.ts +28 -0
- package/src/core/registry/package-part-handlers.js +190 -0
- package/src/core/registry/part-handlers.d.ts +24 -0
- package/src/core/registry/part-handlers.js +172 -0
- package/src/core/registry/run-leaf-handlers.d.ts +26 -0
- package/src/core/registry/run-leaf-handlers.js +72 -0
- package/src/core/security/limits.d.ts +40 -0
- package/src/core/security/limits.js +26 -0
- package/src/core/xml/index.d.ts +7 -0
- package/src/core/xml/index.js +3 -0
- package/src/core/xml/model.d.ts +66 -0
- package/src/core/xml/model.js +17 -0
- package/src/core/xml/parse.d.ts +12 -0
- package/src/core/xml/parse.js +382 -0
- package/src/core/xml/serialize.d.ts +6 -0
- package/src/core/xml/serialize.js +93 -0
- package/src/core/zip/crc32.d.ts +2 -0
- package/src/core/zip/crc32.js +25 -0
- package/src/core/zip/deflate.d.ts +6 -0
- package/src/core/zip/deflate.js +6 -0
- package/src/core/zip/index.d.ts +10 -0
- package/src/core/zip/index.js +4 -0
- package/src/core/zip/inflate-raw.d.ts +17 -0
- package/src/core/zip/inflate-raw.js +450 -0
- package/src/core/zip/names.d.ts +6 -0
- package/src/core/zip/names.js +52 -0
- package/src/core/zip/read.d.ts +8 -0
- package/src/core/zip/read.js +262 -0
- package/src/core/zip/write.d.ts +7 -0
- package/src/core/zip/write.js +189 -0
- package/src/core/zip/zip-entry.d.ts +4 -0
- package/src/core/zip/zip-entry.js +0 -0
- package/src/features/bibliography/index.d.ts +100 -0
- package/src/features/bibliography/index.js +290 -0
- package/src/features/bookmarks/index.d.ts +331 -0
- package/src/features/bookmarks/index.js +1009 -0
- package/src/features/comments/comment-extensions.d.ts +157 -0
- package/src/features/comments/comment-extensions.js +356 -0
- package/src/features/comments/index.d.ts +579 -0
- package/src/features/comments/index.js +1727 -0
- package/src/features/content-controls/index.d.ts +821 -0
- package/src/features/content-controls/index.js +2857 -0
- package/src/features/custom-xml/index.d.ts +236 -0
- package/src/features/custom-xml/index.js +661 -0
- package/src/features/document/alignment.d.ts +23 -0
- package/src/features/document/alignment.js +36 -0
- package/src/features/document/alt-chunk.d.ts +103 -0
- package/src/features/document/alt-chunk.js +221 -0
- package/src/features/document/assert-never.d.ts +1 -0
- package/src/features/document/assert-never.js +4 -0
- package/src/features/document/augmentations.d.ts +578 -0
- package/src/features/document/augmentations.js +0 -0
- package/src/features/document/body-always-on.d.ts +36 -0
- package/src/features/document/body-always-on.js +66 -0
- package/src/features/document/body-blocks.d.ts +7 -0
- package/src/features/document/body-blocks.js +78 -0
- package/src/features/document/body-item-adapters.d.ts +62 -0
- package/src/features/document/body-item-adapters.js +97 -0
- package/src/features/document/body-item-collection.d.ts +151 -0
- package/src/features/document/body-item-collection.js +440 -0
- package/src/features/document/body-item.d.ts +35 -0
- package/src/features/document/body-item.js +8 -0
- package/src/features/document/body.d.ts +150 -0
- package/src/features/document/body.js +263 -0
- package/src/features/document/character-format.d.ts +413 -0
- package/src/features/document/character-format.js +2054 -0
- package/src/features/document/color.d.ts +178 -0
- package/src/features/document/color.js +495 -0
- package/src/features/document/document.d.ts +410 -0
- package/src/features/document/document.js +1049 -0
- package/src/features/document/element-type.d.ts +68 -0
- package/src/features/document/element-type.js +133 -0
- package/src/features/document/entity-type.d.ts +92 -0
- package/src/features/document/entity-type.js +93 -0
- package/src/features/document/feature-block.d.ts +16 -0
- package/src/features/document/feature-block.js +0 -0
- package/src/features/document/feature-inline.d.ts +13 -0
- package/src/features/document/feature-inline.js +0 -0
- package/src/features/document/feature-multi-package-part.d.ts +19 -0
- package/src/features/document/feature-multi-package-part.js +8 -0
- package/src/features/document/feature-package-level-part.d.ts +18 -0
- package/src/features/document/feature-package-level-part.js +8 -0
- package/src/features/document/feature-package-part.d.ts +14 -0
- package/src/features/document/feature-package-part.js +0 -0
- package/src/features/document/feature-run-leaf.d.ts +9 -0
- package/src/features/document/feature-run-leaf.js +0 -0
- package/src/features/document/headers-footers.d.ts +206 -0
- package/src/features/document/headers-footers.js +384 -0
- package/src/features/document/index.d.ts +41 -0
- package/src/features/document/index.js +34 -0
- package/src/features/document/length.d.ts +152 -0
- package/src/features/document/length.js +245 -0
- package/src/features/document/load-options.d.ts +14 -0
- package/src/features/document/load-options.js +0 -0
- package/src/features/document/locale-ids.d.ts +227 -0
- package/src/features/document/locale-ids.js +485 -0
- package/src/features/document/on-off.d.ts +9 -0
- package/src/features/document/on-off.js +27 -0
- package/src/features/document/page-setup.d.ts +339 -0
- package/src/features/document/page-setup.js +244 -0
- package/src/features/document/paragraph-format.d.ts +880 -0
- package/src/features/document/paragraph-format.js +2807 -0
- package/src/features/document/paragraph-item-collection.d.ts +162 -0
- package/src/features/document/paragraph-item-collection.js +363 -0
- package/src/features/document/paragraph-item.d.ts +83 -0
- package/src/features/document/paragraph-item.js +103 -0
- package/src/features/document/paragraph.d.ts +435 -0
- package/src/features/document/paragraph.js +888 -0
- package/src/features/document/run.d.ts +1 -0
- package/src/features/document/run.js +768 -0
- package/src/features/document/section-partition-flatten.d.ts +124 -0
- package/src/features/document/section-partition-flatten.js +217 -0
- package/src/features/document/section-properties-model.d.ts +13 -0
- package/src/features/document/section-properties-model.js +0 -0
- package/src/features/document/section.d.ts +93 -0
- package/src/features/document/section.js +178 -0
- package/src/features/document/sections.d.ts +103 -0
- package/src/features/document/sections.js +217 -0
- package/src/features/document/sub-super-script.d.ts +23 -0
- package/src/features/document/sub-super-script.js +43 -0
- package/src/features/document/text-range.d.ts +445 -0
- package/src/features/document/text-range.js +1156 -0
- package/src/features/document/typed-body-collections.d.ts +162 -0
- package/src/features/document/typed-body-collections.js +371 -0
- package/src/features/document/underline-style.d.ts +38 -0
- package/src/features/document/underline-style.js +126 -0
- package/src/features/document/units.d.ts +8 -0
- package/src/features/document/units.js +7 -0
- package/src/features/document/wml.d.ts +16 -0
- package/src/features/document/wml.js +67 -0
- package/src/features/drawing/authoring.d.ts +27 -0
- package/src/features/drawing/authoring.js +271 -0
- package/src/features/drawing/body-pr.d.ts +271 -0
- package/src/features/drawing/body-pr.js +663 -0
- package/src/features/drawing/drawing-shape.d.ts +1192 -0
- package/src/features/drawing/drawing-shape.js +3239 -0
- package/src/features/drawing/encode-builders.d.ts +176 -0
- package/src/features/drawing/encode-builders.js +390 -0
- package/src/features/drawing/fill-format.d.ts +52 -0
- package/src/features/drawing/fill-format.js +124 -0
- package/src/features/drawing/host-codec.d.ts +632 -0
- package/src/features/drawing/host-codec.js +2595 -0
- package/src/features/drawing/index.d.ts +13 -0
- package/src/features/drawing/index.js +33 -0
- package/src/features/drawing/line-format.d.ts +76 -0
- package/src/features/drawing/line-format.js +343 -0
- package/src/features/drawing/parse-register.d.ts +50 -0
- package/src/features/drawing/parse-register.js +257 -0
- package/src/features/drawing/residual-utils.d.ts +47 -0
- package/src/features/drawing/residual-utils.js +290 -0
- package/src/features/drawing/shape-types.d.ts +433 -0
- package/src/features/drawing/shape-types.js +437 -0
- package/src/features/drawing/sp-pr.d.ts +396 -0
- package/src/features/drawing/sp-pr.js +610 -0
- package/src/features/drawing/text-frame.d.ts +90 -0
- package/src/features/drawing/text-frame.js +152 -0
- package/src/features/drawing/types.d.ts +352 -0
- package/src/features/drawing/types.js +60 -0
- package/src/features/drawing/wrap-format.d.ts +62 -0
- package/src/features/drawing/wrap-format.js +114 -0
- package/src/features/editable-ranges/index.d.ts +494 -0
- package/src/features/editable-ranges/index.js +1348 -0
- package/src/features/fields/index.d.ts +428 -0
- package/src/features/fields/index.js +2148 -0
- package/src/features/fields/paragraph-field.d.ts +187 -0
- package/src/features/fields/paragraph-field.js +692 -0
- package/src/features/font-table/font-substitution-table.d.ts +75 -0
- package/src/features/font-table/font-substitution-table.js +257 -0
- package/src/features/font-table/font-table-entry.d.ts +255 -0
- package/src/features/font-table/font-table-entry.js +823 -0
- package/src/features/font-table/font-table.d.ts +128 -0
- package/src/features/font-table/font-table.js +313 -0
- package/src/features/font-table/index.d.ts +27 -0
- package/src/features/font-table/index.js +48 -0
- package/src/features/glossary/index.d.ts +97 -0
- package/src/features/glossary/index.js +286 -0
- package/src/features/headers-footers/index.d.ts +506 -0
- package/src/features/headers-footers/index.js +1666 -0
- package/src/features/hyperlinks/index.d.ts +230 -0
- package/src/features/hyperlinks/index.js +685 -0
- package/src/features/images/caption-authoring-api.d.ts +33 -0
- package/src/features/images/caption-authoring-api.js +33 -0
- package/src/features/images/caption-enums.d.ts +52 -0
- package/src/features/images/caption-enums.js +141 -0
- package/src/features/images/caption-host.d.ts +10 -0
- package/src/features/images/caption-host.js +21 -0
- package/src/features/images/captions.d.ts +13 -0
- package/src/features/images/captions.js +142 -0
- package/src/features/images/host-codec.d.ts +103 -0
- package/src/features/images/host-codec.js +720 -0
- package/src/features/images/image-sniff.d.ts +21 -0
- package/src/features/images/image-sniff.js +71 -0
- package/src/features/images/index.d.ts +506 -0
- package/src/features/images/index.js +1429 -0
- package/src/features/images/layout-types.d.ts +232 -0
- package/src/features/images/layout-types.js +294 -0
- package/src/features/images/public-entry.d.ts +9 -0
- package/src/features/images/public-entry.js +9 -0
- package/src/features/index.d.ts +35 -0
- package/src/features/index.js +36 -0
- package/src/features/mail-merge/index.d.ts +113 -0
- package/src/features/mail-merge/index.js +315 -0
- package/src/features/notes/index.d.ts +573 -0
- package/src/features/notes/index.js +1725 -0
- package/src/features/numbering/abstract-numbering.d.ts +90 -0
- package/src/features/numbering/abstract-numbering.js +292 -0
- package/src/features/numbering/index.d.ts +182 -0
- package/src/features/numbering/index.js +668 -0
- package/src/features/numbering/list-format.d.ts +158 -0
- package/src/features/numbering/list-format.js +590 -0
- package/src/features/numbering/list-string.d.ts +7 -0
- package/src/features/numbering/list-string.js +423 -0
- package/src/features/numbering/list-style.d.ts +204 -0
- package/src/features/numbering/list-style.js +1084 -0
- package/src/features/numbering/numbering-instance.d.ts +101 -0
- package/src/features/numbering/numbering-instance.js +329 -0
- package/src/features/numbering/numbering-level.d.ts +118 -0
- package/src/features/numbering/numbering-level.js +501 -0
- package/src/features/numbering/picture-bullet.d.ts +34 -0
- package/src/features/numbering/picture-bullet.js +88 -0
- package/src/features/ole-object/catalog.d.ts +300 -0
- package/src/features/ole-object/catalog.js +908 -0
- package/src/features/ole-object/index.d.ts +526 -0
- package/src/features/ole-object/index.js +1421 -0
- package/src/features/ole-object/relationship.d.ts +27 -0
- package/src/features/ole-object/relationship.js +27 -0
- package/src/features/ole-object/typed-dom.d.ts +186 -0
- package/src/features/ole-object/typed-dom.js +595 -0
- package/src/features/properties/index.d.ts +205 -0
- package/src/features/properties/index.js +549 -0
- package/src/features/revisions/index.d.ts +204 -0
- package/src/features/revisions/index.js +695 -0
- package/src/features/sections/column-collection.d.ts +119 -0
- package/src/features/sections/column-collection.js +478 -0
- package/src/features/sections/column.d.ts +15 -0
- package/src/features/sections/column.js +37 -0
- package/src/features/sections/index.d.ts +91 -0
- package/src/features/sections/index.js +1096 -0
- package/src/features/sections/margins.d.ts +40 -0
- package/src/features/sections/margins.js +105 -0
- package/src/features/sections/page-number-style.d.ts +21 -0
- package/src/features/sections/page-number-style.js +62 -0
- package/src/features/sections/page-orientation.d.ts +10 -0
- package/src/features/sections/page-orientation.js +10 -0
- package/src/features/sections/page-setup.d.ts +435 -0
- package/src/features/sections/page-setup.js +1479 -0
- package/src/features/sections/page-size.d.ts +59 -0
- package/src/features/sections/page-size.js +68 -0
- package/src/features/sections/section-break-code.d.ts +27 -0
- package/src/features/sections/section-break-code.js +60 -0
- package/src/features/sections/section-document-association.d.ts +18 -0
- package/src/features/sections/section-document-association.js +31 -0
- package/src/features/sections/section-validation.d.ts +43 -0
- package/src/features/sections/section-validation.js +97 -0
- package/src/features/settings/attached-template.d.ts +35 -0
- package/src/features/settings/attached-template.js +98 -0
- package/src/features/settings/compat-settings.d.ts +216 -0
- package/src/features/settings/compat-settings.js +508 -0
- package/src/features/settings/document-background.d.ts +59 -0
- package/src/features/settings/document-background.js +131 -0
- package/src/features/settings/document-protection.d.ts +65 -0
- package/src/features/settings/document-protection.js +157 -0
- package/src/features/settings/document-settings-facades.d.ts +108 -0
- package/src/features/settings/document-settings-facades.js +312 -0
- package/src/features/settings/document-settings-values.d.ts +43 -0
- package/src/features/settings/document-settings-values.js +60 -0
- package/src/features/settings/footnote-properties.d.ts +211 -0
- package/src/features/settings/footnote-properties.js +591 -0
- package/src/features/settings/index.d.ts +356 -0
- package/src/features/settings/index.js +829 -0
- package/src/features/settings/settings-children.d.ts +151 -0
- package/src/features/settings/settings-children.js +505 -0
- package/src/features/settings/web-settings.d.ts +88 -0
- package/src/features/settings/web-settings.js +227 -0
- package/src/features/settings/zoom.d.ts +79 -0
- package/src/features/settings/zoom.js +147 -0
- package/src/features/styles/builtin-catalog.d.ts +159 -0
- package/src/features/styles/builtin-catalog.js +963 -0
- package/src/features/styles/builtin-resolver.d.ts +49 -0
- package/src/features/styles/builtin-resolver.js +165 -0
- package/src/features/styles/default-styles.d.ts +37 -0
- package/src/features/styles/default-styles.js +186 -0
- package/src/features/styles/default-theme.d.ts +13 -0
- package/src/features/styles/default-theme.js +13 -0
- package/src/features/styles/doc-defaults.d.ts +58 -0
- package/src/features/styles/doc-defaults.js +178 -0
- package/src/features/styles/formatting-resolver.d.ts +27 -0
- package/src/features/styles/formatting-resolver.js +72 -0
- package/src/features/styles/index.d.ts +256 -0
- package/src/features/styles/index.js +1325 -0
- package/src/features/styles/latent-styles.d.ts +68 -0
- package/src/features/styles/latent-styles.js +305 -0
- package/src/features/styles/paragraph-properties.d.ts +71 -0
- package/src/features/styles/paragraph-properties.js +237 -0
- package/src/features/styles/run-properties.d.ts +93 -0
- package/src/features/styles/run-properties.js +516 -0
- package/src/features/styles/style-base.d.ts +402 -0
- package/src/features/styles/style-base.js +1026 -0
- package/src/features/styles/style-collection.d.ts +264 -0
- package/src/features/styles/style-collection.js +714 -0
- package/src/features/styles/style-format-bridge.d.ts +64 -0
- package/src/features/styles/style-format-bridge.js +100 -0
- package/src/features/styles/style.d.ts +84 -0
- package/src/features/styles/style.js +375 -0
- package/src/features/styles/styles-with-effects.d.ts +71 -0
- package/src/features/styles/styles-with-effects.js +180 -0
- package/src/features/styles/table-style.d.ts +272 -0
- package/src/features/styles/table-style.js +1226 -0
- package/src/features/styles/theme.d.ts +126 -0
- package/src/features/styles/theme.js +377 -0
- package/src/features/tables/border-style-map.d.ts +24 -0
- package/src/features/tables/border-style-map.js +81 -0
- package/src/features/tables/borders.d.ts +126 -0
- package/src/features/tables/borders.js +527 -0
- package/src/features/tables/collections.d.ts +113 -0
- package/src/features/tables/collections.js +261 -0
- package/src/features/tables/format.d.ts +208 -0
- package/src/features/tables/format.js +716 -0
- package/src/features/tables/index.d.ts +597 -0
- package/src/features/tables/index.js +2386 -0
- package/src/features/tables/paddings.d.ts +41 -0
- package/src/features/tables/paddings.js +97 -0
- package/src/features/tables/tbl-pr-positioning.d.ts +27 -0
- package/src/features/tables/tbl-pr-positioning.js +178 -0
- package/src/features/tables/tbl-pr.d.ts +528 -0
- package/src/features/tables/tbl-pr.js +1208 -0
- package/src/features/tables/tc-pr.d.ts +168 -0
- package/src/features/tables/tc-pr.js +553 -0
- package/src/features/tables/tr-pr.d.ts +60 -0
- package/src/features/tables/tr-pr.js +215 -0
- package/src/features/watermark/detect.d.ts +76 -0
- package/src/features/watermark/detect.js +219 -0
- package/src/features/watermark/index.d.ts +28 -0
- package/src/features/watermark/index.js +91 -0
- package/src/features/watermark/logical-store.d.ts +29 -0
- package/src/features/watermark/logical-store.js +31 -0
- package/src/features/watermark/model.d.ts +285 -0
- package/src/features/watermark/model.js +597 -0
- package/src/features/watermark/parse.d.ts +84 -0
- package/src/features/watermark/parse.js +815 -0
- package/src/features/watermark/serialize.d.ts +98 -0
- package/src/features/watermark/serialize.js +1517 -0
- package/src/global.js +1 -0
- package/src/index.d.ts +2 -0
- package/src/index.js +2 -0
|
@@ -0,0 +1,1429 @@
|
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
13
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
14
|
+
if (!m) return o;
|
|
15
|
+
var i = m.call(o), r, ar = [], e;
|
|
16
|
+
try {
|
|
17
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
18
|
+
}
|
|
19
|
+
catch (error) { e = { error: error }; }
|
|
20
|
+
finally {
|
|
21
|
+
try {
|
|
22
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
23
|
+
}
|
|
24
|
+
finally { if (e) throw e.error; }
|
|
25
|
+
}
|
|
26
|
+
return ar;
|
|
27
|
+
};
|
|
28
|
+
var __spread = (this && this.__spread) || function () {
|
|
29
|
+
for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i]));
|
|
30
|
+
return ar;
|
|
31
|
+
};
|
|
32
|
+
var __values = (this && this.__values) || function (o) {
|
|
33
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator], i = 0;
|
|
34
|
+
if (m) return m.call(o);
|
|
35
|
+
return {
|
|
36
|
+
next: function () {
|
|
37
|
+
if (o && i >= o.length) o = void 0;
|
|
38
|
+
return { value: o && o[i++], done: !o };
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
export * from './caption-authoring-api';
|
|
43
|
+
export * from './caption-enums';
|
|
44
|
+
export * from './caption-host';
|
|
45
|
+
export * from './captions';
|
|
46
|
+
export * from './host-codec';
|
|
47
|
+
export * from './image-sniff';
|
|
48
|
+
export * from './layout-types';
|
|
49
|
+
import { sha256Hex } from '../../core/compat/sha256';
|
|
50
|
+
import { DocxError } from '../../core/errors/docx-error';
|
|
51
|
+
import { registerAlwaysOnBodyFeatureBootstrap } from '../document/body-always-on';
|
|
52
|
+
import { WordDocument } from '../document/document';
|
|
53
|
+
import { EntityType } from '../document/entity-type';
|
|
54
|
+
import { pointToEmus, emuToPoint, scalePoint, pxToPoint } from '../document/length';
|
|
55
|
+
import { Paragraph } from '../document/paragraph';
|
|
56
|
+
import { FeatureInlineParagraphItem, FeatureRunParagraphItem } from '../document/text-range';
|
|
57
|
+
import { allocateRelationshipId, relationshipsWith, TargetMode } from '../../core/opc/relationships';
|
|
58
|
+
import { partByName, relationshipsForPart, withPartRelationships } from '../../core/opc/package';
|
|
59
|
+
import { partName, partNameKey, resolveInternalTarget } from '../../core/opc/part-name';
|
|
60
|
+
import { featureId, registerFeature, registerFeatureMaterializeHandler, registerFeatureMultiPartHandler, registerFeatureRunLeafHandler, replaceOrAddPackagePart, usedMainDocumentRelationshipIds, visitParagraphsInDocumentOrder, } from '../../core/registry/index';
|
|
61
|
+
import { sniffImageContentType, sniffImagePixelDimensions } from './image-sniff';
|
|
62
|
+
import { requirePictureCaptionAuthoring } from './caption-authoring-api';
|
|
63
|
+
import { bindCaptionHostDocument, hostDocumentOf } from './caption-host';
|
|
64
|
+
import { decodePictureHost, encodePictureHost } from './host-codec';
|
|
65
|
+
import { assertEnumMember, HORIZONTAL_ALIGNMENT_SET, HORIZONTAL_ORIGIN_SET, HorizontalOrigin, PicturePlacement, PICTURE_PLACEMENT_SET, TEXT_WRAPPING_STYLE_SET, TextWrappingStyle, VERTICAL_ALIGNMENT_SET, VERTICAL_ORIGIN_SET, VerticalOrigin } from './layout-types';
|
|
66
|
+
var IMAGES = featureId('images');
|
|
67
|
+
/**
|
|
68
|
+
* @private Transitional image relationship (ECMA-376-4 §9.2.10). */
|
|
69
|
+
export var IMAGE_RELATIONSHIP_TYPE = 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/image';
|
|
70
|
+
/**
|
|
71
|
+
* @private Strict image relationship (ECMA-376-1 §11.3.10). */
|
|
72
|
+
export var STRICT_IMAGE_RELATIONSHIP_TYPE = 'http://purl.oclc.org/ooxml/officeDocument/relationships/image';
|
|
73
|
+
var IMAGE_RELATIONSHIP_TYPES = [IMAGE_RELATIONSHIP_TYPE, STRICT_IMAGE_RELATIONSHIP_TYPE];
|
|
74
|
+
/**
|
|
75
|
+
* @private PNG media type (ECMA-376-1 §15.2.14). */
|
|
76
|
+
var PNG_CONTENT_TYPE = 'image/png';
|
|
77
|
+
/**
|
|
78
|
+
* @private JPEG media type (ECMA-376-1 §15.2.14). */
|
|
79
|
+
var JPEG_CONTENT_TYPE = 'image/jpeg';
|
|
80
|
+
/** Default display size (points) when intrinsic pixels cannot be sniffed. */
|
|
81
|
+
var DEFAULT_IMAGE_WIDTH_PT = 100;
|
|
82
|
+
var DEFAULT_IMAGE_HEIGHT_PT = 100;
|
|
83
|
+
function resolveImageLayout(bytes, options) {
|
|
84
|
+
var opts = options != null ? options : {};
|
|
85
|
+
var pixels = sniffImagePixelDimensions(bytes);
|
|
86
|
+
var hasW = opts.width !== undefined;
|
|
87
|
+
var hasH = opts.height !== undefined;
|
|
88
|
+
var width;
|
|
89
|
+
var height;
|
|
90
|
+
if (hasW && hasH) {
|
|
91
|
+
width = opts.width;
|
|
92
|
+
height = opts.height;
|
|
93
|
+
}
|
|
94
|
+
else if (hasW && !hasH) {
|
|
95
|
+
width = opts.width;
|
|
96
|
+
if (pixels !== undefined && pixels.width > 0) {
|
|
97
|
+
height = scalePoint(width, pixels.height / pixels.width);
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
height = DEFAULT_IMAGE_HEIGHT_PT;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
else if (!hasW && hasH) {
|
|
104
|
+
height = opts.height;
|
|
105
|
+
if (pixels !== undefined && pixels.height > 0) {
|
|
106
|
+
width = scalePoint(height, pixels.width / pixels.height);
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
width = DEFAULT_IMAGE_WIDTH_PT;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
else if (pixels !== undefined && pixels.width > 0 && pixels.height > 0) {
|
|
113
|
+
width = pxToPoint(pixels.width);
|
|
114
|
+
height = pxToPoint(pixels.height);
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
width = DEFAULT_IMAGE_WIDTH_PT;
|
|
118
|
+
height = DEFAULT_IMAGE_HEIGHT_PT;
|
|
119
|
+
}
|
|
120
|
+
var sniffed = sniffImageContentType(bytes);
|
|
121
|
+
var contentType = opts.imageType != null ? opts.imageType : sniffed;
|
|
122
|
+
if (contentType === undefined) {
|
|
123
|
+
throw new DocxError('content/invalid-image', 'Image contentType is required when bytes are not PNG or JPEG');
|
|
124
|
+
}
|
|
125
|
+
return { width: width, height: height, contentType: contentType };
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Build {@link ImageInit} without writing `undefined` into optional
|
|
129
|
+
* fields (`exactOptionalPropertyTypes`).
|
|
130
|
+
*/
|
|
131
|
+
function imageInit(parts) {
|
|
132
|
+
return __assign({ relationshipId: parts.relationshipId, width: parts.width, height: parts.height }, (parts.name !== undefined ? { name: parts.name } : {}), (parts.title !== undefined ? { title: parts.title } : {}), (parts.description !== undefined ? { description: parts.description } : {}), (parts.lockAspectRatio !== undefined
|
|
133
|
+
? { lockAspectRatio: parts.lockAspectRatio }
|
|
134
|
+
: {}), (parts.rotation !== undefined ? { rotation: parts.rotation } : {}), (parts.flipHorizontal !== undefined
|
|
135
|
+
? { flipHorizontal: parts.flipHorizontal }
|
|
136
|
+
: {}), (parts.flipVertical !== undefined ? { flipVertical: parts.flipVertical } : {}), (parts.placement !== undefined ? { placement: parts.placement } : {}), (parts.wrapping !== undefined ? { wrapping: parts.wrapping } : {}), (parts.horizontalOrigin !== undefined
|
|
137
|
+
? { horizontalOrigin: parts.horizontalOrigin }
|
|
138
|
+
: {}), (parts.verticalOrigin !== undefined
|
|
139
|
+
? { verticalOrigin: parts.verticalOrigin }
|
|
140
|
+
: {}), (parts.horizontalPosition !== undefined
|
|
141
|
+
? { horizontalPosition: parts.horizontalPosition }
|
|
142
|
+
: {}), (parts.verticalPosition !== undefined
|
|
143
|
+
? { verticalPosition: parts.verticalPosition }
|
|
144
|
+
: {}), (parts.horizontalAlignment !== undefined
|
|
145
|
+
? { horizontalAlignment: parts.horizontalAlignment }
|
|
146
|
+
: {}), (parts.verticalAlignment !== undefined
|
|
147
|
+
? { verticalAlignment: parts.verticalAlignment }
|
|
148
|
+
: {}), (parts.docPrId !== undefined ? { docPrId: parts.docPrId } : {}), (parts.preservedHost !== undefined ? { preservedHost: parts.preservedHost } : {}), (parts.layoutDirty !== undefined ? { layoutDirty: parts.layoutDirty } : {}), (parts.hyperlinkRelationshipId !== undefined
|
|
149
|
+
? { hyperlinkRelationshipId: parts.hyperlinkRelationshipId }
|
|
150
|
+
: {}), (parts.hyperlinkTarget !== undefined ? { hyperlinkTarget: parts.hyperlinkTarget } : {}));
|
|
151
|
+
}
|
|
152
|
+
function resolvePlacementAndWrapping(placement, wrapping) {
|
|
153
|
+
var wrap = wrapping != null ? wrapping : TextWrappingStyle.Inline;
|
|
154
|
+
if (wrap !== TextWrappingStyle.Inline) {
|
|
155
|
+
return { placement: PicturePlacement.Anchored, wrapping: wrap };
|
|
156
|
+
}
|
|
157
|
+
if (placement === PicturePlacement.Anchored) {
|
|
158
|
+
return { placement: PicturePlacement.Anchored, wrapping: TextWrappingStyle.None };
|
|
159
|
+
}
|
|
160
|
+
return { placement: PicturePlacement.Inline, wrapping: TextWrappingStyle.Inline };
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* DrawingML picture leaf in a paragraph (`w:r/w:drawing` with `wp:inline`
|
|
164
|
+
* or `wp:anchor` + `pic:pic`).
|
|
165
|
+
*
|
|
166
|
+
* Setting {@link Image.textWrappingStyle} to a non-inline value promotes the host
|
|
167
|
+
* to `wp:anchor`. Setting wrapping back to `'inline'` collapses to `wp:inline`
|
|
168
|
+
* and **drops** anchor position/wrap residual by design — see TSDoc on
|
|
169
|
+
* {@link Image.textWrappingStyle}.
|
|
170
|
+
*
|
|
171
|
+
* @public
|
|
172
|
+
*/
|
|
173
|
+
var Picture = /** @class */ (function () {
|
|
174
|
+
function Picture(documentOrRelationshipIdOrInit, width, height) {
|
|
175
|
+
/**
|
|
176
|
+
* Public discriminant for {@link Paragraph.items} ({@link EntityType.Picture}).
|
|
177
|
+
* @public
|
|
178
|
+
*/
|
|
179
|
+
this.type = EntityType.Picture;
|
|
180
|
+
if (documentOrRelationshipIdOrInit instanceof WordDocument) {
|
|
181
|
+
this.relationshipIdValue = '';
|
|
182
|
+
this.widthValue = DEFAULT_IMAGE_WIDTH_PT;
|
|
183
|
+
this.heightValue = DEFAULT_IMAGE_HEIGHT_PT;
|
|
184
|
+
this.nameValue = 'Picture';
|
|
185
|
+
this.titleValue = undefined;
|
|
186
|
+
this.descriptionValue = undefined;
|
|
187
|
+
this.lockAspectRatioValue = true;
|
|
188
|
+
this.rotationValue = 0;
|
|
189
|
+
this.flipHorizontalValue = false;
|
|
190
|
+
this.flipVerticalValue = false;
|
|
191
|
+
this.placementValue = PicturePlacement.Inline;
|
|
192
|
+
this.wrappingValue = TextWrappingStyle.Inline;
|
|
193
|
+
this.horizontalOriginValue = undefined;
|
|
194
|
+
this.verticalOriginValue = undefined;
|
|
195
|
+
this.horizontalPositionValue = undefined;
|
|
196
|
+
this.verticalPositionValue = undefined;
|
|
197
|
+
this.horizontalAlignmentValue = undefined;
|
|
198
|
+
this.verticalAlignmentValue = undefined;
|
|
199
|
+
this.docPrIdValue = 1;
|
|
200
|
+
this.preservedHostValue = undefined;
|
|
201
|
+
this.layoutDirtyValue = true;
|
|
202
|
+
this.hyperlinkRelationshipIdValue = undefined;
|
|
203
|
+
this.hyperlinkTargetValue = undefined;
|
|
204
|
+
bindCaptionHostDocument(this, documentOrRelationshipIdOrInit);
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
var init = typeof documentOrRelationshipIdOrInit === 'string'
|
|
208
|
+
? {
|
|
209
|
+
relationshipId: documentOrRelationshipIdOrInit,
|
|
210
|
+
width: width,
|
|
211
|
+
height: height,
|
|
212
|
+
}
|
|
213
|
+
: documentOrRelationshipIdOrInit;
|
|
214
|
+
var resolved = resolvePlacementAndWrapping(init.placement, init.wrapping);
|
|
215
|
+
this.relationshipIdValue = init.relationshipId;
|
|
216
|
+
this.widthValue = init.width;
|
|
217
|
+
this.heightValue = init.height;
|
|
218
|
+
this.nameValue = init.name != null ? init.name : 'Picture';
|
|
219
|
+
this.titleValue = init.title;
|
|
220
|
+
this.descriptionValue = init.description;
|
|
221
|
+
this.lockAspectRatioValue = init.lockAspectRatio != null ? init.lockAspectRatio : true;
|
|
222
|
+
this.rotationValue = init.rotation != null ? init.rotation : 0;
|
|
223
|
+
this.flipHorizontalValue = init.flipHorizontal != null ? init.flipHorizontal : false;
|
|
224
|
+
this.flipVerticalValue = init.flipVertical != null ? init.flipVertical : false;
|
|
225
|
+
this.placementValue = resolved.placement;
|
|
226
|
+
this.wrappingValue = resolved.wrapping;
|
|
227
|
+
this.horizontalOriginValue = init.horizontalOrigin;
|
|
228
|
+
this.verticalOriginValue = init.verticalOrigin;
|
|
229
|
+
this.horizontalPositionValue = init.horizontalPosition;
|
|
230
|
+
this.verticalPositionValue = init.verticalPosition;
|
|
231
|
+
this.horizontalAlignmentValue = init.horizontalAlignment;
|
|
232
|
+
this.verticalAlignmentValue = init.verticalAlignment;
|
|
233
|
+
this.docPrIdValue = init.docPrId != null ? init.docPrId : 1;
|
|
234
|
+
this.preservedHostValue = init.preservedHost;
|
|
235
|
+
this.layoutDirtyValue = init.layoutDirty != null ? init.layoutDirty : init.preservedHost === undefined;
|
|
236
|
+
this.hyperlinkRelationshipIdValue = init.hyperlinkRelationshipId;
|
|
237
|
+
this.hyperlinkTargetValue = init.hyperlinkTarget;
|
|
238
|
+
}
|
|
239
|
+
/** @private Build from decoded host state. */
|
|
240
|
+
Picture.fromHostState = function (state) {
|
|
241
|
+
return new Picture(imageInit({
|
|
242
|
+
relationshipId: state.relationshipId,
|
|
243
|
+
width: emuToPoint(state.widthEmu),
|
|
244
|
+
height: emuToPoint(state.heightEmu),
|
|
245
|
+
name: state.name,
|
|
246
|
+
title: state.title,
|
|
247
|
+
description: state.description,
|
|
248
|
+
lockAspectRatio: state.lockAspectRatio,
|
|
249
|
+
rotation: state.rotation,
|
|
250
|
+
flipHorizontal: state.flipHorizontal,
|
|
251
|
+
flipVertical: state.flipVertical,
|
|
252
|
+
placement: state.placement,
|
|
253
|
+
wrapping: state.wrapping,
|
|
254
|
+
horizontalOrigin: state.horizontalOrigin,
|
|
255
|
+
verticalOrigin: state.verticalOrigin,
|
|
256
|
+
horizontalPosition: state.horizontalPosition,
|
|
257
|
+
verticalPosition: state.verticalPosition,
|
|
258
|
+
horizontalAlignment: state.horizontalAlignment,
|
|
259
|
+
verticalAlignment: state.verticalAlignment,
|
|
260
|
+
docPrId: state.docPrId,
|
|
261
|
+
preservedHost: state.preservedHost,
|
|
262
|
+
layoutDirty: false,
|
|
263
|
+
hyperlinkRelationshipId: state.hyperlinkRelationshipId,
|
|
264
|
+
}));
|
|
265
|
+
};
|
|
266
|
+
Object.defineProperty(Picture.prototype, "width", {
|
|
267
|
+
/** Display width in points (`wp:extent/@cx` EMU at host boundary). */
|
|
268
|
+
get: function () {
|
|
269
|
+
return this.widthValue;
|
|
270
|
+
},
|
|
271
|
+
set: function (value) {
|
|
272
|
+
this.widthValue = value;
|
|
273
|
+
this.layoutDirtyValue = true;
|
|
274
|
+
},
|
|
275
|
+
enumerable: true,
|
|
276
|
+
configurable: true
|
|
277
|
+
});
|
|
278
|
+
Object.defineProperty(Picture.prototype, "height", {
|
|
279
|
+
/** Display height in points (`wp:extent/@cy` EMU at host boundary). */
|
|
280
|
+
get: function () {
|
|
281
|
+
return this.heightValue;
|
|
282
|
+
},
|
|
283
|
+
set: function (value) {
|
|
284
|
+
this.heightValue = value;
|
|
285
|
+
this.layoutDirtyValue = true;
|
|
286
|
+
},
|
|
287
|
+
enumerable: true,
|
|
288
|
+
configurable: true
|
|
289
|
+
});
|
|
290
|
+
Object.defineProperty(Picture.prototype, "hyperlinkRelationshipId", {
|
|
291
|
+
/**
|
|
292
|
+
* @private
|
|
293
|
+
* DrawingML picture hyperlink relationship id (`a:hlinkClick/@r:id`).
|
|
294
|
+
*/
|
|
295
|
+
get: function () {
|
|
296
|
+
return this.hyperlinkRelationshipIdValue;
|
|
297
|
+
},
|
|
298
|
+
set: function (value) {
|
|
299
|
+
this.hyperlinkRelationshipIdValue = value;
|
|
300
|
+
this.layoutDirtyValue = true;
|
|
301
|
+
},
|
|
302
|
+
enumerable: true,
|
|
303
|
+
configurable: true
|
|
304
|
+
});
|
|
305
|
+
Object.defineProperty(Picture.prototype, "hyperlinkTarget", {
|
|
306
|
+
/**
|
|
307
|
+
* @private
|
|
308
|
+
* Runtime target URI for a picture-backed hyperlink. Not written to the
|
|
309
|
+
* picture DrawingML tree; the package relationship carries the target.
|
|
310
|
+
*/
|
|
311
|
+
get: function () {
|
|
312
|
+
return this.hyperlinkTargetValue;
|
|
313
|
+
},
|
|
314
|
+
set: function (value) {
|
|
315
|
+
this.hyperlinkTargetValue = value;
|
|
316
|
+
},
|
|
317
|
+
enumerable: true,
|
|
318
|
+
configurable: true
|
|
319
|
+
});
|
|
320
|
+
Object.defineProperty(Picture.prototype, "relationshipId", {
|
|
321
|
+
/**
|
|
322
|
+
* @private
|
|
323
|
+
* Relationship id for the image media part; empty until materialized at save. */
|
|
324
|
+
get: function () {
|
|
325
|
+
return this.relationshipIdValue;
|
|
326
|
+
},
|
|
327
|
+
enumerable: true,
|
|
328
|
+
configurable: true
|
|
329
|
+
});
|
|
330
|
+
Object.defineProperty(Picture.prototype, "name", {
|
|
331
|
+
/**
|
|
332
|
+
* Non-visual picture name (`wp:docPr/@name`, `pic:cNvPr/@name`).
|
|
333
|
+
* @defaultValue `'Picture'` on authoring.
|
|
334
|
+
*/
|
|
335
|
+
get: function () {
|
|
336
|
+
return this.nameValue;
|
|
337
|
+
},
|
|
338
|
+
set: function (value) {
|
|
339
|
+
this.nameValue = value;
|
|
340
|
+
this.layoutDirtyValue = true;
|
|
341
|
+
},
|
|
342
|
+
enumerable: true,
|
|
343
|
+
configurable: true
|
|
344
|
+
});
|
|
345
|
+
Object.defineProperty(Picture.prototype, "title", {
|
|
346
|
+
/**
|
|
347
|
+
* Caption / accessibility title (`wp:docPr/@title`).
|
|
348
|
+
* Not the same as {@link description} (`@descr`).
|
|
349
|
+
*/
|
|
350
|
+
get: function () {
|
|
351
|
+
return this.titleValue;
|
|
352
|
+
},
|
|
353
|
+
set: function (value) {
|
|
354
|
+
this.titleValue = value;
|
|
355
|
+
this.layoutDirtyValue = true;
|
|
356
|
+
},
|
|
357
|
+
enumerable: true,
|
|
358
|
+
configurable: true
|
|
359
|
+
});
|
|
360
|
+
Object.defineProperty(Picture.prototype, "description", {
|
|
361
|
+
/** Alternative text (`wp:docPr/@descr`). */
|
|
362
|
+
get: function () {
|
|
363
|
+
return this.descriptionValue;
|
|
364
|
+
},
|
|
365
|
+
set: function (value) {
|
|
366
|
+
this.descriptionValue = value;
|
|
367
|
+
this.layoutDirtyValue = true;
|
|
368
|
+
},
|
|
369
|
+
enumerable: true,
|
|
370
|
+
configurable: true
|
|
371
|
+
});
|
|
372
|
+
Object.defineProperty(Picture.prototype, "lockAspectRatio", {
|
|
373
|
+
/**
|
|
374
|
+
* Aspect-ratio lock (`a:graphicFrameLocks/@noChangeAspect`).
|
|
375
|
+
* Authoring default is `true`; missing locks on load read as `false`.
|
|
376
|
+
*/
|
|
377
|
+
get: function () {
|
|
378
|
+
return this.lockAspectRatioValue;
|
|
379
|
+
},
|
|
380
|
+
set: function (value) {
|
|
381
|
+
this.lockAspectRatioValue = value;
|
|
382
|
+
this.layoutDirtyValue = true;
|
|
383
|
+
},
|
|
384
|
+
enumerable: true,
|
|
385
|
+
configurable: true
|
|
386
|
+
});
|
|
387
|
+
Object.defineProperty(Picture.prototype, "rotation", {
|
|
388
|
+
/**
|
|
389
|
+
* Clockwise rotation in degrees (`a:xfrm/@rot`).
|
|
390
|
+
* Wire uses ST_Angle = degrees × 60000.
|
|
391
|
+
*/
|
|
392
|
+
get: function () {
|
|
393
|
+
return this.rotationValue;
|
|
394
|
+
},
|
|
395
|
+
set: function (value) {
|
|
396
|
+
if (!Number.isFinite(value)) {
|
|
397
|
+
throw new RangeError("Invalid rotation value \"" + String(value) + "\"; expected a finite number");
|
|
398
|
+
}
|
|
399
|
+
this.rotationValue = value;
|
|
400
|
+
this.layoutDirtyValue = true;
|
|
401
|
+
},
|
|
402
|
+
enumerable: true,
|
|
403
|
+
configurable: true
|
|
404
|
+
});
|
|
405
|
+
Object.defineProperty(Picture.prototype, "flipHorizontal", {
|
|
406
|
+
/** Horizontal flip (`a:xfrm/@flipH`). */
|
|
407
|
+
get: function () {
|
|
408
|
+
return this.flipHorizontalValue;
|
|
409
|
+
},
|
|
410
|
+
set: function (value) {
|
|
411
|
+
this.flipHorizontalValue = value;
|
|
412
|
+
this.layoutDirtyValue = true;
|
|
413
|
+
},
|
|
414
|
+
enumerable: true,
|
|
415
|
+
configurable: true
|
|
416
|
+
});
|
|
417
|
+
Object.defineProperty(Picture.prototype, "flipVertical", {
|
|
418
|
+
/** Vertical flip (`a:xfrm/@flipV`). */
|
|
419
|
+
get: function () {
|
|
420
|
+
return this.flipVerticalValue;
|
|
421
|
+
},
|
|
422
|
+
set: function (value) {
|
|
423
|
+
this.flipVerticalValue = value;
|
|
424
|
+
this.layoutDirtyValue = true;
|
|
425
|
+
},
|
|
426
|
+
enumerable: true,
|
|
427
|
+
configurable: true
|
|
428
|
+
});
|
|
429
|
+
Object.defineProperty(Picture.prototype, "placement", {
|
|
430
|
+
/**
|
|
431
|
+
* Host placement (`wp:inline` vs `wp:anchor`).
|
|
432
|
+
* Prefer mutating {@link textWrappingStyle}; non-inline wrapping forces anchored.
|
|
433
|
+
*/
|
|
434
|
+
get: function () {
|
|
435
|
+
return this.placementValue;
|
|
436
|
+
},
|
|
437
|
+
set: function (value) {
|
|
438
|
+
assertEnumMember('placement', value, PICTURE_PLACEMENT_SET);
|
|
439
|
+
this.placementValue = value;
|
|
440
|
+
if (value === PicturePlacement.Inline) {
|
|
441
|
+
this.wrappingValue = TextWrappingStyle.Inline;
|
|
442
|
+
}
|
|
443
|
+
else if (this.wrappingValue === TextWrappingStyle.Inline) {
|
|
444
|
+
this.wrappingValue = TextWrappingStyle.None;
|
|
445
|
+
}
|
|
446
|
+
this.layoutDirtyValue = true;
|
|
447
|
+
},
|
|
448
|
+
enumerable: true,
|
|
449
|
+
configurable: true
|
|
450
|
+
});
|
|
451
|
+
Object.defineProperty(Picture.prototype, "textWrappingStyle", {
|
|
452
|
+
/**
|
|
453
|
+
* Text wrapping style.
|
|
454
|
+
*
|
|
455
|
+
* - `'inline'` serializes as `wp:inline`. Collapsing an anchored picture to
|
|
456
|
+
* inline **drops** position and wrap residual by design.
|
|
457
|
+
* - Other values promote to `wp:anchor` with the matching wrap element.
|
|
458
|
+
* Tight/through without a residual wrapPolygon fall back to `wrapNone`
|
|
459
|
+
* (library does not invent polygons).
|
|
460
|
+
*
|
|
461
|
+
* @throws RangeError when `value` is not a known {@link TextWrappingStyle}.
|
|
462
|
+
*/
|
|
463
|
+
get: function () {
|
|
464
|
+
return this.wrappingValue;
|
|
465
|
+
},
|
|
466
|
+
set: function (value) {
|
|
467
|
+
assertEnumMember('textWrappingStyle', value, TEXT_WRAPPING_STYLE_SET);
|
|
468
|
+
this.wrappingValue = value;
|
|
469
|
+
if (value === TextWrappingStyle.Inline) {
|
|
470
|
+
this.placementValue = PicturePlacement.Inline;
|
|
471
|
+
}
|
|
472
|
+
else {
|
|
473
|
+
this.placementValue = PicturePlacement.Anchored;
|
|
474
|
+
}
|
|
475
|
+
this.layoutDirtyValue = true;
|
|
476
|
+
},
|
|
477
|
+
enumerable: true,
|
|
478
|
+
configurable: true
|
|
479
|
+
});
|
|
480
|
+
Object.defineProperty(Picture.prototype, "wrapping", {
|
|
481
|
+
/**
|
|
482
|
+
|
|
483
|
+
*/
|
|
484
|
+
get: function () {
|
|
485
|
+
return this.textWrappingStyle;
|
|
486
|
+
},
|
|
487
|
+
/**
|
|
488
|
+
|
|
489
|
+
*/
|
|
490
|
+
set: function (value) {
|
|
491
|
+
this.textWrappingStyle = value;
|
|
492
|
+
},
|
|
493
|
+
enumerable: true,
|
|
494
|
+
configurable: true
|
|
495
|
+
});
|
|
496
|
+
Object.defineProperty(Picture.prototype, "horizontalOrigin", {
|
|
497
|
+
/** Horizontal origin (`wp:positionH/@relativeFrom`). */
|
|
498
|
+
get: function () {
|
|
499
|
+
return this.horizontalOriginValue;
|
|
500
|
+
},
|
|
501
|
+
set: function (value) {
|
|
502
|
+
if (value !== undefined) {
|
|
503
|
+
assertEnumMember('horizontalOrigin', value, HORIZONTAL_ORIGIN_SET);
|
|
504
|
+
}
|
|
505
|
+
this.horizontalOriginValue = value;
|
|
506
|
+
this.layoutDirtyValue = true;
|
|
507
|
+
},
|
|
508
|
+
enumerable: true,
|
|
509
|
+
configurable: true
|
|
510
|
+
});
|
|
511
|
+
Object.defineProperty(Picture.prototype, "verticalOrigin", {
|
|
512
|
+
/** Vertical origin (`wp:positionV/@relativeFrom`). */
|
|
513
|
+
get: function () {
|
|
514
|
+
return this.verticalOriginValue;
|
|
515
|
+
},
|
|
516
|
+
set: function (value) {
|
|
517
|
+
if (value !== undefined) {
|
|
518
|
+
assertEnumMember('verticalOrigin', value, VERTICAL_ORIGIN_SET);
|
|
519
|
+
}
|
|
520
|
+
this.verticalOriginValue = value;
|
|
521
|
+
this.layoutDirtyValue = true;
|
|
522
|
+
},
|
|
523
|
+
enumerable: true,
|
|
524
|
+
configurable: true
|
|
525
|
+
});
|
|
526
|
+
Object.defineProperty(Picture.prototype, "horizontalPosition", {
|
|
527
|
+
/**
|
|
528
|
+
* Horizontal offset (`wp:positionH/wp:posOffset`).
|
|
529
|
+
* Setting this clears {@link horizontalAlignment} (align XOR posOffset).
|
|
530
|
+
*/
|
|
531
|
+
get: function () {
|
|
532
|
+
return this.horizontalPositionValue;
|
|
533
|
+
},
|
|
534
|
+
set: function (value) {
|
|
535
|
+
this.horizontalPositionValue = value;
|
|
536
|
+
if (value !== undefined) {
|
|
537
|
+
this.horizontalAlignmentValue = undefined;
|
|
538
|
+
}
|
|
539
|
+
this.layoutDirtyValue = true;
|
|
540
|
+
},
|
|
541
|
+
enumerable: true,
|
|
542
|
+
configurable: true
|
|
543
|
+
});
|
|
544
|
+
Object.defineProperty(Picture.prototype, "verticalPosition", {
|
|
545
|
+
/**
|
|
546
|
+
* Vertical offset (`wp:positionV/wp:posOffset`).
|
|
547
|
+
* Setting this clears {@link verticalAlignment} (align XOR posOffset).
|
|
548
|
+
*/
|
|
549
|
+
get: function () {
|
|
550
|
+
return this.verticalPositionValue;
|
|
551
|
+
},
|
|
552
|
+
set: function (value) {
|
|
553
|
+
this.verticalPositionValue = value;
|
|
554
|
+
if (value !== undefined) {
|
|
555
|
+
this.verticalAlignmentValue = undefined;
|
|
556
|
+
}
|
|
557
|
+
this.layoutDirtyValue = true;
|
|
558
|
+
},
|
|
559
|
+
enumerable: true,
|
|
560
|
+
configurable: true
|
|
561
|
+
});
|
|
562
|
+
Object.defineProperty(Picture.prototype, "horizontalAlignment", {
|
|
563
|
+
/**
|
|
564
|
+
* Horizontal alignment (`wp:positionH/wp:align`).
|
|
565
|
+
* Setting this clears {@link horizontalPosition} (align XOR posOffset).
|
|
566
|
+
*
|
|
567
|
+
* @throws RangeError when `value` is not a known {@link HorizontalAlignment}.
|
|
568
|
+
*/
|
|
569
|
+
get: function () {
|
|
570
|
+
return this.horizontalAlignmentValue;
|
|
571
|
+
},
|
|
572
|
+
set: function (value) {
|
|
573
|
+
if (value !== undefined) {
|
|
574
|
+
assertEnumMember('horizontalAlignment', value, HORIZONTAL_ALIGNMENT_SET);
|
|
575
|
+
this.horizontalPositionValue = undefined;
|
|
576
|
+
}
|
|
577
|
+
this.horizontalAlignmentValue = value;
|
|
578
|
+
this.layoutDirtyValue = true;
|
|
579
|
+
},
|
|
580
|
+
enumerable: true,
|
|
581
|
+
configurable: true
|
|
582
|
+
});
|
|
583
|
+
Object.defineProperty(Picture.prototype, "verticalAlignment", {
|
|
584
|
+
/**
|
|
585
|
+
* Vertical alignment (`wp:positionV/wp:align`).
|
|
586
|
+
* Setting this clears {@link verticalPosition} (align XOR posOffset).
|
|
587
|
+
*
|
|
588
|
+
* @throws RangeError when `value` is not a known {@link VerticalAlignment}.
|
|
589
|
+
*/
|
|
590
|
+
get: function () {
|
|
591
|
+
return this.verticalAlignmentValue;
|
|
592
|
+
},
|
|
593
|
+
set: function (value) {
|
|
594
|
+
if (value !== undefined) {
|
|
595
|
+
assertEnumMember('verticalAlignment', value, VERTICAL_ALIGNMENT_SET);
|
|
596
|
+
this.verticalPositionValue = undefined;
|
|
597
|
+
}
|
|
598
|
+
this.verticalAlignmentValue = value;
|
|
599
|
+
this.layoutDirtyValue = true;
|
|
600
|
+
},
|
|
601
|
+
enumerable: true,
|
|
602
|
+
configurable: true
|
|
603
|
+
});
|
|
604
|
+
/** @private */
|
|
605
|
+
Picture.prototype.isPendingRelationship = function () {
|
|
606
|
+
return this.relationshipIdValue.length === 0;
|
|
607
|
+
};
|
|
608
|
+
/** @private */
|
|
609
|
+
Picture.prototype.resolveRelationshipId = function (relationshipId) {
|
|
610
|
+
this.relationshipIdValue = relationshipId;
|
|
611
|
+
};
|
|
612
|
+
/** @private Apply optional authoring fields from {@link ImageOptions}. */
|
|
613
|
+
Picture.prototype.applyAppendOptions = function (options) {
|
|
614
|
+
if (options.name !== undefined) {
|
|
615
|
+
this.name = options.name;
|
|
616
|
+
}
|
|
617
|
+
if (options.title !== undefined) {
|
|
618
|
+
this.title = options.title;
|
|
619
|
+
}
|
|
620
|
+
if (options.description !== undefined) {
|
|
621
|
+
this.description = options.description;
|
|
622
|
+
}
|
|
623
|
+
if (options.lockAspectRatio !== undefined) {
|
|
624
|
+
this.lockAspectRatio = options.lockAspectRatio;
|
|
625
|
+
}
|
|
626
|
+
if (options.rotation !== undefined) {
|
|
627
|
+
this.rotation = options.rotation;
|
|
628
|
+
}
|
|
629
|
+
if (options.flipHorizontal !== undefined) {
|
|
630
|
+
this.flipHorizontal = options.flipHorizontal;
|
|
631
|
+
}
|
|
632
|
+
if (options.flipVertical !== undefined) {
|
|
633
|
+
this.flipVertical = options.flipVertical;
|
|
634
|
+
}
|
|
635
|
+
var wrap = options.textWrappingStyle !== undefined
|
|
636
|
+
? options.textWrappingStyle
|
|
637
|
+
: options.wrapping;
|
|
638
|
+
if (wrap !== undefined) {
|
|
639
|
+
this.textWrappingStyle = wrap;
|
|
640
|
+
}
|
|
641
|
+
else if (options.placement !== undefined) {
|
|
642
|
+
this.placement = options.placement;
|
|
643
|
+
}
|
|
644
|
+
if (options.horizontalOrigin !== undefined) {
|
|
645
|
+
this.horizontalOrigin = options.horizontalOrigin;
|
|
646
|
+
}
|
|
647
|
+
if (options.verticalOrigin !== undefined) {
|
|
648
|
+
this.verticalOrigin = options.verticalOrigin;
|
|
649
|
+
}
|
|
650
|
+
// Apply align before position so a simultaneous position wins XOR clear.
|
|
651
|
+
if (options.horizontalAlignment !== undefined) {
|
|
652
|
+
this.horizontalAlignment = options.horizontalAlignment;
|
|
653
|
+
}
|
|
654
|
+
if (options.verticalAlignment !== undefined) {
|
|
655
|
+
this.verticalAlignment = options.verticalAlignment;
|
|
656
|
+
}
|
|
657
|
+
if (options.horizontalPosition !== undefined) {
|
|
658
|
+
this.horizontalPosition = options.horizontalPosition;
|
|
659
|
+
}
|
|
660
|
+
if (options.verticalPosition !== undefined) {
|
|
661
|
+
this.verticalPosition = options.verticalPosition;
|
|
662
|
+
}
|
|
663
|
+
};
|
|
664
|
+
/**
|
|
665
|
+
* Add a Word-style caption paragraph next to this picture.
|
|
666
|
+
*
|
|
667
|
+
* Creates a separate caption paragraph (built-in `Caption` style, centered,
|
|
668
|
+
* spacing 30/240 twips) containing a `SEQ <captionName> \* <switch>` complex
|
|
669
|
+
* field (ECMA-376-1 §17.16.5.56), inserted immediately before
|
|
670
|
+
* ({@link CaptionPosition.Above}) or after ({@link CaptionPosition.Below})
|
|
671
|
+
* the paragraph containing this picture. The picture and its paragraph are not
|
|
672
|
+
* moved or modified. The initial field result is the next number in the
|
|
673
|
+
* caption-name sequence; Microsoft Word remains authoritative on refresh.
|
|
674
|
+
*
|
|
675
|
+
* @returns The new caption {@link Paragraph}; append additional caption text
|
|
676
|
+
* or adjust its formatting on the returned object.
|
|
677
|
+
* @throws DocxError `content/invalid-caption-name` when the name is empty or
|
|
678
|
+
* whitespace-only.
|
|
679
|
+
* @throws DocxError `content/invalid-caption-format` /
|
|
680
|
+
* `content/invalid-caption-position` for unknown enum values.
|
|
681
|
+
* @throws DetachedObjectError when this picture is not attached to a paragraph
|
|
682
|
+
* in a main document body.
|
|
683
|
+
*/
|
|
684
|
+
Picture.prototype.addCaption = function (captionName, numberingFormat, position) {
|
|
685
|
+
// Caption authoring reuses fields + styles. Those modules must not enter the
|
|
686
|
+
// always-on core graph; load `./captions.js` (via `@syncfusion/ej2-docx/images` public
|
|
687
|
+
// entry or a direct import) so the provider is installed first.
|
|
688
|
+
return requirePictureCaptionAuthoring()(this, captionName, numberingFormat, position);
|
|
689
|
+
};
|
|
690
|
+
/**
|
|
691
|
+
* Load image bytes into this picture instance.
|
|
692
|
+
*
|
|
693
|
+
* Loads image content into the current `Picture` instance, supporting:
|
|
694
|
+
* - Newly created pictures
|
|
695
|
+
* - Pictures loaded from existing documents
|
|
696
|
+
*
|
|
697
|
+
* If the picture already contains image data, calling `loadImage()` replaces
|
|
698
|
+
* the existing image with the newly supplied image bytes. The replacement
|
|
699
|
+
* occurs within the same `Picture` instance — no remove-and-add operation
|
|
700
|
+
* is required.
|
|
701
|
+
*
|
|
702
|
+
* The Picture instance remains attached to its parent container after image
|
|
703
|
+
* replacement. Parent references, collection indexes, and existing object
|
|
704
|
+
* references remain unchanged. Only the underlying image data is replaced.
|
|
705
|
+
*
|
|
706
|
+
* @example
|
|
707
|
+
* ```typescript
|
|
708
|
+
* // Load image into a newly created picture
|
|
709
|
+
* const picture = new Picture(document);
|
|
710
|
+
* picture.loadImage(imageBytes);
|
|
711
|
+
*
|
|
712
|
+
* // Replace existing picture content (same instance / collection index)
|
|
713
|
+
* const picture = paragraph.items[0] as Picture;
|
|
714
|
+
* picture.loadImage(newImageBytes);
|
|
715
|
+
* ```
|
|
716
|
+
*
|
|
717
|
+
* @param imageBytes - Image data as `Uint8Array` (PNG or JPEG)
|
|
718
|
+
* @throws DocxError when the picture is not attached to a document
|
|
719
|
+
* @public
|
|
720
|
+
*/
|
|
721
|
+
Picture.prototype.loadImage = function (imageBytes) {
|
|
722
|
+
var document = hostDocumentOf(this);
|
|
723
|
+
if (document === undefined) {
|
|
724
|
+
throw new DocxError('model/detached-object', 'Picture is not attached to a document; cannot load image bytes');
|
|
725
|
+
}
|
|
726
|
+
var catalog = imagesFor(document);
|
|
727
|
+
var sniffed = sniffImageContentType(imageBytes);
|
|
728
|
+
var contentType = sniffed != null ? sniffed : PNG_CONTENT_TYPE;
|
|
729
|
+
if (this.isPendingRelationship()) {
|
|
730
|
+
if (catalog.pendingBytesFor(this) !== undefined) {
|
|
731
|
+
catalog.updatePendingBytes(this, imageBytes);
|
|
732
|
+
}
|
|
733
|
+
else {
|
|
734
|
+
catalog.registerPendingImage(this, imageBytes, contentType);
|
|
735
|
+
}
|
|
736
|
+
return;
|
|
737
|
+
}
|
|
738
|
+
// Materialized relationship: replace media bytes in place (layout / rId unchanged).
|
|
739
|
+
catalog.replaceBytes(this.relationshipId, imageBytes);
|
|
740
|
+
};
|
|
741
|
+
/**
|
|
742
|
+
* @private
|
|
743
|
+
*/
|
|
744
|
+
Picture.prototype.toOpenXml = function () {
|
|
745
|
+
if (this.relationshipIdValue.length === 0) {
|
|
746
|
+
throw new DocxError('model/detached-object', 'Inline image relationship id is not materialized; save the document first');
|
|
747
|
+
}
|
|
748
|
+
var input = {
|
|
749
|
+
placement: this.placementValue,
|
|
750
|
+
wrapping: this.wrappingValue,
|
|
751
|
+
widthEmu: pointToEmus(this.widthValue),
|
|
752
|
+
heightEmu: pointToEmus(this.heightValue),
|
|
753
|
+
relationshipId: this.relationshipIdValue,
|
|
754
|
+
name: this.nameValue,
|
|
755
|
+
title: this.titleValue,
|
|
756
|
+
description: this.descriptionValue,
|
|
757
|
+
lockAspectRatio: this.lockAspectRatioValue,
|
|
758
|
+
rotation: this.rotationValue,
|
|
759
|
+
flipHorizontal: this.flipHorizontalValue,
|
|
760
|
+
flipVertical: this.flipVerticalValue,
|
|
761
|
+
horizontalOrigin: this.horizontalOriginValue != null ? this.horizontalOriginValue : HorizontalOrigin.Column,
|
|
762
|
+
verticalOrigin: this.verticalOriginValue != null ? this.verticalOriginValue : VerticalOrigin.Paragraph,
|
|
763
|
+
horizontalPosition: this.horizontalPositionValue,
|
|
764
|
+
verticalPosition: this.verticalPositionValue,
|
|
765
|
+
horizontalAlignment: this.horizontalAlignmentValue,
|
|
766
|
+
verticalAlignment: this.verticalAlignmentValue,
|
|
767
|
+
docPrId: this.docPrIdValue,
|
|
768
|
+
preservedHost: this.preservedHostValue,
|
|
769
|
+
layoutDirty: this.layoutDirtyValue,
|
|
770
|
+
hyperlinkRelationshipId: this.hyperlinkRelationshipIdValue,
|
|
771
|
+
};
|
|
772
|
+
return encodePictureHost(input);
|
|
773
|
+
};
|
|
774
|
+
return Picture;
|
|
775
|
+
}());
|
|
776
|
+
export { Picture };
|
|
777
|
+
/**
|
|
778
|
+
* Image media parts linked from the Main Document.
|
|
779
|
+
*
|
|
780
|
+
* @private
|
|
781
|
+
*/
|
|
782
|
+
var ImagesCatalog = /** @class */ (function () {
|
|
783
|
+
/** @private */
|
|
784
|
+
function ImagesCatalog(entries) {
|
|
785
|
+
this.entries = entries;
|
|
786
|
+
this.byRelationshipId = new Map(__spread(entries.values()).map(function (entry) { return [entry.relationshipId, entry]; }));
|
|
787
|
+
this.pendingRemovals = [];
|
|
788
|
+
this.pendingImages = new Map();
|
|
789
|
+
}
|
|
790
|
+
/** @private */
|
|
791
|
+
ImagesCatalog.prototype.removeEntry = function (relationshipId) {
|
|
792
|
+
var entry = this.byRelationshipId.get(relationshipId);
|
|
793
|
+
if (entry === undefined) {
|
|
794
|
+
return;
|
|
795
|
+
}
|
|
796
|
+
this.entries.delete(entry.partName);
|
|
797
|
+
this.byRelationshipId.delete(relationshipId);
|
|
798
|
+
this.pendingRemovals.push(entry);
|
|
799
|
+
};
|
|
800
|
+
/** @private */
|
|
801
|
+
ImagesCatalog.prototype.isDirty = function () {
|
|
802
|
+
var e_1, _a;
|
|
803
|
+
if (this.pendingRemovals.length > 0 || this.pendingImages.size > 0) {
|
|
804
|
+
return true;
|
|
805
|
+
}
|
|
806
|
+
try {
|
|
807
|
+
for (var _b = __values(this.entries.values()), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
808
|
+
var entry = _c.value;
|
|
809
|
+
if (entry.dirty || entry.pendingRelationship !== undefined) {
|
|
810
|
+
return true;
|
|
811
|
+
}
|
|
812
|
+
}
|
|
813
|
+
}
|
|
814
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
815
|
+
finally {
|
|
816
|
+
try {
|
|
817
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
818
|
+
}
|
|
819
|
+
finally { if (e_1) throw e_1.error; }
|
|
820
|
+
}
|
|
821
|
+
return false;
|
|
822
|
+
};
|
|
823
|
+
/** @private */
|
|
824
|
+
ImagesCatalog.prototype.applyToPackage = function (pkg, mainPartName) {
|
|
825
|
+
var e_2, _a, e_3, _b;
|
|
826
|
+
var next = pkg;
|
|
827
|
+
var _loop_1 = function (entry) {
|
|
828
|
+
if (!entry.dirty && entry.pendingRelationship === undefined) {
|
|
829
|
+
return "continue";
|
|
830
|
+
}
|
|
831
|
+
var rel = entry.pendingRelationship != null ? entry.pendingRelationship : relationshipsForPart(next, mainPartName).items.find(function (item) { return item.id === entry.relationshipId; });
|
|
832
|
+
next = replaceOrAddPackagePart(next, mainPartName, entry.partName, entry.contentType, entry.data, rel);
|
|
833
|
+
entry.dirty = false;
|
|
834
|
+
entry.pendingRelationship = undefined;
|
|
835
|
+
};
|
|
836
|
+
try {
|
|
837
|
+
for (var _c = __values(this.entries.values()), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
838
|
+
var entry = _d.value;
|
|
839
|
+
_loop_1(entry);
|
|
840
|
+
}
|
|
841
|
+
}
|
|
842
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
843
|
+
finally {
|
|
844
|
+
try {
|
|
845
|
+
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
|
|
846
|
+
}
|
|
847
|
+
finally { if (e_2) throw e_2.error; }
|
|
848
|
+
}
|
|
849
|
+
try {
|
|
850
|
+
for (var _e = __values(this.pendingRemovals), _f = _e.next(); !_f.done; _f = _e.next()) {
|
|
851
|
+
var entry = _f.value;
|
|
852
|
+
next = removeImagePartFromPackage(next, mainPartName, entry);
|
|
853
|
+
}
|
|
854
|
+
}
|
|
855
|
+
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
856
|
+
finally {
|
|
857
|
+
try {
|
|
858
|
+
if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
|
|
859
|
+
}
|
|
860
|
+
finally { if (e_3) throw e_3.error; }
|
|
861
|
+
}
|
|
862
|
+
this.pendingRemovals.length = 0;
|
|
863
|
+
return next;
|
|
864
|
+
};
|
|
865
|
+
/** Image bytes for a loaded relationship id. */
|
|
866
|
+
ImagesCatalog.prototype.bytesForRelationship = function (relationshipId) {
|
|
867
|
+
var __ts33_0;
|
|
868
|
+
return ((__ts33_0 = this.byRelationshipId.get(relationshipId)), __ts33_0 == null ? undefined : __ts33_0.data);
|
|
869
|
+
};
|
|
870
|
+
/** @private Pending picture bytes before save-time materialization. */
|
|
871
|
+
ImagesCatalog.prototype.pendingBytesFor = function (picture) {
|
|
872
|
+
var __ts33_1;
|
|
873
|
+
return ((__ts33_1 = this.pendingImages.get(picture)), __ts33_1 == null ? undefined : __ts33_1.bytes);
|
|
874
|
+
};
|
|
875
|
+
/** @private Record picture intent without allocating package ids. */
|
|
876
|
+
ImagesCatalog.prototype.registerPendingImage = function (picture, bytes, contentType) {
|
|
877
|
+
this.pendingImages.set(picture, { bytes: bytes, contentType: contentType });
|
|
878
|
+
};
|
|
879
|
+
/** @private Drop a pending picture that was removed before save. */
|
|
880
|
+
ImagesCatalog.prototype.discardPendingImage = function (picture) {
|
|
881
|
+
this.pendingImages.delete(picture);
|
|
882
|
+
};
|
|
883
|
+
/** @private Replace bytes on a not-yet-materialized picture. */
|
|
884
|
+
ImagesCatalog.prototype.updatePendingBytes = function (picture, bytes) {
|
|
885
|
+
var pending = this.pendingImages.get(picture);
|
|
886
|
+
if (pending === undefined) {
|
|
887
|
+
throw new DocxError('content/unknown-image', 'Pending inline image was not found');
|
|
888
|
+
}
|
|
889
|
+
this.pendingImages.set(picture, __assign({}, pending, { bytes: bytes }));
|
|
890
|
+
};
|
|
891
|
+
/** @private */
|
|
892
|
+
ImagesCatalog.prototype.materializePending = function (document) {
|
|
893
|
+
var _this = this;
|
|
894
|
+
if (this.pendingImages.size === 0) {
|
|
895
|
+
return;
|
|
896
|
+
}
|
|
897
|
+
var hashToRelationshipId = new Map();
|
|
898
|
+
visitParagraphsInDocumentOrder(document, function (paragraph) {
|
|
899
|
+
var e_4, _a;
|
|
900
|
+
try {
|
|
901
|
+
for (var _b = __values(picturesInParagraph(paragraph)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
902
|
+
var picture = _c.value;
|
|
903
|
+
if (!picture.isPendingRelationship()) {
|
|
904
|
+
continue;
|
|
905
|
+
}
|
|
906
|
+
var pending_1 = _this.pendingImages.get(picture);
|
|
907
|
+
if (pending_1 === undefined) {
|
|
908
|
+
continue;
|
|
909
|
+
}
|
|
910
|
+
var hash = sha256(pending_1.bytes);
|
|
911
|
+
var relationshipId = hashToRelationshipId.get(hash);
|
|
912
|
+
if (relationshipId === undefined) {
|
|
913
|
+
var allocated = _this.allocatePart(pending_1.bytes, pending_1.contentType, usedRelationshipIds(document, _this), usedPartNameKeys(document, _this));
|
|
914
|
+
relationshipId = allocated.relationshipId;
|
|
915
|
+
hashToRelationshipId.set(hash, relationshipId);
|
|
916
|
+
}
|
|
917
|
+
picture.resolveRelationshipId(relationshipId);
|
|
918
|
+
_this.pendingImages.delete(picture);
|
|
919
|
+
}
|
|
920
|
+
}
|
|
921
|
+
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
922
|
+
finally {
|
|
923
|
+
try {
|
|
924
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
925
|
+
}
|
|
926
|
+
finally { if (e_4) throw e_4.error; }
|
|
927
|
+
}
|
|
928
|
+
});
|
|
929
|
+
};
|
|
930
|
+
/** @private */
|
|
931
|
+
ImagesCatalog.prototype.pendingRelationshipIds = function () {
|
|
932
|
+
return __spread(this.byRelationshipId.keys());
|
|
933
|
+
};
|
|
934
|
+
/** @private */
|
|
935
|
+
ImagesCatalog.prototype.pendingPartNames = function () {
|
|
936
|
+
return __spread(this.entries.keys());
|
|
937
|
+
};
|
|
938
|
+
/** @private */
|
|
939
|
+
ImagesCatalog.prototype.allocatePart = function (data, contentType, usedRelIds, usedPartNames) {
|
|
940
|
+
var partNameValue = allocateImagePartName(contentType, usedPartNames);
|
|
941
|
+
var relId = allocateRelationshipId(usedRelIds);
|
|
942
|
+
while (this.byRelationshipId.has(relId)) {
|
|
943
|
+
relId = allocateRelationshipId(new Set(__spread(usedRelIds, [relId])));
|
|
944
|
+
}
|
|
945
|
+
var entry = {
|
|
946
|
+
partName: partNameValue,
|
|
947
|
+
relationshipId: relId,
|
|
948
|
+
relationshipType: IMAGE_RELATIONSHIP_TYPE,
|
|
949
|
+
contentType: contentType,
|
|
950
|
+
data: data,
|
|
951
|
+
dirty: true,
|
|
952
|
+
pendingRelationship: {
|
|
953
|
+
id: relId,
|
|
954
|
+
type: IMAGE_RELATIONSHIP_TYPE,
|
|
955
|
+
target: relativeTarget(partNameValue),
|
|
956
|
+
extraAttributes: [],
|
|
957
|
+
children: [],
|
|
958
|
+
},
|
|
959
|
+
};
|
|
960
|
+
this.entries.set(partNameValue, entry);
|
|
961
|
+
this.byRelationshipId.set(relId, entry);
|
|
962
|
+
return { entry: entry, relationshipId: relId };
|
|
963
|
+
};
|
|
964
|
+
/** @private */
|
|
965
|
+
ImagesCatalog.prototype.replaceBytes = function (relationshipId, data) {
|
|
966
|
+
var entry = this.byRelationshipId.get(relationshipId);
|
|
967
|
+
if (entry === undefined) {
|
|
968
|
+
throw new DocxError('content/unknown-image', "Image relationship " + relationshipId + " is not loaded");
|
|
969
|
+
}
|
|
970
|
+
entry.data = data;
|
|
971
|
+
var sniffed = sniffImageContentType(data);
|
|
972
|
+
if (sniffed !== undefined) {
|
|
973
|
+
entry.contentType = sniffed;
|
|
974
|
+
}
|
|
975
|
+
entry.dirty = true;
|
|
976
|
+
};
|
|
977
|
+
/**
|
|
978
|
+
* Bind every inline picture in the main story to this document after body parse
|
|
979
|
+
* so {@link Picture.loadImage} works when pictures are taken from
|
|
980
|
+
* {@link Paragraph.items} without a prior {@link picturesInParagraph} walk.
|
|
981
|
+
*
|
|
982
|
+
* Invoked from {@link WordDocument.fromPackage} via duck-typed
|
|
983
|
+
* `afterMainDocumentLoad` (same pattern as comments).
|
|
984
|
+
*
|
|
985
|
+
* @private
|
|
986
|
+
*/
|
|
987
|
+
ImagesCatalog.prototype.afterMainDocumentLoad = function (document) {
|
|
988
|
+
visitParagraphsInDocumentOrder(document, function (paragraph) {
|
|
989
|
+
// Side effect: picturesInParagraph binds hostDocumentOf for each leaf.
|
|
990
|
+
picturesInParagraph(paragraph);
|
|
991
|
+
});
|
|
992
|
+
};
|
|
993
|
+
return ImagesCatalog;
|
|
994
|
+
}());
|
|
995
|
+
export { ImagesCatalog };
|
|
996
|
+
function extensionForContentType(contentType) {
|
|
997
|
+
return contentType === JPEG_CONTENT_TYPE ? 'jpeg' : 'png';
|
|
998
|
+
}
|
|
999
|
+
function sha256(data) {
|
|
1000
|
+
return sha256Hex(data);
|
|
1001
|
+
}
|
|
1002
|
+
function relativeTarget(partNameValue) {
|
|
1003
|
+
return partNameValue.slice('/word/'.length);
|
|
1004
|
+
}
|
|
1005
|
+
function allocateImagePartName(contentType, used) {
|
|
1006
|
+
var ext = extensionForContentType(contentType);
|
|
1007
|
+
var index = 1;
|
|
1008
|
+
while (used.has(partNameKey(partName("/word/media/image" + String(index) + "." + ext)))) {
|
|
1009
|
+
index += 1;
|
|
1010
|
+
}
|
|
1011
|
+
return partName("/word/media/image" + String(index) + "." + ext);
|
|
1012
|
+
}
|
|
1013
|
+
/**
|
|
1014
|
+
* Resolve media content type for an image relationship target.
|
|
1015
|
+
* Keep non-PNG/JPEG types (e.g. GIF) so {@link ImagesCatalog.replaceBytes} can
|
|
1016
|
+
* find the relationship when replacing an existing picture.
|
|
1017
|
+
*/
|
|
1018
|
+
function contentTypeForPart(part) {
|
|
1019
|
+
if (part.contentType === PNG_CONTENT_TYPE || part.contentType === JPEG_CONTENT_TYPE) {
|
|
1020
|
+
return part.contentType;
|
|
1021
|
+
}
|
|
1022
|
+
if (part.contentType.startsWith('image/')) {
|
|
1023
|
+
return part.contentType;
|
|
1024
|
+
}
|
|
1025
|
+
var lower = part.name.toLowerCase();
|
|
1026
|
+
if (lower.endsWith('.png')) {
|
|
1027
|
+
return PNG_CONTENT_TYPE;
|
|
1028
|
+
}
|
|
1029
|
+
if (lower.endsWith('.jpeg') || lower.endsWith('.jpg')) {
|
|
1030
|
+
return JPEG_CONTENT_TYPE;
|
|
1031
|
+
}
|
|
1032
|
+
if (lower.endsWith('.gif')) {
|
|
1033
|
+
return 'image/gif';
|
|
1034
|
+
}
|
|
1035
|
+
if (part.contentType.length > 0) {
|
|
1036
|
+
return part.contentType;
|
|
1037
|
+
}
|
|
1038
|
+
return 'application/octet-stream';
|
|
1039
|
+
}
|
|
1040
|
+
function loadCatalog(pkg, mainPartName) {
|
|
1041
|
+
var e_5, _a;
|
|
1042
|
+
var rels = relationshipsForPart(pkg, mainPartName);
|
|
1043
|
+
var entries = new Map();
|
|
1044
|
+
try {
|
|
1045
|
+
for (var _b = __values(rels.items), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
1046
|
+
var rel = _c.value;
|
|
1047
|
+
if (IMAGE_RELATIONSHIP_TYPES.indexOf(rel.type) === -1) {
|
|
1048
|
+
continue;
|
|
1049
|
+
}
|
|
1050
|
+
// External image links are valid OPC; keep the relationship as-is and skip part load.
|
|
1051
|
+
if (rel.targetMode === TargetMode.External || /^[a-zA-Z][a-zA-Z0-9+.-]*:/.test(rel.target.trim())) {
|
|
1052
|
+
continue;
|
|
1053
|
+
}
|
|
1054
|
+
var target = resolveInternalTarget(rel.target, mainPartName);
|
|
1055
|
+
var part = partByName(pkg, target);
|
|
1056
|
+
if (part === undefined) {
|
|
1057
|
+
continue;
|
|
1058
|
+
}
|
|
1059
|
+
var contentType = contentTypeForPart(part);
|
|
1060
|
+
entries.set(part.name, {
|
|
1061
|
+
partName: part.name,
|
|
1062
|
+
relationshipId: rel.id,
|
|
1063
|
+
relationshipType: rel.type,
|
|
1064
|
+
contentType: contentType,
|
|
1065
|
+
data: part.data,
|
|
1066
|
+
dirty: false,
|
|
1067
|
+
pendingRelationship: undefined,
|
|
1068
|
+
});
|
|
1069
|
+
}
|
|
1070
|
+
}
|
|
1071
|
+
catch (e_5_1) { e_5 = { error: e_5_1 }; }
|
|
1072
|
+
finally {
|
|
1073
|
+
try {
|
|
1074
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
1075
|
+
}
|
|
1076
|
+
finally { if (e_5) throw e_5.error; }
|
|
1077
|
+
}
|
|
1078
|
+
return new ImagesCatalog(entries);
|
|
1079
|
+
}
|
|
1080
|
+
function removeImagePartFromPackage(pkg, mainPartName, entry) {
|
|
1081
|
+
var next = withRemovedPartLocal(pkg, entry.partName);
|
|
1082
|
+
next = withRemovedContentTypeOverrideLocal(next, entry.partName);
|
|
1083
|
+
next = withFilteredPartRelationshipsLocal(next, mainPartName, function (rel) { return rel.id !== entry.relationshipId; });
|
|
1084
|
+
return next;
|
|
1085
|
+
}
|
|
1086
|
+
function withRemovedPartLocal(pkg, name) {
|
|
1087
|
+
var key = partNameKey(name);
|
|
1088
|
+
var parts = pkg.parts.filter(function (part) { return partNameKey(part.name) !== key; });
|
|
1089
|
+
if (parts.length === pkg.parts.length) {
|
|
1090
|
+
return pkg;
|
|
1091
|
+
}
|
|
1092
|
+
return __assign({}, pkg, { parts: parts });
|
|
1093
|
+
}
|
|
1094
|
+
function withRemovedContentTypeOverrideLocal(pkg, logicalPartName) {
|
|
1095
|
+
return __assign({}, pkg, { contentTypes: {
|
|
1096
|
+
records: pkg.contentTypes.records.filter(function (record) { return !(record.kind === 'override' && record.partName === logicalPartName); }),
|
|
1097
|
+
} });
|
|
1098
|
+
}
|
|
1099
|
+
function withFilteredPartRelationshipsLocal(pkg, source, keep) {
|
|
1100
|
+
var existing = relationshipsForPart(pkg, source);
|
|
1101
|
+
var kept = existing.items.filter(keep);
|
|
1102
|
+
if (kept.length === existing.items.length) {
|
|
1103
|
+
return pkg;
|
|
1104
|
+
}
|
|
1105
|
+
return withPartRelationships(pkg, source, relationshipsWith(kept, existing.opaque));
|
|
1106
|
+
}
|
|
1107
|
+
function usedRelationshipIds(document, _catalog) {
|
|
1108
|
+
// Shared across multi-part features so concurrent pending allocations cannot
|
|
1109
|
+
// emit the same main-document rId (ink + images materialize independently).
|
|
1110
|
+
return usedMainDocumentRelationshipIds(document);
|
|
1111
|
+
}
|
|
1112
|
+
function usedPartNameKeys(document, catalog) {
|
|
1113
|
+
var e_6, _a, e_7, _b;
|
|
1114
|
+
var used = new Set();
|
|
1115
|
+
try {
|
|
1116
|
+
for (var _c = __values(document.opcPackage().parts), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
1117
|
+
var part = _d.value;
|
|
1118
|
+
used.add(partNameKey(part.name));
|
|
1119
|
+
}
|
|
1120
|
+
}
|
|
1121
|
+
catch (e_6_1) { e_6 = { error: e_6_1 }; }
|
|
1122
|
+
finally {
|
|
1123
|
+
try {
|
|
1124
|
+
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
|
|
1125
|
+
}
|
|
1126
|
+
finally { if (e_6) throw e_6.error; }
|
|
1127
|
+
}
|
|
1128
|
+
try {
|
|
1129
|
+
for (var _e = __values(catalog.pendingPartNames()), _f = _e.next(); !_f.done; _f = _e.next()) {
|
|
1130
|
+
var name_1 = _f.value;
|
|
1131
|
+
used.add(partNameKey(name_1));
|
|
1132
|
+
}
|
|
1133
|
+
}
|
|
1134
|
+
catch (e_7_1) { e_7 = { error: e_7_1 }; }
|
|
1135
|
+
finally {
|
|
1136
|
+
try {
|
|
1137
|
+
if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
|
|
1138
|
+
}
|
|
1139
|
+
finally { if (e_7) throw e_7.error; }
|
|
1140
|
+
}
|
|
1141
|
+
return used;
|
|
1142
|
+
}
|
|
1143
|
+
var registered = false;
|
|
1144
|
+
/** @private Test hook */
|
|
1145
|
+
export function resetImagesFeatureForTests() {
|
|
1146
|
+
registered = false;
|
|
1147
|
+
}
|
|
1148
|
+
/** @private Register the images multi-part and inline drawing handlers. Idempotent. */
|
|
1149
|
+
export function registerImagesFeature() {
|
|
1150
|
+
if (registered) {
|
|
1151
|
+
return;
|
|
1152
|
+
}
|
|
1153
|
+
registered = true;
|
|
1154
|
+
registerFeature({ id: IMAGES });
|
|
1155
|
+
registerFeatureMultiPartHandler({
|
|
1156
|
+
featureId: IMAGES,
|
|
1157
|
+
relationshipTypes: IMAGE_RELATIONSHIP_TYPES,
|
|
1158
|
+
loadParts: function (pkg, ctx) {
|
|
1159
|
+
return loadCatalog(pkg, ctx.mainPartName);
|
|
1160
|
+
},
|
|
1161
|
+
});
|
|
1162
|
+
registerFeatureMaterializeHandler({
|
|
1163
|
+
featureId: IMAGES,
|
|
1164
|
+
materialize: function (document) {
|
|
1165
|
+
var part = document.featurePart(IMAGES);
|
|
1166
|
+
if (part instanceof ImagesCatalog) {
|
|
1167
|
+
part.materializePending(document);
|
|
1168
|
+
}
|
|
1169
|
+
},
|
|
1170
|
+
});
|
|
1171
|
+
registerFeatureRunLeafHandler({
|
|
1172
|
+
featureId: IMAGES,
|
|
1173
|
+
wmlLocalName: 'drawing',
|
|
1174
|
+
tryParse: function (element) {
|
|
1175
|
+
var state = decodePictureHost(element);
|
|
1176
|
+
if (state === undefined) {
|
|
1177
|
+
return undefined;
|
|
1178
|
+
}
|
|
1179
|
+
return Picture.fromHostState(state);
|
|
1180
|
+
},
|
|
1181
|
+
});
|
|
1182
|
+
}
|
|
1183
|
+
/**
|
|
1184
|
+
* Image media catalog for a document.
|
|
1185
|
+
*
|
|
1186
|
+
* @throws DocxError `UNKNOWN_FEATURE` when the module was not registered before load.
|
|
1187
|
+
* @private
|
|
1188
|
+
*/
|
|
1189
|
+
export function imagesFor(document) {
|
|
1190
|
+
var part = document.featurePart(IMAGES);
|
|
1191
|
+
if (part === undefined || !(part instanceof ImagesCatalog)) {
|
|
1192
|
+
throw new DocxError('feature/not-registered', 'Images catalog was not loaded; call registerImagesFeature() before WordDocument.open');
|
|
1193
|
+
}
|
|
1194
|
+
return part;
|
|
1195
|
+
}
|
|
1196
|
+
/**
|
|
1197
|
+
* Inline pictures in a paragraph, in document order (including nested inline content controls).
|
|
1198
|
+
*
|
|
1199
|
+
* @private
|
|
1200
|
+
*/
|
|
1201
|
+
export function picturesInParagraph(paragraph) {
|
|
1202
|
+
var found = [];
|
|
1203
|
+
var host;
|
|
1204
|
+
collectPicturesFromParagraphItems(paragraph.items.snapshot(), found, function () {
|
|
1205
|
+
if (host === undefined) {
|
|
1206
|
+
host = tryParagraphDocument(paragraph);
|
|
1207
|
+
}
|
|
1208
|
+
return host;
|
|
1209
|
+
});
|
|
1210
|
+
return found;
|
|
1211
|
+
}
|
|
1212
|
+
/**
|
|
1213
|
+
|
|
1214
|
+
* @private
|
|
1215
|
+
*/
|
|
1216
|
+
export function imagesInParagraph(paragraph) {
|
|
1217
|
+
return picturesInParagraph(paragraph);
|
|
1218
|
+
}
|
|
1219
|
+
function collectPicturesFromParagraphItems(items, found, hostOf) {
|
|
1220
|
+
var e_8, _a;
|
|
1221
|
+
try {
|
|
1222
|
+
for (var items_1 = __values(items), items_1_1 = items_1.next(); !items_1_1.done; items_1_1 = items_1.next()) {
|
|
1223
|
+
var item = items_1_1.value;
|
|
1224
|
+
if (item instanceof Picture) {
|
|
1225
|
+
var resolvedHost = hostDocumentOf(item);
|
|
1226
|
+
var host = resolvedHost !== undefined ? resolvedHost : hostOf();
|
|
1227
|
+
if (host !== undefined) {
|
|
1228
|
+
bindCaptionHostDocument(item, host);
|
|
1229
|
+
}
|
|
1230
|
+
found.push(item);
|
|
1231
|
+
continue;
|
|
1232
|
+
}
|
|
1233
|
+
if (item instanceof FeatureRunParagraphItem && isPictureLeaf(item)) {
|
|
1234
|
+
var leaf = item.value;
|
|
1235
|
+
var resolvedLeafHost = hostDocumentOf(leaf);
|
|
1236
|
+
var host = resolvedLeafHost !== undefined ? resolvedLeafHost : hostOf();
|
|
1237
|
+
if (host !== undefined) {
|
|
1238
|
+
bindCaptionHostDocument(leaf, host);
|
|
1239
|
+
}
|
|
1240
|
+
found.push(leaf);
|
|
1241
|
+
continue;
|
|
1242
|
+
}
|
|
1243
|
+
var nested = nestedParagraphItemsOf(item);
|
|
1244
|
+
if (nested !== undefined) {
|
|
1245
|
+
collectPicturesFromParagraphItems(nested, found, hostOf);
|
|
1246
|
+
}
|
|
1247
|
+
}
|
|
1248
|
+
}
|
|
1249
|
+
catch (e_8_1) { e_8 = { error: e_8_1 }; }
|
|
1250
|
+
finally {
|
|
1251
|
+
try {
|
|
1252
|
+
if (items_1_1 && !items_1_1.done && (_a = items_1.return)) _a.call(items_1);
|
|
1253
|
+
}
|
|
1254
|
+
finally { if (e_8) throw e_8.error; }
|
|
1255
|
+
}
|
|
1256
|
+
}
|
|
1257
|
+
/** Nested run-level items under an inline content control (public or wrapper). */
|
|
1258
|
+
function nestedParagraphItemsOf(item) {
|
|
1259
|
+
if (item instanceof FeatureInlineParagraphItem) {
|
|
1260
|
+
return nestedParagraphItemsOfValue(item.value);
|
|
1261
|
+
}
|
|
1262
|
+
return nestedParagraphItemsOfValue(item);
|
|
1263
|
+
}
|
|
1264
|
+
function nestedParagraphItemsOfValue(value) {
|
|
1265
|
+
if (value === null || typeof value !== 'object') {
|
|
1266
|
+
return undefined;
|
|
1267
|
+
}
|
|
1268
|
+
var candidate = value;
|
|
1269
|
+
if (candidate.entityType !== EntityType.InlineContentControl) {
|
|
1270
|
+
return undefined;
|
|
1271
|
+
}
|
|
1272
|
+
var collection = candidate.paragraphItems;
|
|
1273
|
+
if (collection === undefined) {
|
|
1274
|
+
return undefined;
|
|
1275
|
+
}
|
|
1276
|
+
if (typeof collection.snapshot === 'function') {
|
|
1277
|
+
return collection.snapshot();
|
|
1278
|
+
}
|
|
1279
|
+
return __spread(collection);
|
|
1280
|
+
}
|
|
1281
|
+
function tryParagraphDocument(paragraph) {
|
|
1282
|
+
try {
|
|
1283
|
+
return paragraph.owningDocument();
|
|
1284
|
+
}
|
|
1285
|
+
catch (_a) {
|
|
1286
|
+
return undefined;
|
|
1287
|
+
}
|
|
1288
|
+
}
|
|
1289
|
+
/**
|
|
1290
|
+
* Inline picture bytes for a picture relationship.
|
|
1291
|
+
* @private
|
|
1292
|
+
*/
|
|
1293
|
+
export function inlinePictureBytes(document, picture) {
|
|
1294
|
+
var catalog = imagesFor(document);
|
|
1295
|
+
var pending = catalog.pendingBytesFor(picture);
|
|
1296
|
+
if (pending !== undefined) {
|
|
1297
|
+
return pending;
|
|
1298
|
+
}
|
|
1299
|
+
if (picture.relationshipId.length === 0) {
|
|
1300
|
+
return undefined;
|
|
1301
|
+
}
|
|
1302
|
+
return catalog.bytesForRelationship(picture.relationshipId);
|
|
1303
|
+
}
|
|
1304
|
+
/**
|
|
1305
|
+
|
|
1306
|
+
* @private
|
|
1307
|
+
*/
|
|
1308
|
+
export function inlineImageBytes(document, image) {
|
|
1309
|
+
return inlinePictureBytes(document, image);
|
|
1310
|
+
}
|
|
1311
|
+
/**
|
|
1312
|
+
* Replace picture media bytes without changing layout markup.
|
|
1313
|
+
* @private
|
|
1314
|
+
*/
|
|
1315
|
+
export function replaceInlinePictureBytes(document, picture, bytes) {
|
|
1316
|
+
var catalog = imagesFor(document);
|
|
1317
|
+
if (picture.isPendingRelationship()) {
|
|
1318
|
+
catalog.updatePendingBytes(picture, bytes);
|
|
1319
|
+
return;
|
|
1320
|
+
}
|
|
1321
|
+
catalog.replaceBytes(picture.relationshipId, bytes);
|
|
1322
|
+
}
|
|
1323
|
+
/**
|
|
1324
|
+
|
|
1325
|
+
* @private
|
|
1326
|
+
*/
|
|
1327
|
+
export function replaceInlineImageBytes(document, image, bytes) {
|
|
1328
|
+
replaceInlinePictureBytes(document, image, bytes);
|
|
1329
|
+
}
|
|
1330
|
+
/**
|
|
1331
|
+
* Remove an inline picture run from its paragraph and drop its media on the next save.
|
|
1332
|
+
* @private
|
|
1333
|
+
*/
|
|
1334
|
+
export function removeInlinePicture(document, paragraph, picture) {
|
|
1335
|
+
var e_9, _a;
|
|
1336
|
+
try {
|
|
1337
|
+
for (var _b = __values(paragraph.items.snapshot()), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
1338
|
+
var item = _c.value;
|
|
1339
|
+
if (item instanceof Picture && item === picture) {
|
|
1340
|
+
paragraph.removeFeatureRunItem(picture);
|
|
1341
|
+
if (!picture.isPendingRelationship()) {
|
|
1342
|
+
imagesFor(document).removeEntry(picture.relationshipId);
|
|
1343
|
+
}
|
|
1344
|
+
else {
|
|
1345
|
+
imagesFor(document).discardPendingImage(picture);
|
|
1346
|
+
}
|
|
1347
|
+
return;
|
|
1348
|
+
}
|
|
1349
|
+
if (item instanceof FeatureRunParagraphItem && isPictureLeaf(item) && item.value === picture) {
|
|
1350
|
+
paragraph.removeFeatureRunItem(picture);
|
|
1351
|
+
if (!picture.isPendingRelationship()) {
|
|
1352
|
+
imagesFor(document).removeEntry(picture.relationshipId);
|
|
1353
|
+
}
|
|
1354
|
+
else {
|
|
1355
|
+
imagesFor(document).discardPendingImage(picture);
|
|
1356
|
+
}
|
|
1357
|
+
return;
|
|
1358
|
+
}
|
|
1359
|
+
}
|
|
1360
|
+
}
|
|
1361
|
+
catch (e_9_1) { e_9 = { error: e_9_1 }; }
|
|
1362
|
+
finally {
|
|
1363
|
+
try {
|
|
1364
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
1365
|
+
}
|
|
1366
|
+
finally { if (e_9) throw e_9.error; }
|
|
1367
|
+
}
|
|
1368
|
+
throw new DocxError('content/unknown-image', 'Inline picture is not in this paragraph');
|
|
1369
|
+
}
|
|
1370
|
+
/**
|
|
1371
|
+
|
|
1372
|
+
* @private
|
|
1373
|
+
*/
|
|
1374
|
+
export function removeInlineImage(document, paragraph, image) {
|
|
1375
|
+
removeInlinePicture(document, paragraph, image);
|
|
1376
|
+
}
|
|
1377
|
+
/**
|
|
1378
|
+
* Whether a paragraph item is a modeled inline picture from this module.
|
|
1379
|
+
*
|
|
1380
|
+
* @private
|
|
1381
|
+
*/
|
|
1382
|
+
export function isPictureLeaf(item) {
|
|
1383
|
+
if (item instanceof Picture) {
|
|
1384
|
+
return true;
|
|
1385
|
+
}
|
|
1386
|
+
return item instanceof FeatureRunParagraphItem && item.featureId === IMAGES && item.value instanceof Picture;
|
|
1387
|
+
}
|
|
1388
|
+
/**
|
|
1389
|
+
|
|
1390
|
+
* @private
|
|
1391
|
+
*/
|
|
1392
|
+
export function isImageLeaf(item) {
|
|
1393
|
+
return isPictureLeaf(item);
|
|
1394
|
+
}
|
|
1395
|
+
Paragraph.prototype.appendImage = function (bytes, options) {
|
|
1396
|
+
var opts = options != null ? options : {};
|
|
1397
|
+
var catalog = imagesFor(this.owningDocument());
|
|
1398
|
+
var layout = resolveImageLayout(bytes, opts);
|
|
1399
|
+
var wrap = opts.textWrappingStyle !== undefined ? opts.textWrappingStyle : opts.wrapping;
|
|
1400
|
+
var picture = new Picture(imageInit({
|
|
1401
|
+
relationshipId: '',
|
|
1402
|
+
width: layout.width,
|
|
1403
|
+
height: layout.height,
|
|
1404
|
+
name: opts.name != null ? opts.name : 'Picture',
|
|
1405
|
+
title: opts.title,
|
|
1406
|
+
description: opts.description,
|
|
1407
|
+
lockAspectRatio: opts.lockAspectRatio != null ? opts.lockAspectRatio : true,
|
|
1408
|
+
rotation: opts.rotation != null ? opts.rotation : 0,
|
|
1409
|
+
flipHorizontal: opts.flipHorizontal != null ? opts.flipHorizontal : false,
|
|
1410
|
+
flipVertical: opts.flipVertical != null ? opts.flipVertical : false,
|
|
1411
|
+
placement: opts.placement,
|
|
1412
|
+
wrapping: wrap,
|
|
1413
|
+
horizontalOrigin: opts.horizontalOrigin,
|
|
1414
|
+
verticalOrigin: opts.verticalOrigin,
|
|
1415
|
+
horizontalPosition: opts.horizontalPosition,
|
|
1416
|
+
verticalPosition: opts.verticalPosition,
|
|
1417
|
+
horizontalAlignment: opts.horizontalAlignment,
|
|
1418
|
+
verticalAlignment: opts.verticalAlignment,
|
|
1419
|
+
layoutDirty: true,
|
|
1420
|
+
}));
|
|
1421
|
+
catalog.registerPendingImage(picture, bytes, layout.contentType);
|
|
1422
|
+
bindCaptionHostDocument(picture, this.owningDocument());
|
|
1423
|
+
this.appendFeatureRunItem(IMAGES, picture);
|
|
1424
|
+
return picture;
|
|
1425
|
+
};
|
|
1426
|
+
registerAlwaysOnBodyFeatureBootstrap(function () {
|
|
1427
|
+
registerImagesFeature();
|
|
1428
|
+
});
|
|
1429
|
+
registerImagesFeature();
|