@beyondwork/docx-react-component 1.0.27 → 1.0.29

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 (356) hide show
  1. package/dist/canonical-document-BLEbzL2J.d.cts +844 -0
  2. package/dist/canonical-document-BLEbzL2J.d.ts +844 -0
  3. package/dist/chunk-2FJS5GZM.js +763 -0
  4. package/dist/chunk-2FJS5GZM.js.map +1 -0
  5. package/{src/core/commands/section-layout-commands.ts → dist/chunk-2OQBZS3F.js} +106 -340
  6. package/dist/chunk-2OQBZS3F.js.map +1 -0
  7. package/dist/chunk-2S7W4KFO.js +127 -0
  8. package/dist/chunk-2S7W4KFO.js.map +1 -0
  9. package/dist/chunk-2TG72QSW.js +3874 -0
  10. package/dist/chunk-2TG72QSW.js.map +1 -0
  11. package/{src/core/commands/table-structure-commands.ts → dist/chunk-36QNIZBO.js} +126 -315
  12. package/dist/chunk-36QNIZBO.js.map +1 -0
  13. package/dist/chunk-4AQOYAW4.js +3069 -0
  14. package/dist/chunk-4AQOYAW4.js.map +1 -0
  15. package/dist/chunk-4D5EWJ3P.js +77 -0
  16. package/dist/chunk-4D5EWJ3P.js.map +1 -0
  17. package/dist/chunk-5FN54NDH.js +2257 -0
  18. package/dist/chunk-5FN54NDH.js.map +1 -0
  19. package/dist/chunk-BOYGQYRQ.js +7306 -0
  20. package/dist/chunk-BOYGQYRQ.js.map +1 -0
  21. package/dist/chunk-CN3XMECL.js +212 -0
  22. package/dist/chunk-CN3XMECL.js.map +1 -0
  23. package/dist/chunk-EBI3BX6U.js +164 -0
  24. package/dist/chunk-EBI3BX6U.js.map +1 -0
  25. package/dist/chunk-EILUG3VB.js +1275 -0
  26. package/dist/chunk-EILUG3VB.js.map +1 -0
  27. package/dist/chunk-FUDY333O.js +70 -0
  28. package/dist/chunk-FUDY333O.js.map +1 -0
  29. package/dist/chunk-GBVOWFIK.js +1237 -0
  30. package/dist/chunk-GBVOWFIK.js.map +1 -0
  31. package/dist/chunk-H4TQ3H3Y.js +262 -0
  32. package/dist/chunk-H4TQ3H3Y.js.map +1 -0
  33. package/{src/core/commands/style-commands.ts → dist/chunk-JGB3IXZO.js} +40 -113
  34. package/dist/chunk-JGB3IXZO.js.map +1 -0
  35. package/dist/chunk-KD2QRQPY.js +4342 -0
  36. package/dist/chunk-KD2QRQPY.js.map +1 -0
  37. package/dist/chunk-KLMXQVYK.js +369 -0
  38. package/dist/chunk-KLMXQVYK.js.map +1 -0
  39. package/dist/chunk-KZUG5KFQ.js +214 -0
  40. package/dist/chunk-KZUG5KFQ.js.map +1 -0
  41. package/{src/core/state/text-transaction.ts → dist/chunk-QDAQ4CJU.js} +79 -236
  42. package/dist/chunk-QDAQ4CJU.js.map +1 -0
  43. package/{src/legal/bookmarks.ts → dist/chunk-RMH72RZI.js} +44 -130
  44. package/dist/chunk-RMH72RZI.js.map +1 -0
  45. package/dist/chunk-SWKWQZXM.js +117 -0
  46. package/dist/chunk-SWKWQZXM.js.map +1 -0
  47. package/{src/core/commands/formatting-commands.ts → dist/chunk-TJBP2K4T.js} +196 -536
  48. package/dist/chunk-TJBP2K4T.js.map +1 -0
  49. package/dist/chunk-TLCEAQDQ.js +542 -0
  50. package/dist/chunk-TLCEAQDQ.js.map +1 -0
  51. package/{src/core/commands/text-commands.ts → dist/chunk-UZXBISGO.js} +86 -142
  52. package/dist/chunk-UZXBISGO.js.map +1 -0
  53. package/dist/chunk-WGBAKP3Q.js +3220 -0
  54. package/dist/chunk-WGBAKP3Q.js.map +1 -0
  55. package/dist/compare/index.cjs +5475 -0
  56. package/dist/compare/index.cjs.map +1 -0
  57. package/dist/compare/index.d.cts +114 -0
  58. package/dist/compare/index.d.ts +114 -0
  59. package/dist/compare/index.js +731 -0
  60. package/dist/compare/index.js.map +1 -0
  61. package/dist/core/commands/formatting-commands.cjs +828 -0
  62. package/dist/core/commands/formatting-commands.cjs.map +1 -0
  63. package/dist/core/commands/formatting-commands.d.cts +63 -0
  64. package/dist/core/commands/formatting-commands.d.ts +63 -0
  65. package/dist/core/commands/formatting-commands.js +37 -0
  66. package/dist/core/commands/formatting-commands.js.map +1 -0
  67. package/dist/core/commands/image-commands.cjs +2023 -0
  68. package/dist/core/commands/image-commands.cjs.map +1 -0
  69. package/dist/core/commands/image-commands.d.cts +58 -0
  70. package/dist/core/commands/image-commands.d.ts +58 -0
  71. package/dist/core/commands/image-commands.js +18 -0
  72. package/dist/core/commands/image-commands.js.map +1 -0
  73. package/dist/core/commands/section-layout-commands.cjs +477 -0
  74. package/dist/core/commands/section-layout-commands.cjs.map +1 -0
  75. package/dist/core/commands/section-layout-commands.d.cts +62 -0
  76. package/dist/core/commands/section-layout-commands.d.ts +62 -0
  77. package/dist/core/commands/section-layout-commands.js +21 -0
  78. package/dist/core/commands/section-layout-commands.js.map +1 -0
  79. package/dist/core/commands/style-commands.cjs +214 -0
  80. package/dist/core/commands/style-commands.cjs.map +1 -0
  81. package/dist/core/commands/style-commands.d.cts +13 -0
  82. package/dist/core/commands/style-commands.d.ts +13 -0
  83. package/dist/core/commands/style-commands.js +9 -0
  84. package/dist/core/commands/style-commands.js.map +1 -0
  85. package/dist/core/commands/table-structure-commands.cjs +1883 -0
  86. package/dist/core/commands/table-structure-commands.cjs.map +1 -0
  87. package/dist/core/commands/table-structure-commands.d.cts +59 -0
  88. package/dist/core/commands/table-structure-commands.d.ts +59 -0
  89. package/dist/core/commands/table-structure-commands.js +12 -0
  90. package/dist/core/commands/table-structure-commands.js.map +1 -0
  91. package/dist/core/commands/text-commands.cjs +2391 -0
  92. package/dist/core/commands/text-commands.cjs.map +1 -0
  93. package/dist/core/commands/text-commands.d.cts +24 -0
  94. package/dist/core/commands/text-commands.d.ts +24 -0
  95. package/dist/core/commands/text-commands.js +28 -0
  96. package/dist/core/commands/text-commands.js.map +1 -0
  97. package/dist/core/selection/mapping.cjs +200 -0
  98. package/dist/core/selection/mapping.cjs.map +1 -0
  99. package/dist/core/selection/mapping.d.cts +2 -0
  100. package/dist/core/selection/mapping.d.ts +2 -0
  101. package/dist/core/selection/mapping.js +31 -0
  102. package/dist/core/selection/mapping.js.map +1 -0
  103. package/dist/core/state/editor-state.cjs +2278 -0
  104. package/dist/core/state/editor-state.cjs.map +1 -0
  105. package/dist/core/state/editor-state.d.cts +2 -0
  106. package/dist/core/state/editor-state.d.ts +2 -0
  107. package/dist/core/state/editor-state.js +26 -0
  108. package/dist/core/state/editor-state.js.map +1 -0
  109. package/dist/index.cjs +38553 -0
  110. package/dist/index.cjs.map +1 -0
  111. package/dist/index.d.cts +15 -0
  112. package/dist/index.d.ts +15 -0
  113. package/dist/index.js +7856 -0
  114. package/dist/index.js.map +1 -0
  115. package/dist/io/docx-session.cjs +16236 -0
  116. package/dist/io/docx-session.cjs.map +1 -0
  117. package/dist/io/docx-session.d.cts +21 -0
  118. package/dist/io/docx-session.d.ts +21 -0
  119. package/dist/io/docx-session.js +18 -0
  120. package/dist/io/docx-session.js.map +1 -0
  121. package/dist/legal/index.cjs +3900 -0
  122. package/dist/legal/index.cjs.map +1 -0
  123. package/dist/legal/index.d.cts +86 -0
  124. package/dist/legal/index.d.ts +86 -0
  125. package/dist/legal/index.js +616 -0
  126. package/dist/legal/index.js.map +1 -0
  127. package/dist/public-types-7ZL_94cz.d.ts +1573 -0
  128. package/dist/public-types-CeMaDueh.d.cts +1573 -0
  129. package/dist/public-types.cjs +19 -0
  130. package/dist/public-types.cjs.map +1 -0
  131. package/dist/public-types.d.cts +2 -0
  132. package/dist/public-types.d.ts +2 -0
  133. package/dist/public-types.js +1 -0
  134. package/dist/public-types.js.map +1 -0
  135. package/dist/runtime/document-runtime.cjs +11140 -0
  136. package/dist/runtime/document-runtime.cjs.map +1 -0
  137. package/dist/runtime/document-runtime.d.cts +231 -0
  138. package/dist/runtime/document-runtime.d.ts +231 -0
  139. package/dist/runtime/document-runtime.js +21 -0
  140. package/dist/runtime/document-runtime.js.map +1 -0
  141. package/dist/structural-helpers-CilgOVhh.d.cts +10 -0
  142. package/dist/structural-helpers-q0Gd-eBN.d.ts +10 -0
  143. package/dist/ui-tailwind/editor-surface/search-plugin.cjs +313 -0
  144. package/dist/ui-tailwind/editor-surface/search-plugin.cjs.map +1 -0
  145. package/dist/ui-tailwind/editor-surface/search-plugin.d.cts +67 -0
  146. package/dist/ui-tailwind/editor-surface/search-plugin.d.ts +67 -0
  147. package/dist/ui-tailwind/editor-surface/search-plugin.js +23 -0
  148. package/dist/ui-tailwind/editor-surface/search-plugin.js.map +1 -0
  149. package/dist/ui-tailwind/index.cjs +4833 -0
  150. package/dist/ui-tailwind/index.cjs.map +1 -0
  151. package/dist/ui-tailwind/index.d.cts +617 -0
  152. package/dist/ui-tailwind/index.d.ts +617 -0
  153. package/dist/ui-tailwind/index.js +575 -0
  154. package/dist/ui-tailwind/index.js.map +1 -0
  155. package/package.json +64 -54
  156. package/src/README.md +0 -85
  157. package/src/api/README.md +0 -26
  158. package/src/api/public-types.ts +0 -1418
  159. package/src/api/session-state.ts +0 -60
  160. package/src/compare/diff-engine.ts +0 -623
  161. package/src/compare/export-redlines.ts +0 -280
  162. package/src/compare/index.ts +0 -25
  163. package/src/compare/snapshot.ts +0 -97
  164. package/src/component-inventory.md +0 -99
  165. package/src/core/README.md +0 -10
  166. package/src/core/commands/README.md +0 -3
  167. package/src/core/commands/image-commands.ts +0 -373
  168. package/src/core/commands/index.ts +0 -1757
  169. package/src/core/commands/list-commands.ts +0 -565
  170. package/src/core/commands/paragraph-layout-commands.ts +0 -339
  171. package/src/core/commands/review-commands.ts +0 -108
  172. package/src/core/commands/structural-helpers.ts +0 -309
  173. package/src/core/schema/README.md +0 -3
  174. package/src/core/schema/text-schema.ts +0 -516
  175. package/src/core/search/search-text.ts +0 -357
  176. package/src/core/selection/README.md +0 -3
  177. package/src/core/selection/mapping.ts +0 -289
  178. package/src/core/selection/review-anchors.ts +0 -183
  179. package/src/core/state/README.md +0 -3
  180. package/src/core/state/editor-state.ts +0 -892
  181. package/src/formats/xlsx/io/parse-shared-strings.ts +0 -41
  182. package/src/formats/xlsx/io/parse-sheet.ts +0 -459
  183. package/src/formats/xlsx/io/parse-styles.ts +0 -59
  184. package/src/formats/xlsx/io/parse-workbook.ts +0 -75
  185. package/src/formats/xlsx/io/serialize-shared-strings.ts +0 -72
  186. package/src/formats/xlsx/io/serialize-sheet.ts +0 -333
  187. package/src/formats/xlsx/io/serialize-styles.ts +0 -98
  188. package/src/formats/xlsx/io/serialize-workbook.ts +0 -429
  189. package/src/formats/xlsx/io/xlsx-session.ts +0 -314
  190. package/src/formats/xlsx/model/cell.ts +0 -189
  191. package/src/formats/xlsx/model/sheet.ts +0 -326
  192. package/src/formats/xlsx/model/styles.ts +0 -118
  193. package/src/formats/xlsx/model/workbook.ts +0 -453
  194. package/src/formats/xlsx/runtime/cell-commands.ts +0 -567
  195. package/src/formats/xlsx/runtime/sheet-commands.ts +0 -206
  196. package/src/formats/xlsx/runtime/workbook-runtime.ts +0 -177
  197. package/src/formats/xlsx/runtime/workbook-transaction.ts +0 -822
  198. package/src/index.ts +0 -101
  199. package/src/io/README.md +0 -10
  200. package/src/io/docx-session.ts +0 -2882
  201. package/src/io/export/README.md +0 -3
  202. package/src/io/export/export-session.ts +0 -220
  203. package/src/io/export/minimal-docx.ts +0 -115
  204. package/src/io/export/reattach-preserved-parts.ts +0 -54
  205. package/src/io/export/serialize-comments.ts +0 -947
  206. package/src/io/export/serialize-footnotes.ts +0 -399
  207. package/src/io/export/serialize-headers-footers.ts +0 -372
  208. package/src/io/export/serialize-main-document.ts +0 -1376
  209. package/src/io/export/serialize-numbering.ts +0 -118
  210. package/src/io/export/serialize-revisions.ts +0 -389
  211. package/src/io/export/serialize-runtime-revisions.ts +0 -269
  212. package/src/io/export/serialize-tables.ts +0 -174
  213. package/src/io/export/split-review-boundaries.ts +0 -356
  214. package/src/io/normalize/README.md +0 -3
  215. package/src/io/normalize/normalize-text.ts +0 -639
  216. package/src/io/ooxml/README.md +0 -3
  217. package/src/io/ooxml/highlight-colors.ts +0 -39
  218. package/src/io/ooxml/numbering-sentinels.ts +0 -44
  219. package/src/io/ooxml/parse-comments.ts +0 -846
  220. package/src/io/ooxml/parse-complex-content.ts +0 -287
  221. package/src/io/ooxml/parse-fields.ts +0 -834
  222. package/src/io/ooxml/parse-footnotes.ts +0 -896
  223. package/src/io/ooxml/parse-headers-footers.ts +0 -1169
  224. package/src/io/ooxml/parse-inline-media.ts +0 -461
  225. package/src/io/ooxml/parse-main-document.ts +0 -2877
  226. package/src/io/ooxml/parse-numbering.ts +0 -432
  227. package/src/io/ooxml/parse-revisions.ts +0 -931
  228. package/src/io/ooxml/parse-settings.ts +0 -184
  229. package/src/io/ooxml/parse-shapes.ts +0 -296
  230. package/src/io/ooxml/parse-styles.ts +0 -463
  231. package/src/io/ooxml/parse-tables.ts +0 -618
  232. package/src/io/ooxml/parse-theme.ts +0 -346
  233. package/src/io/ooxml/part-manifest.ts +0 -136
  234. package/src/io/ooxml/revision-boundaries.ts +0 -351
  235. package/src/io/opc/README.md +0 -3
  236. package/src/io/opc/corrupt-package.ts +0 -166
  237. package/src/io/opc/docx-package.ts +0 -74
  238. package/src/io/opc/package-reader.ts +0 -325
  239. package/src/io/opc/package-writer.ts +0 -273
  240. package/src/io/source-package-provenance.ts +0 -241
  241. package/src/legal/cross-references.ts +0 -414
  242. package/src/legal/defined-terms.ts +0 -203
  243. package/src/legal/index.ts +0 -32
  244. package/src/legal/signature-blocks.ts +0 -259
  245. package/src/model/README.md +0 -3
  246. package/src/model/canonical-document.ts +0 -2632
  247. package/src/model/cds-1.0.0.ts +0 -212
  248. package/src/model/snapshot.ts +0 -649
  249. package/src/preservation/README.md +0 -3
  250. package/src/preservation/markup-compatibility.ts +0 -48
  251. package/src/preservation/opaque-fragment-store.ts +0 -89
  252. package/src/preservation/opaque-region.ts +0 -233
  253. package/src/preservation/package-preservation.ts +0 -113
  254. package/src/preservation/preserved-part-manifest.ts +0 -56
  255. package/src/preservation/relationship-retention.ts +0 -57
  256. package/src/preservation/store.ts +0 -185
  257. package/src/review/README.md +0 -16
  258. package/src/review/store/README.md +0 -3
  259. package/src/review/store/comment-anchors.ts +0 -70
  260. package/src/review/store/comment-remapping.ts +0 -154
  261. package/src/review/store/comment-store.ts +0 -331
  262. package/src/review/store/comment-thread.ts +0 -109
  263. package/src/review/store/revision-actions.ts +0 -394
  264. package/src/review/store/revision-store.ts +0 -312
  265. package/src/review/store/revision-types.ts +0 -171
  266. package/src/review/store/runtime-comment-store.ts +0 -43
  267. package/src/runtime/README.md +0 -3
  268. package/src/runtime/ai-action-policy.ts +0 -764
  269. package/src/runtime/collab-review-sync.ts +0 -254
  270. package/src/runtime/document-layout.ts +0 -332
  271. package/src/runtime/document-navigation.ts +0 -603
  272. package/src/runtime/document-runtime.ts +0 -3159
  273. package/src/runtime/document-search.ts +0 -145
  274. package/src/runtime/numbering-prefix.ts +0 -216
  275. package/src/runtime/page-layout-estimation.ts +0 -212
  276. package/src/runtime/read-only-diagnostics-runtime.ts +0 -241
  277. package/src/runtime/review-runtime.ts +0 -44
  278. package/src/runtime/revision-runtime.ts +0 -107
  279. package/src/runtime/session-capabilities.ts +0 -192
  280. package/src/runtime/story-context.ts +0 -164
  281. package/src/runtime/story-targeting.ts +0 -162
  282. package/src/runtime/surface-projection.ts +0 -1357
  283. package/src/runtime/table-commands.ts +0 -173
  284. package/src/runtime/table-schema.ts +0 -309
  285. package/src/runtime/view-state.ts +0 -477
  286. package/src/runtime/virtualized-rendering.ts +0 -258
  287. package/src/runtime/workflow-markup.ts +0 -353
  288. package/src/ui/README.md +0 -30
  289. package/src/ui/WordReviewEditor.tsx +0 -4097
  290. package/src/ui/browser-export.ts +0 -52
  291. package/src/ui/comments/README.md +0 -3
  292. package/src/ui/compatibility/README.md +0 -3
  293. package/src/ui/editor-command-bag.ts +0 -120
  294. package/src/ui/editor-runtime-boundary.ts +0 -1457
  295. package/src/ui/editor-shell-view.tsx +0 -142
  296. package/src/ui/editor-surface/README.md +0 -3
  297. package/src/ui/editor-surface-controller.tsx +0 -63
  298. package/src/ui/headless/comment-decoration-model.ts +0 -124
  299. package/src/ui/headless/preserve-editor-selection.ts +0 -5
  300. package/src/ui/headless/revision-decoration-model.ts +0 -128
  301. package/src/ui/headless/selection-helpers.ts +0 -54
  302. package/src/ui/headless/selection-toolbar-model.ts +0 -34
  303. package/src/ui/headless/use-editor-keyboard.ts +0 -103
  304. package/src/ui/review/README.md +0 -3
  305. package/src/ui/runtime-snapshot-selectors.ts +0 -197
  306. package/src/ui/shared/revision-filters.ts +0 -31
  307. package/src/ui/status/README.md +0 -3
  308. package/src/ui/theme/README.md +0 -3
  309. package/src/ui/toolbar/README.md +0 -3
  310. package/src/ui/workflow-surface-blocked-rails.ts +0 -94
  311. package/src/ui-tailwind/chrome/tw-alert-banner.tsx +0 -64
  312. package/src/ui-tailwind/chrome/tw-image-context-toolbar.tsx +0 -129
  313. package/src/ui-tailwind/chrome/tw-layout-panel.tsx +0 -114
  314. package/src/ui-tailwind/chrome/tw-object-context-toolbar.tsx +0 -34
  315. package/src/ui-tailwind/chrome/tw-page-ruler.tsx +0 -386
  316. package/src/ui-tailwind/chrome/tw-selection-toolbar.tsx +0 -186
  317. package/src/ui-tailwind/chrome/tw-suggestion-card.tsx +0 -139
  318. package/src/ui-tailwind/chrome/tw-table-context-toolbar.tsx +0 -128
  319. package/src/ui-tailwind/chrome/tw-unsaved-modal.tsx +0 -58
  320. package/src/ui-tailwind/chrome/use-before-unload.ts +0 -20
  321. package/src/ui-tailwind/editor-surface/perf-probe.ts +0 -179
  322. package/src/ui-tailwind/editor-surface/pm-collab-plugins.ts +0 -40
  323. package/src/ui-tailwind/editor-surface/pm-command-bridge.ts +0 -178
  324. package/src/ui-tailwind/editor-surface/pm-contextual-ui.ts +0 -31
  325. package/src/ui-tailwind/editor-surface/pm-decorations.ts +0 -427
  326. package/src/ui-tailwind/editor-surface/pm-position-map.ts +0 -123
  327. package/src/ui-tailwind/editor-surface/pm-schema.ts +0 -876
  328. package/src/ui-tailwind/editor-surface/pm-state-from-snapshot.ts +0 -504
  329. package/src/ui-tailwind/editor-surface/search-plugin.ts +0 -168
  330. package/src/ui-tailwind/editor-surface/surface-build-keys.ts +0 -61
  331. package/src/ui-tailwind/editor-surface/tw-caret.tsx +0 -12
  332. package/src/ui-tailwind/editor-surface/tw-editor-surface.tsx +0 -150
  333. package/src/ui-tailwind/editor-surface/tw-inline-token.tsx +0 -129
  334. package/src/ui-tailwind/editor-surface/tw-opaque-block.tsx +0 -58
  335. package/src/ui-tailwind/editor-surface/tw-paragraph-block.tsx +0 -151
  336. package/src/ui-tailwind/editor-surface/tw-prosemirror-surface.tsx +0 -973
  337. package/src/ui-tailwind/editor-surface/tw-segment-view.tsx +0 -111
  338. package/src/ui-tailwind/editor-surface/tw-table-node-view.tsx +0 -436
  339. package/src/ui-tailwind/index.ts +0 -62
  340. package/src/ui-tailwind/page-chrome-model.ts +0 -27
  341. package/src/ui-tailwind/review/tw-comment-sidebar.tsx +0 -406
  342. package/src/ui-tailwind/review/tw-health-panel.tsx +0 -149
  343. package/src/ui-tailwind/review/tw-review-rail.tsx +0 -120
  344. package/src/ui-tailwind/review/tw-revision-sidebar.tsx +0 -164
  345. package/src/ui-tailwind/status/tw-status-bar.tsx +0 -61
  346. package/src/ui-tailwind/toolbar/tw-toolbar-icon-button.tsx +0 -52
  347. package/src/ui-tailwind/toolbar/tw-toolbar.tsx +0 -1064
  348. package/src/ui-tailwind/tw-review-workspace.tsx +0 -1417
  349. package/src/validation/README.md +0 -3
  350. package/src/validation/compatibility-engine.ts +0 -634
  351. package/src/validation/compatibility-report.ts +0 -161
  352. package/src/validation/diagnostics.ts +0 -204
  353. package/src/validation/docx-comment-proof.ts +0 -707
  354. package/src/validation/import-diagnostics.ts +0 -128
  355. package/src/validation/low-priority-word-surfaces.ts +0 -373
  356. /package/{src → dist}/ui-tailwind/theme/editor-theme.css +0 -0
