@open-mercato/documents 0.6.8-develop.7016.1.4ed7b1e49d

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 (602) hide show
  1. package/README.md +88 -0
  2. package/build.mjs +23 -0
  3. package/dist/index.js +5 -0
  4. package/dist/index.js.map +7 -0
  5. package/dist/modules/documents/acl.js +15 -0
  6. package/dist/modules/documents/acl.js.map +7 -0
  7. package/dist/modules/documents/api/[id]/archive/route.js +116 -0
  8. package/dist/modules/documents/api/[id]/archive/route.js.map +7 -0
  9. package/dist/modules/documents/api/[id]/attachments/[attachmentId]/route.js +155 -0
  10. package/dist/modules/documents/api/[id]/attachments/[attachmentId]/route.js.map +7 -0
  11. package/dist/modules/documents/api/[id]/attachments/route.js +153 -0
  12. package/dist/modules/documents/api/[id]/attachments/route.js.map +7 -0
  13. package/dist/modules/documents/api/[id]/collab-token/route.js +180 -0
  14. package/dist/modules/documents/api/[id]/collab-token/route.js.map +7 -0
  15. package/dist/modules/documents/api/[id]/comments/access-check/route.js +86 -0
  16. package/dist/modules/documents/api/[id]/comments/access-check/route.js.map +7 -0
  17. package/dist/modules/documents/api/[id]/comments/route.js +387 -0
  18. package/dist/modules/documents/api/[id]/comments/route.js.map +7 -0
  19. package/dist/modules/documents/api/[id]/content/route.js +143 -0
  20. package/dist/modules/documents/api/[id]/content/route.js.map +7 -0
  21. package/dist/modules/documents/api/[id]/duplicate/route.js +200 -0
  22. package/dist/modules/documents/api/[id]/duplicate/route.js.map +7 -0
  23. package/dist/modules/documents/api/[id]/export/route.js +421 -0
  24. package/dist/modules/documents/api/[id]/export/route.js.map +7 -0
  25. package/dist/modules/documents/api/[id]/favorite/route.js +96 -0
  26. package/dist/modules/documents/api/[id]/favorite/route.js.map +7 -0
  27. package/dist/modules/documents/api/[id]/links/[linkId]/route.js +85 -0
  28. package/dist/modules/documents/api/[id]/links/[linkId]/route.js.map +7 -0
  29. package/dist/modules/documents/api/[id]/links/route.js +257 -0
  30. package/dist/modules/documents/api/[id]/links/route.js.map +7 -0
  31. package/dist/modules/documents/api/[id]/principals/route.js +299 -0
  32. package/dist/modules/documents/api/[id]/principals/route.js.map +7 -0
  33. package/dist/modules/documents/api/[id]/route.js +246 -0
  34. package/dist/modules/documents/api/[id]/route.js.map +7 -0
  35. package/dist/modules/documents/api/[id]/shares/route.js +335 -0
  36. package/dist/modules/documents/api/[id]/shares/route.js.map +7 -0
  37. package/dist/modules/documents/api/[id]/unarchive/route.js +39 -0
  38. package/dist/modules/documents/api/[id]/unarchive/route.js.map +7 -0
  39. package/dist/modules/documents/api/[id]/versions/[versionId]/restore/route.js +133 -0
  40. package/dist/modules/documents/api/[id]/versions/[versionId]/restore/route.js.map +7 -0
  41. package/dist/modules/documents/api/[id]/versions/[versionId]/route.js +93 -0
  42. package/dist/modules/documents/api/[id]/versions/[versionId]/route.js.map +7 -0
  43. package/dist/modules/documents/api/[id]/versions/route.js +193 -0
  44. package/dist/modules/documents/api/[id]/versions/route.js.map +7 -0
  45. package/dist/modules/documents/api/[id]/watch/route.js +97 -0
  46. package/dist/modules/documents/api/[id]/watch/route.js.map +7 -0
  47. package/dist/modules/documents/api/_commands.js +34 -0
  48. package/dist/modules/documents/api/_commands.js.map +7 -0
  49. package/dist/modules/documents/api/_shared.js +490 -0
  50. package/dist/modules/documents/api/_shared.js.map +7 -0
  51. package/dist/modules/documents/api/folders/route.js +256 -0
  52. package/dist/modules/documents/api/folders/route.js.map +7 -0
  53. package/dist/modules/documents/api/instantiate/route.js +108 -0
  54. package/dist/modules/documents/api/instantiate/route.js.map +7 -0
  55. package/dist/modules/documents/api/route.js +322 -0
  56. package/dist/modules/documents/api/route.js.map +7 -0
  57. package/dist/modules/documents/api/templates/[templateId]/preview/route.js +94 -0
  58. package/dist/modules/documents/api/templates/[templateId]/preview/route.js.map +7 -0
  59. package/dist/modules/documents/api/templates/[templateId]/route.js +82 -0
  60. package/dist/modules/documents/api/templates/[templateId]/route.js.map +7 -0
  61. package/dist/modules/documents/api/templates/route.js +344 -0
  62. package/dist/modules/documents/api/templates/route.js.map +7 -0
  63. package/dist/modules/documents/backend/documents/DocumentsPageClient.js +160 -0
  64. package/dist/modules/documents/backend/documents/DocumentsPageClient.js.map +7 -0
  65. package/dist/modules/documents/backend/documents/DocumentsTable.js +143 -0
  66. package/dist/modules/documents/backend/documents/DocumentsTable.js.map +7 -0
  67. package/dist/modules/documents/backend/documents/FolderDialog.js +55 -0
  68. package/dist/modules/documents/backend/documents/FolderDialog.js.map +7 -0
  69. package/dist/modules/documents/backend/documents/FolderTree.js +40 -0
  70. package/dist/modules/documents/backend/documents/FolderTree.js.map +7 -0
  71. package/dist/modules/documents/backend/documents/MoveDocumentDialog.js +64 -0
  72. package/dist/modules/documents/backend/documents/MoveDocumentDialog.js.map +7 -0
  73. package/dist/modules/documents/backend/documents/[id]/CommentAnchorNavigation.js +77 -0
  74. package/dist/modules/documents/backend/documents/[id]/CommentAnchorNavigation.js.map +7 -0
  75. package/dist/modules/documents/backend/documents/[id]/CommentComposer.js +126 -0
  76. package/dist/modules/documents/backend/documents/[id]/CommentComposer.js.map +7 -0
  77. package/dist/modules/documents/backend/documents/[id]/CommentThreadList.js +88 -0
  78. package/dist/modules/documents/backend/documents/[id]/CommentThreadList.js.map +7 -0
  79. package/dist/modules/documents/backend/documents/[id]/CommentsRail.js +123 -0
  80. package/dist/modules/documents/backend/documents/[id]/CommentsRail.js.map +7 -0
  81. package/dist/modules/documents/backend/documents/[id]/DocumentCanvas.js +91 -0
  82. package/dist/modules/documents/backend/documents/[id]/DocumentCanvas.js.map +7 -0
  83. package/dist/modules/documents/backend/documents/[id]/DocumentEditorErrorBoundary.js +27 -0
  84. package/dist/modules/documents/backend/documents/[id]/DocumentEditorErrorBoundary.js.map +7 -0
  85. package/dist/modules/documents/backend/documents/[id]/DocumentEditorIsland.js +50 -0
  86. package/dist/modules/documents/backend/documents/[id]/DocumentEditorIsland.js.map +7 -0
  87. package/dist/modules/documents/backend/documents/[id]/DocumentEditorSurface.js +168 -0
  88. package/dist/modules/documents/backend/documents/[id]/DocumentEditorSurface.js.map +7 -0
  89. package/dist/modules/documents/backend/documents/[id]/DocumentNavigator.js +129 -0
  90. package/dist/modules/documents/backend/documents/[id]/DocumentNavigator.js.map +7 -0
  91. package/dist/modules/documents/backend/documents/[id]/DocumentPageClient.js +429 -0
  92. package/dist/modules/documents/backend/documents/[id]/DocumentPageClient.js.map +7 -0
  93. package/dist/modules/documents/backend/documents/[id]/EditorColorTools.js +68 -0
  94. package/dist/modules/documents/backend/documents/[id]/EditorColorTools.js.map +7 -0
  95. package/dist/modules/documents/backend/documents/[id]/EditorStatusPresence.js +69 -0
  96. package/dist/modules/documents/backend/documents/[id]/EditorStatusPresence.js.map +7 -0
  97. package/dist/modules/documents/backend/documents/[id]/EditorToolbar.js +151 -0
  98. package/dist/modules/documents/backend/documents/[id]/EditorToolbar.js.map +7 -0
  99. package/dist/modules/documents/backend/documents/[id]/ExportMenu.js +121 -0
  100. package/dist/modules/documents/backend/documents/[id]/ExportMenu.js.map +7 -0
  101. package/dist/modules/documents/backend/documents/[id]/MentionPicker.js +114 -0
  102. package/dist/modules/documents/backend/documents/[id]/MentionPicker.js.map +7 -0
  103. package/dist/modules/documents/backend/documents/[id]/OutlinePane.js +70 -0
  104. package/dist/modules/documents/backend/documents/[id]/OutlinePane.js.map +7 -0
  105. package/dist/modules/documents/backend/documents/[id]/RecordFieldsDialog.js +157 -0
  106. package/dist/modules/documents/backend/documents/[id]/RecordFieldsDialog.js.map +7 -0
  107. package/dist/modules/documents/backend/documents/[id]/RelatedRecordsPanel.js +266 -0
  108. package/dist/modules/documents/backend/documents/[id]/RelatedRecordsPanel.js.map +7 -0
  109. package/dist/modules/documents/backend/documents/[id]/VersionHistoryPanel.js +227 -0
  110. package/dist/modules/documents/backend/documents/[id]/VersionHistoryPanel.js.map +7 -0
  111. package/dist/modules/documents/backend/documents/[id]/VersionPreviewDialog.js +157 -0
  112. package/dist/modules/documents/backend/documents/[id]/VersionPreviewDialog.js.map +7 -0
  113. package/dist/modules/documents/backend/documents/[id]/commentTypes.js +150 -0
  114. package/dist/modules/documents/backend/documents/[id]/commentTypes.js.map +7 -0
  115. package/dist/modules/documents/backend/documents/[id]/componentCapabilities.js +13 -0
  116. package/dist/modules/documents/backend/documents/[id]/componentCapabilities.js.map +7 -0
  117. package/dist/modules/documents/backend/documents/[id]/documentPagination.js +295 -0
  118. package/dist/modules/documents/backend/documents/[id]/documentPagination.js.map +7 -0
  119. package/dist/modules/documents/backend/documents/[id]/editorPresenceStyles.js +81 -0
  120. package/dist/modules/documents/backend/documents/[id]/editorPresenceStyles.js.map +7 -0
  121. package/dist/modules/documents/backend/documents/[id]/editorTypes.js +52 -0
  122. package/dist/modules/documents/backend/documents/[id]/editorTypes.js.map +7 -0
  123. package/dist/modules/documents/backend/documents/[id]/page.js +10 -0
  124. package/dist/modules/documents/backend/documents/[id]/page.js.map +7 -0
  125. package/dist/modules/documents/backend/documents/[id]/page.meta.js +16 -0
  126. package/dist/modules/documents/backend/documents/[id]/page.meta.js.map +7 -0
  127. package/dist/modules/documents/backend/documents/[id]/relatedRecordModel.js +38 -0
  128. package/dist/modules/documents/backend/documents/[id]/relatedRecordModel.js.map +7 -0
  129. package/dist/modules/documents/backend/documents/[id]/restoreVersion.js +33 -0
  130. package/dist/modules/documents/backend/documents/[id]/restoreVersion.js.map +7 -0
  131. package/dist/modules/documents/backend/documents/[id]/useDocumentCollaboration.js +392 -0
  132. package/dist/modules/documents/backend/documents/[id]/useDocumentCollaboration.js.map +7 -0
  133. package/dist/modules/documents/backend/documents/[id]/useDocumentComments.js +253 -0
  134. package/dist/modules/documents/backend/documents/[id]/useDocumentComments.js.map +7 -0
  135. package/dist/modules/documents/backend/documents/[id]/useDocumentEditor.js +149 -0
  136. package/dist/modules/documents/backend/documents/[id]/useDocumentEditor.js.map +7 -0
  137. package/dist/modules/documents/backend/documents/[id]/useDocumentTitle.js +82 -0
  138. package/dist/modules/documents/backend/documents/[id]/useDocumentTitle.js.map +7 -0
  139. package/dist/modules/documents/backend/documents/[id]/useEditorInsertions.js +144 -0
  140. package/dist/modules/documents/backend/documents/[id]/useEditorInsertions.js.map +7 -0
  141. package/dist/modules/documents/backend/documents/[id]/useFallbackContentPersistence.js +237 -0
  142. package/dist/modules/documents/backend/documents/[id]/useFallbackContentPersistence.js.map +7 -0
  143. package/dist/modules/documents/backend/documents/[id]/useMentionPicker.js +216 -0
  144. package/dist/modules/documents/backend/documents/[id]/useMentionPicker.js.map +7 -0
  145. package/dist/modules/documents/backend/documents/[id]/versionHistoryModel.js +25 -0
  146. package/dist/modules/documents/backend/documents/[id]/versionHistoryModel.js.map +7 -0
  147. package/dist/modules/documents/backend/documents/components/EntityPicker.js +156 -0
  148. package/dist/modules/documents/backend/documents/components/EntityPicker.js.map +7 -0
  149. package/dist/modules/documents/backend/documents/components/EntityPickerResults.js +46 -0
  150. package/dist/modules/documents/backend/documents/components/EntityPickerResults.js.map +7 -0
  151. package/dist/modules/documents/backend/documents/components/NewFromTemplateDialog.js +127 -0
  152. package/dist/modules/documents/backend/documents/components/NewFromTemplateDialog.js.map +7 -0
  153. package/dist/modules/documents/backend/documents/components/PrincipalPicker.js +84 -0
  154. package/dist/modules/documents/backend/documents/components/PrincipalPicker.js.map +7 -0
  155. package/dist/modules/documents/backend/documents/components/ShareDialog.js +77 -0
  156. package/dist/modules/documents/backend/documents/components/ShareDialog.js.map +7 -0
  157. package/dist/modules/documents/backend/documents/components/ShareDialogAddForm.js +93 -0
  158. package/dist/modules/documents/backend/documents/components/ShareDialogAddForm.js.map +7 -0
  159. package/dist/modules/documents/backend/documents/components/ShareDialogList.js +82 -0
  160. package/dist/modules/documents/backend/documents/components/ShareDialogList.js.map +7 -0
  161. package/dist/modules/documents/backend/documents/components/TemplateBodyEditor.js +96 -0
  162. package/dist/modules/documents/backend/documents/components/TemplateBodyEditor.js.map +7 -0
  163. package/dist/modules/documents/backend/documents/components/TemplateEditorDialog.js +169 -0
  164. package/dist/modules/documents/backend/documents/components/TemplateEditorDialog.js.map +7 -0
  165. package/dist/modules/documents/backend/documents/components/TemplatePreview.js +38 -0
  166. package/dist/modules/documents/backend/documents/components/TemplatePreview.js.map +7 -0
  167. package/dist/modules/documents/backend/documents/components/TemplateSlotFields.js +69 -0
  168. package/dist/modules/documents/backend/documents/components/TemplateSlotFields.js.map +7 -0
  169. package/dist/modules/documents/backend/documents/components/TemplateSlotsEditor.js +71 -0
  170. package/dist/modules/documents/backend/documents/components/TemplateSlotsEditor.js.map +7 -0
  171. package/dist/modules/documents/backend/documents/components/principalPickerModel.js +63 -0
  172. package/dist/modules/documents/backend/documents/components/principalPickerModel.js.map +7 -0
  173. package/dist/modules/documents/backend/documents/components/shareDialogModel.js +68 -0
  174. package/dist/modules/documents/backend/documents/components/shareDialogModel.js.map +7 -0
  175. package/dist/modules/documents/backend/documents/components/templateUi.js +89 -0
  176. package/dist/modules/documents/backend/documents/components/templateUi.js.map +7 -0
  177. package/dist/modules/documents/backend/documents/components/useAvailableEntityRegistry.js +30 -0
  178. package/dist/modules/documents/backend/documents/components/useAvailableEntityRegistry.js.map +7 -0
  179. package/dist/modules/documents/backend/documents/components/useEntitySearch.js +191 -0
  180. package/dist/modules/documents/backend/documents/components/useEntitySearch.js.map +7 -0
  181. package/dist/modules/documents/backend/documents/components/usePrincipalPicker.js +221 -0
  182. package/dist/modules/documents/backend/documents/components/usePrincipalPicker.js.map +7 -0
  183. package/dist/modules/documents/backend/documents/components/useShareDialog.js +236 -0
  184. package/dist/modules/documents/backend/documents/components/useShareDialog.js.map +7 -0
  185. package/dist/modules/documents/backend/documents/components/useTemplateDetail.js +49 -0
  186. package/dist/modules/documents/backend/documents/components/useTemplateDetail.js.map +7 -0
  187. package/dist/modules/documents/backend/documents/components/useTemplateInstantiation.js +234 -0
  188. package/dist/modules/documents/backend/documents/components/useTemplateInstantiation.js.map +7 -0
  189. package/dist/modules/documents/backend/documents/documentUi.js +106 -0
  190. package/dist/modules/documents/backend/documents/documentUi.js.map +7 -0
  191. package/dist/modules/documents/backend/documents/documentsListTypes.js +132 -0
  192. package/dist/modules/documents/backend/documents/documentsListTypes.js.map +7 -0
  193. package/dist/modules/documents/backend/documents/page.js +9 -0
  194. package/dist/modules/documents/backend/documents/page.js.map +7 -0
  195. package/dist/modules/documents/backend/documents/page.meta.js +26 -0
  196. package/dist/modules/documents/backend/documents/page.meta.js.map +7 -0
  197. package/dist/modules/documents/backend/documents/templates/TemplatesPageClient.js +91 -0
  198. package/dist/modules/documents/backend/documents/templates/TemplatesPageClient.js.map +7 -0
  199. package/dist/modules/documents/backend/documents/templates/TemplatesTable.js +58 -0
  200. package/dist/modules/documents/backend/documents/templates/TemplatesTable.js.map +7 -0
  201. package/dist/modules/documents/backend/documents/templates/page.js +9 -0
  202. package/dist/modules/documents/backend/documents/templates/page.js.map +7 -0
  203. package/dist/modules/documents/backend/documents/templates/page.meta.js +34 -0
  204. package/dist/modules/documents/backend/documents/templates/page.meta.js.map +7 -0
  205. package/dist/modules/documents/backend/documents/templates/useTemplatesPage.js +139 -0
  206. package/dist/modules/documents/backend/documents/templates/useTemplatesPage.js.map +7 -0
  207. package/dist/modules/documents/backend/documents/useDocumentsList.js +314 -0
  208. package/dist/modules/documents/backend/documents/useDocumentsList.js.map +7 -0
  209. package/dist/modules/documents/ce.js +8 -0
  210. package/dist/modules/documents/ce.js.map +7 -0
  211. package/dist/modules/documents/commands/aggregate.js +99 -0
  212. package/dist/modules/documents/commands/aggregate.js.map +7 -0
  213. package/dist/modules/documents/commands/attachments.js +252 -0
  214. package/dist/modules/documents/commands/attachments.js.map +7 -0
  215. package/dist/modules/documents/commands/comments.js +782 -0
  216. package/dist/modules/documents/commands/comments.js.map +7 -0
  217. package/dist/modules/documents/commands/content.js +238 -0
  218. package/dist/modules/documents/commands/content.js.map +7 -0
  219. package/dist/modules/documents/commands/document-crud.js +505 -0
  220. package/dist/modules/documents/commands/document-crud.js.map +7 -0
  221. package/dist/modules/documents/commands/documents.js +473 -0
  222. package/dist/modules/documents/commands/documents.js.map +7 -0
  223. package/dist/modules/documents/commands/duplicate.js +640 -0
  224. package/dist/modules/documents/commands/duplicate.js.map +7 -0
  225. package/dist/modules/documents/commands/favorites.js +150 -0
  226. package/dist/modules/documents/commands/favorites.js.map +7 -0
  227. package/dist/modules/documents/commands/folders.js +420 -0
  228. package/dist/modules/documents/commands/folders.js.map +7 -0
  229. package/dist/modules/documents/commands/index.js +64 -0
  230. package/dist/modules/documents/commands/index.js.map +7 -0
  231. package/dist/modules/documents/commands/interceptors.js +300 -0
  232. package/dist/modules/documents/commands/interceptors.js.map +7 -0
  233. package/dist/modules/documents/commands/lifecycle.js +249 -0
  234. package/dist/modules/documents/commands/lifecycle.js.map +7 -0
  235. package/dist/modules/documents/commands/links.js +410 -0
  236. package/dist/modules/documents/commands/links.js.map +7 -0
  237. package/dist/modules/documents/commands/mutation-helpers.js +42 -0
  238. package/dist/modules/documents/commands/mutation-helpers.js.map +7 -0
  239. package/dist/modules/documents/commands/projection-types.js +1 -0
  240. package/dist/modules/documents/commands/projection-types.js.map +7 -0
  241. package/dist/modules/documents/commands/shared.js +143 -0
  242. package/dist/modules/documents/commands/shared.js.map +7 -0
  243. package/dist/modules/documents/commands/shares.js +527 -0
  244. package/dist/modules/documents/commands/shares.js.map +7 -0
  245. package/dist/modules/documents/commands/side-effects.js +103 -0
  246. package/dist/modules/documents/commands/side-effects.js.map +7 -0
  247. package/dist/modules/documents/commands/templates.js +461 -0
  248. package/dist/modules/documents/commands/templates.js.map +7 -0
  249. package/dist/modules/documents/commands/versions.js +432 -0
  250. package/dist/modules/documents/commands/versions.js.map +7 -0
  251. package/dist/modules/documents/commands/watchers.js +164 -0
  252. package/dist/modules/documents/commands/watchers.js.map +7 -0
  253. package/dist/modules/documents/data/entities.js +653 -0
  254. package/dist/modules/documents/data/entities.js.map +7 -0
  255. package/dist/modules/documents/data/extensions.js +44 -0
  256. package/dist/modules/documents/data/extensions.js.map +7 -0
  257. package/dist/modules/documents/data/validators.js +219 -0
  258. package/dist/modules/documents/data/validators.js.map +7 -0
  259. package/dist/modules/documents/di.js +35 -0
  260. package/dist/modules/documents/di.js.map +7 -0
  261. package/dist/modules/documents/encryption.js +12 -0
  262. package/dist/modules/documents/encryption.js.map +7 -0
  263. package/dist/modules/documents/events.js +27 -0
  264. package/dist/modules/documents/events.js.map +7 -0
  265. package/dist/modules/documents/index.js +19 -0
  266. package/dist/modules/documents/index.js.map +7 -0
  267. package/dist/modules/documents/lib/attachmentServicePort.js +30 -0
  268. package/dist/modules/documents/lib/attachmentServicePort.js.map +7 -0
  269. package/dist/modules/documents/lib/capabilities.js +32 -0
  270. package/dist/modules/documents/lib/capabilities.js.map +7 -0
  271. package/dist/modules/documents/lib/collabCloseEvents.js +17 -0
  272. package/dist/modules/documents/lib/collabCloseEvents.js.map +7 -0
  273. package/dist/modules/documents/lib/collabEndpoint.js +22 -0
  274. package/dist/modules/documents/lib/collabEndpoint.js.map +7 -0
  275. package/dist/modules/documents/lib/collabMaterializer.js +107 -0
  276. package/dist/modules/documents/lib/collabMaterializer.js.map +7 -0
  277. package/dist/modules/documents/lib/collabToken.js +120 -0
  278. package/dist/modules/documents/lib/collabToken.js.map +7 -0
  279. package/dist/modules/documents/lib/collaborationAwareness.js +68 -0
  280. package/dist/modules/documents/lib/collaborationAwareness.js.map +7 -0
  281. package/dist/modules/documents/lib/commentAnchors.js +15 -0
  282. package/dist/modules/documents/lib/commentAnchors.js.map +7 -0
  283. package/dist/modules/documents/lib/constants.js +25 -0
  284. package/dist/modules/documents/lib/constants.js.map +7 -0
  285. package/dist/modules/documents/lib/contentService.js +248 -0
  286. package/dist/modules/documents/lib/contentService.js.map +7 -0
  287. package/dist/modules/documents/lib/displayLabels.js +23 -0
  288. package/dist/modules/documents/lib/displayLabels.js.map +7 -0
  289. package/dist/modules/documents/lib/docxRenderer.js +601 -0
  290. package/dist/modules/documents/lib/docxRenderer.js.map +7 -0
  291. package/dist/modules/documents/lib/duplicateContent.js +22 -0
  292. package/dist/modules/documents/lib/duplicateContent.js.map +7 -0
  293. package/dist/modules/documents/lib/editorConfig.js +287 -0
  294. package/dist/modules/documents/lib/editorConfig.js.map +7 -0
  295. package/dist/modules/documents/lib/entityLinks.js +148 -0
  296. package/dist/modules/documents/lib/entityLinks.js.map +7 -0
  297. package/dist/modules/documents/lib/entityRegistry.js +258 -0
  298. package/dist/modules/documents/lib/entityRegistry.js.map +7 -0
  299. package/dist/modules/documents/lib/entityRegistry.server.js +189 -0
  300. package/dist/modules/documents/lib/entityRegistry.server.js.map +7 -0
  301. package/dist/modules/documents/lib/entityRegistryAvailability.server.js +9 -0
  302. package/dist/modules/documents/lib/entityRegistryAvailability.server.js.map +7 -0
  303. package/dist/modules/documents/lib/entitySuggestion.js +50 -0
  304. package/dist/modules/documents/lib/entitySuggestion.js.map +7 -0
  305. package/dist/modules/documents/lib/favorites.js +22 -0
  306. package/dist/modules/documents/lib/favorites.js.map +7 -0
  307. package/dist/modules/documents/lib/folderHierarchySerialization.js +19 -0
  308. package/dist/modules/documents/lib/folderHierarchySerialization.js.map +7 -0
  309. package/dist/modules/documents/lib/historyLimits.js +100 -0
  310. package/dist/modules/documents/lib/historyLimits.js.map +7 -0
  311. package/dist/modules/documents/lib/historyPolicy.js +14 -0
  312. package/dist/modules/documents/lib/historyPolicy.js.map +7 -0
  313. package/dist/modules/documents/lib/organizationAccess.js +17 -0
  314. package/dist/modules/documents/lib/organizationAccess.js.map +7 -0
  315. package/dist/modules/documents/lib/pdfHtml.js +62 -0
  316. package/dist/modules/documents/lib/pdfHtml.js.map +7 -0
  317. package/dist/modules/documents/lib/pdfRenderer.js +284 -0
  318. package/dist/modules/documents/lib/pdfRenderer.js.map +7 -0
  319. package/dist/modules/documents/lib/permissions.js +222 -0
  320. package/dist/modules/documents/lib/permissions.js.map +7 -0
  321. package/dist/modules/documents/lib/platformServices.js +35 -0
  322. package/dist/modules/documents/lib/platformServices.js.map +7 -0
  323. package/dist/modules/documents/lib/recordFieldInsertion.js +58 -0
  324. package/dist/modules/documents/lib/recordFieldInsertion.js.map +7 -0
  325. package/dist/modules/documents/lib/requestBody.js +80 -0
  326. package/dist/modules/documents/lib/requestBody.js.map +7 -0
  327. package/dist/modules/documents/lib/resourceLimits.js +62 -0
  328. package/dist/modules/documents/lib/resourceLimits.js.map +7 -0
  329. package/dist/modules/documents/lib/shareCounts.js +25 -0
  330. package/dist/modules/documents/lib/shareCounts.js.map +7 -0
  331. package/dist/modules/documents/lib/templateFill.js +84 -0
  332. package/dist/modules/documents/lib/templateFill.js.map +7 -0
  333. package/dist/modules/documents/lib/templateInstantiation.js +147 -0
  334. package/dist/modules/documents/lib/templateInstantiation.js.map +7 -0
  335. package/dist/modules/documents/lib/templatePreviewDigest.js +82 -0
  336. package/dist/modules/documents/lib/templatePreviewDigest.js.map +7 -0
  337. package/dist/modules/documents/lib/templateSeeds.js +201 -0
  338. package/dist/modules/documents/lib/templateSeeds.js.map +7 -0
  339. package/dist/modules/documents/lib/userLabels.js +37 -0
  340. package/dist/modules/documents/lib/userLabels.js.map +7 -0
  341. package/dist/modules/documents/lib/versionContent.js +131 -0
  342. package/dist/modules/documents/lib/versionContent.js.map +7 -0
  343. package/dist/modules/documents/lib/versionLabels.js +12 -0
  344. package/dist/modules/documents/lib/versionLabels.js.map +7 -0
  345. package/dist/modules/documents/lib/versioning.js +14 -0
  346. package/dist/modules/documents/lib/versioning.js.map +7 -0
  347. package/dist/modules/documents/lib/visibility.js +422 -0
  348. package/dist/modules/documents/lib/visibility.js.map +7 -0
  349. package/dist/modules/documents/lib/watchers.js +106 -0
  350. package/dist/modules/documents/lib/watchers.js.map +7 -0
  351. package/dist/modules/documents/migrations/Migration20260708163836_documents.js +44 -0
  352. package/dist/modules/documents/migrations/Migration20260708163836_documents.js.map +7 -0
  353. package/dist/modules/documents/migrations/Migration20260709164720_documents.js +17 -0
  354. package/dist/modules/documents/migrations/Migration20260709164720_documents.js.map +7 -0
  355. package/dist/modules/documents/migrations/Migration20260710002318_documents.js +32 -0
  356. package/dist/modules/documents/migrations/Migration20260710002318_documents.js.map +7 -0
  357. package/dist/modules/documents/migrations/Migration20260710071003_documents.js +13 -0
  358. package/dist/modules/documents/migrations/Migration20260710071003_documents.js.map +7 -0
  359. package/dist/modules/documents/migrations/Migration20260712120000_documents.js +13 -0
  360. package/dist/modules/documents/migrations/Migration20260712120000_documents.js.map +7 -0
  361. package/dist/modules/documents/migrations/Migration20260712183000_documents.js +14 -0
  362. package/dist/modules/documents/migrations/Migration20260712183000_documents.js.map +7 -0
  363. package/dist/modules/documents/migrations/Migration20260713092156_documents.js +29 -0
  364. package/dist/modules/documents/migrations/Migration20260713092156_documents.js.map +7 -0
  365. package/dist/modules/documents/migrations/Migration20260717000000_documents.js +37 -0
  366. package/dist/modules/documents/migrations/Migration20260717000000_documents.js.map +7 -0
  367. package/dist/modules/documents/notifications.js +47 -0
  368. package/dist/modules/documents/notifications.js.map +7 -0
  369. package/dist/modules/documents/search.js +101 -0
  370. package/dist/modules/documents/search.js.map +7 -0
  371. package/dist/modules/documents/setup.js +19 -0
  372. package/dist/modules/documents/setup.js.map +7 -0
  373. package/dist/modules/documents/widgets/injection/related-documents/LinkDocumentDialog.js +214 -0
  374. package/dist/modules/documents/widgets/injection/related-documents/LinkDocumentDialog.js.map +7 -0
  375. package/dist/modules/documents/widgets/injection/related-documents/context.js +84 -0
  376. package/dist/modules/documents/widgets/injection/related-documents/context.js.map +7 -0
  377. package/dist/modules/documents/widgets/injection/related-documents/useRelatedDocuments.js +98 -0
  378. package/dist/modules/documents/widgets/injection/related-documents/useRelatedDocuments.js.map +7 -0
  379. package/dist/modules/documents/widgets/injection/related-documents/widget.client.js +83 -0
  380. package/dist/modules/documents/widgets/injection/related-documents/widget.client.js.map +7 -0
  381. package/dist/modules/documents/widgets/injection/related-documents/widget.js +19 -0
  382. package/dist/modules/documents/widgets/injection/related-documents/widget.js.map +7 -0
  383. package/dist/modules/documents/widgets/injection-table.js +21 -0
  384. package/dist/modules/documents/widgets/injection-table.js.map +7 -0
  385. package/dist/server/documents-collab-server.js +2260 -0
  386. package/dist/server/documents-collab-server.js.map +7 -0
  387. package/generated/entities/document/index.ts +12 -0
  388. package/generated/entities/document_attachment/index.ts +9 -0
  389. package/generated/entities/document_comment/index.ts +14 -0
  390. package/generated/entities/document_content/index.ts +11 -0
  391. package/generated/entities/document_entity_link/index.ts +19 -0
  392. package/generated/entities/document_favorite/index.ts +7 -0
  393. package/generated/entities/document_folder/index.ts +9 -0
  394. package/generated/entities/document_share/index.ts +11 -0
  395. package/generated/entities/document_template/index.ts +13 -0
  396. package/generated/entities/document_version/index.ts +9 -0
  397. package/generated/entities/document_watcher/index.ts +7 -0
  398. package/generated/entities.ids.generated.ts +21 -0
  399. package/generated/entity-fields-registry.ts +151 -0
  400. package/jest.config.cjs +34 -0
  401. package/package.json +149 -0
  402. package/server/documents-collab-server.ts +3416 -0
  403. package/src/index.ts +1 -0
  404. package/src/modules/documents/acl.ts +11 -0
  405. package/src/modules/documents/api/[id]/archive/route.ts +132 -0
  406. package/src/modules/documents/api/[id]/attachments/[attachmentId]/route.ts +166 -0
  407. package/src/modules/documents/api/[id]/attachments/route.ts +173 -0
  408. package/src/modules/documents/api/[id]/collab-token/route.ts +203 -0
  409. package/src/modules/documents/api/[id]/comments/access-check/route.ts +96 -0
  410. package/src/modules/documents/api/[id]/comments/route.ts +442 -0
  411. package/src/modules/documents/api/[id]/content/route.ts +156 -0
  412. package/src/modules/documents/api/[id]/duplicate/route.ts +231 -0
  413. package/src/modules/documents/api/[id]/export/route.ts +535 -0
  414. package/src/modules/documents/api/[id]/favorite/route.ts +110 -0
  415. package/src/modules/documents/api/[id]/links/[linkId]/route.ts +92 -0
  416. package/src/modules/documents/api/[id]/links/route.ts +301 -0
  417. package/src/modules/documents/api/[id]/principals/route.ts +375 -0
  418. package/src/modules/documents/api/[id]/route.ts +267 -0
  419. package/src/modules/documents/api/[id]/shares/route.ts +372 -0
  420. package/src/modules/documents/api/[id]/unarchive/route.ts +42 -0
  421. package/src/modules/documents/api/[id]/versions/[versionId]/restore/route.ts +152 -0
  422. package/src/modules/documents/api/[id]/versions/[versionId]/route.ts +100 -0
  423. package/src/modules/documents/api/[id]/versions/route.ts +207 -0
  424. package/src/modules/documents/api/[id]/watch/route.ts +111 -0
  425. package/src/modules/documents/api/_commands.ts +53 -0
  426. package/src/modules/documents/api/_shared.ts +676 -0
  427. package/src/modules/documents/api/folders/route.ts +287 -0
  428. package/src/modules/documents/api/instantiate/route.ts +114 -0
  429. package/src/modules/documents/api/route.ts +362 -0
  430. package/src/modules/documents/api/templates/[templateId]/preview/route.ts +97 -0
  431. package/src/modules/documents/api/templates/[templateId]/route.ts +92 -0
  432. package/src/modules/documents/api/templates/route.ts +370 -0
  433. package/src/modules/documents/backend/documents/DocumentsPageClient.tsx +150 -0
  434. package/src/modules/documents/backend/documents/DocumentsTable.tsx +168 -0
  435. package/src/modules/documents/backend/documents/FolderDialog.tsx +62 -0
  436. package/src/modules/documents/backend/documents/FolderTree.tsx +72 -0
  437. package/src/modules/documents/backend/documents/MoveDocumentDialog.tsx +70 -0
  438. package/src/modules/documents/backend/documents/[id]/CommentAnchorNavigation.ts +88 -0
  439. package/src/modules/documents/backend/documents/[id]/CommentComposer.tsx +136 -0
  440. package/src/modules/documents/backend/documents/[id]/CommentThreadList.tsx +131 -0
  441. package/src/modules/documents/backend/documents/[id]/CommentsRail.tsx +138 -0
  442. package/src/modules/documents/backend/documents/[id]/DocumentCanvas.tsx +111 -0
  443. package/src/modules/documents/backend/documents/[id]/DocumentEditorErrorBoundary.tsx +39 -0
  444. package/src/modules/documents/backend/documents/[id]/DocumentEditorIsland.tsx +50 -0
  445. package/src/modules/documents/backend/documents/[id]/DocumentEditorSurface.tsx +162 -0
  446. package/src/modules/documents/backend/documents/[id]/DocumentNavigator.tsx +129 -0
  447. package/src/modules/documents/backend/documents/[id]/DocumentPageClient.tsx +463 -0
  448. package/src/modules/documents/backend/documents/[id]/EditorColorTools.tsx +71 -0
  449. package/src/modules/documents/backend/documents/[id]/EditorStatusPresence.tsx +78 -0
  450. package/src/modules/documents/backend/documents/[id]/EditorToolbar.tsx +108 -0
  451. package/src/modules/documents/backend/documents/[id]/ExportMenu.tsx +144 -0
  452. package/src/modules/documents/backend/documents/[id]/MentionPicker.tsx +137 -0
  453. package/src/modules/documents/backend/documents/[id]/OutlinePane.tsx +98 -0
  454. package/src/modules/documents/backend/documents/[id]/RecordFieldsDialog.tsx +185 -0
  455. package/src/modules/documents/backend/documents/[id]/RelatedRecordsPanel.tsx +320 -0
  456. package/src/modules/documents/backend/documents/[id]/VersionHistoryPanel.tsx +244 -0
  457. package/src/modules/documents/backend/documents/[id]/VersionPreviewDialog.tsx +197 -0
  458. package/src/modules/documents/backend/documents/[id]/commentTypes.ts +192 -0
  459. package/src/modules/documents/backend/documents/[id]/componentCapabilities.ts +17 -0
  460. package/src/modules/documents/backend/documents/[id]/documentPagination.ts +352 -0
  461. package/src/modules/documents/backend/documents/[id]/editorPresenceStyles.ts +77 -0
  462. package/src/modules/documents/backend/documents/[id]/editorTypes.ts +84 -0
  463. package/src/modules/documents/backend/documents/[id]/page.meta.ts +12 -0
  464. package/src/modules/documents/backend/documents/[id]/page.tsx +6 -0
  465. package/src/modules/documents/backend/documents/[id]/relatedRecordModel.ts +49 -0
  466. package/src/modules/documents/backend/documents/[id]/restoreVersion.ts +49 -0
  467. package/src/modules/documents/backend/documents/[id]/useDocumentCollaboration.ts +458 -0
  468. package/src/modules/documents/backend/documents/[id]/useDocumentComments.ts +286 -0
  469. package/src/modules/documents/backend/documents/[id]/useDocumentEditor.ts +157 -0
  470. package/src/modules/documents/backend/documents/[id]/useDocumentTitle.ts +77 -0
  471. package/src/modules/documents/backend/documents/[id]/useEditorInsertions.ts +147 -0
  472. package/src/modules/documents/backend/documents/[id]/useFallbackContentPersistence.ts +277 -0
  473. package/src/modules/documents/backend/documents/[id]/useMentionPicker.ts +259 -0
  474. package/src/modules/documents/backend/documents/[id]/versionHistoryModel.ts +29 -0
  475. package/src/modules/documents/backend/documents/components/EntityPicker.tsx +171 -0
  476. package/src/modules/documents/backend/documents/components/EntityPickerResults.tsx +64 -0
  477. package/src/modules/documents/backend/documents/components/NewFromTemplateDialog.tsx +136 -0
  478. package/src/modules/documents/backend/documents/components/PrincipalPicker.tsx +90 -0
  479. package/src/modules/documents/backend/documents/components/ShareDialog.tsx +88 -0
  480. package/src/modules/documents/backend/documents/components/ShareDialogAddForm.tsx +113 -0
  481. package/src/modules/documents/backend/documents/components/ShareDialogList.tsx +117 -0
  482. package/src/modules/documents/backend/documents/components/TemplateBodyEditor.tsx +96 -0
  483. package/src/modules/documents/backend/documents/components/TemplateEditorDialog.tsx +171 -0
  484. package/src/modules/documents/backend/documents/components/TemplatePreview.tsx +43 -0
  485. package/src/modules/documents/backend/documents/components/TemplateSlotFields.tsx +72 -0
  486. package/src/modules/documents/backend/documents/components/TemplateSlotsEditor.tsx +72 -0
  487. package/src/modules/documents/backend/documents/components/principalPickerModel.ts +86 -0
  488. package/src/modules/documents/backend/documents/components/shareDialogModel.ts +94 -0
  489. package/src/modules/documents/backend/documents/components/templateUi.ts +128 -0
  490. package/src/modules/documents/backend/documents/components/useAvailableEntityRegistry.ts +43 -0
  491. package/src/modules/documents/backend/documents/components/useEntitySearch.ts +197 -0
  492. package/src/modules/documents/backend/documents/components/usePrincipalPicker.ts +165 -0
  493. package/src/modules/documents/backend/documents/components/useShareDialog.ts +267 -0
  494. package/src/modules/documents/backend/documents/components/useTemplateDetail.ts +54 -0
  495. package/src/modules/documents/backend/documents/components/useTemplateInstantiation.ts +252 -0
  496. package/src/modules/documents/backend/documents/documentUi.ts +134 -0
  497. package/src/modules/documents/backend/documents/documentsListTypes.ts +163 -0
  498. package/src/modules/documents/backend/documents/page.meta.ts +24 -0
  499. package/src/modules/documents/backend/documents/page.tsx +5 -0
  500. package/src/modules/documents/backend/documents/templates/TemplatesPageClient.tsx +93 -0
  501. package/src/modules/documents/backend/documents/templates/TemplatesTable.tsx +71 -0
  502. package/src/modules/documents/backend/documents/templates/page.meta.ts +32 -0
  503. package/src/modules/documents/backend/documents/templates/page.tsx +5 -0
  504. package/src/modules/documents/backend/documents/templates/useTemplatesPage.tsx +148 -0
  505. package/src/modules/documents/backend/documents/useDocumentsList.tsx +305 -0
  506. package/src/modules/documents/ce.ts +6 -0
  507. package/src/modules/documents/commands/aggregate.ts +128 -0
  508. package/src/modules/documents/commands/attachments.ts +309 -0
  509. package/src/modules/documents/commands/comments.ts +966 -0
  510. package/src/modules/documents/commands/content.ts +294 -0
  511. package/src/modules/documents/commands/document-crud.ts +609 -0
  512. package/src/modules/documents/commands/documents.ts +581 -0
  513. package/src/modules/documents/commands/duplicate.ts +772 -0
  514. package/src/modules/documents/commands/favorites.ts +171 -0
  515. package/src/modules/documents/commands/folders.ts +506 -0
  516. package/src/modules/documents/commands/index.ts +33 -0
  517. package/src/modules/documents/commands/interceptors.ts +402 -0
  518. package/src/modules/documents/commands/lifecycle.ts +333 -0
  519. package/src/modules/documents/commands/links.ts +486 -0
  520. package/src/modules/documents/commands/mutation-helpers.ts +48 -0
  521. package/src/modules/documents/commands/projection-types.ts +77 -0
  522. package/src/modules/documents/commands/shared.ts +219 -0
  523. package/src/modules/documents/commands/shares.ts +612 -0
  524. package/src/modules/documents/commands/side-effects.ts +130 -0
  525. package/src/modules/documents/commands/templates.ts +522 -0
  526. package/src/modules/documents/commands/versions.ts +537 -0
  527. package/src/modules/documents/commands/watchers.ts +181 -0
  528. package/src/modules/documents/data/entities.ts +631 -0
  529. package/src/modules/documents/data/extensions.ts +42 -0
  530. package/src/modules/documents/data/validators.ts +248 -0
  531. package/src/modules/documents/di.ts +33 -0
  532. package/src/modules/documents/encryption.ts +14 -0
  533. package/src/modules/documents/events.ts +23 -0
  534. package/src/modules/documents/i18n/.hardcoded-allowlist.json +9 -0
  535. package/src/modules/documents/i18n/de.json +522 -0
  536. package/src/modules/documents/i18n/en.json +522 -0
  537. package/src/modules/documents/i18n/es.json +522 -0
  538. package/src/modules/documents/i18n/ko.json +522 -0
  539. package/src/modules/documents/i18n/pl.json +522 -0
  540. package/src/modules/documents/index.ts +17 -0
  541. package/src/modules/documents/lib/attachmentServicePort.ts +94 -0
  542. package/src/modules/documents/lib/capabilities.ts +57 -0
  543. package/src/modules/documents/lib/collabCloseEvents.ts +26 -0
  544. package/src/modules/documents/lib/collabEndpoint.ts +43 -0
  545. package/src/modules/documents/lib/collabMaterializer.ts +140 -0
  546. package/src/modules/documents/lib/collabToken.ts +170 -0
  547. package/src/modules/documents/lib/collaborationAwareness.ts +102 -0
  548. package/src/modules/documents/lib/commentAnchors.ts +19 -0
  549. package/src/modules/documents/lib/constants.ts +39 -0
  550. package/src/modules/documents/lib/contentService.ts +340 -0
  551. package/src/modules/documents/lib/displayLabels.ts +31 -0
  552. package/src/modules/documents/lib/docxRenderer.ts +685 -0
  553. package/src/modules/documents/lib/duplicateContent.ts +32 -0
  554. package/src/modules/documents/lib/editorConfig.ts +371 -0
  555. package/src/modules/documents/lib/entityLinks.ts +250 -0
  556. package/src/modules/documents/lib/entityRegistry.server.ts +267 -0
  557. package/src/modules/documents/lib/entityRegistry.ts +345 -0
  558. package/src/modules/documents/lib/entityRegistryAvailability.server.ts +19 -0
  559. package/src/modules/documents/lib/entitySuggestion.ts +61 -0
  560. package/src/modules/documents/lib/favorites.ts +35 -0
  561. package/src/modules/documents/lib/folderHierarchySerialization.ts +34 -0
  562. package/src/modules/documents/lib/historyLimits.ts +154 -0
  563. package/src/modules/documents/lib/historyPolicy.ts +7 -0
  564. package/src/modules/documents/lib/organizationAccess.ts +44 -0
  565. package/src/modules/documents/lib/pdfHtml.ts +65 -0
  566. package/src/modules/documents/lib/pdfRenderer.ts +367 -0
  567. package/src/modules/documents/lib/permissions.ts +299 -0
  568. package/src/modules/documents/lib/platformServices.ts +70 -0
  569. package/src/modules/documents/lib/recordFieldInsertion.ts +72 -0
  570. package/src/modules/documents/lib/requestBody.ts +97 -0
  571. package/src/modules/documents/lib/resourceLimits.ts +94 -0
  572. package/src/modules/documents/lib/shareCounts.ts +44 -0
  573. package/src/modules/documents/lib/templateFill.ts +138 -0
  574. package/src/modules/documents/lib/templateInstantiation.ts +206 -0
  575. package/src/modules/documents/lib/templatePreviewDigest.ts +122 -0
  576. package/src/modules/documents/lib/templateSeeds.ts +248 -0
  577. package/src/modules/documents/lib/userLabels.ts +58 -0
  578. package/src/modules/documents/lib/versionContent.ts +163 -0
  579. package/src/modules/documents/lib/versionLabels.ts +9 -0
  580. package/src/modules/documents/lib/versioning.ts +29 -0
  581. package/src/modules/documents/lib/visibility.ts +610 -0
  582. package/src/modules/documents/lib/watchers.ts +129 -0
  583. package/src/modules/documents/migrations/.snapshot-open-mercato.json +2892 -0
  584. package/src/modules/documents/migrations/Migration20260708163836_documents.ts +50 -0
  585. package/src/modules/documents/migrations/Migration20260709164720_documents.ts +19 -0
  586. package/src/modules/documents/migrations/Migration20260710002318_documents.ts +35 -0
  587. package/src/modules/documents/migrations/Migration20260710071003_documents.ts +13 -0
  588. package/src/modules/documents/migrations/Migration20260712120000_documents.ts +13 -0
  589. package/src/modules/documents/migrations/Migration20260712183000_documents.ts +12 -0
  590. package/src/modules/documents/migrations/Migration20260713092156_documents.ts +43 -0
  591. package/src/modules/documents/migrations/Migration20260717000000_documents.ts +40 -0
  592. package/src/modules/documents/notifications.ts +45 -0
  593. package/src/modules/documents/search.ts +118 -0
  594. package/src/modules/documents/setup.ts +19 -0
  595. package/src/modules/documents/widgets/injection/related-documents/LinkDocumentDialog.tsx +224 -0
  596. package/src/modules/documents/widgets/injection/related-documents/context.ts +101 -0
  597. package/src/modules/documents/widgets/injection/related-documents/useRelatedDocuments.ts +112 -0
  598. package/src/modules/documents/widgets/injection/related-documents/widget.client.tsx +76 -0
  599. package/src/modules/documents/widgets/injection/related-documents/widget.ts +19 -0
  600. package/src/modules/documents/widgets/injection-table.ts +20 -0
  601. package/tsconfig.json +9 -0
  602. package/watch.mjs +6 -0
