docxmlater 10.1.3 → 10.1.5

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.
Files changed (371) hide show
  1. package/README.md +759 -754
  2. package/dist/constants/legacyCompatFlags.js +1 -1
  3. package/dist/constants/legacyCompatFlags.js.map +1 -1
  4. package/dist/constants/limits.js.map +1 -1
  5. package/dist/core/Document.d.ts +50 -50
  6. package/dist/core/Document.d.ts.map +1 -1
  7. package/dist/core/Document.js +483 -471
  8. package/dist/core/Document.js.map +1 -1
  9. package/dist/core/DocumentContent.d.ts +9 -9
  10. package/dist/core/DocumentContent.d.ts.map +1 -1
  11. package/dist/core/DocumentContent.js +1 -1
  12. package/dist/core/DocumentContent.js.map +1 -1
  13. package/dist/core/DocumentGenerator.d.ts +11 -11
  14. package/dist/core/DocumentGenerator.d.ts.map +1 -1
  15. package/dist/core/DocumentGenerator.js +251 -251
  16. package/dist/core/DocumentGenerator.js.map +1 -1
  17. package/dist/core/DocumentIdManager.js.map +1 -1
  18. package/dist/core/DocumentParser.d.ts +15 -15
  19. package/dist/core/DocumentParser.d.ts.map +1 -1
  20. package/dist/core/DocumentParser.js +2123 -2155
  21. package/dist/core/DocumentParser.js.map +1 -1
  22. package/dist/core/DocumentValidator.d.ts.map +1 -1
  23. package/dist/core/DocumentValidator.js +2 -5
  24. package/dist/core/DocumentValidator.js.map +1 -1
  25. package/dist/core/Relationship.js.map +1 -1
  26. package/dist/core/RelationshipManager.d.ts.map +1 -1
  27. package/dist/core/RelationshipManager.js +3 -3
  28. package/dist/core/RelationshipManager.js.map +1 -1
  29. package/dist/elements/AlternateContent.js.map +1 -1
  30. package/dist/elements/Bookmark.d.ts.map +1 -1
  31. package/dist/elements/Bookmark.js +3 -1
  32. package/dist/elements/Bookmark.js.map +1 -1
  33. package/dist/elements/BookmarkManager.d.ts.map +1 -1
  34. package/dist/elements/BookmarkManager.js.map +1 -1
  35. package/dist/elements/Comment.d.ts.map +1 -1
  36. package/dist/elements/Comment.js +9 -6
  37. package/dist/elements/Comment.js.map +1 -1
  38. package/dist/elements/CommentManager.d.ts.map +1 -1
  39. package/dist/elements/CommentManager.js +18 -17
  40. package/dist/elements/CommentManager.js.map +1 -1
  41. package/dist/elements/CommonTypes.d.ts +21 -21
  42. package/dist/elements/CommonTypes.d.ts.map +1 -1
  43. package/dist/elements/CommonTypes.js +56 -56
  44. package/dist/elements/CommonTypes.js.map +1 -1
  45. package/dist/elements/CustomXml.js.map +1 -1
  46. package/dist/elements/Endnote.d.ts.map +1 -1
  47. package/dist/elements/Endnote.js +6 -6
  48. package/dist/elements/Endnote.js.map +1 -1
  49. package/dist/elements/EndnoteManager.d.ts.map +1 -1
  50. package/dist/elements/EndnoteManager.js +6 -7
  51. package/dist/elements/EndnoteManager.js.map +1 -1
  52. package/dist/elements/Field.d.ts.map +1 -1
  53. package/dist/elements/Field.js +82 -25
  54. package/dist/elements/Field.js.map +1 -1
  55. package/dist/elements/FieldHelpers.d.ts.map +1 -1
  56. package/dist/elements/FieldHelpers.js.map +1 -1
  57. package/dist/elements/FontManager.d.ts.map +1 -1
  58. package/dist/elements/FontManager.js +1 -1
  59. package/dist/elements/FontManager.js.map +1 -1
  60. package/dist/elements/Footer.js +2 -2
  61. package/dist/elements/Footer.js.map +1 -1
  62. package/dist/elements/Footnote.d.ts.map +1 -1
  63. package/dist/elements/Footnote.js +6 -6
  64. package/dist/elements/Footnote.js.map +1 -1
  65. package/dist/elements/FootnoteManager.d.ts.map +1 -1
  66. package/dist/elements/FootnoteManager.js +6 -7
  67. package/dist/elements/FootnoteManager.js.map +1 -1
  68. package/dist/elements/Header.js +2 -2
  69. package/dist/elements/Header.js.map +1 -1
  70. package/dist/elements/HeaderFooterManager.js.map +1 -1
  71. package/dist/elements/Hyperlink.d.ts +5 -3
  72. package/dist/elements/Hyperlink.d.ts.map +1 -1
  73. package/dist/elements/Hyperlink.js +134 -76
  74. package/dist/elements/Hyperlink.js.map +1 -1
  75. package/dist/elements/Image.d.ts.map +1 -1
  76. package/dist/elements/Image.js +238 -106
  77. package/dist/elements/Image.js.map +1 -1
  78. package/dist/elements/ImageManager.d.ts.map +1 -1
  79. package/dist/elements/ImageManager.js +1 -1
  80. package/dist/elements/ImageManager.js.map +1 -1
  81. package/dist/elements/ImageRun.js +1 -1
  82. package/dist/elements/ImageRun.js.map +1 -1
  83. package/dist/elements/MathElement.js.map +1 -1
  84. package/dist/elements/Paragraph.d.ts +24 -24
  85. package/dist/elements/Paragraph.d.ts.map +1 -1
  86. package/dist/elements/Paragraph.js +181 -188
  87. package/dist/elements/Paragraph.js.map +1 -1
  88. package/dist/elements/PreservedElement.js.map +1 -1
  89. package/dist/elements/PropertyChangeTypes.d.ts.map +1 -1
  90. package/dist/elements/PropertyChangeTypes.js +6 -6
  91. package/dist/elements/PropertyChangeTypes.js.map +1 -1
  92. package/dist/elements/RangeMarker.d.ts.map +1 -1
  93. package/dist/elements/RangeMarker.js.map +1 -1
  94. package/dist/elements/Revision.d.ts.map +1 -1
  95. package/dist/elements/Revision.js +4 -5
  96. package/dist/elements/Revision.js.map +1 -1
  97. package/dist/elements/RevisionContent.js.map +1 -1
  98. package/dist/elements/RevisionManager.d.ts.map +1 -1
  99. package/dist/elements/RevisionManager.js +40 -48
  100. package/dist/elements/RevisionManager.js.map +1 -1
  101. package/dist/elements/Run.d.ts +16 -16
  102. package/dist/elements/Run.d.ts.map +1 -1
  103. package/dist/elements/Run.js +256 -238
  104. package/dist/elements/Run.js.map +1 -1
  105. package/dist/elements/Section.d.ts.map +1 -1
  106. package/dist/elements/Section.js +36 -11
  107. package/dist/elements/Section.js.map +1 -1
  108. package/dist/elements/Shape.d.ts.map +1 -1
  109. package/dist/elements/Shape.js.map +1 -1
  110. package/dist/elements/StructuredDocumentTag.d.ts +6 -6
  111. package/dist/elements/StructuredDocumentTag.d.ts.map +1 -1
  112. package/dist/elements/StructuredDocumentTag.js +99 -104
  113. package/dist/elements/StructuredDocumentTag.js.map +1 -1
  114. package/dist/elements/Table.d.ts +11 -11
  115. package/dist/elements/Table.d.ts.map +1 -1
  116. package/dist/elements/Table.js +102 -107
  117. package/dist/elements/Table.js.map +1 -1
  118. package/dist/elements/TableCell.d.ts +10 -10
  119. package/dist/elements/TableCell.d.ts.map +1 -1
  120. package/dist/elements/TableCell.js +105 -106
  121. package/dist/elements/TableCell.js.map +1 -1
  122. package/dist/elements/TableGridChange.d.ts.map +1 -1
  123. package/dist/elements/TableGridChange.js.map +1 -1
  124. package/dist/elements/TableOfContents.d.ts.map +1 -1
  125. package/dist/elements/TableOfContents.js +4 -4
  126. package/dist/elements/TableOfContents.js.map +1 -1
  127. package/dist/elements/TableOfContentsElement.js.map +1 -1
  128. package/dist/elements/TableRow.d.ts.map +1 -1
  129. package/dist/elements/TableRow.js +13 -6
  130. package/dist/elements/TableRow.js.map +1 -1
  131. package/dist/elements/TextBox.d.ts.map +1 -1
  132. package/dist/elements/TextBox.js +3 -5
  133. package/dist/elements/TextBox.js.map +1 -1
  134. package/dist/formatting/AbstractNumbering.d.ts +4 -4
  135. package/dist/formatting/AbstractNumbering.d.ts.map +1 -1
  136. package/dist/formatting/AbstractNumbering.js +54 -49
  137. package/dist/formatting/AbstractNumbering.js.map +1 -1
  138. package/dist/formatting/NumberingInstance.d.ts.map +1 -1
  139. package/dist/formatting/NumberingInstance.js +1 -3
  140. package/dist/formatting/NumberingInstance.js.map +1 -1
  141. package/dist/formatting/NumberingLevel.d.ts +5 -5
  142. package/dist/formatting/NumberingLevel.d.ts.map +1 -1
  143. package/dist/formatting/NumberingLevel.js +119 -125
  144. package/dist/formatting/NumberingLevel.js.map +1 -1
  145. package/dist/formatting/NumberingManager.d.ts.map +1 -1
  146. package/dist/formatting/NumberingManager.js +9 -9
  147. package/dist/formatting/NumberingManager.js.map +1 -1
  148. package/dist/formatting/Style.d.ts +11 -11
  149. package/dist/formatting/Style.d.ts.map +1 -1
  150. package/dist/formatting/Style.js +219 -247
  151. package/dist/formatting/Style.js.map +1 -1
  152. package/dist/formatting/StylesManager.d.ts +2 -2
  153. package/dist/formatting/StylesManager.d.ts.map +1 -1
  154. package/dist/formatting/StylesManager.js +96 -102
  155. package/dist/formatting/StylesManager.js.map +1 -1
  156. package/dist/helpers/CleanupHelper.d.ts +1 -1
  157. package/dist/helpers/CleanupHelper.d.ts.map +1 -1
  158. package/dist/helpers/CleanupHelper.js +6 -6
  159. package/dist/helpers/CleanupHelper.js.map +1 -1
  160. package/dist/images/ImageOptimizer.js +7 -7
  161. package/dist/images/ImageOptimizer.js.map +1 -1
  162. package/dist/index.d.ts +9 -9
  163. package/dist/index.d.ts.map +1 -1
  164. package/dist/index.js.map +1 -1
  165. package/dist/managers/DrawingManager.js.map +1 -1
  166. package/dist/tracking/DocumentTrackingContext.d.ts.map +1 -1
  167. package/dist/tracking/DocumentTrackingContext.js +23 -7
  168. package/dist/tracking/DocumentTrackingContext.js.map +1 -1
  169. package/dist/tracking/TrackingContext.d.ts.map +1 -1
  170. package/dist/tracking/TrackingContext.js.map +1 -1
  171. package/dist/types/compatibility-types.js.map +1 -1
  172. package/dist/types/formatting.js.map +1 -1
  173. package/dist/types/list-types.d.ts +6 -6
  174. package/dist/types/list-types.js.map +1 -1
  175. package/dist/types/settings-types.js.map +1 -1
  176. package/dist/types/styleConfig.d.ts +2 -2
  177. package/dist/types/styleConfig.js.map +1 -1
  178. package/dist/utils/ChangelogGenerator.d.ts.map +1 -1
  179. package/dist/utils/ChangelogGenerator.js +97 -101
  180. package/dist/utils/ChangelogGenerator.js.map +1 -1
  181. package/dist/utils/CompatibilityUpgrader.d.ts.map +1 -1
  182. package/dist/utils/CompatibilityUpgrader.js +1 -1
  183. package/dist/utils/CompatibilityUpgrader.js.map +1 -1
  184. package/dist/utils/InMemoryRevisionAcceptor.d.ts.map +1 -1
  185. package/dist/utils/InMemoryRevisionAcceptor.js +1 -6
  186. package/dist/utils/InMemoryRevisionAcceptor.js.map +1 -1
  187. package/dist/utils/MoveOperationHelper.d.ts.map +1 -1
  188. package/dist/utils/MoveOperationHelper.js +1 -1
  189. package/dist/utils/MoveOperationHelper.js.map +1 -1
  190. package/dist/utils/RevisionAwareProcessor.d.ts.map +1 -1
  191. package/dist/utils/RevisionAwareProcessor.js +2 -4
  192. package/dist/utils/RevisionAwareProcessor.js.map +1 -1
  193. package/dist/utils/RevisionWalker.d.ts.map +1 -1
  194. package/dist/utils/RevisionWalker.js +4 -12
  195. package/dist/utils/RevisionWalker.js.map +1 -1
  196. package/dist/utils/SelectiveRevisionAcceptor.d.ts.map +1 -1
  197. package/dist/utils/SelectiveRevisionAcceptor.js +2 -6
  198. package/dist/utils/SelectiveRevisionAcceptor.js.map +1 -1
  199. package/dist/utils/ShadingResolver.d.ts.map +1 -1
  200. package/dist/utils/ShadingResolver.js +1 -1
  201. package/dist/utils/ShadingResolver.js.map +1 -1
  202. package/dist/utils/acceptRevisions.d.ts.map +1 -1
  203. package/dist/utils/acceptRevisions.js +23 -12
  204. package/dist/utils/acceptRevisions.js.map +1 -1
  205. package/dist/utils/cnfStyleDecoder.d.ts +1 -1
  206. package/dist/utils/cnfStyleDecoder.d.ts.map +1 -1
  207. package/dist/utils/cnfStyleDecoder.js +40 -40
  208. package/dist/utils/cnfStyleDecoder.js.map +1 -1
  209. package/dist/utils/corruptionDetection.d.ts.map +1 -1
  210. package/dist/utils/corruptionDetection.js.map +1 -1
  211. package/dist/utils/dateFormatting.js.map +1 -1
  212. package/dist/utils/deepClone.js +1 -1
  213. package/dist/utils/deepClone.js.map +1 -1
  214. package/dist/utils/diagnostics.d.ts.map +1 -1
  215. package/dist/utils/diagnostics.js +1 -1
  216. package/dist/utils/diagnostics.js.map +1 -1
  217. package/dist/utils/errorHandling.js.map +1 -1
  218. package/dist/utils/formatting.d.ts.map +1 -1
  219. package/dist/utils/formatting.js +10 -2
  220. package/dist/utils/formatting.js.map +1 -1
  221. package/dist/utils/list-detection.d.ts +2 -2
  222. package/dist/utils/list-detection.d.ts.map +1 -1
  223. package/dist/utils/list-detection.js +21 -23
  224. package/dist/utils/list-detection.js.map +1 -1
  225. package/dist/utils/logger.d.ts.map +1 -1
  226. package/dist/utils/logger.js +12 -7
  227. package/dist/utils/logger.js.map +1 -1
  228. package/dist/utils/parsingHelpers.js.map +1 -1
  229. package/dist/utils/stripTrackedChanges.d.ts.map +1 -1
  230. package/dist/utils/stripTrackedChanges.js +3 -3
  231. package/dist/utils/stripTrackedChanges.js.map +1 -1
  232. package/dist/utils/textDiff.d.ts +1 -1
  233. package/dist/utils/textDiff.js +8 -8
  234. package/dist/utils/textDiff.js.map +1 -1
  235. package/dist/utils/units.js.map +1 -1
  236. package/dist/utils/validation.d.ts.map +1 -1
  237. package/dist/utils/validation.js +24 -7
  238. package/dist/utils/validation.js.map +1 -1
  239. package/dist/utils/xmlSanitization.d.ts.map +1 -1
  240. package/dist/utils/xmlSanitization.js +3 -3
  241. package/dist/utils/xmlSanitization.js.map +1 -1
  242. package/dist/validation/RevisionAutoFixer.d.ts.map +1 -1
  243. package/dist/validation/RevisionAutoFixer.js +5 -5
  244. package/dist/validation/RevisionAutoFixer.js.map +1 -1
  245. package/dist/validation/RevisionValidator.d.ts.map +1 -1
  246. package/dist/validation/RevisionValidator.js +7 -9
  247. package/dist/validation/RevisionValidator.js.map +1 -1
  248. package/dist/validation/ValidationRules.js +3 -3
  249. package/dist/validation/ValidationRules.js.map +1 -1
  250. package/dist/validation/index.js.map +1 -1
  251. package/dist/xml/XMLBuilder.d.ts +1 -1
  252. package/dist/xml/XMLBuilder.d.ts.map +1 -1
  253. package/dist/xml/XMLBuilder.js +98 -100
  254. package/dist/xml/XMLBuilder.js.map +1 -1
  255. package/dist/xml/XMLParser.d.ts.map +1 -1
  256. package/dist/xml/XMLParser.js +61 -66
  257. package/dist/xml/XMLParser.js.map +1 -1
  258. package/dist/zip/ZipHandler.d.ts.map +1 -1
  259. package/dist/zip/ZipHandler.js.map +1 -1
  260. package/dist/zip/ZipReader.d.ts.map +1 -1
  261. package/dist/zip/ZipReader.js +1 -3
  262. package/dist/zip/ZipReader.js.map +1 -1
  263. package/dist/zip/ZipWriter.d.ts +1 -1
  264. package/dist/zip/ZipWriter.d.ts.map +1 -1
  265. package/dist/zip/ZipWriter.js +28 -36
  266. package/dist/zip/ZipWriter.js.map +1 -1
  267. package/dist/zip/types.js +1 -1
  268. package/dist/zip/types.js.map +1 -1
  269. package/package.json +92 -92
  270. package/src/__tests__/helper-methods.test.ts +512 -512
  271. package/src/constants/legacyCompatFlags.ts +138 -138
  272. package/src/constants/limits.ts +50 -50
  273. package/src/core/Document.ts +985 -1145
  274. package/src/core/DocumentContent.ts +461 -467
  275. package/src/core/DocumentGenerator.ts +1133 -1104
  276. package/src/core/DocumentIdManager.ts +158 -158
  277. package/src/core/DocumentParser.ts +2347 -2716
  278. package/src/core/DocumentValidator.ts +363 -372
  279. package/src/core/Relationship.ts +367 -367
  280. package/src/core/RelationshipManager.ts +429 -428
  281. package/src/elements/AlternateContent.ts +42 -42
  282. package/src/elements/Bookmark.ts +212 -210
  283. package/src/elements/BookmarkManager.ts +247 -250
  284. package/src/elements/Comment.ts +356 -359
  285. package/src/elements/CommentManager.ts +499 -502
  286. package/src/elements/CommonTypes.ts +524 -549
  287. package/src/elements/CustomXml.ts +36 -36
  288. package/src/elements/Endnote.ts +221 -217
  289. package/src/elements/EndnoteManager.ts +246 -249
  290. package/src/elements/Field.ts +1292 -1233
  291. package/src/elements/FieldHelpers.ts +329 -333
  292. package/src/elements/FontManager.ts +336 -339
  293. package/src/elements/Footer.ts +269 -269
  294. package/src/elements/Footnote.ts +221 -217
  295. package/src/elements/FootnoteManager.ts +246 -249
  296. package/src/elements/Header.ts +269 -269
  297. package/src/elements/HeaderFooterManager.ts +219 -219
  298. package/src/elements/Hyperlink.ts +1288 -1193
  299. package/src/elements/Image.ts +1982 -1756
  300. package/src/elements/ImageManager.ts +437 -432
  301. package/src/elements/ImageRun.ts +59 -59
  302. package/src/elements/MathElement.ts +65 -65
  303. package/src/elements/Paragraph.ts +4347 -4287
  304. package/src/elements/PreservedElement.ts +53 -53
  305. package/src/elements/PropertyChangeTypes.ts +458 -442
  306. package/src/elements/RangeMarker.ts +382 -400
  307. package/src/elements/Revision.ts +1198 -1217
  308. package/src/elements/RevisionContent.ts +73 -73
  309. package/src/elements/RevisionManager.ts +1070 -1070
  310. package/src/elements/Run.ts +3103 -3073
  311. package/src/elements/Section.ts +1521 -1421
  312. package/src/elements/Shape.ts +884 -873
  313. package/src/elements/StructuredDocumentTag.ts +1176 -1207
  314. package/src/elements/Table.ts +2468 -2524
  315. package/src/elements/TableCell.ts +1617 -1621
  316. package/src/elements/TableGridChange.ts +149 -151
  317. package/src/elements/TableOfContents.ts +701 -691
  318. package/src/elements/TableOfContentsElement.ts +89 -89
  319. package/src/elements/TableRow.ts +960 -929
  320. package/src/elements/TextBox.ts +766 -768
  321. package/src/formatting/AbstractNumbering.ts +580 -579
  322. package/src/formatting/NumberingInstance.ts +295 -299
  323. package/src/formatting/NumberingLevel.ts +981 -1040
  324. package/src/formatting/NumberingManager.ts +833 -827
  325. package/src/formatting/Style.ts +1785 -1879
  326. package/src/formatting/StylesManager.ts +1090 -1130
  327. package/src/helpers/CleanupHelper.ts +524 -524
  328. package/src/images/ImageOptimizer.ts +274 -274
  329. package/src/index.ts +559 -554
  330. package/src/managers/DrawingManager.ts +319 -319
  331. package/src/tracking/DocumentTrackingContext.ts +687 -674
  332. package/src/tracking/TrackingContext.ts +175 -173
  333. package/src/types/compatibility-types.ts +49 -49
  334. package/src/types/formatting.ts +210 -210
  335. package/src/types/list-types.ts +14 -14
  336. package/src/types/settings-types.ts +59 -59
  337. package/src/types/styleConfig.ts +189 -189
  338. package/src/utils/ChangelogGenerator.ts +1583 -1581
  339. package/src/utils/CompatibilityUpgrader.ts +235 -237
  340. package/src/utils/InMemoryRevisionAcceptor.ts +691 -696
  341. package/src/utils/MoveOperationHelper.ts +233 -238
  342. package/src/utils/RevisionAwareProcessor.ts +518 -526
  343. package/src/utils/RevisionWalker.ts +427 -457
  344. package/src/utils/SelectiveRevisionAcceptor.ts +662 -683
  345. package/src/utils/ShadingResolver.ts +105 -107
  346. package/src/utils/acceptRevisions.ts +723 -714
  347. package/src/utils/cnfStyleDecoder.ts +212 -217
  348. package/src/utils/corruptionDetection.ts +346 -345
  349. package/src/utils/dateFormatting.ts +20 -20
  350. package/src/utils/deepClone.ts +77 -78
  351. package/src/utils/diagnostics.ts +125 -129
  352. package/src/utils/errorHandling.ts +80 -80
  353. package/src/utils/formatting.ts +220 -213
  354. package/src/utils/list-detection.ts +32 -42
  355. package/src/utils/logger.ts +412 -404
  356. package/src/utils/parsingHelpers.ts +190 -190
  357. package/src/utils/stripTrackedChanges.ts +356 -353
  358. package/src/utils/textDiff.ts +100 -100
  359. package/src/utils/units.ts +421 -421
  360. package/src/utils/validation.ts +553 -542
  361. package/src/utils/xmlSanitization.ts +179 -182
  362. package/src/validation/RevisionAutoFixer.ts +541 -542
  363. package/src/validation/RevisionValidator.ts +470 -460
  364. package/src/validation/ValidationRules.ts +338 -338
  365. package/src/validation/index.ts +30 -30
  366. package/src/xml/XMLBuilder.ts +857 -871
  367. package/src/xml/XMLParser.ts +877 -919
  368. package/src/zip/ZipHandler.ts +629 -637
  369. package/src/zip/ZipReader.ts +295 -299
  370. package/src/zip/ZipWriter.ts +374 -390
  371. package/src/zip/types.ts +116 -116
