@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,714 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Document-owned live StyleCollection (public Styles DOM).
|
|
3
|
+
*
|
|
4
|
+
* Merges live authoring APIs (paragraph/character facades, StyleOwner) with
|
|
5
|
+
* table-style support, pending ensure, and stable DocxStyle projection cache.
|
|
6
|
+
*
|
|
7
|
+
* @public
|
|
8
|
+
*/
|
|
9
|
+
import { DocxError, InvalidArgumentError } from '../../core/errors/docx-error';
|
|
10
|
+
import { wmlAttr, wmlElement } from '../document/wml';
|
|
11
|
+
import { normalizeStyleName } from './builtin-catalog';
|
|
12
|
+
import { resolveReferencedStyle, resolveStyleForTarget } from './builtin-resolver';
|
|
13
|
+
import { CharacterStyle, createMinimalStyle, createStyleFromDocxStyle, ParagraphStyle, } from './style-base';
|
|
14
|
+
import { createMinimalDocxStyle, DocxStyle } from './style';
|
|
15
|
+
import { TableStyle } from './table-style';
|
|
16
|
+
/**
|
|
17
|
+
* Public styles collection on {@link WordDocument.styles}.
|
|
18
|
+
*
|
|
19
|
+
* Stable identity: `document.styles === document.styles`.
|
|
20
|
+
* Entry identity: `getStyle(id) === getStyle(id)`.
|
|
21
|
+
*
|
|
22
|
+
* @public
|
|
23
|
+
*/
|
|
24
|
+
var StyleCollection = /** @class */ (function () {
|
|
25
|
+
/**
|
|
26
|
+
* @private
|
|
27
|
+
*/
|
|
28
|
+
function StyleCollection(document, host, initial) {
|
|
29
|
+
if (initial === void 0) { initial = []; }
|
|
30
|
+
this.cachedLength = 0;
|
|
31
|
+
this.document = document;
|
|
32
|
+
this.host = host;
|
|
33
|
+
this.styleList = [];
|
|
34
|
+
this.styleById = new Map();
|
|
35
|
+
this.pendingParagraphStyles = new Set();
|
|
36
|
+
this.pendingCharacterStyles = new Set();
|
|
37
|
+
this.pendingTableStyles = new Set();
|
|
38
|
+
this.projected = new Map();
|
|
39
|
+
void this.document;
|
|
40
|
+
for (var i = 0; i < initial.length; i += 1) {
|
|
41
|
+
var style = initial[i];
|
|
42
|
+
this.attachAndIndex(style, false);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
Object.defineProperty(StyleCollection.prototype, "ownerDocument", {
|
|
46
|
+
/**
|
|
47
|
+
* Owning document.
|
|
48
|
+
*
|
|
49
|
+
* @private
|
|
50
|
+
*/
|
|
51
|
+
get: function () {
|
|
52
|
+
return this.document;
|
|
53
|
+
},
|
|
54
|
+
enumerable: true,
|
|
55
|
+
configurable: true
|
|
56
|
+
});
|
|
57
|
+
Object.defineProperty(StyleCollection.prototype, "count", {
|
|
58
|
+
/**
|
|
59
|
+
* Number of styles in document order.
|
|
60
|
+
*
|
|
61
|
+
* @public
|
|
62
|
+
*/
|
|
63
|
+
get: function () {
|
|
64
|
+
this.rebuildIndexProperties();
|
|
65
|
+
return this.styleList.length;
|
|
66
|
+
},
|
|
67
|
+
enumerable: true,
|
|
68
|
+
configurable: true
|
|
69
|
+
});
|
|
70
|
+
/**
|
|
71
|
+
* Style at zero-based index, or `undefined` when out of range.
|
|
72
|
+
*
|
|
73
|
+
* @public
|
|
74
|
+
*/
|
|
75
|
+
StyleCollection.prototype.itemAt = function (index) {
|
|
76
|
+
return this.styleList[index];
|
|
77
|
+
};
|
|
78
|
+
StyleCollection.prototype[Symbol.iterator] = function () {
|
|
79
|
+
var items = this.styleList.slice();
|
|
80
|
+
var i = 0;
|
|
81
|
+
return {
|
|
82
|
+
next: function () {
|
|
83
|
+
if (i >= items.length) {
|
|
84
|
+
return { done: true, value: undefined };
|
|
85
|
+
}
|
|
86
|
+
var value = items[i];
|
|
87
|
+
i += 1;
|
|
88
|
+
return { done: false, value: value };
|
|
89
|
+
},
|
|
90
|
+
};
|
|
91
|
+
};
|
|
92
|
+
/**
|
|
93
|
+
* Look up any style by `w:styleId`.
|
|
94
|
+
*
|
|
95
|
+
* @public
|
|
96
|
+
*/
|
|
97
|
+
StyleCollection.prototype.getStyle = function (styleId) {
|
|
98
|
+
return this.styleById.get(styleId);
|
|
99
|
+
};
|
|
100
|
+
/**
|
|
101
|
+
* Look up any style by `w:styleId` (alias of {@link getStyle}).
|
|
102
|
+
*
|
|
103
|
+
* @public
|
|
104
|
+
*/
|
|
105
|
+
StyleCollection.prototype.findById = function (styleId) {
|
|
106
|
+
return this.getStyle(styleId);
|
|
107
|
+
};
|
|
108
|
+
/**
|
|
109
|
+
* Look up a paragraph style by id.
|
|
110
|
+
*
|
|
111
|
+
* @public
|
|
112
|
+
*/
|
|
113
|
+
StyleCollection.prototype.getParagraphStyle = function (styleId) {
|
|
114
|
+
var style = this.styleById.get(styleId);
|
|
115
|
+
if (style instanceof ParagraphStyle) {
|
|
116
|
+
return style;
|
|
117
|
+
}
|
|
118
|
+
return undefined;
|
|
119
|
+
};
|
|
120
|
+
/**
|
|
121
|
+
* Look up a character style by id.
|
|
122
|
+
*
|
|
123
|
+
* @public
|
|
124
|
+
*/
|
|
125
|
+
StyleCollection.prototype.getCharacterStyle = function (styleId) {
|
|
126
|
+
var style = this.styleById.get(styleId);
|
|
127
|
+
if (style instanceof CharacterStyle) {
|
|
128
|
+
return style;
|
|
129
|
+
}
|
|
130
|
+
return undefined;
|
|
131
|
+
};
|
|
132
|
+
/**
|
|
133
|
+
* Look up a table style by id.
|
|
134
|
+
*
|
|
135
|
+
* @public
|
|
136
|
+
*/
|
|
137
|
+
StyleCollection.prototype.getTableStyle = function (styleId) {
|
|
138
|
+
var style = this.styleById.get(styleId);
|
|
139
|
+
if (style instanceof TableStyle) {
|
|
140
|
+
return style;
|
|
141
|
+
}
|
|
142
|
+
return undefined;
|
|
143
|
+
};
|
|
144
|
+
/**
|
|
145
|
+
* Find a style whose display name matches `name` (normalized).
|
|
146
|
+
*
|
|
147
|
+
* @public
|
|
148
|
+
*/
|
|
149
|
+
StyleCollection.prototype.findByName = function (name) {
|
|
150
|
+
var normalized = normalizeStyleName(name);
|
|
151
|
+
if (normalized.length === 0) {
|
|
152
|
+
return undefined;
|
|
153
|
+
}
|
|
154
|
+
for (var i = 0; i < this.styleList.length; i += 1) {
|
|
155
|
+
var style = this.styleList[i];
|
|
156
|
+
if (style.normalizedName() === normalized) {
|
|
157
|
+
return style;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
return undefined;
|
|
161
|
+
};
|
|
162
|
+
/**
|
|
163
|
+
* Whether a style id exists (including pending ensure).
|
|
164
|
+
*
|
|
165
|
+
* @public
|
|
166
|
+
*/
|
|
167
|
+
StyleCollection.prototype.hasStyle = function (styleId) {
|
|
168
|
+
return (this.styleById.has(styleId) ||
|
|
169
|
+
this.pendingParagraphStyles.has(styleId) ||
|
|
170
|
+
this.pendingCharacterStyles.has(styleId) ||
|
|
171
|
+
this.pendingTableStyles.has(styleId));
|
|
172
|
+
};
|
|
173
|
+
/**
|
|
174
|
+
* Create and add a paragraph style with the given id.
|
|
175
|
+
* Throws when the id is empty or already present.
|
|
176
|
+
*
|
|
177
|
+
* @public
|
|
178
|
+
*/
|
|
179
|
+
StyleCollection.prototype.addParagraphStyle = function (styleId) {
|
|
180
|
+
this.assertNewId(styleId);
|
|
181
|
+
var style = ParagraphStyle.createMinimal(styleId);
|
|
182
|
+
this.attachAndIndex(style, true);
|
|
183
|
+
return style;
|
|
184
|
+
};
|
|
185
|
+
/**
|
|
186
|
+
* Create and add a character style with the given id.
|
|
187
|
+
*
|
|
188
|
+
* @public
|
|
189
|
+
*/
|
|
190
|
+
StyleCollection.prototype.addCharacterStyle = function (styleId) {
|
|
191
|
+
this.assertNewId(styleId);
|
|
192
|
+
var style = CharacterStyle.createMinimal(styleId);
|
|
193
|
+
this.attachAndIndex(style, true);
|
|
194
|
+
return style;
|
|
195
|
+
};
|
|
196
|
+
/**
|
|
197
|
+
* Create a custom table style and add it to this collection.
|
|
198
|
+
*
|
|
199
|
+
* @public
|
|
200
|
+
*/
|
|
201
|
+
StyleCollection.prototype.addTableStyle = function (name) {
|
|
202
|
+
var _this = this;
|
|
203
|
+
var trimmed = name.trim();
|
|
204
|
+
if (trimmed.length === 0) {
|
|
205
|
+
throw new InvalidArgumentError('Table style name must not be empty');
|
|
206
|
+
}
|
|
207
|
+
var styleId = sanitizeStyleId(trimmed);
|
|
208
|
+
if (styleId.length === 0) {
|
|
209
|
+
styleId = 'TableStyle';
|
|
210
|
+
}
|
|
211
|
+
styleId = uniqueStyleId(styleId, function (candidate) { return _this.styleById.has(candidate); });
|
|
212
|
+
var shell = new DocxStyle(styleId, 'table', undefined, true, [
|
|
213
|
+
wmlElement('name', { attributes: [wmlAttr('val', trimmed)] }),
|
|
214
|
+
]);
|
|
215
|
+
var live = this.appendFromDocxShell(shell, true);
|
|
216
|
+
return live;
|
|
217
|
+
};
|
|
218
|
+
/**
|
|
219
|
+
* Ensure a paragraph style exists (built-in catalog or minimal stub).
|
|
220
|
+
* Returns the live style.
|
|
221
|
+
*
|
|
222
|
+
* @public
|
|
223
|
+
*/
|
|
224
|
+
StyleCollection.prototype.ensureParagraphStyle = function (styleId) {
|
|
225
|
+
var existing = this.getParagraphStyle(styleId);
|
|
226
|
+
if (existing !== undefined) {
|
|
227
|
+
return existing;
|
|
228
|
+
}
|
|
229
|
+
this.ensureStyle(styleId, 'paragraph');
|
|
230
|
+
var created = this.getParagraphStyle(styleId);
|
|
231
|
+
if (created === undefined) {
|
|
232
|
+
var byName = this.findByName(styleId);
|
|
233
|
+
if (byName instanceof ParagraphStyle) {
|
|
234
|
+
return byName;
|
|
235
|
+
}
|
|
236
|
+
throw new DocxError('styles/undefined-style', "Failed to ensure paragraph style \"" + styleId + "\"");
|
|
237
|
+
}
|
|
238
|
+
return created;
|
|
239
|
+
};
|
|
240
|
+
/**
|
|
241
|
+
* Ensure a character style exists (built-in catalog or minimal stub).
|
|
242
|
+
*
|
|
243
|
+
* @public
|
|
244
|
+
*/
|
|
245
|
+
StyleCollection.prototype.ensureCharacterStyle = function (styleId) {
|
|
246
|
+
var existing = this.getCharacterStyle(styleId);
|
|
247
|
+
if (existing !== undefined) {
|
|
248
|
+
return existing;
|
|
249
|
+
}
|
|
250
|
+
this.ensureStyle(styleId, 'character');
|
|
251
|
+
var created = this.getCharacterStyle(styleId);
|
|
252
|
+
if (created === undefined) {
|
|
253
|
+
var byName = this.findByName(styleId);
|
|
254
|
+
if (byName instanceof CharacterStyle) {
|
|
255
|
+
return byName;
|
|
256
|
+
}
|
|
257
|
+
throw new DocxError('styles/undefined-style', "Failed to ensure character style \"" + styleId + "\"");
|
|
258
|
+
}
|
|
259
|
+
return created;
|
|
260
|
+
};
|
|
261
|
+
/**
|
|
262
|
+
* Ensure a table style exists (built-in catalog or minimal stub).
|
|
263
|
+
*
|
|
264
|
+
* @public
|
|
265
|
+
*/
|
|
266
|
+
StyleCollection.prototype.ensureTableStyle = function (styleId) {
|
|
267
|
+
var existing = this.getTableStyle(styleId);
|
|
268
|
+
if (existing !== undefined) {
|
|
269
|
+
return existing;
|
|
270
|
+
}
|
|
271
|
+
this.ensureStyle(styleId, 'table');
|
|
272
|
+
var created = this.getTableStyle(styleId);
|
|
273
|
+
if (created === undefined) {
|
|
274
|
+
var byName = this.findByName(styleId);
|
|
275
|
+
if (byName instanceof TableStyle) {
|
|
276
|
+
return byName;
|
|
277
|
+
}
|
|
278
|
+
throw new DocxError('styles/undefined-style', "Failed to ensure table style \"" + styleId + "\"");
|
|
279
|
+
}
|
|
280
|
+
return created;
|
|
281
|
+
};
|
|
282
|
+
/**
|
|
283
|
+
* Remove a style by id or instance. Detaches the style, clears pending /
|
|
284
|
+
* projection caches, strips content references (`pStyle` / `rStyle` / table
|
|
285
|
+
* style) and catalog edges (`basedOn` / `next` / `link`) that point at the
|
|
286
|
+
* removed id so save-time materialize cannot re-create a minimal stub.
|
|
287
|
+
* Returns `true` when removed.
|
|
288
|
+
*
|
|
289
|
+
* Not part of the public Styles collection surface — use {@link Style.remove}.
|
|
290
|
+
*
|
|
291
|
+
* @private
|
|
292
|
+
*/
|
|
293
|
+
StyleCollection.prototype.remove = function (styleOrId) {
|
|
294
|
+
var styleId = typeof styleOrId === 'string' ? styleOrId : styleOrId.styleId;
|
|
295
|
+
var style = this.styleById.get(styleId);
|
|
296
|
+
if (style === undefined) {
|
|
297
|
+
return false;
|
|
298
|
+
}
|
|
299
|
+
if (typeof styleOrId !== 'string' && styleOrId !== style) {
|
|
300
|
+
throw new InvalidArgumentError('Style instance is not the collection entry for its styleId');
|
|
301
|
+
}
|
|
302
|
+
// Content refs first so materialize cannot observe a dangling id after detach.
|
|
303
|
+
if (typeof this.host.purgeContentStyleReferences === 'function') {
|
|
304
|
+
this.host.purgeContentStyleReferences(this.document, styleId);
|
|
305
|
+
}
|
|
306
|
+
this.purgeCatalogReferencesTo(styleId, style);
|
|
307
|
+
var index = this.styleList.indexOf(style);
|
|
308
|
+
if (index >= 0) {
|
|
309
|
+
this.styleList.splice(index, 1);
|
|
310
|
+
}
|
|
311
|
+
this.styleById.delete(styleId);
|
|
312
|
+
this.projected.delete(styleId);
|
|
313
|
+
this.pendingParagraphStyles.delete(styleId);
|
|
314
|
+
this.pendingCharacterStyles.delete(styleId);
|
|
315
|
+
this.pendingTableStyles.delete(styleId);
|
|
316
|
+
if (typeof this.host.forgetProjectedStyle === 'function') {
|
|
317
|
+
this.host.forgetProjectedStyle(styleId);
|
|
318
|
+
}
|
|
319
|
+
style.detach();
|
|
320
|
+
this.host.markStylesDirty();
|
|
321
|
+
this.rebuildIndexProperties();
|
|
322
|
+
return true;
|
|
323
|
+
};
|
|
324
|
+
/**
|
|
325
|
+
* Clear `basedOn` / `next` / `link` on remaining styles that point at `styleId`.
|
|
326
|
+
*
|
|
327
|
+
* @private
|
|
328
|
+
*/
|
|
329
|
+
StyleCollection.prototype.purgeCatalogReferencesTo = function (styleId, removed) {
|
|
330
|
+
for (var i = 0; i < this.styleList.length; i += 1) {
|
|
331
|
+
var other = this.styleList[i];
|
|
332
|
+
if (other === removed) {
|
|
333
|
+
continue;
|
|
334
|
+
}
|
|
335
|
+
other.clearReferencesToStyleId(styleId);
|
|
336
|
+
}
|
|
337
|
+
};
|
|
338
|
+
/**
|
|
339
|
+
* Ordered styles for package serialization.
|
|
340
|
+
*
|
|
341
|
+
* @private
|
|
342
|
+
*/
|
|
343
|
+
StyleCollection.prototype.stylesInOrder = function () {
|
|
344
|
+
return this.styleList;
|
|
345
|
+
};
|
|
346
|
+
/**
|
|
347
|
+
* StyleOwner: mark styles part dirty and drop projection for all styles when
|
|
348
|
+
* a live mutation may have changed modeled XML (host may call for any style).
|
|
349
|
+
*
|
|
350
|
+
* @private
|
|
351
|
+
*/
|
|
352
|
+
StyleCollection.prototype.markStylesDirty = function () {
|
|
353
|
+
// Drop projection cache so subsequent projectDocxStyle re-serializes.
|
|
354
|
+
this.projected.clear();
|
|
355
|
+
this.host.markStylesDirty();
|
|
356
|
+
};
|
|
357
|
+
/**
|
|
358
|
+
* StyleOwner: lookup by id.
|
|
359
|
+
*
|
|
360
|
+
* @private
|
|
361
|
+
*/
|
|
362
|
+
StyleCollection.prototype.lookupStyle = function (styleId) {
|
|
363
|
+
return this.styleById.get(styleId);
|
|
364
|
+
};
|
|
365
|
+
/**
|
|
366
|
+
* Resolver / part surface: find by display name.
|
|
367
|
+
*
|
|
368
|
+
* @private
|
|
369
|
+
*/
|
|
370
|
+
StyleCollection.prototype.findStyleByDisplayName = function (name) {
|
|
371
|
+
var live = this.findByName(name);
|
|
372
|
+
if (live === undefined) {
|
|
373
|
+
return undefined;
|
|
374
|
+
}
|
|
375
|
+
return this.projectDocxStyle(live.styleId);
|
|
376
|
+
};
|
|
377
|
+
/**
|
|
378
|
+
* Add a live style (resolver / hydrate). No-op when id already present.
|
|
379
|
+
*
|
|
380
|
+
* @private
|
|
381
|
+
*/
|
|
382
|
+
StyleCollection.prototype.addStyle = function (style) {
|
|
383
|
+
if (style instanceof DocxStyle) {
|
|
384
|
+
if (this.styleById.has(style.styleId)) {
|
|
385
|
+
return;
|
|
386
|
+
}
|
|
387
|
+
this.appendFromDocxShell(style, true);
|
|
388
|
+
return;
|
|
389
|
+
}
|
|
390
|
+
if (this.styleById.has(style.styleId)) {
|
|
391
|
+
return;
|
|
392
|
+
}
|
|
393
|
+
if (style.isAttached && style.owner !== this) {
|
|
394
|
+
throw new DocxError('argument/invalid', "Style \"" + style.styleId + "\" is owned by another document");
|
|
395
|
+
}
|
|
396
|
+
this.attachAndIndex(style, true);
|
|
397
|
+
};
|
|
398
|
+
/**
|
|
399
|
+
* Hydrate from temporary DocxStyle shells (parse / create path). Does not mark dirty
|
|
400
|
+
* when `markDirty` is false (load path).
|
|
401
|
+
*
|
|
402
|
+
* @private
|
|
403
|
+
*/
|
|
404
|
+
StyleCollection.prototype.hydrateFromDocxStyles = function (sources, markDirty) {
|
|
405
|
+
for (var i = 0; i < sources.length; i += 1) {
|
|
406
|
+
var shell = sources[i];
|
|
407
|
+
if (this.styleById.has(shell.styleId)) {
|
|
408
|
+
continue;
|
|
409
|
+
}
|
|
410
|
+
this.appendFromDocxShell(shell, markDirty);
|
|
411
|
+
}
|
|
412
|
+
};
|
|
413
|
+
/**
|
|
414
|
+
* Replace contents from DocxStyle shells (load / create). Clears existing entries.
|
|
415
|
+
*
|
|
416
|
+
* @private
|
|
417
|
+
*/
|
|
418
|
+
StyleCollection.prototype.replaceFromDocxStyles = function (sources, markDirty) {
|
|
419
|
+
for (var i = 0; i < this.styleList.length; i += 1) {
|
|
420
|
+
this.styleList[i].detach();
|
|
421
|
+
}
|
|
422
|
+
this.styleList.length = 0;
|
|
423
|
+
this.styleById.clear();
|
|
424
|
+
this.projected.clear();
|
|
425
|
+
this.hydrateFromDocxStyles(sources, markDirty);
|
|
426
|
+
this.rebuildIndexProperties();
|
|
427
|
+
};
|
|
428
|
+
/** @private */
|
|
429
|
+
StyleCollection.prototype.registerPendingParagraphStyle = function (styleId) {
|
|
430
|
+
if (styleId.length === 0 || this.styleById.has(styleId)) {
|
|
431
|
+
return;
|
|
432
|
+
}
|
|
433
|
+
this.pendingParagraphStyles.add(styleId);
|
|
434
|
+
};
|
|
435
|
+
/** @private */
|
|
436
|
+
StyleCollection.prototype.registerPendingCharacterStyle = function (styleId) {
|
|
437
|
+
if (styleId.length === 0 || this.styleById.has(styleId)) {
|
|
438
|
+
return;
|
|
439
|
+
}
|
|
440
|
+
this.pendingCharacterStyles.add(styleId);
|
|
441
|
+
};
|
|
442
|
+
/** @private */
|
|
443
|
+
StyleCollection.prototype.registerPendingTableStyle = function (styleId) {
|
|
444
|
+
if (styleId.length === 0 || this.styleById.has(styleId)) {
|
|
445
|
+
return;
|
|
446
|
+
}
|
|
447
|
+
this.pendingTableStyles.add(styleId);
|
|
448
|
+
};
|
|
449
|
+
/**
|
|
450
|
+
* Materialize pending style ids and canonicalize dangling refs (save path).
|
|
451
|
+
*
|
|
452
|
+
* @private
|
|
453
|
+
*/
|
|
454
|
+
StyleCollection.prototype.materializePendingIds = function (onParagraphStyle, onCharacterStyle, onTableStyle) {
|
|
455
|
+
var pendingParagraph = Array.from(this.pendingParagraphStyles);
|
|
456
|
+
this.pendingParagraphStyles.clear();
|
|
457
|
+
for (var i = 0; i < pendingParagraph.length; i += 1) {
|
|
458
|
+
var styleId = pendingParagraph[i];
|
|
459
|
+
if (!this.styleById.has(styleId)) {
|
|
460
|
+
this.ensureStyle(styleId, 'paragraph');
|
|
461
|
+
}
|
|
462
|
+
var resolved = this.styleById.get(styleId);
|
|
463
|
+
if (resolved !== undefined && resolved.styleId !== styleId) {
|
|
464
|
+
onParagraphStyle(styleId, resolved.styleId);
|
|
465
|
+
}
|
|
466
|
+
else if (resolved === undefined) {
|
|
467
|
+
var byName = this.findByName(styleId);
|
|
468
|
+
if (byName !== undefined && byName.styleId !== styleId) {
|
|
469
|
+
onParagraphStyle(styleId, byName.styleId);
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
var pendingCharacter = Array.from(this.pendingCharacterStyles);
|
|
474
|
+
this.pendingCharacterStyles.clear();
|
|
475
|
+
for (var i = 0; i < pendingCharacter.length; i += 1) {
|
|
476
|
+
var styleId = pendingCharacter[i];
|
|
477
|
+
if (!this.styleById.has(styleId)) {
|
|
478
|
+
this.ensureStyle(styleId, 'character');
|
|
479
|
+
}
|
|
480
|
+
var resolved = this.styleById.get(styleId);
|
|
481
|
+
if (resolved !== undefined && resolved.styleId !== styleId) {
|
|
482
|
+
onCharacterStyle(styleId, resolved.styleId);
|
|
483
|
+
}
|
|
484
|
+
else if (resolved === undefined) {
|
|
485
|
+
var byName = this.findByName(styleId);
|
|
486
|
+
if (byName !== undefined && byName.styleId !== styleId) {
|
|
487
|
+
onCharacterStyle(styleId, byName.styleId);
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
if (onTableStyle !== undefined) {
|
|
492
|
+
var pendingTable = Array.from(this.pendingTableStyles);
|
|
493
|
+
this.pendingTableStyles.clear();
|
|
494
|
+
for (var i = 0; i < pendingTable.length; i += 1) {
|
|
495
|
+
var styleId = pendingTable[i];
|
|
496
|
+
if (!this.styleById.has(styleId)) {
|
|
497
|
+
this.ensureStyle(styleId, 'table');
|
|
498
|
+
}
|
|
499
|
+
var resolved = this.styleById.get(styleId);
|
|
500
|
+
if (resolved !== undefined && resolved.styleId !== styleId) {
|
|
501
|
+
onTableStyle(styleId, resolved.styleId);
|
|
502
|
+
}
|
|
503
|
+
else if (resolved === undefined) {
|
|
504
|
+
var byName = this.findByName(styleId);
|
|
505
|
+
if (byName !== undefined && byName.styleId !== styleId) {
|
|
506
|
+
onTableStyle(styleId, byName.styleId);
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
else {
|
|
512
|
+
this.pendingTableStyles.clear();
|
|
513
|
+
}
|
|
514
|
+
};
|
|
515
|
+
/**
|
|
516
|
+
* Adapter so the existing DocxStyle-based catalog resolver can read/add into this collection.
|
|
517
|
+
*
|
|
518
|
+
* @private
|
|
519
|
+
*/
|
|
520
|
+
StyleCollection.prototype.asDocxLookup = function () {
|
|
521
|
+
var self = this;
|
|
522
|
+
return {
|
|
523
|
+
getStyle: function (styleId) {
|
|
524
|
+
return self.projectDocxStyle(styleId);
|
|
525
|
+
},
|
|
526
|
+
findStyleByDisplayName: function (name) {
|
|
527
|
+
return self.findStyleByDisplayName(name);
|
|
528
|
+
},
|
|
529
|
+
addStyle: function (style) {
|
|
530
|
+
if (self.styleById.has(style.styleId)) {
|
|
531
|
+
return;
|
|
532
|
+
}
|
|
533
|
+
self.appendFromDocxShell(style, true);
|
|
534
|
+
},
|
|
535
|
+
};
|
|
536
|
+
};
|
|
537
|
+
/**
|
|
538
|
+
* Project live styles to temporary DocxStyle shells (resolver / transitional StylesPart surface).
|
|
539
|
+
*
|
|
540
|
+
* @private
|
|
541
|
+
*/
|
|
542
|
+
StyleCollection.prototype.projectDocxStyles = function () {
|
|
543
|
+
var out = [];
|
|
544
|
+
for (var i = 0; i < this.styleList.length; i += 1) {
|
|
545
|
+
var shell = this.projectDocxStyle(this.styleList[i].styleId);
|
|
546
|
+
if (shell !== undefined) {
|
|
547
|
+
out.push(shell);
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
return out;
|
|
551
|
+
};
|
|
552
|
+
/**
|
|
553
|
+
* Project one live style to a DocxStyle shell, or `undefined`.
|
|
554
|
+
* Caches by styleId so StylesPart can keep stable object identity until dirty.
|
|
555
|
+
*
|
|
556
|
+
* @private
|
|
557
|
+
*/
|
|
558
|
+
StyleCollection.prototype.projectDocxStyle = function (styleId) {
|
|
559
|
+
var cached = this.projected.get(styleId);
|
|
560
|
+
if (cached !== undefined) {
|
|
561
|
+
return cached;
|
|
562
|
+
}
|
|
563
|
+
var live = this.styleById.get(styleId);
|
|
564
|
+
if (live === undefined) {
|
|
565
|
+
return undefined;
|
|
566
|
+
}
|
|
567
|
+
var shell = live.toDocxStyle();
|
|
568
|
+
this.projected.set(styleId, shell);
|
|
569
|
+
return shell;
|
|
570
|
+
};
|
|
571
|
+
/**
|
|
572
|
+
* @private
|
|
573
|
+
*/
|
|
574
|
+
StyleCollection.prototype.ensureStyle = function (styleId, type) {
|
|
575
|
+
if (styleId.length === 0) {
|
|
576
|
+
throw new DocxError('content/invalid-style-id', 'Style id must not be empty');
|
|
577
|
+
}
|
|
578
|
+
if (this.styleById.has(styleId)) {
|
|
579
|
+
return;
|
|
580
|
+
}
|
|
581
|
+
if (type === 'paragraph' || type === 'character') {
|
|
582
|
+
try {
|
|
583
|
+
resolveStyleForTarget(this.asDocxLookup(), styleId, type);
|
|
584
|
+
}
|
|
585
|
+
catch (err) {
|
|
586
|
+
void err;
|
|
587
|
+
}
|
|
588
|
+
if (this.styleById.has(styleId)) {
|
|
589
|
+
return;
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
var referenced = resolveReferencedStyle(this.asDocxLookup(), styleId, type);
|
|
593
|
+
if (referenced !== undefined) {
|
|
594
|
+
if (!this.styleById.has(referenced.styleId)) {
|
|
595
|
+
this.appendFromDocxShell(referenced, true);
|
|
596
|
+
}
|
|
597
|
+
return;
|
|
598
|
+
}
|
|
599
|
+
if (type === 'table') {
|
|
600
|
+
var created_1 = createMinimalDocxStyle(styleId, 'table');
|
|
601
|
+
this.appendFromDocxShell(created_1, true);
|
|
602
|
+
return;
|
|
603
|
+
}
|
|
604
|
+
var created = createMinimalStyle(styleId, type);
|
|
605
|
+
this.attachAndIndex(created, true);
|
|
606
|
+
};
|
|
607
|
+
StyleCollection.prototype.assertNewId = function (styleId) {
|
|
608
|
+
if (styleId.length === 0) {
|
|
609
|
+
throw new InvalidArgumentError('Style id must not be empty');
|
|
610
|
+
}
|
|
611
|
+
if (this.styleById.has(styleId)) {
|
|
612
|
+
throw new DocxError('argument/invalid', "Style id \"" + styleId + "\" already exists in this document");
|
|
613
|
+
}
|
|
614
|
+
};
|
|
615
|
+
/**
|
|
616
|
+
* Build live Style (or TableStyle) from a DocxStyle shell and index it.
|
|
617
|
+
*
|
|
618
|
+
* @private
|
|
619
|
+
*/
|
|
620
|
+
StyleCollection.prototype.appendFromDocxShell = function (shell, markDirty) {
|
|
621
|
+
var self = this;
|
|
622
|
+
var live;
|
|
623
|
+
if (shell.type === 'table') {
|
|
624
|
+
var tableHost = {
|
|
625
|
+
notifyTableStyleMutation: function () {
|
|
626
|
+
self.projected.delete(shell.styleId);
|
|
627
|
+
self.host.markStylesDirty();
|
|
628
|
+
},
|
|
629
|
+
};
|
|
630
|
+
live = new TableStyle(shell, tableHost);
|
|
631
|
+
}
|
|
632
|
+
else {
|
|
633
|
+
live = createStyleFromDocxStyle(shell);
|
|
634
|
+
}
|
|
635
|
+
this.attachAndIndex(live, markDirty);
|
|
636
|
+
// Prefer the original shell for stable identity when freshly loaded.
|
|
637
|
+
this.projected.set(live.styleId, shell);
|
|
638
|
+
return live;
|
|
639
|
+
};
|
|
640
|
+
StyleCollection.prototype.attachAndIndex = function (style, markDirty) {
|
|
641
|
+
if (this.styleById.has(style.styleId)) {
|
|
642
|
+
return;
|
|
643
|
+
}
|
|
644
|
+
if (style instanceof TableStyle) {
|
|
645
|
+
var self_1 = this;
|
|
646
|
+
style.bindHost({
|
|
647
|
+
notifyTableStyleMutation: function () {
|
|
648
|
+
self_1.projected.delete(style.styleId);
|
|
649
|
+
self_1.host.markStylesDirty();
|
|
650
|
+
},
|
|
651
|
+
});
|
|
652
|
+
}
|
|
653
|
+
style.attach(this);
|
|
654
|
+
this.styleList.push(style);
|
|
655
|
+
this.styleById.set(style.styleId, style);
|
|
656
|
+
if (markDirty) {
|
|
657
|
+
this.host.markStylesDirty();
|
|
658
|
+
}
|
|
659
|
+
this.rebuildIndexProperties();
|
|
660
|
+
};
|
|
661
|
+
/**
|
|
662
|
+
* Numeric index properties (CommentCollection pattern).
|
|
663
|
+
*
|
|
664
|
+
* @private
|
|
665
|
+
*/
|
|
666
|
+
StyleCollection.prototype.rebuildIndexProperties = function () {
|
|
667
|
+
var items = this.styleList;
|
|
668
|
+
var nextLen = items.length;
|
|
669
|
+
var prevLen = this.cachedLength;
|
|
670
|
+
var limit = prevLen > nextLen ? prevLen : nextLen;
|
|
671
|
+
for (var i = 0; i < limit; i += 1) {
|
|
672
|
+
var key = String(i);
|
|
673
|
+
if (i < nextLen) {
|
|
674
|
+
Object.defineProperty(this, key, {
|
|
675
|
+
value: items[i],
|
|
676
|
+
writable: false,
|
|
677
|
+
enumerable: true,
|
|
678
|
+
configurable: true,
|
|
679
|
+
});
|
|
680
|
+
}
|
|
681
|
+
else {
|
|
682
|
+
delete this[key];
|
|
683
|
+
}
|
|
684
|
+
}
|
|
685
|
+
this.cachedLength = nextLen;
|
|
686
|
+
};
|
|
687
|
+
return StyleCollection;
|
|
688
|
+
}());
|
|
689
|
+
export { StyleCollection };
|
|
690
|
+
function sanitizeStyleId(name) {
|
|
691
|
+
var out = '';
|
|
692
|
+
for (var i = 0; i < name.length; i += 1) {
|
|
693
|
+
var ch = name.charAt(i);
|
|
694
|
+
var code = name.charCodeAt(i);
|
|
695
|
+
var isLetter = (code >= 65 && code <= 90) ||
|
|
696
|
+
(code >= 97 && code <= 122) ||
|
|
697
|
+
code > 127;
|
|
698
|
+
var isDigit = code >= 48 && code <= 57;
|
|
699
|
+
if (isLetter || isDigit) {
|
|
700
|
+
out += ch;
|
|
701
|
+
}
|
|
702
|
+
}
|
|
703
|
+
return out;
|
|
704
|
+
}
|
|
705
|
+
function uniqueStyleId(base, exists) {
|
|
706
|
+
if (!exists(base)) {
|
|
707
|
+
return base;
|
|
708
|
+
}
|
|
709
|
+
var n = 1;
|
|
710
|
+
while (exists(base + String(n))) {
|
|
711
|
+
n += 1;
|
|
712
|
+
}
|
|
713
|
+
return base + String(n);
|
|
714
|
+
}
|