docxmlater 10.0.1 → 10.0.3

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 (395) hide show
  1. package/README.md +3 -2
  2. package/dist/constants/legacyCompatFlags.d.ts.map +1 -1
  3. package/dist/constants/legacyCompatFlags.js.map +1 -1
  4. package/dist/constants/limits.d.ts +0 -27
  5. package/dist/constants/limits.d.ts.map +1 -1
  6. package/dist/constants/limits.js +13 -13
  7. package/dist/constants/limits.js.map +1 -1
  8. package/dist/core/Document.d.ts +24 -19
  9. package/dist/core/Document.d.ts.map +1 -1
  10. package/dist/core/Document.js +272 -71
  11. package/dist/core/Document.js.map +1 -1
  12. package/dist/core/DocumentContent.d.ts.map +1 -1
  13. package/dist/core/DocumentContent.js.map +1 -1
  14. package/dist/core/DocumentGenerator.d.ts.map +1 -1
  15. package/dist/core/DocumentGenerator.js +59 -24
  16. package/dist/core/DocumentGenerator.js.map +1 -1
  17. package/dist/core/DocumentIdManager.d.ts.map +1 -1
  18. package/dist/core/DocumentIdManager.js.map +1 -1
  19. package/dist/core/DocumentParser.d.ts +6 -6
  20. package/dist/core/DocumentParser.d.ts.map +1 -1
  21. package/dist/core/DocumentParser.js +60 -54
  22. package/dist/core/DocumentParser.js.map +1 -1
  23. package/dist/core/DocumentValidator.d.ts.map +1 -1
  24. package/dist/core/DocumentValidator.js.map +1 -1
  25. package/dist/core/Relationship.d.ts.map +1 -1
  26. package/dist/core/Relationship.js +1 -1
  27. package/dist/core/Relationship.js.map +1 -1
  28. package/dist/core/RelationshipManager.js +3 -3
  29. package/dist/core/RelationshipManager.js.map +1 -1
  30. package/dist/elements/AlternateContent.js.map +1 -1
  31. package/dist/elements/Bookmark.d.ts.map +1 -1
  32. package/dist/elements/Bookmark.js.map +1 -1
  33. package/dist/elements/BookmarkManager.d.ts.map +1 -1
  34. package/dist/elements/BookmarkManager.js.map +1 -1
  35. package/dist/elements/Comment.js +1 -1
  36. package/dist/elements/Comment.js.map +1 -1
  37. package/dist/elements/CommentManager.d.ts.map +1 -1
  38. package/dist/elements/CommentManager.js +8 -2
  39. package/dist/elements/CommentManager.js.map +1 -1
  40. package/dist/elements/CommonTypes.d.ts.map +1 -1
  41. package/dist/elements/CommonTypes.js +1 -2
  42. package/dist/elements/CommonTypes.js.map +1 -1
  43. package/dist/elements/CustomXml.js.map +1 -1
  44. package/dist/elements/Endnote.d.ts.map +1 -1
  45. package/dist/elements/Endnote.js.map +1 -1
  46. package/dist/elements/EndnoteManager.d.ts.map +1 -1
  47. package/dist/elements/EndnoteManager.js.map +1 -1
  48. package/dist/elements/Field.d.ts.map +1 -1
  49. package/dist/elements/Field.js +31 -28
  50. package/dist/elements/Field.js.map +1 -1
  51. package/dist/elements/FieldHelpers.d.ts.map +1 -1
  52. package/dist/elements/FieldHelpers.js +6 -6
  53. package/dist/elements/FieldHelpers.js.map +1 -1
  54. package/dist/elements/FontManager.d.ts.map +1 -1
  55. package/dist/elements/FontManager.js.map +1 -1
  56. package/dist/elements/Footer.js.map +1 -1
  57. package/dist/elements/Footnote.d.ts.map +1 -1
  58. package/dist/elements/Footnote.js.map +1 -1
  59. package/dist/elements/FootnoteManager.d.ts.map +1 -1
  60. package/dist/elements/FootnoteManager.js.map +1 -1
  61. package/dist/elements/Header.js.map +1 -1
  62. package/dist/elements/HeaderFooterManager.js.map +1 -1
  63. package/dist/elements/Hyperlink.d.ts.map +1 -1
  64. package/dist/elements/Hyperlink.js +5 -5
  65. package/dist/elements/Hyperlink.js.map +1 -1
  66. package/dist/elements/Image.d.ts +2 -2
  67. package/dist/elements/Image.d.ts.map +1 -1
  68. package/dist/elements/Image.js +21 -5
  69. package/dist/elements/Image.js.map +1 -1
  70. package/dist/elements/ImageManager.d.ts.map +1 -1
  71. package/dist/elements/ImageManager.js +2 -2
  72. package/dist/elements/ImageManager.js.map +1 -1
  73. package/dist/elements/ImageRun.js.map +1 -1
  74. package/dist/elements/MathElement.js.map +1 -1
  75. package/dist/elements/Paragraph.d.ts.map +1 -1
  76. package/dist/elements/Paragraph.js +128 -117
  77. package/dist/elements/Paragraph.js.map +1 -1
  78. package/dist/elements/PreservedElement.js.map +1 -1
  79. package/dist/elements/PropertyChangeTypes.js.map +1 -1
  80. package/dist/elements/RangeMarker.js.map +1 -1
  81. package/dist/elements/Revision.d.ts +1 -0
  82. package/dist/elements/Revision.d.ts.map +1 -1
  83. package/dist/elements/Revision.js +44 -5
  84. package/dist/elements/Revision.js.map +1 -1
  85. package/dist/elements/RevisionContent.js.map +1 -1
  86. package/dist/elements/RevisionManager.d.ts.map +1 -1
  87. package/dist/elements/RevisionManager.js.map +1 -1
  88. package/dist/elements/Run.d.ts.map +1 -1
  89. package/dist/elements/Run.js +1 -3
  90. package/dist/elements/Run.js.map +1 -1
  91. package/dist/elements/Section.d.ts.map +1 -1
  92. package/dist/elements/Section.js +127 -118
  93. package/dist/elements/Section.js.map +1 -1
  94. package/dist/elements/Shape.d.ts.map +1 -1
  95. package/dist/elements/Shape.js +21 -0
  96. package/dist/elements/Shape.js.map +1 -1
  97. package/dist/elements/StructuredDocumentTag.d.ts.map +1 -1
  98. package/dist/elements/StructuredDocumentTag.js +20 -8
  99. package/dist/elements/StructuredDocumentTag.js.map +1 -1
  100. package/dist/elements/Table.d.ts +2 -2
  101. package/dist/elements/Table.d.ts.map +1 -1
  102. package/dist/elements/Table.js +29 -35
  103. package/dist/elements/Table.js.map +1 -1
  104. package/dist/elements/TableCell.d.ts +2 -2
  105. package/dist/elements/TableCell.d.ts.map +1 -1
  106. package/dist/elements/TableCell.js +63 -67
  107. package/dist/elements/TableCell.js.map +1 -1
  108. package/dist/elements/TableGridChange.js.map +1 -1
  109. package/dist/elements/TableOfContents.d.ts +6 -6
  110. package/dist/elements/TableOfContents.d.ts.map +1 -1
  111. package/dist/elements/TableOfContents.js.map +1 -1
  112. package/dist/elements/TableOfContentsElement.js.map +1 -1
  113. package/dist/elements/TableRow.d.ts.map +1 -1
  114. package/dist/elements/TableRow.js +65 -47
  115. package/dist/elements/TableRow.js.map +1 -1
  116. package/dist/elements/TextBox.d.ts.map +1 -1
  117. package/dist/elements/TextBox.js +1 -1
  118. package/dist/elements/TextBox.js.map +1 -1
  119. package/dist/formatting/AbstractNumbering.d.ts +1 -1
  120. package/dist/formatting/AbstractNumbering.d.ts.map +1 -1
  121. package/dist/formatting/AbstractNumbering.js +11 -11
  122. package/dist/formatting/AbstractNumbering.js.map +1 -1
  123. package/dist/formatting/NumberingInstance.d.ts.map +1 -1
  124. package/dist/formatting/NumberingInstance.js +4 -4
  125. package/dist/formatting/NumberingInstance.js.map +1 -1
  126. package/dist/formatting/NumberingLevel.d.ts.map +1 -1
  127. package/dist/formatting/NumberingLevel.js +26 -26
  128. package/dist/formatting/NumberingLevel.js.map +1 -1
  129. package/dist/formatting/NumberingManager.d.ts +1 -1
  130. package/dist/formatting/NumberingManager.d.ts.map +1 -1
  131. package/dist/formatting/NumberingManager.js.map +1 -1
  132. package/dist/formatting/Style.d.ts.map +1 -1
  133. package/dist/formatting/Style.js +87 -95
  134. package/dist/formatting/Style.js.map +1 -1
  135. package/dist/formatting/StylesManager.d.ts +3 -3
  136. package/dist/formatting/StylesManager.d.ts.map +1 -1
  137. package/dist/formatting/StylesManager.js.map +1 -1
  138. package/dist/helpers/CleanupHelper.d.ts.map +1 -1
  139. package/dist/helpers/CleanupHelper.js +1 -7
  140. package/dist/helpers/CleanupHelper.js.map +1 -1
  141. package/dist/images/ImageOptimizer.js.map +1 -1
  142. package/dist/index.js.map +1 -1
  143. package/dist/managers/DrawingManager.d.ts.map +1 -1
  144. package/dist/managers/DrawingManager.js.map +1 -1
  145. package/dist/tracking/DocumentTrackingContext.js.map +1 -1
  146. package/dist/tracking/TrackingContext.js.map +1 -1
  147. package/dist/types/compatibility-types.js.map +1 -1
  148. package/dist/types/formatting.js.map +1 -1
  149. package/dist/types/list-types.d.ts +4 -4
  150. package/dist/types/list-types.d.ts.map +1 -1
  151. package/dist/types/list-types.js.map +1 -1
  152. package/dist/types/settings-types.js.map +1 -1
  153. package/dist/types/styleConfig.js.map +1 -1
  154. package/dist/utils/ChangelogGenerator.d.ts.map +1 -1
  155. package/dist/utils/ChangelogGenerator.js.map +1 -1
  156. package/dist/utils/CompatibilityUpgrader.d.ts.map +1 -1
  157. package/dist/utils/CompatibilityUpgrader.js +7 -7
  158. package/dist/utils/CompatibilityUpgrader.js.map +1 -1
  159. package/dist/utils/InMemoryRevisionAcceptor.js +1 -1
  160. package/dist/utils/InMemoryRevisionAcceptor.js.map +1 -1
  161. package/dist/utils/MoveOperationHelper.js.map +1 -1
  162. package/dist/utils/RevisionAwareProcessor.js.map +1 -1
  163. package/dist/utils/RevisionWalker.js.map +1 -1
  164. package/dist/utils/SelectiveRevisionAcceptor.js.map +1 -1
  165. package/dist/utils/ShadingResolver.js +1 -1
  166. package/dist/utils/ShadingResolver.js.map +1 -1
  167. package/dist/utils/acceptRevisions.d.ts +0 -28
  168. package/dist/utils/acceptRevisions.d.ts.map +1 -1
  169. package/dist/utils/acceptRevisions.js +5 -7
  170. package/dist/utils/acceptRevisions.js.map +1 -1
  171. package/dist/utils/cnfStyleDecoder.js +1 -1
  172. package/dist/utils/cnfStyleDecoder.js.map +1 -1
  173. package/dist/utils/corruptionDetection.js.map +1 -1
  174. package/dist/utils/dateFormatting.js.map +1 -1
  175. package/dist/utils/deepClone.d.ts +0 -1
  176. package/dist/utils/deepClone.d.ts.map +1 -1
  177. package/dist/utils/deepClone.js +0 -7
  178. package/dist/utils/deepClone.js.map +1 -1
  179. package/dist/utils/diagnostics.d.ts +2 -2
  180. package/dist/utils/diagnostics.d.ts.map +1 -1
  181. package/dist/utils/diagnostics.js.map +1 -1
  182. package/dist/utils/errorHandling.js.map +1 -1
  183. package/dist/utils/formatting.js.map +1 -1
  184. package/dist/utils/list-detection.d.ts +2 -2
  185. package/dist/utils/list-detection.d.ts.map +1 -1
  186. package/dist/utils/list-detection.js +3 -3
  187. package/dist/utils/list-detection.js.map +1 -1
  188. package/dist/utils/logger.d.ts +2 -4
  189. package/dist/utils/logger.d.ts.map +1 -1
  190. package/dist/utils/logger.js +0 -2
  191. package/dist/utils/logger.js.map +1 -1
  192. package/dist/utils/parsingHelpers.js.map +1 -1
  193. package/dist/utils/stripTrackedChanges.d.ts +0 -19
  194. package/dist/utils/stripTrackedChanges.d.ts.map +1 -1
  195. package/dist/utils/stripTrackedChanges.js +0 -2
  196. package/dist/utils/stripTrackedChanges.js.map +1 -1
  197. package/dist/utils/textDiff.js.map +1 -1
  198. package/dist/utils/units.js.map +1 -1
  199. package/dist/utils/validation.d.ts.map +1 -1
  200. package/dist/utils/validation.js.map +1 -1
  201. package/dist/utils/xmlSanitization.js.map +1 -1
  202. package/dist/validation/RevisionAutoFixer.js.map +1 -1
  203. package/dist/validation/RevisionValidator.js.map +1 -1
  204. package/dist/validation/ValidationRules.js.map +1 -1
  205. package/dist/validation/index.js.map +1 -1
  206. package/dist/xml/XMLBuilder.d.ts.map +1 -1
  207. package/dist/xml/XMLBuilder.js +10 -0
  208. package/dist/xml/XMLBuilder.js.map +1 -1
  209. package/dist/xml/XMLParser.d.ts.map +1 -1
  210. package/dist/xml/XMLParser.js +4 -5
  211. package/dist/xml/XMLParser.js.map +1 -1
  212. package/dist/zip/ZipHandler.js.map +1 -1
  213. package/dist/zip/ZipReader.js.map +1 -1
  214. package/dist/zip/ZipWriter.js.map +1 -1
  215. package/dist/zip/errors.js.map +1 -1
  216. package/dist/zip/types.js.map +1 -1
  217. package/package.json +34 -4
  218. package/src/__tests__/helper-methods.test.ts +512 -0
  219. package/src/constants/legacyCompatFlags.ts +138 -0
  220. package/src/constants/limits.ts +50 -0
  221. package/src/core/CLAUDE.md +109 -0
  222. package/src/core/Document.ts +15569 -0
  223. package/src/core/DocumentContent.ts +467 -0
  224. package/src/core/DocumentGenerator.ts +1104 -0
  225. package/src/core/DocumentIdManager.ts +158 -0
  226. package/src/core/DocumentParser.ts +10107 -0
  227. package/src/core/DocumentValidator.ts +372 -0
  228. package/src/core/Relationship.ts +367 -0
  229. package/src/core/RelationshipManager.ts +428 -0
  230. package/src/elements/AlternateContent.ts +42 -0
  231. package/src/elements/Bookmark.ts +210 -0
  232. package/src/elements/BookmarkManager.ts +250 -0
  233. package/src/elements/CLAUDE.md +126 -0
  234. package/src/elements/Comment.ts +359 -0
  235. package/src/elements/CommentManager.ts +502 -0
  236. package/src/elements/CommonTypes.ts +549 -0
  237. package/src/elements/CustomXml.ts +36 -0
  238. package/src/elements/Endnote.ts +217 -0
  239. package/src/elements/EndnoteManager.ts +249 -0
  240. package/src/elements/Field.ts +1233 -0
  241. package/src/elements/FieldHelpers.ts +333 -0
  242. package/src/elements/FontManager.ts +339 -0
  243. package/src/elements/Footer.ts +269 -0
  244. package/src/elements/Footnote.ts +217 -0
  245. package/src/elements/FootnoteManager.ts +249 -0
  246. package/src/elements/Header.ts +269 -0
  247. package/src/elements/HeaderFooterManager.ts +219 -0
  248. package/src/elements/Hyperlink.ts +1146 -0
  249. package/src/elements/Image.ts +1756 -0
  250. package/src/elements/ImageManager.ts +432 -0
  251. package/src/elements/ImageRun.ts +59 -0
  252. package/src/elements/MathElement.ts +65 -0
  253. package/src/elements/Paragraph.ts +4227 -0
  254. package/src/elements/PreservedElement.ts +53 -0
  255. package/src/elements/PropertyChangeTypes.ts +442 -0
  256. package/src/elements/RangeMarker.ts +400 -0
  257. package/src/elements/Revision.ts +1217 -0
  258. package/src/elements/RevisionContent.ts +73 -0
  259. package/src/elements/RevisionManager.ts +1070 -0
  260. package/src/elements/Run.ts +3068 -0
  261. package/src/elements/Section.ts +1421 -0
  262. package/src/elements/Shape.ts +873 -0
  263. package/src/elements/StructuredDocumentTag.ts +978 -0
  264. package/src/elements/Table.ts +2524 -0
  265. package/src/elements/TableCell.ts +1586 -0
  266. package/src/elements/TableGridChange.ts +151 -0
  267. package/src/elements/TableOfContents.ts +691 -0
  268. package/src/elements/TableOfContentsElement.ts +89 -0
  269. package/src/elements/TableRow.ts +906 -0
  270. package/src/elements/TextBox.ts +768 -0
  271. package/src/formatting/AbstractNumbering.ts +548 -0
  272. package/src/formatting/CLAUDE.md +74 -0
  273. package/src/formatting/NumberingInstance.ts +212 -0
  274. package/src/formatting/NumberingLevel.ts +1006 -0
  275. package/src/formatting/NumberingManager.ts +827 -0
  276. package/src/formatting/Style.ts +1833 -0
  277. package/src/formatting/StylesManager.ts +1005 -0
  278. package/src/helpers/CleanupHelper.ts +524 -0
  279. package/src/images/ImageOptimizer.ts +274 -0
  280. package/src/index.ts +554 -0
  281. package/src/managers/CLAUDE.md +47 -0
  282. package/src/managers/DrawingManager.ts +319 -0
  283. package/src/tracking/DocumentTrackingContext.ts +643 -0
  284. package/src/tracking/TrackingContext.ts +173 -0
  285. package/src/types/compatibility-types.ts +49 -0
  286. package/src/types/formatting.ts +210 -0
  287. package/src/types/list-types.ts +152 -0
  288. package/src/types/settings-types.ts +59 -0
  289. package/src/types/styleConfig.ts +189 -0
  290. package/src/utils/CLAUDE.md +153 -0
  291. package/src/utils/ChangelogGenerator.ts +1581 -0
  292. package/src/utils/CompatibilityUpgrader.ts +237 -0
  293. package/src/utils/InMemoryRevisionAcceptor.ts +668 -0
  294. package/src/utils/MoveOperationHelper.ts +238 -0
  295. package/src/utils/RevisionAwareProcessor.ts +526 -0
  296. package/src/utils/RevisionWalker.ts +457 -0
  297. package/src/utils/SelectiveRevisionAcceptor.ts +613 -0
  298. package/src/utils/ShadingResolver.ts +107 -0
  299. package/src/utils/acceptRevisions.ts +714 -0
  300. package/src/utils/cnfStyleDecoder.ts +217 -0
  301. package/src/utils/corruptionDetection.ts +345 -0
  302. package/src/utils/dateFormatting.ts +20 -0
  303. package/src/utils/deepClone.ts +78 -0
  304. package/src/utils/diagnostics.ts +129 -0
  305. package/src/utils/errorHandling.ts +80 -0
  306. package/src/utils/formatting.ts +213 -0
  307. package/src/utils/list-detection.ts +274 -0
  308. package/src/utils/logger.ts +404 -0
  309. package/src/utils/parsingHelpers.ts +190 -0
  310. package/src/utils/stripTrackedChanges.ts +353 -0
  311. package/src/utils/textDiff.ts +100 -0
  312. package/src/utils/units.ts +421 -0
  313. package/src/utils/validation.ts +542 -0
  314. package/src/utils/xmlSanitization.ts +182 -0
  315. package/src/validation/RevisionAutoFixer.ts +542 -0
  316. package/src/validation/RevisionValidator.ts +460 -0
  317. package/src/validation/ValidationRules.ts +338 -0
  318. package/src/validation/index.ts +30 -0
  319. package/src/xml/CLAUDE.md +65 -0
  320. package/src/xml/XMLBuilder.ts +871 -0
  321. package/src/xml/XMLParser.ts +919 -0
  322. package/src/zip/CLAUDE.md +55 -0
  323. package/src/zip/ZipHandler.ts +637 -0
  324. package/src/zip/ZipReader.ts +299 -0
  325. package/src/zip/ZipWriter.ts +390 -0
  326. package/src/zip/errors.ts +69 -0
  327. package/src/zip/types.ts +116 -0
  328. package/dist/core/ListNormalizer.d.ts +0 -23
  329. package/dist/core/ListNormalizer.d.ts.map +0 -1
  330. package/dist/core/ListNormalizer.js +0 -624
  331. package/dist/core/ListNormalizer.js.map +0 -1
  332. package/dist/images/index.d.ts +0 -2
  333. package/dist/images/index.d.ts.map +0 -1
  334. package/dist/images/index.js +0 -8
  335. package/dist/images/index.js.map +0 -1
  336. package/dist/ms-doc/cfb/CFBReader.d.ts +0 -35
  337. package/dist/ms-doc/cfb/CFBReader.d.ts.map +0 -1
  338. package/dist/ms-doc/cfb/CFBReader.js +0 -360
  339. package/dist/ms-doc/cfb/CFBReader.js.map +0 -1
  340. package/dist/ms-doc/converter/DocToDocxConverter.d.ts +0 -55
  341. package/dist/ms-doc/converter/DocToDocxConverter.d.ts.map +0 -1
  342. package/dist/ms-doc/converter/DocToDocxConverter.js +0 -324
  343. package/dist/ms-doc/converter/DocToDocxConverter.js.map +0 -1
  344. package/dist/ms-doc/fib/FIB.d.ts +0 -18
  345. package/dist/ms-doc/fib/FIB.d.ts.map +0 -1
  346. package/dist/ms-doc/fib/FIB.js +0 -342
  347. package/dist/ms-doc/fib/FIB.js.map +0 -1
  348. package/dist/ms-doc/fields/FieldParser.d.ts +0 -31
  349. package/dist/ms-doc/fields/FieldParser.d.ts.map +0 -1
  350. package/dist/ms-doc/fields/FieldParser.js +0 -266
  351. package/dist/ms-doc/fields/FieldParser.js.map +0 -1
  352. package/dist/ms-doc/images/PictureExtractor.d.ts +0 -22
  353. package/dist/ms-doc/images/PictureExtractor.d.ts.map +0 -1
  354. package/dist/ms-doc/images/PictureExtractor.js +0 -233
  355. package/dist/ms-doc/images/PictureExtractor.js.map +0 -1
  356. package/dist/ms-doc/index.d.ts +0 -20
  357. package/dist/ms-doc/index.d.ts.map +0 -1
  358. package/dist/ms-doc/index.js +0 -59
  359. package/dist/ms-doc/index.js.map +0 -1
  360. package/dist/ms-doc/properties/SPRM.d.ts +0 -210
  361. package/dist/ms-doc/properties/SPRM.d.ts.map +0 -1
  362. package/dist/ms-doc/properties/SPRM.js +0 -633
  363. package/dist/ms-doc/properties/SPRM.js.map +0 -1
  364. package/dist/ms-doc/sections/SectionParser.d.ts +0 -25
  365. package/dist/ms-doc/sections/SectionParser.d.ts.map +0 -1
  366. package/dist/ms-doc/sections/SectionParser.js +0 -214
  367. package/dist/ms-doc/sections/SectionParser.js.map +0 -1
  368. package/dist/ms-doc/styles/StyleSheet.d.ts +0 -23
  369. package/dist/ms-doc/styles/StyleSheet.d.ts.map +0 -1
  370. package/dist/ms-doc/styles/StyleSheet.js +0 -268
  371. package/dist/ms-doc/styles/StyleSheet.js.map +0 -1
  372. package/dist/ms-doc/subdocuments/SubdocumentParser.d.ts +0 -61
  373. package/dist/ms-doc/subdocuments/SubdocumentParser.d.ts.map +0 -1
  374. package/dist/ms-doc/subdocuments/SubdocumentParser.js +0 -208
  375. package/dist/ms-doc/subdocuments/SubdocumentParser.js.map +0 -1
  376. package/dist/ms-doc/tables/TableParser.d.ts +0 -29
  377. package/dist/ms-doc/tables/TableParser.d.ts.map +0 -1
  378. package/dist/ms-doc/tables/TableParser.js +0 -176
  379. package/dist/ms-doc/tables/TableParser.js.map +0 -1
  380. package/dist/ms-doc/text/PieceTable.d.ts +0 -21
  381. package/dist/ms-doc/text/PieceTable.d.ts.map +0 -1
  382. package/dist/ms-doc/text/PieceTable.js +0 -171
  383. package/dist/ms-doc/text/PieceTable.js.map +0 -1
  384. package/dist/ms-doc/types/Constants.d.ts +0 -99
  385. package/dist/ms-doc/types/Constants.d.ts.map +0 -1
  386. package/dist/ms-doc/types/Constants.js +0 -102
  387. package/dist/ms-doc/types/Constants.js.map +0 -1
  388. package/dist/ms-doc/types/DocTypes.d.ts +0 -368
  389. package/dist/ms-doc/types/DocTypes.d.ts.map +0 -1
  390. package/dist/ms-doc/types/DocTypes.js +0 -3
  391. package/dist/ms-doc/types/DocTypes.js.map +0 -1
  392. package/dist/tracking/index.d.ts +0 -3
  393. package/dist/tracking/index.d.ts.map +0 -1
  394. package/dist/tracking/index.js +0 -6
  395. package/dist/tracking/index.js.map +0 -1
