docxmlater 11.0.10 → 12.1.0

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 (361) hide show
  1. package/README.md +53 -13
  2. package/dist/core/Document.d.ts +29 -3
  3. package/dist/core/Document.d.ts.map +1 -1
  4. package/dist/core/Document.js +733 -170
  5. package/dist/core/Document.js.map +1 -1
  6. package/dist/core/DocumentGenerator.d.ts +1 -0
  7. package/dist/core/DocumentGenerator.d.ts.map +1 -1
  8. package/dist/core/DocumentGenerator.js +77 -25
  9. package/dist/core/DocumentGenerator.js.map +1 -1
  10. package/dist/core/DocumentParser.d.ts +7 -3
  11. package/dist/core/DocumentParser.d.ts.map +1 -1
  12. package/dist/core/DocumentParser.js +427 -81
  13. package/dist/core/DocumentParser.js.map +1 -1
  14. package/dist/core/RelationshipManager.d.ts.map +1 -1
  15. package/dist/core/RelationshipManager.js +2 -2
  16. package/dist/core/RelationshipManager.js.map +1 -1
  17. package/dist/elements/Comment.d.ts +15 -1
  18. package/dist/elements/Comment.d.ts.map +1 -1
  19. package/dist/elements/Comment.js +67 -12
  20. package/dist/elements/Comment.js.map +1 -1
  21. package/dist/elements/CommentManager.d.ts +4 -0
  22. package/dist/elements/CommentManager.d.ts.map +1 -1
  23. package/dist/elements/CommentManager.js +74 -16
  24. package/dist/elements/CommentManager.js.map +1 -1
  25. package/dist/elements/EndnoteManager.d.ts.map +1 -1
  26. package/dist/elements/EndnoteManager.js.map +1 -1
  27. package/dist/elements/Field.d.ts +10 -1
  28. package/dist/elements/Field.d.ts.map +1 -1
  29. package/dist/elements/Field.js +76 -34
  30. package/dist/elements/Field.js.map +1 -1
  31. package/dist/elements/FieldHelpers.d.ts +1 -0
  32. package/dist/elements/FieldHelpers.d.ts.map +1 -1
  33. package/dist/elements/FieldHelpers.js +8 -4
  34. package/dist/elements/FieldHelpers.js.map +1 -1
  35. package/dist/elements/Footer.d.ts +3 -1
  36. package/dist/elements/Footer.d.ts.map +1 -1
  37. package/dist/elements/Footer.js +39 -53
  38. package/dist/elements/Footer.js.map +1 -1
  39. package/dist/elements/FootnoteManager.d.ts.map +1 -1
  40. package/dist/elements/FootnoteManager.js.map +1 -1
  41. package/dist/elements/Header.d.ts +3 -1
  42. package/dist/elements/Header.d.ts.map +1 -1
  43. package/dist/elements/Header.js +39 -53
  44. package/dist/elements/Header.js.map +1 -1
  45. package/dist/elements/HeaderFooterManager.d.ts +4 -2
  46. package/dist/elements/HeaderFooterManager.d.ts.map +1 -1
  47. package/dist/elements/HeaderFooterManager.js +36 -6
  48. package/dist/elements/HeaderFooterManager.js.map +1 -1
  49. package/dist/elements/Hyperlink.d.ts +6 -1
  50. package/dist/elements/Hyperlink.d.ts.map +1 -1
  51. package/dist/elements/Hyperlink.js +69 -44
  52. package/dist/elements/Hyperlink.js.map +1 -1
  53. package/dist/elements/Image.d.ts.map +1 -1
  54. package/dist/elements/Image.js +33 -6
  55. package/dist/elements/Image.js.map +1 -1
  56. package/dist/elements/ImageManager.d.ts +1 -0
  57. package/dist/elements/ImageManager.d.ts.map +1 -1
  58. package/dist/elements/ImageManager.js +11 -0
  59. package/dist/elements/ImageManager.js.map +1 -1
  60. package/dist/elements/Paragraph.d.ts +3 -0
  61. package/dist/elements/Paragraph.d.ts.map +1 -1
  62. package/dist/elements/Paragraph.js +91 -26
  63. package/dist/elements/Paragraph.js.map +1 -1
  64. package/dist/elements/Revision.d.ts +4 -0
  65. package/dist/elements/Revision.d.ts.map +1 -1
  66. package/dist/elements/Revision.js +369 -29
  67. package/dist/elements/Revision.js.map +1 -1
  68. package/dist/elements/Run.d.ts +1 -0
  69. package/dist/elements/Run.d.ts.map +1 -1
  70. package/dist/elements/Run.js +24 -4
  71. package/dist/elements/Run.js.map +1 -1
  72. package/dist/elements/Section.d.ts.map +1 -1
  73. package/dist/elements/Section.js +17 -7
  74. package/dist/elements/Section.js.map +1 -1
  75. package/dist/elements/Shape.d.ts.map +1 -1
  76. package/dist/elements/Shape.js +50 -42
  77. package/dist/elements/Shape.js.map +1 -1
  78. package/dist/elements/StructuredDocumentTag.d.ts +9 -1
  79. package/dist/elements/StructuredDocumentTag.d.ts.map +1 -1
  80. package/dist/elements/StructuredDocumentTag.js +46 -6
  81. package/dist/elements/StructuredDocumentTag.js.map +1 -1
  82. package/dist/elements/Table.d.ts +2 -0
  83. package/dist/elements/Table.d.ts.map +1 -1
  84. package/dist/elements/Table.js +90 -42
  85. package/dist/elements/Table.js.map +1 -1
  86. package/dist/elements/TableCell.d.ts +1 -0
  87. package/dist/elements/TableCell.d.ts.map +1 -1
  88. package/dist/elements/TableCell.js +32 -13
  89. package/dist/elements/TableCell.js.map +1 -1
  90. package/dist/elements/TableOfContents.d.ts.map +1 -1
  91. package/dist/elements/TableOfContents.js +5 -7
  92. package/dist/elements/TableOfContents.js.map +1 -1
  93. package/dist/elements/TableRow.d.ts +1 -0
  94. package/dist/elements/TableRow.d.ts.map +1 -1
  95. package/dist/elements/TableRow.js +16 -1
  96. package/dist/elements/TableRow.js.map +1 -1
  97. package/dist/elements/TextBox.d.ts.map +1 -1
  98. package/dist/elements/TextBox.js +55 -42
  99. package/dist/elements/TextBox.js.map +1 -1
  100. package/dist/esm/core/Document.js +735 -172
  101. package/dist/esm/core/Document.js.map +1 -1
  102. package/dist/esm/core/DocumentGenerator.js +77 -25
  103. package/dist/esm/core/DocumentGenerator.js.map +1 -1
  104. package/dist/esm/core/DocumentParser.js +427 -81
  105. package/dist/esm/core/DocumentParser.js.map +1 -1
  106. package/dist/esm/core/RelationshipManager.js +2 -2
  107. package/dist/esm/core/RelationshipManager.js.map +1 -1
  108. package/dist/esm/elements/Comment.js +67 -12
  109. package/dist/esm/elements/Comment.js.map +1 -1
  110. package/dist/esm/elements/CommentManager.js +74 -16
  111. package/dist/esm/elements/CommentManager.js.map +1 -1
  112. package/dist/esm/elements/EndnoteManager.js.map +1 -1
  113. package/dist/esm/elements/Field.js +77 -35
  114. package/dist/esm/elements/Field.js.map +1 -1
  115. package/dist/esm/elements/FieldHelpers.js +7 -4
  116. package/dist/esm/elements/FieldHelpers.js.map +1 -1
  117. package/dist/esm/elements/Footer.js +39 -53
  118. package/dist/esm/elements/Footer.js.map +1 -1
  119. package/dist/esm/elements/FootnoteManager.js.map +1 -1
  120. package/dist/esm/elements/Header.js +39 -53
  121. package/dist/esm/elements/Header.js.map +1 -1
  122. package/dist/esm/elements/HeaderFooterManager.js +36 -6
  123. package/dist/esm/elements/HeaderFooterManager.js.map +1 -1
  124. package/dist/esm/elements/Hyperlink.js +69 -44
  125. package/dist/esm/elements/Hyperlink.js.map +1 -1
  126. package/dist/esm/elements/Image.js +33 -6
  127. package/dist/esm/elements/Image.js.map +1 -1
  128. package/dist/esm/elements/ImageManager.js +11 -0
  129. package/dist/esm/elements/ImageManager.js.map +1 -1
  130. package/dist/esm/elements/Paragraph.js +91 -26
  131. package/dist/esm/elements/Paragraph.js.map +1 -1
  132. package/dist/esm/elements/Revision.js +369 -29
  133. package/dist/esm/elements/Revision.js.map +1 -1
  134. package/dist/esm/elements/Run.js +24 -4
  135. package/dist/esm/elements/Run.js.map +1 -1
  136. package/dist/esm/elements/Section.js +17 -7
  137. package/dist/esm/elements/Section.js.map +1 -1
  138. package/dist/esm/elements/Shape.js +50 -42
  139. package/dist/esm/elements/Shape.js.map +1 -1
  140. package/dist/esm/elements/StructuredDocumentTag.js +46 -6
  141. package/dist/esm/elements/StructuredDocumentTag.js.map +1 -1
  142. package/dist/esm/elements/Table.js +90 -42
  143. package/dist/esm/elements/Table.js.map +1 -1
  144. package/dist/esm/elements/TableCell.js +32 -13
  145. package/dist/esm/elements/TableCell.js.map +1 -1
  146. package/dist/esm/elements/TableOfContents.js +5 -7
  147. package/dist/esm/elements/TableOfContents.js.map +1 -1
  148. package/dist/esm/elements/TableRow.js +16 -1
  149. package/dist/esm/elements/TableRow.js.map +1 -1
  150. package/dist/esm/elements/TextBox.js +55 -42
  151. package/dist/esm/elements/TextBox.js.map +1 -1
  152. package/dist/esm/formatting/AbstractNumbering.js +1 -1
  153. package/dist/esm/formatting/AbstractNumbering.js.map +1 -1
  154. package/dist/esm/formatting/NumberingLevel.js +8 -6
  155. package/dist/esm/formatting/NumberingLevel.js.map +1 -1
  156. package/dist/esm/formatting/NumberingManager.js +16 -1
  157. package/dist/esm/formatting/NumberingManager.js.map +1 -1
  158. package/dist/esm/formatting/Style.js +14 -0
  159. package/dist/esm/formatting/Style.js.map +1 -1
  160. package/dist/esm/formatting/StylesManager.js +14 -2
  161. package/dist/esm/formatting/StylesManager.js.map +1 -1
  162. package/dist/esm/helpers/CleanupHelper.js +103 -26
  163. package/dist/esm/helpers/CleanupHelper.js.map +1 -1
  164. package/dist/esm/images/ImageOptimizer.js +52 -4
  165. package/dist/esm/images/ImageOptimizer.js.map +1 -1
  166. package/dist/esm/index.js +1 -0
  167. package/dist/esm/index.js.map +1 -1
  168. package/dist/esm/internal.js +1 -1
  169. package/dist/esm/internal.js.map +1 -1
  170. package/dist/esm/processors/CompatibilityUpgrader.js +7 -1
  171. package/dist/esm/processors/CompatibilityUpgrader.js.map +1 -1
  172. package/dist/esm/processors/InMemoryRevisionAcceptor.js +134 -13
  173. package/dist/esm/processors/InMemoryRevisionAcceptor.js.map +1 -1
  174. package/dist/esm/processors/RevisionWalker.js +223 -39
  175. package/dist/esm/processors/RevisionWalker.js.map +1 -1
  176. package/dist/esm/processors/SelectiveRevisionAcceptor.js +116 -17
  177. package/dist/esm/processors/SelectiveRevisionAcceptor.js.map +1 -1
  178. package/dist/esm/processors/acceptRevisions.js +20 -11
  179. package/dist/esm/processors/acceptRevisions.js.map +1 -1
  180. package/dist/esm/processors/cnfStyleDecoder.js +7 -7
  181. package/dist/esm/processors/cnfStyleDecoder.js.map +1 -1
  182. package/dist/esm/processors/stripTrackedChanges.js +16 -5
  183. package/dist/esm/processors/stripTrackedChanges.js.map +1 -1
  184. package/dist/esm/utils/deepClone.js +24 -11
  185. package/dist/esm/utils/deepClone.js.map +1 -1
  186. package/dist/esm/utils/units.js +1 -1
  187. package/dist/esm/utils/units.js.map +1 -1
  188. package/dist/esm/utils/validation.js +11 -23
  189. package/dist/esm/utils/validation.js.map +1 -1
  190. package/dist/esm/utils/xmlSanitization.js +131 -7
  191. package/dist/esm/utils/xmlSanitization.js.map +1 -1
  192. package/dist/esm/validation/RevisionAutoFixer.js +69 -55
  193. package/dist/esm/validation/RevisionAutoFixer.js.map +1 -1
  194. package/dist/esm/validation/RevisionValidator.js +24 -20
  195. package/dist/esm/validation/RevisionValidator.js.map +1 -1
  196. package/dist/esm/xml/XMLBuilder.js +52 -20
  197. package/dist/esm/xml/XMLBuilder.js.map +1 -1
  198. package/dist/esm/xml/XMLParser.js +55 -13
  199. package/dist/esm/xml/XMLParser.js.map +1 -1
  200. package/dist/esm/zip/ZipHandler.js +37 -13
  201. package/dist/esm/zip/ZipHandler.js.map +1 -1
  202. package/dist/esm/zip/ZipReader.js +53 -6
  203. package/dist/esm/zip/ZipReader.js.map +1 -1
  204. package/dist/esm/zip/errors.js +7 -0
  205. package/dist/esm/zip/errors.js.map +1 -1
  206. package/dist/esm/zip/types.js +4 -0
  207. package/dist/esm/zip/types.js.map +1 -1
  208. package/dist/formatting/AbstractNumbering.d.ts.map +1 -1
  209. package/dist/formatting/AbstractNumbering.js +1 -1
  210. package/dist/formatting/AbstractNumbering.js.map +1 -1
  211. package/dist/formatting/NumberingLevel.d.ts +1 -1
  212. package/dist/formatting/NumberingLevel.d.ts.map +1 -1
  213. package/dist/formatting/NumberingLevel.js +8 -6
  214. package/dist/formatting/NumberingLevel.js.map +1 -1
  215. package/dist/formatting/NumberingManager.d.ts.map +1 -1
  216. package/dist/formatting/NumberingManager.js +16 -1
  217. package/dist/formatting/NumberingManager.js.map +1 -1
  218. package/dist/formatting/Style.d.ts.map +1 -1
  219. package/dist/formatting/Style.js +14 -0
  220. package/dist/formatting/Style.js.map +1 -1
  221. package/dist/formatting/StylesManager.d.ts +2 -0
  222. package/dist/formatting/StylesManager.d.ts.map +1 -1
  223. package/dist/formatting/StylesManager.js +14 -2
  224. package/dist/formatting/StylesManager.js.map +1 -1
  225. package/dist/helpers/CleanupHelper.d.ts.map +1 -1
  226. package/dist/helpers/CleanupHelper.js +103 -26
  227. package/dist/helpers/CleanupHelper.js.map +1 -1
  228. package/dist/images/ImageOptimizer.d.ts.map +1 -1
  229. package/dist/images/ImageOptimizer.js +52 -4
  230. package/dist/images/ImageOptimizer.js.map +1 -1
  231. package/dist/index.d.ts +3 -1
  232. package/dist/index.d.ts.map +1 -1
  233. package/dist/index.js +4 -2
  234. package/dist/index.js.map +1 -1
  235. package/dist/internal.d.ts +1 -1
  236. package/dist/internal.d.ts.map +1 -1
  237. package/dist/internal.js +2 -1
  238. package/dist/internal.js.map +1 -1
  239. package/dist/processors/CompatibilityUpgrader.d.ts.map +1 -1
  240. package/dist/processors/CompatibilityUpgrader.js +7 -1
  241. package/dist/processors/CompatibilityUpgrader.js.map +1 -1
  242. package/dist/processors/InMemoryRevisionAcceptor.d.ts +1 -0
  243. package/dist/processors/InMemoryRevisionAcceptor.d.ts.map +1 -1
  244. package/dist/processors/InMemoryRevisionAcceptor.js +135 -13
  245. package/dist/processors/InMemoryRevisionAcceptor.js.map +1 -1
  246. package/dist/processors/RevisionWalker.d.ts +9 -3
  247. package/dist/processors/RevisionWalker.d.ts.map +1 -1
  248. package/dist/processors/RevisionWalker.js +223 -39
  249. package/dist/processors/RevisionWalker.js.map +1 -1
  250. package/dist/processors/SelectiveRevisionAcceptor.d.ts.map +1 -1
  251. package/dist/processors/SelectiveRevisionAcceptor.js +116 -17
  252. package/dist/processors/SelectiveRevisionAcceptor.js.map +1 -1
  253. package/dist/processors/acceptRevisions.d.ts +1 -0
  254. package/dist/processors/acceptRevisions.d.ts.map +1 -1
  255. package/dist/processors/acceptRevisions.js +21 -11
  256. package/dist/processors/acceptRevisions.js.map +1 -1
  257. package/dist/processors/cnfStyleDecoder.d.ts.map +1 -1
  258. package/dist/processors/cnfStyleDecoder.js +7 -7
  259. package/dist/processors/cnfStyleDecoder.js.map +1 -1
  260. package/dist/processors/stripTrackedChanges.d.ts.map +1 -1
  261. package/dist/processors/stripTrackedChanges.js +16 -5
  262. package/dist/processors/stripTrackedChanges.js.map +1 -1
  263. package/dist/utils/deepClone.d.ts.map +1 -1
  264. package/dist/utils/deepClone.js +24 -11
  265. package/dist/utils/deepClone.js.map +1 -1
  266. package/dist/utils/units.d.ts.map +1 -1
  267. package/dist/utils/units.js +1 -1
  268. package/dist/utils/units.js.map +1 -1
  269. package/dist/utils/validation.d.ts.map +1 -1
  270. package/dist/utils/validation.js +11 -23
  271. package/dist/utils/validation.js.map +1 -1
  272. package/dist/utils/xmlSanitization.d.ts +2 -0
  273. package/dist/utils/xmlSanitization.d.ts.map +1 -1
  274. package/dist/utils/xmlSanitization.js +133 -7
  275. package/dist/utils/xmlSanitization.js.map +1 -1
  276. package/dist/validation/RevisionAutoFixer.d.ts +6 -2
  277. package/dist/validation/RevisionAutoFixer.d.ts.map +1 -1
  278. package/dist/validation/RevisionAutoFixer.js +68 -54
  279. package/dist/validation/RevisionAutoFixer.js.map +1 -1
  280. package/dist/validation/RevisionValidator.d.ts +2 -0
  281. package/dist/validation/RevisionValidator.d.ts.map +1 -1
  282. package/dist/validation/RevisionValidator.js +26 -21
  283. package/dist/validation/RevisionValidator.js.map +1 -1
  284. package/dist/xml/XMLBuilder.d.ts +1 -0
  285. package/dist/xml/XMLBuilder.d.ts.map +1 -1
  286. package/dist/xml/XMLBuilder.js +52 -20
  287. package/dist/xml/XMLBuilder.js.map +1 -1
  288. package/dist/xml/XMLParser.d.ts +1 -0
  289. package/dist/xml/XMLParser.d.ts.map +1 -1
  290. package/dist/xml/XMLParser.js +55 -13
  291. package/dist/xml/XMLParser.js.map +1 -1
  292. package/dist/zip/ZipHandler.d.ts.map +1 -1
  293. package/dist/zip/ZipHandler.js +37 -13
  294. package/dist/zip/ZipHandler.js.map +1 -1
  295. package/dist/zip/ZipReader.d.ts.map +1 -1
  296. package/dist/zip/ZipReader.js +52 -5
  297. package/dist/zip/ZipReader.js.map +1 -1
  298. package/dist/zip/errors.d.ts +3 -0
  299. package/dist/zip/errors.d.ts.map +1 -1
  300. package/dist/zip/errors.js +9 -1
  301. package/dist/zip/errors.js.map +1 -1
  302. package/dist/zip/types.d.ts +4 -0
  303. package/dist/zip/types.d.ts.map +1 -1
  304. package/dist/zip/types.js +4 -0
  305. package/dist/zip/types.js.map +1 -1
  306. package/package.json +2 -2
  307. package/src/core/Document.ts +1184 -242
  308. package/src/core/DocumentGenerator.ts +106 -26
  309. package/src/core/DocumentParser.ts +681 -114
  310. package/src/core/RelationshipManager.ts +446 -442
  311. package/src/elements/Comment.ts +123 -18
  312. package/src/elements/CommentManager.ts +121 -22
  313. package/src/elements/EndnoteManager.ts +4 -1
  314. package/src/elements/Field.ts +134 -43
  315. package/src/elements/FieldHelpers.ts +20 -4
  316. package/src/elements/Footer.ts +62 -67
  317. package/src/elements/FootnoteManager.ts +4 -1
  318. package/src/elements/Header.ts +62 -67
  319. package/src/elements/HeaderFooterManager.ts +56 -8
  320. package/src/elements/Hyperlink.ts +150 -55
  321. package/src/elements/Image.ts +51 -7
  322. package/src/elements/ImageManager.ts +24 -0
  323. package/src/elements/Paragraph.ts +161 -40
  324. package/src/elements/Revision.ts +446 -47
  325. package/src/elements/Run.ts +44 -6
  326. package/src/elements/Section.ts +25 -9
  327. package/src/elements/Shape.ts +52 -44
  328. package/src/elements/StructuredDocumentTag.ts +83 -8
  329. package/src/elements/Table.ts +151 -50
  330. package/src/elements/TableCell.ts +57 -17
  331. package/src/elements/TableOfContents.ts +10 -9
  332. package/src/elements/TableRow.ts +35 -3
  333. package/src/elements/TextBox.ts +58 -43
  334. package/src/formatting/AbstractNumbering.ts +4 -2
  335. package/src/formatting/NumberingLevel.ts +50 -12
  336. package/src/formatting/NumberingManager.ts +32 -3
  337. package/src/formatting/Style.ts +14 -0
  338. package/src/formatting/StylesManager.ts +29 -2
  339. package/src/helpers/CleanupHelper.ts +122 -30
  340. package/src/images/ImageOptimizer.ts +64 -5
  341. package/src/index.ts +7 -0
  342. package/src/internal.ts +1 -0
  343. package/src/processors/CompatibilityUpgrader.ts +15 -2
  344. package/src/processors/InMemoryRevisionAcceptor.ts +276 -17
  345. package/src/processors/RevisionWalker.ts +390 -46
  346. package/src/processors/SelectiveRevisionAcceptor.ts +164 -28
  347. package/src/processors/acceptRevisions.ts +67 -17
  348. package/src/processors/cnfStyleDecoder.ts +18 -12
  349. package/src/processors/stripTrackedChanges.ts +47 -10
  350. package/src/utils/deepClone.ts +48 -14
  351. package/src/utils/units.ts +3 -1
  352. package/src/utils/validation.ts +30 -32
  353. package/src/utils/xmlSanitization.ts +218 -22
  354. package/src/validation/RevisionAutoFixer.ts +109 -65
  355. package/src/validation/RevisionValidator.ts +48 -23
  356. package/src/xml/XMLBuilder.ts +82 -22
  357. package/src/xml/XMLParser.ts +87 -20
  358. package/src/zip/ZipHandler.ts +61 -21
  359. package/src/zip/ZipReader.ts +135 -13
  360. package/src/zip/errors.ts +15 -0
  361. package/src/zip/types.ts +44 -2
