open-agreements 0.3.1 → 0.4.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 (429) hide show
  1. package/content/templates/closing-checklist/template.docx +0 -0
  2. package/dist/core/checklist/docx-import.d.ts +50 -0
  3. package/dist/core/checklist/docx-import.d.ts.map +1 -0
  4. package/dist/core/checklist/docx-import.js +613 -0
  5. package/dist/core/checklist/docx-import.js.map +1 -0
  6. package/dist/core/checklist/docx-table-helpers.d.ts +33 -0
  7. package/dist/core/checklist/docx-table-helpers.d.ts.map +1 -0
  8. package/dist/core/checklist/docx-table-helpers.js +154 -0
  9. package/dist/core/checklist/docx-table-helpers.js.map +1 -0
  10. package/dist/core/checklist/format-checklist-docx.d.ts.map +1 -1
  11. package/dist/core/checklist/format-checklist-docx.js +37 -88
  12. package/dist/core/checklist/format-checklist-docx.js.map +1 -1
  13. package/dist/core/checklist/index.d.ts +15 -12
  14. package/dist/core/checklist/index.d.ts.map +1 -1
  15. package/dist/core/checklist/index.js +48 -30
  16. package/dist/core/checklist/index.js.map +1 -1
  17. package/dist/core/checklist/status-labels.d.ts +6 -0
  18. package/dist/core/checklist/status-labels.d.ts.map +1 -1
  19. package/dist/core/checklist/status-labels.js +8 -0
  20. package/dist/core/checklist/status-labels.js.map +1 -1
  21. package/dist/index.d.ts +1 -1
  22. package/dist/index.d.ts.map +1 -1
  23. package/dist/index.js +1 -1
  24. package/dist/index.js.map +1 -1
  25. package/node_modules/@usejunior/docx-core/dist/atomizer.d.ts +218 -0
  26. package/node_modules/@usejunior/docx-core/dist/atomizer.d.ts.map +1 -0
  27. package/node_modules/@usejunior/docx-core/dist/atomizer.js +869 -0
  28. package/node_modules/@usejunior/docx-core/dist/atomizer.js.map +1 -0
  29. package/node_modules/@usejunior/docx-core/dist/baselines/atomizer/atomLcs.d.ts +96 -0
  30. package/node_modules/@usejunior/docx-core/dist/baselines/atomizer/atomLcs.d.ts.map +1 -0
  31. package/node_modules/@usejunior/docx-core/dist/baselines/atomizer/atomLcs.js +347 -0
  32. package/node_modules/@usejunior/docx-core/dist/baselines/atomizer/atomLcs.js.map +1 -0
  33. package/node_modules/@usejunior/docx-core/dist/baselines/atomizer/consumerCompatibility.d.ts +2 -0
  34. package/node_modules/@usejunior/docx-core/dist/baselines/atomizer/consumerCompatibility.d.ts.map +1 -0
  35. package/node_modules/@usejunior/docx-core/dist/baselines/atomizer/consumerCompatibility.js +188 -0
  36. package/node_modules/@usejunior/docx-core/dist/baselines/atomizer/consumerCompatibility.js.map +1 -0
  37. package/node_modules/@usejunior/docx-core/dist/baselines/atomizer/debug.d.ts +41 -0
  38. package/node_modules/@usejunior/docx-core/dist/baselines/atomizer/debug.d.ts.map +1 -0
  39. package/node_modules/@usejunior/docx-core/dist/baselines/atomizer/debug.js +85 -0
  40. package/node_modules/@usejunior/docx-core/dist/baselines/atomizer/debug.js.map +1 -0
  41. package/node_modules/@usejunior/docx-core/dist/baselines/atomizer/documentReconstructor.d.ts +64 -0
  42. package/node_modules/@usejunior/docx-core/dist/baselines/atomizer/documentReconstructor.d.ts.map +1 -0
  43. package/node_modules/@usejunior/docx-core/dist/baselines/atomizer/documentReconstructor.js +985 -0
  44. package/node_modules/@usejunior/docx-core/dist/baselines/atomizer/documentReconstructor.js.map +1 -0
  45. package/node_modules/@usejunior/docx-core/dist/baselines/atomizer/hierarchicalLcs.d.ts +111 -0
  46. package/node_modules/@usejunior/docx-core/dist/baselines/atomizer/hierarchicalLcs.d.ts.map +1 -0
  47. package/node_modules/@usejunior/docx-core/dist/baselines/atomizer/hierarchicalLcs.js +469 -0
  48. package/node_modules/@usejunior/docx-core/dist/baselines/atomizer/hierarchicalLcs.js.map +1 -0
  49. package/node_modules/@usejunior/docx-core/dist/baselines/atomizer/inPlaceModifier.d.ts +277 -0
  50. package/node_modules/@usejunior/docx-core/dist/baselines/atomizer/inPlaceModifier.d.ts.map +1 -0
  51. package/node_modules/@usejunior/docx-core/dist/baselines/atomizer/inPlaceModifier.js +2279 -0
  52. package/node_modules/@usejunior/docx-core/dist/baselines/atomizer/inPlaceModifier.js.map +1 -0
  53. package/node_modules/@usejunior/docx-core/dist/baselines/atomizer/numberingIntegration.d.ts +59 -0
  54. package/node_modules/@usejunior/docx-core/dist/baselines/atomizer/numberingIntegration.d.ts.map +1 -0
  55. package/node_modules/@usejunior/docx-core/dist/baselines/atomizer/numberingIntegration.js +209 -0
  56. package/node_modules/@usejunior/docx-core/dist/baselines/atomizer/numberingIntegration.js.map +1 -0
  57. package/node_modules/@usejunior/docx-core/dist/baselines/atomizer/pipeline.d.ts +69 -0
  58. package/node_modules/@usejunior/docx-core/dist/baselines/atomizer/pipeline.d.ts.map +1 -0
  59. package/node_modules/@usejunior/docx-core/dist/baselines/atomizer/pipeline.js +910 -0
  60. package/node_modules/@usejunior/docx-core/dist/baselines/atomizer/pipeline.js.map +1 -0
  61. package/node_modules/@usejunior/docx-core/dist/baselines/atomizer/premergeRuns.d.ts +26 -0
  62. package/node_modules/@usejunior/docx-core/dist/baselines/atomizer/premergeRuns.d.ts.map +1 -0
  63. package/node_modules/@usejunior/docx-core/dist/baselines/atomizer/premergeRuns.js +153 -0
  64. package/node_modules/@usejunior/docx-core/dist/baselines/atomizer/premergeRuns.js.map +1 -0
  65. package/node_modules/@usejunior/docx-core/dist/baselines/atomizer/trackChangesAcceptor.d.ts +63 -0
  66. package/node_modules/@usejunior/docx-core/dist/baselines/atomizer/trackChangesAcceptor.d.ts.map +1 -0
  67. package/node_modules/@usejunior/docx-core/dist/baselines/atomizer/trackChangesAcceptor.js +254 -0
  68. package/node_modules/@usejunior/docx-core/dist/baselines/atomizer/trackChangesAcceptor.js.map +1 -0
  69. package/node_modules/@usejunior/docx-core/dist/baselines/atomizer/trackChangesAcceptorAst.d.ts +64 -0
  70. package/node_modules/@usejunior/docx-core/dist/baselines/atomizer/trackChangesAcceptorAst.d.ts.map +1 -0
  71. package/node_modules/@usejunior/docx-core/dist/baselines/atomizer/trackChangesAcceptorAst.js +616 -0
  72. package/node_modules/@usejunior/docx-core/dist/baselines/atomizer/trackChangesAcceptorAst.js.map +1 -0
  73. package/node_modules/@usejunior/docx-core/dist/baselines/atomizer/xmlToWmlElement.d.ts +65 -0
  74. package/node_modules/@usejunior/docx-core/dist/baselines/atomizer/xmlToWmlElement.d.ts.map +1 -0
  75. package/node_modules/@usejunior/docx-core/dist/baselines/atomizer/xmlToWmlElement.js +95 -0
  76. package/node_modules/@usejunior/docx-core/dist/baselines/atomizer/xmlToWmlElement.js.map +1 -0
  77. package/node_modules/@usejunior/docx-core/dist/baselines/wmlcomparer/DocxodusWasm.d.ts +51 -0
  78. package/node_modules/@usejunior/docx-core/dist/baselines/wmlcomparer/DocxodusWasm.d.ts.map +1 -0
  79. package/node_modules/@usejunior/docx-core/dist/baselines/wmlcomparer/DocxodusWasm.js +83 -0
  80. package/node_modules/@usejunior/docx-core/dist/baselines/wmlcomparer/DocxodusWasm.js.map +1 -0
  81. package/node_modules/@usejunior/docx-core/dist/baselines/wmlcomparer/DotnetCli.d.ts +40 -0
  82. package/node_modules/@usejunior/docx-core/dist/baselines/wmlcomparer/DotnetCli.d.ts.map +1 -0
  83. package/node_modules/@usejunior/docx-core/dist/baselines/wmlcomparer/DotnetCli.js +135 -0
  84. package/node_modules/@usejunior/docx-core/dist/baselines/wmlcomparer/DotnetCli.js.map +1 -0
  85. package/node_modules/@usejunior/docx-core/dist/cli/compare-two.d.ts +28 -0
  86. package/node_modules/@usejunior/docx-core/dist/cli/compare-two.d.ts.map +1 -0
  87. package/node_modules/@usejunior/docx-core/dist/cli/compare-two.js +110 -0
  88. package/node_modules/@usejunior/docx-core/dist/cli/compare-two.js.map +1 -0
  89. package/node_modules/@usejunior/docx-core/dist/cli/index.d.ts +3 -0
  90. package/node_modules/@usejunior/docx-core/dist/cli/index.d.ts.map +1 -0
  91. package/node_modules/@usejunior/docx-core/dist/cli/index.js +21 -0
  92. package/node_modules/@usejunior/docx-core/dist/cli/index.js.map +1 -0
  93. package/node_modules/@usejunior/docx-core/dist/core-types.d.ts +296 -0
  94. package/node_modules/@usejunior/docx-core/dist/core-types.d.ts.map +1 -0
  95. package/node_modules/@usejunior/docx-core/dist/core-types.js +122 -0
  96. package/node_modules/@usejunior/docx-core/dist/core-types.js.map +1 -0
  97. package/node_modules/@usejunior/docx-core/dist/footnotes.d.ts +144 -0
  98. package/node_modules/@usejunior/docx-core/dist/footnotes.d.ts.map +1 -0
  99. package/node_modules/@usejunior/docx-core/dist/footnotes.js +291 -0
  100. package/node_modules/@usejunior/docx-core/dist/footnotes.js.map +1 -0
  101. package/node_modules/@usejunior/docx-core/dist/format-detection.d.ts +120 -0
  102. package/node_modules/@usejunior/docx-core/dist/format-detection.d.ts.map +1 -0
  103. package/node_modules/@usejunior/docx-core/dist/format-detection.js +338 -0
  104. package/node_modules/@usejunior/docx-core/dist/format-detection.js.map +1 -0
  105. package/node_modules/@usejunior/docx-core/dist/index.d.ts +177 -0
  106. package/node_modules/@usejunior/docx-core/dist/index.d.ts.map +1 -0
  107. package/node_modules/@usejunior/docx-core/dist/index.js +55 -0
  108. package/node_modules/@usejunior/docx-core/dist/index.js.map +1 -0
  109. package/node_modules/@usejunior/docx-core/dist/integration/output-artifacts.d.ts +6 -0
  110. package/node_modules/@usejunior/docx-core/dist/integration/output-artifacts.d.ts.map +1 -0
  111. package/node_modules/@usejunior/docx-core/dist/integration/output-artifacts.js +30 -0
  112. package/node_modules/@usejunior/docx-core/dist/integration/output-artifacts.js.map +1 -0
  113. package/node_modules/@usejunior/docx-core/dist/move-detection.d.ts +211 -0
  114. package/node_modules/@usejunior/docx-core/dist/move-detection.d.ts.map +1 -0
  115. package/node_modules/@usejunior/docx-core/dist/move-detection.js +391 -0
  116. package/node_modules/@usejunior/docx-core/dist/move-detection.js.map +1 -0
  117. package/node_modules/@usejunior/docx-core/dist/numbering.d.ts +136 -0
  118. package/node_modules/@usejunior/docx-core/dist/numbering.d.ts.map +1 -0
  119. package/node_modules/@usejunior/docx-core/dist/numbering.js +446 -0
  120. package/node_modules/@usejunior/docx-core/dist/numbering.js.map +1 -0
  121. package/node_modules/@usejunior/docx-core/dist/primitives/accept_changes.d.ts +30 -0
  122. package/node_modules/@usejunior/docx-core/dist/primitives/accept_changes.d.ts.map +1 -0
  123. package/node_modules/@usejunior/docx-core/dist/primitives/accept_changes.js +241 -0
  124. package/node_modules/@usejunior/docx-core/dist/primitives/accept_changes.js.map +1 -0
  125. package/node_modules/@usejunior/docx-core/dist/primitives/bookmarks.d.ts +12 -0
  126. package/node_modules/@usejunior/docx-core/dist/primitives/bookmarks.d.ts.map +1 -0
  127. package/node_modules/@usejunior/docx-core/dist/primitives/bookmarks.js +248 -0
  128. package/node_modules/@usejunior/docx-core/dist/primitives/bookmarks.js.map +1 -0
  129. package/node_modules/@usejunior/docx-core/dist/primitives/comments.d.ts +88 -0
  130. package/node_modules/@usejunior/docx-core/dist/primitives/comments.d.ts.map +1 -0
  131. package/node_modules/@usejunior/docx-core/dist/primitives/comments.js +703 -0
  132. package/node_modules/@usejunior/docx-core/dist/primitives/comments.js.map +1 -0
  133. package/node_modules/@usejunior/docx-core/dist/primitives/document.d.ts +186 -0
  134. package/node_modules/@usejunior/docx-core/dist/primitives/document.d.ts.map +1 -0
  135. package/node_modules/@usejunior/docx-core/dist/primitives/document.js +555 -0
  136. package/node_modules/@usejunior/docx-core/dist/primitives/document.js.map +1 -0
  137. package/node_modules/@usejunior/docx-core/dist/primitives/document_view.d.ts +97 -0
  138. package/node_modules/@usejunior/docx-core/dist/primitives/document_view.d.ts.map +1 -0
  139. package/node_modules/@usejunior/docx-core/dist/primitives/document_view.js +749 -0
  140. package/node_modules/@usejunior/docx-core/dist/primitives/document_view.js.map +1 -0
  141. package/node_modules/@usejunior/docx-core/dist/primitives/dom-helpers.d.ts +94 -0
  142. package/node_modules/@usejunior/docx-core/dist/primitives/dom-helpers.d.ts.map +1 -0
  143. package/node_modules/@usejunior/docx-core/dist/primitives/dom-helpers.js +219 -0
  144. package/node_modules/@usejunior/docx-core/dist/primitives/dom-helpers.js.map +1 -0
  145. package/node_modules/@usejunior/docx-core/dist/primitives/errors.d.ts +7 -0
  146. package/node_modules/@usejunior/docx-core/dist/primitives/errors.d.ts.map +1 -0
  147. package/node_modules/@usejunior/docx-core/dist/primitives/errors.js +10 -0
  148. package/node_modules/@usejunior/docx-core/dist/primitives/errors.js.map +1 -0
  149. package/node_modules/@usejunior/docx-core/dist/primitives/extract_revisions.d.ts +50 -0
  150. package/node_modules/@usejunior/docx-core/dist/primitives/extract_revisions.d.ts.map +1 -0
  151. package/node_modules/@usejunior/docx-core/dist/primitives/extract_revisions.js +340 -0
  152. package/node_modules/@usejunior/docx-core/dist/primitives/extract_revisions.js.map +1 -0
  153. package/node_modules/@usejunior/docx-core/dist/primitives/footnotes.d.ts +37 -0
  154. package/node_modules/@usejunior/docx-core/dist/primitives/footnotes.d.ts.map +1 -0
  155. package/node_modules/@usejunior/docx-core/dist/primitives/footnotes.js +552 -0
  156. package/node_modules/@usejunior/docx-core/dist/primitives/footnotes.js.map +1 -0
  157. package/node_modules/@usejunior/docx-core/dist/primitives/formatting_tags.d.ts +43 -0
  158. package/node_modules/@usejunior/docx-core/dist/primitives/formatting_tags.d.ts.map +1 -0
  159. package/node_modules/@usejunior/docx-core/dist/primitives/formatting_tags.js +291 -0
  160. package/node_modules/@usejunior/docx-core/dist/primitives/formatting_tags.js.map +1 -0
  161. package/node_modules/@usejunior/docx-core/dist/primitives/index.d.ts +27 -0
  162. package/node_modules/@usejunior/docx-core/dist/primitives/index.d.ts.map +1 -0
  163. package/node_modules/@usejunior/docx-core/dist/primitives/index.js +27 -0
  164. package/node_modules/@usejunior/docx-core/dist/primitives/index.js.map +1 -0
  165. package/node_modules/@usejunior/docx-core/dist/primitives/layout.d.ts +53 -0
  166. package/node_modules/@usejunior/docx-core/dist/primitives/layout.d.ts.map +1 -0
  167. package/node_modules/@usejunior/docx-core/dist/primitives/layout.js +178 -0
  168. package/node_modules/@usejunior/docx-core/dist/primitives/layout.js.map +1 -0
  169. package/node_modules/@usejunior/docx-core/dist/primitives/list_labels.d.ts +19 -0
  170. package/node_modules/@usejunior/docx-core/dist/primitives/list_labels.d.ts.map +1 -0
  171. package/node_modules/@usejunior/docx-core/dist/primitives/list_labels.js +57 -0
  172. package/node_modules/@usejunior/docx-core/dist/primitives/list_labels.js.map +1 -0
  173. package/node_modules/@usejunior/docx-core/dist/primitives/matching.d.ts +31 -0
  174. package/node_modules/@usejunior/docx-core/dist/primitives/matching.d.ts.map +1 -0
  175. package/node_modules/@usejunior/docx-core/dist/primitives/matching.js +223 -0
  176. package/node_modules/@usejunior/docx-core/dist/primitives/matching.js.map +1 -0
  177. package/node_modules/@usejunior/docx-core/dist/primitives/merge_runs.d.ts +23 -0
  178. package/node_modules/@usejunior/docx-core/dist/primitives/merge_runs.d.ts.map +1 -0
  179. package/node_modules/@usejunior/docx-core/dist/primitives/merge_runs.js +243 -0
  180. package/node_modules/@usejunior/docx-core/dist/primitives/merge_runs.js.map +1 -0
  181. package/node_modules/@usejunior/docx-core/dist/primitives/namespaces.d.ts +91 -0
  182. package/node_modules/@usejunior/docx-core/dist/primitives/namespaces.d.ts.map +1 -0
  183. package/node_modules/@usejunior/docx-core/dist/primitives/namespaces.js +108 -0
  184. package/node_modules/@usejunior/docx-core/dist/primitives/namespaces.js.map +1 -0
  185. package/node_modules/@usejunior/docx-core/dist/primitives/numbering.d.ts +27 -0
  186. package/node_modules/@usejunior/docx-core/dist/primitives/numbering.d.ts.map +1 -0
  187. package/node_modules/@usejunior/docx-core/dist/primitives/numbering.js +182 -0
  188. package/node_modules/@usejunior/docx-core/dist/primitives/numbering.js.map +1 -0
  189. package/node_modules/@usejunior/docx-core/dist/primitives/prevent_double_elevation.d.ts +18 -0
  190. package/node_modules/@usejunior/docx-core/dist/primitives/prevent_double_elevation.d.ts.map +1 -0
  191. package/node_modules/@usejunior/docx-core/dist/primitives/prevent_double_elevation.js +190 -0
  192. package/node_modules/@usejunior/docx-core/dist/primitives/prevent_double_elevation.js.map +1 -0
  193. package/node_modules/@usejunior/docx-core/dist/primitives/reject_changes.d.ts +27 -0
  194. package/node_modules/@usejunior/docx-core/dist/primitives/reject_changes.d.ts.map +1 -0
  195. package/node_modules/@usejunior/docx-core/dist/primitives/reject_changes.js +371 -0
  196. package/node_modules/@usejunior/docx-core/dist/primitives/reject_changes.js.map +1 -0
  197. package/node_modules/@usejunior/docx-core/dist/primitives/relationships.d.ts +7 -0
  198. package/node_modules/@usejunior/docx-core/dist/primitives/relationships.d.ts.map +1 -0
  199. package/node_modules/@usejunior/docx-core/dist/primitives/relationships.js +24 -0
  200. package/node_modules/@usejunior/docx-core/dist/primitives/relationships.js.map +1 -0
  201. package/node_modules/@usejunior/docx-core/dist/primitives/semantic_tags.d.ts +17 -0
  202. package/node_modules/@usejunior/docx-core/dist/primitives/semantic_tags.d.ts.map +1 -0
  203. package/node_modules/@usejunior/docx-core/dist/primitives/semantic_tags.js +58 -0
  204. package/node_modules/@usejunior/docx-core/dist/primitives/semantic_tags.js.map +1 -0
  205. package/node_modules/@usejunior/docx-core/dist/primitives/simplify_redlines.d.ts +19 -0
  206. package/node_modules/@usejunior/docx-core/dist/primitives/simplify_redlines.d.ts.map +1 -0
  207. package/node_modules/@usejunior/docx-core/dist/primitives/simplify_redlines.js +94 -0
  208. package/node_modules/@usejunior/docx-core/dist/primitives/simplify_redlines.js.map +1 -0
  209. package/node_modules/@usejunior/docx-core/dist/primitives/styles.d.ts +36 -0
  210. package/node_modules/@usejunior/docx-core/dist/primitives/styles.d.ts.map +1 -0
  211. package/node_modules/@usejunior/docx-core/dist/primitives/styles.js +205 -0
  212. package/node_modules/@usejunior/docx-core/dist/primitives/styles.js.map +1 -0
  213. package/node_modules/@usejunior/docx-core/dist/primitives/tables.d.ts +54 -0
  214. package/node_modules/@usejunior/docx-core/dist/primitives/tables.d.ts.map +1 -0
  215. package/node_modules/@usejunior/docx-core/dist/primitives/tables.js +205 -0
  216. package/node_modules/@usejunior/docx-core/dist/primitives/tables.js.map +1 -0
  217. package/node_modules/@usejunior/docx-core/dist/primitives/text.d.ts +30 -0
  218. package/node_modules/@usejunior/docx-core/dist/primitives/text.d.ts.map +1 -0
  219. package/node_modules/@usejunior/docx-core/dist/primitives/text.js +461 -0
  220. package/node_modules/@usejunior/docx-core/dist/primitives/text.js.map +1 -0
  221. package/node_modules/@usejunior/docx-core/dist/primitives/validate_document.d.ts +24 -0
  222. package/node_modules/@usejunior/docx-core/dist/primitives/validate_document.d.ts.map +1 -0
  223. package/node_modules/@usejunior/docx-core/dist/primitives/validate_document.js +147 -0
  224. package/node_modules/@usejunior/docx-core/dist/primitives/validate_document.js.map +1 -0
  225. package/node_modules/@usejunior/docx-core/dist/primitives/xml.d.ts +5 -0
  226. package/node_modules/@usejunior/docx-core/dist/primitives/xml.d.ts.map +1 -0
  227. package/node_modules/@usejunior/docx-core/dist/primitives/xml.js +19 -0
  228. package/node_modules/@usejunior/docx-core/dist/primitives/xml.js.map +1 -0
  229. package/node_modules/@usejunior/docx-core/dist/primitives/zip.d.ts +25 -0
  230. package/node_modules/@usejunior/docx-core/dist/primitives/zip.d.ts.map +1 -0
  231. package/node_modules/@usejunior/docx-core/dist/primitives/zip.js +78 -0
  232. package/node_modules/@usejunior/docx-core/dist/primitives/zip.js.map +1 -0
  233. package/node_modules/@usejunior/docx-core/dist/shared/docx/DocxArchive.d.ts +94 -0
  234. package/node_modules/@usejunior/docx-core/dist/shared/docx/DocxArchive.d.ts.map +1 -0
  235. package/node_modules/@usejunior/docx-core/dist/shared/docx/DocxArchive.js +169 -0
  236. package/node_modules/@usejunior/docx-core/dist/shared/docx/DocxArchive.js.map +1 -0
  237. package/node_modules/@usejunior/docx-core/dist/shared/ooxml/namespaces.d.ts +149 -0
  238. package/node_modules/@usejunior/docx-core/dist/shared/ooxml/namespaces.d.ts.map +1 -0
  239. package/node_modules/@usejunior/docx-core/dist/shared/ooxml/namespaces.js +224 -0
  240. package/node_modules/@usejunior/docx-core/dist/shared/ooxml/namespaces.js.map +1 -0
  241. package/node_modules/@usejunior/docx-core/dist/shared/ooxml/types.d.ts +136 -0
  242. package/node_modules/@usejunior/docx-core/dist/shared/ooxml/types.d.ts.map +1 -0
  243. package/node_modules/@usejunior/docx-core/dist/shared/ooxml/types.js +7 -0
  244. package/node_modules/@usejunior/docx-core/dist/shared/ooxml/types.js.map +1 -0
  245. package/node_modules/@usejunior/docx-core/dist/shared/validators/structural.d.ts +31 -0
  246. package/node_modules/@usejunior/docx-core/dist/shared/validators/structural.d.ts.map +1 -0
  247. package/node_modules/@usejunior/docx-core/dist/shared/validators/structural.js +110 -0
  248. package/node_modules/@usejunior/docx-core/dist/shared/validators/structural.js.map +1 -0
  249. package/node_modules/@usejunior/docx-core/package.json +26 -0
  250. package/node_modules/core-util-is/LICENSE +19 -0
  251. package/node_modules/core-util-is/README.md +3 -0
  252. package/node_modules/core-util-is/lib/util.js +107 -0
  253. package/node_modules/core-util-is/package.json +38 -0
  254. package/node_modules/diff-match-patch/LICENSE +202 -0
  255. package/node_modules/diff-match-patch/README.md +94 -0
  256. package/node_modules/diff-match-patch/index.js +2218 -0
  257. package/node_modules/diff-match-patch/package.json +22 -0
  258. package/node_modules/immediate/LICENSE.txt +20 -0
  259. package/node_modules/immediate/README.md +93 -0
  260. package/node_modules/immediate/dist/immediate.js +75 -0
  261. package/node_modules/immediate/dist/immediate.min.js +1 -0
  262. package/node_modules/immediate/lib/browser.js +69 -0
  263. package/node_modules/immediate/lib/index.js +73 -0
  264. package/node_modules/immediate/package.json +42 -0
  265. package/node_modules/inherits/LICENSE +16 -0
  266. package/node_modules/inherits/README.md +42 -0
  267. package/node_modules/inherits/inherits.js +9 -0
  268. package/node_modules/inherits/inherits_browser.js +27 -0
  269. package/node_modules/inherits/package.json +29 -0
  270. package/node_modules/isarray/.npmignore +1 -0
  271. package/node_modules/isarray/.travis.yml +4 -0
  272. package/node_modules/isarray/Makefile +6 -0
  273. package/node_modules/isarray/README.md +60 -0
  274. package/node_modules/isarray/component.json +19 -0
  275. package/node_modules/isarray/index.js +5 -0
  276. package/node_modules/isarray/package.json +45 -0
  277. package/node_modules/isarray/test.js +20 -0
  278. package/node_modules/jszip/.codeclimate.yml +16 -0
  279. package/node_modules/jszip/.editorconfig +8 -0
  280. package/node_modules/jszip/.eslintrc.js +43 -0
  281. package/node_modules/jszip/.github/workflows/pr.yaml +58 -0
  282. package/node_modules/jszip/.jekyll-metadata +0 -0
  283. package/node_modules/jszip/.travis.yml +17 -0
  284. package/node_modules/jszip/CHANGES.md +204 -0
  285. package/node_modules/jszip/LICENSE.markdown +651 -0
  286. package/node_modules/jszip/README.markdown +33 -0
  287. package/node_modules/jszip/deps.js +37 -0
  288. package/node_modules/jszip/dist/jszip.js +11577 -0
  289. package/node_modules/jszip/dist/jszip.min.js +13 -0
  290. package/node_modules/jszip/graph.svg +601 -0
  291. package/node_modules/jszip/index.d.ts +330 -0
  292. package/node_modules/jszip/lib/base64.js +106 -0
  293. package/node_modules/jszip/lib/compressedObject.js +74 -0
  294. package/node_modules/jszip/lib/compressions.js +14 -0
  295. package/node_modules/jszip/lib/crc32.js +77 -0
  296. package/node_modules/jszip/lib/defaults.js +11 -0
  297. package/node_modules/jszip/lib/external.js +18 -0
  298. package/node_modules/jszip/lib/flate.js +85 -0
  299. package/node_modules/jszip/lib/generate/ZipFileWorker.js +539 -0
  300. package/node_modules/jszip/lib/generate/index.js +57 -0
  301. package/node_modules/jszip/lib/index.js +55 -0
  302. package/node_modules/jszip/lib/license_header.js +11 -0
  303. package/node_modules/jszip/lib/load.js +88 -0
  304. package/node_modules/jszip/lib/nodejs/NodejsStreamInputAdapter.js +74 -0
  305. package/node_modules/jszip/lib/nodejs/NodejsStreamOutputAdapter.js +42 -0
  306. package/node_modules/jszip/lib/nodejsUtils.js +57 -0
  307. package/node_modules/jszip/lib/object.js +384 -0
  308. package/node_modules/jszip/lib/readable-stream-browser.js +10 -0
  309. package/node_modules/jszip/lib/reader/ArrayReader.js +57 -0
  310. package/node_modules/jszip/lib/reader/DataReader.js +116 -0
  311. package/node_modules/jszip/lib/reader/NodeBufferReader.js +19 -0
  312. package/node_modules/jszip/lib/reader/StringReader.js +38 -0
  313. package/node_modules/jszip/lib/reader/Uint8ArrayReader.js +22 -0
  314. package/node_modules/jszip/lib/reader/readerFor.js +28 -0
  315. package/node_modules/jszip/lib/signature.js +7 -0
  316. package/node_modules/jszip/lib/stream/ConvertWorker.js +26 -0
  317. package/node_modules/jszip/lib/stream/Crc32Probe.js +24 -0
  318. package/node_modules/jszip/lib/stream/DataLengthProbe.js +29 -0
  319. package/node_modules/jszip/lib/stream/DataWorker.js +116 -0
  320. package/node_modules/jszip/lib/stream/GenericWorker.js +263 -0
  321. package/node_modules/jszip/lib/stream/StreamHelper.js +214 -0
  322. package/node_modules/jszip/lib/support.js +38 -0
  323. package/node_modules/jszip/lib/utf8.js +275 -0
  324. package/node_modules/jszip/lib/utils.js +501 -0
  325. package/node_modules/jszip/lib/zipEntries.js +261 -0
  326. package/node_modules/jszip/lib/zipEntry.js +293 -0
  327. package/node_modules/jszip/lib/zipObject.js +133 -0
  328. package/node_modules/jszip/package.json +67 -0
  329. package/node_modules/jszip/sponsors.md +21 -0
  330. package/node_modules/jszip/tsconfig.json +101 -0
  331. package/node_modules/jszip/vendor/FileSaver.js +247 -0
  332. package/node_modules/lie/README.md +62 -0
  333. package/node_modules/lie/dist/lie.js +350 -0
  334. package/node_modules/lie/dist/lie.min.js +1 -0
  335. package/node_modules/lie/dist/lie.polyfill.js +358 -0
  336. package/node_modules/lie/dist/lie.polyfill.min.js +1 -0
  337. package/node_modules/lie/lib/browser.js +273 -0
  338. package/node_modules/lie/lib/index.js +298 -0
  339. package/node_modules/lie/license.md +7 -0
  340. package/node_modules/lie/lie.d.ts +244 -0
  341. package/node_modules/lie/package.json +69 -0
  342. package/node_modules/lie/polyfill.js +4 -0
  343. package/node_modules/pako/LICENSE +21 -0
  344. package/node_modules/pako/README.md +191 -0
  345. package/node_modules/pako/dist/pako.js +6818 -0
  346. package/node_modules/pako/dist/pako.min.js +1 -0
  347. package/node_modules/pako/dist/pako_deflate.js +3997 -0
  348. package/node_modules/pako/dist/pako_deflate.min.js +1 -0
  349. package/node_modules/pako/dist/pako_inflate.js +3300 -0
  350. package/node_modules/pako/dist/pako_inflate.min.js +1 -0
  351. package/node_modules/pako/index.js +14 -0
  352. package/node_modules/pako/lib/deflate.js +400 -0
  353. package/node_modules/pako/lib/inflate.js +423 -0
  354. package/node_modules/pako/lib/utils/common.js +105 -0
  355. package/node_modules/pako/lib/utils/strings.js +187 -0
  356. package/node_modules/pako/lib/zlib/README +59 -0
  357. package/node_modules/pako/lib/zlib/adler32.js +51 -0
  358. package/node_modules/pako/lib/zlib/constants.js +68 -0
  359. package/node_modules/pako/lib/zlib/crc32.js +59 -0
  360. package/node_modules/pako/lib/zlib/deflate.js +1874 -0
  361. package/node_modules/pako/lib/zlib/gzheader.js +58 -0
  362. package/node_modules/pako/lib/zlib/inffast.js +345 -0
  363. package/node_modules/pako/lib/zlib/inflate.js +1556 -0
  364. package/node_modules/pako/lib/zlib/inftrees.js +343 -0
  365. package/node_modules/pako/lib/zlib/messages.js +32 -0
  366. package/node_modules/pako/lib/zlib/trees.js +1222 -0
  367. package/node_modules/pako/lib/zlib/zstream.js +47 -0
  368. package/node_modules/pako/package.json +44 -0
  369. package/node_modules/process-nextick-args/index.js +45 -0
  370. package/node_modules/process-nextick-args/license.md +19 -0
  371. package/node_modules/process-nextick-args/package.json +25 -0
  372. package/node_modules/process-nextick-args/readme.md +18 -0
  373. package/node_modules/readable-stream/.travis.yml +34 -0
  374. package/node_modules/readable-stream/CONTRIBUTING.md +38 -0
  375. package/node_modules/readable-stream/GOVERNANCE.md +136 -0
  376. package/node_modules/readable-stream/LICENSE +47 -0
  377. package/node_modules/readable-stream/README.md +58 -0
  378. package/node_modules/readable-stream/doc/wg-meetings/2015-01-30.md +60 -0
  379. package/node_modules/readable-stream/duplex-browser.js +1 -0
  380. package/node_modules/readable-stream/duplex.js +1 -0
  381. package/node_modules/readable-stream/lib/_stream_duplex.js +131 -0
  382. package/node_modules/readable-stream/lib/_stream_passthrough.js +47 -0
  383. package/node_modules/readable-stream/lib/_stream_readable.js +1019 -0
  384. package/node_modules/readable-stream/lib/_stream_transform.js +214 -0
  385. package/node_modules/readable-stream/lib/_stream_writable.js +685 -0
  386. package/node_modules/readable-stream/lib/internal/streams/BufferList.js +78 -0
  387. package/node_modules/readable-stream/lib/internal/streams/destroy.js +84 -0
  388. package/node_modules/readable-stream/lib/internal/streams/stream-browser.js +1 -0
  389. package/node_modules/readable-stream/lib/internal/streams/stream.js +1 -0
  390. package/node_modules/readable-stream/package.json +52 -0
  391. package/node_modules/readable-stream/passthrough.js +1 -0
  392. package/node_modules/readable-stream/readable-browser.js +7 -0
  393. package/node_modules/readable-stream/readable.js +19 -0
  394. package/node_modules/readable-stream/transform.js +1 -0
  395. package/node_modules/readable-stream/writable-browser.js +1 -0
  396. package/node_modules/readable-stream/writable.js +8 -0
  397. package/node_modules/safe-buffer/LICENSE +21 -0
  398. package/node_modules/safe-buffer/README.md +584 -0
  399. package/node_modules/safe-buffer/index.d.ts +187 -0
  400. package/node_modules/safe-buffer/index.js +62 -0
  401. package/node_modules/safe-buffer/package.json +37 -0
  402. package/node_modules/setimmediate/LICENSE.txt +20 -0
  403. package/node_modules/setimmediate/package.json +30 -0
  404. package/node_modules/setimmediate/setImmediate.js +186 -0
  405. package/node_modules/string_decoder/.travis.yml +50 -0
  406. package/node_modules/string_decoder/LICENSE +48 -0
  407. package/node_modules/string_decoder/README.md +47 -0
  408. package/node_modules/string_decoder/lib/string_decoder.js +296 -0
  409. package/node_modules/string_decoder/package.json +31 -0
  410. package/node_modules/util-deprecate/History.md +16 -0
  411. package/node_modules/util-deprecate/LICENSE +24 -0
  412. package/node_modules/util-deprecate/README.md +53 -0
  413. package/node_modules/util-deprecate/browser.js +67 -0
  414. package/node_modules/util-deprecate/node.js +6 -0
  415. package/node_modules/util-deprecate/package.json +27 -0
  416. package/package.json +9 -4
  417. package/packages/docx-core/node_modules/@xmldom/xmldom/CHANGELOG.md +468 -0
  418. package/packages/docx-core/node_modules/@xmldom/xmldom/LICENSE +8 -0
  419. package/packages/docx-core/node_modules/@xmldom/xmldom/SECURITY.md +50 -0
  420. package/packages/docx-core/node_modules/@xmldom/xmldom/index.d.ts +43 -0
  421. package/packages/docx-core/node_modules/@xmldom/xmldom/lib/.eslintrc.yml +2 -0
  422. package/packages/docx-core/node_modules/@xmldom/xmldom/lib/conventions.js +203 -0
  423. package/packages/docx-core/node_modules/@xmldom/xmldom/lib/dom-parser.js +322 -0
  424. package/packages/docx-core/node_modules/@xmldom/xmldom/lib/dom.js +1879 -0
  425. package/packages/docx-core/node_modules/@xmldom/xmldom/lib/entities.js +2166 -0
  426. package/packages/docx-core/node_modules/@xmldom/xmldom/lib/index.js +4 -0
  427. package/packages/docx-core/node_modules/@xmldom/xmldom/lib/sax.js +662 -0
  428. package/packages/docx-core/node_modules/@xmldom/xmldom/package.json +71 -0
  429. package/packages/docx-core/node_modules/@xmldom/xmldom/readme.md +356 -0
