@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,1421 @@
|
|
|
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 __values = (this && this.__values) || function (o) {
|
|
13
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator], i = 0;
|
|
14
|
+
if (m) return m.call(o);
|
|
15
|
+
return {
|
|
16
|
+
next: function () {
|
|
17
|
+
if (o && i >= o.length) o = void 0;
|
|
18
|
+
return { value: o && o[i++], done: !o };
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
23
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
24
|
+
if (!m) return o;
|
|
25
|
+
var i = m.call(o), r, ar = [], e;
|
|
26
|
+
try {
|
|
27
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
28
|
+
}
|
|
29
|
+
catch (error) { e = { error: error }; }
|
|
30
|
+
finally {
|
|
31
|
+
try {
|
|
32
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
33
|
+
}
|
|
34
|
+
finally { if (e) throw e.error; }
|
|
35
|
+
}
|
|
36
|
+
return ar;
|
|
37
|
+
};
|
|
38
|
+
var __spread = (this && this.__spread) || function () {
|
|
39
|
+
for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i]));
|
|
40
|
+
return ar;
|
|
41
|
+
};
|
|
42
|
+
export * from './catalog';
|
|
43
|
+
export * from './relationship';
|
|
44
|
+
export * from './typed-dom';
|
|
45
|
+
import { pointToTwips } from '../document/length';
|
|
46
|
+
import { Paragraph } from '../document/paragraph';
|
|
47
|
+
import { FeatureRunParagraphItem } from '../document/text-range';
|
|
48
|
+
import { isWml } from '../document/wml';
|
|
49
|
+
import { DocxError } from '../../core/errors/index';
|
|
50
|
+
import { registerFeatureMaterializeHandler, registerFeatureMultiPartHandler, featureId, registerFeature, registerFeatureRunLeafHandler, } from '../../core/registry/index';
|
|
51
|
+
import { sniffImageContentType } from '../images/image-sniff';
|
|
52
|
+
import { loadOleObjectCatalog, OleObjectCatalog, OLE_OBJECT_DEFAULT_CONTENT_TYPE } from './catalog';
|
|
53
|
+
import { OFFICE_OLE_NAMESPACE, OleDrawAspect, OleLinkType, OleUpdateMode, applyOleDomMutations, oleAttributeValue, parseOleObjectDomState, readDrawAspect, readFieldCodes, readLinkType, readLinkTypeDescription, readLockedField, readObjectId, readOriginalHeight, readOriginalWidth, readProgId, readShapeId, readUpdateMode, resolveOleChild } from './typed-dom';
|
|
54
|
+
/**
|
|
55
|
+
* @private
|
|
56
|
+
*/
|
|
57
|
+
/**
|
|
58
|
+
* Feature id for the optional OLE-object module.
|
|
59
|
+
*
|
|
60
|
+
* @private
|
|
61
|
+
*/
|
|
62
|
+
export var OLE_OBJECT = featureId('ole-object');
|
|
63
|
+
/**
|
|
64
|
+
* Transitional relationship type for an embedded/linked OLE object part.
|
|
65
|
+
* Defined in {@link ./relationship}; re-exported by `export *` above.
|
|
66
|
+
*
|
|
67
|
+
* @private
|
|
68
|
+
*/
|
|
69
|
+
import { OLE_OBJECT_RELATIONSHIP_TYPE } from './relationship';
|
|
70
|
+
/**
|
|
71
|
+
* Typed, editable view over a WordprocessingML embedded/linked OLE object
|
|
72
|
+
* (`w:object` containing an `o:OLEObject`, `w:objectEmbed`, or
|
|
73
|
+
* `w:objectLink` child).
|
|
74
|
+
*
|
|
75
|
+
* @remarks
|
|
76
|
+
* **Security — never execute.** The library must never activate, open,
|
|
77
|
+
* automate, or execute OLE, ActiveX, VBA, scripts, or external content.
|
|
78
|
+
* Binary payload parts (`word/embeddings/*`) are opaque caller data: the
|
|
79
|
+
* {@link OleObject.payloadBytes} accessor moves bytes in and out verbatim
|
|
80
|
+
* and nothing in the module inspects, parses, or launches them. Link
|
|
81
|
+
* targets are stored strings and are never fetched, resolved, or probed.
|
|
82
|
+
*
|
|
83
|
+
* One semantic model over two schema-backed wire encodings (fixed at load;
|
|
84
|
+
* edits never convert forms):
|
|
85
|
+
* - `office` — `o:OLEObject` (transitional `vml-officeDrawing.xsd`
|
|
86
|
+
* `CT_OLEObject`, ECMA-376-4 §19.2.2.20)
|
|
87
|
+
* - `wml` — `w:objectEmbed` / `w:objectLink` (transitional `wml.xsd`
|
|
88
|
+
* `CT_ObjectEmbed`/`CT_ObjectLink`, ECMA-376-1 §17.3.3.20/§17.3.3.21)
|
|
89
|
+
*
|
|
90
|
+
* Setters patch only the modeled attribute/child on the stored element;
|
|
91
|
+
* every unmodeled sibling attribute/child survives verbatim. `undefined`
|
|
92
|
+
* clears the modeled member (three-state semantics).
|
|
93
|
+
*
|
|
94
|
+
* Schema citations: `w:object` (`CT_Object`, transitional `wml.xsd` line
|
|
95
|
+
* 1167; ECMA-376-1 §17.3.3.19), `CT_OLEObject` + `ST_OLEType` /
|
|
96
|
+
* `ST_OLEDrawAspect` / `ST_OLEUpdateMode` / `ST_OLELinkType`
|
|
97
|
+
* (`vml-officeDrawing.xsd` lines 291/475–493), Office behavior
|
|
98
|
+
* [MS-OI29500] §2.1.1834 (`ObjectID` unsupported on links, regenerated per
|
|
99
|
+
* save). Relationship type: `OLE_OBJECT_RELATIONSHIP_TYPE`.
|
|
100
|
+
*
|
|
101
|
+
* @private
|
|
102
|
+
*/
|
|
103
|
+
var OleObject = /** @class */ (function () {
|
|
104
|
+
/** @private */
|
|
105
|
+
function OleObject(objectElement, oleElement) {
|
|
106
|
+
/**
|
|
107
|
+
* @private True when link authoring registered a pending external target
|
|
108
|
+
* (TASK-8055) that still awaits save-time materialization.
|
|
109
|
+
*/
|
|
110
|
+
this.pendingLink = false;
|
|
111
|
+
/**
|
|
112
|
+
* @private True when icon/preview media authoring registered pending
|
|
113
|
+
* image bytes (TASK-8056) that still await save-time materialization.
|
|
114
|
+
*/
|
|
115
|
+
this.pendingIcon = false;
|
|
116
|
+
var resolved = resolveOleChild(objectElement);
|
|
117
|
+
if (resolved === undefined || resolved.oleElement !== oleElement) {
|
|
118
|
+
// Fallback for direct construction (legacy tests): derive the form
|
|
119
|
+
// from the child element itself.
|
|
120
|
+
var wireForm = oleElement.namespaceUri === OFFICE_OLE_NAMESPACE ? 'office' : 'wml';
|
|
121
|
+
this.state = parseOleObjectDomState(objectElement, oleElement, wireForm);
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
this.state = parseOleObjectDomState(objectElement, resolved.oleElement, resolved.wireForm);
|
|
125
|
+
}
|
|
126
|
+
this.relationshipIdValue = oleAttributeValue(oleElement, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships', 'id');
|
|
127
|
+
// TASK-8056: bind icon media from VML `v:imagedata/@r:id` when present
|
|
128
|
+
// (ECMA-376-4 §19.2.2.20; ECMA-376-1 §15.2.14).
|
|
129
|
+
this.imageRelationshipIdValue = readImageDataRelationshipId(objectElement);
|
|
130
|
+
}
|
|
131
|
+
Object.defineProperty(OleObject.prototype, "wireForm", {
|
|
132
|
+
/**
|
|
133
|
+
* Which schema encoding this object's `w:object` carries.
|
|
134
|
+
*
|
|
135
|
+
* @private
|
|
136
|
+
*/
|
|
137
|
+
get: function () {
|
|
138
|
+
return this.state.wireForm;
|
|
139
|
+
},
|
|
140
|
+
enumerable: true,
|
|
141
|
+
configurable: true
|
|
142
|
+
});
|
|
143
|
+
Object.defineProperty(OleObject.prototype, "linkType", {
|
|
144
|
+
/**
|
|
145
|
+
* Kind of OLE connection — `embed` (storage part) or `link` (external
|
|
146
|
+
* target). `undefined` when the stored `@Type` token is unknown
|
|
147
|
+
* (residual); the WML-native form derives this from
|
|
148
|
+
* `w:objectEmbed` vs `w:objectLink`.
|
|
149
|
+
*
|
|
150
|
+
* @private
|
|
151
|
+
*/
|
|
152
|
+
get: function () {
|
|
153
|
+
return readLinkType(this.state);
|
|
154
|
+
},
|
|
155
|
+
set: function (value) {
|
|
156
|
+
this.mutate({ type: value });
|
|
157
|
+
},
|
|
158
|
+
enumerable: true,
|
|
159
|
+
configurable: true
|
|
160
|
+
});
|
|
161
|
+
Object.defineProperty(OleObject.prototype, "progId", {
|
|
162
|
+
/**
|
|
163
|
+
* Programmatic identifier (`@ProgID` / `@progId`), e.g.
|
|
164
|
+
* `'Excel.Sheet.12'` or `'Acrobat.WordDocument.DC'`.
|
|
165
|
+
*
|
|
166
|
+
* @private
|
|
167
|
+
*/
|
|
168
|
+
get: function () {
|
|
169
|
+
return readProgId(this.state);
|
|
170
|
+
},
|
|
171
|
+
set: function (value) {
|
|
172
|
+
this.mutate({ progId: value });
|
|
173
|
+
},
|
|
174
|
+
enumerable: true,
|
|
175
|
+
configurable: true
|
|
176
|
+
});
|
|
177
|
+
Object.defineProperty(OleObject.prototype, "shapeId", {
|
|
178
|
+
/**
|
|
179
|
+
* Placeholder shape id (`@ShapeID` / `@shapeId`) — the `v:shape` this
|
|
180
|
+
* object is visually bound to.
|
|
181
|
+
*
|
|
182
|
+
* @private
|
|
183
|
+
*/
|
|
184
|
+
get: function () {
|
|
185
|
+
return readShapeId(this.state);
|
|
186
|
+
},
|
|
187
|
+
set: function (value) {
|
|
188
|
+
this.mutate({ shapeId: value });
|
|
189
|
+
},
|
|
190
|
+
enumerable: true,
|
|
191
|
+
configurable: true
|
|
192
|
+
});
|
|
193
|
+
Object.defineProperty(OleObject.prototype, "drawAspect", {
|
|
194
|
+
/**
|
|
195
|
+
* Visual representation (`@DrawAspect` / `@drawAspect`): `content`
|
|
196
|
+
* (render object content) or `icon` (placeholder icon).
|
|
197
|
+
* `undefined` = not set / unparseable residual.
|
|
198
|
+
*
|
|
199
|
+
* @private
|
|
200
|
+
*/
|
|
201
|
+
get: function () {
|
|
202
|
+
return readDrawAspect(this.state);
|
|
203
|
+
},
|
|
204
|
+
set: function (value) {
|
|
205
|
+
this.mutate({ drawAspect: value });
|
|
206
|
+
},
|
|
207
|
+
enumerable: true,
|
|
208
|
+
configurable: true
|
|
209
|
+
});
|
|
210
|
+
Object.defineProperty(OleObject.prototype, "objectId", {
|
|
211
|
+
/**
|
|
212
|
+
* Embedded-object unique id (`@ObjectID`, office form only — the
|
|
213
|
+
* WML-native form has no counterpart). Office regenerates this per save
|
|
214
|
+
* and does not support it on linked objects ([MS-OI29500] §2.1.1834).
|
|
215
|
+
*
|
|
216
|
+
* @private
|
|
217
|
+
*/
|
|
218
|
+
get: function () {
|
|
219
|
+
return readObjectId(this.state);
|
|
220
|
+
},
|
|
221
|
+
set: function (value) {
|
|
222
|
+
this.mutate({ objectId: value });
|
|
223
|
+
},
|
|
224
|
+
enumerable: true,
|
|
225
|
+
configurable: true
|
|
226
|
+
});
|
|
227
|
+
Object.defineProperty(OleObject.prototype, "updateMode", {
|
|
228
|
+
/**
|
|
229
|
+
* Link refresh mode (`@UpdateMode` / `@updateMode`): `always` or
|
|
230
|
+
* `onCall`. Meaningful for linked objects.
|
|
231
|
+
*
|
|
232
|
+
* @private
|
|
233
|
+
*/
|
|
234
|
+
get: function () {
|
|
235
|
+
return readUpdateMode(this.state);
|
|
236
|
+
},
|
|
237
|
+
set: function (value) {
|
|
238
|
+
this.mutate({ updateMode: value });
|
|
239
|
+
},
|
|
240
|
+
enumerable: true,
|
|
241
|
+
configurable: true
|
|
242
|
+
});
|
|
243
|
+
Object.defineProperty(OleObject.prototype, "lockedField", {
|
|
244
|
+
/**
|
|
245
|
+
* Whether the linked object's appearance is locked
|
|
246
|
+
* (`o:LockedField` child / `@lockedField`). `undefined` = absent.
|
|
247
|
+
*
|
|
248
|
+
* @private
|
|
249
|
+
*/
|
|
250
|
+
get: function () {
|
|
251
|
+
return readLockedField(this.state);
|
|
252
|
+
},
|
|
253
|
+
set: function (value) {
|
|
254
|
+
this.mutate({ lockedField: value });
|
|
255
|
+
},
|
|
256
|
+
enumerable: true,
|
|
257
|
+
configurable: true
|
|
258
|
+
});
|
|
259
|
+
Object.defineProperty(OleObject.prototype, "linkTypeDescription", {
|
|
260
|
+
/**
|
|
261
|
+
* `o:LinkType` child value (office form only) — e.g.
|
|
262
|
+
* `'EnhancedMetaFile'`, `'Bitmap'` (`ST_OLELinkType` is an open string).
|
|
263
|
+
*
|
|
264
|
+
* @private
|
|
265
|
+
*/
|
|
266
|
+
get: function () {
|
|
267
|
+
return readLinkTypeDescription(this.state);
|
|
268
|
+
},
|
|
269
|
+
set: function (value) {
|
|
270
|
+
this.mutate({ linkTypeDescription: value });
|
|
271
|
+
},
|
|
272
|
+
enumerable: true,
|
|
273
|
+
configurable: true
|
|
274
|
+
});
|
|
275
|
+
Object.defineProperty(OleObject.prototype, "fieldCodes", {
|
|
276
|
+
/**
|
|
277
|
+
* Stored LINK-field switches (`o:FieldCodes` child / `@fieldCodes`),
|
|
278
|
+
* e.g. `'\\f 0'`. Stored verbatim; never interpreted.
|
|
279
|
+
*
|
|
280
|
+
* @private
|
|
281
|
+
*/
|
|
282
|
+
get: function () {
|
|
283
|
+
return readFieldCodes(this.state);
|
|
284
|
+
},
|
|
285
|
+
set: function (value) {
|
|
286
|
+
this.mutate({ fieldCodes: value });
|
|
287
|
+
},
|
|
288
|
+
enumerable: true,
|
|
289
|
+
configurable: true
|
|
290
|
+
});
|
|
291
|
+
Object.defineProperty(OleObject.prototype, "originalWidth", {
|
|
292
|
+
/**
|
|
293
|
+
* Original placeholder width from `w:object/@dxaOrig` (points;
|
|
294
|
+
* wire is `ST_TwipsMeasure`).
|
|
295
|
+
*
|
|
296
|
+
* @private
|
|
297
|
+
*/
|
|
298
|
+
get: function () {
|
|
299
|
+
return readOriginalWidth(this.state);
|
|
300
|
+
},
|
|
301
|
+
set: function (value) {
|
|
302
|
+
this.mutate({
|
|
303
|
+
originalWidth: value,
|
|
304
|
+
});
|
|
305
|
+
},
|
|
306
|
+
enumerable: true,
|
|
307
|
+
configurable: true
|
|
308
|
+
});
|
|
309
|
+
Object.defineProperty(OleObject.prototype, "originalHeight", {
|
|
310
|
+
/**
|
|
311
|
+
* Original placeholder height from `w:object/@dyaOrig` (points;
|
|
312
|
+
* wire is `ST_TwipsMeasure`).
|
|
313
|
+
*
|
|
314
|
+
* @private
|
|
315
|
+
*/
|
|
316
|
+
get: function () {
|
|
317
|
+
return readOriginalHeight(this.state);
|
|
318
|
+
},
|
|
319
|
+
set: function (value) {
|
|
320
|
+
this.mutate({
|
|
321
|
+
originalHeight: value,
|
|
322
|
+
});
|
|
323
|
+
},
|
|
324
|
+
enumerable: true,
|
|
325
|
+
configurable: true
|
|
326
|
+
});
|
|
327
|
+
Object.defineProperty(OleObject.prototype, "linked", {
|
|
328
|
+
/**
|
|
329
|
+
* `true` when the object is linked (`@Type` = `Link`, or the WML-native
|
|
330
|
+
* `w:objectLink` form); otherwise treated as embedded.
|
|
331
|
+
*
|
|
332
|
+
* @private
|
|
333
|
+
*/
|
|
334
|
+
get: function () {
|
|
335
|
+
return readLinkType(this.state) === OleLinkType.Link;
|
|
336
|
+
},
|
|
337
|
+
enumerable: true,
|
|
338
|
+
configurable: true
|
|
339
|
+
});
|
|
340
|
+
Object.defineProperty(OleObject.prototype, "linkTarget", {
|
|
341
|
+
/**
|
|
342
|
+
* External link target string for linked objects (Main-WordDocument oleObject
|
|
343
|
+
* relationship with `TargetMode="External"`).
|
|
344
|
+
*
|
|
345
|
+
* **Get** returns the pending target registered by
|
|
346
|
+
* {@link Paragraph.appendOleObject} before the first save, otherwise the
|
|
347
|
+
* catalog target bound to `relationshipId`. `undefined` for embeds and
|
|
348
|
+
* when no external relationship is bound.
|
|
349
|
+
*
|
|
350
|
+
* **Security — strings only.** The value is a stored path/URI string and is
|
|
351
|
+
* never fetched, resolved, probed, opened, or executed
|
|
352
|
+
* (`.agent/policies/security.md`). Callers that need network or filesystem
|
|
353
|
+
* access must do so outside this library.
|
|
354
|
+
*
|
|
355
|
+
* @private
|
|
356
|
+
*/
|
|
357
|
+
get: function () {
|
|
358
|
+
if (readLinkType(this.state) !== OleLinkType.Link) {
|
|
359
|
+
return undefined;
|
|
360
|
+
}
|
|
361
|
+
var relationshipIdValue = this.relationshipIdValue;
|
|
362
|
+
var catalog = this.lookUpCatalog();
|
|
363
|
+
if (relationshipIdValue !== undefined &&
|
|
364
|
+
relationshipIdValue.length > 0 &&
|
|
365
|
+
catalog !== undefined) {
|
|
366
|
+
var target = catalog.targetForRelationship(relationshipIdValue);
|
|
367
|
+
if (target !== undefined) {
|
|
368
|
+
return target;
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
if (this.pendingLink && catalog !== undefined) {
|
|
372
|
+
return catalog.pendingTargetFor(this);
|
|
373
|
+
}
|
|
374
|
+
return undefined;
|
|
375
|
+
},
|
|
376
|
+
enumerable: true,
|
|
377
|
+
configurable: true
|
|
378
|
+
});
|
|
379
|
+
Object.defineProperty(OleObject.prototype, "relationshipId", {
|
|
380
|
+
/**
|
|
381
|
+
* Raw relationship id from `@r:id`, when present. Empty until a pending
|
|
382
|
+
* authored embed or link is materialized at save (images `Image`
|
|
383
|
+
* pattern).
|
|
384
|
+
*
|
|
385
|
+
* @private
|
|
386
|
+
*/
|
|
387
|
+
get: function () {
|
|
388
|
+
return this.relationshipIdValue;
|
|
389
|
+
},
|
|
390
|
+
enumerable: true,
|
|
391
|
+
configurable: true
|
|
392
|
+
});
|
|
393
|
+
Object.defineProperty(OleObject.prototype, "imageRelationshipId", {
|
|
394
|
+
/**
|
|
395
|
+
* Image relationship id from `v:imagedata/@r:id` (TASK-8056 icon/preview
|
|
396
|
+
* media). Empty until a pending authored icon is materialized at save.
|
|
397
|
+
*
|
|
398
|
+
* @private
|
|
399
|
+
*/
|
|
400
|
+
get: function () {
|
|
401
|
+
return this.imageRelationshipIdValue;
|
|
402
|
+
},
|
|
403
|
+
enumerable: true,
|
|
404
|
+
configurable: true
|
|
405
|
+
});
|
|
406
|
+
Object.defineProperty(OleObject.prototype, "previewImageBytes", {
|
|
407
|
+
/**
|
|
408
|
+
* Icon/preview image bytes (TASK-8056) — PNG or JPEG only.
|
|
409
|
+
*
|
|
410
|
+
* **Get** returns pending icon bytes registered by
|
|
411
|
+
* {@link Paragraph.appendOleObject} before the first save, otherwise the
|
|
412
|
+
* catalog icon bytes bound to `imageRelationshipId`. `undefined` when no
|
|
413
|
+
* icon/preview media is attached. Bytes are copied defensively. The library
|
|
414
|
+
* never renders, executes, or activates the image
|
|
415
|
+
* (`.agent/policies/security.md`).
|
|
416
|
+
*
|
|
417
|
+
* @private
|
|
418
|
+
*/
|
|
419
|
+
get: function () {
|
|
420
|
+
var catalog = this.lookUpCatalog();
|
|
421
|
+
if (this.pendingIcon && catalog !== undefined) {
|
|
422
|
+
var pending_1 = catalog.pendingIconBytesFor(this);
|
|
423
|
+
if (pending_1 !== undefined) {
|
|
424
|
+
return copyBytes(pending_1);
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
var imageRelationshipIdValue = this.imageRelationshipIdValue;
|
|
428
|
+
if (imageRelationshipIdValue !== undefined &&
|
|
429
|
+
imageRelationshipIdValue.length > 0 &&
|
|
430
|
+
catalog !== undefined) {
|
|
431
|
+
var bytes = catalog.iconBytesForRelationship(imageRelationshipIdValue);
|
|
432
|
+
if (bytes !== undefined) {
|
|
433
|
+
return copyBytes(bytes);
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
return undefined;
|
|
437
|
+
},
|
|
438
|
+
enumerable: true,
|
|
439
|
+
configurable: true
|
|
440
|
+
});
|
|
441
|
+
Object.defineProperty(OleObject.prototype, "payloadBytes", {
|
|
442
|
+
/**
|
|
443
|
+
* Embedded payload bytes — GO program decision Q1 (option A).
|
|
444
|
+
*
|
|
445
|
+
* **Get** returns the embedded object's stored bytes: the pending bytes
|
|
446
|
+
* registered by {@link Paragraph.appendOleObject} before the first save,
|
|
447
|
+
* otherwise the catalog bytes bound to `relationshipId`. `undefined` for
|
|
448
|
+
* linked objects (no part exists) and when the embedding part is missing.
|
|
449
|
+
* The library never interprets these bytes — they are caller data
|
|
450
|
+
* (`.agent/policies/security.md`); any sandboxing decision is the caller's.
|
|
451
|
+
*
|
|
452
|
+
* **Set** replaces the payload bytes byte-for-byte: on pending embeds
|
|
453
|
+
* (registered bytes swap) and on loaded embeddings (catalog entry marked
|
|
454
|
+
* dirty; save rewrites the part). Removing bytes (`undefined`) is not
|
|
455
|
+
* supported — detach by removing the owning run instead. The bytes are
|
|
456
|
+
* copied defensively on both paths.
|
|
457
|
+
*
|
|
458
|
+
* @throws DocxError `content/invalid-ole-object` when setting empty bytes
|
|
459
|
+
* or bytes on a linked object, or when the owning document (and therefore
|
|
460
|
+
* its catalog) is unavailable for a loaded-object write.
|
|
461
|
+
*
|
|
462
|
+
* @private
|
|
463
|
+
*/
|
|
464
|
+
get: function () {
|
|
465
|
+
if (readLinkType(this.state) === OleLinkType.Link) {
|
|
466
|
+
return undefined;
|
|
467
|
+
}
|
|
468
|
+
// Catalog-authoritative for materialized objects; pending registration
|
|
469
|
+
// covers the pre-save window (allocated bytes may differ from what the
|
|
470
|
+
// catalog ends up writing — the catalog entry is the source of truth).
|
|
471
|
+
var relationshipIdValue = this.relationshipIdValue;
|
|
472
|
+
var catalog = this.lookUpCatalog();
|
|
473
|
+
if (relationshipIdValue !== undefined &&
|
|
474
|
+
relationshipIdValue.length > 0 &&
|
|
475
|
+
catalog !== undefined) {
|
|
476
|
+
var bytes = catalog.bytesForRelationship(relationshipIdValue);
|
|
477
|
+
if (bytes !== undefined) {
|
|
478
|
+
return copyBytes(bytes);
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
if (this.pendingPayload !== undefined) {
|
|
482
|
+
return copyBytes(this.pendingPayload.bytes);
|
|
483
|
+
}
|
|
484
|
+
return undefined;
|
|
485
|
+
},
|
|
486
|
+
set: function (value) {
|
|
487
|
+
if (value === undefined) {
|
|
488
|
+
throw new DocxError('content/invalid-ole-object', 'OleObject payloadBytes cannot be cleared; remove the owning run instead');
|
|
489
|
+
}
|
|
490
|
+
if (value.byteLength === 0) {
|
|
491
|
+
throw new DocxError('content/invalid-ole-object', 'OleObject payload bytes must not be empty');
|
|
492
|
+
}
|
|
493
|
+
if (readLinkType(this.state) === OleLinkType.Link) {
|
|
494
|
+
throw new DocxError('content/invalid-ole-object', 'OleObject payloadBytes is only available on embedded objects');
|
|
495
|
+
}
|
|
496
|
+
var copy = copyBytes(value);
|
|
497
|
+
if (this.pendingPayload !== undefined) {
|
|
498
|
+
this.pendingPayload = __assign({}, this.pendingPayload, { bytes: copy });
|
|
499
|
+
// Mirror into the catalog registration so materialization writes the
|
|
500
|
+
// replacement bytes (catalog entry is the save-time source of truth).
|
|
501
|
+
var catalog_1 = this.lookUpCatalog();
|
|
502
|
+
if (catalog_1 !== undefined) {
|
|
503
|
+
catalog_1.updatePendingBytes(this, copy);
|
|
504
|
+
}
|
|
505
|
+
return;
|
|
506
|
+
}
|
|
507
|
+
var relationshipIdValue = this.relationshipIdValue;
|
|
508
|
+
var catalog = this.lookUpCatalog();
|
|
509
|
+
if (relationshipIdValue === undefined ||
|
|
510
|
+
relationshipIdValue.length === 0 ||
|
|
511
|
+
catalog === undefined) {
|
|
512
|
+
throw new DocxError('content/invalid-ole-object', 'OleObject has no embedding part to replace (not yet saved and no pending payload)');
|
|
513
|
+
}
|
|
514
|
+
catalog.replaceBytes(relationshipIdValue, copy);
|
|
515
|
+
},
|
|
516
|
+
enumerable: true,
|
|
517
|
+
configurable: true
|
|
518
|
+
});
|
|
519
|
+
/**
|
|
520
|
+
* Returns the original `w:object` element with modeled edits applied
|
|
521
|
+
* (unmodeled attributes/children stay byte-identical).
|
|
522
|
+
*
|
|
523
|
+
* @private
|
|
524
|
+
*/
|
|
525
|
+
OleObject.prototype.toOpenXml = function () {
|
|
526
|
+
return this.state.element;
|
|
527
|
+
};
|
|
528
|
+
/**
|
|
529
|
+
* Whether the authored embed or link still awaits save-time
|
|
530
|
+
* materialization. True between {@link Paragraph.appendOleObject} and the
|
|
531
|
+
* first {@link WordDocument.saveSync} (or {@link WordDocument.save}).
|
|
532
|
+
*
|
|
533
|
+
* @private
|
|
534
|
+
*/
|
|
535
|
+
OleObject.prototype.isPendingRelationship = function () {
|
|
536
|
+
return this.pendingPayload !== undefined || this.pendingLink;
|
|
537
|
+
};
|
|
538
|
+
/**
|
|
539
|
+
* Bind the materialized relationship id after catalog allocation.
|
|
540
|
+
* Patches `@r:id` on the stored `o:OLEObject`/`w:object*` element
|
|
541
|
+
* (patch-in-place: only the id value changes; prefix/position preserved).
|
|
542
|
+
*
|
|
543
|
+
* @private
|
|
544
|
+
*/
|
|
545
|
+
OleObject.prototype.resolveRelationshipId = function (relationshipId) {
|
|
546
|
+
this.relationshipIdValue = relationshipId;
|
|
547
|
+
this.pendingPayload = undefined;
|
|
548
|
+
this.pendingLink = false;
|
|
549
|
+
// Patch r:id without disturbing anything else on the element.
|
|
550
|
+
this.state = withRelationshipId(this.state, relationshipId);
|
|
551
|
+
};
|
|
552
|
+
/**
|
|
553
|
+
* Register pending embed bytes + content type (authoring path).
|
|
554
|
+
*
|
|
555
|
+
* @private
|
|
556
|
+
*/
|
|
557
|
+
OleObject.prototype.registerPendingPayload = function (bytes, contentType) {
|
|
558
|
+
this.pendingPayload = { bytes: copyBytes(bytes), contentType: contentType };
|
|
559
|
+
this.pendingLink = false;
|
|
560
|
+
};
|
|
561
|
+
/**
|
|
562
|
+
* Mark this object as a pending external link (authoring path).
|
|
563
|
+
* The target string lives on the catalog registration.
|
|
564
|
+
*
|
|
565
|
+
* @private
|
|
566
|
+
*/
|
|
567
|
+
OleObject.prototype.registerPendingLinkTarget = function () {
|
|
568
|
+
this.pendingLink = true;
|
|
569
|
+
this.pendingPayload = undefined;
|
|
570
|
+
};
|
|
571
|
+
/**
|
|
572
|
+
* Whether authored icon/preview media still awaits save-time
|
|
573
|
+
* materialization (TASK-8056; {@link PendingIconHost}).
|
|
574
|
+
*
|
|
575
|
+
* @private
|
|
576
|
+
*/
|
|
577
|
+
OleObject.prototype.isPendingIcon = function () {
|
|
578
|
+
return this.pendingIcon;
|
|
579
|
+
};
|
|
580
|
+
/**
|
|
581
|
+
* Bind the materialized image relationship id after catalog icon
|
|
582
|
+
* allocation. Patches `v:imagedata/@r:id` (TASK-8056).
|
|
583
|
+
*
|
|
584
|
+
* @private
|
|
585
|
+
*/
|
|
586
|
+
OleObject.prototype.resolveIconRelationshipId = function (relationshipId) {
|
|
587
|
+
this.imageRelationshipIdValue = relationshipId;
|
|
588
|
+
this.pendingIcon = false;
|
|
589
|
+
this.state = withImageDataRelationshipId(this.state, relationshipId);
|
|
590
|
+
};
|
|
591
|
+
/**
|
|
592
|
+
* Mark this object as carrying pending icon/preview media (authoring
|
|
593
|
+
* path). Bytes live on the catalog registration.
|
|
594
|
+
*
|
|
595
|
+
* @private
|
|
596
|
+
*/
|
|
597
|
+
OleObject.prototype.registerPendingIconMedia = function () {
|
|
598
|
+
this.pendingIcon = true;
|
|
599
|
+
};
|
|
600
|
+
/** Pending content type for catalog mirroring. @private */
|
|
601
|
+
OleObject.prototype.pendingContentType = function () {
|
|
602
|
+
return this.pendingPayload == null ? undefined : this.pendingPayload.contentType;
|
|
603
|
+
};
|
|
604
|
+
/**
|
|
605
|
+
* Look up the owning document's OLE catalog, `undefined` when detached or
|
|
606
|
+
* the feature was not registered at load (authored documents always have
|
|
607
|
+
* it because `appendOleObject` resolved one to register the payload).
|
|
608
|
+
*
|
|
609
|
+
* @private
|
|
610
|
+
*/
|
|
611
|
+
OleObject.prototype.lookUpCatalog = function () {
|
|
612
|
+
var document = this.owningDocumentOf();
|
|
613
|
+
if (document === undefined) {
|
|
614
|
+
return undefined;
|
|
615
|
+
}
|
|
616
|
+
var part = document.featurePart(OLE_OBJECT);
|
|
617
|
+
return part instanceof OleObjectCatalog ? part : undefined;
|
|
618
|
+
};
|
|
619
|
+
/**
|
|
620
|
+
* Resolve the owning document through the stored element's host run —
|
|
621
|
+
* tracked by the module when the leaf was bound to a run (authoring) or
|
|
622
|
+
* parsed under a catalog-active load. Walks up nothing structural: the
|
|
623
|
+
* catalog contact point is registered at load/append time (see
|
|
624
|
+
* `bindHostDocument`).
|
|
625
|
+
*
|
|
626
|
+
* @private
|
|
627
|
+
*/
|
|
628
|
+
OleObject.prototype.owningDocumentOf = function () {
|
|
629
|
+
return hostDocumentOf(this);
|
|
630
|
+
};
|
|
631
|
+
/**
|
|
632
|
+
* Apply one modeled mutation in a single structural pass (patch-in-place).
|
|
633
|
+
* Invalid enum values throw `DocxError('content/invalid-ole-object')`;
|
|
634
|
+
* non-positive sizes likewise.
|
|
635
|
+
*/
|
|
636
|
+
OleObject.prototype.mutate = function (mutations) {
|
|
637
|
+
var __ts33_0;
|
|
638
|
+
this.state = applyOleDomMutations(this.state, mutations);
|
|
639
|
+
this.relationshipIdValue = ((__ts33_0 = oleAttributeValue(this.state.oleElement, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships', 'id')), __ts33_0 != null ? __ts33_0 : this.relationshipIdValue);
|
|
640
|
+
};
|
|
641
|
+
return OleObject;
|
|
642
|
+
}());
|
|
643
|
+
export { OleObject };
|
|
644
|
+
/** Defensive byte copy (spec: payloadBytes copies on get/set). */
|
|
645
|
+
function copyBytes(bytes) {
|
|
646
|
+
var out = new Uint8Array(bytes.byteLength);
|
|
647
|
+
out.set(bytes);
|
|
648
|
+
return out;
|
|
649
|
+
}
|
|
650
|
+
/**
|
|
651
|
+
* Replace `@r:id` on the OLE child of a state, cloning once and keeping
|
|
652
|
+
* every other attribute/child byte-identical (materialization-time patch;
|
|
653
|
+
* the attribute exists from authoring with an empty value).
|
|
654
|
+
*/
|
|
655
|
+
function withRelationshipId(state, relationshipId) {
|
|
656
|
+
var R_NAMESPACE = 'http://schemas.openxmlformats.org/officeDocument/2006/relationships';
|
|
657
|
+
var element = state.element;
|
|
658
|
+
var oleIndex = element.children.findIndex(function (c) { return c.kind === 'element' &&
|
|
659
|
+
(c === state.oleElement ||
|
|
660
|
+
(c.namespaceUri === state.oleElement.namespaceUri &&
|
|
661
|
+
c.localName === state.oleElement.localName)); });
|
|
662
|
+
if (oleIndex < 0) {
|
|
663
|
+
return state;
|
|
664
|
+
}
|
|
665
|
+
var ole = element.children[oleIndex];
|
|
666
|
+
if (ole === undefined || ole.kind !== 'element') {
|
|
667
|
+
return state;
|
|
668
|
+
}
|
|
669
|
+
var attributes = ole.attributes.map(function (a) { return a.namespaceUri === R_NAMESPACE && a.localName === 'id'
|
|
670
|
+
? __assign({}, a, { value: relationshipId }) : a; });
|
|
671
|
+
var nextOle = __assign({}, ole, { attributes: attributes });
|
|
672
|
+
var nextElement = __assign({}, element, { children: element.children.map(function (c, i) { return (i === oleIndex ? nextOle : c); }) });
|
|
673
|
+
return { element: nextElement, oleElement: nextOle, wireForm: state.wireForm };
|
|
674
|
+
}
|
|
675
|
+
/** VML namespace for `v:shape` / `v:imagedata` (ECMA-376-4 Part 4). */
|
|
676
|
+
var VML_NAMESPACE_URI = 'urn:schemas-microsoft-com:vml';
|
|
677
|
+
/** Relationships namespace used by `r:id` on OLE and imagedata. */
|
|
678
|
+
var R_NAMESPACE_URI = 'http://schemas.openxmlformats.org/officeDocument/2006/relationships';
|
|
679
|
+
/**
|
|
680
|
+
* Read `v:imagedata/@r:id` from a `w:object` element when present
|
|
681
|
+
* (TASK-8056 load path).
|
|
682
|
+
*/
|
|
683
|
+
function readImageDataRelationshipId(objectElement) {
|
|
684
|
+
var e_1, _a, e_2, _b;
|
|
685
|
+
try {
|
|
686
|
+
for (var _c = __values(objectElement.children), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
687
|
+
var child = _d.value;
|
|
688
|
+
if (child.kind !== 'element' ||
|
|
689
|
+
child.namespaceUri !== VML_NAMESPACE_URI ||
|
|
690
|
+
child.localName !== 'shape') {
|
|
691
|
+
continue;
|
|
692
|
+
}
|
|
693
|
+
try {
|
|
694
|
+
for (var _e = __values(child.children), _f = _e.next(); !_f.done; _f = _e.next()) {
|
|
695
|
+
var shapeChild = _f.value;
|
|
696
|
+
if (shapeChild.kind !== 'element' ||
|
|
697
|
+
shapeChild.namespaceUri !== VML_NAMESPACE_URI ||
|
|
698
|
+
shapeChild.localName !== 'imagedata') {
|
|
699
|
+
continue;
|
|
700
|
+
}
|
|
701
|
+
var id = oleAttributeValue(shapeChild, R_NAMESPACE_URI, 'id');
|
|
702
|
+
if (id !== undefined && id.length > 0) {
|
|
703
|
+
return id;
|
|
704
|
+
}
|
|
705
|
+
}
|
|
706
|
+
}
|
|
707
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
708
|
+
finally {
|
|
709
|
+
try {
|
|
710
|
+
if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
|
|
711
|
+
}
|
|
712
|
+
finally { if (e_2) throw e_2.error; }
|
|
713
|
+
}
|
|
714
|
+
}
|
|
715
|
+
}
|
|
716
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
717
|
+
finally {
|
|
718
|
+
try {
|
|
719
|
+
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
|
|
720
|
+
}
|
|
721
|
+
finally { if (e_1) throw e_1.error; }
|
|
722
|
+
}
|
|
723
|
+
return undefined;
|
|
724
|
+
}
|
|
725
|
+
/**
|
|
726
|
+
* Replace `v:imagedata/@r:id` on the shape child of a state, cloning once
|
|
727
|
+
* and keeping every other attribute/child byte-identical (materialization-
|
|
728
|
+
* time icon patch; the attribute exists from authoring with an empty value
|
|
729
|
+
* when icon bytes were supplied).
|
|
730
|
+
*/
|
|
731
|
+
function withImageDataRelationshipId(state, relationshipId) {
|
|
732
|
+
var e_3, _a;
|
|
733
|
+
var element = state.element;
|
|
734
|
+
var shapeIndex = -1;
|
|
735
|
+
var shape;
|
|
736
|
+
for (var i = 0; i < element.children.length; i++) {
|
|
737
|
+
var child = element.children[i];
|
|
738
|
+
if (child !== undefined &&
|
|
739
|
+
child.kind === 'element' &&
|
|
740
|
+
child.namespaceUri === VML_NAMESPACE_URI &&
|
|
741
|
+
child.localName === 'shape') {
|
|
742
|
+
shapeIndex = i;
|
|
743
|
+
shape = child;
|
|
744
|
+
break;
|
|
745
|
+
}
|
|
746
|
+
}
|
|
747
|
+
if (shape === undefined) {
|
|
748
|
+
return state;
|
|
749
|
+
}
|
|
750
|
+
var imageDataIndex = -1;
|
|
751
|
+
var imageData;
|
|
752
|
+
for (var i = 0; i < shape.children.length; i++) {
|
|
753
|
+
var child = shape.children[i];
|
|
754
|
+
if (child !== undefined &&
|
|
755
|
+
child.kind === 'element' &&
|
|
756
|
+
child.namespaceUri === VML_NAMESPACE_URI &&
|
|
757
|
+
child.localName === 'imagedata') {
|
|
758
|
+
imageDataIndex = i;
|
|
759
|
+
imageData = child;
|
|
760
|
+
break;
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
if (imageData === undefined) {
|
|
764
|
+
return state;
|
|
765
|
+
}
|
|
766
|
+
var hasId = imageData.attributes.some(function (a) { return a.namespaceUri === R_NAMESPACE_URI && a.localName === 'id'; });
|
|
767
|
+
var attributes = hasId
|
|
768
|
+
? imageData.attributes.map(function (a) { return a.namespaceUri === R_NAMESPACE_URI && a.localName === 'id'
|
|
769
|
+
? __assign({}, a, { value: relationshipId }) : a; })
|
|
770
|
+
: __spread(imageData.attributes, [
|
|
771
|
+
{
|
|
772
|
+
namespaceUri: R_NAMESPACE_URI,
|
|
773
|
+
prefix: 'r',
|
|
774
|
+
localName: 'id',
|
|
775
|
+
value: relationshipId,
|
|
776
|
+
},
|
|
777
|
+
]);
|
|
778
|
+
var nextImageData = __assign({}, imageData, { attributes: attributes });
|
|
779
|
+
var nextShape = __assign({}, shape, { children: shape.children.map(function (c, i) { return (i === imageDataIndex ? nextImageData : c); }) });
|
|
780
|
+
var nextElement = __assign({}, element, { children: element.children.map(function (c, i) { return (i === shapeIndex ? nextShape : c); }) });
|
|
781
|
+
// oleElement reference stays valid when it is not the shape index.
|
|
782
|
+
var nextOle = state.oleElement;
|
|
783
|
+
if (state.oleElement === shape) {
|
|
784
|
+
nextOle = nextShape;
|
|
785
|
+
}
|
|
786
|
+
else {
|
|
787
|
+
try {
|
|
788
|
+
for (var _b = __values(nextElement.children), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
789
|
+
var child = _c.value;
|
|
790
|
+
if (child.kind === 'element' &&
|
|
791
|
+
child.namespaceUri === state.oleElement.namespaceUri &&
|
|
792
|
+
child.localName === state.oleElement.localName) {
|
|
793
|
+
nextOle = child;
|
|
794
|
+
break;
|
|
795
|
+
}
|
|
796
|
+
}
|
|
797
|
+
}
|
|
798
|
+
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
799
|
+
finally {
|
|
800
|
+
try {
|
|
801
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
802
|
+
}
|
|
803
|
+
finally { if (e_3) throw e_3.error; }
|
|
804
|
+
}
|
|
805
|
+
}
|
|
806
|
+
return { element: nextElement, oleElement: nextOle, wireForm: state.wireForm };
|
|
807
|
+
}
|
|
808
|
+
/**
|
|
809
|
+
* Host-document contact point for OLE leaves. Authored leaves bind their
|
|
810
|
+
* owning document at append; loaded leaves bind during body parse while the
|
|
811
|
+
* document's feature parts are visible (module-level WeakMap, keyed by the
|
|
812
|
+
* leaf instance).
|
|
813
|
+
*/
|
|
814
|
+
var hostDocuments = new WeakMap();
|
|
815
|
+
/** @private Bind a leaf to its owning document (load + authoring paths). */
|
|
816
|
+
function bindHostDocument(object, document) {
|
|
817
|
+
hostDocuments.set(object, document);
|
|
818
|
+
}
|
|
819
|
+
/** @private Host document of a leaf, when bound. */
|
|
820
|
+
function hostDocumentOf(object) {
|
|
821
|
+
return hostDocuments.get(object);
|
|
822
|
+
}
|
|
823
|
+
function parseOleObject(element) {
|
|
824
|
+
if (!isWml(element, 'object')) {
|
|
825
|
+
return undefined;
|
|
826
|
+
}
|
|
827
|
+
var resolved = resolveOleChild(element);
|
|
828
|
+
if (resolved === undefined) {
|
|
829
|
+
return undefined;
|
|
830
|
+
}
|
|
831
|
+
return new OleObject(element, resolved.oleElement);
|
|
832
|
+
}
|
|
833
|
+
var registered = false;
|
|
834
|
+
/** @private Test hook */
|
|
835
|
+
export function resetOleObjectFeatureForTests() {
|
|
836
|
+
registered = false;
|
|
837
|
+
}
|
|
838
|
+
/**
|
|
839
|
+
* Register the OLE-object run-leaf handler. Idempotent.
|
|
840
|
+
*
|
|
841
|
+
* @private
|
|
842
|
+
*/
|
|
843
|
+
export function registerOleObjectFeature() {
|
|
844
|
+
if (registered) {
|
|
845
|
+
return;
|
|
846
|
+
}
|
|
847
|
+
registered = true;
|
|
848
|
+
registerFeature({ id: OLE_OBJECT });
|
|
849
|
+
registerFeatureMultiPartHandler({
|
|
850
|
+
featureId: OLE_OBJECT,
|
|
851
|
+
relationshipTypes: [OLE_OBJECT_RELATIONSHIP_TYPE],
|
|
852
|
+
loadParts: function (pkg, ctx) {
|
|
853
|
+
return loadOleObjectCatalog(pkg, ctx.mainPartName);
|
|
854
|
+
},
|
|
855
|
+
});
|
|
856
|
+
registerFeatureMaterializeHandler({
|
|
857
|
+
featureId: OLE_OBJECT,
|
|
858
|
+
materialize: function (document) {
|
|
859
|
+
var part = document.featurePart(OLE_OBJECT);
|
|
860
|
+
if (part instanceof OleObjectCatalog) {
|
|
861
|
+
part.materializePending(document, oleObjectsInDocument(document));
|
|
862
|
+
}
|
|
863
|
+
},
|
|
864
|
+
});
|
|
865
|
+
registerFeatureRunLeafHandler({
|
|
866
|
+
featureId: OLE_OBJECT,
|
|
867
|
+
wmlLocalName: 'object',
|
|
868
|
+
tryParse: parseOleObject,
|
|
869
|
+
});
|
|
870
|
+
}
|
|
871
|
+
/**
|
|
872
|
+
* Whether a run leaf is a modeled OLE object from this module.
|
|
873
|
+
*
|
|
874
|
+
* @private
|
|
875
|
+
*/
|
|
876
|
+
export function isOleObjectLeaf(item) {
|
|
877
|
+
return item instanceof FeatureRunParagraphItem && item.featureId === OLE_OBJECT && item.value instanceof OleObject;
|
|
878
|
+
}
|
|
879
|
+
function oleObjectsFromLeaves(items) {
|
|
880
|
+
var e_4, _a;
|
|
881
|
+
var found = [];
|
|
882
|
+
try {
|
|
883
|
+
for (var items_1 = __values(items), items_1_1 = items_1.next(); !items_1_1.done; items_1_1 = items_1.next()) {
|
|
884
|
+
var item = items_1_1.value;
|
|
885
|
+
if (isOleObjectLeaf(item)) {
|
|
886
|
+
found.push(item.value);
|
|
887
|
+
}
|
|
888
|
+
}
|
|
889
|
+
}
|
|
890
|
+
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
891
|
+
finally {
|
|
892
|
+
try {
|
|
893
|
+
if (items_1_1 && !items_1_1.done && (_a = items_1.return)) _a.call(items_1);
|
|
894
|
+
}
|
|
895
|
+
finally { if (e_4) throw e_4.error; }
|
|
896
|
+
}
|
|
897
|
+
return found;
|
|
898
|
+
}
|
|
899
|
+
/**
|
|
900
|
+
* OLE objects in a paragraph, in document order. Also refreshes the
|
|
901
|
+
* host-document binding used by {@link OleObject.payloadBytes}.
|
|
902
|
+
*
|
|
903
|
+
* @private
|
|
904
|
+
*/
|
|
905
|
+
export function oleObjectsInParagraph(paragraph) {
|
|
906
|
+
return oleObjectsFromLeaves(paragraph.items.toArray());
|
|
907
|
+
}
|
|
908
|
+
/**
|
|
909
|
+
* OLE objects in the Main Document body, in document order. Also refreshes
|
|
910
|
+
* the host-document binding used by {@link OleObject.payloadBytes}.
|
|
911
|
+
*
|
|
912
|
+
* @private
|
|
913
|
+
*/
|
|
914
|
+
export function oleObjectsInDocument(document) {
|
|
915
|
+
var e_5, _a, e_6, _b;
|
|
916
|
+
var found = [];
|
|
917
|
+
try {
|
|
918
|
+
for (var _c = __values(document.listBlocks()), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
919
|
+
var block = _d.value;
|
|
920
|
+
if (block.type !== 'paragraph') {
|
|
921
|
+
continue;
|
|
922
|
+
}
|
|
923
|
+
try {
|
|
924
|
+
for (var _e = __values(oleObjectsInParagraph(block.paragraph)), _f = _e.next(); !_f.done; _f = _e.next()) {
|
|
925
|
+
var object = _f.value;
|
|
926
|
+
bindHostDocument(object, document);
|
|
927
|
+
found.push(object);
|
|
928
|
+
}
|
|
929
|
+
}
|
|
930
|
+
catch (e_6_1) { e_6 = { error: e_6_1 }; }
|
|
931
|
+
finally {
|
|
932
|
+
try {
|
|
933
|
+
if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
|
|
934
|
+
}
|
|
935
|
+
finally { if (e_6) throw e_6.error; }
|
|
936
|
+
}
|
|
937
|
+
}
|
|
938
|
+
}
|
|
939
|
+
catch (e_5_1) { e_5 = { error: e_5_1 }; }
|
|
940
|
+
finally {
|
|
941
|
+
try {
|
|
942
|
+
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
|
|
943
|
+
}
|
|
944
|
+
finally { if (e_5) throw e_5.error; }
|
|
945
|
+
}
|
|
946
|
+
return found;
|
|
947
|
+
}
|
|
948
|
+
// ---------------------------------------------------------------------------
|
|
949
|
+
// Authoring (TASK-8054): appendOleObject embed path
|
|
950
|
+
// ---------------------------------------------------------------------------
|
|
951
|
+
/** ObjectID upper bound ([MS-OI29500] §2.1.1834: `_<0..2147483647>`). */
|
|
952
|
+
var OBJECT_ID_MAX = 2147483647;
|
|
953
|
+
/** Shape id counter (module-local; Word uses `_x0000_i1026`-style tokens). */
|
|
954
|
+
var nextShapeIndex = 1026;
|
|
955
|
+
/** Anchor id counter (`w14:anchorId`, drawing-module precedent). */
|
|
956
|
+
var nextAnchorId = 0x5fe19563;
|
|
957
|
+
/**
|
|
958
|
+
* Validate one authoring option set and resolve the modeled values.
|
|
959
|
+
*
|
|
960
|
+
* @throws DocxError `content/invalid-ole-object` on any invalid input
|
|
961
|
+
* (missing/empty `progId`, missing payload/target, link-only fields on
|
|
962
|
+
* embed, non-positive size, non-finite numbers).
|
|
963
|
+
*/
|
|
964
|
+
function resolveAuthoringInput(options) {
|
|
965
|
+
var progId = options.progId;
|
|
966
|
+
if (typeof progId !== 'string' || progId.length === 0) {
|
|
967
|
+
throw new DocxError('content/invalid-ole-object', 'appendOleObject requires a non-empty progId (e.g. "Excel.Sheet.12")');
|
|
968
|
+
}
|
|
969
|
+
var hasBytes = options.bytes !== undefined;
|
|
970
|
+
var hasLinkTarget = typeof options.linkTarget === 'string' && options.linkTarget.length > 0;
|
|
971
|
+
var linkOnlySupplied = options.updateMode !== undefined ||
|
|
972
|
+
options.lockedField !== undefined ||
|
|
973
|
+
options.fieldCodes !== undefined ||
|
|
974
|
+
options.linkTypeDescription !== undefined;
|
|
975
|
+
var kind;
|
|
976
|
+
if (options.linkType === OleLinkType.Link) {
|
|
977
|
+
kind = 'link';
|
|
978
|
+
}
|
|
979
|
+
else if (options.linkType === OleLinkType.Embed) {
|
|
980
|
+
kind = 'embed';
|
|
981
|
+
}
|
|
982
|
+
else if (hasLinkTarget && !hasBytes) {
|
|
983
|
+
kind = 'link';
|
|
984
|
+
}
|
|
985
|
+
else {
|
|
986
|
+
kind = 'embed';
|
|
987
|
+
}
|
|
988
|
+
if (kind === 'embed' && linkOnlySupplied) {
|
|
989
|
+
throw new DocxError('content/invalid-ole-object', 'updateMode, lockedField, fieldCodes, and linkTypeDescription apply only to linked OLE objects');
|
|
990
|
+
}
|
|
991
|
+
if (kind === 'embed' && hasLinkTarget) {
|
|
992
|
+
throw new DocxError('content/invalid-ole-object', 'linkTarget applies only to linked OLE objects');
|
|
993
|
+
}
|
|
994
|
+
if (kind === 'link' && hasBytes) {
|
|
995
|
+
throw new DocxError('content/invalid-ole-object', 'payload bytes apply only to embedded OLE objects; linked objects store an external target string only');
|
|
996
|
+
}
|
|
997
|
+
var width = positivePointsOrThrow('width', options.width != null ? options.width : 72);
|
|
998
|
+
var height = positivePointsOrThrow('height', options.height != null ? options.height : 72);
|
|
999
|
+
// DrawAspect follows displayAsIcon only (program GO Q3) — iconBytes alone
|
|
1000
|
+
// never forces Icon.
|
|
1001
|
+
var drawAspect = options.displayAsIcon === true ? OleDrawAspect.Icon : OleDrawAspect.Content;
|
|
1002
|
+
var iconBytes;
|
|
1003
|
+
var iconContentType;
|
|
1004
|
+
if (options.iconBytes !== undefined) {
|
|
1005
|
+
var rawIcon = options.iconBytes;
|
|
1006
|
+
if (!(rawIcon instanceof Uint8Array) || rawIcon.byteLength === 0) {
|
|
1007
|
+
throw new DocxError('content/invalid-ole-object', 'appendOleObject iconBytes must be a non-empty PNG or JPEG byte sequence');
|
|
1008
|
+
}
|
|
1009
|
+
var sniffed = sniffImageContentType(rawIcon);
|
|
1010
|
+
if (sniffed === undefined) {
|
|
1011
|
+
throw new DocxError('content/invalid-ole-object', 'appendOleObject iconBytes must sniff as image/png or image/jpeg');
|
|
1012
|
+
}
|
|
1013
|
+
iconBytes = copyBytes(rawIcon);
|
|
1014
|
+
iconContentType = sniffed;
|
|
1015
|
+
}
|
|
1016
|
+
var common = {
|
|
1017
|
+
progId: progId,
|
|
1018
|
+
width: width,
|
|
1019
|
+
height: height,
|
|
1020
|
+
drawAspect: drawAspect,
|
|
1021
|
+
name: options.name,
|
|
1022
|
+
description: options.description,
|
|
1023
|
+
iconBytes: iconBytes,
|
|
1024
|
+
iconContentType: iconContentType,
|
|
1025
|
+
};
|
|
1026
|
+
if (kind === 'link') {
|
|
1027
|
+
var linkTarget = options.linkTarget;
|
|
1028
|
+
if (typeof linkTarget !== 'string' || linkTarget.length === 0) {
|
|
1029
|
+
throw new DocxError('content/invalid-ole-object', 'appendOleObject link path requires a non-empty linkTarget string');
|
|
1030
|
+
}
|
|
1031
|
+
// Typed as OleUpdateMode; only Always | OnCall are valid public values.
|
|
1032
|
+
var updateMode = options.updateMode === OleUpdateMode.OnCall
|
|
1033
|
+
? OleUpdateMode.OnCall
|
|
1034
|
+
: OleUpdateMode.Always;
|
|
1035
|
+
return __assign({ kind: 'link' }, common, { linkTarget: linkTarget,
|
|
1036
|
+
updateMode: updateMode, lockedField: options.lockedField, fieldCodes: options.fieldCodes, linkTypeDescription: options.linkTypeDescription });
|
|
1037
|
+
}
|
|
1038
|
+
var bytes = options.bytes;
|
|
1039
|
+
if (!(bytes instanceof Uint8Array) || bytes.byteLength === 0) {
|
|
1040
|
+
throw new DocxError('content/invalid-ole-object', 'appendOleObject embed requires non-empty bytes for the embedded object');
|
|
1041
|
+
}
|
|
1042
|
+
return __assign({ kind: 'embed' }, common, { bytes: bytes, contentType: options.contentType != null ? options.contentType : OLE_OBJECT_DEFAULT_CONTENT_TYPE });
|
|
1043
|
+
}
|
|
1044
|
+
/** Validate a positive finite point measure for authoring (wire convert later). */
|
|
1045
|
+
function positivePointsOrThrow(name, value) {
|
|
1046
|
+
var asNumber = value;
|
|
1047
|
+
if (typeof asNumber !== 'number' || !Number.isFinite(asNumber)) {
|
|
1048
|
+
throw new DocxError('content/invalid-ole-object', "OleObject " + name + " must be a finite point value");
|
|
1049
|
+
}
|
|
1050
|
+
if (asNumber < 0) {
|
|
1051
|
+
throw new DocxError('content/invalid-ole-object', "OleObject " + name + " must be a positive point value");
|
|
1052
|
+
}
|
|
1053
|
+
// Reject values that would serialize to a non-positive twips measure.
|
|
1054
|
+
if (pointToTwips(value) <= 0) {
|
|
1055
|
+
throw new DocxError('content/invalid-ole-object', "OleObject " + name + " must be a positive point value");
|
|
1056
|
+
}
|
|
1057
|
+
return value;
|
|
1058
|
+
}
|
|
1059
|
+
/** Next `_<0..2147483647>` ObjectID ([MS-OI29500] §2.1.1834 format). */
|
|
1060
|
+
function allocateObjectId() {
|
|
1061
|
+
// Deterministic-per-process counter in the Word format; Office regenerates
|
|
1062
|
+
// this value on every save, so stability across runs is not required.
|
|
1063
|
+
nextObjectIdValue = (nextObjectIdValue + 1) % (OBJECT_ID_MAX + 1);
|
|
1064
|
+
return "_" + String(nextObjectIdValue);
|
|
1065
|
+
}
|
|
1066
|
+
var nextObjectIdValue = 1850929220 % OBJECT_ID_MAX;
|
|
1067
|
+
/** Next `_x0000_i{N}` shape id token (Word's conventional VML naming). */
|
|
1068
|
+
function allocateShapeId() {
|
|
1069
|
+
var id = "_x0000_i" + String(nextShapeIndex);
|
|
1070
|
+
nextShapeIndex += 1;
|
|
1071
|
+
return id;
|
|
1072
|
+
}
|
|
1073
|
+
/** Next `w14:anchorId` token (8 uppercase hex digits, drawing precedent). */
|
|
1074
|
+
function allocateAnchorId() {
|
|
1075
|
+
nextAnchorId = (nextAnchorId + 1) % 0xffffffff;
|
|
1076
|
+
var hex = nextAnchorId.toString(16).toUpperCase();
|
|
1077
|
+
return hex.length >= 8 ? hex : new Array(8 - hex.length + 1).join('0') + hex;
|
|
1078
|
+
}
|
|
1079
|
+
/** `style="width:{pt}pt;height:{pt}pt"` for the authored `v:shape` (points in, points out). */
|
|
1080
|
+
function shapeStyle(widthPoints, heightPoints) {
|
|
1081
|
+
return "width:" + formatPointsForStyle(widthPoints) + "pt;height:" + formatPointsForStyle(heightPoints) + "pt";
|
|
1082
|
+
}
|
|
1083
|
+
/** Points → VML style number text (2-decimal round, drop trailing .0). */
|
|
1084
|
+
function formatPointsForStyle(points) {
|
|
1085
|
+
var rounded = Math.round(points * 100) / 100;
|
|
1086
|
+
return Number.isInteger(rounded) ? String(rounded) : String(rounded);
|
|
1087
|
+
}
|
|
1088
|
+
/** Element in a namespace with a prefix. */
|
|
1089
|
+
function el(namespaceUri, prefix, localName, attributes, children, namespaceDeclarations) {
|
|
1090
|
+
if (children === void 0) { children = []; }
|
|
1091
|
+
if (namespaceDeclarations === void 0) { namespaceDeclarations = []; }
|
|
1092
|
+
return {
|
|
1093
|
+
kind: 'element',
|
|
1094
|
+
namespaceUri: namespaceUri,
|
|
1095
|
+
prefix: prefix,
|
|
1096
|
+
localName: localName,
|
|
1097
|
+
attributes: attributes,
|
|
1098
|
+
namespaceDeclarations: __spread(namespaceDeclarations),
|
|
1099
|
+
children: children,
|
|
1100
|
+
};
|
|
1101
|
+
}
|
|
1102
|
+
/**
|
|
1103
|
+
* Build the authored `w:object` subtree per the ECMA-376-4 §19.2.2.20
|
|
1104
|
+
* example-2 template (program GO decision Q2: always the VML
|
|
1105
|
+
* `o:OLEObject` form — Word's current output):
|
|
1106
|
+
*
|
|
1107
|
+
* ```xml
|
|
1108
|
+
* <w:object w:dxaOrig="…" w:dyaOrig="…" w14:anchorId="…">
|
|
1109
|
+
* <v:shape id="_x0000_iNNNN" type="#_x0000_t75" style="width:…pt;height:…pt"
|
|
1110
|
+
* o:ole="" alt="…">
|
|
1111
|
+
* <v:imagedata/> <!-- only when icon bytes exist (TASK-8056) -->
|
|
1112
|
+
* </v:shape>
|
|
1113
|
+
* <o:OLEObject Type="Embed|Link" ProgID="…" ShapeID="…" DrawAspect="…"
|
|
1114
|
+
* [UpdateMode="Always|OnCall"] [ObjectID="_…"] r:id="rIdN">
|
|
1115
|
+
* [o:LinkType][o:LockedField][o:FieldCodes] <!-- link children order -->
|
|
1116
|
+
* </o:OLEObject>
|
|
1117
|
+
* </w:object>
|
|
1118
|
+
* ```
|
|
1119
|
+
*
|
|
1120
|
+
* `ShapeID` is shared between `v:shape/@id` and `o:OLEObject/@ShapeID`;
|
|
1121
|
+
* the placeholder shape carries the `o:ole=""` marker. Embeds carry the
|
|
1122
|
+
* Office-required minimum attribute set (`r:id`/`ObjectID`/`ProgID`/
|
|
1123
|
+
* `ShapeID`, [MS-OI29500] §2.1.1834). Links omit `ObjectID` (same clause —
|
|
1124
|
+
* unsupported on linked objects) and emit required `UpdateMode`. `r:id` is
|
|
1125
|
+
* empty here and written at materialization.
|
|
1126
|
+
*/
|
|
1127
|
+
function buildAuthoredOleObjectElement(resolved) {
|
|
1128
|
+
var shapeId = allocateShapeId();
|
|
1129
|
+
var VML_NAMESPACE = 'urn:schemas-microsoft-com:vml';
|
|
1130
|
+
var W14_NAMESPACE = 'http://schemas.microsoft.com/office/word/2010/wordml';
|
|
1131
|
+
var R_NAMESPACE = 'http://schemas.openxmlformats.org/officeDocument/2006/relationships';
|
|
1132
|
+
// TS 3.3 does not narrow discriminated unions through a boolean local.
|
|
1133
|
+
var shapeAttributes = [
|
|
1134
|
+
{ namespaceUri: '', prefix: '', localName: 'id', value: shapeId },
|
|
1135
|
+
{ namespaceUri: '', prefix: '', localName: 'type', value: '#_x0000_t75' },
|
|
1136
|
+
{
|
|
1137
|
+
namespaceUri: '',
|
|
1138
|
+
prefix: '',
|
|
1139
|
+
localName: 'style',
|
|
1140
|
+
value: shapeStyle(resolved.width, resolved.height),
|
|
1141
|
+
},
|
|
1142
|
+
// The OLE placeholder marker (§19.2.2.20 example 2: `o:ole=""`).
|
|
1143
|
+
{ namespaceUri: OFFICE_OLE_NAMESPACE, prefix: 'o', localName: 'ole', value: '' },
|
|
1144
|
+
];
|
|
1145
|
+
if (resolved.name !== undefined) {
|
|
1146
|
+
shapeAttributes.push({ namespaceUri: '', prefix: '', localName: 'alt', value: resolved.name });
|
|
1147
|
+
}
|
|
1148
|
+
if (resolved.description !== undefined) {
|
|
1149
|
+
shapeAttributes.push({
|
|
1150
|
+
namespaceUri: '',
|
|
1151
|
+
prefix: '',
|
|
1152
|
+
localName: 'title',
|
|
1153
|
+
value: resolved.description,
|
|
1154
|
+
});
|
|
1155
|
+
}
|
|
1156
|
+
// v:imagedata only when icon bytes exist (TASK-8056; ECMA-376-4 §19.2.2.20).
|
|
1157
|
+
// r:id is empty here and patched at materialization (same pattern as OLE r:id).
|
|
1158
|
+
var shapeChildren = [];
|
|
1159
|
+
if (resolved.iconBytes !== undefined && resolved.iconContentType !== undefined) {
|
|
1160
|
+
var imageDataAttributes = [
|
|
1161
|
+
{ namespaceUri: R_NAMESPACE, prefix: 'r', localName: 'id', value: '' },
|
|
1162
|
+
];
|
|
1163
|
+
if (resolved.description !== undefined) {
|
|
1164
|
+
imageDataAttributes.push({
|
|
1165
|
+
namespaceUri: OFFICE_OLE_NAMESPACE,
|
|
1166
|
+
prefix: 'o',
|
|
1167
|
+
localName: 'title',
|
|
1168
|
+
value: resolved.description,
|
|
1169
|
+
});
|
|
1170
|
+
}
|
|
1171
|
+
shapeChildren.push(el(VML_NAMESPACE, 'v', 'imagedata', imageDataAttributes));
|
|
1172
|
+
}
|
|
1173
|
+
var shape = el(VML_NAMESPACE, 'v', 'shape', shapeAttributes, shapeChildren);
|
|
1174
|
+
// o:OLEObject attributes in schema declaration order: Type, ProgID,
|
|
1175
|
+
// ShapeID, DrawAspect, ObjectID (embed), UpdateMode (link), r:id.
|
|
1176
|
+
var oleAttributes = [
|
|
1177
|
+
{ namespaceUri: '', prefix: '', localName: 'Type', value: resolved.kind === 'link' ? 'Link' : 'Embed' },
|
|
1178
|
+
{ namespaceUri: '', prefix: '', localName: 'ProgID', value: resolved.progId },
|
|
1179
|
+
{ namespaceUri: '', prefix: '', localName: 'ShapeID', value: shapeId },
|
|
1180
|
+
{
|
|
1181
|
+
namespaceUri: '',
|
|
1182
|
+
prefix: '',
|
|
1183
|
+
localName: 'DrawAspect',
|
|
1184
|
+
value: resolved.drawAspect === OleDrawAspect.Icon ? 'Icon' : 'Content',
|
|
1185
|
+
},
|
|
1186
|
+
];
|
|
1187
|
+
if (resolved.kind === 'link') {
|
|
1188
|
+
// CT_ObjectLink / CT_OLEObject required UpdateMode on linked objects.
|
|
1189
|
+
oleAttributes.push({
|
|
1190
|
+
namespaceUri: '',
|
|
1191
|
+
prefix: '',
|
|
1192
|
+
localName: 'UpdateMode',
|
|
1193
|
+
value: resolved.updateMode === OleUpdateMode.OnCall ? 'OnCall' : 'Always',
|
|
1194
|
+
});
|
|
1195
|
+
}
|
|
1196
|
+
else {
|
|
1197
|
+
// ObjectID is embed-only ([MS-OI29500] §2.1.1834 — unsupported on links).
|
|
1198
|
+
oleAttributes.push({
|
|
1199
|
+
namespaceUri: '',
|
|
1200
|
+
prefix: '',
|
|
1201
|
+
localName: 'ObjectID',
|
|
1202
|
+
value: allocateObjectId(),
|
|
1203
|
+
});
|
|
1204
|
+
}
|
|
1205
|
+
oleAttributes.push({ namespaceUri: R_NAMESPACE, prefix: 'r', localName: 'id', value: '' });
|
|
1206
|
+
// Office children in CT_OLEObject sequence: LinkType → LockedField → FieldCodes.
|
|
1207
|
+
var oleChildren = [];
|
|
1208
|
+
if (resolved.kind === 'link') {
|
|
1209
|
+
if (typeof resolved.linkTypeDescription === 'string') {
|
|
1210
|
+
oleChildren.push(el(OFFICE_OLE_NAMESPACE, 'o', 'LinkType', [], [
|
|
1211
|
+
{ kind: 'text', value: resolved.linkTypeDescription },
|
|
1212
|
+
]));
|
|
1213
|
+
}
|
|
1214
|
+
if (resolved.lockedField !== undefined) {
|
|
1215
|
+
oleChildren.push(el(OFFICE_OLE_NAMESPACE, 'o', 'LockedField', [], [
|
|
1216
|
+
{ kind: 'text', value: resolved.lockedField ? 't' : 'f' },
|
|
1217
|
+
]));
|
|
1218
|
+
}
|
|
1219
|
+
if (typeof resolved.fieldCodes === 'string') {
|
|
1220
|
+
oleChildren.push(el(OFFICE_OLE_NAMESPACE, 'o', 'FieldCodes', [], [
|
|
1221
|
+
{ kind: 'text', value: resolved.fieldCodes },
|
|
1222
|
+
]));
|
|
1223
|
+
}
|
|
1224
|
+
}
|
|
1225
|
+
var oleElement = el(OFFICE_OLE_NAMESPACE, 'o', 'OLEObject', oleAttributes, oleChildren);
|
|
1226
|
+
var element = el(WML_TRANSITIONAL, 'w', 'object', [
|
|
1227
|
+
{
|
|
1228
|
+
namespaceUri: WML_TRANSITIONAL,
|
|
1229
|
+
prefix: 'w',
|
|
1230
|
+
localName: 'dxaOrig',
|
|
1231
|
+
value: String(pointToTwips(resolved.width)),
|
|
1232
|
+
},
|
|
1233
|
+
{
|
|
1234
|
+
namespaceUri: WML_TRANSITIONAL,
|
|
1235
|
+
prefix: 'w',
|
|
1236
|
+
localName: 'dyaOrig',
|
|
1237
|
+
value: String(pointToTwips(resolved.height)),
|
|
1238
|
+
},
|
|
1239
|
+
{
|
|
1240
|
+
namespaceUri: W14_NAMESPACE,
|
|
1241
|
+
prefix: 'w14',
|
|
1242
|
+
localName: 'anchorId',
|
|
1243
|
+
value: allocateAnchorId(),
|
|
1244
|
+
},
|
|
1245
|
+
], [shape, oleElement],
|
|
1246
|
+
// The authored tree declares the namespaces it uses (Word writes these
|
|
1247
|
+
// on the root; a local declaration keeps the subtree well-formed when
|
|
1248
|
+
// the host document lacks them).
|
|
1249
|
+
[
|
|
1250
|
+
{ prefix: 'w14', namespaceUri: W14_NAMESPACE },
|
|
1251
|
+
{ prefix: 'v', namespaceUri: VML_NAMESPACE },
|
|
1252
|
+
{ prefix: 'o', namespaceUri: OFFICE_OLE_NAMESPACE },
|
|
1253
|
+
{ prefix: 'r', namespaceUri: R_NAMESPACE },
|
|
1254
|
+
]);
|
|
1255
|
+
return { element: element, oleElement: oleElement, shapeId: shapeId };
|
|
1256
|
+
}
|
|
1257
|
+
/** Transitional WML namespace (local constant to avoid a core cycle). */
|
|
1258
|
+
var WML_TRANSITIONAL = 'http://schemas.openxmlformats.org/wordprocessingml/2006/main';
|
|
1259
|
+
/**
|
|
1260
|
+
* Resolve the owning document's OLE catalog for authoring.
|
|
1261
|
+
*
|
|
1262
|
+
* @throws DocxError `feature/not-registered` when the OLE module was not
|
|
1263
|
+
* registered before the document was loaded/created (authored path is
|
|
1264
|
+
* impossible without the catalog).
|
|
1265
|
+
*/
|
|
1266
|
+
function catalogForAuthoring(paragraph) {
|
|
1267
|
+
var document = paragraph.owningDocument();
|
|
1268
|
+
var part = document.featurePart(OLE_OBJECT);
|
|
1269
|
+
if (part === undefined || !(part instanceof OleObjectCatalog)) {
|
|
1270
|
+
throw new DocxError('feature/not-registered', 'OLE object catalog was not loaded; call registerOleObjectFeature() before WordDocument.open');
|
|
1271
|
+
}
|
|
1272
|
+
return part;
|
|
1273
|
+
}
|
|
1274
|
+
/**
|
|
1275
|
+
* Author one embedded or linked OLE object and append it to the paragraph
|
|
1276
|
+
* (receiver-owns R2.1; one statement R3.2).
|
|
1277
|
+
*
|
|
1278
|
+
* **Embed path (TASK-8054):** registers payload bytes with the document
|
|
1279
|
+
* catalog at append (pending-relationship pattern, images/ink precedent);
|
|
1280
|
+
* the embedding part `word/embeddings/oleObject{N}.bin`, its main-document
|
|
1281
|
+
* relationship, and the content-type Override are allocated at save.
|
|
1282
|
+
*
|
|
1283
|
+
* **Link path (TASK-8055):** registers an external target string only —
|
|
1284
|
+
* no package part. Save allocates a Main-WordDocument oleObject relationship
|
|
1285
|
+
* with `TargetMode="External"` using the transitional relationship type
|
|
1286
|
+
* (never the Office 2019 long-path type). The target is **never fetched
|
|
1287
|
+
* or opened** (`.agent/policies/security.md`).
|
|
1288
|
+
*
|
|
1289
|
+
* Returns the created {@link OleObject} view (`relationshipId` empty until
|
|
1290
|
+
* the first save materializes it).
|
|
1291
|
+
*
|
|
1292
|
+
* @example
|
|
1293
|
+
* ```ts
|
|
1294
|
+
* // Embed
|
|
1295
|
+
* const embedded = paragraph.appendOleObject({
|
|
1296
|
+
* progId: 'Excel.Sheet.12',
|
|
1297
|
+
* bytes: workbookBytes,
|
|
1298
|
+
* width: (75.35),
|
|
1299
|
+
* height: (49.4),
|
|
1300
|
+
* displayAsIcon: true,
|
|
1301
|
+
* });
|
|
1302
|
+
*
|
|
1303
|
+
* // Link (external target string only — never fetched)
|
|
1304
|
+
* const linked = paragraph.appendOleObject({
|
|
1305
|
+
* progId: 'Excel.Sheet.12',
|
|
1306
|
+
* linkTarget: 'C:\\\\Data\\\\report.xlsx',
|
|
1307
|
+
* updateMode: OleUpdateMode.OnCall,
|
|
1308
|
+
* lockedField: true,
|
|
1309
|
+
* fieldCodes: '\\\\f 0',
|
|
1310
|
+
* displayAsIcon: true,
|
|
1311
|
+
* });
|
|
1312
|
+
* ```
|
|
1313
|
+
*
|
|
1314
|
+
* @throws DocxError `content/invalid-ole-object` on invalid options
|
|
1315
|
+
* (missing `progId`, missing payload/target, link-only fields on embed,
|
|
1316
|
+
* non-positive size).
|
|
1317
|
+
* @throws DocxError `feature/not-registered` when the module is not
|
|
1318
|
+
* registered before load.
|
|
1319
|
+
* @throws DetachedObjectError when the paragraph is not in a document.
|
|
1320
|
+
*
|
|
1321
|
+
* @private
|
|
1322
|
+
*/
|
|
1323
|
+
export function appendOleObjectToParagraph(paragraph, options) {
|
|
1324
|
+
var resolved = resolveAuthoringInput(options);
|
|
1325
|
+
var catalog = catalogForAuthoring(paragraph);
|
|
1326
|
+
var authored = buildAuthoredOleObjectElement(resolved);
|
|
1327
|
+
var object = new OleObject(authored.element, authored.oleElement);
|
|
1328
|
+
bindHostDocument(object, paragraph.owningDocument());
|
|
1329
|
+
if (resolved.kind === 'link') {
|
|
1330
|
+
// Target is a stored string only — catalog never fetches or opens it.
|
|
1331
|
+
object.registerPendingLinkTarget();
|
|
1332
|
+
catalog.registerPendingLink(object, resolved.linkTarget);
|
|
1333
|
+
}
|
|
1334
|
+
else {
|
|
1335
|
+
object.registerPendingPayload(resolved.bytes, resolved.contentType);
|
|
1336
|
+
catalog.registerPendingEmbed(object, resolved.bytes, resolved.contentType);
|
|
1337
|
+
}
|
|
1338
|
+
// TASK-8056: pending icon media (PNG/JPEG only; already sniffed).
|
|
1339
|
+
if (resolved.iconBytes !== undefined && resolved.iconContentType !== undefined) {
|
|
1340
|
+
object.registerPendingIconMedia();
|
|
1341
|
+
catalog.registerPendingIcon(object, resolved.iconBytes, resolved.iconContentType);
|
|
1342
|
+
}
|
|
1343
|
+
paragraph.appendFeatureRunItem(OLE_OBJECT, object);
|
|
1344
|
+
return object;
|
|
1345
|
+
}
|
|
1346
|
+
/**
|
|
1347
|
+
* Remove an OLE object run from its paragraph and drop the embedding part
|
|
1348
|
+
* or external link relationship on the next save (GC parity with
|
|
1349
|
+
* `paragraph.appendFeatureRunItem(OLE_OBJECT, object
|
|
1350
|
+
* this paragraph.
|
|
1351
|
+
*
|
|
1352
|
+
* @private
|
|
1353
|
+
*/
|
|
1354
|
+
export function removeOleObject(document, paragraph, object) {
|
|
1355
|
+
var e_7, _a;
|
|
1356
|
+
try {
|
|
1357
|
+
for (var _b = __values(paragraph.items), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
1358
|
+
var item = _c.value;
|
|
1359
|
+
if (isOleObjectLeaf(item) && item.value === object) {
|
|
1360
|
+
paragraph.removeFeatureRunItem(object);
|
|
1361
|
+
var catalog = documentOleCatalog(document);
|
|
1362
|
+
if (catalog !== undefined) {
|
|
1363
|
+
if (object.isPendingRelationship()) {
|
|
1364
|
+
if (object.linked) {
|
|
1365
|
+
catalog.discardPendingLink(object);
|
|
1366
|
+
}
|
|
1367
|
+
else {
|
|
1368
|
+
catalog.discardPendingEmbed(object);
|
|
1369
|
+
}
|
|
1370
|
+
}
|
|
1371
|
+
else if (object.relationshipId !== undefined && object.relationshipId.length > 0) {
|
|
1372
|
+
catalog.removeEntry(object.relationshipId);
|
|
1373
|
+
}
|
|
1374
|
+
// TASK-8056: drop pending or materialized icon media with the object.
|
|
1375
|
+
if (object.isPendingIcon()) {
|
|
1376
|
+
catalog.discardPendingIcon(object);
|
|
1377
|
+
}
|
|
1378
|
+
else {
|
|
1379
|
+
var imageRelationshipId = object.imageRelationshipId;
|
|
1380
|
+
if (imageRelationshipId !== undefined && imageRelationshipId.length > 0) {
|
|
1381
|
+
catalog.removeIconEntry(imageRelationshipId);
|
|
1382
|
+
}
|
|
1383
|
+
}
|
|
1384
|
+
}
|
|
1385
|
+
return;
|
|
1386
|
+
}
|
|
1387
|
+
}
|
|
1388
|
+
}
|
|
1389
|
+
catch (e_7_1) { e_7 = { error: e_7_1 }; }
|
|
1390
|
+
finally {
|
|
1391
|
+
try {
|
|
1392
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
1393
|
+
}
|
|
1394
|
+
finally { if (e_7) throw e_7.error; }
|
|
1395
|
+
}
|
|
1396
|
+
throw new DocxError('content/invalid-ole-object', 'OLE object is not in this paragraph');
|
|
1397
|
+
}
|
|
1398
|
+
/** Catalog of a loaded document, `undefined` when the feature is absent. */
|
|
1399
|
+
function documentOleCatalog(document) {
|
|
1400
|
+
var part = document.featurePart(OLE_OBJECT);
|
|
1401
|
+
return part instanceof OleObjectCatalog ? part : undefined;
|
|
1402
|
+
}
|
|
1403
|
+
/**
|
|
1404
|
+
* Package catalog for a loaded document.
|
|
1405
|
+
*
|
|
1406
|
+
* @throws DocxError `feature/not-registered` when the module was not
|
|
1407
|
+
* registered before load.
|
|
1408
|
+
*
|
|
1409
|
+
* @private
|
|
1410
|
+
*/
|
|
1411
|
+
export function oleObjectCatalog(document) {
|
|
1412
|
+
var catalog = documentOleCatalog(document);
|
|
1413
|
+
if (catalog === undefined) {
|
|
1414
|
+
throw new DocxError('feature/not-registered', 'OLE object catalog was not loaded; call registerOleObjectFeature() before WordDocument.open');
|
|
1415
|
+
}
|
|
1416
|
+
return catalog;
|
|
1417
|
+
}
|
|
1418
|
+
Paragraph.prototype.appendOleObject = function (options) {
|
|
1419
|
+
return appendOleObjectToParagraph(this, options);
|
|
1420
|
+
};
|
|
1421
|
+
registerOleObjectFeature();
|