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