@@ -0,0 +1,2278 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/core/state/editor-state.ts
21
+ var editor_state_exports = {};
22
+ __export(editor_state_exports, {
23
+ createCanonicalDocumentId: () => createCanonicalDocumentId,
24
+ createDefaultCanonicalDocument: () => createDefaultCanonicalDocument,
25
+ createEditorState: () => createEditorState,
26
+ createEmptyCompatibilityReport: () => createEmptyCompatibilityReport,
27
+ createEmptyReviewStore: () => createEmptyReviewStore,
28
+ createPersistedEditorSnapshot: () => createPersistedEditorSnapshot2,
29
+ createSelectionSnapshot: () => createSelectionSnapshot,
30
+ deriveDocumentStats: () => deriveDocumentStats,
31
+ deriveRenderSnapshot: () => deriveRenderSnapshot,
32
+ normalizeCommentThreadRecord: () => normalizeCommentThreadRecord
33
+ });
34
+ module.exports = __toCommonJS(editor_state_exports);
35
+
36
+ // src/core/selection/mapping.ts
37
+ var DEFAULT_BOUNDARY_ASSOC = {
38
+ start: 1,
39
+ end: -1
40
+ };
41
+ function createRangeAnchor(from, to = from, assoc = DEFAULT_BOUNDARY_ASSOC) {
42
+ return {
43
+ kind: "range",
44
+ range: normalizeRange({ from, to }),
45
+ assoc
46
+ };
47
+ }
48
+ function createNodeAnchor(at, assoc = 1) {
49
+ return {
50
+ kind: "node",
51
+ at,
52
+ assoc
53
+ };
54
+ }
55
+ function createDetachedAnchor(lastKnownRange, reason) {
56
+ return {
57
+ kind: "detached",
58
+ lastKnownRange: normalizeRange(lastKnownRange),
59
+ reason
60
+ };
61
+ }
62
+ function normalizeRange(range) {
63
+ return range.from <= range.to ? { from: range.from, to: range.to } : { from: range.to, to: range.from };
64
+ }
65
+
66
+ // src/model/cds-1.0.0.ts
67
+ var CDS_SCHEMA_VERSION = "cds/1.0.0";
68
+ var LEGACY_PERSISTED_EDITOR_SNAPSHOT_VERSION = "persisted-editor-snapshot/1";
69
+ var PERSISTED_EDITOR_SNAPSHOT_VERSION = "persisted-editor-snapshot/2";
70
+ var COMPATIBILITY_REPORT_VERSION = "compatibility-report/1";
71
+ var ModelValidationError = class extends Error {
72
+ issues;
73
+ constructor(message, issues) {
74
+ super(message);
75
+ this.name = "ModelValidationError";
76
+ this.issues = issues;
77
+ }
78
+ };
79
+ var UUID_PATTERN = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
80
+ var ISO_8601_UTC_PATTERN = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{3})?Z$/;
81
+ function isPlainObject(value) {
82
+ if (value === null || typeof value !== "object" || Array.isArray(value)) {
83
+ return false;
84
+ }
85
+ const prototype = Object.getPrototypeOf(value);
86
+ return prototype === Object.prototype || prototype === null;
87
+ }
88
+ function isNonEmptyString(value) {
89
+ return typeof value === "string" && value.trim().length > 0;
90
+ }
91
+ function isUuid(value) {
92
+ return typeof value === "string" && UUID_PATTERN.test(value);
93
+ }
94
+ function isIso8601UtcTimestamp(value) {
95
+ return typeof value === "string" && ISO_8601_UTC_PATTERN.test(value) && !Number.isNaN(Date.parse(value));
96
+ }
97
+ function asPlainObject(value, path, issues) {
98
+ if (!isPlainObject(value)) {
99
+ issues.push({ path, message: "Expected a plain object." });
100
+ return null;
101
+ }
102
+ return value;
103
+ }
104
+ function expectString(value, path, issues) {
105
+ if (!isNonEmptyString(value)) {
106
+ issues.push({ path, message: "Expected a non-empty string." });
107
+ return null;
108
+ }
109
+ return value;
110
+ }
111
+ function expectStringAllowEmpty(value, path, issues) {
112
+ if (typeof value !== "string") {
113
+ issues.push({ path, message: "Expected a string." });
114
+ return null;
115
+ }
116
+ return value;
117
+ }
118
+ function expectExactString(value, expected, path, issues) {
119
+ if (value !== expected) {
120
+ issues.push({
121
+ path,
122
+ message: `Expected ${JSON.stringify(expected)}.`
123
+ });
124
+ return null;
125
+ }
126
+ return expected;
127
+ }
128
+ function expectIso8601UtcTimestamp(value, path, issues) {
129
+ if (!isIso8601UtcTimestamp(value)) {
130
+ issues.push({
131
+ path,
132
+ message: "Expected an ISO 8601 UTC timestamp string."
133
+ });
134
+ return null;
135
+ }
136
+ return value;
137
+ }
138
+ function expectUuid(value, path, issues) {
139
+ if (!isUuid(value)) {
140
+ issues.push({
141
+ path,
142
+ message: "Expected an RFC 4122 UUID string."
143
+ });
144
+ return null;
145
+ }
146
+ return value;
147
+ }
148
+ function assertValid(issues, message) {
149
+ if (issues.length > 0) {
150
+ throw new ModelValidationError(message, issues);
151
+ }
152
+ }
153
+
154
+ // src/model/canonical-document.ts
155
+ var CANONICAL_DOCUMENT_TOP_LEVEL_KEYS = [
156
+ "schemaVersion",
157
+ "docId",
158
+ "createdAt",
159
+ "updatedAt",
160
+ "metadata",
161
+ "styles",
162
+ "numbering",
163
+ "media",
164
+ "content",
165
+ "review",
166
+ "preservation",
167
+ "diagnostics"
168
+ ];
169
+ var CANONICAL_DOCUMENT_OPTIONAL_KEYS = ["subParts", "fieldRegistry"];
170
+ var ID_PATTERNS = {
171
+ styleId: /^[A-Za-z_][A-Za-z0-9._-]{0,127}$/,
172
+ abstractNumberingId: /^abstract-num:[A-Za-z0-9._-]{1,120}$/,
173
+ numberingInstanceId: /^num:[A-Za-z0-9._-]{1,120}$/,
174
+ mediaId: /^media:[A-Za-z0-9._/-]{1,120}$/,
175
+ commentId: /^(?:comment:[A-Za-z0-9._-]{1,120}|comment-[A-Za-z0-9._-]{1,120}|[0-9]{1,18})$/,
176
+ revisionId: /^(?:revision:[A-Za-z0-9._-]{1,120}|change-[A-Za-z0-9._-]{1,120})$/,
177
+ fragmentId: /^fragment:[A-Za-z0-9._-]{1,120}$/,
178
+ warningId: /^warning:[A-Za-z0-9._:-]{1,120}$/,
179
+ diagnosticId: /^diagnostic:[A-Za-z0-9._-]{1,120}$/,
180
+ packagePartName: /^\/[A-Za-z0-9_.\-\/]+\.[A-Za-z0-9]+$/,
181
+ relationshipId: /^rId[A-Za-z0-9._-]{1,120}$/
182
+ };
183
+ function assertCanonicalDocument(value) {
184
+ const issues = validateCanonicalDocument(value);
185
+ assertValid(issues, "Invalid canonical document.");
186
+ }
187
+ function validateCanonicalDocument(value) {
188
+ const issues = [];
189
+ const record = asPlainObject(value, "$", issues);
190
+ if (!record) {
191
+ return issues;
192
+ }
193
+ validateExactObjectKeys(record, CANONICAL_DOCUMENT_TOP_LEVEL_KEYS, "$", issues, CANONICAL_DOCUMENT_OPTIONAL_KEYS);
194
+ expectExactString(record.schemaVersion, CDS_SCHEMA_VERSION, "$.schemaVersion", issues);
195
+ expectUuid(record.docId, "$.docId", issues);
196
+ expectIso8601UtcTimestamp(record.createdAt, "$.createdAt", issues);
197
+ expectIso8601UtcTimestamp(record.updatedAt, "$.updatedAt", issues);
198
+ validateMetadata(record.metadata, "$.metadata", issues);
199
+ validateStylesCatalog(record.styles, "$.styles", issues);
200
+ validateNumberingCatalog(record.numbering, "$.numbering", issues);
201
+ validateMediaCatalog(record.media, "$.media", issues);
202
+ validateDocumentNode(record.content, "$.content", issues);
203
+ validateReviewStore(record.review, "$.review", issues);
204
+ validatePreservationStore(record.preservation, "$.preservation", issues);
205
+ validateDiagnosticStore(record.diagnostics, "$.diagnostics", issues);
206
+ if (record.subParts !== void 0) {
207
+ validateSubPartsCatalog(record.subParts, "$.subParts", issues);
208
+ }
209
+ validateDocumentReferences(record, issues);
210
+ return issues;
211
+ }
212
+ function validateMetadata(value, path, issues) {
213
+ const record = asPlainObject(value, path, issues);
214
+ if (!record) {
215
+ return;
216
+ }
217
+ const customProperties = asPlainObject(record.customProperties, `${path}.customProperties`, issues);
218
+ if (!customProperties) {
219
+ return;
220
+ }
221
+ for (const [propertyKey, propertyValue] of Object.entries(customProperties)) {
222
+ if (typeof propertyValue !== "string") {
223
+ issues.push({
224
+ path: `${path}.customProperties.${propertyKey}`,
225
+ message: "customProperties values must be strings."
226
+ });
227
+ }
228
+ }
229
+ }
230
+ function validateStylesCatalog(value, path, issues) {
231
+ const record = asPlainObject(value, path, issues);
232
+ if (!record) {
233
+ return;
234
+ }
235
+ validateStyleMap(record.paragraphs, `${path}.paragraphs`, issues);
236
+ validateStyleMap(record.characters, `${path}.characters`, issues);
237
+ validateStyleMap(record.tables, `${path}.tables`, issues);
238
+ if (record.latentStyles !== void 0) {
239
+ validateLatentStyleMap(record.latentStyles, `${path}.latentStyles`, issues);
240
+ }
241
+ }
242
+ function validateStyleMap(value, path, issues) {
243
+ const record = asPlainObject(value, path, issues);
244
+ if (!record) {
245
+ return;
246
+ }
247
+ for (const [styleId, definition] of Object.entries(record)) {
248
+ expectDomainString(styleId, "styleId", `${path}.${styleId}`, issues);
249
+ const definitionRecord = asPlainObject(definition, `${path}.${styleId}`, issues);
250
+ if (!definitionRecord) {
251
+ continue;
252
+ }
253
+ if (definitionRecord.styleId !== styleId) {
254
+ issues.push({
255
+ path: `${path}.${styleId}.styleId`,
256
+ message: "styleId must match the map key."
257
+ });
258
+ }
259
+ }
260
+ }
261
+ function validateLatentStyleMap(value, path, issues) {
262
+ const record = asPlainObject(value, path, issues);
263
+ if (!record) {
264
+ return;
265
+ }
266
+ for (const [styleName, definition] of Object.entries(record)) {
267
+ const definitionRecord = asPlainObject(definition, `${path}.${styleName}`, issues);
268
+ if (!definitionRecord) {
269
+ continue;
270
+ }
271
+ if (definitionRecord.name !== styleName) {
272
+ issues.push({
273
+ path: `${path}.${styleName}.name`,
274
+ message: "name must match the map key."
275
+ });
276
+ }
277
+ if (definitionRecord.uiPriority !== void 0 && typeof definitionRecord.uiPriority !== "number") {
278
+ issues.push({
279
+ path: `${path}.${styleName}.uiPriority`,
280
+ message: "uiPriority must be a number."
281
+ });
282
+ }
283
+ }
284
+ }
285
+ function validateNumberingCatalog(value, path, issues) {
286
+ const record = asPlainObject(value, path, issues);
287
+ if (!record) {
288
+ return;
289
+ }
290
+ const abstractDefinitions = asPlainObject(
291
+ record.abstractDefinitions,
292
+ `${path}.abstractDefinitions`,
293
+ issues
294
+ );
295
+ if (abstractDefinitions) {
296
+ for (const [abstractId, definition] of Object.entries(abstractDefinitions)) {
297
+ expectDomainString(
298
+ abstractId,
299
+ "abstractNumberingId",
300
+ `${path}.abstractDefinitions.${abstractId}`,
301
+ issues
302
+ );
303
+ const definitionRecord = asPlainObject(
304
+ definition,
305
+ `${path}.abstractDefinitions.${abstractId}`,
306
+ issues
307
+ );
308
+ if (definitionRecord && definitionRecord.abstractNumberingId !== abstractId) {
309
+ issues.push({
310
+ path: `${path}.abstractDefinitions.${abstractId}.abstractNumberingId`,
311
+ message: "abstractNumberingId must match the map key."
312
+ });
313
+ }
314
+ }
315
+ }
316
+ const instances = asPlainObject(record.instances, `${path}.instances`, issues);
317
+ if (instances) {
318
+ for (const [instanceId, instance] of Object.entries(instances)) {
319
+ expectDomainString(
320
+ instanceId,
321
+ "numberingInstanceId",
322
+ `${path}.instances.${instanceId}`,
323
+ issues
324
+ );
325
+ const instanceRecord = asPlainObject(
326
+ instance,
327
+ `${path}.instances.${instanceId}`,
328
+ issues
329
+ );
330
+ if (!instanceRecord) {
331
+ continue;
332
+ }
333
+ if (instanceRecord.numberingInstanceId !== instanceId) {
334
+ issues.push({
335
+ path: `${path}.instances.${instanceId}.numberingInstanceId`,
336
+ message: "numberingInstanceId must match the map key."
337
+ });
338
+ }
339
+ expectDomainString(
340
+ instanceRecord.abstractNumberingId,
341
+ "abstractNumberingId",
342
+ `${path}.instances.${instanceId}.abstractNumberingId`,
343
+ issues
344
+ );
345
+ }
346
+ }
347
+ }
348
+ function validateMediaCatalog(value, path, issues) {
349
+ const record = asPlainObject(value, path, issues);
350
+ if (!record) {
351
+ return;
352
+ }
353
+ const items = asPlainObject(record.items, `${path}.items`, issues);
354
+ if (!items) {
355
+ return;
356
+ }
357
+ for (const [mediaId, item] of Object.entries(items)) {
358
+ expectDomainString(mediaId, "mediaId", `${path}.items.${mediaId}`, issues);
359
+ const itemRecord = asPlainObject(item, `${path}.items.${mediaId}`, issues);
360
+ if (!itemRecord) {
361
+ continue;
362
+ }
363
+ if (itemRecord.mediaId !== mediaId) {
364
+ issues.push({
365
+ path: `${path}.items.${mediaId}.mediaId`,
366
+ message: "mediaId must match the map key."
367
+ });
368
+ }
369
+ expectDomainString(
370
+ itemRecord.packagePartName,
371
+ "packagePartName",
372
+ `${path}.items.${mediaId}.packagePartName`,
373
+ issues
374
+ );
375
+ if (itemRecord.relationshipId !== void 0) {
376
+ expectDomainString(
377
+ itemRecord.relationshipId,
378
+ "relationshipId",
379
+ `${path}.items.${mediaId}.relationshipId`,
380
+ issues
381
+ );
382
+ }
383
+ }
384
+ }
385
+ function validateDocumentNode(value, path, issues) {
386
+ const record = asPlainObject(value, path, issues);
387
+ if (!record) {
388
+ return;
389
+ }
390
+ const type = expectString(record.type, `${path}.type`, issues);
391
+ if (!type) {
392
+ return;
393
+ }
394
+ switch (type) {
395
+ case "doc":
396
+ case "paragraph":
397
+ case "sdt":
398
+ case "custom_xml":
399
+ case "hyperlink":
400
+ if (!Array.isArray(record.children)) {
401
+ issues.push({ path: `${path}.children`, message: "children must be an array." });
402
+ } else {
403
+ record.children.forEach(
404
+ (child, index) => validateDocumentNode(child, `${path}.children[${index}]`, issues)
405
+ );
406
+ }
407
+ if (type === "paragraph" && record.styleId !== void 0) {
408
+ expectDomainString(record.styleId, "styleId", `${path}.styleId`, issues);
409
+ }
410
+ if (type === "paragraph" && record.numbering !== void 0) {
411
+ const numbering = asPlainObject(record.numbering, `${path}.numbering`, issues);
412
+ if (numbering) {
413
+ expectDomainString(
414
+ numbering.numberingInstanceId,
415
+ "numberingInstanceId",
416
+ `${path}.numbering.numberingInstanceId`,
417
+ issues
418
+ );
419
+ if (typeof numbering.level !== "number") {
420
+ issues.push({
421
+ path: `${path}.numbering.level`,
422
+ message: "level must be a number."
423
+ });
424
+ }
425
+ }
426
+ }
427
+ if (type === "hyperlink") {
428
+ expectString(record.href, `${path}.href`, issues);
429
+ }
430
+ return;
431
+ case "alt_chunk":
432
+ expectDomainString(record.relationshipId, "relationshipId", `${path}.relationshipId`, issues);
433
+ return;
434
+ case "image":
435
+ expectDomainString(record.mediaId, "mediaId", `${path}.mediaId`, issues);
436
+ if (record.placementXml !== void 0) {
437
+ expectString(record.placementXml, `${path}.placementXml`, issues);
438
+ }
439
+ if (record.display !== void 0) {
440
+ const display = expectString(record.display, `${path}.display`, issues);
441
+ if (display && display !== "inline" && display !== "floating") {
442
+ issues.push({
443
+ path: `${path}.display`,
444
+ message: "display must be 'inline' or 'floating'."
445
+ });
446
+ }
447
+ }
448
+ if (record.floating !== void 0) {
449
+ validateFloatingImageProperties(record.floating, `${path}.floating`, issues);
450
+ }
451
+ return;
452
+ case "opaque_inline":
453
+ case "opaque_block":
454
+ expectDomainString(record.fragmentId, "fragmentId", `${path}.fragmentId`, issues);
455
+ expectDomainString(record.warningId, "warningId", `${path}.warningId`, issues);
456
+ if (record.rawXml !== void 0) {
457
+ expectString(record.rawXml, `${path}.rawXml`, issues);
458
+ }
459
+ return;
460
+ case "table":
461
+ if (!Array.isArray(record.gridColumns)) {
462
+ issues.push({ path: `${path}.gridColumns`, message: "gridColumns must be an array." });
463
+ }
464
+ if (!Array.isArray(record.rows)) {
465
+ issues.push({ path: `${path}.rows`, message: "rows must be an array." });
466
+ } else {
467
+ record.rows.forEach(
468
+ (row, rowIndex) => validateDocumentNode(row, `${path}.rows[${rowIndex}]`, issues)
469
+ );
470
+ }
471
+ return;
472
+ case "table_row":
473
+ if (!Array.isArray(record.cells)) {
474
+ issues.push({ path: `${path}.cells`, message: "cells must be an array." });
475
+ } else {
476
+ record.cells.forEach(
477
+ (cell, cellIndex) => validateDocumentNode(cell, `${path}.cells[${cellIndex}]`, issues)
478
+ );
479
+ }
480
+ return;
481
+ case "table_cell":
482
+ if (!Array.isArray(record.children)) {
483
+ issues.push({ path: `${path}.children`, message: "children must be an array." });
484
+ } else {
485
+ record.children.forEach(
486
+ (child, childIndex) => validateDocumentNode(child, `${path}.children[${childIndex}]`, issues)
487
+ );
488
+ }
489
+ return;
490
+ case "field":
491
+ expectString(record.fieldType, `${path}.fieldType`, issues);
492
+ expectString(record.instruction, `${path}.instruction`, issues);
493
+ if (!Array.isArray(record.children)) {
494
+ issues.push({ path: `${path}.children`, message: "children must be an array." });
495
+ } else {
496
+ record.children.forEach(
497
+ (child, index) => validateDocumentNode(child, `${path}.children[${index}]`, issues)
498
+ );
499
+ }
500
+ return;
501
+ case "bookmark_start":
502
+ expectString(record.bookmarkId, `${path}.bookmarkId`, issues);
503
+ expectString(record.name, `${path}.name`, issues);
504
+ return;
505
+ case "bookmark_end":
506
+ expectString(record.bookmarkId, `${path}.bookmarkId`, issues);
507
+ return;
508
+ case "section_break":
509
+ return;
510
+ case "text":
511
+ if (typeof record.text !== "string") {
512
+ issues.push({
513
+ path: `${path}.text`,
514
+ message: "text must be a string."
515
+ });
516
+ }
517
+ return;
518
+ case "hard_break":
519
+ case "column_break":
520
+ case "tab":
521
+ return;
522
+ case "symbol":
523
+ expectString(record.char, `${path}.char`, issues);
524
+ if (record.font !== void 0) {
525
+ expectString(record.font, `${path}.font`, issues);
526
+ }
527
+ return;
528
+ case "footnote_ref":
529
+ expectString(record.noteId, `${path}.noteId`, issues);
530
+ if (record.noteKind !== "footnote" && record.noteKind !== "endnote") {
531
+ issues.push({
532
+ path: `${path}.noteKind`,
533
+ message: "noteKind must be 'footnote' or 'endnote'."
534
+ });
535
+ }
536
+ return;
537
+ case "chart_preview":
538
+ case "smartart_preview":
539
+ case "shape":
540
+ case "wordart":
541
+ case "vml_shape":
542
+ expectString(record.rawXml, `${path}.rawXml`, issues);
543
+ return;
544
+ default:
545
+ issues.push({
546
+ path: `${path}.type`,
547
+ message: `Unsupported node type ${JSON.stringify(type)}.`
548
+ });
549
+ }
550
+ }
551
+ function validateFloatingImageProperties(value, path, issues) {
552
+ const record = asPlainObject(value, path, issues);
553
+ if (!record) {
554
+ return;
555
+ }
556
+ if (record.horizontalPosition !== void 0) {
557
+ validateFloatingAxisPosition(record.horizontalPosition, `${path}.horizontalPosition`, issues);
558
+ }
559
+ if (record.verticalPosition !== void 0) {
560
+ validateFloatingAxisPosition(record.verticalPosition, `${path}.verticalPosition`, issues);
561
+ }
562
+ if (record.wrap !== void 0) {
563
+ const wrap = expectString(record.wrap, `${path}.wrap`, issues);
564
+ if (wrap && wrap !== "none" && wrap !== "square" && wrap !== "tight" && wrap !== "through" && wrap !== "topAndBottom") {
565
+ issues.push({
566
+ path: `${path}.wrap`,
567
+ message: "wrap must be one of none, square, tight, through, or topAndBottom."
568
+ });
569
+ }
570
+ }
571
+ }
572
+ function validateFloatingAxisPosition(value, path, issues) {
573
+ const record = asPlainObject(value, path, issues);
574
+ if (!record) {
575
+ return;
576
+ }
577
+ if (record.relativeFrom !== void 0) {
578
+ expectString(record.relativeFrom, `${path}.relativeFrom`, issues);
579
+ }
580
+ if (record.align !== void 0) {
581
+ expectString(record.align, `${path}.align`, issues);
582
+ }
583
+ if (record.offset !== void 0 && typeof record.offset !== "number") {
584
+ issues.push({
585
+ path: `${path}.offset`,
586
+ message: "offset must be a number."
587
+ });
588
+ }
589
+ }
590
+ function validateReviewStore(value, path, issues) {
591
+ const record = asPlainObject(value, path, issues);
592
+ if (!record) {
593
+ return;
594
+ }
595
+ const comments = asPlainObject(record.comments, `${path}.comments`, issues);
596
+ if (comments) {
597
+ for (const [commentId, thread] of Object.entries(comments)) {
598
+ expectDomainString(commentId, "commentId", `${path}.comments.${commentId}`, issues);
599
+ const threadRecord = asPlainObject(thread, `${path}.comments.${commentId}`, issues);
600
+ if (!threadRecord) {
601
+ continue;
602
+ }
603
+ if (threadRecord.commentId !== commentId) {
604
+ issues.push({
605
+ path: `${path}.comments.${commentId}.commentId`,
606
+ message: "commentId must match the map key."
607
+ });
608
+ }
609
+ validateAnchor(threadRecord.anchor, `${path}.comments.${commentId}.anchor`, issues);
610
+ expectIso8601UtcTimestamp(
611
+ threadRecord.createdAt,
612
+ `${path}.comments.${commentId}.createdAt`,
613
+ issues
614
+ );
615
+ validateCommentStatus(threadRecord.status, `${path}.comments.${commentId}.status`, issues);
616
+ if (threadRecord.createdBy !== void 0) {
617
+ expectString(
618
+ threadRecord.createdBy,
619
+ `${path}.comments.${commentId}.createdBy`,
620
+ issues
621
+ );
622
+ }
623
+ if (threadRecord.authorId !== void 0) {
624
+ expectString(
625
+ threadRecord.authorId,
626
+ `${path}.comments.${commentId}.authorId`,
627
+ issues
628
+ );
629
+ }
630
+ if (threadRecord.body !== void 0) {
631
+ expectStringAllowEmpty(
632
+ threadRecord.body,
633
+ `${path}.comments.${commentId}.body`,
634
+ issues
635
+ );
636
+ }
637
+ if (!Array.isArray(threadRecord.warningIds)) {
638
+ issues.push({
639
+ path: `${path}.comments.${commentId}.warningIds`,
640
+ message: "warningIds must be an array."
641
+ });
642
+ } else {
643
+ threadRecord.warningIds.forEach(
644
+ (warningId, index) => expectDomainString(
645
+ warningId,
646
+ "warningId",
647
+ `${path}.comments.${commentId}.warningIds[${index}]`,
648
+ issues
649
+ )
650
+ );
651
+ }
652
+ if (threadRecord.entries !== void 0) {
653
+ validateCommentEntries(
654
+ threadRecord.entries,
655
+ `${path}.comments.${commentId}.entries`,
656
+ issues
657
+ );
658
+ }
659
+ if (threadRecord.resolution !== void 0) {
660
+ validateCommentResolution(
661
+ threadRecord.resolution,
662
+ `${path}.comments.${commentId}.resolution`,
663
+ issues
664
+ );
665
+ }
666
+ if (threadRecord.resolvedAt !== void 0) {
667
+ expectIso8601UtcTimestamp(
668
+ threadRecord.resolvedAt,
669
+ `${path}.comments.${commentId}.resolvedAt`,
670
+ issues
671
+ );
672
+ }
673
+ if (threadRecord.isResolved !== void 0 && typeof threadRecord.isResolved !== "boolean") {
674
+ issues.push({
675
+ path: `${path}.comments.${commentId}.isResolved`,
676
+ message: "isResolved must be a boolean."
677
+ });
678
+ }
679
+ if (threadRecord.metadata !== void 0) {
680
+ validateCommentThreadMetadata(
681
+ threadRecord.metadata,
682
+ `${path}.comments.${commentId}.metadata`,
683
+ issues
684
+ );
685
+ }
686
+ }
687
+ }
688
+ const revisions = asPlainObject(record.revisions, `${path}.revisions`, issues);
689
+ if (revisions) {
690
+ for (const [revisionId, revision] of Object.entries(revisions)) {
691
+ expectDomainString(revisionId, "revisionId", `${path}.revisions.${revisionId}`, issues);
692
+ const revisionRecord = asPlainObject(
693
+ revision,
694
+ `${path}.revisions.${revisionId}`,
695
+ issues
696
+ );
697
+ if (!revisionRecord) {
698
+ continue;
699
+ }
700
+ if (revisionRecord.changeId !== revisionId) {
701
+ issues.push({
702
+ path: `${path}.revisions.${revisionId}.changeId`,
703
+ message: "changeId must match the map key."
704
+ });
705
+ }
706
+ validateAnchor(revisionRecord.anchor, `${path}.revisions.${revisionId}.anchor`, issues);
707
+ validateRevisionKind(revisionRecord.kind, `${path}.revisions.${revisionId}.kind`, issues);
708
+ validateRevisionStatus(
709
+ revisionRecord.status,
710
+ `${path}.revisions.${revisionId}.status`,
711
+ issues
712
+ );
713
+ expectIso8601UtcTimestamp(
714
+ revisionRecord.createdAt,
715
+ `${path}.revisions.${revisionId}.createdAt`,
716
+ issues
717
+ );
718
+ if (revisionRecord.authorId !== void 0) {
719
+ expectString(
720
+ revisionRecord.authorId,
721
+ `${path}.revisions.${revisionId}.authorId`,
722
+ issues
723
+ );
724
+ }
725
+ if (revisionRecord.warningIds !== void 0) {
726
+ validateWarningIds(
727
+ revisionRecord.warningIds,
728
+ `${path}.revisions.${revisionId}.warningIds`,
729
+ issues
730
+ );
731
+ }
732
+ if (revisionRecord.metadata !== void 0) {
733
+ validateRevisionMetadata(
734
+ revisionRecord.metadata,
735
+ `${path}.revisions.${revisionId}.metadata`,
736
+ issues
737
+ );
738
+ }
739
+ }
740
+ }
741
+ }
742
+ function validateCommentStatus(value, path, issues) {
743
+ if (value === "open" || value === "resolved" || value === "detached") {
744
+ return;
745
+ }
746
+ issues.push({
747
+ path,
748
+ message: "status must be one of open, resolved, or detached."
749
+ });
750
+ }
751
+ function validateCommentEntries(value, path, issues) {
752
+ if (!Array.isArray(value)) {
753
+ issues.push({
754
+ path,
755
+ message: "entries must be an array."
756
+ });
757
+ return;
758
+ }
759
+ value.forEach((entry, index) => {
760
+ const record = asPlainObject(entry, `${path}[${index}]`, issues);
761
+ if (!record) {
762
+ return;
763
+ }
764
+ expectString(record.entryId, `${path}[${index}].entryId`, issues);
765
+ expectString(record.authorId, `${path}[${index}].authorId`, issues);
766
+ expectStringAllowEmpty(record.body, `${path}[${index}].body`, issues);
767
+ expectIso8601UtcTimestamp(record.createdAt, `${path}[${index}].createdAt`, issues);
768
+ if (record.metadata !== void 0) {
769
+ validateCommentEntryMetadata(record.metadata, `${path}[${index}].metadata`, issues);
770
+ }
771
+ });
772
+ }
773
+ function validateCommentEntryMetadata(value, path, issues) {
774
+ const record = asPlainObject(value, path, issues);
775
+ if (!record) {
776
+ return;
777
+ }
778
+ for (const field of [
779
+ "ooxmlCommentId",
780
+ "paraId",
781
+ "parentParaId",
782
+ "durableId",
783
+ "initials"
784
+ ]) {
785
+ if (record[field] !== void 0) {
786
+ expectString(record[field], `${path}.${field}`, issues);
787
+ }
788
+ }
789
+ }
790
+ function validateCommentResolution(value, path, issues) {
791
+ const record = asPlainObject(value, path, issues);
792
+ if (!record) {
793
+ return;
794
+ }
795
+ expectIso8601UtcTimestamp(record.resolvedAt, `${path}.resolvedAt`, issues);
796
+ expectString(record.resolvedBy, `${path}.resolvedBy`, issues);
797
+ }
798
+ function validateCommentThreadMetadata(value, path, issues) {
799
+ const record = asPlainObject(value, path, issues);
800
+ if (!record) {
801
+ return;
802
+ }
803
+ if (record.source !== void 0 && record.source !== "runtime" && record.source !== "import") {
804
+ issues.push({
805
+ path: `${path}.source`,
806
+ message: "source must be either runtime or import."
807
+ });
808
+ }
809
+ if (record.rootOoxmlCommentId !== void 0) {
810
+ expectString(record.rootOoxmlCommentId, `${path}.rootOoxmlCommentId`, issues);
811
+ }
812
+ if (record.rootParaId !== void 0) {
813
+ expectString(record.rootParaId, `${path}.rootParaId`, issues);
814
+ }
815
+ }
816
+ function validateRevisionKind(value, path, issues) {
817
+ if (value === "insertion" || value === "deletion" || value === "formatting" || value === "move" || value === "property-change") {
818
+ return;
819
+ }
820
+ issues.push({
821
+ path,
822
+ message: "kind must be insertion, deletion, formatting, move, or property-change."
823
+ });
824
+ }
825
+ function validateRevisionStatus(value, path, issues) {
826
+ if (value === "open" || value === "accepted" || value === "rejected" || value === "detached") {
827
+ return;
828
+ }
829
+ issues.push({
830
+ path,
831
+ message: "status must be one of open, accepted, rejected, or detached."
832
+ });
833
+ }
834
+ function validateWarningIds(value, path, issues) {
835
+ if (!Array.isArray(value)) {
836
+ issues.push({
837
+ path,
838
+ message: "warningIds must be an array."
839
+ });
840
+ return;
841
+ }
842
+ value.forEach(
843
+ (warningId, index) => expectDomainString(warningId, "warningId", `${path}[${index}]`, issues)
844
+ );
845
+ }
846
+ function validateRevisionMetadata(value, path, issues) {
847
+ const record = asPlainObject(value, path, issues);
848
+ if (!record) {
849
+ return;
850
+ }
851
+ if (record.source !== void 0 && record.source !== "runtime" && record.source !== "import") {
852
+ issues.push({
853
+ path: `${path}.source`,
854
+ message: "source must be either runtime or import."
855
+ });
856
+ }
857
+ for (const field of [
858
+ "preserveOnlyReason",
859
+ "importedRevisionForm",
860
+ "originalRevisionType",
861
+ "ooxmlRevisionId"
862
+ ]) {
863
+ if (record[field] !== void 0) {
864
+ expectString(record[field], `${path}.${field}`, issues);
865
+ }
866
+ }
867
+ if (record.propertyChangeData !== void 0) {
868
+ const pcd = asPlainObject(record.propertyChangeData, `${path}.propertyChangeData`, issues);
869
+ if (pcd) {
870
+ expectString(pcd.xmlTag, `${path}.propertyChangeData.xmlTag`, issues);
871
+ expectString(pcd.beforeXml, `${path}.propertyChangeData.beforeXml`, issues);
872
+ }
873
+ }
874
+ if (record.moveData !== void 0) {
875
+ const md = asPlainObject(record.moveData, `${path}.moveData`, issues);
876
+ if (md) {
877
+ expectString(md.moveId, `${path}.moveData.moveId`, issues);
878
+ expectString(md.direction, `${path}.moveData.direction`, issues);
879
+ }
880
+ }
881
+ }
882
+ function validatePreservationStore(value, path, issues) {
883
+ const record = asPlainObject(value, path, issues);
884
+ if (!record) {
885
+ return;
886
+ }
887
+ const opaqueFragments = asPlainObject(
888
+ record.opaqueFragments,
889
+ `${path}.opaqueFragments`,
890
+ issues
891
+ );
892
+ if (opaqueFragments) {
893
+ for (const [fragmentId, fragment] of Object.entries(opaqueFragments)) {
894
+ expectDomainString(fragmentId, "fragmentId", `${path}.opaqueFragments.${fragmentId}`, issues);
895
+ const fragmentRecord = asPlainObject(
896
+ fragment,
897
+ `${path}.opaqueFragments.${fragmentId}`,
898
+ issues
899
+ );
900
+ if (!fragmentRecord) {
901
+ continue;
902
+ }
903
+ if (fragmentRecord.fragmentId !== fragmentId) {
904
+ issues.push({
905
+ path: `${path}.opaqueFragments.${fragmentId}.fragmentId`,
906
+ message: "fragmentId must match the map key."
907
+ });
908
+ }
909
+ validateRange(
910
+ fragmentRecord.lastKnownRange,
911
+ `${path}.opaqueFragments.${fragmentId}.lastKnownRange`,
912
+ issues
913
+ );
914
+ expectDomainString(
915
+ fragmentRecord.warningId,
916
+ "warningId",
917
+ `${path}.opaqueFragments.${fragmentId}.warningId`,
918
+ issues
919
+ );
920
+ if (fragmentRecord.packagePartName !== void 0) {
921
+ expectDomainString(
922
+ fragmentRecord.packagePartName,
923
+ "packagePartName",
924
+ `${path}.opaqueFragments.${fragmentId}.packagePartName`,
925
+ issues
926
+ );
927
+ }
928
+ if (fragmentRecord.relationshipId !== void 0) {
929
+ expectDomainString(
930
+ fragmentRecord.relationshipId,
931
+ "relationshipId",
932
+ `${path}.opaqueFragments.${fragmentId}.relationshipId`,
933
+ issues
934
+ );
935
+ }
936
+ }
937
+ }
938
+ const packageParts = asPlainObject(record.packageParts, `${path}.packageParts`, issues);
939
+ if (packageParts) {
940
+ for (const [packagePartName, packagePart] of Object.entries(packageParts)) {
941
+ expectDomainString(
942
+ packagePartName,
943
+ "packagePartName",
944
+ `${path}.packageParts.${packagePartName}`,
945
+ issues
946
+ );
947
+ const packagePartRecord = asPlainObject(
948
+ packagePart,
949
+ `${path}.packageParts.${packagePartName}`,
950
+ issues
951
+ );
952
+ if (!packagePartRecord) {
953
+ continue;
954
+ }
955
+ if (packagePartRecord.packagePartName !== packagePartName) {
956
+ issues.push({
957
+ path: `${path}.packageParts.${packagePartName}.packagePartName`,
958
+ message: "packagePartName must match the map key."
959
+ });
960
+ }
961
+ if (Array.isArray(packagePartRecord.relationshipIds)) {
962
+ packagePartRecord.relationshipIds.forEach(
963
+ (relationshipId, index) => expectDomainString(
964
+ relationshipId,
965
+ "relationshipId",
966
+ `${path}.packageParts.${packagePartName}.relationshipIds[${index}]`,
967
+ issues
968
+ )
969
+ );
970
+ }
971
+ }
972
+ }
973
+ }
974
+ function validateDiagnosticStore(value, path, issues) {
975
+ const record = asPlainObject(value, path, issues);
976
+ if (!record) {
977
+ return;
978
+ }
979
+ if (Array.isArray(record.warnings)) {
980
+ record.warnings.forEach((warning, index) => {
981
+ const warningRecord = asPlainObject(warning, `${path}.warnings[${index}]`, issues);
982
+ if (!warningRecord) {
983
+ return;
984
+ }
985
+ expectDomainString(
986
+ warningRecord.diagnosticId,
987
+ "diagnosticId",
988
+ `${path}.warnings[${index}].diagnosticId`,
989
+ issues
990
+ );
991
+ expectDomainString(
992
+ warningRecord.warningId,
993
+ "warningId",
994
+ `${path}.warnings[${index}].warningId`,
995
+ issues
996
+ );
997
+ });
998
+ }
999
+ if (Array.isArray(record.errors)) {
1000
+ record.errors.forEach((error, index) => {
1001
+ const errorRecord = asPlainObject(error, `${path}.errors[${index}]`, issues);
1002
+ if (!errorRecord) {
1003
+ return;
1004
+ }
1005
+ expectDomainString(
1006
+ errorRecord.diagnosticId,
1007
+ "diagnosticId",
1008
+ `${path}.errors[${index}].diagnosticId`,
1009
+ issues
1010
+ );
1011
+ });
1012
+ }
1013
+ }
1014
+ function validateAnchor(value, path, issues) {
1015
+ const record = asPlainObject(value, path, issues);
1016
+ if (!record) {
1017
+ return;
1018
+ }
1019
+ const kind = expectString(record.kind, `${path}.kind`, issues);
1020
+ if (!kind) {
1021
+ return;
1022
+ }
1023
+ if (kind === "range") {
1024
+ validateRange(record.range, `${path}.range`, issues);
1025
+ validateBoundaryAssoc(record.assoc, `${path}.assoc`, issues);
1026
+ } else if (kind === "node") {
1027
+ if (typeof record.at !== "number") {
1028
+ issues.push({
1029
+ path: `${path}.at`,
1030
+ message: "node anchors must contain a numeric at value."
1031
+ });
1032
+ }
1033
+ if (record.assoc !== -1 && record.assoc !== 1) {
1034
+ issues.push({
1035
+ path: `${path}.assoc`,
1036
+ message: "node anchor assoc must be -1 or 1."
1037
+ });
1038
+ }
1039
+ } else if (kind === "detached") {
1040
+ validateRange(record.lastKnownRange, `${path}.lastKnownRange`, issues);
1041
+ if (record.reason !== "deleted" && record.reason !== "invalidatedByStructureChange" && record.reason !== "importAmbiguity") {
1042
+ issues.push({
1043
+ path: `${path}.reason`,
1044
+ message: "detached anchor reason must be deleted, invalidatedByStructureChange, or importAmbiguity."
1045
+ });
1046
+ }
1047
+ } else {
1048
+ issues.push({
1049
+ path: `${path}.kind`,
1050
+ message: "anchor kind must be range, node, or detached."
1051
+ });
1052
+ }
1053
+ }
1054
+ function validateBoundaryAssoc(value, path, issues) {
1055
+ const record = asPlainObject(value, path, issues);
1056
+ if (!record) {
1057
+ return;
1058
+ }
1059
+ if (record.start !== -1 && record.start !== 1) {
1060
+ issues.push({
1061
+ path: `${path}.start`,
1062
+ message: "assoc.start must be -1 or 1."
1063
+ });
1064
+ }
1065
+ if (record.end !== -1 && record.end !== 1) {
1066
+ issues.push({
1067
+ path: `${path}.end`,
1068
+ message: "assoc.end must be -1 or 1."
1069
+ });
1070
+ }
1071
+ }
1072
+ function validateDocumentReferences(record, issues) {
1073
+ const paragraphStyleIds = new Set(
1074
+ Object.keys(asPlainObject(asPlainObject(record.styles, "$.styles", [])?.paragraphs, "$.styles.paragraphs", []) ?? {})
1075
+ );
1076
+ const numberingInstanceIds = new Set(
1077
+ Object.keys(asPlainObject(asPlainObject(record.numbering, "$.numbering", [])?.instances, "$.numbering.instances", []) ?? {})
1078
+ );
1079
+ const abstractNumberingIds = new Set(
1080
+ Object.keys(asPlainObject(asPlainObject(record.numbering, "$.numbering", [])?.abstractDefinitions, "$.numbering.abstractDefinitions", []) ?? {})
1081
+ );
1082
+ const mediaIds = new Set(
1083
+ Object.keys(asPlainObject(asPlainObject(record.media, "$.media", [])?.items, "$.media.items", []) ?? {})
1084
+ );
1085
+ const warningIds = new Set(
1086
+ (Array.isArray(asPlainObject(record.diagnostics, "$.diagnostics", [])?.warnings) ? asPlainObject(record.diagnostics, "$.diagnostics", [])?.warnings : []).flatMap((warning) => typeof warning.warningId === "string" ? [warning.warningId] : [])
1087
+ );
1088
+ const fragmentIds = new Set(
1089
+ Object.keys(asPlainObject(asPlainObject(record.preservation, "$.preservation", [])?.opaqueFragments, "$.preservation.opaqueFragments", []) ?? {})
1090
+ );
1091
+ const noteIds = collectNoteIds(record);
1092
+ const numberingInstances = asPlainObject(
1093
+ asPlainObject(record.numbering, "$.numbering", [])?.instances,
1094
+ "$.numbering.instances",
1095
+ []
1096
+ );
1097
+ if (numberingInstances) {
1098
+ for (const [instanceId, instance] of Object.entries(numberingInstances)) {
1099
+ const instanceRecord = asPlainObject(instance, `$.numbering.instances.${instanceId}`, []);
1100
+ if (instanceRecord && typeof instanceRecord.abstractNumberingId === "string" && !abstractNumberingIds.has(instanceRecord.abstractNumberingId)) {
1101
+ issues.push({
1102
+ path: `$.numbering.instances.${instanceId}.abstractNumberingId`,
1103
+ message: "abstractNumberingId must reference an existing abstract numbering definition."
1104
+ });
1105
+ }
1106
+ }
1107
+ }
1108
+ validateDocumentNodeReferences(record.content, "$.content", issues, {
1109
+ paragraphStyleIds,
1110
+ numberingInstanceIds,
1111
+ mediaIds,
1112
+ warningIds,
1113
+ fragmentIds,
1114
+ noteIds
1115
+ });
1116
+ validateSubPartReferences(record.subParts, "$.subParts", issues, {
1117
+ paragraphStyleIds,
1118
+ numberingInstanceIds,
1119
+ mediaIds,
1120
+ warningIds,
1121
+ fragmentIds,
1122
+ noteIds
1123
+ });
1124
+ validateReviewReferences(record.review, "$.review", issues, warningIds);
1125
+ }
1126
+ function validateDocumentNodeReferences(value, path, issues, references) {
1127
+ const record = asPlainObject(value, path, issues);
1128
+ if (!record) {
1129
+ return;
1130
+ }
1131
+ const type = typeof record.type === "string" ? record.type : void 0;
1132
+ if (type === "paragraph") {
1133
+ if (typeof record.styleId === "string" && !references.paragraphStyleIds.has(record.styleId)) {
1134
+ issues.push({
1135
+ path: `${path}.styleId`,
1136
+ message: "styleId must reference an existing paragraph style definition."
1137
+ });
1138
+ }
1139
+ const numbering = asPlainObject(record.numbering, `${path}.numbering`, []);
1140
+ if (numbering && typeof numbering.numberingInstanceId === "string" && !references.numberingInstanceIds.has(numbering.numberingInstanceId)) {
1141
+ issues.push({
1142
+ path: `${path}.numbering.numberingInstanceId`,
1143
+ message: "numberingInstanceId must reference an existing numbering instance."
1144
+ });
1145
+ }
1146
+ } else if (type === "image") {
1147
+ if (typeof record.mediaId === "string" && !references.mediaIds.has(record.mediaId)) {
1148
+ issues.push({
1149
+ path: `${path}.mediaId`,
1150
+ message: "mediaId must reference an existing media catalog item."
1151
+ });
1152
+ }
1153
+ } else if (type === "opaque_inline" || type === "opaque_block") {
1154
+ if (typeof record.fragmentId === "string" && !references.fragmentIds.has(record.fragmentId)) {
1155
+ issues.push({
1156
+ path: `${path}.fragmentId`,
1157
+ message: "fragmentId must reference an existing opaque fragment."
1158
+ });
1159
+ }
1160
+ if (typeof record.warningId === "string" && !references.warningIds.has(record.warningId)) {
1161
+ issues.push({
1162
+ path: `${path}.warningId`,
1163
+ message: "warningId must reference an existing diagnostic warning."
1164
+ });
1165
+ }
1166
+ } else if (type === "footnote_ref") {
1167
+ if (typeof record.noteId === "string" && !references.noteIds.has(`${record.noteKind}:${record.noteId}`)) {
1168
+ issues.push({
1169
+ path: `${path}.noteId`,
1170
+ message: "noteId must reference an existing footnote or endnote definition."
1171
+ });
1172
+ }
1173
+ }
1174
+ if (Array.isArray(record.children)) {
1175
+ record.children.forEach(
1176
+ (child, index) => validateDocumentNodeReferences(child, `${path}.children[${index}]`, issues, references)
1177
+ );
1178
+ }
1179
+ if (Array.isArray(record.rows)) {
1180
+ record.rows.forEach(
1181
+ (row, index) => validateDocumentNodeReferences(row, `${path}.rows[${index}]`, issues, references)
1182
+ );
1183
+ }
1184
+ if (Array.isArray(record.cells)) {
1185
+ record.cells.forEach(
1186
+ (cell, index) => validateDocumentNodeReferences(cell, `${path}.cells[${index}]`, issues, references)
1187
+ );
1188
+ }
1189
+ }
1190
+ function validateReviewReferences(value, path, issues, warningIds) {
1191
+ const record = asPlainObject(value, path, issues);
1192
+ if (!record) {
1193
+ return;
1194
+ }
1195
+ const comments = asPlainObject(record.comments, `${path}.comments`, []);
1196
+ if (comments) {
1197
+ for (const [commentId, thread] of Object.entries(comments)) {
1198
+ const threadRecord = asPlainObject(thread, `${path}.comments.${commentId}`, []);
1199
+ if (!threadRecord || !Array.isArray(threadRecord.warningIds)) {
1200
+ continue;
1201
+ }
1202
+ threadRecord.warningIds.forEach((warningId, index) => {
1203
+ if (typeof warningId === "string" && !warningIds.has(warningId)) {
1204
+ issues.push({
1205
+ path: `${path}.comments.${commentId}.warningIds[${index}]`,
1206
+ message: "warningIds must reference existing diagnostic warnings."
1207
+ });
1208
+ }
1209
+ });
1210
+ }
1211
+ }
1212
+ const revisions = asPlainObject(record.revisions, `${path}.revisions`, []);
1213
+ if (revisions) {
1214
+ for (const [revisionId, revision] of Object.entries(revisions)) {
1215
+ const revisionRecord = asPlainObject(revision, `${path}.revisions.${revisionId}`, []);
1216
+ if (!revisionRecord || !Array.isArray(revisionRecord.warningIds)) {
1217
+ continue;
1218
+ }
1219
+ revisionRecord.warningIds.forEach((warningId, index) => {
1220
+ if (typeof warningId === "string" && !warningIds.has(warningId)) {
1221
+ issues.push({
1222
+ path: `${path}.revisions.${revisionId}.warningIds[${index}]`,
1223
+ message: "warningIds must reference existing diagnostic warnings."
1224
+ });
1225
+ }
1226
+ });
1227
+ }
1228
+ }
1229
+ }
1230
+ function validateSubPartReferences(value, path, issues, references) {
1231
+ if (value === void 0) {
1232
+ return;
1233
+ }
1234
+ const record = asPlainObject(value, path, issues);
1235
+ if (!record) {
1236
+ return;
1237
+ }
1238
+ const headers = Array.isArray(record.headers) ? record.headers : [];
1239
+ headers.forEach((header, index) => {
1240
+ const headerRecord = asPlainObject(header, `${path}.headers[${index}]`, []);
1241
+ if (!headerRecord || !Array.isArray(headerRecord.blocks)) {
1242
+ return;
1243
+ }
1244
+ headerRecord.blocks.forEach(
1245
+ (block, blockIndex) => validateDocumentNodeReferences(block, `${path}.headers[${index}].blocks[${blockIndex}]`, issues, references)
1246
+ );
1247
+ });
1248
+ const footers = Array.isArray(record.footers) ? record.footers : [];
1249
+ footers.forEach((footer, index) => {
1250
+ const footerRecord = asPlainObject(footer, `${path}.footers[${index}]`, []);
1251
+ if (!footerRecord || !Array.isArray(footerRecord.blocks)) {
1252
+ return;
1253
+ }
1254
+ footerRecord.blocks.forEach(
1255
+ (block, blockIndex) => validateDocumentNodeReferences(block, `${path}.footers[${index}].blocks[${blockIndex}]`, issues, references)
1256
+ );
1257
+ });
1258
+ if (record.footnoteCollection !== void 0) {
1259
+ const footnoteCollection = asPlainObject(record.footnoteCollection, `${path}.footnoteCollection`, []);
1260
+ const footnotes = asPlainObject(footnoteCollection?.footnotes, `${path}.footnoteCollection.footnotes`, []);
1261
+ if (footnotes) {
1262
+ for (const [noteId, note] of Object.entries(footnotes)) {
1263
+ const noteRecord = asPlainObject(note, `${path}.footnoteCollection.footnotes.${noteId}`, []);
1264
+ if (!noteRecord || !Array.isArray(noteRecord.blocks)) {
1265
+ continue;
1266
+ }
1267
+ noteRecord.blocks.forEach(
1268
+ (block, blockIndex) => validateDocumentNodeReferences(
1269
+ block,
1270
+ `${path}.footnoteCollection.footnotes.${noteId}.blocks[${blockIndex}]`,
1271
+ issues,
1272
+ references
1273
+ )
1274
+ );
1275
+ }
1276
+ }
1277
+ const endnotes = asPlainObject(footnoteCollection?.endnotes, `${path}.footnoteCollection.endnotes`, []);
1278
+ if (endnotes) {
1279
+ for (const [noteId, note] of Object.entries(endnotes)) {
1280
+ const noteRecord = asPlainObject(note, `${path}.footnoteCollection.endnotes.${noteId}`, []);
1281
+ if (!noteRecord || !Array.isArray(noteRecord.blocks)) {
1282
+ continue;
1283
+ }
1284
+ noteRecord.blocks.forEach(
1285
+ (block, blockIndex) => validateDocumentNodeReferences(
1286
+ block,
1287
+ `${path}.footnoteCollection.endnotes.${noteId}.blocks[${blockIndex}]`,
1288
+ issues,
1289
+ references
1290
+ )
1291
+ );
1292
+ }
1293
+ }
1294
+ }
1295
+ }
1296
+ function collectNoteIds(record) {
1297
+ const noteIds = /* @__PURE__ */ new Set();
1298
+ const subParts = asPlainObject(record.subParts, "$.subParts", []);
1299
+ const footnoteCollection = asPlainObject(subParts?.footnoteCollection, "$.subParts.footnoteCollection", []);
1300
+ const footnotes = asPlainObject(footnoteCollection?.footnotes, "$.subParts.footnoteCollection.footnotes", []);
1301
+ if (footnotes) {
1302
+ Object.keys(footnotes).forEach((noteId) => noteIds.add(`footnote:${noteId}`));
1303
+ }
1304
+ const endnotes = asPlainObject(footnoteCollection?.endnotes, "$.subParts.footnoteCollection.endnotes", []);
1305
+ if (endnotes) {
1306
+ Object.keys(endnotes).forEach((noteId) => noteIds.add(`endnote:${noteId}`));
1307
+ }
1308
+ return noteIds;
1309
+ }
1310
+ function validateRange(value, path, issues) {
1311
+ const record = asPlainObject(value, path, issues);
1312
+ if (!record) {
1313
+ return;
1314
+ }
1315
+ if (typeof record.from !== "number" || typeof record.to !== "number") {
1316
+ issues.push({
1317
+ path,
1318
+ message: "Range must contain numeric from and to values."
1319
+ });
1320
+ }
1321
+ }
1322
+ function validateExactObjectKeys(record, expectedKeys, path, issues, allowedOptionalKeys) {
1323
+ const actualKeys = new Set(Object.keys(record));
1324
+ const expected = new Set(expectedKeys);
1325
+ const optional = new Set(allowedOptionalKeys ?? []);
1326
+ for (const expectedKey of expectedKeys) {
1327
+ if (!actualKeys.has(expectedKey)) {
1328
+ issues.push({
1329
+ path,
1330
+ message: `Missing required key ${JSON.stringify(expectedKey)}.`
1331
+ });
1332
+ }
1333
+ }
1334
+ for (const actualKey of actualKeys) {
1335
+ if (!expected.has(actualKey) && !optional.has(actualKey)) {
1336
+ issues.push({
1337
+ path: `${path}.${actualKey}`,
1338
+ message: "Unexpected canonical document key. Render/UI state is not part of the canonical envelope."
1339
+ });
1340
+ }
1341
+ }
1342
+ }
1343
+ function validateSubPartsCatalog(value, path, issues) {
1344
+ if (value === void 0) {
1345
+ return;
1346
+ }
1347
+ const record = asPlainObject(value, path, issues);
1348
+ if (!record) {
1349
+ return;
1350
+ }
1351
+ if (record.headers !== void 0) {
1352
+ if (!Array.isArray(record.headers)) {
1353
+ issues.push({ path: `${path}.headers`, message: "headers must be an array." });
1354
+ } else {
1355
+ record.headers.forEach((header, index) => {
1356
+ const headerRecord = asPlainObject(header, `${path}.headers[${index}]`, issues);
1357
+ if (headerRecord) {
1358
+ expectString(headerRecord.variant, `${path}.headers[${index}].variant`, issues);
1359
+ expectString(headerRecord.partPath, `${path}.headers[${index}].partPath`, issues);
1360
+ expectString(headerRecord.relationshipId, `${path}.headers[${index}].relationshipId`, issues);
1361
+ if (!Array.isArray(headerRecord.blocks)) {
1362
+ issues.push({ path: `${path}.headers[${index}].blocks`, message: "blocks must be an array." });
1363
+ } else {
1364
+ headerRecord.blocks.forEach(
1365
+ (block, blockIndex) => validateDocumentNode(block, `${path}.headers[${index}].blocks[${blockIndex}]`, issues)
1366
+ );
1367
+ }
1368
+ }
1369
+ });
1370
+ }
1371
+ }
1372
+ if (record.footers !== void 0) {
1373
+ if (!Array.isArray(record.footers)) {
1374
+ issues.push({ path: `${path}.footers`, message: "footers must be an array." });
1375
+ } else {
1376
+ record.footers.forEach((footer, index) => {
1377
+ const footerRecord = asPlainObject(footer, `${path}.footers[${index}]`, issues);
1378
+ if (footerRecord) {
1379
+ expectString(footerRecord.variant, `${path}.footers[${index}].variant`, issues);
1380
+ expectString(footerRecord.partPath, `${path}.footers[${index}].partPath`, issues);
1381
+ expectString(footerRecord.relationshipId, `${path}.footers[${index}].relationshipId`, issues);
1382
+ if (!Array.isArray(footerRecord.blocks)) {
1383
+ issues.push({ path: `${path}.footers[${index}].blocks`, message: "blocks must be an array." });
1384
+ } else {
1385
+ footerRecord.blocks.forEach(
1386
+ (block, blockIndex) => validateDocumentNode(block, `${path}.footers[${index}].blocks[${blockIndex}]`, issues)
1387
+ );
1388
+ }
1389
+ }
1390
+ });
1391
+ }
1392
+ }
1393
+ if (record.footnoteCollection !== void 0) {
1394
+ const footnoteCollection = asPlainObject(record.footnoteCollection, `${path}.footnoteCollection`, issues);
1395
+ if (footnoteCollection) {
1396
+ validateSubPartNoteMap(footnoteCollection.footnotes, "footnote", `${path}.footnoteCollection.footnotes`, issues);
1397
+ validateSubPartNoteMap(footnoteCollection.endnotes, "endnote", `${path}.footnoteCollection.endnotes`, issues);
1398
+ }
1399
+ }
1400
+ }
1401
+ function validateSubPartNoteMap(value, expectedKind, path, issues) {
1402
+ const record = asPlainObject(value, path, issues);
1403
+ if (!record) {
1404
+ return;
1405
+ }
1406
+ for (const [noteId, note] of Object.entries(record)) {
1407
+ const noteRecord = asPlainObject(note, `${path}.${noteId}`, issues);
1408
+ if (!noteRecord) {
1409
+ continue;
1410
+ }
1411
+ expectString(noteRecord.noteId, `${path}.${noteId}.noteId`, issues);
1412
+ if (noteRecord.noteId !== noteId) {
1413
+ issues.push({
1414
+ path: `${path}.${noteId}.noteId`,
1415
+ message: "noteId must match the map key."
1416
+ });
1417
+ }
1418
+ if (noteRecord.kind !== expectedKind) {
1419
+ issues.push({
1420
+ path: `${path}.${noteId}.kind`,
1421
+ message: `kind must be ${expectedKind}.`
1422
+ });
1423
+ }
1424
+ if (!Array.isArray(noteRecord.blocks)) {
1425
+ issues.push({ path: `${path}.${noteId}.blocks`, message: "blocks must be an array." });
1426
+ } else {
1427
+ noteRecord.blocks.forEach(
1428
+ (block, blockIndex) => validateDocumentNode(block, `${path}.${noteId}.blocks[${blockIndex}]`, issues)
1429
+ );
1430
+ }
1431
+ }
1432
+ }
1433
+ function expectDomainString(value, domain, path, issues) {
1434
+ const stableId = expectString(value, path, issues);
1435
+ if (!stableId) {
1436
+ return null;
1437
+ }
1438
+ if (!ID_PATTERNS[domain].test(stableId)) {
1439
+ issues.push({
1440
+ path,
1441
+ message: `Expected a valid ${domain}.`
1442
+ });
1443
+ return null;
1444
+ }
1445
+ return stableId;
1446
+ }
1447
+
1448
+ // src/model/snapshot.ts
1449
+ var SNAPSHOT_REQUIRED_TOP_LEVEL_KEYS = [
1450
+ "snapshotVersion",
1451
+ "schemaVersion",
1452
+ "documentId",
1453
+ "docId",
1454
+ "createdAt",
1455
+ "updatedAt",
1456
+ "savedAt",
1457
+ "editorBuild",
1458
+ "canonicalDocument",
1459
+ "compatibility",
1460
+ "warningLog"
1461
+ ];
1462
+ var SNAPSHOT_OPTIONAL_TOP_LEVEL_KEYS = ["sourcePackage", "protectionSnapshot"];
1463
+ var PERSISTED_EDITOR_SNAPSHOT_VERSIONS = /* @__PURE__ */ new Set([
1464
+ LEGACY_PERSISTED_EDITOR_SNAPSHOT_VERSION,
1465
+ PERSISTED_EDITOR_SNAPSHOT_VERSION
1466
+ ]);
1467
+ var DOCX_SOURCE_PACKAGE_MIME_TYPE = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
1468
+ var COMPATIBILITY_FEATURE_CLASSES = /* @__PURE__ */ new Set([
1469
+ "supported-roundtrip",
1470
+ "preserve-only",
1471
+ "unsupported-fatal"
1472
+ ]);
1473
+ var EDITOR_WARNING_CODES = /* @__PURE__ */ new Set([
1474
+ "unsupported_ooxml_preserved",
1475
+ "unsupported_ooxml_locked",
1476
+ "import_normalized",
1477
+ "export_roundtrip_risk",
1478
+ "comment_anchor_detached",
1479
+ "revision_anchor_detached",
1480
+ "large_document_degraded",
1481
+ "font_substitution",
1482
+ "image_missing"
1483
+ ]);
1484
+ var EDITOR_WARNING_SEVERITIES = /* @__PURE__ */ new Set(["info", "warning"]);
1485
+ var EDITOR_WARNING_SOURCES = /* @__PURE__ */ new Set([
1486
+ "import",
1487
+ "runtime",
1488
+ "review",
1489
+ "preservation",
1490
+ "validation",
1491
+ "export"
1492
+ ]);
1493
+ var EDITOR_ERROR_CODES = /* @__PURE__ */ new Set([
1494
+ "import_failed",
1495
+ "export_failed",
1496
+ "package_corrupt",
1497
+ "validation_failed",
1498
+ "datastore_failed",
1499
+ "internal_invariant"
1500
+ ]);
1501
+ var EDITOR_ERROR_SOURCES = /* @__PURE__ */ new Set([
1502
+ "import",
1503
+ "runtime",
1504
+ "validation",
1505
+ "datastore",
1506
+ "host",
1507
+ "export"
1508
+ ]);
1509
+ function assertPersistedEditorSnapshot(snapshot) {
1510
+ const issues = validatePersistedEditorSnapshot(snapshot);
1511
+ assertValid(issues, "Invalid persisted editor snapshot.");
1512
+ }
1513
+ function validatePersistedEditorSnapshot(snapshot) {
1514
+ const issues = [];
1515
+ const record = asPlainObject(snapshot, "$", issues);
1516
+ if (!record) {
1517
+ return issues;
1518
+ }
1519
+ validateExactObjectKeys2(
1520
+ record,
1521
+ SNAPSHOT_REQUIRED_TOP_LEVEL_KEYS,
1522
+ SNAPSHOT_OPTIONAL_TOP_LEVEL_KEYS,
1523
+ "$",
1524
+ issues
1525
+ );
1526
+ validateSnapshotVersion(record.snapshotVersion, "$.snapshotVersion", issues);
1527
+ expectExactString(
1528
+ record.schemaVersion,
1529
+ CDS_SCHEMA_VERSION,
1530
+ "$.schemaVersion",
1531
+ issues
1532
+ );
1533
+ expectString(record.documentId, "$.documentId", issues);
1534
+ expectString(record.docId, "$.docId", issues);
1535
+ expectIso8601UtcTimestamp(record.createdAt, "$.createdAt", issues);
1536
+ expectIso8601UtcTimestamp(record.updatedAt, "$.updatedAt", issues);
1537
+ expectIso8601UtcTimestamp(record.savedAt, "$.savedAt", issues);
1538
+ expectString(record.editorBuild, "$.editorBuild", issues);
1539
+ const canonicalDocumentIssues = validateCanonicalDocument(record.canonicalDocument);
1540
+ issues.push(...canonicalDocumentIssues.map(prefixIssue("$.canonicalDocument")));
1541
+ if (asPlainObject(record.canonicalDocument, "$.canonicalDocument", [])?.docId !== record.docId) {
1542
+ issues.push({
1543
+ path: "$.docId",
1544
+ message: "Snapshot docId must match canonicalDocument.docId."
1545
+ });
1546
+ }
1547
+ validateCompatibilityReport(record.compatibility, "$.compatibility", issues);
1548
+ if (!Array.isArray(record.warningLog)) {
1549
+ issues.push({
1550
+ path: "$.warningLog",
1551
+ message: "warningLog must be an array."
1552
+ });
1553
+ } else {
1554
+ record.warningLog.forEach((warning, index) => {
1555
+ validateEditorWarning(warning, `$.warningLog[${index}]`, issues);
1556
+ });
1557
+ }
1558
+ if (record.sourcePackage !== void 0) {
1559
+ validatePersistedSourcePackage(record.sourcePackage, "$.sourcePackage", issues);
1560
+ }
1561
+ if (record.protectionSnapshot !== void 0) {
1562
+ validateProtectionSnapshot(record.protectionSnapshot, "$.protectionSnapshot", issues);
1563
+ }
1564
+ return issues;
1565
+ }
1566
+ function assertCompatibilityReport(report) {
1567
+ const issues = validateCompatibilityReport(report);
1568
+ assertValid(issues, "Invalid compatibility report.");
1569
+ }
1570
+ function validateCompatibilityReport(report, path = "$", issues = []) {
1571
+ const record = asPlainObject(report, path, issues);
1572
+ if (!record) {
1573
+ return issues;
1574
+ }
1575
+ expectExactString(
1576
+ record.reportVersion,
1577
+ COMPATIBILITY_REPORT_VERSION,
1578
+ `${path}.reportVersion`,
1579
+ issues
1580
+ );
1581
+ expectIso8601UtcTimestamp(record.generatedAt, `${path}.generatedAt`, issues);
1582
+ if (typeof record.blockExport !== "boolean") {
1583
+ issues.push({
1584
+ path: `${path}.blockExport`,
1585
+ message: "blockExport must be a boolean."
1586
+ });
1587
+ }
1588
+ if (!Array.isArray(record.featureEntries)) {
1589
+ issues.push({
1590
+ path: `${path}.featureEntries`,
1591
+ message: "featureEntries must be an array."
1592
+ });
1593
+ } else {
1594
+ record.featureEntries.forEach((featureEntry, index) => {
1595
+ validateCompatibilityFeatureEntry(
1596
+ featureEntry,
1597
+ `${path}.featureEntries[${index}]`,
1598
+ issues
1599
+ );
1600
+ });
1601
+ }
1602
+ if (!Array.isArray(record.warnings)) {
1603
+ issues.push({
1604
+ path: `${path}.warnings`,
1605
+ message: "warnings must be an array."
1606
+ });
1607
+ } else {
1608
+ record.warnings.forEach((warning, index) => {
1609
+ validateEditorWarning(warning, `${path}.warnings[${index}]`, issues);
1610
+ });
1611
+ }
1612
+ if (!Array.isArray(record.errors)) {
1613
+ issues.push({
1614
+ path: `${path}.errors`,
1615
+ message: "errors must be an array."
1616
+ });
1617
+ } else {
1618
+ record.errors.forEach((error, index) => {
1619
+ validateEditorError(error, `${path}.errors[${index}]`, issues);
1620
+ });
1621
+ }
1622
+ return issues;
1623
+ }
1624
+ function validateCompatibilityFeatureEntry(featureEntry, path, issues) {
1625
+ const record = asPlainObject(featureEntry, path, issues);
1626
+ if (!record) {
1627
+ return;
1628
+ }
1629
+ expectString(record.featureEntryId, `${path}.featureEntryId`, issues);
1630
+ expectString(record.featureKey, `${path}.featureKey`, issues);
1631
+ if (typeof record.featureClass !== "string" || !COMPATIBILITY_FEATURE_CLASSES.has(record.featureClass)) {
1632
+ issues.push({
1633
+ path: `${path}.featureClass`,
1634
+ message: "featureClass must be supported-roundtrip, preserve-only, or unsupported-fatal."
1635
+ });
1636
+ }
1637
+ expectString(record.message, `${path}.message`, issues);
1638
+ }
1639
+ function validateEditorWarning(warning, path, issues) {
1640
+ const record = asPlainObject(warning, path, issues);
1641
+ if (!record) {
1642
+ return;
1643
+ }
1644
+ expectString(record.warningId, `${path}.warningId`, issues);
1645
+ if (typeof record.code !== "string" || !EDITOR_WARNING_CODES.has(record.code)) {
1646
+ issues.push({
1647
+ path: `${path}.code`,
1648
+ message: `code must be one of ${JSON.stringify([...EDITOR_WARNING_CODES])}.`
1649
+ });
1650
+ }
1651
+ if (typeof record.severity !== "string" || !EDITOR_WARNING_SEVERITIES.has(record.severity)) {
1652
+ issues.push({
1653
+ path: `${path}.severity`,
1654
+ message: "severity must be info or warning."
1655
+ });
1656
+ }
1657
+ expectString(record.message, `${path}.message`, issues);
1658
+ if (typeof record.source !== "string" || !EDITOR_WARNING_SOURCES.has(record.source)) {
1659
+ issues.push({
1660
+ path: `${path}.source`,
1661
+ message: `source must be one of ${JSON.stringify([...EDITOR_WARNING_SOURCES])}.`
1662
+ });
1663
+ }
1664
+ }
1665
+ function validateEditorError(error, path, issues) {
1666
+ const record = asPlainObject(error, path, issues);
1667
+ if (!record) {
1668
+ return;
1669
+ }
1670
+ expectString(record.errorId, `${path}.errorId`, issues);
1671
+ if (typeof record.code !== "string" || !EDITOR_ERROR_CODES.has(record.code)) {
1672
+ issues.push({
1673
+ path: `${path}.code`,
1674
+ message: `code must be one of ${JSON.stringify([...EDITOR_ERROR_CODES])}.`
1675
+ });
1676
+ }
1677
+ expectString(record.message, `${path}.message`, issues);
1678
+ if (typeof record.source !== "string" || !EDITOR_ERROR_SOURCES.has(record.source)) {
1679
+ issues.push({
1680
+ path: `${path}.source`,
1681
+ message: `source must be one of ${JSON.stringify([...EDITOR_ERROR_SOURCES])}.`
1682
+ });
1683
+ }
1684
+ if (typeof record.isFatal !== "boolean") {
1685
+ issues.push({
1686
+ path: `${path}.isFatal`,
1687
+ message: "isFatal must be a boolean."
1688
+ });
1689
+ }
1690
+ }
1691
+ function validateExactObjectKeys2(record, requiredKeys, optionalKeys, path, issues) {
1692
+ const actualKeys = new Set(Object.keys(record));
1693
+ const allowedKeys = /* @__PURE__ */ new Set([...requiredKeys, ...optionalKeys]);
1694
+ for (const requiredKey of requiredKeys) {
1695
+ if (!actualKeys.has(requiredKey)) {
1696
+ issues.push({
1697
+ path,
1698
+ message: `Missing required key ${JSON.stringify(requiredKey)}.`
1699
+ });
1700
+ }
1701
+ }
1702
+ for (const actualKey of actualKeys) {
1703
+ if (!allowedKeys.has(actualKey)) {
1704
+ issues.push({
1705
+ path: `${path}.${actualKey}`,
1706
+ message: "Unexpected persisted snapshot key. Render/UI state is not part of the persistence contract."
1707
+ });
1708
+ }
1709
+ }
1710
+ }
1711
+ function prefixIssue(basePath) {
1712
+ return (issue) => ({
1713
+ path: `${basePath}${issue.path === "$" ? "" : issue.path.slice(1)}`,
1714
+ message: issue.message
1715
+ });
1716
+ }
1717
+ function validateSnapshotVersion(value, path, issues) {
1718
+ if (typeof value !== "string" || !PERSISTED_EDITOR_SNAPSHOT_VERSIONS.has(value)) {
1719
+ issues.push({
1720
+ path,
1721
+ message: `Expected one of ${JSON.stringify([...PERSISTED_EDITOR_SNAPSHOT_VERSIONS])}.`
1722
+ });
1723
+ return null;
1724
+ }
1725
+ return value;
1726
+ }
1727
+ function validatePersistedSourcePackage(sourcePackage, path, issues) {
1728
+ const record = asPlainObject(sourcePackage, path, issues);
1729
+ if (!record) {
1730
+ return;
1731
+ }
1732
+ validateExactObjectKeys2(
1733
+ record,
1734
+ ["format", "storage", "mimeType", "sha256Hex", "bytesBase64"],
1735
+ ["sourceLabel"],
1736
+ path,
1737
+ issues
1738
+ );
1739
+ expectExactString(record.format, "docx", `${path}.format`, issues);
1740
+ expectExactString(record.storage, "embedded-base64", `${path}.storage`, issues);
1741
+ expectExactString(
1742
+ record.mimeType,
1743
+ DOCX_SOURCE_PACKAGE_MIME_TYPE,
1744
+ `${path}.mimeType`,
1745
+ issues
1746
+ );
1747
+ expectString(record.sha256Hex, `${path}.sha256Hex`, issues);
1748
+ expectString(record.bytesBase64, `${path}.bytesBase64`, issues);
1749
+ if (typeof record.sha256Hex === "string" && !/^[0-9a-f]{64}$/u.test(record.sha256Hex)) {
1750
+ issues.push({
1751
+ path: `${path}.sha256Hex`,
1752
+ message: "Expected a lowercase SHA-256 hex digest."
1753
+ });
1754
+ }
1755
+ if (record.sourceLabel !== void 0) {
1756
+ expectString(record.sourceLabel, `${path}.sourceLabel`, issues);
1757
+ }
1758
+ }
1759
+ function createPersistedEditorSnapshot(params) {
1760
+ assertCanonicalDocument(params.canonicalDocument);
1761
+ assertCompatibilityReport(params.compatibility);
1762
+ return {
1763
+ snapshotVersion: PERSISTED_EDITOR_SNAPSHOT_VERSION,
1764
+ schemaVersion: CDS_SCHEMA_VERSION,
1765
+ documentId: params.documentId,
1766
+ docId: params.canonicalDocument.docId,
1767
+ createdAt: params.canonicalDocument.createdAt,
1768
+ updatedAt: params.canonicalDocument.updatedAt,
1769
+ savedAt: params.savedAt,
1770
+ editorBuild: params.editorBuild,
1771
+ canonicalDocument: params.canonicalDocument,
1772
+ compatibility: params.compatibility,
1773
+ warningLog: params.warningLog ?? params.compatibility.warnings,
1774
+ protectionSnapshot: params.protectionSnapshot,
1775
+ sourcePackage: params.sourcePackage
1776
+ };
1777
+ }
1778
+ function validateProtectionSnapshot(value, path, issues) {
1779
+ const record = asPlainObject(value, path, issues);
1780
+ if (!record) {
1781
+ return;
1782
+ }
1783
+ if (typeof record.hasDocumentProtection !== "boolean") {
1784
+ issues.push({ path: `${path}.hasDocumentProtection`, message: "hasDocumentProtection must be a boolean." });
1785
+ }
1786
+ if (record.editType !== void 0) {
1787
+ expectString(record.editType, `${path}.editType`, issues);
1788
+ }
1789
+ if (typeof record.enforcementActive !== "boolean") {
1790
+ issues.push({ path: `${path}.enforcementActive`, message: "enforcementActive must be a boolean." });
1791
+ }
1792
+ if (!Array.isArray(record.ranges)) {
1793
+ issues.push({ path: `${path}.ranges`, message: "ranges must be an array." });
1794
+ } else {
1795
+ record.ranges.forEach((range, index) => validateProtectionRange(range, `${path}.ranges[${index}]`, issues));
1796
+ }
1797
+ if (!Number.isInteger(record.enforcedRangeCount)) {
1798
+ issues.push({ path: `${path}.enforcedRangeCount`, message: "enforcedRangeCount must be an integer." });
1799
+ }
1800
+ if (!Number.isInteger(record.preservedRangeCount)) {
1801
+ issues.push({ path: `${path}.preservedRangeCount`, message: "preservedRangeCount must be an integer." });
1802
+ }
1803
+ }
1804
+ function validateProtectionRange(value, path, issues) {
1805
+ const record = asPlainObject(value, path, issues);
1806
+ if (!record) {
1807
+ return;
1808
+ }
1809
+ expectString(record.rangeId, `${path}.rangeId`, issues);
1810
+ if (record.start !== void 0 && !Number.isInteger(record.start)) {
1811
+ issues.push({ path: `${path}.start`, message: "start must be an integer." });
1812
+ }
1813
+ if (record.end !== void 0 && !Number.isInteger(record.end)) {
1814
+ issues.push({ path: `${path}.end`, message: "end must be an integer." });
1815
+ }
1816
+ if (record.editorGroup !== void 0) {
1817
+ expectString(record.editorGroup, `${path}.editorGroup`, issues);
1818
+ }
1819
+ if (record.editor !== void 0) {
1820
+ expectString(record.editor, `${path}.editor`, issues);
1821
+ }
1822
+ if (typeof record.enforced !== "boolean") {
1823
+ issues.push({ path: `${path}.enforced`, message: "enforced must be a boolean." });
1824
+ }
1825
+ expectString(record.enforcementReason, `${path}.enforcementReason`, issues);
1826
+ }
1827
+
1828
+ // src/core/state/editor-state.ts
1829
+ function createEmptyReviewStore() {
1830
+ return {
1831
+ comments: {},
1832
+ revisions: {}
1833
+ };
1834
+ }
1835
+ function createDefaultCanonicalDocument(documentId, timestamp) {
1836
+ return {
1837
+ schemaVersion: "cds/1.0.0",
1838
+ docId: createCanonicalDocumentId(documentId),
1839
+ createdAt: timestamp,
1840
+ updatedAt: timestamp,
1841
+ metadata: {
1842
+ customProperties: {}
1843
+ },
1844
+ styles: {
1845
+ paragraphs: {},
1846
+ characters: {},
1847
+ tables: {}
1848
+ },
1849
+ numbering: {
1850
+ abstractDefinitions: {},
1851
+ instances: {}
1852
+ },
1853
+ media: {
1854
+ items: {}
1855
+ },
1856
+ content: {
1857
+ type: "doc",
1858
+ children: [{ type: "paragraph", children: [] }]
1859
+ },
1860
+ review: createEmptyReviewStore(),
1861
+ preservation: {
1862
+ opaqueFragments: {},
1863
+ packageParts: {}
1864
+ },
1865
+ diagnostics: {
1866
+ warnings: [],
1867
+ errors: []
1868
+ }
1869
+ };
1870
+ }
1871
+ function createSelectionSnapshot(anchor = 0, head = anchor) {
1872
+ return {
1873
+ anchor,
1874
+ head,
1875
+ isCollapsed: anchor === head,
1876
+ activeRange: createRangeAnchor(anchor, head, DEFAULT_BOUNDARY_ASSOC)
1877
+ };
1878
+ }
1879
+ function createEmptyCompatibilityReport(generatedAt) {
1880
+ return {
1881
+ reportVersion: "compatibility-report/1",
1882
+ generatedAt,
1883
+ blockExport: false,
1884
+ featureEntries: [],
1885
+ warnings: [],
1886
+ errors: []
1887
+ };
1888
+ }
1889
+ function createEditorState(options) {
1890
+ const timestamp = (/* @__PURE__ */ new Date(0)).toISOString();
1891
+ const normalizedSnapshot = options.persistedSnapshot ? normalizePersistedSnapshotForRuntime(options.persistedSnapshot, options.documentId, timestamp) : void 0;
1892
+ if (options.canonicalDocument) {
1893
+ assertCanonicalDocument(options.canonicalDocument);
1894
+ }
1895
+ const normalizedDocument = normalizedSnapshot ? structuredClone(normalizedSnapshot.canonicalDocument) : options.canonicalDocument ? structuredClone(options.canonicalDocument) : createDefaultCanonicalDocument(options.documentId, timestamp);
1896
+ const warnings = normalizedSnapshot ? normalizeWarningLog(normalizedSnapshot.warningLog) : options.warnings ?? [];
1897
+ const compatibility = normalizedSnapshot ? normalizeCompatibilityReport(normalizedSnapshot.compatibility) : options.compatibility ?? createEmptyCompatibilityReport(normalizedDocument.updatedAt);
1898
+ return {
1899
+ phase: options.fatalError ? "error" : "ready",
1900
+ documentId: options.documentId,
1901
+ sessionId: options.sessionId,
1902
+ sourceLabel: options.sourceLabel,
1903
+ sourcePackage: normalizedSnapshot?.sourcePackage,
1904
+ revision: 0,
1905
+ revisionToken: `${options.sessionId}:0`,
1906
+ isDirty: false,
1907
+ readOnly: options.readOnly ?? false,
1908
+ document: normalizedDocument,
1909
+ selection: createSelectionSnapshot(),
1910
+ warnings,
1911
+ compatibility,
1912
+ fatalError: options.fatalError,
1913
+ runtime: {
1914
+ hasFocus: false
1915
+ }
1916
+ };
1917
+ }
1918
+ function normalizePersistedSnapshotForRuntime(snapshot, documentId, timestamp) {
1919
+ const issues = validatePersistedEditorSnapshot(snapshot);
1920
+ if (issues.length === 0) {
1921
+ return snapshot;
1922
+ }
1923
+ if (!isRecord(snapshot) || !isRecord(snapshot.canonicalDocument)) {
1924
+ assertPersistedEditorSnapshot(snapshot);
1925
+ }
1926
+ const normalizedDocument = normalizeCanonicalDocumentEnvelope(
1927
+ snapshot.canonicalDocument,
1928
+ documentId,
1929
+ timestamp
1930
+ );
1931
+ try {
1932
+ assertCanonicalDocument(normalizedDocument);
1933
+ } catch {
1934
+ assertPersistedEditorSnapshot(snapshot);
1935
+ }
1936
+ const repairWarning = createSnapshotRepairWarning(issues.length);
1937
+ const compatibility = coerceCompatibilityReport(
1938
+ snapshot.compatibility,
1939
+ normalizedDocument.updatedAt,
1940
+ repairWarning
1941
+ );
1942
+ return {
1943
+ snapshotVersion: snapshot.snapshotVersion === "persisted-editor-snapshot/1" || snapshot.snapshotVersion === "persisted-editor-snapshot/2" ? snapshot.snapshotVersion : "persisted-editor-snapshot/2",
1944
+ schemaVersion: "cds/1.0.0",
1945
+ documentId: typeof snapshot.documentId === "string" && snapshot.documentId.length > 0 ? snapshot.documentId : documentId,
1946
+ docId: normalizedDocument.docId,
1947
+ createdAt: normalizedDocument.createdAt,
1948
+ updatedAt: normalizedDocument.updatedAt,
1949
+ savedAt: typeof snapshot.savedAt === "string" && snapshot.savedAt.length > 0 ? snapshot.savedAt : normalizedDocument.updatedAt,
1950
+ editorBuild: typeof snapshot.editorBuild === "string" && snapshot.editorBuild.length > 0 ? snapshot.editorBuild : "dev",
1951
+ canonicalDocument: normalizedDocument,
1952
+ compatibility,
1953
+ warningLog: dedupeWarnings([
1954
+ ...coerceWarnings(snapshot.warningLog),
1955
+ repairWarning
1956
+ ]),
1957
+ sourcePackage: snapshot.sourcePackage
1958
+ };
1959
+ }
1960
+ function normalizeCanonicalDocumentEnvelope(value, documentId, timestamp) {
1961
+ const base = createDefaultCanonicalDocument(documentId, timestamp);
1962
+ const record = isRecord(value) ? value : {};
1963
+ const metadata = isRecord(record.metadata) ? record.metadata : {};
1964
+ return {
1965
+ ...base,
1966
+ ...record,
1967
+ schemaVersion: "cds/1.0.0",
1968
+ docId: isUuid(record.docId) ? record.docId : createCanonicalDocumentId(documentId),
1969
+ createdAt: typeof record.createdAt === "string" && record.createdAt.length > 0 ? record.createdAt : base.createdAt,
1970
+ updatedAt: typeof record.updatedAt === "string" && record.updatedAt.length > 0 ? record.updatedAt : base.updatedAt,
1971
+ metadata: {
1972
+ ...base.metadata,
1973
+ ...metadata,
1974
+ customProperties: isRecord(metadata.customProperties) ? Object.fromEntries(
1975
+ Object.entries(metadata.customProperties).filter(([, entry]) => typeof entry === "string")
1976
+ ) : {}
1977
+ },
1978
+ styles: record.styles === void 0 ? base.styles : record.styles,
1979
+ numbering: record.numbering === void 0 ? base.numbering : record.numbering,
1980
+ media: record.media === void 0 ? base.media : record.media,
1981
+ content: isRecord(record.content) ? record.content : base.content,
1982
+ review: record.review === void 0 ? base.review : record.review,
1983
+ preservation: record.preservation === void 0 ? base.preservation : record.preservation,
1984
+ diagnostics: record.diagnostics === void 0 ? base.diagnostics : record.diagnostics,
1985
+ ...isRecord(record.subParts) ? { subParts: record.subParts } : {}
1986
+ };
1987
+ }
1988
+ function coerceCompatibilityReport(value, generatedAt, repairWarning) {
1989
+ const record = isRecord(value) ? value : {};
1990
+ const warnings = dedupeWarnings([
1991
+ ...coerceWarnings(record.warnings),
1992
+ repairWarning
1993
+ ]);
1994
+ return {
1995
+ reportVersion: "compatibility-report/1",
1996
+ generatedAt: typeof record.generatedAt === "string" && record.generatedAt.length > 0 ? record.generatedAt : generatedAt,
1997
+ blockExport: typeof record.blockExport === "boolean" ? record.blockExport : false,
1998
+ featureEntries: Array.isArray(record.featureEntries) ? record.featureEntries.flatMap((entry) => {
1999
+ if (!isRecord(entry)) {
2000
+ return [];
2001
+ }
2002
+ if (typeof entry.featureEntryId !== "string" || typeof entry.featureKey !== "string" || typeof entry.featureClass !== "string" || typeof entry.message !== "string") {
2003
+ return [];
2004
+ }
2005
+ return [{
2006
+ featureEntryId: entry.featureEntryId,
2007
+ featureKey: entry.featureKey,
2008
+ featureClass: entry.featureClass,
2009
+ message: entry.message,
2010
+ ...entry.affectedAnchor && isRecord(entry.affectedAnchor) ? { affectedAnchor: entry.affectedAnchor } : {},
2011
+ ...isRecord(entry.details) ? { details: entry.details } : {}
2012
+ }];
2013
+ }) : [],
2014
+ warnings,
2015
+ errors: Array.isArray(record.errors) ? record.errors.flatMap((entry) => {
2016
+ if (!isRecord(entry)) {
2017
+ return [];
2018
+ }
2019
+ if (typeof entry.errorId !== "string" || typeof entry.code !== "string" || typeof entry.message !== "string" || typeof entry.source !== "string" || typeof entry.isFatal !== "boolean") {
2020
+ return [];
2021
+ }
2022
+ return [{
2023
+ errorId: entry.errorId,
2024
+ code: entry.code,
2025
+ message: entry.message,
2026
+ source: entry.source,
2027
+ isFatal: entry.isFatal,
2028
+ ...isRecord(entry.details) ? { details: entry.details } : {}
2029
+ }];
2030
+ }) : []
2031
+ };
2032
+ }
2033
+ function coerceWarnings(value) {
2034
+ if (!Array.isArray(value)) {
2035
+ return [];
2036
+ }
2037
+ return value.flatMap((warning) => {
2038
+ if (!isRecord(warning)) {
2039
+ return [];
2040
+ }
2041
+ if (typeof warning.warningId !== "string" || typeof warning.code !== "string" || typeof warning.severity !== "string" || typeof warning.message !== "string" || typeof warning.source !== "string") {
2042
+ return [];
2043
+ }
2044
+ return [{
2045
+ warningId: warning.warningId,
2046
+ code: warning.code,
2047
+ severity: warning.severity,
2048
+ message: warning.message,
2049
+ source: warning.source,
2050
+ ...warning.affectedAnchor && isRecord(warning.affectedAnchor) ? { affectedAnchor: warning.affectedAnchor } : {},
2051
+ ...typeof warning.featureEntryId === "string" ? { featureEntryId: warning.featureEntryId } : {},
2052
+ ...isRecord(warning.details) ? { details: warning.details } : {}
2053
+ }];
2054
+ });
2055
+ }
2056
+ function createSnapshotRepairWarning(issueCount) {
2057
+ return {
2058
+ warningId: `warning:snapshot-repair:${issueCount}`,
2059
+ code: "import_normalized",
2060
+ severity: "warning",
2061
+ message: `Loaded a persisted snapshot after repairing ${issueCount} validation issue${issueCount === 1 ? "" : "s"}.`,
2062
+ source: "validation"
2063
+ };
2064
+ }
2065
+ function dedupeWarnings(warnings) {
2066
+ const seen = /* @__PURE__ */ new Set();
2067
+ const result = [];
2068
+ for (const warning of warnings) {
2069
+ if (!warning.warningId || seen.has(warning.warningId)) {
2070
+ continue;
2071
+ }
2072
+ seen.add(warning.warningId);
2073
+ result.push(warning);
2074
+ }
2075
+ return result;
2076
+ }
2077
+ function deriveDocumentStats(state) {
2078
+ const serializedContent = extractText(state.document.content);
2079
+ return {
2080
+ paragraphCount: estimateParagraphCount(state.document.content),
2081
+ wordCount: serializedContent.trim().length === 0 ? 0 : serializedContent.trim().split(/\s+/u).length,
2082
+ characterCount: Array.from(serializedContent).length,
2083
+ commentCount: Object.keys(state.document.review.comments).length,
2084
+ revisionCount: Object.keys(state.document.review.revisions).length
2085
+ };
2086
+ }
2087
+ function deriveRenderSnapshot(state, history) {
2088
+ const comments = Object.values(state.document.review.comments).sort(
2089
+ (left, right) => left.createdAt.localeCompare(right.createdAt)
2090
+ );
2091
+ const revisions = Object.values(state.document.review.revisions);
2092
+ return {
2093
+ documentId: state.documentId,
2094
+ sessionId: state.sessionId,
2095
+ sourceLabel: state.sourceLabel,
2096
+ revisionToken: state.revisionToken,
2097
+ isReady: state.phase === "ready",
2098
+ isDirty: state.isDirty,
2099
+ readOnly: state.readOnly,
2100
+ selection: state.selection,
2101
+ documentStats: deriveDocumentStats(state),
2102
+ comments: {
2103
+ activeCommentId: state.runtime.activeCommentId,
2104
+ openThreadCount: comments.filter((comment) => comment.status === "open").length,
2105
+ resolvedThreadCount: comments.filter((comment) => comment.status === "resolved").length,
2106
+ threads: comments
2107
+ },
2108
+ trackedChanges: {
2109
+ totalCount: revisions.length,
2110
+ pendingCount: revisions.filter((revision) => revision.status === "open").length,
2111
+ acceptedCount: revisions.filter((revision) => revision.status === "accepted").length,
2112
+ rejectedCount: revisions.filter((revision) => revision.status === "rejected").length
2113
+ },
2114
+ compatibility: {
2115
+ report: state.compatibility,
2116
+ blockExport: state.compatibility.blockExport,
2117
+ totalEntries: state.compatibility.featureEntries.length
2118
+ },
2119
+ warnings: state.warnings,
2120
+ fatalError: state.fatalError,
2121
+ commandState: {
2122
+ canUndo: history.canUndo,
2123
+ canRedo: history.canRedo,
2124
+ canAddComment: !state.readOnly,
2125
+ canAcceptAllChanges: revisions.some((revision) => revision.status === "open"),
2126
+ canRejectAllChanges: revisions.some((revision) => revision.status === "open")
2127
+ }
2128
+ };
2129
+ }
2130
+ function createPersistedEditorSnapshot2(state, options) {
2131
+ const snapshot = createPersistedEditorSnapshot({
2132
+ documentId: state.documentId,
2133
+ savedAt: options.savedAt,
2134
+ editorBuild: options.editorBuild,
2135
+ canonicalDocument: state.document,
2136
+ compatibility: options.compatibility ?? state.compatibility,
2137
+ warningLog: state.warnings,
2138
+ protectionSnapshot: options.protectionSnapshot,
2139
+ sourcePackage: state.sourcePackage
2140
+ });
2141
+ return snapshot;
2142
+ }
2143
+ function estimateParagraphCount(content) {
2144
+ if (Array.isArray(content)) {
2145
+ return content.length;
2146
+ }
2147
+ if (content && typeof content === "object" && Array.isArray(content.blocks)) {
2148
+ return content.blocks.length;
2149
+ }
2150
+ return extractText(content).length > 0 ? 1 : 0;
2151
+ }
2152
+ function normalizeWarningLog(warnings) {
2153
+ return warnings.map((warning) => ({
2154
+ ...warning,
2155
+ affectedAnchor: warning.affectedAnchor ? normalizeAnchorProjection(warning.affectedAnchor) : void 0
2156
+ }));
2157
+ }
2158
+ function normalizeCompatibilityReport(report) {
2159
+ return {
2160
+ ...report,
2161
+ featureEntries: report.featureEntries.map((entry) => ({
2162
+ ...entry,
2163
+ affectedAnchor: entry.affectedAnchor ? normalizeAnchorProjection(entry.affectedAnchor) : void 0
2164
+ })),
2165
+ warnings: normalizeWarningLog(report.warnings)
2166
+ };
2167
+ }
2168
+ function normalizeAnchorProjection(anchor) {
2169
+ switch (anchor.kind) {
2170
+ case "range": {
2171
+ const rangeAnchor = anchor;
2172
+ return rangeAnchor.range ? createRangeAnchor(rangeAnchor.range.from, rangeAnchor.range.to, rangeAnchor.assoc) : createRangeAnchor(rangeAnchor.from ?? 0, rangeAnchor.to ?? 0, rangeAnchor.assoc);
2173
+ }
2174
+ case "node":
2175
+ return createNodeAnchor(anchor.at, anchor.assoc);
2176
+ case "detached":
2177
+ return createDetachedAnchor(anchor.lastKnownRange, anchor.reason);
2178
+ }
2179
+ }
2180
+ function extractText(value) {
2181
+ if (typeof value === "string") {
2182
+ return value;
2183
+ }
2184
+ if (Array.isArray(value)) {
2185
+ return value.map((item) => extractText(item)).join(" ");
2186
+ }
2187
+ if (!value || typeof value !== "object") {
2188
+ return "";
2189
+ }
2190
+ return Object.values(value).map((item) => extractText(item)).filter(Boolean).join(" ");
2191
+ }
2192
+ function isRecord(value) {
2193
+ return Boolean(value) && typeof value === "object" && !Array.isArray(value);
2194
+ }
2195
+ function createCanonicalDocumentId(documentId) {
2196
+ const hashWord = (seed) => {
2197
+ let hash = 2166136261;
2198
+ for (const char of seed) {
2199
+ hash ^= char.charCodeAt(0);
2200
+ hash = Math.imul(hash, 16777619);
2201
+ }
2202
+ return (hash >>> 0).toString(16).padStart(8, "0");
2203
+ };
2204
+ const raw = hashWord(`${documentId}:0`) + hashWord(`${documentId}:1`) + hashWord(`${documentId}:2`) + hashWord(`${documentId}:3`);
2205
+ return [
2206
+ raw.slice(0, 8),
2207
+ raw.slice(8, 12),
2208
+ `4${raw.slice(13, 16)}`,
2209
+ `8${raw.slice(17, 20)}`,
2210
+ raw.slice(20, 32)
2211
+ ].join("-");
2212
+ }
2213
+ function normalizeCommentThreadRecord(value) {
2214
+ const record = isRecord(value) ? value : {};
2215
+ const authorId = typeof record.createdBy === "string" && record.createdBy.length > 0 ? record.createdBy : typeof record.authorId === "string" && record.authorId.length > 0 ? record.authorId : "unknown";
2216
+ const createdAt = typeof record.createdAt === "string" && record.createdAt.length > 0 ? record.createdAt : (/* @__PURE__ */ new Date(0)).toISOString();
2217
+ const entries = Array.isArray(record.entries) ? record.entries.filter((entry) => isRecord(entry)).map((entry, index) => ({
2218
+ entryId: typeof entry.entryId === "string" && entry.entryId.length > 0 ? entry.entryId : `${String(record.commentId ?? "comment")}-entry-${index + 1}`,
2219
+ authorId: typeof entry.authorId === "string" && entry.authorId.length > 0 ? entry.authorId : authorId,
2220
+ body: typeof entry.body === "string" ? entry.body : "",
2221
+ createdAt: typeof entry.createdAt === "string" && entry.createdAt.length > 0 ? entry.createdAt : createdAt,
2222
+ metadata: isRecord(entry.metadata) ? {
2223
+ ooxmlCommentId: typeof entry.metadata.ooxmlCommentId === "string" ? entry.metadata.ooxmlCommentId : void 0,
2224
+ paraId: typeof entry.metadata.paraId === "string" ? entry.metadata.paraId : void 0,
2225
+ parentParaId: typeof entry.metadata.parentParaId === "string" ? entry.metadata.parentParaId : void 0,
2226
+ durableId: typeof entry.metadata.durableId === "string" ? entry.metadata.durableId : void 0,
2227
+ initials: typeof entry.metadata.initials === "string" ? entry.metadata.initials : void 0
2228
+ } : void 0
2229
+ })) : [
2230
+ {
2231
+ entryId: `${String(record.commentId ?? "comment")}-entry-1`,
2232
+ authorId,
2233
+ body: typeof record.body === "string" ? record.body : "",
2234
+ createdAt
2235
+ }
2236
+ ];
2237
+ const resolution = isRecord(record.resolution) ? {
2238
+ resolvedAt: typeof record.resolution.resolvedAt === "string" ? record.resolution.resolvedAt : typeof record.resolvedAt === "string" ? record.resolvedAt : createdAt,
2239
+ resolvedBy: typeof record.resolution.resolvedBy === "string" && record.resolution.resolvedBy.length > 0 ? record.resolution.resolvedBy : authorId
2240
+ } : typeof record.resolvedAt === "string" ? {
2241
+ resolvedAt: record.resolvedAt,
2242
+ resolvedBy: authorId
2243
+ } : void 0;
2244
+ const normalizedStatus = typeof record.status === "string" ? record.status : record.anchor && isRecord(record.anchor) && record.anchor.kind === "detached" ? "detached" : resolution || record.isResolved ? "resolved" : "open";
2245
+ return {
2246
+ commentId: typeof record.commentId === "string" && record.commentId.length > 0 ? record.commentId : "comment-generated",
2247
+ anchor: isRecord(record.anchor) && typeof record.anchor.kind === "string" ? record.anchor : createDetachedAnchor({ from: 0, to: 0 }, "importAmbiguity"),
2248
+ createdAt,
2249
+ createdBy: authorId,
2250
+ authorId,
2251
+ body: entries.map((entry) => entry.body).join("\n"),
2252
+ entries,
2253
+ status: normalizedStatus === "resolved" || normalizedStatus === "detached" ? normalizedStatus : "open",
2254
+ resolution,
2255
+ resolvedAt: resolution?.resolvedAt,
2256
+ warningIds: Array.isArray(record.warningIds) ? record.warningIds.filter((warningId) => typeof warningId === "string") : [],
2257
+ isResolved: normalizedStatus === "resolved",
2258
+ metadata: isRecord(record.metadata) ? {
2259
+ source: record.metadata.source === "import" || record.metadata.source === "runtime" ? record.metadata.source : void 0,
2260
+ rootOoxmlCommentId: typeof record.metadata.rootOoxmlCommentId === "string" ? record.metadata.rootOoxmlCommentId : void 0,
2261
+ rootParaId: typeof record.metadata.rootParaId === "string" ? record.metadata.rootParaId : void 0
2262
+ } : void 0
2263
+ };
2264
+ }
2265
+ // Annotate the CommonJS export names for ESM import in node:
2266
+ 0 && (module.exports = {
2267
+ createCanonicalDocumentId,
2268
+ createDefaultCanonicalDocument,
2269
+ createEditorState,
2270
+ createEmptyCompatibilityReport,
2271
+ createEmptyReviewStore,
2272
+ createPersistedEditorSnapshot,
2273
+ createSelectionSnapshot,
2274
+ deriveDocumentStats,
2275
+ deriveRenderSnapshot,
2276
+ normalizeCommentThreadRecord
2277
+ });
2278
+ //# sourceMappingURL=editor-state.cjs.map