@@ -1,460 +1,470 @@
1
- /**
2
- * RevisionValidator - Validates document revisions for ECMA-376 compliance
3
- *
4
- * Checks tracked changes against OOXML specifications to prevent
5
- * document corruption and ensure compatibility with Microsoft Word.
6
- *
7
- * @module RevisionValidator
8
- */
9
-
10
- import type { Document } from '../core/Document';
11
- import type { Revision } from '../elements/Revision';
12
- import {
13
- REVISION_RULES,
14
- ValidationIssue,
15
- ValidationOptions,
16
- ValidationResult,
17
- createIssueFromRule,
18
- } from './ValidationRules';
19
-
20
- /**
21
- * Validates document revisions for ECMA-376 compliance.
22
- *
23
- * @example
24
- * ```typescript
25
- * const result = RevisionValidator.validate(doc);
26
- * if (!result.valid) {
27
- * console.error(`Found ${result.errors.length} errors`);
28
- * for (const error of result.errors) {
29
- * console.error(` ${error.code}: ${error.message}`);
30
- * }
31
- * }
32
- * ```
33
- */
34
- export class RevisionValidator {
35
- /**
36
- * Validates all revisions in a document.
37
- *
38
- * @param doc - Document to validate
39
- * @param options - Validation options
40
- * @returns Validation result with all issues found
41
- */
42
- static validate(doc: Document, options?: ValidationOptions): ValidationResult {
43
- const revisionManager = doc.getRevisionManager();
44
- if (!revisionManager) {
45
- return this.createEmptyResult();
46
- }
47
-
48
- const revisions = revisionManager.getAllRevisions();
49
- const allIssues: ValidationIssue[] = [];
50
-
51
- // Skip certain rules if lenient mode
52
- const skipRules = new Set(options?.skipRules || []);
53
- if (options?.level === 'lenient') {
54
- // In lenient mode, skip info rules
55
- skipRules.add('REV201');
56
- skipRules.add('REV202');
57
- }
58
-
59
- // Run all validations
60
- if (!skipRules.has('REV001')) {
61
- allIssues.push(...this.validateRevisionIds(revisions));
62
- }
63
- if (!skipRules.has('REV003') && !skipRules.has('REV004')) {
64
- allIssues.push(...this.validateMovePairs(revisions));
65
- }
66
- if (!skipRules.has('REV002')) {
67
- allIssues.push(...this.validateAuthors(revisions));
68
- }
69
- if (!skipRules.has('REV101') && !skipRules.has('REV102')) {
70
- allIssues.push(...this.validateDates(revisions));
71
- }
72
- if (!skipRules.has('REV103')) {
73
- allIssues.push(...this.validateContent(revisions));
74
- }
75
- if (!skipRules.has('REV104') && options?.level === 'strict') {
76
- allIssues.push(...this.validateSequentialIds(revisions));
77
- }
78
- if (!skipRules.has('REV201')) {
79
- allIssues.push(...this.validateRevisionCount(revisions));
80
- }
81
- if (!skipRules.has('REV202')) {
82
- allIssues.push(...this.validateRevisionDates(revisions));
83
- }
84
-
85
- // Apply max issues limit
86
- const limitedIssues = options?.maxIssues
87
- ? allIssues.slice(0, options.maxIssues)
88
- : allIssues;
89
-
90
- // Separate by severity
91
- let errors = limitedIssues.filter(i => i.severity === 'error');
92
- let warnings = limitedIssues.filter(i => i.severity === 'warning');
93
- const infos = limitedIssues.filter(i => i.severity === 'info');
94
- const autoFixable = limitedIssues.filter(i => i.autoFixable);
95
-
96
- // Handle warningsAsErrors option
97
- if (options?.warningsAsErrors) {
98
- errors = [...errors, ...warnings];
99
- warnings = [];
100
- }
101
-
102
- return {
103
- valid: errors.length === 0,
104
- errors,
105
- warnings,
106
- infos,
107
- autoFixable,
108
- summary: {
109
- totalIssues: limitedIssues.length,
110
- errorCount: errors.length,
111
- warningCount: warnings.length,
112
- infoCount: infos.length,
113
- autoFixableCount: autoFixable.length,
114
- },
115
- };
116
- }
117
-
118
- /**
119
- * Creates an empty validation result (for documents with no revisions).
120
- */
121
- private static createEmptyResult(): ValidationResult {
122
- return {
123
- valid: true,
124
- errors: [],
125
- warnings: [],
126
- infos: [],
127
- autoFixable: [],
128
- summary: {
129
- totalIssues: 0,
130
- errorCount: 0,
131
- warningCount: 0,
132
- infoCount: 0,
133
- autoFixableCount: 0,
134
- },
135
- };
136
- }
137
-
138
- /**
139
- * Validates revision ID uniqueness.
140
- *
141
- * Per ECMA-376, revision IDs must be unique within a document.
142
- * Duplicate IDs can cause Word to reject the document.
143
- *
144
- * @param revisions - Array of revisions to validate
145
- * @returns Array of validation issues for duplicate IDs
146
- */
147
- static validateRevisionIds(revisions: Revision[]): ValidationIssue[] {
148
- const issues: ValidationIssue[] = [];
149
- const seenIds = new Map<number, number[]>(); // id -> indices
150
-
151
- revisions.forEach((rev, index) => {
152
- const id = rev.getId();
153
- if (!seenIds.has(id)) {
154
- seenIds.set(id, []);
155
- }
156
- seenIds.get(id)!.push(index);
157
- });
158
-
159
- for (const [id, indices] of seenIds) {
160
- if (indices.length > 1) {
161
- const rule = REVISION_RULES.DUPLICATE_ID;
162
- if (rule) {
163
- issues.push(createIssueFromRule(
164
- rule,
165
- { revisionId: id },
166
- `Duplicate revision ID ${id} found at ${indices.length} locations (indices: ${indices.join(', ')})`
167
- ));
168
- }
169
- }
170
- }
171
-
172
- return issues;
173
- }
174
-
175
- /**
176
- * Validates move operation pairs.
177
- *
178
- * Each moveFrom must have a matching moveTo with the same moveId,
179
- * and vice versa. Orphaned move markers can cause document corruption.
180
- *
181
- * @param revisions - Array of revisions to validate
182
- * @returns Array of validation issues for orphaned move operations
183
- */
184
- static validateMovePairs(revisions: Revision[]): ValidationIssue[] {
185
- const issues: ValidationIssue[] = [];
186
-
187
- const moveFromIds = new Map<string, Revision>();
188
- const moveToIds = new Map<string, Revision>();
189
-
190
- for (const rev of revisions) {
191
- const moveId = rev.getMoveId();
192
- if (!moveId) continue;
193
-
194
- if (rev.getType() === 'moveFrom') {
195
- moveFromIds.set(moveId, rev);
196
- } else if (rev.getType() === 'moveTo') {
197
- moveToIds.set(moveId, rev);
198
- }
199
- }
200
-
201
- // Check for orphaned moveFrom
202
- for (const [moveId, rev] of moveFromIds) {
203
- if (!moveToIds.has(moveId)) {
204
- issues.push(createIssueFromRule(
205
- REVISION_RULES.ORPHANED_MOVE_FROM,
206
- { revisionId: rev.getId() },
207
- `moveFrom with moveId="${moveId}" has no matching moveTo`
208
- ));
209
- }
210
- }
211
-
212
- // Check for orphaned moveTo
213
- for (const [moveId, rev] of moveToIds) {
214
- if (!moveFromIds.has(moveId)) {
215
- issues.push(createIssueFromRule(
216
- REVISION_RULES.ORPHANED_MOVE_TO,
217
- { revisionId: rev.getId() },
218
- `moveTo with moveId="${moveId}" has no matching moveFrom`
219
- ));
220
- }
221
- }
222
-
223
- return issues;
224
- }
225
-
226
- /**
227
- * Validates author presence.
228
- *
229
- * Per ECMA-376, the author attribute is required for revisions.
230
- *
231
- * @param revisions - Array of revisions to validate
232
- * @returns Array of validation issues for missing authors
233
- */
234
- static validateAuthors(revisions: Revision[]): ValidationIssue[] {
235
- const issues: ValidationIssue[] = [];
236
-
237
- for (const rev of revisions) {
238
- const author = rev.getAuthor();
239
- if (!author || author.trim() === '') {
240
- issues.push(createIssueFromRule(
241
- REVISION_RULES.MISSING_AUTHOR,
242
- { revisionId: rev.getId() }
243
- ));
244
- }
245
- }
246
-
247
- return issues;
248
- }
249
-
250
- /**
251
- * Validates date presence and format.
252
- *
253
- * Per ECMA-376, revision dates should be in ISO 8601 format.
254
- *
255
- * @param revisions - Array of revisions to validate
256
- * @returns Array of validation issues for date problems
257
- */
258
- static validateDates(revisions: Revision[]): ValidationIssue[] {
259
- const issues: ValidationIssue[] = [];
260
-
261
- for (const rev of revisions) {
262
- const date = rev.getDate();
263
-
264
- if (!date) {
265
- issues.push(createIssueFromRule(
266
- REVISION_RULES.MISSING_DATE,
267
- { revisionId: rev.getId() }
268
- ));
269
- } else if (isNaN(date.getTime())) {
270
- issues.push(createIssueFromRule(
271
- REVISION_RULES.INVALID_DATE_FORMAT,
272
- { revisionId: rev.getId() },
273
- `Revision ${rev.getId()} has an invalid date`
274
- ));
275
- }
276
- }
277
-
278
- return issues;
279
- }
280
-
281
- /**
282
- * Validates revision content.
283
- *
284
- * Revisions (except property changes) should have content.
285
- *
286
- * @param revisions - Array of revisions to validate
287
- * @returns Array of validation issues for empty revisions
288
- */
289
- static validateContent(revisions: Revision[]): ValidationIssue[] {
290
- const issues: ValidationIssue[] = [];
291
-
292
- const propertyChangeTypes = [
293
- 'runPropertiesChange',
294
- 'paragraphPropertiesChange',
295
- 'tablePropertiesChange',
296
- 'tableExceptionPropertiesChange',
297
- 'tableRowPropertiesChange',
298
- 'tableCellPropertiesChange',
299
- 'sectionPropertiesChange',
300
- 'numberingChange',
301
- ];
302
-
303
- for (const rev of revisions) {
304
- const type = rev.getType();
305
-
306
- // Property changes don't need text content
307
- if (propertyChangeTypes.includes(type)) {
308
- continue;
309
- }
310
-
311
- const runs = rev.getRuns();
312
- const hasContent = runs.length > 0 && runs.some(r => r.getText().length > 0);
313
-
314
- if (!hasContent) {
315
- issues.push(createIssueFromRule(
316
- REVISION_RULES.EMPTY_REVISION,
317
- { revisionId: rev.getId() },
318
- `Revision ${rev.getId()} (type: ${type}) has no content`
319
- ));
320
- }
321
- }
322
-
323
- return issues;
324
- }
325
-
326
- /**
327
- * Validates that revision IDs are sequential.
328
- *
329
- * While not strictly required, sequential IDs are best practice.
330
- *
331
- * @param revisions - Array of revisions to validate
332
- * @returns Array of validation issues for non-sequential IDs
333
- */
334
- static validateSequentialIds(revisions: Revision[]): ValidationIssue[] {
335
- const issues: ValidationIssue[] = [];
336
-
337
- if (revisions.length === 0) return issues;
338
-
339
- // Use Set for O(n) lookup instead of sorting
340
- const idSet = new Set(revisions.map(r => r.getId()));
341
- const ids = Array.from(idSet);
342
-
343
- if (ids.length === 0) return issues;
344
-
345
- const minId = Math.min(...ids);
346
- const maxId = Math.max(...ids);
347
-
348
- // Find actual missing IDs in the range
349
- const missingIds: number[] = [];
350
- for (let i = minId; i <= maxId; i++) {
351
- if (!idSet.has(i)) {
352
- missingIds.push(i);
353
- }
354
- }
355
-
356
- if (missingIds.length > 0) {
357
- issues.push(createIssueFromRule(
358
- REVISION_RULES.NON_SEQUENTIAL_IDS,
359
- undefined,
360
- `Revision IDs are not sequential. Missing IDs: ${missingIds.slice(0, 10).join(', ')}${missingIds.length > 10 ? ` (and ${missingIds.length - 10} more)` : ''}`
361
- ));
362
- }
363
-
364
- return issues;
365
- }
366
-
367
- /**
368
- * Validates revision count (info-level).
369
- *
370
- * Large numbers of revisions can slow down Word.
371
- *
372
- * @param revisions - Array of revisions to validate
373
- * @returns Array of validation issues for large revision counts
374
- */
375
- static validateRevisionCount(revisions: Revision[]): ValidationIssue[] {
376
- const issues: ValidationIssue[] = [];
377
-
378
- if (revisions.length > 1000) {
379
- issues.push(createIssueFromRule(
380
- REVISION_RULES.LARGE_REVISION_COUNT,
381
- undefined,
382
- `Document has ${revisions.length} revisions (>1000). Consider accepting or rejecting some.`
383
- ));
384
- }
385
-
386
- return issues;
387
- }
388
-
389
- /**
390
- * Validates revision dates for staleness (info-level).
391
- *
392
- * Very old revisions may indicate stale tracked changes.
393
- *
394
- * @param revisions - Array of revisions to validate
395
- * @returns Array of validation issues for old revisions
396
- */
397
- static validateRevisionDates(revisions: Revision[]): ValidationIssue[] {
398
- const issues: ValidationIssue[] = [];
399
- const oneYearAgo = new Date();
400
- oneYearAgo.setFullYear(oneYearAgo.getFullYear() - 1);
401
-
402
- let oldCount = 0;
403
- for (const rev of revisions) {
404
- const date = rev.getDate();
405
- if (date && date < oneYearAgo) {
406
- oldCount++;
407
- }
408
- }
409
-
410
- if (oldCount > 0) {
411
- issues.push(createIssueFromRule(
412
- REVISION_RULES.OLD_REVISION_DATE,
413
- undefined,
414
- `${oldCount} revision(s) are older than 1 year. Consider reviewing and accepting.`
415
- ));
416
- }
417
-
418
- return issues;
419
- }
420
-
421
- /**
422
- * Quick check if a document has any validation errors.
423
- *
424
- * @param doc - Document to check
425
- * @returns True if the document has no errors
426
- */
427
- static isValid(doc: Document): boolean {
428
- const result = this.validate(doc, { level: 'normal' });
429
- return result.valid;
430
- }
431
-
432
- /**
433
- * Get a summary string of validation results.
434
- *
435
- * @param result - Validation result
436
- * @returns Human-readable summary string
437
- */
438
- static formatSummary(result: ValidationResult): string {
439
- const lines: string[] = [];
440
-
441
- lines.push(`Validation ${result.valid ? 'PASSED' : 'FAILED'}`);
442
- lines.push(`Total issues: ${result.summary.totalIssues}`);
443
-
444
- if (result.summary.errorCount > 0) {
445
- lines.push(` Errors: ${result.summary.errorCount}`);
446
- }
447
- if (result.summary.warningCount > 0) {
448
- lines.push(` Warnings: ${result.summary.warningCount}`);
449
- }
450
- if (result.summary.infoCount > 0) {
451
- lines.push(` Info: ${result.summary.infoCount}`);
452
- }
453
-
454
- if (result.summary.autoFixableCount > 0) {
455
- lines.push(` Auto-fixable: ${result.summary.autoFixableCount}`);
456
- }
457
-
458
- return lines.join('\n');
459
- }
460
- }
1
+ /**
2
+ * RevisionValidator - Validates document revisions for ECMA-376 compliance
3
+ *
4
+ * Checks tracked changes against OOXML specifications to prevent
5
+ * document corruption and ensure compatibility with Microsoft Word.
6
+ *
7
+ * @module RevisionValidator
8
+ */
9
+
10
+ import type { Document } from '../core/Document';
11
+ import type { Revision } from '../elements/Revision';
12
+ import {
13
+ REVISION_RULES,
14
+ ValidationIssue,
15
+ ValidationOptions,
16
+ ValidationResult,
17
+ createIssueFromRule,
18
+ } from './ValidationRules';
19
+
20
+ /**
21
+ * Validates document revisions for ECMA-376 compliance.
22
+ *
23
+ * @example
24
+ * ```typescript
25
+ * const result = RevisionValidator.validate(doc);
26
+ * if (!result.valid) {
27
+ * console.error(`Found ${result.errors.length} errors`);
28
+ * for (const error of result.errors) {
29
+ * console.error(` ${error.code}: ${error.message}`);
30
+ * }
31
+ * }
32
+ * ```
33
+ */
34
+ export class RevisionValidator {
35
+ /**
36
+ * Validates all revisions in a document.
37
+ *
38
+ * @param doc - Document to validate
39
+ * @param options - Validation options
40
+ * @returns Validation result with all issues found
41
+ */
42
+ static validate(doc: Document, options?: ValidationOptions): ValidationResult {
43
+ const revisionManager = doc.getRevisionManager();
44
+ if (!revisionManager) {
45
+ return this.createEmptyResult();
46
+ }
47
+
48
+ const revisions = revisionManager.getAllRevisions();
49
+ const allIssues: ValidationIssue[] = [];
50
+
51
+ // Skip certain rules if lenient mode
52
+ const skipRules = new Set(options?.skipRules || []);
53
+ if (options?.level === 'lenient') {
54
+ // In lenient mode, skip info rules
55
+ skipRules.add('REV201');
56
+ skipRules.add('REV202');
57
+ }
58
+
59
+ // Run all validations
60
+ if (!skipRules.has('REV001')) {
61
+ allIssues.push(...this.validateRevisionIds(revisions));
62
+ }
63
+ if (!skipRules.has('REV003') && !skipRules.has('REV004')) {
64
+ allIssues.push(...this.validateMovePairs(revisions));
65
+ }
66
+ if (!skipRules.has('REV002')) {
67
+ allIssues.push(...this.validateAuthors(revisions));
68
+ }
69
+ if (!skipRules.has('REV101') && !skipRules.has('REV102')) {
70
+ allIssues.push(...this.validateDates(revisions));
71
+ }
72
+ if (!skipRules.has('REV103')) {
73
+ allIssues.push(...this.validateContent(revisions));
74
+ }
75
+ if (!skipRules.has('REV104') && options?.level === 'strict') {
76
+ allIssues.push(...this.validateSequentialIds(revisions));
77
+ }
78
+ if (!skipRules.has('REV201')) {
79
+ allIssues.push(...this.validateRevisionCount(revisions));
80
+ }
81
+ if (!skipRules.has('REV202')) {
82
+ allIssues.push(...this.validateRevisionDates(revisions));
83
+ }
84
+
85
+ // Apply max issues limit
86
+ const limitedIssues = options?.maxIssues ? allIssues.slice(0, options.maxIssues) : allIssues;
87
+
88
+ // Separate by severity
89
+ let errors = limitedIssues.filter((i) => i.severity === 'error');
90
+ let warnings = limitedIssues.filter((i) => i.severity === 'warning');
91
+ const infos = limitedIssues.filter((i) => i.severity === 'info');
92
+ const autoFixable = limitedIssues.filter((i) => i.autoFixable);
93
+
94
+ // Handle warningsAsErrors option
95
+ if (options?.warningsAsErrors) {
96
+ errors = [...errors, ...warnings];
97
+ warnings = [];
98
+ }
99
+
100
+ return {
101
+ valid: errors.length === 0,
102
+ errors,
103
+ warnings,
104
+ infos,
105
+ autoFixable,
106
+ summary: {
107
+ totalIssues: limitedIssues.length,
108
+ errorCount: errors.length,
109
+ warningCount: warnings.length,
110
+ infoCount: infos.length,
111
+ autoFixableCount: autoFixable.length,
112
+ },
113
+ };
114
+ }
115
+
116
+ /**
117
+ * Creates an empty validation result (for documents with no revisions).
118
+ */
119
+ private static createEmptyResult(): ValidationResult {
120
+ return {
121
+ valid: true,
122
+ errors: [],
123
+ warnings: [],
124
+ infos: [],
125
+ autoFixable: [],
126
+ summary: {
127
+ totalIssues: 0,
128
+ errorCount: 0,
129
+ warningCount: 0,
130
+ infoCount: 0,
131
+ autoFixableCount: 0,
132
+ },
133
+ };
134
+ }
135
+
136
+ /**
137
+ * Validates revision ID uniqueness.
138
+ *
139
+ * Per ECMA-376, revision IDs must be unique within a document.
140
+ * Duplicate IDs can cause Word to reject the document.
141
+ *
142
+ * @param revisions - Array of revisions to validate
143
+ * @returns Array of validation issues for duplicate IDs
144
+ */
145
+ static validateRevisionIds(revisions: Revision[]): ValidationIssue[] {
146
+ const issues: ValidationIssue[] = [];
147
+ const seenIds = new Map<number, number[]>(); // id -> indices
148
+
149
+ revisions.forEach((rev, index) => {
150
+ const id = rev.getId();
151
+ if (!seenIds.has(id)) {
152
+ seenIds.set(id, []);
153
+ }
154
+ seenIds.get(id)!.push(index);
155
+ });
156
+
157
+ for (const [id, indices] of seenIds) {
158
+ if (indices.length > 1) {
159
+ const rule = REVISION_RULES.DUPLICATE_ID;
160
+ if (rule) {
161
+ issues.push(
162
+ createIssueFromRule(
163
+ rule,
164
+ { revisionId: id },
165
+ `Duplicate revision ID ${id} found at ${indices.length} locations (indices: ${indices.join(', ')})`
166
+ )
167
+ );
168
+ }
169
+ }
170
+ }
171
+
172
+ return issues;
173
+ }
174
+
175
+ /**
176
+ * Validates move operation pairs.
177
+ *
178
+ * Each moveFrom must have a matching moveTo with the same moveId,
179
+ * and vice versa. Orphaned move markers can cause document corruption.
180
+ *
181
+ * @param revisions - Array of revisions to validate
182
+ * @returns Array of validation issues for orphaned move operations
183
+ */
184
+ static validateMovePairs(revisions: Revision[]): ValidationIssue[] {
185
+ const issues: ValidationIssue[] = [];
186
+
187
+ const moveFromIds = new Map<string, Revision>();
188
+ const moveToIds = new Map<string, Revision>();
189
+
190
+ for (const rev of revisions) {
191
+ const moveId = rev.getMoveId();
192
+ if (!moveId) continue;
193
+
194
+ if (rev.getType() === 'moveFrom') {
195
+ moveFromIds.set(moveId, rev);
196
+ } else if (rev.getType() === 'moveTo') {
197
+ moveToIds.set(moveId, rev);
198
+ }
199
+ }
200
+
201
+ // Check for orphaned moveFrom
202
+ for (const [moveId, rev] of moveFromIds) {
203
+ if (!moveToIds.has(moveId)) {
204
+ issues.push(
205
+ createIssueFromRule(
206
+ REVISION_RULES.ORPHANED_MOVE_FROM,
207
+ { revisionId: rev.getId() },
208
+ `moveFrom with moveId="${moveId}" has no matching moveTo`
209
+ )
210
+ );
211
+ }
212
+ }
213
+
214
+ // Check for orphaned moveTo
215
+ for (const [moveId, rev] of moveToIds) {
216
+ if (!moveFromIds.has(moveId)) {
217
+ issues.push(
218
+ createIssueFromRule(
219
+ REVISION_RULES.ORPHANED_MOVE_TO,
220
+ { revisionId: rev.getId() },
221
+ `moveTo with moveId="${moveId}" has no matching moveFrom`
222
+ )
223
+ );
224
+ }
225
+ }
226
+
227
+ return issues;
228
+ }
229
+
230
+ /**
231
+ * Validates author presence.
232
+ *
233
+ * Per ECMA-376, the author attribute is required for revisions.
234
+ *
235
+ * @param revisions - Array of revisions to validate
236
+ * @returns Array of validation issues for missing authors
237
+ */
238
+ static validateAuthors(revisions: Revision[]): ValidationIssue[] {
239
+ const issues: ValidationIssue[] = [];
240
+
241
+ for (const rev of revisions) {
242
+ const author = rev.getAuthor();
243
+ if (!author || author.trim() === '') {
244
+ issues.push(
245
+ createIssueFromRule(REVISION_RULES.MISSING_AUTHOR, { revisionId: rev.getId() })
246
+ );
247
+ }
248
+ }
249
+
250
+ return issues;
251
+ }
252
+
253
+ /**
254
+ * Validates date presence and format.
255
+ *
256
+ * Per ECMA-376, revision dates should be in ISO 8601 format.
257
+ *
258
+ * @param revisions - Array of revisions to validate
259
+ * @returns Array of validation issues for date problems
260
+ */
261
+ static validateDates(revisions: Revision[]): ValidationIssue[] {
262
+ const issues: ValidationIssue[] = [];
263
+
264
+ for (const rev of revisions) {
265
+ const date = rev.getDate();
266
+
267
+ if (!date) {
268
+ issues.push(createIssueFromRule(REVISION_RULES.MISSING_DATE, { revisionId: rev.getId() }));
269
+ } else if (isNaN(date.getTime())) {
270
+ issues.push(
271
+ createIssueFromRule(
272
+ REVISION_RULES.INVALID_DATE_FORMAT,
273
+ { revisionId: rev.getId() },
274
+ `Revision ${rev.getId()} has an invalid date`
275
+ )
276
+ );
277
+ }
278
+ }
279
+
280
+ return issues;
281
+ }
282
+
283
+ /**
284
+ * Validates revision content.
285
+ *
286
+ * Revisions (except property changes) should have content.
287
+ *
288
+ * @param revisions - Array of revisions to validate
289
+ * @returns Array of validation issues for empty revisions
290
+ */
291
+ static validateContent(revisions: Revision[]): ValidationIssue[] {
292
+ const issues: ValidationIssue[] = [];
293
+
294
+ const propertyChangeTypes = [
295
+ 'runPropertiesChange',
296
+ 'paragraphPropertiesChange',
297
+ 'tablePropertiesChange',
298
+ 'tableExceptionPropertiesChange',
299
+ 'tableRowPropertiesChange',
300
+ 'tableCellPropertiesChange',
301
+ 'sectionPropertiesChange',
302
+ 'numberingChange',
303
+ ];
304
+
305
+ for (const rev of revisions) {
306
+ const type = rev.getType();
307
+
308
+ // Property changes don't need text content
309
+ if (propertyChangeTypes.includes(type)) {
310
+ continue;
311
+ }
312
+
313
+ const runs = rev.getRuns();
314
+ const hasContent = runs.length > 0 && runs.some((r) => r.getText().length > 0);
315
+
316
+ if (!hasContent) {
317
+ issues.push(
318
+ createIssueFromRule(
319
+ REVISION_RULES.EMPTY_REVISION,
320
+ { revisionId: rev.getId() },
321
+ `Revision ${rev.getId()} (type: ${type}) has no content`
322
+ )
323
+ );
324
+ }
325
+ }
326
+
327
+ return issues;
328
+ }
329
+
330
+ /**
331
+ * Validates that revision IDs are sequential.
332
+ *
333
+ * While not strictly required, sequential IDs are best practice.
334
+ *
335
+ * @param revisions - Array of revisions to validate
336
+ * @returns Array of validation issues for non-sequential IDs
337
+ */
338
+ static validateSequentialIds(revisions: Revision[]): ValidationIssue[] {
339
+ const issues: ValidationIssue[] = [];
340
+
341
+ if (revisions.length === 0) return issues;
342
+
343
+ // Use Set for O(n) lookup instead of sorting
344
+ const idSet = new Set(revisions.map((r) => r.getId()));
345
+ const ids = Array.from(idSet);
346
+
347
+ if (ids.length === 0) return issues;
348
+
349
+ const minId = Math.min(...ids);
350
+ const maxId = Math.max(...ids);
351
+
352
+ // Find actual missing IDs in the range
353
+ const missingIds: number[] = [];
354
+ for (let i = minId; i <= maxId; i++) {
355
+ if (!idSet.has(i)) {
356
+ missingIds.push(i);
357
+ }
358
+ }
359
+
360
+ if (missingIds.length > 0) {
361
+ issues.push(
362
+ createIssueFromRule(
363
+ REVISION_RULES.NON_SEQUENTIAL_IDS,
364
+ undefined,
365
+ `Revision IDs are not sequential. Missing IDs: ${missingIds.slice(0, 10).join(', ')}${missingIds.length > 10 ? ` (and ${missingIds.length - 10} more)` : ''}`
366
+ )
367
+ );
368
+ }
369
+
370
+ return issues;
371
+ }
372
+
373
+ /**
374
+ * Validates revision count (info-level).
375
+ *
376
+ * Large numbers of revisions can slow down Word.
377
+ *
378
+ * @param revisions - Array of revisions to validate
379
+ * @returns Array of validation issues for large revision counts
380
+ */
381
+ static validateRevisionCount(revisions: Revision[]): ValidationIssue[] {
382
+ const issues: ValidationIssue[] = [];
383
+
384
+ if (revisions.length > 1000) {
385
+ issues.push(
386
+ createIssueFromRule(
387
+ REVISION_RULES.LARGE_REVISION_COUNT,
388
+ undefined,
389
+ `Document has ${revisions.length} revisions (>1000). Consider accepting or rejecting some.`
390
+ )
391
+ );
392
+ }
393
+
394
+ return issues;
395
+ }
396
+
397
+ /**
398
+ * Validates revision dates for staleness (info-level).
399
+ *
400
+ * Very old revisions may indicate stale tracked changes.
401
+ *
402
+ * @param revisions - Array of revisions to validate
403
+ * @returns Array of validation issues for old revisions
404
+ */
405
+ static validateRevisionDates(revisions: Revision[]): ValidationIssue[] {
406
+ const issues: ValidationIssue[] = [];
407
+ const oneYearAgo = new Date();
408
+ oneYearAgo.setFullYear(oneYearAgo.getFullYear() - 1);
409
+
410
+ let oldCount = 0;
411
+ for (const rev of revisions) {
412
+ const date = rev.getDate();
413
+ if (date && date < oneYearAgo) {
414
+ oldCount++;
415
+ }
416
+ }
417
+
418
+ if (oldCount > 0) {
419
+ issues.push(
420
+ createIssueFromRule(
421
+ REVISION_RULES.OLD_REVISION_DATE,
422
+ undefined,
423
+ `${oldCount} revision(s) are older than 1 year. Consider reviewing and accepting.`
424
+ )
425
+ );
426
+ }
427
+
428
+ return issues;
429
+ }
430
+
431
+ /**
432
+ * Quick check if a document has any validation errors.
433
+ *
434
+ * @param doc - Document to check
435
+ * @returns True if the document has no errors
436
+ */
437
+ static isValid(doc: Document): boolean {
438
+ const result = this.validate(doc, { level: 'normal' });
439
+ return result.valid;
440
+ }
441
+
442
+ /**
443
+ * Get a summary string of validation results.
444
+ *
445
+ * @param result - Validation result
446
+ * @returns Human-readable summary string
447
+ */
448
+ static formatSummary(result: ValidationResult): string {
449
+ const lines: string[] = [];
450
+
451
+ lines.push(`Validation ${result.valid ? 'PASSED' : 'FAILED'}`);
452
+ lines.push(`Total issues: ${result.summary.totalIssues}`);
453
+
454
+ if (result.summary.errorCount > 0) {
455
+ lines.push(` Errors: ${result.summary.errorCount}`);
456
+ }
457
+ if (result.summary.warningCount > 0) {
458
+ lines.push(` Warnings: ${result.summary.warningCount}`);
459
+ }
460
+ if (result.summary.infoCount > 0) {
461
+ lines.push(` Info: ${result.summary.infoCount}`);
462
+ }
463
+
464
+ if (result.summary.autoFixableCount > 0) {
465
+ lines.push(` Auto-fixable: ${result.summary.autoFixableCount}`);
466
+ }
467
+
468
+ return lines.join('\n');
469
+ }
470
+ }