@@ -0,0 +1,910 @@
1
+ /**
2
+ * Atomizer Pipeline
3
+ *
4
+ * Main orchestration for the atomizer-based document comparison.
5
+ * Integrates atomization, LCS comparison, move detection, format detection,
6
+ * and document reconstruction.
7
+ */
8
+ import { DOMParser, XMLSerializer } from '@xmldom/xmldom';
9
+ import { DocxArchive } from '../../shared/docx/DocxArchive.js';
10
+ import { DEFAULT_MOVE_DETECTION_SETTINGS, DEFAULT_FORMAT_DETECTION_SETTINGS, CorrelationStatus, } from '../../core-types.js';
11
+ import { atomizeTree, assignParagraphIndices } from '../../atomizer.js';
12
+ import { detectMovesInAtomList } from '../../move-detection.js';
13
+ import { detectFormatChangesInAtomList } from '../../format-detection.js';
14
+ import { parseDocumentXml, findBody, backfillParentReferences, } from './xmlToWmlElement.js';
15
+ import { findAllByTagName, getLeafText } from '../../primitives/index.js';
16
+ import { createMergedAtomList, assignUnifiedParagraphIndices, } from './atomLcs.js';
17
+ import { hierarchicalCompare, markHierarchicalCorrelationStatus, } from './hierarchicalLcs.js';
18
+ import { reconstructDocument, computeReconstructionStats, } from './documentReconstructor.js';
19
+ import { modifyRevisedDocument } from './inPlaceModifier.js';
20
+ import { acceptAllChanges, rejectAllChanges, extractTextWithParagraphs, compareTexts, } from './trackChangesAcceptorAst.js';
21
+ import { virtualizeNumberingLabels, DEFAULT_NUMBERING_OPTIONS, } from './numberingIntegration.js';
22
+ import { premergeAdjacentRuns } from './premergeRuns.js';
23
+ function arraysEqual(a, b) {
24
+ if (a.length !== b.length)
25
+ return false;
26
+ for (let i = 0; i < a.length; i++) {
27
+ if (a[i] !== b[i])
28
+ return false;
29
+ }
30
+ return true;
31
+ }
32
+ function collectReferencedBookmarkNames(root) {
33
+ const refs = new Set();
34
+ const refRegex = /\b(?:PAGEREF|REF)\s+([^\s\\]+)/g;
35
+ for (const node of findAllByTagName(root, 'w:instrText')) {
36
+ const instr = getLeafText(node) ?? '';
37
+ for (const match of instr.matchAll(refRegex)) {
38
+ const name = match[1]?.trim();
39
+ if (name)
40
+ refs.add(name);
41
+ }
42
+ }
43
+ return Array.from(refs).sort();
44
+ }
45
+ function collectBookmarkDiagnostics(documentXml) {
46
+ const root = parseDocumentXml(documentXml);
47
+ const startSet = new Set();
48
+ const endSet = new Set();
49
+ const startNameSet = new Set();
50
+ const duplicateStartSet = new Set();
51
+ const duplicateEndSet = new Set();
52
+ const duplicateStartNameSet = new Set();
53
+ for (const node of findAllByTagName(root, 'w:bookmarkStart')) {
54
+ const id = node.getAttribute('w:id');
55
+ if (!id)
56
+ continue;
57
+ if (startSet.has(id))
58
+ duplicateStartSet.add(id);
59
+ else
60
+ startSet.add(id);
61
+ const name = node.getAttribute('w:name');
62
+ if (name) {
63
+ if (startNameSet.has(name))
64
+ duplicateStartNameSet.add(name);
65
+ else
66
+ startNameSet.add(name);
67
+ }
68
+ }
69
+ for (const node of findAllByTagName(root, 'w:bookmarkEnd')) {
70
+ const id = node.getAttribute('w:id');
71
+ if (!id)
72
+ continue;
73
+ if (endSet.has(id))
74
+ duplicateEndSet.add(id);
75
+ else
76
+ endSet.add(id);
77
+ }
78
+ const startIds = Array.from(startSet).sort();
79
+ const endIds = Array.from(endSet).sort();
80
+ const startNames = Array.from(startNameSet).sort();
81
+ const referencedBookmarkNames = collectReferencedBookmarkNames(root);
82
+ const unresolvedReferenceNames = referencedBookmarkNames
83
+ .filter((name) => !startNameSet.has(name))
84
+ .sort();
85
+ const unmatchedStartIds = startIds.filter((id) => !endSet.has(id));
86
+ const unmatchedEndIds = endIds.filter((id) => !startSet.has(id));
87
+ return {
88
+ startIds,
89
+ endIds,
90
+ startNames,
91
+ duplicateStartNames: Array.from(duplicateStartNameSet).sort(),
92
+ referencedBookmarkNames,
93
+ unresolvedReferenceNames,
94
+ duplicateStartIds: Array.from(duplicateStartSet).sort(),
95
+ duplicateEndIds: Array.from(duplicateEndSet).sort(),
96
+ unmatchedStartIds,
97
+ unmatchedEndIds,
98
+ };
99
+ }
100
+ /**
101
+ * Bookmark round-trip safety is semantic, not byte/ID exact:
102
+ * - Bookmark IDs may be renumbered by reconstruction/Word and still be valid.
103
+ * - Bookmark names and field-reference targets must stay intact.
104
+ * - Structural integrity (balanced, no duplicates) must remain intact.
105
+ */
106
+ function bookmarkDiagnosticsSemanticallyEqual(expected, actual) {
107
+ return (arraysEqual(expected.startNames, actual.startNames) &&
108
+ arraysEqual(expected.duplicateStartNames, actual.duplicateStartNames) &&
109
+ arraysEqual(expected.referencedBookmarkNames, actual.referencedBookmarkNames) &&
110
+ arraysEqual(expected.unresolvedReferenceNames, actual.unresolvedReferenceNames) &&
111
+ arraysEqual(expected.duplicateStartIds, actual.duplicateStartIds) &&
112
+ arraysEqual(expected.duplicateEndIds, actual.duplicateEndIds) &&
113
+ arraysEqual(expected.unmatchedStartIds, actual.unmatchedStartIds) &&
114
+ arraysEqual(expected.unmatchedEndIds, actual.unmatchedEndIds));
115
+ }
116
+ function diffIds(expected, actual) {
117
+ const expectedSet = new Set(expected);
118
+ const actualSet = new Set(actual);
119
+ const missing = expected.filter((id) => !actualSet.has(id));
120
+ const unexpected = actual.filter((id) => !expectedSet.has(id));
121
+ return { missing, unexpected };
122
+ }
123
+ function buildTextMismatchDetails(expectedText, actualText) {
124
+ const comparison = compareTexts(expectedText, actualText);
125
+ const expectedParas = expectedText.split('\n');
126
+ const actualParas = actualText.split('\n');
127
+ const maxLen = Math.max(expectedParas.length, actualParas.length);
128
+ let firstDifferingParagraphIndex = -1;
129
+ for (let i = 0; i < maxLen; i++) {
130
+ if ((expectedParas[i] ?? '') !== (actualParas[i] ?? '')) {
131
+ firstDifferingParagraphIndex = i;
132
+ break;
133
+ }
134
+ }
135
+ return {
136
+ expectedLength: comparison.expectedLength,
137
+ actualLength: comparison.actualLength,
138
+ firstDifferingParagraphIndex,
139
+ expectedParagraph: firstDifferingParagraphIndex >= 0 ? (expectedParas[firstDifferingParagraphIndex] ?? '') : '',
140
+ actualParagraph: firstDifferingParagraphIndex >= 0 ? (actualParas[firstDifferingParagraphIndex] ?? '') : '',
141
+ differenceSample: comparison.differences.slice(0, 3),
142
+ };
143
+ }
144
+ function buildBookmarkMismatchDetails(expected, actual) {
145
+ return {
146
+ startNames: diffIds(expected.startNames, actual.startNames),
147
+ referencedBookmarkNames: diffIds(expected.referencedBookmarkNames, actual.referencedBookmarkNames),
148
+ unresolvedReferenceNames: diffIds(expected.unresolvedReferenceNames, actual.unresolvedReferenceNames),
149
+ startIds: diffIds(expected.startIds, actual.startIds),
150
+ endIds: diffIds(expected.endIds, actual.endIds),
151
+ expectedDuplicateStartNames: expected.duplicateStartNames,
152
+ actualDuplicateStartNames: actual.duplicateStartNames,
153
+ expectedDuplicateStartIds: expected.duplicateStartIds,
154
+ actualDuplicateStartIds: actual.duplicateStartIds,
155
+ expectedDuplicateEndIds: expected.duplicateEndIds,
156
+ actualDuplicateEndIds: actual.duplicateEndIds,
157
+ expectedUnmatchedStartIds: expected.unmatchedStartIds,
158
+ actualUnmatchedStartIds: actual.unmatchedStartIds,
159
+ expectedUnmatchedEndIds: expected.unmatchedEndIds,
160
+ actualUnmatchedEndIds: actual.unmatchedEndIds,
161
+ };
162
+ }
163
+ function summarizeIdDelta(delta) {
164
+ return {
165
+ missingCount: delta.missing.length,
166
+ unexpectedCount: delta.unexpected.length,
167
+ firstMissing: delta.missing[0],
168
+ firstUnexpected: delta.unexpected[0],
169
+ };
170
+ }
171
+ function truncateForSummary(value, maxLength = 160) {
172
+ if (value.length <= maxLength) {
173
+ return value;
174
+ }
175
+ return `${value.slice(0, maxLength)}...`;
176
+ }
177
+ function summarizeTextMismatch(details) {
178
+ return {
179
+ firstDifferingParagraphIndex: details.firstDifferingParagraphIndex,
180
+ expectedParagraph: truncateForSummary(details.expectedParagraph),
181
+ actualParagraph: truncateForSummary(details.actualParagraph),
182
+ firstDifference: details.differenceSample[0] ?? 'No diff sample',
183
+ };
184
+ }
185
+ function summarizeBookmarkMismatch(details) {
186
+ return {
187
+ startNames: summarizeIdDelta(details.startNames),
188
+ referencedBookmarkNames: summarizeIdDelta(details.referencedBookmarkNames),
189
+ unresolvedReferenceNames: summarizeIdDelta(details.unresolvedReferenceNames),
190
+ startIds: summarizeIdDelta(details.startIds),
191
+ endIds: summarizeIdDelta(details.endIds),
192
+ unmatchedStartCount: details.actualUnmatchedStartIds.length,
193
+ unmatchedEndCount: details.actualUnmatchedEndIds.length,
194
+ firstUnmatchedStartId: details.actualUnmatchedStartIds[0],
195
+ firstUnmatchedEndId: details.actualUnmatchedEndIds[0],
196
+ };
197
+ }
198
+ function buildFailureSummary(failureDetails) {
199
+ if (!failureDetails) {
200
+ return undefined;
201
+ }
202
+ const summary = {};
203
+ if (failureDetails.acceptText) {
204
+ summary.acceptText = summarizeTextMismatch(failureDetails.acceptText);
205
+ }
206
+ if (failureDetails.rejectText) {
207
+ summary.rejectText = summarizeTextMismatch(failureDetails.rejectText);
208
+ }
209
+ if (failureDetails.acceptBookmarks) {
210
+ summary.acceptBookmarks = summarizeBookmarkMismatch(failureDetails.acceptBookmarks);
211
+ }
212
+ if (failureDetails.rejectBookmarks) {
213
+ summary.rejectBookmarks = summarizeBookmarkMismatch(failureDetails.rejectBookmarks);
214
+ }
215
+ return Object.keys(summary).length > 0 ? summary : undefined;
216
+ }
217
+ /**
218
+ * Validate field structure integrity in document XML.
219
+ *
220
+ * Checks that fldChar begin/end are balanced and that w:instrText only
221
+ * appears inside a proper field sequence (between begin and separate).
222
+ * Orphaned instrText elements render as visible text in Word.
223
+ */
224
+ function validateFieldStructure(documentXml) {
225
+ const root = parseDocumentXml(documentXml);
226
+ // Walk the document in order, tracking field nesting
227
+ const allFldChars = findAllByTagName(root, 'w:fldChar');
228
+ const allInstrTexts = findAllByTagName(root, 'w:instrText');
229
+ // Quick balance check
230
+ let begins = 0;
231
+ let ends = 0;
232
+ for (const fc of allFldChars) {
233
+ const type = fc.getAttribute('w:fldCharType');
234
+ if (type === 'begin')
235
+ begins++;
236
+ else if (type === 'end')
237
+ ends++;
238
+ }
239
+ if (begins !== ends)
240
+ return false;
241
+ // Check that instrText elements are inside a field (between begin and separate).
242
+ // Walk all elements in document order using a recursive scan.
243
+ if (allInstrTexts.length === 0)
244
+ return true; // No instrText, nothing to validate
245
+ // Depth-first scan to check instrText placement
246
+ let depth = 0;
247
+ const pastSeparatorAtDepth = []; // track separator state per depth
248
+ function scan(node) {
249
+ for (let child = node.firstChild; child; child = child.nextSibling) {
250
+ if (child.nodeType !== 1)
251
+ continue; // skip non-elements
252
+ const el = child;
253
+ if (el.tagName === 'w:fldChar') {
254
+ const type = el.getAttribute('w:fldCharType');
255
+ if (type === 'begin') {
256
+ depth++;
257
+ pastSeparatorAtDepth[depth] = 0;
258
+ }
259
+ else if (type === 'separate') {
260
+ if (depth > 0)
261
+ pastSeparatorAtDepth[depth] = 1;
262
+ }
263
+ else if (type === 'end') {
264
+ if (depth > 0)
265
+ depth--;
266
+ }
267
+ }
268
+ else if (el.tagName === 'w:instrText') {
269
+ // instrText must be inside a field (depth > 0) and before the separator
270
+ if (depth === 0 || pastSeparatorAtDepth[depth])
271
+ return false;
272
+ }
273
+ if (!scan(el))
274
+ return false;
275
+ }
276
+ return true;
277
+ }
278
+ return scan(root);
279
+ }
280
+ function evaluateSafetyChecks(originalTextForRoundTrip, revisedTextForRoundTrip, originalBookmarkDiagnostics, revisedBookmarkDiagnostics, candidateXml) {
281
+ const acceptedXml = acceptAllChanges(candidateXml);
282
+ const rejectedXml = rejectAllChanges(candidateXml);
283
+ const acceptedText = extractTextWithParagraphs(acceptedXml);
284
+ const rejectedText = extractTextWithParagraphs(rejectedXml);
285
+ const acceptedBookmarkDiagnostics = collectBookmarkDiagnostics(acceptedXml);
286
+ const rejectedBookmarkDiagnostics = collectBookmarkDiagnostics(rejectedXml);
287
+ const acceptTextComparison = compareTexts(revisedTextForRoundTrip, acceptedText);
288
+ const rejectTextComparison = compareTexts(originalTextForRoundTrip, rejectedText);
289
+ const acceptBookmarksOk = bookmarkDiagnosticsSemanticallyEqual(revisedBookmarkDiagnostics, acceptedBookmarkDiagnostics);
290
+ const rejectBookmarksOk = bookmarkDiagnosticsSemanticallyEqual(originalBookmarkDiagnostics, rejectedBookmarkDiagnostics);
291
+ // Validate field structure: after accept-all and reject-all, every
292
+ // w:instrText must be inside a proper field sequence (between fldChar
293
+ // begin and fldChar separate). Orphaned instrText renders as visible
294
+ // text in Word.
295
+ const fieldStructureOk = validateFieldStructure(acceptedXml) && validateFieldStructure(rejectedXml);
296
+ const checks = {
297
+ acceptText: acceptTextComparison.normalizedIdentical,
298
+ rejectText: rejectTextComparison.normalizedIdentical,
299
+ // Bookmark checks are soft: consumer compatibility pass legitimately alters
300
+ // bookmarks (deduplication, orphan repair, hoisting out of revision wrappers).
301
+ // Log mismatches in diagnostics but don't trigger fallback to rebuild.
302
+ acceptBookmarks: true,
303
+ rejectBookmarks: true,
304
+ fieldStructure: fieldStructureOk,
305
+ };
306
+ const failedChecks = Object.entries(checks)
307
+ .filter(([, ok]) => !ok)
308
+ .map(([name]) => name);
309
+ const failureDetails = {};
310
+ if (!checks.acceptText) {
311
+ failureDetails.acceptText = buildTextMismatchDetails(revisedTextForRoundTrip, acceptedText);
312
+ }
313
+ if (!checks.rejectText) {
314
+ failureDetails.rejectText = buildTextMismatchDetails(originalTextForRoundTrip, rejectedText);
315
+ }
316
+ // Bookmark mismatches are always collected for diagnostics even though the
317
+ // check itself is soft (doesn't trigger fallback).
318
+ if (!acceptBookmarksOk) {
319
+ failureDetails.acceptBookmarks = buildBookmarkMismatchDetails(revisedBookmarkDiagnostics, acceptedBookmarkDiagnostics);
320
+ }
321
+ if (!rejectBookmarksOk) {
322
+ failureDetails.rejectBookmarks = buildBookmarkMismatchDetails(originalBookmarkDiagnostics, rejectedBookmarkDiagnostics);
323
+ }
324
+ return {
325
+ safe: failedChecks.length === 0,
326
+ checks,
327
+ failedChecks,
328
+ failureDetails: failedChecks.length > 0 ? failureDetails : undefined,
329
+ failureSummary: failedChecks.length > 0 ? buildFailureSummary(failureDetails) : undefined,
330
+ };
331
+ }
332
+ /**
333
+ * Compare two DOCX documents using the atomizer-based approach.
334
+ *
335
+ * Pipeline steps:
336
+ * 1. Load DOCX archives
337
+ * 2. Extract document.xml
338
+ * 3. Parse to WmlElement trees
339
+ * 4. Atomize both documents
340
+ * 5. (Optional) Apply numbering virtualization
341
+ * 6. Run LCS on atom hashes
342
+ * 7. Mark correlation status
343
+ * 8. Run move detection
344
+ * 9. Run format detection
345
+ * 10. Reconstruct document with track changes
346
+ * 11. Save and return result
347
+ *
348
+ * @param original - Original document as Buffer
349
+ * @param revised - Revised document as Buffer
350
+ * @param options - Pipeline options
351
+ * @returns Comparison result with track changes document
352
+ */
353
+ export async function compareDocumentsAtomizer(original, revised, options = {}) {
354
+ const { author = 'Comparison', date = new Date(), moveDetection = {}, formatDetection = {}, numbering = {}, premergeRuns = true, reconstructionMode = 'rebuild', } = options;
355
+ // Merge settings with defaults
356
+ const moveSettings = {
357
+ ...DEFAULT_MOVE_DETECTION_SETTINGS,
358
+ ...moveDetection,
359
+ };
360
+ const formatSettings = {
361
+ ...DEFAULT_FORMAT_DETECTION_SETTINGS,
362
+ ...formatDetection,
363
+ };
364
+ const numberingSettings = {
365
+ ...DEFAULT_NUMBERING_OPTIONS,
366
+ ...numbering,
367
+ };
368
+ // Step 1: Load DOCX archives
369
+ const originalArchive = await DocxArchive.load(original);
370
+ const revisedArchive = await DocxArchive.load(revised);
371
+ // Step 2: Extract document.xml
372
+ const originalXml = await originalArchive.getDocumentXml();
373
+ const revisedXml = await revisedArchive.getDocumentXml();
374
+ // Extract numbering.xml if available
375
+ const originalNumberingXml = await originalArchive.getNumberingXml() ?? undefined;
376
+ const revisedNumberingXml = await revisedArchive.getNumberingXml() ?? undefined;
377
+ const originalPart = {
378
+ uri: 'word/document.xml',
379
+ contentType: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml',
380
+ };
381
+ const revisedPart = {
382
+ uri: 'word/document.xml',
383
+ contentType: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml',
384
+ };
385
+ const originalTextForRoundTrip = extractTextWithParagraphs(originalXml);
386
+ const revisedTextForRoundTrip = extractTextWithParagraphs(revisedXml);
387
+ const originalBookmarkDiagnostics = collectBookmarkDiagnostics(originalXml);
388
+ const revisedBookmarkDiagnostics = collectBookmarkDiagnostics(revisedXml);
389
+ const runComparisonPass = (atomizeOptions, outputMode) => {
390
+ // Parse fresh trees for each pass because inplace reconstruction mutates revised AST.
391
+ const originalTree = parseDocumentXml(originalXml);
392
+ const revisedTree = parseDocumentXml(revisedXml);
393
+ backfillParentReferences(originalTree);
394
+ backfillParentReferences(revisedTree);
395
+ const originalBody = findBody(originalTree);
396
+ const revisedBody = findBody(revisedTree);
397
+ if (!originalBody || !revisedBody) {
398
+ throw new Error('Could not find w:body in one or both documents');
399
+ }
400
+ if (premergeRuns) {
401
+ premergeAdjacentRuns(originalBody);
402
+ premergeAdjacentRuns(revisedBody);
403
+ }
404
+ const { atoms: originalAtoms } = atomizeTree(originalBody, [], originalPart, atomizeOptions);
405
+ const { atoms: revisedAtoms } = atomizeTree(revisedBody, [], revisedPart, atomizeOptions);
406
+ // Assign paragraph indices for proper grouping during reconstruction
407
+ assignParagraphIndices(originalAtoms);
408
+ assignParagraphIndices(revisedAtoms);
409
+ // Step 5: Apply numbering virtualization (optional)
410
+ if (numberingSettings.enabled) {
411
+ virtualizeNumberingLabels(originalAtoms, originalNumberingXml, numberingSettings);
412
+ virtualizeNumberingLabels(revisedAtoms, revisedNumberingXml, numberingSettings);
413
+ }
414
+ // Step 6: Run hierarchical LCS (paragraph-level first, then atom-level within)
415
+ const lcsResult = hierarchicalCompare(originalAtoms, revisedAtoms);
416
+ // Step 7: Mark correlation status using hierarchical result
417
+ markHierarchicalCorrelationStatus(originalAtoms, revisedAtoms, lcsResult);
418
+ // Step 8: Run move detection
419
+ if (moveSettings.detectMoves) {
420
+ // Create a combined list for move detection
421
+ // Move detection looks at the revised atoms with Inserted status
422
+ // and original atoms with Deleted status
423
+ const allAtoms = [...originalAtoms, ...revisedAtoms];
424
+ detectMovesInAtomList(allAtoms, moveSettings);
425
+ }
426
+ // Step 9: Run format detection
427
+ if (formatSettings.detectFormatChanges) {
428
+ // Format detection operates on the revised atoms that are Equal
429
+ detectFormatChangesInAtomList(revisedAtoms, formatSettings);
430
+ }
431
+ // Step 10: Create merged atom list for reconstruction
432
+ const mergedAtoms = createMergedAtomList(originalAtoms, revisedAtoms, lcsResult);
433
+ // Step 10b: Assign unified paragraph indices to handle atoms from different trees
434
+ assignUnifiedParagraphIndices(originalAtoms, revisedAtoms, mergedAtoms, lcsResult);
435
+ // Step 11: Reconstruct document with track changes
436
+ let newDocumentXml;
437
+ if (outputMode === 'inplace') {
438
+ // In-place mode: modify the revised AST directly, producing revised-based output.
439
+ newDocumentXml = modifyRevisedDocument(revisedTree, originalAtoms, revisedAtoms, mergedAtoms, { author, date });
440
+ }
441
+ else {
442
+ // Rebuild mode: reconstruct from atoms using original as the structural base.
443
+ newDocumentXml = reconstructDocument(mergedAtoms, originalXml, { author, date });
444
+ }
445
+ return { mergedAtoms, newDocumentXml, outputMode };
446
+ };
447
+ const evaluateRoundTripSafety = (candidateXml) => evaluateSafetyChecks(originalTextForRoundTrip, revisedTextForRoundTrip, originalBookmarkDiagnostics, revisedBookmarkDiagnostics, candidateXml);
448
+ let comparisonResult;
449
+ let fallbackReason;
450
+ let fallbackDiagnostics;
451
+ if (reconstructionMode === 'inplace') {
452
+ // Adaptive strategy:
453
+ // 1) Try no-cross-run passes first (higher run anchoring fidelity).
454
+ // 2) If safety fails, retry with cross-run merging to handle run-fragmented docs.
455
+ // 3) If still unsafe, reuse rebuild reconstruction as a hard safety fallback.
456
+ const inplacePasses = [
457
+ {
458
+ pass: 'inplace_word_split',
459
+ atomizeOptions: {
460
+ cloneLeafNodes: true,
461
+ mergeAcrossRuns: false,
462
+ mergePunctuationAcrossRuns: false,
463
+ splitTextIntoWords: true,
464
+ },
465
+ },
466
+ {
467
+ pass: 'inplace_run_level',
468
+ atomizeOptions: {
469
+ cloneLeafNodes: true,
470
+ mergeAcrossRuns: false,
471
+ mergePunctuationAcrossRuns: false,
472
+ splitTextIntoWords: false,
473
+ },
474
+ },
475
+ {
476
+ pass: 'inplace_word_split_cross_run',
477
+ atomizeOptions: {
478
+ cloneLeafNodes: true,
479
+ mergeAcrossRuns: true,
480
+ mergePunctuationAcrossRuns: true,
481
+ splitTextIntoWords: true,
482
+ },
483
+ },
484
+ {
485
+ pass: 'inplace_run_level_cross_run',
486
+ atomizeOptions: {
487
+ cloneLeafNodes: true,
488
+ mergeAcrossRuns: true,
489
+ mergePunctuationAcrossRuns: true,
490
+ splitTextIntoWords: false,
491
+ },
492
+ },
493
+ ];
494
+ const failedAttempts = [];
495
+ let selected;
496
+ for (const { pass, atomizeOptions } of inplacePasses) {
497
+ const candidate = runComparisonPass(atomizeOptions, 'inplace');
498
+ const safety = evaluateRoundTripSafety(candidate.newDocumentXml);
499
+ if (safety.safe) {
500
+ selected = candidate;
501
+ break;
502
+ }
503
+ failedAttempts.push({
504
+ pass,
505
+ checks: safety.checks,
506
+ failedChecks: safety.failedChecks,
507
+ failureDetails: safety.failureDetails,
508
+ firstDiffSummary: safety.failureSummary,
509
+ });
510
+ }
511
+ if (selected) {
512
+ comparisonResult = selected;
513
+ }
514
+ else {
515
+ comparisonResult = runComparisonPass(undefined, 'rebuild');
516
+ fallbackReason = 'round_trip_safety_check_failed';
517
+ fallbackDiagnostics = {
518
+ attempts: failedAttempts,
519
+ };
520
+ }
521
+ }
522
+ else {
523
+ comparisonResult = runComparisonPass(undefined, 'rebuild');
524
+ }
525
+ const { mergedAtoms, newDocumentXml } = comparisonResult;
526
+ // Step 12: Clone appropriate archive and update document.xml.
527
+ // Use the revised archive only for true inplace output.
528
+ const baseArchive = comparisonResult.outputMode === 'inplace' ? revisedArchive : originalArchive;
529
+ const resultArchive = await baseArchive.clone();
530
+ resultArchive.setDocumentXml(newDocumentXml);
531
+ // Step 12b: For inplace mode, merge auxiliary part definitions (footnotes,
532
+ // endnotes, comments) from the original document. Inplace reconstruction
533
+ // inserts deleted content that may reference definitions not present in the
534
+ // revised archive.
535
+ if (comparisonResult.outputMode === 'inplace') {
536
+ const mergeResults = new Map();
537
+ for (const descriptor of AUXILIARY_PARTS) {
538
+ const result = await mergeAuxiliaryPartDefinitions(originalArchive, resultArchive, newDocumentXml, descriptor);
539
+ if (result.mergedIds.size > 0) {
540
+ mergeResults.set(descriptor.label, result);
541
+ }
542
+ }
543
+ // Post-merge hook for comment ancillary parts
544
+ if (mergeResults.has('comment')) {
545
+ await mergeCommentAncillaryParts(originalArchive, resultArchive, mergeResults.get('comment'));
546
+ }
547
+ }
548
+ // Step 13: Save result and compute stats
549
+ const resultBuffer = await resultArchive.save();
550
+ const stats = computeStats(mergedAtoms);
551
+ return {
552
+ document: resultBuffer,
553
+ stats,
554
+ engine: 'atomizer',
555
+ reconstructionModeRequested: reconstructionMode,
556
+ reconstructionModeUsed: comparisonResult.outputMode,
557
+ fallbackReason,
558
+ fallbackDiagnostics,
559
+ };
560
+ }
561
+ const AUXILIARY_PARTS = [
562
+ {
563
+ label: 'footnote',
564
+ partPath: 'word/footnotes.xml',
565
+ referenceTag: 'w:footnoteReference',
566
+ entryTag: 'w:footnote',
567
+ rootTag: 'w:footnotes',
568
+ contentType: 'application/vnd.openxmlformats-officedocument.wordprocessingml.footnotes+xml',
569
+ relationshipType: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/footnotes',
570
+ },
571
+ {
572
+ label: 'endnote',
573
+ partPath: 'word/endnotes.xml',
574
+ referenceTag: 'w:endnoteReference',
575
+ entryTag: 'w:endnote',
576
+ rootTag: 'w:endnotes',
577
+ contentType: 'application/vnd.openxmlformats-officedocument.wordprocessingml.endnotes+xml',
578
+ relationshipType: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/endnotes',
579
+ },
580
+ {
581
+ label: 'comment',
582
+ partPath: 'word/comments.xml',
583
+ referenceTag: 'w:commentReference',
584
+ entryTag: 'w:comment',
585
+ rootTag: 'w:comments',
586
+ contentType: 'application/vnd.openxmlformats-officedocument.wordprocessingml.comments+xml',
587
+ relationshipType: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments',
588
+ },
589
+ ];
590
+ /**
591
+ * Collect reference IDs from document.xml using DOM parsing.
592
+ */
593
+ function collectReferenceIds(documentXml, referenceTag) {
594
+ const ids = new Set();
595
+ const doc = new DOMParser().parseFromString(documentXml, 'application/xml');
596
+ const refs = doc.getElementsByTagName(referenceTag);
597
+ for (let i = 0; i < refs.length; i++) {
598
+ const id = refs[i].getAttribute('w:id');
599
+ if (id)
600
+ ids.add(id);
601
+ }
602
+ return ids;
603
+ }
604
+ /**
605
+ * Parse an auxiliary part and extract entry elements by ID.
606
+ */
607
+ function parseEntries(xml, entryTag) {
608
+ const doc = new DOMParser().parseFromString(xml, 'application/xml');
609
+ const entries = new Map();
610
+ const elements = doc.getElementsByTagName(entryTag);
611
+ for (let i = 0; i < elements.length; i++) {
612
+ const el = elements[i];
613
+ const id = el.getAttribute('w:id');
614
+ if (id)
615
+ entries.set(id, el);
616
+ }
617
+ return { doc, entries };
618
+ }
619
+ const serializer = new XMLSerializer();
620
+ /**
621
+ * Merge auxiliary part definitions (footnotes, endnotes, comments) from the
622
+ * original archive into the result archive. When inplace mode inserts deleted
623
+ * content, the corresponding definitions must exist in the auxiliary part.
624
+ */
625
+ async function mergeAuxiliaryPartDefinitions(originalArchive, resultArchive, documentXml, descriptor) {
626
+ const result = { mergedIds: new Set(), createdPart: false };
627
+ const referencedIds = collectReferenceIds(documentXml, descriptor.referenceTag);
628
+ if (referencedIds.size === 0)
629
+ return result;
630
+ const originalPartXml = await originalArchive.getFile(descriptor.partPath);
631
+ if (!originalPartXml)
632
+ return result;
633
+ const resultPartXml = await resultArchive.getFile(descriptor.partPath);
634
+ const originalParsed = parseEntries(originalPartXml, descriptor.entryTag);
635
+ const resultParsed = resultPartXml ? parseEntries(resultPartXml, descriptor.entryTag) : null;
636
+ // Find missing entries: referenced in document.xml but not in result
637
+ const missingElements = [];
638
+ for (const id of referencedIds) {
639
+ if (!(resultParsed?.entries.has(id)) && originalParsed.entries.has(id)) {
640
+ missingElements.push(originalParsed.entries.get(id));
641
+ result.mergedIds.add(id);
642
+ }
643
+ }
644
+ if (missingElements.length === 0)
645
+ return result;
646
+ if (resultPartXml && resultParsed) {
647
+ // Insert missing entries into existing result part
648
+ const rootEl = resultParsed.doc.getElementsByTagName(descriptor.rootTag)[0];
649
+ if (rootEl) {
650
+ for (const el of missingElements) {
651
+ const imported = resultParsed.doc.importNode(el, true);
652
+ rootEl.appendChild(imported);
653
+ }
654
+ resultArchive.setFile(descriptor.partPath, serializer.serializeToString(resultParsed.doc));
655
+ }
656
+ }
657
+ else {
658
+ // Create part from scratch: clone root from original, insert missing entries
659
+ const newDoc = new DOMParser().parseFromString(originalPartXml, 'application/xml');
660
+ const rootEl = newDoc.getElementsByTagName(descriptor.rootTag)[0];
661
+ if (rootEl) {
662
+ // Remove all existing entries — we only want the missing ones
663
+ const existingEntries = rootEl.getElementsByTagName(descriptor.entryTag);
664
+ const toRemove = [];
665
+ for (let i = 0; i < existingEntries.length; i++) {
666
+ toRemove.push(existingEntries[i]);
667
+ }
668
+ for (const el of toRemove) {
669
+ rootEl.removeChild(el);
670
+ }
671
+ // Add back only the missing entries
672
+ for (const el of missingElements) {
673
+ const imported = newDoc.importNode(el, true);
674
+ rootEl.appendChild(imported);
675
+ }
676
+ resultArchive.setFile(descriptor.partPath, serializer.serializeToString(newDoc));
677
+ result.createdPart = true;
678
+ // Bootstrap OPC metadata for the newly created part
679
+ await ensureOpcMetadata(resultArchive, descriptor);
680
+ }
681
+ }
682
+ return result;
683
+ }
684
+ // =============================================================================
685
+ // OPC Metadata Bootstrapping
686
+ // =============================================================================
687
+ const CT_NS = 'http://schemas.openxmlformats.org/package/2006/content-types';
688
+ const REL_NS = 'http://schemas.openxmlformats.org/package/2006/relationships';
689
+ /**
690
+ * Ensure [Content_Types].xml and document.xml.rels have entries for a
691
+ * newly-created auxiliary part.
692
+ */
693
+ async function ensureOpcMetadata(archive, descriptor) {
694
+ // 1. Update [Content_Types].xml
695
+ const ctXml = await archive.getFile('[Content_Types].xml');
696
+ if (ctXml) {
697
+ const ctDoc = new DOMParser().parseFromString(ctXml, 'application/xml');
698
+ const typesEl = ctDoc.documentElement;
699
+ const overrides = typesEl.getElementsByTagNameNS(CT_NS, 'Override');
700
+ const partName = `/${descriptor.partPath}`;
701
+ let found = false;
702
+ for (let i = 0; i < overrides.length; i++) {
703
+ if (overrides[i].getAttribute('PartName') === partName) {
704
+ found = true;
705
+ break;
706
+ }
707
+ }
708
+ if (!found) {
709
+ const override = ctDoc.createElementNS(CT_NS, 'Override');
710
+ override.setAttribute('PartName', partName);
711
+ override.setAttribute('ContentType', descriptor.contentType);
712
+ typesEl.appendChild(override);
713
+ archive.setFile('[Content_Types].xml', serializer.serializeToString(ctDoc));
714
+ }
715
+ }
716
+ // 2. Update word/_rels/document.xml.rels
717
+ const relsPath = 'word/_rels/document.xml.rels';
718
+ const relsXml = await archive.getFile(relsPath);
719
+ if (relsXml) {
720
+ const relsDoc = new DOMParser().parseFromString(relsXml, 'application/xml');
721
+ const relsEl = relsDoc.documentElement;
722
+ const existingRels = relsEl.getElementsByTagNameNS(REL_NS, 'Relationship');
723
+ let found = false;
724
+ let maxId = 0;
725
+ for (let i = 0; i < existingRels.length; i++) {
726
+ const rel = existingRels[i];
727
+ if (rel.getAttribute('Type') === descriptor.relationshipType) {
728
+ found = true;
729
+ }
730
+ const id = rel.getAttribute('Id') ?? '';
731
+ const idMatch = /^rId(\d+)$/.exec(id);
732
+ if (idMatch)
733
+ maxId = Math.max(maxId, parseInt(idMatch[1], 10));
734
+ }
735
+ if (!found) {
736
+ maxId++;
737
+ const rel = relsDoc.createElementNS(REL_NS, 'Relationship');
738
+ rel.setAttribute('Id', `rId${maxId}`);
739
+ rel.setAttribute('Type', descriptor.relationshipType);
740
+ rel.setAttribute('Target', descriptor.partPath.replace('word/', ''));
741
+ relsEl.appendChild(rel);
742
+ archive.setFile(relsPath, serializer.serializeToString(relsDoc));
743
+ }
744
+ }
745
+ }
746
+ // =============================================================================
747
+ // Comment Ancillary Parts Merging
748
+ // =============================================================================
749
+ /**
750
+ * After merging comment definitions, copy related entries from
751
+ * commentsExtended.xml and people.xml for author fidelity and reply threading.
752
+ */
753
+ async function mergeCommentAncillaryParts(originalArchive, resultArchive, commentMergeResult) {
754
+ // Collect authors and paraIds from the merged comment entries
755
+ const originalCommentsXml = await originalArchive.getFile('word/comments.xml');
756
+ if (!originalCommentsXml)
757
+ return;
758
+ const origDoc = new DOMParser().parseFromString(originalCommentsXml, 'application/xml');
759
+ const mergedAuthors = new Set();
760
+ const mergedParaIds = new Set();
761
+ const commentEls = origDoc.getElementsByTagName('w:comment');
762
+ for (let i = 0; i < commentEls.length; i++) {
763
+ const el = commentEls[i];
764
+ const id = el.getAttribute('w:id');
765
+ if (!id || !commentMergeResult.mergedIds.has(id))
766
+ continue;
767
+ const author = el.getAttribute('w:author');
768
+ if (author)
769
+ mergedAuthors.add(author);
770
+ // Collect paraIds from <w:p> children inside the comment
771
+ const paras = el.getElementsByTagName('w:p');
772
+ for (let j = 0; j < paras.length; j++) {
773
+ const p = paras[j];
774
+ const paraId = p.getAttribute('w14:paraId');
775
+ if (paraId)
776
+ mergedParaIds.add(paraId);
777
+ }
778
+ }
779
+ // Merge commentsExtended.xml entries matching merged paraIds
780
+ await mergeCommentsExtended(originalArchive, resultArchive, mergedParaIds);
781
+ // Merge people.xml entries matching merged authors
782
+ await mergePeople(originalArchive, resultArchive, mergedAuthors);
783
+ }
784
+ async function mergeCommentsExtended(originalArchive, resultArchive, mergedParaIds) {
785
+ if (mergedParaIds.size === 0)
786
+ return;
787
+ const originalXml = await originalArchive.getFile('word/commentsExtended.xml');
788
+ if (!originalXml)
789
+ return;
790
+ const origDoc = new DOMParser().parseFromString(originalXml, 'application/xml');
791
+ const origEntries = origDoc.getElementsByTagName('w15:commentEx');
792
+ // Collect entries whose paraId matches a merged comment's paragraph
793
+ const entriesToMerge = [];
794
+ for (let i = 0; i < origEntries.length; i++) {
795
+ const el = origEntries[i];
796
+ const paraId = el.getAttribute('w15:paraId');
797
+ if (paraId && mergedParaIds.has(paraId)) {
798
+ entriesToMerge.push(el);
799
+ }
800
+ }
801
+ if (entriesToMerge.length === 0)
802
+ return;
803
+ let resultXml = await resultArchive.getFile('word/commentsExtended.xml');
804
+ if (resultXml) {
805
+ const resultDoc = new DOMParser().parseFromString(resultXml, 'application/xml');
806
+ const rootEl = resultDoc.documentElement;
807
+ // Check existing paraIds to avoid duplicates
808
+ const existingParaIds = new Set();
809
+ const existing = rootEl.getElementsByTagName('w15:commentEx');
810
+ for (let i = 0; i < existing.length; i++) {
811
+ const pid = existing[i].getAttribute('w15:paraId');
812
+ if (pid)
813
+ existingParaIds.add(pid);
814
+ }
815
+ for (const el of entriesToMerge) {
816
+ const pid = el.getAttribute('w15:paraId');
817
+ if (pid && !existingParaIds.has(pid)) {
818
+ rootEl.appendChild(resultDoc.importNode(el, true));
819
+ }
820
+ }
821
+ resultArchive.setFile('word/commentsExtended.xml', serializer.serializeToString(resultDoc));
822
+ }
823
+ // If commentsExtended.xml doesn't exist in result, we don't create it —
824
+ // the file is optional and its absence won't cause crashes.
825
+ }
826
+ async function mergePeople(originalArchive, resultArchive, mergedAuthors) {
827
+ if (mergedAuthors.size === 0)
828
+ return;
829
+ const originalXml = await originalArchive.getFile('word/people.xml');
830
+ if (!originalXml)
831
+ return;
832
+ const origDoc = new DOMParser().parseFromString(originalXml, 'application/xml');
833
+ const origPersons = origDoc.getElementsByTagName('w15:person');
834
+ const personsToMerge = [];
835
+ for (let i = 0; i < origPersons.length; i++) {
836
+ const el = origPersons[i];
837
+ const author = el.getAttribute('w15:author');
838
+ if (author && mergedAuthors.has(author)) {
839
+ personsToMerge.push(el);
840
+ }
841
+ }
842
+ if (personsToMerge.length === 0)
843
+ return;
844
+ let resultXml = await resultArchive.getFile('word/people.xml');
845
+ if (resultXml) {
846
+ const resultDoc = new DOMParser().parseFromString(resultXml, 'application/xml');
847
+ const rootEl = resultDoc.documentElement;
848
+ // Check existing authors to avoid duplicates
849
+ const existingAuthors = new Set();
850
+ const existing = rootEl.getElementsByTagName('w15:person');
851
+ for (let i = 0; i < existing.length; i++) {
852
+ const a = existing[i].getAttribute('w15:author');
853
+ if (a)
854
+ existingAuthors.add(a);
855
+ }
856
+ for (const el of personsToMerge) {
857
+ const a = el.getAttribute('w15:author');
858
+ if (a && !existingAuthors.has(a)) {
859
+ rootEl.appendChild(resultDoc.importNode(el, true));
860
+ }
861
+ }
862
+ resultArchive.setFile('word/people.xml', serializer.serializeToString(resultDoc));
863
+ }
864
+ // If people.xml doesn't exist in result, we don't create it —
865
+ // the file is optional and its absence won't cause crashes.
866
+ }
867
+ /**
868
+ * Compute comparison statistics from merged atoms.
869
+ */
870
+ function computeStats(mergedAtoms) {
871
+ const reconstructionStats = computeReconstructionStats(mergedAtoms);
872
+ // Count unique paragraphs for modifications
873
+ // A modification is when we have both deleted and inserted atoms in the same paragraph
874
+ const modifiedParagraphs = new Set();
875
+ let currentParagraph = '';
876
+ let hasDeleted = false;
877
+ let hasInserted = false;
878
+ for (const atom of mergedAtoms) {
879
+ // Detect paragraph boundaries
880
+ const pAncestor = atom.ancestorElements.find((a) => a.tagName === 'w:p');
881
+ const paragraphId = pAncestor
882
+ ? `${atom.part.uri}:${atom.ancestorElements.indexOf(pAncestor)}`
883
+ : '';
884
+ if (paragraphId !== currentParagraph) {
885
+ // Check previous paragraph
886
+ if (currentParagraph && hasDeleted && hasInserted) {
887
+ modifiedParagraphs.add(currentParagraph);
888
+ }
889
+ currentParagraph = paragraphId;
890
+ hasDeleted = false;
891
+ hasInserted = false;
892
+ }
893
+ if (atom.correlationStatus === CorrelationStatus.Deleted) {
894
+ hasDeleted = true;
895
+ }
896
+ else if (atom.correlationStatus === CorrelationStatus.Inserted) {
897
+ hasInserted = true;
898
+ }
899
+ }
900
+ // Check last paragraph
901
+ if (currentParagraph && hasDeleted && hasInserted) {
902
+ modifiedParagraphs.add(currentParagraph);
903
+ }
904
+ return {
905
+ insertions: reconstructionStats.insertions,
906
+ deletions: reconstructionStats.deletions,
907
+ modifications: modifiedParagraphs.size + reconstructionStats.formatChanges,
908
+ };
909
+ }
910
+ //# sourceMappingURL=pipeline.js.map