@syncfusion/ej2-docx 0.0.0-stage → 35.1.39
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +68 -2
- package/core.js +4 -0
- package/dist/ej2-docx.umd.min.js +2 -0
- package/dist/ej2-docx.umd.min.js.map +1 -0
- package/dist/es6/ej2-docx.es2015.js +66697 -0
- package/dist/es6/ej2-docx.es2015.js.map +1 -0
- package/dist/es6/ej2-docx.es5.js +77568 -0
- package/dist/es6/ej2-docx.es5.js.map +1 -0
- package/dist/global/ej2-docx.min.js +2 -0
- package/dist/global/ej2-docx.min.js.map +1 -0
- package/dist/global/index.d.ts +5 -0
- package/features.js +4 -0
- package/index.js +4 -0
- package/license +10 -0
- package/package.json +31 -4
- package/src/all.d.ts +50 -0
- package/src/all.js +147 -0
- package/src/core/compat/base64.d.ts +13 -0
- package/src/core/compat/base64.js +90 -0
- package/src/core/compat/object-compat.d.ts +30 -0
- package/src/core/compat/object-compat.js +40 -0
- package/src/core/compat/sha256.d.ts +9 -0
- package/src/core/compat/sha256.js +98 -0
- package/src/core/errors/docx-error.d.ts +89 -0
- package/src/core/errors/docx-error.js +138 -0
- package/src/core/errors/error-codes.d.ts +8 -0
- package/src/core/errors/error-codes.js +0 -0
- package/src/core/errors/index.d.ts +10 -0
- package/src/core/errors/index.js +9 -0
- package/src/core/index.d.ts +12 -0
- package/src/core/index.js +12 -0
- package/src/core/mc/alternate-content.d.ts +7 -0
- package/src/core/mc/alternate-content.js +67 -0
- package/src/core/mc/attributes.d.ts +24 -0
- package/src/core/mc/attributes.js +82 -0
- package/src/core/mc/index.d.ts +7 -0
- package/src/core/mc/index.js +5 -0
- package/src/core/mc/inspect.d.ts +16 -0
- package/src/core/mc/inspect.js +148 -0
- package/src/core/mc/namespaces.d.ts +4 -0
- package/src/core/mc/namespaces.js +4 -0
- package/src/core/mc/scope.d.ts +6 -0
- package/src/core/mc/scope.js +47 -0
- package/src/core/opc/content-types.d.ts +34 -0
- package/src/core/opc/content-types.js +162 -0
- package/src/core/opc/index.d.ts +8 -0
- package/src/core/opc/index.js +4 -0
- package/src/core/opc/package.d.ts +49 -0
- package/src/core/opc/package.js +324 -0
- package/src/core/opc/part-name.d.ts +47 -0
- package/src/core/opc/part-name.js +205 -0
- package/src/core/opc/relationships.d.ts +46 -0
- package/src/core/opc/relationships.js +212 -0
- package/src/core/preservation/index.d.ts +2 -0
- package/src/core/preservation/index.js +1 -0
- package/src/core/preservation/opaque-body.d.ts +16 -0
- package/src/core/preservation/opaque-body.js +69 -0
- package/src/core/registry/block-handlers.d.ts +30 -0
- package/src/core/registry/block-handlers.js +36 -0
- package/src/core/registry/create-defaults.d.ts +39 -0
- package/src/core/registry/create-defaults.js +42 -0
- package/src/core/registry/feature-registry.d.ts +20 -0
- package/src/core/registry/feature-registry.js +29 -0
- package/src/core/registry/index.d.ts +9 -0
- package/src/core/registry/index.js +8 -0
- package/src/core/registry/inline-handlers.d.ts +20 -0
- package/src/core/registry/inline-handlers.js +30 -0
- package/src/core/registry/materialize-handlers.d.ts +35 -0
- package/src/core/registry/materialize-handlers.js +75 -0
- package/src/core/registry/multi-part-handlers.d.ts +37 -0
- package/src/core/registry/multi-part-handlers.js +206 -0
- package/src/core/registry/package-part-handlers.d.ts +28 -0
- package/src/core/registry/package-part-handlers.js +190 -0
- package/src/core/registry/part-handlers.d.ts +24 -0
- package/src/core/registry/part-handlers.js +172 -0
- package/src/core/registry/run-leaf-handlers.d.ts +26 -0
- package/src/core/registry/run-leaf-handlers.js +72 -0
- package/src/core/security/limits.d.ts +40 -0
- package/src/core/security/limits.js +26 -0
- package/src/core/xml/index.d.ts +7 -0
- package/src/core/xml/index.js +3 -0
- package/src/core/xml/model.d.ts +66 -0
- package/src/core/xml/model.js +17 -0
- package/src/core/xml/parse.d.ts +12 -0
- package/src/core/xml/parse.js +382 -0
- package/src/core/xml/serialize.d.ts +6 -0
- package/src/core/xml/serialize.js +93 -0
- package/src/core/zip/crc32.d.ts +2 -0
- package/src/core/zip/crc32.js +25 -0
- package/src/core/zip/deflate.d.ts +6 -0
- package/src/core/zip/deflate.js +6 -0
- package/src/core/zip/index.d.ts +10 -0
- package/src/core/zip/index.js +4 -0
- package/src/core/zip/inflate-raw.d.ts +17 -0
- package/src/core/zip/inflate-raw.js +450 -0
- package/src/core/zip/names.d.ts +6 -0
- package/src/core/zip/names.js +52 -0
- package/src/core/zip/read.d.ts +8 -0
- package/src/core/zip/read.js +262 -0
- package/src/core/zip/write.d.ts +7 -0
- package/src/core/zip/write.js +189 -0
- package/src/core/zip/zip-entry.d.ts +4 -0
- package/src/core/zip/zip-entry.js +0 -0
- package/src/features/bibliography/index.d.ts +100 -0
- package/src/features/bibliography/index.js +290 -0
- package/src/features/bookmarks/index.d.ts +331 -0
- package/src/features/bookmarks/index.js +1009 -0
- package/src/features/comments/comment-extensions.d.ts +157 -0
- package/src/features/comments/comment-extensions.js +356 -0
- package/src/features/comments/index.d.ts +579 -0
- package/src/features/comments/index.js +1727 -0
- package/src/features/content-controls/index.d.ts +821 -0
- package/src/features/content-controls/index.js +2857 -0
- package/src/features/custom-xml/index.d.ts +236 -0
- package/src/features/custom-xml/index.js +661 -0
- package/src/features/document/alignment.d.ts +23 -0
- package/src/features/document/alignment.js +36 -0
- package/src/features/document/alt-chunk.d.ts +103 -0
- package/src/features/document/alt-chunk.js +221 -0
- package/src/features/document/assert-never.d.ts +1 -0
- package/src/features/document/assert-never.js +4 -0
- package/src/features/document/augmentations.d.ts +578 -0
- package/src/features/document/augmentations.js +0 -0
- package/src/features/document/body-always-on.d.ts +36 -0
- package/src/features/document/body-always-on.js +66 -0
- package/src/features/document/body-blocks.d.ts +7 -0
- package/src/features/document/body-blocks.js +78 -0
- package/src/features/document/body-item-adapters.d.ts +62 -0
- package/src/features/document/body-item-adapters.js +97 -0
- package/src/features/document/body-item-collection.d.ts +151 -0
- package/src/features/document/body-item-collection.js +440 -0
- package/src/features/document/body-item.d.ts +35 -0
- package/src/features/document/body-item.js +8 -0
- package/src/features/document/body.d.ts +150 -0
- package/src/features/document/body.js +263 -0
- package/src/features/document/character-format.d.ts +413 -0
- package/src/features/document/character-format.js +2054 -0
- package/src/features/document/color.d.ts +178 -0
- package/src/features/document/color.js +495 -0
- package/src/features/document/document.d.ts +410 -0
- package/src/features/document/document.js +1049 -0
- package/src/features/document/element-type.d.ts +68 -0
- package/src/features/document/element-type.js +133 -0
- package/src/features/document/entity-type.d.ts +92 -0
- package/src/features/document/entity-type.js +93 -0
- package/src/features/document/feature-block.d.ts +16 -0
- package/src/features/document/feature-block.js +0 -0
- package/src/features/document/feature-inline.d.ts +13 -0
- package/src/features/document/feature-inline.js +0 -0
- package/src/features/document/feature-multi-package-part.d.ts +19 -0
- package/src/features/document/feature-multi-package-part.js +8 -0
- package/src/features/document/feature-package-level-part.d.ts +18 -0
- package/src/features/document/feature-package-level-part.js +8 -0
- package/src/features/document/feature-package-part.d.ts +14 -0
- package/src/features/document/feature-package-part.js +0 -0
- package/src/features/document/feature-run-leaf.d.ts +9 -0
- package/src/features/document/feature-run-leaf.js +0 -0
- package/src/features/document/headers-footers.d.ts +206 -0
- package/src/features/document/headers-footers.js +384 -0
- package/src/features/document/index.d.ts +41 -0
- package/src/features/document/index.js +34 -0
- package/src/features/document/length.d.ts +152 -0
- package/src/features/document/length.js +245 -0
- package/src/features/document/load-options.d.ts +14 -0
- package/src/features/document/load-options.js +0 -0
- package/src/features/document/locale-ids.d.ts +227 -0
- package/src/features/document/locale-ids.js +485 -0
- package/src/features/document/on-off.d.ts +9 -0
- package/src/features/document/on-off.js +27 -0
- package/src/features/document/page-setup.d.ts +339 -0
- package/src/features/document/page-setup.js +244 -0
- package/src/features/document/paragraph-format.d.ts +880 -0
- package/src/features/document/paragraph-format.js +2807 -0
- package/src/features/document/paragraph-item-collection.d.ts +162 -0
- package/src/features/document/paragraph-item-collection.js +363 -0
- package/src/features/document/paragraph-item.d.ts +83 -0
- package/src/features/document/paragraph-item.js +103 -0
- package/src/features/document/paragraph.d.ts +435 -0
- package/src/features/document/paragraph.js +888 -0
- package/src/features/document/run.d.ts +1 -0
- package/src/features/document/run.js +768 -0
- package/src/features/document/section-partition-flatten.d.ts +124 -0
- package/src/features/document/section-partition-flatten.js +217 -0
- package/src/features/document/section-properties-model.d.ts +13 -0
- package/src/features/document/section-properties-model.js +0 -0
- package/src/features/document/section.d.ts +93 -0
- package/src/features/document/section.js +178 -0
- package/src/features/document/sections.d.ts +103 -0
- package/src/features/document/sections.js +217 -0
- package/src/features/document/sub-super-script.d.ts +23 -0
- package/src/features/document/sub-super-script.js +43 -0
- package/src/features/document/text-range.d.ts +445 -0
- package/src/features/document/text-range.js +1156 -0
- package/src/features/document/typed-body-collections.d.ts +162 -0
- package/src/features/document/typed-body-collections.js +371 -0
- package/src/features/document/underline-style.d.ts +38 -0
- package/src/features/document/underline-style.js +126 -0
- package/src/features/document/units.d.ts +8 -0
- package/src/features/document/units.js +7 -0
- package/src/features/document/wml.d.ts +16 -0
- package/src/features/document/wml.js +67 -0
- package/src/features/drawing/authoring.d.ts +27 -0
- package/src/features/drawing/authoring.js +271 -0
- package/src/features/drawing/body-pr.d.ts +271 -0
- package/src/features/drawing/body-pr.js +663 -0
- package/src/features/drawing/drawing-shape.d.ts +1192 -0
- package/src/features/drawing/drawing-shape.js +3239 -0
- package/src/features/drawing/encode-builders.d.ts +176 -0
- package/src/features/drawing/encode-builders.js +390 -0
- package/src/features/drawing/fill-format.d.ts +52 -0
- package/src/features/drawing/fill-format.js +124 -0
- package/src/features/drawing/host-codec.d.ts +632 -0
- package/src/features/drawing/host-codec.js +2595 -0
- package/src/features/drawing/index.d.ts +13 -0
- package/src/features/drawing/index.js +33 -0
- package/src/features/drawing/line-format.d.ts +76 -0
- package/src/features/drawing/line-format.js +343 -0
- package/src/features/drawing/parse-register.d.ts +50 -0
- package/src/features/drawing/parse-register.js +257 -0
- package/src/features/drawing/residual-utils.d.ts +47 -0
- package/src/features/drawing/residual-utils.js +290 -0
- package/src/features/drawing/shape-types.d.ts +433 -0
- package/src/features/drawing/shape-types.js +437 -0
- package/src/features/drawing/sp-pr.d.ts +396 -0
- package/src/features/drawing/sp-pr.js +610 -0
- package/src/features/drawing/text-frame.d.ts +90 -0
- package/src/features/drawing/text-frame.js +152 -0
- package/src/features/drawing/types.d.ts +352 -0
- package/src/features/drawing/types.js +60 -0
- package/src/features/drawing/wrap-format.d.ts +62 -0
- package/src/features/drawing/wrap-format.js +114 -0
- package/src/features/editable-ranges/index.d.ts +494 -0
- package/src/features/editable-ranges/index.js +1348 -0
- package/src/features/fields/index.d.ts +428 -0
- package/src/features/fields/index.js +2148 -0
- package/src/features/fields/paragraph-field.d.ts +187 -0
- package/src/features/fields/paragraph-field.js +692 -0
- package/src/features/font-table/font-substitution-table.d.ts +75 -0
- package/src/features/font-table/font-substitution-table.js +257 -0
- package/src/features/font-table/font-table-entry.d.ts +255 -0
- package/src/features/font-table/font-table-entry.js +823 -0
- package/src/features/font-table/font-table.d.ts +128 -0
- package/src/features/font-table/font-table.js +313 -0
- package/src/features/font-table/index.d.ts +27 -0
- package/src/features/font-table/index.js +48 -0
- package/src/features/glossary/index.d.ts +97 -0
- package/src/features/glossary/index.js +286 -0
- package/src/features/headers-footers/index.d.ts +506 -0
- package/src/features/headers-footers/index.js +1666 -0
- package/src/features/hyperlinks/index.d.ts +230 -0
- package/src/features/hyperlinks/index.js +685 -0
- package/src/features/images/caption-authoring-api.d.ts +33 -0
- package/src/features/images/caption-authoring-api.js +33 -0
- package/src/features/images/caption-enums.d.ts +52 -0
- package/src/features/images/caption-enums.js +141 -0
- package/src/features/images/caption-host.d.ts +10 -0
- package/src/features/images/caption-host.js +21 -0
- package/src/features/images/captions.d.ts +13 -0
- package/src/features/images/captions.js +142 -0
- package/src/features/images/host-codec.d.ts +103 -0
- package/src/features/images/host-codec.js +720 -0
- package/src/features/images/image-sniff.d.ts +21 -0
- package/src/features/images/image-sniff.js +71 -0
- package/src/features/images/index.d.ts +506 -0
- package/src/features/images/index.js +1429 -0
- package/src/features/images/layout-types.d.ts +232 -0
- package/src/features/images/layout-types.js +294 -0
- package/src/features/images/public-entry.d.ts +9 -0
- package/src/features/images/public-entry.js +9 -0
- package/src/features/index.d.ts +35 -0
- package/src/features/index.js +36 -0
- package/src/features/mail-merge/index.d.ts +113 -0
- package/src/features/mail-merge/index.js +315 -0
- package/src/features/notes/index.d.ts +573 -0
- package/src/features/notes/index.js +1725 -0
- package/src/features/numbering/abstract-numbering.d.ts +90 -0
- package/src/features/numbering/abstract-numbering.js +292 -0
- package/src/features/numbering/index.d.ts +182 -0
- package/src/features/numbering/index.js +668 -0
- package/src/features/numbering/list-format.d.ts +158 -0
- package/src/features/numbering/list-format.js +590 -0
- package/src/features/numbering/list-string.d.ts +7 -0
- package/src/features/numbering/list-string.js +423 -0
- package/src/features/numbering/list-style.d.ts +204 -0
- package/src/features/numbering/list-style.js +1084 -0
- package/src/features/numbering/numbering-instance.d.ts +101 -0
- package/src/features/numbering/numbering-instance.js +329 -0
- package/src/features/numbering/numbering-level.d.ts +118 -0
- package/src/features/numbering/numbering-level.js +501 -0
- package/src/features/numbering/picture-bullet.d.ts +34 -0
- package/src/features/numbering/picture-bullet.js +88 -0
- package/src/features/ole-object/catalog.d.ts +300 -0
- package/src/features/ole-object/catalog.js +908 -0
- package/src/features/ole-object/index.d.ts +526 -0
- package/src/features/ole-object/index.js +1421 -0
- package/src/features/ole-object/relationship.d.ts +27 -0
- package/src/features/ole-object/relationship.js +27 -0
- package/src/features/ole-object/typed-dom.d.ts +186 -0
- package/src/features/ole-object/typed-dom.js +595 -0
- package/src/features/properties/index.d.ts +205 -0
- package/src/features/properties/index.js +549 -0
- package/src/features/revisions/index.d.ts +204 -0
- package/src/features/revisions/index.js +695 -0
- package/src/features/sections/column-collection.d.ts +119 -0
- package/src/features/sections/column-collection.js +478 -0
- package/src/features/sections/column.d.ts +15 -0
- package/src/features/sections/column.js +37 -0
- package/src/features/sections/index.d.ts +91 -0
- package/src/features/sections/index.js +1096 -0
- package/src/features/sections/margins.d.ts +40 -0
- package/src/features/sections/margins.js +105 -0
- package/src/features/sections/page-number-style.d.ts +21 -0
- package/src/features/sections/page-number-style.js +62 -0
- package/src/features/sections/page-orientation.d.ts +10 -0
- package/src/features/sections/page-orientation.js +10 -0
- package/src/features/sections/page-setup.d.ts +435 -0
- package/src/features/sections/page-setup.js +1479 -0
- package/src/features/sections/page-size.d.ts +59 -0
- package/src/features/sections/page-size.js +68 -0
- package/src/features/sections/section-break-code.d.ts +27 -0
- package/src/features/sections/section-break-code.js +60 -0
- package/src/features/sections/section-document-association.d.ts +18 -0
- package/src/features/sections/section-document-association.js +31 -0
- package/src/features/sections/section-validation.d.ts +43 -0
- package/src/features/sections/section-validation.js +97 -0
- package/src/features/settings/attached-template.d.ts +35 -0
- package/src/features/settings/attached-template.js +98 -0
- package/src/features/settings/compat-settings.d.ts +216 -0
- package/src/features/settings/compat-settings.js +508 -0
- package/src/features/settings/document-background.d.ts +59 -0
- package/src/features/settings/document-background.js +131 -0
- package/src/features/settings/document-protection.d.ts +65 -0
- package/src/features/settings/document-protection.js +157 -0
- package/src/features/settings/document-settings-facades.d.ts +108 -0
- package/src/features/settings/document-settings-facades.js +312 -0
- package/src/features/settings/document-settings-values.d.ts +43 -0
- package/src/features/settings/document-settings-values.js +60 -0
- package/src/features/settings/footnote-properties.d.ts +211 -0
- package/src/features/settings/footnote-properties.js +591 -0
- package/src/features/settings/index.d.ts +356 -0
- package/src/features/settings/index.js +829 -0
- package/src/features/settings/settings-children.d.ts +151 -0
- package/src/features/settings/settings-children.js +505 -0
- package/src/features/settings/web-settings.d.ts +88 -0
- package/src/features/settings/web-settings.js +227 -0
- package/src/features/settings/zoom.d.ts +79 -0
- package/src/features/settings/zoom.js +147 -0
- package/src/features/styles/builtin-catalog.d.ts +159 -0
- package/src/features/styles/builtin-catalog.js +963 -0
- package/src/features/styles/builtin-resolver.d.ts +49 -0
- package/src/features/styles/builtin-resolver.js +165 -0
- package/src/features/styles/default-styles.d.ts +37 -0
- package/src/features/styles/default-styles.js +186 -0
- package/src/features/styles/default-theme.d.ts +13 -0
- package/src/features/styles/default-theme.js +13 -0
- package/src/features/styles/doc-defaults.d.ts +58 -0
- package/src/features/styles/doc-defaults.js +178 -0
- package/src/features/styles/formatting-resolver.d.ts +27 -0
- package/src/features/styles/formatting-resolver.js +72 -0
- package/src/features/styles/index.d.ts +256 -0
- package/src/features/styles/index.js +1325 -0
- package/src/features/styles/latent-styles.d.ts +68 -0
- package/src/features/styles/latent-styles.js +305 -0
- package/src/features/styles/paragraph-properties.d.ts +71 -0
- package/src/features/styles/paragraph-properties.js +237 -0
- package/src/features/styles/run-properties.d.ts +93 -0
- package/src/features/styles/run-properties.js +516 -0
- package/src/features/styles/style-base.d.ts +402 -0
- package/src/features/styles/style-base.js +1026 -0
- package/src/features/styles/style-collection.d.ts +264 -0
- package/src/features/styles/style-collection.js +714 -0
- package/src/features/styles/style-format-bridge.d.ts +64 -0
- package/src/features/styles/style-format-bridge.js +100 -0
- package/src/features/styles/style.d.ts +84 -0
- package/src/features/styles/style.js +375 -0
- package/src/features/styles/styles-with-effects.d.ts +71 -0
- package/src/features/styles/styles-with-effects.js +180 -0
- package/src/features/styles/table-style.d.ts +272 -0
- package/src/features/styles/table-style.js +1226 -0
- package/src/features/styles/theme.d.ts +126 -0
- package/src/features/styles/theme.js +377 -0
- package/src/features/tables/border-style-map.d.ts +24 -0
- package/src/features/tables/border-style-map.js +81 -0
- package/src/features/tables/borders.d.ts +126 -0
- package/src/features/tables/borders.js +527 -0
- package/src/features/tables/collections.d.ts +113 -0
- package/src/features/tables/collections.js +261 -0
- package/src/features/tables/format.d.ts +208 -0
- package/src/features/tables/format.js +716 -0
- package/src/features/tables/index.d.ts +597 -0
- package/src/features/tables/index.js +2386 -0
- package/src/features/tables/paddings.d.ts +41 -0
- package/src/features/tables/paddings.js +97 -0
- package/src/features/tables/tbl-pr-positioning.d.ts +27 -0
- package/src/features/tables/tbl-pr-positioning.js +178 -0
- package/src/features/tables/tbl-pr.d.ts +528 -0
- package/src/features/tables/tbl-pr.js +1208 -0
- package/src/features/tables/tc-pr.d.ts +168 -0
- package/src/features/tables/tc-pr.js +553 -0
- package/src/features/tables/tr-pr.d.ts +60 -0
- package/src/features/tables/tr-pr.js +215 -0
- package/src/features/watermark/detect.d.ts +76 -0
- package/src/features/watermark/detect.js +219 -0
- package/src/features/watermark/index.d.ts +28 -0
- package/src/features/watermark/index.js +91 -0
- package/src/features/watermark/logical-store.d.ts +29 -0
- package/src/features/watermark/logical-store.js +31 -0
- package/src/features/watermark/model.d.ts +285 -0
- package/src/features/watermark/model.js +597 -0
- package/src/features/watermark/parse.d.ts +84 -0
- package/src/features/watermark/parse.js +815 -0
- package/src/features/watermark/serialize.d.ts +98 -0
- package/src/features/watermark/serialize.js +1517 -0
- package/src/global.js +1 -0
- package/src/index.d.ts +2 -0
- package/src/index.js +2 -0
|
@@ -0,0 +1,2595 @@
|
|
|
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
|
+
import { parseBodyBlocks, serializeBodyBlocks } from '../document/body-blocks';
|
|
43
|
+
import { emuToPoint } from '../document/length';
|
|
44
|
+
import { isWml, WML, wmlElement } from '../document/wml';
|
|
45
|
+
import { MARKUP_COMPATIBILITY_NAMESPACE } from '../../core/mc/index';
|
|
46
|
+
import { HorizontalAlignment, HorizontalOrigin, TextWrappingStyle, TextWrappingType, VerticalAlignment, VerticalOrigin, isHorizontalAlignmentWire, isVerticalAlignmentWire, isHorizontalOrigin, isVerticalOrigin, isTextWrappingTypeWire } from '../images/layout-types';
|
|
47
|
+
import { buildFillElement, buildLineElement, findSpPrElement } from './sp-pr';
|
|
48
|
+
/**
|
|
49
|
+
* @private
|
|
50
|
+
*/
|
|
51
|
+
export var WP_NS = 'http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing';
|
|
52
|
+
/**
|
|
53
|
+
* @private
|
|
54
|
+
*/
|
|
55
|
+
export var A_NS = 'http://schemas.openxmlformats.org/drawingml/2006/main';
|
|
56
|
+
/**
|
|
57
|
+
* @private
|
|
58
|
+
*/
|
|
59
|
+
export var R_NS = 'http://schemas.openxmlformats.org/officeDocument/2006/relationships';
|
|
60
|
+
/**
|
|
61
|
+
* @private
|
|
62
|
+
*/
|
|
63
|
+
export var WPS_NS = 'http://schemas.microsoft.com/office/word/2010/wordprocessingShape';
|
|
64
|
+
/**
|
|
65
|
+
* @private
|
|
66
|
+
*/
|
|
67
|
+
export var WPG_NS = 'http://schemas.microsoft.com/office/word/2010/wordprocessingGroup';
|
|
68
|
+
/**
|
|
69
|
+
* @private
|
|
70
|
+
*/
|
|
71
|
+
export var WPC_NS = 'http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas';
|
|
72
|
+
/**
|
|
73
|
+
* @private
|
|
74
|
+
*/
|
|
75
|
+
export var VML_NS = 'urn:schemas-microsoft-com:vml';
|
|
76
|
+
/**
|
|
77
|
+
* Word VML extensions namespace (`vml-wordprocessingDrawing.xsd` targetNamespace).
|
|
78
|
+
* Used for `w10:wrap` / `w10:anchorlock` on authored Fallback shapes.
|
|
79
|
+
*
|
|
80
|
+
* @private
|
|
81
|
+
*/
|
|
82
|
+
export var W10_NS = 'urn:schemas-microsoft-com:office:word';
|
|
83
|
+
/**
|
|
84
|
+
* @private
|
|
85
|
+
*/
|
|
86
|
+
export var MC_NS = MARKUP_COMPATIBILITY_NAMESPACE;
|
|
87
|
+
/** 914400 EMU = 1 inch; 12700 EMU = 1 pt. */
|
|
88
|
+
var EMU_PER_POINT = 12700;
|
|
89
|
+
/**
|
|
90
|
+
* ST_Angle: 60000ths of a degree (ECMA-376 DrawingML `dml-main` CT_Transform2D).
|
|
91
|
+
* Same unit as images host-codec; local copy avoids drawing→images encode coupling.
|
|
92
|
+
*
|
|
93
|
+
* @private
|
|
94
|
+
*/
|
|
95
|
+
export var ROTATION_UNITS_PER_DEGREE = 60000;
|
|
96
|
+
function elementChildren(el) {
|
|
97
|
+
return el.children.filter(function (c) { return c.kind === 'element'; });
|
|
98
|
+
}
|
|
99
|
+
function isElement(el, namespaceUri, localName) {
|
|
100
|
+
return el.namespaceUri === namespaceUri && el.localName === localName;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* @private
|
|
104
|
+
*/
|
|
105
|
+
export function findFirstElement(root, namespaceUri, localName) {
|
|
106
|
+
var e_1, _a;
|
|
107
|
+
if (isElement(root, namespaceUri, localName)) {
|
|
108
|
+
return root;
|
|
109
|
+
}
|
|
110
|
+
try {
|
|
111
|
+
for (var _b = __values(elementChildren(root)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
112
|
+
var child = _c.value;
|
|
113
|
+
var found = findFirstElement(child, namespaceUri, localName);
|
|
114
|
+
if (found !== undefined) {
|
|
115
|
+
return found;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
120
|
+
finally {
|
|
121
|
+
try {
|
|
122
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
123
|
+
}
|
|
124
|
+
finally { if (e_1) throw e_1.error; }
|
|
125
|
+
}
|
|
126
|
+
return undefined;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* @private
|
|
130
|
+
*/
|
|
131
|
+
export function attributeValue(el, namespaceUri, localName) {
|
|
132
|
+
var __ts33_0;
|
|
133
|
+
return ((__ts33_0 = el.attributes.find(function (a) { return a.namespaceUri === namespaceUri && a.localName === localName; })), __ts33_0 == null ? undefined : __ts33_0.value);
|
|
134
|
+
}
|
|
135
|
+
function xmlElement(namespaceUri, prefix, localName, options) {
|
|
136
|
+
var __ts33_1, __ts33_2, __ts33_3;
|
|
137
|
+
return {
|
|
138
|
+
kind: 'element',
|
|
139
|
+
namespaceUri: namespaceUri,
|
|
140
|
+
localName: localName,
|
|
141
|
+
prefix: prefix,
|
|
142
|
+
attributes: ((__ts33_1 = options == null ? undefined : options.attributes), __ts33_1 != null ? __ts33_1 : []),
|
|
143
|
+
namespaceDeclarations: ((__ts33_2 = options == null ? undefined : options.namespaceDeclarations), __ts33_2 != null ? __ts33_2 : []),
|
|
144
|
+
children: ((__ts33_3 = options == null ? undefined : options.children), __ts33_3 != null ? __ts33_3 : []),
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
function attr(localName, value, namespaceUri, prefix) {
|
|
148
|
+
if (namespaceUri === void 0) { namespaceUri = ''; }
|
|
149
|
+
if (prefix === void 0) { prefix = ''; }
|
|
150
|
+
return { namespaceUri: namespaceUri, localName: localName, prefix: prefix, value: value };
|
|
151
|
+
}
|
|
152
|
+
function cloneElement(el) {
|
|
153
|
+
return {
|
|
154
|
+
kind: 'element',
|
|
155
|
+
namespaceUri: el.namespaceUri,
|
|
156
|
+
localName: el.localName,
|
|
157
|
+
prefix: el.prefix,
|
|
158
|
+
attributes: el.attributes.map(function (a) { return (__assign({}, a)); }),
|
|
159
|
+
namespaceDeclarations: el.namespaceDeclarations.map(function (n) { return (__assign({}, n)); }),
|
|
160
|
+
children: el.children.map(function (c) {
|
|
161
|
+
if (c.kind === 'element') {
|
|
162
|
+
return cloneElement(c);
|
|
163
|
+
}
|
|
164
|
+
// OpenXmlChild is element | text only (src/core/xml/model.ts).
|
|
165
|
+
return { kind: 'text', value: c.value };
|
|
166
|
+
}),
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
function buildDocPr(input) {
|
|
170
|
+
var attributes = [
|
|
171
|
+
attr('id', String(input.docPrId)),
|
|
172
|
+
attr('name', input.name),
|
|
173
|
+
];
|
|
174
|
+
if (input.title !== undefined && input.title.length > 0) {
|
|
175
|
+
attributes.push(attr('title', input.title));
|
|
176
|
+
}
|
|
177
|
+
if (input.description !== undefined && input.description.length > 0) {
|
|
178
|
+
attributes.push(attr('descr', input.description));
|
|
179
|
+
}
|
|
180
|
+
return xmlElement(WP_NS, 'wp', 'docPr', { attributes: attributes });
|
|
181
|
+
}
|
|
182
|
+
function buildEffectExtent() {
|
|
183
|
+
return xmlElement(WP_NS, 'wp', 'effectExtent', {
|
|
184
|
+
attributes: [attr('l', '0'), attr('t', '0'), attr('r', '0'), attr('b', '0')],
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
function buildXfrmAttributes(input) {
|
|
188
|
+
var xfrmAttrs = [];
|
|
189
|
+
// Omit @rot when 0 — Word/images convention (ST_Angle default).
|
|
190
|
+
if (input.rotation !== 0) {
|
|
191
|
+
xfrmAttrs.push(attr('rot', String(Math.round(input.rotation * ROTATION_UNITS_PER_DEGREE))));
|
|
192
|
+
}
|
|
193
|
+
if (input.flipHorizontal) {
|
|
194
|
+
xfrmAttrs.push(attr('flipH', '1'));
|
|
195
|
+
}
|
|
196
|
+
if (input.flipVertical) {
|
|
197
|
+
xfrmAttrs.push(attr('flipV', '1'));
|
|
198
|
+
}
|
|
199
|
+
return xfrmAttrs;
|
|
200
|
+
}
|
|
201
|
+
function buildXfrm(input) {
|
|
202
|
+
var rotation = input.rotation != null ? input.rotation : 0;
|
|
203
|
+
var flipHorizontal = input.flipHorizontal != null ? input.flipHorizontal : false;
|
|
204
|
+
var flipVertical = input.flipVertical != null ? input.flipVertical : false;
|
|
205
|
+
var off = xmlElement(A_NS, 'a', 'off', {
|
|
206
|
+
attributes: [attr('x', '0'), attr('y', '0')],
|
|
207
|
+
});
|
|
208
|
+
var ext = xmlElement(A_NS, 'a', 'ext', {
|
|
209
|
+
attributes: [attr('cx', String(input.widthEmu)), attr('cy', String(input.heightEmu))],
|
|
210
|
+
});
|
|
211
|
+
return xmlElement(A_NS, 'a', 'xfrm', {
|
|
212
|
+
attributes: buildXfrmAttributes({ rotation: rotation, flipHorizontal: flipHorizontal, flipVertical: flipVertical }),
|
|
213
|
+
children: [off, ext],
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
function buildCNvGraphicFramePr(lockAspectRatio) {
|
|
217
|
+
var lockAttrs = lockAspectRatio ? [attr('noChangeAspect', '1')] : [];
|
|
218
|
+
return xmlElement(WP_NS, 'wp', 'cNvGraphicFramePr', {
|
|
219
|
+
children: [
|
|
220
|
+
xmlElement(A_NS, 'a', 'graphicFrameLocks', {
|
|
221
|
+
attributes: lockAttrs,
|
|
222
|
+
}),
|
|
223
|
+
],
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Build `wps:spPr` children in `CT_ShapeProperties` schema order:
|
|
228
|
+
* `a:xfrm`, `EG_Geometry` (prstGeom + avLst), `EG_FillProperties` (residual
|
|
229
|
+
* preserved when unmodeled), `a:ln` (residual preserved when unmodeled), then
|
|
230
|
+
* residual bag (effects/scene3d/… — GO Q9 residual).
|
|
231
|
+
*/
|
|
232
|
+
function buildSpPrChildren(input, preservedSpPr) {
|
|
233
|
+
var e_2, _a, e_3, _b;
|
|
234
|
+
var children = [];
|
|
235
|
+
children.push(buildXfrm(input));
|
|
236
|
+
children.push(xmlElement(A_NS, 'a', 'prstGeom', {
|
|
237
|
+
attributes: [attr('prst', input.presetGeometry)],
|
|
238
|
+
children: [xmlElement(A_NS, 'a', 'avLst')],
|
|
239
|
+
}));
|
|
240
|
+
// Fill: modeled MVP wins; otherwise preserve the residual fill element.
|
|
241
|
+
if (input.fill !== undefined) {
|
|
242
|
+
children.push(buildFillElement(input.fill));
|
|
243
|
+
}
|
|
244
|
+
else
|
|
245
|
+
try {
|
|
246
|
+
for (var _c = __values(['noFill', 'solidFill', 'gradFill', 'blipFill', 'pattFill', 'grpFill']), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
247
|
+
var localName = _d.value;
|
|
248
|
+
var residualFill = preservedSpPr !== undefined ? findSpPrElement(preservedSpPr, A_NS, localName) : undefined;
|
|
249
|
+
if (residualFill !== undefined) {
|
|
250
|
+
children.push(residualFill);
|
|
251
|
+
break;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
256
|
+
finally {
|
|
257
|
+
try {
|
|
258
|
+
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
|
|
259
|
+
}
|
|
260
|
+
finally { if (e_2) throw e_2.error; }
|
|
261
|
+
}
|
|
262
|
+
// Line: modeled MVP wins; otherwise preserve the residual a:ln element.
|
|
263
|
+
if (input.line !== undefined) {
|
|
264
|
+
children.push(buildLineElement(input.line));
|
|
265
|
+
}
|
|
266
|
+
else if (preservedSpPr !== undefined) {
|
|
267
|
+
var residualLn = findSpPrElement(preservedSpPr, A_NS, 'ln');
|
|
268
|
+
if (residualLn !== undefined) {
|
|
269
|
+
children.push(residualLn);
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
// Residual bag: everything after geometry known to CT_ShapeProperties that
|
|
273
|
+
// the MVP does not model (effects, scene3d, sp3d, extLst) — GO Q9 deferred.
|
|
274
|
+
var residualTail = [];
|
|
275
|
+
if (preservedSpPr !== undefined) {
|
|
276
|
+
var modeledFillNames = new Set([
|
|
277
|
+
'noFill',
|
|
278
|
+
'solidFill',
|
|
279
|
+
'gradFill',
|
|
280
|
+
'blipFill',
|
|
281
|
+
'pattFill',
|
|
282
|
+
'grpFill',
|
|
283
|
+
]);
|
|
284
|
+
try {
|
|
285
|
+
for (var _e = __values(elementChildrenOf(preservedSpPr)), _f = _e.next(); !_f.done; _f = _e.next()) {
|
|
286
|
+
var child = _f.value;
|
|
287
|
+
if (isElement(child, A_NS, 'xfrm') ||
|
|
288
|
+
isElement(child, A_NS, 'prstGeom') ||
|
|
289
|
+
isElement(child, A_NS, 'custGeom') ||
|
|
290
|
+
(isElement(child, A_NS, 'ln') ||
|
|
291
|
+
(child.namespaceUri === A_NS && modeledFillNames.has(child.localName)))) {
|
|
292
|
+
continue;
|
|
293
|
+
}
|
|
294
|
+
residualTail.push(child);
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
298
|
+
finally {
|
|
299
|
+
try {
|
|
300
|
+
if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
|
|
301
|
+
}
|
|
302
|
+
finally { if (e_3) throw e_3.error; }
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
children.push.apply(children, __spread(residualTail));
|
|
306
|
+
return children;
|
|
307
|
+
}
|
|
308
|
+
function elementChildrenOf(el) {
|
|
309
|
+
return el.children.filter(function (c) { return c.kind === 'element'; });
|
|
310
|
+
}
|
|
311
|
+
function buildWpsShape(input) {
|
|
312
|
+
var __ts33_4;
|
|
313
|
+
var preservedSpPr = findResidualSpPr(input.preservedHost);
|
|
314
|
+
var spPr = xmlElement(WPS_NS, 'wps', 'spPr', {
|
|
315
|
+
children: buildSpPrChildren(input, preservedSpPr),
|
|
316
|
+
});
|
|
317
|
+
// Text box marker (`CT_NonVisualDrawingShapeProps/@txBox`, default false) —
|
|
318
|
+
// Word sets it on text box shapes; detection itself keys off the
|
|
319
|
+
// `wps:txbx` child per [MS-ODRAWXML] §2.13.3.2.
|
|
320
|
+
var hasTxbx = input.txbxContent !== undefined || residualHasTxbx(input.preservedHost);
|
|
321
|
+
var cNvSpPr = xmlElement(WPS_NS, 'wps', 'cNvSpPr', {
|
|
322
|
+
attributes: hasTxbx ? [attr('txBox', '1')] : [],
|
|
323
|
+
});
|
|
324
|
+
// CT_WordprocessingShape order (wordprocessingShape.xsd): cNvSpPr?, spPr,
|
|
325
|
+
// style?, extLst?, (txbx|linkedTxbx)?, bodyPr (minOccurs 1). Preserve
|
|
326
|
+
// residual `wps:style` on structure rebuild so solid fill dirty does not
|
|
327
|
+
// drop theme refs (GO).
|
|
328
|
+
var residualStyle = input.preservedHost !== undefined
|
|
329
|
+
? findFirstElement(input.preservedHost, WPS_NS, 'style')
|
|
330
|
+
: undefined;
|
|
331
|
+
var children = [cNvSpPr, spPr];
|
|
332
|
+
if (residualStyle !== undefined) {
|
|
333
|
+
children.push(cloneElement(residualStyle));
|
|
334
|
+
}
|
|
335
|
+
// Text box (TASK-8049): modeled txbxContent when provided; residual txbx
|
|
336
|
+
// cloned verbatim when the rebuild did not model the body (structure dirt
|
|
337
|
+
// from layout/wrap mutators must not drop textbox content). linkedTxbx is
|
|
338
|
+
// OOS (GO) — residual clone preserves it; author path never emits it.
|
|
339
|
+
var residualTxbx = input.preservedHost !== undefined
|
|
340
|
+
? findFirstElement(input.preservedHost, WPS_NS, 'txbx')
|
|
341
|
+
: undefined;
|
|
342
|
+
var residualLinkedTxbx = input.preservedHost !== undefined
|
|
343
|
+
? findFirstElement(input.preservedHost, WPS_NS, 'linkedTxbx')
|
|
344
|
+
: undefined;
|
|
345
|
+
if (input.txbxContent !== undefined) {
|
|
346
|
+
children.push(buildTxbxElement(input.txbxContent));
|
|
347
|
+
}
|
|
348
|
+
else if (residualTxbx !== undefined) {
|
|
349
|
+
children.push(cloneElement(residualTxbx));
|
|
350
|
+
}
|
|
351
|
+
else if (residualLinkedTxbx !== undefined) {
|
|
352
|
+
children.push(cloneElement(residualLinkedTxbx));
|
|
353
|
+
}
|
|
354
|
+
// bodyPr is schema-required (minOccurs 1). Modeled state wins; residual
|
|
355
|
+
// bodyPr is cloned when present; otherwise an empty element is authored
|
|
356
|
+
// (Word convention for a defaulted text body).
|
|
357
|
+
var residualBodyPr = input.preservedHost !== undefined
|
|
358
|
+
? findFirstElement(input.preservedHost, WPS_NS, 'bodyPr')
|
|
359
|
+
: undefined;
|
|
360
|
+
children.push(((__ts33_4 = input.bodyPr != null ? input.bodyPr : residualBodyPr), __ts33_4 != null ? __ts33_4 : buildEmptyBodyPr()));
|
|
361
|
+
return xmlElement(WPS_NS, 'wps', 'wsp', {
|
|
362
|
+
namespaceDeclarations: [{ prefix: 'wps', namespaceUri: WPS_NS }],
|
|
363
|
+
children: children,
|
|
364
|
+
});
|
|
365
|
+
}
|
|
366
|
+
/** Empty `wps:bodyPr` (schema-required element with all-optional content). */
|
|
367
|
+
function buildEmptyBodyPr() {
|
|
368
|
+
return xmlElement(WPS_NS, 'wps', 'bodyPr');
|
|
369
|
+
}
|
|
370
|
+
/**
|
|
371
|
+
* Locate the residual `wps:spPr` for fill/line preservation on rebuild.
|
|
372
|
+
* Residual hosts nest `wps:spPr` under dual MC / `w:drawing` / `wp:*` /
|
|
373
|
+
* `a:graphic` / `wps:wsp`, so lookup is deep.
|
|
374
|
+
*
|
|
375
|
+
* @private
|
|
376
|
+
*/
|
|
377
|
+
export function findResidualSpPr(preservedHost) {
|
|
378
|
+
if (preservedHost === undefined) {
|
|
379
|
+
return undefined;
|
|
380
|
+
}
|
|
381
|
+
return findFirstElement(preservedHost, WPS_NS, 'spPr');
|
|
382
|
+
}
|
|
383
|
+
/**
|
|
384
|
+
* Build `wps:txbx` (`CT_TextboxInfo`) from serialized `w:txbxContent` children.
|
|
385
|
+
*
|
|
386
|
+
* Schema: `CT_TextboxInfo` = sequence `txbxContent` (minOccurs 1) + optional
|
|
387
|
+
* `extLst`; optional `@id` (default 0). `w:txbxContent` is
|
|
388
|
+
* `EG_BlockLevelElts` minOccurs 1 — the body must not be empty (Word authors
|
|
389
|
+
* at least one `w:p`; go6 author minimum matches).
|
|
390
|
+
*
|
|
391
|
+
* Cites:
|
|
392
|
+
* `specs/schemas/xsd/OfficeOpenXML-XMLSchema-Transitional/dml-wordprocessingDrawing.xsd`
|
|
393
|
+
* `CT_TxbxContent` / `CT_TextboxInfo`.
|
|
394
|
+
*
|
|
395
|
+
* @private
|
|
396
|
+
*/
|
|
397
|
+
export function buildTxbxElement(contentChildren) {
|
|
398
|
+
return xmlElement(WPS_NS, 'wps', 'txbx', {
|
|
399
|
+
children: [
|
|
400
|
+
xmlElement(WML, 'w', 'txbxContent', {
|
|
401
|
+
namespaceDeclarations: [{ prefix: 'w', namespaceUri: WML }],
|
|
402
|
+
children: contentChildren,
|
|
403
|
+
}),
|
|
404
|
+
],
|
|
405
|
+
});
|
|
406
|
+
}
|
|
407
|
+
/**
|
|
408
|
+
* Serialize modeled `w:txbxContent` block state into `txbxContent` element
|
|
409
|
+
* children. Modeled paragraphs/tables/SDTs emit their DOM form; residual
|
|
410
|
+
* blocks (opaque XML not owned by a registered feature) pass through verbatim
|
|
411
|
+
* — the library never invents block OOXML it does not model.
|
|
412
|
+
*
|
|
413
|
+
* @private
|
|
414
|
+
*/
|
|
415
|
+
export function serializeTxbxContentBlocks(blocks) {
|
|
416
|
+
return serializeBodyBlocks(blocks);
|
|
417
|
+
}
|
|
418
|
+
/**
|
|
419
|
+
* Parse `w:txbxContent` children into core block state.
|
|
420
|
+
*
|
|
421
|
+
* Uses the same `parseBodyBlocks` path as headers/footers and table cells:
|
|
422
|
+
* `w:p` → modeled `Paragraph`; `w:tbl` → modeled `Table` **only when the
|
|
423
|
+
* tables feature is registered**; `w:sdt` → modeled SDT **only when the
|
|
424
|
+
* content-controls feature is registered**; everything else (and any block
|
|
425
|
+
* whose feature is unregistered) stays residual-opaque — never dropped, never
|
|
426
|
+
* invented (GO Q6; offline policy).
|
|
427
|
+
*
|
|
428
|
+
* @private
|
|
429
|
+
*/
|
|
430
|
+
export function parseTxbxContentBlocks(txbxContent, ctx) {
|
|
431
|
+
return parseBodyBlocks(txbxContent.children, ctx);
|
|
432
|
+
}
|
|
433
|
+
/**
|
|
434
|
+
* Whether any `wps:wsp` under the host carries a `wps:txbx` (or `linkedTxbx`)
|
|
435
|
+
* child — deep walk so dual MC Choice branches resolve.
|
|
436
|
+
*
|
|
437
|
+
* @private
|
|
438
|
+
*/
|
|
439
|
+
export function residualHasTxbx(host) {
|
|
440
|
+
var e_4, _a;
|
|
441
|
+
if (host === undefined) {
|
|
442
|
+
return false;
|
|
443
|
+
}
|
|
444
|
+
var wsp = findFirstElement(host, WPS_NS, 'wsp');
|
|
445
|
+
if (wsp === undefined) {
|
|
446
|
+
return false;
|
|
447
|
+
}
|
|
448
|
+
try {
|
|
449
|
+
for (var _b = __values(elementChildren(wsp)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
450
|
+
var child = _c.value;
|
|
451
|
+
if (isElement(child, WPS_NS, 'txbx') ||
|
|
452
|
+
isElement(child, WPS_NS, 'linkedTxbx')) {
|
|
453
|
+
return true;
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
458
|
+
finally {
|
|
459
|
+
try {
|
|
460
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
461
|
+
}
|
|
462
|
+
finally { if (e_4) throw e_4.error; }
|
|
463
|
+
}
|
|
464
|
+
return false;
|
|
465
|
+
}
|
|
466
|
+
/**
|
|
467
|
+
* Build top-level `wpg:wgp` group shape for graphicData (TASK-8051).
|
|
468
|
+
*
|
|
469
|
+
* Top-level wgp has no `cNvPr` (identity lives on `wp:docPr`). Nested groups
|
|
470
|
+
* use `wpg:grpSp` with `cNvPr` — authored via residual clone or nested
|
|
471
|
+
* structure paths, not this builder.
|
|
472
|
+
*
|
|
473
|
+
* Cites: [MS-ODRAWXML] §2.16.3.2 CT_WordprocessingGroup —
|
|
474
|
+
* `cNvGrpSpPr?`, `grpSpPr`, then `(wsp|grpSp|graphicFrame|contentPart|spTree)*`.
|
|
475
|
+
*
|
|
476
|
+
* @private
|
|
477
|
+
*/
|
|
478
|
+
export function buildWpgGroup(input) {
|
|
479
|
+
var children = input.groupChildElements != null ? input.groupChildElements : [];
|
|
480
|
+
var cNvGrpSpPr = xmlElement(WPG_NS, 'wpg', 'cNvGrpSpPr');
|
|
481
|
+
var xfrmChildren = [
|
|
482
|
+
xmlElement(A_NS, 'a', 'off', {
|
|
483
|
+
attributes: [attr('x', '0'), attr('y', '0')],
|
|
484
|
+
}),
|
|
485
|
+
xmlElement(A_NS, 'a', 'ext', {
|
|
486
|
+
attributes: [attr('cx', String(input.widthEmu)), attr('cy', String(input.heightEmu))],
|
|
487
|
+
}),
|
|
488
|
+
xmlElement(A_NS, 'a', 'chOff', {
|
|
489
|
+
attributes: [attr('x', '0'), attr('y', '0')],
|
|
490
|
+
}),
|
|
491
|
+
xmlElement(A_NS, 'a', 'chExt', {
|
|
492
|
+
attributes: [attr('cx', String(input.widthEmu)), attr('cy', String(input.heightEmu))],
|
|
493
|
+
}),
|
|
494
|
+
];
|
|
495
|
+
var xfrmAttrs = [];
|
|
496
|
+
if (input.rotation !== undefined && input.rotation !== 0) {
|
|
497
|
+
// ST_Angle is 60000ths of a degree.
|
|
498
|
+
xfrmAttrs.push(attr('rot', String(Math.round(input.rotation * 60000))));
|
|
499
|
+
}
|
|
500
|
+
if (input.flipHorizontal === true) {
|
|
501
|
+
xfrmAttrs.push(attr('flipH', '1'));
|
|
502
|
+
}
|
|
503
|
+
if (input.flipVertical === true) {
|
|
504
|
+
xfrmAttrs.push(attr('flipV', '1'));
|
|
505
|
+
}
|
|
506
|
+
var xfrm = xmlElement(A_NS, 'a', 'xfrm', {
|
|
507
|
+
attributes: xfrmAttrs,
|
|
508
|
+
children: xfrmChildren,
|
|
509
|
+
});
|
|
510
|
+
var grpSpPr = xmlElement(WPG_NS, 'wpg', 'grpSpPr', {
|
|
511
|
+
children: [xfrm],
|
|
512
|
+
});
|
|
513
|
+
return xmlElement(WPG_NS, 'wpg', 'wgp', {
|
|
514
|
+
namespaceDeclarations: [{ prefix: 'wpg', namespaceUri: WPG_NS }],
|
|
515
|
+
children: __spread([cNvGrpSpPr, grpSpPr], children),
|
|
516
|
+
});
|
|
517
|
+
}
|
|
518
|
+
/**
|
|
519
|
+
* Build a nested bare `wps:wsp` for group/canvas children (TASK-8051).
|
|
520
|
+
* Carries `wps:cNvPr` identity after `wps:cNvSpPr` (fixture / Word order used
|
|
521
|
+
* by TASK-8051 tests). No dual AC wrapper — nested children are bare wsp.
|
|
522
|
+
*
|
|
523
|
+
* @private
|
|
524
|
+
*/
|
|
525
|
+
export function buildNestedWpsShape(input) {
|
|
526
|
+
var __ts33_5;
|
|
527
|
+
var preservedSpPr = findResidualSpPr(input.preservedHost);
|
|
528
|
+
var spPr = xmlElement(WPS_NS, 'wps', 'spPr', {
|
|
529
|
+
children: buildSpPrChildren(input, preservedSpPr),
|
|
530
|
+
});
|
|
531
|
+
var hasTxbx = input.txbxContent !== undefined || residualHasTxbx(input.preservedHost);
|
|
532
|
+
var cNvSpPr = xmlElement(WPS_NS, 'wps', 'cNvSpPr', {
|
|
533
|
+
attributes: hasTxbx ? [attr('txBox', '1')] : [],
|
|
534
|
+
});
|
|
535
|
+
// Nested identity: wps:cNvPr (id/name/title/descr). Fixture order is
|
|
536
|
+
// cNvSpPr then cNvPr (tests assert ChildA / NestedRect via these attrs).
|
|
537
|
+
var cNvPrAttrs = [
|
|
538
|
+
attr('id', String(input.docPrId)),
|
|
539
|
+
attr('name', input.name),
|
|
540
|
+
];
|
|
541
|
+
if (input.title !== undefined && input.title.length > 0) {
|
|
542
|
+
cNvPrAttrs.push(attr('title', input.title));
|
|
543
|
+
}
|
|
544
|
+
if (input.description !== undefined && input.description.length > 0) {
|
|
545
|
+
cNvPrAttrs.push(attr('descr', input.description));
|
|
546
|
+
}
|
|
547
|
+
var cNvPr = xmlElement(WPS_NS, 'wps', 'cNvPr', {
|
|
548
|
+
attributes: cNvPrAttrs,
|
|
549
|
+
});
|
|
550
|
+
var residualStyle = input.preservedHost !== undefined
|
|
551
|
+
? findFirstElement(input.preservedHost, WPS_NS, 'style')
|
|
552
|
+
: undefined;
|
|
553
|
+
// Match fixture child order: cNvSpPr, cNvPr, spPr, style?, txbx?, bodyPr.
|
|
554
|
+
var children = [cNvSpPr, cNvPr, spPr];
|
|
555
|
+
if (residualStyle !== undefined) {
|
|
556
|
+
children.push(cloneElement(residualStyle));
|
|
557
|
+
}
|
|
558
|
+
var residualTxbx = input.preservedHost !== undefined
|
|
559
|
+
? findFirstElement(input.preservedHost, WPS_NS, 'txbx')
|
|
560
|
+
: undefined;
|
|
561
|
+
var residualLinkedTxbx = input.preservedHost !== undefined
|
|
562
|
+
? findFirstElement(input.preservedHost, WPS_NS, 'linkedTxbx')
|
|
563
|
+
: undefined;
|
|
564
|
+
if (input.txbxContent !== undefined) {
|
|
565
|
+
children.push(buildTxbxElement(input.txbxContent));
|
|
566
|
+
}
|
|
567
|
+
else if (residualTxbx !== undefined) {
|
|
568
|
+
children.push(cloneElement(residualTxbx));
|
|
569
|
+
}
|
|
570
|
+
else if (residualLinkedTxbx !== undefined) {
|
|
571
|
+
children.push(cloneElement(residualLinkedTxbx));
|
|
572
|
+
}
|
|
573
|
+
var residualBodyPr = input.preservedHost !== undefined
|
|
574
|
+
? findFirstElement(input.preservedHost, WPS_NS, 'bodyPr')
|
|
575
|
+
: undefined;
|
|
576
|
+
children.push(((__ts33_5 = input.bodyPr != null ? input.bodyPr : residualBodyPr), __ts33_5 != null ? __ts33_5 : buildEmptyBodyPr()));
|
|
577
|
+
return xmlElement(WPS_NS, 'wps', 'wsp', {
|
|
578
|
+
namespaceDeclarations: [{ prefix: 'wps', namespaceUri: WPS_NS }],
|
|
579
|
+
children: children,
|
|
580
|
+
});
|
|
581
|
+
}
|
|
582
|
+
function buildGraphic(input) {
|
|
583
|
+
if (input.groupChildElements !== undefined) {
|
|
584
|
+
var graphicData_1 = xmlElement(A_NS, 'a', 'graphicData', {
|
|
585
|
+
attributes: [attr('uri', WPG_NS)],
|
|
586
|
+
children: [buildWpgGroup(input)],
|
|
587
|
+
});
|
|
588
|
+
return xmlElement(A_NS, 'a', 'graphic', {
|
|
589
|
+
namespaceDeclarations: [{ prefix: 'a', namespaceUri: A_NS }],
|
|
590
|
+
children: [graphicData_1],
|
|
591
|
+
});
|
|
592
|
+
}
|
|
593
|
+
var graphicData = xmlElement(A_NS, 'a', 'graphicData', {
|
|
594
|
+
attributes: [attr('uri', WPS_NS)],
|
|
595
|
+
children: [buildWpsShape(input)],
|
|
596
|
+
});
|
|
597
|
+
return xmlElement(A_NS, 'a', 'graphic', {
|
|
598
|
+
namespaceDeclarations: [{ prefix: 'a', namespaceUri: A_NS }],
|
|
599
|
+
children: [graphicData],
|
|
600
|
+
});
|
|
601
|
+
}
|
|
602
|
+
/**
|
|
603
|
+
* Parse wrapping from residual host placement.
|
|
604
|
+
*
|
|
605
|
+
* @private
|
|
606
|
+
*/
|
|
607
|
+
export function parseDrawingWrapping(host, placement) {
|
|
608
|
+
if (placement === 'inline') {
|
|
609
|
+
return TextWrappingStyle.Inline;
|
|
610
|
+
}
|
|
611
|
+
if (findFirstElement(host, WP_NS, 'wrapNone') !== undefined) {
|
|
612
|
+
return TextWrappingStyle.None;
|
|
613
|
+
}
|
|
614
|
+
if (findFirstElement(host, WP_NS, 'wrapSquare') !== undefined) {
|
|
615
|
+
return TextWrappingStyle.Square;
|
|
616
|
+
}
|
|
617
|
+
if (findFirstElement(host, WP_NS, 'wrapTight') !== undefined) {
|
|
618
|
+
return TextWrappingStyle.Tight;
|
|
619
|
+
}
|
|
620
|
+
if (findFirstElement(host, WP_NS, 'wrapThrough') !== undefined) {
|
|
621
|
+
return TextWrappingStyle.Through;
|
|
622
|
+
}
|
|
623
|
+
if (findFirstElement(host, WP_NS, 'wrapTopAndBottom') !== undefined) {
|
|
624
|
+
return TextWrappingStyle.TopAndBottom;
|
|
625
|
+
}
|
|
626
|
+
return TextWrappingStyle.None;
|
|
627
|
+
}
|
|
628
|
+
/**
|
|
629
|
+
* Parse `wp:wrapSquare|wrapTight|wrapThrough/@wrapText`.
|
|
630
|
+
* Absent → Both (schema default); wire token → token; other → Unknown.
|
|
631
|
+
*
|
|
632
|
+
* @private
|
|
633
|
+
*/
|
|
634
|
+
export function parseWrapTextAttr(wrapEl) {
|
|
635
|
+
if (wrapEl === undefined) {
|
|
636
|
+
return TextWrappingType.Both;
|
|
637
|
+
}
|
|
638
|
+
var raw = attributeValue(wrapEl, '', 'wrapText');
|
|
639
|
+
if (raw === undefined || raw.trim() === '') {
|
|
640
|
+
return TextWrappingType.Both;
|
|
641
|
+
}
|
|
642
|
+
var token = raw.trim();
|
|
643
|
+
if (isTextWrappingTypeWire(token)) {
|
|
644
|
+
return token;
|
|
645
|
+
}
|
|
646
|
+
return TextWrappingType.Unknown;
|
|
647
|
+
}
|
|
648
|
+
/**
|
|
649
|
+
* Whether residual wrap element already carries the modeled wire wrapText (or
|
|
650
|
+
* wrapText is not applicable / unmodeled / Unknown — keep residual as-is).
|
|
651
|
+
*/
|
|
652
|
+
function residualWrapTextMatches(residualWrap, wrapType) {
|
|
653
|
+
if (wrapType === undefined || wrapType === TextWrappingType.Unknown) {
|
|
654
|
+
return true;
|
|
655
|
+
}
|
|
656
|
+
if (!isTextWrappingTypeWire(wrapType)) {
|
|
657
|
+
return true;
|
|
658
|
+
}
|
|
659
|
+
// Styles without @wrapText never carry side type on wire.
|
|
660
|
+
if (residualWrap.localName === 'wrapNone' || residualWrap.localName === 'wrapTopAndBottom') {
|
|
661
|
+
return true;
|
|
662
|
+
}
|
|
663
|
+
var residualType = parseWrapTextAttr(residualWrap);
|
|
664
|
+
return residualType === wrapType;
|
|
665
|
+
}
|
|
666
|
+
/**
|
|
667
|
+
* Rebuild a residual wrap element with a corrected `@wrapText`, preserving
|
|
668
|
+
* children (e.g. wrapPolygon) and non-wrapText attributes.
|
|
669
|
+
*/
|
|
670
|
+
function rebuildWrapWithWrapText(residualWrap, wrapType) {
|
|
671
|
+
var e_5, _a;
|
|
672
|
+
var attributes = [];
|
|
673
|
+
var sawWrapText = false;
|
|
674
|
+
try {
|
|
675
|
+
for (var _b = __values(residualWrap.attributes), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
676
|
+
var a = _c.value;
|
|
677
|
+
if (a.namespaceUri === '' && a.localName === 'wrapText') {
|
|
678
|
+
attributes.push(attr('wrapText', wrapType));
|
|
679
|
+
sawWrapText = true;
|
|
680
|
+
}
|
|
681
|
+
else {
|
|
682
|
+
attributes.push(__assign({}, a));
|
|
683
|
+
}
|
|
684
|
+
}
|
|
685
|
+
}
|
|
686
|
+
catch (e_5_1) { e_5 = { error: e_5_1 }; }
|
|
687
|
+
finally {
|
|
688
|
+
try {
|
|
689
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
690
|
+
}
|
|
691
|
+
finally { if (e_5) throw e_5.error; }
|
|
692
|
+
}
|
|
693
|
+
if (!sawWrapText) {
|
|
694
|
+
attributes.push(attr('wrapText', wrapType));
|
|
695
|
+
}
|
|
696
|
+
return {
|
|
697
|
+
kind: 'element',
|
|
698
|
+
namespaceUri: residualWrap.namespaceUri,
|
|
699
|
+
localName: residualWrap.localName,
|
|
700
|
+
prefix: residualWrap.prefix,
|
|
701
|
+
attributes: attributes,
|
|
702
|
+
namespaceDeclarations: residualWrap.namespaceDeclarations.map(function (n) { return (__assign({}, n)); }),
|
|
703
|
+
children: residualWrap.children.slice(),
|
|
704
|
+
};
|
|
705
|
+
}
|
|
706
|
+
/**
|
|
707
|
+
* Build wrap element from modeled style.
|
|
708
|
+
* Tight/through require wrapPolygon; without residual polygon, fall back to wrapNone
|
|
709
|
+
* (library does not invent polygons — images parity).
|
|
710
|
+
* When residual matches style but modeled wire wrapType differs, rebuild with
|
|
711
|
+
* corrected wrapText and preserve residual children/attrs.
|
|
712
|
+
*
|
|
713
|
+
* @private
|
|
714
|
+
*/
|
|
715
|
+
export function buildWrapElement(wrapping, residualWrap, wrapType) {
|
|
716
|
+
var residualMatchesStyle = residualWrap !== undefined &&
|
|
717
|
+
((wrapping === TextWrappingStyle.Tight && residualWrap.localName === 'wrapTight') ||
|
|
718
|
+
(wrapping === TextWrappingStyle.Through && residualWrap.localName === 'wrapThrough') ||
|
|
719
|
+
(wrapping === TextWrappingStyle.Square && residualWrap.localName === 'wrapSquare') ||
|
|
720
|
+
(wrapping === TextWrappingStyle.None && residualWrap.localName === 'wrapNone') ||
|
|
721
|
+
(wrapping === TextWrappingStyle.TopAndBottom &&
|
|
722
|
+
residualWrap.localName === 'wrapTopAndBottom'));
|
|
723
|
+
if (residualMatchesStyle && residualWrap !== undefined) {
|
|
724
|
+
if (residualWrapTextMatches(residualWrap, wrapType)) {
|
|
725
|
+
return residualWrap;
|
|
726
|
+
}
|
|
727
|
+
// Modeled schema wrapType differs from residual @wrapText — rebuild.
|
|
728
|
+
if (wrapType !== undefined && isTextWrappingTypeWire(wrapType) &&
|
|
729
|
+
(wrapping === TextWrappingStyle.Square ||
|
|
730
|
+
wrapping === TextWrappingStyle.Tight ||
|
|
731
|
+
wrapping === TextWrappingStyle.Through)) {
|
|
732
|
+
return rebuildWrapWithWrapText(residualWrap, wrapType);
|
|
733
|
+
}
|
|
734
|
+
return residualWrap;
|
|
735
|
+
}
|
|
736
|
+
var wireWrapText = wrapType !== undefined && isTextWrappingTypeWire(wrapType)
|
|
737
|
+
? wrapType
|
|
738
|
+
: TextWrappingType.Both;
|
|
739
|
+
switch (wrapping) {
|
|
740
|
+
case TextWrappingStyle.None:
|
|
741
|
+
return xmlElement(WP_NS, 'wp', 'wrapNone');
|
|
742
|
+
case TextWrappingStyle.Square:
|
|
743
|
+
return xmlElement(WP_NS, 'wp', 'wrapSquare', {
|
|
744
|
+
attributes: [attr('wrapText', wireWrapText)],
|
|
745
|
+
});
|
|
746
|
+
case TextWrappingStyle.TopAndBottom:
|
|
747
|
+
return xmlElement(WP_NS, 'wp', 'wrapTopAndBottom');
|
|
748
|
+
case TextWrappingStyle.Tight:
|
|
749
|
+
case TextWrappingStyle.Through:
|
|
750
|
+
// CT_WrapPath requires wrapPolygon; library does not invent vertices.
|
|
751
|
+
return xmlElement(WP_NS, 'wp', 'wrapNone');
|
|
752
|
+
case TextWrappingStyle.Inline:
|
|
753
|
+
// Encode path never places Inline wrap on anchor (coerced earlier).
|
|
754
|
+
return xmlElement(WP_NS, 'wp', 'wrapNone');
|
|
755
|
+
default:
|
|
756
|
+
return xmlElement(WP_NS, 'wp', 'wrapNone');
|
|
757
|
+
}
|
|
758
|
+
}
|
|
759
|
+
function findResidualWrap(anchor) {
|
|
760
|
+
var e_6, _a;
|
|
761
|
+
if (anchor === undefined) {
|
|
762
|
+
return undefined;
|
|
763
|
+
}
|
|
764
|
+
var _loop_1 = function (name_1) {
|
|
765
|
+
var found = elementChildren(anchor).find(function (c) { return isElement(c, WP_NS, name_1); });
|
|
766
|
+
if (found !== undefined) {
|
|
767
|
+
return { value: found };
|
|
768
|
+
}
|
|
769
|
+
};
|
|
770
|
+
try {
|
|
771
|
+
for (var _b = __values([
|
|
772
|
+
'wrapNone',
|
|
773
|
+
'wrapSquare',
|
|
774
|
+
'wrapTight',
|
|
775
|
+
'wrapThrough',
|
|
776
|
+
'wrapTopAndBottom',
|
|
777
|
+
]), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
778
|
+
var name_1 = _c.value;
|
|
779
|
+
var state_1 = _loop_1(name_1);
|
|
780
|
+
if (typeof state_1 === "object")
|
|
781
|
+
return state_1.value;
|
|
782
|
+
}
|
|
783
|
+
}
|
|
784
|
+
catch (e_6_1) { e_6 = { error: e_6_1 }; }
|
|
785
|
+
finally {
|
|
786
|
+
try {
|
|
787
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
788
|
+
}
|
|
789
|
+
finally { if (e_6) throw e_6.error; }
|
|
790
|
+
}
|
|
791
|
+
return undefined;
|
|
792
|
+
}
|
|
793
|
+
/**
|
|
794
|
+
* Locate residual `wp:positionH` / `wp:positionV` children of an anchor.
|
|
795
|
+
*
|
|
796
|
+
* Children are preserved as-is (unknown `@relativeFrom` tokens or extra
|
|
797
|
+
* position children stay byte-identical on rebuild that does not model them).
|
|
798
|
+
*
|
|
799
|
+
* @private
|
|
800
|
+
*/
|
|
801
|
+
export function findResidualPositions(anchor) {
|
|
802
|
+
if (anchor === undefined) {
|
|
803
|
+
return { positionH: undefined, positionV: undefined };
|
|
804
|
+
}
|
|
805
|
+
return {
|
|
806
|
+
positionH: elementChildren(anchor).find(function (c) { return isElement(c, WP_NS, 'positionH'); }),
|
|
807
|
+
positionV: elementChildren(anchor).find(function (c) { return isElement(c, WP_NS, 'positionV'); }),
|
|
808
|
+
};
|
|
809
|
+
}
|
|
810
|
+
function findResidualEffectExtent(host) {
|
|
811
|
+
if (host === undefined) {
|
|
812
|
+
return undefined;
|
|
813
|
+
}
|
|
814
|
+
return elementChildren(host).find(function (c) { return isElement(c, WP_NS, 'effectExtent'); });
|
|
815
|
+
}
|
|
816
|
+
/**
|
|
817
|
+
* Whether the host carries a local-name attribute with numeric (possibly
|
|
818
|
+
* negative) integer content — used to detect residual host attrs without
|
|
819
|
+
* parsing semantics.
|
|
820
|
+
*/
|
|
821
|
+
/**
|
|
822
|
+
* Build `wp:positionH` for a new anchor when residual position is absent.
|
|
823
|
+
* Images parity default: `relativeFrom="column"` + `posOffset 0`.
|
|
824
|
+
*/
|
|
825
|
+
function buildDefaultPositionH() {
|
|
826
|
+
return xmlElement(WP_NS, 'wp', 'positionH', {
|
|
827
|
+
attributes: [attr('relativeFrom', HorizontalOrigin.Column)],
|
|
828
|
+
children: [
|
|
829
|
+
xmlElement(WP_NS, 'wp', 'posOffset', { children: [{ kind: 'text', value: '0' }] }),
|
|
830
|
+
],
|
|
831
|
+
});
|
|
832
|
+
}
|
|
833
|
+
/**
|
|
834
|
+
* Build `wp:positionV` for a new anchor when residual position is absent.
|
|
835
|
+
* Images parity default: `relativeFrom="paragraph"` + `posOffset 0`.
|
|
836
|
+
*/
|
|
837
|
+
function buildDefaultPositionV() {
|
|
838
|
+
return xmlElement(WP_NS, 'wp', 'positionV', {
|
|
839
|
+
attributes: [attr('relativeFrom', VerticalOrigin.Paragraph)],
|
|
840
|
+
children: [
|
|
841
|
+
xmlElement(WP_NS, 'wp', 'posOffset', { children: [{ kind: 'text', value: '0' }] }),
|
|
842
|
+
],
|
|
843
|
+
});
|
|
844
|
+
}
|
|
845
|
+
/**
|
|
846
|
+
* Build modeled `wp:positionH` (`CT_PosH`).
|
|
847
|
+
*
|
|
848
|
+
* Tokens: `ST_RelFromH` / `ST_AlignH` are imported, not invented (GO Q1 —
|
|
849
|
+
* `src/features/images/layout-types.ts`). Align XOR posOffset follows the
|
|
850
|
+
* `CT_PosH` schema choice. `ST_PositionOffset` is `xsd:int` (negative EMU
|
|
851
|
+
* legal). Default origin `'column'`; offset default `0` (images parity).
|
|
852
|
+
*
|
|
853
|
+
* @private
|
|
854
|
+
*/
|
|
855
|
+
export function buildDrawingPositionH(input) {
|
|
856
|
+
var origin = input.horizontalOrigin !== undefined ? input.horizontalOrigin : HorizontalOrigin.Column;
|
|
857
|
+
var child;
|
|
858
|
+
// Only schema ST_AlignH tokens serialize as wp:align. Model-only None/Unknown use posOffset.
|
|
859
|
+
if (input.horizontalAlignment !== undefined && isHorizontalAlignmentWire(input.horizontalAlignment)) {
|
|
860
|
+
child = xmlElement(WP_NS, 'wp', 'align', {
|
|
861
|
+
children: [{ kind: 'text', value: input.horizontalAlignment }],
|
|
862
|
+
});
|
|
863
|
+
}
|
|
864
|
+
else {
|
|
865
|
+
child = xmlElement(WP_NS, 'wp', 'posOffset', {
|
|
866
|
+
children: [{ kind: 'text', value: String(input.horizontalPositionEmu != null ? input.horizontalPositionEmu : 0) }],
|
|
867
|
+
});
|
|
868
|
+
}
|
|
869
|
+
return xmlElement(WP_NS, 'wp', 'positionH', {
|
|
870
|
+
attributes: [attr('relativeFrom', origin)],
|
|
871
|
+
children: [child],
|
|
872
|
+
});
|
|
873
|
+
}
|
|
874
|
+
/**
|
|
875
|
+
* Build modeled `wp:positionV` (`CT_PosV`). Default origin `'paragraph'`;
|
|
876
|
+
* offset default `0` (images parity).
|
|
877
|
+
*
|
|
878
|
+
* @private
|
|
879
|
+
*/
|
|
880
|
+
export function buildDrawingPositionV(input) {
|
|
881
|
+
var origin = input.verticalOrigin !== undefined ? input.verticalOrigin : VerticalOrigin.Paragraph;
|
|
882
|
+
var child;
|
|
883
|
+
// Only schema ST_AlignV tokens serialize as wp:align. Model-only None/Unknown use posOffset.
|
|
884
|
+
if (input.verticalAlignment !== undefined && isVerticalAlignmentWire(input.verticalAlignment)) {
|
|
885
|
+
child = xmlElement(WP_NS, 'wp', 'align', {
|
|
886
|
+
children: [{ kind: 'text', value: input.verticalAlignment }],
|
|
887
|
+
});
|
|
888
|
+
}
|
|
889
|
+
else {
|
|
890
|
+
child = xmlElement(WP_NS, 'wp', 'posOffset', {
|
|
891
|
+
children: [{ kind: 'text', value: String(input.verticalPositionEmu != null ? input.verticalPositionEmu : 0) }],
|
|
892
|
+
});
|
|
893
|
+
}
|
|
894
|
+
return xmlElement(WP_NS, 'wp', 'positionV', {
|
|
895
|
+
attributes: [attr('relativeFrom', origin)],
|
|
896
|
+
children: [child],
|
|
897
|
+
});
|
|
898
|
+
}
|
|
899
|
+
function copyElementAttrs(source, localNames) {
|
|
900
|
+
var e_7, _a;
|
|
901
|
+
if (source === undefined) {
|
|
902
|
+
return [];
|
|
903
|
+
}
|
|
904
|
+
var out = [];
|
|
905
|
+
try {
|
|
906
|
+
for (var localNames_1 = __values(localNames), localNames_1_1 = localNames_1.next(); !localNames_1_1.done; localNames_1_1 = localNames_1.next()) {
|
|
907
|
+
var name_2 = localNames_1_1.value;
|
|
908
|
+
var value = attributeValue(source, '', name_2);
|
|
909
|
+
if (value !== undefined) {
|
|
910
|
+
out.push(attr(name_2, value));
|
|
911
|
+
}
|
|
912
|
+
}
|
|
913
|
+
}
|
|
914
|
+
catch (e_7_1) { e_7 = { error: e_7_1 }; }
|
|
915
|
+
finally {
|
|
916
|
+
try {
|
|
917
|
+
if (localNames_1_1 && !localNames_1_1.done && (_a = localNames_1.return)) _a.call(localNames_1);
|
|
918
|
+
}
|
|
919
|
+
finally { if (e_7) throw e_7.error; }
|
|
920
|
+
}
|
|
921
|
+
return out;
|
|
922
|
+
}
|
|
923
|
+
function parseEmuAttr(host, localName) {
|
|
924
|
+
var raw = attributeValue(host, '', localName);
|
|
925
|
+
if (raw === undefined || !/^\d+$/.test(raw)) {
|
|
926
|
+
return undefined;
|
|
927
|
+
}
|
|
928
|
+
return Number.parseInt(raw, 10);
|
|
929
|
+
}
|
|
930
|
+
function parseOnOffAttr(host, localName) {
|
|
931
|
+
var raw = attributeValue(host, '', localName);
|
|
932
|
+
return raw === '1' || raw === 'true';
|
|
933
|
+
}
|
|
934
|
+
function textContent(el) {
|
|
935
|
+
var e_8, _a;
|
|
936
|
+
var out = '';
|
|
937
|
+
try {
|
|
938
|
+
for (var _b = __values(el.children), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
939
|
+
var child = _c.value;
|
|
940
|
+
if (child.kind === 'text') {
|
|
941
|
+
out += child.value;
|
|
942
|
+
}
|
|
943
|
+
}
|
|
944
|
+
}
|
|
945
|
+
catch (e_8_1) { e_8 = { error: e_8_1 }; }
|
|
946
|
+
finally {
|
|
947
|
+
try {
|
|
948
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
949
|
+
}
|
|
950
|
+
finally { if (e_8) throw e_8.error; }
|
|
951
|
+
}
|
|
952
|
+
return out;
|
|
953
|
+
}
|
|
954
|
+
/**
|
|
955
|
+
* Parse `wp:posOffset`/`wp:align` under `wp:positionH|V`.
|
|
956
|
+
*
|
|
957
|
+
* Cites: `CT_PosH`/`CT_PosV` — exactly one of `align` or `posOffset`
|
|
958
|
+
* (`ST_PositionOffset` = `xsd:int`, so negative EMU is legal);
|
|
959
|
+
* `ST_AlignH`/`ST_AlignV` token sets —
|
|
960
|
+
* `specs/schemas/xsd/OfficeOpenXML-XMLSchema-Transitional/dml-wordprocessingDrawing.xsd`.
|
|
961
|
+
* Unknown align tokens are dropped from the typed model (never re-written).
|
|
962
|
+
*/
|
|
963
|
+
function parsePosOffsetRawEmu(position) {
|
|
964
|
+
if (position === undefined) {
|
|
965
|
+
return undefined;
|
|
966
|
+
}
|
|
967
|
+
var offset = elementChildren(position).find(function (c) { return isElement(c, WP_NS, 'posOffset'); });
|
|
968
|
+
if (offset === undefined) {
|
|
969
|
+
return undefined;
|
|
970
|
+
}
|
|
971
|
+
var raw = textContent(offset).trim();
|
|
972
|
+
if (!/^-?\d+$/.test(raw)) {
|
|
973
|
+
return undefined;
|
|
974
|
+
}
|
|
975
|
+
return Number.parseInt(raw, 10);
|
|
976
|
+
}
|
|
977
|
+
/** Point form of the parsed `wp:posOffset` EMU (undefined when absent or negative). */
|
|
978
|
+
function parsePosOffsetEmu(position) {
|
|
979
|
+
var emu = parsePosOffsetRawEmu(position);
|
|
980
|
+
// Point is a non-negative brand (images parity). Negative offsets are legal
|
|
981
|
+
// on the wire (ST_PositionOffset = xsd:int) but unrepresentable;
|
|
982
|
+
// the raw element is preserved for round-trip (see findResidualPositions).
|
|
983
|
+
return emu !== undefined && emu >= 0 ? emuToPoint(emu) : undefined;
|
|
984
|
+
}
|
|
985
|
+
/**
|
|
986
|
+
* Parse `wp:align` on positionH/positionV.
|
|
987
|
+
* No position -> undefined (caller). No align child -> None (posOffset axis).
|
|
988
|
+
* Schema wire token -> token. Unrecognized residual token -> Unknown.
|
|
989
|
+
* Never returns undefined for a present position element.
|
|
990
|
+
*/
|
|
991
|
+
function parseAlignChild(position, axis) {
|
|
992
|
+
if (position === undefined) {
|
|
993
|
+
return undefined;
|
|
994
|
+
}
|
|
995
|
+
var alignEl = elementChildren(position).find(function (c) { return isElement(c, WP_NS, 'align'); });
|
|
996
|
+
if (alignEl === undefined) {
|
|
997
|
+
return axis === 'h' ? HorizontalAlignment.None : VerticalAlignment.None;
|
|
998
|
+
}
|
|
999
|
+
var raw = textContent(alignEl).trim();
|
|
1000
|
+
if (axis === 'h') {
|
|
1001
|
+
if (isHorizontalAlignmentWire(raw)) {
|
|
1002
|
+
return raw;
|
|
1003
|
+
}
|
|
1004
|
+
return HorizontalAlignment.Unknown;
|
|
1005
|
+
}
|
|
1006
|
+
if (isVerticalAlignmentWire(raw)) {
|
|
1007
|
+
return raw;
|
|
1008
|
+
}
|
|
1009
|
+
return VerticalAlignment.Unknown;
|
|
1010
|
+
}
|
|
1011
|
+
/**
|
|
1012
|
+
* Read wrapping, distances, behindDoc, and preset geometry from residual DrawingML.
|
|
1013
|
+
*
|
|
1014
|
+
* @private
|
|
1015
|
+
*/
|
|
1016
|
+
export function readDrawingWrapState(residual) {
|
|
1017
|
+
var __ts33_6;
|
|
1018
|
+
var drawing = ((__ts33_6 = preferredDrawingElement(residual)), __ts33_6 != null ? __ts33_6 : residual);
|
|
1019
|
+
var inline = findFirstElement(drawing, WP_NS, 'inline');
|
|
1020
|
+
var anchor = findFirstElement(drawing, WP_NS, 'anchor');
|
|
1021
|
+
var host = inline != null ? inline : anchor;
|
|
1022
|
+
var placement = inline !== undefined ? 'inline' : anchor !== undefined ? 'anchor' : undefined;
|
|
1023
|
+
var wrapping = host !== undefined && placement !== undefined
|
|
1024
|
+
? parseDrawingWrapping(host, placement)
|
|
1025
|
+
: TextWrappingStyle.None;
|
|
1026
|
+
var residualWrap = host !== undefined ? findResidualWrap(host) : undefined;
|
|
1027
|
+
var wrapType = wrapping === TextWrappingStyle.Square ||
|
|
1028
|
+
wrapping === TextWrappingStyle.Tight ||
|
|
1029
|
+
wrapping === TextWrappingStyle.Through
|
|
1030
|
+
? parseWrapTextAttr(residualWrap)
|
|
1031
|
+
: TextWrappingType.Both;
|
|
1032
|
+
var prstGeom = findFirstElement(drawing, A_NS, 'prstGeom');
|
|
1033
|
+
var presetGeometry = prstGeom !== undefined ? attributeValue(prstGeom, '', 'prst') : undefined;
|
|
1034
|
+
var anchorBooleans = {
|
|
1035
|
+
behindDocument: placement === 'anchor' && host !== undefined
|
|
1036
|
+
? parseOnOffAttr(host, 'behindDoc')
|
|
1037
|
+
: false,
|
|
1038
|
+
lockAnchor: placement === 'anchor' && host !== undefined
|
|
1039
|
+
? parseOnOffAttr(host, 'locked')
|
|
1040
|
+
: false,
|
|
1041
|
+
allowOverlap: placement === 'anchor' && host !== undefined
|
|
1042
|
+
? parseOnOffAttr(host, 'allowOverlap')
|
|
1043
|
+
: false,
|
|
1044
|
+
layoutInCell: placement === 'anchor' && host !== undefined
|
|
1045
|
+
? parseOnOffAttr(host, 'layoutInCell')
|
|
1046
|
+
: false,
|
|
1047
|
+
};
|
|
1048
|
+
if (host === undefined) {
|
|
1049
|
+
return __assign({ placement: placement,
|
|
1050
|
+
wrapping: wrapping, wrapType: TextWrappingType.Both, distanceTopEmu: undefined, distanceBottomEmu: undefined, distanceLeftEmu: undefined, distanceRightEmu: undefined }, anchorBooleans, { presetGeometry: presetGeometry });
|
|
1051
|
+
}
|
|
1052
|
+
return __assign({ placement: placement,
|
|
1053
|
+
wrapping: wrapping,
|
|
1054
|
+
wrapType: wrapType, distanceTopEmu: parseEmuAttr(host, 'distT'), distanceBottomEmu: parseEmuAttr(host, 'distB'), distanceLeftEmu: parseEmuAttr(host, 'distL'), distanceRightEmu: parseEmuAttr(host, 'distR') }, anchorBooleans, { presetGeometry: presetGeometry });
|
|
1055
|
+
}
|
|
1056
|
+
/**
|
|
1057
|
+
* Read `wp:positionH` / `wp:positionV` from residual DrawingML.
|
|
1058
|
+
*
|
|
1059
|
+
* Tokens are validated against images `layout-types` sets (GO Q1 import);
|
|
1060
|
+
* unknown `@relativeFrom` or align text is dropped (not preserved into the
|
|
1061
|
+
* typed model) so the encoder never writes an invented token.
|
|
1062
|
+
*
|
|
1063
|
+
* @private
|
|
1064
|
+
*/
|
|
1065
|
+
export function readDrawingPositionState(residual) {
|
|
1066
|
+
var __ts33_7;
|
|
1067
|
+
var drawing = ((__ts33_7 = preferredDrawingElement(residual)), __ts33_7 != null ? __ts33_7 : residual);
|
|
1068
|
+
var inline = findFirstElement(drawing, WP_NS, 'inline');
|
|
1069
|
+
var anchor = findFirstElement(drawing, WP_NS, 'anchor');
|
|
1070
|
+
var host = inline != null ? inline : anchor;
|
|
1071
|
+
var positionH = host !== undefined ? elementChildren(host).find(function (c) { return isElement(c, WP_NS, 'positionH'); }) : undefined;
|
|
1072
|
+
var positionV = host !== undefined ? elementChildren(host).find(function (c) { return isElement(c, WP_NS, 'positionV'); }) : undefined;
|
|
1073
|
+
var hOriginRaw = positionH !== undefined ? attributeValue(positionH, '', 'relativeFrom') : undefined;
|
|
1074
|
+
var vOriginRaw = positionV !== undefined ? attributeValue(positionV, '', 'relativeFrom') : undefined;
|
|
1075
|
+
return {
|
|
1076
|
+
horizontalOrigin: hOriginRaw !== undefined && isHorizontalOrigin(hOriginRaw) ? hOriginRaw : undefined,
|
|
1077
|
+
verticalOrigin: vOriginRaw !== undefined && isVerticalOrigin(vOriginRaw) ? vOriginRaw : undefined,
|
|
1078
|
+
horizontalPosition: parsePosOffsetEmu(positionH),
|
|
1079
|
+
verticalPosition: parsePosOffsetEmu(positionV),
|
|
1080
|
+
horizontalPositionEmu: parsePosOffsetRawEmu(positionH),
|
|
1081
|
+
verticalPositionEmu: parsePosOffsetRawEmu(positionV),
|
|
1082
|
+
horizontalAlignment: parseAlignChild(positionH, 'h'),
|
|
1083
|
+
verticalAlignment: parseAlignChild(positionV, 'v'),
|
|
1084
|
+
};
|
|
1085
|
+
}
|
|
1086
|
+
/**
|
|
1087
|
+
* Resolve effective placement from modeled wrap + requested placement.
|
|
1088
|
+
* Inline wrap forces `wp:inline`; other wraps force `wp:anchor`.
|
|
1089
|
+
*
|
|
1090
|
+
* @private
|
|
1091
|
+
*/
|
|
1092
|
+
export function effectiveDrawingPlacement(placement, wrapping) {
|
|
1093
|
+
if (wrapping === TextWrappingStyle.Inline) {
|
|
1094
|
+
return 'inline';
|
|
1095
|
+
}
|
|
1096
|
+
if (wrapping !== undefined) {
|
|
1097
|
+
return 'anchor';
|
|
1098
|
+
}
|
|
1099
|
+
return placement;
|
|
1100
|
+
}
|
|
1101
|
+
/**
|
|
1102
|
+
* Resolve effective wrapping for encode. Anchor + Inline wrap coerces to None.
|
|
1103
|
+
*
|
|
1104
|
+
* @private
|
|
1105
|
+
*/
|
|
1106
|
+
export function effectiveDrawingWrapping(placement, wrapping) {
|
|
1107
|
+
if (wrapping === undefined) {
|
|
1108
|
+
return placement === 'inline' ? TextWrappingStyle.Inline : TextWrappingStyle.None;
|
|
1109
|
+
}
|
|
1110
|
+
if (placement === 'anchor' && wrapping === TextWrappingStyle.Inline) {
|
|
1111
|
+
return TextWrappingStyle.None;
|
|
1112
|
+
}
|
|
1113
|
+
if (placement === 'inline') {
|
|
1114
|
+
return TextWrappingStyle.Inline;
|
|
1115
|
+
}
|
|
1116
|
+
return wrapping;
|
|
1117
|
+
}
|
|
1118
|
+
function buildInlineHost(input) {
|
|
1119
|
+
var __ts33_8;
|
|
1120
|
+
var preservedInline = input.preservedHost !== undefined
|
|
1121
|
+
? findFirstElement(input.preservedHost, WP_NS, 'inline')
|
|
1122
|
+
: undefined;
|
|
1123
|
+
var effect = ((__ts33_8 = findResidualEffectExtent(preservedInline)), __ts33_8 != null ? __ts33_8 : buildEffectExtent());
|
|
1124
|
+
var distT = input.distanceTopEmu != null ? input.distanceTopEmu : 0;
|
|
1125
|
+
var distB = input.distanceBottomEmu != null ? input.distanceBottomEmu : 0;
|
|
1126
|
+
var distL = input.distanceLeftEmu != null ? input.distanceLeftEmu : 0;
|
|
1127
|
+
var distR = input.distanceRightEmu != null ? input.distanceRightEmu : 0;
|
|
1128
|
+
var nsDecls = [
|
|
1129
|
+
{ prefix: 'wp', namespaceUri: WP_NS },
|
|
1130
|
+
{ prefix: 'a', namespaceUri: A_NS },
|
|
1131
|
+
{ prefix: 'wps', namespaceUri: WPS_NS },
|
|
1132
|
+
];
|
|
1133
|
+
if (input.groupChildElements !== undefined) {
|
|
1134
|
+
nsDecls.push({ prefix: 'wpg', namespaceUri: WPG_NS });
|
|
1135
|
+
}
|
|
1136
|
+
return xmlElement(WP_NS, 'wp', 'inline', {
|
|
1137
|
+
namespaceDeclarations: nsDecls,
|
|
1138
|
+
attributes: [
|
|
1139
|
+
attr('distT', String(distT)),
|
|
1140
|
+
attr('distB', String(distB)),
|
|
1141
|
+
attr('distL', String(distL)),
|
|
1142
|
+
attr('distR', String(distR)),
|
|
1143
|
+
],
|
|
1144
|
+
children: [
|
|
1145
|
+
xmlElement(WP_NS, 'wp', 'extent', {
|
|
1146
|
+
attributes: [attr('cx', String(input.widthEmu)), attr('cy', String(input.heightEmu))],
|
|
1147
|
+
}),
|
|
1148
|
+
effect,
|
|
1149
|
+
buildDocPr(input),
|
|
1150
|
+
buildCNvGraphicFramePr(input.lockAspectRatio != null ? input.lockAspectRatio : true),
|
|
1151
|
+
buildGraphic(input),
|
|
1152
|
+
],
|
|
1153
|
+
});
|
|
1154
|
+
}
|
|
1155
|
+
function buildAnchorHost(input) {
|
|
1156
|
+
var __ts33_9, __ts33_10, __ts33_11, __ts33_12, __ts33_13;
|
|
1157
|
+
var preservedAnchor = input.preservedHost !== undefined
|
|
1158
|
+
? findFirstElement(input.preservedHost, WP_NS, 'anchor')
|
|
1159
|
+
: undefined;
|
|
1160
|
+
var defaultAttrs = [
|
|
1161
|
+
attr('distT', String(input.distanceTopEmu != null ? input.distanceTopEmu : 0)),
|
|
1162
|
+
attr('distB', String(input.distanceBottomEmu != null ? input.distanceBottomEmu : 0)),
|
|
1163
|
+
attr('distL', String(input.distanceLeftEmu != null ? input.distanceLeftEmu : 114300)),
|
|
1164
|
+
attr('distR', String(input.distanceRightEmu != null ? input.distanceRightEmu : 114300)),
|
|
1165
|
+
attr('simplePos', '0'),
|
|
1166
|
+
attr('relativeHeight', '251658240'),
|
|
1167
|
+
attr('behindDoc', input.behindDocument === true ? '1' : '0'),
|
|
1168
|
+
attr('locked', input.lockAnchor === true ? '1' : '0'),
|
|
1169
|
+
attr('layoutInCell', input.layoutInCell === false ? '0' : '1'),
|
|
1170
|
+
attr('allowOverlap', input.allowOverlap === false ? '0' : '1'),
|
|
1171
|
+
];
|
|
1172
|
+
// When modeled host attrs are supplied, prefer them over residual attrs.
|
|
1173
|
+
var hasModeledHostAttrs = input.distanceTopEmu !== undefined ||
|
|
1174
|
+
input.distanceBottomEmu !== undefined ||
|
|
1175
|
+
input.distanceLeftEmu !== undefined ||
|
|
1176
|
+
input.distanceRightEmu !== undefined ||
|
|
1177
|
+
input.behindDocument !== undefined ||
|
|
1178
|
+
input.lockAnchor !== undefined ||
|
|
1179
|
+
input.allowOverlap !== undefined ||
|
|
1180
|
+
input.layoutInCell !== undefined ||
|
|
1181
|
+
input.layoutDirty === true;
|
|
1182
|
+
var attrs;
|
|
1183
|
+
if (hasModeledHostAttrs || preservedAnchor === undefined) {
|
|
1184
|
+
if (preservedAnchor !== undefined && !hasModeledHostAttrs) {
|
|
1185
|
+
var preservedAttrs = copyElementAttrs(preservedAnchor, [
|
|
1186
|
+
'distT',
|
|
1187
|
+
'distB',
|
|
1188
|
+
'distL',
|
|
1189
|
+
'distR',
|
|
1190
|
+
'simplePos',
|
|
1191
|
+
'relativeHeight',
|
|
1192
|
+
'behindDoc',
|
|
1193
|
+
'locked',
|
|
1194
|
+
'layoutInCell',
|
|
1195
|
+
'allowOverlap',
|
|
1196
|
+
'hidden',
|
|
1197
|
+
]);
|
|
1198
|
+
attrs = preservedAttrs.length > 0 ? preservedAttrs : defaultAttrs;
|
|
1199
|
+
}
|
|
1200
|
+
else if (preservedAnchor !== undefined) {
|
|
1201
|
+
// Merge: keep non-modeled structural attrs from residual; override the
|
|
1202
|
+
// modeled distance / behindDoc / anchor-option attrs.
|
|
1203
|
+
var base = copyElementAttrs(preservedAnchor, [
|
|
1204
|
+
'simplePos',
|
|
1205
|
+
'relativeHeight',
|
|
1206
|
+
'hidden',
|
|
1207
|
+
]);
|
|
1208
|
+
var merged = __spread([
|
|
1209
|
+
attr('distT', String(((__ts33_9 = input.distanceTopEmu != null ? input.distanceTopEmu : parseEmuAttr(preservedAnchor, 'distT')), __ts33_9 != null ? __ts33_9 : 0))),
|
|
1210
|
+
attr('distB', String(((__ts33_10 = input.distanceBottomEmu != null ? input.distanceBottomEmu : parseEmuAttr(preservedAnchor, 'distB')), __ts33_10 != null ? __ts33_10 : 0))),
|
|
1211
|
+
attr('distL', String(((__ts33_11 = input.distanceLeftEmu != null ? input.distanceLeftEmu : parseEmuAttr(preservedAnchor, 'distL')), __ts33_11 != null ? __ts33_11 : 114300))),
|
|
1212
|
+
attr('distR', String(((__ts33_12 = input.distanceRightEmu != null ? input.distanceRightEmu : parseEmuAttr(preservedAnchor, 'distR')), __ts33_12 != null ? __ts33_12 : 114300)))
|
|
1213
|
+
], (base.length > 0
|
|
1214
|
+
? base
|
|
1215
|
+
: [
|
|
1216
|
+
attr('simplePos', '0'),
|
|
1217
|
+
attr('relativeHeight', '251658240'),
|
|
1218
|
+
]), [
|
|
1219
|
+
attr('behindDoc', input.behindDocument !== undefined
|
|
1220
|
+
? input.behindDocument
|
|
1221
|
+
? '1'
|
|
1222
|
+
: '0'
|
|
1223
|
+
: parseOnOffAttr(preservedAnchor, 'behindDoc')
|
|
1224
|
+
? '1'
|
|
1225
|
+
: '0'),
|
|
1226
|
+
attr('locked', input.lockAnchor !== undefined
|
|
1227
|
+
? input.lockAnchor
|
|
1228
|
+
? '1'
|
|
1229
|
+
: '0'
|
|
1230
|
+
: parseOnOffAttr(preservedAnchor, 'locked')
|
|
1231
|
+
? '1'
|
|
1232
|
+
: '0'),
|
|
1233
|
+
attr('allowOverlap', input.allowOverlap !== undefined
|
|
1234
|
+
? input.allowOverlap
|
|
1235
|
+
? '1'
|
|
1236
|
+
: '0'
|
|
1237
|
+
: parseOnOffAttr(preservedAnchor, 'allowOverlap')
|
|
1238
|
+
? '1'
|
|
1239
|
+
: '0'),
|
|
1240
|
+
attr('layoutInCell', input.layoutInCell !== undefined
|
|
1241
|
+
? input.layoutInCell
|
|
1242
|
+
? '1'
|
|
1243
|
+
: '0'
|
|
1244
|
+
: parseOnOffAttr(preservedAnchor, 'layoutInCell')
|
|
1245
|
+
? '1'
|
|
1246
|
+
: '0'),
|
|
1247
|
+
]);
|
|
1248
|
+
attrs = merged;
|
|
1249
|
+
}
|
|
1250
|
+
else {
|
|
1251
|
+
attrs = defaultAttrs;
|
|
1252
|
+
}
|
|
1253
|
+
}
|
|
1254
|
+
else {
|
|
1255
|
+
var preservedAttrs = copyElementAttrs(preservedAnchor, [
|
|
1256
|
+
'distT',
|
|
1257
|
+
'distB',
|
|
1258
|
+
'distL',
|
|
1259
|
+
'distR',
|
|
1260
|
+
'simplePos',
|
|
1261
|
+
'relativeHeight',
|
|
1262
|
+
'behindDoc',
|
|
1263
|
+
'locked',
|
|
1264
|
+
'layoutInCell',
|
|
1265
|
+
'allowOverlap',
|
|
1266
|
+
'hidden',
|
|
1267
|
+
]);
|
|
1268
|
+
attrs = preservedAttrs.length > 0 ? preservedAttrs : defaultAttrs;
|
|
1269
|
+
}
|
|
1270
|
+
var residualWrap = findResidualWrap(preservedAnchor);
|
|
1271
|
+
var residualEffect = ((__ts33_13 = findResidualEffectExtent(preservedAnchor)), __ts33_13 != null ? __ts33_13 : buildEffectExtent());
|
|
1272
|
+
var residualSimplePos = preservedAnchor
|
|
1273
|
+
? elementChildren(preservedAnchor).find(function (c) { return isElement(c, WP_NS, 'simplePos'); })
|
|
1274
|
+
: undefined;
|
|
1275
|
+
var residualPositions = findResidualPositions(preservedAnchor);
|
|
1276
|
+
var useModeledLayout = input.layoutDirty === true || preservedAnchor === undefined;
|
|
1277
|
+
var wrapping = effectiveDrawingWrapping('anchor', input.wrapping != null ? input.wrapping : TextWrappingStyle.None);
|
|
1278
|
+
var simplePos;
|
|
1279
|
+
var positionH;
|
|
1280
|
+
var positionV;
|
|
1281
|
+
var wrap;
|
|
1282
|
+
var modeledModes = usedModeledPositionMode(input);
|
|
1283
|
+
if (useModeledLayout) {
|
|
1284
|
+
simplePos = residualSimplePos != null ? residualSimplePos : xmlElement(WP_NS, 'wp', 'simplePos', {
|
|
1285
|
+
attributes: [attr('x', '0'), attr('y', '0')],
|
|
1286
|
+
});
|
|
1287
|
+
// Rebuild each axis independently so setting V never rewrites H.
|
|
1288
|
+
positionH = modeledModes.horizontal
|
|
1289
|
+
? buildDrawingPositionH(input)
|
|
1290
|
+
: (residualPositions.positionH != null ? residualPositions.positionH : buildDefaultPositionH());
|
|
1291
|
+
positionV = modeledModes.vertical
|
|
1292
|
+
? buildDrawingPositionV(input)
|
|
1293
|
+
: (residualPositions.positionV != null ? residualPositions.positionV : buildDefaultPositionV());
|
|
1294
|
+
wrap = buildWrapElement(wrapping, residualWrap, input.wrapType);
|
|
1295
|
+
}
|
|
1296
|
+
else {
|
|
1297
|
+
var ph = elementChildren(preservedAnchor).find(function (c) { return isElement(c, WP_NS, 'positionH'); });
|
|
1298
|
+
var pv = elementChildren(preservedAnchor).find(function (c) { return isElement(c, WP_NS, 'positionV'); });
|
|
1299
|
+
simplePos = residualSimplePos != null ? residualSimplePos : xmlElement(WP_NS, 'wp', 'simplePos', {
|
|
1300
|
+
attributes: [attr('x', '0'), attr('y', '0')],
|
|
1301
|
+
});
|
|
1302
|
+
positionH = ph != null ? ph : xmlElement(WP_NS, 'wp', 'positionH', {
|
|
1303
|
+
attributes: [attr('relativeFrom', 'column')],
|
|
1304
|
+
children: [
|
|
1305
|
+
xmlElement(WP_NS, 'wp', 'posOffset', {
|
|
1306
|
+
children: [{ kind: 'text', value: '0' }],
|
|
1307
|
+
}),
|
|
1308
|
+
],
|
|
1309
|
+
});
|
|
1310
|
+
positionV = pv != null ? pv : xmlElement(WP_NS, 'wp', 'positionV', {
|
|
1311
|
+
attributes: [attr('relativeFrom', 'paragraph')],
|
|
1312
|
+
children: [
|
|
1313
|
+
xmlElement(WP_NS, 'wp', 'posOffset', {
|
|
1314
|
+
children: [{ kind: 'text', value: '0' }],
|
|
1315
|
+
}),
|
|
1316
|
+
],
|
|
1317
|
+
});
|
|
1318
|
+
wrap = residualWrap != null ? residualWrap : xmlElement(WP_NS, 'wp', 'wrapNone');
|
|
1319
|
+
}
|
|
1320
|
+
var nsDecls = [
|
|
1321
|
+
{ prefix: 'wp', namespaceUri: WP_NS },
|
|
1322
|
+
{ prefix: 'a', namespaceUri: A_NS },
|
|
1323
|
+
{ prefix: 'wps', namespaceUri: WPS_NS },
|
|
1324
|
+
];
|
|
1325
|
+
if (input.groupChildElements !== undefined) {
|
|
1326
|
+
nsDecls.push({ prefix: 'wpg', namespaceUri: WPG_NS });
|
|
1327
|
+
}
|
|
1328
|
+
return xmlElement(WP_NS, 'wp', 'anchor', {
|
|
1329
|
+
namespaceDeclarations: nsDecls,
|
|
1330
|
+
attributes: attrs,
|
|
1331
|
+
children: [
|
|
1332
|
+
simplePos,
|
|
1333
|
+
positionH,
|
|
1334
|
+
positionV,
|
|
1335
|
+
xmlElement(WP_NS, 'wp', 'extent', {
|
|
1336
|
+
attributes: [attr('cx', String(input.widthEmu)), attr('cy', String(input.heightEmu))],
|
|
1337
|
+
}),
|
|
1338
|
+
residualEffect,
|
|
1339
|
+
wrap,
|
|
1340
|
+
buildDocPr(input),
|
|
1341
|
+
buildCNvGraphicFramePr(input.lockAspectRatio != null ? input.lockAspectRatio : true),
|
|
1342
|
+
buildGraphic(input),
|
|
1343
|
+
],
|
|
1344
|
+
});
|
|
1345
|
+
}
|
|
1346
|
+
/** True when any anchor-option field is explicitly modeled. */
|
|
1347
|
+
/**
|
|
1348
|
+
* Whether the caller explicitly modeled a position mode (offset or align).
|
|
1349
|
+
* Hydrated-from-residual values do NOT count: rebuilt wire must preserve the
|
|
1350
|
+
* residual axis bytes untouched unless the user intervened on that axis.
|
|
1351
|
+
*
|
|
1352
|
+
* @private
|
|
1353
|
+
*/
|
|
1354
|
+
export function usedModeledPositionMode(input) {
|
|
1355
|
+
return {
|
|
1356
|
+
horizontal: input.horizontalModeled === true,
|
|
1357
|
+
vertical: input.verticalModeled === true,
|
|
1358
|
+
};
|
|
1359
|
+
}
|
|
1360
|
+
function parseOnOff(raw) {
|
|
1361
|
+
return raw === '1' || raw === 'true';
|
|
1362
|
+
}
|
|
1363
|
+
function parseExtentEmus(element) {
|
|
1364
|
+
if (element === undefined) {
|
|
1365
|
+
return undefined;
|
|
1366
|
+
}
|
|
1367
|
+
var cxRaw = attributeValue(element, '', 'cx');
|
|
1368
|
+
var cyRaw = attributeValue(element, '', 'cy');
|
|
1369
|
+
if (cxRaw === undefined || cyRaw === undefined || !/^\d+$/.test(cxRaw) || !/^\d+$/.test(cyRaw)) {
|
|
1370
|
+
return undefined;
|
|
1371
|
+
}
|
|
1372
|
+
return {
|
|
1373
|
+
widthEmu: Number.parseInt(cxRaw, 10),
|
|
1374
|
+
heightEmu: Number.parseInt(cyRaw, 10),
|
|
1375
|
+
};
|
|
1376
|
+
}
|
|
1377
|
+
function parseXfrmTransform(root) {
|
|
1378
|
+
var xfrm = findFirstElement(root, A_NS, 'xfrm');
|
|
1379
|
+
if (xfrm === undefined) {
|
|
1380
|
+
return { rotation: 0, flipHorizontal: false, flipVertical: false, ext: undefined };
|
|
1381
|
+
}
|
|
1382
|
+
var rotRaw = attributeValue(xfrm, '', 'rot');
|
|
1383
|
+
var rotation = rotRaw !== undefined && /^-?\d+$/.test(rotRaw)
|
|
1384
|
+
? Number.parseInt(rotRaw, 10) / ROTATION_UNITS_PER_DEGREE
|
|
1385
|
+
: 0;
|
|
1386
|
+
var extEl = elementChildren(xfrm).find(function (c) { return isElement(c, A_NS, 'ext'); });
|
|
1387
|
+
return {
|
|
1388
|
+
rotation: rotation,
|
|
1389
|
+
flipHorizontal: parseOnOff(attributeValue(xfrm, '', 'flipH')),
|
|
1390
|
+
flipVertical: parseOnOff(attributeValue(xfrm, '', 'flipV')),
|
|
1391
|
+
ext: parseExtentEmus(extEl),
|
|
1392
|
+
};
|
|
1393
|
+
}
|
|
1394
|
+
function parseLockAspect(host) {
|
|
1395
|
+
var locks = findFirstElement(host, A_NS, 'graphicFrameLocks');
|
|
1396
|
+
if (locks === undefined) {
|
|
1397
|
+
return false;
|
|
1398
|
+
}
|
|
1399
|
+
return parseOnOff(attributeValue(locks, '', 'noChangeAspect'));
|
|
1400
|
+
}
|
|
1401
|
+
function preferHost(drawing) {
|
|
1402
|
+
var inline = findFirstElement(drawing, WP_NS, 'inline');
|
|
1403
|
+
var anchor = findFirstElement(drawing, WP_NS, 'anchor');
|
|
1404
|
+
return inline != null ? inline : anchor;
|
|
1405
|
+
}
|
|
1406
|
+
/**
|
|
1407
|
+
* Read size/transform/lock from preferred DrawingML host.
|
|
1408
|
+
* Public size prefers `wp:extent`; xfrm ext is residual until size dirty.
|
|
1409
|
+
*
|
|
1410
|
+
* @private
|
|
1411
|
+
*/
|
|
1412
|
+
export function readDrawingLayout(root) {
|
|
1413
|
+
var __ts33_14, __ts33_15, __ts33_16;
|
|
1414
|
+
var drawing = ((__ts33_14 = preferredDrawingElement(root)), __ts33_14 != null ? __ts33_14 : (isWml(root, 'drawing') ? root : undefined));
|
|
1415
|
+
if (drawing === undefined) {
|
|
1416
|
+
return {
|
|
1417
|
+
widthEmu: undefined,
|
|
1418
|
+
heightEmu: undefined,
|
|
1419
|
+
rotation: 0,
|
|
1420
|
+
flipHorizontal: false,
|
|
1421
|
+
flipVertical: false,
|
|
1422
|
+
lockAspectRatio: false,
|
|
1423
|
+
};
|
|
1424
|
+
}
|
|
1425
|
+
var host = preferHost(drawing);
|
|
1426
|
+
var extentEl = host !== undefined ? findFirstElement(host, WP_NS, 'extent') : undefined;
|
|
1427
|
+
var fromExtent = parseExtentEmus(extentEl);
|
|
1428
|
+
var xfrm = parseXfrmTransform(drawing);
|
|
1429
|
+
return {
|
|
1430
|
+
widthEmu: ((__ts33_15 = fromExtent == null ? undefined : fromExtent.widthEmu), __ts33_15 != null ? __ts33_15 : xfrm.ext == null ? undefined : xfrm.ext.widthEmu),
|
|
1431
|
+
heightEmu: ((__ts33_16 = fromExtent == null ? undefined : fromExtent.heightEmu), __ts33_16 != null ? __ts33_16 : xfrm.ext == null ? undefined : xfrm.ext.heightEmu),
|
|
1432
|
+
rotation: xfrm.rotation,
|
|
1433
|
+
flipHorizontal: xfrm.flipHorizontal,
|
|
1434
|
+
flipVertical: xfrm.flipVertical,
|
|
1435
|
+
lockAspectRatio: host !== undefined ? parseLockAspect(host) : false,
|
|
1436
|
+
};
|
|
1437
|
+
}
|
|
1438
|
+
function replaceLocalAttrs(el, mutator) {
|
|
1439
|
+
var next = mutator(__spread(el.attributes));
|
|
1440
|
+
el.attributes = next;
|
|
1441
|
+
}
|
|
1442
|
+
function setExtentAttrs(el, widthEmu, heightEmu) {
|
|
1443
|
+
replaceLocalAttrs(el, function (attrs) {
|
|
1444
|
+
var e_9, _a;
|
|
1445
|
+
var next = [];
|
|
1446
|
+
var sawCx = false;
|
|
1447
|
+
var sawCy = false;
|
|
1448
|
+
try {
|
|
1449
|
+
for (var attrs_1 = __values(attrs), attrs_1_1 = attrs_1.next(); !attrs_1_1.done; attrs_1_1 = attrs_1.next()) {
|
|
1450
|
+
var a = attrs_1_1.value;
|
|
1451
|
+
if (a.namespaceUri === '' && a.localName === 'cx') {
|
|
1452
|
+
sawCx = true;
|
|
1453
|
+
next.push(attr('cx', String(widthEmu)));
|
|
1454
|
+
continue;
|
|
1455
|
+
}
|
|
1456
|
+
if (a.namespaceUri === '' && a.localName === 'cy') {
|
|
1457
|
+
sawCy = true;
|
|
1458
|
+
next.push(attr('cy', String(heightEmu)));
|
|
1459
|
+
continue;
|
|
1460
|
+
}
|
|
1461
|
+
next.push(a);
|
|
1462
|
+
}
|
|
1463
|
+
}
|
|
1464
|
+
catch (e_9_1) { e_9 = { error: e_9_1 }; }
|
|
1465
|
+
finally {
|
|
1466
|
+
try {
|
|
1467
|
+
if (attrs_1_1 && !attrs_1_1.done && (_a = attrs_1.return)) _a.call(attrs_1);
|
|
1468
|
+
}
|
|
1469
|
+
finally { if (e_9) throw e_9.error; }
|
|
1470
|
+
}
|
|
1471
|
+
if (!sawCx) {
|
|
1472
|
+
next.push(attr('cx', String(widthEmu)));
|
|
1473
|
+
}
|
|
1474
|
+
if (!sawCy) {
|
|
1475
|
+
next.push(attr('cy', String(heightEmu)));
|
|
1476
|
+
}
|
|
1477
|
+
return next;
|
|
1478
|
+
});
|
|
1479
|
+
}
|
|
1480
|
+
function patchXfrmElement(xfrm, layout) {
|
|
1481
|
+
replaceLocalAttrs(xfrm, function (attrs) {
|
|
1482
|
+
var e_10, _a;
|
|
1483
|
+
var kept = [];
|
|
1484
|
+
try {
|
|
1485
|
+
for (var attrs_2 = __values(attrs), attrs_2_1 = attrs_2.next(); !attrs_2_1.done; attrs_2_1 = attrs_2.next()) {
|
|
1486
|
+
var a = attrs_2_1.value;
|
|
1487
|
+
if (a.namespaceUri !== '') {
|
|
1488
|
+
kept.push(a);
|
|
1489
|
+
continue;
|
|
1490
|
+
}
|
|
1491
|
+
if (a.localName === 'rot' || a.localName === 'flipH' || a.localName === 'flipV') {
|
|
1492
|
+
continue;
|
|
1493
|
+
}
|
|
1494
|
+
kept.push(a);
|
|
1495
|
+
}
|
|
1496
|
+
}
|
|
1497
|
+
catch (e_10_1) { e_10 = { error: e_10_1 }; }
|
|
1498
|
+
finally {
|
|
1499
|
+
try {
|
|
1500
|
+
if (attrs_2_1 && !attrs_2_1.done && (_a = attrs_2.return)) _a.call(attrs_2);
|
|
1501
|
+
}
|
|
1502
|
+
finally { if (e_10) throw e_10.error; }
|
|
1503
|
+
}
|
|
1504
|
+
return __spread(kept, buildXfrmAttributes(layout));
|
|
1505
|
+
});
|
|
1506
|
+
var ext = elementChildren(xfrm).find(function (c) { return isElement(c, A_NS, 'ext'); });
|
|
1507
|
+
if (ext === undefined) {
|
|
1508
|
+
ext = xmlElement(A_NS, 'a', 'ext', {
|
|
1509
|
+
attributes: [attr('cx', String(layout.widthEmu)), attr('cy', String(layout.heightEmu))],
|
|
1510
|
+
});
|
|
1511
|
+
var children = __spread(xfrm.children, [ext]);
|
|
1512
|
+
xfrm.children = children;
|
|
1513
|
+
}
|
|
1514
|
+
else {
|
|
1515
|
+
setExtentAttrs(ext, layout.widthEmu, layout.heightEmu);
|
|
1516
|
+
}
|
|
1517
|
+
}
|
|
1518
|
+
function ensureXfrmOnSpPr(drawing, layout) {
|
|
1519
|
+
var xfrm = findFirstElement(drawing, A_NS, 'xfrm');
|
|
1520
|
+
if (xfrm !== undefined) {
|
|
1521
|
+
patchXfrmElement(xfrm, layout);
|
|
1522
|
+
return;
|
|
1523
|
+
}
|
|
1524
|
+
// Insert under first wps:spPr when present (do not invent full wsp tree).
|
|
1525
|
+
var spPr = findFirstElement(drawing, WPS_NS, 'spPr');
|
|
1526
|
+
if (spPr === undefined) {
|
|
1527
|
+
return;
|
|
1528
|
+
}
|
|
1529
|
+
var off = xmlElement(A_NS, 'a', 'off', {
|
|
1530
|
+
attributes: [attr('x', '0'), attr('y', '0')],
|
|
1531
|
+
});
|
|
1532
|
+
var ext = xmlElement(A_NS, 'a', 'ext', {
|
|
1533
|
+
attributes: [attr('cx', String(layout.widthEmu)), attr('cy', String(layout.heightEmu))],
|
|
1534
|
+
});
|
|
1535
|
+
xfrm = xmlElement(A_NS, 'a', 'xfrm', {
|
|
1536
|
+
attributes: buildXfrmAttributes(layout),
|
|
1537
|
+
children: [off, ext],
|
|
1538
|
+
});
|
|
1539
|
+
spPr.children = __spread([xfrm], spPr.children);
|
|
1540
|
+
}
|
|
1541
|
+
function patchCNvGraphicFramePr(host, lockAspectRatio) {
|
|
1542
|
+
var framePr = elementChildren(host).find(function (c) { return isElement(c, WP_NS, 'cNvGraphicFramePr'); });
|
|
1543
|
+
if (framePr === undefined) {
|
|
1544
|
+
framePr = buildCNvGraphicFramePr(lockAspectRatio);
|
|
1545
|
+
// Insert after docPr when possible; else append.
|
|
1546
|
+
var children = __spread(host.children);
|
|
1547
|
+
var docPrIndex = children.findIndex(function (c) { return c.kind === 'element' && isElement(c, WP_NS, 'docPr'); });
|
|
1548
|
+
if (docPrIndex >= 0) {
|
|
1549
|
+
children.splice(docPrIndex + 1, 0, framePr);
|
|
1550
|
+
}
|
|
1551
|
+
else {
|
|
1552
|
+
children.push(framePr);
|
|
1553
|
+
}
|
|
1554
|
+
host.children = children;
|
|
1555
|
+
return;
|
|
1556
|
+
}
|
|
1557
|
+
var locks = elementChildren(framePr).find(function (c) { return isElement(c, A_NS, 'graphicFrameLocks'); });
|
|
1558
|
+
if (locks === undefined) {
|
|
1559
|
+
locks = xmlElement(A_NS, 'a', 'graphicFrameLocks', {
|
|
1560
|
+
attributes: lockAspectRatio ? [attr('noChangeAspect', '1')] : [],
|
|
1561
|
+
});
|
|
1562
|
+
framePr.children = __spread([locks], framePr.children);
|
|
1563
|
+
return;
|
|
1564
|
+
}
|
|
1565
|
+
replaceLocalAttrs(locks, function (attrs) {
|
|
1566
|
+
var e_11, _a;
|
|
1567
|
+
var kept = [];
|
|
1568
|
+
try {
|
|
1569
|
+
for (var attrs_3 = __values(attrs), attrs_3_1 = attrs_3.next(); !attrs_3_1.done; attrs_3_1 = attrs_3.next()) {
|
|
1570
|
+
var a = attrs_3_1.value;
|
|
1571
|
+
if (a.namespaceUri === '' && a.localName === 'noChangeAspect') {
|
|
1572
|
+
continue;
|
|
1573
|
+
}
|
|
1574
|
+
kept.push(a);
|
|
1575
|
+
}
|
|
1576
|
+
}
|
|
1577
|
+
catch (e_11_1) { e_11 = { error: e_11_1 }; }
|
|
1578
|
+
finally {
|
|
1579
|
+
try {
|
|
1580
|
+
if (attrs_3_1 && !attrs_3_1.done && (_a = attrs_3.return)) _a.call(attrs_3);
|
|
1581
|
+
}
|
|
1582
|
+
finally { if (e_11) throw e_11.error; }
|
|
1583
|
+
}
|
|
1584
|
+
if (lockAspectRatio) {
|
|
1585
|
+
kept.push(attr('noChangeAspect', '1'));
|
|
1586
|
+
}
|
|
1587
|
+
return kept;
|
|
1588
|
+
});
|
|
1589
|
+
}
|
|
1590
|
+
function emuToPointsString(emus) {
|
|
1591
|
+
var pt = emus / EMU_PER_POINT;
|
|
1592
|
+
// Avoid scientific notation; trim trailing zeros modestly.
|
|
1593
|
+
var rounded = Math.round(pt * 1000) / 1000;
|
|
1594
|
+
return String(rounded) + "pt";
|
|
1595
|
+
}
|
|
1596
|
+
/**
|
|
1597
|
+
* Convert non-negative EMU to a bare points number string for VML CSS tokens
|
|
1598
|
+
* that omit the `pt` unit in ShapeRequirements samples (e.g. mso-wrap-distance-top:0).
|
|
1599
|
+
* Zero is emitted as `0` (no unit); positive values use `Npt`.
|
|
1600
|
+
*/
|
|
1601
|
+
function emuToCssLengthToken(emus) {
|
|
1602
|
+
if (emus === 0) {
|
|
1603
|
+
return '0';
|
|
1604
|
+
}
|
|
1605
|
+
return emuToPointsString(emus);
|
|
1606
|
+
}
|
|
1607
|
+
/**
|
|
1608
|
+
* sRGB hex for VML color attributes. Strip optional leading `#`; lowercase 6-digit.
|
|
1609
|
+
* Returns undefined when the value is not a 6-digit hex (omit rather than invent).
|
|
1610
|
+
*/
|
|
1611
|
+
function srgbToVmlColor(srgb) {
|
|
1612
|
+
var raw = srgb.startsWith('#') ? srgb.slice(1) : srgb;
|
|
1613
|
+
if (!/^[0-9A-Fa-f]{6}$/.test(raw)) {
|
|
1614
|
+
return undefined;
|
|
1615
|
+
}
|
|
1616
|
+
return "#" + raw.toLowerCase();
|
|
1617
|
+
}
|
|
1618
|
+
/**
|
|
1619
|
+
* DML `ST_LineCap` → VML `ST_StrokeEndCap` (`vml-main.xsd`: flat|square|round).
|
|
1620
|
+
* Cites: AG_StrokeAttributes `@endcap`; DML rnd|sq|flat.
|
|
1621
|
+
*/
|
|
1622
|
+
function mapLineCapToVmlEndcap(cap) {
|
|
1623
|
+
if (cap === undefined) {
|
|
1624
|
+
return undefined;
|
|
1625
|
+
}
|
|
1626
|
+
switch (cap) {
|
|
1627
|
+
case 'rnd':
|
|
1628
|
+
return 'round';
|
|
1629
|
+
case 'sq':
|
|
1630
|
+
return 'square';
|
|
1631
|
+
case 'flat':
|
|
1632
|
+
return 'flat';
|
|
1633
|
+
default:
|
|
1634
|
+
// TS 3.3: LineCap widens to string without literal asserts — no never exhaustiveness.
|
|
1635
|
+
return undefined;
|
|
1636
|
+
}
|
|
1637
|
+
}
|
|
1638
|
+
/**
|
|
1639
|
+
* DML `ST_LineEndType` → VML `ST_StrokeArrowType`.
|
|
1640
|
+
*
|
|
1641
|
+
* Locked corpus pair (ShapeRequirements connector Fallback):
|
|
1642
|
+
* DML `a:tailEnd type="triangle"` → VML `endarrow="block"`.
|
|
1643
|
+
* Identity pairs with matching ST_StrokeArrowType tokens: none, diamond, oval.
|
|
1644
|
+
* Unmapped (stealth, arrow) are omitted — never invent classic/open without cite.
|
|
1645
|
+
*/
|
|
1646
|
+
function mapLineEndTypeToVmlArrow(type) {
|
|
1647
|
+
if (type === undefined) {
|
|
1648
|
+
return undefined;
|
|
1649
|
+
}
|
|
1650
|
+
switch (type) {
|
|
1651
|
+
case 'none':
|
|
1652
|
+
return 'none';
|
|
1653
|
+
case 'triangle':
|
|
1654
|
+
return 'block';
|
|
1655
|
+
case 'diamond':
|
|
1656
|
+
return 'diamond';
|
|
1657
|
+
case 'oval':
|
|
1658
|
+
return 'oval';
|
|
1659
|
+
case 'stealth':
|
|
1660
|
+
case 'arrow':
|
|
1661
|
+
return undefined;
|
|
1662
|
+
default:
|
|
1663
|
+
return undefined;
|
|
1664
|
+
}
|
|
1665
|
+
}
|
|
1666
|
+
/**
|
|
1667
|
+
* DML arrow size (sm|med|lg) → VML ST_StrokeArrowWidth / Point
|
|
1668
|
+
* (narrow|medium|wide and short|medium|long). Same three-level ladder; cited
|
|
1669
|
+
* only when arrow type is also mapped.
|
|
1670
|
+
*/
|
|
1671
|
+
function mapLineEndSizeToVmlWidth(size) {
|
|
1672
|
+
if (size === undefined) {
|
|
1673
|
+
return undefined;
|
|
1674
|
+
}
|
|
1675
|
+
switch (size) {
|
|
1676
|
+
case 'sm':
|
|
1677
|
+
return 'narrow';
|
|
1678
|
+
case 'med':
|
|
1679
|
+
return 'medium';
|
|
1680
|
+
case 'lg':
|
|
1681
|
+
return 'wide';
|
|
1682
|
+
default:
|
|
1683
|
+
// TS 3.3: LineEndSize widens to string[] element without literal asserts.
|
|
1684
|
+
return undefined;
|
|
1685
|
+
}
|
|
1686
|
+
}
|
|
1687
|
+
function mapLineEndSizeToVmlLength(size) {
|
|
1688
|
+
if (size === undefined) {
|
|
1689
|
+
return undefined;
|
|
1690
|
+
}
|
|
1691
|
+
switch (size) {
|
|
1692
|
+
case 'sm':
|
|
1693
|
+
return 'short';
|
|
1694
|
+
case 'med':
|
|
1695
|
+
return 'medium';
|
|
1696
|
+
case 'lg':
|
|
1697
|
+
return 'long';
|
|
1698
|
+
default:
|
|
1699
|
+
return undefined;
|
|
1700
|
+
}
|
|
1701
|
+
}
|
|
1702
|
+
/**
|
|
1703
|
+
* DML `ST_LineDashingVal` → VML `@dashstyle` (xsd:string on AG_StrokeAttributes).
|
|
1704
|
+
* Only clear literal pairs; omit unmapped (never invent dash patterns).
|
|
1705
|
+
*/
|
|
1706
|
+
function mapLineDashingToVml(dash) {
|
|
1707
|
+
if (dash === undefined || dash === 'unknown') {
|
|
1708
|
+
return undefined;
|
|
1709
|
+
}
|
|
1710
|
+
switch (dash) {
|
|
1711
|
+
case 'solid':
|
|
1712
|
+
return 'solid';
|
|
1713
|
+
case 'dash':
|
|
1714
|
+
case 'lgDash':
|
|
1715
|
+
case 'sysDash':
|
|
1716
|
+
return 'dash';
|
|
1717
|
+
case 'dot':
|
|
1718
|
+
case 'sysDot':
|
|
1719
|
+
return 'dot';
|
|
1720
|
+
case 'dashDot':
|
|
1721
|
+
case 'lgDashDot':
|
|
1722
|
+
case 'sysDashDot':
|
|
1723
|
+
return 'dashDot';
|
|
1724
|
+
case 'lgDashDotDot':
|
|
1725
|
+
case 'sysDashDotDot':
|
|
1726
|
+
return 'dashDotDot';
|
|
1727
|
+
default:
|
|
1728
|
+
// TS 3.3: LineDashing widens to string without literal asserts.
|
|
1729
|
+
return undefined;
|
|
1730
|
+
}
|
|
1731
|
+
}
|
|
1732
|
+
/**
|
|
1733
|
+
* `wp:wrap*` style → `w10:wrap/@type` (`ST_WrapType`) and optional
|
|
1734
|
+
* `mso-wrap-style` (ECMA Part 4 allows square|none only on that CSS token).
|
|
1735
|
+
*/
|
|
1736
|
+
function mapWrappingToVmlWrap(wrapping) {
|
|
1737
|
+
switch (wrapping) {
|
|
1738
|
+
case TextWrappingStyle.Square:
|
|
1739
|
+
return { w10Type: 'square', msoWrapStyle: 'square' };
|
|
1740
|
+
case TextWrappingStyle.None:
|
|
1741
|
+
return { w10Type: 'none', msoWrapStyle: 'none' };
|
|
1742
|
+
case TextWrappingStyle.Tight:
|
|
1743
|
+
return { w10Type: 'tight', msoWrapStyle: undefined };
|
|
1744
|
+
case TextWrappingStyle.Through:
|
|
1745
|
+
return { w10Type: 'through', msoWrapStyle: undefined };
|
|
1746
|
+
case TextWrappingStyle.TopAndBottom:
|
|
1747
|
+
return { w10Type: 'topAndBottom', msoWrapStyle: undefined };
|
|
1748
|
+
case TextWrappingStyle.Inline:
|
|
1749
|
+
case undefined:
|
|
1750
|
+
// Inline hosts: no w10:wrap; mso-wrap-style omitted (flow with text).
|
|
1751
|
+
return { w10Type: undefined, msoWrapStyle: undefined };
|
|
1752
|
+
default:
|
|
1753
|
+
// TS 3.3: TextWrappingStyle widens to string without literal asserts.
|
|
1754
|
+
return { w10Type: undefined, msoWrapStyle: undefined };
|
|
1755
|
+
}
|
|
1756
|
+
}
|
|
1757
|
+
/**
|
|
1758
|
+
* DML `ST_RelFromH` → w10 `ST_HorizontalAnchor` / mso-position-horizontal-relative.
|
|
1759
|
+
* Only tokens that exist on both sides: margin|page|text(←column)|char(←character).
|
|
1760
|
+
* Margin-side variants (leftMargin, …) are omitted rather than inventing.
|
|
1761
|
+
*/
|
|
1762
|
+
function mapHorizontalOriginToVml(origin) {
|
|
1763
|
+
switch (origin) {
|
|
1764
|
+
case HorizontalOrigin.Margin:
|
|
1765
|
+
return 'margin';
|
|
1766
|
+
case HorizontalOrigin.Page:
|
|
1767
|
+
return 'page';
|
|
1768
|
+
case HorizontalOrigin.Column:
|
|
1769
|
+
// ShapeRequirements samples use mso-position-horizontal-relative:text for
|
|
1770
|
+
// column-relative anchors (w10 ST_HorizontalAnchor includes `text`).
|
|
1771
|
+
return 'text';
|
|
1772
|
+
case HorizontalOrigin.Character:
|
|
1773
|
+
return 'char';
|
|
1774
|
+
case HorizontalOrigin.LeftMargin:
|
|
1775
|
+
case HorizontalOrigin.RightMargin:
|
|
1776
|
+
case HorizontalOrigin.InsideMargin:
|
|
1777
|
+
case HorizontalOrigin.OutsideMargin:
|
|
1778
|
+
case undefined:
|
|
1779
|
+
return undefined;
|
|
1780
|
+
default:
|
|
1781
|
+
// TS 3.3: HorizontalOrigin widens to string without literal asserts.
|
|
1782
|
+
return undefined;
|
|
1783
|
+
}
|
|
1784
|
+
}
|
|
1785
|
+
/**
|
|
1786
|
+
* DML `ST_RelFromV` → w10 `ST_VerticalAnchor` / mso-position-vertical-relative.
|
|
1787
|
+
* margin|page|text(←paragraph)|line. Margin-side variants omitted.
|
|
1788
|
+
*/
|
|
1789
|
+
function mapVerticalOriginToVml(origin) {
|
|
1790
|
+
switch (origin) {
|
|
1791
|
+
case VerticalOrigin.Margin:
|
|
1792
|
+
return 'margin';
|
|
1793
|
+
case VerticalOrigin.Page:
|
|
1794
|
+
return 'page';
|
|
1795
|
+
case VerticalOrigin.Paragraph:
|
|
1796
|
+
// ShapeRequirements: mso-position-vertical-relative:text
|
|
1797
|
+
return 'text';
|
|
1798
|
+
case VerticalOrigin.Line:
|
|
1799
|
+
return 'line';
|
|
1800
|
+
case VerticalOrigin.TopMargin:
|
|
1801
|
+
case VerticalOrigin.BottomMargin:
|
|
1802
|
+
case VerticalOrigin.InsideMargin:
|
|
1803
|
+
case VerticalOrigin.OutsideMargin:
|
|
1804
|
+
case undefined:
|
|
1805
|
+
return undefined;
|
|
1806
|
+
default:
|
|
1807
|
+
// TS 3.3: VerticalOrigin widens to string without literal asserts.
|
|
1808
|
+
return undefined;
|
|
1809
|
+
}
|
|
1810
|
+
}
|
|
1811
|
+
/**
|
|
1812
|
+
* Build VML `style` attribute from modeled layout (ShapeRequirements Fallback pattern).
|
|
1813
|
+
*
|
|
1814
|
+
* Always: width/height in pt.
|
|
1815
|
+
* Anchor: position:absolute; margin-left/top from offsets when modeled; z-index;
|
|
1816
|
+
* visibility:visible; optional mso-wrap-style (square|none only); mso-wrap-distance-*;
|
|
1817
|
+
* mso-position-horizontal/vertical absolute + relative tokens when origins map.
|
|
1818
|
+
* Rotation: CSS `rotation:N` degrees when non-zero (DML rot is 1/60000 deg).
|
|
1819
|
+
* Flip: `flip:x` / `flip:y` / `flip:xy` when modeled (VML style AG_Style).
|
|
1820
|
+
*/
|
|
1821
|
+
function buildVmlShapeStyle(input) {
|
|
1822
|
+
var __ts33_17, __ts33_18;
|
|
1823
|
+
var placement = effectiveDrawingPlacement(input.placement, input.wrapping);
|
|
1824
|
+
var wrapping = effectiveDrawingWrapping(placement, input.wrapping);
|
|
1825
|
+
var parts = [];
|
|
1826
|
+
if (placement === 'anchor') {
|
|
1827
|
+
parts.push('position:absolute');
|
|
1828
|
+
var marginLeft = input.horizontalPositionEmu != null ? input.horizontalPositionEmu : 0;
|
|
1829
|
+
var marginTop = input.verticalPositionEmu != null ? input.verticalPositionEmu : 0;
|
|
1830
|
+
parts.push("margin-left:" + emuToPointsString(marginLeft));
|
|
1831
|
+
parts.push("margin-top:" + emuToPointsString(marginTop));
|
|
1832
|
+
}
|
|
1833
|
+
parts.push("width:" + emuToPointsString(input.widthEmu));
|
|
1834
|
+
parts.push("height:" + emuToPointsString(input.heightEmu));
|
|
1835
|
+
if (placement === 'anchor') {
|
|
1836
|
+
// Default relativeHeight matches buildAnchorHost (251658240).
|
|
1837
|
+
// behindDoc: Word uses negative z-index for behind-text; emit only when true.
|
|
1838
|
+
var zIndex = input.behindDocument === true ? -251658240 : 251658240;
|
|
1839
|
+
parts.push("z-index:" + String(zIndex));
|
|
1840
|
+
parts.push('visibility:visible');
|
|
1841
|
+
var wrapMap = mapWrappingToVmlWrap(wrapping);
|
|
1842
|
+
if (wrapMap.msoWrapStyle !== undefined) {
|
|
1843
|
+
parts.push("mso-wrap-style:" + wrapMap.msoWrapStyle);
|
|
1844
|
+
}
|
|
1845
|
+
// ShapeRequirements connector sample: mso-wrap-distance-left/right 9pt
|
|
1846
|
+
// (= 114300 EMU anchor default); top/bottom 0.
|
|
1847
|
+
var distL = input.distanceLeftEmu != null ? input.distanceLeftEmu : 114300;
|
|
1848
|
+
var distT = input.distanceTopEmu != null ? input.distanceTopEmu : 0;
|
|
1849
|
+
var distR = input.distanceRightEmu != null ? input.distanceRightEmu : 114300;
|
|
1850
|
+
var distB = input.distanceBottomEmu != null ? input.distanceBottomEmu : 0;
|
|
1851
|
+
parts.push("mso-wrap-distance-left:" + emuToCssLengthToken(distL));
|
|
1852
|
+
parts.push("mso-wrap-distance-top:" + emuToCssLengthToken(distT));
|
|
1853
|
+
parts.push("mso-wrap-distance-right:" + emuToCssLengthToken(distR));
|
|
1854
|
+
parts.push("mso-wrap-distance-bottom:" + emuToCssLengthToken(distB));
|
|
1855
|
+
parts.push('mso-position-horizontal:absolute');
|
|
1856
|
+
var hRel = ((__ts33_17 = mapHorizontalOriginToVml(input.horizontalOrigin)), __ts33_17 != null ? __ts33_17 :
|
|
1857
|
+
// Default column → text (ShapeRequirements + images parity default origin).
|
|
1858
|
+
'text');
|
|
1859
|
+
parts.push("mso-position-horizontal-relative:" + hRel);
|
|
1860
|
+
parts.push('mso-position-vertical:absolute');
|
|
1861
|
+
var vRel = ((__ts33_18 = mapVerticalOriginToVml(input.verticalOrigin)), __ts33_18 != null ? __ts33_18 :
|
|
1862
|
+
// Default paragraph → text.
|
|
1863
|
+
'text');
|
|
1864
|
+
parts.push("mso-position-vertical-relative:" + vRel);
|
|
1865
|
+
}
|
|
1866
|
+
var rotation = input.rotation != null ? input.rotation : 0;
|
|
1867
|
+
if (rotation !== 0) {
|
|
1868
|
+
// VML style rotation is degrees (not DML 60000ths).
|
|
1869
|
+
var rounded = Math.round(rotation * 1000) / 1000;
|
|
1870
|
+
parts.push("rotation:" + String(rounded));
|
|
1871
|
+
}
|
|
1872
|
+
var flipH = input.flipHorizontal === true;
|
|
1873
|
+
var flipV = input.flipVertical === true;
|
|
1874
|
+
if (flipH && flipV) {
|
|
1875
|
+
parts.push('flip:xy');
|
|
1876
|
+
}
|
|
1877
|
+
else if (flipH) {
|
|
1878
|
+
parts.push('flip:x');
|
|
1879
|
+
}
|
|
1880
|
+
else if (flipV) {
|
|
1881
|
+
parts.push('flip:y');
|
|
1882
|
+
}
|
|
1883
|
+
// bodyPr spAutoFit → mso-fit-shape-to-text (Word VML textbox autofit).
|
|
1884
|
+
if (input.bodyPr !== undefined) {
|
|
1885
|
+
var hasSpAutoFit = elementChildren(input.bodyPr).some(function (c) { return c.namespaceUri === A_NS && c.localName === 'spAutoFit'; });
|
|
1886
|
+
if (hasSpAutoFit) {
|
|
1887
|
+
parts.push('mso-fit-shape-to-text:t');
|
|
1888
|
+
}
|
|
1889
|
+
}
|
|
1890
|
+
return parts.join(';');
|
|
1891
|
+
}
|
|
1892
|
+
/**
|
|
1893
|
+
* Read bodyPr inset attributes (lIns/tIns/rIns/bIns EMU) into VML `@inset`
|
|
1894
|
+
* string (`left,top,right,bottom` in pt). CT_Textbox `@inset` (vml-main.xsd).
|
|
1895
|
+
* Missing sides default to 0pt so the four-tuple is well-formed when any side
|
|
1896
|
+
* is modeled.
|
|
1897
|
+
*/
|
|
1898
|
+
function bodyPrInsetsToVmlInset(bodyPr) {
|
|
1899
|
+
if (bodyPr === undefined) {
|
|
1900
|
+
return undefined;
|
|
1901
|
+
}
|
|
1902
|
+
var lRaw = attributeValue(bodyPr, '', 'lIns');
|
|
1903
|
+
var tRaw = attributeValue(bodyPr, '', 'tIns');
|
|
1904
|
+
var rRaw = attributeValue(bodyPr, '', 'rIns');
|
|
1905
|
+
var bRaw = attributeValue(bodyPr, '', 'bIns');
|
|
1906
|
+
if (lRaw === undefined && tRaw === undefined && rRaw === undefined && bRaw === undefined) {
|
|
1907
|
+
return undefined;
|
|
1908
|
+
}
|
|
1909
|
+
var parse = function (raw) {
|
|
1910
|
+
if (raw === undefined || raw === '') {
|
|
1911
|
+
return 0;
|
|
1912
|
+
}
|
|
1913
|
+
var n = Number(raw);
|
|
1914
|
+
return (Number.isFinite(n) ? n : 0);
|
|
1915
|
+
};
|
|
1916
|
+
return emuToPointsString(parse(lRaw)) + "," + emuToPointsString(parse(tRaw)) + "," + emuToPointsString(parse(rRaw)) + "," + emuToPointsString(parse(bRaw));
|
|
1917
|
+
}
|
|
1918
|
+
/**
|
|
1919
|
+
* Build `v:stroke` child when line endcap / dash / arrows / joinstyle need emission.
|
|
1920
|
+
* ShapeRequirements always emits `joinstyle="miter"` on stroke for authored shapes;
|
|
1921
|
+
* we emit the child whenever any stroke detail beyond shape-level color/weight is set,
|
|
1922
|
+
* and always include joinstyle=miter when the child is present (corpus pattern).
|
|
1923
|
+
*/
|
|
1924
|
+
function buildVmlStrokeChild(input) {
|
|
1925
|
+
var line = input.line;
|
|
1926
|
+
if (line === undefined) {
|
|
1927
|
+
return undefined;
|
|
1928
|
+
}
|
|
1929
|
+
var strokeAttrs = [];
|
|
1930
|
+
if (line.kind === 'none') {
|
|
1931
|
+
// AG_StrokeAttributes `@on` — turn stroke off (pairs with shape stroked="f").
|
|
1932
|
+
strokeAttrs.push(attr('on', 'f'));
|
|
1933
|
+
}
|
|
1934
|
+
else {
|
|
1935
|
+
var endcap = mapLineCapToVmlEndcap(line.cap);
|
|
1936
|
+
if (endcap !== undefined) {
|
|
1937
|
+
strokeAttrs.push(attr('endcap', endcap));
|
|
1938
|
+
}
|
|
1939
|
+
var dashstyle = mapLineDashingToVml(line.dash);
|
|
1940
|
+
if (dashstyle !== undefined && dashstyle !== 'solid') {
|
|
1941
|
+
// solid is the default; omit rather than noise.
|
|
1942
|
+
strokeAttrs.push(attr('dashstyle', dashstyle));
|
|
1943
|
+
}
|
|
1944
|
+
if (line.widthEmu !== undefined) {
|
|
1945
|
+
strokeAttrs.push(attr('weight', emuToPointsString(line.widthEmu)));
|
|
1946
|
+
}
|
|
1947
|
+
var color = srgbToVmlColor(line.srgb);
|
|
1948
|
+
if (color !== undefined) {
|
|
1949
|
+
strokeAttrs.push(attr('color', color));
|
|
1950
|
+
}
|
|
1951
|
+
var startArrow = mapLineEndTypeToVmlArrow(line.beginArrowType);
|
|
1952
|
+
if (startArrow !== undefined && startArrow !== 'none') {
|
|
1953
|
+
strokeAttrs.push(attr('startarrow', startArrow));
|
|
1954
|
+
var sw = mapLineEndSizeToVmlWidth(line.beginArrowSize);
|
|
1955
|
+
var sl = mapLineEndSizeToVmlLength(line.beginArrowSize);
|
|
1956
|
+
if (sw !== undefined) {
|
|
1957
|
+
strokeAttrs.push(attr('startarrowwidth', sw));
|
|
1958
|
+
}
|
|
1959
|
+
if (sl !== undefined) {
|
|
1960
|
+
strokeAttrs.push(attr('startarrowlength', sl));
|
|
1961
|
+
}
|
|
1962
|
+
}
|
|
1963
|
+
var endArrow = mapLineEndTypeToVmlArrow(line.endArrowType);
|
|
1964
|
+
if (endArrow !== undefined && endArrow !== 'none') {
|
|
1965
|
+
// ShapeRequirements connector: endarrow="block" (DML triangle).
|
|
1966
|
+
strokeAttrs.push(attr('endarrow', endArrow));
|
|
1967
|
+
var ew = mapLineEndSizeToVmlWidth(line.endArrowSize);
|
|
1968
|
+
var el = mapLineEndSizeToVmlLength(line.endArrowSize);
|
|
1969
|
+
if (ew !== undefined) {
|
|
1970
|
+
strokeAttrs.push(attr('endarrowwidth', ew));
|
|
1971
|
+
}
|
|
1972
|
+
if (el !== undefined) {
|
|
1973
|
+
strokeAttrs.push(attr('endarrowlength', el));
|
|
1974
|
+
}
|
|
1975
|
+
}
|
|
1976
|
+
}
|
|
1977
|
+
// Emit child when we have any stroke detail, or always for solid/none so
|
|
1978
|
+
// joinstyle miter matches ShapeRequirements Fallback samples.
|
|
1979
|
+
strokeAttrs.push(attr('joinstyle', 'miter'));
|
|
1980
|
+
return xmlElement(VML_NS, 'v', 'stroke', { attributes: strokeAttrs });
|
|
1981
|
+
}
|
|
1982
|
+
/**
|
|
1983
|
+
* Corpus-backed VML Fallback pict tree (Policy B dual AC — TASK-8050).
|
|
1984
|
+
*
|
|
1985
|
+
* Emits `w:pict` > `v:shape` with style, fill/stroke attrs, optional `v:stroke`,
|
|
1986
|
+
* `w10:wrap` / `w10:anchorlock`, and `v:textbox` (cloned txbxContent) when modeled.
|
|
1987
|
+
* Does not invent shapetype paths or execute VML.
|
|
1988
|
+
*
|
|
1989
|
+
* @private
|
|
1990
|
+
*/
|
|
1991
|
+
export function buildVmlFallbackStub(input) {
|
|
1992
|
+
var placement = effectiveDrawingPlacement(input.placement, input.wrapping);
|
|
1993
|
+
var wrapping = effectiveDrawingWrapping(placement, input.wrapping);
|
|
1994
|
+
var shapeAttrs = [
|
|
1995
|
+
attr('style', buildVmlShapeStyle(input)),
|
|
1996
|
+
attr('id', "Shape" + String(input.docPrId)),
|
|
1997
|
+
];
|
|
1998
|
+
// AG_Fill: filled / fillcolor (vml-main.xsd).
|
|
1999
|
+
if (input.fill !== undefined) {
|
|
2000
|
+
if (input.fill.kind === 'none') {
|
|
2001
|
+
shapeAttrs.push(attr('filled', 'f'));
|
|
2002
|
+
}
|
|
2003
|
+
else {
|
|
2004
|
+
var color = srgbToVmlColor(input.fill.srgb);
|
|
2005
|
+
if (color !== undefined) {
|
|
2006
|
+
shapeAttrs.push(attr('filled', 't'));
|
|
2007
|
+
shapeAttrs.push(attr('fillcolor', color));
|
|
2008
|
+
}
|
|
2009
|
+
}
|
|
2010
|
+
}
|
|
2011
|
+
// AG_ShapeAttributes: stroked / strokecolor / strokeweight.
|
|
2012
|
+
if (input.line !== undefined) {
|
|
2013
|
+
if (input.line.kind === 'none') {
|
|
2014
|
+
shapeAttrs.push(attr('stroked', 'f'));
|
|
2015
|
+
}
|
|
2016
|
+
else {
|
|
2017
|
+
shapeAttrs.push(attr('stroked', 't'));
|
|
2018
|
+
var color = srgbToVmlColor(input.line.srgb);
|
|
2019
|
+
if (color !== undefined) {
|
|
2020
|
+
shapeAttrs.push(attr('strokecolor', color));
|
|
2021
|
+
}
|
|
2022
|
+
if (input.line.widthEmu !== undefined) {
|
|
2023
|
+
shapeAttrs.push(attr('strokeweight', emuToPointsString(input.line.widthEmu)));
|
|
2024
|
+
}
|
|
2025
|
+
}
|
|
2026
|
+
}
|
|
2027
|
+
var children = [];
|
|
2028
|
+
// v:fill opacity when solid fill has non-opaque transparency (public t = 100 - opacity%).
|
|
2029
|
+
if (input.fill !== undefined && input.fill.kind === 'solid') {
|
|
2030
|
+
var solidFill = input.fill;
|
|
2031
|
+
if (solidFill.alpha !== undefined) {
|
|
2032
|
+
var publicTransparency = Math.round(100 - solidFill.alpha / 1000);
|
|
2033
|
+
if (publicTransparency > 0 && publicTransparency <= 100) {
|
|
2034
|
+
var fillColor = srgbToVmlColor(solidFill.srgb);
|
|
2035
|
+
var fillAttrs = [];
|
|
2036
|
+
if (fillColor !== undefined) {
|
|
2037
|
+
fillAttrs.push(attr('color', fillColor));
|
|
2038
|
+
}
|
|
2039
|
+
fillAttrs.push(attr('opacity', String(100 - publicTransparency) + '%'));
|
|
2040
|
+
children.push(xmlElement(VML_NS, 'v', 'fill', { attributes: fillAttrs }));
|
|
2041
|
+
}
|
|
2042
|
+
}
|
|
2043
|
+
}
|
|
2044
|
+
var strokeChild = buildVmlStrokeChild(input);
|
|
2045
|
+
if (strokeChild !== undefined) {
|
|
2046
|
+
children.push(strokeChild);
|
|
2047
|
+
}
|
|
2048
|
+
// w10:wrap — ST_WrapType from vml-wordprocessingDrawing.xsd.
|
|
2049
|
+
var wrapMap = mapWrappingToVmlWrap(wrapping);
|
|
2050
|
+
var needsW10 = false;
|
|
2051
|
+
if (placement === 'anchor' && wrapMap.w10Type !== undefined) {
|
|
2052
|
+
var wrapAttrs = [attr('type', wrapMap.w10Type)];
|
|
2053
|
+
var anchorx = mapHorizontalOriginToVml(input.horizontalOrigin);
|
|
2054
|
+
var anchory = mapVerticalOriginToVml(input.verticalOrigin);
|
|
2055
|
+
if (anchorx !== undefined) {
|
|
2056
|
+
wrapAttrs.push(attr('anchorx', anchorx));
|
|
2057
|
+
}
|
|
2058
|
+
if (anchory !== undefined) {
|
|
2059
|
+
wrapAttrs.push(attr('anchory', anchory));
|
|
2060
|
+
}
|
|
2061
|
+
children.push(xmlElement(W10_NS, 'w10', 'wrap', {
|
|
2062
|
+
attributes: wrapAttrs,
|
|
2063
|
+
}));
|
|
2064
|
+
needsW10 = true;
|
|
2065
|
+
}
|
|
2066
|
+
// w10:anchorlock — empty CT when lockAnchor (vml-wordprocessingDrawing.xsd).
|
|
2067
|
+
if (placement === 'anchor' && input.lockAnchor === true) {
|
|
2068
|
+
children.push(xmlElement(W10_NS, 'w10', 'anchorlock', {}));
|
|
2069
|
+
needsW10 = true;
|
|
2070
|
+
}
|
|
2071
|
+
// v:textbox — CT_Textbox with optional @inset + w:txbxContent children.
|
|
2072
|
+
// Dual-write text box body into Fallback when txbxContent is modeled (Policy B).
|
|
2073
|
+
if (input.txbxContent !== undefined) {
|
|
2074
|
+
var textboxAttrs = [];
|
|
2075
|
+
var inset = bodyPrInsetsToVmlInset(input.bodyPr);
|
|
2076
|
+
if (inset !== undefined) {
|
|
2077
|
+
textboxAttrs.push(attr('inset', inset));
|
|
2078
|
+
}
|
|
2079
|
+
var txbxChildren = input.txbxContent.map(function (c) { return cloneElement(c); });
|
|
2080
|
+
// CT_Textbox allows w:txbxContent; wrap cloned block children in w:txbxContent
|
|
2081
|
+
// when the payload is raw body blocks (encode path passes txbxContent element
|
|
2082
|
+
// children — typically already the inner blocks, or a single txbxContent).
|
|
2083
|
+
// Prefer a single w:txbxContent wrapper when children are not already one.
|
|
2084
|
+
var textboxChildEls = void 0;
|
|
2085
|
+
if (txbxChildren.length === 1 &&
|
|
2086
|
+
txbxChildren[0] !== undefined &&
|
|
2087
|
+
isWml(txbxChildren[0], 'txbxContent')) {
|
|
2088
|
+
textboxChildEls = txbxChildren;
|
|
2089
|
+
}
|
|
2090
|
+
else {
|
|
2091
|
+
textboxChildEls = [wmlElement('txbxContent', { children: txbxChildren })];
|
|
2092
|
+
}
|
|
2093
|
+
children.push(xmlElement(VML_NS, 'v', 'textbox', {
|
|
2094
|
+
attributes: textboxAttrs,
|
|
2095
|
+
children: textboxChildEls,
|
|
2096
|
+
}));
|
|
2097
|
+
}
|
|
2098
|
+
var namespaceDeclarations = [{ prefix: 'v', namespaceUri: VML_NS }];
|
|
2099
|
+
if (needsW10) {
|
|
2100
|
+
namespaceDeclarations.push({ prefix: 'w10', namespaceUri: W10_NS });
|
|
2101
|
+
}
|
|
2102
|
+
var shape = xmlElement(VML_NS, 'v', 'shape', {
|
|
2103
|
+
attributes: shapeAttrs,
|
|
2104
|
+
children: children,
|
|
2105
|
+
});
|
|
2106
|
+
return wmlElement('pict', {
|
|
2107
|
+
namespaceDeclarations: namespaceDeclarations,
|
|
2108
|
+
children: [shape],
|
|
2109
|
+
});
|
|
2110
|
+
}
|
|
2111
|
+
/**
|
|
2112
|
+
* Build `w:drawing` with `wp:inline` or `wp:anchor` host (Choice body only).
|
|
2113
|
+
* Wrapping drives host kind: Inline ⇒ inline; other styles ⇒ anchor.
|
|
2114
|
+
*
|
|
2115
|
+
* @private
|
|
2116
|
+
*/
|
|
2117
|
+
export function buildDrawingMlHost(input) {
|
|
2118
|
+
var placement = effectiveDrawingPlacement(input.placement, input.wrapping);
|
|
2119
|
+
var wrapping = effectiveDrawingWrapping(placement, input.wrapping);
|
|
2120
|
+
var resolved = __assign({}, input, { placement: placement,
|
|
2121
|
+
wrapping: wrapping });
|
|
2122
|
+
var host = placement === 'inline' ? buildInlineHost(resolved) : buildAnchorHost(resolved);
|
|
2123
|
+
return wmlElement('drawing', { children: [host] });
|
|
2124
|
+
}
|
|
2125
|
+
/**
|
|
2126
|
+
* Author dual AC root: Choice(wps DrawingML) + Fallback(VML pict tree).
|
|
2127
|
+
* Policy B (GO Q2/Q3/Q7) — TASK-8050 corpus-backed VML Fallback.
|
|
2128
|
+
*
|
|
2129
|
+
* @private
|
|
2130
|
+
*/
|
|
2131
|
+
export function encodeAuthoredDrawingShape(input) {
|
|
2132
|
+
var drawing = buildDrawingMlHost(input);
|
|
2133
|
+
var fallback = buildVmlFallbackStub(input);
|
|
2134
|
+
// ECMA-376-3 §7.6: Choice @Requires prefixes must be bound in scope.
|
|
2135
|
+
// Declare xmlns:wps (and supporting prefixes) on AlternateContent so
|
|
2136
|
+
// Requires="wps" resolves before Choice descends into w:drawing.
|
|
2137
|
+
// xmlns:w10 is always declared so anchor Fallback w10:wrap / w10:anchorlock
|
|
2138
|
+
// resolve under Fallback without inventing undeclared prefixes (vml-wordprocessingDrawing.xsd).
|
|
2139
|
+
return xmlElement(MC_NS, 'mc', 'AlternateContent', {
|
|
2140
|
+
namespaceDeclarations: [
|
|
2141
|
+
{ prefix: 'mc', namespaceUri: MC_NS },
|
|
2142
|
+
{ prefix: 'wps', namespaceUri: WPS_NS },
|
|
2143
|
+
{ prefix: 'wp', namespaceUri: WP_NS },
|
|
2144
|
+
{ prefix: 'a', namespaceUri: A_NS },
|
|
2145
|
+
{ prefix: 'v', namespaceUri: VML_NS },
|
|
2146
|
+
{ prefix: 'w10', namespaceUri: W10_NS },
|
|
2147
|
+
],
|
|
2148
|
+
children: [
|
|
2149
|
+
xmlElement(MC_NS, 'mc', 'Choice', {
|
|
2150
|
+
attributes: [attr('Requires', 'wps')],
|
|
2151
|
+
children: [drawing],
|
|
2152
|
+
}),
|
|
2153
|
+
xmlElement(MC_NS, 'mc', 'Fallback', {
|
|
2154
|
+
children: [fallback],
|
|
2155
|
+
}),
|
|
2156
|
+
],
|
|
2157
|
+
});
|
|
2158
|
+
}
|
|
2159
|
+
/**
|
|
2160
|
+
* Author dual AC root for a wordprocessing group: Choice(wpg DrawingML) +
|
|
2161
|
+
* Fallback(VML pict stub). Policy B — TASK-8051.
|
|
2162
|
+
*
|
|
2163
|
+
* Top-level graphicData uri = WPG; body is `wpg:wgp` without cNvPr.
|
|
2164
|
+
* xmlns:wpg is declared on AlternateContent so Requires="wpg" resolves;
|
|
2165
|
+
* xmlns:wps is kept so nested authored `wps:wsp` children resolve.
|
|
2166
|
+
*
|
|
2167
|
+
* @private
|
|
2168
|
+
*/
|
|
2169
|
+
export function encodeAuthoredGroup(input) {
|
|
2170
|
+
// Reuse the leaf host builders via EncodeDrawingShapeInput + groupChildElements.
|
|
2171
|
+
// presetGeometry is a VML-fallback stub placeholder only (not written to DML).
|
|
2172
|
+
// TS 3.3: nested conditional object spreads explode the checker (OOM).
|
|
2173
|
+
// Mutable assigns only when defined — same exactOptionalPropertyTypes semantics.
|
|
2174
|
+
var shapeLikeMutable = {
|
|
2175
|
+
placement: input.placement,
|
|
2176
|
+
widthEmu: input.widthEmu,
|
|
2177
|
+
heightEmu: input.heightEmu,
|
|
2178
|
+
presetGeometry: 'rect',
|
|
2179
|
+
docPrId: input.docPrId,
|
|
2180
|
+
name: input.name,
|
|
2181
|
+
title: input.title,
|
|
2182
|
+
description: input.description,
|
|
2183
|
+
groupChildElements: input.children,
|
|
2184
|
+
};
|
|
2185
|
+
if (input.rotation !== undefined) {
|
|
2186
|
+
shapeLikeMutable.rotation = input.rotation;
|
|
2187
|
+
}
|
|
2188
|
+
if (input.flipHorizontal !== undefined) {
|
|
2189
|
+
shapeLikeMutable.flipHorizontal = input.flipHorizontal;
|
|
2190
|
+
}
|
|
2191
|
+
if (input.flipVertical !== undefined) {
|
|
2192
|
+
shapeLikeMutable.flipVertical = input.flipVertical;
|
|
2193
|
+
}
|
|
2194
|
+
if (input.lockAspectRatio !== undefined) {
|
|
2195
|
+
shapeLikeMutable.lockAspectRatio = input.lockAspectRatio;
|
|
2196
|
+
}
|
|
2197
|
+
if (input.wrapping !== undefined) {
|
|
2198
|
+
shapeLikeMutable.wrapping = input.wrapping;
|
|
2199
|
+
}
|
|
2200
|
+
if (input.distanceTopEmu !== undefined) {
|
|
2201
|
+
shapeLikeMutable.distanceTopEmu = input.distanceTopEmu;
|
|
2202
|
+
}
|
|
2203
|
+
if (input.distanceBottomEmu !== undefined) {
|
|
2204
|
+
shapeLikeMutable.distanceBottomEmu = input.distanceBottomEmu;
|
|
2205
|
+
}
|
|
2206
|
+
if (input.distanceLeftEmu !== undefined) {
|
|
2207
|
+
shapeLikeMutable.distanceLeftEmu = input.distanceLeftEmu;
|
|
2208
|
+
}
|
|
2209
|
+
if (input.distanceRightEmu !== undefined) {
|
|
2210
|
+
shapeLikeMutable.distanceRightEmu = input.distanceRightEmu;
|
|
2211
|
+
}
|
|
2212
|
+
if (input.behindDocument !== undefined) {
|
|
2213
|
+
shapeLikeMutable.behindDocument = input.behindDocument;
|
|
2214
|
+
}
|
|
2215
|
+
if (input.horizontalOrigin !== undefined) {
|
|
2216
|
+
shapeLikeMutable.horizontalOrigin = input.horizontalOrigin;
|
|
2217
|
+
}
|
|
2218
|
+
if (input.verticalOrigin !== undefined) {
|
|
2219
|
+
shapeLikeMutable.verticalOrigin = input.verticalOrigin;
|
|
2220
|
+
}
|
|
2221
|
+
if (input.horizontalPositionEmu !== undefined) {
|
|
2222
|
+
shapeLikeMutable.horizontalPositionEmu = input.horizontalPositionEmu;
|
|
2223
|
+
}
|
|
2224
|
+
if (input.verticalPositionEmu !== undefined) {
|
|
2225
|
+
shapeLikeMutable.verticalPositionEmu = input.verticalPositionEmu;
|
|
2226
|
+
}
|
|
2227
|
+
if (input.horizontalAlignment !== undefined) {
|
|
2228
|
+
shapeLikeMutable.horizontalAlignment = input.horizontalAlignment;
|
|
2229
|
+
}
|
|
2230
|
+
if (input.verticalAlignment !== undefined) {
|
|
2231
|
+
shapeLikeMutable.verticalAlignment = input.verticalAlignment;
|
|
2232
|
+
}
|
|
2233
|
+
if (input.lockAnchor !== undefined) {
|
|
2234
|
+
shapeLikeMutable.lockAnchor = input.lockAnchor;
|
|
2235
|
+
}
|
|
2236
|
+
if (input.allowOverlap !== undefined) {
|
|
2237
|
+
shapeLikeMutable.allowOverlap = input.allowOverlap;
|
|
2238
|
+
}
|
|
2239
|
+
if (input.layoutInCell !== undefined) {
|
|
2240
|
+
shapeLikeMutable.layoutInCell = input.layoutInCell;
|
|
2241
|
+
}
|
|
2242
|
+
if (input.horizontalModeled !== undefined) {
|
|
2243
|
+
shapeLikeMutable.horizontalModeled = input.horizontalModeled;
|
|
2244
|
+
}
|
|
2245
|
+
if (input.verticalModeled !== undefined) {
|
|
2246
|
+
shapeLikeMutable.verticalModeled = input.verticalModeled;
|
|
2247
|
+
}
|
|
2248
|
+
if (input.preservedHost !== undefined) {
|
|
2249
|
+
shapeLikeMutable.preservedHost = input.preservedHost;
|
|
2250
|
+
}
|
|
2251
|
+
if (input.layoutDirty !== undefined) {
|
|
2252
|
+
shapeLikeMutable.layoutDirty = input.layoutDirty;
|
|
2253
|
+
}
|
|
2254
|
+
var shapeLike = shapeLikeMutable;
|
|
2255
|
+
var drawing = buildDrawingMlHost(shapeLike);
|
|
2256
|
+
var fallback = buildVmlFallbackStub(shapeLike);
|
|
2257
|
+
return xmlElement(MC_NS, 'mc', 'AlternateContent', {
|
|
2258
|
+
namespaceDeclarations: [
|
|
2259
|
+
{ prefix: 'mc', namespaceUri: MC_NS },
|
|
2260
|
+
{ prefix: 'wpg', namespaceUri: WPG_NS },
|
|
2261
|
+
{ prefix: 'wps', namespaceUri: WPS_NS },
|
|
2262
|
+
{ prefix: 'wp', namespaceUri: WP_NS },
|
|
2263
|
+
{ prefix: 'a', namespaceUri: A_NS },
|
|
2264
|
+
{ prefix: 'v', namespaceUri: VML_NS },
|
|
2265
|
+
{ prefix: 'w10', namespaceUri: W10_NS },
|
|
2266
|
+
],
|
|
2267
|
+
children: [
|
|
2268
|
+
xmlElement(MC_NS, 'mc', 'Choice', {
|
|
2269
|
+
attributes: [attr('Requires', 'wpg')],
|
|
2270
|
+
children: [drawing],
|
|
2271
|
+
}),
|
|
2272
|
+
xmlElement(MC_NS, 'mc', 'Fallback', {
|
|
2273
|
+
children: [fallback],
|
|
2274
|
+
}),
|
|
2275
|
+
],
|
|
2276
|
+
});
|
|
2277
|
+
}
|
|
2278
|
+
/**
|
|
2279
|
+
* Locate preferred DrawingML `w:drawing` for typed reads.
|
|
2280
|
+
* Prefer MC Choice branch when residual is AlternateContent.
|
|
2281
|
+
*
|
|
2282
|
+
* @private
|
|
2283
|
+
*/
|
|
2284
|
+
export function preferredDrawingElement(root) {
|
|
2285
|
+
var e_12, _a, e_13, _b;
|
|
2286
|
+
if (isWml(root, 'drawing')) {
|
|
2287
|
+
return root;
|
|
2288
|
+
}
|
|
2289
|
+
if (root.namespaceUri === MC_NS && root.localName === 'AlternateContent') {
|
|
2290
|
+
try {
|
|
2291
|
+
for (var _c = __values(elementChildren(root)), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
2292
|
+
var child = _d.value;
|
|
2293
|
+
if (child.namespaceUri !== MC_NS || child.localName !== 'Choice') {
|
|
2294
|
+
continue;
|
|
2295
|
+
}
|
|
2296
|
+
try {
|
|
2297
|
+
for (var _e = __values(elementChildren(child)), _f = _e.next(); !_f.done; _f = _e.next()) {
|
|
2298
|
+
var nested = _f.value;
|
|
2299
|
+
if (isWml(nested, 'drawing')) {
|
|
2300
|
+
return nested;
|
|
2301
|
+
}
|
|
2302
|
+
}
|
|
2303
|
+
}
|
|
2304
|
+
catch (e_13_1) { e_13 = { error: e_13_1 }; }
|
|
2305
|
+
finally {
|
|
2306
|
+
try {
|
|
2307
|
+
if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
|
|
2308
|
+
}
|
|
2309
|
+
finally { if (e_13) throw e_13.error; }
|
|
2310
|
+
}
|
|
2311
|
+
}
|
|
2312
|
+
}
|
|
2313
|
+
catch (e_12_1) { e_12 = { error: e_12_1 }; }
|
|
2314
|
+
finally {
|
|
2315
|
+
try {
|
|
2316
|
+
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
|
|
2317
|
+
}
|
|
2318
|
+
finally { if (e_12) throw e_12.error; }
|
|
2319
|
+
}
|
|
2320
|
+
// No Choice drawing — last resort scan.
|
|
2321
|
+
return findFirstElement(root, root.namespaceUri, 'drawing') !== undefined
|
|
2322
|
+
? undefined
|
|
2323
|
+
: (function () {
|
|
2324
|
+
var e_14, _a;
|
|
2325
|
+
try {
|
|
2326
|
+
for (var _b = __values(elementChildren(root)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
2327
|
+
var child = _c.value;
|
|
2328
|
+
var d = preferredDrawingElement(child);
|
|
2329
|
+
if (d !== undefined) {
|
|
2330
|
+
return d;
|
|
2331
|
+
}
|
|
2332
|
+
if (isWml(child, 'drawing')) {
|
|
2333
|
+
return child;
|
|
2334
|
+
}
|
|
2335
|
+
}
|
|
2336
|
+
}
|
|
2337
|
+
catch (e_14_1) { e_14 = { error: e_14_1 }; }
|
|
2338
|
+
finally {
|
|
2339
|
+
try {
|
|
2340
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
2341
|
+
}
|
|
2342
|
+
finally { if (e_14) throw e_14.error; }
|
|
2343
|
+
}
|
|
2344
|
+
return undefined;
|
|
2345
|
+
})();
|
|
2346
|
+
}
|
|
2347
|
+
return undefined;
|
|
2348
|
+
}
|
|
2349
|
+
/**
|
|
2350
|
+
* Read `wp:docPr` identity from preferred drawing host.
|
|
2351
|
+
*
|
|
2352
|
+
* @private
|
|
2353
|
+
*/
|
|
2354
|
+
export function readDocPrIdentity(root) {
|
|
2355
|
+
var __ts33_19;
|
|
2356
|
+
var drawing = ((__ts33_19 = preferredDrawingElement(root)), __ts33_19 != null ? __ts33_19 : (isWml(root, 'drawing') ? root : undefined));
|
|
2357
|
+
if (drawing === undefined) {
|
|
2358
|
+
return { name: undefined, title: undefined, description: undefined, docPrId: undefined };
|
|
2359
|
+
}
|
|
2360
|
+
var inline = findFirstElement(drawing, WP_NS, 'inline');
|
|
2361
|
+
var anchor = findFirstElement(drawing, WP_NS, 'anchor');
|
|
2362
|
+
var host = inline != null ? inline : anchor;
|
|
2363
|
+
if (host === undefined) {
|
|
2364
|
+
return { name: undefined, title: undefined, description: undefined, docPrId: undefined };
|
|
2365
|
+
}
|
|
2366
|
+
var docPr = findFirstElement(host, WP_NS, 'docPr');
|
|
2367
|
+
if (docPr === undefined) {
|
|
2368
|
+
return { name: undefined, title: undefined, description: undefined, docPrId: undefined };
|
|
2369
|
+
}
|
|
2370
|
+
var idRaw = attributeValue(docPr, '', 'id');
|
|
2371
|
+
var idParsed = idRaw !== undefined && /^\d+$/.test(idRaw) ? Number.parseInt(idRaw, 10) : undefined;
|
|
2372
|
+
var name = attributeValue(docPr, '', 'name');
|
|
2373
|
+
var title = attributeValue(docPr, '', 'title');
|
|
2374
|
+
var descr = attributeValue(docPr, '', 'descr');
|
|
2375
|
+
return {
|
|
2376
|
+
name: name !== undefined && name.length > 0 ? name : undefined,
|
|
2377
|
+
title: title !== undefined && title.length > 0 ? title : undefined,
|
|
2378
|
+
description: descr !== undefined && descr.length > 0 ? descr : undefined,
|
|
2379
|
+
docPrId: idParsed,
|
|
2380
|
+
};
|
|
2381
|
+
}
|
|
2382
|
+
function patchDocPrOnElement(docPr, identity) {
|
|
2383
|
+
var e_15, _a;
|
|
2384
|
+
var next = [];
|
|
2385
|
+
var sawId = false;
|
|
2386
|
+
var sawName = false;
|
|
2387
|
+
var sawTitle = false;
|
|
2388
|
+
var sawDescr = false;
|
|
2389
|
+
try {
|
|
2390
|
+
for (var _b = __values(docPr.attributes), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
2391
|
+
var a = _c.value;
|
|
2392
|
+
if (a.namespaceUri !== '') {
|
|
2393
|
+
next.push(a);
|
|
2394
|
+
continue;
|
|
2395
|
+
}
|
|
2396
|
+
if (a.localName === 'id') {
|
|
2397
|
+
sawId = true;
|
|
2398
|
+
if (identity.docPrId !== undefined) {
|
|
2399
|
+
next.push(attr('id', String(identity.docPrId)));
|
|
2400
|
+
}
|
|
2401
|
+
else {
|
|
2402
|
+
next.push(a);
|
|
2403
|
+
}
|
|
2404
|
+
continue;
|
|
2405
|
+
}
|
|
2406
|
+
if (a.localName === 'name') {
|
|
2407
|
+
sawName = true;
|
|
2408
|
+
if (identity.name !== undefined) {
|
|
2409
|
+
next.push(attr('name', identity.name));
|
|
2410
|
+
}
|
|
2411
|
+
else {
|
|
2412
|
+
// Clearing name is not typical; keep residual when undefined means "no override".
|
|
2413
|
+
// Callers always pass concrete name when dirty from mutators.
|
|
2414
|
+
next.push(a);
|
|
2415
|
+
}
|
|
2416
|
+
continue;
|
|
2417
|
+
}
|
|
2418
|
+
if (a.localName === 'title') {
|
|
2419
|
+
sawTitle = true;
|
|
2420
|
+
if (identity.title === undefined) {
|
|
2421
|
+
continue;
|
|
2422
|
+
}
|
|
2423
|
+
next.push(attr('title', identity.title));
|
|
2424
|
+
continue;
|
|
2425
|
+
}
|
|
2426
|
+
if (a.localName === 'descr') {
|
|
2427
|
+
sawDescr = true;
|
|
2428
|
+
if (identity.description === undefined) {
|
|
2429
|
+
continue;
|
|
2430
|
+
}
|
|
2431
|
+
next.push(attr('descr', identity.description));
|
|
2432
|
+
continue;
|
|
2433
|
+
}
|
|
2434
|
+
next.push(a);
|
|
2435
|
+
}
|
|
2436
|
+
}
|
|
2437
|
+
catch (e_15_1) { e_15 = { error: e_15_1 }; }
|
|
2438
|
+
finally {
|
|
2439
|
+
try {
|
|
2440
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
2441
|
+
}
|
|
2442
|
+
finally { if (e_15) throw e_15.error; }
|
|
2443
|
+
}
|
|
2444
|
+
if (!sawId && identity.docPrId !== undefined) {
|
|
2445
|
+
next.unshift(attr('id', String(identity.docPrId)));
|
|
2446
|
+
}
|
|
2447
|
+
if (!sawName && identity.name !== undefined) {
|
|
2448
|
+
next.push(attr('name', identity.name));
|
|
2449
|
+
}
|
|
2450
|
+
if (!sawTitle && identity.title !== undefined && identity.title.length > 0) {
|
|
2451
|
+
next.push(attr('title', identity.title));
|
|
2452
|
+
}
|
|
2453
|
+
if (!sawDescr && identity.description !== undefined && identity.description.length > 0) {
|
|
2454
|
+
next.push(attr('descr', identity.description));
|
|
2455
|
+
}
|
|
2456
|
+
// Mutate in place on the clone's docPr via replacement — OpenXmlElement.attributes is readonly
|
|
2457
|
+
// in type but we rebuild parent instead. Use object replace:
|
|
2458
|
+
docPr.attributes = next;
|
|
2459
|
+
}
|
|
2460
|
+
/**
|
|
2461
|
+
* Deep-clone residual and patch `wp:docPr` identity attributes only (identity dirty).
|
|
2462
|
+
*
|
|
2463
|
+
* @private
|
|
2464
|
+
*/
|
|
2465
|
+
export function patchResidualDocPr(residual, identity) {
|
|
2466
|
+
var __ts33_20;
|
|
2467
|
+
var cloned = cloneElement(residual);
|
|
2468
|
+
var drawing = ((__ts33_20 = preferredDrawingElement(cloned)), __ts33_20 != null ? __ts33_20 : (isWml(cloned, 'drawing') ? cloned : undefined));
|
|
2469
|
+
if (drawing === undefined) {
|
|
2470
|
+
return cloned;
|
|
2471
|
+
}
|
|
2472
|
+
var inline = findFirstElement(drawing, WP_NS, 'inline');
|
|
2473
|
+
var anchor = findFirstElement(drawing, WP_NS, 'anchor');
|
|
2474
|
+
var host = inline != null ? inline : anchor;
|
|
2475
|
+
if (host === undefined) {
|
|
2476
|
+
return cloned;
|
|
2477
|
+
}
|
|
2478
|
+
var docPr = findFirstElement(host, WP_NS, 'docPr');
|
|
2479
|
+
if (docPr === undefined) {
|
|
2480
|
+
return cloned;
|
|
2481
|
+
}
|
|
2482
|
+
patchDocPrOnElement(docPr, identity);
|
|
2483
|
+
return cloned;
|
|
2484
|
+
}
|
|
2485
|
+
/**
|
|
2486
|
+
* Deep-clone residual and patch layout: `wp:extent`, `a:xfrm` (rot/flip/ext),
|
|
2487
|
+
* `a:graphicFrameLocks/@noChangeAspect`, and optional `wp:docPr` identity.
|
|
2488
|
+
* Preserves `wp:effectExtent` and other unmodeled siblings (layout dirty path).
|
|
2489
|
+
*
|
|
2490
|
+
* @private
|
|
2491
|
+
*/
|
|
2492
|
+
export function patchResidualLayout(residual, layout) {
|
|
2493
|
+
var __ts33_21;
|
|
2494
|
+
var cloned = cloneElement(residual);
|
|
2495
|
+
var drawing = ((__ts33_21 = preferredDrawingElement(cloned)), __ts33_21 != null ? __ts33_21 : (isWml(cloned, 'drawing') ? cloned : undefined));
|
|
2496
|
+
if (drawing === undefined) {
|
|
2497
|
+
return cloned;
|
|
2498
|
+
}
|
|
2499
|
+
var host = preferHost(drawing);
|
|
2500
|
+
if (host === undefined) {
|
|
2501
|
+
return cloned;
|
|
2502
|
+
}
|
|
2503
|
+
var extentEl = findFirstElement(host, WP_NS, 'extent');
|
|
2504
|
+
if (extentEl !== undefined) {
|
|
2505
|
+
setExtentAttrs(extentEl, layout.widthEmu, layout.heightEmu);
|
|
2506
|
+
}
|
|
2507
|
+
else {
|
|
2508
|
+
var extent = xmlElement(WP_NS, 'wp', 'extent', {
|
|
2509
|
+
attributes: [attr('cx', String(layout.widthEmu)), attr('cy', String(layout.heightEmu))],
|
|
2510
|
+
});
|
|
2511
|
+
var children = __spread(host.children);
|
|
2512
|
+
// Prefer before effectExtent / wrap / docPr when possible.
|
|
2513
|
+
var insertAt = children.findIndex(function (c) { return c.kind === 'element' &&
|
|
2514
|
+
(isElement(c, WP_NS, 'effectExtent') ||
|
|
2515
|
+
isElement(c, WP_NS, 'docPr') ||
|
|
2516
|
+
c.localName.startsWith('wrap')); });
|
|
2517
|
+
if (insertAt >= 0) {
|
|
2518
|
+
children.splice(insertAt, 0, extent);
|
|
2519
|
+
}
|
|
2520
|
+
else {
|
|
2521
|
+
children.unshift(extent);
|
|
2522
|
+
}
|
|
2523
|
+
host.children = children;
|
|
2524
|
+
}
|
|
2525
|
+
ensureXfrmOnSpPr(drawing, layout);
|
|
2526
|
+
patchCNvGraphicFramePr(host, layout.lockAspectRatio);
|
|
2527
|
+
var docPr = findFirstElement(host, WP_NS, 'docPr');
|
|
2528
|
+
if (docPr !== undefined) {
|
|
2529
|
+
patchDocPrOnElement(docPr, layout);
|
|
2530
|
+
}
|
|
2531
|
+
return cloned;
|
|
2532
|
+
}
|
|
2533
|
+
/**
|
|
2534
|
+
* True when root is MC AlternateContent owned by drawing (Choice with drawing, not picture/ink).
|
|
2535
|
+
*
|
|
2536
|
+
* @private
|
|
2537
|
+
*/
|
|
2538
|
+
export function isDrawingAlternateContent(root) {
|
|
2539
|
+
return root.namespaceUri === MC_NS && root.localName === 'AlternateContent';
|
|
2540
|
+
}
|
|
2541
|
+
/**
|
|
2542
|
+
* True when residual is a nested bare drawing child (`wps:wsp` or `wpg:grpSp`)
|
|
2543
|
+
* rather than a top-level `w:drawing` / MC host (TASK-8051). Nested identity
|
|
2544
|
+
* lives on `wps:cNvPr` / `wpg:cNvPr`, not `wp:docPr`.
|
|
2545
|
+
*
|
|
2546
|
+
* @private
|
|
2547
|
+
*/
|
|
2548
|
+
export function isNestedDrawingResidual(root) {
|
|
2549
|
+
if (root.namespaceUri === WPS_NS && root.localName === 'wsp') {
|
|
2550
|
+
return true;
|
|
2551
|
+
}
|
|
2552
|
+
if (root.namespaceUri === WPG_NS && root.localName === 'grpSp') {
|
|
2553
|
+
return true;
|
|
2554
|
+
}
|
|
2555
|
+
return false;
|
|
2556
|
+
}
|
|
2557
|
+
/**
|
|
2558
|
+
* Read nested `cNvPr` identity from bare `wps:wsp` / `wpg:grpSp` residual.
|
|
2559
|
+
*
|
|
2560
|
+
* @private
|
|
2561
|
+
*/
|
|
2562
|
+
export function readCNvPrIdentity(root) {
|
|
2563
|
+
var __ts33_22;
|
|
2564
|
+
var cNvPr = ((__ts33_22 = findFirstElement(root, WPS_NS, 'cNvPr')), __ts33_22 != null ? __ts33_22 : findFirstElement(root, WPG_NS, 'cNvPr'));
|
|
2565
|
+
if (cNvPr === undefined) {
|
|
2566
|
+
return { name: undefined, title: undefined, description: undefined, docPrId: undefined };
|
|
2567
|
+
}
|
|
2568
|
+
var idRaw = attributeValue(cNvPr, '', 'id');
|
|
2569
|
+
var idParsed = idRaw !== undefined && /^\d+$/.test(idRaw) ? Number.parseInt(idRaw, 10) : undefined;
|
|
2570
|
+
var name = attributeValue(cNvPr, '', 'name');
|
|
2571
|
+
var title = attributeValue(cNvPr, '', 'title');
|
|
2572
|
+
var descr = attributeValue(cNvPr, '', 'descr');
|
|
2573
|
+
return {
|
|
2574
|
+
name: name !== undefined && name.length > 0 ? name : undefined,
|
|
2575
|
+
title: title !== undefined && title.length > 0 ? title : undefined,
|
|
2576
|
+
description: descr !== undefined && descr.length > 0 ? descr : undefined,
|
|
2577
|
+
docPrId: idParsed,
|
|
2578
|
+
};
|
|
2579
|
+
}
|
|
2580
|
+
/**
|
|
2581
|
+
* Deep-clone nested residual and patch `cNvPr` identity attributes only
|
|
2582
|
+
* (identity dirty on group/canvas children — TASK-8051).
|
|
2583
|
+
*
|
|
2584
|
+
* @private
|
|
2585
|
+
*/
|
|
2586
|
+
export function patchResidualCNvPr(residual, identity) {
|
|
2587
|
+
var __ts33_23;
|
|
2588
|
+
var cloned = cloneElement(residual);
|
|
2589
|
+
var cNvPr = ((__ts33_23 = findFirstElement(cloned, WPS_NS, 'cNvPr')), __ts33_23 != null ? __ts33_23 : findFirstElement(cloned, WPG_NS, 'cNvPr'));
|
|
2590
|
+
if (cNvPr === undefined) {
|
|
2591
|
+
return cloned;
|
|
2592
|
+
}
|
|
2593
|
+
patchDocPrOnElement(cNvPr, identity);
|
|
2594
|
+
return cloned;
|
|
2595
|
+
}
|