@@ -168,8 +168,8 @@ export class RelationshipManager {
168
168
  throw new CorruptedArchiveError('Relationships XML file too large (>10MB). Possible malicious input or corrupted file.');
169
169
  }
170
170
  const relationshipElements = XMLParser.extractElements(xml, 'Relationship');
171
- if (relationshipElements.length > 1000) {
172
- throw new CorruptedArchiveError('Too many relationships in XML file (>1000). Possible malicious input.');
171
+ if (relationshipElements.length > 100000) {
172
+ throw new CorruptedArchiveError('Too many relationships in XML file (>100000). Possible malicious input or corrupted file.');
173
173
  }
174
174
  for (const relationshipElement of relationshipElements) {
175
175
  const id = XMLParser.extractAttribute(relationshipElement, 'Id');
@@ -1 +1 @@
1
- {"version":3,"file":"RelationshipManager.js","sourceRoot":"","sources":["../../../src/core/RelationshipManager.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AACnE,OAAO,EAA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CAAC,CAAC,SAAS,CAAC;gBAGhB,IAAI,eAAe,GAAG,MAAM,CAAC;gBAC7B,IAAI,IAAI,CAAC,QAAQ,CAAC,YAAY,CAAC,EAAE,CAAC;oBAChC,MAAM,MAAM,GAAG,oBAAoB,CAAC,MAAM,CAAC,CAAC;oBAC5C,IAAI,MAAM,EAAE,CAAC;wBACX,eAAe,GAAG,MAAM,CAAC,GAAG,CAAC;oBAC/B,CAAC;gBACH,CAAC;gBAGD,MAAM,YAAY,GAAG,YAAY,CAAC,MAAM,CAAC;oBACvC,EAAE;oBACF,IAAI;oBACJ,MAAM,EAAE,eAAe;oBACvB,UAAU,EAAE,mBAAmB,IAAI,UAAU;iBAC9C,CAAC,CAAC;gBAEH,OAAO,CAAC,eAAe,CAAC,YAAY,CAAC,CAAC;YACxC,CAAC;QACH,CAAC;QAED,OAAO,OAAO,CAAC;IACjB,CAAC;CACF","sourcesContent":["/**\n * RelationshipManager - Manages collections of relationships\n *\n * Handles relationship creation, tracking, and XML generation for various\n * document parts (document.xml, header.xml, footer.xml, etc.)\n */\n\nimport { Relationship, RelationshipType } from './Relationship.js';\nimport { XMLParser } from '../xml/XMLParser.js';\nimport { sanitizeHyperlinkUrl } from '../utils/validation.js';\nimport { InvalidDocxError, CorruptedArchiveError } from '../zip/errors.js';\n\n/**\n * Manages relationships for a document or document part\n */\nexport class RelationshipManager {\n private relationships: Map<string, Relationship>;\n private nextId: number;\n\n /**\n * Creates a new relationship manager\n */\n constructor() {\n this.relationships = new Map();\n this.nextId = 1;\n }\n\n /**\n * Adds a relationship\n * @param relationship The relationship to add\n * @returns The relationship that was added\n */\n addRelationship(relationship: Relationship): Relationship {\n this.relationships.set(relationship.getId(), relationship);\n\n // Update next ID if necessary\n const idMatch = /^rId(\\d+)$/.exec(relationship.getId());\n if (idMatch?.[1]) {\n const idNum = parseInt(idMatch[1], 10);\n if (idNum >= this.nextId) {\n this.nextId = idNum + 1;\n }\n }\n\n return relationship;\n }\n\n /**\n * Gets a relationship by ID\n * @param id The relationship ID\n */\n getRelationship(id: string): Relationship | undefined {\n return this.relationships.get(id);\n }\n\n /**\n * Gets all relationships\n */\n getAllRelationships(): Relationship[] {\n return Array.from(this.relationships.values());\n }\n\n /**\n * Gets relationships of a specific type\n * @param type The relationship type\n */\n getRelationshipsByType(type: string | RelationshipType): Relationship[] {\n return this.getAllRelationships().filter((rel) => rel.getType() === type);\n }\n\n /**\n * Checks if a relationship exists\n * @param id The relationship ID\n */\n hasRelationship(id: string): boolean {\n return this.relationships.has(id);\n }\n\n /**\n * Removes a relationship\n * @param id The relationship ID\n * @returns True if removed, false if not found\n */\n removeRelationship(id: string): boolean {\n return this.relationships.delete(id);\n }\n\n /**\n * Gets the number of relationships\n */\n getCount(): number {\n return this.relationships.size;\n }\n\n /**\n * Clears all relationships\n */\n clear(): this {\n this.relationships.clear();\n this.nextId = 1;\n return this;\n }\n\n /**\n * Generates a new unique relationship ID\n * @returns New relationship ID (e.g., 'rId1', 'rId2')\n */\n generateId(): string {\n return `rId${this.nextId++}`;\n }\n\n /**\n * Adds a styles relationship\n * @returns The created relationship\n */\n addStyles(): Relationship {\n const id = this.generateId();\n return this.addRelationship(Relationship.createStyles(id));\n }\n\n /**\n * Adds a numbering relationship\n * @returns The created relationship\n */\n addNumbering(): Relationship {\n const id = this.generateId();\n return this.addRelationship(Relationship.createNumbering(id));\n }\n\n /**\n * Adds a fontTable relationship\n * @returns The created relationship\n */\n addFontTable(): Relationship {\n const id = this.generateId();\n return this.addRelationship(Relationship.createFontTable(id));\n }\n\n /**\n * Adds a settings relationship\n * @returns The created relationship\n */\n addSettings(): Relationship {\n const id = this.generateId();\n return this.addRelationship(Relationship.createSettings(id));\n }\n\n /**\n * Adds a webSettings relationship\n * @returns The created relationship\n */\n addWebSettings(): Relationship {\n const id = this.generateId();\n return this.addRelationship(Relationship.createWebSettings(id));\n }\n\n /**\n * Adds a theme relationship\n * @returns The created relationship\n */\n addTheme(): Relationship {\n const id = this.generateId();\n return this.addRelationship(Relationship.createTheme(id));\n }\n\n /**\n * Adds an image relationship\n * @param target Image path relative to the part (e.g., 'media/image1.png')\n * @returns The created relationship\n */\n addImage(target: string): Relationship {\n const id = this.generateId();\n return this.addRelationship(Relationship.createImage(id, target));\n }\n\n /**\n * Adds a header relationship\n * @param target Header file path (e.g., 'header1.xml')\n * @returns The created relationship\n */\n addHeader(target: string): Relationship {\n const id = this.generateId();\n return this.addRelationship(Relationship.createHeader(id, target));\n }\n\n /**\n * Adds a footer relationship\n * @param target Footer file path (e.g., 'footer1.xml')\n * @returns The created relationship\n */\n addFooter(target: string): Relationship {\n const id = this.generateId();\n return this.addRelationship(Relationship.createFooter(id, target));\n }\n\n /**\n * Adds a hyperlink relationship\n * @param url The hyperlink URL\n * @returns The created relationship\n */\n addHyperlink(url: string): Relationship {\n const id = this.generateId();\n return this.addRelationship(Relationship.createHyperlink(id, url));\n }\n\n /**\n * Updates the target URL of an existing hyperlink relationship\n *\n * This method modifies an existing relationship's target in-place, maintaining\n * the same relationship ID. This is crucial for proper OpenXML compliance\n * per ECMA-376 §17.16.22, as it prevents orphaned relationships.\n *\n * @param relationshipId The ID of the relationship to update\n * @param newUrl The new URL to set\n * @returns True if updated, false if relationship not found\n */\n updateHyperlinkTarget(relationshipId: string, newUrl: string): boolean {\n const relationship = this.getRelationship(relationshipId);\n if (!relationship) {\n return false;\n }\n\n // Verify this is a hyperlink relationship\n if (relationship.getType() !== RelationshipType.HYPERLINK) {\n throw new InvalidDocxError(\n `Relationship ${relationshipId} is not a hyperlink relationship. ` +\n `Type is ${relationship.getType()}, expected ${RelationshipType.HYPERLINK}`\n );\n }\n\n // Update the target URL\n relationship.setTarget(newUrl);\n return true;\n }\n\n /**\n * Finds a hyperlink relationship by its target URL\n *\n * @param targetUrl The URL to search for\n * @returns The matching relationship, or undefined if not found\n */\n findHyperlinkByTarget(targetUrl: string): Relationship | undefined {\n return this.getAllRelationships().find(\n (rel) => rel.getType() === RelationshipType.HYPERLINK && rel.getTarget() === targetUrl\n );\n }\n\n /**\n * Gets or creates a hyperlink relationship for the given URL\n *\n * This method ensures we don't create duplicate relationships for the same URL.\n * If a relationship already exists for the URL, it returns the existing one.\n * Otherwise, it creates a new relationship.\n *\n * @param url The hyperlink URL\n * @returns The existing or newly created relationship\n */\n getOrCreateHyperlink(url: string): Relationship {\n // Check if relationship already exists for this URL\n const existing = this.findHyperlinkByTarget(url);\n if (existing) {\n return existing;\n }\n\n // Create new relationship\n return this.addHyperlink(url);\n }\n\n /**\n * Removes orphaned hyperlink relationships\n *\n * This method removes hyperlink relationships that are no longer referenced\n * by any hyperlink in the document. Call this after updating URLs to clean\n * up any orphaned relationships.\n *\n * @param referencedIds Set of relationship IDs that are still in use\n * @returns Number of relationships removed\n */\n removeOrphanedHyperlinks(referencedIds: Set<string>): number {\n let removed = 0;\n const toRemove: string[] = [];\n\n // Find orphaned relationships\n for (const rel of this.getAllRelationships()) {\n if (rel.getType() === RelationshipType.HYPERLINK && !referencedIds.has(rel.getId())) {\n toRemove.push(rel.getId());\n }\n }\n\n // Remove orphaned relationships\n for (const id of toRemove) {\n if (this.removeRelationship(id)) {\n removed++;\n }\n }\n\n return removed;\n }\n\n /**\n * Adds a comments relationship\n * @returns The created relationship\n */\n addComments(): Relationship {\n const id = this.generateId();\n return this.addRelationship(Relationship.createComments(id));\n }\n\n /**\n * Adds a footnotes relationship\n * @returns The created relationship\n */\n addFootnotes(): Relationship {\n const id = this.generateId();\n return this.addRelationship(Relationship.createFootnotes(id));\n }\n\n /**\n * Adds an endnotes relationship\n * @returns The created relationship\n */\n addEndnotes(): Relationship {\n const id = this.generateId();\n return this.addRelationship(Relationship.createEndnotes(id));\n }\n\n /**\n * Adds a people relationship (track changes authors)\n * @returns The created relationship\n */\n addPeople(): Relationship {\n const id = this.generateId();\n return this.addRelationship(Relationship.createPeople(id));\n }\n\n /**\n * Generates the relationships XML file content\n * @returns Complete XML string for .rels file\n */\n generateXml(): string {\n const relationships = this.getAllRelationships();\n\n let xml = '<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\\n';\n xml += '<Relationships xmlns=\"http://schemas.openxmlformats.org/package/2006/relationships\">\\n';\n\n for (const rel of relationships) {\n xml += rel.toXML() + '\\n';\n }\n\n xml += '</Relationships>';\n\n return xml;\n }\n\n /**\n * Creates a new relationship manager with common document relationships\n * @returns RelationshipManager with styles, numbering, fontTable, settings, and theme relationships\n */\n static createForDocument(): RelationshipManager {\n const manager = new RelationshipManager();\n manager.addStyles();\n manager.addNumbering();\n manager.addFontTable();\n manager.addSettings();\n manager.addWebSettings();\n manager.addTheme();\n return manager;\n }\n\n /**\n * Creates an empty relationship manager\n * @returns Empty RelationshipManager\n */\n static create(): RelationshipManager {\n return new RelationshipManager();\n }\n\n /**\n * Parses relationships from XML string and creates a populated manager\n * @param xml The relationships XML content (.rels file)\n * @returns RelationshipManager with parsed relationships\n */\n static fromXml(xml: string): RelationshipManager {\n const manager = new RelationshipManager();\n\n // Prevent ReDoS: validate input size (typical .rels files are < 10KB, max 10MB)\n if (xml.length > 10000000) {\n throw new CorruptedArchiveError(\n 'Relationships XML file too large (>10MB). Possible malicious input or corrupted file.'\n );\n }\n\n // Use XMLParser to extract all Relationship elements\n const relationshipElements = XMLParser.extractElements(xml, 'Relationship');\n\n // Prevent infinite loops: check relationship count\n if (relationshipElements.length > 1000) {\n throw new CorruptedArchiveError(\n 'Too many relationships in XML file (>1000). Possible malicious input.'\n );\n }\n\n // Process each relationship element\n for (const relationshipElement of relationshipElements) {\n // Extract attributes using XMLParser\n const id = XMLParser.extractAttribute(relationshipElement, 'Id');\n const type = XMLParser.extractAttribute(relationshipElement, 'Type');\n const target = XMLParser.extractAttribute(relationshipElement, 'Target');\n const targetMode = XMLParser.extractAttribute(relationshipElement, 'TargetMode');\n\n // Only create relationship if all required attributes present\n if (id && type && target) {\n // Validate targetMode before type assertion\n const validatedTargetMode =\n targetMode === 'Internal' || targetMode === 'External' || targetMode === undefined\n ? targetMode\n : undefined;\n\n // Sanitize hyperlink URLs (strip browser extension prefixes)\n let sanitizedTarget = target;\n if (type.endsWith('/hyperlink')) {\n const result = sanitizeHyperlinkUrl(target);\n if (result) {\n sanitizedTarget = result.url;\n }\n }\n\n // Create and add relationship\n const relationship = Relationship.create({\n id,\n type,\n target: sanitizedTarget,\n targetMode: validatedTargetMode || 'Internal',\n });\n\n manager.addRelationship(relationship);\n }\n }\n\n return manager;\n }\n}\n"]}
1
+ {"version":3,"file":"RelationshipManager.js","sourceRoot":"","sources":["../../../src/core/RelationshipManager.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AACnE,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAChD,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EAAE,gBAAgB,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AAK3E,MAAM,OAAO,mBAAmB;IACtB,aAAa,CAA4B;IACzC,MAAM,CAAS;IAKvB;QACE,IAAI,CAAC,aAAa,GAAG,IAAI,GAAG,EAAE,CAAC;QAC/B,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC;IAClB,CAAC;IAOD,eAAe,CAAC,YAA0B;QACxC,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,YAAY,CAAC,KAAK,EAAE,EAAE,YAAY,CAAC,CAAC;QAG3D,MAAM,OAAO,GAAG,YAAY,CAAC,IAAI,CAAC,YAAY,CAAC,KAAK,EAAE,CAAC,CAAC;QACxD,IAAI,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YACjB,MAAM,KAAK,GAAG,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;YACvC,IAAI,KAAK,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;gBACzB,IAAI,CAAC,MAAM,GAAG,KAAK,GAAG,CAAC,CAAC;YAC1B,CAA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C;YACjE,MAAM,IAAI,GAAG,SAAS,CAAC,gBAAgB,CAAC,mBAAmB,EAAE,MAAM,CAAC,CAAC;YACrE,MAAM,MAAM,GAAG,SAAS,CAAC,gBAAgB,CAAC,mBAAmB,EAAE,QAAQ,CAAC,CAAC;YACzE,MAAM,UAAU,GAAG,SAAS,CAAC,gBAAgB,CAAC,mBAAmB,EAAE,YAAY,CAAC,CAAC;YAGjF,IAAI,EAAE,IAAI,IAAI,IAAI,MAAM,EAAE,CAAC;gBAEzB,MAAM,mBAAmB,GACvB,UAAU,KAAK,UAAU,IAAI,UAAU,KAAK,UAAU,IAAI,UAAU,KAAK,SAAS;oBAChF,CAAC,CAAC,UAAU;oBACZ,CAAC,CAAC,SAAS,CAAC;gBAGhB,IAAI,eAAe,GAAG,MAAM,CAAC;gBAC7B,IAAI,IAAI,CAAC,QAAQ,CAAC,YAAY,CAAC,EAAE,CAAC;oBAChC,MAAM,MAAM,GAAG,oBAAoB,CAAC,MAAM,CAAC,CAAC;oBAC5C,IAAI,MAAM,EAAE,CAAC;wBACX,eAAe,GAAG,MAAM,CAAC,GAAG,CAAC;oBAC/B,CAAC;gBACH,CAAC;gBAGD,MAAM,YAAY,GAAG,YAAY,CAAC,MAAM,CAAC;oBACvC,EAAE;oBACF,IAAI;oBACJ,MAAM,EAAE,eAAe;oBACvB,UAAU,EAAE,mBAAmB,IAAI,UAAU;iBAC9C,CAAC,CAAC;gBAEH,OAAO,CAAC,eAAe,CAAC,YAAY,CAAC,CAAC;YACxC,CAAC;QACH,CAAC;QAED,OAAO,OAAO,CAAC;IACjB,CAAC;CACF","sourcesContent":["/**\r\n * RelationshipManager - Manages collections of relationships\r\n *\r\n * Handles relationship creation, tracking, and XML generation for various\r\n * document parts (document.xml, header.xml, footer.xml, etc.)\r\n */\r\n\r\nimport { Relationship, RelationshipType } from './Relationship.js';\r\nimport { XMLParser } from '../xml/XMLParser.js';\r\nimport { sanitizeHyperlinkUrl } from '../utils/validation.js';\r\nimport { InvalidDocxError, CorruptedArchiveError } from '../zip/errors.js';\r\n\r\n/**\r\n * Manages relationships for a document or document part\r\n */\r\nexport class RelationshipManager {\r\n private relationships: Map<string, Relationship>;\r\n private nextId: number;\r\n\r\n /**\r\n * Creates a new relationship manager\r\n */\r\n constructor() {\r\n this.relationships = new Map();\r\n this.nextId = 1;\r\n }\r\n\r\n /**\r\n * Adds a relationship\r\n * @param relationship The relationship to add\r\n * @returns The relationship that was added\r\n */\r\n addRelationship(relationship: Relationship): Relationship {\r\n this.relationships.set(relationship.getId(), relationship);\r\n\r\n // Update next ID if necessary\r\n const idMatch = /^rId(\\d+)$/.exec(relationship.getId());\r\n if (idMatch?.[1]) {\r\n const idNum = parseInt(idMatch[1], 10);\r\n if (idNum >= this.nextId) {\r\n this.nextId = idNum + 1;\r\n }\r\n }\r\n\r\n return relationship;\r\n }\r\n\r\n /**\r\n * Gets a relationship by ID\r\n * @param id The relationship ID\r\n */\r\n getRelationship(id: string): Relationship | undefined {\r\n return this.relationships.get(id);\r\n }\r\n\r\n /**\r\n * Gets all relationships\r\n */\r\n getAllRelationships(): Relationship[] {\r\n return Array.from(this.relationships.values());\r\n }\r\n\r\n /**\r\n * Gets relationships of a specific type\r\n * @param type The relationship type\r\n */\r\n getRelationshipsByType(type: string | RelationshipType): Relationship[] {\r\n return this.getAllRelationships().filter((rel) => rel.getType() === type);\r\n }\r\n\r\n /**\r\n * Checks if a relationship exists\r\n * @param id The relationship ID\r\n */\r\n hasRelationship(id: string): boolean {\r\n return this.relationships.has(id);\r\n }\r\n\r\n /**\r\n * Removes a relationship\r\n * @param id The relationship ID\r\n * @returns True if removed, false if not found\r\n */\r\n removeRelationship(id: string): boolean {\r\n return this.relationships.delete(id);\r\n }\r\n\r\n /**\r\n * Gets the number of relationships\r\n */\r\n getCount(): number {\r\n return this.relationships.size;\r\n }\r\n\r\n /**\r\n * Clears all relationships\r\n */\r\n clear(): this {\r\n this.relationships.clear();\r\n this.nextId = 1;\r\n return this;\r\n }\r\n\r\n /**\r\n * Generates a new unique relationship ID\r\n * @returns New relationship ID (e.g., 'rId1', 'rId2')\r\n */\r\n generateId(): string {\r\n return `rId${this.nextId++}`;\r\n }\r\n\r\n /**\r\n * Adds a styles relationship\r\n * @returns The created relationship\r\n */\r\n addStyles(): Relationship {\r\n const id = this.generateId();\r\n return this.addRelationship(Relationship.createStyles(id));\r\n }\r\n\r\n /**\r\n * Adds a numbering relationship\r\n * @returns The created relationship\r\n */\r\n addNumbering(): Relationship {\r\n const id = this.generateId();\r\n return this.addRelationship(Relationship.createNumbering(id));\r\n }\r\n\r\n /**\r\n * Adds a fontTable relationship\r\n * @returns The created relationship\r\n */\r\n addFontTable(): Relationship {\r\n const id = this.generateId();\r\n return this.addRelationship(Relationship.createFontTable(id));\r\n }\r\n\r\n /**\r\n * Adds a settings relationship\r\n * @returns The created relationship\r\n */\r\n addSettings(): Relationship {\r\n const id = this.generateId();\r\n return this.addRelationship(Relationship.createSettings(id));\r\n }\r\n\r\n /**\r\n * Adds a webSettings relationship\r\n * @returns The created relationship\r\n */\r\n addWebSettings(): Relationship {\r\n const id = this.generateId();\r\n return this.addRelationship(Relationship.createWebSettings(id));\r\n }\r\n\r\n /**\r\n * Adds a theme relationship\r\n * @returns The created relationship\r\n */\r\n addTheme(): Relationship {\r\n const id = this.generateId();\r\n return this.addRelationship(Relationship.createTheme(id));\r\n }\r\n\r\n /**\r\n * Adds an image relationship\r\n * @param target Image path relative to the part (e.g., 'media/image1.png')\r\n * @returns The created relationship\r\n */\r\n addImage(target: string): Relationship {\r\n const id = this.generateId();\r\n return this.addRelationship(Relationship.createImage(id, target));\r\n }\r\n\r\n /**\r\n * Adds a header relationship\r\n * @param target Header file path (e.g., 'header1.xml')\r\n * @returns The created relationship\r\n */\r\n addHeader(target: string): Relationship {\r\n const id = this.generateId();\r\n return this.addRelationship(Relationship.createHeader(id, target));\r\n }\r\n\r\n /**\r\n * Adds a footer relationship\r\n * @param target Footer file path (e.g., 'footer1.xml')\r\n * @returns The created relationship\r\n */\r\n addFooter(target: string): Relationship {\r\n const id = this.generateId();\r\n return this.addRelationship(Relationship.createFooter(id, target));\r\n }\r\n\r\n /**\r\n * Adds a hyperlink relationship\r\n * @param url The hyperlink URL\r\n * @returns The created relationship\r\n */\r\n addHyperlink(url: string): Relationship {\r\n const id = this.generateId();\r\n return this.addRelationship(Relationship.createHyperlink(id, url));\r\n }\r\n\r\n /**\r\n * Updates the target URL of an existing hyperlink relationship\r\n *\r\n * This method modifies an existing relationship's target in-place, maintaining\r\n * the same relationship ID. This is crucial for proper OpenXML compliance\r\n * per ECMA-376 §17.16.22, as it prevents orphaned relationships.\r\n *\r\n * @param relationshipId The ID of the relationship to update\r\n * @param newUrl The new URL to set\r\n * @returns True if updated, false if relationship not found\r\n */\r\n updateHyperlinkTarget(relationshipId: string, newUrl: string): boolean {\r\n const relationship = this.getRelationship(relationshipId);\r\n if (!relationship) {\r\n return false;\r\n }\r\n\r\n // Verify this is a hyperlink relationship\r\n if (relationship.getType() !== RelationshipType.HYPERLINK) {\r\n throw new InvalidDocxError(\r\n `Relationship ${relationshipId} is not a hyperlink relationship. ` +\r\n `Type is ${relationship.getType()}, expected ${RelationshipType.HYPERLINK}`\r\n );\r\n }\r\n\r\n // Update the target URL\r\n relationship.setTarget(newUrl);\r\n return true;\r\n }\r\n\r\n /**\r\n * Finds a hyperlink relationship by its target URL\r\n *\r\n * @param targetUrl The URL to search for\r\n * @returns The matching relationship, or undefined if not found\r\n */\r\n findHyperlinkByTarget(targetUrl: string): Relationship | undefined {\r\n return this.getAllRelationships().find(\r\n (rel) => rel.getType() === RelationshipType.HYPERLINK && rel.getTarget() === targetUrl\r\n );\r\n }\r\n\r\n /**\r\n * Gets or creates a hyperlink relationship for the given URL\r\n *\r\n * This method ensures we don't create duplicate relationships for the same URL.\r\n * If a relationship already exists for the URL, it returns the existing one.\r\n * Otherwise, it creates a new relationship.\r\n *\r\n * @param url The hyperlink URL\r\n * @returns The existing or newly created relationship\r\n */\r\n getOrCreateHyperlink(url: string): Relationship {\r\n // Check if relationship already exists for this URL\r\n const existing = this.findHyperlinkByTarget(url);\r\n if (existing) {\r\n return existing;\r\n }\r\n\r\n // Create new relationship\r\n return this.addHyperlink(url);\r\n }\r\n\r\n /**\r\n * Removes orphaned hyperlink relationships\r\n *\r\n * This method removes hyperlink relationships that are no longer referenced\r\n * by any hyperlink in the document. Call this after updating URLs to clean\r\n * up any orphaned relationships.\r\n *\r\n * @param referencedIds Set of relationship IDs that are still in use\r\n * @returns Number of relationships removed\r\n */\r\n removeOrphanedHyperlinks(referencedIds: Set<string>): number {\r\n let removed = 0;\r\n const toRemove: string[] = [];\r\n\r\n // Find orphaned relationships\r\n for (const rel of this.getAllRelationships()) {\r\n if (rel.getType() === RelationshipType.HYPERLINK && !referencedIds.has(rel.getId())) {\r\n toRemove.push(rel.getId());\r\n }\r\n }\r\n\r\n // Remove orphaned relationships\r\n for (const id of toRemove) {\r\n if (this.removeRelationship(id)) {\r\n removed++;\r\n }\r\n }\r\n\r\n return removed;\r\n }\r\n\r\n /**\r\n * Adds a comments relationship\r\n * @returns The created relationship\r\n */\r\n addComments(): Relationship {\r\n const id = this.generateId();\r\n return this.addRelationship(Relationship.createComments(id));\r\n }\r\n\r\n /**\r\n * Adds a footnotes relationship\r\n * @returns The created relationship\r\n */\r\n addFootnotes(): Relationship {\r\n const id = this.generateId();\r\n return this.addRelationship(Relationship.createFootnotes(id));\r\n }\r\n\r\n /**\r\n * Adds an endnotes relationship\r\n * @returns The created relationship\r\n */\r\n addEndnotes(): Relationship {\r\n const id = this.generateId();\r\n return this.addRelationship(Relationship.createEndnotes(id));\r\n }\r\n\r\n /**\r\n * Adds a people relationship (track changes authors)\r\n * @returns The created relationship\r\n */\r\n addPeople(): Relationship {\r\n const id = this.generateId();\r\n return this.addRelationship(Relationship.createPeople(id));\r\n }\r\n\r\n /**\r\n * Generates the relationships XML file content\r\n * @returns Complete XML string for .rels file\r\n */\r\n generateXml(): string {\r\n const relationships = this.getAllRelationships();\r\n\r\n let xml = '<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\\n';\r\n xml += '<Relationships xmlns=\"http://schemas.openxmlformats.org/package/2006/relationships\">\\n';\r\n\r\n for (const rel of relationships) {\r\n xml += rel.toXML() + '\\n';\r\n }\r\n\r\n xml += '</Relationships>';\r\n\r\n return xml;\r\n }\r\n\r\n /**\r\n * Creates a new relationship manager with common document relationships\r\n * @returns RelationshipManager with styles, numbering, fontTable, settings, and theme relationships\r\n */\r\n static createForDocument(): RelationshipManager {\r\n const manager = new RelationshipManager();\r\n manager.addStyles();\r\n manager.addNumbering();\r\n manager.addFontTable();\r\n manager.addSettings();\r\n manager.addWebSettings();\r\n manager.addTheme();\r\n return manager;\r\n }\r\n\r\n /**\r\n * Creates an empty relationship manager\r\n * @returns Empty RelationshipManager\r\n */\r\n static create(): RelationshipManager {\r\n return new RelationshipManager();\r\n }\r\n\r\n /**\r\n * Parses relationships from XML string and creates a populated manager\r\n * @param xml The relationships XML content (.rels file)\r\n * @returns RelationshipManager with parsed relationships\r\n */\r\n static fromXml(xml: string): RelationshipManager {\r\n const manager = new RelationshipManager();\r\n\r\n // Prevent ReDoS: validate input size (typical .rels files are < 10KB, max 10MB)\r\n if (xml.length > 10000000) {\r\n throw new CorruptedArchiveError(\r\n 'Relationships XML file too large (>10MB). Possible malicious input or corrupted file.'\r\n );\r\n }\r\n\r\n // Use XMLParser to extract all Relationship elements\r\n const relationshipElements = XMLParser.extractElements(xml, 'Relationship');\r\n\r\n // The 10MB size cap above is the primary bound on the work performed here;\r\n // this count check is a far-above-normal backstop. Link- and image-heavy\r\n // documents (each unique hyperlink URL or image is one OPC relationship)\r\n // legitimately exceed several thousand entries, so the limit must stay well\r\n // clear of any realistic part.\r\n if (relationshipElements.length > 100000) {\r\n throw new CorruptedArchiveError(\r\n 'Too many relationships in XML file (>100000). Possible malicious input or corrupted file.'\r\n );\r\n }\r\n\r\n // Process each relationship element\r\n for (const relationshipElement of relationshipElements) {\r\n // Extract attributes using XMLParser\r\n const id = XMLParser.extractAttribute(relationshipElement, 'Id');\r\n const type = XMLParser.extractAttribute(relationshipElement, 'Type');\r\n const target = XMLParser.extractAttribute(relationshipElement, 'Target');\r\n const targetMode = XMLParser.extractAttribute(relationshipElement, 'TargetMode');\r\n\r\n // Only create relationship if all required attributes present\r\n if (id && type && target) {\r\n // Validate targetMode before type assertion\r\n const validatedTargetMode =\r\n targetMode === 'Internal' || targetMode === 'External' || targetMode === undefined\r\n ? targetMode\r\n : undefined;\r\n\r\n // Sanitize hyperlink URLs (strip browser extension prefixes)\r\n let sanitizedTarget = target;\r\n if (type.endsWith('/hyperlink')) {\r\n const result = sanitizeHyperlinkUrl(target);\r\n if (result) {\r\n sanitizedTarget = result.url;\r\n }\r\n }\r\n\r\n // Create and add relationship\r\n const relationship = Relationship.create({\r\n id,\r\n type,\r\n target: sanitizedTarget,\r\n targetMode: validatedTargetMode || 'Internal',\r\n });\r\n\r\n manager.addRelationship(relationship);\r\n }\r\n }\r\n\r\n return manager;\r\n }\r\n}\r\n"]}
@@ -5,9 +5,10 @@ export class Comment {
5
5
  author;
6
6
  initials;
7
7
  date;
8
- runs;
8
+ paragraphs;
9
9
  parentId;
10
10
  done;
11
+ onModified = null;
11
12
  constructor(properties) {
12
13
  this.id = properties.id ?? 0;
13
14
  this.author = properties.author;
@@ -15,15 +16,17 @@ export class Comment {
15
16
  this.date = properties.date || new Date();
16
17
  this.parentId = properties.parentId;
17
18
  this.done = properties.done ?? false;
19
+ let runs;
18
20
  if (typeof properties.content === 'string') {
19
- this.runs = [new Run(properties.content)];
21
+ runs = [new Run(properties.content)];
20
22
  }
21
23
  else if (Array.isArray(properties.content)) {
22
- this.runs = properties.content;
24
+ runs = properties.content;
23
25
  }
24
26
  else {
25
- this.runs = [properties.content];
27
+ runs = [properties.content];
26
28
  }
29
+ this.paragraphs = [{ content: runs }];
27
30
  }
28
31
  generateInitials(author) {
29
32
  const words = author
@@ -46,11 +49,20 @@ export class Comment {
46
49
  setId(id) {
47
50
  this.id = id;
48
51
  }
52
+ setModifiedCallback(callback) {
53
+ this.onModified = callback;
54
+ }
55
+ notifyModified() {
56
+ if (this.onModified) {
57
+ this.onModified();
58
+ }
59
+ }
49
60
  getAuthor() {
50
61
  return this.author;
51
62
  }
52
63
  setAuthor(author) {
53
64
  this.author = author;
65
+ this.notifyModified();
54
66
  return this;
55
67
  }
56
68
  getInitials() {
@@ -58,6 +70,7 @@ export class Comment {
58
70
  }
59
71
  setInitials(initials) {
60
72
  this.initials = initials;
73
+ this.notifyModified();
61
74
  return this;
62
75
  }
63
76
  getDate() {
@@ -65,6 +78,7 @@ export class Comment {
65
78
  }
66
79
  setDate(date) {
67
80
  this.date = date;
81
+ this.notifyModified();
68
82
  return this;
69
83
  }
70
84
  getParentId() {
@@ -78,21 +92,51 @@ export class Comment {
78
92
  }
79
93
  resolve() {
80
94
  this.done = true;
95
+ this.notifyModified();
81
96
  return this;
82
97
  }
83
98
  unresolve() {
84
99
  this.done = false;
100
+ this.notifyModified();
85
101
  return this;
86
102
  }
87
103
  getRuns() {
88
- return [...this.runs];
104
+ const runs = [];
105
+ for (const paragraph of this.paragraphs) {
106
+ for (const item of paragraph.content) {
107
+ if (item instanceof Run) {
108
+ runs.push(item);
109
+ }
110
+ else {
111
+ runs.push(...item.runs);
112
+ }
113
+ }
114
+ }
115
+ return runs;
89
116
  }
90
117
  addRun(run) {
91
- this.runs.push(run);
118
+ let last = this.paragraphs[this.paragraphs.length - 1];
119
+ if (!last) {
120
+ last = { content: [] };
121
+ this.paragraphs.push(last);
122
+ }
123
+ last.content.push(run);
124
+ this.notifyModified();
92
125
  return this;
93
126
  }
127
+ getParagraphs() {
128
+ return this.paragraphs.map((paragraph) => ({
129
+ pPr: paragraph.pPr,
130
+ content: [...paragraph.content],
131
+ }));
132
+ }
133
+ setParagraphs(paragraphs) {
134
+ this.paragraphs = paragraphs;
135
+ }
94
136
  getText() {
95
- return this.runs.map((run) => run.getText()).join('');
137
+ return this.getRuns()
138
+ .map((run) => run.getText())
139
+ .join('');
96
140
  }
97
141
  getContent() {
98
142
  return this.getText();
@@ -145,14 +189,25 @@ export class Comment {
145
189
  if (this.done) {
146
190
  attributes['w:done'] = '1';
147
191
  }
148
- const commentParagraph = {
149
- name: 'w:p',
150
- children: this.runs.map((run) => run.toXML()),
151
- };
192
+ const commentParagraphs = this.paragraphs.map((paragraph) => {
193
+ const children = [];
194
+ if (paragraph.pPr) {
195
+ children.push({ name: '__rawXml', rawXml: paragraph.pPr });
196
+ }
197
+ for (const item of paragraph.content) {
198
+ if (item instanceof Run) {
199
+ children.push(item.toXML());
200
+ }
201
+ else {
202
+ children.push({ name: '__rawXml', rawXml: item.rawXml });
203
+ }
204
+ }
205
+ return { name: 'w:p', children };
206
+ });
152
207
  return {
153
208
  name: 'w:comment',
154
209
  attributes,
155
- children: [commentParagraph],
210
+ children: commentParagraphs,
156
211
  };
157
212
  }
158
213
  static create(author, content, initials) {
@@ -1 +1 @@
1
- {"version":3,"file":"Comment.js","sourceRoot":"","sources":["../../../src/elements/Comment.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAE/B,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAyB9D,MAAM,OAAO,OAAO;IACV,EAAE,CAAS;IACX,MAAM,CAAS;IACf,QAAQ,CAAS;IACjB,IAAI,CAAO;IACX,IAAI,CAAQ;IACZ,QAAQ,CAAU;IAClB,IAAI,CAAU;IAMtB,YAAY,UAA6B;QACvC,IAAI,CAAC,EAAE,GAAG,UAAU,CAAC,EAAE,IAAI,CAAC,CAAC;QAC7B,IAAI,CAAC,MAAM,GAAG,UAAU,CAAC,MAAM,CAAC;QAChC,IAAI,CAAC,QAAQ,GAAG,UAAU,CAAC,QAAQ,IAAI,IAAI,CAAC,gBAAgB,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;QAChF,IAAI,CAAC,IAAI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QAAQ,CAAC,QAAQ,EAAE,CAAC;QACxD,CAAC;QAGD,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC;YACd,UAAU,CAAC,QAAQ,CAAC,GAAG,GAAG,CAAC;QAC7B,CAAC;QAGD,MAAM,gBAAgB,GAAe;YACnC,IAAI,EAAE,KAAK;YACX,QAAQ,EAAE,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC;SAC9C,CAAC;QAEF,OAAO;YACL,IAAI,EAAE,WAAW;YACjB,UAAU;YACV,QAAQ,EAAE,CAAC,gBAAgB,CAAC;SAC7B,CAAC;IACJ,CAAC;IASD,MAAM,CAAC,MAAM,CAAC,MAAc,EAAE,OAA6B,EAAE,QAAiB;QAC5E,OAAO,IAAI,OAAO,CAAC;YACjB,MAAM;YACN,OAAO;YACP,QAAQ;SACT,CAAC,CAAC;IACL,CAAC;IAUD,MAAM,CAAC,WAAW,CAChB,QAAgB,EAChB,MAAc,EACd,OAA6B,EAC7B,QAAiB;QAEjB,OAAO,IAAI,OAAO,CAAC;YACjB,MAAM;YACN,OAAO;YACP,QAAQ;YACR,QAAQ;SACT,CAAC,CAAC;IACL,CAAC;IASD,MAAM,CAAC,eAAe,CAAC,MAAc,EAAE,IAAW,EAAE,QAAiB;QACnE,OAAO,IAAI,OAAO,CAAC;YACjB,MAAM;YACN,OAAO,EAAE,IAAI;YACb,QAAQ;SACT,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["/**\n * Comment - Represents a comment/annotation in a Word document\n *\n * Comments allow users to annotate specific text ranges in a document.\n * They include author, date, content, and can have replies.\n */\n\nimport { Run } from './Run.js';\nimport { XMLElement } from '../xml/XMLBuilder.js';\nimport { formatDateForXml } from '../utils/dateFormatting.js';\n\n/**\n * Comment properties\n */\nexport interface CommentProperties {\n /** Unique comment ID (assigned by CommentManager) */\n id?: number;\n /** Author who created the comment */\n author: string;\n /** Author's initials (optional) */\n initials?: string;\n /** Date when the comment was created */\n date?: Date;\n /** Comment content (text or runs) */\n content: string | Run | Run[];\n /** Parent comment ID (for replies) */\n parentId?: number;\n /** Whether the comment is resolved/done (w:done attribute per ECMA-376) */\n done?: boolean;\n}\n\n/**\n * Represents a comment/annotation in a document\n */\nexport class Comment {\n private id: number;\n private author: string;\n private initials: string;\n private date: Date;\n private runs: Run[];\n private parentId?: number;\n private done: boolean;\n\n /**\n * Creates a new Comment\n * @param properties - Comment properties\n */\n constructor(properties: CommentProperties) {\n this.id = properties.id ?? 0; // Will be assigned by CommentManager\n this.author = properties.author;\n this.initials = properties.initials || this.generateInitials(properties.author);\n this.date = properties.date || new Date();\n this.parentId = properties.parentId;\n this.done = properties.done ?? false;\n\n // Convert content to runs\n if (typeof properties.content === 'string') {\n this.runs = [new Run(properties.content)];\n } else if (Array.isArray(properties.content)) {\n this.runs = properties.content;\n } else {\n this.runs = [properties.content];\n }\n }\n\n /**\n * Generates initials from author name\n * Examples: \"John Doe\" -> \"JD\", \"Jane Smith\" -> \"JS\"\n */\n private generateInitials(author: string): string {\n const words = author\n .trim()\n .split(/\\s+/)\n .filter((w) => w.length > 0);\n if (words.length === 0) return 'U';\n if (words.length === 1) return (words[0] || 'U').substring(0, 2).toUpperCase();\n return (\n words\n .map((word) => word[0] || '')\n .join('')\n .toUpperCase()\n .substring(0, 3) || 'U'\n );\n }\n\n /**\n * Gets the comment ID\n */\n getId(): number {\n return this.id;\n }\n\n /**\n * Sets the comment ID (used by CommentManager)\n * @internal\n */\n setId(id: number): void {\n this.id = id;\n }\n\n /**\n * Gets the author\n */\n getAuthor(): string {\n return this.author;\n }\n\n /**\n * Sets the author\n */\n setAuthor(author: string): this {\n this.author = author;\n return this;\n }\n\n /**\n * Gets the author's initials\n */\n getInitials(): string {\n return this.initials;\n }\n\n /**\n * Sets the author's initials\n */\n setInitials(initials: string): this {\n this.initials = initials;\n return this;\n }\n\n /**\n * Gets the comment date\n */\n getDate(): Date {\n return this.date;\n }\n\n /**\n * Sets the comment date\n */\n setDate(date: Date): this {\n this.date = date;\n return this;\n }\n\n /**\n * Gets the parent comment ID (for replies)\n */\n getParentId(): number | undefined {\n return this.parentId;\n }\n\n /**\n * Checks if this is a reply to another comment\n */\n isReply(): boolean {\n return this.parentId !== undefined;\n }\n\n /**\n * Checks if the comment is resolved/done\n * Per ECMA-376 Part 1, Section 17.13.4.2 (w:done attribute)\n */\n isResolved(): boolean {\n return this.done;\n }\n\n /**\n * Marks the comment as resolved/done\n * Sets w:done=\"1\" in the XML output\n */\n resolve(): this {\n this.done = true;\n return this;\n }\n\n /**\n * Marks the comment as unresolved\n * Removes w:done attribute from XML output\n */\n unresolve(): this {\n this.done = false;\n return this;\n }\n\n /**\n * Gets the runs in this comment\n */\n getRuns(): Run[] {\n return [...this.runs];\n }\n\n /**\n * Adds a run to this comment\n */\n addRun(run: Run): this {\n this.runs.push(run);\n return this;\n }\n\n /**\n * Gets the comment text (combines all runs)\n */\n getText(): string {\n return this.runs.map((run) => run.getText()).join('');\n }\n\n /**\n * Gets the comment content (alias for getText for compatibility)\n */\n getContent(): string {\n return this.getText();\n }\n\n /**\n * Formats a date to ISO 8601 format for XML\n * Uses formatDateForXml() to strip milliseconds which Word does not accept.\n */\n private formatDate(date: Date): string {\n return formatDateForXml(date);\n }\n\n /**\n * Generates XML for the comment range start marker\n * This goes in word/document.xml at the start of the commented range\n */\n toRangeStartXML(): XMLElement {\n return {\n name: 'w:commentRangeStart',\n attributes: {\n 'w:id': this.id.toString(),\n },\n selfClosing: true,\n };\n }\n\n /**\n * Generates XML for the comment range end marker\n * This goes in word/document.xml at the end of the commented range\n */\n toRangeEndXML(): XMLElement {\n return {\n name: 'w:commentRangeEnd',\n attributes: {\n 'w:id': this.id.toString(),\n },\n selfClosing: true,\n };\n }\n\n /**\n * Generates XML for the comment reference\n * This goes in word/document.xml after the range end, inside a run\n */\n toReferenceXML(): XMLElement {\n return {\n name: 'w:r',\n children: [\n {\n name: 'w:commentReference',\n attributes: {\n 'w:id': this.id.toString(),\n },\n selfClosing: true,\n },\n ],\n };\n }\n\n /**\n * Generates XML for the comment definition\n * This goes in word/comments.xml\n */\n toXML(): XMLElement {\n const attributes: Record<string, string> = {\n 'w:id': this.id.toString(),\n 'w:author': this.author,\n 'w:date': this.formatDate(this.date),\n 'w:initials': this.initials,\n };\n\n // Add parent ID for replies (w15 namespace per Office 2012 extensions)\n if (this.parentId !== undefined) {\n attributes['w15:parentId'] = this.parentId.toString();\n }\n\n // Add done attribute for resolved comments (per ECMA-376)\n if (this.done) {\n attributes['w:done'] = '1';\n }\n\n // Create paragraph containing the comment content\n const commentParagraph: XMLElement = {\n name: 'w:p',\n children: this.runs.map((run) => run.toXML()),\n };\n\n return {\n name: 'w:comment',\n attributes,\n children: [commentParagraph],\n };\n }\n\n /**\n * Creates a new comment\n * @param author - Comment author\n * @param content - Comment content (text or runs)\n * @param initials - Optional author initials\n * @returns New Comment instance\n */\n static create(author: string, content: string | Run | Run[], initials?: string): Comment {\n return new Comment({\n author,\n content,\n initials,\n });\n }\n\n /**\n * Creates a reply to an existing comment\n * @param parentId - ID of the parent comment\n * @param author - Reply author\n * @param content - Reply content (text or runs)\n * @param initials - Optional author initials\n * @returns New Comment instance (reply)\n */\n static createReply(\n parentId: number,\n author: string,\n content: string | Run | Run[],\n initials?: string\n ): Comment {\n return new Comment({\n author,\n content,\n initials,\n parentId,\n });\n }\n\n /**\n * Creates a comment with formatted content\n * @param author - Comment author\n * @param runs - Array of formatted runs\n * @param initials - Optional author initials\n * @returns New Comment instance\n */\n static createFormatted(author: string, runs: Run[], initials?: string): Comment {\n return new Comment({\n author,\n content: runs,\n initials,\n });\n }\n}\n"]}
1
+ {"version":3,"file":"Comment.js","sourceRoot":"","sources":["../../../src/elements/Comment.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAE/B,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAqD9D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C9B,CAAC;qBAAM,CAAC;oBACN,QAAQ,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;gBAC3D,CAAC;YACH,CAAC;YACD,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC;QACnC,CAAC,CAAC,CAAC;QAEH,OAAO;YACL,IAAI,EAAE,WAAW;YACjB,UAAU;YACV,QAAQ,EAAE,iBAAiB;SAC5B,CAAC;IACJ,CAAC;IASD,MAAM,CAAC,MAAM,CAAC,MAAc,EAAE,OAA6B,EAAE,QAAiB;QAC5E,OAAO,IAAI,OAAO,CAAC;YACjB,MAAM;YACN,OAAO;YACP,QAAQ;SACT,CAAC,CAAC;IACL,CAAC;IAUD,MAAM,CAAC,WAAW,CAChB,QAAgB,EAChB,MAAc,EACd,OAA6B,EAC7B,QAAiB;QAEjB,OAAO,IAAI,OAAO,CAAC;YACjB,MAAM;YACN,OAAO;YACP,QAAQ;YACR,QAAQ;SACT,CAAC,CAAC;IACL,CAAC;IASD,MAAM,CAAC,eAAe,CAAC,MAAc,EAAE,IAAW,EAAE,QAAiB;QACnE,OAAO,IAAI,OAAO,CAAC;YACjB,MAAM;YACN,OAAO,EAAE,IAAI;YACb,QAAQ;SACT,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["/**\n * Comment - Represents a comment/annotation in a Word document\n *\n * Comments allow users to annotate specific text ranges in a document.\n * They include author, date, content, and can have replies.\n */\n\nimport { Run } from './Run.js';\nimport { XMLElement } from '../xml/XMLBuilder.js';\nimport { formatDateForXml } from '../utils/dateFormatting.js';\n\n/**\n * Inline comment content preserved as raw XML (e.g. w:hyperlink wrappers\n * from a parsed comments.xml). The wrapper is re-emitted verbatim on\n * regeneration so its r:id target survives; the runs parsed from inside\n * it are kept alongside so text extraction still sees their text.\n */\nexport interface CommentPreservedContent {\n /** Original XML emitted verbatim when comments.xml is regenerated */\n rawXml: string;\n /** Runs parsed from inside the preserved element (text extraction only) */\n runs: Run[];\n}\n\n/** Ordered item of comment paragraph content */\nexport type CommentContentItem = Run | CommentPreservedContent;\n\n/**\n * One paragraph of comment content. CT_Comment accepts block-level content\n * (ECMA-376 §17.13.4.2), so comments can span multiple paragraphs, each\n * with its own paragraph properties (typically the CommentText style).\n */\nexport interface CommentParagraph {\n /** Raw <w:pPr> XML preserved for round-trip */\n pPr?: string;\n /** Paragraph content in document order */\n content: CommentContentItem[];\n}\n\n/**\n * Comment properties\n */\nexport interface CommentProperties {\n /** Unique comment ID (assigned by CommentManager) */\n id?: number;\n /** Author who created the comment */\n author: string;\n /** Author's initials (optional) */\n initials?: string;\n /** Date when the comment was created */\n date?: Date;\n /** Comment content (text or runs) */\n content: string | Run | Run[];\n /** Parent comment ID (for replies) */\n parentId?: number;\n /** Whether the comment is resolved/done (w:done attribute per ECMA-376) */\n done?: boolean;\n}\n\n/**\n * Represents a comment/annotation in a document\n */\nexport class Comment {\n private id: number;\n private author: string;\n private initials: string;\n private date: Date;\n private paragraphs: CommentParagraph[];\n private parentId?: number;\n private done: boolean;\n private onModified: (() => void) | null = null;\n\n /**\n * Creates a new Comment\n * @param properties - Comment properties\n */\n constructor(properties: CommentProperties) {\n this.id = properties.id ?? 0; // Will be assigned by CommentManager\n this.author = properties.author;\n this.initials = properties.initials || this.generateInitials(properties.author);\n this.date = properties.date || new Date();\n this.parentId = properties.parentId;\n this.done = properties.done ?? false;\n\n // Convert content to runs in a single paragraph\n let runs: Run[];\n if (typeof properties.content === 'string') {\n runs = [new Run(properties.content)];\n } else if (Array.isArray(properties.content)) {\n runs = properties.content;\n } else {\n runs = [properties.content];\n }\n this.paragraphs = [{ content: runs }];\n }\n\n /**\n * Generates initials from author name\n * Examples: \"John Doe\" -> \"JD\", \"Jane Smith\" -> \"JS\"\n */\n private generateInitials(author: string): string {\n const words = author\n .trim()\n .split(/\\s+/)\n .filter((w) => w.length > 0);\n if (words.length === 0) return 'U';\n if (words.length === 1) return (words[0] || 'U').substring(0, 2).toUpperCase();\n return (\n words\n .map((word) => word[0] || '')\n .join('')\n .toUpperCase()\n .substring(0, 3) || 'U'\n );\n }\n\n /**\n * Gets the comment ID\n */\n getId(): number {\n return this.id;\n }\n\n /**\n * Sets the comment ID (used by CommentManager)\n * @internal\n */\n setId(id: number): void {\n this.id = id;\n }\n\n /**\n * Registers a callback invoked whenever this comment is mutated.\n * Document wires this to its comments dirty flag so edits to parsed\n * comments trigger regeneration of comments.xml instead of being\n * silently discarded by the original-XML passthrough on save.\n * @internal\n */\n setModifiedCallback(callback: () => void): void {\n this.onModified = callback;\n }\n\n private notifyModified(): void {\n if (this.onModified) {\n this.onModified();\n }\n }\n\n /**\n * Gets the author\n */\n getAuthor(): string {\n return this.author;\n }\n\n /**\n * Sets the author\n */\n setAuthor(author: string): this {\n this.author = author;\n this.notifyModified();\n return this;\n }\n\n /**\n * Gets the author's initials\n */\n getInitials(): string {\n return this.initials;\n }\n\n /**\n * Sets the author's initials\n */\n setInitials(initials: string): this {\n this.initials = initials;\n this.notifyModified();\n return this;\n }\n\n /**\n * Gets the comment date\n */\n getDate(): Date {\n return this.date;\n }\n\n /**\n * Sets the comment date\n */\n setDate(date: Date): this {\n this.date = date;\n this.notifyModified();\n return this;\n }\n\n /**\n * Gets the parent comment ID (for replies)\n */\n getParentId(): number | undefined {\n return this.parentId;\n }\n\n /**\n * Checks if this is a reply to another comment\n */\n isReply(): boolean {\n return this.parentId !== undefined;\n }\n\n /**\n * Checks if the comment is resolved/done\n * Per ECMA-376 Part 1, Section 17.13.4.2 (w:done attribute)\n */\n isResolved(): boolean {\n return this.done;\n }\n\n /**\n * Marks the comment as resolved/done\n * Persists as w15:done=\"1\" in word/commentsExtended.xml on save\n */\n resolve(): this {\n this.done = true;\n this.notifyModified();\n return this;\n }\n\n /**\n * Marks the comment as unresolved\n * Drops the w15:done flag from word/commentsExtended.xml on save\n */\n unresolve(): this {\n this.done = false;\n this.notifyModified();\n return this;\n }\n\n /**\n * Gets the runs in this comment (flattened across paragraphs,\n * including runs inside preserved inline content)\n */\n getRuns(): Run[] {\n const runs: Run[] = [];\n for (const paragraph of this.paragraphs) {\n for (const item of paragraph.content) {\n if (item instanceof Run) {\n runs.push(item);\n } else {\n runs.push(...item.runs);\n }\n }\n }\n return runs;\n }\n\n /**\n * Adds a run to this comment (appended to the last paragraph)\n */\n addRun(run: Run): this {\n let last = this.paragraphs[this.paragraphs.length - 1];\n if (!last) {\n last = { content: [] };\n this.paragraphs.push(last);\n }\n last.content.push(run);\n this.notifyModified();\n return this;\n }\n\n /**\n * Gets the comment content grouped by paragraph\n */\n getParagraphs(): CommentParagraph[] {\n return this.paragraphs.map((paragraph) => ({\n pPr: paragraph.pPr,\n content: [...paragraph.content],\n }));\n }\n\n /**\n * Replaces the comment content with parsed paragraphs.\n * Used by DocumentParser to preserve <w:p> boundaries, paragraph\n * properties, and hyperlink wrappers of comments loaded from an\n * existing comments.xml. Not a user mutation — no dirty notification.\n * @internal\n */\n setParagraphs(paragraphs: CommentParagraph[]): void {\n this.paragraphs = paragraphs;\n }\n\n /**\n * Gets the comment text (combines all runs)\n */\n getText(): string {\n return this.getRuns()\n .map((run) => run.getText())\n .join('');\n }\n\n /**\n * Gets the comment content (alias for getText for compatibility)\n */\n getContent(): string {\n return this.getText();\n }\n\n /**\n * Formats a date to ISO 8601 format for XML\n * Uses formatDateForXml() to strip milliseconds which Word does not accept.\n */\n private formatDate(date: Date): string {\n return formatDateForXml(date);\n }\n\n /**\n * Generates XML for the comment range start marker\n * This goes in word/document.xml at the start of the commented range\n */\n toRangeStartXML(): XMLElement {\n return {\n name: 'w:commentRangeStart',\n attributes: {\n 'w:id': this.id.toString(),\n },\n selfClosing: true,\n };\n }\n\n /**\n * Generates XML for the comment range end marker\n * This goes in word/document.xml at the end of the commented range\n */\n toRangeEndXML(): XMLElement {\n return {\n name: 'w:commentRangeEnd',\n attributes: {\n 'w:id': this.id.toString(),\n },\n selfClosing: true,\n };\n }\n\n /**\n * Generates XML for the comment reference\n * This goes in word/document.xml after the range end, inside a run\n */\n toReferenceXML(): XMLElement {\n return {\n name: 'w:r',\n children: [\n {\n name: 'w:commentReference',\n attributes: {\n 'w:id': this.id.toString(),\n },\n selfClosing: true,\n },\n ],\n };\n }\n\n /**\n * Generates XML for the comment definition\n * This goes in word/comments.xml\n */\n toXML(): XMLElement {\n const attributes: Record<string, string> = {\n 'w:id': this.id.toString(),\n 'w:author': this.author,\n 'w:date': this.formatDate(this.date),\n 'w:initials': this.initials,\n };\n\n // Add parent ID for replies (w15 namespace per Office 2012 extensions)\n if (this.parentId !== undefined) {\n attributes['w15:parentId'] = this.parentId.toString();\n }\n\n // Add done attribute for resolved comments (per ECMA-376)\n if (this.done) {\n attributes['w:done'] = '1';\n }\n\n // One <w:p> per stored paragraph — collapsing into a single paragraph\n // concatenates words across the lost boundaries and drops the\n // CommentText paragraph style of parsed comments\n const commentParagraphs: XMLElement[] = this.paragraphs.map((paragraph) => {\n const children: XMLElement[] = [];\n if (paragraph.pPr) {\n children.push({ name: '__rawXml', rawXml: paragraph.pPr });\n }\n for (const item of paragraph.content) {\n if (item instanceof Run) {\n children.push(item.toXML());\n } else {\n children.push({ name: '__rawXml', rawXml: item.rawXml });\n }\n }\n return { name: 'w:p', children };\n });\n\n return {\n name: 'w:comment',\n attributes,\n children: commentParagraphs,\n };\n }\n\n /**\n * Creates a new comment\n * @param author - Comment author\n * @param content - Comment content (text or runs)\n * @param initials - Optional author initials\n * @returns New Comment instance\n */\n static create(author: string, content: string | Run | Run[], initials?: string): Comment {\n return new Comment({\n author,\n content,\n initials,\n });\n }\n\n /**\n * Creates a reply to an existing comment\n * @param parentId - ID of the parent comment\n * @param author - Reply author\n * @param content - Reply content (text or runs)\n * @param initials - Optional author initials\n * @returns New Comment instance (reply)\n */\n static createReply(\n parentId: number,\n author: string,\n content: string | Run | Run[],\n initials?: string\n ): Comment {\n return new Comment({\n author,\n content,\n initials,\n parentId,\n });\n }\n\n /**\n * Creates a comment with formatted content\n * @param author - Comment author\n * @param runs - Array of formatted runs\n * @param initials - Optional author initials\n * @returns New Comment instance\n */\n static createFormatted(author: string, runs: Run[], initials?: string): Comment {\n return new Comment({\n author,\n content: runs,\n initials,\n });\n }\n}\n"]}
@@ -1,4 +1,5 @@
1
1
  import { Comment } from './Comment.js';
2
+ import { Run } from './Run.js';
2
3
  import { XMLBuilder } from '../xml/XMLBuilder.js';
3
4
  import { formatDateForXml } from '../utils/dateFormatting.js';
4
5
  export class CommentManager {
@@ -6,13 +7,23 @@ export class CommentManager {
6
7
  nextId = 0;
7
8
  idProvider = null;
8
9
  idExistsNotifier = null;
10
+ modifiedNotifier = null;
9
11
  setIdProvider(provider, existsNotifier) {
10
12
  this.idProvider = provider;
11
13
  this.idExistsNotifier = existsNotifier || null;
12
14
  }
15
+ setModifiedNotifier(notifier) {
16
+ this.modifiedNotifier = notifier;
17
+ for (const entry of this.comments.values()) {
18
+ entry.comment.setModifiedCallback(notifier);
19
+ }
20
+ }
13
21
  register(comment) {
14
22
  const id = this.idProvider ? this.idProvider() : this.nextId++;
15
23
  comment.setId(id);
24
+ if (this.modifiedNotifier) {
25
+ comment.setModifiedCallback(this.modifiedNotifier);
26
+ }
16
27
  const entry = {
17
28
  comment,
18
29
  replies: [],
@@ -31,6 +42,9 @@ export class CommentManager {
31
42
  if (this.idExistsNotifier) {
32
43
  this.idExistsNotifier(id);
33
44
  }
45
+ if (this.modifiedNotifier) {
46
+ comment.setModifiedCallback(this.modifiedNotifier);
47
+ }
34
48
  const entry = {
35
49
  comment,
36
50
  replies: [],
@@ -107,6 +121,13 @@ export class CommentManager {
107
121
  for (const reply of entry.replies) {
108
122
  this.comments.delete(reply.getId());
109
123
  }
124
+ const parentId = entry.comment.getParentId();
125
+ if (parentId !== undefined) {
126
+ const parentEntry = this.comments.get(parentId);
127
+ if (parentEntry) {
128
+ parentEntry.replies = parentEntry.replies.filter((reply) => reply !== entry.comment);
129
+ }
130
+ }
110
131
  return this.comments.delete(id);
111
132
  }
112
133
  clear() {
@@ -183,22 +204,53 @@ export class CommentManager {
183
204
  </w:comments>`;
184
205
  }
185
206
  const hasReplies = comments.some((c) => c.isReply());
207
+ const hasResolved = comments.some((c) => c.isResolved());
186
208
  let xml = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n';
187
209
  xml += '<w:comments xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"';
188
210
  xml += ' xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"';
211
+ if (hasResolved) {
212
+ xml += ' xmlns:w14="http://schemas.microsoft.com/office/word/2010/wordml"';
213
+ }
189
214
  if (hasReplies) {
190
215
  xml += ' xmlns:w15="http://schemas.microsoft.com/office/word/2012/wordml"';
191
- xml +=
192
- ' xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="w15"';
216
+ }
217
+ if (hasReplies || hasResolved) {
218
+ const ignorable = [hasResolved ? 'w14' : '', hasReplies ? 'w15' : '']
219
+ .filter((ns) => ns.length > 0)
220
+ .join(' ');
221
+ xml += ` xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="${ignorable}"`;
193
222
  }
194
223
  xml += '>\n';
195
224
  for (const comment of comments) {
196
- xml += this.commentToXmlString(comment);
225
+ xml += this.commentToXmlString(comment, hasResolved ? CommentManager.commentParaId(comment.getId()) : undefined);
197
226
  }
198
227
  xml += '</w:comments>';
199
228
  return xml;
200
229
  }
201
- commentToXmlString(comment) {
230
+ static commentParaId(commentId) {
231
+ return ((commentId + 1) & 0x7fffffff).toString(16).toUpperCase().padStart(8, '0');
232
+ }
233
+ generateCommentsExtendedXml() {
234
+ const comments = this.getAllCommentsWithReplies();
235
+ if (!comments.some((c) => c.isResolved())) {
236
+ return null;
237
+ }
238
+ let xml = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n';
239
+ xml += '<w15:commentsEx xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"';
240
+ xml +=
241
+ ' xmlns:w15="http://schemas.microsoft.com/office/word/2012/wordml" mc:Ignorable="w15">\n';
242
+ for (const comment of comments) {
243
+ xml += ` <w15:commentEx w15:paraId="${CommentManager.commentParaId(comment.getId())}"`;
244
+ const parentId = comment.getParentId();
245
+ if (parentId !== undefined && this.comments.has(parentId)) {
246
+ xml += ` w15:paraIdParent="${CommentManager.commentParaId(parentId)}"`;
247
+ }
248
+ xml += ` w15:done="${comment.isResolved() ? '1' : '0'}"/>\n`;
249
+ }
250
+ xml += '</w15:commentsEx>';
251
+ return xml;
252
+ }
253
+ commentToXmlString(comment, paraId) {
202
254
  let xml = ` <w:comment w:id="${comment.getId()}"`;
203
255
  xml += ` w:author="${XMLBuilder.escapeXmlAttribute(comment.getAuthor())}"`;
204
256
  xml += ` w:date="${formatDateForXml(comment.getDate())}"`;
@@ -206,25 +258,31 @@ export class CommentManager {
206
258
  if (comment.isReply() && comment.getParentId() !== undefined) {
207
259
  xml += ` w15:parentId="${comment.getParentId()}"`;
208
260
  }
209
- if (comment.isResolved()) {
210
- xml += ` w:done="1"`;
211
- }
212
261
  xml += '>\n';
213
- xml += ' <w:p>\n';
214
- for (const run of comment.getRuns()) {
215
- xml += this.runToXmlString(run, 6);
262
+ const paragraphs = comment.getParagraphs();
263
+ for (let i = 0; i < paragraphs.length; i++) {
264
+ const paragraph = paragraphs[i];
265
+ const isLast = i === paragraphs.length - 1;
266
+ xml += isLast && paraId ? ` <w:p w14:paraId="${paraId}">\n` : ' <w:p>\n';
267
+ if (paragraph.pPr) {
268
+ xml += ` ${paragraph.pPr}\n`;
269
+ }
270
+ for (const item of paragraph.content) {
271
+ if (item instanceof Run) {
272
+ xml += this.runToXmlString(item, 6);
273
+ }
274
+ else {
275
+ xml += ` ${item.rawXml}\n`;
276
+ }
277
+ }
278
+ xml += ' </w:p>\n';
216
279
  }
217
- xml += ' </w:p>\n';
218
280
  xml += ' </w:comment>\n';
219
281
  return xml;
220
282
  }
221
283
  runToXmlString(run, indent) {
222
284
  const spaces = ' '.repeat(indent);
223
- const text = XMLBuilder.escapeXmlText(run.getText());
224
- let xml = `${spaces}<w:r>\n`;
225
- xml += `${spaces} <w:t xml:space="preserve">${text}</w:t>\n`;
226
- xml += `${spaces}</w:r>\n`;
227
- return xml;
285
+ return `${spaces}${XMLBuilder.elementToString(run.toXML())}\n`;
228
286
  }
229
287
  static create() {
230
288
  return new CommentManager();
@@ -1 +1 @@
1
- {"version":3,"file":"CommentManager.js","sourceRoot":"","sources":["../../../src/elements/CommentManager.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAClD,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AA0B9D,MAAM,OAAO,cAAc;IACjB,QAAQ,GAAG,IAAI,GAAG,EAAwB,CAAC;IAC3C,MAAM,GAAG,CAAC,CAAC;IACX,UAAU,GAA8B,IAAI,CAAC;IAC7C,gBAAgB,GAA4B,IAAI,CAAC;IAUzD,aAAa,CAAC,QAA4B,EAAE,cAAiC;QAC3E,IAAI,CAAC,UAAU,GAAG,QAAQ,CAAC;QAC3B,IAAI,CAAC,gBAAgB,GAAG,cAAc,IAAI,IAAI,CAAC;IACjD,CAAC;IAQD,QAAQ,CAAC,OAAgB;QAEvB,MAAM,EAAE,GAAG,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;QAC/D,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QAGlB,MAAM,KAAK,GAAiB;YAC1B,OAAO;YACP,OAAO,EAAE,EAAE;SACZ,CAAC;QACF,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,KAAK,CAAC,CAAC;QAG1C,IAAI,OAAO,CAAC,OAAO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,UAAU,CAAC,aAAa,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC,CAAC;QAErD,IAAI,GAAG,GAAG,GAAG,MAAM,SAAS,CAAC;QAC7B,GAAG,IAAI,GAAG,MAAM,+BAA+B,IAAI,UAAU,CAAC;QAC9D,GAAG,IAAI,GAAG,MAAM,UAAU,CAAC;QAE3B,OAAO,GAAG,CAAC;IACb,CAAC;IAMD,MAAM,CAAC,MAAM;QACX,OAAO,IAAI,cAAc,EAAE,CAAC;IAC9B,CAAC;CACF","sourcesContent":["/**\n * CommentManager - Manages comments in a document\n *\n * Tracks all comments, assigns unique IDs, handles replies,\n * and generates the comments.xml file.\n *\n * Per ECMA-376, comment IDs must be unique across ALL annotation types\n * in a document. Use setIdProvider() to connect to a centralized ID allocator.\n */\n\nimport { Comment } from './Comment.js';\nimport { Run } from './Run.js';\nimport { XMLBuilder } from '../xml/XMLBuilder.js';\nimport { formatDateForXml } from '../utils/dateFormatting.js';\n\n/**\n * Type for the centralized ID provider callback.\n * Returns the next available annotation ID from a shared counter.\n */\nexport type IdProviderCallback = () => number;\n\n/**\n * Type for callback to notify of existing IDs (for synchronization).\n * Called when registering existing comments to keep the central counter in sync.\n */\nexport type IdExistsCallback = (existingId: number) => void;\n\n/**\n * Comment entry stored by the manager\n */\ninterface CommentEntry {\n comment: Comment;\n /** Comments that are replies to this comment */\n replies: Comment[];\n}\n\n/**\n * Manages document comments\n */\nexport class CommentManager {\n private comments = new Map<number, CommentEntry>();\n private nextId = 0;\n private idProvider: IdProviderCallback | null = null;\n private idExistsNotifier: IdExistsCallback | null = null;\n\n /**\n * Sets the centralized ID provider callback.\n * When set, IDs will be allocated from the centralized DocumentIdManager\n * instead of the local nextId counter.\n *\n * @param provider - Callback that returns the next available ID\n * @param existsNotifier - Optional callback to notify when existing IDs are found\n */\n setIdProvider(provider: IdProviderCallback, existsNotifier?: IdExistsCallback): void {\n this.idProvider = provider;\n this.idExistsNotifier = existsNotifier || null;\n }\n\n /**\n * Registers a comment with the manager\n * Assigns a unique ID\n * @param comment - Comment to register\n * @returns The registered comment (same instance)\n */\n register(comment: Comment): Comment {\n // Assign unique ID - use centralized provider if available\n const id = this.idProvider ? this.idProvider() : this.nextId++;\n comment.setId(id);\n\n // Store comment\n const entry: CommentEntry = {\n comment,\n replies: [],\n };\n this.comments.set(comment.getId(), entry);\n\n // If this is a reply, add it to the parent's replies array\n if (comment.isReply() && comment.getParentId() !== undefined) {\n const parentEntry = this.comments.get(comment.getParentId()!);\n if (parentEntry) {\n parentEntry.replies.push(comment);\n }\n }\n\n return comment;\n }\n\n /**\n * Registers an existing comment (from parsing) with its pre-assigned ID.\n * Unlike register(), this does NOT assign a new ID - the comment must already have one.\n * Used when loading comments from an existing document.\n * @param comment - Comment with ID already set\n */\n registerExisting(comment: Comment): void {\n const id = comment.getId();\n\n // Notify centralized ID manager if connected\n if (this.idExistsNotifier) {\n this.idExistsNotifier(id);\n }\n\n // Store comment\n const entry: CommentEntry = {\n comment,\n replies: [],\n };\n this.comments.set(id, entry);\n\n // Update local nextId if needed\n if (id >= this.nextId) {\n this.nextId = id + 1;\n }\n }\n\n /**\n * Links reply comments to their parents after all comments are parsed.\n * Must be called after all comments are registered via registerExisting().\n * This builds the reply arrays for each parent comment.\n */\n linkReplies(): void {\n // Clear existing replies first for idempotency (safe to call multiple times)\n for (const entry of this.comments.values()) {\n entry.replies = [];\n }\n for (const entry of this.comments.values()) {\n const comment = entry.comment;\n if (comment.isReply() && comment.getParentId() !== undefined) {\n const parentEntry = this.comments.get(comment.getParentId()!);\n if (parentEntry) {\n parentEntry.replies.push(comment);\n }\n }\n }\n }\n\n /**\n * Gets a comment by ID\n * @param id - Comment ID\n * @returns The comment, or undefined if not found\n */\n getComment(id: number): Comment | undefined {\n return this.comments.get(id)?.comment;\n }\n\n /**\n * Gets all comments (top-level only, not replies)\n * @returns Array of all top-level comments\n */\n getAllComments(): Comment[] {\n return Array.from(this.comments.values())\n .filter((entry) => !entry.comment.isReply())\n .map((entry) => entry.comment);\n }\n\n /**\n * Gets all comments including replies\n * @returns Array of all comments\n */\n getAllCommentsWithReplies(): Comment[] {\n return Array.from(this.comments.values()).map((entry) => entry.comment);\n }\n\n /**\n * Gets replies to a comment\n * @param commentId - ID of the parent comment\n * @returns Array of reply comments\n */\n getReplies(commentId: number): Comment[] {\n const entry = this.comments.get(commentId);\n return entry ? [...entry.replies] : [];\n }\n\n /**\n * Checks if a comment has replies\n * @param commentId - ID of the comment\n * @returns True if the comment has replies\n */\n hasReplies(commentId: number): boolean {\n const entry = this.comments.get(commentId);\n return entry ? entry.replies.length > 0 : false;\n }\n\n /**\n * Gets the number of comments (including replies)\n * @returns Number of comments\n */\n getCount(): number {\n return this.comments.size;\n }\n\n /**\n * Gets the number of top-level comments (excluding replies)\n * @returns Number of top-level comments\n */\n getTopLevelCount(): number {\n return this.getAllComments().length;\n }\n\n /**\n * Gets all unique authors who have made comments\n * @returns Array of unique author names\n */\n getAuthors(): string[] {\n const authorsSet = new Set<string>();\n for (const entry of this.comments.values()) {\n authorsSet.add(entry.comment.getAuthor());\n }\n return Array.from(authorsSet);\n }\n\n /**\n * Gets comments by author\n * @param author - Author name to filter by\n * @returns Array of comments by the specified author\n */\n getCommentsByAuthor(author: string): Comment[] {\n return Array.from(this.comments.values())\n .map((entry) => entry.comment)\n .filter((comment) => comment.getAuthor() === author);\n }\n\n /**\n * Gets comments within a date range\n * @param startDate - Start of date range\n * @param endDate - End of date range\n * @returns Array of comments within the date range\n */\n getCommentsByDateRange(startDate: Date, endDate: Date): Comment[] {\n return Array.from(this.comments.values())\n .map((entry) => entry.comment)\n .filter((comment) => {\n const commentDate = comment.getDate();\n return commentDate >= startDate && commentDate <= endDate;\n });\n }\n\n /**\n * Removes a comment\n * Also removes all replies to that comment\n * @param id - Comment ID\n * @returns True if the comment was removed\n */\n removeComment(id: number): boolean {\n const entry = this.comments.get(id);\n if (!entry) {\n return false;\n }\n\n // Remove all replies first\n for (const reply of entry.replies) {\n this.comments.delete(reply.getId());\n }\n\n // Remove the comment itself\n return this.comments.delete(id);\n }\n\n /**\n * Clears all comments\n */\n clear(): void {\n this.comments.clear();\n this.nextId = 0;\n }\n\n /**\n * Sets the next ID to be assigned.\n * Used when loading documents to avoid ID collisions with existing comments.\n * @param id - The next ID value to use\n */\n setNextId(id: number): void {\n this.nextId = id;\n }\n\n /**\n * Creates and registers a new comment\n * @param author - Comment author\n * @param content - Comment content (text or runs)\n * @param initials - Optional author initials\n * @returns The created and registered comment\n */\n createComment(author: string, content: string | Run | Run[], initials?: string): Comment {\n const comment = Comment.create(author, content, initials);\n return this.register(comment);\n }\n\n /**\n * Creates and registers a reply to an existing comment\n * @param parentCommentId - ID of the parent comment\n * @param author - Reply author\n * @param content - Reply content (text or runs)\n * @param initials - Optional author initials\n * @returns The created and registered reply\n * @throws Error if parent comment doesn't exist\n */\n createReply(\n parentCommentId: number,\n author: string,\n content: string | Run | Run[],\n initials?: string\n ): Comment {\n // Verify parent exists\n if (!this.comments.has(parentCommentId)) {\n throw new Error(\n `Cannot create reply: parent comment with ID ${parentCommentId} does not exist`\n );\n }\n\n const reply = Comment.createReply(parentCommentId, author, content, initials);\n return this.register(reply);\n }\n\n /**\n * Checks if there are any comments\n * @returns True if there are no comments\n */\n isEmpty(): boolean {\n return this.comments.size === 0;\n }\n\n /**\n * Gets a comment thread (comment and all its replies)\n * @param commentId - ID of the top-level comment\n * @returns Object with the comment and its replies\n */\n getCommentThread(commentId: number): { comment: Comment; replies: Comment[] } | undefined {\n const entry = this.comments.get(commentId);\n if (!entry || entry.comment.isReply()) {\n return undefined;\n }\n return {\n comment: entry.comment,\n replies: [...entry.replies],\n };\n }\n\n /**\n * Searches comments by text content\n * @param searchText - Text to search for (case-insensitive)\n * @returns Array of comments containing the search text\n */\n findCommentsByText(searchText: string): Comment[] {\n const lowerSearch = searchText.toLowerCase();\n return Array.from(this.comments.values())\n .map((entry) => entry.comment)\n .filter((comment) => comment.getText().toLowerCase().includes(lowerSearch));\n }\n\n /**\n * Gets all resolved/done comments\n * @returns Array of resolved comments\n */\n getResolvedComments(): Comment[] {\n return Array.from(this.comments.values())\n .map((entry) => entry.comment)\n .filter((comment) => comment.isResolved());\n }\n\n /**\n * Gets all unresolved comments\n * @returns Array of unresolved comments\n */\n getUnresolvedComments(): Comment[] {\n return Array.from(this.comments.values())\n .map((entry) => entry.comment)\n .filter((comment) => !comment.isResolved());\n }\n\n /**\n * Gets the most recent comments\n * @param count - Number of recent comments to return\n * @returns Array of most recent comments\n */\n getRecentComments(count: number): Comment[] {\n const allComments = this.getAllCommentsWithReplies();\n return allComments\n .sort((a, b) => b.getDate().getTime() - a.getDate().getTime())\n .slice(0, count);\n }\n\n /**\n * Gets statistics about comments\n * @returns Object with comment statistics\n */\n getStats(): {\n total: number;\n topLevel: number;\n replies: number;\n resolved: number;\n unresolved: number;\n authors: string[];\n nextId: number;\n } {\n const topLevel = this.getTopLevelCount();\n const resolved = this.getResolvedComments().length;\n return {\n total: this.comments.size,\n topLevel,\n replies: this.comments.size - topLevel,\n resolved,\n unresolved: this.comments.size - resolved,\n authors: this.getAuthors(),\n nextId: this.nextId,\n };\n }\n\n /**\n * Generates the word/comments.xml file content\n * @returns XML string for comments.xml\n */\n generateCommentsXml(): string {\n const comments = this.getAllCommentsWithReplies();\n\n if (comments.length === 0) {\n // Return minimal comments.xml\n return `<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n<w:comments xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\">\n</w:comments>`;\n }\n\n // Build XML manually for comments\n const hasReplies = comments.some((c) => c.isReply());\n let xml = '<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\\n';\n xml += '<w:comments xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\"';\n xml += ' xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\"';\n if (hasReplies) {\n xml += ' xmlns:w15=\"http://schemas.microsoft.com/office/word/2012/wordml\"';\n xml +=\n ' xmlns:mc=\"http://schemas.openxmlformats.org/markup-compatibility/2006\" mc:Ignorable=\"w15\"';\n }\n xml += '>\\n';\n\n // Add each comment\n for (const comment of comments) {\n xml += this.commentToXmlString(comment);\n }\n\n xml += '</w:comments>';\n return xml;\n }\n\n /**\n * Converts a comment to XML string\n * @param comment - Comment to convert\n * @returns XML string for the comment\n */\n private commentToXmlString(comment: Comment): string {\n let xml = ` <w:comment w:id=\"${comment.getId()}\"`;\n xml += ` w:author=\"${XMLBuilder.escapeXmlAttribute(comment.getAuthor())}\"`;\n xml += ` w:date=\"${formatDateForXml(comment.getDate())}\"`;\n xml += ` w:initials=\"${XMLBuilder.escapeXmlAttribute(comment.getInitials())}\"`;\n\n if (comment.isReply() && comment.getParentId() !== undefined) {\n xml += ` w15:parentId=\"${comment.getParentId()}\"`;\n }\n\n // Add done attribute for resolved comments (per ECMA-376)\n if (comment.isResolved()) {\n xml += ` w:done=\"1\"`;\n }\n\n xml += '>\\n';\n\n // Add paragraph with runs\n xml += ' <w:p>\\n';\n for (const run of comment.getRuns()) {\n xml += this.runToXmlString(run, 6);\n }\n xml += ' </w:p>\\n';\n\n xml += ' </w:comment>\\n';\n return xml;\n }\n\n /**\n * Converts a run to XML string\n * @param run - Run to convert\n * @param indent - Number of spaces for indentation\n * @returns XML string for the run\n */\n private runToXmlString(run: Run, indent: number): string {\n const spaces = ' '.repeat(indent);\n const text = XMLBuilder.escapeXmlText(run.getText());\n\n let xml = `${spaces}<w:r>\\n`;\n xml += `${spaces} <w:t xml:space=\"preserve\">${text}</w:t>\\n`;\n xml += `${spaces}</w:r>\\n`;\n\n return xml;\n }\n\n /**\n * Creates a new CommentManager\n * @returns New CommentManager instance\n */\n static create(): CommentManager {\n return new CommentManager();\n }\n}\n"]}
1
+ {"version":3,"file":"CommentManager.js","sourceRoot":"","sources":["../../../src/elements/CommentManager.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC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C,IAAI,EAAE,CAAC,CAAC,CAAC;gBACtC,CAAC;qBAAM,CAAC;oBAGN,GAAG,IAAI,SAAS,IAAI,CAAC,MAAM,IAAI,CAAC;gBAClC,CAAC;YACH,CAAC;YACD,GAAG,IAAI,cAAc,CAAC;QACxB,CAAC;QAED,GAAG,IAAI,kBAAkB,CAAC;QAC1B,OAAO,GAAG,CAAC;IACb,CAAC;IAQO,cAAc,CAAC,GAAQ,EAAE,MAAc;QAC7C,MAAM,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QAGlC,OAAO,GAAG,MAAM,GAAG,UAAU,CAAC,eAAe,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC,IAAI,CAAC;IACjE,CAAC;IAMD,MAAM,CAAC,MAAM;QACX,OAAO,IAAI,cAAc,EAAE,CAAC;IAC9B,CAAC;CACF","sourcesContent":["/**\n * CommentManager - Manages comments in a document\n *\n * Tracks all comments, assigns unique IDs, handles replies,\n * and generates the comments.xml file.\n *\n * Per ECMA-376, comment IDs must be unique across ALL annotation types\n * in a document. Use setIdProvider() to connect to a centralized ID allocator.\n */\n\nimport { Comment } from './Comment.js';\nimport { Run } from './Run.js';\nimport { XMLBuilder } from '../xml/XMLBuilder.js';\nimport { formatDateForXml } from '../utils/dateFormatting.js';\n\n/**\n * Type for the centralized ID provider callback.\n * Returns the next available annotation ID from a shared counter.\n */\nexport type IdProviderCallback = () => number;\n\n/**\n * Type for callback to notify of existing IDs (for synchronization).\n * Called when registering existing comments to keep the central counter in sync.\n */\nexport type IdExistsCallback = (existingId: number) => void;\n\n/**\n * Comment entry stored by the manager\n */\ninterface CommentEntry {\n comment: Comment;\n /** Comments that are replies to this comment */\n replies: Comment[];\n}\n\n/**\n * Manages document comments\n */\nexport class CommentManager {\n private comments = new Map<number, CommentEntry>();\n private nextId = 0;\n private idProvider: IdProviderCallback | null = null;\n private idExistsNotifier: IdExistsCallback | null = null;\n private modifiedNotifier: (() => void) | null = null;\n\n /**\n * Sets the centralized ID provider callback.\n * When set, IDs will be allocated from the centralized DocumentIdManager\n * instead of the local nextId counter.\n *\n * @param provider - Callback that returns the next available ID\n * @param existsNotifier - Optional callback to notify when existing IDs are found\n */\n setIdProvider(provider: IdProviderCallback, existsNotifier?: IdExistsCallback): void {\n this.idProvider = provider;\n this.idExistsNotifier = existsNotifier || null;\n }\n\n /**\n * Sets the callback invoked when a registered comment is mutated.\n * Document wires this to its comments dirty flag so instance-level edits\n * (resolve, setAuthor, addRun, ...) force comments.xml regeneration\n * instead of being silently discarded by the original-XML passthrough.\n *\n * @param notifier - Callback invoked on any comment mutation\n */\n setModifiedNotifier(notifier: () => void): void {\n this.modifiedNotifier = notifier;\n for (const entry of this.comments.values()) {\n entry.comment.setModifiedCallback(notifier);\n }\n }\n\n /**\n * Registers a comment with the manager\n * Assigns a unique ID\n * @param comment - Comment to register\n * @returns The registered comment (same instance)\n */\n register(comment: Comment): Comment {\n // Assign unique ID - use centralized provider if available\n const id = this.idProvider ? this.idProvider() : this.nextId++;\n comment.setId(id);\n\n if (this.modifiedNotifier) {\n comment.setModifiedCallback(this.modifiedNotifier);\n }\n\n // Store comment\n const entry: CommentEntry = {\n comment,\n replies: [],\n };\n this.comments.set(comment.getId(), entry);\n\n // If this is a reply, add it to the parent's replies array\n if (comment.isReply() && comment.getParentId() !== undefined) {\n const parentEntry = this.comments.get(comment.getParentId()!);\n if (parentEntry) {\n parentEntry.replies.push(comment);\n }\n }\n\n return comment;\n }\n\n /**\n * Registers an existing comment (from parsing) with its pre-assigned ID.\n * Unlike register(), this does NOT assign a new ID - the comment must already have one.\n * Used when loading comments from an existing document.\n * @param comment - Comment with ID already set\n */\n registerExisting(comment: Comment): void {\n const id = comment.getId();\n\n // Notify centralized ID manager if connected\n if (this.idExistsNotifier) {\n this.idExistsNotifier(id);\n }\n\n if (this.modifiedNotifier) {\n comment.setModifiedCallback(this.modifiedNotifier);\n }\n\n // Store comment\n const entry: CommentEntry = {\n comment,\n replies: [],\n };\n this.comments.set(id, entry);\n\n // Update local nextId if needed\n if (id >= this.nextId) {\n this.nextId = id + 1;\n }\n }\n\n /**\n * Links reply comments to their parents after all comments are parsed.\n * Must be called after all comments are registered via registerExisting().\n * This builds the reply arrays for each parent comment.\n */\n linkReplies(): void {\n // Clear existing replies first for idempotency (safe to call multiple times)\n for (const entry of this.comments.values()) {\n entry.replies = [];\n }\n for (const entry of this.comments.values()) {\n const comment = entry.comment;\n if (comment.isReply() && comment.getParentId() !== undefined) {\n const parentEntry = this.comments.get(comment.getParentId()!);\n if (parentEntry) {\n parentEntry.replies.push(comment);\n }\n }\n }\n }\n\n /**\n * Gets a comment by ID\n * @param id - Comment ID\n * @returns The comment, or undefined if not found\n */\n getComment(id: number): Comment | undefined {\n return this.comments.get(id)?.comment;\n }\n\n /**\n * Gets all comments (top-level only, not replies)\n * @returns Array of all top-level comments\n */\n getAllComments(): Comment[] {\n return Array.from(this.comments.values())\n .filter((entry) => !entry.comment.isReply())\n .map((entry) => entry.comment);\n }\n\n /**\n * Gets all comments including replies\n * @returns Array of all comments\n */\n getAllCommentsWithReplies(): Comment[] {\n return Array.from(this.comments.values()).map((entry) => entry.comment);\n }\n\n /**\n * Gets replies to a comment\n * @param commentId - ID of the parent comment\n * @returns Array of reply comments\n */\n getReplies(commentId: number): Comment[] {\n const entry = this.comments.get(commentId);\n return entry ? [...entry.replies] : [];\n }\n\n /**\n * Checks if a comment has replies\n * @param commentId - ID of the comment\n * @returns True if the comment has replies\n */\n hasReplies(commentId: number): boolean {\n const entry = this.comments.get(commentId);\n return entry ? entry.replies.length > 0 : false;\n }\n\n /**\n * Gets the number of comments (including replies)\n * @returns Number of comments\n */\n getCount(): number {\n return this.comments.size;\n }\n\n /**\n * Gets the number of top-level comments (excluding replies)\n * @returns Number of top-level comments\n */\n getTopLevelCount(): number {\n return this.getAllComments().length;\n }\n\n /**\n * Gets all unique authors who have made comments\n * @returns Array of unique author names\n */\n getAuthors(): string[] {\n const authorsSet = new Set<string>();\n for (const entry of this.comments.values()) {\n authorsSet.add(entry.comment.getAuthor());\n }\n return Array.from(authorsSet);\n }\n\n /**\n * Gets comments by author\n * @param author - Author name to filter by\n * @returns Array of comments by the specified author\n */\n getCommentsByAuthor(author: string): Comment[] {\n return Array.from(this.comments.values())\n .map((entry) => entry.comment)\n .filter((comment) => comment.getAuthor() === author);\n }\n\n /**\n * Gets comments within a date range\n * @param startDate - Start of date range\n * @param endDate - End of date range\n * @returns Array of comments within the date range\n */\n getCommentsByDateRange(startDate: Date, endDate: Date): Comment[] {\n return Array.from(this.comments.values())\n .map((entry) => entry.comment)\n .filter((comment) => {\n const commentDate = comment.getDate();\n return commentDate >= startDate && commentDate <= endDate;\n });\n }\n\n /**\n * Removes a comment\n * Also removes all replies to that comment\n * @param id - Comment ID\n * @returns True if the comment was removed\n */\n removeComment(id: number): boolean {\n const entry = this.comments.get(id);\n if (!entry) {\n return false;\n }\n\n // Remove all replies first\n for (const reply of entry.replies) {\n this.comments.delete(reply.getId());\n }\n\n // A reply is also tracked in its parent's replies array — drop it there\n // too so getReplies()/hasReplies()/getCommentThread() agree with the map\n const parentId = entry.comment.getParentId();\n if (parentId !== undefined) {\n const parentEntry = this.comments.get(parentId);\n if (parentEntry) {\n parentEntry.replies = parentEntry.replies.filter((reply) => reply !== entry.comment);\n }\n }\n\n // Remove the comment itself\n return this.comments.delete(id);\n }\n\n /**\n * Clears all comments\n */\n clear(): void {\n this.comments.clear();\n this.nextId = 0;\n }\n\n /**\n * Sets the next ID to be assigned.\n * Used when loading documents to avoid ID collisions with existing comments.\n * @param id - The next ID value to use\n */\n setNextId(id: number): void {\n this.nextId = id;\n }\n\n /**\n * Creates and registers a new comment\n * @param author - Comment author\n * @param content - Comment content (text or runs)\n * @param initials - Optional author initials\n * @returns The created and registered comment\n */\n createComment(author: string, content: string | Run | Run[], initials?: string): Comment {\n const comment = Comment.create(author, content, initials);\n return this.register(comment);\n }\n\n /**\n * Creates and registers a reply to an existing comment\n * @param parentCommentId - ID of the parent comment\n * @param author - Reply author\n * @param content - Reply content (text or runs)\n * @param initials - Optional author initials\n * @returns The created and registered reply\n * @throws Error if parent comment doesn't exist\n */\n createReply(\n parentCommentId: number,\n author: string,\n content: string | Run | Run[],\n initials?: string\n ): Comment {\n // Verify parent exists\n if (!this.comments.has(parentCommentId)) {\n throw new Error(\n `Cannot create reply: parent comment with ID ${parentCommentId} does not exist`\n );\n }\n\n const reply = Comment.createReply(parentCommentId, author, content, initials);\n return this.register(reply);\n }\n\n /**\n * Checks if there are any comments\n * @returns True if there are no comments\n */\n isEmpty(): boolean {\n return this.comments.size === 0;\n }\n\n /**\n * Gets a comment thread (comment and all its replies)\n * @param commentId - ID of the top-level comment\n * @returns Object with the comment and its replies\n */\n getCommentThread(commentId: number): { comment: Comment; replies: Comment[] } | undefined {\n const entry = this.comments.get(commentId);\n if (!entry || entry.comment.isReply()) {\n return undefined;\n }\n return {\n comment: entry.comment,\n replies: [...entry.replies],\n };\n }\n\n /**\n * Searches comments by text content\n * @param searchText - Text to search for (case-insensitive)\n * @returns Array of comments containing the search text\n */\n findCommentsByText(searchText: string): Comment[] {\n const lowerSearch = searchText.toLowerCase();\n return Array.from(this.comments.values())\n .map((entry) => entry.comment)\n .filter((comment) => comment.getText().toLowerCase().includes(lowerSearch));\n }\n\n /**\n * Gets all resolved/done comments\n * @returns Array of resolved comments\n */\n getResolvedComments(): Comment[] {\n return Array.from(this.comments.values())\n .map((entry) => entry.comment)\n .filter((comment) => comment.isResolved());\n }\n\n /**\n * Gets all unresolved comments\n * @returns Array of unresolved comments\n */\n getUnresolvedComments(): Comment[] {\n return Array.from(this.comments.values())\n .map((entry) => entry.comment)\n .filter((comment) => !comment.isResolved());\n }\n\n /**\n * Gets the most recent comments\n * @param count - Number of recent comments to return\n * @returns Array of most recent comments\n */\n getRecentComments(count: number): Comment[] {\n const allComments = this.getAllCommentsWithReplies();\n return allComments\n .sort((a, b) => b.getDate().getTime() - a.getDate().getTime())\n .slice(0, count);\n }\n\n /**\n * Gets statistics about comments\n * @returns Object with comment statistics\n */\n getStats(): {\n total: number;\n topLevel: number;\n replies: number;\n resolved: number;\n unresolved: number;\n authors: string[];\n nextId: number;\n } {\n const topLevel = this.getTopLevelCount();\n const resolved = this.getResolvedComments().length;\n return {\n total: this.comments.size,\n topLevel,\n replies: this.comments.size - topLevel,\n resolved,\n unresolved: this.comments.size - resolved,\n authors: this.getAuthors(),\n nextId: this.nextId,\n };\n }\n\n /**\n * Generates the word/comments.xml file content\n * @returns XML string for comments.xml\n */\n generateCommentsXml(): string {\n const comments = this.getAllCommentsWithReplies();\n\n if (comments.length === 0) {\n // Return minimal comments.xml\n return `<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n<w:comments xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\">\n</w:comments>`;\n }\n\n // Build XML manually for comments\n const hasReplies = comments.some((c) => c.isReply());\n const hasResolved = comments.some((c) => c.isResolved());\n let xml = '<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\\n';\n xml += '<w:comments xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\"';\n xml += ' xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\"';\n if (hasResolved) {\n xml += ' xmlns:w14=\"http://schemas.microsoft.com/office/word/2010/wordml\"';\n }\n if (hasReplies) {\n xml += ' xmlns:w15=\"http://schemas.microsoft.com/office/word/2012/wordml\"';\n }\n if (hasReplies || hasResolved) {\n const ignorable = [hasResolved ? 'w14' : '', hasReplies ? 'w15' : '']\n .filter((ns) => ns.length > 0)\n .join(' ');\n xml += ` xmlns:mc=\"http://schemas.openxmlformats.org/markup-compatibility/2006\" mc:Ignorable=\"${ignorable}\"`;\n }\n xml += '>\\n';\n\n // Add each comment. CT_Comment declares no resolved-state attribute —\n // that lives in commentsExtended.xml keyed by the w14:paraId of each\n // comment's last paragraph, so emit those anchors when any comment is\n // resolved (see generateCommentsExtendedXml)\n for (const comment of comments) {\n xml += this.commentToXmlString(\n comment,\n hasResolved ? CommentManager.commentParaId(comment.getId()) : undefined\n );\n }\n\n xml += '</w:comments>';\n return xml;\n }\n\n /**\n * Derives the w14:paraId anchor for a comment's last paragraph.\n * Deterministic so comments.xml and commentsExtended.xml agree without\n * shared state. Values must be 8 hex digits, nonzero, and below\n * 0x80000000 per ST_LongHexNumber conventions for paraId.\n * @param commentId - Comment ID\n * @returns 8-character uppercase hex paraId\n */\n static commentParaId(commentId: number): string {\n return ((commentId + 1) & 0x7fffffff).toString(16).toUpperCase().padStart(8, '0');\n }\n\n /**\n * Generates the word/commentsExtended.xml content carrying resolved\n * state (w15:done) and reply threading (w15:paraIdParent).\n * @returns XML string, or null when no comment is resolved (the part is\n * only regenerated when it carries information)\n */\n generateCommentsExtendedXml(): string | null {\n const comments = this.getAllCommentsWithReplies();\n if (!comments.some((c) => c.isResolved())) {\n return null;\n }\n\n let xml = '<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\\n';\n xml += '<w15:commentsEx xmlns:mc=\"http://schemas.openxmlformats.org/markup-compatibility/2006\"';\n xml +=\n ' xmlns:w15=\"http://schemas.microsoft.com/office/word/2012/wordml\" mc:Ignorable=\"w15\">\\n';\n for (const comment of comments) {\n xml += ` <w15:commentEx w15:paraId=\"${CommentManager.commentParaId(comment.getId())}\"`;\n const parentId = comment.getParentId();\n if (parentId !== undefined && this.comments.has(parentId)) {\n xml += ` w15:paraIdParent=\"${CommentManager.commentParaId(parentId)}\"`;\n }\n xml += ` w15:done=\"${comment.isResolved() ? '1' : '0'}\"/>\\n`;\n }\n xml += '</w15:commentsEx>';\n return xml;\n }\n\n /**\n * Converts a comment to XML string\n * @param comment - Comment to convert\n * @param paraId - w14:paraId to anchor on the last paragraph (links the\n * comment to its commentsExtended.xml entry), omitted when no comment\n * in the document is resolved\n * @returns XML string for the comment\n */\n private commentToXmlString(comment: Comment, paraId?: string): string {\n let xml = ` <w:comment w:id=\"${comment.getId()}\"`;\n xml += ` w:author=\"${XMLBuilder.escapeXmlAttribute(comment.getAuthor())}\"`;\n xml += ` w:date=\"${formatDateForXml(comment.getDate())}\"`;\n xml += ` w:initials=\"${XMLBuilder.escapeXmlAttribute(comment.getInitials())}\"`;\n\n if (comment.isReply() && comment.getParentId() !== undefined) {\n xml += ` w15:parentId=\"${comment.getParentId()}\"`;\n }\n\n xml += '>\\n';\n\n // One <w:p> per stored paragraph — collapsing into a single paragraph\n // concatenates words across the lost boundaries and drops paragraph\n // properties (CommentText pStyle) of parsed comments\n const paragraphs = comment.getParagraphs();\n for (let i = 0; i < paragraphs.length; i++) {\n const paragraph = paragraphs[i]!;\n // commentsExtended.xml entries reference the LAST paragraph's paraId\n const isLast = i === paragraphs.length - 1;\n xml += isLast && paraId ? ` <w:p w14:paraId=\"${paraId}\">\\n` : ' <w:p>\\n';\n if (paragraph.pPr) {\n xml += ` ${paragraph.pPr}\\n`;\n }\n for (const item of paragraph.content) {\n if (item instanceof Run) {\n xml += this.runToXmlString(item, 6);\n } else {\n // Preserved inline XML (e.g. w:hyperlink) re-emitted verbatim so\n // its r:id target keeps pointing at word/_rels/comments.xml.rels\n xml += ` ${item.rawXml}\\n`;\n }\n }\n xml += ' </w:p>\\n';\n }\n\n xml += ' </w:comment>\\n';\n return xml;\n }\n\n /**\n * Converts a run to XML string\n * @param run - Run to convert\n * @param indent - Number of spaces for indentation\n * @returns XML string for the run\n */\n private runToXmlString(run: Run, indent: number): string {\n const spaces = ' '.repeat(indent);\n // Serialize through Run.toXML() so w:rPr formatting and non-text\n // content (w:annotationRef, tabs, breaks) survive regeneration\n return `${spaces}${XMLBuilder.elementToString(run.toXML())}\\n`;\n }\n\n /**\n * Creates a new CommentManager\n * @returns New CommentManager instance\n */\n static create(): CommentManager {\n return new CommentManager();\n }\n}\n"]}