@stll/folio-core 0.0.1-placeholder.0 → 0.1.1
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/LICENSE +202 -0
- package/NOTICE.md +29 -0
- package/README.md +41 -0
- package/dist/_virtual/_rolldown/runtime.js +13 -0
- package/dist/ai-edits/apply.d.ts +35 -0
- package/dist/ai-edits/apply.js +683 -0
- package/dist/ai-edits/clean-text.d.ts +28 -0
- package/dist/ai-edits/clean-text.js +23 -0
- package/dist/ai-edits/headless.d.ts +225 -0
- package/dist/ai-edits/headless.js +513 -0
- package/dist/ai-edits/index.d.ts +6 -0
- package/dist/ai-edits/index.js +5 -0
- package/dist/ai-edits/inline-emphasis.d.ts +38 -0
- package/dist/ai-edits/inline-emphasis.js +78 -0
- package/dist/ai-edits/snapshot.d.ts +9 -0
- package/dist/ai-edits/snapshot.js +195 -0
- package/dist/ai-edits/types.d.ts +156 -0
- package/dist/ai-edits/types.js +0 -0
- package/dist/ai-edits/word-diff.d.ts +20 -0
- package/dist/ai-edits/word-diff.js +77 -0
- package/dist/ai-suggestions/apply.d.ts +17 -0
- package/dist/ai-suggestions/apply.js +64 -0
- package/dist/ai-suggestions/conflict.d.ts +22 -0
- package/dist/ai-suggestions/conflict.js +67 -0
- package/dist/ai-suggestions/text-positions.d.ts +21 -0
- package/dist/ai-suggestions/text-positions.js +48 -0
- package/dist/ai-suggestions/types.d.ts +199 -0
- package/dist/ai-suggestions/types.js +59 -0
- package/dist/content-controls/errors.d.ts +52 -0
- package/dist/content-controls/errors.js +36 -0
- package/dist/content-controls/findContentControls.d.ts +55 -0
- package/dist/content-controls/findContentControls.js +75 -0
- package/dist/content-controls/index.d.ts +4 -0
- package/dist/content-controls/index.js +4 -0
- package/dist/content-controls/mutateContentControls.d.ts +51 -0
- package/dist/content-controls/mutateContentControls.js +377 -0
- package/dist/controller/folioEditor.d.ts +21 -0
- package/dist/controller/folioEditor.js +29 -0
- package/dist/controller/folioEditorEvents.d.ts +23 -0
- package/dist/controller/folioEditorEvents.js +24 -0
- package/dist/controller/hiddenEditorApi.d.ts +35 -0
- package/dist/controller/hiddenEditorApi.js +112 -0
- package/dist/controller/hiddenEditorManager.d.ts +93 -0
- package/dist/controller/hiddenEditorManager.js +308 -0
- package/dist/controller/layoutPipeline.d.ts +63 -0
- package/dist/controller/layoutPipeline.js +406 -0
- package/dist/controller/layoutScheduler.d.ts +41 -0
- package/dist/controller/layoutScheduler.js +59 -0
- package/dist/controller/layoutSession.d.ts +24 -0
- package/dist/controller/layoutSession.js +13 -0
- package/dist/docx/blockContentParser.d.ts +13 -0
- package/dist/docx/blockContentParser.js +289 -0
- package/dist/docx/bookmarkParser.d.ts +178 -0
- package/dist/docx/bookmarkParser.js +246 -0
- package/dist/docx/bookmarkPlacement.d.ts +10 -0
- package/dist/docx/bookmarkPlacement.js +50 -0
- package/dist/docx/bulletMarkers.d.ts +4 -0
- package/dist/docx/bulletMarkers.js +42 -0
- package/dist/docx/commentParser.d.ts +34 -0
- package/dist/docx/commentParser.js +127 -0
- package/dist/docx/commentReferenceNormalization.d.ts +25 -0
- package/dist/docx/commentReferenceNormalization.js +97 -0
- package/dist/docx/commentReplyMarkers.d.ts +20 -0
- package/dist/docx/commentReplyMarkers.js +123 -0
- package/dist/docx/compatibility.d.ts +12 -0
- package/dist/docx/compatibility.js +77 -0
- package/dist/docx/documentParser.d.ts +65 -0
- package/dist/docx/documentParser.js +209 -0
- package/dist/docx/drawingUtils.d.ts +56 -0
- package/dist/docx/drawingUtils.js +305 -0
- package/dist/docx/fieldParser.d.ts +228 -0
- package/dist/docx/fieldParser.js +559 -0
- package/dist/docx/footnoteParser.d.ts +109 -0
- package/dist/docx/footnoteParser.js +270 -0
- package/dist/docx/headerFooterParser.d.ts +119 -0
- package/dist/docx/headerFooterParser.js +266 -0
- package/dist/docx/headerFooterRefParser.d.ts +22 -0
- package/dist/docx/headerFooterRefParser.js +52 -0
- package/dist/docx/headerFooterReferenceNormalization.d.ts +19 -0
- package/dist/docx/headerFooterReferenceNormalization.js +64 -0
- package/dist/docx/hyperlinkParser.d.ts +108 -0
- package/dist/docx/hyperlinkParser.js +230 -0
- package/dist/docx/imageParser.d.ts +93 -0
- package/dist/docx/imageParser.js +522 -0
- package/dist/docx/mathToMathml.d.ts +15 -0
- package/dist/docx/mathToMathml.js +357 -0
- package/dist/docx/modelValidation.d.ts +13 -0
- package/dist/docx/modelValidation.js +21 -0
- package/dist/docx/normalizeBaseDirection.d.ts +12 -0
- package/dist/docx/normalizeBaseDirection.js +81 -0
- package/dist/docx/notePropertiesParser.d.ts +16 -0
- package/dist/docx/notePropertiesParser.js +99 -0
- package/dist/docx/numberingParser.d.ts +86 -0
- package/dist/docx/numberingParser.js +735 -0
- package/dist/docx/numberingReferenceNormalization.d.ts +25 -0
- package/dist/docx/numberingReferenceNormalization.js +22 -0
- package/dist/docx/paragraphParser.d.ts +86 -0
- package/dist/docx/paragraphParser.js +1132 -0
- package/dist/docx/paragraphTraversal.d.ts +19 -0
- package/dist/docx/paragraphTraversal.js +76 -0
- package/dist/docx/parser.d.ts +67 -0
- package/dist/docx/parser.js +391 -0
- package/dist/docx/parserEnums.d.ts +45 -0
- package/dist/docx/parserEnums.js +70 -0
- package/dist/docx/relsParser.d.ts +160 -0
- package/dist/docx/relsParser.js +235 -0
- package/dist/docx/replyToComment.d.ts +29 -0
- package/dist/docx/replyToComment.js +73 -0
- package/dist/docx/rezip.d.ts +166 -0
- package/dist/docx/rezip.js +1194 -0
- package/dist/docx/runConsolidator.d.ts +57 -0
- package/dist/docx/runConsolidator.js +224 -0
- package/dist/docx/runParser.d.ts +78 -0
- package/dist/docx/runParser.js +661 -0
- package/dist/docx/sdtProperties.d.ts +15 -0
- package/dist/docx/sdtProperties.js +290 -0
- package/dist/docx/sdtPropertiesPatch.d.ts +16 -0
- package/dist/docx/sdtPropertiesPatch.js +144 -0
- package/dist/docx/sectionParser.d.ts +95 -0
- package/dist/docx/sectionParser.js +534 -0
- package/dist/docx/selectiveSave.d.ts +25 -0
- package/dist/docx/selectiveSave.js +247 -0
- package/dist/docx/selectiveSaveFlags.d.ts +33 -0
- package/dist/docx/selectiveSaveFlags.js +11 -0
- package/dist/docx/selectiveSaveTripwire.d.ts +33 -0
- package/dist/docx/selectiveSaveTripwire.js +79 -0
- package/dist/docx/selectiveXmlPatch.d.ts +103 -0
- package/dist/docx/selectiveXmlPatch.js +493 -0
- package/dist/docx/serializer/blockSdtSerializer.d.ts +6 -0
- package/dist/docx/serializer/blockSdtSerializer.js +88 -0
- package/dist/docx/serializer/borderSerializer.d.ts +25 -0
- package/dist/docx/serializer/borderSerializer.js +44 -0
- package/dist/docx/serializer/commentSerializer.d.ts +31 -0
- package/dist/docx/serializer/commentSerializer.js +184 -0
- package/dist/docx/serializer/documentSerializer.d.ts +65 -0
- package/dist/docx/serializer/documentSerializer.js +199 -0
- package/dist/docx/serializer/headerFooterSerializer.d.ts +12 -0
- package/dist/docx/serializer/headerFooterSerializer.js +84 -0
- package/dist/docx/serializer/noteSerializer.d.ts +19 -0
- package/dist/docx/serializer/noteSerializer.js +70 -0
- package/dist/docx/serializer/numberingSerializer.d.ts +12 -0
- package/dist/docx/serializer/numberingSerializer.js +93 -0
- package/dist/docx/serializer/paragraphSerializer.d.ts +48 -0
- package/dist/docx/serializer/paragraphSerializer.js +559 -0
- package/dist/docx/serializer/runSerializer.d.ts +56 -0
- package/dist/docx/serializer/runSerializer.js +621 -0
- package/dist/docx/serializer/sectionPropertiesSerializer.d.ts +6 -0
- package/dist/docx/serializer/sectionPropertiesSerializer.js +187 -0
- package/dist/docx/serializer/tableSerializer.d.ts +79 -0
- package/dist/docx/serializer/tableSerializer.js +422 -0
- package/dist/docx/serializer/xmlUtils.d.ts +20 -0
- package/dist/docx/serializer/xmlUtils.js +25 -0
- package/dist/docx/settingsParser.d.ts +8 -0
- package/dist/docx/settingsParser.js +36 -0
- package/dist/docx/shapeParser.d.ts +20 -0
- package/dist/docx/shapeParser.js +272 -0
- package/dist/docx/styleParser.d.ts +50 -0
- package/dist/docx/styleParser.js +905 -0
- package/dist/docx/tableParser.d.ts +202 -0
- package/dist/docx/tableParser.js +811 -0
- package/dist/docx/textBoxParser.d.ts +117 -0
- package/dist/docx/textBoxParser.js +262 -0
- package/dist/docx/themeParser.d.ts +77 -0
- package/dist/docx/themeParser.js +330 -0
- package/dist/docx/trackedMoveRangeNormalization.d.ts +22 -0
- package/dist/docx/trackedMoveRangeNormalization.js +100 -0
- package/dist/docx/unzip.d.ts +118 -0
- package/dist/docx/unzip.js +383 -0
- package/dist/docx/vmlImageParser.d.ts +16 -0
- package/dist/docx/vmlImageParser.js +100 -0
- package/dist/docx/watermarkParser.d.ts +45 -0
- package/dist/docx/watermarkParser.js +348 -0
- package/dist/docx/wrapTypes.d.ts +29 -0
- package/dist/docx/wrapTypes.js +48 -0
- package/dist/docx/xmlParser.d.ts +297 -0
- package/dist/docx/xmlParser.js +527 -0
- package/dist/fields/bookmarkPages.d.ts +13 -0
- package/dist/fields/bookmarkPages.js +66 -0
- package/dist/fields/bookmarkText.d.ts +16 -0
- package/dist/fields/bookmarkText.js +61 -0
- package/dist/fields/evaluateField.d.ts +23 -0
- package/dist/fields/evaluateField.js +77 -0
- package/dist/fields/fieldContext.d.ts +21 -0
- package/dist/fields/fieldContext.js +0 -0
- package/dist/fields/resolveFieldValues.d.ts +44 -0
- package/dist/fields/resolveFieldValues.js +204 -0
- package/dist/fields/sectionPageCounts.d.ts +11 -0
- package/dist/fields/sectionPageCounts.js +16 -0
- package/dist/fields/seqValues.d.ts +14 -0
- package/dist/fields/seqValues.js +36 -0
- package/dist/fonts/embeddedFontTable.d.ts +42 -0
- package/dist/fonts/embeddedFontTable.js +80 -0
- package/dist/fonts/embeddedFonts.d.ts +46 -0
- package/dist/fonts/embeddedFonts.js +112 -0
- package/dist/fonts/fontDeobfuscation.d.ts +30 -0
- package/dist/fonts/fontDeobfuscation.js +57 -0
- package/dist/index.d.ts +28 -0
- package/dist/index.js +23 -0
- package/dist/layout-bridge/convert/footnoteLayout.d.ts +57 -0
- package/dist/layout-bridge/convert/footnoteLayout.js +316 -0
- package/dist/layout-bridge/convert/headerFooterLayout.d.ts +74 -0
- package/dist/layout-bridge/convert/headerFooterLayout.js +432 -0
- package/dist/layout-bridge/convert/templatePreviewFlow.d.ts +36 -0
- package/dist/layout-bridge/convert/templatePreviewFlow.js +176 -0
- package/dist/layout-bridge/convert/toFlowBlocks.d.ts +65 -0
- package/dist/layout-bridge/convert/toFlowBlocks.js +1309 -0
- package/dist/layout-bridge/convert/wrapEditorViewAsSurface.d.ts +17 -0
- package/dist/layout-bridge/convert/wrapEditorViewAsSurface.js +36 -0
- package/dist/layout-bridge/dom/clickToPositionDom.d.ts +66 -0
- package/dist/layout-bridge/dom/clickToPositionDom.js +304 -0
- package/dist/layout-bridge/dom/findBodyPmSpans.d.ts +7 -0
- package/dist/layout-bridge/dom/findBodyPmSpans.js +17 -0
- package/dist/layout-bridge/dom/findHfPmSpans.d.ts +62 -0
- package/dist/layout-bridge/dom/findHfPmSpans.js +197 -0
- package/dist/layout-bridge/engine/clickToPosition.d.ts +66 -0
- package/dist/layout-bridge/engine/clickToPosition.js +403 -0
- package/dist/layout-bridge/engine/hitTest.d.ts +135 -0
- package/dist/layout-bridge/engine/hitTest.js +375 -0
- package/dist/layout-bridge/engine/measuring/index.d.ts +10 -0
- package/dist/layout-bridge/engine/measuring/index.js +9 -0
- package/dist/layout-bridge/engine/selectionRects.d.ts +59 -0
- package/dist/layout-bridge/engine/selectionRects.js +485 -0
- package/dist/layout-bridge/engine/tableWidthUtils.d.ts +7 -0
- package/dist/layout-bridge/engine/tableWidthUtils.js +25 -0
- package/dist/layout-engine/index.d.ts +44 -0
- package/dist/layout-engine/index.js +691 -0
- package/dist/layout-engine/keep-together.d.ts +43 -0
- package/dist/layout-engine/keep-together.js +98 -0
- package/dist/layout-engine/layoutInstrumentation.d.ts +50 -0
- package/dist/layout-engine/layoutInstrumentation.js +43 -0
- package/dist/layout-engine/lineFlow.d.ts +8 -0
- package/dist/layout-engine/lineFlow.js +17 -0
- package/dist/layout-engine/measure/cache.d.ts +93 -0
- package/dist/layout-engine/measure/cache.js +245 -0
- package/dist/layout-engine/measure/clampFloatingWrapMargins.d.ts +20 -0
- package/dist/layout-engine/measure/clampFloatingWrapMargins.js +29 -0
- package/dist/layout-engine/measure/featureFlags.d.ts +44 -0
- package/dist/layout-engine/measure/featureFlags.js +19 -0
- package/dist/layout-engine/measure/floatingZones.d.ts +89 -0
- package/dist/layout-engine/measure/floatingZones.js +152 -0
- package/dist/layout-engine/measure/font-metrics.worker.d.ts +17 -0
- package/dist/layout-engine/measure/font-metrics.worker.js +104 -0
- package/dist/layout-engine/measure/index.d.ts +9 -0
- package/dist/layout-engine/measure/index.js +8 -0
- package/dist/layout-engine/measure/listMarkerWidth.d.ts +40 -0
- package/dist/layout-engine/measure/listMarkerWidth.js +76 -0
- package/dist/layout-engine/measure/measureBlocks.d.ts +25 -0
- package/dist/layout-engine/measure/measureBlocks.js +450 -0
- package/dist/layout-engine/measure/measureContainer.d.ts +24 -0
- package/dist/layout-engine/measure/measureContainer.js +280 -0
- package/dist/layout-engine/measure/measureHelpers.d.ts +82 -0
- package/dist/layout-engine/measure/measureHelpers.js +156 -0
- package/dist/layout-engine/measure/measureParagraph.d.ts +61 -0
- package/dist/layout-engine/measure/measureParagraph.js +724 -0
- package/dist/layout-engine/measure/measureProvider.d.ts +23 -0
- package/dist/layout-engine/measure/measureProvider.js +35 -0
- package/dist/layout-engine/measure/measureTypes.d.ts +61 -0
- package/dist/layout-engine/measure/measureTypes.js +0 -0
- package/dist/layout-engine/measure/measureWorker.d.ts +54 -0
- package/dist/layout-engine/measure/measureWorker.js +249 -0
- package/dist/layout-engine/measure/measureWorkerProtocol.d.ts +88 -0
- package/dist/layout-engine/measure/measureWorkerProtocol.js +20 -0
- package/dist/layout-engine/measure/tableCellFloating.d.ts +26 -0
- package/dist/layout-engine/measure/tableCellFloating.js +99 -0
- package/dist/layout-engine/paginator.d.ts +84 -0
- package/dist/layout-engine/paginator.js +348 -0
- package/dist/layout-engine/paragraphFragmentRange.d.ts +9 -0
- package/dist/layout-engine/paragraphFragmentRange.js +40 -0
- package/dist/layout-engine/section-breaks.d.ts +78 -0
- package/dist/layout-engine/section-breaks.js +182 -0
- package/dist/layout-engine/tableRowBreak.d.ts +23 -0
- package/dist/layout-engine/tableRowBreak.js +147 -0
- package/dist/layout-engine/textBoxFlow.d.ts +50 -0
- package/dist/layout-engine/textBoxFlow.js +160 -0
- package/dist/layout-engine/types.d.ts +1031 -0
- package/dist/layout-engine/types.js +100 -0
- package/dist/layout-painter/documentColors.d.ts +4 -0
- package/dist/layout-painter/documentColors.js +40 -0
- package/dist/layout-painter/index.d.ts +110 -0
- package/dist/layout-painter/index.js +182 -0
- package/dist/layout-painter/registry/modules/image.d.ts +6 -0
- package/dist/layout-painter/registry/modules/image.js +17 -0
- package/dist/layout-painter/registry/modules/paragraph.d.ts +6 -0
- package/dist/layout-painter/registry/modules/paragraph.js +18 -0
- package/dist/layout-painter/registry/modules/table.d.ts +6 -0
- package/dist/layout-painter/registry/modules/table.js +16 -0
- package/dist/layout-painter/registry/modules/textBox.d.ts +6 -0
- package/dist/layout-painter/registry/modules/textBox.js +13 -0
- package/dist/layout-painter/registry/modules.d.ts +6 -0
- package/dist/layout-painter/registry/modules.js +26 -0
- package/dist/layout-painter/registry/registry.d.ts +24 -0
- package/dist/layout-painter/registry/registry.js +53 -0
- package/dist/layout-painter/registry/types.d.ts +61 -0
- package/dist/layout-painter/registry/types.js +0 -0
- package/dist/layout-painter/renderFragment.d.ts +32 -0
- package/dist/layout-painter/renderFragment.js +114 -0
- package/dist/layout-painter/renderImage.d.ts +88 -0
- package/dist/layout-painter/renderImage.js +130 -0
- package/dist/layout-painter/renderPage.d.ts +264 -0
- package/dist/layout-painter/renderPage.js +1795 -0
- package/dist/layout-painter/renderParagraph.d.ts +93 -0
- package/dist/layout-painter/renderParagraph.js +1300 -0
- package/dist/layout-painter/renderTable.d.ts +36 -0
- package/dist/layout-painter/renderTable.js +432 -0
- package/dist/layout-painter/renderTextBox.d.ts +22 -0
- package/dist/layout-painter/renderTextBox.js +67 -0
- package/dist/layout-painter/renderUtils.d.ts +42 -0
- package/dist/layout-painter/renderUtils.js +30 -0
- package/dist/layout-painter/renderWatermark.d.ts +16 -0
- package/dist/layout-painter/renderWatermark.js +61 -0
- package/dist/layout-painter/sdtBoundary.d.ts +6 -0
- package/dist/layout-painter/sdtBoundary.js +28 -0
- package/dist/managers/ContextMenuManager.d.ts +28 -0
- package/dist/managers/ContextMenuManager.js +48 -0
- package/dist/managers/DocumentLoaderManager.d.ts +47 -0
- package/dist/managers/DocumentLoaderManager.js +69 -0
- package/dist/managers/EditorModeManager.d.ts +28 -0
- package/dist/managers/EditorModeManager.js +50 -0
- package/dist/managers/ErrorManager.d.ts +26 -0
- package/dist/managers/ErrorManager.js +85 -0
- package/dist/managers/FindReplaceManager.d.ts +54 -0
- package/dist/managers/FindReplaceManager.js +104 -0
- package/dist/managers/HistoryManager.d.ts +92 -0
- package/dist/managers/HistoryManager.js +193 -0
- package/dist/managers/Subscribable.d.ts +34 -0
- package/dist/managers/Subscribable.js +46 -0
- package/dist/managers/TableSelectionManager.d.ts +74 -0
- package/dist/managers/TableSelectionManager.js +225 -0
- package/dist/managers/editorShortcuts.d.ts +42 -0
- package/dist/managers/editorShortcuts.js +60 -0
- package/dist/managers/types.d.ts +41 -0
- package/dist/managers/types.js +0 -0
- package/dist/markdown/annotations.d.ts +14 -0
- package/dist/markdown/annotations.js +42 -0
- package/dist/markdown/escape.d.ts +36 -0
- package/dist/markdown/escape.js +59 -0
- package/dist/markdown/fromMarkdown.d.ts +11 -0
- package/dist/markdown/fromMarkdown.js +223 -0
- package/dist/markdown/headings.d.ts +13 -0
- package/dist/markdown/headings.js +20 -0
- package/dist/markdown/images.d.ts +13 -0
- package/dist/markdown/images.js +63 -0
- package/dist/markdown/index.d.ts +18 -0
- package/dist/markdown/index.js +33 -0
- package/dist/markdown/internals.d.ts +15 -0
- package/dist/markdown/internals.js +35 -0
- package/dist/markdown/renderBlock.d.ts +7 -0
- package/dist/markdown/renderBlock.js +68 -0
- package/dist/markdown/renderParagraph.d.ts +11 -0
- package/dist/markdown/renderParagraph.js +64 -0
- package/dist/markdown/renderRuns.d.ts +11 -0
- package/dist/markdown/renderRuns.js +265 -0
- package/dist/markdown/renderTable.d.ts +8 -0
- package/dist/markdown/renderTable.js +229 -0
- package/dist/markdown/trailers.d.ts +13 -0
- package/dist/markdown/trailers.js +54 -0
- package/dist/markdown/types.d.ts +118 -0
- package/dist/markdown/types.js +0 -0
- package/dist/model.d.ts +13 -0
- package/dist/model.js +4 -0
- package/dist/paged-layout/LayoutSelectionGate.d.ts +80 -0
- package/dist/paged-layout/LayoutSelectionGate.js +131 -0
- package/dist/paged-layout/headerFooterMargins.d.ts +73 -0
- package/dist/paged-layout/headerFooterMargins.js +120 -0
- package/dist/paged-layout/hiddenEditorScroll.d.ts +4 -0
- package/dist/paged-layout/hiddenEditorScroll.js +4 -0
- package/dist/paged-layout/incrementalMeasure.d.ts +33 -0
- package/dist/paged-layout/incrementalMeasure.js +56 -0
- package/dist/paged-layout/rangeProjection.d.ts +51 -0
- package/dist/paged-layout/rangeProjection.js +153 -0
- package/dist/paged-layout/readOnlyEditAttempt.d.ts +5 -0
- package/dist/paged-layout/readOnlyEditAttempt.js +22 -0
- package/dist/paged-layout/scrollNavigation.d.ts +23 -0
- package/dist/paged-layout/scrollNavigation.js +31 -0
- package/dist/paged-layout/scrollPageInfo.d.ts +41 -0
- package/dist/paged-layout/scrollPageInfo.js +34 -0
- package/dist/paged-layout/scrollToPmPosition.d.ts +17 -0
- package/dist/paged-layout/scrollToPmPosition.js +95 -0
- package/dist/paged-layout/sectionBlockWidths.d.ts +35 -0
- package/dist/paged-layout/sectionBlockWidths.js +52 -0
- package/dist/paged-layout/sectionGeometry.d.ts +21 -0
- package/dist/paged-layout/sectionGeometry.js +36 -0
- package/dist/paged-layout/selectionViewportRect.d.ts +29 -0
- package/dist/paged-layout/selectionViewportRect.js +55 -0
- package/dist/paged-layout/tableColumnResize.d.ts +19 -0
- package/dist/paged-layout/tableColumnResize.js +28 -0
- package/dist/paged-layout/tableInsertButtonGeometry.d.ts +15 -0
- package/dist/paged-layout/tableInsertButtonGeometry.js +15 -0
- package/dist/paged-layout/transactionDirtyRange.d.ts +7 -0
- package/dist/paged-layout/transactionDirtyRange.js +27 -0
- package/dist/paged-layout/zoomScrollAnchor.d.ts +40 -0
- package/dist/paged-layout/zoomScrollAnchor.js +25 -0
- package/dist/prosemirror/attrs/index.d.ts +80 -0
- package/dist/prosemirror/attrs/index.js +1218 -0
- package/dist/prosemirror/autospacingBase.d.ts +11 -0
- package/dist/prosemirror/autospacingBase.js +16 -0
- package/dist/prosemirror/commands/comments.d.ts +93 -0
- package/dist/prosemirror/commands/comments.js +435 -0
- package/dist/prosemirror/commands/contentControls.d.ts +45 -0
- package/dist/prosemirror/commands/contentControls.js +294 -0
- package/dist/prosemirror/commands/contentControlsBlockFill.d.ts +15 -0
- package/dist/prosemirror/commands/contentControlsBlockFill.js +19 -0
- package/dist/prosemirror/commands/formatPainter.d.ts +31 -0
- package/dist/prosemirror/commands/formatPainter.js +130 -0
- package/dist/prosemirror/commands/formatting.d.ts +32 -0
- package/dist/prosemirror/commands/formatting.js +45 -0
- package/dist/prosemirror/commands/hyperlink.d.ts +31 -0
- package/dist/prosemirror/commands/hyperlink.js +79 -0
- package/dist/prosemirror/commands/image.d.ts +59 -0
- package/dist/prosemirror/commands/image.js +219 -0
- package/dist/prosemirror/commands/index.d.ts +13 -0
- package/dist/prosemirror/commands/index.js +13 -0
- package/dist/prosemirror/commands/pageBreak.d.ts +10 -0
- package/dist/prosemirror/commands/pageBreak.js +47 -0
- package/dist/prosemirror/commands/paragraph.d.ts +39 -0
- package/dist/prosemirror/commands/paragraph.js +64 -0
- package/dist/prosemirror/commands/pastePlainText.d.ts +39 -0
- package/dist/prosemirror/commands/pastePlainText.js +67 -0
- package/dist/prosemirror/commands/table.d.ts +83 -0
- package/dist/prosemirror/commands/table.js +105 -0
- package/dist/prosemirror/conversion/fromProseDoc.d.ts +27 -0
- package/dist/prosemirror/conversion/fromProseDoc.js +1550 -0
- package/dist/prosemirror/conversion/index.d.ts +4 -0
- package/dist/prosemirror/conversion/index.js +4 -0
- package/dist/prosemirror/conversion/runShadingMark.d.ts +16 -0
- package/dist/prosemirror/conversion/runShadingMark.js +39 -0
- package/dist/prosemirror/conversion/toProseDoc.d.ts +39 -0
- package/dist/prosemirror/conversion/toProseDoc.js +1404 -0
- package/dist/prosemirror/extensions/ExtensionManager.d.ts +43 -0
- package/dist/prosemirror/extensions/ExtensionManager.js +86 -0
- package/dist/prosemirror/extensions/StarterKit.d.ts +16 -0
- package/dist/prosemirror/extensions/StarterKit.js +132 -0
- package/dist/prosemirror/extensions/core/DocExtension.d.ts +9 -0
- package/dist/prosemirror/extensions/core/DocExtension.js +12 -0
- package/dist/prosemirror/extensions/core/HistoryExtension.d.ts +13 -0
- package/dist/prosemirror/extensions/core/HistoryExtension.js +28 -0
- package/dist/prosemirror/extensions/core/ParagraphExtension.d.ts +25 -0
- package/dist/prosemirror/extensions/core/ParagraphExtension.js +619 -0
- package/dist/prosemirror/extensions/core/TextExtension.d.ts +9 -0
- package/dist/prosemirror/extensions/core/TextExtension.js +12 -0
- package/dist/prosemirror/extensions/create.d.ts +17 -0
- package/dist/prosemirror/extensions/create.js +129 -0
- package/dist/prosemirror/extensions/features/AutoBidiDetectionExtension.d.ts +23 -0
- package/dist/prosemirror/extensions/features/AutoBidiDetectionExtension.js +106 -0
- package/dist/prosemirror/extensions/features/BaseKeymapExtension.d.ts +8 -0
- package/dist/prosemirror/extensions/features/BaseKeymapExtension.js +172 -0
- package/dist/prosemirror/extensions/features/BidiShortcutExtension.d.ts +16 -0
- package/dist/prosemirror/extensions/features/BidiShortcutExtension.js +38 -0
- package/dist/prosemirror/extensions/features/ContentControlWidgetsExtension.d.ts +16 -0
- package/dist/prosemirror/extensions/features/ContentControlWidgetsExtension.js +21 -0
- package/dist/prosemirror/extensions/features/DropCursorExtension.d.ts +12 -0
- package/dist/prosemirror/extensions/features/DropCursorExtension.js +20 -0
- package/dist/prosemirror/extensions/features/EmptyParagraphFormatExtension.d.ts +8 -0
- package/dist/prosemirror/extensions/features/EmptyParagraphFormatExtension.js +44 -0
- package/dist/prosemirror/extensions/features/GapCursorExtension.d.ts +19 -0
- package/dist/prosemirror/extensions/features/GapCursorExtension.js +24 -0
- package/dist/prosemirror/extensions/features/ImageDragExtension.d.ts +15 -0
- package/dist/prosemirror/extensions/features/ImageDragExtension.js +66 -0
- package/dist/prosemirror/extensions/features/ImagePasteExtension.d.ts +12 -0
- package/dist/prosemirror/extensions/features/ImagePasteExtension.js +91 -0
- package/dist/prosemirror/extensions/features/ListExtension.d.ts +14 -0
- package/dist/prosemirror/extensions/features/ListExtension.js +340 -0
- package/dist/prosemirror/extensions/features/ParaIdAllocatorExtension.d.ts +9 -0
- package/dist/prosemirror/extensions/features/ParaIdAllocatorExtension.js +60 -0
- package/dist/prosemirror/extensions/features/ParagraphChangeTrackerExtension.d.ts +35 -0
- package/dist/prosemirror/extensions/features/ParagraphChangeTrackerExtension.js +188 -0
- package/dist/prosemirror/extensions/features/PasteCleanupExtension.d.ts +20 -0
- package/dist/prosemirror/extensions/features/PasteCleanupExtension.js +34 -0
- package/dist/prosemirror/extensions/features/PasteStyleInlinerExtension.d.ts +20 -0
- package/dist/prosemirror/extensions/features/PasteStyleInlinerExtension.js +145 -0
- package/dist/prosemirror/extensions/features/SelectionTrackerExtension.d.ts +10 -0
- package/dist/prosemirror/extensions/features/SelectionTrackerExtension.js +17 -0
- package/dist/prosemirror/extensions/features/bidiShortcutController.d.ts +31 -0
- package/dist/prosemirror/extensions/features/bidiShortcutController.js +27 -0
- package/dist/prosemirror/extensions/features/pasteCleanup.d.ts +31 -0
- package/dist/prosemirror/extensions/features/pasteCleanup.js +159 -0
- package/dist/prosemirror/extensions/marks/AllCapsExtension.d.ts +9 -0
- package/dist/prosemirror/extensions/marks/AllCapsExtension.js +24 -0
- package/dist/prosemirror/extensions/marks/BoldExtension.d.ts +9 -0
- package/dist/prosemirror/extensions/marks/BoldExtension.js +41 -0
- package/dist/prosemirror/extensions/marks/CharacterSpacingExtension.d.ts +14 -0
- package/dist/prosemirror/extensions/marks/CharacterSpacingExtension.js +64 -0
- package/dist/prosemirror/extensions/marks/CharacterStyleExtension.d.ts +23 -0
- package/dist/prosemirror/extensions/marks/CharacterStyleExtension.js +47 -0
- package/dist/prosemirror/extensions/marks/CommentExtension.d.ts +12 -0
- package/dist/prosemirror/extensions/marks/CommentExtension.js +38 -0
- package/dist/prosemirror/extensions/marks/FontFamilyExtension.d.ts +9 -0
- package/dist/prosemirror/extensions/marks/FontFamilyExtension.js +55 -0
- package/dist/prosemirror/extensions/marks/FontSizeExtension.d.ts +9 -0
- package/dist/prosemirror/extensions/marks/FontSizeExtension.js +47 -0
- package/dist/prosemirror/extensions/marks/FootnoteRefExtension.d.ts +11 -0
- package/dist/prosemirror/extensions/marks/FootnoteRefExtension.js +92 -0
- package/dist/prosemirror/extensions/marks/HiddenTextExtension.d.ts +23 -0
- package/dist/prosemirror/extensions/marks/HiddenTextExtension.js +35 -0
- package/dist/prosemirror/extensions/marks/HighlightExtension.d.ts +10 -0
- package/dist/prosemirror/extensions/marks/HighlightExtension.js +115 -0
- package/dist/prosemirror/extensions/marks/HyperlinkExtension.d.ts +13 -0
- package/dist/prosemirror/extensions/marks/HyperlinkExtension.js +146 -0
- package/dist/prosemirror/extensions/marks/ItalicExtension.d.ts +9 -0
- package/dist/prosemirror/extensions/marks/ItalicExtension.js +34 -0
- package/dist/prosemirror/extensions/marks/RtlExtension.d.ts +6 -0
- package/dist/prosemirror/extensions/marks/RtlExtension.js +21 -0
- package/dist/prosemirror/extensions/marks/RunFormattingOverrideExtension.d.ts +11 -0
- package/dist/prosemirror/extensions/marks/RunFormattingOverrideExtension.js +75 -0
- package/dist/prosemirror/extensions/marks/RunShadingExtension.d.ts +6 -0
- package/dist/prosemirror/extensions/marks/RunShadingExtension.js +38 -0
- package/dist/prosemirror/extensions/marks/SmallCapsExtension.d.ts +9 -0
- package/dist/prosemirror/extensions/marks/SmallCapsExtension.js +24 -0
- package/dist/prosemirror/extensions/marks/StrikeExtension.d.ts +9 -0
- package/dist/prosemirror/extensions/marks/StrikeExtension.js +33 -0
- package/dist/prosemirror/extensions/marks/SubscriptExtension.d.ts +9 -0
- package/dist/prosemirror/extensions/marks/SubscriptExtension.js +25 -0
- package/dist/prosemirror/extensions/marks/SuperscriptExtension.d.ts +9 -0
- package/dist/prosemirror/extensions/marks/SuperscriptExtension.js +25 -0
- package/dist/prosemirror/extensions/marks/TextColorExtension.d.ts +9 -0
- package/dist/prosemirror/extensions/marks/TextColorExtension.js +50 -0
- package/dist/prosemirror/extensions/marks/TextEffectExtension.d.ts +6 -0
- package/dist/prosemirror/extensions/marks/TextEffectExtension.js +35 -0
- package/dist/prosemirror/extensions/marks/TextEffectsExtensions.d.ts +31 -0
- package/dist/prosemirror/extensions/marks/TextEffectsExtensions.js +134 -0
- package/dist/prosemirror/extensions/marks/TrackedChangeExtensions.d.ts +22 -0
- package/dist/prosemirror/extensions/marks/TrackedChangeExtensions.js +113 -0
- package/dist/prosemirror/extensions/marks/UnderlineExtension.d.ts +9 -0
- package/dist/prosemirror/extensions/marks/UnderlineExtension.js +60 -0
- package/dist/prosemirror/extensions/marks/markUtils.d.ts +34 -0
- package/dist/prosemirror/extensions/marks/markUtils.js +233 -0
- package/dist/prosemirror/extensions/nodes/BlockSdtExtension.d.ts +22 -0
- package/dist/prosemirror/extensions/nodes/BlockSdtExtension.js +122 -0
- package/dist/prosemirror/extensions/nodes/FieldExtension.d.ts +12 -0
- package/dist/prosemirror/extensions/nodes/FieldExtension.js +87 -0
- package/dist/prosemirror/extensions/nodes/HardBreakExtension.d.ts +9 -0
- package/dist/prosemirror/extensions/nodes/HardBreakExtension.js +38 -0
- package/dist/prosemirror/extensions/nodes/HorizontalRuleExtension.d.ts +9 -0
- package/dist/prosemirror/extensions/nodes/HorizontalRuleExtension.js +18 -0
- package/dist/prosemirror/extensions/nodes/ImageExtension.d.ts +9 -0
- package/dist/prosemirror/extensions/nodes/ImageExtension.js +132 -0
- package/dist/prosemirror/extensions/nodes/MathExtension.d.ts +13 -0
- package/dist/prosemirror/extensions/nodes/MathExtension.js +56 -0
- package/dist/prosemirror/extensions/nodes/PageBreakExtension.d.ts +9 -0
- package/dist/prosemirror/extensions/nodes/PageBreakExtension.js +20 -0
- package/dist/prosemirror/extensions/nodes/SdtExtension.d.ts +12 -0
- package/dist/prosemirror/extensions/nodes/SdtExtension.js +107 -0
- package/dist/prosemirror/extensions/nodes/ShapeExtension.d.ts +30 -0
- package/dist/prosemirror/extensions/nodes/ShapeExtension.js +502 -0
- package/dist/prosemirror/extensions/nodes/TabExtension.d.ts +9 -0
- package/dist/prosemirror/extensions/nodes/TabExtension.js +27 -0
- package/dist/prosemirror/extensions/nodes/TableExtension.d.ts +34 -0
- package/dist/prosemirror/extensions/nodes/TableExtension.js +1972 -0
- package/dist/prosemirror/extensions/nodes/TextBoxExtension.d.ts +34 -0
- package/dist/prosemirror/extensions/nodes/TextBoxExtension.js +150 -0
- package/dist/prosemirror/extensions/types.d.ts +101 -0
- package/dist/prosemirror/extensions/types.js +10 -0
- package/dist/prosemirror/findReplaceSelection.d.ts +23 -0
- package/dist/prosemirror/findReplaceSelection.js +86 -0
- package/dist/prosemirror/index.d.ts +25 -0
- package/dist/prosemirror/index.js +23 -0
- package/dist/prosemirror/insertOperations.d.ts +12 -0
- package/dist/prosemirror/insertOperations.js +19 -0
- package/dist/prosemirror/paragraphDirection.d.ts +42 -0
- package/dist/prosemirror/paragraphDirection.js +33 -0
- package/dist/prosemirror/plugins/aiCitationDecorations.d.ts +40 -0
- package/dist/prosemirror/plugins/aiCitationDecorations.js +90 -0
- package/dist/prosemirror/plugins/aiSuggestionDecorations.d.ts +42 -0
- package/dist/prosemirror/plugins/aiSuggestionDecorations.js +135 -0
- package/dist/prosemirror/plugins/anonymizationDecorations.d.ts +60 -0
- package/dist/prosemirror/plugins/anonymizationDecorations.js +120 -0
- package/dist/prosemirror/plugins/autocompleteSuggestion.d.ts +123 -0
- package/dist/prosemirror/plugins/autocompleteSuggestion.js +283 -0
- package/dist/prosemirror/plugins/contentControlWidgets.d.ts +56 -0
- package/dist/prosemirror/plugins/contentControlWidgets.js +192 -0
- package/dist/prosemirror/plugins/createDocScanPlugin.d.ts +37 -0
- package/dist/prosemirror/plugins/createDocScanPlugin.js +55 -0
- package/dist/prosemirror/plugins/documentStyles.d.ts +18 -0
- package/dist/prosemirror/plugins/documentStyles.js +46 -0
- package/dist/prosemirror/plugins/index.d.ts +3 -0
- package/dist/prosemirror/plugins/index.js +3 -0
- package/dist/prosemirror/plugins/pmTextScan.d.ts +19 -0
- package/dist/prosemirror/plugins/pmTextScan.js +39 -0
- package/dist/prosemirror/plugins/selectionTracker.d.ts +43 -0
- package/dist/prosemirror/plugins/selectionTracker.js +179 -0
- package/dist/prosemirror/plugins/suggestionMode.d.ts +70 -0
- package/dist/prosemirror/plugins/suggestionMode.js +489 -0
- package/dist/prosemirror/plugins/templateDirectives.d.ts +25 -0
- package/dist/prosemirror/plugins/templateDirectives.js +67 -0
- package/dist/prosemirror/plugins/templatePreviewValues.d.ts +49 -0
- package/dist/prosemirror/plugins/templatePreviewValues.js +117 -0
- package/dist/prosemirror/plugins/templateSlashMenu.d.ts +57 -0
- package/dist/prosemirror/plugins/templateSlashMenu.js +184 -0
- package/dist/prosemirror/schema/index.d.ts +15 -0
- package/dist/prosemirror/schema/index.js +20 -0
- package/dist/prosemirror/schema/marks.d.ts +118 -0
- package/dist/prosemirror/schema/marks.js +0 -0
- package/dist/prosemirror/schema/nodes.d.ts +389 -0
- package/dist/prosemirror/schema/nodes.js +0 -0
- package/dist/prosemirror/selectionState.d.ts +23 -0
- package/dist/prosemirror/selectionState.js +111 -0
- package/dist/prosemirror/styles/index.d.ts +2 -0
- package/dist/prosemirror/styles/index.js +2 -0
- package/dist/prosemirror/styles/resolvedStyleAttrs.d.ts +32 -0
- package/dist/prosemirror/styles/resolvedStyleAttrs.js +108 -0
- package/dist/prosemirror/styles/styleResolver.d.ts +94 -0
- package/dist/prosemirror/styles/styleResolver.js +200 -0
- package/dist/prosemirror/utils/findParagraphByParaId.d.ts +26 -0
- package/dist/prosemirror/utils/findParagraphByParaId.js +37 -0
- package/dist/prosemirror/utils/tabCalculator.d.ts +110 -0
- package/dist/prosemirror/utils/tabCalculator.js +137 -0
- package/dist/prosemirror/validation.d.ts +20 -0
- package/dist/prosemirror/validation.js +177 -0
- package/dist/server.d.ts +7 -0
- package/dist/server.js +6 -0
- package/dist/style-engine/index.d.ts +3 -0
- package/dist/style-engine/index.js +2 -0
- package/dist/style-engine/styleEngine.d.ts +67 -0
- package/dist/style-engine/styleEngine.js +70 -0
- package/dist/types/block-id.d.ts +66 -0
- package/dist/types/block-id.js +73 -0
- package/dist/types/colors.d.ts +2 -0
- package/dist/types/colors.js +0 -0
- package/dist/types/content.d.ts +2 -0
- package/dist/types/content.js +0 -0
- package/dist/types/document.d.ts +7 -0
- package/dist/types/document.js +0 -0
- package/dist/types/documentEnumValues.d.ts +89 -0
- package/dist/types/documentEnumValues.js +693 -0
- package/dist/types/formatting.d.ts +2 -0
- package/dist/types/formatting.js +0 -0
- package/dist/types/index.d.ts +107 -0
- package/dist/types/index.js +0 -0
- package/dist/utils/authorColors.d.ts +16 -0
- package/dist/utils/authorColors.js +30 -0
- package/dist/utils/baseDirection.d.ts +23 -0
- package/dist/utils/baseDirection.js +34 -0
- package/dist/utils/clipboard.d.ts +126 -0
- package/dist/utils/clipboard.js +622 -0
- package/dist/utils/colorResolver.d.ts +158 -0
- package/dist/utils/colorResolver.js +557 -0
- package/dist/utils/createDocument.d.ts +50 -0
- package/dist/utils/createDocument.js +262 -0
- package/dist/utils/documentLoaderBehavior.d.ts +22 -0
- package/dist/utils/documentLoaderBehavior.js +14 -0
- package/dist/utils/docxInput.d.ts +22 -0
- package/dist/utils/docxInput.js +16 -0
- package/dist/utils/domGuards.d.ts +59 -0
- package/dist/utils/domGuards.js +82 -0
- package/dist/utils/fontFamilyMerge.d.ts +7 -0
- package/dist/utils/fontFamilyMerge.js +31 -0
- package/dist/utils/fontLoader.d.ts +50 -0
- package/dist/utils/fontLoader.js +177 -0
- package/dist/utils/fontResolver.d.ts +61 -0
- package/dist/utils/fontResolver.js +651 -0
- package/dist/utils/fontWeights.d.ts +4 -0
- package/dist/utils/fontWeights.js +4 -0
- package/dist/utils/formatToStyle.d.ts +103 -0
- package/dist/utils/formatToStyle.js +289 -0
- package/dist/utils/headerFooter.d.ts +74 -0
- package/dist/utils/headerFooter.js +257 -0
- package/dist/utils/headingCollector.d.ts +22 -0
- package/dist/utils/headingCollector.js +36 -0
- package/dist/utils/hexId.d.ts +33 -0
- package/dist/utils/hexId.js +37 -0
- package/dist/utils/imageValidation.d.ts +5 -0
- package/dist/utils/imageValidation.js +31 -0
- package/dist/utils/paragraphFormattingMerge.d.ts +14 -0
- package/dist/utils/paragraphFormattingMerge.js +68 -0
- package/dist/utils/replaceText.d.ts +17 -0
- package/dist/utils/replaceText.js +161 -0
- package/dist/utils/rotationBoundingBox.d.ts +12 -0
- package/dist/utils/rotationBoundingBox.js +36 -0
- package/dist/utils/scriptSegments.d.ts +36 -0
- package/dist/utils/scriptSegments.js +52 -0
- package/dist/utils/tableOperations.d.ts +87 -0
- package/dist/utils/tableOperations.js +259 -0
- package/dist/utils/textFormattingMerge.d.ts +6 -0
- package/dist/utils/textFormattingMerge.js +31 -0
- package/dist/utils/tiffConverter.d.ts +18 -0
- package/dist/utils/tiffConverter.js +83 -0
- package/dist/utils/units.d.ts +99 -0
- package/dist/utils/units.js +139 -0
- package/dist/utils/urlSecurity.d.ts +7 -0
- package/dist/utils/urlSecurity.js +65 -0
- package/dist/watermark/index.d.ts +39 -0
- package/dist/watermark/index.js +149 -0
- package/package.json +122 -2
|
@@ -0,0 +1,513 @@
|
|
|
1
|
+
import { deterministicHexId } from "../utils/hexId.js";
|
|
2
|
+
import { repackDocx } from "../docx/rezip.js";
|
|
3
|
+
import { createFolioAIEditSnapshot } from "./snapshot.js";
|
|
4
|
+
import { applyFolioAIEditOperations } from "./apply.js";
|
|
5
|
+
import { createReply } from "../docx/replyToComment.js";
|
|
6
|
+
import { attemptSelectiveSave } from "../docx/selectiveSave.js";
|
|
7
|
+
import { parseDocx } from "../docx/parser.js";
|
|
8
|
+
import { acceptAIEditRevision, acceptAllChanges, rejectAIEditRevision, rejectAllChanges } from "../prosemirror/commands/comments.js";
|
|
9
|
+
import { updateDocumentContent } from "../prosemirror/conversion/fromProseDoc.js";
|
|
10
|
+
import { getChangedParagraphIds, hasStructuralChanges, hasUntrackedChanges, ignoreTrackedChanges } from "../prosemirror/extensions/features/ParagraphChangeTrackerExtension.js";
|
|
11
|
+
import { schema, singletonManager } from "../prosemirror/schema/index.js";
|
|
12
|
+
import { toProseDoc } from "../prosemirror/conversion/toProseDoc.js";
|
|
13
|
+
import { EditorState } from "prosemirror-state";
|
|
14
|
+
//#region src/ai-edits/headless.ts
|
|
15
|
+
/**
|
|
16
|
+
* Headless `.docx` review path: buffer -> apply AI edits -> buffer, with
|
|
17
|
+
* no `EditorView` and no DOM. A queue worker or agent can read a document,
|
|
18
|
+
* apply `FolioAIEditOperation`s (tracked-changes or direct), and write a
|
|
19
|
+
* reviewed `.docx` back out — the server-side counterpart to the React
|
|
20
|
+
* editor's live apply flow.
|
|
21
|
+
*
|
|
22
|
+
* The operation applier is shared, not forked: {@link applyFolioAIEditOperations}
|
|
23
|
+
* only needs a {@link FolioAIEditView} seam (`{ state, dispatch }`), which a
|
|
24
|
+
* headless `EditorState` satisfies via `state.apply(tr)`. The React editor and
|
|
25
|
+
* this reviewer therefore run byte-for-byte the same anchor resolution,
|
|
26
|
+
* word-diff redlines, and tracked-change bookkeeping.
|
|
27
|
+
*
|
|
28
|
+
* Save mirrors the editor's own path: a selective patch of only the changed
|
|
29
|
+
* paragraphs in `document.xml` (leaving every untouched part byte-exact), with
|
|
30
|
+
* a full repack as the fallback for structural edits.
|
|
31
|
+
*
|
|
32
|
+
* Scope: BODY blocks. Footnote / endnote note-body apply is intentionally out
|
|
33
|
+
* of scope here and can build on the note serialization work separately.
|
|
34
|
+
*/
|
|
35
|
+
/**
|
|
36
|
+
* Standalone comment-id allocator for the reviewer. The React editor uses
|
|
37
|
+
* `Date.now()`-seeded ids from `commentsHelpers`; that module is DOM-bound
|
|
38
|
+
* (`EditorView`, `findBodyPmAnchors`) and unimportable here, so the reviewer
|
|
39
|
+
* mints its own. Seeded once per realm and incremented so ids stay unique
|
|
40
|
+
* across reviewers created within the same millisecond.
|
|
41
|
+
*/
|
|
42
|
+
let commentIdCursor = Date.now();
|
|
43
|
+
/**
|
|
44
|
+
* Build the note-free comment thread the apply layer references by id.
|
|
45
|
+
* Mirrors `commentsHelpers.createComment` (a pure object literal there) so a
|
|
46
|
+
* headless `commentOnBlock` / `comment` op serialises the same `comments.xml`
|
|
47
|
+
* shape the editor produces.
|
|
48
|
+
*/
|
|
49
|
+
const createReviewerComment = (text, author) => ({
|
|
50
|
+
id: commentIdCursor++,
|
|
51
|
+
author,
|
|
52
|
+
date: (/* @__PURE__ */ new Date()).toISOString(),
|
|
53
|
+
content: [{
|
|
54
|
+
type: "paragraph",
|
|
55
|
+
formatting: {},
|
|
56
|
+
content: [{
|
|
57
|
+
type: "run",
|
|
58
|
+
formatting: {},
|
|
59
|
+
content: [{
|
|
60
|
+
type: "text",
|
|
61
|
+
text
|
|
62
|
+
}]
|
|
63
|
+
}]
|
|
64
|
+
}]
|
|
65
|
+
});
|
|
66
|
+
/**
|
|
67
|
+
* Assign a stable `w14:paraId` to every body paragraph that lacks one (or
|
|
68
|
+
* duplicates an earlier id), derived deterministically from the paragraph's
|
|
69
|
+
* text plus its document ordinal. Re-parsing the SAME bytes mints the SAME ids,
|
|
70
|
+
* so the block ids a snapshot exposes are reproducible across
|
|
71
|
+
* {@link FolioDocxReviewer.fromBuffer} calls — the documented "snapshot on one
|
|
72
|
+
* parse, apply on another" flow resolves instead of skipping every op as a
|
|
73
|
+
* stale anchor. Word-authored paraIds are preserved; only gaps and collisions
|
|
74
|
+
* get a fresh id.
|
|
75
|
+
*
|
|
76
|
+
* The shared `ParaIdAllocatorExtension` mints RANDOM ids (correct for freshly
|
|
77
|
+
* typed paragraphs in the live editor); this load-time pass is deterministic so
|
|
78
|
+
* a paraId-less corpus document anchors reproducibly. The transaction is marked
|
|
79
|
+
* ignore-tracked so the change baseline stays clean.
|
|
80
|
+
*/
|
|
81
|
+
const ensureDeterministicParaIdsInState = (state) => {
|
|
82
|
+
const seen = /* @__PURE__ */ new Set();
|
|
83
|
+
const updates = [];
|
|
84
|
+
let ordinal = 0;
|
|
85
|
+
state.doc.descendants((node, pos) => {
|
|
86
|
+
if (node.type.name !== "paragraph") return;
|
|
87
|
+
ordinal += 1;
|
|
88
|
+
const existing = node.attrs["paraId"];
|
|
89
|
+
if (typeof existing === "string" && existing.length > 0 && !seen.has(existing)) {
|
|
90
|
+
seen.add(existing);
|
|
91
|
+
return false;
|
|
92
|
+
}
|
|
93
|
+
let paraId = deterministicHexId(`${node.textContent}:${ordinal}`);
|
|
94
|
+
for (let salt = 1; seen.has(paraId); salt++) paraId = deterministicHexId(`${node.textContent}:${ordinal}:${salt}`);
|
|
95
|
+
seen.add(paraId);
|
|
96
|
+
updates.push({
|
|
97
|
+
pos,
|
|
98
|
+
attrs: {
|
|
99
|
+
...node.attrs,
|
|
100
|
+
paraId
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
return false;
|
|
104
|
+
});
|
|
105
|
+
if (updates.length === 0) return state;
|
|
106
|
+
const tr = state.tr;
|
|
107
|
+
for (const update of updates) tr.setNodeMarkup(update.pos, void 0, update.attrs);
|
|
108
|
+
ignoreTrackedChanges(tr);
|
|
109
|
+
tr.setMeta("addToHistory", false);
|
|
110
|
+
return state.apply(tr);
|
|
111
|
+
};
|
|
112
|
+
/**
|
|
113
|
+
* One LLM-ready line for a block: `[<blockId>] text`, with an `(h<level>)` tag
|
|
114
|
+
* for headings and the list marker for list items, so a model can copy the
|
|
115
|
+
* block id straight back into an operation.
|
|
116
|
+
*/
|
|
117
|
+
const formatBlockForLLM = (block) => {
|
|
118
|
+
const label = `[${block.id}]`;
|
|
119
|
+
if (block.kind === "heading") return `${label} (h${headingLevel(block)}) ${block.text}`;
|
|
120
|
+
if (block.kind === "listItem") return `${label} ${block.displayLabel ?? "•"} ${block.text}`;
|
|
121
|
+
return `${label} ${block.text}`;
|
|
122
|
+
};
|
|
123
|
+
const headingLevel = (block) => {
|
|
124
|
+
const digits = /(\d+)/u.exec(block.styleId ?? block.displayLabel ?? "")?.[1];
|
|
125
|
+
const level = digits ? Number.parseInt(digits, 10) : 1;
|
|
126
|
+
return level >= 1 && level <= 9 ? level : 1;
|
|
127
|
+
};
|
|
128
|
+
const revisionIdOf = (target) => typeof target === "number" ? target : target.id;
|
|
129
|
+
const commentPlainText = (comment) => (comment.content ?? []).map(paragraphPlainText).join("\n");
|
|
130
|
+
const paragraphPlainText = (paragraph) => {
|
|
131
|
+
const parts = [];
|
|
132
|
+
for (const item of paragraph.content ?? []) {
|
|
133
|
+
if (item.type !== "run") continue;
|
|
134
|
+
for (const runItem of item.content ?? []) if (runItem.type === "text") parts.push(runItem.text);
|
|
135
|
+
}
|
|
136
|
+
return parts.join("");
|
|
137
|
+
};
|
|
138
|
+
/**
|
|
139
|
+
* Headless `.docx` reviewer. Parse a buffer, read blocks, apply
|
|
140
|
+
* `FolioAIEditOperation`s against the document model, and write the reviewed
|
|
141
|
+
* `.docx` back out — no editor instance, no DOM.
|
|
142
|
+
*
|
|
143
|
+
* @example
|
|
144
|
+
* ```ts
|
|
145
|
+
* const reviewer = await FolioDocxReviewer.fromBuffer(buffer, { author: "AI" });
|
|
146
|
+
* const { blocks } = reviewer.snapshot();
|
|
147
|
+
* reviewer.applyOperations([
|
|
148
|
+
* { id: "1", type: "replaceInBlock", blockId: blocks[0].id, find: "$50k", replace: "$500k" },
|
|
149
|
+
* ]);
|
|
150
|
+
* const reviewed = await reviewer.toBuffer();
|
|
151
|
+
* ```
|
|
152
|
+
*/
|
|
153
|
+
var FolioDocxReviewer = class FolioDocxReviewer {
|
|
154
|
+
/** Default author for tracked changes and comments. */
|
|
155
|
+
author;
|
|
156
|
+
baseDocument;
|
|
157
|
+
originalBuffer;
|
|
158
|
+
state;
|
|
159
|
+
createdComments = [];
|
|
160
|
+
constructor(args) {
|
|
161
|
+
this.baseDocument = args.baseDocument;
|
|
162
|
+
this.originalBuffer = args.originalBuffer;
|
|
163
|
+
this.state = args.state;
|
|
164
|
+
this.author = args.author;
|
|
165
|
+
}
|
|
166
|
+
/** Parse a `.docx` buffer into a reviewer. */
|
|
167
|
+
static async fromBuffer(buffer, options = {}) {
|
|
168
|
+
const baseDocument = await parseDocx(buffer, {
|
|
169
|
+
detectVariables: false,
|
|
170
|
+
preloadFonts: false
|
|
171
|
+
});
|
|
172
|
+
const plugins = singletonManager.getPlugins();
|
|
173
|
+
return new FolioDocxReviewer({
|
|
174
|
+
baseDocument,
|
|
175
|
+
originalBuffer: buffer,
|
|
176
|
+
state: ensureDeterministicParaIdsInState(EditorState.create({
|
|
177
|
+
schema,
|
|
178
|
+
doc: toProseDoc(baseDocument),
|
|
179
|
+
plugins
|
|
180
|
+
})),
|
|
181
|
+
author: options.author ?? "AI"
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Snapshot the current document into AI-facing blocks (id, kind, text) plus
|
|
186
|
+
* the anchor map the apply layer resolves operations against.
|
|
187
|
+
*/
|
|
188
|
+
snapshot() {
|
|
189
|
+
return createFolioAIEditSnapshot(this.state.doc);
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Apply operations against the current state. Reuses the live-editor applier
|
|
193
|
+
* verbatim via a headless `{ state, dispatch }` seam; the resulting state
|
|
194
|
+
* (including any comments) is retained for {@link toBuffer}.
|
|
195
|
+
*/
|
|
196
|
+
applyOperations(operations, options = {}) {
|
|
197
|
+
const snapshot = options.snapshot ?? this.snapshot();
|
|
198
|
+
const view = {
|
|
199
|
+
state: this.state,
|
|
200
|
+
dispatch: (transaction) => {
|
|
201
|
+
view.state = view.state.apply(transaction);
|
|
202
|
+
}
|
|
203
|
+
};
|
|
204
|
+
const result = applyFolioAIEditOperations({
|
|
205
|
+
view,
|
|
206
|
+
snapshot,
|
|
207
|
+
operations,
|
|
208
|
+
mode: options.mode ?? "tracked-changes",
|
|
209
|
+
author: this.author,
|
|
210
|
+
createCommentId: (text) => {
|
|
211
|
+
const comment = createReviewerComment(text, this.author);
|
|
212
|
+
this.createdComments.push(comment);
|
|
213
|
+
return comment.id;
|
|
214
|
+
}
|
|
215
|
+
});
|
|
216
|
+
this.state = view.state;
|
|
217
|
+
return result;
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* The body blocks with their stable ids, in document order — the same
|
|
221
|
+
* `FolioAIBlock` shape {@link snapshot} builds, reused verbatim so the ids
|
|
222
|
+
* feed straight back into {@link applyOperations} and accept / reject.
|
|
223
|
+
*/
|
|
224
|
+
getContent() {
|
|
225
|
+
return this.snapshot().blocks;
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* The body as LLM-ready plain text: one line per block, each prefixed with
|
|
229
|
+
* its stable block id (`[<blockId>] text`). Copyable verbatim into a prompt
|
|
230
|
+
* without JSON quote-escaping.
|
|
231
|
+
*/
|
|
232
|
+
getContentAsText() {
|
|
233
|
+
return this.getContent().map(formatBlockForLLM).join("\n");
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* The tracked changes (insertions and deletions) present in the body, read
|
|
237
|
+
* from the same `insertion` / `deletion` marks the editor renders. Each
|
|
238
|
+
* carries the revision id {@link acceptChange} / {@link rejectChange} resolve
|
|
239
|
+
* against. Runs of one revision within a block fold into a single entry.
|
|
240
|
+
*/
|
|
241
|
+
getChanges(filter) {
|
|
242
|
+
const insertionType = this.state.schema.marks["insertion"];
|
|
243
|
+
const deletionType = this.state.schema.marks["deletion"];
|
|
244
|
+
const blockStarts = this.blockStartIds();
|
|
245
|
+
const grouped = /* @__PURE__ */ new Map();
|
|
246
|
+
let currentBlockId = null;
|
|
247
|
+
this.state.doc.descendants((node, pos) => {
|
|
248
|
+
if (node.isTextblock) {
|
|
249
|
+
currentBlockId = blockStarts.get(pos) ?? null;
|
|
250
|
+
return true;
|
|
251
|
+
}
|
|
252
|
+
if (!node.isInline || node.text === void 0) return;
|
|
253
|
+
const text = node.text;
|
|
254
|
+
for (const mark of node.marks) {
|
|
255
|
+
if (typeof mark.attrs["revisionId"] !== "number") continue;
|
|
256
|
+
let kind;
|
|
257
|
+
if (mark.type === insertionType) kind = "insertion";
|
|
258
|
+
else if (mark.type === deletionType) kind = "deletion";
|
|
259
|
+
else continue;
|
|
260
|
+
const revisionId = mark.attrs["revisionId"];
|
|
261
|
+
const key = `${currentBlockId ?? ""}:${kind}:${revisionId}`;
|
|
262
|
+
const existing = grouped.get(key);
|
|
263
|
+
if (existing) {
|
|
264
|
+
existing.text += text;
|
|
265
|
+
continue;
|
|
266
|
+
}
|
|
267
|
+
const author = mark.attrs["author"];
|
|
268
|
+
const date = mark.attrs["date"];
|
|
269
|
+
grouped.set(key, {
|
|
270
|
+
id: revisionId,
|
|
271
|
+
type: kind,
|
|
272
|
+
author: typeof author === "string" ? author : "",
|
|
273
|
+
date: typeof date === "string" ? date : null,
|
|
274
|
+
text,
|
|
275
|
+
blockId: currentBlockId
|
|
276
|
+
});
|
|
277
|
+
}
|
|
278
|
+
});
|
|
279
|
+
const changes = [...grouped.values()];
|
|
280
|
+
if (!filter) return changes;
|
|
281
|
+
return changes.filter((change) => (filter.author === void 0 || change.author === filter.author) && (filter.type === void 0 || change.type === filter.type));
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* The comment threads in the document — comments parsed from the package plus
|
|
285
|
+
* any the reviewer authored — with their anchored text and containing block
|
|
286
|
+
* id. Only run text is read from a comment body; richer comment content
|
|
287
|
+
* (nested tracked changes, hyperlinks) is out of scope.
|
|
288
|
+
*/
|
|
289
|
+
getComments(filter) {
|
|
290
|
+
const definitions = [...this.baseDocument.package.document.comments ?? [], ...this.createdComments];
|
|
291
|
+
if (definitions.length === 0) return [];
|
|
292
|
+
const anchors = this.commentAnchors();
|
|
293
|
+
const repliesByParent = /* @__PURE__ */ new Map();
|
|
294
|
+
const topLevel = [];
|
|
295
|
+
for (const comment of definitions) {
|
|
296
|
+
if (comment.parentId === void 0) {
|
|
297
|
+
topLevel.push(comment);
|
|
298
|
+
continue;
|
|
299
|
+
}
|
|
300
|
+
const siblings = repliesByParent.get(comment.parentId) ?? [];
|
|
301
|
+
siblings.push(comment);
|
|
302
|
+
repliesByParent.set(comment.parentId, siblings);
|
|
303
|
+
}
|
|
304
|
+
const threads = topLevel.map((comment) => {
|
|
305
|
+
const anchor = anchors.get(comment.id);
|
|
306
|
+
return {
|
|
307
|
+
id: comment.id,
|
|
308
|
+
author: comment.author,
|
|
309
|
+
date: comment.date ?? null,
|
|
310
|
+
text: commentPlainText(comment),
|
|
311
|
+
anchoredText: anchor?.text ?? "",
|
|
312
|
+
blockId: anchor?.blockId ?? null,
|
|
313
|
+
replies: (repliesByParent.get(comment.id) ?? []).map((reply) => ({
|
|
314
|
+
id: reply.id,
|
|
315
|
+
author: reply.author,
|
|
316
|
+
date: reply.date ?? null,
|
|
317
|
+
text: commentPlainText(reply)
|
|
318
|
+
})),
|
|
319
|
+
done: comment.done ?? false
|
|
320
|
+
};
|
|
321
|
+
});
|
|
322
|
+
if (!filter) return threads;
|
|
323
|
+
return threads.filter((thread) => (filter.author === void 0 || thread.author === filter.author) && (filter.done === void 0 || thread.done === filter.done));
|
|
324
|
+
}
|
|
325
|
+
/**
|
|
326
|
+
* Add a reply to a comment thread. Pass a {@link FolioReviewComment} from
|
|
327
|
+
* {@link getComments} or its id; the reply threads under that comment's root
|
|
328
|
+
* (Word threads are flat). On {@link toBuffer} the reply is written as a real
|
|
329
|
+
* Word reply — linked via `commentsExtended.xml` and given its own
|
|
330
|
+
* `commentRange` markers + reference anchored on the parent's range. Returns
|
|
331
|
+
* the created reply, or `null` when the target comment is absent.
|
|
332
|
+
*/
|
|
333
|
+
replyTo(target, input) {
|
|
334
|
+
const parentId = typeof target === "number" ? target : target.id;
|
|
335
|
+
const reply = createReply([...this.baseDocument.package.document.comments ?? [], ...this.createdComments], parentId, {
|
|
336
|
+
author: input.author ?? this.author,
|
|
337
|
+
text: input.text,
|
|
338
|
+
...input.initials !== void 0 ? { initials: input.initials } : {}
|
|
339
|
+
});
|
|
340
|
+
if (!reply) return null;
|
|
341
|
+
this.createdComments.push(reply);
|
|
342
|
+
return {
|
|
343
|
+
id: reply.id,
|
|
344
|
+
author: reply.author,
|
|
345
|
+
date: reply.date ?? null,
|
|
346
|
+
text: input.text
|
|
347
|
+
};
|
|
348
|
+
}
|
|
349
|
+
/**
|
|
350
|
+
* Accept an existing tracked change, keeping its text and dropping the
|
|
351
|
+
* redline. Pass a {@link FolioReviewChange} from {@link getChanges} or its
|
|
352
|
+
* revision id. Reuses the editor's own accept command headlessly, so the
|
|
353
|
+
* resolved state persists on {@link toBuffer}. Returns `false` when the
|
|
354
|
+
* revision is no longer present (already resolved, or never existed).
|
|
355
|
+
*/
|
|
356
|
+
acceptChange(target) {
|
|
357
|
+
return this.runCommand(acceptAIEditRevision(revisionIdOf(target)));
|
|
358
|
+
}
|
|
359
|
+
/**
|
|
360
|
+
* Reject an existing tracked change: an insertion's text is removed, a
|
|
361
|
+
* deletion's text is restored. See {@link acceptChange} for targeting.
|
|
362
|
+
*/
|
|
363
|
+
rejectChange(target) {
|
|
364
|
+
return this.runCommand(rejectAIEditRevision(revisionIdOf(target)));
|
|
365
|
+
}
|
|
366
|
+
/**
|
|
367
|
+
* Accept every tracked change in the body. Returns the number of changes
|
|
368
|
+
* present before the sweep. Runs unconditionally: the underlying command also
|
|
369
|
+
* resolves paragraph-level changes (`w:pPrChange`, paragraph-boundary
|
|
370
|
+
* ins/del) that {@link getChanges} does not enumerate. Note-body changes are
|
|
371
|
+
* out of scope.
|
|
372
|
+
*/
|
|
373
|
+
acceptAll() {
|
|
374
|
+
const count = this.countTrackedChanges();
|
|
375
|
+
this.runCommand(acceptAllChanges());
|
|
376
|
+
return count;
|
|
377
|
+
}
|
|
378
|
+
/** Reject every tracked change in the body. See {@link acceptAll}. */
|
|
379
|
+
rejectAll() {
|
|
380
|
+
const count = this.countTrackedChanges();
|
|
381
|
+
this.runCommand(rejectAllChanges());
|
|
382
|
+
return count;
|
|
383
|
+
}
|
|
384
|
+
/** The current document model with edits merged back in. */
|
|
385
|
+
toDocument() {
|
|
386
|
+
const document = updateDocumentContent(this.baseDocument, this.state.doc);
|
|
387
|
+
if (this.createdComments.length > 0) document.package.document.comments = [...document.package.document.comments ?? [], ...this.createdComments];
|
|
388
|
+
return document;
|
|
389
|
+
}
|
|
390
|
+
/**
|
|
391
|
+
* Serialise the reviewed document to a new `.docx` buffer. Tries a selective
|
|
392
|
+
* patch first (only changed paragraphs are rewritten; every other byte of the
|
|
393
|
+
* original package is preserved), falling back to a full repack for
|
|
394
|
+
* structural edits — the same two-tier path the editor's save uses.
|
|
395
|
+
*/
|
|
396
|
+
async toBuffer() {
|
|
397
|
+
const document = this.toDocument();
|
|
398
|
+
const selective = await this.trySelectiveSave(document);
|
|
399
|
+
if (selective) return selective;
|
|
400
|
+
return repackDocx({
|
|
401
|
+
...document,
|
|
402
|
+
originalBuffer: this.originalBuffer
|
|
403
|
+
});
|
|
404
|
+
}
|
|
405
|
+
/**
|
|
406
|
+
* Attempt the selective patch, treating a throw the same as a decline. Odd
|
|
407
|
+
* source XML can make the paragraph diff throw rather than return `null`; a
|
|
408
|
+
* full repack is the correct lossless fallback in both cases, so the fallback
|
|
409
|
+
* is the graceful handling — no separate error surface is needed here.
|
|
410
|
+
*/
|
|
411
|
+
async trySelectiveSave(document) {
|
|
412
|
+
try {
|
|
413
|
+
return await attemptSelectiveSave(document, this.originalBuffer, {
|
|
414
|
+
changedParaIds: getChangedParagraphIds(this.state),
|
|
415
|
+
structuralChange: hasStructuralChanges(this.state),
|
|
416
|
+
hasUntrackedChanges: hasUntrackedChanges(this.state)
|
|
417
|
+
});
|
|
418
|
+
} catch {
|
|
419
|
+
return null;
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
/**
|
|
423
|
+
* Count every tracked change an accept-all / reject-all sweep resolves: the
|
|
424
|
+
* inline insertion / deletion groups {@link getChanges} enumerates, plus
|
|
425
|
+
* paragraph-level changes (`pPrMark`, `_propertyChanges`) that live on
|
|
426
|
+
* paragraph attrs rather than inline marks.
|
|
427
|
+
*/
|
|
428
|
+
countTrackedChanges() {
|
|
429
|
+
let count = this.getChanges().length;
|
|
430
|
+
this.state.doc.descendants((node) => {
|
|
431
|
+
if (node.type.name !== "paragraph") return;
|
|
432
|
+
const pPrMark = node.attrs["pPrMark"];
|
|
433
|
+
if (pPrMark !== null && pPrMark !== void 0) count += 1;
|
|
434
|
+
const propertyChanges = node.attrs["_propertyChanges"];
|
|
435
|
+
if (Array.isArray(propertyChanges) && propertyChanges.length > 0) count += 1;
|
|
436
|
+
return false;
|
|
437
|
+
});
|
|
438
|
+
return count;
|
|
439
|
+
}
|
|
440
|
+
/** Map each snapshot block's start position to its stable id. */
|
|
441
|
+
blockStartIds() {
|
|
442
|
+
const starts = /* @__PURE__ */ new Map();
|
|
443
|
+
for (const anchor of Object.values(this.snapshot().anchors)) starts.set(anchor.from, anchor.id);
|
|
444
|
+
return starts;
|
|
445
|
+
}
|
|
446
|
+
/** Map each anchored comment id to its anchored text and containing block id. */
|
|
447
|
+
commentAnchors() {
|
|
448
|
+
const commentType = this.state.schema.marks["comment"];
|
|
449
|
+
const anchors = /* @__PURE__ */ new Map();
|
|
450
|
+
if (!commentType) return anchors;
|
|
451
|
+
const blockStarts = this.blockStartIds();
|
|
452
|
+
let currentBlockId = null;
|
|
453
|
+
this.state.doc.descendants((node, pos) => {
|
|
454
|
+
if (node.isTextblock) {
|
|
455
|
+
currentBlockId = blockStarts.get(pos) ?? null;
|
|
456
|
+
return true;
|
|
457
|
+
}
|
|
458
|
+
if (!node.isInline || node.text === void 0) return;
|
|
459
|
+
const text = node.text;
|
|
460
|
+
for (const mark of node.marks) {
|
|
461
|
+
if (mark.type !== commentType || typeof mark.attrs["commentId"] !== "number") continue;
|
|
462
|
+
const commentId = mark.attrs["commentId"];
|
|
463
|
+
const existing = anchors.get(commentId);
|
|
464
|
+
if (!existing) {
|
|
465
|
+
anchors.set(commentId, {
|
|
466
|
+
text,
|
|
467
|
+
blockId: currentBlockId
|
|
468
|
+
});
|
|
469
|
+
continue;
|
|
470
|
+
}
|
|
471
|
+
existing.text += text;
|
|
472
|
+
existing.blockId ??= currentBlockId;
|
|
473
|
+
}
|
|
474
|
+
});
|
|
475
|
+
return anchors;
|
|
476
|
+
}
|
|
477
|
+
/**
|
|
478
|
+
* Drive a ProseMirror command against the reviewer's headless state via the
|
|
479
|
+
* same `{ state, dispatch }` seam {@link applyOperations} uses, retaining the
|
|
480
|
+
* resulting state for {@link toBuffer}.
|
|
481
|
+
*/
|
|
482
|
+
runCommand(command) {
|
|
483
|
+
const view = {
|
|
484
|
+
state: this.state,
|
|
485
|
+
dispatch: (transaction) => {
|
|
486
|
+
view.state = view.state.apply(transaction);
|
|
487
|
+
}
|
|
488
|
+
};
|
|
489
|
+
const handled = command(view.state, view.dispatch);
|
|
490
|
+
this.state = view.state;
|
|
491
|
+
return handled;
|
|
492
|
+
}
|
|
493
|
+
};
|
|
494
|
+
/**
|
|
495
|
+
* One-shot headless review: parse `buffer`, apply `operations`, and return the
|
|
496
|
+
* reviewed `.docx` buffer alongside the applied / skipped breakdown. Convenience
|
|
497
|
+
* wrapper over {@link FolioDocxReviewer} for callers that already hold the
|
|
498
|
+
* operations to run.
|
|
499
|
+
*/
|
|
500
|
+
const applyFolioAIEditsToBuffer = async (buffer, operations, options = {}) => {
|
|
501
|
+
const reviewer = await FolioDocxReviewer.fromBuffer(buffer, { ...options.author !== void 0 && { author: options.author } });
|
|
502
|
+
const { applied, skipped } = reviewer.applyOperations(operations, {
|
|
503
|
+
...options.mode !== void 0 && { mode: options.mode },
|
|
504
|
+
...options.snapshot !== void 0 && { snapshot: options.snapshot }
|
|
505
|
+
});
|
|
506
|
+
return {
|
|
507
|
+
buffer: await reviewer.toBuffer(),
|
|
508
|
+
applied,
|
|
509
|
+
skipped
|
|
510
|
+
};
|
|
511
|
+
};
|
|
512
|
+
//#endregion
|
|
513
|
+
export { FolioDocxReviewer, applyFolioAIEditsToBuffer };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { FolioAIBlock, FolioAIBlockAnchor, FolioAIBlockKind, FolioAIBlockPreviewRun, FolioAIComment, FolioAIEditAppliedOperation, FolioAIEditApplyMode, FolioAIEditApplyResult, FolioAIEditOperation, FolioAIEditReviewMeta, FolioAIEditSeverity, FolioAIEditSkipReason, FolioAIEditSkippedOperation, FolioAIEditSnapshot, FolioAISignatureParty } from "./types.js";
|
|
2
|
+
import { FolioAIEditView, applyFolioAIEditOperations } from "./apply.js";
|
|
3
|
+
import { createFolioAIEditSnapshot, hashFolioAIBlockText, normalizeFolioAIBlockText } from "./snapshot.js";
|
|
4
|
+
import { getFolioParaIdFromBlockId } from "../types/block-id.js";
|
|
5
|
+
import { WordDiffSegment, diffWordSegments } from "./word-diff.js";
|
|
6
|
+
export { type FolioAIBlock, type FolioAIBlockAnchor, type FolioAIBlockKind, type FolioAIBlockPreviewRun, type FolioAIComment, type FolioAIEditAppliedOperation, type FolioAIEditApplyMode, type FolioAIEditApplyResult, type FolioAIEditOperation, type FolioAIEditReviewMeta, type FolioAIEditSeverity, type FolioAIEditSkipReason, type FolioAIEditSkippedOperation, type FolioAIEditSnapshot, type FolioAIEditView, type FolioAISignatureParty, type WordDiffSegment, applyFolioAIEditOperations, createFolioAIEditSnapshot, diffWordSegments, getFolioParaIdFromBlockId, hashFolioAIBlockText, normalizeFolioAIBlockText };
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { getFolioParaIdFromBlockId } from "../types/block-id.js";
|
|
2
|
+
import { createFolioAIEditSnapshot, hashFolioAIBlockText, normalizeFolioAIBlockText } from "./snapshot.js";
|
|
3
|
+
import { diffWordSegments } from "./word-diff.js";
|
|
4
|
+
import { applyFolioAIEditOperations } from "./apply.js";
|
|
5
|
+
export { applyFolioAIEditOperations, createFolioAIEditSnapshot, diffWordSegments, getFolioParaIdFromBlockId, hashFolioAIBlockText, normalizeFolioAIBlockText };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
//#region src/ai-edits/inline-emphasis.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Turn the bold / bold-italic markdown the chat model sometimes emits inside
|
|
4
|
+
* inserted or replaced block text ("**Date:**", "***Term***") into structured
|
|
5
|
+
* runs the editor renders as real Word formatting.
|
|
6
|
+
*
|
|
7
|
+
* The active-docx-edit tool gives the model no inline run-formatting channel —
|
|
8
|
+
* only paragraph-level `styleId`. When the model wants a bold label or party
|
|
9
|
+
* name mid-sentence it improvises with markdown, and because DOCX has no notion
|
|
10
|
+
* of markdown those markers otherwise reach the document as literal asterisks.
|
|
11
|
+
*
|
|
12
|
+
* Deliberately conservative: only paired `**bold**` and `***bold italic***`
|
|
13
|
+
* asterisk markers with non-space inner content count as emphasis. Underscores
|
|
14
|
+
* are always literal — `__Borrower__` / snake_case placeholders are common in
|
|
15
|
+
* legal templates, and a lone `*` is far more likely a multiplication sign than
|
|
16
|
+
* a delimiter. Nesting is not interpreted; inner content is taken verbatim.
|
|
17
|
+
* Backslashes are ordinary characters (no markdown escapes), so Windows paths
|
|
18
|
+
* and regex survive intact.
|
|
19
|
+
*/
|
|
20
|
+
type InlineEmphasisRun = {
|
|
21
|
+
text: string;
|
|
22
|
+
bold: boolean;
|
|
23
|
+
italic: boolean;
|
|
24
|
+
};
|
|
25
|
+
declare const parseInlineEmphasisRuns: (input: string) => InlineEmphasisRun[];
|
|
26
|
+
/** True when `input` contains at least one bold / italic span worth promoting
|
|
27
|
+
* to real marks; lets callers skip the run rebuild for plain text. */
|
|
28
|
+
declare const hasInlineEmphasis: (input: string) => boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Drop emphasis markers without reconstructing formatting. Used on the
|
|
31
|
+
* tracked-changes replace path, where the word-diff redline cannot carry inline
|
|
32
|
+
* marks; stripping at least keeps literal `**` out of the document. Returns the
|
|
33
|
+
* input verbatim when no real span is present, so plain prose (and stray
|
|
34
|
+
* single `*` / escaped `\*`) is never reshaped.
|
|
35
|
+
*/
|
|
36
|
+
declare const stripInlineEmphasisMarkers: (input: string) => string;
|
|
37
|
+
//#endregion
|
|
38
|
+
export { InlineEmphasisRun, hasInlineEmphasis, parseInlineEmphasisRuns, stripInlineEmphasisMarkers };
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
//#region src/ai-edits/inline-emphasis.ts
|
|
2
|
+
const MARKERS = [{
|
|
3
|
+
marker: "***",
|
|
4
|
+
bold: true,
|
|
5
|
+
italic: true
|
|
6
|
+
}, {
|
|
7
|
+
marker: "**",
|
|
8
|
+
bold: true,
|
|
9
|
+
italic: false
|
|
10
|
+
}];
|
|
11
|
+
const isSpace = (ch) => ch === void 0 || ch === " " || ch === " " || ch === "\n";
|
|
12
|
+
const matchMarkerAt = (input, at) => MARKERS.find((m) => input.startsWith(m.marker, at));
|
|
13
|
+
const appendLiteral = (runs, text) => {
|
|
14
|
+
if (text.length === 0) return;
|
|
15
|
+
const last = runs.at(-1);
|
|
16
|
+
if (last && !last.bold && !last.italic) {
|
|
17
|
+
last.text += text;
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
runs.push({
|
|
21
|
+
text,
|
|
22
|
+
bold: false,
|
|
23
|
+
italic: false
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
const parseInlineEmphasisRuns = (input) => {
|
|
27
|
+
const runs = [];
|
|
28
|
+
let buffer = "";
|
|
29
|
+
let i = 0;
|
|
30
|
+
const flushBuffer = () => {
|
|
31
|
+
appendLiteral(runs, buffer);
|
|
32
|
+
buffer = "";
|
|
33
|
+
};
|
|
34
|
+
while (i < input.length) {
|
|
35
|
+
const ch = input[i];
|
|
36
|
+
const matched = matchMarkerAt(input, i);
|
|
37
|
+
if (!matched) {
|
|
38
|
+
buffer += ch;
|
|
39
|
+
i += 1;
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
const contentStart = i + matched.marker.length;
|
|
43
|
+
const closeIdx = input.indexOf(matched.marker, contentStart);
|
|
44
|
+
const content = closeIdx === -1 ? "" : input.slice(contentStart, closeIdx);
|
|
45
|
+
if (!(closeIdx !== -1 && content.length > 0 && !isSpace(content[0]) && !isSpace(content.at(-1)))) {
|
|
46
|
+
buffer += ch;
|
|
47
|
+
i += 1;
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
flushBuffer();
|
|
51
|
+
runs.push({
|
|
52
|
+
text: content,
|
|
53
|
+
bold: matched.bold,
|
|
54
|
+
italic: matched.italic
|
|
55
|
+
});
|
|
56
|
+
i = closeIdx + matched.marker.length;
|
|
57
|
+
}
|
|
58
|
+
flushBuffer();
|
|
59
|
+
return runs;
|
|
60
|
+
};
|
|
61
|
+
const hasEmphasis = (runs) => runs.some((run) => run.bold || run.italic);
|
|
62
|
+
/** True when `input` contains at least one bold / italic span worth promoting
|
|
63
|
+
* to real marks; lets callers skip the run rebuild for plain text. */
|
|
64
|
+
const hasInlineEmphasis = (input) => hasEmphasis(parseInlineEmphasisRuns(input));
|
|
65
|
+
/**
|
|
66
|
+
* Drop emphasis markers without reconstructing formatting. Used on the
|
|
67
|
+
* tracked-changes replace path, where the word-diff redline cannot carry inline
|
|
68
|
+
* marks; stripping at least keeps literal `**` out of the document. Returns the
|
|
69
|
+
* input verbatim when no real span is present, so plain prose (and stray
|
|
70
|
+
* single `*` / escaped `\*`) is never reshaped.
|
|
71
|
+
*/
|
|
72
|
+
const stripInlineEmphasisMarkers = (input) => {
|
|
73
|
+
const runs = parseInlineEmphasisRuns(input);
|
|
74
|
+
if (!hasEmphasis(runs)) return input;
|
|
75
|
+
return runs.map((run) => run.text).join("");
|
|
76
|
+
};
|
|
77
|
+
//#endregion
|
|
78
|
+
export { hasInlineEmphasis, parseInlineEmphasisRuns, stripInlineEmphasisMarkers };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { FolioAIEditSnapshot } from "./types.js";
|
|
2
|
+
import { Node } from "prosemirror-model";
|
|
3
|
+
|
|
4
|
+
//#region src/ai-edits/snapshot.d.ts
|
|
5
|
+
declare const normalizeFolioAIBlockText: (text: string) => string;
|
|
6
|
+
declare const hashFolioAIBlockText: (text: string) => string;
|
|
7
|
+
declare const createFolioAIEditSnapshot: (doc: Node) => FolioAIEditSnapshot;
|
|
8
|
+
//#endregion
|
|
9
|
+
export { createFolioAIEditSnapshot, hashFolioAIBlockText, normalizeFolioAIBlockText };
|