@@ -0,0 +1,428 @@
1
+ /**
2
+ * RelationshipManager - Manages collections of relationships
3
+ *
4
+ * Handles relationship creation, tracking, and XML generation for various
5
+ * document parts (document.xml, header.xml, footer.xml, etc.)
6
+ */
7
+
8
+ import { Relationship, RelationshipType } from './Relationship';
9
+ import { XMLParser } from '../xml/XMLParser';
10
+
11
+ /**
12
+ * Manages relationships for a document or document part
13
+ */
14
+ export class RelationshipManager {
15
+ private relationships: Map<string, Relationship>;
16
+ private nextId: number;
17
+
18
+ /**
19
+ * Creates a new relationship manager
20
+ */
21
+ constructor() {
22
+ this.relationships = new Map();
23
+ this.nextId = 1;
24
+ }
25
+
26
+ /**
27
+ * Adds a relationship
28
+ * @param relationship The relationship to add
29
+ * @returns The relationship that was added
30
+ */
31
+ addRelationship(relationship: Relationship): Relationship {
32
+ this.relationships.set(relationship.getId(), relationship);
33
+
34
+ // Update next ID if necessary
35
+ const idMatch = /^rId(\d+)$/.exec(relationship.getId());
36
+ if (idMatch?.[1]) {
37
+ const idNum = parseInt(idMatch[1], 10);
38
+ if (idNum >= this.nextId) {
39
+ this.nextId = idNum + 1;
40
+ }
41
+ }
42
+
43
+ return relationship;
44
+ }
45
+
46
+ /**
47
+ * Gets a relationship by ID
48
+ * @param id The relationship ID
49
+ */
50
+ getRelationship(id: string): Relationship | undefined {
51
+ return this.relationships.get(id);
52
+ }
53
+
54
+ /**
55
+ * Gets all relationships
56
+ */
57
+ getAllRelationships(): Relationship[] {
58
+ return Array.from(this.relationships.values());
59
+ }
60
+
61
+ /**
62
+ * Gets relationships of a specific type
63
+ * @param type The relationship type
64
+ */
65
+ getRelationshipsByType(type: string | RelationshipType): Relationship[] {
66
+ return this.getAllRelationships().filter(rel => rel.getType() === type);
67
+ }
68
+
69
+ /**
70
+ * Checks if a relationship exists
71
+ * @param id The relationship ID
72
+ */
73
+ hasRelationship(id: string): boolean {
74
+ return this.relationships.has(id);
75
+ }
76
+
77
+ /**
78
+ * Removes a relationship
79
+ * @param id The relationship ID
80
+ * @returns True if removed, false if not found
81
+ */
82
+ removeRelationship(id: string): boolean {
83
+ return this.relationships.delete(id);
84
+ }
85
+
86
+ /**
87
+ * Gets the number of relationships
88
+ */
89
+ getCount(): number {
90
+ return this.relationships.size;
91
+ }
92
+
93
+ /**
94
+ * Clears all relationships
95
+ */
96
+ clear(): this {
97
+ this.relationships.clear();
98
+ this.nextId = 1;
99
+ return this;
100
+ }
101
+
102
+ /**
103
+ * Generates a new unique relationship ID
104
+ * @returns New relationship ID (e.g., 'rId1', 'rId2')
105
+ */
106
+ generateId(): string {
107
+ return `rId${this.nextId++}`;
108
+ }
109
+
110
+ /**
111
+ * Adds a styles relationship
112
+ * @returns The created relationship
113
+ */
114
+ addStyles(): Relationship {
115
+ const id = this.generateId();
116
+ return this.addRelationship(Relationship.createStyles(id));
117
+ }
118
+
119
+ /**
120
+ * Adds a numbering relationship
121
+ * @returns The created relationship
122
+ */
123
+ addNumbering(): Relationship {
124
+ const id = this.generateId();
125
+ return this.addRelationship(Relationship.createNumbering(id));
126
+ }
127
+
128
+ /**
129
+ * Adds a fontTable relationship
130
+ * @returns The created relationship
131
+ */
132
+ addFontTable(): Relationship {
133
+ const id = this.generateId();
134
+ return this.addRelationship(Relationship.createFontTable(id));
135
+ }
136
+
137
+ /**
138
+ * Adds a settings relationship
139
+ * @returns The created relationship
140
+ */
141
+ addSettings(): Relationship {
142
+ const id = this.generateId();
143
+ return this.addRelationship(Relationship.createSettings(id));
144
+ }
145
+
146
+ /**
147
+ * Adds a webSettings relationship
148
+ * @returns The created relationship
149
+ */
150
+ addWebSettings(): Relationship {
151
+ const id = this.generateId();
152
+ return this.addRelationship(Relationship.createWebSettings(id));
153
+ }
154
+
155
+ /**
156
+ * Adds a theme relationship
157
+ * @returns The created relationship
158
+ */
159
+ addTheme(): Relationship {
160
+ const id = this.generateId();
161
+ return this.addRelationship(Relationship.createTheme(id));
162
+ }
163
+
164
+ /**
165
+ * Adds an image relationship
166
+ * @param target Image path relative to the part (e.g., 'media/image1.png')
167
+ * @returns The created relationship
168
+ */
169
+ addImage(target: string): Relationship {
170
+ const id = this.generateId();
171
+ return this.addRelationship(Relationship.createImage(id, target));
172
+ }
173
+
174
+ /**
175
+ * Adds a header relationship
176
+ * @param target Header file path (e.g., 'header1.xml')
177
+ * @returns The created relationship
178
+ */
179
+ addHeader(target: string): Relationship {
180
+ const id = this.generateId();
181
+ return this.addRelationship(Relationship.createHeader(id, target));
182
+ }
183
+
184
+ /**
185
+ * Adds a footer relationship
186
+ * @param target Footer file path (e.g., 'footer1.xml')
187
+ * @returns The created relationship
188
+ */
189
+ addFooter(target: string): Relationship {
190
+ const id = this.generateId();
191
+ return this.addRelationship(Relationship.createFooter(id, target));
192
+ }
193
+
194
+ /**
195
+ * Adds a hyperlink relationship
196
+ * @param url The hyperlink URL
197
+ * @returns The created relationship
198
+ */
199
+ addHyperlink(url: string): Relationship {
200
+ const id = this.generateId();
201
+ return this.addRelationship(Relationship.createHyperlink(id, url));
202
+ }
203
+
204
+ /**
205
+ * Updates the target URL of an existing hyperlink relationship
206
+ *
207
+ * This method modifies an existing relationship's target in-place, maintaining
208
+ * the same relationship ID. This is crucial for proper OpenXML compliance
209
+ * per ECMA-376 §17.16.22, as it prevents orphaned relationships.
210
+ *
211
+ * @param relationshipId The ID of the relationship to update
212
+ * @param newUrl The new URL to set
213
+ * @returns True if updated, false if relationship not found
214
+ */
215
+ updateHyperlinkTarget(relationshipId: string, newUrl: string): boolean {
216
+ const relationship = this.getRelationship(relationshipId);
217
+ if (!relationship) {
218
+ return false;
219
+ }
220
+
221
+ // Verify this is a hyperlink relationship
222
+ if (relationship.getType() !== RelationshipType.HYPERLINK) {
223
+ throw new Error(
224
+ `Relationship ${relationshipId} is not a hyperlink relationship. ` +
225
+ `Type is ${relationship.getType()}, expected ${RelationshipType.HYPERLINK}`
226
+ );
227
+ }
228
+
229
+ // Update the target URL
230
+ relationship.setTarget(newUrl);
231
+ return true;
232
+ }
233
+
234
+ /**
235
+ * Finds a hyperlink relationship by its target URL
236
+ *
237
+ * @param targetUrl The URL to search for
238
+ * @returns The matching relationship, or undefined if not found
239
+ */
240
+ findHyperlinkByTarget(targetUrl: string): Relationship | undefined {
241
+ return this.getAllRelationships().find(
242
+ rel => rel.getType() === RelationshipType.HYPERLINK && rel.getTarget() === targetUrl
243
+ );
244
+ }
245
+
246
+ /**
247
+ * Gets or creates a hyperlink relationship for the given URL
248
+ *
249
+ * This method ensures we don't create duplicate relationships for the same URL.
250
+ * If a relationship already exists for the URL, it returns the existing one.
251
+ * Otherwise, it creates a new relationship.
252
+ *
253
+ * @param url The hyperlink URL
254
+ * @returns The existing or newly created relationship
255
+ */
256
+ getOrCreateHyperlink(url: string): Relationship {
257
+ // Check if relationship already exists for this URL
258
+ const existing = this.findHyperlinkByTarget(url);
259
+ if (existing) {
260
+ return existing;
261
+ }
262
+
263
+ // Create new relationship
264
+ return this.addHyperlink(url);
265
+ }
266
+
267
+ /**
268
+ * Removes orphaned hyperlink relationships
269
+ *
270
+ * This method removes hyperlink relationships that are no longer referenced
271
+ * by any hyperlink in the document. Call this after updating URLs to clean
272
+ * up any orphaned relationships.
273
+ *
274
+ * @param referencedIds Set of relationship IDs that are still in use
275
+ * @returns Number of relationships removed
276
+ */
277
+ removeOrphanedHyperlinks(referencedIds: Set<string>): number {
278
+ let removed = 0;
279
+ const toRemove: string[] = [];
280
+
281
+ // Find orphaned relationships
282
+ for (const rel of this.getAllRelationships()) {
283
+ if (rel.getType() === RelationshipType.HYPERLINK && !referencedIds.has(rel.getId())) {
284
+ toRemove.push(rel.getId());
285
+ }
286
+ }
287
+
288
+ // Remove orphaned relationships
289
+ for (const id of toRemove) {
290
+ if (this.removeRelationship(id)) {
291
+ removed++;
292
+ }
293
+ }
294
+
295
+ return removed;
296
+ }
297
+
298
+ /**
299
+ * Adds a comments relationship
300
+ * @returns The created relationship
301
+ */
302
+ addComments(): Relationship {
303
+ const id = this.generateId();
304
+ return this.addRelationship(Relationship.createComments(id));
305
+ }
306
+
307
+ /**
308
+ * Adds a footnotes relationship
309
+ * @returns The created relationship
310
+ */
311
+ addFootnotes(): Relationship {
312
+ const id = this.generateId();
313
+ return this.addRelationship(Relationship.createFootnotes(id));
314
+ }
315
+
316
+ /**
317
+ * Adds an endnotes relationship
318
+ * @returns The created relationship
319
+ */
320
+ addEndnotes(): Relationship {
321
+ const id = this.generateId();
322
+ return this.addRelationship(Relationship.createEndnotes(id));
323
+ }
324
+
325
+ /**
326
+ * Adds a people relationship (track changes authors)
327
+ * @returns The created relationship
328
+ */
329
+ addPeople(): Relationship {
330
+ const id = this.generateId();
331
+ return this.addRelationship(Relationship.createPeople(id));
332
+ }
333
+
334
+ /**
335
+ * Generates the relationships XML file content
336
+ * @returns Complete XML string for .rels file
337
+ */
338
+ generateXml(): string {
339
+ const relationships = this.getAllRelationships();
340
+
341
+ let xml = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n';
342
+ xml += '<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">\n';
343
+
344
+ for (const rel of relationships) {
345
+ xml += rel.toXML() + '\n';
346
+ }
347
+
348
+ xml += '</Relationships>';
349
+
350
+ return xml;
351
+ }
352
+
353
+ /**
354
+ * Creates a new relationship manager with common document relationships
355
+ * @returns RelationshipManager with styles, numbering, fontTable, settings, and theme relationships
356
+ */
357
+ static createForDocument(): RelationshipManager {
358
+ const manager = new RelationshipManager();
359
+ manager.addStyles();
360
+ manager.addNumbering();
361
+ manager.addFontTable();
362
+ manager.addSettings();
363
+ manager.addWebSettings();
364
+ manager.addTheme();
365
+ return manager;
366
+ }
367
+
368
+ /**
369
+ * Creates an empty relationship manager
370
+ * @returns Empty RelationshipManager
371
+ */
372
+ static create(): RelationshipManager {
373
+ return new RelationshipManager();
374
+ }
375
+
376
+ /**
377
+ * Parses relationships from XML string and creates a populated manager
378
+ * @param xml The relationships XML content (.rels file)
379
+ * @returns RelationshipManager with parsed relationships
380
+ */
381
+ static fromXml(xml: string): RelationshipManager {
382
+ const manager = new RelationshipManager();
383
+
384
+ // Prevent ReDoS: validate input size (typical .rels files are < 10KB)
385
+ if (xml.length > 100000) {
386
+ throw new Error('Relationships XML file too large (>100KB). Possible malicious input or corrupted file.');
387
+ }
388
+
389
+ // Use XMLParser to extract all Relationship elements
390
+ const relationshipElements = XMLParser.extractElements(xml, 'Relationship');
391
+
392
+ // Prevent infinite loops: check relationship count
393
+ if (relationshipElements.length > 1000) {
394
+ throw new Error('Too many relationships in XML file (>1000). Possible malicious input.');
395
+ }
396
+
397
+ // Process each relationship element
398
+ for (const relationshipElement of relationshipElements) {
399
+ // Extract attributes using XMLParser
400
+ const id = XMLParser.extractAttribute(relationshipElement, 'Id');
401
+ const type = XMLParser.extractAttribute(relationshipElement, 'Type');
402
+ const target = XMLParser.extractAttribute(relationshipElement, 'Target');
403
+ const targetMode = XMLParser.extractAttribute(relationshipElement, 'TargetMode');
404
+
405
+ // Only create relationship if all required attributes present
406
+ if (id && type && target) {
407
+ // Validate targetMode before type assertion
408
+ const validatedTargetMode =
409
+ targetMode === 'Internal' || targetMode === 'External' || targetMode === undefined
410
+ ? (targetMode)
411
+ : undefined;
412
+
413
+ // Create and add relationship
414
+ const relationship = Relationship.create({
415
+ id,
416
+ type,
417
+ target,
418
+ targetMode: validatedTargetMode || 'Internal',
419
+ });
420
+
421
+ manager.addRelationship(relationship);
422
+ }
423
+ }
424
+
425
+ return manager;
426
+ }
427
+
428
+ }
@@ -0,0 +1,42 @@
1
+ /**
2
+ * AlternateContent - Represents mc:AlternateContent block element
3
+ *
4
+ * Per ECMA-376 Part 3 §11.4, mc:AlternateContent provides markup compatibility.
5
+ * Word uses this for newer features (Word 2010+ shapes as Choice, VML as Fallback).
6
+ *
7
+ * Stored as raw XML for round-trip fidelity since the internal structure varies widely.
8
+ */
9
+
10
+ import { XMLElement } from '../xml/XMLBuilder';
11
+
12
+ export class AlternateContent {
13
+ private rawXml: string;
14
+
15
+ constructor(rawXml: string) {
16
+ this.rawXml = rawXml;
17
+ }
18
+
19
+ /**
20
+ * Returns the raw XML for round-trip serialization
21
+ */
22
+ toXML(): XMLElement {
23
+ return {
24
+ name: '__rawXml',
25
+ rawXml: this.rawXml,
26
+ } as XMLElement;
27
+ }
28
+
29
+ /**
30
+ * Gets the raw XML string
31
+ */
32
+ getRawXml(): string {
33
+ return this.rawXml;
34
+ }
35
+
36
+ /**
37
+ * Returns the element type identifier
38
+ */
39
+ getType(): string {
40
+ return 'alternateContent';
41
+ }
42
+ }
@@ -0,0 +1,210 @@
1
+ /**
2
+ * Bookmark - Represents a bookmark in a Word document
3
+ *
4
+ * Bookmarks mark specific locations in a document for internal navigation.
5
+ * They consist of a start marker and an end marker with matching IDs.
6
+ */
7
+
8
+ import { XMLElement } from '../xml/XMLBuilder';
9
+
10
+ /**
11
+ * Bookmark properties
12
+ */
13
+ export interface BookmarkProperties {
14
+ /** Unique bookmark ID (generated automatically if not provided) */
15
+ id?: number;
16
+ /** Bookmark name (must be unique within document) */
17
+ name: string;
18
+ /** Skip name normalization (used when loading from existing documents) */
19
+ skipNormalization?: boolean;
20
+ }
21
+
22
+ /**
23
+ * Represents a bookmark location in a document
24
+ */
25
+ export class Bookmark {
26
+ private id: number;
27
+ private name: string;
28
+
29
+ /**
30
+ * Creates a new Bookmark
31
+ * @param properties - Bookmark properties
32
+ */
33
+ constructor(properties: BookmarkProperties) {
34
+ this.id = properties.id ?? 0; // ID will be assigned by BookmarkManager
35
+ // Preserve exact bookmark names when loading from documents (Word allows =, ., etc.)
36
+ // Only normalize when creating new bookmarks programmatically
37
+ this.name = properties.skipNormalization ? properties.name : this.normalizeName(properties.name);
38
+ }
39
+
40
+ /**
41
+ * Normalizes a bookmark name to be valid
42
+ * - Must start with a letter or underscore
43
+ * - Can only contain letters, numbers, and underscores
44
+ * - Maximum 40 characters
45
+ * - Case-insensitive (Word converts to lowercase)
46
+ * @param name - Raw bookmark name
47
+ * @returns Normalized bookmark name
48
+ */
49
+ private normalizeName(name: string): string {
50
+ // Remove invalid characters
51
+ let normalized = name.replace(/[^a-zA-Z0-9_]/g, '_');
52
+
53
+ // Ensure it starts with a letter or underscore
54
+ if (normalized.length > 0 && /^\d/.test(normalized)) {
55
+ normalized = '_' + normalized;
56
+ }
57
+
58
+ // Limit to 40 characters
59
+ if (normalized.length > 40) {
60
+ normalized = normalized.substring(0, 40);
61
+ }
62
+
63
+ // Default if empty
64
+ if (normalized.length === 0) {
65
+ normalized = '_bookmark';
66
+ }
67
+
68
+ return normalized;
69
+ }
70
+
71
+ /**
72
+ * Gets the bookmark ID
73
+ */
74
+ getId(): number {
75
+ return this.id;
76
+ }
77
+
78
+ /**
79
+ * Sets the bookmark ID (used by BookmarkManager)
80
+ * @internal
81
+ */
82
+ setId(id: number): void {
83
+ this.id = id;
84
+ }
85
+
86
+ /**
87
+ * Gets the bookmark name
88
+ */
89
+ getName(): string {
90
+ return this.name;
91
+ }
92
+
93
+ /**
94
+ * Sets the bookmark name (normalizes the name)
95
+ *
96
+ * The name will be normalized:
97
+ * - Invalid characters replaced with underscores
98
+ * - Leading digits prefixed with underscore
99
+ * - Limited to 40 characters
100
+ *
101
+ * @param name - New bookmark name
102
+ * @returns This bookmark for chaining
103
+ */
104
+ setName(name: string): this {
105
+ this.name = this.normalizeName(name);
106
+ return this;
107
+ }
108
+
109
+ /**
110
+ * Sets the bookmark name without normalization
111
+ *
112
+ * Use this method when:
113
+ * - Preserving exact names from imported documents
114
+ * - Setting names with special characters that Word allows (=, ., etc.)
115
+ * - Round-trip fidelity is required
116
+ *
117
+ * **Warning:** Setting invalid bookmark names may cause issues in Word.
118
+ * Only use this if you know the name is valid or needs to match an existing document.
119
+ *
120
+ * @param name - Raw bookmark name (not normalized)
121
+ * @returns This bookmark for chaining
122
+ *
123
+ * @example
124
+ * ```typescript
125
+ * // Preserve exact name from Word document
126
+ * bookmark.setRawName('SECTION=II.MNKE7E8NA385_');
127
+ *
128
+ * // For new bookmarks, prefer setName() which normalizes
129
+ * bookmark.setName('My Heading'); // Becomes 'My_Heading'
130
+ * ```
131
+ */
132
+ setRawName(name: string): this {
133
+ this.name = name;
134
+ return this;
135
+ }
136
+
137
+ /**
138
+ * Generates XML for the bookmark start marker
139
+ * @returns XMLElement for bookmarkStart
140
+ */
141
+ toStartXML(): XMLElement {
142
+ return {
143
+ name: 'w:bookmarkStart',
144
+ attributes: {
145
+ 'w:id': this.id.toString(),
146
+ 'w:name': this.name,
147
+ },
148
+ selfClosing: true,
149
+ };
150
+ }
151
+
152
+ /**
153
+ * Generates XML for the bookmark end marker
154
+ * @returns XMLElement for bookmarkEnd
155
+ */
156
+ toEndXML(): XMLElement {
157
+ return {
158
+ name: 'w:bookmarkEnd',
159
+ attributes: {
160
+ 'w:id': this.id.toString(),
161
+ },
162
+ selfClosing: true,
163
+ };
164
+ }
165
+
166
+ /**
167
+ * Generates both start and end XML elements as an array
168
+ * @returns Array of XMLElements [start, end]
169
+ */
170
+ toXML(): [XMLElement, XMLElement] {
171
+ return [this.toStartXML(), this.toEndXML()];
172
+ }
173
+
174
+ /**
175
+ * Creates a new Bookmark
176
+ * @param name - Bookmark name
177
+ * @returns New Bookmark instance
178
+ */
179
+ static create(name: string): Bookmark {
180
+ return new Bookmark({ name });
181
+ }
182
+
183
+ /**
184
+ * Creates a bookmark for a heading
185
+ * Useful for table of contents internal links
186
+ * @param headingText - The text of the heading
187
+ * @returns New Bookmark instance with normalized name
188
+ */
189
+ static createForHeading(headingText: string): Bookmark {
190
+ // Create a bookmark name from heading text
191
+ // Example: "Chapter 1: Introduction" -> "_Chapter_1_Introduction"
192
+ const name = headingText
193
+ .trim()
194
+ .replace(/[^a-zA-Z0-9]+/g, '_')
195
+ .substring(0, 40);
196
+ return new Bookmark({ name: name || '_heading' });
197
+ }
198
+
199
+ /**
200
+ * Creates a bookmark with an auto-generated unique name
201
+ * @param prefix - Optional prefix for the name (default: 'bookmark')
202
+ * @returns New Bookmark instance
203
+ */
204
+ static createAuto(prefix = 'bookmark'): Bookmark {
205
+ const timestamp = Date.now().toString(36);
206
+ const random = Math.random().toString(36).substring(2, 7);
207
+ const name = `${prefix}_${timestamp}_${random}`;
208
+ return new Bookmark({ name });
209
+ }
210
+ }