docxmlater 10.4.1 → 11.0.4
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 +3 -3
- package/dist/constants/legacyCompatFlags.d.ts +1 -1
- package/dist/constants/legacyCompatFlags.d.ts.map +1 -1
- package/dist/constants/legacyCompatFlags.js.map +1 -1
- package/dist/core/Document.d.ts +74 -67
- package/dist/core/Document.d.ts.map +1 -1
- package/dist/core/Document.js +605 -414
- package/dist/core/Document.js.map +1 -1
- package/dist/core/DocumentContent.d.ts +11 -10
- package/dist/core/DocumentContent.d.ts.map +1 -1
- package/dist/core/DocumentContent.js +19 -19
- package/dist/core/DocumentContent.js.map +1 -1
- package/dist/core/DocumentEvents.d.ts +39 -0
- package/dist/core/DocumentEvents.d.ts.map +1 -0
- package/dist/core/DocumentEvents.js +51 -0
- package/dist/core/DocumentEvents.js.map +1 -0
- package/dist/core/DocumentGenerator.d.ts +11 -11
- package/dist/core/DocumentGenerator.d.ts.map +1 -1
- package/dist/core/DocumentGenerator.js +72 -52
- package/dist/core/DocumentGenerator.js.map +1 -1
- package/dist/core/DocumentParser.d.ts +15 -15
- package/dist/core/DocumentParser.d.ts.map +1 -1
- package/dist/core/DocumentParser.js +2056 -1073
- package/dist/core/DocumentParser.js.map +1 -1
- package/dist/core/DocumentValidator.d.ts +3 -3
- package/dist/core/DocumentValidator.d.ts.map +1 -1
- package/dist/core/DocumentValidator.js +31 -31
- package/dist/core/DocumentValidator.js.map +1 -1
- package/dist/core/ElementRegistry.d.ts +22 -0
- package/dist/core/ElementRegistry.d.ts.map +1 -0
- package/dist/core/ElementRegistry.js +27 -0
- package/dist/core/ElementRegistry.js.map +1 -0
- package/dist/core/Relationship.js +4 -4
- package/dist/core/Relationship.js.map +1 -1
- package/dist/core/RelationshipManager.d.ts +1 -1
- package/dist/core/RelationshipManager.d.ts.map +1 -1
- package/dist/core/RelationshipManager.js +32 -32
- package/dist/core/RelationshipManager.js.map +1 -1
- package/dist/elements/AlternateContent.d.ts +1 -1
- package/dist/elements/AlternateContent.d.ts.map +1 -1
- package/dist/elements/AlternateContent.js.map +1 -1
- package/dist/elements/Bookmark.d.ts +6 -1
- package/dist/elements/Bookmark.d.ts.map +1 -1
- package/dist/elements/Bookmark.js +19 -3
- package/dist/elements/Bookmark.js.map +1 -1
- package/dist/elements/BookmarkManager.d.ts +1 -1
- package/dist/elements/BookmarkManager.d.ts.map +1 -1
- package/dist/elements/BookmarkManager.js +7 -7
- package/dist/elements/BookmarkManager.js.map +1 -1
- package/dist/elements/Comment.d.ts +2 -2
- package/dist/elements/Comment.d.ts.map +1 -1
- package/dist/elements/Comment.js +4 -4
- package/dist/elements/Comment.js.map +1 -1
- package/dist/elements/CommentManager.d.ts +2 -2
- package/dist/elements/CommentManager.d.ts.map +1 -1
- package/dist/elements/CommentManager.js +9 -9
- package/dist/elements/CommentManager.js.map +1 -1
- package/dist/elements/CommonTypes.d.ts +9 -4
- package/dist/elements/CommonTypes.d.ts.map +1 -1
- package/dist/elements/CommonTypes.js +1 -0
- package/dist/elements/CommonTypes.js.map +1 -1
- package/dist/elements/CustomXml.d.ts +1 -1
- package/dist/elements/CustomXml.d.ts.map +1 -1
- package/dist/elements/CustomXml.js.map +1 -1
- package/dist/elements/Endnote.d.ts +2 -2
- package/dist/elements/Endnote.d.ts.map +1 -1
- package/dist/elements/Endnote.js +9 -9
- package/dist/elements/Endnote.js.map +1 -1
- package/dist/elements/EndnoteManager.d.ts +1 -1
- package/dist/elements/EndnoteManager.d.ts.map +1 -1
- package/dist/elements/EndnoteManager.js +11 -11
- package/dist/elements/EndnoteManager.js.map +1 -1
- package/dist/elements/Field.d.ts +9 -5
- package/dist/elements/Field.d.ts.map +1 -1
- package/dist/elements/Field.js +21 -9
- package/dist/elements/Field.js.map +1 -1
- package/dist/elements/FieldHelpers.d.ts +1 -1
- package/dist/elements/FieldHelpers.d.ts.map +1 -1
- package/dist/elements/FieldHelpers.js +10 -10
- package/dist/elements/FieldHelpers.js.map +1 -1
- package/dist/elements/Footer.d.ts +3 -3
- package/dist/elements/Footer.d.ts.map +1 -1
- package/dist/elements/Footer.js +5 -5
- package/dist/elements/Footer.js.map +1 -1
- package/dist/elements/Footnote.d.ts +2 -2
- package/dist/elements/Footnote.d.ts.map +1 -1
- package/dist/elements/Footnote.js +9 -9
- package/dist/elements/Footnote.js.map +1 -1
- package/dist/elements/FootnoteManager.d.ts +1 -1
- package/dist/elements/FootnoteManager.d.ts.map +1 -1
- package/dist/elements/FootnoteManager.js +11 -11
- package/dist/elements/FootnoteManager.js.map +1 -1
- package/dist/elements/Header.d.ts +3 -3
- package/dist/elements/Header.d.ts.map +1 -1
- package/dist/elements/Header.js +5 -5
- package/dist/elements/Header.js.map +1 -1
- package/dist/elements/HeaderFooterManager.d.ts +2 -2
- package/dist/elements/HeaderFooterManager.d.ts.map +1 -1
- package/dist/elements/HeaderFooterManager.js.map +1 -1
- package/dist/elements/Hyperlink.d.ts +5 -5
- package/dist/elements/Hyperlink.d.ts.map +1 -1
- package/dist/elements/Hyperlink.js +29 -29
- package/dist/elements/Hyperlink.js.map +1 -1
- package/dist/elements/Image.d.ts +1 -1
- package/dist/elements/Image.d.ts.map +1 -1
- package/dist/elements/Image.js +67 -67
- package/dist/elements/Image.js.map +1 -1
- package/dist/elements/ImageManager.d.ts +1 -1
- package/dist/elements/ImageManager.d.ts.map +1 -1
- package/dist/elements/ImageManager.js +4 -4
- package/dist/elements/ImageManager.js.map +1 -1
- package/dist/elements/ImageRun.d.ts +3 -3
- package/dist/elements/ImageRun.d.ts.map +1 -1
- package/dist/elements/ImageRun.js +2 -2
- package/dist/elements/ImageRun.js.map +1 -1
- package/dist/elements/MathElement.d.ts +1 -1
- package/dist/elements/MathElement.d.ts.map +1 -1
- package/dist/elements/MathElement.js.map +1 -1
- package/dist/elements/Paragraph.d.ts +34 -19
- package/dist/elements/Paragraph.d.ts.map +1 -1
- package/dist/elements/Paragraph.js +286 -231
- package/dist/elements/Paragraph.js.map +1 -1
- package/dist/elements/PreservedElement.d.ts +1 -1
- package/dist/elements/PreservedElement.d.ts.map +1 -1
- package/dist/elements/PreservedElement.js.map +1 -1
- package/dist/elements/PropertyChangeTypes.d.ts +2 -2
- package/dist/elements/PropertyChangeTypes.d.ts.map +1 -1
- package/dist/elements/PropertyChangeTypes.js.map +1 -1
- package/dist/elements/RangeMarker.d.ts +14 -1
- package/dist/elements/RangeMarker.d.ts.map +1 -1
- package/dist/elements/RangeMarker.js +46 -8
- package/dist/elements/RangeMarker.js.map +1 -1
- package/dist/elements/RegisteredBodyElement.d.ts +15 -0
- package/dist/elements/RegisteredBodyElement.d.ts.map +1 -0
- package/dist/elements/RegisteredBodyElement.js +44 -0
- package/dist/elements/RegisteredBodyElement.js.map +1 -0
- package/dist/elements/Revision.d.ts +8 -8
- package/dist/elements/Revision.d.ts.map +1 -1
- package/dist/elements/Revision.js +12 -12
- package/dist/elements/Revision.js.map +1 -1
- package/dist/elements/RevisionContent.d.ts +3 -3
- package/dist/elements/RevisionContent.d.ts.map +1 -1
- package/dist/elements/RevisionContent.js.map +1 -1
- package/dist/elements/RevisionManager.d.ts +2 -2
- package/dist/elements/RevisionManager.d.ts.map +1 -1
- package/dist/elements/RevisionManager.js +2 -2
- package/dist/elements/RevisionManager.js.map +1 -1
- package/dist/elements/Run.d.ts +16 -10
- package/dist/elements/Run.d.ts.map +1 -1
- package/dist/elements/Run.js +199 -173
- package/dist/elements/Run.js.map +1 -1
- package/dist/elements/Section.d.ts +4 -2
- package/dist/elements/Section.d.ts.map +1 -1
- package/dist/elements/Section.js +152 -145
- package/dist/elements/Section.js.map +1 -1
- package/dist/elements/Shape.d.ts +3 -3
- package/dist/elements/Shape.d.ts.map +1 -1
- package/dist/elements/Shape.js +12 -12
- package/dist/elements/Shape.js.map +1 -1
- package/dist/elements/StructuredDocumentTag.d.ts +3 -3
- package/dist/elements/StructuredDocumentTag.d.ts.map +1 -1
- package/dist/elements/StructuredDocumentTag.js +39 -39
- package/dist/elements/StructuredDocumentTag.js.map +1 -1
- package/dist/elements/Table.d.ts +16 -10
- package/dist/elements/Table.d.ts.map +1 -1
- package/dist/elements/Table.js +118 -89
- package/dist/elements/Table.js.map +1 -1
- package/dist/elements/TableCell.d.ts +11 -11
- package/dist/elements/TableCell.d.ts.map +1 -1
- package/dist/elements/TableCell.js +108 -78
- package/dist/elements/TableCell.js.map +1 -1
- package/dist/elements/TableGridChange.d.ts +1 -1
- package/dist/elements/TableGridChange.d.ts.map +1 -1
- package/dist/elements/TableGridChange.js +3 -3
- package/dist/elements/TableGridChange.js.map +1 -1
- package/dist/elements/TableOfContents.d.ts +1 -1
- package/dist/elements/TableOfContents.d.ts.map +1 -1
- package/dist/elements/TableOfContents.js +2 -2
- package/dist/elements/TableOfContents.js.map +1 -1
- package/dist/elements/TableOfContentsElement.d.ts +2 -2
- package/dist/elements/TableOfContentsElement.d.ts.map +1 -1
- package/dist/elements/TableOfContentsElement.js +5 -5
- package/dist/elements/TableOfContentsElement.js.map +1 -1
- package/dist/elements/TableRow.d.ts +18 -7
- package/dist/elements/TableRow.d.ts.map +1 -1
- package/dist/elements/TableRow.js +127 -74
- package/dist/elements/TableRow.js.map +1 -1
- package/dist/elements/TextBox.d.ts +4 -4
- package/dist/elements/TextBox.d.ts.map +1 -1
- package/dist/elements/TextBox.js +6 -6
- package/dist/elements/TextBox.js.map +1 -1
- package/dist/esm/constants/legacyCompatFlags.js +97 -0
- package/dist/esm/constants/legacyCompatFlags.js.map +1 -0
- package/dist/esm/constants/limits.js +36 -0
- package/dist/esm/constants/limits.js.map +1 -0
- package/dist/esm/core/Document.js +8498 -0
- package/dist/esm/core/Document.js.map +1 -0
- package/dist/esm/core/DocumentContent.js +190 -0
- package/dist/esm/core/DocumentContent.js.map +1 -0
- package/dist/esm/core/DocumentEvents.js +47 -0
- package/dist/esm/core/DocumentEvents.js.map +1 -0
- package/dist/esm/core/DocumentGenerator.js +764 -0
- package/dist/esm/core/DocumentGenerator.js.map +1 -0
- package/dist/esm/core/DocumentIdManager.js +67 -0
- package/dist/esm/core/DocumentIdManager.js.map +1 -0
- package/dist/esm/core/DocumentParser.js +8760 -0
- package/dist/esm/core/DocumentParser.js.map +1 -0
- package/dist/esm/core/DocumentValidator.js +222 -0
- package/dist/esm/core/DocumentValidator.js.map +1 -0
- package/dist/esm/core/ElementRegistry.js +24 -0
- package/dist/esm/core/ElementRegistry.js.map +1 -0
- package/dist/esm/core/Relationship.js +177 -0
- package/dist/esm/core/Relationship.js.map +1 -0
- package/dist/esm/core/RelationshipManager.js +202 -0
- package/dist/esm/core/RelationshipManager.js.map +1 -0
- package/dist/esm/elements/AlternateContent.js +19 -0
- package/dist/esm/elements/AlternateContent.js.map +1 -0
- package/dist/esm/elements/Bookmark.js +115 -0
- package/dist/esm/elements/Bookmark.js.map +1 -0
- package/dist/esm/elements/BookmarkManager.js +99 -0
- package/dist/esm/elements/BookmarkManager.js.map +1 -0
- package/dist/esm/elements/Comment.js +181 -0
- package/dist/esm/elements/Comment.js.map +1 -0
- package/dist/esm/elements/CommentManager.js +233 -0
- package/dist/esm/elements/CommentManager.js.map +1 -0
- package/dist/esm/elements/CommonTypes.js +106 -0
- package/dist/esm/elements/CommonTypes.js.map +1 -0
- package/dist/esm/elements/CustomXml.js +19 -0
- package/dist/esm/elements/CustomXml.js.map +1 -0
- package/dist/esm/elements/Endnote.js +107 -0
- package/dist/esm/elements/Endnote.js.map +1 -0
- package/dist/esm/elements/EndnoteManager.js +119 -0
- package/dist/esm/elements/EndnoteManager.js.map +1 -0
- package/dist/esm/elements/Field.js +856 -0
- package/dist/esm/elements/Field.js.map +1 -0
- package/dist/esm/elements/FieldHelpers.js +134 -0
- package/dist/esm/elements/FieldHelpers.js.map +1 -0
- package/dist/esm/elements/FontManager.js +158 -0
- package/dist/esm/elements/FontManager.js.map +1 -0
- package/dist/esm/elements/Footer.js +141 -0
- package/dist/esm/elements/Footer.js.map +1 -0
- package/dist/esm/elements/Footnote.js +107 -0
- package/dist/esm/elements/Footnote.js.map +1 -0
- package/dist/esm/elements/FootnoteManager.js +119 -0
- package/dist/esm/elements/FootnoteManager.js.map +1 -0
- package/dist/esm/elements/Header.js +141 -0
- package/dist/esm/elements/Header.js.map +1 -0
- package/dist/esm/elements/HeaderFooterManager.js +87 -0
- package/dist/esm/elements/HeaderFooterManager.js.map +1 -0
- package/dist/esm/elements/Hyperlink.js +586 -0
- package/dist/esm/elements/Hyperlink.js.map +1 -0
- package/dist/esm/elements/Image.js +1288 -0
- package/dist/esm/elements/Image.js.map +1 -0
- package/dist/esm/elements/ImageManager.js +223 -0
- package/dist/esm/elements/ImageManager.js.map +1 -0
- package/dist/esm/elements/ImageRun.js +29 -0
- package/dist/esm/elements/ImageRun.js.map +1 -0
- package/dist/esm/elements/MathElement.js +37 -0
- package/dist/esm/elements/MathElement.js.map +1 -0
- package/dist/esm/elements/Paragraph.js +2308 -0
- package/dist/esm/elements/Paragraph.js.map +1 -0
- package/dist/esm/elements/PreservedElement.js +29 -0
- package/dist/esm/elements/PreservedElement.js.map +1 -0
- package/dist/esm/elements/PropertyChangeTypes.js +53 -0
- package/dist/esm/elements/PropertyChangeTypes.js.map +1 -0
- package/dist/esm/elements/RangeMarker.js +219 -0
- package/dist/esm/elements/RangeMarker.js.map +1 -0
- package/dist/esm/elements/RegisteredBodyElement.js +40 -0
- package/dist/esm/elements/RegisteredBodyElement.js.map +1 -0
- package/dist/esm/elements/Revision.js +498 -0
- package/dist/esm/elements/Revision.js.map +1 -0
- package/dist/esm/elements/RevisionContent.js +18 -0
- package/dist/esm/elements/RevisionContent.js.map +1 -0
- package/dist/esm/elements/RevisionManager.js +486 -0
- package/dist/esm/elements/RevisionManager.js.map +1 -0
- package/dist/esm/elements/Run.js +1465 -0
- package/dist/esm/elements/Run.js.map +1 -0
- package/dist/esm/elements/Section.js +978 -0
- package/dist/esm/elements/Section.js.map +1 -0
- package/dist/esm/elements/Shape.js +493 -0
- package/dist/esm/elements/Shape.js.map +1 -0
- package/dist/esm/elements/StructuredDocumentTag.js +471 -0
- package/dist/esm/elements/StructuredDocumentTag.js.map +1 -0
- package/dist/esm/elements/Table.js +1456 -0
- package/dist/esm/elements/Table.js.map +1 -0
- package/dist/esm/elements/TableCell.js +835 -0
- package/dist/esm/elements/TableCell.js.map +1 -0
- package/dist/esm/elements/TableGridChange.js +52 -0
- package/dist/esm/elements/TableGridChange.js.map +1 -0
- package/dist/esm/elements/TableOfContents.js +389 -0
- package/dist/esm/elements/TableOfContents.js.map +1 -0
- package/dist/esm/elements/TableOfContentsElement.js +29 -0
- package/dist/esm/elements/TableOfContentsElement.js.map +1 -0
- package/dist/esm/elements/TableRow.js +555 -0
- package/dist/esm/elements/TableRow.js.map +1 -0
- package/dist/esm/elements/TextBox.js +459 -0
- package/dist/esm/elements/TextBox.js.map +1 -0
- package/dist/esm/formatting/AbstractNumbering.js +325 -0
- package/dist/esm/formatting/AbstractNumbering.js.map +1 -0
- package/dist/esm/formatting/NumberingInstance.js +150 -0
- package/dist/esm/formatting/NumberingInstance.js.map +1 -0
- package/dist/esm/formatting/NumberingLevel.js +608 -0
- package/dist/esm/formatting/NumberingLevel.js.map +1 -0
- package/dist/esm/formatting/NumberingManager.js +423 -0
- package/dist/esm/formatting/NumberingManager.js.map +1 -0
- package/dist/esm/formatting/Style.js +1151 -0
- package/dist/esm/formatting/Style.js.map +1 -0
- package/dist/esm/formatting/StylesManager.js +557 -0
- package/dist/esm/formatting/StylesManager.js.map +1 -0
- package/dist/esm/helpers/CleanupHelper.js +350 -0
- package/dist/esm/helpers/CleanupHelper.js.map +1 -0
- package/dist/esm/images/ImageOptimizer.js +161 -0
- package/dist/esm/images/ImageOptimizer.js.map +1 -0
- package/dist/esm/index.js +75 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/internal.js +16 -0
- package/dist/esm/internal.js.map +1 -0
- package/dist/esm/managers/DrawingManager.js +163 -0
- package/dist/esm/managers/DrawingManager.js.map +1 -0
- package/dist/esm/package.json +3 -0
- package/dist/esm/processors/ChangelogGenerator.js +970 -0
- package/dist/esm/processors/ChangelogGenerator.js.map +1 -0
- package/dist/esm/processors/CompatibilityUpgrader.js +130 -0
- package/dist/esm/processors/CompatibilityUpgrader.js.map +1 -0
- package/dist/esm/processors/InMemoryRevisionAcceptor.js +530 -0
- package/dist/esm/processors/InMemoryRevisionAcceptor.js.map +1 -0
- package/dist/esm/processors/MoveOperationHelper.js +57 -0
- package/dist/esm/processors/MoveOperationHelper.js.map +1 -0
- package/dist/esm/processors/RevisionAwareProcessor.js +232 -0
- package/dist/esm/processors/RevisionAwareProcessor.js.map +1 -0
- package/dist/esm/processors/RevisionWalker.js +278 -0
- package/dist/esm/processors/RevisionWalker.js.map +1 -0
- package/dist/{utils → esm/processors}/SelectiveRevisionAcceptor.js +81 -42
- package/dist/esm/processors/SelectiveRevisionAcceptor.js.map +1 -0
- package/dist/esm/processors/ShadingResolver.js +66 -0
- package/dist/esm/processors/ShadingResolver.js.map +1 -0
- package/dist/esm/processors/acceptRevisions.js +416 -0
- package/dist/esm/processors/acceptRevisions.js.map +1 -0
- package/dist/esm/processors/cnfStyleDecoder.js +89 -0
- package/dist/esm/processors/cnfStyleDecoder.js.map +1 -0
- package/dist/esm/processors/stripTrackedChanges.js +201 -0
- package/dist/esm/processors/stripTrackedChanges.js.map +1 -0
- package/dist/esm/tracking/DocumentTrackingContext.js +531 -0
- package/dist/esm/tracking/DocumentTrackingContext.js.map +1 -0
- package/dist/esm/tracking/TrackingContext.js +2 -0
- package/dist/esm/tracking/TrackingContext.js.map +1 -0
- package/dist/esm/types/compatibility-types.js +8 -0
- package/dist/esm/types/compatibility-types.js.map +1 -0
- package/dist/esm/types/document-types.js +2 -0
- package/dist/esm/types/document-types.js.map +1 -0
- package/dist/esm/types/formatting.js +2 -0
- package/dist/esm/types/formatting.js.map +1 -0
- package/dist/esm/types/list-types.js +2 -0
- package/dist/esm/types/list-types.js.map +1 -0
- package/dist/esm/types/settings-types.js +2 -0
- package/dist/esm/types/settings-types.js.map +1 -0
- package/dist/esm/types/styleConfig.js +2 -0
- package/dist/esm/types/styleConfig.js.map +1 -0
- package/dist/esm/utils/KeyedRegistry.js +32 -0
- package/dist/esm/utils/KeyedRegistry.js.map +1 -0
- package/dist/esm/utils/corruptionDetection.js +155 -0
- package/dist/esm/utils/corruptionDetection.js.map +1 -0
- package/dist/esm/utils/dateFormatting.js +4 -0
- package/dist/esm/utils/dateFormatting.js.map +1 -0
- package/dist/esm/utils/deepClone.js +40 -0
- package/dist/esm/utils/deepClone.js.map +1 -0
- package/dist/esm/utils/deepEqual.js +47 -0
- package/dist/esm/utils/deepEqual.js.map +1 -0
- package/dist/esm/utils/diagnostics.js +69 -0
- package/dist/esm/utils/diagnostics.js.map +1 -0
- package/dist/esm/utils/errorHandling.js +36 -0
- package/dist/esm/utils/errorHandling.js.map +1 -0
- package/dist/esm/utils/formatting.js +93 -0
- package/dist/esm/utils/formatting.js.map +1 -0
- package/dist/esm/utils/list-detection.js +148 -0
- package/dist/esm/utils/list-detection.js.map +1 -0
- package/dist/esm/utils/logger.js +205 -0
- package/dist/esm/utils/logger.js.map +1 -0
- package/dist/esm/utils/parsingHelpers.js +56 -0
- package/dist/esm/utils/parsingHelpers.js.map +1 -0
- package/dist/esm/utils/textDiff.js +42 -0
- package/dist/esm/utils/textDiff.js.map +1 -0
- package/dist/esm/utils/units.js +152 -0
- package/dist/esm/utils/units.js.map +1 -0
- package/dist/esm/utils/validation.js +285 -0
- package/dist/esm/utils/validation.js.map +1 -0
- package/dist/esm/utils/xmlSanitization.js +54 -0
- package/dist/esm/utils/xmlSanitization.js.map +1 -0
- package/dist/esm/validation/RevisionAutoFixer.js +340 -0
- package/dist/esm/validation/RevisionAutoFixer.js.map +1 -0
- package/dist/esm/validation/RevisionValidator.js +240 -0
- package/dist/esm/validation/RevisionValidator.js.map +1 -0
- package/dist/esm/validation/ValidationRuleRegistry.js +40 -0
- package/dist/esm/validation/ValidationRuleRegistry.js.map +1 -0
- package/dist/esm/validation/ValidationRules.js +92 -0
- package/dist/esm/validation/ValidationRules.js.map +1 -0
- package/dist/esm/validation/index.js +4 -0
- package/dist/esm/validation/index.js.map +1 -0
- package/dist/esm/xml/XMLBuilder.js +434 -0
- package/dist/esm/xml/XMLBuilder.js.map +1 -0
- package/dist/esm/xml/XMLParser.js +486 -0
- package/dist/esm/xml/XMLParser.js.map +1 -0
- package/dist/esm/zip/ZipHandler.js +298 -0
- package/dist/esm/zip/ZipHandler.js.map +1 -0
- package/dist/esm/zip/ZipReader.js +147 -0
- package/dist/esm/zip/ZipReader.js.map +1 -0
- package/dist/esm/zip/ZipWriter.js +199 -0
- package/dist/esm/zip/ZipWriter.js.map +1 -0
- package/dist/esm/zip/errors.js +43 -0
- package/dist/esm/zip/errors.js.map +1 -0
- package/dist/esm/zip/types.js +31 -0
- package/dist/esm/zip/types.js.map +1 -0
- package/dist/formatting/AbstractNumbering.d.ts +2 -2
- package/dist/formatting/AbstractNumbering.d.ts.map +1 -1
- package/dist/formatting/AbstractNumbering.js +33 -33
- package/dist/formatting/AbstractNumbering.js.map +1 -1
- package/dist/formatting/NumberingInstance.d.ts +2 -2
- package/dist/formatting/NumberingInstance.d.ts.map +1 -1
- package/dist/formatting/NumberingInstance.js +7 -7
- package/dist/formatting/NumberingInstance.js.map +1 -1
- package/dist/formatting/NumberingLevel.d.ts +11 -2
- package/dist/formatting/NumberingLevel.d.ts.map +1 -1
- package/dist/formatting/NumberingLevel.js +111 -25
- package/dist/formatting/NumberingLevel.js.map +1 -1
- package/dist/formatting/NumberingManager.d.ts +4 -4
- package/dist/formatting/NumberingManager.d.ts.map +1 -1
- package/dist/formatting/NumberingManager.js +28 -28
- package/dist/formatting/NumberingManager.js.map +1 -1
- package/dist/formatting/Style.d.ts +14 -7
- package/dist/formatting/Style.d.ts.map +1 -1
- package/dist/formatting/Style.js +309 -112
- package/dist/formatting/Style.js.map +1 -1
- package/dist/formatting/StylesManager.d.ts +2 -2
- package/dist/formatting/StylesManager.d.ts.map +1 -1
- package/dist/formatting/StylesManager.js +52 -52
- package/dist/formatting/StylesManager.js.map +1 -1
- package/dist/helpers/CleanupHelper.d.ts +1 -1
- package/dist/helpers/CleanupHelper.d.ts.map +1 -1
- package/dist/helpers/CleanupHelper.js +15 -15
- package/dist/helpers/CleanupHelper.js.map +1 -1
- package/dist/index.d.ts +81 -90
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +286 -317
- package/dist/index.js.map +1 -1
- package/dist/internal.d.ts +16 -0
- package/dist/internal.d.ts.map +1 -0
- package/dist/internal.js +42 -0
- package/dist/internal.js.map +1 -0
- package/dist/managers/DrawingManager.d.ts +3 -3
- package/dist/managers/DrawingManager.d.ts.map +1 -1
- package/dist/managers/DrawingManager.js +12 -12
- package/dist/managers/DrawingManager.js.map +1 -1
- package/dist/{utils → processors}/ChangelogGenerator.d.ts +2 -2
- package/dist/processors/ChangelogGenerator.d.ts.map +1 -0
- package/dist/{utils → processors}/ChangelogGenerator.js +2 -2
- package/dist/processors/ChangelogGenerator.js.map +1 -0
- package/dist/processors/CompatibilityUpgrader.d.ts.map +1 -0
- package/dist/{utils → processors}/CompatibilityUpgrader.js +10 -10
- package/dist/processors/CompatibilityUpgrader.js.map +1 -0
- package/dist/{utils → processors}/InMemoryRevisionAcceptor.d.ts +3 -3
- package/dist/processors/InMemoryRevisionAcceptor.d.ts.map +1 -0
- package/dist/{utils → processors}/InMemoryRevisionAcceptor.js +84 -27
- package/dist/processors/InMemoryRevisionAcceptor.js.map +1 -0
- package/dist/{utils → processors}/MoveOperationHelper.d.ts +4 -4
- package/dist/processors/MoveOperationHelper.d.ts.map +1 -0
- package/dist/{utils → processors}/MoveOperationHelper.js +10 -10
- package/dist/processors/MoveOperationHelper.js.map +1 -0
- package/dist/{utils → processors}/RevisionAwareProcessor.d.ts +3 -3
- package/dist/processors/RevisionAwareProcessor.d.ts.map +1 -0
- package/dist/{utils → processors}/RevisionAwareProcessor.js +2 -2
- package/dist/processors/RevisionAwareProcessor.js.map +1 -0
- package/dist/{utils → processors}/RevisionWalker.d.ts +2 -1
- package/dist/processors/RevisionWalker.d.ts.map +1 -0
- package/dist/{utils → processors}/RevisionWalker.js +28 -0
- package/dist/processors/RevisionWalker.js.map +1 -0
- package/dist/{utils → processors}/SelectiveRevisionAcceptor.d.ts +4 -3
- package/dist/processors/SelectiveRevisionAcceptor.d.ts.map +1 -0
- package/dist/processors/SelectiveRevisionAcceptor.js +402 -0
- package/dist/processors/SelectiveRevisionAcceptor.js.map +1 -0
- package/dist/processors/ShadingResolver.d.ts +6 -0
- package/dist/processors/ShadingResolver.d.ts.map +1 -0
- package/dist/{utils → processors}/ShadingResolver.js +2 -2
- package/dist/processors/ShadingResolver.js.map +1 -0
- package/dist/{utils → processors}/acceptRevisions.d.ts +1 -1
- package/dist/processors/acceptRevisions.d.ts.map +1 -0
- package/dist/{utils → processors}/acceptRevisions.js +24 -4
- package/dist/processors/acceptRevisions.js.map +1 -0
- package/dist/{utils → processors}/cnfStyleDecoder.d.ts +1 -1
- package/dist/processors/cnfStyleDecoder.d.ts.map +1 -0
- package/dist/processors/cnfStyleDecoder.js.map +1 -0
- package/dist/processors/stripTrackedChanges.d.ts +3 -0
- package/dist/processors/stripTrackedChanges.d.ts.map +1 -0
- package/dist/{utils → processors}/stripTrackedChanges.js +16 -6
- package/dist/processors/stripTrackedChanges.js.map +1 -0
- package/dist/tracking/DocumentTrackingContext.d.ts +4 -4
- package/dist/tracking/DocumentTrackingContext.d.ts.map +1 -1
- package/dist/tracking/DocumentTrackingContext.js +38 -43
- package/dist/tracking/DocumentTrackingContext.js.map +1 -1
- package/dist/tracking/TrackingContext.d.ts +8 -8
- package/dist/tracking/TrackingContext.d.ts.map +1 -1
- package/dist/tracking/TrackingContext.js.map +1 -1
- package/dist/types/document-types.d.ts +28 -0
- package/dist/types/document-types.d.ts.map +1 -0
- package/dist/types/document-types.js +3 -0
- package/dist/types/document-types.js.map +1 -0
- package/dist/types/formatting.d.ts +4 -4
- package/dist/types/formatting.d.ts.map +1 -1
- package/dist/types/formatting.js.map +1 -1
- package/dist/types/settings-types.d.ts +6 -0
- package/dist/types/settings-types.d.ts.map +1 -1
- package/dist/types/settings-types.js.map +1 -1
- package/dist/utils/KeyedRegistry.d.ts +13 -0
- package/dist/utils/KeyedRegistry.d.ts.map +1 -0
- package/dist/utils/KeyedRegistry.js +36 -0
- package/dist/utils/KeyedRegistry.js.map +1 -0
- package/dist/utils/corruptionDetection.d.ts +1 -1
- package/dist/utils/corruptionDetection.d.ts.map +1 -1
- package/dist/utils/corruptionDetection.js +4 -4
- package/dist/utils/corruptionDetection.js.map +1 -1
- package/dist/utils/deepEqual.d.ts +2 -0
- package/dist/utils/deepEqual.d.ts.map +1 -0
- package/dist/utils/deepEqual.js +50 -0
- package/dist/utils/deepEqual.js.map +1 -0
- package/dist/utils/list-detection.d.ts +2 -2
- package/dist/utils/list-detection.d.ts.map +1 -1
- package/dist/utils/list-detection.js.map +1 -1
- package/dist/utils/parsingHelpers.d.ts +1 -1
- package/dist/utils/parsingHelpers.d.ts.map +1 -1
- package/dist/utils/parsingHelpers.js +2 -2
- package/dist/utils/parsingHelpers.js.map +1 -1
- package/dist/utils/validation.js +7 -7
- package/dist/utils/validation.js.map +1 -1
- package/dist/utils/xmlSanitization.js +2 -2
- package/dist/utils/xmlSanitization.js.map +1 -1
- package/dist/validation/RevisionAutoFixer.d.ts +4 -4
- package/dist/validation/RevisionAutoFixer.d.ts.map +1 -1
- package/dist/validation/RevisionAutoFixer.js +11 -11
- package/dist/validation/RevisionAutoFixer.js.map +1 -1
- package/dist/validation/RevisionValidator.d.ts +5 -4
- package/dist/validation/RevisionValidator.d.ts.map +1 -1
- package/dist/validation/RevisionValidator.js +29 -30
- package/dist/validation/RevisionValidator.js.map +1 -1
- package/dist/validation/ValidationRuleRegistry.d.ts +27 -0
- package/dist/validation/ValidationRuleRegistry.d.ts.map +1 -0
- package/dist/validation/ValidationRuleRegistry.js +43 -0
- package/dist/validation/ValidationRuleRegistry.js.map +1 -0
- package/dist/validation/index.d.ts +3 -3
- package/dist/validation/index.d.ts.map +1 -1
- package/dist/validation/index.js +10 -10
- package/dist/validation/index.js.map +1 -1
- package/dist/xml/XMLBuilder.d.ts +6 -1
- package/dist/xml/XMLBuilder.d.ts.map +1 -1
- package/dist/xml/XMLBuilder.js +11 -6
- package/dist/xml/XMLBuilder.js.map +1 -1
- package/dist/xml/XMLParser.js +6 -6
- package/dist/xml/XMLParser.js.map +1 -1
- package/dist/zip/ZipHandler.d.ts +1 -1
- package/dist/zip/ZipHandler.d.ts.map +1 -1
- package/dist/zip/ZipHandler.js +8 -8
- package/dist/zip/ZipHandler.js.map +1 -1
- package/dist/zip/ZipReader.d.ts +1 -1
- package/dist/zip/ZipReader.d.ts.map +1 -1
- package/dist/zip/ZipReader.js +14 -14
- package/dist/zip/ZipReader.js.map +1 -1
- package/dist/zip/ZipWriter.d.ts +1 -1
- package/dist/zip/ZipWriter.d.ts.map +1 -1
- package/dist/zip/ZipWriter.js +10 -10
- package/dist/zip/ZipWriter.js.map +1 -1
- package/package.json +20 -4
- package/src/constants/legacyCompatFlags.ts +1 -1
- package/src/core/Document.ts +461 -167
- package/src/core/DocumentContent.ts +14 -11
- package/src/core/DocumentEvents.ts +90 -0
- package/src/core/DocumentGenerator.ts +49 -22
- package/src/core/DocumentParser.ts +2180 -617
- package/src/core/DocumentValidator.ts +7 -7
- package/src/core/ElementRegistry.ts +69 -0
- package/src/core/Relationship.ts +1 -1
- package/src/core/RelationshipManager.ts +4 -4
- package/src/elements/AlternateContent.ts +1 -1
- package/src/elements/Bookmark.ts +52 -4
- package/src/elements/BookmarkManager.ts +2 -2
- package/src/elements/Comment.ts +3 -3
- package/src/elements/CommentManager.ts +4 -4
- package/src/elements/CommonTypes.ts +45 -7
- package/src/elements/CustomXml.ts +1 -1
- package/src/elements/Endnote.ts +2 -2
- package/src/elements/EndnoteManager.ts +3 -3
- package/src/elements/Field.ts +44 -10
- package/src/elements/FieldHelpers.ts +2 -2
- package/src/elements/Footer.ts +4 -4
- package/src/elements/Footnote.ts +2 -2
- package/src/elements/FootnoteManager.ts +3 -3
- package/src/elements/Header.ts +4 -4
- package/src/elements/HeaderFooterManager.ts +2 -2
- package/src/elements/Hyperlink.ts +16 -12
- package/src/elements/Image.ts +3 -3
- package/src/elements/ImageManager.ts +2 -2
- package/src/elements/ImageRun.ts +3 -3
- package/src/elements/MathElement.ts +1 -1
- package/src/elements/Paragraph.ts +221 -88
- package/src/elements/PreservedElement.ts +1 -1
- package/src/elements/PropertyChangeTypes.ts +2 -2
- package/src/elements/RangeMarker.ts +153 -12
- package/src/elements/RegisteredBodyElement.ts +52 -0
- package/src/elements/Revision.ts +14 -14
- package/src/elements/RevisionContent.ts +3 -3
- package/src/elements/RevisionManager.ts +3 -3
- package/src/elements/Run.ts +221 -94
- package/src/elements/Section.ts +136 -69
- package/src/elements/Shape.ts +4 -4
- package/src/elements/StructuredDocumentTag.ts +3 -3
- package/src/elements/Table.ts +91 -27
- package/src/elements/TableCell.ts +62 -34
- package/src/elements/TableGridChange.ts +1 -1
- package/src/elements/TableOfContents.ts +1 -1
- package/src/elements/TableOfContentsElement.ts +2 -2
- package/src/elements/TableRow.ts +192 -48
- package/src/elements/TextBox.ts +5 -5
- package/src/formatting/AbstractNumbering.ts +3 -3
- package/src/formatting/NumberingInstance.ts +2 -2
- package/src/formatting/NumberingLevel.ts +201 -10
- package/src/formatting/NumberingManager.ts +5 -5
- package/src/formatting/Style.ts +382 -86
- package/src/formatting/StylesManager.ts +4 -4
- package/src/helpers/CleanupHelper.ts +6 -6
- package/src/index.ts +118 -127
- package/src/internal.ts +79 -0
- package/src/managers/DrawingManager.ts +3 -3
- package/src/{utils → processors}/ChangelogGenerator.ts +3 -3
- package/src/{utils → processors}/CompatibilityUpgrader.ts +2 -2
- package/src/{utils → processors}/InMemoryRevisionAcceptor.ts +100 -12
- package/src/{utils → processors}/MoveOperationHelper.ts +5 -5
- package/src/{utils → processors}/RevisionAwareProcessor.ts +3 -3
- package/src/{utils → processors}/RevisionWalker.ts +42 -1
- package/src/{utils → processors}/SelectiveRevisionAcceptor.ts +98 -39
- package/src/{utils → processors}/ShadingResolver.ts +5 -5
- package/src/{utils → processors}/acceptRevisions.ts +77 -9
- package/src/{utils → processors}/cnfStyleDecoder.ts +1 -1
- package/src/{utils → processors}/stripTrackedChanges.ts +35 -10
- package/src/tracking/DocumentTrackingContext.ts +12 -14
- package/src/tracking/TrackingContext.ts +8 -8
- package/src/types/document-types.ts +53 -0
- package/src/types/formatting.ts +4 -4
- package/src/types/settings-types.ts +32 -0
- package/src/utils/KeyedRegistry.ts +41 -0
- package/src/utils/corruptionDetection.ts +2 -2
- package/src/utils/deepEqual.ts +58 -0
- package/src/utils/list-detection.ts +2 -2
- package/src/utils/parsingHelpers.ts +11 -3
- package/src/utils/validation.ts +3 -3
- package/src/utils/xmlSanitization.ts +1 -1
- package/src/validation/RevisionAutoFixer.ts +5 -5
- package/src/validation/RevisionValidator.ts +39 -28
- package/src/validation/ValidationRuleRegistry.ts +86 -0
- package/src/validation/index.ts +3 -3
- package/src/xml/XMLBuilder.ts +13 -3
- package/src/xml/XMLParser.ts +2 -2
- package/src/zip/ZipHandler.ts +4 -4
- package/src/zip/ZipReader.ts +3 -3
- package/src/zip/ZipWriter.ts +3 -3
- package/dist/utils/ChangelogGenerator.d.ts.map +0 -1
- package/dist/utils/ChangelogGenerator.js.map +0 -1
- package/dist/utils/CompatibilityUpgrader.d.ts.map +0 -1
- package/dist/utils/CompatibilityUpgrader.js.map +0 -1
- package/dist/utils/InMemoryRevisionAcceptor.d.ts.map +0 -1
- package/dist/utils/InMemoryRevisionAcceptor.js.map +0 -1
- package/dist/utils/MoveOperationHelper.d.ts.map +0 -1
- package/dist/utils/MoveOperationHelper.js.map +0 -1
- package/dist/utils/RevisionAwareProcessor.d.ts.map +0 -1
- package/dist/utils/RevisionAwareProcessor.js.map +0 -1
- package/dist/utils/RevisionWalker.d.ts.map +0 -1
- package/dist/utils/RevisionWalker.js.map +0 -1
- package/dist/utils/SelectiveRevisionAcceptor.d.ts.map +0 -1
- package/dist/utils/SelectiveRevisionAcceptor.js.map +0 -1
- package/dist/utils/ShadingResolver.d.ts +0 -6
- package/dist/utils/ShadingResolver.d.ts.map +0 -1
- package/dist/utils/ShadingResolver.js.map +0 -1
- package/dist/utils/acceptRevisions.d.ts.map +0 -1
- package/dist/utils/acceptRevisions.js.map +0 -1
- package/dist/utils/cnfStyleDecoder.d.ts.map +0 -1
- package/dist/utils/cnfStyleDecoder.js.map +0 -1
- package/dist/utils/stripTrackedChanges.d.ts +0 -3
- package/dist/utils/stripTrackedChanges.d.ts.map +0 -1
- package/dist/utils/stripTrackedChanges.js.map +0 -1
- package/src/__tests__/helper-methods.test.ts +0 -512
- package/src/constants/CLAUDE.md +0 -28
- package/src/core/CLAUDE.md +0 -113
- package/src/elements/CLAUDE.md +0 -142
- package/src/formatting/CLAUDE.md +0 -78
- package/src/managers/CLAUDE.md +0 -47
- package/src/tracking/CLAUDE.md +0 -30
- package/src/types/CLAUDE.md +0 -39
- package/src/utils/CLAUDE.md +0 -168
- package/src/validation/CLAUDE.md +0 -40
- package/src/xml/CLAUDE.md +0 -65
- package/src/zip/CLAUDE.md +0 -55
- /package/dist/{utils → processors}/CompatibilityUpgrader.d.ts +0 -0
- /package/dist/{utils → processors}/cnfStyleDecoder.js +0 -0
|
@@ -0,0 +1,2308 @@
|
|
|
1
|
+
import { deepClone } from '../utils/deepClone.js';
|
|
2
|
+
import { deepEqual } from '../utils/deepEqual.js';
|
|
3
|
+
import { formatDateForXml } from '../utils/dateFormatting.js';
|
|
4
|
+
import { logParagraphContent, logTextDirection } from '../utils/diagnostics.js';
|
|
5
|
+
import { isEqualFormatting } from '../utils/formatting.js';
|
|
6
|
+
import { defaultLogger } from '../utils/logger.js';
|
|
7
|
+
import { XMLBuilder } from '../xml/XMLBuilder.js';
|
|
8
|
+
import { buildShadingAttributes, } from './CommonTypes.js';
|
|
9
|
+
import { ComplexField, Field } from './Field.js';
|
|
10
|
+
import { Hyperlink } from './Hyperlink.js';
|
|
11
|
+
import { RangeMarker } from './RangeMarker.js';
|
|
12
|
+
import { Revision } from './Revision.js';
|
|
13
|
+
import { Run } from './Run.js';
|
|
14
|
+
import { Shape } from './Shape.js';
|
|
15
|
+
import { TextBox } from './TextBox.js';
|
|
16
|
+
export function isRun(content) {
|
|
17
|
+
return content instanceof Run;
|
|
18
|
+
}
|
|
19
|
+
export function isField(content) {
|
|
20
|
+
return content instanceof Field || content instanceof ComplexField;
|
|
21
|
+
}
|
|
22
|
+
export function isSimpleField(content) {
|
|
23
|
+
return content instanceof Field && !(content instanceof ComplexField);
|
|
24
|
+
}
|
|
25
|
+
export function isComplexField(content) {
|
|
26
|
+
return content instanceof ComplexField;
|
|
27
|
+
}
|
|
28
|
+
export function isHyperlink(content) {
|
|
29
|
+
return content instanceof Hyperlink;
|
|
30
|
+
}
|
|
31
|
+
export function isRevision(content) {
|
|
32
|
+
return content instanceof Revision;
|
|
33
|
+
}
|
|
34
|
+
export function isRangeMarker(content) {
|
|
35
|
+
return content instanceof RangeMarker;
|
|
36
|
+
}
|
|
37
|
+
export function isShape(content) {
|
|
38
|
+
return content instanceof Shape;
|
|
39
|
+
}
|
|
40
|
+
export function isTextBox(content) {
|
|
41
|
+
return content instanceof TextBox;
|
|
42
|
+
}
|
|
43
|
+
export class Paragraph {
|
|
44
|
+
content = [];
|
|
45
|
+
formatting;
|
|
46
|
+
bookmarksStart = [];
|
|
47
|
+
bookmarksEnd = [];
|
|
48
|
+
commentsStart = [];
|
|
49
|
+
commentsEnd = [];
|
|
50
|
+
_isPreserved = false;
|
|
51
|
+
trackingContext;
|
|
52
|
+
_parentCell;
|
|
53
|
+
_stylesManager;
|
|
54
|
+
_isPartOfMultiParagraphField;
|
|
55
|
+
constructor(formatting = {}) {
|
|
56
|
+
this.formatting = formatting;
|
|
57
|
+
}
|
|
58
|
+
_setTrackingContext(context) {
|
|
59
|
+
this.trackingContext = context;
|
|
60
|
+
}
|
|
61
|
+
_setParentCell(cell) {
|
|
62
|
+
this._parentCell = cell;
|
|
63
|
+
}
|
|
64
|
+
_getParentCell() {
|
|
65
|
+
return this._parentCell;
|
|
66
|
+
}
|
|
67
|
+
isInTableCell() {
|
|
68
|
+
return this._parentCell !== undefined;
|
|
69
|
+
}
|
|
70
|
+
getTableConditionalStyle() {
|
|
71
|
+
if (this._parentCell) {
|
|
72
|
+
const cellFormatting = this._parentCell.getFormatting();
|
|
73
|
+
if (cellFormatting.cnfStyle) {
|
|
74
|
+
return cellFormatting.cnfStyle;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return this.formatting.cnfStyle;
|
|
78
|
+
}
|
|
79
|
+
_setStylesManager(manager) {
|
|
80
|
+
this._stylesManager = manager;
|
|
81
|
+
}
|
|
82
|
+
_getStylesManager() {
|
|
83
|
+
return this._stylesManager;
|
|
84
|
+
}
|
|
85
|
+
static create(textOrFormatting, formatting) {
|
|
86
|
+
if (typeof textOrFormatting === 'string') {
|
|
87
|
+
const paragraph = new Paragraph(formatting);
|
|
88
|
+
paragraph.addText(textOrFormatting);
|
|
89
|
+
return paragraph;
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
return new Paragraph(textOrFormatting);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
static createWithStyle(text, styleId) {
|
|
96
|
+
const paragraph = new Paragraph({ style: styleId });
|
|
97
|
+
paragraph.addText(text);
|
|
98
|
+
return paragraph;
|
|
99
|
+
}
|
|
100
|
+
static createEmpty() {
|
|
101
|
+
return new Paragraph();
|
|
102
|
+
}
|
|
103
|
+
static createFormatted(text, runFormatting, paragraphFormatting) {
|
|
104
|
+
const paragraph = new Paragraph(paragraphFormatting);
|
|
105
|
+
paragraph.addText(text, runFormatting);
|
|
106
|
+
return paragraph;
|
|
107
|
+
}
|
|
108
|
+
addRun(run) {
|
|
109
|
+
run._setParentParagraph(this);
|
|
110
|
+
if (this.trackingContext?.isEnabled()) {
|
|
111
|
+
const revision = Revision.createInsertion(this.trackingContext.getAuthor(), run, new Date());
|
|
112
|
+
this.trackingContext.getRevisionManager().register(revision);
|
|
113
|
+
this.content.push(revision);
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
this.content.push(run);
|
|
117
|
+
}
|
|
118
|
+
return this;
|
|
119
|
+
}
|
|
120
|
+
addField(field) {
|
|
121
|
+
if (this.trackingContext?.isEnabled()) {
|
|
122
|
+
this.content.push(field);
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
this.content.push(field);
|
|
126
|
+
}
|
|
127
|
+
return this;
|
|
128
|
+
}
|
|
129
|
+
addComplexField(field) {
|
|
130
|
+
this.content.push(field);
|
|
131
|
+
return this;
|
|
132
|
+
}
|
|
133
|
+
addHyperlink(urlOrHyperlink) {
|
|
134
|
+
if (typeof urlOrHyperlink === 'string') {
|
|
135
|
+
const hyperlink = new Hyperlink({ url: urlOrHyperlink, text: urlOrHyperlink });
|
|
136
|
+
hyperlink._setParentParagraph(this);
|
|
137
|
+
if (this.trackingContext?.isEnabled()) {
|
|
138
|
+
const revision = Revision.createInsertion(this.trackingContext.getAuthor(), hyperlink, new Date());
|
|
139
|
+
this.trackingContext.getRevisionManager().register(revision);
|
|
140
|
+
this.content.push(revision);
|
|
141
|
+
}
|
|
142
|
+
else {
|
|
143
|
+
this.content.push(hyperlink);
|
|
144
|
+
}
|
|
145
|
+
return hyperlink;
|
|
146
|
+
}
|
|
147
|
+
else if (urlOrHyperlink instanceof Hyperlink) {
|
|
148
|
+
urlOrHyperlink._setParentParagraph(this);
|
|
149
|
+
if (this.trackingContext?.isEnabled()) {
|
|
150
|
+
const revision = Revision.createInsertion(this.trackingContext.getAuthor(), urlOrHyperlink, new Date());
|
|
151
|
+
this.trackingContext.getRevisionManager().register(revision);
|
|
152
|
+
this.content.push(revision);
|
|
153
|
+
}
|
|
154
|
+
else {
|
|
155
|
+
this.content.push(urlOrHyperlink);
|
|
156
|
+
}
|
|
157
|
+
return this;
|
|
158
|
+
}
|
|
159
|
+
else {
|
|
160
|
+
const hyperlink = new Hyperlink({ text: 'Link' });
|
|
161
|
+
hyperlink._setParentParagraph(this);
|
|
162
|
+
if (this.trackingContext?.isEnabled()) {
|
|
163
|
+
const revision = Revision.createInsertion(this.trackingContext.getAuthor(), hyperlink, new Date());
|
|
164
|
+
this.trackingContext.getRevisionManager().register(revision);
|
|
165
|
+
this.content.push(revision);
|
|
166
|
+
}
|
|
167
|
+
else {
|
|
168
|
+
this.content.push(hyperlink);
|
|
169
|
+
}
|
|
170
|
+
return hyperlink;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
addRevision(revision) {
|
|
174
|
+
this.content.push(revision);
|
|
175
|
+
return this;
|
|
176
|
+
}
|
|
177
|
+
addRangeMarker(rangeMarker) {
|
|
178
|
+
this.content.push(rangeMarker);
|
|
179
|
+
return this;
|
|
180
|
+
}
|
|
181
|
+
addShape(shape) {
|
|
182
|
+
this.content.push(shape);
|
|
183
|
+
return this;
|
|
184
|
+
}
|
|
185
|
+
addTextBox(textbox) {
|
|
186
|
+
this.content.push(textbox);
|
|
187
|
+
return this;
|
|
188
|
+
}
|
|
189
|
+
addContent(item) {
|
|
190
|
+
this.content.push(item);
|
|
191
|
+
return this;
|
|
192
|
+
}
|
|
193
|
+
addBookmarkStart(bookmark) {
|
|
194
|
+
this.bookmarksStart.push(bookmark);
|
|
195
|
+
return this;
|
|
196
|
+
}
|
|
197
|
+
addBookmarkEnd(bookmark) {
|
|
198
|
+
this.bookmarksEnd.push(bookmark);
|
|
199
|
+
return this;
|
|
200
|
+
}
|
|
201
|
+
addBookmark(bookmark) {
|
|
202
|
+
this.addBookmarkStart(bookmark);
|
|
203
|
+
this.addBookmarkEnd(bookmark);
|
|
204
|
+
return this;
|
|
205
|
+
}
|
|
206
|
+
getBookmarksStart() {
|
|
207
|
+
return [...this.bookmarksStart];
|
|
208
|
+
}
|
|
209
|
+
getBookmarksEnd() {
|
|
210
|
+
return [...this.bookmarksEnd];
|
|
211
|
+
}
|
|
212
|
+
removeBookmarkEnd(id) {
|
|
213
|
+
const index = this.bookmarksEnd.findIndex((bm) => bm.getId() === id);
|
|
214
|
+
if (index !== -1) {
|
|
215
|
+
this.bookmarksEnd.splice(index, 1);
|
|
216
|
+
return true;
|
|
217
|
+
}
|
|
218
|
+
return false;
|
|
219
|
+
}
|
|
220
|
+
addCommentStart(comment) {
|
|
221
|
+
this.commentsStart.push(comment);
|
|
222
|
+
return this;
|
|
223
|
+
}
|
|
224
|
+
addCommentEnd(comment) {
|
|
225
|
+
this.commentsEnd.push(comment);
|
|
226
|
+
return this;
|
|
227
|
+
}
|
|
228
|
+
addComment(comment) {
|
|
229
|
+
this.addCommentStart(comment);
|
|
230
|
+
this.addCommentEnd(comment);
|
|
231
|
+
return this;
|
|
232
|
+
}
|
|
233
|
+
getCommentsStart() {
|
|
234
|
+
return [...this.commentsStart];
|
|
235
|
+
}
|
|
236
|
+
getCommentsEnd() {
|
|
237
|
+
return [...this.commentsEnd];
|
|
238
|
+
}
|
|
239
|
+
addPageNumber(formatting) {
|
|
240
|
+
return this.addField(Field.createPageNumber(formatting));
|
|
241
|
+
}
|
|
242
|
+
addTotalPages(formatting) {
|
|
243
|
+
return this.addField(Field.createTotalPages(formatting));
|
|
244
|
+
}
|
|
245
|
+
addDate(format, formatting) {
|
|
246
|
+
return this.addField(Field.createDate(format, formatting));
|
|
247
|
+
}
|
|
248
|
+
addTime(format, formatting) {
|
|
249
|
+
return this.addField(Field.createTime(format, formatting));
|
|
250
|
+
}
|
|
251
|
+
addFilename(includePath = false, formatting) {
|
|
252
|
+
return this.addField(Field.createFilename(includePath, formatting));
|
|
253
|
+
}
|
|
254
|
+
addAuthor(formatting) {
|
|
255
|
+
return this.addField(Field.createAuthor(formatting));
|
|
256
|
+
}
|
|
257
|
+
addTitle(formatting) {
|
|
258
|
+
return this.addField(Field.createTitle(formatting));
|
|
259
|
+
}
|
|
260
|
+
addText(text, formatting) {
|
|
261
|
+
const run = new Run(text, formatting);
|
|
262
|
+
run._setParentParagraph(this);
|
|
263
|
+
if (this.trackingContext?.isEnabled()) {
|
|
264
|
+
const revision = Revision.createInsertion(this.trackingContext.getAuthor(), run, new Date());
|
|
265
|
+
this.trackingContext.getRevisionManager().register(revision);
|
|
266
|
+
this.content.push(revision);
|
|
267
|
+
}
|
|
268
|
+
else {
|
|
269
|
+
this.content.push(run);
|
|
270
|
+
}
|
|
271
|
+
return this;
|
|
272
|
+
}
|
|
273
|
+
addLineBreak() {
|
|
274
|
+
const run = new Run('');
|
|
275
|
+
run.addBreak();
|
|
276
|
+
this.content.push(run);
|
|
277
|
+
return this;
|
|
278
|
+
}
|
|
279
|
+
addColumnBreak() {
|
|
280
|
+
const run = new Run('');
|
|
281
|
+
run.addBreak('column');
|
|
282
|
+
this.content.push(run);
|
|
283
|
+
return this;
|
|
284
|
+
}
|
|
285
|
+
setText(text, formatting) {
|
|
286
|
+
this.content = [new Run(text, formatting)];
|
|
287
|
+
return this;
|
|
288
|
+
}
|
|
289
|
+
getRuns() {
|
|
290
|
+
const runs = [];
|
|
291
|
+
for (const item of this.content) {
|
|
292
|
+
if (item instanceof Run) {
|
|
293
|
+
runs.push(item);
|
|
294
|
+
}
|
|
295
|
+
else if (item instanceof Revision) {
|
|
296
|
+
runs.push(...item.getRuns());
|
|
297
|
+
}
|
|
298
|
+
else if (item instanceof Hyperlink) {
|
|
299
|
+
runs.push(item.getRun());
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
return runs;
|
|
303
|
+
}
|
|
304
|
+
getRevisions() {
|
|
305
|
+
return this.content.filter((item) => item instanceof Revision);
|
|
306
|
+
}
|
|
307
|
+
getContent() {
|
|
308
|
+
return [...this.content];
|
|
309
|
+
}
|
|
310
|
+
clearContent() {
|
|
311
|
+
if (this.trackingContext?.isEnabled() && this.content.length > 0) {
|
|
312
|
+
const deletedContent = [];
|
|
313
|
+
for (const item of this.content) {
|
|
314
|
+
if (item instanceof Revision) {
|
|
315
|
+
deletedContent.push(item);
|
|
316
|
+
}
|
|
317
|
+
else if (item instanceof Run || item instanceof Hyperlink) {
|
|
318
|
+
const revision = Revision.createDeletion(this.trackingContext.getAuthor(), item, new Date());
|
|
319
|
+
this.trackingContext.getRevisionManager().register(revision);
|
|
320
|
+
deletedContent.push(revision);
|
|
321
|
+
}
|
|
322
|
+
else {
|
|
323
|
+
deletedContent.push(item);
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
this.content = deletedContent;
|
|
327
|
+
}
|
|
328
|
+
else {
|
|
329
|
+
this.content = [];
|
|
330
|
+
}
|
|
331
|
+
return this;
|
|
332
|
+
}
|
|
333
|
+
replaceContent(oldItem, newItems) {
|
|
334
|
+
const index = this.content.indexOf(oldItem);
|
|
335
|
+
if (index === -1) {
|
|
336
|
+
return false;
|
|
337
|
+
}
|
|
338
|
+
this.content.splice(index, 1, ...newItems);
|
|
339
|
+
return true;
|
|
340
|
+
}
|
|
341
|
+
setContent(content) {
|
|
342
|
+
if (this.trackingContext?.isEnabled() && this.content.length > 0) {
|
|
343
|
+
const deletedContent = [];
|
|
344
|
+
for (const item of this.content) {
|
|
345
|
+
if (item instanceof Revision) {
|
|
346
|
+
deletedContent.push(item);
|
|
347
|
+
}
|
|
348
|
+
else if (item instanceof Run || item instanceof Hyperlink) {
|
|
349
|
+
const revision = Revision.createDeletion(this.trackingContext.getAuthor(), item, new Date());
|
|
350
|
+
this.trackingContext.getRevisionManager().register(revision);
|
|
351
|
+
deletedContent.push(revision);
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
this.content = [...deletedContent, ...content];
|
|
355
|
+
}
|
|
356
|
+
else {
|
|
357
|
+
this.content = [...content];
|
|
358
|
+
}
|
|
359
|
+
for (const item of this.content) {
|
|
360
|
+
if (item instanceof Hyperlink) {
|
|
361
|
+
item._setParentParagraph(this);
|
|
362
|
+
}
|
|
363
|
+
else if (item instanceof Run) {
|
|
364
|
+
item._setParentParagraph(this);
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
removeContentAt(index) {
|
|
369
|
+
if (index < 0 || index >= this.content.length) {
|
|
370
|
+
return undefined;
|
|
371
|
+
}
|
|
372
|
+
const item = this.content[index];
|
|
373
|
+
if (this.trackingContext?.isEnabled()) {
|
|
374
|
+
if (item instanceof Run || item instanceof Hyperlink) {
|
|
375
|
+
const revision = Revision.createDeletion(this.trackingContext.getAuthor(), item, new Date());
|
|
376
|
+
this.trackingContext.getRevisionManager().register(revision);
|
|
377
|
+
this.content[index] = revision;
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
else {
|
|
381
|
+
this.content.splice(index, 1);
|
|
382
|
+
}
|
|
383
|
+
return item;
|
|
384
|
+
}
|
|
385
|
+
getText() {
|
|
386
|
+
return this.content
|
|
387
|
+
.filter((item) => item instanceof Run || item instanceof Hyperlink)
|
|
388
|
+
.map((item) => item.getText())
|
|
389
|
+
.join('');
|
|
390
|
+
}
|
|
391
|
+
getFields() {
|
|
392
|
+
return this.content.filter((item) => item instanceof Field || item instanceof ComplexField);
|
|
393
|
+
}
|
|
394
|
+
findFieldsByInstruction(pattern) {
|
|
395
|
+
const regex = typeof pattern === 'string' ? new RegExp(pattern, 'i') : pattern;
|
|
396
|
+
return this.getFields().filter((field) => {
|
|
397
|
+
const instruction = field.getInstruction();
|
|
398
|
+
return regex.test(instruction);
|
|
399
|
+
});
|
|
400
|
+
}
|
|
401
|
+
removeAllFields() {
|
|
402
|
+
const originalLength = this.content.length;
|
|
403
|
+
this.content = this.content.filter((item) => !(item instanceof Field || item instanceof ComplexField));
|
|
404
|
+
return originalLength - this.content.length;
|
|
405
|
+
}
|
|
406
|
+
replaceField(oldField, replacement) {
|
|
407
|
+
const index = this.content.indexOf(oldField);
|
|
408
|
+
if (index === -1)
|
|
409
|
+
return false;
|
|
410
|
+
if (typeof replacement === 'string') {
|
|
411
|
+
this.content[index] = new Run(replacement);
|
|
412
|
+
}
|
|
413
|
+
else {
|
|
414
|
+
this.content[index] = replacement;
|
|
415
|
+
}
|
|
416
|
+
return true;
|
|
417
|
+
}
|
|
418
|
+
getFormatting() {
|
|
419
|
+
return { ...this.formatting };
|
|
420
|
+
}
|
|
421
|
+
getLeftIndent() {
|
|
422
|
+
return this.formatting.indentation?.left;
|
|
423
|
+
}
|
|
424
|
+
getRightIndent() {
|
|
425
|
+
return this.formatting.indentation?.right;
|
|
426
|
+
}
|
|
427
|
+
getFirstLineIndent() {
|
|
428
|
+
return this.formatting.indentation?.firstLine;
|
|
429
|
+
}
|
|
430
|
+
getHangingIndent() {
|
|
431
|
+
return this.formatting.indentation?.hanging;
|
|
432
|
+
}
|
|
433
|
+
getSpaceBefore() {
|
|
434
|
+
return this.formatting.spacing?.before;
|
|
435
|
+
}
|
|
436
|
+
getSpaceAfter() {
|
|
437
|
+
return this.formatting.spacing?.after;
|
|
438
|
+
}
|
|
439
|
+
getLineSpacing() {
|
|
440
|
+
return this.formatting.spacing?.line;
|
|
441
|
+
}
|
|
442
|
+
getAlignment() {
|
|
443
|
+
return this.formatting.alignment;
|
|
444
|
+
}
|
|
445
|
+
getKeepNext() {
|
|
446
|
+
return this.formatting.keepNext ?? false;
|
|
447
|
+
}
|
|
448
|
+
getKeepLines() {
|
|
449
|
+
return this.formatting.keepLines ?? false;
|
|
450
|
+
}
|
|
451
|
+
getPageBreakBefore() {
|
|
452
|
+
return this.formatting.pageBreakBefore ?? false;
|
|
453
|
+
}
|
|
454
|
+
getOutlineLevel() {
|
|
455
|
+
return this.formatting.outlineLevel;
|
|
456
|
+
}
|
|
457
|
+
getTextDirection() {
|
|
458
|
+
return this.formatting.textDirection;
|
|
459
|
+
}
|
|
460
|
+
getWidowControl() {
|
|
461
|
+
return this.formatting.widowControl ?? true;
|
|
462
|
+
}
|
|
463
|
+
getContextualSpacing() {
|
|
464
|
+
return this.formatting.contextualSpacing ?? false;
|
|
465
|
+
}
|
|
466
|
+
hasNumbering() {
|
|
467
|
+
return this.formatting.numbering?.numId !== undefined && this.formatting.numbering.numId !== 0;
|
|
468
|
+
}
|
|
469
|
+
isNumberingSuppressed() {
|
|
470
|
+
return this.formatting.numberingSuppressed === true;
|
|
471
|
+
}
|
|
472
|
+
hasFields() {
|
|
473
|
+
return this.getFields().length > 0;
|
|
474
|
+
}
|
|
475
|
+
hasBookmarks() {
|
|
476
|
+
return this.getBookmarksStart().length > 0;
|
|
477
|
+
}
|
|
478
|
+
hasComments() {
|
|
479
|
+
return this.getCommentsStart().length > 0;
|
|
480
|
+
}
|
|
481
|
+
hasRevisions() {
|
|
482
|
+
return this.getRevisions().length > 0;
|
|
483
|
+
}
|
|
484
|
+
consolidateRevisions(timeWindowMs = 1000) {
|
|
485
|
+
if (!this.hasRevisions()) {
|
|
486
|
+
return 0;
|
|
487
|
+
}
|
|
488
|
+
const consolidatedContent = [];
|
|
489
|
+
let mergeCount = 0;
|
|
490
|
+
let currentMergeGroup = null;
|
|
491
|
+
for (const item of this.content) {
|
|
492
|
+
if (item instanceof Revision) {
|
|
493
|
+
if (currentMergeGroup && this.canMergeRevisions(currentMergeGroup, item, timeWindowMs)) {
|
|
494
|
+
for (const content of item.getContent()) {
|
|
495
|
+
currentMergeGroup.addContent(content);
|
|
496
|
+
}
|
|
497
|
+
mergeCount++;
|
|
498
|
+
}
|
|
499
|
+
else {
|
|
500
|
+
if (currentMergeGroup) {
|
|
501
|
+
consolidatedContent.push(currentMergeGroup);
|
|
502
|
+
}
|
|
503
|
+
currentMergeGroup = this.cloneRevision(item);
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
else {
|
|
507
|
+
if (currentMergeGroup) {
|
|
508
|
+
consolidatedContent.push(currentMergeGroup);
|
|
509
|
+
currentMergeGroup = null;
|
|
510
|
+
}
|
|
511
|
+
consolidatedContent.push(item);
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
if (currentMergeGroup) {
|
|
515
|
+
consolidatedContent.push(currentMergeGroup);
|
|
516
|
+
}
|
|
517
|
+
if (mergeCount > 0) {
|
|
518
|
+
this.content = consolidatedContent;
|
|
519
|
+
}
|
|
520
|
+
return mergeCount;
|
|
521
|
+
}
|
|
522
|
+
canMergeRevisions(rev1, rev2, timeWindowMs) {
|
|
523
|
+
if (rev1.getType() !== rev2.getType()) {
|
|
524
|
+
return false;
|
|
525
|
+
}
|
|
526
|
+
const mergeableTypes = ['insert', 'delete', 'moveFrom', 'moveTo'];
|
|
527
|
+
if (!mergeableTypes.includes(rev1.getType())) {
|
|
528
|
+
return false;
|
|
529
|
+
}
|
|
530
|
+
if (rev1.getAuthor() !== rev2.getAuthor()) {
|
|
531
|
+
return false;
|
|
532
|
+
}
|
|
533
|
+
const timeDiff = Math.abs(rev1.getDate().getTime() - rev2.getDate().getTime());
|
|
534
|
+
if (timeDiff > timeWindowMs) {
|
|
535
|
+
return false;
|
|
536
|
+
}
|
|
537
|
+
return true;
|
|
538
|
+
}
|
|
539
|
+
cloneRevision(revision) {
|
|
540
|
+
const cloned = new Revision({
|
|
541
|
+
id: revision.getId(),
|
|
542
|
+
author: revision.getAuthor(),
|
|
543
|
+
date: revision.getDate(),
|
|
544
|
+
type: revision.getType(),
|
|
545
|
+
content: [...revision.getContent()],
|
|
546
|
+
previousProperties: revision.getPreviousProperties(),
|
|
547
|
+
newProperties: revision.getNewProperties(),
|
|
548
|
+
moveId: revision.getMoveId(),
|
|
549
|
+
moveLocation: revision.getMoveLocation(),
|
|
550
|
+
location: revision.getLocation(),
|
|
551
|
+
fieldContext: revision.getFieldContext(),
|
|
552
|
+
});
|
|
553
|
+
return cloned;
|
|
554
|
+
}
|
|
555
|
+
isEmpty() {
|
|
556
|
+
return this.getText().trim().length === 0;
|
|
557
|
+
}
|
|
558
|
+
contains(text, caseSensitive = false) {
|
|
559
|
+
const paraText = caseSensitive ? this.getText() : this.getText().toLowerCase();
|
|
560
|
+
const search = caseSensitive ? text : text.toLowerCase();
|
|
561
|
+
return paraText.includes(search);
|
|
562
|
+
}
|
|
563
|
+
getStyle() {
|
|
564
|
+
return this.formatting.style;
|
|
565
|
+
}
|
|
566
|
+
detectHeadingLevel() {
|
|
567
|
+
const style = this.formatting.style;
|
|
568
|
+
if (style) {
|
|
569
|
+
const match = /^Heading(\d)$/i.exec(style);
|
|
570
|
+
if (match?.[1]) {
|
|
571
|
+
const level = parseInt(match[1], 10);
|
|
572
|
+
return level >= 1 && level <= 9 ? level : null;
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
if (this.formatting.outlineLevel !== undefined) {
|
|
576
|
+
const level = this.formatting.outlineLevel + 1;
|
|
577
|
+
return level >= 1 && level <= 9 ? level : null;
|
|
578
|
+
}
|
|
579
|
+
const text = this.getText().trim();
|
|
580
|
+
if (!text)
|
|
581
|
+
return null;
|
|
582
|
+
const runs = this.getRuns();
|
|
583
|
+
if (runs.length === 0)
|
|
584
|
+
return null;
|
|
585
|
+
const firstRun = runs[0];
|
|
586
|
+
if (!firstRun)
|
|
587
|
+
return null;
|
|
588
|
+
const fmt = firstRun.getFormatting();
|
|
589
|
+
if (!fmt)
|
|
590
|
+
return null;
|
|
591
|
+
if (fmt.bold && fmt.size) {
|
|
592
|
+
if (fmt.size >= 24)
|
|
593
|
+
return 1;
|
|
594
|
+
if (fmt.size >= 20)
|
|
595
|
+
return 2;
|
|
596
|
+
if (fmt.size >= 16)
|
|
597
|
+
return 3;
|
|
598
|
+
if (fmt.size >= 14)
|
|
599
|
+
return 4;
|
|
600
|
+
}
|
|
601
|
+
if (fmt.bold && fmt.allCaps && text.length < 100) {
|
|
602
|
+
return 2;
|
|
603
|
+
}
|
|
604
|
+
return null;
|
|
605
|
+
}
|
|
606
|
+
setAlignment(alignment) {
|
|
607
|
+
const previousValue = this.formatting.alignment;
|
|
608
|
+
this.formatting.alignment = alignment;
|
|
609
|
+
if (this.trackingContext?.isEnabled() && previousValue !== alignment) {
|
|
610
|
+
this.trackingContext.trackParagraphPropertyChange(this, 'alignment', previousValue, alignment);
|
|
611
|
+
}
|
|
612
|
+
return this;
|
|
613
|
+
}
|
|
614
|
+
setLeftIndent(twips) {
|
|
615
|
+
if (this.formatting.numbering) {
|
|
616
|
+
defaultLogger.warn('Setting left indentation on a numbered paragraph has no effect. ' +
|
|
617
|
+
'Numbering controls indentation. Use different numbering levels to change indent.');
|
|
618
|
+
}
|
|
619
|
+
const previousValue = this.formatting.indentation?.left;
|
|
620
|
+
if (!this.formatting.indentation) {
|
|
621
|
+
this.formatting.indentation = {};
|
|
622
|
+
}
|
|
623
|
+
this.formatting.indentation.left = twips;
|
|
624
|
+
if (this.trackingContext?.isEnabled() && previousValue !== twips) {
|
|
625
|
+
this.trackingContext.trackParagraphPropertyChange(this, 'indentation.left', previousValue, twips);
|
|
626
|
+
}
|
|
627
|
+
return this;
|
|
628
|
+
}
|
|
629
|
+
setRightIndent(twips) {
|
|
630
|
+
const previousValue = this.formatting.indentation?.right;
|
|
631
|
+
if (!this.formatting.indentation) {
|
|
632
|
+
this.formatting.indentation = {};
|
|
633
|
+
}
|
|
634
|
+
this.formatting.indentation.right = twips;
|
|
635
|
+
if (this.trackingContext?.isEnabled() && previousValue !== twips) {
|
|
636
|
+
this.trackingContext.trackParagraphPropertyChange(this, 'indentation.right', previousValue, twips);
|
|
637
|
+
}
|
|
638
|
+
return this;
|
|
639
|
+
}
|
|
640
|
+
setFirstLineIndent(twips) {
|
|
641
|
+
if (this.formatting.numbering) {
|
|
642
|
+
defaultLogger.warn('Setting first line indentation on a numbered paragraph has no effect. ' +
|
|
643
|
+
'Numbering controls indentation using hanging indent.');
|
|
644
|
+
}
|
|
645
|
+
const previousValue = this.formatting.indentation?.firstLine;
|
|
646
|
+
if (!this.formatting.indentation) {
|
|
647
|
+
this.formatting.indentation = {};
|
|
648
|
+
}
|
|
649
|
+
this.formatting.indentation.firstLine = twips;
|
|
650
|
+
if (this.trackingContext?.isEnabled() && previousValue !== twips) {
|
|
651
|
+
this.trackingContext.trackParagraphPropertyChange(this, 'indentation.firstLine', previousValue, twips);
|
|
652
|
+
}
|
|
653
|
+
return this;
|
|
654
|
+
}
|
|
655
|
+
setHangingIndent(twips) {
|
|
656
|
+
if (twips < 0) {
|
|
657
|
+
throw new Error('Hanging indent must be non-negative');
|
|
658
|
+
}
|
|
659
|
+
if (this.formatting.numbering) {
|
|
660
|
+
defaultLogger.warn('Setting hanging indentation on a numbered paragraph has no effect. ' +
|
|
661
|
+
'Numbering controls indentation.');
|
|
662
|
+
}
|
|
663
|
+
const previousValue = this.formatting.indentation?.hanging;
|
|
664
|
+
if (!this.formatting.indentation) {
|
|
665
|
+
this.formatting.indentation = {};
|
|
666
|
+
}
|
|
667
|
+
this.formatting.indentation.hanging = twips;
|
|
668
|
+
if (this.trackingContext?.isEnabled() && previousValue !== twips) {
|
|
669
|
+
this.trackingContext.trackParagraphPropertyChange(this, 'indentation.hanging', previousValue, twips);
|
|
670
|
+
}
|
|
671
|
+
return this;
|
|
672
|
+
}
|
|
673
|
+
setSpaceBefore(twips) {
|
|
674
|
+
const previousValue = this.formatting.spacing?.before;
|
|
675
|
+
if (!this.formatting.spacing) {
|
|
676
|
+
this.formatting.spacing = {};
|
|
677
|
+
}
|
|
678
|
+
this.formatting.spacing.before = twips;
|
|
679
|
+
if (this.trackingContext?.isEnabled() && previousValue !== twips) {
|
|
680
|
+
this.trackingContext.trackParagraphPropertyChange(this, 'spacing.before', previousValue, twips);
|
|
681
|
+
}
|
|
682
|
+
return this;
|
|
683
|
+
}
|
|
684
|
+
setSpaceAfter(twips) {
|
|
685
|
+
const previousValue = this.formatting.spacing?.after;
|
|
686
|
+
if (!this.formatting.spacing) {
|
|
687
|
+
this.formatting.spacing = {};
|
|
688
|
+
}
|
|
689
|
+
this.formatting.spacing.after = twips;
|
|
690
|
+
if (this.trackingContext?.isEnabled() && previousValue !== twips) {
|
|
691
|
+
this.trackingContext.trackParagraphPropertyChange(this, 'spacing.after', previousValue, twips);
|
|
692
|
+
}
|
|
693
|
+
return this;
|
|
694
|
+
}
|
|
695
|
+
setLineSpacing(twips, rule = 'auto') {
|
|
696
|
+
const previousLine = this.formatting.spacing?.line;
|
|
697
|
+
const previousRule = this.formatting.spacing?.lineRule;
|
|
698
|
+
if (!this.formatting.spacing) {
|
|
699
|
+
this.formatting.spacing = {};
|
|
700
|
+
}
|
|
701
|
+
this.formatting.spacing.line = twips;
|
|
702
|
+
this.formatting.spacing.lineRule = rule;
|
|
703
|
+
if (this.trackingContext?.isEnabled()) {
|
|
704
|
+
if (previousLine !== twips) {
|
|
705
|
+
this.trackingContext.trackParagraphPropertyChange(this, 'spacing.line', previousLine, twips);
|
|
706
|
+
}
|
|
707
|
+
if (previousRule !== rule) {
|
|
708
|
+
this.trackingContext.trackParagraphPropertyChange(this, 'spacing.lineRule', previousRule, rule);
|
|
709
|
+
}
|
|
710
|
+
}
|
|
711
|
+
return this;
|
|
712
|
+
}
|
|
713
|
+
clearSpacing() {
|
|
714
|
+
delete this.formatting.spacing;
|
|
715
|
+
return this;
|
|
716
|
+
}
|
|
717
|
+
setStyle(styleId) {
|
|
718
|
+
const previousValue = this.formatting.style;
|
|
719
|
+
this.formatting.style = styleId;
|
|
720
|
+
if (this.trackingContext?.isEnabled() && previousValue !== styleId) {
|
|
721
|
+
this.trackingContext.trackParagraphPropertyChange(this, 'style', previousValue, styleId);
|
|
722
|
+
}
|
|
723
|
+
return this;
|
|
724
|
+
}
|
|
725
|
+
setKeepNext(keepNext = true) {
|
|
726
|
+
const previousValue = this.formatting.keepNext;
|
|
727
|
+
this.formatting.keepNext = keepNext;
|
|
728
|
+
if (keepNext) {
|
|
729
|
+
this.formatting.pageBreakBefore = undefined;
|
|
730
|
+
}
|
|
731
|
+
if (this.trackingContext?.isEnabled() && previousValue !== keepNext) {
|
|
732
|
+
this.trackingContext.trackParagraphPropertyChange(this, 'keepNext', previousValue, keepNext);
|
|
733
|
+
}
|
|
734
|
+
return this;
|
|
735
|
+
}
|
|
736
|
+
setKeepLines(keepLines = true) {
|
|
737
|
+
const previousValue = this.formatting.keepLines;
|
|
738
|
+
this.formatting.keepLines = keepLines;
|
|
739
|
+
if (keepLines) {
|
|
740
|
+
this.formatting.pageBreakBefore = undefined;
|
|
741
|
+
}
|
|
742
|
+
if (this.trackingContext?.isEnabled() && previousValue !== keepLines) {
|
|
743
|
+
this.trackingContext.trackParagraphPropertyChange(this, 'keepLines', previousValue, keepLines);
|
|
744
|
+
}
|
|
745
|
+
return this;
|
|
746
|
+
}
|
|
747
|
+
setPageBreakBefore(pageBreakBefore = true) {
|
|
748
|
+
const previousValue = this.formatting.pageBreakBefore;
|
|
749
|
+
this.formatting.pageBreakBefore = pageBreakBefore;
|
|
750
|
+
if (this.trackingContext?.isEnabled() && previousValue !== pageBreakBefore) {
|
|
751
|
+
this.trackingContext.trackParagraphPropertyChange(this, 'pageBreakBefore', previousValue, pageBreakBefore);
|
|
752
|
+
}
|
|
753
|
+
return this;
|
|
754
|
+
}
|
|
755
|
+
setPreserved(preserved = true) {
|
|
756
|
+
this._isPreserved = preserved;
|
|
757
|
+
return this;
|
|
758
|
+
}
|
|
759
|
+
isPreserved() {
|
|
760
|
+
return this._isPreserved;
|
|
761
|
+
}
|
|
762
|
+
setNumbering(numId, level = 0) {
|
|
763
|
+
if (numId < 0) {
|
|
764
|
+
throw new Error('Numbering ID must be non-negative');
|
|
765
|
+
}
|
|
766
|
+
if (level < 0 || level > 8) {
|
|
767
|
+
throw new Error('Level must be between 0 and 8');
|
|
768
|
+
}
|
|
769
|
+
const previousValue = this.formatting.numbering;
|
|
770
|
+
this.formatting.numbering = { numId, level };
|
|
771
|
+
delete this.formatting.numberingSuppressed;
|
|
772
|
+
if (this.formatting.indentation) {
|
|
773
|
+
const { right } = this.formatting.indentation;
|
|
774
|
+
this.formatting.indentation = right !== undefined ? { right } : undefined;
|
|
775
|
+
}
|
|
776
|
+
if (this.trackingContext?.isEnabled()) {
|
|
777
|
+
const newValue = { numId, level };
|
|
778
|
+
if (previousValue?.numId !== newValue.numId || previousValue?.level !== newValue.level) {
|
|
779
|
+
this.trackingContext.trackParagraphPropertyChange(this, 'numbering', previousValue, newValue);
|
|
780
|
+
}
|
|
781
|
+
}
|
|
782
|
+
return this;
|
|
783
|
+
}
|
|
784
|
+
setContextualSpacing(enable = true) {
|
|
785
|
+
const previousValue = this.formatting.contextualSpacing;
|
|
786
|
+
this.formatting.contextualSpacing = enable;
|
|
787
|
+
if (this.trackingContext?.isEnabled() && previousValue !== enable) {
|
|
788
|
+
this.trackingContext.trackParagraphPropertyChange(this, 'contextualSpacing', previousValue, enable);
|
|
789
|
+
}
|
|
790
|
+
return this;
|
|
791
|
+
}
|
|
792
|
+
removeNumbering() {
|
|
793
|
+
delete this.formatting.numbering;
|
|
794
|
+
delete this.formatting.numberingSuppressed;
|
|
795
|
+
return this;
|
|
796
|
+
}
|
|
797
|
+
getNumbering() {
|
|
798
|
+
return this.formatting.numbering ? { ...this.formatting.numbering } : undefined;
|
|
799
|
+
}
|
|
800
|
+
setWidowControl(enable = true) {
|
|
801
|
+
const previousValue = this.formatting.widowControl;
|
|
802
|
+
this.formatting.widowControl = enable;
|
|
803
|
+
if (this.trackingContext?.isEnabled() && previousValue !== enable) {
|
|
804
|
+
this.trackingContext.trackParagraphPropertyChange(this, 'widowControl', previousValue, enable);
|
|
805
|
+
}
|
|
806
|
+
return this;
|
|
807
|
+
}
|
|
808
|
+
setOutlineLevel(level) {
|
|
809
|
+
if (level < 0 || level > 9) {
|
|
810
|
+
throw new Error('Outline level must be between 0 and 9');
|
|
811
|
+
}
|
|
812
|
+
const previousValue = this.formatting.outlineLevel;
|
|
813
|
+
this.formatting.outlineLevel = level;
|
|
814
|
+
if (this.trackingContext?.isEnabled() && previousValue !== level) {
|
|
815
|
+
this.trackingContext.trackParagraphPropertyChange(this, 'outlineLevel', previousValue, level);
|
|
816
|
+
}
|
|
817
|
+
return this;
|
|
818
|
+
}
|
|
819
|
+
setSuppressLineNumbers(suppress = true) {
|
|
820
|
+
const previousValue = this.formatting.suppressLineNumbers;
|
|
821
|
+
this.formatting.suppressLineNumbers = suppress;
|
|
822
|
+
if (this.trackingContext?.isEnabled() && previousValue !== suppress) {
|
|
823
|
+
this.trackingContext.trackParagraphPropertyChange(this, 'suppressLineNumbers', previousValue, suppress);
|
|
824
|
+
}
|
|
825
|
+
return this;
|
|
826
|
+
}
|
|
827
|
+
setBidi(enable = true) {
|
|
828
|
+
const previousValue = this.formatting.bidi;
|
|
829
|
+
this.formatting.bidi = enable;
|
|
830
|
+
if (this.trackingContext?.isEnabled() && previousValue !== enable) {
|
|
831
|
+
this.trackingContext.trackParagraphPropertyChange(this, 'bidi', previousValue, enable);
|
|
832
|
+
}
|
|
833
|
+
return this;
|
|
834
|
+
}
|
|
835
|
+
setTextDirection(direction) {
|
|
836
|
+
const previousValue = this.formatting.textDirection;
|
|
837
|
+
this.formatting.textDirection = direction;
|
|
838
|
+
if (this.trackingContext?.isEnabled() && previousValue !== direction) {
|
|
839
|
+
this.trackingContext.trackParagraphPropertyChange(this, 'textDirection', previousValue, direction);
|
|
840
|
+
}
|
|
841
|
+
return this;
|
|
842
|
+
}
|
|
843
|
+
setTextAlignment(alignment) {
|
|
844
|
+
const previousValue = this.formatting.textAlignment;
|
|
845
|
+
this.formatting.textAlignment = alignment;
|
|
846
|
+
if (this.trackingContext?.isEnabled() && previousValue !== alignment) {
|
|
847
|
+
this.trackingContext.trackParagraphPropertyChange(this, 'textAlignment', previousValue, alignment);
|
|
848
|
+
}
|
|
849
|
+
return this;
|
|
850
|
+
}
|
|
851
|
+
setMirrorIndents(enable = true) {
|
|
852
|
+
const previousValue = this.formatting.mirrorIndents;
|
|
853
|
+
this.formatting.mirrorIndents = enable;
|
|
854
|
+
if (this.trackingContext?.isEnabled() && previousValue !== enable) {
|
|
855
|
+
this.trackingContext.trackParagraphPropertyChange(this, 'mirrorIndents', previousValue, enable);
|
|
856
|
+
}
|
|
857
|
+
return this;
|
|
858
|
+
}
|
|
859
|
+
setAdjustRightInd(enable = true) {
|
|
860
|
+
const previousValue = this.formatting.adjustRightInd;
|
|
861
|
+
this.formatting.adjustRightInd = enable;
|
|
862
|
+
if (this.trackingContext?.isEnabled() && previousValue !== enable) {
|
|
863
|
+
this.trackingContext.trackParagraphPropertyChange(this, 'adjustRightInd', previousValue, enable);
|
|
864
|
+
}
|
|
865
|
+
return this;
|
|
866
|
+
}
|
|
867
|
+
setFrameProperties(props) {
|
|
868
|
+
const previousValue = this.formatting.framePr;
|
|
869
|
+
this.formatting.framePr = props;
|
|
870
|
+
if (this.trackingContext?.isEnabled() && previousValue !== props) {
|
|
871
|
+
this.trackingContext.trackParagraphPropertyChange(this, 'framePr', previousValue, props);
|
|
872
|
+
}
|
|
873
|
+
return this;
|
|
874
|
+
}
|
|
875
|
+
setSuppressAutoHyphens(suppress = true) {
|
|
876
|
+
const previousValue = this.formatting.suppressAutoHyphens;
|
|
877
|
+
this.formatting.suppressAutoHyphens = suppress;
|
|
878
|
+
if (this.trackingContext?.isEnabled() && previousValue !== suppress) {
|
|
879
|
+
this.trackingContext.trackParagraphPropertyChange(this, 'suppressAutoHyphens', previousValue, suppress);
|
|
880
|
+
}
|
|
881
|
+
return this;
|
|
882
|
+
}
|
|
883
|
+
setKinsoku(enable = true) {
|
|
884
|
+
this.formatting.kinsoku = enable;
|
|
885
|
+
return this;
|
|
886
|
+
}
|
|
887
|
+
setWordWrap(enable = true) {
|
|
888
|
+
this.formatting.wordWrap = enable;
|
|
889
|
+
return this;
|
|
890
|
+
}
|
|
891
|
+
setOverflowPunct(enable = true) {
|
|
892
|
+
this.formatting.overflowPunct = enable;
|
|
893
|
+
return this;
|
|
894
|
+
}
|
|
895
|
+
setTopLinePunct(enable = true) {
|
|
896
|
+
this.formatting.topLinePunct = enable;
|
|
897
|
+
return this;
|
|
898
|
+
}
|
|
899
|
+
setAutoSpaceDE(enable = true) {
|
|
900
|
+
this.formatting.autoSpaceDE = enable;
|
|
901
|
+
return this;
|
|
902
|
+
}
|
|
903
|
+
setAutoSpaceDN(enable = true) {
|
|
904
|
+
this.formatting.autoSpaceDN = enable;
|
|
905
|
+
return this;
|
|
906
|
+
}
|
|
907
|
+
setSuppressOverlap(suppress = true) {
|
|
908
|
+
const previousValue = this.formatting.suppressOverlap;
|
|
909
|
+
this.formatting.suppressOverlap = suppress;
|
|
910
|
+
if (this.trackingContext?.isEnabled() && previousValue !== suppress) {
|
|
911
|
+
this.trackingContext.trackParagraphPropertyChange(this, 'suppressOverlap', previousValue, suppress);
|
|
912
|
+
}
|
|
913
|
+
return this;
|
|
914
|
+
}
|
|
915
|
+
setTextboxTightWrap(wrap) {
|
|
916
|
+
const previousValue = this.formatting.textboxTightWrap;
|
|
917
|
+
this.formatting.textboxTightWrap = wrap;
|
|
918
|
+
if (this.trackingContext?.isEnabled() && previousValue !== wrap) {
|
|
919
|
+
this.trackingContext.trackParagraphPropertyChange(this, 'textboxTightWrap', previousValue, wrap);
|
|
920
|
+
}
|
|
921
|
+
return this;
|
|
922
|
+
}
|
|
923
|
+
setDivId(id) {
|
|
924
|
+
const previousValue = this.formatting.divId;
|
|
925
|
+
this.formatting.divId = id;
|
|
926
|
+
if (this.trackingContext?.isEnabled() && previousValue !== id) {
|
|
927
|
+
this.trackingContext.trackParagraphPropertyChange(this, 'divId', previousValue, id);
|
|
928
|
+
}
|
|
929
|
+
return this;
|
|
930
|
+
}
|
|
931
|
+
setConditionalFormatting(bitmask) {
|
|
932
|
+
const previousValue = this.formatting.cnfStyle;
|
|
933
|
+
this.formatting.cnfStyle = bitmask;
|
|
934
|
+
if (this.trackingContext?.isEnabled() && previousValue !== bitmask) {
|
|
935
|
+
this.trackingContext.trackParagraphPropertyChange(this, 'cnfStyle', previousValue, bitmask);
|
|
936
|
+
}
|
|
937
|
+
return this;
|
|
938
|
+
}
|
|
939
|
+
setSectionProperties(properties) {
|
|
940
|
+
const previousValue = this.formatting.sectPr;
|
|
941
|
+
this.formatting.sectPr = properties;
|
|
942
|
+
if (this.trackingContext?.isEnabled() && previousValue !== properties) {
|
|
943
|
+
this.trackingContext.trackParagraphPropertyChange(this, 'sectPr', previousValue, properties);
|
|
944
|
+
}
|
|
945
|
+
return this;
|
|
946
|
+
}
|
|
947
|
+
setParagraphPropertiesChange(change) {
|
|
948
|
+
const previousValue = this.formatting.pPrChange;
|
|
949
|
+
this.formatting.pPrChange = change;
|
|
950
|
+
if (this.trackingContext?.isEnabled() && previousValue !== change) {
|
|
951
|
+
this.trackingContext.trackParagraphPropertyChange(this, 'pPrChange', previousValue, change);
|
|
952
|
+
}
|
|
953
|
+
return this;
|
|
954
|
+
}
|
|
955
|
+
clearParagraphPropertiesChange() {
|
|
956
|
+
delete this.formatting.pPrChange;
|
|
957
|
+
return this;
|
|
958
|
+
}
|
|
959
|
+
setParagraphMarkFormatting(properties) {
|
|
960
|
+
const previousValue = this.formatting.paragraphMarkRunProperties;
|
|
961
|
+
this.formatting.paragraphMarkRunProperties = properties;
|
|
962
|
+
if (this.trackingContext?.isEnabled() && previousValue !== properties) {
|
|
963
|
+
this.trackingContext.trackParagraphPropertyChange(this, 'paragraphMarkRunProperties', previousValue, properties);
|
|
964
|
+
}
|
|
965
|
+
return this;
|
|
966
|
+
}
|
|
967
|
+
markParagraphMarkAsDeleted(id, author, date) {
|
|
968
|
+
this.formatting.paragraphMarkDeletion = {
|
|
969
|
+
id,
|
|
970
|
+
author,
|
|
971
|
+
date: date || new Date(),
|
|
972
|
+
};
|
|
973
|
+
return this;
|
|
974
|
+
}
|
|
975
|
+
clearParagraphMarkDeletion() {
|
|
976
|
+
delete this.formatting.paragraphMarkDeletion;
|
|
977
|
+
return this;
|
|
978
|
+
}
|
|
979
|
+
isParagraphMarkDeleted() {
|
|
980
|
+
return !!this.formatting.paragraphMarkDeletion;
|
|
981
|
+
}
|
|
982
|
+
markParagraphMarkAsInserted(id, author, date) {
|
|
983
|
+
this.formatting.paragraphMarkInsertion = {
|
|
984
|
+
id,
|
|
985
|
+
author,
|
|
986
|
+
date: date || new Date(),
|
|
987
|
+
};
|
|
988
|
+
return this;
|
|
989
|
+
}
|
|
990
|
+
clearParagraphMarkInsertion() {
|
|
991
|
+
delete this.formatting.paragraphMarkInsertion;
|
|
992
|
+
return this;
|
|
993
|
+
}
|
|
994
|
+
isParagraphMarkInserted() {
|
|
995
|
+
return !!this.formatting.paragraphMarkInsertion;
|
|
996
|
+
}
|
|
997
|
+
toXML() {
|
|
998
|
+
const runData = this.getRuns().map((run) => ({
|
|
999
|
+
text: run.getText(),
|
|
1000
|
+
rtl: run.isRTL(),
|
|
1001
|
+
}));
|
|
1002
|
+
logParagraphContent('serialization', -1, runData, this.formatting.bidi);
|
|
1003
|
+
if (this.formatting.bidi) {
|
|
1004
|
+
logTextDirection(`Serializing paragraph with BiDi enabled`);
|
|
1005
|
+
}
|
|
1006
|
+
const pPrChildren = [];
|
|
1007
|
+
if (this.formatting.style) {
|
|
1008
|
+
pPrChildren.push(XMLBuilder.wSelf('pStyle', { 'w:val': this.formatting.style }));
|
|
1009
|
+
}
|
|
1010
|
+
if (this.formatting.keepNext !== undefined) {
|
|
1011
|
+
pPrChildren.push(XMLBuilder.wSelf('keepNext', { 'w:val': this.formatting.keepNext ? '1' : '0' }));
|
|
1012
|
+
}
|
|
1013
|
+
if (this.formatting.keepLines !== undefined) {
|
|
1014
|
+
pPrChildren.push(XMLBuilder.wSelf('keepLines', { 'w:val': this.formatting.keepLines ? '1' : '0' }));
|
|
1015
|
+
}
|
|
1016
|
+
if (this.formatting.pageBreakBefore !== undefined) {
|
|
1017
|
+
pPrChildren.push(XMLBuilder.wSelf('pageBreakBefore', {
|
|
1018
|
+
'w:val': this.formatting.pageBreakBefore ? '1' : '0',
|
|
1019
|
+
}));
|
|
1020
|
+
}
|
|
1021
|
+
if (this.formatting.framePr) {
|
|
1022
|
+
const attrs = {};
|
|
1023
|
+
const f = this.formatting.framePr;
|
|
1024
|
+
if (f.w !== undefined)
|
|
1025
|
+
attrs['w:w'] = f.w.toString();
|
|
1026
|
+
if (f.h !== undefined)
|
|
1027
|
+
attrs['w:h'] = f.h.toString();
|
|
1028
|
+
if (f.hRule)
|
|
1029
|
+
attrs['w:hRule'] = f.hRule;
|
|
1030
|
+
if (f.x !== undefined)
|
|
1031
|
+
attrs['w:x'] = f.x.toString();
|
|
1032
|
+
if (f.y !== undefined)
|
|
1033
|
+
attrs['w:y'] = f.y.toString();
|
|
1034
|
+
if (f.xAlign)
|
|
1035
|
+
attrs['w:xAlign'] = f.xAlign;
|
|
1036
|
+
if (f.yAlign)
|
|
1037
|
+
attrs['w:yAlign'] = f.yAlign;
|
|
1038
|
+
if (f.hAnchor)
|
|
1039
|
+
attrs['w:hAnchor'] = f.hAnchor;
|
|
1040
|
+
if (f.vAnchor)
|
|
1041
|
+
attrs['w:vAnchor'] = f.vAnchor;
|
|
1042
|
+
if (f.hSpace !== undefined)
|
|
1043
|
+
attrs['w:hSpace'] = f.hSpace.toString();
|
|
1044
|
+
if (f.vSpace !== undefined)
|
|
1045
|
+
attrs['w:vSpace'] = f.vSpace.toString();
|
|
1046
|
+
if (f.wrap)
|
|
1047
|
+
attrs['w:wrap'] = f.wrap;
|
|
1048
|
+
if (f.dropCap)
|
|
1049
|
+
attrs['w:dropCap'] = f.dropCap;
|
|
1050
|
+
if (f.lines !== undefined)
|
|
1051
|
+
attrs['w:lines'] = f.lines.toString();
|
|
1052
|
+
if (f.anchorLock !== undefined)
|
|
1053
|
+
attrs['w:anchorLock'] = f.anchorLock ? '1' : '0';
|
|
1054
|
+
if (Object.keys(attrs).length > 0) {
|
|
1055
|
+
pPrChildren.push(XMLBuilder.wSelf('framePr', attrs));
|
|
1056
|
+
}
|
|
1057
|
+
}
|
|
1058
|
+
if (this.formatting.widowControl !== undefined) {
|
|
1059
|
+
pPrChildren.push(XMLBuilder.wSelf('widowControl', {
|
|
1060
|
+
'w:val': this.formatting.widowControl ? '1' : '0',
|
|
1061
|
+
}));
|
|
1062
|
+
}
|
|
1063
|
+
if (this.formatting.numbering) {
|
|
1064
|
+
const numPr = XMLBuilder.w('numPr', undefined, [
|
|
1065
|
+
XMLBuilder.wSelf('ilvl', {
|
|
1066
|
+
'w:val': this.formatting.numbering.level.toString(),
|
|
1067
|
+
}),
|
|
1068
|
+
XMLBuilder.wSelf('numId', {
|
|
1069
|
+
'w:val': this.formatting.numbering.numId.toString(),
|
|
1070
|
+
}),
|
|
1071
|
+
]);
|
|
1072
|
+
pPrChildren.push(numPr);
|
|
1073
|
+
}
|
|
1074
|
+
else if (this.formatting.numberingSuppressed) {
|
|
1075
|
+
const numPr = XMLBuilder.w('numPr', undefined, [
|
|
1076
|
+
XMLBuilder.wSelf('ilvl', { 'w:val': '0' }),
|
|
1077
|
+
XMLBuilder.wSelf('numId', { 'w:val': '0' }),
|
|
1078
|
+
]);
|
|
1079
|
+
pPrChildren.push(numPr);
|
|
1080
|
+
}
|
|
1081
|
+
if (this.formatting.suppressLineNumbers !== undefined) {
|
|
1082
|
+
pPrChildren.push(XMLBuilder.wSelf('suppressLineNumbers', {
|
|
1083
|
+
'w:val': this.formatting.suppressLineNumbers ? '1' : '0',
|
|
1084
|
+
}));
|
|
1085
|
+
}
|
|
1086
|
+
if (this.formatting.borders) {
|
|
1087
|
+
const borderChildren = [];
|
|
1088
|
+
const borders = this.formatting.borders;
|
|
1089
|
+
const createBorder = (borderType, border) => {
|
|
1090
|
+
if (!border)
|
|
1091
|
+
return null;
|
|
1092
|
+
const attributes = {
|
|
1093
|
+
'w:val': border.style ?? 'nil',
|
|
1094
|
+
};
|
|
1095
|
+
if (border.size !== undefined)
|
|
1096
|
+
attributes['w:sz'] = border.size;
|
|
1097
|
+
if (border.color)
|
|
1098
|
+
attributes['w:color'] = border.color;
|
|
1099
|
+
if (border.space !== undefined)
|
|
1100
|
+
attributes['w:space'] = border.space;
|
|
1101
|
+
if (border.themeColor)
|
|
1102
|
+
attributes['w:themeColor'] = border.themeColor;
|
|
1103
|
+
if (border.themeTint)
|
|
1104
|
+
attributes['w:themeTint'] = border.themeTint;
|
|
1105
|
+
if (border.themeShade)
|
|
1106
|
+
attributes['w:themeShade'] = border.themeShade;
|
|
1107
|
+
if (border.shadow !== undefined)
|
|
1108
|
+
attributes['w:shadow'] = border.shadow ? '1' : '0';
|
|
1109
|
+
if (border.frame !== undefined)
|
|
1110
|
+
attributes['w:frame'] = border.frame ? '1' : '0';
|
|
1111
|
+
return XMLBuilder.wSelf(borderType, attributes);
|
|
1112
|
+
};
|
|
1113
|
+
const topBorder = createBorder('top', borders.top);
|
|
1114
|
+
if (topBorder)
|
|
1115
|
+
borderChildren.push(topBorder);
|
|
1116
|
+
const leftBorder = createBorder('left', borders.left);
|
|
1117
|
+
if (leftBorder)
|
|
1118
|
+
borderChildren.push(leftBorder);
|
|
1119
|
+
const bottomBorder = createBorder('bottom', borders.bottom);
|
|
1120
|
+
if (bottomBorder)
|
|
1121
|
+
borderChildren.push(bottomBorder);
|
|
1122
|
+
const rightBorder = createBorder('right', borders.right);
|
|
1123
|
+
if (rightBorder)
|
|
1124
|
+
borderChildren.push(rightBorder);
|
|
1125
|
+
const betweenBorder = createBorder('between', borders.between);
|
|
1126
|
+
if (betweenBorder)
|
|
1127
|
+
borderChildren.push(betweenBorder);
|
|
1128
|
+
const barBorder = createBorder('bar', borders.bar);
|
|
1129
|
+
if (barBorder)
|
|
1130
|
+
borderChildren.push(barBorder);
|
|
1131
|
+
if (borderChildren.length > 0) {
|
|
1132
|
+
pPrChildren.push(XMLBuilder.w('pBdr', undefined, borderChildren));
|
|
1133
|
+
}
|
|
1134
|
+
}
|
|
1135
|
+
if (this.formatting.shading) {
|
|
1136
|
+
const shdAttrs = buildShadingAttributes(this.formatting.shading);
|
|
1137
|
+
if (Object.keys(shdAttrs).length > 0) {
|
|
1138
|
+
pPrChildren.push(XMLBuilder.wSelf('shd', shdAttrs));
|
|
1139
|
+
}
|
|
1140
|
+
}
|
|
1141
|
+
if (this.formatting.tabs && this.formatting.tabs.length > 0) {
|
|
1142
|
+
const tabChildren = [];
|
|
1143
|
+
for (const tab of this.formatting.tabs) {
|
|
1144
|
+
const attributes = {
|
|
1145
|
+
'w:val': tab.val ?? 'left',
|
|
1146
|
+
'w:pos': tab.position,
|
|
1147
|
+
};
|
|
1148
|
+
if (tab.leader)
|
|
1149
|
+
attributes['w:leader'] = tab.leader;
|
|
1150
|
+
tabChildren.push(XMLBuilder.wSelf('tab', attributes));
|
|
1151
|
+
}
|
|
1152
|
+
if (tabChildren.length > 0) {
|
|
1153
|
+
pPrChildren.push(XMLBuilder.w('tabs', undefined, tabChildren));
|
|
1154
|
+
}
|
|
1155
|
+
}
|
|
1156
|
+
if (this.formatting.suppressAutoHyphens !== undefined) {
|
|
1157
|
+
pPrChildren.push(XMLBuilder.wSelf('suppressAutoHyphens', {
|
|
1158
|
+
'w:val': this.formatting.suppressAutoHyphens ? '1' : '0',
|
|
1159
|
+
}));
|
|
1160
|
+
}
|
|
1161
|
+
if (this.formatting.kinsoku !== undefined) {
|
|
1162
|
+
pPrChildren.push(XMLBuilder.wSelf('kinsoku', { 'w:val': this.formatting.kinsoku ? '1' : '0' }));
|
|
1163
|
+
}
|
|
1164
|
+
if (this.formatting.wordWrap !== undefined) {
|
|
1165
|
+
pPrChildren.push(XMLBuilder.wSelf('wordWrap', { 'w:val': this.formatting.wordWrap ? '1' : '0' }));
|
|
1166
|
+
}
|
|
1167
|
+
if (this.formatting.overflowPunct !== undefined) {
|
|
1168
|
+
pPrChildren.push(XMLBuilder.wSelf('overflowPunct', { 'w:val': this.formatting.overflowPunct ? '1' : '0' }));
|
|
1169
|
+
}
|
|
1170
|
+
if (this.formatting.topLinePunct !== undefined) {
|
|
1171
|
+
pPrChildren.push(XMLBuilder.wSelf('topLinePunct', { 'w:val': this.formatting.topLinePunct ? '1' : '0' }));
|
|
1172
|
+
}
|
|
1173
|
+
if (this.formatting.autoSpaceDE !== undefined) {
|
|
1174
|
+
pPrChildren.push(XMLBuilder.wSelf('autoSpaceDE', { 'w:val': this.formatting.autoSpaceDE ? '1' : '0' }));
|
|
1175
|
+
}
|
|
1176
|
+
if (this.formatting.autoSpaceDN !== undefined) {
|
|
1177
|
+
pPrChildren.push(XMLBuilder.wSelf('autoSpaceDN', { 'w:val': this.formatting.autoSpaceDN ? '1' : '0' }));
|
|
1178
|
+
}
|
|
1179
|
+
if (this.formatting.bidi !== undefined) {
|
|
1180
|
+
pPrChildren.push(XMLBuilder.wSelf('bidi', { 'w:val': this.formatting.bidi ? '1' : '0' }));
|
|
1181
|
+
}
|
|
1182
|
+
if (this.formatting.adjustRightInd !== undefined) {
|
|
1183
|
+
pPrChildren.push(XMLBuilder.wSelf('adjustRightInd', {
|
|
1184
|
+
'w:val': this.formatting.adjustRightInd ? '1' : '0',
|
|
1185
|
+
}));
|
|
1186
|
+
}
|
|
1187
|
+
if (this.formatting.spacing) {
|
|
1188
|
+
const spc = this.formatting.spacing;
|
|
1189
|
+
const attributes = {};
|
|
1190
|
+
if (spc.before !== undefined)
|
|
1191
|
+
attributes['w:before'] = spc.before;
|
|
1192
|
+
if (spc.beforeLines !== undefined)
|
|
1193
|
+
attributes['w:beforeLines'] = spc.beforeLines;
|
|
1194
|
+
if (spc.beforeAutospacing !== undefined)
|
|
1195
|
+
attributes['w:beforeAutospacing'] = spc.beforeAutospacing ? '1' : '0';
|
|
1196
|
+
if (spc.after !== undefined)
|
|
1197
|
+
attributes['w:after'] = spc.after;
|
|
1198
|
+
if (spc.afterLines !== undefined)
|
|
1199
|
+
attributes['w:afterLines'] = spc.afterLines;
|
|
1200
|
+
if (spc.afterAutospacing !== undefined)
|
|
1201
|
+
attributes['w:afterAutospacing'] = spc.afterAutospacing ? '1' : '0';
|
|
1202
|
+
if (spc.line !== undefined)
|
|
1203
|
+
attributes['w:line'] = spc.line;
|
|
1204
|
+
if (spc.lineRule)
|
|
1205
|
+
attributes['w:lineRule'] = spc.lineRule;
|
|
1206
|
+
if (Object.keys(attributes).length > 0) {
|
|
1207
|
+
pPrChildren.push(XMLBuilder.wSelf('spacing', attributes));
|
|
1208
|
+
}
|
|
1209
|
+
}
|
|
1210
|
+
if (this.formatting.indentation) {
|
|
1211
|
+
const ind = this.formatting.indentation;
|
|
1212
|
+
const attributes = {};
|
|
1213
|
+
if (ind.left !== undefined)
|
|
1214
|
+
attributes['w:left'] = ind.left;
|
|
1215
|
+
if (ind.right !== undefined)
|
|
1216
|
+
attributes['w:right'] = ind.right;
|
|
1217
|
+
if (ind.hanging !== undefined) {
|
|
1218
|
+
attributes['w:hanging'] = ind.hanging;
|
|
1219
|
+
}
|
|
1220
|
+
else if (ind.firstLine !== undefined) {
|
|
1221
|
+
attributes['w:firstLine'] = ind.firstLine;
|
|
1222
|
+
}
|
|
1223
|
+
if (ind.leftChars !== undefined)
|
|
1224
|
+
attributes['w:leftChars'] = ind.leftChars;
|
|
1225
|
+
if (ind.rightChars !== undefined)
|
|
1226
|
+
attributes['w:rightChars'] = ind.rightChars;
|
|
1227
|
+
if (ind.hangingChars !== undefined) {
|
|
1228
|
+
attributes['w:hangingChars'] = ind.hangingChars;
|
|
1229
|
+
}
|
|
1230
|
+
else if (ind.firstLineChars !== undefined) {
|
|
1231
|
+
attributes['w:firstLineChars'] = ind.firstLineChars;
|
|
1232
|
+
}
|
|
1233
|
+
if (Object.keys(attributes).length > 0) {
|
|
1234
|
+
pPrChildren.push(XMLBuilder.wSelf('ind', attributes));
|
|
1235
|
+
}
|
|
1236
|
+
}
|
|
1237
|
+
if (this.formatting.contextualSpacing !== undefined) {
|
|
1238
|
+
pPrChildren.push(XMLBuilder.wSelf('contextualSpacing', {
|
|
1239
|
+
'w:val': this.formatting.contextualSpacing ? '1' : '0',
|
|
1240
|
+
}));
|
|
1241
|
+
}
|
|
1242
|
+
if (this.formatting.mirrorIndents !== undefined) {
|
|
1243
|
+
pPrChildren.push(XMLBuilder.wSelf('mirrorIndents', { 'w:val': this.formatting.mirrorIndents ? '1' : '0' }));
|
|
1244
|
+
}
|
|
1245
|
+
if (this.formatting.suppressOverlap !== undefined) {
|
|
1246
|
+
pPrChildren.push(XMLBuilder.wSelf('suppressOverlap', {
|
|
1247
|
+
'w:val': this.formatting.suppressOverlap ? '1' : '0',
|
|
1248
|
+
}));
|
|
1249
|
+
}
|
|
1250
|
+
if (this.formatting.alignment) {
|
|
1251
|
+
const alignmentValue = this.formatting.alignment === 'justify' ? 'both' : this.formatting.alignment;
|
|
1252
|
+
pPrChildren.push(XMLBuilder.wSelf('jc', { 'w:val': alignmentValue }));
|
|
1253
|
+
}
|
|
1254
|
+
if (this.formatting.textDirection) {
|
|
1255
|
+
pPrChildren.push(XMLBuilder.wSelf('textDirection', {
|
|
1256
|
+
'w:val': this.formatting.textDirection,
|
|
1257
|
+
}));
|
|
1258
|
+
}
|
|
1259
|
+
if (this.formatting.textAlignment) {
|
|
1260
|
+
pPrChildren.push(XMLBuilder.wSelf('textAlignment', {
|
|
1261
|
+
'w:val': this.formatting.textAlignment,
|
|
1262
|
+
}));
|
|
1263
|
+
}
|
|
1264
|
+
if (this.formatting.textboxTightWrap) {
|
|
1265
|
+
pPrChildren.push(XMLBuilder.wSelf('textboxTightWrap', {
|
|
1266
|
+
'w:val': this.formatting.textboxTightWrap,
|
|
1267
|
+
}));
|
|
1268
|
+
}
|
|
1269
|
+
if (this.formatting.outlineLevel !== undefined) {
|
|
1270
|
+
pPrChildren.push(XMLBuilder.wSelf('outlineLvl', {
|
|
1271
|
+
'w:val': this.formatting.outlineLevel.toString(),
|
|
1272
|
+
}));
|
|
1273
|
+
}
|
|
1274
|
+
if (this.formatting.divId !== undefined) {
|
|
1275
|
+
pPrChildren.push(XMLBuilder.wSelf('divId', { 'w:val': this.formatting.divId.toString() }));
|
|
1276
|
+
}
|
|
1277
|
+
if (this.formatting.cnfStyle) {
|
|
1278
|
+
pPrChildren.push(XMLBuilder.wSelf('cnfStyle', { 'w:val': this.formatting.cnfStyle }));
|
|
1279
|
+
}
|
|
1280
|
+
if (this.formatting.paragraphMarkRunProperties ||
|
|
1281
|
+
this.formatting.paragraphMarkDeletion ||
|
|
1282
|
+
this.formatting.paragraphMarkInsertion ||
|
|
1283
|
+
this.formatting.paragraphMarkRunPropertiesChange) {
|
|
1284
|
+
const rPrChildren = [];
|
|
1285
|
+
if (this.formatting.paragraphMarkInsertion) {
|
|
1286
|
+
const ins = this.formatting.paragraphMarkInsertion;
|
|
1287
|
+
rPrChildren.push(XMLBuilder.wSelf('ins', {
|
|
1288
|
+
'w:id': ins.id.toString(),
|
|
1289
|
+
'w:author': ins.author,
|
|
1290
|
+
'w:date': formatDateForXml(ins.date),
|
|
1291
|
+
}));
|
|
1292
|
+
}
|
|
1293
|
+
if (this.formatting.paragraphMarkDeletion) {
|
|
1294
|
+
const del = this.formatting.paragraphMarkDeletion;
|
|
1295
|
+
rPrChildren.push(XMLBuilder.wSelf('del', {
|
|
1296
|
+
'w:id': del.id.toString(),
|
|
1297
|
+
'w:author': del.author,
|
|
1298
|
+
'w:date': formatDateForXml(del.date),
|
|
1299
|
+
}));
|
|
1300
|
+
}
|
|
1301
|
+
if (this.formatting.paragraphMarkRunProperties) {
|
|
1302
|
+
const rPr = Run.generateRunPropertiesXML(this.formatting.paragraphMarkRunProperties);
|
|
1303
|
+
if (rPr?.children) {
|
|
1304
|
+
for (const child of rPr.children) {
|
|
1305
|
+
if (typeof child !== 'string') {
|
|
1306
|
+
rPrChildren.push(child);
|
|
1307
|
+
}
|
|
1308
|
+
}
|
|
1309
|
+
}
|
|
1310
|
+
}
|
|
1311
|
+
const paraRPrChange = this.formatting.paragraphMarkRunPropertiesChange;
|
|
1312
|
+
if (paraRPrChange) {
|
|
1313
|
+
const prevRPr = Run.generateRunPropertiesXML(paraRPrChange.previousProperties);
|
|
1314
|
+
const prevRPrElement = prevRPr ?? {
|
|
1315
|
+
name: 'w:rPr',
|
|
1316
|
+
attributes: {},
|
|
1317
|
+
children: [],
|
|
1318
|
+
};
|
|
1319
|
+
rPrChildren.push({
|
|
1320
|
+
name: 'w:rPrChange',
|
|
1321
|
+
attributes: {
|
|
1322
|
+
'w:id': paraRPrChange.id.toString(),
|
|
1323
|
+
'w:author': paraRPrChange.author,
|
|
1324
|
+
'w:date': formatDateForXml(paraRPrChange.date),
|
|
1325
|
+
},
|
|
1326
|
+
children: [prevRPrElement],
|
|
1327
|
+
});
|
|
1328
|
+
}
|
|
1329
|
+
if (rPrChildren.length > 0) {
|
|
1330
|
+
pPrChildren.push(XMLBuilder.w('rPr', undefined, rPrChildren));
|
|
1331
|
+
}
|
|
1332
|
+
}
|
|
1333
|
+
if (this.formatting.sectPr) {
|
|
1334
|
+
if (typeof this.formatting.sectPr === 'string') {
|
|
1335
|
+
pPrChildren.push({
|
|
1336
|
+
name: '__rawXml',
|
|
1337
|
+
rawXml: this.formatting.sectPr,
|
|
1338
|
+
});
|
|
1339
|
+
}
|
|
1340
|
+
}
|
|
1341
|
+
if (this.formatting.pPrChange) {
|
|
1342
|
+
const change = this.formatting.pPrChange;
|
|
1343
|
+
const attrs = {};
|
|
1344
|
+
if (change.id)
|
|
1345
|
+
attrs['w:id'] = change.id;
|
|
1346
|
+
if (change.author)
|
|
1347
|
+
attrs['w:author'] = change.author;
|
|
1348
|
+
if (change.date)
|
|
1349
|
+
attrs['w:date'] = change.date;
|
|
1350
|
+
const prevPPrChildren = [];
|
|
1351
|
+
if (change.previousProperties) {
|
|
1352
|
+
const prev = change.previousProperties;
|
|
1353
|
+
if (prev.style) {
|
|
1354
|
+
prevPPrChildren.push(XMLBuilder.wSelf('pStyle', { 'w:val': prev.style }));
|
|
1355
|
+
}
|
|
1356
|
+
if (prev.keepNext !== undefined) {
|
|
1357
|
+
prevPPrChildren.push(XMLBuilder.wSelf('keepNext', prev.keepNext ? { 'w:val': '1' } : { 'w:val': '0' }));
|
|
1358
|
+
}
|
|
1359
|
+
if (prev.keepLines !== undefined) {
|
|
1360
|
+
prevPPrChildren.push(XMLBuilder.wSelf('keepLines', prev.keepLines ? { 'w:val': '1' } : { 'w:val': '0' }));
|
|
1361
|
+
}
|
|
1362
|
+
if (prev.pageBreakBefore !== undefined) {
|
|
1363
|
+
prevPPrChildren.push(XMLBuilder.wSelf('pageBreakBefore', prev.pageBreakBefore ? { 'w:val': '1' } : { 'w:val': '0' }));
|
|
1364
|
+
}
|
|
1365
|
+
if (prev.framePr) {
|
|
1366
|
+
const fAttrs = {};
|
|
1367
|
+
const f = prev.framePr;
|
|
1368
|
+
if (f.w !== undefined)
|
|
1369
|
+
fAttrs['w:w'] = f.w.toString();
|
|
1370
|
+
if (f.h !== undefined)
|
|
1371
|
+
fAttrs['w:h'] = f.h.toString();
|
|
1372
|
+
if (f.hRule)
|
|
1373
|
+
fAttrs['w:hRule'] = f.hRule;
|
|
1374
|
+
if (f.x !== undefined)
|
|
1375
|
+
fAttrs['w:x'] = f.x.toString();
|
|
1376
|
+
if (f.y !== undefined)
|
|
1377
|
+
fAttrs['w:y'] = f.y.toString();
|
|
1378
|
+
if (f.xAlign)
|
|
1379
|
+
fAttrs['w:xAlign'] = f.xAlign;
|
|
1380
|
+
if (f.yAlign)
|
|
1381
|
+
fAttrs['w:yAlign'] = f.yAlign;
|
|
1382
|
+
if (f.hAnchor)
|
|
1383
|
+
fAttrs['w:hAnchor'] = f.hAnchor;
|
|
1384
|
+
if (f.vAnchor)
|
|
1385
|
+
fAttrs['w:vAnchor'] = f.vAnchor;
|
|
1386
|
+
if (f.hSpace !== undefined)
|
|
1387
|
+
fAttrs['w:hSpace'] = f.hSpace.toString();
|
|
1388
|
+
if (f.vSpace !== undefined)
|
|
1389
|
+
fAttrs['w:vSpace'] = f.vSpace.toString();
|
|
1390
|
+
if (f.wrap)
|
|
1391
|
+
fAttrs['w:wrap'] = f.wrap;
|
|
1392
|
+
if (f.dropCap)
|
|
1393
|
+
fAttrs['w:dropCap'] = f.dropCap;
|
|
1394
|
+
if (f.lines !== undefined)
|
|
1395
|
+
fAttrs['w:lines'] = f.lines.toString();
|
|
1396
|
+
if (f.anchorLock !== undefined)
|
|
1397
|
+
fAttrs['w:anchorLock'] = f.anchorLock ? '1' : '0';
|
|
1398
|
+
if (Object.keys(fAttrs).length > 0) {
|
|
1399
|
+
prevPPrChildren.push(XMLBuilder.wSelf('framePr', fAttrs));
|
|
1400
|
+
}
|
|
1401
|
+
}
|
|
1402
|
+
if (prev.widowControl !== undefined) {
|
|
1403
|
+
prevPPrChildren.push(XMLBuilder.wSelf('widowControl', {
|
|
1404
|
+
'w:val': prev.widowControl ? '1' : '0',
|
|
1405
|
+
}));
|
|
1406
|
+
}
|
|
1407
|
+
if (prev.numbering) {
|
|
1408
|
+
const numPrChildren = [];
|
|
1409
|
+
if (prev.numbering.level !== undefined) {
|
|
1410
|
+
numPrChildren.push(XMLBuilder.wSelf('ilvl', { 'w:val': prev.numbering.level.toString() }));
|
|
1411
|
+
}
|
|
1412
|
+
if (prev.numbering.numId !== undefined) {
|
|
1413
|
+
numPrChildren.push(XMLBuilder.wSelf('numId', { 'w:val': prev.numbering.numId.toString() }));
|
|
1414
|
+
}
|
|
1415
|
+
if (numPrChildren.length > 0) {
|
|
1416
|
+
prevPPrChildren.push(XMLBuilder.w('numPr', undefined, numPrChildren));
|
|
1417
|
+
}
|
|
1418
|
+
}
|
|
1419
|
+
else if (prev.numberingSuppressed) {
|
|
1420
|
+
prevPPrChildren.push(XMLBuilder.w('numPr', undefined, [
|
|
1421
|
+
XMLBuilder.wSelf('ilvl', { 'w:val': '0' }),
|
|
1422
|
+
XMLBuilder.wSelf('numId', { 'w:val': '0' }),
|
|
1423
|
+
]));
|
|
1424
|
+
}
|
|
1425
|
+
if (prev.suppressLineNumbers !== undefined) {
|
|
1426
|
+
prevPPrChildren.push(XMLBuilder.wSelf('suppressLineNumbers', {
|
|
1427
|
+
'w:val': prev.suppressLineNumbers ? '1' : '0',
|
|
1428
|
+
}));
|
|
1429
|
+
}
|
|
1430
|
+
if (prev.borders) {
|
|
1431
|
+
const borderChildren = [];
|
|
1432
|
+
const borderSides = ['top', 'left', 'bottom', 'right', 'between', 'bar'];
|
|
1433
|
+
for (const side of borderSides) {
|
|
1434
|
+
const border = prev.borders[side];
|
|
1435
|
+
if (border) {
|
|
1436
|
+
const attrs = { 'w:val': border.style ?? 'nil' };
|
|
1437
|
+
if (border.size !== undefined)
|
|
1438
|
+
attrs['w:sz'] = border.size.toString();
|
|
1439
|
+
if (border.color)
|
|
1440
|
+
attrs['w:color'] = border.color;
|
|
1441
|
+
if (border.space !== undefined)
|
|
1442
|
+
attrs['w:space'] = border.space.toString();
|
|
1443
|
+
if (border.themeColor)
|
|
1444
|
+
attrs['w:themeColor'] = border.themeColor;
|
|
1445
|
+
if (border.themeTint)
|
|
1446
|
+
attrs['w:themeTint'] = border.themeTint;
|
|
1447
|
+
if (border.themeShade)
|
|
1448
|
+
attrs['w:themeShade'] = border.themeShade;
|
|
1449
|
+
if (border.shadow !== undefined)
|
|
1450
|
+
attrs['w:shadow'] = border.shadow ? '1' : '0';
|
|
1451
|
+
if (border.frame !== undefined)
|
|
1452
|
+
attrs['w:frame'] = border.frame ? '1' : '0';
|
|
1453
|
+
borderChildren.push(XMLBuilder.wSelf(side, attrs));
|
|
1454
|
+
}
|
|
1455
|
+
}
|
|
1456
|
+
if (borderChildren.length > 0) {
|
|
1457
|
+
prevPPrChildren.push(XMLBuilder.w('pBdr', undefined, borderChildren));
|
|
1458
|
+
}
|
|
1459
|
+
}
|
|
1460
|
+
if (prev.shading) {
|
|
1461
|
+
const shdAttrs = buildShadingAttributes(prev.shading);
|
|
1462
|
+
if (Object.keys(shdAttrs).length > 0) {
|
|
1463
|
+
prevPPrChildren.push(XMLBuilder.wSelf('shd', shdAttrs));
|
|
1464
|
+
}
|
|
1465
|
+
}
|
|
1466
|
+
if (prev.tabs && prev.tabs.length > 0) {
|
|
1467
|
+
const tabChildren = prev.tabs.map((tab) => {
|
|
1468
|
+
const tabAttrs = {
|
|
1469
|
+
'w:val': tab.val ?? 'left',
|
|
1470
|
+
'w:pos': tab.position.toString(),
|
|
1471
|
+
};
|
|
1472
|
+
if (tab.leader)
|
|
1473
|
+
tabAttrs['w:leader'] = tab.leader;
|
|
1474
|
+
return XMLBuilder.wSelf('tab', tabAttrs);
|
|
1475
|
+
});
|
|
1476
|
+
prevPPrChildren.push(XMLBuilder.w('tabs', undefined, tabChildren));
|
|
1477
|
+
}
|
|
1478
|
+
if (prev.suppressAutoHyphens !== undefined) {
|
|
1479
|
+
prevPPrChildren.push(XMLBuilder.wSelf('suppressAutoHyphens', {
|
|
1480
|
+
'w:val': prev.suppressAutoHyphens ? '1' : '0',
|
|
1481
|
+
}));
|
|
1482
|
+
}
|
|
1483
|
+
if (prev.kinsoku !== undefined) {
|
|
1484
|
+
prevPPrChildren.push(XMLBuilder.wSelf('kinsoku', { 'w:val': prev.kinsoku ? '1' : '0' }));
|
|
1485
|
+
}
|
|
1486
|
+
if (prev.wordWrap !== undefined) {
|
|
1487
|
+
prevPPrChildren.push(XMLBuilder.wSelf('wordWrap', { 'w:val': prev.wordWrap ? '1' : '0' }));
|
|
1488
|
+
}
|
|
1489
|
+
if (prev.overflowPunct !== undefined) {
|
|
1490
|
+
prevPPrChildren.push(XMLBuilder.wSelf('overflowPunct', { 'w:val': prev.overflowPunct ? '1' : '0' }));
|
|
1491
|
+
}
|
|
1492
|
+
if (prev.topLinePunct !== undefined) {
|
|
1493
|
+
prevPPrChildren.push(XMLBuilder.wSelf('topLinePunct', { 'w:val': prev.topLinePunct ? '1' : '0' }));
|
|
1494
|
+
}
|
|
1495
|
+
if (prev.autoSpaceDE !== undefined) {
|
|
1496
|
+
prevPPrChildren.push(XMLBuilder.wSelf('autoSpaceDE', { 'w:val': prev.autoSpaceDE ? '1' : '0' }));
|
|
1497
|
+
}
|
|
1498
|
+
if (prev.autoSpaceDN !== undefined) {
|
|
1499
|
+
prevPPrChildren.push(XMLBuilder.wSelf('autoSpaceDN', { 'w:val': prev.autoSpaceDN ? '1' : '0' }));
|
|
1500
|
+
}
|
|
1501
|
+
if (prev.bidi !== undefined) {
|
|
1502
|
+
prevPPrChildren.push(XMLBuilder.wSelf('bidi', { 'w:val': prev.bidi ? '1' : '0' }));
|
|
1503
|
+
}
|
|
1504
|
+
if (prev.adjustRightInd !== undefined) {
|
|
1505
|
+
prevPPrChildren.push(XMLBuilder.wSelf('adjustRightInd', {
|
|
1506
|
+
'w:val': prev.adjustRightInd ? '1' : '0',
|
|
1507
|
+
}));
|
|
1508
|
+
}
|
|
1509
|
+
if (prev.spacing) {
|
|
1510
|
+
const spacingAttrs = {};
|
|
1511
|
+
if (prev.spacing.before !== undefined)
|
|
1512
|
+
spacingAttrs['w:before'] = prev.spacing.before.toString();
|
|
1513
|
+
if (prev.spacing.beforeLines !== undefined)
|
|
1514
|
+
spacingAttrs['w:beforeLines'] = prev.spacing.beforeLines.toString();
|
|
1515
|
+
if (prev.spacing.beforeAutospacing !== undefined)
|
|
1516
|
+
spacingAttrs['w:beforeAutospacing'] = prev.spacing.beforeAutospacing ? '1' : '0';
|
|
1517
|
+
if (prev.spacing.after !== undefined)
|
|
1518
|
+
spacingAttrs['w:after'] = prev.spacing.after.toString();
|
|
1519
|
+
if (prev.spacing.afterLines !== undefined)
|
|
1520
|
+
spacingAttrs['w:afterLines'] = prev.spacing.afterLines.toString();
|
|
1521
|
+
if (prev.spacing.afterAutospacing !== undefined)
|
|
1522
|
+
spacingAttrs['w:afterAutospacing'] = prev.spacing.afterAutospacing ? '1' : '0';
|
|
1523
|
+
if (prev.spacing.line !== undefined)
|
|
1524
|
+
spacingAttrs['w:line'] = prev.spacing.line.toString();
|
|
1525
|
+
if (prev.spacing.lineRule)
|
|
1526
|
+
spacingAttrs['w:lineRule'] = prev.spacing.lineRule;
|
|
1527
|
+
if (Object.keys(spacingAttrs).length > 0) {
|
|
1528
|
+
prevPPrChildren.push(XMLBuilder.wSelf('spacing', spacingAttrs));
|
|
1529
|
+
}
|
|
1530
|
+
}
|
|
1531
|
+
if (prev.indentation) {
|
|
1532
|
+
const indAttrs = {};
|
|
1533
|
+
const indentation = prev.indentation;
|
|
1534
|
+
if (indentation.left !== undefined)
|
|
1535
|
+
indAttrs['w:left'] = indentation.left.toString();
|
|
1536
|
+
if (indentation.right !== undefined)
|
|
1537
|
+
indAttrs['w:right'] = indentation.right.toString();
|
|
1538
|
+
if (indentation.hanging !== undefined) {
|
|
1539
|
+
indAttrs['w:hanging'] = indentation.hanging.toString();
|
|
1540
|
+
}
|
|
1541
|
+
else if (indentation.firstLine !== undefined) {
|
|
1542
|
+
indAttrs['w:firstLine'] = indentation.firstLine.toString();
|
|
1543
|
+
}
|
|
1544
|
+
if (indentation.leftChars !== undefined)
|
|
1545
|
+
indAttrs['w:leftChars'] = indentation.leftChars.toString();
|
|
1546
|
+
if (indentation.rightChars !== undefined)
|
|
1547
|
+
indAttrs['w:rightChars'] = indentation.rightChars.toString();
|
|
1548
|
+
if (indentation.hangingChars !== undefined) {
|
|
1549
|
+
indAttrs['w:hangingChars'] = indentation.hangingChars.toString();
|
|
1550
|
+
}
|
|
1551
|
+
else if (indentation.firstLineChars !== undefined) {
|
|
1552
|
+
indAttrs['w:firstLineChars'] = indentation.firstLineChars.toString();
|
|
1553
|
+
}
|
|
1554
|
+
prevPPrChildren.push(XMLBuilder.wSelf('ind', indAttrs));
|
|
1555
|
+
}
|
|
1556
|
+
if (prev.contextualSpacing !== undefined) {
|
|
1557
|
+
prevPPrChildren.push(XMLBuilder.wSelf('contextualSpacing', {
|
|
1558
|
+
'w:val': prev.contextualSpacing ? '1' : '0',
|
|
1559
|
+
}));
|
|
1560
|
+
}
|
|
1561
|
+
if (prev.mirrorIndents !== undefined) {
|
|
1562
|
+
prevPPrChildren.push(XMLBuilder.wSelf('mirrorIndents', {
|
|
1563
|
+
'w:val': prev.mirrorIndents ? '1' : '0',
|
|
1564
|
+
}));
|
|
1565
|
+
}
|
|
1566
|
+
if (prev.suppressOverlap !== undefined) {
|
|
1567
|
+
prevPPrChildren.push(XMLBuilder.wSelf('suppressOverlap', {
|
|
1568
|
+
'w:val': prev.suppressOverlap ? '1' : '0',
|
|
1569
|
+
}));
|
|
1570
|
+
}
|
|
1571
|
+
if (prev.alignment) {
|
|
1572
|
+
const alignmentValue = prev.alignment === 'justify' ? 'both' : prev.alignment;
|
|
1573
|
+
prevPPrChildren.push(XMLBuilder.wSelf('jc', { 'w:val': alignmentValue }));
|
|
1574
|
+
}
|
|
1575
|
+
if (prev.textDirection) {
|
|
1576
|
+
prevPPrChildren.push(XMLBuilder.wSelf('textDirection', { 'w:val': prev.textDirection }));
|
|
1577
|
+
}
|
|
1578
|
+
if (prev.textAlignment) {
|
|
1579
|
+
prevPPrChildren.push(XMLBuilder.wSelf('textAlignment', { 'w:val': prev.textAlignment }));
|
|
1580
|
+
}
|
|
1581
|
+
if (prev.textboxTightWrap) {
|
|
1582
|
+
prevPPrChildren.push(XMLBuilder.wSelf('textboxTightWrap', { 'w:val': prev.textboxTightWrap }));
|
|
1583
|
+
}
|
|
1584
|
+
if (prev.outlineLevel !== undefined) {
|
|
1585
|
+
prevPPrChildren.push(XMLBuilder.wSelf('outlineLvl', { 'w:val': prev.outlineLevel.toString() }));
|
|
1586
|
+
}
|
|
1587
|
+
if (prev.divId !== undefined) {
|
|
1588
|
+
prevPPrChildren.push(XMLBuilder.wSelf('divId', { 'w:val': prev.divId.toString() }));
|
|
1589
|
+
}
|
|
1590
|
+
if (prev.cnfStyle) {
|
|
1591
|
+
prevPPrChildren.push(XMLBuilder.wSelf('cnfStyle', { 'w:val': prev.cnfStyle }));
|
|
1592
|
+
}
|
|
1593
|
+
}
|
|
1594
|
+
if (prevPPrChildren.length > 0) {
|
|
1595
|
+
const pPrChangeChildren = [
|
|
1596
|
+
{
|
|
1597
|
+
name: 'w:pPr',
|
|
1598
|
+
attributes: {},
|
|
1599
|
+
children: prevPPrChildren,
|
|
1600
|
+
},
|
|
1601
|
+
];
|
|
1602
|
+
pPrChildren.push({
|
|
1603
|
+
name: 'w:pPrChange',
|
|
1604
|
+
attributes: attrs,
|
|
1605
|
+
children: pPrChangeChildren,
|
|
1606
|
+
});
|
|
1607
|
+
}
|
|
1608
|
+
}
|
|
1609
|
+
const paragraphChildren = [];
|
|
1610
|
+
if (pPrChildren.length > 0) {
|
|
1611
|
+
paragraphChildren.push(XMLBuilder.w('pPr', undefined, pPrChildren));
|
|
1612
|
+
}
|
|
1613
|
+
for (const bookmark of this.bookmarksStart) {
|
|
1614
|
+
paragraphChildren.push(bookmark.toStartXML());
|
|
1615
|
+
}
|
|
1616
|
+
for (const comment of this.commentsStart) {
|
|
1617
|
+
paragraphChildren.push(comment.toRangeStartXML());
|
|
1618
|
+
}
|
|
1619
|
+
for (let i = 0; i < this.content.length; i++) {
|
|
1620
|
+
const item = this.content[i];
|
|
1621
|
+
if (item instanceof Field) {
|
|
1622
|
+
paragraphChildren.push(item.toXML());
|
|
1623
|
+
}
|
|
1624
|
+
else if (item instanceof ComplexField) {
|
|
1625
|
+
const fieldXml = item.toXML();
|
|
1626
|
+
if (Array.isArray(fieldXml)) {
|
|
1627
|
+
paragraphChildren.push(...fieldXml);
|
|
1628
|
+
}
|
|
1629
|
+
else {
|
|
1630
|
+
paragraphChildren.push(XMLBuilder.w('r', undefined, [fieldXml]));
|
|
1631
|
+
}
|
|
1632
|
+
}
|
|
1633
|
+
else if (item instanceof Hyperlink) {
|
|
1634
|
+
paragraphChildren.push(item.toXML());
|
|
1635
|
+
}
|
|
1636
|
+
else if (item instanceof Revision) {
|
|
1637
|
+
const revType = item.getType();
|
|
1638
|
+
if (revType === 'runPropertiesChange' ||
|
|
1639
|
+
revType === 'paragraphPropertiesChange' ||
|
|
1640
|
+
revType === 'tablePropertiesChange' ||
|
|
1641
|
+
revType === 'tableExceptionPropertiesChange' ||
|
|
1642
|
+
revType === 'tableRowPropertiesChange' ||
|
|
1643
|
+
revType === 'tableCellPropertiesChange' ||
|
|
1644
|
+
revType === 'sectionPropertiesChange' ||
|
|
1645
|
+
revType === 'numberingChange') {
|
|
1646
|
+
continue;
|
|
1647
|
+
}
|
|
1648
|
+
const revisionXml = item.toXML();
|
|
1649
|
+
if (revisionXml) {
|
|
1650
|
+
paragraphChildren.push(revisionXml);
|
|
1651
|
+
}
|
|
1652
|
+
}
|
|
1653
|
+
else if (item instanceof RangeMarker) {
|
|
1654
|
+
paragraphChildren.push(item.toXML());
|
|
1655
|
+
}
|
|
1656
|
+
else if (item instanceof Shape) {
|
|
1657
|
+
paragraphChildren.push(XMLBuilder.w('r', undefined, [item.toXML()]));
|
|
1658
|
+
}
|
|
1659
|
+
else if (item instanceof TextBox) {
|
|
1660
|
+
paragraphChildren.push(XMLBuilder.w('r', undefined, [item.toXML()]));
|
|
1661
|
+
}
|
|
1662
|
+
else if (item) {
|
|
1663
|
+
paragraphChildren.push(item.toXML());
|
|
1664
|
+
}
|
|
1665
|
+
}
|
|
1666
|
+
if (this.content.length === 0) {
|
|
1667
|
+
paragraphChildren.push(new Run('').toXML());
|
|
1668
|
+
}
|
|
1669
|
+
for (const comment of this.commentsEnd) {
|
|
1670
|
+
paragraphChildren.push(comment.toRangeEndXML());
|
|
1671
|
+
}
|
|
1672
|
+
for (const comment of this.commentsEnd) {
|
|
1673
|
+
paragraphChildren.push(comment.toReferenceXML());
|
|
1674
|
+
}
|
|
1675
|
+
for (const bookmark of this.bookmarksEnd) {
|
|
1676
|
+
paragraphChildren.push(bookmark.toEndXML());
|
|
1677
|
+
}
|
|
1678
|
+
const paragraphAttributes = {};
|
|
1679
|
+
if (this.formatting.paraId) {
|
|
1680
|
+
paragraphAttributes['w14:paraId'] = this.formatting.paraId;
|
|
1681
|
+
}
|
|
1682
|
+
if (this.formatting.textId) {
|
|
1683
|
+
paragraphAttributes['w14:textId'] = this.formatting.textId;
|
|
1684
|
+
}
|
|
1685
|
+
return XMLBuilder.w('p', Object.keys(paragraphAttributes).length > 0 ? paragraphAttributes : undefined, paragraphChildren);
|
|
1686
|
+
}
|
|
1687
|
+
getWordCount() {
|
|
1688
|
+
const text = this.getText().trim();
|
|
1689
|
+
if (!text)
|
|
1690
|
+
return 0;
|
|
1691
|
+
const words = text.split(/\s+/).filter((word) => word.length > 0);
|
|
1692
|
+
return words.length;
|
|
1693
|
+
}
|
|
1694
|
+
getLength(includeSpaces = true) {
|
|
1695
|
+
const text = this.getText();
|
|
1696
|
+
if (includeSpaces) {
|
|
1697
|
+
return text.length;
|
|
1698
|
+
}
|
|
1699
|
+
else {
|
|
1700
|
+
return text.replace(/\s/g, '').length;
|
|
1701
|
+
}
|
|
1702
|
+
}
|
|
1703
|
+
clone() {
|
|
1704
|
+
const clonedFormatting = deepClone(this.formatting);
|
|
1705
|
+
const clonedParagraph = new Paragraph(clonedFormatting);
|
|
1706
|
+
for (const item of this.content) {
|
|
1707
|
+
if (item instanceof Run) {
|
|
1708
|
+
const runFormatting = item.getFormatting();
|
|
1709
|
+
const clonedRun = new Run(item.getText(), deepClone(runFormatting));
|
|
1710
|
+
clonedParagraph.addRun(clonedRun);
|
|
1711
|
+
}
|
|
1712
|
+
else {
|
|
1713
|
+
clonedParagraph.content.push(item);
|
|
1714
|
+
}
|
|
1715
|
+
}
|
|
1716
|
+
clonedParagraph.bookmarksStart = [...this.bookmarksStart];
|
|
1717
|
+
clonedParagraph.bookmarksEnd = [...this.bookmarksEnd];
|
|
1718
|
+
clonedParagraph.commentsStart = [...this.commentsStart];
|
|
1719
|
+
clonedParagraph.commentsEnd = [...this.commentsEnd];
|
|
1720
|
+
return clonedParagraph;
|
|
1721
|
+
}
|
|
1722
|
+
toJSON() {
|
|
1723
|
+
const runs = this.getRuns().map((run) => ({
|
|
1724
|
+
text: run.getText(),
|
|
1725
|
+
formatting: run.getFormatting(),
|
|
1726
|
+
}));
|
|
1727
|
+
const result = {
|
|
1728
|
+
text: this.getText(),
|
|
1729
|
+
runs,
|
|
1730
|
+
};
|
|
1731
|
+
if (this.formatting.style)
|
|
1732
|
+
result.style = this.formatting.style;
|
|
1733
|
+
if (this.formatting.alignment)
|
|
1734
|
+
result.alignment = this.formatting.alignment;
|
|
1735
|
+
if (this.formatting.numbering)
|
|
1736
|
+
result.numbering = { ...this.formatting.numbering };
|
|
1737
|
+
if (this.formatting.indentation)
|
|
1738
|
+
result.indentation = { ...this.formatting.indentation };
|
|
1739
|
+
if (this.formatting.spacing) {
|
|
1740
|
+
result.spacing = {
|
|
1741
|
+
before: this.formatting.spacing.before,
|
|
1742
|
+
after: this.formatting.spacing.after,
|
|
1743
|
+
line: this.formatting.spacing.line,
|
|
1744
|
+
lineRule: this.formatting.spacing.lineRule,
|
|
1745
|
+
};
|
|
1746
|
+
}
|
|
1747
|
+
return result;
|
|
1748
|
+
}
|
|
1749
|
+
static fromJSON(data) {
|
|
1750
|
+
const para = new Paragraph();
|
|
1751
|
+
if (data.runs && data.runs.length > 0) {
|
|
1752
|
+
for (const runData of data.runs) {
|
|
1753
|
+
para.addText(runData.text, runData.formatting);
|
|
1754
|
+
}
|
|
1755
|
+
}
|
|
1756
|
+
else if (data.text) {
|
|
1757
|
+
para.addText(data.text);
|
|
1758
|
+
}
|
|
1759
|
+
if (data.style)
|
|
1760
|
+
para.setStyle(data.style);
|
|
1761
|
+
if (data.alignment)
|
|
1762
|
+
para.setAlignment(data.alignment);
|
|
1763
|
+
if (data.numbering)
|
|
1764
|
+
para.setNumbering(data.numbering.numId, data.numbering.level);
|
|
1765
|
+
if (data.indentation) {
|
|
1766
|
+
if (data.indentation.left !== undefined)
|
|
1767
|
+
para.setLeftIndent(data.indentation.left);
|
|
1768
|
+
if (data.indentation.right !== undefined)
|
|
1769
|
+
para.setRightIndent(data.indentation.right);
|
|
1770
|
+
if (data.indentation.firstLine !== undefined)
|
|
1771
|
+
para.setFirstLineIndent(data.indentation.firstLine);
|
|
1772
|
+
if (data.indentation.hanging !== undefined)
|
|
1773
|
+
para.setHangingIndent(data.indentation.hanging);
|
|
1774
|
+
}
|
|
1775
|
+
if (data.spacing) {
|
|
1776
|
+
if (data.spacing.before !== undefined)
|
|
1777
|
+
para.setSpaceBefore(data.spacing.before);
|
|
1778
|
+
if (data.spacing.after !== undefined)
|
|
1779
|
+
para.setSpaceAfter(data.spacing.after);
|
|
1780
|
+
if (data.spacing.line !== undefined) {
|
|
1781
|
+
para.setLineSpacing(data.spacing.line, data.spacing.lineRule ?? 'auto');
|
|
1782
|
+
}
|
|
1783
|
+
}
|
|
1784
|
+
return para;
|
|
1785
|
+
}
|
|
1786
|
+
splitAt(offset) {
|
|
1787
|
+
const tailPara = new Paragraph(deepClone(this.formatting));
|
|
1788
|
+
const totalLength = this.getText().length;
|
|
1789
|
+
if (offset >= totalLength) {
|
|
1790
|
+
return tailPara;
|
|
1791
|
+
}
|
|
1792
|
+
if (offset <= 0) {
|
|
1793
|
+
tailPara.content = this.content;
|
|
1794
|
+
this.content = [];
|
|
1795
|
+
return tailPara;
|
|
1796
|
+
}
|
|
1797
|
+
let charPos = 0;
|
|
1798
|
+
let splitContentIndex = -1;
|
|
1799
|
+
for (let i = 0; i < this.content.length; i++) {
|
|
1800
|
+
const item = this.content[i];
|
|
1801
|
+
if (item instanceof Run) {
|
|
1802
|
+
const runLen = item.getText().length;
|
|
1803
|
+
const runEnd = charPos + runLen;
|
|
1804
|
+
if (runEnd <= offset) {
|
|
1805
|
+
charPos = runEnd;
|
|
1806
|
+
continue;
|
|
1807
|
+
}
|
|
1808
|
+
if (charPos >= offset) {
|
|
1809
|
+
splitContentIndex = i;
|
|
1810
|
+
break;
|
|
1811
|
+
}
|
|
1812
|
+
const localOffset = offset - charPos;
|
|
1813
|
+
const tailRun = item.splitAt(localOffset);
|
|
1814
|
+
this.content.splice(i + 1, 0, tailRun);
|
|
1815
|
+
splitContentIndex = i + 1;
|
|
1816
|
+
break;
|
|
1817
|
+
}
|
|
1818
|
+
else {
|
|
1819
|
+
if (charPos >= offset) {
|
|
1820
|
+
splitContentIndex = i;
|
|
1821
|
+
break;
|
|
1822
|
+
}
|
|
1823
|
+
}
|
|
1824
|
+
}
|
|
1825
|
+
if (splitContentIndex === -1) {
|
|
1826
|
+
return tailPara;
|
|
1827
|
+
}
|
|
1828
|
+
tailPara.content = this.content.splice(splitContentIndex);
|
|
1829
|
+
return tailPara;
|
|
1830
|
+
}
|
|
1831
|
+
setBorder(borders) {
|
|
1832
|
+
if (!this.formatting) {
|
|
1833
|
+
this.formatting = {};
|
|
1834
|
+
}
|
|
1835
|
+
this.formatting.borders = borders;
|
|
1836
|
+
return this;
|
|
1837
|
+
}
|
|
1838
|
+
setShading(shading) {
|
|
1839
|
+
if (!this.formatting) {
|
|
1840
|
+
this.formatting = {};
|
|
1841
|
+
}
|
|
1842
|
+
const previousValue = this.formatting.shading;
|
|
1843
|
+
this.formatting.shading = shading;
|
|
1844
|
+
if (this.trackingContext?.isEnabled() && previousValue !== shading) {
|
|
1845
|
+
this.trackingContext.trackParagraphPropertyChange(this, 'shading', previousValue, shading);
|
|
1846
|
+
}
|
|
1847
|
+
return this;
|
|
1848
|
+
}
|
|
1849
|
+
setTabs(tabs) {
|
|
1850
|
+
if (!this.formatting) {
|
|
1851
|
+
this.formatting = {};
|
|
1852
|
+
}
|
|
1853
|
+
this.formatting.tabs = tabs;
|
|
1854
|
+
return this;
|
|
1855
|
+
}
|
|
1856
|
+
insertRunAt(index, run) {
|
|
1857
|
+
if (index < 0)
|
|
1858
|
+
index = 0;
|
|
1859
|
+
if (index > this.content.length)
|
|
1860
|
+
index = this.content.length;
|
|
1861
|
+
this.content.splice(index, 0, run);
|
|
1862
|
+
return this;
|
|
1863
|
+
}
|
|
1864
|
+
removeRunAt(index) {
|
|
1865
|
+
if (index >= 0 && index < this.content.length) {
|
|
1866
|
+
const item = this.content[index];
|
|
1867
|
+
if (item instanceof Run) {
|
|
1868
|
+
this.content.splice(index, 1);
|
|
1869
|
+
return true;
|
|
1870
|
+
}
|
|
1871
|
+
}
|
|
1872
|
+
return false;
|
|
1873
|
+
}
|
|
1874
|
+
replaceRunAt(index, run) {
|
|
1875
|
+
if (index >= 0 && index < this.content.length) {
|
|
1876
|
+
const item = this.content[index];
|
|
1877
|
+
if (item instanceof Run) {
|
|
1878
|
+
this.content[index] = run;
|
|
1879
|
+
return true;
|
|
1880
|
+
}
|
|
1881
|
+
}
|
|
1882
|
+
return false;
|
|
1883
|
+
}
|
|
1884
|
+
findText(text, options) {
|
|
1885
|
+
const indices = [];
|
|
1886
|
+
const caseSensitive = options?.caseSensitive || false;
|
|
1887
|
+
const wholeWord = options?.wholeWord || false;
|
|
1888
|
+
const searchText = caseSensitive ? text : text.toLowerCase();
|
|
1889
|
+
for (let i = 0; i < this.content.length; i++) {
|
|
1890
|
+
const item = this.content[i];
|
|
1891
|
+
if (item instanceof Run) {
|
|
1892
|
+
const runText = caseSensitive ? item.getText() : item.getText().toLowerCase();
|
|
1893
|
+
if (wholeWord) {
|
|
1894
|
+
const wordPattern = new RegExp(`\\b${searchText.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}\\b`);
|
|
1895
|
+
if (wordPattern.test(runText)) {
|
|
1896
|
+
indices.push(i);
|
|
1897
|
+
}
|
|
1898
|
+
}
|
|
1899
|
+
else {
|
|
1900
|
+
if (runText.includes(searchText)) {
|
|
1901
|
+
indices.push(i);
|
|
1902
|
+
}
|
|
1903
|
+
}
|
|
1904
|
+
}
|
|
1905
|
+
}
|
|
1906
|
+
return indices;
|
|
1907
|
+
}
|
|
1908
|
+
replaceText(find, replace, options) {
|
|
1909
|
+
let replacementCount = 0;
|
|
1910
|
+
const caseSensitive = options?.caseSensitive || false;
|
|
1911
|
+
const wholeWord = options?.wholeWord || false;
|
|
1912
|
+
for (const item of this.content) {
|
|
1913
|
+
if (item instanceof Run) {
|
|
1914
|
+
const originalText = item.getText();
|
|
1915
|
+
let newText = originalText;
|
|
1916
|
+
if (wholeWord) {
|
|
1917
|
+
const wordPattern = new RegExp(`\\b${find.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}\\b`, caseSensitive ? 'g' : 'gi');
|
|
1918
|
+
const matches = originalText.match(wordPattern);
|
|
1919
|
+
if (matches) {
|
|
1920
|
+
replacementCount += matches.length;
|
|
1921
|
+
newText = originalText.replace(wordPattern, replace);
|
|
1922
|
+
}
|
|
1923
|
+
}
|
|
1924
|
+
else {
|
|
1925
|
+
const searchPattern = new RegExp(find.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), caseSensitive ? 'g' : 'gi');
|
|
1926
|
+
const matches = originalText.match(searchPattern);
|
|
1927
|
+
if (matches) {
|
|
1928
|
+
replacementCount += matches.length;
|
|
1929
|
+
newText = originalText.replace(searchPattern, replace);
|
|
1930
|
+
}
|
|
1931
|
+
}
|
|
1932
|
+
if (newText !== originalText) {
|
|
1933
|
+
item.setText(newText);
|
|
1934
|
+
}
|
|
1935
|
+
}
|
|
1936
|
+
}
|
|
1937
|
+
return replacementCount;
|
|
1938
|
+
}
|
|
1939
|
+
replaceAll(find, replace) {
|
|
1940
|
+
return this.replaceTextCrossRun(find, replace);
|
|
1941
|
+
}
|
|
1942
|
+
findTextCrossRun(find, options) {
|
|
1943
|
+
const caseSensitive = options?.caseSensitive ?? false;
|
|
1944
|
+
let fullText = '';
|
|
1945
|
+
for (const item of this.content) {
|
|
1946
|
+
if (item instanceof Run) {
|
|
1947
|
+
fullText += item.getText();
|
|
1948
|
+
}
|
|
1949
|
+
}
|
|
1950
|
+
if (fullText.length === 0)
|
|
1951
|
+
return [];
|
|
1952
|
+
const escaped = find.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
1953
|
+
const regex = new RegExp(escaped, caseSensitive ? 'g' : 'gi');
|
|
1954
|
+
const results = [];
|
|
1955
|
+
let m;
|
|
1956
|
+
while ((m = regex.exec(fullText)) !== null) {
|
|
1957
|
+
results.push({ offset: m.index, text: m[0] });
|
|
1958
|
+
}
|
|
1959
|
+
return results;
|
|
1960
|
+
}
|
|
1961
|
+
replaceTextCrossRun(find, replace, options) {
|
|
1962
|
+
const caseSensitive = options?.caseSensitive ?? false;
|
|
1963
|
+
const runMap = [];
|
|
1964
|
+
let charPos = 0;
|
|
1965
|
+
for (let i = 0; i < this.content.length; i++) {
|
|
1966
|
+
const item = this.content[i];
|
|
1967
|
+
if (item instanceof Run) {
|
|
1968
|
+
const len = item.getText().length;
|
|
1969
|
+
if (len > 0) {
|
|
1970
|
+
runMap.push({ run: item, contentIndex: i, start: charPos, end: charPos + len });
|
|
1971
|
+
}
|
|
1972
|
+
charPos += len;
|
|
1973
|
+
}
|
|
1974
|
+
}
|
|
1975
|
+
if (runMap.length === 0)
|
|
1976
|
+
return 0;
|
|
1977
|
+
const fullText = runMap.map((r) => r.run.getText()).join('');
|
|
1978
|
+
const escaped = find.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
1979
|
+
const regex = new RegExp(escaped, caseSensitive ? 'g' : 'gi');
|
|
1980
|
+
const matches = [];
|
|
1981
|
+
let m;
|
|
1982
|
+
while ((m = regex.exec(fullText)) !== null) {
|
|
1983
|
+
matches.push({ start: m.index, end: m.index + m[0].length });
|
|
1984
|
+
}
|
|
1985
|
+
if (matches.length === 0)
|
|
1986
|
+
return 0;
|
|
1987
|
+
for (let mi = matches.length - 1; mi >= 0; mi--) {
|
|
1988
|
+
const match = matches[mi];
|
|
1989
|
+
const affectedRuns = runMap.filter((r) => r.end > match.start && r.start < match.end);
|
|
1990
|
+
if (affectedRuns.length === 0)
|
|
1991
|
+
continue;
|
|
1992
|
+
const firstAffected = affectedRuns[0];
|
|
1993
|
+
const lastAffected = affectedRuns[affectedRuns.length - 1];
|
|
1994
|
+
const keepBefore = match.start > firstAffected.start
|
|
1995
|
+
? firstAffected.run.getText().slice(0, match.start - firstAffected.start)
|
|
1996
|
+
: '';
|
|
1997
|
+
const keepAfter = match.end < lastAffected.end
|
|
1998
|
+
? lastAffected.run.getText().slice(match.end - lastAffected.start)
|
|
1999
|
+
: '';
|
|
2000
|
+
firstAffected.run.setText(keepBefore + replace + keepAfter);
|
|
2001
|
+
for (let r = affectedRuns.length - 1; r >= 1; r--) {
|
|
2002
|
+
const runEntry = affectedRuns[r];
|
|
2003
|
+
const idx = this.content.indexOf(runEntry.run);
|
|
2004
|
+
if (idx !== -1) {
|
|
2005
|
+
this.content.splice(idx, 1);
|
|
2006
|
+
}
|
|
2007
|
+
}
|
|
2008
|
+
}
|
|
2009
|
+
return matches.length;
|
|
2010
|
+
}
|
|
2011
|
+
deleteRange(start, end) {
|
|
2012
|
+
if (start >= end)
|
|
2013
|
+
return this;
|
|
2014
|
+
const runMap = [];
|
|
2015
|
+
let charPos = 0;
|
|
2016
|
+
for (let i = 0; i < this.content.length; i++) {
|
|
2017
|
+
const item = this.content[i];
|
|
2018
|
+
if (item instanceof Run) {
|
|
2019
|
+
const len = item.getText().length;
|
|
2020
|
+
if (len > 0) {
|
|
2021
|
+
runMap.push({ index: i, start: charPos, end: charPos + len });
|
|
2022
|
+
}
|
|
2023
|
+
charPos += len;
|
|
2024
|
+
}
|
|
2025
|
+
}
|
|
2026
|
+
for (let m = runMap.length - 1; m >= 0; m--) {
|
|
2027
|
+
const entry = runMap[m];
|
|
2028
|
+
const run = this.content[entry.index];
|
|
2029
|
+
if (entry.end <= start || entry.start >= end)
|
|
2030
|
+
continue;
|
|
2031
|
+
const runStart = entry.start;
|
|
2032
|
+
const runEnd = entry.end;
|
|
2033
|
+
const delStart = Math.max(0, start - runStart);
|
|
2034
|
+
const delEnd = Math.min(runEnd - runStart, end - runStart);
|
|
2035
|
+
const runLen = runEnd - runStart;
|
|
2036
|
+
if (delStart === 0 && delEnd === runLen) {
|
|
2037
|
+
this.content.splice(entry.index, 1);
|
|
2038
|
+
}
|
|
2039
|
+
else {
|
|
2040
|
+
const textBefore = run.getText().slice(0, delStart);
|
|
2041
|
+
const textAfter = run.getText().slice(delEnd);
|
|
2042
|
+
run.setText(textBefore + textAfter);
|
|
2043
|
+
}
|
|
2044
|
+
}
|
|
2045
|
+
return this;
|
|
2046
|
+
}
|
|
2047
|
+
truncate(maxLength, suffix = '...') {
|
|
2048
|
+
const text = this.getText();
|
|
2049
|
+
if (text.length <= maxLength)
|
|
2050
|
+
return this;
|
|
2051
|
+
const cutoff = Math.max(0, maxLength - suffix.length);
|
|
2052
|
+
this.deleteRange(cutoff, text.length);
|
|
2053
|
+
if (suffix) {
|
|
2054
|
+
this.addText(suffix);
|
|
2055
|
+
}
|
|
2056
|
+
return this;
|
|
2057
|
+
}
|
|
2058
|
+
wrap(prefix, suffix, formatting) {
|
|
2059
|
+
if (prefix) {
|
|
2060
|
+
const prefixRun = new Run(prefix, formatting);
|
|
2061
|
+
this.content.unshift(prefixRun);
|
|
2062
|
+
}
|
|
2063
|
+
if (suffix) {
|
|
2064
|
+
const suffixRun = new Run(suffix, formatting);
|
|
2065
|
+
this.content.push(suffixRun);
|
|
2066
|
+
}
|
|
2067
|
+
return this;
|
|
2068
|
+
}
|
|
2069
|
+
getRunAtOffset(offset) {
|
|
2070
|
+
if (offset < 0)
|
|
2071
|
+
return undefined;
|
|
2072
|
+
let charPos = 0;
|
|
2073
|
+
for (const item of this.content) {
|
|
2074
|
+
if (!(item instanceof Run))
|
|
2075
|
+
continue;
|
|
2076
|
+
const len = item.getText().length;
|
|
2077
|
+
if (charPos + len > offset) {
|
|
2078
|
+
return { run: item, localOffset: offset - charPos };
|
|
2079
|
+
}
|
|
2080
|
+
charPos += len;
|
|
2081
|
+
}
|
|
2082
|
+
return undefined;
|
|
2083
|
+
}
|
|
2084
|
+
getFormattingAtOffset(offset) {
|
|
2085
|
+
const result = this.getRunAtOffset(offset);
|
|
2086
|
+
return result ? result.run.getFormatting() : undefined;
|
|
2087
|
+
}
|
|
2088
|
+
applyFormattingToRange(start, end, formatting) {
|
|
2089
|
+
if (start >= end)
|
|
2090
|
+
return this;
|
|
2091
|
+
const contentMap = [];
|
|
2092
|
+
let charPos = 0;
|
|
2093
|
+
for (let i = 0; i < this.content.length; i++) {
|
|
2094
|
+
const item = this.content[i];
|
|
2095
|
+
let len = 0;
|
|
2096
|
+
if (item instanceof Run) {
|
|
2097
|
+
len = item.getText().length;
|
|
2098
|
+
}
|
|
2099
|
+
if (len > 0) {
|
|
2100
|
+
contentMap.push({ index: i, start: charPos, end: charPos + len });
|
|
2101
|
+
}
|
|
2102
|
+
charPos += len;
|
|
2103
|
+
}
|
|
2104
|
+
for (let m = contentMap.length - 1; m >= 0; m--) {
|
|
2105
|
+
const entry = contentMap[m];
|
|
2106
|
+
const run = this.content[entry.index];
|
|
2107
|
+
if (entry.end <= start || entry.start >= end)
|
|
2108
|
+
continue;
|
|
2109
|
+
const runStart = entry.start;
|
|
2110
|
+
const runEnd = entry.end;
|
|
2111
|
+
const splitStart = Math.max(0, start - runStart);
|
|
2112
|
+
const splitEnd = Math.min(runEnd - runStart, end - runStart);
|
|
2113
|
+
const runLen = runEnd - runStart;
|
|
2114
|
+
if (splitStart === 0 && splitEnd === runLen) {
|
|
2115
|
+
this.applyFormattingToRun(run, formatting);
|
|
2116
|
+
}
|
|
2117
|
+
else if (splitStart === 0) {
|
|
2118
|
+
const tail = run.splitAt(splitEnd);
|
|
2119
|
+
this.applyFormattingToRun(run, formatting);
|
|
2120
|
+
this.content.splice(entry.index + 1, 0, tail);
|
|
2121
|
+
}
|
|
2122
|
+
else if (splitEnd === runLen) {
|
|
2123
|
+
const tail = run.splitAt(splitStart);
|
|
2124
|
+
this.applyFormattingToRun(tail, formatting);
|
|
2125
|
+
this.content.splice(entry.index + 1, 0, tail);
|
|
2126
|
+
}
|
|
2127
|
+
else {
|
|
2128
|
+
const mid = run.splitAt(splitStart);
|
|
2129
|
+
const tail = mid.splitAt(splitEnd - splitStart);
|
|
2130
|
+
this.applyFormattingToRun(mid, formatting);
|
|
2131
|
+
this.content.splice(entry.index + 1, 0, mid, tail);
|
|
2132
|
+
}
|
|
2133
|
+
}
|
|
2134
|
+
return this;
|
|
2135
|
+
}
|
|
2136
|
+
applyFormattingToRun(run, formatting) {
|
|
2137
|
+
if (formatting.bold !== undefined)
|
|
2138
|
+
run.setBold(formatting.bold);
|
|
2139
|
+
if (formatting.italic !== undefined)
|
|
2140
|
+
run.setItalic(formatting.italic);
|
|
2141
|
+
if (formatting.underline !== undefined)
|
|
2142
|
+
run.setUnderline(formatting.underline);
|
|
2143
|
+
if (formatting.strike !== undefined)
|
|
2144
|
+
run.setStrike(formatting.strike);
|
|
2145
|
+
if (formatting.subscript !== undefined)
|
|
2146
|
+
run.setSubscript(formatting.subscript);
|
|
2147
|
+
if (formatting.superscript !== undefined)
|
|
2148
|
+
run.setSuperscript(formatting.superscript);
|
|
2149
|
+
if (formatting.smallCaps !== undefined)
|
|
2150
|
+
run.setSmallCaps(formatting.smallCaps);
|
|
2151
|
+
if (formatting.allCaps !== undefined)
|
|
2152
|
+
run.setAllCaps(formatting.allCaps);
|
|
2153
|
+
if (formatting.font !== undefined)
|
|
2154
|
+
run.setFont(formatting.font);
|
|
2155
|
+
if (formatting.size !== undefined)
|
|
2156
|
+
run.setSize(formatting.size);
|
|
2157
|
+
if (formatting.color !== undefined)
|
|
2158
|
+
run.setColor(formatting.color);
|
|
2159
|
+
if (formatting.highlight !== undefined)
|
|
2160
|
+
run.setHighlight(formatting.highlight);
|
|
2161
|
+
if (formatting.characterSpacing !== undefined)
|
|
2162
|
+
run.setCharacterSpacing(formatting.characterSpacing);
|
|
2163
|
+
if (formatting.vanish !== undefined)
|
|
2164
|
+
run.setVanish(formatting.vanish);
|
|
2165
|
+
}
|
|
2166
|
+
consolidateRuns() {
|
|
2167
|
+
if (this.content.length < 2)
|
|
2168
|
+
return 0;
|
|
2169
|
+
const consolidated = [];
|
|
2170
|
+
let eliminated = 0;
|
|
2171
|
+
for (const item of this.content) {
|
|
2172
|
+
if (!(item instanceof Run)) {
|
|
2173
|
+
consolidated.push(item);
|
|
2174
|
+
continue;
|
|
2175
|
+
}
|
|
2176
|
+
const prev = consolidated.length > 0 ? consolidated[consolidated.length - 1] : undefined;
|
|
2177
|
+
if (prev instanceof Run &&
|
|
2178
|
+
isEqualFormatting(prev.getFormatting(), item.getFormatting())) {
|
|
2179
|
+
const mergedContent = [...prev.getContent(), ...item.getContent()];
|
|
2180
|
+
const mergedRun = Run.createFromContent(mergedContent, deepClone(prev.getFormatting()));
|
|
2181
|
+
consolidated[consolidated.length - 1] = mergedRun;
|
|
2182
|
+
eliminated++;
|
|
2183
|
+
}
|
|
2184
|
+
else {
|
|
2185
|
+
consolidated.push(item);
|
|
2186
|
+
}
|
|
2187
|
+
}
|
|
2188
|
+
if (eliminated > 0) {
|
|
2189
|
+
this.content = consolidated;
|
|
2190
|
+
}
|
|
2191
|
+
return eliminated;
|
|
2192
|
+
}
|
|
2193
|
+
mergeWith(otherPara) {
|
|
2194
|
+
for (const item of otherPara.content) {
|
|
2195
|
+
if (item instanceof Run) {
|
|
2196
|
+
this.content.push(item.clone());
|
|
2197
|
+
}
|
|
2198
|
+
else {
|
|
2199
|
+
this.content.push(item);
|
|
2200
|
+
}
|
|
2201
|
+
}
|
|
2202
|
+
this.bookmarksStart.push(...otherPara.bookmarksStart);
|
|
2203
|
+
this.bookmarksEnd.push(...otherPara.bookmarksEnd);
|
|
2204
|
+
this.commentsStart.push(...otherPara.commentsStart);
|
|
2205
|
+
this.commentsEnd.push(...otherPara.commentsEnd);
|
|
2206
|
+
return this;
|
|
2207
|
+
}
|
|
2208
|
+
clearDirectRunFormatting(properties) {
|
|
2209
|
+
const runs = this.getRuns();
|
|
2210
|
+
for (const run of runs) {
|
|
2211
|
+
const formatting = run.getFormatting();
|
|
2212
|
+
if (properties && properties.length > 0) {
|
|
2213
|
+
const newFormatting = { ...formatting };
|
|
2214
|
+
for (const prop of properties) {
|
|
2215
|
+
if (prop in newFormatting) {
|
|
2216
|
+
delete newFormatting[prop];
|
|
2217
|
+
}
|
|
2218
|
+
}
|
|
2219
|
+
const text = run.getText();
|
|
2220
|
+
const newRun = new Run(text, newFormatting);
|
|
2221
|
+
const index = this.content.indexOf(run);
|
|
2222
|
+
if (index !== -1) {
|
|
2223
|
+
this.content[index] = newRun;
|
|
2224
|
+
}
|
|
2225
|
+
}
|
|
2226
|
+
else {
|
|
2227
|
+
const text = run.getText();
|
|
2228
|
+
const newRun = new Run(text, {});
|
|
2229
|
+
const index = this.content.indexOf(run);
|
|
2230
|
+
if (index !== -1) {
|
|
2231
|
+
this.content[index] = newRun;
|
|
2232
|
+
}
|
|
2233
|
+
}
|
|
2234
|
+
}
|
|
2235
|
+
return this;
|
|
2236
|
+
}
|
|
2237
|
+
applyStyleAndClearFormatting(styleId, clearProperties) {
|
|
2238
|
+
this.setStyle(styleId);
|
|
2239
|
+
if (clearProperties !== undefined) {
|
|
2240
|
+
this.clearDirectRunFormatting(clearProperties.length === 0 ? undefined : clearProperties);
|
|
2241
|
+
}
|
|
2242
|
+
return this;
|
|
2243
|
+
}
|
|
2244
|
+
clearDirectFormattingConflicts(styleDefinition) {
|
|
2245
|
+
const styleProperties = styleDefinition.getProperties();
|
|
2246
|
+
const styleParagraphFormatting = styleProperties.paragraphFormatting || {};
|
|
2247
|
+
const styleRunFormatting = styleProperties.runFormatting || {};
|
|
2248
|
+
const conflictingParaProps = [];
|
|
2249
|
+
for (const key in this.formatting) {
|
|
2250
|
+
const propKey = key;
|
|
2251
|
+
if (propKey === 'style') {
|
|
2252
|
+
continue;
|
|
2253
|
+
}
|
|
2254
|
+
if (styleParagraphFormatting[propKey] === undefined) {
|
|
2255
|
+
continue;
|
|
2256
|
+
}
|
|
2257
|
+
if (propKey === 'indentation') {
|
|
2258
|
+
const paraIndent = this.formatting.indentation;
|
|
2259
|
+
const styleIndent = styleParagraphFormatting.indentation;
|
|
2260
|
+
if (paraIndent?.left === 0 && styleIndent?.left && styleIndent.left > 0) {
|
|
2261
|
+
continue;
|
|
2262
|
+
}
|
|
2263
|
+
conflictingParaProps.push(propKey);
|
|
2264
|
+
continue;
|
|
2265
|
+
}
|
|
2266
|
+
if (propKey === 'spacing' ||
|
|
2267
|
+
propKey === 'borders' ||
|
|
2268
|
+
propKey === 'shading' ||
|
|
2269
|
+
propKey === 'numbering') {
|
|
2270
|
+
const paraValue = this.formatting[propKey];
|
|
2271
|
+
const styleValue = styleParagraphFormatting[propKey];
|
|
2272
|
+
if (!deepEqual(paraValue, styleValue)) {
|
|
2273
|
+
conflictingParaProps.push(propKey);
|
|
2274
|
+
}
|
|
2275
|
+
}
|
|
2276
|
+
else {
|
|
2277
|
+
if (this.formatting[propKey] !== styleParagraphFormatting[propKey]) {
|
|
2278
|
+
conflictingParaProps.push(propKey);
|
|
2279
|
+
}
|
|
2280
|
+
}
|
|
2281
|
+
}
|
|
2282
|
+
for (const prop of conflictingParaProps) {
|
|
2283
|
+
delete this.formatting[prop];
|
|
2284
|
+
}
|
|
2285
|
+
for (const item of this.content) {
|
|
2286
|
+
if (item instanceof Run) {
|
|
2287
|
+
item.clearFormattingConflicts(styleRunFormatting);
|
|
2288
|
+
}
|
|
2289
|
+
}
|
|
2290
|
+
return this;
|
|
2291
|
+
}
|
|
2292
|
+
clearDirectFormatting() {
|
|
2293
|
+
const style = this.formatting.style;
|
|
2294
|
+
const numbering = this.formatting.numbering;
|
|
2295
|
+
this.formatting = {};
|
|
2296
|
+
if (style)
|
|
2297
|
+
this.formatting.style = style;
|
|
2298
|
+
if (numbering)
|
|
2299
|
+
this.formatting.numbering = numbering;
|
|
2300
|
+
for (const item of this.content) {
|
|
2301
|
+
if (item instanceof Run) {
|
|
2302
|
+
item.clearFormatting();
|
|
2303
|
+
}
|
|
2304
|
+
}
|
|
2305
|
+
return this;
|
|
2306
|
+
}
|
|
2307
|
+
}
|
|
2308
|
+
//# sourceMappingURL=Paragraph.js.map
|