@@ -0,0 +1,685 @@
1
+ import { createRequire } from 'node:module'
2
+ import { isAbsolute } from 'node:path'
3
+ import { Worker } from 'node:worker_threads'
4
+
5
+ export const DOCX_RENDER_MAX_CONCURRENCY = 2
6
+ export const DOCX_RENDER_MAX_QUEUE = 4
7
+ export const DOCX_RENDER_ACQUIRE_TIMEOUT_MS = 2_000
8
+ export const DOCX_RENDER_TIMEOUT_MS = 20_000
9
+ export const DOCX_MAX_OUTPUT_BYTES = 25 * 1024 * 1024
10
+ export const DOCX_WORKER_CHUNK_BYTES = 64 * 1024
11
+ export const DOCX_WORKER_RESOURCE_LIMITS = Object.freeze({
12
+ maxOldGenerationSizeMb: 128,
13
+ maxYoungGenerationSizeMb: 16,
14
+ stackSizeMb: 4,
15
+ })
16
+ const DOCX_OVERLOADED_MARKER = Symbol.for('open-mercato.documents.docxRenderer.overloaded')
17
+ const DOCX_TIMEOUT_MARKER = Symbol.for('open-mercato.documents.docxRenderer.timeout')
18
+ const DOCX_OUTPUT_TOO_LARGE_MARKER = Symbol.for('open-mercato.documents.docxRenderer.outputTooLarge')
19
+ const DOCX_FAILED_MARKER = Symbol.for('open-mercato.documents.docxRenderer.failed')
20
+
21
+ export class DocxRenderOverloadedError extends Error {
22
+ readonly [DOCX_OVERLOADED_MARKER] = true
23
+ constructor() {
24
+ super('DOCX renderer is at capacity')
25
+ this.name = 'DocxRenderOverloadedError'
26
+ }
27
+ }
28
+
29
+ export class DocxRenderTimeoutError extends Error {
30
+ readonly [DOCX_TIMEOUT_MARKER] = true
31
+ constructor() {
32
+ super('DOCX renderer timed out')
33
+ this.name = 'DocxRenderTimeoutError'
34
+ }
35
+ }
36
+
37
+ export class DocxRenderOutputTooLargeError extends Error {
38
+ readonly [DOCX_OUTPUT_TOO_LARGE_MARKER] = true
39
+ constructor() {
40
+ super('DOCX renderer output exceeded its byte limit')
41
+ this.name = 'DocxRenderOutputTooLargeError'
42
+ }
43
+ }
44
+
45
+ export class DocxRenderFailedError extends Error {
46
+ readonly [DOCX_FAILED_MARKER] = true
47
+ constructor(options: { cause?: unknown } = {}) {
48
+ super('DOCX renderer failed', options)
49
+ this.name = 'DocxRenderFailedError'
50
+ }
51
+ }
52
+
53
+ function hasErrorMarker(error: unknown, marker: symbol): boolean {
54
+ return Boolean(error && typeof error === 'object' && (error as Record<symbol, unknown>)[marker] === true)
55
+ }
56
+
57
+ export const isDocxRenderOverloadedError = (error: unknown): boolean => (
58
+ error instanceof DocxRenderOverloadedError || hasErrorMarker(error, DOCX_OVERLOADED_MARKER)
59
+ )
60
+ export const isDocxRenderTimeoutError = (error: unknown): boolean => (
61
+ error instanceof DocxRenderTimeoutError || hasErrorMarker(error, DOCX_TIMEOUT_MARKER)
62
+ )
63
+ export const isDocxRenderOutputTooLargeError = (error: unknown): boolean => (
64
+ error instanceof DocxRenderOutputTooLargeError || hasErrorMarker(error, DOCX_OUTPUT_TOO_LARGE_MARKER)
65
+ )
66
+ export const isDocxRenderFailedError = (error: unknown): boolean => (
67
+ error instanceof DocxRenderFailedError || hasErrorMarker(error, DOCX_FAILED_MARKER)
68
+ )
69
+
70
+ type DocxRendererOptions = {
71
+ maxConcurrency?: number
72
+ maxQueue?: number
73
+ acquireTimeoutMs?: number
74
+ renderTimeoutMs?: number
75
+ maxOutputBytes?: number
76
+ }
77
+
78
+ export interface DocxWorker {
79
+ on(event: 'message', listener: (message: unknown) => void): unknown
80
+ on(event: 'error', listener: (error: Error) => void): unknown
81
+ on(event: 'exit', listener: (code: number) => void): unknown
82
+ terminate(): Promise<number>
83
+ }
84
+
85
+ export type DocxWorkerFactoryInput = {
86
+ html: string
87
+ modulePath: string | null
88
+ moduleSpecifier: string
89
+ requireFrom: string
90
+ maxOutputBytes: number
91
+ chunkBytes: number
92
+ }
93
+
94
+ export type DocxWorkerFactory = (input: DocxWorkerFactoryInput) => DocxWorker
95
+
96
+ type DocxRendererDeps = {
97
+ workerFactory?: DocxWorkerFactory
98
+ modulePath?: string | null
99
+ allocateOutput?: (byteLength: number) => Uint8Array
100
+ }
101
+
102
+ /**
103
+ * The worker body is a standalone source string because it is evaluated in a
104
+ * fresh `worker_threads` context that cannot import from this package.
105
+ *
106
+ * The cost of that constraint: everything inside this template is invisible to
107
+ * `tsc`, `eslint` and `ds-lint`, so a typo here is a runtime failure rather
108
+ * than a build failure. The behaviour is pinned by __tests__/docxRenderer.test.ts,
109
+ * which drives a real worker rather than only a fake — keep it that way when
110
+ * editing this string.
111
+ */
112
+ const DOCX_WORKER_SOURCE = String.raw`
113
+ const { parentPort, workerData } = require('node:worker_threads')
114
+
115
+ const VOID_TAGS = new Set(['br', 'hr', 'img', 'input'])
116
+
117
+ function attributes(source) {
118
+ const result = {}
119
+ const pattern = /([A-Za-z_:][-A-Za-z0-9_:.]*)(?:\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s"'=<>]+)))?/g
120
+ let match
121
+ while ((match = pattern.exec(source)) !== null) {
122
+ result[match[1].toLowerCase()] = match[2] ?? match[3] ?? match[4] ?? ''
123
+ }
124
+ return result
125
+ }
126
+
127
+ function parseHtml(html) {
128
+ const root = { tag: 'root', attrs: {}, children: [] }
129
+ const stack = [root]
130
+ const tokens = String(html).match(/<!--[\s\S]*?-->|<![^>]*>|<\/?[A-Za-z][^>]*>|[^<]+/g) || []
131
+ for (const token of tokens) {
132
+ if (token.startsWith('<!--') || token.startsWith('<!')) continue
133
+ if (!token.startsWith('<')) {
134
+ stack[stack.length - 1].children.push(token)
135
+ continue
136
+ }
137
+ const closing = /^<\/\s*([A-Za-z0-9-]+)/.exec(token)
138
+ if (closing) {
139
+ const tag = closing[1].toLowerCase()
140
+ while (stack.length > 1) {
141
+ const node = stack.pop()
142
+ if (node.tag === tag) break
143
+ }
144
+ continue
145
+ }
146
+ const opening = /^<\s*([A-Za-z0-9-]+)([\s\S]*?)\/?\s*>$/.exec(token)
147
+ if (!opening) continue
148
+ const tag = opening[1].toLowerCase()
149
+ const node = { tag, attrs: attributes(opening[2]), children: [] }
150
+ stack[stack.length - 1].children.push(node)
151
+ if (!VOID_TAGS.has(tag) && !/\/\s*>$/.test(token)) stack.push(node)
152
+ }
153
+ return root
154
+ }
155
+
156
+ function decode(value) {
157
+ return String(value)
158
+ .replace(/&#x([0-9a-f]+);/gi, (_match, code) => String.fromCodePoint(Number.parseInt(code, 16)))
159
+ .replace(/&#([0-9]+);/g, (_match, code) => String.fromCodePoint(Number.parseInt(code, 10)))
160
+ .replace(/&(amp|lt|gt|quot|apos|nbsp);/g, (_match, name) => ({ amp: '&', lt: '<', gt: '>', quot: '"', apos: "'", nbsp: ' ' })[name])
161
+ }
162
+
163
+ function inlineNodes(nodes, marks) {
164
+ const result = []
165
+ for (const child of Array.isArray(nodes) ? nodes : []) {
166
+ if (typeof child === 'string') {
167
+ const text = decode(child)
168
+ if (text) result.push({ type: 'text', text, marks })
169
+ continue
170
+ }
171
+ if (!child || typeof child !== 'object') continue
172
+ if (child.tag === 'br') {
173
+ result.push({ type: 'hardBreak' })
174
+ continue
175
+ }
176
+ if (child.tag === 'img') {
177
+ result.push({ type: 'image', attrs: { src: child.attrs.src || '' } })
178
+ continue
179
+ }
180
+ const markType = ({ strong: 'bold', b: 'bold', em: 'italic', i: 'italic', u: 'underline', s: 'strike', strike: 'strike', code: 'code' })[child.tag]
181
+ result.push(...inlineNodes(child.children, markType ? [...marks, { type: markType }] : marks))
182
+ }
183
+ return result
184
+ }
185
+
186
+ function blockNodes(nodes) {
187
+ const result = []
188
+ for (const child of Array.isArray(nodes) ? nodes : []) {
189
+ if (typeof child === 'string') {
190
+ if (decode(child).trim()) result.push({ type: 'paragraph', content: inlineNodes([child], []) })
191
+ continue
192
+ }
193
+ if (!child || typeof child !== 'object') continue
194
+ const align = /(?:^|;)\s*text-align\s*:\s*(left|center|right|justify)/i.exec(child.attrs.style || '')
195
+ if (child.tag === 'div' && String(child.attrs.class || '').split(/\s+/).includes('page-break')) {
196
+ result.push({ type: 'pageBreak' })
197
+ } else if (child.tag === 'p' || child.tag === 'div') {
198
+ result.push({ type: 'paragraph', attrs: { textAlign: align && align[1].toLowerCase() }, content: inlineNodes(child.children, []) })
199
+ } else if (/^h[1-6]$/.test(child.tag)) {
200
+ result.push({ type: 'heading', attrs: { level: Number(child.tag.slice(1)), textAlign: align && align[1].toLowerCase() }, content: inlineNodes(child.children, []) })
201
+ } else if (child.tag === 'ul' || child.tag === 'ol') {
202
+ result.push({
203
+ type: child.tag === 'ol' ? 'orderedList' : 'bulletList',
204
+ content: child.children.filter((item) => item && typeof item === 'object' && item.tag === 'li').map((item) => ({
205
+ type: 'listItem',
206
+ content: blockNodes(item.children).length ? blockNodes(item.children) : [{ type: 'paragraph', content: inlineNodes(item.children, []) }],
207
+ })),
208
+ })
209
+ } else if (child.tag === 'blockquote') {
210
+ result.push({ type: 'blockquote', content: inlineNodes(child.children, []) })
211
+ } else if (child.tag === 'pre') {
212
+ result.push({ type: 'codeBlock', content: inlineNodes(child.children, [{ type: 'code' }]) })
213
+ } else if (child.tag === 'hr') {
214
+ result.push({ type: 'horizontalRule' })
215
+ } else if (child.tag === 'img') {
216
+ result.push({ type: 'image', attrs: { src: child.attrs.src || '' } })
217
+ } else if (child.tag === 'table') {
218
+ const rows = []
219
+ const visitRows = (entries) => {
220
+ for (const entry of Array.isArray(entries) ? entries : []) {
221
+ if (!entry || typeof entry !== 'object') continue
222
+ if (entry.tag === 'tr') {
223
+ rows.push({
224
+ type: 'tableRow',
225
+ content: entry.children.filter((cell) => cell && typeof cell === 'object' && ['td', 'th'].includes(cell.tag)).map((cell) => ({
226
+ type: cell.tag === 'th' ? 'tableHeader' : 'tableCell',
227
+ content: blockNodes(cell.children).length ? blockNodes(cell.children) : [{ type: 'paragraph', content: inlineNodes(cell.children, []) }],
228
+ })),
229
+ })
230
+ } else visitRows(entry.children)
231
+ }
232
+ }
233
+ visitRows(child.children)
234
+ result.push({ type: 'table', content: rows })
235
+ } else {
236
+ const nested = blockNodes(child.children)
237
+ if (nested.length) result.push(...nested)
238
+ else if (inlineNodes(child.children, []).length) result.push({ type: 'paragraph', content: inlineNodes(child.children, []) })
239
+ }
240
+ }
241
+ return result
242
+ }
243
+
244
+ function htmlToDocumentJson(html) {
245
+ return { type: 'doc', content: blockNodes(parseHtml(html).children) }
246
+ }
247
+
248
+ function xml(value) {
249
+ return String(value ?? '')
250
+ .replaceAll('&', '&amp;')
251
+ .replaceAll('<', '&lt;')
252
+ .replaceAll('>', '&gt;')
253
+ .replaceAll('"', '&quot;')
254
+ .replaceAll("'", '&apos;')
255
+ }
256
+
257
+ function markProperties(marks) {
258
+ const names = new Set((Array.isArray(marks) ? marks : []).map((mark) => mark && mark.type))
259
+ return [
260
+ names.has('bold') ? '<w:b/>' : '',
261
+ names.has('italic') ? '<w:i/>' : '',
262
+ names.has('underline') ? '<w:u w:val="single"/>' : '',
263
+ names.has('strike') ? '<w:strike/>' : '',
264
+ names.has('code') ? '<w:rFonts w:ascii="Courier New" w:hAnsi="Courier New"/>' : '',
265
+ ].join('')
266
+ }
267
+
268
+ function textRun(node) {
269
+ const text = String(node && node.text || '')
270
+ const properties = markProperties(node && node.marks)
271
+ return '<w:r>' + (properties ? '<w:rPr>' + properties + '</w:rPr>' : '')
272
+ + '<w:t xml:space="preserve">' + xml(text) + '</w:t></w:r>'
273
+ }
274
+
275
+ function inlineContent(nodes, state) {
276
+ return (Array.isArray(nodes) ? nodes : []).map((node) => {
277
+ if (!node || typeof node !== 'object') return ''
278
+ if (node.type === 'text') return textRun(node)
279
+ if (node.type === 'hardBreak') return '<w:r><w:br/></w:r>'
280
+ if (node.type === 'entityRef') return textRun({ text: node.attrs && node.attrs.label || '' })
281
+ if (node.type === 'image') return imageRun(node, state)
282
+ return inlineContent(node.content, state)
283
+ }).join('')
284
+ }
285
+
286
+ function paragraphProperties(node, options) {
287
+ const properties = []
288
+ if (options && options.style) properties.push('<w:pStyle w:val="' + xml(options.style) + '"/>')
289
+ if (options && options.numberId) {
290
+ properties.push('<w:numPr><w:ilvl w:val="' + Number(options.level || 0) + '"/><w:numId w:val="' + Number(options.numberId) + '"/></w:numPr>')
291
+ }
292
+ const alignment = node && node.attrs && node.attrs.textAlign
293
+ if (['left', 'center', 'right', 'justify'].includes(alignment)) {
294
+ properties.push('<w:jc w:val="' + alignment + '"/>')
295
+ }
296
+ return properties.length ? '<w:pPr>' + properties.join('') + '</w:pPr>' : ''
297
+ }
298
+
299
+ function paragraph(node, state, options) {
300
+ return '<w:p>' + paragraphProperties(node, options) + inlineContent(node && node.content, state) + '</w:p>'
301
+ }
302
+
303
+ function imageDimensions(bytes, mimeType) {
304
+ if (mimeType === 'image/png' && bytes.length >= 24) {
305
+ return { width: bytes.readUInt32BE(16), height: bytes.readUInt32BE(20) }
306
+ }
307
+ if (mimeType === 'image/jpeg' && bytes.length >= 4) {
308
+ let offset = 2
309
+ while (offset + 8 < bytes.length) {
310
+ if (bytes[offset] !== 0xff) break
311
+ const marker = bytes[offset + 1]
312
+ offset += 2
313
+ if (marker === 0xd8 || marker === 0xd9 || marker === 0x01 || (marker >= 0xd0 && marker <= 0xd7)) continue
314
+ if (offset + 2 > bytes.length) break
315
+ const length = bytes.readUInt16BE(offset)
316
+ if (length < 2 || offset + length > bytes.length) break
317
+ if ([0xc0, 0xc1, 0xc2, 0xc3, 0xc5, 0xc6, 0xc7, 0xc9, 0xca, 0xcb, 0xcd, 0xce, 0xcf].includes(marker)) {
318
+ return { width: bytes.readUInt16BE(offset + 5), height: bytes.readUInt16BE(offset + 3) }
319
+ }
320
+ offset += length
321
+ }
322
+ }
323
+ return { width: 640, height: 480 }
324
+ }
325
+
326
+ function imageRun(node, state) {
327
+ const source = node && node.attrs && node.attrs.src
328
+ const match = typeof source === 'string' && /^data:(image\/(?:png|jpeg));base64,([A-Za-z0-9+/]+={0,2})$/.exec(source)
329
+ if (!match) return ''
330
+ const bytes = Buffer.from(match[2], 'base64')
331
+ if (bytes.length === 0 || bytes.toString('base64') !== match[2]) return ''
332
+ const extension = match[1] === 'image/png' ? 'png' : 'jpg'
333
+ const imageId = state.images.length + 1
334
+ const relationshipId = 'rId' + (imageId + 2)
335
+ const dimensions = imageDimensions(bytes, match[1])
336
+ const maxWidth = 5486400
337
+ const scale = Math.min(1, 640 / Math.max(1, dimensions.width))
338
+ const width = Math.max(9525, Math.round(dimensions.width * scale * 9525))
339
+ const height = Math.max(9525, Math.round(dimensions.height * scale * 9525))
340
+ state.images.push({ bytes, extension, relationshipId, imageId })
341
+ return '<w:r><w:drawing><wp:inline distT="0" distB="0" distL="0" distR="0">'
342
+ + '<wp:extent cx="' + Math.min(width, maxWidth) + '" cy="' + Math.round(height * Math.min(1, maxWidth / width)) + '"/>'
343
+ + '<wp:docPr id="' + imageId + '" name="Image ' + imageId + '"/>'
344
+ + '<a:graphic><a:graphicData uri="http://schemas.openxmlformats.org/drawingml/2006/picture">'
345
+ + '<pic:pic><pic:nvPicPr><pic:cNvPr id="' + imageId + '" name="image.' + extension + '"/><pic:cNvPicPr/></pic:nvPicPr>'
346
+ + '<pic:blipFill><a:blip r:embed="' + relationshipId + '"/><a:stretch><a:fillRect/></a:stretch></pic:blipFill>'
347
+ + '<pic:spPr><a:xfrm><a:off x="0" y="0"/><a:ext cx="' + width + '" cy="' + height + '"/></a:xfrm>'
348
+ + '<a:prstGeom prst="rect"><a:avLst/></a:prstGeom></pic:spPr></pic:pic>'
349
+ + '</a:graphicData></a:graphic></wp:inline></w:drawing></w:r>'
350
+ }
351
+
352
+ function renderList(node, state, level, numberId) {
353
+ return (Array.isArray(node.content) ? node.content : []).map((item) => {
354
+ const children = Array.isArray(item && item.content) ? item.content : []
355
+ return children.map((child) => {
356
+ if (child.type === 'paragraph') return paragraph(child, state, { numberId, level })
357
+ if (child.type === 'bulletList') return renderList(child, state, level + 1, 1)
358
+ if (child.type === 'orderedList') return renderList(child, state, level + 1, 2)
359
+ return renderBlock(child, state)
360
+ }).join('')
361
+ }).join('')
362
+ }
363
+
364
+ function renderTable(node, state) {
365
+ const rows = (Array.isArray(node.content) ? node.content : []).map((row) => {
366
+ const cells = (Array.isArray(row && row.content) ? row.content : []).map((cell) => (
367
+ '<w:tc><w:tcPr><w:tcW w:w="0" w:type="auto"/></w:tcPr>'
368
+ + (Array.isArray(cell && cell.content) ? cell.content.map((entry) => renderBlock(entry, state)).join('') : '<w:p/>')
369
+ + '</w:tc>'
370
+ )).join('')
371
+ return '<w:tr>' + cells + '</w:tr>'
372
+ }).join('')
373
+ return '<w:tbl><w:tblPr><w:tblBorders><w:top w:val="single" w:sz="4"/><w:left w:val="single" w:sz="4"/>'
374
+ + '<w:bottom w:val="single" w:sz="4"/><w:right w:val="single" w:sz="4"/><w:insideH w:val="single" w:sz="4"/>'
375
+ + '<w:insideV w:val="single" w:sz="4"/></w:tblBorders></w:tblPr>' + rows + '</w:tbl>'
376
+ }
377
+
378
+ function renderBlock(node, state) {
379
+ if (!node || typeof node !== 'object') return ''
380
+ if (node.type === 'paragraph') return paragraph(node, state)
381
+ if (node.type === 'heading') return paragraph(node, state, { style: 'Heading' + Math.min(6, Math.max(1, Number(node.attrs && node.attrs.level || 1))) })
382
+ if (node.type === 'bulletList' || node.type === 'taskList') return renderList(node, state, 0, 1)
383
+ if (node.type === 'orderedList') return renderList(node, state, 0, 2)
384
+ if (node.type === 'blockquote') return '<w:p><w:pPr><w:ind w:left="720"/></w:pPr>' + inlineContent(node.content, state) + '</w:p>'
385
+ if (node.type === 'codeBlock') return '<w:p><w:pPr><w:pStyle w:val="Code"/></w:pPr>' + inlineContent(node.content, state) + '</w:p>'
386
+ if (node.type === 'horizontalRule') return '<w:p><w:pPr><w:pBdr><w:bottom w:val="single" w:sz="6"/></w:pBdr></w:pPr></w:p>'
387
+ if (node.type === 'table') return renderTable(node, state)
388
+ if (node.type === 'pageBreak') return '<w:p><w:r><w:br w:type="page"/></w:r></w:p>'
389
+ if (node.type === 'image') return '<w:p>' + imageRun(node, state) + '</w:p>'
390
+ return (Array.isArray(node.content) ? node.content : []).map((child) => renderBlock(child, state)).join('')
391
+ }
392
+
393
+ function documentXml(documentJson, state) {
394
+ const body = (Array.isArray(documentJson && documentJson.content) ? documentJson.content : [])
395
+ .map((node) => renderBlock(node, state)).join('')
396
+ return '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>'
397
+ + '<w:document xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" '
398
+ + 'xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" '
399
+ + 'xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing" '
400
+ + 'xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" '
401
+ + 'xmlns:pic="http://schemas.openxmlformats.org/drawingml/2006/picture">'
402
+ + '<w:body>' + body + '<w:sectPr><w:pgSz w:w="11906" w:h="16838"/><w:pgMar w:top="1440" w:right="1440" w:bottom="1440" w:left="1440"/></w:sectPr></w:body></w:document>'
403
+ }
404
+
405
+ async function convert(documentJson, JSZip) {
406
+ const zip = new JSZip()
407
+ const state = { images: [] }
408
+ const document = documentXml(documentJson, state)
409
+ zip.file('[Content_Types].xml', '<?xml version="1.0" encoding="UTF-8"?>'
410
+ + '<Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types">'
411
+ + '<Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"/>'
412
+ + '<Default Extension="xml" ContentType="application/xml"/><Default Extension="png" ContentType="image/png"/>'
413
+ + '<Default Extension="jpg" ContentType="image/jpeg"/>'
414
+ + '<Override PartName="/word/document.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml"/>'
415
+ + '<Override PartName="/word/styles.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.styles+xml"/>'
416
+ + '<Override PartName="/word/numbering.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.numbering+xml"/>'
417
+ + '</Types>')
418
+ zip.file('_rels/.rels', '<?xml version="1.0" encoding="UTF-8"?>'
419
+ + '<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">'
420
+ + '<Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" Target="word/document.xml"/>'
421
+ + '</Relationships>')
422
+ zip.file('word/document.xml', document)
423
+ zip.file('word/styles.xml', '<?xml version="1.0" encoding="UTF-8"?>'
424
+ + '<w:styles xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">'
425
+ + '<w:style w:type="paragraph" w:default="1" w:styleId="Normal"><w:name w:val="Normal"/></w:style>'
426
+ + [1,2,3,4,5,6].map((level) => '<w:style w:type="paragraph" w:styleId="Heading' + level + '"><w:name w:val="heading ' + level + '"/><w:basedOn w:val="Normal"/><w:rPr><w:b/><w:sz w:val="' + (34 - level * 2) + '"/></w:rPr></w:style>').join('')
427
+ + '<w:style w:type="paragraph" w:styleId="Code"><w:name w:val="Code"/><w:rPr><w:rFonts w:ascii="Courier New" w:hAnsi="Courier New"/></w:rPr></w:style>'
428
+ + '</w:styles>')
429
+ zip.file('word/numbering.xml', '<?xml version="1.0" encoding="UTF-8"?>'
430
+ + '<w:numbering xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">'
431
+ + '<w:abstractNum w:abstractNumId="1"><w:lvl w:ilvl="0"><w:numFmt w:val="bullet"/><w:lvlText w:val="•"/></w:lvl></w:abstractNum>'
432
+ + '<w:abstractNum w:abstractNumId="2"><w:lvl w:ilvl="0"><w:numFmt w:val="decimal"/><w:lvlText w:val="%1."/></w:lvl></w:abstractNum>'
433
+ + '<w:num w:numId="1"><w:abstractNumId w:val="1"/></w:num><w:num w:numId="2"><w:abstractNumId w:val="2"/></w:num>'
434
+ + '</w:numbering>')
435
+ const relationships = [
436
+ '<Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles" Target="styles.xml"/>',
437
+ '<Relationship Id="rId2" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/numbering" Target="numbering.xml"/>',
438
+ ]
439
+ for (const image of state.images) {
440
+ zip.file('word/media/image' + image.imageId + '.' + image.extension, image.bytes)
441
+ relationships.push('<Relationship Id="' + image.relationshipId + '" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/image" Target="media/image' + image.imageId + '.' + image.extension + '"/>')
442
+ }
443
+ zip.file('word/_rels/document.xml.rels', '<?xml version="1.0" encoding="UTF-8"?>'
444
+ + '<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">'
445
+ + relationships.join('') + '</Relationships>')
446
+ return zip.generateAsync({ type: 'uint8array', compression: 'DEFLATE', compressionOptions: { level: 6 } })
447
+ }
448
+
449
+ ;(async () => {
450
+ const imported = typeof workerData.modulePath === 'string'
451
+ ? require(workerData.modulePath)
452
+ : require('node:module').createRequire(workerData.requireFrom)(workerData.moduleSpecifier)
453
+ const JSZip = typeof imported === 'function' ? imported : imported && imported.default
454
+ if (typeof JSZip !== 'function') throw new Error('[internal] JSZip export is not callable')
455
+ const bytes = await convert(htmlToDocumentJson(workerData.html), JSZip)
456
+ if (bytes.byteLength > workerData.maxOutputBytes) {
457
+ parentPort.postMessage({ type: 'overflow' })
458
+ parentPort.close()
459
+ return
460
+ }
461
+
462
+ parentPort.postMessage({ type: 'start', totalBytes: bytes.byteLength })
463
+ for (let offset = 0; offset < bytes.byteLength; offset += workerData.chunkBytes) {
464
+ const length = Math.min(workerData.chunkBytes, bytes.byteLength - offset)
465
+ const chunk = new Uint8Array(length)
466
+ chunk.set(bytes.subarray(offset, offset + length))
467
+ parentPort.postMessage({ type: 'chunk', chunk }, [chunk.buffer])
468
+ }
469
+ parentPort.postMessage({ type: 'done' })
470
+ parentPort.close()
471
+ })().catch((error) => {
472
+ parentPort.postMessage({
473
+ type: 'error',
474
+ message: error && typeof error.message === 'string' ? error.message : 'DOCX conversion failed',
475
+ })
476
+ parentPort.close()
477
+ })
478
+ `
479
+
480
+ const requireFromHere = createRequire(import.meta.url)
481
+
482
+ function defaultWorkerFactory(input: DocxWorkerFactoryInput): DocxWorker {
483
+ return new Worker(DOCX_WORKER_SOURCE, {
484
+ eval: true,
485
+ workerData: input,
486
+ resourceLimits: DOCX_WORKER_RESOURCE_LIMITS,
487
+ // `--input-type=module` is valid only for the parent's eval/stdin entry and
488
+ // would reinterpret this deliberately CommonJS worker source. Preserve all
489
+ // other execArgv entries, including Yarn PnP loaders.
490
+ execArgv: process.execArgv.filter((arg) => !arg.startsWith('--input-type')),
491
+ })
492
+ }
493
+
494
+ function resolveDocxArchiveModuleReference(): Pick<DocxWorkerFactoryInput, 'modulePath' | 'moduleSpecifier' | 'requireFrom'> {
495
+ // createRequire keeps node-modules and Yarn PnP resolution anchored to this
496
+ // package. Turbopack rewrites a statically traced external `require.resolve`
497
+ // to its numeric module id, which Node workers cannot require directly. Keep
498
+ // the static lookup so output tracing includes the dependency, but fall back
499
+ // to runtime resolution inside the unbundled worker when the value is not an
500
+ // absolute Node path.
501
+ const tracedPath: unknown = requireFromHere.resolve('jszip')
502
+ return {
503
+ modulePath: typeof tracedPath === 'string' && isAbsolute(tracedPath) ? tracedPath : null,
504
+ moduleSpecifier: 'jszip',
505
+ requireFrom: import.meta.url,
506
+ }
507
+ }
508
+
509
+ export function createDocxRenderer(
510
+ options: DocxRendererOptions = {},
511
+ deps: DocxRendererDeps = {},
512
+ ) {
513
+ const maxConcurrency = options.maxConcurrency ?? DOCX_RENDER_MAX_CONCURRENCY
514
+ const maxQueue = options.maxQueue ?? DOCX_RENDER_MAX_QUEUE
515
+ const acquireTimeoutMs = options.acquireTimeoutMs ?? DOCX_RENDER_ACQUIRE_TIMEOUT_MS
516
+ const renderTimeoutMs = options.renderTimeoutMs ?? DOCX_RENDER_TIMEOUT_MS
517
+ const maxOutputBytes = options.maxOutputBytes ?? DOCX_MAX_OUTPUT_BYTES
518
+ const workerFactory = deps.workerFactory ?? defaultWorkerFactory
519
+ const allocateOutput = deps.allocateOutput ?? ((byteLength: number) => new Uint8Array(byteLength))
520
+ let active = 0
521
+ const waiters: Array<{
522
+ resolve: (release: () => void) => void
523
+ reject: (error: Error) => void
524
+ timer: ReturnType<typeof setTimeout>
525
+ }> = []
526
+
527
+ const grant = (): (() => void) => {
528
+ active += 1
529
+ let released = false
530
+ return () => {
531
+ if (released) return
532
+ released = true
533
+ active -= 1
534
+ const waiter = waiters.shift()
535
+ if (!waiter) return
536
+ clearTimeout(waiter.timer)
537
+ waiter.resolve(grant())
538
+ }
539
+ }
540
+
541
+ const acquire = async (): Promise<() => void> => {
542
+ if (active < maxConcurrency) return grant()
543
+ if (waiters.length >= maxQueue) throw new DocxRenderOverloadedError()
544
+ return await new Promise<() => void>((resolve, reject) => {
545
+ const waiter = {
546
+ resolve,
547
+ reject,
548
+ timer: setTimeout(() => {
549
+ const index = waiters.indexOf(waiter)
550
+ if (index >= 0) waiters.splice(index, 1)
551
+ reject(new DocxRenderOverloadedError())
552
+ }, acquireTimeoutMs),
553
+ }
554
+ waiters.push(waiter)
555
+ })
556
+ }
557
+
558
+ const runWorker = (html: string): Promise<Uint8Array> => new Promise((resolve, reject) => {
559
+ let worker: DocxWorker
560
+ try {
561
+ const moduleReference = deps.modulePath === undefined
562
+ ? resolveDocxArchiveModuleReference()
563
+ : { modulePath: deps.modulePath, moduleSpecifier: 'jszip', requireFrom: import.meta.url }
564
+ worker = workerFactory({
565
+ html,
566
+ ...moduleReference,
567
+ maxOutputBytes,
568
+ chunkBytes: DOCX_WORKER_CHUNK_BYTES,
569
+ })
570
+ } catch (error) {
571
+ reject(new DocxRenderFailedError({ cause: error }))
572
+ return
573
+ }
574
+
575
+ let settled = false
576
+ let output: Uint8Array | null = null
577
+ let expectedBytes: number | null = null
578
+ let receivedBytes = 0
579
+ const timer = setTimeout(() => {
580
+ if (settled) return
581
+ settled = true
582
+ void worker.terminate().catch(() => undefined).then(() => {
583
+ reject(new DocxRenderTimeoutError())
584
+ })
585
+ }, renderTimeoutMs)
586
+
587
+ const terminateAndReject = (error: Error) => {
588
+ if (settled) return
589
+ settled = true
590
+ clearTimeout(timer)
591
+ void worker.terminate().catch(() => undefined).then(() => reject(error))
592
+ }
593
+
594
+ const terminateAndResolve = (value: Uint8Array) => {
595
+ if (settled) return
596
+ settled = true
597
+ clearTimeout(timer)
598
+ void worker.terminate().catch(() => undefined).then(() => resolve(value))
599
+ }
600
+
601
+ worker.on('message', (message) => {
602
+ if (settled || !message || typeof message !== 'object') return
603
+ const record = message as Record<string, unknown>
604
+ if (record.type === 'overflow') {
605
+ terminateAndReject(new DocxRenderOutputTooLargeError())
606
+ return
607
+ }
608
+ if (record.type === 'error') {
609
+ const message = typeof record.message === 'string'
610
+ ? record.message
611
+ : 'DOCX worker reported an unknown conversion failure'
612
+ terminateAndReject(new DocxRenderFailedError({ cause: new Error(message) }))
613
+ return
614
+ }
615
+ if (record.type === 'start') {
616
+ const totalBytes = record.totalBytes
617
+ if (
618
+ expectedBytes !== null
619
+ || typeof totalBytes !== 'number'
620
+ || !Number.isSafeInteger(totalBytes)
621
+ || totalBytes < 0
622
+ || totalBytes > maxOutputBytes
623
+ ) {
624
+ terminateAndReject(new DocxRenderOutputTooLargeError())
625
+ return
626
+ }
627
+ try {
628
+ output = allocateOutput(totalBytes)
629
+ if (output.byteLength !== totalBytes) throw new Error('[internal] invalid DOCX output allocation')
630
+ expectedBytes = totalBytes
631
+ } catch (error) {
632
+ terminateAndReject(new DocxRenderFailedError({ cause: error }))
633
+ }
634
+ return
635
+ }
636
+ if (record.type === 'chunk') {
637
+ const chunk = record.chunk
638
+ if (
639
+ expectedBytes === null
640
+ || !output
641
+ || !(chunk instanceof Uint8Array)
642
+ || receivedBytes + chunk.byteLength > expectedBytes
643
+ || receivedBytes + chunk.byteLength > maxOutputBytes
644
+ ) {
645
+ terminateAndReject(new DocxRenderOutputTooLargeError())
646
+ return
647
+ }
648
+ output.set(chunk, receivedBytes)
649
+ receivedBytes += chunk.byteLength
650
+ return
651
+ }
652
+ if (record.type === 'done') {
653
+ if (expectedBytes === null || !output || receivedBytes !== expectedBytes) {
654
+ terminateAndReject(new DocxRenderFailedError())
655
+ return
656
+ }
657
+ terminateAndResolve(output)
658
+ }
659
+ })
660
+ worker.on('error', (error) => terminateAndReject(new DocxRenderFailedError({ cause: error })))
661
+ worker.on('exit', (code) => {
662
+ if (!settled) terminateAndReject(new DocxRenderFailedError({ cause: new Error(`DOCX worker exited with code ${code}`) }))
663
+ })
664
+ })
665
+
666
+ const render = async (html: string): Promise<Uint8Array> => {
667
+ const release = await acquire()
668
+ try {
669
+ return await runWorker(html)
670
+ } finally {
671
+ release()
672
+ }
673
+ }
674
+
675
+ return { render }
676
+ }
677
+
678
+ const DOCX_RENDERER_KEY = Symbol.for('open-mercato.documents.docxRenderer')
679
+ const globalStore = globalThis as typeof globalThis & {
680
+ [DOCX_RENDERER_KEY]?: ReturnType<typeof createDocxRenderer>
681
+ }
682
+ const processDocxRenderer = globalStore[DOCX_RENDERER_KEY]
683
+ ?? (globalStore[DOCX_RENDERER_KEY] = createDocxRenderer())
684
+
685
+ export const renderDocxWithCapacity = processDocxRenderer.render