@syncfusion/ej2-docx 0.0.0-stage → 35.1.40
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.gitleaksignore +35 -0
- package/README.md +68 -2
- package/core.js +4 -0
- package/dist/ej2-docx.umd.min.js +11 -0
- package/dist/ej2-docx.umd.min.js.map +1 -0
- package/dist/es6/ej2-docx.es2015.js +66697 -0
- package/dist/es6/ej2-docx.es2015.js.map +1 -0
- package/dist/es6/ej2-docx.es5.js +77568 -0
- package/dist/es6/ej2-docx.es5.js.map +1 -0
- package/dist/global/ej2-docx.min.js +11 -0
- package/dist/global/ej2-docx.min.js.map +1 -0
- package/dist/global/index.d.ts +14 -0
- package/features.js +4 -0
- package/index.js +4 -0
- package/license +10 -0
- package/package.json +30 -3
- package/src/all.d.ts +50 -0
- package/src/all.js +147 -0
- package/src/core/compat/base64.d.ts +13 -0
- package/src/core/compat/base64.js +90 -0
- package/src/core/compat/object-compat.d.ts +30 -0
- package/src/core/compat/object-compat.js +40 -0
- package/src/core/compat/sha256.d.ts +9 -0
- package/src/core/compat/sha256.js +98 -0
- package/src/core/errors/docx-error.d.ts +89 -0
- package/src/core/errors/docx-error.js +138 -0
- package/src/core/errors/error-codes.d.ts +8 -0
- package/src/core/errors/error-codes.js +0 -0
- package/src/core/errors/index.d.ts +10 -0
- package/src/core/errors/index.js +9 -0
- package/src/core/index.d.ts +12 -0
- package/src/core/index.js +12 -0
- package/src/core/mc/alternate-content.d.ts +7 -0
- package/src/core/mc/alternate-content.js +67 -0
- package/src/core/mc/attributes.d.ts +24 -0
- package/src/core/mc/attributes.js +82 -0
- package/src/core/mc/index.d.ts +7 -0
- package/src/core/mc/index.js +5 -0
- package/src/core/mc/inspect.d.ts +16 -0
- package/src/core/mc/inspect.js +148 -0
- package/src/core/mc/namespaces.d.ts +4 -0
- package/src/core/mc/namespaces.js +4 -0
- package/src/core/mc/scope.d.ts +6 -0
- package/src/core/mc/scope.js +47 -0
- package/src/core/opc/content-types.d.ts +34 -0
- package/src/core/opc/content-types.js +162 -0
- package/src/core/opc/index.d.ts +8 -0
- package/src/core/opc/index.js +4 -0
- package/src/core/opc/package.d.ts +49 -0
- package/src/core/opc/package.js +324 -0
- package/src/core/opc/part-name.d.ts +47 -0
- package/src/core/opc/part-name.js +205 -0
- package/src/core/opc/relationships.d.ts +46 -0
- package/src/core/opc/relationships.js +212 -0
- package/src/core/preservation/index.d.ts +2 -0
- package/src/core/preservation/index.js +1 -0
- package/src/core/preservation/opaque-body.d.ts +16 -0
- package/src/core/preservation/opaque-body.js +69 -0
- package/src/core/registry/block-handlers.d.ts +30 -0
- package/src/core/registry/block-handlers.js +36 -0
- package/src/core/registry/create-defaults.d.ts +39 -0
- package/src/core/registry/create-defaults.js +42 -0
- package/src/core/registry/feature-registry.d.ts +20 -0
- package/src/core/registry/feature-registry.js +29 -0
- package/src/core/registry/index.d.ts +9 -0
- package/src/core/registry/index.js +8 -0
- package/src/core/registry/inline-handlers.d.ts +20 -0
- package/src/core/registry/inline-handlers.js +30 -0
- package/src/core/registry/materialize-handlers.d.ts +35 -0
- package/src/core/registry/materialize-handlers.js +75 -0
- package/src/core/registry/multi-part-handlers.d.ts +37 -0
- package/src/core/registry/multi-part-handlers.js +206 -0
- package/src/core/registry/package-part-handlers.d.ts +28 -0
- package/src/core/registry/package-part-handlers.js +190 -0
- package/src/core/registry/part-handlers.d.ts +24 -0
- package/src/core/registry/part-handlers.js +172 -0
- package/src/core/registry/run-leaf-handlers.d.ts +26 -0
- package/src/core/registry/run-leaf-handlers.js +72 -0
- package/src/core/security/limits.d.ts +40 -0
- package/src/core/security/limits.js +26 -0
- package/src/core/xml/index.d.ts +7 -0
- package/src/core/xml/index.js +3 -0
- package/src/core/xml/model.d.ts +66 -0
- package/src/core/xml/model.js +17 -0
- package/src/core/xml/parse.d.ts +12 -0
- package/src/core/xml/parse.js +382 -0
- package/src/core/xml/serialize.d.ts +6 -0
- package/src/core/xml/serialize.js +93 -0
- package/src/core/zip/crc32.d.ts +2 -0
- package/src/core/zip/crc32.js +25 -0
- package/src/core/zip/deflate.d.ts +6 -0
- package/src/core/zip/deflate.js +6 -0
- package/src/core/zip/index.d.ts +10 -0
- package/src/core/zip/index.js +4 -0
- package/src/core/zip/inflate-raw.d.ts +17 -0
- package/src/core/zip/inflate-raw.js +450 -0
- package/src/core/zip/names.d.ts +6 -0
- package/src/core/zip/names.js +52 -0
- package/src/core/zip/read.d.ts +8 -0
- package/src/core/zip/read.js +262 -0
- package/src/core/zip/write.d.ts +7 -0
- package/src/core/zip/write.js +189 -0
- package/src/core/zip/zip-entry.d.ts +4 -0
- package/src/core/zip/zip-entry.js +0 -0
- package/src/features/bibliography/index.d.ts +100 -0
- package/src/features/bibliography/index.js +290 -0
- package/src/features/bookmarks/index.d.ts +331 -0
- package/src/features/bookmarks/index.js +1009 -0
- package/src/features/comments/comment-extensions.d.ts +157 -0
- package/src/features/comments/comment-extensions.js +356 -0
- package/src/features/comments/index.d.ts +579 -0
- package/src/features/comments/index.js +1727 -0
- package/src/features/content-controls/index.d.ts +821 -0
- package/src/features/content-controls/index.js +2857 -0
- package/src/features/custom-xml/index.d.ts +236 -0
- package/src/features/custom-xml/index.js +661 -0
- package/src/features/document/alignment.d.ts +23 -0
- package/src/features/document/alignment.js +36 -0
- package/src/features/document/alt-chunk.d.ts +103 -0
- package/src/features/document/alt-chunk.js +221 -0
- package/src/features/document/assert-never.d.ts +1 -0
- package/src/features/document/assert-never.js +4 -0
- package/src/features/document/augmentations.d.ts +578 -0
- package/src/features/document/augmentations.js +0 -0
- package/src/features/document/body-always-on.d.ts +36 -0
- package/src/features/document/body-always-on.js +66 -0
- package/src/features/document/body-blocks.d.ts +7 -0
- package/src/features/document/body-blocks.js +78 -0
- package/src/features/document/body-item-adapters.d.ts +62 -0
- package/src/features/document/body-item-adapters.js +97 -0
- package/src/features/document/body-item-collection.d.ts +151 -0
- package/src/features/document/body-item-collection.js +440 -0
- package/src/features/document/body-item.d.ts +35 -0
- package/src/features/document/body-item.js +8 -0
- package/src/features/document/body.d.ts +150 -0
- package/src/features/document/body.js +263 -0
- package/src/features/document/character-format.d.ts +413 -0
- package/src/features/document/character-format.js +2054 -0
- package/src/features/document/color.d.ts +178 -0
- package/src/features/document/color.js +495 -0
- package/src/features/document/document.d.ts +410 -0
- package/src/features/document/document.js +1049 -0
- package/src/features/document/element-type.d.ts +68 -0
- package/src/features/document/element-type.js +133 -0
- package/src/features/document/entity-type.d.ts +92 -0
- package/src/features/document/entity-type.js +93 -0
- package/src/features/document/feature-block.d.ts +16 -0
- package/src/features/document/feature-block.js +0 -0
- package/src/features/document/feature-inline.d.ts +13 -0
- package/src/features/document/feature-inline.js +0 -0
- package/src/features/document/feature-multi-package-part.d.ts +19 -0
- package/src/features/document/feature-multi-package-part.js +8 -0
- package/src/features/document/feature-package-level-part.d.ts +18 -0
- package/src/features/document/feature-package-level-part.js +8 -0
- package/src/features/document/feature-package-part.d.ts +14 -0
- package/src/features/document/feature-package-part.js +0 -0
- package/src/features/document/feature-run-leaf.d.ts +9 -0
- package/src/features/document/feature-run-leaf.js +0 -0
- package/src/features/document/headers-footers.d.ts +206 -0
- package/src/features/document/headers-footers.js +384 -0
- package/src/features/document/index.d.ts +41 -0
- package/src/features/document/index.js +34 -0
- package/src/features/document/length.d.ts +152 -0
- package/src/features/document/length.js +245 -0
- package/src/features/document/load-options.d.ts +14 -0
- package/src/features/document/load-options.js +0 -0
- package/src/features/document/locale-ids.d.ts +227 -0
- package/src/features/document/locale-ids.js +485 -0
- package/src/features/document/on-off.d.ts +9 -0
- package/src/features/document/on-off.js +27 -0
- package/src/features/document/page-setup.d.ts +339 -0
- package/src/features/document/page-setup.js +244 -0
- package/src/features/document/paragraph-format.d.ts +880 -0
- package/src/features/document/paragraph-format.js +2807 -0
- package/src/features/document/paragraph-item-collection.d.ts +162 -0
- package/src/features/document/paragraph-item-collection.js +363 -0
- package/src/features/document/paragraph-item.d.ts +83 -0
- package/src/features/document/paragraph-item.js +103 -0
- package/src/features/document/paragraph.d.ts +435 -0
- package/src/features/document/paragraph.js +888 -0
- package/src/features/document/run.d.ts +1 -0
- package/src/features/document/run.js +768 -0
- package/src/features/document/section-partition-flatten.d.ts +124 -0
- package/src/features/document/section-partition-flatten.js +217 -0
- package/src/features/document/section-properties-model.d.ts +13 -0
- package/src/features/document/section-properties-model.js +0 -0
- package/src/features/document/section.d.ts +93 -0
- package/src/features/document/section.js +178 -0
- package/src/features/document/sections.d.ts +103 -0
- package/src/features/document/sections.js +217 -0
- package/src/features/document/sub-super-script.d.ts +23 -0
- package/src/features/document/sub-super-script.js +43 -0
- package/src/features/document/text-range.d.ts +445 -0
- package/src/features/document/text-range.js +1156 -0
- package/src/features/document/typed-body-collections.d.ts +162 -0
- package/src/features/document/typed-body-collections.js +371 -0
- package/src/features/document/underline-style.d.ts +38 -0
- package/src/features/document/underline-style.js +126 -0
- package/src/features/document/units.d.ts +8 -0
- package/src/features/document/units.js +7 -0
- package/src/features/document/wml.d.ts +16 -0
- package/src/features/document/wml.js +67 -0
- package/src/features/drawing/authoring.d.ts +27 -0
- package/src/features/drawing/authoring.js +271 -0
- package/src/features/drawing/body-pr.d.ts +271 -0
- package/src/features/drawing/body-pr.js +663 -0
- package/src/features/drawing/drawing-shape.d.ts +1192 -0
- package/src/features/drawing/drawing-shape.js +3239 -0
- package/src/features/drawing/encode-builders.d.ts +176 -0
- package/src/features/drawing/encode-builders.js +390 -0
- package/src/features/drawing/fill-format.d.ts +52 -0
- package/src/features/drawing/fill-format.js +124 -0
- package/src/features/drawing/host-codec.d.ts +632 -0
- package/src/features/drawing/host-codec.js +2595 -0
- package/src/features/drawing/index.d.ts +13 -0
- package/src/features/drawing/index.js +33 -0
- package/src/features/drawing/line-format.d.ts +76 -0
- package/src/features/drawing/line-format.js +343 -0
- package/src/features/drawing/parse-register.d.ts +50 -0
- package/src/features/drawing/parse-register.js +257 -0
- package/src/features/drawing/residual-utils.d.ts +47 -0
- package/src/features/drawing/residual-utils.js +290 -0
- package/src/features/drawing/shape-types.d.ts +433 -0
- package/src/features/drawing/shape-types.js +437 -0
- package/src/features/drawing/sp-pr.d.ts +396 -0
- package/src/features/drawing/sp-pr.js +610 -0
- package/src/features/drawing/text-frame.d.ts +90 -0
- package/src/features/drawing/text-frame.js +152 -0
- package/src/features/drawing/types.d.ts +352 -0
- package/src/features/drawing/types.js +60 -0
- package/src/features/drawing/wrap-format.d.ts +62 -0
- package/src/features/drawing/wrap-format.js +114 -0
- package/src/features/editable-ranges/index.d.ts +494 -0
- package/src/features/editable-ranges/index.js +1348 -0
- package/src/features/fields/index.d.ts +428 -0
- package/src/features/fields/index.js +2148 -0
- package/src/features/fields/paragraph-field.d.ts +187 -0
- package/src/features/fields/paragraph-field.js +692 -0
- package/src/features/font-table/font-substitution-table.d.ts +75 -0
- package/src/features/font-table/font-substitution-table.js +257 -0
- package/src/features/font-table/font-table-entry.d.ts +255 -0
- package/src/features/font-table/font-table-entry.js +823 -0
- package/src/features/font-table/font-table.d.ts +128 -0
- package/src/features/font-table/font-table.js +313 -0
- package/src/features/font-table/index.d.ts +27 -0
- package/src/features/font-table/index.js +48 -0
- package/src/features/glossary/index.d.ts +97 -0
- package/src/features/glossary/index.js +286 -0
- package/src/features/headers-footers/index.d.ts +506 -0
- package/src/features/headers-footers/index.js +1666 -0
- package/src/features/hyperlinks/index.d.ts +230 -0
- package/src/features/hyperlinks/index.js +685 -0
- package/src/features/images/caption-authoring-api.d.ts +33 -0
- package/src/features/images/caption-authoring-api.js +33 -0
- package/src/features/images/caption-enums.d.ts +52 -0
- package/src/features/images/caption-enums.js +141 -0
- package/src/features/images/caption-host.d.ts +10 -0
- package/src/features/images/caption-host.js +21 -0
- package/src/features/images/captions.d.ts +13 -0
- package/src/features/images/captions.js +142 -0
- package/src/features/images/host-codec.d.ts +103 -0
- package/src/features/images/host-codec.js +720 -0
- package/src/features/images/image-sniff.d.ts +21 -0
- package/src/features/images/image-sniff.js +71 -0
- package/src/features/images/index.d.ts +506 -0
- package/src/features/images/index.js +1429 -0
- package/src/features/images/layout-types.d.ts +232 -0
- package/src/features/images/layout-types.js +294 -0
- package/src/features/images/public-entry.d.ts +9 -0
- package/src/features/images/public-entry.js +9 -0
- package/src/features/index.d.ts +35 -0
- package/src/features/index.js +36 -0
- package/src/features/mail-merge/index.d.ts +113 -0
- package/src/features/mail-merge/index.js +315 -0
- package/src/features/notes/index.d.ts +573 -0
- package/src/features/notes/index.js +1725 -0
- package/src/features/numbering/abstract-numbering.d.ts +90 -0
- package/src/features/numbering/abstract-numbering.js +292 -0
- package/src/features/numbering/index.d.ts +182 -0
- package/src/features/numbering/index.js +668 -0
- package/src/features/numbering/list-format.d.ts +158 -0
- package/src/features/numbering/list-format.js +590 -0
- package/src/features/numbering/list-string.d.ts +7 -0
- package/src/features/numbering/list-string.js +423 -0
- package/src/features/numbering/list-style.d.ts +204 -0
- package/src/features/numbering/list-style.js +1084 -0
- package/src/features/numbering/numbering-instance.d.ts +101 -0
- package/src/features/numbering/numbering-instance.js +329 -0
- package/src/features/numbering/numbering-level.d.ts +118 -0
- package/src/features/numbering/numbering-level.js +501 -0
- package/src/features/numbering/picture-bullet.d.ts +34 -0
- package/src/features/numbering/picture-bullet.js +88 -0
- package/src/features/ole-object/catalog.d.ts +300 -0
- package/src/features/ole-object/catalog.js +908 -0
- package/src/features/ole-object/index.d.ts +526 -0
- package/src/features/ole-object/index.js +1421 -0
- package/src/features/ole-object/relationship.d.ts +27 -0
- package/src/features/ole-object/relationship.js +27 -0
- package/src/features/ole-object/typed-dom.d.ts +186 -0
- package/src/features/ole-object/typed-dom.js +595 -0
- package/src/features/properties/index.d.ts +205 -0
- package/src/features/properties/index.js +549 -0
- package/src/features/revisions/index.d.ts +204 -0
- package/src/features/revisions/index.js +695 -0
- package/src/features/sections/column-collection.d.ts +119 -0
- package/src/features/sections/column-collection.js +478 -0
- package/src/features/sections/column.d.ts +15 -0
- package/src/features/sections/column.js +37 -0
- package/src/features/sections/index.d.ts +91 -0
- package/src/features/sections/index.js +1096 -0
- package/src/features/sections/margins.d.ts +40 -0
- package/src/features/sections/margins.js +105 -0
- package/src/features/sections/page-number-style.d.ts +21 -0
- package/src/features/sections/page-number-style.js +62 -0
- package/src/features/sections/page-orientation.d.ts +10 -0
- package/src/features/sections/page-orientation.js +10 -0
- package/src/features/sections/page-setup.d.ts +435 -0
- package/src/features/sections/page-setup.js +1479 -0
- package/src/features/sections/page-size.d.ts +59 -0
- package/src/features/sections/page-size.js +68 -0
- package/src/features/sections/section-break-code.d.ts +27 -0
- package/src/features/sections/section-break-code.js +60 -0
- package/src/features/sections/section-document-association.d.ts +18 -0
- package/src/features/sections/section-document-association.js +31 -0
- package/src/features/sections/section-validation.d.ts +43 -0
- package/src/features/sections/section-validation.js +97 -0
- package/src/features/settings/attached-template.d.ts +35 -0
- package/src/features/settings/attached-template.js +98 -0
- package/src/features/settings/compat-settings.d.ts +216 -0
- package/src/features/settings/compat-settings.js +508 -0
- package/src/features/settings/document-background.d.ts +59 -0
- package/src/features/settings/document-background.js +131 -0
- package/src/features/settings/document-protection.d.ts +65 -0
- package/src/features/settings/document-protection.js +157 -0
- package/src/features/settings/document-settings-facades.d.ts +108 -0
- package/src/features/settings/document-settings-facades.js +312 -0
- package/src/features/settings/document-settings-values.d.ts +43 -0
- package/src/features/settings/document-settings-values.js +60 -0
- package/src/features/settings/footnote-properties.d.ts +211 -0
- package/src/features/settings/footnote-properties.js +591 -0
- package/src/features/settings/index.d.ts +356 -0
- package/src/features/settings/index.js +829 -0
- package/src/features/settings/settings-children.d.ts +151 -0
- package/src/features/settings/settings-children.js +505 -0
- package/src/features/settings/web-settings.d.ts +88 -0
- package/src/features/settings/web-settings.js +227 -0
- package/src/features/settings/zoom.d.ts +79 -0
- package/src/features/settings/zoom.js +147 -0
- package/src/features/styles/builtin-catalog.d.ts +159 -0
- package/src/features/styles/builtin-catalog.js +963 -0
- package/src/features/styles/builtin-resolver.d.ts +49 -0
- package/src/features/styles/builtin-resolver.js +165 -0
- package/src/features/styles/default-styles.d.ts +37 -0
- package/src/features/styles/default-styles.js +186 -0
- package/src/features/styles/default-theme.d.ts +13 -0
- package/src/features/styles/default-theme.js +13 -0
- package/src/features/styles/doc-defaults.d.ts +58 -0
- package/src/features/styles/doc-defaults.js +178 -0
- package/src/features/styles/formatting-resolver.d.ts +27 -0
- package/src/features/styles/formatting-resolver.js +72 -0
- package/src/features/styles/index.d.ts +256 -0
- package/src/features/styles/index.js +1325 -0
- package/src/features/styles/latent-styles.d.ts +68 -0
- package/src/features/styles/latent-styles.js +305 -0
- package/src/features/styles/paragraph-properties.d.ts +71 -0
- package/src/features/styles/paragraph-properties.js +237 -0
- package/src/features/styles/run-properties.d.ts +93 -0
- package/src/features/styles/run-properties.js +516 -0
- package/src/features/styles/style-base.d.ts +402 -0
- package/src/features/styles/style-base.js +1026 -0
- package/src/features/styles/style-collection.d.ts +264 -0
- package/src/features/styles/style-collection.js +714 -0
- package/src/features/styles/style-format-bridge.d.ts +64 -0
- package/src/features/styles/style-format-bridge.js +100 -0
- package/src/features/styles/style.d.ts +84 -0
- package/src/features/styles/style.js +375 -0
- package/src/features/styles/styles-with-effects.d.ts +71 -0
- package/src/features/styles/styles-with-effects.js +180 -0
- package/src/features/styles/table-style.d.ts +272 -0
- package/src/features/styles/table-style.js +1226 -0
- package/src/features/styles/theme.d.ts +126 -0
- package/src/features/styles/theme.js +377 -0
- package/src/features/tables/border-style-map.d.ts +24 -0
- package/src/features/tables/border-style-map.js +81 -0
- package/src/features/tables/borders.d.ts +126 -0
- package/src/features/tables/borders.js +527 -0
- package/src/features/tables/collections.d.ts +113 -0
- package/src/features/tables/collections.js +261 -0
- package/src/features/tables/format.d.ts +208 -0
- package/src/features/tables/format.js +716 -0
- package/src/features/tables/index.d.ts +597 -0
- package/src/features/tables/index.js +2386 -0
- package/src/features/tables/paddings.d.ts +41 -0
- package/src/features/tables/paddings.js +97 -0
- package/src/features/tables/tbl-pr-positioning.d.ts +27 -0
- package/src/features/tables/tbl-pr-positioning.js +178 -0
- package/src/features/tables/tbl-pr.d.ts +528 -0
- package/src/features/tables/tbl-pr.js +1208 -0
- package/src/features/tables/tc-pr.d.ts +168 -0
- package/src/features/tables/tc-pr.js +553 -0
- package/src/features/tables/tr-pr.d.ts +60 -0
- package/src/features/tables/tr-pr.js +215 -0
- package/src/features/watermark/detect.d.ts +76 -0
- package/src/features/watermark/detect.js +219 -0
- package/src/features/watermark/index.d.ts +28 -0
- package/src/features/watermark/index.js +91 -0
- package/src/features/watermark/logical-store.d.ts +29 -0
- package/src/features/watermark/logical-store.js +31 -0
- package/src/features/watermark/model.d.ts +285 -0
- package/src/features/watermark/model.js +597 -0
- package/src/features/watermark/parse.d.ts +84 -0
- package/src/features/watermark/parse.js +815 -0
- package/src/features/watermark/serialize.d.ts +98 -0
- package/src/features/watermark/serialize.js +1517 -0
- package/src/global.js +1 -0
- package/src/index.d.ts +2 -0
- package/src/index.js +2 -0
|
@@ -0,0 +1,1208 @@
|
|
|
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
|
+
/**
|
|
23
|
+
* Typed parse/serialize helpers for `w:tblPr` and shared table property types.
|
|
24
|
+
*
|
|
25
|
+
* Citations: Transitional `wml.xsd` `CT_TblPrBase`, `CT_TblWidth`, `CT_TblBorders`,
|
|
26
|
+
* `CT_TblCellMar`, `CT_TblLook`, `ST_JcTable`, `ST_TblWidth`.
|
|
27
|
+
*/
|
|
28
|
+
import { twipsToPoint, pointToTwips } from '../document/length';
|
|
29
|
+
import { parseOnOff, serializeOnOff } from '../document/on-off';
|
|
30
|
+
import { elementChildren, isWml, wValAttribute, wmlAttr, wmlElement, } from '../document/wml';
|
|
31
|
+
export { pointToTwips, twipsToPoint };
|
|
32
|
+
/**
|
|
33
|
+
* How Word interprets a table row's height (`ST_HeightRule`).
|
|
34
|
+
*
|
|
35
|
+
* - `auto`: the row grows and shrinks with its content.
|
|
36
|
+
* - `atLeast`: the height is a minimum; content can still push it taller.
|
|
37
|
+
* - `exact`: the height is fixed; overflow is clipped.
|
|
38
|
+
*/
|
|
39
|
+
export var TableRowHeightRule = {
|
|
40
|
+
Auto: 'auto',
|
|
41
|
+
AtLeast: 'atLeast',
|
|
42
|
+
Exact: 'exact',
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* Horizontal alignment of a table or table row on the page
|
|
46
|
+
* (`w:jc` / `ST_JcTable` public subset).
|
|
47
|
+
*
|
|
48
|
+
* - {@link TableAlignment.Left}: hug the left margin (Word default; wire `left`).
|
|
49
|
+
* - {@link TableAlignment.Center}: center between the margins (wire `center`).
|
|
50
|
+
* - {@link TableAlignment.Right}: hug the right margin (wire `right`).
|
|
51
|
+
*
|
|
52
|
+
* @public
|
|
53
|
+
*/
|
|
54
|
+
export var TableAlignment = {
|
|
55
|
+
Left: 'left',
|
|
56
|
+
Center: 'center',
|
|
57
|
+
Right: 'right',
|
|
58
|
+
};
|
|
59
|
+
// ---------------------------------------------------------------------------
|
|
60
|
+
// Shared low-level helpers
|
|
61
|
+
// ---------------------------------------------------------------------------
|
|
62
|
+
export function parseDecimalVal(raw) {
|
|
63
|
+
if (raw === undefined || !/^-?\d+$/.test(raw)) {
|
|
64
|
+
return undefined;
|
|
65
|
+
}
|
|
66
|
+
return parseInt(raw, 10);
|
|
67
|
+
}
|
|
68
|
+
export function wmlAttrVal(el, localName) {
|
|
69
|
+
var __ts33_0;
|
|
70
|
+
return ((__ts33_0 = el.attributes.find(function (a) { return a.localName === localName && (a.prefix === 'w' || a.prefix === ''); })), __ts33_0 == null ? undefined : __ts33_0.value);
|
|
71
|
+
}
|
|
72
|
+
function findWmlChild(parent, localName) {
|
|
73
|
+
var e_1, _a;
|
|
74
|
+
try {
|
|
75
|
+
for (var _b = __values(elementChildren(parent)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
76
|
+
var child = _c.value;
|
|
77
|
+
if (isWml(child, localName)) {
|
|
78
|
+
return child;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
83
|
+
finally {
|
|
84
|
+
try {
|
|
85
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
86
|
+
}
|
|
87
|
+
finally { if (e_1) throw e_1.error; }
|
|
88
|
+
}
|
|
89
|
+
return undefined;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Replace or remove all children with `localName`; append when missing.
|
|
93
|
+
* Preserves attributes and unmodeled siblings on the parent element.
|
|
94
|
+
*/
|
|
95
|
+
export function upsertPropChild(parent, parentLocalName, localName, replacement) {
|
|
96
|
+
var e_2, _a;
|
|
97
|
+
var children = elementChildren(parent);
|
|
98
|
+
var next = [];
|
|
99
|
+
var replaced = false;
|
|
100
|
+
try {
|
|
101
|
+
for (var children_1 = __values(children), children_1_1 = children_1.next(); !children_1_1.done; children_1_1 = children_1.next()) {
|
|
102
|
+
var child = children_1_1.value;
|
|
103
|
+
if (isWml(child, localName)) {
|
|
104
|
+
if (!replaced && replacement !== undefined) {
|
|
105
|
+
next.push(replacement);
|
|
106
|
+
}
|
|
107
|
+
replaced = true;
|
|
108
|
+
continue;
|
|
109
|
+
}
|
|
110
|
+
next.push(child);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
114
|
+
finally {
|
|
115
|
+
try {
|
|
116
|
+
if (children_1_1 && !children_1_1.done && (_a = children_1.return)) _a.call(children_1);
|
|
117
|
+
}
|
|
118
|
+
finally { if (e_2) throw e_2.error; }
|
|
119
|
+
}
|
|
120
|
+
if (!replaced && replacement !== undefined) {
|
|
121
|
+
next.push(replacement);
|
|
122
|
+
}
|
|
123
|
+
return wmlElement(parentLocalName, {
|
|
124
|
+
attributes: parent.attributes,
|
|
125
|
+
namespaceDeclarations: parent.namespaceDeclarations,
|
|
126
|
+
children: next,
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
export function emptyPropsToUndefined(el) {
|
|
130
|
+
if (el === undefined) {
|
|
131
|
+
return undefined;
|
|
132
|
+
}
|
|
133
|
+
if (elementChildren(el).length === 0 && el.attributes.length === 0) {
|
|
134
|
+
return undefined;
|
|
135
|
+
}
|
|
136
|
+
return el;
|
|
137
|
+
}
|
|
138
|
+
// ---------------------------------------------------------------------------
|
|
139
|
+
// Width (CT_TblWidth)
|
|
140
|
+
// ---------------------------------------------------------------------------
|
|
141
|
+
var WIDTH_TYPES = new Set(['auto', 'dxa', 'nil', 'pct']);
|
|
142
|
+
/**
|
|
143
|
+
* Parse `CT_TblWidth` (`@w:w`, `@w:type`).
|
|
144
|
+
*
|
|
145
|
+
* @private
|
|
146
|
+
*/
|
|
147
|
+
export function parseTblWidth(el) {
|
|
148
|
+
var __ts33_1, __ts33_2;
|
|
149
|
+
var typeRaw = ((__ts33_1 = wmlAttrVal(el, 'type')), __ts33_1 != null ? __ts33_1 : 'dxa');
|
|
150
|
+
if (!WIDTH_TYPES.has(typeRaw)) {
|
|
151
|
+
return undefined;
|
|
152
|
+
}
|
|
153
|
+
var type = typeRaw;
|
|
154
|
+
var wRaw = wmlAttrVal(el, 'w');
|
|
155
|
+
var n = ((__ts33_2 = parseDecimalVal(wRaw)), __ts33_2 != null ? __ts33_2 : 0);
|
|
156
|
+
// pct: store fiftieths-of-percent raw via twips bridge (task note).
|
|
157
|
+
// dxa/auto/nil: twips (may be 0).
|
|
158
|
+
return { type: type, value: twipsToPoint(n) };
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Serialize `CT_TblWidth`.
|
|
162
|
+
*
|
|
163
|
+
* @private
|
|
164
|
+
*/
|
|
165
|
+
export function serializeTblWidth(localName, width) {
|
|
166
|
+
var w = pointToTwips(width.value);
|
|
167
|
+
return wmlElement(localName, {
|
|
168
|
+
attributes: [wmlAttr('w', String(w)), wmlAttr('type', width.type)],
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
// ---------------------------------------------------------------------------
|
|
172
|
+
// Borders
|
|
173
|
+
// ---------------------------------------------------------------------------
|
|
174
|
+
/**
|
|
175
|
+
* Parse one `CT_Border`.
|
|
176
|
+
*
|
|
177
|
+
* @private
|
|
178
|
+
*/
|
|
179
|
+
export function parseBorderEdge(el) {
|
|
180
|
+
var style = wmlAttrVal(el, 'val');
|
|
181
|
+
if (style === undefined) {
|
|
182
|
+
return undefined;
|
|
183
|
+
}
|
|
184
|
+
var colorRaw = wmlAttrVal(el, 'color');
|
|
185
|
+
var szRaw = wmlAttrVal(el, 'sz');
|
|
186
|
+
var sz = szRaw !== undefined ? parseDecimalVal(szRaw) : undefined;
|
|
187
|
+
var spaceRaw = wmlAttrVal(el, 'space');
|
|
188
|
+
var space = spaceRaw !== undefined ? parseDecimalVal(spaceRaw) : undefined;
|
|
189
|
+
var shadowRaw = wmlAttrVal(el, 'shadow');
|
|
190
|
+
var shadow;
|
|
191
|
+
if (shadowRaw !== undefined) {
|
|
192
|
+
var normalized = shadowRaw.trim().toLowerCase();
|
|
193
|
+
if (normalized === 'true' || normalized === '1' || normalized === 'on') {
|
|
194
|
+
shadow = true;
|
|
195
|
+
}
|
|
196
|
+
else if (normalized === 'false' || normalized === '0' || normalized === 'off') {
|
|
197
|
+
shadow = false;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
return __assign({ style: style }, (colorRaw !== undefined ? { color: colorRaw } : {}), (sz !== undefined ? { size: sz } : {}), (space !== undefined ? { space: space } : {}), (shadow !== undefined ? { shadow: shadow } : {}));
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Serialize one border edge element.
|
|
204
|
+
*
|
|
205
|
+
* `CT_Border` requires `@w:val`; an edge parsed without a style token
|
|
206
|
+
* (schema-invalid input) is skipped so the output stays schema-valid.
|
|
207
|
+
*
|
|
208
|
+
* @private
|
|
209
|
+
*/
|
|
210
|
+
export function serializeBorderEdge(localName, edge) {
|
|
211
|
+
if (edge.style === undefined) {
|
|
212
|
+
return undefined;
|
|
213
|
+
}
|
|
214
|
+
var attrs = [wmlAttr('val', edge.style)];
|
|
215
|
+
if (edge.color !== undefined) {
|
|
216
|
+
// ST_HexColor / 'auto': strip a leading '#' if present.
|
|
217
|
+
var color = edge.color;
|
|
218
|
+
if (color.length > 0 && color.charAt(0) === '#') {
|
|
219
|
+
color = color.slice(1);
|
|
220
|
+
}
|
|
221
|
+
attrs.push(wmlAttr('color', color));
|
|
222
|
+
}
|
|
223
|
+
if (edge.size !== undefined) {
|
|
224
|
+
attrs.push(wmlAttr('sz', String(edge.size)));
|
|
225
|
+
}
|
|
226
|
+
if (edge.space !== undefined) {
|
|
227
|
+
attrs.push(wmlAttr('space', String(edge.space)));
|
|
228
|
+
}
|
|
229
|
+
if (edge.shadow !== undefined) {
|
|
230
|
+
attrs.push(wmlAttr('shadow', edge.shadow ? 'true' : 'false'));
|
|
231
|
+
}
|
|
232
|
+
return wmlElement(localName, { attributes: attrs });
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Parse table borders. Maps `start`→`left`, `end`→`right` (Strict → API).
|
|
236
|
+
*
|
|
237
|
+
* @private
|
|
238
|
+
*/
|
|
239
|
+
export function parseTblBorders(el) {
|
|
240
|
+
var e_3, _a;
|
|
241
|
+
var top;
|
|
242
|
+
var left;
|
|
243
|
+
var bottom;
|
|
244
|
+
var right;
|
|
245
|
+
var insideH;
|
|
246
|
+
var insideV;
|
|
247
|
+
try {
|
|
248
|
+
for (var _b = __values(elementChildren(el)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
249
|
+
var child = _c.value;
|
|
250
|
+
if (!isWml(child, child.localName)) {
|
|
251
|
+
continue;
|
|
252
|
+
}
|
|
253
|
+
var edge = parseBorderEdge(child);
|
|
254
|
+
if (edge === undefined) {
|
|
255
|
+
continue;
|
|
256
|
+
}
|
|
257
|
+
switch (child.localName) {
|
|
258
|
+
case 'top':
|
|
259
|
+
top = edge;
|
|
260
|
+
break;
|
|
261
|
+
case 'left':
|
|
262
|
+
case 'start':
|
|
263
|
+
left = edge;
|
|
264
|
+
break;
|
|
265
|
+
case 'bottom':
|
|
266
|
+
bottom = edge;
|
|
267
|
+
break;
|
|
268
|
+
case 'right':
|
|
269
|
+
case 'end':
|
|
270
|
+
right = edge;
|
|
271
|
+
break;
|
|
272
|
+
case 'insideH':
|
|
273
|
+
insideH = edge;
|
|
274
|
+
break;
|
|
275
|
+
case 'insideV':
|
|
276
|
+
insideV = edge;
|
|
277
|
+
break;
|
|
278
|
+
default:
|
|
279
|
+
break;
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
284
|
+
finally {
|
|
285
|
+
try {
|
|
286
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
287
|
+
}
|
|
288
|
+
finally { if (e_3) throw e_3.error; }
|
|
289
|
+
}
|
|
290
|
+
return __assign({}, (top !== undefined ? { top: top } : {}), (left !== undefined ? { left: left } : {}), (bottom !== undefined ? { bottom: bottom } : {}), (right !== undefined ? { right: right } : {}), (insideH !== undefined ? { insideH: insideH } : {}), (insideV !== undefined ? { insideV: insideV } : {}));
|
|
291
|
+
}
|
|
292
|
+
/**
|
|
293
|
+
* Serialize table borders as Transitional `left`/`right` (Word parity).
|
|
294
|
+
* Preserves unmodeled children (e.g. Strict `start`/`end`) when rewriting.
|
|
295
|
+
*
|
|
296
|
+
* @private
|
|
297
|
+
*/
|
|
298
|
+
export function serializeTblBorders(borders, existing) {
|
|
299
|
+
var e_4, _a;
|
|
300
|
+
var modeled = new Set(['top', 'left', 'right', 'bottom', 'insideH', 'insideV', 'start', 'end']);
|
|
301
|
+
var children = [];
|
|
302
|
+
var pushEdge = function (localName, edge) {
|
|
303
|
+
var el = edge !== undefined ? serializeBorderEdge(localName, edge) : undefined;
|
|
304
|
+
if (el !== undefined) {
|
|
305
|
+
children.push(el);
|
|
306
|
+
}
|
|
307
|
+
};
|
|
308
|
+
pushEdge('top', borders.top);
|
|
309
|
+
pushEdge('left', borders.left);
|
|
310
|
+
pushEdge('bottom', borders.bottom);
|
|
311
|
+
pushEdge('right', borders.right);
|
|
312
|
+
pushEdge('insideH', borders.insideH);
|
|
313
|
+
pushEdge('insideV', borders.insideV);
|
|
314
|
+
if (existing !== undefined) {
|
|
315
|
+
try {
|
|
316
|
+
for (var _b = __values(elementChildren(existing)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
317
|
+
var child = _c.value;
|
|
318
|
+
if (!isWml(child, child.localName) || !modeled.has(child.localName)) {
|
|
319
|
+
children.push(child);
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
324
|
+
finally {
|
|
325
|
+
try {
|
|
326
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
327
|
+
}
|
|
328
|
+
finally { if (e_4) throw e_4.error; }
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
return wmlElement('tblBorders', { children: children });
|
|
332
|
+
}
|
|
333
|
+
/**
|
|
334
|
+
* Parse cell borders including diagonals.
|
|
335
|
+
*
|
|
336
|
+
* @private
|
|
337
|
+
*/
|
|
338
|
+
export function parseTcBorders(el) {
|
|
339
|
+
var e_5, _a;
|
|
340
|
+
var base = parseTblBorders(el);
|
|
341
|
+
var tl2br;
|
|
342
|
+
var tr2bl;
|
|
343
|
+
try {
|
|
344
|
+
for (var _b = __values(elementChildren(el)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
345
|
+
var child = _c.value;
|
|
346
|
+
if (!isWml(child, child.localName)) {
|
|
347
|
+
continue;
|
|
348
|
+
}
|
|
349
|
+
var edge = parseBorderEdge(child);
|
|
350
|
+
if (edge === undefined) {
|
|
351
|
+
continue;
|
|
352
|
+
}
|
|
353
|
+
if (child.localName === 'tl2br') {
|
|
354
|
+
tl2br = edge;
|
|
355
|
+
}
|
|
356
|
+
else if (child.localName === 'tr2bl') {
|
|
357
|
+
tr2bl = edge;
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
catch (e_5_1) { e_5 = { error: e_5_1 }; }
|
|
362
|
+
finally {
|
|
363
|
+
try {
|
|
364
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
365
|
+
}
|
|
366
|
+
finally { if (e_5) throw e_5.error; }
|
|
367
|
+
}
|
|
368
|
+
return __assign({}, base, (tl2br !== undefined ? { tl2br: tl2br } : {}), (tr2bl !== undefined ? { tr2bl: tr2bl } : {}));
|
|
369
|
+
}
|
|
370
|
+
/**
|
|
371
|
+
* Serialize cell borders (`w:tcBorders`).
|
|
372
|
+
*
|
|
373
|
+
* @private
|
|
374
|
+
*/
|
|
375
|
+
export function serializeTcBorders(borders, existing) {
|
|
376
|
+
var e_6, _a;
|
|
377
|
+
var modeled = new Set([
|
|
378
|
+
'top',
|
|
379
|
+
'left',
|
|
380
|
+
'right',
|
|
381
|
+
'bottom',
|
|
382
|
+
'insideH',
|
|
383
|
+
'insideV',
|
|
384
|
+
'start',
|
|
385
|
+
'end',
|
|
386
|
+
'tl2br',
|
|
387
|
+
'tr2bl',
|
|
388
|
+
]);
|
|
389
|
+
var children = [];
|
|
390
|
+
var pushEdge = function (localName, edge) {
|
|
391
|
+
var el = edge !== undefined ? serializeBorderEdge(localName, edge) : undefined;
|
|
392
|
+
if (el !== undefined) {
|
|
393
|
+
children.push(el);
|
|
394
|
+
}
|
|
395
|
+
};
|
|
396
|
+
pushEdge('top', borders.top);
|
|
397
|
+
pushEdge('left', borders.left);
|
|
398
|
+
pushEdge('bottom', borders.bottom);
|
|
399
|
+
pushEdge('right', borders.right);
|
|
400
|
+
pushEdge('insideH', borders.insideH);
|
|
401
|
+
pushEdge('insideV', borders.insideV);
|
|
402
|
+
pushEdge('tl2br', borders.tl2br);
|
|
403
|
+
pushEdge('tr2bl', borders.tr2bl);
|
|
404
|
+
if (existing !== undefined) {
|
|
405
|
+
try {
|
|
406
|
+
for (var _b = __values(elementChildren(existing)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
407
|
+
var child = _c.value;
|
|
408
|
+
if (!isWml(child, child.localName) || !modeled.has(child.localName)) {
|
|
409
|
+
children.push(child);
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
catch (e_6_1) { e_6 = { error: e_6_1 }; }
|
|
414
|
+
finally {
|
|
415
|
+
try {
|
|
416
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
417
|
+
}
|
|
418
|
+
finally { if (e_6) throw e_6.error; }
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
return wmlElement('tcBorders', { children: children });
|
|
422
|
+
}
|
|
423
|
+
// ---------------------------------------------------------------------------
|
|
424
|
+
// Margins (CT_TblCellMar / CT_TcMar)
|
|
425
|
+
// ---------------------------------------------------------------------------
|
|
426
|
+
function parseMarginEdge(el) {
|
|
427
|
+
var typeRaw = wmlAttrVal(el, 'type');
|
|
428
|
+
// Prefer dxa; accept missing type as dxa (common Word output).
|
|
429
|
+
if (typeRaw !== undefined && typeRaw !== 'dxa' && typeRaw !== 'auto' && typeRaw !== 'nil') {
|
|
430
|
+
// pct margins are rare; still accept numeric w as twips-like raw for round-trip via Point
|
|
431
|
+
if (typeRaw !== 'pct') {
|
|
432
|
+
return undefined;
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
var n = parseDecimalVal(wmlAttrVal(el, 'w'));
|
|
436
|
+
if (n === undefined) {
|
|
437
|
+
return undefined;
|
|
438
|
+
}
|
|
439
|
+
return twipsToPoint(n);
|
|
440
|
+
}
|
|
441
|
+
/**
|
|
442
|
+
* Parse table/cell margins. Maps `start`→`left`, `end`→`right`.
|
|
443
|
+
*
|
|
444
|
+
* @private
|
|
445
|
+
*/
|
|
446
|
+
export function parseCellMargins(el) {
|
|
447
|
+
var e_7, _a;
|
|
448
|
+
var top;
|
|
449
|
+
var right;
|
|
450
|
+
var bottom;
|
|
451
|
+
var left;
|
|
452
|
+
try {
|
|
453
|
+
for (var _b = __values(elementChildren(el)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
454
|
+
var child = _c.value;
|
|
455
|
+
if (!isWml(child, child.localName)) {
|
|
456
|
+
continue;
|
|
457
|
+
}
|
|
458
|
+
var len = parseMarginEdge(child);
|
|
459
|
+
if (len === undefined) {
|
|
460
|
+
continue;
|
|
461
|
+
}
|
|
462
|
+
switch (child.localName) {
|
|
463
|
+
case 'top':
|
|
464
|
+
top = len;
|
|
465
|
+
break;
|
|
466
|
+
case 'right':
|
|
467
|
+
case 'end':
|
|
468
|
+
right = len;
|
|
469
|
+
break;
|
|
470
|
+
case 'bottom':
|
|
471
|
+
bottom = len;
|
|
472
|
+
break;
|
|
473
|
+
case 'left':
|
|
474
|
+
case 'start':
|
|
475
|
+
left = len;
|
|
476
|
+
break;
|
|
477
|
+
default:
|
|
478
|
+
break;
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
catch (e_7_1) { e_7 = { error: e_7_1 }; }
|
|
483
|
+
finally {
|
|
484
|
+
try {
|
|
485
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
486
|
+
}
|
|
487
|
+
finally { if (e_7) throw e_7.error; }
|
|
488
|
+
}
|
|
489
|
+
return __assign({}, (top !== undefined ? { top: top } : {}), (right !== undefined ? { right: right } : {}), (bottom !== undefined ? { bottom: bottom } : {}), (left !== undefined ? { left: left } : {}));
|
|
490
|
+
}
|
|
491
|
+
function serializeMarginEdge(localName, value) {
|
|
492
|
+
return wmlElement(localName, {
|
|
493
|
+
attributes: [wmlAttr('w', String(pointToTwips(value))), wmlAttr('type', 'dxa')],
|
|
494
|
+
});
|
|
495
|
+
}
|
|
496
|
+
/**
|
|
497
|
+
* Serialize margins container (`tblCellMar` or `tcMar`) with Transitional left/right.
|
|
498
|
+
*
|
|
499
|
+
* @private
|
|
500
|
+
*/
|
|
501
|
+
export function serializeCellMargins(containerLocalName, margins, existing) {
|
|
502
|
+
var e_8, _a;
|
|
503
|
+
var modeled = new Set(['top', 'left', 'right', 'bottom', 'start', 'end']);
|
|
504
|
+
var children = [];
|
|
505
|
+
if (margins.top !== undefined) {
|
|
506
|
+
children.push(serializeMarginEdge('top', margins.top));
|
|
507
|
+
}
|
|
508
|
+
if (margins.left !== undefined) {
|
|
509
|
+
children.push(serializeMarginEdge('left', margins.left));
|
|
510
|
+
}
|
|
511
|
+
if (margins.bottom !== undefined) {
|
|
512
|
+
children.push(serializeMarginEdge('bottom', margins.bottom));
|
|
513
|
+
}
|
|
514
|
+
if (margins.right !== undefined) {
|
|
515
|
+
children.push(serializeMarginEdge('right', margins.right));
|
|
516
|
+
}
|
|
517
|
+
if (existing !== undefined) {
|
|
518
|
+
try {
|
|
519
|
+
for (var _b = __values(elementChildren(existing)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
520
|
+
var child = _c.value;
|
|
521
|
+
if (!isWml(child, child.localName) || !modeled.has(child.localName)) {
|
|
522
|
+
children.push(child);
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
catch (e_8_1) { e_8 = { error: e_8_1 }; }
|
|
527
|
+
finally {
|
|
528
|
+
try {
|
|
529
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
530
|
+
}
|
|
531
|
+
finally { if (e_8) throw e_8.error; }
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
return wmlElement(containerLocalName, { children: children });
|
|
535
|
+
}
|
|
536
|
+
// ---------------------------------------------------------------------------
|
|
537
|
+
// Shading
|
|
538
|
+
// ---------------------------------------------------------------------------
|
|
539
|
+
/**
|
|
540
|
+
* Parse `w:shd` (pattern is free string per task).
|
|
541
|
+
*
|
|
542
|
+
* @private
|
|
543
|
+
*/
|
|
544
|
+
export function parseShd(el) {
|
|
545
|
+
var fillRaw = wmlAttrVal(el, 'fill');
|
|
546
|
+
var colorRaw = wmlAttrVal(el, 'color');
|
|
547
|
+
var valRaw = wmlAttrVal(el, 'val');
|
|
548
|
+
return __assign({}, (fillRaw !== undefined ? { fill: fillRaw } : {}), (colorRaw !== undefined ? { color: colorRaw } : {}), (valRaw !== undefined ? { pattern: valRaw } : {}));
|
|
549
|
+
}
|
|
550
|
+
/**
|
|
551
|
+
* Serialize `w:shd` (order: pattern/val, color, fill).
|
|
552
|
+
*
|
|
553
|
+
* @private
|
|
554
|
+
*/
|
|
555
|
+
export function serializeShd(shd) {
|
|
556
|
+
var attrs = [];
|
|
557
|
+
if (shd.pattern !== undefined) {
|
|
558
|
+
attrs.push(wmlAttr('val', shd.pattern));
|
|
559
|
+
}
|
|
560
|
+
if (shd.color !== undefined) {
|
|
561
|
+
attrs.push(wmlAttr('color', shd.color));
|
|
562
|
+
}
|
|
563
|
+
if (shd.fill !== undefined) {
|
|
564
|
+
// ST_HexColor / 'auto': strip a leading '#' if present so invalid
|
|
565
|
+
// authoring input still emits a schema-valid wire value.
|
|
566
|
+
var fill = shd.fill;
|
|
567
|
+
if (fill.length > 0 && fill.charAt(0) === '#') {
|
|
568
|
+
fill = fill.slice(1);
|
|
569
|
+
}
|
|
570
|
+
attrs.push(wmlAttr('fill', fill));
|
|
571
|
+
}
|
|
572
|
+
return wmlElement('shd', { attributes: attrs });
|
|
573
|
+
}
|
|
574
|
+
// ---------------------------------------------------------------------------
|
|
575
|
+
// Alignment (ST_JcTable subset)
|
|
576
|
+
// ---------------------------------------------------------------------------
|
|
577
|
+
/**
|
|
578
|
+
* Parse table/row `w:jc` → public left|center|right (start→left, end→right).
|
|
579
|
+
*
|
|
580
|
+
* @private
|
|
581
|
+
*/
|
|
582
|
+
export function parseTableAlignment(el) {
|
|
583
|
+
var raw = wValAttribute(el);
|
|
584
|
+
if (raw === 'left' || raw === 'start') {
|
|
585
|
+
return 'left';
|
|
586
|
+
}
|
|
587
|
+
if (raw === 'right' || raw === 'end') {
|
|
588
|
+
return 'right';
|
|
589
|
+
}
|
|
590
|
+
if (raw === 'center') {
|
|
591
|
+
return 'center';
|
|
592
|
+
}
|
|
593
|
+
return undefined;
|
|
594
|
+
}
|
|
595
|
+
/**
|
|
596
|
+
* Serialize table/row alignment as Transitional left|center|right.
|
|
597
|
+
*
|
|
598
|
+
* @private
|
|
599
|
+
*/
|
|
600
|
+
export function serializeTableAlignment(alignment) {
|
|
601
|
+
return wmlElement('jc', { attributes: [wmlAttr('val', alignment)] });
|
|
602
|
+
}
|
|
603
|
+
// ---------------------------------------------------------------------------
|
|
604
|
+
// tblLook
|
|
605
|
+
// ---------------------------------------------------------------------------
|
|
606
|
+
/** ECMA-376 / Word `w:tblLook/@w:val` bit flags (when named attrs absent). */
|
|
607
|
+
var TBLLOOK_FIRST_ROW = 0x0020;
|
|
608
|
+
var TBLLOOK_LAST_ROW = 0x0040;
|
|
609
|
+
var TBLLOOK_FIRST_COLUMN = 0x0080;
|
|
610
|
+
var TBLLOOK_LAST_COLUMN = 0x0100;
|
|
611
|
+
var TBLLOOK_NO_H_BAND = 0x0200;
|
|
612
|
+
var TBLLOOK_NO_V_BAND = 0x0400;
|
|
613
|
+
function parseHexMask(raw) {
|
|
614
|
+
if (raw === undefined || raw.length === 0) {
|
|
615
|
+
return undefined;
|
|
616
|
+
}
|
|
617
|
+
// TS 3.3 / ES5 parity: avoid String.prototype.startsWith.
|
|
618
|
+
var cleaned = (raw.indexOf('0x') === 0 || raw.indexOf('0X') === 0) ? raw.slice(2) : raw;
|
|
619
|
+
if (!/^[0-9a-fA-F]+$/.test(cleaned)) {
|
|
620
|
+
return undefined;
|
|
621
|
+
}
|
|
622
|
+
return parseInt(cleaned, 16);
|
|
623
|
+
}
|
|
624
|
+
function onOffAttr(el, localName) {
|
|
625
|
+
var raw = wmlAttrVal(el, localName);
|
|
626
|
+
if (raw === undefined) {
|
|
627
|
+
return undefined;
|
|
628
|
+
}
|
|
629
|
+
if (raw === '1' || raw === 'true' || raw === 'on') {
|
|
630
|
+
return true;
|
|
631
|
+
}
|
|
632
|
+
if (raw === '0' || raw === 'false' || raw === 'off') {
|
|
633
|
+
return false;
|
|
634
|
+
}
|
|
635
|
+
return undefined;
|
|
636
|
+
}
|
|
637
|
+
/**
|
|
638
|
+
* Parse `w:tblLook` named onOff attrs and/or legacy hex `@w:val`.
|
|
639
|
+
*
|
|
640
|
+
* @private
|
|
641
|
+
*/
|
|
642
|
+
export function parseTblLook(el) {
|
|
643
|
+
var firstRow = onOffAttr(el, 'firstRow');
|
|
644
|
+
var lastRow = onOffAttr(el, 'lastRow');
|
|
645
|
+
var firstCol = onOffAttr(el, 'firstColumn');
|
|
646
|
+
var lastCol = onOffAttr(el, 'lastColumn');
|
|
647
|
+
var noHBand = onOffAttr(el, 'noHBand');
|
|
648
|
+
var noVBand = onOffAttr(el, 'noVBand');
|
|
649
|
+
var mask = parseHexMask(wmlAttrVal(el, 'val'));
|
|
650
|
+
if (mask !== undefined) {
|
|
651
|
+
if (firstRow === undefined) {
|
|
652
|
+
firstRow = (mask & TBLLOOK_FIRST_ROW) !== 0;
|
|
653
|
+
}
|
|
654
|
+
if (lastRow === undefined) {
|
|
655
|
+
lastRow = (mask & TBLLOOK_LAST_ROW) !== 0;
|
|
656
|
+
}
|
|
657
|
+
if (firstCol === undefined) {
|
|
658
|
+
firstCol = (mask & TBLLOOK_FIRST_COLUMN) !== 0;
|
|
659
|
+
}
|
|
660
|
+
if (lastCol === undefined) {
|
|
661
|
+
lastCol = (mask & TBLLOOK_LAST_COLUMN) !== 0;
|
|
662
|
+
}
|
|
663
|
+
if (noHBand === undefined) {
|
|
664
|
+
noHBand = (mask & TBLLOOK_NO_H_BAND) !== 0;
|
|
665
|
+
}
|
|
666
|
+
if (noVBand === undefined) {
|
|
667
|
+
noVBand = (mask & TBLLOOK_NO_V_BAND) !== 0;
|
|
668
|
+
}
|
|
669
|
+
}
|
|
670
|
+
return __assign({}, (firstRow !== undefined ? { firstRow: firstRow } : {}), (lastRow !== undefined ? { lastRow: lastRow } : {}), (firstCol !== undefined ? { firstCol: firstCol } : {}), (lastCol !== undefined ? { lastCol: lastCol } : {}), (noHBand !== undefined ? { noHBand: noHBand } : {}), (noVBand !== undefined ? { noVBand: noVBand } : {}));
|
|
671
|
+
}
|
|
672
|
+
function pushOnOffAttr(attrs, localName, value) {
|
|
673
|
+
if (value === undefined) {
|
|
674
|
+
return;
|
|
675
|
+
}
|
|
676
|
+
attrs.push(wmlAttr(localName, value ? '1' : '0'));
|
|
677
|
+
}
|
|
678
|
+
/**
|
|
679
|
+
* Serialize `w:tblLook` with named onOff attributes (preferred over hex-only).
|
|
680
|
+
*
|
|
681
|
+
* @private
|
|
682
|
+
*/
|
|
683
|
+
export function serializeTblLook(look) {
|
|
684
|
+
var attrs = [];
|
|
685
|
+
pushOnOffAttr(attrs, 'firstRow', look.firstRow);
|
|
686
|
+
pushOnOffAttr(attrs, 'lastRow', look.lastRow);
|
|
687
|
+
pushOnOffAttr(attrs, 'firstColumn', look.firstCol);
|
|
688
|
+
pushOnOffAttr(attrs, 'lastColumn', look.lastCol);
|
|
689
|
+
pushOnOffAttr(attrs, 'noHBand', look.noHBand);
|
|
690
|
+
pushOnOffAttr(attrs, 'noVBand', look.noVBand);
|
|
691
|
+
return wmlElement('tblLook', { attributes: attrs });
|
|
692
|
+
}
|
|
693
|
+
/**
|
|
694
|
+
* DocIO / transitional ST_Cnf character positions (1-based LTR) → CT_Cnf fields.
|
|
695
|
+
* Corner bit order (positions 9–12): firstRowLastColumn, firstRowFirstColumn,
|
|
696
|
+
* lastRowLastColumn, lastRowFirstColumn. Named XML attrs still emit NW→SE order.
|
|
697
|
+
*/
|
|
698
|
+
var CNF_VAL_FIELDS = [
|
|
699
|
+
'firstRow',
|
|
700
|
+
'lastRow',
|
|
701
|
+
'firstColumn',
|
|
702
|
+
'lastColumn',
|
|
703
|
+
'oddVBand',
|
|
704
|
+
'evenVBand',
|
|
705
|
+
'oddHBand',
|
|
706
|
+
'evenHBand',
|
|
707
|
+
'firstRowLastColumn',
|
|
708
|
+
'firstRowFirstColumn',
|
|
709
|
+
'lastRowLastColumn',
|
|
710
|
+
'lastRowFirstColumn',
|
|
711
|
+
];
|
|
712
|
+
var CNF_KNOWN_ATTRS = {
|
|
713
|
+
val: true,
|
|
714
|
+
firstRow: true,
|
|
715
|
+
lastRow: true,
|
|
716
|
+
firstColumn: true,
|
|
717
|
+
lastColumn: true,
|
|
718
|
+
oddVBand: true,
|
|
719
|
+
evenVBand: true,
|
|
720
|
+
oddHBand: true,
|
|
721
|
+
evenHBand: true,
|
|
722
|
+
firstRowFirstColumn: true,
|
|
723
|
+
firstRowLastColumn: true,
|
|
724
|
+
lastRowFirstColumn: true,
|
|
725
|
+
lastRowLastColumn: true,
|
|
726
|
+
};
|
|
727
|
+
function parseCnfValMask(raw) {
|
|
728
|
+
if (raw === undefined || raw.length !== 12 || !/^[01]{12}$/.test(raw)) {
|
|
729
|
+
return undefined;
|
|
730
|
+
}
|
|
731
|
+
return raw;
|
|
732
|
+
}
|
|
733
|
+
function cnfStyleHasAny(state) {
|
|
734
|
+
for (var i = 0; i < CNF_VAL_FIELDS.length; i++) {
|
|
735
|
+
if (state[CNF_VAL_FIELDS[i]] !== undefined) {
|
|
736
|
+
return true;
|
|
737
|
+
}
|
|
738
|
+
}
|
|
739
|
+
return false;
|
|
740
|
+
}
|
|
741
|
+
/**
|
|
742
|
+
* All-false normalized conditional membership.
|
|
743
|
+
*
|
|
744
|
+
* @private
|
|
745
|
+
*/
|
|
746
|
+
export function createDefaultCnfStyle() {
|
|
747
|
+
return {
|
|
748
|
+
firstRow: false,
|
|
749
|
+
lastRow: false,
|
|
750
|
+
firstColumn: false,
|
|
751
|
+
lastColumn: false,
|
|
752
|
+
oddVBand: false,
|
|
753
|
+
evenVBand: false,
|
|
754
|
+
oddHBand: false,
|
|
755
|
+
evenHBand: false,
|
|
756
|
+
firstRowFirstColumn: false,
|
|
757
|
+
firstRowLastColumn: false,
|
|
758
|
+
lastRowFirstColumn: false,
|
|
759
|
+
lastRowLastColumn: false,
|
|
760
|
+
};
|
|
761
|
+
}
|
|
762
|
+
/**
|
|
763
|
+
* Coerce partial/optional {@link CnfStyle} into a fully boolean {@link NormalizedCnfStyle}.
|
|
764
|
+
*
|
|
765
|
+
* @private
|
|
766
|
+
*/
|
|
767
|
+
export function normalizeCnfStyle(state) {
|
|
768
|
+
return {
|
|
769
|
+
firstRow: state !== undefined && state.firstRow === true,
|
|
770
|
+
lastRow: state !== undefined && state.lastRow === true,
|
|
771
|
+
firstColumn: state !== undefined && state.firstColumn === true,
|
|
772
|
+
lastColumn: state !== undefined && state.lastColumn === true,
|
|
773
|
+
oddVBand: state !== undefined && state.oddVBand === true,
|
|
774
|
+
evenVBand: state !== undefined && state.evenVBand === true,
|
|
775
|
+
oddHBand: state !== undefined && state.oddHBand === true,
|
|
776
|
+
evenHBand: state !== undefined && state.evenHBand === true,
|
|
777
|
+
firstRowFirstColumn: state !== undefined && state.firstRowFirstColumn === true,
|
|
778
|
+
firstRowLastColumn: state !== undefined && state.firstRowLastColumn === true,
|
|
779
|
+
lastRowFirstColumn: state !== undefined && state.lastRowFirstColumn === true,
|
|
780
|
+
lastRowLastColumn: state !== undefined && state.lastRowLastColumn === true,
|
|
781
|
+
};
|
|
782
|
+
}
|
|
783
|
+
/**
|
|
784
|
+
* True when any named flag is true on a normalized state.
|
|
785
|
+
*
|
|
786
|
+
* @private
|
|
787
|
+
*/
|
|
788
|
+
export function normalizedCnfStyleHasTrue(state) {
|
|
789
|
+
for (var i = 0; i < CNF_VAL_FIELDS.length; i++) {
|
|
790
|
+
if (state[CNF_VAL_FIELDS[i]] === true) {
|
|
791
|
+
return true;
|
|
792
|
+
}
|
|
793
|
+
}
|
|
794
|
+
return false;
|
|
795
|
+
}
|
|
796
|
+
/**
|
|
797
|
+
* Alias of {@link normalizedCnfStyleHasTrue} (DocIO placement helper name).
|
|
798
|
+
*
|
|
799
|
+
* @private
|
|
800
|
+
*/
|
|
801
|
+
export function hasAnyCnfStyleFlag(state) {
|
|
802
|
+
return normalizedCnfStyleHasTrue(state);
|
|
803
|
+
}
|
|
804
|
+
/**
|
|
805
|
+
* Parse `w:cnfStyle` named OnOff attributes and/or transitional `@w:val` ST_Cnf.
|
|
806
|
+
* Named attributes win when both forms are present (same rule as {@link parseTblLook}).
|
|
807
|
+
*
|
|
808
|
+
* @private
|
|
809
|
+
*/
|
|
810
|
+
export function parseCnfStyle(el) {
|
|
811
|
+
// Mutable bag — CnfStyle fields are readonly on the public shape.
|
|
812
|
+
var named = {
|
|
813
|
+
firstRow: onOffAttr(el, 'firstRow'),
|
|
814
|
+
lastRow: onOffAttr(el, 'lastRow'),
|
|
815
|
+
firstColumn: onOffAttr(el, 'firstColumn'),
|
|
816
|
+
lastColumn: onOffAttr(el, 'lastColumn'),
|
|
817
|
+
oddVBand: onOffAttr(el, 'oddVBand'),
|
|
818
|
+
evenVBand: onOffAttr(el, 'evenVBand'),
|
|
819
|
+
oddHBand: onOffAttr(el, 'oddHBand'),
|
|
820
|
+
evenHBand: onOffAttr(el, 'evenHBand'),
|
|
821
|
+
firstRowFirstColumn: onOffAttr(el, 'firstRowFirstColumn'),
|
|
822
|
+
firstRowLastColumn: onOffAttr(el, 'firstRowLastColumn'),
|
|
823
|
+
lastRowFirstColumn: onOffAttr(el, 'lastRowFirstColumn'),
|
|
824
|
+
lastRowLastColumn: onOffAttr(el, 'lastRowLastColumn'),
|
|
825
|
+
};
|
|
826
|
+
var mask = parseCnfValMask(wmlAttrVal(el, 'val'));
|
|
827
|
+
if (mask !== undefined) {
|
|
828
|
+
for (var i = 0; i < CNF_VAL_FIELDS.length; i++) {
|
|
829
|
+
var key = CNF_VAL_FIELDS[i];
|
|
830
|
+
if (named[key] === undefined) {
|
|
831
|
+
named[key] = mask.charAt(i) === '1';
|
|
832
|
+
}
|
|
833
|
+
}
|
|
834
|
+
}
|
|
835
|
+
var out = {};
|
|
836
|
+
for (var i = 0; i < CNF_VAL_FIELDS.length; i++) {
|
|
837
|
+
var key = CNF_VAL_FIELDS[i];
|
|
838
|
+
var value = named[key];
|
|
839
|
+
if (value !== undefined) {
|
|
840
|
+
out[key] = value;
|
|
841
|
+
}
|
|
842
|
+
}
|
|
843
|
+
return out;
|
|
844
|
+
}
|
|
845
|
+
/**
|
|
846
|
+
* Serialize `w:cnfStyle` with `w:val` first, then all twelve named OnOff attrs
|
|
847
|
+
* as explicit `0`/`1`. Preserves unknown attributes, namespaces, and children.
|
|
848
|
+
*
|
|
849
|
+
* @private
|
|
850
|
+
*/
|
|
851
|
+
export function serializeCnfStyle(state, existing) {
|
|
852
|
+
var val = '';
|
|
853
|
+
for (var i = 0; i < CNF_VAL_FIELDS.length; i += 1) {
|
|
854
|
+
var key = CNF_VAL_FIELDS[i];
|
|
855
|
+
val += state[key] ? '1' : '0';
|
|
856
|
+
}
|
|
857
|
+
var attrs = [
|
|
858
|
+
wmlAttr('val', val),
|
|
859
|
+
wmlAttr('firstRow', state.firstRow ? '1' : '0'),
|
|
860
|
+
wmlAttr('lastRow', state.lastRow ? '1' : '0'),
|
|
861
|
+
wmlAttr('firstColumn', state.firstColumn ? '1' : '0'),
|
|
862
|
+
wmlAttr('lastColumn', state.lastColumn ? '1' : '0'),
|
|
863
|
+
wmlAttr('oddVBand', state.oddVBand ? '1' : '0'),
|
|
864
|
+
wmlAttr('evenVBand', state.evenVBand ? '1' : '0'),
|
|
865
|
+
wmlAttr('oddHBand', state.oddHBand ? '1' : '0'),
|
|
866
|
+
wmlAttr('evenHBand', state.evenHBand ? '1' : '0'),
|
|
867
|
+
wmlAttr('firstRowFirstColumn', state.firstRowFirstColumn ? '1' : '0'),
|
|
868
|
+
wmlAttr('firstRowLastColumn', state.firstRowLastColumn ? '1' : '0'),
|
|
869
|
+
wmlAttr('lastRowFirstColumn', state.lastRowFirstColumn ? '1' : '0'),
|
|
870
|
+
wmlAttr('lastRowLastColumn', state.lastRowLastColumn ? '1' : '0'),
|
|
871
|
+
];
|
|
872
|
+
if (existing !== undefined) {
|
|
873
|
+
for (var i = 0; i < existing.attributes.length; i += 1) {
|
|
874
|
+
var attr = existing.attributes[i];
|
|
875
|
+
if (CNF_KNOWN_ATTRS[attr.localName] === true) {
|
|
876
|
+
continue;
|
|
877
|
+
}
|
|
878
|
+
attrs.push(attr);
|
|
879
|
+
}
|
|
880
|
+
}
|
|
881
|
+
return wmlElement('cnfStyle', {
|
|
882
|
+
attributes: attrs,
|
|
883
|
+
namespaceDeclarations: existing !== undefined ? existing.namespaceDeclarations : undefined,
|
|
884
|
+
children: existing !== undefined ? elementChildren(existing) : undefined,
|
|
885
|
+
});
|
|
886
|
+
}
|
|
887
|
+
/**
|
|
888
|
+
* True when any `CnfStyle` flag is explicitly set (including `false`).
|
|
889
|
+
*
|
|
890
|
+
* @private
|
|
891
|
+
*/
|
|
892
|
+
export function cnfStyleIsEmpty(state) {
|
|
893
|
+
return !cnfStyleHasAny(state);
|
|
894
|
+
}
|
|
895
|
+
// ---------------------------------------------------------------------------
|
|
896
|
+
// String-valued children (caption / description)
|
|
897
|
+
// ---------------------------------------------------------------------------
|
|
898
|
+
function parseStringVal(el) {
|
|
899
|
+
return wValAttribute(el);
|
|
900
|
+
}
|
|
901
|
+
function serializeStringVal(localName, value) {
|
|
902
|
+
return wmlElement(localName, { attributes: [wmlAttr('val', value)] });
|
|
903
|
+
}
|
|
904
|
+
// ---------------------------------------------------------------------------
|
|
905
|
+
// tblPr read / write
|
|
906
|
+
// ---------------------------------------------------------------------------
|
|
907
|
+
function ensureTblPr(tblPr) {
|
|
908
|
+
return tblPr != null ? tblPr : wmlElement('tblPr');
|
|
909
|
+
}
|
|
910
|
+
function writeTblChild(tblPr, localName, replacement) {
|
|
911
|
+
return upsertPropChild(ensureTblPr(tblPr), 'tblPr', localName, replacement);
|
|
912
|
+
}
|
|
913
|
+
/**
|
|
914
|
+
* @private
|
|
915
|
+
*/
|
|
916
|
+
export function readTableAlignment(tblPr) {
|
|
917
|
+
var el = findWmlChild(tblPr, 'jc');
|
|
918
|
+
return el !== undefined ? parseTableAlignment(el) : undefined;
|
|
919
|
+
}
|
|
920
|
+
/**
|
|
921
|
+
* @private
|
|
922
|
+
*/
|
|
923
|
+
export function writeTableAlignment(tblPr, alignment) {
|
|
924
|
+
return writeTblChild(tblPr, 'jc', alignment !== undefined ? serializeTableAlignment(alignment) : undefined);
|
|
925
|
+
}
|
|
926
|
+
/**
|
|
927
|
+
* @private
|
|
928
|
+
*/
|
|
929
|
+
export function readTableIndent(tblPr) {
|
|
930
|
+
var el = findWmlChild(tblPr, 'tblInd');
|
|
931
|
+
if (el === undefined) {
|
|
932
|
+
return undefined;
|
|
933
|
+
}
|
|
934
|
+
var n = parseDecimalVal(wmlAttrVal(el, 'w'));
|
|
935
|
+
if (n === undefined) {
|
|
936
|
+
return undefined;
|
|
937
|
+
}
|
|
938
|
+
return twipsToPoint(n);
|
|
939
|
+
}
|
|
940
|
+
/**
|
|
941
|
+
* @private
|
|
942
|
+
*/
|
|
943
|
+
export function writeTableIndent(tblPr, indent) {
|
|
944
|
+
if (indent === undefined) {
|
|
945
|
+
return writeTblChild(tblPr, 'tblInd', undefined);
|
|
946
|
+
}
|
|
947
|
+
var element = wmlElement('tblInd', {
|
|
948
|
+
attributes: [wmlAttr('w', String(pointToTwips(indent))), wmlAttr('type', 'dxa')],
|
|
949
|
+
});
|
|
950
|
+
return writeTblChild(tblPr, 'tblInd', element);
|
|
951
|
+
}
|
|
952
|
+
/**
|
|
953
|
+
* @private
|
|
954
|
+
*/
|
|
955
|
+
export function readTablePreferredWidth(tblPr) {
|
|
956
|
+
var el = findWmlChild(tblPr, 'tblW');
|
|
957
|
+
return el !== undefined ? parseTblWidth(el) : undefined;
|
|
958
|
+
}
|
|
959
|
+
/**
|
|
960
|
+
* @private
|
|
961
|
+
*/
|
|
962
|
+
export function writeTablePreferredWidth(tblPr, width) {
|
|
963
|
+
return writeTblChild(tblPr, 'tblW', width !== undefined ? serializeTblWidth('tblW', width) : undefined);
|
|
964
|
+
}
|
|
965
|
+
/**
|
|
966
|
+
* @private
|
|
967
|
+
*/
|
|
968
|
+
export function readTableBorders(tblPr) {
|
|
969
|
+
var el = findWmlChild(tblPr, 'tblBorders');
|
|
970
|
+
if (el === undefined) {
|
|
971
|
+
return undefined;
|
|
972
|
+
}
|
|
973
|
+
var borders = parseTblBorders(el);
|
|
974
|
+
if (borders.top === undefined &&
|
|
975
|
+
borders.left === undefined &&
|
|
976
|
+
borders.bottom === undefined &&
|
|
977
|
+
borders.right === undefined &&
|
|
978
|
+
borders.insideH === undefined &&
|
|
979
|
+
borders.insideV === undefined) {
|
|
980
|
+
return undefined;
|
|
981
|
+
}
|
|
982
|
+
return borders;
|
|
983
|
+
}
|
|
984
|
+
/**
|
|
985
|
+
* @private
|
|
986
|
+
*/
|
|
987
|
+
export function writeTableBorders(tblPr, borders) {
|
|
988
|
+
var existing = findWmlChild(tblPr, 'tblBorders');
|
|
989
|
+
return writeTblChild(tblPr, 'tblBorders', borders !== undefined ? serializeTblBorders(borders, existing) : undefined);
|
|
990
|
+
}
|
|
991
|
+
/**
|
|
992
|
+
* @private
|
|
993
|
+
*/
|
|
994
|
+
export function readTableCellMargins(tblPr) {
|
|
995
|
+
var el = findWmlChild(tblPr, 'tblCellMar');
|
|
996
|
+
if (el === undefined) {
|
|
997
|
+
return undefined;
|
|
998
|
+
}
|
|
999
|
+
var m = parseCellMargins(el);
|
|
1000
|
+
if (m.top === undefined &&
|
|
1001
|
+
m.right === undefined &&
|
|
1002
|
+
m.bottom === undefined &&
|
|
1003
|
+
m.left === undefined) {
|
|
1004
|
+
return undefined;
|
|
1005
|
+
}
|
|
1006
|
+
return m;
|
|
1007
|
+
}
|
|
1008
|
+
/**
|
|
1009
|
+
* @private
|
|
1010
|
+
*/
|
|
1011
|
+
export function writeTableCellMargins(tblPr, margins) {
|
|
1012
|
+
var existing = findWmlChild(tblPr, 'tblCellMar');
|
|
1013
|
+
return writeTblChild(tblPr, 'tblCellMar', margins !== undefined ? serializeCellMargins('tblCellMar', margins, existing) : undefined);
|
|
1014
|
+
}
|
|
1015
|
+
/**
|
|
1016
|
+
* @private
|
|
1017
|
+
*/
|
|
1018
|
+
export function readTableCellSpacing(tblPr) {
|
|
1019
|
+
var el = findWmlChild(tblPr, 'tblCellSpacing');
|
|
1020
|
+
if (el === undefined) {
|
|
1021
|
+
return undefined;
|
|
1022
|
+
}
|
|
1023
|
+
var n = parseDecimalVal(wmlAttrVal(el, 'w'));
|
|
1024
|
+
if (n === undefined) {
|
|
1025
|
+
return undefined;
|
|
1026
|
+
}
|
|
1027
|
+
return twipsToPoint(n);
|
|
1028
|
+
}
|
|
1029
|
+
/**
|
|
1030
|
+
* @private
|
|
1031
|
+
*/
|
|
1032
|
+
export function writeTableCellSpacing(tblPr, spacing) {
|
|
1033
|
+
if (spacing === undefined) {
|
|
1034
|
+
return writeTblChild(tblPr, 'tblCellSpacing', undefined);
|
|
1035
|
+
}
|
|
1036
|
+
var element = wmlElement('tblCellSpacing', {
|
|
1037
|
+
attributes: [wmlAttr('w', String(pointToTwips(spacing))), wmlAttr('type', 'dxa')],
|
|
1038
|
+
});
|
|
1039
|
+
return writeTblChild(tblPr, 'tblCellSpacing', element);
|
|
1040
|
+
}
|
|
1041
|
+
/**
|
|
1042
|
+
* @private
|
|
1043
|
+
*/
|
|
1044
|
+
export function readTableShading(tblPr) {
|
|
1045
|
+
var el = findWmlChild(tblPr, 'shd');
|
|
1046
|
+
if (el === undefined) {
|
|
1047
|
+
return undefined;
|
|
1048
|
+
}
|
|
1049
|
+
var shd = parseShd(el);
|
|
1050
|
+
if (shd.fill === undefined && shd.color === undefined && shd.pattern === undefined) {
|
|
1051
|
+
return undefined;
|
|
1052
|
+
}
|
|
1053
|
+
return shd;
|
|
1054
|
+
}
|
|
1055
|
+
/**
|
|
1056
|
+
* @private
|
|
1057
|
+
*/
|
|
1058
|
+
export function writeTableShading(tblPr, shading) {
|
|
1059
|
+
return writeTblChild(tblPr, 'shd', shading !== undefined ? serializeShd(shading) : undefined);
|
|
1060
|
+
}
|
|
1061
|
+
/**
|
|
1062
|
+
* @private
|
|
1063
|
+
*/
|
|
1064
|
+
export function readTableLook(tblPr) {
|
|
1065
|
+
var el = findWmlChild(tblPr, 'tblLook');
|
|
1066
|
+
if (el === undefined) {
|
|
1067
|
+
return undefined;
|
|
1068
|
+
}
|
|
1069
|
+
var look = parseTblLook(el);
|
|
1070
|
+
if (look.firstRow === undefined &&
|
|
1071
|
+
look.lastRow === undefined &&
|
|
1072
|
+
look.firstCol === undefined &&
|
|
1073
|
+
look.lastCol === undefined &&
|
|
1074
|
+
look.noHBand === undefined &&
|
|
1075
|
+
look.noVBand === undefined) {
|
|
1076
|
+
return undefined;
|
|
1077
|
+
}
|
|
1078
|
+
return look;
|
|
1079
|
+
}
|
|
1080
|
+
/**
|
|
1081
|
+
* @private
|
|
1082
|
+
*/
|
|
1083
|
+
export function writeTableLook(tblPr, look) {
|
|
1084
|
+
return writeTblChild(tblPr, 'tblLook', look !== undefined ? serializeTblLook(look) : undefined);
|
|
1085
|
+
}
|
|
1086
|
+
/**
|
|
1087
|
+
* @private
|
|
1088
|
+
*/
|
|
1089
|
+
export function readTableCaption(tblPr) {
|
|
1090
|
+
var el = findWmlChild(tblPr, 'tblCaption');
|
|
1091
|
+
return el !== undefined ? parseStringVal(el) : undefined;
|
|
1092
|
+
}
|
|
1093
|
+
/**
|
|
1094
|
+
* @private
|
|
1095
|
+
*/
|
|
1096
|
+
export function writeTableCaption(tblPr, caption) {
|
|
1097
|
+
return writeTblChild(tblPr, 'tblCaption', caption !== undefined ? serializeStringVal('tblCaption', caption) : undefined);
|
|
1098
|
+
}
|
|
1099
|
+
/**
|
|
1100
|
+
* @private
|
|
1101
|
+
*/
|
|
1102
|
+
export function readTableDescription(tblPr) {
|
|
1103
|
+
var el = findWmlChild(tblPr, 'tblDescription');
|
|
1104
|
+
return el !== undefined ? parseStringVal(el) : undefined;
|
|
1105
|
+
}
|
|
1106
|
+
/**
|
|
1107
|
+
* @private
|
|
1108
|
+
*/
|
|
1109
|
+
export function writeTableDescription(tblPr, description) {
|
|
1110
|
+
return writeTblChild(tblPr, 'tblDescription', description !== undefined ? serializeStringVal('tblDescription', description) : undefined);
|
|
1111
|
+
}
|
|
1112
|
+
/**
|
|
1113
|
+
* Read `w:tblStyle/@w:val`.
|
|
1114
|
+
*
|
|
1115
|
+
* @private
|
|
1116
|
+
*/
|
|
1117
|
+
export function readTableStyle(tblPr) {
|
|
1118
|
+
var el = findWmlChild(tblPr, 'tblStyle');
|
|
1119
|
+
return el !== undefined ? parseStringVal(el) : undefined;
|
|
1120
|
+
}
|
|
1121
|
+
/**
|
|
1122
|
+
* Write or clear `w:tblStyle`.
|
|
1123
|
+
*
|
|
1124
|
+
* @private
|
|
1125
|
+
*/
|
|
1126
|
+
export function writeTableStyle(tblPr, styleId) {
|
|
1127
|
+
return writeTblChild(tblPr, 'tblStyle', styleId !== undefined ? serializeStringVal('tblStyle', styleId) : undefined);
|
|
1128
|
+
}
|
|
1129
|
+
/**
|
|
1130
|
+
* Read `w:tblLayout/@w:type` → public {@link TableLayout}.
|
|
1131
|
+
*
|
|
1132
|
+
* Absent element → `autoFit`. Unknown wire tokens leave the child untouched and
|
|
1133
|
+
* return `autoFit` for the typed surface (extras preserved on the element).
|
|
1134
|
+
*
|
|
1135
|
+
* @private
|
|
1136
|
+
*/
|
|
1137
|
+
export function readTableLayout(tblPr) {
|
|
1138
|
+
var el = findWmlChild(tblPr, 'tblLayout');
|
|
1139
|
+
if (el === undefined) {
|
|
1140
|
+
return 'autoFit';
|
|
1141
|
+
}
|
|
1142
|
+
var raw = wmlAttrVal(el, 'type');
|
|
1143
|
+
if (raw === 'fixed') {
|
|
1144
|
+
return 'fixed';
|
|
1145
|
+
}
|
|
1146
|
+
// `autofit`, missing type, or unknown → public autoFit (default algorithm).
|
|
1147
|
+
return 'autoFit';
|
|
1148
|
+
}
|
|
1149
|
+
/**
|
|
1150
|
+
* Write `w:tblLayout`. Omit-on-default: `autoFit` removes the element;
|
|
1151
|
+
* `fixed` emits `<w:tblLayout w:type="fixed"/>`.
|
|
1152
|
+
*
|
|
1153
|
+
* @private
|
|
1154
|
+
*/
|
|
1155
|
+
export function writeTableLayout(tblPr, layout) {
|
|
1156
|
+
if (layout === 'autoFit') {
|
|
1157
|
+
return writeTblChild(tblPr, 'tblLayout', undefined);
|
|
1158
|
+
}
|
|
1159
|
+
return writeTblChild(tblPr, 'tblLayout', wmlElement('tblLayout', { attributes: [wmlAttr('type', 'fixed')] }));
|
|
1160
|
+
}
|
|
1161
|
+
/**
|
|
1162
|
+
* Read `w:tblStyleRowBandSize/@w:val` (`CT_DecimalNumber`).
|
|
1163
|
+
*
|
|
1164
|
+
* Absent or non-integer wire → `undefined` (consumer default band height is 1).
|
|
1165
|
+
* Citations: ECMA-376-1 §17.7.6.7; Transitional `wml.xsd` `CT_TblPrBase`.
|
|
1166
|
+
*
|
|
1167
|
+
* @private
|
|
1168
|
+
*/
|
|
1169
|
+
export function readTableRowBandSize(tblPr) {
|
|
1170
|
+
var el = findWmlChild(tblPr, 'tblStyleRowBandSize');
|
|
1171
|
+
if (el === undefined) {
|
|
1172
|
+
return undefined;
|
|
1173
|
+
}
|
|
1174
|
+
return parseDecimalVal(wValAttribute(el));
|
|
1175
|
+
}
|
|
1176
|
+
/**
|
|
1177
|
+
* Write or clear `w:tblStyleRowBandSize`. Emitted only when `size` is defined.
|
|
1178
|
+
*
|
|
1179
|
+
* @private
|
|
1180
|
+
*/
|
|
1181
|
+
export function writeTableRowBandSize(tblPr, size) {
|
|
1182
|
+
return writeTblChild(tblPr, 'tblStyleRowBandSize', size !== undefined ? serializeStringVal('tblStyleRowBandSize', String(size)) : undefined);
|
|
1183
|
+
}
|
|
1184
|
+
/**
|
|
1185
|
+
* Read `w:tblStyleColBandSize/@w:val` (`CT_DecimalNumber`).
|
|
1186
|
+
*
|
|
1187
|
+
* Absent or non-integer wire → `undefined` (consumer default band width is 1).
|
|
1188
|
+
* Citations: ECMA-376-1 §17.7.6.5; Transitional `wml.xsd` `CT_TblPrBase`.
|
|
1189
|
+
*
|
|
1190
|
+
* @private
|
|
1191
|
+
*/
|
|
1192
|
+
export function readTableColumnBandSize(tblPr) {
|
|
1193
|
+
var el = findWmlChild(tblPr, 'tblStyleColBandSize');
|
|
1194
|
+
if (el === undefined) {
|
|
1195
|
+
return undefined;
|
|
1196
|
+
}
|
|
1197
|
+
return parseDecimalVal(wValAttribute(el));
|
|
1198
|
+
}
|
|
1199
|
+
/**
|
|
1200
|
+
* Write or clear `w:tblStyleColBandSize`. Emitted only when `size` is defined.
|
|
1201
|
+
*
|
|
1202
|
+
* @private
|
|
1203
|
+
*/
|
|
1204
|
+
export function writeTableColumnBandSize(tblPr, size) {
|
|
1205
|
+
return writeTblChild(tblPr, 'tblStyleColBandSize', size !== undefined ? serializeStringVal('tblStyleColBandSize', String(size)) : undefined);
|
|
1206
|
+
}
|
|
1207
|
+
// Re-export on-off for tr/tc consumers that need serializeOnOff without extra imports coupling
|
|
1208
|
+
export { parseOnOff, serializeOnOff };
|