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,359 +1,356 @@
1
- /**
2
- * Comment - Represents a comment/annotation in a Word document
3
- *
4
- * Comments allow users to annotate specific text ranges in a document.
5
- * They include author, date, content, and can have replies.
6
- */
7
-
8
- import { Run } from './Run';
9
- import { XMLElement } from '../xml/XMLBuilder';
10
- import { formatDateForXml } from '../utils/dateFormatting';
11
-
12
- /**
13
- * Comment properties
14
- */
15
- export interface CommentProperties {
16
- /** Unique comment ID (assigned by CommentManager) */
17
- id?: number;
18
- /** Author who created the comment */
19
- author: string;
20
- /** Author's initials (optional) */
21
- initials?: string;
22
- /** Date when the comment was created */
23
- date?: Date;
24
- /** Comment content (text or runs) */
25
- content: string | Run | Run[];
26
- /** Parent comment ID (for replies) */
27
- parentId?: number;
28
- /** Whether the comment is resolved/done (w:done attribute per ECMA-376) */
29
- done?: boolean;
30
- }
31
-
32
- /**
33
- * Represents a comment/annotation in a document
34
- */
35
- export class Comment {
36
- private id: number;
37
- private author: string;
38
- private initials: string;
39
- private date: Date;
40
- private runs: Run[];
41
- private parentId?: number;
42
- private done: boolean;
43
-
44
- /**
45
- * Creates a new Comment
46
- * @param properties - Comment properties
47
- */
48
- constructor(properties: CommentProperties) {
49
- this.id = properties.id ?? 0; // Will be assigned by CommentManager
50
- this.author = properties.author;
51
- this.initials = properties.initials || this.generateInitials(properties.author);
52
- this.date = properties.date || new Date();
53
- this.parentId = properties.parentId;
54
- this.done = properties.done ?? false;
55
-
56
- // Convert content to runs
57
- if (typeof properties.content === 'string') {
58
- this.runs = [new Run(properties.content)];
59
- } else if (Array.isArray(properties.content)) {
60
- this.runs = properties.content;
61
- } else {
62
- this.runs = [properties.content];
63
- }
64
- }
65
-
66
- /**
67
- * Generates initials from author name
68
- * Examples: "John Doe" -> "JD", "Jane Smith" -> "JS"
69
- */
70
- private generateInitials(author: string): string {
71
- const words = author.trim().split(/\s+/).filter(w => w.length > 0);
72
- if (words.length === 0) return 'U';
73
- if (words.length === 1) return (words[0] || 'U').substring(0, 2).toUpperCase();
74
- return words
75
- .map(word => word[0] || '')
76
- .join('')
77
- .toUpperCase()
78
- .substring(0, 3) || 'U';
79
- }
80
-
81
- /**
82
- * Gets the comment ID
83
- */
84
- getId(): number {
85
- return this.id;
86
- }
87
-
88
- /**
89
- * Sets the comment ID (used by CommentManager)
90
- * @internal
91
- */
92
- setId(id: number): void {
93
- this.id = id;
94
- }
95
-
96
- /**
97
- * Gets the author
98
- */
99
- getAuthor(): string {
100
- return this.author;
101
- }
102
-
103
- /**
104
- * Sets the author
105
- */
106
- setAuthor(author: string): this {
107
- this.author = author;
108
- return this;
109
- }
110
-
111
- /**
112
- * Gets the author's initials
113
- */
114
- getInitials(): string {
115
- return this.initials;
116
- }
117
-
118
- /**
119
- * Sets the author's initials
120
- */
121
- setInitials(initials: string): this {
122
- this.initials = initials;
123
- return this;
124
- }
125
-
126
- /**
127
- * Gets the comment date
128
- */
129
- getDate(): Date {
130
- return this.date;
131
- }
132
-
133
- /**
134
- * Sets the comment date
135
- */
136
- setDate(date: Date): this {
137
- this.date = date;
138
- return this;
139
- }
140
-
141
- /**
142
- * Gets the parent comment ID (for replies)
143
- */
144
- getParentId(): number | undefined {
145
- return this.parentId;
146
- }
147
-
148
- /**
149
- * Checks if this is a reply to another comment
150
- */
151
- isReply(): boolean {
152
- return this.parentId !== undefined;
153
- }
154
-
155
- /**
156
- * Checks if the comment is resolved/done
157
- * Per ECMA-376 Part 1, Section 17.13.4.2 (w:done attribute)
158
- */
159
- isResolved(): boolean {
160
- return this.done;
161
- }
162
-
163
- /**
164
- * Marks the comment as resolved/done
165
- * Sets w:done="1" in the XML output
166
- */
167
- resolve(): this {
168
- this.done = true;
169
- return this;
170
- }
171
-
172
- /**
173
- * Marks the comment as unresolved
174
- * Removes w:done attribute from XML output
175
- */
176
- unresolve(): this {
177
- this.done = false;
178
- return this;
179
- }
180
-
181
- /**
182
- * Gets the runs in this comment
183
- */
184
- getRuns(): Run[] {
185
- return [...this.runs];
186
- }
187
-
188
- /**
189
- * Adds a run to this comment
190
- */
191
- addRun(run: Run): this {
192
- this.runs.push(run);
193
- return this;
194
- }
195
-
196
- /**
197
- * Gets the comment text (combines all runs)
198
- */
199
- getText(): string {
200
- return this.runs.map(run => run.getText()).join('');
201
- }
202
-
203
- /**
204
- * Gets the comment content (alias for getText for compatibility)
205
- */
206
- getContent(): string {
207
- return this.getText();
208
- }
209
-
210
- /**
211
- * Formats a date to ISO 8601 format for XML
212
- * Uses formatDateForXml() to strip milliseconds which Word does not accept.
213
- */
214
- private formatDate(date: Date): string {
215
- return formatDateForXml(date);
216
- }
217
-
218
- /**
219
- * Generates XML for the comment range start marker
220
- * This goes in word/document.xml at the start of the commented range
221
- */
222
- toRangeStartXML(): XMLElement {
223
- return {
224
- name: 'w:commentRangeStart',
225
- attributes: {
226
- 'w:id': this.id.toString(),
227
- },
228
- selfClosing: true,
229
- };
230
- }
231
-
232
- /**
233
- * Generates XML for the comment range end marker
234
- * This goes in word/document.xml at the end of the commented range
235
- */
236
- toRangeEndXML(): XMLElement {
237
- return {
238
- name: 'w:commentRangeEnd',
239
- attributes: {
240
- 'w:id': this.id.toString(),
241
- },
242
- selfClosing: true,
243
- };
244
- }
245
-
246
- /**
247
- * Generates XML for the comment reference
248
- * This goes in word/document.xml after the range end, inside a run
249
- */
250
- toReferenceXML(): XMLElement {
251
- return {
252
- name: 'w:r',
253
- children: [
254
- {
255
- name: 'w:commentReference',
256
- attributes: {
257
- 'w:id': this.id.toString(),
258
- },
259
- selfClosing: true,
260
- },
261
- ],
262
- };
263
- }
264
-
265
- /**
266
- * Generates XML for the comment definition
267
- * This goes in word/comments.xml
268
- */
269
- toXML(): XMLElement {
270
- const attributes: Record<string, string> = {
271
- 'w:id': this.id.toString(),
272
- 'w:author': this.author,
273
- 'w:date': this.formatDate(this.date),
274
- 'w:initials': this.initials,
275
- };
276
-
277
- // Add parent ID for replies (w15 namespace per Office 2012 extensions)
278
- if (this.parentId !== undefined) {
279
- attributes['w15:parentId'] = this.parentId.toString();
280
- }
281
-
282
- // Add done attribute for resolved comments (per ECMA-376)
283
- if (this.done) {
284
- attributes['w:done'] = '1';
285
- }
286
-
287
- // Create paragraph containing the comment content
288
- const commentParagraph: XMLElement = {
289
- name: 'w:p',
290
- children: this.runs.map(run => run.toXML()),
291
- };
292
-
293
- return {
294
- name: 'w:comment',
295
- attributes,
296
- children: [commentParagraph],
297
- };
298
- }
299
-
300
- /**
301
- * Creates a new comment
302
- * @param author - Comment author
303
- * @param content - Comment content (text or runs)
304
- * @param initials - Optional author initials
305
- * @returns New Comment instance
306
- */
307
- static create(
308
- author: string,
309
- content: string | Run | Run[],
310
- initials?: string
311
- ): Comment {
312
- return new Comment({
313
- author,
314
- content,
315
- initials,
316
- });
317
- }
318
-
319
- /**
320
- * Creates a reply to an existing comment
321
- * @param parentId - ID of the parent comment
322
- * @param author - Reply author
323
- * @param content - Reply content (text or runs)
324
- * @param initials - Optional author initials
325
- * @returns New Comment instance (reply)
326
- */
327
- static createReply(
328
- parentId: number,
329
- author: string,
330
- content: string | Run | Run[],
331
- initials?: string
332
- ): Comment {
333
- return new Comment({
334
- author,
335
- content,
336
- initials,
337
- parentId,
338
- });
339
- }
340
-
341
- /**
342
- * Creates a comment with formatted content
343
- * @param author - Comment author
344
- * @param runs - Array of formatted runs
345
- * @param initials - Optional author initials
346
- * @returns New Comment instance
347
- */
348
- static createFormatted(
349
- author: string,
350
- runs: Run[],
351
- initials?: string
352
- ): Comment {
353
- return new Comment({
354
- author,
355
- content: runs,
356
- initials,
357
- });
358
- }
359
- }
1
+ /**
2
+ * Comment - Represents a comment/annotation in a Word document
3
+ *
4
+ * Comments allow users to annotate specific text ranges in a document.
5
+ * They include author, date, content, and can have replies.
6
+ */
7
+
8
+ import { Run } from './Run';
9
+ import { XMLElement } from '../xml/XMLBuilder';
10
+ import { formatDateForXml } from '../utils/dateFormatting';
11
+
12
+ /**
13
+ * Comment properties
14
+ */
15
+ export interface CommentProperties {
16
+ /** Unique comment ID (assigned by CommentManager) */
17
+ id?: number;
18
+ /** Author who created the comment */
19
+ author: string;
20
+ /** Author's initials (optional) */
21
+ initials?: string;
22
+ /** Date when the comment was created */
23
+ date?: Date;
24
+ /** Comment content (text or runs) */
25
+ content: string | Run | Run[];
26
+ /** Parent comment ID (for replies) */
27
+ parentId?: number;
28
+ /** Whether the comment is resolved/done (w:done attribute per ECMA-376) */
29
+ done?: boolean;
30
+ }
31
+
32
+ /**
33
+ * Represents a comment/annotation in a document
34
+ */
35
+ export class Comment {
36
+ private id: number;
37
+ private author: string;
38
+ private initials: string;
39
+ private date: Date;
40
+ private runs: Run[];
41
+ private parentId?: number;
42
+ private done: boolean;
43
+
44
+ /**
45
+ * Creates a new Comment
46
+ * @param properties - Comment properties
47
+ */
48
+ constructor(properties: CommentProperties) {
49
+ this.id = properties.id ?? 0; // Will be assigned by CommentManager
50
+ this.author = properties.author;
51
+ this.initials = properties.initials || this.generateInitials(properties.author);
52
+ this.date = properties.date || new Date();
53
+ this.parentId = properties.parentId;
54
+ this.done = properties.done ?? false;
55
+
56
+ // Convert content to runs
57
+ if (typeof properties.content === 'string') {
58
+ this.runs = [new Run(properties.content)];
59
+ } else if (Array.isArray(properties.content)) {
60
+ this.runs = properties.content;
61
+ } else {
62
+ this.runs = [properties.content];
63
+ }
64
+ }
65
+
66
+ /**
67
+ * Generates initials from author name
68
+ * Examples: "John Doe" -> "JD", "Jane Smith" -> "JS"
69
+ */
70
+ private generateInitials(author: string): string {
71
+ const words = author
72
+ .trim()
73
+ .split(/\s+/)
74
+ .filter((w) => w.length > 0);
75
+ if (words.length === 0) return 'U';
76
+ if (words.length === 1) return (words[0] || 'U').substring(0, 2).toUpperCase();
77
+ return (
78
+ words
79
+ .map((word) => word[0] || '')
80
+ .join('')
81
+ .toUpperCase()
82
+ .substring(0, 3) || 'U'
83
+ );
84
+ }
85
+
86
+ /**
87
+ * Gets the comment ID
88
+ */
89
+ getId(): number {
90
+ return this.id;
91
+ }
92
+
93
+ /**
94
+ * Sets the comment ID (used by CommentManager)
95
+ * @internal
96
+ */
97
+ setId(id: number): void {
98
+ this.id = id;
99
+ }
100
+
101
+ /**
102
+ * Gets the author
103
+ */
104
+ getAuthor(): string {
105
+ return this.author;
106
+ }
107
+
108
+ /**
109
+ * Sets the author
110
+ */
111
+ setAuthor(author: string): this {
112
+ this.author = author;
113
+ return this;
114
+ }
115
+
116
+ /**
117
+ * Gets the author's initials
118
+ */
119
+ getInitials(): string {
120
+ return this.initials;
121
+ }
122
+
123
+ /**
124
+ * Sets the author's initials
125
+ */
126
+ setInitials(initials: string): this {
127
+ this.initials = initials;
128
+ return this;
129
+ }
130
+
131
+ /**
132
+ * Gets the comment date
133
+ */
134
+ getDate(): Date {
135
+ return this.date;
136
+ }
137
+
138
+ /**
139
+ * Sets the comment date
140
+ */
141
+ setDate(date: Date): this {
142
+ this.date = date;
143
+ return this;
144
+ }
145
+
146
+ /**
147
+ * Gets the parent comment ID (for replies)
148
+ */
149
+ getParentId(): number | undefined {
150
+ return this.parentId;
151
+ }
152
+
153
+ /**
154
+ * Checks if this is a reply to another comment
155
+ */
156
+ isReply(): boolean {
157
+ return this.parentId !== undefined;
158
+ }
159
+
160
+ /**
161
+ * Checks if the comment is resolved/done
162
+ * Per ECMA-376 Part 1, Section 17.13.4.2 (w:done attribute)
163
+ */
164
+ isResolved(): boolean {
165
+ return this.done;
166
+ }
167
+
168
+ /**
169
+ * Marks the comment as resolved/done
170
+ * Sets w:done="1" in the XML output
171
+ */
172
+ resolve(): this {
173
+ this.done = true;
174
+ return this;
175
+ }
176
+
177
+ /**
178
+ * Marks the comment as unresolved
179
+ * Removes w:done attribute from XML output
180
+ */
181
+ unresolve(): this {
182
+ this.done = false;
183
+ return this;
184
+ }
185
+
186
+ /**
187
+ * Gets the runs in this comment
188
+ */
189
+ getRuns(): Run[] {
190
+ return [...this.runs];
191
+ }
192
+
193
+ /**
194
+ * Adds a run to this comment
195
+ */
196
+ addRun(run: Run): this {
197
+ this.runs.push(run);
198
+ return this;
199
+ }
200
+
201
+ /**
202
+ * Gets the comment text (combines all runs)
203
+ */
204
+ getText(): string {
205
+ return this.runs.map((run) => run.getText()).join('');
206
+ }
207
+
208
+ /**
209
+ * Gets the comment content (alias for getText for compatibility)
210
+ */
211
+ getContent(): string {
212
+ return this.getText();
213
+ }
214
+
215
+ /**
216
+ * Formats a date to ISO 8601 format for XML
217
+ * Uses formatDateForXml() to strip milliseconds which Word does not accept.
218
+ */
219
+ private formatDate(date: Date): string {
220
+ return formatDateForXml(date);
221
+ }
222
+
223
+ /**
224
+ * Generates XML for the comment range start marker
225
+ * This goes in word/document.xml at the start of the commented range
226
+ */
227
+ toRangeStartXML(): XMLElement {
228
+ return {
229
+ name: 'w:commentRangeStart',
230
+ attributes: {
231
+ 'w:id': this.id.toString(),
232
+ },
233
+ selfClosing: true,
234
+ };
235
+ }
236
+
237
+ /**
238
+ * Generates XML for the comment range end marker
239
+ * This goes in word/document.xml at the end of the commented range
240
+ */
241
+ toRangeEndXML(): XMLElement {
242
+ return {
243
+ name: 'w:commentRangeEnd',
244
+ attributes: {
245
+ 'w:id': this.id.toString(),
246
+ },
247
+ selfClosing: true,
248
+ };
249
+ }
250
+
251
+ /**
252
+ * Generates XML for the comment reference
253
+ * This goes in word/document.xml after the range end, inside a run
254
+ */
255
+ toReferenceXML(): XMLElement {
256
+ return {
257
+ name: 'w:r',
258
+ children: [
259
+ {
260
+ name: 'w:commentReference',
261
+ attributes: {
262
+ 'w:id': this.id.toString(),
263
+ },
264
+ selfClosing: true,
265
+ },
266
+ ],
267
+ };
268
+ }
269
+
270
+ /**
271
+ * Generates XML for the comment definition
272
+ * This goes in word/comments.xml
273
+ */
274
+ toXML(): XMLElement {
275
+ const attributes: Record<string, string> = {
276
+ 'w:id': this.id.toString(),
277
+ 'w:author': this.author,
278
+ 'w:date': this.formatDate(this.date),
279
+ 'w:initials': this.initials,
280
+ };
281
+
282
+ // Add parent ID for replies (w15 namespace per Office 2012 extensions)
283
+ if (this.parentId !== undefined) {
284
+ attributes['w15:parentId'] = this.parentId.toString();
285
+ }
286
+
287
+ // Add done attribute for resolved comments (per ECMA-376)
288
+ if (this.done) {
289
+ attributes['w:done'] = '1';
290
+ }
291
+
292
+ // Create paragraph containing the comment content
293
+ const commentParagraph: XMLElement = {
294
+ name: 'w:p',
295
+ children: this.runs.map((run) => run.toXML()),
296
+ };
297
+
298
+ return {
299
+ name: 'w:comment',
300
+ attributes,
301
+ children: [commentParagraph],
302
+ };
303
+ }
304
+
305
+ /**
306
+ * Creates a new comment
307
+ * @param author - Comment author
308
+ * @param content - Comment content (text or runs)
309
+ * @param initials - Optional author initials
310
+ * @returns New Comment instance
311
+ */
312
+ static create(author: string, content: string | Run | Run[], initials?: string): Comment {
313
+ return new Comment({
314
+ author,
315
+ content,
316
+ initials,
317
+ });
318
+ }
319
+
320
+ /**
321
+ * Creates a reply to an existing comment
322
+ * @param parentId - ID of the parent comment
323
+ * @param author - Reply author
324
+ * @param content - Reply content (text or runs)
325
+ * @param initials - Optional author initials
326
+ * @returns New Comment instance (reply)
327
+ */
328
+ static createReply(
329
+ parentId: number,
330
+ author: string,
331
+ content: string | Run | Run[],
332
+ initials?: string
333
+ ): Comment {
334
+ return new Comment({
335
+ author,
336
+ content,
337
+ initials,
338
+ parentId,
339
+ });
340
+ }
341
+
342
+ /**
343
+ * Creates a comment with formatted content
344
+ * @param author - Comment author
345
+ * @param runs - Array of formatted runs
346
+ * @param initials - Optional author initials
347
+ * @returns New Comment instance
348
+ */
349
+ static createFormatted(author: string, runs: Run[], initials?: string): Comment {
350
+ return new Comment({
351
+ author,
352
+ content: runs,
353
+ initials,
354
+ });
355
+ }
356
+ }