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